Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
index e294986..8eb065d 100644 (file)
@@ -188,7 +188,7 @@ static int mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,
         CDEBUG(D_NET, "mode: %o\n", body->mode);
 
         offset = REPLY_REC_OFF + 1;
-        LASSERT_REPSWAB(req, offset);
+        lustre_set_rep_swabbed(req, offset);
         if (body->eadatasize != 0) {
                 /* reply indicates presence of eadata; check it's there... */
                 eadata = lustre_msg_buf(req->rq_repmsg, offset++,
@@ -499,35 +499,51 @@ int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
 
         md->body = lustre_msg_buf(req->rq_repmsg, offset, sizeof (*md->body));
         LASSERT (md->body != NULL);
-        LASSERT_REPSWABBED(req, offset);
+        LASSERT(lustre_rep_swabbed(req, offset));
         offset++;
 
         if (md->body->valid & OBD_MD_FLEASIZE) {
                 int lmmsize;
                 struct lov_mds_md *lmm;
 
-                LASSERT(S_ISREG(md->body->mode));
+                if (!S_ISREG(md->body->mode)) {
+                        CERROR("OBD_MD_FLEASIZE set, should be a regular file, "
+                               "but is not\n");
+                        GOTO(out, rc = -EPROTO);
+                }
 
                 if (md->body->eadatasize == 0) {
                         CERROR("OBD_MD_FLEASIZE set, but eadatasize 0\n");
-                        RETURN(-EPROTO);
+                        GOTO(out, rc = -EPROTO);
                 }
                 lmmsize = md->body->eadatasize;
                 lmm = lustre_msg_buf(req->rq_repmsg, offset, lmmsize);
-                LASSERT (lmm != NULL);
-                LASSERT_REPSWABBED(req, offset);
+                if (!lmm) {
+                        CERROR ("incorrect message: lmm == 0\n");
+                        GOTO(out, rc = -EPROTO);
+                }
+                LASSERT(lustre_rep_swabbed(req, offset));
 
                 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
                 if (rc < 0)
-                        RETURN(rc);
+                        GOTO(out, rc);
+
+                if (rc < sizeof(*md->lsm)) {
+                        CERROR ("lsm size too small:  rc < sizeof (*md->lsm) "
+                                "(%d < %d)\n", rc, sizeof(*md->lsm));
+                        GOTO(out, rc = -EPROTO);
+                }
 
-                LASSERT (rc >= sizeof (*md->lsm));
                 offset++;
         } else if (md->body->valid & OBD_MD_FLDIREA) {
                 int lmvsize;
                 struct lov_mds_md *lmv;
-                
-                LASSERT(S_ISDIR(md->body->mode));
+
+                if(!S_ISDIR(md->body->mode)) {
+                        CERROR("OBD_MD_FLDIREA set, should be a directory, but "
+                               "is not\n");
+                        GOTO(out, rc = -EPROTO);
+                }
 
                 if (md->body->eadatasize == 0) {
                         CERROR("OBD_MD_FLDIREA is set, but eadatasize 0\n");
@@ -536,15 +552,23 @@ int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
                 if (md->body->valid & OBD_MD_MEA) {
                         lmvsize = md->body->eadatasize;
                         lmv = lustre_msg_buf(req->rq_repmsg, offset, lmvsize);
-                        LASSERT (lmv != NULL);
-                        LASSERT_REPSWABBED(req, offset);
+                        if (!lmv) {
+                                CERROR ("incorrect message: lmv == 0\n");
+                                GOTO(out, rc = -EPROTO);
+                        }
+
+                        LASSERT(lustre_rep_swabbed(req, offset));
 
                         rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
                                           lmvsize);
                         if (rc < 0)
-                                RETURN(rc);
+                                GOTO(out, rc);
 
-                        LASSERT (rc >= sizeof (*md->mea));
+                        if (rc < sizeof(*md->mea)) {
+                                CERROR ("size too small:  rc < sizeof(*md->mea) "
+                                        "(%d < %d)\n", rc, sizeof(*md->mea));
+                                GOTO(out, rc = -EPROTO);
+                        }
                 }
                 offset++;
         }
@@ -554,7 +578,10 @@ int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
         if (md->body->valid & OBD_MD_FLRMTPERM) {
                 md->remote_perm = lustre_msg_buf(req->rq_repmsg, offset++,
                                                 sizeof(struct mdt_remote_perm));
-                LASSERT(md->remote_perm);
+                if (!md->remote_perm) {
+                        CERROR ("incorrect message: remote_perm == 0\n");
+                        GOTO(out, rc = -EPROTO);
+                }
         }
 
         /* for ACL, it's possible that FLACL is set but aclsize is zero.  only
@@ -692,15 +719,13 @@ void mdc_commit_delayed(struct ptlrpc_request *req)
         list_del_init(&req->rq_mod_list);
         if (req->rq_sequence) {
                 list_for_each_entry_safe(cur, tmp, &mod->mod_replay_list,
-                                         rq_mod_list)
-                {
+                                         rq_mod_list) {
                         LASSERT(cur != LP_POISON);
                         LASSERT(cur->rq_type != LI_POISON);
                         DEBUG_REQ(D_HA, cur, "req balanced");
                         LASSERT(cur->rq_transno != 0);
                         LASSERT(cur->rq_import == req->rq_import);
 
-                        list_del_init(&cur->rq_mod_list);
                         /* We no longer want to preserve this for transno-
                          * unconditional replay. */
                         spin_lock(&cur->rq_lock);
@@ -734,7 +759,7 @@ int mdc_set_open_replay_data(struct obd_export *exp,
         LASSERT(rec != NULL);
 
         /* Incoming message in my byte order (it's been swabbed). */
-        LASSERT_REPSWABBED(open_req, DLM_REPLY_REC_OFF);
+        LASSERT(lustre_rep_swabbed(open_req, DLM_REPLY_REC_OFF));
 
         /* Outgoing messages always in my byte order. */
         LASSERT(body != NULL);
@@ -774,7 +799,7 @@ int mdc_set_open_replay_data(struct obd_export *exp,
                 LBUG();
         }
 
-        DEBUG_REQ(D_HA, open_req, "Set up open replay data");
+        DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
         RETURN(0);
 }
 
@@ -844,7 +869,7 @@ int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
 
         if (req->rq_repmsg == NULL) {
-                CDEBUG(D_HA, "request failed to send: %p, %d\n", req,
+                CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
                        req->rq_status);
                 if (rc == 0)
                         rc = req->rq_status ? req->rq_status : -EIO;
@@ -1029,14 +1054,10 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
         int rc;
         ENTRY;
 
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-        MOD_INC_USE_COUNT;
-#else
         if (!try_module_get(THIS_MODULE)) {
                 CERROR("Can't get module. Is it alive?");
                 return -EINVAL;
         }
-#endif
         switch (cmd) {
         case OBD_IOC_CLIENT_RECOVER:
                 rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1);
@@ -1069,11 +1090,7 @@ static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
                 GOTO(out, rc = -ENOTTY);
         }
 out:
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-        MOD_DEC_USE_COUNT;
-#else
         module_put(THIS_MODULE);
-#endif
 
         return rc;
 }