Whamcloud - gitweb
b=3550
[fs/lustre-release.git] / lustre / utils / lfs.c
index 658a921..71095ab 100644 (file)
@@ -29,7 +29,6 @@
 #include <getopt.h>
 #include <string.h>
 #include <mntent.h>
-#include <portals/api-support.h>
 #include <portals/ptlctl.h>
 
 #include <liblustre.h>
@@ -42,6 +41,7 @@
 
 /* all functions */
 static int lfs_setstripe(int argc, char **argv);
+static int lfs_dirstripe(int argc, char **argv);
 static int lfs_find(int argc, char **argv);
 static int lfs_getstripe(int argc, char **argv);
 static int lfs_osts(int argc, char **argv);
@@ -56,7 +56,12 @@ command_t cmdlist[] = {
          "usage: setstripe <filename|dirname> <stripe size> <stripe start> <stripe count>\n"
          "\tstripe size:  Number of bytes in each stripe (0 default)\n"
          "\tstripe start: OST index of first stripe (-1 default)\n"
-         "\tstripe count: Number of OSTs to stripe over (0 default, -1 all)"},
+         "\tstripe count: Number of OSTs to stripe over (0 default)"},
+        {"dirstripe", lfs_dirstripe, 0,
+         "To create a new dir with a specific striping pattern.\n"
+         "usage: dirstripe <dirname> <stripe count> [<mds idx list>]\n"
+         "\tstripe count: Number of MDSes to stripe over (0 default)\n"
+         "\tmds idx list: List of MDS servers to contain the dir (not implemented)"},
         {"find", lfs_find, 0,
          "To list the extended attributes for a given filename or files in a\n"
          "directory or recursively for all files in a directory tree.\n"
@@ -113,7 +118,7 @@ static int lfs_setstripe(int argc, char **argv)
                 return CMD_HELP;
         }
 
-        result = op_create_file(argv[1], st_size, st_offset, st_count);
+        result = llapi_file_create(argv[1], st_size, st_offset, st_count, 0);
         if (result)
                 fprintf(stderr, "error: %s: create stripe file failed\n",
                                 argv[0]);
@@ -121,6 +126,31 @@ static int lfs_setstripe(int argc, char **argv)
         return result;
 }
 
+static int lfs_dirstripe(int argc, char **argv)
+{
+        int result;
+        int st_count;
+        char *end;
+
+        if (argc != 3)
+                return CMD_HELP;
+
+        // get the stripe size
+        st_count = strtoul(argv[2], &end, 0);
+        if (*end != '\0') {
+                fprintf(stderr, "error: %s: bad count '%s'\n",
+                                argv[0], argv[2]);
+                return CMD_HELP;
+        }
+
+        result = op_create_dir(argv[1], st_count);
+        if (result)
+                fprintf(stderr, "error: %s: create stripe dir failed\n",
+                                argv[0]);
+
+        return result;
+}
+
 static int lfs_find(int argc, char **argv)
 {
         struct option long_opts[] = {
@@ -174,7 +204,7 @@ static int lfs_find(int argc, char **argv)
                 return CMD_HELP;
 
         do {
-                rc = op_find(argv[optind], obduuid, recursive, verbose, quiet);
+                rc = llapi_find(argv[optind], obduuid, recursive,verbose,quiet);
         } while (++optind < argc && !rc);
 
         if (rc)
@@ -193,7 +223,7 @@ static int lfs_getstripe(int argc, char **argv)
         optind = 1;
 
         do {
-                rc = op_find(argv[optind], obduuid, 0, 0, 0);
+                rc = llapi_find(argv[optind], obduuid, 0, 0, 0);
         } while (++optind < argc && !rc);
 
         if (rc)
@@ -222,10 +252,11 @@ static int lfs_osts(int argc, char **argv)
                 mnt = getmntent(fp);
                 while (feof(fp) == 0 && ferror(fp) ==0) {
                         if (llapi_is_lustre_mnttype(mnt->mnt_type)) {
-                                rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0);
+                                rc = llapi_find(mnt->mnt_dir, obduuid, 0, 0, 0);
                                 if (rc)
-                                        fprintf(stderr, "error: lfs osts failed for %s\n",
-                                                mnt->mnt_dir);
+                                        fprintf(stderr,
+                                               "error: lfs osts failed on %s\n",
+                                               mnt->mnt_dir);
                         }
                         mnt = getmntent(fp);
                 }
@@ -240,25 +271,25 @@ static int lfs_check(int argc, char **argv)
         int rc;
         FILE *fp;
         struct mntent *mnt = NULL;
-        int type_num = 1;
-        char *obd_type_p[2];
+        int num_types = 1;
+        char *obd_types[2];
         char obd_type1[4];
         char obd_type2[4];
 
         if (argc != 2)
                 return CMD_HELP;
 
-        obd_type_p[1]=obd_type1;
-        obd_type_p[2]=obd_type2;
-
-        if (strcmp(argv[1],"osts")==0) {
-                strcpy(obd_type_p[0],"osc");
-        } else if (strcmp(argv[1],"mds")==0) {
-                strcpy(obd_type_p[0],"mdc");
-        } else if (strcmp(argv[1],"servers")==0) {
-                type_num=2;
-                strcpy(obd_type_p[0],"osc");
-                strcpy(obd_type_p[1],"mdc");
+        obd_types[1] = obd_type1;
+        obd_types[2] = obd_type2;
+
+        if (strcmp(argv[1], "osts") == 0) {
+                strcpy(obd_types[0], "osc");
+        } else if (strcmp(argv[1], "mds") == 0) {
+                strcpy(obd_types[0], "mdc");
+        } else if (strcmp(argv[1], "servers") == 0) {
+                num_types = 2;
+                strcpy(obd_types[0], "osc");
+                strcpy(obd_types[1], "mdc");
         } else {
                 fprintf(stderr, "error: %s: option '%s' unrecognized\n",
                                 argv[0], argv[1]);
@@ -279,7 +310,7 @@ static int lfs_check(int argc, char **argv)
                 endmntent(fp);
         }
 
-        rc = op_check(type_num,obd_type_p,mnt->mnt_dir);
+        rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir);
 
         if (rc)
                 fprintf(stderr, "error: %s: %s status failed\n",
@@ -317,9 +348,9 @@ static int lfs_catinfo(int argc, char **argv)
 
         if (mnt) {
                 if (argc == 3)
-                        rc = op_catinfo(mnt->mnt_dir, argv[1], argv[2]);
+                        rc = llapi_catinfo(mnt->mnt_dir, argv[1], argv[2]);
                 else
-                        rc = op_catinfo(mnt->mnt_dir, argv[1], NULL);
+                        rc = llapi_catinfo(mnt->mnt_dir, argv[1], NULL);
         } else {
                 fprintf(stderr, "no lustre_lite mounted.\n");
                 rc = -1;