Whamcloud - gitweb
b=14538
[fs/lustre-release.git] / lustre / mdc / mdc_locks.c
index 36539f0..44af012 100644 (file)
@@ -190,16 +190,11 @@ static void mdc_realloc_openmsg(struct ptlrpc_request *req,
         struct lustre_msg *new_msg;
 
         old_len = lustre_msg_buflen(old_msg, DLM_INTENT_REC_OFF + 2);
-        /* save old size */
-        old_size = lustre_msg_size(lustre_request_magic(req),
-                                   req->rq_reqmsg->lm_bufcount,
-                                   req->rq_reqmsg->lm_buflens);
-
+        old_size = lustre_packed_msg_size(old_msg);
         lustre_msg_set_buflen(old_msg, DLM_INTENT_REC_OFF + 2,
                               body->eadatasize);
-        new_size = lustre_msg_size(lustre_request_magic(req),
-                                   req->rq_reqmsg->lm_bufcount,
-                                   req->rq_reqmsg->lm_buflens);
+        new_size = lustre_packed_msg_size(old_msg);
+
         OBD_ALLOC(new_msg, new_size);
         if (new_msg != NULL) {
                 DEBUG_REQ(D_INFO, req, "replace reqmsg for larger EA %u\n",
@@ -248,6 +243,7 @@ static struct ptlrpc_request *mdc_intent_open_pack(struct obd_export *exp,
                                                         cl_max_mds_easize,
                            [DLM_REPLY_REC_OFF+2] = LUSTRE_POSIX_ACL_MAX_SIZE };
         CFS_LIST_HEAD(cancels);
+        int do_join = (it->it_flags & O_JOIN_FILE) && data->data;
         int count = 0;
         int mode;
         int rc;
@@ -255,8 +251,8 @@ static struct ptlrpc_request *mdc_intent_open_pack(struct obd_export *exp,
         it->it_create_mode |= S_IFREG;
 
         rc = lustre_msg_size(class_exp2cliimp(exp)->imp_msg_magic, 6, size);
-                if (rc & (rc - 1))
-                        size[DLM_INTENT_REC_OFF + 2] =
+        if (rc & (rc - 1))
+                size[DLM_INTENT_REC_OFF + 2] =
                          min(size[DLM_INTENT_REC_OFF + 2] + round_up(rc) - rc,
                                      obddev->u.cli.cl_max_mds_easize);
 
@@ -275,20 +271,23 @@ static struct ptlrpc_request *mdc_intent_open_pack(struct obd_export *exp,
         }
 
         /* If CREATE or JOIN_FILE, cancel parent's UPDATE lock. */
-        if (it->it_op & IT_CREAT || it->it_flags & O_JOIN_FILE)
+        if (it->it_op & IT_CREAT || do_join)
                 mode = LCK_EX;
         else
                 mode = LCK_CR;
         count += mdc_resource_get_unused(exp, &data->fid1, &cancels, mode,
                                          MDS_INODELOCK_UPDATE);
-        if (it->it_flags & O_JOIN_FILE) {
+        if (do_join) {
                 __u64 head_size = (*(__u64 *)data->data);
                         /* join is like an unlink of the tail */
                 size[DLM_INTENT_REC_OFF + 3] = sizeof(struct mds_rec_join);
                 req = ldlm_prep_enqueue_req(exp, 7, size, &cancels, count);
-                mdc_join_pack(req, DLM_INTENT_REC_OFF + 3, data, head_size);
+                if (req)
+                        mdc_join_pack(req, DLM_INTENT_REC_OFF + 3, data, 
+                                      head_size);
         } else {
                 req = ldlm_prep_enqueue_req(exp, 6, size, &cancels, count);
+                it->it_flags &= ~O_JOIN_FILE;
         }
 
         if (req) {