Whamcloud - gitweb
Minor bugfix to allow multiple networked operations:
[fs/lustre-release.git] / lustre / llite / namei.c
index 15bd677..01df8cb 100644 (file)
@@ -38,7 +38,7 @@ extern void ll_change_inode(struct inode *inode);
 extern int ll_setattr(struct dentry *de, struct iattr *attr);
 
 /* from dir.c */
-extern int ext2_add_link (struct dentry *dentry, struct inode *inode);
+extern int ll_add_link (struct dentry *dentry, struct inode *inode);
 ino_t ll_inode_by_name(struct inode * dir, struct dentry *dentry, int *typ);
 int ext2_make_empty(struct inode *inode, struct inode *parent);
 struct ext2_dir_entry_2 * ext2_find_entry (struct inode * dir,
@@ -55,21 +55,18 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
 static inline void ext2_inc_count(struct inode *inode)
 {
        inode->i_nlink++;
-       ll_change_inode(inode);
 }
 
 /* postpone the disk update until the inode really goes away */ 
 static inline void ext2_dec_count(struct inode *inode)
 {
        inode->i_nlink--;
-       if (inode->i_nlink > 0) 
-               ll_change_inode(inode);
 }
 
 static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
 {
        int err;
-       err = ext2_add_link(dentry, inode);
+       err = ll_add_link(dentry, inode);
        if (!err) {
                d_instantiate(dentry, inode);
                return 0;
@@ -83,8 +80,9 @@ static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
 static struct dentry *ll_lookup(struct inode * dir, struct dentry *dentry)
 {
        struct mds_rep *rep; 
-       struct mds_rep_hdr *hdr = NULL; 
+       struct ptlrep_hdr *hdr = NULL; 
        struct inode * inode = NULL;
+        struct ll_sb_info *sbi;
        int err;
        int type;
        ino_t ino;
@@ -97,8 +95,10 @@ static struct dentry *ll_lookup(struct inode * dir, struct dentry *dentry)
        if (!ino)
                goto negative;
 
-       err = mdc_getattr(ino, type, OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 
-                        &rep, &hdr);
+        sbi = (struct ll_sb_info *)(&dir->i_sb->u.generic_sbp);
+
+       err = mdc_getattr(sbi->ll_peer_ptr, ino, type,
+                         OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, &rep, &hdr);
         if ( err ) {
                 printk(__FUNCTION__ ": obdo_fromid failed\n");
                 EXIT;
@@ -133,52 +133,49 @@ static inline int ext2_match (int len, const char * const name,
         return !memcmp(name, de->name, len);
 }
 
-static struct inode *ll_new_inode(struct inode *dir, int mode)
+static struct inode *ll_create_node(struct inode *dir, const char *name, 
+                                   int namelen, int mode, __u64 id)
 {
-        struct obdo *oa;
         struct inode *inode;
+       struct mds_rep *rep;
+       struct ptlrep_hdr *hdr;
         int err;
+        struct ll_sb_info *sbi =
+               (struct ll_sb_info *)(&dir->i_sb->u.generic_sbp);
 
         ENTRY;
 
-        oa = obdo_alloc();
-        if (!oa) {
+       err = mdc_create(sbi->ll_peer_ptr, dir, name, namelen, mode, id,
+                        current->uid, current->gid, CURRENT_TIME, 
+                        &rep, &hdr); 
+       if (err) { 
                 EXIT;
-                return ERR_PTR(-ENOMEM);
-        }
-
-        /* Send a hint to the create method on the type of file to create */
-        oa->o_mode = mode;
-        oa->o_valid |= OBD_MD_FLMODE;
-       CDEBUG(D_INODE, "\n");
-        err = obd_create(IID(dir), oa);
-       CDEBUG(D_INODE, "\n");
-
-        if ( err ) {
-                printk("new_inode - fatal: err %d\n", err);
-                obdo_free(oa);
-                EXIT;
-                return ERR_PTR(err);
-        }
-       CDEBUG(D_INODE, "obdo mode %o\n", oa->o_mode);
-
-        inode = iget4(dir->i_sb, (ino_t)oa->o_id, NULL, oa);
-       CDEBUG(D_INODE, "\n");
-        obdo_free(oa);
-
-        if (!inode) {
-                printk("new_inode -fatal:  %ld\n", (long)oa->o_id);
-                obd_destroy(IID(dir), oa);
+               return ERR_PTR(err);
+       }
+       if ( hdr->status) {
+               EXIT;
+               return ERR_PTR(hdr->status);
+       }
+       rep->valid = OBD_MD_FLNOTOBD;
+
+       rep->objid = id; 
+       rep->nlink = 1;
+       rep->mode = mode;
+       printk("-- new_inode: objid %lld, ino %d, mode %o\n", 
+              rep->objid, rep->ino, rep->mode); 
+
+        inode = iget4(dir->i_sb, rep->ino, NULL, rep);
+        if (IS_ERR(inode)) {
+                printk(__FUNCTION__ ": new_inode -fatal:  %ld\n", 
+                      PTR_ERR(inode));
                 EXIT;
                 return ERR_PTR(-EIO);
         }
 
         if (!list_empty(&inode->i_dentry)) {
-                printk("new_inode -fatal: aliases %ld, ct %d lnk %d\n", 
-                      (long)oa->o_id,
-                      atomic_read(&inode->i_count), 
+                printk("new_inode -fatal: aliases %d, ct %d lnk %d\n", 
+                      rep->ino, atomic_read(&inode->i_count), 
                       inode->i_nlink);
-                obd_destroy(IID(dir), oa);
                 iput(inode);
                 EXIT;
                 return ERR_PTR(-EIO);
@@ -199,25 +196,41 @@ static struct inode *ll_new_inode(struct inode *dir, int mode)
  */
 static int ll_create (struct inode * dir, struct dentry * dentry, int mode)
 {
-       struct inode * inode = ll_new_inode (dir, mode);
-       int err = PTR_ERR(inode);
+       int err; 
+       struct obdo oa;
+       struct inode * inode;
+
+       err = obd_create(IID(dir), &oa);  
+       if (err) { 
+               EXIT; 
+               return err;
+       }
+
+       mode = mode | S_IFREG;
+       printk("ll_create: name %s mode %o\n", dentry->d_name.name, mode);
+       inode = ll_create_node(dir, dentry->d_name.name, 
+                              dentry->d_name.len, 
+                              mode, oa.o_id);
+       err = PTR_ERR(inode);
        if (!IS_ERR(inode)) {
+               // XXX clean up the object
                inode->i_op = &ll_file_inode_operations;
                inode->i_fop = &ll_file_operations;
                inode->i_mapping->a_ops = &ll_aops;
                err = ext2_add_nondir(dentry, inode);
        }
+       EXIT;
        return err;
 } /* ll_create */
 
 
 static int ll_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev)
 {
-       struct inode * inode = ll_new_inode (dir, mode);
+       struct inode * inode = ll_create_node(dir, dentry->d_name.name, 
+                                             dentry->d_name.len, mode, 0);
        int err = PTR_ERR(inode);
        if (!IS_ERR(inode)) {
                init_special_inode(inode, mode, rdev);
-               ll_change_inode(inode);
                err = ext2_add_nondir(dentry, inode);
        }
        return err;
@@ -235,7 +248,9 @@ static int ll_symlink (struct inode * dir, struct dentry * dentry,
        if (l > sb->s_blocksize)
                goto out;
 
-       inode = ll_new_inode (dir, S_IFLNK | S_IRWXUGO);
+       inode = ll_create_node(dir, dentry->d_name.name, 
+                              dentry->d_name.len, 
+                              S_IFLNK | S_IRWXUGO, 0);
        err = PTR_ERR(inode);
        if (IS_ERR(inode))
                goto out;
@@ -254,7 +269,6 @@ static int ll_symlink (struct inode * dir, struct dentry * dentry,
                memcpy(oinfo->lli_inline, symname, l);
                inode->i_size = l-1;
        }
-       ll_change_inode(inode);
 
        err = ext2_add_nondir(dentry, inode);
 out:
@@ -298,7 +312,9 @@ static int ll_mkdir(struct inode * dir, struct dentry * dentry, int mode)
 
        ext2_inc_count(dir);
 
-       inode = ll_new_inode (dir, S_IFDIR | mode);
+       inode = ll_create_node (dir, dentry->d_name.name, 
+                               dentry->d_name.len,
+                               S_IFDIR | mode, 0);
        err = PTR_ERR(inode);
        if (IS_ERR(inode))
                goto out_dir;
@@ -313,7 +329,7 @@ static int ll_mkdir(struct inode * dir, struct dentry * dentry, int mode)
        if (err)
                goto out_fail;
 
-       err = ext2_add_link(dentry, inode);
+       err = ll_add_link(dentry, inode);
        if (err)
                goto out_fail;
 
@@ -419,7 +435,7 @@ static int ll_rename (struct inode * old_dir, struct dentry * old_dentry,
                                goto out_dir;
                }
                ext2_inc_count(old_inode);
-               err = ext2_add_link(new_dentry, old_inode);
+               err = ll_add_link(new_dentry, old_inode);
                if (err) {
                        ext2_dec_count(old_inode);
                        goto out_dir;