Whamcloud - gitweb
Type proposals, simplifications.
[fs/lustre-release.git] / lustre / obdfs / namei.c
index 4c074a4..b874135 100644 (file)
@@ -70,7 +70,7 @@ static inline int ext2_match (int len, const char * const name,
  * itself (as a parameter - res_dir). It does NOT read the inode of the
  * entry - you'll have to do that yourself if you want to.
  */
-struct page * obdfs_find_entry (struct inode * dir,
+static struct page * obdfs_find_entry (struct inode * dir,
                                             const char * const name, int namelen,
                                             struct ext2_dir_entry_2 ** res_dir, int lock)
 {
@@ -107,9 +107,9 @@ struct page * obdfs_find_entry (struct inode * dir,
                        /* this code is executed quadratically often */
                        /* do minimal checking `by hand' */
                        int de_len;
-                       CDEBUG(D_INODE, "Entry %p len %d, page at %#lx - %#lx , offset %lx\n",
-                              de, le16_to_cpu(de->rec_len), page_address(page), page_address(page) + 
-                              PAGE_SIZE, offset);
+                       /* CDEBUG(D_INODE, "Entry %p len %d, page at %#lx - %#lx , offset %lx\n",
+                              de, le16_to_cpu(de->rec_len), page_address(page),
+                              page_address(page) + PAGE_SIZE, offset); */
 
                        if ((char *) de + namelen <= dlimit &&
                            ext2_match (namelen, name, de)) {
@@ -125,14 +125,13 @@ struct page * obdfs_find_entry (struct inode * dir,
                        /* prevent looping on a bad block */
                        de_len = le16_to_cpu(de->rec_len);
                        if (de_len <= 0) {
-                               CDEBUG(D_INODE, "Bad entry: at %p len %d\n",
-                                      de, de_len);
+                               printk("Bad entry at %p len %d\n", de, de_len);
                                goto failure;
                        }
                        offset += de_len;
                        de = (struct ext2_dir_entry_2 *)
                                ((char *) de + de_len);
-                       CDEBUG(D_INODE, "Next while %lx\n", offset);
+                       /* CDEBUG(D_INODE, "Next while %lx\n", offset); */
                }
                if ( lock ) 
                        UnlockPage(page);
@@ -294,10 +293,8 @@ static struct page *obdfs_add_entry (struct inode * dir,
                                return NULL;
                }
                CDEBUG(D_INODE, "Testing for enough space at de %p\n", de);
-               if ( (le32_to_cpu(de->inode) == 0 && 
-                     le16_to_cpu(de->rec_len) >= rec_len) ||
-                    (le16_to_cpu(de->rec_len) >= 
-                     EXT2_DIR_REC_LEN(de->name_len) + rec_len)) {
+               if ( (le32_to_cpu(de->inode) == 0 && le16_to_cpu(de->rec_len) >= rec_len) ||
+                    (le16_to_cpu(de->rec_len) >= EXT2_DIR_REC_LEN(de->name_len) + rec_len)) {
                        offset += le16_to_cpu(de->rec_len);
                        CDEBUG(D_INODE, "Found enough space de %p, offset %#lx\n", de, offset);
                        if (le32_to_cpu(de->inode)) {
@@ -409,6 +406,7 @@ static inline void ext2_set_de_type(struct super_block *sb,
 /*
  * Display all dentries holding the specified inode.
  */
+#if 0
 static void show_dentry(struct list_head * dlist, int subdirs)
 {
        struct list_head *tmp = dlist;
@@ -439,6 +437,7 @@ static void show_dentry(struct list_head * dlist, int subdirs)
                               unhashed);
        }
 }
+#endif
 
 
 /*
@@ -455,25 +454,24 @@ int obdfs_create (struct inode * dir, struct dentry * dentry, int mode)
        struct page *page;
        struct ext2_dir_entry_2 * de;
        int err = -EIO;
-       ino_t ino;
+       objid id;
 
         ENTRY;
 
        /*
         * N.B. Several error exits in ext2_new_inode don't set err.
         */
-       ino = iops(dir)->o_create(iid(dir), 0, &err);
+       err = iops(dir)->o_create(iid(dir), 0, &id);
        if ( err ) 
                return err;
-       err = -EIO;
-       inode =  iget(dir->i_sb, ino);
+       inode =  iget(dir->i_sb, (ino_t)id);
        if (!inode || !list_empty(&inode->i_dentry)) {
-               CDEBUG(D_INODE, "No inode, ino %ld\n", ino);
+               CDEBUG(D_INODE, "No inode, ino %ld\n", id);
                EXIT;
-               return err;
+               return -EIO;
        }
 
-       inode->i_op = &obdfs_inode_ops;
+       inode->i_op = &obdfs_file_inode_operations;
        inode->i_mode = mode;
        mark_inode_dirty(inode);
        page = obdfs_add_entry (dir, dentry->d_name.name, dentry->d_name.len, &de, &err);
@@ -506,21 +504,21 @@ int obdfs_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev)
        struct inode * inode;
        struct page *page;
        struct ext2_dir_entry_2 * de;
-       int err = -EIO;
+       int err;
 
-       ino_t ino;
+       objid id;
 
         ENTRY;
 
        /*
         * N.B. Several error exits in ext2_new_inode don't set err.
         */
-       ino = iops(dir)->o_create(iid(dir), 0, &err);
-       if ( ino == -1 ) 
-               return -1;
-       inode =  iget(dir->i_sb, ino);
-       if (!inode)
+       err = iops(dir)->o_create(iid(dir), 0, &id);
+       if ( err ) 
                return err;
+       inode =  iget(dir->i_sb, (ino_t)id);
+       if (!inode)
+               return -EIO;
 
        inode->i_uid = current->fsuid;
        init_special_inode(inode, mode, rdev);
@@ -555,11 +553,11 @@ out_no_entry:
 
 int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
 {
-       struct inode * child;
-       struct page *page, *child_page;
+       struct inode * inode;
+       struct page *page, *inode_page;
        struct ext2_dir_entry_2 * de;
        int err;
-       ino_t ino;
+       objid id;
 
        ENTRY;
 
@@ -567,28 +565,27 @@ int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
        if (dir->i_nlink >= EXT2_LINK_MAX)
                goto out;
 
-       err = -EIO;
-       ino = iops(dir)->o_create(iid(dir), 0, &err);
-       if ( ino == -1 ) 
-               return -1;
-       child =  iget(dir->i_sb, ino);
-       if (!child)
+       err = iops(dir)->o_create(iid(dir), 0, &id);
+       if ( err ) 
                return err;
+       inode =  iget(dir->i_sb, (ino_t)id);
+       if (!inode)
+               return -EIO;
 
 
-       child->i_op = &obdfs_inode_ops;
-       child->i_blocks = 0;    
-       child_page = obdfs_getpage(child, 0, 1, LOCKED);
-       if (!child_page) {
-               child->i_nlink--; /* is this nlink == 0? */
-               mark_inode_dirty(child);
-               iput (child);
+       inode->i_op = &obdfs_dir_inode_operations;
+       inode->i_blocks = 0;    
+       inode_page = obdfs_getpage(inode, 0, 1, LOCKED);
+       if (!inode_page) {
+               inode->i_nlink--; /* is this nlink == 0? */
+               mark_inode_dirty(inode);
+               iput (inode);
                return err;
        }
 
        /* create . and .. */
-       de = (struct ext2_dir_entry_2 *) page_address(child_page);
-       de->inode = cpu_to_le32(child->i_ino);
+       de = (struct ext2_dir_entry_2 *) page_address(inode_page);
+       de->inode = cpu_to_le32(inode->i_ino);
        de->name_len = 1;
        de->rec_len = cpu_to_le16(EXT2_DIR_REC_LEN(de->name_len));
        strcpy (de->name, ".");
@@ -601,17 +598,17 @@ int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
        strcpy (de->name, "..");
        ext2_set_de_type(dir->i_sb, de, S_IFDIR);
        
-       iops(dir)->o_brw(WRITE, iid(dir), child, child_page, 1);
-       child->i_blocks = PAGE_SIZE/child->i_sb->s_blocksize;
-       child->i_size = PAGE_SIZE;
-       UnlockPage(child_page);
-       page_cache_release(child_page);
-
-       child->i_nlink = 2;
-       child->i_mode = S_IFDIR | mode;
+       iops(dir)->o_brw(WRITE, iid(dir), inode, inode_page, 1);
+       inode->i_blocks = PAGE_SIZE/inode->i_sb->s_blocksize;
+       inode->i_size = PAGE_SIZE;
+       UnlockPage(inode_page);
+       page_cache_release(inode_page);
+
+       inode->i_nlink = 2;
+       inode->i_mode = S_IFDIR | mode;
        if (dir->i_mode & S_ISGID)
-               child->i_mode |= S_ISGID;
-       mark_inode_dirty(child);
+               inode->i_mode |= S_ISGID;
+       mark_inode_dirty(inode);
 
        /* now deal with the parent */
        page = obdfs_add_entry(dir, dentry->d_name.name, dentry->d_name.len, &de, &err);
@@ -619,7 +616,7 @@ int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
                goto out_no_entry;
        }
 
-       de->inode = cpu_to_le32(child->i_ino);
+       de->inode = cpu_to_le32(inode->i_ino);
        ext2_set_de_type(dir->i_sb, de, S_IFDIR);
        dir->i_version = ++event;
 
@@ -635,16 +632,16 @@ int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode)
        iops(dir)->o_brw(WRITE, iid(dir), dir, page, 1);
        UnlockPage(page);
        page_cache_release(page);
-       d_instantiate(dentry, child);
+       d_instantiate(dentry, inode);
        err = 0;
 out:
        EXIT;
        return err;
 
 out_no_entry:
-       child->i_nlink = 0;
-       mark_inode_dirty(child);
-       iput (child);
+       inode->i_nlink = 0;
+       mark_inode_dirty(inode);
+       iput (inode);
        EXIT;
        goto out;
 }
@@ -724,7 +721,7 @@ int obdfs_rmdir (struct inode * dir, struct dentry *dentry)
        struct page *page;
        struct ext2_dir_entry_2 * de;
 
-        ENTRY;
+       ENTRY;
 
        retval = -ENOENT;
        page = obdfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &de, LOCKED);
@@ -838,31 +835,29 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna
        char * link;
        int i, l, err = -EIO;
        char c;
-       ino_t ino;
+       objid id;
 
         ENTRY;
        /*
         * N.B. Several error exits in ext2_new_inode don't set err.
         */
-       ino = iops(dir)->o_create(iid(dir), 0, &err);
-       if ( ino == -1 )  {
+       err = iops(dir)->o_create(iid(dir), 0, &id);
+       if ( err )  {
                EXIT;
-               return -1;
+               return err;
        }
-       inode =  iget(dir->i_sb, ino);
+       inode =  iget(dir->i_sb, (ino_t)id);
        if (!inode) {
                EXIT;
                return err;
        }
-
        inode->i_mode = S_IFLNK | S_IRWXUGO;
        inode->i_op = &obdfs_symlink_inode_operations;
        for (l = 0; l < inode->i_sb->s_blocksize - 1 &&
             symname [l]; l++)
                ;
 
-       /* For obdfs we always use normal (not fast) symlinks
-       if (l >= sizeof (inode->u.ext2_i.i_data)) { */
+       if (l >= sizeof (inode->u.ext2_i.i_data)) {
                CDEBUG(D_INODE, "l=%d, normal symlink\n", l);
 
                name_page = obdfs_getpage(inode, 0, 1, LOCKED);
@@ -874,24 +869,22 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna
                        return err;
                }
                link = (char *)page_address(name_page);
-       /* } else {
+       } else {
                link = (char *) inode->u.ext2_i.i_data;
 
                CDEBUG(D_INODE, "l=%d, fast symlink\n", l);
 
-       } */
+       }
        i = 0;
        while (i < inode->i_sb->s_blocksize - 1 && (c = *(symname++)))
                link[i++] = c;
        link[i] = 0;
-
-       /* if (name_page) { */
+       if (name_page) {
                iops(inode)->o_brw(WRITE, iid(inode), inode, name_page, 1);
                PDEBUG(name_page, "symlink");
                UnlockPage(name_page);
                page_cache_release(name_page);
-       /* } */
-
+       }
        inode->i_size = i;
        mark_inode_dirty(inode);