Whamcloud - gitweb
r=adilger,phil
[fs/lustre-release.git] / lustre / mds / mds_open.c
index 457bbcf..e959402 100644 (file)
@@ -28,6 +28,7 @@
 #endif
 #define DEBUG_SUBSYSTEM S_MDS
 
+#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/version.h>
@@ -54,7 +55,7 @@
  * mds_mfd_close - for force closing files when a client dies
  */
 
-/* 
+/*
  * MDS file data handling: file data holds a handle for a file opened
  * by a client.
  */
@@ -132,7 +133,7 @@ static void mds_free_filterdata(struct inode *inode)
         iput(inode);
 }
 
-/* Write access to a file: executors cause a negative count, 
+/* Write access to a file: executors cause a negative count,
  * writers a positive count.  The semaphore is needed to perform
  * a check for the sign and then increment or decrement atomically.
  *
@@ -243,7 +244,7 @@ static struct mds_file_data *mds_dentry_open(struct dentry *dentry,
         struct mds_body *body;
         int error;
         ENTRY;
-        
+
         mfd = mds_mfd_new();
         if (mfd == NULL) {
                 CERROR("mds: out of memory\n");
@@ -339,7 +340,8 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset,
         }
 
         /* replay case */
-        if (rec->ur_fid2->id) {
+        if(lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
+                LASSERT (rec->ur_fid2->id);
                 body->valid |= OBD_MD_FLBLKSZ | OBD_MD_FLEASIZE;
                 lmm_size = rec->ur_eadatalen;
                 lmm = rec->ur_eadata;
@@ -358,6 +360,10 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset,
                 RETURN(0);
         }
 
+        
+        if (OBD_FAIL_CHECK_ONCE(OBD_FAIL_MDS_ALLOC_OBDO))
+                GOTO(out_ids, rc = -ENOMEM);
+
         oa = obdo_alloc();
         if (oa == NULL)
                 GOTO(out_ids, rc = -ENOMEM);
@@ -373,28 +379,38 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset,
         obdo_from_inode(oa, inode, OBD_MD_FLTYPE|OBD_MD_FLATIME|OBD_MD_FLMTIME|
                         OBD_MD_FLCTIME);
 
-        /* check if things like lstripe/lfs stripe are sending us the ea */
-        if (rec->ur_flags & MDS_OPEN_HAS_EA) {
-                rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, mds->mds_osc_exp,
+        if (!(rec->ur_flags & MDS_OPEN_HAS_OBJS)) {
+                /* check if things like lstripe/lfs stripe are sending us the ea */
+                if (rec->ur_flags & MDS_OPEN_HAS_EA) {
+                        rc = obd_iocontrol(OBD_IOC_LOV_SETSTRIPE, 
+                                           mds->mds_osc_exp,
+                                           0, &lsm, rec->ur_eadata);
+                        if (rc)
+                                GOTO(out_oa, rc);
+                }
+                rc = obd_create(mds->mds_osc_exp, oa, &lsm, &oti);
+                if (rc) {
+                        int level = D_ERROR;
+                        if (rc == -ENOSPC)
+                                level = D_INODE;
+                        CDEBUG(level, "error creating objects for "
+                                      "inode %lu: rc = %d\n",
+                               inode->i_ino, rc);
+                        if (rc > 0) {
+                                CERROR("obd_create returned invalid "
+                                       "rc %d\n", rc);
+                                rc = -EIO;
+                        }
+                        GOTO(out_oa, rc);
+                }
+        } else {
+                rc = obd_iocontrol(OBD_IOC_LOV_SETEA, mds->mds_osc_exp,
                                    0, &lsm, rec->ur_eadata);
-                if (rc)
+                if (rc) {
                         GOTO(out_oa, rc);
-        }
-
-        rc = obd_create(mds->mds_osc_exp, oa, &lsm, &oti);
-        if (rc) {
-                int level = D_ERROR;
-                if (rc == -ENOSPC)
-                        level = D_INODE;
-                CDEBUG(level, "error creating objects for inode %lu: rc = %d\n",
-                       inode->i_ino, rc);
-                if (rc > 0) {
-                        CERROR("obd_create returned invalid rc %d\n", rc);
-                        rc = -EIO;
                 }
-                GOTO(out_oa, rc);
+                lsm->lsm_object_id = oa->o_id;
         }
-
         if (inode->i_size) {
                 oa->o_size = inode->i_size;
                 obdo_from_inode(oa, inode, OBD_MD_FLTYPE|OBD_MD_FLATIME|
@@ -445,7 +461,6 @@ static void reconstruct_open(struct mds_update_record *rec, int offset,
                              struct ptlrpc_request *req,
                              struct lustre_handle *child_lockh)
 {
-        struct ptlrpc_request *oldreq = req->rq_export->exp_outstanding_reply;
         struct mds_export_data *med = &req->rq_export->exp_mds_data;
         struct mds_client_data *mcd = med->med_mcd;
         struct mds_obd *mds = mds_req2mds(req);
@@ -543,10 +558,11 @@ static void reconstruct_open(struct mds_update_record *rec, int offset,
                 mfd = NULL;
         }
 
-        if (oldreq != NULL) {
-                /* if we're not recovering, it had better be found */
-                LASSERT(mfd != NULL);
-        } else if (mfd == NULL) {
+#warning "XXX fixme"
+        /* Here it used to LASSERT(mfd) if exp_outstanding_reply != NULL.
+         * Now that exp_outstanding_reply is a list, it's just using mfd != NULL
+         * to detect a re-open */
+        if (mfd == NULL) {
                 mntget(mds->mds_vfsmnt);
                 CERROR("Re-opened file \n");
                 mfd = mds_dentry_open(child, mds->mds_vfsmnt,
@@ -730,16 +746,16 @@ int mds_lock_new_child(struct obd_device *obd, struct inode *inode,
         if (child_lockh == NULL)
                 child_lockh = &lockh;
 
-        rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, NULL,
-                              child_res_id, LDLM_PLAIN, NULL, 0,
-                              LCK_EX, &lock_flags, ldlm_completion_ast,
-                              mds_blocking_ast, NULL, child_lockh);
+        rc = ldlm_cli_enqueue(NULL, NULL, obd->obd_namespace, child_res_id,
+                              LDLM_PLAIN, NULL, LCK_EX, &lock_flags,
+                              mds_blocking_ast, ldlm_completion_ast, NULL, NULL,
+                              NULL, 0, NULL, child_lockh);
         if (rc != ELDLM_OK)
                 CERROR("ldlm_cli_enqueue: %d\n", rc);
         else if (child_lockh == &lockh)
                 ldlm_lock_decref(child_lockh, LCK_EX);
 
-        return rc;
+        RETURN(rc);
 }
 
 int mds_open(struct mds_update_record *rec, int offset,
@@ -774,15 +790,23 @@ int mds_open(struct mds_update_record *rec, int offset,
         /* Step 0: If we are passed a fid, then we assume the client already
          * opened this file and is only replaying the RPC, so we open the
          * inode by fid (at some large expense in security). */
-        if (rec->ur_fid2->id) {
+        if (lustre_msg_get_flags(req->rq_reqmsg) & MSG_REPLAY) {
+                DEBUG_REQ(D_HA, req, "open replay, disp: "LPX64"\n", 
+                          rep->lock_policy_res1);
+
+                LASSERT(rec->ur_fid2->id);
+                
                 rc = mds_open_by_fid(req, rec->ur_fid2, body, rec->ur_flags,
                                      rec, rep);
-                if (rc != -ENOENT)
+                if (rc != -ENOENT) 
                         RETURN(rc);
                 /* We didn't find the correct inode on disk either, so we
                  * need to re-create it via a regular replay. */
                 LASSERT(rec->ur_flags & MDS_OPEN_CREAT);
+        } else {
+                LASSERT(!rec->ur_fid2->id);
         }
+
         LASSERT(offset == 2); /* If we got here, we must be called via intent */
 
         med = &req->rq_export->exp_mds_data;
@@ -928,6 +952,16 @@ int mds_open(struct mds_update_record *rec, int offset,
         if ((rec->ur_flags & MDS_OPEN_DIRECTORY) &&
             !S_ISDIR(dchild->d_inode->i_mode))
                 GOTO(cleanup, rc = -ENOTDIR);
+        if (S_ISDIR(dchild->d_inode->i_mode)) { 
+                if (rec->ur_flags & MDS_OPEN_CREAT || rec->ur_flags & FMODE_WRITE) {
+                        /*we are tryying to create or write a exist dir*/
+                        GOTO(cleanup, rc = -EISDIR);
+                }
+                if (ll_permission(dchild->d_inode, acc_mode, NULL)) {
+                        GOTO(cleanup, rc = -EACCES);
+                }
+        }
 
         /* Step 5: mds_open it */
         rc = mds_finish_open(req, dchild, body, rec->ur_flags, &handle, rec,
@@ -959,7 +993,7 @@ int mds_open(struct mds_update_record *rec, int offset,
                 if (rc)
                         ldlm_lock_decref(&parent_lockh, parent_mode);
                 else
-                        ldlm_put_lock_into_req(req, &parent_lockh, parent_mode);
+                        ptlrpc_save_lock (req, &parent_lockh, parent_mode);
         }
         if (rc == 0)
                 atomic_inc(&mds->mds_open_count);
@@ -985,7 +1019,7 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd,
         struct mds_obd *mds = &obd->u.mds;
         struct inode *pending_dir = mds->mds_pending_dir->d_inode;
         void *handle = NULL;
-        struct mds_body *request_body = NULL, *reply_body;
+        struct mds_body *request_body = NULL, *reply_body = NULL;
         struct dentry_params dp;
         ENTRY;
 
@@ -1012,7 +1046,7 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd,
         if (last_orphan && unlink_orphan) {
                 LASSERT(rc == 0); /* mds_put_write_access must have succeeded */
 
-                CWARN("destroying orphan object %s\n", fidname);
+                CDEBUG(D_HA, "destroying orphan object %s\n", fidname);
 
                 /* Sadly, there is no easy way to save pending_child from
                  * mds_reint_unlink() into mfd, so we need to re-lookup,
@@ -1035,14 +1069,16 @@ int mds_mfd_close(struct ptlrpc_request *req, struct obd_device *obd,
                         GOTO(cleanup, rc);
                 }
 
-#ifdef ENABLE_ORPHANS
                 if (req != NULL &&
                     (reply_body->valid & OBD_MD_FLEASIZE) &&
                     mds_log_op_unlink(obd, pending_child->d_inode,
-                                      req->rq_repmsg, 1) > 0) {
+                                lustre_msg_buf(req->rq_repmsg, 1, 0),
+                                req->rq_repmsg->buflens[1],
+                                lustre_msg_buf(req->rq_repmsg, 2, 0),
+                                req->rq_repmsg->buflens[2]) > 0) {
                         reply_body->valid |= OBD_MD_FLCOOKIE;
                 }
-#endif
+
                 pending_child->d_fsdata = (void *) &dp;
                 dp.p_inum = 0;
                 dp.p_ptr = req;