From: Richard Henwood Date: Wed, 2 Nov 2011 23:33:51 +0000 (-0400) Subject: LU-680 lfs: instance <-> mount point mapping from lfs X-Git-Tag: 2.1.53~17 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=8d935e6d3137bc4678ca2f22c1a30d34474cf677 LU-680 lfs: instance <-> mount point mapping from lfs A new option to 'lfs' has been created to return the mapping between Lustre filesystem instance and paths. The option is 'getname' and it may be called with or without arguements. 'lfs getname' without arguments returns the instances of all Lustre mount points. 'lfs getname [path...]' returns the instance of each specified path. If the path is not a Lustre instance 'No such device' is returned. OBD_IOC_GETNAME has been added to file.c to provide consistent behavior for file as well as directory paths. A llapi_getname helper function has been added to liblustreapi that returns a lustre instance name if a path is provided. Documentation for 'lfs getname' is included inline an the lfs man page has been updated. Signed-off-by: Richard Henwood Signed-off-by: John L. Hammond Change-Id: Iab8ff12d604c7ce853f3c204b455e3b641f659f4 Reviewed-on: http://review.whamcloud.com/1373 Reviewed-by: Andreas Dilger Tested-by: Hudson Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/doc/lfs.1 b/lustre/doc/lfs.1 index 5415367..5953ad4 100644 --- a/lustre/doc/lfs.1 +++ b/lustre/doc/lfs.1 @@ -21,8 +21,7 @@ lfs \- Lustre utility to create a file with specific striping pattern, find the \fB[[!] --uid|-u|--user|-U |] \fB\fR .br -.B lfs osts -.RB [ path ] +.B lfs getname [-h]|[path ...] .br .B lfs getstripe [--obd|-O ] [--quiet|-q] [--verbose|-v] \fB[--count | -c ] [--index | -i | --offset | -o ] @@ -35,6 +34,9 @@ lfs \- Lustre utility to create a file with specific striping pattern, find the .br .B lfs setstripe -d .br +.B lfs osts +.RB [ path ] +.br .B lfs poollist [.] | .br .B lfs quota [-q] [-v] [-o obd_uuid|-I ost_idx|-i mdt_idx] [-u | -u |-g | -g ] @@ -102,6 +104,12 @@ for \fBM\fRega-, \fBG\fRiga-, \fBT\fRera-, \fBP\fReta-, or \fBE\fRxabytes. .B find To search the directory tree rooted at the given dir/file name for the files that match the given parameters: \fB--atime\fR (file was last accessed N*24 hours ago), \fB--ctime\fR (file's status was last changed N*24 hours ago), \fB--mtime\fR (file's data was last modified N*24 hours ago), \fB--obd\fR (file has an object on a specific OST or OSTs), \fB--size\fR (file has size in bytes, or \fBk\fRilo-, \fBM\fRega-, \fBG\fRiga-, \fBT\fRera-, \fBP\fReta-, or \fBE\fRxabytes if a suffix is given), \fB--type\fR (file has the type: \fBb\fRlock, \fBc\fRharacter, \fBd\fRirectory, \fBp\fRipe, \fBf\fRile, sym\fBl\fRink, \fBs\fRocket, or \fBD\fRoor (Solaris)), \fB--uid\fR (file has specific numeric user ID), \fB--user\fR (file owned by specific user, numeric user ID allowed), \fB--gid\fR (file has specific group ID), \fB--group\fR (file belongs to specific group, numeric group ID allowed). The option \fB--maxdepth\fR limits find to decend at most N levels of directory tree. The options \fB--print\fR and \fB--print0\fR print full file name, followed by a newline or NUL character correspondingly. Using \fB!\fR before an option negates its meaning (\fIfiles NOT matching the parameter\fR). Using \fB+\fR before a numeric value means \fIfiles with the parameter OR MORE\fR, while \fB-\fR before a numeric value means \fIfiles with the parameter OR LESS\fR. .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 diff --git a/lustre/include/lustre/liblustreapi.h b/lustre/include/lustre/liblustreapi.h index bf61daf..87c058a 100644 --- a/lustre/include/lustre/liblustreapi.h +++ b/lustre/include/lustre/liblustreapi.h @@ -194,6 +194,8 @@ extern int llapi_path2fid(const char *path, lustre_fid *fid); extern int llapi_search_mounts(const char *pathname, int index, char *mntdir, char *fsname); extern int llapi_search_fsname(const char *pathname, char *fsname); +extern int llapi_getname(const char *path, char *buf, size_t size); + extern void llapi_ping_target(char *obd_type, char *obd_name, char *obd_uuid, void *args); diff --git a/lustre/llite/file.c b/lustre/llite/file.c index bcff3e6..0f2f8d3 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -1755,6 +1755,7 @@ int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd, #endif struct ll_file_data *fd = LUSTRE_FPRIVATE(file); int flags; + ENTRY; CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p),cmd=%x\n", inode->i_ino, @@ -1833,7 +1834,6 @@ int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd, } case OBD_IOC_FID2PATH: RETURN(ll_fid2path(ll_i2mdexp(inode), (void *)arg)); - case LL_IOC_GET_MDTIDX: { int mdtidx; @@ -1846,6 +1846,16 @@ int ll_file_ioctl(struct inode *inode, struct file *file, unsigned int cmd, RETURN(0); } + case OBD_IOC_GETNAME: { + struct obd_device *obd = + class_exp2obd(ll_i2sbi(inode)->ll_dt_exp); + if (!obd) + RETURN(-EFAULT); + if (cfs_copy_to_user((void *)arg, obd->obd_name, + strlen(obd->obd_name) + 1)) + RETURN(-EFAULT); + RETURN(0); + } default: { int err; diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 99707f2..9694bac 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -86,6 +86,7 @@ static int lfs_find(int argc, char **argv); static int lfs_getstripe(int argc, char **argv); static int lfs_osts(int argc, char **argv); static int lfs_df(int argc, char **argv); +static int lfs_getname(int argc, char **argv); static int lfs_check(int argc, char **argv); static int lfs_catinfo(int argc, char **argv); #ifdef HAVE_SYS_QUOTA_H @@ -169,6 +170,9 @@ command_t cmdlist[] = { "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] [--pool|-p [.] [path]"}, + {"getname", lfs_getname, 0, "list instances and specified mount points " + "[for specified path only]\n" + "Usage: getname [-h]|[path ...] "}, #ifdef HAVE_SYS_QUOTA_H {"quotachown",lfs_quotachown, 0, "Change files' owner or group on the specified filesystem.\n" @@ -1163,6 +1167,46 @@ static int lfs_df(int argc, char **argv) return rc; } +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)]; + + optind = 0; + while ((c = getopt(argc, argv, "h")) != -1) + 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; + } + + printf("%s %s\n", buf, mntdir); + + 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; + } + + printf("%s %s\n", buf, argv[optind]); + } + } + return rc; +} + static int lfs_check(int argc, char **argv) { int rc; diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index e08bef0..999a2c3 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -657,6 +657,31 @@ int llapi_search_fsname(const char *pathname, char *fsname) return rc; } +int llapi_getname(const char *path, char *buf, size_t size) +{ + struct obd_uuid uuid_buf; + char *uuid = uuid_buf.uuid; + int rc, nr; + + memset(&uuid_buf, 0, sizeof(uuid_buf)); + rc = llapi_file_get_lov_uuid(path, &uuid_buf); + if (rc) + return rc; + + /* We want to turn lustre-clilov-ffff88002738bc00 into + * lustre-ffff88002738bc00. */ + + nr = snprintf(buf, size, "%.*s-%s", + (int) (strlen(uuid) - 24), uuid, + uuid + strlen(uuid) - 16); + + if (nr >= size) + rc = -ENAMETOOLONG; + + return rc; +} + + /* return the first file matching this pattern */ static int first_match(char *pattern, char *buffer) {