Whamcloud - gitweb
LU-9537 utils: implement "lfs getstripe --fid" for directories 14/43714/4
authorYoann Valeri <yoann.valeri@cea.fr>
Wed, 12 May 2021 09:48:04 +0000 (11:48 +0200)
committerOleg Drokin <green@whamcloud.com>
Wed, 2 Jun 2021 17:49:06 +0000 (17:49 +0000)
Enhance the lfs command by displaying a directory fid when using "lfs
getstripe --fid" on one.

When displaying information through "lfs getstripe --fid", we would
check if the given path was associated to a directory or not. If so,
the fid display would just be skipped, showing a simple blank line.
However, a user could still find the fid of a directory by using "lfs
path2fid" on the same directory.  Therefore, this patch adds a hook to
the underlying "llapi_fd2fid()" (called internally by "lfs path2fid")
when trying to display a directory fid with "lfs getstripe --fid".

Signed-off-by: Yoann Valeri <yoann.valeri@cea.fr>
Change-Id: Ia153717e3feb1a359b8b54297995365fc34a1c29
Reviewed-on: https://review.whamcloud.com/43714
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/tests/sanity.sh
lustre/utils/liblustreapi.c

index 157b568..f1732e5 100755 (executable)
@@ -5893,6 +5893,7 @@ run_test 54e "console/tty device works in lustre ======================"
 
 test_56a() {
        local numfiles=3
+       local numdirs=2
        local dir=$DIR/$tdir
 
        rm -rf $dir
@@ -5932,9 +5933,10 @@ test_56a() {
 
        #test lfs getstripe with -v prints lmm_fid
        filenum=$($LFS getstripe -v $dir | grep -c lmm_fid)
-       [[ $filenum -eq $((numfiles * numcomp)) ]] ||
+       local countfids=$((numdirs + numfiles * numcomp))
+       [[ $filenum -eq $countfids ]] ||
                error "$LFS getstripe -v $dir: "\
-                     "got $filenum want $((numfiles * numcomp)) lmm_fid"
+                     "got $filenum want $countfids lmm_fid"
        [[ $($LFS getstripe $dir | grep -c lmm_fid) -eq 0 ]] ||
                error "$LFS getstripe $dir: showed lmm_fid by default"
        echo "$LFS getstripe --verbose passed"
index ff645c2..03dbfad 100644 (file)
@@ -2919,7 +2919,8 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
                             space, prefix,
                             (uintmax_t)lmm_oi_id(&lum->lmm_oi));
        }
-       if ((verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) && !is_dir) {
+
+       if (verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) {
                __u64 seq;
                __u32 oid;
                __u32 ver;
@@ -2927,30 +2928,51 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
                if (verbose & ~VERBOSE_DFID)
                        llapi_printf(LLAPI_MSG_NORMAL, "%slmm_fid:           ",
                                     space);
-               /*
-                * This needs a bit of hand-holding since old 1.x lmm_oi
-                * have { oi.oi_id = mds_inum, oi.oi_seq = 0 } and 2.x lmm_oi
-                * have { oi.oi_id = mds_oid, oi.oi_seq = mds_seq } instead of
-                * a real FID.  Ideally the 2.x code would have stored this
-                * like a FID with { oi_id = mds_seq, oi_seq = mds_oid } so the
-                * ostid union lu_fid { f_seq = mds_seq, f_oid = mds_oid }
-                * worked properly (especially since IGIF FIDs use mds_inum as
-                * the FID SEQ), but unfortunately that didn't happen.
-                *
-                * Print it to look like an IGIF FID, even though the fields
-                * are reversed on disk, so that it makes sense to userspace.
-                *
-                * Don't use ostid_id() and ostid_seq(), since they assume the
-                * oi_fid fields are in the right order.  This is why there are
-                * separate lmm_oi_seq() and lmm_oi_id() routines for this.
-                *
-                * For newer layout types hopefully this will be a real FID.
-                */
-               seq = lmm_oi_seq(&lum->lmm_oi) == 0 ?
-                       lmm_oi_id(&lum->lmm_oi) : lmm_oi_seq(&lum->lmm_oi);
-               oid = lmm_oi_seq(&lum->lmm_oi) == 0 ?
-                       0 : (__u32)lmm_oi_id(&lum->lmm_oi);
-               ver = (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32);
+
+               if (is_dir) {
+                       struct lu_fid dir_fid;
+
+                       rc = llapi_path2fid(path, &dir_fid);
+                       if (rc)
+                               llapi_error(LLAPI_MSG_ERROR, rc,
+                                           "Cannot determine directory fid.");
+
+                       seq = dir_fid.f_seq;
+                       oid = dir_fid.f_oid;
+                       ver = dir_fid.f_ver;
+               } else {
+                       /*
+                        * This needs a bit of hand-holding since old 1.x
+                        * lmm_oi have { oi.oi_id = mds_inum, oi.oi_seq = 0 }
+                        * and 2.x lmm_oi have { oi.oi_id = mds_oid,
+                        * oi.oi_seq = mds_seq } instead of a real FID.
+                        * Ideally the 2.x code would have stored this like a
+                        * FID with { oi_id = mds_seq, oi_seq = mds_oid } so
+                        * the ostid union lu_fid { f_seq = mds_seq,
+                        * f_oid = mds_oid } worked properly (especially since
+                        * IGIF FIDs use mds_inum as the FID SEQ), but
+                        * unfortunately that didn't happen.
+                        *
+                        * Print it to look like an IGIF FID, even though the
+                        * fields are reversed on disk, so that it makes sense
+                        * to userspace.
+                        *
+                        * Don't use ostid_id() and ostid_seq(), since they
+                        * assume the oi_fid fields are in the right order.
+                        * This is why there are separate lmm_oi_seq() and
+                        * lmm_oi_id() routines for this.
+                        *
+                        * For newer layout types hopefully this will be a
+                        * real FID.
+                        */
+                       seq = lmm_oi_seq(&lum->lmm_oi) == 0 ?
+                               lmm_oi_id(&lum->lmm_oi) :
+                               lmm_oi_seq(&lum->lmm_oi);
+                       oid = lmm_oi_seq(&lum->lmm_oi) == 0 ?
+                           0 : (__u32)lmm_oi_id(&lum->lmm_oi);
+                       ver = (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32);
+               }
+
                if (yaml)
                        llapi_printf(LLAPI_MSG_NORMAL, DFID_NOBRACE"\n",
                                     (unsigned long long)seq, oid, ver);