X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fobdfs%2Fnamei.c;h=b874135f45318c3865c47185ef76d38b1db1f9a1;hb=86ada49822948e9cf3a8488b3297f111bcaef72e;hp=6bb405afdab8220fc46ea382cd5129c5a5a784d1;hpb=17eaf7c18899a5fc9027b57d84240cbd2349a6db;p=fs%2Flustre-release.git diff --git a/lustre/obdfs/namei.c b/lustre/obdfs/namei.c index 6bb405a..b874135 100644 --- a/lustre/obdfs/namei.c +++ b/lustre/obdfs/namei.c @@ -1,5 +1,5 @@ /* - * linux/fs/ext2/namei.c + * linux/fs/obdfs/namei.c * * Copyright (C) 1992, 1993, 1994, 1995 * Remy Card (card@masi.ibp.fr) @@ -8,7 +8,7 @@ * * from * - * linux/fs/minix/namei.c + * linux/fs/ext2/namei.c * * Copyright (C) 1991, 1992 Linus Torvalds * @@ -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) { @@ -86,7 +86,7 @@ struct page * obdfs_find_entry (struct inode * dir, if (namelen > EXT2_NAME_LEN) return NULL; - CDEBUG(D_INODE, "dirsize is %ld\n", dir->i_size); + CDEBUG(D_INODE, "dirsize is %Ld\n", dir->i_size); page = 0; offset = 0; @@ -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; @@ -418,9 +416,9 @@ static void show_dentry(struct list_head * dlist, int subdirs) const char * unhashed = ""; if ( subdirs ) - dentry = list_entry(tmp, struct dentry, d_child); - else - dentry = list_entry(tmp, struct dentry, d_alias); + dentry = list_entry(tmp, struct dentry, d_child); + else + dentry = list_entry(tmp, struct dentry, d_alias); if (list_empty(&dentry->d_hash)) unhashed = "(unhashed)"; @@ -439,6 +437,7 @@ static void show_dentry(struct list_head * dlist, int subdirs) unhashed); } } +#endif /* @@ -455,27 +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; - struct obdfs_sb_info *sbi; - ino_t ino; + objid id; ENTRY; - sbi = dir->i_sb->u.generic_sbp; /* * N.B. Several error exits in ext2_new_inode don't set err. */ - ino = sbi->osi_ops->o_create(sbi->osi_conn_info.conn_id, 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); @@ -489,8 +485,7 @@ int obdfs_create (struct inode * dir, struct dentry * dentry, int mode) de->inode = cpu_to_le32(inode->i_ino); ext2_set_de_type(dir->i_sb, de, S_IFREG); dir->i_version = ++event; - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - dir, page, 0); + iops(dir)->o_brw(WRITE, iid(dir), dir, page, 0); UnlockPage(page); #if 0 if (IS_SYNC(dir)) { @@ -509,23 +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; - struct obdfs_sb_info *sbi; + int err; - ino_t ino; + objid id; ENTRY; - sbi = dir->i_sb->u.generic_sbp; /* * N.B. Several error exits in ext2_new_inode don't set err. */ - ino = sbi->osi_ops->o_create(sbi->osi_conn_info.conn_id, 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); @@ -536,8 +529,7 @@ int obdfs_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev) dir->i_version = ++event; ext2_set_de_type(dir->i_sb, de, inode->i_mode); mark_inode_dirty(inode); - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - dir, page, 0); + iops(dir)->o_brw(WRITE, iid(dir), dir, page, 0); UnlockPage(page); #if 0 @@ -561,44 +553,39 @@ 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; - struct obdfs_sb_info *sbi; int err; - ino_t ino; + objid id; ENTRY; - sbi = dir->i_sb->u.generic_sbp; err = -EMLINK; if (dir->i_nlink >= EXT2_LINK_MAX) goto out; - err = -EIO; - ino = iops(dir)->o_create(sbi->osi_conn_info.conn_id, 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_size = PAGE_SIZE; - 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; } - child->i_blocks = PAGE_SIZE/child->i_sb->s_blocksize; /* 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, "."); @@ -611,15 +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, sbi->osi_conn_info.conn_id, child, child_page, 1); - 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); @@ -627,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; @@ -640,19 +629,19 @@ int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode) dir->i_nlink++; dir->u.ext2_i.i_flags &= ~EXT2_BTREE_FL; mark_inode_dirty(dir); - iops(dir)->o_brw(WRITE, sbi->osi_conn_info.conn_id, dir, page, 1); + 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; } @@ -731,10 +720,8 @@ int obdfs_rmdir (struct inode * dir, struct dentry *dentry) struct inode * inode; struct page *page; struct ext2_dir_entry_2 * de; - struct obdfs_sb_info *sbi; - ENTRY; - sbi = dir->i_sb->u.generic_sbp; + ENTRY; retval = -ENOENT; page = obdfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &de, LOCKED); @@ -756,7 +743,7 @@ int obdfs_rmdir (struct inode * dir, struct dentry *dentry) dir->i_version = ++event; if (retval) goto end_rmdir; - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, dir, page, 0); + iops(dir)->o_brw(WRITE, iid(dir), dir, page, 0); UnlockPage(page); #if 0 if (IS_SYNC(dir)) { @@ -791,10 +778,8 @@ int obdfs_unlink(struct inode * dir, struct dentry *dentry) struct inode * inode; struct page *page; struct ext2_dir_entry_2 * de; - struct obdfs_sb_info *sbi; ENTRY; - sbi = dir->i_sb->u.generic_sbp; retval = -ENOENT; page = obdfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &de, LOCKED); @@ -818,7 +803,7 @@ int obdfs_unlink(struct inode * dir, struct dentry *dentry) if (retval) goto end_unlink; dir->i_version = ++event; - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, dir, page, 0); + iops(dir)->o_brw(WRITE, iid(dir), dir, page, 0); UnlockPage(page); #if 0 if (IS_SYNC(dir)) { @@ -850,29 +835,29 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna char * link; int i, l, err = -EIO; char c; - struct obdfs_sb_info *sbi; - ino_t ino; + objid id; ENTRY; - - sbi = dir->i_sb->u.generic_sbp; /* * N.B. Several error exits in ext2_new_inode don't set err. */ - ino = sbi->osi_ops->o_create(sbi->osi_conn_info.conn_id, 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 ) { + EXIT; return err; - + } + inode = iget(dir->i_sb, (ino_t)id); + if (!inode) { + EXIT; + return err; + } inode->i_mode = S_IFLNK | S_IRWXUGO; - inode->i_op = &obdfs_inode_ops; + inode->i_op = &obdfs_symlink_inode_operations; for (l = 0; l < inode->i_sb->s_blocksize - 1 && symname [l]; l++) ; - 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); @@ -880,6 +865,7 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna inode->i_nlink--; mark_inode_dirty(inode); iput (inode); + EXIT; return err; } link = (char *)page_address(name_page); @@ -894,8 +880,7 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna link[i++] = c; link[i] = 0; if (name_page) { - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - inode, name_page, 1); + iops(inode)->o_brw(WRITE, iid(inode), inode, name_page, 1); PDEBUG(name_page, "symlink"); UnlockPage(name_page); page_cache_release(name_page); @@ -909,8 +894,7 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna de->inode = cpu_to_le32(inode->i_ino); ext2_set_de_type(dir->i_sb, de, S_IFLNK); dir->i_version = ++event; - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - dir, page, 1); + iops(dir)->o_brw(WRITE, iid(dir), dir, page, 1); UnlockPage(page); #if 0 if (IS_SYNC(dir)) { @@ -921,6 +905,7 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna d_instantiate(dentry, inode); err = 0; out: + EXIT; return err; out_no_entry: @@ -937,10 +922,8 @@ int obdfs_link (struct dentry * old_dentry, struct ext2_dir_entry_2 * de; struct page *page; int err; - struct obdfs_sb_info *sbi; ENTRY; - sbi = dir->i_sb->u.generic_sbp; if (S_ISDIR(inode->i_mode)) return -EPERM; @@ -955,8 +938,7 @@ int obdfs_link (struct dentry * old_dentry, de->inode = cpu_to_le32(inode->i_ino); ext2_set_de_type(dir->i_sb, de, inode->i_mode); dir->i_version = ++event; - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - dir, page, 0); + iops(dir)->o_brw(WRITE, iid(dir), dir, page, 0); UnlockPage(page); #if 0 @@ -989,10 +971,8 @@ int obdfs_rename (struct inode * old_dir, struct dentry *old_dentry, struct page * old_page, * new_page, * dir_page; struct ext2_dir_entry_2 * old_de, * new_de; int retval; - struct obdfs_sb_info *sbi; ENTRY; - sbi = old_dir->i_sb->u.generic_sbp; new_page = dir_page = NULL; @@ -1076,8 +1056,7 @@ int obdfs_rename (struct inode * old_dir, struct dentry *old_dentry, mark_inode_dirty(old_dir); if (dir_page) { PARENT_INO(page_address(dir_page)) = le32_to_cpu(new_dir->i_ino); - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - old_inode, dir_page, 0); + iops(old_inode)->o_brw(WRITE, iid(old_inode), old_inode, dir_page, 0); old_dir->i_nlink--; mark_inode_dirty(old_dir); if (new_inode) { @@ -1090,14 +1069,13 @@ int obdfs_rename (struct inode * old_dir, struct dentry *old_dentry, } } if ( old_page != new_page ) { - unsigned long offset = old_page->offset; + unsigned long index = old_page->index; /* lock the old_page and release unlocked copy */ CDEBUG(D_INODE, "old_page at %p\n", old_page); page_cache_release(old_page); - old_page = obdfs_getpage(old_dir, offset, 0, LOCKED); + old_page = obdfs_getpage(old_dir, index >> PAGE_SHIFT, 0, LOCKED); CDEBUG(D_INODE, "old_page at %p\n", old_page); - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - old_dir, old_page, 0); + iops(old_dir)->o_brw(WRITE, iid(old_dir), old_dir, old_page,0); } #if 0 if (IS_SYNC(old_dir)) { @@ -1105,8 +1083,7 @@ int obdfs_rename (struct inode * old_dir, struct dentry *old_dentry, wait_on_buffer (old_bh); } #endif - sbi->osi_ops->o_brw(WRITE, sbi->osi_conn_info.conn_id, - new_dir, new_page, 0); + iops(new_dir)->o_brw(WRITE, iid(new_dir), new_dir, new_page, 0); #if 0 if (IS_SYNC(new_dir)) { ll_rw_block (WRITE, 1, &new_bh);