aboutsummaryrefslogtreecommitdiffstats
path: root/module/os/linux/zfs
diff options
context:
space:
mode:
authorAndrew <[email protected]>2022-06-17 13:44:49 -0500
committerGitHub <[email protected]>2022-06-17 11:44:49 -0700
commitf60973998593c37f55beea05e74528c1992b7849 (patch)
tree86ac557cf6f6bec9006cf72f296eb2190d93ab36 /module/os/linux/zfs
parent10891b37fa8f2cbf71ec529fc3808113d94d52ef (diff)
expose snapshot count via stat(2) of .zfs/snapshot (#13559)
Increase nlinks in stat results of ./zfs/snapshot based on snapshot count. This provides quick and efficient method for administrators to get snapshot counts without having to use libzfs or list the snapdir contents. Reviewed-by: Ryan Moeller <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Andrew Walker <[email protected]> Closes #13559
Diffstat (limited to 'module/os/linux/zfs')
-rw-r--r--module/os/linux/zfs/zpl_ctldir.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/module/os/linux/zfs/zpl_ctldir.c b/module/os/linux/zfs/zpl_ctldir.c
index f4e1ab7ae..d5c222120 100644
--- a/module/os/linux/zfs/zpl_ctldir.c
+++ b/module/os/linux/zfs/zpl_ctldir.c
@@ -32,6 +32,9 @@
#include <sys/zfs_vnops.h>
#include <sys/zfs_ctldir.h>
#include <sys/zpl.h>
+#include <sys/dmu.h>
+#include <sys/dsl_dataset.h>
+#include <sys/zap.h>
/*
* Common open routine. Disallow any write access.
@@ -411,6 +414,20 @@ zpl_snapdir_getattr_impl(const struct path *path, struct kstat *stat,
#endif
stat->nlink = stat->size = 2;
+
+ dsl_dataset_t *ds = dmu_objset_ds(zfsvfs->z_os);
+ if (dsl_dataset_phys(ds)->ds_snapnames_zapobj != 0) {
+ uint64_t snap_count;
+ int err = zap_count(
+ dmu_objset_pool(ds->ds_objset)->dp_meta_objset,
+ dsl_dataset_phys(ds)->ds_snapnames_zapobj, &snap_count);
+ if (err != 0) {
+ ZPL_EXIT(zfsvfs);
+ return (-err);
+ }
+ stat->nlink += snap_count;
+ }
+
stat->ctime = stat->mtime = dmu_objset_snap_cmtime(zfsvfs->z_os);
stat->atime = current_time(ip);
ZPL_EXIT(zfsvfs);