Whamcloud - gitweb
LU-3544 fid: do open-by-fid by default
[fs/lustre-release.git] / lustre / mdc / mdc_locks.c
index 67a2032..2d3d171 100644 (file)
@@ -189,7 +189,7 @@ int mdc_null_inode(struct obd_export *exp,
        fid_build_reg_res_name(fid, &res_id);
 
        res = ldlm_resource_get(ns, NULL, &res_id, 0, 0);
-       if(res == NULL)
+       if (IS_ERR(res))
                RETURN(0);
 
        lock_res(res);
@@ -248,19 +248,19 @@ static inline void mdc_clear_replay_flag(struct ptlrpc_request *req, int rc)
  * but this is incredibly unlikely, and questionable whether the client
  * could do MDS recovery under OOM anyways... */
 static void mdc_realloc_openmsg(struct ptlrpc_request *req,
-                                struct mdt_body *body)
+                               struct mdt_body *body)
 {
-        int     rc;
+       int     rc;
 
-        /* FIXME: remove this explicit offset. */
-        rc = sptlrpc_cli_enlarge_reqbuf(req, DLM_INTENT_REC_OFF + 4,
-                                        body->eadatasize);
-        if (rc) {
-                CERROR("Can't enlarge segment %d size to %d\n",
-                       DLM_INTENT_REC_OFF + 4, body->eadatasize);
-                body->valid &= ~OBD_MD_FLEASIZE;
-                body->eadatasize = 0;
-        }
+       /* FIXME: remove this explicit offset. */
+       rc = sptlrpc_cli_enlarge_reqbuf(req, DLM_INTENT_REC_OFF + 4,
+                                       body->mbo_eadatasize);
+       if (rc) {
+               CERROR("Can't enlarge segment %d size to %d\n",
+                      DLM_INTENT_REC_OFF + 4, body->mbo_eadatasize);
+               body->mbo_valid &= ~OBD_MD_FLEASIZE;
+               body->mbo_eadatasize = 0;
+       }
 }
 
 static struct ptlrpc_request *
@@ -272,14 +272,12 @@ mdc_intent_open_pack(struct obd_export *exp, struct lookup_intent *it,
        struct ldlm_intent      *lit;
        const void              *lmm = op_data->op_data;
        int                      lmmsize = op_data->op_data_size;
-       struct list_head         cancels;
-       int count = 0;
-       int mode;
-       int rc;
+       struct list_head         cancels = LIST_HEAD_INIT(cancels);
+       int                      count = 0;
+       int                      mode;
+       int                      rc;
         ENTRY;
 
-       INIT_LIST_HEAD(&cancels);
-
         it->it_create_mode = (it->it_create_mode & ~S_IFMT) | S_IFREG;
 
         /* XXX: openlock is not cancelled for cross-refs. */
@@ -369,7 +367,7 @@ mdc_intent_getxattr_pack(struct obd_export *exp,
        struct ptlrpc_request   *req;
        struct ldlm_intent      *lit;
        int                     rc, count = 0, maxdata;
-       CFS_LIST_HEAD(cancels);
+       struct list_head        cancels = LIST_HEAD_INIT(cancels);
 
        ENTRY;
 
@@ -653,7 +651,7 @@ static int mdc_finish_enqueue(struct obd_export *exp,
                        mdc_set_open_replay_data(NULL, NULL, it);
                }
 
-                if ((body->valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE)) != 0) {
+               if (body->mbo_valid & (OBD_MD_FLDIREA | OBD_MD_FLEASIZE)) {
                         void *eadata;
 
                        mdc_update_max_ea_from_body(exp, body);
@@ -663,14 +661,14 @@ static int mdc_finish_enqueue(struct obd_export *exp,
                          * Eventually, obd_unpackmd() will check the contents.
                          */
                         eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
-                                                              body->eadatasize);
-                        if (eadata == NULL)
-                                RETURN(-EPROTO);
+                                                       body->mbo_eadatasize);
+                       if (eadata == NULL)
+                               RETURN(-EPROTO);
 
                        /* save lvb data and length in case this is for layout
                         * lock */
                        lvb_data = eadata;
-                       lvb_len = body->eadatasize;
+                       lvb_len = body->mbo_eadatasize;
 
                         /*
                          * We save the reply LOV EA in case we have to replay a
@@ -685,24 +683,25 @@ static int mdc_finish_enqueue(struct obd_export *exp,
                                 void *lmm;
                                 if (req_capsule_get_size(pill, &RMF_EADATA,
                                                          RCL_CLIENT) <
-                                    body->eadatasize)
-                                        mdc_realloc_openmsg(req, body);
-                                else
-                                        req_capsule_shrink(pill, &RMF_EADATA,
-                                                           body->eadatasize,
-                                                           RCL_CLIENT);
-
-                                req_capsule_set_size(pill, &RMF_EADATA,
-                                                     RCL_CLIENT,
-                                                     body->eadatasize);
-
-                                lmm = req_capsule_client_get(pill, &RMF_EADATA);
-                                if (lmm)
-                                        memcpy(lmm, eadata, body->eadatasize);
-                        }
-                }
+                                   body->mbo_eadatasize)
+                                       mdc_realloc_openmsg(req, body);
+                               else
+                                       req_capsule_shrink(pill, &RMF_EADATA,
+                                                          body->mbo_eadatasize,
+                                                          RCL_CLIENT);
+
+                               req_capsule_set_size(pill, &RMF_EADATA,
+                                                    RCL_CLIENT,
+                                                    body->mbo_eadatasize);
+
+                               lmm = req_capsule_client_get(pill, &RMF_EADATA);
+                               if (lmm)
+                                       memcpy(lmm, eadata,
+                                              body->mbo_eadatasize);
+                       }
+               }
 
-                if (body->valid & OBD_MD_FLRMTPERM) {
+               if (body->mbo_valid & OBD_MD_FLRMTPERM) {
                         struct mdt_remote_perm *perm;
 
                         LASSERT(client_is_remote(exp));
@@ -711,7 +710,7 @@ static int mdc_finish_enqueue(struct obd_export *exp,
                         if (perm == NULL)
                                 RETURN(-EPROTO);
                 }
-                if (body->valid & OBD_MD_FLMDSCAPA) {
+               if (body->mbo_valid & OBD_MD_FLMDSCAPA) {
                         struct lustre_capa *capa, *p;
 
                         capa = req_capsule_server_get(pill, &RMF_CAPA1);
@@ -725,7 +724,7 @@ static int mdc_finish_enqueue(struct obd_export *exp,
                                 *p = *capa;
                         }
                 }
-                if (body->valid & OBD_MD_FLOSSCAPA) {
+               if (body->mbo_valid & OBD_MD_FLOSSCAPA) {
                         struct lustre_capa *capa;
 
                         capa = req_capsule_server_get(pill, &RMF_CAPA2);
@@ -830,7 +829,6 @@ resend:
                         einfo->ei_type);
                res_id.name[3] = LDLM_FLOCK;
        } else if (it->it_op & IT_OPEN) {
-               LASSERT(einfo->ei_cbdata == NULL);
                req = mdc_intent_open_pack(exp, it, op_data);
        } else if (it->it_op & IT_UNLINK) {
                req = mdc_intent_unlink_pack(exp, it, op_data);
@@ -900,9 +898,8 @@ resend:
        mdc_put_rpc_lock(obddev->u.cli.cl_rpc_lock, it);
 
        if (rc < 0) {
-               CDEBUG_LIMIT((rc == -EACCES || rc == -EIDRM) ? D_INFO : D_ERROR,
-                            "%s: ldlm_cli_enqueue failed: rc = %d\n",
-                            obddev->obd_name, rc);
+               CDEBUG(D_INFO, "%s: ldlm_cli_enqueue failed: rc = %d\n",
+                      obddev->obd_name, rc);
 
                mdc_clear_replay_flag(req, rc);
                ptlrpc_req_finished(req);
@@ -978,25 +975,6 @@ static int mdc_finish_intent_lock(struct obd_export *exp,
         mdt_body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
         LASSERT(mdt_body != NULL);      /* mdc_enqueue checked */
 
-        /* If we were revalidating a fid/name pair, mark the intent in
-         * case we fail and get called again from lookup */
-        if (fid_is_sane(&op_data->op_fid2) &&
-            it->it_create_mode & M_CHECK_STALE &&
-            it->it_op != IT_GETATTR) {
-                /* Also: did we find the same inode? */
-                /* 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);
         if (rc)
                 RETURN(rc);
@@ -1037,10 +1015,10 @@ static int mdc_finish_intent_lock(struct obd_export *exp,
                 ldlm_policy_data_t policy = lock->l_policy_data;
                 LDLM_DEBUG(lock, "matching against this");
 
-               LASSERTF(fid_res_name_eq(&mdt_body->fid1,
+               LASSERTF(fid_res_name_eq(&mdt_body->mbo_fid1,
                                         &lock->l_resource->lr_name),
                         "Lock res_id: "DLDLMRES", fid: "DFID"\n",
-                        PLDLMRES(lock->l_resource), PFID(&mdt_body->fid1));
+                        PLDLMRES(lock->l_resource), PFID(&mdt_body->mbo_fid1));
                LDLM_LOCK_PUT(lock);
 
                 memcpy(&old_lock, lockh, sizeof(*lockh));
@@ -1187,7 +1165,7 @@ int mdc_intent_lock(struct obd_export *exp, struct md_op_data *op_data,
 
        /* For case if upper layer did not alloc fid, do it now. */
        if (!fid_is_sane(&op_data->op_fid2) && it->it_op & IT_CREAT) {
-               rc = mdc_fid_alloc(exp, &op_data->op_fid2, op_data);
+               rc = mdc_fid_alloc(NULL, exp, &op_data->op_fid2, op_data);
                if (rc < 0) {
                        CERROR("Can't alloc new fid, rc %d\n", rc);
                        RETURN(rc);