]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: libxcmd: encapsulate fs_table initialization
authorAlex Elder <aelder@sgi.com>
Mon, 3 Oct 2011 12:49:17 +0000 (12:49 +0000)
committerAlex Elder <aelder@sgi.com>
Thu, 6 Oct 2011 20:19:29 +0000 (15:19 -0500)
Change fs_table_initialise() so it takes an array of mount points
and an array of project identifiers as arguments (along with their
respective sizes).

Change the quota code to provide fs_table_initialise() these arrays
rather than doing the individual mount point and project insertion
by itself.  Other users just pass 0 counts, which results in filling
fs_table with entries for all mounted filesystems and all defined
projects.

This allows a few fs_table functions to be given private scope.

Signed-off-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
growfs/xfs_growfs.c
include/path.h
io/parent.c
libxcmd/paths.c
quota/init.c

index 98ce5df6d2f41bdc4c5e91b28f3867d8215e8b8f..a6d298bf2cb906153f1d589151e94f3c2e7711a2 100644 (file)
@@ -193,7 +193,7 @@ main(int argc, char **argv)
        if (dflag + lflag + rflag == 0)
                aflag = 1;
 
-       fs_table_initialise();
+       fs_table_initialise(0, NULL, 0, NULL);
        fs = fs_table_lookup(argv[optind], FS_MOUNT_POINT);
        if (!fs) {
                fprintf(stderr, _("%s: %s is not a mounted XFS filesystem\n"),
index b8c8b31587c5a95b8c387df4b7f46be0187351b6..757ba49e1a38621dc04f38f0d51f92f93e10bc72 100644 (file)
@@ -47,11 +47,9 @@ extern fs_path_t *fs_table;  /* array of entries in fs table  */
 extern fs_path_t *fs_path;     /* current entry in the fs table */
 extern char *mtab_file;
 
-extern void fs_table_initialise(void);
+extern void fs_table_initialise(int, char *[], int, char *[]);
 extern void fs_table_destroy(void);
 
-extern void fs_table_insert_mount(char *__mount);
-extern void fs_table_insert_project(char *__project);
 extern void fs_table_insert_project_path(char *__dir, uint __projid);
 
 
index 5d356e6ec34a9d5e6d250b6a8fbf4d94ffefdb06..47faaa00279f69e7d9f681cda3fe7b24675ea710 100644 (file)
@@ -377,7 +377,7 @@ parent_f(int argc, char **argv)
 
        if (!tab_init) {
                tab_init = 1;
-               fs_table_initialise();
+               fs_table_initialise(0, NULL, 0, NULL);
        }
        fs = fs_table_lookup(file->name, FS_MOUNT_POINT);
        if (!fs) {
index ed931101d97b9ce78a9c06ddc7c6e72d11b090ce..755307ef43a82346dcdc521b805b98ab40882c46 100644 (file)
@@ -365,7 +365,7 @@ fs_mount_point_from_path(
        return fs;
 }
 
-void
+static void
 fs_table_insert_mount(
        char            *mount)
 {
@@ -424,7 +424,7 @@ fs_table_initialise_projects(
        return error;
 }
 
-void
+static void
 fs_table_insert_project(
        char            *project)
 {
@@ -444,20 +444,47 @@ fs_table_insert_project(
        }
 }
 
+/*
+ * Initialize fs_table to contain the given set of mount points and
+ * projects.  If mount_count is zero, mounts is ignored and the
+ * table is populated with mounted filesystems.  If project_count is
+ * zero, projects is ignored and the table is populated with all
+ * projects defined in the projects file.
+ */
 void
-fs_table_initialise(void)
+fs_table_initialise(
+       int     mount_count,
+       char    *mounts[],
+       int     project_count,
+       char    *projects[])
 {
-       int             error;
+       int     error;
+       int     i;
 
-       error = fs_table_initialise_mounts(NULL);
-       if (!error)
+       if (mount_count) {
+               for (i = 0; i < mount_count; i++)
+                       fs_table_insert_mount(mounts[i]);
+       } else {
+               error = fs_table_initialise_mounts(NULL);
+               if (error)
+                       goto out_exit;
+       }
+       if (project_count) {
+               for (i = 0; i < project_count; i++)
+                       fs_table_insert_project(projects[i]);
+       } else {
                error = fs_table_initialise_projects(NULL);
-       if (error) {
-               fs_table_destroy();
-               fprintf(stderr, _("%s: cannot initialise path table: %s\n"),
-                       progname, strerror(error));
-               exit(1);
+               if (error)
+                       goto out_exit;
        }
+
+       return;
+
+out_exit:
+       fs_table_destroy();
+       fprintf(stderr, _("%s: cannot initialise path table: %s\n"),
+               progname, strerror(error));
+       exit(1);
 }
 
 void 
index 96b6389394f8281b41cc664e5c342f42ecf801bd..3293b90d7b6827f3e0ebee927aa4130327cdb419 100644 (file)
@@ -135,19 +135,8 @@ init(
                }
        }
 
-       if (optind == argc) {
-               fs_table_initialise();
-       } else {
-               while (optind < argc)
-                       fs_table_insert_mount(argv[optind++]);
-               if (!nprojopts)
-                       fs_table_insert_project(NULL);
-               else
-                       for (c = 0; c < nprojopts; c++)
-                               fs_table_insert_project(projopts[c]);
-       }
-       if (projopts)
-               free(projopts);
+       fs_table_initialise(argc - optind, &argv[optind], nprojopts, projopts);
+       free(projopts);
 
        init_commands();
        add_args_command(init_args_command);