From a78113bf560e431b107f7c1cc445c7036b859197 Mon Sep 17 00:00:00 2001 From: Andrew Perepechko Date: Thu, 16 Sep 2010 15:12:40 +0400 Subject: [PATCH] b=20101 lfs ost enhancements a=James Simmons i=Andreas Dilger i=Brian Murrell --- lustre/doc/lfs.1 | 6 +++- lustre/tests/sanity.sh | 4 +-- lustre/tests/test-framework.sh | 5 +++ lustre/utils/lfs.c | 76 +++++++++++++++++++----------------------- lustre/utils/liblustreapi.c | 2 +- 5 files changed, 48 insertions(+), 45 deletions(-) diff --git a/lustre/doc/lfs.1 b/lustre/doc/lfs.1 index 92c5a4b..8dd67e7 100644 --- a/lustre/doc/lfs.1 +++ b/lustre/doc/lfs.1 @@ -18,6 +18,7 @@ lfs \- Lustre utility to create a file with specific striping pattern, find the \fB\fR .br .B lfs osts +.RB [ path ] .br .B lfs getstripe [--obd|-O ] [--quiet|-q] [--verbose|-v] \fB[--count | -c ] [--index | -i | --offset | -o ] @@ -89,7 +90,10 @@ for \fBM\fRega-, \fBG\fRiga-, \fBT\fRera-, \fBP\fReta-, or \fBE\fRxabytes. 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 osts -List all the OSTs for the filesystem +.RB [ path ] +List all the OSTs for all mounted filesystems. If a \fBpath\fR is provided +that is located on a lustre mounted file system then only the OSTs belonging +to that filesystem are displayed. .TP .B getstripe [--obd|-O ] [--quiet|-q] [--verbose|-v] \fB[--count | -c ] [--size | -s ] [--index | -i ] diff --git a/lustre/tests/sanity.sh b/lustre/tests/sanity.sh index e525c48..f997e79 100644 --- a/lustre/tests/sanity.sh +++ b/lustre/tests/sanity.sh @@ -2722,8 +2722,8 @@ run_test 56h "check lfs find ! -name =============================" test_56i() { tdir=${tdir}i mkdir -p $DIR/$tdir - UUID=`$LFS osts $DIR/$tdir | awk '/0: / { print $2 }'` - OUT="`$LFIND -ost $UUID $DIR/$tdir`" + UUID=$(ostuuid_from_index 0 $DIR/$tdir) + OUT=$($LFIND -obd $UUID $DIR/$tdir) [ "$OUT" ] && error "$LFIND returned directory '$OUT'" || true } run_test 56i "check 'lfs find -ost UUID' skips directories =======" diff --git a/lustre/tests/test-framework.sh b/lustre/tests/test-framework.sh index 79e2fe4..0c96a56 100644 --- a/lustre/tests/test-framework.sh +++ b/lustre/tests/test-framework.sh @@ -2752,6 +2752,11 @@ osc_to_ost() echo $ost } +ostuuid_from_index() +{ + $LFS osts $2 | awk '/^'$1'/ { print $2 }' +} + remote_node () { local node=$1 [ "$node" != "$(hostname)" ] diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 4544a11..68a3c17 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -150,7 +150,8 @@ command_t cmdlist[] = { {"join", lfs_join, 0, "join two lustre files into one - join A, B, will be like cat B >> A & del B\n" "usage: join \n"}, - {"osts", lfs_osts, 0, "osts"}, + {"osts", lfs_osts, 0, "list OSTs connected to client " + "[for specified path only]\n" "usage: osts [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" @@ -847,20 +848,33 @@ static int lfs_getstripe(int argc, char **argv) static int lfs_osts(int argc, char **argv) { - char mntdir[PATH_MAX] = {'\0'}; + char mntdir[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'}; struct find_param param; int index = 0, rc = 0; - if (argc != 1) + if (argc > 2) return CMD_HELP; - while (llapi_search_mounts(NULL, index++, mntdir, NULL) == 0) { + if (argc == 2 && !realpath(argv[1], path)) { + rc = -errno; + fprintf(stderr, "error: invalid path '%s': %s\n", + argv[1], strerror(-rc)); + return rc; + } + + while (!llapi_search_mounts(path, index++, mntdir, NULL)) { + /* Check if we have a mount point */ + if (mntdir[0] == '\0') + continue; + memset(¶m, 0, sizeof(param)); rc = llapi_ostlist(mntdir, ¶m); if (rc) { fprintf(stderr, "error: %s: failed on %s\n", argv[0], mntdir); } + if (path[0] != '\0') + break; memset(mntdir, 0, PATH_MAX); } @@ -1073,16 +1087,15 @@ static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, int cooked) printf("\n"); showdf(mntdir, &sum, "filesystem summary:", ishow, cooked, NULL, 0,0); - + printf("\n"); return 0; } static int lfs_df(int argc, char **argv) { - char *path = NULL; - char *mntdir = NULL; + char mntdir[PATH_MAX] = {'\0'}, path[PATH_MAX] = {'\0'}; int ishow = 0, cooked = 0; - int c, rc = 0; + int c, rc = 0, index = 0; char fsname[PATH_MAX] = "", *pool_name = NULL; struct option long_opts[] = { {"pool", required_argument, 0, 'p'}, @@ -1105,45 +1118,26 @@ static int lfs_df(int argc, char **argv) return CMD_HELP; } } - if (optind < argc ) - path = argv[optind]; - if ((mntdir = malloc(PATH_MAX)) == NULL) { - fprintf(stderr, "error: cannot allocate %d bytes\n", - PATH_MAX); - return -ENOMEM; + if (optind < argc && !realpath(argv[optind], path)) { + rc = -errno; + fprintf(stderr, "error: invalid path '%s': %s\n", + argv[optind], strerror(-rc)); + return rc; } - memset(mntdir, 0, PATH_MAX); - - if (path) { - char rpath[PATH_MAX] = {'\0'}; - if (!realpath(path, rpath)) { - rc = -errno; - fprintf(stderr, "error: invalid path '%s': %s\n", - path, strerror(-rc)); - return rc; - } - - rc = llapi_search_mounts(rpath, 0, mntdir, fsname); - if (rc == 0 && mntdir[0] != '\0') { - rc = mntdf(mntdir, fsname, pool_name, ishow, cooked); - printf("\n"); - } - } else { - int index = 0; + while (!llapi_search_mounts(path, index++, mntdir, fsname)) { + /* Check if we have a mount point */ + if (mntdir[0] == '\0') + continue; - while (!llapi_search_mounts(NULL, index++, mntdir, fsname)) { - rc = mntdf(mntdir, fsname, pool_name, ishow, cooked); - if (rc) - break; - printf("\n"); - fsname[0] = '\0'; /* avoid matching in next loop */ - mntdir[0] = '\0'; /* avoid matching in next loop */ - } + rc = mntdf(mntdir, fsname, pool_name, ishow, cooked); + if (rc || path[0] != '\0') + break; + fsname[0] = '\0'; /* avoid matching in next loop */ + mntdir[0] = '\0'; /* avoid matching in next loop */ } - free(mntdir); return rc; } diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 1e88a51..9a0aeb4 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -594,7 +594,7 @@ int llapi_search_mounts(const char *pathname, int index, char *mntdir, { int want = WANT_PATH, idx = -1; - if (!pathname) { + if (!pathname || pathname[0] == '\0') { want |= WANT_INDEX; idx = index; } else -- 1.8.3.1