是否有一个libzfs相当于" zfs destroy -npv foo bar baz"?

时间:2017-08-24 11:21:25

标签: zfs

我在FreeBSD上使用py-libzfs来列出,创建和销毁快照,并且它正在按照这些基本操作的预期工作,但我现在正试图找出"如何如果删除了几个快照,会释放多少空间?"。

在ZFS中删除多个快照可以释放 more 而不是每个快照空间的总和,因为它最终可以释放多个快照引用的块。

在shell上,可以使用以下命令找到该问题的正确答案:

zfs destroy -npv <dataset>@<snap1>%<snap2>,<snap3>,<...>

我希望尽可能避免打电话给外部程序,所以我试图在没有运气的情况下浏览the code,但我找不到任何相关文档。

甚至可能从libzfs中获取那种信息?如何?

1 个答案:

答案 0 :(得分:1)

py-libzfslibzfs周围的1:1包装,所以我来看看libzfs_core,尤其是:

/*
 * Destroys snapshots.
 *
 * The keys in the snaps nvlist are the snapshots to be destroyed.
 * They must all be in the same pool.
 *
 * Snapshots that do not exist will be silently ignored.
 *
 * If 'defer' is not set, and a snapshot has user holds or clones, the
 * destroy operation will fail and none of the snapshots will be
 * destroyed.
 *
 * If 'defer' is set, and a snapshot has user holds or clones, it will be
 * marked for deferred destruction, and will be destroyed when the last hold
 * or clone is removed/destroyed.
 *
 * The return value will be 0 if all snapshots were destroyed (or marked for
 * later destruction if 'defer' is set) or didn't exist to begin with.
 *
 * Otherwise the return value will be the errno of a (unspecified) snapshot
 * that failed, no snapshots will be destroyed, and the errlist will have an
 * entry for each snapshot that failed.  The value in the errlist will be
 * the (int32) error code.
 */
int
lzc_destroy_snaps(nvlist_t *snaps, boolean_t defer, nvlist_t **errlist)

关于该API的文档很少,因此您最好的朋友是zfs/usr/src/cddl/contrib/opensolaris/cmd/zfs命令的来源。

还请注意,尽管相关,但OpenZFS,Linux上的ZFS和FreeBSD上的ZFS是不同的实现,它们源自一个来源,因此会随着时间的推移而发生变化。目前正在努力为所有平台统一(Open)ZFS代码库,但是目前我们还没有...