X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Flfs.c;h=7a8c37466fa374d4c6ecf00db028e107b8f9547c;hb=9daaacb744531f08d67f851e9d1bed00572dddd8;hp=8f20c8eeb48dd5d001251b7ead466738caa52ed8;hpb=63bd163f2fe0c885ec93004609635c7bdf945253;p=fs%2Flustre-release.git diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 8f20c8e..7a8c374 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -29,26 +29,22 @@ #include #include #include -#include #include #include #include +#include +#include #include "parser.h" #include "obdctl.h" -extern int op_create_file(char *name, long stripe_size, int stripe_offset, - int stripe_count); -extern int op_find(char *path, struct obd_uuid *obduuid, int recursive, - int verbose, int quiet); -extern int op_check(int type_num, char **obd_type_p, char *dir); -extern int op_catinfo(char *dir, char *keyword, char *node_name); - /* 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_showfid(int argc, char **argv); static int lfs_osts(int argc, char **argv); static int lfs_check(int argc, char **argv); static int lfs_catinfo(int argc, char **argv); @@ -56,25 +52,36 @@ static int lfs_catinfo(int argc, char **argv); /* all avaialable commands */ command_t cmdlist[] = { {"setstripe", lfs_setstripe, 0, - "blah...\n" - "usage: setstripe \n" + "Create a new file with a specific striping pattern or\n" + "Set the default striping pattern on an existing directory\n" + "usage: setstripe \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)"}, + {"dirstripe", lfs_dirstripe, 0, + "To create a new dir with a specific striping pattern.\n" + "usage: dirstripe []\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, - "blah...\n" + "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" "usage: find [--obd ] [--quiet | --verbose] [--recursive] ..."}, {"getstripe", lfs_getstripe, 0, - "blah...\n" - "usage:getstripe "}, - {"check", lfs_check, 0, - "blah...\n" + "To list the striping pattern for given filename.\n" + "usage: getstripe "}, + {"showfid", lfs_showfid, 0, + "To list the fid and store cookie for given filename.\n" + "usage: showfid [--quiet | --verbose] [--recursive] ..."}, + {"check", lfs_check, 0, + "Display the status of MDS or OSTs (as specified in the command)\n" + "or all the servers (MDS and OSTs).\n" "usage: check "}, {"catinfo", lfs_catinfo, 0, "Show information of specified type logs.\n" - "usage: catinfo [node name]" - "keywords are one of followings: config, deletions.\n" - "client node name must be provided when use keyword config."}, + "usage: catinfo {keyword} [node name]\n" + "\tkeywords are one of followings: config, deletions.\n" + "\tnode name must be provided when use keyword config."}, {"osts", lfs_osts, 0, "osts"}, {"help", Parser_help, 0, "help"}, {"exit", Parser_quit, 0, "quit"}, @@ -115,7 +122,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]); @@ -123,6 +130,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[] = { @@ -176,7 +208,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, 0); } while (++optind < argc && !rc); if (rc) @@ -195,7 +227,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, 0); } while (++optind < argc && !rc); if (rc) @@ -205,13 +237,63 @@ static int lfs_getstripe(int argc, char **argv) return rc; } +static int lfs_showfid(int argc, char **argv) +{ + struct option long_opts[] = { + {"quiet", 0, 0, 'q'}, + {"recursive", 0, 0, 'r'}, + {"verbose", 0, 0, 'v'}, + {0, 0, 0, 0} + }; + char short_opts[] = "hqrv"; + int quiet, verbose, recursive, c, rc; + + optind = 0; + quiet = verbose = recursive = 0; + while ((c = getopt_long(argc, argv, short_opts, + long_opts, NULL)) != -1) { + switch (c) { + case 'q': + quiet++; + verbose = 0; + break; + case 'r': + recursive = 1; + break; + case 'v': + verbose++; + quiet = 0; + break; + case '?': + return CMD_HELP; + break; + default: + fprintf(stderr, "error: %s: option '%s' unrecognized\n", + argv[0], argv[optind - 1]); + return CMD_HELP; + } + } + + if (optind >= argc) + return CMD_HELP; + + do { + rc = llapi_find(argv[optind], NULL, recursive, verbose, quiet, 1); + } while (++optind < argc && !rc); + + if (rc) + fprintf(stderr, "error: %s: find failed\n", argv[0]); + + return rc; +} + static int lfs_osts(int argc, char **argv) { FILE *fp; struct mntent *mnt = NULL; struct obd_uuid *obduuid = NULL; int rc=0; - + if (argc != 1) return CMD_HELP; @@ -223,17 +305,18 @@ static int lfs_osts(int argc, char **argv) } else { mnt = getmntent(fp); while (feof(fp) == 0 && ferror(fp) ==0) { - if (strcmp(mnt->mnt_type, "lustre_lite") == 0) { - rc = op_find(mnt->mnt_dir, obduuid, 0, 0, 0); + if (llapi_is_lustre_mnttype(mnt->mnt_type)) { + rc = llapi_find(mnt->mnt_dir, obduuid, 0, 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); } endmntent(fp); } - + return rc; } @@ -242,29 +325,29 @@ 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]); - return CMD_HELP; + argv[0], argv[1]); + return CMD_HELP; } fp = setmntent(MOUNTED, "r"); @@ -274,19 +357,19 @@ static int lfs_check(int argc, char **argv) } else { mnt = getmntent(fp); while (feof(fp) == 0 && ferror(fp) ==0) { - if (strcmp(mnt->mnt_type, "lustre_lite") == 0) + if (llapi_is_lustre_mnttype(mnt->mnt_type)) break; mnt = getmntent(fp); } 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", argv[0],argv[1]); - + return rc; } @@ -296,7 +379,7 @@ static int lfs_catinfo(int argc, char **argv) FILE *fp; struct mntent *mnt = NULL; int rc; - + if (argc < 2 || (!strcmp(argv[1],"config") && argc < 3)) return CMD_HELP; @@ -305,12 +388,12 @@ static int lfs_catinfo(int argc, char **argv) fp = setmntent(MOUNTED, "r"); if (fp == NULL) { - fprintf(stderr, "setmntent(%s): %s:", MOUNTED, + fprintf(stderr, "setmntent(%s): %s:", MOUNTED, strerror(errno)); } else { mnt = getmntent(fp); while (feof(fp) == 0 && ferror(fp) == 0) { - if (strcmp(mnt->mnt_type, "lustre_lite") == 0) + if (llapi_is_lustre_mnttype(mnt->mnt_type)) break; mnt = getmntent(fp); } @@ -319,9 +402,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; @@ -335,13 +418,13 @@ int main(int argc, char **argv) int rc; setlinebuf(stdout); - + ptl_initialize(argc, argv); if (obd_initialize(argc, argv) < 0) exit(2); if (dbg_initialize(argc, argv) < 0) exit(3); - + Parser_init("lfs > ", cmdlist); if (argc > 1) {