Skip to content

Consider the preliminary snapshot when calculating the size of the snapshot

Goal

physicalSize of a snapshot often (in physical mode) shows incorrect value because it is built on top of pre-snapshot which does not contain any changes

  {
    "id": "dblab_pool/clone_pre_20211103192437@snapshot_20211102220622",
    "createdAt": "2021-11-03 19:26:12 UTC",
    "dataStateAt": "2021-11-02 22:06:22 UTC",
    "physicalSize": 0,
    "logicalSize": 94455637504,
    "pool": "dblab_pool",
    "numClones": 1
  }

zfs list -t snapshot

NAME                                                              USED  AVAIL     REFER  MOUNTPOINT
dblab_pool@snapshot_20211103192437_pre                           5,07G      -     28,0G  -
dblab_pool/clone_pre_20211103192437@snapshot_20211102220622         0B      -     28,2G  -

TODO / How to implement

  • Parse pre-clone name
  • Find pre-clone origin
  • Get the size of the origin snapshot
$ zfs get used datastore/clone_pre_20211107150000@snapshot_20211107150002
NAME                                                        PROPERTY  VALUE  SOURCE
datastore/clone_pre_20211107150000@snapshot_20211107150002  used      0B     -

$ zfs get origin datastore/clone_pre_20211107150000
NAME                                PROPERTY  VALUE                                  SOURCE
datastore/clone_pre_20211107150000  origin    datastore@snapshot_20211107150000_pre  -

$ zfs get used datastore@snapshot_20211107150000_pre
NAME                                   PROPERTY  VALUE  SOURCE
datastore@snapshot_20211107150000_pre  used      243K   -

$ zfs get used -H datastore@snapshot_20211107150000_pre
datastore@snapshot_20211107150000_pre	used	243K	-

The go-libzfs library might be useful to avoid a lot of parsing actions: https://github.com/bicomsystems/go-libzfs

Acceptance criteria

Edited by Artyom Kartasov