Inner-Heaven / libzetta-rs

Stable interface for programmatic administration of ZFS from Rust
BSD 2-Clause "Simplified" License
62 stars 16 forks source link

Panic when reading properties of volume snapshots #260

Open ociaw opened 8 months ago

ociaw commented 8 months ago

Describe the bug

libzetta panics when reading the properties of snapshots of volumes:

thread 'main' panicked at /home/username/.cargo/git/checkouts/libzetta-rs-2c006bbd2fc21a39/7191a10/src/zfs/open3.rs:493:45:
Failed to build properties: UninitializedField("devices")

libzetta expects the properties devices, exec, setuid, xattr, version, and casesensitivity to exist on every snapshot. However, these properties do not appear on volume snapshots, causing a panic.

To Reproduce

Attempt to get the properties of a snapshot without a devices property. For example, only the following properties are present on a snapshot of a volume on my pool:

> zfs get -Hp all bulk/encrypted/images/testing-popos
bulk/encrypted/images/testing-popos     type    volume  -
bulk/encrypted/images/testing-popos     creation        1639013065      -
bulk/encrypted/images/testing-popos     used    340523659264    -
bulk/encrypted/images/testing-popos     available       1575171211264   -
bulk/encrypted/images/testing-popos     referenced      340523659264    -
bulk/encrypted/images/testing-popos     compressratio   1.61    -
bulk/encrypted/images/testing-popos     reservation     0       default
bulk/encrypted/images/testing-popos     volsize 549755813888    local
bulk/encrypted/images/testing-popos     volblocksize    16384   default
bulk/encrypted/images/testing-popos     checksum        on      default
bulk/encrypted/images/testing-popos     compression     zstd    inherited from bulk
bulk/encrypted/images/testing-popos     readonly        off     default
bulk/encrypted/images/testing-popos     createtxg       165358  -
bulk/encrypted/images/testing-popos     copies  1       default
bulk/encrypted/images/testing-popos     refreservation  0       default
bulk/encrypted/images/testing-popos     guid    13843560448143234298    -
bulk/encrypted/images/testing-popos     primarycache    all     default
bulk/encrypted/images/testing-popos     secondarycache  all     default
bulk/encrypted/images/testing-popos     usedbysnapshots 0       -
bulk/encrypted/images/testing-popos     usedbydataset   340523659264    -
bulk/encrypted/images/testing-popos     usedbychildren  0       -
bulk/encrypted/images/testing-popos     usedbyrefreservation    0       -
bulk/encrypted/images/testing-popos     logbias latency default
bulk/encrypted/images/testing-popos     objsetid        1415    -
bulk/encrypted/images/testing-popos     dedup   off     default
bulk/encrypted/images/testing-popos     mlslabel        none    default
bulk/encrypted/images/testing-popos     sync    standard        default
bulk/encrypted/images/testing-popos     refcompressratio        1.61    -
bulk/encrypted/images/testing-popos     written 0       -
bulk/encrypted/images/testing-popos     logicalused     545906790912    -
bulk/encrypted/images/testing-popos     logicalreferenced       545906790912    -
bulk/encrypted/images/testing-popos     volmode default default
bulk/encrypted/images/testing-popos     snapshot_limit  none    default
bulk/encrypted/images/testing-popos     snapshot_count  none    default
bulk/encrypted/images/testing-popos     snapdev hidden  default
bulk/encrypted/images/testing-popos     context none    default
bulk/encrypted/images/testing-popos     fscontext       none    default
bulk/encrypted/images/testing-popos     defcontext      none    default
bulk/encrypted/images/testing-popos     rootcontext     none    default
bulk/encrypted/images/testing-popos     redundant_metadata      all     default
bulk/encrypted/images/testing-popos     encryption      aes-256-gcm     -
bulk/encrypted/images/testing-popos     keylocation     none    default
bulk/encrypted/images/testing-popos     keyformat       passphrase      -
bulk/encrypted/images/testing-popos     pbkdf2iters     350000  -
bulk/encrypted/images/testing-popos     encryptionroot  bulk/encrypted  -
bulk/encrypted/images/testing-popos     keystatus       available       -

Expected behavior

No panic occurs. Unsure if the final solution should simply ignore the missing properties or if a new type (such as VolumeSnapshotProperties) should be created, as there are a number of volume-specific properties such as volblocksize that are not represented in SnapshotProperties.

Please complete the following information:

andoriyu commented 8 months ago

I will take a look later this week and cut a new release after fixing it.

andoriyu commented 8 months ago

I guess it's either make them optional or make a separate Properties type. Both are breaking change. if there is no objections, then I will go with making them optional.