Whamcloud - gitweb
LU-10948 mdt: Remove openlock compat code with 2.1
[fs/lustre-release.git] / lustre / mdt / mdt_open.c
index 9211ee2..eb43f79 100644 (file)
@@ -542,6 +542,11 @@ static int mdt_finish_open(struct mdt_thread_info *info,
                RETURN(-EOPNOTSUPP);
        }
 
+       /* Overstriped files can crash older clients */
+       if (isreg && !exp_connect_overstriping(exp) &&
+           mdt_lmm_is_overstriping(ma->ma_lmm))
+               RETURN(-EOPNOTSUPP);
+
        /* LU-2275, simulate broken behaviour (esp. prevalent in
         * pre-2.4 servers where a very strange reply is sent on error
         * that looks like it was actually almost successful and a
@@ -1360,11 +1365,7 @@ int mdt_reint_open(struct mdt_thread_info *info, struct mdt_lock_handle *lhc)
                        GOTO(out, result = -EFAULT);
                }
                CDEBUG(D_INFO, "No object(1), continue as regular open.\n");
-       } else if (open_flags & (MDS_OPEN_BY_FID | MDS_OPEN_LOCK)) {
-               /*
-                * MDS_OPEN_LOCK is checked for backward compatibility with 2.1
-                * client.
-                */
+       } else if (open_flags & MDS_OPEN_BY_FID) {
                result = mdt_open_by_fid_lock(info, ldlm_rep, lhc);
                if (result < 0)
                        CDEBUG(D_INFO, "no object for "DFID": %d\n",
@@ -1741,6 +1742,22 @@ static inline int mdt_hsm_set_released(struct lov_mds_md *lmm)
        return 0;
 }
 
+static inline int mdt_get_lmm_gen(struct lov_mds_md *lmm, __u32 *gen)
+{
+       struct lov_comp_md_v1 *comp_v1;
+
+       if (le32_to_cpu(lmm->lmm_magic == LOV_MAGIC_COMP_V1)) {
+               comp_v1 = (struct lov_comp_md_v1 *)lmm;
+               *gen = le32_to_cpu(comp_v1->lcm_layout_gen);
+       } else if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V1 ||
+                  le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_V3) {
+               *gen = le16_to_cpu(lmm->lmm_layout_gen);
+       } else {
+               return -EINVAL;
+       }
+       return 0;
+}
+
 static int mdt_hsm_release(struct mdt_thread_info *info, struct mdt_object *o,
                           struct md_attr *ma)
 {
@@ -1800,19 +1817,66 @@ static int mdt_hsm_release(struct mdt_thread_info *info, struct mdt_object *o,
        if (rc != 0)
                GOTO(out_unlock, rc);
 
-       if (!mdt_hsm_release_allow(ma))
-               GOTO(out_unlock, rc = -EPERM);
-
-       /* already released? */
-       if (ma->ma_hsm.mh_flags & HS_RELEASED)
-               GOTO(out_unlock, rc = 0);
+       if (ma->ma_attr_flags & MDS_PCC_ATTACH) {
+               if (ma->ma_valid & MA_HSM) {
+                       if (ma->ma_hsm.mh_flags & HS_RELEASED)
+                               GOTO(out_unlock, rc = -EALREADY);
+
+                       if (ma->ma_hsm.mh_arch_id != data->cd_archive_id)
+                               CDEBUG(D_CACHE,
+                                      DFID" archive id diff: %llu:%u\n",
+                                      PFID(mdt_object_fid(o)),
+                                      ma->ma_hsm.mh_arch_id,
+                                      data->cd_archive_id);
+
+                       if (!(ma->ma_hsm.mh_flags & HS_DIRTY) &&
+                           ma->ma_hsm.mh_arch_ver == data->cd_data_version) {
+                               CDEBUG(D_CACHE,
+                                      DFID" data version matches: packed=%llu "
+                                      "and on-disk=%llu\n",
+                                      PFID(mdt_object_fid(o)),
+                                      data->cd_data_version,
+                                      ma->ma_hsm.mh_arch_ver);
+                               ma->ma_hsm.mh_flags = HS_ARCHIVED | HS_EXISTS;
+                       }
 
-       /* Compare on-disk and packed data_version */
-       if (data->cd_data_version != ma->ma_hsm.mh_arch_ver) {
-               CDEBUG(D_HSM, DFID" data_version mismatches: packed=%llu"
-                      " and on-disk=%llu\n", PFID(mdt_object_fid(o)),
-                      data->cd_data_version, ma->ma_hsm.mh_arch_ver);
-               GOTO(out_unlock, rc = -EPERM);
+                       if (ma->ma_hsm.mh_flags & HS_DIRTY)
+                               ma->ma_hsm.mh_flags = HS_ARCHIVED | HS_EXISTS;
+               } else {
+                       /* Set up HSM attribte for PCC archived object */
+                       CLASSERT(sizeof(struct hsm_attrs) <=
+                                sizeof(info->mti_xattr_buf));
+                       buf = &info->mti_buf;
+                       buf->lb_buf = info->mti_xattr_buf;
+                       buf->lb_len = sizeof(struct hsm_attrs);
+                       memset(&ma->ma_hsm, 0, sizeof(ma->ma_hsm));
+                       ma->ma_hsm.mh_flags = HS_ARCHIVED | HS_EXISTS;
+                       ma->ma_hsm.mh_arch_id = data->cd_archive_id;
+                       ma->ma_hsm.mh_arch_ver = data->cd_data_version;
+                       lustre_hsm2buf(buf->lb_buf, &ma->ma_hsm);
+
+                       rc = mo_xattr_set(info->mti_env, mdt_object_child(o),
+                                         buf, XATTR_NAME_HSM, 0);
+                       if (rc)
+                               GOTO(out_unlock, rc);
+               }
+       } else {
+               if (!mdt_hsm_release_allow(ma))
+                       GOTO(out_unlock, rc = -EPERM);
+
+               /* already released? */
+               if (ma->ma_hsm.mh_flags & HS_RELEASED)
+                       GOTO(out_unlock, rc = 0);
+
+               /* Compare on-disk and packed data_version */
+               if (data->cd_data_version != ma->ma_hsm.mh_arch_ver) {
+                       CDEBUG(D_HSM, DFID" data_version mismatches: "
+                              "packed=%llu and on-disk=%llu\n",
+                              PFID(mdt_object_fid(o)),
+                              data->cd_data_version,
+                              ma->ma_hsm.mh_arch_ver);
+                       GOTO(out_unlock, rc = -EPERM);
+               }
        }
 
        ma->ma_valid = MA_INODE;
@@ -1908,6 +1972,12 @@ static int mdt_hsm_release(struct mdt_thread_info *info, struct mdt_object *o,
        rc = mo_swap_layouts(info->mti_env, mdt_object_child(o),
                             mdt_object_child(orphan),
                             SWAP_LAYOUTS_MDS_HSM);
+
+       if (!rc && ma->ma_attr_flags & MDS_PCC_ATTACH) {
+               ma->ma_need = MA_LOV;
+               rc = mdt_attr_get_complex(info, o, ma);
+       }
+
        EXIT;
 
 out_layout_lock:
@@ -1934,6 +2004,13 @@ out_unlock:
                repbody = req_capsule_server_get(info->mti_pill, &RMF_MDT_BODY);
                LASSERT(repbody != NULL);
                repbody->mbo_valid |= OBD_MD_CLOSE_INTENT_EXECED;
+               if (ma->ma_attr_flags & MDS_PCC_ATTACH) {
+                       LASSERT(ma->ma_valid & MA_LOV);
+                       rc = mdt_get_lmm_gen(ma->ma_lmm,
+                                            &repbody->mbo_layout_gen);
+                       if (!rc)
+                               repbody->mbo_valid |= OBD_MD_LAYOUT_VERSION;
+               }
        }
 
 out_reprocess: