diff mbox series

[1/3] libfrog: define a self_healing filesystem property

Message ID 172230941003.1544039.14396399914334113330.stgit@frogsfrogsfrogs (mailing list archive)
State Accepted, archived
Headers show
Series [1/3] libfrog: define a self_healing filesystem property | expand

Commit Message

Darrick J. Wong July 30, 2024, 3:21 a.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 libfrog/fsproperties.c |   38 ++++++++++++++++++++++++++++++++++++++
 libfrog/fsproperties.h |   13 +++++++++++++
 2 files changed, 51 insertions(+)

Comments

Christoph Hellwig July 30, 2024, 9:56 p.m. UTC | #1
self-healing sounds a little imposterous :)

The code itself looks fine though.
Darrick J. Wong July 30, 2024, 11:51 p.m. UTC | #2
On Tue, Jul 30, 2024 at 02:56:50PM -0700, Christoph Hellwig wrote:
> self-healing sounds a little imposterous :)

Do you have a better suggestion?

"auto_fsck"?

"auto_unf***"? ;)

"background_fsck"?

"background_scrub"?

"patrol_scrub"? <ugh>

> The code itself looks fine though.

--D
Christoph Hellwig July 31, 2024, 3:43 p.m. UTC | #3
On Tue, Jul 30, 2024 at 04:51:03PM -0700, Darrick J. Wong wrote:
> On Tue, Jul 30, 2024 at 02:56:50PM -0700, Christoph Hellwig wrote:
> > self-healing sounds a little imposterous :)
> 
> Do you have a better suggestion?

Heh.  Maybe actually make it to separate ones?
auto_scrub and auto_repair?
Darrick J. Wong July 31, 2024, 5:45 p.m. UTC | #4
On Wed, Jul 31, 2024 at 08:43:19AM -0700, Christoph Hellwig wrote:
> On Tue, Jul 30, 2024 at 04:51:03PM -0700, Darrick J. Wong wrote:
> > On Tue, Jul 30, 2024 at 02:56:50PM -0700, Christoph Hellwig wrote:
> > > self-healing sounds a little imposterous :)
> > 
> > Do you have a better suggestion?
> 
> Heh.  Maybe actually make it to separate ones?
> auto_scrub and auto_repair?

I don't want multiple attributes because that enables sysadmins to give
us mixed messages.  What happens if we encounter this:

auto_scrub=no
auto_repair=yes
auto_optimize=paula

?

Better just to have one attribute and make them pick the one they want.

How about auto_fsck={none,check,optimize,repair} ?

--D
Christoph Hellwig July 31, 2024, 7:43 p.m. UTC | #5
On Wed, Jul 31, 2024 at 10:45:31AM -0700, Darrick J. Wong wrote:
> Better just to have one attribute and make them pick the one they want.
> 
> How about auto_fsck={none,check,optimize,repair} ?

Sounds good.
diff mbox series

Patch

diff --git a/libfrog/fsproperties.c b/libfrog/fsproperties.c
index c317d15c1de0..4ccd0edd8453 100644
--- a/libfrog/fsproperties.c
+++ b/libfrog/fsproperties.c
@@ -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;
 }
diff --git a/libfrog/fsproperties.h b/libfrog/fsproperties.h
index 6dee8259a437..7004d339715a 100644
--- a/libfrog/fsproperties.h
+++ b/libfrog/fsproperties.h
@@ -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__ */