From 2a4821b836c82764ff13dbf32ba2386c9d3dca8e Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Thu, 4 Apr 2019 01:21:46 -0600 Subject: [PATCH] LU-12159 utils: improve lfs getname functionality Add "-n" and "-i" options to lfs getname to allow printing only the fsname or instance ID of the filesystem(s). Split out the documentation to a separate lfs-getname.1 man page. Signed-off-by: Andreas Dilger Change-Id: Ie132513325b6630fc5103a89b469271ba7392cb2 Reviewed-on: https://review.whamcloud.com/34595 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Ben Evans Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- lustre/doc/lfs-getname.1 | 43 ++++++++++++++ lustre/doc/lfs.1 | 13 ++-- lustre/utils/lfs.c | 151 +++++++++++++++++++++++++++++++++-------------- 3 files changed, 154 insertions(+), 53 deletions(-) create mode 100644 lustre/doc/lfs-getname.1 diff --git a/lustre/doc/lfs-getname.1 b/lustre/doc/lfs-getname.1 new file mode 100644 index 0000000..dd43fb2 --- /dev/null +++ b/lustre/doc/lfs-getname.1 @@ -0,0 +1,43 @@ +.TH LFS-GETSOM 1 2018-10-04 "Lustre" "lustre Utilities" +.SH NAME +lfs getname \- retrieve the filesystem name and instance ID +.SH SYNOPSIS +.B lfs getname +.RB [ --help | -h "] [" --instance | -i "] [" --fsname | -n ] +.RI [ pathname ...] +.SH DESCRIPTION +Print the filesystem name, instance ID, and mountpoint for all +Lustre mount points on the local client. If one or more +.I pathname +arguments are provided, then only print the Lustre filesystem name +and instance ID for these mount points. +.SH OPTIONS +.TP +.BR --help | -h +Print the usage message. +.TP +.BR --fsname | -n +Print only the Lustre filesystem name for each filesystem. If +.B -n +is used with a single +.I pathname +then the filesystem name is printed without the mountpoint. +.TP +.BR --instance | -i +Only show the mount instance ID for each filesystem. If +.B -i +is used with a single +.I pathname +then the instance ID is printed without the mountpoint. +.SH EXAMPLES +.TP +.B $ lfs getname +myth-ffff880428703400 /myth +.br +testfs-ffff937009271000 /mnt/testfs +.TP +.B $ lfs getname -n /mnt/testfs +testfs +.SH SEE ALSO +.BR lfs (1), +.BR lustre (7) diff --git a/lustre/doc/lfs.1 b/lustre/doc/lfs.1 index cdb50db..5b1177b 100644 --- a/lustre/doc/lfs.1 +++ b/lustre/doc/lfs.1 @@ -44,7 +44,9 @@ lfs \- client utility for Lustre-specific file layout and other attributes [[\fB!\fR] \fB--uid\fR|\fB-u\fR|\fB--user\fR|\fB-U \fR<\fIuname\fR>|<\fIuid\fR>] .br -.B lfs getname [-h]|[path ...] +.B lfs getname +.RB [ --help | -h "] [" --instance | -i "] [" --fsname | -n "] [" +.IR path ...] .br .B lfs getstripe [\fB--component-count\fR|\fB--comp-count\fR] @@ -184,12 +186,6 @@ data has not been changed during an archive operation or before a release operation, and by OST migration, primarily for verifying that file data has not been changed during a data copy, when done in non-blocking mode. .TP -.B getname [-h]|[path ...] -Report all the Lustre mount points and the corresponding Lustre filesystem -instance. If one or more \fBpath\fR entries are provided, then only the -Lustre instance for these mount points is returned. If the path given is not on -a Lustre instance 'No such device' is reported. -.TP .B osts .RB [ path ] List all the OSTs for all mounted filesystems. If a \fBpath\fR is provided @@ -312,8 +308,9 @@ The lfs command is part of the Lustre filesystem. .BR lctl (8), .BR lfs-df (1), .BR lfs-find (1), -.BR lfs-getstripe (1), .BR lfs-getdirstripe (1), +.BR lfs-getname (1), +.BR lfs-getstripe (1), .BR lfs-hsm (1), .BR lfs-mkdir (1), .BR lfs-migrate (1), diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index eaeca58..d2413ff 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -413,26 +413,26 @@ command_t cmdlist[] = { "\thashtype: hash type of the striped directory.\n" "\t fnv_1a_64 FNV-1a hash algorithm\n" "\t all_char sum of characters % MDT_COUNT\n"}, - {"check", lfs_check, 0, + {"check", lfs_check, 0, "Display the status of MGTs, MDTs or OSTs (as specified in the command)\n" "or all the servers (MGTs, MDTs and OSTs).\n" "usage: check "}, - {"osts", lfs_osts, 0, "list OSTs connected to client " - "[for specified path only]\n" "usage: osts [path]"}, - {"mdts", lfs_mdts, 0, "list MDTs connected to client " - "[for specified path only]\n" "usage: mdts [path]"}, - {"df", lfs_df, 0, - "report filesystem disk space usage or inodes usage" - "of each MDS and all OSDs or a batch belonging to a specific pool .\n" - "Usage: df [-i] [-h] [--lazy|-l] [--pool|-p [.] [path]"}, - {"getname", lfs_getname, 0, "list instances and specified mount points " - "[for specified path only]\n" - "Usage: getname [-h]|[path ...] "}, + {"osts", lfs_osts, 0, "list OSTs connected to client " + "[for specified path only]\n" "usage: osts [path]"}, + {"mdts", lfs_mdts, 0, "list MDTs connected to client " + "[for specified path only]\n" "usage: mdts [path]"}, + {"df", lfs_df, 0, + "report filesystem disk space usage or inodes usage " + "of each MDS and all OSDs or a batch belonging to a specific pool.\n" + "Usage: df [-i] [-h] [--lazy|-l] [--pool|-p [.] [path]"}, + {"getname", lfs_getname, 0, + "list instances and specified mount points [for specified path only]\n" + "Usage: getname [--help|-h] [--instance|-i] [--fsname|-n] [path ...]"}, #ifdef HAVE_SYS_QUOTA_H - {"setquota", lfs_setquota, 0, "Set filesystem quotas.\n" + {"setquota", lfs_setquota, 0, "Set filesystem quotas.\n" "usage: setquota <-u|-g|-p> ||||\n" - " -b -B \n" - " -i -I \n" + " -b -B \n" + " -i -I \n" " setquota <-u|--user|-g|--group|-p|--projid> ||||\n" " [--block-softlimit ]\n" " [--block-hardlimit ]\n" @@ -5442,43 +5442,104 @@ static int lfs_df(int argc, char **argv) return rc; } +static int print_instance(const char *mntdir, char *fsname, size_t fsnamelen, + bool opt_instance, bool opt_fsname, bool opt_mntdir) +{ + char *buf = fsname; + + /* llapi_search_mounts() fills "fsname", but that is not called if + * explicit paths are specified on the command-line + */ + if (opt_instance || (opt_fsname && fsname[0] == '\0')) { + int rc = llapi_getname(mntdir, fsname, fsnamelen); + + if (rc < 0) { + fprintf(stderr, "cannot get instance for '%s': %s\n", + mntdir, strerror(-rc)); + return rc; + } + buf = fsname; + if (!opt_instance) { + /* print only the fsname name */ + buf = strchr(fsname, '-'); + if (buf) + *buf = '\0'; + buf = fsname; + } else if (!opt_fsname) { + /* print only the instance name */ + buf = strchr(fsname, '-'); + if (buf) + buf++; + else + buf = fsname; + } + } else if (opt_fsname) { + /* print only the fsname */ + buf = fsname; + } + + printf("%s %s\n", buf, opt_mntdir ? mntdir : ""); + + return 0; +} + static int lfs_getname(int argc, char **argv) { - char mntdir[PATH_MAX] = "", path[PATH_MAX] = "", fsname[PATH_MAX] = ""; - int rc = 0, index = 0, c; - char buf[sizeof(struct obd_uuid)]; + struct option long_opts[] = { + { .val = 'h', .name = "help", .has_arg = no_argument }, + { .val = 'i', .name = "instance", .has_arg = no_argument }, + { .val = 'n', .name = "fsname", .has_arg = no_argument }, + { .name = NULL} }; + bool opt_instance = false, opt_fsname = false; + char fsname[PATH_MAX] = ""; + int rc = 0, rc2, c; - while ((c = getopt(argc, argv, "h")) != -1) - return CMD_HELP; + while ((c = getopt_long(argc, argv, "hin", long_opts, NULL)) != -1) { + switch (c) { + case 'i': + opt_instance = true; + break; + case 'n': + opt_fsname = true; + break; + case 'h': + default: + return CMD_HELP; + } + } - if (optind == argc) { /* no paths specified, get all paths. */ - while (!llapi_search_mounts(path, index++, mntdir, fsname)) { - rc = llapi_getname(mntdir, buf, sizeof(buf)); - if (rc < 0) { - fprintf(stderr, - "cannot get name for `%s': %s\n", - mntdir, strerror(-rc)); - break; - } + /* If neither option is given, print both instance and fsname */ + if (!opt_instance && !opt_fsname) + opt_instance = opt_fsname = true; - printf("%s %s\n", buf, mntdir); + if (optind == argc) { /* no paths specified, get all paths. */ + char mntdir[PATH_MAX] = "", path[PATH_MAX] = ""; + int index = 0; - path[0] = fsname[0] = mntdir[0] = 0; - } - } else { /* paths specified, only attempt to search these. */ - for (; optind < argc; optind++) { - rc = llapi_getname(argv[optind], buf, sizeof(buf)); - if (rc < 0) { - fprintf(stderr, - "cannot get name for `%s': %s\n", - argv[optind], strerror(-rc)); - break; - } + while (!llapi_search_mounts(path, index++, mntdir, fsname)) { + rc2 = print_instance(mntdir, fsname, sizeof(fsname), + opt_instance, opt_fsname, true); + if (!rc) + rc = rc2; + path[0] = fsname[0] = mntdir[0] = '\0'; + } + } else { /* paths specified, only attempt to search these. */ + bool opt_mntdir; - printf("%s %s\n", buf, argv[optind]); - } - } - return rc; + /* if only one path is given, print only requested info */ + opt_mntdir = argc - optind > 1 || (opt_instance == opt_fsname); + + for (; optind < argc; optind++) { + rc2 = print_instance(argv[optind], fsname, + sizeof(fsname), opt_instance, + opt_fsname, opt_mntdir); + if (!rc) + rc = rc2; + fsname[0] = '\0'; + } + } + + return rc; } static int lfs_check(int argc, char **argv) -- 1.8.3.1