aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2008-04-14 07:11:02 -0400
committerPaul Mackerras <paulus@samba.org>2008-04-14 07:11:02 -0400
commitac7c5353b189e10cf5dd27399f64f7b013abffc6 (patch)
tree8222d92b774c256d6ec4399c716d76b3f05ddc4b /fs
parenta8f75ea70c58546205fb7673be41455b9da5d9a7 (diff)
parent120dd64cacd4fb796bca0acba3665553f1d9ecaa (diff)
Merge branch 'linux-2.6'
Diffstat (limited to 'fs')
-rw-r--r--fs/Kconfig8
-rw-r--r--fs/afs/cell.c16
-rw-r--r--fs/afs/internal.h3
-rw-r--r--fs/afs/mntpt.c8
-rw-r--r--fs/afs/super.c1
-rw-r--r--fs/aio.c18
-rw-r--r--fs/anon_inodes.c18
-rw-r--r--fs/buffer.c28
-rw-r--r--fs/cifs/cifs_dfs_ref.c1
-rw-r--r--fs/cifs/cifsacl.c4
-rw-r--r--fs/efs/inode.c2
-rw-r--r--fs/file_table.c6
-rw-r--r--fs/hfsplus/dir.c23
-rw-r--r--fs/hppfs/hppfs_kern.c435
-rw-r--r--fs/hugetlbfs/inode.c2
-rw-r--r--fs/jbd/journal.c4
-rw-r--r--fs/jbd/revoke.c4
-rw-r--r--fs/jbd2/journal.c12
-rw-r--r--fs/jbd2/revoke.c4
-rw-r--r--fs/namei.c63
-rw-r--r--fs/namespace.c200
-rw-r--r--fs/nfs/file.c4
-rw-r--r--fs/nfs/inode.c1
-rw-r--r--fs/nfs/super.c2
-rw-r--r--fs/open.c20
-rw-r--r--fs/pipe.c19
-rw-r--r--fs/pnode.c2
-rw-r--r--fs/reiserfs/do_balan.c8
-rw-r--r--fs/reiserfs/fix_node.c8
-rw-r--r--fs/reiserfs/lbalance.c2
-rw-r--r--fs/reiserfs/namei.c2
-rw-r--r--fs/reiserfs/xattr.c110
-rw-r--r--fs/signalfd.c7
-rw-r--r--fs/smbfs/smbiod.c2
-rw-r--r--fs/splice.c33
-rw-r--r--fs/super.c1
-rw-r--r--fs/xfs/linux-2.6/xfs_ioctl.c2
-rw-r--r--fs/xfs/quota/xfs_qm.c6
-rw-r--r--fs/xfs/quota/xfs_qm_bhv.c2
-rw-r--r--fs/xfs/quota/xfs_qm_syscalls.c4
-rw-r--r--fs/xfs/xfs_attr_leaf.c6
-rw-r--r--fs/xfs/xfs_bmap.c18
-rw-r--r--fs/xfs/xfs_bmap_btree.h2
-rw-r--r--fs/xfs/xfs_dir2.c2
-rw-r--r--fs/xfs/xfs_fsops.c24
-rw-r--r--fs/xfs/xfs_ialloc.c6
-rw-r--r--fs/xfs/xfs_inode.c6
-rw-r--r--fs/xfs/xfs_inode_item.c4
-rw-r--r--fs/xfs/xfs_itable.c2
-rw-r--r--fs/xfs/xfs_log.c14
-rw-r--r--fs/xfs/xfs_log_priv.h4
-rw-r--r--fs/xfs/xfs_log_recover.c16
-rw-r--r--fs/xfs/xfs_mount.c59
-rw-r--r--fs/xfs/xfs_sb.h107
-rw-r--r--fs/xfs/xfs_utils.c6
-rw-r--r--fs/xfs/xfs_vfsops.c9
-rw-r--r--fs/xfs/xfs_vnodeops.c2
57 files changed, 636 insertions, 746 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
index d7312825592b..c509123bea49 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1744,10 +1744,10 @@ config ROOT_NFS
1744 If you want your Linux box to mount its whole root file system (the 1744 If you want your Linux box to mount its whole root file system (the
1745 one containing the directory /) from some other computer over the 1745 one containing the directory /) from some other computer over the
1746 net via NFS (presumably because your box doesn't have a hard disk), 1746 net via NFS (presumably because your box doesn't have a hard disk),
1747 say Y. Read <file:Documentation/nfsroot.txt> for details. It is 1747 say Y. Read <file:Documentation/filesystems/nfsroot.txt> for
1748 likely that in this case, you also want to say Y to "Kernel level IP 1748 details. It is likely that in this case, you also want to say Y to
1749 autoconfiguration" so that your box can discover its network address 1749 "Kernel level IP autoconfiguration" so that your box can discover
1750 at boot time. 1750 its network address at boot time.
1751 1751
1752 Most people say N here. 1752 Most people say N here.
1753 1753
diff --git a/fs/afs/cell.c b/fs/afs/cell.c
index 970d38f30565..584bb0f9c36a 100644
--- a/fs/afs/cell.c
+++ b/fs/afs/cell.c
@@ -127,14 +127,21 @@ struct afs_cell *afs_cell_create(const char *name, char *vllist)
127 127
128 _enter("%s,%s", name, vllist); 128 _enter("%s,%s", name, vllist);
129 129
130 down_write(&afs_cells_sem);
131 read_lock(&afs_cells_lock);
132 list_for_each_entry(cell, &afs_cells, link) {
133 if (strcasecmp(cell->name, name) == 0)
134 goto duplicate_name;
135 }
136 read_unlock(&afs_cells_lock);
137
130 cell = afs_cell_alloc(name, vllist); 138 cell = afs_cell_alloc(name, vllist);
131 if (IS_ERR(cell)) { 139 if (IS_ERR(cell)) {
132 _leave(" = %ld", PTR_ERR(cell)); 140 _leave(" = %ld", PTR_ERR(cell));
141 up_write(&afs_cells_sem);
133 return cell; 142 return cell;
134 } 143 }
135 144
136 down_write(&afs_cells_sem);
137
138 /* add a proc directory for this cell */ 145 /* add a proc directory for this cell */
139 ret = afs_proc_cell_setup(cell); 146 ret = afs_proc_cell_setup(cell);
140 if (ret < 0) 147 if (ret < 0)
@@ -167,6 +174,11 @@ error:
167 kfree(cell); 174 kfree(cell);
168 _leave(" = %d", ret); 175 _leave(" = %d", ret);
169 return ERR_PTR(ret); 176 return ERR_PTR(ret);
177
178duplicate_name:
179 read_unlock(&afs_cells_lock);
180 up_write(&afs_cells_sem);
181 return ERR_PTR(-EEXIST);
170} 182}
171 183
172/* 184/*
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 5ca3625cd39e..eec41c76de72 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -573,7 +573,6 @@ extern const struct file_operations afs_mntpt_file_operations;
573 573
574extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *); 574extern int afs_mntpt_check_symlink(struct afs_vnode *, struct key *);
575extern void afs_mntpt_kill_timer(void); 575extern void afs_mntpt_kill_timer(void);
576extern void afs_umount_begin(struct vfsmount *, int);
577 576
578/* 577/*
579 * proc.c 578 * proc.c
@@ -750,7 +749,7 @@ extern int afs_fsync(struct file *, struct dentry *, int);
750extern unsigned afs_debug; 749extern unsigned afs_debug;
751 750
752#define dbgprintk(FMT,...) \ 751#define dbgprintk(FMT,...) \
753 printk("[%x%-6.6s] "FMT"\n", smp_processor_id(), current->comm ,##__VA_ARGS__) 752 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
754 753
755/* make sure we maintain the format strings, even when debugging is disabled */ 754/* make sure we maintain the format strings, even when debugging is disabled */
756static inline __attribute__((format(printf,1,2))) 755static inline __attribute__((format(printf,1,2)))
diff --git a/fs/afs/mntpt.c b/fs/afs/mntpt.c
index a3510b8ba3e7..2f5503902c37 100644
--- a/fs/afs/mntpt.c
+++ b/fs/afs/mntpt.c
@@ -283,11 +283,3 @@ void afs_mntpt_kill_timer(void)
283 cancel_delayed_work(&afs_mntpt_expiry_timer); 283 cancel_delayed_work(&afs_mntpt_expiry_timer);
284 flush_scheduled_work(); 284 flush_scheduled_work();
285} 285}
286
287/*
288 * begin unmount by attempting to remove all automounted mountpoints we added
289 */
290void afs_umount_begin(struct vfsmount *vfsmnt, int flags)
291{
292 shrink_submounts(vfsmnt, &afs_vfsmounts);
293}
diff --git a/fs/afs/super.c b/fs/afs/super.c
index 36bbce45f44b..4b572b801d8d 100644
--- a/fs/afs/super.c
+++ b/fs/afs/super.c
@@ -50,7 +50,6 @@ static const struct super_operations afs_super_ops = {
50 .write_inode = afs_write_inode, 50 .write_inode = afs_write_inode,
51 .destroy_inode = afs_destroy_inode, 51 .destroy_inode = afs_destroy_inode,
52 .clear_inode = afs_clear_inode, 52 .clear_inode = afs_clear_inode,
53 .umount_begin = afs_umount_begin,
54 .put_super = afs_put_super, 53 .put_super = afs_put_super,
55 .show_options = generic_show_options, 54 .show_options = generic_show_options,
56}; 55};
diff --git a/fs/aio.c b/fs/aio.c
index 6af921940622..228368610dfa 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -936,14 +936,6 @@ int aio_complete(struct kiocb *iocb, long res, long res2)
936 return 1; 936 return 1;
937 } 937 }
938 938
939 /*
940 * Check if the user asked us to deliver the result through an
941 * eventfd. The eventfd_signal() function is safe to be called
942 * from IRQ context.
943 */
944 if (!IS_ERR(iocb->ki_eventfd))
945 eventfd_signal(iocb->ki_eventfd, 1);
946
947 info = &ctx->ring_info; 939 info = &ctx->ring_info;
948 940
949 /* add a completion event to the ring buffer. 941 /* add a completion event to the ring buffer.
@@ -992,6 +984,15 @@ int aio_complete(struct kiocb *iocb, long res, long res2)
992 kunmap_atomic(ring, KM_IRQ1); 984 kunmap_atomic(ring, KM_IRQ1);
993 985
994 pr_debug("added to ring %p at [%lu]\n", iocb, tail); 986 pr_debug("added to ring %p at [%lu]\n", iocb, tail);
987
988 /*
989 * Check if the user asked us to deliver the result through an
990 * eventfd. The eventfd_signal() function is safe to be called
991 * from IRQ context.
992 */
993 if (!IS_ERR(iocb->ki_eventfd))
994 eventfd_signal(iocb->ki_eventfd, 1);
995
995put_rq: 996put_rq:
996 /* everything turned out well, dispose of the aiocb. */ 997 /* everything turned out well, dispose of the aiocb. */
997 ret = __aio_put_req(ctx, iocb); 998 ret = __aio_put_req(ctx, iocb);
@@ -1790,6 +1791,7 @@ asmlinkage long sys_io_getevents(aio_context_t ctx_id,
1790 put_ioctx(ioctx); 1791 put_ioctx(ioctx);
1791 } 1792 }
1792 1793
1794 asmlinkage_protect(5, ret, ctx_id, min_nr, nr, events, timeout);
1793 return ret; 1795 return ret;
1794} 1796}
1795 1797
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 23321889d9b0..f42be069e085 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -81,13 +81,10 @@ int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
81 81
82 if (IS_ERR(anon_inode_inode)) 82 if (IS_ERR(anon_inode_inode))
83 return -ENODEV; 83 return -ENODEV;
84 file = get_empty_filp();
85 if (!file)
86 return -ENFILE;
87 84
88 error = get_unused_fd(); 85 error = get_unused_fd();
89 if (error < 0) 86 if (error < 0)
90 goto err_put_filp; 87 return error;
91 fd = error; 88 fd = error;
92 89
93 /* 90 /*
@@ -114,14 +111,15 @@ int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
114 dentry->d_flags &= ~DCACHE_UNHASHED; 111 dentry->d_flags &= ~DCACHE_UNHASHED;
115 d_instantiate(dentry, anon_inode_inode); 112 d_instantiate(dentry, anon_inode_inode);
116 113
117 file->f_path.mnt = mntget(anon_inode_mnt); 114 error = -ENFILE;
118 file->f_path.dentry = dentry; 115 file = alloc_file(anon_inode_mnt, dentry,
116 FMODE_READ | FMODE_WRITE, fops);
117 if (!file)
118 goto err_dput;
119 file->f_mapping = anon_inode_inode->i_mapping; 119 file->f_mapping = anon_inode_inode->i_mapping;
120 120
121 file->f_pos = 0; 121 file->f_pos = 0;
122 file->f_flags = O_RDWR; 122 file->f_flags = O_RDWR;
123 file->f_op = fops;
124 file->f_mode = FMODE_READ | FMODE_WRITE;
125 file->f_version = 0; 123 file->f_version = 0;
126 file->private_data = priv; 124 file->private_data = priv;
127 125
@@ -132,10 +130,10 @@ int anon_inode_getfd(int *pfd, struct inode **pinode, struct file **pfile,
132 *pfile = file; 130 *pfile = file;
133 return 0; 131 return 0;
134 132
133err_dput:
134 dput(dentry);
135err_put_unused_fd: 135err_put_unused_fd:
136 put_unused_fd(fd); 136 put_unused_fd(fd);
137err_put_filp:
138 put_filp(file);
139 return error; 137 return error;
140} 138}
141EXPORT_SYMBOL_GPL(anon_inode_getfd); 139EXPORT_SYMBOL_GPL(anon_inode_getfd);
diff --git a/fs/buffer.c b/fs/buffer.c
index 7ba58386beee..39ff14403d13 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1181,7 +1181,20 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size)
1181void mark_buffer_dirty(struct buffer_head *bh) 1181void mark_buffer_dirty(struct buffer_head *bh)
1182{ 1182{
1183 WARN_ON_ONCE(!buffer_uptodate(bh)); 1183 WARN_ON_ONCE(!buffer_uptodate(bh));
1184 if (!buffer_dirty(bh) && !test_set_buffer_dirty(bh)) 1184
1185 /*
1186 * Very *carefully* optimize the it-is-already-dirty case.
1187 *
1188 * Don't let the final "is it dirty" escape to before we
1189 * perhaps modified the buffer.
1190 */
1191 if (buffer_dirty(bh)) {
1192 smp_mb();
1193 if (buffer_dirty(bh))
1194 return;
1195 }
1196
1197 if (!test_set_buffer_dirty(bh))
1185 __set_page_dirty(bh->b_page, page_mapping(bh->b_page), 0); 1198 __set_page_dirty(bh->b_page, page_mapping(bh->b_page), 0);
1186} 1199}
1187 1200
@@ -2564,14 +2577,13 @@ int nobh_write_end(struct file *file, struct address_space *mapping,
2564 struct inode *inode = page->mapping->host; 2577 struct inode *inode = page->mapping->host;
2565 struct buffer_head *head = fsdata; 2578 struct buffer_head *head = fsdata;
2566 struct buffer_head *bh; 2579 struct buffer_head *bh;
2580 BUG_ON(fsdata != NULL && page_has_buffers(page));
2567 2581
2568 if (!PageMappedToDisk(page)) { 2582 if (unlikely(copied < len) && !page_has_buffers(page))
2569 if (unlikely(copied < len) && !page_has_buffers(page)) 2583 attach_nobh_buffers(page, head);
2570 attach_nobh_buffers(page, head); 2584 if (page_has_buffers(page))
2571 if (page_has_buffers(page)) 2585 return generic_write_end(file, mapping, pos, len,
2572 return generic_write_end(file, mapping, pos, len, 2586 copied, page, fsdata);
2573 copied, page, fsdata);
2574 }
2575 2587
2576 SetPageUptodate(page); 2588 SetPageUptodate(page);
2577 set_page_dirty(page); 2589 set_page_dirty(page);
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index a1a95b027136..56c924033b78 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -33,7 +33,6 @@ void dfs_shrink_umount_helper(struct vfsmount *vfsmnt)
33{ 33{
34 mark_mounts_for_expiry(&cifs_dfs_automount_list); 34 mark_mounts_for_expiry(&cifs_dfs_automount_list);
35 mark_mounts_for_expiry(&cifs_dfs_automount_list); 35 mark_mounts_for_expiry(&cifs_dfs_automount_list);
36 shrink_submounts(vfsmnt, &cifs_dfs_automount_list);
37} 36}
38 37
39/** 38/**
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index 1f5a4289b848..1cb5b0a9f2ac 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -261,7 +261,7 @@ static void mode_to_access_flags(umode_t mode, umode_t bits_to_use,
261 return; 261 return;
262} 262}
263 263
264static __le16 fill_ace_for_sid(struct cifs_ace *pntace, 264static __u16 fill_ace_for_sid(struct cifs_ace *pntace,
265 const struct cifs_sid *psid, __u64 nmode, umode_t bits) 265 const struct cifs_sid *psid, __u64 nmode, umode_t bits)
266{ 266{
267 int i; 267 int i;
@@ -411,7 +411,7 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
411static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid, 411static int set_chmod_dacl(struct cifs_acl *pndacl, struct cifs_sid *pownersid,
412 struct cifs_sid *pgrpsid, __u64 nmode) 412 struct cifs_sid *pgrpsid, __u64 nmode)
413{ 413{
414 __le16 size = 0; 414 u16 size = 0;
415 struct cifs_acl *pnndacl; 415 struct cifs_acl *pnndacl;
416 416
417 pnndacl = (struct cifs_acl *)((char *)pndacl + sizeof(struct cifs_acl)); 417 pnndacl = (struct cifs_acl *)((char *)pndacl + sizeof(struct cifs_acl));
diff --git a/fs/efs/inode.c b/fs/efs/inode.c
index 79e19e5958e1..a8e7797b9477 100644
--- a/fs/efs/inode.c
+++ b/fs/efs/inode.c
@@ -140,7 +140,7 @@ struct inode *efs_iget(struct super_block *super, unsigned long ino)
140 brelse(bh); 140 brelse(bh);
141 141
142#ifdef DEBUG 142#ifdef DEBUG
143 printk(KERN_DEBUG "EFS: read_inode(): inode %lu, extents %d, mode %o\n", 143 printk(KERN_DEBUG "EFS: efs_iget(): inode %lu, extents %d, mode %o\n",
144 inode->i_ino, in->numextents, inode->i_mode); 144 inode->i_ino, in->numextents, inode->i_mode);
145#endif 145#endif
146 146
diff --git a/fs/file_table.c b/fs/file_table.c
index 6d27befe2d48..986ff4ed0a7c 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -83,6 +83,12 @@ int proc_nr_files(ctl_table *table, int write, struct file *filp,
83/* Find an unused file structure and return a pointer to it. 83/* Find an unused file structure and return a pointer to it.
84 * Returns NULL, if there are no more free file structures or 84 * Returns NULL, if there are no more free file structures or
85 * we run out of memory. 85 * we run out of memory.
86 *
87 * Be very careful using this. You are responsible for
88 * getting write access to any mount that you might assign
89 * to this filp, if it is opened for write. If this is not
90 * done, you will imbalance int the mount's writer count
91 * and a warning at __fput() time.
86 */ 92 */
87struct file *get_empty_filp(void) 93struct file *get_empty_filp(void)
88{ 94{
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 29683645fa0a..5f4023678251 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -340,16 +340,23 @@ static int hfsplus_unlink(struct inode *dir, struct dentry *dentry)
340 340
341 if (inode->i_nlink > 0) 341 if (inode->i_nlink > 0)
342 drop_nlink(inode); 342 drop_nlink(inode);
343 hfsplus_delete_inode(inode); 343 if (inode->i_ino == cnid)
344 if (inode->i_ino != cnid && !inode->i_nlink) { 344 clear_nlink(inode);
345 if (!atomic_read(&HFSPLUS_I(inode).opencnt)) { 345 if (!inode->i_nlink) {
346 res = hfsplus_delete_cat(inode->i_ino, HFSPLUS_SB(sb).hidden_dir, NULL); 346 if (inode->i_ino != cnid) {
347 if (!res) 347 HFSPLUS_SB(sb).file_count--;
348 hfsplus_delete_inode(inode); 348 if (!atomic_read(&HFSPLUS_I(inode).opencnt)) {
349 res = hfsplus_delete_cat(inode->i_ino,
350 HFSPLUS_SB(sb).hidden_dir,
351 NULL);
352 if (!res)
353 hfsplus_delete_inode(inode);
354 } else
355 inode->i_flags |= S_DEAD;
349 } else 356 } else
350 inode->i_flags |= S_DEAD; 357 hfsplus_delete_inode(inode);
351 } else 358 } else
352 clear_nlink(inode); 359 HFSPLUS_SB(sb).file_count--;
353 inode->i_ctime = CURRENT_TIME_SEC; 360 inode->i_ctime = CURRENT_TIME_SEC;
354 mark_inode_dirty(inode); 361 mark_inode_dirty(inode);
355 362
diff --git a/fs/hppfs/hppfs_kern.c b/fs/hppfs/hppfs_kern.c
index a1e1f0f61aa5..8601d8ef3b55 100644
--- a/fs/hppfs/hppfs_kern.c
+++ b/fs/hppfs/hppfs_kern.c
@@ -1,23 +1,24 @@
1/* 1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL 3 * Licensed under the GPL
4 */ 4 */
5 5
6#include <linux/fs.h> 6#include <linux/ctype.h>
7#include <linux/dcache.h>
7#include <linux/file.h> 8#include <linux/file.h>
8#include <linux/module.h> 9#include <linux/fs.h>
9#include <linux/init.h> 10#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/list.h>
12#include <linux/kernel.h> 11#include <linux/kernel.h>
13#include <linux/ctype.h> 12#include <linux/list.h>
14#include <linux/dcache.h> 13#include <linux/module.h>
14#include <linux/mount.h>
15#include <linux/slab.h>
15#include <linux/statfs.h> 16#include <linux/statfs.h>
17#include <linux/types.h>
16#include <asm/uaccess.h> 18#include <asm/uaccess.h>
17#include <asm/fcntl.h>
18#include "os.h" 19#include "os.h"
19 20
20static int init_inode(struct inode *inode, struct dentry *dentry); 21static struct inode *get_inode(struct super_block *, struct dentry *);
21 22
22struct hppfs_data { 23struct hppfs_data {
23 struct list_head list; 24 struct list_head list;
@@ -51,14 +52,14 @@ static int is_pid(struct dentry *dentry)
51 int i; 52 int i;
52 53
53 sb = dentry->d_sb; 54 sb = dentry->d_sb;
54 if((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root)) 55 if ((sb->s_op != &hppfs_sbops) || (dentry->d_parent != sb->s_root))
55 return(0); 56 return 0;
56 57
57 for(i = 0; i < dentry->d_name.len; i++){ 58 for (i = 0; i < dentry->d_name.len; i++) {
58 if(!isdigit(dentry->d_name.name[i])) 59 if (!isdigit(dentry->d_name.name[i]))
59 return(0); 60 return 0;
60 } 61 }
61 return(1); 62 return 1;
62} 63}
63 64
64static char *dentry_name(struct dentry *dentry, int extra) 65static char *dentry_name(struct dentry *dentry, int extra)
@@ -70,8 +71,8 @@ static char *dentry_name(struct dentry *dentry, int extra)
70 71
71 len = 0; 72 len = 0;
72 parent = dentry; 73 parent = dentry;
73 while(parent->d_parent != parent){ 74 while (parent->d_parent != parent) {
74 if(is_pid(parent)) 75 if (is_pid(parent))
75 len += strlen("pid") + 1; 76 len += strlen("pid") + 1;
76 else len += parent->d_name.len + 1; 77 else len += parent->d_name.len + 1;
77 parent = parent->d_parent; 78 parent = parent->d_parent;
@@ -80,12 +81,13 @@ static char *dentry_name(struct dentry *dentry, int extra)
80 root = "proc"; 81 root = "proc";
81 len += strlen(root); 82 len += strlen(root);
82 name = kmalloc(len + extra + 1, GFP_KERNEL); 83 name = kmalloc(len + extra + 1, GFP_KERNEL);
83 if(name == NULL) return(NULL); 84 if (name == NULL)
85 return NULL;
84 86
85 name[len] = '\0'; 87 name[len] = '\0';
86 parent = dentry; 88 parent = dentry;
87 while(parent->d_parent != parent){ 89 while (parent->d_parent != parent) {
88 if(is_pid(parent)){ 90 if (is_pid(parent)) {
89 seg_name = "pid"; 91 seg_name = "pid";
90 seg_len = strlen("pid"); 92 seg_len = strlen("pid");
91 } 93 }
@@ -100,27 +102,25 @@ static char *dentry_name(struct dentry *dentry, int extra)
100 parent = parent->d_parent; 102 parent = parent->d_parent;
101 } 103 }
102 strncpy(name, root, strlen(root)); 104 strncpy(name, root, strlen(root));
103 return(name); 105 return name;
104} 106}
105 107
106struct dentry_operations hppfs_dentry_ops = {
107};
108
109static int file_removed(struct dentry *dentry, const char *file) 108static int file_removed(struct dentry *dentry, const char *file)
110{ 109{
111 char *host_file; 110 char *host_file;
112 int extra, fd; 111 int extra, fd;
113 112
114 extra = 0; 113 extra = 0;
115 if(file != NULL) extra += strlen(file) + 1; 114 if (file != NULL)
115 extra += strlen(file) + 1;
116 116
117 host_file = dentry_name(dentry, extra + strlen("/remove")); 117 host_file = dentry_name(dentry, extra + strlen("/remove"));
118 if(host_file == NULL){ 118 if (host_file == NULL) {
119 printk("file_removed : allocation failed\n"); 119 printk(KERN_ERR "file_removed : allocation failed\n");
120 return(-ENOMEM); 120 return -ENOMEM;
121 } 121 }
122 122
123 if(file != NULL){ 123 if (file != NULL) {
124 strcat(host_file, "/"); 124 strcat(host_file, "/");
125 strcat(host_file, file); 125 strcat(host_file, file);
126 } 126 }
@@ -128,45 +128,11 @@ static int file_removed(struct dentry *dentry, const char *file)
128 128
129 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); 129 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
130 kfree(host_file); 130 kfree(host_file);
131 if(fd > 0){ 131 if (fd > 0) {
132 os_close_file(fd); 132 os_close_file(fd);
133 return(1); 133 return 1;
134 }
135 return(0);
136}
137
138static void hppfs_read_inode(struct inode *ino)
139{
140 struct inode *proc_ino;
141
142 if(HPPFS_I(ino)->proc_dentry == NULL)
143 return;
144
145 proc_ino = HPPFS_I(ino)->proc_dentry->d_inode;
146 ino->i_uid = proc_ino->i_uid;
147 ino->i_gid = proc_ino->i_gid;
148 ino->i_atime = proc_ino->i_atime;
149 ino->i_mtime = proc_ino->i_mtime;
150 ino->i_ctime = proc_ino->i_ctime;
151 ino->i_ino = proc_ino->i_ino;
152 ino->i_mode = proc_ino->i_mode;
153 ino->i_nlink = proc_ino->i_nlink;
154 ino->i_size = proc_ino->i_size;
155 ino->i_blocks = proc_ino->i_blocks;
156}
157
158static struct inode *hppfs_iget(struct super_block *sb)
159{
160 struct inode *inode;
161
162 inode = iget_locked(sb, 0);
163 if (!inode)
164 return ERR_PTR(-ENOMEM);
165 if (inode->i_state & I_NEW) {
166 hppfs_read_inode(inode);
167 unlock_new_inode(inode);
168 } 134 }
169 return inode; 135 return 0;
170} 136}
171 137
172static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry, 138static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
@@ -177,55 +143,45 @@ static struct dentry *hppfs_lookup(struct inode *ino, struct dentry *dentry,
177 int err, deleted; 143 int err, deleted;
178 144
179 deleted = file_removed(dentry, NULL); 145 deleted = file_removed(dentry, NULL);
180 if(deleted < 0) 146 if (deleted < 0)
181 return(ERR_PTR(deleted)); 147 return ERR_PTR(deleted);
182 else if(deleted) 148 else if (deleted)
183 return(ERR_PTR(-ENOENT)); 149 return ERR_PTR(-ENOENT);
184 150
185 err = -ENOMEM; 151 err = -ENOMEM;
186 parent = HPPFS_I(ino)->proc_dentry; 152 parent = HPPFS_I(ino)->proc_dentry;
187 mutex_lock(&parent->d_inode->i_mutex); 153 mutex_lock(&parent->d_inode->i_mutex);
188 proc_dentry = d_lookup(parent, &dentry->d_name); 154 proc_dentry = d_lookup(parent, &dentry->d_name);
189 if(proc_dentry == NULL){ 155 if (proc_dentry == NULL) {
190 proc_dentry = d_alloc(parent, &dentry->d_name); 156 proc_dentry = d_alloc(parent, &dentry->d_name);
191 if(proc_dentry == NULL){ 157 if (proc_dentry == NULL) {
192 mutex_unlock(&parent->d_inode->i_mutex); 158 mutex_unlock(&parent->d_inode->i_mutex);
193 goto out; 159 goto out;
194 } 160 }
195 new = (*parent->d_inode->i_op->lookup)(parent->d_inode, 161 new = (*parent->d_inode->i_op->lookup)(parent->d_inode,
196 proc_dentry, NULL); 162 proc_dentry, NULL);
197 if(new){ 163 if (new) {
198 dput(proc_dentry); 164 dput(proc_dentry);
199 proc_dentry = new; 165 proc_dentry = new;
200 } 166 }
201 } 167 }
202 mutex_unlock(&parent->d_inode->i_mutex); 168 mutex_unlock(&parent->d_inode->i_mutex);
203 169
204 if(IS_ERR(proc_dentry)) 170 if (IS_ERR(proc_dentry))
205 return(proc_dentry); 171 return proc_dentry;
206 172
207 inode = hppfs_iget(ino->i_sb); 173 err = -ENOMEM;
208 if (IS_ERR(inode)) { 174 inode = get_inode(ino->i_sb, proc_dentry);
209 err = PTR_ERR(inode); 175 if (!inode)
210 goto out_dput; 176 goto out_dput;
211 }
212
213 err = init_inode(inode, proc_dentry);
214 if(err)
215 goto out_put;
216
217 hppfs_read_inode(inode);
218 177
219 d_add(dentry, inode); 178 d_add(dentry, inode);
220 dentry->d_op = &hppfs_dentry_ops; 179 return NULL;
221 return(NULL);
222 180
223 out_put:
224 iput(inode);
225 out_dput: 181 out_dput:
226 dput(proc_dentry); 182 dput(proc_dentry);
227 out: 183 out:
228 return(ERR_PTR(err)); 184 return ERR_PTR(err);
229} 185}
230 186
231static const struct inode_operations hppfs_file_iops = { 187static const struct inode_operations hppfs_file_iops = {
@@ -239,15 +195,16 @@ static ssize_t read_proc(struct file *file, char __user *buf, ssize_t count,
239 195
240 read = file->f_path.dentry->d_inode->i_fop->read; 196 read = file->f_path.dentry->d_inode->i_fop->read;
241 197
242 if(!is_user) 198 if (!is_user)
243 set_fs(KERNEL_DS); 199 set_fs(KERNEL_DS);
244 200
245 n = (*read)(file, buf, count, &file->f_pos); 201 n = (*read)(file, buf, count, &file->f_pos);
246 202
247 if(!is_user) 203 if (!is_user)
248 set_fs(USER_DS); 204 set_fs(USER_DS);
249 205
250 if(ppos) *ppos = file->f_pos; 206 if (ppos)
207 *ppos = file->f_pos;
251 return n; 208 return n;
252} 209}
253 210
@@ -259,24 +216,23 @@ static ssize_t hppfs_read_file(int fd, char __user *buf, ssize_t count)
259 216
260 n = -ENOMEM; 217 n = -ENOMEM;
261 new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 218 new_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
262 if(new_buf == NULL){ 219 if (new_buf == NULL) {
263 printk("hppfs_read_file : kmalloc failed\n"); 220 printk(KERN_ERR "hppfs_read_file : kmalloc failed\n");
264 goto out; 221 goto out;
265 } 222 }
266 n = 0; 223 n = 0;
267 while(count > 0){ 224 while (count > 0) {
268 cur = min_t(ssize_t, count, PAGE_SIZE); 225 cur = min_t(ssize_t, count, PAGE_SIZE);
269 err = os_read_file(fd, new_buf, cur); 226 err = os_read_file(fd, new_buf, cur);
270 if(err < 0){ 227 if (err < 0) {
271 printk("hppfs_read : read failed, errno = %d\n", 228 printk(KERN_ERR "hppfs_read : read failed, "
272 err); 229 "errno = %d\n", err);
273 n = err; 230 n = err;
274 goto out_free; 231 goto out_free;
275 } 232 } else if (err == 0)
276 else if(err == 0)
277 break; 233 break;
278 234
279 if(copy_to_user(buf, new_buf, err)){ 235 if (copy_to_user(buf, new_buf, err)) {
280 n = -EFAULT; 236 n = -EFAULT;
281 goto out_free; 237 goto out_free;
282 } 238 }
@@ -297,35 +253,36 @@ static ssize_t hppfs_read(struct file *file, char __user *buf, size_t count,
297 loff_t off; 253 loff_t off;
298 int err; 254 int err;
299 255
300 if(hppfs->contents != NULL){ 256 if (hppfs->contents != NULL) {
301 if(*ppos >= hppfs->len) return(0); 257 if (*ppos >= hppfs->len)
258 return 0;
302 259
303 data = hppfs->contents; 260 data = hppfs->contents;
304 off = *ppos; 261 off = *ppos;
305 while(off >= sizeof(data->contents)){ 262 while (off >= sizeof(data->contents)) {
306 data = list_entry(data->list.next, struct hppfs_data, 263 data = list_entry(data->list.next, struct hppfs_data,
307 list); 264 list);
308 off -= sizeof(data->contents); 265 off -= sizeof(data->contents);
309 } 266 }
310 267
311 if(off + count > hppfs->len) 268 if (off + count > hppfs->len)
312 count = hppfs->len - off; 269 count = hppfs->len - off;
313 copy_to_user(buf, &data->contents[off], count); 270 copy_to_user(buf, &data->contents[off], count);
314 *ppos += count; 271 *ppos += count;
315 } 272 } else if (hppfs->host_fd != -1) {
316 else if(hppfs->host_fd != -1){
317 err = os_seek_file(hppfs->host_fd, *ppos); 273 err = os_seek_file(hppfs->host_fd, *ppos);
318 if(err){ 274 if (err) {
319 printk("hppfs_read : seek failed, errno = %d\n", err); 275 printk(KERN_ERR "hppfs_read : seek failed, "
320 return(err); 276 "errno = %d\n", err);
277 return err;
321 } 278 }
322 count = hppfs_read_file(hppfs->host_fd, buf, count); 279 count = hppfs_read_file(hppfs->host_fd, buf, count);
323 if(count > 0) 280 if (count > 0)
324 *ppos += count; 281 *ppos += count;
325 } 282 }
326 else count = read_proc(hppfs->proc_file, buf, count, ppos, 1); 283 else count = read_proc(hppfs->proc_file, buf, count, ppos, 1);
327 284
328 return(count); 285 return count;
329} 286}
330 287
331static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len, 288static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len,
@@ -342,7 +299,7 @@ static ssize_t hppfs_write(struct file *file, const char __user *buf, size_t len
342 err = (*write)(proc_file, buf, len, &proc_file->f_pos); 299 err = (*write)(proc_file, buf, len, &proc_file->f_pos);
343 file->f_pos = proc_file->f_pos; 300 file->f_pos = proc_file->f_pos;
344 301
345 return(err); 302 return err;
346} 303}
347 304
348static int open_host_sock(char *host_file, int *filter_out) 305static int open_host_sock(char *host_file, int *filter_out)
@@ -354,13 +311,13 @@ static int open_host_sock(char *host_file, int *filter_out)
354 strcpy(end, "/rw"); 311 strcpy(end, "/rw");
355 *filter_out = 1; 312 *filter_out = 1;
356 fd = os_connect_socket(host_file); 313 fd = os_connect_socket(host_file);
357 if(fd > 0) 314 if (fd > 0)
358 return(fd); 315 return fd;
359 316
360 strcpy(end, "/r"); 317 strcpy(end, "/r");
361 *filter_out = 0; 318 *filter_out = 0;
362 fd = os_connect_socket(host_file); 319 fd = os_connect_socket(host_file);
363 return(fd); 320 return fd;
364} 321}
365 322
366static void free_contents(struct hppfs_data *head) 323static void free_contents(struct hppfs_data *head)
@@ -368,9 +325,10 @@ static void free_contents(struct hppfs_data *head)
368 struct hppfs_data *data; 325 struct hppfs_data *data;
369 struct list_head *ele, *next; 326 struct list_head *ele, *next;
370 327
371 if(head == NULL) return; 328 if (head == NULL)
329 return;
372 330
373 list_for_each_safe(ele, next, &head->list){ 331 list_for_each_safe(ele, next, &head->list) {
374 data = list_entry(ele, struct hppfs_data, list); 332 data = list_entry(ele, struct hppfs_data, list);
375 kfree(data); 333 kfree(data);
376 } 334 }
@@ -387,8 +345,8 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
387 345
388 err = -ENOMEM; 346 err = -ENOMEM;
389 data = kmalloc(sizeof(*data), GFP_KERNEL); 347 data = kmalloc(sizeof(*data), GFP_KERNEL);
390 if(data == NULL){ 348 if (data == NULL) {
391 printk("hppfs_get_data : head allocation failed\n"); 349 printk(KERN_ERR "hppfs_get_data : head allocation failed\n");
392 goto failed; 350 goto failed;
393 } 351 }
394 352
@@ -397,36 +355,36 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
397 head = data; 355 head = data;
398 *size_out = 0; 356 *size_out = 0;
399 357
400 if(filter){ 358 if (filter) {
401 while((n = read_proc(proc_file, data->contents, 359 while ((n = read_proc(proc_file, data->contents,
402 sizeof(data->contents), NULL, 0)) > 0) 360 sizeof(data->contents), NULL, 0)) > 0)
403 os_write_file(fd, data->contents, n); 361 os_write_file(fd, data->contents, n);
404 err = os_shutdown_socket(fd, 0, 1); 362 err = os_shutdown_socket(fd, 0, 1);
405 if(err){ 363 if (err) {
406 printk("hppfs_get_data : failed to shut down " 364 printk(KERN_ERR "hppfs_get_data : failed to shut down "
407 "socket\n"); 365 "socket\n");
408 goto failed_free; 366 goto failed_free;
409 } 367 }
410 } 368 }
411 while(1){ 369 while (1) {
412 n = os_read_file(fd, data->contents, sizeof(data->contents)); 370 n = os_read_file(fd, data->contents, sizeof(data->contents));
413 if(n < 0){ 371 if (n < 0) {
414 err = n; 372 err = n;
415 printk("hppfs_get_data : read failed, errno = %d\n", 373 printk(KERN_ERR "hppfs_get_data : read failed, "
416 err); 374 "errno = %d\n", err);
417 goto failed_free; 375 goto failed_free;
418 } 376 } else if (n == 0)
419 else if(n == 0)
420 break; 377 break;
421 378
422 *size_out += n; 379 *size_out += n;
423 380
424 if(n < sizeof(data->contents)) 381 if (n < sizeof(data->contents))
425 break; 382 break;
426 383
427 new = kmalloc(sizeof(*data), GFP_KERNEL); 384 new = kmalloc(sizeof(*data), GFP_KERNEL);
428 if(new == 0){ 385 if (new == 0) {
429 printk("hppfs_get_data : data allocation failed\n"); 386 printk(KERN_ERR "hppfs_get_data : data allocation "
387 "failed\n");
430 err = -ENOMEM; 388 err = -ENOMEM;
431 goto failed_free; 389 goto failed_free;
432 } 390 }
@@ -435,12 +393,12 @@ static struct hppfs_data *hppfs_get_data(int fd, int filter,
435 list_add(&new->list, &data->list); 393 list_add(&new->list, &data->list);
436 data = new; 394 data = new;
437 } 395 }
438 return(head); 396 return head;
439 397
440 failed_free: 398 failed_free:
441 free_contents(head); 399 free_contents(head);
442 failed: 400 failed:
443 return(ERR_PTR(err)); 401 return ERR_PTR(err);
444} 402}
445 403
446static struct hppfs_private *hppfs_data(void) 404static struct hppfs_private *hppfs_data(void)
@@ -448,77 +406,79 @@ static struct hppfs_private *hppfs_data(void)
448 struct hppfs_private *data; 406 struct hppfs_private *data;
449 407
450 data = kmalloc(sizeof(*data), GFP_KERNEL); 408 data = kmalloc(sizeof(*data), GFP_KERNEL);
451 if(data == NULL) 409 if (data == NULL)
452 return(data); 410 return data;
453 411
454 *data = ((struct hppfs_private ) { .host_fd = -1, 412 *data = ((struct hppfs_private ) { .host_fd = -1,
455 .len = -1, 413 .len = -1,
456 .contents = NULL } ); 414 .contents = NULL } );
457 return(data); 415 return data;
458} 416}
459 417
460static int file_mode(int fmode) 418static int file_mode(int fmode)
461{ 419{
462 if(fmode == (FMODE_READ | FMODE_WRITE)) 420 if (fmode == (FMODE_READ | FMODE_WRITE))
463 return(O_RDWR); 421 return O_RDWR;
464 if(fmode == FMODE_READ) 422 if (fmode == FMODE_READ)
465 return(O_RDONLY); 423 return O_RDONLY;
466 if(fmode == FMODE_WRITE) 424 if (fmode == FMODE_WRITE)
467 return(O_WRONLY); 425 return O_WRONLY;
468 return(0); 426 return 0;
469} 427}
470 428
471static int hppfs_open(struct inode *inode, struct file *file) 429static int hppfs_open(struct inode *inode, struct file *file)
472{ 430{
473 struct hppfs_private *data; 431 struct hppfs_private *data;
474 struct dentry *proc_dentry; 432 struct dentry *proc_dentry;
433 struct vfsmount *proc_mnt;
475 char *host_file; 434 char *host_file;
476 int err, fd, type, filter; 435 int err, fd, type, filter;
477 436
478 err = -ENOMEM; 437 err = -ENOMEM;
479 data = hppfs_data(); 438 data = hppfs_data();
480 if(data == NULL) 439 if (data == NULL)
481 goto out; 440 goto out;
482 441
483 host_file = dentry_name(file->f_path.dentry, strlen("/rw")); 442 host_file = dentry_name(file->f_path.dentry, strlen("/rw"));
484 if(host_file == NULL) 443 if (host_file == NULL)
485 goto out_free2; 444 goto out_free2;
486 445
487 proc_dentry = HPPFS_I(inode)->proc_dentry; 446 proc_dentry = HPPFS_I(inode)->proc_dentry;
447 proc_mnt = inode->i_sb->s_fs_info;
488 448
489 /* XXX This isn't closed anywhere */ 449 /* XXX This isn't closed anywhere */
490 data->proc_file = dentry_open(dget(proc_dentry), NULL, 450 data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
491 file_mode(file->f_mode)); 451 file_mode(file->f_mode));
492 err = PTR_ERR(data->proc_file); 452 err = PTR_ERR(data->proc_file);
493 if(IS_ERR(data->proc_file)) 453 if (IS_ERR(data->proc_file))
494 goto out_free1; 454 goto out_free1;
495 455
496 type = os_file_type(host_file); 456 type = os_file_type(host_file);
497 if(type == OS_TYPE_FILE){ 457 if (type == OS_TYPE_FILE) {
498 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0); 458 fd = os_open_file(host_file, of_read(OPENFLAGS()), 0);
499 if(fd >= 0) 459 if (fd >= 0)
500 data->host_fd = fd; 460 data->host_fd = fd;
501 else printk("hppfs_open : failed to open '%s', errno = %d\n", 461 else
502 host_file, -fd); 462 printk(KERN_ERR "hppfs_open : failed to open '%s', "
463 "errno = %d\n", host_file, -fd);
503 464
504 data->contents = NULL; 465 data->contents = NULL;
505 } 466 } else if (type == OS_TYPE_DIR) {
506 else if(type == OS_TYPE_DIR){
507 fd = open_host_sock(host_file, &filter); 467 fd = open_host_sock(host_file, &filter);
508 if(fd > 0){ 468 if (fd > 0) {
509 data->contents = hppfs_get_data(fd, filter, 469 data->contents = hppfs_get_data(fd, filter,
510 data->proc_file, 470 data->proc_file,
511 file, &data->len); 471 file, &data->len);
512 if(!IS_ERR(data->contents)) 472 if (!IS_ERR(data->contents))
513 data->host_fd = fd; 473 data->host_fd = fd;
514 } 474 } else
515 else printk("hppfs_open : failed to open a socket in " 475 printk(KERN_ERR "hppfs_open : failed to open a socket "
516 "'%s', errno = %d\n", host_file, -fd); 476 "in '%s', errno = %d\n", host_file, -fd);
517 } 477 }
518 kfree(host_file); 478 kfree(host_file);
519 479
520 file->private_data = data; 480 file->private_data = data;
521 return(0); 481 return 0;
522 482
523 out_free1: 483 out_free1:
524 kfree(host_file); 484 kfree(host_file);
@@ -526,34 +486,36 @@ static int hppfs_open(struct inode *inode, struct file *file)
526 free_contents(data->contents); 486 free_contents(data->contents);
527 kfree(data); 487 kfree(data);
528 out: 488 out:
529 return(err); 489 return err;
530} 490}
531 491
532static int hppfs_dir_open(struct inode *inode, struct file *file) 492static int hppfs_dir_open(struct inode *inode, struct file *file)
533{ 493{
534 struct hppfs_private *data; 494 struct hppfs_private *data;
535 struct dentry *proc_dentry; 495 struct dentry *proc_dentry;
496 struct vfsmount *proc_mnt;
536 int err; 497 int err;
537 498
538 err = -ENOMEM; 499 err = -ENOMEM;
539 data = hppfs_data(); 500 data = hppfs_data();
540 if(data == NULL) 501 if (data == NULL)
541 goto out; 502 goto out;
542 503
543 proc_dentry = HPPFS_I(inode)->proc_dentry; 504 proc_dentry = HPPFS_I(inode)->proc_dentry;
544 data->proc_file = dentry_open(dget(proc_dentry), NULL, 505 proc_mnt = inode->i_sb->s_fs_info;
506 data->proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt),
545 file_mode(file->f_mode)); 507 file_mode(file->f_mode));
546 err = PTR_ERR(data->proc_file); 508 err = PTR_ERR(data->proc_file);
547 if(IS_ERR(data->proc_file)) 509 if (IS_ERR(data->proc_file))
548 goto out_free; 510 goto out_free;
549 511
550 file->private_data = data; 512 file->private_data = data;
551 return(0); 513 return 0;
552 514
553 out_free: 515 out_free:
554 kfree(data); 516 kfree(data);
555 out: 517 out:
556 return(err); 518 return err;
557} 519}
558 520
559static loff_t hppfs_llseek(struct file *file, loff_t off, int where) 521static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
@@ -564,13 +526,13 @@ static loff_t hppfs_llseek(struct file *file, loff_t off, int where)
564 loff_t ret; 526 loff_t ret;
565 527
566 llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek; 528 llseek = proc_file->f_path.dentry->d_inode->i_fop->llseek;
567 if(llseek != NULL){ 529 if (llseek != NULL) {
568 ret = (*llseek)(proc_file, off, where); 530 ret = (*llseek)(proc_file, off, where);
569 if(ret < 0) 531 if (ret < 0)
570 return(ret); 532 return ret;
571 } 533 }
572 534
573 return(default_llseek(file, off, where)); 535 return default_llseek(file, off, where);
574} 536}
575 537
576static const struct file_operations hppfs_file_fops = { 538static const struct file_operations hppfs_file_fops = {
@@ -592,11 +554,11 @@ static int hppfs_filldir(void *d, const char *name, int size,
592{ 554{
593 struct hppfs_dirent *dirent = d; 555 struct hppfs_dirent *dirent = d;
594 556
595 if(file_removed(dirent->dentry, name)) 557 if (file_removed(dirent->dentry, name))
596 return(0); 558 return 0;
597 559
598 return((*dirent->filldir)(dirent->vfs_dirent, name, size, offset, 560 return (*dirent->filldir)(dirent->vfs_dirent, name, size, offset,
599 inode, type)); 561 inode, type);
600} 562}
601 563
602static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir) 564static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
@@ -607,7 +569,8 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
607 struct hppfs_dirent dirent = ((struct hppfs_dirent) 569 struct hppfs_dirent dirent = ((struct hppfs_dirent)
608 { .vfs_dirent = ent, 570 { .vfs_dirent = ent,
609 .filldir = filldir, 571 .filldir = filldir,
610 .dentry = file->f_path.dentry } ); 572 .dentry = file->f_path.dentry
573 });
611 int err; 574 int err;
612 575
613 readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir; 576 readdir = proc_file->f_path.dentry->d_inode->i_fop->readdir;
@@ -616,12 +579,12 @@ static int hppfs_readdir(struct file *file, void *ent, filldir_t filldir)
616 err = (*readdir)(proc_file, &dirent, hppfs_filldir); 579 err = (*readdir)(proc_file, &dirent, hppfs_filldir);
617 file->f_pos = proc_file->f_pos; 580 file->f_pos = proc_file->f_pos;
618 581
619 return(err); 582 return err;
620} 583}
621 584
622static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync) 585static int hppfs_fsync(struct file *file, struct dentry *dentry, int datasync)
623{ 586{
624 return(0); 587 return 0;
625} 588}
626 589
627static const struct file_operations hppfs_dir_fops = { 590static const struct file_operations hppfs_dir_fops = {
@@ -639,7 +602,7 @@ static int hppfs_statfs(struct dentry *dentry, struct kstatfs *sf)
639 sf->f_files = 0; 602 sf->f_files = 0;
640 sf->f_ffree = 0; 603 sf->f_ffree = 0;
641 sf->f_type = HPPFS_SUPER_MAGIC; 604 sf->f_type = HPPFS_SUPER_MAGIC;
642 return(0); 605 return 0;
643} 606}
644 607
645static struct inode *hppfs_alloc_inode(struct super_block *sb) 608static struct inode *hppfs_alloc_inode(struct super_block *sb)
@@ -647,12 +610,12 @@ static struct inode *hppfs_alloc_inode(struct super_block *sb)
647 struct hppfs_inode_info *hi; 610 struct hppfs_inode_info *hi;
648 611
649 hi = kmalloc(sizeof(*hi), GFP_KERNEL); 612 hi = kmalloc(sizeof(*hi), GFP_KERNEL);
650 if(hi == NULL) 613 if (!hi)
651 return(NULL); 614 return NULL;
652 615
653 *hi = ((struct hppfs_inode_info) { .proc_dentry = NULL }); 616 hi->proc_dentry = NULL;
654 inode_init_once(&hi->vfs_inode); 617 inode_init_once(&hi->vfs_inode);
655 return(&hi->vfs_inode); 618 return &hi->vfs_inode;
656} 619}
657 620
658void hppfs_delete_inode(struct inode *ino) 621void hppfs_delete_inode(struct inode *ino)
@@ -665,21 +628,31 @@ static void hppfs_destroy_inode(struct inode *inode)
665 kfree(HPPFS_I(inode)); 628 kfree(HPPFS_I(inode));
666} 629}
667 630
631static void hppfs_put_super(struct super_block *sb)
632{
633 mntput(sb->s_fs_info);
634}
635
668static const struct super_operations hppfs_sbops = { 636static const struct super_operations hppfs_sbops = {
669 .alloc_inode = hppfs_alloc_inode, 637 .alloc_inode = hppfs_alloc_inode,
670 .destroy_inode = hppfs_destroy_inode, 638 .destroy_inode = hppfs_destroy_inode,
671 .delete_inode = hppfs_delete_inode, 639 .delete_inode = hppfs_delete_inode,
672 .statfs = hppfs_statfs, 640 .statfs = hppfs_statfs,
641 .put_super = hppfs_put_super,
673}; 642};
674 643
675static int hppfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) 644static int hppfs_readlink(struct dentry *dentry, char __user *buffer,
645 int buflen)
676{ 646{
677 struct file *proc_file; 647 struct file *proc_file;
678 struct dentry *proc_dentry; 648 struct dentry *proc_dentry;
649 struct vfsmount *proc_mnt;
679 int ret; 650 int ret;
680 651
681 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 652 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
682 proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); 653 proc_mnt = dentry->d_sb->s_fs_info;
654
655 proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY);
683 if (IS_ERR(proc_file)) 656 if (IS_ERR(proc_file))
684 return PTR_ERR(proc_file); 657 return PTR_ERR(proc_file);
685 658
@@ -694,10 +667,13 @@ static void* hppfs_follow_link(struct dentry *dentry, struct nameidata *nd)
694{ 667{
695 struct file *proc_file; 668 struct file *proc_file;
696 struct dentry *proc_dentry; 669 struct dentry *proc_dentry;
670 struct vfsmount *proc_mnt;
697 void *ret; 671 void *ret;
698 672
699 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry; 673 proc_dentry = HPPFS_I(dentry->d_inode)->proc_dentry;
700 proc_file = dentry_open(dget(proc_dentry), NULL, O_RDONLY); 674 proc_mnt = dentry->d_sb->s_fs_info;
675
676 proc_file = dentry_open(dget(proc_dentry), mntget(proc_mnt), O_RDONLY);
701 if (IS_ERR(proc_file)) 677 if (IS_ERR(proc_file))
702 return proc_file; 678 return proc_file;
703 679
@@ -717,70 +693,72 @@ static const struct inode_operations hppfs_link_iops = {
717 .follow_link = hppfs_follow_link, 693 .follow_link = hppfs_follow_link,
718}; 694};
719 695
720static int init_inode(struct inode *inode, struct dentry *dentry) 696static struct inode *get_inode(struct super_block *sb, struct dentry *dentry)
721{ 697{
722 if(S_ISDIR(dentry->d_inode->i_mode)){ 698 struct inode *proc_ino = dentry->d_inode;
699 struct inode *inode = new_inode(sb);
700
701 if (!inode)
702 return ERR_PTR(-ENOMEM);
703
704 if (S_ISDIR(dentry->d_inode->i_mode)) {
723 inode->i_op = &hppfs_dir_iops; 705 inode->i_op = &hppfs_dir_iops;
724 inode->i_fop = &hppfs_dir_fops; 706 inode->i_fop = &hppfs_dir_fops;
725 } 707 } else if (S_ISLNK(dentry->d_inode->i_mode)) {
726 else if(S_ISLNK(dentry->d_inode->i_mode)){
727 inode->i_op = &hppfs_link_iops; 708 inode->i_op = &hppfs_link_iops;
728 inode->i_fop = &hppfs_file_fops; 709 inode->i_fop = &hppfs_file_fops;
729 } 710 } else {
730 else {
731 inode->i_op = &hppfs_file_iops; 711 inode->i_op = &hppfs_file_iops;
732 inode->i_fop = &hppfs_file_fops; 712 inode->i_fop = &hppfs_file_fops;
733 } 713 }
734 714
735 HPPFS_I(inode)->proc_dentry = dentry; 715 HPPFS_I(inode)->proc_dentry = dentry;
736 716
737 return(0); 717 inode->i_uid = proc_ino->i_uid;
718 inode->i_gid = proc_ino->i_gid;
719 inode->i_atime = proc_ino->i_atime;
720 inode->i_mtime = proc_ino->i_mtime;
721 inode->i_ctime = proc_ino->i_ctime;
722 inode->i_ino = proc_ino->i_ino;
723 inode->i_mode = proc_ino->i_mode;
724 inode->i_nlink = proc_ino->i_nlink;
725 inode->i_size = proc_ino->i_size;
726 inode->i_blocks = proc_ino->i_blocks;
727
728 return 0;
738} 729}
739 730
740static int hppfs_fill_super(struct super_block *sb, void *d, int silent) 731static int hppfs_fill_super(struct super_block *sb, void *d, int silent)
741{ 732{
742 struct inode *root_inode; 733 struct inode *root_inode;
743 struct file_system_type *procfs; 734 struct vfsmount *proc_mnt;
744 struct super_block *proc_sb; 735 int err = -ENOENT;
745 int err;
746 736
747 err = -ENOENT; 737 proc_mnt = do_kern_mount("proc", 0, "proc", NULL);
748 procfs = get_fs_type("proc"); 738 if (IS_ERR(proc_mnt))
749 if(procfs == NULL)
750 goto out; 739 goto out;
751 740
752 if(list_empty(&procfs->fs_supers))
753 goto out;
754
755 proc_sb = list_entry(procfs->fs_supers.next, struct super_block,
756 s_instances);
757
758 sb->s_blocksize = 1024; 741 sb->s_blocksize = 1024;
759 sb->s_blocksize_bits = 10; 742 sb->s_blocksize_bits = 10;
760 sb->s_magic = HPPFS_SUPER_MAGIC; 743 sb->s_magic = HPPFS_SUPER_MAGIC;
761 sb->s_op = &hppfs_sbops; 744 sb->s_op = &hppfs_sbops;
762 745 sb->s_fs_info = proc_mnt;
763 root_inode = hppfs_iget(sb);
764 if (IS_ERR(root_inode)) {
765 err = PTR_ERR(root_inode);
766 goto out;
767 }
768
769 err = init_inode(root_inode, proc_sb->s_root);
770 if(err)
771 goto out_put;
772 746
773 err = -ENOMEM; 747 err = -ENOMEM;
774 sb->s_root = d_alloc_root(root_inode); 748 root_inode = get_inode(sb, proc_mnt->mnt_sb->s_root);
775 if(sb->s_root == NULL) 749 if (!root_inode)
776 goto out_put; 750 goto out_mntput;
777 751
778 hppfs_read_inode(root_inode); 752 sb->s_root = d_alloc_root(root_inode);
753 if (!sb->s_root)
754 goto out_iput;
779 755
780 return(0); 756 return 0;
781 757
782 out_put: 758 out_iput:
783 iput(root_inode); 759 iput(root_inode);
760 out_mntput:
761 mntput(proc_mnt);
784 out: 762 out:
785 return(err); 763 return(err);
786} 764}
@@ -802,7 +780,7 @@ static struct file_system_type hppfs_type = {
802 780
803static int __init init_hppfs(void) 781static int __init init_hppfs(void)
804{ 782{
805 return(register_filesystem(&hppfs_type)); 783 return register_filesystem(&hppfs_type);
806} 784}
807 785
808static void __exit exit_hppfs(void) 786static void __exit exit_hppfs(void)
@@ -813,14 +791,3 @@ static void __exit exit_hppfs(void)
813module_init(init_hppfs) 791module_init(init_hppfs)
814module_exit(exit_hppfs) 792module_exit(exit_hppfs)
815MODULE_LICENSE("GPL"); 793MODULE_LICENSE("GPL");
816
817/*
818 * Overrides for Emacs so that we follow Linus's tabbing style.
819 * Emacs will notice this stuff at the end of the file and automatically
820 * adjust the settings for this buffer only. This must remain at the end
821 * of the file.
822 * ---------------------------------------------------------------------------
823 * Local variables:
824 * c-file-style: "linux"
825 * End:
826 */
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index eee9487ae47f..6846785fe904 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -954,7 +954,7 @@ struct file *hugetlb_file_setup(const char *name, size_t size)
954 FMODE_WRITE | FMODE_READ, 954 FMODE_WRITE | FMODE_READ,
955 &hugetlbfs_file_operations); 955 &hugetlbfs_file_operations);
956 if (!file) 956 if (!file)
957 goto out_inode; 957 goto out_dentry; /* inode is already attached */
958 958
959 return file; 959 return file;
960 960
diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c
index 9816293442ab..0e081d5f32e8 100644
--- a/fs/jbd/journal.c
+++ b/fs/jbd/journal.c
@@ -1620,14 +1620,14 @@ static int journal_init_journal_head_cache(void)
1620{ 1620{
1621 int retval; 1621 int retval;
1622 1622
1623 J_ASSERT(journal_head_cache == 0); 1623 J_ASSERT(journal_head_cache == NULL);
1624 journal_head_cache = kmem_cache_create("journal_head", 1624 journal_head_cache = kmem_cache_create("journal_head",
1625 sizeof(struct journal_head), 1625 sizeof(struct journal_head),
1626 0, /* offset */ 1626 0, /* offset */
1627 SLAB_TEMPORARY, /* flags */ 1627 SLAB_TEMPORARY, /* flags */
1628 NULL); /* ctor */ 1628 NULL); /* ctor */
1629 retval = 0; 1629 retval = 0;
1630 if (journal_head_cache == 0) { 1630 if (!journal_head_cache) {
1631 retval = -ENOMEM; 1631 retval = -ENOMEM;
1632 printk(KERN_EMERG "JBD: no memory for journal_head cache\n"); 1632 printk(KERN_EMERG "JBD: no memory for journal_head cache\n");
1633 } 1633 }
diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c
index ad2eacf570c6..d5f8eee7c88c 100644
--- a/fs/jbd/revoke.c
+++ b/fs/jbd/revoke.c
@@ -173,13 +173,13 @@ int __init journal_init_revoke_caches(void)
173 0, 173 0,
174 SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, 174 SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY,
175 NULL); 175 NULL);
176 if (revoke_record_cache == 0) 176 if (!revoke_record_cache)
177 return -ENOMEM; 177 return -ENOMEM;
178 178
179 revoke_table_cache = kmem_cache_create("revoke_table", 179 revoke_table_cache = kmem_cache_create("revoke_table",
180 sizeof(struct jbd_revoke_table_s), 180 sizeof(struct jbd_revoke_table_s),
181 0, SLAB_TEMPORARY, NULL); 181 0, SLAB_TEMPORARY, NULL);
182 if (revoke_table_cache == 0) { 182 if (!revoke_table_cache) {
183 kmem_cache_destroy(revoke_record_cache); 183 kmem_cache_destroy(revoke_record_cache);
184 revoke_record_cache = NULL; 184 revoke_record_cache = NULL;
185 return -ENOMEM; 185 return -ENOMEM;
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 96ba846992e9..954cff001df6 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -219,7 +219,7 @@ static int jbd2_journal_start_thread(journal_t *journal)
219 if (IS_ERR(t)) 219 if (IS_ERR(t))
220 return PTR_ERR(t); 220 return PTR_ERR(t);
221 221
222 wait_event(journal->j_wait_done_commit, journal->j_task != 0); 222 wait_event(journal->j_wait_done_commit, journal->j_task != NULL);
223 return 0; 223 return 0;
224} 224}
225 225
@@ -231,7 +231,7 @@ static void journal_kill_thread(journal_t *journal)
231 while (journal->j_task) { 231 while (journal->j_task) {
232 wake_up(&journal->j_wait_commit); 232 wake_up(&journal->j_wait_commit);
233 spin_unlock(&journal->j_state_lock); 233 spin_unlock(&journal->j_state_lock);
234 wait_event(journal->j_wait_done_commit, journal->j_task == 0); 234 wait_event(journal->j_wait_done_commit, journal->j_task == NULL);
235 spin_lock(&journal->j_state_lock); 235 spin_lock(&journal->j_state_lock);
236 } 236 }
237 spin_unlock(&journal->j_state_lock); 237 spin_unlock(&journal->j_state_lock);
@@ -1969,14 +1969,14 @@ static int journal_init_jbd2_journal_head_cache(void)
1969{ 1969{
1970 int retval; 1970 int retval;
1971 1971
1972 J_ASSERT(jbd2_journal_head_cache == 0); 1972 J_ASSERT(jbd2_journal_head_cache == NULL);
1973 jbd2_journal_head_cache = kmem_cache_create("jbd2_journal_head", 1973 jbd2_journal_head_cache = kmem_cache_create("jbd2_journal_head",
1974 sizeof(struct journal_head), 1974 sizeof(struct journal_head),
1975 0, /* offset */ 1975 0, /* offset */
1976 SLAB_TEMPORARY, /* flags */ 1976 SLAB_TEMPORARY, /* flags */
1977 NULL); /* ctor */ 1977 NULL); /* ctor */
1978 retval = 0; 1978 retval = 0;
1979 if (jbd2_journal_head_cache == 0) { 1979 if (!jbd2_journal_head_cache) {
1980 retval = -ENOMEM; 1980 retval = -ENOMEM;
1981 printk(KERN_EMERG "JBD: no memory for journal_head cache\n"); 1981 printk(KERN_EMERG "JBD: no memory for journal_head cache\n");
1982 } 1982 }
@@ -2002,14 +2002,14 @@ static struct journal_head *journal_alloc_journal_head(void)
2002 atomic_inc(&nr_journal_heads); 2002 atomic_inc(&nr_journal_heads);
2003#endif 2003#endif
2004 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS); 2004 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
2005 if (ret == 0) { 2005 if (!ret) {
2006 jbd_debug(1, "out of memory for journal_head\n"); 2006 jbd_debug(1, "out of memory for journal_head\n");
2007 if (time_after(jiffies, last_warning + 5*HZ)) { 2007 if (time_after(jiffies, last_warning + 5*HZ)) {
2008 printk(KERN_NOTICE "ENOMEM in %s, retrying.\n", 2008 printk(KERN_NOTICE "ENOMEM in %s, retrying.\n",
2009 __FUNCTION__); 2009 __FUNCTION__);
2010 last_warning = jiffies; 2010 last_warning = jiffies;
2011 } 2011 }
2012 while (ret == 0) { 2012 while (!ret) {
2013 yield(); 2013 yield();
2014 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS); 2014 ret = kmem_cache_alloc(jbd2_journal_head_cache, GFP_NOFS);
2015 } 2015 }
diff --git a/fs/jbd2/revoke.c b/fs/jbd2/revoke.c
index df36f42e19e1..2e1453a5e998 100644
--- a/fs/jbd2/revoke.c
+++ b/fs/jbd2/revoke.c
@@ -174,13 +174,13 @@ int __init jbd2_journal_init_revoke_caches(void)
174 0, 174 0,
175 SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, 175 SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY,
176 NULL); 176 NULL);
177 if (jbd2_revoke_record_cache == 0) 177 if (!jbd2_revoke_record_cache)
178 return -ENOMEM; 178 return -ENOMEM;
179 179
180 jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table", 180 jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table",
181 sizeof(struct jbd2_revoke_table_s), 181 sizeof(struct jbd2_revoke_table_s),
182 0, SLAB_TEMPORARY, NULL); 182 0, SLAB_TEMPORARY, NULL);
183 if (jbd2_revoke_table_cache == 0) { 183 if (!jbd2_revoke_table_cache) {
184 kmem_cache_destroy(jbd2_revoke_record_cache); 184 kmem_cache_destroy(jbd2_revoke_record_cache);
185 jbd2_revoke_record_cache = NULL; 185 jbd2_revoke_record_cache = NULL;
186 return -ENOMEM; 186 return -ENOMEM;
diff --git a/fs/namei.c b/fs/namei.c
index 6b7a0eef4090..8cf9bb9c2fc0 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -106,7 +106,7 @@
106 * any extra contention... 106 * any extra contention...
107 */ 107 */
108 108
109static int link_path_walk(const char *name, struct nameidata *nd); 109static int __link_path_walk(const char *name, struct nameidata *nd);
110 110
111/* In order to reduce some races, while at the same time doing additional 111/* In order to reduce some races, while at the same time doing additional
112 * checking and hopefully speeding things up, we copy filenames to the 112 * checking and hopefully speeding things up, we copy filenames to the
@@ -563,6 +563,37 @@ walk_init_root(const char *name, struct nameidata *nd)
563 return 1; 563 return 1;
564} 564}
565 565
566/*
567 * Wrapper to retry pathname resolution whenever the underlying
568 * file system returns an ESTALE.
569 *
570 * Retry the whole path once, forcing real lookup requests
571 * instead of relying on the dcache.
572 */
573static __always_inline int link_path_walk(const char *name, struct nameidata *nd)
574{
575 struct path save = nd->path;
576 int result;
577
578 /* make sure the stuff we saved doesn't go away */
579 dget(save.dentry);
580 mntget(save.mnt);
581
582 result = __link_path_walk(name, nd);
583 if (result == -ESTALE) {
584 /* nd->path had been dropped */
585 nd->path = save;
586 dget(nd->path.dentry);
587 mntget(nd->path.mnt);
588 nd->flags |= LOOKUP_REVAL;
589 result = __link_path_walk(name, nd);
590 }
591
592 path_put(&save);
593
594 return result;
595}
596
566static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link) 597static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link)
567{ 598{
568 int res = 0; 599 int res = 0;
@@ -1020,36 +1051,6 @@ return_err:
1020 return err; 1051 return err;
1021} 1052}
1022 1053
1023/*
1024 * Wrapper to retry pathname resolution whenever the underlying
1025 * file system returns an ESTALE.
1026 *
1027 * Retry the whole path once, forcing real lookup requests
1028 * instead of relying on the dcache.
1029 */
1030static int link_path_walk(const char *name, struct nameidata *nd)
1031{
1032 struct nameidata save = *nd;
1033 int result;
1034
1035 /* make sure the stuff we saved doesn't go away */
1036 dget(save.path.dentry);
1037 mntget(save.path.mnt);
1038
1039 result = __link_path_walk(name, nd);
1040 if (result == -ESTALE) {
1041 *nd = save;
1042 dget(nd->path.dentry);
1043 mntget(nd->path.mnt);
1044 nd->flags |= LOOKUP_REVAL;
1045 result = __link_path_walk(name, nd);
1046 }
1047
1048 path_put(&save.path);
1049
1050 return result;
1051}
1052
1053static int path_walk(const char *name, struct nameidata *nd) 1054static int path_walk(const char *name, struct nameidata *nd)
1054{ 1055{
1055 current->total_link_count = 0; 1056 current->total_link_count = 0;
diff --git a/fs/namespace.c b/fs/namespace.c
index 7953c96a2071..94f026ec990a 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -155,15 +155,15 @@ static void __touch_mnt_namespace(struct mnt_namespace *ns)
155 } 155 }
156} 156}
157 157
158static void detach_mnt(struct vfsmount *mnt, struct nameidata *old_nd) 158static void detach_mnt(struct vfsmount *mnt, struct path *old_path)
159{ 159{
160 old_nd->path.dentry = mnt->mnt_mountpoint; 160 old_path->dentry = mnt->mnt_mountpoint;
161 old_nd->path.mnt = mnt->mnt_parent; 161 old_path->mnt = mnt->mnt_parent;
162 mnt->mnt_parent = mnt; 162 mnt->mnt_parent = mnt;
163 mnt->mnt_mountpoint = mnt->mnt_root; 163 mnt->mnt_mountpoint = mnt->mnt_root;
164 list_del_init(&mnt->mnt_child); 164 list_del_init(&mnt->mnt_child);
165 list_del_init(&mnt->mnt_hash); 165 list_del_init(&mnt->mnt_hash);
166 old_nd->path.dentry->d_mounted--; 166 old_path->dentry->d_mounted--;
167} 167}
168 168
169void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry, 169void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
@@ -174,12 +174,12 @@ void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
174 dentry->d_mounted++; 174 dentry->d_mounted++;
175} 175}
176 176
177static void attach_mnt(struct vfsmount *mnt, struct nameidata *nd) 177static void attach_mnt(struct vfsmount *mnt, struct path *path)
178{ 178{
179 mnt_set_mountpoint(nd->path.mnt, nd->path.dentry, mnt); 179 mnt_set_mountpoint(path->mnt, path->dentry, mnt);
180 list_add_tail(&mnt->mnt_hash, mount_hashtable + 180 list_add_tail(&mnt->mnt_hash, mount_hashtable +
181 hash(nd->path.mnt, nd->path.dentry)); 181 hash(path->mnt, path->dentry));
182 list_add_tail(&mnt->mnt_child, &nd->path.mnt->mnt_mounts); 182 list_add_tail(&mnt->mnt_child, &path->mnt->mnt_mounts);
183} 183}
184 184
185/* 185/*
@@ -262,10 +262,8 @@ static struct vfsmount *clone_mnt(struct vfsmount *old, struct dentry *root,
262 /* stick the duplicate mount on the same expiry list 262 /* stick the duplicate mount on the same expiry list
263 * as the original if that was on one */ 263 * as the original if that was on one */
264 if (flag & CL_EXPIRE) { 264 if (flag & CL_EXPIRE) {
265 spin_lock(&vfsmount_lock);
266 if (!list_empty(&old->mnt_expire)) 265 if (!list_empty(&old->mnt_expire))
267 list_add(&mnt->mnt_expire, &old->mnt_expire); 266 list_add(&mnt->mnt_expire, &old->mnt_expire);
268 spin_unlock(&vfsmount_lock);
269 } 267 }
270 } 268 }
271 return mnt; 269 return mnt;
@@ -548,6 +546,7 @@ void release_mounts(struct list_head *head)
548 m = mnt->mnt_parent; 546 m = mnt->mnt_parent;
549 mnt->mnt_mountpoint = mnt->mnt_root; 547 mnt->mnt_mountpoint = mnt->mnt_root;
550 mnt->mnt_parent = mnt; 548 mnt->mnt_parent = mnt;
549 m->mnt_ghosts--;
551 spin_unlock(&vfsmount_lock); 550 spin_unlock(&vfsmount_lock);
552 dput(dentry); 551 dput(dentry);
553 mntput(m); 552 mntput(m);
@@ -572,12 +571,16 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
572 __touch_mnt_namespace(p->mnt_ns); 571 __touch_mnt_namespace(p->mnt_ns);
573 p->mnt_ns = NULL; 572 p->mnt_ns = NULL;
574 list_del_init(&p->mnt_child); 573 list_del_init(&p->mnt_child);
575 if (p->mnt_parent != p) 574 if (p->mnt_parent != p) {
575 p->mnt_parent->mnt_ghosts++;
576 p->mnt_mountpoint->d_mounted--; 576 p->mnt_mountpoint->d_mounted--;
577 }
577 change_mnt_propagation(p, MS_PRIVATE); 578 change_mnt_propagation(p, MS_PRIVATE);
578 } 579 }
579} 580}
580 581
582static void shrink_submounts(struct vfsmount *mnt, struct list_head *umounts);
583
581static int do_umount(struct vfsmount *mnt, int flags) 584static int do_umount(struct vfsmount *mnt, int flags)
582{ 585{
583 struct super_block *sb = mnt->mnt_sb; 586 struct super_block *sb = mnt->mnt_sb;
@@ -650,6 +653,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
650 spin_lock(&vfsmount_lock); 653 spin_lock(&vfsmount_lock);
651 event++; 654 event++;
652 655
656 if (!(flags & MNT_DETACH))
657 shrink_submounts(mnt, &umount_list);
658
653 retval = -EBUSY; 659 retval = -EBUSY;
654 if (flags & MNT_DETACH || !propagate_mount_busy(mnt, 2)) { 660 if (flags & MNT_DETACH || !propagate_mount_busy(mnt, 2)) {
655 if (!list_empty(&mnt->mnt_list)) 661 if (!list_empty(&mnt->mnt_list))
@@ -744,7 +750,7 @@ struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
744 int flag) 750 int flag)
745{ 751{
746 struct vfsmount *res, *p, *q, *r, *s; 752 struct vfsmount *res, *p, *q, *r, *s;
747 struct nameidata nd; 753 struct path path;
748 754
749 if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt)) 755 if (!(flag & CL_COPY_ALL) && IS_MNT_UNBINDABLE(mnt))
750 return NULL; 756 return NULL;
@@ -769,14 +775,14 @@ struct vfsmount *copy_tree(struct vfsmount *mnt, struct dentry *dentry,
769 q = q->mnt_parent; 775 q = q->mnt_parent;
770 } 776 }
771 p = s; 777 p = s;
772 nd.path.mnt = q; 778 path.mnt = q;
773 nd.path.dentry = p->mnt_mountpoint; 779 path.dentry = p->mnt_mountpoint;
774 q = clone_mnt(p, p->mnt_root, flag); 780 q = clone_mnt(p, p->mnt_root, flag);
775 if (!q) 781 if (!q)
776 goto Enomem; 782 goto Enomem;
777 spin_lock(&vfsmount_lock); 783 spin_lock(&vfsmount_lock);
778 list_add_tail(&q->mnt_list, &res->mnt_list); 784 list_add_tail(&q->mnt_list, &res->mnt_list);
779 attach_mnt(q, &nd); 785 attach_mnt(q, &path);
780 spin_unlock(&vfsmount_lock); 786 spin_unlock(&vfsmount_lock);
781 } 787 }
782 } 788 }
@@ -876,11 +882,11 @@ void drop_collected_mounts(struct vfsmount *mnt)
876 * in allocations. 882 * in allocations.
877 */ 883 */
878static int attach_recursive_mnt(struct vfsmount *source_mnt, 884static int attach_recursive_mnt(struct vfsmount *source_mnt,
879 struct nameidata *nd, struct nameidata *parent_nd) 885 struct path *path, struct path *parent_path)
880{ 886{
881 LIST_HEAD(tree_list); 887 LIST_HEAD(tree_list);
882 struct vfsmount *dest_mnt = nd->path.mnt; 888 struct vfsmount *dest_mnt = path->mnt;
883 struct dentry *dest_dentry = nd->path.dentry; 889 struct dentry *dest_dentry = path->dentry;
884 struct vfsmount *child, *p; 890 struct vfsmount *child, *p;
885 891
886 if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list)) 892 if (propagate_mnt(dest_mnt, dest_dentry, source_mnt, &tree_list))
@@ -892,9 +898,9 @@ static int attach_recursive_mnt(struct vfsmount *source_mnt,
892 } 898 }
893 899
894 spin_lock(&vfsmount_lock); 900 spin_lock(&vfsmount_lock);
895 if (parent_nd) { 901 if (parent_path) {
896 detach_mnt(source_mnt, parent_nd); 902 detach_mnt(source_mnt, parent_path);
897 attach_mnt(source_mnt, nd); 903 attach_mnt(source_mnt, path);
898 touch_mnt_namespace(current->nsproxy->mnt_ns); 904 touch_mnt_namespace(current->nsproxy->mnt_ns);
899 } else { 905 } else {
900 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt); 906 mnt_set_mountpoint(dest_mnt, dest_dentry, source_mnt);
@@ -930,7 +936,7 @@ static int graft_tree(struct vfsmount *mnt, struct nameidata *nd)
930 936
931 err = -ENOENT; 937 err = -ENOENT;
932 if (IS_ROOT(nd->path.dentry) || !d_unhashed(nd->path.dentry)) 938 if (IS_ROOT(nd->path.dentry) || !d_unhashed(nd->path.dentry))
933 err = attach_recursive_mnt(mnt, nd, NULL); 939 err = attach_recursive_mnt(mnt, &nd->path, NULL);
934out_unlock: 940out_unlock:
935 mutex_unlock(&nd->path.dentry->d_inode->i_mutex); 941 mutex_unlock(&nd->path.dentry->d_inode->i_mutex);
936 if (!err) 942 if (!err)
@@ -1059,7 +1065,8 @@ static inline int tree_contains_unbindable(struct vfsmount *mnt)
1059 */ 1065 */
1060static noinline int do_move_mount(struct nameidata *nd, char *old_name) 1066static noinline int do_move_mount(struct nameidata *nd, char *old_name)
1061{ 1067{
1062 struct nameidata old_nd, parent_nd; 1068 struct nameidata old_nd;
1069 struct path parent_path;
1063 struct vfsmount *p; 1070 struct vfsmount *p;
1064 int err = 0; 1071 int err = 0;
1065 if (!capable(CAP_SYS_ADMIN)) 1072 if (!capable(CAP_SYS_ADMIN))
@@ -1114,21 +1121,19 @@ static noinline int do_move_mount(struct nameidata *nd, char *old_name)
1114 if (p == old_nd.path.mnt) 1121 if (p == old_nd.path.mnt)
1115 goto out1; 1122 goto out1;
1116 1123
1117 err = attach_recursive_mnt(old_nd.path.mnt, nd, &parent_nd); 1124 err = attach_recursive_mnt(old_nd.path.mnt, &nd->path, &parent_path);
1118 if (err) 1125 if (err)
1119 goto out1; 1126 goto out1;
1120 1127
1121 spin_lock(&vfsmount_lock);
1122 /* if the mount is moved, it should no longer be expire 1128 /* if the mount is moved, it should no longer be expire
1123 * automatically */ 1129 * automatically */
1124 list_del_init(&old_nd.path.mnt->mnt_expire); 1130 list_del_init(&old_nd.path.mnt->mnt_expire);
1125 spin_unlock(&vfsmount_lock);
1126out1: 1131out1:
1127 mutex_unlock(&nd->path.dentry->d_inode->i_mutex); 1132 mutex_unlock(&nd->path.dentry->d_inode->i_mutex);
1128out: 1133out:
1129 up_write(&namespace_sem); 1134 up_write(&namespace_sem);
1130 if (!err) 1135 if (!err)
1131 path_put(&parent_nd.path); 1136 path_put(&parent_path);
1132 path_put(&old_nd.path); 1137 path_put(&old_nd.path);
1133 return err; 1138 return err;
1134} 1139}
@@ -1189,12 +1194,9 @@ int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
1189 if ((err = graft_tree(newmnt, nd))) 1194 if ((err = graft_tree(newmnt, nd)))
1190 goto unlock; 1195 goto unlock;
1191 1196
1192 if (fslist) { 1197 if (fslist) /* add to the specified expiration list */
1193 /* add to the specified expiration list */
1194 spin_lock(&vfsmount_lock);
1195 list_add_tail(&newmnt->mnt_expire, fslist); 1198 list_add_tail(&newmnt->mnt_expire, fslist);
1196 spin_unlock(&vfsmount_lock); 1199
1197 }
1198 up_write(&namespace_sem); 1200 up_write(&namespace_sem);
1199 return 0; 1201 return 0;
1200 1202
@@ -1206,75 +1208,6 @@ unlock:
1206 1208
1207EXPORT_SYMBOL_GPL(do_add_mount); 1209EXPORT_SYMBOL_GPL(do_add_mount);
1208 1210
1209static void expire_mount(struct vfsmount *mnt, struct list_head *mounts,
1210 struct list_head *umounts)
1211{
1212 spin_lock(&vfsmount_lock);
1213
1214 /*
1215 * Check if mount is still attached, if not, let whoever holds it deal
1216 * with the sucker
1217 */
1218 if (mnt->mnt_parent == mnt) {
1219 spin_unlock(&vfsmount_lock);
1220 return;
1221 }
1222
1223 /*
1224 * Check that it is still dead: the count should now be 2 - as
1225 * contributed by the vfsmount parent and the mntget above
1226 */
1227 if (!propagate_mount_busy(mnt, 2)) {
1228 /* delete from the namespace */
1229 touch_mnt_namespace(mnt->mnt_ns);
1230 list_del_init(&mnt->mnt_list);
1231 mnt->mnt_ns = NULL;
1232 umount_tree(mnt, 1, umounts);
1233 spin_unlock(&vfsmount_lock);
1234 } else {
1235 /*
1236 * Someone brought it back to life whilst we didn't have any
1237 * locks held so return it to the expiration list
1238 */
1239 list_add_tail(&mnt->mnt_expire, mounts);
1240 spin_unlock(&vfsmount_lock);
1241 }
1242}
1243
1244/*
1245 * go through the vfsmounts we've just consigned to the graveyard to
1246 * - check that they're still dead
1247 * - delete the vfsmount from the appropriate namespace under lock
1248 * - dispose of the corpse
1249 */
1250static void expire_mount_list(struct list_head *graveyard, struct list_head *mounts)
1251{
1252 struct mnt_namespace *ns;
1253 struct vfsmount *mnt;
1254
1255 while (!list_empty(graveyard)) {
1256 LIST_HEAD(umounts);
1257 mnt = list_first_entry(graveyard, struct vfsmount, mnt_expire);
1258 list_del_init(&mnt->mnt_expire);
1259
1260 /* don't do anything if the namespace is dead - all the
1261 * vfsmounts from it are going away anyway */
1262 ns = mnt->mnt_ns;
1263 if (!ns || !ns->root)
1264 continue;
1265 get_mnt_ns(ns);
1266
1267 spin_unlock(&vfsmount_lock);
1268 down_write(&namespace_sem);
1269 expire_mount(mnt, mounts, &umounts);
1270 up_write(&namespace_sem);
1271 release_mounts(&umounts);
1272 mntput(mnt);
1273 put_mnt_ns(ns);
1274 spin_lock(&vfsmount_lock);
1275 }
1276}
1277
1278/* 1211/*
1279 * process a list of expirable mountpoints with the intent of discarding any 1212 * process a list of expirable mountpoints with the intent of discarding any
1280 * mountpoints that aren't in use and haven't been touched since last we came 1213 * mountpoints that aren't in use and haven't been touched since last we came
@@ -1284,10 +1217,12 @@ void mark_mounts_for_expiry(struct list_head *mounts)
1284{ 1217{
1285 struct vfsmount *mnt, *next; 1218 struct vfsmount *mnt, *next;
1286 LIST_HEAD(graveyard); 1219 LIST_HEAD(graveyard);
1220 LIST_HEAD(umounts);
1287 1221
1288 if (list_empty(mounts)) 1222 if (list_empty(mounts))
1289 return; 1223 return;
1290 1224
1225 down_write(&namespace_sem);
1291 spin_lock(&vfsmount_lock); 1226 spin_lock(&vfsmount_lock);
1292 1227
1293 /* extract from the expiration list every vfsmount that matches the 1228 /* extract from the expiration list every vfsmount that matches the
@@ -1298,16 +1233,19 @@ void mark_mounts_for_expiry(struct list_head *mounts)
1298 */ 1233 */
1299 list_for_each_entry_safe(mnt, next, mounts, mnt_expire) { 1234 list_for_each_entry_safe(mnt, next, mounts, mnt_expire) {
1300 if (!xchg(&mnt->mnt_expiry_mark, 1) || 1235 if (!xchg(&mnt->mnt_expiry_mark, 1) ||
1301 atomic_read(&mnt->mnt_count) != 1) 1236 propagate_mount_busy(mnt, 1))
1302 continue; 1237 continue;
1303
1304 mntget(mnt);
1305 list_move(&mnt->mnt_expire, &graveyard); 1238 list_move(&mnt->mnt_expire, &graveyard);
1306 } 1239 }
1307 1240 while (!list_empty(&graveyard)) {
1308 expire_mount_list(&graveyard, mounts); 1241 mnt = list_first_entry(&graveyard, struct vfsmount, mnt_expire);
1309 1242 touch_mnt_namespace(mnt->mnt_ns);
1243 umount_tree(mnt, 1, &umounts);
1244 }
1310 spin_unlock(&vfsmount_lock); 1245 spin_unlock(&vfsmount_lock);
1246 up_write(&namespace_sem);
1247
1248 release_mounts(&umounts);
1311} 1249}
1312 1250
1313EXPORT_SYMBOL_GPL(mark_mounts_for_expiry); 1251EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
@@ -1343,7 +1281,6 @@ resume:
1343 } 1281 }
1344 1282
1345 if (!propagate_mount_busy(mnt, 1)) { 1283 if (!propagate_mount_busy(mnt, 1)) {
1346 mntget(mnt);
1347 list_move_tail(&mnt->mnt_expire, graveyard); 1284 list_move_tail(&mnt->mnt_expire, graveyard);
1348 found++; 1285 found++;
1349 } 1286 }
@@ -1363,22 +1300,22 @@ resume:
1363 * process a list of expirable mountpoints with the intent of discarding any 1300 * process a list of expirable mountpoints with the intent of discarding any
1364 * submounts of a specific parent mountpoint 1301 * submounts of a specific parent mountpoint
1365 */ 1302 */
1366void shrink_submounts(struct vfsmount *mountpoint, struct list_head *mounts) 1303static void shrink_submounts(struct vfsmount *mnt, struct list_head *umounts)
1367{ 1304{
1368 LIST_HEAD(graveyard); 1305 LIST_HEAD(graveyard);
1369 int found; 1306 struct vfsmount *m;
1370
1371 spin_lock(&vfsmount_lock);
1372 1307
1373 /* extract submounts of 'mountpoint' from the expiration list */ 1308 /* extract submounts of 'mountpoint' from the expiration list */
1374 while ((found = select_submounts(mountpoint, &graveyard)) != 0) 1309 while (select_submounts(mnt, &graveyard)) {
1375 expire_mount_list(&graveyard, mounts); 1310 while (!list_empty(&graveyard)) {
1376 1311 m = list_first_entry(&graveyard, struct vfsmount,
1377 spin_unlock(&vfsmount_lock); 1312 mnt_expire);
1313 touch_mnt_namespace(mnt->mnt_ns);
1314 umount_tree(mnt, 1, umounts);
1315 }
1316 }
1378} 1317}
1379 1318
1380EXPORT_SYMBOL_GPL(shrink_submounts);
1381
1382/* 1319/*
1383 * Some copy_from_user() implementations do not return the exact number of 1320 * Some copy_from_user() implementations do not return the exact number of
1384 * bytes remaining to copy on a fault. But copy_mount_options() requires that. 1321 * bytes remaining to copy on a fault. But copy_mount_options() requires that.
@@ -1683,7 +1620,7 @@ void set_fs_pwd(struct fs_struct *fs, struct path *path)
1683 path_put(&old_pwd); 1620 path_put(&old_pwd);
1684} 1621}
1685 1622
1686static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd) 1623static void chroot_fs_refs(struct path *old_root, struct path *new_root)
1687{ 1624{
1688 struct task_struct *g, *p; 1625 struct task_struct *g, *p;
1689 struct fs_struct *fs; 1626 struct fs_struct *fs;
@@ -1695,12 +1632,12 @@ static void chroot_fs_refs(struct nameidata *old_nd, struct nameidata *new_nd)
1695 if (fs) { 1632 if (fs) {
1696 atomic_inc(&fs->count); 1633 atomic_inc(&fs->count);
1697 task_unlock(p); 1634 task_unlock(p);
1698 if (fs->root.dentry == old_nd->path.dentry 1635 if (fs->root.dentry == old_root->dentry
1699 && fs->root.mnt == old_nd->path.mnt) 1636 && fs->root.mnt == old_root->mnt)
1700 set_fs_root(fs, &new_nd->path); 1637 set_fs_root(fs, new_root);
1701 if (fs->pwd.dentry == old_nd->path.dentry 1638 if (fs->pwd.dentry == old_root->dentry
1702 && fs->pwd.mnt == old_nd->path.mnt) 1639 && fs->pwd.mnt == old_root->mnt)
1703 set_fs_pwd(fs, &new_nd->path); 1640 set_fs_pwd(fs, new_root);
1704 put_fs_struct(fs); 1641 put_fs_struct(fs);
1705 } else 1642 } else
1706 task_unlock(p); 1643 task_unlock(p);
@@ -1737,7 +1674,8 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
1737 const char __user * put_old) 1674 const char __user * put_old)
1738{ 1675{
1739 struct vfsmount *tmp; 1676 struct vfsmount *tmp;
1740 struct nameidata new_nd, old_nd, parent_nd, root_parent, user_nd; 1677 struct nameidata new_nd, old_nd, user_nd;
1678 struct path parent_path, root_parent;
1741 int error; 1679 int error;
1742 1680
1743 if (!capable(CAP_SYS_ADMIN)) 1681 if (!capable(CAP_SYS_ADMIN))
@@ -1811,19 +1749,19 @@ asmlinkage long sys_pivot_root(const char __user * new_root,
1811 goto out3; 1749 goto out3;
1812 } else if (!is_subdir(old_nd.path.dentry, new_nd.path.dentry)) 1750 } else if (!is_subdir(old_nd.path.dentry, new_nd.path.dentry))
1813 goto out3; 1751 goto out3;
1814 detach_mnt(new_nd.path.mnt, &parent_nd); 1752 detach_mnt(new_nd.path.mnt, &parent_path);
1815 detach_mnt(user_nd.path.mnt, &root_parent); 1753 detach_mnt(user_nd.path.mnt, &root_parent);
1816 /* mount old root on put_old */ 1754 /* mount old root on put_old */
1817 attach_mnt(user_nd.path.mnt, &old_nd); 1755 attach_mnt(user_nd.path.mnt, &old_nd.path);
1818 /* mount new_root on / */ 1756 /* mount new_root on / */
1819 attach_mnt(new_nd.path.mnt, &root_parent); 1757 attach_mnt(new_nd.path.mnt, &root_parent);
1820 touch_mnt_namespace(current->nsproxy->mnt_ns); 1758 touch_mnt_namespace(current->nsproxy->mnt_ns);
1821 spin_unlock(&vfsmount_lock); 1759 spin_unlock(&vfsmount_lock);
1822 chroot_fs_refs(&user_nd, &new_nd); 1760 chroot_fs_refs(&user_nd.path, &new_nd.path);
1823 security_sb_post_pivotroot(&user_nd, &new_nd); 1761 security_sb_post_pivotroot(&user_nd, &new_nd);
1824 error = 0; 1762 error = 0;
1825 path_put(&root_parent.path); 1763 path_put(&root_parent);
1826 path_put(&parent_nd.path); 1764 path_put(&parent_path);
1827out2: 1765out2:
1828 mutex_unlock(&old_nd.path.dentry->d_inode->i_mutex); 1766 mutex_unlock(&old_nd.path.dentry->d_inode->i_mutex);
1829 up_write(&namespace_sem); 1767 up_write(&namespace_sem);
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index ef57a5ae5904..5d2e9d9a4e28 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -64,7 +64,11 @@ const struct file_operations nfs_file_operations = {
64 .write = do_sync_write, 64 .write = do_sync_write,
65 .aio_read = nfs_file_read, 65 .aio_read = nfs_file_read,
66 .aio_write = nfs_file_write, 66 .aio_write = nfs_file_write,
67#ifdef CONFIG_MMU
67 .mmap = nfs_file_mmap, 68 .mmap = nfs_file_mmap,
69#else
70 .mmap = generic_file_mmap,
71#endif
68 .open = nfs_file_open, 72 .open = nfs_file_open,
69 .flush = nfs_file_flush, 73 .flush = nfs_file_flush,
70 .release = nfs_file_release, 74 .release = nfs_file_release,
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index a4c7cf2bff3a..6f88d7c77ac9 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -506,6 +506,7 @@ static struct nfs_open_context *alloc_nfs_open_context(struct vfsmount *mnt, str
506 ctx->cred = get_rpccred(cred); 506 ctx->cred = get_rpccred(cred);
507 ctx->state = NULL; 507 ctx->state = NULL;
508 ctx->lockowner = current->files; 508 ctx->lockowner = current->files;
509 ctx->flags = 0;
509 ctx->error = 0; 510 ctx->error = 0;
510 ctx->dir_cookie = 0; 511 ctx->dir_cookie = 0;
511 atomic_set(&ctx->count, 1); 512 atomic_set(&ctx->count, 1);
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index dd4dfcd632ec..f9219024f31a 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -589,8 +589,6 @@ static void nfs_umount_begin(struct vfsmount *vfsmnt, int flags)
589 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb); 589 struct nfs_server *server = NFS_SB(vfsmnt->mnt_sb);
590 struct rpc_clnt *rpc; 590 struct rpc_clnt *rpc;
591 591
592 shrink_submounts(vfsmnt, &nfs_automount_list);
593
594 if (!(flags & MNT_FORCE)) 592 if (!(flags & MNT_FORCE))
595 return; 593 return;
596 /* -EIO all pending I/O */ 594 /* -EIO all pending I/O */
diff --git a/fs/open.c b/fs/open.c
index 54198538b67e..3fa4e4ffce4c 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -335,7 +335,7 @@ asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length)
335{ 335{
336 long ret = do_sys_ftruncate(fd, length, 1); 336 long ret = do_sys_ftruncate(fd, length, 1);
337 /* avoid REGPARM breakage on x86: */ 337 /* avoid REGPARM breakage on x86: */
338 prevent_tail_call(ret); 338 asmlinkage_protect(2, ret, fd, length);
339 return ret; 339 return ret;
340} 340}
341 341
@@ -350,7 +350,7 @@ asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length)
350{ 350{
351 long ret = do_sys_ftruncate(fd, length, 0); 351 long ret = do_sys_ftruncate(fd, length, 0);
352 /* avoid REGPARM breakage on x86: */ 352 /* avoid REGPARM breakage on x86: */
353 prevent_tail_call(ret); 353 asmlinkage_protect(2, ret, fd, length);
354 return ret; 354 return ret;
355} 355}
356#endif 356#endif
@@ -903,6 +903,18 @@ struct file *dentry_open(struct dentry *dentry, struct vfsmount *mnt, int flags)
903 int error; 903 int error;
904 struct file *f; 904 struct file *f;
905 905
906 /*
907 * We must always pass in a valid mount pointer. Historically
908 * callers got away with not passing it, but we must enforce this at
909 * the earliest possible point now to avoid strange problems deep in the
910 * filesystem stack.
911 */
912 if (!mnt) {
913 printk(KERN_WARNING "%s called with NULL vfsmount\n", __func__);
914 dump_stack();
915 return ERR_PTR(-EINVAL);
916 }
917
906 error = -ENFILE; 918 error = -ENFILE;
907 f = get_empty_filp(); 919 f = get_empty_filp();
908 if (f == NULL) { 920 if (f == NULL) {
@@ -1055,7 +1067,7 @@ asmlinkage long sys_open(const char __user *filename, int flags, int mode)
1055 1067
1056 ret = do_sys_open(AT_FDCWD, filename, flags, mode); 1068 ret = do_sys_open(AT_FDCWD, filename, flags, mode);
1057 /* avoid REGPARM breakage on x86: */ 1069 /* avoid REGPARM breakage on x86: */
1058 prevent_tail_call(ret); 1070 asmlinkage_protect(3, ret, filename, flags, mode);
1059 return ret; 1071 return ret;
1060} 1072}
1061 1073
@@ -1069,7 +1081,7 @@ asmlinkage long sys_openat(int dfd, const char __user *filename, int flags,
1069 1081
1070 ret = do_sys_open(dfd, filename, flags, mode); 1082 ret = do_sys_open(dfd, filename, flags, mode);
1071 /* avoid REGPARM breakage on x86: */ 1083 /* avoid REGPARM breakage on x86: */
1072 prevent_tail_call(ret); 1084 asmlinkage_protect(4, ret, dfd, filename, flags, mode);
1073 return ret; 1085 return ret;
1074} 1086}
1075 1087
diff --git a/fs/pipe.c b/fs/pipe.c
index 3c185b6527bc..8be381bbcb54 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -957,13 +957,10 @@ struct file *create_write_pipe(void)
957 struct dentry *dentry; 957 struct dentry *dentry;
958 struct qstr name = { .name = "" }; 958 struct qstr name = { .name = "" };
959 959
960 f = get_empty_filp();
961 if (!f)
962 return ERR_PTR(-ENFILE);
963 err = -ENFILE; 960 err = -ENFILE;
964 inode = get_pipe_inode(); 961 inode = get_pipe_inode();
965 if (!inode) 962 if (!inode)
966 goto err_file; 963 goto err;
967 964
968 err = -ENOMEM; 965 err = -ENOMEM;
969 dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &name); 966 dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &name);
@@ -978,22 +975,24 @@ struct file *create_write_pipe(void)
978 */ 975 */
979 dentry->d_flags &= ~DCACHE_UNHASHED; 976 dentry->d_flags &= ~DCACHE_UNHASHED;
980 d_instantiate(dentry, inode); 977 d_instantiate(dentry, inode);
981 f->f_path.mnt = mntget(pipe_mnt); 978
982 f->f_path.dentry = dentry; 979 err = -ENFILE;
980 f = alloc_file(pipe_mnt, dentry, FMODE_WRITE, &write_pipe_fops);
981 if (!f)
982 goto err_dentry;
983 f->f_mapping = inode->i_mapping; 983 f->f_mapping = inode->i_mapping;
984 984
985 f->f_flags = O_WRONLY; 985 f->f_flags = O_WRONLY;
986 f->f_op = &write_pipe_fops;
987 f->f_mode = FMODE_WRITE;
988 f->f_version = 0; 986 f->f_version = 0;
989 987
990 return f; 988 return f;
991 989
990 err_dentry:
991 dput(dentry);
992 err_inode: 992 err_inode:
993 free_pipe_info(inode); 993 free_pipe_info(inode);
994 iput(inode); 994 iput(inode);
995 err_file: 995 err:
996 put_filp(f);
997 return ERR_PTR(err); 996 return ERR_PTR(err);
998} 997}
999 998
diff --git a/fs/pnode.c b/fs/pnode.c
index 05ba692bc540..1d8f5447f3f7 100644
--- a/fs/pnode.c
+++ b/fs/pnode.c
@@ -225,7 +225,7 @@ out:
225 */ 225 */
226static inline int do_refcount_check(struct vfsmount *mnt, int count) 226static inline int do_refcount_check(struct vfsmount *mnt, int count)
227{ 227{
228 int mycount = atomic_read(&mnt->mnt_count); 228 int mycount = atomic_read(&mnt->mnt_count) - mnt->mnt_ghosts;
229 return (mycount > count); 229 return (mycount > count);
230} 230}
231 231
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index f85c5cf4934c..7ee4208793b6 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -283,7 +283,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
283 return balance_leaf_when_delete(tb, flag); 283 return balance_leaf_when_delete(tb, flag);
284 284
285 zeros_num = 0; 285 zeros_num = 0;
286 if (flag == M_INSERT && body == 0) 286 if (flag == M_INSERT && !body)
287 zeros_num = ih_item_len(ih); 287 zeros_num = ih_item_len(ih);
288 288
289 pos_in_item = tb->tb_path->pos_in_item; 289 pos_in_item = tb->tb_path->pos_in_item;
@@ -1728,7 +1728,7 @@ struct buffer_head *get_FEB(struct tree_balance *tb)
1728 struct buffer_info bi; 1728 struct buffer_info bi;
1729 1729
1730 for (i = 0; i < MAX_FEB_SIZE; i++) 1730 for (i = 0; i < MAX_FEB_SIZE; i++)
1731 if (tb->FEB[i] != 0) 1731 if (tb->FEB[i] != NULL)
1732 break; 1732 break;
1733 1733
1734 if (i == MAX_FEB_SIZE) 1734 if (i == MAX_FEB_SIZE)
@@ -1827,7 +1827,7 @@ int get_left_neighbor_position(struct tree_balance *tb, int h)
1827{ 1827{
1828 int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1); 1828 int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1);
1829 1829
1830 RFALSE(PATH_H_PPARENT(tb->tb_path, h) == 0 || tb->FL[h] == 0, 1830 RFALSE(PATH_H_PPARENT(tb->tb_path, h) == NULL || tb->FL[h] == NULL,
1831 "vs-12325: FL[%d](%p) or F[%d](%p) does not exist", 1831 "vs-12325: FL[%d](%p) or F[%d](%p) does not exist",
1832 h, tb->FL[h], h, PATH_H_PPARENT(tb->tb_path, h)); 1832 h, tb->FL[h], h, PATH_H_PPARENT(tb->tb_path, h));
1833 1833
@@ -1841,7 +1841,7 @@ int get_right_neighbor_position(struct tree_balance *tb, int h)
1841{ 1841{
1842 int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1); 1842 int Sh_position = PATH_H_POSITION(tb->tb_path, h + 1);
1843 1843
1844 RFALSE(PATH_H_PPARENT(tb->tb_path, h) == 0 || tb->FR[h] == 0, 1844 RFALSE(PATH_H_PPARENT(tb->tb_path, h) == NULL || tb->FR[h] == NULL,
1845 "vs-12330: F[%d](%p) or FR[%d](%p) does not exist", 1845 "vs-12330: F[%d](%p) or FR[%d](%p) does not exist",
1846 h, PATH_H_PPARENT(tb->tb_path, h), h, tb->FR[h]); 1846 h, PATH_H_PPARENT(tb->tb_path, h), h, tb->FR[h]);
1847 1847
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index 0ee35c6c9b72..07d05e0842b7 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -153,7 +153,7 @@ static void create_virtual_node(struct tree_balance *tb, int h)
153 if (vn->vn_mode == M_INSERT) { 153 if (vn->vn_mode == M_INSERT) {
154 struct virtual_item *vi = vn->vn_vi + vn->vn_affected_item_num; 154 struct virtual_item *vi = vn->vn_vi + vn->vn_affected_item_num;
155 155
156 RFALSE(vn->vn_ins_ih == 0, 156 RFALSE(vn->vn_ins_ih == NULL,
157 "vs-8040: item header of inserted item is not specified"); 157 "vs-8040: item header of inserted item is not specified");
158 vi->vi_item_len = tb->insert_size[0]; 158 vi->vi_item_len = tb->insert_size[0];
159 vi->vi_ih = vn->vn_ins_ih; 159 vi->vi_ih = vn->vn_ins_ih;
@@ -857,7 +857,8 @@ static int get_lfree(struct tree_balance *tb, int h)
857 struct buffer_head *l, *f; 857 struct buffer_head *l, *f;
858 int order; 858 int order;
859 859
860 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == 0 || (l = tb->FL[h]) == 0) 860 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL ||
861 (l = tb->FL[h]) == NULL)
861 return 0; 862 return 0;
862 863
863 if (f == l) 864 if (f == l)
@@ -878,7 +879,8 @@ static int get_rfree(struct tree_balance *tb, int h)
878 struct buffer_head *r, *f; 879 struct buffer_head *r, *f;
879 int order; 880 int order;
880 881
881 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == 0 || (r = tb->FR[h]) == 0) 882 if ((f = PATH_H_PPARENT(tb->tb_path, h)) == NULL ||
883 (r = tb->FR[h]) == NULL)
882 return 0; 884 return 0;
883 885
884 if (f == r) 886 if (f == r)
diff --git a/fs/reiserfs/lbalance.c b/fs/reiserfs/lbalance.c
index 281f8061ac58..6de060a6aa7f 100644
--- a/fs/reiserfs/lbalance.c
+++ b/fs/reiserfs/lbalance.c
@@ -626,7 +626,7 @@ static void leaf_define_dest_src_infos(int shift_mode, struct tree_balance *tb,
626 "vs-10250: leaf_define_dest_src_infos: shift type is unknown (%d)", 626 "vs-10250: leaf_define_dest_src_infos: shift type is unknown (%d)",
627 shift_mode); 627 shift_mode);
628 } 628 }
629 RFALSE(src_bi->bi_bh == 0 || dest_bi->bi_bh == 0, 629 RFALSE(!src_bi->bi_bh || !dest_bi->bi_bh,
630 "vs-10260: mode==%d, source (%p) or dest (%p) buffer is initialized incorrectly", 630 "vs-10260: mode==%d, source (%p) or dest (%p) buffer is initialized incorrectly",
631 shift_mode, src_bi->bi_bh, dest_bi->bi_bh); 631 shift_mode, src_bi->bi_bh, dest_bi->bi_bh);
632} 632}
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index b378eea332ca..8867533cb727 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -452,7 +452,7 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
452 buflen = DEH_SIZE + ROUND_UP(namelen); 452 buflen = DEH_SIZE + ROUND_UP(namelen);
453 if (buflen > sizeof(small_buf)) { 453 if (buflen > sizeof(small_buf)) {
454 buffer = kmalloc(buflen, GFP_NOFS); 454 buffer = kmalloc(buflen, GFP_NOFS);
455 if (buffer == 0) 455 if (!buffer)
456 return -ENOMEM; 456 return -ENOMEM;
457 } else 457 } else
458 buffer = small_buf; 458 buffer = small_buf;
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index eba037b3338f..344b9b96cc56 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -191,28 +191,11 @@ static struct dentry *get_xa_file_dentry(const struct inode *inode,
191 dput(xadir); 191 dput(xadir);
192 if (err) 192 if (err)
193 xafile = ERR_PTR(err); 193 xafile = ERR_PTR(err);
194 return xafile;
195}
196
197/* Opens a file pointer to the attribute associated with inode */
198static struct file *open_xa_file(const struct inode *inode, const char *name,
199 int flags)
200{
201 struct dentry *xafile;
202 struct file *fp;
203
204 xafile = get_xa_file_dentry(inode, name, flags);
205 if (IS_ERR(xafile))
206 return ERR_PTR(PTR_ERR(xafile));
207 else if (!xafile->d_inode) { 194 else if (!xafile->d_inode) {
208 dput(xafile); 195 dput(xafile);
209 return ERR_PTR(-ENODATA); 196 xafile = ERR_PTR(-ENODATA);
210 } 197 }
211 198 return xafile;
212 fp = dentry_open(xafile, NULL, O_RDWR);
213 /* dentry_open dputs the dentry if it fails */
214
215 return fp;
216} 199}
217 200
218/* 201/*
@@ -228,9 +211,8 @@ static struct file *open_xa_file(const struct inode *inode, const char *name,
228 * we're called with i_mutex held, so there are no worries about the directory 211 * we're called with i_mutex held, so there are no worries about the directory
229 * changing underneath us. 212 * changing underneath us.
230 */ 213 */
231static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir) 214static int __xattr_readdir(struct inode *inode, void *dirent, filldir_t filldir)
232{ 215{
233 struct inode *inode = filp->f_path.dentry->d_inode;
234 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 216 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
235 INITIALIZE_PATH(path_to_entry); 217 INITIALIZE_PATH(path_to_entry);
236 struct buffer_head *bh; 218 struct buffer_head *bh;
@@ -374,23 +356,16 @@ static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
374 * 356 *
375 */ 357 */
376static 358static
377int xattr_readdir(struct file *file, filldir_t filler, void *buf) 359int xattr_readdir(struct inode *inode, filldir_t filler, void *buf)
378{ 360{
379 struct inode *inode = file->f_path.dentry->d_inode; 361 int res = -ENOENT;
380 int res = -ENOTDIR;
381 if (!file->f_op || !file->f_op->readdir)
382 goto out;
383 mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR); 362 mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR);
384// down(&inode->i_zombie);
385 res = -ENOENT;
386 if (!IS_DEADDIR(inode)) { 363 if (!IS_DEADDIR(inode)) {
387 lock_kernel(); 364 lock_kernel();
388 res = __xattr_readdir(file, buf, filler); 365 res = __xattr_readdir(inode, buf, filler);
389 unlock_kernel(); 366 unlock_kernel();
390 } 367 }
391// up(&inode->i_zombie);
392 mutex_unlock(&inode->i_mutex); 368 mutex_unlock(&inode->i_mutex);
393 out:
394 return res; 369 return res;
395} 370}
396 371
@@ -442,7 +417,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
442 size_t buffer_size, int flags) 417 size_t buffer_size, int flags)
443{ 418{
444 int err = 0; 419 int err = 0;
445 struct file *fp; 420 struct dentry *dentry;
446 struct page *page; 421 struct page *page;
447 char *data; 422 char *data;
448 struct address_space *mapping; 423 struct address_space *mapping;
@@ -460,18 +435,18 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
460 xahash = xattr_hash(buffer, buffer_size); 435 xahash = xattr_hash(buffer, buffer_size);
461 436
462 open_file: 437 open_file:
463 fp = open_xa_file(inode, name, flags); 438 dentry = get_xa_file_dentry(inode, name, flags);
464 if (IS_ERR(fp)) { 439 if (IS_ERR(dentry)) {
465 err = PTR_ERR(fp); 440 err = PTR_ERR(dentry);
466 goto out; 441 goto out;
467 } 442 }
468 443
469 xinode = fp->f_path.dentry->d_inode; 444 xinode = dentry->d_inode;
470 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 445 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
471 446
472 /* we need to copy it off.. */ 447 /* we need to copy it off.. */
473 if (xinode->i_nlink > 1) { 448 if (xinode->i_nlink > 1) {
474 fput(fp); 449 dput(dentry);
475 err = reiserfs_xattr_del(inode, name); 450 err = reiserfs_xattr_del(inode, name);
476 if (err < 0) 451 if (err < 0)
477 goto out; 452 goto out;
@@ -485,7 +460,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
485 newattrs.ia_size = buffer_size; 460 newattrs.ia_size = buffer_size;
486 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME; 461 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
487 mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR); 462 mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR);
488 err = notify_change(fp->f_path.dentry, &newattrs); 463 err = notify_change(dentry, &newattrs);
489 if (err) 464 if (err)
490 goto out_filp; 465 goto out_filp;
491 466
@@ -518,15 +493,14 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
518 rxh->h_hash = cpu_to_le32(xahash); 493 rxh->h_hash = cpu_to_le32(xahash);
519 } 494 }
520 495
521 err = reiserfs_prepare_write(fp, page, page_offset, 496 err = reiserfs_prepare_write(NULL, page, page_offset,
522 page_offset + chunk + skip); 497 page_offset + chunk + skip);
523 if (!err) { 498 if (!err) {
524 if (buffer) 499 if (buffer)
525 memcpy(data + skip, buffer + buffer_pos, chunk); 500 memcpy(data + skip, buffer + buffer_pos, chunk);
526 err = 501 err = reiserfs_commit_write(NULL, page, page_offset,
527 reiserfs_commit_write(fp, page, page_offset, 502 page_offset + chunk +
528 page_offset + chunk + 503 skip);
529 skip);
530 } 504 }
531 unlock_page(page); 505 unlock_page(page);
532 reiserfs_put_page(page); 506 reiserfs_put_page(page);
@@ -548,7 +522,7 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
548 522
549 out_filp: 523 out_filp:
550 mutex_unlock(&xinode->i_mutex); 524 mutex_unlock(&xinode->i_mutex);
551 fput(fp); 525 dput(dentry);
552 526
553 out: 527 out:
554 return err; 528 return err;
@@ -562,7 +536,7 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
562 size_t buffer_size) 536 size_t buffer_size)
563{ 537{
564 ssize_t err = 0; 538 ssize_t err = 0;
565 struct file *fp; 539 struct dentry *dentry;
566 size_t isize; 540 size_t isize;
567 size_t file_pos = 0; 541 size_t file_pos = 0;
568 size_t buffer_pos = 0; 542 size_t buffer_pos = 0;
@@ -578,13 +552,13 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
578 if (get_inode_sd_version(inode) == STAT_DATA_V1) 552 if (get_inode_sd_version(inode) == STAT_DATA_V1)
579 return -EOPNOTSUPP; 553 return -EOPNOTSUPP;
580 554
581 fp = open_xa_file(inode, name, FL_READONLY); 555 dentry = get_xa_file_dentry(inode, name, FL_READONLY);
582 if (IS_ERR(fp)) { 556 if (IS_ERR(dentry)) {
583 err = PTR_ERR(fp); 557 err = PTR_ERR(dentry);
584 goto out; 558 goto out;
585 } 559 }
586 560
587 xinode = fp->f_path.dentry->d_inode; 561 xinode = dentry->d_inode;
588 isize = xinode->i_size; 562 isize = xinode->i_size;
589 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 563 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
590 564
@@ -652,7 +626,7 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
652 } 626 }
653 627
654 out_dput: 628 out_dput:
655 fput(fp); 629 dput(dentry);
656 630
657 out: 631 out:
658 return err; 632 return err;
@@ -742,7 +716,6 @@ reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
742/* This is called w/ inode->i_mutex downed */ 716/* This is called w/ inode->i_mutex downed */
743int reiserfs_delete_xattrs(struct inode *inode) 717int reiserfs_delete_xattrs(struct inode *inode)
744{ 718{
745 struct file *fp;
746 struct dentry *dir, *root; 719 struct dentry *dir, *root;
747 int err = 0; 720 int err = 0;
748 721
@@ -763,15 +736,8 @@ int reiserfs_delete_xattrs(struct inode *inode)
763 return 0; 736 return 0;
764 } 737 }
765 738
766 fp = dentry_open(dir, NULL, O_RDWR);
767 if (IS_ERR(fp)) {
768 err = PTR_ERR(fp);
769 /* dentry_open dputs the dentry if it fails */
770 goto out;
771 }
772
773 lock_kernel(); 739 lock_kernel();
774 err = xattr_readdir(fp, reiserfs_delete_xattrs_filler, dir); 740 err = xattr_readdir(dir->d_inode, reiserfs_delete_xattrs_filler, dir);
775 if (err) { 741 if (err) {
776 unlock_kernel(); 742 unlock_kernel();
777 goto out_dir; 743 goto out_dir;
@@ -791,7 +757,7 @@ int reiserfs_delete_xattrs(struct inode *inode)
791 unlock_kernel(); 757 unlock_kernel();
792 758
793 out_dir: 759 out_dir:
794 fput(fp); 760 dput(dir);
795 761
796 out: 762 out:
797 if (!err) 763 if (!err)
@@ -833,7 +799,6 @@ reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen,
833 799
834int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs) 800int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
835{ 801{
836 struct file *fp;
837 struct dentry *dir; 802 struct dentry *dir;
838 int err = 0; 803 int err = 0;
839 struct reiserfs_chown_buf buf; 804 struct reiserfs_chown_buf buf;
@@ -857,13 +822,6 @@ int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
857 goto out; 822 goto out;
858 } 823 }
859 824
860 fp = dentry_open(dir, NULL, O_RDWR);
861 if (IS_ERR(fp)) {
862 err = PTR_ERR(fp);
863 /* dentry_open dputs the dentry if it fails */
864 goto out;
865 }
866
867 lock_kernel(); 825 lock_kernel();
868 826
869 attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME); 827 attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
@@ -871,7 +829,7 @@ int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
871 buf.attrs = attrs; 829 buf.attrs = attrs;
872 buf.inode = inode; 830 buf.inode = inode;
873 831
874 err = xattr_readdir(fp, reiserfs_chown_xattrs_filler, &buf); 832 err = xattr_readdir(dir->d_inode, reiserfs_chown_xattrs_filler, &buf);
875 if (err) { 833 if (err) {
876 unlock_kernel(); 834 unlock_kernel();
877 goto out_dir; 835 goto out_dir;
@@ -881,7 +839,7 @@ int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
881 unlock_kernel(); 839 unlock_kernel();
882 840
883 out_dir: 841 out_dir:
884 fput(fp); 842 dput(dir);
885 843
886 out: 844 out:
887 attrs->ia_valid = ia_valid; 845 attrs->ia_valid = ia_valid;
@@ -1029,7 +987,6 @@ reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
1029 */ 987 */
1030ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) 988ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
1031{ 989{
1032 struct file *fp;
1033 struct dentry *dir; 990 struct dentry *dir;
1034 int err = 0; 991 int err = 0;
1035 struct reiserfs_listxattr_buf buf; 992 struct reiserfs_listxattr_buf buf;
@@ -1052,13 +1009,6 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
1052 goto out; 1009 goto out;
1053 } 1010 }
1054 1011
1055 fp = dentry_open(dir, NULL, O_RDWR);
1056 if (IS_ERR(fp)) {
1057 err = PTR_ERR(fp);
1058 /* dentry_open dputs the dentry if it fails */
1059 goto out;
1060 }
1061
1062 buf.r_buf = buffer; 1012 buf.r_buf = buffer;
1063 buf.r_size = buffer ? size : 0; 1013 buf.r_size = buffer ? size : 0;
1064 buf.r_pos = 0; 1014 buf.r_pos = 0;
@@ -1066,7 +1016,7 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
1066 1016
1067 REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir; 1017 REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir;
1068 1018
1069 err = xattr_readdir(fp, reiserfs_listxattr_filler, &buf); 1019 err = xattr_readdir(dir->d_inode, reiserfs_listxattr_filler, &buf);
1070 if (err) 1020 if (err)
1071 goto out_dir; 1021 goto out_dir;
1072 1022
@@ -1076,7 +1026,7 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
1076 err = buf.r_pos; 1026 err = buf.r_pos;
1077 1027
1078 out_dir: 1028 out_dir:
1079 fput(fp); 1029 dput(dir);
1080 1030
1081 out: 1031 out:
1082 reiserfs_read_unlock_xattr_i(dentry->d_inode); 1032 reiserfs_read_unlock_xattr_i(dentry->d_inode);
diff --git a/fs/signalfd.c b/fs/signalfd.c
index cb2b63ae0bf4..8ead0db35933 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -111,9 +111,14 @@ static int signalfd_copyinfo(struct signalfd_siginfo __user *uinfo,
111 err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid); 111 err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
112 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr); 112 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
113 break; 113 break;
114 default: /* this is just in case for now ... */ 114 default:
115 /*
116 * This case catches also the signals queued by sigqueue().
117 */
115 err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid); 118 err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid);
116 err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid); 119 err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid);
120 err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr);
121 err |= __put_user(kinfo->si_int, &uinfo->ssi_int);
117 break; 122 break;
118 } 123 }
119 124
diff --git a/fs/smbfs/smbiod.c b/fs/smbfs/smbiod.c
index fae8e85af0ed..6bd9b691a463 100644
--- a/fs/smbfs/smbiod.c
+++ b/fs/smbfs/smbiod.c
@@ -206,7 +206,7 @@ int smbiod_retry(struct smb_sb_info *server)
206 206
207 smb_close_socket(server); 207 smb_close_socket(server);
208 208
209 if (pid == 0) { 209 if (!pid) {
210 /* FIXME: this is fatal, umount? */ 210 /* FIXME: this is fatal, umount? */
211 printk(KERN_ERR "smb_retry: no connection process\n"); 211 printk(KERN_ERR "smb_retry: no connection process\n");
212 server->state = CONN_RETRIED; 212 server->state = CONN_RETRIED;
diff --git a/fs/splice.c b/fs/splice.c
index 0670c915cd35..eeb1a86a7014 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -320,7 +320,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
320 break; 320 break;
321 321
322 error = add_to_page_cache_lru(page, mapping, index, 322 error = add_to_page_cache_lru(page, mapping, index,
323 GFP_KERNEL); 323 mapping_gfp_mask(mapping));
324 if (unlikely(error)) { 324 if (unlikely(error)) {
325 page_cache_release(page); 325 page_cache_release(page);
326 if (error == -EEXIST) 326 if (error == -EEXIST)
@@ -370,8 +370,10 @@ __generic_file_splice_read(struct file *in, loff_t *ppos,
370 * for an in-flight io page 370 * for an in-flight io page
371 */ 371 */
372 if (flags & SPLICE_F_NONBLOCK) { 372 if (flags & SPLICE_F_NONBLOCK) {
373 if (TestSetPageLocked(page)) 373 if (TestSetPageLocked(page)) {
374 error = -EAGAIN;
374 break; 375 break;
376 }
375 } else 377 } else
376 lock_page(page); 378 lock_page(page);
377 379
@@ -479,9 +481,8 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
479 struct pipe_inode_info *pipe, size_t len, 481 struct pipe_inode_info *pipe, size_t len,
480 unsigned int flags) 482 unsigned int flags)
481{ 483{
482 ssize_t spliced;
483 int ret;
484 loff_t isize, left; 484 loff_t isize, left;
485 int ret;
485 486
486 isize = i_size_read(in->f_mapping->host); 487 isize = i_size_read(in->f_mapping->host);
487 if (unlikely(*ppos >= isize)) 488 if (unlikely(*ppos >= isize))
@@ -491,29 +492,9 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
491 if (unlikely(left < len)) 492 if (unlikely(left < len))
492 len = left; 493 len = left;
493 494
494 ret = 0; 495 ret = __generic_file_splice_read(in, ppos, pipe, len, flags);
495 spliced = 0; 496 if (ret > 0)
496 while (len && !spliced) {
497 ret = __generic_file_splice_read(in, ppos, pipe, len, flags);
498
499 if (ret < 0)
500 break;
501 else if (!ret) {
502 if (spliced)
503 break;
504 if (flags & SPLICE_F_NONBLOCK) {
505 ret = -EAGAIN;
506 break;
507 }
508 }
509
510 *ppos += ret; 497 *ppos += ret;
511 len -= ret;
512 spliced += ret;
513 }
514
515 if (spliced)
516 return spliced;
517 498
518 return ret; 499 return ret;
519} 500}
diff --git a/fs/super.c b/fs/super.c
index d0a941a4e620..09008dbd264e 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -945,6 +945,7 @@ do_kern_mount(const char *fstype, int flags, const char *name, void *data)
945 put_filesystem(type); 945 put_filesystem(type);
946 return mnt; 946 return mnt;
947} 947}
948EXPORT_SYMBOL_GPL(do_kern_mount);
948 949
949struct vfsmount *kern_mount_data(struct file_system_type *type, void *data) 950struct vfsmount *kern_mount_data(struct file_system_type *type, void *data)
950{ 951{
diff --git a/fs/xfs/linux-2.6/xfs_ioctl.c b/fs/xfs/linux-2.6/xfs_ioctl.c
index a9952e490ac9..f34bd010eb51 100644
--- a/fs/xfs/linux-2.6/xfs_ioctl.c
+++ b/fs/xfs/linux-2.6/xfs_ioctl.c
@@ -732,7 +732,7 @@ xfs_ioctl(
732 * Only allow the sys admin to reserve space unless 732 * Only allow the sys admin to reserve space unless
733 * unwritten extents are enabled. 733 * unwritten extents are enabled.
734 */ 734 */
735 if (!XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) && 735 if (!xfs_sb_version_hasextflgbit(&mp->m_sb) &&
736 !capable(CAP_SYS_ADMIN)) 736 !capable(CAP_SYS_ADMIN))
737 return -EPERM; 737 return -EPERM;
738 738
diff --git a/fs/xfs/quota/xfs_qm.c b/fs/xfs/quota/xfs_qm.c
index 1f3da5b8657b..8e9c5ae6504d 100644
--- a/fs/xfs/quota/xfs_qm.c
+++ b/fs/xfs/quota/xfs_qm.c
@@ -1405,13 +1405,13 @@ xfs_qm_qino_alloc(
1405#if defined(DEBUG) && defined(XFS_LOUD_RECOVERY) 1405#if defined(DEBUG) && defined(XFS_LOUD_RECOVERY)
1406 unsigned oldv = mp->m_sb.sb_versionnum; 1406 unsigned oldv = mp->m_sb.sb_versionnum;
1407#endif 1407#endif
1408 ASSERT(!XFS_SB_VERSION_HASQUOTA(&mp->m_sb)); 1408 ASSERT(!xfs_sb_version_hasquota(&mp->m_sb));
1409 ASSERT((sbfields & (XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | 1409 ASSERT((sbfields & (XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO |
1410 XFS_SB_GQUOTINO | XFS_SB_QFLAGS)) == 1410 XFS_SB_GQUOTINO | XFS_SB_QFLAGS)) ==
1411 (XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | 1411 (XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO |
1412 XFS_SB_GQUOTINO | XFS_SB_QFLAGS)); 1412 XFS_SB_GQUOTINO | XFS_SB_QFLAGS));
1413 1413
1414 XFS_SB_VERSION_ADDQUOTA(&mp->m_sb); 1414 xfs_sb_version_addquota(&mp->m_sb);
1415 mp->m_sb.sb_uquotino = NULLFSINO; 1415 mp->m_sb.sb_uquotino = NULLFSINO;
1416 mp->m_sb.sb_gquotino = NULLFSINO; 1416 mp->m_sb.sb_gquotino = NULLFSINO;
1417 1417
@@ -1954,7 +1954,7 @@ xfs_qm_init_quotainos(
1954 /* 1954 /*
1955 * Get the uquota and gquota inodes 1955 * Get the uquota and gquota inodes
1956 */ 1956 */
1957 if (XFS_SB_VERSION_HASQUOTA(&mp->m_sb)) { 1957 if (xfs_sb_version_hasquota(&mp->m_sb)) {
1958 if (XFS_IS_UQUOTA_ON(mp) && 1958 if (XFS_IS_UQUOTA_ON(mp) &&
1959 mp->m_sb.sb_uquotino != NULLFSINO) { 1959 mp->m_sb.sb_uquotino != NULLFSINO) {
1960 ASSERT(mp->m_sb.sb_uquotino > 0); 1960 ASSERT(mp->m_sb.sb_uquotino > 0);
diff --git a/fs/xfs/quota/xfs_qm_bhv.c b/fs/xfs/quota/xfs_qm_bhv.c
index 97bb32937585..f4f6c4c861d7 100644
--- a/fs/xfs/quota/xfs_qm_bhv.c
+++ b/fs/xfs/quota/xfs_qm_bhv.c
@@ -118,7 +118,7 @@ xfs_qm_newmount(
118 *quotaflags = 0; 118 *quotaflags = 0;
119 *needquotamount = B_FALSE; 119 *needquotamount = B_FALSE;
120 120
121 quotaondisk = XFS_SB_VERSION_HASQUOTA(&mp->m_sb) && 121 quotaondisk = xfs_sb_version_hasquota(&mp->m_sb) &&
122 (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT); 122 (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT);
123 123
124 if (quotaondisk) { 124 if (quotaondisk) {
diff --git a/fs/xfs/quota/xfs_qm_syscalls.c b/fs/xfs/quota/xfs_qm_syscalls.c
index 2cc5886cfe85..d2b8be7e75f9 100644
--- a/fs/xfs/quota/xfs_qm_syscalls.c
+++ b/fs/xfs/quota/xfs_qm_syscalls.c
@@ -377,7 +377,7 @@ xfs_qm_scall_trunc_qfiles(
377 if (!capable(CAP_SYS_ADMIN)) 377 if (!capable(CAP_SYS_ADMIN))
378 return XFS_ERROR(EPERM); 378 return XFS_ERROR(EPERM);
379 error = 0; 379 error = 0;
380 if (!XFS_SB_VERSION_HASQUOTA(&mp->m_sb) || flags == 0) { 380 if (!xfs_sb_version_hasquota(&mp->m_sb) || flags == 0) {
381 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags); 381 qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags);
382 return XFS_ERROR(EINVAL); 382 return XFS_ERROR(EINVAL);
383 } 383 }
@@ -522,7 +522,7 @@ xfs_qm_scall_getqstat(
522 memset(out, 0, sizeof(fs_quota_stat_t)); 522 memset(out, 0, sizeof(fs_quota_stat_t));
523 523
524 out->qs_version = FS_QSTAT_VERSION; 524 out->qs_version = FS_QSTAT_VERSION;
525 if (! XFS_SB_VERSION_HASQUOTA(&mp->m_sb)) { 525 if (!xfs_sb_version_hasquota(&mp->m_sb)) {
526 out->qs_uquota.qfs_ino = NULLFSINO; 526 out->qs_uquota.qfs_ino = NULLFSINO;
527 out->qs_gquota.qfs_ino = NULLFSINO; 527 out->qs_gquota.qfs_ino = NULLFSINO;
528 return (0); 528 return (0);
diff --git a/fs/xfs/xfs_attr_leaf.c b/fs/xfs/xfs_attr_leaf.c
index b08e2a2a8add..96ba6aa4ed8c 100644
--- a/fs/xfs/xfs_attr_leaf.c
+++ b/fs/xfs/xfs_attr_leaf.c
@@ -227,10 +227,10 @@ STATIC void
227xfs_sbversion_add_attr2(xfs_mount_t *mp, xfs_trans_t *tp) 227xfs_sbversion_add_attr2(xfs_mount_t *mp, xfs_trans_t *tp)
228{ 228{
229 if ((mp->m_flags & XFS_MOUNT_ATTR2) && 229 if ((mp->m_flags & XFS_MOUNT_ATTR2) &&
230 !(XFS_SB_VERSION_HASATTR2(&mp->m_sb))) { 230 !(xfs_sb_version_hasattr2(&mp->m_sb))) {
231 spin_lock(&mp->m_sb_lock); 231 spin_lock(&mp->m_sb_lock);
232 if (!XFS_SB_VERSION_HASATTR2(&mp->m_sb)) { 232 if (!xfs_sb_version_hasattr2(&mp->m_sb)) {
233 XFS_SB_VERSION_ADDATTR2(&mp->m_sb); 233 xfs_sb_version_addattr2(&mp->m_sb);
234 spin_unlock(&mp->m_sb_lock); 234 spin_unlock(&mp->m_sb_lock);
235 xfs_mod_sb(tp, XFS_SB_VERSIONNUM | XFS_SB_FEATURES2); 235 xfs_mod_sb(tp, XFS_SB_VERSIONNUM | XFS_SB_FEATURES2);
236 } else 236 } else
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index 1c0a5a585a82..2def273855a2 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -4047,17 +4047,17 @@ xfs_bmap_add_attrfork(
4047 xfs_trans_log_inode(tp, ip, logflags); 4047 xfs_trans_log_inode(tp, ip, logflags);
4048 if (error) 4048 if (error)
4049 goto error2; 4049 goto error2;
4050 if (!XFS_SB_VERSION_HASATTR(&mp->m_sb) || 4050 if (!xfs_sb_version_hasattr(&mp->m_sb) ||
4051 (!XFS_SB_VERSION_HASATTR2(&mp->m_sb) && version == 2)) { 4051 (!xfs_sb_version_hasattr2(&mp->m_sb) && version == 2)) {
4052 __int64_t sbfields = 0; 4052 __int64_t sbfields = 0;
4053 4053
4054 spin_lock(&mp->m_sb_lock); 4054 spin_lock(&mp->m_sb_lock);
4055 if (!XFS_SB_VERSION_HASATTR(&mp->m_sb)) { 4055 if (!xfs_sb_version_hasattr(&mp->m_sb)) {
4056 XFS_SB_VERSION_ADDATTR(&mp->m_sb); 4056 xfs_sb_version_addattr(&mp->m_sb);
4057 sbfields |= XFS_SB_VERSIONNUM; 4057 sbfields |= XFS_SB_VERSIONNUM;
4058 } 4058 }
4059 if (!XFS_SB_VERSION_HASATTR2(&mp->m_sb) && version == 2) { 4059 if (!xfs_sb_version_hasattr2(&mp->m_sb) && version == 2) {
4060 XFS_SB_VERSION_ADDATTR2(&mp->m_sb); 4060 xfs_sb_version_addattr2(&mp->m_sb);
4061 sbfields |= (XFS_SB_VERSIONNUM | XFS_SB_FEATURES2); 4061 sbfields |= (XFS_SB_VERSIONNUM | XFS_SB_FEATURES2);
4062 } 4062 }
4063 if (sbfields) { 4063 if (sbfields) {
@@ -5043,7 +5043,7 @@ xfs_bmapi(
5043 * A wasdelay extent has been initialized, so 5043 * A wasdelay extent has been initialized, so
5044 * shouldn't be flagged as unwritten. 5044 * shouldn't be flagged as unwritten.
5045 */ 5045 */
5046 if (wr && XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb)) { 5046 if (wr && xfs_sb_version_hasextflgbit(&mp->m_sb)) {
5047 if (!wasdelay && (flags & XFS_BMAPI_PREALLOC)) 5047 if (!wasdelay && (flags & XFS_BMAPI_PREALLOC))
5048 got.br_state = XFS_EXT_UNWRITTEN; 5048 got.br_state = XFS_EXT_UNWRITTEN;
5049 } 5049 }
@@ -5483,7 +5483,7 @@ xfs_bunmapi(
5483 * get rid of part of a realtime extent. 5483 * get rid of part of a realtime extent.
5484 */ 5484 */
5485 if (del.br_state == XFS_EXT_UNWRITTEN || 5485 if (del.br_state == XFS_EXT_UNWRITTEN ||
5486 !XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb)) { 5486 !xfs_sb_version_hasextflgbit(&mp->m_sb)) {
5487 /* 5487 /*
5488 * This piece is unwritten, or we're not 5488 * This piece is unwritten, or we're not
5489 * using unwritten extents. Skip over it. 5489 * using unwritten extents. Skip over it.
@@ -5535,7 +5535,7 @@ xfs_bunmapi(
5535 } else if ((del.br_startoff == start && 5535 } else if ((del.br_startoff == start &&
5536 (del.br_state == XFS_EXT_UNWRITTEN || 5536 (del.br_state == XFS_EXT_UNWRITTEN ||
5537 xfs_trans_get_block_res(tp) == 0)) || 5537 xfs_trans_get_block_res(tp) == 0)) ||
5538 !XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb)) { 5538 !xfs_sb_version_hasextflgbit(&mp->m_sb)) {
5539 /* 5539 /*
5540 * Can't make it unwritten. There isn't 5540 * Can't make it unwritten. There isn't
5541 * a full extent here so just skip it. 5541 * a full extent here so just skip it.
diff --git a/fs/xfs/xfs_bmap_btree.h b/fs/xfs/xfs_bmap_btree.h
index 2d950e975918..cd0d4b4bb816 100644
--- a/fs/xfs/xfs_bmap_btree.h
+++ b/fs/xfs/xfs_bmap_btree.h
@@ -120,7 +120,7 @@ typedef enum {
120 * Extent state and extent format macros. 120 * Extent state and extent format macros.
121 */ 121 */
122#define XFS_EXTFMT_INODE(x) \ 122#define XFS_EXTFMT_INODE(x) \
123 (XFS_SB_VERSION_HASEXTFLGBIT(&((x)->i_mount->m_sb)) ? \ 123 (xfs_sb_version_hasextflgbit(&((x)->i_mount->m_sb)) ? \
124 XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE) 124 XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE)
125#define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN) 125#define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN)
126 126
diff --git a/fs/xfs/xfs_dir2.c b/fs/xfs/xfs_dir2.c
index be7c4251fa61..e92e73f0e6af 100644
--- a/fs/xfs/xfs_dir2.c
+++ b/fs/xfs/xfs_dir2.c
@@ -49,7 +49,7 @@ void
49xfs_dir_mount( 49xfs_dir_mount(
50 xfs_mount_t *mp) 50 xfs_mount_t *mp)
51{ 51{
52 ASSERT(XFS_SB_VERSION_HASDIRV2(&mp->m_sb)); 52 ASSERT(xfs_sb_version_hasdirv2(&mp->m_sb));
53 ASSERT((1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog)) <= 53 ASSERT((1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog)) <=
54 XFS_MAX_BLOCKSIZE); 54 XFS_MAX_BLOCKSIZE);
55 mp->m_dirblksize = 1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog); 55 mp->m_dirblksize = 1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog);
diff --git a/fs/xfs/xfs_fsops.c b/fs/xfs/xfs_fsops.c
index eadc1591c795..d3a0f538d6a6 100644
--- a/fs/xfs/xfs_fsops.c
+++ b/fs/xfs/xfs_fsops.c
@@ -77,36 +77,36 @@ xfs_fs_geometry(
77 if (new_version >= 3) { 77 if (new_version >= 3) {
78 geo->version = XFS_FSOP_GEOM_VERSION; 78 geo->version = XFS_FSOP_GEOM_VERSION;
79 geo->flags = 79 geo->flags =
80 (XFS_SB_VERSION_HASATTR(&mp->m_sb) ? 80 (xfs_sb_version_hasattr(&mp->m_sb) ?
81 XFS_FSOP_GEOM_FLAGS_ATTR : 0) | 81 XFS_FSOP_GEOM_FLAGS_ATTR : 0) |
82 (XFS_SB_VERSION_HASNLINK(&mp->m_sb) ? 82 (xfs_sb_version_hasnlink(&mp->m_sb) ?
83 XFS_FSOP_GEOM_FLAGS_NLINK : 0) | 83 XFS_FSOP_GEOM_FLAGS_NLINK : 0) |
84 (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) ? 84 (xfs_sb_version_hasquota(&mp->m_sb) ?
85 XFS_FSOP_GEOM_FLAGS_QUOTA : 0) | 85 XFS_FSOP_GEOM_FLAGS_QUOTA : 0) |
86 (XFS_SB_VERSION_HASALIGN(&mp->m_sb) ? 86 (xfs_sb_version_hasalign(&mp->m_sb) ?
87 XFS_FSOP_GEOM_FLAGS_IALIGN : 0) | 87 XFS_FSOP_GEOM_FLAGS_IALIGN : 0) |
88 (XFS_SB_VERSION_HASDALIGN(&mp->m_sb) ? 88 (xfs_sb_version_hasdalign(&mp->m_sb) ?
89 XFS_FSOP_GEOM_FLAGS_DALIGN : 0) | 89 XFS_FSOP_GEOM_FLAGS_DALIGN : 0) |
90 (XFS_SB_VERSION_HASSHARED(&mp->m_sb) ? 90 (xfs_sb_version_hasshared(&mp->m_sb) ?
91 XFS_FSOP_GEOM_FLAGS_SHARED : 0) | 91 XFS_FSOP_GEOM_FLAGS_SHARED : 0) |
92 (XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) ? 92 (xfs_sb_version_hasextflgbit(&mp->m_sb) ?
93 XFS_FSOP_GEOM_FLAGS_EXTFLG : 0) | 93 XFS_FSOP_GEOM_FLAGS_EXTFLG : 0) |
94 (XFS_SB_VERSION_HASDIRV2(&mp->m_sb) ? 94 (xfs_sb_version_hasdirv2(&mp->m_sb) ?
95 XFS_FSOP_GEOM_FLAGS_DIRV2 : 0) | 95 XFS_FSOP_GEOM_FLAGS_DIRV2 : 0) |
96 (XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ? 96 (xfs_sb_version_hassector(&mp->m_sb) ?
97 XFS_FSOP_GEOM_FLAGS_SECTOR : 0) | 97 XFS_FSOP_GEOM_FLAGS_SECTOR : 0) |
98 (xfs_sb_version_haslazysbcount(&mp->m_sb) ? 98 (xfs_sb_version_haslazysbcount(&mp->m_sb) ?
99 XFS_FSOP_GEOM_FLAGS_LAZYSB : 0) | 99 XFS_FSOP_GEOM_FLAGS_LAZYSB : 0) |
100 (XFS_SB_VERSION_HASATTR2(&mp->m_sb) ? 100 (xfs_sb_version_hasattr2(&mp->m_sb) ?
101 XFS_FSOP_GEOM_FLAGS_ATTR2 : 0); 101 XFS_FSOP_GEOM_FLAGS_ATTR2 : 0);
102 geo->logsectsize = XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ? 102 geo->logsectsize = xfs_sb_version_hassector(&mp->m_sb) ?
103 mp->m_sb.sb_logsectsize : BBSIZE; 103 mp->m_sb.sb_logsectsize : BBSIZE;
104 geo->rtsectsize = mp->m_sb.sb_blocksize; 104 geo->rtsectsize = mp->m_sb.sb_blocksize;
105 geo->dirblocksize = mp->m_dirblksize; 105 geo->dirblocksize = mp->m_dirblksize;
106 } 106 }
107 if (new_version >= 4) { 107 if (new_version >= 4) {
108 geo->flags |= 108 geo->flags |=
109 (XFS_SB_VERSION_HASLOGV2(&mp->m_sb) ? 109 (xfs_sb_version_haslogv2(&mp->m_sb) ?
110 XFS_FSOP_GEOM_FLAGS_LOGV2 : 0); 110 XFS_FSOP_GEOM_FLAGS_LOGV2 : 0);
111 geo->logsunit = mp->m_sb.sb_logsunit; 111 geo->logsunit = mp->m_sb.sb_logsunit;
112 } 112 }
diff --git a/fs/xfs/xfs_ialloc.c b/fs/xfs/xfs_ialloc.c
index db9d5fa600af..5a146cb22980 100644
--- a/fs/xfs/xfs_ialloc.c
+++ b/fs/xfs/xfs_ialloc.c
@@ -191,7 +191,7 @@ xfs_ialloc_ag_alloc(
191 ASSERT(!(args.mp->m_flags & XFS_MOUNT_NOALIGN)); 191 ASSERT(!(args.mp->m_flags & XFS_MOUNT_NOALIGN));
192 args.alignment = args.mp->m_dalign; 192 args.alignment = args.mp->m_dalign;
193 isaligned = 1; 193 isaligned = 1;
194 } else if (XFS_SB_VERSION_HASALIGN(&args.mp->m_sb) && 194 } else if (xfs_sb_version_hasalign(&args.mp->m_sb) &&
195 args.mp->m_sb.sb_inoalignmt >= 195 args.mp->m_sb.sb_inoalignmt >=
196 XFS_B_TO_FSBT(args.mp, 196 XFS_B_TO_FSBT(args.mp,
197 XFS_INODE_CLUSTER_SIZE(args.mp))) 197 XFS_INODE_CLUSTER_SIZE(args.mp)))
@@ -230,7 +230,7 @@ xfs_ialloc_ag_alloc(
230 args.agbno = be32_to_cpu(agi->agi_root); 230 args.agbno = be32_to_cpu(agi->agi_root);
231 args.fsbno = XFS_AGB_TO_FSB(args.mp, 231 args.fsbno = XFS_AGB_TO_FSB(args.mp,
232 be32_to_cpu(agi->agi_seqno), args.agbno); 232 be32_to_cpu(agi->agi_seqno), args.agbno);
233 if (XFS_SB_VERSION_HASALIGN(&args.mp->m_sb) && 233 if (xfs_sb_version_hasalign(&args.mp->m_sb) &&
234 args.mp->m_sb.sb_inoalignmt >= 234 args.mp->m_sb.sb_inoalignmt >=
235 XFS_B_TO_FSBT(args.mp, XFS_INODE_CLUSTER_SIZE(args.mp))) 235 XFS_B_TO_FSBT(args.mp, XFS_INODE_CLUSTER_SIZE(args.mp)))
236 args.alignment = args.mp->m_sb.sb_inoalignmt; 236 args.alignment = args.mp->m_sb.sb_inoalignmt;
@@ -271,7 +271,7 @@ xfs_ialloc_ag_alloc(
271 * use the old version so that old kernels will continue to be 271 * use the old version so that old kernels will continue to be
272 * able to use the file system. 272 * able to use the file system.
273 */ 273 */
274 if (XFS_SB_VERSION_HASNLINK(&args.mp->m_sb)) 274 if (xfs_sb_version_hasnlink(&args.mp->m_sb))
275 version = XFS_DINODE_VERSION_2; 275 version = XFS_DINODE_VERSION_2;
276 else 276 else
277 version = XFS_DINODE_VERSION_1; 277 version = XFS_DINODE_VERSION_1;
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index a550546a7083..f43a6e01d68f 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -1147,7 +1147,7 @@ xfs_ialloc(
1147 * the inode version number now. This way we only do the conversion 1147 * the inode version number now. This way we only do the conversion
1148 * here rather than here and in the flush/logging code. 1148 * here rather than here and in the flush/logging code.
1149 */ 1149 */
1150 if (XFS_SB_VERSION_HASNLINK(&tp->t_mountp->m_sb) && 1150 if (xfs_sb_version_hasnlink(&tp->t_mountp->m_sb) &&
1151 ip->i_d.di_version == XFS_DINODE_VERSION_1) { 1151 ip->i_d.di_version == XFS_DINODE_VERSION_1) {
1152 ip->i_d.di_version = XFS_DINODE_VERSION_2; 1152 ip->i_d.di_version = XFS_DINODE_VERSION_2;
1153 /* 1153 /*
@@ -3434,9 +3434,9 @@ xfs_iflush_int(
3434 * has been updated, then make the conversion permanent. 3434 * has been updated, then make the conversion permanent.
3435 */ 3435 */
3436 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1 || 3436 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1 ||
3437 XFS_SB_VERSION_HASNLINK(&mp->m_sb)); 3437 xfs_sb_version_hasnlink(&mp->m_sb));
3438 if (ip->i_d.di_version == XFS_DINODE_VERSION_1) { 3438 if (ip->i_d.di_version == XFS_DINODE_VERSION_1) {
3439 if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) { 3439 if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
3440 /* 3440 /*
3441 * Convert it back. 3441 * Convert it back.
3442 */ 3442 */
diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
index 034ca7202295..2c775b4ae9e6 100644
--- a/fs/xfs/xfs_inode_item.c
+++ b/fs/xfs/xfs_inode_item.c
@@ -296,9 +296,9 @@ xfs_inode_item_format(
296 */ 296 */
297 mp = ip->i_mount; 297 mp = ip->i_mount;
298 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1 || 298 ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1 ||
299 XFS_SB_VERSION_HASNLINK(&mp->m_sb)); 299 xfs_sb_version_hasnlink(&mp->m_sb));
300 if (ip->i_d.di_version == XFS_DINODE_VERSION_1) { 300 if (ip->i_d.di_version == XFS_DINODE_VERSION_1) {
301 if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) { 301 if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
302 /* 302 /*
303 * Convert it back. 303 * Convert it back.
304 */ 304 */
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index 658aab6b1bbf..f615e04364f4 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -45,7 +45,7 @@ xfs_internal_inum(
45 xfs_ino_t ino) 45 xfs_ino_t ino)
46{ 46{
47 return (ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino || 47 return (ino == mp->m_sb.sb_rbmino || ino == mp->m_sb.sb_rsumino ||
48 (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) && 48 (xfs_sb_version_hasquota(&mp->m_sb) &&
49 (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino))); 49 (ino == mp->m_sb.sb_uquotino || ino == mp->m_sb.sb_gquotino)));
50} 50}
51 51
diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c
index a75edca1860f..31f2b04f2c97 100644
--- a/fs/xfs/xfs_log.c
+++ b/fs/xfs/xfs_log.c
@@ -1090,7 +1090,7 @@ xlog_get_iclog_buffer_size(xfs_mount_t *mp,
1090 size >>= 1; 1090 size >>= 1;
1091 } 1091 }
1092 1092
1093 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) { 1093 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1094 /* # headers = size / 32K 1094 /* # headers = size / 32K
1095 * one header holds cycles from 32K of data 1095 * one header holds cycles from 32K of data
1096 */ 1096 */
@@ -1186,13 +1186,13 @@ xlog_alloc_log(xfs_mount_t *mp,
1186 log->l_grant_reserve_cycle = 1; 1186 log->l_grant_reserve_cycle = 1;
1187 log->l_grant_write_cycle = 1; 1187 log->l_grant_write_cycle = 1;
1188 1188
1189 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb)) { 1189 if (xfs_sb_version_hassector(&mp->m_sb)) {
1190 log->l_sectbb_log = mp->m_sb.sb_logsectlog - BBSHIFT; 1190 log->l_sectbb_log = mp->m_sb.sb_logsectlog - BBSHIFT;
1191 ASSERT(log->l_sectbb_log <= mp->m_sectbb_log); 1191 ASSERT(log->l_sectbb_log <= mp->m_sectbb_log);
1192 /* for larger sector sizes, must have v2 or external log */ 1192 /* for larger sector sizes, must have v2 or external log */
1193 ASSERT(log->l_sectbb_log == 0 || 1193 ASSERT(log->l_sectbb_log == 0 ||
1194 log->l_logBBstart == 0 || 1194 log->l_logBBstart == 0 ||
1195 XFS_SB_VERSION_HASLOGV2(&mp->m_sb)); 1195 xfs_sb_version_haslogv2(&mp->m_sb));
1196 ASSERT(mp->m_sb.sb_logsectlog >= BBSHIFT); 1196 ASSERT(mp->m_sb.sb_logsectlog >= BBSHIFT);
1197 } 1197 }
1198 log->l_sectbb_mask = (1 << log->l_sectbb_log) - 1; 1198 log->l_sectbb_mask = (1 << log->l_sectbb_log) - 1;
@@ -1247,7 +1247,7 @@ xlog_alloc_log(xfs_mount_t *mp,
1247 memset(head, 0, sizeof(xlog_rec_header_t)); 1247 memset(head, 0, sizeof(xlog_rec_header_t));
1248 head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM); 1248 head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
1249 head->h_version = cpu_to_be32( 1249 head->h_version = cpu_to_be32(
1250 XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1); 1250 xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? 2 : 1);
1251 head->h_size = cpu_to_be32(log->l_iclog_size); 1251 head->h_size = cpu_to_be32(log->l_iclog_size);
1252 /* new fields */ 1252 /* new fields */
1253 head->h_fmt = cpu_to_be32(XLOG_FMT); 1253 head->h_fmt = cpu_to_be32(XLOG_FMT);
@@ -1402,7 +1402,7 @@ xlog_sync(xlog_t *log,
1402 int roundoff; /* roundoff to BB or stripe */ 1402 int roundoff; /* roundoff to BB or stripe */
1403 int split = 0; /* split write into two regions */ 1403 int split = 0; /* split write into two regions */
1404 int error; 1404 int error;
1405 int v2 = XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb); 1405 int v2 = xfs_sb_version_haslogv2(&log->l_mp->m_sb);
1406 1406
1407 XFS_STATS_INC(xs_log_writes); 1407 XFS_STATS_INC(xs_log_writes);
1408 ASSERT(iclog->ic_refcnt == 0); 1408 ASSERT(iclog->ic_refcnt == 0);
@@ -2881,7 +2881,7 @@ xlog_state_switch_iclogs(xlog_t *log,
2881 log->l_curr_block += BTOBB(eventual_size)+BTOBB(log->l_iclog_hsize); 2881 log->l_curr_block += BTOBB(eventual_size)+BTOBB(log->l_iclog_hsize);
2882 2882
2883 /* Round up to next log-sunit */ 2883 /* Round up to next log-sunit */
2884 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) && 2884 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb) &&
2885 log->l_mp->m_sb.sb_logsunit > 1) { 2885 log->l_mp->m_sb.sb_logsunit > 1) {
2886 __uint32_t sunit_bb = BTOBB(log->l_mp->m_sb.sb_logsunit); 2886 __uint32_t sunit_bb = BTOBB(log->l_mp->m_sb.sb_logsunit);
2887 log->l_curr_block = roundup(log->l_curr_block, sunit_bb); 2887 log->l_curr_block = roundup(log->l_curr_block, sunit_bb);
@@ -3334,7 +3334,7 @@ xlog_ticket_get(xlog_t *log,
3334 unit_bytes += sizeof(xlog_op_header_t) * num_headers; 3334 unit_bytes += sizeof(xlog_op_header_t) * num_headers;
3335 3335
3336 /* for roundoff padding for transaction data and one for commit record */ 3336 /* for roundoff padding for transaction data and one for commit record */
3337 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) && 3337 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb) &&
3338 log->l_mp->m_sb.sb_logsunit > 1) { 3338 log->l_mp->m_sb.sb_logsunit > 1) {
3339 /* log su roundoff */ 3339 /* log su roundoff */
3340 unit_bytes += 2*log->l_mp->m_sb.sb_logsunit; 3340 unit_bytes += 2*log->l_mp->m_sb.sb_logsunit;
diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h
index e008233ee249..c6244cc733c0 100644
--- a/fs/xfs/xfs_log_priv.h
+++ b/fs/xfs/xfs_log_priv.h
@@ -49,10 +49,10 @@ struct xfs_mount;
49#define XLOG_HEADER_SIZE 512 49#define XLOG_HEADER_SIZE 512
50 50
51#define XLOG_REC_SHIFT(log) \ 51#define XLOG_REC_SHIFT(log) \
52 BTOBB(1 << (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? \ 52 BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
53 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT)) 53 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
54#define XLOG_TOTAL_REC_SHIFT(log) \ 54#define XLOG_TOTAL_REC_SHIFT(log) \
55 BTOBB(XLOG_MAX_ICLOGS << (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? \ 55 BTOBB(XLOG_MAX_ICLOGS << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
56 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT)) 56 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
57 57
58 58
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index b82d5d4d2462..b2b70eba282c 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -478,7 +478,7 @@ xlog_find_verify_log_record(
478 * reset last_blk. Only when last_blk points in the middle of a log 478 * reset last_blk. Only when last_blk points in the middle of a log
479 * record do we update last_blk. 479 * record do we update last_blk.
480 */ 480 */
481 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 481 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
482 uint h_size = be32_to_cpu(head->h_size); 482 uint h_size = be32_to_cpu(head->h_size);
483 483
484 xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE; 484 xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE;
@@ -888,7 +888,7 @@ xlog_find_tail(
888 * unmount record if there is one, so we pass the lsn of the 888 * unmount record if there is one, so we pass the lsn of the
889 * unmount record rather than the block after it. 889 * unmount record rather than the block after it.
890 */ 890 */
891 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 891 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
892 int h_size = be32_to_cpu(rhead->h_size); 892 int h_size = be32_to_cpu(rhead->h_size);
893 int h_version = be32_to_cpu(rhead->h_version); 893 int h_version = be32_to_cpu(rhead->h_version);
894 894
@@ -1101,7 +1101,7 @@ xlog_add_record(
1101 recp->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM); 1101 recp->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
1102 recp->h_cycle = cpu_to_be32(cycle); 1102 recp->h_cycle = cpu_to_be32(cycle);
1103 recp->h_version = cpu_to_be32( 1103 recp->h_version = cpu_to_be32(
1104 XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1); 1104 xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? 2 : 1);
1105 recp->h_lsn = cpu_to_be64(xlog_assign_lsn(cycle, block)); 1105 recp->h_lsn = cpu_to_be64(xlog_assign_lsn(cycle, block));
1106 recp->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(tail_cycle, tail_block)); 1106 recp->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(tail_cycle, tail_block));
1107 recp->h_fmt = cpu_to_be32(XLOG_FMT); 1107 recp->h_fmt = cpu_to_be32(XLOG_FMT);
@@ -3348,7 +3348,7 @@ xlog_pack_data(
3348 dp += BBSIZE; 3348 dp += BBSIZE;
3349 } 3349 }
3350 3350
3351 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 3351 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
3352 xhdr = (xlog_in_core_2_t *)&iclog->ic_header; 3352 xhdr = (xlog_in_core_2_t *)&iclog->ic_header;
3353 for ( ; i < BTOBB(size); i++) { 3353 for ( ; i < BTOBB(size); i++) {
3354 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3354 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
@@ -3388,7 +3388,7 @@ xlog_unpack_data_checksum(
3388 be32_to_cpu(rhead->h_chksum), chksum); 3388 be32_to_cpu(rhead->h_chksum), chksum);
3389 cmn_err(CE_DEBUG, 3389 cmn_err(CE_DEBUG,
3390"XFS: Disregard message if filesystem was created with non-DEBUG kernel"); 3390"XFS: Disregard message if filesystem was created with non-DEBUG kernel");
3391 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 3391 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
3392 cmn_err(CE_DEBUG, 3392 cmn_err(CE_DEBUG,
3393 "XFS: LogR this is a LogV2 filesystem\n"); 3393 "XFS: LogR this is a LogV2 filesystem\n");
3394 } 3394 }
@@ -3415,7 +3415,7 @@ xlog_unpack_data(
3415 dp += BBSIZE; 3415 dp += BBSIZE;
3416 } 3416 }
3417 3417
3418 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 3418 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
3419 xhdr = (xlog_in_core_2_t *)rhead; 3419 xhdr = (xlog_in_core_2_t *)rhead;
3420 for ( ; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) { 3420 for ( ; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
3421 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE); 3421 j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
@@ -3494,7 +3494,7 @@ xlog_do_recovery_pass(
3494 * Read the header of the tail block and get the iclog buffer size from 3494 * Read the header of the tail block and get the iclog buffer size from
3495 * h_size. Use this to tell how many sectors make up the log header. 3495 * h_size. Use this to tell how many sectors make up the log header.
3496 */ 3496 */
3497 if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) { 3497 if (xfs_sb_version_haslogv2(&log->l_mp->m_sb)) {
3498 /* 3498 /*
3499 * When using variable length iclogs, read first sector of 3499 * When using variable length iclogs, read first sector of
3500 * iclog header and extract the header size from it. Get a 3500 * iclog header and extract the header size from it. Get a
@@ -3838,7 +3838,7 @@ xlog_do_recover(
3838 sbp = &log->l_mp->m_sb; 3838 sbp = &log->l_mp->m_sb;
3839 xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp)); 3839 xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp));
3840 ASSERT(sbp->sb_magicnum == XFS_SB_MAGIC); 3840 ASSERT(sbp->sb_magicnum == XFS_SB_MAGIC);
3841 ASSERT(XFS_SB_GOOD_VERSION(sbp)); 3841 ASSERT(xfs_sb_good_version(sbp));
3842 xfs_buf_relse(bp); 3842 xfs_buf_relse(bp);
3843 3843
3844 /* We've re-read the superblock so re-initialize per-cpu counters */ 3844 /* We've re-read the superblock so re-initialize per-cpu counters */
diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
index 6409b3762995..8ed164eb9544 100644
--- a/fs/xfs/xfs_mount.c
+++ b/fs/xfs/xfs_mount.c
@@ -44,7 +44,7 @@
44#include "xfs_quota.h" 44#include "xfs_quota.h"
45#include "xfs_fsops.h" 45#include "xfs_fsops.h"
46 46
47STATIC void xfs_mount_log_sbunit(xfs_mount_t *, __int64_t); 47STATIC void xfs_mount_log_sb(xfs_mount_t *, __int64_t);
48STATIC int xfs_uuid_mount(xfs_mount_t *); 48STATIC int xfs_uuid_mount(xfs_mount_t *);
49STATIC void xfs_uuid_unmount(xfs_mount_t *mp); 49STATIC void xfs_uuid_unmount(xfs_mount_t *mp);
50STATIC void xfs_unmountfs_wait(xfs_mount_t *); 50STATIC void xfs_unmountfs_wait(xfs_mount_t *);
@@ -119,6 +119,7 @@ static const struct {
119 { offsetof(xfs_sb_t, sb_logsectsize),0 }, 119 { offsetof(xfs_sb_t, sb_logsectsize),0 },
120 { offsetof(xfs_sb_t, sb_logsunit), 0 }, 120 { offsetof(xfs_sb_t, sb_logsunit), 0 },
121 { offsetof(xfs_sb_t, sb_features2), 0 }, 121 { offsetof(xfs_sb_t, sb_features2), 0 },
122 { offsetof(xfs_sb_t, sb_bad_features2), 0 },
122 { sizeof(xfs_sb_t), 0 } 123 { sizeof(xfs_sb_t), 0 }
123}; 124};
124 125
@@ -225,7 +226,7 @@ xfs_mount_validate_sb(
225 return XFS_ERROR(EWRONGFS); 226 return XFS_ERROR(EWRONGFS);
226 } 227 }
227 228
228 if (!XFS_SB_GOOD_VERSION(sbp)) { 229 if (!xfs_sb_good_version(sbp)) {
229 xfs_fs_mount_cmn_err(flags, "bad version"); 230 xfs_fs_mount_cmn_err(flags, "bad version");
230 return XFS_ERROR(EWRONGFS); 231 return XFS_ERROR(EWRONGFS);
231 } 232 }
@@ -300,7 +301,7 @@ xfs_mount_validate_sb(
300 /* 301 /*
301 * Version 1 directory format has never worked on Linux. 302 * Version 1 directory format has never worked on Linux.
302 */ 303 */
303 if (unlikely(!XFS_SB_VERSION_HASDIRV2(sbp))) { 304 if (unlikely(!xfs_sb_version_hasdirv2(sbp))) {
304 xfs_fs_mount_cmn_err(flags, 305 xfs_fs_mount_cmn_err(flags,
305 "file system using version 1 directory format"); 306 "file system using version 1 directory format");
306 return XFS_ERROR(ENOSYS); 307 return XFS_ERROR(ENOSYS);
@@ -449,6 +450,7 @@ xfs_sb_from_disk(
449 to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize); 450 to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize);
450 to->sb_logsunit = be32_to_cpu(from->sb_logsunit); 451 to->sb_logsunit = be32_to_cpu(from->sb_logsunit);
451 to->sb_features2 = be32_to_cpu(from->sb_features2); 452 to->sb_features2 = be32_to_cpu(from->sb_features2);
453 to->sb_bad_features2 = be32_to_cpu(from->sb_bad_features2);
452} 454}
453 455
454/* 456/*
@@ -781,7 +783,7 @@ xfs_update_alignment(xfs_mount_t *mp, int mfsi_flags, __uint64_t *update_flags)
781 * Update superblock with new values 783 * Update superblock with new values
782 * and log changes 784 * and log changes
783 */ 785 */
784 if (XFS_SB_VERSION_HASDALIGN(sbp)) { 786 if (xfs_sb_version_hasdalign(sbp)) {
785 if (sbp->sb_unit != mp->m_dalign) { 787 if (sbp->sb_unit != mp->m_dalign) {
786 sbp->sb_unit = mp->m_dalign; 788 sbp->sb_unit = mp->m_dalign;
787 *update_flags |= XFS_SB_UNIT; 789 *update_flags |= XFS_SB_UNIT;
@@ -792,7 +794,7 @@ xfs_update_alignment(xfs_mount_t *mp, int mfsi_flags, __uint64_t *update_flags)
792 } 794 }
793 } 795 }
794 } else if ((mp->m_flags & XFS_MOUNT_NOALIGN) != XFS_MOUNT_NOALIGN && 796 } else if ((mp->m_flags & XFS_MOUNT_NOALIGN) != XFS_MOUNT_NOALIGN &&
795 XFS_SB_VERSION_HASDALIGN(&mp->m_sb)) { 797 xfs_sb_version_hasdalign(&mp->m_sb)) {
796 mp->m_dalign = sbp->sb_unit; 798 mp->m_dalign = sbp->sb_unit;
797 mp->m_swidth = sbp->sb_width; 799 mp->m_swidth = sbp->sb_width;
798 } 800 }
@@ -869,7 +871,7 @@ xfs_set_rw_sizes(xfs_mount_t *mp)
869STATIC void 871STATIC void
870xfs_set_inoalignment(xfs_mount_t *mp) 872xfs_set_inoalignment(xfs_mount_t *mp)
871{ 873{
872 if (XFS_SB_VERSION_HASALIGN(&mp->m_sb) && 874 if (xfs_sb_version_hasalign(&mp->m_sb) &&
873 mp->m_sb.sb_inoalignmt >= 875 mp->m_sb.sb_inoalignmt >=
874 XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size)) 876 XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size))
875 mp->m_inoalign_mask = mp->m_sb.sb_inoalignmt - 1; 877 mp->m_inoalign_mask = mp->m_sb.sb_inoalignmt - 1;
@@ -970,6 +972,38 @@ xfs_mountfs(
970 xfs_mount_common(mp, sbp); 972 xfs_mount_common(mp, sbp);
971 973
972 /* 974 /*
975 * Check for a mismatched features2 values. Older kernels
976 * read & wrote into the wrong sb offset for sb_features2
977 * on some platforms due to xfs_sb_t not being 64bit size aligned
978 * when sb_features2 was added, which made older superblock
979 * reading/writing routines swap it as a 64-bit value.
980 *
981 * For backwards compatibility, we make both slots equal.
982 *
983 * If we detect a mismatched field, we OR the set bits into the
984 * existing features2 field in case it has already been modified; we
985 * don't want to lose any features. We then update the bad location
986 * with the ORed value so that older kernels will see any features2
987 * flags, and mark the two fields as needing updates once the
988 * transaction subsystem is online.
989 */
990 if (xfs_sb_has_mismatched_features2(sbp)) {
991 cmn_err(CE_WARN,
992 "XFS: correcting sb_features alignment problem");
993 sbp->sb_features2 |= sbp->sb_bad_features2;
994 sbp->sb_bad_features2 = sbp->sb_features2;
995 update_flags |= XFS_SB_FEATURES2 | XFS_SB_BAD_FEATURES2;
996
997 /*
998 * Re-check for ATTR2 in case it was found in bad_features2
999 * slot.
1000 */
1001 if (xfs_sb_version_hasattr2(&mp->m_sb))
1002 mp->m_flags |= XFS_MOUNT_ATTR2;
1003
1004 }
1005
1006 /*
973 * Check if sb_agblocks is aligned at stripe boundary 1007 * Check if sb_agblocks is aligned at stripe boundary
974 * If sb_agblocks is NOT aligned turn off m_dalign since 1008 * If sb_agblocks is NOT aligned turn off m_dalign since
975 * allocator alignment is within an ag, therefore ag has 1009 * allocator alignment is within an ag, therefore ag has
@@ -1159,11 +1193,10 @@ xfs_mountfs(
1159 } 1193 }
1160 1194
1161 /* 1195 /*
1162 * If fs is not mounted readonly, then update the superblock 1196 * If fs is not mounted readonly, then update the superblock changes.
1163 * unit and width changes.
1164 */ 1197 */
1165 if (update_flags && !(mp->m_flags & XFS_MOUNT_RDONLY)) 1198 if (update_flags && !(mp->m_flags & XFS_MOUNT_RDONLY))
1166 xfs_mount_log_sbunit(mp, update_flags); 1199 xfs_mount_log_sb(mp, update_flags);
1167 1200
1168 /* 1201 /*
1169 * Initialise the XFS quota management subsystem for this mount 1202 * Initialise the XFS quota management subsystem for this mount
@@ -1875,16 +1908,18 @@ xfs_uuid_unmount(
1875 1908
1876/* 1909/*
1877 * Used to log changes to the superblock unit and width fields which could 1910 * Used to log changes to the superblock unit and width fields which could
1878 * be altered by the mount options. Only the first superblock is updated. 1911 * be altered by the mount options, as well as any potential sb_features2
1912 * fixup. Only the first superblock is updated.
1879 */ 1913 */
1880STATIC void 1914STATIC void
1881xfs_mount_log_sbunit( 1915xfs_mount_log_sb(
1882 xfs_mount_t *mp, 1916 xfs_mount_t *mp,
1883 __int64_t fields) 1917 __int64_t fields)
1884{ 1918{
1885 xfs_trans_t *tp; 1919 xfs_trans_t *tp;
1886 1920
1887 ASSERT(fields & (XFS_SB_UNIT|XFS_SB_WIDTH|XFS_SB_UUID)); 1921 ASSERT(fields & (XFS_SB_UNIT | XFS_SB_WIDTH | XFS_SB_UUID |
1922 XFS_SB_FEATURES2 | XFS_SB_BAD_FEATURES2));
1888 1923
1889 tp = xfs_trans_alloc(mp, XFS_TRANS_SB_UNIT); 1924 tp = xfs_trans_alloc(mp, XFS_TRANS_SB_UNIT);
1890 if (xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0, 1925 if (xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
diff --git a/fs/xfs/xfs_sb.h b/fs/xfs/xfs_sb.h
index 94660b1a6ccc..d904efe7f871 100644
--- a/fs/xfs/xfs_sb.h
+++ b/fs/xfs/xfs_sb.h
@@ -89,6 +89,7 @@ struct xfs_mount;
89 89
90/* 90/*
91 * Superblock - in core version. Must match the ondisk version below. 91 * Superblock - in core version. Must match the ondisk version below.
92 * Must be padded to 64 bit alignment.
92 */ 93 */
93typedef struct xfs_sb { 94typedef struct xfs_sb {
94 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */ 95 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
@@ -145,10 +146,21 @@ typedef struct xfs_sb {
145 __uint16_t sb_logsectsize; /* sector size for the log, bytes */ 146 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
146 __uint32_t sb_logsunit; /* stripe unit size for the log */ 147 __uint32_t sb_logsunit; /* stripe unit size for the log */
147 __uint32_t sb_features2; /* additional feature bits */ 148 __uint32_t sb_features2; /* additional feature bits */
149
150 /*
151 * bad features2 field as a result of failing to pad the sb
152 * structure to 64 bits. Some machines will be using this field
153 * for features2 bits. Easiest just to mark it bad and not use
154 * it for anything else.
155 */
156 __uint32_t sb_bad_features2;
157
158 /* must be padded to 64 bit alignment */
148} xfs_sb_t; 159} xfs_sb_t;
149 160
150/* 161/*
151 * Superblock - on disk version. Must match the in core version below. 162 * Superblock - on disk version. Must match the in core version above.
163 * Must be padded to 64 bit alignment.
152 */ 164 */
153typedef struct xfs_dsb { 165typedef struct xfs_dsb {
154 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */ 166 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
@@ -205,6 +217,15 @@ typedef struct xfs_dsb {
205 __be16 sb_logsectsize; /* sector size for the log, bytes */ 217 __be16 sb_logsectsize; /* sector size for the log, bytes */
206 __be32 sb_logsunit; /* stripe unit size for the log */ 218 __be32 sb_logsunit; /* stripe unit size for the log */
207 __be32 sb_features2; /* additional feature bits */ 219 __be32 sb_features2; /* additional feature bits */
220 /*
221 * bad features2 field as a result of failing to pad the sb
222 * structure to 64 bits. Some machines will be using this field
223 * for features2 bits. Easiest just to mark it bad and not use
224 * it for anything else.
225 */
226 __be32 sb_bad_features2;
227
228 /* must be padded to 64 bit alignment */
208} xfs_dsb_t; 229} xfs_dsb_t;
209 230
210/* 231/*
@@ -223,7 +244,7 @@ typedef enum {
223 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN, 244 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
224 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG, 245 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
225 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT, 246 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
226 XFS_SBS_FEATURES2, 247 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2,
227 XFS_SBS_FIELDCOUNT 248 XFS_SBS_FIELDCOUNT
228} xfs_sb_field_t; 249} xfs_sb_field_t;
229 250
@@ -248,13 +269,15 @@ typedef enum {
248#define XFS_SB_IFREE XFS_SB_MVAL(IFREE) 269#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
249#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS) 270#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
250#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2) 271#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
272#define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
251#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT) 273#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
252#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1) 274#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
253#define XFS_SB_MOD_BITS \ 275#define XFS_SB_MOD_BITS \
254 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \ 276 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
255 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \ 277 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
256 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \ 278 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
257 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2) 279 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
280 XFS_SB_BAD_FEATURES2)
258 281
259 282
260/* 283/*
@@ -271,7 +294,6 @@ typedef enum {
271 294
272#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS) 295#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
273 296
274#define XFS_SB_GOOD_VERSION(sbp) xfs_sb_good_version(sbp)
275#ifdef __KERNEL__ 297#ifdef __KERNEL__
276static inline int xfs_sb_good_version(xfs_sb_t *sbp) 298static inline int xfs_sb_good_version(xfs_sb_t *sbp)
277{ 299{
@@ -297,7 +319,15 @@ static inline int xfs_sb_good_version(xfs_sb_t *sbp)
297} 319}
298#endif /* __KERNEL__ */ 320#endif /* __KERNEL__ */
299 321
300#define XFS_SB_VERSION_TONEW(v) xfs_sb_version_tonew(v) 322/*
323 * Detect a mismatched features2 field. Older kernels read/wrote
324 * this into the wrong slot, so to be safe we keep them in sync.
325 */
326static inline int xfs_sb_has_mismatched_features2(xfs_sb_t *sbp)
327{
328 return (sbp->sb_bad_features2 != sbp->sb_features2);
329}
330
301static inline unsigned xfs_sb_version_tonew(unsigned v) 331static inline unsigned xfs_sb_version_tonew(unsigned v)
302{ 332{
303 return ((((v) == XFS_SB_VERSION_1) ? \ 333 return ((((v) == XFS_SB_VERSION_1) ? \
@@ -308,7 +338,6 @@ static inline unsigned xfs_sb_version_tonew(unsigned v)
308 XFS_SB_VERSION_4); 338 XFS_SB_VERSION_4);
309} 339}
310 340
311#define XFS_SB_VERSION_TOOLD(v) xfs_sb_version_toold(v)
312static inline unsigned xfs_sb_version_toold(unsigned v) 341static inline unsigned xfs_sb_version_toold(unsigned v)
313{ 342{
314 return (((v) & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT)) ? \ 343 return (((v) & (XFS_SB_VERSION_QUOTABIT | XFS_SB_VERSION_ALIGNBIT)) ? \
@@ -320,7 +349,6 @@ static inline unsigned xfs_sb_version_toold(unsigned v)
320 XFS_SB_VERSION_1))); 349 XFS_SB_VERSION_1)));
321} 350}
322 351
323#define XFS_SB_VERSION_HASATTR(sbp) xfs_sb_version_hasattr(sbp)
324static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp) 352static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
325{ 353{
326 return ((sbp)->sb_versionnum == XFS_SB_VERSION_2) || \ 354 return ((sbp)->sb_versionnum == XFS_SB_VERSION_2) || \
@@ -329,7 +357,6 @@ static inline int xfs_sb_version_hasattr(xfs_sb_t *sbp)
329 ((sbp)->sb_versionnum & XFS_SB_VERSION_ATTRBIT)); 357 ((sbp)->sb_versionnum & XFS_SB_VERSION_ATTRBIT));
330} 358}
331 359
332#define XFS_SB_VERSION_ADDATTR(sbp) xfs_sb_version_addattr(sbp)
333static inline void xfs_sb_version_addattr(xfs_sb_t *sbp) 360static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
334{ 361{
335 (sbp)->sb_versionnum = (((sbp)->sb_versionnum == XFS_SB_VERSION_1) ? \ 362 (sbp)->sb_versionnum = (((sbp)->sb_versionnum == XFS_SB_VERSION_1) ? \
@@ -339,7 +366,6 @@ static inline void xfs_sb_version_addattr(xfs_sb_t *sbp)
339 (XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT))); 366 (XFS_SB_VERSION_4 | XFS_SB_VERSION_ATTRBIT)));
340} 367}
341 368
342#define XFS_SB_VERSION_HASNLINK(sbp) xfs_sb_version_hasnlink(sbp)
343static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp) 369static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
344{ 370{
345 return ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \ 371 return ((sbp)->sb_versionnum == XFS_SB_VERSION_3) || \
@@ -347,7 +373,6 @@ static inline int xfs_sb_version_hasnlink(xfs_sb_t *sbp)
347 ((sbp)->sb_versionnum & XFS_SB_VERSION_NLINKBIT)); 373 ((sbp)->sb_versionnum & XFS_SB_VERSION_NLINKBIT));
348} 374}
349 375
350#define XFS_SB_VERSION_ADDNLINK(sbp) xfs_sb_version_addnlink(sbp)
351static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp) 376static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
352{ 377{
353 (sbp)->sb_versionnum = ((sbp)->sb_versionnum <= XFS_SB_VERSION_2 ? \ 378 (sbp)->sb_versionnum = ((sbp)->sb_versionnum <= XFS_SB_VERSION_2 ? \
@@ -355,115 +380,63 @@ static inline void xfs_sb_version_addnlink(xfs_sb_t *sbp)
355 ((sbp)->sb_versionnum | XFS_SB_VERSION_NLINKBIT)); 380 ((sbp)->sb_versionnum | XFS_SB_VERSION_NLINKBIT));
356} 381}
357 382
358#define XFS_SB_VERSION_HASQUOTA(sbp) xfs_sb_version_hasquota(sbp)
359static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp) 383static inline int xfs_sb_version_hasquota(xfs_sb_t *sbp)
360{ 384{
361 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 385 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
362 ((sbp)->sb_versionnum & XFS_SB_VERSION_QUOTABIT); 386 ((sbp)->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
363} 387}
364 388
365#define XFS_SB_VERSION_ADDQUOTA(sbp) xfs_sb_version_addquota(sbp)
366static inline void xfs_sb_version_addquota(xfs_sb_t *sbp) 389static inline void xfs_sb_version_addquota(xfs_sb_t *sbp)
367{ 390{
368 (sbp)->sb_versionnum = \ 391 (sbp)->sb_versionnum = \
369 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 ? \ 392 (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4 ? \
370 ((sbp)->sb_versionnum | XFS_SB_VERSION_QUOTABIT) : \ 393 ((sbp)->sb_versionnum | XFS_SB_VERSION_QUOTABIT) : \
371 (XFS_SB_VERSION_TONEW((sbp)->sb_versionnum) | \ 394 (xfs_sb_version_tonew((sbp)->sb_versionnum) | \
372 XFS_SB_VERSION_QUOTABIT)); 395 XFS_SB_VERSION_QUOTABIT));
373} 396}
374 397
375#define XFS_SB_VERSION_HASALIGN(sbp) xfs_sb_version_hasalign(sbp)
376static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp) 398static inline int xfs_sb_version_hasalign(xfs_sb_t *sbp)
377{ 399{
378 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 400 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
379 ((sbp)->sb_versionnum & XFS_SB_VERSION_ALIGNBIT); 401 ((sbp)->sb_versionnum & XFS_SB_VERSION_ALIGNBIT);
380} 402}
381 403
382#define XFS_SB_VERSION_SUBALIGN(sbp) xfs_sb_version_subalign(sbp)
383static inline void xfs_sb_version_subalign(xfs_sb_t *sbp)
384{
385 (sbp)->sb_versionnum = \
386 XFS_SB_VERSION_TOOLD((sbp)->sb_versionnum & ~XFS_SB_VERSION_ALIGNBIT);
387}
388
389#define XFS_SB_VERSION_HASDALIGN(sbp) xfs_sb_version_hasdalign(sbp)
390static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp) 404static inline int xfs_sb_version_hasdalign(xfs_sb_t *sbp)
391{ 405{
392 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 406 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
393 ((sbp)->sb_versionnum & XFS_SB_VERSION_DALIGNBIT); 407 ((sbp)->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
394} 408}
395 409
396#define XFS_SB_VERSION_ADDDALIGN(sbp) xfs_sb_version_adddalign(sbp)
397static inline int xfs_sb_version_adddalign(xfs_sb_t *sbp)
398{
399 return (sbp)->sb_versionnum = \
400 ((sbp)->sb_versionnum | XFS_SB_VERSION_DALIGNBIT);
401}
402
403#define XFS_SB_VERSION_HASSHARED(sbp) xfs_sb_version_hasshared(sbp)
404static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp) 410static inline int xfs_sb_version_hasshared(xfs_sb_t *sbp)
405{ 411{
406 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 412 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
407 ((sbp)->sb_versionnum & XFS_SB_VERSION_SHAREDBIT); 413 ((sbp)->sb_versionnum & XFS_SB_VERSION_SHAREDBIT);
408} 414}
409 415
410#define XFS_SB_VERSION_ADDSHARED(sbp) xfs_sb_version_addshared(sbp)
411static inline int xfs_sb_version_addshared(xfs_sb_t *sbp)
412{
413 return (sbp)->sb_versionnum = \
414 ((sbp)->sb_versionnum | XFS_SB_VERSION_SHAREDBIT);
415}
416
417#define XFS_SB_VERSION_SUBSHARED(sbp) xfs_sb_version_subshared(sbp)
418static inline int xfs_sb_version_subshared(xfs_sb_t *sbp)
419{
420 return (sbp)->sb_versionnum = \
421 ((sbp)->sb_versionnum & ~XFS_SB_VERSION_SHAREDBIT);
422}
423
424#define XFS_SB_VERSION_HASDIRV2(sbp) xfs_sb_version_hasdirv2(sbp)
425static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp) 416static inline int xfs_sb_version_hasdirv2(xfs_sb_t *sbp)
426{ 417{
427 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 418 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
428 ((sbp)->sb_versionnum & XFS_SB_VERSION_DIRV2BIT); 419 ((sbp)->sb_versionnum & XFS_SB_VERSION_DIRV2BIT);
429} 420}
430 421
431#define XFS_SB_VERSION_HASLOGV2(sbp) xfs_sb_version_haslogv2(sbp)
432static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp) 422static inline int xfs_sb_version_haslogv2(xfs_sb_t *sbp)
433{ 423{
434 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 424 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
435 ((sbp)->sb_versionnum & XFS_SB_VERSION_LOGV2BIT); 425 ((sbp)->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
436} 426}
437 427
438#define XFS_SB_VERSION_HASEXTFLGBIT(sbp) xfs_sb_version_hasextflgbit(sbp)
439static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp) 428static inline int xfs_sb_version_hasextflgbit(xfs_sb_t *sbp)
440{ 429{
441 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 430 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
442 ((sbp)->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT); 431 ((sbp)->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
443} 432}
444 433
445#define XFS_SB_VERSION_ADDEXTFLGBIT(sbp) xfs_sb_version_addextflgbit(sbp)
446static inline int xfs_sb_version_addextflgbit(xfs_sb_t *sbp)
447{
448 return (sbp)->sb_versionnum = \
449 ((sbp)->sb_versionnum | XFS_SB_VERSION_EXTFLGBIT);
450}
451
452#define XFS_SB_VERSION_SUBEXTFLGBIT(sbp) xfs_sb_version_subextflgbit(sbp)
453static inline int xfs_sb_version_subextflgbit(xfs_sb_t *sbp)
454{
455 return (sbp)->sb_versionnum = \
456 ((sbp)->sb_versionnum & ~XFS_SB_VERSION_EXTFLGBIT);
457}
458
459#define XFS_SB_VERSION_HASSECTOR(sbp) xfs_sb_version_hassector(sbp)
460static inline int xfs_sb_version_hassector(xfs_sb_t *sbp) 434static inline int xfs_sb_version_hassector(xfs_sb_t *sbp)
461{ 435{
462 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 436 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
463 ((sbp)->sb_versionnum & XFS_SB_VERSION_SECTORBIT); 437 ((sbp)->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
464} 438}
465 439
466#define XFS_SB_VERSION_HASMOREBITS(sbp) xfs_sb_version_hasmorebits(sbp)
467static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp) 440static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
468{ 441{
469 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \ 442 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4) && \
@@ -476,24 +449,22 @@ static inline int xfs_sb_version_hasmorebits(xfs_sb_t *sbp)
476 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro: 449 * For example, for a bit defined as XFS_SB_VERSION2_FUNBIT, has a macro:
477 * 450 *
478 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp) 451 * SB_VERSION_HASFUNBIT(xfs_sb_t *sbp)
479 * ((XFS_SB_VERSION_HASMOREBITS(sbp) && 452 * ((xfs_sb_version_hasmorebits(sbp) &&
480 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT) 453 * ((sbp)->sb_features2 & XFS_SB_VERSION2_FUNBIT)
481 */ 454 */
482 455
483static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp) 456static inline int xfs_sb_version_haslazysbcount(xfs_sb_t *sbp)
484{ 457{
485 return (XFS_SB_VERSION_HASMOREBITS(sbp) && \ 458 return (xfs_sb_version_hasmorebits(sbp) && \
486 ((sbp)->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT)); 459 ((sbp)->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
487} 460}
488 461
489#define XFS_SB_VERSION_HASATTR2(sbp) xfs_sb_version_hasattr2(sbp)
490static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp) 462static inline int xfs_sb_version_hasattr2(xfs_sb_t *sbp)
491{ 463{
492 return (XFS_SB_VERSION_HASMOREBITS(sbp)) && \ 464 return (xfs_sb_version_hasmorebits(sbp)) && \
493 ((sbp)->sb_features2 & XFS_SB_VERSION2_ATTR2BIT); 465 ((sbp)->sb_features2 & XFS_SB_VERSION2_ATTR2BIT);
494} 466}
495 467
496#define XFS_SB_VERSION_ADDATTR2(sbp) xfs_sb_version_addattr2(sbp)
497static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp) 468static inline void xfs_sb_version_addattr2(xfs_sb_t *sbp)
498{ 469{
499 ((sbp)->sb_versionnum = \ 470 ((sbp)->sb_versionnum = \
diff --git a/fs/xfs/xfs_utils.c b/fs/xfs/xfs_utils.c
index 45d740df53b7..18a85e746680 100644
--- a/fs/xfs/xfs_utils.c
+++ b/fs/xfs/xfs_utils.c
@@ -339,10 +339,10 @@ xfs_bump_ino_vers2(
339 ip->i_d.di_onlink = 0; 339 ip->i_d.di_onlink = 0;
340 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad)); 340 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
341 mp = tp->t_mountp; 341 mp = tp->t_mountp;
342 if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) { 342 if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
343 spin_lock(&mp->m_sb_lock); 343 spin_lock(&mp->m_sb_lock);
344 if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) { 344 if (!xfs_sb_version_hasnlink(&mp->m_sb)) {
345 XFS_SB_VERSION_ADDNLINK(&mp->m_sb); 345 xfs_sb_version_addnlink(&mp->m_sb);
346 spin_unlock(&mp->m_sb_lock); 346 spin_unlock(&mp->m_sb_lock);
347 xfs_mod_sb(tp, XFS_SB_VERSIONNUM); 347 xfs_mod_sb(tp, XFS_SB_VERSIONNUM);
348 } else { 348 } else {
diff --git a/fs/xfs/xfs_vfsops.c b/fs/xfs/xfs_vfsops.c
index 7321304a69cc..7094caff13cf 100644
--- a/fs/xfs/xfs_vfsops.c
+++ b/fs/xfs/xfs_vfsops.c
@@ -330,7 +330,7 @@ xfs_finish_flags(
330 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); 330 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
331 331
332 /* Fail a mount where the logbuf is smaller then the log stripe */ 332 /* Fail a mount where the logbuf is smaller then the log stripe */
333 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) { 333 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
334 if ((ap->logbufsize <= 0) && 334 if ((ap->logbufsize <= 0) &&
335 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) { 335 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
336 mp->m_logbsize = mp->m_sb.sb_logsunit; 336 mp->m_logbsize = mp->m_sb.sb_logsunit;
@@ -349,9 +349,8 @@ xfs_finish_flags(
349 } 349 }
350 } 350 }
351 351
352 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) { 352 if (xfs_sb_version_hasattr2(&mp->m_sb))
353 mp->m_flags |= XFS_MOUNT_ATTR2; 353 mp->m_flags |= XFS_MOUNT_ATTR2;
354 }
355 354
356 /* 355 /*
357 * prohibit r/w mounts of read-only filesystems 356 * prohibit r/w mounts of read-only filesystems
@@ -366,7 +365,7 @@ xfs_finish_flags(
366 * check for shared mount. 365 * check for shared mount.
367 */ 366 */
368 if (ap->flags & XFSMNT_SHARED) { 367 if (ap->flags & XFSMNT_SHARED) {
369 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb)) 368 if (!xfs_sb_version_hasshared(&mp->m_sb))
370 return XFS_ERROR(EINVAL); 369 return XFS_ERROR(EINVAL);
371 370
372 /* 371 /*
@@ -512,7 +511,7 @@ xfs_mount(
512 if (!error && logdev && logdev != ddev) { 511 if (!error && logdev && logdev != ddev) {
513 unsigned int log_sector_size = BBSIZE; 512 unsigned int log_sector_size = BBSIZE;
514 513
515 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb)) 514 if (xfs_sb_version_hassector(&mp->m_sb))
516 log_sector_size = mp->m_sb.sb_logsectsize; 515 log_sector_size = mp->m_sb.sb_logsectsize;
517 error = xfs_setsize_buftarg(mp->m_logdev_targp, 516 error = xfs_setsize_buftarg(mp->m_logdev_targp,
518 mp->m_sb.sb_blocksize, 517 mp->m_sb.sb_blocksize,
diff --git a/fs/xfs/xfs_vnodeops.c b/fs/xfs/xfs_vnodeops.c
index 51305242ff8c..64c5953feca4 100644
--- a/fs/xfs/xfs_vnodeops.c
+++ b/fs/xfs/xfs_vnodeops.c
@@ -4132,7 +4132,7 @@ xfs_free_file_space(
4132 * actually need to zero the extent edges. Otherwise xfs_bunmapi 4132 * actually need to zero the extent edges. Otherwise xfs_bunmapi
4133 * will take care of it for us. 4133 * will take care of it for us.
4134 */ 4134 */
4135 if (rt && !XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb)) { 4135 if (rt && !xfs_sb_version_hasextflgbit(&mp->m_sb)) {
4136 nimap = 1; 4136 nimap = 1;
4137 error = xfs_bmapi(NULL, ip, startoffset_fsb, 4137 error = xfs_bmapi(NULL, ip, startoffset_fsb,
4138 1, 0, NULL, 0, &imap, &nimap, NULL, NULL); 4138 1, 0, NULL, 0, &imap, &nimap, NULL, NULL);