Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / mdc / mdc_locks.c
index 70aca4a..932564d 100644 (file)
@@ -307,19 +307,11 @@ static struct ptlrpc_request *mdc_intent_open_pack(struct obd_export *exp,
                                      RCL_CLIENT, 0);
         }
 
-        if (exp_connect_cancelset(exp) && count) {
-                req_capsule_set_size(&req->rq_pill, &RMF_DLM_REQ, RCL_CLIENT,
-                                     ldlm_request_bufsize(count, LDLM_ENQUEUE));
-        }
-
-        rc = ptlrpc_request_pack(req, LUSTRE_DLM_VERSION, LDLM_ENQUEUE);
+        rc = ldlm_prep_enqueue_req(exp, req, &cancels, count);
         if (rc) {
                 ptlrpc_request_free(req);
-                ldlm_lock_list_put(&cancels, l_bl_ast, count);
                 return NULL;
         }
-        if (exp_connect_cancelset(exp) && req)
-                ldlm_cli_cancel_list(&cancels, count, req, 0);
 
         if (joinfile) {
                 __u64 head_size = *(__u64 *)op_data->op_data;
@@ -365,7 +357,7 @@ static struct ptlrpc_request *mdc_intent_unlink_pack(struct obd_export *exp,
         req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                              op_data->op_namelen + 1);
 
-        rc = ptlrpc_request_pack(req, LUSTRE_DLM_VERSION, LDLM_ENQUEUE);
+        rc = ldlm_prep_enqueue_req(exp, req, NULL, 0);
         if (rc) {
                 ptlrpc_request_free(req);
                 RETURN(ERR_PTR(rc));
@@ -410,7 +402,7 @@ static struct ptlrpc_request *mdc_intent_getattr_pack(struct obd_export *exp,
         req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
                              op_data->op_namelen + 1);
 
-        rc = ptlrpc_request_pack(req, LUSTRE_DLM_VERSION, LDLM_ENQUEUE);
+        rc = ldlm_prep_enqueue_req(exp, req, NULL, 0);
         if (rc) {
                 ptlrpc_request_free(req);
                 RETURN(ERR_PTR(rc));
@@ -435,14 +427,19 @@ static struct ptlrpc_request *mdc_intent_getattr_pack(struct obd_export *exp,
 static struct ptlrpc_request *ldlm_enqueue_pack(struct obd_export *exp)
 {
         struct ptlrpc_request *req;
+        int rc;
         ENTRY;
 
-        req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
-                                        &RQF_LDLM_ENQUEUE, LUSTRE_DLM_VERSION,
-                                        LDLM_ENQUEUE);
+        req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_LDLM_ENQUEUE);
         if (req == NULL)
                 RETURN(ERR_PTR(-ENOMEM));
 
+        rc = ldlm_prep_enqueue_req(exp, req, NULL, 0);
+        if (rc) {
+                ptlrpc_request_free(req);
+                RETURN(ERR_PTR(rc));
+        }
+
         ptlrpc_request_set_replen(req);
         RETURN(req);
 }
@@ -644,11 +641,10 @@ int mdc_enqueue(struct obd_export *exp, struct ldlm_enqueue_info *einfo,
                         struct mdt_remote_perm *perm;
 
                         LASSERT(client_is_remote(exp));
-                        perm = req_capsule_server_get(pill, &RMF_ACL);
+                        perm = req_capsule_server_swab_get(pill, &RMF_ACL,
+                                                lustre_swab_mdt_remote_perm);
                         if (perm == NULL)
                                 RETURN(-EPROTO);
-
-                        lustre_swab_mdt_remote_perm(perm);
                 }
                 if (body->valid & OBD_MD_FLMDSCAPA) {
                         struct lustre_capa *capa, *p;
@@ -817,8 +813,17 @@ int mdc_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
                 it_set_disposition(it, DISP_ENQ_COMPLETE);
 
                 /* Also: did we find the same inode? */
-                if (!lu_fid_eq(&op_data->op_fid2, &mdt_body->fid1))
+                /* sever can return one of two fids:
+                 * op_fid2 - new allocated fid - if file is created.
+                 * op_fid3 - existent fid - if file only open.
+                 * op_fid3 is saved in lmv_intent_open */
+                if ((!lu_fid_eq(&op_data->op_fid2, &mdt_body->fid1)) &&
+                    (!lu_fid_eq(&op_data->op_fid3, &mdt_body->fid1))) {
+                        CDEBUG(D_DENTRY, "Found stale data "DFID"("DFID")/"DFID
+                               "\n", PFID(&op_data->op_fid2),
+                               PFID(&op_data->op_fid2), PFID(&mdt_body->fid1));
                         RETURN(-ESTALE);
+                }
         }
 
         rc = it_open_error(DISP_LOOKUP_EXECD, it);