Whamcloud - gitweb
check readonly file system asap: in mdt_req_handle() & in mdt_intent_opc()
authorhuanghua <huanghua>
Tue, 18 Jul 2006 08:04:29 +0000 (08:04 +0000)
committerhuanghua <huanghua>
Tue, 18 Jul 2006 08:04:29 +0000 (08:04 +0000)
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_open.c
lustre/mdt/mdt_reint.c
lustre/mdt/mdt_xattr.c

index 0295be7..55509a9 100644 (file)
@@ -93,7 +93,12 @@ enum mdt_handler_flags {
          * this request has fixed reply format, so that reply message can be
          * packed by generic code.
          */
-        HABEO_REFERO = (1 << 2)
+        HABEO_REFERO = (1 << 2),
+        /*
+         * this request will modify something, so check whether the filesystem
+         * is readonly or not, then return -EROFS to client asap if necessary.
+         */
+        HABEO_MUTABOR = (1 << 3)
 };
 
 struct mdt_opc_slice {
@@ -1030,6 +1035,11 @@ static int mdt_req_handle(struct mdt_thread_info *info,
                 result = mdt_unpack_req_pack_rep(info, flags);
         }
 
+        
+        if (result == 0 && flags & HABEO_MUTABOR) {
+                if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
+                        result = -EROFS; 
+        }
         if (result == 0 && flags & HABEO_CLAVIS) {
                 struct ldlm_request *dlm_req;
 
@@ -1081,7 +1091,6 @@ static int mdt_req_handle(struct mdt_thread_info *info,
                 /* FIXME: fake untill journal callback is OK.*/
                 mdt_update_last_transno(info, result);
         }
-        req_capsule_fini(&info->mti_pill);
         RETURN(result);
 }
 
@@ -1100,32 +1109,32 @@ void mdt_lock_handle_fini(struct mdt_lock_handle *lh)
 static void mdt_thread_info_init(struct ptlrpc_request *req,
                                  struct mdt_thread_info *info)
 {
+        memset(info, 0, sizeof *info);
+/*
         int i;
-
         memset(&info->mti_rr, 0, sizeof info->mti_rr);
         memset(&info->mti_attr, 0, sizeof info->mti_attr);
 
-        info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
         for (i = 0; i < ARRAY_SIZE(info->mti_rep_buf_size); i++)
                 info->mti_rep_buf_size[i] = 0;
         info->mti_rep_buf_nr = i;
         for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
                 mdt_lock_handle_init(&info->mti_lh[i]);
+*/
 
+        info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
         info->mti_ctxt = req->rq_svc_thread->t_ctx;
         /* it can be NULL while CONNECT */
         if (req->rq_export)
                 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
         req_capsule_init(&info->mti_pill, req, RCL_SERVER, info->mti_rep_buf_size);
-
-        /* other members of "struct mdt_thread_info" should be initialized
-         * by users before they can be used. */
 }
 
 static void mdt_thread_info_fini(struct mdt_thread_info *info)
 {
         int i;
 
+        req_capsule_fini(&info->mti_pill);
         if (info->mti_object != NULL) {
                 mdt_object_put(info->mti_ctxt, info->mti_object);
                 info->mti_object = NULL;
@@ -1435,13 +1444,13 @@ static struct mdt_it_flavor {
         },
         [MDT_IT_OCREAT]   = {
                 .it_fmt   = &RQF_LDLM_INTENT,
-                .it_flags = 0,
+                .it_flags = HABEO_MUTABOR,
                 .it_act   = mdt_intent_reint,
                 .it_reint = REINT_OPEN
         },
         [MDT_IT_CREATE]   = {
                 .it_fmt   = &RQF_LDLM_INTENT,
-                .it_flags = 0,
+                .it_flags = HABEO_MUTABOR,
                 .it_act   = mdt_intent_reint,
                 .it_reint = REINT_CREATE
         },
@@ -1462,13 +1471,13 @@ static struct mdt_it_flavor {
         },
         [MDT_IT_UNLINK]   = {
                 .it_fmt   = &RQF_LDLM_INTENT_UNLINK,
-                .it_flags = 0,
+                .it_flags = HABEO_MUTABOR,
                 .it_act   = NULL, /* XXX can be mdt_intent_reint, ? */
                 .it_reint = REINT_UNLINK
         },
         [MDT_IT_TRUNC]    = {
                 .it_fmt   = NULL,
-                .it_flags = 0,
+                .it_flags = HABEO_MUTABOR,
                 .it_act   = NULL
         },
         [MDT_IT_GETXATTR] = {
@@ -1675,13 +1684,16 @@ static int mdt_intent_opc(long itopc, struct mdt_thread_info *info,
 
         rc = mdt_unpack_req_pack_rep(info, flv->it_flags);
         if (rc == 0) {
-                /* execute policy */
-                /*XXX LASSERT( flv->it_act) */
-                if (flv->it_act) {
-                        rc = flv->it_act(opc, info, lockp, flags);
-                } else
-                        rc = -EOPNOTSUPP;
+                struct ptlrpc_request *req = mdt_info_req(info);
+                if (flv->it_flags & HABEO_MUTABOR &&
+                    req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
+                        rc = -EROFS;
         }
+        if (rc == 0 && flv->it_act != NULL) {
+                /* execute policy */
+                rc = flv->it_act(opc, info, lockp, flags);
+        } else
+                rc = -EOPNOTSUPP;
         RETURN(rc);
 }
 
@@ -2754,11 +2766,13 @@ DEF_MDT_HNDL_F(0,                         DISCONNECT,   mdt_disconnect),
 DEF_MDT_HNDL_F(0           |HABEO_REFERO, GETSTATUS,    mdt_getstatus),
 DEF_MDT_HNDL_F(HABEO_CORPUS,              GETATTR,      mdt_getattr),
 DEF_MDT_HNDL_F(HABEO_CORPUS,              GETATTR_NAME, mdt_getattr_name),
-DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, SETXATTR,     mdt_setxattr),
+DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO|HABEO_MUTABOR, 
+                                          SETXATTR,     mdt_setxattr),
 DEF_MDT_HNDL_F(HABEO_CORPUS,              GETXATTR,     mdt_getxattr),
 DEF_MDT_HNDL_F(0           |HABEO_REFERO, STATFS,       mdt_statfs),
 DEF_MDT_HNDL_F(HABEO_CORPUS,              READPAGE,     mdt_readpage),
-DEF_MDT_HNDL_F(0,                         REINT,        mdt_reint),
+DEF_MDT_HNDL_F(0                        |HABEO_MUTABOR,
+                                          REINT,        mdt_reint),
 DEF_MDT_HNDL_F(HABEO_CORPUS|HABEO_REFERO, CLOSE,        mdt_close),
 DEF_MDT_HNDL_0(0,                         DONE_WRITING, mdt_done_writing),
 DEF_MDT_HNDL_F(0           |HABEO_REFERO, PIN,          mdt_pin),
index 3ad3494..ed4f35e 100644 (file)
@@ -229,7 +229,6 @@ int mdt_reint_open(struct mdt_thread_info *info)
         struct mdt_object      *child;
         struct mdt_lock_handle *lh;
         struct ldlm_reply      *ldlm_rep;
-        struct ptlrpc_request  *req = mdt_info_req(info);
         struct lu_fid          *child_fid = &info->mti_tmp_fid1;
         int                     result;
         int                     created = 0;
@@ -269,8 +268,6 @@ int mdt_reint_open(struct mdt_thread_info *info)
                 intent_set_disposition(ldlm_rep, DISP_LOOKUP_NEG);
                 if (!(info->mti_attr.la_flags & MDS_OPEN_CREAT))
                         GOTO(out_parent, result);
-                if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                        GOTO(out_parent, result = -EROFS);
                 *child_fid = *info->mti_rr.rr_fid2;
         } else {
                 intent_set_disposition(ldlm_rep, DISP_LOOKUP_POS);
index 14a61ad..0c4a94a 100644 (file)
@@ -166,9 +166,6 @@ static int mdt_reint_setattr(struct mdt_thread_info *info)
         if (lu_object_exists(info->mti_ctxt, &mo->mot_obj.mo_lu) <= 0)
                 GOTO(out_unlock, rc = -ENOENT);
 
-        if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                GOTO(out_unlock, rc = -EROFS);
-
         rc = mo_attr_set(info->mti_ctxt, next, attr);
         if (rc != 0)
                 GOTO(out_unlock, rc);
@@ -264,9 +261,6 @@ static int mdt_reint_unlink(struct mdt_thread_info *info)
                 RETURN(PTR_ERR(mp));
 
         if (strlen(rr->rr_name) == 0) {
-                if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                        GOTO(out_unlock_parent, rc = -EROFS);
-
                 /* remote partial operation */
                 rc = mo_ref_del(info->mti_ctxt, mdt_object_child(mp));
                 GOTO(out_unlock_parent, rc);
@@ -287,9 +281,7 @@ static int mdt_reint_unlink(struct mdt_thread_info *info)
         if (IS_ERR(mc))
                 GOTO(out_unlock_parent, rc = PTR_ERR(mc));
 
-        /*step 3:  do some checking*/
-        if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                GOTO(out_unlock_child, rc = -EROFS);
+        /*step 3:  do some checking ...*/
 
         /* step 4: delete it */
         /* cmm will take care if child is local or remote */
@@ -333,9 +325,6 @@ static int mdt_reint_link(struct mdt_thread_info *info)
                 RETURN(PTR_ERR(ms));
 
         if (strlen(rr->rr_name) == 0) {
-                if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                        GOTO(out_unlock_source, rc = -EROFS);
-
                 /* remote partial operation */
                 rc = mo_ref_add(info->mti_ctxt, mdt_object_child(ms));
                 GOTO(out_unlock_source, rc);
@@ -347,9 +336,6 @@ static int mdt_reint_link(struct mdt_thread_info *info)
         if (IS_ERR(mp))
                 GOTO(out_unlock_source, rc = PTR_ERR(mp));
 
-        if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                GOTO(out_unlock_target, rc = -EROFS);
-
         /* step 4: link it */
         rc = mdo_link(info->mti_ctxt, mdt_object_child(mp),
                       mdt_object_child(ms), rr->rr_name);
@@ -395,9 +381,6 @@ static int mdt_reint_rename_tgt(struct mdt_thread_info *info)
         if (rc != 0 && rc != -ENOENT)
                 GOTO(out_unlock_tgtdir, rc);
 
-        if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                GOTO(out_unlock_tgt, rc = -EROFS);
-
         if (rc == 0) {
                 lh_tgt->mlh_mode = LCK_EX;
 
@@ -506,9 +489,7 @@ static int mdt_reint_rename(struct mdt_thread_info *info)
                         GOTO(out_unlock_old, rc = PTR_ERR(mnew));
         }
 
-        /* step 5: dome some checking*/
-        if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                GOTO(out_unlock_new, rc = -EROFS);
+        /* step 5: dome some checking ...*/
 
         /* step 6: rename it */
         rc = mdo_rename(info->mti_ctxt, mdt_object_child(msrcdir),
index 1ac9459..11e13db 100644 (file)
@@ -199,9 +199,6 @@ int mdt_setxattr(struct mdt_thread_info *info)
         if (rc != 0)
                 GOTO(out, rc);
 
-        if (req->rq_export->exp_connect_flags & OBD_CONNECT_RDONLY)
-                GOTO(out_unlock, rc = -EROFS);
-
         if ((valid & OBD_MD_FLXATTR) == OBD_MD_FLXATTR) {
                 char * xattr;
                 if (!req_capsule_field_present(&info->mti_pill, &RMF_EADATA)) {