Whamcloud - gitweb
LU-15132 mdc: Use early cancels for hsm requests
authorEtienne AUJAMES <etienne.aujames@cea.fr>
Mon, 2 May 2022 12:27:17 +0000 (14:27 +0200)
committerAndreas Dilger <adilger@whamcloud.com>
Fri, 14 Oct 2022 20:00:57 +0000 (20:00 +0000)
HSM RELEASE and RESTORE requests take EX layout lock on the MDT side.
So the client can use early cancel for its local lock on the resource
to limit the contention (mdt side).

This patch does not pack ldlm request inside the hsm request because
the field (RMF_DLM_REQ) does not exist in the request. Adding this
field inside the request would break compatibility with _old_ servers.

Lustre-change: https://review.whamcloud.com/47181
Lustre-commit: 60d2a4b0efa4a944b558bd9b63b6334f7e70419b

Signed-off-by: Xing Huang <hxing@ddn.com>
Change-Id: I30a57b4855c28eef9c55a9645d3b6c491f962b13
Reviewed-on: https://review.whamcloud.com/c/ex/lustre-release/+/48652
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Qian Yingjin <qian@ddn.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lustre/mdc/mdc_request.c

index 1c1a007..f4620c5 100644 (file)
@@ -1983,20 +1983,48 @@ out:
        return rc;
 }
 
+/* For RESTORE and RELEASE the mdt will take EX lock on the file layout.
+ * So we can use early cancel on client side locks for that resource.
+ */
+static inline int mdc_hsm_request_lock_to_cancel(struct obd_export *exp,
+                                                struct hsm_user_request *hur,
+                                                struct list_head *cancels)
+{
+       struct hsm_user_item *hui = &hur->hur_user_item[0];
+       struct hsm_request *req_hr = &hur->hur_request;
+       int count = 0;
+       int i;
+
+       if (req_hr->hr_action != HUA_RESTORE &&
+           req_hr->hr_action != HUA_RELEASE)
+               return 0;
+
+       for (i = 0; i < req_hr->hr_itemcount; i++, hui++) {
+               if (!fid_is_sane(&hui->hui_fid))
+                       continue;
+               count += mdc_resource_get_unused(exp, &hui->hui_fid, cancels,
+                                                LCK_EX, MDS_INODELOCK_LAYOUT);
+       }
+
+       return count;
+}
+
 static int mdc_ioc_hsm_request(struct obd_export *exp,
                               struct hsm_user_request *hur)
 {
-       struct obd_import       *imp = class_exp2cliimp(exp);
-       struct ptlrpc_request   *req;
-       struct hsm_request      *req_hr;
-       struct hsm_user_item    *req_hui;
-       char                    *req_opaque;
-       int                      rc;
+       struct obd_import *imp = class_exp2cliimp(exp);
+       struct ptlrpc_request *req;
+       struct hsm_request *req_hr;
+       struct hsm_user_item *req_hui;
+       char *req_opaque;
+       LIST_HEAD(cancels);
+       int count;
+       int rc;
        ENTRY;
 
        req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST);
        if (req == NULL)
-               GOTO(out, rc = -ENOMEM);
+               RETURN(-ENOMEM);
 
        req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT,
                             hur->hur_request.hr_itemcount
@@ -2010,6 +2038,9 @@ static int mdc_ioc_hsm_request(struct obd_export *exp,
                RETURN(rc);
        }
 
+       /* Cancel existing locks */
+       count = mdc_hsm_request_lock_to_cancel(exp, hur, &cancels);
+       ldlm_cli_cancel_list(&cancels, count, NULL, 0);
        mdc_pack_body(&req->rq_pill, NULL, 0, 0, -1, 0);
 
        /* Copy hsm_request struct */