From: Darrick J. Wong <djwong@xxxxxxxxxx> 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@xxxxxxxxxx> --- libfrog/fsproperties.c | 38 ++++++++++++++++++++++++++++++++++++++ libfrog/fsproperties.h | 13 +++++++++++++ 2 files changed, 51 insertions(+) diff --git a/libfrog/fsproperties.c b/libfrog/fsproperties.c index c317d15c1..72485f627 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)) +/* 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; } diff --git a/libfrog/fsproperties.h b/libfrog/fsproperties.h index b1ac4cdd7..11d6530bc 100644 --- a/libfrog/fsproperties.h +++ b/libfrog/fsproperties.h @@ -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__ */