Whamcloud - gitweb
- Added DEBUG_SUBSYSTEMs
[fs/lustre-release.git] / lustre / llite / namei.c
index 9dc1050..39f5809 100644 (file)
@@ -29,6 +29,9 @@
 #include <linux/fs.h>
 #include <linux/locks.h>
 #include <linux/quotaops.h>
+
+#define DEBUG_SUBSYSTEM S_LLIGHT
+
 #include <linux/obd_support.h>
 #include <linux/lustre_light.h>
 extern struct address_space_operations ll_aops;
@@ -38,7 +41,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 +58,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;
@@ -82,8 +82,11 @@ static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
 /* methods */
 static struct dentry *ll_lookup(struct inode * dir, struct dentry *dentry)
 {
-        struct obdo *oa;
+       struct mds_rep *rep; 
+       struct ptlrep_hdr *hdr = NULL; 
        struct inode * inode = NULL;
+        struct ll_sb_info *sbi = ll_i2sbi(dir);
+       int err;
        int type;
        ino_t ino;
        
@@ -95,16 +98,18 @@ static struct dentry *ll_lookup(struct inode * dir, struct dentry *dentry)
        if (!ino)
                goto negative;
 
-        oa = obdo_fromid(IID(dir), ino, type, 
-                        OBD_MD_FLNOTOBD | OBD_MD_FLBLOCKS);
-        if ( IS_ERR(oa) ) {
+       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;
                 return ERR_PTR(-EACCES); 
         }
 
-       inode = iget4(dir->i_sb, ino, NULL, oa);
-        obdo_free(oa);
+       inode = iget4(dir->i_sb, ino, NULL, rep);
+
+        /* FIXME: this is not the right way to get this size */
+        OBD_FREE(hdr, sizeof(struct ptlrep_hdr) + sizeof(struct mds_rep));
 
        if (!inode) 
                return ERR_PTR(-EACCES);
@@ -131,56 +136,51 @@ 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, const char *tgt, int tgtlen, 
+                                   int mode, __u64 id)
 {
-        struct obdo *oa;
         struct inode *inode;
+       struct mds_rep *rep;
+       struct ptlrep_hdr *hdr;
         int err;
+       time_t time = CURRENT_TIME;
+        struct ll_sb_info *sbi = ll_i2sbi(dir);
 
         ENTRY;
-        if (IOPS(dir, create) == NULL) {
-                printk(KERN_ERR __FUNCTION__ ": no create method!\n");
-                EXIT;
-                return ERR_PTR(-EIO);
-        }
-        oa = obdo_alloc();
-        if (!oa) {
-                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 = IOPS(dir, create)(IID(dir), oa);
-       CDEBUG(D_INODE, "\n");
 
-        if ( err ) {
-                printk("new_inode - fatal: err %d\n", err);
-                obdo_free(oa);
+       err = mdc_create(sbi->ll_peer_ptr, dir, name, namelen, tgt, tgtlen,
+                        mode, id, 
+                        current->uid, current->gid, time, &rep, &hdr); 
+       if (err) { 
                 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);
-                IOPS(dir, 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->atime = rep->ctime = rep->mtime = time;
+       rep->mode = mode;
+        CDEBUG(D_INODE, "-- 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);
-                IOPS(dir, destroy)(IID(dir), oa);
                 iput(inode);
                 EXIT;
                 return ERR_PTR(-EIO);
@@ -190,6 +190,82 @@ static struct inode *ll_new_inode(struct inode *dir, int mode)
         return inode;
 } /* ll_new_inode */
 
+int ll_mdc_unlink(struct inode *dir, const char *name, int len)
+{
+       struct mds_rep *rep;
+       struct ptlrep_hdr *hdr;
+        int err;
+        struct ll_sb_info *sbi = ll_i2sbi(dir);
+
+        ENTRY;
+
+       err = mdc_unlink(sbi->ll_peer_ptr, dir, name, len, &rep, &hdr); 
+
+       if (err) { 
+                EXIT;
+               return err;
+       }
+       if ( hdr->status) {
+               EXIT;
+               return hdr->status;
+       }
+
+        EXIT;
+       return 0;
+}
+
+int ll_mdc_link(struct dentry *src, struct inode *dir, 
+               const char *name, int len)
+{
+       struct mds_rep *rep;
+       struct ptlrep_hdr *hdr;
+        int err;
+        struct ll_sb_info *sbi = ll_i2sbi(dir);
+
+        ENTRY;
+
+       err = mdc_link(sbi->ll_peer_ptr, src, dir, name, len, &rep, &hdr); 
+
+       if (err) { 
+                EXIT;
+               return err;
+       }
+       if ( hdr->status) {
+               EXIT;
+               return hdr->status;
+       }
+
+        EXIT;
+       return 0;
+}
+
+int ll_mdc_rename(struct inode *src, struct inode *tgt, 
+                 struct dentry *old, struct dentry *new)
+{
+       struct mds_rep *rep;
+       struct ptlrep_hdr *hdr;
+        int err;
+        struct ll_sb_info *sbi = ll_i2sbi(src);
+
+        ENTRY;
+
+       err = mdc_rename(sbi->ll_peer_ptr, src, tgt, 
+                        old->d_name.name, old->d_name.len, 
+                        new->d_name.name, new->d_name.len, 
+                        &rep, &hdr); 
+
+       if (err) { 
+                EXIT;
+               return err;
+       }
+       if ( hdr->status) {
+               EXIT;
+               return hdr->status;
+       }
+
+        EXIT;
+       return 0;
+}
 
 /*
  * By the time this is called, we already have created
@@ -201,25 +277,42 @@ 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;
+        CDEBUG(D_DENTRY, "name %s mode %o\n", dentry->d_name.name, mode);
+       inode = ll_create_node(dir, dentry->d_name.name, dentry->d_name.len, 
+                              NULL, 0,
+                              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, NULL, 0,
+                                             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;
@@ -228,51 +321,40 @@ static int ll_mknod (struct inode * dir, struct dentry *dentry, int mode, int rd
 static int ll_symlink (struct inode * dir, struct dentry * dentry,
        const char * symname)
 {
-       struct super_block * sb = dir->i_sb;
        int err = -ENAMETOOLONG;
-       unsigned l = strlen(symname)+1;
+       unsigned l = strlen(symname);
        struct inode * inode;
         struct ll_inode_info *oinfo;
 
-       if (l > sb->s_blocksize)
-               goto out;
+       if (l > LL_INLINESZ)
+               return err;
 
-       inode = ll_new_inode (dir, S_IFLNK | S_IRWXUGO);
+       inode = ll_create_node(dir, dentry->d_name.name, 
+                              dentry->d_name.len, symname, l,
+                              S_IFLNK | S_IRWXUGO, 0);
        err = PTR_ERR(inode);
        if (IS_ERR(inode))
-               goto out;
+               return err;
 
         oinfo = ll_i2info(inode);
-        if (l >= sizeof(oinfo->lli_inline)) {
-               /* slow symlink */
-               inode->i_op = &page_symlink_inode_operations;
-               inode->i_mapping->a_ops = &ll_aops;
-               err = block_symlink(inode, symname, l);
-               if (err)
-                       goto out_fail;
-       } else {
-               /* fast symlink */
-               inode->i_op = &ll_fast_symlink_inode_operations;
-               memcpy(oinfo->lli_inline, symname, l);
-               inode->i_size = l-1;
-       }
-       ll_change_inode(inode);
+       
+       inode->i_op = &ll_fast_symlink_inode_operations;
+       memcpy(oinfo->lli_inline, symname, l);
+       inode->i_size = l-1;
 
        err = ext2_add_nondir(dentry, inode);
-out:
-       return err;
 
-out_fail:
-       ext2_dec_count(inode);
-       iput (inode);
-       goto out;
+       if (err) { 
+               ext2_dec_count(inode);
+               iput (inode);
+       }
+       return err;
 }
 
-
-
 static int ll_link (struct dentry * old_dentry, struct inode * dir,
        struct dentry *dentry)
 {
+       int err;
        struct inode *inode = old_dentry->d_inode;
 
        if (S_ISDIR(inode->i_mode))
@@ -281,6 +363,13 @@ static int ll_link (struct dentry * old_dentry, struct inode * dir,
        if (inode->i_nlink >= EXT2_LINK_MAX)
                return -EMLINK;
 
+       err = ll_mdc_link(old_dentry, dir, 
+                         dentry->d_name.name, dentry->d_name.len);
+       if (err) { 
+               EXIT;
+               return err;
+       }
+
        inode->i_ctime = CURRENT_TIME;
        ext2_inc_count(inode);
        atomic_inc(&inode->i_count);
@@ -300,7 +389,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, NULL, 0, 
+                               S_IFDIR | mode, 0);
        err = PTR_ERR(inode);
        if (IS_ERR(inode))
                goto out_dir;
@@ -308,14 +399,14 @@ static int ll_mkdir(struct inode * dir, struct dentry * dentry, int mode)
        inode->i_op = &ll_dir_inode_operations;
        inode->i_fop = &ll_dir_operations;
        inode->i_mapping->a_ops = &ll_aops;
-
+       inode->i_nlink = 1;
        ext2_inc_count(inode);
 
        err = ext2_make_empty(inode, dir);
        if (err)
                goto out_fail;
 
-       err = ext2_add_link(dentry, inode);
+       err = ll_add_link(dentry, inode);
        if (err)
                goto out_fail;
 
@@ -345,6 +436,11 @@ static int ll_unlink(struct inode * dir, struct dentry *dentry)
        de = ext2_find_entry (dir, dentry, &page);
        if (!de)
                goto out;
+       
+       err = ll_mdc_unlink(dir, dentry->d_name.name, dentry->d_name.len);
+       if (err) 
+               goto out;
+
 
        err = ext2_delete_entry (de, page);
        if (err)
@@ -385,6 +481,10 @@ static int ll_rename (struct inode * old_dir, struct dentry * old_dentry,
        struct ext2_dir_entry_2 * old_de;
        int err = -ENOENT;
 
+       err = ll_mdc_rename(old_dir, new_dir, old_dentry, new_dentry); 
+       if (err) 
+               goto out;
+
        old_de = ext2_find_entry (old_dir, old_dentry, &old_page);
        if (!old_de)
                goto out;
@@ -421,7 +521,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;