From b20b6c22cd57f7f1671b7b8acd2c4610fcb9ade2 Mon Sep 17 00:00:00 2001 From: Bill O'Donnell Date: Fri, 26 Aug 2016 11:20:37 +1000 Subject: [PATCH] xfs_quota: certain commands must always be available Add CMD_ALL_FSTYPES to enable basic xfs_quota commands (e.g. help, quit) to be run regardless of the filesystem type we are operating on. Use CMD_FLAG_FOREIGN_OK on commands suitable for foreign filesystems. Refactor init_check_command in quota/init.c for clarity. [ dchinner: CMD_SKIP_CHECK -> CMD_ALL_FSTYPES ] Signed-off-by: Bill O'Donnell Reviewed-by: Dave Chinner Signed-off-by: Dave Chinner --- libxcmd/help.c | 3 ++- libxcmd/quit.c | 3 ++- quota/init.c | 29 ++++++++++++++++++++--------- quota/init.h | 2 ++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/libxcmd/help.c b/libxcmd/help.c index fad0ab98f..8894c7931 100644 --- a/libxcmd/help.c +++ b/libxcmd/help.c @@ -18,6 +18,7 @@ #include "platform_defs.h" #include "command.h" +#include "../quota/init.h" static cmdinfo_t help_cmd; static void help_onecmd(const char *cmd, const cmdinfo_t *ct); @@ -88,7 +89,7 @@ help_init(void) help_cmd.cfunc = help_f; help_cmd.argmin = 0; help_cmd.argmax = 1; - help_cmd.flags = CMD_FLAG_GLOBAL; + help_cmd.flags = CMD_FLAG_GLOBAL | CMD_ALL_FSTYPES; help_cmd.args = _("[command]"); help_cmd.oneline = _("help for one or all commands"); diff --git a/libxcmd/quit.c b/libxcmd/quit.c index 0183b8f78..e0af91629 100644 --- a/libxcmd/quit.c +++ b/libxcmd/quit.c @@ -18,6 +18,7 @@ #include "platform_defs.h" #include "command.h" +#include "../quota/init.h" static cmdinfo_t quit_cmd; @@ -38,7 +39,7 @@ quit_init(void) quit_cmd.cfunc = quit_f; quit_cmd.argmin = -1; quit_cmd.argmax = -1; - quit_cmd.flags = CMD_FLAG_GLOBAL; + quit_cmd.flags = CMD_FLAG_GLOBAL | CMD_ALL_FSTYPES; quit_cmd.oneline = _("exit the program"); add_command(&quit_cmd); diff --git a/quota/init.c b/quota/init.c index 137cd6852..44be3222b 100644 --- a/quota/init.c +++ b/quota/init.c @@ -109,15 +109,26 @@ static int init_check_command( const cmdinfo_t *ct) { - if (fs_path && - !(ct->flags & CMD_FLAG_FOREIGN_OK) && - (fs_path->fs_flags & FS_FOREIGN)) { - fprintf(stderr, - _("foreign mount active, %s command is for XFS filesystems only\n"), - ct->name); - return 0; - } - return 1; + if (!fs_path) + return 1; + + /* Always run commands that we are told to skip here */ + if (ct->flags & CMD_ALL_FSTYPES) + return 1; + + /* if it's an XFS filesystem, always run the command */ + if (!(fs_path->fs_flags & FS_FOREIGN)) + return 1; + + /* If the user specified foreign filesysetms are ok, run it */ + if (foreign_allowed && + (ct->flags & CMD_FLAG_FOREIGN_OK)) + return 1; + + /* foreign filesystem and it's not a valid command! */ + fprintf(stderr, _("%s command is for XFS filesystems only\n"), + ct->name); + return 0; } static void diff --git a/quota/init.h b/quota/init.h index 687985557..4eb44c4d7 100644 --- a/quota/init.h +++ b/quota/init.h @@ -31,3 +31,5 @@ extern void report_init(void); extern void state_init(void); extern void init_cvtnum(unsigned int *, unsigned int *); + +#define CMD_ALL_FSTYPES (1<<0) /* command is always available */ -- 2.47.2