]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libfrog: define a autofsck filesystem property
authorDarrick J. Wong <djwong@kernel.org>
Thu, 8 Aug 2024 16:38:48 +0000 (09:38 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 8 Aug 2024 16:38:48 +0000 (09:38 -0700)
Now that we have the ability to set properties on filesystems, create an
"autofsck" property so that sysadmins can control background xfs_scrub
behaviors.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libfrog/fsproperties.c
libfrog/fsproperties.h

index c317d15c1de0b62fc58f03cf182e7c5966f90cf0..72485f62720d134b29442cac3d672fc4dcd1b2dc 100644 (file)
@@ -29,11 +29,49 @@ __fsprops_lookup(
 #define fsprops_lookup(values, value) \
        __fsprops_lookup((values), ARRAY_SIZE(values), (value))
 
+/* Automatic background fsck fs property */
+
+static const char *fsprop_autofsck_values[] = {
+       [FSPROP_AUTOFSCK_UNSET]         = NULL,
+       [FSPROP_AUTOFSCK_NONE]          = "none",
+       [FSPROP_AUTOFSCK_CHECK]         = "check",
+       [FSPROP_AUTOFSCK_OPTIMIZE]      = "optimize",
+       [FSPROP_AUTOFSCK_REPAIR]        = "repair",
+};
+
+/* Convert the autofsck property enum to a string. */
+const char *
+fsprop_autofsck_write(
+       enum fsprop_autofsck    x)
+{
+       if (x <= FSPROP_AUTOFSCK_UNSET ||
+           x >= ARRAY_SIZE(fsprop_autofsck_values))
+               return NULL;
+       return fsprop_autofsck_values[x];
+}
+
+/*
+ * Turn a autofsck value string into an enumerated value, or _UNSET if it's
+ * not recognized.
+ */
+enum fsprop_autofsck
+fsprop_autofsck_read(
+       const char      *value)
+{
+       int ret = fsprops_lookup(fsprop_autofsck_values, value);
+       if (ret < 0)
+               return FSPROP_AUTOFSCK_UNSET;
+       return ret;
+}
+
 /* Return true if a fs property name=value tuple is allowed. */
 bool
 fsprop_validate(
        const char      *name,
        const char      *value)
 {
+       if (!strcmp(name, FSPROP_AUTOFSCK_NAME))
+               return fsprops_lookup(fsprop_autofsck_values, value) >= 0;
+
        return true;
 }
index b1ac4cdd700432acf3db0f6df569ccfd6b6c6c85..11d6530bc9a6d67587fee87f5f85ddc8a959f49e 100644 (file)
@@ -50,4 +50,17 @@ bool fsprop_validate(const char *name, const char *value);
 
 /* Specific Filesystem Properties */
 
+#define FSPROP_AUTOFSCK_NAME           "autofsck"
+
+enum fsprop_autofsck {
+       FSPROP_AUTOFSCK_UNSET = 0,      /* do not set property */
+       FSPROP_AUTOFSCK_NONE,           /* no background scrubs */
+       FSPROP_AUTOFSCK_CHECK,          /* allow only background checking */
+       FSPROP_AUTOFSCK_OPTIMIZE,       /* allow background optimization */
+       FSPROP_AUTOFSCK_REPAIR,         /* allow background repair & optimization */
+};
+
+const char *fsprop_autofsck_write(enum fsprop_autofsck x);
+enum fsprop_autofsck fsprop_autofsck_read(const char *value);
+
 #endif /* __LIBFROG_FSPROPERTIES_H__ */