Whamcloud - gitweb
LU-2783 ofd: Implement OBD_IOC_GET_OBJ_VERSION
[fs/lustre-release.git] / lustre / mdt / mdt_handler.c
index c5293ec..3576847 100644 (file)
@@ -1063,7 +1063,8 @@ int mdt_swap_layouts(struct mdt_thread_info *info)
                GOTO(put, rc);
 
        msl = req_capsule_client_get(info->mti_pill, &RMF_SWAP_LAYOUTS);
-       LASSERT(msl != NULL);
+       if (msl == NULL)
+               GOTO(put, rc = -EPROTO);
 
        lh1 = &info->mti_lh[MDT_LH_NEW];
        mdt_lock_reg_init(lh1, LCK_EX);
@@ -3788,14 +3789,16 @@ static int mdt_intent_reint(enum mdt_it_code opcode,
         if (rc != 0)
                 mdt_set_disposition(info, rep, DISP_LOOKUP_EXECD);
 
-        /* Cross-ref case, the lock should be returned to the client */
-        if (rc == -EREMOTE) {
-                LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
-                rep->lock_policy_res2 = 0;
-                rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
-                RETURN(rc);
-        }
-        rep->lock_policy_res2 = clear_serious(rc);
+       /* the open lock or the lock for cross-ref object should be
+        * returned to the client */
+       if (rc == -EREMOTE || mdt_get_disposition(rep, DISP_OPEN_LOCK)) {
+               LASSERT(lustre_handle_is_used(&lhc->mlh_reg_lh));
+               rep->lock_policy_res2 = 0;
+               rc = mdt_intent_lock_replace(info, lockp, NULL, lhc, flags);
+               RETURN(rc);
+       }
+
+       rep->lock_policy_res2 = clear_serious(rc);
 
         if (rep->lock_policy_res2 == -ENOENT &&
             mdt_get_disposition(rep, DISP_LOOKUP_NEG))
@@ -5703,6 +5706,8 @@ static int mdt_fid2path(struct mdt_thread_info *info,
                rc = -EREMOTE;
        else if (!mdt_object_exists(obj))
                rc = -ENOENT;
+       else
+               rc = 0;
 
        if (rc < 0) {
                mdt_object_put(info->mti_env, obj);
@@ -5811,17 +5816,24 @@ static int mdt_ioc_child(struct lu_env *env, struct mdt_device *mdt,
 
 static int mdt_ioc_version_get(struct mdt_thread_info *mti, void *karg)
 {
-        struct obd_ioctl_data *data = karg;
-        struct lu_fid *fid = (struct lu_fid *)data->ioc_inlbuf1;
-        __u64 version;
-        struct mdt_object *obj;
-        struct mdt_lock_handle  *lh;
-        int rc;
-        ENTRY;
+       struct obd_ioctl_data *data = karg;
+       struct lu_fid *fid;
+       __u64 version;
+       struct mdt_object *obj;
+       struct mdt_lock_handle  *lh;
+       int rc;
+       ENTRY;
 
-        CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
-        if (!fid_is_sane(fid))
-                RETURN(-EINVAL);
+       if (data->ioc_inlbuf1 == NULL || data->ioc_inllen1 != sizeof(*fid) ||
+           data->ioc_inlbuf2 == NULL || data->ioc_inllen2 != sizeof(version))
+               RETURN(-EINVAL);
+
+       fid = (struct lu_fid *)data->ioc_inlbuf1;
+
+       if (!fid_is_sane(fid))
+               RETURN(-EINVAL);
+
+       CDEBUG(D_IOCTL, "getting version for "DFID"\n", PFID(fid));
 
         lh = &mti->mti_lh[MDT_LH_PARENT];
         mdt_lock_reg_init(lh, LCK_CR);