]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_quota: add -d option to limit directory depth
authorArkadiusz Miśkiewicz <arekm@maven.pl>
Thu, 29 Jan 2009 21:51:45 +0000 (22:51 +0100)
committerChristoph Hellwig <hch@brick.lst.de>
Thu, 29 Jan 2009 21:51:45 +0000 (22:51 +0100)
xfs_quota project directory depth processing can now be limited
to certain depth. For example: xfs_quota -x -c "project -d 2 -s 10"
limits recursion to level 2.

Signed-off-by: Arkadiusz Miśkiewicz <arekm@maven.pl>
Reviewed-by: Donald Douwsma <ddouwsma@bigpond.net.au>
Reviewed-by: Christoph Hellwig <hch@lst.de>
quota/project.c

index b4171e551e6b1064dd7ad3e3152d49bcbd43d71d..f2ff19be45a1f8c98f21632d1cfa90928da11d86 100644 (file)
@@ -23,6 +23,7 @@
 
 static cmdinfo_t project_cmd;
 static prid_t prid;
+static int recurse_depth = -1;
 
 enum {
        CHECK_PROJECT   = 0x1,
@@ -75,6 +76,10 @@ project_help(void)
 " which do not have the project ID of the rest of the tree, or if the inode\n"
 " flag is not set.\n"
 "\n"
+" The -d <depth> option allows to descend at most <depth> levels of directories\n"
+" below the command line arguments. -d 0 means only apply the actions\n"
+" to the top level of the projects. -d -1 means no recursion limit (default).\n"
+"\n"
 " The /etc/projid and /etc/projects file formats are simple, and described\n"
 " on the xfs_quota man page.\n"
 "\n"));
@@ -90,6 +95,9 @@ check_project(
        struct fsxattr          fsx;
        int                     fd;
 
+       if (recurse_depth >= 0 && data->level > recurse_depth)
+               return -1;
+
        if (flag == FTW_NS ){
                exitcode = 1;
                fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
@@ -132,6 +140,9 @@ clear_project(
        struct fsxattr          fsx;
        int                     fd;
 
+       if (recurse_depth >= 0 && data->level > recurse_depth)
+               return -1;
+
        if (flag == FTW_NS ){
                exitcode = 1;
                fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
@@ -176,6 +187,9 @@ setup_project(
        struct fsxattr          fsx;
        int                     fd;
 
+       if (recurse_depth >= 0 && data->level > recurse_depth)
+               return -1;
+
        if (flag == FTW_NS ){
                exitcode = 1;
                fprintf(stderr, _("%s: cannot stat file %s\n"), progname, path);
@@ -219,15 +233,15 @@ project_operations(
        switch (type) {
        case CHECK_PROJECT:
                printf(_("Checking project %s (path %s)...\n"), project, dir);
-               nftw(dir, check_project, 100, FTW_PHYS|FTW_MOUNT|FTW_DEPTH);
+               nftw(dir, check_project, 100, FTW_PHYS|FTW_MOUNT);
                break;
        case SETUP_PROJECT:
                printf(_("Setting up project %s (path %s)...\n"), project, dir);
-               nftw(dir, setup_project, 100, FTW_PHYS|FTW_MOUNT|FTW_DEPTH);
+               nftw(dir, setup_project, 100, FTW_PHYS|FTW_MOUNT);
                break;
        case CLEAR_PROJECT:
                printf(_("Clearing project %s (path %s)...\n"), project, dir);
-               nftw(dir, clear_project, 100, FTW_PHYS|FTW_MOUNT|FTW_DEPTH);
+               nftw(dir, clear_project, 100, FTW_PHYS|FTW_MOUNT);
                break;
        }
 }
@@ -249,8 +263,9 @@ project(
                count++;
        }
 
-       printf(_("Processed %d %s paths for project %s\n"),
-                count, projects_file, project);
+       printf(_("Processed %d %s paths for project %s with recursion depth %s (%d)\n"),
+                count, projects_file, project,
+                recurse_depth < 0 ? _("infinite") : _("limited"), recurse_depth);
 }
 
 static int
@@ -260,11 +275,16 @@ project_f(
 {
        int             c, type = 0;
 
-       while ((c = getopt(argc, argv, "csC")) != EOF) {
+       while ((c = getopt(argc, argv, "cd:sC")) != EOF) {
                switch (c) {
                case 'c':
                        type = CHECK_PROJECT;
                        break;
+               case 'd':
+                       recurse_depth = atoi(optarg);
+                       if (recurse_depth < 0)
+                               recurse_depth = -1;
+                       break;
                case 's':
                        type = SETUP_PROJECT;
                        break;
@@ -311,7 +331,7 @@ project_init(void)
        project_cmd.name = _("project");
        project_cmd.altname = _("tree");
        project_cmd.cfunc = project_f;
-       project_cmd.args = _("[-c|-s|-C] project ...");
+       project_cmd.args = _("[-c|-s|-C|-d <depth>] project ...");
        project_cmd.argmin = 1;
        project_cmd.argmax = -1;
        project_cmd.oneline = _("check, setup or clear project quota trees");