Skip to content

Commit 1a54ef8

Browse files
balajirraochrismason-xx
authored andcommitted
Introduce btrfs_iget helper
Date: Mon, 21 Jul 2008 02:01:04 +0530 This patch introduces a btrfs_iget helper to be used in NFS support. Signed-off-by: Balaji Rao <[email protected]> Signed-off-by: David Woodhouse <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent b64a285 commit 1a54ef8

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

fs/btrfs/ctree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,8 @@ struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
17001700
struct btrfs_root *root);
17011701
struct inode *btrfs_ilookup(struct super_block *s, u64 objectid,
17021702
u64 root_objectid);
1703+
struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
1704+
struct btrfs_root *root, int *is_new);
17031705
int btrfs_commit_write(struct file *file, struct page *page,
17041706
unsigned from, unsigned to);
17051707
struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,

fs/btrfs/inode.c

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,33 @@ struct inode *btrfs_iget_locked(struct super_block *s, u64 objectid,
18401840
return inode;
18411841
}
18421842

1843+
/* Get an inode object given its location and corresponding root.
1844+
* Returns in *is_new if the inode was read from disk
1845+
*/
1846+
struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location,
1847+
struct btrfs_root *root, int *is_new)
1848+
{
1849+
struct inode *inode;
1850+
1851+
inode = btrfs_iget_locked(s, location->objectid, root);
1852+
if (!inode)
1853+
return ERR_PTR(-EACCES);
1854+
1855+
if (inode->i_state & I_NEW) {
1856+
BTRFS_I(inode)->root = root;
1857+
memcpy(&BTRFS_I(inode)->location, location, sizeof(*location));
1858+
btrfs_read_locked_inode(inode);
1859+
unlock_new_inode(inode);
1860+
if (is_new)
1861+
*is_new = 1;
1862+
} else {
1863+
if (is_new)
1864+
*is_new = 0;
1865+
}
1866+
1867+
return inode;
1868+
}
1869+
18431870
static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
18441871
struct nameidata *nd)
18451872
{
@@ -1848,7 +1875,7 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
18481875
struct btrfs_root *root = bi->root;
18491876
struct btrfs_root *sub_root = root;
18501877
struct btrfs_key location;
1851-
int ret, do_orphan = 0;
1878+
int ret, new, do_orphan = 0;
18521879

18531880
if (dentry->d_name.len > BTRFS_NAME_LEN)
18541881
return ERR_PTR(-ENAMETOOLONG);
@@ -1866,23 +1893,15 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry,
18661893
return ERR_PTR(ret);
18671894
if (ret > 0)
18681895
return ERR_PTR(-ENOENT);
1869-
1870-
inode = btrfs_iget_locked(dir->i_sb, location.objectid,
1871-
sub_root);
1872-
if (!inode)
1873-
return ERR_PTR(-EACCES);
1874-
if (inode->i_state & I_NEW) {
1875-
/* the inode and parent dir are two different roots */
1876-
if (sub_root != root) {
1877-
igrab(inode);
1878-
sub_root->inode = inode;
1879-
do_orphan = 1;
1880-
}
1881-
BTRFS_I(inode)->root = sub_root;
1882-
memcpy(&BTRFS_I(inode)->location, &location,
1883-
sizeof(location));
1884-
btrfs_read_locked_inode(inode);
1885-
unlock_new_inode(inode);
1896+
inode = btrfs_iget(dir->i_sb, &location, sub_root, &new);
1897+
if (IS_ERR(inode))
1898+
return ERR_CAST(inode);
1899+
1900+
/* the inode and parent dir are two different roots */
1901+
if (new && root != sub_root) {
1902+
igrab(inode);
1903+
sub_root->inode = inode;
1904+
do_orphan = 1;
18861905
}
18871906
}
18881907

0 commit comments

Comments
 (0)