xfs_quota: allow operation on foreign filesystem types
PATCH 1/1 xfs_quota: allow operation on foreign filesystem types
From: Dave Chinner <[email protected]>
This allows xfs_quota to be used on ext4 for project quota testing in xfstests.
--- include/command.h | 3 ++- include/path.h | 1 + io/init.h | 2 +- libxcmd/paths.c | 7 +++---- quota/free.c | 1 + quota/init.c | 16 ++++++++++++++++ quota/path.c | 5 +++-- quota/project.c | 1 + quota/quota.c | 1 + quota/report.c | 2 ++ quota/state.c | 2 ++ 11 files changed, 33 insertions(+), 8 deletions(-)
include/command.h +2 -1
@@ -20,7 +20,8 @@#include <sys/time.h> -#define CMD_FLAG_GLOBAL ((int)0x80000000)/* don't iterate "args" */ +#define CMD_FLAG_GLOBAL (1<<31)/* don't iterate "args" */ +#define CMD_FLAG_FOREIGN_OK (1<<30)/* command not restricted to XFS */ typedef int (*cfunc_t )(int argc,char **argv);typedef void (*helpfunc_t )(void );
include/path.h +1 -0
@@ -29,6 +29,7 @@#define FS_MOUNT_POINT (1<<0)#define FS_PROJECT_PATH (1<<1) +#define FS_FOREIGN (1<<2) typedef struct fs_path { char *fs_name; /* Data device for filesystem */
io/init.h +1 -1
@@ -18,7 +18,7 @@#define CMD_NOFILE_OK (1<<0)/* command doesn't need an open file */ #define CMD_NOMAP_OK (1<<1)/* command doesn't need a mapped region */ -#define CMD_FOREIGN_OK (1<<2)/* command not restricted to XFS files */ +#define CMD_FOREIGN_OK CMD_FLAG_FOREIGN_OKextern char *progname;extern int exitcode;
libxcmd/paths.c +3 -4
@@ -113,6 +113,9 @@ fs_table_insert( goto out_nodev; } +if (!platform_test_xfs_path (dir)) + flags |=FS_FOREIGN ; +/* * Make copies of the directory and data device path. * The log device and real-time device, if non-null,
@@ -301,8 +304,6 @@ fs_table_initialise_mounts(return errno;while ((mnt =getmntent (mtp)) !=NULL ) { -if (strcmp (mnt->mnt_type,"xfs" ) !=0 ) -continue ;if (!realpath (mnt->mnt_dir, rmnt_dir))continue ;if (!realpath (mnt->mnt_fsname, rmnt_fsname))
@@ -360,8 +361,6 @@ fs_table_initialise_mounts(return errno;for (i =0 ; i < count; i++) { -if (strcmp (stats[i].f_fstypename,"xfs" ) !=0 ) -continue ;if (!realpath (stats[i].f_mntfromname, rmntfromname))continue ;if (!realpath (stats[i].f_mntonname, rmntonname))
quota/free.c +1 -0
@@ -371,6 +371,7 @@ free_init(void) free_cmd.args =_ ("[-bir] [-hn] [-f file]" ); free_cmd.oneline =_ ("show free and used counts for blocks and inodes" ); free_cmd.help = free_help; + free_cmd.flags =CMD_FLAG_FOREIGN_OK ;add_command (&free_cmd); }
quota/init.c +16 -0
@@ -92,6 +92,21 @@ init_args_command(return index; } +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 ; +} + static void init( int argc,
@@ -140,6 +155,7 @@ init(init_commands ();add_args_command (init_args_command); +add_check_command (init_check_command);/* * Ensure that global commands don't end up with an invalid path pointer
quota/path.c +3 -2
@@ -42,6 +42,7 @@ printpath(if (number) {printf (_ ("%c%03d%c " ), braces?'[' :' ' , index, braces?']' :' ' ); } +printf ("%s " , (path->fs_flags &FS_FOREIGN ) ?"(F)" :" " );printf (_ ("%-19s %s" ), path->fs_dir, path->fs_name);if (path->fs_flags &FS_PROJECT_PATH ) { prj =getprprid (path->fs_prid);
@@ -127,7 +128,7 @@ path_init(void) path_cmd.cfunc = path_f; path_cmd.argmin =0 ; path_cmd.argmax =1 ; - path_cmd.flags =CMD_FLAG_GLOBAL ; + path_cmd.flags =CMD_FLAG_GLOBAL |CMD_FLAG_FOREIGN_OK ; path_cmd.oneline =_ ("set current path, or show the list of paths" ); print_cmd.name ="print" ;
@@ -135,7 +136,7 @@ path_init(void) print_cmd.cfunc = print_f; print_cmd.argmin =0 ; print_cmd.argmax =0 ; - print_cmd.flags =CMD_FLAG_GLOBAL ; + print_cmd.flags =CMD_FLAG_GLOBAL |CMD_FLAG_FOREIGN_OK ; print_cmd.oneline =_ ("list known mount points and projects" );if (expert)
quota/project.c +1 -0
@@ -355,6 +355,7 @@ project_init(void) project_cmd.argmax =-1 ; project_cmd.oneline =_ ("check, setup or clear project quota trees" ); project_cmd.help = project_help; + project_cmd.flags =CMD_FLAG_FOREIGN_OK ;if (expert)add_command (&project_cmd);
quota/quota.c +1 -0
@@ -464,6 +464,7 @@ quota_init(void) quota_cmd.args =_ ("[-bir] [-gpu] [-hnNv] [-f file] [id|name]..." ); quota_cmd.oneline =_ ("show usage and limits" ); quota_cmd.help = quota_help; + quota_cmd.flags =CMD_FLAG_FOREIGN_OK ;add_command ("a_cmd); }
quota/report.c +2 -0
@@ -658,6 +658,7 @@ report_init(void) dump_cmd.args =_ ("[-gpu] [-f file]" ); dump_cmd.oneline =_ ("dump quota information for backup utilities" ); dump_cmd.help = dump_help; + dump_cmd.flags =CMD_FLAG_FOREIGN_OK ; report_cmd.name ="report" ; report_cmd.altname ="repquota" ;
@@ -668,6 +669,7 @@ report_init(void) report_cmd.args =_ ("[-bir] [-gpu] [-ahnt] [-f file]" ); report_cmd.oneline =_ ("report filesystem quota information" ); report_cmd.help = report_help; + report_cmd.flags =CMD_FLAG_FOREIGN_OK ;if (expert) {add_command (&dump_cmd);
quota/state.c +2 -0
@@ -527,6 +527,7 @@ state_init(void) off_cmd.args =_ ("[-gpu] [-v]" ); off_cmd.oneline =_ ("permanently switch quota off for a path" ); off_cmd.help = off_help; + off_cmd.flags =CMD_FLAG_FOREIGN_OK ; state_cmd.name ="state" ; state_cmd.cfunc = state_f;
@@ -535,6 +536,7 @@ state_init(void) state_cmd.args =_ ("[-gpu] [-a] [-v] [-f file]" ); state_cmd.oneline =_ ("get overall quota state information" ); state_cmd.help = state_help; + state_cmd.flags =CMD_FLAG_FOREIGN_OK ; enable_cmd.name ="enable" ; enable_cmd.cfunc = enable_f;
Signature · 1 line
2.5.0
Quoted 7 lines · Dave Chinner
From: Dave Chinner <[email protected]>
This allows
xfs_quotato be used on ext4 for project quota testing in xfstests.Signed-off-by Dave Chinner <[email protected]>---
...
Quoted 13 lines
quota/report.c +1
-0@@ -658,6 +658,7 @@ report_init(void) dump_cmd.args =_ ("[-gpu] [-f file]" ); dump_cmd.oneline =_ ("dump quota information for backup utilities" ); dump_cmd.help = dump_help; + dump_cmd.flags =CMD_FLAG_FOREIGN_OK ; report_cmd.name ="report" ; report_cmd.altname ="repquota" ;
quota/report.c report_init(void) · line 672
Quoted 4 lines
quota/report.c +1
-0@@ -668,6 +669,7 @@ report_init(void) report_cmd.args =_ ("[-bir] [-gpu] [-ahnt] [-f file]" ); report_cmd.oneline =_ ("report filesystem quota information" ); report_cmd.help = report_help; + report_cmd.flags =CMD_FLAG_FOREIGN_OK ;
There's another
report_cmd.flags = CMD_FLAG_GLOBAL;
above this which gets overwritten here; this command needs to be:
report_cmd.flags = CMD_FLAG_GLOBAL | CMD_FLAG_FOREIGN_OK;
or else
xfs_quota -x -c "report -a"
goes bonkers, iterating in nested loops and printing filesystems multiple times.
It also seems that "report -a" should not be changing defaults this way such that non-xfs filesystems will get printed; this will be an unexpected change to default behavior.
Perhaps a top-level "-f" option to explicitly enable foreign filesystem detection would be best?
-Eric