error "$GETSTRIPE $DIR/$tdir: found $FILENUM, not $NUMFILES"
echo "$GETSTRIPE --recursive passed."
- # test lfs getstripe with file instead of dir
+ # test lfs getstripe with file instead of dir
FILENUM=$($GETSTRIPE $DIR/$tdir/file1 | grep -c obdidx)
[[ $FILENUM -eq 1 ]] ||
error "$GETSTRIPE $DIR/$tdir/file1: found $FILENUM, not 1"
echo "$GETSTRIPE file1 passed."
- #test lfs getstripe with --verbose
+ #test lfs getstripe with --verbose
[[ $($GETSTRIPE --verbose $DIR/$tdir |
grep -c lmm_magic) -eq $NUMFILES ]] ||
error "$GETSTRIPE --verbose $DIR/$tdir: want $NUMFILES"
[[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_magic) -eq 0 ]] ||
- rror "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
+ error "$GETSTRIPE $DIR/$tdir: showed lmm_magic"
+
+ #test lfs getstripe with -v prints lmm_fid
+ [[ $($GETSTRIPE -v $DIR/$tdir | grep -c lmm_fid) -eq $NUMFILES ]] ||
+ error "$GETSTRIPE -v $DIR/$tdir: want $NUMFILES lmm_fid: lines"
+ [[ $($GETSTRIPE $DIR/$tdir | grep -c lmm_fid) -eq 0 ]] ||
+ error "$GETSTRIPE $DIR/$tdir: showed lmm_fid"
echo "$GETSTRIPE --verbose passed."
- #test lfs getstripe with --obd
- $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
+ #check for FID information
+ local fid1=$($GETSTRIPE --fid $DIR/$tdir/file1)
+ local fid2=$($GETSTRIPE --verbose $DIR/$tdir/file1 |
+ awk '/lmm_fid: / { print $2 }')
+ local fid3=$($LFS path2fid $DIR/$tdir/file1)
+ [ "$fid1" != "$fid2" ] &&
+ error "getstripe --fid $fid1 != getstripe --verbose $fid2"
+ [ "$fid1" != "$fid3" ] &&
+ error "getstripe --fid $fid1 != lfs path2fid $fid3"
+ echo "$GETSTRIPE --fid passed."
+
+ #test lfs getstripe with --obd
+ $GETSTRIPE --obd wrong_uuid $DIR/$tdir 2>&1 |
grep -q "unknown obduuid" ||
error "$GETSTRIPE --obd wrong_uuid should return error message"
[[ $OSTCOUNT -lt 2 ]] &&
- skip_env "skipping other $GETSTRIPE --obd test" && return
+ skip_env "skipping other $GETSTRIPE --obd test" && return
- OSTIDX=1
- OBDUUID=$(ostuuid_from_index $OSTIDX)
+ OSTIDX=1
+ OBDUUID=$(ostuuid_from_index $OSTIDX)
FILENUM=$($GETSTRIPE -ir $DIR/$tdir | grep "^$OSTIDX\$" | wc -l)
FOUND=$($GETSTRIPE -r --obd $OBDUUID $DIR/$tdir | grep obdidx | wc -l)
[[ $FOUND -eq $FILENUM ]] ||
test_56t() { # LU-611
TDIR=$DIR/${tdir}t
- setup_56 $NUMFILES $NUMDIRS "-s 512k"
+ setup_56 $NUMFILES $NUMDIRS "--stripe-size 512k"
$SETSTRIPE -S 256k $TDIR/$tfile.{0,1,2,3}
[[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
skip "Need MDS version at least 2.4.1" && return
- touch $DIR/$tfile
- local FID=$($LFS path2fid $DIR/$tfile)
- [ -z "$FID" ] && error "path2fid unable to get $DIR/$tfile FID"
+ local tf=$DIR/$tfile
+ touch $tf
- # check that we get the same pathname back
- local FOUND=$($LFS fid2path $MOUNT "$FID")
- [ -z "$FOUND" ] && error "fid2path unable to get $FID path"
- [ "$FOUND" != "$DIR/$tfile" ] &&
- error "fid2path(path2fid($DIR/$tfile)) = $FOUND != $DIR/$tfile"
+ local fid=$($LFS path2fid $tf)
+ [ -z "$fid" ] && error "path2fid unable to get $tf FID"
- rm -rf $DIR/$tfile
+ # check that we get the same pathname back
+ local found=$($LFS fid2path $MOUNT "$fid")
+ [ -z "$found" ] && error "fid2path unable to get '$fid' path"
+ [ "$found" == "$tf" ] ||
+ error "fid2path($fid=path2fid($tf)) = $found != $tf"
}
run_test 154A "lfs path2fid and fid2path basic checks"
{"getstripe", lfs_getstripe, 0,
"To list the striping info for a given file or files in a\n"
"directory or recursively for all files in a directory tree.\n"
- "usage: getstripe [--ost|-O <uuid>] [--quiet | -q] [--verbose | -v]\n"
+ "usage: getstripe [--ost|-O <uuid>] [--quiet|-q] [--verbose|-v]\n"
" [--stripe-count|-c] [--stripe-index|-i]\n"
" [--pool|-p] [--stripe-size|-S] [--directory|-d]\n"
" [--mdt-index|-M] [--recursive|-r] [--raw|-R]\n"
- " [--layout|-L]\n"
+ " [--layout|-L] [--fid|-F] [--generation|-g]\n"
" <directory|filename> ..."},
{"setdirstripe", lfs_setdirstripe, 0,
"To create a striped directory on a specified MDT. This can only\n"
{"stripe_count", no_argument, 0, 'c'},
{"directory", no_argument, 0, 'd'},
{"default", no_argument, 0, 'D'},
+ {"fid", no_argument, 0, 'F'},
{"generation", no_argument, 0, 'g'},
#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 53, 0)
/* This formerly implied "stripe-index", but was explicitly
};
int c, rc;
- while ((c = getopt_long(argc, argv, "cdDghiLMoO:pqrRsSv",
+ while ((c = getopt_long(argc, argv, "cdDFghiLMoO:pqrRsSv",
long_opts, NULL)) != -1) {
switch (c) {
case 'O':
case 'D':
param->fp_get_default_lmv = 1;
break;
+ case 'F':
+ if (!(param->fp_verbose & VERBOSE_DETAIL)) {
+ param->fp_verbose |= VERBOSE_DFID;
+ param->fp_max_depth = 0;
+ }
+ break;
case 'r':
param->fp_recursive = 1;
break;
case 'v':
- param->fp_verbose = VERBOSE_ALL | VERBOSE_DETAIL;
+ param->fp_verbose = VERBOSE_DEFAULT | VERBOSE_DETAIL;
break;
case 'c':
#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 53, 0)
param->fp_max_depth = -1;
if (!param->fp_verbose)
- param->fp_verbose = VERBOSE_ALL;
+ param->fp_verbose = VERBOSE_DEFAULT;
if (param->fp_quiet)
param->fp_verbose = VERBOSE_OBJID;
}
static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
- struct lov_user_ost_data_v1 *objects,
- int is_dir, int verbose, int depth,
- int raw, char *pool_name)
+ struct lov_user_ost_data_v1 *objects,
+ int is_dir, int verbose, int depth,
+ int raw, char *pool_name)
{
- char *prefix = is_dir ? "" : "lmm_";
+ char *prefix = is_dir ? "" : "lmm_";
char *separator = "";
- int rc;
+ int rc;
if (is_dir && lmm_oi_seq(&lum->lmm_oi) == FID_SEQ_LOV_DEFAULT) {
lmm_oi_set_seq(&lum->lmm_oi, 0);
llapi_printf(LLAPI_MSG_NORMAL, "(Default) ");
}
- if (depth && path && ((verbose != VERBOSE_OBJID) || !is_dir))
- llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
+ if (depth && path && ((verbose != VERBOSE_OBJID) || !is_dir))
+ llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path);
if ((verbose & VERBOSE_DETAIL) && !is_dir) {
llapi_printf(LLAPI_MSG_NORMAL, "lmm_magic: 0x%08X\n",
llapi_printf(LLAPI_MSG_NORMAL, "lmm_object_id: %#jx\n",
(uintmax_t)lmm_oi_id(&lum->lmm_oi));
}
+ if ((verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) && !is_dir) {
+ if (verbose & ~VERBOSE_DFID)
+ llapi_printf(LLAPI_MSG_NORMAL, "lmm_fid: ");
+ /* 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. */
+ llapi_printf(LLAPI_MSG_NORMAL, DFID"\n",
+ lmm_oi_seq(&lum->lmm_oi) == 0 ?
+ lmm_oi_id(&lum->lmm_oi) :
+ lmm_oi_seq(&lum->lmm_oi),
+ lmm_oi_seq(&lum->lmm_oi) == 0 ?
+ 0 : (__u32)lmm_oi_id(&lum->lmm_oi),
+ (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32));
+ }
- if (verbose & VERBOSE_COUNT) {
- if (verbose & ~VERBOSE_COUNT)
- llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_count: ",
- prefix);
- if (is_dir) {
- if (!raw && lum->lmm_stripe_count == 0) {
- unsigned int scount;
- rc = sattr_cache_get_defaults(NULL, path,
- &scount, NULL,
- NULL);
- if (rc == 0)
+ if (verbose & VERBOSE_COUNT) {
+ if (verbose & ~VERBOSE_COUNT)
+ llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_count: ",
+ prefix);
+ if (is_dir) {
+ if (!raw && lum->lmm_stripe_count == 0) {
+ unsigned int scount;
+ rc = sattr_cache_get_defaults(NULL, path,
+ &scount, NULL,
+ NULL);
+ if (rc == 0)
llapi_printf(LLAPI_MSG_NORMAL, "%d",
scount);
- else
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Cannot determine default"
- " stripe count.");
- } else {
+ else
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Cannot determine default"
+ " stripe count.");
+ } else {
llapi_printf(LLAPI_MSG_NORMAL, "%d",
- lum->lmm_stripe_count ==
- (typeof(lum->lmm_stripe_count))(-1)
+ lum->lmm_stripe_count ==
+ (typeof(lum->lmm_stripe_count))(-1)
? -1 : lum->lmm_stripe_count);
- }
- } else {
+ }
+ } else {
llapi_printf(LLAPI_MSG_NORMAL, "%hd",
(__s16)lum->lmm_stripe_count);
- }
+ }
separator = is_dir ? " " : "\n";
- }
+ }
- if (verbose & VERBOSE_SIZE) {
+ if (verbose & VERBOSE_SIZE) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_SIZE)
- llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_size: ",
- prefix);
- if (is_dir && !raw && lum->lmm_stripe_size == 0) {
- unsigned int ssize;
- rc = sattr_cache_get_defaults(NULL, path, NULL, &ssize,
- NULL);
- if (rc == 0)
+ if (verbose & ~VERBOSE_SIZE)
+ llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_size: ",
+ prefix);
+ if (is_dir && !raw && lum->lmm_stripe_size == 0) {
+ unsigned int ssize;
+ rc = sattr_cache_get_defaults(NULL, path, NULL, &ssize,
+ NULL);
+ if (rc == 0)
llapi_printf(LLAPI_MSG_NORMAL, "%u", ssize);
- else
- llapi_error(LLAPI_MSG_ERROR, rc,
- "Cannot determine default"
- " stripe size.");
- } else {
+ else
+ llapi_error(LLAPI_MSG_ERROR, rc,
+ "Cannot determine default"
+ " stripe size.");
+ } else {
llapi_printf(LLAPI_MSG_NORMAL, "%u",
lum->lmm_stripe_size);
- }
+ }
separator = is_dir ? " " : "\n";
- }
+ }
if ((verbose & VERBOSE_LAYOUT) && !is_dir) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
separator = "\n";
}
- if ((verbose & VERBOSE_GENERATION) && !is_dir) {
+ if ((verbose & VERBOSE_GENERATION) && !is_dir) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_GENERATION)
- llapi_printf(LLAPI_MSG_NORMAL, "%slayout_gen: ",
- prefix);
+ if (verbose & ~VERBOSE_GENERATION)
+ llapi_printf(LLAPI_MSG_NORMAL, "%slayout_gen: ",
+ prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%u",
(int)lum->lmm_layout_gen);
separator = "\n";
- }
+ }
- if (verbose & VERBOSE_OFFSET) {
+ if (verbose & VERBOSE_OFFSET) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_OFFSET)
- llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset: ",
- prefix);
- if (is_dir)
+ if (verbose & ~VERBOSE_OFFSET)
+ llapi_printf(LLAPI_MSG_NORMAL, "%sstripe_offset: ",
+ prefix);
+ if (is_dir)
llapi_printf(LLAPI_MSG_NORMAL, "%d",
- lum->lmm_stripe_offset ==
- (typeof(lum->lmm_stripe_offset))(-1) ? -1 :
+ lum->lmm_stripe_offset ==
+ (typeof(lum->lmm_stripe_offset))(-1) ? -1 :
lum->lmm_stripe_offset);
- else
+ else
llapi_printf(LLAPI_MSG_NORMAL, "%u",
objects[0].l_ost_idx);
separator = is_dir ? " " : "\n";
- }
+ }
- if ((verbose & VERBOSE_POOL) && (pool_name != NULL)) {
+ if ((verbose & VERBOSE_POOL) && (pool_name != NULL)) {
llapi_printf(LLAPI_MSG_NORMAL, "%s", separator);
- if (verbose & ~VERBOSE_POOL)
- llapi_printf(LLAPI_MSG_NORMAL, "%spool: ",
- prefix);
+ if (verbose & ~VERBOSE_POOL)
+ llapi_printf(LLAPI_MSG_NORMAL, "%spool: ",
+ prefix);
llapi_printf(LLAPI_MSG_NORMAL, "%s", pool_name);
- }
+ }
- if (!is_dir || (is_dir && (verbose != VERBOSE_OBJID)))
- llapi_printf(LLAPI_MSG_NORMAL, "\n");
+ if (!is_dir || (is_dir && (verbose != VERBOSE_OBJID)))
+ llapi_printf(LLAPI_MSG_NORMAL, "\n");
}
void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name,
int llapi_fid2path(const char *device, const char *fidstr, char *buf,
int buflen, long long *recno, int *linkno)
{
+ const char *fidstr_orig = fidstr;
struct lu_fid fid;
struct getinfo_fid2path *gf;
int rc;
sscanf(fidstr, SFID, RFID(&fid));
if (!fid_is_sane(&fid)) {
llapi_err_noerrno(LLAPI_MSG_ERROR,
- "bad FID format [%s], should be [seq:oid:ver]"
- " (e.g. "DFID")\n", fidstr,
+ "bad FID format '%s', should be [seq:oid:ver]"
+ " (e.g. "DFID")\n", fidstr_orig,
(unsigned long long)FID_SEQ_NORMAL, 2, 0);
return -EINVAL;
}
gf = malloc(sizeof(*gf) + buflen);
if (gf == NULL)
return -ENOMEM;
+
gf->gf_fid = fid;
gf->gf_recno = *recno;
gf->gf_linkno = *linkno;
/* Take path or fsname */
rc = root_ioctl(device, OBD_IOC_FID2PATH, gf, NULL, 0);
- if (rc) {
- if (rc != -ENOENT)
- llapi_error(LLAPI_MSG_ERROR, rc, "ioctl err %d", rc);
- } else {
- memcpy(buf, gf->gf_u.gf_path, gf->gf_pathlen);
- if (buf[0] == '\0') { /* ROOT path */
- buf[0] = '/';
- buf[1] = '\0';
- }
- *recno = gf->gf_recno;
- *linkno = gf->gf_linkno;
- }
+ if (rc)
+ goto out_free;
- free(gf);
- return rc;
+ memcpy(buf, gf->gf_u.gf_path, gf->gf_pathlen);
+ if (buf[0] == '\0') { /* ROOT path */
+ buf[0] = '/';
+ buf[1] = '\0';
+ }
+ *recno = gf->gf_recno;
+ *linkno = gf->gf_linkno;
+
+out_free:
+ free(gf);
+ return rc;
}
static int fid_from_lma(const char *path, const int fd, lustre_fid *fid)