Whamcloud - gitweb
LU-14494 mdt: check object exists in mdt_close_handle_layouts()
[fs/lustre-release.git] / lustre / mdt / mdt_open.c
index ef12eb1..b839eaa 100644 (file)
@@ -1695,7 +1695,7 @@ static struct mdt_object *mdt_orphan_open(struct mdt_thread_info *info,
 
        uc = lu_ucred(env);
        uc_cap_save = uc->uc_cap;
-       uc->uc_cap |= BIT(CFS_CAP_DAC_OVERRIDE);
+       uc->uc_cap |= BIT(CAP_DAC_OVERRIDE);
        rc = mdo_create(env, mdt_object_child(local_root), &lname,
                        mdt_object_child(obj), spec, attr);
        uc->uc_cap = uc_cap_save;
@@ -1967,7 +1967,7 @@ static int mdt_hsm_release(struct mdt_thread_info *info, struct mdt_object *o,
        /* The orphan has root ownership so we need to raise
         * CAP_FOWNER to set the HSM attributes. */
        cap = uc->uc_cap;
-       uc->uc_cap |= MD_CAP_TO_MASK(CFS_CAP_FOWNER);
+       uc->uc_cap |= MD_CAP_TO_MASK(CAP_FOWNER);
        rc = mo_xattr_set(info->mti_env, mdt_object_child(orphan), buf,
                          XATTR_NAME_HSM, 0);
        uc->uc_cap = cap;
@@ -2036,7 +2036,7 @@ int mdt_close_handle_layouts(struct mdt_thread_info *info,
        struct mdt_lock_handle  *lh2 = &info->mti_lh[MDT_LH_OLD];
        struct close_data       *data;
        struct ldlm_lock        *lease;
-       struct mdt_object       *o1 = o, *o2;
+       struct mdt_object       *o1 = o, *o2 = NULL;
        bool                     lease_broken;
        bool                     swap_objects;
        int                      rc;
@@ -2070,10 +2070,11 @@ int mdt_close_handle_layouts(struct mdt_thread_info *info,
        if (IS_ERR(o2))
                GOTO(out_lease, rc = PTR_ERR(o2));
 
-       if (!S_ISREG(lu_object_attr(&o2->mot_obj))) {
-               swap_objects = false; /* not swapped yet */
+       if (!mdt_object_exists(o2))
+               GOTO(out_obj, rc = -ENOENT);
+
+       if (!S_ISREG(lu_object_attr(&o2->mot_obj)))
                GOTO(out_obj, rc = -EINVAL);
-       }
 
        if (swap_objects)
                swap(o1, o2);
@@ -2181,7 +2182,9 @@ out_unlock_sem:
        }
 
 out_obj:
-       mdt_object_put(info->mti_env, swap_objects ? o1 : o2);
+       /* Callee takes care of o, we must put the other one. We know
+        * that o1 != o2 from check of lu_fid_cmp() above. */
+       mdt_object_put(info->mti_env, o1 != o ? o1 : o2);
 
        ldlm_reprocess_all(lease->l_resource, lease);