if (get_user(pathlen, &gfin->gf_pathlen))
RETURN(-EFAULT);
- if (pathlen > PATH_MAX)
- RETURN(-EINVAL);
pathlen_orig = pathlen;
gf_alloc:
int remote_gf_size = 0;
int currentisenc = 0;
int globalisenc = 0;
+ int excess;
int rc;
gf = karg;
}
}
- CDEBUG(D_INFO, "%s: get path %s "DFID" rec: %llu ln: %u\n",
+ excess = gf->gf_pathlen > 3072 ? gf->gf_pathlen - 3072 : 0;
+ CDEBUG(D_INFO, "%s: get path %.*s "DFID" rec: %llu ln: %u\n",
tgt->ltd_exp->exp_obd->obd_name,
- gf->gf_u.gf_path, PFID(&gf->gf_fid), gf->gf_recno,
- gf->gf_linkno);
+ gf->gf_pathlen - excess, gf->gf_u.gf_path + excess,
+ PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno);
if (rc == 0)
GOTO(out_fid2path, rc);
{
struct mdt_device *mdt = info->mti_mdt;
struct mdt_object *obj;
- int rc;
+ int excess;
+ int rc;
ENTRY;
rc = mdt_path(info, obj, fp, root_fid);
- CDEBUG(D_INFO, "fid "DFID", path %s recno %#llx linkno %u\n",
- PFID(&fp->gf_fid), fp->gf_u.gf_path,
- fp->gf_recno, fp->gf_linkno);
+ excess = fp->gf_pathlen > 3072 ? fp->gf_pathlen - 3072 : 0;
+ CDEBUG(D_INFO, "fid "DFID", path %.*s recno %#llx linkno %u\n",
+ PFID(&fp->gf_fid), fp->gf_pathlen - excess,
+ fp->gf_u.gf_path + excess, fp->gf_recno, fp->gf_linkno);
mdt_object_put(info->mti_env, obj);
}
run_test 154h "Verify interactive path2fid"
+test_154i()
+{
+ local long=thislongpathnameisforaverydeepsubdirthatwewanttotestagainst
+ local depth
+ local path
+ local max
+ local fid
+
+ mkdir -p $DIR/$tdir
+ cd $DIR/$tdir
+
+ # create a directory tree with full path longer than PATH_MAX=4096
+ max=$((4096 / $(wc -c <<< $long) + 5))
+ for (( depth = 0; depth <= max; depth++)); do
+ mkdir -v $long$depth || error "mkdir $long$depth failed"
+ cd $long$depth
+ done
+
+ fid=$($LFS path2fid .) || error "path2fid failed"
+ path=$($LFS fid2path $MOUNT $fid) || error "fid2path failed (1)"
+ echo -e "Path for fid $fid is:\n$path"
+
+ path=$($LFS fid2path $(cd ..; pwd) $fid) || error "fid2path failed (2)"
+ echo -e "Path for fid $fid is:\n$path"
+}
+run_test 154i "fid2path for path longer than PATH_MAX"
+
test_155_small_load() {
local temp=$TMP/$tfile
local file=$DIR/$tfile
bool print_link = false;
bool print_fid = false;
bool print_mnt_dir;
- char mnt_dir[PATH_MAX] = "";
+ char *mnt_dir = NULL;
+ int mnt_dir_len = PATH_MAX + 1;
int mnt_fd = -1;
char *path_or_fsname;
long long recno = -1;
}
path_or_fsname = argv[optind];
+ if (path_or_fsname && strlen(path_or_fsname))
+ mnt_dir_len = strlen(path_or_fsname) + 1;
+ mnt_dir = malloc(mnt_dir_len + 1);
+ if (!mnt_dir) {
+ rc = -ENOMEM;
+ goto out;
+ }
if (*path_or_fsname == '/') {
print_mnt_dir = true;
for (i = optind + 1; i < argc; i++) {
const char *fid_str = argv[i];
+ int path_len = PATH_MAX;
+ char *path_buf;
struct lu_fid fid;
char *ptr = NULL;
int rc2;
int linktmp = (linkno >= 0) ? linkno : 0;
+ path_buf = malloc(path_len);
+ if (!path_buf) {
+ if (rc == 0)
+ rc = -ENOMEM;
+ continue;
+ }
+
while (1) {
int oldtmp = linktmp;
long long rectmp = recno;
- char path_buf[PATH_MAX];
+fid2path:
rc2 = llapi_fid2path_at(mnt_fd, &fid, path_buf,
- sizeof(path_buf), &rectmp,
+ path_len, &rectmp,
&linktmp);
if (rc2 < 0) {
+ if (rc2 == -ERANGE) {
+ char *tmpbuf;
+
+ path_len += PATH_MAX;
+ tmpbuf = realloc(path_buf, path_len);
+ if (!tmpbuf) {
+ if (rc == 0)
+ rc = -ENOMEM;
+ break;
+ }
+ path_buf = tmpbuf;
+ goto fid2path;
+ }
fprintf(stderr,
"%s fid2path: cannot find %s %s: %s\n",
progname, path_or_fsname, fid_str,
/* no more links */
break;
}
+ free(path_buf);
}
out:
if (!(mnt_fd < 0))
close(mnt_fd);
+ free(mnt_dir);
return rc;
}