From d73691c64e05650d838aaeb7da94fd8bdfb60907 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 13 Jul 2025 04:46:22 +0900 Subject: [PATCH] quotacheck: introduce string table for quota check mode No functional change, just refactoring. --- src/quotacheck/quotacheck.c | 39 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index b98819f0ef..49d63d77d0 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -7,10 +7,26 @@ #include "main-func.h" #include "proc-cmdline.h" #include "process-util.h" +#include "string-table.h" #include "string-util.h" -static bool arg_skip = false; -static bool arg_force = false; +typedef enum QuotaCheckMode { + QUOTA_CHECK_AUTO, + QUOTA_CHECK_FORCE, + QUOTA_CHECK_SKIP, + _QUOTA_CHECK_MODE_MAX, + _QUOTA_CHECK_MODE_INVALID = -EINVAL, +} QuotaCheckMode; + +static QuotaCheckMode arg_mode = QUOTA_CHECK_AUTO; + +static const char * const quota_check_mode_table[_QUOTA_CHECK_MODE_MAX] = { + [QUOTA_CHECK_AUTO] = "auto", + [QUOTA_CHECK_FORCE] = "force", + [QUOTA_CHECK_SKIP] = "skip", +}; + +DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(quota_check_mode, QuotaCheckMode); static int parse_proc_cmdline_item(const char *key, const char *value, void *data) { @@ -19,17 +35,12 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat if (proc_cmdline_value_missing(key, value)) return 0; - if (streq(value, "auto")) - arg_force = arg_skip = false; - else if (streq(value, "force")) - arg_force = true; - else if (streq(value, "skip")) - arg_skip = true; - else - log_warning("Invalid quotacheck.mode= value, ignoring: %s", value); + arg_mode = quota_check_mode_from_string(value); + if (arg_mode < 0) + log_warning_errno(arg_mode, "Invalid quotacheck.mode= value, ignoring: %s", value); } else if (streq(key, "forcequotacheck") && !value) - arg_force = true; + arg_mode = QUOTA_CHECK_FORCE; return 0; } @@ -49,10 +60,10 @@ static int run(int argc, char *argv[]) { if (r < 0) log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); - if (!arg_force) { - if (arg_skip) - return 0; + if (arg_mode == QUOTA_CHECK_SKIP) + return 0; + if (arg_mode == QUOTA_CHECK_AUTO) { /* This is created by systemd-fsck when fsck detected and corrected errors. In normal * operations quotacheck is not needed. */ if (access("/run/systemd/quotacheck", F_OK) < 0) {