Whamcloud - gitweb
A mostly-fix for "mknod /mnt/lustre/foofo p". It doesn't fail outright
[fs/lustre-release.git] / lustre / llite / namei.c
index ab9108f..39214e4 100644 (file)
@@ -98,23 +98,24 @@ int ll_lock(struct inode *dir, struct dentry *dentry,
             struct lookup_intent *it, struct lustre_handle *lockh)
 {
         struct ll_sb_info *sbi = ll_i2sbi(dir);
-        int err;
+        int err, lock_mode;
 
         if ((it->it_op & (IT_CREAT | IT_MKDIR | IT_SYMLINK | IT_SETATTR |
-                          IT_MKNOD)) )
-                err = mdc_enqueue(&sbi->ll_mdc_conn, LDLM_MDSINTENT,
-                                  it, LCK_PW, dir, dentry, lockh, 0, NULL, 0,
-                                  dir, sizeof(*dir));
+                          IT_MKNOD)))
+                lock_mode = LCK_PW;
         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_UNLINK |
                               IT_RMDIR | IT_RENAME | IT_RENAME2))
-                err = mdc_enqueue(&sbi->ll_mdc_conn, LDLM_MDSINTENT,
-                                  it, LCK_PR, dir, dentry, lockh, 0, NULL, 0,
-                                  dir, sizeof(*dir));
+                lock_mode = LCK_PR;
+        else if (it->it_op & IT_LOOKUP)
+                lock_mode = LCK_CR;
         else {
                 LBUG();
                 RETURN(-1);
         }
 
+        err = mdc_enqueue(&sbi->ll_mdc_conn, LDLM_MDSINTENT, it, lock_mode, dir,
+                          dentry, lockh, 0, NULL, 0, dir, sizeof(*dir));
+
         RETURN(err);
 }
 
@@ -136,13 +137,14 @@ static struct dentry *ll_lookup2(struct inode * dir, struct dentry *dentry,
         struct ll_inode_md md;
         struct lustre_handle lockh;
         int err, type, offset;
+        struct lookup_intent lookup_it = { IT_LOOKUP };
         obd_id ino;
 
         ENTRY;
 
         if (it == NULL) {
-                LBUG();
-                RETURN(NULL);
+                it = &lookup_it;
+                dentry->d_it = it;
         }
 
         CDEBUG(D_INFO, "name: %*s, intent op: %d\n", dentry->d_name.len,
@@ -153,30 +155,22 @@ static struct dentry *ll_lookup2(struct inode * dir, struct dentry *dentry,
 
         err = ll_lock(dir, dentry, it, &lockh);
         if (err < 0) {
-                /* FIXME: Mike handle EINTR here */
+                /* FIXME: Mike LBUG() can disappear the moment that 
+                 *   ll_lock has sane interrupt behavior 
+                 */
                 LBUG();
                 RETURN(ERR_PTR(err));
         }
         memcpy(it->it_lock_handle, &lockh, sizeof(lockh));
 
         if ((it->it_op & (IT_CREAT | IT_MKDIR | IT_SYMLINK | IT_MKNOD)) &&
-            it->it_disposition && !it->it_status) {
-#if 0
-                if (it->it_data)
-                        CERROR("leaking request %p\n", it->it_data);
-#endif
+            it->it_disposition && !it->it_status)
                 GOTO(negative, NULL);
-        }
 
-        if ((it->it_op & (IT_RENAME | IT_GETATTR | IT_UNLINK | IT_RMDIR)) &&
-            it->it_disposition && it->it_status) {
-#if 0
-                if (it->it_data)
-                        CERROR("request: %p, status: %d\n", it->it_data,
-                               it->it_status);
-#endif
+        if ((it->it_op & (IT_RENAME | IT_GETATTR | IT_UNLINK | IT_RMDIR |
+                          IT_SETATTR | IT_LOOKUP)) && 
+            it->it_disposition && it->it_status)
                 GOTO(negative, NULL);
-        }
 
         request = (struct ptlrpc_request *)it->it_data;
         if (!it->it_disposition) {
@@ -184,6 +178,7 @@ static struct dentry *ll_lookup2(struct inode * dir, struct dentry *dentry,
                 memcpy(&lli->lli_intent_lock_handle, &lockh, sizeof(lockh));
 
                 ino = ll_inode_by_name(dir, dentry, &type);
+#warning FIXME: handle negative inode case (see old ll_lookup)
 
                 err = mdc_getattr(&sbi->ll_mdc_conn, ino, type,
                                   OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
@@ -193,71 +188,47 @@ static struct dentry *ll_lookup2(struct inode * dir, struct dentry *dentry,
                         RETURN(ERR_PTR(-abs(err)));
                 }
                 offset = 0;
-        } else if (it->it_op == IT_UNLINK) {
-                struct obdo *obdo;
-                obdo = lustre_msg_buf(request->rq_repmsg, 1);
-                inode = new_inode(dir->i_sb);
-
-                ll_i2info(inode)->lli_obdo = obdo_alloc();
-                /* XXX fix mem allocation error */
-                memcpy(ll_i2info(inode)->lli_obdo, obdo, sizeof(*obdo));
-
-                if (!inode)
-                        GOTO(out_req, -ENOMEM);
-                inode->i_mode = S_IFREG;
-                inode->i_nlink = 1;
-                GOTO(out_req, 0);
-        } else if (it->it_op == IT_RMDIR) {
-                inode = new_inode(dir->i_sb);
-                if (!inode)
-                        GOTO(out_req, -ENOMEM);
-                ll_i2info(inode)->lli_obdo = NULL;
-                inode->i_mode = S_IFDIR;
-                inode->i_nlink = 1;
-                GOTO(out_req, 0);
-        } else if (it->it_op != IT_RENAME2) {
-                struct mds_body *body;
-
+        } else if (it->it_op == IT_RENAME2) {
+                inode = ((struct dentry *)(it->it_data))->d_inode;
+                GOTO(out_req, NULL); 
+        } else {
                 offset = 1;
-                body = lustre_msg_buf(request->rq_repmsg, 1);
-                type = body->mode;
-                ino = body->fid1.id;
         }
 
-        if (S_ISREG(type)) {
-                if (request->rq_repmsg->bufcount < offset + 2 ||
-                    request->rq_repmsg->buflens[offset + 1] !=
-                    sizeof(struct obdo))
+        md.body = lustre_msg_buf(request->rq_repmsg, offset);
+        if (S_ISREG(md.body->mode)) {
+                if (request->rq_repmsg->bufcount < offset + 1)
                         LBUG();
-
-                md.obdo = lustre_msg_buf(request->rq_repmsg, offset + 1);
+                md.md = lustre_msg_buf(request->rq_repmsg, offset + 1);
         } else
-                md.obdo = NULL;
-
-        if (!(it->it_op & IT_RENAME2))
-                md.body = lustre_msg_buf(request->rq_repmsg, offset);
+                md.md = NULL;
 
+        /* No rpc's happen during iget4, -ENOMEM's are possible */
         inode = iget4(dir->i_sb, ino, ll_find_inode, &md);
-
         if (it->it_op & IT_RENAME)
                 it->it_data = dentry;
 
  out_req:
         ptlrpc_free_req(request);
-        if (!inode)
+        if (!inode || IS_ERR(inode)) { 
+                ll_intent_release(dentry); 
                 RETURN(ERR_PTR(-ENOMEM));
-
+        }
         EXIT;
  negative:
         dentry->d_op = &ll_d_ops;
         d_add(dentry, inode);
+        if (it->it_op == IT_LOOKUP)
+                ll_intent_release(dentry);
+
         return NULL;
 }
 
 static struct inode *ll_create_node(struct inode *dir, const char *name,
                                     int namelen, const char *tgt, int tgtlen,
                                     int mode, __u64 extra,
-                                    struct lookup_intent *it, struct obdo *obdo)
+                                    struct lookup_intent *it,
+                                    struct lov_stripe_md *smd)
 {
         struct inode *inode;
         struct ptlrpc_request *request = NULL;
@@ -279,17 +250,17 @@ static struct inode *ll_create_node(struct inode *dir, const char *name,
         if (!it->it_disposition) {
                 rc = mdc_create(&sbi->ll_mdc_conn, dir, name, namelen, tgt,
                                  tgtlen, mode, current->fsuid,
-                                 gid, time, extra, obdo, &request);
+                                 gid, time, extra, smd, &request);
                 if (rc) {
                         inode = ERR_PTR(rc);
                         GOTO(out, rc);
                 }
                 body = lustre_msg_buf(request->rq_repmsg, 0);
-                md.obdo = obdo;
+                md.md = smd;
         } else {
                 request = it->it_data;
                 body = lustre_msg_buf(request->rq_repmsg, 1);
-                md.obdo = NULL;
+                md.md = NULL;
         }
 
         body->valid = OBD_MD_FLNOTOBD;
@@ -389,21 +360,22 @@ static int ll_create(struct inode * dir, struct dentry * dentry, int mode)
         int err, rc = 0;
         struct obdo oa;
         struct inode *inode;
+        struct lov_stripe_md *smd;
+        struct ll_inode_info *ii;
 
         if (dentry->d_it->it_disposition == 0) {
                 memset(&oa, 0, sizeof(oa));
                 oa.o_valid = OBD_MD_FLMODE;
                 oa.o_mode = S_IFREG | 0600;
-                rc = obd_create(ll_i2obdconn(dir), &oa);
+                rc = obd_create(ll_i2obdconn(dir), &oa, &smd);
                 if (rc)
                         RETURN(rc);
         }
 
-        mode = mode | S_IFREG;
         CDEBUG(D_DENTRY, "name %s mode %o o_id %lld\n",
                dentry->d_name.name, mode, (unsigned long long)oa.o_id);
         inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len,
-                               NULL, 0, mode, 0, dentry->d_it, &oa);
+                               NULL, 0, mode, 0, dentry->d_it, smd);
 
         if (IS_ERR(inode)) {
                 rc = PTR_ERR(inode);
@@ -428,7 +400,8 @@ static int ll_create(struct inode * dir, struct dentry * dentry, int mode)
         RETURN(rc);
 
 out_destroy:
-        err = obd_destroy(ll_i2obdconn(dir), &oa);
+        oa.o_easize = ii->lli_smd->lmd_size;
+        err = obd_destroy(ll_i2obdconn(dir), &oa, ii->lli_smd);
         if (err)
                 CERROR("error destroying object %Ld in error path: err = %d\n",
                        (unsigned long long)oa.o_id, err);
@@ -440,7 +413,7 @@ static int ll_mknod(struct inode *dir, struct dentry *dentry, int mode,
 {
         struct inode * inode = ll_create_node(dir, dentry->d_name.name,
                                               dentry->d_name.len, NULL, 0,
-                                              mode, rdev, NULL, NULL);
+                                              mode, rdev, dentry->d_it, NULL);
         int err = PTR_ERR(inode);
         if (!IS_ERR(inode))
                 err = ext2_add_nondir(dentry, inode);