Commit 0a370e5de9e5a48eb4b268e9f5e2286b82f44012
Committed by
Linus Torvalds
1 parent
b88a27edcd
Exists in
master
and in
4 other branches
iget: stop HOSTFS from using iget() and read_inode()
Stop the HOSTFS filesystem from using iget() and read_inode(). Provide hostfs_iget(), and call that instead of iget(). hostfs_iget() then uses iget_locked() directly and returns a proper error code instead of an inode in the event of an error. hostfs_fill_sb_common() returns any error incurred when getting the root inode instead of EINVAL. Note that the contents of hostfs_kern.c need to be examined: (*) hostfs_iget() should perhaps subsume init_inode() and hostfs_read_inode(). (*) It would appear that all hostfs inodes are the same inode because iget() was being called with inode number 0 - which forms the lookup key. [akpm@linux-foundation.org: coding-style fixes] Signed-off-by: David Howells <dhowells@redhat.com> Cc: Jeff Dike <jdike@addtoit.com> Acked-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 38 additions and 19 deletions Side-by-side Diff
fs/hostfs/hostfs_kern.c
... | ... | @@ -202,7 +202,7 @@ |
202 | 202 | return ERR_PTR(n); |
203 | 203 | } |
204 | 204 | |
205 | -static int read_inode(struct inode *ino) | |
205 | +static int hostfs_read_inode(struct inode *ino) | |
206 | 206 | { |
207 | 207 | char *name; |
208 | 208 | int err = 0; |
... | ... | @@ -233,6 +233,25 @@ |
233 | 233 | return err; |
234 | 234 | } |
235 | 235 | |
236 | +static struct inode *hostfs_iget(struct super_block *sb) | |
237 | +{ | |
238 | + struct inode *inode; | |
239 | + long ret; | |
240 | + | |
241 | + inode = iget_locked(sb, 0); | |
242 | + if (!inode) | |
243 | + return ERR_PTR(-ENOMEM); | |
244 | + if (inode->i_state & I_NEW) { | |
245 | + ret = hostfs_read_inode(inode); | |
246 | + if (ret < 0) { | |
247 | + iget_failed(inode); | |
248 | + return ERR_PTR(ret); | |
249 | + } | |
250 | + unlock_new_inode(inode); | |
251 | + } | |
252 | + return inode; | |
253 | +} | |
254 | + | |
236 | 255 | int hostfs_statfs(struct dentry *dentry, struct kstatfs *sf) |
237 | 256 | { |
238 | 257 | /* |
239 | 258 | |
... | ... | @@ -303,17 +322,11 @@ |
303 | 322 | kfree(HOSTFS_I(inode)); |
304 | 323 | } |
305 | 324 | |
306 | -static void hostfs_read_inode(struct inode *inode) | |
307 | -{ | |
308 | - read_inode(inode); | |
309 | -} | |
310 | - | |
311 | 325 | static const struct super_operations hostfs_sbops = { |
312 | 326 | .alloc_inode = hostfs_alloc_inode, |
313 | 327 | .drop_inode = generic_delete_inode, |
314 | 328 | .delete_inode = hostfs_delete_inode, |
315 | 329 | .destroy_inode = hostfs_destroy_inode, |
316 | - .read_inode = hostfs_read_inode, | |
317 | 330 | .statfs = hostfs_statfs, |
318 | 331 | }; |
319 | 332 | |
320 | 333 | |
... | ... | @@ -571,10 +584,11 @@ |
571 | 584 | char *name; |
572 | 585 | int error, fd; |
573 | 586 | |
574 | - error = -ENOMEM; | |
575 | - inode = iget(dir->i_sb, 0); | |
576 | - if (inode == NULL) | |
587 | + inode = hostfs_iget(dir->i_sb); | |
588 | + if (IS_ERR(inode)) { | |
589 | + error = PTR_ERR(inode); | |
577 | 590 | goto out; |
591 | + } | |
578 | 592 | |
579 | 593 | error = init_inode(inode, dentry); |
580 | 594 | if (error) |
581 | 595 | |
... | ... | @@ -615,10 +629,11 @@ |
615 | 629 | char *name; |
616 | 630 | int err; |
617 | 631 | |
618 | - err = -ENOMEM; | |
619 | - inode = iget(ino->i_sb, 0); | |
620 | - if (inode == NULL) | |
632 | + inode = hostfs_iget(ino->i_sb); | |
633 | + if (IS_ERR(inode)) { | |
634 | + err = PTR_ERR(inode); | |
621 | 635 | goto out; |
636 | + } | |
622 | 637 | |
623 | 638 | err = init_inode(inode, dentry); |
624 | 639 | if (err) |
625 | 640 | |
626 | 641 | |
... | ... | @@ -736,11 +751,13 @@ |
736 | 751 | { |
737 | 752 | struct inode *inode; |
738 | 753 | char *name; |
739 | - int err = -ENOMEM; | |
754 | + int err; | |
740 | 755 | |
741 | - inode = iget(dir->i_sb, 0); | |
742 | - if (inode == NULL) | |
756 | + inode = hostfs_iget(dir->i_sb); | |
757 | + if (IS_ERR(inode)) { | |
758 | + err = PTR_ERR(inode); | |
743 | 759 | goto out; |
760 | + } | |
744 | 761 | |
745 | 762 | err = init_inode(inode, dentry); |
746 | 763 | if (err) |
747 | 764 | |
... | ... | @@ -952,9 +969,11 @@ |
952 | 969 | |
953 | 970 | sprintf(host_root_path, "%s/%s", root_ino, req_root); |
954 | 971 | |
955 | - root_inode = iget(sb, 0); | |
956 | - if (root_inode == NULL) | |
972 | + root_inode = hostfs_iget(sb); | |
973 | + if (IS_ERR(root_inode)) { | |
974 | + err = PTR_ERR(root_inode); | |
957 | 975 | goto out_free; |
976 | + } | |
958 | 977 | |
959 | 978 | err = init_inode(root_inode, NULL); |
960 | 979 | if (err) |
... | ... | @@ -972,7 +991,7 @@ |
972 | 991 | if (sb->s_root == NULL) |
973 | 992 | goto out_put; |
974 | 993 | |
975 | - err = read_inode(root_inode); | |
994 | + err = hostfs_read_inode(root_inode); | |
976 | 995 | if (err) { |
977 | 996 | /* No iput in this case because the dput does that for us */ |
978 | 997 | dput(sb->s_root); |