#include <getopt.h>
#include <string.h>
#include <mntent.h>
-#include <portals/api-support.h>
+#include <dirent.h>
+#include <libgen.h>
#include <portals/ptlctl.h>
#include <liblustre.h>
/* 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);
+static int lfs_getfacl(int argc, char **argv);
+static int lfs_setfacl(int argc, char **argv);
/* all avaialable commands */
command_t cmdlist[] = {
{"setstripe", lfs_setstripe, 0,
"Create a new file with a specific striping pattern or\n"
- "Set the default striping pattern on an existing directory\n"
+ "set the default striping pattern on an existing directory or\n"
+ "delete the default striping pattern from an existing directory\n"
"usage: setstripe <filename|dirname> <stripe size> <stripe start> <stripe count>\n"
+ " or \n"
+ " setstripe -d <dirname>\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"
"usage: find [--obd <uuid>] [--quiet | --verbose] [--recursive] <dir|file> ..."},
{"getstripe", lfs_getstripe, 0,
"To list the striping pattern for given filename.\n"
- "usage:getstripe <filename>"},
+ "usage: getstripe <filename>"},
+ {"showfid", lfs_showfid, 0,
+ "To list the fid and store cookie for given filename.\n"
+ "usage: showfid [--quiet | --verbose] [--recursive] <dir|file> ..."},
{"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: catinfo {keyword} [node name]\n"
"\tkeywords are one of followings: config, deletions.\n"
"\tnode name must be provided when use keyword config."},
+ {"getfacl", lfs_getfacl, 0,
+ "Get file access control lists.\n"
+ "usage: getfacl [-dRLPvh] file"},
+ {"setfacl", lfs_setfacl, 0,
+ "Set file access control lists.\n"
+ "usage: setfacl [-bkndRLPvh] [{-m|-x} acl_spec] [{-M|-X} acl_file] file ..."},
{"osts", lfs_osts, 0, "osts"},
{"help", Parser_help, 0, "help"},
{"exit", Parser_quit, 0, "quit"},
/* functions */
static int lfs_setstripe(int argc, char **argv)
{
+ char *fname;
int result;
- long st_size;
- int st_offset, st_count;
+ long st_size = 0;
+ int st_offset = -1, st_count = 0;
char *end;
- if (argc != 5)
+ if (argc != 5 && argc != 3)
return CMD_HELP;
- // get the stripe size
- st_size = strtoul(argv[2], &end, 0);
- if (*end != '\0') {
- fprintf(stderr, "error: %s: bad stripe size '%s'\n",
- argv[0], argv[2]);
- return CMD_HELP;
+ if (argc == 3) {
+ if (strcmp(argv[1], "-d") != 0)
+ return CMD_HELP;
+
+ fname = argv[2];
+ st_size = -1;
+ } else {
+ fname = argv[1];
+
+ // get the stripe size
+ st_size = strtoul(argv[2], &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "error: %s: bad stripe size '%s'\n",
+ argv[0], argv[2]);
+ return CMD_HELP;
+ }
+ // get the stripe offset
+ st_offset = strtoul(argv[3], &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
+ argv[0], argv[3]);
+ return CMD_HELP;
+ }
+ // get the stripe count
+ st_count = strtoul(argv[4], &end, 0);
+ if (*end != '\0') {
+ fprintf(stderr, "error: %s: bad stripe count '%s'\n",
+ argv[0], argv[4]);
+ return CMD_HELP;
+ }
}
- // get the stripe offset
- st_offset = strtoul(argv[3], &end, 0);
- if (*end != '\0') {
- fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
- argv[0], argv[3]);
+
+ result = llapi_file_create(fname, st_size, st_offset, st_count, 0);
+ if (result)
+ fprintf(stderr, "error: %s: create stripe file failed\n",
+ argv[0]);
+
+ 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 count
- st_count = strtoul(argv[4], &end, 0);
+
+ // get the stripe size
+ st_count = strtoul(argv[2], &end, 0);
if (*end != '\0') {
- fprintf(stderr, "error: %s: bad stripe count '%s'\n",
- argv[0], argv[4]);
+ fprintf(stderr, "error: %s: bad count '%s'\n",
+ argv[0], argv[2]);
return CMD_HELP;
}
- result = op_create_file(argv[1], st_size, st_offset, st_count);
+ result = op_create_dir(argv[1], st_count);
if (result)
- fprintf(stderr, "error: %s: create stripe file failed\n",
+ fprintf(stderr, "error: %s: create stripe dir failed\n",
argv[0]);
return result;
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)
static int lfs_getstripe(int argc, char **argv)
{
+ struct option long_opts[] = {
+ {"quiet", 0, 0, 'q'},
+ {"verbose", 0, 0, 'v'},
+ {0, 0, 0, 0}
+ };
+ char short_opts[] = "qv";
+ int quiet, verbose, recursive, c, rc;
struct obd_uuid *obduuid = NULL;
- int rc;
- if (argc != 2)
- return CMD_HELP;
+ optind = 0;
+ quiet = verbose = recursive = 0;
+ while ((c = getopt_long(argc, argv, short_opts,
+ long_opts, NULL)) != -1) {
+ switch (c) {
+ case 'o':
+ if (obduuid) {
+ fprintf(stderr,
+ "error: %s: only one obduuid allowed",
+ argv[0]);
+ return CMD_HELP;
+ }
+ obduuid = (struct obd_uuid *)optarg;
+ break;
+ case 'q':
+ quiet++;
+ verbose = 0;
+ 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;
+ break;
+ }
+ }
- optind = 1;
+ if (optind >= argc)
+ return CMD_HELP;
do {
- rc = op_find(argv[optind], obduuid, 0, 0, 0);
+ rc = llapi_find(argv[optind], obduuid, recursive, verbose, quiet, 0);
} while (++optind < argc && !rc);
if (rc)
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;
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, 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);
}
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[0] = obd_type1;
+ obd_types[1] = 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");
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",
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;
return rc;
}
+/*
+ * We assume one and only one filename is supplied as the
+ * last parameter.
+ */
+static int acl_cmd_parse(int argc, char **argv,
+ char *dirbuf, char *cmdbuf)
+{
+ char path[PATH_MAX];
+ char path2[PATH_MAX];
+ FILE *fp;
+ struct mntent *mnt = NULL;
+ char *dir, *tgt;
+ int found = 0, i;
+
+ if (argc < 2)
+ return -1;
+
+ /* get path prefix */
+ strncpy(path, argv[argc - 1], PATH_MAX);
+ dir = dirname(path);
+
+ /* try to resolve the pathname into relative to the
+ * root of the mounted lustre filesystem.
+ * FIXME we simply suppose there's no sub-mounted filesystems
+ * under this mounted lustre tree.
+ */
+ if (getcwd(path2, PATH_MAX) == NULL) {
+ fprintf(stderr, "getcwd old: %s\n", strerror(errno));
+ return -1;
+ }
+
+ if (chdir(dir) == -1) {
+ fprintf(stderr, "chdir to %s: %s\n",
+ dir, strerror(errno));
+ return -1;
+ }
+
+ if (getcwd(path, PATH_MAX) == NULL) {
+ fprintf(stderr, "getcwd new: %s\n", strerror(errno));
+ return -1;
+ }
+
+ if (chdir(path2) == -1) {
+ fprintf(stderr, "chdir back: %s\n", strerror(errno));
+ return -1;
+ }
+
+ fp = setmntent(MOUNTED, "r");
+ if (fp == NULL) {
+ fprintf(stderr, "setmntent(%s): %s\n", MOUNTED,
+ strerror(errno));
+ return -1;
+ }
+
+ while (1) {
+ mnt = getmntent(fp);
+ if (!mnt)
+ break;
+
+ if (!llapi_is_lustre_mnttype(mnt->mnt_type))
+ continue;
+
+ if (!strncmp(mnt->mnt_dir, path, strlen(mnt->mnt_dir))) {
+ char *p;
+
+ /* save the mountpoint dir part */
+ strncpy(dirbuf, mnt->mnt_dir, PATH_MAX);
+
+ /* get rest of path under the mountpoint,
+ * don't start with slash.
+ */
+ p = path + strlen(mnt->mnt_dir);
+ while (*p == '/')
+ p++;
+ snprintf(path2, PATH_MAX, "%s", p);
+
+ /* remove trailing slash */
+ if (path2[strlen(path2)] == '/')
+ path2[strlen(path2)] = '\0';
+ found = 1;
+ /* continue try to match more proper fs */
+ }
+ }
+ endmntent(fp);
+
+ if (!found) {
+ fprintf(stderr, "no mounted lustre fs\n");
+ return -1;
+ }
+
+ /* get base name of target */
+ strncpy(path, argv[argc - 1], PATH_MAX);
+ tgt = basename(path);
+
+ cmdbuf[0] = '\0';
+ for (i = 1; i < argc - 1; i++) {
+ strncat(cmdbuf, argv[i], PATH_MAX);
+ strncat(cmdbuf, " ", PATH_MAX);
+ }
+ strncat(cmdbuf, path2, PATH_MAX);
+ if (path2[0] != '\0')
+ strncat(cmdbuf, "/", PATH_MAX);
+ strncat(cmdbuf, tgt, PATH_MAX);
+
+ return 0;
+}
+
+static int lfs_getfacl(int argc, char **argv)
+{
+ char dir[PATH_MAX];
+ char cmd[PATH_MAX];
+
+ if (acl_cmd_parse(argc, argv, dir, cmd))
+ return CMD_HELP;
+
+ return llapi_getfacl(dir, cmd);
+}
+
+static int lfs_setfacl(int argc, char **argv)
+{
+ char dir[PATH_MAX];
+ char cmd[PATH_MAX];
+
+ if (acl_cmd_parse(argc, argv, dir, cmd))
+ return CMD_HELP;
+
+ return llapi_setfacl(dir, cmd);
+}
+
int main(int argc, char **argv)
{
int rc;