Whamcloud - gitweb
LU-14398 hsm: use llapi_fid2path_at() in the copytool 08/41408/2
authorJohn L. Hammond <jhammond@whamcloud.com>
Wed, 3 Feb 2021 20:19:05 +0000 (14:19 -0600)
committerOleg Drokin <green@whamcloud.com>
Mon, 22 Mar 2021 16:26:04 +0000 (16:26 +0000)
In lhsmtool_posix.c and liblustreapi_hsm.c, convert several uses of
uses of llapi_fid2path() to llapi_fid2path_at().

Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: Ice64d02010b4260287be4d4e26c6b75b178bc81b
Reviewed-on: https://review.whamcloud.com/41408
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/utils/lhsmtool_posix.c
lustre/utils/liblustreapi_hsm.c

index 67f0579..3a75678 100644 (file)
@@ -1086,17 +1086,19 @@ static int ct_archive(const struct hsm_action_item *hai, const long hal_flags)
                int              depth = 0;
                ssize_t          sz;
 
                int              depth = 0;
                ssize_t          sz;
 
-               sprintf(buf, DFID, PFID(&hai->hai_fid));
                sprintf(src, "%s/shadow/", opt.o_hsm_root);
 
                ptr = opt.o_hsm_root;
                while (*ptr)
                        (*ptr++ == '/') ? depth-- : 0;
 
                sprintf(src, "%s/shadow/", opt.o_hsm_root);
 
                ptr = opt.o_hsm_root;
                while (*ptr)
                        (*ptr++ == '/') ? depth-- : 0;
 
-               rc = llapi_fid2path(opt.o_mnt, buf, src + strlen(src),
-                                   sizeof(src) - strlen(src), &recno, &linkno);
+               rc = llapi_fid2path_at(opt.o_mnt_fd, &hai->hai_fid,
+                                      src + strlen(src),
+                                      sizeof(src) - strlen(src),
+                                      &recno, &linkno);
                if (rc < 0) {
                if (rc < 0) {
-                       CT_ERROR(rc, "cannot get FID of '%s'", buf);
+                       CT_ERROR(rc, "cannot get FID of "DFID,
+                                PFID(&hai->hai_fid));
                        rcf = rcf ? rcf : rc;
                        goto fini_minor;
                }
                        rcf = rcf ? rcf : rc;
                        goto fini_minor;
                }
@@ -1350,19 +1352,19 @@ static int ct_process_item(struct hsm_action_item *hai, const long hal_flags)
 
        if (opt.o_verbose >= LLAPI_MSG_INFO || opt.o_dry_run) {
                /* Print the original path */
 
        if (opt.o_verbose >= LLAPI_MSG_INFO || opt.o_dry_run) {
                /* Print the original path */
-               char            fid[128];
                char            path[PATH_MAX];
                long long       recno = -1;
                int             linkno = 0;
 
                char            path[PATH_MAX];
                long long       recno = -1;
                int             linkno = 0;
 
-               sprintf(fid, DFID, PFID(&hai->hai_fid));
-               CT_TRACE("'%s' action %s reclen %d, cookie=%#jx",
-                        fid, hsm_copytool_action2name(hai->hai_action),
+               CT_TRACE(DFID" action %s reclen %d, cookie=%#jx",
+                        PFID(&hai->hai_fid),
+                        hsm_copytool_action2name(hai->hai_action),
                         hai->hai_len, (uintmax_t)hai->hai_cookie);
                         hai->hai_len, (uintmax_t)hai->hai_cookie);
-               rc = llapi_fid2path(opt.o_mnt, fid, path,
-                                   sizeof(path), &recno, &linkno);
+               rc = llapi_fid2path_at(opt.o_mnt_fd, &hai->hai_fid, path,
+                                      sizeof(path), &recno, &linkno);
                if (rc < 0)
                if (rc < 0)
-                       CT_ERROR(rc, "cannot get path of FID %s", fid);
+                       CT_ERROR(rc, "cannot get path of "DFID,
+                                PFID(&hai->hai_fid));
                else
                        CT_TRACE("processing file '%s'", path);
        }
                else
                        CT_TRACE("processing file '%s'", path);
        }
index 8d9938b..ba99cd3 100644 (file)
@@ -412,8 +412,9 @@ static int llapi_hsm_log_ct_progress(struct hsm_copyaction_private **phcp,
        /* lustre_path isn't available after a restore completes */
        /* total_bytes isn't available after a restore or archive completes */
        if (progress_type != CT_FINISH) {
        /* lustre_path isn't available after a restore completes */
        /* total_bytes isn't available after a restore or archive completes */
        if (progress_type != CT_FINISH) {
-               rc = llapi_fid2path(hcp->ct_priv->mnt, strfid, lustre_path,
-                                   sizeof(lustre_path), &recno, &linkno);
+               rc = llapi_fid2path_at(hcp->ct_priv->mnt_fd, &hai->hai_dfid,
+                                      lustre_path, sizeof(lustre_path),
+                                      &recno, &linkno);
                if (rc < 0)
                        goto err;
 
                if (rc < 0)
                        goto err;
 
@@ -937,25 +938,22 @@ out_err:
  * \param parent_len Destination buffer size.
  * \return 0 on success.
  */
  * \param parent_len Destination buffer size.
  * \return 0 on success.
  */
-static int fid_parent(const char *mnt, const struct lu_fid *fid, char *parent,
-                     size_t parent_len)
+static int fid_parent(const struct hsm_copytool_private *ct,
+                     const struct lu_fid *fid, char *parent, size_t parent_len)
 {
        int              rc;
        int              linkno = 0;
        long long        recno = -1;
        char             file[PATH_MAX];
 {
        int              rc;
        int              linkno = 0;
        long long        recno = -1;
        char             file[PATH_MAX];
-       char             strfid[FID_NOBRACE_LEN + 1];
        char            *ptr;
 
        char            *ptr;
 
-       snprintf(strfid, sizeof(strfid), DFID_NOBRACE, PFID(fid));
-
-       rc = llapi_fid2path(mnt, strfid, file, sizeof(file),
-                           &recno, &linkno);
+       rc = llapi_fid2path_at(ct->mnt_fd, fid, file, sizeof(file),
+                              &recno, &linkno);
        if (rc < 0)
                return rc;
 
        /* fid2path returns a relative path */
        if (rc < 0)
                return rc;
 
        /* fid2path returns a relative path */
-       rc = snprintf(parent, parent_len, "%s/%s", mnt, file);
+       rc = snprintf(parent, parent_len, "%s/%s", ct->mnt, file);
        if (rc >= parent_len)
                return -ENAMETOOLONG;
 
        if (rc >= parent_len)
                return -ENAMETOOLONG;
 
@@ -1039,19 +1037,19 @@ out:
 static int create_restore_volatile(struct hsm_copyaction_private *hcp,
                                   int mdt_index, int open_flags)
 {
 static int create_restore_volatile(struct hsm_copyaction_private *hcp,
                                   int mdt_index, int open_flags)
 {
-       int                      rc;
-       int                      fd;
-       char                     parent[PATH_MAX + 1];
-       const char              *mnt = hcp->ct_priv->mnt;
-       struct hsm_action_item  *hai = &hcp->copy.hc_hai;
+       const struct hsm_copytool_private *ct = hcp->ct_priv;
+       struct hsm_action_item *hai = &hcp->copy.hc_hai;
+       char parent[PATH_MAX + 1];
+       int fd;
+       int rc;
 
 
-       rc = fid_parent(mnt, &hai->hai_fid, parent, sizeof(parent));
+       rc = fid_parent(ct, &hai->hai_fid, parent, sizeof(parent));
        if (rc < 0) {
                /* fid_parent() failed, try to keep on going */
                llapi_error(LLAPI_MSG_ERROR, rc,
                            "cannot get parent path to restore "DFID" "
        if (rc < 0) {
                /* fid_parent() failed, try to keep on going */
                llapi_error(LLAPI_MSG_ERROR, rc,
                            "cannot get parent path to restore "DFID" "
-                           "using '%s'", PFID(&hai->hai_fid), mnt);
-               snprintf(parent, sizeof(parent), "%s", mnt);
+                           "using '%s'", PFID(&hai->hai_fid), ct->mnt);
+               snprintf(parent, sizeof(parent), "%s", ct->mnt);
        }
 
        fd = llapi_create_volatile_idx(parent, mdt_index, open_flags);
        }
 
        fd = llapi_create_volatile_idx(parent, mdt_index, open_flags);