Whamcloud - gitweb
LU-14494 mdt: check object exists in mdt_close_handle_layouts() 05/41905/7
authorJohn L. Hammond <jhammond@whamcloud.com>
Fri, 5 Mar 2021 18:47:43 +0000 (12:47 -0600)
committerOleg Drokin <green@whamcloud.com>
Tue, 30 Mar 2021 04:16:18 +0000 (04:16 +0000)
In mdt_close_handle_layouts() the client supplied FID may not identify
an existing object. So check for this before calling lu_object_attr().

Signed-off-by: John L. Hammond <jhammond@whamcloud.com>
Change-Id: Ib1710ca4bf7587e0496b3a37a2afb65f81250455
Reviewed-on: https://review.whamcloud.com/41905
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Alex Zhuravlev <bzzz@whamcloud.com>
Reviewed-by: Mike Pershin <mpershin@whamcloud.com>
lustre/mdt/mdt_open.c

index 837323e..b839eaa 100644 (file)
@@ -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_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;
        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 (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);
                GOTO(out_obj, rc = -EINVAL);
-       }
 
        if (swap_objects)
                swap(o1, o2);
 
        if (swap_objects)
                swap(o1, o2);
@@ -2181,7 +2182,9 @@ out_unlock_sem:
        }
 
 out_obj:
        }
 
 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);
 
 
        ldlm_reprocess_all(lease->l_resource, lease);