]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
libfrog: define a self_healing filesystem property
authorDarrick J. Wong <djwong@kernel.org>
Fri, 26 Jul 2024 20:32:43 +0000 (13:32 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Wed, 31 Jul 2024 01:45:40 +0000 (18:45 -0700)
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libfrog/fsproperties.c
libfrog/fsproperties.h

index c317d15c1de0b62fc58f03cf182e7c5966f90cf0..4ccd0edd845386272b1ea409b4e16dde98ed58a0 100644 (file)
@@ -29,11 +29,49 @@ __fsprops_lookup(
 #define fsprops_lookup(values, value) \
        __fsprops_lookup((values), ARRAY_SIZE(values), (value))
 
+/* Self-healing fs property */
+
+static const char *fsprop_self_healing_values[] = {
+       [FSPROP_SELFHEAL_UNSET]         = NULL,
+       [FSPROP_SELFHEAL_NONE]          = "none",
+       [FSPROP_SELFHEAL_CHECK]         = "check",
+       [FSPROP_SELFHEAL_OPTIMIZE]      = "optimize",
+       [FSPROP_SELFHEAL_REPAIR]        = "repair",
+};
+
+/* Convert the self_healing property enum to a string. */
+const char *
+fsprop_write_self_healing(
+       enum fsprop_self_healing        x)
+{
+       if (x <= FSPROP_SELFHEAL_UNSET ||
+           x >= ARRAY_SIZE(fsprop_self_healing_values))
+               return NULL;
+       return fsprop_self_healing_values[x];
+}
+
+/*
+ * Turn a self_healing value string into an enumerated value, or _UNSET if it's
+ * not recognized.
+ */
+enum fsprop_self_healing
+fsprop_read_self_healing(
+       const char      *value)
+{
+       int ret = fsprops_lookup(fsprop_self_healing_values, value);
+       if (ret < 0)
+               return FSPROP_SELFHEAL_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_SELF_HEALING_NAME))
+               return fsprops_lookup(fsprop_self_healing_values, value) >= 0;
+
        return true;
 }
index 6dee8259a43744d1dda0c4bc7c6a6bb2b2fd1836..7004d339715abba5a50a3564cf2e27df17de1098 100644 (file)
@@ -47,4 +47,17 @@ bool fsprop_validate(const char *name, const char *value);
 
 /* Specific Filesystem Properties */
 
+#define FSPROP_SELF_HEALING_NAME       "self_healing"
+
+enum fsprop_self_healing {
+       FSPROP_SELFHEAL_UNSET = 0,      /* do not set property */
+       FSPROP_SELFHEAL_NONE,           /* no background scrubs */
+       FSPROP_SELFHEAL_CHECK,          /* allow only background checking */
+       FSPROP_SELFHEAL_OPTIMIZE,       /* allow background optimization */
+       FSPROP_SELFHEAL_REPAIR,         /* allow background repair & optimization */
+};
+
+const char *fsprop_write_self_healing(enum fsprop_self_healing x);
+enum fsprop_self_healing fsprop_read_self_healing(const char *value);
+
 #endif /* __LIBFROG_FSPROPERTIES_H__ */