Whamcloud - gitweb
LU-14398 hsm: use llapi_fid2path_at() in the copytool
[fs/lustre-release.git] / lustre / utils / liblustreapi_hsm.c
index c8a68ef..ba99cd3 100644 (file)
@@ -81,7 +81,7 @@ struct hsm_copyaction_private {
        __s32                                    data_fd;
        const struct hsm_copytool_private       *ct_priv;
        struct hsm_copy                          copy;
-       lstat_t                                  stat;
+       lstatx_t                                 statx;
 };
 
 enum ct_progress_type {
@@ -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) {
-               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;
 
@@ -657,8 +658,6 @@ err:
 out_free:
        if (json_items != NULL)
                llapi_json_destroy_list(&json_items);
-
-       return;
 }
 
 /** Register a copytool
@@ -939,25 +938,22 @@ out_err:
  * \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];
-       char             strfid[FID_NOBRACE_LEN + 1];
        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 */
-       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;
 
@@ -996,7 +992,7 @@ static int ct_open_by_fid(const struct hsm_copytool_private *ct,
  */
 static int ct_md_getattr(const struct hsm_copytool_private *ct,
                         const struct lu_fid *fid,
-                        lstat_t *st)
+                        lstatx_t *stx)
 {
        struct lov_user_mds_data *lmd;
        char fname[FID_NOBRACE_LEN + 1] = "";
@@ -1009,11 +1005,11 @@ static int ct_md_getattr(const struct hsm_copytool_private *ct,
        if (rc >= sizeof(fname) || rc == 0)
                return -EINVAL;
 
-       lmd_size = sizeof(lmd->lmd_st) +
+       lmd_size = offsetof(typeof(*lmd), lmd_lmm) +
                lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3);
 
-       if (lmd_size < sizeof(lmd->lmd_st) + XATTR_SIZE_MAX)
-               lmd_size = sizeof(lmd->lmd_st) + XATTR_SIZE_MAX;
+       if (lmd_size < offsetof(typeof(*lmd), lmd_lmm) + XATTR_SIZE_MAX)
+               lmd_size = offsetof(typeof(*lmd), lmd_lmm) + XATTR_SIZE_MAX;
 
        lmd = malloc(lmd_size);
        if (lmd == NULL)
@@ -1024,7 +1020,7 @@ static int ct_md_getattr(const struct hsm_copytool_private *ct,
        if (rc)
                goto out;
 
-       *st = lmd->lmd_st;
+       *stx = lmd->lmd_stx;
 out:
        free(lmd);
 
@@ -1041,26 +1037,26 @@ out:
 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" "
-                           "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);
        if (fd < 0)
                return fd;
 
-       rc = fchown(fd, hcp->stat.st_uid, hcp->stat.st_gid);
+       rc = fchown(fd, hcp->statx.stx_uid, hcp->statx.stx_gid);
        if (rc < 0)
                goto err_cleanup;
 
@@ -1130,7 +1126,7 @@ int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp,
 
                hcp->source_fd = fd;
        } else if (hai->hai_action == HSMA_RESTORE) {
-               rc = ct_md_getattr(hcp->ct_priv, &hai->hai_fid, &hcp->stat);
+               rc = ct_md_getattr(hcp->ct_priv, &hai->hai_fid, &hcp->statx);
                if (rc < 0)
                        goto err_out;
 
@@ -1229,12 +1225,12 @@ int llapi_hsm_action_end(struct hsm_copyaction_private **phcp,
 
        if (hai->hai_action == HSMA_RESTORE && errval == 0) {
                struct ll_futimes_3 lfu = {
-                       .lfu_atime_sec = hcp->stat.st_atim.tv_sec,
-                       .lfu_atime_nsec = hcp->stat.st_atim.tv_nsec,
-                       .lfu_mtime_sec = hcp->stat.st_mtim.tv_sec,
-                       .lfu_mtime_nsec = hcp->stat.st_mtim.tv_nsec,
-                       .lfu_ctime_sec = hcp->stat.st_ctim.tv_sec,
-                       .lfu_ctime_nsec = hcp->stat.st_ctim.tv_nsec,
+                       .lfu_atime_sec = hcp->statx.stx_atime.tv_sec,
+                       .lfu_atime_nsec = hcp->statx.stx_atime.tv_nsec,
+                       .lfu_mtime_sec = hcp->statx.stx_mtime.tv_sec,
+                       .lfu_mtime_nsec = hcp->statx.stx_mtime.tv_nsec,
+                       .lfu_ctime_sec = hcp->statx.stx_ctime.tv_sec,
+                       .lfu_ctime_nsec = hcp->statx.stx_ctime.tv_nsec,
                };
 
                rc = fsync(hcp->data_fd);