Whamcloud - gitweb
- Added DEBUG_SUBSYSTEMs
[fs/lustre-release.git] / lustre / llite / namei.c
index f0e55c6..39f5809 100644 (file)
@@ -1,5 +1,4 @@
 /*
- *  linux/fs/obdfs/namei.c
  *
  * This code is issued under the GNU General Public License.
  * See the file COPYING in this distribution
 #include <linux/fs.h>
 #include <linux/locks.h>
 #include <linux/quotaops.h>
+
+#define DEBUG_SUBSYSTEM S_LLIGHT
+
 #include <linux/obd_support.h>
-#include <linux/obdfs.h>
-extern struct address_space_operations obdfs_aops;
+#include <linux/lustre_light.h>
+extern struct address_space_operations ll_aops;
 
 /* from super.c */
-extern void obdfs_change_inode(struct inode *inode);
-extern int obdfs_setattr(struct dentry *de, struct iattr *attr);
+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);
-ino_t obdfs_inode_by_name(struct inode * dir, struct dentry *dentry, int *typ);
+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,
                   struct dentry *dentry, struct page ** res_page);
@@ -56,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++;
-       obdfs_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) 
-               obdfs_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;
@@ -81,10 +80,13 @@ static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
 }
 
 /* methods */
-static struct dentry *obdfs_lookup(struct inode * dir, struct dentry *dentry)
+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;
        
@@ -92,20 +94,22 @@ static struct dentry *obdfs_lookup(struct inode * dir, struct dentry *dentry)
        if (dentry->d_name.len > EXT2_NAME_LEN)
                return ERR_PTR(-ENAMETOOLONG);
 
-       ino = obdfs_inode_by_name(dir, dentry, &type);
+       ino = ll_inode_by_name(dir, dentry, &type);
        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);
@@ -132,56 +136,51 @@ static inline int ext2_match (int len, const char * const name,
         return !memcmp(name, de->name, len);
 }
 
-static struct inode *obdfs_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);
@@ -189,8 +188,84 @@ static struct inode *obdfs_new_inode(struct inode *dir, int mode)
 
         EXIT;
         return inode;
-} /* obdfs_new_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
@@ -200,80 +275,86 @@ static struct inode *obdfs_new_inode(struct inode *dir, int mode)
  * If the create succeeds, we fill in the inode information
  * with d_instantiate(). 
  */
-static int obdfs_create (struct inode * dir, struct dentry * dentry, int mode)
+static int ll_create (struct inode * dir, struct dentry * dentry, int mode)
 {
-       struct inode * inode = obdfs_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)) {
-               inode->i_op = &obdfs_file_inode_operations;
-               inode->i_fop = &obdfs_file_operations;
-               inode->i_mapping->a_ops = &obdfs_aops;
+               // 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;
-} /* obdfs_create */
+} /* ll_create */
 
 
-static int obdfs_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev)
+static int ll_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev)
 {
-       struct inode * inode = obdfs_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);
-               obdfs_change_inode(inode);
                err = ext2_add_nondir(dentry, inode);
        }
        return err;
 }
 
-static int obdfs_symlink (struct inode * dir, struct dentry * dentry,
+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 obdfs_inode_info *oinfo;
+        struct ll_inode_info *oinfo;
 
-       if (l > sb->s_blocksize)
-               goto out;
+       if (l > LL_INLINESZ)
+               return err;
 
-       inode = obdfs_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 = obdfs_i2info(inode);
-        if (l >= sizeof(oinfo->oi_inline)) {
-               /* slow symlink */
-               inode->i_op = &page_symlink_inode_operations;
-               inode->i_mapping->a_ops = &obdfs_aops;
-               err = block_symlink(inode, symname, l);
-               if (err)
-                       goto out_fail;
-       } else {
-               /* fast symlink */
-               inode->i_op = &obdfs_fast_symlink_inode_operations;
-               memcpy(oinfo->oi_inline, symname, l);
-               inode->i_size = l-1;
-       }
-       obdfs_change_inode(inode);
+        oinfo = ll_i2info(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 obdfs_link (struct dentry * old_dentry, struct inode * dir,
+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))
@@ -282,6 +363,13 @@ static int obdfs_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);
@@ -290,7 +378,7 @@ static int obdfs_link (struct dentry * old_dentry, struct inode * dir,
 }
 
 
-static int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
+static int ll_mkdir(struct inode * dir, struct dentry * dentry, int mode)
 {
        struct inode * inode;
        int err = -EMLINK;
@@ -301,22 +389,24 @@ static int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
 
        ext2_inc_count(dir);
 
-       inode = obdfs_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;
 
-       inode->i_op = &obdfs_dir_inode_operations;
-       inode->i_fop = &obdfs_dir_operations;
-       inode->i_mapping->a_ops = &obdfs_aops;
-
+       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;
 
@@ -336,7 +426,7 @@ out_dir:
        goto out;
 }
 
-static int obdfs_unlink(struct inode * dir, struct dentry *dentry)
+static int ll_unlink(struct inode * dir, struct dentry *dentry)
 {
        struct inode * inode = dentry->d_inode;
        struct ext2_dir_entry_2 * de;
@@ -346,6 +436,11 @@ static int obdfs_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)
@@ -359,13 +454,13 @@ out:
 }
 
 
-static int obdfs_rmdir (struct inode * dir, struct dentry *dentry)
+static int ll_rmdir (struct inode * dir, struct dentry *dentry)
 {
        struct inode * inode = dentry->d_inode;
        int err = -ENOTEMPTY;
 
        if (ext2_empty_dir(inode)) {
-               err = obdfs_unlink(dir, dentry);
+               err = ll_unlink(dir, dentry);
                if (!err) {
                        inode->i_size = 0;
                        ext2_dec_count(inode);
@@ -375,7 +470,7 @@ static int obdfs_rmdir (struct inode * dir, struct dentry *dentry)
        return err;
 }
 
-static int obdfs_rename (struct inode * old_dir, struct dentry * old_dentry,
+static int ll_rename (struct inode * old_dir, struct dentry * old_dentry,
        struct inode * new_dir, struct dentry * new_dentry )
 {
        struct inode * old_inode = old_dentry->d_inode;
@@ -386,6 +481,10 @@ static int obdfs_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;
@@ -422,7 +521,7 @@ static int obdfs_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;
@@ -453,15 +552,15 @@ out:
        return err;
 }
 
-struct inode_operations obdfs_dir_inode_operations = {
-       create:         obdfs_create,
-       lookup:         obdfs_lookup,
-       link:           obdfs_link,
-       unlink:         obdfs_unlink,
-       symlink:        obdfs_symlink,
-       mkdir:          obdfs_mkdir,
-       rmdir:          obdfs_rmdir,
-       mknod:          obdfs_mknod,
-       rename:         obdfs_rename,
-       setattr:        obdfs_setattr
+struct inode_operations ll_dir_inode_operations = {
+       create:         ll_create,
+       lookup:         ll_lookup,
+       link:           ll_link,
+       unlink:         ll_unlink,
+       symlink:        ll_symlink,
+       mkdir:          ll_mkdir,
+       rmdir:          ll_rmdir,
+       mknod:          ll_mknod,
+       rename:         ll_rename,
+       setattr:        ll_setattr
 };