Whamcloud - gitweb
LU-14199 sec: find policy version in use for sepol
[fs/lustre-release.git] / lustre / utils / liblustreapi_hsm.c
index 39624f2..8d9938b 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 {
@@ -657,8 +657,6 @@ err:
 out_free:
        if (json_items != NULL)
                llapi_json_destroy_list(&json_items);
-
-       return;
 }
 
 /** Register a copytool
@@ -996,7 +994,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 +1007,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 +1022,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);
 
@@ -1060,7 +1058,7 @@ static int create_restore_volatile(struct hsm_copyaction_private *hcp,
        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 +1128,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;
 
@@ -1140,7 +1138,37 @@ int llapi_hsm_action_begin(struct hsm_copyaction_private **phcp,
                        goto err_out;
        } else if (hai->hai_action == HSMA_REMOVE) {
                /* Since remove is atomic there is no need to send an
-                * initial MDS_HSM_PROGRESS RPC. */
+                * initial MDS_HSM_PROGRESS RPC.
+                * RW-PCC uses Lustre HSM mechanism for data synchronization.
+                * At the beginning of RW-PCC attach, the client tries to
+                * exclusively open the file by using a lease lock. A
+                * successful lease open ensures that the current attach
+                * process is the unique opener for the file.
+                * After taking the lease, the file data is then copied from
+                * OSTs into PCC and then the client closes the lease with
+                * with a PCC attach intent.
+                * However, for a file with HSM exists, archived state (i.e. a
+                * cached file just was detached from PCC and restore into
+                * OST), a HSM REMOVE request may delete the above PCC copy
+                * during RW-PCC attach wrongly.
+                * Thus, a open/close on the corresponding Lustre file is added
+                * for HSMA_REMOVE here to solve this conflict.
+                */
+               fd = ct_open_by_fid(hcp->ct_priv, &hai->hai_fid,
+                               O_RDONLY | O_NOATIME | O_NOFOLLOW | O_NONBLOCK);
+               if (fd < 0) {
+                       rc = fd;
+                       /* ignore the error in case of Remove Archive on Last
+                        * Unlink (RAoLU).
+                        */
+                       if (rc == -ENOENT) {
+                               rc = 0;
+                               goto out_log;
+                       }
+                       goto err_out;
+               }
+
+               hcp->source_fd = fd;
                goto out_log;
        }
 
@@ -1199,12 +1227,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);