aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorFelix Blyakher <felixb@sgi.com>2009-03-30 23:08:33 -0400
committerFelix Blyakher <felixb@sgi.com>2009-03-30 23:08:33 -0400
commit930861c4e6f13ce2e7d06cd1ef11441a065517d9 (patch)
treedf6ff01f89768ff8d6fe6a64491be30e6e56c3e0 /fs
parent8b112171734c791afaf43ccc8c6ec492e7006e44 (diff)
parent15f7176eb1cccec0a332541285ee752b935c1c85 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'fs')
-rw-r--r--fs/9p/v9fs_vfs.h4
-rw-r--r--fs/9p/vfs_dentry.c4
-rw-r--r--fs/9p/vfs_super.c5
-rw-r--r--fs/Kconfig56
-rw-r--r--fs/Makefile6
-rw-r--r--fs/adfs/adfs.h2
-rw-r--r--fs/adfs/dir.c2
-rw-r--r--fs/affs/affs.h3
-rw-r--r--fs/affs/amigaffs.c8
-rw-r--r--fs/affs/namei.c4
-rw-r--r--fs/afs/dir.c2
-rw-r--r--fs/afs/proc.c1
-rw-r--r--fs/anon_inodes.c2
-rw-r--r--fs/attr.c3
-rw-r--r--fs/autofs/root.c2
-rw-r--r--fs/autofs4/inode.c2
-rw-r--r--fs/autofs4/root.c4
-rw-r--r--fs/bio-integrity.c85
-rw-r--r--fs/bio.c87
-rw-r--r--fs/block_dev.c146
-rw-r--r--fs/btrfs/disk-io.c2
-rw-r--r--fs/buffer.c145
-rw-r--r--fs/cifs/CHANGES11
-rw-r--r--fs/cifs/Kconfig21
-rw-r--r--fs/cifs/README22
-rw-r--r--fs/cifs/cifs_debug.c3
-rw-r--r--fs/cifs/cifs_dfs_ref.c36
-rw-r--r--fs/cifs/cifs_fs_sb.h1
-rw-r--r--fs/cifs/cifsfs.c3
-rw-r--r--fs/cifs/cifsfs.h4
-rw-r--r--fs/cifs/cifsglob.h2
-rw-r--r--fs/cifs/cifspdu.h76
-rw-r--r--fs/cifs/cifsproto.h9
-rw-r--r--fs/cifs/cifssmb.c27
-rw-r--r--fs/cifs/connect.c9
-rw-r--r--fs/cifs/dir.c10
-rw-r--r--fs/cifs/file.c199
-rw-r--r--fs/cifs/inode.c3
-rw-r--r--fs/cifs/smbfsctl.h84
-rw-r--r--fs/coda/dir.c2
-rw-r--r--fs/compat.c45
-rw-r--r--fs/compat_ioctl.c8
-rw-r--r--fs/configfs/dir.c2
-rw-r--r--fs/dcache.c48
-rw-r--r--fs/devpts/inode.c188
-rw-r--r--fs/dlm/dir.c18
-rw-r--r--fs/dlm/dlm_internal.h2
-rw-r--r--fs/dlm/lock.c60
-rw-r--r--fs/dlm/lockspace.c2
-rw-r--r--fs/dlm/lowcomms.c181
-rw-r--r--fs/dlm/user.c24
-rw-r--r--fs/drop_caches.c2
-rw-r--r--fs/ecryptfs/dentry.c2
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h2
-rw-r--r--fs/eventpoll.c12
-rw-r--r--fs/exec.c23
-rw-r--r--fs/ext2/balloc.c8
-rw-r--r--fs/ext2/ialloc.c10
-rw-r--r--fs/ext2/inode.c2
-rw-r--r--fs/ext2/super.c1
-rw-r--r--fs/ext2/xattr.c8
-rw-r--r--fs/ext3/balloc.c8
-rw-r--r--fs/ext3/ialloc.c12
-rw-r--r--fs/ext3/inode.c24
-rw-r--r--fs/ext3/namei.c6
-rw-r--r--fs/ext3/super.c48
-rw-r--r--fs/ext3/xattr.c6
-rw-r--r--fs/ext4/balloc.c2
-rw-r--r--fs/ext4/ext4.h2
-rw-r--r--fs/ext4/ialloc.c12
-rw-r--r--fs/ext4/inode.c40
-rw-r--r--fs/ext4/mballoc.c46
-rw-r--r--fs/ext4/namei.c6
-rw-r--r--fs/ext4/super.c54
-rw-r--r--fs/ext4/xattr.c6
-rw-r--r--fs/fat/namei_msdos.c2
-rw-r--r--fs/fat/namei_vfat.c4
-rw-r--r--fs/fcntl.c37
-rw-r--r--fs/file_table.c3
-rw-r--r--fs/fuse/dir.c2
-rw-r--r--fs/fuse/file.c3
-rw-r--r--fs/fuse/fuse_i.h2
-rw-r--r--fs/gfs2/Kconfig17
-rw-r--r--fs/gfs2/Makefile4
-rw-r--r--fs/gfs2/acl.c1
-rw-r--r--fs/gfs2/bmap.c1
-rw-r--r--fs/gfs2/dir.c1
-rw-r--r--fs/gfs2/eaops.c1
-rw-r--r--fs/gfs2/eattr.c1
-rw-r--r--fs/gfs2/glock.c268
-rw-r--r--fs/gfs2/glock.h127
-rw-r--r--fs/gfs2/glops.c160
-rw-r--r--fs/gfs2/glops.h1
-rw-r--r--fs/gfs2/incore.h71
-rw-r--r--fs/gfs2/inode.c13
-rw-r--r--fs/gfs2/inode.h22
-rw-r--r--fs/gfs2/lock_dlm.c241
-rw-r--r--fs/gfs2/locking.c232
-rw-r--r--fs/gfs2/locking/dlm/Makefile3
-rw-r--r--fs/gfs2/locking/dlm/lock.c708
-rw-r--r--fs/gfs2/locking/dlm/lock_dlm.h166
-rw-r--r--fs/gfs2/locking/dlm/main.c48
-rw-r--r--fs/gfs2/locking/dlm/mount.c276
-rw-r--r--fs/gfs2/locking/dlm/sysfs.c226
-rw-r--r--fs/gfs2/locking/dlm/thread.c68
-rw-r--r--fs/gfs2/log.c1
-rw-r--r--fs/gfs2/lops.c1
-rw-r--r--fs/gfs2/main.c13
-rw-r--r--fs/gfs2/meta_io.c22
-rw-r--r--fs/gfs2/meta_io.h1
-rw-r--r--fs/gfs2/mount.c128
-rw-r--r--fs/gfs2/mount.h17
-rw-r--r--fs/gfs2/ops_address.c5
-rw-r--r--fs/gfs2/ops_dentry.c3
-rw-r--r--fs/gfs2/ops_export.c1
-rw-r--r--fs/gfs2/ops_file.c76
-rw-r--r--fs/gfs2/ops_fstype.c156
-rw-r--r--fs/gfs2/ops_inode.c1
-rw-r--r--fs/gfs2/ops_super.c44
-rw-r--r--fs/gfs2/quota.c203
-rw-r--r--fs/gfs2/quota.h2
-rw-r--r--fs/gfs2/recovery.c28
-rw-r--r--fs/gfs2/rgrp.c189
-rw-r--r--fs/gfs2/super.c3
-rw-r--r--fs/gfs2/super.h28
-rw-r--r--fs/gfs2/sys.c236
-rw-r--r--fs/gfs2/trans.c19
-rw-r--r--fs/gfs2/util.c11
-rw-r--r--fs/hfs/hfs_fs.h2
-rw-r--r--fs/hfs/sysdep.c2
-rw-r--r--fs/hfsplus/hfsplus_fs.h2
-rw-r--r--fs/hfsplus/inode.c2
-rw-r--r--fs/hostfs/hostfs_kern.c4
-rw-r--r--fs/hpfs/dentry.c2
-rw-r--r--fs/inode.c77
-rw-r--r--fs/internal.h2
-rw-r--r--fs/ioctl.c18
-rw-r--r--fs/isofs/inode.c2
-rw-r--r--fs/jfs/Kconfig1
-rw-r--r--fs/jfs/acl.c2
-rw-r--r--fs/jfs/inode.c6
-rw-r--r--fs/jfs/jfs_debug.c1
-rw-r--r--fs/jfs/jfs_dtree.c18
-rw-r--r--fs/jfs/jfs_extent.c73
-rw-r--r--fs/jfs/jfs_imap.c10
-rw-r--r--fs/jfs/jfs_inode.c4
-rw-r--r--fs/jfs/jfs_inode.h2
-rw-r--r--fs/jfs/jfs_metapage.c18
-rw-r--r--fs/jfs/jfs_types.h29
-rw-r--r--fs/jfs/jfs_xtree.c277
-rw-r--r--fs/jfs/jfs_xtree.h2
-rw-r--r--fs/jfs/namei.c10
-rw-r--r--fs/jfs/super.c4
-rw-r--r--fs/jfs/xattr.c12
-rw-r--r--fs/libfs.c5
-rw-r--r--fs/namei.c56
-rw-r--r--fs/namespace.c14
-rw-r--r--fs/ncpfs/dir.c4
-rw-r--r--fs/nfs/client.c2
-rw-r--r--fs/nfs/dir.c4
-rw-r--r--fs/nfs/nfs4_fs.h2
-rw-r--r--fs/nfsd/vfs.c9
-rw-r--r--fs/notify/inotify/inotify.c16
-rw-r--r--fs/ocfs2/dcache.c2
-rw-r--r--fs/ocfs2/dcache.h2
-rw-r--r--fs/open.c2
-rw-r--r--fs/partitions/check.c10
-rw-r--r--fs/partitions/ibm.c101
-rw-r--r--fs/pipe.c23
-rw-r--r--fs/proc/base.c56
-rw-r--r--fs/proc/generic.c65
-rw-r--r--fs/proc/inode-alloc.txt14
-rw-r--r--fs/proc/inode.c21
-rw-r--r--fs/proc/internal.h1
-rw-r--r--fs/proc/proc_sysctl.c4
-rw-r--r--fs/proc/proc_tty.c1
-rw-r--r--fs/proc/root.c3
-rw-r--r--fs/proc/task_mmu.c8
-rw-r--r--fs/proc/uptime.c38
-rw-r--r--fs/quota/Kconfig59
-rw-r--r--fs/quota/Makefile14
-rw-r--r--fs/quota/dquot.c (renamed from fs/dquot.c)577
-rw-r--r--fs/quota/quota.c (renamed from fs/quota.c)37
-rw-r--r--fs/quota/quota_tree.c (renamed from fs/quota_tree.c)132
-rw-r--r--fs/quota/quota_tree.h (renamed from fs/quota_tree.h)0
-rw-r--r--fs/quota/quota_v1.c (renamed from fs/quota_v1.c)48
-rw-r--r--fs/quota/quota_v2.c (renamed from fs/quota_v2.c)3
-rw-r--r--fs/quota/quotaio_v1.h (renamed from fs/quotaio_v1.h)0
-rw-r--r--fs/quota/quotaio_v2.h (renamed from fs/quotaio_v2.h)0
-rw-r--r--fs/ramfs/file-nommu.c6
-rw-r--r--fs/reiserfs/Makefile4
-rw-r--r--fs/reiserfs/README4
-rw-r--r--fs/reiserfs/bitmap.c86
-rw-r--r--fs/reiserfs/dir.c28
-rw-r--r--fs/reiserfs/do_balan.c313
-rw-r--r--fs/reiserfs/file.c34
-rw-r--r--fs/reiserfs/fix_node.c1021
-rw-r--r--fs/reiserfs/hashes.c2
-rw-r--r--fs/reiserfs/ibalance.c22
-rw-r--r--fs/reiserfs/inode.c213
-rw-r--r--fs/reiserfs/ioctl.c2
-rw-r--r--fs/reiserfs/item_ops.c68
-rw-r--r--fs/reiserfs/journal.c1077
-rw-r--r--fs/reiserfs/lbalance.c66
-rw-r--r--fs/reiserfs/namei.c186
-rw-r--r--fs/reiserfs/objectid.c12
-rw-r--r--fs/reiserfs/prints.c134
-rw-r--r--fs/reiserfs/procfs.c16
-rw-r--r--fs/reiserfs/resize.c6
-rw-r--r--fs/reiserfs/stree.c1174
-rw-r--r--fs/reiserfs/super.c363
-rw-r--r--fs/reiserfs/tail_conversion.c96
-rw-r--r--fs/reiserfs/xattr.c1377
-rw-r--r--fs/reiserfs/xattr_acl.c257
-rw-r--r--fs/reiserfs/xattr_security.c80
-rw-r--r--fs/reiserfs/xattr_trusted.c45
-rw-r--r--fs/reiserfs/xattr_user.c31
-rw-r--r--fs/seq_file.c2
-rw-r--r--fs/smbfs/dir.c4
-rw-r--r--fs/super.c28
-rw-r--r--fs/sync.c16
-rw-r--r--fs/sysfs/bin.c253
-rw-r--r--fs/sysfs/dir.c35
-rw-r--r--fs/sysfs/file.c26
-rw-r--r--fs/sysfs/inode.c17
-rw-r--r--fs/sysfs/mount.c6
-rw-r--r--fs/sysfs/sysfs.h3
-rw-r--r--fs/sysv/namei.c2
-rw-r--r--fs/sysv/sysv.h2
-rw-r--r--fs/ubifs/super.c3
-rw-r--r--fs/udf/balloc.c14
-rw-r--r--fs/udf/ialloc.c8
-rw-r--r--fs/ufs/balloc.c12
-rw-r--r--fs/ufs/ialloc.c8
-rw-r--r--fs/ufs/inode.c39
-rw-r--r--fs/ufs/namei.c2
-rw-r--r--fs/ufs/super.c11
-rw-r--r--fs/ufs/ufs.h2
238 files changed, 7093 insertions, 7952 deletions
diff --git a/fs/9p/v9fs_vfs.h b/fs/9p/v9fs_vfs.h
index c295ba786ed..f0c7de78e20 100644
--- a/fs/9p/v9fs_vfs.h
+++ b/fs/9p/v9fs_vfs.h
@@ -41,8 +41,8 @@ extern struct file_system_type v9fs_fs_type;
41extern const struct address_space_operations v9fs_addr_operations; 41extern const struct address_space_operations v9fs_addr_operations;
42extern const struct file_operations v9fs_file_operations; 42extern const struct file_operations v9fs_file_operations;
43extern const struct file_operations v9fs_dir_operations; 43extern const struct file_operations v9fs_dir_operations;
44extern struct dentry_operations v9fs_dentry_operations; 44extern const struct dentry_operations v9fs_dentry_operations;
45extern struct dentry_operations v9fs_cached_dentry_operations; 45extern const struct dentry_operations v9fs_cached_dentry_operations;
46 46
47struct inode *v9fs_get_inode(struct super_block *sb, int mode); 47struct inode *v9fs_get_inode(struct super_block *sb, int mode);
48ino_t v9fs_qid2ino(struct p9_qid *qid); 48ino_t v9fs_qid2ino(struct p9_qid *qid);
diff --git a/fs/9p/vfs_dentry.c b/fs/9p/vfs_dentry.c
index 06dcc7c4f23..d74325295b1 100644
--- a/fs/9p/vfs_dentry.c
+++ b/fs/9p/vfs_dentry.c
@@ -104,12 +104,12 @@ void v9fs_dentry_release(struct dentry *dentry)
104 } 104 }
105} 105}
106 106
107struct dentry_operations v9fs_cached_dentry_operations = { 107const struct dentry_operations v9fs_cached_dentry_operations = {
108 .d_delete = v9fs_cached_dentry_delete, 108 .d_delete = v9fs_cached_dentry_delete,
109 .d_release = v9fs_dentry_release, 109 .d_release = v9fs_dentry_release,
110}; 110};
111 111
112struct dentry_operations v9fs_dentry_operations = { 112const struct dentry_operations v9fs_dentry_operations = {
113 .d_delete = v9fs_dentry_delete, 113 .d_delete = v9fs_dentry_delete,
114 .d_release = v9fs_dentry_release, 114 .d_release = v9fs_dentry_release,
115}; 115};
diff --git a/fs/9p/vfs_super.c b/fs/9p/vfs_super.c
index 93212e40221..5f8ab8adb5f 100644
--- a/fs/9p/vfs_super.c
+++ b/fs/9p/vfs_super.c
@@ -168,8 +168,9 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
168 p9stat_free(st); 168 p9stat_free(st);
169 kfree(st); 169 kfree(st);
170 170
171P9_DPRINTK(P9_DEBUG_VFS, " return simple set mount\n"); 171P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n");
172 return simple_set_mnt(mnt, sb); 172 simple_set_mnt(mnt, sb);
173 return 0;
173 174
174release_sb: 175release_sb:
175 if (sb) { 176 if (sb) {
diff --git a/fs/Kconfig b/fs/Kconfig
index 93945dd0b1a..cef8b18ceaa 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -56,61 +56,7 @@ endif # BLOCK
56 56
57source "fs/notify/Kconfig" 57source "fs/notify/Kconfig"
58 58
59config QUOTA 59source "fs/quota/Kconfig"
60 bool "Quota support"
61 help
62 If you say Y here, you will be able to set per user limits for disk
63 usage (also called disk quotas). Currently, it works for the
64 ext2, ext3, and reiserfs file system. ext3 also supports journalled
65 quotas for which you don't need to run quotacheck(8) after an unclean
66 shutdown.
67 For further details, read the Quota mini-HOWTO, available from
68 <http://www.tldp.org/docs.html#howto>, or the documentation provided
69 with the quota tools. Probably the quota support is only useful for
70 multi user systems. If unsure, say N.
71
72config QUOTA_NETLINK_INTERFACE
73 bool "Report quota messages through netlink interface"
74 depends on QUOTA && NET
75 help
76 If you say Y here, quota warnings (about exceeding softlimit, reaching
77 hardlimit, etc.) will be reported through netlink interface. If unsure,
78 say Y.
79
80config PRINT_QUOTA_WARNING
81 bool "Print quota warnings to console (OBSOLETE)"
82 depends on QUOTA
83 default y
84 help
85 If you say Y here, quota warnings (about exceeding softlimit, reaching
86 hardlimit, etc.) will be printed to the process' controlling terminal.
87 Note that this behavior is currently deprecated and may go away in
88 future. Please use notification via netlink socket instead.
89
90# Generic support for tree structured quota files. Seleted when needed.
91config QUOTA_TREE
92 tristate
93
94config QFMT_V1
95 tristate "Old quota format support"
96 depends on QUOTA
97 help
98 This quota format was (is) used by kernels earlier than 2.4.22. If
99 you have quota working and you don't want to convert to new quota
100 format say Y here.
101
102config QFMT_V2
103 tristate "Quota format v2 support"
104 depends on QUOTA
105 select QUOTA_TREE
106 help
107 This quota format allows using quotas with 32-bit UIDs/GIDs. If you
108 need this functionality say Y here.
109
110config QUOTACTL
111 bool
112 depends on XFS_QUOTA || QUOTA
113 default y
114 60
115source "fs/autofs/Kconfig" 61source "fs/autofs/Kconfig"
116source "fs/autofs4/Kconfig" 62source "fs/autofs4/Kconfig"
diff --git a/fs/Makefile b/fs/Makefile
index dc20db34867..6e82a307bcd 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -51,11 +51,7 @@ obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o xattr_acl.o
51obj-$(CONFIG_NFS_COMMON) += nfs_common/ 51obj-$(CONFIG_NFS_COMMON) += nfs_common/
52obj-$(CONFIG_GENERIC_ACL) += generic_acl.o 52obj-$(CONFIG_GENERIC_ACL) += generic_acl.o
53 53
54obj-$(CONFIG_QUOTA) += dquot.o 54obj-y += quota/
55obj-$(CONFIG_QFMT_V1) += quota_v1.o
56obj-$(CONFIG_QFMT_V2) += quota_v2.o
57obj-$(CONFIG_QUOTA_TREE) += quota_tree.o
58obj-$(CONFIG_QUOTACTL) += quota.o
59 55
60obj-$(CONFIG_PROC_FS) += proc/ 56obj-$(CONFIG_PROC_FS) += proc/
61obj-y += partitions/ 57obj-y += partitions/
diff --git a/fs/adfs/adfs.h b/fs/adfs/adfs.h
index 831157502d5..e0a85dbeeb8 100644
--- a/fs/adfs/adfs.h
+++ b/fs/adfs/adfs.h
@@ -86,7 +86,7 @@ void __adfs_error(struct super_block *sb, const char *function,
86/* dir_*.c */ 86/* dir_*.c */
87extern const struct inode_operations adfs_dir_inode_operations; 87extern const struct inode_operations adfs_dir_inode_operations;
88extern const struct file_operations adfs_dir_operations; 88extern const struct file_operations adfs_dir_operations;
89extern struct dentry_operations adfs_dentry_operations; 89extern const struct dentry_operations adfs_dentry_operations;
90extern struct adfs_dir_ops adfs_f_dir_ops; 90extern struct adfs_dir_ops adfs_f_dir_ops;
91extern struct adfs_dir_ops adfs_fplus_dir_ops; 91extern struct adfs_dir_ops adfs_fplus_dir_ops;
92 92
diff --git a/fs/adfs/dir.c b/fs/adfs/dir.c
index 85a30e92980..e867ccf3724 100644
--- a/fs/adfs/dir.c
+++ b/fs/adfs/dir.c
@@ -263,7 +263,7 @@ adfs_compare(struct dentry *parent, struct qstr *entry, struct qstr *name)
263 return 0; 263 return 0;
264} 264}
265 265
266struct dentry_operations adfs_dentry_operations = { 266const struct dentry_operations adfs_dentry_operations = {
267 .d_hash = adfs_hash, 267 .d_hash = adfs_hash,
268 .d_compare = adfs_compare, 268 .d_compare = adfs_compare,
269}; 269};
diff --git a/fs/affs/affs.h b/fs/affs/affs.h
index e9ec915f755..1a2d5e3c7f4 100644
--- a/fs/affs/affs.h
+++ b/fs/affs/affs.h
@@ -199,8 +199,7 @@ extern const struct address_space_operations affs_symlink_aops;
199extern const struct address_space_operations affs_aops; 199extern const struct address_space_operations affs_aops;
200extern const struct address_space_operations affs_aops_ofs; 200extern const struct address_space_operations affs_aops_ofs;
201 201
202extern struct dentry_operations affs_dentry_operations; 202extern const struct dentry_operations affs_dentry_operations;
203extern struct dentry_operations affs_dentry_operations_intl;
204 203
205static inline void 204static inline void
206affs_set_blocksize(struct super_block *sb, int size) 205affs_set_blocksize(struct super_block *sb, int size)
diff --git a/fs/affs/amigaffs.c b/fs/affs/amigaffs.c
index 805573005de..7d0f0a30f7a 100644
--- a/fs/affs/amigaffs.c
+++ b/fs/affs/amigaffs.c
@@ -179,14 +179,18 @@ affs_remove_link(struct dentry *dentry)
179 affs_lock_dir(dir); 179 affs_lock_dir(dir);
180 affs_fix_dcache(dentry, link_ino); 180 affs_fix_dcache(dentry, link_ino);
181 retval = affs_remove_hash(dir, link_bh); 181 retval = affs_remove_hash(dir, link_bh);
182 if (retval) 182 if (retval) {
183 affs_unlock_dir(dir);
183 goto done; 184 goto done;
185 }
184 mark_buffer_dirty_inode(link_bh, inode); 186 mark_buffer_dirty_inode(link_bh, inode);
185 187
186 memcpy(AFFS_TAIL(sb, bh)->name, AFFS_TAIL(sb, link_bh)->name, 32); 188 memcpy(AFFS_TAIL(sb, bh)->name, AFFS_TAIL(sb, link_bh)->name, 32);
187 retval = affs_insert_hash(dir, bh); 189 retval = affs_insert_hash(dir, bh);
188 if (retval) 190 if (retval) {
191 affs_unlock_dir(dir);
189 goto done; 192 goto done;
193 }
190 mark_buffer_dirty_inode(bh, inode); 194 mark_buffer_dirty_inode(bh, inode);
191 195
192 affs_unlock_dir(dir); 196 affs_unlock_dir(dir);
diff --git a/fs/affs/namei.c b/fs/affs/namei.c
index cfcf1b6cf82..960d336ec69 100644
--- a/fs/affs/namei.c
+++ b/fs/affs/namei.c
@@ -19,12 +19,12 @@ static int affs_intl_toupper(int ch);
19static int affs_intl_hash_dentry(struct dentry *, struct qstr *); 19static int affs_intl_hash_dentry(struct dentry *, struct qstr *);
20static int affs_intl_compare_dentry(struct dentry *, struct qstr *, struct qstr *); 20static int affs_intl_compare_dentry(struct dentry *, struct qstr *, struct qstr *);
21 21
22struct dentry_operations affs_dentry_operations = { 22const struct dentry_operations affs_dentry_operations = {
23 .d_hash = affs_hash_dentry, 23 .d_hash = affs_hash_dentry,
24 .d_compare = affs_compare_dentry, 24 .d_compare = affs_compare_dentry,
25}; 25};
26 26
27static struct dentry_operations affs_intl_dentry_operations = { 27static const struct dentry_operations affs_intl_dentry_operations = {
28 .d_hash = affs_intl_hash_dentry, 28 .d_hash = affs_intl_hash_dentry,
29 .d_compare = affs_intl_compare_dentry, 29 .d_compare = affs_intl_compare_dentry,
30}; 30};
diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index 99cf390641f..9bd757774c9 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -62,7 +62,7 @@ const struct inode_operations afs_dir_inode_operations = {
62 .setattr = afs_setattr, 62 .setattr = afs_setattr,
63}; 63};
64 64
65static struct dentry_operations afs_fs_dentry_operations = { 65static const struct dentry_operations afs_fs_dentry_operations = {
66 .d_revalidate = afs_d_revalidate, 66 .d_revalidate = afs_d_revalidate,
67 .d_delete = afs_d_delete, 67 .d_delete = afs_d_delete,
68 .d_release = afs_d_release, 68 .d_release = afs_d_release,
diff --git a/fs/afs/proc.c b/fs/afs/proc.c
index 7578c1ab9e0..8630615e57f 100644
--- a/fs/afs/proc.c
+++ b/fs/afs/proc.c
@@ -146,7 +146,6 @@ int afs_proc_init(void)
146 proc_afs = proc_mkdir("fs/afs", NULL); 146 proc_afs = proc_mkdir("fs/afs", NULL);
147 if (!proc_afs) 147 if (!proc_afs)
148 goto error_dir; 148 goto error_dir;
149 proc_afs->owner = THIS_MODULE;
150 149
151 p = proc_create("cells", 0, proc_afs, &afs_proc_cells_fops); 150 p = proc_create("cells", 0, proc_afs, &afs_proc_cells_fops);
152 if (!p) 151 if (!p)
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 3bbdb9d0237..1dd96d4406c 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -48,7 +48,7 @@ static struct file_system_type anon_inode_fs_type = {
48 .get_sb = anon_inodefs_get_sb, 48 .get_sb = anon_inodefs_get_sb,
49 .kill_sb = kill_anon_super, 49 .kill_sb = kill_anon_super,
50}; 50};
51static struct dentry_operations anon_inodefs_dentry_operations = { 51static const struct dentry_operations anon_inodefs_dentry_operations = {
52 .d_delete = anon_inodefs_delete_dentry, 52 .d_delete = anon_inodefs_delete_dentry,
53}; 53};
54 54
diff --git a/fs/attr.c b/fs/attr.c
index f4360192a93..9fe1b1bd30a 100644
--- a/fs/attr.c
+++ b/fs/attr.c
@@ -173,7 +173,8 @@ int notify_change(struct dentry * dentry, struct iattr * attr)
173 if (!error) { 173 if (!error) {
174 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) || 174 if ((ia_valid & ATTR_UID && attr->ia_uid != inode->i_uid) ||
175 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid)) 175 (ia_valid & ATTR_GID && attr->ia_gid != inode->i_gid))
176 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0; 176 error = vfs_dq_transfer(inode, attr) ?
177 -EDQUOT : 0;
177 if (!error) 178 if (!error)
178 error = inode_setattr(inode, attr); 179 error = inode_setattr(inode, attr);
179 } 180 }
diff --git a/fs/autofs/root.c b/fs/autofs/root.c
index 8aacade5695..4a1401cea0a 100644
--- a/fs/autofs/root.c
+++ b/fs/autofs/root.c
@@ -192,7 +192,7 @@ static int autofs_revalidate(struct dentry * dentry, struct nameidata *nd)
192 return 1; 192 return 1;
193} 193}
194 194
195static struct dentry_operations autofs_dentry_operations = { 195static const struct dentry_operations autofs_dentry_operations = {
196 .d_revalidate = autofs_revalidate, 196 .d_revalidate = autofs_revalidate,
197}; 197};
198 198
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 716e12b627b..69c8142da83 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -310,7 +310,7 @@ static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)
310 return ino; 310 return ino;
311} 311}
312 312
313static struct dentry_operations autofs4_sb_dentry_operations = { 313static const struct dentry_operations autofs4_sb_dentry_operations = {
314 .d_release = autofs4_dentry_release, 314 .d_release = autofs4_dentry_release,
315}; 315};
316 316
diff --git a/fs/autofs4/root.c b/fs/autofs4/root.c
index 2a41c2a7fc5..74b1469a950 100644
--- a/fs/autofs4/root.c
+++ b/fs/autofs4/root.c
@@ -349,13 +349,13 @@ void autofs4_dentry_release(struct dentry *de)
349} 349}
350 350
351/* For dentries of directories in the root dir */ 351/* For dentries of directories in the root dir */
352static struct dentry_operations autofs4_root_dentry_operations = { 352static const struct dentry_operations autofs4_root_dentry_operations = {
353 .d_revalidate = autofs4_revalidate, 353 .d_revalidate = autofs4_revalidate,
354 .d_release = autofs4_dentry_release, 354 .d_release = autofs4_dentry_release,
355}; 355};
356 356
357/* For other dentries */ 357/* For other dentries */
358static struct dentry_operations autofs4_dentry_operations = { 358static const struct dentry_operations autofs4_dentry_operations = {
359 .d_revalidate = autofs4_revalidate, 359 .d_revalidate = autofs4_revalidate,
360 .d_release = autofs4_dentry_release, 360 .d_release = autofs4_dentry_release,
361}; 361};
diff --git a/fs/bio-integrity.c b/fs/bio-integrity.c
index fe2b1aa2464..31c46a241ba 100644
--- a/fs/bio-integrity.c
+++ b/fs/bio-integrity.c
@@ -26,23 +26,23 @@
26#include <linux/workqueue.h> 26#include <linux/workqueue.h>
27 27
28static struct kmem_cache *bio_integrity_slab __read_mostly; 28static struct kmem_cache *bio_integrity_slab __read_mostly;
29static mempool_t *bio_integrity_pool;
30static struct bio_set *integrity_bio_set;
29static struct workqueue_struct *kintegrityd_wq; 31static struct workqueue_struct *kintegrityd_wq;
30 32
31/** 33/**
32 * bio_integrity_alloc_bioset - Allocate integrity payload and attach it to bio 34 * bio_integrity_alloc - Allocate integrity payload and attach it to bio
33 * @bio: bio to attach integrity metadata to 35 * @bio: bio to attach integrity metadata to
34 * @gfp_mask: Memory allocation mask 36 * @gfp_mask: Memory allocation mask
35 * @nr_vecs: Number of integrity metadata scatter-gather elements 37 * @nr_vecs: Number of integrity metadata scatter-gather elements
36 * @bs: bio_set to allocate from
37 * 38 *
38 * Description: This function prepares a bio for attaching integrity 39 * Description: This function prepares a bio for attaching integrity
39 * metadata. nr_vecs specifies the maximum number of pages containing 40 * metadata. nr_vecs specifies the maximum number of pages containing
40 * integrity metadata that can be attached. 41 * integrity metadata that can be attached.
41 */ 42 */
42struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio, 43struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
43 gfp_t gfp_mask, 44 gfp_t gfp_mask,
44 unsigned int nr_vecs, 45 unsigned int nr_vecs)
45 struct bio_set *bs)
46{ 46{
47 struct bio_integrity_payload *bip; 47 struct bio_integrity_payload *bip;
48 struct bio_vec *iv; 48 struct bio_vec *iv;
@@ -50,7 +50,7 @@ struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio,
50 50
51 BUG_ON(bio == NULL); 51 BUG_ON(bio == NULL);
52 52
53 bip = mempool_alloc(bs->bio_integrity_pool, gfp_mask); 53 bip = mempool_alloc(bio_integrity_pool, gfp_mask);
54 if (unlikely(bip == NULL)) { 54 if (unlikely(bip == NULL)) {
55 printk(KERN_ERR "%s: could not alloc bip\n", __func__); 55 printk(KERN_ERR "%s: could not alloc bip\n", __func__);
56 return NULL; 56 return NULL;
@@ -58,10 +58,10 @@ struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio,
58 58
59 memset(bip, 0, sizeof(*bip)); 59 memset(bip, 0, sizeof(*bip));
60 60
61 iv = bvec_alloc_bs(gfp_mask, nr_vecs, &idx, bs); 61 iv = bvec_alloc_bs(gfp_mask, nr_vecs, &idx, integrity_bio_set);
62 if (unlikely(iv == NULL)) { 62 if (unlikely(iv == NULL)) {
63 printk(KERN_ERR "%s: could not alloc bip_vec\n", __func__); 63 printk(KERN_ERR "%s: could not alloc bip_vec\n", __func__);
64 mempool_free(bip, bs->bio_integrity_pool); 64 mempool_free(bip, bio_integrity_pool);
65 return NULL; 65 return NULL;
66 } 66 }
67 67
@@ -72,35 +72,16 @@ struct bio_integrity_payload *bio_integrity_alloc_bioset(struct bio *bio,
72 72
73 return bip; 73 return bip;
74} 74}
75EXPORT_SYMBOL(bio_integrity_alloc_bioset);
76
77/**
78 * bio_integrity_alloc - Allocate integrity payload and attach it to bio
79 * @bio: bio to attach integrity metadata to
80 * @gfp_mask: Memory allocation mask
81 * @nr_vecs: Number of integrity metadata scatter-gather elements
82 *
83 * Description: This function prepares a bio for attaching integrity
84 * metadata. nr_vecs specifies the maximum number of pages containing
85 * integrity metadata that can be attached.
86 */
87struct bio_integrity_payload *bio_integrity_alloc(struct bio *bio,
88 gfp_t gfp_mask,
89 unsigned int nr_vecs)
90{
91 return bio_integrity_alloc_bioset(bio, gfp_mask, nr_vecs, fs_bio_set);
92}
93EXPORT_SYMBOL(bio_integrity_alloc); 75EXPORT_SYMBOL(bio_integrity_alloc);
94 76
95/** 77/**
96 * bio_integrity_free - Free bio integrity payload 78 * bio_integrity_free - Free bio integrity payload
97 * @bio: bio containing bip to be freed 79 * @bio: bio containing bip to be freed
98 * @bs: bio_set this bio was allocated from
99 * 80 *
100 * Description: Used to free the integrity portion of a bio. Usually 81 * Description: Used to free the integrity portion of a bio. Usually
101 * called from bio_free(). 82 * called from bio_free().
102 */ 83 */
103void bio_integrity_free(struct bio *bio, struct bio_set *bs) 84void bio_integrity_free(struct bio *bio)
104{ 85{
105 struct bio_integrity_payload *bip = bio->bi_integrity; 86 struct bio_integrity_payload *bip = bio->bi_integrity;
106 87
@@ -111,8 +92,8 @@ void bio_integrity_free(struct bio *bio, struct bio_set *bs)
111 && bip->bip_buf != NULL) 92 && bip->bip_buf != NULL)
112 kfree(bip->bip_buf); 93 kfree(bip->bip_buf);
113 94
114 bvec_free_bs(bs, bip->bip_vec, bip->bip_pool); 95 bvec_free_bs(integrity_bio_set, bip->bip_vec, bip->bip_pool);
115 mempool_free(bip, bs->bio_integrity_pool); 96 mempool_free(bip, bio_integrity_pool);
116 97
117 bio->bi_integrity = NULL; 98 bio->bi_integrity = NULL;
118} 99}
@@ -686,19 +667,17 @@ EXPORT_SYMBOL(bio_integrity_split);
686 * @bio: New bio 667 * @bio: New bio
687 * @bio_src: Original bio 668 * @bio_src: Original bio
688 * @gfp_mask: Memory allocation mask 669 * @gfp_mask: Memory allocation mask
689 * @bs: bio_set to allocate bip from
690 * 670 *
691 * Description: Called to allocate a bip when cloning a bio 671 * Description: Called to allocate a bip when cloning a bio
692 */ 672 */
693int bio_integrity_clone(struct bio *bio, struct bio *bio_src, 673int bio_integrity_clone(struct bio *bio, struct bio *bio_src, gfp_t gfp_mask)
694 gfp_t gfp_mask, struct bio_set *bs)
695{ 674{
696 struct bio_integrity_payload *bip_src = bio_src->bi_integrity; 675 struct bio_integrity_payload *bip_src = bio_src->bi_integrity;
697 struct bio_integrity_payload *bip; 676 struct bio_integrity_payload *bip;
698 677
699 BUG_ON(bip_src == NULL); 678 BUG_ON(bip_src == NULL);
700 679
701 bip = bio_integrity_alloc_bioset(bio, gfp_mask, bip_src->bip_vcnt, bs); 680 bip = bio_integrity_alloc(bio, gfp_mask, bip_src->bip_vcnt);
702 681
703 if (bip == NULL) 682 if (bip == NULL)
704 return -EIO; 683 return -EIO;
@@ -714,37 +693,25 @@ int bio_integrity_clone(struct bio *bio, struct bio *bio_src,
714} 693}
715EXPORT_SYMBOL(bio_integrity_clone); 694EXPORT_SYMBOL(bio_integrity_clone);
716 695
717int bioset_integrity_create(struct bio_set *bs, int pool_size) 696static int __init bio_integrity_init(void)
718{ 697{
719 bs->bio_integrity_pool = mempool_create_slab_pool(pool_size, 698 kintegrityd_wq = create_workqueue("kintegrityd");
720 bio_integrity_slab);
721 if (!bs->bio_integrity_pool)
722 return -1;
723
724 return 0;
725}
726EXPORT_SYMBOL(bioset_integrity_create);
727 699
728void bioset_integrity_free(struct bio_set *bs) 700 if (!kintegrityd_wq)
729{ 701 panic("Failed to create kintegrityd\n");
730 if (bs->bio_integrity_pool)
731 mempool_destroy(bs->bio_integrity_pool);
732}
733EXPORT_SYMBOL(bioset_integrity_free);
734 702
735void __init bio_integrity_init_slab(void)
736{
737 bio_integrity_slab = KMEM_CACHE(bio_integrity_payload, 703 bio_integrity_slab = KMEM_CACHE(bio_integrity_payload,
738 SLAB_HWCACHE_ALIGN|SLAB_PANIC); 704 SLAB_HWCACHE_ALIGN|SLAB_PANIC);
739}
740 705
741static int __init integrity_init(void) 706 bio_integrity_pool = mempool_create_slab_pool(BIO_POOL_SIZE,
742{ 707 bio_integrity_slab);
743 kintegrityd_wq = create_workqueue("kintegrityd"); 708 if (!bio_integrity_pool)
709 panic("bio_integrity: can't allocate bip pool\n");
744 710
745 if (!kintegrityd_wq) 711 integrity_bio_set = bioset_create(BIO_POOL_SIZE, 0);
746 panic("Failed to create kintegrityd\n"); 712 if (!integrity_bio_set)
713 panic("bio_integrity: can't allocate bio_set\n");
747 714
748 return 0; 715 return 0;
749} 716}
750subsys_initcall(integrity_init); 717subsys_initcall(bio_integrity_init);
diff --git a/fs/bio.c b/fs/bio.c
index d4f06327c81..a040cde7f6f 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -248,7 +248,7 @@ void bio_free(struct bio *bio, struct bio_set *bs)
248 bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio)); 248 bvec_free_bs(bs, bio->bi_io_vec, BIO_POOL_IDX(bio));
249 249
250 if (bio_integrity(bio)) 250 if (bio_integrity(bio))
251 bio_integrity_free(bio, bs); 251 bio_integrity_free(bio);
252 252
253 /* 253 /*
254 * If we have front padding, adjust the bio pointer before freeing 254 * If we have front padding, adjust the bio pointer before freeing
@@ -301,48 +301,51 @@ void bio_init(struct bio *bio)
301 **/ 301 **/
302struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs) 302struct bio *bio_alloc_bioset(gfp_t gfp_mask, int nr_iovecs, struct bio_set *bs)
303{ 303{
304 struct bio_vec *bvl = NULL;
304 struct bio *bio = NULL; 305 struct bio *bio = NULL;
305 void *uninitialized_var(p); 306 unsigned long idx = 0;
307 void *p = NULL;
306 308
307 if (bs) { 309 if (bs) {
308 p = mempool_alloc(bs->bio_pool, gfp_mask); 310 p = mempool_alloc(bs->bio_pool, gfp_mask);
309 311 if (!p)
310 if (p) 312 goto err;
311 bio = p + bs->front_pad; 313 bio = p + bs->front_pad;
312 } else 314 } else {
313 bio = kmalloc(sizeof(*bio), gfp_mask); 315 bio = kmalloc(sizeof(*bio), gfp_mask);
316 if (!bio)
317 goto err;
318 }
314 319
315 if (likely(bio)) { 320 bio_init(bio);
316 struct bio_vec *bvl = NULL; 321
317 322 if (unlikely(!nr_iovecs))
318 bio_init(bio); 323 goto out_set;
319 if (likely(nr_iovecs)) { 324
320 unsigned long uninitialized_var(idx); 325 if (nr_iovecs <= BIO_INLINE_VECS) {
321 326 bvl = bio->bi_inline_vecs;
322 if (nr_iovecs <= BIO_INLINE_VECS) { 327 nr_iovecs = BIO_INLINE_VECS;
323 idx = 0; 328 } else {
324 bvl = bio->bi_inline_vecs; 329 bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, bs);
325 nr_iovecs = BIO_INLINE_VECS; 330 if (unlikely(!bvl))
326 } else { 331 goto err_free;
327 bvl = bvec_alloc_bs(gfp_mask, nr_iovecs, &idx, 332
328 bs); 333 nr_iovecs = bvec_nr_vecs(idx);
329 nr_iovecs = bvec_nr_vecs(idx);
330 }
331 if (unlikely(!bvl)) {
332 if (bs)
333 mempool_free(p, bs->bio_pool);
334 else
335 kfree(bio);
336 bio = NULL;
337 goto out;
338 }
339 bio->bi_flags |= idx << BIO_POOL_OFFSET;
340 bio->bi_max_vecs = nr_iovecs;
341 }
342 bio->bi_io_vec = bvl;
343 } 334 }
344out: 335 bio->bi_flags |= idx << BIO_POOL_OFFSET;
336 bio->bi_max_vecs = nr_iovecs;
337out_set:
338 bio->bi_io_vec = bvl;
339
345 return bio; 340 return bio;
341
342err_free:
343 if (bs)
344 mempool_free(p, bs->bio_pool);
345 else
346 kfree(bio);
347err:
348 return NULL;
346} 349}
347 350
348struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs) 351struct bio *bio_alloc(gfp_t gfp_mask, int nr_iovecs)
@@ -463,7 +466,7 @@ struct bio *bio_clone(struct bio *bio, gfp_t gfp_mask)
463 if (bio_integrity(bio)) { 466 if (bio_integrity(bio)) {
464 int ret; 467 int ret;
465 468
466 ret = bio_integrity_clone(b, bio, gfp_mask, fs_bio_set); 469 ret = bio_integrity_clone(b, bio, gfp_mask);
467 470
468 if (ret < 0) { 471 if (ret < 0) {
469 bio_put(b); 472 bio_put(b);
@@ -1526,7 +1529,6 @@ void bioset_free(struct bio_set *bs)
1526 if (bs->bio_pool) 1529 if (bs->bio_pool)
1527 mempool_destroy(bs->bio_pool); 1530 mempool_destroy(bs->bio_pool);
1528 1531
1529 bioset_integrity_free(bs);
1530 biovec_free_pools(bs); 1532 biovec_free_pools(bs);
1531 bio_put_slab(bs); 1533 bio_put_slab(bs);
1532 1534
@@ -1567,9 +1569,6 @@ struct bio_set *bioset_create(unsigned int pool_size, unsigned int front_pad)
1567 if (!bs->bio_pool) 1569 if (!bs->bio_pool)
1568 goto bad; 1570 goto bad;
1569 1571
1570 if (bioset_integrity_create(bs, pool_size))
1571 goto bad;
1572
1573 if (!biovec_create_pools(bs, pool_size)) 1572 if (!biovec_create_pools(bs, pool_size))
1574 return bs; 1573 return bs;
1575 1574
@@ -1586,6 +1585,13 @@ static void __init biovec_init_slabs(void)
1586 int size; 1585 int size;
1587 struct biovec_slab *bvs = bvec_slabs + i; 1586 struct biovec_slab *bvs = bvec_slabs + i;
1588 1587
1588#ifndef CONFIG_BLK_DEV_INTEGRITY
1589 if (bvs->nr_vecs <= BIO_INLINE_VECS) {
1590 bvs->slab = NULL;
1591 continue;
1592 }
1593#endif
1594
1589 size = bvs->nr_vecs * sizeof(struct bio_vec); 1595 size = bvs->nr_vecs * sizeof(struct bio_vec);
1590 bvs->slab = kmem_cache_create(bvs->name, size, 0, 1596 bvs->slab = kmem_cache_create(bvs->name, size, 0,
1591 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL); 1597 SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
@@ -1600,7 +1606,6 @@ static int __init init_bio(void)
1600 if (!bio_slabs) 1606 if (!bio_slabs)
1601 panic("bio: can't allocate bios\n"); 1607 panic("bio: can't allocate bios\n");
1602 1608
1603 bio_integrity_init_slab();
1604 biovec_init_slabs(); 1609 biovec_init_slabs();
1605 1610
1606 fs_bio_set = bioset_create(BIO_POOL_SIZE, 0); 1611 fs_bio_set = bioset_create(BIO_POOL_SIZE, 0);
diff --git a/fs/block_dev.c b/fs/block_dev.c
index b3c1efff5e1..8c3c6899ccf 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -18,6 +18,7 @@
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/blkpg.h> 19#include <linux/blkpg.h>
20#include <linux/buffer_head.h> 20#include <linux/buffer_head.h>
21#include <linux/pagevec.h>
21#include <linux/writeback.h> 22#include <linux/writeback.h>
22#include <linux/mpage.h> 23#include <linux/mpage.h>
23#include <linux/mount.h> 24#include <linux/mount.h>
@@ -174,6 +175,151 @@ blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov,
174 iov, offset, nr_segs, blkdev_get_blocks, NULL); 175 iov, offset, nr_segs, blkdev_get_blocks, NULL);
175} 176}
176 177
178/*
179 * Write out and wait upon all the dirty data associated with a block
180 * device via its mapping. Does not take the superblock lock.
181 */
182int sync_blockdev(struct block_device *bdev)
183{
184 int ret = 0;
185
186 if (bdev)
187 ret = filemap_write_and_wait(bdev->bd_inode->i_mapping);
188 return ret;
189}
190EXPORT_SYMBOL(sync_blockdev);
191
192/*
193 * Write out and wait upon all dirty data associated with this
194 * device. Filesystem data as well as the underlying block
195 * device. Takes the superblock lock.
196 */
197int fsync_bdev(struct block_device *bdev)
198{
199 struct super_block *sb = get_super(bdev);
200 if (sb) {
201 int res = fsync_super(sb);
202 drop_super(sb);
203 return res;
204 }
205 return sync_blockdev(bdev);
206}
207
208/**
209 * freeze_bdev -- lock a filesystem and force it into a consistent state
210 * @bdev: blockdevice to lock
211 *
212 * This takes the block device bd_mount_sem to make sure no new mounts
213 * happen on bdev until thaw_bdev() is called.
214 * If a superblock is found on this device, we take the s_umount semaphore
215 * on it to make sure nobody unmounts until the snapshot creation is done.
216 * The reference counter (bd_fsfreeze_count) guarantees that only the last
217 * unfreeze process can unfreeze the frozen filesystem actually when multiple
218 * freeze requests arrive simultaneously. It counts up in freeze_bdev() and
219 * count down in thaw_bdev(). When it becomes 0, thaw_bdev() will unfreeze
220 * actually.
221 */
222struct super_block *freeze_bdev(struct block_device *bdev)
223{
224 struct super_block *sb;
225 int error = 0;
226
227 mutex_lock(&bdev->bd_fsfreeze_mutex);
228 if (bdev->bd_fsfreeze_count > 0) {
229 bdev->bd_fsfreeze_count++;
230 sb = get_super(bdev);
231 mutex_unlock(&bdev->bd_fsfreeze_mutex);
232 return sb;
233 }
234 bdev->bd_fsfreeze_count++;
235
236 down(&bdev->bd_mount_sem);
237 sb = get_super(bdev);
238 if (sb && !(sb->s_flags & MS_RDONLY)) {
239 sb->s_frozen = SB_FREEZE_WRITE;
240 smp_wmb();
241
242 __fsync_super(sb);
243
244 sb->s_frozen = SB_FREEZE_TRANS;
245 smp_wmb();
246
247 sync_blockdev(sb->s_bdev);
248
249 if (sb->s_op->freeze_fs) {
250 error = sb->s_op->freeze_fs(sb);
251 if (error) {
252 printk(KERN_ERR
253 "VFS:Filesystem freeze failed\n");
254 sb->s_frozen = SB_UNFROZEN;
255 drop_super(sb);
256 up(&bdev->bd_mount_sem);
257 bdev->bd_fsfreeze_count--;
258 mutex_unlock(&bdev->bd_fsfreeze_mutex);
259 return ERR_PTR(error);
260 }
261 }
262 }
263
264 sync_blockdev(bdev);
265 mutex_unlock(&bdev->bd_fsfreeze_mutex);
266
267 return sb; /* thaw_bdev releases s->s_umount and bd_mount_sem */
268}
269EXPORT_SYMBOL(freeze_bdev);
270
271/**
272 * thaw_bdev -- unlock filesystem
273 * @bdev: blockdevice to unlock
274 * @sb: associated superblock
275 *
276 * Unlocks the filesystem and marks it writeable again after freeze_bdev().
277 */
278int thaw_bdev(struct block_device *bdev, struct super_block *sb)
279{
280 int error = 0;
281
282 mutex_lock(&bdev->bd_fsfreeze_mutex);
283 if (!bdev->bd_fsfreeze_count) {
284 mutex_unlock(&bdev->bd_fsfreeze_mutex);
285 return -EINVAL;
286 }
287
288 bdev->bd_fsfreeze_count--;
289 if (bdev->bd_fsfreeze_count > 0) {
290 if (sb)
291 drop_super(sb);
292 mutex_unlock(&bdev->bd_fsfreeze_mutex);
293 return 0;
294 }
295
296 if (sb) {
297 BUG_ON(sb->s_bdev != bdev);
298 if (!(sb->s_flags & MS_RDONLY)) {
299 if (sb->s_op->unfreeze_fs) {
300 error = sb->s_op->unfreeze_fs(sb);
301 if (error) {
302 printk(KERN_ERR
303 "VFS:Filesystem thaw failed\n");
304 sb->s_frozen = SB_FREEZE_TRANS;
305 bdev->bd_fsfreeze_count++;
306 mutex_unlock(&bdev->bd_fsfreeze_mutex);
307 return error;
308 }
309 }
310 sb->s_frozen = SB_UNFROZEN;
311 smp_wmb();
312 wake_up(&sb->s_wait_unfrozen);
313 }
314 drop_super(sb);
315 }
316
317 up(&bdev->bd_mount_sem);
318 mutex_unlock(&bdev->bd_fsfreeze_mutex);
319 return 0;
320}
321EXPORT_SYMBOL(thaw_bdev);
322
177static int blkdev_writepage(struct page *page, struct writeback_control *wbc) 323static int blkdev_writepage(struct page *page, struct writeback_control *wbc)
178{ 324{
179 return block_write_full_page(page, blkdev_get_block, wbc); 325 return block_write_full_page(page, blkdev_get_block, wbc);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3e18175248e..6ec80c0fc86 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2385,7 +2385,7 @@ void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
2385 unsigned long thresh = 32 * 1024 * 1024; 2385 unsigned long thresh = 32 * 1024 * 1024;
2386 tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree; 2386 tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;
2387 2387
2388 if (current_is_pdflush() || current->flags & PF_MEMALLOC) 2388 if (current->flags & PF_MEMALLOC)
2389 return; 2389 return;
2390 2390
2391 num_dirty = count_range_bits(tree, &start, (u64)-1, 2391 num_dirty = count_range_bits(tree, &start, (u64)-1,
diff --git a/fs/buffer.c b/fs/buffer.c
index 891e1c78e4f..a2fd743d97c 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -166,151 +166,6 @@ void end_buffer_write_sync(struct buffer_head *bh, int uptodate)
166} 166}
167 167
168/* 168/*
169 * Write out and wait upon all the dirty data associated with a block
170 * device via its mapping. Does not take the superblock lock.
171 */
172int sync_blockdev(struct block_device *bdev)
173{
174 int ret = 0;
175
176 if (bdev)
177 ret = filemap_write_and_wait(bdev->bd_inode->i_mapping);
178 return ret;
179}
180EXPORT_SYMBOL(sync_blockdev);
181
182/*
183 * Write out and wait upon all dirty data associated with this
184 * device. Filesystem data as well as the underlying block
185 * device. Takes the superblock lock.
186 */
187int fsync_bdev(struct block_device *bdev)
188{
189 struct super_block *sb = get_super(bdev);
190 if (sb) {
191 int res = fsync_super(sb);
192 drop_super(sb);
193 return res;
194 }
195 return sync_blockdev(bdev);
196}
197
198/**
199 * freeze_bdev -- lock a filesystem and force it into a consistent state
200 * @bdev: blockdevice to lock
201 *
202 * This takes the block device bd_mount_sem to make sure no new mounts
203 * happen on bdev until thaw_bdev() is called.
204 * If a superblock is found on this device, we take the s_umount semaphore
205 * on it to make sure nobody unmounts until the snapshot creation is done.
206 * The reference counter (bd_fsfreeze_count) guarantees that only the last
207 * unfreeze process can unfreeze the frozen filesystem actually when multiple
208 * freeze requests arrive simultaneously. It counts up in freeze_bdev() and
209 * count down in thaw_bdev(). When it becomes 0, thaw_bdev() will unfreeze
210 * actually.
211 */
212struct super_block *freeze_bdev(struct block_device *bdev)
213{
214 struct super_block *sb;
215 int error = 0;
216
217 mutex_lock(&bdev->bd_fsfreeze_mutex);
218 if (bdev->bd_fsfreeze_count > 0) {
219 bdev->bd_fsfreeze_count++;
220 sb = get_super(bdev);
221 mutex_unlock(&bdev->bd_fsfreeze_mutex);
222 return sb;
223 }
224 bdev->bd_fsfreeze_count++;
225
226 down(&bdev->bd_mount_sem);
227 sb = get_super(bdev);
228 if (sb && !(sb->s_flags & MS_RDONLY)) {
229 sb->s_frozen = SB_FREEZE_WRITE;
230 smp_wmb();
231
232 __fsync_super(sb);
233
234 sb->s_frozen = SB_FREEZE_TRANS;
235 smp_wmb();
236
237 sync_blockdev(sb->s_bdev);
238
239 if (sb->s_op->freeze_fs) {
240 error = sb->s_op->freeze_fs(sb);
241 if (error) {
242 printk(KERN_ERR
243 "VFS:Filesystem freeze failed\n");
244 sb->s_frozen = SB_UNFROZEN;
245 drop_super(sb);
246 up(&bdev->bd_mount_sem);
247 bdev->bd_fsfreeze_count--;
248 mutex_unlock(&bdev->bd_fsfreeze_mutex);
249 return ERR_PTR(error);
250 }
251 }
252 }
253
254 sync_blockdev(bdev);
255 mutex_unlock(&bdev->bd_fsfreeze_mutex);
256
257 return sb; /* thaw_bdev releases s->s_umount and bd_mount_sem */
258}
259EXPORT_SYMBOL(freeze_bdev);
260
261/**
262 * thaw_bdev -- unlock filesystem
263 * @bdev: blockdevice to unlock
264 * @sb: associated superblock
265 *
266 * Unlocks the filesystem and marks it writeable again after freeze_bdev().
267 */
268int thaw_bdev(struct block_device *bdev, struct super_block *sb)
269{
270 int error = 0;
271
272 mutex_lock(&bdev->bd_fsfreeze_mutex);
273 if (!bdev->bd_fsfreeze_count) {
274 mutex_unlock(&bdev->bd_fsfreeze_mutex);
275 return -EINVAL;
276 }
277
278 bdev->bd_fsfreeze_count--;
279 if (bdev->bd_fsfreeze_count > 0) {
280 if (sb)
281 drop_super(sb);
282 mutex_unlock(&bdev->bd_fsfreeze_mutex);
283 return 0;
284 }
285
286 if (sb) {
287 BUG_ON(sb->s_bdev != bdev);
288 if (!(sb->s_flags & MS_RDONLY)) {
289 if (sb->s_op->unfreeze_fs) {
290 error = sb->s_op->unfreeze_fs(sb);
291 if (error) {
292 printk(KERN_ERR
293 "VFS:Filesystem thaw failed\n");
294 sb->s_frozen = SB_FREEZE_TRANS;
295 bdev->bd_fsfreeze_count++;
296 mutex_unlock(&bdev->bd_fsfreeze_mutex);
297 return error;
298 }
299 }
300 sb->s_frozen = SB_UNFROZEN;
301 smp_wmb();
302 wake_up(&sb->s_wait_unfrozen);
303 }
304 drop_super(sb);
305 }
306
307 up(&bdev->bd_mount_sem);
308 mutex_unlock(&bdev->bd_fsfreeze_mutex);
309 return 0;
310}
311EXPORT_SYMBOL(thaw_bdev);
312
313/*
314 * Various filesystems appear to want __find_get_block to be non-blocking. 169 * Various filesystems appear to want __find_get_block to be non-blocking.
315 * But it's the page lock which protects the buffers. To get around this, 170 * But it's the page lock which protects the buffers. To get around this,
316 * we get exclusion from try_to_free_buffers with the blockdev mapping's 171 * we get exclusion from try_to_free_buffers with the blockdev mapping's
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES
index 851388fafc7..65984006192 100644
--- a/fs/cifs/CHANGES
+++ b/fs/cifs/CHANGES
@@ -6,7 +6,16 @@ the server to treat subsequent connections, especially those that
6are authenticated as guest, as reconnections, invalidating the earlier 6are authenticated as guest, as reconnections, invalidating the earlier
7user's smb session. This fix allows cifs to mount multiple times to the 7user's smb session. This fix allows cifs to mount multiple times to the
8same server with different userids without risking invalidating earlier 8same server with different userids without risking invalidating earlier
9established security contexts. 9established security contexts. fsync now sends SMB Flush operation
10to better ensure that we wait for server to write all of the data to
11server disk (not just write it over the network). Add new mount
12parameter to allow user to disable sending the (slow) SMB flush on
13fsync if desired (fsync still flushes all cached write data to the server).
14Posix file open support added (turned off after one attempt if server
15fails to support it properly, as with Samba server versions prior to 3.3.2)
16Fix "redzone overwritten" bug in cifs_put_tcon (CIFSTcon may allocate too
17little memory for the "nativeFileSystem" field returned by the server
18during mount).
10 19
11Version 1.56 20Version 1.56
12------------ 21------------
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig
index 341a98965bd..6994a0f54f0 100644
--- a/fs/cifs/Kconfig
+++ b/fs/cifs/Kconfig
@@ -118,6 +118,18 @@ config CIFS_DEBUG2
118 option can be turned off unless you are debugging 118 option can be turned off unless you are debugging
119 cifs problems. If unsure, say N. 119 cifs problems. If unsure, say N.
120 120
121config CIFS_DFS_UPCALL
122 bool "DFS feature support"
123 depends on CIFS && KEYS
124 help
125 Distributed File System (DFS) support is used to access shares
126 transparently in an enterprise name space, even if the share
127 moves to a different server. This feature also enables
128 an upcall mechanism for CIFS which contacts userspace helper
129 utilities to provide server name resolution (host names to
130 IP addresses) which is needed for implicit mounts of DFS junction
131 points. If unsure, say N.
132
121config CIFS_EXPERIMENTAL 133config CIFS_EXPERIMENTAL
122 bool "CIFS Experimental Features (EXPERIMENTAL)" 134 bool "CIFS Experimental Features (EXPERIMENTAL)"
123 depends on CIFS && EXPERIMENTAL 135 depends on CIFS && EXPERIMENTAL
@@ -131,12 +143,3 @@ config CIFS_EXPERIMENTAL
131 (which is disabled by default). See the file fs/cifs/README 143 (which is disabled by default). See the file fs/cifs/README
132 for more details. If unsure, say N. 144 for more details. If unsure, say N.
133 145
134config CIFS_DFS_UPCALL
135 bool "DFS feature support (EXPERIMENTAL)"
136 depends on CIFS_EXPERIMENTAL
137 depends on KEYS
138 help
139 Enables an upcall mechanism for CIFS which contacts userspace
140 helper utilities to provide server name resolution (host names to
141 IP addresses) which is needed for implicit mounts of DFS junction
142 points. If unsure, say N.
diff --git a/fs/cifs/README b/fs/cifs/README
index da4515e3be2..07434181623 100644
--- a/fs/cifs/README
+++ b/fs/cifs/README
@@ -472,6 +472,19 @@ A partial list of the supported mount options follows:
472 even if the cifs server would support posix advisory locks. 472 even if the cifs server would support posix advisory locks.
473 "forcemand" is accepted as a shorter form of this mount 473 "forcemand" is accepted as a shorter form of this mount
474 option. 474 option.
475 nostrictsync If this mount option is set, when an application does an
476 fsync call then the cifs client does not send an SMB Flush
477 to the server (to force the server to write all dirty data
478 for this file immediately to disk), although cifs still sends
479 all dirty (cached) file data to the server and waits for the
480 server to respond to the write. Since SMB Flush can be
481 very slow, and some servers may be reliable enough (to risk
482 delaying slightly flushing the data to disk on the server),
483 turning on this option may be useful to improve performance for
484 applications that fsync too much, at a small risk of server
485 crash. If this mount option is not set, by default cifs will
486 send an SMB flush request (and wait for a response) on every
487 fsync call.
475 nodfs Disable DFS (global name space support) even if the 488 nodfs Disable DFS (global name space support) even if the
476 server claims to support it. This can help work around 489 server claims to support it. This can help work around
477 a problem with parsing of DFS paths with Samba server 490 a problem with parsing of DFS paths with Samba server
@@ -692,13 +705,14 @@ require this helper. Note that NTLMv2 security (which does not require the
692cifs.upcall helper program), instead of using Kerberos, is sufficient for 705cifs.upcall helper program), instead of using Kerberos, is sufficient for
693some use cases. 706some use cases.
694 707
695Enabling DFS support (used to access shares transparently in an MS-DFS 708DFS support allows transparent redirection to shares in an MS-DFS name space.
696global name space) requires that CONFIG_CIFS_EXPERIMENTAL be enabled. In 709In addition, DFS support for target shares which are specified as UNC
697addition, DFS support for target shares which are specified as UNC
698names which begin with host names (rather than IP addresses) requires 710names which begin with host names (rather than IP addresses) requires
699a user space helper (such as cifs.upcall) to be present in order to 711a user space helper (such as cifs.upcall) to be present in order to
700translate host names to ip address, and the user space helper must also 712translate host names to ip address, and the user space helper must also
701be configured in the file /etc/request-key.conf 713be configured in the file /etc/request-key.conf. Samba, Windows servers and
714many NAS appliances support DFS as a way of constructing a global name
715space to ease network configuration and improve reliability.
702 716
703To use cifs Kerberos and DFS support, the Linux keyutils package should be 717To use cifs Kerberos and DFS support, the Linux keyutils package should be
704installed and something like the following lines should be added to the 718installed and something like the following lines should be added to the
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
index 490e34bbf27..7f19fefd3d4 100644
--- a/fs/cifs/cifs_debug.c
+++ b/fs/cifs/cifs_debug.c
@@ -340,6 +340,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
340 seq_printf(m, "\nWrites: %d Bytes: %lld", 340 seq_printf(m, "\nWrites: %d Bytes: %lld",
341 atomic_read(&tcon->num_writes), 341 atomic_read(&tcon->num_writes),
342 (long long)(tcon->bytes_written)); 342 (long long)(tcon->bytes_written));
343 seq_printf(m, "\nFlushes: %d",
344 atomic_read(&tcon->num_flushes));
343 seq_printf(m, "\nLocks: %d HardLinks: %d " 345 seq_printf(m, "\nLocks: %d HardLinks: %d "
344 "Symlinks: %d", 346 "Symlinks: %d",
345 atomic_read(&tcon->num_locks), 347 atomic_read(&tcon->num_locks),
@@ -402,7 +404,6 @@ cifs_proc_init(void)
402 if (proc_fs_cifs == NULL) 404 if (proc_fs_cifs == NULL)
403 return; 405 return;
404 406
405 proc_fs_cifs->owner = THIS_MODULE;
406 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops); 407 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
407 408
408#ifdef CONFIG_CIFS_STATS 409#ifdef CONFIG_CIFS_STATS
diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c
index 85c0a74d034..5fdbf8a1447 100644
--- a/fs/cifs/cifs_dfs_ref.c
+++ b/fs/cifs/cifs_dfs_ref.c
@@ -104,9 +104,9 @@ static char *cifs_get_share_name(const char *node_name)
104 104
105 105
106/** 106/**
107 * compose_mount_options - creates mount options for refferral 107 * cifs_compose_mount_options - creates mount options for refferral
108 * @sb_mountdata: parent/root DFS mount options (template) 108 * @sb_mountdata: parent/root DFS mount options (template)
109 * @dentry: point where we are going to mount 109 * @fullpath: full path in UNC format
110 * @ref: server's referral 110 * @ref: server's referral
111 * @devname: pointer for saving device name 111 * @devname: pointer for saving device name
112 * 112 *
@@ -116,8 +116,8 @@ static char *cifs_get_share_name(const char *node_name)
116 * Returns: pointer to new mount options or ERR_PTR. 116 * Returns: pointer to new mount options or ERR_PTR.
117 * Caller is responcible for freeing retunrned value if it is not error. 117 * Caller is responcible for freeing retunrned value if it is not error.
118 */ 118 */
119static char *compose_mount_options(const char *sb_mountdata, 119char *cifs_compose_mount_options(const char *sb_mountdata,
120 struct dentry *dentry, 120 const char *fullpath,
121 const struct dfs_info3_param *ref, 121 const struct dfs_info3_param *ref,
122 char **devname) 122 char **devname)
123{ 123{
@@ -128,7 +128,6 @@ static char *compose_mount_options(const char *sb_mountdata,
128 char *srvIP = NULL; 128 char *srvIP = NULL;
129 char sep = ','; 129 char sep = ',';
130 int off, noff; 130 int off, noff;
131 char *fullpath;
132 131
133 if (sb_mountdata == NULL) 132 if (sb_mountdata == NULL)
134 return ERR_PTR(-EINVAL); 133 return ERR_PTR(-EINVAL);
@@ -202,17 +201,6 @@ static char *compose_mount_options(const char *sb_mountdata,
202 goto compose_mount_options_err; 201 goto compose_mount_options_err;
203 } 202 }
204 203
205 /*
206 * this function gives us a path with a double backslash prefix. We
207 * require a single backslash for DFS. Temporarily increment fullpath
208 * to put it in the proper form and decrement before freeing it.
209 */
210 fullpath = build_path_from_dentry(dentry);
211 if (!fullpath) {
212 rc = -ENOMEM;
213 goto compose_mount_options_err;
214 }
215 ++fullpath;
216 tkn_e = strchr(tkn_e + 1, '\\'); 204 tkn_e = strchr(tkn_e + 1, '\\');
217 if (tkn_e || (strlen(fullpath) - ref->path_consumed)) { 205 if (tkn_e || (strlen(fullpath) - ref->path_consumed)) {
218 strncat(mountdata, &sep, 1); 206 strncat(mountdata, &sep, 1);
@@ -221,8 +209,6 @@ static char *compose_mount_options(const char *sb_mountdata,
221 strcat(mountdata, tkn_e + 1); 209 strcat(mountdata, tkn_e + 1);
222 strcat(mountdata, fullpath + ref->path_consumed); 210 strcat(mountdata, fullpath + ref->path_consumed);
223 } 211 }
224 --fullpath;
225 kfree(fullpath);
226 212
227 /*cFYI(1,("%s: parent mountdata: %s", __func__,sb_mountdata));*/ 213 /*cFYI(1,("%s: parent mountdata: %s", __func__,sb_mountdata));*/
228 /*cFYI(1, ("%s: submount mountdata: %s", __func__, mountdata ));*/ 214 /*cFYI(1, ("%s: submount mountdata: %s", __func__, mountdata ));*/
@@ -245,10 +231,20 @@ static struct vfsmount *cifs_dfs_do_refmount(const struct vfsmount *mnt_parent,
245 struct vfsmount *mnt; 231 struct vfsmount *mnt;
246 char *mountdata; 232 char *mountdata;
247 char *devname = NULL; 233 char *devname = NULL;
234 char *fullpath;
248 235
249 cifs_sb = CIFS_SB(dentry->d_inode->i_sb); 236 cifs_sb = CIFS_SB(dentry->d_inode->i_sb);
250 mountdata = compose_mount_options(cifs_sb->mountdata, 237 /*
251 dentry, ref, &devname); 238 * this function gives us a path with a double backslash prefix. We
239 * require a single backslash for DFS.
240 */
241 fullpath = build_path_from_dentry(dentry);
242 if (!fullpath)
243 return ERR_PTR(-ENOMEM);
244
245 mountdata = cifs_compose_mount_options(cifs_sb->mountdata,
246 fullpath + 1, ref, &devname);
247 kfree(fullpath);
252 248
253 if (IS_ERR(mountdata)) 249 if (IS_ERR(mountdata))
254 return (struct vfsmount *)mountdata; 250 return (struct vfsmount *)mountdata;
diff --git a/fs/cifs/cifs_fs_sb.h b/fs/cifs/cifs_fs_sb.h
index c4c306f7b06..4797787c6a4 100644
--- a/fs/cifs/cifs_fs_sb.h
+++ b/fs/cifs/cifs_fs_sb.h
@@ -32,6 +32,7 @@
32#define CIFS_MOUNT_OVERR_GID 0x800 /* override gid returned from server */ 32#define CIFS_MOUNT_OVERR_GID 0x800 /* override gid returned from server */
33#define CIFS_MOUNT_DYNPERM 0x1000 /* allow in-memory only mode setting */ 33#define CIFS_MOUNT_DYNPERM 0x1000 /* allow in-memory only mode setting */
34#define CIFS_MOUNT_NOPOSIXBRL 0x2000 /* mandatory not posix byte range lock */ 34#define CIFS_MOUNT_NOPOSIXBRL 0x2000 /* mandatory not posix byte range lock */
35#define CIFS_MOUNT_NOSSYNC 0x4000 /* don't do slow SMBflush on every sync*/
35 36
36struct cifs_sb_info { 37struct cifs_sb_info {
37 struct cifsTconInfo *tcon; /* primary mount */ 38 struct cifsTconInfo *tcon; /* primary mount */
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 13ea53251dc..38491fd3871 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -606,7 +606,8 @@ cifs_get_sb(struct file_system_type *fs_type,
606 return rc; 606 return rc;
607 } 607 }
608 sb->s_flags |= MS_ACTIVE; 608 sb->s_flags |= MS_ACTIVE;
609 return simple_set_mnt(mnt, sb); 609 simple_set_mnt(mnt, sb);
610 return 0;
610} 611}
611 612
612static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov, 613static ssize_t cifs_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 2b1d28a9ee2..77e190dc288 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -78,8 +78,8 @@ extern int cifs_dir_open(struct inode *inode, struct file *file);
78extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir); 78extern int cifs_readdir(struct file *file, void *direntry, filldir_t filldir);
79 79
80/* Functions related to dir entries */ 80/* Functions related to dir entries */
81extern struct dentry_operations cifs_dentry_ops; 81extern const struct dentry_operations cifs_dentry_ops;
82extern struct dentry_operations cifs_ci_dentry_ops; 82extern const struct dentry_operations cifs_ci_dentry_ops;
83 83
84/* Functions related to symlinks */ 84/* Functions related to symlinks */
85extern void *cifs_follow_link(struct dentry *direntry, struct nameidata *nd); 85extern void *cifs_follow_link(struct dentry *direntry, struct nameidata *nd);
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
index e004f6db5fc..9fbf4dff5da 100644
--- a/fs/cifs/cifsglob.h
+++ b/fs/cifs/cifsglob.h
@@ -254,6 +254,7 @@ struct cifsTconInfo {
254 atomic_t num_smbs_sent; 254 atomic_t num_smbs_sent;
255 atomic_t num_writes; 255 atomic_t num_writes;
256 atomic_t num_reads; 256 atomic_t num_reads;
257 atomic_t num_flushes;
257 atomic_t num_oplock_brks; 258 atomic_t num_oplock_brks;
258 atomic_t num_opens; 259 atomic_t num_opens;
259 atomic_t num_closes; 260 atomic_t num_closes;
@@ -298,6 +299,7 @@ struct cifsTconInfo {
298 bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol 299 bool unix_ext:1; /* if false disable Linux extensions to CIFS protocol
299 for this mount even if server would support */ 300 for this mount even if server would support */
300 bool local_lease:1; /* check leases (only) on local system not remote */ 301 bool local_lease:1; /* check leases (only) on local system not remote */
302 bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
301 bool need_reconnect:1; /* connection reset, tid now invalid */ 303 bool need_reconnect:1; /* connection reset, tid now invalid */
302 /* BB add field for back pointer to sb struct(s)? */ 304 /* BB add field for back pointer to sb struct(s)? */
303}; 305};
diff --git a/fs/cifs/cifspdu.h b/fs/cifs/cifspdu.h
index b4e2e9f0ee3..b370489c8da 100644
--- a/fs/cifs/cifspdu.h
+++ b/fs/cifs/cifspdu.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * fs/cifs/cifspdu.h 2 * fs/cifs/cifspdu.h
3 * 3 *
4 * Copyright (c) International Business Machines Corp., 2002,2008 4 * Copyright (c) International Business Machines Corp., 2002,2009
5 * Author(s): Steve French (sfrench@us.ibm.com) 5 * Author(s): Steve French (sfrench@us.ibm.com)
6 * 6 *
7 * This library is free software; you can redistribute it and/or modify 7 * This library is free software; you can redistribute it and/or modify
@@ -23,6 +23,7 @@
23#define _CIFSPDU_H 23#define _CIFSPDU_H
24 24
25#include <net/sock.h> 25#include <net/sock.h>
26#include "smbfsctl.h"
26 27
27#ifdef CONFIG_CIFS_WEAK_PW_HASH 28#ifdef CONFIG_CIFS_WEAK_PW_HASH
28#define LANMAN_PROT 0 29#define LANMAN_PROT 0
@@ -34,15 +35,15 @@
34#define POSIX_PROT (CIFS_PROT+1) 35#define POSIX_PROT (CIFS_PROT+1)
35#define BAD_PROT 0xFFFF 36#define BAD_PROT 0xFFFF
36 37
37/* SMB command codes */ 38/* SMB command codes:
38/* 39 * Note some commands have minimal (wct=0,bcc=0), or uninteresting, responses
39 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
40 * (ie which include no useful data other than the SMB error code itself). 40 * (ie which include no useful data other than the SMB error code itself).
41 * Knowing this helps avoid response buffer allocations and copy in some cases 41 * This can allow us to avoid response buffer allocations and copy in some cases
42 */ 42 */
43#define SMB_COM_CREATE_DIRECTORY 0x00 /* trivial response */ 43#define SMB_COM_CREATE_DIRECTORY 0x00 /* trivial response */
44#define SMB_COM_DELETE_DIRECTORY 0x01 /* trivial response */ 44#define SMB_COM_DELETE_DIRECTORY 0x01 /* trivial response */
45#define SMB_COM_CLOSE 0x04 /* triv req/rsp, timestamp ignored */ 45#define SMB_COM_CLOSE 0x04 /* triv req/rsp, timestamp ignored */
46#define SMB_COM_FLUSH 0x05 /* triv req/rsp */
46#define SMB_COM_DELETE 0x06 /* trivial response */ 47#define SMB_COM_DELETE 0x06 /* trivial response */
47#define SMB_COM_RENAME 0x07 /* trivial response */ 48#define SMB_COM_RENAME 0x07 /* trivial response */
48#define SMB_COM_QUERY_INFORMATION 0x08 /* aka getattr */ 49#define SMB_COM_QUERY_INFORMATION 0x08 /* aka getattr */
@@ -790,6 +791,12 @@ typedef struct smb_com_close_rsp {
790 __u16 ByteCount; /* bct = 0 */ 791 __u16 ByteCount; /* bct = 0 */
791} __attribute__((packed)) CLOSE_RSP; 792} __attribute__((packed)) CLOSE_RSP;
792 793
794typedef struct smb_com_flush_req {
795 struct smb_hdr hdr; /* wct = 1 */
796 __u16 FileID;
797 __u16 ByteCount; /* 0 */
798} __attribute__((packed)) FLUSH_REQ;
799
793typedef struct smb_com_findclose_req { 800typedef struct smb_com_findclose_req {
794 struct smb_hdr hdr; /* wct = 1 */ 801 struct smb_hdr hdr; /* wct = 1 */
795 __u16 FileID; 802 __u16 FileID;
@@ -1924,19 +1931,19 @@ typedef struct smb_com_transaction2_get_dfs_refer_req {
1924#define DFS_TYPE_ROOT 0x0001 1931#define DFS_TYPE_ROOT 0x0001
1925 1932
1926/* Referral Entry Flags */ 1933/* Referral Entry Flags */
1927#define DFS_NAME_LIST_REF 0x0200 1934#define DFS_NAME_LIST_REF 0x0200 /* set for domain or DC referral responses */
1935#define DFS_TARGET_SET_BOUNDARY 0x0400 /* only valid with version 4 dfs req */
1928 1936
1929typedef struct dfs_referral_level_3 { 1937typedef struct dfs_referral_level_3 { /* version 4 is same, + one flag bit */
1930 __le16 VersionNumber; 1938 __le16 VersionNumber; /* must be 3 or 4 */
1931 __le16 Size; 1939 __le16 Size;
1932 __le16 ServerType; /* 0x0001 = root targets; 0x0000 = link targets */ 1940 __le16 ServerType; /* 0x0001 = root targets; 0x0000 = link targets */
1933 __le16 ReferralEntryFlags; /* 0x0200 bit set only for domain 1941 __le16 ReferralEntryFlags;
1934 or DC referral responce */
1935 __le32 TimeToLive; 1942 __le32 TimeToLive;
1936 __le16 DfsPathOffset; 1943 __le16 DfsPathOffset;
1937 __le16 DfsAlternatePathOffset; 1944 __le16 DfsAlternatePathOffset;
1938 __le16 NetworkAddressOffset; /* offset of the link target */ 1945 __le16 NetworkAddressOffset; /* offset of the link target */
1939 __le16 ServiceSiteGuid; 1946 __u8 ServiceSiteGuid[16]; /* MBZ, ignored */
1940} __attribute__((packed)) REFERRAL3; 1947} __attribute__((packed)) REFERRAL3;
1941 1948
1942typedef struct smb_com_transaction_get_dfs_refer_rsp { 1949typedef struct smb_com_transaction_get_dfs_refer_rsp {
@@ -1946,48 +1953,15 @@ typedef struct smb_com_transaction_get_dfs_refer_rsp {
1946 __u8 Pad; 1953 __u8 Pad;
1947 __le16 PathConsumed; 1954 __le16 PathConsumed;
1948 __le16 NumberOfReferrals; 1955 __le16 NumberOfReferrals;
1949 __le16 DFSFlags; 1956 __le32 DFSFlags;
1950 __u16 Pad2;
1951 REFERRAL3 referrals[1]; /* array of level 3 dfs_referral structures */ 1957 REFERRAL3 referrals[1]; /* array of level 3 dfs_referral structures */
1952 /* followed by the strings pointed to by the referral structures */ 1958 /* followed by the strings pointed to by the referral structures */
1953} __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_RSP; 1959} __attribute__((packed)) TRANSACTION2_GET_DFS_REFER_RSP;
1954 1960
1955/* DFS Flags */ 1961/* DFS Flags */
1956#define DFSREF_REFERRAL_SERVER 0x0001 1962#define DFSREF_REFERRAL_SERVER 0x00000001 /* all targets are DFS roots */
1957#define DFSREF_STORAGE_SERVER 0x0002 1963#define DFSREF_STORAGE_SERVER 0x00000002 /* no further ref requests needed */
1958 1964#define DFSREF_TARGET_FAILBACK 0x00000004 /* only for DFS referral version 4 */
1959/* IOCTL information */
1960/*
1961 * List of ioctl function codes that look to be of interest to remote clients
1962 * like this one. Need to do some experimentation to make sure they all work
1963 * remotely. Some of the following, such as the encryption/compression ones
1964 * would be invoked from tools via a specialized hook into the VFS rather
1965 * than via the standard vfs entry points
1966 */
1967#define FSCTL_REQUEST_OPLOCK_LEVEL_1 0x00090000
1968#define FSCTL_REQUEST_OPLOCK_LEVEL_2 0x00090004
1969#define FSCTL_REQUEST_BATCH_OPLOCK 0x00090008
1970#define FSCTL_LOCK_VOLUME 0x00090018
1971#define FSCTL_UNLOCK_VOLUME 0x0009001C
1972#define FSCTL_GET_COMPRESSION 0x0009003C
1973#define FSCTL_SET_COMPRESSION 0x0009C040
1974#define FSCTL_REQUEST_FILTER_OPLOCK 0x0009008C
1975#define FSCTL_FILESYS_GET_STATISTICS 0x00090090
1976#define FSCTL_SET_REPARSE_POINT 0x000900A4
1977#define FSCTL_GET_REPARSE_POINT 0x000900A8
1978#define FSCTL_DELETE_REPARSE_POINT 0x000900AC
1979#define FSCTL_SET_SPARSE 0x000900C4
1980#define FSCTL_SET_ZERO_DATA 0x000900C8
1981#define FSCTL_SET_ENCRYPTION 0x000900D7
1982#define FSCTL_ENCRYPTION_FSCTL_IO 0x000900DB
1983#define FSCTL_WRITE_RAW_ENCRYPTED 0x000900DF
1984#define FSCTL_READ_RAW_ENCRYPTED 0x000900E3
1985#define FSCTL_SIS_COPYFILE 0x00090100
1986#define FSCTL_SIS_LINK_FILES 0x0009C104
1987
1988#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
1989#define IO_REPARSE_TAG_HSM 0xC0000004
1990#define IO_REPARSE_TAG_SIS 0x80000007
1991 1965
1992/* 1966/*
1993 ************************************************************************ 1967 ************************************************************************
@@ -2508,8 +2482,6 @@ struct data_blob {
2508 6) Use nanosecond timestamps throughout all time fields if 2482 6) Use nanosecond timestamps throughout all time fields if
2509 corresponding attribute flag is set 2483 corresponding attribute flag is set
2510 7) sendfile - handle based copy 2484 7) sendfile - handle based copy
2511 8) Direct i/o
2512 9) Misc fcntls?
2513 2485
2514 what about fixing 64 bit alignment 2486 what about fixing 64 bit alignment
2515 2487
@@ -2628,7 +2600,5 @@ typedef struct file_chattr_info {
2628 __le64 mode; /* list of actual attribute bits on this inode */ 2600 __le64 mode; /* list of actual attribute bits on this inode */
2629} __attribute__((packed)) FILE_CHATTR_INFO; /* ext attributes 2601} __attribute__((packed)) FILE_CHATTR_INFO; /* ext attributes
2630 (chattr, chflags) level 0x206 */ 2602 (chattr, chflags) level 0x206 */
2631 2603#endif /* POSIX */
2632#endif
2633
2634#endif /* _CIFSPDU_H */ 2604#endif /* _CIFSPDU_H */
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index 083dfc57c7a..4167716d32f 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -44,6 +44,9 @@ extern void _FreeXid(unsigned int);
44extern char *build_path_from_dentry(struct dentry *); 44extern char *build_path_from_dentry(struct dentry *);
45extern char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb); 45extern char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb);
46extern char *build_wildcard_path_from_dentry(struct dentry *direntry); 46extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
47extern char *cifs_compose_mount_options(const char *sb_mountdata,
48 const char *fullpath, const struct dfs_info3_param *ref,
49 char **devname);
47/* extern void renew_parental_timestamps(struct dentry *direntry);*/ 50/* extern void renew_parental_timestamps(struct dentry *direntry);*/
48extern int SendReceive(const unsigned int /* xid */ , struct cifsSesInfo *, 51extern int SendReceive(const unsigned int /* xid */ , struct cifsSesInfo *,
49 struct smb_hdr * /* input */ , 52 struct smb_hdr * /* input */ ,
@@ -92,6 +95,9 @@ extern u64 cifs_UnixTimeToNT(struct timespec);
92extern __le64 cnvrtDosCifsTm(__u16 date, __u16 time); 95extern __le64 cnvrtDosCifsTm(__u16 date, __u16 time);
93extern struct timespec cnvrtDosUnixTm(__u16 date, __u16 time); 96extern struct timespec cnvrtDosUnixTm(__u16 date, __u16 time);
94 97
98extern int cifs_posix_open(char *full_path, struct inode **pinode,
99 struct super_block *sb, int mode, int oflags,
100 int *poplock, __u16 *pnetfid, int xid);
95extern void posix_fill_in_inode(struct inode *tmp_inode, 101extern void posix_fill_in_inode(struct inode *tmp_inode,
96 FILE_UNIX_BASIC_INFO *pData, int isNewInode); 102 FILE_UNIX_BASIC_INFO *pData, int isNewInode);
97extern struct inode *cifs_new_inode(struct super_block *sb, __u64 *inum); 103extern struct inode *cifs_new_inode(struct super_block *sb, __u64 *inum);
@@ -281,6 +287,9 @@ extern int CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon,
281extern int CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, 287extern int CIFSSMBClose(const int xid, struct cifsTconInfo *tcon,
282 const int smb_file_id); 288 const int smb_file_id);
283 289
290extern int CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon,
291 const int smb_file_id);
292
284extern int CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, 293extern int CIFSSMBRead(const int xid, struct cifsTconInfo *tcon,
285 const int netfid, unsigned int count, 294 const int netfid, unsigned int count,
286 const __u64 lseek, unsigned int *nbytes, char **buf, 295 const __u64 lseek, unsigned int *nbytes, char **buf,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index 939e2f76b95..bc09c998631 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -1934,6 +1934,27 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id)
1934} 1934}
1935 1935
1936int 1936int
1937CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id)
1938{
1939 int rc = 0;
1940 FLUSH_REQ *pSMB = NULL;
1941 cFYI(1, ("In CIFSSMBFlush"));
1942
1943 rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB);
1944 if (rc)
1945 return rc;
1946
1947 pSMB->FileID = (__u16) smb_file_id;
1948 pSMB->ByteCount = 0;
1949 rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
1950 cifs_stats_inc(&tcon->num_flushes);
1951 if (rc)
1952 cERROR(1, ("Send error in Flush = %d", rc));
1953
1954 return rc;
1955}
1956
1957int
1937CIFSSMBRename(const int xid, struct cifsTconInfo *tcon, 1958CIFSSMBRename(const int xid, struct cifsTconInfo *tcon,
1938 const char *fromName, const char *toName, 1959 const char *fromName, const char *toName,
1939 const struct nls_table *nls_codepage, int remap) 1960 const struct nls_table *nls_codepage, int remap)
@@ -2356,8 +2377,10 @@ winCreateHardLinkRetry:
2356 PATH_MAX, nls_codepage, remap); 2377 PATH_MAX, nls_codepage, remap);
2357 name_len++; /* trailing null */ 2378 name_len++; /* trailing null */
2358 name_len *= 2; 2379 name_len *= 2;
2359 pSMB->OldFileName[name_len] = 0; /* pad */ 2380
2360 pSMB->OldFileName[name_len + 1] = 0x04; 2381 /* protocol specifies ASCII buffer format (0x04) for unicode */
2382 pSMB->OldFileName[name_len] = 0x04;
2383 pSMB->OldFileName[name_len + 1] = 0x00; /* pad */
2361 name_len2 = 2384 name_len2 =
2362 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2], 2385 cifsConvertToUCS((__le16 *)&pSMB->OldFileName[name_len + 2],
2363 toName, PATH_MAX, nls_codepage, remap); 2386 toName, PATH_MAX, nls_codepage, remap);
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index da0f4ffa061..0de3b5615a2 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -95,6 +95,7 @@ struct smb_vol {
95 bool local_lease:1; /* check leases only on local system, not remote */ 95 bool local_lease:1; /* check leases only on local system, not remote */
96 bool noblocksnd:1; 96 bool noblocksnd:1;
97 bool noautotune:1; 97 bool noautotune:1;
98 bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
98 unsigned int rsize; 99 unsigned int rsize;
99 unsigned int wsize; 100 unsigned int wsize;
100 unsigned int sockopt; 101 unsigned int sockopt;
@@ -1274,6 +1275,10 @@ cifs_parse_mount_options(char *options, const char *devname,
1274 vol->intr = 0; 1275 vol->intr = 0;
1275 } else if (strnicmp(data, "intr", 4) == 0) { 1276 } else if (strnicmp(data, "intr", 4) == 0) {
1276 vol->intr = 1; 1277 vol->intr = 1;
1278 } else if (strnicmp(data, "nostrictsync", 12) == 0) {
1279 vol->nostrictsync = 1;
1280 } else if (strnicmp(data, "strictsync", 10) == 0) {
1281 vol->nostrictsync = 0;
1277 } else if (strnicmp(data, "serverino", 7) == 0) { 1282 } else if (strnicmp(data, "serverino", 7) == 0) {
1278 vol->server_ino = 1; 1283 vol->server_ino = 1;
1279 } else if (strnicmp(data, "noserverino", 9) == 0) { 1284 } else if (strnicmp(data, "noserverino", 9) == 0) {
@@ -2160,6 +2165,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
2160 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL; 2165 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_UNX_EMUL;
2161 if (pvolume_info->nobrl) 2166 if (pvolume_info->nobrl)
2162 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL; 2167 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_BRL;
2168 if (pvolume_info->nostrictsync)
2169 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOSSYNC;
2163 if (pvolume_info->mand_lock) 2170 if (pvolume_info->mand_lock)
2164 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL; 2171 cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NOPOSIXBRL;
2165 if (pvolume_info->cifs_acl) 2172 if (pvolume_info->cifs_acl)
@@ -3667,7 +3674,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
3667 BCC(smb_buffer_response)) { 3674 BCC(smb_buffer_response)) {
3668 kfree(tcon->nativeFileSystem); 3675 kfree(tcon->nativeFileSystem);
3669 tcon->nativeFileSystem = 3676 tcon->nativeFileSystem =
3670 kzalloc(length + 2, GFP_KERNEL); 3677 kzalloc(2*(length + 1), GFP_KERNEL);
3671 if (tcon->nativeFileSystem) 3678 if (tcon->nativeFileSystem)
3672 cifs_strfromUCS_le( 3679 cifs_strfromUCS_le(
3673 tcon->nativeFileSystem, 3680 tcon->nativeFileSystem,
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c
index 89fb7283265..2f35cccfcd8 100644
--- a/fs/cifs/dir.c
+++ b/fs/cifs/dir.c
@@ -129,7 +129,7 @@ cifs_bp_rename_retry:
129 return full_path; 129 return full_path;
130} 130}
131 131
132static int cifs_posix_open(char *full_path, struct inode **pinode, 132int cifs_posix_open(char *full_path, struct inode **pinode,
133 struct super_block *sb, int mode, int oflags, 133 struct super_block *sb, int mode, int oflags,
134 int *poplock, __u16 *pnetfid, int xid) 134 int *poplock, __u16 *pnetfid, int xid)
135{ 135{
@@ -187,7 +187,9 @@ static int cifs_posix_open(char *full_path, struct inode **pinode,
187 if (!pinode) 187 if (!pinode)
188 goto posix_open_ret; /* caller does not need info */ 188 goto posix_open_ret; /* caller does not need info */
189 189
190 *pinode = cifs_new_inode(sb, &presp_data->UniqueId); 190 if (*pinode == NULL)
191 *pinode = cifs_new_inode(sb, &presp_data->UniqueId);
192 /* else an inode was passed in. Update its info, don't create one */
191 193
192 /* We do not need to close the file if new_inode fails since 194 /* We do not need to close the file if new_inode fails since
193 the caller will retry qpathinfo as long as inode is null */ 195 the caller will retry qpathinfo as long as inode is null */
@@ -699,7 +701,7 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
699 return rc; 701 return rc;
700} */ 702} */
701 703
702struct dentry_operations cifs_dentry_ops = { 704const struct dentry_operations cifs_dentry_ops = {
703 .d_revalidate = cifs_d_revalidate, 705 .d_revalidate = cifs_d_revalidate,
704/* d_delete: cifs_d_delete, */ /* not needed except for debugging */ 706/* d_delete: cifs_d_delete, */ /* not needed except for debugging */
705}; 707};
@@ -737,7 +739,7 @@ static int cifs_ci_compare(struct dentry *dentry, struct qstr *a,
737 return 1; 739 return 1;
738} 740}
739 741
740struct dentry_operations cifs_ci_dentry_ops = { 742const struct dentry_operations cifs_ci_dentry_ops = {
741 .d_revalidate = cifs_d_revalidate, 743 .d_revalidate = cifs_d_revalidate,
742 .d_hash = cifs_ci_hash, 744 .d_hash = cifs_ci_hash,
743 .d_compare = cifs_ci_compare, 745 .d_compare = cifs_ci_compare,
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 12bb656fbe7..81747acca4c 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -78,8 +78,36 @@ static inline int cifs_convert_flags(unsigned int flags)
78 return (READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES | 78 return (READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES |
79 FILE_WRITE_EA | FILE_APPEND_DATA | FILE_WRITE_DATA | 79 FILE_WRITE_EA | FILE_APPEND_DATA | FILE_WRITE_DATA |
80 FILE_READ_DATA); 80 FILE_READ_DATA);
81}
81 82
83static inline fmode_t cifs_posix_convert_flags(unsigned int flags)
84{
85 fmode_t posix_flags = 0;
82 86
87 if ((flags & O_ACCMODE) == O_RDONLY)
88 posix_flags = FMODE_READ;
89 else if ((flags & O_ACCMODE) == O_WRONLY)
90 posix_flags = FMODE_WRITE;
91 else if ((flags & O_ACCMODE) == O_RDWR) {
92 /* GENERIC_ALL is too much permission to request
93 can cause unnecessary access denied on create */
94 /* return GENERIC_ALL; */
95 posix_flags = FMODE_READ | FMODE_WRITE;
96 }
97 /* can not map O_CREAT or O_EXCL or O_TRUNC flags when
98 reopening a file. They had their effect on the original open */
99 if (flags & O_APPEND)
100 posix_flags |= (fmode_t)O_APPEND;
101 if (flags & O_SYNC)
102 posix_flags |= (fmode_t)O_SYNC;
103 if (flags & O_DIRECTORY)
104 posix_flags |= (fmode_t)O_DIRECTORY;
105 if (flags & O_NOFOLLOW)
106 posix_flags |= (fmode_t)O_NOFOLLOW;
107 if (flags & O_DIRECT)
108 posix_flags |= (fmode_t)O_DIRECT;
109
110 return posix_flags;
83} 111}
84 112
85static inline int cifs_get_disposition(unsigned int flags) 113static inline int cifs_get_disposition(unsigned int flags)
@@ -97,6 +125,80 @@ static inline int cifs_get_disposition(unsigned int flags)
97} 125}
98 126
99/* all arguments to this function must be checked for validity in caller */ 127/* all arguments to this function must be checked for validity in caller */
128static inline int cifs_posix_open_inode_helper(struct inode *inode,
129 struct file *file, struct cifsInodeInfo *pCifsInode,
130 struct cifsFileInfo *pCifsFile, int oplock, u16 netfid)
131{
132 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
133/* struct timespec temp; */ /* BB REMOVEME BB */
134
135 file->private_data = kmalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
136 if (file->private_data == NULL)
137 return -ENOMEM;
138 pCifsFile = cifs_init_private(file->private_data, inode, file, netfid);
139 write_lock(&GlobalSMBSeslock);
140 list_add(&pCifsFile->tlist, &cifs_sb->tcon->openFileList);
141
142 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
143 if (pCifsInode == NULL) {
144 write_unlock(&GlobalSMBSeslock);
145 return -EINVAL;
146 }
147
148 /* want handles we can use to read with first
149 in the list so we do not have to walk the
150 list to search for one in write_begin */
151 if ((file->f_flags & O_ACCMODE) == O_WRONLY) {
152 list_add_tail(&pCifsFile->flist,
153 &pCifsInode->openFileList);
154 } else {
155 list_add(&pCifsFile->flist,
156 &pCifsInode->openFileList);
157 }
158
159 if (pCifsInode->clientCanCacheRead) {
160 /* we have the inode open somewhere else
161 no need to discard cache data */
162 goto psx_client_can_cache;
163 }
164
165 /* BB FIXME need to fix this check to move it earlier into posix_open
166 BB fIX following section BB FIXME */
167
168 /* if not oplocked, invalidate inode pages if mtime or file
169 size changed */
170/* temp = cifs_NTtimeToUnix(le64_to_cpu(buf->LastWriteTime));
171 if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) &&
172 (file->f_path.dentry->d_inode->i_size ==
173 (loff_t)le64_to_cpu(buf->EndOfFile))) {
174 cFYI(1, ("inode unchanged on server"));
175 } else {
176 if (file->f_path.dentry->d_inode->i_mapping) {
177 rc = filemap_write_and_wait(file->f_path.dentry->d_inode->i_mapping);
178 if (rc != 0)
179 CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc;
180 }
181 cFYI(1, ("invalidating remote inode since open detected it "
182 "changed"));
183 invalidate_remote_inode(file->f_path.dentry->d_inode);
184 } */
185
186psx_client_can_cache:
187 if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
188 pCifsInode->clientCanCacheAll = true;
189 pCifsInode->clientCanCacheRead = true;
190 cFYI(1, ("Exclusive Oplock granted on inode %p",
191 file->f_path.dentry->d_inode));
192 } else if ((oplock & 0xF) == OPLOCK_READ)
193 pCifsInode->clientCanCacheRead = true;
194
195 /* will have to change the unlock if we reenable the
196 filemap_fdatawrite (which does not seem necessary */
197 write_unlock(&GlobalSMBSeslock);
198 return 0;
199}
200
201/* all arguments to this function must be checked for validity in caller */
100static inline int cifs_open_inode_helper(struct inode *inode, struct file *file, 202static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
101 struct cifsInodeInfo *pCifsInode, struct cifsFileInfo *pCifsFile, 203 struct cifsInodeInfo *pCifsInode, struct cifsFileInfo *pCifsFile,
102 struct cifsTconInfo *pTcon, int *oplock, FILE_ALL_INFO *buf, 204 struct cifsTconInfo *pTcon, int *oplock, FILE_ALL_INFO *buf,
@@ -167,7 +269,7 @@ int cifs_open(struct inode *inode, struct file *file)
167 int rc = -EACCES; 269 int rc = -EACCES;
168 int xid, oplock; 270 int xid, oplock;
169 struct cifs_sb_info *cifs_sb; 271 struct cifs_sb_info *cifs_sb;
170 struct cifsTconInfo *pTcon; 272 struct cifsTconInfo *tcon;
171 struct cifsFileInfo *pCifsFile; 273 struct cifsFileInfo *pCifsFile;
172 struct cifsInodeInfo *pCifsInode; 274 struct cifsInodeInfo *pCifsInode;
173 struct list_head *tmp; 275 struct list_head *tmp;
@@ -180,7 +282,7 @@ int cifs_open(struct inode *inode, struct file *file)
180 xid = GetXid(); 282 xid = GetXid();
181 283
182 cifs_sb = CIFS_SB(inode->i_sb); 284 cifs_sb = CIFS_SB(inode->i_sb);
183 pTcon = cifs_sb->tcon; 285 tcon = cifs_sb->tcon;
184 286
185 if (file->f_flags & O_CREAT) { 287 if (file->f_flags & O_CREAT) {
186 /* search inode for this file and fill in file->private_data */ 288 /* search inode for this file and fill in file->private_data */
@@ -220,6 +322,45 @@ int cifs_open(struct inode *inode, struct file *file)
220 322
221 cFYI(1, ("inode = 0x%p file flags are 0x%x for %s", 323 cFYI(1, ("inode = 0x%p file flags are 0x%x for %s",
222 inode, file->f_flags, full_path)); 324 inode, file->f_flags, full_path));
325
326 if (oplockEnabled)
327 oplock = REQ_OPLOCK;
328 else
329 oplock = 0;
330
331 if (!tcon->broken_posix_open && tcon->unix_ext &&
332 (tcon->ses->capabilities & CAP_UNIX) &&
333 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
334 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
335 int oflags = (int) cifs_posix_convert_flags(file->f_flags);
336 /* can not refresh inode info since size could be stale */
337 rc = cifs_posix_open(full_path, &inode, inode->i_sb,
338 cifs_sb->mnt_file_mode /* ignored */,
339 oflags, &oplock, &netfid, xid);
340 if (rc == 0) {
341 cFYI(1, ("posix open succeeded"));
342 /* no need for special case handling of setting mode
343 on read only files needed here */
344
345 cifs_posix_open_inode_helper(inode, file, pCifsInode,
346 pCifsFile, oplock, netfid);
347 goto out;
348 } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
349 if (tcon->ses->serverNOS)
350 cERROR(1, ("server %s of type %s returned"
351 " unexpected error on SMB posix open"
352 ", disabling posix open support."
353 " Check if server update available.",
354 tcon->ses->serverName,
355 tcon->ses->serverNOS));
356 tcon->broken_posix_open = true;
357 } else if ((rc != -EIO) && (rc != -EREMOTE) &&
358 (rc != -EOPNOTSUPP)) /* path not found or net err */
359 goto out;
360 /* else fallthrough to retry open the old way on network i/o
361 or DFS errors */
362 }
363
223 desiredAccess = cifs_convert_flags(file->f_flags); 364 desiredAccess = cifs_convert_flags(file->f_flags);
224 365
225/********************************************************************* 366/*********************************************************************
@@ -248,11 +389,6 @@ int cifs_open(struct inode *inode, struct file *file)
248 389
249 disposition = cifs_get_disposition(file->f_flags); 390 disposition = cifs_get_disposition(file->f_flags);
250 391
251 if (oplockEnabled)
252 oplock = REQ_OPLOCK;
253 else
254 oplock = 0;
255
256 /* BB pass O_SYNC flag through on file attributes .. BB */ 392 /* BB pass O_SYNC flag through on file attributes .. BB */
257 393
258 /* Also refresh inode by passing in file_info buf returned by SMBOpen 394 /* Also refresh inode by passing in file_info buf returned by SMBOpen
@@ -269,7 +405,7 @@ int cifs_open(struct inode *inode, struct file *file)
269 } 405 }
270 406
271 if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS) 407 if (cifs_sb->tcon->ses->capabilities & CAP_NT_SMBS)
272 rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, 408 rc = CIFSSMBOpen(xid, tcon, full_path, disposition,
273 desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf, 409 desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
274 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags 410 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
275 & CIFS_MOUNT_MAP_SPECIAL_CHR); 411 & CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -278,7 +414,7 @@ int cifs_open(struct inode *inode, struct file *file)
278 414
279 if (rc == -EIO) { 415 if (rc == -EIO) {
280 /* Old server, try legacy style OpenX */ 416 /* Old server, try legacy style OpenX */
281 rc = SMBLegacyOpen(xid, pTcon, full_path, disposition, 417 rc = SMBLegacyOpen(xid, tcon, full_path, disposition,
282 desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf, 418 desiredAccess, CREATE_NOT_DIR, &netfid, &oplock, buf,
283 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags 419 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags
284 & CIFS_MOUNT_MAP_SPECIAL_CHR); 420 & CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -295,12 +431,12 @@ int cifs_open(struct inode *inode, struct file *file)
295 } 431 }
296 pCifsFile = cifs_init_private(file->private_data, inode, file, netfid); 432 pCifsFile = cifs_init_private(file->private_data, inode, file, netfid);
297 write_lock(&GlobalSMBSeslock); 433 write_lock(&GlobalSMBSeslock);
298 list_add(&pCifsFile->tlist, &pTcon->openFileList); 434 list_add(&pCifsFile->tlist, &tcon->openFileList);
299 435
300 pCifsInode = CIFS_I(file->f_path.dentry->d_inode); 436 pCifsInode = CIFS_I(file->f_path.dentry->d_inode);
301 if (pCifsInode) { 437 if (pCifsInode) {
302 rc = cifs_open_inode_helper(inode, file, pCifsInode, 438 rc = cifs_open_inode_helper(inode, file, pCifsInode,
303 pCifsFile, pTcon, 439 pCifsFile, tcon,
304 &oplock, buf, full_path, xid); 440 &oplock, buf, full_path, xid);
305 } else { 441 } else {
306 write_unlock(&GlobalSMBSeslock); 442 write_unlock(&GlobalSMBSeslock);
@@ -309,7 +445,7 @@ int cifs_open(struct inode *inode, struct file *file)
309 if (oplock & CIFS_CREATE_ACTION) { 445 if (oplock & CIFS_CREATE_ACTION) {
310 /* time to set mode which we can not set earlier due to 446 /* time to set mode which we can not set earlier due to
311 problems creating new read-only files */ 447 problems creating new read-only files */
312 if (pTcon->unix_ext) { 448 if (tcon->unix_ext) {
313 struct cifs_unix_set_info_args args = { 449 struct cifs_unix_set_info_args args = {
314 .mode = inode->i_mode, 450 .mode = inode->i_mode,
315 .uid = NO_CHANGE_64, 451 .uid = NO_CHANGE_64,
@@ -319,7 +455,7 @@ int cifs_open(struct inode *inode, struct file *file)
319 .mtime = NO_CHANGE_64, 455 .mtime = NO_CHANGE_64,
320 .device = 0, 456 .device = 0,
321 }; 457 };
322 CIFSSMBUnixSetInfo(xid, pTcon, full_path, &args, 458 CIFSSMBUnixSetInfo(xid, tcon, full_path, &args,
323 cifs_sb->local_nls, 459 cifs_sb->local_nls,
324 cifs_sb->mnt_cifs_flags & 460 cifs_sb->mnt_cifs_flags &
325 CIFS_MOUNT_MAP_SPECIAL_CHR); 461 CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -349,7 +485,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush)
349 int rc = -EACCES; 485 int rc = -EACCES;
350 int xid, oplock; 486 int xid, oplock;
351 struct cifs_sb_info *cifs_sb; 487 struct cifs_sb_info *cifs_sb;
352 struct cifsTconInfo *pTcon; 488 struct cifsTconInfo *tcon;
353 struct cifsFileInfo *pCifsFile; 489 struct cifsFileInfo *pCifsFile;
354 struct cifsInodeInfo *pCifsInode; 490 struct cifsInodeInfo *pCifsInode;
355 struct inode *inode; 491 struct inode *inode;
@@ -387,7 +523,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush)
387 } 523 }
388 524
389 cifs_sb = CIFS_SB(inode->i_sb); 525 cifs_sb = CIFS_SB(inode->i_sb);
390 pTcon = cifs_sb->tcon; 526 tcon = cifs_sb->tcon;
391 527
392/* can not grab rename sem here because various ops, including 528/* can not grab rename sem here because various ops, including
393 those that already have the rename sem can end up causing writepage 529 those that already have the rename sem can end up causing writepage
@@ -404,20 +540,37 @@ reopen_error_exit:
404 540
405 cFYI(1, ("inode = 0x%p file flags 0x%x for %s", 541 cFYI(1, ("inode = 0x%p file flags 0x%x for %s",
406 inode, file->f_flags, full_path)); 542 inode, file->f_flags, full_path));
407 desiredAccess = cifs_convert_flags(file->f_flags);
408 543
409 if (oplockEnabled) 544 if (oplockEnabled)
410 oplock = REQ_OPLOCK; 545 oplock = REQ_OPLOCK;
411 else 546 else
412 oplock = 0; 547 oplock = 0;
413 548
549 if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) &&
550 (CIFS_UNIX_POSIX_PATH_OPS_CAP &
551 le64_to_cpu(tcon->fsUnixInfo.Capability))) {
552 int oflags = (int) cifs_posix_convert_flags(file->f_flags);
553 /* can not refresh inode info since size could be stale */
554 rc = cifs_posix_open(full_path, NULL, inode->i_sb,
555 cifs_sb->mnt_file_mode /* ignored */,
556 oflags, &oplock, &netfid, xid);
557 if (rc == 0) {
558 cFYI(1, ("posix reopen succeeded"));
559 goto reopen_success;
560 }
561 /* fallthrough to retry open the old way on errors, especially
562 in the reconnect path it is important to retry hard */
563 }
564
565 desiredAccess = cifs_convert_flags(file->f_flags);
566
414 /* Can not refresh inode by passing in file_info buf to be returned 567 /* Can not refresh inode by passing in file_info buf to be returned
415 by SMBOpen and then calling get_inode_info with returned buf 568 by SMBOpen and then calling get_inode_info with returned buf
416 since file might have write behind data that needs to be flushed 569 since file might have write behind data that needs to be flushed
417 and server version of file size can be stale. If we knew for sure 570 and server version of file size can be stale. If we knew for sure
418 that inode was not dirty locally we could do this */ 571 that inode was not dirty locally we could do this */
419 572
420 rc = CIFSSMBOpen(xid, pTcon, full_path, disposition, desiredAccess, 573 rc = CIFSSMBOpen(xid, tcon, full_path, disposition, desiredAccess,
421 CREATE_NOT_DIR, &netfid, &oplock, NULL, 574 CREATE_NOT_DIR, &netfid, &oplock, NULL,
422 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 575 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
423 CIFS_MOUNT_MAP_SPECIAL_CHR); 576 CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -426,6 +579,7 @@ reopen_error_exit:
426 cFYI(1, ("cifs_open returned 0x%x", rc)); 579 cFYI(1, ("cifs_open returned 0x%x", rc));
427 cFYI(1, ("oplock: %d", oplock)); 580 cFYI(1, ("oplock: %d", oplock));
428 } else { 581 } else {
582reopen_success:
429 pCifsFile->netfid = netfid; 583 pCifsFile->netfid = netfid;
430 pCifsFile->invalidHandle = false; 584 pCifsFile->invalidHandle = false;
431 up(&pCifsFile->fh_sem); 585 up(&pCifsFile->fh_sem);
@@ -439,7 +593,7 @@ reopen_error_exit:
439 go to server to get inode info */ 593 go to server to get inode info */
440 pCifsInode->clientCanCacheAll = false; 594 pCifsInode->clientCanCacheAll = false;
441 pCifsInode->clientCanCacheRead = false; 595 pCifsInode->clientCanCacheRead = false;
442 if (pTcon->unix_ext) 596 if (tcon->unix_ext)
443 rc = cifs_get_inode_info_unix(&inode, 597 rc = cifs_get_inode_info_unix(&inode,
444 full_path, inode->i_sb, xid); 598 full_path, inode->i_sb, xid);
445 else 599 else
@@ -467,7 +621,6 @@ reopen_error_exit:
467 cifs_relock_file(pCifsFile); 621 cifs_relock_file(pCifsFile);
468 } 622 }
469 } 623 }
470
471 kfree(full_path); 624 kfree(full_path);
472 FreeXid(xid); 625 FreeXid(xid);
473 return rc; 626 return rc;
@@ -1523,6 +1676,9 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
1523{ 1676{
1524 int xid; 1677 int xid;
1525 int rc = 0; 1678 int rc = 0;
1679 struct cifsTconInfo *tcon;
1680 struct cifsFileInfo *smbfile =
1681 (struct cifsFileInfo *)file->private_data;
1526 struct inode *inode = file->f_path.dentry->d_inode; 1682 struct inode *inode = file->f_path.dentry->d_inode;
1527 1683
1528 xid = GetXid(); 1684 xid = GetXid();
@@ -1534,7 +1690,12 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
1534 if (rc == 0) { 1690 if (rc == 0) {
1535 rc = CIFS_I(inode)->write_behind_rc; 1691 rc = CIFS_I(inode)->write_behind_rc;
1536 CIFS_I(inode)->write_behind_rc = 0; 1692 CIFS_I(inode)->write_behind_rc = 0;
1693 tcon = CIFS_SB(inode->i_sb)->tcon;
1694 if (!rc && tcon && smbfile &&
1695 !(CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC))
1696 rc = CIFSSMBFlush(xid, tcon, smbfile->netfid);
1537 } 1697 }
1698
1538 FreeXid(xid); 1699 FreeXid(xid);
1539 return rc; 1700 return rc;
1540} 1701}
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 4690a360c85..a8797cc6080 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -763,6 +763,9 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, int xid,
763 struct cifsTconInfo *pTcon = cifs_sb->tcon; 763 struct cifsTconInfo *pTcon = cifs_sb->tcon;
764 FILE_BASIC_INFO info_buf; 764 FILE_BASIC_INFO info_buf;
765 765
766 if (attrs == NULL)
767 return -EINVAL;
768
766 if (attrs->ia_valid & ATTR_ATIME) { 769 if (attrs->ia_valid & ATTR_ATIME) {
767 set_time = true; 770 set_time = true;
768 info_buf.LastAccessTime = 771 info_buf.LastAccessTime =
diff --git a/fs/cifs/smbfsctl.h b/fs/cifs/smbfsctl.h
new file mode 100644
index 00000000000..7056b891e08
--- /dev/null
+++ b/fs/cifs/smbfsctl.h
@@ -0,0 +1,84 @@
1/*
2 * fs/cifs/smbfsctl.h: SMB, CIFS, SMB2 FSCTL definitions
3 *
4 * Copyright (c) International Business Machines Corp., 2002,2009
5 * Author(s): Steve French (sfrench@us.ibm.com)
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 * the GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22/* IOCTL information */
23/*
24 * List of ioctl/fsctl function codes that are or could be useful in the
25 * future to remote clients like cifs or SMB2 client. There is probably
26 * a slightly larger set of fsctls that NTFS local filesystem could handle,
27 * including the seven below that we do not have struct definitions for.
28 * Even with protocol definitions for most of these now available, we still
29 * need to do some experimentation to identify which are practical to do
30 * remotely. Some of the following, such as the encryption/compression ones
31 * could be invoked from tools via a specialized hook into the VFS rather
32 * than via the standard vfs entry points
33 */
34#define FSCTL_REQUEST_OPLOCK_LEVEL_1 0x00090000
35#define FSCTL_REQUEST_OPLOCK_LEVEL_2 0x00090004
36#define FSCTL_REQUEST_BATCH_OPLOCK 0x00090008
37#define FSCTL_LOCK_VOLUME 0x00090018
38#define FSCTL_UNLOCK_VOLUME 0x0009001C
39#define FSCTL_IS_PATHNAME_VALID 0x0009002C /* BB add struct */
40#define FSCTL_GET_COMPRESSION 0x0009003C /* BB add struct */
41#define FSCTL_SET_COMPRESSION 0x0009C040 /* BB add struct */
42#define FSCTL_QUERY_FAT_BPB 0x00090058 /* BB add struct */
43/* Verify the next FSCTL number, we had it as 0x00090090 before */
44#define FSCTL_FILESYSTEM_GET_STATS 0x00090060 /* BB add struct */
45#define FSCTL_GET_NTFS_VOLUME_DATA 0x00090064 /* BB add struct */
46#define FSCTL_GET_RETRIEVAL_POINTERS 0x00090073 /* BB add struct */
47#define FSCTL_IS_VOLUME_DIRTY 0x00090078 /* BB add struct */
48#define FSCTL_ALLOW_EXTENDED_DASD_IO 0x00090083 /* BB add struct */
49#define FSCTL_REQUEST_FILTER_OPLOCK 0x0009008C
50#define FSCTL_FIND_FILES_BY_SID 0x0009008F /* BB add struct */
51#define FSCTL_SET_OBJECT_ID 0x00090098 /* BB add struct */
52#define FSCTL_GET_OBJECT_ID 0x0009009C /* BB add struct */
53#define FSCTL_DELETE_OBJECT_ID 0x000900A0 /* BB add struct */
54#define FSCTL_SET_REPARSE_POINT 0x000900A4 /* BB add struct */
55#define FSCTL_GET_REPARSE_POINT 0x000900A8 /* BB add struct */
56#define FSCTL_DELETE_REPARSE_POINT 0x000900AC /* BB add struct */
57#define FSCTL_SET_OBJECT_ID_EXTENDED 0x000900BC /* BB add struct */
58#define FSCTL_CREATE_OR_GET_OBJECT_ID 0x000900C0 /* BB add struct */
59#define FSCTL_SET_SPARSE 0x000900C4 /* BB add struct */
60#define FSCTL_SET_ZERO_DATA 0x000900C8 /* BB add struct */
61#define FSCTL_SET_ENCRYPTION 0x000900D7 /* BB add struct */
62#define FSCTL_ENCRYPTION_FSCTL_IO 0x000900DB /* BB add struct */
63#define FSCTL_WRITE_RAW_ENCRYPTED 0x000900DF /* BB add struct */
64#define FSCTL_READ_RAW_ENCRYPTED 0x000900E3 /* BB add struct */
65#define FSCTL_READ_FILE_USN_DATA 0x000900EB /* BB add struct */
66#define FSCTL_WRITE_USN_CLOSE_RECORD 0x000900EF /* BB add struct */
67#define FSCTL_SIS_COPYFILE 0x00090100 /* BB add struct */
68#define FSCTL_RECALL_FILE 0x00090117 /* BB add struct */
69#define FSCTL_QUERY_SPARING_INFO 0x00090138 /* BB add struct */
70#define FSCTL_SET_ZERO_ON_DEALLOC 0x00090194 /* BB add struct */
71#define FSCTL_SET_SHORT_NAME_BEHAVIOR 0x000901B4 /* BB add struct */
72#define FSCTL_QUERY_ALLOCATED_RANGES 0x000940CF /* BB add struct */
73#define FSCTL_SET_DEFECT_MANAGEMENT 0x00098134 /* BB add struct */
74#define FSCTL_SIS_LINK_FILES 0x0009C104
75#define FSCTL_PIPE_PEEK 0x0011400C /* BB add struct */
76#define FSCTL_PIPE_TRANSCEIVE 0x0011C017 /* BB add struct */
77/* strange that the number for this op is not sequential with previous op */
78#define FSCTL_PIPE_WAIT 0x00110018 /* BB add struct */
79#define FSCTL_LMR_GET_LINK_TRACK_INF 0x001400E8 /* BB add struct */
80#define FSCTL_LMR_SET_LINK_TRACK_INF 0x001400EC /* BB add struct */
81
82#define IO_REPARSE_TAG_MOUNT_POINT 0xA0000003
83#define IO_REPARSE_TAG_HSM 0xC0000004
84#define IO_REPARSE_TAG_SIS 0x80000007
diff --git a/fs/coda/dir.c b/fs/coda/dir.c
index 75b1fa90b2c..4bb9d0a5dec 100644
--- a/fs/coda/dir.c
+++ b/fs/coda/dir.c
@@ -59,7 +59,7 @@ static int coda_return_EIO(void)
59} 59}
60#define CODA_EIO_ERROR ((void *) (coda_return_EIO)) 60#define CODA_EIO_ERROR ((void *) (coda_return_EIO))
61 61
62static struct dentry_operations coda_dentry_operations = 62static const struct dentry_operations coda_dentry_operations =
63{ 63{
64 .d_revalidate = coda_dentry_revalidate, 64 .d_revalidate = coda_dentry_revalidate,
65 .d_delete = coda_dentry_delete, 65 .d_delete = coda_dentry_delete,
diff --git a/fs/compat.c b/fs/compat.c
index d0145ca2757..55efdfebdf5 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -378,6 +378,34 @@ out:
378 return error; 378 return error;
379} 379}
380 380
381/*
382 * This is a copy of sys_ustat, just dealing with a structure layout.
383 * Given how simple this syscall is that apporach is more maintainable
384 * than the various conversion hacks.
385 */
386asmlinkage long compat_sys_ustat(unsigned dev, struct compat_ustat __user *u)
387{
388 struct super_block *sb;
389 struct compat_ustat tmp;
390 struct kstatfs sbuf;
391 int err;
392
393 sb = user_get_super(new_decode_dev(dev));
394 if (!sb)
395 return -EINVAL;
396 err = vfs_statfs(sb->s_root, &sbuf);
397 drop_super(sb);
398 if (err)
399 return err;
400
401 memset(&tmp, 0, sizeof(struct compat_ustat));
402 tmp.f_tfree = sbuf.f_bfree;
403 tmp.f_tinode = sbuf.f_ffree;
404 if (copy_to_user(u, &tmp, sizeof(struct compat_ustat)))
405 return -EFAULT;
406 return 0;
407}
408
381static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl) 409static int get_compat_flock(struct flock *kfl, struct compat_flock __user *ufl)
382{ 410{
383 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) || 411 if (!access_ok(VERIFY_READ, ufl, sizeof(*ufl)) ||
@@ -1392,22 +1420,28 @@ int compat_do_execve(char * filename,
1392{ 1420{
1393 struct linux_binprm *bprm; 1421 struct linux_binprm *bprm;
1394 struct file *file; 1422 struct file *file;
1423 struct files_struct *displaced;
1395 int retval; 1424 int retval;
1396 1425
1426 retval = unshare_files(&displaced);
1427 if (retval)
1428 goto out_ret;
1429
1397 retval = -ENOMEM; 1430 retval = -ENOMEM;
1398 bprm = kzalloc(sizeof(*bprm), GFP_KERNEL); 1431 bprm = kzalloc(sizeof(*bprm), GFP_KERNEL);
1399 if (!bprm) 1432 if (!bprm)
1400 goto out_ret; 1433 goto out_files;
1401 1434
1402 retval = mutex_lock_interruptible(&current->cred_exec_mutex); 1435 retval = mutex_lock_interruptible(&current->cred_exec_mutex);
1403 if (retval < 0) 1436 if (retval < 0)
1404 goto out_free; 1437 goto out_free;
1438 current->in_execve = 1;
1405 1439
1406 retval = -ENOMEM; 1440 retval = -ENOMEM;
1407 bprm->cred = prepare_exec_creds(); 1441 bprm->cred = prepare_exec_creds();
1408 if (!bprm->cred) 1442 if (!bprm->cred)
1409 goto out_unlock; 1443 goto out_unlock;
1410 check_unsafe_exec(bprm, current->files); 1444 check_unsafe_exec(bprm);
1411 1445
1412 file = open_exec(filename); 1446 file = open_exec(filename);
1413 retval = PTR_ERR(file); 1447 retval = PTR_ERR(file);
@@ -1454,9 +1488,12 @@ int compat_do_execve(char * filename,
1454 goto out; 1488 goto out;
1455 1489
1456 /* execve succeeded */ 1490 /* execve succeeded */
1491 current->in_execve = 0;
1457 mutex_unlock(&current->cred_exec_mutex); 1492 mutex_unlock(&current->cred_exec_mutex);
1458 acct_update_integrals(current); 1493 acct_update_integrals(current);
1459 free_bprm(bprm); 1494 free_bprm(bprm);
1495 if (displaced)
1496 put_files_struct(displaced);
1460 return retval; 1497 return retval;
1461 1498
1462out: 1499out:
@@ -1470,11 +1507,15 @@ out_file:
1470 } 1507 }
1471 1508
1472out_unlock: 1509out_unlock:
1510 current->in_execve = 0;
1473 mutex_unlock(&current->cred_exec_mutex); 1511 mutex_unlock(&current->cred_exec_mutex);
1474 1512
1475out_free: 1513out_free:
1476 free_bprm(bprm); 1514 free_bprm(bprm);
1477 1515
1516out_files:
1517 if (displaced)
1518 reset_files_struct(displaced);
1478out_ret: 1519out_ret:
1479 return retval; 1520 return retval;
1480} 1521}
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 45e59d3c7f1..ff786687e93 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -522,6 +522,11 @@ static int dev_ifsioc(unsigned int fd, unsigned int cmd, unsigned long arg)
522 if (err) 522 if (err)
523 return -EFAULT; 523 return -EFAULT;
524 break; 524 break;
525 case SIOCSHWTSTAMP:
526 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
527 return -EFAULT;
528 ifr.ifr_data = compat_ptr(uifr32->ifr_ifru.ifru_data);
529 break;
525 default: 530 default:
526 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32))) 531 if (copy_from_user(&ifr, uifr32, sizeof(*uifr32)))
527 return -EFAULT; 532 return -EFAULT;
@@ -1993,6 +1998,8 @@ COMPATIBLE_IOCTL(TUNSETGROUP)
1993COMPATIBLE_IOCTL(TUNGETFEATURES) 1998COMPATIBLE_IOCTL(TUNGETFEATURES)
1994COMPATIBLE_IOCTL(TUNSETOFFLOAD) 1999COMPATIBLE_IOCTL(TUNSETOFFLOAD)
1995COMPATIBLE_IOCTL(TUNSETTXFILTER) 2000COMPATIBLE_IOCTL(TUNSETTXFILTER)
2001COMPATIBLE_IOCTL(TUNGETSNDBUF)
2002COMPATIBLE_IOCTL(TUNSETSNDBUF)
1996/* Big V */ 2003/* Big V */
1997COMPATIBLE_IOCTL(VT_SETMODE) 2004COMPATIBLE_IOCTL(VT_SETMODE)
1998COMPATIBLE_IOCTL(VT_GETMODE) 2005COMPATIBLE_IOCTL(VT_GETMODE)
@@ -2566,6 +2573,7 @@ HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
2566HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc) 2573HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
2567HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc) 2574HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
2568HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc) 2575HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
2576HANDLE_IOCTL(SIOCSHWTSTAMP, dev_ifsioc)
2569 2577
2570/* ioctls used by appletalk ddp.c */ 2578/* ioctls used by appletalk ddp.c */
2571HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc) 2579HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
index 8e93341f3e8..05373db21a4 100644
--- a/fs/configfs/dir.c
+++ b/fs/configfs/dir.c
@@ -72,7 +72,7 @@ static int configfs_d_delete(struct dentry *dentry)
72 return 1; 72 return 1;
73} 73}
74 74
75static struct dentry_operations configfs_dentry_ops = { 75static const struct dentry_operations configfs_dentry_ops = {
76 .d_iput = configfs_d_iput, 76 .d_iput = configfs_d_iput,
77 /* simple_delete_dentry() isn't exported */ 77 /* simple_delete_dentry() isn't exported */
78 .d_delete = configfs_d_delete, 78 .d_delete = configfs_d_delete,
diff --git a/fs/dcache.c b/fs/dcache.c
index 07e2d4a44bd..90bbd7e1b11 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1247,15 +1247,18 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode,
1247 struct dentry *found; 1247 struct dentry *found;
1248 struct dentry *new; 1248 struct dentry *new;
1249 1249
1250 /* Does a dentry matching the name exist already? */ 1250 /*
1251 * First check if a dentry matching the name already exists,
1252 * if not go ahead and create it now.
1253 */
1251 found = d_hash_and_lookup(dentry->d_parent, name); 1254 found = d_hash_and_lookup(dentry->d_parent, name);
1252 /* If not, create it now and return */
1253 if (!found) { 1255 if (!found) {
1254 new = d_alloc(dentry->d_parent, name); 1256 new = d_alloc(dentry->d_parent, name);
1255 if (!new) { 1257 if (!new) {
1256 error = -ENOMEM; 1258 error = -ENOMEM;
1257 goto err_out; 1259 goto err_out;
1258 } 1260 }
1261
1259 found = d_splice_alias(inode, new); 1262 found = d_splice_alias(inode, new);
1260 if (found) { 1263 if (found) {
1261 dput(new); 1264 dput(new);
@@ -1263,61 +1266,46 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode,
1263 } 1266 }
1264 return new; 1267 return new;
1265 } 1268 }
1266 /* Matching dentry exists, check if it is negative. */ 1269
1270 /*
1271 * If a matching dentry exists, and it's not negative use it.
1272 *
1273 * Decrement the reference count to balance the iget() done
1274 * earlier on.
1275 */
1267 if (found->d_inode) { 1276 if (found->d_inode) {
1268 if (unlikely(found->d_inode != inode)) { 1277 if (unlikely(found->d_inode != inode)) {
1269 /* This can't happen because bad inodes are unhashed. */ 1278 /* This can't happen because bad inodes are unhashed. */
1270 BUG_ON(!is_bad_inode(inode)); 1279 BUG_ON(!is_bad_inode(inode));
1271 BUG_ON(!is_bad_inode(found->d_inode)); 1280 BUG_ON(!is_bad_inode(found->d_inode));
1272 } 1281 }
1273 /*
1274 * Already have the inode and the dentry attached, decrement
1275 * the reference count to balance the iget() done
1276 * earlier on. We found the dentry using d_lookup() so it
1277 * cannot be disconnected and thus we do not need to worry
1278 * about any NFS/disconnectedness issues here.
1279 */
1280 iput(inode); 1282 iput(inode);
1281 return found; 1283 return found;
1282 } 1284 }
1285
1283 /* 1286 /*
1284 * Negative dentry: instantiate it unless the inode is a directory and 1287 * Negative dentry: instantiate it unless the inode is a directory and
1285 * has a 'disconnected' dentry (i.e. IS_ROOT and DCACHE_DISCONNECTED), 1288 * already has a dentry.
1286 * in which case d_move() that in place of the found dentry.
1287 */ 1289 */
1288 if (!S_ISDIR(inode->i_mode)) {
1289 /* Not a directory; everything is easy. */
1290 d_instantiate(found, inode);
1291 return found;
1292 }
1293 spin_lock(&dcache_lock); 1290 spin_lock(&dcache_lock);
1294 if (list_empty(&inode->i_dentry)) { 1291 if (!S_ISDIR(inode->i_mode) || list_empty(&inode->i_dentry)) {
1295 /*
1296 * Directory without a 'disconnected' dentry; we need to do
1297 * d_instantiate() by hand because it takes dcache_lock which
1298 * we already hold.
1299 */
1300 __d_instantiate(found, inode); 1292 __d_instantiate(found, inode);
1301 spin_unlock(&dcache_lock); 1293 spin_unlock(&dcache_lock);
1302 security_d_instantiate(found, inode); 1294 security_d_instantiate(found, inode);
1303 return found; 1295 return found;
1304 } 1296 }
1297
1305 /* 1298 /*
1306 * Directory with a 'disconnected' dentry; get a reference to the 1299 * In case a directory already has a (disconnected) entry grab a
1307 * 'disconnected' dentry. 1300 * reference to it, move it in place and use it.
1308 */ 1301 */
1309 new = list_entry(inode->i_dentry.next, struct dentry, d_alias); 1302 new = list_entry(inode->i_dentry.next, struct dentry, d_alias);
1310 dget_locked(new); 1303 dget_locked(new);
1311 spin_unlock(&dcache_lock); 1304 spin_unlock(&dcache_lock);
1312 /* Do security vodoo. */
1313 security_d_instantiate(found, inode); 1305 security_d_instantiate(found, inode);
1314 /* Move new in place of found. */
1315 d_move(new, found); 1306 d_move(new, found);
1316 /* Balance the iget() we did above. */
1317 iput(inode); 1307 iput(inode);
1318 /* Throw away found. */
1319 dput(found); 1308 dput(found);
1320 /* Use new as the actual dentry. */
1321 return new; 1309 return new;
1322 1310
1323err_out: 1311err_out:
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index bff4052b05e..63a4a59e414 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -322,177 +322,81 @@ static int compare_init_pts_sb(struct super_block *s, void *p)
322} 322}
323 323
324/* 324/*
325 * Safely parse the mount options in @data and update @opts. 325 * devpts_get_sb()
326 * 326 *
327 * devpts ends up parsing options two times during mount, due to the 327 * If the '-o newinstance' mount option was specified, mount a new
328 * two modes of operation it supports. The first parse occurs in 328 * (private) instance of devpts. PTYs created in this instance are
329 * devpts_get_sb() when determining the mode (single-instance or 329 * independent of the PTYs in other devpts instances.
330 * multi-instance mode). The second parse happens in devpts_remount()
331 * or new_pts_mount() depending on the mode.
332 * 330 *
333 * Parsing of options modifies the @data making subsequent parsing 331 * If the '-o newinstance' option was not specified, mount/remount the
334 * incorrect. So make a local copy of @data and parse it. 332 * initial kernel mount of devpts. This type of mount gives the
333 * legacy, single-instance semantics.
335 * 334 *
336 * Return: 0 On success, -errno on error 335 * The 'newinstance' option is needed to support multiple namespace
337 */ 336 * semantics in devpts while preserving backward compatibility of the
338static int safe_parse_mount_options(void *data, struct pts_mount_opts *opts) 337 * current 'single-namespace' semantics. i.e all mounts of devpts
339{ 338 * without the 'newinstance' mount option should bind to the initial
340 int rc; 339 * kernel mount, like get_sb_single().
341 void *datacp;
342
343 if (!data)
344 return 0;
345
346 /* Use kstrdup() ? */
347 datacp = kmalloc(PAGE_SIZE, GFP_KERNEL);
348 if (!datacp)
349 return -ENOMEM;
350
351 memcpy(datacp, data, PAGE_SIZE);
352 rc = parse_mount_options((char *)datacp, PARSE_MOUNT, opts);
353 kfree(datacp);
354
355 return rc;
356}
357
358/*
359 * Mount a new (private) instance of devpts. PTYs created in this
360 * instance are independent of the PTYs in other devpts instances.
361 */
362static int new_pts_mount(struct file_system_type *fs_type, int flags,
363 void *data, struct vfsmount *mnt)
364{
365 int err;
366 struct pts_fs_info *fsi;
367 struct pts_mount_opts *opts;
368
369 err = get_sb_nodev(fs_type, flags, data, devpts_fill_super, mnt);
370 if (err)
371 return err;
372
373 fsi = DEVPTS_SB(mnt->mnt_sb);
374 opts = &fsi->mount_opts;
375
376 err = parse_mount_options(data, PARSE_MOUNT, opts);
377 if (err)
378 goto fail;
379
380 err = mknod_ptmx(mnt->mnt_sb);
381 if (err)
382 goto fail;
383
384 return 0;
385
386fail:
387 dput(mnt->mnt_sb->s_root);
388 deactivate_super(mnt->mnt_sb);
389 return err;
390}
391
392/*
393 * Check if 'newinstance' mount option was specified in @data.
394 * 340 *
395 * Return: -errno on error (eg: invalid mount options specified) 341 * Mounts with 'newinstance' option create a new, private namespace.
396 * : 1 if 'newinstance' mount option was specified
397 * : 0 if 'newinstance' mount option was NOT specified
398 */
399static int is_new_instance_mount(void *data)
400{
401 int rc;
402 struct pts_mount_opts opts;
403
404 if (!data)
405 return 0;
406
407 rc = safe_parse_mount_options(data, &opts);
408 if (!rc)
409 rc = opts.newinstance;
410
411 return rc;
412}
413
414/*
415 * get_init_pts_sb()
416 *
417 * This interface is needed to support multiple namespace semantics in
418 * devpts while preserving backward compatibility of the current 'single-
419 * namespace' semantics. i.e all mounts of devpts without the 'newinstance'
420 * mount option should bind to the initial kernel mount, like
421 * get_sb_single().
422 * 342 *
423 * Mounts with 'newinstance' option create a new private namespace. 343 * NOTE:
424 * 344 *
425 * But for single-mount semantics, devpts cannot use get_sb_single(), 345 * For single-mount semantics, devpts cannot use get_sb_single(),
426 * because get_sb_single()/sget() find and use the super-block from 346 * because get_sb_single()/sget() find and use the super-block from
427 * the most recent mount of devpts. But that recent mount may be a 347 * the most recent mount of devpts. But that recent mount may be a
428 * 'newinstance' mount and get_sb_single() would pick the newinstance 348 * 'newinstance' mount and get_sb_single() would pick the newinstance
429 * super-block instead of the initial super-block. 349 * super-block instead of the initial super-block.
430 *
431 * This interface is identical to get_sb_single() except that it
432 * consistently selects the 'single-namespace' superblock even in the
433 * presence of the private namespace (i.e 'newinstance') super-blocks.
434 */ 350 */
435static int get_init_pts_sb(struct file_system_type *fs_type, int flags, 351static int devpts_get_sb(struct file_system_type *fs_type,
436 void *data, struct vfsmount *mnt) 352 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
437{ 353{
438 struct super_block *s;
439 int error; 354 int error;
355 struct pts_mount_opts opts;
356 struct super_block *s;
357
358 memset(&opts, 0, sizeof(opts));
359 if (data) {
360 error = parse_mount_options(data, PARSE_MOUNT, &opts);
361 if (error)
362 return error;
363 }
364
365 if (opts.newinstance)
366 s = sget(fs_type, NULL, set_anon_super, NULL);
367 else
368 s = sget(fs_type, compare_init_pts_sb, set_anon_super, NULL);
440 369
441 s = sget(fs_type, compare_init_pts_sb, set_anon_super, NULL);
442 if (IS_ERR(s)) 370 if (IS_ERR(s))
443 return PTR_ERR(s); 371 return PTR_ERR(s);
444 372
445 if (!s->s_root) { 373 if (!s->s_root) {
446 s->s_flags = flags; 374 s->s_flags = flags;
447 error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0); 375 error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0);
448 if (error) { 376 if (error)
449 up_write(&s->s_umount); 377 goto out_undo_sget;
450 deactivate_super(s);
451 return error;
452 }
453 s->s_flags |= MS_ACTIVE; 378 s->s_flags |= MS_ACTIVE;
454 } 379 }
455 do_remount_sb(s, flags, data, 0);
456 return simple_set_mnt(mnt, s);
457}
458 380
459/* 381 simple_set_mnt(mnt, s);
460 * Mount or remount the initial kernel mount of devpts. This type of
461 * mount maintains the legacy, single-instance semantics, while the
462 * kernel still allows multiple-instances.
463 */
464static int init_pts_mount(struct file_system_type *fs_type, int flags,
465 void *data, struct vfsmount *mnt)
466{
467 int err;
468 382
469 err = get_init_pts_sb(fs_type, flags, data, mnt); 383 memcpy(&(DEVPTS_SB(s))->mount_opts, &opts, sizeof(opts));
470 if (err)
471 return err;
472 384
473 err = mknod_ptmx(mnt->mnt_sb); 385 error = mknod_ptmx(s);
474 if (err) { 386 if (error)
475 dput(mnt->mnt_sb->s_root); 387 goto out_dput;
476 deactivate_super(mnt->mnt_sb);
477 }
478 388
479 return err; 389 return 0;
480}
481
482static int devpts_get_sb(struct file_system_type *fs_type,
483 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
484{
485 int new;
486
487 new = is_new_instance_mount(data);
488 if (new < 0)
489 return new;
490 390
491 if (new) 391out_dput:
492 return new_pts_mount(fs_type, flags, data, mnt); 392 dput(s->s_root);
493 393
494 return init_pts_mount(fs_type, flags, data, mnt); 394out_undo_sget:
395 up_write(&s->s_umount);
396 deactivate_super(s);
397 return error;
495} 398}
399
496#else 400#else
497/* 401/*
498 * This supports only the legacy single-instance semantics (no 402 * This supports only the legacy single-instance semantics (no
diff --git a/fs/dlm/dir.c b/fs/dlm/dir.c
index 92969f879a1..858fba14aaa 100644
--- a/fs/dlm/dir.c
+++ b/fs/dlm/dir.c
@@ -156,7 +156,7 @@ void dlm_dir_remove_entry(struct dlm_ls *ls, int nodeid, char *name, int namelen
156 156
157 bucket = dir_hash(ls, name, namelen); 157 bucket = dir_hash(ls, name, namelen);
158 158
159 write_lock(&ls->ls_dirtbl[bucket].lock); 159 spin_lock(&ls->ls_dirtbl[bucket].lock);
160 160
161 de = search_bucket(ls, name, namelen, bucket); 161 de = search_bucket(ls, name, namelen, bucket);
162 162
@@ -173,7 +173,7 @@ void dlm_dir_remove_entry(struct dlm_ls *ls, int nodeid, char *name, int namelen
173 list_del(&de->list); 173 list_del(&de->list);
174 kfree(de); 174 kfree(de);
175 out: 175 out:
176 write_unlock(&ls->ls_dirtbl[bucket].lock); 176 spin_unlock(&ls->ls_dirtbl[bucket].lock);
177} 177}
178 178
179void dlm_dir_clear(struct dlm_ls *ls) 179void dlm_dir_clear(struct dlm_ls *ls)
@@ -185,14 +185,14 @@ void dlm_dir_clear(struct dlm_ls *ls)
185 DLM_ASSERT(list_empty(&ls->ls_recover_list), ); 185 DLM_ASSERT(list_empty(&ls->ls_recover_list), );
186 186
187 for (i = 0; i < ls->ls_dirtbl_size; i++) { 187 for (i = 0; i < ls->ls_dirtbl_size; i++) {
188 write_lock(&ls->ls_dirtbl[i].lock); 188 spin_lock(&ls->ls_dirtbl[i].lock);
189 head = &ls->ls_dirtbl[i].list; 189 head = &ls->ls_dirtbl[i].list;
190 while (!list_empty(head)) { 190 while (!list_empty(head)) {
191 de = list_entry(head->next, struct dlm_direntry, list); 191 de = list_entry(head->next, struct dlm_direntry, list);
192 list_del(&de->list); 192 list_del(&de->list);
193 put_free_de(ls, de); 193 put_free_de(ls, de);
194 } 194 }
195 write_unlock(&ls->ls_dirtbl[i].lock); 195 spin_unlock(&ls->ls_dirtbl[i].lock);
196 } 196 }
197} 197}
198 198
@@ -307,17 +307,17 @@ static int get_entry(struct dlm_ls *ls, int nodeid, char *name,
307 307
308 bucket = dir_hash(ls, name, namelen); 308 bucket = dir_hash(ls, name, namelen);
309 309
310 write_lock(&ls->ls_dirtbl[bucket].lock); 310 spin_lock(&ls->ls_dirtbl[bucket].lock);
311 de = search_bucket(ls, name, namelen, bucket); 311 de = search_bucket(ls, name, namelen, bucket);
312 if (de) { 312 if (de) {
313 *r_nodeid = de->master_nodeid; 313 *r_nodeid = de->master_nodeid;
314 write_unlock(&ls->ls_dirtbl[bucket].lock); 314 spin_unlock(&ls->ls_dirtbl[bucket].lock);
315 if (*r_nodeid == nodeid) 315 if (*r_nodeid == nodeid)
316 return -EEXIST; 316 return -EEXIST;
317 return 0; 317 return 0;
318 } 318 }
319 319
320 write_unlock(&ls->ls_dirtbl[bucket].lock); 320 spin_unlock(&ls->ls_dirtbl[bucket].lock);
321 321
322 if (namelen > DLM_RESNAME_MAXLEN) 322 if (namelen > DLM_RESNAME_MAXLEN)
323 return -EINVAL; 323 return -EINVAL;
@@ -330,7 +330,7 @@ static int get_entry(struct dlm_ls *ls, int nodeid, char *name,
330 de->length = namelen; 330 de->length = namelen;
331 memcpy(de->name, name, namelen); 331 memcpy(de->name, name, namelen);
332 332
333 write_lock(&ls->ls_dirtbl[bucket].lock); 333 spin_lock(&ls->ls_dirtbl[bucket].lock);
334 tmp = search_bucket(ls, name, namelen, bucket); 334 tmp = search_bucket(ls, name, namelen, bucket);
335 if (tmp) { 335 if (tmp) {
336 kfree(de); 336 kfree(de);
@@ -339,7 +339,7 @@ static int get_entry(struct dlm_ls *ls, int nodeid, char *name,
339 list_add_tail(&de->list, &ls->ls_dirtbl[bucket].list); 339 list_add_tail(&de->list, &ls->ls_dirtbl[bucket].list);
340 } 340 }
341 *r_nodeid = de->master_nodeid; 341 *r_nodeid = de->master_nodeid;
342 write_unlock(&ls->ls_dirtbl[bucket].lock); 342 spin_unlock(&ls->ls_dirtbl[bucket].lock);
343 return 0; 343 return 0;
344} 344}
345 345
diff --git a/fs/dlm/dlm_internal.h b/fs/dlm/dlm_internal.h
index 076e86f38bc..d01ca0a711d 100644
--- a/fs/dlm/dlm_internal.h
+++ b/fs/dlm/dlm_internal.h
@@ -99,7 +99,7 @@ struct dlm_direntry {
99 99
100struct dlm_dirtable { 100struct dlm_dirtable {
101 struct list_head list; 101 struct list_head list;
102 rwlock_t lock; 102 spinlock_t lock;
103}; 103};
104 104
105struct dlm_rsbtable { 105struct dlm_rsbtable {
diff --git a/fs/dlm/lock.c b/fs/dlm/lock.c
index 01e7d39c5fb..205ec95b347 100644
--- a/fs/dlm/lock.c
+++ b/fs/dlm/lock.c
@@ -835,7 +835,7 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype)
835 lkb->lkb_wait_count++; 835 lkb->lkb_wait_count++;
836 hold_lkb(lkb); 836 hold_lkb(lkb);
837 837
838 log_debug(ls, "add overlap %x cur %d new %d count %d flags %x", 838 log_debug(ls, "addwait %x cur %d overlap %d count %d f %x",
839 lkb->lkb_id, lkb->lkb_wait_type, mstype, 839 lkb->lkb_id, lkb->lkb_wait_type, mstype,
840 lkb->lkb_wait_count, lkb->lkb_flags); 840 lkb->lkb_wait_count, lkb->lkb_flags);
841 goto out; 841 goto out;
@@ -851,7 +851,7 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype)
851 list_add(&lkb->lkb_wait_reply, &ls->ls_waiters); 851 list_add(&lkb->lkb_wait_reply, &ls->ls_waiters);
852 out: 852 out:
853 if (error) 853 if (error)
854 log_error(ls, "add_to_waiters %x error %d flags %x %d %d %s", 854 log_error(ls, "addwait error %x %d flags %x %d %d %s",
855 lkb->lkb_id, error, lkb->lkb_flags, mstype, 855 lkb->lkb_id, error, lkb->lkb_flags, mstype,
856 lkb->lkb_wait_type, lkb->lkb_resource->res_name); 856 lkb->lkb_wait_type, lkb->lkb_resource->res_name);
857 mutex_unlock(&ls->ls_waiters_mutex); 857 mutex_unlock(&ls->ls_waiters_mutex);
@@ -863,23 +863,55 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype)
863 request reply on the requestqueue) between dlm_recover_waiters_pre() which 863 request reply on the requestqueue) between dlm_recover_waiters_pre() which
864 set RESEND and dlm_recover_waiters_post() */ 864 set RESEND and dlm_recover_waiters_post() */
865 865
866static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype) 866static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype,
867 struct dlm_message *ms)
867{ 868{
868 struct dlm_ls *ls = lkb->lkb_resource->res_ls; 869 struct dlm_ls *ls = lkb->lkb_resource->res_ls;
869 int overlap_done = 0; 870 int overlap_done = 0;
870 871
871 if (is_overlap_unlock(lkb) && (mstype == DLM_MSG_UNLOCK_REPLY)) { 872 if (is_overlap_unlock(lkb) && (mstype == DLM_MSG_UNLOCK_REPLY)) {
873 log_debug(ls, "remwait %x unlock_reply overlap", lkb->lkb_id);
872 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK; 874 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_UNLOCK;
873 overlap_done = 1; 875 overlap_done = 1;
874 goto out_del; 876 goto out_del;
875 } 877 }
876 878
877 if (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL_REPLY)) { 879 if (is_overlap_cancel(lkb) && (mstype == DLM_MSG_CANCEL_REPLY)) {
880 log_debug(ls, "remwait %x cancel_reply overlap", lkb->lkb_id);
878 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL; 881 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL;
879 overlap_done = 1; 882 overlap_done = 1;
880 goto out_del; 883 goto out_del;
881 } 884 }
882 885
886 /* Cancel state was preemptively cleared by a successful convert,
887 see next comment, nothing to do. */
888
889 if ((mstype == DLM_MSG_CANCEL_REPLY) &&
890 (lkb->lkb_wait_type != DLM_MSG_CANCEL)) {
891 log_debug(ls, "remwait %x cancel_reply wait_type %d",
892 lkb->lkb_id, lkb->lkb_wait_type);
893 return -1;
894 }
895
896 /* Remove for the convert reply, and premptively remove for the
897 cancel reply. A convert has been granted while there's still
898 an outstanding cancel on it (the cancel is moot and the result
899 in the cancel reply should be 0). We preempt the cancel reply
900 because the app gets the convert result and then can follow up
901 with another op, like convert. This subsequent op would see the
902 lingering state of the cancel and fail with -EBUSY. */
903
904 if ((mstype == DLM_MSG_CONVERT_REPLY) &&
905 (lkb->lkb_wait_type == DLM_MSG_CONVERT) &&
906 is_overlap_cancel(lkb) && ms && !ms->m_result) {
907 log_debug(ls, "remwait %x convert_reply zap overlap_cancel",
908 lkb->lkb_id);
909 lkb->lkb_wait_type = 0;
910 lkb->lkb_flags &= ~DLM_IFL_OVERLAP_CANCEL;
911 lkb->lkb_wait_count--;
912 goto out_del;
913 }
914
883 /* N.B. type of reply may not always correspond to type of original 915 /* N.B. type of reply may not always correspond to type of original
884 msg due to lookup->request optimization, verify others? */ 916 msg due to lookup->request optimization, verify others? */
885 917
@@ -888,8 +920,8 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype)
888 goto out_del; 920 goto out_del;
889 } 921 }
890 922
891 log_error(ls, "remove_from_waiters lkid %x flags %x types %d %d", 923 log_error(ls, "remwait error %x reply %d flags %x no wait_type",
892 lkb->lkb_id, lkb->lkb_flags, mstype, lkb->lkb_wait_type); 924 lkb->lkb_id, mstype, lkb->lkb_flags);
893 return -1; 925 return -1;
894 926
895 out_del: 927 out_del:
@@ -899,7 +931,7 @@ static int _remove_from_waiters(struct dlm_lkb *lkb, int mstype)
899 this would happen */ 931 this would happen */
900 932
901 if (overlap_done && lkb->lkb_wait_type) { 933 if (overlap_done && lkb->lkb_wait_type) {
902 log_error(ls, "remove_from_waiters %x reply %d give up on %d", 934 log_error(ls, "remwait error %x reply %d wait_type %d overlap",
903 lkb->lkb_id, mstype, lkb->lkb_wait_type); 935 lkb->lkb_id, mstype, lkb->lkb_wait_type);
904 lkb->lkb_wait_count--; 936 lkb->lkb_wait_count--;
905 lkb->lkb_wait_type = 0; 937 lkb->lkb_wait_type = 0;
@@ -921,7 +953,7 @@ static int remove_from_waiters(struct dlm_lkb *lkb, int mstype)
921 int error; 953 int error;
922 954
923 mutex_lock(&ls->ls_waiters_mutex); 955 mutex_lock(&ls->ls_waiters_mutex);
924 error = _remove_from_waiters(lkb, mstype); 956 error = _remove_from_waiters(lkb, mstype, NULL);
925 mutex_unlock(&ls->ls_waiters_mutex); 957 mutex_unlock(&ls->ls_waiters_mutex);
926 return error; 958 return error;
927} 959}
@@ -936,7 +968,7 @@ static int remove_from_waiters_ms(struct dlm_lkb *lkb, struct dlm_message *ms)
936 968
937 if (ms != &ls->ls_stub_ms) 969 if (ms != &ls->ls_stub_ms)
938 mutex_lock(&ls->ls_waiters_mutex); 970 mutex_lock(&ls->ls_waiters_mutex);
939 error = _remove_from_waiters(lkb, ms->m_type); 971 error = _remove_from_waiters(lkb, ms->m_type, ms);
940 if (ms != &ls->ls_stub_ms) 972 if (ms != &ls->ls_stub_ms)
941 mutex_unlock(&ls->ls_waiters_mutex); 973 mutex_unlock(&ls->ls_waiters_mutex);
942 return error; 974 return error;
@@ -2083,6 +2115,11 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,
2083 lkb->lkb_timeout_cs = args->timeout; 2115 lkb->lkb_timeout_cs = args->timeout;
2084 rv = 0; 2116 rv = 0;
2085 out: 2117 out:
2118 if (rv)
2119 log_debug(ls, "validate_lock_args %d %x %x %x %d %d %s",
2120 rv, lkb->lkb_id, lkb->lkb_flags, args->flags,
2121 lkb->lkb_status, lkb->lkb_wait_type,
2122 lkb->lkb_resource->res_name);
2086 return rv; 2123 return rv;
2087} 2124}
2088 2125
@@ -2149,6 +2186,13 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args)
2149 goto out; 2186 goto out;
2150 } 2187 }
2151 2188
2189 /* there's nothing to cancel */
2190 if (lkb->lkb_status == DLM_LKSTS_GRANTED &&
2191 !lkb->lkb_wait_type) {
2192 rv = -EBUSY;
2193 goto out;
2194 }
2195
2152 switch (lkb->lkb_wait_type) { 2196 switch (lkb->lkb_wait_type) {
2153 case DLM_MSG_LOOKUP: 2197 case DLM_MSG_LOOKUP:
2154 case DLM_MSG_REQUEST: 2198 case DLM_MSG_REQUEST:
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index aa32e5f0249..cd8e2df3c29 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -487,7 +487,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
487 goto out_lkbfree; 487 goto out_lkbfree;
488 for (i = 0; i < size; i++) { 488 for (i = 0; i < size; i++) {
489 INIT_LIST_HEAD(&ls->ls_dirtbl[i].list); 489 INIT_LIST_HEAD(&ls->ls_dirtbl[i].list);
490 rwlock_init(&ls->ls_dirtbl[i].lock); 490 spin_lock_init(&ls->ls_dirtbl[i].lock);
491 } 491 }
492 492
493 INIT_LIST_HEAD(&ls->ls_waiters); 493 INIT_LIST_HEAD(&ls->ls_waiters);
diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index 103a5ebd137..609108a8326 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -2,7 +2,7 @@
2******************************************************************************* 2*******************************************************************************
3** 3**
4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 4** Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
5** Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 5** Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
6** 6**
7** This copyrighted material is made available to anyone wishing to use, 7** This copyrighted material is made available to anyone wishing to use,
8** modify, copy, or redistribute it subject to the terms and conditions 8** modify, copy, or redistribute it subject to the terms and conditions
@@ -21,7 +21,7 @@
21 * 21 *
22 * Cluster nodes are referred to by their nodeids. nodeids are 22 * Cluster nodes are referred to by their nodeids. nodeids are
23 * simply 32 bit numbers to the locking module - if they need to 23 * simply 32 bit numbers to the locking module - if they need to
24 * be expanded for the cluster infrastructure then that is it's 24 * be expanded for the cluster infrastructure then that is its
25 * responsibility. It is this layer's 25 * responsibility. It is this layer's
26 * responsibility to resolve these into IP address or 26 * responsibility to resolve these into IP address or
27 * whatever it needs for inter-node communication. 27 * whatever it needs for inter-node communication.
@@ -36,9 +36,9 @@
36 * of high load. Also, this way, the sending thread can collect together 36 * of high load. Also, this way, the sending thread can collect together
37 * messages bound for one node and send them in one block. 37 * messages bound for one node and send them in one block.
38 * 38 *
39 * lowcomms will choose to use wither TCP or SCTP as its transport layer 39 * lowcomms will choose to use either TCP or SCTP as its transport layer
40 * depending on the configuration variable 'protocol'. This should be set 40 * depending on the configuration variable 'protocol'. This should be set
41 * to 0 (default) for TCP or 1 for SCTP. It shouldbe configured using a 41 * to 0 (default) for TCP or 1 for SCTP. It should be configured using a
42 * cluster-wide mechanism as it must be the same on all nodes of the cluster 42 * cluster-wide mechanism as it must be the same on all nodes of the cluster
43 * for the DLM to function. 43 * for the DLM to function.
44 * 44 *
@@ -48,11 +48,11 @@
48#include <net/sock.h> 48#include <net/sock.h>
49#include <net/tcp.h> 49#include <net/tcp.h>
50#include <linux/pagemap.h> 50#include <linux/pagemap.h>
51#include <linux/idr.h>
52#include <linux/file.h> 51#include <linux/file.h>
53#include <linux/mutex.h> 52#include <linux/mutex.h>
54#include <linux/sctp.h> 53#include <linux/sctp.h>
55#include <net/sctp/user.h> 54#include <net/sctp/user.h>
55#include <net/ipv6.h>
56 56
57#include "dlm_internal.h" 57#include "dlm_internal.h"
58#include "lowcomms.h" 58#include "lowcomms.h"
@@ -60,6 +60,7 @@
60#include "config.h" 60#include "config.h"
61 61
62#define NEEDED_RMEM (4*1024*1024) 62#define NEEDED_RMEM (4*1024*1024)
63#define CONN_HASH_SIZE 32
63 64
64struct cbuf { 65struct cbuf {
65 unsigned int base; 66 unsigned int base;
@@ -114,6 +115,7 @@ struct connection {
114 int retries; 115 int retries;
115#define MAX_CONNECT_RETRIES 3 116#define MAX_CONNECT_RETRIES 3
116 int sctp_assoc; 117 int sctp_assoc;
118 struct hlist_node list;
117 struct connection *othercon; 119 struct connection *othercon;
118 struct work_struct rwork; /* Receive workqueue */ 120 struct work_struct rwork; /* Receive workqueue */
119 struct work_struct swork; /* Send workqueue */ 121 struct work_struct swork; /* Send workqueue */
@@ -138,14 +140,37 @@ static int dlm_local_count;
138static struct workqueue_struct *recv_workqueue; 140static struct workqueue_struct *recv_workqueue;
139static struct workqueue_struct *send_workqueue; 141static struct workqueue_struct *send_workqueue;
140 142
141static DEFINE_IDR(connections_idr); 143static struct hlist_head connection_hash[CONN_HASH_SIZE];
142static DEFINE_MUTEX(connections_lock); 144static DEFINE_MUTEX(connections_lock);
143static int max_nodeid;
144static struct kmem_cache *con_cache; 145static struct kmem_cache *con_cache;
145 146
146static void process_recv_sockets(struct work_struct *work); 147static void process_recv_sockets(struct work_struct *work);
147static void process_send_sockets(struct work_struct *work); 148static void process_send_sockets(struct work_struct *work);
148 149
150
151/* This is deliberately very simple because most clusters have simple
152 sequential nodeids, so we should be able to go straight to a connection
153 struct in the array */
154static inline int nodeid_hash(int nodeid)
155{
156 return nodeid & (CONN_HASH_SIZE-1);
157}
158
159static struct connection *__find_con(int nodeid)
160{
161 int r;
162 struct hlist_node *h;
163 struct connection *con;
164
165 r = nodeid_hash(nodeid);
166
167 hlist_for_each_entry(con, h, &connection_hash[r], list) {
168 if (con->nodeid == nodeid)
169 return con;
170 }
171 return NULL;
172}
173
149/* 174/*
150 * If 'allocation' is zero then we don't attempt to create a new 175 * If 'allocation' is zero then we don't attempt to create a new
151 * connection structure for this node. 176 * connection structure for this node.
@@ -154,31 +179,17 @@ static struct connection *__nodeid2con(int nodeid, gfp_t alloc)
154{ 179{
155 struct connection *con = NULL; 180 struct connection *con = NULL;
156 int r; 181 int r;
157 int n;
158 182
159 con = idr_find(&connections_idr, nodeid); 183 con = __find_con(nodeid);
160 if (con || !alloc) 184 if (con || !alloc)
161 return con; 185 return con;
162 186
163 r = idr_pre_get(&connections_idr, alloc);
164 if (!r)
165 return NULL;
166
167 con = kmem_cache_zalloc(con_cache, alloc); 187 con = kmem_cache_zalloc(con_cache, alloc);
168 if (!con) 188 if (!con)
169 return NULL; 189 return NULL;
170 190
171 r = idr_get_new_above(&connections_idr, con, nodeid, &n); 191 r = nodeid_hash(nodeid);
172 if (r) { 192 hlist_add_head(&con->list, &connection_hash[r]);
173 kmem_cache_free(con_cache, con);
174 return NULL;
175 }
176
177 if (n != nodeid) {
178 idr_remove(&connections_idr, n);
179 kmem_cache_free(con_cache, con);
180 return NULL;
181 }
182 193
183 con->nodeid = nodeid; 194 con->nodeid = nodeid;
184 mutex_init(&con->sock_mutex); 195 mutex_init(&con->sock_mutex);
@@ -189,19 +200,30 @@ static struct connection *__nodeid2con(int nodeid, gfp_t alloc)
189 200
190 /* Setup action pointers for child sockets */ 201 /* Setup action pointers for child sockets */
191 if (con->nodeid) { 202 if (con->nodeid) {
192 struct connection *zerocon = idr_find(&connections_idr, 0); 203 struct connection *zerocon = __find_con(0);
193 204
194 con->connect_action = zerocon->connect_action; 205 con->connect_action = zerocon->connect_action;
195 if (!con->rx_action) 206 if (!con->rx_action)
196 con->rx_action = zerocon->rx_action; 207 con->rx_action = zerocon->rx_action;
197 } 208 }
198 209
199 if (nodeid > max_nodeid)
200 max_nodeid = nodeid;
201
202 return con; 210 return con;
203} 211}
204 212
213/* Loop round all connections */
214static void foreach_conn(void (*conn_func)(struct connection *c))
215{
216 int i;
217 struct hlist_node *h, *n;
218 struct connection *con;
219
220 for (i = 0; i < CONN_HASH_SIZE; i++) {
221 hlist_for_each_entry_safe(con, h, n, &connection_hash[i], list){
222 conn_func(con);
223 }
224 }
225}
226
205static struct connection *nodeid2con(int nodeid, gfp_t allocation) 227static struct connection *nodeid2con(int nodeid, gfp_t allocation)
206{ 228{
207 struct connection *con; 229 struct connection *con;
@@ -217,14 +239,17 @@ static struct connection *nodeid2con(int nodeid, gfp_t allocation)
217static struct connection *assoc2con(int assoc_id) 239static struct connection *assoc2con(int assoc_id)
218{ 240{
219 int i; 241 int i;
242 struct hlist_node *h;
220 struct connection *con; 243 struct connection *con;
221 244
222 mutex_lock(&connections_lock); 245 mutex_lock(&connections_lock);
223 for (i=0; i<=max_nodeid; i++) { 246
224 con = __nodeid2con(i, 0); 247 for (i = 0 ; i < CONN_HASH_SIZE; i++) {
225 if (con && con->sctp_assoc == assoc_id) { 248 hlist_for_each_entry(con, h, &connection_hash[i], list) {
226 mutex_unlock(&connections_lock); 249 if (con && con->sctp_assoc == assoc_id) {
227 return con; 250 mutex_unlock(&connections_lock);
251 return con;
252 }
228 } 253 }
229 } 254 }
230 mutex_unlock(&connections_lock); 255 mutex_unlock(&connections_lock);
@@ -250,8 +275,7 @@ static int nodeid_to_addr(int nodeid, struct sockaddr *retaddr)
250 } else { 275 } else {
251 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &addr; 276 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &addr;
252 struct sockaddr_in6 *ret6 = (struct sockaddr_in6 *) retaddr; 277 struct sockaddr_in6 *ret6 = (struct sockaddr_in6 *) retaddr;
253 memcpy(&ret6->sin6_addr, &in6->sin6_addr, 278 ipv6_addr_copy(&ret6->sin6_addr, &in6->sin6_addr);
254 sizeof(in6->sin6_addr));
255 } 279 }
256 280
257 return 0; 281 return 0;
@@ -376,25 +400,23 @@ static void sctp_send_shutdown(sctp_assoc_t associd)
376 log_print("send EOF to node failed: %d", ret); 400 log_print("send EOF to node failed: %d", ret);
377} 401}
378 402
403static void sctp_init_failed_foreach(struct connection *con)
404{
405 con->sctp_assoc = 0;
406 if (test_and_clear_bit(CF_CONNECT_PENDING, &con->flags)) {
407 if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags))
408 queue_work(send_workqueue, &con->swork);
409 }
410}
411
379/* INIT failed but we don't know which node... 412/* INIT failed but we don't know which node...
380 restart INIT on all pending nodes */ 413 restart INIT on all pending nodes */
381static void sctp_init_failed(void) 414static void sctp_init_failed(void)
382{ 415{
383 int i;
384 struct connection *con;
385
386 mutex_lock(&connections_lock); 416 mutex_lock(&connections_lock);
387 for (i=1; i<=max_nodeid; i++) { 417
388 con = __nodeid2con(i, 0); 418 foreach_conn(sctp_init_failed_foreach);
389 if (!con) 419
390 continue;
391 con->sctp_assoc = 0;
392 if (test_and_clear_bit(CF_CONNECT_PENDING, &con->flags)) {
393 if (!test_and_set_bit(CF_WRITE_PENDING, &con->flags)) {
394 queue_work(send_workqueue, &con->swork);
395 }
396 }
397 }
398 mutex_unlock(&connections_lock); 420 mutex_unlock(&connections_lock);
399} 421}
400 422
@@ -1313,13 +1335,10 @@ out_connect:
1313 1335
1314static void clean_one_writequeue(struct connection *con) 1336static void clean_one_writequeue(struct connection *con)
1315{ 1337{
1316 struct list_head *list; 1338 struct writequeue_entry *e, *safe;
1317 struct list_head *temp;
1318 1339
1319 spin_lock(&con->writequeue_lock); 1340 spin_lock(&con->writequeue_lock);
1320 list_for_each_safe(list, temp, &con->writequeue) { 1341 list_for_each_entry_safe(e, safe, &con->writequeue, list) {
1321 struct writequeue_entry *e =
1322 list_entry(list, struct writequeue_entry, list);
1323 list_del(&e->list); 1342 list_del(&e->list);
1324 free_entry(e); 1343 free_entry(e);
1325 } 1344 }
@@ -1369,14 +1388,7 @@ static void process_send_sockets(struct work_struct *work)
1369/* Discard all entries on the write queues */ 1388/* Discard all entries on the write queues */
1370static void clean_writequeues(void) 1389static void clean_writequeues(void)
1371{ 1390{
1372 int nodeid; 1391 foreach_conn(clean_one_writequeue);
1373
1374 for (nodeid = 1; nodeid <= max_nodeid; nodeid++) {
1375 struct connection *con = __nodeid2con(nodeid, 0);
1376
1377 if (con)
1378 clean_one_writequeue(con);
1379 }
1380} 1392}
1381 1393
1382static void work_stop(void) 1394static void work_stop(void)
@@ -1406,23 +1418,29 @@ static int work_start(void)
1406 return 0; 1418 return 0;
1407} 1419}
1408 1420
1409void dlm_lowcomms_stop(void) 1421static void stop_conn(struct connection *con)
1410{ 1422{
1411 int i; 1423 con->flags |= 0x0F;
1412 struct connection *con; 1424 if (con->sock)
1425 con->sock->sk->sk_user_data = NULL;
1426}
1413 1427
1428static void free_conn(struct connection *con)
1429{
1430 close_connection(con, true);
1431 if (con->othercon)
1432 kmem_cache_free(con_cache, con->othercon);
1433 hlist_del(&con->list);
1434 kmem_cache_free(con_cache, con);
1435}
1436
1437void dlm_lowcomms_stop(void)
1438{
1414 /* Set all the flags to prevent any 1439 /* Set all the flags to prevent any
1415 socket activity. 1440 socket activity.
1416 */ 1441 */
1417 mutex_lock(&connections_lock); 1442 mutex_lock(&connections_lock);
1418 for (i = 0; i <= max_nodeid; i++) { 1443 foreach_conn(stop_conn);
1419 con = __nodeid2con(i, 0);
1420 if (con) {
1421 con->flags |= 0x0F;
1422 if (con->sock)
1423 con->sock->sk->sk_user_data = NULL;
1424 }
1425 }
1426 mutex_unlock(&connections_lock); 1444 mutex_unlock(&connections_lock);
1427 1445
1428 work_stop(); 1446 work_stop();
@@ -1430,25 +1448,20 @@ void dlm_lowcomms_stop(void)
1430 mutex_lock(&connections_lock); 1448 mutex_lock(&connections_lock);
1431 clean_writequeues(); 1449 clean_writequeues();
1432 1450
1433 for (i = 0; i <= max_nodeid; i++) { 1451 foreach_conn(free_conn);
1434 con = __nodeid2con(i, 0); 1452
1435 if (con) {
1436 close_connection(con, true);
1437 if (con->othercon)
1438 kmem_cache_free(con_cache, con->othercon);
1439 kmem_cache_free(con_cache, con);
1440 }
1441 }
1442 max_nodeid = 0;
1443 mutex_unlock(&connections_lock); 1453 mutex_unlock(&connections_lock);
1444 kmem_cache_destroy(con_cache); 1454 kmem_cache_destroy(con_cache);
1445 idr_init(&connections_idr);
1446} 1455}
1447 1456
1448int dlm_lowcomms_start(void) 1457int dlm_lowcomms_start(void)
1449{ 1458{
1450 int error = -EINVAL; 1459 int error = -EINVAL;
1451 struct connection *con; 1460 struct connection *con;
1461 int i;
1462
1463 for (i = 0; i < CONN_HASH_SIZE; i++)
1464 INIT_HLIST_HEAD(&connection_hash[i]);
1452 1465
1453 init_local(); 1466 init_local();
1454 if (!dlm_local_count) { 1467 if (!dlm_local_count) {
diff --git a/fs/dlm/user.c b/fs/dlm/user.c
index 065149e84f4..ebce994ab0b 100644
--- a/fs/dlm/user.c
+++ b/fs/dlm/user.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006-2008 Red Hat, Inc. All rights reserved. 2 * Copyright (C) 2006-2009 Red Hat, Inc. All rights reserved.
3 * 3 *
4 * This copyrighted material is made available to anyone wishing to use, 4 * This copyrighted material is made available to anyone wishing to use,
5 * modify, copy, or redistribute it subject to the terms and conditions 5 * modify, copy, or redistribute it subject to the terms and conditions
@@ -84,7 +84,7 @@ struct dlm_lock_result32 {
84 84
85static void compat_input(struct dlm_write_request *kb, 85static void compat_input(struct dlm_write_request *kb,
86 struct dlm_write_request32 *kb32, 86 struct dlm_write_request32 *kb32,
87 size_t count) 87 int namelen)
88{ 88{
89 kb->version[0] = kb32->version[0]; 89 kb->version[0] = kb32->version[0];
90 kb->version[1] = kb32->version[1]; 90 kb->version[1] = kb32->version[1];
@@ -96,8 +96,7 @@ static void compat_input(struct dlm_write_request *kb,
96 kb->cmd == DLM_USER_REMOVE_LOCKSPACE) { 96 kb->cmd == DLM_USER_REMOVE_LOCKSPACE) {
97 kb->i.lspace.flags = kb32->i.lspace.flags; 97 kb->i.lspace.flags = kb32->i.lspace.flags;
98 kb->i.lspace.minor = kb32->i.lspace.minor; 98 kb->i.lspace.minor = kb32->i.lspace.minor;
99 memcpy(kb->i.lspace.name, kb32->i.lspace.name, count - 99 memcpy(kb->i.lspace.name, kb32->i.lspace.name, namelen);
100 offsetof(struct dlm_write_request32, i.lspace.name));
101 } else if (kb->cmd == DLM_USER_PURGE) { 100 } else if (kb->cmd == DLM_USER_PURGE) {
102 kb->i.purge.nodeid = kb32->i.purge.nodeid; 101 kb->i.purge.nodeid = kb32->i.purge.nodeid;
103 kb->i.purge.pid = kb32->i.purge.pid; 102 kb->i.purge.pid = kb32->i.purge.pid;
@@ -115,8 +114,7 @@ static void compat_input(struct dlm_write_request *kb,
115 kb->i.lock.bastaddr = (void *)(long)kb32->i.lock.bastaddr; 114 kb->i.lock.bastaddr = (void *)(long)kb32->i.lock.bastaddr;
116 kb->i.lock.lksb = (void *)(long)kb32->i.lock.lksb; 115 kb->i.lock.lksb = (void *)(long)kb32->i.lock.lksb;
117 memcpy(kb->i.lock.lvb, kb32->i.lock.lvb, DLM_USER_LVB_LEN); 116 memcpy(kb->i.lock.lvb, kb32->i.lock.lvb, DLM_USER_LVB_LEN);
118 memcpy(kb->i.lock.name, kb32->i.lock.name, count - 117 memcpy(kb->i.lock.name, kb32->i.lock.name, namelen);
119 offsetof(struct dlm_write_request32, i.lock.name));
120 } 118 }
121} 119}
122 120
@@ -539,9 +537,16 @@ static ssize_t device_write(struct file *file, const char __user *buf,
539#ifdef CONFIG_COMPAT 537#ifdef CONFIG_COMPAT
540 if (!kbuf->is64bit) { 538 if (!kbuf->is64bit) {
541 struct dlm_write_request32 *k32buf; 539 struct dlm_write_request32 *k32buf;
540 int namelen = 0;
541
542 if (count > sizeof(struct dlm_write_request32))
543 namelen = count - sizeof(struct dlm_write_request32);
544
542 k32buf = (struct dlm_write_request32 *)kbuf; 545 k32buf = (struct dlm_write_request32 *)kbuf;
543 kbuf = kmalloc(count + 1 + (sizeof(struct dlm_write_request) - 546
544 sizeof(struct dlm_write_request32)), GFP_KERNEL); 547 /* add 1 after namelen so that the name string is terminated */
548 kbuf = kzalloc(sizeof(struct dlm_write_request) + namelen + 1,
549 GFP_KERNEL);
545 if (!kbuf) { 550 if (!kbuf) {
546 kfree(k32buf); 551 kfree(k32buf);
547 return -ENOMEM; 552 return -ENOMEM;
@@ -549,7 +554,8 @@ static ssize_t device_write(struct file *file, const char __user *buf,
549 554
550 if (proc) 555 if (proc)
551 set_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags); 556 set_bit(DLM_PROC_FLAGS_COMPAT, &proc->flags);
552 compat_input(kbuf, k32buf, count + 1); 557
558 compat_input(kbuf, k32buf, namelen);
553 kfree(k32buf); 559 kfree(k32buf);
554 } 560 }
555#endif 561#endif
diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index 3e5637fc377..44d725f612c 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -18,7 +18,7 @@ static void drop_pagecache_sb(struct super_block *sb)
18 18
19 spin_lock(&inode_lock); 19 spin_lock(&inode_lock);
20 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { 20 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
21 if (inode->i_state & (I_FREEING|I_WILL_FREE)) 21 if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW))
22 continue; 22 continue;
23 if (inode->i_mapping->nrpages == 0) 23 if (inode->i_mapping->nrpages == 0)
24 continue; 24 continue;
diff --git a/fs/ecryptfs/dentry.c b/fs/ecryptfs/dentry.c
index 5e596583946..2dda5ade75b 100644
--- a/fs/ecryptfs/dentry.c
+++ b/fs/ecryptfs/dentry.c
@@ -89,7 +89,7 @@ static void ecryptfs_d_release(struct dentry *dentry)
89 return; 89 return;
90} 90}
91 91
92struct dentry_operations ecryptfs_dops = { 92const struct dentry_operations ecryptfs_dops = {
93 .d_revalidate = ecryptfs_d_revalidate, 93 .d_revalidate = ecryptfs_d_revalidate,
94 .d_release = ecryptfs_d_release, 94 .d_release = ecryptfs_d_release,
95}; 95};
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index ac749d4d644..064c5820e4e 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -580,7 +580,7 @@ extern const struct inode_operations ecryptfs_main_iops;
580extern const struct inode_operations ecryptfs_dir_iops; 580extern const struct inode_operations ecryptfs_dir_iops;
581extern const struct inode_operations ecryptfs_symlink_iops; 581extern const struct inode_operations ecryptfs_symlink_iops;
582extern const struct super_operations ecryptfs_sops; 582extern const struct super_operations ecryptfs_sops;
583extern struct dentry_operations ecryptfs_dops; 583extern const struct dentry_operations ecryptfs_dops;
584extern struct address_space_operations ecryptfs_aops; 584extern struct address_space_operations ecryptfs_aops;
585extern int ecryptfs_verbosity; 585extern int ecryptfs_verbosity;
586extern unsigned int ecryptfs_message_buf_len; 586extern unsigned int ecryptfs_message_buf_len;
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 011b9b8c90c..c5c424f23fd 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -417,10 +417,10 @@ static int ep_remove(struct eventpoll *ep, struct epitem *epi)
417 ep_unregister_pollwait(ep, epi); 417 ep_unregister_pollwait(ep, epi);
418 418
419 /* Remove the current item from the list of epoll hooks */ 419 /* Remove the current item from the list of epoll hooks */
420 spin_lock(&file->f_ep_lock); 420 spin_lock(&file->f_lock);
421 if (ep_is_linked(&epi->fllink)) 421 if (ep_is_linked(&epi->fllink))
422 list_del_init(&epi->fllink); 422 list_del_init(&epi->fllink);
423 spin_unlock(&file->f_ep_lock); 423 spin_unlock(&file->f_lock);
424 424
425 rb_erase(&epi->rbn, &ep->rbr); 425 rb_erase(&epi->rbn, &ep->rbr);
426 426
@@ -538,7 +538,7 @@ void eventpoll_release_file(struct file *file)
538 struct epitem *epi; 538 struct epitem *epi;
539 539
540 /* 540 /*
541 * We don't want to get "file->f_ep_lock" because it is not 541 * We don't want to get "file->f_lock" because it is not
542 * necessary. It is not necessary because we're in the "struct file" 542 * necessary. It is not necessary because we're in the "struct file"
543 * cleanup path, and this means that noone is using this file anymore. 543 * cleanup path, and this means that noone is using this file anymore.
544 * So, for example, epoll_ctl() cannot hit here sicne if we reach this 544 * So, for example, epoll_ctl() cannot hit here sicne if we reach this
@@ -547,6 +547,8 @@ void eventpoll_release_file(struct file *file)
547 * will correctly serialize the operation. We do need to acquire 547 * will correctly serialize the operation. We do need to acquire
548 * "ep->mtx" after "epmutex" because ep_remove() requires it when called 548 * "ep->mtx" after "epmutex" because ep_remove() requires it when called
549 * from anywhere but ep_free(). 549 * from anywhere but ep_free().
550 *
551 * Besides, ep_remove() acquires the lock, so we can't hold it here.
550 */ 552 */
551 mutex_lock(&epmutex); 553 mutex_lock(&epmutex);
552 554
@@ -785,9 +787,9 @@ static int ep_insert(struct eventpoll *ep, struct epoll_event *event,
785 goto error_unregister; 787 goto error_unregister;
786 788
787 /* Add the current item to the list of active epoll hook for this file */ 789 /* Add the current item to the list of active epoll hook for this file */
788 spin_lock(&tfile->f_ep_lock); 790 spin_lock(&tfile->f_lock);
789 list_add_tail(&epi->fllink, &tfile->f_ep_links); 791 list_add_tail(&epi->fllink, &tfile->f_ep_links);
790 spin_unlock(&tfile->f_ep_lock); 792 spin_unlock(&tfile->f_lock);
791 793
792 /* 794 /*
793 * Add the current item to the RB tree. All RB tree operations are 795 * Add the current item to the RB tree. All RB tree operations are
diff --git a/fs/exec.c b/fs/exec.c
index 929b58004b7..c5128fbc916 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -45,6 +45,7 @@
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/mount.h> 46#include <linux/mount.h>
47#include <linux/security.h> 47#include <linux/security.h>
48#include <linux/ima.h>
48#include <linux/syscalls.h> 49#include <linux/syscalls.h>
49#include <linux/tsacct_kern.h> 50#include <linux/tsacct_kern.h>
50#include <linux/cn_proc.h> 51#include <linux/cn_proc.h>
@@ -127,6 +128,9 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
127 MAY_READ | MAY_EXEC | MAY_OPEN); 128 MAY_READ | MAY_EXEC | MAY_OPEN);
128 if (error) 129 if (error)
129 goto exit; 130 goto exit;
131 error = ima_path_check(&nd.path, MAY_READ | MAY_EXEC | MAY_OPEN);
132 if (error)
133 goto exit;
130 134
131 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); 135 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
132 error = PTR_ERR(file); 136 error = PTR_ERR(file);
@@ -674,6 +678,9 @@ struct file *open_exec(const char *name)
674 err = inode_permission(nd.path.dentry->d_inode, MAY_EXEC | MAY_OPEN); 678 err = inode_permission(nd.path.dentry->d_inode, MAY_EXEC | MAY_OPEN);
675 if (err) 679 if (err)
676 goto out_path_put; 680 goto out_path_put;
681 err = ima_path_check(&nd.path, MAY_EXEC | MAY_OPEN);
682 if (err)
683 goto out_path_put;
677 684
678 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); 685 file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
679 if (IS_ERR(file)) 686 if (IS_ERR(file))
@@ -1049,28 +1056,24 @@ EXPORT_SYMBOL(install_exec_creds);
1049 * - the caller must hold current->cred_exec_mutex to protect against 1056 * - the caller must hold current->cred_exec_mutex to protect against
1050 * PTRACE_ATTACH 1057 * PTRACE_ATTACH
1051 */ 1058 */
1052void check_unsafe_exec(struct linux_binprm *bprm, struct files_struct *files) 1059void check_unsafe_exec(struct linux_binprm *bprm)
1053{ 1060{
1054 struct task_struct *p = current, *t; 1061 struct task_struct *p = current, *t;
1055 unsigned long flags; 1062 unsigned long flags;
1056 unsigned n_fs, n_files, n_sighand; 1063 unsigned n_fs, n_sighand;
1057 1064
1058 bprm->unsafe = tracehook_unsafe_exec(p); 1065 bprm->unsafe = tracehook_unsafe_exec(p);
1059 1066
1060 n_fs = 1; 1067 n_fs = 1;
1061 n_files = 1;
1062 n_sighand = 1; 1068 n_sighand = 1;
1063 lock_task_sighand(p, &flags); 1069 lock_task_sighand(p, &flags);
1064 for (t = next_thread(p); t != p; t = next_thread(t)) { 1070 for (t = next_thread(p); t != p; t = next_thread(t)) {
1065 if (t->fs == p->fs) 1071 if (t->fs == p->fs)
1066 n_fs++; 1072 n_fs++;
1067 if (t->files == files)
1068 n_files++;
1069 n_sighand++; 1073 n_sighand++;
1070 } 1074 }
1071 1075
1072 if (atomic_read(&p->fs->count) > n_fs || 1076 if (atomic_read(&p->fs->count) > n_fs ||
1073 atomic_read(&p->files->count) > n_files ||
1074 atomic_read(&p->sighand->count) > n_sighand) 1077 atomic_read(&p->sighand->count) > n_sighand)
1075 bprm->unsafe |= LSM_UNSAFE_SHARE; 1078 bprm->unsafe |= LSM_UNSAFE_SHARE;
1076 1079
@@ -1184,6 +1187,9 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
1184 retval = security_bprm_check(bprm); 1187 retval = security_bprm_check(bprm);
1185 if (retval) 1188 if (retval)
1186 return retval; 1189 return retval;
1190 retval = ima_bprm_check(bprm);
1191 if (retval)
1192 return retval;
1187 1193
1188 /* kernel module loader fixup */ 1194 /* kernel module loader fixup */
1189 /* so we don't try to load run modprobe in kernel space. */ 1195 /* so we don't try to load run modprobe in kernel space. */
@@ -1284,12 +1290,13 @@ int do_execve(char * filename,
1284 retval = mutex_lock_interruptible(&current->cred_exec_mutex); 1290 retval = mutex_lock_interruptible(&current->cred_exec_mutex);
1285 if (retval < 0) 1291 if (retval < 0)
1286 goto out_free; 1292 goto out_free;
1293 current->in_execve = 1;
1287 1294
1288 retval = -ENOMEM; 1295 retval = -ENOMEM;
1289 bprm->cred = prepare_exec_creds(); 1296 bprm->cred = prepare_exec_creds();
1290 if (!bprm->cred) 1297 if (!bprm->cred)
1291 goto out_unlock; 1298 goto out_unlock;
1292 check_unsafe_exec(bprm, displaced); 1299 check_unsafe_exec(bprm);
1293 1300
1294 file = open_exec(filename); 1301 file = open_exec(filename);
1295 retval = PTR_ERR(file); 1302 retval = PTR_ERR(file);
@@ -1337,6 +1344,7 @@ int do_execve(char * filename,
1337 goto out; 1344 goto out;
1338 1345
1339 /* execve succeeded */ 1346 /* execve succeeded */
1347 current->in_execve = 0;
1340 mutex_unlock(&current->cred_exec_mutex); 1348 mutex_unlock(&current->cred_exec_mutex);
1341 acct_update_integrals(current); 1349 acct_update_integrals(current);
1342 free_bprm(bprm); 1350 free_bprm(bprm);
@@ -1355,6 +1363,7 @@ out_file:
1355 } 1363 }
1356 1364
1357out_unlock: 1365out_unlock:
1366 current->in_execve = 0;
1358 mutex_unlock(&current->cred_exec_mutex); 1367 mutex_unlock(&current->cred_exec_mutex);
1359 1368
1360out_free: 1369out_free:
diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index 4a29d637608..7f8d2e5a7ea 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -570,7 +570,7 @@ do_more:
570error_return: 570error_return:
571 brelse(bitmap_bh); 571 brelse(bitmap_bh);
572 release_blocks(sb, freed); 572 release_blocks(sb, freed);
573 DQUOT_FREE_BLOCK(inode, freed); 573 vfs_dq_free_block(inode, freed);
574} 574}
575 575
576/** 576/**
@@ -1247,7 +1247,7 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
1247 /* 1247 /*
1248 * Check quota for allocation of this block. 1248 * Check quota for allocation of this block.
1249 */ 1249 */
1250 if (DQUOT_ALLOC_BLOCK(inode, num)) { 1250 if (vfs_dq_alloc_block(inode, num)) {
1251 *errp = -EDQUOT; 1251 *errp = -EDQUOT;
1252 return 0; 1252 return 0;
1253 } 1253 }
@@ -1409,7 +1409,7 @@ allocated:
1409 1409
1410 *errp = 0; 1410 *errp = 0;
1411 brelse(bitmap_bh); 1411 brelse(bitmap_bh);
1412 DQUOT_FREE_BLOCK(inode, *count-num); 1412 vfs_dq_free_block(inode, *count-num);
1413 *count = num; 1413 *count = num;
1414 return ret_block; 1414 return ret_block;
1415 1415
@@ -1420,7 +1420,7 @@ out:
1420 * Undo the block allocation 1420 * Undo the block allocation
1421 */ 1421 */
1422 if (!performed_allocation) 1422 if (!performed_allocation)
1423 DQUOT_FREE_BLOCK(inode, *count); 1423 vfs_dq_free_block(inode, *count);
1424 brelse(bitmap_bh); 1424 brelse(bitmap_bh);
1425 return 0; 1425 return 0;
1426} 1426}
diff --git a/fs/ext2/ialloc.c b/fs/ext2/ialloc.c
index 66321a877e7..15387c9c17d 100644
--- a/fs/ext2/ialloc.c
+++ b/fs/ext2/ialloc.c
@@ -121,8 +121,8 @@ void ext2_free_inode (struct inode * inode)
121 if (!is_bad_inode(inode)) { 121 if (!is_bad_inode(inode)) {
122 /* Quota is already initialized in iput() */ 122 /* Quota is already initialized in iput() */
123 ext2_xattr_delete_inode(inode); 123 ext2_xattr_delete_inode(inode);
124 DQUOT_FREE_INODE(inode); 124 vfs_dq_free_inode(inode);
125 DQUOT_DROP(inode); 125 vfs_dq_drop(inode);
126 } 126 }
127 127
128 es = EXT2_SB(sb)->s_es; 128 es = EXT2_SB(sb)->s_es;
@@ -586,7 +586,7 @@ got:
586 goto fail_drop; 586 goto fail_drop;
587 } 587 }
588 588
589 if (DQUOT_ALLOC_INODE(inode)) { 589 if (vfs_dq_alloc_inode(inode)) {
590 err = -EDQUOT; 590 err = -EDQUOT;
591 goto fail_drop; 591 goto fail_drop;
592 } 592 }
@@ -605,10 +605,10 @@ got:
605 return inode; 605 return inode;
606 606
607fail_free_drop: 607fail_free_drop:
608 DQUOT_FREE_INODE(inode); 608 vfs_dq_free_inode(inode);
609 609
610fail_drop: 610fail_drop:
611 DQUOT_DROP(inode); 611 vfs_dq_drop(inode);
612 inode->i_flags |= S_NOQUOTA; 612 inode->i_flags |= S_NOQUOTA;
613 inode->i_nlink = 0; 613 inode->i_nlink = 0;
614 unlock_new_inode(inode); 614 unlock_new_inode(inode);
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 23fff2f8778..b43b9556366 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -1444,7 +1444,7 @@ int ext2_setattr(struct dentry *dentry, struct iattr *iattr)
1444 return error; 1444 return error;
1445 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) || 1445 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
1446 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) { 1446 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
1447 error = DQUOT_TRANSFER(inode, iattr) ? -EDQUOT : 0; 1447 error = vfs_dq_transfer(inode, iattr) ? -EDQUOT : 0;
1448 if (error) 1448 if (error)
1449 return error; 1449 return error;
1450 } 1450 }
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 7c6e3606f0e..f983225266d 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -1331,6 +1331,7 @@ static ssize_t ext2_quota_read(struct super_block *sb, int type, char *data,
1331 sb->s_blocksize - offset : toread; 1331 sb->s_blocksize - offset : toread;
1332 1332
1333 tmp_bh.b_state = 0; 1333 tmp_bh.b_state = 0;
1334 tmp_bh.b_size = sb->s_blocksize;
1334 err = ext2_get_block(inode, blk, &tmp_bh, 0); 1335 err = ext2_get_block(inode, blk, &tmp_bh, 0);
1335 if (err < 0) 1336 if (err < 0)
1336 return err; 1337 return err;
diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 987a5261cc2..7913531ec6d 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -642,7 +642,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
642 ea_bdebug(new_bh, "reusing block"); 642 ea_bdebug(new_bh, "reusing block");
643 643
644 error = -EDQUOT; 644 error = -EDQUOT;
645 if (DQUOT_ALLOC_BLOCK(inode, 1)) { 645 if (vfs_dq_alloc_block(inode, 1)) {
646 unlock_buffer(new_bh); 646 unlock_buffer(new_bh);
647 goto cleanup; 647 goto cleanup;
648 } 648 }
@@ -699,7 +699,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
699 * as if nothing happened and cleanup the unused block */ 699 * as if nothing happened and cleanup the unused block */
700 if (error && error != -ENOSPC) { 700 if (error && error != -ENOSPC) {
701 if (new_bh && new_bh != old_bh) 701 if (new_bh && new_bh != old_bh)
702 DQUOT_FREE_BLOCK(inode, 1); 702 vfs_dq_free_block(inode, 1);
703 goto cleanup; 703 goto cleanup;
704 } 704 }
705 } else 705 } else
@@ -731,7 +731,7 @@ ext2_xattr_set2(struct inode *inode, struct buffer_head *old_bh,
731 le32_add_cpu(&HDR(old_bh)->h_refcount, -1); 731 le32_add_cpu(&HDR(old_bh)->h_refcount, -1);
732 if (ce) 732 if (ce)
733 mb_cache_entry_release(ce); 733 mb_cache_entry_release(ce);
734 DQUOT_FREE_BLOCK(inode, 1); 734 vfs_dq_free_block(inode, 1);
735 mark_buffer_dirty(old_bh); 735 mark_buffer_dirty(old_bh);
736 ea_bdebug(old_bh, "refcount now=%d", 736 ea_bdebug(old_bh, "refcount now=%d",
737 le32_to_cpu(HDR(old_bh)->h_refcount)); 737 le32_to_cpu(HDR(old_bh)->h_refcount));
@@ -794,7 +794,7 @@ ext2_xattr_delete_inode(struct inode *inode)
794 mark_buffer_dirty(bh); 794 mark_buffer_dirty(bh);
795 if (IS_SYNC(inode)) 795 if (IS_SYNC(inode))
796 sync_dirty_buffer(bh); 796 sync_dirty_buffer(bh);
797 DQUOT_FREE_BLOCK(inode, 1); 797 vfs_dq_free_block(inode, 1);
798 } 798 }
799 EXT2_I(inode)->i_file_acl = 0; 799 EXT2_I(inode)->i_file_acl = 0;
800 800
diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
index 0dbf1c04847..225202db897 100644
--- a/fs/ext3/balloc.c
+++ b/fs/ext3/balloc.c
@@ -676,7 +676,7 @@ void ext3_free_blocks(handle_t *handle, struct inode *inode,
676 } 676 }
677 ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks); 677 ext3_free_blocks_sb(handle, sb, block, count, &dquot_freed_blocks);
678 if (dquot_freed_blocks) 678 if (dquot_freed_blocks)
679 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks); 679 vfs_dq_free_block(inode, dquot_freed_blocks);
680 return; 680 return;
681} 681}
682 682
@@ -1502,7 +1502,7 @@ ext3_fsblk_t ext3_new_blocks(handle_t *handle, struct inode *inode,
1502 /* 1502 /*
1503 * Check quota for allocation of this block. 1503 * Check quota for allocation of this block.
1504 */ 1504 */
1505 if (DQUOT_ALLOC_BLOCK(inode, num)) { 1505 if (vfs_dq_alloc_block(inode, num)) {
1506 *errp = -EDQUOT; 1506 *errp = -EDQUOT;
1507 return 0; 1507 return 0;
1508 } 1508 }
@@ -1714,7 +1714,7 @@ allocated:
1714 1714
1715 *errp = 0; 1715 *errp = 0;
1716 brelse(bitmap_bh); 1716 brelse(bitmap_bh);
1717 DQUOT_FREE_BLOCK(inode, *count-num); 1717 vfs_dq_free_block(inode, *count-num);
1718 *count = num; 1718 *count = num;
1719 return ret_block; 1719 return ret_block;
1720 1720
@@ -1729,7 +1729,7 @@ out:
1729 * Undo the block allocation 1729 * Undo the block allocation
1730 */ 1730 */
1731 if (!performed_allocation) 1731 if (!performed_allocation)
1732 DQUOT_FREE_BLOCK(inode, *count); 1732 vfs_dq_free_block(inode, *count);
1733 brelse(bitmap_bh); 1733 brelse(bitmap_bh);
1734 return 0; 1734 return 0;
1735} 1735}
diff --git a/fs/ext3/ialloc.c b/fs/ext3/ialloc.c
index 8de6c720e51..dd13d60d524 100644
--- a/fs/ext3/ialloc.c
+++ b/fs/ext3/ialloc.c
@@ -123,10 +123,10 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
123 * Note: we must free any quota before locking the superblock, 123 * Note: we must free any quota before locking the superblock,
124 * as writing the quota to disk may need the lock as well. 124 * as writing the quota to disk may need the lock as well.
125 */ 125 */
126 DQUOT_INIT(inode); 126 vfs_dq_init(inode);
127 ext3_xattr_delete_inode(handle, inode); 127 ext3_xattr_delete_inode(handle, inode);
128 DQUOT_FREE_INODE(inode); 128 vfs_dq_free_inode(inode);
129 DQUOT_DROP(inode); 129 vfs_dq_drop(inode);
130 130
131 is_directory = S_ISDIR(inode->i_mode); 131 is_directory = S_ISDIR(inode->i_mode);
132 132
@@ -589,7 +589,7 @@ got:
589 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0; 589 sizeof(struct ext3_inode) - EXT3_GOOD_OLD_INODE_SIZE : 0;
590 590
591 ret = inode; 591 ret = inode;
592 if(DQUOT_ALLOC_INODE(inode)) { 592 if (vfs_dq_alloc_inode(inode)) {
593 err = -EDQUOT; 593 err = -EDQUOT;
594 goto fail_drop; 594 goto fail_drop;
595 } 595 }
@@ -620,10 +620,10 @@ really_out:
620 return ret; 620 return ret;
621 621
622fail_free_drop: 622fail_free_drop:
623 DQUOT_FREE_INODE(inode); 623 vfs_dq_free_inode(inode);
624 624
625fail_drop: 625fail_drop:
626 DQUOT_DROP(inode); 626 vfs_dq_drop(inode);
627 inode->i_flags |= S_NOQUOTA; 627 inode->i_flags |= S_NOQUOTA;
628 inode->i_nlink = 0; 628 inode->i_nlink = 0;
629 unlock_new_inode(inode); 629 unlock_new_inode(inode);
diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c
index 5fa453b49a6..4a09ff16987 100644
--- a/fs/ext3/inode.c
+++ b/fs/ext3/inode.c
@@ -1435,6 +1435,10 @@ static int journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)
1435 return 0; 1435 return 0;
1436} 1436}
1437 1437
1438static int buffer_unmapped(handle_t *handle, struct buffer_head *bh)
1439{
1440 return !buffer_mapped(bh);
1441}
1438/* 1442/*
1439 * Note that we always start a transaction even if we're not journalling 1443 * Note that we always start a transaction even if we're not journalling
1440 * data. This is to preserve ordering: any hole instantiation within 1444 * data. This is to preserve ordering: any hole instantiation within
@@ -1505,6 +1509,15 @@ static int ext3_ordered_writepage(struct page *page,
1505 if (ext3_journal_current_handle()) 1509 if (ext3_journal_current_handle())
1506 goto out_fail; 1510 goto out_fail;
1507 1511
1512 if (!page_has_buffers(page)) {
1513 create_empty_buffers(page, inode->i_sb->s_blocksize,
1514 (1 << BH_Dirty)|(1 << BH_Uptodate));
1515 } else if (!walk_page_buffers(NULL, page_buffers(page), 0, PAGE_CACHE_SIZE, NULL, buffer_unmapped)) {
1516 /* Provide NULL instead of get_block so that we catch bugs if buffers weren't really mapped */
1517 return block_write_full_page(page, NULL, wbc);
1518 }
1519 page_bufs = page_buffers(page);
1520
1508 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode)); 1521 handle = ext3_journal_start(inode, ext3_writepage_trans_blocks(inode));
1509 1522
1510 if (IS_ERR(handle)) { 1523 if (IS_ERR(handle)) {
@@ -1512,11 +1525,6 @@ static int ext3_ordered_writepage(struct page *page,
1512 goto out_fail; 1525 goto out_fail;
1513 } 1526 }
1514 1527
1515 if (!page_has_buffers(page)) {
1516 create_empty_buffers(page, inode->i_sb->s_blocksize,
1517 (1 << BH_Dirty)|(1 << BH_Uptodate));
1518 }
1519 page_bufs = page_buffers(page);
1520 walk_page_buffers(handle, page_bufs, 0, 1528 walk_page_buffers(handle, page_bufs, 0,
1521 PAGE_CACHE_SIZE, NULL, bget_one); 1529 PAGE_CACHE_SIZE, NULL, bget_one);
1522 1530
@@ -3055,7 +3063,7 @@ int ext3_setattr(struct dentry *dentry, struct iattr *attr)
3055 error = PTR_ERR(handle); 3063 error = PTR_ERR(handle);
3056 goto err_out; 3064 goto err_out;
3057 } 3065 }
3058 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0; 3066 error = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0;
3059 if (error) { 3067 if (error) {
3060 ext3_journal_stop(handle); 3068 ext3_journal_stop(handle);
3061 return error; 3069 return error;
@@ -3146,7 +3154,7 @@ static int ext3_writepage_trans_blocks(struct inode *inode)
3146 ret = 2 * (bpp + indirects) + 2; 3154 ret = 2 * (bpp + indirects) + 2;
3147 3155
3148#ifdef CONFIG_QUOTA 3156#ifdef CONFIG_QUOTA
3149 /* We know that structure was already allocated during DQUOT_INIT so 3157 /* We know that structure was already allocated during vfs_dq_init so
3150 * we will be updating only the data blocks + inodes */ 3158 * we will be updating only the data blocks + inodes */
3151 ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb); 3159 ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb);
3152#endif 3160#endif
@@ -3237,7 +3245,7 @@ int ext3_mark_inode_dirty(handle_t *handle, struct inode *inode)
3237 * i_size has been changed by generic_commit_write() and we thus need 3245 * i_size has been changed by generic_commit_write() and we thus need
3238 * to include the updated inode in the current transaction. 3246 * to include the updated inode in the current transaction.
3239 * 3247 *
3240 * Also, DQUOT_ALLOC_SPACE() will always dirty the inode when blocks 3248 * Also, vfs_dq_alloc_space() will always dirty the inode when blocks
3241 * are allocated to the file. 3249 * are allocated to the file.
3242 * 3250 *
3243 * If the inode is marked synchronous, we don't honour that here - doing 3251 * If the inode is marked synchronous, we don't honour that here - doing
diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c
index 4db4ffa1eda..e2fc63cbba8 100644
--- a/fs/ext3/namei.c
+++ b/fs/ext3/namei.c
@@ -2049,7 +2049,7 @@ static int ext3_rmdir (struct inode * dir, struct dentry *dentry)
2049 2049
2050 /* Initialize quotas before so that eventual writes go in 2050 /* Initialize quotas before so that eventual writes go in
2051 * separate transaction */ 2051 * separate transaction */
2052 DQUOT_INIT(dentry->d_inode); 2052 vfs_dq_init(dentry->d_inode);
2053 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2053 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb));
2054 if (IS_ERR(handle)) 2054 if (IS_ERR(handle))
2055 return PTR_ERR(handle); 2055 return PTR_ERR(handle);
@@ -2108,7 +2108,7 @@ static int ext3_unlink(struct inode * dir, struct dentry *dentry)
2108 2108
2109 /* Initialize quotas before so that eventual writes go 2109 /* Initialize quotas before so that eventual writes go
2110 * in separate transaction */ 2110 * in separate transaction */
2111 DQUOT_INIT(dentry->d_inode); 2111 vfs_dq_init(dentry->d_inode);
2112 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb)); 2112 handle = ext3_journal_start(dir, EXT3_DELETE_TRANS_BLOCKS(dir->i_sb));
2113 if (IS_ERR(handle)) 2113 if (IS_ERR(handle))
2114 return PTR_ERR(handle); 2114 return PTR_ERR(handle);
@@ -2272,7 +2272,7 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry,
2272 /* Initialize quotas before so that eventual writes go 2272 /* Initialize quotas before so that eventual writes go
2273 * in separate transaction */ 2273 * in separate transaction */
2274 if (new_dentry->d_inode) 2274 if (new_dentry->d_inode)
2275 DQUOT_INIT(new_dentry->d_inode); 2275 vfs_dq_init(new_dentry->d_inode);
2276 handle = ext3_journal_start(old_dir, 2 * 2276 handle = ext3_journal_start(old_dir, 2 *
2277 EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) + 2277 EXT3_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2278 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2); 2278 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 2);
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 4a970411a45..9e5b8e387e1 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -707,8 +707,6 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
707#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group") 707#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
708#define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) 708#define QTYPE2MOPT(on, t) ((t)==USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
709 709
710static int ext3_dquot_initialize(struct inode *inode, int type);
711static int ext3_dquot_drop(struct inode *inode);
712static int ext3_write_dquot(struct dquot *dquot); 710static int ext3_write_dquot(struct dquot *dquot);
713static int ext3_acquire_dquot(struct dquot *dquot); 711static int ext3_acquire_dquot(struct dquot *dquot);
714static int ext3_release_dquot(struct dquot *dquot); 712static int ext3_release_dquot(struct dquot *dquot);
@@ -723,8 +721,8 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
723 const char *data, size_t len, loff_t off); 721 const char *data, size_t len, loff_t off);
724 722
725static struct dquot_operations ext3_quota_operations = { 723static struct dquot_operations ext3_quota_operations = {
726 .initialize = ext3_dquot_initialize, 724 .initialize = dquot_initialize,
727 .drop = ext3_dquot_drop, 725 .drop = dquot_drop,
728 .alloc_space = dquot_alloc_space, 726 .alloc_space = dquot_alloc_space,
729 .alloc_inode = dquot_alloc_inode, 727 .alloc_inode = dquot_alloc_inode,
730 .free_space = dquot_free_space, 728 .free_space = dquot_free_space,
@@ -1438,7 +1436,7 @@ static void ext3_orphan_cleanup (struct super_block * sb,
1438 } 1436 }
1439 1437
1440 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan); 1438 list_add(&EXT3_I(inode)->i_orphan, &EXT3_SB(sb)->s_orphan);
1441 DQUOT_INIT(inode); 1439 vfs_dq_init(inode);
1442 if (inode->i_nlink) { 1440 if (inode->i_nlink) {
1443 printk(KERN_DEBUG 1441 printk(KERN_DEBUG
1444 "%s: truncating inode %lu to %Ld bytes\n", 1442 "%s: truncating inode %lu to %Ld bytes\n",
@@ -2702,7 +2700,7 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
2702 * Process 1 Process 2 2700 * Process 1 Process 2
2703 * ext3_create() quota_sync() 2701 * ext3_create() quota_sync()
2704 * journal_start() write_dquot() 2702 * journal_start() write_dquot()
2705 * DQUOT_INIT() down(dqio_mutex) 2703 * vfs_dq_init() down(dqio_mutex)
2706 * down(dqio_mutex) journal_start() 2704 * down(dqio_mutex) journal_start()
2707 * 2705 *
2708 */ 2706 */
@@ -2714,44 +2712,6 @@ static inline struct inode *dquot_to_inode(struct dquot *dquot)
2714 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; 2712 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
2715} 2713}
2716 2714
2717static int ext3_dquot_initialize(struct inode *inode, int type)
2718{
2719 handle_t *handle;
2720 int ret, err;
2721
2722 /* We may create quota structure so we need to reserve enough blocks */
2723 handle = ext3_journal_start(inode, 2*EXT3_QUOTA_INIT_BLOCKS(inode->i_sb));
2724 if (IS_ERR(handle))
2725 return PTR_ERR(handle);
2726 ret = dquot_initialize(inode, type);
2727 err = ext3_journal_stop(handle);
2728 if (!ret)
2729 ret = err;
2730 return ret;
2731}
2732
2733static int ext3_dquot_drop(struct inode *inode)
2734{
2735 handle_t *handle;
2736 int ret, err;
2737
2738 /* We may delete quota structure so we need to reserve enough blocks */
2739 handle = ext3_journal_start(inode, 2*EXT3_QUOTA_DEL_BLOCKS(inode->i_sb));
2740 if (IS_ERR(handle)) {
2741 /*
2742 * We call dquot_drop() anyway to at least release references
2743 * to quota structures so that umount does not hang.
2744 */
2745 dquot_drop(inode);
2746 return PTR_ERR(handle);
2747 }
2748 ret = dquot_drop(inode);
2749 err = ext3_journal_stop(handle);
2750 if (!ret)
2751 ret = err;
2752 return ret;
2753}
2754
2755static int ext3_write_dquot(struct dquot *dquot) 2715static int ext3_write_dquot(struct dquot *dquot)
2756{ 2716{
2757 int ret, err; 2717 int ret, err;
diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
index 175414ac221..83b7be849bd 100644
--- a/fs/ext3/xattr.c
+++ b/fs/ext3/xattr.c
@@ -498,7 +498,7 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode,
498 error = ext3_journal_dirty_metadata(handle, bh); 498 error = ext3_journal_dirty_metadata(handle, bh);
499 if (IS_SYNC(inode)) 499 if (IS_SYNC(inode))
500 handle->h_sync = 1; 500 handle->h_sync = 1;
501 DQUOT_FREE_BLOCK(inode, 1); 501 vfs_dq_free_block(inode, 1);
502 ea_bdebug(bh, "refcount now=%d; releasing", 502 ea_bdebug(bh, "refcount now=%d; releasing",
503 le32_to_cpu(BHDR(bh)->h_refcount)); 503 le32_to_cpu(BHDR(bh)->h_refcount));
504 if (ce) 504 if (ce)
@@ -774,7 +774,7 @@ inserted:
774 /* The old block is released after updating 774 /* The old block is released after updating
775 the inode. */ 775 the inode. */
776 error = -EDQUOT; 776 error = -EDQUOT;
777 if (DQUOT_ALLOC_BLOCK(inode, 1)) 777 if (vfs_dq_alloc_block(inode, 1))
778 goto cleanup; 778 goto cleanup;
779 error = ext3_journal_get_write_access(handle, 779 error = ext3_journal_get_write_access(handle,
780 new_bh); 780 new_bh);
@@ -848,7 +848,7 @@ cleanup:
848 return error; 848 return error;
849 849
850cleanup_dquot: 850cleanup_dquot:
851 DQUOT_FREE_BLOCK(inode, 1); 851 vfs_dq_free_block(inode, 1);
852 goto cleanup; 852 goto cleanup;
853 853
854bad_block: 854bad_block:
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index de9459b4cb9..38f40d55899 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -536,7 +536,7 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
536 ext4_mb_free_blocks(handle, inode, block, count, 536 ext4_mb_free_blocks(handle, inode, block, count,
537 metadata, &dquot_freed_blocks); 537 metadata, &dquot_freed_blocks);
538 if (dquot_freed_blocks) 538 if (dquot_freed_blocks)
539 DQUOT_FREE_BLOCK(inode, dquot_freed_blocks); 539 vfs_dq_free_block(inode, dquot_freed_blocks);
540 return; 540 return;
541} 541}
542 542
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index b0c87dce66a..6083bb38057 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -20,6 +20,7 @@
20#include <linux/blkdev.h> 20#include <linux/blkdev.h>
21#include <linux/magic.h> 21#include <linux/magic.h>
22#include <linux/jbd2.h> 22#include <linux/jbd2.h>
23#include <linux/quota.h>
23#include "ext4_i.h" 24#include "ext4_i.h"
24 25
25/* 26/*
@@ -1098,6 +1099,7 @@ extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
1098extern int ext4_block_truncate_page(handle_t *handle, 1099extern int ext4_block_truncate_page(handle_t *handle,
1099 struct address_space *mapping, loff_t from); 1100 struct address_space *mapping, loff_t from);
1100extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page); 1101extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct page *page);
1102extern qsize_t ext4_get_reserved_space(struct inode *inode);
1101 1103
1102/* ioctl.c */ 1104/* ioctl.c */
1103extern long ext4_ioctl(struct file *, unsigned int, unsigned long); 1105extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 2d2b3585ee9..fb51b40e3e8 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -220,10 +220,10 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
220 * Note: we must free any quota before locking the superblock, 220 * Note: we must free any quota before locking the superblock,
221 * as writing the quota to disk may need the lock as well. 221 * as writing the quota to disk may need the lock as well.
222 */ 222 */
223 DQUOT_INIT(inode); 223 vfs_dq_init(inode);
224 ext4_xattr_delete_inode(handle, inode); 224 ext4_xattr_delete_inode(handle, inode);
225 DQUOT_FREE_INODE(inode); 225 vfs_dq_free_inode(inode);
226 DQUOT_DROP(inode); 226 vfs_dq_drop(inode);
227 227
228 is_directory = S_ISDIR(inode->i_mode); 228 is_directory = S_ISDIR(inode->i_mode);
229 229
@@ -915,7 +915,7 @@ got:
915 ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize; 915 ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize;
916 916
917 ret = inode; 917 ret = inode;
918 if (DQUOT_ALLOC_INODE(inode)) { 918 if (vfs_dq_alloc_inode(inode)) {
919 err = -EDQUOT; 919 err = -EDQUOT;
920 goto fail_drop; 920 goto fail_drop;
921 } 921 }
@@ -956,10 +956,10 @@ really_out:
956 return ret; 956 return ret;
957 957
958fail_free_drop: 958fail_free_drop:
959 DQUOT_FREE_INODE(inode); 959 vfs_dq_free_inode(inode);
960 960
961fail_drop: 961fail_drop:
962 DQUOT_DROP(inode); 962 vfs_dq_drop(inode);
963 inode->i_flags |= S_NOQUOTA; 963 inode->i_flags |= S_NOQUOTA;
964 inode->i_nlink = 0; 964 inode->i_nlink = 0;
965 unlock_new_inode(inode); 965 unlock_new_inode(inode);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index c7fed5b1874..71d3ecd5db7 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -975,6 +975,17 @@ out:
975 return err; 975 return err;
976} 976}
977 977
978qsize_t ext4_get_reserved_space(struct inode *inode)
979{
980 unsigned long long total;
981
982 spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
983 total = EXT4_I(inode)->i_reserved_data_blocks +
984 EXT4_I(inode)->i_reserved_meta_blocks;
985 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
986
987 return total;
988}
978/* 989/*
979 * Calculate the number of metadata blocks need to reserve 990 * Calculate the number of metadata blocks need to reserve
980 * to allocate @blocks for non extent file based file 991 * to allocate @blocks for non extent file based file
@@ -1036,8 +1047,14 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)
1036 /* update per-inode reservations */ 1047 /* update per-inode reservations */
1037 BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); 1048 BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks);
1038 EXT4_I(inode)->i_reserved_data_blocks -= used; 1049 EXT4_I(inode)->i_reserved_data_blocks -= used;
1039
1040 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1050 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1051
1052 /*
1053 * free those over-booking quota for metadata blocks
1054 */
1055
1056 if (mdb_free)
1057 vfs_dq_release_reservation_block(inode, mdb_free);
1041} 1058}
1042 1059
1043/* 1060/*
@@ -1553,8 +1570,8 @@ static int ext4_journalled_write_end(struct file *file,
1553static int ext4_da_reserve_space(struct inode *inode, int nrblocks) 1570static int ext4_da_reserve_space(struct inode *inode, int nrblocks)
1554{ 1571{
1555 int retries = 0; 1572 int retries = 0;
1556 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 1573 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
1557 unsigned long md_needed, mdblocks, total = 0; 1574 unsigned long md_needed, mdblocks, total = 0;
1558 1575
1559 /* 1576 /*
1560 * recalculate the amount of metadata blocks to reserve 1577 * recalculate the amount of metadata blocks to reserve
@@ -1570,12 +1587,23 @@ repeat:
1570 md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; 1587 md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks;
1571 total = md_needed + nrblocks; 1588 total = md_needed + nrblocks;
1572 1589
1590 /*
1591 * Make quota reservation here to prevent quota overflow
1592 * later. Real quota accounting is done at pages writeout
1593 * time.
1594 */
1595 if (vfs_dq_reserve_block(inode, total)) {
1596 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1597 return -EDQUOT;
1598 }
1599
1573 if (ext4_claim_free_blocks(sbi, total)) { 1600 if (ext4_claim_free_blocks(sbi, total)) {
1574 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1601 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1575 if (ext4_should_retry_alloc(inode->i_sb, &retries)) { 1602 if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
1576 yield(); 1603 yield();
1577 goto repeat; 1604 goto repeat;
1578 } 1605 }
1606 vfs_dq_release_reservation_block(inode, total);
1579 return -ENOSPC; 1607 return -ENOSPC;
1580 } 1608 }
1581 EXT4_I(inode)->i_reserved_data_blocks += nrblocks; 1609 EXT4_I(inode)->i_reserved_data_blocks += nrblocks;
@@ -1629,6 +1657,8 @@ static void ext4_da_release_space(struct inode *inode, int to_free)
1629 BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks); 1657 BUG_ON(mdb > EXT4_I(inode)->i_reserved_meta_blocks);
1630 EXT4_I(inode)->i_reserved_meta_blocks = mdb; 1658 EXT4_I(inode)->i_reserved_meta_blocks = mdb;
1631 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1659 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
1660
1661 vfs_dq_release_reservation_block(inode, release);
1632} 1662}
1633 1663
1634static void ext4_da_page_release_reservation(struct page *page, 1664static void ext4_da_page_release_reservation(struct page *page,
@@ -4612,7 +4642,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
4612 error = PTR_ERR(handle); 4642 error = PTR_ERR(handle);
4613 goto err_out; 4643 goto err_out;
4614 } 4644 }
4615 error = DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0; 4645 error = vfs_dq_transfer(inode, attr) ? -EDQUOT : 0;
4616 if (error) { 4646 if (error) {
4617 ext4_journal_stop(handle); 4647 ext4_journal_stop(handle);
4618 return error; 4648 return error;
@@ -4991,7 +5021,7 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
4991 * i_size has been changed by generic_commit_write() and we thus need 5021 * i_size has been changed by generic_commit_write() and we thus need
4992 * to include the updated inode in the current transaction. 5022 * to include the updated inode in the current transaction.
4993 * 5023 *
4994 * Also, DQUOT_ALLOC_SPACE() will always dirty the inode when blocks 5024 * Also, vfs_dq_alloc_block() will always dirty the inode when blocks
4995 * are allocated to the file. 5025 * are allocated to the file.
4996 * 5026 *
4997 * If the inode is marked synchronous, we don't honour that here - doing 5027 * If the inode is marked synchronous, we don't honour that here - doing
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 9f61e62f435..b038188bd03 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -3086,9 +3086,12 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
3086 if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED)) 3086 if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED))
3087 /* release all the reserved blocks if non delalloc */ 3087 /* release all the reserved blocks if non delalloc */
3088 percpu_counter_sub(&sbi->s_dirtyblocks_counter, reserv_blks); 3088 percpu_counter_sub(&sbi->s_dirtyblocks_counter, reserv_blks);
3089 else 3089 else {
3090 percpu_counter_sub(&sbi->s_dirtyblocks_counter, 3090 percpu_counter_sub(&sbi->s_dirtyblocks_counter,
3091 ac->ac_b_ex.fe_len); 3091 ac->ac_b_ex.fe_len);
3092 /* convert reserved quota blocks to real quota blocks */
3093 vfs_dq_claim_block(ac->ac_inode, ac->ac_b_ex.fe_len);
3094 }
3092 3095
3093 if (sbi->s_log_groups_per_flex) { 3096 if (sbi->s_log_groups_per_flex) {
3094 ext4_group_t flex_group = ext4_flex_group(sbi, 3097 ext4_group_t flex_group = ext4_flex_group(sbi,
@@ -4544,7 +4547,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4544 struct ext4_sb_info *sbi; 4547 struct ext4_sb_info *sbi;
4545 struct super_block *sb; 4548 struct super_block *sb;
4546 ext4_fsblk_t block = 0; 4549 ext4_fsblk_t block = 0;
4547 unsigned int inquota; 4550 unsigned int inquota = 0;
4548 unsigned int reserv_blks = 0; 4551 unsigned int reserv_blks = 0;
4549 4552
4550 sb = ar->inode->i_sb; 4553 sb = ar->inode->i_sb;
@@ -4562,9 +4565,17 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4562 (unsigned long long) ar->pleft, 4565 (unsigned long long) ar->pleft,
4563 (unsigned long long) ar->pright); 4566 (unsigned long long) ar->pright);
4564 4567
4565 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) { 4568 /*
4566 /* 4569 * For delayed allocation, we could skip the ENOSPC and
4567 * With delalloc we already reserved the blocks 4570 * EDQUOT check, as blocks and quotas have been already
4571 * reserved when data being copied into pagecache.
4572 */
4573 if (EXT4_I(ar->inode)->i_delalloc_reserved_flag)
4574 ar->flags |= EXT4_MB_DELALLOC_RESERVED;
4575 else {
4576 /* Without delayed allocation we need to verify
4577 * there is enough free blocks to do block allocation
4578 * and verify allocation doesn't exceed the quota limits.
4568 */ 4579 */
4569 while (ar->len && ext4_claim_free_blocks(sbi, ar->len)) { 4580 while (ar->len && ext4_claim_free_blocks(sbi, ar->len)) {
4570 /* let others to free the space */ 4581 /* let others to free the space */
@@ -4576,19 +4587,16 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4576 return 0; 4587 return 0;
4577 } 4588 }
4578 reserv_blks = ar->len; 4589 reserv_blks = ar->len;
4590 while (ar->len && vfs_dq_alloc_block(ar->inode, ar->len)) {
4591 ar->flags |= EXT4_MB_HINT_NOPREALLOC;
4592 ar->len--;
4593 }
4594 inquota = ar->len;
4595 if (ar->len == 0) {
4596 *errp = -EDQUOT;
4597 goto out3;
4598 }
4579 } 4599 }
4580 while (ar->len && DQUOT_ALLOC_BLOCK(ar->inode, ar->len)) {
4581 ar->flags |= EXT4_MB_HINT_NOPREALLOC;
4582 ar->len--;
4583 }
4584 if (ar->len == 0) {
4585 *errp = -EDQUOT;
4586 goto out3;
4587 }
4588 inquota = ar->len;
4589
4590 if (EXT4_I(ar->inode)->i_delalloc_reserved_flag)
4591 ar->flags |= EXT4_MB_DELALLOC_RESERVED;
4592 4600
4593 ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS); 4601 ac = kmem_cache_alloc(ext4_ac_cachep, GFP_NOFS);
4594 if (!ac) { 4602 if (!ac) {
@@ -4654,8 +4662,8 @@ repeat:
4654out2: 4662out2:
4655 kmem_cache_free(ext4_ac_cachep, ac); 4663 kmem_cache_free(ext4_ac_cachep, ac);
4656out1: 4664out1:
4657 if (ar->len < inquota) 4665 if (inquota && ar->len < inquota)
4658 DQUOT_FREE_BLOCK(ar->inode, inquota - ar->len); 4666 vfs_dq_free_block(ar->inode, inquota - ar->len);
4659out3: 4667out3:
4660 if (!ar->len) { 4668 if (!ar->len) {
4661 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) 4669 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index ba702bd7910..83410244d3e 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -2092,7 +2092,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
2092 2092
2093 /* Initialize quotas before so that eventual writes go in 2093 /* Initialize quotas before so that eventual writes go in
2094 * separate transaction */ 2094 * separate transaction */
2095 DQUOT_INIT(dentry->d_inode); 2095 vfs_dq_init(dentry->d_inode);
2096 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb)); 2096 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2097 if (IS_ERR(handle)) 2097 if (IS_ERR(handle))
2098 return PTR_ERR(handle); 2098 return PTR_ERR(handle);
@@ -2151,7 +2151,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
2151 2151
2152 /* Initialize quotas before so that eventual writes go 2152 /* Initialize quotas before so that eventual writes go
2153 * in separate transaction */ 2153 * in separate transaction */
2154 DQUOT_INIT(dentry->d_inode); 2154 vfs_dq_init(dentry->d_inode);
2155 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb)); 2155 handle = ext4_journal_start(dir, EXT4_DELETE_TRANS_BLOCKS(dir->i_sb));
2156 if (IS_ERR(handle)) 2156 if (IS_ERR(handle))
2157 return PTR_ERR(handle); 2157 return PTR_ERR(handle);
@@ -2318,7 +2318,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2318 /* Initialize quotas before so that eventual writes go 2318 /* Initialize quotas before so that eventual writes go
2319 * in separate transaction */ 2319 * in separate transaction */
2320 if (new_dentry->d_inode) 2320 if (new_dentry->d_inode)
2321 DQUOT_INIT(new_dentry->d_inode); 2321 vfs_dq_init(new_dentry->d_inode);
2322 handle = ext4_journal_start(old_dir, 2 * 2322 handle = ext4_journal_start(old_dir, 2 *
2323 EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) + 2323 EXT4_DATA_TRANS_BLOCKS(old_dir->i_sb) +
2324 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2); 2324 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 2);
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 39d1993cfa1..f7371a6a923 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -926,8 +926,6 @@ static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_
926#define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group") 926#define QTYPE2NAME(t) ((t) == USRQUOTA ? "user" : "group")
927#define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA)) 927#define QTYPE2MOPT(on, t) ((t) == USRQUOTA?((on)##USRJQUOTA):((on)##GRPJQUOTA))
928 928
929static int ext4_dquot_initialize(struct inode *inode, int type);
930static int ext4_dquot_drop(struct inode *inode);
931static int ext4_write_dquot(struct dquot *dquot); 929static int ext4_write_dquot(struct dquot *dquot);
932static int ext4_acquire_dquot(struct dquot *dquot); 930static int ext4_acquire_dquot(struct dquot *dquot);
933static int ext4_release_dquot(struct dquot *dquot); 931static int ext4_release_dquot(struct dquot *dquot);
@@ -942,9 +940,13 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
942 const char *data, size_t len, loff_t off); 940 const char *data, size_t len, loff_t off);
943 941
944static struct dquot_operations ext4_quota_operations = { 942static struct dquot_operations ext4_quota_operations = {
945 .initialize = ext4_dquot_initialize, 943 .initialize = dquot_initialize,
946 .drop = ext4_dquot_drop, 944 .drop = dquot_drop,
947 .alloc_space = dquot_alloc_space, 945 .alloc_space = dquot_alloc_space,
946 .reserve_space = dquot_reserve_space,
947 .claim_space = dquot_claim_space,
948 .release_rsv = dquot_release_reserved_space,
949 .get_reserved_space = ext4_get_reserved_space,
948 .alloc_inode = dquot_alloc_inode, 950 .alloc_inode = dquot_alloc_inode,
949 .free_space = dquot_free_space, 951 .free_space = dquot_free_space,
950 .free_inode = dquot_free_inode, 952 .free_inode = dquot_free_inode,
@@ -1802,7 +1804,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1802 } 1804 }
1803 1805
1804 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); 1806 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1805 DQUOT_INIT(inode); 1807 vfs_dq_init(inode);
1806 if (inode->i_nlink) { 1808 if (inode->i_nlink) {
1807 printk(KERN_DEBUG 1809 printk(KERN_DEBUG
1808 "%s: truncating inode %lu to %lld bytes\n", 1810 "%s: truncating inode %lu to %lld bytes\n",
@@ -3367,8 +3369,8 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3367 * is locked for write. Otherwise the are possible deadlocks: 3369 * is locked for write. Otherwise the are possible deadlocks:
3368 * Process 1 Process 2 3370 * Process 1 Process 2
3369 * ext4_create() quota_sync() 3371 * ext4_create() quota_sync()
3370 * jbd2_journal_start() write_dquot() 3372 * jbd2_journal_start() write_dquot()
3371 * DQUOT_INIT() down(dqio_mutex) 3373 * vfs_dq_init() down(dqio_mutex)
3372 * down(dqio_mutex) jbd2_journal_start() 3374 * down(dqio_mutex) jbd2_journal_start()
3373 * 3375 *
3374 */ 3376 */
@@ -3380,44 +3382,6 @@ static inline struct inode *dquot_to_inode(struct dquot *dquot)
3380 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type]; 3382 return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
3381} 3383}
3382 3384
3383static int ext4_dquot_initialize(struct inode *inode, int type)
3384{
3385 handle_t *handle;
3386 int ret, err;
3387
3388 /* We may create quota structure so we need to reserve enough blocks */
3389 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_INIT_BLOCKS(inode->i_sb));
3390 if (IS_ERR(handle))
3391 return PTR_ERR(handle);
3392 ret = dquot_initialize(inode, type);
3393 err = ext4_journal_stop(handle);
3394 if (!ret)
3395 ret = err;
3396 return ret;
3397}
3398
3399static int ext4_dquot_drop(struct inode *inode)
3400{
3401 handle_t *handle;
3402 int ret, err;
3403
3404 /* We may delete quota structure so we need to reserve enough blocks */
3405 handle = ext4_journal_start(inode, 2*EXT4_QUOTA_DEL_BLOCKS(inode->i_sb));
3406 if (IS_ERR(handle)) {
3407 /*
3408 * We call dquot_drop() anyway to at least release references
3409 * to quota structures so that umount does not hang.
3410 */
3411 dquot_drop(inode);
3412 return PTR_ERR(handle);
3413 }
3414 ret = dquot_drop(inode);
3415 err = ext4_journal_stop(handle);
3416 if (!ret)
3417 ret = err;
3418 return ret;
3419}
3420
3421static int ext4_write_dquot(struct dquot *dquot) 3385static int ext4_write_dquot(struct dquot *dquot)
3422{ 3386{
3423 int ret, err; 3387 int ret, err;
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 157ce6589c5..62b31c24699 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -490,7 +490,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
490 error = ext4_handle_dirty_metadata(handle, inode, bh); 490 error = ext4_handle_dirty_metadata(handle, inode, bh);
491 if (IS_SYNC(inode)) 491 if (IS_SYNC(inode))
492 ext4_handle_sync(handle); 492 ext4_handle_sync(handle);
493 DQUOT_FREE_BLOCK(inode, 1); 493 vfs_dq_free_block(inode, 1);
494 ea_bdebug(bh, "refcount now=%d; releasing", 494 ea_bdebug(bh, "refcount now=%d; releasing",
495 le32_to_cpu(BHDR(bh)->h_refcount)); 495 le32_to_cpu(BHDR(bh)->h_refcount));
496 if (ce) 496 if (ce)
@@ -784,7 +784,7 @@ inserted:
784 /* The old block is released after updating 784 /* The old block is released after updating
785 the inode. */ 785 the inode. */
786 error = -EDQUOT; 786 error = -EDQUOT;
787 if (DQUOT_ALLOC_BLOCK(inode, 1)) 787 if (vfs_dq_alloc_block(inode, 1))
788 goto cleanup; 788 goto cleanup;
789 error = ext4_journal_get_write_access(handle, 789 error = ext4_journal_get_write_access(handle,
790 new_bh); 790 new_bh);
@@ -860,7 +860,7 @@ cleanup:
860 return error; 860 return error;
861 861
862cleanup_dquot: 862cleanup_dquot:
863 DQUOT_FREE_BLOCK(inode, 1); 863 vfs_dq_free_block(inode, 1);
864 goto cleanup; 864 goto cleanup;
865 865
866bad_block: 866bad_block:
diff --git a/fs/fat/namei_msdos.c b/fs/fat/namei_msdos.c
index 7ba03a4acbe..da3f361a37d 100644
--- a/fs/fat/namei_msdos.c
+++ b/fs/fat/namei_msdos.c
@@ -188,7 +188,7 @@ old_compare:
188 goto out; 188 goto out;
189} 189}
190 190
191static struct dentry_operations msdos_dentry_operations = { 191static const struct dentry_operations msdos_dentry_operations = {
192 .d_hash = msdos_hash, 192 .d_hash = msdos_hash,
193 .d_compare = msdos_cmp, 193 .d_compare = msdos_cmp,
194}; 194};
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index 8ae32e37673..a0e00e3a46e 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -166,13 +166,13 @@ static int vfat_cmp(struct dentry *dentry, struct qstr *a, struct qstr *b)
166 return 1; 166 return 1;
167} 167}
168 168
169static struct dentry_operations vfat_ci_dentry_ops = { 169static const struct dentry_operations vfat_ci_dentry_ops = {
170 .d_revalidate = vfat_revalidate_ci, 170 .d_revalidate = vfat_revalidate_ci,
171 .d_hash = vfat_hashi, 171 .d_hash = vfat_hashi,
172 .d_compare = vfat_cmpi, 172 .d_compare = vfat_cmpi,
173}; 173};
174 174
175static struct dentry_operations vfat_dentry_ops = { 175static const struct dentry_operations vfat_dentry_ops = {
176 .d_revalidate = vfat_revalidate, 176 .d_revalidate = vfat_revalidate,
177 .d_hash = vfat_hash, 177 .d_hash = vfat_hash,
178 .d_compare = vfat_cmp, 178 .d_compare = vfat_cmp,
diff --git a/fs/fcntl.c b/fs/fcntl.c
index bd215cc791d..cc8e4de2fee 100644
--- a/fs/fcntl.c
+++ b/fs/fcntl.c
@@ -141,7 +141,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
141 return ret; 141 return ret;
142} 142}
143 143
144#define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | FASYNC | O_DIRECT | O_NOATIME) 144#define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
145 145
146static int setfl(int fd, struct file * filp, unsigned long arg) 146static int setfl(int fd, struct file * filp, unsigned long arg)
147{ 147{
@@ -177,21 +177,21 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
177 return error; 177 return error;
178 178
179 /* 179 /*
180 * We still need a lock here for now to keep multiple FASYNC calls 180 * ->fasync() is responsible for setting the FASYNC bit.
181 * from racing with each other.
182 */ 181 */
183 lock_kernel(); 182 if (((arg ^ filp->f_flags) & FASYNC) && filp->f_op &&
184 if ((arg ^ filp->f_flags) & FASYNC) { 183 filp->f_op->fasync) {
185 if (filp->f_op && filp->f_op->fasync) { 184 error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0);
186 error = filp->f_op->fasync(fd, filp, (arg & FASYNC) != 0); 185 if (error < 0)
187 if (error < 0) 186 goto out;
188 goto out; 187 if (error > 0)
189 } 188 error = 0;
190 } 189 }
191 190 spin_lock(&filp->f_lock);
192 filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK); 191 filp->f_flags = (arg & SETFL_MASK) | (filp->f_flags & ~SETFL_MASK);
192 spin_unlock(&filp->f_lock);
193
193 out: 194 out:
194 unlock_kernel();
195 return error; 195 return error;
196} 196}
197 197
@@ -516,7 +516,7 @@ static DEFINE_RWLOCK(fasync_lock);
516static struct kmem_cache *fasync_cache __read_mostly; 516static struct kmem_cache *fasync_cache __read_mostly;
517 517
518/* 518/*
519 * fasync_helper() is used by some character device drivers (mainly mice) 519 * fasync_helper() is used by almost all character device drivers
520 * to set up the fasync queue. It returns negative on error, 0 if it did 520 * to set up the fasync queue. It returns negative on error, 0 if it did
521 * no changes and positive if it added/deleted the entry. 521 * no changes and positive if it added/deleted the entry.
522 */ 522 */
@@ -531,6 +531,12 @@ int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fap
531 if (!new) 531 if (!new)
532 return -ENOMEM; 532 return -ENOMEM;
533 } 533 }
534
535 /*
536 * We need to take f_lock first since it's not an IRQ-safe
537 * lock.
538 */
539 spin_lock(&filp->f_lock);
534 write_lock_irq(&fasync_lock); 540 write_lock_irq(&fasync_lock);
535 for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) { 541 for (fp = fapp; (fa = *fp) != NULL; fp = &fa->fa_next) {
536 if (fa->fa_file == filp) { 542 if (fa->fa_file == filp) {
@@ -555,7 +561,12 @@ int fasync_helper(int fd, struct file * filp, int on, struct fasync_struct **fap
555 result = 1; 561 result = 1;
556 } 562 }
557out: 563out:
564 if (on)
565 filp->f_flags |= FASYNC;
566 else
567 filp->f_flags &= ~FASYNC;
558 write_unlock_irq(&fasync_lock); 568 write_unlock_irq(&fasync_lock);
569 spin_unlock(&filp->f_lock);
559 return result; 570 return result;
560} 571}
561 572
diff --git a/fs/file_table.c b/fs/file_table.c
index bbeeac6efa1..b74a8e1da91 100644
--- a/fs/file_table.c
+++ b/fs/file_table.c
@@ -13,6 +13,7 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/security.h> 15#include <linux/security.h>
16#include <linux/ima.h>
16#include <linux/eventpoll.h> 17#include <linux/eventpoll.h>
17#include <linux/rcupdate.h> 18#include <linux/rcupdate.h>
18#include <linux/mount.h> 19#include <linux/mount.h>
@@ -127,6 +128,7 @@ struct file *get_empty_filp(void)
127 atomic_long_set(&f->f_count, 1); 128 atomic_long_set(&f->f_count, 1);
128 rwlock_init(&f->f_owner.lock); 129 rwlock_init(&f->f_owner.lock);
129 f->f_cred = get_cred(cred); 130 f->f_cred = get_cred(cred);
131 spin_lock_init(&f->f_lock);
130 eventpoll_init_file(f); 132 eventpoll_init_file(f);
131 /* f->f_version: 0 */ 133 /* f->f_version: 0 */
132 return f; 134 return f;
@@ -279,6 +281,7 @@ void __fput(struct file *file)
279 if (file->f_op && file->f_op->release) 281 if (file->f_op && file->f_op->release)
280 file->f_op->release(inode, file); 282 file->f_op->release(inode, file);
281 security_file_free(file); 283 security_file_free(file);
284 ima_file_free(file);
282 if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL)) 285 if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL))
283 cdev_put(inode->i_cdev); 286 cdev_put(inode->i_cdev);
284 fops_put(file->f_op); 287 fops_put(file->f_op);
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index fdff346e96f..06da05261e0 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -224,7 +224,7 @@ static int invalid_nodeid(u64 nodeid)
224 return !nodeid || nodeid == FUSE_ROOT_ID; 224 return !nodeid || nodeid == FUSE_ROOT_ID;
225} 225}
226 226
227struct dentry_operations fuse_dentry_operations = { 227const struct dentry_operations fuse_dentry_operations = {
228 .d_revalidate = fuse_dentry_revalidate, 228 .d_revalidate = fuse_dentry_revalidate,
229}; 229};
230 230
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index d9fdb7cec53..821d10f719b 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1465,7 +1465,7 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin)
1465 case SEEK_END: 1465 case SEEK_END:
1466 retval = fuse_update_attributes(inode, NULL, file, NULL); 1466 retval = fuse_update_attributes(inode, NULL, file, NULL);
1467 if (retval) 1467 if (retval)
1468 return retval; 1468 goto exit;
1469 offset += i_size_read(inode); 1469 offset += i_size_read(inode);
1470 break; 1470 break;
1471 case SEEK_CUR: 1471 case SEEK_CUR:
@@ -1479,6 +1479,7 @@ static loff_t fuse_file_llseek(struct file *file, loff_t offset, int origin)
1479 } 1479 }
1480 retval = offset; 1480 retval = offset;
1481 } 1481 }
1482exit:
1482 mutex_unlock(&inode->i_mutex); 1483 mutex_unlock(&inode->i_mutex);
1483 return retval; 1484 return retval;
1484} 1485}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 5e64b815a5a..6fc5aedaa0d 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -493,7 +493,7 @@ static inline u64 get_node_id(struct inode *inode)
493/** Device operations */ 493/** Device operations */
494extern const struct file_operations fuse_dev_operations; 494extern const struct file_operations fuse_dev_operations;
495 495
496extern struct dentry_operations fuse_dentry_operations; 496extern const struct dentry_operations fuse_dentry_operations;
497 497
498/** 498/**
499 * Get a filled in inode 499 * Get a filled in inode
diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig
index e563a644981..3a981b7f64c 100644
--- a/fs/gfs2/Kconfig
+++ b/fs/gfs2/Kconfig
@@ -1,6 +1,10 @@
1config GFS2_FS 1config GFS2_FS
2 tristate "GFS2 file system support" 2 tristate "GFS2 file system support"
3 depends on EXPERIMENTAL && (64BIT || LBD) 3 depends on EXPERIMENTAL && (64BIT || LBD)
4 select DLM if GFS2_FS_LOCKING_DLM
5 select CONFIGFS_FS if GFS2_FS_LOCKING_DLM
6 select SYSFS if GFS2_FS_LOCKING_DLM
7 select IP_SCTP if DLM_SCTP
4 select FS_POSIX_ACL 8 select FS_POSIX_ACL
5 select CRC32 9 select CRC32
6 help 10 help
@@ -18,17 +22,16 @@ config GFS2_FS
18 the locking module below. Documentation and utilities for GFS2 can 22 the locking module below. Documentation and utilities for GFS2 can
19 be found here: http://sources.redhat.com/cluster 23 be found here: http://sources.redhat.com/cluster
20 24
21 The "nolock" lock module is now built in to GFS2 by default. 25 The "nolock" lock module is now built in to GFS2 by default. If
26 you want to use the DLM, be sure to enable HOTPLUG and IPv4/6
27 networking.
22 28
23config GFS2_FS_LOCKING_DLM 29config GFS2_FS_LOCKING_DLM
24 tristate "GFS2 DLM locking module" 30 bool "GFS2 DLM locking"
25 depends on GFS2_FS && SYSFS && NET && INET && (IPV6 || IPV6=n) 31 depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && HOTPLUG
26 select IP_SCTP if DLM_SCTP
27 select CONFIGFS_FS
28 select DLM
29 help 32 help
30 Multiple node locking module for GFS2 33 Multiple node locking module for GFS2
31 34
32 Most users of GFS2 will require this module. It provides the locking 35 Most users of GFS2 will require this. It provides the locking
33 interface between GFS2 and the DLM, which is required to use GFS2 36 interface between GFS2 and the DLM, which is required to use GFS2
34 in a cluster environment. 37 in a cluster environment.
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index c1b4ec6a965..a851ea4bdf7 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -1,9 +1,9 @@
1obj-$(CONFIG_GFS2_FS) += gfs2.o 1obj-$(CONFIG_GFS2_FS) += gfs2.o
2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \ 2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \
3 glops.o inode.o log.o lops.o locking.o main.o meta_io.o \ 3 glops.o inode.o log.o lops.o main.o meta_io.o \
4 mount.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ 4 mount.o ops_address.o ops_dentry.o ops_export.o ops_file.o \
5 ops_fstype.o ops_inode.o ops_super.o quota.o \ 5 ops_fstype.o ops_inode.o ops_super.o quota.o \
6 recovery.o rgrp.o super.o sys.o trans.o util.o 6 recovery.o rgrp.o super.o sys.o trans.o util.o
7 7
8obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/ 8gfs2-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o
9 9
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index e335dceb6a4..43764f4fa76 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -15,7 +15,6 @@
15#include <linux/posix_acl.h> 15#include <linux/posix_acl.h>
16#include <linux/posix_acl_xattr.h> 16#include <linux/posix_acl_xattr.h>
17#include <linux/gfs2_ondisk.h> 17#include <linux/gfs2_ondisk.h>
18#include <linux/lm_interface.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
21#include "incore.h" 20#include "incore.h"
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 11ffc56f1f8..3a5d3f883e1 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/lm_interface.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index b7c8e5c7079..aef4d0c0674 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -60,7 +60,6 @@
60#include <linux/gfs2_ondisk.h> 60#include <linux/gfs2_ondisk.h>
61#include <linux/crc32.h> 61#include <linux/crc32.h>
62#include <linux/vmalloc.h> 62#include <linux/vmalloc.h>
63#include <linux/lm_interface.h>
64 63
65#include "gfs2.h" 64#include "gfs2.h"
66#include "incore.h" 65#include "incore.h"
diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c
index f114ba2b355..dee9b03e5b3 100644
--- a/fs/gfs2/eaops.c
+++ b/fs/gfs2/eaops.c
@@ -14,7 +14,6 @@
14#include <linux/capability.h> 14#include <linux/capability.h>
15#include <linux/xattr.h> 15#include <linux/xattr.h>
16#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
17#include <linux/lm_interface.h>
18#include <asm/uaccess.h> 17#include <asm/uaccess.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c
index 0d1c76d906a..899763aed21 100644
--- a/fs/gfs2/eattr.c
+++ b/fs/gfs2/eattr.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/xattr.h> 14#include <linux/xattr.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17#include <asm/uaccess.h> 16#include <asm/uaccess.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 6b983aef785..3984e47d1d3 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -10,7 +10,6 @@
10#include <linux/sched.h> 10#include <linux/sched.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/completion.h>
14#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/sort.h> 15#include <linux/sort.h>
@@ -18,7 +17,6 @@
18#include <linux/kallsyms.h> 17#include <linux/kallsyms.h>
19#include <linux/gfs2_ondisk.h> 18#include <linux/gfs2_ondisk.h>
20#include <linux/list.h> 19#include <linux/list.h>
21#include <linux/lm_interface.h>
22#include <linux/wait.h> 20#include <linux/wait.h>
23#include <linux/module.h> 21#include <linux/module.h>
24#include <linux/rwsem.h> 22#include <linux/rwsem.h>
@@ -155,13 +153,10 @@ static void glock_free(struct gfs2_glock *gl)
155 struct gfs2_sbd *sdp = gl->gl_sbd; 153 struct gfs2_sbd *sdp = gl->gl_sbd;
156 struct inode *aspace = gl->gl_aspace; 154 struct inode *aspace = gl->gl_aspace;
157 155
158 if (sdp->sd_lockstruct.ls_ops->lm_put_lock)
159 sdp->sd_lockstruct.ls_ops->lm_put_lock(gl->gl_lock);
160
161 if (aspace) 156 if (aspace)
162 gfs2_aspace_put(aspace); 157 gfs2_aspace_put(aspace);
163 158
164 kmem_cache_free(gfs2_glock_cachep, gl); 159 sdp->sd_lockstruct.ls_ops->lm_put_lock(gfs2_glock_cachep, gl);
165} 160}
166 161
167/** 162/**
@@ -172,6 +167,7 @@ static void glock_free(struct gfs2_glock *gl)
172 167
173static void gfs2_glock_hold(struct gfs2_glock *gl) 168static void gfs2_glock_hold(struct gfs2_glock *gl)
174{ 169{
170 GLOCK_BUG_ON(gl, atomic_read(&gl->gl_ref) == 0);
175 atomic_inc(&gl->gl_ref); 171 atomic_inc(&gl->gl_ref);
176} 172}
177 173
@@ -211,17 +207,15 @@ int gfs2_glock_put(struct gfs2_glock *gl)
211 atomic_dec(&lru_count); 207 atomic_dec(&lru_count);
212 } 208 }
213 spin_unlock(&lru_lock); 209 spin_unlock(&lru_lock);
214 GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_UNLOCKED);
215 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_lru));
216 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); 210 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));
217 glock_free(gl); 211 glock_free(gl);
218 rv = 1; 212 rv = 1;
219 goto out; 213 goto out;
220 } 214 }
221 write_unlock(gl_lock_addr(gl->gl_hash));
222 /* 1 for being hashed, 1 for having state != LM_ST_UNLOCKED */ 215 /* 1 for being hashed, 1 for having state != LM_ST_UNLOCKED */
223 if (atomic_read(&gl->gl_ref) == 2) 216 if (atomic_read(&gl->gl_ref) == 2)
224 gfs2_glock_schedule_for_reclaim(gl); 217 gfs2_glock_schedule_for_reclaim(gl);
218 write_unlock(gl_lock_addr(gl->gl_hash));
225out: 219out:
226 return rv; 220 return rv;
227} 221}
@@ -256,27 +250,6 @@ static struct gfs2_glock *search_bucket(unsigned int hash,
256} 250}
257 251
258/** 252/**
259 * gfs2_glock_find() - Find glock by lock number
260 * @sdp: The GFS2 superblock
261 * @name: The lock name
262 *
263 * Returns: NULL, or the struct gfs2_glock with the requested number
264 */
265
266static struct gfs2_glock *gfs2_glock_find(const struct gfs2_sbd *sdp,
267 const struct lm_lockname *name)
268{
269 unsigned int hash = gl_hash(sdp, name);
270 struct gfs2_glock *gl;
271
272 read_lock(gl_lock_addr(hash));
273 gl = search_bucket(hash, sdp, name);
274 read_unlock(gl_lock_addr(hash));
275
276 return gl;
277}
278
279/**
280 * may_grant - check if its ok to grant a new lock 253 * may_grant - check if its ok to grant a new lock
281 * @gl: The glock 254 * @gl: The glock
282 * @gh: The lock request which we wish to grant 255 * @gh: The lock request which we wish to grant
@@ -523,7 +496,7 @@ out_locked:
523} 496}
524 497
525static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock, 498static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
526 unsigned int cur_state, unsigned int req_state, 499 unsigned int req_state,
527 unsigned int flags) 500 unsigned int flags)
528{ 501{
529 int ret = LM_OUT_ERROR; 502 int ret = LM_OUT_ERROR;
@@ -532,7 +505,7 @@ static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
532 return req_state == LM_ST_UNLOCKED ? 0 : req_state; 505 return req_state == LM_ST_UNLOCKED ? 0 : req_state;
533 506
534 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 507 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
535 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state, 508 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock,
536 req_state, flags); 509 req_state, flags);
537 return ret; 510 return ret;
538} 511}
@@ -575,7 +548,7 @@ __acquires(&gl->gl_spin)
575 gl->gl_state == LM_ST_DEFERRED) && 548 gl->gl_state == LM_ST_DEFERRED) &&
576 !(lck_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 549 !(lck_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
577 lck_flags |= LM_FLAG_TRY_1CB; 550 lck_flags |= LM_FLAG_TRY_1CB;
578 ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, target, lck_flags); 551 ret = gfs2_lm_lock(sdp, gl, target, lck_flags);
579 552
580 if (!(ret & LM_OUT_ASYNC)) { 553 if (!(ret & LM_OUT_ASYNC)) {
581 finish_xmote(gl, ret); 554 finish_xmote(gl, ret);
@@ -624,10 +597,11 @@ __acquires(&gl->gl_spin)
624 597
625 GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)); 598 GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags));
626 599
600 down_read(&gfs2_umount_flush_sem);
627 if (test_bit(GLF_DEMOTE, &gl->gl_flags) && 601 if (test_bit(GLF_DEMOTE, &gl->gl_flags) &&
628 gl->gl_demote_state != gl->gl_state) { 602 gl->gl_demote_state != gl->gl_state) {
629 if (find_first_holder(gl)) 603 if (find_first_holder(gl))
630 goto out; 604 goto out_unlock;
631 if (nonblock) 605 if (nonblock)
632 goto out_sched; 606 goto out_sched;
633 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags); 607 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
@@ -638,23 +612,26 @@ __acquires(&gl->gl_spin)
638 gfs2_demote_wake(gl); 612 gfs2_demote_wake(gl);
639 ret = do_promote(gl); 613 ret = do_promote(gl);
640 if (ret == 0) 614 if (ret == 0)
641 goto out; 615 goto out_unlock;
642 if (ret == 2) 616 if (ret == 2)
643 return; 617 goto out_sem;
644 gh = find_first_waiter(gl); 618 gh = find_first_waiter(gl);
645 gl->gl_target = gh->gh_state; 619 gl->gl_target = gh->gh_state;
646 if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 620 if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
647 do_error(gl, 0); /* Fail queued try locks */ 621 do_error(gl, 0); /* Fail queued try locks */
648 } 622 }
649 do_xmote(gl, gh, gl->gl_target); 623 do_xmote(gl, gh, gl->gl_target);
624out_sem:
625 up_read(&gfs2_umount_flush_sem);
650 return; 626 return;
651 627
652out_sched: 628out_sched:
653 gfs2_glock_hold(gl); 629 gfs2_glock_hold(gl);
654 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0) 630 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
655 gfs2_glock_put(gl); 631 gfs2_glock_put(gl);
656out: 632out_unlock:
657 clear_bit(GLF_LOCK, &gl->gl_flags); 633 clear_bit(GLF_LOCK, &gl->gl_flags);
634 goto out_sem;
658} 635}
659 636
660static void glock_work_func(struct work_struct *work) 637static void glock_work_func(struct work_struct *work)
@@ -681,18 +658,6 @@ static void glock_work_func(struct work_struct *work)
681 gfs2_glock_put(gl); 658 gfs2_glock_put(gl);
682} 659}
683 660
684static int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
685 void **lockp)
686{
687 int error = -EIO;
688 if (!sdp->sd_lockstruct.ls_ops->lm_get_lock)
689 return 0;
690 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
691 error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
692 sdp->sd_lockstruct.ls_lockspace, name, lockp);
693 return error;
694}
695
696/** 661/**
697 * gfs2_glock_get() - Get a glock, or create one if one doesn't exist 662 * gfs2_glock_get() - Get a glock, or create one if one doesn't exist
698 * @sdp: The GFS2 superblock 663 * @sdp: The GFS2 superblock
@@ -719,10 +684,11 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
719 gl = search_bucket(hash, sdp, &name); 684 gl = search_bucket(hash, sdp, &name);
720 read_unlock(gl_lock_addr(hash)); 685 read_unlock(gl_lock_addr(hash));
721 686
722 if (gl || !create) { 687 *glp = gl;
723 *glp = gl; 688 if (gl)
724 return 0; 689 return 0;
725 } 690 if (!create)
691 return -ENOENT;
726 692
727 gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL); 693 gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL);
728 if (!gl) 694 if (!gl)
@@ -736,7 +702,9 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
736 gl->gl_demote_state = LM_ST_EXCLUSIVE; 702 gl->gl_demote_state = LM_ST_EXCLUSIVE;
737 gl->gl_hash = hash; 703 gl->gl_hash = hash;
738 gl->gl_ops = glops; 704 gl->gl_ops = glops;
739 gl->gl_stamp = jiffies; 705 snprintf(gl->gl_strname, GDLM_STRNAME_BYTES, "%8x%16llx", name.ln_type, (unsigned long long)number);
706 memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb));
707 gl->gl_lksb.sb_lvbptr = gl->gl_lvb;
740 gl->gl_tchange = jiffies; 708 gl->gl_tchange = jiffies;
741 gl->gl_object = NULL; 709 gl->gl_object = NULL;
742 gl->gl_sbd = sdp; 710 gl->gl_sbd = sdp;
@@ -753,10 +721,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
753 } 721 }
754 } 722 }
755 723
756 error = gfs2_lm_get_lock(sdp, &name, &gl->gl_lock);
757 if (error)
758 goto fail_aspace;
759
760 write_lock(gl_lock_addr(hash)); 724 write_lock(gl_lock_addr(hash));
761 tmp = search_bucket(hash, sdp, &name); 725 tmp = search_bucket(hash, sdp, &name);
762 if (tmp) { 726 if (tmp) {
@@ -772,9 +736,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
772 736
773 return 0; 737 return 0;
774 738
775fail_aspace:
776 if (gl->gl_aspace)
777 gfs2_aspace_put(gl->gl_aspace);
778fail: 739fail:
779 kmem_cache_free(gfs2_glock_cachep, gl); 740 kmem_cache_free(gfs2_glock_cachep, gl);
780 return error; 741 return error;
@@ -966,7 +927,7 @@ do_cancel:
966 if (!(gh->gh_flags & LM_FLAG_PRIORITY)) { 927 if (!(gh->gh_flags & LM_FLAG_PRIORITY)) {
967 spin_unlock(&gl->gl_spin); 928 spin_unlock(&gl->gl_spin);
968 if (sdp->sd_lockstruct.ls_ops->lm_cancel) 929 if (sdp->sd_lockstruct.ls_ops->lm_cancel)
969 sdp->sd_lockstruct.ls_ops->lm_cancel(gl->gl_lock); 930 sdp->sd_lockstruct.ls_ops->lm_cancel(gl);
970 spin_lock(&gl->gl_spin); 931 spin_lock(&gl->gl_spin);
971 } 932 }
972 return; 933 return;
@@ -1051,7 +1012,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
1051 spin_lock(&gl->gl_spin); 1012 spin_lock(&gl->gl_spin);
1052 clear_bit(GLF_LOCK, &gl->gl_flags); 1013 clear_bit(GLF_LOCK, &gl->gl_flags);
1053 } 1014 }
1054 gl->gl_stamp = jiffies;
1055 if (list_empty(&gl->gl_holders) && 1015 if (list_empty(&gl->gl_holders) &&
1056 !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && 1016 !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
1057 !test_bit(GLF_DEMOTE, &gl->gl_flags)) 1017 !test_bit(GLF_DEMOTE, &gl->gl_flags))
@@ -1240,70 +1200,13 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs)
1240 gfs2_glock_dq_uninit(&ghs[x]); 1200 gfs2_glock_dq_uninit(&ghs[x]);
1241} 1201}
1242 1202
1243static int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp) 1203void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
1244{
1245 int error = -EIO;
1246 if (!sdp->sd_lockstruct.ls_ops->lm_hold_lvb)
1247 return 0;
1248 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
1249 error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
1250 return error;
1251}
1252
1253/**
1254 * gfs2_lvb_hold - attach a LVB from a glock
1255 * @gl: The glock in question
1256 *
1257 */
1258
1259int gfs2_lvb_hold(struct gfs2_glock *gl)
1260{
1261 int error;
1262
1263 if (!atomic_read(&gl->gl_lvb_count)) {
1264 error = gfs2_lm_hold_lvb(gl->gl_sbd, gl->gl_lock, &gl->gl_lvb);
1265 if (error)
1266 return error;
1267 gfs2_glock_hold(gl);
1268 }
1269 atomic_inc(&gl->gl_lvb_count);
1270
1271 return 0;
1272}
1273
1274/**
1275 * gfs2_lvb_unhold - detach a LVB from a glock
1276 * @gl: The glock in question
1277 *
1278 */
1279
1280void gfs2_lvb_unhold(struct gfs2_glock *gl)
1281{
1282 struct gfs2_sbd *sdp = gl->gl_sbd;
1283
1284 gfs2_glock_hold(gl);
1285 gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count) > 0);
1286 if (atomic_dec_and_test(&gl->gl_lvb_count)) {
1287 if (sdp->sd_lockstruct.ls_ops->lm_unhold_lvb)
1288 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(gl->gl_lock, gl->gl_lvb);
1289 gl->gl_lvb = NULL;
1290 gfs2_glock_put(gl);
1291 }
1292 gfs2_glock_put(gl);
1293}
1294
1295static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1296 unsigned int state)
1297{ 1204{
1298 struct gfs2_glock *gl;
1299 unsigned long delay = 0; 1205 unsigned long delay = 0;
1300 unsigned long holdtime; 1206 unsigned long holdtime;
1301 unsigned long now = jiffies; 1207 unsigned long now = jiffies;
1302 1208
1303 gl = gfs2_glock_find(sdp, name); 1209 gfs2_glock_hold(gl);
1304 if (!gl)
1305 return;
1306
1307 holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time; 1210 holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time;
1308 if (time_before(now, holdtime)) 1211 if (time_before(now, holdtime))
1309 delay = holdtime - now; 1212 delay = holdtime - now;
@@ -1317,74 +1220,33 @@ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1317 gfs2_glock_put(gl); 1220 gfs2_glock_put(gl);
1318} 1221}
1319 1222
1320static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
1321{
1322 struct gfs2_jdesc *jd;
1323
1324 spin_lock(&sdp->sd_jindex_spin);
1325 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
1326 if (jd->jd_jid != jid)
1327 continue;
1328 jd->jd_dirty = 1;
1329 break;
1330 }
1331 spin_unlock(&sdp->sd_jindex_spin);
1332}
1333
1334/** 1223/**
1335 * gfs2_glock_cb - Callback used by locking module 1224 * gfs2_glock_complete - Callback used by locking
1336 * @sdp: Pointer to the superblock 1225 * @gl: Pointer to the glock
1337 * @type: Type of callback 1226 * @ret: The return value from the dlm
1338 * @data: Type dependent data pointer
1339 * 1227 *
1340 * Called by the locking module when it wants to tell us something.
1341 * Either we need to drop a lock, one of our ASYNC requests completed, or
1342 * a journal from another client needs to be recovered.
1343 */ 1228 */
1344 1229
1345void gfs2_glock_cb(void *cb_data, unsigned int type, void *data) 1230void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
1346{ 1231{
1347 struct gfs2_sbd *sdp = cb_data; 1232 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
1348 1233 gl->gl_reply = ret;
1349 switch (type) { 1234 if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))) {
1350 case LM_CB_NEED_E: 1235 struct gfs2_holder *gh;
1351 blocking_cb(sdp, data, LM_ST_UNLOCKED); 1236 spin_lock(&gl->gl_spin);
1352 return; 1237 gh = find_first_waiter(gl);
1353 1238 if ((!(gh && (gh->gh_flags & LM_FLAG_NOEXP)) &&
1354 case LM_CB_NEED_D: 1239 (gl->gl_target != LM_ST_UNLOCKED)) ||
1355 blocking_cb(sdp, data, LM_ST_DEFERRED); 1240 ((ret & ~LM_OUT_ST_MASK) != 0))
1356 return; 1241 set_bit(GLF_FROZEN, &gl->gl_flags);
1357 1242 spin_unlock(&gl->gl_spin);
1358 case LM_CB_NEED_S: 1243 if (test_bit(GLF_FROZEN, &gl->gl_flags))
1359 blocking_cb(sdp, data, LM_ST_SHARED);
1360 return;
1361
1362 case LM_CB_ASYNC: {
1363 struct lm_async_cb *async = data;
1364 struct gfs2_glock *gl;
1365
1366 down_read(&gfs2_umount_flush_sem);
1367 gl = gfs2_glock_find(sdp, &async->lc_name);
1368 if (gfs2_assert_warn(sdp, gl))
1369 return; 1244 return;
1370 gl->gl_reply = async->lc_ret;
1371 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1372 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1373 gfs2_glock_put(gl);
1374 up_read(&gfs2_umount_flush_sem);
1375 return;
1376 }
1377
1378 case LM_CB_NEED_RECOVERY:
1379 gfs2_jdesc_make_dirty(sdp, *(unsigned int *)data);
1380 if (sdp->sd_recoverd_process)
1381 wake_up_process(sdp->sd_recoverd_process);
1382 return;
1383
1384 default:
1385 gfs2_assert_warn(sdp, 0);
1386 return;
1387 } 1245 }
1246 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1247 gfs2_glock_hold(gl);
1248 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1249 gfs2_glock_put(gl);
1388} 1250}
1389 1251
1390/** 1252/**
@@ -1515,6 +1377,25 @@ out:
1515 return has_entries; 1377 return has_entries;
1516} 1378}
1517 1379
1380
1381/**
1382 * thaw_glock - thaw out a glock which has an unprocessed reply waiting
1383 * @gl: The glock to thaw
1384 *
1385 * N.B. When we freeze a glock, we leave a ref to the glock outstanding,
1386 * so this has to result in the ref count being dropped by one.
1387 */
1388
1389static void thaw_glock(struct gfs2_glock *gl)
1390{
1391 if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))
1392 return;
1393 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1394 gfs2_glock_hold(gl);
1395 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1396 gfs2_glock_put(gl);
1397}
1398
1518/** 1399/**
1519 * clear_glock - look at a glock and see if we can free it from glock cache 1400 * clear_glock - look at a glock and see if we can free it from glock cache
1520 * @gl: the glock to look at 1401 * @gl: the glock to look at
@@ -1540,6 +1421,20 @@ static void clear_glock(struct gfs2_glock *gl)
1540} 1421}
1541 1422
1542/** 1423/**
1424 * gfs2_glock_thaw - Thaw any frozen glocks
1425 * @sdp: The super block
1426 *
1427 */
1428
1429void gfs2_glock_thaw(struct gfs2_sbd *sdp)
1430{
1431 unsigned x;
1432
1433 for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
1434 examine_bucket(thaw_glock, sdp, x);
1435}
1436
1437/**
1543 * gfs2_gl_hash_clear - Empty out the glock hash table 1438 * gfs2_gl_hash_clear - Empty out the glock hash table
1544 * @sdp: the filesystem 1439 * @sdp: the filesystem
1545 * @wait: wait until it's all gone 1440 * @wait: wait until it's all gone
@@ -1619,7 +1514,7 @@ static const char *hflags2str(char *buf, unsigned flags, unsigned long iflags)
1619 if (flags & LM_FLAG_NOEXP) 1514 if (flags & LM_FLAG_NOEXP)
1620 *p++ = 'e'; 1515 *p++ = 'e';
1621 if (flags & LM_FLAG_ANY) 1516 if (flags & LM_FLAG_ANY)
1622 *p++ = 'a'; 1517 *p++ = 'A';
1623 if (flags & LM_FLAG_PRIORITY) 1518 if (flags & LM_FLAG_PRIORITY)
1624 *p++ = 'p'; 1519 *p++ = 'p';
1625 if (flags & GL_ASYNC) 1520 if (flags & GL_ASYNC)
@@ -1683,6 +1578,10 @@ static const char *gflags2str(char *buf, const unsigned long *gflags)
1683 *p++ = 'i'; 1578 *p++ = 'i';
1684 if (test_bit(GLF_REPLY_PENDING, gflags)) 1579 if (test_bit(GLF_REPLY_PENDING, gflags))
1685 *p++ = 'r'; 1580 *p++ = 'r';
1581 if (test_bit(GLF_INITIAL, gflags))
1582 *p++ = 'I';
1583 if (test_bit(GLF_FROZEN, gflags))
1584 *p++ = 'F';
1686 *p = 0; 1585 *p = 0;
1687 return buf; 1586 return buf;
1688} 1587}
@@ -1717,14 +1616,13 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
1717 dtime *= 1000000/HZ; /* demote time in uSec */ 1616 dtime *= 1000000/HZ; /* demote time in uSec */
1718 if (!test_bit(GLF_DEMOTE, &gl->gl_flags)) 1617 if (!test_bit(GLF_DEMOTE, &gl->gl_flags))
1719 dtime = 0; 1618 dtime = 0;
1720 gfs2_print_dbg(seq, "G: s:%s n:%u/%llu f:%s t:%s d:%s/%llu l:%d a:%d r:%d\n", 1619 gfs2_print_dbg(seq, "G: s:%s n:%u/%llu f:%s t:%s d:%s/%llu a:%d r:%d\n",
1721 state2str(gl->gl_state), 1620 state2str(gl->gl_state),
1722 gl->gl_name.ln_type, 1621 gl->gl_name.ln_type,
1723 (unsigned long long)gl->gl_name.ln_number, 1622 (unsigned long long)gl->gl_name.ln_number,
1724 gflags2str(gflags_buf, &gl->gl_flags), 1623 gflags2str(gflags_buf, &gl->gl_flags),
1725 state2str(gl->gl_target), 1624 state2str(gl->gl_target),
1726 state2str(gl->gl_demote_state), dtime, 1625 state2str(gl->gl_demote_state), dtime,
1727 atomic_read(&gl->gl_lvb_count),
1728 atomic_read(&gl->gl_ail_count), 1626 atomic_read(&gl->gl_ail_count),
1729 atomic_read(&gl->gl_ref)); 1627 atomic_read(&gl->gl_ref));
1730 1628
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 543ec7ecfbd..a602a28f6f0 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -11,15 +11,130 @@
11#define __GLOCK_DOT_H__ 11#define __GLOCK_DOT_H__
12 12
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/parser.h>
14#include "incore.h" 15#include "incore.h"
15 16
16/* Flags for lock requests; used in gfs2_holder gh_flag field. 17/* Options for hostdata parser */
17 From lm_interface.h: 18
19enum {
20 Opt_jid,
21 Opt_id,
22 Opt_first,
23 Opt_nodir,
24 Opt_err,
25};
26
27/*
28 * lm_lockname types
29 */
30
31#define LM_TYPE_RESERVED 0x00
32#define LM_TYPE_NONDISK 0x01
33#define LM_TYPE_INODE 0x02
34#define LM_TYPE_RGRP 0x03
35#define LM_TYPE_META 0x04
36#define LM_TYPE_IOPEN 0x05
37#define LM_TYPE_FLOCK 0x06
38#define LM_TYPE_PLOCK 0x07
39#define LM_TYPE_QUOTA 0x08
40#define LM_TYPE_JOURNAL 0x09
41
42/*
43 * lm_lock() states
44 *
45 * SHARED is compatible with SHARED, not with DEFERRED or EX.
46 * DEFERRED is compatible with DEFERRED, not with SHARED or EX.
47 */
48
49#define LM_ST_UNLOCKED 0
50#define LM_ST_EXCLUSIVE 1
51#define LM_ST_DEFERRED 2
52#define LM_ST_SHARED 3
53
54/*
55 * lm_lock() flags
56 *
57 * LM_FLAG_TRY
58 * Don't wait to acquire the lock if it can't be granted immediately.
59 *
60 * LM_FLAG_TRY_1CB
61 * Send one blocking callback if TRY is set and the lock is not granted.
62 *
63 * LM_FLAG_NOEXP
64 * GFS sets this flag on lock requests it makes while doing journal recovery.
65 * These special requests should not be blocked due to the recovery like
66 * ordinary locks would be.
67 *
68 * LM_FLAG_ANY
69 * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may
70 * also be granted in SHARED. The preferred state is whichever is compatible
71 * with other granted locks, or the specified state if no other locks exist.
72 *
73 * LM_FLAG_PRIORITY
74 * Override fairness considerations. Suppose a lock is held in a shared state
75 * and there is a pending request for the deferred state. A shared lock
76 * request with the priority flag would be allowed to bypass the deferred
77 * request and directly join the other shared lock. A shared lock request
78 * without the priority flag might be forced to wait until the deferred
79 * requested had acquired and released the lock.
80 */
81
18#define LM_FLAG_TRY 0x00000001 82#define LM_FLAG_TRY 0x00000001
19#define LM_FLAG_TRY_1CB 0x00000002 83#define LM_FLAG_TRY_1CB 0x00000002
20#define LM_FLAG_NOEXP 0x00000004 84#define LM_FLAG_NOEXP 0x00000004
21#define LM_FLAG_ANY 0x00000008 85#define LM_FLAG_ANY 0x00000008
22#define LM_FLAG_PRIORITY 0x00000010 */ 86#define LM_FLAG_PRIORITY 0x00000010
87#define GL_ASYNC 0x00000040
88#define GL_EXACT 0x00000080
89#define GL_SKIP 0x00000100
90#define GL_ATIME 0x00000200
91#define GL_NOCACHE 0x00000400
92
93/*
94 * lm_lock() and lm_async_cb return flags
95 *
96 * LM_OUT_ST_MASK
97 * Masks the lower two bits of lock state in the returned value.
98 *
99 * LM_OUT_CANCELED
100 * The lock request was canceled.
101 *
102 * LM_OUT_ASYNC
103 * The result of the request will be returned in an LM_CB_ASYNC callback.
104 *
105 */
106
107#define LM_OUT_ST_MASK 0x00000003
108#define LM_OUT_CANCELED 0x00000008
109#define LM_OUT_ASYNC 0x00000080
110#define LM_OUT_ERROR 0x00000100
111
112/*
113 * lm_recovery_done() messages
114 */
115
116#define LM_RD_GAVEUP 308
117#define LM_RD_SUCCESS 309
118
119#define GLR_TRYFAILED 13
120
121struct lm_lockops {
122 const char *lm_proto_name;
123 int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname);
124 void (*lm_unmount) (struct gfs2_sbd *sdp);
125 void (*lm_withdraw) (struct gfs2_sbd *sdp);
126 void (*lm_put_lock) (struct kmem_cache *cachep, void *gl);
127 unsigned int (*lm_lock) (struct gfs2_glock *gl,
128 unsigned int req_state, unsigned int flags);
129 void (*lm_cancel) (struct gfs2_glock *gl);
130 const match_table_t *lm_tokens;
131};
132
133#define LM_FLAG_TRY 0x00000001
134#define LM_FLAG_TRY_1CB 0x00000002
135#define LM_FLAG_NOEXP 0x00000004
136#define LM_FLAG_ANY 0x00000008
137#define LM_FLAG_PRIORITY 0x00000010
23 138
24#define GL_ASYNC 0x00000040 139#define GL_ASYNC 0x00000040
25#define GL_EXACT 0x00000080 140#define GL_EXACT 0x00000080
@@ -128,10 +243,12 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
128int gfs2_lvb_hold(struct gfs2_glock *gl); 243int gfs2_lvb_hold(struct gfs2_glock *gl);
129void gfs2_lvb_unhold(struct gfs2_glock *gl); 244void gfs2_lvb_unhold(struct gfs2_glock *gl);
130 245
131void gfs2_glock_cb(void *cb_data, unsigned int type, void *data); 246void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
247void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
132void gfs2_reclaim_glock(struct gfs2_sbd *sdp); 248void gfs2_reclaim_glock(struct gfs2_sbd *sdp);
133void gfs2_gl_hash_clear(struct gfs2_sbd *sdp); 249void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
134void gfs2_glock_finish_truncate(struct gfs2_inode *ip); 250void gfs2_glock_finish_truncate(struct gfs2_inode *ip);
251void gfs2_glock_thaw(struct gfs2_sbd *sdp);
135 252
136int __init gfs2_glock_init(void); 253int __init gfs2_glock_init(void);
137void gfs2_glock_exit(void); 254void gfs2_glock_exit(void);
@@ -141,4 +258,6 @@ void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp);
141int gfs2_register_debugfs(void); 258int gfs2_register_debugfs(void);
142void gfs2_unregister_debugfs(void); 259void gfs2_unregister_debugfs(void);
143 260
261extern const struct lm_lockops gfs2_dlm_ops;
262
144#endif /* __GLOCK_DOT_H__ */ 263#endif /* __GLOCK_DOT_H__ */
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 8522d3aa64f..bf23a62aa92 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -12,7 +12,6 @@
12#include <linux/completion.h> 12#include <linux/completion.h>
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/lm_interface.h>
16#include <linux/bio.h> 15#include <linux/bio.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
@@ -38,20 +37,25 @@
38static void gfs2_ail_empty_gl(struct gfs2_glock *gl) 37static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
39{ 38{
40 struct gfs2_sbd *sdp = gl->gl_sbd; 39 struct gfs2_sbd *sdp = gl->gl_sbd;
41 unsigned int blocks;
42 struct list_head *head = &gl->gl_ail_list; 40 struct list_head *head = &gl->gl_ail_list;
43 struct gfs2_bufdata *bd; 41 struct gfs2_bufdata *bd;
44 struct buffer_head *bh; 42 struct buffer_head *bh;
45 int error; 43 struct gfs2_trans tr;
46 44
47 blocks = atomic_read(&gl->gl_ail_count); 45 memset(&tr, 0, sizeof(tr));
48 if (!blocks) 46 tr.tr_revokes = atomic_read(&gl->gl_ail_count);
49 return;
50 47
51 error = gfs2_trans_begin(sdp, 0, blocks); 48 if (!tr.tr_revokes)
52 if (gfs2_assert_withdraw(sdp, !error))
53 return; 49 return;
54 50
51 /* A shortened, inline version of gfs2_trans_begin() */
52 tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64));
53 tr.tr_ip = (unsigned long)__builtin_return_address(0);
54 INIT_LIST_HEAD(&tr.tr_list_buf);
55 gfs2_log_reserve(sdp, tr.tr_reserved);
56 BUG_ON(current->journal_info);
57 current->journal_info = &tr;
58
55 gfs2_log_lock(sdp); 59 gfs2_log_lock(sdp);
56 while (!list_empty(head)) { 60 while (!list_empty(head)) {
57 bd = list_entry(head->next, struct gfs2_bufdata, 61 bd = list_entry(head->next, struct gfs2_bufdata,
@@ -72,29 +76,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
72} 76}
73 77
74/** 78/**
75 * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock 79 * rgrp_go_sync - sync out the metadata for this glock
76 * @gl: the glock
77 *
78 */
79
80static void gfs2_pte_inval(struct gfs2_glock *gl)
81{
82 struct gfs2_inode *ip;
83 struct inode *inode;
84
85 ip = gl->gl_object;
86 inode = &ip->i_inode;
87 if (!ip || !S_ISREG(inode->i_mode))
88 return;
89
90 unmap_shared_mapping_range(inode->i_mapping, 0, 0);
91 if (test_bit(GIF_SW_PAGED, &ip->i_flags))
92 set_bit(GLF_DIRTY, &gl->gl_flags);
93
94}
95
96/**
97 * meta_go_sync - sync out the metadata for this glock
98 * @gl: the glock 80 * @gl: the glock
99 * 81 *
100 * Called when demoting or unlocking an EX glock. We must flush 82 * Called when demoting or unlocking an EX glock. We must flush
@@ -102,36 +84,42 @@ static void gfs2_pte_inval(struct gfs2_glock *gl)
102 * not return to caller to demote/unlock the glock until I/O is complete. 84 * not return to caller to demote/unlock the glock until I/O is complete.
103 */ 85 */
104 86
105static void meta_go_sync(struct gfs2_glock *gl) 87static void rgrp_go_sync(struct gfs2_glock *gl)
106{ 88{
107 if (gl->gl_state != LM_ST_EXCLUSIVE) 89 struct address_space *metamapping = gl->gl_aspace->i_mapping;
90 int error;
91
92 if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
108 return; 93 return;
94 BUG_ON(gl->gl_state != LM_ST_EXCLUSIVE);
109 95
110 if (test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) { 96 gfs2_log_flush(gl->gl_sbd, gl);
111 gfs2_log_flush(gl->gl_sbd, gl); 97 filemap_fdatawrite(metamapping);
112 gfs2_meta_sync(gl); 98 error = filemap_fdatawait(metamapping);
113 gfs2_ail_empty_gl(gl); 99 mapping_set_error(metamapping, error);
114 } 100 gfs2_ail_empty_gl(gl);
115} 101}
116 102
117/** 103/**
118 * meta_go_inval - invalidate the metadata for this glock 104 * rgrp_go_inval - invalidate the metadata for this glock
119 * @gl: the glock 105 * @gl: the glock
120 * @flags: 106 * @flags:
121 * 107 *
108 * We never used LM_ST_DEFERRED with resource groups, so that we
109 * should always see the metadata flag set here.
110 *
122 */ 111 */
123 112
124static void meta_go_inval(struct gfs2_glock *gl, int flags) 113static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
125{ 114{
126 if (!(flags & DIO_METADATA)) 115 struct address_space *mapping = gl->gl_aspace->i_mapping;
127 return;
128 116
129 gfs2_meta_inval(gl); 117 BUG_ON(!(flags & DIO_METADATA));
130 if (gl->gl_object == GFS2_I(gl->gl_sbd->sd_rindex)) 118 gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count));
131 gl->gl_sbd->sd_rindex_uptodate = 0; 119 truncate_inode_pages(mapping, 0);
132 else if (gl->gl_ops == &gfs2_rgrp_glops && gl->gl_object) {
133 struct gfs2_rgrpd *rgd = (struct gfs2_rgrpd *)gl->gl_object;
134 120
121 if (gl->gl_object) {
122 struct gfs2_rgrpd *rgd = (struct gfs2_rgrpd *)gl->gl_object;
135 rgd->rd_flags &= ~GFS2_RDF_UPTODATE; 123 rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
136 } 124 }
137} 125}
@@ -148,48 +136,54 @@ static void inode_go_sync(struct gfs2_glock *gl)
148 struct address_space *metamapping = gl->gl_aspace->i_mapping; 136 struct address_space *metamapping = gl->gl_aspace->i_mapping;
149 int error; 137 int error;
150 138
151 if (gl->gl_state != LM_ST_UNLOCKED)
152 gfs2_pte_inval(gl);
153 if (gl->gl_state != LM_ST_EXCLUSIVE)
154 return;
155
156 if (ip && !S_ISREG(ip->i_inode.i_mode)) 139 if (ip && !S_ISREG(ip->i_inode.i_mode))
157 ip = NULL; 140 ip = NULL;
141 if (ip && test_and_clear_bit(GIF_SW_PAGED, &ip->i_flags))
142 unmap_shared_mapping_range(ip->i_inode.i_mapping, 0, 0);
143 if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
144 return;
158 145
159 if (test_bit(GLF_DIRTY, &gl->gl_flags)) { 146 BUG_ON(gl->gl_state != LM_ST_EXCLUSIVE);
160 gfs2_log_flush(gl->gl_sbd, gl); 147
161 filemap_fdatawrite(metamapping); 148 gfs2_log_flush(gl->gl_sbd, gl);
162 if (ip) { 149 filemap_fdatawrite(metamapping);
163 struct address_space *mapping = ip->i_inode.i_mapping; 150 if (ip) {
164 filemap_fdatawrite(mapping); 151 struct address_space *mapping = ip->i_inode.i_mapping;
165 error = filemap_fdatawait(mapping); 152 filemap_fdatawrite(mapping);
166 mapping_set_error(mapping, error); 153 error = filemap_fdatawait(mapping);
167 } 154 mapping_set_error(mapping, error);
168 error = filemap_fdatawait(metamapping);
169 mapping_set_error(metamapping, error);
170 clear_bit(GLF_DIRTY, &gl->gl_flags);
171 gfs2_ail_empty_gl(gl);
172 } 155 }
156 error = filemap_fdatawait(metamapping);
157 mapping_set_error(metamapping, error);
158 gfs2_ail_empty_gl(gl);
173} 159}
174 160
175/** 161/**
176 * inode_go_inval - prepare a inode glock to be released 162 * inode_go_inval - prepare a inode glock to be released
177 * @gl: the glock 163 * @gl: the glock
178 * @flags: 164 * @flags:
165 *
166 * Normally we invlidate everything, but if we are moving into
167 * LM_ST_DEFERRED from LM_ST_SHARED or LM_ST_EXCLUSIVE then we
168 * can keep hold of the metadata, since it won't have changed.
179 * 169 *
180 */ 170 */
181 171
182static void inode_go_inval(struct gfs2_glock *gl, int flags) 172static void inode_go_inval(struct gfs2_glock *gl, int flags)
183{ 173{
184 struct gfs2_inode *ip = gl->gl_object; 174 struct gfs2_inode *ip = gl->gl_object;
185 int meta = (flags & DIO_METADATA);
186 175
187 if (meta) { 176 gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count));
188 gfs2_meta_inval(gl); 177
178 if (flags & DIO_METADATA) {
179 struct address_space *mapping = gl->gl_aspace->i_mapping;
180 truncate_inode_pages(mapping, 0);
189 if (ip) 181 if (ip)
190 set_bit(GIF_INVALID, &ip->i_flags); 182 set_bit(GIF_INVALID, &ip->i_flags);
191 } 183 }
192 184
185 if (ip == GFS2_I(gl->gl_sbd->sd_rindex))
186 gl->gl_sbd->sd_rindex_uptodate = 0;
193 if (ip && S_ISREG(ip->i_inode.i_mode)) 187 if (ip && S_ISREG(ip->i_inode.i_mode))
194 truncate_inode_pages(ip->i_inode.i_mapping, 0); 188 truncate_inode_pages(ip->i_inode.i_mapping, 0);
195} 189}
@@ -390,20 +384,7 @@ static int trans_go_demote_ok(const struct gfs2_glock *gl)
390 return 0; 384 return 0;
391} 385}
392 386
393/**
394 * quota_go_demote_ok - Check to see if it's ok to unlock a quota glock
395 * @gl: the glock
396 *
397 * Returns: 1 if it's ok
398 */
399
400static int quota_go_demote_ok(const struct gfs2_glock *gl)
401{
402 return !atomic_read(&gl->gl_lvb_count);
403}
404
405const struct gfs2_glock_operations gfs2_meta_glops = { 387const struct gfs2_glock_operations gfs2_meta_glops = {
406 .go_xmote_th = meta_go_sync,
407 .go_type = LM_TYPE_META, 388 .go_type = LM_TYPE_META,
408}; 389};
409 390
@@ -418,8 +399,8 @@ const struct gfs2_glock_operations gfs2_inode_glops = {
418}; 399};
419 400
420const struct gfs2_glock_operations gfs2_rgrp_glops = { 401const struct gfs2_glock_operations gfs2_rgrp_glops = {
421 .go_xmote_th = meta_go_sync, 402 .go_xmote_th = rgrp_go_sync,
422 .go_inval = meta_go_inval, 403 .go_inval = rgrp_go_inval,
423 .go_demote_ok = rgrp_go_demote_ok, 404 .go_demote_ok = rgrp_go_demote_ok,
424 .go_lock = rgrp_go_lock, 405 .go_lock = rgrp_go_lock,
425 .go_unlock = rgrp_go_unlock, 406 .go_unlock = rgrp_go_unlock,
@@ -448,7 +429,6 @@ const struct gfs2_glock_operations gfs2_nondisk_glops = {
448}; 429};
449 430
450const struct gfs2_glock_operations gfs2_quota_glops = { 431const struct gfs2_glock_operations gfs2_quota_glops = {
451 .go_demote_ok = quota_go_demote_ok,
452 .go_type = LM_TYPE_QUOTA, 432 .go_type = LM_TYPE_QUOTA,
453}; 433};
454 434
@@ -456,3 +436,15 @@ const struct gfs2_glock_operations gfs2_journal_glops = {
456 .go_type = LM_TYPE_JOURNAL, 436 .go_type = LM_TYPE_JOURNAL,
457}; 437};
458 438
439const struct gfs2_glock_operations *gfs2_glops_list[] = {
440 [LM_TYPE_META] = &gfs2_meta_glops,
441 [LM_TYPE_INODE] = &gfs2_inode_glops,
442 [LM_TYPE_RGRP] = &gfs2_rgrp_glops,
443 [LM_TYPE_NONDISK] = &gfs2_trans_glops,
444 [LM_TYPE_IOPEN] = &gfs2_iopen_glops,
445 [LM_TYPE_FLOCK] = &gfs2_flock_glops,
446 [LM_TYPE_NONDISK] = &gfs2_nondisk_glops,
447 [LM_TYPE_QUOTA] = &gfs2_quota_glops,
448 [LM_TYPE_JOURNAL] = &gfs2_journal_glops,
449};
450
diff --git a/fs/gfs2/glops.h b/fs/gfs2/glops.h
index a1d9b5b024e..b3aa2e3210f 100644
--- a/fs/gfs2/glops.h
+++ b/fs/gfs2/glops.h
@@ -21,5 +21,6 @@ extern const struct gfs2_glock_operations gfs2_flock_glops;
21extern const struct gfs2_glock_operations gfs2_nondisk_glops; 21extern const struct gfs2_glock_operations gfs2_nondisk_glops;
22extern const struct gfs2_glock_operations gfs2_quota_glops; 22extern const struct gfs2_glock_operations gfs2_quota_glops;
23extern const struct gfs2_glock_operations gfs2_journal_glops; 23extern const struct gfs2_glock_operations gfs2_journal_glops;
24extern const struct gfs2_glock_operations *gfs2_glops_list[];
24 25
25#endif /* __GLOPS_DOT_H__ */ 26#endif /* __GLOPS_DOT_H__ */
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 608849d0002..399d1b97804 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -12,6 +12,8 @@
12 12
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/workqueue.h> 14#include <linux/workqueue.h>
15#include <linux/dlm.h>
16#include <linux/buffer_head.h>
15 17
16#define DIO_WAIT 0x00000010 18#define DIO_WAIT 0x00000010
17#define DIO_METADATA 0x00000020 19#define DIO_METADATA 0x00000020
@@ -26,6 +28,7 @@ struct gfs2_trans;
26struct gfs2_ail; 28struct gfs2_ail;
27struct gfs2_jdesc; 29struct gfs2_jdesc;
28struct gfs2_sbd; 30struct gfs2_sbd;
31struct lm_lockops;
29 32
30typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret); 33typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret);
31 34
@@ -121,6 +124,28 @@ struct gfs2_bufdata {
121 struct list_head bd_ail_gl_list; 124 struct list_head bd_ail_gl_list;
122}; 125};
123 126
127/*
128 * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a
129 * prefix of lock_dlm_ gets awkward.
130 */
131
132#define GDLM_STRNAME_BYTES 25
133#define GDLM_LVB_SIZE 32
134
135enum {
136 DFL_BLOCK_LOCKS = 0,
137};
138
139struct lm_lockname {
140 u64 ln_number;
141 unsigned int ln_type;
142};
143
144#define lm_name_equal(name1, name2) \
145 (((name1)->ln_number == (name2)->ln_number) && \
146 ((name1)->ln_type == (name2)->ln_type))
147
148
124struct gfs2_glock_operations { 149struct gfs2_glock_operations {
125 void (*go_xmote_th) (struct gfs2_glock *gl); 150 void (*go_xmote_th) (struct gfs2_glock *gl);
126 int (*go_xmote_bh) (struct gfs2_glock *gl, struct gfs2_holder *gh); 151 int (*go_xmote_bh) (struct gfs2_glock *gl, struct gfs2_holder *gh);
@@ -162,6 +187,8 @@ enum {
162 GLF_LFLUSH = 7, 187 GLF_LFLUSH = 7,
163 GLF_INVALIDATE_IN_PROGRESS = 8, 188 GLF_INVALIDATE_IN_PROGRESS = 8,
164 GLF_REPLY_PENDING = 9, 189 GLF_REPLY_PENDING = 9,
190 GLF_INITIAL = 10,
191 GLF_FROZEN = 11,
165}; 192};
166 193
167struct gfs2_glock { 194struct gfs2_glock {
@@ -176,16 +203,15 @@ struct gfs2_glock {
176 unsigned int gl_target; 203 unsigned int gl_target;
177 unsigned int gl_reply; 204 unsigned int gl_reply;
178 unsigned int gl_hash; 205 unsigned int gl_hash;
206 unsigned int gl_req;
179 unsigned int gl_demote_state; /* state requested by remote node */ 207 unsigned int gl_demote_state; /* state requested by remote node */
180 unsigned long gl_demote_time; /* time of first demote request */ 208 unsigned long gl_demote_time; /* time of first demote request */
181 struct list_head gl_holders; 209 struct list_head gl_holders;
182 210
183 const struct gfs2_glock_operations *gl_ops; 211 const struct gfs2_glock_operations *gl_ops;
184 void *gl_lock; 212 char gl_strname[GDLM_STRNAME_BYTES];
185 char *gl_lvb; 213 struct dlm_lksb gl_lksb;
186 atomic_t gl_lvb_count; 214 char gl_lvb[32];
187
188 unsigned long gl_stamp;
189 unsigned long gl_tchange; 215 unsigned long gl_tchange;
190 void *gl_object; 216 void *gl_object;
191 217
@@ -283,7 +309,9 @@ enum {
283 309
284struct gfs2_quota_data { 310struct gfs2_quota_data {
285 struct list_head qd_list; 311 struct list_head qd_list;
286 unsigned int qd_count; 312 struct list_head qd_reclaim;
313
314 atomic_t qd_count;
287 315
288 u32 qd_id; 316 u32 qd_id;
289 unsigned long qd_flags; /* QDF_... */ 317 unsigned long qd_flags; /* QDF_... */
@@ -303,7 +331,6 @@ struct gfs2_quota_data {
303 331
304 u64 qd_sync_gen; 332 u64 qd_sync_gen;
305 unsigned long qd_last_warn; 333 unsigned long qd_last_warn;
306 unsigned long qd_last_touched;
307}; 334};
308 335
309struct gfs2_trans { 336struct gfs2_trans {
@@ -390,7 +417,7 @@ struct gfs2_args {
390 unsigned int ar_suiddir:1; /* suiddir support */ 417 unsigned int ar_suiddir:1; /* suiddir support */
391 unsigned int ar_data:2; /* ordered/writeback */ 418 unsigned int ar_data:2; /* ordered/writeback */
392 unsigned int ar_meta:1; /* mount metafs */ 419 unsigned int ar_meta:1; /* mount metafs */
393 unsigned int ar_num_glockd; /* Number of glockd threads */ 420 unsigned int ar_discard:1; /* discard requests */
394}; 421};
395 422
396struct gfs2_tune { 423struct gfs2_tune {
@@ -406,7 +433,6 @@ struct gfs2_tune {
406 unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */ 433 unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */
407 unsigned int gt_quota_scale_num; /* Numerator */ 434 unsigned int gt_quota_scale_num; /* Numerator */
408 unsigned int gt_quota_scale_den; /* Denominator */ 435 unsigned int gt_quota_scale_den; /* Denominator */
409 unsigned int gt_quota_cache_secs;
410 unsigned int gt_quota_quantum; /* Secs between syncs to quota file */ 436 unsigned int gt_quota_quantum; /* Secs between syncs to quota file */
411 unsigned int gt_new_files_jdata; 437 unsigned int gt_new_files_jdata;
412 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */ 438 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */
@@ -445,6 +471,31 @@ struct gfs2_sb_host {
445 471
446 char sb_lockproto[GFS2_LOCKNAME_LEN]; 472 char sb_lockproto[GFS2_LOCKNAME_LEN];
447 char sb_locktable[GFS2_LOCKNAME_LEN]; 473 char sb_locktable[GFS2_LOCKNAME_LEN];
474 u8 sb_uuid[16];
475};
476
477/*
478 * lm_mount() return values
479 *
480 * ls_jid - the journal ID this node should use
481 * ls_first - this node is the first to mount the file system
482 * ls_lockspace - lock module's context for this file system
483 * ls_ops - lock module's functions
484 */
485
486struct lm_lockstruct {
487 u32 ls_id;
488 unsigned int ls_jid;
489 unsigned int ls_first;
490 unsigned int ls_first_done;
491 unsigned int ls_nodir;
492 const struct lm_lockops *ls_ops;
493 unsigned long ls_flags;
494 dlm_lockspace_t *ls_dlm;
495
496 int ls_recover_jid;
497 int ls_recover_jid_done;
498 int ls_recover_jid_status;
448}; 499};
449 500
450struct gfs2_sbd { 501struct gfs2_sbd {
@@ -520,7 +571,6 @@ struct gfs2_sbd {
520 spinlock_t sd_jindex_spin; 571 spinlock_t sd_jindex_spin;
521 struct mutex sd_jindex_mutex; 572 struct mutex sd_jindex_mutex;
522 unsigned int sd_journals; 573 unsigned int sd_journals;
523 unsigned long sd_jindex_refresh_time;
524 574
525 struct gfs2_jdesc *sd_jdesc; 575 struct gfs2_jdesc *sd_jdesc;
526 struct gfs2_holder sd_journal_gh; 576 struct gfs2_holder sd_journal_gh;
@@ -540,7 +590,6 @@ struct gfs2_sbd {
540 590
541 struct list_head sd_quota_list; 591 struct list_head sd_quota_list;
542 atomic_t sd_quota_count; 592 atomic_t sd_quota_count;
543 spinlock_t sd_quota_spin;
544 struct mutex sd_quota_mutex; 593 struct mutex sd_quota_mutex;
545 wait_queue_head_t sd_quota_wait; 594 wait_queue_head_t sd_quota_wait;
546 struct list_head sd_trunc_list; 595 struct list_head sd_trunc_list;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 3b87c188da4..7b277d44915 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -16,7 +16,6 @@
16#include <linux/sort.h> 16#include <linux/sort.h>
17#include <linux/gfs2_ondisk.h> 17#include <linux/gfs2_ondisk.h>
18#include <linux/crc32.h> 18#include <linux/crc32.h>
19#include <linux/lm_interface.h>
20#include <linux/security.h> 19#include <linux/security.h>
21#include <linux/time.h> 20#include <linux/time.h>
22 21
@@ -137,16 +136,16 @@ void gfs2_set_iop(struct inode *inode)
137 136
138 if (S_ISREG(mode)) { 137 if (S_ISREG(mode)) {
139 inode->i_op = &gfs2_file_iops; 138 inode->i_op = &gfs2_file_iops;
140 if (sdp->sd_args.ar_localflocks) 139 if (gfs2_localflocks(sdp))
141 inode->i_fop = &gfs2_file_fops_nolock; 140 inode->i_fop = gfs2_file_fops_nolock;
142 else 141 else
143 inode->i_fop = &gfs2_file_fops; 142 inode->i_fop = gfs2_file_fops;
144 } else if (S_ISDIR(mode)) { 143 } else if (S_ISDIR(mode)) {
145 inode->i_op = &gfs2_dir_iops; 144 inode->i_op = &gfs2_dir_iops;
146 if (sdp->sd_args.ar_localflocks) 145 if (gfs2_localflocks(sdp))
147 inode->i_fop = &gfs2_dir_fops_nolock; 146 inode->i_fop = gfs2_dir_fops_nolock;
148 else 147 else
149 inode->i_fop = &gfs2_dir_fops; 148 inode->i_fop = gfs2_dir_fops;
150 } else if (S_ISLNK(mode)) { 149 } else if (S_ISLNK(mode)) {
151 inode->i_op = &gfs2_symlink_iops; 150 inode->i_op = &gfs2_symlink_iops;
152 } else { 151 } else {
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index d5329364cdf..dca4fee3078 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -101,12 +101,26 @@ void gfs2_dinode_print(const struct gfs2_inode *ip);
101extern const struct inode_operations gfs2_file_iops; 101extern const struct inode_operations gfs2_file_iops;
102extern const struct inode_operations gfs2_dir_iops; 102extern const struct inode_operations gfs2_dir_iops;
103extern const struct inode_operations gfs2_symlink_iops; 103extern const struct inode_operations gfs2_symlink_iops;
104extern const struct file_operations gfs2_file_fops; 104extern const struct file_operations *gfs2_file_fops_nolock;
105extern const struct file_operations gfs2_dir_fops; 105extern const struct file_operations *gfs2_dir_fops_nolock;
106extern const struct file_operations gfs2_file_fops_nolock;
107extern const struct file_operations gfs2_dir_fops_nolock;
108 106
109extern void gfs2_set_inode_flags(struct inode *inode); 107extern void gfs2_set_inode_flags(struct inode *inode);
108
109#ifdef CONFIG_GFS2_FS_LOCKING_DLM
110extern const struct file_operations *gfs2_file_fops;
111extern const struct file_operations *gfs2_dir_fops;
112static inline int gfs2_localflocks(const struct gfs2_sbd *sdp)
113{
114 return sdp->sd_args.ar_localflocks;
115}
116#else /* Single node only */
117#define gfs2_file_fops NULL
118#define gfs2_dir_fops NULL
119static inline int gfs2_localflocks(const struct gfs2_sbd *sdp)
120{
121 return 1;
122}
123#endif /* CONFIG_GFS2_FS_LOCKING_DLM */
110 124
111#endif /* __INODE_DOT_H__ */ 125#endif /* __INODE_DOT_H__ */
112 126
diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c
new file mode 100644
index 00000000000..46df988323b
--- /dev/null
+++ b/fs/gfs2/lock_dlm.c
@@ -0,0 +1,241 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/fs.h>
11#include <linux/dlm.h>
12#include <linux/types.h>
13#include <linux/gfs2_ondisk.h>
14
15#include "incore.h"
16#include "glock.h"
17#include "util.h"
18
19
20static void gdlm_ast(void *arg)
21{
22 struct gfs2_glock *gl = arg;
23 unsigned ret = gl->gl_state;
24
25 BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED);
26
27 if (gl->gl_lksb.sb_flags & DLM_SBF_VALNOTVALID)
28 memset(gl->gl_lvb, 0, GDLM_LVB_SIZE);
29
30 switch (gl->gl_lksb.sb_status) {
31 case -DLM_EUNLOCK: /* Unlocked, so glock can be freed */
32 kmem_cache_free(gfs2_glock_cachep, gl);
33 return;
34 case -DLM_ECANCEL: /* Cancel while getting lock */
35 ret |= LM_OUT_CANCELED;
36 goto out;
37 case -EAGAIN: /* Try lock fails */
38 goto out;
39 case -EINVAL: /* Invalid */
40 case -ENOMEM: /* Out of memory */
41 ret |= LM_OUT_ERROR;
42 goto out;
43 case 0: /* Success */
44 break;
45 default: /* Something unexpected */
46 BUG();
47 }
48
49 ret = gl->gl_req;
50 if (gl->gl_lksb.sb_flags & DLM_SBF_ALTMODE) {
51 if (gl->gl_req == LM_ST_SHARED)
52 ret = LM_ST_DEFERRED;
53 else if (gl->gl_req == LM_ST_DEFERRED)
54 ret = LM_ST_SHARED;
55 else
56 BUG();
57 }
58
59 set_bit(GLF_INITIAL, &gl->gl_flags);
60 gfs2_glock_complete(gl, ret);
61 return;
62out:
63 if (!test_bit(GLF_INITIAL, &gl->gl_flags))
64 gl->gl_lksb.sb_lkid = 0;
65 gfs2_glock_complete(gl, ret);
66}
67
68static void gdlm_bast(void *arg, int mode)
69{
70 struct gfs2_glock *gl = arg;
71
72 switch (mode) {
73 case DLM_LOCK_EX:
74 gfs2_glock_cb(gl, LM_ST_UNLOCKED);
75 break;
76 case DLM_LOCK_CW:
77 gfs2_glock_cb(gl, LM_ST_DEFERRED);
78 break;
79 case DLM_LOCK_PR:
80 gfs2_glock_cb(gl, LM_ST_SHARED);
81 break;
82 default:
83 printk(KERN_ERR "unknown bast mode %d", mode);
84 BUG();
85 }
86}
87
88/* convert gfs lock-state to dlm lock-mode */
89
90static int make_mode(const unsigned int lmstate)
91{
92 switch (lmstate) {
93 case LM_ST_UNLOCKED:
94 return DLM_LOCK_NL;
95 case LM_ST_EXCLUSIVE:
96 return DLM_LOCK_EX;
97 case LM_ST_DEFERRED:
98 return DLM_LOCK_CW;
99 case LM_ST_SHARED:
100 return DLM_LOCK_PR;
101 }
102 printk(KERN_ERR "unknown LM state %d", lmstate);
103 BUG();
104 return -1;
105}
106
107static u32 make_flags(const u32 lkid, const unsigned int gfs_flags,
108 const int req)
109{
110 u32 lkf = 0;
111
112 if (gfs_flags & LM_FLAG_TRY)
113 lkf |= DLM_LKF_NOQUEUE;
114
115 if (gfs_flags & LM_FLAG_TRY_1CB) {
116 lkf |= DLM_LKF_NOQUEUE;
117 lkf |= DLM_LKF_NOQUEUEBAST;
118 }
119
120 if (gfs_flags & LM_FLAG_PRIORITY) {
121 lkf |= DLM_LKF_NOORDER;
122 lkf |= DLM_LKF_HEADQUE;
123 }
124
125 if (gfs_flags & LM_FLAG_ANY) {
126 if (req == DLM_LOCK_PR)
127 lkf |= DLM_LKF_ALTCW;
128 else if (req == DLM_LOCK_CW)
129 lkf |= DLM_LKF_ALTPR;
130 else
131 BUG();
132 }
133
134 if (lkid != 0)
135 lkf |= DLM_LKF_CONVERT;
136
137 lkf |= DLM_LKF_VALBLK;
138
139 return lkf;
140}
141
142static unsigned int gdlm_lock(struct gfs2_glock *gl,
143 unsigned int req_state, unsigned int flags)
144{
145 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
146 int error;
147 int req;
148 u32 lkf;
149
150 gl->gl_req = req_state;
151 req = make_mode(req_state);
152 lkf = make_flags(gl->gl_lksb.sb_lkid, flags, req);
153
154 /*
155 * Submit the actual lock request.
156 */
157
158 error = dlm_lock(ls->ls_dlm, req, &gl->gl_lksb, lkf, gl->gl_strname,
159 GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast);
160 if (error == -EAGAIN)
161 return 0;
162 if (error)
163 return LM_OUT_ERROR;
164 return LM_OUT_ASYNC;
165}
166
167static void gdlm_put_lock(struct kmem_cache *cachep, void *ptr)
168{
169 struct gfs2_glock *gl = ptr;
170 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
171 int error;
172
173 if (gl->gl_lksb.sb_lkid == 0) {
174 kmem_cache_free(cachep, gl);
175 return;
176 }
177
178 error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_VALBLK,
179 NULL, gl);
180 if (error) {
181 printk(KERN_ERR "gdlm_unlock %x,%llx err=%d\n",
182 gl->gl_name.ln_type,
183 (unsigned long long)gl->gl_name.ln_number, error);
184 return;
185 }
186}
187
188static void gdlm_cancel(struct gfs2_glock *gl)
189{
190 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
191 dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_CANCEL, NULL, gl);
192}
193
194static int gdlm_mount(struct gfs2_sbd *sdp, const char *fsname)
195{
196 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
197 int error;
198
199 if (fsname == NULL) {
200 fs_info(sdp, "no fsname found\n");
201 return -EINVAL;
202 }
203
204 error = dlm_new_lockspace(fsname, strlen(fsname), &ls->ls_dlm,
205 DLM_LSFL_FS | DLM_LSFL_NEWEXCL |
206 (ls->ls_nodir ? DLM_LSFL_NODIR : 0),
207 GDLM_LVB_SIZE);
208 if (error)
209 printk(KERN_ERR "dlm_new_lockspace error %d", error);
210
211 return error;
212}
213
214static void gdlm_unmount(struct gfs2_sbd *sdp)
215{
216 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
217
218 if (ls->ls_dlm) {
219 dlm_release_lockspace(ls->ls_dlm, 2);
220 ls->ls_dlm = NULL;
221 }
222}
223
224static const match_table_t dlm_tokens = {
225 { Opt_jid, "jid=%d"},
226 { Opt_id, "id=%d"},
227 { Opt_first, "first=%d"},
228 { Opt_nodir, "nodir=%d"},
229 { Opt_err, NULL },
230};
231
232const struct lm_lockops gfs2_dlm_ops = {
233 .lm_proto_name = "lock_dlm",
234 .lm_mount = gdlm_mount,
235 .lm_unmount = gdlm_unmount,
236 .lm_put_lock = gdlm_put_lock,
237 .lm_lock = gdlm_lock,
238 .lm_cancel = gdlm_cancel,
239 .lm_tokens = &dlm_tokens,
240};
241
diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c
deleted file mode 100644
index 523243a13a2..00000000000
--- a/fs/gfs2/locking.c
+++ /dev/null
@@ -1,232 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/string.h>
13#include <linux/slab.h>
14#include <linux/wait.h>
15#include <linux/sched.h>
16#include <linux/kmod.h>
17#include <linux/fs.h>
18#include <linux/delay.h>
19#include <linux/lm_interface.h>
20
21struct lmh_wrapper {
22 struct list_head lw_list;
23 const struct lm_lockops *lw_ops;
24};
25
26static int nolock_mount(char *table_name, char *host_data,
27 lm_callback_t cb, void *cb_data,
28 unsigned int min_lvb_size, int flags,
29 struct lm_lockstruct *lockstruct,
30 struct kobject *fskobj);
31
32/* List of registered low-level locking protocols. A file system selects one
33 of them by name at mount time, e.g. lock_nolock, lock_dlm. */
34
35static const struct lm_lockops nolock_ops = {
36 .lm_proto_name = "lock_nolock",
37 .lm_mount = nolock_mount,
38};
39
40static struct lmh_wrapper nolock_proto = {
41 .lw_list = LIST_HEAD_INIT(nolock_proto.lw_list),
42 .lw_ops = &nolock_ops,
43};
44
45static LIST_HEAD(lmh_list);
46static DEFINE_MUTEX(lmh_lock);
47
48static int nolock_mount(char *table_name, char *host_data,
49 lm_callback_t cb, void *cb_data,
50 unsigned int min_lvb_size, int flags,
51 struct lm_lockstruct *lockstruct,
52 struct kobject *fskobj)
53{
54 char *c;
55 unsigned int jid;
56
57 c = strstr(host_data, "jid=");
58 if (!c)
59 jid = 0;
60 else {
61 c += 4;
62 sscanf(c, "%u", &jid);
63 }
64
65 lockstruct->ls_jid = jid;
66 lockstruct->ls_first = 1;
67 lockstruct->ls_lvb_size = min_lvb_size;
68 lockstruct->ls_ops = &nolock_ops;
69 lockstruct->ls_flags = LM_LSFLAG_LOCAL;
70
71 return 0;
72}
73
74/**
75 * gfs2_register_lockproto - Register a low-level locking protocol
76 * @proto: the protocol definition
77 *
78 * Returns: 0 on success, -EXXX on failure
79 */
80
81int gfs2_register_lockproto(const struct lm_lockops *proto)
82{
83 struct lmh_wrapper *lw;
84
85 mutex_lock(&lmh_lock);
86
87 list_for_each_entry(lw, &lmh_list, lw_list) {
88 if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) {
89 mutex_unlock(&lmh_lock);
90 printk(KERN_INFO "GFS2: protocol %s already exists\n",
91 proto->lm_proto_name);
92 return -EEXIST;
93 }
94 }
95
96 lw = kzalloc(sizeof(struct lmh_wrapper), GFP_KERNEL);
97 if (!lw) {
98 mutex_unlock(&lmh_lock);
99 return -ENOMEM;
100 }
101
102 lw->lw_ops = proto;
103 list_add(&lw->lw_list, &lmh_list);
104
105 mutex_unlock(&lmh_lock);
106
107 return 0;
108}
109
110/**
111 * gfs2_unregister_lockproto - Unregister a low-level locking protocol
112 * @proto: the protocol definition
113 *
114 */
115
116void gfs2_unregister_lockproto(const struct lm_lockops *proto)
117{
118 struct lmh_wrapper *lw;
119
120 mutex_lock(&lmh_lock);
121
122 list_for_each_entry(lw, &lmh_list, lw_list) {
123 if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) {
124 list_del(&lw->lw_list);
125 mutex_unlock(&lmh_lock);
126 kfree(lw);
127 return;
128 }
129 }
130
131 mutex_unlock(&lmh_lock);
132
133 printk(KERN_WARNING "GFS2: can't unregister lock protocol %s\n",
134 proto->lm_proto_name);
135}
136
137/**
138 * gfs2_mount_lockproto - Mount a lock protocol
139 * @proto_name - the name of the protocol
140 * @table_name - the name of the lock space
141 * @host_data - data specific to this host
142 * @cb - the callback to the code using the lock module
143 * @sdp - The GFS2 superblock
144 * @min_lvb_size - the mininum LVB size that the caller can deal with
145 * @flags - LM_MFLAG_*
146 * @lockstruct - a structure returned describing the mount
147 *
148 * Returns: 0 on success, -EXXX on failure
149 */
150
151int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data,
152 lm_callback_t cb, void *cb_data,
153 unsigned int min_lvb_size, int flags,
154 struct lm_lockstruct *lockstruct,
155 struct kobject *fskobj)
156{
157 struct lmh_wrapper *lw = NULL;
158 int try = 0;
159 int error, found;
160
161
162retry:
163 mutex_lock(&lmh_lock);
164
165 if (list_empty(&nolock_proto.lw_list))
166 list_add(&nolock_proto.lw_list, &lmh_list);
167
168 found = 0;
169 list_for_each_entry(lw, &lmh_list, lw_list) {
170 if (!strcmp(lw->lw_ops->lm_proto_name, proto_name)) {
171 found = 1;
172 break;
173 }
174 }
175
176 if (!found) {
177 if (!try && capable(CAP_SYS_MODULE)) {
178 try = 1;
179 mutex_unlock(&lmh_lock);
180 request_module(proto_name);
181 goto retry;
182 }
183 printk(KERN_INFO "GFS2: can't find protocol %s\n", proto_name);
184 error = -ENOENT;
185 goto out;
186 }
187
188 if (lw->lw_ops->lm_owner &&
189 !try_module_get(lw->lw_ops->lm_owner)) {
190 try = 0;
191 mutex_unlock(&lmh_lock);
192 msleep(1000);
193 goto retry;
194 }
195
196 error = lw->lw_ops->lm_mount(table_name, host_data, cb, cb_data,
197 min_lvb_size, flags, lockstruct, fskobj);
198 if (error)
199 module_put(lw->lw_ops->lm_owner);
200out:
201 mutex_unlock(&lmh_lock);
202 return error;
203}
204
205void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct)
206{
207 mutex_lock(&lmh_lock);
208 if (lockstruct->ls_ops->lm_unmount)
209 lockstruct->ls_ops->lm_unmount(lockstruct->ls_lockspace);
210 if (lockstruct->ls_ops->lm_owner)
211 module_put(lockstruct->ls_ops->lm_owner);
212 mutex_unlock(&lmh_lock);
213}
214
215/**
216 * gfs2_withdraw_lockproto - abnormally unmount a lock module
217 * @lockstruct: the lockstruct passed into mount
218 *
219 */
220
221void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct)
222{
223 mutex_lock(&lmh_lock);
224 lockstruct->ls_ops->lm_withdraw(lockstruct->ls_lockspace);
225 if (lockstruct->ls_ops->lm_owner)
226 module_put(lockstruct->ls_ops->lm_owner);
227 mutex_unlock(&lmh_lock);
228}
229
230EXPORT_SYMBOL_GPL(gfs2_register_lockproto);
231EXPORT_SYMBOL_GPL(gfs2_unregister_lockproto);
232
diff --git a/fs/gfs2/locking/dlm/Makefile b/fs/gfs2/locking/dlm/Makefile
deleted file mode 100644
index 2609bb6cd01..00000000000
--- a/fs/gfs2/locking/dlm/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o
2lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o
3
diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c
deleted file mode 100644
index 2482c904750..00000000000
--- a/fs/gfs2/locking/dlm/lock.c
+++ /dev/null
@@ -1,708 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include "lock_dlm.h"
11
12static char junk_lvb[GDLM_LVB_SIZE];
13
14
15/* convert dlm lock-mode to gfs lock-state */
16
17static s16 gdlm_make_lmstate(s16 dlmmode)
18{
19 switch (dlmmode) {
20 case DLM_LOCK_IV:
21 case DLM_LOCK_NL:
22 return LM_ST_UNLOCKED;
23 case DLM_LOCK_EX:
24 return LM_ST_EXCLUSIVE;
25 case DLM_LOCK_CW:
26 return LM_ST_DEFERRED;
27 case DLM_LOCK_PR:
28 return LM_ST_SHARED;
29 }
30 gdlm_assert(0, "unknown DLM mode %d", dlmmode);
31 return -1;
32}
33
34/* A lock placed on this queue is re-submitted to DLM as soon as the lock_dlm
35 thread gets to it. */
36
37static void queue_submit(struct gdlm_lock *lp)
38{
39 struct gdlm_ls *ls = lp->ls;
40
41 spin_lock(&ls->async_lock);
42 list_add_tail(&lp->delay_list, &ls->submit);
43 spin_unlock(&ls->async_lock);
44 wake_up(&ls->thread_wait);
45}
46
47static void wake_up_ast(struct gdlm_lock *lp)
48{
49 clear_bit(LFL_AST_WAIT, &lp->flags);
50 smp_mb__after_clear_bit();
51 wake_up_bit(&lp->flags, LFL_AST_WAIT);
52}
53
54static void gdlm_delete_lp(struct gdlm_lock *lp)
55{
56 struct gdlm_ls *ls = lp->ls;
57
58 spin_lock(&ls->async_lock);
59 if (!list_empty(&lp->delay_list))
60 list_del_init(&lp->delay_list);
61 ls->all_locks_count--;
62 spin_unlock(&ls->async_lock);
63
64 kfree(lp);
65}
66
67static void gdlm_queue_delayed(struct gdlm_lock *lp)
68{
69 struct gdlm_ls *ls = lp->ls;
70
71 spin_lock(&ls->async_lock);
72 list_add_tail(&lp->delay_list, &ls->delayed);
73 spin_unlock(&ls->async_lock);
74}
75
76static void process_complete(struct gdlm_lock *lp)
77{
78 struct gdlm_ls *ls = lp->ls;
79 struct lm_async_cb acb;
80
81 memset(&acb, 0, sizeof(acb));
82
83 if (lp->lksb.sb_status == -DLM_ECANCEL) {
84 log_info("complete dlm cancel %x,%llx flags %lx",
85 lp->lockname.ln_type,
86 (unsigned long long)lp->lockname.ln_number,
87 lp->flags);
88
89 lp->req = lp->cur;
90 acb.lc_ret |= LM_OUT_CANCELED;
91 if (lp->cur == DLM_LOCK_IV)
92 lp->lksb.sb_lkid = 0;
93 goto out;
94 }
95
96 if (test_and_clear_bit(LFL_DLM_UNLOCK, &lp->flags)) {
97 if (lp->lksb.sb_status != -DLM_EUNLOCK) {
98 log_info("unlock sb_status %d %x,%llx flags %lx",
99 lp->lksb.sb_status, lp->lockname.ln_type,
100 (unsigned long long)lp->lockname.ln_number,
101 lp->flags);
102 return;
103 }
104
105 lp->cur = DLM_LOCK_IV;
106 lp->req = DLM_LOCK_IV;
107 lp->lksb.sb_lkid = 0;
108
109 if (test_and_clear_bit(LFL_UNLOCK_DELETE, &lp->flags)) {
110 gdlm_delete_lp(lp);
111 return;
112 }
113 goto out;
114 }
115
116 if (lp->lksb.sb_flags & DLM_SBF_VALNOTVALID)
117 memset(lp->lksb.sb_lvbptr, 0, GDLM_LVB_SIZE);
118
119 if (lp->lksb.sb_flags & DLM_SBF_ALTMODE) {
120 if (lp->req == DLM_LOCK_PR)
121 lp->req = DLM_LOCK_CW;
122 else if (lp->req == DLM_LOCK_CW)
123 lp->req = DLM_LOCK_PR;
124 }
125
126 /*
127 * A canceled lock request. The lock was just taken off the delayed
128 * list and was never even submitted to dlm.
129 */
130
131 if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) {
132 log_info("complete internal cancel %x,%llx",
133 lp->lockname.ln_type,
134 (unsigned long long)lp->lockname.ln_number);
135 lp->req = lp->cur;
136 acb.lc_ret |= LM_OUT_CANCELED;
137 goto out;
138 }
139
140 /*
141 * An error occured.
142 */
143
144 if (lp->lksb.sb_status) {
145 /* a "normal" error */
146 if ((lp->lksb.sb_status == -EAGAIN) &&
147 (lp->lkf & DLM_LKF_NOQUEUE)) {
148 lp->req = lp->cur;
149 if (lp->cur == DLM_LOCK_IV)
150 lp->lksb.sb_lkid = 0;
151 goto out;
152 }
153
154 /* this could only happen with cancels I think */
155 log_info("ast sb_status %d %x,%llx flags %lx",
156 lp->lksb.sb_status, lp->lockname.ln_type,
157 (unsigned long long)lp->lockname.ln_number,
158 lp->flags);
159 return;
160 }
161
162 /*
163 * This is an AST for an EX->EX conversion for sync_lvb from GFS.
164 */
165
166 if (test_and_clear_bit(LFL_SYNC_LVB, &lp->flags)) {
167 wake_up_ast(lp);
168 return;
169 }
170
171 /*
172 * A lock has been demoted to NL because it initially completed during
173 * BLOCK_LOCKS. Now it must be requested in the originally requested
174 * mode.
175 */
176
177 if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) {
178 gdlm_assert(lp->req == DLM_LOCK_NL, "%x,%llx",
179 lp->lockname.ln_type,
180 (unsigned long long)lp->lockname.ln_number);
181 gdlm_assert(lp->prev_req > DLM_LOCK_NL, "%x,%llx",
182 lp->lockname.ln_type,
183 (unsigned long long)lp->lockname.ln_number);
184
185 lp->cur = DLM_LOCK_NL;
186 lp->req = lp->prev_req;
187 lp->prev_req = DLM_LOCK_IV;
188 lp->lkf &= ~DLM_LKF_CONVDEADLK;
189
190 set_bit(LFL_NOCACHE, &lp->flags);
191
192 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
193 !test_bit(LFL_NOBLOCK, &lp->flags))
194 gdlm_queue_delayed(lp);
195 else
196 queue_submit(lp);
197 return;
198 }
199
200 /*
201 * A request is granted during dlm recovery. It may be granted
202 * because the locks of a failed node were cleared. In that case,
203 * there may be inconsistent data beneath this lock and we must wait
204 * for recovery to complete to use it. When gfs recovery is done this
205 * granted lock will be converted to NL and then reacquired in this
206 * granted state.
207 */
208
209 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
210 !test_bit(LFL_NOBLOCK, &lp->flags) &&
211 lp->req != DLM_LOCK_NL) {
212
213 lp->cur = lp->req;
214 lp->prev_req = lp->req;
215 lp->req = DLM_LOCK_NL;
216 lp->lkf |= DLM_LKF_CONVERT;
217 lp->lkf &= ~DLM_LKF_CONVDEADLK;
218
219 log_debug("rereq %x,%llx id %x %d,%d",
220 lp->lockname.ln_type,
221 (unsigned long long)lp->lockname.ln_number,
222 lp->lksb.sb_lkid, lp->cur, lp->req);
223
224 set_bit(LFL_REREQUEST, &lp->flags);
225 queue_submit(lp);
226 return;
227 }
228
229 /*
230 * DLM demoted the lock to NL before it was granted so GFS must be
231 * told it cannot cache data for this lock.
232 */
233
234 if (lp->lksb.sb_flags & DLM_SBF_DEMOTED)
235 set_bit(LFL_NOCACHE, &lp->flags);
236
237out:
238 /*
239 * This is an internal lock_dlm lock
240 */
241
242 if (test_bit(LFL_INLOCK, &lp->flags)) {
243 clear_bit(LFL_NOBLOCK, &lp->flags);
244 lp->cur = lp->req;
245 wake_up_ast(lp);
246 return;
247 }
248
249 /*
250 * Normal completion of a lock request. Tell GFS it now has the lock.
251 */
252
253 clear_bit(LFL_NOBLOCK, &lp->flags);
254 lp->cur = lp->req;
255
256 acb.lc_name = lp->lockname;
257 acb.lc_ret |= gdlm_make_lmstate(lp->cur);
258
259 ls->fscb(ls->sdp, LM_CB_ASYNC, &acb);
260}
261
262static void gdlm_ast(void *astarg)
263{
264 struct gdlm_lock *lp = astarg;
265 clear_bit(LFL_ACTIVE, &lp->flags);
266 process_complete(lp);
267}
268
269static void process_blocking(struct gdlm_lock *lp, int bast_mode)
270{
271 struct gdlm_ls *ls = lp->ls;
272 unsigned int cb = 0;
273
274 switch (gdlm_make_lmstate(bast_mode)) {
275 case LM_ST_EXCLUSIVE:
276 cb = LM_CB_NEED_E;
277 break;
278 case LM_ST_DEFERRED:
279 cb = LM_CB_NEED_D;
280 break;
281 case LM_ST_SHARED:
282 cb = LM_CB_NEED_S;
283 break;
284 default:
285 gdlm_assert(0, "unknown bast mode %u", bast_mode);
286 }
287
288 ls->fscb(ls->sdp, cb, &lp->lockname);
289}
290
291
292static void gdlm_bast(void *astarg, int mode)
293{
294 struct gdlm_lock *lp = astarg;
295
296 if (!mode) {
297 printk(KERN_INFO "lock_dlm: bast mode zero %x,%llx\n",
298 lp->lockname.ln_type,
299 (unsigned long long)lp->lockname.ln_number);
300 return;
301 }
302
303 process_blocking(lp, mode);
304}
305
306/* convert gfs lock-state to dlm lock-mode */
307
308static s16 make_mode(s16 lmstate)
309{
310 switch (lmstate) {
311 case LM_ST_UNLOCKED:
312 return DLM_LOCK_NL;
313 case LM_ST_EXCLUSIVE:
314 return DLM_LOCK_EX;
315 case LM_ST_DEFERRED:
316 return DLM_LOCK_CW;
317 case LM_ST_SHARED:
318 return DLM_LOCK_PR;
319 }
320 gdlm_assert(0, "unknown LM state %d", lmstate);
321 return -1;
322}
323
324
325/* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and
326 DLM_LOCK_IV are both considered LM_ST_UNLOCKED by GFS. */
327
328static void check_cur_state(struct gdlm_lock *lp, unsigned int cur_state)
329{
330 s16 cur = make_mode(cur_state);
331 if (lp->cur != DLM_LOCK_IV)
332 gdlm_assert(lp->cur == cur, "%d, %d", lp->cur, cur);
333}
334
335static inline unsigned int make_flags(struct gdlm_lock *lp,
336 unsigned int gfs_flags,
337 s16 cur, s16 req)
338{
339 unsigned int lkf = 0;
340
341 if (gfs_flags & LM_FLAG_TRY)
342 lkf |= DLM_LKF_NOQUEUE;
343
344 if (gfs_flags & LM_FLAG_TRY_1CB) {
345 lkf |= DLM_LKF_NOQUEUE;
346 lkf |= DLM_LKF_NOQUEUEBAST;
347 }
348
349 if (gfs_flags & LM_FLAG_PRIORITY) {
350 lkf |= DLM_LKF_NOORDER;
351 lkf |= DLM_LKF_HEADQUE;
352 }
353
354 if (gfs_flags & LM_FLAG_ANY) {
355 if (req == DLM_LOCK_PR)
356 lkf |= DLM_LKF_ALTCW;
357 else if (req == DLM_LOCK_CW)
358 lkf |= DLM_LKF_ALTPR;
359 }
360
361 if (lp->lksb.sb_lkid != 0) {
362 lkf |= DLM_LKF_CONVERT;
363 }
364
365 if (lp->lvb)
366 lkf |= DLM_LKF_VALBLK;
367
368 return lkf;
369}
370
371/* make_strname - convert GFS lock numbers to a string */
372
373static inline void make_strname(const struct lm_lockname *lockname,
374 struct gdlm_strname *str)
375{
376 sprintf(str->name, "%8x%16llx", lockname->ln_type,
377 (unsigned long long)lockname->ln_number);
378 str->namelen = GDLM_STRNAME_BYTES;
379}
380
381static int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name,
382 struct gdlm_lock **lpp)
383{
384 struct gdlm_lock *lp;
385
386 lp = kzalloc(sizeof(struct gdlm_lock), GFP_NOFS);
387 if (!lp)
388 return -ENOMEM;
389
390 lp->lockname = *name;
391 make_strname(name, &lp->strname);
392 lp->ls = ls;
393 lp->cur = DLM_LOCK_IV;
394 INIT_LIST_HEAD(&lp->delay_list);
395
396 spin_lock(&ls->async_lock);
397 ls->all_locks_count++;
398 spin_unlock(&ls->async_lock);
399
400 *lpp = lp;
401 return 0;
402}
403
404int gdlm_get_lock(void *lockspace, struct lm_lockname *name,
405 void **lockp)
406{
407 struct gdlm_lock *lp;
408 int error;
409
410 error = gdlm_create_lp(lockspace, name, &lp);
411
412 *lockp = lp;
413 return error;
414}
415
416void gdlm_put_lock(void *lock)
417{
418 gdlm_delete_lp(lock);
419}
420
421unsigned int gdlm_do_lock(struct gdlm_lock *lp)
422{
423 struct gdlm_ls *ls = lp->ls;
424 int error, bast = 1;
425
426 /*
427 * When recovery is in progress, delay lock requests for submission
428 * once recovery is done. Requests for recovery (NOEXP) and unlocks
429 * can pass.
430 */
431
432 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
433 !test_bit(LFL_NOBLOCK, &lp->flags) && lp->req != DLM_LOCK_NL) {
434 gdlm_queue_delayed(lp);
435 return LM_OUT_ASYNC;
436 }
437
438 /*
439 * Submit the actual lock request.
440 */
441
442 if (test_bit(LFL_NOBAST, &lp->flags))
443 bast = 0;
444
445 set_bit(LFL_ACTIVE, &lp->flags);
446
447 log_debug("lk %x,%llx id %x %d,%d %x", lp->lockname.ln_type,
448 (unsigned long long)lp->lockname.ln_number, lp->lksb.sb_lkid,
449 lp->cur, lp->req, lp->lkf);
450
451 error = dlm_lock(ls->dlm_lockspace, lp->req, &lp->lksb, lp->lkf,
452 lp->strname.name, lp->strname.namelen, 0, gdlm_ast,
453 lp, bast ? gdlm_bast : NULL);
454
455 if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) {
456 lp->lksb.sb_status = -EAGAIN;
457 gdlm_ast(lp);
458 error = 0;
459 }
460
461 if (error) {
462 log_error("%s: gdlm_lock %x,%llx err=%d cur=%d req=%d lkf=%x "
463 "flags=%lx", ls->fsname, lp->lockname.ln_type,
464 (unsigned long long)lp->lockname.ln_number, error,
465 lp->cur, lp->req, lp->lkf, lp->flags);
466 return LM_OUT_ERROR;
467 }
468 return LM_OUT_ASYNC;
469}
470
471static unsigned int gdlm_do_unlock(struct gdlm_lock *lp)
472{
473 struct gdlm_ls *ls = lp->ls;
474 unsigned int lkf = 0;
475 int error;
476
477 set_bit(LFL_DLM_UNLOCK, &lp->flags);
478 set_bit(LFL_ACTIVE, &lp->flags);
479
480 if (lp->lvb)
481 lkf = DLM_LKF_VALBLK;
482
483 log_debug("un %x,%llx %x %d %x", lp->lockname.ln_type,
484 (unsigned long long)lp->lockname.ln_number,
485 lp->lksb.sb_lkid, lp->cur, lkf);
486
487 error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, NULL, lp);
488
489 if (error) {
490 log_error("%s: gdlm_unlock %x,%llx err=%d cur=%d req=%d lkf=%x "
491 "flags=%lx", ls->fsname, lp->lockname.ln_type,
492 (unsigned long long)lp->lockname.ln_number, error,
493 lp->cur, lp->req, lp->lkf, lp->flags);
494 return LM_OUT_ERROR;
495 }
496 return LM_OUT_ASYNC;
497}
498
499unsigned int gdlm_lock(void *lock, unsigned int cur_state,
500 unsigned int req_state, unsigned int flags)
501{
502 struct gdlm_lock *lp = lock;
503
504 if (req_state == LM_ST_UNLOCKED)
505 return gdlm_unlock(lock, cur_state);
506
507 if (req_state == LM_ST_UNLOCKED)
508 return gdlm_unlock(lock, cur_state);
509
510 clear_bit(LFL_DLM_CANCEL, &lp->flags);
511 if (flags & LM_FLAG_NOEXP)
512 set_bit(LFL_NOBLOCK, &lp->flags);
513
514 check_cur_state(lp, cur_state);
515 lp->req = make_mode(req_state);
516 lp->lkf = make_flags(lp, flags, lp->cur, lp->req);
517
518 return gdlm_do_lock(lp);
519}
520
521unsigned int gdlm_unlock(void *lock, unsigned int cur_state)
522{
523 struct gdlm_lock *lp = lock;
524
525 clear_bit(LFL_DLM_CANCEL, &lp->flags);
526 if (lp->cur == DLM_LOCK_IV)
527 return 0;
528 return gdlm_do_unlock(lp);
529}
530
531void gdlm_cancel(void *lock)
532{
533 struct gdlm_lock *lp = lock;
534 struct gdlm_ls *ls = lp->ls;
535 int error, delay_list = 0;
536
537 if (test_bit(LFL_DLM_CANCEL, &lp->flags))
538 return;
539
540 log_info("gdlm_cancel %x,%llx flags %lx", lp->lockname.ln_type,
541 (unsigned long long)lp->lockname.ln_number, lp->flags);
542
543 spin_lock(&ls->async_lock);
544 if (!list_empty(&lp->delay_list)) {
545 list_del_init(&lp->delay_list);
546 delay_list = 1;
547 }
548 spin_unlock(&ls->async_lock);
549
550 if (delay_list) {
551 set_bit(LFL_CANCEL, &lp->flags);
552 set_bit(LFL_ACTIVE, &lp->flags);
553 gdlm_ast(lp);
554 return;
555 }
556
557 if (!test_bit(LFL_ACTIVE, &lp->flags) ||
558 test_bit(LFL_DLM_UNLOCK, &lp->flags)) {
559 log_info("gdlm_cancel skip %x,%llx flags %lx",
560 lp->lockname.ln_type,
561 (unsigned long long)lp->lockname.ln_number, lp->flags);
562 return;
563 }
564
565 /* the lock is blocked in the dlm */
566
567 set_bit(LFL_DLM_CANCEL, &lp->flags);
568 set_bit(LFL_ACTIVE, &lp->flags);
569
570 error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, DLM_LKF_CANCEL,
571 NULL, lp);
572
573 log_info("gdlm_cancel rv %d %x,%llx flags %lx", error,
574 lp->lockname.ln_type,
575 (unsigned long long)lp->lockname.ln_number, lp->flags);
576
577 if (error == -EBUSY)
578 clear_bit(LFL_DLM_CANCEL, &lp->flags);
579}
580
581static int gdlm_add_lvb(struct gdlm_lock *lp)
582{
583 char *lvb;
584
585 lvb = kzalloc(GDLM_LVB_SIZE, GFP_NOFS);
586 if (!lvb)
587 return -ENOMEM;
588
589 lp->lksb.sb_lvbptr = lvb;
590 lp->lvb = lvb;
591 return 0;
592}
593
594static void gdlm_del_lvb(struct gdlm_lock *lp)
595{
596 kfree(lp->lvb);
597 lp->lvb = NULL;
598 lp->lksb.sb_lvbptr = NULL;
599}
600
601static int gdlm_ast_wait(void *word)
602{
603 schedule();
604 return 0;
605}
606
607/* This can do a synchronous dlm request (requiring a lock_dlm thread to get
608 the completion) because gfs won't call hold_lvb() during a callback (from
609 the context of a lock_dlm thread). */
610
611static int hold_null_lock(struct gdlm_lock *lp)
612{
613 struct gdlm_lock *lpn = NULL;
614 int error;
615
616 if (lp->hold_null) {
617 printk(KERN_INFO "lock_dlm: lvb already held\n");
618 return 0;
619 }
620
621 error = gdlm_create_lp(lp->ls, &lp->lockname, &lpn);
622 if (error)
623 goto out;
624
625 lpn->lksb.sb_lvbptr = junk_lvb;
626 lpn->lvb = junk_lvb;
627
628 lpn->req = DLM_LOCK_NL;
629 lpn->lkf = DLM_LKF_VALBLK | DLM_LKF_EXPEDITE;
630 set_bit(LFL_NOBAST, &lpn->flags);
631 set_bit(LFL_INLOCK, &lpn->flags);
632 set_bit(LFL_AST_WAIT, &lpn->flags);
633
634 gdlm_do_lock(lpn);
635 wait_on_bit(&lpn->flags, LFL_AST_WAIT, gdlm_ast_wait, TASK_UNINTERRUPTIBLE);
636 error = lpn->lksb.sb_status;
637 if (error) {
638 printk(KERN_INFO "lock_dlm: hold_null_lock dlm error %d\n",
639 error);
640 gdlm_delete_lp(lpn);
641 lpn = NULL;
642 }
643out:
644 lp->hold_null = lpn;
645 return error;
646}
647
648/* This cannot do a synchronous dlm request (requiring a lock_dlm thread to get
649 the completion) because gfs may call unhold_lvb() during a callback (from
650 the context of a lock_dlm thread) which could cause a deadlock since the
651 other lock_dlm thread could be engaged in recovery. */
652
653static void unhold_null_lock(struct gdlm_lock *lp)
654{
655 struct gdlm_lock *lpn = lp->hold_null;
656
657 gdlm_assert(lpn, "%x,%llx", lp->lockname.ln_type,
658 (unsigned long long)lp->lockname.ln_number);
659 lpn->lksb.sb_lvbptr = NULL;
660 lpn->lvb = NULL;
661 set_bit(LFL_UNLOCK_DELETE, &lpn->flags);
662 gdlm_do_unlock(lpn);
663 lp->hold_null = NULL;
664}
665
666/* Acquire a NL lock because gfs requires the value block to remain
667 intact on the resource while the lvb is "held" even if it's holding no locks
668 on the resource. */
669
670int gdlm_hold_lvb(void *lock, char **lvbp)
671{
672 struct gdlm_lock *lp = lock;
673 int error;
674
675 error = gdlm_add_lvb(lp);
676 if (error)
677 return error;
678
679 *lvbp = lp->lvb;
680
681 error = hold_null_lock(lp);
682 if (error)
683 gdlm_del_lvb(lp);
684
685 return error;
686}
687
688void gdlm_unhold_lvb(void *lock, char *lvb)
689{
690 struct gdlm_lock *lp = lock;
691
692 unhold_null_lock(lp);
693 gdlm_del_lvb(lp);
694}
695
696void gdlm_submit_delayed(struct gdlm_ls *ls)
697{
698 struct gdlm_lock *lp, *safe;
699
700 spin_lock(&ls->async_lock);
701 list_for_each_entry_safe(lp, safe, &ls->delayed, delay_list) {
702 list_del_init(&lp->delay_list);
703 list_add_tail(&lp->delay_list, &ls->submit);
704 }
705 spin_unlock(&ls->async_lock);
706 wake_up(&ls->thread_wait);
707}
708
diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h
deleted file mode 100644
index 3c98e7c6f93..00000000000
--- a/fs/gfs2/locking/dlm/lock_dlm.h
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef LOCK_DLM_DOT_H
11#define LOCK_DLM_DOT_H
12
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/spinlock.h>
16#include <linux/types.h>
17#include <linux/string.h>
18#include <linux/list.h>
19#include <linux/socket.h>
20#include <linux/delay.h>
21#include <linux/kthread.h>
22#include <linux/kobject.h>
23#include <linux/fcntl.h>
24#include <linux/wait.h>
25#include <net/sock.h>
26
27#include <linux/dlm.h>
28#include <linux/dlm_plock.h>
29#include <linux/lm_interface.h>
30
31/*
32 * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a
33 * prefix of lock_dlm_ gets awkward. Externally, GFS refers to this module
34 * as "lock_dlm".
35 */
36
37#define GDLM_STRNAME_BYTES 24
38#define GDLM_LVB_SIZE 32
39#define GDLM_DROP_COUNT 0
40#define GDLM_DROP_PERIOD 60
41#define GDLM_NAME_LEN 128
42
43/* GFS uses 12 bytes to identify a resource (32 bit type + 64 bit number).
44 We sprintf these numbers into a 24 byte string of hex values to make them
45 human-readable (to make debugging simpler.) */
46
47struct gdlm_strname {
48 unsigned char name[GDLM_STRNAME_BYTES];
49 unsigned short namelen;
50};
51
52enum {
53 DFL_BLOCK_LOCKS = 0,
54 DFL_SPECTATOR = 1,
55 DFL_WITHDRAW = 2,
56};
57
58struct gdlm_ls {
59 u32 id;
60 int jid;
61 int first;
62 int first_done;
63 unsigned long flags;
64 struct kobject kobj;
65 char clustername[GDLM_NAME_LEN];
66 char fsname[GDLM_NAME_LEN];
67 int fsflags;
68 dlm_lockspace_t *dlm_lockspace;
69 lm_callback_t fscb;
70 struct gfs2_sbd *sdp;
71 int recover_jid;
72 int recover_jid_done;
73 int recover_jid_status;
74 spinlock_t async_lock;
75 struct list_head delayed;
76 struct list_head submit;
77 u32 all_locks_count;
78 wait_queue_head_t wait_control;
79 struct task_struct *thread;
80 wait_queue_head_t thread_wait;
81};
82
83enum {
84 LFL_NOBLOCK = 0,
85 LFL_NOCACHE = 1,
86 LFL_DLM_UNLOCK = 2,
87 LFL_DLM_CANCEL = 3,
88 LFL_SYNC_LVB = 4,
89 LFL_FORCE_PROMOTE = 5,
90 LFL_REREQUEST = 6,
91 LFL_ACTIVE = 7,
92 LFL_INLOCK = 8,
93 LFL_CANCEL = 9,
94 LFL_NOBAST = 10,
95 LFL_HEADQUE = 11,
96 LFL_UNLOCK_DELETE = 12,
97 LFL_AST_WAIT = 13,
98};
99
100struct gdlm_lock {
101 struct gdlm_ls *ls;
102 struct lm_lockname lockname;
103 struct gdlm_strname strname;
104 char *lvb;
105 struct dlm_lksb lksb;
106
107 s16 cur;
108 s16 req;
109 s16 prev_req;
110 u32 lkf; /* dlm flags DLM_LKF_ */
111 unsigned long flags; /* lock_dlm flags LFL_ */
112
113 struct list_head delay_list; /* delayed */
114 struct gdlm_lock *hold_null; /* NL lock for hold_lvb */
115};
116
117#define gdlm_assert(assertion, fmt, args...) \
118do { \
119 if (unlikely(!(assertion))) { \
120 printk(KERN_EMERG "lock_dlm: fatal assertion failed \"%s\"\n" \
121 "lock_dlm: " fmt "\n", \
122 #assertion, ##args); \
123 BUG(); \
124 } \
125} while (0)
126
127#define log_print(lev, fmt, arg...) printk(lev "lock_dlm: " fmt "\n" , ## arg)
128#define log_info(fmt, arg...) log_print(KERN_INFO , fmt , ## arg)
129#define log_error(fmt, arg...) log_print(KERN_ERR , fmt , ## arg)
130#ifdef LOCK_DLM_LOG_DEBUG
131#define log_debug(fmt, arg...) log_print(KERN_DEBUG , fmt , ## arg)
132#else
133#define log_debug(fmt, arg...)
134#endif
135
136/* sysfs.c */
137
138int gdlm_sysfs_init(void);
139void gdlm_sysfs_exit(void);
140int gdlm_kobject_setup(struct gdlm_ls *, struct kobject *);
141void gdlm_kobject_release(struct gdlm_ls *);
142
143/* thread.c */
144
145int gdlm_init_threads(struct gdlm_ls *);
146void gdlm_release_threads(struct gdlm_ls *);
147
148/* lock.c */
149
150void gdlm_submit_delayed(struct gdlm_ls *);
151unsigned int gdlm_do_lock(struct gdlm_lock *);
152
153int gdlm_get_lock(void *, struct lm_lockname *, void **);
154void gdlm_put_lock(void *);
155unsigned int gdlm_lock(void *, unsigned int, unsigned int, unsigned int);
156unsigned int gdlm_unlock(void *, unsigned int);
157void gdlm_cancel(void *);
158int gdlm_hold_lvb(void *, char **);
159void gdlm_unhold_lvb(void *, char *);
160
161/* mount.c */
162
163extern const struct lm_lockops gdlm_ops;
164
165#endif
166
diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c
deleted file mode 100644
index b9a03a7ff80..00000000000
--- a/fs/gfs2/locking/dlm/main.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/init.h>
11
12#include "lock_dlm.h"
13
14static int __init init_lock_dlm(void)
15{
16 int error;
17
18 error = gfs2_register_lockproto(&gdlm_ops);
19 if (error) {
20 printk(KERN_WARNING "lock_dlm: can't register protocol: %d\n",
21 error);
22 return error;
23 }
24
25 error = gdlm_sysfs_init();
26 if (error) {
27 gfs2_unregister_lockproto(&gdlm_ops);
28 return error;
29 }
30
31 printk(KERN_INFO
32 "Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__);
33 return 0;
34}
35
36static void __exit exit_lock_dlm(void)
37{
38 gdlm_sysfs_exit();
39 gfs2_unregister_lockproto(&gdlm_ops);
40}
41
42module_init(init_lock_dlm);
43module_exit(exit_lock_dlm);
44
45MODULE_DESCRIPTION("GFS DLM Locking Module");
46MODULE_AUTHOR("Red Hat, Inc.");
47MODULE_LICENSE("GPL");
48
diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c
deleted file mode 100644
index 1aa7eb6a022..00000000000
--- a/fs/gfs2/locking/dlm/mount.c
+++ /dev/null
@@ -1,276 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include "lock_dlm.h"
11
12const struct lm_lockops gdlm_ops;
13
14
15static struct gdlm_ls *init_gdlm(lm_callback_t cb, struct gfs2_sbd *sdp,
16 int flags, char *table_name)
17{
18 struct gdlm_ls *ls;
19 char buf[256], *p;
20
21 ls = kzalloc(sizeof(struct gdlm_ls), GFP_KERNEL);
22 if (!ls)
23 return NULL;
24
25 ls->fscb = cb;
26 ls->sdp = sdp;
27 ls->fsflags = flags;
28 spin_lock_init(&ls->async_lock);
29 INIT_LIST_HEAD(&ls->delayed);
30 INIT_LIST_HEAD(&ls->submit);
31 init_waitqueue_head(&ls->thread_wait);
32 init_waitqueue_head(&ls->wait_control);
33 ls->jid = -1;
34
35 strncpy(buf, table_name, 256);
36 buf[255] = '\0';
37
38 p = strchr(buf, ':');
39 if (!p) {
40 log_info("invalid table_name \"%s\"", table_name);
41 kfree(ls);
42 return NULL;
43 }
44 *p = '\0';
45 p++;
46
47 strncpy(ls->clustername, buf, GDLM_NAME_LEN);
48 strncpy(ls->fsname, p, GDLM_NAME_LEN);
49
50 return ls;
51}
52
53static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir)
54{
55 char data[256];
56 char *options, *x, *y;
57 int error = 0;
58
59 memset(data, 0, 256);
60 strncpy(data, data_arg, 255);
61
62 if (!strlen(data)) {
63 log_error("no mount options, (u)mount helpers not installed");
64 return -EINVAL;
65 }
66
67 for (options = data; (x = strsep(&options, ":")); ) {
68 if (!*x)
69 continue;
70
71 y = strchr(x, '=');
72 if (y)
73 *y++ = 0;
74
75 if (!strcmp(x, "jid")) {
76 if (!y) {
77 log_error("need argument to jid");
78 error = -EINVAL;
79 break;
80 }
81 sscanf(y, "%u", &ls->jid);
82
83 } else if (!strcmp(x, "first")) {
84 if (!y) {
85 log_error("need argument to first");
86 error = -EINVAL;
87 break;
88 }
89 sscanf(y, "%u", &ls->first);
90
91 } else if (!strcmp(x, "id")) {
92 if (!y) {
93 log_error("need argument to id");
94 error = -EINVAL;
95 break;
96 }
97 sscanf(y, "%u", &ls->id);
98
99 } else if (!strcmp(x, "nodir")) {
100 if (!y) {
101 log_error("need argument to nodir");
102 error = -EINVAL;
103 break;
104 }
105 sscanf(y, "%u", nodir);
106
107 } else {
108 log_error("unkonwn option: %s", x);
109 error = -EINVAL;
110 break;
111 }
112 }
113
114 return error;
115}
116
117static int gdlm_mount(char *table_name, char *host_data,
118 lm_callback_t cb, void *cb_data,
119 unsigned int min_lvb_size, int flags,
120 struct lm_lockstruct *lockstruct,
121 struct kobject *fskobj)
122{
123 struct gdlm_ls *ls;
124 int error = -ENOMEM, nodir = 0;
125
126 if (min_lvb_size > GDLM_LVB_SIZE)
127 goto out;
128
129 ls = init_gdlm(cb, cb_data, flags, table_name);
130 if (!ls)
131 goto out;
132
133 error = make_args(ls, host_data, &nodir);
134 if (error)
135 goto out;
136
137 error = gdlm_init_threads(ls);
138 if (error)
139 goto out_free;
140
141 error = gdlm_kobject_setup(ls, fskobj);
142 if (error)
143 goto out_thread;
144
145 error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname),
146 &ls->dlm_lockspace,
147 DLM_LSFL_FS | DLM_LSFL_NEWEXCL |
148 (nodir ? DLM_LSFL_NODIR : 0),
149 GDLM_LVB_SIZE);
150 if (error) {
151 log_error("dlm_new_lockspace error %d", error);
152 goto out_kobj;
153 }
154
155 lockstruct->ls_jid = ls->jid;
156 lockstruct->ls_first = ls->first;
157 lockstruct->ls_lockspace = ls;
158 lockstruct->ls_ops = &gdlm_ops;
159 lockstruct->ls_flags = 0;
160 lockstruct->ls_lvb_size = GDLM_LVB_SIZE;
161 return 0;
162
163out_kobj:
164 gdlm_kobject_release(ls);
165out_thread:
166 gdlm_release_threads(ls);
167out_free:
168 kfree(ls);
169out:
170 return error;
171}
172
173static void gdlm_unmount(void *lockspace)
174{
175 struct gdlm_ls *ls = lockspace;
176
177 log_debug("unmount flags %lx", ls->flags);
178
179 /* FIXME: serialize unmount and withdraw in case they
180 happen at once. Also, if unmount follows withdraw,
181 wait for withdraw to finish. */
182
183 if (test_bit(DFL_WITHDRAW, &ls->flags))
184 goto out;
185
186 gdlm_kobject_release(ls);
187 dlm_release_lockspace(ls->dlm_lockspace, 2);
188 gdlm_release_threads(ls);
189 BUG_ON(ls->all_locks_count);
190out:
191 kfree(ls);
192}
193
194static void gdlm_recovery_done(void *lockspace, unsigned int jid,
195 unsigned int message)
196{
197 char env_jid[20];
198 char env_status[20];
199 char *envp[] = { env_jid, env_status, NULL };
200 struct gdlm_ls *ls = lockspace;
201 ls->recover_jid_done = jid;
202 ls->recover_jid_status = message;
203 sprintf(env_jid, "JID=%d", jid);
204 sprintf(env_status, "RECOVERY=%s",
205 message == LM_RD_SUCCESS ? "Done" : "Failed");
206 kobject_uevent_env(&ls->kobj, KOBJ_CHANGE, envp);
207}
208
209static void gdlm_others_may_mount(void *lockspace)
210{
211 char *message = "FIRSTMOUNT=Done";
212 char *envp[] = { message, NULL };
213 struct gdlm_ls *ls = lockspace;
214 ls->first_done = 1;
215 kobject_uevent_env(&ls->kobj, KOBJ_CHANGE, envp);
216}
217
218/* Userspace gets the offline uevent, blocks new gfs locks on
219 other mounters, and lets us know (sets WITHDRAW flag). Then,
220 userspace leaves the mount group while we leave the lockspace. */
221
222static void gdlm_withdraw(void *lockspace)
223{
224 struct gdlm_ls *ls = lockspace;
225
226 kobject_uevent(&ls->kobj, KOBJ_OFFLINE);
227
228 wait_event_interruptible(ls->wait_control,
229 test_bit(DFL_WITHDRAW, &ls->flags));
230
231 dlm_release_lockspace(ls->dlm_lockspace, 2);
232 gdlm_release_threads(ls);
233 gdlm_kobject_release(ls);
234}
235
236static int gdlm_plock(void *lockspace, struct lm_lockname *name,
237 struct file *file, int cmd, struct file_lock *fl)
238{
239 struct gdlm_ls *ls = lockspace;
240 return dlm_posix_lock(ls->dlm_lockspace, name->ln_number, file, cmd, fl);
241}
242
243static int gdlm_punlock(void *lockspace, struct lm_lockname *name,
244 struct file *file, struct file_lock *fl)
245{
246 struct gdlm_ls *ls = lockspace;
247 return dlm_posix_unlock(ls->dlm_lockspace, name->ln_number, file, fl);
248}
249
250static int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
251 struct file *file, struct file_lock *fl)
252{
253 struct gdlm_ls *ls = lockspace;
254 return dlm_posix_get(ls->dlm_lockspace, name->ln_number, file, fl);
255}
256
257const struct lm_lockops gdlm_ops = {
258 .lm_proto_name = "lock_dlm",
259 .lm_mount = gdlm_mount,
260 .lm_others_may_mount = gdlm_others_may_mount,
261 .lm_unmount = gdlm_unmount,
262 .lm_withdraw = gdlm_withdraw,
263 .lm_get_lock = gdlm_get_lock,
264 .lm_put_lock = gdlm_put_lock,
265 .lm_lock = gdlm_lock,
266 .lm_unlock = gdlm_unlock,
267 .lm_plock = gdlm_plock,
268 .lm_punlock = gdlm_punlock,
269 .lm_plock_get = gdlm_plock_get,
270 .lm_cancel = gdlm_cancel,
271 .lm_hold_lvb = gdlm_hold_lvb,
272 .lm_unhold_lvb = gdlm_unhold_lvb,
273 .lm_recovery_done = gdlm_recovery_done,
274 .lm_owner = THIS_MODULE,
275};
276
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
deleted file mode 100644
index 9b7edcf7bd4..00000000000
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ /dev/null
@@ -1,226 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/ctype.h>
11#include <linux/stat.h>
12
13#include "lock_dlm.h"
14
15static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf)
16{
17 return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name);
18}
19
20static ssize_t block_show(struct gdlm_ls *ls, char *buf)
21{
22 ssize_t ret;
23 int val = 0;
24
25 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
26 val = 1;
27 ret = sprintf(buf, "%d\n", val);
28 return ret;
29}
30
31static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len)
32{
33 ssize_t ret = len;
34 int val;
35
36 val = simple_strtol(buf, NULL, 0);
37
38 if (val == 1)
39 set_bit(DFL_BLOCK_LOCKS, &ls->flags);
40 else if (val == 0) {
41 clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
42 gdlm_submit_delayed(ls);
43 } else {
44 ret = -EINVAL;
45 }
46 return ret;
47}
48
49static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf)
50{
51 ssize_t ret;
52 int val = 0;
53
54 if (test_bit(DFL_WITHDRAW, &ls->flags))
55 val = 1;
56 ret = sprintf(buf, "%d\n", val);
57 return ret;
58}
59
60static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
61{
62 ssize_t ret = len;
63 int val;
64
65 val = simple_strtol(buf, NULL, 0);
66
67 if (val == 1)
68 set_bit(DFL_WITHDRAW, &ls->flags);
69 else
70 ret = -EINVAL;
71 wake_up(&ls->wait_control);
72 return ret;
73}
74
75static ssize_t id_show(struct gdlm_ls *ls, char *buf)
76{
77 return sprintf(buf, "%u\n", ls->id);
78}
79
80static ssize_t jid_show(struct gdlm_ls *ls, char *buf)
81{
82 return sprintf(buf, "%d\n", ls->jid);
83}
84
85static ssize_t first_show(struct gdlm_ls *ls, char *buf)
86{
87 return sprintf(buf, "%d\n", ls->first);
88}
89
90static ssize_t first_done_show(struct gdlm_ls *ls, char *buf)
91{
92 return sprintf(buf, "%d\n", ls->first_done);
93}
94
95static ssize_t recover_show(struct gdlm_ls *ls, char *buf)
96{
97 return sprintf(buf, "%d\n", ls->recover_jid);
98}
99
100static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
101{
102 ls->recover_jid = simple_strtol(buf, NULL, 0);
103 ls->fscb(ls->sdp, LM_CB_NEED_RECOVERY, &ls->recover_jid);
104 return len;
105}
106
107static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf)
108{
109 return sprintf(buf, "%d\n", ls->recover_jid_done);
110}
111
112static ssize_t recover_status_show(struct gdlm_ls *ls, char *buf)
113{
114 return sprintf(buf, "%d\n", ls->recover_jid_status);
115}
116
117struct gdlm_attr {
118 struct attribute attr;
119 ssize_t (*show)(struct gdlm_ls *, char *);
120 ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
121};
122
123#define GDLM_ATTR(_name,_mode,_show,_store) \
124static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
125
126GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
127GDLM_ATTR(block, 0644, block_show, block_store);
128GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
129GDLM_ATTR(id, 0444, id_show, NULL);
130GDLM_ATTR(jid, 0444, jid_show, NULL);
131GDLM_ATTR(first, 0444, first_show, NULL);
132GDLM_ATTR(first_done, 0444, first_done_show, NULL);
133GDLM_ATTR(recover, 0644, recover_show, recover_store);
134GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
135GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
136
137static struct attribute *gdlm_attrs[] = {
138 &gdlm_attr_proto_name.attr,
139 &gdlm_attr_block.attr,
140 &gdlm_attr_withdraw.attr,
141 &gdlm_attr_id.attr,
142 &gdlm_attr_jid.attr,
143 &gdlm_attr_first.attr,
144 &gdlm_attr_first_done.attr,
145 &gdlm_attr_recover.attr,
146 &gdlm_attr_recover_done.attr,
147 &gdlm_attr_recover_status.attr,
148 NULL,
149};
150
151static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
152 char *buf)
153{
154 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
155 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
156 return a->show ? a->show(ls, buf) : 0;
157}
158
159static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
160 const char *buf, size_t len)
161{
162 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
163 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
164 return a->store ? a->store(ls, buf, len) : len;
165}
166
167static struct sysfs_ops gdlm_attr_ops = {
168 .show = gdlm_attr_show,
169 .store = gdlm_attr_store,
170};
171
172static struct kobj_type gdlm_ktype = {
173 .default_attrs = gdlm_attrs,
174 .sysfs_ops = &gdlm_attr_ops,
175};
176
177static struct kset *gdlm_kset;
178
179int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
180{
181 int error;
182
183 ls->kobj.kset = gdlm_kset;
184 error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj,
185 "lock_module");
186 if (error)
187 log_error("can't register kobj %d", error);
188 kobject_uevent(&ls->kobj, KOBJ_ADD);
189
190 return error;
191}
192
193void gdlm_kobject_release(struct gdlm_ls *ls)
194{
195 kobject_put(&ls->kobj);
196}
197
198static int gdlm_uevent(struct kset *kset, struct kobject *kobj,
199 struct kobj_uevent_env *env)
200{
201 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
202 add_uevent_var(env, "LOCKTABLE=%s:%s", ls->clustername, ls->fsname);
203 add_uevent_var(env, "LOCKPROTO=lock_dlm");
204 return 0;
205}
206
207static struct kset_uevent_ops gdlm_uevent_ops = {
208 .uevent = gdlm_uevent,
209};
210
211
212int gdlm_sysfs_init(void)
213{
214 gdlm_kset = kset_create_and_add("lock_dlm", &gdlm_uevent_ops, kernel_kobj);
215 if (!gdlm_kset) {
216 printk(KERN_WARNING "%s: can not create kset\n", __func__);
217 return -ENOMEM;
218 }
219 return 0;
220}
221
222void gdlm_sysfs_exit(void)
223{
224 kset_unregister(gdlm_kset);
225}
226
diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c
deleted file mode 100644
index 38823efd698..00000000000
--- a/fs/gfs2/locking/dlm/thread.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include "lock_dlm.h"
11
12static inline int no_work(struct gdlm_ls *ls)
13{
14 int ret;
15
16 spin_lock(&ls->async_lock);
17 ret = list_empty(&ls->submit);
18 spin_unlock(&ls->async_lock);
19
20 return ret;
21}
22
23static int gdlm_thread(void *data)
24{
25 struct gdlm_ls *ls = (struct gdlm_ls *) data;
26 struct gdlm_lock *lp = NULL;
27
28 while (!kthread_should_stop()) {
29 wait_event_interruptible(ls->thread_wait,
30 !no_work(ls) || kthread_should_stop());
31
32 spin_lock(&ls->async_lock);
33
34 if (!list_empty(&ls->submit)) {
35 lp = list_entry(ls->submit.next, struct gdlm_lock,
36 delay_list);
37 list_del_init(&lp->delay_list);
38 spin_unlock(&ls->async_lock);
39 gdlm_do_lock(lp);
40 spin_lock(&ls->async_lock);
41 }
42 spin_unlock(&ls->async_lock);
43 }
44
45 return 0;
46}
47
48int gdlm_init_threads(struct gdlm_ls *ls)
49{
50 struct task_struct *p;
51 int error;
52
53 p = kthread_run(gdlm_thread, ls, "lock_dlm");
54 error = IS_ERR(p);
55 if (error) {
56 log_error("can't start lock_dlm thread %d", error);
57 return error;
58 }
59 ls->thread = p;
60
61 return 0;
62}
63
64void gdlm_release_threads(struct gdlm_ls *ls)
65{
66 kthread_stop(ls->thread);
67}
68
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index ad305854bdc..98918a75641 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -14,7 +14,6 @@
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/crc32.h> 16#include <linux/crc32.h>
17#include <linux/lm_interface.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/kthread.h> 18#include <linux/kthread.h>
20#include <linux/freezer.h> 19#include <linux/freezer.h>
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 4390f6f4047..80e4f5f898b 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -13,7 +13,6 @@
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 7cacfde3219..a6892ed0840 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -14,7 +14,6 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
17#include <linux/lm_interface.h>
18#include <asm/atomic.h> 17#include <asm/atomic.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
@@ -23,6 +22,12 @@
23#include "sys.h" 22#include "sys.h"
24#include "util.h" 23#include "util.h"
25#include "glock.h" 24#include "glock.h"
25#include "quota.h"
26
27static struct shrinker qd_shrinker = {
28 .shrink = gfs2_shrink_qd_memory,
29 .seeks = DEFAULT_SEEKS,
30};
26 31
27static void gfs2_init_inode_once(void *foo) 32static void gfs2_init_inode_once(void *foo)
28{ 33{
@@ -41,8 +46,6 @@ static void gfs2_init_glock_once(void *foo)
41 INIT_HLIST_NODE(&gl->gl_list); 46 INIT_HLIST_NODE(&gl->gl_list);
42 spin_lock_init(&gl->gl_spin); 47 spin_lock_init(&gl->gl_spin);
43 INIT_LIST_HEAD(&gl->gl_holders); 48 INIT_LIST_HEAD(&gl->gl_holders);
44 gl->gl_lvb = NULL;
45 atomic_set(&gl->gl_lvb_count, 0);
46 INIT_LIST_HEAD(&gl->gl_lru); 49 INIT_LIST_HEAD(&gl->gl_lru);
47 INIT_LIST_HEAD(&gl->gl_ail_list); 50 INIT_LIST_HEAD(&gl->gl_ail_list);
48 atomic_set(&gl->gl_ail_count, 0); 51 atomic_set(&gl->gl_ail_count, 0);
@@ -100,6 +103,8 @@ static int __init init_gfs2_fs(void)
100 if (!gfs2_quotad_cachep) 103 if (!gfs2_quotad_cachep)
101 goto fail; 104 goto fail;
102 105
106 register_shrinker(&qd_shrinker);
107
103 error = register_filesystem(&gfs2_fs_type); 108 error = register_filesystem(&gfs2_fs_type);
104 if (error) 109 if (error)
105 goto fail; 110 goto fail;
@@ -117,6 +122,7 @@ static int __init init_gfs2_fs(void)
117fail_unregister: 122fail_unregister:
118 unregister_filesystem(&gfs2_fs_type); 123 unregister_filesystem(&gfs2_fs_type);
119fail: 124fail:
125 unregister_shrinker(&qd_shrinker);
120 gfs2_glock_exit(); 126 gfs2_glock_exit();
121 127
122 if (gfs2_quotad_cachep) 128 if (gfs2_quotad_cachep)
@@ -145,6 +151,7 @@ fail:
145 151
146static void __exit exit_gfs2_fs(void) 152static void __exit exit_gfs2_fs(void)
147{ 153{
154 unregister_shrinker(&qd_shrinker);
148 gfs2_glock_exit(); 155 gfs2_glock_exit();
149 gfs2_unregister_debugfs(); 156 gfs2_unregister_debugfs();
150 unregister_filesystem(&gfs2_fs_type); 157 unregister_filesystem(&gfs2_fs_type);
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 09853620c95..8d6f13256b2 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -19,7 +19,6 @@
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/bio.h> 20#include <linux/bio.h>
21#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
22#include <linux/lm_interface.h>
23 22
24#include "gfs2.h" 23#include "gfs2.h"
25#include "incore.h" 24#include "incore.h"
@@ -90,27 +89,6 @@ void gfs2_aspace_put(struct inode *aspace)
90} 89}
91 90
92/** 91/**
93 * gfs2_meta_inval - Invalidate all buffers associated with a glock
94 * @gl: the glock
95 *
96 */
97
98void gfs2_meta_inval(struct gfs2_glock *gl)
99{
100 struct gfs2_sbd *sdp = gl->gl_sbd;
101 struct inode *aspace = gl->gl_aspace;
102 struct address_space *mapping = gl->gl_aspace->i_mapping;
103
104 gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
105
106 atomic_inc(&aspace->i_writecount);
107 truncate_inode_pages(mapping, 0);
108 atomic_dec(&aspace->i_writecount);
109
110 gfs2_assert_withdraw(sdp, !mapping->nrpages);
111}
112
113/**
114 * gfs2_meta_sync - Sync all buffers associated with a glock 92 * gfs2_meta_sync - Sync all buffers associated with a glock
115 * @gl: The glock 93 * @gl: The glock
116 * 94 *
diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h
index b1a5f3674d4..de270c2f9b6 100644
--- a/fs/gfs2/meta_io.h
+++ b/fs/gfs2/meta_io.h
@@ -40,7 +40,6 @@ static inline void gfs2_buffer_copy_tail(struct buffer_head *to_bh,
40struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp); 40struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp);
41void gfs2_aspace_put(struct inode *aspace); 41void gfs2_aspace_put(struct inode *aspace);
42 42
43void gfs2_meta_inval(struct gfs2_glock *gl);
44void gfs2_meta_sync(struct gfs2_glock *gl); 43void gfs2_meta_sync(struct gfs2_glock *gl);
45 44
46struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno); 45struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno);
diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c
index 3cb0a44ba02..f7e8527a21e 100644
--- a/fs/gfs2/mount.c
+++ b/fs/gfs2/mount.c
@@ -12,12 +12,11 @@
12#include <linux/completion.h> 12#include <linux/completion.h>
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/lm_interface.h>
16#include <linux/parser.h> 15#include <linux/parser.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
20#include "mount.h" 19#include "super.h"
21#include "sys.h" 20#include "sys.h"
22#include "util.h" 21#include "util.h"
23 22
@@ -37,11 +36,15 @@ enum {
37 Opt_quota_off, 36 Opt_quota_off,
38 Opt_quota_account, 37 Opt_quota_account,
39 Opt_quota_on, 38 Opt_quota_on,
39 Opt_quota,
40 Opt_noquota,
40 Opt_suiddir, 41 Opt_suiddir,
41 Opt_nosuiddir, 42 Opt_nosuiddir,
42 Opt_data_writeback, 43 Opt_data_writeback,
43 Opt_data_ordered, 44 Opt_data_ordered,
44 Opt_meta, 45 Opt_meta,
46 Opt_discard,
47 Opt_nodiscard,
45 Opt_err, 48 Opt_err,
46}; 49};
47 50
@@ -61,11 +64,15 @@ static const match_table_t tokens = {
61 {Opt_quota_off, "quota=off"}, 64 {Opt_quota_off, "quota=off"},
62 {Opt_quota_account, "quota=account"}, 65 {Opt_quota_account, "quota=account"},
63 {Opt_quota_on, "quota=on"}, 66 {Opt_quota_on, "quota=on"},
67 {Opt_quota, "quota"},
68 {Opt_noquota, "noquota"},
64 {Opt_suiddir, "suiddir"}, 69 {Opt_suiddir, "suiddir"},
65 {Opt_nosuiddir, "nosuiddir"}, 70 {Opt_nosuiddir, "nosuiddir"},
66 {Opt_data_writeback, "data=writeback"}, 71 {Opt_data_writeback, "data=writeback"},
67 {Opt_data_ordered, "data=ordered"}, 72 {Opt_data_ordered, "data=ordered"},
68 {Opt_meta, "meta"}, 73 {Opt_meta, "meta"},
74 {Opt_discard, "discard"},
75 {Opt_nodiscard, "nodiscard"},
69 {Opt_err, NULL} 76 {Opt_err, NULL}
70}; 77};
71 78
@@ -77,101 +84,46 @@ static const match_table_t tokens = {
77 * Return: errno 84 * Return: errno
78 */ 85 */
79 86
80int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount) 87int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
81{ 88{
82 struct gfs2_args *args = &sdp->sd_args; 89 char *o;
83 char *data = data_arg; 90 int token;
84 char *options, *o, *v; 91 substring_t tmp[MAX_OPT_ARGS];
85 int error = 0;
86
87 if (!remount) {
88 /* Set some defaults */
89 args->ar_quota = GFS2_QUOTA_DEFAULT;
90 args->ar_data = GFS2_DATA_DEFAULT;
91 }
92 92
93 /* Split the options into tokens with the "," character and 93 /* Split the options into tokens with the "," character and
94 process them */ 94 process them */
95 95
96 for (options = data; (o = strsep(&options, ",")); ) { 96 while (1) {
97 int token; 97 o = strsep(&options, ",");
98 substring_t tmp[MAX_OPT_ARGS]; 98 if (o == NULL)
99 99 break;
100 if (!*o) 100 if (*o == '\0')
101 continue; 101 continue;
102 102
103 token = match_token(o, tokens, tmp); 103 token = match_token(o, tokens, tmp);
104 switch (token) { 104 switch (token) {
105 case Opt_lockproto: 105 case Opt_lockproto:
106 v = match_strdup(&tmp[0]); 106 match_strlcpy(args->ar_lockproto, &tmp[0],
107 if (!v) { 107 GFS2_LOCKNAME_LEN);
108 fs_info(sdp, "no memory for lockproto\n");
109 error = -ENOMEM;
110 goto out_error;
111 }
112
113 if (remount && strcmp(v, args->ar_lockproto)) {
114 kfree(v);
115 goto cant_remount;
116 }
117
118 strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
119 args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
120 kfree(v);
121 break; 108 break;
122 case Opt_locktable: 109 case Opt_locktable:
123 v = match_strdup(&tmp[0]); 110 match_strlcpy(args->ar_locktable, &tmp[0],
124 if (!v) { 111 GFS2_LOCKNAME_LEN);
125 fs_info(sdp, "no memory for locktable\n");
126 error = -ENOMEM;
127 goto out_error;
128 }
129
130 if (remount && strcmp(v, args->ar_locktable)) {
131 kfree(v);
132 goto cant_remount;
133 }
134
135 strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
136 args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
137 kfree(v);
138 break; 112 break;
139 case Opt_hostdata: 113 case Opt_hostdata:
140 v = match_strdup(&tmp[0]); 114 match_strlcpy(args->ar_hostdata, &tmp[0],
141 if (!v) { 115 GFS2_LOCKNAME_LEN);
142 fs_info(sdp, "no memory for hostdata\n");
143 error = -ENOMEM;
144 goto out_error;
145 }
146
147 if (remount && strcmp(v, args->ar_hostdata)) {
148 kfree(v);
149 goto cant_remount;
150 }
151
152 strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
153 args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
154 kfree(v);
155 break; 116 break;
156 case Opt_spectator: 117 case Opt_spectator:
157 if (remount && !args->ar_spectator)
158 goto cant_remount;
159 args->ar_spectator = 1; 118 args->ar_spectator = 1;
160 sdp->sd_vfs->s_flags |= MS_RDONLY;
161 break; 119 break;
162 case Opt_ignore_local_fs: 120 case Opt_ignore_local_fs:
163 if (remount && !args->ar_ignore_local_fs)
164 goto cant_remount;
165 args->ar_ignore_local_fs = 1; 121 args->ar_ignore_local_fs = 1;
166 break; 122 break;
167 case Opt_localflocks: 123 case Opt_localflocks:
168 if (remount && !args->ar_localflocks)
169 goto cant_remount;
170 args->ar_localflocks = 1; 124 args->ar_localflocks = 1;
171 break; 125 break;
172 case Opt_localcaching: 126 case Opt_localcaching:
173 if (remount && !args->ar_localcaching)
174 goto cant_remount;
175 args->ar_localcaching = 1; 127 args->ar_localcaching = 1;
176 break; 128 break;
177 case Opt_debug: 129 case Opt_debug:
@@ -181,25 +133,23 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
181 args->ar_debug = 0; 133 args->ar_debug = 0;
182 break; 134 break;
183 case Opt_upgrade: 135 case Opt_upgrade:
184 if (remount && !args->ar_upgrade)
185 goto cant_remount;
186 args->ar_upgrade = 1; 136 args->ar_upgrade = 1;
187 break; 137 break;
188 case Opt_acl: 138 case Opt_acl:
189 args->ar_posix_acl = 1; 139 args->ar_posix_acl = 1;
190 sdp->sd_vfs->s_flags |= MS_POSIXACL;
191 break; 140 break;
192 case Opt_noacl: 141 case Opt_noacl:
193 args->ar_posix_acl = 0; 142 args->ar_posix_acl = 0;
194 sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
195 break; 143 break;
196 case Opt_quota_off: 144 case Opt_quota_off:
145 case Opt_noquota:
197 args->ar_quota = GFS2_QUOTA_OFF; 146 args->ar_quota = GFS2_QUOTA_OFF;
198 break; 147 break;
199 case Opt_quota_account: 148 case Opt_quota_account:
200 args->ar_quota = GFS2_QUOTA_ACCOUNT; 149 args->ar_quota = GFS2_QUOTA_ACCOUNT;
201 break; 150 break;
202 case Opt_quota_on: 151 case Opt_quota_on:
152 case Opt_quota:
203 args->ar_quota = GFS2_QUOTA_ON; 153 args->ar_quota = GFS2_QUOTA_ON;
204 break; 154 break;
205 case Opt_suiddir: 155 case Opt_suiddir:
@@ -215,29 +165,21 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
215 args->ar_data = GFS2_DATA_ORDERED; 165 args->ar_data = GFS2_DATA_ORDERED;
216 break; 166 break;
217 case Opt_meta: 167 case Opt_meta:
218 if (remount && args->ar_meta != 1)
219 goto cant_remount;
220 args->ar_meta = 1; 168 args->ar_meta = 1;
221 break; 169 break;
170 case Opt_discard:
171 args->ar_discard = 1;
172 break;
173 case Opt_nodiscard:
174 args->ar_discard = 0;
175 break;
222 case Opt_err: 176 case Opt_err:
223 default: 177 default:
224 fs_info(sdp, "unknown option: %s\n", o); 178 fs_info(sdp, "invalid mount option: %s\n", o);
225 error = -EINVAL; 179 return -EINVAL;
226 goto out_error;
227 } 180 }
228 } 181 }
229 182
230out_error: 183 return 0;
231 if (error)
232 fs_info(sdp, "invalid mount option(s)\n");
233
234 if (data != data_arg)
235 kfree(data);
236
237 return error;
238
239cant_remount:
240 fs_info(sdp, "can't remount with option %s\n", o);
241 return -EINVAL;
242} 184}
243 185
diff --git a/fs/gfs2/mount.h b/fs/gfs2/mount.h
deleted file mode 100644
index 401288acfdf..00000000000
--- a/fs/gfs2/mount.h
+++ /dev/null
@@ -1,17 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef __MOUNT_DOT_H__
11#define __MOUNT_DOT_H__
12
13struct gfs2_sbd;
14
15int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount);
16
17#endif /* __MOUNT_DOT_H__ */
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index 4ddab67867e..a6dde1751e1 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -19,7 +19,6 @@
19#include <linux/writeback.h> 19#include <linux/writeback.h>
20#include <linux/swap.h> 20#include <linux/swap.h>
21#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
22#include <linux/lm_interface.h>
23#include <linux/backing-dev.h> 22#include <linux/backing-dev.h>
24 23
25#include "gfs2.h" 24#include "gfs2.h"
@@ -442,6 +441,7 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
442 */ 441 */
443 if (unlikely(page->index)) { 442 if (unlikely(page->index)) {
444 zero_user(page, 0, PAGE_CACHE_SIZE); 443 zero_user(page, 0, PAGE_CACHE_SIZE);
444 SetPageUptodate(page);
445 return 0; 445 return 0;
446 } 446 }
447 447
@@ -1096,6 +1096,7 @@ static const struct address_space_operations gfs2_writeback_aops = {
1096 .releasepage = gfs2_releasepage, 1096 .releasepage = gfs2_releasepage,
1097 .direct_IO = gfs2_direct_IO, 1097 .direct_IO = gfs2_direct_IO,
1098 .migratepage = buffer_migrate_page, 1098 .migratepage = buffer_migrate_page,
1099 .is_partially_uptodate = block_is_partially_uptodate,
1099}; 1100};
1100 1101
1101static const struct address_space_operations gfs2_ordered_aops = { 1102static const struct address_space_operations gfs2_ordered_aops = {
@@ -1111,6 +1112,7 @@ static const struct address_space_operations gfs2_ordered_aops = {
1111 .releasepage = gfs2_releasepage, 1112 .releasepage = gfs2_releasepage,
1112 .direct_IO = gfs2_direct_IO, 1113 .direct_IO = gfs2_direct_IO,
1113 .migratepage = buffer_migrate_page, 1114 .migratepage = buffer_migrate_page,
1115 .is_partially_uptodate = block_is_partially_uptodate,
1114}; 1116};
1115 1117
1116static const struct address_space_operations gfs2_jdata_aops = { 1118static const struct address_space_operations gfs2_jdata_aops = {
@@ -1125,6 +1127,7 @@ static const struct address_space_operations gfs2_jdata_aops = {
1125 .bmap = gfs2_bmap, 1127 .bmap = gfs2_bmap,
1126 .invalidatepage = gfs2_invalidatepage, 1128 .invalidatepage = gfs2_invalidatepage,
1127 .releasepage = gfs2_releasepage, 1129 .releasepage = gfs2_releasepage,
1130 .is_partially_uptodate = block_is_partially_uptodate,
1128}; 1131};
1129 1132
1130void gfs2_set_aops(struct inode *inode) 1133void gfs2_set_aops(struct inode *inode)
diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c
index c2ad36330ca..022c66cd560 100644
--- a/fs/gfs2/ops_dentry.c
+++ b/fs/gfs2/ops_dentry.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/lm_interface.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
@@ -108,7 +107,7 @@ static int gfs2_dhash(struct dentry *dentry, struct qstr *str)
108 return 0; 107 return 0;
109} 108}
110 109
111struct dentry_operations gfs2_dops = { 110const struct dentry_operations gfs2_dops = {
112 .d_revalidate = gfs2_drevalidate, 111 .d_revalidate = gfs2_drevalidate,
113 .d_hash = gfs2_dhash, 112 .d_hash = gfs2_dhash,
114}; 113};
diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c
index 7fdeb14ddd1..9200ef22171 100644
--- a/fs/gfs2/ops_export.c
+++ b/fs/gfs2/ops_export.c
@@ -14,7 +14,6 @@
14#include <linux/exportfs.h> 14#include <linux/exportfs.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/crc32.h> 16#include <linux/crc32.h>
17#include <linux/lm_interface.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
20#include "incore.h" 19#include "incore.h"
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index 93fe41b67f9..3b9e8de3500 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -20,9 +20,10 @@
20#include <linux/gfs2_ondisk.h> 20#include <linux/gfs2_ondisk.h>
21#include <linux/ext2_fs.h> 21#include <linux/ext2_fs.h>
22#include <linux/crc32.h> 22#include <linux/crc32.h>
23#include <linux/lm_interface.h>
24#include <linux/writeback.h> 23#include <linux/writeback.h>
25#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include <linux/dlm.h>
26#include <linux/dlm_plock.h>
26 27
27#include "gfs2.h" 28#include "gfs2.h"
28#include "incore.h" 29#include "incore.h"
@@ -354,7 +355,9 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct page *page)
354 if (ret) 355 if (ret)
355 goto out; 356 goto out;
356 357
358 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
357 set_bit(GIF_SW_PAGED, &ip->i_flags); 359 set_bit(GIF_SW_PAGED, &ip->i_flags);
360
358 ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required); 361 ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required);
359 if (ret || !alloc_required) 362 if (ret || !alloc_required)
360 goto out_unlock; 363 goto out_unlock;
@@ -560,57 +563,24 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync)
560 return ret; 563 return ret;
561} 564}
562 565
566#ifdef CONFIG_GFS2_FS_LOCKING_DLM
567
563/** 568/**
564 * gfs2_setlease - acquire/release a file lease 569 * gfs2_setlease - acquire/release a file lease
565 * @file: the file pointer 570 * @file: the file pointer
566 * @arg: lease type 571 * @arg: lease type
567 * @fl: file lock 572 * @fl: file lock
568 * 573 *
574 * We don't currently have a way to enforce a lease across the whole
575 * cluster; until we do, disable leases (by just returning -EINVAL),
576 * unless the administrator has requested purely local locking.
577 *
569 * Returns: errno 578 * Returns: errno
570 */ 579 */
571 580
572static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl) 581static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl)
573{ 582{
574 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); 583 return -EINVAL;
575
576 /*
577 * We don't currently have a way to enforce a lease across the whole
578 * cluster; until we do, disable leases (by just returning -EINVAL),
579 * unless the administrator has requested purely local locking.
580 */
581 if (!sdp->sd_args.ar_localflocks)
582 return -EINVAL;
583 return generic_setlease(file, arg, fl);
584}
585
586static int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
587 struct file *file, struct file_lock *fl)
588{
589 int error = -EIO;
590 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
591 error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
592 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
593 return error;
594}
595
596static int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
597 struct file *file, int cmd, struct file_lock *fl)
598{
599 int error = -EIO;
600 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
601 error = sdp->sd_lockstruct.ls_ops->lm_plock(
602 sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
603 return error;
604}
605
606static int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
607 struct file *file, struct file_lock *fl)
608{
609 int error = -EIO;
610 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
611 error = sdp->sd_lockstruct.ls_ops->lm_punlock(
612 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
613 return error;
614} 584}
615 585
616/** 586/**
@@ -626,9 +596,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
626{ 596{
627 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); 597 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
628 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); 598 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
629 struct lm_lockname name = 599 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
630 { .ln_number = ip->i_no_addr,
631 .ln_type = LM_TYPE_PLOCK };
632 600
633 if (!(fl->fl_flags & FL_POSIX)) 601 if (!(fl->fl_flags & FL_POSIX))
634 return -ENOLCK; 602 return -ENOLCK;
@@ -640,12 +608,14 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
640 cmd = F_SETLK; 608 cmd = F_SETLK;
641 fl->fl_type = F_UNLCK; 609 fl->fl_type = F_UNLCK;
642 } 610 }
611 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
612 return -EIO;
643 if (IS_GETLK(cmd)) 613 if (IS_GETLK(cmd))
644 return gfs2_lm_plock_get(sdp, &name, file, fl); 614 return dlm_posix_get(ls->ls_dlm, ip->i_no_addr, file, fl);
645 else if (fl->fl_type == F_UNLCK) 615 else if (fl->fl_type == F_UNLCK)
646 return gfs2_lm_punlock(sdp, &name, file, fl); 616 return dlm_posix_unlock(ls->ls_dlm, ip->i_no_addr, file, fl);
647 else 617 else
648 return gfs2_lm_plock(sdp, &name, file, cmd, fl); 618 return dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl);
649} 619}
650 620
651static int do_flock(struct file *file, int cmd, struct file_lock *fl) 621static int do_flock(struct file *file, int cmd, struct file_lock *fl)
@@ -732,7 +702,7 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
732 } 702 }
733} 703}
734 704
735const struct file_operations gfs2_file_fops = { 705const struct file_operations *gfs2_file_fops = &(const struct file_operations){
736 .llseek = gfs2_llseek, 706 .llseek = gfs2_llseek,
737 .read = do_sync_read, 707 .read = do_sync_read,
738 .aio_read = generic_file_aio_read, 708 .aio_read = generic_file_aio_read,
@@ -750,7 +720,7 @@ const struct file_operations gfs2_file_fops = {
750 .setlease = gfs2_setlease, 720 .setlease = gfs2_setlease,
751}; 721};
752 722
753const struct file_operations gfs2_dir_fops = { 723const struct file_operations *gfs2_dir_fops = &(const struct file_operations){
754 .readdir = gfs2_readdir, 724 .readdir = gfs2_readdir,
755 .unlocked_ioctl = gfs2_ioctl, 725 .unlocked_ioctl = gfs2_ioctl,
756 .open = gfs2_open, 726 .open = gfs2_open,
@@ -760,7 +730,9 @@ const struct file_operations gfs2_dir_fops = {
760 .flock = gfs2_flock, 730 .flock = gfs2_flock,
761}; 731};
762 732
763const struct file_operations gfs2_file_fops_nolock = { 733#endif /* CONFIG_GFS2_FS_LOCKING_DLM */
734
735const struct file_operations *gfs2_file_fops_nolock = &(const struct file_operations){
764 .llseek = gfs2_llseek, 736 .llseek = gfs2_llseek,
765 .read = do_sync_read, 737 .read = do_sync_read,
766 .aio_read = generic_file_aio_read, 738 .aio_read = generic_file_aio_read,
@@ -773,10 +745,10 @@ const struct file_operations gfs2_file_fops_nolock = {
773 .fsync = gfs2_fsync, 745 .fsync = gfs2_fsync,
774 .splice_read = generic_file_splice_read, 746 .splice_read = generic_file_splice_read,
775 .splice_write = generic_file_splice_write, 747 .splice_write = generic_file_splice_write,
776 .setlease = gfs2_setlease, 748 .setlease = generic_setlease,
777}; 749};
778 750
779const struct file_operations gfs2_dir_fops_nolock = { 751const struct file_operations *gfs2_dir_fops_nolock = &(const struct file_operations){
780 .readdir = gfs2_readdir, 752 .readdir = gfs2_readdir,
781 .unlocked_ioctl = gfs2_ioctl, 753 .unlocked_ioctl = gfs2_ioctl,
782 .open = gfs2_open, 754 .open = gfs2_open,
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index f91eebdde58..51883b3ad89 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -17,7 +17,6 @@
17#include <linux/namei.h> 17#include <linux/namei.h>
18#include <linux/mount.h> 18#include <linux/mount.h>
19#include <linux/gfs2_ondisk.h> 19#include <linux/gfs2_ondisk.h>
20#include <linux/lm_interface.h>
21 20
22#include "gfs2.h" 21#include "gfs2.h"
23#include "incore.h" 22#include "incore.h"
@@ -25,7 +24,6 @@
25#include "glock.h" 24#include "glock.h"
26#include "glops.h" 25#include "glops.h"
27#include "inode.h" 26#include "inode.h"
28#include "mount.h"
29#include "recovery.h" 27#include "recovery.h"
30#include "rgrp.h" 28#include "rgrp.h"
31#include "super.h" 29#include "super.h"
@@ -64,7 +62,6 @@ static void gfs2_tune_init(struct gfs2_tune *gt)
64 gt->gt_quota_warn_period = 10; 62 gt->gt_quota_warn_period = 10;
65 gt->gt_quota_scale_num = 1; 63 gt->gt_quota_scale_num = 1;
66 gt->gt_quota_scale_den = 1; 64 gt->gt_quota_scale_den = 1;
67 gt->gt_quota_cache_secs = 300;
68 gt->gt_quota_quantum = 60; 65 gt->gt_quota_quantum = 60;
69 gt->gt_new_files_jdata = 0; 66 gt->gt_new_files_jdata = 0;
70 gt->gt_max_readahead = 1 << 18; 67 gt->gt_max_readahead = 1 << 18;
@@ -100,7 +97,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
100 mutex_init(&sdp->sd_jindex_mutex); 97 mutex_init(&sdp->sd_jindex_mutex);
101 98
102 INIT_LIST_HEAD(&sdp->sd_quota_list); 99 INIT_LIST_HEAD(&sdp->sd_quota_list);
103 spin_lock_init(&sdp->sd_quota_spin);
104 mutex_init(&sdp->sd_quota_mutex); 100 mutex_init(&sdp->sd_quota_mutex);
105 init_waitqueue_head(&sdp->sd_quota_wait); 101 init_waitqueue_head(&sdp->sd_quota_wait);
106 INIT_LIST_HEAD(&sdp->sd_trunc_list); 102 INIT_LIST_HEAD(&sdp->sd_trunc_list);
@@ -238,6 +234,7 @@ static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf)
238 234
239 memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN); 235 memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
240 memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); 236 memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
237 memcpy(sb->sb_uuid, str->sb_uuid, 16);
241} 238}
242 239
243/** 240/**
@@ -299,15 +296,15 @@ static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector)
299 __free_page(page); 296 __free_page(page);
300 return 0; 297 return 0;
301} 298}
299
302/** 300/**
303 * gfs2_read_sb - Read super block 301 * gfs2_read_sb - Read super block
304 * @sdp: The GFS2 superblock 302 * @sdp: The GFS2 superblock
305 * @gl: the glock for the superblock (assumed to be held)
306 * @silent: Don't print message if mount fails 303 * @silent: Don't print message if mount fails
307 * 304 *
308 */ 305 */
309 306
310static int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) 307static int gfs2_read_sb(struct gfs2_sbd *sdp, int silent)
311{ 308{
312 u32 hash_blocks, ind_blocks, leaf_blocks; 309 u32 hash_blocks, ind_blocks, leaf_blocks;
313 u32 tmp_blocks; 310 u32 tmp_blocks;
@@ -527,7 +524,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent)
527 return ret; 524 return ret;
528 } 525 }
529 526
530 ret = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); 527 ret = gfs2_read_sb(sdp, silent);
531 if (ret) { 528 if (ret) {
532 fs_err(sdp, "can't read superblock: %d\n", ret); 529 fs_err(sdp, "can't read superblock: %d\n", ret);
533 goto out; 530 goto out;
@@ -630,13 +627,13 @@ static int map_journal_extents(struct gfs2_sbd *sdp)
630 return rc; 627 return rc;
631} 628}
632 629
633static void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) 630static void gfs2_others_may_mount(struct gfs2_sbd *sdp)
634{ 631{
635 if (!sdp->sd_lockstruct.ls_ops->lm_others_may_mount) 632 char *message = "FIRSTMOUNT=Done";
636 return; 633 char *envp[] = { message, NULL };
637 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 634 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
638 sdp->sd_lockstruct.ls_ops->lm_others_may_mount( 635 ls->ls_first_done = 1;
639 sdp->sd_lockstruct.ls_lockspace); 636 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
640} 637}
641 638
642/** 639/**
@@ -796,7 +793,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
796 } 793 }
797 } 794 }
798 795
799 gfs2_lm_others_may_mount(sdp); 796 gfs2_others_may_mount(sdp);
800 } else if (!sdp->sd_args.ar_spectator) { 797 } else if (!sdp->sd_args.ar_spectator) {
801 error = gfs2_recover_journal(sdp->sd_jdesc); 798 error = gfs2_recover_journal(sdp->sd_jdesc);
802 if (error) { 799 if (error) {
@@ -1005,7 +1002,6 @@ static int init_threads(struct gfs2_sbd *sdp, int undo)
1005 goto fail_quotad; 1002 goto fail_quotad;
1006 1003
1007 sdp->sd_log_flush_time = jiffies; 1004 sdp->sd_log_flush_time = jiffies;
1008 sdp->sd_jindex_refresh_time = jiffies;
1009 1005
1010 p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); 1006 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
1011 error = IS_ERR(p); 1007 error = IS_ERR(p);
@@ -1033,6 +1029,17 @@ fail:
1033 return error; 1029 return error;
1034} 1030}
1035 1031
1032static const match_table_t nolock_tokens = {
1033 { Opt_jid, "jid=%d\n", },
1034 { Opt_err, NULL },
1035};
1036
1037static const struct lm_lockops nolock_ops = {
1038 .lm_proto_name = "lock_nolock",
1039 .lm_put_lock = kmem_cache_free,
1040 .lm_tokens = &nolock_tokens,
1041};
1042
1036/** 1043/**
1037 * gfs2_lm_mount - mount a locking protocol 1044 * gfs2_lm_mount - mount a locking protocol
1038 * @sdp: the filesystem 1045 * @sdp: the filesystem
@@ -1044,31 +1051,73 @@ fail:
1044 1051
1045static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) 1052static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
1046{ 1053{
1047 char *proto = sdp->sd_proto_name; 1054 const struct lm_lockops *lm;
1048 char *table = sdp->sd_table_name; 1055 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
1049 int flags = LM_MFLAG_CONV_NODROP; 1056 struct gfs2_args *args = &sdp->sd_args;
1050 int error; 1057 const char *proto = sdp->sd_proto_name;
1058 const char *table = sdp->sd_table_name;
1059 const char *fsname;
1060 char *o, *options;
1061 int ret;
1051 1062
1052 if (sdp->sd_args.ar_spectator) 1063 if (!strcmp("lock_nolock", proto)) {
1053 flags |= LM_MFLAG_SPECTATOR; 1064 lm = &nolock_ops;
1065 sdp->sd_args.ar_localflocks = 1;
1066 sdp->sd_args.ar_localcaching = 1;
1067#ifdef CONFIG_GFS2_FS_LOCKING_DLM
1068 } else if (!strcmp("lock_dlm", proto)) {
1069 lm = &gfs2_dlm_ops;
1070#endif
1071 } else {
1072 printk(KERN_INFO "GFS2: can't find protocol %s\n", proto);
1073 return -ENOENT;
1074 }
1054 1075
1055 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table); 1076 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
1056 1077
1057 error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata, 1078 ls->ls_ops = lm;
1058 gfs2_glock_cb, sdp, 1079 ls->ls_first = 1;
1059 GFS2_MIN_LVB_SIZE, flags, 1080 ls->ls_id = 0;
1060 &sdp->sd_lockstruct, &sdp->sd_kobj);
1061 if (error) {
1062 fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
1063 proto, table, sdp->sd_args.ar_hostdata);
1064 goto out;
1065 }
1066 1081
1067 if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) || 1082 for (options = args->ar_hostdata; (o = strsep(&options, ":")); ) {
1068 gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >= 1083 substring_t tmp[MAX_OPT_ARGS];
1069 GFS2_MIN_LVB_SIZE)) { 1084 int token, option;
1070 gfs2_unmount_lockproto(&sdp->sd_lockstruct); 1085
1071 goto out; 1086 if (!o || !*o)
1087 continue;
1088
1089 token = match_token(o, *lm->lm_tokens, tmp);
1090 switch (token) {
1091 case Opt_jid:
1092 ret = match_int(&tmp[0], &option);
1093 if (ret || option < 0)
1094 goto hostdata_error;
1095 ls->ls_jid = option;
1096 break;
1097 case Opt_id:
1098 ret = match_int(&tmp[0], &option);
1099 if (ret)
1100 goto hostdata_error;
1101 ls->ls_id = option;
1102 break;
1103 case Opt_first:
1104 ret = match_int(&tmp[0], &option);
1105 if (ret || (option != 0 && option != 1))
1106 goto hostdata_error;
1107 ls->ls_first = option;
1108 break;
1109 case Opt_nodir:
1110 ret = match_int(&tmp[0], &option);
1111 if (ret || (option != 0 && option != 1))
1112 goto hostdata_error;
1113 ls->ls_nodir = option;
1114 break;
1115 case Opt_err:
1116 default:
1117hostdata_error:
1118 fs_info(sdp, "unknown hostdata (%s)\n", o);
1119 return -EINVAL;
1120 }
1072 } 1121 }
1073 1122
1074 if (sdp->sd_args.ar_spectator) 1123 if (sdp->sd_args.ar_spectator)
@@ -1077,22 +1126,25 @@ static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
1077 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table, 1126 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
1078 sdp->sd_lockstruct.ls_jid); 1127 sdp->sd_lockstruct.ls_jid);
1079 1128
1080 fs_info(sdp, "Joined cluster. Now mounting FS...\n"); 1129 fsname = strchr(table, ':');
1081 1130 if (fsname)
1082 if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) && 1131 fsname++;
1083 !sdp->sd_args.ar_ignore_local_fs) { 1132 if (lm->lm_mount == NULL) {
1084 sdp->sd_args.ar_localflocks = 1; 1133 fs_info(sdp, "Now mounting FS...\n");
1085 sdp->sd_args.ar_localcaching = 1; 1134 return 0;
1086 } 1135 }
1087 1136 ret = lm->lm_mount(sdp, fsname);
1088out: 1137 if (ret == 0)
1089 return error; 1138 fs_info(sdp, "Joined cluster. Now mounting FS...\n");
1139 return ret;
1090} 1140}
1091 1141
1092void gfs2_lm_unmount(struct gfs2_sbd *sdp) 1142void gfs2_lm_unmount(struct gfs2_sbd *sdp)
1093{ 1143{
1094 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 1144 const struct lm_lockops *lm = sdp->sd_lockstruct.ls_ops;
1095 gfs2_unmount_lockproto(&sdp->sd_lockstruct); 1145 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) &&
1146 lm->lm_unmount)
1147 lm->lm_unmount(sdp);
1096} 1148}
1097 1149
1098/** 1150/**
@@ -1116,12 +1168,20 @@ static int fill_super(struct super_block *sb, void *data, int silent)
1116 return -ENOMEM; 1168 return -ENOMEM;
1117 } 1169 }
1118 1170
1119 error = gfs2_mount_args(sdp, (char *)data, 0); 1171 sdp->sd_args.ar_quota = GFS2_QUOTA_DEFAULT;
1172 sdp->sd_args.ar_data = GFS2_DATA_DEFAULT;
1173
1174 error = gfs2_mount_args(sdp, &sdp->sd_args, data);
1120 if (error) { 1175 if (error) {
1121 printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); 1176 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
1122 goto fail; 1177 goto fail;
1123 } 1178 }
1124 1179
1180 if (sdp->sd_args.ar_spectator)
1181 sb->s_flags |= MS_RDONLY;
1182 if (sdp->sd_args.ar_posix_acl)
1183 sb->s_flags |= MS_POSIXACL;
1184
1125 sb->s_magic = GFS2_MAGIC; 1185 sb->s_magic = GFS2_MAGIC;
1126 sb->s_op = &gfs2_super_ops; 1186 sb->s_op = &gfs2_super_ops;
1127 sb->s_export_op = &gfs2_export_ops; 1187 sb->s_export_op = &gfs2_export_ops;
@@ -1199,6 +1259,8 @@ fail_sb:
1199 dput(sdp->sd_root_dir); 1259 dput(sdp->sd_root_dir);
1200 if (sdp->sd_master_dir) 1260 if (sdp->sd_master_dir)
1201 dput(sdp->sd_master_dir); 1261 dput(sdp->sd_master_dir);
1262 if (sb->s_root)
1263 dput(sb->s_root);
1202 sb->s_root = NULL; 1264 sb->s_root = NULL;
1203fail_locking: 1265fail_locking:
1204 init_locking(sdp, &mount_gh, UNDO); 1266 init_locking(sdp, &mount_gh, UNDO);
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 49877546beb..abd5429ae28 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -18,7 +18,6 @@
18#include <linux/posix_acl.h> 18#include <linux/posix_acl.h>
19#include <linux/gfs2_ondisk.h> 19#include <linux/gfs2_ondisk.h>
20#include <linux/crc32.h> 20#include <linux/crc32.h>
21#include <linux/lm_interface.h>
22#include <linux/fiemap.h> 21#include <linux/fiemap.h>
23#include <asm/uaccess.h> 22#include <asm/uaccess.h>
24 23
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c
index 320323d0347..458019569dc 100644
--- a/fs/gfs2/ops_super.c
+++ b/fs/gfs2/ops_super.c
@@ -19,7 +19,6 @@
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/gfs2_ondisk.h> 20#include <linux/gfs2_ondisk.h>
21#include <linux/crc32.h> 21#include <linux/crc32.h>
22#include <linux/lm_interface.h>
23#include <linux/time.h> 22#include <linux/time.h>
24 23
25#include "gfs2.h" 24#include "gfs2.h"
@@ -27,7 +26,6 @@
27#include "glock.h" 26#include "glock.h"
28#include "inode.h" 27#include "inode.h"
29#include "log.h" 28#include "log.h"
30#include "mount.h"
31#include "quota.h" 29#include "quota.h"
32#include "recovery.h" 30#include "recovery.h"
33#include "rgrp.h" 31#include "rgrp.h"
@@ -40,6 +38,8 @@
40#include "bmap.h" 38#include "bmap.h"
41#include "meta_io.h" 39#include "meta_io.h"
42 40
41#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
42
43/** 43/**
44 * gfs2_write_inode - Make sure the inode is stable on the disk 44 * gfs2_write_inode - Make sure the inode is stable on the disk
45 * @inode: The inode 45 * @inode: The inode
@@ -435,25 +435,45 @@ static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
435static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) 435static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
436{ 436{
437 struct gfs2_sbd *sdp = sb->s_fs_info; 437 struct gfs2_sbd *sdp = sb->s_fs_info;
438 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
438 int error; 439 int error;
439 440
440 error = gfs2_mount_args(sdp, data, 1); 441 error = gfs2_mount_args(sdp, &args, data);
441 if (error) 442 if (error)
442 return error; 443 return error;
443 444
445 /* Not allowed to change locking details */
446 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
447 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
448 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
449 return -EINVAL;
450
451 /* Some flags must not be changed */
452 if (args_neq(&args, &sdp->sd_args, spectator) ||
453 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
454 args_neq(&args, &sdp->sd_args, localflocks) ||
455 args_neq(&args, &sdp->sd_args, localcaching) ||
456 args_neq(&args, &sdp->sd_args, meta))
457 return -EINVAL;
458
444 if (sdp->sd_args.ar_spectator) 459 if (sdp->sd_args.ar_spectator)
445 *flags |= MS_RDONLY; 460 *flags |= MS_RDONLY;
446 else { 461
447 if (*flags & MS_RDONLY) { 462 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
448 if (!(sb->s_flags & MS_RDONLY)) 463 if (*flags & MS_RDONLY)
449 error = gfs2_make_fs_ro(sdp); 464 error = gfs2_make_fs_ro(sdp);
450 } else if (!(*flags & MS_RDONLY) && 465 else
451 (sb->s_flags & MS_RDONLY)) {
452 error = gfs2_make_fs_rw(sdp); 466 error = gfs2_make_fs_rw(sdp);
453 } 467 if (error)
468 return error;
454 } 469 }
455 470
456 return error; 471 sdp->sd_args = args;
472 if (sdp->sd_args.ar_posix_acl)
473 sb->s_flags |= MS_POSIXACL;
474 else
475 sb->s_flags &= ~MS_POSIXACL;
476 return 0;
457} 477}
458 478
459/** 479/**
@@ -588,6 +608,8 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
588 } 608 }
589 seq_printf(s, ",data=%s", state); 609 seq_printf(s, ",data=%s", state);
590 } 610 }
611 if (args->ar_discard)
612 seq_printf(s, ",discard");
591 613
592 return 0; 614 return 0;
593} 615}
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index b08d09696b3..8d53f66b5bc 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -45,7 +45,6 @@
45#include <linux/fs.h> 45#include <linux/fs.h>
46#include <linux/bio.h> 46#include <linux/bio.h>
47#include <linux/gfs2_ondisk.h> 47#include <linux/gfs2_ondisk.h>
48#include <linux/lm_interface.h>
49#include <linux/kthread.h> 48#include <linux/kthread.h>
50#include <linux/freezer.h> 49#include <linux/freezer.h>
51 50
@@ -80,6 +79,51 @@ struct gfs2_quota_change_host {
80 u32 qc_id; 79 u32 qc_id;
81}; 80};
82 81
82static LIST_HEAD(qd_lru_list);
83static atomic_t qd_lru_count = ATOMIC_INIT(0);
84static spinlock_t qd_lru_lock = SPIN_LOCK_UNLOCKED;
85
86int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask)
87{
88 struct gfs2_quota_data *qd;
89 struct gfs2_sbd *sdp;
90
91 if (nr == 0)
92 goto out;
93
94 if (!(gfp_mask & __GFP_FS))
95 return -1;
96
97 spin_lock(&qd_lru_lock);
98 while (nr && !list_empty(&qd_lru_list)) {
99 qd = list_entry(qd_lru_list.next,
100 struct gfs2_quota_data, qd_reclaim);
101 sdp = qd->qd_gl->gl_sbd;
102
103 /* Free from the filesystem-specific list */
104 list_del(&qd->qd_list);
105
106 gfs2_assert_warn(sdp, !qd->qd_change);
107 gfs2_assert_warn(sdp, !qd->qd_slot_count);
108 gfs2_assert_warn(sdp, !qd->qd_bh_count);
109
110 gfs2_glock_put(qd->qd_gl);
111 atomic_dec(&sdp->sd_quota_count);
112
113 /* Delete it from the common reclaim list */
114 list_del_init(&qd->qd_reclaim);
115 atomic_dec(&qd_lru_count);
116 spin_unlock(&qd_lru_lock);
117 kmem_cache_free(gfs2_quotad_cachep, qd);
118 spin_lock(&qd_lru_lock);
119 nr--;
120 }
121 spin_unlock(&qd_lru_lock);
122
123out:
124 return (atomic_read(&qd_lru_count) * sysctl_vfs_cache_pressure) / 100;
125}
126
83static u64 qd2offset(struct gfs2_quota_data *qd) 127static u64 qd2offset(struct gfs2_quota_data *qd)
84{ 128{
85 u64 offset; 129 u64 offset;
@@ -100,22 +144,18 @@ static int qd_alloc(struct gfs2_sbd *sdp, int user, u32 id,
100 if (!qd) 144 if (!qd)
101 return -ENOMEM; 145 return -ENOMEM;
102 146
103 qd->qd_count = 1; 147 atomic_set(&qd->qd_count, 1);
104 qd->qd_id = id; 148 qd->qd_id = id;
105 if (user) 149 if (user)
106 set_bit(QDF_USER, &qd->qd_flags); 150 set_bit(QDF_USER, &qd->qd_flags);
107 qd->qd_slot = -1; 151 qd->qd_slot = -1;
152 INIT_LIST_HEAD(&qd->qd_reclaim);
108 153
109 error = gfs2_glock_get(sdp, 2 * (u64)id + !user, 154 error = gfs2_glock_get(sdp, 2 * (u64)id + !user,
110 &gfs2_quota_glops, CREATE, &qd->qd_gl); 155 &gfs2_quota_glops, CREATE, &qd->qd_gl);
111 if (error) 156 if (error)
112 goto fail; 157 goto fail;
113 158
114 error = gfs2_lvb_hold(qd->qd_gl);
115 gfs2_glock_put(qd->qd_gl);
116 if (error)
117 goto fail;
118
119 *qdp = qd; 159 *qdp = qd;
120 160
121 return 0; 161 return 0;
@@ -135,11 +175,17 @@ static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
135 175
136 for (;;) { 176 for (;;) {
137 found = 0; 177 found = 0;
138 spin_lock(&sdp->sd_quota_spin); 178 spin_lock(&qd_lru_lock);
139 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { 179 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
140 if (qd->qd_id == id && 180 if (qd->qd_id == id &&
141 !test_bit(QDF_USER, &qd->qd_flags) == !user) { 181 !test_bit(QDF_USER, &qd->qd_flags) == !user) {
142 qd->qd_count++; 182 if (!atomic_read(&qd->qd_count) &&
183 !list_empty(&qd->qd_reclaim)) {
184 /* Remove it from reclaim list */
185 list_del_init(&qd->qd_reclaim);
186 atomic_dec(&qd_lru_count);
187 }
188 atomic_inc(&qd->qd_count);
143 found = 1; 189 found = 1;
144 break; 190 break;
145 } 191 }
@@ -155,11 +201,11 @@ static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
155 new_qd = NULL; 201 new_qd = NULL;
156 } 202 }
157 203
158 spin_unlock(&sdp->sd_quota_spin); 204 spin_unlock(&qd_lru_lock);
159 205
160 if (qd || !create) { 206 if (qd || !create) {
161 if (new_qd) { 207 if (new_qd) {
162 gfs2_lvb_unhold(new_qd->qd_gl); 208 gfs2_glock_put(new_qd->qd_gl);
163 kmem_cache_free(gfs2_quotad_cachep, new_qd); 209 kmem_cache_free(gfs2_quotad_cachep, new_qd);
164 } 210 }
165 *qdp = qd; 211 *qdp = qd;
@@ -175,21 +221,18 @@ static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
175static void qd_hold(struct gfs2_quota_data *qd) 221static void qd_hold(struct gfs2_quota_data *qd)
176{ 222{
177 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 223 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
178 224 gfs2_assert(sdp, atomic_read(&qd->qd_count));
179 spin_lock(&sdp->sd_quota_spin); 225 atomic_inc(&qd->qd_count);
180 gfs2_assert(sdp, qd->qd_count);
181 qd->qd_count++;
182 spin_unlock(&sdp->sd_quota_spin);
183} 226}
184 227
185static void qd_put(struct gfs2_quota_data *qd) 228static void qd_put(struct gfs2_quota_data *qd)
186{ 229{
187 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 230 if (atomic_dec_and_lock(&qd->qd_count, &qd_lru_lock)) {
188 spin_lock(&sdp->sd_quota_spin); 231 /* Add to the reclaim list */
189 gfs2_assert(sdp, qd->qd_count); 232 list_add_tail(&qd->qd_reclaim, &qd_lru_list);
190 if (!--qd->qd_count) 233 atomic_inc(&qd_lru_count);
191 qd->qd_last_touched = jiffies; 234 spin_unlock(&qd_lru_lock);
192 spin_unlock(&sdp->sd_quota_spin); 235 }
193} 236}
194 237
195static int slot_get(struct gfs2_quota_data *qd) 238static int slot_get(struct gfs2_quota_data *qd)
@@ -198,10 +241,10 @@ static int slot_get(struct gfs2_quota_data *qd)
198 unsigned int c, o = 0, b; 241 unsigned int c, o = 0, b;
199 unsigned char byte = 0; 242 unsigned char byte = 0;
200 243
201 spin_lock(&sdp->sd_quota_spin); 244 spin_lock(&qd_lru_lock);
202 245
203 if (qd->qd_slot_count++) { 246 if (qd->qd_slot_count++) {
204 spin_unlock(&sdp->sd_quota_spin); 247 spin_unlock(&qd_lru_lock);
205 return 0; 248 return 0;
206 } 249 }
207 250
@@ -225,13 +268,13 @@ found:
225 268
226 sdp->sd_quota_bitmap[c][o] |= 1 << b; 269 sdp->sd_quota_bitmap[c][o] |= 1 << b;
227 270
228 spin_unlock(&sdp->sd_quota_spin); 271 spin_unlock(&qd_lru_lock);
229 272
230 return 0; 273 return 0;
231 274
232fail: 275fail:
233 qd->qd_slot_count--; 276 qd->qd_slot_count--;
234 spin_unlock(&sdp->sd_quota_spin); 277 spin_unlock(&qd_lru_lock);
235 return -ENOSPC; 278 return -ENOSPC;
236} 279}
237 280
@@ -239,23 +282,23 @@ static void slot_hold(struct gfs2_quota_data *qd)
239{ 282{
240 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 283 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
241 284
242 spin_lock(&sdp->sd_quota_spin); 285 spin_lock(&qd_lru_lock);
243 gfs2_assert(sdp, qd->qd_slot_count); 286 gfs2_assert(sdp, qd->qd_slot_count);
244 qd->qd_slot_count++; 287 qd->qd_slot_count++;
245 spin_unlock(&sdp->sd_quota_spin); 288 spin_unlock(&qd_lru_lock);
246} 289}
247 290
248static void slot_put(struct gfs2_quota_data *qd) 291static void slot_put(struct gfs2_quota_data *qd)
249{ 292{
250 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 293 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
251 294
252 spin_lock(&sdp->sd_quota_spin); 295 spin_lock(&qd_lru_lock);
253 gfs2_assert(sdp, qd->qd_slot_count); 296 gfs2_assert(sdp, qd->qd_slot_count);
254 if (!--qd->qd_slot_count) { 297 if (!--qd->qd_slot_count) {
255 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0); 298 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0);
256 qd->qd_slot = -1; 299 qd->qd_slot = -1;
257 } 300 }
258 spin_unlock(&sdp->sd_quota_spin); 301 spin_unlock(&qd_lru_lock);
259} 302}
260 303
261static int bh_get(struct gfs2_quota_data *qd) 304static int bh_get(struct gfs2_quota_data *qd)
@@ -330,7 +373,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
330 if (sdp->sd_vfs->s_flags & MS_RDONLY) 373 if (sdp->sd_vfs->s_flags & MS_RDONLY)
331 return 0; 374 return 0;
332 375
333 spin_lock(&sdp->sd_quota_spin); 376 spin_lock(&qd_lru_lock);
334 377
335 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { 378 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
336 if (test_bit(QDF_LOCKED, &qd->qd_flags) || 379 if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
@@ -341,8 +384,8 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
341 list_move_tail(&qd->qd_list, &sdp->sd_quota_list); 384 list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
342 385
343 set_bit(QDF_LOCKED, &qd->qd_flags); 386 set_bit(QDF_LOCKED, &qd->qd_flags);
344 gfs2_assert_warn(sdp, qd->qd_count); 387 gfs2_assert_warn(sdp, atomic_read(&qd->qd_count));
345 qd->qd_count++; 388 atomic_inc(&qd->qd_count);
346 qd->qd_change_sync = qd->qd_change; 389 qd->qd_change_sync = qd->qd_change;
347 gfs2_assert_warn(sdp, qd->qd_slot_count); 390 gfs2_assert_warn(sdp, qd->qd_slot_count);
348 qd->qd_slot_count++; 391 qd->qd_slot_count++;
@@ -354,7 +397,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
354 if (!found) 397 if (!found)
355 qd = NULL; 398 qd = NULL;
356 399
357 spin_unlock(&sdp->sd_quota_spin); 400 spin_unlock(&qd_lru_lock);
358 401
359 if (qd) { 402 if (qd) {
360 gfs2_assert_warn(sdp, qd->qd_change_sync); 403 gfs2_assert_warn(sdp, qd->qd_change_sync);
@@ -379,24 +422,24 @@ static int qd_trylock(struct gfs2_quota_data *qd)
379 if (sdp->sd_vfs->s_flags & MS_RDONLY) 422 if (sdp->sd_vfs->s_flags & MS_RDONLY)
380 return 0; 423 return 0;
381 424
382 spin_lock(&sdp->sd_quota_spin); 425 spin_lock(&qd_lru_lock);
383 426
384 if (test_bit(QDF_LOCKED, &qd->qd_flags) || 427 if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
385 !test_bit(QDF_CHANGE, &qd->qd_flags)) { 428 !test_bit(QDF_CHANGE, &qd->qd_flags)) {
386 spin_unlock(&sdp->sd_quota_spin); 429 spin_unlock(&qd_lru_lock);
387 return 0; 430 return 0;
388 } 431 }
389 432
390 list_move_tail(&qd->qd_list, &sdp->sd_quota_list); 433 list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
391 434
392 set_bit(QDF_LOCKED, &qd->qd_flags); 435 set_bit(QDF_LOCKED, &qd->qd_flags);
393 gfs2_assert_warn(sdp, qd->qd_count); 436 gfs2_assert_warn(sdp, atomic_read(&qd->qd_count));
394 qd->qd_count++; 437 atomic_inc(&qd->qd_count);
395 qd->qd_change_sync = qd->qd_change; 438 qd->qd_change_sync = qd->qd_change;
396 gfs2_assert_warn(sdp, qd->qd_slot_count); 439 gfs2_assert_warn(sdp, qd->qd_slot_count);
397 qd->qd_slot_count++; 440 qd->qd_slot_count++;
398 441
399 spin_unlock(&sdp->sd_quota_spin); 442 spin_unlock(&qd_lru_lock);
400 443
401 gfs2_assert_warn(sdp, qd->qd_change_sync); 444 gfs2_assert_warn(sdp, qd->qd_change_sync);
402 if (bh_get(qd)) { 445 if (bh_get(qd)) {
@@ -556,9 +599,9 @@ static void do_qc(struct gfs2_quota_data *qd, s64 change)
556 x = be64_to_cpu(qc->qc_change) + change; 599 x = be64_to_cpu(qc->qc_change) + change;
557 qc->qc_change = cpu_to_be64(x); 600 qc->qc_change = cpu_to_be64(x);
558 601
559 spin_lock(&sdp->sd_quota_spin); 602 spin_lock(&qd_lru_lock);
560 qd->qd_change = x; 603 qd->qd_change = x;
561 spin_unlock(&sdp->sd_quota_spin); 604 spin_unlock(&qd_lru_lock);
562 605
563 if (!x) { 606 if (!x) {
564 gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags)); 607 gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags));
@@ -802,8 +845,8 @@ restart:
802 loff_t pos; 845 loff_t pos;
803 gfs2_glock_dq_uninit(q_gh); 846 gfs2_glock_dq_uninit(q_gh);
804 error = gfs2_glock_nq_init(qd->qd_gl, 847 error = gfs2_glock_nq_init(qd->qd_gl,
805 LM_ST_EXCLUSIVE, GL_NOCACHE, 848 LM_ST_EXCLUSIVE, GL_NOCACHE,
806 q_gh); 849 q_gh);
807 if (error) 850 if (error)
808 return error; 851 return error;
809 852
@@ -820,7 +863,6 @@ restart:
820 863
821 gfs2_glock_dq_uninit(&i_gh); 864 gfs2_glock_dq_uninit(&i_gh);
822 865
823
824 gfs2_quota_in(&q, buf); 866 gfs2_quota_in(&q, buf);
825 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; 867 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
826 qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC); 868 qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC);
@@ -890,9 +932,9 @@ static int need_sync(struct gfs2_quota_data *qd)
890 if (!qd->qd_qb.qb_limit) 932 if (!qd->qd_qb.qb_limit)
891 return 0; 933 return 0;
892 934
893 spin_lock(&sdp->sd_quota_spin); 935 spin_lock(&qd_lru_lock);
894 value = qd->qd_change; 936 value = qd->qd_change;
895 spin_unlock(&sdp->sd_quota_spin); 937 spin_unlock(&qd_lru_lock);
896 938
897 spin_lock(&gt->gt_spin); 939 spin_lock(&gt->gt_spin);
898 num = gt->gt_quota_scale_num; 940 num = gt->gt_quota_scale_num;
@@ -985,9 +1027,9 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
985 continue; 1027 continue;
986 1028
987 value = (s64)be64_to_cpu(qd->qd_qb.qb_value); 1029 value = (s64)be64_to_cpu(qd->qd_qb.qb_value);
988 spin_lock(&sdp->sd_quota_spin); 1030 spin_lock(&qd_lru_lock);
989 value += qd->qd_change; 1031 value += qd->qd_change;
990 spin_unlock(&sdp->sd_quota_spin); 1032 spin_unlock(&qd_lru_lock);
991 1033
992 if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) { 1034 if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) {
993 print_message(qd, "exceeded"); 1035 print_message(qd, "exceeded");
@@ -1171,13 +1213,12 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
1171 qd->qd_change = qc.qc_change; 1213 qd->qd_change = qc.qc_change;
1172 qd->qd_slot = slot; 1214 qd->qd_slot = slot;
1173 qd->qd_slot_count = 1; 1215 qd->qd_slot_count = 1;
1174 qd->qd_last_touched = jiffies;
1175 1216
1176 spin_lock(&sdp->sd_quota_spin); 1217 spin_lock(&qd_lru_lock);
1177 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1); 1218 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1);
1178 list_add(&qd->qd_list, &sdp->sd_quota_list); 1219 list_add(&qd->qd_list, &sdp->sd_quota_list);
1179 atomic_inc(&sdp->sd_quota_count); 1220 atomic_inc(&sdp->sd_quota_count);
1180 spin_unlock(&sdp->sd_quota_spin); 1221 spin_unlock(&qd_lru_lock);
1181 1222
1182 found++; 1223 found++;
1183 } 1224 }
@@ -1197,73 +1238,48 @@ fail:
1197 return error; 1238 return error;
1198} 1239}
1199 1240
1200static void gfs2_quota_scan(struct gfs2_sbd *sdp)
1201{
1202 struct gfs2_quota_data *qd, *safe;
1203 LIST_HEAD(dead);
1204
1205 spin_lock(&sdp->sd_quota_spin);
1206 list_for_each_entry_safe(qd, safe, &sdp->sd_quota_list, qd_list) {
1207 if (!qd->qd_count &&
1208 time_after_eq(jiffies, qd->qd_last_touched +
1209 gfs2_tune_get(sdp, gt_quota_cache_secs) * HZ)) {
1210 list_move(&qd->qd_list, &dead);
1211 gfs2_assert_warn(sdp,
1212 atomic_read(&sdp->sd_quota_count) > 0);
1213 atomic_dec(&sdp->sd_quota_count);
1214 }
1215 }
1216 spin_unlock(&sdp->sd_quota_spin);
1217
1218 while (!list_empty(&dead)) {
1219 qd = list_entry(dead.next, struct gfs2_quota_data, qd_list);
1220 list_del(&qd->qd_list);
1221
1222 gfs2_assert_warn(sdp, !qd->qd_change);
1223 gfs2_assert_warn(sdp, !qd->qd_slot_count);
1224 gfs2_assert_warn(sdp, !qd->qd_bh_count);
1225
1226 gfs2_lvb_unhold(qd->qd_gl);
1227 kmem_cache_free(gfs2_quotad_cachep, qd);
1228 }
1229}
1230
1231void gfs2_quota_cleanup(struct gfs2_sbd *sdp) 1241void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
1232{ 1242{
1233 struct list_head *head = &sdp->sd_quota_list; 1243 struct list_head *head = &sdp->sd_quota_list;
1234 struct gfs2_quota_data *qd; 1244 struct gfs2_quota_data *qd;
1235 unsigned int x; 1245 unsigned int x;
1236 1246
1237 spin_lock(&sdp->sd_quota_spin); 1247 spin_lock(&qd_lru_lock);
1238 while (!list_empty(head)) { 1248 while (!list_empty(head)) {
1239 qd = list_entry(head->prev, struct gfs2_quota_data, qd_list); 1249 qd = list_entry(head->prev, struct gfs2_quota_data, qd_list);
1240 1250
1241 if (qd->qd_count > 1 || 1251 if (atomic_read(&qd->qd_count) > 1 ||
1242 (qd->qd_count && !test_bit(QDF_CHANGE, &qd->qd_flags))) { 1252 (atomic_read(&qd->qd_count) &&
1253 !test_bit(QDF_CHANGE, &qd->qd_flags))) {
1243 list_move(&qd->qd_list, head); 1254 list_move(&qd->qd_list, head);
1244 spin_unlock(&sdp->sd_quota_spin); 1255 spin_unlock(&qd_lru_lock);
1245 schedule(); 1256 schedule();
1246 spin_lock(&sdp->sd_quota_spin); 1257 spin_lock(&qd_lru_lock);
1247 continue; 1258 continue;
1248 } 1259 }
1249 1260
1250 list_del(&qd->qd_list); 1261 list_del(&qd->qd_list);
1262 /* Also remove if this qd exists in the reclaim list */
1263 if (!list_empty(&qd->qd_reclaim)) {
1264 list_del_init(&qd->qd_reclaim);
1265 atomic_dec(&qd_lru_count);
1266 }
1251 atomic_dec(&sdp->sd_quota_count); 1267 atomic_dec(&sdp->sd_quota_count);
1252 spin_unlock(&sdp->sd_quota_spin); 1268 spin_unlock(&qd_lru_lock);
1253 1269
1254 if (!qd->qd_count) { 1270 if (!atomic_read(&qd->qd_count)) {
1255 gfs2_assert_warn(sdp, !qd->qd_change); 1271 gfs2_assert_warn(sdp, !qd->qd_change);
1256 gfs2_assert_warn(sdp, !qd->qd_slot_count); 1272 gfs2_assert_warn(sdp, !qd->qd_slot_count);
1257 } else 1273 } else
1258 gfs2_assert_warn(sdp, qd->qd_slot_count == 1); 1274 gfs2_assert_warn(sdp, qd->qd_slot_count == 1);
1259 gfs2_assert_warn(sdp, !qd->qd_bh_count); 1275 gfs2_assert_warn(sdp, !qd->qd_bh_count);
1260 1276
1261 gfs2_lvb_unhold(qd->qd_gl); 1277 gfs2_glock_put(qd->qd_gl);
1262 kmem_cache_free(gfs2_quotad_cachep, qd); 1278 kmem_cache_free(gfs2_quotad_cachep, qd);
1263 1279
1264 spin_lock(&sdp->sd_quota_spin); 1280 spin_lock(&qd_lru_lock);
1265 } 1281 }
1266 spin_unlock(&sdp->sd_quota_spin); 1282 spin_unlock(&qd_lru_lock);
1267 1283
1268 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count)); 1284 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count));
1269 1285
@@ -1341,9 +1357,6 @@ int gfs2_quotad(void *data)
1341 quotad_check_timeo(sdp, "sync", gfs2_quota_sync, t, 1357 quotad_check_timeo(sdp, "sync", gfs2_quota_sync, t,
1342 &quotad_timeo, &tune->gt_quota_quantum); 1358 &quotad_timeo, &tune->gt_quota_quantum);
1343 1359
1344 /* FIXME: This should be turned into a shrinker */
1345 gfs2_quota_scan(sdp);
1346
1347 /* Check for & recover partially truncated inodes */ 1360 /* Check for & recover partially truncated inodes */
1348 quotad_check_trunc_list(sdp); 1361 quotad_check_trunc_list(sdp);
1349 1362
diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h
index cec9032be97..0fa5fa63d0e 100644
--- a/fs/gfs2/quota.h
+++ b/fs/gfs2/quota.h
@@ -49,4 +49,6 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip)
49 return ret; 49 return ret;
50} 50}
51 51
52extern int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask);
53
52#endif /* __QUOTA_DOT_H__ */ 54#endif /* __QUOTA_DOT_H__ */
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index efd09c3d2b2..247e8f7d6b3 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/lm_interface.h>
17#include <linux/kthread.h> 16#include <linux/kthread.h>
18#include <linux/freezer.h> 17#include <linux/freezer.h>
19 18
@@ -427,20 +426,23 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header_host *hea
427} 426}
428 427
429 428
430static void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, 429static void gfs2_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
431 unsigned int message) 430 unsigned int message)
432{ 431{
433 if (!sdp->sd_lockstruct.ls_ops->lm_recovery_done) 432 char env_jid[20];
434 return; 433 char env_status[20];
435 434 char *envp[] = { env_jid, env_status, NULL };
436 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 435 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
437 sdp->sd_lockstruct.ls_ops->lm_recovery_done( 436 ls->ls_recover_jid_done = jid;
438 sdp->sd_lockstruct.ls_lockspace, jid, message); 437 ls->ls_recover_jid_status = message;
438 sprintf(env_jid, "JID=%d", jid);
439 sprintf(env_status, "RECOVERY=%s",
440 message == LM_RD_SUCCESS ? "Done" : "Failed");
441 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
439} 442}
440 443
441
442/** 444/**
443 * gfs2_recover_journal - recovery a given journal 445 * gfs2_recover_journal - recover a given journal
444 * @jd: the struct gfs2_jdesc describing the journal 446 * @jd: the struct gfs2_jdesc describing the journal
445 * 447 *
446 * Acquire the journal's lock, check to see if the journal is clean, and 448 * Acquire the journal's lock, check to see if the journal is clean, and
@@ -561,7 +563,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
561 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) 563 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid)
562 gfs2_glock_dq_uninit(&ji_gh); 564 gfs2_glock_dq_uninit(&ji_gh);
563 565
564 gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS); 566 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS);
565 567
566 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) 568 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid)
567 gfs2_glock_dq_uninit(&j_gh); 569 gfs2_glock_dq_uninit(&j_gh);
@@ -581,7 +583,7 @@ fail_gunlock_j:
581 fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done"); 583 fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done");
582 584
583fail: 585fail:
584 gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP); 586 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP);
585 return error; 587 return error;
586} 588}
587 589
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 8b01c635d92..f03d024038e 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -13,8 +13,8 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17#include <linux/prefetch.h> 16#include <linux/prefetch.h>
17#include <linux/blkdev.h>
18 18
19#include "gfs2.h" 19#include "gfs2.h"
20#include "incore.h" 20#include "incore.h"
@@ -132,81 +132,90 @@ static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd,
132} 132}
133 133
134/** 134/**
135 * gfs2_bit_search
136 * @ptr: Pointer to bitmap data
137 * @mask: Mask to use (normally 0x55555.... but adjusted for search start)
138 * @state: The state we are searching for
139 *
140 * We xor the bitmap data with a patter which is the bitwise opposite
141 * of what we are looking for, this gives rise to a pattern of ones
142 * wherever there is a match. Since we have two bits per entry, we
143 * take this pattern, shift it down by one place and then and it with
144 * the original. All the even bit positions (0,2,4, etc) then represent
145 * successful matches, so we mask with 0x55555..... to remove the unwanted
146 * odd bit positions.
147 *
148 * This allows searching of a whole u64 at once (32 blocks) with a
149 * single test (on 64 bit arches).
150 */
151
152static inline u64 gfs2_bit_search(const __le64 *ptr, u64 mask, u8 state)
153{
154 u64 tmp;
155 static const u64 search[] = {
156 [0] = 0xffffffffffffffffULL,
157 [1] = 0xaaaaaaaaaaaaaaaaULL,
158 [2] = 0x5555555555555555ULL,
159 [3] = 0x0000000000000000ULL,
160 };
161 tmp = le64_to_cpu(*ptr) ^ search[state];
162 tmp &= (tmp >> 1);
163 tmp &= mask;
164 return tmp;
165}
166
167/**
135 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing 168 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing
136 * a block in a given allocation state. 169 * a block in a given allocation state.
137 * @buffer: the buffer that holds the bitmaps 170 * @buffer: the buffer that holds the bitmaps
138 * @buflen: the length (in bytes) of the buffer 171 * @len: the length (in bytes) of the buffer
139 * @goal: start search at this block's bit-pair (within @buffer) 172 * @goal: start search at this block's bit-pair (within @buffer)
140 * @old_state: GFS2_BLKST_XXX the state of the block we're looking for. 173 * @state: GFS2_BLKST_XXX the state of the block we're looking for.
141 * 174 *
142 * Scope of @goal and returned block number is only within this bitmap buffer, 175 * Scope of @goal and returned block number is only within this bitmap buffer,
143 * not entire rgrp or filesystem. @buffer will be offset from the actual 176 * not entire rgrp or filesystem. @buffer will be offset from the actual
144 * beginning of a bitmap block buffer, skipping any header structures. 177 * beginning of a bitmap block buffer, skipping any header structures, but
178 * headers are always a multiple of 64 bits long so that the buffer is
179 * always aligned to a 64 bit boundary.
180 *
181 * The size of the buffer is in bytes, but is it assumed that it is
182 * always ok to to read a complete multiple of 64 bits at the end
183 * of the block in case the end is no aligned to a natural boundary.
145 * 184 *
146 * Return: the block number (bitmap buffer scope) that was found 185 * Return: the block number (bitmap buffer scope) that was found
147 */ 186 */
148 187
149static u32 gfs2_bitfit(const u8 *buffer, unsigned int buflen, u32 goal, 188static u32 gfs2_bitfit(const u8 *buf, const unsigned int len,
150 u8 old_state) 189 u32 goal, u8 state)
151{ 190{
152 const u8 *byte, *start, *end; 191 u32 spoint = (goal << 1) & ((8*sizeof(u64)) - 1);
153 int bit, startbit; 192 const __le64 *ptr = ((__le64 *)buf) + (goal >> 5);
154 u32 g1, g2, misaligned; 193 const __le64 *end = (__le64 *)(buf + ALIGN(len, sizeof(u64)));
155 unsigned long *plong; 194 u64 tmp;
156 unsigned long lskipval; 195 u64 mask = 0x5555555555555555ULL;
157 196 u32 bit;
158 lskipval = (old_state & GFS2_BLKST_USED) ? LBITSKIP00 : LBITSKIP55; 197
159 g1 = (goal / GFS2_NBBY); 198 BUG_ON(state > 3);
160 start = buffer + g1; 199
161 byte = start; 200 /* Mask off bits we don't care about at the start of the search */
162 end = buffer + buflen; 201 mask <<= spoint;
163 g2 = ALIGN(g1, sizeof(unsigned long)); 202 tmp = gfs2_bit_search(ptr, mask, state);
164 plong = (unsigned long *)(buffer + g2); 203 ptr++;
165 startbit = bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; 204 while(tmp == 0 && ptr < end) {
166 misaligned = g2 - g1; 205 tmp = gfs2_bit_search(ptr, 0x5555555555555555ULL, state);
167 if (!misaligned) 206 ptr++;
168 goto ulong_aligned;
169/* parse the bitmap a byte at a time */
170misaligned:
171 while (byte < end) {
172 if (((*byte >> bit) & GFS2_BIT_MASK) == old_state) {
173 return goal +
174 (((byte - start) * GFS2_NBBY) +
175 ((bit - startbit) >> 1));
176 }
177 bit += GFS2_BIT_SIZE;
178 if (bit >= GFS2_NBBY * GFS2_BIT_SIZE) {
179 bit = 0;
180 byte++;
181 misaligned--;
182 if (!misaligned) {
183 plong = (unsigned long *)byte;
184 goto ulong_aligned;
185 }
186 }
187 }
188 return BFITNOENT;
189
190/* parse the bitmap a unsigned long at a time */
191ulong_aligned:
192 /* Stop at "end - 1" or else prefetch can go past the end and segfault.
193 We could "if" it but we'd lose some of the performance gained.
194 This way will only slow down searching the very last 4/8 bytes
195 depending on architecture. I've experimented with several ways
196 of writing this section such as using an else before the goto
197 but this one seems to be the fastest. */
198 while ((unsigned char *)plong < end - sizeof(unsigned long)) {
199 prefetch(plong + 1);
200 if (((*plong) & LBITMASK) != lskipval)
201 break;
202 plong++;
203 }
204 if ((unsigned char *)plong < end) {
205 byte = (const u8 *)plong;
206 misaligned += sizeof(unsigned long) - 1;
207 goto misaligned;
208 } 207 }
209 return BFITNOENT; 208 /* Mask off any bits which are more than len bytes from the start */
209 if (ptr == end && (len & (sizeof(u64) - 1)))
210 tmp &= (((u64)~0) >> (64 - 8*(len & (sizeof(u64) - 1))));
211 /* Didn't find anything, so return */
212 if (tmp == 0)
213 return BFITNOENT;
214 ptr--;
215 bit = fls64(tmp);
216 bit--; /* fls64 always adds one to the bit count */
217 bit /= 2; /* two bits per entry in the bitmap */
218 return (((const unsigned char *)ptr - buf) * GFS2_NBBY) + bit;
210} 219}
211 220
212/** 221/**
@@ -831,6 +840,58 @@ void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd)
831 spin_unlock(&sdp->sd_rindex_spin); 840 spin_unlock(&sdp->sd_rindex_spin);
832} 841}
833 842
843static void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
844 const struct gfs2_bitmap *bi)
845{
846 struct super_block *sb = sdp->sd_vfs;
847 struct block_device *bdev = sb->s_bdev;
848 const unsigned int sects_per_blk = sdp->sd_sb.sb_bsize /
849 bdev_hardsect_size(sb->s_bdev);
850 u64 blk;
851 sector_t start = 0;
852 sector_t nr_sects = 0;
853 int rv;
854 unsigned int x;
855
856 for (x = 0; x < bi->bi_len; x++) {
857 const u8 *orig = bi->bi_bh->b_data + bi->bi_offset + x;
858 const u8 *clone = bi->bi_clone + bi->bi_offset + x;
859 u8 diff = ~(*orig | (*orig >> 1)) & (*clone | (*clone >> 1));
860 diff &= 0x55;
861 if (diff == 0)
862 continue;
863 blk = offset + ((bi->bi_start + x) * GFS2_NBBY);
864 blk *= sects_per_blk; /* convert to sectors */
865 while(diff) {
866 if (diff & 1) {
867 if (nr_sects == 0)
868 goto start_new_extent;
869 if ((start + nr_sects) != blk) {
870 rv = blkdev_issue_discard(bdev, start,
871 nr_sects, GFP_NOFS);
872 if (rv)
873 goto fail;
874 nr_sects = 0;
875start_new_extent:
876 start = blk;
877 }
878 nr_sects += sects_per_blk;
879 }
880 diff >>= 2;
881 blk += sects_per_blk;
882 }
883 }
884 if (nr_sects) {
885 rv = blkdev_issue_discard(bdev, start, nr_sects, GFP_NOFS);
886 if (rv)
887 goto fail;
888 }
889 return;
890fail:
891 fs_warn(sdp, "error %d on discard request, turning discards off for this filesystem", rv);
892 sdp->sd_args.ar_discard = 0;
893}
894
834void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd) 895void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
835{ 896{
836 struct gfs2_sbd *sdp = rgd->rd_sbd; 897 struct gfs2_sbd *sdp = rgd->rd_sbd;
@@ -841,6 +902,8 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
841 struct gfs2_bitmap *bi = rgd->rd_bits + x; 902 struct gfs2_bitmap *bi = rgd->rd_bits + x;
842 if (!bi->bi_clone) 903 if (!bi->bi_clone)
843 continue; 904 continue;
905 if (sdp->sd_args.ar_discard)
906 gfs2_rgrp_send_discards(sdp, rgd->rd_data0, bi);
844 memcpy(bi->bi_clone + bi->bi_offset, 907 memcpy(bi->bi_clone + bi->bi_offset,
845 bi->bi_bh->b_data + bi->bi_offset, bi->bi_len); 908 bi->bi_bh->b_data + bi->bi_offset, bi->bi_len);
846 } 909 }
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 141b781f2fc..601913e0a48 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -15,7 +15,6 @@
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
17#include <linux/bio.h> 17#include <linux/bio.h>
18#include <linux/lm_interface.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
21#include "incore.h" 20#include "incore.h"
@@ -339,7 +338,6 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
339 struct gfs2_holder *t_gh) 338 struct gfs2_holder *t_gh)
340{ 339{
341 struct gfs2_inode *ip; 340 struct gfs2_inode *ip;
342 struct gfs2_holder ji_gh;
343 struct gfs2_jdesc *jd; 341 struct gfs2_jdesc *jd;
344 struct lfcc *lfcc; 342 struct lfcc *lfcc;
345 LIST_HEAD(list); 343 LIST_HEAD(list);
@@ -387,7 +385,6 @@ out:
387 gfs2_glock_dq_uninit(&lfcc->gh); 385 gfs2_glock_dq_uninit(&lfcc->gh);
388 kfree(lfcc); 386 kfree(lfcc);
389 } 387 }
390 gfs2_glock_dq_uninit(&ji_gh);
391 return error; 388 return error;
392} 389}
393 390
diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h
index f6b8b00ad88..b56413e3e40 100644
--- a/fs/gfs2/super.h
+++ b/fs/gfs2/super.h
@@ -14,7 +14,7 @@
14#include <linux/dcache.h> 14#include <linux/dcache.h>
15#include "incore.h" 15#include "incore.h"
16 16
17void gfs2_lm_unmount(struct gfs2_sbd *sdp); 17extern void gfs2_lm_unmount(struct gfs2_sbd *sdp);
18 18
19static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp) 19static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp)
20{ 20{
@@ -27,27 +27,29 @@ static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp)
27 27
28void gfs2_jindex_free(struct gfs2_sbd *sdp); 28void gfs2_jindex_free(struct gfs2_sbd *sdp);
29 29
30struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid); 30extern int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *data);
31int gfs2_jdesc_check(struct gfs2_jdesc *jd);
32 31
33int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename, 32extern struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid);
34 struct gfs2_inode **ipp); 33extern int gfs2_jdesc_check(struct gfs2_jdesc *jd);
35 34
36int gfs2_make_fs_rw(struct gfs2_sbd *sdp); 35extern int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename,
36 struct gfs2_inode **ipp);
37 37
38int gfs2_statfs_init(struct gfs2_sbd *sdp); 38extern int gfs2_make_fs_rw(struct gfs2_sbd *sdp);
39void gfs2_statfs_change(struct gfs2_sbd *sdp,
40 s64 total, s64 free, s64 dinodes);
41int gfs2_statfs_sync(struct gfs2_sbd *sdp);
42 39
43int gfs2_freeze_fs(struct gfs2_sbd *sdp); 40extern int gfs2_statfs_init(struct gfs2_sbd *sdp);
44void gfs2_unfreeze_fs(struct gfs2_sbd *sdp); 41extern void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
42 s64 dinodes);
43extern int gfs2_statfs_sync(struct gfs2_sbd *sdp);
44
45extern int gfs2_freeze_fs(struct gfs2_sbd *sdp);
46extern void gfs2_unfreeze_fs(struct gfs2_sbd *sdp);
45 47
46extern struct file_system_type gfs2_fs_type; 48extern struct file_system_type gfs2_fs_type;
47extern struct file_system_type gfs2meta_fs_type; 49extern struct file_system_type gfs2meta_fs_type;
48extern const struct export_operations gfs2_export_ops; 50extern const struct export_operations gfs2_export_ops;
49extern const struct super_operations gfs2_super_ops; 51extern const struct super_operations gfs2_super_ops;
50extern struct dentry_operations gfs2_dops; 52extern const struct dentry_operations gfs2_dops;
51 53
52#endif /* __SUPER_DOT_H__ */ 54#endif /* __SUPER_DOT_H__ */
53 55
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 26c1fa777a9..7655f5025fe 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -14,9 +14,8 @@
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/kobject.h> 16#include <linux/kobject.h>
17#include <linux/gfs2_ondisk.h>
18#include <linux/lm_interface.h>
19#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18#include <linux/gfs2_ondisk.h>
20 19
21#include "gfs2.h" 20#include "gfs2.h"
22#include "incore.h" 21#include "incore.h"
@@ -25,6 +24,7 @@
25#include "glock.h" 24#include "glock.h"
26#include "quota.h" 25#include "quota.h"
27#include "util.h" 26#include "util.h"
27#include "glops.h"
28 28
29static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) 29static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
30{ 30{
@@ -37,6 +37,30 @@ static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
37 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); 37 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname);
38} 38}
39 39
40static int gfs2_uuid_valid(const u8 *uuid)
41{
42 int i;
43
44 for (i = 0; i < 16; i++) {
45 if (uuid[i])
46 return 1;
47 }
48 return 0;
49}
50
51static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf)
52{
53 const u8 *uuid = sdp->sd_sb.sb_uuid;
54 buf[0] = '\0';
55 if (!gfs2_uuid_valid(uuid))
56 return 0;
57 return snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X-%02X%02X-"
58 "%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
59 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5],
60 uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11],
61 uuid[12], uuid[13], uuid[14], uuid[15]);
62}
63
40static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) 64static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
41{ 65{
42 unsigned int count; 66 unsigned int count;
@@ -148,6 +172,46 @@ static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf,
148 return len; 172 return len;
149} 173}
150 174
175static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
176{
177 struct gfs2_glock *gl;
178 const struct gfs2_glock_operations *glops;
179 unsigned int glmode;
180 unsigned int gltype;
181 unsigned long long glnum;
182 char mode[16];
183 int rv;
184
185 if (!capable(CAP_SYS_ADMIN))
186 return -EACCES;
187
188 rv = sscanf(buf, "%u:%llu %15s", &gltype, &glnum,
189 mode);
190 if (rv != 3)
191 return -EINVAL;
192
193 if (strcmp(mode, "EX") == 0)
194 glmode = LM_ST_UNLOCKED;
195 else if ((strcmp(mode, "CW") == 0) || (strcmp(mode, "DF") == 0))
196 glmode = LM_ST_DEFERRED;
197 else if ((strcmp(mode, "PR") == 0) || (strcmp(mode, "SH") == 0))
198 glmode = LM_ST_SHARED;
199 else
200 return -EINVAL;
201
202 if (gltype > LM_TYPE_JOURNAL)
203 return -EINVAL;
204 glops = gfs2_glops_list[gltype];
205 if (glops == NULL)
206 return -EINVAL;
207 rv = gfs2_glock_get(sdp, glnum, glops, 0, &gl);
208 if (rv)
209 return rv;
210 gfs2_glock_cb(gl, glmode);
211 gfs2_glock_put(gl);
212 return len;
213}
214
151struct gfs2_attr { 215struct gfs2_attr {
152 struct attribute attr; 216 struct attribute attr;
153 ssize_t (*show)(struct gfs2_sbd *, char *); 217 ssize_t (*show)(struct gfs2_sbd *, char *);
@@ -159,22 +223,26 @@ static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
159 223
160GFS2_ATTR(id, 0444, id_show, NULL); 224GFS2_ATTR(id, 0444, id_show, NULL);
161GFS2_ATTR(fsname, 0444, fsname_show, NULL); 225GFS2_ATTR(fsname, 0444, fsname_show, NULL);
226GFS2_ATTR(uuid, 0444, uuid_show, NULL);
162GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); 227GFS2_ATTR(freeze, 0644, freeze_show, freeze_store);
163GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); 228GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
164GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); 229GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store);
165GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); 230GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store);
166GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); 231GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store);
167GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); 232GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store);
233GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store);
168 234
169static struct attribute *gfs2_attrs[] = { 235static struct attribute *gfs2_attrs[] = {
170 &gfs2_attr_id.attr, 236 &gfs2_attr_id.attr,
171 &gfs2_attr_fsname.attr, 237 &gfs2_attr_fsname.attr,
238 &gfs2_attr_uuid.attr,
172 &gfs2_attr_freeze.attr, 239 &gfs2_attr_freeze.attr,
173 &gfs2_attr_withdraw.attr, 240 &gfs2_attr_withdraw.attr,
174 &gfs2_attr_statfs_sync.attr, 241 &gfs2_attr_statfs_sync.attr,
175 &gfs2_attr_quota_sync.attr, 242 &gfs2_attr_quota_sync.attr,
176 &gfs2_attr_quota_refresh_user.attr, 243 &gfs2_attr_quota_refresh_user.attr,
177 &gfs2_attr_quota_refresh_group.attr, 244 &gfs2_attr_quota_refresh_group.attr,
245 &gfs2_attr_demote_rq.attr,
178 NULL, 246 NULL,
179}; 247};
180 248
@@ -224,14 +292,145 @@ static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
224 292
225LOCKSTRUCT_ATTR(jid, "%u\n"); 293LOCKSTRUCT_ATTR(jid, "%u\n");
226LOCKSTRUCT_ATTR(first, "%u\n"); 294LOCKSTRUCT_ATTR(first, "%u\n");
227LOCKSTRUCT_ATTR(lvb_size, "%u\n");
228LOCKSTRUCT_ATTR(flags, "%d\n");
229 295
230static struct attribute *lockstruct_attrs[] = { 296static struct attribute *lockstruct_attrs[] = {
231 &lockstruct_attr_jid.attr, 297 &lockstruct_attr_jid.attr,
232 &lockstruct_attr_first.attr, 298 &lockstruct_attr_first.attr,
233 &lockstruct_attr_lvb_size.attr, 299 NULL,
234 &lockstruct_attr_flags.attr, 300};
301
302/*
303 * lock_module. Originally from lock_dlm
304 */
305
306static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf)
307{
308 const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops;
309 return sprintf(buf, "%s\n", ops->lm_proto_name);
310}
311
312static ssize_t block_show(struct gfs2_sbd *sdp, char *buf)
313{
314 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
315 ssize_t ret;
316 int val = 0;
317
318 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))
319 val = 1;
320 ret = sprintf(buf, "%d\n", val);
321 return ret;
322}
323
324static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
325{
326 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
327 ssize_t ret = len;
328 int val;
329
330 val = simple_strtol(buf, NULL, 0);
331
332 if (val == 1)
333 set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
334 else if (val == 0) {
335 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
336 smp_mb__after_clear_bit();
337 gfs2_glock_thaw(sdp);
338 } else {
339 ret = -EINVAL;
340 }
341 return ret;
342}
343
344static ssize_t lkid_show(struct gfs2_sbd *sdp, char *buf)
345{
346 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
347 return sprintf(buf, "%u\n", ls->ls_id);
348}
349
350static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf)
351{
352 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
353 return sprintf(buf, "%d\n", ls->ls_first);
354}
355
356static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
357{
358 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
359 return sprintf(buf, "%d\n", ls->ls_first_done);
360}
361
362static ssize_t recover_show(struct gfs2_sbd *sdp, char *buf)
363{
364 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
365 return sprintf(buf, "%d\n", ls->ls_recover_jid);
366}
367
368static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
369{
370 struct gfs2_jdesc *jd;
371
372 spin_lock(&sdp->sd_jindex_spin);
373 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
374 if (jd->jd_jid != jid)
375 continue;
376 jd->jd_dirty = 1;
377 break;
378 }
379 spin_unlock(&sdp->sd_jindex_spin);
380}
381
382static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
383{
384 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
385 ls->ls_recover_jid = simple_strtol(buf, NULL, 0);
386 gfs2_jdesc_make_dirty(sdp, ls->ls_recover_jid);
387 if (sdp->sd_recoverd_process)
388 wake_up_process(sdp->sd_recoverd_process);
389 return len;
390}
391
392static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf)
393{
394 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
395 return sprintf(buf, "%d\n", ls->ls_recover_jid_done);
396}
397
398static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf)
399{
400 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
401 return sprintf(buf, "%d\n", ls->ls_recover_jid_status);
402}
403
404struct gdlm_attr {
405 struct attribute attr;
406 ssize_t (*show)(struct gfs2_sbd *sdp, char *);
407 ssize_t (*store)(struct gfs2_sbd *sdp, const char *, size_t);
408};
409
410#define GDLM_ATTR(_name,_mode,_show,_store) \
411static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
412
413GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
414GDLM_ATTR(block, 0644, block_show, block_store);
415GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
416GDLM_ATTR(id, 0444, lkid_show, NULL);
417GDLM_ATTR(first, 0444, lkfirst_show, NULL);
418GDLM_ATTR(first_done, 0444, first_done_show, NULL);
419GDLM_ATTR(recover, 0644, recover_show, recover_store);
420GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
421GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
422
423static struct attribute *lock_module_attrs[] = {
424 &gdlm_attr_proto_name.attr,
425 &gdlm_attr_block.attr,
426 &gdlm_attr_withdraw.attr,
427 &gdlm_attr_id.attr,
428 &lockstruct_attr_jid.attr,
429 &gdlm_attr_first.attr,
430 &gdlm_attr_first_done.attr,
431 &gdlm_attr_recover.attr,
432 &gdlm_attr_recover_done.attr,
433 &gdlm_attr_recover_status.attr,
235 NULL, 434 NULL,
236}; 435};
237 436
@@ -373,7 +572,6 @@ TUNE_ATTR(complain_secs, 0);
373TUNE_ATTR(statfs_slow, 0); 572TUNE_ATTR(statfs_slow, 0);
374TUNE_ATTR(new_files_jdata, 0); 573TUNE_ATTR(new_files_jdata, 0);
375TUNE_ATTR(quota_simul_sync, 1); 574TUNE_ATTR(quota_simul_sync, 1);
376TUNE_ATTR(quota_cache_secs, 1);
377TUNE_ATTR(stall_secs, 1); 575TUNE_ATTR(stall_secs, 1);
378TUNE_ATTR(statfs_quantum, 1); 576TUNE_ATTR(statfs_quantum, 1);
379TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); 577TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
@@ -389,7 +587,6 @@ static struct attribute *tune_attrs[] = {
389 &tune_attr_complain_secs.attr, 587 &tune_attr_complain_secs.attr,
390 &tune_attr_statfs_slow.attr, 588 &tune_attr_statfs_slow.attr,
391 &tune_attr_quota_simul_sync.attr, 589 &tune_attr_quota_simul_sync.attr,
392 &tune_attr_quota_cache_secs.attr,
393 &tune_attr_stall_secs.attr, 590 &tune_attr_stall_secs.attr,
394 &tune_attr_statfs_quantum.attr, 591 &tune_attr_statfs_quantum.attr,
395 &tune_attr_recoverd_secs.attr, 592 &tune_attr_recoverd_secs.attr,
@@ -414,6 +611,11 @@ static struct attribute_group tune_group = {
414 .attrs = tune_attrs, 611 .attrs = tune_attrs,
415}; 612};
416 613
614static struct attribute_group lock_module_group = {
615 .name = "lock_module",
616 .attrs = lock_module_attrs,
617};
618
417int gfs2_sys_fs_add(struct gfs2_sbd *sdp) 619int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
418{ 620{
419 int error; 621 int error;
@@ -436,9 +638,15 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
436 if (error) 638 if (error)
437 goto fail_args; 639 goto fail_args;
438 640
641 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
642 if (error)
643 goto fail_tune;
644
439 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD); 645 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
440 return 0; 646 return 0;
441 647
648fail_tune:
649 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
442fail_args: 650fail_args:
443 sysfs_remove_group(&sdp->sd_kobj, &args_group); 651 sysfs_remove_group(&sdp->sd_kobj, &args_group);
444fail_lockstruct: 652fail_lockstruct:
@@ -455,15 +663,27 @@ void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
455 sysfs_remove_group(&sdp->sd_kobj, &tune_group); 663 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
456 sysfs_remove_group(&sdp->sd_kobj, &args_group); 664 sysfs_remove_group(&sdp->sd_kobj, &args_group);
457 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); 665 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
666 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
458 kobject_put(&sdp->sd_kobj); 667 kobject_put(&sdp->sd_kobj);
459} 668}
460 669
670
461static int gfs2_uevent(struct kset *kset, struct kobject *kobj, 671static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
462 struct kobj_uevent_env *env) 672 struct kobj_uevent_env *env)
463{ 673{
464 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); 674 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
675 const u8 *uuid = sdp->sd_sb.sb_uuid;
676
465 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name); 677 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
466 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name); 678 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
679 if (gfs2_uuid_valid(uuid)) {
680 add_uevent_var(env, "UUID=%02X%02X%02X%02X-%02X%02X-%02X%02X-"
681 "%02X%02X-%02X%02X%02X%02X%02X%02X",
682 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4],
683 uuid[5], uuid[6], uuid[7], uuid[8], uuid[9],
684 uuid[10], uuid[11], uuid[12], uuid[13],
685 uuid[14], uuid[15]);
686 }
467 return 0; 687 return 0;
468} 688}
469 689
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index f677b8a83f0..053752d4b27 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -12,9 +12,8 @@
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/gfs2_ondisk.h>
16#include <linux/kallsyms.h> 15#include <linux/kallsyms.h>
17#include <linux/lm_interface.h> 16#include <linux/gfs2_ondisk.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
20#include "incore.h" 19#include "incore.h"
@@ -88,9 +87,11 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
88 87
89 if (!tr->tr_touched) { 88 if (!tr->tr_touched) {
90 gfs2_log_release(sdp, tr->tr_reserved); 89 gfs2_log_release(sdp, tr->tr_reserved);
91 gfs2_glock_dq(&tr->tr_t_gh); 90 if (tr->tr_t_gh.gh_gl) {
92 gfs2_holder_uninit(&tr->tr_t_gh); 91 gfs2_glock_dq(&tr->tr_t_gh);
93 kfree(tr); 92 gfs2_holder_uninit(&tr->tr_t_gh);
93 kfree(tr);
94 }
94 return; 95 return;
95 } 96 }
96 97
@@ -106,9 +107,11 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
106 } 107 }
107 108
108 gfs2_log_commit(sdp, tr); 109 gfs2_log_commit(sdp, tr);
109 gfs2_glock_dq(&tr->tr_t_gh); 110 if (tr->tr_t_gh.gh_gl) {
110 gfs2_holder_uninit(&tr->tr_t_gh); 111 gfs2_glock_dq(&tr->tr_t_gh);
111 kfree(tr); 112 gfs2_holder_uninit(&tr->tr_t_gh);
113 kfree(tr);
114 }
112 115
113 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) 116 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
114 gfs2_log_flush(sdp, NULL); 117 gfs2_log_flush(sdp, NULL);
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 374f50e9549..9d12b1118ba 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/crc32.h> 14#include <linux/crc32.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17#include <asm/uaccess.h> 16#include <asm/uaccess.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
@@ -35,6 +34,8 @@ void gfs2_assert_i(struct gfs2_sbd *sdp)
35 34
36int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) 35int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
37{ 36{
37 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
38 const struct lm_lockops *lm = ls->ls_ops;
38 va_list args; 39 va_list args;
39 40
40 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags)) 41 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
@@ -47,8 +48,12 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
47 fs_err(sdp, "about to withdraw this file system\n"); 48 fs_err(sdp, "about to withdraw this file system\n");
48 BUG_ON(sdp->sd_args.ar_debug); 49 BUG_ON(sdp->sd_args.ar_debug);
49 50
50 fs_err(sdp, "telling LM to withdraw\n"); 51 kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
51 gfs2_withdraw_lockproto(&sdp->sd_lockstruct); 52
53 if (lm->lm_unmount) {
54 fs_err(sdp, "telling LM to unmount\n");
55 lm->lm_unmount(sdp);
56 }
52 fs_err(sdp, "withdrawn\n"); 57 fs_err(sdp, "withdrawn\n");
53 dump_stack(); 58 dump_stack();
54 59
diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h
index 9955232fdf8..052387e1167 100644
--- a/fs/hfs/hfs_fs.h
+++ b/fs/hfs/hfs_fs.h
@@ -213,7 +213,7 @@ extern void hfs_mdb_put(struct super_block *);
213extern int hfs_part_find(struct super_block *, sector_t *, sector_t *); 213extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
214 214
215/* string.c */ 215/* string.c */
216extern struct dentry_operations hfs_dentry_operations; 216extern const struct dentry_operations hfs_dentry_operations;
217 217
218extern int hfs_hash_dentry(struct dentry *, struct qstr *); 218extern int hfs_hash_dentry(struct dentry *, struct qstr *);
219extern int hfs_strcmp(const unsigned char *, unsigned int, 219extern int hfs_strcmp(const unsigned char *, unsigned int,
diff --git a/fs/hfs/sysdep.c b/fs/hfs/sysdep.c
index 5bf89ec01cd..7478f5c219a 100644
--- a/fs/hfs/sysdep.c
+++ b/fs/hfs/sysdep.c
@@ -31,7 +31,7 @@ static int hfs_revalidate_dentry(struct dentry *dentry, struct nameidata *nd)
31 return 1; 31 return 1;
32} 32}
33 33
34struct dentry_operations hfs_dentry_operations = 34const struct dentry_operations hfs_dentry_operations =
35{ 35{
36 .d_revalidate = hfs_revalidate_dentry, 36 .d_revalidate = hfs_revalidate_dentry,
37 .d_hash = hfs_hash_dentry, 37 .d_hash = hfs_hash_dentry,
diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h
index f027a905225..5c10d803d9d 100644
--- a/fs/hfsplus/hfsplus_fs.h
+++ b/fs/hfsplus/hfsplus_fs.h
@@ -327,7 +327,7 @@ void hfsplus_file_truncate(struct inode *);
327/* inode.c */ 327/* inode.c */
328extern const struct address_space_operations hfsplus_aops; 328extern const struct address_space_operations hfsplus_aops;
329extern const struct address_space_operations hfsplus_btree_aops; 329extern const struct address_space_operations hfsplus_btree_aops;
330extern struct dentry_operations hfsplus_dentry_operations; 330extern const struct dentry_operations hfsplus_dentry_operations;
331 331
332void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *); 332void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
333void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *); 333void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index f105ee9e1cc..1bcf597c056 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -137,7 +137,7 @@ const struct address_space_operations hfsplus_aops = {
137 .writepages = hfsplus_writepages, 137 .writepages = hfsplus_writepages,
138}; 138};
139 139
140struct dentry_operations hfsplus_dentry_operations = { 140const struct dentry_operations hfsplus_dentry_operations = {
141 .d_hash = hfsplus_hash_dentry, 141 .d_hash = hfsplus_hash_dentry,
142 .d_compare = hfsplus_compare_dentry, 142 .d_compare = hfsplus_compare_dentry,
143}; 143};
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index 5c538e0ec14..fe02ad4740e 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -31,12 +31,12 @@ static inline struct hostfs_inode_info *HOSTFS_I(struct inode *inode)
31 31
32#define FILE_HOSTFS_I(file) HOSTFS_I((file)->f_path.dentry->d_inode) 32#define FILE_HOSTFS_I(file) HOSTFS_I((file)->f_path.dentry->d_inode)
33 33
34int hostfs_d_delete(struct dentry *dentry) 34static int hostfs_d_delete(struct dentry *dentry)
35{ 35{
36 return 1; 36 return 1;
37} 37}
38 38
39struct dentry_operations hostfs_dentry_ops = { 39static const struct dentry_operations hostfs_dentry_ops = {
40 .d_delete = hostfs_d_delete, 40 .d_delete = hostfs_d_delete,
41}; 41};
42 42
diff --git a/fs/hpfs/dentry.c b/fs/hpfs/dentry.c
index 08319126b2a..940d6d150be 100644
--- a/fs/hpfs/dentry.c
+++ b/fs/hpfs/dentry.c
@@ -49,7 +49,7 @@ static int hpfs_compare_dentry(struct dentry *dentry, struct qstr *a, struct qst
49 return 0; 49 return 0;
50} 50}
51 51
52static struct dentry_operations hpfs_dentry_operations = { 52static const struct dentry_operations hpfs_dentry_operations = {
53 .d_hash = hpfs_hash_dentry, 53 .d_hash = hpfs_hash_dentry,
54 .d_compare = hpfs_compare_dentry, 54 .d_compare = hpfs_compare_dentry,
55}; 55};
diff --git a/fs/inode.c b/fs/inode.c
index 826fb0b9d1c..d06d6d268de 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -17,6 +17,7 @@
17#include <linux/hash.h> 17#include <linux/hash.h>
18#include <linux/swap.h> 18#include <linux/swap.h>
19#include <linux/security.h> 19#include <linux/security.h>
20#include <linux/ima.h>
20#include <linux/pagemap.h> 21#include <linux/pagemap.h>
21#include <linux/cdev.h> 22#include <linux/cdev.h>
22#include <linux/bootmem.h> 23#include <linux/bootmem.h>
@@ -147,13 +148,13 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
147 inode->i_cdev = NULL; 148 inode->i_cdev = NULL;
148 inode->i_rdev = 0; 149 inode->i_rdev = 0;
149 inode->dirtied_when = 0; 150 inode->dirtied_when = 0;
150 if (security_inode_alloc(inode)) { 151
151 if (inode->i_sb->s_op->destroy_inode) 152 if (security_inode_alloc(inode))
152 inode->i_sb->s_op->destroy_inode(inode); 153 goto out_free_inode;
153 else 154
154 kmem_cache_free(inode_cachep, (inode)); 155 /* allocate and initialize an i_integrity */
155 return NULL; 156 if (ima_inode_alloc(inode))
156 } 157 goto out_free_security;
157 158
158 spin_lock_init(&inode->i_lock); 159 spin_lock_init(&inode->i_lock);
159 lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); 160 lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
@@ -189,6 +190,15 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
189 inode->i_mapping = mapping; 190 inode->i_mapping = mapping;
190 191
191 return inode; 192 return inode;
193
194out_free_security:
195 security_inode_free(inode);
196out_free_inode:
197 if (inode->i_sb->s_op->destroy_inode)
198 inode->i_sb->s_op->destroy_inode(inode);
199 else
200 kmem_cache_free(inode_cachep, (inode));
201 return NULL;
192} 202}
193EXPORT_SYMBOL(inode_init_always); 203EXPORT_SYMBOL(inode_init_always);
194 204
@@ -284,7 +294,7 @@ void clear_inode(struct inode *inode)
284 BUG_ON(!(inode->i_state & I_FREEING)); 294 BUG_ON(!(inode->i_state & I_FREEING));
285 BUG_ON(inode->i_state & I_CLEAR); 295 BUG_ON(inode->i_state & I_CLEAR);
286 inode_sync_wait(inode); 296 inode_sync_wait(inode);
287 DQUOT_DROP(inode); 297 vfs_dq_drop(inode);
288 if (inode->i_sb->s_op->clear_inode) 298 if (inode->i_sb->s_op->clear_inode)
289 inode->i_sb->s_op->clear_inode(inode); 299 inode->i_sb->s_op->clear_inode(inode);
290 if (S_ISBLK(inode->i_mode) && inode->i_bdev) 300 if (S_ISBLK(inode->i_mode) && inode->i_bdev)
@@ -356,6 +366,8 @@ static int invalidate_list(struct list_head *head, struct list_head *dispose)
356 if (tmp == head) 366 if (tmp == head)
357 break; 367 break;
358 inode = list_entry(tmp, struct inode, i_sb_list); 368 inode = list_entry(tmp, struct inode, i_sb_list);
369 if (inode->i_state & I_NEW)
370 continue;
359 invalidate_inode_buffers(inode); 371 invalidate_inode_buffers(inode);
360 if (!atomic_read(&inode->i_count)) { 372 if (!atomic_read(&inode->i_count)) {
361 list_move(&inode->i_list, dispose); 373 list_move(&inode->i_list, dispose);
@@ -1158,7 +1170,7 @@ void generic_delete_inode(struct inode *inode)
1158 if (op->delete_inode) { 1170 if (op->delete_inode) {
1159 void (*delete)(struct inode *) = op->delete_inode; 1171 void (*delete)(struct inode *) = op->delete_inode;
1160 if (!is_bad_inode(inode)) 1172 if (!is_bad_inode(inode))
1161 DQUOT_INIT(inode); 1173 vfs_dq_init(inode);
1162 /* Filesystems implementing their own 1174 /* Filesystems implementing their own
1163 * s_op->delete_inode are required to call 1175 * s_op->delete_inode are required to call
1164 * truncate_inode_pages and clear_inode() 1176 * truncate_inode_pages and clear_inode()
@@ -1290,6 +1302,40 @@ sector_t bmap(struct inode * inode, sector_t block)
1290} 1302}
1291EXPORT_SYMBOL(bmap); 1303EXPORT_SYMBOL(bmap);
1292 1304
1305/*
1306 * With relative atime, only update atime if the previous atime is
1307 * earlier than either the ctime or mtime or if at least a day has
1308 * passed since the last atime update.
1309 */
1310static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
1311 struct timespec now)
1312{
1313
1314 if (!(mnt->mnt_flags & MNT_RELATIME))
1315 return 1;
1316 /*
1317 * Is mtime younger than atime? If yes, update atime:
1318 */
1319 if (timespec_compare(&inode->i_mtime, &inode->i_atime) >= 0)
1320 return 1;
1321 /*
1322 * Is ctime younger than atime? If yes, update atime:
1323 */
1324 if (timespec_compare(&inode->i_ctime, &inode->i_atime) >= 0)
1325 return 1;
1326
1327 /*
1328 * Is the previous atime value older than a day? If yes,
1329 * update atime:
1330 */
1331 if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60)
1332 return 1;
1333 /*
1334 * Good, we can skip the atime update:
1335 */
1336 return 0;
1337}
1338
1293/** 1339/**
1294 * touch_atime - update the access time 1340 * touch_atime - update the access time
1295 * @mnt: mount the inode is accessed on 1341 * @mnt: mount the inode is accessed on
@@ -1317,17 +1363,12 @@ void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
1317 goto out; 1363 goto out;
1318 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)) 1364 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
1319 goto out; 1365 goto out;
1320 if (mnt->mnt_flags & MNT_RELATIME) {
1321 /*
1322 * With relative atime, only update atime if the previous
1323 * atime is earlier than either the ctime or mtime.
1324 */
1325 if (timespec_compare(&inode->i_mtime, &inode->i_atime) < 0 &&
1326 timespec_compare(&inode->i_ctime, &inode->i_atime) < 0)
1327 goto out;
1328 }
1329 1366
1330 now = current_fs_time(inode->i_sb); 1367 now = current_fs_time(inode->i_sb);
1368
1369 if (!relatime_need_update(mnt, inode, now))
1370 goto out;
1371
1331 if (timespec_equal(&inode->i_atime, &now)) 1372 if (timespec_equal(&inode->i_atime, &now))
1332 goto out; 1373 goto out;
1333 1374
diff --git a/fs/internal.h b/fs/internal.h
index 0d8ac497b3d..53af885f173 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -43,7 +43,7 @@ extern void __init chrdev_init(void);
43/* 43/*
44 * exec.c 44 * exec.c
45 */ 45 */
46extern void check_unsafe_exec(struct linux_binprm *, struct files_struct *); 46extern void check_unsafe_exec(struct linux_binprm *);
47 47
48/* 48/*
49 * namespace.c 49 * namespace.c
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 240ec63984c..ac2d47e4392 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -404,10 +404,12 @@ static int ioctl_fionbio(struct file *filp, int __user *argp)
404 if (O_NONBLOCK != O_NDELAY) 404 if (O_NONBLOCK != O_NDELAY)
405 flag |= O_NDELAY; 405 flag |= O_NDELAY;
406#endif 406#endif
407 spin_lock(&filp->f_lock);
407 if (on) 408 if (on)
408 filp->f_flags |= flag; 409 filp->f_flags |= flag;
409 else 410 else
410 filp->f_flags &= ~flag; 411 filp->f_flags &= ~flag;
412 spin_unlock(&filp->f_lock);
411 return error; 413 return error;
412} 414}
413 415
@@ -425,18 +427,12 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp,
425 /* Did FASYNC state change ? */ 427 /* Did FASYNC state change ? */
426 if ((flag ^ filp->f_flags) & FASYNC) { 428 if ((flag ^ filp->f_flags) & FASYNC) {
427 if (filp->f_op && filp->f_op->fasync) 429 if (filp->f_op && filp->f_op->fasync)
430 /* fasync() adjusts filp->f_flags */
428 error = filp->f_op->fasync(fd, filp, on); 431 error = filp->f_op->fasync(fd, filp, on);
429 else 432 else
430 error = -ENOTTY; 433 error = -ENOTTY;
431 } 434 }
432 if (error) 435 return error < 0 ? error : 0;
433 return error;
434
435 if (on)
436 filp->f_flags |= FASYNC;
437 else
438 filp->f_flags &= ~FASYNC;
439 return error;
440} 436}
441 437
442static int ioctl_fsfreeze(struct file *filp) 438static int ioctl_fsfreeze(struct file *filp)
@@ -499,17 +495,11 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
499 break; 495 break;
500 496
501 case FIONBIO: 497 case FIONBIO:
502 /* BKL needed to avoid races tweaking f_flags */
503 lock_kernel();
504 error = ioctl_fionbio(filp, argp); 498 error = ioctl_fionbio(filp, argp);
505 unlock_kernel();
506 break; 499 break;
507 500
508 case FIOASYNC: 501 case FIOASYNC:
509 /* BKL needed to avoid races tweaking f_flags */
510 lock_kernel();
511 error = ioctl_fioasync(fd, filp, argp); 502 error = ioctl_fioasync(fd, filp, argp);
512 unlock_kernel();
513 break; 503 break;
514 504
515 case FIOQSIZE: 505 case FIOQSIZE:
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index 6147ec3643a..13d2eddd069 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -114,7 +114,7 @@ static const struct super_operations isofs_sops = {
114}; 114};
115 115
116 116
117static struct dentry_operations isofs_dentry_ops[] = { 117static const struct dentry_operations isofs_dentry_ops[] = {
118 { 118 {
119 .d_hash = isofs_hash, 119 .d_hash = isofs_hash,
120 .d_compare = isofs_dentry_cmp, 120 .d_compare = isofs_dentry_cmp,
diff --git a/fs/jfs/Kconfig b/fs/jfs/Kconfig
index 9ff619a6f9c..57cef19951d 100644
--- a/fs/jfs/Kconfig
+++ b/fs/jfs/Kconfig
@@ -1,6 +1,7 @@
1config JFS_FS 1config JFS_FS
2 tristate "JFS filesystem support" 2 tristate "JFS filesystem support"
3 select NLS 3 select NLS
4 select CRC32
4 help 5 help
5 This is a port of IBM's Journaled Filesystem . More information is 6 This is a port of IBM's Journaled Filesystem . More information is
6 available in the file <file:Documentation/filesystems/jfs.txt>. 7 available in the file <file:Documentation/filesystems/jfs.txt>.
diff --git a/fs/jfs/acl.c b/fs/jfs/acl.c
index d3e5c33665d..a166c1669e8 100644
--- a/fs/jfs/acl.c
+++ b/fs/jfs/acl.c
@@ -233,7 +233,7 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
233 233
234 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) || 234 if ((iattr->ia_valid & ATTR_UID && iattr->ia_uid != inode->i_uid) ||
235 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) { 235 (iattr->ia_valid & ATTR_GID && iattr->ia_gid != inode->i_gid)) {
236 if (DQUOT_TRANSFER(inode, iattr)) 236 if (vfs_dq_transfer(inode, iattr))
237 return -EDQUOT; 237 return -EDQUOT;
238 } 238 }
239 239
diff --git a/fs/jfs/inode.c b/fs/jfs/inode.c
index b00ee9f05a0..b2ae190a77b 100644
--- a/fs/jfs/inode.c
+++ b/fs/jfs/inode.c
@@ -158,9 +158,9 @@ void jfs_delete_inode(struct inode *inode)
158 /* 158 /*
159 * Free the inode from the quota allocation. 159 * Free the inode from the quota allocation.
160 */ 160 */
161 DQUOT_INIT(inode); 161 vfs_dq_init(inode);
162 DQUOT_FREE_INODE(inode); 162 vfs_dq_free_inode(inode);
163 DQUOT_DROP(inode); 163 vfs_dq_drop(inode);
164 } 164 }
165 165
166 clear_inode(inode); 166 clear_inode(inode);
diff --git a/fs/jfs/jfs_debug.c b/fs/jfs/jfs_debug.c
index 6a73de84bce..dd824d9b0b1 100644
--- a/fs/jfs/jfs_debug.c
+++ b/fs/jfs/jfs_debug.c
@@ -90,7 +90,6 @@ void jfs_proc_init(void)
90 90
91 if (!(base = proc_mkdir("fs/jfs", NULL))) 91 if (!(base = proc_mkdir("fs/jfs", NULL)))
92 return; 92 return;
93 base->owner = THIS_MODULE;
94 93
95 for (i = 0; i < NPROCENT; i++) 94 for (i = 0; i < NPROCENT; i++)
96 proc_create(Entries[i].name, 0, base, Entries[i].proc_fops); 95 proc_create(Entries[i].name, 0, base, Entries[i].proc_fops);
diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c
index 4dcc0581999..925871e9887 100644
--- a/fs/jfs/jfs_dtree.c
+++ b/fs/jfs/jfs_dtree.c
@@ -381,10 +381,10 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
381 * It's time to move the inline table to an external 381 * It's time to move the inline table to an external
382 * page and begin to build the xtree 382 * page and begin to build the xtree
383 */ 383 */
384 if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage)) 384 if (vfs_dq_alloc_block(ip, sbi->nbperpage))
385 goto clean_up; 385 goto clean_up;
386 if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) { 386 if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
387 DQUOT_FREE_BLOCK(ip, sbi->nbperpage); 387 vfs_dq_free_block(ip, sbi->nbperpage);
388 goto clean_up; 388 goto clean_up;
389 } 389 }
390 390
@@ -408,7 +408,7 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
408 memcpy(&jfs_ip->i_dirtable, temp_table, 408 memcpy(&jfs_ip->i_dirtable, temp_table,
409 sizeof (temp_table)); 409 sizeof (temp_table));
410 dbFree(ip, xaddr, sbi->nbperpage); 410 dbFree(ip, xaddr, sbi->nbperpage);
411 DQUOT_FREE_BLOCK(ip, sbi->nbperpage); 411 vfs_dq_free_block(ip, sbi->nbperpage);
412 goto clean_up; 412 goto clean_up;
413 } 413 }
414 ip->i_size = PSIZE; 414 ip->i_size = PSIZE;
@@ -1027,7 +1027,7 @@ static int dtSplitUp(tid_t tid,
1027 n = xlen; 1027 n = xlen;
1028 1028
1029 /* Allocate blocks to quota. */ 1029 /* Allocate blocks to quota. */
1030 if (DQUOT_ALLOC_BLOCK(ip, n)) { 1030 if (vfs_dq_alloc_block(ip, n)) {
1031 rc = -EDQUOT; 1031 rc = -EDQUOT;
1032 goto extendOut; 1032 goto extendOut;
1033 } 1033 }
@@ -1308,7 +1308,7 @@ static int dtSplitUp(tid_t tid,
1308 1308
1309 /* Rollback quota allocation */ 1309 /* Rollback quota allocation */
1310 if (rc && quota_allocation) 1310 if (rc && quota_allocation)
1311 DQUOT_FREE_BLOCK(ip, quota_allocation); 1311 vfs_dq_free_block(ip, quota_allocation);
1312 1312
1313 dtSplitUp_Exit: 1313 dtSplitUp_Exit:
1314 1314
@@ -1369,7 +1369,7 @@ static int dtSplitPage(tid_t tid, struct inode *ip, struct dtsplit * split,
1369 return -EIO; 1369 return -EIO;
1370 1370
1371 /* Allocate blocks to quota. */ 1371 /* Allocate blocks to quota. */
1372 if (DQUOT_ALLOC_BLOCK(ip, lengthPXD(pxd))) { 1372 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) {
1373 release_metapage(rmp); 1373 release_metapage(rmp);
1374 return -EDQUOT; 1374 return -EDQUOT;
1375 } 1375 }
@@ -1916,7 +1916,7 @@ static int dtSplitRoot(tid_t tid,
1916 rp = rmp->data; 1916 rp = rmp->data;
1917 1917
1918 /* Allocate blocks to quota. */ 1918 /* Allocate blocks to quota. */
1919 if (DQUOT_ALLOC_BLOCK(ip, lengthPXD(pxd))) { 1919 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) {
1920 release_metapage(rmp); 1920 release_metapage(rmp);
1921 return -EDQUOT; 1921 return -EDQUOT;
1922 } 1922 }
@@ -2287,7 +2287,7 @@ static int dtDeleteUp(tid_t tid, struct inode *ip,
2287 xlen = lengthPXD(&fp->header.self); 2287 xlen = lengthPXD(&fp->header.self);
2288 2288
2289 /* Free quota allocation. */ 2289 /* Free quota allocation. */
2290 DQUOT_FREE_BLOCK(ip, xlen); 2290 vfs_dq_free_block(ip, xlen);
2291 2291
2292 /* free/invalidate its buffer page */ 2292 /* free/invalidate its buffer page */
2293 discard_metapage(fmp); 2293 discard_metapage(fmp);
@@ -2363,7 +2363,7 @@ static int dtDeleteUp(tid_t tid, struct inode *ip,
2363 xlen = lengthPXD(&p->header.self); 2363 xlen = lengthPXD(&p->header.self);
2364 2364
2365 /* Free quota allocation */ 2365 /* Free quota allocation */
2366 DQUOT_FREE_BLOCK(ip, xlen); 2366 vfs_dq_free_block(ip, xlen);
2367 2367
2368 /* free/invalidate its buffer page */ 2368 /* free/invalidate its buffer page */
2369 discard_metapage(mp); 2369 discard_metapage(mp);
diff --git a/fs/jfs/jfs_extent.c b/fs/jfs/jfs_extent.c
index 7ae1e3281de..bbbd5f202e3 100644
--- a/fs/jfs/jfs_extent.c
+++ b/fs/jfs/jfs_extent.c
@@ -141,7 +141,7 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr)
141 } 141 }
142 142
143 /* Allocate blocks to quota. */ 143 /* Allocate blocks to quota. */
144 if (DQUOT_ALLOC_BLOCK(ip, nxlen)) { 144 if (vfs_dq_alloc_block(ip, nxlen)) {
145 dbFree(ip, nxaddr, (s64) nxlen); 145 dbFree(ip, nxaddr, (s64) nxlen);
146 mutex_unlock(&JFS_IP(ip)->commit_mutex); 146 mutex_unlock(&JFS_IP(ip)->commit_mutex);
147 return -EDQUOT; 147 return -EDQUOT;
@@ -164,7 +164,7 @@ extAlloc(struct inode *ip, s64 xlen, s64 pno, xad_t * xp, bool abnr)
164 */ 164 */
165 if (rc) { 165 if (rc) {
166 dbFree(ip, nxaddr, nxlen); 166 dbFree(ip, nxaddr, nxlen);
167 DQUOT_FREE_BLOCK(ip, nxlen); 167 vfs_dq_free_block(ip, nxlen);
168 mutex_unlock(&JFS_IP(ip)->commit_mutex); 168 mutex_unlock(&JFS_IP(ip)->commit_mutex);
169 return (rc); 169 return (rc);
170 } 170 }
@@ -256,7 +256,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
256 goto exit; 256 goto exit;
257 257
258 /* Allocat blocks to quota. */ 258 /* Allocat blocks to quota. */
259 if (DQUOT_ALLOC_BLOCK(ip, nxlen)) { 259 if (vfs_dq_alloc_block(ip, nxlen)) {
260 dbFree(ip, nxaddr, (s64) nxlen); 260 dbFree(ip, nxaddr, (s64) nxlen);
261 mutex_unlock(&JFS_IP(ip)->commit_mutex); 261 mutex_unlock(&JFS_IP(ip)->commit_mutex);
262 return -EDQUOT; 262 return -EDQUOT;
@@ -297,7 +297,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
297 /* extend the extent */ 297 /* extend the extent */
298 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) { 298 if ((rc = xtExtend(0, ip, xoff + xlen, (int) nextend, 0))) {
299 dbFree(ip, xaddr + xlen, delta); 299 dbFree(ip, xaddr + xlen, delta);
300 DQUOT_FREE_BLOCK(ip, nxlen); 300 vfs_dq_free_block(ip, nxlen);
301 goto exit; 301 goto exit;
302 } 302 }
303 } else { 303 } else {
@@ -308,7 +308,7 @@ int extRealloc(struct inode *ip, s64 nxlen, xad_t * xp, bool abnr)
308 */ 308 */
309 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) { 309 if ((rc = xtTailgate(0, ip, xoff, (int) ntail, nxaddr, 0))) {
310 dbFree(ip, nxaddr, nxlen); 310 dbFree(ip, nxaddr, nxlen);
311 DQUOT_FREE_BLOCK(ip, nxlen); 311 vfs_dq_free_block(ip, nxlen);
312 goto exit; 312 goto exit;
313 } 313 }
314 } 314 }
@@ -362,11 +362,12 @@ exit:
362int extHint(struct inode *ip, s64 offset, xad_t * xp) 362int extHint(struct inode *ip, s64 offset, xad_t * xp)
363{ 363{
364 struct super_block *sb = ip->i_sb; 364 struct super_block *sb = ip->i_sb;
365 struct xadlist xadl; 365 int nbperpage = JFS_SBI(sb)->nbperpage;
366 struct lxdlist lxdl;
367 lxd_t lxd;
368 s64 prev; 366 s64 prev;
369 int rc, nbperpage = JFS_SBI(sb)->nbperpage; 367 int rc = 0;
368 s64 xaddr;
369 int xlen;
370 int xflag;
370 371
371 /* init the hint as "no hint provided" */ 372 /* init the hint as "no hint provided" */
372 XADaddress(xp, 0); 373 XADaddress(xp, 0);
@@ -376,46 +377,30 @@ int extHint(struct inode *ip, s64 offset, xad_t * xp)
376 */ 377 */
377 prev = ((offset & ~POFFSET) >> JFS_SBI(sb)->l2bsize) - nbperpage; 378 prev = ((offset & ~POFFSET) >> JFS_SBI(sb)->l2bsize) - nbperpage;
378 379
379 /* if the offsets in the first page of the file, 380 /* if the offset is in the first page of the file, no hint provided.
380 * no hint provided.
381 */ 381 */
382 if (prev < 0) 382 if (prev < 0)
383 return (0); 383 goto out;
384
385 /* prepare to lookup the previous page's extent info */
386 lxdl.maxnlxd = 1;
387 lxdl.nlxd = 1;
388 lxdl.lxd = &lxd;
389 LXDoffset(&lxd, prev)
390 LXDlength(&lxd, nbperpage);
391
392 xadl.maxnxad = 1;
393 xadl.nxad = 0;
394 xadl.xad = xp;
395
396 /* perform the lookup */
397 if ((rc = xtLookupList(ip, &lxdl, &xadl, 0)))
398 return (rc);
399
400 /* check if no extent exists for the previous page.
401 * this is possible for sparse files.
402 */
403 if (xadl.nxad == 0) {
404// assert(ISSPARSE(ip));
405 return (0);
406 }
407 384
408 /* only preserve the abnr flag within the xad flags 385 rc = xtLookup(ip, prev, nbperpage, &xflag, &xaddr, &xlen, 0);
409 * of the returned hint.
410 */
411 xp->flag &= XAD_NOTRECORDED;
412 386
413 if(xadl.nxad != 1 || lengthXAD(xp) != nbperpage) { 387 if ((rc == 0) && xlen) {
414 jfs_error(ip->i_sb, "extHint: corrupt xtree"); 388 if (xlen != nbperpage) {
415 return -EIO; 389 jfs_error(ip->i_sb, "extHint: corrupt xtree");
416 } 390 rc = -EIO;
391 }
392 XADaddress(xp, xaddr);
393 XADlength(xp, xlen);
394 /*
395 * only preserve the abnr flag within the xad flags
396 * of the returned hint.
397 */
398 xp->flag = xflag & XAD_NOTRECORDED;
399 } else
400 rc = 0;
417 401
418 return (0); 402out:
403 return (rc);
419} 404}
420 405
421 406
diff --git a/fs/jfs/jfs_imap.c b/fs/jfs/jfs_imap.c
index 0f94381ca6d..346057218ed 100644
--- a/fs/jfs/jfs_imap.c
+++ b/fs/jfs/jfs_imap.c
@@ -57,12 +57,6 @@
57#include "jfs_debug.h" 57#include "jfs_debug.h"
58 58
59/* 59/*
60 * __mark_inode_dirty expects inodes to be hashed. Since we don't want
61 * special inodes in the fileset inode space, we make them appear hashed,
62 * but do not put on any lists.
63 */
64
65/*
66 * imap locks 60 * imap locks
67 */ 61 */
68/* iag free list lock */ 62/* iag free list lock */
@@ -497,7 +491,9 @@ struct inode *diReadSpecial(struct super_block *sb, ino_t inum, int secondary)
497 release_metapage(mp); 491 release_metapage(mp);
498 492
499 /* 493 /*
500 * that will look hashed, but won't be on any list; hlist_del() 494 * __mark_inode_dirty expects inodes to be hashed. Since we don't
495 * want special inodes in the fileset inode space, we make them
496 * appear hashed, but do not put on any lists. hlist_del()
501 * will work fine and require no locking. 497 * will work fine and require no locking.
502 */ 498 */
503 ip->i_hash.pprev = &ip->i_hash.next; 499 ip->i_hash.pprev = &ip->i_hash.next;
diff --git a/fs/jfs/jfs_inode.c b/fs/jfs/jfs_inode.c
index d4d142c2edd..dc0e02159ac 100644
--- a/fs/jfs/jfs_inode.c
+++ b/fs/jfs/jfs_inode.c
@@ -116,7 +116,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
116 /* 116 /*
117 * Allocate inode to quota. 117 * Allocate inode to quota.
118 */ 118 */
119 if (DQUOT_ALLOC_INODE(inode)) { 119 if (vfs_dq_alloc_inode(inode)) {
120 rc = -EDQUOT; 120 rc = -EDQUOT;
121 goto fail_drop; 121 goto fail_drop;
122 } 122 }
@@ -162,7 +162,7 @@ struct inode *ialloc(struct inode *parent, umode_t mode)
162 return inode; 162 return inode;
163 163
164fail_drop: 164fail_drop:
165 DQUOT_DROP(inode); 165 vfs_dq_drop(inode);
166 inode->i_flags |= S_NOQUOTA; 166 inode->i_flags |= S_NOQUOTA;
167fail_unlock: 167fail_unlock:
168 inode->i_nlink = 0; 168 inode->i_nlink = 0;
diff --git a/fs/jfs/jfs_inode.h b/fs/jfs/jfs_inode.h
index adb2fafcc54..1eff7db34d6 100644
--- a/fs/jfs/jfs_inode.h
+++ b/fs/jfs/jfs_inode.h
@@ -47,5 +47,5 @@ extern const struct file_operations jfs_dir_operations;
47extern const struct inode_operations jfs_file_inode_operations; 47extern const struct inode_operations jfs_file_inode_operations;
48extern const struct file_operations jfs_file_operations; 48extern const struct file_operations jfs_file_operations;
49extern const struct inode_operations jfs_symlink_inode_operations; 49extern const struct inode_operations jfs_symlink_inode_operations;
50extern struct dentry_operations jfs_ci_dentry_operations; 50extern const struct dentry_operations jfs_ci_dentry_operations;
51#endif /* _H_JFS_INODE */ 51#endif /* _H_JFS_INODE */
diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index c350057087d..07b6c5dfb4b 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -369,6 +369,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
369 unsigned long bio_bytes = 0; 369 unsigned long bio_bytes = 0;
370 unsigned long bio_offset = 0; 370 unsigned long bio_offset = 0;
371 int offset; 371 int offset;
372 int bad_blocks = 0;
372 373
373 page_start = (sector_t)page->index << 374 page_start = (sector_t)page->index <<
374 (PAGE_CACHE_SHIFT - inode->i_blkbits); 375 (PAGE_CACHE_SHIFT - inode->i_blkbits);
@@ -394,6 +395,7 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
394 } 395 }
395 396
396 clear_bit(META_dirty, &mp->flag); 397 clear_bit(META_dirty, &mp->flag);
398 set_bit(META_io, &mp->flag);
397 block_offset = offset >> inode->i_blkbits; 399 block_offset = offset >> inode->i_blkbits;
398 lblock = page_start + block_offset; 400 lblock = page_start + block_offset;
399 if (bio) { 401 if (bio) {
@@ -402,7 +404,6 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
402 len = min(xlen, blocks_per_mp); 404 len = min(xlen, blocks_per_mp);
403 xlen -= len; 405 xlen -= len;
404 bio_bytes += len << inode->i_blkbits; 406 bio_bytes += len << inode->i_blkbits;
405 set_bit(META_io, &mp->flag);
406 continue; 407 continue;
407 } 408 }
408 /* Not contiguous */ 409 /* Not contiguous */
@@ -424,12 +425,14 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
424 xlen = (PAGE_CACHE_SIZE - offset) >> inode->i_blkbits; 425 xlen = (PAGE_CACHE_SIZE - offset) >> inode->i_blkbits;
425 pblock = metapage_get_blocks(inode, lblock, &xlen); 426 pblock = metapage_get_blocks(inode, lblock, &xlen);
426 if (!pblock) { 427 if (!pblock) {
427 /* Need better error handling */
428 printk(KERN_ERR "JFS: metapage_get_blocks failed\n"); 428 printk(KERN_ERR "JFS: metapage_get_blocks failed\n");
429 dec_io(page, last_write_complete); 429 /*
430 * We already called inc_io(), but can't cancel it
431 * with dec_io() until we're done with the page
432 */
433 bad_blocks++;
430 continue; 434 continue;
431 } 435 }
432 set_bit(META_io, &mp->flag);
433 len = min(xlen, (int)JFS_SBI(inode->i_sb)->nbperpage); 436 len = min(xlen, (int)JFS_SBI(inode->i_sb)->nbperpage);
434 437
435 bio = bio_alloc(GFP_NOFS, 1); 438 bio = bio_alloc(GFP_NOFS, 1);
@@ -459,6 +462,9 @@ static int metapage_writepage(struct page *page, struct writeback_control *wbc)
459 462
460 unlock_page(page); 463 unlock_page(page);
461 464
465 if (bad_blocks)
466 goto err_out;
467
462 if (nr_underway == 0) 468 if (nr_underway == 0)
463 end_page_writeback(page); 469 end_page_writeback(page);
464 470
@@ -474,7 +480,9 @@ skip:
474 bio_put(bio); 480 bio_put(bio);
475 unlock_page(page); 481 unlock_page(page);
476 dec_io(page, last_write_complete); 482 dec_io(page, last_write_complete);
477 483err_out:
484 while (bad_blocks--)
485 dec_io(page, last_write_complete);
478 return -EIO; 486 return -EIO;
479} 487}
480 488
diff --git a/fs/jfs/jfs_types.h b/fs/jfs/jfs_types.h
index 649f9817acc..43ea3713c08 100644
--- a/fs/jfs/jfs_types.h
+++ b/fs/jfs/jfs_types.h
@@ -58,35 +58,6 @@ struct timestruc_t {
58#define ONES 0xffffffffu /* all bit on */ 58#define ONES 0xffffffffu /* all bit on */
59 59
60/* 60/*
61 * logical xd (lxd)
62 */
63typedef struct {
64 unsigned len:24;
65 unsigned off1:8;
66 u32 off2;
67} lxd_t;
68
69/* lxd_t field construction */
70#define LXDlength(lxd, length32) ( (lxd)->len = length32 )
71#define LXDoffset(lxd, offset64)\
72{\
73 (lxd)->off1 = ((s64)offset64) >> 32;\
74 (lxd)->off2 = (offset64) & 0xffffffff;\
75}
76
77/* lxd_t field extraction */
78#define lengthLXD(lxd) ( (lxd)->len )
79#define offsetLXD(lxd)\
80 ( ((s64)((lxd)->off1)) << 32 | (lxd)->off2 )
81
82/* lxd list */
83struct lxdlist {
84 s16 maxnlxd;
85 s16 nlxd;
86 lxd_t *lxd;
87};
88
89/*
90 * physical xd (pxd) 61 * physical xd (pxd)
91 */ 62 */
92typedef struct { 63typedef struct {
diff --git a/fs/jfs/jfs_xtree.c b/fs/jfs/jfs_xtree.c
index ae3acafb447..d654a645864 100644
--- a/fs/jfs/jfs_xtree.c
+++ b/fs/jfs/jfs_xtree.c
@@ -164,11 +164,8 @@ int xtLookup(struct inode *ip, s64 lstart,
164 /* is lookup offset beyond eof ? */ 164 /* is lookup offset beyond eof ? */
165 size = ((u64) ip->i_size + (JFS_SBI(ip->i_sb)->bsize - 1)) >> 165 size = ((u64) ip->i_size + (JFS_SBI(ip->i_sb)->bsize - 1)) >>
166 JFS_SBI(ip->i_sb)->l2bsize; 166 JFS_SBI(ip->i_sb)->l2bsize;
167 if (lstart >= size) { 167 if (lstart >= size)
168 jfs_err("xtLookup: lstart (0x%lx) >= size (0x%lx)",
169 (ulong) lstart, (ulong) size);
170 return 0; 168 return 0;
171 }
172 } 169 }
173 170
174 /* 171 /*
@@ -220,264 +217,6 @@ int xtLookup(struct inode *ip, s64 lstart,
220 return rc; 217 return rc;
221} 218}
222 219
223
224/*
225 * xtLookupList()
226 *
227 * function: map a single logical extent into a list of physical extent;
228 *
229 * parameter:
230 * struct inode *ip,
231 * struct lxdlist *lxdlist, lxd list (in)
232 * struct xadlist *xadlist, xad list (in/out)
233 * int flag)
234 *
235 * coverage of lxd by xad under assumption of
236 * . lxd's are ordered and disjoint.
237 * . xad's are ordered and disjoint.
238 *
239 * return:
240 * 0: success
241 *
242 * note: a page being written (even a single byte) is backed fully,
243 * except the last page which is only backed with blocks
244 * required to cover the last byte;
245 * the extent backing a page is fully contained within an xad;
246 */
247int xtLookupList(struct inode *ip, struct lxdlist * lxdlist,
248 struct xadlist * xadlist, int flag)
249{
250 int rc = 0;
251 struct btstack btstack;
252 int cmp;
253 s64 bn;
254 struct metapage *mp;
255 xtpage_t *p;
256 int index;
257 lxd_t *lxd;
258 xad_t *xad, *pxd;
259 s64 size, lstart, lend, xstart, xend, pstart;
260 s64 llen, xlen, plen;
261 s64 xaddr, paddr;
262 int nlxd, npxd, maxnpxd;
263
264 npxd = xadlist->nxad = 0;
265 maxnpxd = xadlist->maxnxad;
266 pxd = xadlist->xad;
267
268 nlxd = lxdlist->nlxd;
269 lxd = lxdlist->lxd;
270
271 lstart = offsetLXD(lxd);
272 llen = lengthLXD(lxd);
273 lend = lstart + llen;
274
275 size = (ip->i_size + (JFS_SBI(ip->i_sb)->bsize - 1)) >>
276 JFS_SBI(ip->i_sb)->l2bsize;
277
278 /*
279 * search for the xad entry covering the logical extent
280 */
281 search:
282 if (lstart >= size)
283 return 0;
284
285 if ((rc = xtSearch(ip, lstart, NULL, &cmp, &btstack, 0)))
286 return rc;
287
288 /*
289 * compute the physical extent covering logical extent
290 *
291 * N.B. search may have failed (e.g., hole in sparse file),
292 * and returned the index of the next entry.
293 */
294//map:
295 /* retrieve search result */
296 XT_GETSEARCH(ip, btstack.top, bn, mp, p, index);
297
298 /* is xad on the next sibling page ? */
299 if (index == le16_to_cpu(p->header.nextindex)) {
300 if (p->header.flag & BT_ROOT)
301 goto mapend;
302
303 if ((bn = le64_to_cpu(p->header.next)) == 0)
304 goto mapend;
305
306 XT_PUTPAGE(mp);
307
308 /* get next sibling page */
309 XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
310 if (rc)
311 return rc;
312
313 index = XTENTRYSTART;
314 }
315
316 xad = &p->xad[index];
317
318 /*
319 * is lxd covered by xad ?
320 */
321 compare:
322 xstart = offsetXAD(xad);
323 xlen = lengthXAD(xad);
324 xend = xstart + xlen;
325 xaddr = addressXAD(xad);
326
327 compare1:
328 if (xstart < lstart)
329 goto compare2;
330
331 /* (lstart <= xstart) */
332
333 /* lxd is NOT covered by xad */
334 if (lend <= xstart) {
335 /*
336 * get next lxd
337 */
338 if (--nlxd == 0)
339 goto mapend;
340 lxd++;
341
342 lstart = offsetLXD(lxd);
343 llen = lengthLXD(lxd);
344 lend = lstart + llen;
345 if (lstart >= size)
346 goto mapend;
347
348 /* compare with the current xad */
349 goto compare1;
350 }
351 /* lxd is covered by xad */
352 else { /* (xstart < lend) */
353
354 /* initialize new pxd */
355 pstart = xstart;
356 plen = min(lend - xstart, xlen);
357 paddr = xaddr;
358
359 goto cover;
360 }
361
362 /* (xstart < lstart) */
363 compare2:
364 /* lxd is covered by xad */
365 if (lstart < xend) {
366 /* initialize new pxd */
367 pstart = lstart;
368 plen = min(xend - lstart, llen);
369 paddr = xaddr + (lstart - xstart);
370
371 goto cover;
372 }
373 /* lxd is NOT covered by xad */
374 else { /* (xend <= lstart) */
375
376 /*
377 * get next xad
378 *
379 * linear search next xad covering lxd on
380 * the current xad page, and then tree search
381 */
382 if (index == le16_to_cpu(p->header.nextindex) - 1) {
383 if (p->header.flag & BT_ROOT)
384 goto mapend;
385
386 XT_PUTPAGE(mp);
387 goto search;
388 } else {
389 index++;
390 xad++;
391
392 /* compare with new xad */
393 goto compare;
394 }
395 }
396
397 /*
398 * lxd is covered by xad and a new pxd has been initialized
399 * (lstart <= xstart < lend) or (xstart < lstart < xend)
400 */
401 cover:
402 /* finalize pxd corresponding to current xad */
403 XT_PUTENTRY(pxd, xad->flag, pstart, plen, paddr);
404
405 if (++npxd >= maxnpxd)
406 goto mapend;
407 pxd++;
408
409 /*
410 * lxd is fully covered by xad
411 */
412 if (lend <= xend) {
413 /*
414 * get next lxd
415 */
416 if (--nlxd == 0)
417 goto mapend;
418 lxd++;
419
420 lstart = offsetLXD(lxd);
421 llen = lengthLXD(lxd);
422 lend = lstart + llen;
423 if (lstart >= size)
424 goto mapend;
425
426 /*
427 * test for old xad covering new lxd
428 * (old xstart < new lstart)
429 */
430 goto compare2;
431 }
432 /*
433 * lxd is partially covered by xad
434 */
435 else { /* (xend < lend) */
436
437 /*
438 * get next xad
439 *
440 * linear search next xad covering lxd on
441 * the current xad page, and then next xad page search
442 */
443 if (index == le16_to_cpu(p->header.nextindex) - 1) {
444 if (p->header.flag & BT_ROOT)
445 goto mapend;
446
447 if ((bn = le64_to_cpu(p->header.next)) == 0)
448 goto mapend;
449
450 XT_PUTPAGE(mp);
451
452 /* get next sibling page */
453 XT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
454 if (rc)
455 return rc;
456
457 index = XTENTRYSTART;
458 xad = &p->xad[index];
459 } else {
460 index++;
461 xad++;
462 }
463
464 /*
465 * test for new xad covering old lxd
466 * (old lstart < new xstart)
467 */
468 goto compare;
469 }
470
471 mapend:
472 xadlist->nxad = npxd;
473
474//out:
475 XT_PUTPAGE(mp);
476
477 return rc;
478}
479
480
481/* 220/*
482 * xtSearch() 221 * xtSearch()
483 * 222 *
@@ -846,10 +585,10 @@ int xtInsert(tid_t tid, /* transaction id */
846 hint = addressXAD(xad) + lengthXAD(xad) - 1; 585 hint = addressXAD(xad) + lengthXAD(xad) - 1;
847 } else 586 } else
848 hint = 0; 587 hint = 0;
849 if ((rc = DQUOT_ALLOC_BLOCK(ip, xlen))) 588 if ((rc = vfs_dq_alloc_block(ip, xlen)))
850 goto out; 589 goto out;
851 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) { 590 if ((rc = dbAlloc(ip, hint, (s64) xlen, &xaddr))) {
852 DQUOT_FREE_BLOCK(ip, xlen); 591 vfs_dq_free_block(ip, xlen);
853 goto out; 592 goto out;
854 } 593 }
855 } 594 }
@@ -878,7 +617,7 @@ int xtInsert(tid_t tid, /* transaction id */
878 /* undo data extent allocation */ 617 /* undo data extent allocation */
879 if (*xaddrp == 0) { 618 if (*xaddrp == 0) {
880 dbFree(ip, xaddr, (s64) xlen); 619 dbFree(ip, xaddr, (s64) xlen);
881 DQUOT_FREE_BLOCK(ip, xlen); 620 vfs_dq_free_block(ip, xlen);
882 } 621 }
883 return rc; 622 return rc;
884 } 623 }
@@ -1246,7 +985,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
1246 rbn = addressPXD(pxd); 985 rbn = addressPXD(pxd);
1247 986
1248 /* Allocate blocks to quota. */ 987 /* Allocate blocks to quota. */
1249 if (DQUOT_ALLOC_BLOCK(ip, lengthPXD(pxd))) { 988 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) {
1250 rc = -EDQUOT; 989 rc = -EDQUOT;
1251 goto clean_up; 990 goto clean_up;
1252 } 991 }
@@ -1456,7 +1195,7 @@ xtSplitPage(tid_t tid, struct inode *ip,
1456 1195
1457 /* Rollback quota allocation. */ 1196 /* Rollback quota allocation. */
1458 if (quota_allocation) 1197 if (quota_allocation)
1459 DQUOT_FREE_BLOCK(ip, quota_allocation); 1198 vfs_dq_free_block(ip, quota_allocation);
1460 1199
1461 return (rc); 1200 return (rc);
1462} 1201}
@@ -1513,7 +1252,7 @@ xtSplitRoot(tid_t tid,
1513 return -EIO; 1252 return -EIO;
1514 1253
1515 /* Allocate blocks to quota. */ 1254 /* Allocate blocks to quota. */
1516 if (DQUOT_ALLOC_BLOCK(ip, lengthPXD(pxd))) { 1255 if (vfs_dq_alloc_block(ip, lengthPXD(pxd))) {
1517 release_metapage(rmp); 1256 release_metapage(rmp);
1518 return -EDQUOT; 1257 return -EDQUOT;
1519 } 1258 }
@@ -3941,7 +3680,7 @@ s64 xtTruncate(tid_t tid, struct inode *ip, s64 newsize, int flag)
3941 ip->i_size = newsize; 3680 ip->i_size = newsize;
3942 3681
3943 /* update quota allocation to reflect freed blocks */ 3682 /* update quota allocation to reflect freed blocks */
3944 DQUOT_FREE_BLOCK(ip, nfreed); 3683 vfs_dq_free_block(ip, nfreed);
3945 3684
3946 /* 3685 /*
3947 * free tlock of invalidated pages 3686 * free tlock of invalidated pages
diff --git a/fs/jfs/jfs_xtree.h b/fs/jfs/jfs_xtree.h
index 70815c8a3d6..08c0c749b98 100644
--- a/fs/jfs/jfs_xtree.h
+++ b/fs/jfs/jfs_xtree.h
@@ -110,8 +110,6 @@ typedef union {
110 */ 110 */
111extern int xtLookup(struct inode *ip, s64 lstart, s64 llen, 111extern int xtLookup(struct inode *ip, s64 lstart, s64 llen,
112 int *pflag, s64 * paddr, int *plen, int flag); 112 int *pflag, s64 * paddr, int *plen, int flag);
113extern int xtLookupList(struct inode *ip, struct lxdlist * lxdlist,
114 struct xadlist * xadlist, int flag);
115extern void xtInitRoot(tid_t tid, struct inode *ip); 113extern void xtInitRoot(tid_t tid, struct inode *ip);
116extern int xtInsert(tid_t tid, struct inode *ip, 114extern int xtInsert(tid_t tid, struct inode *ip,
117 int xflag, s64 xoff, int xlen, s64 * xaddrp, int flag); 115 int xflag, s64 xoff, int xlen, s64 * xaddrp, int flag);
diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index b4de56b851e..514ee2edb92 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -35,7 +35,7 @@
35/* 35/*
36 * forward references 36 * forward references
37 */ 37 */
38struct dentry_operations jfs_ci_dentry_operations; 38const struct dentry_operations jfs_ci_dentry_operations;
39 39
40static s64 commitZeroLink(tid_t, struct inode *); 40static s64 commitZeroLink(tid_t, struct inode *);
41 41
@@ -356,7 +356,7 @@ static int jfs_rmdir(struct inode *dip, struct dentry *dentry)
356 jfs_info("jfs_rmdir: dip:0x%p name:%s", dip, dentry->d_name.name); 356 jfs_info("jfs_rmdir: dip:0x%p name:%s", dip, dentry->d_name.name);
357 357
358 /* Init inode for quota operations. */ 358 /* Init inode for quota operations. */
359 DQUOT_INIT(ip); 359 vfs_dq_init(ip);
360 360
361 /* directory must be empty to be removed */ 361 /* directory must be empty to be removed */
362 if (!dtEmpty(ip)) { 362 if (!dtEmpty(ip)) {
@@ -483,7 +483,7 @@ static int jfs_unlink(struct inode *dip, struct dentry *dentry)
483 jfs_info("jfs_unlink: dip:0x%p name:%s", dip, dentry->d_name.name); 483 jfs_info("jfs_unlink: dip:0x%p name:%s", dip, dentry->d_name.name);
484 484
485 /* Init inode for quota operations. */ 485 /* Init inode for quota operations. */
486 DQUOT_INIT(ip); 486 vfs_dq_init(ip);
487 487
488 if ((rc = get_UCSname(&dname, dentry))) 488 if ((rc = get_UCSname(&dname, dentry)))
489 goto out; 489 goto out;
@@ -1136,7 +1136,7 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1136 } else if (new_ip) { 1136 } else if (new_ip) {
1137 IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL); 1137 IWRITE_LOCK(new_ip, RDWRLOCK_NORMAL);
1138 /* Init inode for quota operations. */ 1138 /* Init inode for quota operations. */
1139 DQUOT_INIT(new_ip); 1139 vfs_dq_init(new_ip);
1140 } 1140 }
1141 1141
1142 /* 1142 /*
@@ -1595,7 +1595,7 @@ out:
1595 return result; 1595 return result;
1596} 1596}
1597 1597
1598struct dentry_operations jfs_ci_dentry_operations = 1598const struct dentry_operations jfs_ci_dentry_operations =
1599{ 1599{
1600 .d_hash = jfs_ci_hash, 1600 .d_hash = jfs_ci_hash,
1601 .d_compare = jfs_ci_compare, 1601 .d_compare = jfs_ci_compare,
diff --git a/fs/jfs/super.c b/fs/jfs/super.c
index b37d1f78b85..6f21adf9479 100644
--- a/fs/jfs/super.c
+++ b/fs/jfs/super.c
@@ -29,6 +29,7 @@
29#include <linux/posix_acl.h> 29#include <linux/posix_acl.h>
30#include <linux/buffer_head.h> 30#include <linux/buffer_head.h>
31#include <linux/exportfs.h> 31#include <linux/exportfs.h>
32#include <linux/crc32.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33#include <linux/seq_file.h> 34#include <linux/seq_file.h>
34 35
@@ -168,6 +169,9 @@ static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
168 buf->f_files = maxinodes; 169 buf->f_files = maxinodes;
169 buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) - 170 buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
170 atomic_read(&imap->im_numfree)); 171 atomic_read(&imap->im_numfree));
172 buf->f_fsid.val[0] = (u32)crc32_le(0, sbi->uuid, sizeof(sbi->uuid)/2);
173 buf->f_fsid.val[1] = (u32)crc32_le(0, sbi->uuid + sizeof(sbi->uuid)/2,
174 sizeof(sbi->uuid)/2);
171 175
172 buf->f_namelen = JFS_NAME_MAX; 176 buf->f_namelen = JFS_NAME_MAX;
173 return 0; 177 return 0;
diff --git a/fs/jfs/xattr.c b/fs/jfs/xattr.c
index 9b7f2cdaae0..61dfa8173eb 100644
--- a/fs/jfs/xattr.c
+++ b/fs/jfs/xattr.c
@@ -260,14 +260,14 @@ static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
260 nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits; 260 nblocks = (size + (sb->s_blocksize - 1)) >> sb->s_blocksize_bits;
261 261
262 /* Allocate new blocks to quota. */ 262 /* Allocate new blocks to quota. */
263 if (DQUOT_ALLOC_BLOCK(ip, nblocks)) { 263 if (vfs_dq_alloc_block(ip, nblocks)) {
264 return -EDQUOT; 264 return -EDQUOT;
265 } 265 }
266 266
267 rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno); 267 rc = dbAlloc(ip, INOHINT(ip), nblocks, &blkno);
268 if (rc) { 268 if (rc) {
269 /*Rollback quota allocation. */ 269 /*Rollback quota allocation. */
270 DQUOT_FREE_BLOCK(ip, nblocks); 270 vfs_dq_free_block(ip, nblocks);
271 return rc; 271 return rc;
272 } 272 }
273 273
@@ -332,7 +332,7 @@ static int ea_write(struct inode *ip, struct jfs_ea_list *ealist, int size,
332 332
333 failed: 333 failed:
334 /* Rollback quota allocation. */ 334 /* Rollback quota allocation. */
335 DQUOT_FREE_BLOCK(ip, nblocks); 335 vfs_dq_free_block(ip, nblocks);
336 336
337 dbFree(ip, blkno, nblocks); 337 dbFree(ip, blkno, nblocks);
338 return rc; 338 return rc;
@@ -538,7 +538,7 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
538 538
539 if (blocks_needed > current_blocks) { 539 if (blocks_needed > current_blocks) {
540 /* Allocate new blocks to quota. */ 540 /* Allocate new blocks to quota. */
541 if (DQUOT_ALLOC_BLOCK(inode, blocks_needed)) 541 if (vfs_dq_alloc_block(inode, blocks_needed))
542 return -EDQUOT; 542 return -EDQUOT;
543 543
544 quota_allocation = blocks_needed; 544 quota_allocation = blocks_needed;
@@ -602,7 +602,7 @@ static int ea_get(struct inode *inode, struct ea_buffer *ea_buf, int min_size)
602 clean_up: 602 clean_up:
603 /* Rollback quota allocation */ 603 /* Rollback quota allocation */
604 if (quota_allocation) 604 if (quota_allocation)
605 DQUOT_FREE_BLOCK(inode, quota_allocation); 605 vfs_dq_free_block(inode, quota_allocation);
606 606
607 return (rc); 607 return (rc);
608} 608}
@@ -677,7 +677,7 @@ static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf,
677 677
678 /* If old blocks exist, they must be removed from quota allocation. */ 678 /* If old blocks exist, they must be removed from quota allocation. */
679 if (old_blocks) 679 if (old_blocks)
680 DQUOT_FREE_BLOCK(inode, old_blocks); 680 vfs_dq_free_block(inode, old_blocks);
681 681
682 inode->i_ctime = CURRENT_TIME; 682 inode->i_ctime = CURRENT_TIME;
683 683
diff --git a/fs/libfs.c b/fs/libfs.c
index 49b44099dab..4910a36f516 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -44,7 +44,7 @@ static int simple_delete_dentry(struct dentry *dentry)
44 */ 44 */
45struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) 45struct dentry *simple_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
46{ 46{
47 static struct dentry_operations simple_dentry_operations = { 47 static const struct dentry_operations simple_dentry_operations = {
48 .d_delete = simple_delete_dentry, 48 .d_delete = simple_delete_dentry,
49 }; 49 };
50 50
@@ -242,7 +242,8 @@ int get_sb_pseudo(struct file_system_type *fs_type, char *name,
242 d_instantiate(dentry, root); 242 d_instantiate(dentry, root);
243 s->s_root = dentry; 243 s->s_root = dentry;
244 s->s_flags |= MS_ACTIVE; 244 s->s_flags |= MS_ACTIVE;
245 return simple_set_mnt(mnt, s); 245 simple_set_mnt(mnt, s);
246 return 0;
246 247
247Enomem: 248Enomem:
248 up_write(&s->s_umount); 249 up_write(&s->s_umount);
diff --git a/fs/namei.c b/fs/namei.c
index bbc15c23755..d040ce11785 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -24,6 +24,7 @@
24#include <linux/fsnotify.h> 24#include <linux/fsnotify.h>
25#include <linux/personality.h> 25#include <linux/personality.h>
26#include <linux/security.h> 26#include <linux/security.h>
27#include <linux/ima.h>
27#include <linux/syscalls.h> 28#include <linux/syscalls.h>
28#include <linux/mount.h> 29#include <linux/mount.h>
29#include <linux/audit.h> 30#include <linux/audit.h>
@@ -850,6 +851,8 @@ static int __link_path_walk(const char *name, struct nameidata *nd)
850 if (err == -EAGAIN) 851 if (err == -EAGAIN)
851 err = inode_permission(nd->path.dentry->d_inode, 852 err = inode_permission(nd->path.dentry->d_inode,
852 MAY_EXEC); 853 MAY_EXEC);
854 if (!err)
855 err = ima_path_check(&nd->path, MAY_EXEC);
853 if (err) 856 if (err)
854 break; 857 break;
855 858
@@ -1470,7 +1473,7 @@ int vfs_create(struct inode *dir, struct dentry *dentry, int mode,
1470 error = security_inode_create(dir, dentry, mode); 1473 error = security_inode_create(dir, dentry, mode);
1471 if (error) 1474 if (error)
1472 return error; 1475 return error;
1473 DQUOT_INIT(dir); 1476 vfs_dq_init(dir);
1474 error = dir->i_op->create(dir, dentry, mode, nd); 1477 error = dir->i_op->create(dir, dentry, mode, nd);
1475 if (!error) 1478 if (!error)
1476 fsnotify_create(dir, dentry); 1479 fsnotify_create(dir, dentry);
@@ -1486,29 +1489,32 @@ int may_open(struct path *path, int acc_mode, int flag)
1486 if (!inode) 1489 if (!inode)
1487 return -ENOENT; 1490 return -ENOENT;
1488 1491
1489 if (S_ISLNK(inode->i_mode)) 1492 switch (inode->i_mode & S_IFMT) {
1493 case S_IFLNK:
1490 return -ELOOP; 1494 return -ELOOP;
1491 1495 case S_IFDIR:
1492 if (S_ISDIR(inode->i_mode) && (acc_mode & MAY_WRITE)) 1496 if (acc_mode & MAY_WRITE)
1493 return -EISDIR; 1497 return -EISDIR;
1494 1498 break;
1495 /* 1499 case S_IFBLK:
1496 * FIFO's, sockets and device files are special: they don't 1500 case S_IFCHR:
1497 * actually live on the filesystem itself, and as such you
1498 * can write to them even if the filesystem is read-only.
1499 */
1500 if (S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
1501 flag &= ~O_TRUNC;
1502 } else if (S_ISBLK(inode->i_mode) || S_ISCHR(inode->i_mode)) {
1503 if (path->mnt->mnt_flags & MNT_NODEV) 1501 if (path->mnt->mnt_flags & MNT_NODEV)
1504 return -EACCES; 1502 return -EACCES;
1505 1503 /*FALLTHRU*/
1504 case S_IFIFO:
1505 case S_IFSOCK:
1506 flag &= ~O_TRUNC; 1506 flag &= ~O_TRUNC;
1507 break;
1507 } 1508 }
1508 1509
1509 error = inode_permission(inode, acc_mode); 1510 error = inode_permission(inode, acc_mode);
1510 if (error) 1511 if (error)
1511 return error; 1512 return error;
1513
1514 error = ima_path_check(path,
1515 acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC));
1516 if (error)
1517 return error;
1512 /* 1518 /*
1513 * An append-only file must be opened in append mode for writing. 1519 * An append-only file must be opened in append mode for writing.
1514 */ 1520 */
@@ -1544,7 +1550,7 @@ int may_open(struct path *path, int acc_mode, int flag)
1544 error = security_path_truncate(path, 0, 1550 error = security_path_truncate(path, 0,
1545 ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); 1551 ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
1546 if (!error) { 1552 if (!error) {
1547 DQUOT_INIT(inode); 1553 vfs_dq_init(inode);
1548 1554
1549 error = do_truncate(dentry, 0, 1555 error = do_truncate(dentry, 0,
1550 ATTR_MTIME|ATTR_CTIME|ATTR_OPEN, 1556 ATTR_MTIME|ATTR_CTIME|ATTR_OPEN,
@@ -1555,7 +1561,7 @@ int may_open(struct path *path, int acc_mode, int flag)
1555 return error; 1561 return error;
1556 } else 1562 } else
1557 if (flag & FMODE_WRITE) 1563 if (flag & FMODE_WRITE)
1558 DQUOT_INIT(inode); 1564 vfs_dq_init(inode);
1559 1565
1560 return 0; 1566 return 0;
1561} 1567}
@@ -1938,7 +1944,7 @@ int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
1938 if (error) 1944 if (error)
1939 return error; 1945 return error;
1940 1946
1941 DQUOT_INIT(dir); 1947 vfs_dq_init(dir);
1942 error = dir->i_op->mknod(dir, dentry, mode, dev); 1948 error = dir->i_op->mknod(dir, dentry, mode, dev);
1943 if (!error) 1949 if (!error)
1944 fsnotify_create(dir, dentry); 1950 fsnotify_create(dir, dentry);
@@ -2037,7 +2043,7 @@ int vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
2037 if (error) 2043 if (error)
2038 return error; 2044 return error;
2039 2045
2040 DQUOT_INIT(dir); 2046 vfs_dq_init(dir);
2041 error = dir->i_op->mkdir(dir, dentry, mode); 2047 error = dir->i_op->mkdir(dir, dentry, mode);
2042 if (!error) 2048 if (!error)
2043 fsnotify_mkdir(dir, dentry); 2049 fsnotify_mkdir(dir, dentry);
@@ -2123,7 +2129,7 @@ int vfs_rmdir(struct inode *dir, struct dentry *dentry)
2123 if (!dir->i_op->rmdir) 2129 if (!dir->i_op->rmdir)
2124 return -EPERM; 2130 return -EPERM;
2125 2131
2126 DQUOT_INIT(dir); 2132 vfs_dq_init(dir);
2127 2133
2128 mutex_lock(&dentry->d_inode->i_mutex); 2134 mutex_lock(&dentry->d_inode->i_mutex);
2129 dentry_unhash(dentry); 2135 dentry_unhash(dentry);
@@ -2210,7 +2216,7 @@ int vfs_unlink(struct inode *dir, struct dentry *dentry)
2210 if (!dir->i_op->unlink) 2216 if (!dir->i_op->unlink)
2211 return -EPERM; 2217 return -EPERM;
2212 2218
2213 DQUOT_INIT(dir); 2219 vfs_dq_init(dir);
2214 2220
2215 mutex_lock(&dentry->d_inode->i_mutex); 2221 mutex_lock(&dentry->d_inode->i_mutex);
2216 if (d_mountpoint(dentry)) 2222 if (d_mountpoint(dentry))
@@ -2321,7 +2327,7 @@ int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
2321 if (error) 2327 if (error)
2322 return error; 2328 return error;
2323 2329
2324 DQUOT_INIT(dir); 2330 vfs_dq_init(dir);
2325 error = dir->i_op->symlink(dir, dentry, oldname); 2331 error = dir->i_op->symlink(dir, dentry, oldname);
2326 if (!error) 2332 if (!error)
2327 fsnotify_create(dir, dentry); 2333 fsnotify_create(dir, dentry);
@@ -2405,7 +2411,7 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de
2405 return error; 2411 return error;
2406 2412
2407 mutex_lock(&inode->i_mutex); 2413 mutex_lock(&inode->i_mutex);
2408 DQUOT_INIT(dir); 2414 vfs_dq_init(dir);
2409 error = dir->i_op->link(old_dentry, dir, new_dentry); 2415 error = dir->i_op->link(old_dentry, dir, new_dentry);
2410 mutex_unlock(&inode->i_mutex); 2416 mutex_unlock(&inode->i_mutex);
2411 if (!error) 2417 if (!error)
@@ -2604,8 +2610,8 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
2604 if (!old_dir->i_op->rename) 2610 if (!old_dir->i_op->rename)
2605 return -EPERM; 2611 return -EPERM;
2606 2612
2607 DQUOT_INIT(old_dir); 2613 vfs_dq_init(old_dir);
2608 DQUOT_INIT(new_dir); 2614 vfs_dq_init(new_dir);
2609 2615
2610 old_name = fsnotify_oldname_init(old_dentry->d_name.name); 2616 old_name = fsnotify_oldname_init(old_dentry->d_name.name);
2611 2617
diff --git a/fs/namespace.c b/fs/namespace.c
index 06f8e63f6cb..0a42e0e9602 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -397,11 +397,10 @@ static void __mnt_unmake_readonly(struct vfsmount *mnt)
397 spin_unlock(&vfsmount_lock); 397 spin_unlock(&vfsmount_lock);
398} 398}
399 399
400int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb) 400void simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
401{ 401{
402 mnt->mnt_sb = sb; 402 mnt->mnt_sb = sb;
403 mnt->mnt_root = dget(sb->s_root); 403 mnt->mnt_root = dget(sb->s_root);
404 return 0;
405} 404}
406 405
407EXPORT_SYMBOL(simple_set_mnt); 406EXPORT_SYMBOL(simple_set_mnt);
@@ -780,6 +779,7 @@ static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
780 { MNT_NOATIME, ",noatime" }, 779 { MNT_NOATIME, ",noatime" },
781 { MNT_NODIRATIME, ",nodiratime" }, 780 { MNT_NODIRATIME, ",nodiratime" },
782 { MNT_RELATIME, ",relatime" }, 781 { MNT_RELATIME, ",relatime" },
782 { MNT_STRICTATIME, ",strictatime" },
783 { 0, NULL } 783 { 0, NULL }
784 }; 784 };
785 const struct proc_fs_info *fs_infop; 785 const struct proc_fs_info *fs_infop;
@@ -1919,6 +1919,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
1919 if (data_page) 1919 if (data_page)
1920 ((char *)data_page)[PAGE_SIZE - 1] = 0; 1920 ((char *)data_page)[PAGE_SIZE - 1] = 0;
1921 1921
1922 /* Default to relatime */
1923 mnt_flags |= MNT_RELATIME;
1924
1922 /* Separate the per-mountpoint flags */ 1925 /* Separate the per-mountpoint flags */
1923 if (flags & MS_NOSUID) 1926 if (flags & MS_NOSUID)
1924 mnt_flags |= MNT_NOSUID; 1927 mnt_flags |= MNT_NOSUID;
@@ -1930,13 +1933,14 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
1930 mnt_flags |= MNT_NOATIME; 1933 mnt_flags |= MNT_NOATIME;
1931 if (flags & MS_NODIRATIME) 1934 if (flags & MS_NODIRATIME)
1932 mnt_flags |= MNT_NODIRATIME; 1935 mnt_flags |= MNT_NODIRATIME;
1933 if (flags & MS_RELATIME) 1936 if (flags & MS_STRICTATIME)
1934 mnt_flags |= MNT_RELATIME; 1937 mnt_flags &= ~(MNT_RELATIME | MNT_NOATIME);
1935 if (flags & MS_RDONLY) 1938 if (flags & MS_RDONLY)
1936 mnt_flags |= MNT_READONLY; 1939 mnt_flags |= MNT_READONLY;
1937 1940
1938 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | 1941 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
1939 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT); 1942 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
1943 MS_STRICTATIME);
1940 1944
1941 /* ... and get the mountpoint */ 1945 /* ... and get the mountpoint */
1942 retval = kern_path(dir_name, LOOKUP_FOLLOW, &path); 1946 retval = kern_path(dir_name, LOOKUP_FOLLOW, &path);
diff --git a/fs/ncpfs/dir.c b/fs/ncpfs/dir.c
index 07e9715b865..9c590722d87 100644
--- a/fs/ncpfs/dir.c
+++ b/fs/ncpfs/dir.c
@@ -79,7 +79,7 @@ static int ncp_hash_dentry(struct dentry *, struct qstr *);
79static int ncp_compare_dentry (struct dentry *, struct qstr *, struct qstr *); 79static int ncp_compare_dentry (struct dentry *, struct qstr *, struct qstr *);
80static int ncp_delete_dentry(struct dentry *); 80static int ncp_delete_dentry(struct dentry *);
81 81
82static struct dentry_operations ncp_dentry_operations = 82static const struct dentry_operations ncp_dentry_operations =
83{ 83{
84 .d_revalidate = ncp_lookup_validate, 84 .d_revalidate = ncp_lookup_validate,
85 .d_hash = ncp_hash_dentry, 85 .d_hash = ncp_hash_dentry,
@@ -87,7 +87,7 @@ static struct dentry_operations ncp_dentry_operations =
87 .d_delete = ncp_delete_dentry, 87 .d_delete = ncp_delete_dentry,
88}; 88};
89 89
90struct dentry_operations ncp_root_dentry_operations = 90const struct dentry_operations ncp_root_dentry_operations =
91{ 91{
92 .d_hash = ncp_hash_dentry, 92 .d_hash = ncp_hash_dentry,
93 .d_compare = ncp_compare_dentry, 93 .d_compare = ncp_compare_dentry,
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 574158ae239..2277421656e 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -1606,8 +1606,6 @@ int __init nfs_fs_proc_init(void)
1606 if (!proc_fs_nfs) 1606 if (!proc_fs_nfs)
1607 goto error_0; 1607 goto error_0;
1608 1608
1609 proc_fs_nfs->owner = THIS_MODULE;
1610
1611 /* a file of servers with which we're dealing */ 1609 /* a file of servers with which we're dealing */
1612 p = proc_create("servers", S_IFREG|S_IRUGO, 1610 p = proc_create("servers", S_IFREG|S_IRUGO,
1613 proc_fs_nfs, &nfs_server_list_fops); 1611 proc_fs_nfs, &nfs_server_list_fops);
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 672368f865c..78bf72fc1db 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -899,7 +899,7 @@ static void nfs_dentry_iput(struct dentry *dentry, struct inode *inode)
899 iput(inode); 899 iput(inode);
900} 900}
901 901
902struct dentry_operations nfs_dentry_operations = { 902const struct dentry_operations nfs_dentry_operations = {
903 .d_revalidate = nfs_lookup_revalidate, 903 .d_revalidate = nfs_lookup_revalidate,
904 .d_delete = nfs_dentry_delete, 904 .d_delete = nfs_dentry_delete,
905 .d_iput = nfs_dentry_iput, 905 .d_iput = nfs_dentry_iput,
@@ -967,7 +967,7 @@ out:
967#ifdef CONFIG_NFS_V4 967#ifdef CONFIG_NFS_V4
968static int nfs_open_revalidate(struct dentry *, struct nameidata *); 968static int nfs_open_revalidate(struct dentry *, struct nameidata *);
969 969
970struct dentry_operations nfs4_dentry_operations = { 970const struct dentry_operations nfs4_dentry_operations = {
971 .d_revalidate = nfs_open_revalidate, 971 .d_revalidate = nfs_open_revalidate,
972 .d_delete = nfs_dentry_delete, 972 .d_delete = nfs_dentry_delete,
973 .d_iput = nfs_dentry_iput, 973 .d_iput = nfs_dentry_iput,
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index 4e4d3320437..84345deab26 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -179,7 +179,7 @@ struct nfs4_state_recovery_ops {
179 int (*recover_lock)(struct nfs4_state *, struct file_lock *); 179 int (*recover_lock)(struct nfs4_state *, struct file_lock *);
180}; 180};
181 181
182extern struct dentry_operations nfs4_dentry_operations; 182extern const struct dentry_operations nfs4_dentry_operations;
183extern const struct inode_operations nfs4_dir_inode_operations; 183extern const struct inode_operations nfs4_dir_inode_operations;
184 184
185/* inode.c */ 185/* inode.c */
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 6e50aaa56ca..78376b6c023 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -356,7 +356,7 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
356 put_write_access(inode); 356 put_write_access(inode);
357 goto out_nfserr; 357 goto out_nfserr;
358 } 358 }
359 DQUOT_INIT(inode); 359 vfs_dq_init(inode);
360 } 360 }
361 361
362 /* sanitize the mode change */ 362 /* sanitize the mode change */
@@ -723,7 +723,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
723 else 723 else
724 flags = O_WRONLY|O_LARGEFILE; 724 flags = O_WRONLY|O_LARGEFILE;
725 725
726 DQUOT_INIT(inode); 726 vfs_dq_init(inode);
727 } 727 }
728 *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt), 728 *filp = dentry_open(dget(dentry), mntget(fhp->fh_export->ex_path.mnt),
729 flags, cred); 729 flags, cred);
@@ -998,8 +998,11 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
998 998
999 if (!EX_ISSYNC(exp)) 999 if (!EX_ISSYNC(exp))
1000 stable = 0; 1000 stable = 0;
1001 if (stable && !EX_WGATHER(exp)) 1001 if (stable && !EX_WGATHER(exp)) {
1002 spin_lock(&file->f_lock);
1002 file->f_flags |= O_SYNC; 1003 file->f_flags |= O_SYNC;
1004 spin_unlock(&file->f_lock);
1005 }
1003 1006
1004 /* Write the data. */ 1007 /* Write the data. */
1005 oldfs = get_fs(); set_fs(KERNEL_DS); 1008 oldfs = get_fs(); set_fs(KERNEL_DS);
diff --git a/fs/notify/inotify/inotify.c b/fs/notify/inotify/inotify.c
index 331f2e88e28..220c13f0d73 100644
--- a/fs/notify/inotify/inotify.c
+++ b/fs/notify/inotify/inotify.c
@@ -380,6 +380,14 @@ void inotify_unmount_inodes(struct list_head *list)
380 struct list_head *watches; 380 struct list_head *watches;
381 381
382 /* 382 /*
383 * We cannot __iget() an inode in state I_CLEAR, I_FREEING,
384 * I_WILL_FREE, or I_NEW which is fine because by that point
385 * the inode cannot have any associated watches.
386 */
387 if (inode->i_state & (I_CLEAR|I_FREEING|I_WILL_FREE|I_NEW))
388 continue;
389
390 /*
383 * If i_count is zero, the inode cannot have any watches and 391 * If i_count is zero, the inode cannot have any watches and
384 * doing an __iget/iput with MS_ACTIVE clear would actually 392 * doing an __iget/iput with MS_ACTIVE clear would actually
385 * evict all inodes with zero i_count from icache which is 393 * evict all inodes with zero i_count from icache which is
@@ -388,14 +396,6 @@ void inotify_unmount_inodes(struct list_head *list)
388 if (!atomic_read(&inode->i_count)) 396 if (!atomic_read(&inode->i_count))
389 continue; 397 continue;
390 398
391 /*
392 * We cannot __iget() an inode in state I_CLEAR, I_FREEING, or
393 * I_WILL_FREE which is fine because by that point the inode
394 * cannot have any associated watches.
395 */
396 if (inode->i_state & (I_CLEAR | I_FREEING | I_WILL_FREE))
397 continue;
398
399 need_iput_tmp = need_iput; 399 need_iput_tmp = need_iput;
400 need_iput = NULL; 400 need_iput = NULL;
401 /* In case inotify_remove_watch_locked() drops a reference. */ 401 /* In case inotify_remove_watch_locked() drops a reference. */
diff --git a/fs/ocfs2/dcache.c b/fs/ocfs2/dcache.c
index e9d7c2038c0..7d604480557 100644
--- a/fs/ocfs2/dcache.c
+++ b/fs/ocfs2/dcache.c
@@ -455,7 +455,7 @@ out_move:
455 d_move(dentry, target); 455 d_move(dentry, target);
456} 456}
457 457
458struct dentry_operations ocfs2_dentry_ops = { 458const struct dentry_operations ocfs2_dentry_ops = {
459 .d_revalidate = ocfs2_dentry_revalidate, 459 .d_revalidate = ocfs2_dentry_revalidate,
460 .d_iput = ocfs2_dentry_iput, 460 .d_iput = ocfs2_dentry_iput,
461}; 461};
diff --git a/fs/ocfs2/dcache.h b/fs/ocfs2/dcache.h
index d06e16c0664..faa12e75f98 100644
--- a/fs/ocfs2/dcache.h
+++ b/fs/ocfs2/dcache.h
@@ -26,7 +26,7 @@
26#ifndef OCFS2_DCACHE_H 26#ifndef OCFS2_DCACHE_H
27#define OCFS2_DCACHE_H 27#define OCFS2_DCACHE_H
28 28
29extern struct dentry_operations ocfs2_dentry_ops; 29extern const struct dentry_operations ocfs2_dentry_ops;
30 30
31struct ocfs2_dentry_lock { 31struct ocfs2_dentry_lock {
32 /* Use count of dentry lock */ 32 /* Use count of dentry lock */
diff --git a/fs/open.c b/fs/open.c
index a3a78ceb2a2..75b61677daa 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -273,7 +273,7 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
273 if (!error) 273 if (!error)
274 error = security_path_truncate(&path, length, 0); 274 error = security_path_truncate(&path, length, 0);
275 if (!error) { 275 if (!error) {
276 DQUOT_INIT(inode); 276 vfs_dq_init(inode);
277 error = do_truncate(path.dentry, length, 0, NULL); 277 error = do_truncate(path.dentry, length, 0, NULL);
278 } 278 }
279 279
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 6d720243f5f..38e337d51ce 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -400,7 +400,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
400 pdev->devt = devt; 400 pdev->devt = devt;
401 401
402 /* delay uevent until 'holders' subdir is created */ 402 /* delay uevent until 'holders' subdir is created */
403 pdev->uevent_suppress = 1; 403 dev_set_uevent_suppress(pdev, 1);
404 err = device_add(pdev); 404 err = device_add(pdev);
405 if (err) 405 if (err)
406 goto out_put; 406 goto out_put;
@@ -410,7 +410,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
410 if (!p->holder_dir) 410 if (!p->holder_dir)
411 goto out_del; 411 goto out_del;
412 412
413 pdev->uevent_suppress = 0; 413 dev_set_uevent_suppress(pdev, 0);
414 if (flags & ADDPART_FLAG_WHOLEDISK) { 414 if (flags & ADDPART_FLAG_WHOLEDISK) {
415 err = device_create_file(pdev, &dev_attr_whole_disk); 415 err = device_create_file(pdev, &dev_attr_whole_disk);
416 if (err) 416 if (err)
@@ -422,7 +422,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
422 rcu_assign_pointer(ptbl->part[partno], p); 422 rcu_assign_pointer(ptbl->part[partno], p);
423 423
424 /* suppress uevent if the disk supresses it */ 424 /* suppress uevent if the disk supresses it */
425 if (!ddev->uevent_suppress) 425 if (!dev_get_uevent_suppress(pdev))
426 kobject_uevent(&pdev->kobj, KOBJ_ADD); 426 kobject_uevent(&pdev->kobj, KOBJ_ADD);
427 427
428 return p; 428 return p;
@@ -455,7 +455,7 @@ void register_disk(struct gendisk *disk)
455 dev_set_name(ddev, disk->disk_name); 455 dev_set_name(ddev, disk->disk_name);
456 456
457 /* delay uevents, until we scanned partition table */ 457 /* delay uevents, until we scanned partition table */
458 ddev->uevent_suppress = 1; 458 dev_set_uevent_suppress(ddev, 1);
459 459
460 if (device_add(ddev)) 460 if (device_add(ddev))
461 return; 461 return;
@@ -490,7 +490,7 @@ void register_disk(struct gendisk *disk)
490 490
491exit: 491exit:
492 /* announce disk after possible partitions are created */ 492 /* announce disk after possible partitions are created */
493 ddev->uevent_suppress = 0; 493 dev_set_uevent_suppress(ddev, 0);
494 kobject_uevent(&ddev->kobj, KOBJ_ADD); 494 kobject_uevent(&ddev->kobj, KOBJ_ADD);
495 495
496 /* announce possible partitions */ 496 /* announce possible partitions */
diff --git a/fs/partitions/ibm.c b/fs/partitions/ibm.c
index 1e064c4a4f8..46297683cd3 100644
--- a/fs/partitions/ibm.c
+++ b/fs/partitions/ibm.c
@@ -21,20 +21,38 @@
21 * compute the block number from a 21 * compute the block number from a
22 * cyl-cyl-head-head structure 22 * cyl-cyl-head-head structure
23 */ 23 */
24static inline int 24static sector_t
25cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) { 25cchh2blk (struct vtoc_cchh *ptr, struct hd_geometry *geo) {
26 return ptr->cc * geo->heads * geo->sectors + 26
27 ptr->hh * geo->sectors; 27 sector_t cyl;
28 __u16 head;
29
30 /*decode cylinder and heads for large volumes */
31 cyl = ptr->hh & 0xFFF0;
32 cyl <<= 12;
33 cyl |= ptr->cc;
34 head = ptr->hh & 0x000F;
35 return cyl * geo->heads * geo->sectors +
36 head * geo->sectors;
28} 37}
29 38
30/* 39/*
31 * compute the block number from a 40 * compute the block number from a
32 * cyl-cyl-head-head-block structure 41 * cyl-cyl-head-head-block structure
33 */ 42 */
34static inline int 43static sector_t
35cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) { 44cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
36 return ptr->cc * geo->heads * geo->sectors + 45
37 ptr->hh * geo->sectors + 46 sector_t cyl;
47 __u16 head;
48
49 /*decode cylinder and heads for large volumes */
50 cyl = ptr->hh & 0xFFF0;
51 cyl <<= 12;
52 cyl |= ptr->cc;
53 head = ptr->hh & 0x000F;
54 return cyl * geo->heads * geo->sectors +
55 head * geo->sectors +
38 ptr->b; 56 ptr->b;
39} 57}
40 58
@@ -43,14 +61,15 @@ cchhb2blk (struct vtoc_cchhb *ptr, struct hd_geometry *geo) {
43int 61int
44ibm_partition(struct parsed_partitions *state, struct block_device *bdev) 62ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
45{ 63{
46 int blocksize, offset, size,res; 64 int blocksize, res;
47 loff_t i_size; 65 loff_t i_size, offset, size, fmt_size;
48 dasd_information2_t *info; 66 dasd_information2_t *info;
49 struct hd_geometry *geo; 67 struct hd_geometry *geo;
50 char type[5] = {0,}; 68 char type[5] = {0,};
51 char name[7] = {0,}; 69 char name[7] = {0,};
52 union label_t { 70 union label_t {
53 struct vtoc_volume_label vol; 71 struct vtoc_volume_label_cdl vol;
72 struct vtoc_volume_label_ldl lnx;
54 struct vtoc_cms_label cms; 73 struct vtoc_cms_label cms;
55 } *label; 74 } *label;
56 unsigned char *data; 75 unsigned char *data;
@@ -85,14 +104,16 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
85 if (data == NULL) 104 if (data == NULL)
86 goto out_readerr; 105 goto out_readerr;
87 106
88 strncpy (type, data, 4);
89 if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD")))
90 strncpy(name, data + 8, 6);
91 else
92 strncpy(name, data + 4, 6);
93 memcpy(label, data, sizeof(union label_t)); 107 memcpy(label, data, sizeof(union label_t));
94 put_dev_sector(sect); 108 put_dev_sector(sect);
95 109
110 if ((!info->FBA_layout) && (!strcmp(info->type, "ECKD"))) {
111 strncpy(type, label->vol.vollbl, 4);
112 strncpy(name, label->vol.volid, 6);
113 } else {
114 strncpy(type, label->lnx.vollbl, 4);
115 strncpy(name, label->lnx.volid, 6);
116 }
96 EBCASC(type, 4); 117 EBCASC(type, 4);
97 EBCASC(name, 6); 118 EBCASC(name, 6);
98 119
@@ -110,36 +131,54 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
110 /* 131 /*
111 * VM style CMS1 labeled disk 132 * VM style CMS1 labeled disk
112 */ 133 */
134 blocksize = label->cms.block_size;
113 if (label->cms.disk_offset != 0) { 135 if (label->cms.disk_offset != 0) {
114 printk("CMS1/%8s(MDSK):", name); 136 printk("CMS1/%8s(MDSK):", name);
115 /* disk is reserved minidisk */ 137 /* disk is reserved minidisk */
116 blocksize = label->cms.block_size;
117 offset = label->cms.disk_offset; 138 offset = label->cms.disk_offset;
118 size = (label->cms.block_count - 1) 139 size = (label->cms.block_count - 1)
119 * (blocksize >> 9); 140 * (blocksize >> 9);
120 } else { 141 } else {
121 printk("CMS1/%8s:", name); 142 printk("CMS1/%8s:", name);
122 offset = (info->label_block + 1); 143 offset = (info->label_block + 1);
123 size = i_size >> 9; 144 size = label->cms.block_count
145 * (blocksize >> 9);
124 } 146 }
147 put_partition(state, 1, offset*(blocksize >> 9),
148 size-offset*(blocksize >> 9));
125 } else { 149 } else {
126 /* 150 if (strncmp(type, "LNX1", 4) == 0) {
127 * Old style LNX1 or unlabeled disk 151 printk("LNX1/%8s:", name);
128 */ 152 if (label->lnx.ldl_version == 0xf2) {
129 if (strncmp(type, "LNX1", 4) == 0) 153 fmt_size = label->lnx.formatted_blocks
130 printk ("LNX1/%8s:", name); 154 * (blocksize >> 9);
131 else 155 } else if (!strcmp(info->type, "ECKD")) {
156 /* formated w/o large volume support */
157 fmt_size = geo->cylinders * geo->heads
158 * geo->sectors * (blocksize >> 9);
159 } else {
160 /* old label and no usable disk geometry
161 * (e.g. DIAG) */
162 fmt_size = i_size >> 9;
163 }
164 size = i_size >> 9;
165 if (fmt_size < size)
166 size = fmt_size;
167 offset = (info->label_block + 1);
168 } else {
169 /* unlabeled disk */
132 printk("(nonl)"); 170 printk("(nonl)");
133 offset = (info->label_block + 1); 171 size = i_size >> 9;
134 size = i_size >> 9; 172 offset = (info->label_block + 1);
135 } 173 }
136 put_partition(state, 1, offset*(blocksize >> 9), 174 put_partition(state, 1, offset*(blocksize >> 9),
137 size-offset*(blocksize >> 9)); 175 size-offset*(blocksize >> 9));
176 }
138 } else if (info->format == DASD_FORMAT_CDL) { 177 } else if (info->format == DASD_FORMAT_CDL) {
139 /* 178 /*
140 * New style CDL formatted disk 179 * New style CDL formatted disk
141 */ 180 */
142 unsigned int blk; 181 sector_t blk;
143 int counter; 182 int counter;
144 183
145 /* 184 /*
@@ -166,7 +205,8 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
166 /* skip FMT4 / FMT5 / FMT7 labels */ 205 /* skip FMT4 / FMT5 / FMT7 labels */
167 if (f1.DS1FMTID == _ascebc['4'] 206 if (f1.DS1FMTID == _ascebc['4']
168 || f1.DS1FMTID == _ascebc['5'] 207 || f1.DS1FMTID == _ascebc['5']
169 || f1.DS1FMTID == _ascebc['7']) { 208 || f1.DS1FMTID == _ascebc['7']
209 || f1.DS1FMTID == _ascebc['9']) {
170 blk++; 210 blk++;
171 data = read_dev_sector(bdev, blk * 211 data = read_dev_sector(bdev, blk *
172 (blocksize/512), 212 (blocksize/512),
@@ -174,8 +214,9 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
174 continue; 214 continue;
175 } 215 }
176 216
177 /* only FMT1 valid at this point */ 217 /* only FMT1 and 8 labels valid at this point */
178 if (f1.DS1FMTID != _ascebc['1']) 218 if (f1.DS1FMTID != _ascebc['1'] &&
219 f1.DS1FMTID != _ascebc['8'])
179 break; 220 break;
180 221
181 /* OK, we got valid partition data */ 222 /* OK, we got valid partition data */
diff --git a/fs/pipe.c b/fs/pipe.c
index 14f502b89cf..4af7aa52181 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -667,10 +667,7 @@ pipe_read_fasync(int fd, struct file *filp, int on)
667 retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers); 667 retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_readers);
668 mutex_unlock(&inode->i_mutex); 668 mutex_unlock(&inode->i_mutex);
669 669
670 if (retval < 0) 670 return retval;
671 return retval;
672
673 return 0;
674} 671}
675 672
676 673
@@ -684,10 +681,7 @@ pipe_write_fasync(int fd, struct file *filp, int on)
684 retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers); 681 retval = fasync_helper(fd, filp, on, &inode->i_pipe->fasync_writers);
685 mutex_unlock(&inode->i_mutex); 682 mutex_unlock(&inode->i_mutex);
686 683
687 if (retval < 0) 684 return retval;
688 return retval;
689
690 return 0;
691} 685}
692 686
693 687
@@ -706,11 +700,7 @@ pipe_rdwr_fasync(int fd, struct file *filp, int on)
706 fasync_helper(-1, filp, 0, &pipe->fasync_readers); 700 fasync_helper(-1, filp, 0, &pipe->fasync_readers);
707 } 701 }
708 mutex_unlock(&inode->i_mutex); 702 mutex_unlock(&inode->i_mutex);
709 703 return retval;
710 if (retval < 0)
711 return retval;
712
713 return 0;
714} 704}
715 705
716 706
@@ -870,7 +860,7 @@ static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen)
870 dentry->d_inode->i_ino); 860 dentry->d_inode->i_ino);
871} 861}
872 862
873static struct dentry_operations pipefs_dentry_operations = { 863static const struct dentry_operations pipefs_dentry_operations = {
874 .d_delete = pipefs_delete_dentry, 864 .d_delete = pipefs_delete_dentry,
875 .d_dname = pipefs_dname, 865 .d_dname = pipefs_dname,
876}; 866};
@@ -1034,11 +1024,6 @@ int do_pipe_flags(int *fd, int flags)
1034 return error; 1024 return error;
1035} 1025}
1036 1026
1037int do_pipe(int *fd)
1038{
1039 return do_pipe_flags(fd, 0);
1040}
1041
1042/* 1027/*
1043 * sys_pipe() is the normal C calling standard for creating 1028 * sys_pipe() is the normal C calling standard for creating
1044 * a pipe. It's not the way Unix traditionally does this, though. 1029 * a pipe. It's not the way Unix traditionally does this, though.
diff --git a/fs/proc/base.c b/fs/proc/base.c
index beaa0ce3b82..e0afd326b68 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -146,15 +146,22 @@ static unsigned int pid_entry_count_dirs(const struct pid_entry *entries,
146 return count; 146 return count;
147} 147}
148 148
149static struct fs_struct *get_fs_struct(struct task_struct *task) 149static int get_fs_path(struct task_struct *task, struct path *path, bool root)
150{ 150{
151 struct fs_struct *fs; 151 struct fs_struct *fs;
152 int result = -ENOENT;
153
152 task_lock(task); 154 task_lock(task);
153 fs = task->fs; 155 fs = task->fs;
154 if(fs) 156 if (fs) {
155 atomic_inc(&fs->count); 157 read_lock(&fs->lock);
158 *path = root ? fs->root : fs->pwd;
159 path_get(path);
160 read_unlock(&fs->lock);
161 result = 0;
162 }
156 task_unlock(task); 163 task_unlock(task);
157 return fs; 164 return result;
158} 165}
159 166
160static int get_nr_threads(struct task_struct *tsk) 167static int get_nr_threads(struct task_struct *tsk)
@@ -172,42 +179,24 @@ static int get_nr_threads(struct task_struct *tsk)
172static int proc_cwd_link(struct inode *inode, struct path *path) 179static int proc_cwd_link(struct inode *inode, struct path *path)
173{ 180{
174 struct task_struct *task = get_proc_task(inode); 181 struct task_struct *task = get_proc_task(inode);
175 struct fs_struct *fs = NULL;
176 int result = -ENOENT; 182 int result = -ENOENT;
177 183
178 if (task) { 184 if (task) {
179 fs = get_fs_struct(task); 185 result = get_fs_path(task, path, 0);
180 put_task_struct(task); 186 put_task_struct(task);
181 } 187 }
182 if (fs) {
183 read_lock(&fs->lock);
184 *path = fs->pwd;
185 path_get(&fs->pwd);
186 read_unlock(&fs->lock);
187 result = 0;
188 put_fs_struct(fs);
189 }
190 return result; 188 return result;
191} 189}
192 190
193static int proc_root_link(struct inode *inode, struct path *path) 191static int proc_root_link(struct inode *inode, struct path *path)
194{ 192{
195 struct task_struct *task = get_proc_task(inode); 193 struct task_struct *task = get_proc_task(inode);
196 struct fs_struct *fs = NULL;
197 int result = -ENOENT; 194 int result = -ENOENT;
198 195
199 if (task) { 196 if (task) {
200 fs = get_fs_struct(task); 197 result = get_fs_path(task, path, 1);
201 put_task_struct(task); 198 put_task_struct(task);
202 } 199 }
203 if (fs) {
204 read_lock(&fs->lock);
205 *path = fs->root;
206 path_get(&fs->root);
207 read_unlock(&fs->lock);
208 result = 0;
209 put_fs_struct(fs);
210 }
211 return result; 200 return result;
212} 201}
213 202
@@ -596,7 +585,6 @@ static int mounts_open_common(struct inode *inode, struct file *file,
596 struct task_struct *task = get_proc_task(inode); 585 struct task_struct *task = get_proc_task(inode);
597 struct nsproxy *nsp; 586 struct nsproxy *nsp;
598 struct mnt_namespace *ns = NULL; 587 struct mnt_namespace *ns = NULL;
599 struct fs_struct *fs = NULL;
600 struct path root; 588 struct path root;
601 struct proc_mounts *p; 589 struct proc_mounts *p;
602 int ret = -EINVAL; 590 int ret = -EINVAL;
@@ -610,22 +598,16 @@ static int mounts_open_common(struct inode *inode, struct file *file,
610 get_mnt_ns(ns); 598 get_mnt_ns(ns);
611 } 599 }
612 rcu_read_unlock(); 600 rcu_read_unlock();
613 if (ns) 601 if (ns && get_fs_path(task, &root, 1) == 0)
614 fs = get_fs_struct(task); 602 ret = 0;
615 put_task_struct(task); 603 put_task_struct(task);
616 } 604 }
617 605
618 if (!ns) 606 if (!ns)
619 goto err; 607 goto err;
620 if (!fs) 608 if (ret)
621 goto err_put_ns; 609 goto err_put_ns;
622 610
623 read_lock(&fs->lock);
624 root = fs->root;
625 path_get(&root);
626 read_unlock(&fs->lock);
627 put_fs_struct(fs);
628
629 ret = -ENOMEM; 611 ret = -ENOMEM;
630 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL); 612 p = kmalloc(sizeof(struct proc_mounts), GFP_KERNEL);
631 if (!p) 613 if (!p)
@@ -1545,7 +1527,7 @@ static int pid_delete_dentry(struct dentry * dentry)
1545 return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first; 1527 return !proc_pid(dentry->d_inode)->tasks[PIDTYPE_PID].first;
1546} 1528}
1547 1529
1548static struct dentry_operations pid_dentry_operations = 1530static const struct dentry_operations pid_dentry_operations =
1549{ 1531{
1550 .d_revalidate = pid_revalidate, 1532 .d_revalidate = pid_revalidate,
1551 .d_delete = pid_delete_dentry, 1533 .d_delete = pid_delete_dentry,
@@ -1717,7 +1699,7 @@ static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd)
1717 return 0; 1699 return 0;
1718} 1700}
1719 1701
1720static struct dentry_operations tid_fd_dentry_operations = 1702static const struct dentry_operations tid_fd_dentry_operations =
1721{ 1703{
1722 .d_revalidate = tid_fd_revalidate, 1704 .d_revalidate = tid_fd_revalidate,
1723 .d_delete = pid_delete_dentry, 1705 .d_delete = pid_delete_dentry,
@@ -2339,7 +2321,7 @@ static int proc_base_revalidate(struct dentry *dentry, struct nameidata *nd)
2339 return 0; 2321 return 0;
2340} 2322}
2341 2323
2342static struct dentry_operations proc_base_dentry_operations = 2324static const struct dentry_operations proc_base_dentry_operations =
2343{ 2325{
2344 .d_revalidate = proc_base_revalidate, 2326 .d_revalidate = proc_base_revalidate,
2345 .d_delete = pid_delete_dentry, 2327 .d_delete = pid_delete_dentry,
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index db7fa5cab98..fa678abc9db 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -37,7 +37,7 @@ static int proc_match(int len, const char *name, struct proc_dir_entry *de)
37#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024) 37#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
38 38
39static ssize_t 39static ssize_t
40proc_file_read(struct file *file, char __user *buf, size_t nbytes, 40__proc_file_read(struct file *file, char __user *buf, size_t nbytes,
41 loff_t *ppos) 41 loff_t *ppos)
42{ 42{
43 struct inode * inode = file->f_path.dentry->d_inode; 43 struct inode * inode = file->f_path.dentry->d_inode;
@@ -183,19 +183,47 @@ proc_file_read(struct file *file, char __user *buf, size_t nbytes,
183} 183}
184 184
185static ssize_t 185static ssize_t
186proc_file_read(struct file *file, char __user *buf, size_t nbytes,
187 loff_t *ppos)
188{
189 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
190 ssize_t rv = -EIO;
191
192 spin_lock(&pde->pde_unload_lock);
193 if (!pde->proc_fops) {
194 spin_unlock(&pde->pde_unload_lock);
195 return rv;
196 }
197 pde->pde_users++;
198 spin_unlock(&pde->pde_unload_lock);
199
200 rv = __proc_file_read(file, buf, nbytes, ppos);
201
202 pde_users_dec(pde);
203 return rv;
204}
205
206static ssize_t
186proc_file_write(struct file *file, const char __user *buffer, 207proc_file_write(struct file *file, const char __user *buffer,
187 size_t count, loff_t *ppos) 208 size_t count, loff_t *ppos)
188{ 209{
189 struct inode *inode = file->f_path.dentry->d_inode; 210 struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode);
190 struct proc_dir_entry * dp; 211 ssize_t rv = -EIO;
191 212
192 dp = PDE(inode); 213 if (pde->write_proc) {
193 214 spin_lock(&pde->pde_unload_lock);
194 if (!dp->write_proc) 215 if (!pde->proc_fops) {
195 return -EIO; 216 spin_unlock(&pde->pde_unload_lock);
217 return rv;
218 }
219 pde->pde_users++;
220 spin_unlock(&pde->pde_unload_lock);
196 221
197 /* FIXME: does this routine need ppos? probably... */ 222 /* FIXME: does this routine need ppos? probably... */
198 return dp->write_proc(file, buffer, count, dp->data); 223 rv = pde->write_proc(file, buffer, count, pde->data);
224 pde_users_dec(pde);
225 }
226 return rv;
199} 227}
200 228
201 229
@@ -307,6 +335,21 @@ static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */
307/* 335/*
308 * Return an inode number between PROC_DYNAMIC_FIRST and 336 * Return an inode number between PROC_DYNAMIC_FIRST and
309 * 0xffffffff, or zero on failure. 337 * 0xffffffff, or zero on failure.
338 *
339 * Current inode allocations in the proc-fs (hex-numbers):
340 *
341 * 00000000 reserved
342 * 00000001-00000fff static entries (goners)
343 * 001 root-ino
344 *
345 * 00001000-00001fff unused
346 * 0001xxxx-7fffxxxx pid-dir entries for pid 1-7fff
347 * 80000000-efffffff unused
348 * f0000000-ffffffff dynamic entries
349 *
350 * Goal:
351 * Once we split the thing into several virtual filesystems,
352 * we will get rid of magical ranges (and this comment, BTW).
310 */ 353 */
311static unsigned int get_inode_number(void) 354static unsigned int get_inode_number(void)
312{ 355{
@@ -363,7 +406,7 @@ static int proc_delete_dentry(struct dentry * dentry)
363 return 1; 406 return 1;
364} 407}
365 408
366static struct dentry_operations proc_dentry_operations = 409static const struct dentry_operations proc_dentry_operations =
367{ 410{
368 .d_delete = proc_delete_dentry, 411 .d_delete = proc_delete_dentry,
369}; 412};
diff --git a/fs/proc/inode-alloc.txt b/fs/proc/inode-alloc.txt
deleted file mode 100644
index 77212f938c2..00000000000
--- a/fs/proc/inode-alloc.txt
+++ /dev/null
@@ -1,14 +0,0 @@
1Current inode allocations in the proc-fs (hex-numbers):
2
3 00000000 reserved
4 00000001-00000fff static entries (goners)
5 001 root-ino
6
7 00001000-00001fff unused
8 0001xxxx-7fffxxxx pid-dir entries for pid 1-7fff
9 80000000-efffffff unused
10 f0000000-ffffffff dynamic entries
11
12Goal:
13 a) once we'll split the thing into several virtual filesystems we
14 will get rid of magical ranges (and this file, BTW).
diff --git a/fs/proc/inode.c b/fs/proc/inode.c
index d8bb5c671f4..d78ade30554 100644
--- a/fs/proc/inode.c
+++ b/fs/proc/inode.c
@@ -58,11 +58,8 @@ static void proc_delete_inode(struct inode *inode)
58 58
59 /* Let go of any associated proc directory entry */ 59 /* Let go of any associated proc directory entry */
60 de = PROC_I(inode)->pde; 60 de = PROC_I(inode)->pde;
61 if (de) { 61 if (de)
62 if (de->owner)
63 module_put(de->owner);
64 de_put(de); 62 de_put(de);
65 }
66 if (PROC_I(inode)->sysctl) 63 if (PROC_I(inode)->sysctl)
67 sysctl_head_put(PROC_I(inode)->sysctl); 64 sysctl_head_put(PROC_I(inode)->sysctl);
68 clear_inode(inode); 65 clear_inode(inode);
@@ -127,7 +124,7 @@ static void __pde_users_dec(struct proc_dir_entry *pde)
127 complete(pde->pde_unload_completion); 124 complete(pde->pde_unload_completion);
128} 125}
129 126
130static void pde_users_dec(struct proc_dir_entry *pde) 127void pde_users_dec(struct proc_dir_entry *pde)
131{ 128{
132 spin_lock(&pde->pde_unload_lock); 129 spin_lock(&pde->pde_unload_lock);
133 __pde_users_dec(pde); 130 __pde_users_dec(pde);
@@ -449,12 +446,9 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
449{ 446{
450 struct inode * inode; 447 struct inode * inode;
451 448
452 if (!try_module_get(de->owner))
453 goto out_mod;
454
455 inode = iget_locked(sb, ino); 449 inode = iget_locked(sb, ino);
456 if (!inode) 450 if (!inode)
457 goto out_ino; 451 return NULL;
458 if (inode->i_state & I_NEW) { 452 if (inode->i_state & I_NEW) {
459 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; 453 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
460 PROC_I(inode)->fd = 0; 454 PROC_I(inode)->fd = 0;
@@ -485,16 +479,9 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino,
485 } 479 }
486 } 480 }
487 unlock_new_inode(inode); 481 unlock_new_inode(inode);
488 } else { 482 } else
489 module_put(de->owner);
490 de_put(de); 483 de_put(de);
491 }
492 return inode; 484 return inode;
493
494out_ino:
495 module_put(de->owner);
496out_mod:
497 return NULL;
498} 485}
499 486
500int proc_fill_super(struct super_block *s) 487int proc_fill_super(struct super_block *s)
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index cd53ff83849..f6db9618a88 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -91,3 +91,4 @@ struct pde_opener {
91 int (*release)(struct inode *, struct file *); 91 int (*release)(struct inode *, struct file *);
92 struct list_head lh; 92 struct list_head lh;
93}; 93};
94void pde_users_dec(struct proc_dir_entry *pde);
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 94fcfff6863..9b1e4e9a16b 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -7,7 +7,7 @@
7#include <linux/security.h> 7#include <linux/security.h>
8#include "internal.h" 8#include "internal.h"
9 9
10static struct dentry_operations proc_sys_dentry_operations; 10static const struct dentry_operations proc_sys_dentry_operations;
11static const struct file_operations proc_sys_file_operations; 11static const struct file_operations proc_sys_file_operations;
12static const struct inode_operations proc_sys_inode_operations; 12static const struct inode_operations proc_sys_inode_operations;
13static const struct file_operations proc_sys_dir_file_operations; 13static const struct file_operations proc_sys_dir_file_operations;
@@ -396,7 +396,7 @@ static int proc_sys_compare(struct dentry *dir, struct qstr *qstr,
396 return !sysctl_is_seen(PROC_I(dentry->d_inode)->sysctl); 396 return !sysctl_is_seen(PROC_I(dentry->d_inode)->sysctl);
397} 397}
398 398
399static struct dentry_operations proc_sys_dentry_operations = { 399static const struct dentry_operations proc_sys_dentry_operations = {
400 .d_revalidate = proc_sys_revalidate, 400 .d_revalidate = proc_sys_revalidate,
401 .d_delete = proc_sys_delete, 401 .d_delete = proc_sys_delete,
402 .d_compare = proc_sys_compare, 402 .d_compare = proc_sys_compare,
diff --git a/fs/proc/proc_tty.c b/fs/proc/proc_tty.c
index d153946d6d1..4a9e0f65ae6 100644
--- a/fs/proc/proc_tty.c
+++ b/fs/proc/proc_tty.c
@@ -152,7 +152,6 @@ void proc_tty_register_driver(struct tty_driver *driver)
152 if (!ent) 152 if (!ent)
153 return; 153 return;
154 ent->read_proc = driver->ops->read_proc; 154 ent->read_proc = driver->ops->read_proc;
155 ent->owner = driver->owner;
156 ent->data = driver; 155 ent->data = driver;
157 156
158 driver->proc_entry = ent; 157 driver->proc_entry = ent;
diff --git a/fs/proc/root.c b/fs/proc/root.c
index f6299a25594..1e15a2b176e 100644
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -83,7 +83,8 @@ static int proc_get_sb(struct file_system_type *fs_type,
83 ns->proc_mnt = mnt; 83 ns->proc_mnt = mnt;
84 } 84 }
85 85
86 return simple_set_mnt(mnt, sb); 86 simple_set_mnt(mnt, sb);
87 return 0;
87} 88}
88 89
89static void proc_kill_sb(struct super_block *sb) 90static void proc_kill_sb(struct super_block *sb)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 94063840832..b0ae0be4801 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -693,8 +693,8 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
693 goto out_pages; 693 goto out_pages;
694 } 694 }
695 695
696 pm.out = (u64 *)buf; 696 pm.out = (u64 __user *)buf;
697 pm.end = (u64 *)(buf + count); 697 pm.end = (u64 __user *)(buf + count);
698 698
699 pagemap_walk.pmd_entry = pagemap_pte_range; 699 pagemap_walk.pmd_entry = pagemap_pte_range;
700 pagemap_walk.pte_hole = pagemap_pte_hole; 700 pagemap_walk.pte_hole = pagemap_pte_hole;
@@ -720,9 +720,9 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
720 if (ret == PM_END_OF_BUFFER) 720 if (ret == PM_END_OF_BUFFER)
721 ret = 0; 721 ret = 0;
722 /* don't need mmap_sem for these, but this looks cleaner */ 722 /* don't need mmap_sem for these, but this looks cleaner */
723 *ppos += (char *)pm.out - buf; 723 *ppos += (char __user *)pm.out - buf;
724 if (!ret) 724 if (!ret)
725 ret = (char *)pm.out - buf; 725 ret = (char __user *)pm.out - buf;
726 726
727out_pages: 727out_pages:
728 for (; pagecount; pagecount--) { 728 for (; pagecount; pagecount--) {
diff --git a/fs/proc/uptime.c b/fs/proc/uptime.c
index df26aa88fa4..0c10a0b3f14 100644
--- a/fs/proc/uptime.c
+++ b/fs/proc/uptime.c
@@ -1,45 +1,43 @@
1#include <linux/fs.h>
1#include <linux/init.h> 2#include <linux/init.h>
2#include <linux/proc_fs.h> 3#include <linux/proc_fs.h>
3#include <linux/sched.h> 4#include <linux/sched.h>
5#include <linux/seq_file.h>
4#include <linux/time.h> 6#include <linux/time.h>
5#include <asm/cputime.h> 7#include <asm/cputime.h>
6 8
7static int proc_calc_metrics(char *page, char **start, off_t off, 9static int uptime_proc_show(struct seq_file *m, void *v)
8 int count, int *eof, int len)
9{
10 if (len <= off + count)
11 *eof = 1;
12 *start = page + off;
13 len -= off;
14 if (len > count)
15 len = count;
16 if (len < 0)
17 len = 0;
18 return len;
19}
20
21static int uptime_read_proc(char *page, char **start, off_t off, int count,
22 int *eof, void *data)
23{ 10{
24 struct timespec uptime; 11 struct timespec uptime;
25 struct timespec idle; 12 struct timespec idle;
26 int len;
27 cputime_t idletime = cputime_add(init_task.utime, init_task.stime); 13 cputime_t idletime = cputime_add(init_task.utime, init_task.stime);
28 14
29 do_posix_clock_monotonic_gettime(&uptime); 15 do_posix_clock_monotonic_gettime(&uptime);
30 monotonic_to_bootbased(&uptime); 16 monotonic_to_bootbased(&uptime);
31 cputime_to_timespec(idletime, &idle); 17 cputime_to_timespec(idletime, &idle);
32 len = sprintf(page, "%lu.%02lu %lu.%02lu\n", 18 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
33 (unsigned long) uptime.tv_sec, 19 (unsigned long) uptime.tv_sec,
34 (uptime.tv_nsec / (NSEC_PER_SEC / 100)), 20 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
35 (unsigned long) idle.tv_sec, 21 (unsigned long) idle.tv_sec,
36 (idle.tv_nsec / (NSEC_PER_SEC / 100))); 22 (idle.tv_nsec / (NSEC_PER_SEC / 100)));
37 return proc_calc_metrics(page, start, off, count, eof, len); 23 return 0;
38} 24}
39 25
26static int uptime_proc_open(struct inode *inode, struct file *file)
27{
28 return single_open(file, uptime_proc_show, NULL);
29}
30
31static const struct file_operations uptime_proc_fops = {
32 .open = uptime_proc_open,
33 .read = seq_read,
34 .llseek = seq_lseek,
35 .release = single_release,
36};
37
40static int __init proc_uptime_init(void) 38static int __init proc_uptime_init(void)
41{ 39{
42 create_proc_read_entry("uptime", 0, NULL, uptime_read_proc, NULL); 40 proc_create("uptime", 0, NULL, &uptime_proc_fops);
43 return 0; 41 return 0;
44} 42}
45module_init(proc_uptime_init); 43module_init(proc_uptime_init);
diff --git a/fs/quota/Kconfig b/fs/quota/Kconfig
new file mode 100644
index 00000000000..8047e01ef46
--- /dev/null
+++ b/fs/quota/Kconfig
@@ -0,0 +1,59 @@
1#
2# Quota configuration
3#
4
5config QUOTA
6 bool "Quota support"
7 help
8 If you say Y here, you will be able to set per user limits for disk
9 usage (also called disk quotas). Currently, it works for the
10 ext2, ext3, and reiserfs file system. ext3 also supports journalled
11 quotas for which you don't need to run quotacheck(8) after an unclean
12 shutdown.
13 For further details, read the Quota mini-HOWTO, available from
14 <http://www.tldp.org/docs.html#howto>, or the documentation provided
15 with the quota tools. Probably the quota support is only useful for
16 multi user systems. If unsure, say N.
17
18config QUOTA_NETLINK_INTERFACE
19 bool "Report quota messages through netlink interface"
20 depends on QUOTA && NET
21 help
22 If you say Y here, quota warnings (about exceeding softlimit, reaching
23 hardlimit, etc.) will be reported through netlink interface. If unsure,
24 say Y.
25
26config PRINT_QUOTA_WARNING
27 bool "Print quota warnings to console (OBSOLETE)"
28 depends on QUOTA
29 default y
30 help
31 If you say Y here, quota warnings (about exceeding softlimit, reaching
32 hardlimit, etc.) will be printed to the process' controlling terminal.
33 Note that this behavior is currently deprecated and may go away in
34 future. Please use notification via netlink socket instead.
35
36# Generic support for tree structured quota files. Selected when needed.
37config QUOTA_TREE
38 tristate
39
40config QFMT_V1
41 tristate "Old quota format support"
42 depends on QUOTA
43 help
44 This quota format was (is) used by kernels earlier than 2.4.22. If
45 you have quota working and you don't want to convert to new quota
46 format say Y here.
47
48config QFMT_V2
49 tristate "Quota format v2 support"
50 depends on QUOTA
51 select QUOTA_TREE
52 help
53 This quota format allows using quotas with 32-bit UIDs/GIDs. If you
54 need this functionality say Y here.
55
56config QUOTACTL
57 bool
58 depends on XFS_QUOTA || QUOTA
59 default y
diff --git a/fs/quota/Makefile b/fs/quota/Makefile
new file mode 100644
index 00000000000..385a0831cc9
--- /dev/null
+++ b/fs/quota/Makefile
@@ -0,0 +1,14 @@
1#
2# Makefile for the Linux filesystems.
3#
4# 14 Sep 2000, Christoph Hellwig <hch@infradead.org>
5# Rewritten to use lists instead of if-statements.
6#
7
8obj-y :=
9
10obj-$(CONFIG_QUOTA) += dquot.o
11obj-$(CONFIG_QFMT_V1) += quota_v1.o
12obj-$(CONFIG_QFMT_V2) += quota_v2.o
13obj-$(CONFIG_QUOTA_TREE) += quota_tree.o
14obj-$(CONFIG_QUOTACTL) += quota.o
diff --git a/fs/dquot.c b/fs/quota/dquot.c
index bca3cac4bee..2ca967a5ef7 100644
--- a/fs/dquot.c
+++ b/fs/quota/dquot.c
@@ -129,9 +129,10 @@
129 * i_mutex on quota files is special (it's below dqio_mutex) 129 * i_mutex on quota files is special (it's below dqio_mutex)
130 */ 130 */
131 131
132static DEFINE_SPINLOCK(dq_list_lock); 132static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_list_lock);
133static DEFINE_SPINLOCK(dq_state_lock); 133static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_state_lock);
134DEFINE_SPINLOCK(dq_data_lock); 134__cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_data_lock);
135EXPORT_SYMBOL(dq_data_lock);
135 136
136static char *quotatypes[] = INITQFNAMES; 137static char *quotatypes[] = INITQFNAMES;
137static struct quota_format_type *quota_formats; /* List of registered formats */ 138static struct quota_format_type *quota_formats; /* List of registered formats */
@@ -148,35 +149,46 @@ int register_quota_format(struct quota_format_type *fmt)
148 spin_unlock(&dq_list_lock); 149 spin_unlock(&dq_list_lock);
149 return 0; 150 return 0;
150} 151}
152EXPORT_SYMBOL(register_quota_format);
151 153
152void unregister_quota_format(struct quota_format_type *fmt) 154void unregister_quota_format(struct quota_format_type *fmt)
153{ 155{
154 struct quota_format_type **actqf; 156 struct quota_format_type **actqf;
155 157
156 spin_lock(&dq_list_lock); 158 spin_lock(&dq_list_lock);
157 for (actqf = &quota_formats; *actqf && *actqf != fmt; actqf = &(*actqf)->qf_next); 159 for (actqf = &quota_formats; *actqf && *actqf != fmt;
160 actqf = &(*actqf)->qf_next)
161 ;
158 if (*actqf) 162 if (*actqf)
159 *actqf = (*actqf)->qf_next; 163 *actqf = (*actqf)->qf_next;
160 spin_unlock(&dq_list_lock); 164 spin_unlock(&dq_list_lock);
161} 165}
166EXPORT_SYMBOL(unregister_quota_format);
162 167
163static struct quota_format_type *find_quota_format(int id) 168static struct quota_format_type *find_quota_format(int id)
164{ 169{
165 struct quota_format_type *actqf; 170 struct quota_format_type *actqf;
166 171
167 spin_lock(&dq_list_lock); 172 spin_lock(&dq_list_lock);
168 for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next); 173 for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id;
174 actqf = actqf->qf_next)
175 ;
169 if (!actqf || !try_module_get(actqf->qf_owner)) { 176 if (!actqf || !try_module_get(actqf->qf_owner)) {
170 int qm; 177 int qm;
171 178
172 spin_unlock(&dq_list_lock); 179 spin_unlock(&dq_list_lock);
173 180
174 for (qm = 0; module_names[qm].qm_fmt_id && module_names[qm].qm_fmt_id != id; qm++); 181 for (qm = 0; module_names[qm].qm_fmt_id &&
175 if (!module_names[qm].qm_fmt_id || request_module(module_names[qm].qm_mod_name)) 182 module_names[qm].qm_fmt_id != id; qm++)
183 ;
184 if (!module_names[qm].qm_fmt_id ||
185 request_module(module_names[qm].qm_mod_name))
176 return NULL; 186 return NULL;
177 187
178 spin_lock(&dq_list_lock); 188 spin_lock(&dq_list_lock);
179 for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id; actqf = actqf->qf_next); 189 for (actqf = quota_formats; actqf && actqf->qf_fmt_id != id;
190 actqf = actqf->qf_next)
191 ;
180 if (actqf && !try_module_get(actqf->qf_owner)) 192 if (actqf && !try_module_get(actqf->qf_owner))
181 actqf = NULL; 193 actqf = NULL;
182 } 194 }
@@ -215,6 +227,7 @@ static unsigned int dq_hash_bits, dq_hash_mask;
215static struct hlist_head *dquot_hash; 227static struct hlist_head *dquot_hash;
216 228
217struct dqstats dqstats; 229struct dqstats dqstats;
230EXPORT_SYMBOL(dqstats);
218 231
219static inline unsigned int 232static inline unsigned int
220hashfn(const struct super_block *sb, unsigned int id, int type) 233hashfn(const struct super_block *sb, unsigned int id, int type)
@@ -230,7 +243,8 @@ hashfn(const struct super_block *sb, unsigned int id, int type)
230 */ 243 */
231static inline void insert_dquot_hash(struct dquot *dquot) 244static inline void insert_dquot_hash(struct dquot *dquot)
232{ 245{
233 struct hlist_head *head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type); 246 struct hlist_head *head;
247 head = dquot_hash + hashfn(dquot->dq_sb, dquot->dq_id, dquot->dq_type);
234 hlist_add_head(&dquot->dq_hash, head); 248 hlist_add_head(&dquot->dq_hash, head);
235} 249}
236 250
@@ -239,17 +253,19 @@ static inline void remove_dquot_hash(struct dquot *dquot)
239 hlist_del_init(&dquot->dq_hash); 253 hlist_del_init(&dquot->dq_hash);
240} 254}
241 255
242static inline struct dquot *find_dquot(unsigned int hashent, struct super_block *sb, unsigned int id, int type) 256static struct dquot *find_dquot(unsigned int hashent, struct super_block *sb,
257 unsigned int id, int type)
243{ 258{
244 struct hlist_node *node; 259 struct hlist_node *node;
245 struct dquot *dquot; 260 struct dquot *dquot;
246 261
247 hlist_for_each (node, dquot_hash+hashent) { 262 hlist_for_each (node, dquot_hash+hashent) {
248 dquot = hlist_entry(node, struct dquot, dq_hash); 263 dquot = hlist_entry(node, struct dquot, dq_hash);
249 if (dquot->dq_sb == sb && dquot->dq_id == id && dquot->dq_type == type) 264 if (dquot->dq_sb == sb && dquot->dq_id == id &&
265 dquot->dq_type == type)
250 return dquot; 266 return dquot;
251 } 267 }
252 return NODQUOT; 268 return NULL;
253} 269}
254 270
255/* Add a dquot to the tail of the free list */ 271/* Add a dquot to the tail of the free list */
@@ -309,6 +325,7 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
309 spin_unlock(&dq_list_lock); 325 spin_unlock(&dq_list_lock);
310 return 0; 326 return 0;
311} 327}
328EXPORT_SYMBOL(dquot_mark_dquot_dirty);
312 329
313/* This function needs dq_list_lock */ 330/* This function needs dq_list_lock */
314static inline int clear_dquot_dirty(struct dquot *dquot) 331static inline int clear_dquot_dirty(struct dquot *dquot)
@@ -345,8 +362,10 @@ int dquot_acquire(struct dquot *dquot)
345 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) { 362 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && !dquot->dq_off) {
346 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); 363 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
347 /* Write the info if needed */ 364 /* Write the info if needed */
348 if (info_dirty(&dqopt->info[dquot->dq_type])) 365 if (info_dirty(&dqopt->info[dquot->dq_type])) {
349 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); 366 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
367 dquot->dq_sb, dquot->dq_type);
368 }
350 if (ret < 0) 369 if (ret < 0)
351 goto out_iolock; 370 goto out_iolock;
352 if (ret2 < 0) { 371 if (ret2 < 0) {
@@ -360,6 +379,7 @@ out_iolock:
360 mutex_unlock(&dquot->dq_lock); 379 mutex_unlock(&dquot->dq_lock);
361 return ret; 380 return ret;
362} 381}
382EXPORT_SYMBOL(dquot_acquire);
363 383
364/* 384/*
365 * Write dquot to disk 385 * Write dquot to disk
@@ -380,8 +400,10 @@ int dquot_commit(struct dquot *dquot)
380 * => we have better not writing it */ 400 * => we have better not writing it */
381 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { 401 if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
382 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); 402 ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot);
383 if (info_dirty(&dqopt->info[dquot->dq_type])) 403 if (info_dirty(&dqopt->info[dquot->dq_type])) {
384 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); 404 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
405 dquot->dq_sb, dquot->dq_type);
406 }
385 if (ret >= 0) 407 if (ret >= 0)
386 ret = ret2; 408 ret = ret2;
387 } 409 }
@@ -389,6 +411,7 @@ out_sem:
389 mutex_unlock(&dqopt->dqio_mutex); 411 mutex_unlock(&dqopt->dqio_mutex);
390 return ret; 412 return ret;
391} 413}
414EXPORT_SYMBOL(dquot_commit);
392 415
393/* 416/*
394 * Release dquot 417 * Release dquot
@@ -406,8 +429,10 @@ int dquot_release(struct dquot *dquot)
406 if (dqopt->ops[dquot->dq_type]->release_dqblk) { 429 if (dqopt->ops[dquot->dq_type]->release_dqblk) {
407 ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot); 430 ret = dqopt->ops[dquot->dq_type]->release_dqblk(dquot);
408 /* Write the info */ 431 /* Write the info */
409 if (info_dirty(&dqopt->info[dquot->dq_type])) 432 if (info_dirty(&dqopt->info[dquot->dq_type])) {
410 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(dquot->dq_sb, dquot->dq_type); 433 ret2 = dqopt->ops[dquot->dq_type]->write_file_info(
434 dquot->dq_sb, dquot->dq_type);
435 }
411 if (ret >= 0) 436 if (ret >= 0)
412 ret = ret2; 437 ret = ret2;
413 } 438 }
@@ -417,6 +442,7 @@ out_dqlock:
417 mutex_unlock(&dquot->dq_lock); 442 mutex_unlock(&dquot->dq_lock);
418 return ret; 443 return ret;
419} 444}
445EXPORT_SYMBOL(dquot_release);
420 446
421void dquot_destroy(struct dquot *dquot) 447void dquot_destroy(struct dquot *dquot)
422{ 448{
@@ -516,6 +542,7 @@ out:
516 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); 542 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
517 return ret; 543 return ret;
518} 544}
545EXPORT_SYMBOL(dquot_scan_active);
519 546
520int vfs_quota_sync(struct super_block *sb, int type) 547int vfs_quota_sync(struct super_block *sb, int type)
521{ 548{
@@ -533,7 +560,8 @@ int vfs_quota_sync(struct super_block *sb, int type)
533 spin_lock(&dq_list_lock); 560 spin_lock(&dq_list_lock);
534 dirty = &dqopt->info[cnt].dqi_dirty_list; 561 dirty = &dqopt->info[cnt].dqi_dirty_list;
535 while (!list_empty(dirty)) { 562 while (!list_empty(dirty)) {
536 dquot = list_first_entry(dirty, struct dquot, dq_dirty); 563 dquot = list_first_entry(dirty, struct dquot,
564 dq_dirty);
537 /* Dirty and inactive can be only bad dquot... */ 565 /* Dirty and inactive can be only bad dquot... */
538 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { 566 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) {
539 clear_dquot_dirty(dquot); 567 clear_dquot_dirty(dquot);
@@ -563,6 +591,7 @@ int vfs_quota_sync(struct super_block *sb, int type)
563 591
564 return 0; 592 return 0;
565} 593}
594EXPORT_SYMBOL(vfs_quota_sync);
566 595
567/* Free unused dquots from cache */ 596/* Free unused dquots from cache */
568static void prune_dqcache(int count) 597static void prune_dqcache(int count)
@@ -672,6 +701,7 @@ we_slept:
672 put_dquot_last(dquot); 701 put_dquot_last(dquot);
673 spin_unlock(&dq_list_lock); 702 spin_unlock(&dq_list_lock);
674} 703}
704EXPORT_SYMBOL(dqput);
675 705
676struct dquot *dquot_alloc(struct super_block *sb, int type) 706struct dquot *dquot_alloc(struct super_block *sb, int type)
677{ 707{
@@ -685,7 +715,7 @@ static struct dquot *get_empty_dquot(struct super_block *sb, int type)
685 715
686 dquot = sb->dq_op->alloc_dquot(sb, type); 716 dquot = sb->dq_op->alloc_dquot(sb, type);
687 if(!dquot) 717 if(!dquot)
688 return NODQUOT; 718 return NULL;
689 719
690 mutex_init(&dquot->dq_lock); 720 mutex_init(&dquot->dq_lock);
691 INIT_LIST_HEAD(&dquot->dq_free); 721 INIT_LIST_HEAD(&dquot->dq_free);
@@ -711,10 +741,10 @@ static struct dquot *get_empty_dquot(struct super_block *sb, int type)
711struct dquot *dqget(struct super_block *sb, unsigned int id, int type) 741struct dquot *dqget(struct super_block *sb, unsigned int id, int type)
712{ 742{
713 unsigned int hashent = hashfn(sb, id, type); 743 unsigned int hashent = hashfn(sb, id, type);
714 struct dquot *dquot = NODQUOT, *empty = NODQUOT; 744 struct dquot *dquot = NULL, *empty = NULL;
715 745
716 if (!sb_has_quota_active(sb, type)) 746 if (!sb_has_quota_active(sb, type))
717 return NODQUOT; 747 return NULL;
718we_slept: 748we_slept:
719 spin_lock(&dq_list_lock); 749 spin_lock(&dq_list_lock);
720 spin_lock(&dq_state_lock); 750 spin_lock(&dq_state_lock);
@@ -725,15 +755,17 @@ we_slept:
725 } 755 }
726 spin_unlock(&dq_state_lock); 756 spin_unlock(&dq_state_lock);
727 757
728 if ((dquot = find_dquot(hashent, sb, id, type)) == NODQUOT) { 758 dquot = find_dquot(hashent, sb, id, type);
729 if (empty == NODQUOT) { 759 if (!dquot) {
760 if (!empty) {
730 spin_unlock(&dq_list_lock); 761 spin_unlock(&dq_list_lock);
731 if ((empty = get_empty_dquot(sb, type)) == NODQUOT) 762 empty = get_empty_dquot(sb, type);
763 if (!empty)
732 schedule(); /* Try to wait for a moment... */ 764 schedule(); /* Try to wait for a moment... */
733 goto we_slept; 765 goto we_slept;
734 } 766 }
735 dquot = empty; 767 dquot = empty;
736 empty = NODQUOT; 768 empty = NULL;
737 dquot->dq_id = id; 769 dquot->dq_id = id;
738 /* all dquots go on the inuse_list */ 770 /* all dquots go on the inuse_list */
739 put_inuse(dquot); 771 put_inuse(dquot);
@@ -749,13 +781,14 @@ we_slept:
749 dqstats.lookups++; 781 dqstats.lookups++;
750 spin_unlock(&dq_list_lock); 782 spin_unlock(&dq_list_lock);
751 } 783 }
752 /* Wait for dq_lock - after this we know that either dquot_release() is already 784 /* Wait for dq_lock - after this we know that either dquot_release() is
753 * finished or it will be canceled due to dq_count > 1 test */ 785 * already finished or it will be canceled due to dq_count > 1 test */
754 wait_on_dquot(dquot); 786 wait_on_dquot(dquot);
755 /* Read the dquot and instantiate it (everything done only if needed) */ 787 /* Read the dquot / allocate space in quota file */
756 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) && sb->dq_op->acquire_dquot(dquot) < 0) { 788 if (!test_bit(DQ_ACTIVE_B, &dquot->dq_flags) &&
789 sb->dq_op->acquire_dquot(dquot) < 0) {
757 dqput(dquot); 790 dqput(dquot);
758 dquot = NODQUOT; 791 dquot = NULL;
759 goto out; 792 goto out;
760 } 793 }
761#ifdef __DQUOT_PARANOIA 794#ifdef __DQUOT_PARANOIA
@@ -767,6 +800,7 @@ out:
767 800
768 return dquot; 801 return dquot;
769} 802}
803EXPORT_SYMBOL(dqget);
770 804
771static int dqinit_needed(struct inode *inode, int type) 805static int dqinit_needed(struct inode *inode, int type)
772{ 806{
@@ -775,9 +809,9 @@ static int dqinit_needed(struct inode *inode, int type)
775 if (IS_NOQUOTA(inode)) 809 if (IS_NOQUOTA(inode))
776 return 0; 810 return 0;
777 if (type != -1) 811 if (type != -1)
778 return inode->i_dquot[type] == NODQUOT; 812 return !inode->i_dquot[type];
779 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 813 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
780 if (inode->i_dquot[cnt] == NODQUOT) 814 if (!inode->i_dquot[cnt])
781 return 1; 815 return 1;
782 return 0; 816 return 0;
783} 817}
@@ -789,12 +823,12 @@ static void add_dquot_ref(struct super_block *sb, int type)
789 823
790 spin_lock(&inode_lock); 824 spin_lock(&inode_lock);
791 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { 825 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
826 if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW))
827 continue;
792 if (!atomic_read(&inode->i_writecount)) 828 if (!atomic_read(&inode->i_writecount))
793 continue; 829 continue;
794 if (!dqinit_needed(inode, type)) 830 if (!dqinit_needed(inode, type))
795 continue; 831 continue;
796 if (inode->i_state & (I_FREEING|I_WILL_FREE))
797 continue;
798 832
799 __iget(inode); 833 __iget(inode);
800 spin_unlock(&inode_lock); 834 spin_unlock(&inode_lock);
@@ -813,7 +847,10 @@ static void add_dquot_ref(struct super_block *sb, int type)
813 iput(old_inode); 847 iput(old_inode);
814} 848}
815 849
816/* Return 0 if dqput() won't block (note that 1 doesn't necessarily mean blocking) */ 850/*
851 * Return 0 if dqput() won't block.
852 * (note that 1 doesn't necessarily mean blocking)
853 */
817static inline int dqput_blocks(struct dquot *dquot) 854static inline int dqput_blocks(struct dquot *dquot)
818{ 855{
819 if (atomic_read(&dquot->dq_count) <= 1) 856 if (atomic_read(&dquot->dq_count) <= 1)
@@ -821,22 +858,27 @@ static inline int dqput_blocks(struct dquot *dquot)
821 return 0; 858 return 0;
822} 859}
823 860
824/* Remove references to dquots from inode - add dquot to list for freeing if needed */ 861/*
825/* We can't race with anybody because we hold dqptr_sem for writing... */ 862 * Remove references to dquots from inode and add dquot to list for freeing
863 * if we have the last referece to dquot
864 * We can't race with anybody because we hold dqptr_sem for writing...
865 */
826static int remove_inode_dquot_ref(struct inode *inode, int type, 866static int remove_inode_dquot_ref(struct inode *inode, int type,
827 struct list_head *tofree_head) 867 struct list_head *tofree_head)
828{ 868{
829 struct dquot *dquot = inode->i_dquot[type]; 869 struct dquot *dquot = inode->i_dquot[type];
830 870
831 inode->i_dquot[type] = NODQUOT; 871 inode->i_dquot[type] = NULL;
832 if (dquot != NODQUOT) { 872 if (dquot) {
833 if (dqput_blocks(dquot)) { 873 if (dqput_blocks(dquot)) {
834#ifdef __DQUOT_PARANOIA 874#ifdef __DQUOT_PARANOIA
835 if (atomic_read(&dquot->dq_count) != 1) 875 if (atomic_read(&dquot->dq_count) != 1)
836 printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count)); 876 printk(KERN_WARNING "VFS: Adding dquot with dq_count %d to dispose list.\n", atomic_read(&dquot->dq_count));
837#endif 877#endif
838 spin_lock(&dq_list_lock); 878 spin_lock(&dq_list_lock);
839 list_add(&dquot->dq_free, tofree_head); /* As dquot must have currently users it can't be on the free list... */ 879 /* As dquot must have currently users it can't be on
880 * the free list... */
881 list_add(&dquot->dq_free, tofree_head);
840 spin_unlock(&dq_list_lock); 882 spin_unlock(&dq_list_lock);
841 return 1; 883 return 1;
842 } 884 }
@@ -846,19 +888,22 @@ static int remove_inode_dquot_ref(struct inode *inode, int type,
846 return 0; 888 return 0;
847} 889}
848 890
849/* Free list of dquots - called from inode.c */ 891/*
850/* dquots are removed from inodes, no new references can be got so we are the only ones holding reference */ 892 * Free list of dquots
893 * Dquots are removed from inodes and no new references can be got so we are
894 * the only ones holding reference
895 */
851static void put_dquot_list(struct list_head *tofree_head) 896static void put_dquot_list(struct list_head *tofree_head)
852{ 897{
853 struct list_head *act_head; 898 struct list_head *act_head;
854 struct dquot *dquot; 899 struct dquot *dquot;
855 900
856 act_head = tofree_head->next; 901 act_head = tofree_head->next;
857 /* So now we have dquots on the list... Just free them */
858 while (act_head != tofree_head) { 902 while (act_head != tofree_head) {
859 dquot = list_entry(act_head, struct dquot, dq_free); 903 dquot = list_entry(act_head, struct dquot, dq_free);
860 act_head = act_head->next; 904 act_head = act_head->next;
861 list_del_init(&dquot->dq_free); /* Remove dquot from the list so we won't have problems... */ 905 /* Remove dquot from the list so we won't have problems... */
906 list_del_init(&dquot->dq_free);
862 dqput(dquot); 907 dqput(dquot);
863 } 908 }
864} 909}
@@ -870,6 +915,12 @@ static void remove_dquot_ref(struct super_block *sb, int type,
870 915
871 spin_lock(&inode_lock); 916 spin_lock(&inode_lock);
872 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { 917 list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
918 /*
919 * We have to scan also I_NEW inodes because they can already
920 * have quota pointer initialized. Luckily, we need to touch
921 * only quota pointers and these have separate locking
922 * (dqptr_sem).
923 */
873 if (!IS_NOQUOTA(inode)) 924 if (!IS_NOQUOTA(inode))
874 remove_inode_dquot_ref(inode, type, tofree_head); 925 remove_inode_dquot_ref(inode, type, tofree_head);
875 } 926 }
@@ -899,7 +950,29 @@ static inline void dquot_incr_space(struct dquot *dquot, qsize_t number)
899 dquot->dq_dqb.dqb_curspace += number; 950 dquot->dq_dqb.dqb_curspace += number;
900} 951}
901 952
902static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number) 953static inline void dquot_resv_space(struct dquot *dquot, qsize_t number)
954{
955 dquot->dq_dqb.dqb_rsvspace += number;
956}
957
958/*
959 * Claim reserved quota space
960 */
961static void dquot_claim_reserved_space(struct dquot *dquot,
962 qsize_t number)
963{
964 WARN_ON(dquot->dq_dqb.dqb_rsvspace < number);
965 dquot->dq_dqb.dqb_curspace += number;
966 dquot->dq_dqb.dqb_rsvspace -= number;
967}
968
969static inline
970void dquot_free_reserved_space(struct dquot *dquot, qsize_t number)
971{
972 dquot->dq_dqb.dqb_rsvspace -= number;
973}
974
975static void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
903{ 976{
904 if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE || 977 if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
905 dquot->dq_dqb.dqb_curinodes >= number) 978 dquot->dq_dqb.dqb_curinodes >= number)
@@ -911,7 +984,7 @@ static inline void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
911 clear_bit(DQ_INODES_B, &dquot->dq_flags); 984 clear_bit(DQ_INODES_B, &dquot->dq_flags);
912} 985}
913 986
914static inline void dquot_decr_space(struct dquot *dquot, qsize_t number) 987static void dquot_decr_space(struct dquot *dquot, qsize_t number)
915{ 988{
916 if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE || 989 if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
917 dquot->dq_dqb.dqb_curspace >= number) 990 dquot->dq_dqb.dqb_curspace >= number)
@@ -938,7 +1011,7 @@ static int warning_issued(struct dquot *dquot, const int warntype)
938#ifdef CONFIG_PRINT_QUOTA_WARNING 1011#ifdef CONFIG_PRINT_QUOTA_WARNING
939static int flag_print_warnings = 1; 1012static int flag_print_warnings = 1;
940 1013
941static inline int need_print_warning(struct dquot *dquot) 1014static int need_print_warning(struct dquot *dquot)
942{ 1015{
943 if (!flag_print_warnings) 1016 if (!flag_print_warnings)
944 return 0; 1017 return 0;
@@ -1057,10 +1130,7 @@ static void send_warning(const struct dquot *dquot, const char warntype)
1057 goto attr_err_out; 1130 goto attr_err_out;
1058 genlmsg_end(skb, msg_head); 1131 genlmsg_end(skb, msg_head);
1059 1132
1060 ret = genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS); 1133 genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
1061 if (ret < 0 && ret != -ESRCH)
1062 printk(KERN_ERR
1063 "VFS: Failed to send notification message: %d\n", ret);
1064 return; 1134 return;
1065attr_err_out: 1135attr_err_out:
1066 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n"); 1136 printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
@@ -1068,13 +1138,17 @@ err_out:
1068 kfree_skb(skb); 1138 kfree_skb(skb);
1069} 1139}
1070#endif 1140#endif
1071 1141/*
1072static inline void flush_warnings(struct dquot * const *dquots, char *warntype) 1142 * Write warnings to the console and send warning messages over netlink.
1143 *
1144 * Note that this function can sleep.
1145 */
1146static void flush_warnings(struct dquot *const *dquots, char *warntype)
1073{ 1147{
1074 int i; 1148 int i;
1075 1149
1076 for (i = 0; i < MAXQUOTAS; i++) 1150 for (i = 0; i < MAXQUOTAS; i++)
1077 if (dquots[i] != NODQUOT && warntype[i] != QUOTA_NL_NOWARN && 1151 if (dquots[i] && warntype[i] != QUOTA_NL_NOWARN &&
1078 !warning_issued(dquots[i], warntype[i])) { 1152 !warning_issued(dquots[i], warntype[i])) {
1079#ifdef CONFIG_PRINT_QUOTA_WARNING 1153#ifdef CONFIG_PRINT_QUOTA_WARNING
1080 print_warning(dquots[i], warntype[i]); 1154 print_warning(dquots[i], warntype[i]);
@@ -1085,42 +1159,47 @@ static inline void flush_warnings(struct dquot * const *dquots, char *warntype)
1085 } 1159 }
1086} 1160}
1087 1161
1088static inline char ignore_hardlimit(struct dquot *dquot) 1162static int ignore_hardlimit(struct dquot *dquot)
1089{ 1163{
1090 struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type]; 1164 struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
1091 1165
1092 return capable(CAP_SYS_RESOURCE) && 1166 return capable(CAP_SYS_RESOURCE) &&
1093 (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD || !(info->dqi_flags & V1_DQF_RSQUASH)); 1167 (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD ||
1168 !(info->dqi_flags & V1_DQF_RSQUASH));
1094} 1169}
1095 1170
1096/* needs dq_data_lock */ 1171/* needs dq_data_lock */
1097static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype) 1172static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1098{ 1173{
1174 qsize_t newinodes = dquot->dq_dqb.dqb_curinodes + inodes;
1175
1099 *warntype = QUOTA_NL_NOWARN; 1176 *warntype = QUOTA_NL_NOWARN;
1100 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) || 1177 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) ||
1101 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1178 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1102 return QUOTA_OK; 1179 return QUOTA_OK;
1103 1180
1104 if (dquot->dq_dqb.dqb_ihardlimit && 1181 if (dquot->dq_dqb.dqb_ihardlimit &&
1105 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_ihardlimit && 1182 newinodes > dquot->dq_dqb.dqb_ihardlimit &&
1106 !ignore_hardlimit(dquot)) { 1183 !ignore_hardlimit(dquot)) {
1107 *warntype = QUOTA_NL_IHARDWARN; 1184 *warntype = QUOTA_NL_IHARDWARN;
1108 return NO_QUOTA; 1185 return NO_QUOTA;
1109 } 1186 }
1110 1187
1111 if (dquot->dq_dqb.dqb_isoftlimit && 1188 if (dquot->dq_dqb.dqb_isoftlimit &&
1112 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit && 1189 newinodes > dquot->dq_dqb.dqb_isoftlimit &&
1113 dquot->dq_dqb.dqb_itime && get_seconds() >= dquot->dq_dqb.dqb_itime && 1190 dquot->dq_dqb.dqb_itime &&
1191 get_seconds() >= dquot->dq_dqb.dqb_itime &&
1114 !ignore_hardlimit(dquot)) { 1192 !ignore_hardlimit(dquot)) {
1115 *warntype = QUOTA_NL_ISOFTLONGWARN; 1193 *warntype = QUOTA_NL_ISOFTLONGWARN;
1116 return NO_QUOTA; 1194 return NO_QUOTA;
1117 } 1195 }
1118 1196
1119 if (dquot->dq_dqb.dqb_isoftlimit && 1197 if (dquot->dq_dqb.dqb_isoftlimit &&
1120 (dquot->dq_dqb.dqb_curinodes + inodes) > dquot->dq_dqb.dqb_isoftlimit && 1198 newinodes > dquot->dq_dqb.dqb_isoftlimit &&
1121 dquot->dq_dqb.dqb_itime == 0) { 1199 dquot->dq_dqb.dqb_itime == 0) {
1122 *warntype = QUOTA_NL_ISOFTWARN; 1200 *warntype = QUOTA_NL_ISOFTWARN;
1123 dquot->dq_dqb.dqb_itime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace; 1201 dquot->dq_dqb.dqb_itime = get_seconds() +
1202 sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
1124 } 1203 }
1125 1204
1126 return QUOTA_OK; 1205 return QUOTA_OK;
@@ -1129,13 +1208,19 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
1129/* needs dq_data_lock */ 1208/* needs dq_data_lock */
1130static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype) 1209static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *warntype)
1131{ 1210{
1211 qsize_t tspace;
1212 struct super_block *sb = dquot->dq_sb;
1213
1132 *warntype = QUOTA_NL_NOWARN; 1214 *warntype = QUOTA_NL_NOWARN;
1133 if (!sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type) || 1215 if (!sb_has_quota_limits_enabled(sb, dquot->dq_type) ||
1134 test_bit(DQ_FAKE_B, &dquot->dq_flags)) 1216 test_bit(DQ_FAKE_B, &dquot->dq_flags))
1135 return QUOTA_OK; 1217 return QUOTA_OK;
1136 1218
1219 tspace = dquot->dq_dqb.dqb_curspace + dquot->dq_dqb.dqb_rsvspace
1220 + space;
1221
1137 if (dquot->dq_dqb.dqb_bhardlimit && 1222 if (dquot->dq_dqb.dqb_bhardlimit &&
1138 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bhardlimit && 1223 tspace > dquot->dq_dqb.dqb_bhardlimit &&
1139 !ignore_hardlimit(dquot)) { 1224 !ignore_hardlimit(dquot)) {
1140 if (!prealloc) 1225 if (!prealloc)
1141 *warntype = QUOTA_NL_BHARDWARN; 1226 *warntype = QUOTA_NL_BHARDWARN;
@@ -1143,8 +1228,9 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1143 } 1228 }
1144 1229
1145 if (dquot->dq_dqb.dqb_bsoftlimit && 1230 if (dquot->dq_dqb.dqb_bsoftlimit &&
1146 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit && 1231 tspace > dquot->dq_dqb.dqb_bsoftlimit &&
1147 dquot->dq_dqb.dqb_btime && get_seconds() >= dquot->dq_dqb.dqb_btime && 1232 dquot->dq_dqb.dqb_btime &&
1233 get_seconds() >= dquot->dq_dqb.dqb_btime &&
1148 !ignore_hardlimit(dquot)) { 1234 !ignore_hardlimit(dquot)) {
1149 if (!prealloc) 1235 if (!prealloc)
1150 *warntype = QUOTA_NL_BSOFTLONGWARN; 1236 *warntype = QUOTA_NL_BSOFTLONGWARN;
@@ -1152,11 +1238,12 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1152 } 1238 }
1153 1239
1154 if (dquot->dq_dqb.dqb_bsoftlimit && 1240 if (dquot->dq_dqb.dqb_bsoftlimit &&
1155 dquot->dq_dqb.dqb_curspace + space > dquot->dq_dqb.dqb_bsoftlimit && 1241 tspace > dquot->dq_dqb.dqb_bsoftlimit &&
1156 dquot->dq_dqb.dqb_btime == 0) { 1242 dquot->dq_dqb.dqb_btime == 0) {
1157 if (!prealloc) { 1243 if (!prealloc) {
1158 *warntype = QUOTA_NL_BSOFTWARN; 1244 *warntype = QUOTA_NL_BSOFTWARN;
1159 dquot->dq_dqb.dqb_btime = get_seconds() + sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_bgrace; 1245 dquot->dq_dqb.dqb_btime = get_seconds() +
1246 sb_dqopt(sb)->info[dquot->dq_type].dqi_bgrace;
1160 } 1247 }
1161 else 1248 else
1162 /* 1249 /*
@@ -1171,15 +1258,18 @@ static int check_bdq(struct dquot *dquot, qsize_t space, int prealloc, char *war
1171 1258
1172static int info_idq_free(struct dquot *dquot, qsize_t inodes) 1259static int info_idq_free(struct dquot *dquot, qsize_t inodes)
1173{ 1260{
1261 qsize_t newinodes;
1262
1174 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) || 1263 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) ||
1175 dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit || 1264 dquot->dq_dqb.dqb_curinodes <= dquot->dq_dqb.dqb_isoftlimit ||
1176 !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type)) 1265 !sb_has_quota_limits_enabled(dquot->dq_sb, dquot->dq_type))
1177 return QUOTA_NL_NOWARN; 1266 return QUOTA_NL_NOWARN;
1178 1267
1179 if (dquot->dq_dqb.dqb_curinodes - inodes <= dquot->dq_dqb.dqb_isoftlimit) 1268 newinodes = dquot->dq_dqb.dqb_curinodes - inodes;
1269 if (newinodes <= dquot->dq_dqb.dqb_isoftlimit)
1180 return QUOTA_NL_ISOFTBELOW; 1270 return QUOTA_NL_ISOFTBELOW;
1181 if (dquot->dq_dqb.dqb_curinodes >= dquot->dq_dqb.dqb_ihardlimit && 1271 if (dquot->dq_dqb.dqb_curinodes >= dquot->dq_dqb.dqb_ihardlimit &&
1182 dquot->dq_dqb.dqb_curinodes - inodes < dquot->dq_dqb.dqb_ihardlimit) 1272 newinodes < dquot->dq_dqb.dqb_ihardlimit)
1183 return QUOTA_NL_IHARDBELOW; 1273 return QUOTA_NL_IHARDBELOW;
1184 return QUOTA_NL_NOWARN; 1274 return QUOTA_NL_NOWARN;
1185} 1275}
@@ -1206,7 +1296,7 @@ int dquot_initialize(struct inode *inode, int type)
1206{ 1296{
1207 unsigned int id = 0; 1297 unsigned int id = 0;
1208 int cnt, ret = 0; 1298 int cnt, ret = 0;
1209 struct dquot *got[MAXQUOTAS] = { NODQUOT, NODQUOT }; 1299 struct dquot *got[MAXQUOTAS] = { NULL, NULL };
1210 struct super_block *sb = inode->i_sb; 1300 struct super_block *sb = inode->i_sb;
1211 1301
1212 /* First test before acquiring mutex - solves deadlocks when we 1302 /* First test before acquiring mutex - solves deadlocks when we
@@ -1239,9 +1329,9 @@ int dquot_initialize(struct inode *inode, int type)
1239 /* Avoid races with quotaoff() */ 1329 /* Avoid races with quotaoff() */
1240 if (!sb_has_quota_active(sb, cnt)) 1330 if (!sb_has_quota_active(sb, cnt))
1241 continue; 1331 continue;
1242 if (inode->i_dquot[cnt] == NODQUOT) { 1332 if (!inode->i_dquot[cnt]) {
1243 inode->i_dquot[cnt] = got[cnt]; 1333 inode->i_dquot[cnt] = got[cnt];
1244 got[cnt] = NODQUOT; 1334 got[cnt] = NULL;
1245 } 1335 }
1246 } 1336 }
1247out_err: 1337out_err:
@@ -1251,6 +1341,7 @@ out_err:
1251 dqput(got[cnt]); 1341 dqput(got[cnt]);
1252 return ret; 1342 return ret;
1253} 1343}
1344EXPORT_SYMBOL(dquot_initialize);
1254 1345
1255/* 1346/*
1256 * Release all quotas referenced by inode 1347 * Release all quotas referenced by inode
@@ -1263,7 +1354,7 @@ int dquot_drop(struct inode *inode)
1263 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1354 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1264 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1355 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1265 put[cnt] = inode->i_dquot[cnt]; 1356 put[cnt] = inode->i_dquot[cnt];
1266 inode->i_dquot[cnt] = NODQUOT; 1357 inode->i_dquot[cnt] = NULL;
1267 } 1358 }
1268 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1359 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1269 1360
@@ -1271,6 +1362,7 @@ int dquot_drop(struct inode *inode)
1271 dqput(put[cnt]); 1362 dqput(put[cnt]);
1272 return 0; 1363 return 0;
1273} 1364}
1365EXPORT_SYMBOL(dquot_drop);
1274 1366
1275/* Wrapper to remove references to quota structures from inode */ 1367/* Wrapper to remove references to quota structures from inode */
1276void vfs_dq_drop(struct inode *inode) 1368void vfs_dq_drop(struct inode *inode)
@@ -1287,12 +1379,13 @@ void vfs_dq_drop(struct inode *inode)
1287 * must assure that nobody can come after the DQUOT_DROP and 1379 * must assure that nobody can come after the DQUOT_DROP and
1288 * add quota pointers back anyway */ 1380 * add quota pointers back anyway */
1289 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1381 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1290 if (inode->i_dquot[cnt] != NODQUOT) 1382 if (inode->i_dquot[cnt])
1291 break; 1383 break;
1292 if (cnt < MAXQUOTAS) 1384 if (cnt < MAXQUOTAS)
1293 inode->i_sb->dq_op->drop(inode); 1385 inode->i_sb->dq_op->drop(inode);
1294 } 1386 }
1295} 1387}
1388EXPORT_SYMBOL(vfs_dq_drop);
1296 1389
1297/* 1390/*
1298 * Following four functions update i_blocks+i_bytes fields and 1391 * Following four functions update i_blocks+i_bytes fields and
@@ -1306,51 +1399,93 @@ void vfs_dq_drop(struct inode *inode)
1306/* 1399/*
1307 * This operation can block, but only after everything is updated 1400 * This operation can block, but only after everything is updated
1308 */ 1401 */
1309int dquot_alloc_space(struct inode *inode, qsize_t number, int warn) 1402int __dquot_alloc_space(struct inode *inode, qsize_t number,
1403 int warn, int reserve)
1310{ 1404{
1311 int cnt, ret = NO_QUOTA; 1405 int cnt, ret = QUOTA_OK;
1312 char warntype[MAXQUOTAS]; 1406 char warntype[MAXQUOTAS];
1313 1407
1314 /* First test before acquiring mutex - solves deadlocks when we
1315 * re-enter the quota code and are already holding the mutex */
1316 if (IS_NOQUOTA(inode)) {
1317out_add:
1318 inode_add_bytes(inode, number);
1319 return QUOTA_OK;
1320 }
1321 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1408 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1322 warntype[cnt] = QUOTA_NL_NOWARN; 1409 warntype[cnt] = QUOTA_NL_NOWARN;
1323 1410
1324 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1325 if (IS_NOQUOTA(inode)) { /* Now we can do reliable test... */
1326 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1327 goto out_add;
1328 }
1329 spin_lock(&dq_data_lock); 1411 spin_lock(&dq_data_lock);
1330 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1412 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1331 if (inode->i_dquot[cnt] == NODQUOT) 1413 if (!inode->i_dquot[cnt])
1332 continue; 1414 continue;
1333 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) == NO_QUOTA) 1415 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt)
1334 goto warn_put_all; 1416 == NO_QUOTA) {
1417 ret = NO_QUOTA;
1418 goto out_unlock;
1419 }
1335 } 1420 }
1336 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1421 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1337 if (inode->i_dquot[cnt] == NODQUOT) 1422 if (!inode->i_dquot[cnt])
1338 continue; 1423 continue;
1339 dquot_incr_space(inode->i_dquot[cnt], number); 1424 if (reserve)
1425 dquot_resv_space(inode->i_dquot[cnt], number);
1426 else
1427 dquot_incr_space(inode->i_dquot[cnt], number);
1340 } 1428 }
1341 inode_add_bytes(inode, number); 1429 if (!reserve)
1342 ret = QUOTA_OK; 1430 inode_add_bytes(inode, number);
1343warn_put_all: 1431out_unlock:
1344 spin_unlock(&dq_data_lock); 1432 spin_unlock(&dq_data_lock);
1345 if (ret == QUOTA_OK)
1346 /* Dirtify all the dquots - this can block when journalling */
1347 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1348 if (inode->i_dquot[cnt])
1349 mark_dquot_dirty(inode->i_dquot[cnt]);
1350 flush_warnings(inode->i_dquot, warntype); 1433 flush_warnings(inode->i_dquot, warntype);
1434 return ret;
1435}
1436
1437int dquot_alloc_space(struct inode *inode, qsize_t number, int warn)
1438{
1439 int cnt, ret = QUOTA_OK;
1440
1441 /*
1442 * First test before acquiring mutex - solves deadlocks when we
1443 * re-enter the quota code and are already holding the mutex
1444 */
1445 if (IS_NOQUOTA(inode)) {
1446 inode_add_bytes(inode, number);
1447 goto out;
1448 }
1449
1450 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1451 if (IS_NOQUOTA(inode)) {
1452 inode_add_bytes(inode, number);
1453 goto out_unlock;
1454 }
1455
1456 ret = __dquot_alloc_space(inode, number, warn, 0);
1457 if (ret == NO_QUOTA)
1458 goto out_unlock;
1459
1460 /* Dirtify all the dquots - this can block when journalling */
1461 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1462 if (inode->i_dquot[cnt])
1463 mark_dquot_dirty(inode->i_dquot[cnt]);
1464out_unlock:
1351 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1465 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1466out:
1352 return ret; 1467 return ret;
1353} 1468}
1469EXPORT_SYMBOL(dquot_alloc_space);
1470
1471int dquot_reserve_space(struct inode *inode, qsize_t number, int warn)
1472{
1473 int ret = QUOTA_OK;
1474
1475 if (IS_NOQUOTA(inode))
1476 goto out;
1477
1478 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1479 if (IS_NOQUOTA(inode))
1480 goto out_unlock;
1481
1482 ret = __dquot_alloc_space(inode, number, warn, 1);
1483out_unlock:
1484 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1485out:
1486 return ret;
1487}
1488EXPORT_SYMBOL(dquot_reserve_space);
1354 1489
1355/* 1490/*
1356 * This operation can block, but only after everything is updated 1491 * This operation can block, but only after everything is updated
@@ -1373,14 +1508,15 @@ int dquot_alloc_inode(const struct inode *inode, qsize_t number)
1373 } 1508 }
1374 spin_lock(&dq_data_lock); 1509 spin_lock(&dq_data_lock);
1375 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1510 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1376 if (inode->i_dquot[cnt] == NODQUOT) 1511 if (!inode->i_dquot[cnt])
1377 continue; 1512 continue;
1378 if (check_idq(inode->i_dquot[cnt], number, warntype+cnt) == NO_QUOTA) 1513 if (check_idq(inode->i_dquot[cnt], number, warntype+cnt)
1514 == NO_QUOTA)
1379 goto warn_put_all; 1515 goto warn_put_all;
1380 } 1516 }
1381 1517
1382 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1518 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1383 if (inode->i_dquot[cnt] == NODQUOT) 1519 if (!inode->i_dquot[cnt])
1384 continue; 1520 continue;
1385 dquot_incr_inodes(inode->i_dquot[cnt], number); 1521 dquot_incr_inodes(inode->i_dquot[cnt], number);
1386 } 1522 }
@@ -1396,6 +1532,73 @@ warn_put_all:
1396 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1532 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1397 return ret; 1533 return ret;
1398} 1534}
1535EXPORT_SYMBOL(dquot_alloc_inode);
1536
1537int dquot_claim_space(struct inode *inode, qsize_t number)
1538{
1539 int cnt;
1540 int ret = QUOTA_OK;
1541
1542 if (IS_NOQUOTA(inode)) {
1543 inode_add_bytes(inode, number);
1544 goto out;
1545 }
1546
1547 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1548 if (IS_NOQUOTA(inode)) {
1549 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1550 inode_add_bytes(inode, number);
1551 goto out;
1552 }
1553
1554 spin_lock(&dq_data_lock);
1555 /* Claim reserved quotas to allocated quotas */
1556 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1557 if (inode->i_dquot[cnt])
1558 dquot_claim_reserved_space(inode->i_dquot[cnt],
1559 number);
1560 }
1561 /* Update inode bytes */
1562 inode_add_bytes(inode, number);
1563 spin_unlock(&dq_data_lock);
1564 /* Dirtify all the dquots - this can block when journalling */
1565 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1566 if (inode->i_dquot[cnt])
1567 mark_dquot_dirty(inode->i_dquot[cnt]);
1568 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1569out:
1570 return ret;
1571}
1572EXPORT_SYMBOL(dquot_claim_space);
1573
1574/*
1575 * Release reserved quota space
1576 */
1577void dquot_release_reserved_space(struct inode *inode, qsize_t number)
1578{
1579 int cnt;
1580
1581 if (IS_NOQUOTA(inode))
1582 goto out;
1583
1584 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1585 if (IS_NOQUOTA(inode))
1586 goto out_unlock;
1587
1588 spin_lock(&dq_data_lock);
1589 /* Release reserved dquots */
1590 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1591 if (inode->i_dquot[cnt])
1592 dquot_free_reserved_space(inode->i_dquot[cnt], number);
1593 }
1594 spin_unlock(&dq_data_lock);
1595
1596out_unlock:
1597 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1598out:
1599 return;
1600}
1601EXPORT_SYMBOL(dquot_release_reserved_space);
1399 1602
1400/* 1603/*
1401 * This operation can block, but only after everything is updated 1604 * This operation can block, but only after everything is updated
@@ -1421,7 +1624,7 @@ out_sub:
1421 } 1624 }
1422 spin_lock(&dq_data_lock); 1625 spin_lock(&dq_data_lock);
1423 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1626 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1424 if (inode->i_dquot[cnt] == NODQUOT) 1627 if (!inode->i_dquot[cnt])
1425 continue; 1628 continue;
1426 warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number); 1629 warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number);
1427 dquot_decr_space(inode->i_dquot[cnt], number); 1630 dquot_decr_space(inode->i_dquot[cnt], number);
@@ -1436,6 +1639,7 @@ out_sub:
1436 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1639 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1437 return QUOTA_OK; 1640 return QUOTA_OK;
1438} 1641}
1642EXPORT_SYMBOL(dquot_free_space);
1439 1643
1440/* 1644/*
1441 * This operation can block, but only after everything is updated 1645 * This operation can block, but only after everything is updated
@@ -1458,7 +1662,7 @@ int dquot_free_inode(const struct inode *inode, qsize_t number)
1458 } 1662 }
1459 spin_lock(&dq_data_lock); 1663 spin_lock(&dq_data_lock);
1460 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1664 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1461 if (inode->i_dquot[cnt] == NODQUOT) 1665 if (!inode->i_dquot[cnt])
1462 continue; 1666 continue;
1463 warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number); 1667 warntype[cnt] = info_idq_free(inode->i_dquot[cnt], number);
1464 dquot_decr_inodes(inode->i_dquot[cnt], number); 1668 dquot_decr_inodes(inode->i_dquot[cnt], number);
@@ -1472,6 +1676,20 @@ int dquot_free_inode(const struct inode *inode, qsize_t number)
1472 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1676 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem);
1473 return QUOTA_OK; 1677 return QUOTA_OK;
1474} 1678}
1679EXPORT_SYMBOL(dquot_free_inode);
1680
1681/*
1682 * call back function, get reserved quota space from underlying fs
1683 */
1684qsize_t dquot_get_reserved_space(struct inode *inode)
1685{
1686 qsize_t reserved_space = 0;
1687
1688 if (sb_any_quota_active(inode->i_sb) &&
1689 inode->i_sb->dq_op->get_reserved_space)
1690 reserved_space = inode->i_sb->dq_op->get_reserved_space(inode);
1691 return reserved_space;
1692}
1475 1693
1476/* 1694/*
1477 * Transfer the number of inode and blocks from one diskquota to an other. 1695 * Transfer the number of inode and blocks from one diskquota to an other.
@@ -1481,7 +1699,8 @@ int dquot_free_inode(const struct inode *inode, qsize_t number)
1481 */ 1699 */
1482int dquot_transfer(struct inode *inode, struct iattr *iattr) 1700int dquot_transfer(struct inode *inode, struct iattr *iattr)
1483{ 1701{
1484 qsize_t space; 1702 qsize_t space, cur_space;
1703 qsize_t rsv_space = 0;
1485 struct dquot *transfer_from[MAXQUOTAS]; 1704 struct dquot *transfer_from[MAXQUOTAS];
1486 struct dquot *transfer_to[MAXQUOTAS]; 1705 struct dquot *transfer_to[MAXQUOTAS];
1487 int cnt, ret = QUOTA_OK; 1706 int cnt, ret = QUOTA_OK;
@@ -1496,22 +1715,16 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
1496 return QUOTA_OK; 1715 return QUOTA_OK;
1497 /* Initialize the arrays */ 1716 /* Initialize the arrays */
1498 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1717 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1499 transfer_from[cnt] = NODQUOT; 1718 transfer_from[cnt] = NULL;
1500 transfer_to[cnt] = NODQUOT; 1719 transfer_to[cnt] = NULL;
1501 warntype_to[cnt] = QUOTA_NL_NOWARN; 1720 warntype_to[cnt] = QUOTA_NL_NOWARN;
1502 switch (cnt) {
1503 case USRQUOTA:
1504 if (!chuid)
1505 continue;
1506 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_uid, cnt);
1507 break;
1508 case GRPQUOTA:
1509 if (!chgid)
1510 continue;
1511 transfer_to[cnt] = dqget(inode->i_sb, iattr->ia_gid, cnt);
1512 break;
1513 }
1514 } 1721 }
1722 if (chuid)
1723 transfer_to[USRQUOTA] = dqget(inode->i_sb, iattr->ia_uid,
1724 USRQUOTA);
1725 if (chgid)
1726 transfer_to[GRPQUOTA] = dqget(inode->i_sb, iattr->ia_gid,
1727 GRPQUOTA);
1515 1728
1516 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1729 down_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1517 /* Now recheck reliably when holding dqptr_sem */ 1730 /* Now recheck reliably when holding dqptr_sem */
@@ -1520,10 +1733,12 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
1520 goto put_all; 1733 goto put_all;
1521 } 1734 }
1522 spin_lock(&dq_data_lock); 1735 spin_lock(&dq_data_lock);
1523 space = inode_get_bytes(inode); 1736 cur_space = inode_get_bytes(inode);
1737 rsv_space = dquot_get_reserved_space(inode);
1738 space = cur_space + rsv_space;
1524 /* Build the transfer_from list and check the limits */ 1739 /* Build the transfer_from list and check the limits */
1525 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1740 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1526 if (transfer_to[cnt] == NODQUOT) 1741 if (!transfer_to[cnt])
1527 continue; 1742 continue;
1528 transfer_from[cnt] = inode->i_dquot[cnt]; 1743 transfer_from[cnt] = inode->i_dquot[cnt];
1529 if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) == 1744 if (check_idq(transfer_to[cnt], 1, warntype_to + cnt) ==
@@ -1539,7 +1754,7 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
1539 /* 1754 /*
1540 * Skip changes for same uid or gid or for turned off quota-type. 1755 * Skip changes for same uid or gid or for turned off quota-type.
1541 */ 1756 */
1542 if (transfer_to[cnt] == NODQUOT) 1757 if (!transfer_to[cnt])
1543 continue; 1758 continue;
1544 1759
1545 /* Due to IO error we might not have transfer_from[] structure */ 1760 /* Due to IO error we might not have transfer_from[] structure */
@@ -1549,11 +1764,14 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
1549 warntype_from_space[cnt] = 1764 warntype_from_space[cnt] =
1550 info_bdq_free(transfer_from[cnt], space); 1765 info_bdq_free(transfer_from[cnt], space);
1551 dquot_decr_inodes(transfer_from[cnt], 1); 1766 dquot_decr_inodes(transfer_from[cnt], 1);
1552 dquot_decr_space(transfer_from[cnt], space); 1767 dquot_decr_space(transfer_from[cnt], cur_space);
1768 dquot_free_reserved_space(transfer_from[cnt],
1769 rsv_space);
1553 } 1770 }
1554 1771
1555 dquot_incr_inodes(transfer_to[cnt], 1); 1772 dquot_incr_inodes(transfer_to[cnt], 1);
1556 dquot_incr_space(transfer_to[cnt], space); 1773 dquot_incr_space(transfer_to[cnt], cur_space);
1774 dquot_resv_space(transfer_to[cnt], rsv_space);
1557 1775
1558 inode->i_dquot[cnt] = transfer_to[cnt]; 1776 inode->i_dquot[cnt] = transfer_to[cnt];
1559 } 1777 }
@@ -1567,7 +1785,7 @@ int dquot_transfer(struct inode *inode, struct iattr *iattr)
1567 if (transfer_to[cnt]) { 1785 if (transfer_to[cnt]) {
1568 mark_dquot_dirty(transfer_to[cnt]); 1786 mark_dquot_dirty(transfer_to[cnt]);
1569 /* The reference we got is transferred to the inode */ 1787 /* The reference we got is transferred to the inode */
1570 transfer_to[cnt] = NODQUOT; 1788 transfer_to[cnt] = NULL;
1571 } 1789 }
1572 } 1790 }
1573warn_put_all: 1791warn_put_all:
@@ -1585,10 +1803,11 @@ over_quota:
1585 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1803 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem);
1586 /* Clear dquot pointers we don't want to dqput() */ 1804 /* Clear dquot pointers we don't want to dqput() */
1587 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1805 for (cnt = 0; cnt < MAXQUOTAS; cnt++)
1588 transfer_from[cnt] = NODQUOT; 1806 transfer_from[cnt] = NULL;
1589 ret = NO_QUOTA; 1807 ret = NO_QUOTA;
1590 goto warn_put_all; 1808 goto warn_put_all;
1591} 1809}
1810EXPORT_SYMBOL(dquot_transfer);
1592 1811
1593/* Wrapper for transferring ownership of an inode */ 1812/* Wrapper for transferring ownership of an inode */
1594int vfs_dq_transfer(struct inode *inode, struct iattr *iattr) 1813int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
@@ -1600,7 +1819,7 @@ int vfs_dq_transfer(struct inode *inode, struct iattr *iattr)
1600 } 1819 }
1601 return 0; 1820 return 0;
1602} 1821}
1603 1822EXPORT_SYMBOL(vfs_dq_transfer);
1604 1823
1605/* 1824/*
1606 * Write info of quota file to disk 1825 * Write info of quota file to disk
@@ -1615,6 +1834,7 @@ int dquot_commit_info(struct super_block *sb, int type)
1615 mutex_unlock(&dqopt->dqio_mutex); 1834 mutex_unlock(&dqopt->dqio_mutex);
1616 return ret; 1835 return ret;
1617} 1836}
1837EXPORT_SYMBOL(dquot_commit_info);
1618 1838
1619/* 1839/*
1620 * Definitions of diskquota operations. 1840 * Definitions of diskquota operations.
@@ -1700,8 +1920,8 @@ int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags)
1700 drop_dquot_ref(sb, cnt); 1920 drop_dquot_ref(sb, cnt);
1701 invalidate_dquots(sb, cnt); 1921 invalidate_dquots(sb, cnt);
1702 /* 1922 /*
1703 * Now all dquots should be invalidated, all writes done so we should be only 1923 * Now all dquots should be invalidated, all writes done so we
1704 * users of the info. No locks needed. 1924 * should be only users of the info. No locks needed.
1705 */ 1925 */
1706 if (info_dirty(&dqopt->info[cnt])) 1926 if (info_dirty(&dqopt->info[cnt]))
1707 sb->dq_op->write_info(sb, cnt); 1927 sb->dq_op->write_info(sb, cnt);
@@ -1739,10 +1959,12 @@ int vfs_quota_disable(struct super_block *sb, int type, unsigned int flags)
1739 /* If quota was reenabled in the meantime, we have 1959 /* If quota was reenabled in the meantime, we have
1740 * nothing to do */ 1960 * nothing to do */
1741 if (!sb_has_quota_loaded(sb, cnt)) { 1961 if (!sb_has_quota_loaded(sb, cnt)) {
1742 mutex_lock_nested(&toputinode[cnt]->i_mutex, I_MUTEX_QUOTA); 1962 mutex_lock_nested(&toputinode[cnt]->i_mutex,
1963 I_MUTEX_QUOTA);
1743 toputinode[cnt]->i_flags &= ~(S_IMMUTABLE | 1964 toputinode[cnt]->i_flags &= ~(S_IMMUTABLE |
1744 S_NOATIME | S_NOQUOTA); 1965 S_NOATIME | S_NOQUOTA);
1745 truncate_inode_pages(&toputinode[cnt]->i_data, 0); 1966 truncate_inode_pages(&toputinode[cnt]->i_data,
1967 0);
1746 mutex_unlock(&toputinode[cnt]->i_mutex); 1968 mutex_unlock(&toputinode[cnt]->i_mutex);
1747 mark_inode_dirty(toputinode[cnt]); 1969 mark_inode_dirty(toputinode[cnt]);
1748 } 1970 }
@@ -1767,13 +1989,14 @@ put_inodes:
1767 } 1989 }
1768 return ret; 1990 return ret;
1769} 1991}
1992EXPORT_SYMBOL(vfs_quota_disable);
1770 1993
1771int vfs_quota_off(struct super_block *sb, int type, int remount) 1994int vfs_quota_off(struct super_block *sb, int type, int remount)
1772{ 1995{
1773 return vfs_quota_disable(sb, type, remount ? DQUOT_SUSPENDED : 1996 return vfs_quota_disable(sb, type, remount ? DQUOT_SUSPENDED :
1774 (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED)); 1997 (DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED));
1775} 1998}
1776 1999EXPORT_SYMBOL(vfs_quota_off);
1777/* 2000/*
1778 * Turn quotas on on a device 2001 * Turn quotas on on a device
1779 */ 2002 */
@@ -1831,7 +2054,8 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
1831 * possible) Also nobody should write to the file - we use 2054 * possible) Also nobody should write to the file - we use
1832 * special IO operations which ignore the immutable bit. */ 2055 * special IO operations which ignore the immutable bit. */
1833 down_write(&dqopt->dqptr_sem); 2056 down_write(&dqopt->dqptr_sem);
1834 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | S_NOQUOTA); 2057 oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE |
2058 S_NOQUOTA);
1835 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE; 2059 inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
1836 up_write(&dqopt->dqptr_sem); 2060 up_write(&dqopt->dqptr_sem);
1837 sb->dq_op->drop(inode); 2061 sb->dq_op->drop(inode);
@@ -1850,7 +2074,8 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
1850 dqopt->info[type].dqi_fmt_id = format_id; 2074 dqopt->info[type].dqi_fmt_id = format_id;
1851 INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list); 2075 INIT_LIST_HEAD(&dqopt->info[type].dqi_dirty_list);
1852 mutex_lock(&dqopt->dqio_mutex); 2076 mutex_lock(&dqopt->dqio_mutex);
1853 if ((error = dqopt->ops[type]->read_file_info(sb, type)) < 0) { 2077 error = dqopt->ops[type]->read_file_info(sb, type);
2078 if (error < 0) {
1854 mutex_unlock(&dqopt->dqio_mutex); 2079 mutex_unlock(&dqopt->dqio_mutex);
1855 goto out_file_init; 2080 goto out_file_init;
1856 } 2081 }
@@ -1930,6 +2155,7 @@ int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
1930 DQUOT_LIMITS_ENABLED); 2155 DQUOT_LIMITS_ENABLED);
1931 return error; 2156 return error;
1932} 2157}
2158EXPORT_SYMBOL(vfs_quota_on_path);
1933 2159
1934int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name, 2160int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name,
1935 int remount) 2161 int remount)
@@ -1947,6 +2173,7 @@ int vfs_quota_on(struct super_block *sb, int type, int format_id, char *name,
1947 } 2173 }
1948 return error; 2174 return error;
1949} 2175}
2176EXPORT_SYMBOL(vfs_quota_on);
1950 2177
1951/* 2178/*
1952 * More powerful function for turning on quotas allowing setting 2179 * More powerful function for turning on quotas allowing setting
@@ -1993,6 +2220,7 @@ out_lock:
1993load_quota: 2220load_quota:
1994 return vfs_load_quota_inode(inode, type, format_id, flags); 2221 return vfs_load_quota_inode(inode, type, format_id, flags);
1995} 2222}
2223EXPORT_SYMBOL(vfs_quota_enable);
1996 2224
1997/* 2225/*
1998 * This function is used when filesystem needs to initialize quotas 2226 * This function is used when filesystem needs to initialize quotas
@@ -2022,6 +2250,7 @@ out:
2022 dput(dentry); 2250 dput(dentry);
2023 return error; 2251 return error;
2024} 2252}
2253EXPORT_SYMBOL(vfs_quota_on_mount);
2025 2254
2026/* Wrapper to turn on quotas when remounting rw */ 2255/* Wrapper to turn on quotas when remounting rw */
2027int vfs_dq_quota_on_remount(struct super_block *sb) 2256int vfs_dq_quota_on_remount(struct super_block *sb)
@@ -2038,6 +2267,7 @@ int vfs_dq_quota_on_remount(struct super_block *sb)
2038 } 2267 }
2039 return ret; 2268 return ret;
2040} 2269}
2270EXPORT_SYMBOL(vfs_dq_quota_on_remount);
2041 2271
2042static inline qsize_t qbtos(qsize_t blocks) 2272static inline qsize_t qbtos(qsize_t blocks)
2043{ 2273{
@@ -2057,7 +2287,7 @@ static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di)
2057 spin_lock(&dq_data_lock); 2287 spin_lock(&dq_data_lock);
2058 di->dqb_bhardlimit = stoqb(dm->dqb_bhardlimit); 2288 di->dqb_bhardlimit = stoqb(dm->dqb_bhardlimit);
2059 di->dqb_bsoftlimit = stoqb(dm->dqb_bsoftlimit); 2289 di->dqb_bsoftlimit = stoqb(dm->dqb_bsoftlimit);
2060 di->dqb_curspace = dm->dqb_curspace; 2290 di->dqb_curspace = dm->dqb_curspace + dm->dqb_rsvspace;
2061 di->dqb_ihardlimit = dm->dqb_ihardlimit; 2291 di->dqb_ihardlimit = dm->dqb_ihardlimit;
2062 di->dqb_isoftlimit = dm->dqb_isoftlimit; 2292 di->dqb_isoftlimit = dm->dqb_isoftlimit;
2063 di->dqb_curinodes = dm->dqb_curinodes; 2293 di->dqb_curinodes = dm->dqb_curinodes;
@@ -2067,18 +2297,20 @@ static void do_get_dqblk(struct dquot *dquot, struct if_dqblk *di)
2067 spin_unlock(&dq_data_lock); 2297 spin_unlock(&dq_data_lock);
2068} 2298}
2069 2299
2070int vfs_get_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di) 2300int vfs_get_dqblk(struct super_block *sb, int type, qid_t id,
2301 struct if_dqblk *di)
2071{ 2302{
2072 struct dquot *dquot; 2303 struct dquot *dquot;
2073 2304
2074 dquot = dqget(sb, id, type); 2305 dquot = dqget(sb, id, type);
2075 if (dquot == NODQUOT) 2306 if (!dquot)
2076 return -ESRCH; 2307 return -ESRCH;
2077 do_get_dqblk(dquot, di); 2308 do_get_dqblk(dquot, di);
2078 dqput(dquot); 2309 dqput(dquot);
2079 2310
2080 return 0; 2311 return 0;
2081} 2312}
2313EXPORT_SYMBOL(vfs_get_dqblk);
2082 2314
2083/* Generic routine for setting common part of quota structure */ 2315/* Generic routine for setting common part of quota structure */
2084static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di) 2316static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
@@ -2097,7 +2329,7 @@ static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
2097 2329
2098 spin_lock(&dq_data_lock); 2330 spin_lock(&dq_data_lock);
2099 if (di->dqb_valid & QIF_SPACE) { 2331 if (di->dqb_valid & QIF_SPACE) {
2100 dm->dqb_curspace = di->dqb_curspace; 2332 dm->dqb_curspace = di->dqb_curspace - dm->dqb_rsvspace;
2101 check_blim = 1; 2333 check_blim = 1;
2102 __set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags); 2334 __set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags);
2103 } 2335 }
@@ -2130,22 +2362,25 @@ static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
2130 } 2362 }
2131 2363
2132 if (check_blim) { 2364 if (check_blim) {
2133 if (!dm->dqb_bsoftlimit || dm->dqb_curspace < dm->dqb_bsoftlimit) { 2365 if (!dm->dqb_bsoftlimit ||
2366 dm->dqb_curspace < dm->dqb_bsoftlimit) {
2134 dm->dqb_btime = 0; 2367 dm->dqb_btime = 0;
2135 clear_bit(DQ_BLKS_B, &dquot->dq_flags); 2368 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
2136 } 2369 } else if (!(di->dqb_valid & QIF_BTIME))
2137 else if (!(di->dqb_valid & QIF_BTIME)) /* Set grace only if user hasn't provided his own... */ 2370 /* Set grace only if user hasn't provided his own... */
2138 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace; 2371 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace;
2139 } 2372 }
2140 if (check_ilim) { 2373 if (check_ilim) {
2141 if (!dm->dqb_isoftlimit || dm->dqb_curinodes < dm->dqb_isoftlimit) { 2374 if (!dm->dqb_isoftlimit ||
2375 dm->dqb_curinodes < dm->dqb_isoftlimit) {
2142 dm->dqb_itime = 0; 2376 dm->dqb_itime = 0;
2143 clear_bit(DQ_INODES_B, &dquot->dq_flags); 2377 clear_bit(DQ_INODES_B, &dquot->dq_flags);
2144 } 2378 } else if (!(di->dqb_valid & QIF_ITIME))
2145 else if (!(di->dqb_valid & QIF_ITIME)) /* Set grace only if user hasn't provided his own... */ 2379 /* Set grace only if user hasn't provided his own... */
2146 dm->dqb_itime = get_seconds() + dqi->dqi_igrace; 2380 dm->dqb_itime = get_seconds() + dqi->dqi_igrace;
2147 } 2381 }
2148 if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit || dm->dqb_isoftlimit) 2382 if (dm->dqb_bhardlimit || dm->dqb_bsoftlimit || dm->dqb_ihardlimit ||
2383 dm->dqb_isoftlimit)
2149 clear_bit(DQ_FAKE_B, &dquot->dq_flags); 2384 clear_bit(DQ_FAKE_B, &dquot->dq_flags);
2150 else 2385 else
2151 set_bit(DQ_FAKE_B, &dquot->dq_flags); 2386 set_bit(DQ_FAKE_B, &dquot->dq_flags);
@@ -2155,7 +2390,8 @@ static int do_set_dqblk(struct dquot *dquot, struct if_dqblk *di)
2155 return 0; 2390 return 0;
2156} 2391}
2157 2392
2158int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *di) 2393int vfs_set_dqblk(struct super_block *sb, int type, qid_t id,
2394 struct if_dqblk *di)
2159{ 2395{
2160 struct dquot *dquot; 2396 struct dquot *dquot;
2161 int rc; 2397 int rc;
@@ -2170,6 +2406,7 @@ int vfs_set_dqblk(struct super_block *sb, int type, qid_t id, struct if_dqblk *d
2170out: 2406out:
2171 return rc; 2407 return rc;
2172} 2408}
2409EXPORT_SYMBOL(vfs_set_dqblk);
2173 2410
2174/* Generic routine for getting common part of quota file information */ 2411/* Generic routine for getting common part of quota file information */
2175int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii) 2412int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
@@ -2191,6 +2428,7 @@ int vfs_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
2191 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); 2428 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
2192 return 0; 2429 return 0;
2193} 2430}
2431EXPORT_SYMBOL(vfs_get_dqinfo);
2194 2432
2195/* Generic routine for setting common part of quota file information */ 2433/* Generic routine for setting common part of quota file information */
2196int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii) 2434int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
@@ -2210,7 +2448,8 @@ int vfs_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii)
2210 if (ii->dqi_valid & IIF_IGRACE) 2448 if (ii->dqi_valid & IIF_IGRACE)
2211 mi->dqi_igrace = ii->dqi_igrace; 2449 mi->dqi_igrace = ii->dqi_igrace;
2212 if (ii->dqi_valid & IIF_FLAGS) 2450 if (ii->dqi_valid & IIF_FLAGS)
2213 mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) | (ii->dqi_flags & DQF_MASK); 2451 mi->dqi_flags = (mi->dqi_flags & ~DQF_MASK) |
2452 (ii->dqi_flags & DQF_MASK);
2214 spin_unlock(&dq_data_lock); 2453 spin_unlock(&dq_data_lock);
2215 mark_info_dirty(sb, type); 2454 mark_info_dirty(sb, type);
2216 /* Force write to disk */ 2455 /* Force write to disk */
@@ -2219,6 +2458,7 @@ out:
2219 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); 2458 mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex);
2220 return err; 2459 return err;
2221} 2460}
2461EXPORT_SYMBOL(vfs_set_dqinfo);
2222 2462
2223struct quotactl_ops vfs_quotactl_ops = { 2463struct quotactl_ops vfs_quotactl_ops = {
2224 .quota_on = vfs_quota_on, 2464 .quota_on = vfs_quota_on,
@@ -2368,43 +2608,10 @@ static int __init dquot_init(void)
2368 2608
2369#ifdef CONFIG_QUOTA_NETLINK_INTERFACE 2609#ifdef CONFIG_QUOTA_NETLINK_INTERFACE
2370 if (genl_register_family(&quota_genl_family) != 0) 2610 if (genl_register_family(&quota_genl_family) != 0)
2371 printk(KERN_ERR "VFS: Failed to create quota netlink interface.\n"); 2611 printk(KERN_ERR
2612 "VFS: Failed to create quota netlink interface.\n");
2372#endif 2613#endif
2373 2614
2374 return 0; 2615 return 0;
2375} 2616}
2376module_init(dquot_init); 2617module_init(dquot_init);
2377
2378EXPORT_SYMBOL(register_quota_format);
2379EXPORT_SYMBOL(unregister_quota_format);
2380EXPORT_SYMBOL(dqstats);
2381EXPORT_SYMBOL(dq_data_lock);
2382EXPORT_SYMBOL(vfs_quota_enable);
2383EXPORT_SYMBOL(vfs_quota_on);
2384EXPORT_SYMBOL(vfs_quota_on_path);
2385EXPORT_SYMBOL(vfs_quota_on_mount);
2386EXPORT_SYMBOL(vfs_quota_disable);
2387EXPORT_SYMBOL(vfs_quota_off);
2388EXPORT_SYMBOL(dquot_scan_active);
2389EXPORT_SYMBOL(vfs_quota_sync);
2390EXPORT_SYMBOL(vfs_get_dqinfo);
2391EXPORT_SYMBOL(vfs_set_dqinfo);
2392EXPORT_SYMBOL(vfs_get_dqblk);
2393EXPORT_SYMBOL(vfs_set_dqblk);
2394EXPORT_SYMBOL(dquot_commit);
2395EXPORT_SYMBOL(dquot_commit_info);
2396EXPORT_SYMBOL(dquot_acquire);
2397EXPORT_SYMBOL(dquot_release);
2398EXPORT_SYMBOL(dquot_mark_dquot_dirty);
2399EXPORT_SYMBOL(dquot_initialize);
2400EXPORT_SYMBOL(dquot_drop);
2401EXPORT_SYMBOL(vfs_dq_drop);
2402EXPORT_SYMBOL(dqget);
2403EXPORT_SYMBOL(dqput);
2404EXPORT_SYMBOL(dquot_alloc_space);
2405EXPORT_SYMBOL(dquot_alloc_inode);
2406EXPORT_SYMBOL(dquot_free_space);
2407EXPORT_SYMBOL(dquot_free_inode);
2408EXPORT_SYMBOL(dquot_transfer);
2409EXPORT_SYMBOL(vfs_dq_transfer);
2410EXPORT_SYMBOL(vfs_dq_quota_on_remount);
diff --git a/fs/quota.c b/fs/quota/quota.c
index d76ada914f9..b7f5a468f07 100644
--- a/fs/quota.c
+++ b/fs/quota/quota.c
@@ -20,7 +20,8 @@
20#include <linux/types.h> 20#include <linux/types.h>
21 21
22/* Check validity of generic quotactl commands */ 22/* Check validity of generic quotactl commands */
23static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id) 23static int generic_quotactl_valid(struct super_block *sb, int type, int cmd,
24 qid_t id)
24{ 25{
25 if (type >= MAXQUOTAS) 26 if (type >= MAXQUOTAS)
26 return -EINVAL; 27 return -EINVAL;
@@ -72,7 +73,8 @@ static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid
72 case Q_SETINFO: 73 case Q_SETINFO:
73 case Q_SETQUOTA: 74 case Q_SETQUOTA:
74 case Q_GETQUOTA: 75 case Q_GETQUOTA:
75 /* This is just informative test so we are satisfied without a lock */ 76 /* This is just an informative test so we are satisfied
77 * without the lock */
76 if (!sb_has_quota_active(sb, type)) 78 if (!sb_has_quota_active(sb, type))
77 return -ESRCH; 79 return -ESRCH;
78 } 80 }
@@ -92,7 +94,8 @@ static int generic_quotactl_valid(struct super_block *sb, int type, int cmd, qid
92} 94}
93 95
94/* Check validity of XFS Quota Manager commands */ 96/* Check validity of XFS Quota Manager commands */
95static int xqm_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id) 97static int xqm_quotactl_valid(struct super_block *sb, int type, int cmd,
98 qid_t id)
96{ 99{
97 if (type >= XQM_MAXQUOTAS) 100 if (type >= XQM_MAXQUOTAS)
98 return -EINVAL; 101 return -EINVAL;
@@ -142,7 +145,8 @@ static int xqm_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t i
142 return 0; 145 return 0;
143} 146}
144 147
145static int check_quotactl_valid(struct super_block *sb, int type, int cmd, qid_t id) 148static int check_quotactl_valid(struct super_block *sb, int type, int cmd,
149 qid_t id)
146{ 150{
147 int error; 151 int error;
148 152
@@ -180,7 +184,8 @@ static void quota_sync_sb(struct super_block *sb, int type)
180 continue; 184 continue;
181 if (!sb_has_quota_active(sb, cnt)) 185 if (!sb_has_quota_active(sb, cnt))
182 continue; 186 continue;
183 mutex_lock_nested(&sb_dqopt(sb)->files[cnt]->i_mutex, I_MUTEX_QUOTA); 187 mutex_lock_nested(&sb_dqopt(sb)->files[cnt]->i_mutex,
188 I_MUTEX_QUOTA);
184 truncate_inode_pages(&sb_dqopt(sb)->files[cnt]->i_data, 0); 189 truncate_inode_pages(&sb_dqopt(sb)->files[cnt]->i_data, 0);
185 mutex_unlock(&sb_dqopt(sb)->files[cnt]->i_mutex); 190 mutex_unlock(&sb_dqopt(sb)->files[cnt]->i_mutex);
186 } 191 }
@@ -200,14 +205,15 @@ void sync_dquots(struct super_block *sb, int type)
200 spin_lock(&sb_lock); 205 spin_lock(&sb_lock);
201restart: 206restart:
202 list_for_each_entry(sb, &super_blocks, s_list) { 207 list_for_each_entry(sb, &super_blocks, s_list) {
203 /* This test just improves performance so it needn't be reliable... */ 208 /* This test just improves performance so it needn't be
209 * reliable... */
204 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 210 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
205 if (type != -1 && type != cnt) 211 if (type != -1 && type != cnt)
206 continue; 212 continue;
207 if (!sb_has_quota_active(sb, cnt)) 213 if (!sb_has_quota_active(sb, cnt))
208 continue; 214 continue;
209 if (!info_dirty(&sb_dqopt(sb)->info[cnt]) && 215 if (!info_dirty(&sb_dqopt(sb)->info[cnt]) &&
210 list_empty(&sb_dqopt(sb)->info[cnt].dqi_dirty_list)) 216 list_empty(&sb_dqopt(sb)->info[cnt].dqi_dirty_list))
211 continue; 217 continue;
212 break; 218 break;
213 } 219 }
@@ -227,7 +233,8 @@ restart:
227} 233}
228 234
229/* Copy parameters and call proper function */ 235/* Copy parameters and call proper function */
230static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, void __user *addr) 236static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id,
237 void __user *addr)
231{ 238{
232 int ret; 239 int ret;
233 240
@@ -235,7 +242,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, void
235 case Q_QUOTAON: { 242 case Q_QUOTAON: {
236 char *pathname; 243 char *pathname;
237 244
238 if (IS_ERR(pathname = getname(addr))) 245 pathname = getname(addr);
246 if (IS_ERR(pathname))
239 return PTR_ERR(pathname); 247 return PTR_ERR(pathname);
240 ret = sb->s_qcop->quota_on(sb, type, id, pathname, 0); 248 ret = sb->s_qcop->quota_on(sb, type, id, pathname, 0);
241 putname(pathname); 249 putname(pathname);
@@ -261,7 +269,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, void
261 case Q_GETINFO: { 269 case Q_GETINFO: {
262 struct if_dqinfo info; 270 struct if_dqinfo info;
263 271
264 if ((ret = sb->s_qcop->get_info(sb, type, &info))) 272 ret = sb->s_qcop->get_info(sb, type, &info);
273 if (ret)
265 return ret; 274 return ret;
266 if (copy_to_user(addr, &info, sizeof(info))) 275 if (copy_to_user(addr, &info, sizeof(info)))
267 return -EFAULT; 276 return -EFAULT;
@@ -277,7 +286,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, void
277 case Q_GETQUOTA: { 286 case Q_GETQUOTA: {
278 struct if_dqblk idq; 287 struct if_dqblk idq;
279 288
280 if ((ret = sb->s_qcop->get_dqblk(sb, type, id, &idq))) 289 ret = sb->s_qcop->get_dqblk(sb, type, id, &idq);
290 if (ret)
281 return ret; 291 return ret;
282 if (copy_to_user(addr, &idq, sizeof(idq))) 292 if (copy_to_user(addr, &idq, sizeof(idq)))
283 return -EFAULT; 293 return -EFAULT;
@@ -322,7 +332,8 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, void
322 case Q_XGETQUOTA: { 332 case Q_XGETQUOTA: {
323 struct fs_disk_quota fdq; 333 struct fs_disk_quota fdq;
324 334
325 if ((ret = sb->s_qcop->get_xquota(sb, type, id, &fdq))) 335 ret = sb->s_qcop->get_xquota(sb, type, id, &fdq);
336 if (ret)
326 return ret; 337 return ret;
327 if (copy_to_user(addr, &fdq, sizeof(fdq))) 338 if (copy_to_user(addr, &fdq, sizeof(fdq)))
328 return -EFAULT; 339 return -EFAULT;
@@ -341,7 +352,7 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, void
341 * look up a superblock on which quota ops will be performed 352 * look up a superblock on which quota ops will be performed
342 * - use the name of a block device to find the superblock thereon 353 * - use the name of a block device to find the superblock thereon
343 */ 354 */
344static inline struct super_block *quotactl_block(const char __user *special) 355static struct super_block *quotactl_block(const char __user *special)
345{ 356{
346#ifdef CONFIG_BLOCK 357#ifdef CONFIG_BLOCK
347 struct block_device *bdev; 358 struct block_device *bdev;
diff --git a/fs/quota_tree.c b/fs/quota/quota_tree.c
index 953404c95b1..f81f4bcfb17 100644
--- a/fs/quota_tree.c
+++ b/fs/quota/quota_tree.c
@@ -22,8 +22,6 @@ MODULE_LICENSE("GPL");
22 22
23#define __QUOTA_QT_PARANOIA 23#define __QUOTA_QT_PARANOIA
24 24
25typedef char *dqbuf_t;
26
27static int get_index(struct qtree_mem_dqinfo *info, qid_t id, int depth) 25static int get_index(struct qtree_mem_dqinfo *info, qid_t id, int depth)
28{ 26{
29 unsigned int epb = info->dqi_usable_bs >> 2; 27 unsigned int epb = info->dqi_usable_bs >> 2;
@@ -35,46 +33,42 @@ static int get_index(struct qtree_mem_dqinfo *info, qid_t id, int depth)
35} 33}
36 34
37/* Number of entries in one blocks */ 35/* Number of entries in one blocks */
38static inline int qtree_dqstr_in_blk(struct qtree_mem_dqinfo *info) 36static int qtree_dqstr_in_blk(struct qtree_mem_dqinfo *info)
39{ 37{
40 return (info->dqi_usable_bs - sizeof(struct qt_disk_dqdbheader)) 38 return (info->dqi_usable_bs - sizeof(struct qt_disk_dqdbheader))
41 / info->dqi_entry_size; 39 / info->dqi_entry_size;
42} 40}
43 41
44static dqbuf_t getdqbuf(size_t size) 42static char *getdqbuf(size_t size)
45{ 43{
46 dqbuf_t buf = kmalloc(size, GFP_NOFS); 44 char *buf = kmalloc(size, GFP_NOFS);
47 if (!buf) 45 if (!buf)
48 printk(KERN_WARNING "VFS: Not enough memory for quota buffers.\n"); 46 printk(KERN_WARNING
47 "VFS: Not enough memory for quota buffers.\n");
49 return buf; 48 return buf;
50} 49}
51 50
52static inline void freedqbuf(dqbuf_t buf) 51static ssize_t read_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf)
53{
54 kfree(buf);
55}
56
57static inline ssize_t read_blk(struct qtree_mem_dqinfo *info, uint blk, dqbuf_t buf)
58{ 52{
59 struct super_block *sb = info->dqi_sb; 53 struct super_block *sb = info->dqi_sb;
60 54
61 memset(buf, 0, info->dqi_usable_bs); 55 memset(buf, 0, info->dqi_usable_bs);
62 return sb->s_op->quota_read(sb, info->dqi_type, (char *)buf, 56 return sb->s_op->quota_read(sb, info->dqi_type, buf,
63 info->dqi_usable_bs, blk << info->dqi_blocksize_bits); 57 info->dqi_usable_bs, blk << info->dqi_blocksize_bits);
64} 58}
65 59
66static inline ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, dqbuf_t buf) 60static ssize_t write_blk(struct qtree_mem_dqinfo *info, uint blk, char *buf)
67{ 61{
68 struct super_block *sb = info->dqi_sb; 62 struct super_block *sb = info->dqi_sb;
69 63
70 return sb->s_op->quota_write(sb, info->dqi_type, (char *)buf, 64 return sb->s_op->quota_write(sb, info->dqi_type, buf,
71 info->dqi_usable_bs, blk << info->dqi_blocksize_bits); 65 info->dqi_usable_bs, blk << info->dqi_blocksize_bits);
72} 66}
73 67
74/* Remove empty block from list and return it */ 68/* Remove empty block from list and return it */
75static int get_free_dqblk(struct qtree_mem_dqinfo *info) 69static int get_free_dqblk(struct qtree_mem_dqinfo *info)
76{ 70{
77 dqbuf_t buf = getdqbuf(info->dqi_usable_bs); 71 char *buf = getdqbuf(info->dqi_usable_bs);
78 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf; 72 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
79 int ret, blk; 73 int ret, blk;
80 74
@@ -98,12 +92,12 @@ static int get_free_dqblk(struct qtree_mem_dqinfo *info)
98 mark_info_dirty(info->dqi_sb, info->dqi_type); 92 mark_info_dirty(info->dqi_sb, info->dqi_type);
99 ret = blk; 93 ret = blk;
100out_buf: 94out_buf:
101 freedqbuf(buf); 95 kfree(buf);
102 return ret; 96 return ret;
103} 97}
104 98
105/* Insert empty block to the list */ 99/* Insert empty block to the list */
106static int put_free_dqblk(struct qtree_mem_dqinfo *info, dqbuf_t buf, uint blk) 100static int put_free_dqblk(struct qtree_mem_dqinfo *info, char *buf, uint blk)
107{ 101{
108 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf; 102 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
109 int err; 103 int err;
@@ -120,9 +114,10 @@ static int put_free_dqblk(struct qtree_mem_dqinfo *info, dqbuf_t buf, uint blk)
120} 114}
121 115
122/* Remove given block from the list of blocks with free entries */ 116/* Remove given block from the list of blocks with free entries */
123static int remove_free_dqentry(struct qtree_mem_dqinfo *info, dqbuf_t buf, uint blk) 117static int remove_free_dqentry(struct qtree_mem_dqinfo *info, char *buf,
118 uint blk)
124{ 119{
125 dqbuf_t tmpbuf = getdqbuf(info->dqi_usable_bs); 120 char *tmpbuf = getdqbuf(info->dqi_usable_bs);
126 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf; 121 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
127 uint nextblk = le32_to_cpu(dh->dqdh_next_free); 122 uint nextblk = le32_to_cpu(dh->dqdh_next_free);
128 uint prevblk = le32_to_cpu(dh->dqdh_prev_free); 123 uint prevblk = le32_to_cpu(dh->dqdh_prev_free);
@@ -153,21 +148,24 @@ static int remove_free_dqentry(struct qtree_mem_dqinfo *info, dqbuf_t buf, uint
153 info->dqi_free_entry = nextblk; 148 info->dqi_free_entry = nextblk;
154 mark_info_dirty(info->dqi_sb, info->dqi_type); 149 mark_info_dirty(info->dqi_sb, info->dqi_type);
155 } 150 }
156 freedqbuf(tmpbuf); 151 kfree(tmpbuf);
157 dh->dqdh_next_free = dh->dqdh_prev_free = cpu_to_le32(0); 152 dh->dqdh_next_free = dh->dqdh_prev_free = cpu_to_le32(0);
158 /* No matter whether write succeeds block is out of list */ 153 /* No matter whether write succeeds block is out of list */
159 if (write_blk(info, blk, buf) < 0) 154 if (write_blk(info, blk, buf) < 0)
160 printk(KERN_ERR "VFS: Can't write block (%u) with free entries.\n", blk); 155 printk(KERN_ERR
156 "VFS: Can't write block (%u) with free entries.\n",
157 blk);
161 return 0; 158 return 0;
162out_buf: 159out_buf:
163 freedqbuf(tmpbuf); 160 kfree(tmpbuf);
164 return err; 161 return err;
165} 162}
166 163
167/* Insert given block to the beginning of list with free entries */ 164/* Insert given block to the beginning of list with free entries */
168static int insert_free_dqentry(struct qtree_mem_dqinfo *info, dqbuf_t buf, uint blk) 165static int insert_free_dqentry(struct qtree_mem_dqinfo *info, char *buf,
166 uint blk)
169{ 167{
170 dqbuf_t tmpbuf = getdqbuf(info->dqi_usable_bs); 168 char *tmpbuf = getdqbuf(info->dqi_usable_bs);
171 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf; 169 struct qt_disk_dqdbheader *dh = (struct qt_disk_dqdbheader *)buf;
172 int err; 170 int err;
173 171
@@ -188,12 +186,12 @@ static int insert_free_dqentry(struct qtree_mem_dqinfo *info, dqbuf_t buf, uint
188 if (err < 0) 186 if (err < 0)
189 goto out_buf; 187 goto out_buf;
190 } 188 }
191 freedqbuf(tmpbuf); 189 kfree(tmpbuf);
192 info->dqi_free_entry = blk; 190 info->dqi_free_entry = blk;
193 mark_info_dirty(info->dqi_sb, info->dqi_type); 191 mark_info_dirty(info->dqi_sb, info->dqi_type);
194 return 0; 192 return 0;
195out_buf: 193out_buf:
196 freedqbuf(tmpbuf); 194 kfree(tmpbuf);
197 return err; 195 return err;
198} 196}
199 197
@@ -215,7 +213,7 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info,
215{ 213{
216 uint blk, i; 214 uint blk, i;
217 struct qt_disk_dqdbheader *dh; 215 struct qt_disk_dqdbheader *dh;
218 dqbuf_t buf = getdqbuf(info->dqi_usable_bs); 216 char *buf = getdqbuf(info->dqi_usable_bs);
219 char *ddquot; 217 char *ddquot;
220 218
221 *err = 0; 219 *err = 0;
@@ -233,11 +231,12 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info,
233 blk = get_free_dqblk(info); 231 blk = get_free_dqblk(info);
234 if ((int)blk < 0) { 232 if ((int)blk < 0) {
235 *err = blk; 233 *err = blk;
236 freedqbuf(buf); 234 kfree(buf);
237 return 0; 235 return 0;
238 } 236 }
239 memset(buf, 0, info->dqi_usable_bs); 237 memset(buf, 0, info->dqi_usable_bs);
240 /* This is enough as block is already zeroed and entry list is empty... */ 238 /* This is enough as the block is already zeroed and the entry
239 * list is empty... */
241 info->dqi_free_entry = blk; 240 info->dqi_free_entry = blk;
242 mark_info_dirty(dquot->dq_sb, dquot->dq_type); 241 mark_info_dirty(dquot->dq_sb, dquot->dq_type);
243 } 242 }
@@ -253,9 +252,12 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info,
253 } 252 }
254 le16_add_cpu(&dh->dqdh_entries, 1); 253 le16_add_cpu(&dh->dqdh_entries, 1);
255 /* Find free structure in block */ 254 /* Find free structure in block */
256 for (i = 0, ddquot = ((char *)buf) + sizeof(struct qt_disk_dqdbheader); 255 ddquot = buf + sizeof(struct qt_disk_dqdbheader);
257 i < qtree_dqstr_in_blk(info) && !qtree_entry_unused(info, ddquot); 256 for (i = 0; i < qtree_dqstr_in_blk(info); i++) {
258 i++, ddquot += info->dqi_entry_size); 257 if (qtree_entry_unused(info, ddquot))
258 break;
259 ddquot += info->dqi_entry_size;
260 }
259#ifdef __QUOTA_QT_PARANOIA 261#ifdef __QUOTA_QT_PARANOIA
260 if (i == qtree_dqstr_in_blk(info)) { 262 if (i == qtree_dqstr_in_blk(info)) {
261 printk(KERN_ERR "VFS: find_free_dqentry(): Data block full " 263 printk(KERN_ERR "VFS: find_free_dqentry(): Data block full "
@@ -273,10 +275,10 @@ static uint find_free_dqentry(struct qtree_mem_dqinfo *info,
273 dquot->dq_off = (blk << info->dqi_blocksize_bits) + 275 dquot->dq_off = (blk << info->dqi_blocksize_bits) +
274 sizeof(struct qt_disk_dqdbheader) + 276 sizeof(struct qt_disk_dqdbheader) +
275 i * info->dqi_entry_size; 277 i * info->dqi_entry_size;
276 freedqbuf(buf); 278 kfree(buf);
277 return blk; 279 return blk;
278out_buf: 280out_buf:
279 freedqbuf(buf); 281 kfree(buf);
280 return 0; 282 return 0;
281} 283}
282 284
@@ -284,7 +286,7 @@ out_buf:
284static int do_insert_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot, 286static int do_insert_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
285 uint *treeblk, int depth) 287 uint *treeblk, int depth)
286{ 288{
287 dqbuf_t buf = getdqbuf(info->dqi_usable_bs); 289 char *buf = getdqbuf(info->dqi_usable_bs);
288 int ret = 0, newson = 0, newact = 0; 290 int ret = 0, newson = 0, newact = 0;
289 __le32 *ref; 291 __le32 *ref;
290 uint newblk; 292 uint newblk;
@@ -333,7 +335,7 @@ static int do_insert_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
333 put_free_dqblk(info, buf, *treeblk); 335 put_free_dqblk(info, buf, *treeblk);
334 } 336 }
335out_buf: 337out_buf:
336 freedqbuf(buf); 338 kfree(buf);
337 return ret; 339 return ret;
338} 340}
339 341
@@ -346,14 +348,15 @@ static inline int dq_insert_tree(struct qtree_mem_dqinfo *info,
346} 348}
347 349
348/* 350/*
349 * We don't have to be afraid of deadlocks as we never have quotas on quota files... 351 * We don't have to be afraid of deadlocks as we never have quotas on quota
352 * files...
350 */ 353 */
351int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) 354int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
352{ 355{
353 int type = dquot->dq_type; 356 int type = dquot->dq_type;
354 struct super_block *sb = dquot->dq_sb; 357 struct super_block *sb = dquot->dq_sb;
355 ssize_t ret; 358 ssize_t ret;
356 dqbuf_t ddquot = getdqbuf(info->dqi_entry_size); 359 char *ddquot = getdqbuf(info->dqi_entry_size);
357 360
358 if (!ddquot) 361 if (!ddquot)
359 return -ENOMEM; 362 return -ENOMEM;
@@ -364,15 +367,15 @@ int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
364 if (ret < 0) { 367 if (ret < 0) {
365 printk(KERN_ERR "VFS: Error %zd occurred while " 368 printk(KERN_ERR "VFS: Error %zd occurred while "
366 "creating quota.\n", ret); 369 "creating quota.\n", ret);
367 freedqbuf(ddquot); 370 kfree(ddquot);
368 return ret; 371 return ret;
369 } 372 }
370 } 373 }
371 spin_lock(&dq_data_lock); 374 spin_lock(&dq_data_lock);
372 info->dqi_ops->mem2disk_dqblk(ddquot, dquot); 375 info->dqi_ops->mem2disk_dqblk(ddquot, dquot);
373 spin_unlock(&dq_data_lock); 376 spin_unlock(&dq_data_lock);
374 ret = sb->s_op->quota_write(sb, type, (char *)ddquot, 377 ret = sb->s_op->quota_write(sb, type, ddquot, info->dqi_entry_size,
375 info->dqi_entry_size, dquot->dq_off); 378 dquot->dq_off);
376 if (ret != info->dqi_entry_size) { 379 if (ret != info->dqi_entry_size) {
377 printk(KERN_WARNING "VFS: dquota write failed on dev %s\n", 380 printk(KERN_WARNING "VFS: dquota write failed on dev %s\n",
378 sb->s_id); 381 sb->s_id);
@@ -382,7 +385,7 @@ int qtree_write_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
382 ret = 0; 385 ret = 0;
383 } 386 }
384 dqstats.writes++; 387 dqstats.writes++;
385 freedqbuf(ddquot); 388 kfree(ddquot);
386 389
387 return ret; 390 return ret;
388} 391}
@@ -393,7 +396,7 @@ static int free_dqentry(struct qtree_mem_dqinfo *info, struct dquot *dquot,
393 uint blk) 396 uint blk)
394{ 397{
395 struct qt_disk_dqdbheader *dh; 398 struct qt_disk_dqdbheader *dh;
396 dqbuf_t buf = getdqbuf(info->dqi_usable_bs); 399 char *buf = getdqbuf(info->dqi_usable_bs);
397 int ret = 0; 400 int ret = 0;
398 401
399 if (!buf) 402 if (!buf)
@@ -444,7 +447,7 @@ static int free_dqentry(struct qtree_mem_dqinfo *info, struct dquot *dquot,
444 } 447 }
445 dquot->dq_off = 0; /* Quota is now unattached */ 448 dquot->dq_off = 0; /* Quota is now unattached */
446out_buf: 449out_buf:
447 freedqbuf(buf); 450 kfree(buf);
448 return ret; 451 return ret;
449} 452}
450 453
@@ -452,7 +455,7 @@ out_buf:
452static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot, 455static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
453 uint *blk, int depth) 456 uint *blk, int depth)
454{ 457{
455 dqbuf_t buf = getdqbuf(info->dqi_usable_bs); 458 char *buf = getdqbuf(info->dqi_usable_bs);
456 int ret = 0; 459 int ret = 0;
457 uint newblk; 460 uint newblk;
458 __le32 *ref = (__le32 *)buf; 461 __le32 *ref = (__le32 *)buf;
@@ -475,9 +478,8 @@ static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
475 int i; 478 int i;
476 ref[get_index(info, dquot->dq_id, depth)] = cpu_to_le32(0); 479 ref[get_index(info, dquot->dq_id, depth)] = cpu_to_le32(0);
477 /* Block got empty? */ 480 /* Block got empty? */
478 for (i = 0; 481 for (i = 0; i < (info->dqi_usable_bs >> 2) && !ref[i]; i++)
479 i < (info->dqi_usable_bs >> 2) && !ref[i]; 482 ;
480 i++);
481 /* Don't put the root block into the free block list */ 483 /* Don't put the root block into the free block list */
482 if (i == (info->dqi_usable_bs >> 2) 484 if (i == (info->dqi_usable_bs >> 2)
483 && *blk != QT_TREEOFF) { 485 && *blk != QT_TREEOFF) {
@@ -491,7 +493,7 @@ static int remove_tree(struct qtree_mem_dqinfo *info, struct dquot *dquot,
491 } 493 }
492 } 494 }
493out_buf: 495out_buf:
494 freedqbuf(buf); 496 kfree(buf);
495 return ret; 497 return ret;
496} 498}
497 499
@@ -510,7 +512,7 @@ EXPORT_SYMBOL(qtree_delete_dquot);
510static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info, 512static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info,
511 struct dquot *dquot, uint blk) 513 struct dquot *dquot, uint blk)
512{ 514{
513 dqbuf_t buf = getdqbuf(info->dqi_usable_bs); 515 char *buf = getdqbuf(info->dqi_usable_bs);
514 loff_t ret = 0; 516 loff_t ret = 0;
515 int i; 517 int i;
516 char *ddquot; 518 char *ddquot;
@@ -522,9 +524,12 @@ static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info,
522 printk(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk); 524 printk(KERN_ERR "VFS: Can't read quota tree block %u.\n", blk);
523 goto out_buf; 525 goto out_buf;
524 } 526 }
525 for (i = 0, ddquot = ((char *)buf) + sizeof(struct qt_disk_dqdbheader); 527 ddquot = buf + sizeof(struct qt_disk_dqdbheader);
526 i < qtree_dqstr_in_blk(info) && !info->dqi_ops->is_id(ddquot, dquot); 528 for (i = 0; i < qtree_dqstr_in_blk(info); i++) {
527 i++, ddquot += info->dqi_entry_size); 529 if (info->dqi_ops->is_id(ddquot, dquot))
530 break;
531 ddquot += info->dqi_entry_size;
532 }
528 if (i == qtree_dqstr_in_blk(info)) { 533 if (i == qtree_dqstr_in_blk(info)) {
529 printk(KERN_ERR "VFS: Quota for id %u referenced " 534 printk(KERN_ERR "VFS: Quota for id %u referenced "
530 "but not present.\n", dquot->dq_id); 535 "but not present.\n", dquot->dq_id);
@@ -535,7 +540,7 @@ static loff_t find_block_dqentry(struct qtree_mem_dqinfo *info,
535 qt_disk_dqdbheader) + i * info->dqi_entry_size; 540 qt_disk_dqdbheader) + i * info->dqi_entry_size;
536 } 541 }
537out_buf: 542out_buf:
538 freedqbuf(buf); 543 kfree(buf);
539 return ret; 544 return ret;
540} 545}
541 546
@@ -543,7 +548,7 @@ out_buf:
543static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info, 548static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info,
544 struct dquot *dquot, uint blk, int depth) 549 struct dquot *dquot, uint blk, int depth)
545{ 550{
546 dqbuf_t buf = getdqbuf(info->dqi_usable_bs); 551 char *buf = getdqbuf(info->dqi_usable_bs);
547 loff_t ret = 0; 552 loff_t ret = 0;
548 __le32 *ref = (__le32 *)buf; 553 __le32 *ref = (__le32 *)buf;
549 554
@@ -563,7 +568,7 @@ static loff_t find_tree_dqentry(struct qtree_mem_dqinfo *info,
563 else 568 else
564 ret = find_block_dqentry(info, dquot, blk); 569 ret = find_block_dqentry(info, dquot, blk);
565out_buf: 570out_buf:
566 freedqbuf(buf); 571 kfree(buf);
567 return ret; 572 return ret;
568} 573}
569 574
@@ -579,7 +584,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
579 int type = dquot->dq_type; 584 int type = dquot->dq_type;
580 struct super_block *sb = dquot->dq_sb; 585 struct super_block *sb = dquot->dq_sb;
581 loff_t offset; 586 loff_t offset;
582 dqbuf_t ddquot; 587 char *ddquot;
583 int ret = 0; 588 int ret = 0;
584 589
585#ifdef __QUOTA_QT_PARANOIA 590#ifdef __QUOTA_QT_PARANOIA
@@ -607,8 +612,8 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
607 ddquot = getdqbuf(info->dqi_entry_size); 612 ddquot = getdqbuf(info->dqi_entry_size);
608 if (!ddquot) 613 if (!ddquot)
609 return -ENOMEM; 614 return -ENOMEM;
610 ret = sb->s_op->quota_read(sb, type, (char *)ddquot, 615 ret = sb->s_op->quota_read(sb, type, ddquot, info->dqi_entry_size,
611 info->dqi_entry_size, dquot->dq_off); 616 dquot->dq_off);
612 if (ret != info->dqi_entry_size) { 617 if (ret != info->dqi_entry_size) {
613 if (ret >= 0) 618 if (ret >= 0)
614 ret = -EIO; 619 ret = -EIO;
@@ -616,7 +621,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
616 "structure for id %u.\n", dquot->dq_id); 621 "structure for id %u.\n", dquot->dq_id);
617 set_bit(DQ_FAKE_B, &dquot->dq_flags); 622 set_bit(DQ_FAKE_B, &dquot->dq_flags);
618 memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk)); 623 memset(&dquot->dq_dqb, 0, sizeof(struct mem_dqblk));
619 freedqbuf(ddquot); 624 kfree(ddquot);
620 goto out; 625 goto out;
621 } 626 }
622 spin_lock(&dq_data_lock); 627 spin_lock(&dq_data_lock);
@@ -627,7 +632,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
627 !dquot->dq_dqb.dqb_isoftlimit) 632 !dquot->dq_dqb.dqb_isoftlimit)
628 set_bit(DQ_FAKE_B, &dquot->dq_flags); 633 set_bit(DQ_FAKE_B, &dquot->dq_flags);
629 spin_unlock(&dq_data_lock); 634 spin_unlock(&dq_data_lock);
630 freedqbuf(ddquot); 635 kfree(ddquot);
631out: 636out:
632 dqstats.reads++; 637 dqstats.reads++;
633 return ret; 638 return ret;
@@ -638,7 +643,8 @@ EXPORT_SYMBOL(qtree_read_dquot);
638 * the only one operating on dquot (thanks to dq_lock) */ 643 * the only one operating on dquot (thanks to dq_lock) */
639int qtree_release_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot) 644int qtree_release_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
640{ 645{
641 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) && !(dquot->dq_dqb.dqb_curinodes | dquot->dq_dqb.dqb_curspace)) 646 if (test_bit(DQ_FAKE_B, &dquot->dq_flags) &&
647 !(dquot->dq_dqb.dqb_curinodes | dquot->dq_dqb.dqb_curspace))
642 return qtree_delete_dquot(info, dquot); 648 return qtree_delete_dquot(info, dquot);
643 return 0; 649 return 0;
644} 650}
diff --git a/fs/quota_tree.h b/fs/quota/quota_tree.h
index a1ab8db81a5..a1ab8db81a5 100644
--- a/fs/quota_tree.h
+++ b/fs/quota/quota_tree.h
diff --git a/fs/quota_v1.c b/fs/quota/quota_v1.c
index b4af1c69ad1..0edcf42b177 100644
--- a/fs/quota_v1.c
+++ b/fs/quota/quota_v1.c
@@ -62,11 +62,14 @@ static int v1_read_dqblk(struct dquot *dquot)
62 62
63 /* Set structure to 0s in case read fails/is after end of file */ 63 /* Set structure to 0s in case read fails/is after end of file */
64 memset(&dqblk, 0, sizeof(struct v1_disk_dqblk)); 64 memset(&dqblk, 0, sizeof(struct v1_disk_dqblk));
65 dquot->dq_sb->s_op->quota_read(dquot->dq_sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(dquot->dq_id)); 65 dquot->dq_sb->s_op->quota_read(dquot->dq_sb, type, (char *)&dqblk,
66 sizeof(struct v1_disk_dqblk), v1_dqoff(dquot->dq_id));
66 67
67 v1_disk2mem_dqblk(&dquot->dq_dqb, &dqblk); 68 v1_disk2mem_dqblk(&dquot->dq_dqb, &dqblk);
68 if (dquot->dq_dqb.dqb_bhardlimit == 0 && dquot->dq_dqb.dqb_bsoftlimit == 0 && 69 if (dquot->dq_dqb.dqb_bhardlimit == 0 &&
69 dquot->dq_dqb.dqb_ihardlimit == 0 && dquot->dq_dqb.dqb_isoftlimit == 0) 70 dquot->dq_dqb.dqb_bsoftlimit == 0 &&
71 dquot->dq_dqb.dqb_ihardlimit == 0 &&
72 dquot->dq_dqb.dqb_isoftlimit == 0)
70 set_bit(DQ_FAKE_B, &dquot->dq_flags); 73 set_bit(DQ_FAKE_B, &dquot->dq_flags);
71 dqstats.reads++; 74 dqstats.reads++;
72 75
@@ -81,13 +84,16 @@ static int v1_commit_dqblk(struct dquot *dquot)
81 84
82 v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb); 85 v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb);
83 if (dquot->dq_id == 0) { 86 if (dquot->dq_id == 0) {
84 dqblk.dqb_btime = sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace; 87 dqblk.dqb_btime =
85 dqblk.dqb_itime = sb_dqopt(dquot->dq_sb)->info[type].dqi_igrace; 88 sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace;
89 dqblk.dqb_itime =
90 sb_dqopt(dquot->dq_sb)->info[type].dqi_igrace;
86 } 91 }
87 ret = 0; 92 ret = 0;
88 if (sb_dqopt(dquot->dq_sb)->files[type]) 93 if (sb_dqopt(dquot->dq_sb)->files[type])
89 ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type, (char *)&dqblk, 94 ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type,
90 sizeof(struct v1_disk_dqblk), v1_dqoff(dquot->dq_id)); 95 (char *)&dqblk, sizeof(struct v1_disk_dqblk),
96 v1_dqoff(dquot->dq_id));
91 if (ret != sizeof(struct v1_disk_dqblk)) { 97 if (ret != sizeof(struct v1_disk_dqblk)) {
92 printk(KERN_WARNING "VFS: dquota write failed on dev %s\n", 98 printk(KERN_WARNING "VFS: dquota write failed on dev %s\n",
93 dquot->dq_sb->s_id); 99 dquot->dq_sb->s_id);
@@ -130,15 +136,20 @@ static int v1_check_quota_file(struct super_block *sb, int type)
130 return 0; 136 return 0;
131 blocks = isize >> BLOCK_SIZE_BITS; 137 blocks = isize >> BLOCK_SIZE_BITS;
132 off = isize & (BLOCK_SIZE - 1); 138 off = isize & (BLOCK_SIZE - 1);
133 if ((blocks % sizeof(struct v1_disk_dqblk) * BLOCK_SIZE + off) % sizeof(struct v1_disk_dqblk)) 139 if ((blocks % sizeof(struct v1_disk_dqblk) * BLOCK_SIZE + off) %
140 sizeof(struct v1_disk_dqblk))
134 return 0; 141 return 0;
135 /* Doublecheck whether we didn't get file with new format - with old quotactl() this could happen */ 142 /* Doublecheck whether we didn't get file with new format - with old
136 size = sb->s_op->quota_read(sb, type, (char *)&dqhead, sizeof(struct v2_disk_dqheader), 0); 143 * quotactl() this could happen */
144 size = sb->s_op->quota_read(sb, type, (char *)&dqhead,
145 sizeof(struct v2_disk_dqheader), 0);
137 if (size != sizeof(struct v2_disk_dqheader)) 146 if (size != sizeof(struct v2_disk_dqheader))
138 return 1; /* Probably not new format */ 147 return 1; /* Probably not new format */
139 if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type]) 148 if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type])
140 return 1; /* Definitely not new format */ 149 return 1; /* Definitely not new format */
141 printk(KERN_INFO "VFS: %s: Refusing to turn on old quota format on given file. It probably contains newer quota format.\n", sb->s_id); 150 printk(KERN_INFO
151 "VFS: %s: Refusing to turn on old quota format on given file."
152 " It probably contains newer quota format.\n", sb->s_id);
142 return 0; /* Seems like a new format file -> refuse it */ 153 return 0; /* Seems like a new format file -> refuse it */
143} 154}
144 155
@@ -148,7 +159,9 @@ static int v1_read_file_info(struct super_block *sb, int type)
148 struct v1_disk_dqblk dqblk; 159 struct v1_disk_dqblk dqblk;
149 int ret; 160 int ret;
150 161
151 if ((ret = sb->s_op->quota_read(sb, type, (char *)&dqblk, sizeof(struct v1_disk_dqblk), v1_dqoff(0))) != sizeof(struct v1_disk_dqblk)) { 162 ret = sb->s_op->quota_read(sb, type, (char *)&dqblk,
163 sizeof(struct v1_disk_dqblk), v1_dqoff(0));
164 if (ret != sizeof(struct v1_disk_dqblk)) {
152 if (ret >= 0) 165 if (ret >= 0)
153 ret = -EIO; 166 ret = -EIO;
154 goto out; 167 goto out;
@@ -157,8 +170,10 @@ static int v1_read_file_info(struct super_block *sb, int type)
157 /* limits are stored as unsigned 32-bit data */ 170 /* limits are stored as unsigned 32-bit data */
158 dqopt->info[type].dqi_maxblimit = 0xffffffff; 171 dqopt->info[type].dqi_maxblimit = 0xffffffff;
159 dqopt->info[type].dqi_maxilimit = 0xffffffff; 172 dqopt->info[type].dqi_maxilimit = 0xffffffff;
160 dqopt->info[type].dqi_igrace = dqblk.dqb_itime ? dqblk.dqb_itime : MAX_IQ_TIME; 173 dqopt->info[type].dqi_igrace =
161 dqopt->info[type].dqi_bgrace = dqblk.dqb_btime ? dqblk.dqb_btime : MAX_DQ_TIME; 174 dqblk.dqb_itime ? dqblk.dqb_itime : MAX_IQ_TIME;
175 dqopt->info[type].dqi_bgrace =
176 dqblk.dqb_btime ? dqblk.dqb_btime : MAX_DQ_TIME;
162out: 177out:
163 return ret; 178 return ret;
164} 179}
@@ -170,8 +185,9 @@ static int v1_write_file_info(struct super_block *sb, int type)
170 int ret; 185 int ret;
171 186
172 dqopt->info[type].dqi_flags &= ~DQF_INFO_DIRTY; 187 dqopt->info[type].dqi_flags &= ~DQF_INFO_DIRTY;
173 if ((ret = sb->s_op->quota_read(sb, type, (char *)&dqblk, 188 ret = sb->s_op->quota_read(sb, type, (char *)&dqblk,
174 sizeof(struct v1_disk_dqblk), v1_dqoff(0))) != sizeof(struct v1_disk_dqblk)) { 189 sizeof(struct v1_disk_dqblk), v1_dqoff(0));
190 if (ret != sizeof(struct v1_disk_dqblk)) {
175 if (ret >= 0) 191 if (ret >= 0)
176 ret = -EIO; 192 ret = -EIO;
177 goto out; 193 goto out;
diff --git a/fs/quota_v2.c b/fs/quota/quota_v2.c
index b618b563635..a5475fb1ae4 100644
--- a/fs/quota_v2.c
+++ b/fs/quota/quota_v2.c
@@ -54,7 +54,8 @@ static int v2_check_quota_file(struct super_block *sb, int type)
54 static const uint quota_magics[] = V2_INITQMAGICS; 54 static const uint quota_magics[] = V2_INITQMAGICS;
55 static const uint quota_versions[] = V2_INITQVERSIONS; 55 static const uint quota_versions[] = V2_INITQVERSIONS;
56 56
57 size = sb->s_op->quota_read(sb, type, (char *)&dqhead, sizeof(struct v2_disk_dqheader), 0); 57 size = sb->s_op->quota_read(sb, type, (char *)&dqhead,
58 sizeof(struct v2_disk_dqheader), 0);
58 if (size != sizeof(struct v2_disk_dqheader)) { 59 if (size != sizeof(struct v2_disk_dqheader)) {
59 printk("quota_v2: failed read expected=%zd got=%zd\n", 60 printk("quota_v2: failed read expected=%zd got=%zd\n",
60 sizeof(struct v2_disk_dqheader), size); 61 sizeof(struct v2_disk_dqheader), size);
diff --git a/fs/quotaio_v1.h b/fs/quota/quotaio_v1.h
index 746654b5de7..746654b5de7 100644
--- a/fs/quotaio_v1.h
+++ b/fs/quota/quotaio_v1.h
diff --git a/fs/quotaio_v2.h b/fs/quota/quotaio_v2.h
index 530fe580685..530fe580685 100644
--- a/fs/quotaio_v2.h
+++ b/fs/quota/quotaio_v2.h
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index 5d7c7ececa6..995ef1d6686 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -18,7 +18,6 @@
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/backing-dev.h> 19#include <linux/backing-dev.h>
20#include <linux/ramfs.h> 20#include <linux/ramfs.h>
21#include <linux/quotaops.h>
22#include <linux/pagevec.h> 21#include <linux/pagevec.h>
23#include <linux/mman.h> 22#include <linux/mman.h>
24 23
@@ -205,11 +204,6 @@ static int ramfs_nommu_setattr(struct dentry *dentry, struct iattr *ia)
205 if (ret) 204 if (ret)
206 return ret; 205 return ret;
207 206
208 /* by providing our own setattr() method, we skip this quotaism */
209 if ((old_ia_valid & ATTR_UID && ia->ia_uid != inode->i_uid) ||
210 (old_ia_valid & ATTR_GID && ia->ia_gid != inode->i_gid))
211 ret = DQUOT_TRANSFER(inode, ia) ? -EDQUOT : 0;
212
213 /* pick out size-changing events */ 207 /* pick out size-changing events */
214 if (ia->ia_valid & ATTR_SIZE) { 208 if (ia->ia_valid & ATTR_SIZE) {
215 loff_t size = i_size_read(inode); 209 loff_t size = i_size_read(inode);
diff --git a/fs/reiserfs/Makefile b/fs/reiserfs/Makefile
index 0eb7ac08048..7c5ab6330dd 100644
--- a/fs/reiserfs/Makefile
+++ b/fs/reiserfs/Makefile
@@ -7,10 +7,10 @@ obj-$(CONFIG_REISERFS_FS) += reiserfs.o
7reiserfs-objs := bitmap.o do_balan.o namei.o inode.o file.o dir.o fix_node.o \ 7reiserfs-objs := bitmap.o do_balan.o namei.o inode.o file.o dir.o fix_node.o \
8 super.o prints.o objectid.o lbalance.o ibalance.o stree.o \ 8 super.o prints.o objectid.o lbalance.o ibalance.o stree.o \
9 hashes.o tail_conversion.o journal.o resize.o \ 9 hashes.o tail_conversion.o journal.o resize.o \
10 item_ops.o ioctl.o procfs.o 10 item_ops.o ioctl.o procfs.o xattr.o
11 11
12ifeq ($(CONFIG_REISERFS_FS_XATTR),y) 12ifeq ($(CONFIG_REISERFS_FS_XATTR),y)
13reiserfs-objs += xattr.o xattr_user.o xattr_trusted.o 13reiserfs-objs += xattr_user.o xattr_trusted.o
14endif 14endif
15 15
16ifeq ($(CONFIG_REISERFS_FS_SECURITY),y) 16ifeq ($(CONFIG_REISERFS_FS_SECURITY),y)
diff --git a/fs/reiserfs/README b/fs/reiserfs/README
index 90e1670e4e6..14e8c9d460e 100644
--- a/fs/reiserfs/README
+++ b/fs/reiserfs/README
@@ -1,4 +1,4 @@
1[LICENSING] 1[LICENSING]
2 2
3ReiserFS is hereby licensed under the GNU General 3ReiserFS is hereby licensed under the GNU General
4Public License version 2. 4Public License version 2.
@@ -31,7 +31,7 @@ the GPL as not allowing those additional licensing options, you read
31it wrongly, and Richard Stallman agrees with me, when carefully read 31it wrongly, and Richard Stallman agrees with me, when carefully read
32you can see that those restrictions on additional terms do not apply 32you can see that those restrictions on additional terms do not apply
33to the owner of the copyright, and my interpretation of this shall 33to the owner of the copyright, and my interpretation of this shall
34govern for this license. 34govern for this license.
35 35
36Finally, nothing in this license shall be interpreted to allow you to 36Finally, nothing in this license shall be interpreted to allow you to
37fail to fairly credit me, or to remove my credits, without my 37fail to fairly credit me, or to remove my credits, without my
diff --git a/fs/reiserfs/bitmap.c b/fs/reiserfs/bitmap.c
index 4646caa6045..e716161ab32 100644
--- a/fs/reiserfs/bitmap.c
+++ b/fs/reiserfs/bitmap.c
@@ -40,8 +40,8 @@
40 40
41#define SET_OPTION(optname) \ 41#define SET_OPTION(optname) \
42 do { \ 42 do { \
43 reiserfs_warning(s, "reiserfs: option \"%s\" is set", #optname); \ 43 reiserfs_info(s, "block allocator option \"%s\" is set", #optname); \
44 set_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)); \ 44 set_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)); \
45 } while(0) 45 } while(0)
46#define TEST_OPTION(optname, s) \ 46#define TEST_OPTION(optname, s) \
47 test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s)) 47 test_bit(_ALLOC_ ## optname , &SB_ALLOC_OPTS(s))
@@ -64,9 +64,9 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
64 unsigned int bmap_count = reiserfs_bmap_count(s); 64 unsigned int bmap_count = reiserfs_bmap_count(s);
65 65
66 if (block == 0 || block >= SB_BLOCK_COUNT(s)) { 66 if (block == 0 || block >= SB_BLOCK_COUNT(s)) {
67 reiserfs_warning(s, 67 reiserfs_error(s, "vs-4010",
68 "vs-4010: is_reusable: block number is out of range %lu (%u)", 68 "block number is out of range %lu (%u)",
69 block, SB_BLOCK_COUNT(s)); 69 block, SB_BLOCK_COUNT(s));
70 return 0; 70 return 0;
71 } 71 }
72 72
@@ -79,31 +79,30 @@ int is_reusable(struct super_block *s, b_blocknr_t block, int bit_value)
79 b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1; 79 b_blocknr_t bmap1 = REISERFS_SB(s)->s_sbh->b_blocknr + 1;
80 if (block >= bmap1 && 80 if (block >= bmap1 &&
81 block <= bmap1 + bmap_count) { 81 block <= bmap1 + bmap_count) {
82 reiserfs_warning(s, "vs: 4019: is_reusable: " 82 reiserfs_error(s, "vs-4019", "bitmap block %lu(%u) "
83 "bitmap block %lu(%u) can't be freed or reused", 83 "can't be freed or reused",
84 block, bmap_count); 84 block, bmap_count);
85 return 0; 85 return 0;
86 } 86 }
87 } else { 87 } else {
88 if (offset == 0) { 88 if (offset == 0) {
89 reiserfs_warning(s, "vs: 4020: is_reusable: " 89 reiserfs_error(s, "vs-4020", "bitmap block %lu(%u) "
90 "bitmap block %lu(%u) can't be freed or reused", 90 "can't be freed or reused",
91 block, bmap_count); 91 block, bmap_count);
92 return 0; 92 return 0;
93 } 93 }
94 } 94 }
95 95
96 if (bmap >= bmap_count) { 96 if (bmap >= bmap_count) {
97 reiserfs_warning(s, 97 reiserfs_error(s, "vs-4030", "bitmap for requested block "
98 "vs-4030: is_reusable: there is no so many bitmap blocks: " 98 "is out of range: block=%lu, bitmap_nr=%u",
99 "block=%lu, bitmap_nr=%u", block, bmap); 99 block, bmap);
100 return 0; 100 return 0;
101 } 101 }
102 102
103 if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) { 103 if (bit_value == 0 && block == SB_ROOT_BLOCK(s)) {
104 reiserfs_warning(s, 104 reiserfs_error(s, "vs-4050", "this is root block (%u), "
105 "vs-4050: is_reusable: this is root block (%u), " 105 "it must be busy", SB_ROOT_BLOCK(s));
106 "it must be busy", SB_ROOT_BLOCK(s));
107 return 0; 106 return 0;
108 } 107 }
109 108
@@ -154,8 +153,8 @@ static int scan_bitmap_block(struct reiserfs_transaction_handle *th,
154/* - I mean `a window of zero bits' as in description of this function - Zam. */ 153/* - I mean `a window of zero bits' as in description of this function - Zam. */
155 154
156 if (!bi) { 155 if (!bi) {
157 reiserfs_warning(s, "NULL bitmap info pointer for bitmap %d", 156 reiserfs_error(s, "jdm-4055", "NULL bitmap info pointer "
158 bmap_n); 157 "for bitmap %d", bmap_n);
159 return 0; 158 return 0;
160 } 159 }
161 160
@@ -400,11 +399,8 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
400 get_bit_address(s, block, &nr, &offset); 399 get_bit_address(s, block, &nr, &offset);
401 400
402 if (nr >= reiserfs_bmap_count(s)) { 401 if (nr >= reiserfs_bmap_count(s)) {
403 reiserfs_warning(s, "vs-4075: reiserfs_free_block: " 402 reiserfs_error(s, "vs-4075", "block %lu is out of range",
404 "block %lu is out of range on %s " 403 block);
405 "(nr=%u,max=%u)", block,
406 reiserfs_bdevname(s), nr,
407 reiserfs_bmap_count(s));
408 return; 404 return;
409 } 405 }
410 406
@@ -416,9 +412,8 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
416 412
417 /* clear bit for the given block in bit map */ 413 /* clear bit for the given block in bit map */
418 if (!reiserfs_test_and_clear_le_bit(offset, bmbh->b_data)) { 414 if (!reiserfs_test_and_clear_le_bit(offset, bmbh->b_data)) {
419 reiserfs_warning(s, "vs-4080: reiserfs_free_block: " 415 reiserfs_error(s, "vs-4080",
420 "free_block (%s:%lu)[dev:blocknr]: bit already cleared", 416 "block %lu: bit already cleared", block);
421 reiserfs_bdevname(s), block);
422 } 417 }
423 apbi[nr].free_count++; 418 apbi[nr].free_count++;
424 journal_mark_dirty(th, s, bmbh); 419 journal_mark_dirty(th, s, bmbh);
@@ -430,7 +425,7 @@ static void _reiserfs_free_block(struct reiserfs_transaction_handle *th,
430 425
431 journal_mark_dirty(th, s, sbh); 426 journal_mark_dirty(th, s, sbh);
432 if (for_unformatted) 427 if (for_unformatted)
433 DQUOT_FREE_BLOCK_NODIRTY(inode, 1); 428 vfs_dq_free_block_nodirty(inode, 1);
434} 429}
435 430
436void reiserfs_free_block(struct reiserfs_transaction_handle *th, 431void reiserfs_free_block(struct reiserfs_transaction_handle *th,
@@ -445,7 +440,7 @@ void reiserfs_free_block(struct reiserfs_transaction_handle *th,
445 return; 440 return;
446 441
447 if (block > sb_block_count(REISERFS_SB(s)->s_rs)) { 442 if (block > sb_block_count(REISERFS_SB(s)->s_rs)) {
448 reiserfs_panic(th->t_super, "bitmap-4072", 443 reiserfs_error(th->t_super, "bitmap-4072",
449 "Trying to free block outside file system " 444 "Trying to free block outside file system "
450 "boundaries (%lu > %lu)", 445 "boundaries (%lu > %lu)",
451 block, sb_block_count(REISERFS_SB(s)->s_rs)); 446 block, sb_block_count(REISERFS_SB(s)->s_rs));
@@ -477,9 +472,8 @@ static void __discard_prealloc(struct reiserfs_transaction_handle *th,
477 BUG_ON(!th->t_trans_id); 472 BUG_ON(!th->t_trans_id);
478#ifdef CONFIG_REISERFS_CHECK 473#ifdef CONFIG_REISERFS_CHECK
479 if (ei->i_prealloc_count < 0) 474 if (ei->i_prealloc_count < 0)
480 reiserfs_warning(th->t_super, 475 reiserfs_error(th->t_super, "zam-4001",
481 "zam-4001:%s: inode has negative prealloc blocks count.", 476 "inode has negative prealloc blocks count.");
482 __func__);
483#endif 477#endif
484 while (ei->i_prealloc_count > 0) { 478 while (ei->i_prealloc_count > 0) {
485 reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block); 479 reiserfs_free_prealloc_block(th, inode, ei->i_prealloc_block);
@@ -515,9 +509,9 @@ void reiserfs_discard_all_prealloc(struct reiserfs_transaction_handle *th)
515 i_prealloc_list); 509 i_prealloc_list);
516#ifdef CONFIG_REISERFS_CHECK 510#ifdef CONFIG_REISERFS_CHECK
517 if (!ei->i_prealloc_count) { 511 if (!ei->i_prealloc_count) {
518 reiserfs_warning(th->t_super, 512 reiserfs_error(th->t_super, "zam-4001",
519 "zam-4001:%s: inode is in prealloc list but has no preallocated blocks.", 513 "inode is in prealloc list but has "
520 __func__); 514 "no preallocated blocks.");
521 } 515 }
522#endif 516#endif
523 __discard_prealloc(th, ei); 517 __discard_prealloc(th, ei);
@@ -631,12 +625,12 @@ int reiserfs_parse_alloc_options(struct super_block *s, char *options)
631 continue; 625 continue;
632 } 626 }
633 627
634 reiserfs_warning(s, "zam-4001: %s : unknown option - %s", 628 reiserfs_warning(s, "zam-4001", "unknown option - %s",
635 __func__, this_char); 629 this_char);
636 return 1; 630 return 1;
637 } 631 }
638 632
639 reiserfs_warning(s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s)); 633 reiserfs_info(s, "allocator options = [%08x]\n", SB_ALLOC_OPTS(s));
640 return 0; 634 return 0;
641} 635}
642 636
@@ -1055,7 +1049,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1055 amount_needed, hint->inode->i_uid); 1049 amount_needed, hint->inode->i_uid);
1056#endif 1050#endif
1057 quota_ret = 1051 quota_ret =
1058 DQUOT_ALLOC_BLOCK_NODIRTY(hint->inode, amount_needed); 1052 vfs_dq_alloc_block_nodirty(hint->inode, amount_needed);
1059 if (quota_ret) /* Quota exceeded? */ 1053 if (quota_ret) /* Quota exceeded? */
1060 return QUOTA_EXCEEDED; 1054 return QUOTA_EXCEEDED;
1061 if (hint->preallocate && hint->prealloc_size) { 1055 if (hint->preallocate && hint->prealloc_size) {
@@ -1064,8 +1058,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1064 "reiserquota: allocating (prealloc) %d blocks id=%u", 1058 "reiserquota: allocating (prealloc) %d blocks id=%u",
1065 hint->prealloc_size, hint->inode->i_uid); 1059 hint->prealloc_size, hint->inode->i_uid);
1066#endif 1060#endif
1067 quota_ret = 1061 quota_ret = vfs_dq_prealloc_block_nodirty(hint->inode,
1068 DQUOT_PREALLOC_BLOCK_NODIRTY(hint->inode,
1069 hint->prealloc_size); 1062 hint->prealloc_size);
1070 if (quota_ret) 1063 if (quota_ret)
1071 hint->preallocate = hint->prealloc_size = 0; 1064 hint->preallocate = hint->prealloc_size = 0;
@@ -1098,7 +1091,10 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1098 nr_allocated, 1091 nr_allocated,
1099 hint->inode->i_uid); 1092 hint->inode->i_uid);
1100#endif 1093#endif
1101 DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + hint->prealloc_size - nr_allocated); /* Free not allocated blocks */ 1094 /* Free not allocated blocks */
1095 vfs_dq_free_block_nodirty(hint->inode,
1096 amount_needed + hint->prealloc_size -
1097 nr_allocated);
1102 } 1098 }
1103 while (nr_allocated--) 1099 while (nr_allocated--)
1104 reiserfs_free_block(hint->th, hint->inode, 1100 reiserfs_free_block(hint->th, hint->inode,
@@ -1129,7 +1125,7 @@ static inline int blocknrs_and_prealloc_arrays_from_search_start
1129 REISERFS_I(hint->inode)->i_prealloc_count, 1125 REISERFS_I(hint->inode)->i_prealloc_count,
1130 hint->inode->i_uid); 1126 hint->inode->i_uid);
1131#endif 1127#endif
1132 DQUOT_FREE_BLOCK_NODIRTY(hint->inode, amount_needed + 1128 vfs_dq_free_block_nodirty(hint->inode, amount_needed +
1133 hint->prealloc_size - nr_allocated - 1129 hint->prealloc_size - nr_allocated -
1134 REISERFS_I(hint->inode)-> 1130 REISERFS_I(hint->inode)->
1135 i_prealloc_count); 1131 i_prealloc_count);
@@ -1219,7 +1215,9 @@ void reiserfs_cache_bitmap_metadata(struct super_block *sb,
1219 unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size); 1215 unsigned long *cur = (unsigned long *)(bh->b_data + bh->b_size);
1220 1216
1221 /* The first bit must ALWAYS be 1 */ 1217 /* The first bit must ALWAYS be 1 */
1222 BUG_ON(!reiserfs_test_le_bit(0, (unsigned long *)bh->b_data)); 1218 if (!reiserfs_test_le_bit(0, (unsigned long *)bh->b_data))
1219 reiserfs_error(sb, "reiserfs-2025", "bitmap block %lu is "
1220 "corrupted: first bit must be 1", bh->b_blocknr);
1223 1221
1224 info->free_count = 0; 1222 info->free_count = 0;
1225 1223
diff --git a/fs/reiserfs/dir.c b/fs/reiserfs/dir.c
index e6b03d2020c..67a80d7e59e 100644
--- a/fs/reiserfs/dir.c
+++ b/fs/reiserfs/dir.c
@@ -41,10 +41,10 @@ static int reiserfs_dir_fsync(struct file *filp, struct dentry *dentry,
41 41
42#define store_ih(where,what) copy_item_head (where, what) 42#define store_ih(where,what) copy_item_head (where, what)
43 43
44// 44int reiserfs_readdir_dentry(struct dentry *dentry, void *dirent,
45static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir) 45 filldir_t filldir, loff_t *pos)
46{ 46{
47 struct inode *inode = filp->f_path.dentry->d_inode; 47 struct inode *inode = dentry->d_inode;
48 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 48 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
49 INITIALIZE_PATH(path_to_entry); 49 INITIALIZE_PATH(path_to_entry);
50 struct buffer_head *bh; 50 struct buffer_head *bh;
@@ -64,13 +64,9 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
64 64
65 /* form key for search the next directory entry using f_pos field of 65 /* form key for search the next directory entry using f_pos field of
66 file structure */ 66 file structure */
67 make_cpu_key(&pos_key, inode, 67 make_cpu_key(&pos_key, inode, *pos ?: DOT_OFFSET, TYPE_DIRENTRY, 3);
68 (filp->f_pos) ? (filp->f_pos) : DOT_OFFSET, TYPE_DIRENTRY,
69 3);
70 next_pos = cpu_key_k_offset(&pos_key); 68 next_pos = cpu_key_k_offset(&pos_key);
71 69
72 /* reiserfs_warning (inode->i_sb, "reiserfs_readdir 1: f_pos = %Ld", filp->f_pos); */
73
74 path_to_entry.reada = PATH_READA; 70 path_to_entry.reada = PATH_READA;
75 while (1) { 71 while (1) {
76 research: 72 research:
@@ -144,7 +140,7 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
144 /* Ignore the .reiserfs_priv entry */ 140 /* Ignore the .reiserfs_priv entry */
145 if (reiserfs_xattrs(inode->i_sb) && 141 if (reiserfs_xattrs(inode->i_sb) &&
146 !old_format_only(inode->i_sb) && 142 !old_format_only(inode->i_sb) &&
147 filp->f_path.dentry == inode->i_sb->s_root && 143 dentry == inode->i_sb->s_root &&
148 REISERFS_SB(inode->i_sb)->priv_root && 144 REISERFS_SB(inode->i_sb)->priv_root &&
149 REISERFS_SB(inode->i_sb)->priv_root->d_inode 145 REISERFS_SB(inode->i_sb)->priv_root->d_inode
150 && deh_objectid(deh) == 146 && deh_objectid(deh) ==
@@ -156,7 +152,7 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
156 } 152 }
157 153
158 d_off = deh_offset(deh); 154 d_off = deh_offset(deh);
159 filp->f_pos = d_off; 155 *pos = d_off;
160 d_ino = deh_objectid(deh); 156 d_ino = deh_objectid(deh);
161 if (d_reclen <= 32) { 157 if (d_reclen <= 32) {
162 local_buf = small_buf; 158 local_buf = small_buf;
@@ -223,15 +219,21 @@ static int reiserfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
223 219
224 } /* while */ 220 } /* while */
225 221
226 end: 222end:
227 filp->f_pos = next_pos; 223 *pos = next_pos;
228 pathrelse(&path_to_entry); 224 pathrelse(&path_to_entry);
229 reiserfs_check_path(&path_to_entry); 225 reiserfs_check_path(&path_to_entry);
230 out: 226out:
231 reiserfs_write_unlock(inode->i_sb); 227 reiserfs_write_unlock(inode->i_sb);
232 return ret; 228 return ret;
233} 229}
234 230
231static int reiserfs_readdir(struct file *file, void *dirent, filldir_t filldir)
232{
233 struct dentry *dentry = file->f_path.dentry;
234 return reiserfs_readdir_dentry(dentry, dirent, filldir, &file->f_pos);
235}
236
235/* compose directory item containing "." and ".." entries (entries are 237/* compose directory item containing "." and ".." entries (entries are
236 not aligned to 4 byte boundary) */ 238 not aligned to 4 byte boundary) */
237/* the last four params are LE */ 239/* the last four params are LE */
diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
index 2f87f5b1463..4beb964a2a3 100644
--- a/fs/reiserfs/do_balan.c
+++ b/fs/reiserfs/do_balan.c
@@ -29,6 +29,43 @@ struct tree_balance *cur_tb = NULL; /* detects whether more than one
29 is interrupting do_balance */ 29 is interrupting do_balance */
30#endif 30#endif
31 31
32static inline void buffer_info_init_left(struct tree_balance *tb,
33 struct buffer_info *bi)
34{
35 bi->tb = tb;
36 bi->bi_bh = tb->L[0];
37 bi->bi_parent = tb->FL[0];
38 bi->bi_position = get_left_neighbor_position(tb, 0);
39}
40
41static inline void buffer_info_init_right(struct tree_balance *tb,
42 struct buffer_info *bi)
43{
44 bi->tb = tb;
45 bi->bi_bh = tb->R[0];
46 bi->bi_parent = tb->FR[0];
47 bi->bi_position = get_right_neighbor_position(tb, 0);
48}
49
50static inline void buffer_info_init_tbS0(struct tree_balance *tb,
51 struct buffer_info *bi)
52{
53 bi->tb = tb;
54 bi->bi_bh = PATH_PLAST_BUFFER(tb->tb_path);
55 bi->bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
56 bi->bi_position = PATH_H_POSITION(tb->tb_path, 1);
57}
58
59static inline void buffer_info_init_bh(struct tree_balance *tb,
60 struct buffer_info *bi,
61 struct buffer_head *bh)
62{
63 bi->tb = tb;
64 bi->bi_bh = bh;
65 bi->bi_parent = NULL;
66 bi->bi_position = 0;
67}
68
32inline void do_balance_mark_leaf_dirty(struct tree_balance *tb, 69inline void do_balance_mark_leaf_dirty(struct tree_balance *tb,
33 struct buffer_head *bh, int flag) 70 struct buffer_head *bh, int flag)
34{ 71{
@@ -39,21 +76,21 @@ inline void do_balance_mark_leaf_dirty(struct tree_balance *tb,
39#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty 76#define do_balance_mark_internal_dirty do_balance_mark_leaf_dirty
40#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty 77#define do_balance_mark_sb_dirty do_balance_mark_leaf_dirty
41 78
42/* summary: 79/* summary:
43 if deleting something ( tb->insert_size[0] < 0 ) 80 if deleting something ( tb->insert_size[0] < 0 )
44 return(balance_leaf_when_delete()); (flag d handled here) 81 return(balance_leaf_when_delete()); (flag d handled here)
45 else 82 else
46 if lnum is larger than 0 we put items into the left node 83 if lnum is larger than 0 we put items into the left node
47 if rnum is larger than 0 we put items into the right node 84 if rnum is larger than 0 we put items into the right node
48 if snum1 is larger than 0 we put items into the new node s1 85 if snum1 is larger than 0 we put items into the new node s1
49 if snum2 is larger than 0 we put items into the new node s2 86 if snum2 is larger than 0 we put items into the new node s2
50Note that all *num* count new items being created. 87Note that all *num* count new items being created.
51 88
52It would be easier to read balance_leaf() if each of these summary 89It would be easier to read balance_leaf() if each of these summary
53lines was a separate procedure rather than being inlined. I think 90lines was a separate procedure rather than being inlined. I think
54that there are many passages here and in balance_leaf_when_delete() in 91that there are many passages here and in balance_leaf_when_delete() in
55which two calls to one procedure can replace two passages, and it 92which two calls to one procedure can replace two passages, and it
56might save cache space and improve software maintenance costs to do so. 93might save cache space and improve software maintenance costs to do so.
57 94
58Vladimir made the perceptive comment that we should offload most of 95Vladimir made the perceptive comment that we should offload most of
59the decision making in this function into fix_nodes/check_balance, and 96the decision making in this function into fix_nodes/check_balance, and
@@ -86,6 +123,7 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
86 "PAP-12010: tree can not be empty"); 123 "PAP-12010: tree can not be empty");
87 124
88 ih = B_N_PITEM_HEAD(tbS0, item_pos); 125 ih = B_N_PITEM_HEAD(tbS0, item_pos);
126 buffer_info_init_tbS0(tb, &bi);
89 127
90 /* Delete or truncate the item */ 128 /* Delete or truncate the item */
91 129
@@ -96,10 +134,6 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
96 "vs-12013: mode Delete, insert size %d, ih to be deleted %h", 134 "vs-12013: mode Delete, insert size %d, ih to be deleted %h",
97 -tb->insert_size[0], ih); 135 -tb->insert_size[0], ih);
98 136
99 bi.tb = tb;
100 bi.bi_bh = tbS0;
101 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
102 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
103 leaf_delete_items(&bi, 0, item_pos, 1, -1); 137 leaf_delete_items(&bi, 0, item_pos, 1, -1);
104 138
105 if (!item_pos && tb->CFL[0]) { 139 if (!item_pos && tb->CFL[0]) {
@@ -121,10 +155,6 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
121 break; 155 break;
122 156
123 case M_CUT:{ /* cut item in S[0] */ 157 case M_CUT:{ /* cut item in S[0] */
124 bi.tb = tb;
125 bi.bi_bh = tbS0;
126 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
127 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
128 if (is_direntry_le_ih(ih)) { 158 if (is_direntry_le_ih(ih)) {
129 159
130 /* UFS unlink semantics are such that you can only delete one directory entry at a time. */ 160 /* UFS unlink semantics are such that you can only delete one directory entry at a time. */
@@ -153,8 +183,8 @@ static int balance_leaf_when_delete(struct tree_balance *tb, int flag)
153 183
154 default: 184 default:
155 print_cur_tb("12040"); 185 print_cur_tb("12040");
156 reiserfs_panic(tb->tb_sb, 186 reiserfs_panic(tb->tb_sb, "PAP-12040",
157 "PAP-12040: balance_leaf_when_delete: unexpectable mode: %s(%d)", 187 "unexpected mode: %s(%d)",
158 (flag == 188 (flag ==
159 M_PASTE) ? "PASTE" : ((flag == 189 M_PASTE) ? "PASTE" : ((flag ==
160 M_INSERT) ? "INSERT" : 190 M_INSERT) ? "INSERT" :
@@ -258,15 +288,15 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
258 ) 288 )
259{ 289{
260 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path); 290 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
261 int item_pos = PATH_LAST_POSITION(tb->tb_path); /* index into the array of item headers in S[0] 291 int item_pos = PATH_LAST_POSITION(tb->tb_path); /* index into the array of item headers in S[0]
262 of the affected item */ 292 of the affected item */
263 struct buffer_info bi; 293 struct buffer_info bi;
264 struct buffer_head *S_new[2]; /* new nodes allocated to hold what could not fit into S */ 294 struct buffer_head *S_new[2]; /* new nodes allocated to hold what could not fit into S */
265 int snum[2]; /* number of items that will be placed 295 int snum[2]; /* number of items that will be placed
266 into S_new (includes partially shifted 296 into S_new (includes partially shifted
267 items) */ 297 items) */
268 int sbytes[2]; /* if an item is partially shifted into S_new then 298 int sbytes[2]; /* if an item is partially shifted into S_new then
269 if it is a directory item 299 if it is a directory item
270 it is the number of entries from the item that are shifted into S_new 300 it is the number of entries from the item that are shifted into S_new
271 else 301 else
272 it is the number of bytes from the item that are shifted into S_new 302 it is the number of bytes from the item that are shifted into S_new
@@ -325,11 +355,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
325 ih_item_len(ih)); 355 ih_item_len(ih));
326 356
327 /* Insert new item into L[0] */ 357 /* Insert new item into L[0] */
328 bi.tb = tb; 358 buffer_info_init_left(tb, &bi);
329 bi.bi_bh = tb->L[0];
330 bi.bi_parent = tb->FL[0];
331 bi.bi_position =
332 get_left_neighbor_position(tb, 0);
333 leaf_insert_into_buf(&bi, 359 leaf_insert_into_buf(&bi,
334 n + item_pos - 360 n + item_pos -
335 ret_val, ih, body, 361 ret_val, ih, body,
@@ -369,11 +395,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
369 leaf_shift_left(tb, tb->lnum[0] - 1, 395 leaf_shift_left(tb, tb->lnum[0] - 1,
370 tb->lbytes); 396 tb->lbytes);
371 /* Insert new item into L[0] */ 397 /* Insert new item into L[0] */
372 bi.tb = tb; 398 buffer_info_init_left(tb, &bi);
373 bi.bi_bh = tb->L[0];
374 bi.bi_parent = tb->FL[0];
375 bi.bi_position =
376 get_left_neighbor_position(tb, 0);
377 leaf_insert_into_buf(&bi, 399 leaf_insert_into_buf(&bi,
378 n + item_pos - 400 n + item_pos -
379 ret_val, ih, body, 401 ret_val, ih, body,
@@ -429,13 +451,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
429 } 451 }
430 452
431 /* Append given directory entry to directory item */ 453 /* Append given directory entry to directory item */
432 bi.tb = tb; 454 buffer_info_init_left(tb, &bi);
433 bi.bi_bh = tb->L[0];
434 bi.bi_parent =
435 tb->FL[0];
436 bi.bi_position =
437 get_left_neighbor_position
438 (tb, 0);
439 leaf_paste_in_buffer 455 leaf_paste_in_buffer
440 (&bi, 456 (&bi,
441 n + item_pos - 457 n + item_pos -
@@ -449,8 +465,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
449 /* when we have merge directory item, pos_in_item has been changed too */ 465 /* when we have merge directory item, pos_in_item has been changed too */
450 466
451 /* paste new directory entry. 1 is entry number */ 467 /* paste new directory entry. 1 is entry number */
452 leaf_paste_entries(bi. 468 leaf_paste_entries(&bi,
453 bi_bh,
454 n + 469 n +
455 item_pos 470 item_pos
456 - 471 -
@@ -524,13 +539,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
524 (tbS0, 539 (tbS0,
525 item_pos))); 540 item_pos)));
526 /* Append to body of item in L[0] */ 541 /* Append to body of item in L[0] */
527 bi.tb = tb; 542 buffer_info_init_left(tb, &bi);
528 bi.bi_bh = tb->L[0];
529 bi.bi_parent =
530 tb->FL[0];
531 bi.bi_position =
532 get_left_neighbor_position
533 (tb, 0);
534 leaf_paste_in_buffer 543 leaf_paste_in_buffer
535 (&bi, 544 (&bi,
536 n + item_pos - 545 n + item_pos -
@@ -681,11 +690,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
681 leaf_shift_left(tb, tb->lnum[0], 690 leaf_shift_left(tb, tb->lnum[0],
682 tb->lbytes); 691 tb->lbytes);
683 /* Append to body of item in L[0] */ 692 /* Append to body of item in L[0] */
684 bi.tb = tb; 693 buffer_info_init_left(tb, &bi);
685 bi.bi_bh = tb->L[0];
686 bi.bi_parent = tb->FL[0];
687 bi.bi_position =
688 get_left_neighbor_position(tb, 0);
689 leaf_paste_in_buffer(&bi, 694 leaf_paste_in_buffer(&bi,
690 n + item_pos - 695 n + item_pos -
691 ret_val, 696 ret_val,
@@ -699,7 +704,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
699 n + item_pos - 704 n + item_pos -
700 ret_val); 705 ret_val);
701 if (is_direntry_le_ih(pasted)) 706 if (is_direntry_le_ih(pasted))
702 leaf_paste_entries(bi.bi_bh, 707 leaf_paste_entries(&bi,
703 n + 708 n +
704 item_pos - 709 item_pos -
705 ret_val, 710 ret_val,
@@ -722,8 +727,9 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
722 } 727 }
723 break; 728 break;
724 default: /* cases d and t */ 729 default: /* cases d and t */
725 reiserfs_panic(tb->tb_sb, 730 reiserfs_panic(tb->tb_sb, "PAP-12130",
726 "PAP-12130: balance_leaf: lnum > 0: unexpectable mode: %s(%d)", 731 "lnum > 0: unexpected mode: "
732 " %s(%d)",
727 (flag == 733 (flag ==
728 M_DELETE) ? "DELETE" : ((flag == 734 M_DELETE) ? "DELETE" : ((flag ==
729 M_CUT) 735 M_CUT)
@@ -776,11 +782,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
776 set_le_ih_k_offset(ih, offset); 782 set_le_ih_k_offset(ih, offset);
777 put_ih_item_len(ih, tb->rbytes); 783 put_ih_item_len(ih, tb->rbytes);
778 /* Insert part of the item into R[0] */ 784 /* Insert part of the item into R[0] */
779 bi.tb = tb; 785 buffer_info_init_right(tb, &bi);
780 bi.bi_bh = tb->R[0];
781 bi.bi_parent = tb->FR[0];
782 bi.bi_position =
783 get_right_neighbor_position(tb, 0);
784 if ((old_len - tb->rbytes) > zeros_num) { 786 if ((old_len - tb->rbytes) > zeros_num) {
785 r_zeros_number = 0; 787 r_zeros_number = 0;
786 r_body = 788 r_body =
@@ -817,11 +819,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
817 tb->rnum[0] - 1, 819 tb->rnum[0] - 1,
818 tb->rbytes); 820 tb->rbytes);
819 /* Insert new item into R[0] */ 821 /* Insert new item into R[0] */
820 bi.tb = tb; 822 buffer_info_init_right(tb, &bi);
821 bi.bi_bh = tb->R[0];
822 bi.bi_parent = tb->FR[0];
823 bi.bi_position =
824 get_right_neighbor_position(tb, 0);
825 leaf_insert_into_buf(&bi, 823 leaf_insert_into_buf(&bi,
826 item_pos - n + 824 item_pos - n +
827 tb->rnum[0] - 1, 825 tb->rnum[0] - 1,
@@ -881,21 +879,14 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
881 pos_in_item - 879 pos_in_item -
882 entry_count + 880 entry_count +
883 tb->rbytes - 1; 881 tb->rbytes - 1;
884 bi.tb = tb; 882 buffer_info_init_right(tb, &bi);
885 bi.bi_bh = tb->R[0];
886 bi.bi_parent =
887 tb->FR[0];
888 bi.bi_position =
889 get_right_neighbor_position
890 (tb, 0);
891 leaf_paste_in_buffer 883 leaf_paste_in_buffer
892 (&bi, 0, 884 (&bi, 0,
893 paste_entry_position, 885 paste_entry_position,
894 tb->insert_size[0], 886 tb->insert_size[0],
895 body, zeros_num); 887 body, zeros_num);
896 /* paste entry */ 888 /* paste entry */
897 leaf_paste_entries(bi. 889 leaf_paste_entries(&bi,
898 bi_bh,
899 0, 890 0,
900 paste_entry_position, 891 paste_entry_position,
901 1, 892 1,
@@ -1019,12 +1010,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1019 (tb, tb->CFR[0], 0); 1010 (tb, tb->CFR[0], 0);
1020 1011
1021 /* Append part of body into R[0] */ 1012 /* Append part of body into R[0] */
1022 bi.tb = tb; 1013 buffer_info_init_right(tb, &bi);
1023 bi.bi_bh = tb->R[0];
1024 bi.bi_parent = tb->FR[0];
1025 bi.bi_position =
1026 get_right_neighbor_position
1027 (tb, 0);
1028 if (n_rem > zeros_num) { 1014 if (n_rem > zeros_num) {
1029 r_zeros_number = 0; 1015 r_zeros_number = 0;
1030 r_body = 1016 r_body =
@@ -1071,12 +1057,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1071 tb->rbytes); 1057 tb->rbytes);
1072 /* append item in R[0] */ 1058 /* append item in R[0] */
1073 if (pos_in_item >= 0) { 1059 if (pos_in_item >= 0) {
1074 bi.tb = tb; 1060 buffer_info_init_right(tb, &bi);
1075 bi.bi_bh = tb->R[0];
1076 bi.bi_parent = tb->FR[0];
1077 bi.bi_position =
1078 get_right_neighbor_position
1079 (tb, 0);
1080 leaf_paste_in_buffer(&bi, 1061 leaf_paste_in_buffer(&bi,
1081 item_pos - 1062 item_pos -
1082 n + 1063 n +
@@ -1096,7 +1077,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1096 tb->rnum[0]); 1077 tb->rnum[0]);
1097 if (is_direntry_le_ih(pasted) 1078 if (is_direntry_le_ih(pasted)
1098 && pos_in_item >= 0) { 1079 && pos_in_item >= 0) {
1099 leaf_paste_entries(bi.bi_bh, 1080 leaf_paste_entries(&bi,
1100 item_pos - 1081 item_pos -
1101 n + 1082 n +
1102 tb->rnum[0], 1083 tb->rnum[0],
@@ -1136,8 +1117,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1136 } 1117 }
1137 break; 1118 break;
1138 default: /* cases d and t */ 1119 default: /* cases d and t */
1139 reiserfs_panic(tb->tb_sb, 1120 reiserfs_panic(tb->tb_sb, "PAP-12175",
1140 "PAP-12175: balance_leaf: rnum > 0: unexpectable mode: %s(%d)", 1121 "rnum > 0: unexpected mode: %s(%d)",
1141 (flag == 1122 (flag ==
1142 M_DELETE) ? "DELETE" : ((flag == 1123 M_DELETE) ? "DELETE" : ((flag ==
1143 M_CUT) ? "CUT" 1124 M_CUT) ? "CUT"
@@ -1167,8 +1148,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1167 not set correctly */ 1148 not set correctly */
1168 if (tb->CFL[0]) { 1149 if (tb->CFL[0]) {
1169 if (!tb->CFR[0]) 1150 if (!tb->CFR[0])
1170 reiserfs_panic(tb->tb_sb, 1151 reiserfs_panic(tb->tb_sb, "vs-12195",
1171 "vs-12195: balance_leaf: CFR not initialized"); 1152 "CFR not initialized");
1172 copy_key(B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]), 1153 copy_key(B_N_PDELIM_KEY(tb->CFL[0], tb->lkey[0]),
1173 B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0])); 1154 B_N_PDELIM_KEY(tb->CFR[0], tb->rkey[0]));
1174 do_balance_mark_internal_dirty(tb, tb->CFL[0], 0); 1155 do_balance_mark_internal_dirty(tb, tb->CFL[0], 0);
@@ -1232,10 +1213,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1232 put_ih_item_len(ih, sbytes[i]); 1213 put_ih_item_len(ih, sbytes[i]);
1233 1214
1234 /* Insert part of the item into S_new[i] before 0-th item */ 1215 /* Insert part of the item into S_new[i] before 0-th item */
1235 bi.tb = tb; 1216 buffer_info_init_bh(tb, &bi, S_new[i]);
1236 bi.bi_bh = S_new[i];
1237 bi.bi_parent = NULL;
1238 bi.bi_position = 0;
1239 1217
1240 if ((old_len - sbytes[i]) > zeros_num) { 1218 if ((old_len - sbytes[i]) > zeros_num) {
1241 r_zeros_number = 0; 1219 r_zeros_number = 0;
@@ -1267,10 +1245,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1267 S_new[i]); 1245 S_new[i]);
1268 1246
1269 /* Insert new item into S_new[i] */ 1247 /* Insert new item into S_new[i] */
1270 bi.tb = tb; 1248 buffer_info_init_bh(tb, &bi, S_new[i]);
1271 bi.bi_bh = S_new[i];
1272 bi.bi_parent = NULL;
1273 bi.bi_position = 0;
1274 leaf_insert_into_buf(&bi, 1249 leaf_insert_into_buf(&bi,
1275 item_pos - n + 1250 item_pos - n +
1276 snum[i] - 1, ih, 1251 snum[i] - 1, ih,
@@ -1327,10 +1302,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1327 sbytes[i] - 1, 1302 sbytes[i] - 1,
1328 S_new[i]); 1303 S_new[i]);
1329 /* Paste given directory entry to directory item */ 1304 /* Paste given directory entry to directory item */
1330 bi.tb = tb; 1305 buffer_info_init_bh(tb, &bi, S_new[i]);
1331 bi.bi_bh = S_new[i];
1332 bi.bi_parent = NULL;
1333 bi.bi_position = 0;
1334 leaf_paste_in_buffer 1306 leaf_paste_in_buffer
1335 (&bi, 0, 1307 (&bi, 0,
1336 pos_in_item - 1308 pos_in_item -
@@ -1339,8 +1311,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1339 tb->insert_size[0], 1311 tb->insert_size[0],
1340 body, zeros_num); 1312 body, zeros_num);
1341 /* paste new directory entry */ 1313 /* paste new directory entry */
1342 leaf_paste_entries(bi. 1314 leaf_paste_entries(&bi,
1343 bi_bh,
1344 0, 1315 0,
1345 pos_in_item 1316 pos_in_item
1346 - 1317 -
@@ -1401,11 +1372,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1401 if (n_rem < 0) 1372 if (n_rem < 0)
1402 n_rem = 0; 1373 n_rem = 0;
1403 /* Append part of body into S_new[0] */ 1374 /* Append part of body into S_new[0] */
1404 bi.tb = tb; 1375 buffer_info_init_bh(tb, &bi, S_new[i]);
1405 bi.bi_bh = S_new[i];
1406 bi.bi_parent = NULL;
1407 bi.bi_position = 0;
1408
1409 if (n_rem > zeros_num) { 1376 if (n_rem > zeros_num) {
1410 r_zeros_number = 0; 1377 r_zeros_number = 0;
1411 r_body = 1378 r_body =
@@ -1475,7 +1442,10 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1475 && (pos_in_item != ih_item_len(ih_check) 1442 && (pos_in_item != ih_item_len(ih_check)
1476 || tb->insert_size[0] <= 0)) 1443 || tb->insert_size[0] <= 0))
1477 reiserfs_panic(tb->tb_sb, 1444 reiserfs_panic(tb->tb_sb,
1478 "PAP-12235: balance_leaf: pos_in_item must be equal to ih_item_len"); 1445 "PAP-12235",
1446 "pos_in_item "
1447 "must be equal "
1448 "to ih_item_len");
1479#endif /* CONFIG_REISERFS_CHECK */ 1449#endif /* CONFIG_REISERFS_CHECK */
1480 1450
1481 leaf_mi = 1451 leaf_mi =
@@ -1489,10 +1459,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1489 leaf_mi); 1459 leaf_mi);
1490 1460
1491 /* paste into item */ 1461 /* paste into item */
1492 bi.tb = tb; 1462 buffer_info_init_bh(tb, &bi, S_new[i]);
1493 bi.bi_bh = S_new[i];
1494 bi.bi_parent = NULL;
1495 bi.bi_position = 0;
1496 leaf_paste_in_buffer(&bi, 1463 leaf_paste_in_buffer(&bi,
1497 item_pos - n + 1464 item_pos - n +
1498 snum[i], 1465 snum[i],
@@ -1505,7 +1472,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1505 item_pos - n + 1472 item_pos - n +
1506 snum[i]); 1473 snum[i]);
1507 if (is_direntry_le_ih(pasted)) { 1474 if (is_direntry_le_ih(pasted)) {
1508 leaf_paste_entries(bi.bi_bh, 1475 leaf_paste_entries(&bi,
1509 item_pos - 1476 item_pos -
1510 n + snum[i], 1477 n + snum[i],
1511 pos_in_item, 1478 pos_in_item,
@@ -1535,8 +1502,8 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1535 } 1502 }
1536 break; 1503 break;
1537 default: /* cases d and t */ 1504 default: /* cases d and t */
1538 reiserfs_panic(tb->tb_sb, 1505 reiserfs_panic(tb->tb_sb, "PAP-12245",
1539 "PAP-12245: balance_leaf: blknum > 2: unexpectable mode: %s(%d)", 1506 "blknum > 2: unexpected mode: %s(%d)",
1540 (flag == 1507 (flag ==
1541 M_DELETE) ? "DELETE" : ((flag == 1508 M_DELETE) ? "DELETE" : ((flag ==
1542 M_CUT) ? "CUT" 1509 M_CUT) ? "CUT"
@@ -1559,10 +1526,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1559 1526
1560 switch (flag) { 1527 switch (flag) {
1561 case M_INSERT: /* insert item into S[0] */ 1528 case M_INSERT: /* insert item into S[0] */
1562 bi.tb = tb; 1529 buffer_info_init_tbS0(tb, &bi);
1563 bi.bi_bh = tbS0;
1564 bi.bi_parent = PATH_H_PPARENT(tb->tb_path, 0);
1565 bi.bi_position = PATH_H_POSITION(tb->tb_path, 1);
1566 leaf_insert_into_buf(&bi, item_pos, ih, body, 1530 leaf_insert_into_buf(&bi, item_pos, ih, body,
1567 zeros_num); 1531 zeros_num);
1568 1532
@@ -1589,14 +1553,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1589 "PAP-12260: insert_size is 0 already"); 1553 "PAP-12260: insert_size is 0 already");
1590 1554
1591 /* prepare space */ 1555 /* prepare space */
1592 bi.tb = tb; 1556 buffer_info_init_tbS0(tb, &bi);
1593 bi.bi_bh = tbS0;
1594 bi.bi_parent =
1595 PATH_H_PPARENT(tb->tb_path,
1596 0);
1597 bi.bi_position =
1598 PATH_H_POSITION(tb->tb_path,
1599 1);
1600 leaf_paste_in_buffer(&bi, 1557 leaf_paste_in_buffer(&bi,
1601 item_pos, 1558 item_pos,
1602 pos_in_item, 1559 pos_in_item,
@@ -1606,7 +1563,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1606 zeros_num); 1563 zeros_num);
1607 1564
1608 /* paste entry */ 1565 /* paste entry */
1609 leaf_paste_entries(bi.bi_bh, 1566 leaf_paste_entries(&bi,
1610 item_pos, 1567 item_pos,
1611 pos_in_item, 1568 pos_in_item,
1612 1, 1569 1,
@@ -1644,14 +1601,7 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1644 RFALSE(tb->insert_size[0] <= 0, 1601 RFALSE(tb->insert_size[0] <= 0,
1645 "PAP-12275: insert size must not be %d", 1602 "PAP-12275: insert size must not be %d",
1646 tb->insert_size[0]); 1603 tb->insert_size[0]);
1647 bi.tb = tb; 1604 buffer_info_init_tbS0(tb, &bi);
1648 bi.bi_bh = tbS0;
1649 bi.bi_parent =
1650 PATH_H_PPARENT(tb->tb_path,
1651 0);
1652 bi.bi_position =
1653 PATH_H_POSITION(tb->tb_path,
1654 1);
1655 leaf_paste_in_buffer(&bi, 1605 leaf_paste_in_buffer(&bi,
1656 item_pos, 1606 item_pos,
1657 pos_in_item, 1607 pos_in_item,
@@ -1681,10 +1631,11 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1681 print_cur_tb("12285"); 1631 print_cur_tb("12285");
1682 reiserfs_panic(tb-> 1632 reiserfs_panic(tb->
1683 tb_sb, 1633 tb_sb,
1684 "PAP-12285: balance_leaf: insert_size must be 0 (%d)", 1634 "PAP-12285",
1685 tb-> 1635 "insert_size "
1686 insert_size 1636 "must be 0 "
1687 [0]); 1637 "(%d)",
1638 tb->insert_size[0]);
1688 } 1639 }
1689 } 1640 }
1690#endif /* CONFIG_REISERFS_CHECK */ 1641#endif /* CONFIG_REISERFS_CHECK */
@@ -1697,11 +1648,10 @@ static int balance_leaf(struct tree_balance *tb, struct item_head *ih, /* item h
1697 if (flag == M_PASTE && tb->insert_size[0]) { 1648 if (flag == M_PASTE && tb->insert_size[0]) {
1698 print_cur_tb("12290"); 1649 print_cur_tb("12290");
1699 reiserfs_panic(tb->tb_sb, 1650 reiserfs_panic(tb->tb_sb,
1700 "PAP-12290: balance_leaf: insert_size is still not 0 (%d)", 1651 "PAP-12290", "insert_size is still not 0 (%d)",
1701 tb->insert_size[0]); 1652 tb->insert_size[0]);
1702 } 1653 }
1703#endif /* CONFIG_REISERFS_CHECK */ 1654#endif /* CONFIG_REISERFS_CHECK */
1704
1705 return 0; 1655 return 0;
1706} /* Leaf level of the tree is balanced (end of balance_leaf) */ 1656} /* Leaf level of the tree is balanced (end of balance_leaf) */
1707 1657
@@ -1724,7 +1674,6 @@ void make_empty_node(struct buffer_info *bi)
1724struct buffer_head *get_FEB(struct tree_balance *tb) 1674struct buffer_head *get_FEB(struct tree_balance *tb)
1725{ 1675{
1726 int i; 1676 int i;
1727 struct buffer_head *first_b;
1728 struct buffer_info bi; 1677 struct buffer_info bi;
1729 1678
1730 for (i = 0; i < MAX_FEB_SIZE; i++) 1679 for (i = 0; i < MAX_FEB_SIZE; i++)
@@ -1732,19 +1681,15 @@ struct buffer_head *get_FEB(struct tree_balance *tb)
1732 break; 1681 break;
1733 1682
1734 if (i == MAX_FEB_SIZE) 1683 if (i == MAX_FEB_SIZE)
1735 reiserfs_panic(tb->tb_sb, 1684 reiserfs_panic(tb->tb_sb, "vs-12300", "FEB list is empty");
1736 "vs-12300: get_FEB: FEB list is empty");
1737 1685
1738 bi.tb = tb; 1686 buffer_info_init_bh(tb, &bi, tb->FEB[i]);
1739 bi.bi_bh = first_b = tb->FEB[i];
1740 bi.bi_parent = NULL;
1741 bi.bi_position = 0;
1742 make_empty_node(&bi); 1687 make_empty_node(&bi);
1743 set_buffer_uptodate(first_b); 1688 set_buffer_uptodate(tb->FEB[i]);
1689 tb->used[i] = tb->FEB[i];
1744 tb->FEB[i] = NULL; 1690 tb->FEB[i] = NULL;
1745 tb->used[i] = first_b;
1746 1691
1747 return (first_b); 1692 return tb->used[i];
1748} 1693}
1749 1694
1750/* This is now used because reiserfs_free_block has to be able to 1695/* This is now used because reiserfs_free_block has to be able to
@@ -1755,15 +1700,16 @@ static void store_thrown(struct tree_balance *tb, struct buffer_head *bh)
1755 int i; 1700 int i;
1756 1701
1757 if (buffer_dirty(bh)) 1702 if (buffer_dirty(bh))
1758 reiserfs_warning(tb->tb_sb, 1703 reiserfs_warning(tb->tb_sb, "reiserfs-12320",
1759 "store_thrown deals with dirty buffer"); 1704 "called with dirty buffer");
1760 for (i = 0; i < ARRAY_SIZE(tb->thrown); i++) 1705 for (i = 0; i < ARRAY_SIZE(tb->thrown); i++)
1761 if (!tb->thrown[i]) { 1706 if (!tb->thrown[i]) {
1762 tb->thrown[i] = bh; 1707 tb->thrown[i] = bh;
1763 get_bh(bh); /* free_thrown puts this */ 1708 get_bh(bh); /* free_thrown puts this */
1764 return; 1709 return;
1765 } 1710 }
1766 reiserfs_warning(tb->tb_sb, "store_thrown: too many thrown buffers"); 1711 reiserfs_warning(tb->tb_sb, "reiserfs-12321",
1712 "too many thrown buffers");
1767} 1713}
1768 1714
1769static void free_thrown(struct tree_balance *tb) 1715static void free_thrown(struct tree_balance *tb)
@@ -1774,8 +1720,8 @@ static void free_thrown(struct tree_balance *tb)
1774 if (tb->thrown[i]) { 1720 if (tb->thrown[i]) {
1775 blocknr = tb->thrown[i]->b_blocknr; 1721 blocknr = tb->thrown[i]->b_blocknr;
1776 if (buffer_dirty(tb->thrown[i])) 1722 if (buffer_dirty(tb->thrown[i]))
1777 reiserfs_warning(tb->tb_sb, 1723 reiserfs_warning(tb->tb_sb, "reiserfs-12322",
1778 "free_thrown deals with dirty buffer %d", 1724 "called with dirty buffer %d",
1779 blocknr); 1725 blocknr);
1780 brelse(tb->thrown[i]); /* incremented in store_thrown */ 1726 brelse(tb->thrown[i]); /* incremented in store_thrown */
1781 reiserfs_free_block(tb->transaction_handle, NULL, 1727 reiserfs_free_block(tb->transaction_handle, NULL,
@@ -1873,20 +1819,19 @@ static void check_internal_node(struct super_block *s, struct buffer_head *bh,
1873 for (i = 0; i <= B_NR_ITEMS(bh); i++, dc++) { 1819 for (i = 0; i <= B_NR_ITEMS(bh); i++, dc++) {
1874 if (!is_reusable(s, dc_block_number(dc), 1)) { 1820 if (!is_reusable(s, dc_block_number(dc), 1)) {
1875 print_cur_tb(mes); 1821 print_cur_tb(mes);
1876 reiserfs_panic(s, 1822 reiserfs_panic(s, "PAP-12338",
1877 "PAP-12338: check_internal_node: invalid child pointer %y in %b", 1823 "invalid child pointer %y in %b",
1878 dc, bh); 1824 dc, bh);
1879 } 1825 }
1880 } 1826 }
1881} 1827}
1882 1828
1883static int locked_or_not_in_tree(struct buffer_head *bh, char *which) 1829static int locked_or_not_in_tree(struct tree_balance *tb,
1830 struct buffer_head *bh, char *which)
1884{ 1831{
1885 if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) || 1832 if ((!buffer_journal_prepared(bh) && buffer_locked(bh)) ||
1886 !B_IS_IN_TREE(bh)) { 1833 !B_IS_IN_TREE(bh)) {
1887 reiserfs_warning(NULL, 1834 reiserfs_warning(tb->tb_sb, "vs-12339", "%s (%b)", which, bh);
1888 "vs-12339: locked_or_not_in_tree: %s (%b)",
1889 which, bh);
1890 return 1; 1835 return 1;
1891 } 1836 }
1892 return 0; 1837 return 0;
@@ -1897,26 +1842,28 @@ static int check_before_balancing(struct tree_balance *tb)
1897 int retval = 0; 1842 int retval = 0;
1898 1843
1899 if (cur_tb) { 1844 if (cur_tb) {
1900 reiserfs_panic(tb->tb_sb, "vs-12335: check_before_balancing: " 1845 reiserfs_panic(tb->tb_sb, "vs-12335", "suspect that schedule "
1901 "suspect that schedule occurred based on cur_tb not being null at this point in code. " 1846 "occurred based on cur_tb not being null at "
1902 "do_balance cannot properly handle schedule occurring while it runs."); 1847 "this point in code. do_balance cannot properly "
1848 "handle schedule occurring while it runs.");
1903 } 1849 }
1904 1850
1905 /* double check that buffers that we will modify are unlocked. (fix_nodes should already have 1851 /* double check that buffers that we will modify are unlocked. (fix_nodes should already have
1906 prepped all of these for us). */ 1852 prepped all of these for us). */
1907 if (tb->lnum[0]) { 1853 if (tb->lnum[0]) {
1908 retval |= locked_or_not_in_tree(tb->L[0], "L[0]"); 1854 retval |= locked_or_not_in_tree(tb, tb->L[0], "L[0]");
1909 retval |= locked_or_not_in_tree(tb->FL[0], "FL[0]"); 1855 retval |= locked_or_not_in_tree(tb, tb->FL[0], "FL[0]");
1910 retval |= locked_or_not_in_tree(tb->CFL[0], "CFL[0]"); 1856 retval |= locked_or_not_in_tree(tb, tb->CFL[0], "CFL[0]");
1911 check_leaf(tb->L[0]); 1857 check_leaf(tb->L[0]);
1912 } 1858 }
1913 if (tb->rnum[0]) { 1859 if (tb->rnum[0]) {
1914 retval |= locked_or_not_in_tree(tb->R[0], "R[0]"); 1860 retval |= locked_or_not_in_tree(tb, tb->R[0], "R[0]");
1915 retval |= locked_or_not_in_tree(tb->FR[0], "FR[0]"); 1861 retval |= locked_or_not_in_tree(tb, tb->FR[0], "FR[0]");
1916 retval |= locked_or_not_in_tree(tb->CFR[0], "CFR[0]"); 1862 retval |= locked_or_not_in_tree(tb, tb->CFR[0], "CFR[0]");
1917 check_leaf(tb->R[0]); 1863 check_leaf(tb->R[0]);
1918 } 1864 }
1919 retval |= locked_or_not_in_tree(PATH_PLAST_BUFFER(tb->tb_path), "S[0]"); 1865 retval |= locked_or_not_in_tree(tb, PATH_PLAST_BUFFER(tb->tb_path),
1866 "S[0]");
1920 check_leaf(PATH_PLAST_BUFFER(tb->tb_path)); 1867 check_leaf(PATH_PLAST_BUFFER(tb->tb_path));
1921 1868
1922 return retval; 1869 return retval;
@@ -1930,8 +1877,8 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1930 dc_size(B_N_CHILD 1877 dc_size(B_N_CHILD
1931 (tb->FL[0], get_left_neighbor_position(tb, 0)))) { 1878 (tb->FL[0], get_left_neighbor_position(tb, 0)))) {
1932 print_cur_tb("12221"); 1879 print_cur_tb("12221");
1933 reiserfs_panic(tb->tb_sb, 1880 reiserfs_panic(tb->tb_sb, "PAP-12355",
1934 "PAP-12355: check_after_balance_leaf: shift to left was incorrect"); 1881 "shift to left was incorrect");
1935 } 1882 }
1936 } 1883 }
1937 if (tb->rnum[0]) { 1884 if (tb->rnum[0]) {
@@ -1940,8 +1887,8 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1940 dc_size(B_N_CHILD 1887 dc_size(B_N_CHILD
1941 (tb->FR[0], get_right_neighbor_position(tb, 0)))) { 1888 (tb->FR[0], get_right_neighbor_position(tb, 0)))) {
1942 print_cur_tb("12222"); 1889 print_cur_tb("12222");
1943 reiserfs_panic(tb->tb_sb, 1890 reiserfs_panic(tb->tb_sb, "PAP-12360",
1944 "PAP-12360: check_after_balance_leaf: shift to right was incorrect"); 1891 "shift to right was incorrect");
1945 } 1892 }
1946 } 1893 }
1947 if (PATH_H_PBUFFER(tb->tb_path, 1) && 1894 if (PATH_H_PBUFFER(tb->tb_path, 1) &&
@@ -1955,7 +1902,7 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1955 PATH_H_POSITION(tb->tb_path, 1902 PATH_H_POSITION(tb->tb_path,
1956 1)))); 1903 1))));
1957 print_cur_tb("12223"); 1904 print_cur_tb("12223");
1958 reiserfs_warning(tb->tb_sb, 1905 reiserfs_warning(tb->tb_sb, "reiserfs-12363",
1959 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; " 1906 "B_FREE_SPACE (PATH_H_PBUFFER(tb->tb_path,0)) = %d; "
1960 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d", 1907 "MAX_CHILD_SIZE (%d) - dc_size( %y, %d ) [%d] = %d",
1961 left, 1908 left,
@@ -1966,8 +1913,7 @@ static void check_after_balance_leaf(struct tree_balance *tb)
1966 (PATH_H_PBUFFER(tb->tb_path, 1), 1913 (PATH_H_PBUFFER(tb->tb_path, 1),
1967 PATH_H_POSITION(tb->tb_path, 1))), 1914 PATH_H_POSITION(tb->tb_path, 1))),
1968 right); 1915 right);
1969 reiserfs_panic(tb->tb_sb, 1916 reiserfs_panic(tb->tb_sb, "PAP-12365", "S is incorrect");
1970 "PAP-12365: check_after_balance_leaf: S is incorrect");
1971 } 1917 }
1972} 1918}
1973 1919
@@ -2037,7 +1983,7 @@ static inline void do_balance_starts(struct tree_balance *tb)
2037 /* store_print_tb (tb); */ 1983 /* store_print_tb (tb); */
2038 1984
2039 /* do not delete, just comment it out */ 1985 /* do not delete, just comment it out */
2040/* print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb, 1986/* print_tb(flag, PATH_LAST_POSITION(tb->tb_path), tb->tb_path->pos_in_item, tb,
2041 "check");*/ 1987 "check");*/
2042 RFALSE(check_before_balancing(tb), "PAP-12340: locked buffers in TB"); 1988 RFALSE(check_before_balancing(tb), "PAP-12340: locked buffers in TB");
2043#ifdef CONFIG_REISERFS_CHECK 1989#ifdef CONFIG_REISERFS_CHECK
@@ -2102,14 +2048,13 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
2102 tb->need_balance_dirty = 0; 2048 tb->need_balance_dirty = 0;
2103 2049
2104 if (FILESYSTEM_CHANGED_TB(tb)) { 2050 if (FILESYSTEM_CHANGED_TB(tb)) {
2105 reiserfs_panic(tb->tb_sb, 2051 reiserfs_panic(tb->tb_sb, "clm-6000", "fs generation has "
2106 "clm-6000: do_balance, fs generation has changed\n"); 2052 "changed");
2107 } 2053 }
2108 /* if we have no real work to do */ 2054 /* if we have no real work to do */
2109 if (!tb->insert_size[0]) { 2055 if (!tb->insert_size[0]) {
2110 reiserfs_warning(tb->tb_sb, 2056 reiserfs_warning(tb->tb_sb, "PAP-12350",
2111 "PAP-12350: do_balance: insert_size == 0, mode == %c", 2057 "insert_size == 0, mode == %c", flag);
2112 flag);
2113 unfix_nodes(tb); 2058 unfix_nodes(tb);
2114 return; 2059 return;
2115 } 2060 }
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index 33408417038..9f436668b7f 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -20,14 +20,14 @@
20** insertion/balancing, for files that are written in one write. 20** insertion/balancing, for files that are written in one write.
21** It avoids unnecessary tail packings (balances) for files that are written in 21** It avoids unnecessary tail packings (balances) for files that are written in
22** multiple writes and are small enough to have tails. 22** multiple writes and are small enough to have tails.
23** 23**
24** file_release is called by the VFS layer when the file is closed. If 24** file_release is called by the VFS layer when the file is closed. If
25** this is the last open file descriptor, and the file 25** this is the last open file descriptor, and the file
26** small enough to have a tail, and the tail is currently in an 26** small enough to have a tail, and the tail is currently in an
27** unformatted node, the tail is converted back into a direct item. 27** unformatted node, the tail is converted back into a direct item.
28** 28**
29** We use reiserfs_truncate_file to pack the tail, since it already has 29** We use reiserfs_truncate_file to pack the tail, since it already has
30** all the conditions coded. 30** all the conditions coded.
31*/ 31*/
32static int reiserfs_file_release(struct inode *inode, struct file *filp) 32static int reiserfs_file_release(struct inode *inode, struct file *filp)
33{ 33{
@@ -76,7 +76,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp)
76 * and let the admin know what is going on. 76 * and let the admin know what is going on.
77 */ 77 */
78 igrab(inode); 78 igrab(inode);
79 reiserfs_warning(inode->i_sb, 79 reiserfs_warning(inode->i_sb, "clm-9001",
80 "pinning inode %lu because the " 80 "pinning inode %lu because the "
81 "preallocation can't be freed", 81 "preallocation can't be freed",
82 inode->i_ino); 82 inode->i_ino);
@@ -134,23 +134,23 @@ static void reiserfs_vfs_truncate_file(struct inode *inode)
134 * be removed... 134 * be removed...
135 */ 135 */
136 136
137static int reiserfs_sync_file(struct file *p_s_filp, 137static int reiserfs_sync_file(struct file *filp,
138 struct dentry *p_s_dentry, int datasync) 138 struct dentry *dentry, int datasync)
139{ 139{
140 struct inode *p_s_inode = p_s_dentry->d_inode; 140 struct inode *inode = dentry->d_inode;
141 int n_err; 141 int err;
142 int barrier_done; 142 int barrier_done;
143 143
144 BUG_ON(!S_ISREG(p_s_inode->i_mode)); 144 BUG_ON(!S_ISREG(inode->i_mode));
145 n_err = sync_mapping_buffers(p_s_inode->i_mapping); 145 err = sync_mapping_buffers(inode->i_mapping);
146 reiserfs_write_lock(p_s_inode->i_sb); 146 reiserfs_write_lock(inode->i_sb);
147 barrier_done = reiserfs_commit_for_inode(p_s_inode); 147 barrier_done = reiserfs_commit_for_inode(inode);
148 reiserfs_write_unlock(p_s_inode->i_sb); 148 reiserfs_write_unlock(inode->i_sb);
149 if (barrier_done != 1 && reiserfs_barrier_flush(p_s_inode->i_sb)) 149 if (barrier_done != 1 && reiserfs_barrier_flush(inode->i_sb))
150 blkdev_issue_flush(p_s_inode->i_sb->s_bdev, NULL); 150 blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
151 if (barrier_done < 0) 151 if (barrier_done < 0)
152 return barrier_done; 152 return barrier_done;
153 return (n_err < 0) ? -EIO : 0; 153 return (err < 0) ? -EIO : 0;
154} 154}
155 155
156/* taken fs/buffer.c:__block_commit_write */ 156/* taken fs/buffer.c:__block_commit_write */
@@ -223,7 +223,7 @@ int reiserfs_commit_page(struct inode *inode, struct page *page,
223} 223}
224 224
225/* Write @count bytes at position @ppos in a file indicated by @file 225/* Write @count bytes at position @ppos in a file indicated by @file
226 from the buffer @buf. 226 from the buffer @buf.
227 227
228 generic_file_write() is only appropriate for filesystems that are not seeking to optimize performance and want 228 generic_file_write() is only appropriate for filesystems that are not seeking to optimize performance and want
229 something simple that works. It is not for serious use by general purpose filesystems, excepting the one that it was 229 something simple that works. It is not for serious use by general purpose filesystems, excepting the one that it was
diff --git a/fs/reiserfs/fix_node.c b/fs/reiserfs/fix_node.c
index 07d05e0842b..5e5a4e6fbaf 100644
--- a/fs/reiserfs/fix_node.c
+++ b/fs/reiserfs/fix_node.c
@@ -30,8 +30,8 @@
30 ** get_direct_parent 30 ** get_direct_parent
31 ** get_neighbors 31 ** get_neighbors
32 ** fix_nodes 32 ** fix_nodes
33 ** 33 **
34 ** 34 **
35 **/ 35 **/
36 36
37#include <linux/time.h> 37#include <linux/time.h>
@@ -135,8 +135,7 @@ static void create_virtual_node(struct tree_balance *tb, int h)
135 vn->vn_free_ptr += 135 vn->vn_free_ptr +=
136 op_create_vi(vn, vi, is_affected, tb->insert_size[0]); 136 op_create_vi(vn, vi, is_affected, tb->insert_size[0]);
137 if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr) 137 if (tb->vn_buf + tb->vn_buf_size < vn->vn_free_ptr)
138 reiserfs_panic(tb->tb_sb, 138 reiserfs_panic(tb->tb_sb, "vs-8030",
139 "vs-8030: create_virtual_node: "
140 "virtual node space consumed"); 139 "virtual node space consumed");
141 140
142 if (!is_affected) 141 if (!is_affected)
@@ -186,8 +185,9 @@ static void create_virtual_node(struct tree_balance *tb, int h)
186 && I_ENTRY_COUNT(B_N_PITEM_HEAD(Sh, 0)) == 1)) { 185 && I_ENTRY_COUNT(B_N_PITEM_HEAD(Sh, 0)) == 1)) {
187 /* node contains more than 1 item, or item is not directory item, or this item contains more than 1 entry */ 186 /* node contains more than 1 item, or item is not directory item, or this item contains more than 1 entry */
188 print_block(Sh, 0, -1, -1); 187 print_block(Sh, 0, -1, -1);
189 reiserfs_panic(tb->tb_sb, 188 reiserfs_panic(tb->tb_sb, "vs-8045",
190 "vs-8045: create_virtual_node: rdkey %k, affected item==%d (mode==%c) Must be %c", 189 "rdkey %k, affected item==%d "
190 "(mode==%c) Must be %c",
191 key, vn->vn_affected_item_num, 191 key, vn->vn_affected_item_num,
192 vn->vn_mode, M_DELETE); 192 vn->vn_mode, M_DELETE);
193 } 193 }
@@ -377,9 +377,9 @@ static int get_num_ver(int mode, struct tree_balance *tb, int h,
377 int needed_nodes; 377 int needed_nodes;
378 int start_item, /* position of item we start filling node from */ 378 int start_item, /* position of item we start filling node from */
379 end_item, /* position of item we finish filling node by */ 379 end_item, /* position of item we finish filling node by */
380 start_bytes, /* number of first bytes (entries for directory) of start_item-th item 380 start_bytes, /* number of first bytes (entries for directory) of start_item-th item
381 we do not include into node that is being filled */ 381 we do not include into node that is being filled */
382 end_bytes; /* number of last bytes (entries for directory) of end_item-th item 382 end_bytes; /* number of last bytes (entries for directory) of end_item-th item
383 we do node include into node that is being filled */ 383 we do node include into node that is being filled */
384 int split_item_positions[2]; /* these are positions in virtual item of 384 int split_item_positions[2]; /* these are positions in virtual item of
385 items, that are split between S[0] and 385 items, that are split between S[0] and
@@ -496,8 +496,8 @@ static int get_num_ver(int mode, struct tree_balance *tb, int h,
496 snum012[needed_nodes - 1 + 3] = units; 496 snum012[needed_nodes - 1 + 3] = units;
497 497
498 if (needed_nodes > 2) 498 if (needed_nodes > 2)
499 reiserfs_warning(tb->tb_sb, "vs-8111: get_num_ver: " 499 reiserfs_warning(tb->tb_sb, "vs-8111",
500 "split_item_position is out of boundary"); 500 "split_item_position is out of range");
501 snum012[needed_nodes - 1]++; 501 snum012[needed_nodes - 1]++;
502 split_item_positions[needed_nodes - 1] = i; 502 split_item_positions[needed_nodes - 1] = i;
503 needed_nodes++; 503 needed_nodes++;
@@ -533,8 +533,8 @@ static int get_num_ver(int mode, struct tree_balance *tb, int h,
533 533
534 if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY && 534 if (vn->vn_vi[split_item_num].vi_index != TYPE_DIRENTRY &&
535 vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT) 535 vn->vn_vi[split_item_num].vi_index != TYPE_INDIRECT)
536 reiserfs_warning(tb->tb_sb, "vs-8115: get_num_ver: not " 536 reiserfs_warning(tb->tb_sb, "vs-8115",
537 "directory or indirect item"); 537 "not directory or indirect item");
538 } 538 }
539 539
540 /* now we know S2bytes, calculate S1bytes */ 540 /* now we know S2bytes, calculate S1bytes */
@@ -569,7 +569,7 @@ extern struct tree_balance *cur_tb;
569 569
570/* Set parameters for balancing. 570/* Set parameters for balancing.
571 * Performs write of results of analysis of balancing into structure tb, 571 * Performs write of results of analysis of balancing into structure tb,
572 * where it will later be used by the functions that actually do the balancing. 572 * where it will later be used by the functions that actually do the balancing.
573 * Parameters: 573 * Parameters:
574 * tb tree_balance structure; 574 * tb tree_balance structure;
575 * h current level of the node; 575 * h current level of the node;
@@ -749,25 +749,26 @@ else \
749 -1, -1);\ 749 -1, -1);\
750} 750}
751 751
752static void free_buffers_in_tb(struct tree_balance *p_s_tb) 752static void free_buffers_in_tb(struct tree_balance *tb)
753{ 753{
754 int n_counter; 754 int i;
755 755
756 decrement_counters_in_path(p_s_tb->tb_path); 756 pathrelse(tb->tb_path);
757 757
758 for (n_counter = 0; n_counter < MAX_HEIGHT; n_counter++) { 758 for (i = 0; i < MAX_HEIGHT; i++) {
759 decrement_bcount(p_s_tb->L[n_counter]); 759 brelse(tb->L[i]);
760 p_s_tb->L[n_counter] = NULL; 760 brelse(tb->R[i]);
761 decrement_bcount(p_s_tb->R[n_counter]); 761 brelse(tb->FL[i]);
762 p_s_tb->R[n_counter] = NULL; 762 brelse(tb->FR[i]);
763 decrement_bcount(p_s_tb->FL[n_counter]); 763 brelse(tb->CFL[i]);
764 p_s_tb->FL[n_counter] = NULL; 764 brelse(tb->CFR[i]);
765 decrement_bcount(p_s_tb->FR[n_counter]); 765
766 p_s_tb->FR[n_counter] = NULL; 766 tb->L[i] = NULL;
767 decrement_bcount(p_s_tb->CFL[n_counter]); 767 tb->R[i] = NULL;
768 p_s_tb->CFL[n_counter] = NULL; 768 tb->FL[i] = NULL;
769 decrement_bcount(p_s_tb->CFR[n_counter]); 769 tb->FR[i] = NULL;
770 p_s_tb->CFR[n_counter] = NULL; 770 tb->CFL[i] = NULL;
771 tb->CFR[i] = NULL;
771 } 772 }
772} 773}
773 774
@@ -777,14 +778,14 @@ static void free_buffers_in_tb(struct tree_balance *p_s_tb)
777 * NO_DISK_SPACE - no disk space. 778 * NO_DISK_SPACE - no disk space.
778 */ 779 */
779/* The function is NOT SCHEDULE-SAFE! */ 780/* The function is NOT SCHEDULE-SAFE! */
780static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h) 781static int get_empty_nodes(struct tree_balance *tb, int h)
781{ 782{
782 struct buffer_head *p_s_new_bh, 783 struct buffer_head *new_bh,
783 *p_s_Sh = PATH_H_PBUFFER(p_s_tb->tb_path, n_h); 784 *Sh = PATH_H_PBUFFER(tb->tb_path, h);
784 b_blocknr_t *p_n_blocknr, a_n_blocknrs[MAX_AMOUNT_NEEDED] = { 0, }; 785 b_blocknr_t *blocknr, blocknrs[MAX_AMOUNT_NEEDED] = { 0, };
785 int n_counter, n_number_of_freeblk, n_amount_needed, /* number of needed empty blocks */ 786 int counter, number_of_freeblk, amount_needed, /* number of needed empty blocks */
786 n_retval = CARRY_ON; 787 retval = CARRY_ON;
787 struct super_block *p_s_sb = p_s_tb->tb_sb; 788 struct super_block *sb = tb->tb_sb;
788 789
789 /* number_of_freeblk is the number of empty blocks which have been 790 /* number_of_freeblk is the number of empty blocks which have been
790 acquired for use by the balancing algorithm minus the number of 791 acquired for use by the balancing algorithm minus the number of
@@ -792,7 +793,7 @@ static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h)
792 number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs 793 number_of_freeblk = tb->cur_blknum can be non-zero if a schedule occurs
793 after empty blocks are acquired, and the balancing analysis is 794 after empty blocks are acquired, and the balancing analysis is
794 then restarted, amount_needed is the number needed by this level 795 then restarted, amount_needed is the number needed by this level
795 (n_h) of the balancing analysis. 796 (h) of the balancing analysis.
796 797
797 Note that for systems with many processes writing, it would be 798 Note that for systems with many processes writing, it would be
798 more layout optimal to calculate the total number needed by all 799 more layout optimal to calculate the total number needed by all
@@ -800,54 +801,54 @@ static int get_empty_nodes(struct tree_balance *p_s_tb, int n_h)
800 801
801 /* Initiate number_of_freeblk to the amount acquired prior to the restart of 802 /* Initiate number_of_freeblk to the amount acquired prior to the restart of
802 the analysis or 0 if not restarted, then subtract the amount needed 803 the analysis or 0 if not restarted, then subtract the amount needed
803 by all of the levels of the tree below n_h. */ 804 by all of the levels of the tree below h. */
804 /* blknum includes S[n_h], so we subtract 1 in this calculation */ 805 /* blknum includes S[h], so we subtract 1 in this calculation */
805 for (n_counter = 0, n_number_of_freeblk = p_s_tb->cur_blknum; 806 for (counter = 0, number_of_freeblk = tb->cur_blknum;
806 n_counter < n_h; n_counter++) 807 counter < h; counter++)
807 n_number_of_freeblk -= 808 number_of_freeblk -=
808 (p_s_tb->blknum[n_counter]) ? (p_s_tb->blknum[n_counter] - 809 (tb->blknum[counter]) ? (tb->blknum[counter] -
809 1) : 0; 810 1) : 0;
810 811
811 /* Allocate missing empty blocks. */ 812 /* Allocate missing empty blocks. */
812 /* if p_s_Sh == 0 then we are getting a new root */ 813 /* if Sh == 0 then we are getting a new root */
813 n_amount_needed = (p_s_Sh) ? (p_s_tb->blknum[n_h] - 1) : 1; 814 amount_needed = (Sh) ? (tb->blknum[h] - 1) : 1;
814 /* Amount_needed = the amount that we need more than the amount that we have. */ 815 /* Amount_needed = the amount that we need more than the amount that we have. */
815 if (n_amount_needed > n_number_of_freeblk) 816 if (amount_needed > number_of_freeblk)
816 n_amount_needed -= n_number_of_freeblk; 817 amount_needed -= number_of_freeblk;
817 else /* If we have enough already then there is nothing to do. */ 818 else /* If we have enough already then there is nothing to do. */
818 return CARRY_ON; 819 return CARRY_ON;
819 820
820 /* No need to check quota - is not allocated for blocks used for formatted nodes */ 821 /* No need to check quota - is not allocated for blocks used for formatted nodes */
821 if (reiserfs_new_form_blocknrs(p_s_tb, a_n_blocknrs, 822 if (reiserfs_new_form_blocknrs(tb, blocknrs,
822 n_amount_needed) == NO_DISK_SPACE) 823 amount_needed) == NO_DISK_SPACE)
823 return NO_DISK_SPACE; 824 return NO_DISK_SPACE;
824 825
825 /* for each blocknumber we just got, get a buffer and stick it on FEB */ 826 /* for each blocknumber we just got, get a buffer and stick it on FEB */
826 for (p_n_blocknr = a_n_blocknrs, n_counter = 0; 827 for (blocknr = blocknrs, counter = 0;
827 n_counter < n_amount_needed; p_n_blocknr++, n_counter++) { 828 counter < amount_needed; blocknr++, counter++) {
828 829
829 RFALSE(!*p_n_blocknr, 830 RFALSE(!*blocknr,
830 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks"); 831 "PAP-8135: reiserfs_new_blocknrs failed when got new blocks");
831 832
832 p_s_new_bh = sb_getblk(p_s_sb, *p_n_blocknr); 833 new_bh = sb_getblk(sb, *blocknr);
833 RFALSE(buffer_dirty(p_s_new_bh) || 834 RFALSE(buffer_dirty(new_bh) ||
834 buffer_journaled(p_s_new_bh) || 835 buffer_journaled(new_bh) ||
835 buffer_journal_dirty(p_s_new_bh), 836 buffer_journal_dirty(new_bh),
836 "PAP-8140: journlaled or dirty buffer %b for the new block", 837 "PAP-8140: journlaled or dirty buffer %b for the new block",
837 p_s_new_bh); 838 new_bh);
838 839
839 /* Put empty buffers into the array. */ 840 /* Put empty buffers into the array. */
840 RFALSE(p_s_tb->FEB[p_s_tb->cur_blknum], 841 RFALSE(tb->FEB[tb->cur_blknum],
841 "PAP-8141: busy slot for new buffer"); 842 "PAP-8141: busy slot for new buffer");
842 843
843 set_buffer_journal_new(p_s_new_bh); 844 set_buffer_journal_new(new_bh);
844 p_s_tb->FEB[p_s_tb->cur_blknum++] = p_s_new_bh; 845 tb->FEB[tb->cur_blknum++] = new_bh;
845 } 846 }
846 847
847 if (n_retval == CARRY_ON && FILESYSTEM_CHANGED_TB(p_s_tb)) 848 if (retval == CARRY_ON && FILESYSTEM_CHANGED_TB(tb))
848 n_retval = REPEAT_SEARCH; 849 retval = REPEAT_SEARCH;
849 850
850 return n_retval; 851 return retval;
851} 852}
852 853
853/* Get free space of the left neighbor, which is stored in the parent 854/* Get free space of the left neighbor, which is stored in the parent
@@ -895,35 +896,36 @@ static int get_rfree(struct tree_balance *tb, int h)
895} 896}
896 897
897/* Check whether left neighbor is in memory. */ 898/* Check whether left neighbor is in memory. */
898static int is_left_neighbor_in_cache(struct tree_balance *p_s_tb, int n_h) 899static int is_left_neighbor_in_cache(struct tree_balance *tb, int h)
899{ 900{
900 struct buffer_head *p_s_father, *left; 901 struct buffer_head *father, *left;
901 struct super_block *p_s_sb = p_s_tb->tb_sb; 902 struct super_block *sb = tb->tb_sb;
902 b_blocknr_t n_left_neighbor_blocknr; 903 b_blocknr_t left_neighbor_blocknr;
903 int n_left_neighbor_position; 904 int left_neighbor_position;
904 905
905 if (!p_s_tb->FL[n_h]) /* Father of the left neighbor does not exist. */ 906 /* Father of the left neighbor does not exist. */
907 if (!tb->FL[h])
906 return 0; 908 return 0;
907 909
908 /* Calculate father of the node to be balanced. */ 910 /* Calculate father of the node to be balanced. */
909 p_s_father = PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1); 911 father = PATH_H_PBUFFER(tb->tb_path, h + 1);
910 912
911 RFALSE(!p_s_father || 913 RFALSE(!father ||
912 !B_IS_IN_TREE(p_s_father) || 914 !B_IS_IN_TREE(father) ||
913 !B_IS_IN_TREE(p_s_tb->FL[n_h]) || 915 !B_IS_IN_TREE(tb->FL[h]) ||
914 !buffer_uptodate(p_s_father) || 916 !buffer_uptodate(father) ||
915 !buffer_uptodate(p_s_tb->FL[n_h]), 917 !buffer_uptodate(tb->FL[h]),
916 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid", 918 "vs-8165: F[h] (%b) or FL[h] (%b) is invalid",
917 p_s_father, p_s_tb->FL[n_h]); 919 father, tb->FL[h]);
918 920
919 /* Get position of the pointer to the left neighbor into the left father. */ 921 /* Get position of the pointer to the left neighbor into the left father. */
920 n_left_neighbor_position = (p_s_father == p_s_tb->FL[n_h]) ? 922 left_neighbor_position = (father == tb->FL[h]) ?
921 p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb->FL[n_h]); 923 tb->lkey[h] : B_NR_ITEMS(tb->FL[h]);
922 /* Get left neighbor block number. */ 924 /* Get left neighbor block number. */
923 n_left_neighbor_blocknr = 925 left_neighbor_blocknr =
924 B_N_CHILD_NUM(p_s_tb->FL[n_h], n_left_neighbor_position); 926 B_N_CHILD_NUM(tb->FL[h], left_neighbor_position);
925 /* Look for the left neighbor in the cache. */ 927 /* Look for the left neighbor in the cache. */
926 if ((left = sb_find_get_block(p_s_sb, n_left_neighbor_blocknr))) { 928 if ((left = sb_find_get_block(sb, left_neighbor_blocknr))) {
927 929
928 RFALSE(buffer_uptodate(left) && !B_IS_IN_TREE(left), 930 RFALSE(buffer_uptodate(left) && !B_IS_IN_TREE(left),
929 "vs-8170: left neighbor (%b %z) is not in the tree", 931 "vs-8170: left neighbor (%b %z) is not in the tree",
@@ -938,10 +940,10 @@ static int is_left_neighbor_in_cache(struct tree_balance *p_s_tb, int n_h)
938#define LEFT_PARENTS 'l' 940#define LEFT_PARENTS 'l'
939#define RIGHT_PARENTS 'r' 941#define RIGHT_PARENTS 'r'
940 942
941static void decrement_key(struct cpu_key *p_s_key) 943static void decrement_key(struct cpu_key *key)
942{ 944{
943 // call item specific function for this key 945 // call item specific function for this key
944 item_ops[cpu_key_k_type(p_s_key)]->decrement_key(p_s_key); 946 item_ops[cpu_key_k_type(key)]->decrement_key(key);
945} 947}
946 948
947/* Calculate far left/right parent of the left/right neighbor of the current node, that 949/* Calculate far left/right parent of the left/right neighbor of the current node, that
@@ -952,77 +954,77 @@ static void decrement_key(struct cpu_key *p_s_key)
952 SCHEDULE_OCCURRED - schedule occurred while the function worked; 954 SCHEDULE_OCCURRED - schedule occurred while the function worked;
953 * CARRY_ON - schedule didn't occur while the function worked; 955 * CARRY_ON - schedule didn't occur while the function worked;
954 */ 956 */
955static int get_far_parent(struct tree_balance *p_s_tb, 957static int get_far_parent(struct tree_balance *tb,
956 int n_h, 958 int h,
957 struct buffer_head **pp_s_father, 959 struct buffer_head **pfather,
958 struct buffer_head **pp_s_com_father, char c_lr_par) 960 struct buffer_head **pcom_father, char c_lr_par)
959{ 961{
960 struct buffer_head *p_s_parent; 962 struct buffer_head *parent;
961 INITIALIZE_PATH(s_path_to_neighbor_father); 963 INITIALIZE_PATH(s_path_to_neighbor_father);
962 struct treepath *p_s_path = p_s_tb->tb_path; 964 struct treepath *path = tb->tb_path;
963 struct cpu_key s_lr_father_key; 965 struct cpu_key s_lr_father_key;
964 int n_counter, 966 int counter,
965 n_position = INT_MAX, 967 position = INT_MAX,
966 n_first_last_position = 0, 968 first_last_position = 0,
967 n_path_offset = PATH_H_PATH_OFFSET(p_s_path, n_h); 969 path_offset = PATH_H_PATH_OFFSET(path, h);
968 970
969 /* Starting from F[n_h] go upwards in the tree, and look for the common 971 /* Starting from F[h] go upwards in the tree, and look for the common
970 ancestor of F[n_h], and its neighbor l/r, that should be obtained. */ 972 ancestor of F[h], and its neighbor l/r, that should be obtained. */
971 973
972 n_counter = n_path_offset; 974 counter = path_offset;
973 975
974 RFALSE(n_counter < FIRST_PATH_ELEMENT_OFFSET, 976 RFALSE(counter < FIRST_PATH_ELEMENT_OFFSET,
975 "PAP-8180: invalid path length"); 977 "PAP-8180: invalid path length");
976 978
977 for (; n_counter > FIRST_PATH_ELEMENT_OFFSET; n_counter--) { 979 for (; counter > FIRST_PATH_ELEMENT_OFFSET; counter--) {
978 /* Check whether parent of the current buffer in the path is really parent in the tree. */ 980 /* Check whether parent of the current buffer in the path is really parent in the tree. */
979 if (!B_IS_IN_TREE 981 if (!B_IS_IN_TREE
980 (p_s_parent = PATH_OFFSET_PBUFFER(p_s_path, n_counter - 1))) 982 (parent = PATH_OFFSET_PBUFFER(path, counter - 1)))
981 return REPEAT_SEARCH; 983 return REPEAT_SEARCH;
982 /* Check whether position in the parent is correct. */ 984 /* Check whether position in the parent is correct. */
983 if ((n_position = 985 if ((position =
984 PATH_OFFSET_POSITION(p_s_path, 986 PATH_OFFSET_POSITION(path,
985 n_counter - 1)) > 987 counter - 1)) >
986 B_NR_ITEMS(p_s_parent)) 988 B_NR_ITEMS(parent))
987 return REPEAT_SEARCH; 989 return REPEAT_SEARCH;
988 /* Check whether parent at the path really points to the child. */ 990 /* Check whether parent at the path really points to the child. */
989 if (B_N_CHILD_NUM(p_s_parent, n_position) != 991 if (B_N_CHILD_NUM(parent, position) !=
990 PATH_OFFSET_PBUFFER(p_s_path, n_counter)->b_blocknr) 992 PATH_OFFSET_PBUFFER(path, counter)->b_blocknr)
991 return REPEAT_SEARCH; 993 return REPEAT_SEARCH;
992 /* Return delimiting key if position in the parent is not equal to first/last one. */ 994 /* Return delimiting key if position in the parent is not equal to first/last one. */
993 if (c_lr_par == RIGHT_PARENTS) 995 if (c_lr_par == RIGHT_PARENTS)
994 n_first_last_position = B_NR_ITEMS(p_s_parent); 996 first_last_position = B_NR_ITEMS(parent);
995 if (n_position != n_first_last_position) { 997 if (position != first_last_position) {
996 *pp_s_com_father = p_s_parent; 998 *pcom_father = parent;
997 get_bh(*pp_s_com_father); 999 get_bh(*pcom_father);
998 /*(*pp_s_com_father = p_s_parent)->b_count++; */ 1000 /*(*pcom_father = parent)->b_count++; */
999 break; 1001 break;
1000 } 1002 }
1001 } 1003 }
1002 1004
1003 /* if we are in the root of the tree, then there is no common father */ 1005 /* if we are in the root of the tree, then there is no common father */
1004 if (n_counter == FIRST_PATH_ELEMENT_OFFSET) { 1006 if (counter == FIRST_PATH_ELEMENT_OFFSET) {
1005 /* Check whether first buffer in the path is the root of the tree. */ 1007 /* Check whether first buffer in the path is the root of the tree. */
1006 if (PATH_OFFSET_PBUFFER 1008 if (PATH_OFFSET_PBUFFER
1007 (p_s_tb->tb_path, 1009 (tb->tb_path,
1008 FIRST_PATH_ELEMENT_OFFSET)->b_blocknr == 1010 FIRST_PATH_ELEMENT_OFFSET)->b_blocknr ==
1009 SB_ROOT_BLOCK(p_s_tb->tb_sb)) { 1011 SB_ROOT_BLOCK(tb->tb_sb)) {
1010 *pp_s_father = *pp_s_com_father = NULL; 1012 *pfather = *pcom_father = NULL;
1011 return CARRY_ON; 1013 return CARRY_ON;
1012 } 1014 }
1013 return REPEAT_SEARCH; 1015 return REPEAT_SEARCH;
1014 } 1016 }
1015 1017
1016 RFALSE(B_LEVEL(*pp_s_com_father) <= DISK_LEAF_NODE_LEVEL, 1018 RFALSE(B_LEVEL(*pcom_father) <= DISK_LEAF_NODE_LEVEL,
1017 "PAP-8185: (%b %z) level too small", 1019 "PAP-8185: (%b %z) level too small",
1018 *pp_s_com_father, *pp_s_com_father); 1020 *pcom_father, *pcom_father);
1019 1021
1020 /* Check whether the common parent is locked. */ 1022 /* Check whether the common parent is locked. */
1021 1023
1022 if (buffer_locked(*pp_s_com_father)) { 1024 if (buffer_locked(*pcom_father)) {
1023 __wait_on_buffer(*pp_s_com_father); 1025 __wait_on_buffer(*pcom_father);
1024 if (FILESYSTEM_CHANGED_TB(p_s_tb)) { 1026 if (FILESYSTEM_CHANGED_TB(tb)) {
1025 decrement_bcount(*pp_s_com_father); 1027 brelse(*pcom_father);
1026 return REPEAT_SEARCH; 1028 return REPEAT_SEARCH;
1027 } 1029 }
1028 } 1030 }
@@ -1032,128 +1034,131 @@ static int get_far_parent(struct tree_balance *p_s_tb,
1032 1034
1033 /* Form key to get parent of the left/right neighbor. */ 1035 /* Form key to get parent of the left/right neighbor. */
1034 le_key2cpu_key(&s_lr_father_key, 1036 le_key2cpu_key(&s_lr_father_key,
1035 B_N_PDELIM_KEY(*pp_s_com_father, 1037 B_N_PDELIM_KEY(*pcom_father,
1036 (c_lr_par == 1038 (c_lr_par ==
1037 LEFT_PARENTS) ? (p_s_tb->lkey[n_h - 1] = 1039 LEFT_PARENTS) ? (tb->lkey[h - 1] =
1038 n_position - 1040 position -
1039 1) : (p_s_tb->rkey[n_h - 1041 1) : (tb->rkey[h -
1040 1] = 1042 1] =
1041 n_position))); 1043 position)));
1042 1044
1043 if (c_lr_par == LEFT_PARENTS) 1045 if (c_lr_par == LEFT_PARENTS)
1044 decrement_key(&s_lr_father_key); 1046 decrement_key(&s_lr_father_key);
1045 1047
1046 if (search_by_key 1048 if (search_by_key
1047 (p_s_tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father, 1049 (tb->tb_sb, &s_lr_father_key, &s_path_to_neighbor_father,
1048 n_h + 1) == IO_ERROR) 1050 h + 1) == IO_ERROR)
1049 // path is released 1051 // path is released
1050 return IO_ERROR; 1052 return IO_ERROR;
1051 1053
1052 if (FILESYSTEM_CHANGED_TB(p_s_tb)) { 1054 if (FILESYSTEM_CHANGED_TB(tb)) {
1053 decrement_counters_in_path(&s_path_to_neighbor_father); 1055 pathrelse(&s_path_to_neighbor_father);
1054 decrement_bcount(*pp_s_com_father); 1056 brelse(*pcom_father);
1055 return REPEAT_SEARCH; 1057 return REPEAT_SEARCH;
1056 } 1058 }
1057 1059
1058 *pp_s_father = PATH_PLAST_BUFFER(&s_path_to_neighbor_father); 1060 *pfather = PATH_PLAST_BUFFER(&s_path_to_neighbor_father);
1059 1061
1060 RFALSE(B_LEVEL(*pp_s_father) != n_h + 1, 1062 RFALSE(B_LEVEL(*pfather) != h + 1,
1061 "PAP-8190: (%b %z) level too small", *pp_s_father, *pp_s_father); 1063 "PAP-8190: (%b %z) level too small", *pfather, *pfather);
1062 RFALSE(s_path_to_neighbor_father.path_length < 1064 RFALSE(s_path_to_neighbor_father.path_length <
1063 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small"); 1065 FIRST_PATH_ELEMENT_OFFSET, "PAP-8192: path length is too small");
1064 1066
1065 s_path_to_neighbor_father.path_length--; 1067 s_path_to_neighbor_father.path_length--;
1066 decrement_counters_in_path(&s_path_to_neighbor_father); 1068 pathrelse(&s_path_to_neighbor_father);
1067 return CARRY_ON; 1069 return CARRY_ON;
1068} 1070}
1069 1071
1070/* Get parents of neighbors of node in the path(S[n_path_offset]) and common parents of 1072/* Get parents of neighbors of node in the path(S[path_offset]) and common parents of
1071 * S[n_path_offset] and L[n_path_offset]/R[n_path_offset]: F[n_path_offset], FL[n_path_offset], 1073 * S[path_offset] and L[path_offset]/R[path_offset]: F[path_offset], FL[path_offset],
1072 * FR[n_path_offset], CFL[n_path_offset], CFR[n_path_offset]. 1074 * FR[path_offset], CFL[path_offset], CFR[path_offset].
1073 * Calculate numbers of left and right delimiting keys position: lkey[n_path_offset], rkey[n_path_offset]. 1075 * Calculate numbers of left and right delimiting keys position: lkey[path_offset], rkey[path_offset].
1074 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; 1076 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1075 * CARRY_ON - schedule didn't occur while the function worked; 1077 * CARRY_ON - schedule didn't occur while the function worked;
1076 */ 1078 */
1077static int get_parents(struct tree_balance *p_s_tb, int n_h) 1079static int get_parents(struct tree_balance *tb, int h)
1078{ 1080{
1079 struct treepath *p_s_path = p_s_tb->tb_path; 1081 struct treepath *path = tb->tb_path;
1080 int n_position, 1082 int position,
1081 n_ret_value, 1083 ret,
1082 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); 1084 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h);
1083 struct buffer_head *p_s_curf, *p_s_curcf; 1085 struct buffer_head *curf, *curcf;
1084 1086
1085 /* Current node is the root of the tree or will be root of the tree */ 1087 /* Current node is the root of the tree or will be root of the tree */
1086 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) { 1088 if (path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
1087 /* The root can not have parents. 1089 /* The root can not have parents.
1088 Release nodes which previously were obtained as parents of the current node neighbors. */ 1090 Release nodes which previously were obtained as parents of the current node neighbors. */
1089 decrement_bcount(p_s_tb->FL[n_h]); 1091 brelse(tb->FL[h]);
1090 decrement_bcount(p_s_tb->CFL[n_h]); 1092 brelse(tb->CFL[h]);
1091 decrement_bcount(p_s_tb->FR[n_h]); 1093 brelse(tb->FR[h]);
1092 decrement_bcount(p_s_tb->CFR[n_h]); 1094 brelse(tb->CFR[h]);
1093 p_s_tb->FL[n_h] = p_s_tb->CFL[n_h] = p_s_tb->FR[n_h] = 1095 tb->FL[h] = NULL;
1094 p_s_tb->CFR[n_h] = NULL; 1096 tb->CFL[h] = NULL;
1097 tb->FR[h] = NULL;
1098 tb->CFR[h] = NULL;
1095 return CARRY_ON; 1099 return CARRY_ON;
1096 } 1100 }
1097 1101
1098 /* Get parent FL[n_path_offset] of L[n_path_offset]. */ 1102 /* Get parent FL[path_offset] of L[path_offset]. */
1099 if ((n_position = PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1))) { 1103 position = PATH_OFFSET_POSITION(path, path_offset - 1);
1104 if (position) {
1100 /* Current node is not the first child of its parent. */ 1105 /* Current node is not the first child of its parent. */
1101 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */ 1106 curf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1102 p_s_curf = p_s_curcf = 1107 curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1103 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1); 1108 get_bh(curf);
1104 get_bh(p_s_curf); 1109 get_bh(curf);
1105 get_bh(p_s_curf); 1110 tb->lkey[h] = position - 1;
1106 p_s_tb->lkey[n_h] = n_position - 1;
1107 } else { 1111 } else {
1108 /* Calculate current parent of L[n_path_offset], which is the left neighbor of the current node. 1112 /* Calculate current parent of L[path_offset], which is the left neighbor of the current node.
1109 Calculate current common parent of L[n_path_offset] and the current node. Note that 1113 Calculate current common parent of L[path_offset] and the current node. Note that
1110 CFL[n_path_offset] not equal FL[n_path_offset] and CFL[n_path_offset] not equal F[n_path_offset]. 1114 CFL[path_offset] not equal FL[path_offset] and CFL[path_offset] not equal F[path_offset].
1111 Calculate lkey[n_path_offset]. */ 1115 Calculate lkey[path_offset]. */
1112 if ((n_ret_value = get_far_parent(p_s_tb, n_h + 1, &p_s_curf, 1116 if ((ret = get_far_parent(tb, h + 1, &curf,
1113 &p_s_curcf, 1117 &curcf,
1114 LEFT_PARENTS)) != CARRY_ON) 1118 LEFT_PARENTS)) != CARRY_ON)
1115 return n_ret_value; 1119 return ret;
1116 } 1120 }
1117 1121
1118 decrement_bcount(p_s_tb->FL[n_h]); 1122 brelse(tb->FL[h]);
1119 p_s_tb->FL[n_h] = p_s_curf; /* New initialization of FL[n_h]. */ 1123 tb->FL[h] = curf; /* New initialization of FL[h]. */
1120 decrement_bcount(p_s_tb->CFL[n_h]); 1124 brelse(tb->CFL[h]);
1121 p_s_tb->CFL[n_h] = p_s_curcf; /* New initialization of CFL[n_h]. */ 1125 tb->CFL[h] = curcf; /* New initialization of CFL[h]. */
1122 1126
1123 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) || 1127 RFALSE((curf && !B_IS_IN_TREE(curf)) ||
1124 (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)), 1128 (curcf && !B_IS_IN_TREE(curcf)),
1125 "PAP-8195: FL (%b) or CFL (%b) is invalid", p_s_curf, p_s_curcf); 1129 "PAP-8195: FL (%b) or CFL (%b) is invalid", curf, curcf);
1126 1130
1127/* Get parent FR[n_h] of R[n_h]. */ 1131/* Get parent FR[h] of R[h]. */
1128 1132
1129/* Current node is the last child of F[n_h]. FR[n_h] != F[n_h]. */ 1133/* Current node is the last child of F[h]. FR[h] != F[h]. */
1130 if (n_position == B_NR_ITEMS(PATH_H_PBUFFER(p_s_path, n_h + 1))) { 1134 if (position == B_NR_ITEMS(PATH_H_PBUFFER(path, h + 1))) {
1131/* Calculate current parent of R[n_h], which is the right neighbor of F[n_h]. 1135/* Calculate current parent of R[h], which is the right neighbor of F[h].
1132 Calculate current common parent of R[n_h] and current node. Note that CFR[n_h] 1136 Calculate current common parent of R[h] and current node. Note that CFR[h]
1133 not equal FR[n_path_offset] and CFR[n_h] not equal F[n_h]. */ 1137 not equal FR[path_offset] and CFR[h] not equal F[h]. */
1134 if ((n_ret_value = 1138 if ((ret =
1135 get_far_parent(p_s_tb, n_h + 1, &p_s_curf, &p_s_curcf, 1139 get_far_parent(tb, h + 1, &curf, &curcf,
1136 RIGHT_PARENTS)) != CARRY_ON) 1140 RIGHT_PARENTS)) != CARRY_ON)
1137 return n_ret_value; 1141 return ret;
1138 } else { 1142 } else {
1139/* Current node is not the last child of its parent F[n_h]. */ 1143/* Current node is not the last child of its parent F[h]. */
1140 /*(p_s_curf = p_s_curcf = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))->b_count += 2; */ 1144 curf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1141 p_s_curf = p_s_curcf = 1145 curcf = PATH_OFFSET_PBUFFER(path, path_offset - 1);
1142 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1); 1146 get_bh(curf);
1143 get_bh(p_s_curf); 1147 get_bh(curf);
1144 get_bh(p_s_curf); 1148 tb->rkey[h] = position;
1145 p_s_tb->rkey[n_h] = n_position;
1146 } 1149 }
1147 1150
1148 decrement_bcount(p_s_tb->FR[n_h]); 1151 brelse(tb->FR[h]);
1149 p_s_tb->FR[n_h] = p_s_curf; /* New initialization of FR[n_path_offset]. */ 1152 /* New initialization of FR[path_offset]. */
1153 tb->FR[h] = curf;
1150 1154
1151 decrement_bcount(p_s_tb->CFR[n_h]); 1155 brelse(tb->CFR[h]);
1152 p_s_tb->CFR[n_h] = p_s_curcf; /* New initialization of CFR[n_path_offset]. */ 1156 /* New initialization of CFR[path_offset]. */
1157 tb->CFR[h] = curcf;
1153 1158
1154 RFALSE((p_s_curf && !B_IS_IN_TREE(p_s_curf)) || 1159 RFALSE((curf && !B_IS_IN_TREE(curf)) ||
1155 (p_s_curcf && !B_IS_IN_TREE(p_s_curcf)), 1160 (curcf && !B_IS_IN_TREE(curcf)),
1156 "PAP-8205: FR (%b) or CFR (%b) is invalid", p_s_curf, p_s_curcf); 1161 "PAP-8205: FR (%b) or CFR (%b) is invalid", curf, curcf);
1157 1162
1158 return CARRY_ON; 1163 return CARRY_ON;
1159} 1164}
@@ -1203,7 +1208,7 @@ static inline int can_node_be_removed(int mode, int lfree, int sfree, int rfree,
1203 * h current level of the node; 1208 * h current level of the node;
1204 * inum item number in S[h]; 1209 * inum item number in S[h];
1205 * mode i - insert, p - paste; 1210 * mode i - insert, p - paste;
1206 * Returns: 1 - schedule occurred; 1211 * Returns: 1 - schedule occurred;
1207 * 0 - balancing for higher levels needed; 1212 * 0 - balancing for higher levels needed;
1208 * -1 - no balancing for higher levels needed; 1213 * -1 - no balancing for higher levels needed;
1209 * -2 - no disk space. 1214 * -2 - no disk space.
@@ -1217,7 +1222,7 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1217 contains node being balanced. The mnemonic is 1222 contains node being balanced. The mnemonic is
1218 that the attempted change in node space used level 1223 that the attempted change in node space used level
1219 is levbytes bytes. */ 1224 is levbytes bytes. */
1220 n_ret_value; 1225 ret;
1221 1226
1222 int lfree, sfree, rfree /* free space in L, S and R */ ; 1227 int lfree, sfree, rfree /* free space in L, S and R */ ;
1223 1228
@@ -1238,7 +1243,7 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1238 /* we perform 8 calls to get_num_ver(). For each call we calculate five parameters. 1243 /* we perform 8 calls to get_num_ver(). For each call we calculate five parameters.
1239 where 4th parameter is s1bytes and 5th - s2bytes 1244 where 4th parameter is s1bytes and 5th - s2bytes
1240 */ 1245 */
1241 short snum012[40] = { 0, }; /* s0num, s1num, s2num for 8 cases 1246 short snum012[40] = { 0, }; /* s0num, s1num, s2num for 8 cases
1242 0,1 - do not shift and do not shift but bottle 1247 0,1 - do not shift and do not shift but bottle
1243 2 - shift only whole item to left 1248 2 - shift only whole item to left
1244 3 - shift to left and bottle as much as possible 1249 3 - shift to left and bottle as much as possible
@@ -1255,24 +1260,24 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1255 /* Calculate balance parameters for creating new root. */ 1260 /* Calculate balance parameters for creating new root. */
1256 if (!Sh) { 1261 if (!Sh) {
1257 if (!h) 1262 if (!h)
1258 reiserfs_panic(tb->tb_sb, 1263 reiserfs_panic(tb->tb_sb, "vs-8210",
1259 "vs-8210: ip_check_balance: S[0] can not be 0"); 1264 "S[0] can not be 0");
1260 switch (n_ret_value = get_empty_nodes(tb, h)) { 1265 switch (ret = get_empty_nodes(tb, h)) {
1261 case CARRY_ON: 1266 case CARRY_ON:
1262 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1); 1267 set_parameters(tb, h, 0, 0, 1, NULL, -1, -1);
1263 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */ 1268 return NO_BALANCING_NEEDED; /* no balancing for higher levels needed */
1264 1269
1265 case NO_DISK_SPACE: 1270 case NO_DISK_SPACE:
1266 case REPEAT_SEARCH: 1271 case REPEAT_SEARCH:
1267 return n_ret_value; 1272 return ret;
1268 default: 1273 default:
1269 reiserfs_panic(tb->tb_sb, 1274 reiserfs_panic(tb->tb_sb, "vs-8215", "incorrect "
1270 "vs-8215: ip_check_balance: incorrect return value of get_empty_nodes"); 1275 "return value of get_empty_nodes");
1271 } 1276 }
1272 } 1277 }
1273 1278
1274 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) /* get parents of S[h] neighbors. */ 1279 if ((ret = get_parents(tb, h)) != CARRY_ON) /* get parents of S[h] neighbors. */
1275 return n_ret_value; 1280 return ret;
1276 1281
1277 sfree = B_FREE_SPACE(Sh); 1282 sfree = B_FREE_SPACE(Sh);
1278 1283
@@ -1287,7 +1292,7 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1287 1292
1288 create_virtual_node(tb, h); 1293 create_virtual_node(tb, h);
1289 1294
1290 /* 1295 /*
1291 determine maximal number of items we can shift to the left neighbor (in tb structure) 1296 determine maximal number of items we can shift to the left neighbor (in tb structure)
1292 and the maximal number of bytes that can flow to the left neighbor 1297 and the maximal number of bytes that can flow to the left neighbor
1293 from the left most liquid item that cannot be shifted from S[0] entirely (returned value) 1298 from the left most liquid item that cannot be shifted from S[0] entirely (returned value)
@@ -1348,13 +1353,13 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1348 1353
1349 { 1354 {
1350 int lpar, rpar, nset, lset, rset, lrset; 1355 int lpar, rpar, nset, lset, rset, lrset;
1351 /* 1356 /*
1352 * regular overflowing of the node 1357 * regular overflowing of the node
1353 */ 1358 */
1354 1359
1355 /* get_num_ver works in 2 modes (FLOW & NO_FLOW) 1360 /* get_num_ver works in 2 modes (FLOW & NO_FLOW)
1356 lpar, rpar - number of items we can shift to left/right neighbor (including splitting item) 1361 lpar, rpar - number of items we can shift to left/right neighbor (including splitting item)
1357 nset, lset, rset, lrset - shows, whether flowing items give better packing 1362 nset, lset, rset, lrset - shows, whether flowing items give better packing
1358 */ 1363 */
1359#define FLOW 1 1364#define FLOW 1
1360#define NO_FLOW 0 /* do not any splitting */ 1365#define NO_FLOW 0 /* do not any splitting */
@@ -1544,7 +1549,7 @@ static int ip_check_balance(struct tree_balance *tb, int h)
1544 * h current level of the node; 1549 * h current level of the node;
1545 * inum item number in S[h]; 1550 * inum item number in S[h];
1546 * mode i - insert, p - paste; 1551 * mode i - insert, p - paste;
1547 * Returns: 1 - schedule occurred; 1552 * Returns: 1 - schedule occurred;
1548 * 0 - balancing for higher levels needed; 1553 * 0 - balancing for higher levels needed;
1549 * -1 - no balancing for higher levels needed; 1554 * -1 - no balancing for higher levels needed;
1550 * -2 - no disk space. 1555 * -2 - no disk space.
@@ -1559,7 +1564,7 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h)
1559 /* Sh is the node whose balance is currently being checked, 1564 /* Sh is the node whose balance is currently being checked,
1560 and Fh is its father. */ 1565 and Fh is its father. */
1561 struct buffer_head *Sh, *Fh; 1566 struct buffer_head *Sh, *Fh;
1562 int maxsize, n_ret_value; 1567 int maxsize, ret;
1563 int lfree, rfree /* free space in L and R */ ; 1568 int lfree, rfree /* free space in L and R */ ;
1564 1569
1565 Sh = PATH_H_PBUFFER(tb->tb_path, h); 1570 Sh = PATH_H_PBUFFER(tb->tb_path, h);
@@ -1584,8 +1589,8 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h)
1584 return CARRY_ON; 1589 return CARRY_ON;
1585 } 1590 }
1586 1591
1587 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) 1592 if ((ret = get_parents(tb, h)) != CARRY_ON)
1588 return n_ret_value; 1593 return ret;
1589 1594
1590 /* get free space of neighbors */ 1595 /* get free space of neighbors */
1591 rfree = get_rfree(tb, h); 1596 rfree = get_rfree(tb, h);
@@ -1727,7 +1732,7 @@ static int dc_check_balance_internal(struct tree_balance *tb, int h)
1727 * h current level of the node; 1732 * h current level of the node;
1728 * inum item number in S[h]; 1733 * inum item number in S[h];
1729 * mode i - insert, p - paste; 1734 * mode i - insert, p - paste;
1730 * Returns: 1 - schedule occurred; 1735 * Returns: 1 - schedule occurred;
1731 * 0 - balancing for higher levels needed; 1736 * 0 - balancing for higher levels needed;
1732 * -1 - no balancing for higher levels needed; 1737 * -1 - no balancing for higher levels needed;
1733 * -2 - no disk space. 1738 * -2 - no disk space.
@@ -1742,7 +1747,7 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h)
1742 attempted change in node space used level is levbytes bytes. */ 1747 attempted change in node space used level is levbytes bytes. */
1743 int levbytes; 1748 int levbytes;
1744 /* the maximal item size */ 1749 /* the maximal item size */
1745 int maxsize, n_ret_value; 1750 int maxsize, ret;
1746 /* S0 is the node whose balance is currently being checked, 1751 /* S0 is the node whose balance is currently being checked,
1747 and F0 is its father. */ 1752 and F0 is its father. */
1748 struct buffer_head *S0, *F0; 1753 struct buffer_head *S0, *F0;
@@ -1764,8 +1769,8 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h)
1764 return NO_BALANCING_NEEDED; 1769 return NO_BALANCING_NEEDED;
1765 } 1770 }
1766 1771
1767 if ((n_ret_value = get_parents(tb, h)) != CARRY_ON) 1772 if ((ret = get_parents(tb, h)) != CARRY_ON)
1768 return n_ret_value; 1773 return ret;
1769 1774
1770 /* get free space of neighbors */ 1775 /* get free space of neighbors */
1771 rfree = get_rfree(tb, h); 1776 rfree = get_rfree(tb, h);
@@ -1821,7 +1826,7 @@ static int dc_check_balance_leaf(struct tree_balance *tb, int h)
1821 * h current level of the node; 1826 * h current level of the node;
1822 * inum item number in S[h]; 1827 * inum item number in S[h];
1823 * mode d - delete, c - cut. 1828 * mode d - delete, c - cut.
1824 * Returns: 1 - schedule occurred; 1829 * Returns: 1 - schedule occurred;
1825 * 0 - balancing for higher levels needed; 1830 * 0 - balancing for higher levels needed;
1826 * -1 - no balancing for higher levels needed; 1831 * -1 - no balancing for higher levels needed;
1827 * -2 - no disk space. 1832 * -2 - no disk space.
@@ -1850,7 +1855,7 @@ static int dc_check_balance(struct tree_balance *tb, int h)
1850 * h current level of the node; 1855 * h current level of the node;
1851 * inum item number in S[h]; 1856 * inum item number in S[h];
1852 * mode i - insert, p - paste, d - delete, c - cut. 1857 * mode i - insert, p - paste, d - delete, c - cut.
1853 * Returns: 1 - schedule occurred; 1858 * Returns: 1 - schedule occurred;
1854 * 0 - balancing for higher levels needed; 1859 * 0 - balancing for higher levels needed;
1855 * -1 - no balancing for higher levels needed; 1860 * -1 - no balancing for higher levels needed;
1856 * -2 - no disk space. 1861 * -2 - no disk space.
@@ -1884,137 +1889,138 @@ static int check_balance(int mode,
1884} 1889}
1885 1890
1886/* Check whether parent at the path is the really parent of the current node.*/ 1891/* Check whether parent at the path is the really parent of the current node.*/
1887static int get_direct_parent(struct tree_balance *p_s_tb, int n_h) 1892static int get_direct_parent(struct tree_balance *tb, int h)
1888{ 1893{
1889 struct buffer_head *p_s_bh; 1894 struct buffer_head *bh;
1890 struct treepath *p_s_path = p_s_tb->tb_path; 1895 struct treepath *path = tb->tb_path;
1891 int n_position, 1896 int position,
1892 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h); 1897 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h);
1893 1898
1894 /* We are in the root or in the new root. */ 1899 /* We are in the root or in the new root. */
1895 if (n_path_offset <= FIRST_PATH_ELEMENT_OFFSET) { 1900 if (path_offset <= FIRST_PATH_ELEMENT_OFFSET) {
1896 1901
1897 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET - 1, 1902 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET - 1,
1898 "PAP-8260: invalid offset in the path"); 1903 "PAP-8260: invalid offset in the path");
1899 1904
1900 if (PATH_OFFSET_PBUFFER(p_s_path, FIRST_PATH_ELEMENT_OFFSET)-> 1905 if (PATH_OFFSET_PBUFFER(path, FIRST_PATH_ELEMENT_OFFSET)->
1901 b_blocknr == SB_ROOT_BLOCK(p_s_tb->tb_sb)) { 1906 b_blocknr == SB_ROOT_BLOCK(tb->tb_sb)) {
1902 /* Root is not changed. */ 1907 /* Root is not changed. */
1903 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1) = NULL; 1908 PATH_OFFSET_PBUFFER(path, path_offset - 1) = NULL;
1904 PATH_OFFSET_POSITION(p_s_path, n_path_offset - 1) = 0; 1909 PATH_OFFSET_POSITION(path, path_offset - 1) = 0;
1905 return CARRY_ON; 1910 return CARRY_ON;
1906 } 1911 }
1907 return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */ 1912 return REPEAT_SEARCH; /* Root is changed and we must recalculate the path. */
1908 } 1913 }
1909 1914
1910 if (!B_IS_IN_TREE 1915 if (!B_IS_IN_TREE
1911 (p_s_bh = PATH_OFFSET_PBUFFER(p_s_path, n_path_offset - 1))) 1916 (bh = PATH_OFFSET_PBUFFER(path, path_offset - 1)))
1912 return REPEAT_SEARCH; /* Parent in the path is not in the tree. */ 1917 return REPEAT_SEARCH; /* Parent in the path is not in the tree. */
1913 1918
1914 if ((n_position = 1919 if ((position =
1915 PATH_OFFSET_POSITION(p_s_path, 1920 PATH_OFFSET_POSITION(path,
1916 n_path_offset - 1)) > B_NR_ITEMS(p_s_bh)) 1921 path_offset - 1)) > B_NR_ITEMS(bh))
1917 return REPEAT_SEARCH; 1922 return REPEAT_SEARCH;
1918 1923
1919 if (B_N_CHILD_NUM(p_s_bh, n_position) != 1924 if (B_N_CHILD_NUM(bh, position) !=
1920 PATH_OFFSET_PBUFFER(p_s_path, n_path_offset)->b_blocknr) 1925 PATH_OFFSET_PBUFFER(path, path_offset)->b_blocknr)
1921 /* Parent in the path is not parent of the current node in the tree. */ 1926 /* Parent in the path is not parent of the current node in the tree. */
1922 return REPEAT_SEARCH; 1927 return REPEAT_SEARCH;
1923 1928
1924 if (buffer_locked(p_s_bh)) { 1929 if (buffer_locked(bh)) {
1925 __wait_on_buffer(p_s_bh); 1930 __wait_on_buffer(bh);
1926 if (FILESYSTEM_CHANGED_TB(p_s_tb)) 1931 if (FILESYSTEM_CHANGED_TB(tb))
1927 return REPEAT_SEARCH; 1932 return REPEAT_SEARCH;
1928 } 1933 }
1929 1934
1930 return CARRY_ON; /* Parent in the path is unlocked and really parent of the current node. */ 1935 return CARRY_ON; /* Parent in the path is unlocked and really parent of the current node. */
1931} 1936}
1932 1937
1933/* Using lnum[n_h] and rnum[n_h] we should determine what neighbors 1938/* Using lnum[h] and rnum[h] we should determine what neighbors
1934 * of S[n_h] we 1939 * of S[h] we
1935 * need in order to balance S[n_h], and get them if necessary. 1940 * need in order to balance S[h], and get them if necessary.
1936 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked; 1941 * Returns: SCHEDULE_OCCURRED - schedule occurred while the function worked;
1937 * CARRY_ON - schedule didn't occur while the function worked; 1942 * CARRY_ON - schedule didn't occur while the function worked;
1938 */ 1943 */
1939static int get_neighbors(struct tree_balance *p_s_tb, int n_h) 1944static int get_neighbors(struct tree_balance *tb, int h)
1940{ 1945{
1941 int n_child_position, 1946 int child_position,
1942 n_path_offset = PATH_H_PATH_OFFSET(p_s_tb->tb_path, n_h + 1); 1947 path_offset = PATH_H_PATH_OFFSET(tb->tb_path, h + 1);
1943 unsigned long n_son_number; 1948 unsigned long son_number;
1944 struct super_block *p_s_sb = p_s_tb->tb_sb; 1949 struct super_block *sb = tb->tb_sb;
1945 struct buffer_head *p_s_bh; 1950 struct buffer_head *bh;
1946 1951
1947 PROC_INFO_INC(p_s_sb, get_neighbors[n_h]); 1952 PROC_INFO_INC(sb, get_neighbors[h]);
1948 1953
1949 if (p_s_tb->lnum[n_h]) { 1954 if (tb->lnum[h]) {
1950 /* We need left neighbor to balance S[n_h]. */ 1955 /* We need left neighbor to balance S[h]. */
1951 PROC_INFO_INC(p_s_sb, need_l_neighbor[n_h]); 1956 PROC_INFO_INC(sb, need_l_neighbor[h]);
1952 p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset); 1957 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset);
1953 1958
1954 RFALSE(p_s_bh == p_s_tb->FL[n_h] && 1959 RFALSE(bh == tb->FL[h] &&
1955 !PATH_OFFSET_POSITION(p_s_tb->tb_path, n_path_offset), 1960 !PATH_OFFSET_POSITION(tb->tb_path, path_offset),
1956 "PAP-8270: invalid position in the parent"); 1961 "PAP-8270: invalid position in the parent");
1957 1962
1958 n_child_position = 1963 child_position =
1959 (p_s_bh == 1964 (bh ==
1960 p_s_tb->FL[n_h]) ? p_s_tb->lkey[n_h] : B_NR_ITEMS(p_s_tb-> 1965 tb->FL[h]) ? tb->lkey[h] : B_NR_ITEMS(tb->
1961 FL[n_h]); 1966 FL[h]);
1962 n_son_number = B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position); 1967 son_number = B_N_CHILD_NUM(tb->FL[h], child_position);
1963 p_s_bh = sb_bread(p_s_sb, n_son_number); 1968 bh = sb_bread(sb, son_number);
1964 if (!p_s_bh) 1969 if (!bh)
1965 return IO_ERROR; 1970 return IO_ERROR;
1966 if (FILESYSTEM_CHANGED_TB(p_s_tb)) { 1971 if (FILESYSTEM_CHANGED_TB(tb)) {
1967 decrement_bcount(p_s_bh); 1972 brelse(bh);
1968 PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]); 1973 PROC_INFO_INC(sb, get_neighbors_restart[h]);
1969 return REPEAT_SEARCH; 1974 return REPEAT_SEARCH;
1970 } 1975 }
1971 1976
1972 RFALSE(!B_IS_IN_TREE(p_s_tb->FL[n_h]) || 1977 RFALSE(!B_IS_IN_TREE(tb->FL[h]) ||
1973 n_child_position > B_NR_ITEMS(p_s_tb->FL[n_h]) || 1978 child_position > B_NR_ITEMS(tb->FL[h]) ||
1974 B_N_CHILD_NUM(p_s_tb->FL[n_h], n_child_position) != 1979 B_N_CHILD_NUM(tb->FL[h], child_position) !=
1975 p_s_bh->b_blocknr, "PAP-8275: invalid parent"); 1980 bh->b_blocknr, "PAP-8275: invalid parent");
1976 RFALSE(!B_IS_IN_TREE(p_s_bh), "PAP-8280: invalid child"); 1981 RFALSE(!B_IS_IN_TREE(bh), "PAP-8280: invalid child");
1977 RFALSE(!n_h && 1982 RFALSE(!h &&
1978 B_FREE_SPACE(p_s_bh) != 1983 B_FREE_SPACE(bh) !=
1979 MAX_CHILD_SIZE(p_s_bh) - 1984 MAX_CHILD_SIZE(bh) -
1980 dc_size(B_N_CHILD(p_s_tb->FL[0], n_child_position)), 1985 dc_size(B_N_CHILD(tb->FL[0], child_position)),
1981 "PAP-8290: invalid child size of left neighbor"); 1986 "PAP-8290: invalid child size of left neighbor");
1982 1987
1983 decrement_bcount(p_s_tb->L[n_h]); 1988 brelse(tb->L[h]);
1984 p_s_tb->L[n_h] = p_s_bh; 1989 tb->L[h] = bh;
1985 } 1990 }
1986 1991
1987 if (p_s_tb->rnum[n_h]) { /* We need right neighbor to balance S[n_path_offset]. */ 1992 /* We need right neighbor to balance S[path_offset]. */
1988 PROC_INFO_INC(p_s_sb, need_r_neighbor[n_h]); 1993 if (tb->rnum[h]) { /* We need right neighbor to balance S[path_offset]. */
1989 p_s_bh = PATH_OFFSET_PBUFFER(p_s_tb->tb_path, n_path_offset); 1994 PROC_INFO_INC(sb, need_r_neighbor[h]);
1995 bh = PATH_OFFSET_PBUFFER(tb->tb_path, path_offset);
1990 1996
1991 RFALSE(p_s_bh == p_s_tb->FR[n_h] && 1997 RFALSE(bh == tb->FR[h] &&
1992 PATH_OFFSET_POSITION(p_s_tb->tb_path, 1998 PATH_OFFSET_POSITION(tb->tb_path,
1993 n_path_offset) >= 1999 path_offset) >=
1994 B_NR_ITEMS(p_s_bh), 2000 B_NR_ITEMS(bh),
1995 "PAP-8295: invalid position in the parent"); 2001 "PAP-8295: invalid position in the parent");
1996 2002
1997 n_child_position = 2003 child_position =
1998 (p_s_bh == p_s_tb->FR[n_h]) ? p_s_tb->rkey[n_h] + 1 : 0; 2004 (bh == tb->FR[h]) ? tb->rkey[h] + 1 : 0;
1999 n_son_number = B_N_CHILD_NUM(p_s_tb->FR[n_h], n_child_position); 2005 son_number = B_N_CHILD_NUM(tb->FR[h], child_position);
2000 p_s_bh = sb_bread(p_s_sb, n_son_number); 2006 bh = sb_bread(sb, son_number);
2001 if (!p_s_bh) 2007 if (!bh)
2002 return IO_ERROR; 2008 return IO_ERROR;
2003 if (FILESYSTEM_CHANGED_TB(p_s_tb)) { 2009 if (FILESYSTEM_CHANGED_TB(tb)) {
2004 decrement_bcount(p_s_bh); 2010 brelse(bh);
2005 PROC_INFO_INC(p_s_sb, get_neighbors_restart[n_h]); 2011 PROC_INFO_INC(sb, get_neighbors_restart[h]);
2006 return REPEAT_SEARCH; 2012 return REPEAT_SEARCH;
2007 } 2013 }
2008 decrement_bcount(p_s_tb->R[n_h]); 2014 brelse(tb->R[h]);
2009 p_s_tb->R[n_h] = p_s_bh; 2015 tb->R[h] = bh;
2010 2016
2011 RFALSE(!n_h 2017 RFALSE(!h
2012 && B_FREE_SPACE(p_s_bh) != 2018 && B_FREE_SPACE(bh) !=
2013 MAX_CHILD_SIZE(p_s_bh) - 2019 MAX_CHILD_SIZE(bh) -
2014 dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position)), 2020 dc_size(B_N_CHILD(tb->FR[0], child_position)),
2015 "PAP-8300: invalid child size of right neighbor (%d != %d - %d)", 2021 "PAP-8300: invalid child size of right neighbor (%d != %d - %d)",
2016 B_FREE_SPACE(p_s_bh), MAX_CHILD_SIZE(p_s_bh), 2022 B_FREE_SPACE(bh), MAX_CHILD_SIZE(bh),
2017 dc_size(B_N_CHILD(p_s_tb->FR[0], n_child_position))); 2023 dc_size(B_N_CHILD(tb->FR[0], child_position)));
2018 2024
2019 } 2025 }
2020 return CARRY_ON; 2026 return CARRY_ON;
@@ -2088,52 +2094,46 @@ static int get_mem_for_virtual_node(struct tree_balance *tb)
2088} 2094}
2089 2095
2090#ifdef CONFIG_REISERFS_CHECK 2096#ifdef CONFIG_REISERFS_CHECK
2091static void tb_buffer_sanity_check(struct super_block *p_s_sb, 2097static void tb_buffer_sanity_check(struct super_block *sb,
2092 struct buffer_head *p_s_bh, 2098 struct buffer_head *bh,
2093 const char *descr, int level) 2099 const char *descr, int level)
2094{ 2100{
2095 if (p_s_bh) { 2101 if (bh) {
2096 if (atomic_read(&(p_s_bh->b_count)) <= 0) { 2102 if (atomic_read(&(bh->b_count)) <= 0)
2097 2103
2098 reiserfs_panic(p_s_sb, 2104 reiserfs_panic(sb, "jmacd-1", "negative or zero "
2099 "jmacd-1: tb_buffer_sanity_check(): negative or zero reference counter for buffer %s[%d] (%b)\n", 2105 "reference counter for buffer %s[%d] "
2100 descr, level, p_s_bh); 2106 "(%b)", descr, level, bh);
2101 } 2107
2102 2108 if (!buffer_uptodate(bh))
2103 if (!buffer_uptodate(p_s_bh)) { 2109 reiserfs_panic(sb, "jmacd-2", "buffer is not up "
2104 reiserfs_panic(p_s_sb, 2110 "to date %s[%d] (%b)",
2105 "jmacd-2: tb_buffer_sanity_check(): buffer is not up to date %s[%d] (%b)\n", 2111 descr, level, bh);
2106 descr, level, p_s_bh); 2112
2107 } 2113 if (!B_IS_IN_TREE(bh))
2108 2114 reiserfs_panic(sb, "jmacd-3", "buffer is not "
2109 if (!B_IS_IN_TREE(p_s_bh)) { 2115 "in tree %s[%d] (%b)",
2110 reiserfs_panic(p_s_sb, 2116 descr, level, bh);
2111 "jmacd-3: tb_buffer_sanity_check(): buffer is not in tree %s[%d] (%b)\n", 2117
2112 descr, level, p_s_bh); 2118 if (bh->b_bdev != sb->s_bdev)
2113 } 2119 reiserfs_panic(sb, "jmacd-4", "buffer has wrong "
2114 2120 "device %s[%d] (%b)",
2115 if (p_s_bh->b_bdev != p_s_sb->s_bdev) { 2121 descr, level, bh);
2116 reiserfs_panic(p_s_sb, 2122
2117 "jmacd-4: tb_buffer_sanity_check(): buffer has wrong device %s[%d] (%b)\n", 2123 if (bh->b_size != sb->s_blocksize)
2118 descr, level, p_s_bh); 2124 reiserfs_panic(sb, "jmacd-5", "buffer has wrong "
2119 } 2125 "blocksize %s[%d] (%b)",
2120 2126 descr, level, bh);
2121 if (p_s_bh->b_size != p_s_sb->s_blocksize) { 2127
2122 reiserfs_panic(p_s_sb, 2128 if (bh->b_blocknr > SB_BLOCK_COUNT(sb))
2123 "jmacd-5: tb_buffer_sanity_check(): buffer has wrong blocksize %s[%d] (%b)\n", 2129 reiserfs_panic(sb, "jmacd-6", "buffer block "
2124 descr, level, p_s_bh); 2130 "number too high %s[%d] (%b)",
2125 } 2131 descr, level, bh);
2126
2127 if (p_s_bh->b_blocknr > SB_BLOCK_COUNT(p_s_sb)) {
2128 reiserfs_panic(p_s_sb,
2129 "jmacd-6: tb_buffer_sanity_check(): buffer block number too high %s[%d] (%b)\n",
2130 descr, level, p_s_bh);
2131 }
2132 } 2132 }
2133} 2133}
2134#else 2134#else
2135static void tb_buffer_sanity_check(struct super_block *p_s_sb, 2135static void tb_buffer_sanity_check(struct super_block *sb,
2136 struct buffer_head *p_s_bh, 2136 struct buffer_head *bh,
2137 const char *descr, int level) 2137 const char *descr, int level)
2138{; 2138{;
2139} 2139}
@@ -2144,7 +2144,7 @@ static int clear_all_dirty_bits(struct super_block *s, struct buffer_head *bh)
2144 return reiserfs_prepare_for_journal(s, bh, 0); 2144 return reiserfs_prepare_for_journal(s, bh, 0);
2145} 2145}
2146 2146
2147static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb) 2147static int wait_tb_buffers_until_unlocked(struct tree_balance *tb)
2148{ 2148{
2149 struct buffer_head *locked; 2149 struct buffer_head *locked;
2150#ifdef CONFIG_REISERFS_CHECK 2150#ifdef CONFIG_REISERFS_CHECK
@@ -2156,95 +2156,94 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb)
2156 2156
2157 locked = NULL; 2157 locked = NULL;
2158 2158
2159 for (i = p_s_tb->tb_path->path_length; 2159 for (i = tb->tb_path->path_length;
2160 !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i--) { 2160 !locked && i > ILLEGAL_PATH_ELEMENT_OFFSET; i--) {
2161 if (PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) { 2161 if (PATH_OFFSET_PBUFFER(tb->tb_path, i)) {
2162 /* if I understand correctly, we can only be sure the last buffer 2162 /* if I understand correctly, we can only be sure the last buffer
2163 ** in the path is in the tree --clm 2163 ** in the path is in the tree --clm
2164 */ 2164 */
2165#ifdef CONFIG_REISERFS_CHECK 2165#ifdef CONFIG_REISERFS_CHECK
2166 if (PATH_PLAST_BUFFER(p_s_tb->tb_path) == 2166 if (PATH_PLAST_BUFFER(tb->tb_path) ==
2167 PATH_OFFSET_PBUFFER(p_s_tb->tb_path, i)) { 2167 PATH_OFFSET_PBUFFER(tb->tb_path, i))
2168 tb_buffer_sanity_check(p_s_tb->tb_sb, 2168 tb_buffer_sanity_check(tb->tb_sb,
2169 PATH_OFFSET_PBUFFER 2169 PATH_OFFSET_PBUFFER
2170 (p_s_tb->tb_path, 2170 (tb->tb_path,
2171 i), "S", 2171 i), "S",
2172 p_s_tb->tb_path-> 2172 tb->tb_path->
2173 path_length - i); 2173 path_length - i);
2174 }
2175#endif 2174#endif
2176 if (!clear_all_dirty_bits(p_s_tb->tb_sb, 2175 if (!clear_all_dirty_bits(tb->tb_sb,
2177 PATH_OFFSET_PBUFFER 2176 PATH_OFFSET_PBUFFER
2178 (p_s_tb->tb_path, 2177 (tb->tb_path,
2179 i))) { 2178 i))) {
2180 locked = 2179 locked =
2181 PATH_OFFSET_PBUFFER(p_s_tb->tb_path, 2180 PATH_OFFSET_PBUFFER(tb->tb_path,
2182 i); 2181 i);
2183 } 2182 }
2184 } 2183 }
2185 } 2184 }
2186 2185
2187 for (i = 0; !locked && i < MAX_HEIGHT && p_s_tb->insert_size[i]; 2186 for (i = 0; !locked && i < MAX_HEIGHT && tb->insert_size[i];
2188 i++) { 2187 i++) {
2189 2188
2190 if (p_s_tb->lnum[i]) { 2189 if (tb->lnum[i]) {
2191 2190
2192 if (p_s_tb->L[i]) { 2191 if (tb->L[i]) {
2193 tb_buffer_sanity_check(p_s_tb->tb_sb, 2192 tb_buffer_sanity_check(tb->tb_sb,
2194 p_s_tb->L[i], 2193 tb->L[i],
2195 "L", i); 2194 "L", i);
2196 if (!clear_all_dirty_bits 2195 if (!clear_all_dirty_bits
2197 (p_s_tb->tb_sb, p_s_tb->L[i])) 2196 (tb->tb_sb, tb->L[i]))
2198 locked = p_s_tb->L[i]; 2197 locked = tb->L[i];
2199 } 2198 }
2200 2199
2201 if (!locked && p_s_tb->FL[i]) { 2200 if (!locked && tb->FL[i]) {
2202 tb_buffer_sanity_check(p_s_tb->tb_sb, 2201 tb_buffer_sanity_check(tb->tb_sb,
2203 p_s_tb->FL[i], 2202 tb->FL[i],
2204 "FL", i); 2203 "FL", i);
2205 if (!clear_all_dirty_bits 2204 if (!clear_all_dirty_bits
2206 (p_s_tb->tb_sb, p_s_tb->FL[i])) 2205 (tb->tb_sb, tb->FL[i]))
2207 locked = p_s_tb->FL[i]; 2206 locked = tb->FL[i];
2208 } 2207 }
2209 2208
2210 if (!locked && p_s_tb->CFL[i]) { 2209 if (!locked && tb->CFL[i]) {
2211 tb_buffer_sanity_check(p_s_tb->tb_sb, 2210 tb_buffer_sanity_check(tb->tb_sb,
2212 p_s_tb->CFL[i], 2211 tb->CFL[i],
2213 "CFL", i); 2212 "CFL", i);
2214 if (!clear_all_dirty_bits 2213 if (!clear_all_dirty_bits
2215 (p_s_tb->tb_sb, p_s_tb->CFL[i])) 2214 (tb->tb_sb, tb->CFL[i]))
2216 locked = p_s_tb->CFL[i]; 2215 locked = tb->CFL[i];
2217 } 2216 }
2218 2217
2219 } 2218 }
2220 2219
2221 if (!locked && (p_s_tb->rnum[i])) { 2220 if (!locked && (tb->rnum[i])) {
2222 2221
2223 if (p_s_tb->R[i]) { 2222 if (tb->R[i]) {
2224 tb_buffer_sanity_check(p_s_tb->tb_sb, 2223 tb_buffer_sanity_check(tb->tb_sb,
2225 p_s_tb->R[i], 2224 tb->R[i],
2226 "R", i); 2225 "R", i);
2227 if (!clear_all_dirty_bits 2226 if (!clear_all_dirty_bits
2228 (p_s_tb->tb_sb, p_s_tb->R[i])) 2227 (tb->tb_sb, tb->R[i]))
2229 locked = p_s_tb->R[i]; 2228 locked = tb->R[i];
2230 } 2229 }
2231 2230
2232 if (!locked && p_s_tb->FR[i]) { 2231 if (!locked && tb->FR[i]) {
2233 tb_buffer_sanity_check(p_s_tb->tb_sb, 2232 tb_buffer_sanity_check(tb->tb_sb,
2234 p_s_tb->FR[i], 2233 tb->FR[i],
2235 "FR", i); 2234 "FR", i);
2236 if (!clear_all_dirty_bits 2235 if (!clear_all_dirty_bits
2237 (p_s_tb->tb_sb, p_s_tb->FR[i])) 2236 (tb->tb_sb, tb->FR[i]))
2238 locked = p_s_tb->FR[i]; 2237 locked = tb->FR[i];
2239 } 2238 }
2240 2239
2241 if (!locked && p_s_tb->CFR[i]) { 2240 if (!locked && tb->CFR[i]) {
2242 tb_buffer_sanity_check(p_s_tb->tb_sb, 2241 tb_buffer_sanity_check(tb->tb_sb,
2243 p_s_tb->CFR[i], 2242 tb->CFR[i],
2244 "CFR", i); 2243 "CFR", i);
2245 if (!clear_all_dirty_bits 2244 if (!clear_all_dirty_bits
2246 (p_s_tb->tb_sb, p_s_tb->CFR[i])) 2245 (tb->tb_sb, tb->CFR[i]))
2247 locked = p_s_tb->CFR[i]; 2246 locked = tb->CFR[i];
2248 } 2247 }
2249 } 2248 }
2250 } 2249 }
@@ -2257,10 +2256,10 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb)
2257 ** --clm 2256 ** --clm
2258 */ 2257 */
2259 for (i = 0; !locked && i < MAX_FEB_SIZE; i++) { 2258 for (i = 0; !locked && i < MAX_FEB_SIZE; i++) {
2260 if (p_s_tb->FEB[i]) { 2259 if (tb->FEB[i]) {
2261 if (!clear_all_dirty_bits 2260 if (!clear_all_dirty_bits
2262 (p_s_tb->tb_sb, p_s_tb->FEB[i])) 2261 (tb->tb_sb, tb->FEB[i]))
2263 locked = p_s_tb->FEB[i]; 2262 locked = tb->FEB[i];
2264 } 2263 }
2265 } 2264 }
2266 2265
@@ -2268,21 +2267,20 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb)
2268#ifdef CONFIG_REISERFS_CHECK 2267#ifdef CONFIG_REISERFS_CHECK
2269 repeat_counter++; 2268 repeat_counter++;
2270 if ((repeat_counter % 10000) == 0) { 2269 if ((repeat_counter % 10000) == 0) {
2271 reiserfs_warning(p_s_tb->tb_sb, 2270 reiserfs_warning(tb->tb_sb, "reiserfs-8200",
2272 "wait_tb_buffers_until_released(): too many " 2271 "too many iterations waiting "
2273 "iterations waiting for buffer to unlock " 2272 "for buffer to unlock "
2274 "(%b)", locked); 2273 "(%b)", locked);
2275 2274
2276 /* Don't loop forever. Try to recover from possible error. */ 2275 /* Don't loop forever. Try to recover from possible error. */
2277 2276
2278 return (FILESYSTEM_CHANGED_TB(p_s_tb)) ? 2277 return (FILESYSTEM_CHANGED_TB(tb)) ?
2279 REPEAT_SEARCH : CARRY_ON; 2278 REPEAT_SEARCH : CARRY_ON;
2280 } 2279 }
2281#endif 2280#endif
2282 __wait_on_buffer(locked); 2281 __wait_on_buffer(locked);
2283 if (FILESYSTEM_CHANGED_TB(p_s_tb)) { 2282 if (FILESYSTEM_CHANGED_TB(tb))
2284 return REPEAT_SEARCH; 2283 return REPEAT_SEARCH;
2285 }
2286 } 2284 }
2287 2285
2288 } while (locked); 2286 } while (locked);
@@ -2295,15 +2293,15 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb)
2295 * analyze what and where should be moved; 2293 * analyze what and where should be moved;
2296 * get sufficient number of new nodes; 2294 * get sufficient number of new nodes;
2297 * Balancing will start only after all resources will be collected at a time. 2295 * Balancing will start only after all resources will be collected at a time.
2298 * 2296 *
2299 * When ported to SMP kernels, only at the last moment after all needed nodes 2297 * When ported to SMP kernels, only at the last moment after all needed nodes
2300 * are collected in cache, will the resources be locked using the usual 2298 * are collected in cache, will the resources be locked using the usual
2301 * textbook ordered lock acquisition algorithms. Note that ensuring that 2299 * textbook ordered lock acquisition algorithms. Note that ensuring that
2302 * this code neither write locks what it does not need to write lock nor locks out of order 2300 * this code neither write locks what it does not need to write lock nor locks out of order
2303 * will be a pain in the butt that could have been avoided. Grumble grumble. -Hans 2301 * will be a pain in the butt that could have been avoided. Grumble grumble. -Hans
2304 * 2302 *
2305 * fix is meant in the sense of render unchanging 2303 * fix is meant in the sense of render unchanging
2306 * 2304 *
2307 * Latency might be improved by first gathering a list of what buffers are needed 2305 * Latency might be improved by first gathering a list of what buffers are needed
2308 * and then getting as many of them in parallel as possible? -Hans 2306 * and then getting as many of them in parallel as possible? -Hans
2309 * 2307 *
@@ -2312,159 +2310,160 @@ static int wait_tb_buffers_until_unlocked(struct tree_balance *p_s_tb)
2312 * tb tree_balance structure; 2310 * tb tree_balance structure;
2313 * inum item number in S[h]; 2311 * inum item number in S[h];
2314 * pos_in_item - comment this if you can 2312 * pos_in_item - comment this if you can
2315 * ins_ih & ins_sd are used when inserting 2313 * ins_ih item head of item being inserted
2314 * data inserted item or data to be pasted
2316 * Returns: 1 - schedule occurred while the function worked; 2315 * Returns: 1 - schedule occurred while the function worked;
2317 * 0 - schedule didn't occur while the function worked; 2316 * 0 - schedule didn't occur while the function worked;
2318 * -1 - if no_disk_space 2317 * -1 - if no_disk_space
2319 */ 2318 */
2320 2319
2321int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb, struct item_head *p_s_ins_ih, // item head of item being inserted 2320int fix_nodes(int op_mode, struct tree_balance *tb,
2322 const void *data // inserted item or data to be pasted 2321 struct item_head *ins_ih, const void *data)
2323 )
2324{ 2322{
2325 int n_ret_value, n_h, n_item_num = PATH_LAST_POSITION(p_s_tb->tb_path); 2323 int ret, h, item_num = PATH_LAST_POSITION(tb->tb_path);
2326 int n_pos_in_item; 2324 int pos_in_item;
2327 2325
2328 /* we set wait_tb_buffers_run when we have to restore any dirty bits cleared 2326 /* we set wait_tb_buffers_run when we have to restore any dirty bits cleared
2329 ** during wait_tb_buffers_run 2327 ** during wait_tb_buffers_run
2330 */ 2328 */
2331 int wait_tb_buffers_run = 0; 2329 int wait_tb_buffers_run = 0;
2332 struct buffer_head *p_s_tbS0 = PATH_PLAST_BUFFER(p_s_tb->tb_path); 2330 struct buffer_head *tbS0 = PATH_PLAST_BUFFER(tb->tb_path);
2333 2331
2334 ++REISERFS_SB(p_s_tb->tb_sb)->s_fix_nodes; 2332 ++REISERFS_SB(tb->tb_sb)->s_fix_nodes;
2335 2333
2336 n_pos_in_item = p_s_tb->tb_path->pos_in_item; 2334 pos_in_item = tb->tb_path->pos_in_item;
2337 2335
2338 p_s_tb->fs_gen = get_generation(p_s_tb->tb_sb); 2336 tb->fs_gen = get_generation(tb->tb_sb);
2339 2337
2340 /* we prepare and log the super here so it will already be in the 2338 /* we prepare and log the super here so it will already be in the
2341 ** transaction when do_balance needs to change it. 2339 ** transaction when do_balance needs to change it.
2342 ** This way do_balance won't have to schedule when trying to prepare 2340 ** This way do_balance won't have to schedule when trying to prepare
2343 ** the super for logging 2341 ** the super for logging
2344 */ 2342 */
2345 reiserfs_prepare_for_journal(p_s_tb->tb_sb, 2343 reiserfs_prepare_for_journal(tb->tb_sb,
2346 SB_BUFFER_WITH_SB(p_s_tb->tb_sb), 1); 2344 SB_BUFFER_WITH_SB(tb->tb_sb), 1);
2347 journal_mark_dirty(p_s_tb->transaction_handle, p_s_tb->tb_sb, 2345 journal_mark_dirty(tb->transaction_handle, tb->tb_sb,
2348 SB_BUFFER_WITH_SB(p_s_tb->tb_sb)); 2346 SB_BUFFER_WITH_SB(tb->tb_sb));
2349 if (FILESYSTEM_CHANGED_TB(p_s_tb)) 2347 if (FILESYSTEM_CHANGED_TB(tb))
2350 return REPEAT_SEARCH; 2348 return REPEAT_SEARCH;
2351 2349
2352 /* if it possible in indirect_to_direct conversion */ 2350 /* if it possible in indirect_to_direct conversion */
2353 if (buffer_locked(p_s_tbS0)) { 2351 if (buffer_locked(tbS0)) {
2354 __wait_on_buffer(p_s_tbS0); 2352 __wait_on_buffer(tbS0);
2355 if (FILESYSTEM_CHANGED_TB(p_s_tb)) 2353 if (FILESYSTEM_CHANGED_TB(tb))
2356 return REPEAT_SEARCH; 2354 return REPEAT_SEARCH;
2357 } 2355 }
2358#ifdef CONFIG_REISERFS_CHECK 2356#ifdef CONFIG_REISERFS_CHECK
2359 if (cur_tb) { 2357 if (cur_tb) {
2360 print_cur_tb("fix_nodes"); 2358 print_cur_tb("fix_nodes");
2361 reiserfs_panic(p_s_tb->tb_sb, 2359 reiserfs_panic(tb->tb_sb, "PAP-8305",
2362 "PAP-8305: fix_nodes: there is pending do_balance"); 2360 "there is pending do_balance");
2363 } 2361 }
2364 2362
2365 if (!buffer_uptodate(p_s_tbS0) || !B_IS_IN_TREE(p_s_tbS0)) { 2363 if (!buffer_uptodate(tbS0) || !B_IS_IN_TREE(tbS0))
2366 reiserfs_panic(p_s_tb->tb_sb, 2364 reiserfs_panic(tb->tb_sb, "PAP-8320", "S[0] (%b %z) is "
2367 "PAP-8320: fix_nodes: S[0] (%b %z) is not uptodate " 2365 "not uptodate at the beginning of fix_nodes "
2368 "at the beginning of fix_nodes or not in tree (mode %c)", 2366 "or not in tree (mode %c)",
2369 p_s_tbS0, p_s_tbS0, n_op_mode); 2367 tbS0, tbS0, op_mode);
2370 }
2371 2368
2372 /* Check parameters. */ 2369 /* Check parameters. */
2373 switch (n_op_mode) { 2370 switch (op_mode) {
2374 case M_INSERT: 2371 case M_INSERT:
2375 if (n_item_num <= 0 || n_item_num > B_NR_ITEMS(p_s_tbS0)) 2372 if (item_num <= 0 || item_num > B_NR_ITEMS(tbS0))
2376 reiserfs_panic(p_s_tb->tb_sb, 2373 reiserfs_panic(tb->tb_sb, "PAP-8330", "Incorrect "
2377 "PAP-8330: fix_nodes: Incorrect item number %d (in S0 - %d) in case of insert", 2374 "item number %d (in S0 - %d) in case "
2378 n_item_num, B_NR_ITEMS(p_s_tbS0)); 2375 "of insert", item_num,
2376 B_NR_ITEMS(tbS0));
2379 break; 2377 break;
2380 case M_PASTE: 2378 case M_PASTE:
2381 case M_DELETE: 2379 case M_DELETE:
2382 case M_CUT: 2380 case M_CUT:
2383 if (n_item_num < 0 || n_item_num >= B_NR_ITEMS(p_s_tbS0)) { 2381 if (item_num < 0 || item_num >= B_NR_ITEMS(tbS0)) {
2384 print_block(p_s_tbS0, 0, -1, -1); 2382 print_block(tbS0, 0, -1, -1);
2385 reiserfs_panic(p_s_tb->tb_sb, 2383 reiserfs_panic(tb->tb_sb, "PAP-8335", "Incorrect "
2386 "PAP-8335: fix_nodes: Incorrect item number(%d); mode = %c insert_size = %d\n", 2384 "item number(%d); mode = %c "
2387 n_item_num, n_op_mode, 2385 "insert_size = %d",
2388 p_s_tb->insert_size[0]); 2386 item_num, op_mode,
2387 tb->insert_size[0]);
2389 } 2388 }
2390 break; 2389 break;
2391 default: 2390 default:
2392 reiserfs_panic(p_s_tb->tb_sb, 2391 reiserfs_panic(tb->tb_sb, "PAP-8340", "Incorrect mode "
2393 "PAP-8340: fix_nodes: Incorrect mode of operation"); 2392 "of operation");
2394 } 2393 }
2395#endif 2394#endif
2396 2395
2397 if (get_mem_for_virtual_node(p_s_tb) == REPEAT_SEARCH) 2396 if (get_mem_for_virtual_node(tb) == REPEAT_SEARCH)
2398 // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat 2397 // FIXME: maybe -ENOMEM when tb->vn_buf == 0? Now just repeat
2399 return REPEAT_SEARCH; 2398 return REPEAT_SEARCH;
2400 2399
2401 /* Starting from the leaf level; for all levels n_h of the tree. */ 2400 /* Starting from the leaf level; for all levels h of the tree. */
2402 for (n_h = 0; n_h < MAX_HEIGHT && p_s_tb->insert_size[n_h]; n_h++) { 2401 for (h = 0; h < MAX_HEIGHT && tb->insert_size[h]; h++) {
2403 if ((n_ret_value = get_direct_parent(p_s_tb, n_h)) != CARRY_ON) { 2402 ret = get_direct_parent(tb, h);
2403 if (ret != CARRY_ON)
2404 goto repeat; 2404 goto repeat;
2405 }
2406 2405
2407 if ((n_ret_value = 2406 ret = check_balance(op_mode, tb, h, item_num,
2408 check_balance(n_op_mode, p_s_tb, n_h, n_item_num, 2407 pos_in_item, ins_ih, data);
2409 n_pos_in_item, p_s_ins_ih, 2408 if (ret != CARRY_ON) {
2410 data)) != CARRY_ON) { 2409 if (ret == NO_BALANCING_NEEDED) {
2411 if (n_ret_value == NO_BALANCING_NEEDED) {
2412 /* No balancing for higher levels needed. */ 2410 /* No balancing for higher levels needed. */
2413 if ((n_ret_value = 2411 ret = get_neighbors(tb, h);
2414 get_neighbors(p_s_tb, n_h)) != CARRY_ON) { 2412 if (ret != CARRY_ON)
2415 goto repeat; 2413 goto repeat;
2416 } 2414 if (h != MAX_HEIGHT - 1)
2417 if (n_h != MAX_HEIGHT - 1) 2415 tb->insert_size[h + 1] = 0;
2418 p_s_tb->insert_size[n_h + 1] = 0;
2419 /* ok, analysis and resource gathering are complete */ 2416 /* ok, analysis and resource gathering are complete */
2420 break; 2417 break;
2421 } 2418 }
2422 goto repeat; 2419 goto repeat;
2423 } 2420 }
2424 2421
2425 if ((n_ret_value = get_neighbors(p_s_tb, n_h)) != CARRY_ON) { 2422 ret = get_neighbors(tb, h);
2423 if (ret != CARRY_ON)
2426 goto repeat; 2424 goto repeat;
2427 }
2428 2425
2429 if ((n_ret_value = get_empty_nodes(p_s_tb, n_h)) != CARRY_ON) { 2426 /* No disk space, or schedule occurred and analysis may be
2430 goto repeat; /* No disk space, or schedule occurred and 2427 * invalid and needs to be redone. */
2431 analysis may be invalid and needs to be redone. */ 2428 ret = get_empty_nodes(tb, h);
2432 } 2429 if (ret != CARRY_ON)
2430 goto repeat;
2433 2431
2434 if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h)) { 2432 if (!PATH_H_PBUFFER(tb->tb_path, h)) {
2435 /* We have a positive insert size but no nodes exist on this 2433 /* We have a positive insert size but no nodes exist on this
2436 level, this means that we are creating a new root. */ 2434 level, this means that we are creating a new root. */
2437 2435
2438 RFALSE(p_s_tb->blknum[n_h] != 1, 2436 RFALSE(tb->blknum[h] != 1,
2439 "PAP-8350: creating new empty root"); 2437 "PAP-8350: creating new empty root");
2440 2438
2441 if (n_h < MAX_HEIGHT - 1) 2439 if (h < MAX_HEIGHT - 1)
2442 p_s_tb->insert_size[n_h + 1] = 0; 2440 tb->insert_size[h + 1] = 0;
2443 } else if (!PATH_H_PBUFFER(p_s_tb->tb_path, n_h + 1)) { 2441 } else if (!PATH_H_PBUFFER(tb->tb_path, h + 1)) {
2444 if (p_s_tb->blknum[n_h] > 1) { 2442 if (tb->blknum[h] > 1) {
2445 /* The tree needs to be grown, so this node S[n_h] 2443 /* The tree needs to be grown, so this node S[h]
2446 which is the root node is split into two nodes, 2444 which is the root node is split into two nodes,
2447 and a new node (S[n_h+1]) will be created to 2445 and a new node (S[h+1]) will be created to
2448 become the root node. */ 2446 become the root node. */
2449 2447
2450 RFALSE(n_h == MAX_HEIGHT - 1, 2448 RFALSE(h == MAX_HEIGHT - 1,
2451 "PAP-8355: attempt to create too high of a tree"); 2449 "PAP-8355: attempt to create too high of a tree");
2452 2450
2453 p_s_tb->insert_size[n_h + 1] = 2451 tb->insert_size[h + 1] =
2454 (DC_SIZE + 2452 (DC_SIZE +
2455 KEY_SIZE) * (p_s_tb->blknum[n_h] - 1) + 2453 KEY_SIZE) * (tb->blknum[h] - 1) +
2456 DC_SIZE; 2454 DC_SIZE;
2457 } else if (n_h < MAX_HEIGHT - 1) 2455 } else if (h < MAX_HEIGHT - 1)
2458 p_s_tb->insert_size[n_h + 1] = 0; 2456 tb->insert_size[h + 1] = 0;
2459 } else 2457 } else
2460 p_s_tb->insert_size[n_h + 1] = 2458 tb->insert_size[h + 1] =
2461 (DC_SIZE + KEY_SIZE) * (p_s_tb->blknum[n_h] - 1); 2459 (DC_SIZE + KEY_SIZE) * (tb->blknum[h] - 1);
2462 } 2460 }
2463 2461
2464 if ((n_ret_value = wait_tb_buffers_until_unlocked(p_s_tb)) == CARRY_ON) { 2462 ret = wait_tb_buffers_until_unlocked(tb);
2465 if (FILESYSTEM_CHANGED_TB(p_s_tb)) { 2463 if (ret == CARRY_ON) {
2464 if (FILESYSTEM_CHANGED_TB(tb)) {
2466 wait_tb_buffers_run = 1; 2465 wait_tb_buffers_run = 1;
2467 n_ret_value = REPEAT_SEARCH; 2466 ret = REPEAT_SEARCH;
2468 goto repeat; 2467 goto repeat;
2469 } else { 2468 } else {
2470 return CARRY_ON; 2469 return CARRY_ON;
@@ -2485,57 +2484,57 @@ int fix_nodes(int n_op_mode, struct tree_balance *p_s_tb, struct item_head *p_s_
2485 2484
2486 /* Release path buffers. */ 2485 /* Release path buffers. */
2487 if (wait_tb_buffers_run) { 2486 if (wait_tb_buffers_run) {
2488 pathrelse_and_restore(p_s_tb->tb_sb, p_s_tb->tb_path); 2487 pathrelse_and_restore(tb->tb_sb, tb->tb_path);
2489 } else { 2488 } else {
2490 pathrelse(p_s_tb->tb_path); 2489 pathrelse(tb->tb_path);
2491 } 2490 }
2492 /* brelse all resources collected for balancing */ 2491 /* brelse all resources collected for balancing */
2493 for (i = 0; i < MAX_HEIGHT; i++) { 2492 for (i = 0; i < MAX_HEIGHT; i++) {
2494 if (wait_tb_buffers_run) { 2493 if (wait_tb_buffers_run) {
2495 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, 2494 reiserfs_restore_prepared_buffer(tb->tb_sb,
2496 p_s_tb->L[i]); 2495 tb->L[i]);
2497 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, 2496 reiserfs_restore_prepared_buffer(tb->tb_sb,
2498 p_s_tb->R[i]); 2497 tb->R[i]);
2499 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, 2498 reiserfs_restore_prepared_buffer(tb->tb_sb,
2500 p_s_tb->FL[i]); 2499 tb->FL[i]);
2501 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, 2500 reiserfs_restore_prepared_buffer(tb->tb_sb,
2502 p_s_tb->FR[i]); 2501 tb->FR[i]);
2503 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, 2502 reiserfs_restore_prepared_buffer(tb->tb_sb,
2504 p_s_tb-> 2503 tb->
2505 CFL[i]); 2504 CFL[i]);
2506 reiserfs_restore_prepared_buffer(p_s_tb->tb_sb, 2505 reiserfs_restore_prepared_buffer(tb->tb_sb,
2507 p_s_tb-> 2506 tb->
2508 CFR[i]); 2507 CFR[i]);
2509 } 2508 }
2510 2509
2511 brelse(p_s_tb->L[i]); 2510 brelse(tb->L[i]);
2512 p_s_tb->L[i] = NULL; 2511 brelse(tb->R[i]);
2513 brelse(p_s_tb->R[i]); 2512 brelse(tb->FL[i]);
2514 p_s_tb->R[i] = NULL; 2513 brelse(tb->FR[i]);
2515 brelse(p_s_tb->FL[i]); 2514 brelse(tb->CFL[i]);
2516 p_s_tb->FL[i] = NULL; 2515 brelse(tb->CFR[i]);
2517 brelse(p_s_tb->FR[i]); 2516
2518 p_s_tb->FR[i] = NULL; 2517 tb->L[i] = NULL;
2519 brelse(p_s_tb->CFL[i]); 2518 tb->R[i] = NULL;
2520 p_s_tb->CFL[i] = NULL; 2519 tb->FL[i] = NULL;
2521 brelse(p_s_tb->CFR[i]); 2520 tb->FR[i] = NULL;
2522 p_s_tb->CFR[i] = NULL; 2521 tb->CFL[i] = NULL;
2522 tb->CFR[i] = NULL;
2523 } 2523 }
2524 2524
2525 if (wait_tb_buffers_run) { 2525 if (wait_tb_buffers_run) {
2526 for (i = 0; i < MAX_FEB_SIZE; i++) { 2526 for (i = 0; i < MAX_FEB_SIZE; i++) {
2527 if (p_s_tb->FEB[i]) { 2527 if (tb->FEB[i])
2528 reiserfs_restore_prepared_buffer 2528 reiserfs_restore_prepared_buffer
2529 (p_s_tb->tb_sb, p_s_tb->FEB[i]); 2529 (tb->tb_sb, tb->FEB[i]);
2530 }
2531 } 2530 }
2532 } 2531 }
2533 return n_ret_value; 2532 return ret;
2534 } 2533 }
2535 2534
2536} 2535}
2537 2536
2538/* Anatoly will probably forgive me renaming p_s_tb to tb. I just 2537/* Anatoly will probably forgive me renaming tb to tb. I just
2539 wanted to make lines shorter */ 2538 wanted to make lines shorter */
2540void unfix_nodes(struct tree_balance *tb) 2539void unfix_nodes(struct tree_balance *tb)
2541{ 2540{
diff --git a/fs/reiserfs/hashes.c b/fs/reiserfs/hashes.c
index e664ac16fad..6471c670743 100644
--- a/fs/reiserfs/hashes.c
+++ b/fs/reiserfs/hashes.c
@@ -7,7 +7,7 @@
7 * (see Applied Cryptography, 2nd edition, p448). 7 * (see Applied Cryptography, 2nd edition, p448).
8 * 8 *
9 * Jeremy Fitzhardinge <jeremy@zip.com.au> 1998 9 * Jeremy Fitzhardinge <jeremy@zip.com.au> 1998
10 * 10 *
11 * Jeremy has agreed to the contents of reiserfs/README. -Hans 11 * Jeremy has agreed to the contents of reiserfs/README. -Hans
12 * Yura's function is added (04/07/2000) 12 * Yura's function is added (04/07/2000)
13 */ 13 */
diff --git a/fs/reiserfs/ibalance.c b/fs/reiserfs/ibalance.c
index de391a82b99..2074fd95046 100644
--- a/fs/reiserfs/ibalance.c
+++ b/fs/reiserfs/ibalance.c
@@ -105,8 +105,8 @@ static void internal_define_dest_src_infos(int shift_mode,
105 break; 105 break;
106 106
107 default: 107 default:
108 reiserfs_panic(tb->tb_sb, 108 reiserfs_panic(tb->tb_sb, "ibalance-1",
109 "internal_define_dest_src_infos: shift type is unknown (%d)", 109 "shift type is unknown (%d)",
110 shift_mode); 110 shift_mode);
111 } 111 }
112} 112}
@@ -278,7 +278,7 @@ static void internal_delete_childs(struct buffer_info *cur_bi, int from, int n)
278 278
279/* copy cpy_num node pointers and cpy_num - 1 items from buffer src to buffer dest 279/* copy cpy_num node pointers and cpy_num - 1 items from buffer src to buffer dest
280* last_first == FIRST_TO_LAST means, that we copy first items from src to tail of dest 280* last_first == FIRST_TO_LAST means, that we copy first items from src to tail of dest
281 * last_first == LAST_TO_FIRST means, that we copy last items from src to head of dest 281 * last_first == LAST_TO_FIRST means, that we copy last items from src to head of dest
282 */ 282 */
283static void internal_copy_pointers_items(struct buffer_info *dest_bi, 283static void internal_copy_pointers_items(struct buffer_info *dest_bi,
284 struct buffer_head *src, 284 struct buffer_head *src,
@@ -385,7 +385,7 @@ static void internal_move_pointers_items(struct buffer_info *dest_bi,
385 if (last_first == FIRST_TO_LAST) { /* shift_left occurs */ 385 if (last_first == FIRST_TO_LAST) { /* shift_left occurs */
386 first_pointer = 0; 386 first_pointer = 0;
387 first_item = 0; 387 first_item = 0;
388 /* delete cpy_num - del_par pointers and keys starting for pointers with first_pointer, 388 /* delete cpy_num - del_par pointers and keys starting for pointers with first_pointer,
389 for key - with first_item */ 389 for key - with first_item */
390 internal_delete_pointers_items(src_bi, first_pointer, 390 internal_delete_pointers_items(src_bi, first_pointer,
391 first_item, cpy_num - del_par); 391 first_item, cpy_num - del_par);
@@ -453,7 +453,7 @@ static void internal_insert_key(struct buffer_info *dest_bi, int dest_position_b
453 } 453 }
454} 454}
455 455
456/* Insert d_key'th (delimiting) key from buffer cfl to tail of dest. 456/* Insert d_key'th (delimiting) key from buffer cfl to tail of dest.
457 * Copy pointer_amount node pointers and pointer_amount - 1 items from buffer src to buffer dest. 457 * Copy pointer_amount node pointers and pointer_amount - 1 items from buffer src to buffer dest.
458 * Replace d_key'th key in buffer cfl. 458 * Replace d_key'th key in buffer cfl.
459 * Delete pointer_amount items and node pointers from buffer src. 459 * Delete pointer_amount items and node pointers from buffer src.
@@ -518,7 +518,7 @@ static void internal_shift1_left(struct tree_balance *tb,
518 /* internal_move_pointers_items (tb->L[h], tb->S[h], FIRST_TO_LAST, pointer_amount, 1); */ 518 /* internal_move_pointers_items (tb->L[h], tb->S[h], FIRST_TO_LAST, pointer_amount, 1); */
519} 519}
520 520
521/* Insert d_key'th (delimiting) key from buffer cfr to head of dest. 521/* Insert d_key'th (delimiting) key from buffer cfr to head of dest.
522 * Copy n node pointers and n - 1 items from buffer src to buffer dest. 522 * Copy n node pointers and n - 1 items from buffer src to buffer dest.
523 * Replace d_key'th key in buffer cfr. 523 * Replace d_key'th key in buffer cfr.
524 * Delete n items and node pointers from buffer src. 524 * Delete n items and node pointers from buffer src.
@@ -702,8 +702,8 @@ static void balance_internal_when_delete(struct tree_balance *tb,
702 702
703 return; 703 return;
704 } 704 }
705 reiserfs_panic(tb->tb_sb, 705 reiserfs_panic(tb->tb_sb, "ibalance-2",
706 "balance_internal_when_delete: unexpected tb->lnum[%d]==%d or tb->rnum[%d]==%d", 706 "unexpected tb->lnum[%d]==%d or tb->rnum[%d]==%d",
707 h, tb->lnum[h], h, tb->rnum[h]); 707 h, tb->lnum[h], h, tb->rnum[h]);
708} 708}
709 709
@@ -749,7 +749,7 @@ int balance_internal(struct tree_balance *tb, /* tree_balance structure
749 this means that new pointers and items must be inserted AFTER * 749 this means that new pointers and items must be inserted AFTER *
750 child_pos 750 child_pos
751 } 751 }
752 else 752 else
753 { 753 {
754 it is the position of the leftmost pointer that must be deleted (together with 754 it is the position of the leftmost pointer that must be deleted (together with
755 its corresponding key to the left of the pointer) 755 its corresponding key to the left of the pointer)
@@ -940,8 +940,8 @@ int balance_internal(struct tree_balance *tb, /* tree_balance structure
940 struct block_head *blkh; 940 struct block_head *blkh;
941 941
942 if (tb->blknum[h] != 1) 942 if (tb->blknum[h] != 1)
943 reiserfs_panic(NULL, 943 reiserfs_panic(NULL, "ibalance-3", "One new node "
944 "balance_internal: One new node required for creating the new root"); 944 "required for creating the new root");
945 /* S[h] = empty buffer from the list FEB. */ 945 /* S[h] = empty buffer from the list FEB. */
946 tbSh = get_FEB(tb); 946 tbSh = get_FEB(tb);
947 blkh = B_BLK_HEAD(tbSh); 947 blkh = B_BLK_HEAD(tbSh);
diff --git a/fs/reiserfs/inode.c b/fs/reiserfs/inode.c
index 55fce92cdf1..6fd0f47e45d 100644
--- a/fs/reiserfs/inode.c
+++ b/fs/reiserfs/inode.c
@@ -53,7 +53,7 @@ void reiserfs_delete_inode(struct inode *inode)
53 * after delete_object so that quota updates go into the same transaction as 53 * after delete_object so that quota updates go into the same transaction as
54 * stat data deletion */ 54 * stat data deletion */
55 if (!err) 55 if (!err)
56 DQUOT_FREE_INODE(inode); 56 vfs_dq_free_inode(inode);
57 57
58 if (journal_end(&th, inode->i_sb, jbegin_count)) 58 if (journal_end(&th, inode->i_sb, jbegin_count))
59 goto out; 59 goto out;
@@ -363,7 +363,7 @@ static int _get_block_create_0(struct inode *inode, sector_t block,
363 } 363 }
364 /* make sure we don't read more bytes than actually exist in 364 /* make sure we don't read more bytes than actually exist in
365 ** the file. This can happen in odd cases where i_size isn't 365 ** the file. This can happen in odd cases where i_size isn't
366 ** correct, and when direct item padding results in a few 366 ** correct, and when direct item padding results in a few
367 ** extra bytes at the end of the direct item 367 ** extra bytes at the end of the direct item
368 */ 368 */
369 if ((le_ih_k_offset(ih) + path.pos_in_item) > inode->i_size) 369 if ((le_ih_k_offset(ih) + path.pos_in_item) > inode->i_size)
@@ -438,15 +438,15 @@ static int reiserfs_bmap(struct inode *inode, sector_t block,
438** -ENOENT instead of a valid buffer. block_prepare_write expects to 438** -ENOENT instead of a valid buffer. block_prepare_write expects to
439** be able to do i/o on the buffers returned, unless an error value 439** be able to do i/o on the buffers returned, unless an error value
440** is also returned. 440** is also returned.
441** 441**
442** So, this allows block_prepare_write to be used for reading a single block 442** So, this allows block_prepare_write to be used for reading a single block
443** in a page. Where it does not produce a valid page for holes, or past the 443** in a page. Where it does not produce a valid page for holes, or past the
444** end of the file. This turns out to be exactly what we need for reading 444** end of the file. This turns out to be exactly what we need for reading
445** tails for conversion. 445** tails for conversion.
446** 446**
447** The point of the wrapper is forcing a certain value for create, even 447** The point of the wrapper is forcing a certain value for create, even
448** though the VFS layer is calling this function with create==1. If you 448** though the VFS layer is calling this function with create==1. If you
449** don't want to send create == GET_BLOCK_NO_HOLE to reiserfs_get_block, 449** don't want to send create == GET_BLOCK_NO_HOLE to reiserfs_get_block,
450** don't use this function. 450** don't use this function.
451*/ 451*/
452static int reiserfs_get_block_create_0(struct inode *inode, sector_t block, 452static int reiserfs_get_block_create_0(struct inode *inode, sector_t block,
@@ -602,7 +602,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
602 int done; 602 int done;
603 int fs_gen; 603 int fs_gen;
604 struct reiserfs_transaction_handle *th = NULL; 604 struct reiserfs_transaction_handle *th = NULL;
605 /* space reserved in transaction batch: 605 /* space reserved in transaction batch:
606 . 3 balancings in direct->indirect conversion 606 . 3 balancings in direct->indirect conversion
607 . 1 block involved into reiserfs_update_sd() 607 . 1 block involved into reiserfs_update_sd()
608 XXX in practically impossible worst case direct2indirect() 608 XXX in practically impossible worst case direct2indirect()
@@ -754,7 +754,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
754 reiserfs_write_unlock(inode->i_sb); 754 reiserfs_write_unlock(inode->i_sb);
755 755
756 /* the item was found, so new blocks were not added to the file 756 /* the item was found, so new blocks were not added to the file
757 ** there is no need to make sure the inode is updated with this 757 ** there is no need to make sure the inode is updated with this
758 ** transaction 758 ** transaction
759 */ 759 */
760 return retval; 760 return retval;
@@ -841,10 +841,12 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
841 tail_offset); 841 tail_offset);
842 if (retval) { 842 if (retval) {
843 if (retval != -ENOSPC) 843 if (retval != -ENOSPC)
844 reiserfs_warning(inode->i_sb, 844 reiserfs_error(inode->i_sb,
845 "clm-6004: convert tail failed inode %lu, error %d", 845 "clm-6004",
846 inode->i_ino, 846 "convert tail failed "
847 retval); 847 "inode %lu, error %d",
848 inode->i_ino,
849 retval);
848 if (allocated_block_nr) { 850 if (allocated_block_nr) {
849 /* the bitmap, the super, and the stat data == 3 */ 851 /* the bitmap, the super, and the stat data == 3 */
850 if (!th) 852 if (!th)
@@ -984,7 +986,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
984 986
985 /* this loop could log more blocks than we had originally asked 987 /* this loop could log more blocks than we had originally asked
986 ** for. So, we have to allow the transaction to end if it is 988 ** for. So, we have to allow the transaction to end if it is
987 ** too big or too full. Update the inode so things are 989 ** too big or too full. Update the inode so things are
988 ** consistent if we crash before the function returns 990 ** consistent if we crash before the function returns
989 ** 991 **
990 ** release the path so that anybody waiting on the path before 992 ** release the path so that anybody waiting on the path before
@@ -995,7 +997,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
995 if (retval) 997 if (retval)
996 goto failure; 998 goto failure;
997 } 999 }
998 /* inserting indirect pointers for a hole can take a 1000 /* inserting indirect pointers for a hole can take a
999 ** long time. reschedule if needed 1001 ** long time. reschedule if needed
1000 */ 1002 */
1001 cond_resched(); 1003 cond_resched();
@@ -1006,8 +1008,7 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
1006 goto failure; 1008 goto failure;
1007 } 1009 }
1008 if (retval == POSITION_FOUND) { 1010 if (retval == POSITION_FOUND) {
1009 reiserfs_warning(inode->i_sb, 1011 reiserfs_warning(inode->i_sb, "vs-825",
1010 "vs-825: reiserfs_get_block: "
1011 "%K should not be found", &key); 1012 "%K should not be found", &key);
1012 retval = -EEXIST; 1013 retval = -EEXIST;
1013 if (allocated_block_nr) 1014 if (allocated_block_nr)
@@ -1299,8 +1300,7 @@ static void update_stat_data(struct treepath *path, struct inode *inode,
1299 ih = PATH_PITEM_HEAD(path); 1300 ih = PATH_PITEM_HEAD(path);
1300 1301
1301 if (!is_statdata_le_ih(ih)) 1302 if (!is_statdata_le_ih(ih))
1302 reiserfs_panic(inode->i_sb, 1303 reiserfs_panic(inode->i_sb, "vs-13065", "key %k, found item %h",
1303 "vs-13065: update_stat_data: key %k, found item %h",
1304 INODE_PKEY(inode), ih); 1304 INODE_PKEY(inode), ih);
1305 1305
1306 if (stat_data_v1(ih)) { 1306 if (stat_data_v1(ih)) {
@@ -1332,10 +1332,9 @@ void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
1332 /* look for the object's stat data */ 1332 /* look for the object's stat data */
1333 retval = search_item(inode->i_sb, &key, &path); 1333 retval = search_item(inode->i_sb, &key, &path);
1334 if (retval == IO_ERROR) { 1334 if (retval == IO_ERROR) {
1335 reiserfs_warning(inode->i_sb, 1335 reiserfs_error(inode->i_sb, "vs-13050",
1336 "vs-13050: reiserfs_update_sd: " 1336 "i/o failure occurred trying to "
1337 "i/o failure occurred trying to update %K stat data", 1337 "update %K stat data", &key);
1338 &key);
1339 return; 1338 return;
1340 } 1339 }
1341 if (retval == ITEM_NOT_FOUND) { 1340 if (retval == ITEM_NOT_FOUND) {
@@ -1345,9 +1344,9 @@ void reiserfs_update_sd_size(struct reiserfs_transaction_handle *th,
1345 /*reiserfs_warning (inode->i_sb, "vs-13050: reiserfs_update_sd: i_nlink == 0, stat data not found"); */ 1344 /*reiserfs_warning (inode->i_sb, "vs-13050: reiserfs_update_sd: i_nlink == 0, stat data not found"); */
1346 return; 1345 return;
1347 } 1346 }
1348 reiserfs_warning(inode->i_sb, 1347 reiserfs_warning(inode->i_sb, "vs-13060",
1349 "vs-13060: reiserfs_update_sd: " 1348 "stat data of object %k (nlink == %d) "
1350 "stat data of object %k (nlink == %d) not found (pos %d)", 1349 "not found (pos %d)",
1351 INODE_PKEY(inode), inode->i_nlink, 1350 INODE_PKEY(inode), inode->i_nlink,
1352 pos); 1351 pos);
1353 reiserfs_check_path(&path); 1352 reiserfs_check_path(&path);
@@ -1424,10 +1423,9 @@ void reiserfs_read_locked_inode(struct inode *inode,
1424 /* look for the object's stat data */ 1423 /* look for the object's stat data */
1425 retval = search_item(inode->i_sb, &key, &path_to_sd); 1424 retval = search_item(inode->i_sb, &key, &path_to_sd);
1426 if (retval == IO_ERROR) { 1425 if (retval == IO_ERROR) {
1427 reiserfs_warning(inode->i_sb, 1426 reiserfs_error(inode->i_sb, "vs-13070",
1428 "vs-13070: reiserfs_read_locked_inode: " 1427 "i/o failure occurred trying to find "
1429 "i/o failure occurred trying to find stat data of %K", 1428 "stat data of %K", &key);
1430 &key);
1431 reiserfs_make_bad_inode(inode); 1429 reiserfs_make_bad_inode(inode);
1432 return; 1430 return;
1433 } 1431 }
@@ -1446,7 +1444,7 @@ void reiserfs_read_locked_inode(struct inode *inode,
1446 update sd on unlink all that is required is to check for nlink 1444 update sd on unlink all that is required is to check for nlink
1447 here. This bug was first found by Sizif when debugging 1445 here. This bug was first found by Sizif when debugging
1448 SquidNG/Butterfly, forgotten, and found again after Philippe 1446 SquidNG/Butterfly, forgotten, and found again after Philippe
1449 Gramoulle <philippe.gramoulle@mmania.com> reproduced it. 1447 Gramoulle <philippe.gramoulle@mmania.com> reproduced it.
1450 1448
1451 More logical fix would require changes in fs/inode.c:iput() to 1449 More logical fix would require changes in fs/inode.c:iput() to
1452 remove inode from hash-table _after_ fs cleaned disk stuff up and 1450 remove inode from hash-table _after_ fs cleaned disk stuff up and
@@ -1457,8 +1455,7 @@ void reiserfs_read_locked_inode(struct inode *inode,
1457 during mount (fs/reiserfs/super.c:finish_unfinished()). */ 1455 during mount (fs/reiserfs/super.c:finish_unfinished()). */
1458 if ((inode->i_nlink == 0) && 1456 if ((inode->i_nlink == 0) &&
1459 !REISERFS_SB(inode->i_sb)->s_is_unlinked_ok) { 1457 !REISERFS_SB(inode->i_sb)->s_is_unlinked_ok) {
1460 reiserfs_warning(inode->i_sb, 1458 reiserfs_warning(inode->i_sb, "vs-13075",
1461 "vs-13075: reiserfs_read_locked_inode: "
1462 "dead inode read from disk %K. " 1459 "dead inode read from disk %K. "
1463 "This is likely to be race with knfsd. Ignore", 1460 "This is likely to be race with knfsd. Ignore",
1464 &key); 1461 &key);
@@ -1555,7 +1552,7 @@ struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
1555 */ 1552 */
1556 if (fh_type > fh_len) { 1553 if (fh_type > fh_len) {
1557 if (fh_type != 6 || fh_len != 5) 1554 if (fh_type != 6 || fh_len != 5)
1558 reiserfs_warning(sb, 1555 reiserfs_warning(sb, "reiserfs-13077",
1559 "nfsd/reiserfs, fhtype=%d, len=%d - odd", 1556 "nfsd/reiserfs, fhtype=%d, len=%d - odd",
1560 fh_type, fh_len); 1557 fh_type, fh_len);
1561 fh_type = 5; 1558 fh_type = 5;
@@ -1622,7 +1619,7 @@ int reiserfs_write_inode(struct inode *inode, int do_sync)
1622 if (inode->i_sb->s_flags & MS_RDONLY) 1619 if (inode->i_sb->s_flags & MS_RDONLY)
1623 return -EROFS; 1620 return -EROFS;
1624 /* memory pressure can sometimes initiate write_inode calls with sync == 1, 1621 /* memory pressure can sometimes initiate write_inode calls with sync == 1,
1625 ** these cases are just when the system needs ram, not when the 1622 ** these cases are just when the system needs ram, not when the
1626 ** inode needs to reach disk for safety, and they can safely be 1623 ** inode needs to reach disk for safety, and they can safely be
1627 ** ignored because the altered inode has already been logged. 1624 ** ignored because the altered inode has already been logged.
1628 */ 1625 */
@@ -1680,13 +1677,13 @@ static int reiserfs_new_directory(struct reiserfs_transaction_handle *th,
1680 /* look for place in the tree for new item */ 1677 /* look for place in the tree for new item */
1681 retval = search_item(sb, &key, path); 1678 retval = search_item(sb, &key, path);
1682 if (retval == IO_ERROR) { 1679 if (retval == IO_ERROR) {
1683 reiserfs_warning(sb, "vs-13080: reiserfs_new_directory: " 1680 reiserfs_error(sb, "vs-13080",
1684 "i/o failure occurred creating new directory"); 1681 "i/o failure occurred creating new directory");
1685 return -EIO; 1682 return -EIO;
1686 } 1683 }
1687 if (retval == ITEM_FOUND) { 1684 if (retval == ITEM_FOUND) {
1688 pathrelse(path); 1685 pathrelse(path);
1689 reiserfs_warning(sb, "vs-13070: reiserfs_new_directory: " 1686 reiserfs_warning(sb, "vs-13070",
1690 "object with this key exists (%k)", 1687 "object with this key exists (%k)",
1691 &(ih->ih_key)); 1688 &(ih->ih_key));
1692 return -EEXIST; 1689 return -EEXIST;
@@ -1720,13 +1717,13 @@ static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct i
1720 /* look for place in the tree for new item */ 1717 /* look for place in the tree for new item */
1721 retval = search_item(sb, &key, path); 1718 retval = search_item(sb, &key, path);
1722 if (retval == IO_ERROR) { 1719 if (retval == IO_ERROR) {
1723 reiserfs_warning(sb, "vs-13080: reiserfs_new_symlinik: " 1720 reiserfs_error(sb, "vs-13080",
1724 "i/o failure occurred creating new symlink"); 1721 "i/o failure occurred creating new symlink");
1725 return -EIO; 1722 return -EIO;
1726 } 1723 }
1727 if (retval == ITEM_FOUND) { 1724 if (retval == ITEM_FOUND) {
1728 pathrelse(path); 1725 pathrelse(path);
1729 reiserfs_warning(sb, "vs-13080: reiserfs_new_symlink: " 1726 reiserfs_warning(sb, "vs-13080",
1730 "object with this key exists (%k)", 1727 "object with this key exists (%k)",
1731 &(ih->ih_key)); 1728 &(ih->ih_key));
1732 return -EEXIST; 1729 return -EEXIST;
@@ -1739,7 +1736,7 @@ static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct i
1739/* inserts the stat data into the tree, and then calls 1736/* inserts the stat data into the tree, and then calls
1740 reiserfs_new_directory (to insert ".", ".." item if new object is 1737 reiserfs_new_directory (to insert ".", ".." item if new object is
1741 directory) or reiserfs_new_symlink (to insert symlink body if new 1738 directory) or reiserfs_new_symlink (to insert symlink body if new
1742 object is symlink) or nothing (if new object is regular file) 1739 object is symlink) or nothing (if new object is regular file)
1743 1740
1744 NOTE! uid and gid must already be set in the inode. If we return 1741 NOTE! uid and gid must already be set in the inode. If we return
1745 non-zero due to an error, we have to drop the quota previously allocated 1742 non-zero due to an error, we have to drop the quota previously allocated
@@ -1747,10 +1744,11 @@ static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct i
1747 if we return non-zero, we also end the transaction. */ 1744 if we return non-zero, we also end the transaction. */
1748int reiserfs_new_inode(struct reiserfs_transaction_handle *th, 1745int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1749 struct inode *dir, int mode, const char *symname, 1746 struct inode *dir, int mode, const char *symname,
1750 /* 0 for regular, EMTRY_DIR_SIZE for dirs, 1747 /* 0 for regular, EMTRY_DIR_SIZE for dirs,
1751 strlen (symname) for symlinks) */ 1748 strlen (symname) for symlinks) */
1752 loff_t i_size, struct dentry *dentry, 1749 loff_t i_size, struct dentry *dentry,
1753 struct inode *inode) 1750 struct inode *inode,
1751 struct reiserfs_security_handle *security)
1754{ 1752{
1755 struct super_block *sb; 1753 struct super_block *sb;
1756 struct reiserfs_iget_args args; 1754 struct reiserfs_iget_args args;
@@ -1763,7 +1761,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1763 1761
1764 BUG_ON(!th->t_trans_id); 1762 BUG_ON(!th->t_trans_id);
1765 1763
1766 if (DQUOT_ALLOC_INODE(inode)) { 1764 if (vfs_dq_alloc_inode(inode)) {
1767 err = -EDQUOT; 1765 err = -EDQUOT;
1768 goto out_end_trans; 1766 goto out_end_trans;
1769 } 1767 }
@@ -1796,7 +1794,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1796 goto out_bad_inode; 1794 goto out_bad_inode;
1797 } 1795 }
1798 if (old_format_only(sb)) 1796 if (old_format_only(sb))
1799 /* not a perfect generation count, as object ids can be reused, but 1797 /* not a perfect generation count, as object ids can be reused, but
1800 ** this is as good as reiserfs can do right now. 1798 ** this is as good as reiserfs can do right now.
1801 ** note that the private part of inode isn't filled in yet, we have 1799 ** note that the private part of inode isn't filled in yet, we have
1802 ** to use the directory. 1800 ** to use the directory.
@@ -1917,9 +1915,8 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1917 goto out_inserted_sd; 1915 goto out_inserted_sd;
1918 } 1916 }
1919 1917
1920 /* XXX CHECK THIS */
1921 if (reiserfs_posixacl(inode->i_sb)) { 1918 if (reiserfs_posixacl(inode->i_sb)) {
1922 retval = reiserfs_inherit_default_acl(dir, dentry, inode); 1919 retval = reiserfs_inherit_default_acl(th, dir, dentry, inode);
1923 if (retval) { 1920 if (retval) {
1924 err = retval; 1921 err = retval;
1925 reiserfs_check_path(&path_to_key); 1922 reiserfs_check_path(&path_to_key);
@@ -1927,10 +1924,23 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1927 goto out_inserted_sd; 1924 goto out_inserted_sd;
1928 } 1925 }
1929 } else if (inode->i_sb->s_flags & MS_POSIXACL) { 1926 } else if (inode->i_sb->s_flags & MS_POSIXACL) {
1930 reiserfs_warning(inode->i_sb, "ACLs aren't enabled in the fs, " 1927 reiserfs_warning(inode->i_sb, "jdm-13090",
1928 "ACLs aren't enabled in the fs, "
1931 "but vfs thinks they are!"); 1929 "but vfs thinks they are!");
1932 } else if (is_reiserfs_priv_object(dir)) { 1930 } else if (IS_PRIVATE(dir))
1933 reiserfs_mark_inode_private(inode); 1931 inode->i_flags |= S_PRIVATE;
1932
1933 if (security->name) {
1934 retval = reiserfs_security_write(th, inode, security);
1935 if (retval) {
1936 err = retval;
1937 reiserfs_check_path(&path_to_key);
1938 retval = journal_end(th, th->t_super,
1939 th->t_blocks_allocated);
1940 if (retval)
1941 err = retval;
1942 goto out_inserted_sd;
1943 }
1934 } 1944 }
1935 1945
1936 reiserfs_update_sd(th, inode); 1946 reiserfs_update_sd(th, inode);
@@ -1947,12 +1957,12 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1947 INODE_PKEY(inode)->k_objectid = 0; 1957 INODE_PKEY(inode)->k_objectid = 0;
1948 1958
1949 /* Quota change must be inside a transaction for journaling */ 1959 /* Quota change must be inside a transaction for journaling */
1950 DQUOT_FREE_INODE(inode); 1960 vfs_dq_free_inode(inode);
1951 1961
1952 out_end_trans: 1962 out_end_trans:
1953 journal_end(th, th->t_super, th->t_blocks_allocated); 1963 journal_end(th, th->t_super, th->t_blocks_allocated);
1954 /* Drop can be outside and it needs more credits so it's better to have it outside */ 1964 /* Drop can be outside and it needs more credits so it's better to have it outside */
1955 DQUOT_DROP(inode); 1965 vfs_dq_drop(inode);
1956 inode->i_flags |= S_NOQUOTA; 1966 inode->i_flags |= S_NOQUOTA;
1957 make_bad_inode(inode); 1967 make_bad_inode(inode);
1958 1968
@@ -1960,19 +1970,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1960 inode->i_nlink = 0; 1970 inode->i_nlink = 0;
1961 th->t_trans_id = 0; /* so the caller can't use this handle later */ 1971 th->t_trans_id = 0; /* so the caller can't use this handle later */
1962 unlock_new_inode(inode); /* OK to do even if we hadn't locked it */ 1972 unlock_new_inode(inode); /* OK to do even if we hadn't locked it */
1963 1973 iput(inode);
1964 /* If we were inheriting an ACL, we need to release the lock so that
1965 * iput doesn't deadlock in reiserfs_delete_xattrs. The locking
1966 * code really needs to be reworked, but this will take care of it
1967 * for now. -jeffm */
1968#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1969 if (REISERFS_I(dir)->i_acl_default && !IS_ERR(REISERFS_I(dir)->i_acl_default)) {
1970 reiserfs_write_unlock_xattrs(dir->i_sb);
1971 iput(inode);
1972 reiserfs_write_lock_xattrs(dir->i_sb);
1973 } else
1974#endif
1975 iput(inode);
1976 return err; 1974 return err;
1977} 1975}
1978 1976
@@ -1989,7 +1987,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
1989** 1987**
1990** on failure, nonzero is returned, page_result and bh_result are untouched. 1988** on failure, nonzero is returned, page_result and bh_result are untouched.
1991*/ 1989*/
1992static int grab_tail_page(struct inode *p_s_inode, 1990static int grab_tail_page(struct inode *inode,
1993 struct page **page_result, 1991 struct page **page_result,
1994 struct buffer_head **bh_result) 1992 struct buffer_head **bh_result)
1995{ 1993{
@@ -1997,11 +1995,11 @@ static int grab_tail_page(struct inode *p_s_inode,
1997 /* we want the page with the last byte in the file, 1995 /* we want the page with the last byte in the file,
1998 ** not the page that will hold the next byte for appending 1996 ** not the page that will hold the next byte for appending
1999 */ 1997 */
2000 unsigned long index = (p_s_inode->i_size - 1) >> PAGE_CACHE_SHIFT; 1998 unsigned long index = (inode->i_size - 1) >> PAGE_CACHE_SHIFT;
2001 unsigned long pos = 0; 1999 unsigned long pos = 0;
2002 unsigned long start = 0; 2000 unsigned long start = 0;
2003 unsigned long blocksize = p_s_inode->i_sb->s_blocksize; 2001 unsigned long blocksize = inode->i_sb->s_blocksize;
2004 unsigned long offset = (p_s_inode->i_size) & (PAGE_CACHE_SIZE - 1); 2002 unsigned long offset = (inode->i_size) & (PAGE_CACHE_SIZE - 1);
2005 struct buffer_head *bh; 2003 struct buffer_head *bh;
2006 struct buffer_head *head; 2004 struct buffer_head *head;
2007 struct page *page; 2005 struct page *page;
@@ -2015,7 +2013,7 @@ static int grab_tail_page(struct inode *p_s_inode,
2015 if ((offset & (blocksize - 1)) == 0) { 2013 if ((offset & (blocksize - 1)) == 0) {
2016 return -ENOENT; 2014 return -ENOENT;
2017 } 2015 }
2018 page = grab_cache_page(p_s_inode->i_mapping, index); 2016 page = grab_cache_page(inode->i_mapping, index);
2019 error = -ENOMEM; 2017 error = -ENOMEM;
2020 if (!page) { 2018 if (!page) {
2021 goto out; 2019 goto out;
@@ -2044,10 +2042,8 @@ static int grab_tail_page(struct inode *p_s_inode,
2044 ** I've screwed up the code to find the buffer, or the code to 2042 ** I've screwed up the code to find the buffer, or the code to
2045 ** call prepare_write 2043 ** call prepare_write
2046 */ 2044 */
2047 reiserfs_warning(p_s_inode->i_sb, 2045 reiserfs_error(inode->i_sb, "clm-6000",
2048 "clm-6000: error reading block %lu on dev %s", 2046 "error reading block %lu", bh->b_blocknr);
2049 bh->b_blocknr,
2050 reiserfs_bdevname(p_s_inode->i_sb));
2051 error = -EIO; 2047 error = -EIO;
2052 goto unlock; 2048 goto unlock;
2053 } 2049 }
@@ -2069,57 +2065,58 @@ static int grab_tail_page(struct inode *p_s_inode,
2069** 2065**
2070** some code taken from block_truncate_page 2066** some code taken from block_truncate_page
2071*/ 2067*/
2072int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps) 2068int reiserfs_truncate_file(struct inode *inode, int update_timestamps)
2073{ 2069{
2074 struct reiserfs_transaction_handle th; 2070 struct reiserfs_transaction_handle th;
2075 /* we want the offset for the first byte after the end of the file */ 2071 /* we want the offset for the first byte after the end of the file */
2076 unsigned long offset = p_s_inode->i_size & (PAGE_CACHE_SIZE - 1); 2072 unsigned long offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
2077 unsigned blocksize = p_s_inode->i_sb->s_blocksize; 2073 unsigned blocksize = inode->i_sb->s_blocksize;
2078 unsigned length; 2074 unsigned length;
2079 struct page *page = NULL; 2075 struct page *page = NULL;
2080 int error; 2076 int error;
2081 struct buffer_head *bh = NULL; 2077 struct buffer_head *bh = NULL;
2082 int err2; 2078 int err2;
2083 2079
2084 reiserfs_write_lock(p_s_inode->i_sb); 2080 reiserfs_write_lock(inode->i_sb);
2085 2081
2086 if (p_s_inode->i_size > 0) { 2082 if (inode->i_size > 0) {
2087 if ((error = grab_tail_page(p_s_inode, &page, &bh))) { 2083 error = grab_tail_page(inode, &page, &bh);
2088 // -ENOENT means we truncated past the end of the file, 2084 if (error) {
2085 // -ENOENT means we truncated past the end of the file,
2089 // and get_block_create_0 could not find a block to read in, 2086 // and get_block_create_0 could not find a block to read in,
2090 // which is ok. 2087 // which is ok.
2091 if (error != -ENOENT) 2088 if (error != -ENOENT)
2092 reiserfs_warning(p_s_inode->i_sb, 2089 reiserfs_error(inode->i_sb, "clm-6001",
2093 "clm-6001: grab_tail_page failed %d", 2090 "grab_tail_page failed %d",
2094 error); 2091 error);
2095 page = NULL; 2092 page = NULL;
2096 bh = NULL; 2093 bh = NULL;
2097 } 2094 }
2098 } 2095 }
2099 2096
2100 /* so, if page != NULL, we have a buffer head for the offset at 2097 /* so, if page != NULL, we have a buffer head for the offset at
2101 ** the end of the file. if the bh is mapped, and bh->b_blocknr != 0, 2098 ** the end of the file. if the bh is mapped, and bh->b_blocknr != 0,
2102 ** then we have an unformatted node. Otherwise, we have a direct item, 2099 ** then we have an unformatted node. Otherwise, we have a direct item,
2103 ** and no zeroing is required on disk. We zero after the truncate, 2100 ** and no zeroing is required on disk. We zero after the truncate,
2104 ** because the truncate might pack the item anyway 2101 ** because the truncate might pack the item anyway
2105 ** (it will unmap bh if it packs). 2102 ** (it will unmap bh if it packs).
2106 */ 2103 */
2107 /* it is enough to reserve space in transaction for 2 balancings: 2104 /* it is enough to reserve space in transaction for 2 balancings:
2108 one for "save" link adding and another for the first 2105 one for "save" link adding and another for the first
2109 cut_from_item. 1 is for update_sd */ 2106 cut_from_item. 1 is for update_sd */
2110 error = journal_begin(&th, p_s_inode->i_sb, 2107 error = journal_begin(&th, inode->i_sb,
2111 JOURNAL_PER_BALANCE_CNT * 2 + 1); 2108 JOURNAL_PER_BALANCE_CNT * 2 + 1);
2112 if (error) 2109 if (error)
2113 goto out; 2110 goto out;
2114 reiserfs_update_inode_transaction(p_s_inode); 2111 reiserfs_update_inode_transaction(inode);
2115 if (update_timestamps) 2112 if (update_timestamps)
2116 /* we are doing real truncate: if the system crashes before the last 2113 /* we are doing real truncate: if the system crashes before the last
2117 transaction of truncating gets committed - on reboot the file 2114 transaction of truncating gets committed - on reboot the file
2118 either appears truncated properly or not truncated at all */ 2115 either appears truncated properly or not truncated at all */
2119 add_save_link(&th, p_s_inode, 1); 2116 add_save_link(&th, inode, 1);
2120 err2 = reiserfs_do_truncate(&th, p_s_inode, page, update_timestamps); 2117 err2 = reiserfs_do_truncate(&th, inode, page, update_timestamps);
2121 error = 2118 error =
2122 journal_end(&th, p_s_inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1); 2119 journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT * 2 + 1);
2123 if (error) 2120 if (error)
2124 goto out; 2121 goto out;
2125 2122
@@ -2130,7 +2127,7 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
2130 } 2127 }
2131 2128
2132 if (update_timestamps) { 2129 if (update_timestamps) {
2133 error = remove_save_link(p_s_inode, 1 /* truncate */ ); 2130 error = remove_save_link(inode, 1 /* truncate */);
2134 if (error) 2131 if (error)
2135 goto out; 2132 goto out;
2136 } 2133 }
@@ -2149,14 +2146,14 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
2149 page_cache_release(page); 2146 page_cache_release(page);
2150 } 2147 }
2151 2148
2152 reiserfs_write_unlock(p_s_inode->i_sb); 2149 reiserfs_write_unlock(inode->i_sb);
2153 return 0; 2150 return 0;
2154 out: 2151 out:
2155 if (page) { 2152 if (page) {
2156 unlock_page(page); 2153 unlock_page(page);
2157 page_cache_release(page); 2154 page_cache_release(page);
2158 } 2155 }
2159 reiserfs_write_unlock(p_s_inode->i_sb); 2156 reiserfs_write_unlock(inode->i_sb);
2160 return error; 2157 return error;
2161} 2158}
2162 2159
@@ -2208,9 +2205,8 @@ static int map_block_for_writepage(struct inode *inode,
2208 /* we've found an unformatted node */ 2205 /* we've found an unformatted node */
2209 if (indirect_item_found(retval, ih)) { 2206 if (indirect_item_found(retval, ih)) {
2210 if (bytes_copied > 0) { 2207 if (bytes_copied > 0) {
2211 reiserfs_warning(inode->i_sb, 2208 reiserfs_warning(inode->i_sb, "clm-6002",
2212 "clm-6002: bytes_copied %d", 2209 "bytes_copied %d", bytes_copied);
2213 bytes_copied);
2214 } 2210 }
2215 if (!get_block_num(item, pos_in_item)) { 2211 if (!get_block_num(item, pos_in_item)) {
2216 /* crap, we are writing to a hole */ 2212 /* crap, we are writing to a hole */
@@ -2267,9 +2263,8 @@ static int map_block_for_writepage(struct inode *inode,
2267 goto research; 2263 goto research;
2268 } 2264 }
2269 } else { 2265 } else {
2270 reiserfs_warning(inode->i_sb, 2266 reiserfs_warning(inode->i_sb, "clm-6003",
2271 "clm-6003: bad item inode %lu, device %s", 2267 "bad item inode %lu", inode->i_ino);
2272 inode->i_ino, reiserfs_bdevname(inode->i_sb));
2273 retval = -EIO; 2268 retval = -EIO;
2274 goto out; 2269 goto out;
2275 } 2270 }
@@ -2312,8 +2307,8 @@ static int map_block_for_writepage(struct inode *inode,
2312 return retval; 2307 return retval;
2313} 2308}
2314 2309
2315/* 2310/*
2316 * mason@suse.com: updated in 2.5.54 to follow the same general io 2311 * mason@suse.com: updated in 2.5.54 to follow the same general io
2317 * start/recovery path as __block_write_full_page, along with special 2312 * start/recovery path as __block_write_full_page, along with special
2318 * code to handle reiserfs tails. 2313 * code to handle reiserfs tails.
2319 */ 2314 */
@@ -2453,7 +2448,7 @@ static int reiserfs_write_full_page(struct page *page,
2453 unlock_page(page); 2448 unlock_page(page);
2454 2449
2455 /* 2450 /*
2456 * since any buffer might be the only dirty buffer on the page, 2451 * since any buffer might be the only dirty buffer on the page,
2457 * the first submit_bh can bring the page out of writeback. 2452 * the first submit_bh can bring the page out of writeback.
2458 * be careful with the buffers. 2453 * be careful with the buffers.
2459 */ 2454 */
@@ -2472,8 +2467,8 @@ static int reiserfs_write_full_page(struct page *page,
2472 if (nr == 0) { 2467 if (nr == 0) {
2473 /* 2468 /*
2474 * if this page only had a direct item, it is very possible for 2469 * if this page only had a direct item, it is very possible for
2475 * no io to be required without there being an error. Or, 2470 * no io to be required without there being an error. Or,
2476 * someone else could have locked them and sent them down the 2471 * someone else could have locked them and sent them down the
2477 * pipe without locking the page 2472 * pipe without locking the page
2478 */ 2473 */
2479 bh = head; 2474 bh = head;
@@ -2492,7 +2487,7 @@ static int reiserfs_write_full_page(struct page *page,
2492 2487
2493 fail: 2488 fail:
2494 /* catches various errors, we need to make sure any valid dirty blocks 2489 /* catches various errors, we need to make sure any valid dirty blocks
2495 * get to the media. The page is currently locked and not marked for 2490 * get to the media. The page is currently locked and not marked for
2496 * writeback 2491 * writeback
2497 */ 2492 */
2498 ClearPageUptodate(page); 2493 ClearPageUptodate(page);
@@ -3119,7 +3114,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
3119 if (error) 3114 if (error)
3120 goto out; 3115 goto out;
3121 error = 3116 error =
3122 DQUOT_TRANSFER(inode, attr) ? -EDQUOT : 0; 3117 vfs_dq_transfer(inode, attr) ? -EDQUOT : 0;
3123 if (error) { 3118 if (error) {
3124 journal_end(&th, inode->i_sb, 3119 journal_end(&th, inode->i_sb,
3125 jbegin_count); 3120 jbegin_count);
diff --git a/fs/reiserfs/ioctl.c b/fs/reiserfs/ioctl.c
index 830332021ed..0ccc3fdda7b 100644
--- a/fs/reiserfs/ioctl.c
+++ b/fs/reiserfs/ioctl.c
@@ -189,7 +189,7 @@ int reiserfs_unpack(struct inode *inode, struct file *filp)
189 } 189 }
190 190
191 /* we unpack by finding the page with the tail, and calling 191 /* we unpack by finding the page with the tail, and calling
192 ** reiserfs_prepare_write on that page. This will force a 192 ** reiserfs_prepare_write on that page. This will force a
193 ** reiserfs_get_block to unpack the tail for us. 193 ** reiserfs_get_block to unpack the tail for us.
194 */ 194 */
195 index = inode->i_size >> PAGE_CACHE_SHIFT; 195 index = inode->i_size >> PAGE_CACHE_SHIFT;
diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
index 9475557ab49..72cb1cc51b8 100644
--- a/fs/reiserfs/item_ops.c
+++ b/fs/reiserfs/item_ops.c
@@ -97,7 +97,8 @@ static int sd_unit_num(struct virtual_item *vi)
97 97
98static void sd_print_vi(struct virtual_item *vi) 98static void sd_print_vi(struct virtual_item *vi)
99{ 99{
100 reiserfs_warning(NULL, "STATDATA, index %d, type 0x%x, %h", 100 reiserfs_warning(NULL, "reiserfs-16100",
101 "STATDATA, index %d, type 0x%x, %h",
101 vi->vi_index, vi->vi_type, vi->vi_ih); 102 vi->vi_index, vi->vi_type, vi->vi_ih);
102} 103}
103 104
@@ -190,7 +191,8 @@ static int direct_unit_num(struct virtual_item *vi)
190 191
191static void direct_print_vi(struct virtual_item *vi) 192static void direct_print_vi(struct virtual_item *vi)
192{ 193{
193 reiserfs_warning(NULL, "DIRECT, index %d, type 0x%x, %h", 194 reiserfs_warning(NULL, "reiserfs-16101",
195 "DIRECT, index %d, type 0x%x, %h",
194 vi->vi_index, vi->vi_type, vi->vi_ih); 196 vi->vi_index, vi->vi_type, vi->vi_ih);
195} 197}
196 198
@@ -278,7 +280,7 @@ static void indirect_print_item(struct item_head *ih, char *item)
278 unp = (__le32 *) item; 280 unp = (__le32 *) item;
279 281
280 if (ih_item_len(ih) % UNFM_P_SIZE) 282 if (ih_item_len(ih) % UNFM_P_SIZE)
281 reiserfs_warning(NULL, "indirect_print_item: invalid item len"); 283 reiserfs_warning(NULL, "reiserfs-16102", "invalid item len");
282 284
283 printk("%d pointers\n[ ", (int)I_UNFM_NUM(ih)); 285 printk("%d pointers\n[ ", (int)I_UNFM_NUM(ih));
284 for (j = 0; j < I_UNFM_NUM(ih); j++) { 286 for (j = 0; j < I_UNFM_NUM(ih); j++) {
@@ -334,7 +336,8 @@ static int indirect_unit_num(struct virtual_item *vi)
334 336
335static void indirect_print_vi(struct virtual_item *vi) 337static void indirect_print_vi(struct virtual_item *vi)
336{ 338{
337 reiserfs_warning(NULL, "INDIRECT, index %d, type 0x%x, %h", 339 reiserfs_warning(NULL, "reiserfs-16103",
340 "INDIRECT, index %d, type 0x%x, %h",
338 vi->vi_index, vi->vi_type, vi->vi_ih); 341 vi->vi_index, vi->vi_type, vi->vi_ih);
339} 342}
340 343
@@ -359,7 +362,7 @@ static struct item_operations indirect_ops = {
359 362
360static int direntry_bytes_number(struct item_head *ih, int block_size) 363static int direntry_bytes_number(struct item_head *ih, int block_size)
361{ 364{
362 reiserfs_warning(NULL, "vs-16090: direntry_bytes_number: " 365 reiserfs_warning(NULL, "vs-16090",
363 "bytes number is asked for direntry"); 366 "bytes number is asked for direntry");
364 return 0; 367 return 0;
365} 368}
@@ -514,8 +517,9 @@ static int direntry_create_vi(struct virtual_node *vn,
514 ((is_affected 517 ((is_affected
515 && (vn->vn_mode == M_PASTE 518 && (vn->vn_mode == M_PASTE
516 || vn->vn_mode == M_CUT)) ? insert_size : 0)) { 519 || vn->vn_mode == M_CUT)) ? insert_size : 0)) {
517 reiserfs_panic(NULL, 520 reiserfs_panic(NULL, "vs-8025", "(mode==%c, "
518 "vs-8025: set_entry_sizes: (mode==%c, insert_size==%d), invalid length of directory item", 521 "insert_size==%d), invalid length of "
522 "directory item",
519 vn->vn_mode, insert_size); 523 vn->vn_mode, insert_size);
520 } 524 }
521 } 525 }
@@ -546,7 +550,8 @@ static int direntry_check_left(struct virtual_item *vi, int free,
546 } 550 }
547 551
548 if (entries == dir_u->entry_count) { 552 if (entries == dir_u->entry_count) {
549 reiserfs_panic(NULL, "free space %d, entry_count %d\n", free, 553 reiserfs_panic(NULL, "item_ops-1",
554 "free space %d, entry_count %d", free,
550 dir_u->entry_count); 555 dir_u->entry_count);
551 } 556 }
552 557
@@ -614,7 +619,8 @@ static void direntry_print_vi(struct virtual_item *vi)
614 int i; 619 int i;
615 struct direntry_uarea *dir_u = vi->vi_uarea; 620 struct direntry_uarea *dir_u = vi->vi_uarea;
616 621
617 reiserfs_warning(NULL, "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x", 622 reiserfs_warning(NULL, "reiserfs-16104",
623 "DIRENTRY, index %d, type 0x%x, %h, flags 0x%x",
618 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags); 624 vi->vi_index, vi->vi_type, vi->vi_ih, dir_u->flags);
619 printk("%d entries: ", dir_u->entry_count); 625 printk("%d entries: ", dir_u->entry_count);
620 for (i = 0; i < dir_u->entry_count; i++) 626 for (i = 0; i < dir_u->entry_count; i++)
@@ -642,43 +648,43 @@ static struct item_operations direntry_ops = {
642// 648//
643static int errcatch_bytes_number(struct item_head *ih, int block_size) 649static int errcatch_bytes_number(struct item_head *ih, int block_size)
644{ 650{
645 reiserfs_warning(NULL, 651 reiserfs_warning(NULL, "green-16001",
646 "green-16001: Invalid item type observed, run fsck ASAP"); 652 "Invalid item type observed, run fsck ASAP");
647 return 0; 653 return 0;
648} 654}
649 655
650static void errcatch_decrement_key(struct cpu_key *key) 656static void errcatch_decrement_key(struct cpu_key *key)
651{ 657{
652 reiserfs_warning(NULL, 658 reiserfs_warning(NULL, "green-16002",
653 "green-16002: Invalid item type observed, run fsck ASAP"); 659 "Invalid item type observed, run fsck ASAP");
654} 660}
655 661
656static int errcatch_is_left_mergeable(struct reiserfs_key *key, 662static int errcatch_is_left_mergeable(struct reiserfs_key *key,
657 unsigned long bsize) 663 unsigned long bsize)
658{ 664{
659 reiserfs_warning(NULL, 665 reiserfs_warning(NULL, "green-16003",
660 "green-16003: Invalid item type observed, run fsck ASAP"); 666 "Invalid item type observed, run fsck ASAP");
661 return 0; 667 return 0;
662} 668}
663 669
664static void errcatch_print_item(struct item_head *ih, char *item) 670static void errcatch_print_item(struct item_head *ih, char *item)
665{ 671{
666 reiserfs_warning(NULL, 672 reiserfs_warning(NULL, "green-16004",
667 "green-16004: Invalid item type observed, run fsck ASAP"); 673 "Invalid item type observed, run fsck ASAP");
668} 674}
669 675
670static void errcatch_check_item(struct item_head *ih, char *item) 676static void errcatch_check_item(struct item_head *ih, char *item)
671{ 677{
672 reiserfs_warning(NULL, 678 reiserfs_warning(NULL, "green-16005",
673 "green-16005: Invalid item type observed, run fsck ASAP"); 679 "Invalid item type observed, run fsck ASAP");
674} 680}
675 681
676static int errcatch_create_vi(struct virtual_node *vn, 682static int errcatch_create_vi(struct virtual_node *vn,
677 struct virtual_item *vi, 683 struct virtual_item *vi,
678 int is_affected, int insert_size) 684 int is_affected, int insert_size)
679{ 685{
680 reiserfs_warning(NULL, 686 reiserfs_warning(NULL, "green-16006",
681 "green-16006: Invalid item type observed, run fsck ASAP"); 687 "Invalid item type observed, run fsck ASAP");
682 return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where 688 return 0; // We might return -1 here as well, but it won't help as create_virtual_node() from where
683 // this operation is called from is of return type void. 689 // this operation is called from is of return type void.
684} 690}
@@ -686,36 +692,36 @@ static int errcatch_create_vi(struct virtual_node *vn,
686static int errcatch_check_left(struct virtual_item *vi, int free, 692static int errcatch_check_left(struct virtual_item *vi, int free,
687 int start_skip, int end_skip) 693 int start_skip, int end_skip)
688{ 694{
689 reiserfs_warning(NULL, 695 reiserfs_warning(NULL, "green-16007",
690 "green-16007: Invalid item type observed, run fsck ASAP"); 696 "Invalid item type observed, run fsck ASAP");
691 return -1; 697 return -1;
692} 698}
693 699
694static int errcatch_check_right(struct virtual_item *vi, int free) 700static int errcatch_check_right(struct virtual_item *vi, int free)
695{ 701{
696 reiserfs_warning(NULL, 702 reiserfs_warning(NULL, "green-16008",
697 "green-16008: Invalid item type observed, run fsck ASAP"); 703 "Invalid item type observed, run fsck ASAP");
698 return -1; 704 return -1;
699} 705}
700 706
701static int errcatch_part_size(struct virtual_item *vi, int first, int count) 707static int errcatch_part_size(struct virtual_item *vi, int first, int count)
702{ 708{
703 reiserfs_warning(NULL, 709 reiserfs_warning(NULL, "green-16009",
704 "green-16009: Invalid item type observed, run fsck ASAP"); 710 "Invalid item type observed, run fsck ASAP");
705 return 0; 711 return 0;
706} 712}
707 713
708static int errcatch_unit_num(struct virtual_item *vi) 714static int errcatch_unit_num(struct virtual_item *vi)
709{ 715{
710 reiserfs_warning(NULL, 716 reiserfs_warning(NULL, "green-16010",
711 "green-16010: Invalid item type observed, run fsck ASAP"); 717 "Invalid item type observed, run fsck ASAP");
712 return 0; 718 return 0;
713} 719}
714 720
715static void errcatch_print_vi(struct virtual_item *vi) 721static void errcatch_print_vi(struct virtual_item *vi)
716{ 722{
717 reiserfs_warning(NULL, 723 reiserfs_warning(NULL, "green-16011",
718 "green-16011: Invalid item type observed, run fsck ASAP"); 724 "Invalid item type observed, run fsck ASAP");
719} 725}
720 726
721static struct item_operations errcatch_ops = { 727static struct item_operations errcatch_ops = {
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index 9643c3bbeb3..77f5bb746bf 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -1,36 +1,36 @@
1/* 1/*
2** Write ahead logging implementation copyright Chris Mason 2000 2** Write ahead logging implementation copyright Chris Mason 2000
3** 3**
4** The background commits make this code very interelated, and 4** The background commits make this code very interelated, and
5** overly complex. I need to rethink things a bit....The major players: 5** overly complex. I need to rethink things a bit....The major players:
6** 6**
7** journal_begin -- call with the number of blocks you expect to log. 7** journal_begin -- call with the number of blocks you expect to log.
8** If the current transaction is too 8** If the current transaction is too
9** old, it will block until the current transaction is 9** old, it will block until the current transaction is
10** finished, and then start a new one. 10** finished, and then start a new one.
11** Usually, your transaction will get joined in with 11** Usually, your transaction will get joined in with
12** previous ones for speed. 12** previous ones for speed.
13** 13**
14** journal_join -- same as journal_begin, but won't block on the current 14** journal_join -- same as journal_begin, but won't block on the current
15** transaction regardless of age. Don't ever call 15** transaction regardless of age. Don't ever call
16** this. Ever. There are only two places it should be 16** this. Ever. There are only two places it should be
17** called from, and they are both inside this file. 17** called from, and they are both inside this file.
18** 18**
19** journal_mark_dirty -- adds blocks into this transaction. clears any flags 19** journal_mark_dirty -- adds blocks into this transaction. clears any flags
20** that might make them get sent to disk 20** that might make them get sent to disk
21** and then marks them BH_JDirty. Puts the buffer head 21** and then marks them BH_JDirty. Puts the buffer head
22** into the current transaction hash. 22** into the current transaction hash.
23** 23**
24** journal_end -- if the current transaction is batchable, it does nothing 24** journal_end -- if the current transaction is batchable, it does nothing
25** otherwise, it could do an async/synchronous commit, or 25** otherwise, it could do an async/synchronous commit, or
26** a full flush of all log and real blocks in the 26** a full flush of all log and real blocks in the
27** transaction. 27** transaction.
28** 28**
29** flush_old_commits -- if the current transaction is too old, it is ended and 29** flush_old_commits -- if the current transaction is too old, it is ended and
30** commit blocks are sent to disk. Forces commit blocks 30** commit blocks are sent to disk. Forces commit blocks
31** to disk for all backgrounded commits that have been 31** to disk for all backgrounded commits that have been
32** around too long. 32** around too long.
33** -- Note, if you call this as an immediate flush from 33** -- Note, if you call this as an immediate flush from
34** from within kupdate, it will ignore the immediate flag 34** from within kupdate, it will ignore the immediate flag
35*/ 35*/
36 36
@@ -97,7 +97,7 @@ static int flush_commit_list(struct super_block *s,
97 struct reiserfs_journal_list *jl, int flushall); 97 struct reiserfs_journal_list *jl, int flushall);
98static int can_dirty(struct reiserfs_journal_cnode *cn); 98static int can_dirty(struct reiserfs_journal_cnode *cn);
99static int journal_join(struct reiserfs_transaction_handle *th, 99static int journal_join(struct reiserfs_transaction_handle *th,
100 struct super_block *p_s_sb, unsigned long nblocks); 100 struct super_block *sb, unsigned long nblocks);
101static int release_journal_dev(struct super_block *super, 101static int release_journal_dev(struct super_block *super,
102 struct reiserfs_journal *journal); 102 struct reiserfs_journal *journal);
103static int dirty_one_transaction(struct super_block *s, 103static int dirty_one_transaction(struct super_block *s,
@@ -113,12 +113,12 @@ enum {
113}; 113};
114 114
115static int do_journal_begin_r(struct reiserfs_transaction_handle *th, 115static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
116 struct super_block *p_s_sb, 116 struct super_block *sb,
117 unsigned long nblocks, int join); 117 unsigned long nblocks, int join);
118 118
119static void init_journal_hash(struct super_block *p_s_sb) 119static void init_journal_hash(struct super_block *sb)
120{ 120{
121 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 121 struct reiserfs_journal *journal = SB_JOURNAL(sb);
122 memset(journal->j_hash_table, 0, 122 memset(journal->j_hash_table, 0,
123 JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *)); 123 JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *));
124} 124}
@@ -145,7 +145,7 @@ static void disable_barrier(struct super_block *s)
145} 145}
146 146
147static struct reiserfs_bitmap_node *allocate_bitmap_node(struct super_block 147static struct reiserfs_bitmap_node *allocate_bitmap_node(struct super_block
148 *p_s_sb) 148 *sb)
149{ 149{
150 struct reiserfs_bitmap_node *bn; 150 struct reiserfs_bitmap_node *bn;
151 static int id; 151 static int id;
@@ -154,7 +154,7 @@ static struct reiserfs_bitmap_node *allocate_bitmap_node(struct super_block
154 if (!bn) { 154 if (!bn) {
155 return NULL; 155 return NULL;
156 } 156 }
157 bn->data = kzalloc(p_s_sb->s_blocksize, GFP_NOFS); 157 bn->data = kzalloc(sb->s_blocksize, GFP_NOFS);
158 if (!bn->data) { 158 if (!bn->data) {
159 kfree(bn); 159 kfree(bn);
160 return NULL; 160 return NULL;
@@ -164,9 +164,9 @@ static struct reiserfs_bitmap_node *allocate_bitmap_node(struct super_block
164 return bn; 164 return bn;
165} 165}
166 166
167static struct reiserfs_bitmap_node *get_bitmap_node(struct super_block *p_s_sb) 167static struct reiserfs_bitmap_node *get_bitmap_node(struct super_block *sb)
168{ 168{
169 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 169 struct reiserfs_journal *journal = SB_JOURNAL(sb);
170 struct reiserfs_bitmap_node *bn = NULL; 170 struct reiserfs_bitmap_node *bn = NULL;
171 struct list_head *entry = journal->j_bitmap_nodes.next; 171 struct list_head *entry = journal->j_bitmap_nodes.next;
172 172
@@ -176,21 +176,21 @@ static struct reiserfs_bitmap_node *get_bitmap_node(struct super_block *p_s_sb)
176 if (entry != &journal->j_bitmap_nodes) { 176 if (entry != &journal->j_bitmap_nodes) {
177 bn = list_entry(entry, struct reiserfs_bitmap_node, list); 177 bn = list_entry(entry, struct reiserfs_bitmap_node, list);
178 list_del(entry); 178 list_del(entry);
179 memset(bn->data, 0, p_s_sb->s_blocksize); 179 memset(bn->data, 0, sb->s_blocksize);
180 journal->j_free_bitmap_nodes--; 180 journal->j_free_bitmap_nodes--;
181 return bn; 181 return bn;
182 } 182 }
183 bn = allocate_bitmap_node(p_s_sb); 183 bn = allocate_bitmap_node(sb);
184 if (!bn) { 184 if (!bn) {
185 yield(); 185 yield();
186 goto repeat; 186 goto repeat;
187 } 187 }
188 return bn; 188 return bn;
189} 189}
190static inline void free_bitmap_node(struct super_block *p_s_sb, 190static inline void free_bitmap_node(struct super_block *sb,
191 struct reiserfs_bitmap_node *bn) 191 struct reiserfs_bitmap_node *bn)
192{ 192{
193 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 193 struct reiserfs_journal *journal = SB_JOURNAL(sb);
194 journal->j_used_bitmap_nodes--; 194 journal->j_used_bitmap_nodes--;
195 if (journal->j_free_bitmap_nodes > REISERFS_MAX_BITMAP_NODES) { 195 if (journal->j_free_bitmap_nodes > REISERFS_MAX_BITMAP_NODES) {
196 kfree(bn->data); 196 kfree(bn->data);
@@ -201,46 +201,46 @@ static inline void free_bitmap_node(struct super_block *p_s_sb,
201 } 201 }
202} 202}
203 203
204static void allocate_bitmap_nodes(struct super_block *p_s_sb) 204static void allocate_bitmap_nodes(struct super_block *sb)
205{ 205{
206 int i; 206 int i;
207 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 207 struct reiserfs_journal *journal = SB_JOURNAL(sb);
208 struct reiserfs_bitmap_node *bn = NULL; 208 struct reiserfs_bitmap_node *bn = NULL;
209 for (i = 0; i < REISERFS_MIN_BITMAP_NODES; i++) { 209 for (i = 0; i < REISERFS_MIN_BITMAP_NODES; i++) {
210 bn = allocate_bitmap_node(p_s_sb); 210 bn = allocate_bitmap_node(sb);
211 if (bn) { 211 if (bn) {
212 list_add(&bn->list, &journal->j_bitmap_nodes); 212 list_add(&bn->list, &journal->j_bitmap_nodes);
213 journal->j_free_bitmap_nodes++; 213 journal->j_free_bitmap_nodes++;
214 } else { 214 } else {
215 break; // this is ok, we'll try again when more are needed 215 break; /* this is ok, we'll try again when more are needed */
216 } 216 }
217 } 217 }
218} 218}
219 219
220static int set_bit_in_list_bitmap(struct super_block *p_s_sb, 220static int set_bit_in_list_bitmap(struct super_block *sb,
221 b_blocknr_t block, 221 b_blocknr_t block,
222 struct reiserfs_list_bitmap *jb) 222 struct reiserfs_list_bitmap *jb)
223{ 223{
224 unsigned int bmap_nr = block / (p_s_sb->s_blocksize << 3); 224 unsigned int bmap_nr = block / (sb->s_blocksize << 3);
225 unsigned int bit_nr = block % (p_s_sb->s_blocksize << 3); 225 unsigned int bit_nr = block % (sb->s_blocksize << 3);
226 226
227 if (!jb->bitmaps[bmap_nr]) { 227 if (!jb->bitmaps[bmap_nr]) {
228 jb->bitmaps[bmap_nr] = get_bitmap_node(p_s_sb); 228 jb->bitmaps[bmap_nr] = get_bitmap_node(sb);
229 } 229 }
230 set_bit(bit_nr, (unsigned long *)jb->bitmaps[bmap_nr]->data); 230 set_bit(bit_nr, (unsigned long *)jb->bitmaps[bmap_nr]->data);
231 return 0; 231 return 0;
232} 232}
233 233
234static void cleanup_bitmap_list(struct super_block *p_s_sb, 234static void cleanup_bitmap_list(struct super_block *sb,
235 struct reiserfs_list_bitmap *jb) 235 struct reiserfs_list_bitmap *jb)
236{ 236{
237 int i; 237 int i;
238 if (jb->bitmaps == NULL) 238 if (jb->bitmaps == NULL)
239 return; 239 return;
240 240
241 for (i = 0; i < reiserfs_bmap_count(p_s_sb); i++) { 241 for (i = 0; i < reiserfs_bmap_count(sb); i++) {
242 if (jb->bitmaps[i]) { 242 if (jb->bitmaps[i]) {
243 free_bitmap_node(p_s_sb, jb->bitmaps[i]); 243 free_bitmap_node(sb, jb->bitmaps[i]);
244 jb->bitmaps[i] = NULL; 244 jb->bitmaps[i] = NULL;
245 } 245 }
246 } 246 }
@@ -249,7 +249,7 @@ static void cleanup_bitmap_list(struct super_block *p_s_sb,
249/* 249/*
250** only call this on FS unmount. 250** only call this on FS unmount.
251*/ 251*/
252static int free_list_bitmaps(struct super_block *p_s_sb, 252static int free_list_bitmaps(struct super_block *sb,
253 struct reiserfs_list_bitmap *jb_array) 253 struct reiserfs_list_bitmap *jb_array)
254{ 254{
255 int i; 255 int i;
@@ -257,16 +257,16 @@ static int free_list_bitmaps(struct super_block *p_s_sb,
257 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) { 257 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
258 jb = jb_array + i; 258 jb = jb_array + i;
259 jb->journal_list = NULL; 259 jb->journal_list = NULL;
260 cleanup_bitmap_list(p_s_sb, jb); 260 cleanup_bitmap_list(sb, jb);
261 vfree(jb->bitmaps); 261 vfree(jb->bitmaps);
262 jb->bitmaps = NULL; 262 jb->bitmaps = NULL;
263 } 263 }
264 return 0; 264 return 0;
265} 265}
266 266
267static int free_bitmap_nodes(struct super_block *p_s_sb) 267static int free_bitmap_nodes(struct super_block *sb)
268{ 268{
269 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 269 struct reiserfs_journal *journal = SB_JOURNAL(sb);
270 struct list_head *next = journal->j_bitmap_nodes.next; 270 struct list_head *next = journal->j_bitmap_nodes.next;
271 struct reiserfs_bitmap_node *bn; 271 struct reiserfs_bitmap_node *bn;
272 272
@@ -283,10 +283,10 @@ static int free_bitmap_nodes(struct super_block *p_s_sb)
283} 283}
284 284
285/* 285/*
286** get memory for JOURNAL_NUM_BITMAPS worth of bitmaps. 286** get memory for JOURNAL_NUM_BITMAPS worth of bitmaps.
287** jb_array is the array to be filled in. 287** jb_array is the array to be filled in.
288*/ 288*/
289int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb, 289int reiserfs_allocate_list_bitmaps(struct super_block *sb,
290 struct reiserfs_list_bitmap *jb_array, 290 struct reiserfs_list_bitmap *jb_array,
291 unsigned int bmap_nr) 291 unsigned int bmap_nr)
292{ 292{
@@ -300,30 +300,30 @@ int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb,
300 jb->journal_list = NULL; 300 jb->journal_list = NULL;
301 jb->bitmaps = vmalloc(mem); 301 jb->bitmaps = vmalloc(mem);
302 if (!jb->bitmaps) { 302 if (!jb->bitmaps) {
303 reiserfs_warning(p_s_sb, 303 reiserfs_warning(sb, "clm-2000", "unable to "
304 "clm-2000, unable to allocate bitmaps for journal lists"); 304 "allocate bitmaps for journal lists");
305 failed = 1; 305 failed = 1;
306 break; 306 break;
307 } 307 }
308 memset(jb->bitmaps, 0, mem); 308 memset(jb->bitmaps, 0, mem);
309 } 309 }
310 if (failed) { 310 if (failed) {
311 free_list_bitmaps(p_s_sb, jb_array); 311 free_list_bitmaps(sb, jb_array);
312 return -1; 312 return -1;
313 } 313 }
314 return 0; 314 return 0;
315} 315}
316 316
317/* 317/*
318** find an available list bitmap. If you can't find one, flush a commit list 318** find an available list bitmap. If you can't find one, flush a commit list
319** and try again 319** and try again
320*/ 320*/
321static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *p_s_sb, 321static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *sb,
322 struct reiserfs_journal_list 322 struct reiserfs_journal_list
323 *jl) 323 *jl)
324{ 324{
325 int i, j; 325 int i, j;
326 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 326 struct reiserfs_journal *journal = SB_JOURNAL(sb);
327 struct reiserfs_list_bitmap *jb = NULL; 327 struct reiserfs_list_bitmap *jb = NULL;
328 328
329 for (j = 0; j < (JOURNAL_NUM_BITMAPS * 3); j++) { 329 for (j = 0; j < (JOURNAL_NUM_BITMAPS * 3); j++) {
@@ -331,7 +331,7 @@ static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *p_s_sb,
331 journal->j_list_bitmap_index = (i + 1) % JOURNAL_NUM_BITMAPS; 331 journal->j_list_bitmap_index = (i + 1) % JOURNAL_NUM_BITMAPS;
332 jb = journal->j_list_bitmap + i; 332 jb = journal->j_list_bitmap + i;
333 if (journal->j_list_bitmap[i].journal_list) { 333 if (journal->j_list_bitmap[i].journal_list) {
334 flush_commit_list(p_s_sb, 334 flush_commit_list(sb,
335 journal->j_list_bitmap[i]. 335 journal->j_list_bitmap[i].
336 journal_list, 1); 336 journal_list, 1);
337 if (!journal->j_list_bitmap[i].journal_list) { 337 if (!journal->j_list_bitmap[i].journal_list) {
@@ -348,7 +348,7 @@ static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *p_s_sb,
348 return jb; 348 return jb;
349} 349}
350 350
351/* 351/*
352** allocates a new chunk of X nodes, and links them all together as a list. 352** allocates a new chunk of X nodes, and links them all together as a list.
353** Uses the cnode->next and cnode->prev pointers 353** Uses the cnode->next and cnode->prev pointers
354** returns NULL on failure 354** returns NULL on failure
@@ -376,14 +376,14 @@ static struct reiserfs_journal_cnode *allocate_cnodes(int num_cnodes)
376} 376}
377 377
378/* 378/*
379** pulls a cnode off the free list, or returns NULL on failure 379** pulls a cnode off the free list, or returns NULL on failure
380*/ 380*/
381static struct reiserfs_journal_cnode *get_cnode(struct super_block *p_s_sb) 381static struct reiserfs_journal_cnode *get_cnode(struct super_block *sb)
382{ 382{
383 struct reiserfs_journal_cnode *cn; 383 struct reiserfs_journal_cnode *cn;
384 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 384 struct reiserfs_journal *journal = SB_JOURNAL(sb);
385 385
386 reiserfs_check_lock_depth(p_s_sb, "get_cnode"); 386 reiserfs_check_lock_depth(sb, "get_cnode");
387 387
388 if (journal->j_cnode_free <= 0) { 388 if (journal->j_cnode_free <= 0) {
389 return NULL; 389 return NULL;
@@ -403,14 +403,14 @@ static struct reiserfs_journal_cnode *get_cnode(struct super_block *p_s_sb)
403} 403}
404 404
405/* 405/*
406** returns a cnode to the free list 406** returns a cnode to the free list
407*/ 407*/
408static void free_cnode(struct super_block *p_s_sb, 408static void free_cnode(struct super_block *sb,
409 struct reiserfs_journal_cnode *cn) 409 struct reiserfs_journal_cnode *cn)
410{ 410{
411 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 411 struct reiserfs_journal *journal = SB_JOURNAL(sb);
412 412
413 reiserfs_check_lock_depth(p_s_sb, "free_cnode"); 413 reiserfs_check_lock_depth(sb, "free_cnode");
414 414
415 journal->j_cnode_used--; 415 journal->j_cnode_used--;
416 journal->j_cnode_free++; 416 journal->j_cnode_free++;
@@ -436,8 +436,8 @@ void reiserfs_check_lock_depth(struct super_block *sb, char *caller)
436{ 436{
437#ifdef CONFIG_SMP 437#ifdef CONFIG_SMP
438 if (current->lock_depth < 0) { 438 if (current->lock_depth < 0) {
439 reiserfs_panic(sb, "%s called without kernel lock held", 439 reiserfs_panic(sb, "journal-1", "%s called without kernel "
440 caller); 440 "lock held", caller);
441 } 441 }
442#else 442#else
443 ; 443 ;
@@ -481,11 +481,11 @@ static inline struct reiserfs_journal_cnode *get_journal_hash_dev(struct
481** reject it on the next call to reiserfs_in_journal 481** reject it on the next call to reiserfs_in_journal
482** 482**
483*/ 483*/
484int reiserfs_in_journal(struct super_block *p_s_sb, 484int reiserfs_in_journal(struct super_block *sb,
485 unsigned int bmap_nr, int bit_nr, int search_all, 485 unsigned int bmap_nr, int bit_nr, int search_all,
486 b_blocknr_t * next_zero_bit) 486 b_blocknr_t * next_zero_bit)
487{ 487{
488 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 488 struct reiserfs_journal *journal = SB_JOURNAL(sb);
489 struct reiserfs_journal_cnode *cn; 489 struct reiserfs_journal_cnode *cn;
490 struct reiserfs_list_bitmap *jb; 490 struct reiserfs_list_bitmap *jb;
491 int i; 491 int i;
@@ -493,14 +493,14 @@ int reiserfs_in_journal(struct super_block *p_s_sb,
493 493
494 *next_zero_bit = 0; /* always start this at zero. */ 494 *next_zero_bit = 0; /* always start this at zero. */
495 495
496 PROC_INFO_INC(p_s_sb, journal.in_journal); 496 PROC_INFO_INC(sb, journal.in_journal);
497 /* If we aren't doing a search_all, this is a metablock, and it will be logged before use. 497 /* If we aren't doing a search_all, this is a metablock, and it will be logged before use.
498 ** if we crash before the transaction that freed it commits, this transaction won't 498 ** if we crash before the transaction that freed it commits, this transaction won't
499 ** have committed either, and the block will never be written 499 ** have committed either, and the block will never be written
500 */ 500 */
501 if (search_all) { 501 if (search_all) {
502 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) { 502 for (i = 0; i < JOURNAL_NUM_BITMAPS; i++) {
503 PROC_INFO_INC(p_s_sb, journal.in_journal_bitmap); 503 PROC_INFO_INC(sb, journal.in_journal_bitmap);
504 jb = journal->j_list_bitmap + i; 504 jb = journal->j_list_bitmap + i;
505 if (jb->journal_list && jb->bitmaps[bmap_nr] && 505 if (jb->journal_list && jb->bitmaps[bmap_nr] &&
506 test_bit(bit_nr, 506 test_bit(bit_nr,
@@ -510,28 +510,28 @@ int reiserfs_in_journal(struct super_block *p_s_sb,
510 find_next_zero_bit((unsigned long *) 510 find_next_zero_bit((unsigned long *)
511 (jb->bitmaps[bmap_nr]-> 511 (jb->bitmaps[bmap_nr]->
512 data), 512 data),
513 p_s_sb->s_blocksize << 3, 513 sb->s_blocksize << 3,
514 bit_nr + 1); 514 bit_nr + 1);
515 return 1; 515 return 1;
516 } 516 }
517 } 517 }
518 } 518 }
519 519
520 bl = bmap_nr * (p_s_sb->s_blocksize << 3) + bit_nr; 520 bl = bmap_nr * (sb->s_blocksize << 3) + bit_nr;
521 /* is it in any old transactions? */ 521 /* is it in any old transactions? */
522 if (search_all 522 if (search_all
523 && (cn = 523 && (cn =
524 get_journal_hash_dev(p_s_sb, journal->j_list_hash_table, bl))) { 524 get_journal_hash_dev(sb, journal->j_list_hash_table, bl))) {
525 return 1; 525 return 1;
526 } 526 }
527 527
528 /* is it in the current transaction. This should never happen */ 528 /* is it in the current transaction. This should never happen */
529 if ((cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, bl))) { 529 if ((cn = get_journal_hash_dev(sb, journal->j_hash_table, bl))) {
530 BUG(); 530 BUG();
531 return 1; 531 return 1;
532 } 532 }
533 533
534 PROC_INFO_INC(p_s_sb, journal.in_journal_reusable); 534 PROC_INFO_INC(sb, journal.in_journal_reusable);
535 /* safe for reuse */ 535 /* safe for reuse */
536 return 0; 536 return 0;
537} 537}
@@ -553,16 +553,16 @@ static inline void insert_journal_hash(struct reiserfs_journal_cnode **table,
553} 553}
554 554
555/* lock the current transaction */ 555/* lock the current transaction */
556static inline void lock_journal(struct super_block *p_s_sb) 556static inline void lock_journal(struct super_block *sb)
557{ 557{
558 PROC_INFO_INC(p_s_sb, journal.lock_journal); 558 PROC_INFO_INC(sb, journal.lock_journal);
559 mutex_lock(&SB_JOURNAL(p_s_sb)->j_mutex); 559 mutex_lock(&SB_JOURNAL(sb)->j_mutex);
560} 560}
561 561
562/* unlock the current transaction */ 562/* unlock the current transaction */
563static inline void unlock_journal(struct super_block *p_s_sb) 563static inline void unlock_journal(struct super_block *sb)
564{ 564{
565 mutex_unlock(&SB_JOURNAL(p_s_sb)->j_mutex); 565 mutex_unlock(&SB_JOURNAL(sb)->j_mutex);
566} 566}
567 567
568static inline void get_journal_list(struct reiserfs_journal_list *jl) 568static inline void get_journal_list(struct reiserfs_journal_list *jl)
@@ -574,7 +574,7 @@ static inline void put_journal_list(struct super_block *s,
574 struct reiserfs_journal_list *jl) 574 struct reiserfs_journal_list *jl)
575{ 575{
576 if (jl->j_refcount < 1) { 576 if (jl->j_refcount < 1) {
577 reiserfs_panic(s, "trans id %lu, refcount at %d", 577 reiserfs_panic(s, "journal-2", "trans id %u, refcount at %d",
578 jl->j_trans_id, jl->j_refcount); 578 jl->j_trans_id, jl->j_refcount);
579 } 579 }
580 if (--jl->j_refcount == 0) 580 if (--jl->j_refcount == 0)
@@ -586,20 +586,20 @@ static inline void put_journal_list(struct super_block *s,
586** it gets called by flush_commit_list, and cleans up any data stored about blocks freed during a 586** it gets called by flush_commit_list, and cleans up any data stored about blocks freed during a
587** transaction. 587** transaction.
588*/ 588*/
589static void cleanup_freed_for_journal_list(struct super_block *p_s_sb, 589static void cleanup_freed_for_journal_list(struct super_block *sb,
590 struct reiserfs_journal_list *jl) 590 struct reiserfs_journal_list *jl)
591{ 591{
592 592
593 struct reiserfs_list_bitmap *jb = jl->j_list_bitmap; 593 struct reiserfs_list_bitmap *jb = jl->j_list_bitmap;
594 if (jb) { 594 if (jb) {
595 cleanup_bitmap_list(p_s_sb, jb); 595 cleanup_bitmap_list(sb, jb);
596 } 596 }
597 jl->j_list_bitmap->journal_list = NULL; 597 jl->j_list_bitmap->journal_list = NULL;
598 jl->j_list_bitmap = NULL; 598 jl->j_list_bitmap = NULL;
599} 599}
600 600
601static int journal_list_still_alive(struct super_block *s, 601static int journal_list_still_alive(struct super_block *s,
602 unsigned long trans_id) 602 unsigned int trans_id)
603{ 603{
604 struct reiserfs_journal *journal = SB_JOURNAL(s); 604 struct reiserfs_journal *journal = SB_JOURNAL(s);
605 struct list_head *entry = &journal->j_journal_list; 605 struct list_head *entry = &journal->j_journal_list;
@@ -644,8 +644,8 @@ static void reiserfs_end_buffer_io_sync(struct buffer_head *bh, int uptodate)
644 char b[BDEVNAME_SIZE]; 644 char b[BDEVNAME_SIZE];
645 645
646 if (buffer_journaled(bh)) { 646 if (buffer_journaled(bh)) {
647 reiserfs_warning(NULL, 647 reiserfs_warning(NULL, "clm-2084",
648 "clm-2084: pinned buffer %lu:%s sent to disk", 648 "pinned buffer %lu:%s sent to disk",
649 bh->b_blocknr, bdevname(bh->b_bdev, b)); 649 bh->b_blocknr, bdevname(bh->b_bdev, b));
650 } 650 }
651 if (uptodate) 651 if (uptodate)
@@ -933,9 +933,9 @@ static int flush_older_commits(struct super_block *s,
933 struct reiserfs_journal_list *other_jl; 933 struct reiserfs_journal_list *other_jl;
934 struct reiserfs_journal_list *first_jl; 934 struct reiserfs_journal_list *first_jl;
935 struct list_head *entry; 935 struct list_head *entry;
936 unsigned long trans_id = jl->j_trans_id; 936 unsigned int trans_id = jl->j_trans_id;
937 unsigned long other_trans_id; 937 unsigned int other_trans_id;
938 unsigned long first_trans_id; 938 unsigned int first_trans_id;
939 939
940 find_first: 940 find_first:
941 /* 941 /*
@@ -1014,7 +1014,7 @@ static int flush_commit_list(struct super_block *s,
1014 int i; 1014 int i;
1015 b_blocknr_t bn; 1015 b_blocknr_t bn;
1016 struct buffer_head *tbh = NULL; 1016 struct buffer_head *tbh = NULL;
1017 unsigned long trans_id = jl->j_trans_id; 1017 unsigned int trans_id = jl->j_trans_id;
1018 struct reiserfs_journal *journal = SB_JOURNAL(s); 1018 struct reiserfs_journal *journal = SB_JOURNAL(s);
1019 int barrier = 0; 1019 int barrier = 0;
1020 int retval = 0; 1020 int retval = 0;
@@ -1122,7 +1122,8 @@ static int flush_commit_list(struct super_block *s,
1122 sync_dirty_buffer(tbh); 1122 sync_dirty_buffer(tbh);
1123 if (unlikely(!buffer_uptodate(tbh))) { 1123 if (unlikely(!buffer_uptodate(tbh))) {
1124#ifdef CONFIG_REISERFS_CHECK 1124#ifdef CONFIG_REISERFS_CHECK
1125 reiserfs_warning(s, "journal-601, buffer write failed"); 1125 reiserfs_warning(s, "journal-601",
1126 "buffer write failed");
1126#endif 1127#endif
1127 retval = -EIO; 1128 retval = -EIO;
1128 } 1129 }
@@ -1154,14 +1155,14 @@ static int flush_commit_list(struct super_block *s,
1154 * up propagating the write error out to the filesystem. */ 1155 * up propagating the write error out to the filesystem. */
1155 if (unlikely(!buffer_uptodate(jl->j_commit_bh))) { 1156 if (unlikely(!buffer_uptodate(jl->j_commit_bh))) {
1156#ifdef CONFIG_REISERFS_CHECK 1157#ifdef CONFIG_REISERFS_CHECK
1157 reiserfs_warning(s, "journal-615: buffer write failed"); 1158 reiserfs_warning(s, "journal-615", "buffer write failed");
1158#endif 1159#endif
1159 retval = -EIO; 1160 retval = -EIO;
1160 } 1161 }
1161 bforget(jl->j_commit_bh); 1162 bforget(jl->j_commit_bh);
1162 if (journal->j_last_commit_id != 0 && 1163 if (journal->j_last_commit_id != 0 &&
1163 (jl->j_trans_id - journal->j_last_commit_id) != 1) { 1164 (jl->j_trans_id - journal->j_last_commit_id) != 1) {
1164 reiserfs_warning(s, "clm-2200: last commit %lu, current %lu", 1165 reiserfs_warning(s, "clm-2200", "last commit %lu, current %lu",
1165 journal->j_last_commit_id, jl->j_trans_id); 1166 journal->j_last_commit_id, jl->j_trans_id);
1166 } 1167 }
1167 journal->j_last_commit_id = jl->j_trans_id; 1168 journal->j_last_commit_id = jl->j_trans_id;
@@ -1191,8 +1192,8 @@ static int flush_commit_list(struct super_block *s,
1191} 1192}
1192 1193
1193/* 1194/*
1194** flush_journal_list frequently needs to find a newer transaction for a given block. This does that, or 1195** flush_journal_list frequently needs to find a newer transaction for a given block. This does that, or
1195** returns NULL if it can't find anything 1196** returns NULL if it can't find anything
1196*/ 1197*/
1197static struct reiserfs_journal_list *find_newer_jl_for_cn(struct 1198static struct reiserfs_journal_list *find_newer_jl_for_cn(struct
1198 reiserfs_journal_cnode 1199 reiserfs_journal_cnode
@@ -1236,11 +1237,11 @@ static void remove_journal_hash(struct super_block *,
1236** journal list for this transaction. Aside from freeing the cnode, this also allows the 1237** journal list for this transaction. Aside from freeing the cnode, this also allows the
1237** block to be reallocated for data blocks if it had been deleted. 1238** block to be reallocated for data blocks if it had been deleted.
1238*/ 1239*/
1239static void remove_all_from_journal_list(struct super_block *p_s_sb, 1240static void remove_all_from_journal_list(struct super_block *sb,
1240 struct reiserfs_journal_list *jl, 1241 struct reiserfs_journal_list *jl,
1241 int debug) 1242 int debug)
1242{ 1243{
1243 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 1244 struct reiserfs_journal *journal = SB_JOURNAL(sb);
1244 struct reiserfs_journal_cnode *cn, *last; 1245 struct reiserfs_journal_cnode *cn, *last;
1245 cn = jl->j_realblock; 1246 cn = jl->j_realblock;
1246 1247
@@ -1250,18 +1251,18 @@ static void remove_all_from_journal_list(struct super_block *p_s_sb,
1250 while (cn) { 1251 while (cn) {
1251 if (cn->blocknr != 0) { 1252 if (cn->blocknr != 0) {
1252 if (debug) { 1253 if (debug) {
1253 reiserfs_warning(p_s_sb, 1254 reiserfs_warning(sb, "reiserfs-2201",
1254 "block %u, bh is %d, state %ld", 1255 "block %u, bh is %d, state %ld",
1255 cn->blocknr, cn->bh ? 1 : 0, 1256 cn->blocknr, cn->bh ? 1 : 0,
1256 cn->state); 1257 cn->state);
1257 } 1258 }
1258 cn->state = 0; 1259 cn->state = 0;
1259 remove_journal_hash(p_s_sb, journal->j_list_hash_table, 1260 remove_journal_hash(sb, journal->j_list_hash_table,
1260 jl, cn->blocknr, 1); 1261 jl, cn->blocknr, 1);
1261 } 1262 }
1262 last = cn; 1263 last = cn;
1263 cn = cn->next; 1264 cn = cn->next;
1264 free_cnode(p_s_sb, last); 1265 free_cnode(sb, last);
1265 } 1266 }
1266 jl->j_realblock = NULL; 1267 jl->j_realblock = NULL;
1267} 1268}
@@ -1273,12 +1274,12 @@ static void remove_all_from_journal_list(struct super_block *p_s_sb,
1273** called by flush_journal_list, before it calls remove_all_from_journal_list 1274** called by flush_journal_list, before it calls remove_all_from_journal_list
1274** 1275**
1275*/ 1276*/
1276static int _update_journal_header_block(struct super_block *p_s_sb, 1277static int _update_journal_header_block(struct super_block *sb,
1277 unsigned long offset, 1278 unsigned long offset,
1278 unsigned long trans_id) 1279 unsigned int trans_id)
1279{ 1280{
1280 struct reiserfs_journal_header *jh; 1281 struct reiserfs_journal_header *jh;
1281 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 1282 struct reiserfs_journal *journal = SB_JOURNAL(sb);
1282 1283
1283 if (reiserfs_is_journal_aborted(journal)) 1284 if (reiserfs_is_journal_aborted(journal))
1284 return -EIO; 1285 return -EIO;
@@ -1288,8 +1289,8 @@ static int _update_journal_header_block(struct super_block *p_s_sb,
1288 wait_on_buffer((journal->j_header_bh)); 1289 wait_on_buffer((journal->j_header_bh));
1289 if (unlikely(!buffer_uptodate(journal->j_header_bh))) { 1290 if (unlikely(!buffer_uptodate(journal->j_header_bh))) {
1290#ifdef CONFIG_REISERFS_CHECK 1291#ifdef CONFIG_REISERFS_CHECK
1291 reiserfs_warning(p_s_sb, 1292 reiserfs_warning(sb, "journal-699",
1292 "journal-699: buffer write failed"); 1293 "buffer write failed");
1293#endif 1294#endif
1294 return -EIO; 1295 return -EIO;
1295 } 1296 }
@@ -1302,49 +1303,49 @@ static int _update_journal_header_block(struct super_block *p_s_sb,
1302 jh->j_first_unflushed_offset = cpu_to_le32(offset); 1303 jh->j_first_unflushed_offset = cpu_to_le32(offset);
1303 jh->j_mount_id = cpu_to_le32(journal->j_mount_id); 1304 jh->j_mount_id = cpu_to_le32(journal->j_mount_id);
1304 1305
1305 if (reiserfs_barrier_flush(p_s_sb)) { 1306 if (reiserfs_barrier_flush(sb)) {
1306 int ret; 1307 int ret;
1307 lock_buffer(journal->j_header_bh); 1308 lock_buffer(journal->j_header_bh);
1308 ret = submit_barrier_buffer(journal->j_header_bh); 1309 ret = submit_barrier_buffer(journal->j_header_bh);
1309 if (ret == -EOPNOTSUPP) { 1310 if (ret == -EOPNOTSUPP) {
1310 set_buffer_uptodate(journal->j_header_bh); 1311 set_buffer_uptodate(journal->j_header_bh);
1311 disable_barrier(p_s_sb); 1312 disable_barrier(sb);
1312 goto sync; 1313 goto sync;
1313 } 1314 }
1314 wait_on_buffer(journal->j_header_bh); 1315 wait_on_buffer(journal->j_header_bh);
1315 check_barrier_completion(p_s_sb, journal->j_header_bh); 1316 check_barrier_completion(sb, journal->j_header_bh);
1316 } else { 1317 } else {
1317 sync: 1318 sync:
1318 set_buffer_dirty(journal->j_header_bh); 1319 set_buffer_dirty(journal->j_header_bh);
1319 sync_dirty_buffer(journal->j_header_bh); 1320 sync_dirty_buffer(journal->j_header_bh);
1320 } 1321 }
1321 if (!buffer_uptodate(journal->j_header_bh)) { 1322 if (!buffer_uptodate(journal->j_header_bh)) {
1322 reiserfs_warning(p_s_sb, 1323 reiserfs_warning(sb, "journal-837",
1323 "journal-837: IO error during journal replay"); 1324 "IO error during journal replay");
1324 return -EIO; 1325 return -EIO;
1325 } 1326 }
1326 } 1327 }
1327 return 0; 1328 return 0;
1328} 1329}
1329 1330
1330static int update_journal_header_block(struct super_block *p_s_sb, 1331static int update_journal_header_block(struct super_block *sb,
1331 unsigned long offset, 1332 unsigned long offset,
1332 unsigned long trans_id) 1333 unsigned int trans_id)
1333{ 1334{
1334 return _update_journal_header_block(p_s_sb, offset, trans_id); 1335 return _update_journal_header_block(sb, offset, trans_id);
1335} 1336}
1336 1337
1337/* 1338/*
1338** flush any and all journal lists older than you are 1339** flush any and all journal lists older than you are
1339** can only be called from flush_journal_list 1340** can only be called from flush_journal_list
1340*/ 1341*/
1341static int flush_older_journal_lists(struct super_block *p_s_sb, 1342static int flush_older_journal_lists(struct super_block *sb,
1342 struct reiserfs_journal_list *jl) 1343 struct reiserfs_journal_list *jl)
1343{ 1344{
1344 struct list_head *entry; 1345 struct list_head *entry;
1345 struct reiserfs_journal_list *other_jl; 1346 struct reiserfs_journal_list *other_jl;
1346 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 1347 struct reiserfs_journal *journal = SB_JOURNAL(sb);
1347 unsigned long trans_id = jl->j_trans_id; 1348 unsigned int trans_id = jl->j_trans_id;
1348 1349
1349 /* we know we are the only ones flushing things, no extra race 1350 /* we know we are the only ones flushing things, no extra race
1350 * protection is required. 1351 * protection is required.
@@ -1358,7 +1359,7 @@ static int flush_older_journal_lists(struct super_block *p_s_sb,
1358 if (other_jl->j_trans_id < trans_id) { 1359 if (other_jl->j_trans_id < trans_id) {
1359 BUG_ON(other_jl->j_refcount <= 0); 1360 BUG_ON(other_jl->j_refcount <= 0);
1360 /* do not flush all */ 1361 /* do not flush all */
1361 flush_journal_list(p_s_sb, other_jl, 0); 1362 flush_journal_list(sb, other_jl, 0);
1362 1363
1363 /* other_jl is now deleted from the list */ 1364 /* other_jl is now deleted from the list */
1364 goto restart; 1365 goto restart;
@@ -1381,8 +1382,8 @@ static void del_from_work_list(struct super_block *s,
1381** always set flushall to 1, unless you are calling from inside 1382** always set flushall to 1, unless you are calling from inside
1382** flush_journal_list 1383** flush_journal_list
1383** 1384**
1384** IMPORTANT. This can only be called while there are no journal writers, 1385** IMPORTANT. This can only be called while there are no journal writers,
1385** and the journal is locked. That means it can only be called from 1386** and the journal is locked. That means it can only be called from
1386** do_journal_end, or by journal_release 1387** do_journal_end, or by journal_release
1387*/ 1388*/
1388static int flush_journal_list(struct super_block *s, 1389static int flush_journal_list(struct super_block *s,
@@ -1401,8 +1402,7 @@ static int flush_journal_list(struct super_block *s,
1401 BUG_ON(j_len_saved <= 0); 1402 BUG_ON(j_len_saved <= 0);
1402 1403
1403 if (atomic_read(&journal->j_wcount) != 0) { 1404 if (atomic_read(&journal->j_wcount) != 0) {
1404 reiserfs_warning(s, 1405 reiserfs_warning(s, "clm-2048", "called with wcount %d",
1405 "clm-2048: flush_journal_list called with wcount %d",
1406 atomic_read(&journal->j_wcount)); 1406 atomic_read(&journal->j_wcount));
1407 } 1407 }
1408 BUG_ON(jl->j_trans_id == 0); 1408 BUG_ON(jl->j_trans_id == 0);
@@ -1416,8 +1416,7 @@ static int flush_journal_list(struct super_block *s,
1416 1416
1417 count = 0; 1417 count = 0;
1418 if (j_len_saved > journal->j_trans_max) { 1418 if (j_len_saved > journal->j_trans_max) {
1419 reiserfs_panic(s, 1419 reiserfs_panic(s, "journal-715", "length is %lu, trans id %lu",
1420 "journal-715: flush_journal_list, length is %lu, trans id %lu\n",
1421 j_len_saved, jl->j_trans_id); 1420 j_len_saved, jl->j_trans_id);
1422 return 0; 1421 return 0;
1423 } 1422 }
@@ -1430,7 +1429,7 @@ static int flush_journal_list(struct super_block *s,
1430 goto flush_older_and_return; 1429 goto flush_older_and_return;
1431 } 1430 }
1432 1431
1433 /* start by putting the commit list on disk. This will also flush 1432 /* start by putting the commit list on disk. This will also flush
1434 ** the commit lists of any olders transactions 1433 ** the commit lists of any olders transactions
1435 */ 1434 */
1436 flush_commit_list(s, jl, 1); 1435 flush_commit_list(s, jl, 1);
@@ -1445,12 +1444,12 @@ static int flush_journal_list(struct super_block *s,
1445 goto flush_older_and_return; 1444 goto flush_older_and_return;
1446 } 1445 }
1447 1446
1448 /* loop through each cnode, see if we need to write it, 1447 /* loop through each cnode, see if we need to write it,
1449 ** or wait on a more recent transaction, or just ignore it 1448 ** or wait on a more recent transaction, or just ignore it
1450 */ 1449 */
1451 if (atomic_read(&(journal->j_wcount)) != 0) { 1450 if (atomic_read(&(journal->j_wcount)) != 0) {
1452 reiserfs_panic(s, 1451 reiserfs_panic(s, "journal-844", "journal list is flushing, "
1453 "journal-844: panic journal list is flushing, wcount is not 0\n"); 1452 "wcount is not 0");
1454 } 1453 }
1455 cn = jl->j_realblock; 1454 cn = jl->j_realblock;
1456 while (cn) { 1455 while (cn) {
@@ -1474,8 +1473,8 @@ static int flush_journal_list(struct super_block *s,
1474 if (!pjl && cn->bh) { 1473 if (!pjl && cn->bh) {
1475 saved_bh = cn->bh; 1474 saved_bh = cn->bh;
1476 1475
1477 /* we do this to make sure nobody releases the buffer while 1476 /* we do this to make sure nobody releases the buffer while
1478 ** we are working with it 1477 ** we are working with it
1479 */ 1478 */
1480 get_bh(saved_bh); 1479 get_bh(saved_bh);
1481 1480
@@ -1498,8 +1497,8 @@ static int flush_journal_list(struct super_block *s,
1498 goto free_cnode; 1497 goto free_cnode;
1499 } 1498 }
1500 1499
1501 /* bh == NULL when the block got to disk on its own, OR, 1500 /* bh == NULL when the block got to disk on its own, OR,
1502 ** the block got freed in a future transaction 1501 ** the block got freed in a future transaction
1503 */ 1502 */
1504 if (saved_bh == NULL) { 1503 if (saved_bh == NULL) {
1505 goto free_cnode; 1504 goto free_cnode;
@@ -1510,8 +1509,8 @@ static int flush_journal_list(struct super_block *s,
1510 ** is not marked JDirty_wait 1509 ** is not marked JDirty_wait
1511 */ 1510 */
1512 if ((!was_jwait) && !buffer_locked(saved_bh)) { 1511 if ((!was_jwait) && !buffer_locked(saved_bh)) {
1513 reiserfs_warning(s, 1512 reiserfs_warning(s, "journal-813",
1514 "journal-813: BAD! buffer %llu %cdirty %cjwait, " 1513 "BAD! buffer %llu %cdirty %cjwait, "
1515 "not in a newer tranasction", 1514 "not in a newer tranasction",
1516 (unsigned long long)saved_bh-> 1515 (unsigned long long)saved_bh->
1517 b_blocknr, was_dirty ? ' ' : '!', 1516 b_blocknr, was_dirty ? ' ' : '!',
@@ -1529,8 +1528,8 @@ static int flush_journal_list(struct super_block *s,
1529 unlock_buffer(saved_bh); 1528 unlock_buffer(saved_bh);
1530 count++; 1529 count++;
1531 } else { 1530 } else {
1532 reiserfs_warning(s, 1531 reiserfs_warning(s, "clm-2082",
1533 "clm-2082: Unable to flush buffer %llu in %s", 1532 "Unable to flush buffer %llu in %s",
1534 (unsigned long long)saved_bh-> 1533 (unsigned long long)saved_bh->
1535 b_blocknr, __func__); 1534 b_blocknr, __func__);
1536 } 1535 }
@@ -1541,8 +1540,8 @@ static int flush_journal_list(struct super_block *s,
1541 /* we incremented this to keep others from taking the buffer head away */ 1540 /* we incremented this to keep others from taking the buffer head away */
1542 put_bh(saved_bh); 1541 put_bh(saved_bh);
1543 if (atomic_read(&(saved_bh->b_count)) < 0) { 1542 if (atomic_read(&(saved_bh->b_count)) < 0) {
1544 reiserfs_warning(s, 1543 reiserfs_warning(s, "journal-945",
1545 "journal-945: saved_bh->b_count < 0"); 1544 "saved_bh->b_count < 0");
1546 } 1545 }
1547 } 1546 }
1548 } 1547 }
@@ -1551,18 +1550,18 @@ static int flush_journal_list(struct super_block *s,
1551 while (cn) { 1550 while (cn) {
1552 if (test_bit(BLOCK_NEEDS_FLUSH, &cn->state)) { 1551 if (test_bit(BLOCK_NEEDS_FLUSH, &cn->state)) {
1553 if (!cn->bh) { 1552 if (!cn->bh) {
1554 reiserfs_panic(s, 1553 reiserfs_panic(s, "journal-1011",
1555 "journal-1011: cn->bh is NULL\n"); 1554 "cn->bh is NULL");
1556 } 1555 }
1557 wait_on_buffer(cn->bh); 1556 wait_on_buffer(cn->bh);
1558 if (!cn->bh) { 1557 if (!cn->bh) {
1559 reiserfs_panic(s, 1558 reiserfs_panic(s, "journal-1012",
1560 "journal-1012: cn->bh is NULL\n"); 1559 "cn->bh is NULL");
1561 } 1560 }
1562 if (unlikely(!buffer_uptodate(cn->bh))) { 1561 if (unlikely(!buffer_uptodate(cn->bh))) {
1563#ifdef CONFIG_REISERFS_CHECK 1562#ifdef CONFIG_REISERFS_CHECK
1564 reiserfs_warning(s, 1563 reiserfs_warning(s, "journal-949",
1565 "journal-949: buffer write failed\n"); 1564 "buffer write failed");
1566#endif 1565#endif
1567 err = -EIO; 1566 err = -EIO;
1568 } 1567 }
@@ -1587,7 +1586,7 @@ static int flush_journal_list(struct super_block *s,
1587 __func__); 1586 __func__);
1588 flush_older_and_return: 1587 flush_older_and_return:
1589 1588
1590 /* before we can update the journal header block, we _must_ flush all 1589 /* before we can update the journal header block, we _must_ flush all
1591 ** real blocks from all older transactions to disk. This is because 1590 ** real blocks from all older transactions to disk. This is because
1592 ** once the header block is updated, this transaction will not be 1591 ** once the header block is updated, this transaction will not be
1593 ** replayed after a crash 1592 ** replayed after a crash
@@ -1597,7 +1596,7 @@ static int flush_journal_list(struct super_block *s,
1597 } 1596 }
1598 1597
1599 err = journal->j_errno; 1598 err = journal->j_errno;
1600 /* before we can remove everything from the hash tables for this 1599 /* before we can remove everything from the hash tables for this
1601 ** transaction, we must make sure it can never be replayed 1600 ** transaction, we must make sure it can never be replayed
1602 ** 1601 **
1603 ** since we are only called from do_journal_end, we know for sure there 1602 ** since we are only called from do_journal_end, we know for sure there
@@ -1623,7 +1622,7 @@ static int flush_journal_list(struct super_block *s,
1623 1622
1624 if (journal->j_last_flush_id != 0 && 1623 if (journal->j_last_flush_id != 0 &&
1625 (jl->j_trans_id - journal->j_last_flush_id) != 1) { 1624 (jl->j_trans_id - journal->j_last_flush_id) != 1) {
1626 reiserfs_warning(s, "clm-2201: last flush %lu, current %lu", 1625 reiserfs_warning(s, "clm-2201", "last flush %lu, current %lu",
1627 journal->j_last_flush_id, jl->j_trans_id); 1626 journal->j_last_flush_id, jl->j_trans_id);
1628 } 1627 }
1629 journal->j_last_flush_id = jl->j_trans_id; 1628 journal->j_last_flush_id = jl->j_trans_id;
@@ -1758,13 +1757,13 @@ static int dirty_one_transaction(struct super_block *s,
1758static int kupdate_transactions(struct super_block *s, 1757static int kupdate_transactions(struct super_block *s,
1759 struct reiserfs_journal_list *jl, 1758 struct reiserfs_journal_list *jl,
1760 struct reiserfs_journal_list **next_jl, 1759 struct reiserfs_journal_list **next_jl,
1761 unsigned long *next_trans_id, 1760 unsigned int *next_trans_id,
1762 int num_blocks, int num_trans) 1761 int num_blocks, int num_trans)
1763{ 1762{
1764 int ret = 0; 1763 int ret = 0;
1765 int written = 0; 1764 int written = 0;
1766 int transactions_flushed = 0; 1765 int transactions_flushed = 0;
1767 unsigned long orig_trans_id = jl->j_trans_id; 1766 unsigned int orig_trans_id = jl->j_trans_id;
1768 struct buffer_chunk chunk; 1767 struct buffer_chunk chunk;
1769 struct list_head *entry; 1768 struct list_head *entry;
1770 struct reiserfs_journal *journal = SB_JOURNAL(s); 1769 struct reiserfs_journal *journal = SB_JOURNAL(s);
@@ -1833,7 +1832,7 @@ static int flush_used_journal_lists(struct super_block *s,
1833 int limit = 256; 1832 int limit = 256;
1834 struct reiserfs_journal_list *tjl; 1833 struct reiserfs_journal_list *tjl;
1835 struct reiserfs_journal_list *flush_jl; 1834 struct reiserfs_journal_list *flush_jl;
1836 unsigned long trans_id; 1835 unsigned int trans_id;
1837 struct reiserfs_journal *journal = SB_JOURNAL(s); 1836 struct reiserfs_journal *journal = SB_JOURNAL(s);
1838 1837
1839 flush_jl = tjl = jl; 1838 flush_jl = tjl = jl;
@@ -1909,22 +1908,22 @@ void remove_journal_hash(struct super_block *sb,
1909 } 1908 }
1910} 1909}
1911 1910
1912static void free_journal_ram(struct super_block *p_s_sb) 1911static void free_journal_ram(struct super_block *sb)
1913{ 1912{
1914 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 1913 struct reiserfs_journal *journal = SB_JOURNAL(sb);
1915 kfree(journal->j_current_jl); 1914 kfree(journal->j_current_jl);
1916 journal->j_num_lists--; 1915 journal->j_num_lists--;
1917 1916
1918 vfree(journal->j_cnode_free_orig); 1917 vfree(journal->j_cnode_free_orig);
1919 free_list_bitmaps(p_s_sb, journal->j_list_bitmap); 1918 free_list_bitmaps(sb, journal->j_list_bitmap);
1920 free_bitmap_nodes(p_s_sb); /* must be after free_list_bitmaps */ 1919 free_bitmap_nodes(sb); /* must be after free_list_bitmaps */
1921 if (journal->j_header_bh) { 1920 if (journal->j_header_bh) {
1922 brelse(journal->j_header_bh); 1921 brelse(journal->j_header_bh);
1923 } 1922 }
1924 /* j_header_bh is on the journal dev, make sure not to release the journal 1923 /* j_header_bh is on the journal dev, make sure not to release the journal
1925 * dev until we brelse j_header_bh 1924 * dev until we brelse j_header_bh
1926 */ 1925 */
1927 release_journal_dev(p_s_sb, journal); 1926 release_journal_dev(sb, journal);
1928 vfree(journal); 1927 vfree(journal);
1929} 1928}
1930 1929
@@ -1933,27 +1932,27 @@ static void free_journal_ram(struct super_block *p_s_sb)
1933** of read_super() yet. Any other caller must keep error at 0. 1932** of read_super() yet. Any other caller must keep error at 0.
1934*/ 1933*/
1935static int do_journal_release(struct reiserfs_transaction_handle *th, 1934static int do_journal_release(struct reiserfs_transaction_handle *th,
1936 struct super_block *p_s_sb, int error) 1935 struct super_block *sb, int error)
1937{ 1936{
1938 struct reiserfs_transaction_handle myth; 1937 struct reiserfs_transaction_handle myth;
1939 int flushed = 0; 1938 int flushed = 0;
1940 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 1939 struct reiserfs_journal *journal = SB_JOURNAL(sb);
1941 1940
1942 /* we only want to flush out transactions if we were called with error == 0 1941 /* we only want to flush out transactions if we were called with error == 0
1943 */ 1942 */
1944 if (!error && !(p_s_sb->s_flags & MS_RDONLY)) { 1943 if (!error && !(sb->s_flags & MS_RDONLY)) {
1945 /* end the current trans */ 1944 /* end the current trans */
1946 BUG_ON(!th->t_trans_id); 1945 BUG_ON(!th->t_trans_id);
1947 do_journal_end(th, p_s_sb, 10, FLUSH_ALL); 1946 do_journal_end(th, sb, 10, FLUSH_ALL);
1948 1947
1949 /* make sure something gets logged to force our way into the flush code */ 1948 /* make sure something gets logged to force our way into the flush code */
1950 if (!journal_join(&myth, p_s_sb, 1)) { 1949 if (!journal_join(&myth, sb, 1)) {
1951 reiserfs_prepare_for_journal(p_s_sb, 1950 reiserfs_prepare_for_journal(sb,
1952 SB_BUFFER_WITH_SB(p_s_sb), 1951 SB_BUFFER_WITH_SB(sb),
1953 1); 1952 1);
1954 journal_mark_dirty(&myth, p_s_sb, 1953 journal_mark_dirty(&myth, sb,
1955 SB_BUFFER_WITH_SB(p_s_sb)); 1954 SB_BUFFER_WITH_SB(sb));
1956 do_journal_end(&myth, p_s_sb, 1, FLUSH_ALL); 1955 do_journal_end(&myth, sb, 1, FLUSH_ALL);
1957 flushed = 1; 1956 flushed = 1;
1958 } 1957 }
1959 } 1958 }
@@ -1961,26 +1960,26 @@ static int do_journal_release(struct reiserfs_transaction_handle *th,
1961 /* this also catches errors during the do_journal_end above */ 1960 /* this also catches errors during the do_journal_end above */
1962 if (!error && reiserfs_is_journal_aborted(journal)) { 1961 if (!error && reiserfs_is_journal_aborted(journal)) {
1963 memset(&myth, 0, sizeof(myth)); 1962 memset(&myth, 0, sizeof(myth));
1964 if (!journal_join_abort(&myth, p_s_sb, 1)) { 1963 if (!journal_join_abort(&myth, sb, 1)) {
1965 reiserfs_prepare_for_journal(p_s_sb, 1964 reiserfs_prepare_for_journal(sb,
1966 SB_BUFFER_WITH_SB(p_s_sb), 1965 SB_BUFFER_WITH_SB(sb),
1967 1); 1966 1);
1968 journal_mark_dirty(&myth, p_s_sb, 1967 journal_mark_dirty(&myth, sb,
1969 SB_BUFFER_WITH_SB(p_s_sb)); 1968 SB_BUFFER_WITH_SB(sb));
1970 do_journal_end(&myth, p_s_sb, 1, FLUSH_ALL); 1969 do_journal_end(&myth, sb, 1, FLUSH_ALL);
1971 } 1970 }
1972 } 1971 }
1973 1972
1974 reiserfs_mounted_fs_count--; 1973 reiserfs_mounted_fs_count--;
1975 /* wait for all commits to finish */ 1974 /* wait for all commits to finish */
1976 cancel_delayed_work(&SB_JOURNAL(p_s_sb)->j_work); 1975 cancel_delayed_work(&SB_JOURNAL(sb)->j_work);
1977 flush_workqueue(commit_wq); 1976 flush_workqueue(commit_wq);
1978 if (!reiserfs_mounted_fs_count) { 1977 if (!reiserfs_mounted_fs_count) {
1979 destroy_workqueue(commit_wq); 1978 destroy_workqueue(commit_wq);
1980 commit_wq = NULL; 1979 commit_wq = NULL;
1981 } 1980 }
1982 1981
1983 free_journal_ram(p_s_sb); 1982 free_journal_ram(sb);
1984 1983
1985 return 0; 1984 return 0;
1986} 1985}
@@ -1989,41 +1988,41 @@ static int do_journal_release(struct reiserfs_transaction_handle *th,
1989** call on unmount. flush all journal trans, release all alloc'd ram 1988** call on unmount. flush all journal trans, release all alloc'd ram
1990*/ 1989*/
1991int journal_release(struct reiserfs_transaction_handle *th, 1990int journal_release(struct reiserfs_transaction_handle *th,
1992 struct super_block *p_s_sb) 1991 struct super_block *sb)
1993{ 1992{
1994 return do_journal_release(th, p_s_sb, 0); 1993 return do_journal_release(th, sb, 0);
1995} 1994}
1996 1995
1997/* 1996/*
1998** only call from an error condition inside reiserfs_read_super! 1997** only call from an error condition inside reiserfs_read_super!
1999*/ 1998*/
2000int journal_release_error(struct reiserfs_transaction_handle *th, 1999int journal_release_error(struct reiserfs_transaction_handle *th,
2001 struct super_block *p_s_sb) 2000 struct super_block *sb)
2002{ 2001{
2003 return do_journal_release(th, p_s_sb, 1); 2002 return do_journal_release(th, sb, 1);
2004} 2003}
2005 2004
2006/* compares description block with commit block. returns 1 if they differ, 0 if they are the same */ 2005/* compares description block with commit block. returns 1 if they differ, 0 if they are the same */
2007static int journal_compare_desc_commit(struct super_block *p_s_sb, 2006static int journal_compare_desc_commit(struct super_block *sb,
2008 struct reiserfs_journal_desc *desc, 2007 struct reiserfs_journal_desc *desc,
2009 struct reiserfs_journal_commit *commit) 2008 struct reiserfs_journal_commit *commit)
2010{ 2009{
2011 if (get_commit_trans_id(commit) != get_desc_trans_id(desc) || 2010 if (get_commit_trans_id(commit) != get_desc_trans_id(desc) ||
2012 get_commit_trans_len(commit) != get_desc_trans_len(desc) || 2011 get_commit_trans_len(commit) != get_desc_trans_len(desc) ||
2013 get_commit_trans_len(commit) > SB_JOURNAL(p_s_sb)->j_trans_max || 2012 get_commit_trans_len(commit) > SB_JOURNAL(sb)->j_trans_max ||
2014 get_commit_trans_len(commit) <= 0) { 2013 get_commit_trans_len(commit) <= 0) {
2015 return 1; 2014 return 1;
2016 } 2015 }
2017 return 0; 2016 return 0;
2018} 2017}
2019 2018
2020/* returns 0 if it did not find a description block 2019/* returns 0 if it did not find a description block
2021** returns -1 if it found a corrupt commit block 2020** returns -1 if it found a corrupt commit block
2022** returns 1 if both desc and commit were valid 2021** returns 1 if both desc and commit were valid
2023*/ 2022*/
2024static int journal_transaction_is_valid(struct super_block *p_s_sb, 2023static int journal_transaction_is_valid(struct super_block *sb,
2025 struct buffer_head *d_bh, 2024 struct buffer_head *d_bh,
2026 unsigned long *oldest_invalid_trans_id, 2025 unsigned int *oldest_invalid_trans_id,
2027 unsigned long *newest_mount_id) 2026 unsigned long *newest_mount_id)
2028{ 2027{
2029 struct reiserfs_journal_desc *desc; 2028 struct reiserfs_journal_desc *desc;
@@ -2039,7 +2038,7 @@ static int journal_transaction_is_valid(struct super_block *p_s_sb,
2039 && !memcmp(get_journal_desc_magic(d_bh), JOURNAL_DESC_MAGIC, 8)) { 2038 && !memcmp(get_journal_desc_magic(d_bh), JOURNAL_DESC_MAGIC, 8)) {
2040 if (oldest_invalid_trans_id && *oldest_invalid_trans_id 2039 if (oldest_invalid_trans_id && *oldest_invalid_trans_id
2041 && get_desc_trans_id(desc) > *oldest_invalid_trans_id) { 2040 && get_desc_trans_id(desc) > *oldest_invalid_trans_id) {
2042 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2041 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2043 "journal-986: transaction " 2042 "journal-986: transaction "
2044 "is valid returning because trans_id %d is greater than " 2043 "is valid returning because trans_id %d is greater than "
2045 "oldest_invalid %lu", 2044 "oldest_invalid %lu",
@@ -2049,7 +2048,7 @@ static int journal_transaction_is_valid(struct super_block *p_s_sb,
2049 } 2048 }
2050 if (newest_mount_id 2049 if (newest_mount_id
2051 && *newest_mount_id > get_desc_mount_id(desc)) { 2050 && *newest_mount_id > get_desc_mount_id(desc)) {
2052 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2051 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2053 "journal-1087: transaction " 2052 "journal-1087: transaction "
2054 "is valid returning because mount_id %d is less than " 2053 "is valid returning because mount_id %d is less than "
2055 "newest_mount_id %lu", 2054 "newest_mount_id %lu",
@@ -2057,36 +2056,37 @@ static int journal_transaction_is_valid(struct super_block *p_s_sb,
2057 *newest_mount_id); 2056 *newest_mount_id);
2058 return -1; 2057 return -1;
2059 } 2058 }
2060 if (get_desc_trans_len(desc) > SB_JOURNAL(p_s_sb)->j_trans_max) { 2059 if (get_desc_trans_len(desc) > SB_JOURNAL(sb)->j_trans_max) {
2061 reiserfs_warning(p_s_sb, 2060 reiserfs_warning(sb, "journal-2018",
2062 "journal-2018: Bad transaction length %d encountered, ignoring transaction", 2061 "Bad transaction length %d "
2062 "encountered, ignoring transaction",
2063 get_desc_trans_len(desc)); 2063 get_desc_trans_len(desc));
2064 return -1; 2064 return -1;
2065 } 2065 }
2066 offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb); 2066 offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(sb);
2067 2067
2068 /* ok, we have a journal description block, lets see if the transaction was valid */ 2068 /* ok, we have a journal description block, lets see if the transaction was valid */
2069 c_bh = 2069 c_bh =
2070 journal_bread(p_s_sb, 2070 journal_bread(sb,
2071 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2071 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2072 ((offset + get_desc_trans_len(desc) + 2072 ((offset + get_desc_trans_len(desc) +
2073 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))); 2073 1) % SB_ONDISK_JOURNAL_SIZE(sb)));
2074 if (!c_bh) 2074 if (!c_bh)
2075 return 0; 2075 return 0;
2076 commit = (struct reiserfs_journal_commit *)c_bh->b_data; 2076 commit = (struct reiserfs_journal_commit *)c_bh->b_data;
2077 if (journal_compare_desc_commit(p_s_sb, desc, commit)) { 2077 if (journal_compare_desc_commit(sb, desc, commit)) {
2078 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2078 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2079 "journal_transaction_is_valid, commit offset %ld had bad " 2079 "journal_transaction_is_valid, commit offset %ld had bad "
2080 "time %d or length %d", 2080 "time %d or length %d",
2081 c_bh->b_blocknr - 2081 c_bh->b_blocknr -
2082 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2082 SB_ONDISK_JOURNAL_1st_BLOCK(sb),
2083 get_commit_trans_id(commit), 2083 get_commit_trans_id(commit),
2084 get_commit_trans_len(commit)); 2084 get_commit_trans_len(commit));
2085 brelse(c_bh); 2085 brelse(c_bh);
2086 if (oldest_invalid_trans_id) { 2086 if (oldest_invalid_trans_id) {
2087 *oldest_invalid_trans_id = 2087 *oldest_invalid_trans_id =
2088 get_desc_trans_id(desc); 2088 get_desc_trans_id(desc);
2089 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2089 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2090 "journal-1004: " 2090 "journal-1004: "
2091 "transaction_is_valid setting oldest invalid trans_id " 2091 "transaction_is_valid setting oldest invalid trans_id "
2092 "to %d", 2092 "to %d",
@@ -2095,11 +2095,11 @@ static int journal_transaction_is_valid(struct super_block *p_s_sb,
2095 return -1; 2095 return -1;
2096 } 2096 }
2097 brelse(c_bh); 2097 brelse(c_bh);
2098 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2098 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2099 "journal-1006: found valid " 2099 "journal-1006: found valid "
2100 "transaction start offset %llu, len %d id %d", 2100 "transaction start offset %llu, len %d id %d",
2101 d_bh->b_blocknr - 2101 d_bh->b_blocknr -
2102 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2102 SB_ONDISK_JOURNAL_1st_BLOCK(sb),
2103 get_desc_trans_len(desc), 2103 get_desc_trans_len(desc),
2104 get_desc_trans_id(desc)); 2104 get_desc_trans_id(desc));
2105 return 1; 2105 return 1;
@@ -2121,63 +2121,63 @@ static void brelse_array(struct buffer_head **heads, int num)
2121** this either reads in a replays a transaction, or returns because the transaction 2121** this either reads in a replays a transaction, or returns because the transaction
2122** is invalid, or too old. 2122** is invalid, or too old.
2123*/ 2123*/
2124static int journal_read_transaction(struct super_block *p_s_sb, 2124static int journal_read_transaction(struct super_block *sb,
2125 unsigned long cur_dblock, 2125 unsigned long cur_dblock,
2126 unsigned long oldest_start, 2126 unsigned long oldest_start,
2127 unsigned long oldest_trans_id, 2127 unsigned int oldest_trans_id,
2128 unsigned long newest_mount_id) 2128 unsigned long newest_mount_id)
2129{ 2129{
2130 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 2130 struct reiserfs_journal *journal = SB_JOURNAL(sb);
2131 struct reiserfs_journal_desc *desc; 2131 struct reiserfs_journal_desc *desc;
2132 struct reiserfs_journal_commit *commit; 2132 struct reiserfs_journal_commit *commit;
2133 unsigned long trans_id = 0; 2133 unsigned int trans_id = 0;
2134 struct buffer_head *c_bh; 2134 struct buffer_head *c_bh;
2135 struct buffer_head *d_bh; 2135 struct buffer_head *d_bh;
2136 struct buffer_head **log_blocks = NULL; 2136 struct buffer_head **log_blocks = NULL;
2137 struct buffer_head **real_blocks = NULL; 2137 struct buffer_head **real_blocks = NULL;
2138 unsigned long trans_offset; 2138 unsigned int trans_offset;
2139 int i; 2139 int i;
2140 int trans_half; 2140 int trans_half;
2141 2141
2142 d_bh = journal_bread(p_s_sb, cur_dblock); 2142 d_bh = journal_bread(sb, cur_dblock);
2143 if (!d_bh) 2143 if (!d_bh)
2144 return 1; 2144 return 1;
2145 desc = (struct reiserfs_journal_desc *)d_bh->b_data; 2145 desc = (struct reiserfs_journal_desc *)d_bh->b_data;
2146 trans_offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb); 2146 trans_offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(sb);
2147 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1037: " 2147 reiserfs_debug(sb, REISERFS_DEBUG_CODE, "journal-1037: "
2148 "journal_read_transaction, offset %llu, len %d mount_id %d", 2148 "journal_read_transaction, offset %llu, len %d mount_id %d",
2149 d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2149 d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(sb),
2150 get_desc_trans_len(desc), get_desc_mount_id(desc)); 2150 get_desc_trans_len(desc), get_desc_mount_id(desc));
2151 if (get_desc_trans_id(desc) < oldest_trans_id) { 2151 if (get_desc_trans_id(desc) < oldest_trans_id) {
2152 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1039: " 2152 reiserfs_debug(sb, REISERFS_DEBUG_CODE, "journal-1039: "
2153 "journal_read_trans skipping because %lu is too old", 2153 "journal_read_trans skipping because %lu is too old",
2154 cur_dblock - 2154 cur_dblock -
2155 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb)); 2155 SB_ONDISK_JOURNAL_1st_BLOCK(sb));
2156 brelse(d_bh); 2156 brelse(d_bh);
2157 return 1; 2157 return 1;
2158 } 2158 }
2159 if (get_desc_mount_id(desc) != newest_mount_id) { 2159 if (get_desc_mount_id(desc) != newest_mount_id) {
2160 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1146: " 2160 reiserfs_debug(sb, REISERFS_DEBUG_CODE, "journal-1146: "
2161 "journal_read_trans skipping because %d is != " 2161 "journal_read_trans skipping because %d is != "
2162 "newest_mount_id %lu", get_desc_mount_id(desc), 2162 "newest_mount_id %lu", get_desc_mount_id(desc),
2163 newest_mount_id); 2163 newest_mount_id);
2164 brelse(d_bh); 2164 brelse(d_bh);
2165 return 1; 2165 return 1;
2166 } 2166 }
2167 c_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2167 c_bh = journal_bread(sb, SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2168 ((trans_offset + get_desc_trans_len(desc) + 1) % 2168 ((trans_offset + get_desc_trans_len(desc) + 1) %
2169 SB_ONDISK_JOURNAL_SIZE(p_s_sb))); 2169 SB_ONDISK_JOURNAL_SIZE(sb)));
2170 if (!c_bh) { 2170 if (!c_bh) {
2171 brelse(d_bh); 2171 brelse(d_bh);
2172 return 1; 2172 return 1;
2173 } 2173 }
2174 commit = (struct reiserfs_journal_commit *)c_bh->b_data; 2174 commit = (struct reiserfs_journal_commit *)c_bh->b_data;
2175 if (journal_compare_desc_commit(p_s_sb, desc, commit)) { 2175 if (journal_compare_desc_commit(sb, desc, commit)) {
2176 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2176 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2177 "journal_read_transaction, " 2177 "journal_read_transaction, "
2178 "commit offset %llu had bad time %d or length %d", 2178 "commit offset %llu had bad time %d or length %d",
2179 c_bh->b_blocknr - 2179 c_bh->b_blocknr -
2180 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2180 SB_ONDISK_JOURNAL_1st_BLOCK(sb),
2181 get_commit_trans_id(commit), 2181 get_commit_trans_id(commit),
2182 get_commit_trans_len(commit)); 2182 get_commit_trans_len(commit));
2183 brelse(c_bh); 2183 brelse(c_bh);
@@ -2195,38 +2195,41 @@ static int journal_read_transaction(struct super_block *p_s_sb,
2195 brelse(d_bh); 2195 brelse(d_bh);
2196 kfree(log_blocks); 2196 kfree(log_blocks);
2197 kfree(real_blocks); 2197 kfree(real_blocks);
2198 reiserfs_warning(p_s_sb, 2198 reiserfs_warning(sb, "journal-1169",
2199 "journal-1169: kmalloc failed, unable to mount FS"); 2199 "kmalloc failed, unable to mount FS");
2200 return -1; 2200 return -1;
2201 } 2201 }
2202 /* get all the buffer heads */ 2202 /* get all the buffer heads */
2203 trans_half = journal_trans_half(p_s_sb->s_blocksize); 2203 trans_half = journal_trans_half(sb->s_blocksize);
2204 for (i = 0; i < get_desc_trans_len(desc); i++) { 2204 for (i = 0; i < get_desc_trans_len(desc); i++) {
2205 log_blocks[i] = 2205 log_blocks[i] =
2206 journal_getblk(p_s_sb, 2206 journal_getblk(sb,
2207 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2207 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2208 (trans_offset + 1 + 2208 (trans_offset + 1 +
2209 i) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2209 i) % SB_ONDISK_JOURNAL_SIZE(sb));
2210 if (i < trans_half) { 2210 if (i < trans_half) {
2211 real_blocks[i] = 2211 real_blocks[i] =
2212 sb_getblk(p_s_sb, 2212 sb_getblk(sb,
2213 le32_to_cpu(desc->j_realblock[i])); 2213 le32_to_cpu(desc->j_realblock[i]));
2214 } else { 2214 } else {
2215 real_blocks[i] = 2215 real_blocks[i] =
2216 sb_getblk(p_s_sb, 2216 sb_getblk(sb,
2217 le32_to_cpu(commit-> 2217 le32_to_cpu(commit->
2218 j_realblock[i - trans_half])); 2218 j_realblock[i - trans_half]));
2219 } 2219 }
2220 if (real_blocks[i]->b_blocknr > SB_BLOCK_COUNT(p_s_sb)) { 2220 if (real_blocks[i]->b_blocknr > SB_BLOCK_COUNT(sb)) {
2221 reiserfs_warning(p_s_sb, 2221 reiserfs_warning(sb, "journal-1207",
2222 "journal-1207: REPLAY FAILURE fsck required! Block to replay is outside of filesystem"); 2222 "REPLAY FAILURE fsck required! "
2223 "Block to replay is outside of "
2224 "filesystem");
2223 goto abort_replay; 2225 goto abort_replay;
2224 } 2226 }
2225 /* make sure we don't try to replay onto log or reserved area */ 2227 /* make sure we don't try to replay onto log or reserved area */
2226 if (is_block_in_log_or_reserved_area 2228 if (is_block_in_log_or_reserved_area
2227 (p_s_sb, real_blocks[i]->b_blocknr)) { 2229 (sb, real_blocks[i]->b_blocknr)) {
2228 reiserfs_warning(p_s_sb, 2230 reiserfs_warning(sb, "journal-1204",
2229 "journal-1204: REPLAY FAILURE fsck required! Trying to replay onto a log block"); 2231 "REPLAY FAILURE fsck required! "
2232 "Trying to replay onto a log block");
2230 abort_replay: 2233 abort_replay:
2231 brelse_array(log_blocks, i); 2234 brelse_array(log_blocks, i);
2232 brelse_array(real_blocks, i); 2235 brelse_array(real_blocks, i);
@@ -2242,8 +2245,9 @@ static int journal_read_transaction(struct super_block *p_s_sb,
2242 for (i = 0; i < get_desc_trans_len(desc); i++) { 2245 for (i = 0; i < get_desc_trans_len(desc); i++) {
2243 wait_on_buffer(log_blocks[i]); 2246 wait_on_buffer(log_blocks[i]);
2244 if (!buffer_uptodate(log_blocks[i])) { 2247 if (!buffer_uptodate(log_blocks[i])) {
2245 reiserfs_warning(p_s_sb, 2248 reiserfs_warning(sb, "journal-1212",
2246 "journal-1212: REPLAY FAILURE fsck required! buffer write failed"); 2249 "REPLAY FAILURE fsck required! "
2250 "buffer write failed");
2247 brelse_array(log_blocks + i, 2251 brelse_array(log_blocks + i,
2248 get_desc_trans_len(desc) - i); 2252 get_desc_trans_len(desc) - i);
2249 brelse_array(real_blocks, get_desc_trans_len(desc)); 2253 brelse_array(real_blocks, get_desc_trans_len(desc));
@@ -2266,8 +2270,9 @@ static int journal_read_transaction(struct super_block *p_s_sb,
2266 for (i = 0; i < get_desc_trans_len(desc); i++) { 2270 for (i = 0; i < get_desc_trans_len(desc); i++) {
2267 wait_on_buffer(real_blocks[i]); 2271 wait_on_buffer(real_blocks[i]);
2268 if (!buffer_uptodate(real_blocks[i])) { 2272 if (!buffer_uptodate(real_blocks[i])) {
2269 reiserfs_warning(p_s_sb, 2273 reiserfs_warning(sb, "journal-1226",
2270 "journal-1226: REPLAY FAILURE, fsck required! buffer write failed"); 2274 "REPLAY FAILURE, fsck required! "
2275 "buffer write failed");
2271 brelse_array(real_blocks + i, 2276 brelse_array(real_blocks + i,
2272 get_desc_trans_len(desc) - i); 2277 get_desc_trans_len(desc) - i);
2273 brelse(c_bh); 2278 brelse(c_bh);
@@ -2279,15 +2284,15 @@ static int journal_read_transaction(struct super_block *p_s_sb,
2279 brelse(real_blocks[i]); 2284 brelse(real_blocks[i]);
2280 } 2285 }
2281 cur_dblock = 2286 cur_dblock =
2282 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2287 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2283 ((trans_offset + get_desc_trans_len(desc) + 2288 ((trans_offset + get_desc_trans_len(desc) +
2284 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2289 2) % SB_ONDISK_JOURNAL_SIZE(sb));
2285 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2290 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2286 "journal-1095: setting journal " "start to offset %ld", 2291 "journal-1095: setting journal " "start to offset %ld",
2287 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb)); 2292 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(sb));
2288 2293
2289 /* init starting values for the first transaction, in case this is the last transaction to be replayed. */ 2294 /* init starting values for the first transaction, in case this is the last transaction to be replayed. */
2290 journal->j_start = cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb); 2295 journal->j_start = cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(sb);
2291 journal->j_last_flush_trans_id = trans_id; 2296 journal->j_last_flush_trans_id = trans_id;
2292 journal->j_trans_id = trans_id + 1; 2297 journal->j_trans_id = trans_id + 1;
2293 /* check for trans_id overflow */ 2298 /* check for trans_id overflow */
@@ -2352,12 +2357,12 @@ static struct buffer_head *reiserfs_breada(struct block_device *dev,
2352** 2357**
2353** On exit, it sets things up so the first transaction will work correctly. 2358** On exit, it sets things up so the first transaction will work correctly.
2354*/ 2359*/
2355static int journal_read(struct super_block *p_s_sb) 2360static int journal_read(struct super_block *sb)
2356{ 2361{
2357 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 2362 struct reiserfs_journal *journal = SB_JOURNAL(sb);
2358 struct reiserfs_journal_desc *desc; 2363 struct reiserfs_journal_desc *desc;
2359 unsigned long oldest_trans_id = 0; 2364 unsigned int oldest_trans_id = 0;
2360 unsigned long oldest_invalid_trans_id = 0; 2365 unsigned int oldest_invalid_trans_id = 0;
2361 time_t start; 2366 time_t start;
2362 unsigned long oldest_start = 0; 2367 unsigned long oldest_start = 0;
2363 unsigned long cur_dblock = 0; 2368 unsigned long cur_dblock = 0;
@@ -2370,46 +2375,46 @@ static int journal_read(struct super_block *p_s_sb)
2370 int ret; 2375 int ret;
2371 char b[BDEVNAME_SIZE]; 2376 char b[BDEVNAME_SIZE];
2372 2377
2373 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb); 2378 cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(sb);
2374 reiserfs_info(p_s_sb, "checking transaction log (%s)\n", 2379 reiserfs_info(sb, "checking transaction log (%s)\n",
2375 bdevname(journal->j_dev_bd, b)); 2380 bdevname(journal->j_dev_bd, b));
2376 start = get_seconds(); 2381 start = get_seconds();
2377 2382
2378 /* step 1, read in the journal header block. Check the transaction it says 2383 /* step 1, read in the journal header block. Check the transaction it says
2379 ** is the first unflushed, and if that transaction is not valid, 2384 ** is the first unflushed, and if that transaction is not valid,
2380 ** replay is done 2385 ** replay is done
2381 */ 2386 */
2382 journal->j_header_bh = journal_bread(p_s_sb, 2387 journal->j_header_bh = journal_bread(sb,
2383 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) 2388 SB_ONDISK_JOURNAL_1st_BLOCK(sb)
2384 + SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2389 + SB_ONDISK_JOURNAL_SIZE(sb));
2385 if (!journal->j_header_bh) { 2390 if (!journal->j_header_bh) {
2386 return 1; 2391 return 1;
2387 } 2392 }
2388 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data); 2393 jh = (struct reiserfs_journal_header *)(journal->j_header_bh->b_data);
2389 if (le32_to_cpu(jh->j_first_unflushed_offset) < 2394 if (le32_to_cpu(jh->j_first_unflushed_offset) <
2390 SB_ONDISK_JOURNAL_SIZE(p_s_sb) 2395 SB_ONDISK_JOURNAL_SIZE(sb)
2391 && le32_to_cpu(jh->j_last_flush_trans_id) > 0) { 2396 && le32_to_cpu(jh->j_last_flush_trans_id) > 0) {
2392 oldest_start = 2397 oldest_start =
2393 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2398 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2394 le32_to_cpu(jh->j_first_unflushed_offset); 2399 le32_to_cpu(jh->j_first_unflushed_offset);
2395 oldest_trans_id = le32_to_cpu(jh->j_last_flush_trans_id) + 1; 2400 oldest_trans_id = le32_to_cpu(jh->j_last_flush_trans_id) + 1;
2396 newest_mount_id = le32_to_cpu(jh->j_mount_id); 2401 newest_mount_id = le32_to_cpu(jh->j_mount_id);
2397 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2402 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2398 "journal-1153: found in " 2403 "journal-1153: found in "
2399 "header: first_unflushed_offset %d, last_flushed_trans_id " 2404 "header: first_unflushed_offset %d, last_flushed_trans_id "
2400 "%lu", le32_to_cpu(jh->j_first_unflushed_offset), 2405 "%lu", le32_to_cpu(jh->j_first_unflushed_offset),
2401 le32_to_cpu(jh->j_last_flush_trans_id)); 2406 le32_to_cpu(jh->j_last_flush_trans_id));
2402 valid_journal_header = 1; 2407 valid_journal_header = 1;
2403 2408
2404 /* now, we try to read the first unflushed offset. If it is not valid, 2409 /* now, we try to read the first unflushed offset. If it is not valid,
2405 ** there is nothing more we can do, and it makes no sense to read 2410 ** there is nothing more we can do, and it makes no sense to read
2406 ** through the whole log. 2411 ** through the whole log.
2407 */ 2412 */
2408 d_bh = 2413 d_bh =
2409 journal_bread(p_s_sb, 2414 journal_bread(sb,
2410 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2415 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2411 le32_to_cpu(jh->j_first_unflushed_offset)); 2416 le32_to_cpu(jh->j_first_unflushed_offset));
2412 ret = journal_transaction_is_valid(p_s_sb, d_bh, NULL, NULL); 2417 ret = journal_transaction_is_valid(sb, d_bh, NULL, NULL);
2413 if (!ret) { 2418 if (!ret) {
2414 continue_replay = 0; 2419 continue_replay = 0;
2415 } 2420 }
@@ -2417,9 +2422,9 @@ static int journal_read(struct super_block *p_s_sb)
2417 goto start_log_replay; 2422 goto start_log_replay;
2418 } 2423 }
2419 2424
2420 if (continue_replay && bdev_read_only(p_s_sb->s_bdev)) { 2425 if (continue_replay && bdev_read_only(sb->s_bdev)) {
2421 reiserfs_warning(p_s_sb, 2426 reiserfs_warning(sb, "clm-2076",
2422 "clm-2076: device is readonly, unable to replay log"); 2427 "device is readonly, unable to replay log");
2423 return -1; 2428 return -1;
2424 } 2429 }
2425 2430
@@ -2428,17 +2433,17 @@ static int journal_read(struct super_block *p_s_sb)
2428 */ 2433 */
2429 while (continue_replay 2434 while (continue_replay
2430 && cur_dblock < 2435 && cur_dblock <
2431 (SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2436 (SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2432 SB_ONDISK_JOURNAL_SIZE(p_s_sb))) { 2437 SB_ONDISK_JOURNAL_SIZE(sb))) {
2433 /* Note that it is required for blocksize of primary fs device and journal 2438 /* Note that it is required for blocksize of primary fs device and journal
2434 device to be the same */ 2439 device to be the same */
2435 d_bh = 2440 d_bh =
2436 reiserfs_breada(journal->j_dev_bd, cur_dblock, 2441 reiserfs_breada(journal->j_dev_bd, cur_dblock,
2437 p_s_sb->s_blocksize, 2442 sb->s_blocksize,
2438 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2443 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2439 SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2444 SB_ONDISK_JOURNAL_SIZE(sb));
2440 ret = 2445 ret =
2441 journal_transaction_is_valid(p_s_sb, d_bh, 2446 journal_transaction_is_valid(sb, d_bh,
2442 &oldest_invalid_trans_id, 2447 &oldest_invalid_trans_id,
2443 &newest_mount_id); 2448 &newest_mount_id);
2444 if (ret == 1) { 2449 if (ret == 1) {
@@ -2447,26 +2452,26 @@ static int journal_read(struct super_block *p_s_sb)
2447 oldest_trans_id = get_desc_trans_id(desc); 2452 oldest_trans_id = get_desc_trans_id(desc);
2448 oldest_start = d_bh->b_blocknr; 2453 oldest_start = d_bh->b_blocknr;
2449 newest_mount_id = get_desc_mount_id(desc); 2454 newest_mount_id = get_desc_mount_id(desc);
2450 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2455 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2451 "journal-1179: Setting " 2456 "journal-1179: Setting "
2452 "oldest_start to offset %llu, trans_id %lu", 2457 "oldest_start to offset %llu, trans_id %lu",
2453 oldest_start - 2458 oldest_start -
2454 SB_ONDISK_JOURNAL_1st_BLOCK 2459 SB_ONDISK_JOURNAL_1st_BLOCK
2455 (p_s_sb), oldest_trans_id); 2460 (sb), oldest_trans_id);
2456 } else if (oldest_trans_id > get_desc_trans_id(desc)) { 2461 } else if (oldest_trans_id > get_desc_trans_id(desc)) {
2457 /* one we just read was older */ 2462 /* one we just read was older */
2458 oldest_trans_id = get_desc_trans_id(desc); 2463 oldest_trans_id = get_desc_trans_id(desc);
2459 oldest_start = d_bh->b_blocknr; 2464 oldest_start = d_bh->b_blocknr;
2460 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2465 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2461 "journal-1180: Resetting " 2466 "journal-1180: Resetting "
2462 "oldest_start to offset %lu, trans_id %lu", 2467 "oldest_start to offset %lu, trans_id %lu",
2463 oldest_start - 2468 oldest_start -
2464 SB_ONDISK_JOURNAL_1st_BLOCK 2469 SB_ONDISK_JOURNAL_1st_BLOCK
2465 (p_s_sb), oldest_trans_id); 2470 (sb), oldest_trans_id);
2466 } 2471 }
2467 if (newest_mount_id < get_desc_mount_id(desc)) { 2472 if (newest_mount_id < get_desc_mount_id(desc)) {
2468 newest_mount_id = get_desc_mount_id(desc); 2473 newest_mount_id = get_desc_mount_id(desc);
2469 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2474 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2470 "journal-1299: Setting " 2475 "journal-1299: Setting "
2471 "newest_mount_id to %d", 2476 "newest_mount_id to %d",
2472 get_desc_mount_id(desc)); 2477 get_desc_mount_id(desc));
@@ -2481,17 +2486,17 @@ static int journal_read(struct super_block *p_s_sb)
2481 start_log_replay: 2486 start_log_replay:
2482 cur_dblock = oldest_start; 2487 cur_dblock = oldest_start;
2483 if (oldest_trans_id) { 2488 if (oldest_trans_id) {
2484 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2489 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2485 "journal-1206: Starting replay " 2490 "journal-1206: Starting replay "
2486 "from offset %llu, trans_id %lu", 2491 "from offset %llu, trans_id %lu",
2487 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2492 cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(sb),
2488 oldest_trans_id); 2493 oldest_trans_id);
2489 2494
2490 } 2495 }
2491 replay_count = 0; 2496 replay_count = 0;
2492 while (continue_replay && oldest_trans_id > 0) { 2497 while (continue_replay && oldest_trans_id > 0) {
2493 ret = 2498 ret =
2494 journal_read_transaction(p_s_sb, cur_dblock, oldest_start, 2499 journal_read_transaction(sb, cur_dblock, oldest_start,
2495 oldest_trans_id, newest_mount_id); 2500 oldest_trans_id, newest_mount_id);
2496 if (ret < 0) { 2501 if (ret < 0) {
2497 return ret; 2502 return ret;
@@ -2499,14 +2504,14 @@ static int journal_read(struct super_block *p_s_sb)
2499 break; 2504 break;
2500 } 2505 }
2501 cur_dblock = 2506 cur_dblock =
2502 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + journal->j_start; 2507 SB_ONDISK_JOURNAL_1st_BLOCK(sb) + journal->j_start;
2503 replay_count++; 2508 replay_count++;
2504 if (cur_dblock == oldest_start) 2509 if (cur_dblock == oldest_start)
2505 break; 2510 break;
2506 } 2511 }
2507 2512
2508 if (oldest_trans_id == 0) { 2513 if (oldest_trans_id == 0) {
2509 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 2514 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
2510 "journal-1225: No valid " "transactions found"); 2515 "journal-1225: No valid " "transactions found");
2511 } 2516 }
2512 /* j_start does not get set correctly if we don't replay any transactions. 2517 /* j_start does not get set correctly if we don't replay any transactions.
@@ -2526,16 +2531,16 @@ static int journal_read(struct super_block *p_s_sb)
2526 } else { 2531 } else {
2527 journal->j_mount_id = newest_mount_id + 1; 2532 journal->j_mount_id = newest_mount_id + 1;
2528 } 2533 }
2529 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1299: Setting " 2534 reiserfs_debug(sb, REISERFS_DEBUG_CODE, "journal-1299: Setting "
2530 "newest_mount_id to %lu", journal->j_mount_id); 2535 "newest_mount_id to %lu", journal->j_mount_id);
2531 journal->j_first_unflushed_offset = journal->j_start; 2536 journal->j_first_unflushed_offset = journal->j_start;
2532 if (replay_count > 0) { 2537 if (replay_count > 0) {
2533 reiserfs_info(p_s_sb, 2538 reiserfs_info(sb,
2534 "replayed %d transactions in %lu seconds\n", 2539 "replayed %d transactions in %lu seconds\n",
2535 replay_count, get_seconds() - start); 2540 replay_count, get_seconds() - start);
2536 } 2541 }
2537 if (!bdev_read_only(p_s_sb->s_bdev) && 2542 if (!bdev_read_only(sb->s_bdev) &&
2538 _update_journal_header_block(p_s_sb, journal->j_start, 2543 _update_journal_header_block(sb, journal->j_start,
2539 journal->j_last_flush_trans_id)) { 2544 journal->j_last_flush_trans_id)) {
2540 /* replay failed, caller must call free_journal_ram and abort 2545 /* replay failed, caller must call free_journal_ram and abort
2541 ** the mount 2546 ** the mount
@@ -2560,9 +2565,9 @@ static struct reiserfs_journal_list *alloc_journal_list(struct super_block *s)
2560 return jl; 2565 return jl;
2561} 2566}
2562 2567
2563static void journal_list_init(struct super_block *p_s_sb) 2568static void journal_list_init(struct super_block *sb)
2564{ 2569{
2565 SB_JOURNAL(p_s_sb)->j_current_jl = alloc_journal_list(p_s_sb); 2570 SB_JOURNAL(sb)->j_current_jl = alloc_journal_list(sb);
2566} 2571}
2567 2572
2568static int release_journal_dev(struct super_block *super, 2573static int release_journal_dev(struct super_block *super,
@@ -2580,9 +2585,8 @@ static int release_journal_dev(struct super_block *super,
2580 } 2585 }
2581 2586
2582 if (result != 0) { 2587 if (result != 0) {
2583 reiserfs_warning(super, 2588 reiserfs_warning(super, "sh-457",
2584 "sh-457: release_journal_dev: Cannot release journal device: %i", 2589 "Cannot release journal device: %i", result);
2585 result);
2586 } 2590 }
2587 return result; 2591 return result;
2588} 2592}
@@ -2612,7 +2616,7 @@ static int journal_init_dev(struct super_block *super,
2612 if (IS_ERR(journal->j_dev_bd)) { 2616 if (IS_ERR(journal->j_dev_bd)) {
2613 result = PTR_ERR(journal->j_dev_bd); 2617 result = PTR_ERR(journal->j_dev_bd);
2614 journal->j_dev_bd = NULL; 2618 journal->j_dev_bd = NULL;
2615 reiserfs_warning(super, "sh-458: journal_init_dev: " 2619 reiserfs_warning(super, "sh-458",
2616 "cannot init journal device '%s': %i", 2620 "cannot init journal device '%s': %i",
2617 __bdevname(jdev, b), result); 2621 __bdevname(jdev, b), result);
2618 return result; 2622 return result;
@@ -2662,30 +2666,30 @@ static int journal_init_dev(struct super_block *super,
2662 */ 2666 */
2663#define REISERFS_STANDARD_BLKSIZE (4096) 2667#define REISERFS_STANDARD_BLKSIZE (4096)
2664 2668
2665static int check_advise_trans_params(struct super_block *p_s_sb, 2669static int check_advise_trans_params(struct super_block *sb,
2666 struct reiserfs_journal *journal) 2670 struct reiserfs_journal *journal)
2667{ 2671{
2668 if (journal->j_trans_max) { 2672 if (journal->j_trans_max) {
2669 /* Non-default journal params. 2673 /* Non-default journal params.
2670 Do sanity check for them. */ 2674 Do sanity check for them. */
2671 int ratio = 1; 2675 int ratio = 1;
2672 if (p_s_sb->s_blocksize < REISERFS_STANDARD_BLKSIZE) 2676 if (sb->s_blocksize < REISERFS_STANDARD_BLKSIZE)
2673 ratio = REISERFS_STANDARD_BLKSIZE / p_s_sb->s_blocksize; 2677 ratio = REISERFS_STANDARD_BLKSIZE / sb->s_blocksize;
2674 2678
2675 if (journal->j_trans_max > JOURNAL_TRANS_MAX_DEFAULT / ratio || 2679 if (journal->j_trans_max > JOURNAL_TRANS_MAX_DEFAULT / ratio ||
2676 journal->j_trans_max < JOURNAL_TRANS_MIN_DEFAULT / ratio || 2680 journal->j_trans_max < JOURNAL_TRANS_MIN_DEFAULT / ratio ||
2677 SB_ONDISK_JOURNAL_SIZE(p_s_sb) / journal->j_trans_max < 2681 SB_ONDISK_JOURNAL_SIZE(sb) / journal->j_trans_max <
2678 JOURNAL_MIN_RATIO) { 2682 JOURNAL_MIN_RATIO) {
2679 reiserfs_warning(p_s_sb, 2683 reiserfs_warning(sb, "sh-462",
2680 "sh-462: bad transaction max size (%u). FSCK?", 2684 "bad transaction max size (%u). "
2681 journal->j_trans_max); 2685 "FSCK?", journal->j_trans_max);
2682 return 1; 2686 return 1;
2683 } 2687 }
2684 if (journal->j_max_batch != (journal->j_trans_max) * 2688 if (journal->j_max_batch != (journal->j_trans_max) *
2685 JOURNAL_MAX_BATCH_DEFAULT/JOURNAL_TRANS_MAX_DEFAULT) { 2689 JOURNAL_MAX_BATCH_DEFAULT/JOURNAL_TRANS_MAX_DEFAULT) {
2686 reiserfs_warning(p_s_sb, 2690 reiserfs_warning(sb, "sh-463",
2687 "sh-463: bad transaction max batch (%u). FSCK?", 2691 "bad transaction max batch (%u). "
2688 journal->j_max_batch); 2692 "FSCK?", journal->j_max_batch);
2689 return 1; 2693 return 1;
2690 } 2694 }
2691 } else { 2695 } else {
@@ -2693,9 +2697,11 @@ static int check_advise_trans_params(struct super_block *p_s_sb,
2693 The file system was created by old version 2697 The file system was created by old version
2694 of mkreiserfs, so some fields contain zeros, 2698 of mkreiserfs, so some fields contain zeros,
2695 and we need to advise proper values for them */ 2699 and we need to advise proper values for them */
2696 if (p_s_sb->s_blocksize != REISERFS_STANDARD_BLKSIZE) 2700 if (sb->s_blocksize != REISERFS_STANDARD_BLKSIZE) {
2697 reiserfs_panic(p_s_sb, "sh-464: bad blocksize (%u)", 2701 reiserfs_warning(sb, "sh-464", "bad blocksize (%u)",
2698 p_s_sb->s_blocksize); 2702 sb->s_blocksize);
2703 return 1;
2704 }
2699 journal->j_trans_max = JOURNAL_TRANS_MAX_DEFAULT; 2705 journal->j_trans_max = JOURNAL_TRANS_MAX_DEFAULT;
2700 journal->j_max_batch = JOURNAL_MAX_BATCH_DEFAULT; 2706 journal->j_max_batch = JOURNAL_MAX_BATCH_DEFAULT;
2701 journal->j_max_commit_age = JOURNAL_MAX_COMMIT_AGE; 2707 journal->j_max_commit_age = JOURNAL_MAX_COMMIT_AGE;
@@ -2706,10 +2712,10 @@ static int check_advise_trans_params(struct super_block *p_s_sb,
2706/* 2712/*
2707** must be called once on fs mount. calls journal_read for you 2713** must be called once on fs mount. calls journal_read for you
2708*/ 2714*/
2709int journal_init(struct super_block *p_s_sb, const char *j_dev_name, 2715int journal_init(struct super_block *sb, const char *j_dev_name,
2710 int old_format, unsigned int commit_max_age) 2716 int old_format, unsigned int commit_max_age)
2711{ 2717{
2712 int num_cnodes = SB_ONDISK_JOURNAL_SIZE(p_s_sb) * 2; 2718 int num_cnodes = SB_ONDISK_JOURNAL_SIZE(sb) * 2;
2713 struct buffer_head *bhjh; 2719 struct buffer_head *bhjh;
2714 struct reiserfs_super_block *rs; 2720 struct reiserfs_super_block *rs;
2715 struct reiserfs_journal_header *jh; 2721 struct reiserfs_journal_header *jh;
@@ -2717,10 +2723,10 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2717 struct reiserfs_journal_list *jl; 2723 struct reiserfs_journal_list *jl;
2718 char b[BDEVNAME_SIZE]; 2724 char b[BDEVNAME_SIZE];
2719 2725
2720 journal = SB_JOURNAL(p_s_sb) = vmalloc(sizeof(struct reiserfs_journal)); 2726 journal = SB_JOURNAL(sb) = vmalloc(sizeof(struct reiserfs_journal));
2721 if (!journal) { 2727 if (!journal) {
2722 reiserfs_warning(p_s_sb, 2728 reiserfs_warning(sb, "journal-1256",
2723 "journal-1256: unable to get memory for journal structure"); 2729 "unable to get memory for journal structure");
2724 return 1; 2730 return 1;
2725 } 2731 }
2726 memset(journal, 0, sizeof(struct reiserfs_journal)); 2732 memset(journal, 0, sizeof(struct reiserfs_journal));
@@ -2729,51 +2735,51 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2729 INIT_LIST_HEAD(&journal->j_working_list); 2735 INIT_LIST_HEAD(&journal->j_working_list);
2730 INIT_LIST_HEAD(&journal->j_journal_list); 2736 INIT_LIST_HEAD(&journal->j_journal_list);
2731 journal->j_persistent_trans = 0; 2737 journal->j_persistent_trans = 0;
2732 if (reiserfs_allocate_list_bitmaps(p_s_sb, 2738 if (reiserfs_allocate_list_bitmaps(sb,
2733 journal->j_list_bitmap, 2739 journal->j_list_bitmap,
2734 reiserfs_bmap_count(p_s_sb))) 2740 reiserfs_bmap_count(sb)))
2735 goto free_and_return; 2741 goto free_and_return;
2736 allocate_bitmap_nodes(p_s_sb); 2742 allocate_bitmap_nodes(sb);
2737 2743
2738 /* reserved for journal area support */ 2744 /* reserved for journal area support */
2739 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ? 2745 SB_JOURNAL_1st_RESERVED_BLOCK(sb) = (old_format ?
2740 REISERFS_OLD_DISK_OFFSET_IN_BYTES 2746 REISERFS_OLD_DISK_OFFSET_IN_BYTES
2741 / p_s_sb->s_blocksize + 2747 / sb->s_blocksize +
2742 reiserfs_bmap_count(p_s_sb) + 2748 reiserfs_bmap_count(sb) +
2743 1 : 2749 1 :
2744 REISERFS_DISK_OFFSET_IN_BYTES / 2750 REISERFS_DISK_OFFSET_IN_BYTES /
2745 p_s_sb->s_blocksize + 2); 2751 sb->s_blocksize + 2);
2746 2752
2747 /* Sanity check to see is the standard journal fitting withing first bitmap 2753 /* Sanity check to see is the standard journal fitting withing first bitmap
2748 (actual for small blocksizes) */ 2754 (actual for small blocksizes) */
2749 if (!SB_ONDISK_JOURNAL_DEVICE(p_s_sb) && 2755 if (!SB_ONDISK_JOURNAL_DEVICE(sb) &&
2750 (SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) + 2756 (SB_JOURNAL_1st_RESERVED_BLOCK(sb) +
2751 SB_ONDISK_JOURNAL_SIZE(p_s_sb) > p_s_sb->s_blocksize * 8)) { 2757 SB_ONDISK_JOURNAL_SIZE(sb) > sb->s_blocksize * 8)) {
2752 reiserfs_warning(p_s_sb, 2758 reiserfs_warning(sb, "journal-1393",
2753 "journal-1393: journal does not fit for area " 2759 "journal does not fit for area addressed "
2754 "addressed by first of bitmap blocks. It starts at " 2760 "by first of bitmap blocks. It starts at "
2755 "%u and its size is %u. Block size %ld", 2761 "%u and its size is %u. Block size %ld",
2756 SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb), 2762 SB_JOURNAL_1st_RESERVED_BLOCK(sb),
2757 SB_ONDISK_JOURNAL_SIZE(p_s_sb), 2763 SB_ONDISK_JOURNAL_SIZE(sb),
2758 p_s_sb->s_blocksize); 2764 sb->s_blocksize);
2759 goto free_and_return; 2765 goto free_and_return;
2760 } 2766 }
2761 2767
2762 if (journal_init_dev(p_s_sb, journal, j_dev_name) != 0) { 2768 if (journal_init_dev(sb, journal, j_dev_name) != 0) {
2763 reiserfs_warning(p_s_sb, 2769 reiserfs_warning(sb, "sh-462",
2764 "sh-462: unable to initialize jornal device"); 2770 "unable to initialize jornal device");
2765 goto free_and_return; 2771 goto free_and_return;
2766 } 2772 }
2767 2773
2768 rs = SB_DISK_SUPER_BLOCK(p_s_sb); 2774 rs = SB_DISK_SUPER_BLOCK(sb);
2769 2775
2770 /* read journal header */ 2776 /* read journal header */
2771 bhjh = journal_bread(p_s_sb, 2777 bhjh = journal_bread(sb,
2772 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 2778 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
2773 SB_ONDISK_JOURNAL_SIZE(p_s_sb)); 2779 SB_ONDISK_JOURNAL_SIZE(sb));
2774 if (!bhjh) { 2780 if (!bhjh) {
2775 reiserfs_warning(p_s_sb, 2781 reiserfs_warning(sb, "sh-459",
2776 "sh-459: unable to read journal header"); 2782 "unable to read journal header");
2777 goto free_and_return; 2783 goto free_and_return;
2778 } 2784 }
2779 jh = (struct reiserfs_journal_header *)(bhjh->b_data); 2785 jh = (struct reiserfs_journal_header *)(bhjh->b_data);
@@ -2782,10 +2788,10 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2782 if (is_reiserfs_jr(rs) 2788 if (is_reiserfs_jr(rs)
2783 && (le32_to_cpu(jh->jh_journal.jp_journal_magic) != 2789 && (le32_to_cpu(jh->jh_journal.jp_journal_magic) !=
2784 sb_jp_journal_magic(rs))) { 2790 sb_jp_journal_magic(rs))) {
2785 reiserfs_warning(p_s_sb, 2791 reiserfs_warning(sb, "sh-460",
2786 "sh-460: journal header magic %x " 2792 "journal header magic %x (device %s) does "
2787 "(device %s) does not match to magic found in super " 2793 "not match to magic found in super block %x",
2788 "block %x", jh->jh_journal.jp_journal_magic, 2794 jh->jh_journal.jp_journal_magic,
2789 bdevname(journal->j_dev_bd, b), 2795 bdevname(journal->j_dev_bd, b),
2790 sb_jp_journal_magic(rs)); 2796 sb_jp_journal_magic(rs));
2791 brelse(bhjh); 2797 brelse(bhjh);
@@ -2798,7 +2804,7 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2798 le32_to_cpu(jh->jh_journal.jp_journal_max_commit_age); 2804 le32_to_cpu(jh->jh_journal.jp_journal_max_commit_age);
2799 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE; 2805 journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
2800 2806
2801 if (check_advise_trans_params(p_s_sb, journal) != 0) 2807 if (check_advise_trans_params(sb, journal) != 0)
2802 goto free_and_return; 2808 goto free_and_return;
2803 journal->j_default_max_commit_age = journal->j_max_commit_age; 2809 journal->j_default_max_commit_age = journal->j_max_commit_age;
2804 2810
@@ -2807,12 +2813,12 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2807 journal->j_max_trans_age = commit_max_age; 2813 journal->j_max_trans_age = commit_max_age;
2808 } 2814 }
2809 2815
2810 reiserfs_info(p_s_sb, "journal params: device %s, size %u, " 2816 reiserfs_info(sb, "journal params: device %s, size %u, "
2811 "journal first block %u, max trans len %u, max batch %u, " 2817 "journal first block %u, max trans len %u, max batch %u, "
2812 "max commit age %u, max trans age %u\n", 2818 "max commit age %u, max trans age %u\n",
2813 bdevname(journal->j_dev_bd, b), 2819 bdevname(journal->j_dev_bd, b),
2814 SB_ONDISK_JOURNAL_SIZE(p_s_sb), 2820 SB_ONDISK_JOURNAL_SIZE(sb),
2815 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb), 2821 SB_ONDISK_JOURNAL_1st_BLOCK(sb),
2816 journal->j_trans_max, 2822 journal->j_trans_max,
2817 journal->j_max_batch, 2823 journal->j_max_batch,
2818 journal->j_max_commit_age, journal->j_max_trans_age); 2824 journal->j_max_commit_age, journal->j_max_trans_age);
@@ -2820,7 +2826,7 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2820 brelse(bhjh); 2826 brelse(bhjh);
2821 2827
2822 journal->j_list_bitmap_index = 0; 2828 journal->j_list_bitmap_index = 0;
2823 journal_list_init(p_s_sb); 2829 journal_list_init(sb);
2824 2830
2825 memset(journal->j_list_hash_table, 0, 2831 memset(journal->j_list_hash_table, 0,
2826 JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *)); 2832 JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *));
@@ -2852,7 +2858,7 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2852 journal->j_must_wait = 0; 2858 journal->j_must_wait = 0;
2853 2859
2854 if (journal->j_cnode_free == 0) { 2860 if (journal->j_cnode_free == 0) {
2855 reiserfs_warning(p_s_sb, "journal-2004: Journal cnode memory " 2861 reiserfs_warning(sb, "journal-2004", "Journal cnode memory "
2856 "allocation failed (%ld bytes). Journal is " 2862 "allocation failed (%ld bytes). Journal is "
2857 "too large for available memory. Usually " 2863 "too large for available memory. Usually "
2858 "this is due to a journal that is too large.", 2864 "this is due to a journal that is too large.",
@@ -2860,16 +2866,17 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2860 goto free_and_return; 2866 goto free_and_return;
2861 } 2867 }
2862 2868
2863 init_journal_hash(p_s_sb); 2869 init_journal_hash(sb);
2864 jl = journal->j_current_jl; 2870 jl = journal->j_current_jl;
2865 jl->j_list_bitmap = get_list_bitmap(p_s_sb, jl); 2871 jl->j_list_bitmap = get_list_bitmap(sb, jl);
2866 if (!jl->j_list_bitmap) { 2872 if (!jl->j_list_bitmap) {
2867 reiserfs_warning(p_s_sb, 2873 reiserfs_warning(sb, "journal-2005",
2868 "journal-2005, get_list_bitmap failed for journal list 0"); 2874 "get_list_bitmap failed for journal list 0");
2869 goto free_and_return; 2875 goto free_and_return;
2870 } 2876 }
2871 if (journal_read(p_s_sb) < 0) { 2877 if (journal_read(sb) < 0) {
2872 reiserfs_warning(p_s_sb, "Replay Failure, unable to mount"); 2878 reiserfs_warning(sb, "reiserfs-2006",
2879 "Replay Failure, unable to mount");
2873 goto free_and_return; 2880 goto free_and_return;
2874 } 2881 }
2875 2882
@@ -2878,10 +2885,10 @@ int journal_init(struct super_block *p_s_sb, const char *j_dev_name,
2878 commit_wq = create_workqueue("reiserfs"); 2885 commit_wq = create_workqueue("reiserfs");
2879 2886
2880 INIT_DELAYED_WORK(&journal->j_work, flush_async_commits); 2887 INIT_DELAYED_WORK(&journal->j_work, flush_async_commits);
2881 journal->j_work_sb = p_s_sb; 2888 journal->j_work_sb = sb;
2882 return 0; 2889 return 0;
2883 free_and_return: 2890 free_and_return:
2884 free_journal_ram(p_s_sb); 2891 free_journal_ram(sb);
2885 return 1; 2892 return 1;
2886} 2893}
2887 2894
@@ -2912,7 +2919,7 @@ int journal_transaction_should_end(struct reiserfs_transaction_handle *th,
2912 return 0; 2919 return 0;
2913} 2920}
2914 2921
2915/* this must be called inside a transaction, and requires the 2922/* this must be called inside a transaction, and requires the
2916** kernel_lock to be held 2923** kernel_lock to be held
2917*/ 2924*/
2918void reiserfs_block_writes(struct reiserfs_transaction_handle *th) 2925void reiserfs_block_writes(struct reiserfs_transaction_handle *th)
@@ -2970,7 +2977,7 @@ static void wake_queued_writers(struct super_block *s)
2970 wake_up(&journal->j_join_wait); 2977 wake_up(&journal->j_join_wait);
2971} 2978}
2972 2979
2973static void let_transaction_grow(struct super_block *sb, unsigned long trans_id) 2980static void let_transaction_grow(struct super_block *sb, unsigned int trans_id)
2974{ 2981{
2975 struct reiserfs_journal *journal = SB_JOURNAL(sb); 2982 struct reiserfs_journal *journal = SB_JOURNAL(sb);
2976 unsigned long bcount = journal->j_bcount; 2983 unsigned long bcount = journal->j_bcount;
@@ -2997,43 +3004,43 @@ static void let_transaction_grow(struct super_block *sb, unsigned long trans_id)
2997** expect to use in nblocks. 3004** expect to use in nblocks.
2998*/ 3005*/
2999static int do_journal_begin_r(struct reiserfs_transaction_handle *th, 3006static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
3000 struct super_block *p_s_sb, unsigned long nblocks, 3007 struct super_block *sb, unsigned long nblocks,
3001 int join) 3008 int join)
3002{ 3009{
3003 time_t now = get_seconds(); 3010 time_t now = get_seconds();
3004 int old_trans_id; 3011 unsigned int old_trans_id;
3005 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3012 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3006 struct reiserfs_transaction_handle myth; 3013 struct reiserfs_transaction_handle myth;
3007 int sched_count = 0; 3014 int sched_count = 0;
3008 int retval; 3015 int retval;
3009 3016
3010 reiserfs_check_lock_depth(p_s_sb, "journal_begin"); 3017 reiserfs_check_lock_depth(sb, "journal_begin");
3011 BUG_ON(nblocks > journal->j_trans_max); 3018 BUG_ON(nblocks > journal->j_trans_max);
3012 3019
3013 PROC_INFO_INC(p_s_sb, journal.journal_being); 3020 PROC_INFO_INC(sb, journal.journal_being);
3014 /* set here for journal_join */ 3021 /* set here for journal_join */
3015 th->t_refcount = 1; 3022 th->t_refcount = 1;
3016 th->t_super = p_s_sb; 3023 th->t_super = sb;
3017 3024
3018 relock: 3025 relock:
3019 lock_journal(p_s_sb); 3026 lock_journal(sb);
3020 if (join != JBEGIN_ABORT && reiserfs_is_journal_aborted(journal)) { 3027 if (join != JBEGIN_ABORT && reiserfs_is_journal_aborted(journal)) {
3021 unlock_journal(p_s_sb); 3028 unlock_journal(sb);
3022 retval = journal->j_errno; 3029 retval = journal->j_errno;
3023 goto out_fail; 3030 goto out_fail;
3024 } 3031 }
3025 journal->j_bcount++; 3032 journal->j_bcount++;
3026 3033
3027 if (test_bit(J_WRITERS_BLOCKED, &journal->j_state)) { 3034 if (test_bit(J_WRITERS_BLOCKED, &journal->j_state)) {
3028 unlock_journal(p_s_sb); 3035 unlock_journal(sb);
3029 reiserfs_wait_on_write_block(p_s_sb); 3036 reiserfs_wait_on_write_block(sb);
3030 PROC_INFO_INC(p_s_sb, journal.journal_relock_writers); 3037 PROC_INFO_INC(sb, journal.journal_relock_writers);
3031 goto relock; 3038 goto relock;
3032 } 3039 }
3033 now = get_seconds(); 3040 now = get_seconds();
3034 3041
3035 /* if there is no room in the journal OR 3042 /* if there is no room in the journal OR
3036 ** if this transaction is too old, and we weren't called joinable, wait for it to finish before beginning 3043 ** if this transaction is too old, and we weren't called joinable, wait for it to finish before beginning
3037 ** we don't sleep if there aren't other writers 3044 ** we don't sleep if there aren't other writers
3038 */ 3045 */
3039 3046
@@ -3048,7 +3055,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
3048 || (!join && journal->j_cnode_free < (journal->j_trans_max * 3))) { 3055 || (!join && journal->j_cnode_free < (journal->j_trans_max * 3))) {
3049 3056
3050 old_trans_id = journal->j_trans_id; 3057 old_trans_id = journal->j_trans_id;
3051 unlock_journal(p_s_sb); /* allow others to finish this transaction */ 3058 unlock_journal(sb); /* allow others to finish this transaction */
3052 3059
3053 if (!join && (journal->j_len_alloc + nblocks + 2) >= 3060 if (!join && (journal->j_len_alloc + nblocks + 2) >=
3054 journal->j_max_batch && 3061 journal->j_max_batch &&
@@ -3056,7 +3063,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
3056 (journal->j_len_alloc * 75)) { 3063 (journal->j_len_alloc * 75)) {
3057 if (atomic_read(&journal->j_wcount) > 10) { 3064 if (atomic_read(&journal->j_wcount) > 10) {
3058 sched_count++; 3065 sched_count++;
3059 queue_log_writer(p_s_sb); 3066 queue_log_writer(sb);
3060 goto relock; 3067 goto relock;
3061 } 3068 }
3062 } 3069 }
@@ -3066,25 +3073,25 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
3066 if (atomic_read(&journal->j_jlock)) { 3073 if (atomic_read(&journal->j_jlock)) {
3067 while (journal->j_trans_id == old_trans_id && 3074 while (journal->j_trans_id == old_trans_id &&
3068 atomic_read(&journal->j_jlock)) { 3075 atomic_read(&journal->j_jlock)) {
3069 queue_log_writer(p_s_sb); 3076 queue_log_writer(sb);
3070 } 3077 }
3071 goto relock; 3078 goto relock;
3072 } 3079 }
3073 retval = journal_join(&myth, p_s_sb, 1); 3080 retval = journal_join(&myth, sb, 1);
3074 if (retval) 3081 if (retval)
3075 goto out_fail; 3082 goto out_fail;
3076 3083
3077 /* someone might have ended the transaction while we joined */ 3084 /* someone might have ended the transaction while we joined */
3078 if (old_trans_id != journal->j_trans_id) { 3085 if (old_trans_id != journal->j_trans_id) {
3079 retval = do_journal_end(&myth, p_s_sb, 1, 0); 3086 retval = do_journal_end(&myth, sb, 1, 0);
3080 } else { 3087 } else {
3081 retval = do_journal_end(&myth, p_s_sb, 1, COMMIT_NOW); 3088 retval = do_journal_end(&myth, sb, 1, COMMIT_NOW);
3082 } 3089 }
3083 3090
3084 if (retval) 3091 if (retval)
3085 goto out_fail; 3092 goto out_fail;
3086 3093
3087 PROC_INFO_INC(p_s_sb, journal.journal_relock_wcount); 3094 PROC_INFO_INC(sb, journal.journal_relock_wcount);
3088 goto relock; 3095 goto relock;
3089 } 3096 }
3090 /* we are the first writer, set trans_id */ 3097 /* we are the first writer, set trans_id */
@@ -3096,7 +3103,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
3096 th->t_blocks_logged = 0; 3103 th->t_blocks_logged = 0;
3097 th->t_blocks_allocated = nblocks; 3104 th->t_blocks_allocated = nblocks;
3098 th->t_trans_id = journal->j_trans_id; 3105 th->t_trans_id = journal->j_trans_id;
3099 unlock_journal(p_s_sb); 3106 unlock_journal(sb);
3100 INIT_LIST_HEAD(&th->t_list); 3107 INIT_LIST_HEAD(&th->t_list);
3101 get_fs_excl(); 3108 get_fs_excl();
3102 return 0; 3109 return 0;
@@ -3106,7 +3113,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
3106 /* Re-set th->t_super, so we can properly keep track of how many 3113 /* Re-set th->t_super, so we can properly keep track of how many
3107 * persistent transactions there are. We need to do this so if this 3114 * persistent transactions there are. We need to do this so if this
3108 * call is part of a failed restart_transaction, we can free it later */ 3115 * call is part of a failed restart_transaction, we can free it later */
3109 th->t_super = p_s_sb; 3116 th->t_super = sb;
3110 return retval; 3117 return retval;
3111} 3118}
3112 3119
@@ -3157,7 +3164,7 @@ int reiserfs_end_persistent_transaction(struct reiserfs_transaction_handle *th)
3157} 3164}
3158 3165
3159static int journal_join(struct reiserfs_transaction_handle *th, 3166static int journal_join(struct reiserfs_transaction_handle *th,
3160 struct super_block *p_s_sb, unsigned long nblocks) 3167 struct super_block *sb, unsigned long nblocks)
3161{ 3168{
3162 struct reiserfs_transaction_handle *cur_th = current->journal_info; 3169 struct reiserfs_transaction_handle *cur_th = current->journal_info;
3163 3170
@@ -3166,11 +3173,11 @@ static int journal_join(struct reiserfs_transaction_handle *th,
3166 */ 3173 */
3167 th->t_handle_save = cur_th; 3174 th->t_handle_save = cur_th;
3168 BUG_ON(cur_th && cur_th->t_refcount > 1); 3175 BUG_ON(cur_th && cur_th->t_refcount > 1);
3169 return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_JOIN); 3176 return do_journal_begin_r(th, sb, nblocks, JBEGIN_JOIN);
3170} 3177}
3171 3178
3172int journal_join_abort(struct reiserfs_transaction_handle *th, 3179int journal_join_abort(struct reiserfs_transaction_handle *th,
3173 struct super_block *p_s_sb, unsigned long nblocks) 3180 struct super_block *sb, unsigned long nblocks)
3174{ 3181{
3175 struct reiserfs_transaction_handle *cur_th = current->journal_info; 3182 struct reiserfs_transaction_handle *cur_th = current->journal_info;
3176 3183
@@ -3179,11 +3186,11 @@ int journal_join_abort(struct reiserfs_transaction_handle *th,
3179 */ 3186 */
3180 th->t_handle_save = cur_th; 3187 th->t_handle_save = cur_th;
3181 BUG_ON(cur_th && cur_th->t_refcount > 1); 3188 BUG_ON(cur_th && cur_th->t_refcount > 1);
3182 return do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_ABORT); 3189 return do_journal_begin_r(th, sb, nblocks, JBEGIN_ABORT);
3183} 3190}
3184 3191
3185int journal_begin(struct reiserfs_transaction_handle *th, 3192int journal_begin(struct reiserfs_transaction_handle *th,
3186 struct super_block *p_s_sb, unsigned long nblocks) 3193 struct super_block *sb, unsigned long nblocks)
3187{ 3194{
3188 struct reiserfs_transaction_handle *cur_th = current->journal_info; 3195 struct reiserfs_transaction_handle *cur_th = current->journal_info;
3189 int ret; 3196 int ret;
@@ -3191,28 +3198,29 @@ int journal_begin(struct reiserfs_transaction_handle *th,
3191 th->t_handle_save = NULL; 3198 th->t_handle_save = NULL;
3192 if (cur_th) { 3199 if (cur_th) {
3193 /* we are nesting into the current transaction */ 3200 /* we are nesting into the current transaction */
3194 if (cur_th->t_super == p_s_sb) { 3201 if (cur_th->t_super == sb) {
3195 BUG_ON(!cur_th->t_refcount); 3202 BUG_ON(!cur_th->t_refcount);
3196 cur_th->t_refcount++; 3203 cur_th->t_refcount++;
3197 memcpy(th, cur_th, sizeof(*th)); 3204 memcpy(th, cur_th, sizeof(*th));
3198 if (th->t_refcount <= 1) 3205 if (th->t_refcount <= 1)
3199 reiserfs_warning(p_s_sb, 3206 reiserfs_warning(sb, "reiserfs-2005",
3200 "BAD: refcount <= 1, but journal_info != 0"); 3207 "BAD: refcount <= 1, but "
3208 "journal_info != 0");
3201 return 0; 3209 return 0;
3202 } else { 3210 } else {
3203 /* we've ended up with a handle from a different filesystem. 3211 /* we've ended up with a handle from a different filesystem.
3204 ** save it and restore on journal_end. This should never 3212 ** save it and restore on journal_end. This should never
3205 ** really happen... 3213 ** really happen...
3206 */ 3214 */
3207 reiserfs_warning(p_s_sb, 3215 reiserfs_warning(sb, "clm-2100",
3208 "clm-2100: nesting info a different FS"); 3216 "nesting info a different FS");
3209 th->t_handle_save = current->journal_info; 3217 th->t_handle_save = current->journal_info;
3210 current->journal_info = th; 3218 current->journal_info = th;
3211 } 3219 }
3212 } else { 3220 } else {
3213 current->journal_info = th; 3221 current->journal_info = th;
3214 } 3222 }
3215 ret = do_journal_begin_r(th, p_s_sb, nblocks, JBEGIN_REG); 3223 ret = do_journal_begin_r(th, sb, nblocks, JBEGIN_REG);
3216 BUG_ON(current->journal_info != th); 3224 BUG_ON(current->journal_info != th);
3217 3225
3218 /* I guess this boils down to being the reciprocal of clm-2100 above. 3226 /* I guess this boils down to being the reciprocal of clm-2100 above.
@@ -3232,32 +3240,32 @@ int journal_begin(struct reiserfs_transaction_handle *th,
3232** 3240**
3233** if it was dirty, cleans and files onto the clean list. I can't let it be dirty again until the 3241** if it was dirty, cleans and files onto the clean list. I can't let it be dirty again until the
3234** transaction is committed. 3242** transaction is committed.
3235** 3243**
3236** if j_len, is bigger than j_len_alloc, it pushes j_len_alloc to 10 + j_len. 3244** if j_len, is bigger than j_len_alloc, it pushes j_len_alloc to 10 + j_len.
3237*/ 3245*/
3238int journal_mark_dirty(struct reiserfs_transaction_handle *th, 3246int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3239 struct super_block *p_s_sb, struct buffer_head *bh) 3247 struct super_block *sb, struct buffer_head *bh)
3240{ 3248{
3241 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3249 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3242 struct reiserfs_journal_cnode *cn = NULL; 3250 struct reiserfs_journal_cnode *cn = NULL;
3243 int count_already_incd = 0; 3251 int count_already_incd = 0;
3244 int prepared = 0; 3252 int prepared = 0;
3245 BUG_ON(!th->t_trans_id); 3253 BUG_ON(!th->t_trans_id);
3246 3254
3247 PROC_INFO_INC(p_s_sb, journal.mark_dirty); 3255 PROC_INFO_INC(sb, journal.mark_dirty);
3248 if (th->t_trans_id != journal->j_trans_id) { 3256 if (th->t_trans_id != journal->j_trans_id) {
3249 reiserfs_panic(th->t_super, 3257 reiserfs_panic(th->t_super, "journal-1577",
3250 "journal-1577: handle trans id %ld != current trans id %ld\n", 3258 "handle trans id %ld != current trans id %ld",
3251 th->t_trans_id, journal->j_trans_id); 3259 th->t_trans_id, journal->j_trans_id);
3252 } 3260 }
3253 3261
3254 p_s_sb->s_dirt = 1; 3262 sb->s_dirt = 1;
3255 3263
3256 prepared = test_clear_buffer_journal_prepared(bh); 3264 prepared = test_clear_buffer_journal_prepared(bh);
3257 clear_buffer_journal_restore_dirty(bh); 3265 clear_buffer_journal_restore_dirty(bh);
3258 /* already in this transaction, we are done */ 3266 /* already in this transaction, we are done */
3259 if (buffer_journaled(bh)) { 3267 if (buffer_journaled(bh)) {
3260 PROC_INFO_INC(p_s_sb, journal.mark_dirty_already); 3268 PROC_INFO_INC(sb, journal.mark_dirty_already);
3261 return 0; 3269 return 0;
3262 } 3270 }
3263 3271
@@ -3266,7 +3274,8 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3266 ** could get to disk too early. NOT GOOD. 3274 ** could get to disk too early. NOT GOOD.
3267 */ 3275 */
3268 if (!prepared || buffer_dirty(bh)) { 3276 if (!prepared || buffer_dirty(bh)) {
3269 reiserfs_warning(p_s_sb, "journal-1777: buffer %llu bad state " 3277 reiserfs_warning(sb, "journal-1777",
3278 "buffer %llu bad state "
3270 "%cPREPARED %cLOCKED %cDIRTY %cJDIRTY_WAIT", 3279 "%cPREPARED %cLOCKED %cDIRTY %cJDIRTY_WAIT",
3271 (unsigned long long)bh->b_blocknr, 3280 (unsigned long long)bh->b_blocknr,
3272 prepared ? ' ' : '!', 3281 prepared ? ' ' : '!',
@@ -3276,23 +3285,23 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3276 } 3285 }
3277 3286
3278 if (atomic_read(&(journal->j_wcount)) <= 0) { 3287 if (atomic_read(&(journal->j_wcount)) <= 0) {
3279 reiserfs_warning(p_s_sb, 3288 reiserfs_warning(sb, "journal-1409",
3280 "journal-1409: journal_mark_dirty returning because j_wcount was %d", 3289 "returning because j_wcount was %d",
3281 atomic_read(&(journal->j_wcount))); 3290 atomic_read(&(journal->j_wcount)));
3282 return 1; 3291 return 1;
3283 } 3292 }
3284 /* this error means I've screwed up, and we've overflowed the transaction. 3293 /* this error means I've screwed up, and we've overflowed the transaction.
3285 ** Nothing can be done here, except make the FS readonly or panic. 3294 ** Nothing can be done here, except make the FS readonly or panic.
3286 */ 3295 */
3287 if (journal->j_len >= journal->j_trans_max) { 3296 if (journal->j_len >= journal->j_trans_max) {
3288 reiserfs_panic(th->t_super, 3297 reiserfs_panic(th->t_super, "journal-1413",
3289 "journal-1413: journal_mark_dirty: j_len (%lu) is too big\n", 3298 "j_len (%lu) is too big",
3290 journal->j_len); 3299 journal->j_len);
3291 } 3300 }
3292 3301
3293 if (buffer_journal_dirty(bh)) { 3302 if (buffer_journal_dirty(bh)) {
3294 count_already_incd = 1; 3303 count_already_incd = 1;
3295 PROC_INFO_INC(p_s_sb, journal.mark_dirty_notjournal); 3304 PROC_INFO_INC(sb, journal.mark_dirty_notjournal);
3296 clear_buffer_journal_dirty(bh); 3305 clear_buffer_journal_dirty(bh);
3297 } 3306 }
3298 3307
@@ -3304,9 +3313,9 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3304 3313
3305 /* now put this guy on the end */ 3314 /* now put this guy on the end */
3306 if (!cn) { 3315 if (!cn) {
3307 cn = get_cnode(p_s_sb); 3316 cn = get_cnode(sb);
3308 if (!cn) { 3317 if (!cn) {
3309 reiserfs_panic(p_s_sb, "get_cnode failed!\n"); 3318 reiserfs_panic(sb, "journal-4", "get_cnode failed!");
3310 } 3319 }
3311 3320
3312 if (th->t_blocks_logged == th->t_blocks_allocated) { 3321 if (th->t_blocks_logged == th->t_blocks_allocated) {
@@ -3318,7 +3327,7 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3318 3327
3319 cn->bh = bh; 3328 cn->bh = bh;
3320 cn->blocknr = bh->b_blocknr; 3329 cn->blocknr = bh->b_blocknr;
3321 cn->sb = p_s_sb; 3330 cn->sb = sb;
3322 cn->jlist = NULL; 3331 cn->jlist = NULL;
3323 insert_journal_hash(journal->j_hash_table, cn); 3332 insert_journal_hash(journal->j_hash_table, cn);
3324 if (!count_already_incd) { 3333 if (!count_already_incd) {
@@ -3339,11 +3348,11 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3339} 3348}
3340 3349
3341int journal_end(struct reiserfs_transaction_handle *th, 3350int journal_end(struct reiserfs_transaction_handle *th,
3342 struct super_block *p_s_sb, unsigned long nblocks) 3351 struct super_block *sb, unsigned long nblocks)
3343{ 3352{
3344 if (!current->journal_info && th->t_refcount > 1) 3353 if (!current->journal_info && th->t_refcount > 1)
3345 reiserfs_warning(p_s_sb, "REISER-NESTING: th NULL, refcount %d", 3354 reiserfs_warning(sb, "REISER-NESTING",
3346 th->t_refcount); 3355 "th NULL, refcount %d", th->t_refcount);
3347 3356
3348 if (!th->t_trans_id) { 3357 if (!th->t_trans_id) {
3349 WARN_ON(1); 3358 WARN_ON(1);
@@ -3366,26 +3375,26 @@ int journal_end(struct reiserfs_transaction_handle *th,
3366 } 3375 }
3367 return 0; 3376 return 0;
3368 } else { 3377 } else {
3369 return do_journal_end(th, p_s_sb, nblocks, 0); 3378 return do_journal_end(th, sb, nblocks, 0);
3370 } 3379 }
3371} 3380}
3372 3381
3373/* removes from the current transaction, relsing and descrementing any counters. 3382/* removes from the current transaction, relsing and descrementing any counters.
3374** also files the removed buffer directly onto the clean list 3383** also files the removed buffer directly onto the clean list
3375** 3384**
3376** called by journal_mark_freed when a block has been deleted 3385** called by journal_mark_freed when a block has been deleted
3377** 3386**
3378** returns 1 if it cleaned and relsed the buffer. 0 otherwise 3387** returns 1 if it cleaned and relsed the buffer. 0 otherwise
3379*/ 3388*/
3380static int remove_from_transaction(struct super_block *p_s_sb, 3389static int remove_from_transaction(struct super_block *sb,
3381 b_blocknr_t blocknr, int already_cleaned) 3390 b_blocknr_t blocknr, int already_cleaned)
3382{ 3391{
3383 struct buffer_head *bh; 3392 struct buffer_head *bh;
3384 struct reiserfs_journal_cnode *cn; 3393 struct reiserfs_journal_cnode *cn;
3385 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3394 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3386 int ret = 0; 3395 int ret = 0;
3387 3396
3388 cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, blocknr); 3397 cn = get_journal_hash_dev(sb, journal->j_hash_table, blocknr);
3389 if (!cn || !cn->bh) { 3398 if (!cn || !cn->bh) {
3390 return ret; 3399 return ret;
3391 } 3400 }
@@ -3403,7 +3412,7 @@ static int remove_from_transaction(struct super_block *p_s_sb,
3403 journal->j_last = cn->prev; 3412 journal->j_last = cn->prev;
3404 } 3413 }
3405 if (bh) 3414 if (bh)
3406 remove_journal_hash(p_s_sb, journal->j_hash_table, NULL, 3415 remove_journal_hash(sb, journal->j_hash_table, NULL,
3407 bh->b_blocknr, 0); 3416 bh->b_blocknr, 0);
3408 clear_buffer_journaled(bh); /* don't log this one */ 3417 clear_buffer_journaled(bh); /* don't log this one */
3409 3418
@@ -3413,14 +3422,14 @@ static int remove_from_transaction(struct super_block *p_s_sb,
3413 clear_buffer_journal_test(bh); 3422 clear_buffer_journal_test(bh);
3414 put_bh(bh); 3423 put_bh(bh);
3415 if (atomic_read(&(bh->b_count)) < 0) { 3424 if (atomic_read(&(bh->b_count)) < 0) {
3416 reiserfs_warning(p_s_sb, 3425 reiserfs_warning(sb, "journal-1752",
3417 "journal-1752: remove from trans, b_count < 0"); 3426 "b_count < 0");
3418 } 3427 }
3419 ret = 1; 3428 ret = 1;
3420 } 3429 }
3421 journal->j_len--; 3430 journal->j_len--;
3422 journal->j_len_alloc--; 3431 journal->j_len_alloc--;
3423 free_cnode(p_s_sb, cn); 3432 free_cnode(sb, cn);
3424 return ret; 3433 return ret;
3425} 3434}
3426 3435
@@ -3468,22 +3477,22 @@ static int can_dirty(struct reiserfs_journal_cnode *cn)
3468} 3477}
3469 3478
3470/* syncs the commit blocks, but does not force the real buffers to disk 3479/* syncs the commit blocks, but does not force the real buffers to disk
3471** will wait until the current transaction is done/committed before returning 3480** will wait until the current transaction is done/committed before returning
3472*/ 3481*/
3473int journal_end_sync(struct reiserfs_transaction_handle *th, 3482int journal_end_sync(struct reiserfs_transaction_handle *th,
3474 struct super_block *p_s_sb, unsigned long nblocks) 3483 struct super_block *sb, unsigned long nblocks)
3475{ 3484{
3476 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3485 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3477 3486
3478 BUG_ON(!th->t_trans_id); 3487 BUG_ON(!th->t_trans_id);
3479 /* you can sync while nested, very, very bad */ 3488 /* you can sync while nested, very, very bad */
3480 BUG_ON(th->t_refcount > 1); 3489 BUG_ON(th->t_refcount > 1);
3481 if (journal->j_len == 0) { 3490 if (journal->j_len == 0) {
3482 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 3491 reiserfs_prepare_for_journal(sb, SB_BUFFER_WITH_SB(sb),
3483 1); 3492 1);
3484 journal_mark_dirty(th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)); 3493 journal_mark_dirty(th, sb, SB_BUFFER_WITH_SB(sb));
3485 } 3494 }
3486 return do_journal_end(th, p_s_sb, nblocks, COMMIT_NOW | WAIT); 3495 return do_journal_end(th, sb, nblocks, COMMIT_NOW | WAIT);
3487} 3496}
3488 3497
3489/* 3498/*
@@ -3493,7 +3502,7 @@ static void flush_async_commits(struct work_struct *work)
3493{ 3502{
3494 struct reiserfs_journal *journal = 3503 struct reiserfs_journal *journal =
3495 container_of(work, struct reiserfs_journal, j_work.work); 3504 container_of(work, struct reiserfs_journal, j_work.work);
3496 struct super_block *p_s_sb = journal->j_work_sb; 3505 struct super_block *sb = journal->j_work_sb;
3497 struct reiserfs_journal_list *jl; 3506 struct reiserfs_journal_list *jl;
3498 struct list_head *entry; 3507 struct list_head *entry;
3499 3508
@@ -3502,7 +3511,7 @@ static void flush_async_commits(struct work_struct *work)
3502 /* last entry is the youngest, commit it and you get everything */ 3511 /* last entry is the youngest, commit it and you get everything */
3503 entry = journal->j_journal_list.prev; 3512 entry = journal->j_journal_list.prev;
3504 jl = JOURNAL_LIST_ENTRY(entry); 3513 jl = JOURNAL_LIST_ENTRY(entry);
3505 flush_commit_list(p_s_sb, jl, 1); 3514 flush_commit_list(sb, jl, 1);
3506 } 3515 }
3507 unlock_kernel(); 3516 unlock_kernel();
3508} 3517}
@@ -3511,11 +3520,11 @@ static void flush_async_commits(struct work_struct *work)
3511** flushes any old transactions to disk 3520** flushes any old transactions to disk
3512** ends the current transaction if it is too old 3521** ends the current transaction if it is too old
3513*/ 3522*/
3514int reiserfs_flush_old_commits(struct super_block *p_s_sb) 3523int reiserfs_flush_old_commits(struct super_block *sb)
3515{ 3524{
3516 time_t now; 3525 time_t now;
3517 struct reiserfs_transaction_handle th; 3526 struct reiserfs_transaction_handle th;
3518 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3527 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3519 3528
3520 now = get_seconds(); 3529 now = get_seconds();
3521 /* safety check so we don't flush while we are replaying the log during 3530 /* safety check so we don't flush while we are replaying the log during
@@ -3532,35 +3541,35 @@ int reiserfs_flush_old_commits(struct super_block *p_s_sb)
3532 journal->j_trans_start_time > 0 && 3541 journal->j_trans_start_time > 0 &&
3533 journal->j_len > 0 && 3542 journal->j_len > 0 &&
3534 (now - journal->j_trans_start_time) > journal->j_max_trans_age) { 3543 (now - journal->j_trans_start_time) > journal->j_max_trans_age) {
3535 if (!journal_join(&th, p_s_sb, 1)) { 3544 if (!journal_join(&th, sb, 1)) {
3536 reiserfs_prepare_for_journal(p_s_sb, 3545 reiserfs_prepare_for_journal(sb,
3537 SB_BUFFER_WITH_SB(p_s_sb), 3546 SB_BUFFER_WITH_SB(sb),
3538 1); 3547 1);
3539 journal_mark_dirty(&th, p_s_sb, 3548 journal_mark_dirty(&th, sb,
3540 SB_BUFFER_WITH_SB(p_s_sb)); 3549 SB_BUFFER_WITH_SB(sb));
3541 3550
3542 /* we're only being called from kreiserfsd, it makes no sense to do 3551 /* we're only being called from kreiserfsd, it makes no sense to do
3543 ** an async commit so that kreiserfsd can do it later 3552 ** an async commit so that kreiserfsd can do it later
3544 */ 3553 */
3545 do_journal_end(&th, p_s_sb, 1, COMMIT_NOW | WAIT); 3554 do_journal_end(&th, sb, 1, COMMIT_NOW | WAIT);
3546 } 3555 }
3547 } 3556 }
3548 return p_s_sb->s_dirt; 3557 return sb->s_dirt;
3549} 3558}
3550 3559
3551/* 3560/*
3552** returns 0 if do_journal_end should return right away, returns 1 if do_journal_end should finish the commit 3561** returns 0 if do_journal_end should return right away, returns 1 if do_journal_end should finish the commit
3553** 3562**
3554** if the current transaction is too old, but still has writers, this will wait on j_join_wait until all 3563** if the current transaction is too old, but still has writers, this will wait on j_join_wait until all
3555** the writers are done. By the time it wakes up, the transaction it was called has already ended, so it just 3564** the writers are done. By the time it wakes up, the transaction it was called has already ended, so it just
3556** flushes the commit list and returns 0. 3565** flushes the commit list and returns 0.
3557** 3566**
3558** Won't batch when flush or commit_now is set. Also won't batch when others are waiting on j_join_wait. 3567** Won't batch when flush or commit_now is set. Also won't batch when others are waiting on j_join_wait.
3559** 3568**
3560** Note, we can't allow the journal_end to proceed while there are still writers in the log. 3569** Note, we can't allow the journal_end to proceed while there are still writers in the log.
3561*/ 3570*/
3562static int check_journal_end(struct reiserfs_transaction_handle *th, 3571static int check_journal_end(struct reiserfs_transaction_handle *th,
3563 struct super_block *p_s_sb, unsigned long nblocks, 3572 struct super_block *sb, unsigned long nblocks,
3564 int flags) 3573 int flags)
3565{ 3574{
3566 3575
@@ -3569,13 +3578,13 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3569 int commit_now = flags & COMMIT_NOW; 3578 int commit_now = flags & COMMIT_NOW;
3570 int wait_on_commit = flags & WAIT; 3579 int wait_on_commit = flags & WAIT;
3571 struct reiserfs_journal_list *jl; 3580 struct reiserfs_journal_list *jl;
3572 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3581 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3573 3582
3574 BUG_ON(!th->t_trans_id); 3583 BUG_ON(!th->t_trans_id);
3575 3584
3576 if (th->t_trans_id != journal->j_trans_id) { 3585 if (th->t_trans_id != journal->j_trans_id) {
3577 reiserfs_panic(th->t_super, 3586 reiserfs_panic(th->t_super, "journal-1577",
3578 "journal-1577: handle trans id %ld != current trans id %ld\n", 3587 "handle trans id %ld != current trans id %ld",
3579 th->t_trans_id, journal->j_trans_id); 3588 th->t_trans_id, journal->j_trans_id);
3580 } 3589 }
3581 3590
@@ -3584,7 +3593,7 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3584 atomic_dec(&(journal->j_wcount)); 3593 atomic_dec(&(journal->j_wcount));
3585 } 3594 }
3586 3595
3587 /* BUG, deal with case where j_len is 0, but people previously freed blocks need to be released 3596 /* BUG, deal with case where j_len is 0, but people previously freed blocks need to be released
3588 ** will be dealt with by next transaction that actually writes something, but should be taken 3597 ** will be dealt with by next transaction that actually writes something, but should be taken
3589 ** care of in this trans 3598 ** care of in this trans
3590 */ 3599 */
@@ -3593,7 +3602,7 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3593 /* if wcount > 0, and we are called to with flush or commit_now, 3602 /* if wcount > 0, and we are called to with flush or commit_now,
3594 ** we wait on j_join_wait. We will wake up when the last writer has 3603 ** we wait on j_join_wait. We will wake up when the last writer has
3595 ** finished the transaction, and started it on its way to the disk. 3604 ** finished the transaction, and started it on its way to the disk.
3596 ** Then, we flush the commit or journal list, and just return 0 3605 ** Then, we flush the commit or journal list, and just return 0
3597 ** because the rest of journal end was already done for this transaction. 3606 ** because the rest of journal end was already done for this transaction.
3598 */ 3607 */
3599 if (atomic_read(&(journal->j_wcount)) > 0) { 3608 if (atomic_read(&(journal->j_wcount)) > 0) {
@@ -3608,31 +3617,31 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3608 if (flush) { 3617 if (flush) {
3609 journal->j_next_full_flush = 1; 3618 journal->j_next_full_flush = 1;
3610 } 3619 }
3611 unlock_journal(p_s_sb); 3620 unlock_journal(sb);
3612 3621
3613 /* sleep while the current transaction is still j_jlocked */ 3622 /* sleep while the current transaction is still j_jlocked */
3614 while (journal->j_trans_id == trans_id) { 3623 while (journal->j_trans_id == trans_id) {
3615 if (atomic_read(&journal->j_jlock)) { 3624 if (atomic_read(&journal->j_jlock)) {
3616 queue_log_writer(p_s_sb); 3625 queue_log_writer(sb);
3617 } else { 3626 } else {
3618 lock_journal(p_s_sb); 3627 lock_journal(sb);
3619 if (journal->j_trans_id == trans_id) { 3628 if (journal->j_trans_id == trans_id) {
3620 atomic_set(&(journal->j_jlock), 3629 atomic_set(&(journal->j_jlock),
3621 1); 3630 1);
3622 } 3631 }
3623 unlock_journal(p_s_sb); 3632 unlock_journal(sb);
3624 } 3633 }
3625 } 3634 }
3626 BUG_ON(journal->j_trans_id == trans_id); 3635 BUG_ON(journal->j_trans_id == trans_id);
3627 3636
3628 if (commit_now 3637 if (commit_now
3629 && journal_list_still_alive(p_s_sb, trans_id) 3638 && journal_list_still_alive(sb, trans_id)
3630 && wait_on_commit) { 3639 && wait_on_commit) {
3631 flush_commit_list(p_s_sb, jl, 1); 3640 flush_commit_list(sb, jl, 1);
3632 } 3641 }
3633 return 0; 3642 return 0;
3634 } 3643 }
3635 unlock_journal(p_s_sb); 3644 unlock_journal(sb);
3636 return 0; 3645 return 0;
3637 } 3646 }
3638 3647
@@ -3649,13 +3658,13 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3649 && journal->j_len_alloc < journal->j_max_batch 3658 && journal->j_len_alloc < journal->j_max_batch
3650 && journal->j_cnode_free > (journal->j_trans_max * 3)) { 3659 && journal->j_cnode_free > (journal->j_trans_max * 3)) {
3651 journal->j_bcount++; 3660 journal->j_bcount++;
3652 unlock_journal(p_s_sb); 3661 unlock_journal(sb);
3653 return 0; 3662 return 0;
3654 } 3663 }
3655 3664
3656 if (journal->j_start > SB_ONDISK_JOURNAL_SIZE(p_s_sb)) { 3665 if (journal->j_start > SB_ONDISK_JOURNAL_SIZE(sb)) {
3657 reiserfs_panic(p_s_sb, 3666 reiserfs_panic(sb, "journal-003",
3658 "journal-003: journal_end: j_start (%ld) is too high\n", 3667 "j_start (%ld) is too high",
3659 journal->j_start); 3668 journal->j_start);
3660 } 3669 }
3661 return 1; 3670 return 1;
@@ -3664,7 +3673,7 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3664/* 3673/*
3665** Does all the work that makes deleting blocks safe. 3674** Does all the work that makes deleting blocks safe.
3666** when deleting a block mark BH_JNew, just remove it from the current transaction, clean it's buffer_head and move on. 3675** when deleting a block mark BH_JNew, just remove it from the current transaction, clean it's buffer_head and move on.
3667** 3676**
3668** otherwise: 3677** otherwise:
3669** set a bit for the block in the journal bitmap. That will prevent it from being allocated for unformatted nodes 3678** set a bit for the block in the journal bitmap. That will prevent it from being allocated for unformatted nodes
3670** before this transaction has finished. 3679** before this transaction has finished.
@@ -3676,16 +3685,16 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3676** Then remove it from the current transaction, decrementing any counters and filing it on the clean list. 3685** Then remove it from the current transaction, decrementing any counters and filing it on the clean list.
3677*/ 3686*/
3678int journal_mark_freed(struct reiserfs_transaction_handle *th, 3687int journal_mark_freed(struct reiserfs_transaction_handle *th,
3679 struct super_block *p_s_sb, b_blocknr_t blocknr) 3688 struct super_block *sb, b_blocknr_t blocknr)
3680{ 3689{
3681 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3690 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3682 struct reiserfs_journal_cnode *cn = NULL; 3691 struct reiserfs_journal_cnode *cn = NULL;
3683 struct buffer_head *bh = NULL; 3692 struct buffer_head *bh = NULL;
3684 struct reiserfs_list_bitmap *jb = NULL; 3693 struct reiserfs_list_bitmap *jb = NULL;
3685 int cleaned = 0; 3694 int cleaned = 0;
3686 BUG_ON(!th->t_trans_id); 3695 BUG_ON(!th->t_trans_id);
3687 3696
3688 cn = get_journal_hash_dev(p_s_sb, journal->j_hash_table, blocknr); 3697 cn = get_journal_hash_dev(sb, journal->j_hash_table, blocknr);
3689 if (cn && cn->bh) { 3698 if (cn && cn->bh) {
3690 bh = cn->bh; 3699 bh = cn->bh;
3691 get_bh(bh); 3700 get_bh(bh);
@@ -3695,15 +3704,15 @@ int journal_mark_freed(struct reiserfs_transaction_handle *th,
3695 clear_buffer_journal_new(bh); 3704 clear_buffer_journal_new(bh);
3696 clear_prepared_bits(bh); 3705 clear_prepared_bits(bh);
3697 reiserfs_clean_and_file_buffer(bh); 3706 reiserfs_clean_and_file_buffer(bh);
3698 cleaned = remove_from_transaction(p_s_sb, blocknr, cleaned); 3707 cleaned = remove_from_transaction(sb, blocknr, cleaned);
3699 } else { 3708 } else {
3700 /* set the bit for this block in the journal bitmap for this transaction */ 3709 /* set the bit for this block in the journal bitmap for this transaction */
3701 jb = journal->j_current_jl->j_list_bitmap; 3710 jb = journal->j_current_jl->j_list_bitmap;
3702 if (!jb) { 3711 if (!jb) {
3703 reiserfs_panic(p_s_sb, 3712 reiserfs_panic(sb, "journal-1702",
3704 "journal-1702: journal_mark_freed, journal_list_bitmap is NULL\n"); 3713 "journal_list_bitmap is NULL");
3705 } 3714 }
3706 set_bit_in_list_bitmap(p_s_sb, blocknr, jb); 3715 set_bit_in_list_bitmap(sb, blocknr, jb);
3707 3716
3708 /* Note, the entire while loop is not allowed to schedule. */ 3717 /* Note, the entire while loop is not allowed to schedule. */
3709 3718
@@ -3711,13 +3720,13 @@ int journal_mark_freed(struct reiserfs_transaction_handle *th,
3711 clear_prepared_bits(bh); 3720 clear_prepared_bits(bh);
3712 reiserfs_clean_and_file_buffer(bh); 3721 reiserfs_clean_and_file_buffer(bh);
3713 } 3722 }
3714 cleaned = remove_from_transaction(p_s_sb, blocknr, cleaned); 3723 cleaned = remove_from_transaction(sb, blocknr, cleaned);
3715 3724
3716 /* find all older transactions with this block, make sure they don't try to write it out */ 3725 /* find all older transactions with this block, make sure they don't try to write it out */
3717 cn = get_journal_hash_dev(p_s_sb, journal->j_list_hash_table, 3726 cn = get_journal_hash_dev(sb, journal->j_list_hash_table,
3718 blocknr); 3727 blocknr);
3719 while (cn) { 3728 while (cn) {
3720 if (p_s_sb == cn->sb && blocknr == cn->blocknr) { 3729 if (sb == cn->sb && blocknr == cn->blocknr) {
3721 set_bit(BLOCK_FREED, &cn->state); 3730 set_bit(BLOCK_FREED, &cn->state);
3722 if (cn->bh) { 3731 if (cn->bh) {
3723 if (!cleaned) { 3732 if (!cleaned) {
@@ -3733,8 +3742,9 @@ int journal_mark_freed(struct reiserfs_transaction_handle *th,
3733 put_bh(cn->bh); 3742 put_bh(cn->bh);
3734 if (atomic_read 3743 if (atomic_read
3735 (&(cn->bh->b_count)) < 0) { 3744 (&(cn->bh->b_count)) < 0) {
3736 reiserfs_warning(p_s_sb, 3745 reiserfs_warning(sb,
3737 "journal-2138: cn->bh->b_count < 0"); 3746 "journal-2138",
3747 "cn->bh->b_count < 0");
3738 } 3748 }
3739 } 3749 }
3740 if (cn->jlist) { /* since we are clearing the bh, we MUST dec nonzerolen */ 3750 if (cn->jlist) { /* since we are clearing the bh, we MUST dec nonzerolen */
@@ -3824,7 +3834,7 @@ static int __commit_trans_jl(struct inode *inode, unsigned long id,
3824 3834
3825int reiserfs_commit_for_inode(struct inode *inode) 3835int reiserfs_commit_for_inode(struct inode *inode)
3826{ 3836{
3827 unsigned long id = REISERFS_I(inode)->i_trans_id; 3837 unsigned int id = REISERFS_I(inode)->i_trans_id;
3828 struct reiserfs_journal_list *jl = REISERFS_I(inode)->i_jl; 3838 struct reiserfs_journal_list *jl = REISERFS_I(inode)->i_jl;
3829 3839
3830 /* for the whole inode, assume unset id means it was 3840 /* for the whole inode, assume unset id means it was
@@ -3839,18 +3849,18 @@ int reiserfs_commit_for_inode(struct inode *inode)
3839 return __commit_trans_jl(inode, id, jl); 3849 return __commit_trans_jl(inode, id, jl);
3840} 3850}
3841 3851
3842void reiserfs_restore_prepared_buffer(struct super_block *p_s_sb, 3852void reiserfs_restore_prepared_buffer(struct super_block *sb,
3843 struct buffer_head *bh) 3853 struct buffer_head *bh)
3844{ 3854{
3845 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3855 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3846 PROC_INFO_INC(p_s_sb, journal.restore_prepared); 3856 PROC_INFO_INC(sb, journal.restore_prepared);
3847 if (!bh) { 3857 if (!bh) {
3848 return; 3858 return;
3849 } 3859 }
3850 if (test_clear_buffer_journal_restore_dirty(bh) && 3860 if (test_clear_buffer_journal_restore_dirty(bh) &&
3851 buffer_journal_dirty(bh)) { 3861 buffer_journal_dirty(bh)) {
3852 struct reiserfs_journal_cnode *cn; 3862 struct reiserfs_journal_cnode *cn;
3853 cn = get_journal_hash_dev(p_s_sb, 3863 cn = get_journal_hash_dev(sb,
3854 journal->j_list_hash_table, 3864 journal->j_list_hash_table,
3855 bh->b_blocknr); 3865 bh->b_blocknr);
3856 if (cn && can_dirty(cn)) { 3866 if (cn && can_dirty(cn)) {
@@ -3867,12 +3877,12 @@ extern struct tree_balance *cur_tb;
3867** be written to disk while we are altering it. So, we must: 3877** be written to disk while we are altering it. So, we must:
3868** clean it 3878** clean it
3869** wait on it. 3879** wait on it.
3870** 3880**
3871*/ 3881*/
3872int reiserfs_prepare_for_journal(struct super_block *p_s_sb, 3882int reiserfs_prepare_for_journal(struct super_block *sb,
3873 struct buffer_head *bh, int wait) 3883 struct buffer_head *bh, int wait)
3874{ 3884{
3875 PROC_INFO_INC(p_s_sb, journal.prepare); 3885 PROC_INFO_INC(sb, journal.prepare);
3876 3886
3877 if (!trylock_buffer(bh)) { 3887 if (!trylock_buffer(bh)) {
3878 if (!wait) 3888 if (!wait)
@@ -3909,7 +3919,7 @@ static void flush_old_journal_lists(struct super_block *s)
3909 } 3919 }
3910} 3920}
3911 3921
3912/* 3922/*
3913** long and ugly. If flush, will not return until all commit 3923** long and ugly. If flush, will not return until all commit
3914** blocks and all real buffers in the trans are on disk. 3924** blocks and all real buffers in the trans are on disk.
3915** If no_async, won't return until all commit blocks are on disk. 3925** If no_async, won't return until all commit blocks are on disk.
@@ -3920,10 +3930,10 @@ static void flush_old_journal_lists(struct super_block *s)
3920** journal lists, etc just won't happen. 3930** journal lists, etc just won't happen.
3921*/ 3931*/
3922static int do_journal_end(struct reiserfs_transaction_handle *th, 3932static int do_journal_end(struct reiserfs_transaction_handle *th,
3923 struct super_block *p_s_sb, unsigned long nblocks, 3933 struct super_block *sb, unsigned long nblocks,
3924 int flags) 3934 int flags)
3925{ 3935{
3926 struct reiserfs_journal *journal = SB_JOURNAL(p_s_sb); 3936 struct reiserfs_journal *journal = SB_JOURNAL(sb);
3927 struct reiserfs_journal_cnode *cn, *next, *jl_cn; 3937 struct reiserfs_journal_cnode *cn, *next, *jl_cn;
3928 struct reiserfs_journal_cnode *last_cn = NULL; 3938 struct reiserfs_journal_cnode *last_cn = NULL;
3929 struct reiserfs_journal_desc *desc; 3939 struct reiserfs_journal_desc *desc;
@@ -3938,7 +3948,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
3938 struct reiserfs_journal_list *jl, *temp_jl; 3948 struct reiserfs_journal_list *jl, *temp_jl;
3939 struct list_head *entry, *safe; 3949 struct list_head *entry, *safe;
3940 unsigned long jindex; 3950 unsigned long jindex;
3941 unsigned long commit_trans_id; 3951 unsigned int commit_trans_id;
3942 int trans_half; 3952 int trans_half;
3943 3953
3944 BUG_ON(th->t_refcount > 1); 3954 BUG_ON(th->t_refcount > 1);
@@ -3946,21 +3956,21 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
3946 3956
3947 /* protect flush_older_commits from doing mistakes if the 3957 /* protect flush_older_commits from doing mistakes if the
3948 transaction ID counter gets overflowed. */ 3958 transaction ID counter gets overflowed. */
3949 if (th->t_trans_id == ~0UL) 3959 if (th->t_trans_id == ~0U)
3950 flags |= FLUSH_ALL | COMMIT_NOW | WAIT; 3960 flags |= FLUSH_ALL | COMMIT_NOW | WAIT;
3951 flush = flags & FLUSH_ALL; 3961 flush = flags & FLUSH_ALL;
3952 wait_on_commit = flags & WAIT; 3962 wait_on_commit = flags & WAIT;
3953 3963
3954 put_fs_excl(); 3964 put_fs_excl();
3955 current->journal_info = th->t_handle_save; 3965 current->journal_info = th->t_handle_save;
3956 reiserfs_check_lock_depth(p_s_sb, "journal end"); 3966 reiserfs_check_lock_depth(sb, "journal end");
3957 if (journal->j_len == 0) { 3967 if (journal->j_len == 0) {
3958 reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 3968 reiserfs_prepare_for_journal(sb, SB_BUFFER_WITH_SB(sb),
3959 1); 3969 1);
3960 journal_mark_dirty(th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)); 3970 journal_mark_dirty(th, sb, SB_BUFFER_WITH_SB(sb));
3961 } 3971 }
3962 3972
3963 lock_journal(p_s_sb); 3973 lock_journal(sb);
3964 if (journal->j_next_full_flush) { 3974 if (journal->j_next_full_flush) {
3965 flags |= FLUSH_ALL; 3975 flags |= FLUSH_ALL;
3966 flush = 1; 3976 flush = 1;
@@ -3970,13 +3980,13 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
3970 wait_on_commit = 1; 3980 wait_on_commit = 1;
3971 } 3981 }
3972 3982
3973 /* check_journal_end locks the journal, and unlocks if it does not return 1 3983 /* check_journal_end locks the journal, and unlocks if it does not return 1
3974 ** it tells us if we should continue with the journal_end, or just return 3984 ** it tells us if we should continue with the journal_end, or just return
3975 */ 3985 */
3976 if (!check_journal_end(th, p_s_sb, nblocks, flags)) { 3986 if (!check_journal_end(th, sb, nblocks, flags)) {
3977 p_s_sb->s_dirt = 1; 3987 sb->s_dirt = 1;
3978 wake_queued_writers(p_s_sb); 3988 wake_queued_writers(sb);
3979 reiserfs_async_progress_wait(p_s_sb); 3989 reiserfs_async_progress_wait(sb);
3980 goto out; 3990 goto out;
3981 } 3991 }
3982 3992
@@ -4005,8 +4015,8 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4005 4015
4006 /* setup description block */ 4016 /* setup description block */
4007 d_bh = 4017 d_bh =
4008 journal_getblk(p_s_sb, 4018 journal_getblk(sb,
4009 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 4019 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
4010 journal->j_start); 4020 journal->j_start);
4011 set_buffer_uptodate(d_bh); 4021 set_buffer_uptodate(d_bh);
4012 desc = (struct reiserfs_journal_desc *)(d_bh)->b_data; 4022 desc = (struct reiserfs_journal_desc *)(d_bh)->b_data;
@@ -4015,9 +4025,9 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4015 set_desc_trans_id(desc, journal->j_trans_id); 4025 set_desc_trans_id(desc, journal->j_trans_id);
4016 4026
4017 /* setup commit block. Don't write (keep it clean too) this one until after everyone else is written */ 4027 /* setup commit block. Don't write (keep it clean too) this one until after everyone else is written */
4018 c_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 4028 c_bh = journal_getblk(sb, SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
4019 ((journal->j_start + journal->j_len + 4029 ((journal->j_start + journal->j_len +
4020 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))); 4030 1) % SB_ONDISK_JOURNAL_SIZE(sb)));
4021 commit = (struct reiserfs_journal_commit *)c_bh->b_data; 4031 commit = (struct reiserfs_journal_commit *)c_bh->b_data;
4022 memset(c_bh->b_data, 0, c_bh->b_size); 4032 memset(c_bh->b_data, 0, c_bh->b_size);
4023 set_commit_trans_id(commit, journal->j_trans_id); 4033 set_commit_trans_id(commit, journal->j_trans_id);
@@ -4050,13 +4060,13 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4050 ** for each real block, add it to the journal list hash, 4060 ** for each real block, add it to the journal list hash,
4051 ** copy into real block index array in the commit or desc block 4061 ** copy into real block index array in the commit or desc block
4052 */ 4062 */
4053 trans_half = journal_trans_half(p_s_sb->s_blocksize); 4063 trans_half = journal_trans_half(sb->s_blocksize);
4054 for (i = 0, cn = journal->j_first; cn; cn = cn->next, i++) { 4064 for (i = 0, cn = journal->j_first; cn; cn = cn->next, i++) {
4055 if (buffer_journaled(cn->bh)) { 4065 if (buffer_journaled(cn->bh)) {
4056 jl_cn = get_cnode(p_s_sb); 4066 jl_cn = get_cnode(sb);
4057 if (!jl_cn) { 4067 if (!jl_cn) {
4058 reiserfs_panic(p_s_sb, 4068 reiserfs_panic(sb, "journal-1676",
4059 "journal-1676, get_cnode returned NULL\n"); 4069 "get_cnode returned NULL");
4060 } 4070 }
4061 if (i == 0) { 4071 if (i == 0) {
4062 jl->j_realblock = jl_cn; 4072 jl->j_realblock = jl_cn;
@@ -4067,18 +4077,19 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4067 last_cn->next = jl_cn; 4077 last_cn->next = jl_cn;
4068 } 4078 }
4069 last_cn = jl_cn; 4079 last_cn = jl_cn;
4070 /* make sure the block we are trying to log is not a block 4080 /* make sure the block we are trying to log is not a block
4071 of journal or reserved area */ 4081 of journal or reserved area */
4072 4082
4073 if (is_block_in_log_or_reserved_area 4083 if (is_block_in_log_or_reserved_area
4074 (p_s_sb, cn->bh->b_blocknr)) { 4084 (sb, cn->bh->b_blocknr)) {
4075 reiserfs_panic(p_s_sb, 4085 reiserfs_panic(sb, "journal-2332",
4076 "journal-2332: Trying to log block %lu, which is a log block\n", 4086 "Trying to log block %lu, "
4087 "which is a log block",
4077 cn->bh->b_blocknr); 4088 cn->bh->b_blocknr);
4078 } 4089 }
4079 jl_cn->blocknr = cn->bh->b_blocknr; 4090 jl_cn->blocknr = cn->bh->b_blocknr;
4080 jl_cn->state = 0; 4091 jl_cn->state = 0;
4081 jl_cn->sb = p_s_sb; 4092 jl_cn->sb = sb;
4082 jl_cn->bh = cn->bh; 4093 jl_cn->bh = cn->bh;
4083 jl_cn->jlist = jl; 4094 jl_cn->jlist = jl;
4084 insert_journal_hash(journal->j_list_hash_table, jl_cn); 4095 insert_journal_hash(journal->j_list_hash_table, jl_cn);
@@ -4119,11 +4130,11 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4119 char *addr; 4130 char *addr;
4120 struct page *page; 4131 struct page *page;
4121 tmp_bh = 4132 tmp_bh =
4122 journal_getblk(p_s_sb, 4133 journal_getblk(sb,
4123 SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + 4134 SB_ONDISK_JOURNAL_1st_BLOCK(sb) +
4124 ((cur_write_start + 4135 ((cur_write_start +
4125 jindex) % 4136 jindex) %
4126 SB_ONDISK_JOURNAL_SIZE(p_s_sb))); 4137 SB_ONDISK_JOURNAL_SIZE(sb)));
4127 set_buffer_uptodate(tmp_bh); 4138 set_buffer_uptodate(tmp_bh);
4128 page = cn->bh->b_page; 4139 page = cn->bh->b_page;
4129 addr = kmap(page); 4140 addr = kmap(page);
@@ -4137,12 +4148,13 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4137 clear_buffer_journaled(cn->bh); 4148 clear_buffer_journaled(cn->bh);
4138 } else { 4149 } else {
4139 /* JDirty cleared sometime during transaction. don't log this one */ 4150 /* JDirty cleared sometime during transaction. don't log this one */
4140 reiserfs_warning(p_s_sb, 4151 reiserfs_warning(sb, "journal-2048",
4141 "journal-2048: do_journal_end: BAD, buffer in journal hash, but not JDirty!"); 4152 "BAD, buffer in journal hash, "
4153 "but not JDirty!");
4142 brelse(cn->bh); 4154 brelse(cn->bh);
4143 } 4155 }
4144 next = cn->next; 4156 next = cn->next;
4145 free_cnode(p_s_sb, cn); 4157 free_cnode(sb, cn);
4146 cn = next; 4158 cn = next;
4147 cond_resched(); 4159 cond_resched();
4148 } 4160 }
@@ -4152,7 +4164,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4152 ** so we dirty/relse c_bh in flush_commit_list, with commit_left <= 1. 4164 ** so we dirty/relse c_bh in flush_commit_list, with commit_left <= 1.
4153 */ 4165 */
4154 4166
4155 journal->j_current_jl = alloc_journal_list(p_s_sb); 4167 journal->j_current_jl = alloc_journal_list(sb);
4156 4168
4157 /* now it is safe to insert this transaction on the main list */ 4169 /* now it is safe to insert this transaction on the main list */
4158 list_add_tail(&jl->j_list, &journal->j_journal_list); 4170 list_add_tail(&jl->j_list, &journal->j_journal_list);
@@ -4163,7 +4175,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4163 old_start = journal->j_start; 4175 old_start = journal->j_start;
4164 journal->j_start = 4176 journal->j_start =
4165 (journal->j_start + journal->j_len + 4177 (journal->j_start + journal->j_len +
4166 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb); 4178 2) % SB_ONDISK_JOURNAL_SIZE(sb);
4167 atomic_set(&(journal->j_wcount), 0); 4179 atomic_set(&(journal->j_wcount), 0);
4168 journal->j_bcount = 0; 4180 journal->j_bcount = 0;
4169 journal->j_last = NULL; 4181 journal->j_last = NULL;
@@ -4178,7 +4190,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4178 journal->j_len_alloc = 0; 4190 journal->j_len_alloc = 0;
4179 journal->j_next_full_flush = 0; 4191 journal->j_next_full_flush = 0;
4180 journal->j_next_async_flush = 0; 4192 journal->j_next_async_flush = 0;
4181 init_journal_hash(p_s_sb); 4193 init_journal_hash(sb);
4182 4194
4183 // make sure reiserfs_add_jh sees the new current_jl before we 4195 // make sure reiserfs_add_jh sees the new current_jl before we
4184 // write out the tails 4196 // write out the tails
@@ -4207,14 +4219,14 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4207 ** queue don't wait for this proc to flush journal lists and such. 4219 ** queue don't wait for this proc to flush journal lists and such.
4208 */ 4220 */
4209 if (flush) { 4221 if (flush) {
4210 flush_commit_list(p_s_sb, jl, 1); 4222 flush_commit_list(sb, jl, 1);
4211 flush_journal_list(p_s_sb, jl, 1); 4223 flush_journal_list(sb, jl, 1);
4212 } else if (!(jl->j_state & LIST_COMMIT_PENDING)) 4224 } else if (!(jl->j_state & LIST_COMMIT_PENDING))
4213 queue_delayed_work(commit_wq, &journal->j_work, HZ / 10); 4225 queue_delayed_work(commit_wq, &journal->j_work, HZ / 10);
4214 4226
4215 /* if the next transaction has any chance of wrapping, flush 4227 /* if the next transaction has any chance of wrapping, flush
4216 ** transactions that might get overwritten. If any journal lists are very 4228 ** transactions that might get overwritten. If any journal lists are very
4217 ** old flush them as well. 4229 ** old flush them as well.
4218 */ 4230 */
4219 first_jl: 4231 first_jl:
4220 list_for_each_safe(entry, safe, &journal->j_journal_list) { 4232 list_for_each_safe(entry, safe, &journal->j_journal_list) {
@@ -4222,11 +4234,11 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4222 if (journal->j_start <= temp_jl->j_start) { 4234 if (journal->j_start <= temp_jl->j_start) {
4223 if ((journal->j_start + journal->j_trans_max + 1) >= 4235 if ((journal->j_start + journal->j_trans_max + 1) >=
4224 temp_jl->j_start) { 4236 temp_jl->j_start) {
4225 flush_used_journal_lists(p_s_sb, temp_jl); 4237 flush_used_journal_lists(sb, temp_jl);
4226 goto first_jl; 4238 goto first_jl;
4227 } else if ((journal->j_start + 4239 } else if ((journal->j_start +
4228 journal->j_trans_max + 1) < 4240 journal->j_trans_max + 1) <
4229 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) { 4241 SB_ONDISK_JOURNAL_SIZE(sb)) {
4230 /* if we don't cross into the next transaction and we don't 4242 /* if we don't cross into the next transaction and we don't
4231 * wrap, there is no way we can overlap any later transactions 4243 * wrap, there is no way we can overlap any later transactions
4232 * break now 4244 * break now
@@ -4235,11 +4247,11 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4235 } 4247 }
4236 } else if ((journal->j_start + 4248 } else if ((journal->j_start +
4237 journal->j_trans_max + 1) > 4249 journal->j_trans_max + 1) >
4238 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) { 4250 SB_ONDISK_JOURNAL_SIZE(sb)) {
4239 if (((journal->j_start + journal->j_trans_max + 1) % 4251 if (((journal->j_start + journal->j_trans_max + 1) %
4240 SB_ONDISK_JOURNAL_SIZE(p_s_sb)) >= 4252 SB_ONDISK_JOURNAL_SIZE(sb)) >=
4241 temp_jl->j_start) { 4253 temp_jl->j_start) {
4242 flush_used_journal_lists(p_s_sb, temp_jl); 4254 flush_used_journal_lists(sb, temp_jl);
4243 goto first_jl; 4255 goto first_jl;
4244 } else { 4256 } else {
4245 /* we don't overlap anything from out start to the end of the 4257 /* we don't overlap anything from out start to the end of the
@@ -4250,46 +4262,47 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4250 } 4262 }
4251 } 4263 }
4252 } 4264 }
4253 flush_old_journal_lists(p_s_sb); 4265 flush_old_journal_lists(sb);
4254 4266
4255 journal->j_current_jl->j_list_bitmap = 4267 journal->j_current_jl->j_list_bitmap =
4256 get_list_bitmap(p_s_sb, journal->j_current_jl); 4268 get_list_bitmap(sb, journal->j_current_jl);
4257 4269
4258 if (!(journal->j_current_jl->j_list_bitmap)) { 4270 if (!(journal->j_current_jl->j_list_bitmap)) {
4259 reiserfs_panic(p_s_sb, 4271 reiserfs_panic(sb, "journal-1996",
4260 "journal-1996: do_journal_end, could not get a list bitmap\n"); 4272 "could not get a list bitmap");
4261 } 4273 }
4262 4274
4263 atomic_set(&(journal->j_jlock), 0); 4275 atomic_set(&(journal->j_jlock), 0);
4264 unlock_journal(p_s_sb); 4276 unlock_journal(sb);
4265 /* wake up any body waiting to join. */ 4277 /* wake up any body waiting to join. */
4266 clear_bit(J_WRITERS_QUEUED, &journal->j_state); 4278 clear_bit(J_WRITERS_QUEUED, &journal->j_state);
4267 wake_up(&(journal->j_join_wait)); 4279 wake_up(&(journal->j_join_wait));
4268 4280
4269 if (!flush && wait_on_commit && 4281 if (!flush && wait_on_commit &&
4270 journal_list_still_alive(p_s_sb, commit_trans_id)) { 4282 journal_list_still_alive(sb, commit_trans_id)) {
4271 flush_commit_list(p_s_sb, jl, 1); 4283 flush_commit_list(sb, jl, 1);
4272 } 4284 }
4273 out: 4285 out:
4274 reiserfs_check_lock_depth(p_s_sb, "journal end2"); 4286 reiserfs_check_lock_depth(sb, "journal end2");
4275 4287
4276 memset(th, 0, sizeof(*th)); 4288 memset(th, 0, sizeof(*th));
4277 /* Re-set th->t_super, so we can properly keep track of how many 4289 /* Re-set th->t_super, so we can properly keep track of how many
4278 * persistent transactions there are. We need to do this so if this 4290 * persistent transactions there are. We need to do this so if this
4279 * call is part of a failed restart_transaction, we can free it later */ 4291 * call is part of a failed restart_transaction, we can free it later */
4280 th->t_super = p_s_sb; 4292 th->t_super = sb;
4281 4293
4282 return journal->j_errno; 4294 return journal->j_errno;
4283} 4295}
4284 4296
4285static void __reiserfs_journal_abort_hard(struct super_block *sb) 4297/* Send the file system read only and refuse new transactions */
4298void reiserfs_abort_journal(struct super_block *sb, int errno)
4286{ 4299{
4287 struct reiserfs_journal *journal = SB_JOURNAL(sb); 4300 struct reiserfs_journal *journal = SB_JOURNAL(sb);
4288 if (test_bit(J_ABORTED, &journal->j_state)) 4301 if (test_bit(J_ABORTED, &journal->j_state))
4289 return; 4302 return;
4290 4303
4291 printk(KERN_CRIT "REISERFS: Aborting journal for filesystem on %s\n", 4304 if (!journal->j_errno)
4292 reiserfs_bdevname(sb)); 4305 journal->j_errno = errno;
4293 4306
4294 sb->s_flags |= MS_RDONLY; 4307 sb->s_flags |= MS_RDONLY;
4295 set_bit(J_ABORTED, &journal->j_state); 4308 set_bit(J_ABORTED, &journal->j_state);
@@ -4299,19 +4312,3 @@ static void __reiserfs_journal_abort_hard(struct super_block *sb)
4299#endif 4312#endif
4300} 4313}
4301 4314
4302static void __reiserfs_journal_abort_soft(struct super_block *sb, int errno)
4303{
4304 struct reiserfs_journal *journal = SB_JOURNAL(sb);
4305 if (test_bit(J_ABORTED, &journal->j_state))
4306 return;
4307
4308 if (!journal->j_errno)
4309 journal->j_errno = errno;
4310
4311 __reiserfs_journal_abort_hard(sb);
4312}
4313
4314void reiserfs_journal_abort(struct super_block *sb, int errno)
4315{
4316 __reiserfs_journal_abort_soft(sb, errno);
4317}
diff --git a/fs/reiserfs/lbalance.c b/fs/reiserfs/lbalance.c
index 6de060a6aa7..381750a155f 100644
--- a/fs/reiserfs/lbalance.c
+++ b/fs/reiserfs/lbalance.c
@@ -111,7 +111,7 @@ static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
111 item_num_in_dest = 111 item_num_in_dest =
112 (last_first == FIRST_TO_LAST) ? (B_NR_ITEMS(dest) - 1) : 0; 112 (last_first == FIRST_TO_LAST) ? (B_NR_ITEMS(dest) - 1) : 0;
113 113
114 leaf_paste_entries(dest_bi->bi_bh, item_num_in_dest, 114 leaf_paste_entries(dest_bi, item_num_in_dest,
115 (last_first == 115 (last_first ==
116 FIRST_TO_LAST) ? I_ENTRY_COUNT(B_N_PITEM_HEAD(dest, 116 FIRST_TO_LAST) ? I_ENTRY_COUNT(B_N_PITEM_HEAD(dest,
117 item_num_in_dest)) 117 item_num_in_dest))
@@ -119,8 +119,8 @@ static void leaf_copy_dir_entries(struct buffer_info *dest_bi,
119 DEH_SIZE * copy_count + copy_records_len); 119 DEH_SIZE * copy_count + copy_records_len);
120} 120}
121 121
122/* Copy the first (if last_first == FIRST_TO_LAST) or last (last_first == LAST_TO_FIRST) item or 122/* Copy the first (if last_first == FIRST_TO_LAST) or last (last_first == LAST_TO_FIRST) item or
123 part of it or nothing (see the return 0 below) from SOURCE to the end 123 part of it or nothing (see the return 0 below) from SOURCE to the end
124 (if last_first) or beginning (!last_first) of the DEST */ 124 (if last_first) or beginning (!last_first) of the DEST */
125/* returns 1 if anything was copied, else 0 */ 125/* returns 1 if anything was copied, else 0 */
126static int leaf_copy_boundary_item(struct buffer_info *dest_bi, 126static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
@@ -168,10 +168,11 @@ static int leaf_copy_boundary_item(struct buffer_info *dest_bi,
168 if (bytes_or_entries == ih_item_len(ih) 168 if (bytes_or_entries == ih_item_len(ih)
169 && is_indirect_le_ih(ih)) 169 && is_indirect_le_ih(ih))
170 if (get_ih_free_space(ih)) 170 if (get_ih_free_space(ih))
171 reiserfs_panic(NULL, 171 reiserfs_panic(sb_from_bi(dest_bi),
172 "vs-10020: leaf_copy_boundary_item: " 172 "vs-10020",
173 "last unformatted node must be filled entirely (%h)", 173 "last unformatted node "
174 ih); 174 "must be filled "
175 "entirely (%h)", ih);
175 } 176 }
176#endif 177#endif
177 178
@@ -395,7 +396,7 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
395 else { 396 else {
396 struct item_head n_ih; 397 struct item_head n_ih;
397 398
398 /* copy part of the body of the item number 'item_num' of SOURCE to the end of the DEST 399 /* copy part of the body of the item number 'item_num' of SOURCE to the end of the DEST
399 part defined by 'cpy_bytes'; create new item header; change old item_header (????); 400 part defined by 'cpy_bytes'; create new item header; change old item_header (????);
400 n_ih = new item_header; 401 n_ih = new item_header;
401 */ 402 */
@@ -425,7 +426,7 @@ static void leaf_item_bottle(struct buffer_info *dest_bi,
425 else { 426 else {
426 struct item_head n_ih; 427 struct item_head n_ih;
427 428
428 /* copy part of the body of the item number 'item_num' of SOURCE to the begin of the DEST 429 /* copy part of the body of the item number 'item_num' of SOURCE to the begin of the DEST
429 part defined by 'cpy_bytes'; create new item header; 430 part defined by 'cpy_bytes'; create new item header;
430 n_ih = new item_header; 431 n_ih = new item_header;
431 */ 432 */
@@ -622,9 +623,8 @@ static void leaf_define_dest_src_infos(int shift_mode, struct tree_balance *tb,
622 break; 623 break;
623 624
624 default: 625 default:
625 reiserfs_panic(NULL, 626 reiserfs_panic(sb_from_bi(src_bi), "vs-10250",
626 "vs-10250: leaf_define_dest_src_infos: shift type is unknown (%d)", 627 "shift type is unknown (%d)", shift_mode);
627 shift_mode);
628 } 628 }
629 RFALSE(!src_bi->bi_bh || !dest_bi->bi_bh, 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",
@@ -674,9 +674,9 @@ int leaf_shift_left(struct tree_balance *tb, int shift_num, int shift_bytes)
674#ifdef CONFIG_REISERFS_CHECK 674#ifdef CONFIG_REISERFS_CHECK
675 if (tb->tb_mode == M_PASTE || tb->tb_mode == M_INSERT) { 675 if (tb->tb_mode == M_PASTE || tb->tb_mode == M_INSERT) {
676 print_cur_tb("vs-10275"); 676 print_cur_tb("vs-10275");
677 reiserfs_panic(tb->tb_sb, 677 reiserfs_panic(tb->tb_sb, "vs-10275",
678 "vs-10275: leaf_shift_left: balance condition corrupted (%c)", 678 "balance condition corrupted "
679 tb->tb_mode); 679 "(%c)", tb->tb_mode);
680 } 680 }
681#endif 681#endif
682 682
@@ -724,7 +724,7 @@ int leaf_shift_right(struct tree_balance *tb, int shift_num, int shift_bytes)
724static void leaf_delete_items_entirely(struct buffer_info *bi, 724static void leaf_delete_items_entirely(struct buffer_info *bi,
725 int first, int del_num); 725 int first, int del_num);
726/* If del_bytes == -1, starting from position 'first' delete del_num items in whole in buffer CUR. 726/* If del_bytes == -1, starting from position 'first' delete del_num items in whole in buffer CUR.
727 If not. 727 If not.
728 If last_first == 0. Starting from position 'first' delete del_num-1 items in whole. Delete part of body of 728 If last_first == 0. Starting from position 'first' delete del_num-1 items in whole. Delete part of body of
729 the first item. Part defined by del_bytes. Don't delete first item header 729 the first item. Part defined by del_bytes. Don't delete first item header
730 If last_first == 1. Starting from position 'first+1' delete del_num-1 items in whole. Delete part of body of 730 If last_first == 1. Starting from position 'first+1' delete del_num-1 items in whole. Delete part of body of
@@ -783,7 +783,7 @@ void leaf_delete_items(struct buffer_info *cur_bi, int last_first,
783 /* len = body len of item */ 783 /* len = body len of item */
784 len = ih_item_len(ih); 784 len = ih_item_len(ih);
785 785
786 /* delete the part of the last item of the bh 786 /* delete the part of the last item of the bh
787 do not delete item header 787 do not delete item header
788 */ 788 */
789 leaf_cut_from_buffer(cur_bi, B_NR_ITEMS(bh) - 1, 789 leaf_cut_from_buffer(cur_bi, B_NR_ITEMS(bh) - 1,
@@ -865,7 +865,7 @@ void leaf_insert_into_buf(struct buffer_info *bi, int before,
865 } 865 }
866} 866}
867 867
868/* paste paste_size bytes to affected_item_num-th item. 868/* paste paste_size bytes to affected_item_num-th item.
869 When item is a directory, this only prepare space for new entries */ 869 When item is a directory, this only prepare space for new entries */
870void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num, 870void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num,
871 int pos_in_item, int paste_size, 871 int pos_in_item, int paste_size,
@@ -889,9 +889,12 @@ void leaf_paste_in_buffer(struct buffer_info *bi, int affected_item_num,
889 889
890#ifdef CONFIG_REISERFS_CHECK 890#ifdef CONFIG_REISERFS_CHECK
891 if (zeros_number > paste_size) { 891 if (zeros_number > paste_size) {
892 struct super_block *sb = NULL;
893 if (bi && bi->tb)
894 sb = bi->tb->tb_sb;
892 print_cur_tb("10177"); 895 print_cur_tb("10177");
893 reiserfs_panic(NULL, 896 reiserfs_panic(sb, "vs-10177",
894 "vs-10177: leaf_paste_in_buffer: ero number == %d, paste_size == %d", 897 "zeros_number == %d, paste_size == %d",
895 zeros_number, paste_size); 898 zeros_number, paste_size);
896 } 899 }
897#endif /* CONFIG_REISERFS_CHECK */ 900#endif /* CONFIG_REISERFS_CHECK */
@@ -1019,7 +1022,7 @@ static int leaf_cut_entries(struct buffer_head *bh,
1019/* when cut item is part of regular file 1022/* when cut item is part of regular file
1020 pos_in_item - first byte that must be cut 1023 pos_in_item - first byte that must be cut
1021 cut_size - number of bytes to be cut beginning from pos_in_item 1024 cut_size - number of bytes to be cut beginning from pos_in_item
1022 1025
1023 when cut item is part of directory 1026 when cut item is part of directory
1024 pos_in_item - number of first deleted entry 1027 pos_in_item - number of first deleted entry
1025 cut_size - count of deleted entries 1028 cut_size - count of deleted entries
@@ -1191,7 +1194,7 @@ static void leaf_delete_items_entirely(struct buffer_info *bi,
1191} 1194}
1192 1195
1193/* paste new_entry_count entries (new_dehs, records) into position before to item_num-th item */ 1196/* paste new_entry_count entries (new_dehs, records) into position before to item_num-th item */
1194void leaf_paste_entries(struct buffer_head *bh, 1197void leaf_paste_entries(struct buffer_info *bi,
1195 int item_num, 1198 int item_num,
1196 int before, 1199 int before,
1197 int new_entry_count, 1200 int new_entry_count,
@@ -1203,6 +1206,7 @@ void leaf_paste_entries(struct buffer_head *bh,
1203 struct reiserfs_de_head *deh; 1206 struct reiserfs_de_head *deh;
1204 char *insert_point; 1207 char *insert_point;
1205 int i, old_entry_num; 1208 int i, old_entry_num;
1209 struct buffer_head *bh = bi->bi_bh;
1206 1210
1207 if (new_entry_count == 0) 1211 if (new_entry_count == 0)
1208 return; 1212 return;
@@ -1271,7 +1275,7 @@ void leaf_paste_entries(struct buffer_head *bh,
1271 /* change item key if necessary (when we paste before 0-th entry */ 1275 /* change item key if necessary (when we paste before 0-th entry */
1272 if (!before) { 1276 if (!before) {
1273 set_le_ih_k_offset(ih, deh_offset(new_dehs)); 1277 set_le_ih_k_offset(ih, deh_offset(new_dehs));
1274/* memcpy (&ih->ih_key.k_offset, 1278/* memcpy (&ih->ih_key.k_offset,
1275 &new_dehs->deh_offset, SHORT_KEY_SIZE);*/ 1279 &new_dehs->deh_offset, SHORT_KEY_SIZE);*/
1276 } 1280 }
1277#ifdef CONFIG_REISERFS_CHECK 1281#ifdef CONFIG_REISERFS_CHECK
@@ -1287,13 +1291,17 @@ void leaf_paste_entries(struct buffer_head *bh,
1287 prev = (i != 0) ? deh_location(&(deh[i - 1])) : 0; 1291 prev = (i != 0) ? deh_location(&(deh[i - 1])) : 0;
1288 1292
1289 if (prev && prev <= deh_location(&(deh[i]))) 1293 if (prev && prev <= deh_location(&(deh[i])))
1290 reiserfs_warning(NULL, 1294 reiserfs_error(sb_from_bi(bi), "vs-10240",
1291 "vs-10240: leaf_paste_entries: directory item (%h) corrupted (prev %a, cur(%d) %a)", 1295 "directory item (%h) "
1292 ih, deh + i - 1, i, deh + i); 1296 "corrupted (prev %a, "
1297 "cur(%d) %a)",
1298 ih, deh + i - 1, i, deh + i);
1293 if (next && next >= deh_location(&(deh[i]))) 1299 if (next && next >= deh_location(&(deh[i])))
1294 reiserfs_warning(NULL, 1300 reiserfs_error(sb_from_bi(bi), "vs-10250",
1295 "vs-10250: leaf_paste_entries: directory item (%h) corrupted (cur(%d) %a, next %a)", 1301 "directory item (%h) "
1296 ih, i, deh + i, deh + i + 1); 1302 "corrupted (cur(%d) %a, "
1303 "next %a)",
1304 ih, i, deh + i, deh + i + 1);
1297 } 1305 }
1298 } 1306 }
1299#endif 1307#endif
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index 738967f6c8e..efd4d720718 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -106,7 +106,7 @@ key of the first directory entry in it.
106This function first calls search_by_key, then, if item whose first 106This function first calls search_by_key, then, if item whose first
107entry matches is not found it looks for the entry inside directory 107entry matches is not found it looks for the entry inside directory
108item found by search_by_key. Fills the path to the entry, and to the 108item found by search_by_key. Fills the path to the entry, and to the
109entry position in the item 109entry position in the item
110 110
111*/ 111*/
112 112
@@ -120,8 +120,8 @@ int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
120 switch (retval) { 120 switch (retval) {
121 case ITEM_NOT_FOUND: 121 case ITEM_NOT_FOUND:
122 if (!PATH_LAST_POSITION(path)) { 122 if (!PATH_LAST_POSITION(path)) {
123 reiserfs_warning(sb, 123 reiserfs_error(sb, "vs-7000", "search_by_key "
124 "vs-7000: search_by_entry_key: search_by_key returned item position == 0"); 124 "returned item position == 0");
125 pathrelse(path); 125 pathrelse(path);
126 return IO_ERROR; 126 return IO_ERROR;
127 } 127 }
@@ -135,8 +135,7 @@ int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
135 135
136 default: 136 default:
137 pathrelse(path); 137 pathrelse(path);
138 reiserfs_warning(sb, 138 reiserfs_error(sb, "vs-7002", "no path to here");
139 "vs-7002: search_by_entry_key: no path to here");
140 return IO_ERROR; 139 return IO_ERROR;
141 } 140 }
142 141
@@ -146,10 +145,9 @@ int search_by_entry_key(struct super_block *sb, const struct cpu_key *key,
146 if (!is_direntry_le_ih(de->de_ih) || 145 if (!is_direntry_le_ih(de->de_ih) ||
147 COMP_SHORT_KEYS(&(de->de_ih->ih_key), key)) { 146 COMP_SHORT_KEYS(&(de->de_ih->ih_key), key)) {
148 print_block(de->de_bh, 0, -1, -1); 147 print_block(de->de_bh, 0, -1, -1);
149 reiserfs_panic(sb, 148 reiserfs_panic(sb, "vs-7005", "found item %h is not directory "
150 "vs-7005: search_by_entry_key: found item %h is not directory item or " 149 "item or does not belong to the same directory "
151 "does not belong to the same directory as key %K", 150 "as key %K", de->de_ih, key);
152 de->de_ih, key);
153 } 151 }
154#endif /* CONFIG_REISERFS_CHECK */ 152#endif /* CONFIG_REISERFS_CHECK */
155 153
@@ -300,8 +298,7 @@ static int reiserfs_find_entry(struct inode *dir, const char *name, int namelen,
300 search_by_entry_key(dir->i_sb, &key_to_search, 298 search_by_entry_key(dir->i_sb, &key_to_search,
301 path_to_entry, de); 299 path_to_entry, de);
302 if (retval == IO_ERROR) { 300 if (retval == IO_ERROR) {
303 reiserfs_warning(dir->i_sb, "zam-7001: io error in %s", 301 reiserfs_error(dir->i_sb, "zam-7001", "io error");
304 __func__);
305 return IO_ERROR; 302 return IO_ERROR;
306 } 303 }
307 304
@@ -361,9 +358,10 @@ static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
361 return ERR_PTR(-EACCES); 358 return ERR_PTR(-EACCES);
362 } 359 }
363 360
364 /* Propogate the priv_object flag so we know we're in the priv tree */ 361 /* Propagate the private flag so we know we're
365 if (is_reiserfs_priv_object(dir)) 362 * in the priv tree */
366 reiserfs_mark_inode_private(inode); 363 if (IS_PRIVATE(dir))
364 inode->i_flags |= S_PRIVATE;
367 } 365 }
368 reiserfs_write_unlock(dir->i_sb); 366 reiserfs_write_unlock(dir->i_sb);
369 if (retval == IO_ERROR) { 367 if (retval == IO_ERROR) {
@@ -373,7 +371,7 @@ static struct dentry *reiserfs_lookup(struct inode *dir, struct dentry *dentry,
373 return d_splice_alias(inode, dentry); 371 return d_splice_alias(inode, dentry);
374} 372}
375 373
376/* 374/*
377** looks up the dentry of the parent directory for child. 375** looks up the dentry of the parent directory for child.
378** taken from ext2_get_parent 376** taken from ext2_get_parent
379*/ 377*/
@@ -403,7 +401,7 @@ struct dentry *reiserfs_get_parent(struct dentry *child)
403 return d_obtain_alias(inode); 401 return d_obtain_alias(inode);
404} 402}
405 403
406/* add entry to the directory (entry can be hidden). 404/* add entry to the directory (entry can be hidden).
407 405
408insert definition of when hidden directories are used here -Hans 406insert definition of when hidden directories are used here -Hans
409 407
@@ -484,10 +482,9 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
484 } 482 }
485 483
486 if (retval != NAME_FOUND) { 484 if (retval != NAME_FOUND) {
487 reiserfs_warning(dir->i_sb, 485 reiserfs_error(dir->i_sb, "zam-7002",
488 "zam-7002:%s: \"reiserfs_find_entry\" " 486 "reiserfs_find_entry() returned "
489 "has returned unexpected value (%d)", 487 "unexpected value (%d)", retval);
490 __func__, retval);
491 } 488 }
492 489
493 return -EEXIST; 490 return -EEXIST;
@@ -498,8 +495,9 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
498 MAX_GENERATION_NUMBER + 1); 495 MAX_GENERATION_NUMBER + 1);
499 if (gen_number > MAX_GENERATION_NUMBER) { 496 if (gen_number > MAX_GENERATION_NUMBER) {
500 /* there is no free generation number */ 497 /* there is no free generation number */
501 reiserfs_warning(dir->i_sb, 498 reiserfs_warning(dir->i_sb, "reiserfs-7010",
502 "reiserfs_add_entry: Congratulations! we have got hash function screwed up"); 499 "Congratulations! we have got hash function "
500 "screwed up");
503 if (buffer != small_buf) 501 if (buffer != small_buf)
504 kfree(buffer); 502 kfree(buffer);
505 pathrelse(&path); 503 pathrelse(&path);
@@ -515,10 +513,9 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
515 if (gen_number != 0) { /* we need to re-search for the insertion point */ 513 if (gen_number != 0) { /* we need to re-search for the insertion point */
516 if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) != 514 if (search_by_entry_key(dir->i_sb, &entry_key, &path, &de) !=
517 NAME_NOT_FOUND) { 515 NAME_NOT_FOUND) {
518 reiserfs_warning(dir->i_sb, 516 reiserfs_warning(dir->i_sb, "vs-7032",
519 "vs-7032: reiserfs_add_entry: " 517 "entry with this key (%K) already "
520 "entry with this key (%K) already exists", 518 "exists", &entry_key);
521 &entry_key);
522 519
523 if (buffer != small_buf) 520 if (buffer != small_buf)
524 kfree(buffer); 521 kfree(buffer);
@@ -555,15 +552,15 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th,
555*/ 552*/
556static int drop_new_inode(struct inode *inode) 553static int drop_new_inode(struct inode *inode)
557{ 554{
558 DQUOT_DROP(inode); 555 vfs_dq_drop(inode);
559 make_bad_inode(inode); 556 make_bad_inode(inode);
560 inode->i_flags |= S_NOQUOTA; 557 inode->i_flags |= S_NOQUOTA;
561 iput(inode); 558 iput(inode);
562 return 0; 559 return 0;
563} 560}
564 561
565/* utility function that does setup for reiserfs_new_inode. 562/* utility function that does setup for reiserfs_new_inode.
566** DQUOT_INIT needs lots of credits so it's better to have it 563** vfs_dq_init needs lots of credits so it's better to have it
567** outside of a transaction, so we had to pull some bits of 564** outside of a transaction, so we had to pull some bits of
568** reiserfs_new_inode out into this func. 565** reiserfs_new_inode out into this func.
569*/ 566*/
@@ -586,7 +583,7 @@ static int new_inode_init(struct inode *inode, struct inode *dir, int mode)
586 } else { 583 } else {
587 inode->i_gid = current_fsgid(); 584 inode->i_gid = current_fsgid();
588 } 585 }
589 DQUOT_INIT(inode); 586 vfs_dq_init(inode);
590 return 0; 587 return 0;
591} 588}
592 589
@@ -601,20 +598,22 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
601 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + 598 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
602 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); 599 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
603 struct reiserfs_transaction_handle th; 600 struct reiserfs_transaction_handle th;
604 int locked; 601 struct reiserfs_security_handle security;
605 602
606 if (!(inode = new_inode(dir->i_sb))) { 603 if (!(inode = new_inode(dir->i_sb))) {
607 return -ENOMEM; 604 return -ENOMEM;
608 } 605 }
609 new_inode_init(inode, dir, mode); 606 new_inode_init(inode, dir, mode);
610 607
611 locked = reiserfs_cache_default_acl(dir); 608 jbegin_count += reiserfs_cache_default_acl(dir);
612 609 retval = reiserfs_security_init(dir, inode, &security);
610 if (retval < 0) {
611 drop_new_inode(inode);
612 return retval;
613 }
614 jbegin_count += retval;
613 reiserfs_write_lock(dir->i_sb); 615 reiserfs_write_lock(dir->i_sb);
614 616
615 if (locked)
616 reiserfs_write_lock_xattrs(dir->i_sb);
617
618 retval = journal_begin(&th, dir->i_sb, jbegin_count); 617 retval = journal_begin(&th, dir->i_sb, jbegin_count);
619 if (retval) { 618 if (retval) {
620 drop_new_inode(inode); 619 drop_new_inode(inode);
@@ -623,15 +622,10 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
623 622
624 retval = 623 retval =
625 reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry, 624 reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
626 inode); 625 inode, &security);
627 if (retval) 626 if (retval)
628 goto out_failed; 627 goto out_failed;
629 628
630 if (locked) {
631 reiserfs_write_unlock_xattrs(dir->i_sb);
632 locked = 0;
633 }
634
635 inode->i_op = &reiserfs_file_inode_operations; 629 inode->i_op = &reiserfs_file_inode_operations;
636 inode->i_fop = &reiserfs_file_operations; 630 inode->i_fop = &reiserfs_file_operations;
637 inode->i_mapping->a_ops = &reiserfs_address_space_operations; 631 inode->i_mapping->a_ops = &reiserfs_address_space_operations;
@@ -658,8 +652,6 @@ static int reiserfs_create(struct inode *dir, struct dentry *dentry, int mode,
658 retval = journal_end(&th, dir->i_sb, jbegin_count); 652 retval = journal_end(&th, dir->i_sb, jbegin_count);
659 653
660 out_failed: 654 out_failed:
661 if (locked)
662 reiserfs_write_unlock_xattrs(dir->i_sb);
663 reiserfs_write_unlock(dir->i_sb); 655 reiserfs_write_unlock(dir->i_sb);
664 return retval; 656 return retval;
665} 657}
@@ -670,12 +662,12 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
670 int retval; 662 int retval;
671 struct inode *inode; 663 struct inode *inode;
672 struct reiserfs_transaction_handle th; 664 struct reiserfs_transaction_handle th;
665 struct reiserfs_security_handle security;
673 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ 666 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
674 int jbegin_count = 667 int jbegin_count =
675 JOURNAL_PER_BALANCE_CNT * 3 + 668 JOURNAL_PER_BALANCE_CNT * 3 +
676 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + 669 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
677 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); 670 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
678 int locked;
679 671
680 if (!new_valid_dev(rdev)) 672 if (!new_valid_dev(rdev))
681 return -EINVAL; 673 return -EINVAL;
@@ -685,13 +677,15 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
685 } 677 }
686 new_inode_init(inode, dir, mode); 678 new_inode_init(inode, dir, mode);
687 679
688 locked = reiserfs_cache_default_acl(dir); 680 jbegin_count += reiserfs_cache_default_acl(dir);
689 681 retval = reiserfs_security_init(dir, inode, &security);
682 if (retval < 0) {
683 drop_new_inode(inode);
684 return retval;
685 }
686 jbegin_count += retval;
690 reiserfs_write_lock(dir->i_sb); 687 reiserfs_write_lock(dir->i_sb);
691 688
692 if (locked)
693 reiserfs_write_lock_xattrs(dir->i_sb);
694
695 retval = journal_begin(&th, dir->i_sb, jbegin_count); 689 retval = journal_begin(&th, dir->i_sb, jbegin_count);
696 if (retval) { 690 if (retval) {
697 drop_new_inode(inode); 691 drop_new_inode(inode);
@@ -700,16 +694,11 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
700 694
701 retval = 695 retval =
702 reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry, 696 reiserfs_new_inode(&th, dir, mode, NULL, 0 /*i_size */ , dentry,
703 inode); 697 inode, &security);
704 if (retval) { 698 if (retval) {
705 goto out_failed; 699 goto out_failed;
706 } 700 }
707 701
708 if (locked) {
709 reiserfs_write_unlock_xattrs(dir->i_sb);
710 locked = 0;
711 }
712
713 inode->i_op = &reiserfs_special_inode_operations; 702 inode->i_op = &reiserfs_special_inode_operations;
714 init_special_inode(inode, inode->i_mode, rdev); 703 init_special_inode(inode, inode->i_mode, rdev);
715 704
@@ -739,8 +728,6 @@ static int reiserfs_mknod(struct inode *dir, struct dentry *dentry, int mode,
739 retval = journal_end(&th, dir->i_sb, jbegin_count); 728 retval = journal_end(&th, dir->i_sb, jbegin_count);
740 729
741 out_failed: 730 out_failed:
742 if (locked)
743 reiserfs_write_unlock_xattrs(dir->i_sb);
744 reiserfs_write_unlock(dir->i_sb); 731 reiserfs_write_unlock(dir->i_sb);
745 return retval; 732 return retval;
746} 733}
@@ -750,12 +737,12 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
750 int retval; 737 int retval;
751 struct inode *inode; 738 struct inode *inode;
752 struct reiserfs_transaction_handle th; 739 struct reiserfs_transaction_handle th;
740 struct reiserfs_security_handle security;
753 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ 741 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
754 int jbegin_count = 742 int jbegin_count =
755 JOURNAL_PER_BALANCE_CNT * 3 + 743 JOURNAL_PER_BALANCE_CNT * 3 +
756 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) + 744 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir->i_sb) +
757 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb)); 745 REISERFS_QUOTA_TRANS_BLOCKS(dir->i_sb));
758 int locked;
759 746
760#ifdef DISPLACE_NEW_PACKING_LOCALITIES 747#ifdef DISPLACE_NEW_PACKING_LOCALITIES
761 /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */ 748 /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */
@@ -767,11 +754,14 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
767 } 754 }
768 new_inode_init(inode, dir, mode); 755 new_inode_init(inode, dir, mode);
769 756
770 locked = reiserfs_cache_default_acl(dir); 757 jbegin_count += reiserfs_cache_default_acl(dir);
771 758 retval = reiserfs_security_init(dir, inode, &security);
759 if (retval < 0) {
760 drop_new_inode(inode);
761 return retval;
762 }
763 jbegin_count += retval;
772 reiserfs_write_lock(dir->i_sb); 764 reiserfs_write_lock(dir->i_sb);
773 if (locked)
774 reiserfs_write_lock_xattrs(dir->i_sb);
775 765
776 retval = journal_begin(&th, dir->i_sb, jbegin_count); 766 retval = journal_begin(&th, dir->i_sb, jbegin_count);
777 if (retval) { 767 if (retval) {
@@ -787,17 +777,12 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
787 retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ , 777 retval = reiserfs_new_inode(&th, dir, mode, NULL /*symlink */ ,
788 old_format_only(dir->i_sb) ? 778 old_format_only(dir->i_sb) ?
789 EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE, 779 EMPTY_DIR_SIZE_V1 : EMPTY_DIR_SIZE,
790 dentry, inode); 780 dentry, inode, &security);
791 if (retval) { 781 if (retval) {
792 dir->i_nlink--; 782 dir->i_nlink--;
793 goto out_failed; 783 goto out_failed;
794 } 784 }
795 785
796 if (locked) {
797 reiserfs_write_unlock_xattrs(dir->i_sb);
798 locked = 0;
799 }
800
801 reiserfs_update_inode_transaction(inode); 786 reiserfs_update_inode_transaction(inode);
802 reiserfs_update_inode_transaction(dir); 787 reiserfs_update_inode_transaction(dir);
803 788
@@ -827,8 +812,6 @@ static int reiserfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
827 unlock_new_inode(inode); 812 unlock_new_inode(inode);
828 retval = journal_end(&th, dir->i_sb, jbegin_count); 813 retval = journal_end(&th, dir->i_sb, jbegin_count);
829 out_failed: 814 out_failed:
830 if (locked)
831 reiserfs_write_unlock_xattrs(dir->i_sb);
832 reiserfs_write_unlock(dir->i_sb); 815 reiserfs_write_unlock(dir->i_sb);
833 return retval; 816 return retval;
834} 817}
@@ -837,7 +820,7 @@ static inline int reiserfs_empty_dir(struct inode *inode)
837{ 820{
838 /* we can cheat because an old format dir cannot have 821 /* we can cheat because an old format dir cannot have
839 ** EMPTY_DIR_SIZE, and a new format dir cannot have 822 ** EMPTY_DIR_SIZE, and a new format dir cannot have
840 ** EMPTY_DIR_SIZE_V1. So, if the inode is either size, 823 ** EMPTY_DIR_SIZE_V1. So, if the inode is either size,
841 ** regardless of disk format version, the directory is empty. 824 ** regardless of disk format version, the directory is empty.
842 */ 825 */
843 if (inode->i_size != EMPTY_DIR_SIZE && 826 if (inode->i_size != EMPTY_DIR_SIZE &&
@@ -903,8 +886,9 @@ static int reiserfs_rmdir(struct inode *dir, struct dentry *dentry)
903 goto end_rmdir; 886 goto end_rmdir;
904 887
905 if (inode->i_nlink != 2 && inode->i_nlink != 1) 888 if (inode->i_nlink != 2 && inode->i_nlink != 1)
906 reiserfs_warning(inode->i_sb, "%s: empty directory has nlink " 889 reiserfs_error(inode->i_sb, "reiserfs-7040",
907 "!= 2 (%d)", __func__, inode->i_nlink); 890 "empty directory has nlink != 2 (%d)",
891 inode->i_nlink);
908 892
909 clear_nlink(inode); 893 clear_nlink(inode);
910 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC; 894 inode->i_ctime = dir->i_ctime = dir->i_mtime = CURRENT_TIME_SEC;
@@ -980,10 +964,9 @@ static int reiserfs_unlink(struct inode *dir, struct dentry *dentry)
980 } 964 }
981 965
982 if (!inode->i_nlink) { 966 if (!inode->i_nlink) {
983 reiserfs_warning(inode->i_sb, "%s: deleting nonexistent file " 967 reiserfs_warning(inode->i_sb, "reiserfs-7042",
984 "(%s:%lu), %d", __func__, 968 "deleting nonexistent file (%lu), %d",
985 reiserfs_bdevname(inode->i_sb), inode->i_ino, 969 inode->i_ino, inode->i_nlink);
986 inode->i_nlink);
987 inode->i_nlink = 1; 970 inode->i_nlink = 1;
988 } 971 }
989 972
@@ -1037,6 +1020,7 @@ static int reiserfs_symlink(struct inode *parent_dir,
1037 char *name; 1020 char *name;
1038 int item_len; 1021 int item_len;
1039 struct reiserfs_transaction_handle th; 1022 struct reiserfs_transaction_handle th;
1023 struct reiserfs_security_handle security;
1040 int mode = S_IFLNK | S_IRWXUGO; 1024 int mode = S_IFLNK | S_IRWXUGO;
1041 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */ 1025 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
1042 int jbegin_count = 1026 int jbegin_count =
@@ -1049,6 +1033,13 @@ static int reiserfs_symlink(struct inode *parent_dir,
1049 } 1033 }
1050 new_inode_init(inode, parent_dir, mode); 1034 new_inode_init(inode, parent_dir, mode);
1051 1035
1036 retval = reiserfs_security_init(parent_dir, inode, &security);
1037 if (retval < 0) {
1038 drop_new_inode(inode);
1039 return retval;
1040 }
1041 jbegin_count += retval;
1042
1052 reiserfs_write_lock(parent_dir->i_sb); 1043 reiserfs_write_lock(parent_dir->i_sb);
1053 item_len = ROUND_UP(strlen(symname)); 1044 item_len = ROUND_UP(strlen(symname));
1054 if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) { 1045 if (item_len > MAX_DIRECT_ITEM_LEN(parent_dir->i_sb->s_blocksize)) {
@@ -1066,8 +1057,6 @@ static int reiserfs_symlink(struct inode *parent_dir,
1066 memcpy(name, symname, strlen(symname)); 1057 memcpy(name, symname, strlen(symname));
1067 padd_item(name, item_len, strlen(symname)); 1058 padd_item(name, item_len, strlen(symname));
1068 1059
1069 /* We would inherit the default ACL here, but symlinks don't get ACLs */
1070
1071 retval = journal_begin(&th, parent_dir->i_sb, jbegin_count); 1060 retval = journal_begin(&th, parent_dir->i_sb, jbegin_count);
1072 if (retval) { 1061 if (retval) {
1073 drop_new_inode(inode); 1062 drop_new_inode(inode);
@@ -1077,7 +1066,7 @@ static int reiserfs_symlink(struct inode *parent_dir,
1077 1066
1078 retval = 1067 retval =
1079 reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname), 1068 reiserfs_new_inode(&th, parent_dir, mode, name, strlen(symname),
1080 dentry, inode); 1069 dentry, inode, &security);
1081 kfree(name); 1070 kfree(name);
1082 if (retval) { /* reiserfs_new_inode iputs for us */ 1071 if (retval) { /* reiserfs_new_inode iputs for us */
1083 goto out_failed; 1072 goto out_failed;
@@ -1173,7 +1162,7 @@ static int reiserfs_link(struct dentry *old_dentry, struct inode *dir,
1173 return retval; 1162 return retval;
1174} 1163}
1175 1164
1176// de contains information pointing to an entry which 1165/* de contains information pointing to an entry which */
1177static int de_still_valid(const char *name, int len, 1166static int de_still_valid(const char *name, int len,
1178 struct reiserfs_dir_entry *de) 1167 struct reiserfs_dir_entry *de)
1179{ 1168{
@@ -1196,15 +1185,14 @@ static int entry_points_to_object(const char *name, int len,
1196 1185
1197 if (inode) { 1186 if (inode) {
1198 if (!de_visible(de->de_deh + de->de_entry_num)) 1187 if (!de_visible(de->de_deh + de->de_entry_num))
1199 reiserfs_panic(NULL, 1188 reiserfs_panic(inode->i_sb, "vs-7042",
1200 "vs-7042: entry_points_to_object: entry must be visible"); 1189 "entry must be visible");
1201 return (de->de_objectid == inode->i_ino) ? 1 : 0; 1190 return (de->de_objectid == inode->i_ino) ? 1 : 0;
1202 } 1191 }
1203 1192
1204 /* this must be added hidden entry */ 1193 /* this must be added hidden entry */
1205 if (de_visible(de->de_deh + de->de_entry_num)) 1194 if (de_visible(de->de_deh + de->de_entry_num))
1206 reiserfs_panic(NULL, 1195 reiserfs_panic(NULL, "vs-7043", "entry must be visible");
1207 "vs-7043: entry_points_to_object: entry must be visible");
1208 1196
1209 return 1; 1197 return 1;
1210} 1198}
@@ -1218,10 +1206,10 @@ static void set_ino_in_dir_entry(struct reiserfs_dir_entry *de,
1218 de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid; 1206 de->de_deh[de->de_entry_num].deh_objectid = key->k_objectid;
1219} 1207}
1220 1208
1221/* 1209/*
1222 * process, that is going to call fix_nodes/do_balance must hold only 1210 * process, that is going to call fix_nodes/do_balance must hold only
1223 * one path. If it holds 2 or more, it can get into endless waiting in 1211 * one path. If it holds 2 or more, it can get into endless waiting in
1224 * get_empty_nodes or its clones 1212 * get_empty_nodes or its clones
1225 */ 1213 */
1226static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry, 1214static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1227 struct inode *new_dir, struct dentry *new_dentry) 1215 struct inode *new_dir, struct dentry *new_dentry)
@@ -1275,7 +1263,7 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1275 1263
1276 old_inode_mode = old_inode->i_mode; 1264 old_inode_mode = old_inode->i_mode;
1277 if (S_ISDIR(old_inode_mode)) { 1265 if (S_ISDIR(old_inode_mode)) {
1278 // make sure, that directory being renamed has correct ".." 1266 // make sure, that directory being renamed has correct ".."
1279 // and that its new parent directory has not too many links 1267 // and that its new parent directory has not too many links
1280 // already 1268 // already
1281 1269
@@ -1286,8 +1274,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1286 } 1274 }
1287 } 1275 }
1288 1276
1289 /* directory is renamed, its parent directory will be changed, 1277 /* directory is renamed, its parent directory will be changed,
1290 ** so find ".." entry 1278 ** so find ".." entry
1291 */ 1279 */
1292 dot_dot_de.de_gen_number_bit_string = NULL; 1280 dot_dot_de.de_gen_number_bit_string = NULL;
1293 retval = 1281 retval =
@@ -1318,8 +1306,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1318 new_dentry->d_name.len, old_inode, 0); 1306 new_dentry->d_name.len, old_inode, 0);
1319 if (retval == -EEXIST) { 1307 if (retval == -EEXIST) {
1320 if (!new_dentry_inode) { 1308 if (!new_dentry_inode) {
1321 reiserfs_panic(old_dir->i_sb, 1309 reiserfs_panic(old_dir->i_sb, "vs-7050",
1322 "vs-7050: new entry is found, new inode == 0\n"); 1310 "new entry is found, new inode == 0");
1323 } 1311 }
1324 } else if (retval) { 1312 } else if (retval) {
1325 int err = journal_end(&th, old_dir->i_sb, jbegin_count); 1313 int err = journal_end(&th, old_dir->i_sb, jbegin_count);
@@ -1397,9 +1385,9 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1397 this stuff, yes? Then, having 1385 this stuff, yes? Then, having
1398 gathered everything into RAM we 1386 gathered everything into RAM we
1399 should lock the buffers, yes? -Hans */ 1387 should lock the buffers, yes? -Hans */
1400 /* probably. our rename needs to hold more 1388 /* probably. our rename needs to hold more
1401 ** than one path at once. The seals would 1389 ** than one path at once. The seals would
1402 ** have to be written to deal with multi-path 1390 ** have to be written to deal with multi-path
1403 ** issues -chris 1391 ** issues -chris
1404 */ 1392 */
1405 /* sanity checking before doing the rename - avoid races many 1393 /* sanity checking before doing the rename - avoid races many
@@ -1477,7 +1465,7 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1477 } 1465 }
1478 1466
1479 if (S_ISDIR(old_inode_mode)) { 1467 if (S_ISDIR(old_inode_mode)) {
1480 // adjust ".." of renamed directory 1468 /* adjust ".." of renamed directory */
1481 set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir)); 1469 set_ino_in_dir_entry(&dot_dot_de, INODE_PKEY(new_dir));
1482 journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh); 1470 journal_mark_dirty(&th, new_dir->i_sb, dot_dot_de.de_bh);
1483 1471
@@ -1499,8 +1487,8 @@ static int reiserfs_rename(struct inode *old_dir, struct dentry *old_dentry,
1499 if (reiserfs_cut_from_item 1487 if (reiserfs_cut_from_item
1500 (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL, 1488 (&th, &old_entry_path, &(old_de.de_entry_key), old_dir, NULL,
1501 0) < 0) 1489 0) < 0)
1502 reiserfs_warning(old_dir->i_sb, 1490 reiserfs_error(old_dir->i_sb, "vs-7060",
1503 "vs-7060: reiserfs_rename: couldn't not cut old name. Fsck later?"); 1491 "couldn't not cut old name. Fsck later?");
1504 1492
1505 old_dir->i_size -= DEH_SIZE + old_de.de_entrylen; 1493 old_dir->i_size -= DEH_SIZE + old_de.de_entrylen;
1506 1494
diff --git a/fs/reiserfs/objectid.c b/fs/reiserfs/objectid.c
index ea0cf8c28a9..3a6de810bd6 100644
--- a/fs/reiserfs/objectid.c
+++ b/fs/reiserfs/objectid.c
@@ -18,8 +18,7 @@
18static void check_objectid_map(struct super_block *s, __le32 * map) 18static void check_objectid_map(struct super_block *s, __le32 * map)
19{ 19{
20 if (le32_to_cpu(map[0]) != 1) 20 if (le32_to_cpu(map[0]) != 1)
21 reiserfs_panic(s, 21 reiserfs_panic(s, "vs-15010", "map corrupted: %lx",
22 "vs-15010: check_objectid_map: map corrupted: %lx",
23 (long unsigned int)le32_to_cpu(map[0])); 22 (long unsigned int)le32_to_cpu(map[0]));
24 23
25 // FIXME: add something else here 24 // FIXME: add something else here
@@ -61,7 +60,7 @@ __u32 reiserfs_get_unused_objectid(struct reiserfs_transaction_handle *th)
61 /* comment needed -Hans */ 60 /* comment needed -Hans */
62 unused_objectid = le32_to_cpu(map[1]); 61 unused_objectid = le32_to_cpu(map[1]);
63 if (unused_objectid == U32_MAX) { 62 if (unused_objectid == U32_MAX) {
64 reiserfs_warning(s, "%s: no more object ids", __func__); 63 reiserfs_warning(s, "reiserfs-15100", "no more object ids");
65 reiserfs_restore_prepared_buffer(s, SB_BUFFER_WITH_SB(s)); 64 reiserfs_restore_prepared_buffer(s, SB_BUFFER_WITH_SB(s));
66 return 0; 65 return 0;
67 } 66 }
@@ -160,9 +159,8 @@ void reiserfs_release_objectid(struct reiserfs_transaction_handle *th,
160 i += 2; 159 i += 2;
161 } 160 }
162 161
163 reiserfs_warning(s, 162 reiserfs_error(s, "vs-15011", "tried to free free object id (%lu)",
164 "vs-15011: reiserfs_release_objectid: tried to free free object id (%lu)", 163 (long unsigned)objectid_to_release);
165 (long unsigned)objectid_to_release);
166} 164}
167 165
168int reiserfs_convert_objectid_map_v1(struct super_block *s) 166int reiserfs_convert_objectid_map_v1(struct super_block *s)
@@ -182,7 +180,7 @@ int reiserfs_convert_objectid_map_v1(struct super_block *s)
182 180
183 if (cur_size > new_size) { 181 if (cur_size > new_size) {
184 /* mark everyone used that was listed as free at the end of the objectid 182 /* mark everyone used that was listed as free at the end of the objectid
185 ** map 183 ** map
186 */ 184 */
187 objectid_map[new_size - 1] = objectid_map[cur_size - 1]; 185 objectid_map[new_size - 1] = objectid_map[cur_size - 1];
188 set_sb_oid_cursize(disk_sb, new_size); 186 set_sb_oid_cursize(disk_sb, new_size);
diff --git a/fs/reiserfs/prints.c b/fs/reiserfs/prints.c
index 740bb8c0c1a..536eacaeb71 100644
--- a/fs/reiserfs/prints.c
+++ b/fs/reiserfs/prints.c
@@ -157,19 +157,16 @@ static void sprintf_disk_child(char *buf, struct disk_child *dc)
157 dc_size(dc)); 157 dc_size(dc));
158} 158}
159 159
160static char *is_there_reiserfs_struct(char *fmt, int *what, int *skip) 160static char *is_there_reiserfs_struct(char *fmt, int *what)
161{ 161{
162 char *k = fmt; 162 char *k = fmt;
163 163
164 *skip = 0;
165
166 while ((k = strchr(k, '%')) != NULL) { 164 while ((k = strchr(k, '%')) != NULL) {
167 if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' || 165 if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
168 k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a') { 166 k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a') {
169 *what = k[1]; 167 *what = k[1];
170 break; 168 break;
171 } 169 }
172 (*skip)++;
173 k++; 170 k++;
174 } 171 }
175 return k; 172 return k;
@@ -181,30 +178,29 @@ static char *is_there_reiserfs_struct(char *fmt, int *what, int *skip)
181 appropriative printk. With this reiserfs_warning you can use format 178 appropriative printk. With this reiserfs_warning you can use format
182 specification for complex structures like you used to do with 179 specification for complex structures like you used to do with
183 printfs for integers, doubles and pointers. For instance, to print 180 printfs for integers, doubles and pointers. For instance, to print
184 out key structure you have to write just: 181 out key structure you have to write just:
185 reiserfs_warning ("bad key %k", key); 182 reiserfs_warning ("bad key %k", key);
186 instead of 183 instead of
187 printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid, 184 printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid,
188 key->k_offset, key->k_uniqueness); 185 key->k_offset, key->k_uniqueness);
189*/ 186*/
190 187static DEFINE_SPINLOCK(error_lock);
191static void prepare_error_buf(const char *fmt, va_list args) 188static void prepare_error_buf(const char *fmt, va_list args)
192{ 189{
193 char *fmt1 = fmt_buf; 190 char *fmt1 = fmt_buf;
194 char *k; 191 char *k;
195 char *p = error_buf; 192 char *p = error_buf;
196 int i, j, what, skip; 193 int what;
194
195 spin_lock(&error_lock);
197 196
198 strcpy(fmt1, fmt); 197 strcpy(fmt1, fmt);
199 198
200 while ((k = is_there_reiserfs_struct(fmt1, &what, &skip)) != NULL) { 199 while ((k = is_there_reiserfs_struct(fmt1, &what)) != NULL) {
201 *k = 0; 200 *k = 0;
202 201
203 p += vsprintf(p, fmt1, args); 202 p += vsprintf(p, fmt1, args);
204 203
205 for (i = 0; i < skip; i++)
206 j = va_arg(args, int);
207
208 switch (what) { 204 switch (what) {
209 case 'k': 205 case 'k':
210 sprintf_le_key(p, va_arg(args, struct reiserfs_key *)); 206 sprintf_le_key(p, va_arg(args, struct reiserfs_key *));
@@ -243,15 +239,16 @@ static void prepare_error_buf(const char *fmt, va_list args)
243 fmt1 = k + 2; 239 fmt1 = k + 2;
244 } 240 }
245 vsprintf(p, fmt1, args); 241 vsprintf(p, fmt1, args);
242 spin_unlock(&error_lock);
246 243
247} 244}
248 245
249/* in addition to usual conversion specifiers this accepts reiserfs 246/* in addition to usual conversion specifiers this accepts reiserfs
250 specific conversion specifiers: 247 specific conversion specifiers:
251 %k to print little endian key, 248 %k to print little endian key,
252 %K to print cpu key, 249 %K to print cpu key,
253 %h to print item_head, 250 %h to print item_head,
254 %t to print directory entry 251 %t to print directory entry
255 %z to print block head (arg must be struct buffer_head * 252 %z to print block head (arg must be struct buffer_head *
256 %b to print buffer_head 253 %b to print buffer_head
257*/ 254*/
@@ -264,14 +261,17 @@ static void prepare_error_buf(const char *fmt, va_list args)
264 va_end( args );\ 261 va_end( args );\
265} 262}
266 263
267void reiserfs_warning(struct super_block *sb, const char *fmt, ...) 264void __reiserfs_warning(struct super_block *sb, const char *id,
265 const char *function, const char *fmt, ...)
268{ 266{
269 do_reiserfs_warning(fmt); 267 do_reiserfs_warning(fmt);
270 if (sb) 268 if (sb)
271 printk(KERN_WARNING "ReiserFS: %s: warning: %s\n", 269 printk(KERN_WARNING "REISERFS warning (device %s): %s%s%s: "
272 reiserfs_bdevname(sb), error_buf); 270 "%s\n", sb->s_id, id ? id : "", id ? " " : "",
271 function, error_buf);
273 else 272 else
274 printk(KERN_WARNING "ReiserFS: warning: %s\n", error_buf); 273 printk(KERN_WARNING "REISERFS warning: %s%s%s: %s\n",
274 id ? id : "", id ? " " : "", function, error_buf);
275} 275}
276 276
277/* No newline.. reiserfs_info calls can be followed by printk's */ 277/* No newline.. reiserfs_info calls can be followed by printk's */
@@ -279,10 +279,10 @@ void reiserfs_info(struct super_block *sb, const char *fmt, ...)
279{ 279{
280 do_reiserfs_warning(fmt); 280 do_reiserfs_warning(fmt);
281 if (sb) 281 if (sb)
282 printk(KERN_NOTICE "ReiserFS: %s: %s", 282 printk(KERN_NOTICE "REISERFS (device %s): %s",
283 reiserfs_bdevname(sb), error_buf); 283 sb->s_id, error_buf);
284 else 284 else
285 printk(KERN_NOTICE "ReiserFS: %s", error_buf); 285 printk(KERN_NOTICE "REISERFS %s:", error_buf);
286} 286}
287 287
288/* No newline.. reiserfs_printk calls can be followed by printk's */ 288/* No newline.. reiserfs_printk calls can be followed by printk's */
@@ -297,10 +297,10 @@ void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
297#ifdef CONFIG_REISERFS_CHECK 297#ifdef CONFIG_REISERFS_CHECK
298 do_reiserfs_warning(fmt); 298 do_reiserfs_warning(fmt);
299 if (s) 299 if (s)
300 printk(KERN_DEBUG "ReiserFS: %s: %s\n", 300 printk(KERN_DEBUG "REISERFS debug (device %s): %s\n",
301 reiserfs_bdevname(s), error_buf); 301 s->s_id, error_buf);
302 else 302 else
303 printk(KERN_DEBUG "ReiserFS: %s\n", error_buf); 303 printk(KERN_DEBUG "REISERFS debug: %s\n", error_buf);
304#endif 304#endif
305} 305}
306 306
@@ -314,17 +314,17 @@ void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
314 maintainer-errorid. Don't bother with reusing errorids, there are 314 maintainer-errorid. Don't bother with reusing errorids, there are
315 lots of numbers out there. 315 lots of numbers out there.
316 316
317 Example: 317 Example:
318 318
319 reiserfs_panic( 319 reiserfs_panic(
320 p_sb, "reiser-29: reiserfs_new_blocknrs: " 320 p_sb, "reiser-29: reiserfs_new_blocknrs: "
321 "one of search_start or rn(%d) is equal to MAX_B_NUM," 321 "one of search_start or rn(%d) is equal to MAX_B_NUM,"
322 "which means that we are optimizing location based on the bogus location of a temp buffer (%p).", 322 "which means that we are optimizing location based on the bogus location of a temp buffer (%p).",
323 rn, bh 323 rn, bh
324 ); 324 );
325 325
326 Regular panic()s sometimes clear the screen before the message can 326 Regular panic()s sometimes clear the screen before the message can
327 be read, thus the need for the while loop. 327 be read, thus the need for the while loop.
328 328
329 Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it 329 Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it
330 pointless complexity): 330 pointless complexity):
@@ -353,14 +353,46 @@ void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
353extern struct tree_balance *cur_tb; 353extern struct tree_balance *cur_tb;
354#endif 354#endif
355 355
356void reiserfs_panic(struct super_block *sb, const char *fmt, ...) 356void __reiserfs_panic(struct super_block *sb, const char *id,
357 const char *function, const char *fmt, ...)
357{ 358{
358 do_reiserfs_warning(fmt); 359 do_reiserfs_warning(fmt);
359 360
361#ifdef CONFIG_REISERFS_CHECK
360 dump_stack(); 362 dump_stack();
363#endif
364 if (sb)
365 panic(KERN_WARNING "REISERFS panic (device %s): %s%s%s: %s\n",
366 sb->s_id, id ? id : "", id ? " " : "",
367 function, error_buf);
368 else
369 panic(KERN_WARNING "REISERFS panic: %s%s%s: %s\n",
370 id ? id : "", id ? " " : "", function, error_buf);
371}
372
373void __reiserfs_error(struct super_block *sb, const char *id,
374 const char *function, const char *fmt, ...)
375{
376 do_reiserfs_warning(fmt);
361 377
362 panic(KERN_EMERG "REISERFS: panic (device %s): %s\n", 378 BUG_ON(sb == NULL);
363 reiserfs_bdevname(sb), error_buf); 379
380 if (reiserfs_error_panic(sb))
381 __reiserfs_panic(sb, id, function, error_buf);
382
383 if (id && id[0])
384 printk(KERN_CRIT "REISERFS error (device %s): %s %s: %s\n",
385 sb->s_id, id, function, error_buf);
386 else
387 printk(KERN_CRIT "REISERFS error (device %s): %s: %s\n",
388 sb->s_id, function, error_buf);
389
390 if (sb->s_flags & MS_RDONLY)
391 return;
392
393 reiserfs_info(sb, "Remounting filesystem read-only\n");
394 sb->s_flags |= MS_RDONLY;
395 reiserfs_abort_journal(sb, -EIO);
364} 396}
365 397
366void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...) 398void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
@@ -368,18 +400,18 @@ void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
368 do_reiserfs_warning(fmt); 400 do_reiserfs_warning(fmt);
369 401
370 if (reiserfs_error_panic(sb)) { 402 if (reiserfs_error_panic(sb)) {
371 panic(KERN_CRIT "REISERFS: panic (device %s): %s\n", 403 panic(KERN_CRIT "REISERFS panic (device %s): %s\n", sb->s_id,
372 reiserfs_bdevname(sb), error_buf); 404 error_buf);
373 } 405 }
374 406
375 if (sb->s_flags & MS_RDONLY) 407 if (reiserfs_is_journal_aborted(SB_JOURNAL(sb)))
376 return; 408 return;
377 409
378 printk(KERN_CRIT "REISERFS: abort (device %s): %s\n", 410 printk(KERN_CRIT "REISERFS abort (device %s): %s\n", sb->s_id,
379 reiserfs_bdevname(sb), error_buf); 411 error_buf);
380 412
381 sb->s_flags |= MS_RDONLY; 413 sb->s_flags |= MS_RDONLY;
382 reiserfs_journal_abort(sb, errno); 414 reiserfs_abort_journal(sb, errno);
383} 415}
384 416
385/* this prints internal nodes (4 keys/items in line) (dc_number, 417/* this prints internal nodes (4 keys/items in line) (dc_number,
@@ -681,12 +713,10 @@ static void check_leaf_block_head(struct buffer_head *bh)
681 blkh = B_BLK_HEAD(bh); 713 blkh = B_BLK_HEAD(bh);
682 nr = blkh_nr_item(blkh); 714 nr = blkh_nr_item(blkh);
683 if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE) 715 if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
684 reiserfs_panic(NULL, 716 reiserfs_panic(NULL, "vs-6010", "invalid item number %z",
685 "vs-6010: check_leaf_block_head: invalid item number %z",
686 bh); 717 bh);
687 if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr) 718 if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr)
688 reiserfs_panic(NULL, 719 reiserfs_panic(NULL, "vs-6020", "invalid free space %z",
689 "vs-6020: check_leaf_block_head: invalid free space %z",
690 bh); 720 bh);
691 721
692} 722}
@@ -697,21 +727,15 @@ static void check_internal_block_head(struct buffer_head *bh)
697 727
698 blkh = B_BLK_HEAD(bh); 728 blkh = B_BLK_HEAD(bh);
699 if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT)) 729 if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT))
700 reiserfs_panic(NULL, 730 reiserfs_panic(NULL, "vs-6025", "invalid level %z", bh);
701 "vs-6025: check_internal_block_head: invalid level %z",
702 bh);
703 731
704 if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE) 732 if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
705 reiserfs_panic(NULL, 733 reiserfs_panic(NULL, "vs-6030", "invalid item number %z", bh);
706 "vs-6030: check_internal_block_head: invalid item number %z",
707 bh);
708 734
709 if (B_FREE_SPACE(bh) != 735 if (B_FREE_SPACE(bh) !=
710 bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) - 736 bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) -
711 DC_SIZE * (B_NR_ITEMS(bh) + 1)) 737 DC_SIZE * (B_NR_ITEMS(bh) + 1))
712 reiserfs_panic(NULL, 738 reiserfs_panic(NULL, "vs-6040", "invalid free space %z", bh);
713 "vs-6040: check_internal_block_head: invalid free space %z",
714 bh);
715 739
716} 740}
717 741
diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
index 37173fa07d1..9229e5514a4 100644
--- a/fs/reiserfs/procfs.c
+++ b/fs/reiserfs/procfs.c
@@ -321,7 +321,7 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
321 /* incore fields */ 321 /* incore fields */
322 "j_1st_reserved_block: \t%i\n" 322 "j_1st_reserved_block: \t%i\n"
323 "j_state: \t%li\n" 323 "j_state: \t%li\n"
324 "j_trans_id: \t%lu\n" 324 "j_trans_id: \t%u\n"
325 "j_mount_id: \t%lu\n" 325 "j_mount_id: \t%lu\n"
326 "j_start: \t%lu\n" 326 "j_start: \t%lu\n"
327 "j_len: \t%lu\n" 327 "j_len: \t%lu\n"
@@ -329,7 +329,7 @@ static int show_journal(struct seq_file *m, struct super_block *sb)
329 "j_wcount: \t%i\n" 329 "j_wcount: \t%i\n"
330 "j_bcount: \t%lu\n" 330 "j_bcount: \t%lu\n"
331 "j_first_unflushed_offset: \t%lu\n" 331 "j_first_unflushed_offset: \t%lu\n"
332 "j_last_flush_trans_id: \t%lu\n" 332 "j_last_flush_trans_id: \t%u\n"
333 "j_trans_start_time: \t%li\n" 333 "j_trans_start_time: \t%li\n"
334 "j_list_bitmap_index: \t%i\n" 334 "j_list_bitmap_index: \t%i\n"
335 "j_must_wait: \t%i\n" 335 "j_must_wait: \t%i\n"
@@ -492,7 +492,6 @@ int reiserfs_proc_info_init(struct super_block *sb)
492 spin_lock_init(&__PINFO(sb).lock); 492 spin_lock_init(&__PINFO(sb).lock);
493 REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root); 493 REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root);
494 if (REISERFS_SB(sb)->procdir) { 494 if (REISERFS_SB(sb)->procdir) {
495 REISERFS_SB(sb)->procdir->owner = THIS_MODULE;
496 REISERFS_SB(sb)->procdir->data = sb; 495 REISERFS_SB(sb)->procdir->data = sb;
497 add_file(sb, "version", show_version); 496 add_file(sb, "version", show_version);
498 add_file(sb, "super", show_super); 497 add_file(sb, "super", show_super);
@@ -503,7 +502,7 @@ int reiserfs_proc_info_init(struct super_block *sb)
503 add_file(sb, "journal", show_journal); 502 add_file(sb, "journal", show_journal);
504 return 0; 503 return 0;
505 } 504 }
506 reiserfs_warning(sb, "reiserfs: cannot create /proc/%s/%s", 505 reiserfs_warning(sb, "cannot create /proc/%s/%s",
507 proc_info_root_name, b); 506 proc_info_root_name, b);
508 return 1; 507 return 1;
509} 508}
@@ -556,11 +555,8 @@ int reiserfs_proc_info_global_init(void)
556{ 555{
557 if (proc_info_root == NULL) { 556 if (proc_info_root == NULL) {
558 proc_info_root = proc_mkdir(proc_info_root_name, NULL); 557 proc_info_root = proc_mkdir(proc_info_root_name, NULL);
559 if (proc_info_root) { 558 if (!proc_info_root) {
560 proc_info_root->owner = THIS_MODULE; 559 reiserfs_warning(NULL, "cannot create /proc/%s",
561 } else {
562 reiserfs_warning(NULL,
563 "reiserfs: cannot create /proc/%s",
564 proc_info_root_name); 560 proc_info_root_name);
565 return 1; 561 return 1;
566 } 562 }
@@ -634,7 +630,7 @@ int reiserfs_global_version_in_proc(char *buffer, char **start,
634 * 630 *
635 */ 631 */
636 632
637/* 633/*
638 * Make Linus happy. 634 * Make Linus happy.
639 * Local variables: 635 * Local variables:
640 * c-indentation-style: "K&R" 636 * c-indentation-style: "K&R"
diff --git a/fs/reiserfs/resize.c b/fs/reiserfs/resize.c
index f71c3948ede..238e9d9b31e 100644
--- a/fs/reiserfs/resize.c
+++ b/fs/reiserfs/resize.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README 2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
3 */ 3 */
4 4
5/* 5/*
6 * Written by Alexander Zarochentcev. 6 * Written by Alexander Zarochentcev.
7 * 7 *
8 * The kernel part of the (on-line) reiserfs resizer. 8 * The kernel part of the (on-line) reiserfs resizer.
@@ -101,7 +101,7 @@ int reiserfs_resize(struct super_block *s, unsigned long block_count_new)
101 memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size); 101 memcpy(jbitmap[i].bitmaps, jb->bitmaps, copy_size);
102 102
103 /* just in case vfree schedules on us, copy the new 103 /* just in case vfree schedules on us, copy the new
104 ** pointer into the journal struct before freeing the 104 ** pointer into the journal struct before freeing the
105 ** old one 105 ** old one
106 */ 106 */
107 node_tmp = jb->bitmaps; 107 node_tmp = jb->bitmaps;
diff --git a/fs/reiserfs/stree.c b/fs/reiserfs/stree.c
index abbc64dcc8d..d036ee5b1c8 100644
--- a/fs/reiserfs/stree.c
+++ b/fs/reiserfs/stree.c
@@ -23,7 +23,6 @@
23 * get_rkey 23 * get_rkey
24 * key_in_buffer 24 * key_in_buffer
25 * decrement_bcount 25 * decrement_bcount
26 * decrement_counters_in_path
27 * reiserfs_check_path 26 * reiserfs_check_path
28 * pathrelse_and_restore 27 * pathrelse_and_restore
29 * pathrelse 28 * pathrelse
@@ -57,28 +56,28 @@
57#include <linux/quotaops.h> 56#include <linux/quotaops.h>
58 57
59/* Does the buffer contain a disk block which is in the tree. */ 58/* Does the buffer contain a disk block which is in the tree. */
60inline int B_IS_IN_TREE(const struct buffer_head *p_s_bh) 59inline int B_IS_IN_TREE(const struct buffer_head *bh)
61{ 60{
62 61
63 RFALSE(B_LEVEL(p_s_bh) > MAX_HEIGHT, 62 RFALSE(B_LEVEL(bh) > MAX_HEIGHT,
64 "PAP-1010: block (%b) has too big level (%z)", p_s_bh, p_s_bh); 63 "PAP-1010: block (%b) has too big level (%z)", bh, bh);
65 64
66 return (B_LEVEL(p_s_bh) != FREE_LEVEL); 65 return (B_LEVEL(bh) != FREE_LEVEL);
67} 66}
68 67
69// 68//
70// to gets item head in le form 69// to gets item head in le form
71// 70//
72inline void copy_item_head(struct item_head *p_v_to, 71inline void copy_item_head(struct item_head *to,
73 const struct item_head *p_v_from) 72 const struct item_head *from)
74{ 73{
75 memcpy(p_v_to, p_v_from, IH_SIZE); 74 memcpy(to, from, IH_SIZE);
76} 75}
77 76
78/* k1 is pointer to on-disk structure which is stored in little-endian 77/* k1 is pointer to on-disk structure which is stored in little-endian
79 form. k2 is pointer to cpu variable. For key of items of the same 78 form. k2 is pointer to cpu variable. For key of items of the same
80 object this returns 0. 79 object this returns 0.
81 Returns: -1 if key1 < key2 80 Returns: -1 if key1 < key2
82 0 if key1 == key2 81 0 if key1 == key2
83 1 if key1 > key2 */ 82 1 if key1 > key2 */
84inline int comp_short_keys(const struct reiserfs_key *le_key, 83inline int comp_short_keys(const struct reiserfs_key *le_key,
@@ -136,15 +135,15 @@ static inline int comp_keys(const struct reiserfs_key *le_key,
136inline int comp_short_le_keys(const struct reiserfs_key *key1, 135inline int comp_short_le_keys(const struct reiserfs_key *key1,
137 const struct reiserfs_key *key2) 136 const struct reiserfs_key *key2)
138{ 137{
139 __u32 *p_s_1_u32, *p_s_2_u32; 138 __u32 *k1_u32, *k2_u32;
140 int n_key_length = REISERFS_SHORT_KEY_LEN; 139 int key_length = REISERFS_SHORT_KEY_LEN;
141 140
142 p_s_1_u32 = (__u32 *) key1; 141 k1_u32 = (__u32 *) key1;
143 p_s_2_u32 = (__u32 *) key2; 142 k2_u32 = (__u32 *) key2;
144 for (; n_key_length--; ++p_s_1_u32, ++p_s_2_u32) { 143 for (; key_length--; ++k1_u32, ++k2_u32) {
145 if (le32_to_cpu(*p_s_1_u32) < le32_to_cpu(*p_s_2_u32)) 144 if (le32_to_cpu(*k1_u32) < le32_to_cpu(*k2_u32))
146 return -1; 145 return -1;
147 if (le32_to_cpu(*p_s_1_u32) > le32_to_cpu(*p_s_2_u32)) 146 if (le32_to_cpu(*k1_u32) > le32_to_cpu(*k2_u32))
148 return 1; 147 return 1;
149 } 148 }
150 return 0; 149 return 0;
@@ -175,52 +174,51 @@ inline int comp_le_keys(const struct reiserfs_key *k1,
175 * Binary search toolkit function * 174 * Binary search toolkit function *
176 * Search for an item in the array by the item key * 175 * Search for an item in the array by the item key *
177 * Returns: 1 if found, 0 if not found; * 176 * Returns: 1 if found, 0 if not found; *
178 * *p_n_pos = number of the searched element if found, else the * 177 * *pos = number of the searched element if found, else the *
179 * number of the first element that is larger than p_v_key. * 178 * number of the first element that is larger than key. *
180 **************************************************************************/ 179 **************************************************************************/
181/* For those not familiar with binary search: n_lbound is the leftmost item that it 180/* For those not familiar with binary search: lbound is the leftmost item that it
182 could be, n_rbound the rightmost item that it could be. We examine the item 181 could be, rbound the rightmost item that it could be. We examine the item
183 halfway between n_lbound and n_rbound, and that tells us either that we can increase 182 halfway between lbound and rbound, and that tells us either that we can increase
184 n_lbound, or decrease n_rbound, or that we have found it, or if n_lbound <= n_rbound that 183 lbound, or decrease rbound, or that we have found it, or if lbound <= rbound that
185 there are no possible items, and we have not found it. With each examination we 184 there are no possible items, and we have not found it. With each examination we
186 cut the number of possible items it could be by one more than half rounded down, 185 cut the number of possible items it could be by one more than half rounded down,
187 or we find it. */ 186 or we find it. */
188static inline int bin_search(const void *p_v_key, /* Key to search for. */ 187static inline int bin_search(const void *key, /* Key to search for. */
189 const void *p_v_base, /* First item in the array. */ 188 const void *base, /* First item in the array. */
190 int p_n_num, /* Number of items in the array. */ 189 int num, /* Number of items in the array. */
191 int p_n_width, /* Item size in the array. 190 int width, /* Item size in the array.
192 searched. Lest the reader be 191 searched. Lest the reader be
193 confused, note that this is crafted 192 confused, note that this is crafted
194 as a general function, and when it 193 as a general function, and when it
195 is applied specifically to the array 194 is applied specifically to the array
196 of item headers in a node, p_n_width 195 of item headers in a node, width
197 is actually the item header size not 196 is actually the item header size not
198 the item size. */ 197 the item size. */
199 int *p_n_pos /* Number of the searched for element. */ 198 int *pos /* Number of the searched for element. */
200 ) 199 )
201{ 200{
202 int n_rbound, n_lbound, n_j; 201 int rbound, lbound, j;
203 202
204 for (n_j = ((n_rbound = p_n_num - 1) + (n_lbound = 0)) / 2; 203 for (j = ((rbound = num - 1) + (lbound = 0)) / 2;
205 n_lbound <= n_rbound; n_j = (n_rbound + n_lbound) / 2) 204 lbound <= rbound; j = (rbound + lbound) / 2)
206 switch (comp_keys 205 switch (comp_keys
207 ((struct reiserfs_key *)((char *)p_v_base + 206 ((struct reiserfs_key *)((char *)base + j * width),
208 n_j * p_n_width), 207 (struct cpu_key *)key)) {
209 (struct cpu_key *)p_v_key)) {
210 case -1: 208 case -1:
211 n_lbound = n_j + 1; 209 lbound = j + 1;
212 continue; 210 continue;
213 case 1: 211 case 1:
214 n_rbound = n_j - 1; 212 rbound = j - 1;
215 continue; 213 continue;
216 case 0: 214 case 0:
217 *p_n_pos = n_j; 215 *pos = j;
218 return ITEM_FOUND; /* Key found in the array. */ 216 return ITEM_FOUND; /* Key found in the array. */
219 } 217 }
220 218
221 /* bin_search did not find given key, it returns position of key, 219 /* bin_search did not find given key, it returns position of key,
222 that is minimal and greater than the given one. */ 220 that is minimal and greater than the given one. */
223 *p_n_pos = n_lbound; 221 *pos = lbound;
224 return ITEM_NOT_FOUND; 222 return ITEM_NOT_FOUND;
225} 223}
226 224
@@ -243,90 +241,88 @@ static const struct reiserfs_key MAX_KEY = {
243 of the path, and going upwards. We must check the path's validity at each step. If the key is not in 241 of the path, and going upwards. We must check the path's validity at each step. If the key is not in
244 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this 242 the path, there is no delimiting key in the tree (buffer is first or last buffer in tree), and in this
245 case we return a special key, either MIN_KEY or MAX_KEY. */ 243 case we return a special key, either MIN_KEY or MAX_KEY. */
246static inline const struct reiserfs_key *get_lkey(const struct treepath 244static inline const struct reiserfs_key *get_lkey(const struct treepath *chk_path,
247 *p_s_chk_path, 245 const struct super_block *sb)
248 const struct super_block
249 *p_s_sb)
250{ 246{
251 int n_position, n_path_offset = p_s_chk_path->path_length; 247 int position, path_offset = chk_path->path_length;
252 struct buffer_head *p_s_parent; 248 struct buffer_head *parent;
253 249
254 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 250 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET,
255 "PAP-5010: invalid offset in the path"); 251 "PAP-5010: invalid offset in the path");
256 252
257 /* While not higher in path than first element. */ 253 /* While not higher in path than first element. */
258 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 254 while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
259 255
260 RFALSE(!buffer_uptodate 256 RFALSE(!buffer_uptodate
261 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 257 (PATH_OFFSET_PBUFFER(chk_path, path_offset)),
262 "PAP-5020: parent is not uptodate"); 258 "PAP-5020: parent is not uptodate");
263 259
264 /* Parent at the path is not in the tree now. */ 260 /* Parent at the path is not in the tree now. */
265 if (!B_IS_IN_TREE 261 if (!B_IS_IN_TREE
266 (p_s_parent = 262 (parent =
267 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset))) 263 PATH_OFFSET_PBUFFER(chk_path, path_offset)))
268 return &MAX_KEY; 264 return &MAX_KEY;
269 /* Check whether position in the parent is correct. */ 265 /* Check whether position in the parent is correct. */
270 if ((n_position = 266 if ((position =
271 PATH_OFFSET_POSITION(p_s_chk_path, 267 PATH_OFFSET_POSITION(chk_path,
272 n_path_offset)) > 268 path_offset)) >
273 B_NR_ITEMS(p_s_parent)) 269 B_NR_ITEMS(parent))
274 return &MAX_KEY; 270 return &MAX_KEY;
275 /* Check whether parent at the path really points to the child. */ 271 /* Check whether parent at the path really points to the child. */
276 if (B_N_CHILD_NUM(p_s_parent, n_position) != 272 if (B_N_CHILD_NUM(parent, position) !=
277 PATH_OFFSET_PBUFFER(p_s_chk_path, 273 PATH_OFFSET_PBUFFER(chk_path,
278 n_path_offset + 1)->b_blocknr) 274 path_offset + 1)->b_blocknr)
279 return &MAX_KEY; 275 return &MAX_KEY;
280 /* Return delimiting key if position in the parent is not equal to zero. */ 276 /* Return delimiting key if position in the parent is not equal to zero. */
281 if (n_position) 277 if (position)
282 return B_N_PDELIM_KEY(p_s_parent, n_position - 1); 278 return B_N_PDELIM_KEY(parent, position - 1);
283 } 279 }
284 /* Return MIN_KEY if we are in the root of the buffer tree. */ 280 /* Return MIN_KEY if we are in the root of the buffer tree. */
285 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 281 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
286 b_blocknr == SB_ROOT_BLOCK(p_s_sb)) 282 b_blocknr == SB_ROOT_BLOCK(sb))
287 return &MIN_KEY; 283 return &MIN_KEY;
288 return &MAX_KEY; 284 return &MAX_KEY;
289} 285}
290 286
291/* Get delimiting key of the buffer at the path and its right neighbor. */ 287/* Get delimiting key of the buffer at the path and its right neighbor. */
292inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path, 288inline const struct reiserfs_key *get_rkey(const struct treepath *chk_path,
293 const struct super_block *p_s_sb) 289 const struct super_block *sb)
294{ 290{
295 int n_position, n_path_offset = p_s_chk_path->path_length; 291 int position, path_offset = chk_path->path_length;
296 struct buffer_head *p_s_parent; 292 struct buffer_head *parent;
297 293
298 RFALSE(n_path_offset < FIRST_PATH_ELEMENT_OFFSET, 294 RFALSE(path_offset < FIRST_PATH_ELEMENT_OFFSET,
299 "PAP-5030: invalid offset in the path"); 295 "PAP-5030: invalid offset in the path");
300 296
301 while (n_path_offset-- > FIRST_PATH_ELEMENT_OFFSET) { 297 while (path_offset-- > FIRST_PATH_ELEMENT_OFFSET) {
302 298
303 RFALSE(!buffer_uptodate 299 RFALSE(!buffer_uptodate
304 (PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset)), 300 (PATH_OFFSET_PBUFFER(chk_path, path_offset)),
305 "PAP-5040: parent is not uptodate"); 301 "PAP-5040: parent is not uptodate");
306 302
307 /* Parent at the path is not in the tree now. */ 303 /* Parent at the path is not in the tree now. */
308 if (!B_IS_IN_TREE 304 if (!B_IS_IN_TREE
309 (p_s_parent = 305 (parent =
310 PATH_OFFSET_PBUFFER(p_s_chk_path, n_path_offset))) 306 PATH_OFFSET_PBUFFER(chk_path, path_offset)))
311 return &MIN_KEY; 307 return &MIN_KEY;
312 /* Check whether position in the parent is correct. */ 308 /* Check whether position in the parent is correct. */
313 if ((n_position = 309 if ((position =
314 PATH_OFFSET_POSITION(p_s_chk_path, 310 PATH_OFFSET_POSITION(chk_path,
315 n_path_offset)) > 311 path_offset)) >
316 B_NR_ITEMS(p_s_parent)) 312 B_NR_ITEMS(parent))
317 return &MIN_KEY; 313 return &MIN_KEY;
318 /* Check whether parent at the path really points to the child. */ 314 /* Check whether parent at the path really points to the child. */
319 if (B_N_CHILD_NUM(p_s_parent, n_position) != 315 if (B_N_CHILD_NUM(parent, position) !=
320 PATH_OFFSET_PBUFFER(p_s_chk_path, 316 PATH_OFFSET_PBUFFER(chk_path,
321 n_path_offset + 1)->b_blocknr) 317 path_offset + 1)->b_blocknr)
322 return &MIN_KEY; 318 return &MIN_KEY;
323 /* Return delimiting key if position in the parent is not the last one. */ 319 /* Return delimiting key if position in the parent is not the last one. */
324 if (n_position != B_NR_ITEMS(p_s_parent)) 320 if (position != B_NR_ITEMS(parent))
325 return B_N_PDELIM_KEY(p_s_parent, n_position); 321 return B_N_PDELIM_KEY(parent, position);
326 } 322 }
327 /* Return MAX_KEY if we are in the root of the buffer tree. */ 323 /* Return MAX_KEY if we are in the root of the buffer tree. */
328 if (PATH_OFFSET_PBUFFER(p_s_chk_path, FIRST_PATH_ELEMENT_OFFSET)-> 324 if (PATH_OFFSET_PBUFFER(chk_path, FIRST_PATH_ELEMENT_OFFSET)->
329 b_blocknr == SB_ROOT_BLOCK(p_s_sb)) 325 b_blocknr == SB_ROOT_BLOCK(sb))
330 return &MAX_KEY; 326 return &MAX_KEY;
331 return &MIN_KEY; 327 return &MIN_KEY;
332} 328}
@@ -336,60 +332,29 @@ inline const struct reiserfs_key *get_rkey(const struct treepath *p_s_chk_path,
336 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the 332 the path. These delimiting keys are stored at least one level above that buffer in the tree. If the
337 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in 333 buffer is the first or last node in the tree order then one of the delimiting keys may be absent, and in
338 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */ 334 this case get_lkey and get_rkey return a special key which is MIN_KEY or MAX_KEY. */
339static inline int key_in_buffer(struct treepath *p_s_chk_path, /* Path which should be checked. */ 335static inline int key_in_buffer(struct treepath *chk_path, /* Path which should be checked. */
340 const struct cpu_key *p_s_key, /* Key which should be checked. */ 336 const struct cpu_key *key, /* Key which should be checked. */
341 struct super_block *p_s_sb /* Super block pointer. */ 337 struct super_block *sb
342 ) 338 )
343{ 339{
344 340
345 RFALSE(!p_s_key || p_s_chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET 341 RFALSE(!key || chk_path->path_length < FIRST_PATH_ELEMENT_OFFSET
346 || p_s_chk_path->path_length > MAX_HEIGHT, 342 || chk_path->path_length > MAX_HEIGHT,
347 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)", 343 "PAP-5050: pointer to the key(%p) is NULL or invalid path length(%d)",
348 p_s_key, p_s_chk_path->path_length); 344 key, chk_path->path_length);
349 RFALSE(!PATH_PLAST_BUFFER(p_s_chk_path)->b_bdev, 345 RFALSE(!PATH_PLAST_BUFFER(chk_path)->b_bdev,
350 "PAP-5060: device must not be NODEV"); 346 "PAP-5060: device must not be NODEV");
351 347
352 if (comp_keys(get_lkey(p_s_chk_path, p_s_sb), p_s_key) == 1) 348 if (comp_keys(get_lkey(chk_path, sb), key) == 1)
353 /* left delimiting key is bigger, that the key we look for */ 349 /* left delimiting key is bigger, that the key we look for */
354 return 0; 350 return 0;
355 // if ( comp_keys(p_s_key, get_rkey(p_s_chk_path, p_s_sb)) != -1 ) 351 /* if ( comp_keys(key, get_rkey(chk_path, sb)) != -1 ) */
356 if (comp_keys(get_rkey(p_s_chk_path, p_s_sb), p_s_key) != 1) 352 if (comp_keys(get_rkey(chk_path, sb), key) != 1)
357 /* p_s_key must be less than right delimitiing key */ 353 /* key must be less than right delimitiing key */
358 return 0; 354 return 0;
359 return 1; 355 return 1;
360} 356}
361 357
362inline void decrement_bcount(struct buffer_head *p_s_bh)
363{
364 if (p_s_bh) {
365 if (atomic_read(&(p_s_bh->b_count))) {
366 put_bh(p_s_bh);
367 return;
368 }
369 reiserfs_panic(NULL,
370 "PAP-5070: decrement_bcount: trying to free free buffer %b",
371 p_s_bh);
372 }
373}
374
375/* Decrement b_count field of the all buffers in the path. */
376void decrement_counters_in_path(struct treepath *p_s_search_path)
377{
378 int n_path_offset = p_s_search_path->path_length;
379
380 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET ||
381 n_path_offset > EXTENDED_MAX_HEIGHT - 1,
382 "PAP-5080: invalid path offset of %d", n_path_offset);
383
384 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
385 struct buffer_head *bh;
386
387 bh = PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--);
388 decrement_bcount(bh);
389 }
390 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
391}
392
393int reiserfs_check_path(struct treepath *p) 358int reiserfs_check_path(struct treepath *p)
394{ 359{
395 RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET, 360 RFALSE(p->path_length != ILLEGAL_PATH_ELEMENT_OFFSET,
@@ -397,40 +362,38 @@ int reiserfs_check_path(struct treepath *p)
397 return 0; 362 return 0;
398} 363}
399 364
400/* Release all buffers in the path. Restore dirty bits clean 365/* Drop the reference to each buffer in a path and restore
401** when preparing the buffer for the log 366 * dirty bits clean when preparing the buffer for the log.
402** 367 * This version should only be called from fix_nodes() */
403** only called from fix_nodes() 368void pathrelse_and_restore(struct super_block *sb,
404*/ 369 struct treepath *search_path)
405void pathrelse_and_restore(struct super_block *s, struct treepath *p_s_search_path)
406{ 370{
407 int n_path_offset = p_s_search_path->path_length; 371 int path_offset = search_path->path_length;
408 372
409 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 373 RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
410 "clm-4000: invalid path offset"); 374 "clm-4000: invalid path offset");
411 375
412 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) { 376 while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) {
413 reiserfs_restore_prepared_buffer(s, 377 struct buffer_head *bh;
414 PATH_OFFSET_PBUFFER 378 bh = PATH_OFFSET_PBUFFER(search_path, path_offset--);
415 (p_s_search_path, 379 reiserfs_restore_prepared_buffer(sb, bh);
416 n_path_offset)); 380 brelse(bh);
417 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--));
418 } 381 }
419 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 382 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
420} 383}
421 384
422/* Release all buffers in the path. */ 385/* Drop the reference to each buffer in a path */
423void pathrelse(struct treepath *p_s_search_path) 386void pathrelse(struct treepath *search_path)
424{ 387{
425 int n_path_offset = p_s_search_path->path_length; 388 int path_offset = search_path->path_length;
426 389
427 RFALSE(n_path_offset < ILLEGAL_PATH_ELEMENT_OFFSET, 390 RFALSE(path_offset < ILLEGAL_PATH_ELEMENT_OFFSET,
428 "PAP-5090: invalid path offset"); 391 "PAP-5090: invalid path offset");
429 392
430 while (n_path_offset > ILLEGAL_PATH_ELEMENT_OFFSET) 393 while (path_offset > ILLEGAL_PATH_ELEMENT_OFFSET)
431 brelse(PATH_OFFSET_PBUFFER(p_s_search_path, n_path_offset--)); 394 brelse(PATH_OFFSET_PBUFFER(search_path, path_offset--));
432 395
433 p_s_search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET; 396 search_path->path_length = ILLEGAL_PATH_ELEMENT_OFFSET;
434} 397}
435 398
436static int is_leaf(char *buf, int blocksize, struct buffer_head *bh) 399static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
@@ -444,23 +407,24 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
444 407
445 blkh = (struct block_head *)buf; 408 blkh = (struct block_head *)buf;
446 if (blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) { 409 if (blkh_level(blkh) != DISK_LEAF_NODE_LEVEL) {
447 reiserfs_warning(NULL, 410 reiserfs_warning(NULL, "reiserfs-5080",
448 "is_leaf: this should be caught earlier"); 411 "this should be caught earlier");
449 return 0; 412 return 0;
450 } 413 }
451 414
452 nr = blkh_nr_item(blkh); 415 nr = blkh_nr_item(blkh);
453 if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) { 416 if (nr < 1 || nr > ((blocksize - BLKH_SIZE) / (IH_SIZE + MIN_ITEM_LEN))) {
454 /* item number is too big or too small */ 417 /* item number is too big or too small */
455 reiserfs_warning(NULL, "is_leaf: nr_item seems wrong: %z", bh); 418 reiserfs_warning(NULL, "reiserfs-5081",
419 "nr_item seems wrong: %z", bh);
456 return 0; 420 return 0;
457 } 421 }
458 ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1; 422 ih = (struct item_head *)(buf + BLKH_SIZE) + nr - 1;
459 used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih)); 423 used_space = BLKH_SIZE + IH_SIZE * nr + (blocksize - ih_location(ih));
460 if (used_space != blocksize - blkh_free_space(blkh)) { 424 if (used_space != blocksize - blkh_free_space(blkh)) {
461 /* free space does not match to calculated amount of use space */ 425 /* free space does not match to calculated amount of use space */
462 reiserfs_warning(NULL, "is_leaf: free space seems wrong: %z", 426 reiserfs_warning(NULL, "reiserfs-5082",
463 bh); 427 "free space seems wrong: %z", bh);
464 return 0; 428 return 0;
465 } 429 }
466 // FIXME: it is_leaf will hit performance too much - we may have 430 // FIXME: it is_leaf will hit performance too much - we may have
@@ -471,29 +435,29 @@ static int is_leaf(char *buf, int blocksize, struct buffer_head *bh)
471 prev_location = blocksize; 435 prev_location = blocksize;
472 for (i = 0; i < nr; i++, ih++) { 436 for (i = 0; i < nr; i++, ih++) {
473 if (le_ih_k_type(ih) == TYPE_ANY) { 437 if (le_ih_k_type(ih) == TYPE_ANY) {
474 reiserfs_warning(NULL, 438 reiserfs_warning(NULL, "reiserfs-5083",
475 "is_leaf: wrong item type for item %h", 439 "wrong item type for item %h",
476 ih); 440 ih);
477 return 0; 441 return 0;
478 } 442 }
479 if (ih_location(ih) >= blocksize 443 if (ih_location(ih) >= blocksize
480 || ih_location(ih) < IH_SIZE * nr) { 444 || ih_location(ih) < IH_SIZE * nr) {
481 reiserfs_warning(NULL, 445 reiserfs_warning(NULL, "reiserfs-5084",
482 "is_leaf: item location seems wrong: %h", 446 "item location seems wrong: %h",
483 ih); 447 ih);
484 return 0; 448 return 0;
485 } 449 }
486 if (ih_item_len(ih) < 1 450 if (ih_item_len(ih) < 1
487 || ih_item_len(ih) > MAX_ITEM_LEN(blocksize)) { 451 || ih_item_len(ih) > MAX_ITEM_LEN(blocksize)) {
488 reiserfs_warning(NULL, 452 reiserfs_warning(NULL, "reiserfs-5085",
489 "is_leaf: item length seems wrong: %h", 453 "item length seems wrong: %h",
490 ih); 454 ih);
491 return 0; 455 return 0;
492 } 456 }
493 if (prev_location - ih_location(ih) != ih_item_len(ih)) { 457 if (prev_location - ih_location(ih) != ih_item_len(ih)) {
494 reiserfs_warning(NULL, 458 reiserfs_warning(NULL, "reiserfs-5086",
495 "is_leaf: item location seems wrong (second one): %h", 459 "item location seems wrong "
496 ih); 460 "(second one): %h", ih);
497 return 0; 461 return 0;
498 } 462 }
499 prev_location = ih_location(ih); 463 prev_location = ih_location(ih);
@@ -514,24 +478,23 @@ static int is_internal(char *buf, int blocksize, struct buffer_head *bh)
514 nr = blkh_level(blkh); 478 nr = blkh_level(blkh);
515 if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) { 479 if (nr <= DISK_LEAF_NODE_LEVEL || nr > MAX_HEIGHT) {
516 /* this level is not possible for internal nodes */ 480 /* this level is not possible for internal nodes */
517 reiserfs_warning(NULL, 481 reiserfs_warning(NULL, "reiserfs-5087",
518 "is_internal: this should be caught earlier"); 482 "this should be caught earlier");
519 return 0; 483 return 0;
520 } 484 }
521 485
522 nr = blkh_nr_item(blkh); 486 nr = blkh_nr_item(blkh);
523 if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) { 487 if (nr > (blocksize - BLKH_SIZE - DC_SIZE) / (KEY_SIZE + DC_SIZE)) {
524 /* for internal which is not root we might check min number of keys */ 488 /* for internal which is not root we might check min number of keys */
525 reiserfs_warning(NULL, 489 reiserfs_warning(NULL, "reiserfs-5088",
526 "is_internal: number of key seems wrong: %z", 490 "number of key seems wrong: %z", bh);
527 bh);
528 return 0; 491 return 0;
529 } 492 }
530 493
531 used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1); 494 used_space = BLKH_SIZE + KEY_SIZE * nr + DC_SIZE * (nr + 1);
532 if (used_space != blocksize - blkh_free_space(blkh)) { 495 if (used_space != blocksize - blkh_free_space(blkh)) {
533 reiserfs_warning(NULL, 496 reiserfs_warning(NULL, "reiserfs-5089",
534 "is_internal: free space seems wrong: %z", bh); 497 "free space seems wrong: %z", bh);
535 return 0; 498 return 0;
536 } 499 }
537 // one may imagine much more checks 500 // one may imagine much more checks
@@ -543,8 +506,8 @@ static int is_internal(char *buf, int blocksize, struct buffer_head *bh)
543static int is_tree_node(struct buffer_head *bh, int level) 506static int is_tree_node(struct buffer_head *bh, int level)
544{ 507{
545 if (B_LEVEL(bh) != level) { 508 if (B_LEVEL(bh) != level) {
546 reiserfs_warning(NULL, 509 reiserfs_warning(NULL, "reiserfs-5090", "node level %d does "
547 "is_tree_node: node level %d does not match to the expected one %d", 510 "not match to the expected one %d",
548 B_LEVEL(bh), level); 511 B_LEVEL(bh), level);
549 return 0; 512 return 0;
550 } 513 }
@@ -580,10 +543,10 @@ static void search_by_key_reada(struct super_block *s,
580/************************************************************************** 543/**************************************************************************
581 * Algorithm SearchByKey * 544 * Algorithm SearchByKey *
582 * look for item in the Disk S+Tree by its key * 545 * look for item in the Disk S+Tree by its key *
583 * Input: p_s_sb - super block * 546 * Input: sb - super block *
584 * p_s_key - pointer to the key to search * 547 * key - pointer to the key to search *
585 * Output: ITEM_FOUND, ITEM_NOT_FOUND or IO_ERROR * 548 * Output: ITEM_FOUND, ITEM_NOT_FOUND or IO_ERROR *
586 * p_s_search_path - path from the root to the needed leaf * 549 * search_path - path from the root to the needed leaf *
587 **************************************************************************/ 550 **************************************************************************/
588 551
589/* This function fills up the path from the root to the leaf as it 552/* This function fills up the path from the root to the leaf as it
@@ -600,22 +563,22 @@ static void search_by_key_reada(struct super_block *s,
600 correctness of the top of the path but need not be checked for the 563 correctness of the top of the path but need not be checked for the
601 correctness of the bottom of the path */ 564 correctness of the bottom of the path */
602/* The function is NOT SCHEDULE-SAFE! */ 565/* The function is NOT SCHEDULE-SAFE! */
603int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /* Key to search. */ 566int search_by_key(struct super_block *sb, const struct cpu_key *key, /* Key to search. */
604 struct treepath *p_s_search_path,/* This structure was 567 struct treepath *search_path,/* This structure was
605 allocated and initialized 568 allocated and initialized
606 by the calling 569 by the calling
607 function. It is filled up 570 function. It is filled up
608 by this function. */ 571 by this function. */
609 int n_stop_level /* How far down the tree to search. To 572 int stop_level /* How far down the tree to search. To
610 stop at leaf level - set to 573 stop at leaf level - set to
611 DISK_LEAF_NODE_LEVEL */ 574 DISK_LEAF_NODE_LEVEL */
612 ) 575 )
613{ 576{
614 b_blocknr_t n_block_number; 577 b_blocknr_t block_number;
615 int expected_level; 578 int expected_level;
616 struct buffer_head *p_s_bh; 579 struct buffer_head *bh;
617 struct path_element *p_s_last_element; 580 struct path_element *last_element;
618 int n_node_level, n_retval; 581 int node_level, retval;
619 int right_neighbor_of_leaf_node; 582 int right_neighbor_of_leaf_node;
620 int fs_gen; 583 int fs_gen;
621 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA]; 584 struct buffer_head *reada_bh[SEARCH_BY_KEY_READA];
@@ -623,80 +586,79 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
623 int reada_count = 0; 586 int reada_count = 0;
624 587
625#ifdef CONFIG_REISERFS_CHECK 588#ifdef CONFIG_REISERFS_CHECK
626 int n_repeat_counter = 0; 589 int repeat_counter = 0;
627#endif 590#endif
628 591
629 PROC_INFO_INC(p_s_sb, search_by_key); 592 PROC_INFO_INC(sb, search_by_key);
630 593
631 /* As we add each node to a path we increase its count. This means that 594 /* As we add each node to a path we increase its count. This means that
632 we must be careful to release all nodes in a path before we either 595 we must be careful to release all nodes in a path before we either
633 discard the path struct or re-use the path struct, as we do here. */ 596 discard the path struct or re-use the path struct, as we do here. */
634 597
635 decrement_counters_in_path(p_s_search_path); 598 pathrelse(search_path);
636 599
637 right_neighbor_of_leaf_node = 0; 600 right_neighbor_of_leaf_node = 0;
638 601
639 /* With each iteration of this loop we search through the items in the 602 /* With each iteration of this loop we search through the items in the
640 current node, and calculate the next current node(next path element) 603 current node, and calculate the next current node(next path element)
641 for the next iteration of this loop.. */ 604 for the next iteration of this loop.. */
642 n_block_number = SB_ROOT_BLOCK(p_s_sb); 605 block_number = SB_ROOT_BLOCK(sb);
643 expected_level = -1; 606 expected_level = -1;
644 while (1) { 607 while (1) {
645 608
646#ifdef CONFIG_REISERFS_CHECK 609#ifdef CONFIG_REISERFS_CHECK
647 if (!(++n_repeat_counter % 50000)) 610 if (!(++repeat_counter % 50000))
648 reiserfs_warning(p_s_sb, "PAP-5100: search_by_key: %s:" 611 reiserfs_warning(sb, "PAP-5100",
649 "there were %d iterations of while loop " 612 "%s: there were %d iterations of "
650 "looking for key %K", 613 "while loop looking for key %K",
651 current->comm, n_repeat_counter, 614 current->comm, repeat_counter,
652 p_s_key); 615 key);
653#endif 616#endif
654 617
655 /* prep path to have another element added to it. */ 618 /* prep path to have another element added to it. */
656 p_s_last_element = 619 last_element =
657 PATH_OFFSET_PELEMENT(p_s_search_path, 620 PATH_OFFSET_PELEMENT(search_path,
658 ++p_s_search_path->path_length); 621 ++search_path->path_length);
659 fs_gen = get_generation(p_s_sb); 622 fs_gen = get_generation(sb);
660 623
661 /* Read the next tree node, and set the last element in the path to 624 /* Read the next tree node, and set the last element in the path to
662 have a pointer to it. */ 625 have a pointer to it. */
663 if ((p_s_bh = p_s_last_element->pe_buffer = 626 if ((bh = last_element->pe_buffer =
664 sb_getblk(p_s_sb, n_block_number))) { 627 sb_getblk(sb, block_number))) {
665 if (!buffer_uptodate(p_s_bh) && reada_count > 1) { 628 if (!buffer_uptodate(bh) && reada_count > 1)
666 search_by_key_reada(p_s_sb, reada_bh, 629 search_by_key_reada(sb, reada_bh,
667 reada_blocks, reada_count); 630 reada_blocks, reada_count);
668 } 631 ll_rw_block(READ, 1, &bh);
669 ll_rw_block(READ, 1, &p_s_bh); 632 wait_on_buffer(bh);
670 wait_on_buffer(p_s_bh); 633 if (!buffer_uptodate(bh))
671 if (!buffer_uptodate(p_s_bh))
672 goto io_error; 634 goto io_error;
673 } else { 635 } else {
674 io_error: 636 io_error:
675 p_s_search_path->path_length--; 637 search_path->path_length--;
676 pathrelse(p_s_search_path); 638 pathrelse(search_path);
677 return IO_ERROR; 639 return IO_ERROR;
678 } 640 }
679 reada_count = 0; 641 reada_count = 0;
680 if (expected_level == -1) 642 if (expected_level == -1)
681 expected_level = SB_TREE_HEIGHT(p_s_sb); 643 expected_level = SB_TREE_HEIGHT(sb);
682 expected_level--; 644 expected_level--;
683 645
684 /* It is possible that schedule occurred. We must check whether the key 646 /* It is possible that schedule occurred. We must check whether the key
685 to search is still in the tree rooted from the current buffer. If 647 to search is still in the tree rooted from the current buffer. If
686 not then repeat search from the root. */ 648 not then repeat search from the root. */
687 if (fs_changed(fs_gen, p_s_sb) && 649 if (fs_changed(fs_gen, sb) &&
688 (!B_IS_IN_TREE(p_s_bh) || 650 (!B_IS_IN_TREE(bh) ||
689 B_LEVEL(p_s_bh) != expected_level || 651 B_LEVEL(bh) != expected_level ||
690 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb))) { 652 !key_in_buffer(search_path, key, sb))) {
691 PROC_INFO_INC(p_s_sb, search_by_key_fs_changed); 653 PROC_INFO_INC(sb, search_by_key_fs_changed);
692 PROC_INFO_INC(p_s_sb, search_by_key_restarted); 654 PROC_INFO_INC(sb, search_by_key_restarted);
693 PROC_INFO_INC(p_s_sb, 655 PROC_INFO_INC(sb,
694 sbk_restarted[expected_level - 1]); 656 sbk_restarted[expected_level - 1]);
695 decrement_counters_in_path(p_s_search_path); 657 pathrelse(search_path);
696 658
697 /* Get the root block number so that we can repeat the search 659 /* Get the root block number so that we can repeat the search
698 starting from the root. */ 660 starting from the root. */
699 n_block_number = SB_ROOT_BLOCK(p_s_sb); 661 block_number = SB_ROOT_BLOCK(sb);
700 expected_level = -1; 662 expected_level = -1;
701 right_neighbor_of_leaf_node = 0; 663 right_neighbor_of_leaf_node = 0;
702 664
@@ -704,53 +666,53 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
704 continue; 666 continue;
705 } 667 }
706 668
707 /* only check that the key is in the buffer if p_s_key is not 669 /* only check that the key is in the buffer if key is not
708 equal to the MAX_KEY. Latter case is only possible in 670 equal to the MAX_KEY. Latter case is only possible in
709 "finish_unfinished()" processing during mount. */ 671 "finish_unfinished()" processing during mount. */
710 RFALSE(comp_keys(&MAX_KEY, p_s_key) && 672 RFALSE(comp_keys(&MAX_KEY, key) &&
711 !key_in_buffer(p_s_search_path, p_s_key, p_s_sb), 673 !key_in_buffer(search_path, key, sb),
712 "PAP-5130: key is not in the buffer"); 674 "PAP-5130: key is not in the buffer");
713#ifdef CONFIG_REISERFS_CHECK 675#ifdef CONFIG_REISERFS_CHECK
714 if (cur_tb) { 676 if (cur_tb) {
715 print_cur_tb("5140"); 677 print_cur_tb("5140");
716 reiserfs_panic(p_s_sb, 678 reiserfs_panic(sb, "PAP-5140",
717 "PAP-5140: search_by_key: schedule occurred in do_balance!"); 679 "schedule occurred in do_balance!");
718 } 680 }
719#endif 681#endif
720 682
721 // make sure, that the node contents look like a node of 683 // make sure, that the node contents look like a node of
722 // certain level 684 // certain level
723 if (!is_tree_node(p_s_bh, expected_level)) { 685 if (!is_tree_node(bh, expected_level)) {
724 reiserfs_warning(p_s_sb, "vs-5150: search_by_key: " 686 reiserfs_error(sb, "vs-5150",
725 "invalid format found in block %ld. Fsck?", 687 "invalid format found in block %ld. "
726 p_s_bh->b_blocknr); 688 "Fsck?", bh->b_blocknr);
727 pathrelse(p_s_search_path); 689 pathrelse(search_path);
728 return IO_ERROR; 690 return IO_ERROR;
729 } 691 }
730 692
731 /* ok, we have acquired next formatted node in the tree */ 693 /* ok, we have acquired next formatted node in the tree */
732 n_node_level = B_LEVEL(p_s_bh); 694 node_level = B_LEVEL(bh);
733 695
734 PROC_INFO_BH_STAT(p_s_sb, p_s_bh, n_node_level - 1); 696 PROC_INFO_BH_STAT(sb, bh, node_level - 1);
735 697
736 RFALSE(n_node_level < n_stop_level, 698 RFALSE(node_level < stop_level,
737 "vs-5152: tree level (%d) is less than stop level (%d)", 699 "vs-5152: tree level (%d) is less than stop level (%d)",
738 n_node_level, n_stop_level); 700 node_level, stop_level);
739 701
740 n_retval = bin_search(p_s_key, B_N_PITEM_HEAD(p_s_bh, 0), 702 retval = bin_search(key, B_N_PITEM_HEAD(bh, 0),
741 B_NR_ITEMS(p_s_bh), 703 B_NR_ITEMS(bh),
742 (n_node_level == 704 (node_level ==
743 DISK_LEAF_NODE_LEVEL) ? IH_SIZE : 705 DISK_LEAF_NODE_LEVEL) ? IH_SIZE :
744 KEY_SIZE, 706 KEY_SIZE,
745 &(p_s_last_element->pe_position)); 707 &(last_element->pe_position));
746 if (n_node_level == n_stop_level) { 708 if (node_level == stop_level) {
747 return n_retval; 709 return retval;
748 } 710 }
749 711
750 /* we are not in the stop level */ 712 /* we are not in the stop level */
751 if (n_retval == ITEM_FOUND) 713 if (retval == ITEM_FOUND)
752 /* item has been found, so we choose the pointer which is to the right of the found one */ 714 /* item has been found, so we choose the pointer which is to the right of the found one */
753 p_s_last_element->pe_position++; 715 last_element->pe_position++;
754 716
755 /* if item was not found we choose the position which is to 717 /* if item was not found we choose the position which is to
756 the left of the found item. This requires no code, 718 the left of the found item. This requires no code,
@@ -759,24 +721,24 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
759 /* So we have chosen a position in the current node which is 721 /* So we have chosen a position in the current node which is
760 an internal node. Now we calculate child block number by 722 an internal node. Now we calculate child block number by
761 position in the node. */ 723 position in the node. */
762 n_block_number = 724 block_number =
763 B_N_CHILD_NUM(p_s_bh, p_s_last_element->pe_position); 725 B_N_CHILD_NUM(bh, last_element->pe_position);
764 726
765 /* if we are going to read leaf nodes, try for read ahead as well */ 727 /* if we are going to read leaf nodes, try for read ahead as well */
766 if ((p_s_search_path->reada & PATH_READA) && 728 if ((search_path->reada & PATH_READA) &&
767 n_node_level == DISK_LEAF_NODE_LEVEL + 1) { 729 node_level == DISK_LEAF_NODE_LEVEL + 1) {
768 int pos = p_s_last_element->pe_position; 730 int pos = last_element->pe_position;
769 int limit = B_NR_ITEMS(p_s_bh); 731 int limit = B_NR_ITEMS(bh);
770 struct reiserfs_key *le_key; 732 struct reiserfs_key *le_key;
771 733
772 if (p_s_search_path->reada & PATH_READA_BACK) 734 if (search_path->reada & PATH_READA_BACK)
773 limit = 0; 735 limit = 0;
774 while (reada_count < SEARCH_BY_KEY_READA) { 736 while (reada_count < SEARCH_BY_KEY_READA) {
775 if (pos == limit) 737 if (pos == limit)
776 break; 738 break;
777 reada_blocks[reada_count++] = 739 reada_blocks[reada_count++] =
778 B_N_CHILD_NUM(p_s_bh, pos); 740 B_N_CHILD_NUM(bh, pos);
779 if (p_s_search_path->reada & PATH_READA_BACK) 741 if (search_path->reada & PATH_READA_BACK)
780 pos--; 742 pos--;
781 else 743 else
782 pos++; 744 pos++;
@@ -784,9 +746,9 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
784 /* 746 /*
785 * check to make sure we're in the same object 747 * check to make sure we're in the same object
786 */ 748 */
787 le_key = B_N_PDELIM_KEY(p_s_bh, pos); 749 le_key = B_N_PDELIM_KEY(bh, pos);
788 if (le32_to_cpu(le_key->k_objectid) != 750 if (le32_to_cpu(le_key->k_objectid) !=
789 p_s_key->on_disk_key.k_objectid) { 751 key->on_disk_key.k_objectid) {
790 break; 752 break;
791 } 753 }
792 } 754 }
@@ -795,11 +757,11 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
795} 757}
796 758
797/* Form the path to an item and position in this item which contains 759/* Form the path to an item and position in this item which contains
798 file byte defined by p_s_key. If there is no such item 760 file byte defined by key. If there is no such item
799 corresponding to the key, we point the path to the item with 761 corresponding to the key, we point the path to the item with
800 maximal key less than p_s_key, and *p_n_pos_in_item is set to one 762 maximal key less than key, and *pos_in_item is set to one
801 past the last entry/byte in the item. If searching for entry in a 763 past the last entry/byte in the item. If searching for entry in a
802 directory item, and it is not found, *p_n_pos_in_item is set to one 764 directory item, and it is not found, *pos_in_item is set to one
803 entry more than the entry with maximal key which is less than the 765 entry more than the entry with maximal key which is less than the
804 sought key. 766 sought key.
805 767
@@ -810,48 +772,48 @@ int search_by_key(struct super_block *p_s_sb, const struct cpu_key *p_s_key, /*
810 units of directory entries. */ 772 units of directory entries. */
811 773
812/* The function is NOT SCHEDULE-SAFE! */ 774/* The function is NOT SCHEDULE-SAFE! */
813int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the super block. */ 775int search_for_position_by_key(struct super_block *sb, /* Pointer to the super block. */
814 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */ 776 const struct cpu_key *p_cpu_key, /* Key to search (cpu variable) */
815 struct treepath *p_s_search_path /* Filled up by this function. */ 777 struct treepath *search_path /* Filled up by this function. */
816 ) 778 )
817{ 779{
818 struct item_head *p_le_ih; /* pointer to on-disk structure */ 780 struct item_head *p_le_ih; /* pointer to on-disk structure */
819 int n_blk_size; 781 int blk_size;
820 loff_t item_offset, offset; 782 loff_t item_offset, offset;
821 struct reiserfs_dir_entry de; 783 struct reiserfs_dir_entry de;
822 int retval; 784 int retval;
823 785
824 /* If searching for directory entry. */ 786 /* If searching for directory entry. */
825 if (is_direntry_cpu_key(p_cpu_key)) 787 if (is_direntry_cpu_key(p_cpu_key))
826 return search_by_entry_key(p_s_sb, p_cpu_key, p_s_search_path, 788 return search_by_entry_key(sb, p_cpu_key, search_path,
827 &de); 789 &de);
828 790
829 /* If not searching for directory entry. */ 791 /* If not searching for directory entry. */
830 792
831 /* If item is found. */ 793 /* If item is found. */
832 retval = search_item(p_s_sb, p_cpu_key, p_s_search_path); 794 retval = search_item(sb, p_cpu_key, search_path);
833 if (retval == IO_ERROR) 795 if (retval == IO_ERROR)
834 return retval; 796 return retval;
835 if (retval == ITEM_FOUND) { 797 if (retval == ITEM_FOUND) {
836 798
837 RFALSE(!ih_item_len 799 RFALSE(!ih_item_len
838 (B_N_PITEM_HEAD 800 (B_N_PITEM_HEAD
839 (PATH_PLAST_BUFFER(p_s_search_path), 801 (PATH_PLAST_BUFFER(search_path),
840 PATH_LAST_POSITION(p_s_search_path))), 802 PATH_LAST_POSITION(search_path))),
841 "PAP-5165: item length equals zero"); 803 "PAP-5165: item length equals zero");
842 804
843 pos_in_item(p_s_search_path) = 0; 805 pos_in_item(search_path) = 0;
844 return POSITION_FOUND; 806 return POSITION_FOUND;
845 } 807 }
846 808
847 RFALSE(!PATH_LAST_POSITION(p_s_search_path), 809 RFALSE(!PATH_LAST_POSITION(search_path),
848 "PAP-5170: position equals zero"); 810 "PAP-5170: position equals zero");
849 811
850 /* Item is not found. Set path to the previous item. */ 812 /* Item is not found. Set path to the previous item. */
851 p_le_ih = 813 p_le_ih =
852 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(p_s_search_path), 814 B_N_PITEM_HEAD(PATH_PLAST_BUFFER(search_path),
853 --PATH_LAST_POSITION(p_s_search_path)); 815 --PATH_LAST_POSITION(search_path));
854 n_blk_size = p_s_sb->s_blocksize; 816 blk_size = sb->s_blocksize;
855 817
856 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) { 818 if (comp_short_keys(&(p_le_ih->ih_key), p_cpu_key)) {
857 return FILE_NOT_FOUND; 819 return FILE_NOT_FOUND;
@@ -863,10 +825,10 @@ int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the sup
863 825
864 /* Needed byte is contained in the item pointed to by the path. */ 826 /* Needed byte is contained in the item pointed to by the path. */
865 if (item_offset <= offset && 827 if (item_offset <= offset &&
866 item_offset + op_bytes_number(p_le_ih, n_blk_size) > offset) { 828 item_offset + op_bytes_number(p_le_ih, blk_size) > offset) {
867 pos_in_item(p_s_search_path) = offset - item_offset; 829 pos_in_item(search_path) = offset - item_offset;
868 if (is_indirect_le_ih(p_le_ih)) { 830 if (is_indirect_le_ih(p_le_ih)) {
869 pos_in_item(p_s_search_path) /= n_blk_size; 831 pos_in_item(search_path) /= blk_size;
870 } 832 }
871 return POSITION_FOUND; 833 return POSITION_FOUND;
872 } 834 }
@@ -874,30 +836,30 @@ int search_for_position_by_key(struct super_block *p_s_sb, /* Pointer to the sup
874 /* Needed byte is not contained in the item pointed to by the 836 /* Needed byte is not contained in the item pointed to by the
875 path. Set pos_in_item out of the item. */ 837 path. Set pos_in_item out of the item. */
876 if (is_indirect_le_ih(p_le_ih)) 838 if (is_indirect_le_ih(p_le_ih))
877 pos_in_item(p_s_search_path) = 839 pos_in_item(search_path) =
878 ih_item_len(p_le_ih) / UNFM_P_SIZE; 840 ih_item_len(p_le_ih) / UNFM_P_SIZE;
879 else 841 else
880 pos_in_item(p_s_search_path) = ih_item_len(p_le_ih); 842 pos_in_item(search_path) = ih_item_len(p_le_ih);
881 843
882 return POSITION_NOT_FOUND; 844 return POSITION_NOT_FOUND;
883} 845}
884 846
885/* Compare given item and item pointed to by the path. */ 847/* Compare given item and item pointed to by the path. */
886int comp_items(const struct item_head *stored_ih, const struct treepath *p_s_path) 848int comp_items(const struct item_head *stored_ih, const struct treepath *path)
887{ 849{
888 struct buffer_head *p_s_bh; 850 struct buffer_head *bh = PATH_PLAST_BUFFER(path);
889 struct item_head *ih; 851 struct item_head *ih;
890 852
891 /* Last buffer at the path is not in the tree. */ 853 /* Last buffer at the path is not in the tree. */
892 if (!B_IS_IN_TREE(p_s_bh = PATH_PLAST_BUFFER(p_s_path))) 854 if (!B_IS_IN_TREE(bh))
893 return 1; 855 return 1;
894 856
895 /* Last path position is invalid. */ 857 /* Last path position is invalid. */
896 if (PATH_LAST_POSITION(p_s_path) >= B_NR_ITEMS(p_s_bh)) 858 if (PATH_LAST_POSITION(path) >= B_NR_ITEMS(bh))
897 return 1; 859 return 1;
898 860
899 /* we need only to know, whether it is the same item */ 861 /* we need only to know, whether it is the same item */
900 ih = get_ih(p_s_path); 862 ih = get_ih(path);
901 return memcmp(stored_ih, ih, IH_SIZE); 863 return memcmp(stored_ih, ih, IH_SIZE);
902} 864}
903 865
@@ -924,9 +886,9 @@ static inline int prepare_for_direct_item(struct treepath *path,
924 } 886 }
925 // new file gets truncated 887 // new file gets truncated
926 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) { 888 if (get_inode_item_key_version(inode) == KEY_FORMAT_3_6) {
927 // 889 //
928 round_len = ROUND_UP(new_file_length); 890 round_len = ROUND_UP(new_file_length);
929 /* this was n_new_file_length < le_ih ... */ 891 /* this was new_file_length < le_ih ... */
930 if (round_len < le_ih_k_offset(le_ih)) { 892 if (round_len < le_ih_k_offset(le_ih)) {
931 *cut_size = -(IH_SIZE + ih_item_len(le_ih)); 893 *cut_size = -(IH_SIZE + ih_item_len(le_ih));
932 return M_DELETE; /* Delete this item. */ 894 return M_DELETE; /* Delete this item. */
@@ -986,96 +948,95 @@ static inline int prepare_for_direntry_item(struct treepath *path,
986 In case of file truncate calculate whether this item must be deleted/truncated or last 948 In case of file truncate calculate whether this item must be deleted/truncated or last
987 unformatted node of this item will be converted to a direct item. 949 unformatted node of this item will be converted to a direct item.
988 This function returns a determination of what balance mode the calling function should employ. */ 950 This function returns a determination of what balance mode the calling function should employ. */
989static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *p_s_path, const struct cpu_key *p_s_item_key, int *p_n_removed, /* Number of unformatted nodes which were removed 951static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, struct inode *inode, struct treepath *path, const struct cpu_key *item_key, int *removed, /* Number of unformatted nodes which were removed
990 from end of the file. */ 952 from end of the file. */
991 int *p_n_cut_size, unsigned long long n_new_file_length /* MAX_KEY_OFFSET in case of delete. */ 953 int *cut_size, unsigned long long new_file_length /* MAX_KEY_OFFSET in case of delete. */
992 ) 954 )
993{ 955{
994 struct super_block *p_s_sb = inode->i_sb; 956 struct super_block *sb = inode->i_sb;
995 struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_path); 957 struct item_head *p_le_ih = PATH_PITEM_HEAD(path);
996 struct buffer_head *p_s_bh = PATH_PLAST_BUFFER(p_s_path); 958 struct buffer_head *bh = PATH_PLAST_BUFFER(path);
997 959
998 BUG_ON(!th->t_trans_id); 960 BUG_ON(!th->t_trans_id);
999 961
1000 /* Stat_data item. */ 962 /* Stat_data item. */
1001 if (is_statdata_le_ih(p_le_ih)) { 963 if (is_statdata_le_ih(p_le_ih)) {
1002 964
1003 RFALSE(n_new_file_length != max_reiserfs_offset(inode), 965 RFALSE(new_file_length != max_reiserfs_offset(inode),
1004 "PAP-5210: mode must be M_DELETE"); 966 "PAP-5210: mode must be M_DELETE");
1005 967
1006 *p_n_cut_size = -(IH_SIZE + ih_item_len(p_le_ih)); 968 *cut_size = -(IH_SIZE + ih_item_len(p_le_ih));
1007 return M_DELETE; 969 return M_DELETE;
1008 } 970 }
1009 971
1010 /* Directory item. */ 972 /* Directory item. */
1011 if (is_direntry_le_ih(p_le_ih)) 973 if (is_direntry_le_ih(p_le_ih))
1012 return prepare_for_direntry_item(p_s_path, p_le_ih, inode, 974 return prepare_for_direntry_item(path, p_le_ih, inode,
1013 n_new_file_length, 975 new_file_length,
1014 p_n_cut_size); 976 cut_size);
1015 977
1016 /* Direct item. */ 978 /* Direct item. */
1017 if (is_direct_le_ih(p_le_ih)) 979 if (is_direct_le_ih(p_le_ih))
1018 return prepare_for_direct_item(p_s_path, p_le_ih, inode, 980 return prepare_for_direct_item(path, p_le_ih, inode,
1019 n_new_file_length, p_n_cut_size); 981 new_file_length, cut_size);
1020 982
1021 /* Case of an indirect item. */ 983 /* Case of an indirect item. */
1022 { 984 {
1023 int blk_size = p_s_sb->s_blocksize; 985 int blk_size = sb->s_blocksize;
1024 struct item_head s_ih; 986 struct item_head s_ih;
1025 int need_re_search; 987 int need_re_search;
1026 int delete = 0; 988 int delete = 0;
1027 int result = M_CUT; 989 int result = M_CUT;
1028 int pos = 0; 990 int pos = 0;
1029 991
1030 if ( n_new_file_length == max_reiserfs_offset (inode) ) { 992 if ( new_file_length == max_reiserfs_offset (inode) ) {
1031 /* prepare_for_delete_or_cut() is called by 993 /* prepare_for_delete_or_cut() is called by
1032 * reiserfs_delete_item() */ 994 * reiserfs_delete_item() */
1033 n_new_file_length = 0; 995 new_file_length = 0;
1034 delete = 1; 996 delete = 1;
1035 } 997 }
1036 998
1037 do { 999 do {
1038 need_re_search = 0; 1000 need_re_search = 0;
1039 *p_n_cut_size = 0; 1001 *cut_size = 0;
1040 p_s_bh = PATH_PLAST_BUFFER(p_s_path); 1002 bh = PATH_PLAST_BUFFER(path);
1041 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 1003 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1042 pos = I_UNFM_NUM(&s_ih); 1004 pos = I_UNFM_NUM(&s_ih);
1043 1005
1044 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > n_new_file_length) { 1006 while (le_ih_k_offset (&s_ih) + (pos - 1) * blk_size > new_file_length) {
1045 __le32 *unfm; 1007 __le32 *unfm;
1046 __u32 block; 1008 __u32 block;
1047 1009
1048 /* Each unformatted block deletion may involve one additional 1010 /* Each unformatted block deletion may involve one additional
1049 * bitmap block into the transaction, thereby the initial 1011 * bitmap block into the transaction, thereby the initial
1050 * journal space reservation might not be enough. */ 1012 * journal space reservation might not be enough. */
1051 if (!delete && (*p_n_cut_size) != 0 && 1013 if (!delete && (*cut_size) != 0 &&
1052 reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { 1014 reiserfs_transaction_free_space(th) < JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD)
1053 break; 1015 break;
1054 }
1055 1016
1056 unfm = (__le32 *)B_I_PITEM(p_s_bh, &s_ih) + pos - 1; 1017 unfm = (__le32 *)B_I_PITEM(bh, &s_ih) + pos - 1;
1057 block = get_block_num(unfm, 0); 1018 block = get_block_num(unfm, 0);
1058 1019
1059 if (block != 0) { 1020 if (block != 0) {
1060 reiserfs_prepare_for_journal(p_s_sb, p_s_bh, 1); 1021 reiserfs_prepare_for_journal(sb, bh, 1);
1061 put_block_num(unfm, 0, 0); 1022 put_block_num(unfm, 0, 0);
1062 journal_mark_dirty (th, p_s_sb, p_s_bh); 1023 journal_mark_dirty(th, sb, bh);
1063 reiserfs_free_block(th, inode, block, 1); 1024 reiserfs_free_block(th, inode, block, 1);
1064 } 1025 }
1065 1026
1066 cond_resched(); 1027 cond_resched();
1067 1028
1068 if (item_moved (&s_ih, p_s_path)) { 1029 if (item_moved (&s_ih, path)) {
1069 need_re_search = 1; 1030 need_re_search = 1;
1070 break; 1031 break;
1071 } 1032 }
1072 1033
1073 pos --; 1034 pos --;
1074 (*p_n_removed) ++; 1035 (*removed)++;
1075 (*p_n_cut_size) -= UNFM_P_SIZE; 1036 (*cut_size) -= UNFM_P_SIZE;
1076 1037
1077 if (pos == 0) { 1038 if (pos == 0) {
1078 (*p_n_cut_size) -= IH_SIZE; 1039 (*cut_size) -= IH_SIZE;
1079 result = M_DELETE; 1040 result = M_DELETE;
1080 break; 1041 break;
1081 } 1042 }
@@ -1083,12 +1044,12 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1083 /* a trick. If the buffer has been logged, this will do nothing. If 1044 /* a trick. If the buffer has been logged, this will do nothing. If
1084 ** we've broken the loop without logging it, it will restore the 1045 ** we've broken the loop without logging it, it will restore the
1085 ** buffer */ 1046 ** buffer */
1086 reiserfs_restore_prepared_buffer(p_s_sb, p_s_bh); 1047 reiserfs_restore_prepared_buffer(sb, bh);
1087 } while (need_re_search && 1048 } while (need_re_search &&
1088 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path) == POSITION_FOUND); 1049 search_for_position_by_key(sb, item_key, path) == POSITION_FOUND);
1089 pos_in_item(p_s_path) = pos * UNFM_P_SIZE; 1050 pos_in_item(path) = pos * UNFM_P_SIZE;
1090 1051
1091 if (*p_n_cut_size == 0) { 1052 if (*cut_size == 0) {
1092 /* Nothing were cut. maybe convert last unformatted node to the 1053 /* Nothing were cut. maybe convert last unformatted node to the
1093 * direct item? */ 1054 * direct item? */
1094 result = M_CONVERT; 1055 result = M_CONVERT;
@@ -1098,45 +1059,45 @@ static char prepare_for_delete_or_cut(struct reiserfs_transaction_handle *th, st
1098} 1059}
1099 1060
1100/* Calculate number of bytes which will be deleted or cut during balance */ 1061/* Calculate number of bytes which will be deleted or cut during balance */
1101static int calc_deleted_bytes_number(struct tree_balance *p_s_tb, char c_mode) 1062static int calc_deleted_bytes_number(struct tree_balance *tb, char mode)
1102{ 1063{
1103 int n_del_size; 1064 int del_size;
1104 struct item_head *p_le_ih = PATH_PITEM_HEAD(p_s_tb->tb_path); 1065 struct item_head *p_le_ih = PATH_PITEM_HEAD(tb->tb_path);
1105 1066
1106 if (is_statdata_le_ih(p_le_ih)) 1067 if (is_statdata_le_ih(p_le_ih))
1107 return 0; 1068 return 0;
1108 1069
1109 n_del_size = 1070 del_size =
1110 (c_mode == 1071 (mode ==
1111 M_DELETE) ? ih_item_len(p_le_ih) : -p_s_tb->insert_size[0]; 1072 M_DELETE) ? ih_item_len(p_le_ih) : -tb->insert_size[0];
1112 if (is_direntry_le_ih(p_le_ih)) { 1073 if (is_direntry_le_ih(p_le_ih)) {
1113 // return EMPTY_DIR_SIZE; /* We delete emty directoris only. */ 1074 /* return EMPTY_DIR_SIZE; We delete emty directoris only.
1114 // we can't use EMPTY_DIR_SIZE, as old format dirs have a different 1075 * we can't use EMPTY_DIR_SIZE, as old format dirs have a different
1115 // empty size. ick. FIXME, is this right? 1076 * empty size. ick. FIXME, is this right? */
1116 // 1077 return del_size;
1117 return n_del_size;
1118 } 1078 }
1119 1079
1120 if (is_indirect_le_ih(p_le_ih)) 1080 if (is_indirect_le_ih(p_le_ih))
1121 n_del_size = (n_del_size / UNFM_P_SIZE) * (PATH_PLAST_BUFFER(p_s_tb->tb_path)->b_size); // - get_ih_free_space (p_le_ih); 1081 del_size = (del_size / UNFM_P_SIZE) *
1122 return n_del_size; 1082 (PATH_PLAST_BUFFER(tb->tb_path)->b_size);
1083 return del_size;
1123} 1084}
1124 1085
1125static void init_tb_struct(struct reiserfs_transaction_handle *th, 1086static void init_tb_struct(struct reiserfs_transaction_handle *th,
1126 struct tree_balance *p_s_tb, 1087 struct tree_balance *tb,
1127 struct super_block *p_s_sb, 1088 struct super_block *sb,
1128 struct treepath *p_s_path, int n_size) 1089 struct treepath *path, int size)
1129{ 1090{
1130 1091
1131 BUG_ON(!th->t_trans_id); 1092 BUG_ON(!th->t_trans_id);
1132 1093
1133 memset(p_s_tb, '\0', sizeof(struct tree_balance)); 1094 memset(tb, '\0', sizeof(struct tree_balance));
1134 p_s_tb->transaction_handle = th; 1095 tb->transaction_handle = th;
1135 p_s_tb->tb_sb = p_s_sb; 1096 tb->tb_sb = sb;
1136 p_s_tb->tb_path = p_s_path; 1097 tb->tb_path = path;
1137 PATH_OFFSET_PBUFFER(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL; 1098 PATH_OFFSET_PBUFFER(path, ILLEGAL_PATH_ELEMENT_OFFSET) = NULL;
1138 PATH_OFFSET_POSITION(p_s_path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0; 1099 PATH_OFFSET_POSITION(path, ILLEGAL_PATH_ELEMENT_OFFSET) = 0;
1139 p_s_tb->insert_size[0] = n_size; 1100 tb->insert_size[0] = size;
1140} 1101}
1141 1102
1142void padd_item(char *item, int total_length, int length) 1103void padd_item(char *item, int total_length, int length)
@@ -1175,73 +1136,77 @@ char head2type(struct item_head *ih)
1175} 1136}
1176#endif 1137#endif
1177 1138
1178/* Delete object item. */ 1139/* Delete object item.
1179int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the deleted item. */ 1140 * th - active transaction handle
1180 const struct cpu_key *p_s_item_key, /* Key to search for the deleted item. */ 1141 * path - path to the deleted item
1181 struct inode *p_s_inode, /* inode is here just to update i_blocks and quotas */ 1142 * item_key - key to search for the deleted item
1182 struct buffer_head *p_s_un_bh) 1143 * indode - used for updating i_blocks and quotas
1183{ /* NULL or unformatted node pointer. */ 1144 * un_bh - NULL or unformatted node pointer
1184 struct super_block *p_s_sb = p_s_inode->i_sb; 1145 */
1146int reiserfs_delete_item(struct reiserfs_transaction_handle *th,
1147 struct treepath *path, const struct cpu_key *item_key,
1148 struct inode *inode, struct buffer_head *un_bh)
1149{
1150 struct super_block *sb = inode->i_sb;
1185 struct tree_balance s_del_balance; 1151 struct tree_balance s_del_balance;
1186 struct item_head s_ih; 1152 struct item_head s_ih;
1187 struct item_head *q_ih; 1153 struct item_head *q_ih;
1188 int quota_cut_bytes; 1154 int quota_cut_bytes;
1189 int n_ret_value, n_del_size, n_removed; 1155 int ret_value, del_size, removed;
1190 1156
1191#ifdef CONFIG_REISERFS_CHECK 1157#ifdef CONFIG_REISERFS_CHECK
1192 char c_mode; 1158 char mode;
1193 int n_iter = 0; 1159 int iter = 0;
1194#endif 1160#endif
1195 1161
1196 BUG_ON(!th->t_trans_id); 1162 BUG_ON(!th->t_trans_id);
1197 1163
1198 init_tb_struct(th, &s_del_balance, p_s_sb, p_s_path, 1164 init_tb_struct(th, &s_del_balance, sb, path,
1199 0 /*size is unknown */ ); 1165 0 /*size is unknown */ );
1200 1166
1201 while (1) { 1167 while (1) {
1202 n_removed = 0; 1168 removed = 0;
1203 1169
1204#ifdef CONFIG_REISERFS_CHECK 1170#ifdef CONFIG_REISERFS_CHECK
1205 n_iter++; 1171 iter++;
1206 c_mode = 1172 mode =
1207#endif 1173#endif
1208 prepare_for_delete_or_cut(th, p_s_inode, p_s_path, 1174 prepare_for_delete_or_cut(th, inode, path,
1209 p_s_item_key, &n_removed, 1175 item_key, &removed,
1210 &n_del_size, 1176 &del_size,
1211 max_reiserfs_offset(p_s_inode)); 1177 max_reiserfs_offset(inode));
1212 1178
1213 RFALSE(c_mode != M_DELETE, "PAP-5320: mode must be M_DELETE"); 1179 RFALSE(mode != M_DELETE, "PAP-5320: mode must be M_DELETE");
1214 1180
1215 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 1181 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
1216 s_del_balance.insert_size[0] = n_del_size; 1182 s_del_balance.insert_size[0] = del_size;
1217 1183
1218 n_ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL); 1184 ret_value = fix_nodes(M_DELETE, &s_del_balance, NULL, NULL);
1219 if (n_ret_value != REPEAT_SEARCH) 1185 if (ret_value != REPEAT_SEARCH)
1220 break; 1186 break;
1221 1187
1222 PROC_INFO_INC(p_s_sb, delete_item_restarted); 1188 PROC_INFO_INC(sb, delete_item_restarted);
1223 1189
1224 // file system changed, repeat search 1190 // file system changed, repeat search
1225 n_ret_value = 1191 ret_value =
1226 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); 1192 search_for_position_by_key(sb, item_key, path);
1227 if (n_ret_value == IO_ERROR) 1193 if (ret_value == IO_ERROR)
1228 break; 1194 break;
1229 if (n_ret_value == FILE_NOT_FOUND) { 1195 if (ret_value == FILE_NOT_FOUND) {
1230 reiserfs_warning(p_s_sb, 1196 reiserfs_warning(sb, "vs-5340",
1231 "vs-5340: reiserfs_delete_item: "
1232 "no items of the file %K found", 1197 "no items of the file %K found",
1233 p_s_item_key); 1198 item_key);
1234 break; 1199 break;
1235 } 1200 }
1236 } /* while (1) */ 1201 } /* while (1) */
1237 1202
1238 if (n_ret_value != CARRY_ON) { 1203 if (ret_value != CARRY_ON) {
1239 unfix_nodes(&s_del_balance); 1204 unfix_nodes(&s_del_balance);
1240 return 0; 1205 return 0;
1241 } 1206 }
1242 // reiserfs_delete_item returns item length when success 1207 // reiserfs_delete_item returns item length when success
1243 n_ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE); 1208 ret_value = calc_deleted_bytes_number(&s_del_balance, M_DELETE);
1244 q_ih = get_ih(p_s_path); 1209 q_ih = get_ih(path);
1245 quota_cut_bytes = ih_item_len(q_ih); 1210 quota_cut_bytes = ih_item_len(q_ih);
1246 1211
1247 /* hack so the quota code doesn't have to guess if the file 1212 /* hack so the quota code doesn't have to guess if the file
@@ -1250,15 +1215,15 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1250 ** split into multiple items, and we only want to decrement for 1215 ** split into multiple items, and we only want to decrement for
1251 ** the unfm node once 1216 ** the unfm node once
1252 */ 1217 */
1253 if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(q_ih)) { 1218 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(q_ih)) {
1254 if ((le_ih_k_offset(q_ih) & (p_s_sb->s_blocksize - 1)) == 1) { 1219 if ((le_ih_k_offset(q_ih) & (sb->s_blocksize - 1)) == 1) {
1255 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE; 1220 quota_cut_bytes = sb->s_blocksize + UNFM_P_SIZE;
1256 } else { 1221 } else {
1257 quota_cut_bytes = 0; 1222 quota_cut_bytes = 0;
1258 } 1223 }
1259 } 1224 }
1260 1225
1261 if (p_s_un_bh) { 1226 if (un_bh) {
1262 int off; 1227 int off;
1263 char *data; 1228 char *data;
1264 1229
@@ -1276,31 +1241,31 @@ int reiserfs_delete_item(struct reiserfs_transaction_handle *th, struct treepath
1276 ** The unformatted node must be dirtied later on. We can't be 1241 ** The unformatted node must be dirtied later on. We can't be
1277 ** sure here if the entire tail has been deleted yet. 1242 ** sure here if the entire tail has been deleted yet.
1278 ** 1243 **
1279 ** p_s_un_bh is from the page cache (all unformatted nodes are 1244 ** un_bh is from the page cache (all unformatted nodes are
1280 ** from the page cache) and might be a highmem page. So, we 1245 ** from the page cache) and might be a highmem page. So, we
1281 ** can't use p_s_un_bh->b_data. 1246 ** can't use un_bh->b_data.
1282 ** -clm 1247 ** -clm
1283 */ 1248 */
1284 1249
1285 data = kmap_atomic(p_s_un_bh->b_page, KM_USER0); 1250 data = kmap_atomic(un_bh->b_page, KM_USER0);
1286 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1)); 1251 off = ((le_ih_k_offset(&s_ih) - 1) & (PAGE_CACHE_SIZE - 1));
1287 memcpy(data + off, 1252 memcpy(data + off,
1288 B_I_PITEM(PATH_PLAST_BUFFER(p_s_path), &s_ih), 1253 B_I_PITEM(PATH_PLAST_BUFFER(path), &s_ih),
1289 n_ret_value); 1254 ret_value);
1290 kunmap_atomic(data, KM_USER0); 1255 kunmap_atomic(data, KM_USER0);
1291 } 1256 }
1292 /* Perform balancing after all resources have been collected at once. */ 1257 /* Perform balancing after all resources have been collected at once. */
1293 do_balance(&s_del_balance, NULL, NULL, M_DELETE); 1258 do_balance(&s_del_balance, NULL, NULL, M_DELETE);
1294 1259
1295#ifdef REISERQUOTA_DEBUG 1260#ifdef REISERQUOTA_DEBUG
1296 reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, 1261 reiserfs_debug(sb, REISERFS_DEBUG_CODE,
1297 "reiserquota delete_item(): freeing %u, id=%u type=%c", 1262 "reiserquota delete_item(): freeing %u, id=%u type=%c",
1298 quota_cut_bytes, p_s_inode->i_uid, head2type(&s_ih)); 1263 quota_cut_bytes, inode->i_uid, head2type(&s_ih));
1299#endif 1264#endif
1300 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes); 1265 vfs_dq_free_space_nodirty(inode, quota_cut_bytes);
1301 1266
1302 /* Return deleted body length */ 1267 /* Return deleted body length */
1303 return n_ret_value; 1268 return ret_value;
1304} 1269}
1305 1270
1306/* Summary Of Mechanisms For Handling Collisions Between Processes: 1271/* Summary Of Mechanisms For Handling Collisions Between Processes:
@@ -1338,10 +1303,9 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
1338 while (1) { 1303 while (1) {
1339 retval = search_item(th->t_super, &cpu_key, &path); 1304 retval = search_item(th->t_super, &cpu_key, &path);
1340 if (retval == IO_ERROR) { 1305 if (retval == IO_ERROR) {
1341 reiserfs_warning(th->t_super, 1306 reiserfs_error(th->t_super, "vs-5350",
1342 "vs-5350: reiserfs_delete_solid_item: " 1307 "i/o failure occurred trying "
1343 "i/o failure occurred trying to delete %K", 1308 "to delete %K", &cpu_key);
1344 &cpu_key);
1345 break; 1309 break;
1346 } 1310 }
1347 if (retval != ITEM_FOUND) { 1311 if (retval != ITEM_FOUND) {
@@ -1355,9 +1319,8 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
1355 GET_GENERATION_NUMBER(le_key_k_offset 1319 GET_GENERATION_NUMBER(le_key_k_offset
1356 (le_key_version(key), 1320 (le_key_version(key),
1357 key)) == 1)) 1321 key)) == 1))
1358 reiserfs_warning(th->t_super, 1322 reiserfs_warning(th->t_super, "vs-5355",
1359 "vs-5355: reiserfs_delete_solid_item: %k not found", 1323 "%k not found", key);
1360 key);
1361 break; 1324 break;
1362 } 1325 }
1363 if (!tb_init) { 1326 if (!tb_init) {
@@ -1383,14 +1346,13 @@ void reiserfs_delete_solid_item(struct reiserfs_transaction_handle *th,
1383 quota_cut_bytes, inode->i_uid, 1346 quota_cut_bytes, inode->i_uid,
1384 key2type(key)); 1347 key2type(key));
1385#endif 1348#endif
1386 DQUOT_FREE_SPACE_NODIRTY(inode, 1349 vfs_dq_free_space_nodirty(inode,
1387 quota_cut_bytes); 1350 quota_cut_bytes);
1388 } 1351 }
1389 break; 1352 break;
1390 } 1353 }
1391 // IO_ERROR, NO_DISK_SPACE, etc 1354 // IO_ERROR, NO_DISK_SPACE, etc
1392 reiserfs_warning(th->t_super, 1355 reiserfs_warning(th->t_super, "vs-5360",
1393 "vs-5360: reiserfs_delete_solid_item: "
1394 "could not delete %K due to fix_nodes failure", 1356 "could not delete %K due to fix_nodes failure",
1395 &cpu_key); 1357 &cpu_key);
1396 unfix_nodes(&tb); 1358 unfix_nodes(&tb);
@@ -1462,36 +1424,37 @@ static void unmap_buffers(struct page *page, loff_t pos)
1462} 1424}
1463 1425
1464static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th, 1426static int maybe_indirect_to_direct(struct reiserfs_transaction_handle *th,
1465 struct inode *p_s_inode, 1427 struct inode *inode,
1466 struct page *page, 1428 struct page *page,
1467 struct treepath *p_s_path, 1429 struct treepath *path,
1468 const struct cpu_key *p_s_item_key, 1430 const struct cpu_key *item_key,
1469 loff_t n_new_file_size, char *p_c_mode) 1431 loff_t new_file_size, char *mode)
1470{ 1432{
1471 struct super_block *p_s_sb = p_s_inode->i_sb; 1433 struct super_block *sb = inode->i_sb;
1472 int n_block_size = p_s_sb->s_blocksize; 1434 int block_size = sb->s_blocksize;
1473 int cut_bytes; 1435 int cut_bytes;
1474 BUG_ON(!th->t_trans_id); 1436 BUG_ON(!th->t_trans_id);
1475 BUG_ON(n_new_file_size != p_s_inode->i_size); 1437 BUG_ON(new_file_size != inode->i_size);
1476 1438
1477 /* the page being sent in could be NULL if there was an i/o error 1439 /* the page being sent in could be NULL if there was an i/o error
1478 ** reading in the last block. The user will hit problems trying to 1440 ** reading in the last block. The user will hit problems trying to
1479 ** read the file, but for now we just skip the indirect2direct 1441 ** read the file, but for now we just skip the indirect2direct
1480 */ 1442 */
1481 if (atomic_read(&p_s_inode->i_count) > 1 || 1443 if (atomic_read(&inode->i_count) > 1 ||
1482 !tail_has_to_be_packed(p_s_inode) || 1444 !tail_has_to_be_packed(inode) ||
1483 !page || (REISERFS_I(p_s_inode)->i_flags & i_nopack_mask)) { 1445 !page || (REISERFS_I(inode)->i_flags & i_nopack_mask)) {
1484 // leave tail in an unformatted node 1446 /* leave tail in an unformatted node */
1485 *p_c_mode = M_SKIP_BALANCING; 1447 *mode = M_SKIP_BALANCING;
1486 cut_bytes = 1448 cut_bytes =
1487 n_block_size - (n_new_file_size & (n_block_size - 1)); 1449 block_size - (new_file_size & (block_size - 1));
1488 pathrelse(p_s_path); 1450 pathrelse(path);
1489 return cut_bytes; 1451 return cut_bytes;
1490 } 1452 }
1491 /* Permorm the conversion to a direct_item. */ 1453 /* Perform the conversion to a direct_item. */
1492 /*return indirect_to_direct (p_s_inode, p_s_path, p_s_item_key, n_new_file_size, p_c_mode); */ 1454 /* return indirect_to_direct(inode, path, item_key,
1493 return indirect2direct(th, p_s_inode, page, p_s_path, p_s_item_key, 1455 new_file_size, mode); */
1494 n_new_file_size, p_c_mode); 1456 return indirect2direct(th, inode, page, path, item_key,
1457 new_file_size, mode);
1495} 1458}
1496 1459
1497/* we did indirect_to_direct conversion. And we have inserted direct 1460/* we did indirect_to_direct conversion. And we have inserted direct
@@ -1515,8 +1478,8 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th,
1515 /* look for the last byte of the tail */ 1478 /* look for the last byte of the tail */
1516 if (search_for_position_by_key(inode->i_sb, &tail_key, path) == 1479 if (search_for_position_by_key(inode->i_sb, &tail_key, path) ==
1517 POSITION_NOT_FOUND) 1480 POSITION_NOT_FOUND)
1518 reiserfs_panic(inode->i_sb, 1481 reiserfs_panic(inode->i_sb, "vs-5615",
1519 "vs-5615: indirect_to_direct_roll_back: found invalid item"); 1482 "found invalid item");
1520 RFALSE(path->pos_in_item != 1483 RFALSE(path->pos_in_item !=
1521 ih_item_len(PATH_PITEM_HEAD(path)) - 1, 1484 ih_item_len(PATH_PITEM_HEAD(path)) - 1,
1522 "vs-5616: appended bytes found"); 1485 "vs-5616: appended bytes found");
@@ -1533,38 +1496,39 @@ static void indirect_to_direct_roll_back(struct reiserfs_transaction_handle *th,
1533 set_cpu_key_k_offset(&tail_key, 1496 set_cpu_key_k_offset(&tail_key,
1534 cpu_key_k_offset(&tail_key) - removed); 1497 cpu_key_k_offset(&tail_key) - removed);
1535 } 1498 }
1536 reiserfs_warning(inode->i_sb, 1499 reiserfs_warning(inode->i_sb, "reiserfs-5091", "indirect_to_direct "
1537 "indirect_to_direct_roll_back: indirect_to_direct conversion has been rolled back due to lack of disk space"); 1500 "conversion has been rolled back due to "
1501 "lack of disk space");
1538 //mark_file_without_tail (inode); 1502 //mark_file_without_tail (inode);
1539 mark_inode_dirty(inode); 1503 mark_inode_dirty(inode);
1540} 1504}
1541 1505
1542/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */ 1506/* (Truncate or cut entry) or delete object item. Returns < 0 on failure */
1543int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th, 1507int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1544 struct treepath *p_s_path, 1508 struct treepath *path,
1545 struct cpu_key *p_s_item_key, 1509 struct cpu_key *item_key,
1546 struct inode *p_s_inode, 1510 struct inode *inode,
1547 struct page *page, loff_t n_new_file_size) 1511 struct page *page, loff_t new_file_size)
1548{ 1512{
1549 struct super_block *p_s_sb = p_s_inode->i_sb; 1513 struct super_block *sb = inode->i_sb;
1550 /* Every function which is going to call do_balance must first 1514 /* Every function which is going to call do_balance must first
1551 create a tree_balance structure. Then it must fill up this 1515 create a tree_balance structure. Then it must fill up this
1552 structure by using the init_tb_struct and fix_nodes functions. 1516 structure by using the init_tb_struct and fix_nodes functions.
1553 After that we can make tree balancing. */ 1517 After that we can make tree balancing. */
1554 struct tree_balance s_cut_balance; 1518 struct tree_balance s_cut_balance;
1555 struct item_head *p_le_ih; 1519 struct item_head *p_le_ih;
1556 int n_cut_size = 0, /* Amount to be cut. */ 1520 int cut_size = 0, /* Amount to be cut. */
1557 n_ret_value = CARRY_ON, n_removed = 0, /* Number of the removed unformatted nodes. */ 1521 ret_value = CARRY_ON, removed = 0, /* Number of the removed unformatted nodes. */
1558 n_is_inode_locked = 0; 1522 is_inode_locked = 0;
1559 char c_mode; /* Mode of the balance. */ 1523 char mode; /* Mode of the balance. */
1560 int retval2 = -1; 1524 int retval2 = -1;
1561 int quota_cut_bytes; 1525 int quota_cut_bytes;
1562 loff_t tail_pos = 0; 1526 loff_t tail_pos = 0;
1563 1527
1564 BUG_ON(!th->t_trans_id); 1528 BUG_ON(!th->t_trans_id);
1565 1529
1566 init_tb_struct(th, &s_cut_balance, p_s_inode->i_sb, p_s_path, 1530 init_tb_struct(th, &s_cut_balance, inode->i_sb, path,
1567 n_cut_size); 1531 cut_size);
1568 1532
1569 /* Repeat this loop until we either cut the item without needing 1533 /* Repeat this loop until we either cut the item without needing
1570 to balance, or we fix_nodes without schedule occurring */ 1534 to balance, or we fix_nodes without schedule occurring */
@@ -1574,144 +1538,142 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1574 free unformatted nodes which are pointed to by the cut 1538 free unformatted nodes which are pointed to by the cut
1575 pointers. */ 1539 pointers. */
1576 1540
1577 c_mode = 1541 mode =
1578 prepare_for_delete_or_cut(th, p_s_inode, p_s_path, 1542 prepare_for_delete_or_cut(th, inode, path,
1579 p_s_item_key, &n_removed, 1543 item_key, &removed,
1580 &n_cut_size, n_new_file_size); 1544 &cut_size, new_file_size);
1581 if (c_mode == M_CONVERT) { 1545 if (mode == M_CONVERT) {
1582 /* convert last unformatted node to direct item or leave 1546 /* convert last unformatted node to direct item or leave
1583 tail in the unformatted node */ 1547 tail in the unformatted node */
1584 RFALSE(n_ret_value != CARRY_ON, 1548 RFALSE(ret_value != CARRY_ON,
1585 "PAP-5570: can not convert twice"); 1549 "PAP-5570: can not convert twice");
1586 1550
1587 n_ret_value = 1551 ret_value =
1588 maybe_indirect_to_direct(th, p_s_inode, page, 1552 maybe_indirect_to_direct(th, inode, page,
1589 p_s_path, p_s_item_key, 1553 path, item_key,
1590 n_new_file_size, &c_mode); 1554 new_file_size, &mode);
1591 if (c_mode == M_SKIP_BALANCING) 1555 if (mode == M_SKIP_BALANCING)
1592 /* tail has been left in the unformatted node */ 1556 /* tail has been left in the unformatted node */
1593 return n_ret_value; 1557 return ret_value;
1594 1558
1595 n_is_inode_locked = 1; 1559 is_inode_locked = 1;
1596 1560
1597 /* removing of last unformatted node will change value we 1561 /* removing of last unformatted node will change value we
1598 have to return to truncate. Save it */ 1562 have to return to truncate. Save it */
1599 retval2 = n_ret_value; 1563 retval2 = ret_value;
1600 /*retval2 = p_s_sb->s_blocksize - (n_new_file_size & (p_s_sb->s_blocksize - 1)); */ 1564 /*retval2 = sb->s_blocksize - (new_file_size & (sb->s_blocksize - 1)); */
1601 1565
1602 /* So, we have performed the first part of the conversion: 1566 /* So, we have performed the first part of the conversion:
1603 inserting the new direct item. Now we are removing the 1567 inserting the new direct item. Now we are removing the
1604 last unformatted node pointer. Set key to search for 1568 last unformatted node pointer. Set key to search for
1605 it. */ 1569 it. */
1606 set_cpu_key_k_type(p_s_item_key, TYPE_INDIRECT); 1570 set_cpu_key_k_type(item_key, TYPE_INDIRECT);
1607 p_s_item_key->key_length = 4; 1571 item_key->key_length = 4;
1608 n_new_file_size -= 1572 new_file_size -=
1609 (n_new_file_size & (p_s_sb->s_blocksize - 1)); 1573 (new_file_size & (sb->s_blocksize - 1));
1610 tail_pos = n_new_file_size; 1574 tail_pos = new_file_size;
1611 set_cpu_key_k_offset(p_s_item_key, n_new_file_size + 1); 1575 set_cpu_key_k_offset(item_key, new_file_size + 1);
1612 if (search_for_position_by_key 1576 if (search_for_position_by_key
1613 (p_s_sb, p_s_item_key, 1577 (sb, item_key,
1614 p_s_path) == POSITION_NOT_FOUND) { 1578 path) == POSITION_NOT_FOUND) {
1615 print_block(PATH_PLAST_BUFFER(p_s_path), 3, 1579 print_block(PATH_PLAST_BUFFER(path), 3,
1616 PATH_LAST_POSITION(p_s_path) - 1, 1580 PATH_LAST_POSITION(path) - 1,
1617 PATH_LAST_POSITION(p_s_path) + 1); 1581 PATH_LAST_POSITION(path) + 1);
1618 reiserfs_panic(p_s_sb, 1582 reiserfs_panic(sb, "PAP-5580", "item to "
1619 "PAP-5580: reiserfs_cut_from_item: item to convert does not exist (%K)", 1583 "convert does not exist (%K)",
1620 p_s_item_key); 1584 item_key);
1621 } 1585 }
1622 continue; 1586 continue;
1623 } 1587 }
1624 if (n_cut_size == 0) { 1588 if (cut_size == 0) {
1625 pathrelse(p_s_path); 1589 pathrelse(path);
1626 return 0; 1590 return 0;
1627 } 1591 }
1628 1592
1629 s_cut_balance.insert_size[0] = n_cut_size; 1593 s_cut_balance.insert_size[0] = cut_size;
1630 1594
1631 n_ret_value = fix_nodes(c_mode, &s_cut_balance, NULL, NULL); 1595 ret_value = fix_nodes(mode, &s_cut_balance, NULL, NULL);
1632 if (n_ret_value != REPEAT_SEARCH) 1596 if (ret_value != REPEAT_SEARCH)
1633 break; 1597 break;
1634 1598
1635 PROC_INFO_INC(p_s_sb, cut_from_item_restarted); 1599 PROC_INFO_INC(sb, cut_from_item_restarted);
1636 1600
1637 n_ret_value = 1601 ret_value =
1638 search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path); 1602 search_for_position_by_key(sb, item_key, path);
1639 if (n_ret_value == POSITION_FOUND) 1603 if (ret_value == POSITION_FOUND)
1640 continue; 1604 continue;
1641 1605
1642 reiserfs_warning(p_s_sb, 1606 reiserfs_warning(sb, "PAP-5610", "item %K not found",
1643 "PAP-5610: reiserfs_cut_from_item: item %K not found", 1607 item_key);
1644 p_s_item_key);
1645 unfix_nodes(&s_cut_balance); 1608 unfix_nodes(&s_cut_balance);
1646 return (n_ret_value == IO_ERROR) ? -EIO : -ENOENT; 1609 return (ret_value == IO_ERROR) ? -EIO : -ENOENT;
1647 } /* while */ 1610 } /* while */
1648 1611
1649 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE) 1612 // check fix_nodes results (IO_ERROR or NO_DISK_SPACE)
1650 if (n_ret_value != CARRY_ON) { 1613 if (ret_value != CARRY_ON) {
1651 if (n_is_inode_locked) { 1614 if (is_inode_locked) {
1652 // FIXME: this seems to be not needed: we are always able 1615 // FIXME: this seems to be not needed: we are always able
1653 // to cut item 1616 // to cut item
1654 indirect_to_direct_roll_back(th, p_s_inode, p_s_path); 1617 indirect_to_direct_roll_back(th, inode, path);
1655 } 1618 }
1656 if (n_ret_value == NO_DISK_SPACE) 1619 if (ret_value == NO_DISK_SPACE)
1657 reiserfs_warning(p_s_sb, "NO_DISK_SPACE"); 1620 reiserfs_warning(sb, "reiserfs-5092",
1621 "NO_DISK_SPACE");
1658 unfix_nodes(&s_cut_balance); 1622 unfix_nodes(&s_cut_balance);
1659 return -EIO; 1623 return -EIO;
1660 } 1624 }
1661 1625
1662 /* go ahead and perform balancing */ 1626 /* go ahead and perform balancing */
1663 1627
1664 RFALSE(c_mode == M_PASTE || c_mode == M_INSERT, "invalid mode"); 1628 RFALSE(mode == M_PASTE || mode == M_INSERT, "invalid mode");
1665 1629
1666 /* Calculate number of bytes that need to be cut from the item. */ 1630 /* Calculate number of bytes that need to be cut from the item. */
1667 quota_cut_bytes = 1631 quota_cut_bytes =
1668 (c_mode == 1632 (mode ==
1669 M_DELETE) ? ih_item_len(get_ih(p_s_path)) : -s_cut_balance. 1633 M_DELETE) ? ih_item_len(get_ih(path)) : -s_cut_balance.
1670 insert_size[0]; 1634 insert_size[0];
1671 if (retval2 == -1) 1635 if (retval2 == -1)
1672 n_ret_value = calc_deleted_bytes_number(&s_cut_balance, c_mode); 1636 ret_value = calc_deleted_bytes_number(&s_cut_balance, mode);
1673 else 1637 else
1674 n_ret_value = retval2; 1638 ret_value = retval2;
1675 1639
1676 /* For direct items, we only change the quota when deleting the last 1640 /* For direct items, we only change the quota when deleting the last
1677 ** item. 1641 ** item.
1678 */ 1642 */
1679 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path); 1643 p_le_ih = PATH_PITEM_HEAD(s_cut_balance.tb_path);
1680 if (!S_ISLNK(p_s_inode->i_mode) && is_direct_le_ih(p_le_ih)) { 1644 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_le_ih)) {
1681 if (c_mode == M_DELETE && 1645 if (mode == M_DELETE &&
1682 (le_ih_k_offset(p_le_ih) & (p_s_sb->s_blocksize - 1)) == 1646 (le_ih_k_offset(p_le_ih) & (sb->s_blocksize - 1)) ==
1683 1) { 1647 1) {
1684 // FIXME: this is to keep 3.5 happy 1648 // FIXME: this is to keep 3.5 happy
1685 REISERFS_I(p_s_inode)->i_first_direct_byte = U32_MAX; 1649 REISERFS_I(inode)->i_first_direct_byte = U32_MAX;
1686 quota_cut_bytes = p_s_sb->s_blocksize + UNFM_P_SIZE; 1650 quota_cut_bytes = sb->s_blocksize + UNFM_P_SIZE;
1687 } else { 1651 } else {
1688 quota_cut_bytes = 0; 1652 quota_cut_bytes = 0;
1689 } 1653 }
1690 } 1654 }
1691#ifdef CONFIG_REISERFS_CHECK 1655#ifdef CONFIG_REISERFS_CHECK
1692 if (n_is_inode_locked) { 1656 if (is_inode_locked) {
1693 struct item_head *le_ih = 1657 struct item_head *le_ih =
1694 PATH_PITEM_HEAD(s_cut_balance.tb_path); 1658 PATH_PITEM_HEAD(s_cut_balance.tb_path);
1695 /* we are going to complete indirect2direct conversion. Make 1659 /* we are going to complete indirect2direct conversion. Make
1696 sure, that we exactly remove last unformatted node pointer 1660 sure, that we exactly remove last unformatted node pointer
1697 of the item */ 1661 of the item */
1698 if (!is_indirect_le_ih(le_ih)) 1662 if (!is_indirect_le_ih(le_ih))
1699 reiserfs_panic(p_s_sb, 1663 reiserfs_panic(sb, "vs-5652",
1700 "vs-5652: reiserfs_cut_from_item: "
1701 "item must be indirect %h", le_ih); 1664 "item must be indirect %h", le_ih);
1702 1665
1703 if (c_mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE) 1666 if (mode == M_DELETE && ih_item_len(le_ih) != UNFM_P_SIZE)
1704 reiserfs_panic(p_s_sb, 1667 reiserfs_panic(sb, "vs-5653", "completing "
1705 "vs-5653: reiserfs_cut_from_item: " 1668 "indirect2direct conversion indirect "
1706 "completing indirect2direct conversion indirect item %h " 1669 "item %h being deleted must be of "
1707 "being deleted must be of 4 byte long", 1670 "4 byte long", le_ih);
1708 le_ih);
1709 1671
1710 if (c_mode == M_CUT 1672 if (mode == M_CUT
1711 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) { 1673 && s_cut_balance.insert_size[0] != -UNFM_P_SIZE) {
1712 reiserfs_panic(p_s_sb, 1674 reiserfs_panic(sb, "vs-5654", "can not complete "
1713 "vs-5654: reiserfs_cut_from_item: " 1675 "indirect2direct conversion of %h "
1714 "can not complete indirect2direct conversion of %h (CUT, insert_size==%d)", 1676 "(CUT, insert_size==%d)",
1715 le_ih, s_cut_balance.insert_size[0]); 1677 le_ih, s_cut_balance.insert_size[0]);
1716 } 1678 }
1717 /* it would be useful to make sure, that right neighboring 1679 /* it would be useful to make sure, that right neighboring
@@ -1719,23 +1681,23 @@ int reiserfs_cut_from_item(struct reiserfs_transaction_handle *th,
1719 } 1681 }
1720#endif 1682#endif
1721 1683
1722 do_balance(&s_cut_balance, NULL, NULL, c_mode); 1684 do_balance(&s_cut_balance, NULL, NULL, mode);
1723 if (n_is_inode_locked) { 1685 if (is_inode_locked) {
1724 /* we've done an indirect->direct conversion. when the data block 1686 /* we've done an indirect->direct conversion. when the data block
1725 ** was freed, it was removed from the list of blocks that must 1687 ** was freed, it was removed from the list of blocks that must
1726 ** be flushed before the transaction commits, make sure to 1688 ** be flushed before the transaction commits, make sure to
1727 ** unmap and invalidate it 1689 ** unmap and invalidate it
1728 */ 1690 */
1729 unmap_buffers(page, tail_pos); 1691 unmap_buffers(page, tail_pos);
1730 REISERFS_I(p_s_inode)->i_flags &= ~i_pack_on_close_mask; 1692 REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask;
1731 } 1693 }
1732#ifdef REISERQUOTA_DEBUG 1694#ifdef REISERQUOTA_DEBUG
1733 reiserfs_debug(p_s_inode->i_sb, REISERFS_DEBUG_CODE, 1695 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1734 "reiserquota cut_from_item(): freeing %u id=%u type=%c", 1696 "reiserquota cut_from_item(): freeing %u id=%u type=%c",
1735 quota_cut_bytes, p_s_inode->i_uid, '?'); 1697 quota_cut_bytes, inode->i_uid, '?');
1736#endif 1698#endif
1737 DQUOT_FREE_SPACE_NODIRTY(p_s_inode, quota_cut_bytes); 1699 vfs_dq_free_space_nodirty(inode, quota_cut_bytes);
1738 return n_ret_value; 1700 return ret_value;
1739} 1701}
1740 1702
1741static void truncate_directory(struct reiserfs_transaction_handle *th, 1703static void truncate_directory(struct reiserfs_transaction_handle *th,
@@ -1743,8 +1705,7 @@ static void truncate_directory(struct reiserfs_transaction_handle *th,
1743{ 1705{
1744 BUG_ON(!th->t_trans_id); 1706 BUG_ON(!th->t_trans_id);
1745 if (inode->i_nlink) 1707 if (inode->i_nlink)
1746 reiserfs_warning(inode->i_sb, 1708 reiserfs_error(inode->i_sb, "vs-5655", "link count != 0");
1747 "vs-5655: truncate_directory: link count != 0");
1748 1709
1749 set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), DOT_OFFSET); 1710 set_le_key_k_offset(KEY_FORMAT_3_5, INODE_PKEY(inode), DOT_OFFSET);
1750 set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_DIRENTRY); 1711 set_le_key_k_type(KEY_FORMAT_3_5, INODE_PKEY(inode), TYPE_DIRENTRY);
@@ -1756,8 +1717,8 @@ static void truncate_directory(struct reiserfs_transaction_handle *th,
1756 1717
1757/* Truncate file to the new size. Note, this must be called with a transaction 1718/* Truncate file to the new size. Note, this must be called with a transaction
1758 already started */ 1719 already started */
1759int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, /* ->i_size contains new 1720int reiserfs_do_truncate(struct reiserfs_transaction_handle *th,
1760 size */ 1721 struct inode *inode, /* ->i_size contains new size */
1761 struct page *page, /* up to date for last block */ 1722 struct page *page, /* up to date for last block */
1762 int update_timestamps /* when it is called by 1723 int update_timestamps /* when it is called by
1763 file_release to convert 1724 file_release to convert
@@ -1768,47 +1729,45 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p
1768 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */ 1729 INITIALIZE_PATH(s_search_path); /* Path to the current object item. */
1769 struct item_head *p_le_ih; /* Pointer to an item header. */ 1730 struct item_head *p_le_ih; /* Pointer to an item header. */
1770 struct cpu_key s_item_key; /* Key to search for a previous file item. */ 1731 struct cpu_key s_item_key; /* Key to search for a previous file item. */
1771 loff_t n_file_size, /* Old file size. */ 1732 loff_t file_size, /* Old file size. */
1772 n_new_file_size; /* New file size. */ 1733 new_file_size; /* New file size. */
1773 int n_deleted; /* Number of deleted or truncated bytes. */ 1734 int deleted; /* Number of deleted or truncated bytes. */
1774 int retval; 1735 int retval;
1775 int err = 0; 1736 int err = 0;
1776 1737
1777 BUG_ON(!th->t_trans_id); 1738 BUG_ON(!th->t_trans_id);
1778 if (! 1739 if (!
1779 (S_ISREG(p_s_inode->i_mode) || S_ISDIR(p_s_inode->i_mode) 1740 (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode)
1780 || S_ISLNK(p_s_inode->i_mode))) 1741 || S_ISLNK(inode->i_mode)))
1781 return 0; 1742 return 0;
1782 1743
1783 if (S_ISDIR(p_s_inode->i_mode)) { 1744 if (S_ISDIR(inode->i_mode)) {
1784 // deletion of directory - no need to update timestamps 1745 // deletion of directory - no need to update timestamps
1785 truncate_directory(th, p_s_inode); 1746 truncate_directory(th, inode);
1786 return 0; 1747 return 0;
1787 } 1748 }
1788 1749
1789 /* Get new file size. */ 1750 /* Get new file size. */
1790 n_new_file_size = p_s_inode->i_size; 1751 new_file_size = inode->i_size;
1791 1752
1792 // FIXME: note, that key type is unimportant here 1753 // FIXME: note, that key type is unimportant here
1793 make_cpu_key(&s_item_key, p_s_inode, max_reiserfs_offset(p_s_inode), 1754 make_cpu_key(&s_item_key, inode, max_reiserfs_offset(inode),
1794 TYPE_DIRECT, 3); 1755 TYPE_DIRECT, 3);
1795 1756
1796 retval = 1757 retval =
1797 search_for_position_by_key(p_s_inode->i_sb, &s_item_key, 1758 search_for_position_by_key(inode->i_sb, &s_item_key,
1798 &s_search_path); 1759 &s_search_path);
1799 if (retval == IO_ERROR) { 1760 if (retval == IO_ERROR) {
1800 reiserfs_warning(p_s_inode->i_sb, 1761 reiserfs_error(inode->i_sb, "vs-5657",
1801 "vs-5657: reiserfs_do_truncate: " 1762 "i/o failure occurred trying to truncate %K",
1802 "i/o failure occurred trying to truncate %K", 1763 &s_item_key);
1803 &s_item_key);
1804 err = -EIO; 1764 err = -EIO;
1805 goto out; 1765 goto out;
1806 } 1766 }
1807 if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) { 1767 if (retval == POSITION_FOUND || retval == FILE_NOT_FOUND) {
1808 reiserfs_warning(p_s_inode->i_sb, 1768 reiserfs_error(inode->i_sb, "PAP-5660",
1809 "PAP-5660: reiserfs_do_truncate: " 1769 "wrong result %d of search for %K", retval,
1810 "wrong result %d of search for %K", retval, 1770 &s_item_key);
1811 &s_item_key);
1812 1771
1813 err = -EIO; 1772 err = -EIO;
1814 goto out; 1773 goto out;
@@ -1819,56 +1778,56 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p
1819 /* Get real file size (total length of all file items) */ 1778 /* Get real file size (total length of all file items) */
1820 p_le_ih = PATH_PITEM_HEAD(&s_search_path); 1779 p_le_ih = PATH_PITEM_HEAD(&s_search_path);
1821 if (is_statdata_le_ih(p_le_ih)) 1780 if (is_statdata_le_ih(p_le_ih))
1822 n_file_size = 0; 1781 file_size = 0;
1823 else { 1782 else {
1824 loff_t offset = le_ih_k_offset(p_le_ih); 1783 loff_t offset = le_ih_k_offset(p_le_ih);
1825 int bytes = 1784 int bytes =
1826 op_bytes_number(p_le_ih, p_s_inode->i_sb->s_blocksize); 1785 op_bytes_number(p_le_ih, inode->i_sb->s_blocksize);
1827 1786
1828 /* this may mismatch with real file size: if last direct item 1787 /* this may mismatch with real file size: if last direct item
1829 had no padding zeros and last unformatted node had no free 1788 had no padding zeros and last unformatted node had no free
1830 space, this file would have this file size */ 1789 space, this file would have this file size */
1831 n_file_size = offset + bytes - 1; 1790 file_size = offset + bytes - 1;
1832 } 1791 }
1833 /* 1792 /*
1834 * are we doing a full truncate or delete, if so 1793 * are we doing a full truncate or delete, if so
1835 * kick in the reada code 1794 * kick in the reada code
1836 */ 1795 */
1837 if (n_new_file_size == 0) 1796 if (new_file_size == 0)
1838 s_search_path.reada = PATH_READA | PATH_READA_BACK; 1797 s_search_path.reada = PATH_READA | PATH_READA_BACK;
1839 1798
1840 if (n_file_size == 0 || n_file_size < n_new_file_size) { 1799 if (file_size == 0 || file_size < new_file_size) {
1841 goto update_and_out; 1800 goto update_and_out;
1842 } 1801 }
1843 1802
1844 /* Update key to search for the last file item. */ 1803 /* Update key to search for the last file item. */
1845 set_cpu_key_k_offset(&s_item_key, n_file_size); 1804 set_cpu_key_k_offset(&s_item_key, file_size);
1846 1805
1847 do { 1806 do {
1848 /* Cut or delete file item. */ 1807 /* Cut or delete file item. */
1849 n_deleted = 1808 deleted =
1850 reiserfs_cut_from_item(th, &s_search_path, &s_item_key, 1809 reiserfs_cut_from_item(th, &s_search_path, &s_item_key,
1851 p_s_inode, page, n_new_file_size); 1810 inode, page, new_file_size);
1852 if (n_deleted < 0) { 1811 if (deleted < 0) {
1853 reiserfs_warning(p_s_inode->i_sb, 1812 reiserfs_warning(inode->i_sb, "vs-5665",
1854 "vs-5665: reiserfs_do_truncate: reiserfs_cut_from_item failed"); 1813 "reiserfs_cut_from_item failed");
1855 reiserfs_check_path(&s_search_path); 1814 reiserfs_check_path(&s_search_path);
1856 return 0; 1815 return 0;
1857 } 1816 }
1858 1817
1859 RFALSE(n_deleted > n_file_size, 1818 RFALSE(deleted > file_size,
1860 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K", 1819 "PAP-5670: reiserfs_cut_from_item: too many bytes deleted: deleted %d, file_size %lu, item_key %K",
1861 n_deleted, n_file_size, &s_item_key); 1820 deleted, file_size, &s_item_key);
1862 1821
1863 /* Change key to search the last file item. */ 1822 /* Change key to search the last file item. */
1864 n_file_size -= n_deleted; 1823 file_size -= deleted;
1865 1824
1866 set_cpu_key_k_offset(&s_item_key, n_file_size); 1825 set_cpu_key_k_offset(&s_item_key, file_size);
1867 1826
1868 /* While there are bytes to truncate and previous file item is presented in the tree. */ 1827 /* While there are bytes to truncate and previous file item is presented in the tree. */
1869 1828
1870 /* 1829 /*
1871 ** This loop could take a really long time, and could log 1830 ** This loop could take a really long time, and could log
1872 ** many more blocks than a transaction can hold. So, we do a polite 1831 ** many more blocks than a transaction can hold. So, we do a polite
1873 ** journal end here, and if the transaction needs ending, we make 1832 ** journal end here, and if the transaction needs ending, we make
1874 ** sure the file is consistent before ending the current trans 1833 ** sure the file is consistent before ending the current trans
@@ -1877,37 +1836,38 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p
1877 if (journal_transaction_should_end(th, 0) || 1836 if (journal_transaction_should_end(th, 0) ||
1878 reiserfs_transaction_free_space(th) <= JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) { 1837 reiserfs_transaction_free_space(th) <= JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD) {
1879 int orig_len_alloc = th->t_blocks_allocated; 1838 int orig_len_alloc = th->t_blocks_allocated;
1880 decrement_counters_in_path(&s_search_path); 1839 pathrelse(&s_search_path);
1881 1840
1882 if (update_timestamps) { 1841 if (update_timestamps) {
1883 p_s_inode->i_mtime = p_s_inode->i_ctime = 1842 inode->i_mtime = CURRENT_TIME_SEC;
1884 CURRENT_TIME_SEC; 1843 inode->i_ctime = CURRENT_TIME_SEC;
1885 } 1844 }
1886 reiserfs_update_sd(th, p_s_inode); 1845 reiserfs_update_sd(th, inode);
1887 1846
1888 err = journal_end(th, p_s_inode->i_sb, orig_len_alloc); 1847 err = journal_end(th, inode->i_sb, orig_len_alloc);
1889 if (err) 1848 if (err)
1890 goto out; 1849 goto out;
1891 err = journal_begin(th, p_s_inode->i_sb, 1850 err = journal_begin(th, inode->i_sb,
1892 JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD + JOURNAL_PER_BALANCE_CNT * 4) ; 1851 JOURNAL_FOR_FREE_BLOCK_AND_UPDATE_SD + JOURNAL_PER_BALANCE_CNT * 4) ;
1893 if (err) 1852 if (err)
1894 goto out; 1853 goto out;
1895 reiserfs_update_inode_transaction(p_s_inode); 1854 reiserfs_update_inode_transaction(inode);
1896 } 1855 }
1897 } while (n_file_size > ROUND_UP(n_new_file_size) && 1856 } while (file_size > ROUND_UP(new_file_size) &&
1898 search_for_position_by_key(p_s_inode->i_sb, &s_item_key, 1857 search_for_position_by_key(inode->i_sb, &s_item_key,
1899 &s_search_path) == POSITION_FOUND); 1858 &s_search_path) == POSITION_FOUND);
1900 1859
1901 RFALSE(n_file_size > ROUND_UP(n_new_file_size), 1860 RFALSE(file_size > ROUND_UP(new_file_size),
1902 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d", 1861 "PAP-5680: truncate did not finish: new_file_size %Ld, current %Ld, oid %d",
1903 n_new_file_size, n_file_size, s_item_key.on_disk_key.k_objectid); 1862 new_file_size, file_size, s_item_key.on_disk_key.k_objectid);
1904 1863
1905 update_and_out: 1864 update_and_out:
1906 if (update_timestamps) { 1865 if (update_timestamps) {
1907 // this is truncate, not file closing 1866 // this is truncate, not file closing
1908 p_s_inode->i_mtime = p_s_inode->i_ctime = CURRENT_TIME_SEC; 1867 inode->i_mtime = CURRENT_TIME_SEC;
1868 inode->i_ctime = CURRENT_TIME_SEC;
1909 } 1869 }
1910 reiserfs_update_sd(th, p_s_inode); 1870 reiserfs_update_sd(th, inode);
1911 1871
1912 out: 1872 out:
1913 pathrelse(&s_search_path); 1873 pathrelse(&s_search_path);
@@ -1917,7 +1877,7 @@ int reiserfs_do_truncate(struct reiserfs_transaction_handle *th, struct inode *p
1917#ifdef CONFIG_REISERFS_CHECK 1877#ifdef CONFIG_REISERFS_CHECK
1918// this makes sure, that we __append__, not overwrite or add holes 1878// this makes sure, that we __append__, not overwrite or add holes
1919static void check_research_for_paste(struct treepath *path, 1879static void check_research_for_paste(struct treepath *path,
1920 const struct cpu_key *p_s_key) 1880 const struct cpu_key *key)
1921{ 1881{
1922 struct item_head *found_ih = get_ih(path); 1882 struct item_head *found_ih = get_ih(path);
1923 1883
@@ -1925,36 +1885,36 @@ static void check_research_for_paste(struct treepath *path,
1925 if (le_ih_k_offset(found_ih) + 1885 if (le_ih_k_offset(found_ih) +
1926 op_bytes_number(found_ih, 1886 op_bytes_number(found_ih,
1927 get_last_bh(path)->b_size) != 1887 get_last_bh(path)->b_size) !=
1928 cpu_key_k_offset(p_s_key) 1888 cpu_key_k_offset(key)
1929 || op_bytes_number(found_ih, 1889 || op_bytes_number(found_ih,
1930 get_last_bh(path)->b_size) != 1890 get_last_bh(path)->b_size) !=
1931 pos_in_item(path)) 1891 pos_in_item(path))
1932 reiserfs_panic(NULL, 1892 reiserfs_panic(NULL, "PAP-5720", "found direct item "
1933 "PAP-5720: check_research_for_paste: " 1893 "%h or position (%d) does not match "
1934 "found direct item %h or position (%d) does not match to key %K", 1894 "to key %K", found_ih,
1935 found_ih, pos_in_item(path), p_s_key); 1895 pos_in_item(path), key);
1936 } 1896 }
1937 if (is_indirect_le_ih(found_ih)) { 1897 if (is_indirect_le_ih(found_ih)) {
1938 if (le_ih_k_offset(found_ih) + 1898 if (le_ih_k_offset(found_ih) +
1939 op_bytes_number(found_ih, 1899 op_bytes_number(found_ih,
1940 get_last_bh(path)->b_size) != 1900 get_last_bh(path)->b_size) !=
1941 cpu_key_k_offset(p_s_key) 1901 cpu_key_k_offset(key)
1942 || I_UNFM_NUM(found_ih) != pos_in_item(path) 1902 || I_UNFM_NUM(found_ih) != pos_in_item(path)
1943 || get_ih_free_space(found_ih) != 0) 1903 || get_ih_free_space(found_ih) != 0)
1944 reiserfs_panic(NULL, 1904 reiserfs_panic(NULL, "PAP-5730", "found indirect "
1945 "PAP-5730: check_research_for_paste: " 1905 "item (%h) or position (%d) does not "
1946 "found indirect item (%h) or position (%d) does not match to key (%K)", 1906 "match to key (%K)",
1947 found_ih, pos_in_item(path), p_s_key); 1907 found_ih, pos_in_item(path), key);
1948 } 1908 }
1949} 1909}
1950#endif /* config reiserfs check */ 1910#endif /* config reiserfs check */
1951 1911
1952/* Paste bytes to the existing item. Returns bytes number pasted into the item. */ 1912/* Paste bytes to the existing item. Returns bytes number pasted into the item. */
1953int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_search_path, /* Path to the pasted item. */ 1913int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct treepath *search_path, /* Path to the pasted item. */
1954 const struct cpu_key *p_s_key, /* Key to search for the needed item. */ 1914 const struct cpu_key *key, /* Key to search for the needed item. */
1955 struct inode *inode, /* Inode item belongs to */ 1915 struct inode *inode, /* Inode item belongs to */
1956 const char *p_c_body, /* Pointer to the bytes to paste. */ 1916 const char *body, /* Pointer to the bytes to paste. */
1957 int n_pasted_size) 1917 int pasted_size)
1958{ /* Size of pasted bytes. */ 1918{ /* Size of pasted bytes. */
1959 struct tree_balance s_paste_balance; 1919 struct tree_balance s_paste_balance;
1960 int retval; 1920 int retval;
@@ -1967,18 +1927,18 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1967#ifdef REISERQUOTA_DEBUG 1927#ifdef REISERQUOTA_DEBUG
1968 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1928 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
1969 "reiserquota paste_into_item(): allocating %u id=%u type=%c", 1929 "reiserquota paste_into_item(): allocating %u id=%u type=%c",
1970 n_pasted_size, inode->i_uid, 1930 pasted_size, inode->i_uid,
1971 key2type(&(p_s_key->on_disk_key))); 1931 key2type(&(key->on_disk_key)));
1972#endif 1932#endif
1973 1933
1974 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, n_pasted_size)) { 1934 if (vfs_dq_alloc_space_nodirty(inode, pasted_size)) {
1975 pathrelse(p_s_search_path); 1935 pathrelse(search_path);
1976 return -EDQUOT; 1936 return -EDQUOT;
1977 } 1937 }
1978 init_tb_struct(th, &s_paste_balance, th->t_super, p_s_search_path, 1938 init_tb_struct(th, &s_paste_balance, th->t_super, search_path,
1979 n_pasted_size); 1939 pasted_size);
1980#ifdef DISPLACE_NEW_PACKING_LOCALITIES 1940#ifdef DISPLACE_NEW_PACKING_LOCALITIES
1981 s_paste_balance.key = p_s_key->on_disk_key; 1941 s_paste_balance.key = key->on_disk_key;
1982#endif 1942#endif
1983 1943
1984 /* DQUOT_* can schedule, must check before the fix_nodes */ 1944 /* DQUOT_* can schedule, must check before the fix_nodes */
@@ -1988,33 +1948,33 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
1988 1948
1989 while ((retval = 1949 while ((retval =
1990 fix_nodes(M_PASTE, &s_paste_balance, NULL, 1950 fix_nodes(M_PASTE, &s_paste_balance, NULL,
1991 p_c_body)) == REPEAT_SEARCH) { 1951 body)) == REPEAT_SEARCH) {
1992 search_again: 1952 search_again:
1993 /* file system changed while we were in the fix_nodes */ 1953 /* file system changed while we were in the fix_nodes */
1994 PROC_INFO_INC(th->t_super, paste_into_item_restarted); 1954 PROC_INFO_INC(th->t_super, paste_into_item_restarted);
1995 retval = 1955 retval =
1996 search_for_position_by_key(th->t_super, p_s_key, 1956 search_for_position_by_key(th->t_super, key,
1997 p_s_search_path); 1957 search_path);
1998 if (retval == IO_ERROR) { 1958 if (retval == IO_ERROR) {
1999 retval = -EIO; 1959 retval = -EIO;
2000 goto error_out; 1960 goto error_out;
2001 } 1961 }
2002 if (retval == POSITION_FOUND) { 1962 if (retval == POSITION_FOUND) {
2003 reiserfs_warning(inode->i_sb, 1963 reiserfs_warning(inode->i_sb, "PAP-5710",
2004 "PAP-5710: reiserfs_paste_into_item: entry or pasted byte (%K) exists", 1964 "entry or pasted byte (%K) exists",
2005 p_s_key); 1965 key);
2006 retval = -EEXIST; 1966 retval = -EEXIST;
2007 goto error_out; 1967 goto error_out;
2008 } 1968 }
2009#ifdef CONFIG_REISERFS_CHECK 1969#ifdef CONFIG_REISERFS_CHECK
2010 check_research_for_paste(p_s_search_path, p_s_key); 1970 check_research_for_paste(search_path, key);
2011#endif 1971#endif
2012 } 1972 }
2013 1973
2014 /* Perform balancing after all resources are collected by fix_nodes, and 1974 /* Perform balancing after all resources are collected by fix_nodes, and
2015 accessing them will not risk triggering schedule. */ 1975 accessing them will not risk triggering schedule. */
2016 if (retval == CARRY_ON) { 1976 if (retval == CARRY_ON) {
2017 do_balance(&s_paste_balance, NULL /*ih */ , p_c_body, M_PASTE); 1977 do_balance(&s_paste_balance, NULL /*ih */ , body, M_PASTE);
2018 return 0; 1978 return 0;
2019 } 1979 }
2020 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO; 1980 retval = (retval == NO_DISK_SPACE) ? -ENOSPC : -EIO;
@@ -2024,18 +1984,24 @@ int reiserfs_paste_into_item(struct reiserfs_transaction_handle *th, struct tree
2024#ifdef REISERQUOTA_DEBUG 1984#ifdef REISERQUOTA_DEBUG
2025 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 1985 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2026 "reiserquota paste_into_item(): freeing %u id=%u type=%c", 1986 "reiserquota paste_into_item(): freeing %u id=%u type=%c",
2027 n_pasted_size, inode->i_uid, 1987 pasted_size, inode->i_uid,
2028 key2type(&(p_s_key->on_disk_key))); 1988 key2type(&(key->on_disk_key)));
2029#endif 1989#endif
2030 DQUOT_FREE_SPACE_NODIRTY(inode, n_pasted_size); 1990 vfs_dq_free_space_nodirty(inode, pasted_size);
2031 return retval; 1991 return retval;
2032} 1992}
2033 1993
2034/* Insert new item into the buffer at the path. */ 1994/* Insert new item into the buffer at the path.
2035int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath *p_s_path, /* Path to the inserteded item. */ 1995 * th - active transaction handle
2036 const struct cpu_key *key, struct item_head *p_s_ih, /* Pointer to the item header to insert. */ 1996 * path - path to the inserted item
2037 struct inode *inode, const char *p_c_body) 1997 * ih - pointer to the item header to insert
2038{ /* Pointer to the bytes to insert. */ 1998 * body - pointer to the bytes to insert
1999 */
2000int reiserfs_insert_item(struct reiserfs_transaction_handle *th,
2001 struct treepath *path, const struct cpu_key *key,
2002 struct item_head *ih, struct inode *inode,
2003 const char *body)
2004{
2039 struct tree_balance s_ins_balance; 2005 struct tree_balance s_ins_balance;
2040 int retval; 2006 int retval;
2041 int fs_gen = 0; 2007 int fs_gen = 0;
@@ -2045,28 +2011,27 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2045 2011
2046 if (inode) { /* Do we count quotas for item? */ 2012 if (inode) { /* Do we count quotas for item? */
2047 fs_gen = get_generation(inode->i_sb); 2013 fs_gen = get_generation(inode->i_sb);
2048 quota_bytes = ih_item_len(p_s_ih); 2014 quota_bytes = ih_item_len(ih);
2049 2015
2050 /* hack so the quota code doesn't have to guess if the file has 2016 /* hack so the quota code doesn't have to guess if the file has
2051 ** a tail, links are always tails, so there's no guessing needed 2017 ** a tail, links are always tails, so there's no guessing needed
2052 */ 2018 */
2053 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(p_s_ih)) { 2019 if (!S_ISLNK(inode->i_mode) && is_direct_le_ih(ih))
2054 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE; 2020 quota_bytes = inode->i_sb->s_blocksize + UNFM_P_SIZE;
2055 }
2056#ifdef REISERQUOTA_DEBUG 2021#ifdef REISERQUOTA_DEBUG
2057 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE, 2022 reiserfs_debug(inode->i_sb, REISERFS_DEBUG_CODE,
2058 "reiserquota insert_item(): allocating %u id=%u type=%c", 2023 "reiserquota insert_item(): allocating %u id=%u type=%c",
2059 quota_bytes, inode->i_uid, head2type(p_s_ih)); 2024 quota_bytes, inode->i_uid, head2type(ih));
2060#endif 2025#endif
2061 /* We can't dirty inode here. It would be immediately written but 2026 /* We can't dirty inode here. It would be immediately written but
2062 * appropriate stat item isn't inserted yet... */ 2027 * appropriate stat item isn't inserted yet... */
2063 if (DQUOT_ALLOC_SPACE_NODIRTY(inode, quota_bytes)) { 2028 if (vfs_dq_alloc_space_nodirty(inode, quota_bytes)) {
2064 pathrelse(p_s_path); 2029 pathrelse(path);
2065 return -EDQUOT; 2030 return -EDQUOT;
2066 } 2031 }
2067 } 2032 }
2068 init_tb_struct(th, &s_ins_balance, th->t_super, p_s_path, 2033 init_tb_struct(th, &s_ins_balance, th->t_super, path,
2069 IH_SIZE + ih_item_len(p_s_ih)); 2034 IH_SIZE + ih_item_len(ih));
2070#ifdef DISPLACE_NEW_PACKING_LOCALITIES 2035#ifdef DISPLACE_NEW_PACKING_LOCALITIES
2071 s_ins_balance.key = key->on_disk_key; 2036 s_ins_balance.key = key->on_disk_key;
2072#endif 2037#endif
@@ -2076,19 +2041,18 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2076 } 2041 }
2077 2042
2078 while ((retval = 2043 while ((retval =
2079 fix_nodes(M_INSERT, &s_ins_balance, p_s_ih, 2044 fix_nodes(M_INSERT, &s_ins_balance, ih,
2080 p_c_body)) == REPEAT_SEARCH) { 2045 body)) == REPEAT_SEARCH) {
2081 search_again: 2046 search_again:
2082 /* file system changed while we were in the fix_nodes */ 2047 /* file system changed while we were in the fix_nodes */
2083 PROC_INFO_INC(th->t_super, insert_item_restarted); 2048 PROC_INFO_INC(th->t_super, insert_item_restarted);
2084 retval = search_item(th->t_super, key, p_s_path); 2049 retval = search_item(th->t_super, key, path);
2085 if (retval == IO_ERROR) { 2050 if (retval == IO_ERROR) {
2086 retval = -EIO; 2051 retval = -EIO;
2087 goto error_out; 2052 goto error_out;
2088 } 2053 }
2089 if (retval == ITEM_FOUND) { 2054 if (retval == ITEM_FOUND) {
2090 reiserfs_warning(th->t_super, 2055 reiserfs_warning(th->t_super, "PAP-5760",
2091 "PAP-5760: reiserfs_insert_item: "
2092 "key %K already exists in the tree", 2056 "key %K already exists in the tree",
2093 key); 2057 key);
2094 retval = -EEXIST; 2058 retval = -EEXIST;
@@ -2098,7 +2062,7 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2098 2062
2099 /* make balancing after all resources will be collected at a time */ 2063 /* make balancing after all resources will be collected at a time */
2100 if (retval == CARRY_ON) { 2064 if (retval == CARRY_ON) {
2101 do_balance(&s_ins_balance, p_s_ih, p_c_body, M_INSERT); 2065 do_balance(&s_ins_balance, ih, body, M_INSERT);
2102 return 0; 2066 return 0;
2103 } 2067 }
2104 2068
@@ -2109,9 +2073,9 @@ int reiserfs_insert_item(struct reiserfs_transaction_handle *th, struct treepath
2109#ifdef REISERQUOTA_DEBUG 2073#ifdef REISERQUOTA_DEBUG
2110 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE, 2074 reiserfs_debug(th->t_super, REISERFS_DEBUG_CODE,
2111 "reiserquota insert_item(): freeing %u id=%u type=%c", 2075 "reiserquota insert_item(): freeing %u id=%u type=%c",
2112 quota_bytes, inode->i_uid, head2type(p_s_ih)); 2076 quota_bytes, inode->i_uid, head2type(ih));
2113#endif 2077#endif
2114 if (inode) 2078 if (inode)
2115 DQUOT_FREE_SPACE_NODIRTY(inode, quota_bytes); 2079 vfs_dq_free_space_nodirty(inode, quota_bytes);
2116 return retval; 2080 return retval;
2117} 2081}
diff --git a/fs/reiserfs/super.c b/fs/reiserfs/super.c
index f3c820b7582..972250c6289 100644
--- a/fs/reiserfs/super.c
+++ b/fs/reiserfs/super.c
@@ -183,9 +183,9 @@ static int finish_unfinished(struct super_block *s)
183 if (REISERFS_SB(s)->s_qf_names[i]) { 183 if (REISERFS_SB(s)->s_qf_names[i]) {
184 int ret = reiserfs_quota_on_mount(s, i); 184 int ret = reiserfs_quota_on_mount(s, i);
185 if (ret < 0) 185 if (ret < 0)
186 reiserfs_warning(s, 186 reiserfs_warning(s, "reiserfs-2500",
187 "reiserfs: cannot turn on journaled quota: error %d", 187 "cannot turn on journaled "
188 ret); 188 "quota: error %d", ret);
189 } 189 }
190 } 190 }
191#endif 191#endif
@@ -195,17 +195,16 @@ static int finish_unfinished(struct super_block *s)
195 while (!retval) { 195 while (!retval) {
196 retval = search_item(s, &max_cpu_key, &path); 196 retval = search_item(s, &max_cpu_key, &path);
197 if (retval != ITEM_NOT_FOUND) { 197 if (retval != ITEM_NOT_FOUND) {
198 reiserfs_warning(s, 198 reiserfs_error(s, "vs-2140",
199 "vs-2140: finish_unfinished: search_by_key returned %d", 199 "search_by_key returned %d", retval);
200 retval);
201 break; 200 break;
202 } 201 }
203 202
204 bh = get_last_bh(&path); 203 bh = get_last_bh(&path);
205 item_pos = get_item_pos(&path); 204 item_pos = get_item_pos(&path);
206 if (item_pos != B_NR_ITEMS(bh)) { 205 if (item_pos != B_NR_ITEMS(bh)) {
207 reiserfs_warning(s, 206 reiserfs_warning(s, "vs-2060",
208 "vs-2060: finish_unfinished: wrong position found"); 207 "wrong position found");
209 break; 208 break;
210 } 209 }
211 item_pos--; 210 item_pos--;
@@ -235,8 +234,7 @@ static int finish_unfinished(struct super_block *s)
235 if (!inode) { 234 if (!inode) {
236 /* the unlink almost completed, it just did not manage to remove 235 /* the unlink almost completed, it just did not manage to remove
237 "save" link and release objectid */ 236 "save" link and release objectid */
238 reiserfs_warning(s, 237 reiserfs_warning(s, "vs-2180", "iget failed for %K",
239 "vs-2180: finish_unfinished: iget failed for %K",
240 &obj_key); 238 &obj_key);
241 retval = remove_save_link_only(s, &save_link_key, 1); 239 retval = remove_save_link_only(s, &save_link_key, 1);
242 continue; 240 continue;
@@ -244,21 +242,22 @@ static int finish_unfinished(struct super_block *s)
244 242
245 if (!truncate && inode->i_nlink) { 243 if (!truncate && inode->i_nlink) {
246 /* file is not unlinked */ 244 /* file is not unlinked */
247 reiserfs_warning(s, 245 reiserfs_warning(s, "vs-2185",
248 "vs-2185: finish_unfinished: file %K is not unlinked", 246 "file %K is not unlinked",
249 &obj_key); 247 &obj_key);
250 retval = remove_save_link_only(s, &save_link_key, 0); 248 retval = remove_save_link_only(s, &save_link_key, 0);
251 continue; 249 continue;
252 } 250 }
253 DQUOT_INIT(inode); 251 vfs_dq_init(inode);
254 252
255 if (truncate && S_ISDIR(inode->i_mode)) { 253 if (truncate && S_ISDIR(inode->i_mode)) {
256 /* We got a truncate request for a dir which is impossible. 254 /* We got a truncate request for a dir which is impossible.
257 The only imaginable way is to execute unfinished truncate request 255 The only imaginable way is to execute unfinished truncate request
258 then boot into old kernel, remove the file and create dir with 256 then boot into old kernel, remove the file and create dir with
259 the same key. */ 257 the same key. */
260 reiserfs_warning(s, 258 reiserfs_warning(s, "green-2101",
261 "green-2101: impossible truncate on a directory %k. Please report", 259 "impossible truncate on a "
260 "directory %k. Please report",
262 INODE_PKEY(inode)); 261 INODE_PKEY(inode));
263 retval = remove_save_link_only(s, &save_link_key, 0); 262 retval = remove_save_link_only(s, &save_link_key, 0);
264 truncate = 0; 263 truncate = 0;
@@ -288,9 +287,10 @@ static int finish_unfinished(struct super_block *s)
288 /* removal gets completed in iput */ 287 /* removal gets completed in iput */
289 retval = 0; 288 retval = 0;
290 } else { 289 } else {
291 reiserfs_warning(s, "Dead loop in " 290 reiserfs_warning(s, "super-2189", "Dead loop "
292 "finish_unfinished detected, " 291 "in finish_unfinished "
293 "just remove save link\n"); 292 "detected, just remove "
293 "save link\n");
294 retval = remove_save_link_only(s, 294 retval = remove_save_link_only(s,
295 &save_link_key, 0); 295 &save_link_key, 0);
296 } 296 }
@@ -360,8 +360,9 @@ void add_save_link(struct reiserfs_transaction_handle *th,
360 } else { 360 } else {
361 /* truncate */ 361 /* truncate */
362 if (S_ISDIR(inode->i_mode)) 362 if (S_ISDIR(inode->i_mode))
363 reiserfs_warning(inode->i_sb, 363 reiserfs_warning(inode->i_sb, "green-2102",
364 "green-2102: Adding a truncate savelink for a directory %k! Please report", 364 "Adding a truncate savelink for "
365 "a directory %k! Please report",
365 INODE_PKEY(inode)); 366 INODE_PKEY(inode));
366 set_cpu_key_k_offset(&key, 1); 367 set_cpu_key_k_offset(&key, 1);
367 set_cpu_key_k_type(&key, TYPE_INDIRECT); 368 set_cpu_key_k_type(&key, TYPE_INDIRECT);
@@ -376,9 +377,9 @@ void add_save_link(struct reiserfs_transaction_handle *th,
376 retval = search_item(inode->i_sb, &key, &path); 377 retval = search_item(inode->i_sb, &key, &path);
377 if (retval != ITEM_NOT_FOUND) { 378 if (retval != ITEM_NOT_FOUND) {
378 if (retval != -ENOSPC) 379 if (retval != -ENOSPC)
379 reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:" 380 reiserfs_error(inode->i_sb, "vs-2100",
380 "search_by_key (%K) returned %d", &key, 381 "search_by_key (%K) returned %d", &key,
381 retval); 382 retval);
382 pathrelse(&path); 383 pathrelse(&path);
383 return; 384 return;
384 } 385 }
@@ -391,9 +392,8 @@ void add_save_link(struct reiserfs_transaction_handle *th,
391 reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link); 392 reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
392 if (retval) { 393 if (retval) {
393 if (retval != -ENOSPC) 394 if (retval != -ENOSPC)
394 reiserfs_warning(inode->i_sb, 395 reiserfs_error(inode->i_sb, "vs-2120",
395 "vs-2120: add_save_link: insert_item returned %d", 396 "insert_item returned %d", retval);
396 retval);
397 } else { 397 } else {
398 if (truncate) 398 if (truncate)
399 REISERFS_I(inode)->i_flags |= 399 REISERFS_I(inode)->i_flags |=
@@ -492,8 +492,7 @@ static void reiserfs_put_super(struct super_block *s)
492 print_statistics(s); 492 print_statistics(s);
493 493
494 if (REISERFS_SB(s)->reserved_blocks != 0) { 494 if (REISERFS_SB(s)->reserved_blocks != 0) {
495 reiserfs_warning(s, 495 reiserfs_warning(s, "green-2005", "reserved blocks left %d",
496 "green-2005: reiserfs_put_super: reserved blocks left %d",
497 REISERFS_SB(s)->reserved_blocks); 496 REISERFS_SB(s)->reserved_blocks);
498 } 497 }
499 498
@@ -559,8 +558,8 @@ static void reiserfs_dirty_inode(struct inode *inode)
559 558
560 int err = 0; 559 int err = 0;
561 if (inode->i_sb->s_flags & MS_RDONLY) { 560 if (inode->i_sb->s_flags & MS_RDONLY) {
562 reiserfs_warning(inode->i_sb, 561 reiserfs_warning(inode->i_sb, "clm-6006",
563 "clm-6006: writing inode %lu on readonly FS", 562 "writing inode %lu on readonly FS",
564 inode->i_ino); 563 inode->i_ino);
565 return; 564 return;
566 } 565 }
@@ -629,8 +628,6 @@ static const struct super_operations reiserfs_sops = {
629#ifdef CONFIG_QUOTA 628#ifdef CONFIG_QUOTA
630#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group") 629#define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
631 630
632static int reiserfs_dquot_initialize(struct inode *, int);
633static int reiserfs_dquot_drop(struct inode *);
634static int reiserfs_write_dquot(struct dquot *); 631static int reiserfs_write_dquot(struct dquot *);
635static int reiserfs_acquire_dquot(struct dquot *); 632static int reiserfs_acquire_dquot(struct dquot *);
636static int reiserfs_release_dquot(struct dquot *); 633static int reiserfs_release_dquot(struct dquot *);
@@ -639,8 +636,8 @@ static int reiserfs_write_info(struct super_block *, int);
639static int reiserfs_quota_on(struct super_block *, int, int, char *, int); 636static int reiserfs_quota_on(struct super_block *, int, int, char *, int);
640 637
641static struct dquot_operations reiserfs_quota_operations = { 638static struct dquot_operations reiserfs_quota_operations = {
642 .initialize = reiserfs_dquot_initialize, 639 .initialize = dquot_initialize,
643 .drop = reiserfs_dquot_drop, 640 .drop = dquot_drop,
644 .alloc_space = dquot_alloc_space, 641 .alloc_space = dquot_alloc_space,
645 .alloc_inode = dquot_alloc_inode, 642 .alloc_inode = dquot_alloc_inode,
646 .free_space = dquot_free_space, 643 .free_space = dquot_free_space,
@@ -759,7 +756,7 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
759 char **opt_arg, unsigned long *bit_flags) 756 char **opt_arg, unsigned long *bit_flags)
760{ 757{
761 char *p; 758 char *p;
762 /* foo=bar, 759 /* foo=bar,
763 ^ ^ ^ 760 ^ ^ ^
764 | | +-- option_end 761 | | +-- option_end
765 | +-- arg_start 762 | +-- arg_start
@@ -794,13 +791,15 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
794 if (bit_flags) { 791 if (bit_flags) {
795 if (opt->clrmask == 792 if (opt->clrmask ==
796 (1 << REISERFS_UNSUPPORTED_OPT)) 793 (1 << REISERFS_UNSUPPORTED_OPT))
797 reiserfs_warning(s, "%s not supported.", 794 reiserfs_warning(s, "super-6500",
795 "%s not supported.\n",
798 p); 796 p);
799 else 797 else
800 *bit_flags &= ~opt->clrmask; 798 *bit_flags &= ~opt->clrmask;
801 if (opt->setmask == 799 if (opt->setmask ==
802 (1 << REISERFS_UNSUPPORTED_OPT)) 800 (1 << REISERFS_UNSUPPORTED_OPT))
803 reiserfs_warning(s, "%s not supported.", 801 reiserfs_warning(s, "super-6501",
802 "%s not supported.\n",
804 p); 803 p);
805 else 804 else
806 *bit_flags |= opt->setmask; 805 *bit_flags |= opt->setmask;
@@ -809,7 +808,8 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
809 } 808 }
810 } 809 }
811 if (!opt->option_name) { 810 if (!opt->option_name) {
812 reiserfs_warning(s, "unknown mount option \"%s\"", p); 811 reiserfs_warning(s, "super-6502",
812 "unknown mount option \"%s\"", p);
813 return -1; 813 return -1;
814 } 814 }
815 815
@@ -817,8 +817,9 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
817 switch (*p) { 817 switch (*p) {
818 case '=': 818 case '=':
819 if (!opt->arg_required) { 819 if (!opt->arg_required) {
820 reiserfs_warning(s, 820 reiserfs_warning(s, "super-6503",
821 "the option \"%s\" does not require an argument", 821 "the option \"%s\" does not "
822 "require an argument\n",
822 opt->option_name); 823 opt->option_name);
823 return -1; 824 return -1;
824 } 825 }
@@ -826,14 +827,15 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
826 827
827 case 0: 828 case 0:
828 if (opt->arg_required) { 829 if (opt->arg_required) {
829 reiserfs_warning(s, 830 reiserfs_warning(s, "super-6504",
830 "the option \"%s\" requires an argument", 831 "the option \"%s\" requires an "
831 opt->option_name); 832 "argument\n", opt->option_name);
832 return -1; 833 return -1;
833 } 834 }
834 break; 835 break;
835 default: 836 default:
836 reiserfs_warning(s, "head of option \"%s\" is only correct", 837 reiserfs_warning(s, "super-6505",
838 "head of option \"%s\" is only correct\n",
837 opt->option_name); 839 opt->option_name);
838 return -1; 840 return -1;
839 } 841 }
@@ -845,7 +847,8 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
845 && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY)) 847 && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
846 && !strlen(p)) { 848 && !strlen(p)) {
847 /* this catches "option=," if not allowed */ 849 /* this catches "option=," if not allowed */
848 reiserfs_warning(s, "empty argument for \"%s\"", 850 reiserfs_warning(s, "super-6506",
851 "empty argument for \"%s\"\n",
849 opt->option_name); 852 opt->option_name);
850 return -1; 853 return -1;
851 } 854 }
@@ -867,7 +870,8 @@ static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
867 } 870 }
868 } 871 }
869 872
870 reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p, 873 reiserfs_warning(s, "super-6506",
874 "bad value \"%s\" for option \"%s\"\n", p,
871 opt->option_name); 875 opt->option_name);
872 return -1; 876 return -1;
873} 877}
@@ -957,9 +961,9 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
957 *blocks = simple_strtoul(arg, &p, 0); 961 *blocks = simple_strtoul(arg, &p, 0);
958 if (*p != '\0') { 962 if (*p != '\0') {
959 /* NNN does not look like a number */ 963 /* NNN does not look like a number */
960 reiserfs_warning(s, 964 reiserfs_warning(s, "super-6507",
961 "reiserfs_parse_options: bad value %s", 965 "bad value %s for "
962 arg); 966 "-oresize\n", arg);
963 return 0; 967 return 0;
964 } 968 }
965 } 969 }
@@ -970,8 +974,8 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
970 unsigned long val = simple_strtoul(arg, &p, 0); 974 unsigned long val = simple_strtoul(arg, &p, 0);
971 /* commit=NNN (time in seconds) */ 975 /* commit=NNN (time in seconds) */
972 if (*p != '\0' || val >= (unsigned int)-1) { 976 if (*p != '\0' || val >= (unsigned int)-1) {
973 reiserfs_warning(s, 977 reiserfs_warning(s, "super-6508",
974 "reiserfs_parse_options: bad value %s", 978 "bad value %s for -ocommit\n",
975 arg); 979 arg);
976 return 0; 980 return 0;
977 } 981 }
@@ -979,16 +983,18 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
979 } 983 }
980 984
981 if (c == 'w') { 985 if (c == 'w') {
982 reiserfs_warning(s, "reiserfs: nolargeio option is no longer supported"); 986 reiserfs_warning(s, "super-6509", "nolargeio option "
987 "is no longer supported");
983 return 0; 988 return 0;
984 } 989 }
985 990
986 if (c == 'j') { 991 if (c == 'j') {
987 if (arg && *arg && jdev_name) { 992 if (arg && *arg && jdev_name) {
988 if (*jdev_name) { //Hm, already assigned? 993 if (*jdev_name) { //Hm, already assigned?
989 reiserfs_warning(s, 994 reiserfs_warning(s, "super-6510",
990 "reiserfs_parse_options: journal device was already specified to be %s", 995 "journal device was "
991 *jdev_name); 996 "already specified to "
997 "be %s", *jdev_name);
992 return 0; 998 return 0;
993 } 999 }
994 *jdev_name = arg; 1000 *jdev_name = arg;
@@ -1000,29 +1006,35 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
1000 1006
1001 if (sb_any_quota_loaded(s) && 1007 if (sb_any_quota_loaded(s) &&
1002 (!*arg != !REISERFS_SB(s)->s_qf_names[qtype])) { 1008 (!*arg != !REISERFS_SB(s)->s_qf_names[qtype])) {
1003 reiserfs_warning(s, 1009 reiserfs_warning(s, "super-6511",
1004 "reiserfs_parse_options: cannot change journaled quota options when quota turned on."); 1010 "cannot change journaled "
1011 "quota options when quota "
1012 "turned on.");
1005 return 0; 1013 return 0;
1006 } 1014 }
1007 if (*arg) { /* Some filename specified? */ 1015 if (*arg) { /* Some filename specified? */
1008 if (REISERFS_SB(s)->s_qf_names[qtype] 1016 if (REISERFS_SB(s)->s_qf_names[qtype]
1009 && strcmp(REISERFS_SB(s)->s_qf_names[qtype], 1017 && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
1010 arg)) { 1018 arg)) {
1011 reiserfs_warning(s, 1019 reiserfs_warning(s, "super-6512",
1012 "reiserfs_parse_options: %s quota file already specified.", 1020 "%s quota file "
1021 "already specified.",
1013 QTYPE2NAME(qtype)); 1022 QTYPE2NAME(qtype));
1014 return 0; 1023 return 0;
1015 } 1024 }
1016 if (strchr(arg, '/')) { 1025 if (strchr(arg, '/')) {
1017 reiserfs_warning(s, 1026 reiserfs_warning(s, "super-6513",
1018 "reiserfs_parse_options: quotafile must be on filesystem root."); 1027 "quotafile must be "
1028 "on filesystem root.");
1019 return 0; 1029 return 0;
1020 } 1030 }
1021 qf_names[qtype] = 1031 qf_names[qtype] =
1022 kmalloc(strlen(arg) + 1, GFP_KERNEL); 1032 kmalloc(strlen(arg) + 1, GFP_KERNEL);
1023 if (!qf_names[qtype]) { 1033 if (!qf_names[qtype]) {
1024 reiserfs_warning(s, 1034 reiserfs_warning(s, "reiserfs-2502",
1025 "reiserfs_parse_options: not enough memory for storing quotafile name."); 1035 "not enough memory "
1036 "for storing "
1037 "quotafile name.");
1026 return 0; 1038 return 0;
1027 } 1039 }
1028 strcpy(qf_names[qtype], arg); 1040 strcpy(qf_names[qtype], arg);
@@ -1040,21 +1052,24 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
1040 else if (!strcmp(arg, "vfsv0")) 1052 else if (!strcmp(arg, "vfsv0"))
1041 *qfmt = QFMT_VFS_V0; 1053 *qfmt = QFMT_VFS_V0;
1042 else { 1054 else {
1043 reiserfs_warning(s, 1055 reiserfs_warning(s, "super-6514",
1044 "reiserfs_parse_options: unknown quota format specified."); 1056 "unknown quota format "
1057 "specified.");
1045 return 0; 1058 return 0;
1046 } 1059 }
1047 if (sb_any_quota_loaded(s) && 1060 if (sb_any_quota_loaded(s) &&
1048 *qfmt != REISERFS_SB(s)->s_jquota_fmt) { 1061 *qfmt != REISERFS_SB(s)->s_jquota_fmt) {
1049 reiserfs_warning(s, 1062 reiserfs_warning(s, "super-6515",
1050 "reiserfs_parse_options: cannot change journaled quota options when quota turned on."); 1063 "cannot change journaled "
1064 "quota options when quota "
1065 "turned on.");
1051 return 0; 1066 return 0;
1052 } 1067 }
1053 } 1068 }
1054#else 1069#else
1055 if (c == 'u' || c == 'g' || c == 'f') { 1070 if (c == 'u' || c == 'g' || c == 'f') {
1056 reiserfs_warning(s, 1071 reiserfs_warning(s, "reiserfs-2503", "journaled "
1057 "reiserfs_parse_options: journaled quota options not supported."); 1072 "quota options not supported.");
1058 return 0; 1073 return 0;
1059 } 1074 }
1060#endif 1075#endif
@@ -1063,15 +1078,15 @@ static int reiserfs_parse_options(struct super_block *s, char *options, /* strin
1063#ifdef CONFIG_QUOTA 1078#ifdef CONFIG_QUOTA
1064 if (!REISERFS_SB(s)->s_jquota_fmt && !*qfmt 1079 if (!REISERFS_SB(s)->s_jquota_fmt && !*qfmt
1065 && (qf_names[USRQUOTA] || qf_names[GRPQUOTA])) { 1080 && (qf_names[USRQUOTA] || qf_names[GRPQUOTA])) {
1066 reiserfs_warning(s, 1081 reiserfs_warning(s, "super-6515",
1067 "reiserfs_parse_options: journaled quota format not specified."); 1082 "journaled quota format not specified.");
1068 return 0; 1083 return 0;
1069 } 1084 }
1070 /* This checking is not precise wrt the quota type but for our purposes it is sufficient */ 1085 /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
1071 if (!(*mount_options & (1 << REISERFS_QUOTA)) 1086 if (!(*mount_options & (1 << REISERFS_QUOTA))
1072 && sb_any_quota_loaded(s)) { 1087 && sb_any_quota_loaded(s)) {
1073 reiserfs_warning(s, 1088 reiserfs_warning(s, "super-6516", "quota options must "
1074 "reiserfs_parse_options: quota options must be present when quota is turned on."); 1089 "be present when quota is turned on.");
1075 return 0; 1090 return 0;
1076 } 1091 }
1077#endif 1092#endif
@@ -1131,14 +1146,15 @@ static void handle_attrs(struct super_block *s)
1131 1146
1132 if (reiserfs_attrs(s)) { 1147 if (reiserfs_attrs(s)) {
1133 if (old_format_only(s)) { 1148 if (old_format_only(s)) {
1134 reiserfs_warning(s, 1149 reiserfs_warning(s, "super-6517", "cannot support "
1135 "reiserfs: cannot support attributes on 3.5.x disk format"); 1150 "attributes on 3.5.x disk format");
1136 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS); 1151 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1137 return; 1152 return;
1138 } 1153 }
1139 if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) { 1154 if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
1140 reiserfs_warning(s, 1155 reiserfs_warning(s, "super-6518", "cannot support "
1141 "reiserfs: cannot support attributes until flag is set in super-block"); 1156 "attributes until flag is set in "
1157 "super-block");
1142 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS); 1158 REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
1143 } 1159 }
1144 } 1160 }
@@ -1280,6 +1296,8 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
1280 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs); 1296 REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
1281 s->s_flags &= ~MS_RDONLY; 1297 s->s_flags &= ~MS_RDONLY;
1282 set_sb_umount_state(rs, REISERFS_ERROR_FS); 1298 set_sb_umount_state(rs, REISERFS_ERROR_FS);
1299 if (!old_format_only(s))
1300 set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
1283 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */ 1301 /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
1284 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s)); 1302 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1285 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS; 1303 REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
@@ -1314,7 +1332,7 @@ static int read_super_block(struct super_block *s, int offset)
1314 1332
1315 bh = sb_bread(s, offset / s->s_blocksize); 1333 bh = sb_bread(s, offset / s->s_blocksize);
1316 if (!bh) { 1334 if (!bh) {
1317 reiserfs_warning(s, "sh-2006: read_super_block: " 1335 reiserfs_warning(s, "sh-2006",
1318 "bread failed (dev %s, block %lu, size %lu)", 1336 "bread failed (dev %s, block %lu, size %lu)",
1319 reiserfs_bdevname(s), offset / s->s_blocksize, 1337 reiserfs_bdevname(s), offset / s->s_blocksize,
1320 s->s_blocksize); 1338 s->s_blocksize);
@@ -1328,15 +1346,15 @@ static int read_super_block(struct super_block *s, int offset)
1328 } 1346 }
1329 // 1347 //
1330 // ok, reiserfs signature (old or new) found in at the given offset 1348 // ok, reiserfs signature (old or new) found in at the given offset
1331 // 1349 //
1332 fs_blocksize = sb_blocksize(rs); 1350 fs_blocksize = sb_blocksize(rs);
1333 brelse(bh); 1351 brelse(bh);
1334 sb_set_blocksize(s, fs_blocksize); 1352 sb_set_blocksize(s, fs_blocksize);
1335 1353
1336 bh = sb_bread(s, offset / s->s_blocksize); 1354 bh = sb_bread(s, offset / s->s_blocksize);
1337 if (!bh) { 1355 if (!bh) {
1338 reiserfs_warning(s, "sh-2007: read_super_block: " 1356 reiserfs_warning(s, "sh-2007",
1339 "bread failed (dev %s, block %lu, size %lu)\n", 1357 "bread failed (dev %s, block %lu, size %lu)",
1340 reiserfs_bdevname(s), offset / s->s_blocksize, 1358 reiserfs_bdevname(s), offset / s->s_blocksize,
1341 s->s_blocksize); 1359 s->s_blocksize);
1342 return 1; 1360 return 1;
@@ -1344,8 +1362,8 @@ static int read_super_block(struct super_block *s, int offset)
1344 1362
1345 rs = (struct reiserfs_super_block *)bh->b_data; 1363 rs = (struct reiserfs_super_block *)bh->b_data;
1346 if (sb_blocksize(rs) != s->s_blocksize) { 1364 if (sb_blocksize(rs) != s->s_blocksize) {
1347 reiserfs_warning(s, "sh-2011: read_super_block: " 1365 reiserfs_warning(s, "sh-2011", "can't find a reiserfs "
1348 "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n", 1366 "filesystem on (dev %s, block %Lu, size %lu)",
1349 reiserfs_bdevname(s), 1367 reiserfs_bdevname(s),
1350 (unsigned long long)bh->b_blocknr, 1368 (unsigned long long)bh->b_blocknr,
1351 s->s_blocksize); 1369 s->s_blocksize);
@@ -1355,9 +1373,10 @@ static int read_super_block(struct super_block *s, int offset)
1355 1373
1356 if (rs->s_v1.s_root_block == cpu_to_le32(-1)) { 1374 if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
1357 brelse(bh); 1375 brelse(bh);
1358 reiserfs_warning(s, 1376 reiserfs_warning(s, "super-6519", "Unfinished reiserfsck "
1359 "Unfinished reiserfsck --rebuild-tree run detected. Please run\n" 1377 "--rebuild-tree run detected. Please run\n"
1360 "reiserfsck --rebuild-tree and wait for a completion. If that fails\n" 1378 "reiserfsck --rebuild-tree and wait for a "
1379 "completion. If that fails\n"
1361 "get newer reiserfsprogs package"); 1380 "get newer reiserfsprogs package");
1362 return 1; 1381 return 1;
1363 } 1382 }
@@ -1369,18 +1388,15 @@ static int read_super_block(struct super_block *s, int offset)
1369 /* magic is of non-standard journal filesystem, look at s_version to 1388 /* magic is of non-standard journal filesystem, look at s_version to
1370 find which format is in use */ 1389 find which format is in use */
1371 if (sb_version(rs) == REISERFS_VERSION_2) 1390 if (sb_version(rs) == REISERFS_VERSION_2)
1372 reiserfs_warning(s, 1391 reiserfs_info(s, "found reiserfs format \"3.6\""
1373 "read_super_block: found reiserfs format \"3.6\"" 1392 " with non-standard journal\n");
1374 " with non-standard journal");
1375 else if (sb_version(rs) == REISERFS_VERSION_1) 1393 else if (sb_version(rs) == REISERFS_VERSION_1)
1376 reiserfs_warning(s, 1394 reiserfs_info(s, "found reiserfs format \"3.5\""
1377 "read_super_block: found reiserfs format \"3.5\"" 1395 " with non-standard journal\n");
1378 " with non-standard journal");
1379 else { 1396 else {
1380 reiserfs_warning(s, 1397 reiserfs_warning(s, "sh-2012", "found unknown "
1381 "sh-2012: read_super_block: found unknown " 1398 "format \"%u\" of reiserfs with "
1382 "format \"%u\" of reiserfs with non-standard magic", 1399 "non-standard magic", sb_version(rs));
1383 sb_version(rs));
1384 return 1; 1400 return 1;
1385 } 1401 }
1386 } else 1402 } else
@@ -1410,8 +1426,7 @@ static int reread_meta_blocks(struct super_block *s)
1410 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s))); 1426 ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
1411 wait_on_buffer(SB_BUFFER_WITH_SB(s)); 1427 wait_on_buffer(SB_BUFFER_WITH_SB(s));
1412 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) { 1428 if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
1413 reiserfs_warning(s, 1429 reiserfs_warning(s, "reiserfs-2504", "error reading the super");
1414 "reread_meta_blocks, error reading the super");
1415 return 1; 1430 return 1;
1416 } 1431 }
1417 1432
@@ -1454,8 +1469,8 @@ static __u32 find_hash_out(struct super_block *s)
1454 if (reiserfs_rupasov_hash(s)) { 1469 if (reiserfs_rupasov_hash(s)) {
1455 hash = YURA_HASH; 1470 hash = YURA_HASH;
1456 } 1471 }
1457 reiserfs_warning(s, "FS seems to be empty, autodetect " 1472 reiserfs_info(s, "FS seems to be empty, autodetect "
1458 "is using the default hash"); 1473 "is using the default hash\n");
1459 break; 1474 break;
1460 } 1475 }
1461 r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen)); 1476 r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
@@ -1475,10 +1490,10 @@ static __u32 find_hash_out(struct super_block *s)
1475 && (yurahash == 1490 && (yurahash ==
1476 GET_HASH_VALUE(deh_offset 1491 GET_HASH_VALUE(deh_offset
1477 (&(de.de_deh[de.de_entry_num])))))) { 1492 (&(de.de_deh[de.de_entry_num])))))) {
1478 reiserfs_warning(s, 1493 reiserfs_warning(s, "reiserfs-2506", "Unable to "
1479 "Unable to automatically detect hash function. " 1494 "automatically detect hash function. "
1480 "Please mount with -o hash={tea,rupasov,r5}", 1495 "Please mount with -o "
1481 reiserfs_bdevname(s)); 1496 "hash={tea,rupasov,r5}");
1482 hash = UNSET_HASH; 1497 hash = UNSET_HASH;
1483 break; 1498 break;
1484 } 1499 }
@@ -1492,7 +1507,8 @@ static __u32 find_hash_out(struct super_block *s)
1492 (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash) 1507 (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
1493 hash = R5_HASH; 1508 hash = R5_HASH;
1494 else { 1509 else {
1495 reiserfs_warning(s, "Unrecognised hash function"); 1510 reiserfs_warning(s, "reiserfs-2506",
1511 "Unrecognised hash function");
1496 hash = UNSET_HASH; 1512 hash = UNSET_HASH;
1497 } 1513 }
1498 } while (0); 1514 } while (0);
@@ -1516,21 +1532,24 @@ static int what_hash(struct super_block *s)
1516 code = find_hash_out(s); 1532 code = find_hash_out(s);
1517 1533
1518 if (code != UNSET_HASH && reiserfs_hash_detect(s)) { 1534 if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
1519 /* detection has found the hash, and we must check against the 1535 /* detection has found the hash, and we must check against the
1520 ** mount options 1536 ** mount options
1521 */ 1537 */
1522 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) { 1538 if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
1523 reiserfs_warning(s, "Error, %s hash detected, " 1539 reiserfs_warning(s, "reiserfs-2507",
1540 "Error, %s hash detected, "
1524 "unable to force rupasov hash", 1541 "unable to force rupasov hash",
1525 reiserfs_hashname(code)); 1542 reiserfs_hashname(code));
1526 code = UNSET_HASH; 1543 code = UNSET_HASH;
1527 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) { 1544 } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
1528 reiserfs_warning(s, "Error, %s hash detected, " 1545 reiserfs_warning(s, "reiserfs-2508",
1546 "Error, %s hash detected, "
1529 "unable to force tea hash", 1547 "unable to force tea hash",
1530 reiserfs_hashname(code)); 1548 reiserfs_hashname(code));
1531 code = UNSET_HASH; 1549 code = UNSET_HASH;
1532 } else if (reiserfs_r5_hash(s) && code != R5_HASH) { 1550 } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
1533 reiserfs_warning(s, "Error, %s hash detected, " 1551 reiserfs_warning(s, "reiserfs-2509",
1552 "Error, %s hash detected, "
1534 "unable to force r5 hash", 1553 "unable to force r5 hash",
1535 reiserfs_hashname(code)); 1554 reiserfs_hashname(code));
1536 code = UNSET_HASH; 1555 code = UNSET_HASH;
@@ -1546,7 +1565,7 @@ static int what_hash(struct super_block *s)
1546 } 1565 }
1547 } 1566 }
1548 1567
1549 /* if we are mounted RW, and we have a new valid hash code, update 1568 /* if we are mounted RW, and we have a new valid hash code, update
1550 ** the super 1569 ** the super
1551 */ 1570 */
1552 if (code != UNSET_HASH && 1571 if (code != UNSET_HASH &&
@@ -1589,9 +1608,9 @@ static int function2code(hashf_t func)
1589 return 0; 1608 return 0;
1590} 1609}
1591 1610
1592#define SWARN(silent, s, ...) \ 1611#define SWARN(silent, s, id, ...) \
1593 if (!(silent)) \ 1612 if (!(silent)) \
1594 reiserfs_warning (s, __VA_ARGS__) 1613 reiserfs_warning(s, id, __VA_ARGS__)
1595 1614
1596static int reiserfs_fill_super(struct super_block *s, void *data, int silent) 1615static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1597{ 1616{
@@ -1625,10 +1644,6 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1625 REISERFS_SB(s)->s_alloc_options.preallocmin = 0; 1644 REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
1626 /* Preallocate by 16 blocks (17-1) at once */ 1645 /* Preallocate by 16 blocks (17-1) at once */
1627 REISERFS_SB(s)->s_alloc_options.preallocsize = 17; 1646 REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
1628#ifdef CONFIG_REISERFS_FS_XATTR
1629 /* Initialize the rwsem for xattr dir */
1630 init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
1631#endif
1632 /* setup default block allocator options */ 1647 /* setup default block allocator options */
1633 reiserfs_init_alloc_options(s); 1648 reiserfs_init_alloc_options(s);
1634 1649
@@ -1643,8 +1658,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1643#endif 1658#endif
1644 1659
1645 if (blocks) { 1660 if (blocks) {
1646 SWARN(silent, s, "jmacd-7: reiserfs_fill_super: resize option " 1661 SWARN(silent, s, "jmacd-7", "resize option for remount only");
1647 "for remount only");
1648 goto error; 1662 goto error;
1649 } 1663 }
1650 1664
@@ -1653,8 +1667,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1653 old_format = 1; 1667 old_format = 1;
1654 /* try new format (64-th 1k block), which can contain reiserfs super block */ 1668 /* try new format (64-th 1k block), which can contain reiserfs super block */
1655 else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) { 1669 else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
1656 SWARN(silent, s, 1670 SWARN(silent, s, "sh-2021", "can not find reiserfs on %s",
1657 "sh-2021: reiserfs_fill_super: can not find reiserfs on %s",
1658 reiserfs_bdevname(s)); 1671 reiserfs_bdevname(s));
1659 goto error; 1672 goto error;
1660 } 1673 }
@@ -1666,13 +1679,12 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1666 if (s->s_bdev && s->s_bdev->bd_inode 1679 if (s->s_bdev && s->s_bdev->bd_inode
1667 && i_size_read(s->s_bdev->bd_inode) < 1680 && i_size_read(s->s_bdev->bd_inode) <
1668 sb_block_count(rs) * sb_blocksize(rs)) { 1681 sb_block_count(rs) * sb_blocksize(rs)) {
1669 SWARN(silent, s, 1682 SWARN(silent, s, "", "Filesystem cannot be "
1670 "Filesystem on %s cannot be mounted because it is bigger than the device", 1683 "mounted because it is bigger than the device");
1671 reiserfs_bdevname(s)); 1684 SWARN(silent, s, "", "You may need to run fsck "
1672 SWARN(silent, s, 1685 "or increase size of your LVM partition");
1673 "You may need to run fsck or increase size of your LVM partition"); 1686 SWARN(silent, s, "", "Or may be you forgot to "
1674 SWARN(silent, s, 1687 "reboot after fdisk when it told you to");
1675 "Or may be you forgot to reboot after fdisk when it told you to");
1676 goto error; 1688 goto error;
1677 } 1689 }
1678 1690
@@ -1680,14 +1692,13 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1680 sbi->s_mount_state = REISERFS_VALID_FS; 1692 sbi->s_mount_state = REISERFS_VALID_FS;
1681 1693
1682 if ((errval = reiserfs_init_bitmap_cache(s))) { 1694 if ((errval = reiserfs_init_bitmap_cache(s))) {
1683 SWARN(silent, s, 1695 SWARN(silent, s, "jmacd-8", "unable to read bitmap");
1684 "jmacd-8: reiserfs_fill_super: unable to read bitmap");
1685 goto error; 1696 goto error;
1686 } 1697 }
1687 errval = -EINVAL; 1698 errval = -EINVAL;
1688#ifdef CONFIG_REISERFS_CHECK 1699#ifdef CONFIG_REISERFS_CHECK
1689 SWARN(silent, s, "CONFIG_REISERFS_CHECK is set ON"); 1700 SWARN(silent, s, "", "CONFIG_REISERFS_CHECK is set ON");
1690 SWARN(silent, s, "- it is slow mode for debugging."); 1701 SWARN(silent, s, "", "- it is slow mode for debugging.");
1691#endif 1702#endif
1692 1703
1693 /* make data=ordered the default */ 1704 /* make data=ordered the default */
@@ -1708,8 +1719,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1708 } 1719 }
1709 // set_device_ro(s->s_dev, 1) ; 1720 // set_device_ro(s->s_dev, 1) ;
1710 if (journal_init(s, jdev_name, old_format, commit_max_age)) { 1721 if (journal_init(s, jdev_name, old_format, commit_max_age)) {
1711 SWARN(silent, s, 1722 SWARN(silent, s, "sh-2022",
1712 "sh-2022: reiserfs_fill_super: unable to initialize journal space"); 1723 "unable to initialize journal space");
1713 goto error; 1724 goto error;
1714 } else { 1725 } else {
1715 jinit_done = 1; /* once this is set, journal_release must be called 1726 jinit_done = 1; /* once this is set, journal_release must be called
@@ -1717,8 +1728,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1717 */ 1728 */
1718 } 1729 }
1719 if (reread_meta_blocks(s)) { 1730 if (reread_meta_blocks(s)) {
1720 SWARN(silent, s, 1731 SWARN(silent, s, "jmacd-9",
1721 "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init"); 1732 "unable to reread meta blocks after journal init");
1722 goto error; 1733 goto error;
1723 } 1734 }
1724 1735
@@ -1726,8 +1737,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1726 goto error; 1737 goto error;
1727 1738
1728 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) { 1739 if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
1729 SWARN(silent, s, 1740 SWARN(silent, s, "clm-7000",
1730 "clm-7000: Detected readonly device, marking FS readonly"); 1741 "Detected readonly device, marking FS readonly");
1731 s->s_flags |= MS_RDONLY; 1742 s->s_flags |= MS_RDONLY;
1732 } 1743 }
1733 args.objectid = REISERFS_ROOT_OBJECTID; 1744 args.objectid = REISERFS_ROOT_OBJECTID;
@@ -1736,8 +1747,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1736 iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor, 1747 iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
1737 reiserfs_init_locked_inode, (void *)(&args)); 1748 reiserfs_init_locked_inode, (void *)(&args));
1738 if (!root_inode) { 1749 if (!root_inode) {
1739 SWARN(silent, s, 1750 SWARN(silent, s, "jmacd-10", "get root inode failed");
1740 "jmacd-10: reiserfs_fill_super: get root inode failed");
1741 goto error; 1751 goto error;
1742 } 1752 }
1743 1753
@@ -1786,7 +1796,7 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1786 * avoiding corruption. -jeffm */ 1796 * avoiding corruption. -jeffm */
1787 if (bmap_would_wrap(reiserfs_bmap_count(s)) && 1797 if (bmap_would_wrap(reiserfs_bmap_count(s)) &&
1788 sb_bmap_nr(rs) != 0) { 1798 sb_bmap_nr(rs) != 0) {
1789 reiserfs_warning(s, "super-2030: This file system " 1799 reiserfs_warning(s, "super-2030", "This file system "
1790 "claims to use %u bitmap blocks in " 1800 "claims to use %u bitmap blocks in "
1791 "its super block, but requires %u. " 1801 "its super block, but requires %u. "
1792 "Clearing to zero.", sb_bmap_nr(rs), 1802 "Clearing to zero.", sb_bmap_nr(rs),
@@ -1819,7 +1829,9 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
1819 } else if (!silent) { 1829 } else if (!silent) {
1820 reiserfs_info(s, "using 3.5.x disk format\n"); 1830 reiserfs_info(s, "using 3.5.x disk format\n");
1821 } 1831 }
1822 } 1832 } else
1833 set_sb_mnt_count(rs, sb_mnt_count(rs) + 1);
1834
1823 1835
1824 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s)); 1836 journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
1825 errval = journal_end(&th, s, 1); 1837 errval = journal_end(&th, s, 1);
@@ -1896,58 +1908,6 @@ static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
1896} 1908}
1897 1909
1898#ifdef CONFIG_QUOTA 1910#ifdef CONFIG_QUOTA
1899static int reiserfs_dquot_initialize(struct inode *inode, int type)
1900{
1901 struct reiserfs_transaction_handle th;
1902 int ret, err;
1903
1904 /* We may create quota structure so we need to reserve enough blocks */
1905 reiserfs_write_lock(inode->i_sb);
1906 ret =
1907 journal_begin(&th, inode->i_sb,
1908 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1909 if (ret)
1910 goto out;
1911 ret = dquot_initialize(inode, type);
1912 err =
1913 journal_end(&th, inode->i_sb,
1914 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
1915 if (!ret && err)
1916 ret = err;
1917 out:
1918 reiserfs_write_unlock(inode->i_sb);
1919 return ret;
1920}
1921
1922static int reiserfs_dquot_drop(struct inode *inode)
1923{
1924 struct reiserfs_transaction_handle th;
1925 int ret, err;
1926
1927 /* We may delete quota structure so we need to reserve enough blocks */
1928 reiserfs_write_lock(inode->i_sb);
1929 ret =
1930 journal_begin(&th, inode->i_sb,
1931 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1932 if (ret) {
1933 /*
1934 * We call dquot_drop() anyway to at least release references
1935 * to quota structures so that umount does not hang.
1936 */
1937 dquot_drop(inode);
1938 goto out;
1939 }
1940 ret = dquot_drop(inode);
1941 err =
1942 journal_end(&th, inode->i_sb,
1943 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
1944 if (!ret && err)
1945 ret = err;
1946 out:
1947 reiserfs_write_unlock(inode->i_sb);
1948 return ret;
1949}
1950
1951static int reiserfs_write_dquot(struct dquot *dquot) 1911static int reiserfs_write_dquot(struct dquot *dquot)
1952{ 1912{
1953 struct reiserfs_transaction_handle th; 1913 struct reiserfs_transaction_handle th;
@@ -2085,8 +2045,8 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2085 if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) { 2045 if (!(REISERFS_I(inode)->i_flags & i_nopack_mask)) {
2086 err = reiserfs_unpack(inode, NULL); 2046 err = reiserfs_unpack(inode, NULL);
2087 if (err) { 2047 if (err) {
2088 reiserfs_warning(sb, 2048 reiserfs_warning(sb, "super-6520",
2089 "reiserfs: Unpacking tail of quota file failed" 2049 "Unpacking tail of quota file failed"
2090 " (%d). Cannot turn on quotas.", err); 2050 " (%d). Cannot turn on quotas.", err);
2091 err = -EINVAL; 2051 err = -EINVAL;
2092 goto out; 2052 goto out;
@@ -2097,8 +2057,8 @@ static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
2097 if (REISERFS_SB(sb)->s_qf_names[type]) { 2057 if (REISERFS_SB(sb)->s_qf_names[type]) {
2098 /* Quotafile not of fs root? */ 2058 /* Quotafile not of fs root? */
2099 if (path.dentry->d_parent != sb->s_root) 2059 if (path.dentry->d_parent != sb->s_root)
2100 reiserfs_warning(sb, 2060 reiserfs_warning(sb, "super-6521",
2101 "reiserfs: Quota file not on filesystem root. " 2061 "Quota file not on filesystem root. "
2102 "Journalled quota will not work."); 2062 "Journalled quota will not work.");
2103 } 2063 }
2104 2064
@@ -2249,9 +2209,6 @@ static int __init init_reiserfs_fs(void)
2249 return ret; 2209 return ret;
2250 } 2210 }
2251 2211
2252 if ((ret = reiserfs_xattr_register_handlers()))
2253 goto failed_reiserfs_xattr_register_handlers;
2254
2255 reiserfs_proc_info_global_init(); 2212 reiserfs_proc_info_global_init();
2256 reiserfs_proc_register_global("version", 2213 reiserfs_proc_register_global("version",
2257 reiserfs_global_version_in_proc); 2214 reiserfs_global_version_in_proc);
@@ -2262,9 +2219,6 @@ static int __init init_reiserfs_fs(void)
2262 return 0; 2219 return 0;
2263 } 2220 }
2264 2221
2265 reiserfs_xattr_unregister_handlers();
2266
2267 failed_reiserfs_xattr_register_handlers:
2268 reiserfs_proc_unregister_global("version"); 2222 reiserfs_proc_unregister_global("version");
2269 reiserfs_proc_info_global_done(); 2223 reiserfs_proc_info_global_done();
2270 destroy_inodecache(); 2224 destroy_inodecache();
@@ -2274,7 +2228,6 @@ static int __init init_reiserfs_fs(void)
2274 2228
2275static void __exit exit_reiserfs_fs(void) 2229static void __exit exit_reiserfs_fs(void)
2276{ 2230{
2277 reiserfs_xattr_unregister_handlers();
2278 reiserfs_proc_unregister_global("version"); 2231 reiserfs_proc_unregister_global("version");
2279 reiserfs_proc_info_global_done(); 2232 reiserfs_proc_info_global_done();
2280 unregister_filesystem(&reiserfs_fs_type); 2233 unregister_filesystem(&reiserfs_fs_type);
diff --git a/fs/reiserfs/tail_conversion.c b/fs/reiserfs/tail_conversion.c
index f8121a1147e..d7f6e51bef2 100644
--- a/fs/reiserfs/tail_conversion.c
+++ b/fs/reiserfs/tail_conversion.c
@@ -26,7 +26,7 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
26 converted item. */ 26 converted item. */
27 struct item_head ind_ih; /* new indirect item to be inserted or 27 struct item_head ind_ih; /* new indirect item to be inserted or
28 key of unfm pointer to be pasted */ 28 key of unfm pointer to be pasted */
29 int n_blk_size, n_retval; /* returned value for reiserfs_insert_item and clones */ 29 int blk_size, retval; /* returned value for reiserfs_insert_item and clones */
30 unp_t unfm_ptr; /* Handle on an unformatted node 30 unp_t unfm_ptr; /* Handle on an unformatted node
31 that will be inserted in the 31 that will be inserted in the
32 tree. */ 32 tree. */
@@ -35,7 +35,7 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
35 35
36 REISERFS_SB(sb)->s_direct2indirect++; 36 REISERFS_SB(sb)->s_direct2indirect++;
37 37
38 n_blk_size = sb->s_blocksize; 38 blk_size = sb->s_blocksize;
39 39
40 /* and key to search for append or insert pointer to the new 40 /* and key to search for append or insert pointer to the new
41 unformatted node. */ 41 unformatted node. */
@@ -46,11 +46,11 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
46 /* Set the key to search for the place for new unfm pointer */ 46 /* Set the key to search for the place for new unfm pointer */
47 make_cpu_key(&end_key, inode, tail_offset, TYPE_INDIRECT, 4); 47 make_cpu_key(&end_key, inode, tail_offset, TYPE_INDIRECT, 4);
48 48
49 // FIXME: we could avoid this 49 /* FIXME: we could avoid this */
50 if (search_for_position_by_key(sb, &end_key, path) == POSITION_FOUND) { 50 if (search_for_position_by_key(sb, &end_key, path) == POSITION_FOUND) {
51 reiserfs_warning(sb, "PAP-14030: direct2indirect: " 51 reiserfs_error(sb, "PAP-14030",
52 "pasted or inserted byte exists in the tree %K. " 52 "pasted or inserted byte exists in "
53 "Use fsck to repair.", &end_key); 53 "the tree %K. Use fsck to repair.", &end_key);
54 pathrelse(path); 54 pathrelse(path);
55 return -EIO; 55 return -EIO;
56 } 56 }
@@ -64,17 +64,17 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
64 set_ih_free_space(&ind_ih, 0); /* delete at nearest future */ 64 set_ih_free_space(&ind_ih, 0); /* delete at nearest future */
65 put_ih_item_len(&ind_ih, UNFM_P_SIZE); 65 put_ih_item_len(&ind_ih, UNFM_P_SIZE);
66 PATH_LAST_POSITION(path)++; 66 PATH_LAST_POSITION(path)++;
67 n_retval = 67 retval =
68 reiserfs_insert_item(th, path, &end_key, &ind_ih, inode, 68 reiserfs_insert_item(th, path, &end_key, &ind_ih, inode,
69 (char *)&unfm_ptr); 69 (char *)&unfm_ptr);
70 } else { 70 } else {
71 /* Paste into last indirect item of an object. */ 71 /* Paste into last indirect item of an object. */
72 n_retval = reiserfs_paste_into_item(th, path, &end_key, inode, 72 retval = reiserfs_paste_into_item(th, path, &end_key, inode,
73 (char *)&unfm_ptr, 73 (char *)&unfm_ptr,
74 UNFM_P_SIZE); 74 UNFM_P_SIZE);
75 } 75 }
76 if (n_retval) { 76 if (retval) {
77 return n_retval; 77 return retval;
78 } 78 }
79 // note: from here there are two keys which have matching first 79 // note: from here there are two keys which have matching first
80 // three key components. They only differ by the fourth one. 80 // three key components. They only differ by the fourth one.
@@ -92,14 +92,13 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
92 last item of the file */ 92 last item of the file */
93 if (search_for_position_by_key(sb, &end_key, path) == 93 if (search_for_position_by_key(sb, &end_key, path) ==
94 POSITION_FOUND) 94 POSITION_FOUND)
95 reiserfs_panic(sb, 95 reiserfs_panic(sb, "PAP-14050",
96 "PAP-14050: direct2indirect: "
97 "direct item (%K) not found", &end_key); 96 "direct item (%K) not found", &end_key);
98 p_le_ih = PATH_PITEM_HEAD(path); 97 p_le_ih = PATH_PITEM_HEAD(path);
99 RFALSE(!is_direct_le_ih(p_le_ih), 98 RFALSE(!is_direct_le_ih(p_le_ih),
100 "vs-14055: direct item expected(%K), found %h", 99 "vs-14055: direct item expected(%K), found %h",
101 &end_key, p_le_ih); 100 &end_key, p_le_ih);
102 tail_size = (le_ih_k_offset(p_le_ih) & (n_blk_size - 1)) 101 tail_size = (le_ih_k_offset(p_le_ih) & (blk_size - 1))
103 + ih_item_len(p_le_ih) - 1; 102 + ih_item_len(p_le_ih) - 1;
104 103
105 /* we only send the unbh pointer if the buffer is not up to date. 104 /* we only send the unbh pointer if the buffer is not up to date.
@@ -114,11 +113,11 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
114 } else { 113 } else {
115 up_to_date_bh = unbh; 114 up_to_date_bh = unbh;
116 } 115 }
117 n_retval = reiserfs_delete_item(th, path, &end_key, inode, 116 retval = reiserfs_delete_item(th, path, &end_key, inode,
118 up_to_date_bh); 117 up_to_date_bh);
119 118
120 total_tail += n_retval; 119 total_tail += retval;
121 if (tail_size == n_retval) 120 if (tail_size == retval)
122 // done: file does not have direct items anymore 121 // done: file does not have direct items anymore
123 break; 122 break;
124 123
@@ -130,7 +129,7 @@ int direct2indirect(struct reiserfs_transaction_handle *th, struct inode *inode,
130 unsigned pgoff = 129 unsigned pgoff =
131 (tail_offset + total_tail - 1) & (PAGE_CACHE_SIZE - 1); 130 (tail_offset + total_tail - 1) & (PAGE_CACHE_SIZE - 1);
132 char *kaddr = kmap_atomic(up_to_date_bh->b_page, KM_USER0); 131 char *kaddr = kmap_atomic(up_to_date_bh->b_page, KM_USER0);
133 memset(kaddr + pgoff, 0, n_blk_size - total_tail); 132 memset(kaddr + pgoff, 0, blk_size - total_tail);
134 kunmap_atomic(kaddr, KM_USER0); 133 kunmap_atomic(kaddr, KM_USER0);
135 } 134 }
136 135
@@ -171,14 +170,18 @@ void reiserfs_unmap_buffer(struct buffer_head *bh)
171 what we expect from it (number of cut bytes). But when tail remains 170 what we expect from it (number of cut bytes). But when tail remains
172 in the unformatted node, we set mode to SKIP_BALANCING and unlock 171 in the unformatted node, we set mode to SKIP_BALANCING and unlock
173 inode */ 172 inode */
174int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_inode, struct page *page, struct treepath *p_s_path, /* path to the indirect item. */ 173int indirect2direct(struct reiserfs_transaction_handle *th,
175 const struct cpu_key *p_s_item_key, /* Key to look for unformatted node pointer to be cut. */ 174 struct inode *inode, struct page *page,
175 struct treepath *path, /* path to the indirect item. */
176 const struct cpu_key *item_key, /* Key to look for
177 * unformatted node
178 * pointer to be cut. */
176 loff_t n_new_file_size, /* New file size. */ 179 loff_t n_new_file_size, /* New file size. */
177 char *p_c_mode) 180 char *mode)
178{ 181{
179 struct super_block *p_s_sb = p_s_inode->i_sb; 182 struct super_block *sb = inode->i_sb;
180 struct item_head s_ih; 183 struct item_head s_ih;
181 unsigned long n_block_size = p_s_sb->s_blocksize; 184 unsigned long block_size = sb->s_blocksize;
182 char *tail; 185 char *tail;
183 int tail_len, round_tail_len; 186 int tail_len, round_tail_len;
184 loff_t pos, pos1; /* position of first byte of the tail */ 187 loff_t pos, pos1; /* position of first byte of the tail */
@@ -186,22 +189,22 @@ int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_in
186 189
187 BUG_ON(!th->t_trans_id); 190 BUG_ON(!th->t_trans_id);
188 191
189 REISERFS_SB(p_s_sb)->s_indirect2direct++; 192 REISERFS_SB(sb)->s_indirect2direct++;
190 193
191 *p_c_mode = M_SKIP_BALANCING; 194 *mode = M_SKIP_BALANCING;
192 195
193 /* store item head path points to. */ 196 /* store item head path points to. */
194 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 197 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
195 198
196 tail_len = (n_new_file_size & (n_block_size - 1)); 199 tail_len = (n_new_file_size & (block_size - 1));
197 if (get_inode_sd_version(p_s_inode) == STAT_DATA_V2) 200 if (get_inode_sd_version(inode) == STAT_DATA_V2)
198 round_tail_len = ROUND_UP(tail_len); 201 round_tail_len = ROUND_UP(tail_len);
199 else 202 else
200 round_tail_len = tail_len; 203 round_tail_len = tail_len;
201 204
202 pos = 205 pos =
203 le_ih_k_offset(&s_ih) - 1 + (ih_item_len(&s_ih) / UNFM_P_SIZE - 206 le_ih_k_offset(&s_ih) - 1 + (ih_item_len(&s_ih) / UNFM_P_SIZE -
204 1) * p_s_sb->s_blocksize; 207 1) * sb->s_blocksize;
205 pos1 = pos; 208 pos1 = pos;
206 209
207 // we are protected by i_mutex. The tail can not disapper, not 210 // we are protected by i_mutex. The tail can not disapper, not
@@ -210,27 +213,26 @@ int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_in
210 213
211 tail = (char *)kmap(page); /* this can schedule */ 214 tail = (char *)kmap(page); /* this can schedule */
212 215
213 if (path_changed(&s_ih, p_s_path)) { 216 if (path_changed(&s_ih, path)) {
214 /* re-search indirect item */ 217 /* re-search indirect item */
215 if (search_for_position_by_key(p_s_sb, p_s_item_key, p_s_path) 218 if (search_for_position_by_key(sb, item_key, path)
216 == POSITION_NOT_FOUND) 219 == POSITION_NOT_FOUND)
217 reiserfs_panic(p_s_sb, 220 reiserfs_panic(sb, "PAP-5520",
218 "PAP-5520: indirect2direct: "
219 "item to be converted %K does not exist", 221 "item to be converted %K does not exist",
220 p_s_item_key); 222 item_key);
221 copy_item_head(&s_ih, PATH_PITEM_HEAD(p_s_path)); 223 copy_item_head(&s_ih, PATH_PITEM_HEAD(path));
222#ifdef CONFIG_REISERFS_CHECK 224#ifdef CONFIG_REISERFS_CHECK
223 pos = le_ih_k_offset(&s_ih) - 1 + 225 pos = le_ih_k_offset(&s_ih) - 1 +
224 (ih_item_len(&s_ih) / UNFM_P_SIZE - 226 (ih_item_len(&s_ih) / UNFM_P_SIZE -
225 1) * p_s_sb->s_blocksize; 227 1) * sb->s_blocksize;
226 if (pos != pos1) 228 if (pos != pos1)
227 reiserfs_panic(p_s_sb, "vs-5530: indirect2direct: " 229 reiserfs_panic(sb, "vs-5530", "tail position "
228 "tail position changed while we were reading it"); 230 "changed while we were reading it");
229#endif 231#endif
230 } 232 }
231 233
232 /* Set direct item header to insert. */ 234 /* Set direct item header to insert. */
233 make_le_item_head(&s_ih, NULL, get_inode_item_key_version(p_s_inode), 235 make_le_item_head(&s_ih, NULL, get_inode_item_key_version(inode),
234 pos1 + 1, TYPE_DIRECT, round_tail_len, 236 pos1 + 1, TYPE_DIRECT, round_tail_len,
235 0xffff /*ih_free_space */ ); 237 0xffff /*ih_free_space */ );
236 238
@@ -240,13 +242,13 @@ int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_in
240 */ 242 */
241 tail = tail + (pos & (PAGE_CACHE_SIZE - 1)); 243 tail = tail + (pos & (PAGE_CACHE_SIZE - 1));
242 244
243 PATH_LAST_POSITION(p_s_path)++; 245 PATH_LAST_POSITION(path)++;
244 246
245 key = *p_s_item_key; 247 key = *item_key;
246 set_cpu_key_k_type(&key, TYPE_DIRECT); 248 set_cpu_key_k_type(&key, TYPE_DIRECT);
247 key.key_length = 4; 249 key.key_length = 4;
248 /* Insert tail as new direct item in the tree */ 250 /* Insert tail as new direct item in the tree */
249 if (reiserfs_insert_item(th, p_s_path, &key, &s_ih, p_s_inode, 251 if (reiserfs_insert_item(th, path, &key, &s_ih, inode,
250 tail ? tail : NULL) < 0) { 252 tail ? tail : NULL) < 0) {
251 /* No disk memory. So we can not convert last unformatted node 253 /* No disk memory. So we can not convert last unformatted node
252 to the direct item. In this case we used to adjust 254 to the direct item. In this case we used to adjust
@@ -255,12 +257,12 @@ int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_in
255 unformatted node. For now i_size is considered as guard for 257 unformatted node. For now i_size is considered as guard for
256 going out of file size */ 258 going out of file size */
257 kunmap(page); 259 kunmap(page);
258 return n_block_size - round_tail_len; 260 return block_size - round_tail_len;
259 } 261 }
260 kunmap(page); 262 kunmap(page);
261 263
262 /* make sure to get the i_blocks changes from reiserfs_insert_item */ 264 /* make sure to get the i_blocks changes from reiserfs_insert_item */
263 reiserfs_update_sd(th, p_s_inode); 265 reiserfs_update_sd(th, inode);
264 266
265 // note: we have now the same as in above direct2indirect 267 // note: we have now the same as in above direct2indirect
266 // conversion: there are two keys which have matching first three 268 // conversion: there are two keys which have matching first three
@@ -268,11 +270,11 @@ int indirect2direct(struct reiserfs_transaction_handle *th, struct inode *p_s_in
268 270
269 /* We have inserted new direct item and must remove last 271 /* We have inserted new direct item and must remove last
270 unformatted node. */ 272 unformatted node. */
271 *p_c_mode = M_CUT; 273 *mode = M_CUT;
272 274
273 /* we store position of first direct item in the in-core inode */ 275 /* we store position of first direct item in the in-core inode */
274 //mark_file_with_tail (p_s_inode, pos1 + 1); 276 /* mark_file_with_tail (inode, pos1 + 1); */
275 REISERFS_I(p_s_inode)->i_first_direct_byte = pos1 + 1; 277 REISERFS_I(inode)->i_first_direct_byte = pos1 + 1;
276 278
277 return n_block_size - round_tail_len; 279 return block_size - round_tail_len;
278} 280}
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index ad92461cbfc..f83f52bae39 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -27,6 +27,10 @@
27 * these are special cases for filesystem ACLs, they are interpreted by the 27 * these are special cases for filesystem ACLs, they are interpreted by the
28 * kernel, in addition, they are negatively and positively cached and attached 28 * kernel, in addition, they are negatively and positively cached and attached
29 * to the inode so that unnecessary lookups are avoided. 29 * to the inode so that unnecessary lookups are avoided.
30 *
31 * Locking works like so:
32 * Directory components (xattr root, xattr dir) are protectd by their i_mutex.
33 * The xattrs themselves are protected by the xattr_sem.
30 */ 34 */
31 35
32#include <linux/reiserfs_fs.h> 36#include <linux/reiserfs_fs.h>
@@ -44,328 +48,334 @@
44#include <net/checksum.h> 48#include <net/checksum.h>
45#include <linux/smp_lock.h> 49#include <linux/smp_lock.h>
46#include <linux/stat.h> 50#include <linux/stat.h>
51#include <linux/quotaops.h>
47 52
48#define FL_READONLY 128
49#define FL_DIR_SEM_HELD 256
50#define PRIVROOT_NAME ".reiserfs_priv" 53#define PRIVROOT_NAME ".reiserfs_priv"
51#define XAROOT_NAME "xattrs" 54#define XAROOT_NAME "xattrs"
52 55
53static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
54 *prefix);
55 56
56/* Returns the dentry referring to the root of the extended attribute 57/* Helpers for inode ops. We do this so that we don't have all the VFS
57 * directory tree. If it has already been retrieved, it is used. If it 58 * overhead and also for proper i_mutex annotation.
58 * hasn't been created and the flags indicate creation is allowed, we 59 * dir->i_mutex must be held for all of them. */
59 * attempt to create it. On error, we return a pointer-encoded error. 60#ifdef CONFIG_REISERFS_FS_XATTR
60 */ 61static int xattr_create(struct inode *dir, struct dentry *dentry, int mode)
61static struct dentry *get_xa_root(struct super_block *sb, int flags)
62{ 62{
63 struct dentry *privroot = dget(REISERFS_SB(sb)->priv_root); 63 BUG_ON(!mutex_is_locked(&dir->i_mutex));
64 struct dentry *xaroot; 64 vfs_dq_init(dir);
65 return dir->i_op->create(dir, dentry, mode, NULL);
66}
67#endif
65 68
66 /* This needs to be created at mount-time */ 69static int xattr_mkdir(struct inode *dir, struct dentry *dentry, int mode)
67 if (!privroot) 70{
68 return ERR_PTR(-ENODATA); 71 BUG_ON(!mutex_is_locked(&dir->i_mutex));
72 vfs_dq_init(dir);
73 return dir->i_op->mkdir(dir, dentry, mode);
74}
69 75
70 mutex_lock_nested(&privroot->d_inode->i_mutex, I_MUTEX_XATTR); 76/* We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr
71 if (REISERFS_SB(sb)->xattr_root) { 77 * mutation ops aren't called during rename or splace, which are the
72 xaroot = dget(REISERFS_SB(sb)->xattr_root); 78 * only other users of I_MUTEX_CHILD. It violates the ordering, but that's
73 goto out; 79 * better than allocating another subclass just for this code. */
74 } 80static int xattr_unlink(struct inode *dir, struct dentry *dentry)
81{
82 int error;
83 BUG_ON(!mutex_is_locked(&dir->i_mutex));
84 vfs_dq_init(dir);
75 85
76 xaroot = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME)); 86 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD);
77 if (IS_ERR(xaroot)) { 87 error = dir->i_op->unlink(dir, dentry);
78 goto out; 88 mutex_unlock(&dentry->d_inode->i_mutex);
79 } else if (!xaroot->d_inode) { 89
90 if (!error)
91 d_delete(dentry);
92 return error;
93}
94
95static int xattr_rmdir(struct inode *dir, struct dentry *dentry)
96{
97 int error;
98 BUG_ON(!mutex_is_locked(&dir->i_mutex));
99 vfs_dq_init(dir);
100
101 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD);
102 dentry_unhash(dentry);
103 error = dir->i_op->rmdir(dir, dentry);
104 if (!error)
105 dentry->d_inode->i_flags |= S_DEAD;
106 mutex_unlock(&dentry->d_inode->i_mutex);
107 if (!error)
108 d_delete(dentry);
109 dput(dentry);
110
111 return error;
112}
113
114#define xattr_may_create(flags) (!flags || flags & XATTR_CREATE)
115
116/* Returns and possibly creates the xattr dir. */
117static struct dentry *lookup_or_create_dir(struct dentry *parent,
118 const char *name, int flags)
119{
120 struct dentry *dentry;
121 BUG_ON(!parent);
122
123 dentry = lookup_one_len(name, parent, strlen(name));
124 if (IS_ERR(dentry))
125 return dentry;
126 else if (!dentry->d_inode) {
80 int err = -ENODATA; 127 int err = -ENODATA;
81 if (flags == 0 || flags & XATTR_CREATE) 128
82 err = privroot->d_inode->i_op->mkdir(privroot->d_inode, 129 if (xattr_may_create(flags)) {
83 xaroot, 0700); 130 mutex_lock_nested(&parent->d_inode->i_mutex,
131 I_MUTEX_XATTR);
132 err = xattr_mkdir(parent->d_inode, dentry, 0700);
133 mutex_unlock(&parent->d_inode->i_mutex);
134 }
135
84 if (err) { 136 if (err) {
85 dput(xaroot); 137 dput(dentry);
86 xaroot = ERR_PTR(err); 138 dentry = ERR_PTR(err);
87 goto out;
88 } 139 }
89 } 140 }
90 REISERFS_SB(sb)->xattr_root = dget(xaroot);
91 141
92 out: 142 return dentry;
93 mutex_unlock(&privroot->d_inode->i_mutex); 143}
94 dput(privroot); 144
95 return xaroot; 145static struct dentry *open_xa_root(struct super_block *sb, int flags)
146{
147 struct dentry *privroot = REISERFS_SB(sb)->priv_root;
148 if (!privroot)
149 return ERR_PTR(-ENODATA);
150 return lookup_or_create_dir(privroot, XAROOT_NAME, flags);
96} 151}
97 152
98/* Opens the directory corresponding to the inode's extended attribute store.
99 * If flags allow, the tree to the directory may be created. If creation is
100 * prohibited, -ENODATA is returned. */
101static struct dentry *open_xa_dir(const struct inode *inode, int flags) 153static struct dentry *open_xa_dir(const struct inode *inode, int flags)
102{ 154{
103 struct dentry *xaroot, *xadir; 155 struct dentry *xaroot, *xadir;
104 char namebuf[17]; 156 char namebuf[17];
105 157
106 xaroot = get_xa_root(inode->i_sb, flags); 158 xaroot = open_xa_root(inode->i_sb, flags);
107 if (IS_ERR(xaroot)) 159 if (IS_ERR(xaroot))
108 return xaroot; 160 return xaroot;
109 161
110 /* ok, we have xaroot open */
111 snprintf(namebuf, sizeof(namebuf), "%X.%X", 162 snprintf(namebuf, sizeof(namebuf), "%X.%X",
112 le32_to_cpu(INODE_PKEY(inode)->k_objectid), 163 le32_to_cpu(INODE_PKEY(inode)->k_objectid),
113 inode->i_generation); 164 inode->i_generation);
114 xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
115 if (IS_ERR(xadir)) {
116 dput(xaroot);
117 return xadir;
118 }
119
120 if (!xadir->d_inode) {
121 int err;
122 if (flags == 0 || flags & XATTR_CREATE) {
123 /* Although there is nothing else trying to create this directory,
124 * another directory with the same hash may be created, so we need
125 * to protect against that */
126 err =
127 xaroot->d_inode->i_op->mkdir(xaroot->d_inode, xadir,
128 0700);
129 if (err) {
130 dput(xaroot);
131 dput(xadir);
132 return ERR_PTR(err);
133 }
134 }
135 if (!xadir->d_inode) {
136 dput(xaroot);
137 dput(xadir);
138 return ERR_PTR(-ENODATA);
139 }
140 }
141 165
166 xadir = lookup_or_create_dir(xaroot, namebuf, flags);
142 dput(xaroot); 167 dput(xaroot);
143 return xadir; 168 return xadir;
169
144} 170}
145 171
146/* Returns a dentry corresponding to a specific extended attribute file 172/* The following are side effects of other operations that aren't explicitly
147 * for the inode. If flags allow, the file is created. Otherwise, a 173 * modifying extended attributes. This includes operations such as permissions
148 * valid or negative dentry, or an error is returned. */ 174 * or ownership changes, object deletions, etc. */
149static struct dentry *get_xa_file_dentry(const struct inode *inode, 175struct reiserfs_dentry_buf {
150 const char *name, int flags) 176 struct dentry *xadir;
151{ 177 int count;
152 struct dentry *xadir, *xafile; 178 struct dentry *dentries[8];
153 int err = 0; 179};
154 180
155 xadir = open_xa_dir(inode, flags); 181static int
156 if (IS_ERR(xadir)) { 182fill_with_dentries(void *buf, const char *name, int namelen, loff_t offset,
157 return ERR_CAST(xadir); 183 u64 ino, unsigned int d_type)
158 } else if (!xadir->d_inode) { 184{
159 dput(xadir); 185 struct reiserfs_dentry_buf *dbuf = buf;
160 return ERR_PTR(-ENODATA); 186 struct dentry *dentry;
161 }
162 187
163 xafile = lookup_one_len(name, xadir, strlen(name)); 188 if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
164 if (IS_ERR(xafile)) { 189 return -ENOSPC;
165 dput(xadir);
166 return ERR_CAST(xafile);
167 }
168 190
169 if (xafile->d_inode) { /* file exists */ 191 if (name[0] == '.' && (name[1] == '\0' ||
170 if (flags & XATTR_CREATE) { 192 (name[1] == '.' && name[2] == '\0')))
171 err = -EEXIST; 193 return 0;
172 dput(xafile);
173 goto out;
174 }
175 } else if (flags & XATTR_REPLACE || flags & FL_READONLY) {
176 goto out;
177 } else {
178 /* inode->i_mutex is down, so nothing else can try to create
179 * the same xattr */
180 err = xadir->d_inode->i_op->create(xadir->d_inode, xafile,
181 0700 | S_IFREG, NULL);
182 194
183 if (err) { 195 dentry = lookup_one_len(name, dbuf->xadir, namelen);
184 dput(xafile); 196 if (IS_ERR(dentry)) {
185 goto out; 197 return PTR_ERR(dentry);
186 } 198 } else if (!dentry->d_inode) {
199 /* A directory entry exists, but no file? */
200 reiserfs_error(dentry->d_sb, "xattr-20003",
201 "Corrupted directory: xattr %s listed but "
202 "not found for file %s.\n",
203 dentry->d_name.name, dbuf->xadir->d_name.name);
204 dput(dentry);
205 return -EIO;
187 } 206 }
188 207
189 out: 208 dbuf->dentries[dbuf->count++] = dentry;
190 dput(xadir); 209 return 0;
191 if (err)
192 xafile = ERR_PTR(err);
193 else if (!xafile->d_inode) {
194 dput(xafile);
195 xafile = ERR_PTR(-ENODATA);
196 }
197 return xafile;
198} 210}
199 211
200/* 212static void
201 * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but 213cleanup_dentry_buf(struct reiserfs_dentry_buf *buf)
202 * we need to drop the path before calling the filldir struct. That
203 * would be a big performance hit to the non-xattr case, so I've copied
204 * the whole thing for now. --clm
205 *
206 * the big difference is that I go backwards through the directory,
207 * and don't mess with f->f_pos, but the idea is the same. Do some
208 * action on each and every entry in the directory.
209 *
210 * we're called with i_mutex held, so there are no worries about the directory
211 * changing underneath us.
212 */
213static int __xattr_readdir(struct inode *inode, void *dirent, filldir_t filldir)
214{ 214{
215 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */ 215 int i;
216 INITIALIZE_PATH(path_to_entry); 216 for (i = 0; i < buf->count; i++)
217 struct buffer_head *bh; 217 if (buf->dentries[i])
218 int entry_num; 218 dput(buf->dentries[i]);
219 struct item_head *ih, tmp_ih; 219}
220 int search_res; 220
221 char *local_buf; 221static int reiserfs_for_each_xattr(struct inode *inode,
222 loff_t next_pos; 222 int (*action)(struct dentry *, void *),
223 char small_buf[32]; /* avoid kmalloc if we can */ 223 void *data)
224 struct reiserfs_de_head *deh; 224{
225 int d_reclen; 225 struct dentry *dir;
226 char *d_name; 226 int i, err = 0;
227 off_t d_off; 227 loff_t pos = 0;
228 ino_t d_ino; 228 struct reiserfs_dentry_buf buf = {
229 struct reiserfs_dir_entry de; 229 .count = 0,
230 230 };
231 /* form key for search the next directory entry using f_pos field of
232 file structure */
233 next_pos = max_reiserfs_offset(inode);
234
235 while (1) {
236 research:
237 if (next_pos <= DOT_DOT_OFFSET)
238 break;
239 make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3);
240
241 search_res =
242 search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
243 &de);
244 if (search_res == IO_ERROR) {
245 // FIXME: we could just skip part of directory which could
246 // not be read
247 pathrelse(&path_to_entry);
248 return -EIO;
249 }
250 231
251 if (search_res == NAME_NOT_FOUND) 232 /* Skip out, an xattr has no xattrs associated with it */
252 de.de_entry_num--; 233 if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
234 return 0;
253 235
254 set_de_name_and_namelen(&de); 236 dir = open_xa_dir(inode, XATTR_REPLACE);
255 entry_num = de.de_entry_num; 237 if (IS_ERR(dir)) {
256 deh = &(de.de_deh[entry_num]); 238 err = PTR_ERR(dir);
239 goto out;
240 } else if (!dir->d_inode) {
241 err = 0;
242 goto out_dir;
243 }
257 244
258 bh = de.de_bh; 245 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
259 ih = de.de_ih; 246 buf.xadir = dir;
247 err = reiserfs_readdir_dentry(dir, &buf, fill_with_dentries, &pos);
248 while ((err == 0 || err == -ENOSPC) && buf.count) {
249 err = 0;
260 250
261 if (!is_direntry_le_ih(ih)) { 251 for (i = 0; i < buf.count && buf.dentries[i]; i++) {
262 reiserfs_warning(inode->i_sb, "not direntry %h", ih); 252 int lerr = 0;
263 break; 253 struct dentry *dentry = buf.dentries[i];
264 }
265 copy_item_head(&tmp_ih, ih);
266 254
267 /* we must have found item, that is item of this directory, */ 255 if (err == 0 && !S_ISDIR(dentry->d_inode->i_mode))
268 RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key), 256 lerr = action(dentry, data);
269 "vs-9000: found item %h does not match to dir we readdir %K",
270 ih, &pos_key);
271 257
272 if (deh_offset(deh) <= DOT_DOT_OFFSET) { 258 dput(dentry);
273 break; 259 buf.dentries[i] = NULL;
260 err = lerr ?: err;
274 } 261 }
262 buf.count = 0;
263 if (!err)
264 err = reiserfs_readdir_dentry(dir, &buf,
265 fill_with_dentries, &pos);
266 }
267 mutex_unlock(&dir->d_inode->i_mutex);
275 268
276 /* look for the previous entry in the directory */ 269 /* Clean up after a failed readdir */
277 next_pos = deh_offset(deh) - 1; 270 cleanup_dentry_buf(&buf);
278
279 if (!de_visible(deh))
280 /* it is hidden entry */
281 continue;
282 271
283 d_reclen = entry_length(bh, ih, entry_num); 272 if (!err) {
284 d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh); 273 /* We start a transaction here to avoid a ABBA situation
285 d_off = deh_offset(deh); 274 * between the xattr root's i_mutex and the journal lock.
286 d_ino = deh_objectid(deh); 275 * This doesn't incur much additional overhead since the
276 * new transaction will just nest inside the
277 * outer transaction. */
278 int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 +
279 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
280 struct reiserfs_transaction_handle th;
281 err = journal_begin(&th, inode->i_sb, blocks);
282 if (!err) {
283 int jerror;
284 mutex_lock_nested(&dir->d_parent->d_inode->i_mutex,
285 I_MUTEX_XATTR);
286 err = action(dir, data);
287 jerror = journal_end(&th, inode->i_sb, blocks);
288 mutex_unlock(&dir->d_parent->d_inode->i_mutex);
289 err = jerror ?: err;
290 }
291 }
292out_dir:
293 dput(dir);
294out:
295 /* -ENODATA isn't an error */
296 if (err == -ENODATA)
297 err = 0;
298 return err;
299}
287 300
288 if (!d_name[d_reclen - 1]) 301static int delete_one_xattr(struct dentry *dentry, void *data)
289 d_reclen = strlen(d_name); 302{
303 struct inode *dir = dentry->d_parent->d_inode;
290 304
291 if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) { 305 /* This is the xattr dir, handle specially. */
292 /* too big to send back to VFS */ 306 if (S_ISDIR(dentry->d_inode->i_mode))
293 continue; 307 return xattr_rmdir(dir, dentry);
294 }
295 308
296 /* Ignore the .reiserfs_priv entry */ 309 return xattr_unlink(dir, dentry);
297 if (reiserfs_xattrs(inode->i_sb) && 310}
298 !old_format_only(inode->i_sb) &&
299 deh_objectid(deh) ==
300 le32_to_cpu(INODE_PKEY
301 (REISERFS_SB(inode->i_sb)->priv_root->d_inode)->
302 k_objectid))
303 continue;
304
305 if (d_reclen <= 32) {
306 local_buf = small_buf;
307 } else {
308 local_buf = kmalloc(d_reclen, GFP_NOFS);
309 if (!local_buf) {
310 pathrelse(&path_to_entry);
311 return -ENOMEM;
312 }
313 if (item_moved(&tmp_ih, &path_to_entry)) {
314 kfree(local_buf);
315 311
316 /* sigh, must retry. Do this same offset again */ 312static int chown_one_xattr(struct dentry *dentry, void *data)
317 next_pos = d_off; 313{
318 goto research; 314 struct iattr *attrs = data;
319 } 315 return reiserfs_setattr(dentry, attrs);
320 } 316}
321 317
322 // Note, that we copy name to user space via temporary 318/* No i_mutex, but the inode is unconnected. */
323 // buffer (local_buf) because filldir will block if 319int reiserfs_delete_xattrs(struct inode *inode)
324 // user space buffer is swapped out. At that time 320{
325 // entry can move to somewhere else 321 int err = reiserfs_for_each_xattr(inode, delete_one_xattr, NULL);
326 memcpy(local_buf, d_name, d_reclen); 322 if (err)
327 323 reiserfs_warning(inode->i_sb, "jdm-20004",
328 /* the filldir function might need to start transactions, 324 "Couldn't delete all xattrs (%d)\n", err);
329 * or do who knows what. Release the path now that we've 325 return err;
330 * copied all the important stuff out of the deh 326}
331 */
332 pathrelse(&path_to_entry);
333
334 if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
335 DT_UNKNOWN) < 0) {
336 if (local_buf != small_buf) {
337 kfree(local_buf);
338 }
339 goto end;
340 }
341 if (local_buf != small_buf) {
342 kfree(local_buf);
343 }
344 } /* while */
345 327
346 end: 328/* inode->i_mutex: down */
347 pathrelse(&path_to_entry); 329int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
348 return 0; 330{
331 int err = reiserfs_for_each_xattr(inode, chown_one_xattr, attrs);
332 if (err)
333 reiserfs_warning(inode->i_sb, "jdm-20007",
334 "Couldn't chown all xattrs (%d)\n", err);
335 return err;
349} 336}
350 337
351/* 338#ifdef CONFIG_REISERFS_FS_XATTR
352 * this could be done with dedicated readdir ops for the xattr files, 339/* Returns a dentry corresponding to a specific extended attribute file
353 * but I want to get something working asap 340 * for the inode. If flags allow, the file is created. Otherwise, a
354 * this is stolen from vfs_readdir 341 * valid or negative dentry, or an error is returned. */
355 * 342static struct dentry *xattr_lookup(struct inode *inode, const char *name,
356 */ 343 int flags)
357static
358int xattr_readdir(struct inode *inode, filldir_t filler, void *buf)
359{ 344{
360 int res = -ENOENT; 345 struct dentry *xadir, *xafile;
361 mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR); 346 int err = 0;
362 if (!IS_DEADDIR(inode)) { 347
363 lock_kernel(); 348 xadir = open_xa_dir(inode, flags);
364 res = __xattr_readdir(inode, buf, filler); 349 if (IS_ERR(xadir))
365 unlock_kernel(); 350 return ERR_CAST(xadir);
351
352 xafile = lookup_one_len(name, xadir, strlen(name));
353 if (IS_ERR(xafile)) {
354 err = PTR_ERR(xafile);
355 goto out;
366 } 356 }
367 mutex_unlock(&inode->i_mutex); 357
368 return res; 358 if (xafile->d_inode && (flags & XATTR_CREATE))
359 err = -EEXIST;
360
361 if (!xafile->d_inode) {
362 err = -ENODATA;
363 if (xattr_may_create(flags)) {
364 mutex_lock_nested(&xadir->d_inode->i_mutex,
365 I_MUTEX_XATTR);
366 err = xattr_create(xadir->d_inode, xafile,
367 0700|S_IFREG);
368 mutex_unlock(&xadir->d_inode->i_mutex);
369 }
370 }
371
372 if (err)
373 dput(xafile);
374out:
375 dput(xadir);
376 if (err)
377 return ERR_PTR(err);
378 return xafile;
369} 379}
370 380
371/* Internal operations on file data */ 381/* Internal operations on file data */
@@ -375,14 +385,14 @@ static inline void reiserfs_put_page(struct page *page)
375 page_cache_release(page); 385 page_cache_release(page);
376} 386}
377 387
378static struct page *reiserfs_get_page(struct inode *dir, unsigned long n) 388static struct page *reiserfs_get_page(struct inode *dir, size_t n)
379{ 389{
380 struct address_space *mapping = dir->i_mapping; 390 struct address_space *mapping = dir->i_mapping;
381 struct page *page; 391 struct page *page;
382 /* We can deadlock if we try to free dentries, 392 /* We can deadlock if we try to free dentries,
383 and an unlink/rmdir has just occured - GFP_NOFS avoids this */ 393 and an unlink/rmdir has just occured - GFP_NOFS avoids this */
384 mapping_set_gfp_mask(mapping, GFP_NOFS); 394 mapping_set_gfp_mask(mapping, GFP_NOFS);
385 page = read_mapping_page(mapping, n, NULL); 395 page = read_mapping_page(mapping, n >> PAGE_CACHE_SHIFT, NULL);
386 if (!IS_ERR(page)) { 396 if (!IS_ERR(page)) {
387 kmap(page); 397 kmap(page);
388 if (PageError(page)) 398 if (PageError(page))
@@ -405,6 +415,45 @@ int reiserfs_commit_write(struct file *f, struct page *page,
405int reiserfs_prepare_write(struct file *f, struct page *page, 415int reiserfs_prepare_write(struct file *f, struct page *page,
406 unsigned from, unsigned to); 416 unsigned from, unsigned to);
407 417
418static void update_ctime(struct inode *inode)
419{
420 struct timespec now = current_fs_time(inode->i_sb);
421 if (hlist_unhashed(&inode->i_hash) || !inode->i_nlink ||
422 timespec_equal(&inode->i_ctime, &now))
423 return;
424
425 inode->i_ctime = CURRENT_TIME_SEC;
426 mark_inode_dirty(inode);
427}
428
429static int lookup_and_delete_xattr(struct inode *inode, const char *name)
430{
431 int err = 0;
432 struct dentry *dentry, *xadir;
433
434 xadir = open_xa_dir(inode, XATTR_REPLACE);
435 if (IS_ERR(xadir))
436 return PTR_ERR(xadir);
437
438 dentry = lookup_one_len(name, xadir, strlen(name));
439 if (IS_ERR(dentry)) {
440 err = PTR_ERR(dentry);
441 goto out_dput;
442 }
443
444 if (dentry->d_inode) {
445 mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
446 err = xattr_unlink(xadir->d_inode, dentry);
447 mutex_unlock(&xadir->d_inode->i_mutex);
448 update_ctime(inode);
449 }
450
451 dput(dentry);
452out_dput:
453 dput(xadir);
454 return err;
455}
456
408 457
409/* Generic extended attribute operations that can be used by xa plugins */ 458/* Generic extended attribute operations that can be used by xa plugins */
410 459
@@ -412,58 +461,32 @@ int reiserfs_prepare_write(struct file *f, struct page *page,
412 * inode->i_mutex: down 461 * inode->i_mutex: down
413 */ 462 */
414int 463int
415reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer, 464reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
416 size_t buffer_size, int flags) 465 struct inode *inode, const char *name,
466 const void *buffer, size_t buffer_size, int flags)
417{ 467{
418 int err = 0; 468 int err = 0;
419 struct dentry *dentry; 469 struct dentry *dentry;
420 struct page *page; 470 struct page *page;
421 char *data; 471 char *data;
422 struct address_space *mapping;
423 size_t file_pos = 0; 472 size_t file_pos = 0;
424 size_t buffer_pos = 0; 473 size_t buffer_pos = 0;
425 struct inode *xinode; 474 size_t new_size;
426 struct iattr newattrs;
427 __u32 xahash = 0; 475 __u32 xahash = 0;
428 476
429 if (get_inode_sd_version(inode) == STAT_DATA_V1) 477 if (get_inode_sd_version(inode) == STAT_DATA_V1)
430 return -EOPNOTSUPP; 478 return -EOPNOTSUPP;
431 479
432 /* Empty xattrs are ok, they're just empty files, no hash */ 480 if (!buffer)
433 if (buffer && buffer_size) 481 return lookup_and_delete_xattr(inode, name);
434 xahash = xattr_hash(buffer, buffer_size);
435 482
436 open_file: 483 dentry = xattr_lookup(inode, name, flags);
437 dentry = get_xa_file_dentry(inode, name, flags); 484 if (IS_ERR(dentry))
438 if (IS_ERR(dentry)) { 485 return PTR_ERR(dentry);
439 err = PTR_ERR(dentry);
440 goto out;
441 }
442
443 xinode = dentry->d_inode;
444 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
445 486
446 /* we need to copy it off.. */ 487 down_write(&REISERFS_I(inode)->i_xattr_sem);
447 if (xinode->i_nlink > 1) {
448 dput(dentry);
449 err = reiserfs_xattr_del(inode, name);
450 if (err < 0)
451 goto out;
452 /* We just killed the old one, we're not replacing anymore */
453 if (flags & XATTR_REPLACE)
454 flags &= ~XATTR_REPLACE;
455 goto open_file;
456 }
457 488
458 /* Resize it so we're ok to write there */ 489 xahash = xattr_hash(buffer, buffer_size);
459 newattrs.ia_size = buffer_size;
460 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
461 mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR);
462 err = notify_change(dentry, &newattrs);
463 if (err)
464 goto out_filp;
465
466 mapping = xinode->i_mapping;
467 while (buffer_pos < buffer_size || buffer_pos == 0) { 490 while (buffer_pos < buffer_size || buffer_pos == 0) {
468 size_t chunk; 491 size_t chunk;
469 size_t skip = 0; 492 size_t skip = 0;
@@ -473,10 +496,10 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
473 else 496 else
474 chunk = buffer_size - buffer_pos; 497 chunk = buffer_size - buffer_pos;
475 498
476 page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT); 499 page = reiserfs_get_page(dentry->d_inode, file_pos);
477 if (IS_ERR(page)) { 500 if (IS_ERR(page)) {
478 err = PTR_ERR(page); 501 err = PTR_ERR(page);
479 goto out_filp; 502 goto out_unlock;
480 } 503 }
481 504
482 lock_page(page); 505 lock_page(page);
@@ -510,28 +533,61 @@ reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
510 break; 533 break;
511 } 534 }
512 535
513 /* We can't mark the inode dirty if it's not hashed. This is the case 536 new_size = buffer_size + sizeof(struct reiserfs_xattr_header);
514 * when we're inheriting the default ACL. If we dirty it, the inode 537 if (!err && new_size < i_size_read(dentry->d_inode)) {
515 * gets marked dirty, but won't (ever) make it onto the dirty list until 538 struct iattr newattrs = {
516 * it's synced explicitly to clear I_DIRTY. This is bad. */ 539 .ia_ctime = current_fs_time(inode->i_sb),
517 if (!hlist_unhashed(&inode->i_hash)) { 540 .ia_size = buffer_size,
518 inode->i_ctime = CURRENT_TIME_SEC; 541 .ia_valid = ATTR_SIZE | ATTR_CTIME,
519 mark_inode_dirty(inode); 542 };
543 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR);
544 down_write(&dentry->d_inode->i_alloc_sem);
545 err = reiserfs_setattr(dentry, &newattrs);
546 up_write(&dentry->d_inode->i_alloc_sem);
547 mutex_unlock(&dentry->d_inode->i_mutex);
548 } else
549 update_ctime(inode);
550out_unlock:
551 up_write(&REISERFS_I(inode)->i_xattr_sem);
552 dput(dentry);
553 return err;
554}
555
556/* We need to start a transaction to maintain lock ordering */
557int reiserfs_xattr_set(struct inode *inode, const char *name,
558 const void *buffer, size_t buffer_size, int flags)
559{
560
561 struct reiserfs_transaction_handle th;
562 int error, error2;
563 size_t jbegin_count = reiserfs_xattr_nblocks(inode, buffer_size);
564
565 if (!(flags & XATTR_REPLACE))
566 jbegin_count += reiserfs_xattr_jcreate_nblocks(inode);
567
568 reiserfs_write_lock(inode->i_sb);
569 error = journal_begin(&th, inode->i_sb, jbegin_count);
570 if (error) {
571 reiserfs_write_unlock(inode->i_sb);
572 return error;
520 } 573 }
521 574
522 out_filp: 575 error = reiserfs_xattr_set_handle(&th, inode, name,
523 mutex_unlock(&xinode->i_mutex); 576 buffer, buffer_size, flags);
524 dput(dentry);
525 577
526 out: 578 error2 = journal_end(&th, inode->i_sb, jbegin_count);
527 return err; 579 if (error == 0)
580 error = error2;
581 reiserfs_write_unlock(inode->i_sb);
582
583 return error;
528} 584}
529 585
530/* 586/*
531 * inode->i_mutex: down 587 * inode->i_mutex: down
532 */ 588 */
533int 589int
534reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer, 590reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer,
535 size_t buffer_size) 591 size_t buffer_size)
536{ 592{
537 ssize_t err = 0; 593 ssize_t err = 0;
@@ -540,7 +596,6 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
540 size_t file_pos = 0; 596 size_t file_pos = 0;
541 size_t buffer_pos = 0; 597 size_t buffer_pos = 0;
542 struct page *page; 598 struct page *page;
543 struct inode *xinode;
544 __u32 hash = 0; 599 __u32 hash = 0;
545 600
546 if (name == NULL) 601 if (name == NULL)
@@ -551,25 +606,25 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
551 if (get_inode_sd_version(inode) == STAT_DATA_V1) 606 if (get_inode_sd_version(inode) == STAT_DATA_V1)
552 return -EOPNOTSUPP; 607 return -EOPNOTSUPP;
553 608
554 dentry = get_xa_file_dentry(inode, name, FL_READONLY); 609 dentry = xattr_lookup(inode, name, XATTR_REPLACE);
555 if (IS_ERR(dentry)) { 610 if (IS_ERR(dentry)) {
556 err = PTR_ERR(dentry); 611 err = PTR_ERR(dentry);
557 goto out; 612 goto out;
558 } 613 }
559 614
560 xinode = dentry->d_inode; 615 down_read(&REISERFS_I(inode)->i_xattr_sem);
561 isize = xinode->i_size; 616
562 REISERFS_I(inode)->i_flags |= i_has_xattr_dir; 617 isize = i_size_read(dentry->d_inode);
563 618
564 /* Just return the size needed */ 619 /* Just return the size needed */
565 if (buffer == NULL) { 620 if (buffer == NULL) {
566 err = isize - sizeof(struct reiserfs_xattr_header); 621 err = isize - sizeof(struct reiserfs_xattr_header);
567 goto out_dput; 622 goto out_unlock;
568 } 623 }
569 624
570 if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) { 625 if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
571 err = -ERANGE; 626 err = -ERANGE;
572 goto out_dput; 627 goto out_unlock;
573 } 628 }
574 629
575 while (file_pos < isize) { 630 while (file_pos < isize) {
@@ -581,10 +636,10 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
581 else 636 else
582 chunk = isize - file_pos; 637 chunk = isize - file_pos;
583 638
584 page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT); 639 page = reiserfs_get_page(dentry->d_inode, file_pos);
585 if (IS_ERR(page)) { 640 if (IS_ERR(page)) {
586 err = PTR_ERR(page); 641 err = PTR_ERR(page);
587 goto out_dput; 642 goto out_unlock;
588 } 643 }
589 644
590 lock_page(page); 645 lock_page(page);
@@ -598,12 +653,12 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
598 if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) { 653 if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
599 unlock_page(page); 654 unlock_page(page);
600 reiserfs_put_page(page); 655 reiserfs_put_page(page);
601 reiserfs_warning(inode->i_sb, 656 reiserfs_warning(inode->i_sb, "jdm-20001",
602 "Invalid magic for xattr (%s) " 657 "Invalid magic for xattr (%s) "
603 "associated with %k", name, 658 "associated with %k", name,
604 INODE_PKEY(inode)); 659 INODE_PKEY(inode));
605 err = -EIO; 660 err = -EIO;
606 goto out_dput; 661 goto out_unlock;
607 } 662 }
608 hash = le32_to_cpu(rxh->h_hash); 663 hash = le32_to_cpu(rxh->h_hash);
609 } 664 }
@@ -618,256 +673,83 @@ reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
618 673
619 if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) != 674 if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
620 hash) { 675 hash) {
621 reiserfs_warning(inode->i_sb, 676 reiserfs_warning(inode->i_sb, "jdm-20002",
622 "Invalid hash for xattr (%s) associated " 677 "Invalid hash for xattr (%s) associated "
623 "with %k", name, INODE_PKEY(inode)); 678 "with %k", name, INODE_PKEY(inode));
624 err = -EIO; 679 err = -EIO;
625 } 680 }
626 681
627 out_dput: 682out_unlock:
683 up_read(&REISERFS_I(inode)->i_xattr_sem);
628 dput(dentry); 684 dput(dentry);
629 685
630 out: 686out:
631 return err; 687 return err;
632} 688}
633 689
634static int 690/* Actual operations that are exported to VFS-land */
635__reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen) 691struct xattr_handler *reiserfs_xattr_handlers[] = {
636{ 692 &reiserfs_xattr_user_handler,
637 struct dentry *dentry; 693 &reiserfs_xattr_trusted_handler,
638 struct inode *dir = xadir->d_inode; 694#ifdef CONFIG_REISERFS_FS_SECURITY
639 int err = 0; 695 &reiserfs_xattr_security_handler,
640 696#endif
641 dentry = lookup_one_len(name, xadir, namelen); 697#ifdef CONFIG_REISERFS_FS_POSIX_ACL
642 if (IS_ERR(dentry)) { 698 &reiserfs_posix_acl_access_handler,
643 err = PTR_ERR(dentry); 699 &reiserfs_posix_acl_default_handler,
644 goto out; 700#endif
645 } else if (!dentry->d_inode) { 701 NULL
646 err = -ENODATA;
647 goto out_file;
648 }
649
650 /* Skip directories.. */
651 if (S_ISDIR(dentry->d_inode->i_mode))
652 goto out_file;
653
654 if (!is_reiserfs_priv_object(dentry->d_inode)) {
655 reiserfs_warning(dir->i_sb, "OID %08x [%.*s/%.*s] doesn't have "
656 "priv flag set [parent is %sset].",
657 le32_to_cpu(INODE_PKEY(dentry->d_inode)->
658 k_objectid), xadir->d_name.len,
659 xadir->d_name.name, namelen, name,
660 is_reiserfs_priv_object(xadir->
661 d_inode) ? "" :
662 "not ");
663 dput(dentry);
664 return -EIO;
665 }
666
667 err = dir->i_op->unlink(dir, dentry);
668 if (!err)
669 d_delete(dentry);
670
671 out_file:
672 dput(dentry);
673
674 out:
675 return err;
676}
677
678int reiserfs_xattr_del(struct inode *inode, const char *name)
679{
680 struct dentry *dir;
681 int err;
682
683 dir = open_xa_dir(inode, FL_READONLY);
684 if (IS_ERR(dir)) {
685 err = PTR_ERR(dir);
686 goto out;
687 }
688
689 err = __reiserfs_xattr_del(dir, name, strlen(name));
690 dput(dir);
691
692 if (!err) {
693 inode->i_ctime = CURRENT_TIME_SEC;
694 mark_inode_dirty(inode);
695 }
696
697 out:
698 return err;
699}
700
701/* The following are side effects of other operations that aren't explicitly
702 * modifying extended attributes. This includes operations such as permissions
703 * or ownership changes, object deletions, etc. */
704
705static int
706reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
707 loff_t offset, u64 ino, unsigned int d_type)
708{
709 struct dentry *xadir = (struct dentry *)buf;
710
711 return __reiserfs_xattr_del(xadir, name, namelen);
712
713}
714
715/* This is called w/ inode->i_mutex downed */
716int reiserfs_delete_xattrs(struct inode *inode)
717{
718 struct dentry *dir, *root;
719 int err = 0;
720
721 /* Skip out, an xattr has no xattrs associated with it */
722 if (is_reiserfs_priv_object(inode) ||
723 get_inode_sd_version(inode) == STAT_DATA_V1 ||
724 !reiserfs_xattrs(inode->i_sb)) {
725 return 0;
726 }
727 reiserfs_read_lock_xattrs(inode->i_sb);
728 dir = open_xa_dir(inode, FL_READONLY);
729 reiserfs_read_unlock_xattrs(inode->i_sb);
730 if (IS_ERR(dir)) {
731 err = PTR_ERR(dir);
732 goto out;
733 } else if (!dir->d_inode) {
734 dput(dir);
735 return 0;
736 }
737
738 lock_kernel();
739 err = xattr_readdir(dir->d_inode, reiserfs_delete_xattrs_filler, dir);
740 if (err) {
741 unlock_kernel();
742 goto out_dir;
743 }
744
745 /* Leftovers besides . and .. -- that's not good. */
746 if (dir->d_inode->i_nlink <= 2) {
747 root = get_xa_root(inode->i_sb, XATTR_REPLACE);
748 reiserfs_write_lock_xattrs(inode->i_sb);
749 err = vfs_rmdir(root->d_inode, dir);
750 reiserfs_write_unlock_xattrs(inode->i_sb);
751 dput(root);
752 } else {
753 reiserfs_warning(inode->i_sb,
754 "Couldn't remove all entries in directory");
755 }
756 unlock_kernel();
757
758 out_dir:
759 dput(dir);
760
761 out:
762 if (!err)
763 REISERFS_I(inode)->i_flags =
764 REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
765 return err;
766}
767
768struct reiserfs_chown_buf {
769 struct inode *inode;
770 struct dentry *xadir;
771 struct iattr *attrs;
772}; 702};
773 703
774/* XXX: If there is a better way to do this, I'd love to hear about it */ 704/*
775static int 705 * In order to implement different sets of xattr operations for each xattr
776reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen, 706 * prefix with the generic xattr API, a filesystem should create a
777 loff_t offset, u64 ino, unsigned int d_type) 707 * null-terminated array of struct xattr_handler (one for each prefix) and
778{ 708 * hang a pointer to it off of the s_xattr field of the superblock.
779 struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf; 709 *
780 struct dentry *xafile, *xadir = chown_buf->xadir; 710 * The generic_fooxattr() functions will use this list to dispatch xattr
781 struct iattr *attrs = chown_buf->attrs; 711 * operations to the correct xattr_handler.
782 int err = 0; 712 */
783 713#define for_each_xattr_handler(handlers, handler) \
784 xafile = lookup_one_len(name, xadir, namelen); 714 for ((handler) = *(handlers)++; \
785 if (IS_ERR(xafile)) 715 (handler) != NULL; \
786 return PTR_ERR(xafile); 716 (handler) = *(handlers)++)
787 else if (!xafile->d_inode) {
788 dput(xafile);
789 return -ENODATA;
790 }
791
792 if (!S_ISDIR(xafile->d_inode->i_mode))
793 err = notify_change(xafile, attrs);
794 dput(xafile);
795
796 return err;
797}
798 717
799int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs) 718/* This is the implementation for the xattr plugin infrastructure */
719static inline struct xattr_handler *
720find_xattr_handler_prefix(struct xattr_handler **handlers,
721 const char *name)
800{ 722{
801 struct dentry *dir; 723 struct xattr_handler *xah;
802 int err = 0;
803 struct reiserfs_chown_buf buf;
804 unsigned int ia_valid = attrs->ia_valid;
805 724
806 /* Skip out, an xattr has no xattrs associated with it */ 725 if (!handlers)
807 if (is_reiserfs_priv_object(inode) || 726 return NULL;
808 get_inode_sd_version(inode) == STAT_DATA_V1 ||
809 !reiserfs_xattrs(inode->i_sb)) {
810 return 0;
811 }
812 reiserfs_read_lock_xattrs(inode->i_sb);
813 dir = open_xa_dir(inode, FL_READONLY);
814 reiserfs_read_unlock_xattrs(inode->i_sb);
815 if (IS_ERR(dir)) {
816 if (PTR_ERR(dir) != -ENODATA)
817 err = PTR_ERR(dir);
818 goto out;
819 } else if (!dir->d_inode) {
820 dput(dir);
821 goto out;
822 }
823 727
824 lock_kernel(); 728 for_each_xattr_handler(handlers, xah) {
825 729 if (strncmp(xah->prefix, name, strlen(xah->prefix)) == 0)
826 attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME); 730 break;
827 buf.xadir = dir;
828 buf.attrs = attrs;
829 buf.inode = inode;
830
831 err = xattr_readdir(dir->d_inode, reiserfs_chown_xattrs_filler, &buf);
832 if (err) {
833 unlock_kernel();
834 goto out_dir;
835 } 731 }
836 732
837 err = notify_change(dir, attrs); 733 return xah;
838 unlock_kernel();
839
840 out_dir:
841 dput(dir);
842
843 out:
844 attrs->ia_valid = ia_valid;
845 return err;
846} 734}
847 735
848/* Actual operations that are exported to VFS-land */
849 736
850/* 737/*
851 * Inode operation getxattr() 738 * Inode operation getxattr()
852 * Preliminary locking: we down dentry->d_inode->i_mutex
853 */ 739 */
854ssize_t 740ssize_t
855reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, 741reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
856 size_t size) 742 size_t size)
857{ 743{
858 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name); 744 struct inode *inode = dentry->d_inode;
859 int err; 745 struct xattr_handler *handler;
860 746
861 if (!xah || !reiserfs_xattrs(dentry->d_sb) || 747 handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name);
862 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 748
749 if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1)
863 return -EOPNOTSUPP; 750 return -EOPNOTSUPP;
864 751
865 reiserfs_read_lock_xattr_i(dentry->d_inode); 752 return handler->get(inode, name, buffer, size);
866 reiserfs_read_lock_xattrs(dentry->d_sb);
867 err = xah->get(dentry->d_inode, name, buffer, size);
868 reiserfs_read_unlock_xattrs(dentry->d_sb);
869 reiserfs_read_unlock_xattr_i(dentry->d_inode);
870 return err;
871} 753}
872 754
873/* 755/*
@@ -879,27 +761,15 @@ int
879reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, 761reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
880 size_t size, int flags) 762 size_t size, int flags)
881{ 763{
882 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name); 764 struct inode *inode = dentry->d_inode;
883 int err; 765 struct xattr_handler *handler;
884 int lock;
885 766
886 if (!xah || !reiserfs_xattrs(dentry->d_sb) || 767 handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name);
887 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 768
769 if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1)
888 return -EOPNOTSUPP; 770 return -EOPNOTSUPP;
889 771
890 reiserfs_write_lock_xattr_i(dentry->d_inode); 772 return handler->set(inode, name, value, size, flags);
891 lock = !has_xattr_dir(dentry->d_inode);
892 if (lock)
893 reiserfs_write_lock_xattrs(dentry->d_sb);
894 else
895 reiserfs_read_lock_xattrs(dentry->d_sb);
896 err = xah->set(dentry->d_inode, name, value, size, flags);
897 if (lock)
898 reiserfs_write_unlock_xattrs(dentry->d_sb);
899 else
900 reiserfs_read_unlock_xattrs(dentry->d_sb);
901 reiserfs_write_unlock_xattr_i(dentry->d_inode);
902 return err;
903} 773}
904 774
905/* 775/*
@@ -909,86 +779,66 @@ reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
909 */ 779 */
910int reiserfs_removexattr(struct dentry *dentry, const char *name) 780int reiserfs_removexattr(struct dentry *dentry, const char *name)
911{ 781{
912 int err; 782 struct inode *inode = dentry->d_inode;
913 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name); 783 struct xattr_handler *handler;
784 handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name);
914 785
915 if (!xah || !reiserfs_xattrs(dentry->d_sb) || 786 if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1)
916 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
917 return -EOPNOTSUPP; 787 return -EOPNOTSUPP;
918 788
919 reiserfs_write_lock_xattr_i(dentry->d_inode); 789 return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
920 reiserfs_read_lock_xattrs(dentry->d_sb);
921
922 /* Deletion pre-operation */
923 if (xah->del) {
924 err = xah->del(dentry->d_inode, name);
925 if (err)
926 goto out;
927 }
928
929 err = reiserfs_xattr_del(dentry->d_inode, name);
930
931 dentry->d_inode->i_ctime = CURRENT_TIME_SEC;
932 mark_inode_dirty(dentry->d_inode);
933
934 out:
935 reiserfs_read_unlock_xattrs(dentry->d_sb);
936 reiserfs_write_unlock_xattr_i(dentry->d_inode);
937 return err;
938} 790}
939 791
940/* This is what filldir will use: 792struct listxattr_buf {
941 * r_pos will always contain the amount of space required for the entire 793 size_t size;
942 * list. If r_pos becomes larger than r_size, we need more space and we 794 size_t pos;
943 * return an error indicating this. If r_pos is less than r_size, then we've 795 char *buf;
944 * filled the buffer successfully and we return success */ 796 struct inode *inode;
945struct reiserfs_listxattr_buf {
946 int r_pos;
947 int r_size;
948 char *r_buf;
949 struct inode *r_inode;
950}; 797};
951 798
952static int 799static int listxattr_filler(void *buf, const char *name, int namelen,
953reiserfs_listxattr_filler(void *buf, const char *name, int namelen, 800 loff_t offset, u64 ino, unsigned int d_type)
954 loff_t offset, u64 ino, unsigned int d_type)
955{ 801{
956 struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf; 802 struct listxattr_buf *b = (struct listxattr_buf *)buf;
957 int len = 0; 803 size_t size;
958 if (name[0] != '.' 804 if (name[0] != '.' ||
959 || (namelen != 1 && (name[1] != '.' || namelen != 2))) { 805 (namelen != 1 && (name[1] != '.' || namelen != 2))) {
960 struct reiserfs_xattr_handler *xah = 806 struct xattr_handler *handler;
961 find_xattr_handler_prefix(name); 807 handler = find_xattr_handler_prefix(b->inode->i_sb->s_xattr,
962 if (!xah) 808 name);
963 return 0; /* Unsupported xattr name, skip it */ 809 if (!handler) /* Unsupported xattr name */
964 810 return 0;
965 /* We call ->list() twice because the operation isn't required to just 811 if (b->buf) {
966 * return the name back - we want to make sure we have enough space */ 812 size = handler->list(b->inode, b->buf + b->pos,
967 len += xah->list(b->r_inode, name, namelen, NULL); 813 b->size, name, namelen);
968 814 if (size > b->size)
969 if (len) { 815 return -ERANGE;
970 if (b->r_pos + len + 1 <= b->r_size) { 816 } else {
971 char *p = b->r_buf + b->r_pos; 817 size = handler->list(b->inode, NULL, 0, name, namelen);
972 p += xah->list(b->r_inode, name, namelen, p);
973 *p++ = '\0';
974 }
975 b->r_pos += len + 1;
976 } 818 }
977 }
978 819
820 b->pos += size;
821 }
979 return 0; 822 return 0;
980} 823}
981 824
982/* 825/*
983 * Inode operation listxattr() 826 * Inode operation listxattr()
984 * 827 *
985 * Preliminary locking: we down dentry->d_inode->i_mutex 828 * We totally ignore the generic listxattr here because it would be stupid
829 * not to. Since the xattrs are organized in a directory, we can just
830 * readdir to find them.
986 */ 831 */
987ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) 832ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
988{ 833{
989 struct dentry *dir; 834 struct dentry *dir;
990 int err = 0; 835 int err = 0;
991 struct reiserfs_listxattr_buf buf; 836 loff_t pos = 0;
837 struct listxattr_buf buf = {
838 .inode = dentry->d_inode,
839 .buf = buffer,
840 .size = buffer ? size : 0,
841 };
992 842
993 if (!dentry->d_inode) 843 if (!dentry->d_inode)
994 return -EINVAL; 844 return -EINVAL;
@@ -997,130 +847,104 @@ ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
997 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 847 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
998 return -EOPNOTSUPP; 848 return -EOPNOTSUPP;
999 849
1000 reiserfs_read_lock_xattr_i(dentry->d_inode); 850 dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE);
1001 reiserfs_read_lock_xattrs(dentry->d_sb);
1002 dir = open_xa_dir(dentry->d_inode, FL_READONLY);
1003 reiserfs_read_unlock_xattrs(dentry->d_sb);
1004 if (IS_ERR(dir)) { 851 if (IS_ERR(dir)) {
1005 err = PTR_ERR(dir); 852 err = PTR_ERR(dir);
1006 if (err == -ENODATA) 853 if (err == -ENODATA)
1007 err = 0; /* Not an error if there aren't any xattrs */ 854 err = 0; /* Not an error if there aren't any xattrs */
1008 goto out; 855 goto out;
1009 } 856 }
1010 857
1011 buf.r_buf = buffer; 858 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
1012 buf.r_size = buffer ? size : 0; 859 err = reiserfs_readdir_dentry(dir, &buf, listxattr_filler, &pos);
1013 buf.r_pos = 0; 860 mutex_unlock(&dir->d_inode->i_mutex);
1014 buf.r_inode = dentry->d_inode;
1015 861
1016 REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir; 862 if (!err)
1017 863 err = buf.pos;
1018 err = xattr_readdir(dir->d_inode, reiserfs_listxattr_filler, &buf);
1019 if (err)
1020 goto out_dir;
1021
1022 if (buf.r_pos > buf.r_size && buffer != NULL)
1023 err = -ERANGE;
1024 else
1025 err = buf.r_pos;
1026 864
1027 out_dir:
1028 dput(dir); 865 dput(dir);
1029 866out:
1030 out:
1031 reiserfs_read_unlock_xattr_i(dentry->d_inode);
1032 return err; 867 return err;
1033} 868}
1034 869
1035/* This is the implementation for the xattr plugin infrastructure */ 870static int reiserfs_check_acl(struct inode *inode, int mask)
1036static LIST_HEAD(xattr_handlers);
1037static DEFINE_RWLOCK(handler_lock);
1038
1039static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
1040 *prefix)
1041{ 871{
1042 struct reiserfs_xattr_handler *xah = NULL; 872 struct posix_acl *acl;
1043 struct list_head *p; 873 int error = -EAGAIN; /* do regular unix permission checks by default */
1044 874
1045 read_lock(&handler_lock); 875 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
1046 list_for_each(p, &xattr_handlers) { 876
1047 xah = list_entry(p, struct reiserfs_xattr_handler, handlers); 877 if (acl) {
1048 if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0) 878 if (!IS_ERR(acl)) {
1049 break; 879 error = posix_acl_permission(inode, acl, mask);
1050 xah = NULL; 880 posix_acl_release(acl);
881 } else if (PTR_ERR(acl) != -ENODATA)
882 error = PTR_ERR(acl);
1051 } 883 }
1052 884
1053 read_unlock(&handler_lock); 885 return error;
1054 return xah;
1055} 886}
1056 887
1057static void __unregister_handlers(void) 888int reiserfs_permission(struct inode *inode, int mask)
1058{ 889{
1059 struct reiserfs_xattr_handler *xah; 890 /*
1060 struct list_head *p, *tmp; 891 * We don't do permission checks on the internal objects.
1061 892 * Permissions are determined by the "owning" object.
1062 list_for_each_safe(p, tmp, &xattr_handlers) { 893 */
1063 xah = list_entry(p, struct reiserfs_xattr_handler, handlers); 894 if (IS_PRIVATE(inode))
1064 if (xah->exit) 895 return 0;
1065 xah->exit(); 896 /*
1066 897 * Stat data v1 doesn't support ACLs.
1067 list_del_init(p); 898 */
1068 } 899 if (get_inode_sd_version(inode) == STAT_DATA_V1)
1069 INIT_LIST_HEAD(&xattr_handlers); 900 return generic_permission(inode, mask, NULL);
901 else
902 return generic_permission(inode, mask, reiserfs_check_acl);
1070} 903}
1071 904
1072int __init reiserfs_xattr_register_handlers(void) 905static int create_privroot(struct dentry *dentry)
1073{ 906{
1074 int err = 0; 907 int err;
1075 struct reiserfs_xattr_handler *xah; 908 struct inode *inode = dentry->d_parent->d_inode;
1076 struct list_head *p; 909 mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR);
1077 910 err = xattr_mkdir(inode, dentry, 0700);
1078 write_lock(&handler_lock); 911 mutex_unlock(&inode->i_mutex);
1079 912 if (err) {
1080 /* If we're already initialized, nothing to do */ 913 dput(dentry);
1081 if (!list_empty(&xattr_handlers)) { 914 dentry = NULL;
1082 write_unlock(&handler_lock);
1083 return 0;
1084 }
1085
1086 /* Add the handlers */
1087 list_add_tail(&user_handler.handlers, &xattr_handlers);
1088 list_add_tail(&trusted_handler.handlers, &xattr_handlers);
1089#ifdef CONFIG_REISERFS_FS_SECURITY
1090 list_add_tail(&security_handler.handlers, &xattr_handlers);
1091#endif
1092#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1093 list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers);
1094 list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers);
1095#endif
1096
1097 /* Run initializers, if available */
1098 list_for_each(p, &xattr_handlers) {
1099 xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
1100 if (xah->init) {
1101 err = xah->init();
1102 if (err) {
1103 list_del_init(p);
1104 break;
1105 }
1106 }
1107 } 915 }
1108 916
1109 /* Clean up other handlers, if any failed */ 917 if (dentry && dentry->d_inode)
1110 if (err) 918 reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr "
1111 __unregister_handlers(); 919 "storage.\n", PRIVROOT_NAME);
1112 920
1113 write_unlock(&handler_lock);
1114 return err; 921 return err;
1115} 922}
1116 923
1117void reiserfs_xattr_unregister_handlers(void) 924static int xattr_mount_check(struct super_block *s)
1118{ 925{
1119 write_lock(&handler_lock); 926 /* We need generation numbers to ensure that the oid mapping is correct
1120 __unregister_handlers(); 927 * v3.5 filesystems don't have them. */
1121 write_unlock(&handler_lock); 928 if (old_format_only(s)) {
929 if (reiserfs_xattrs_optional(s)) {
930 /* Old format filesystem, but optional xattrs have
931 * been enabled. Error out. */
932 reiserfs_warning(s, "jdm-2005",
933 "xattrs/ACLs not supported "
934 "on pre-v3.6 format filesystems. "
935 "Failing mount.");
936 return -EOPNOTSUPP;
937 }
938 }
939
940 return 0;
1122} 941}
1123 942
943#else
944int __init reiserfs_xattr_register_handlers(void) { return 0; }
945void reiserfs_xattr_unregister_handlers(void) {}
946#endif
947
1124/* This will catch lookups from the fs root to .reiserfs_priv */ 948/* This will catch lookups from the fs root to .reiserfs_priv */
1125static int 949static int
1126xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name) 950xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name)
@@ -1136,7 +960,7 @@ xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name)
1136 return 1; 960 return 1;
1137} 961}
1138 962
1139static struct dentry_operations xattr_lookup_poison_ops = { 963static const struct dentry_operations xattr_lookup_poison_ops = {
1140 .d_compare = xattr_lookup_poison, 964 .d_compare = xattr_lookup_poison,
1141}; 965};
1142 966
@@ -1147,48 +971,23 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1147{ 971{
1148 int err = 0; 972 int err = 0;
1149 973
1150 /* We need generation numbers to ensure that the oid mapping is correct 974#ifdef CONFIG_REISERFS_FS_XATTR
1151 * v3.5 filesystems don't have them. */ 975 err = xattr_mount_check(s);
1152 if (!old_format_only(s)) { 976 if (err)
1153 set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1154 } else if (reiserfs_xattrs_optional(s)) {
1155 /* Old format filesystem, but optional xattrs have been enabled
1156 * at mount time. Error out. */
1157 reiserfs_warning(s, "xattrs/ACLs not supported on pre v3.6 "
1158 "format filesystem. Failing mount.");
1159 err = -EOPNOTSUPP;
1160 goto error; 977 goto error;
1161 } else { 978#endif
1162 /* Old format filesystem, but no optional xattrs have been enabled. This
1163 * means we silently disable xattrs on the filesystem. */
1164 clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1165 }
1166 979
1167 /* If we don't have the privroot located yet - go find it */ 980 /* If we don't have the privroot located yet - go find it */
1168 if (reiserfs_xattrs(s) && !REISERFS_SB(s)->priv_root) { 981 if (!REISERFS_SB(s)->priv_root) {
1169 struct dentry *dentry; 982 struct dentry *dentry;
1170 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root, 983 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
1171 strlen(PRIVROOT_NAME)); 984 strlen(PRIVROOT_NAME));
1172 if (!IS_ERR(dentry)) { 985 if (!IS_ERR(dentry)) {
1173 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) { 986#ifdef CONFIG_REISERFS_FS_XATTR
1174 struct inode *inode = dentry->d_parent->d_inode; 987 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode)
1175 mutex_lock_nested(&inode->i_mutex, 988 err = create_privroot(dentry);
1176 I_MUTEX_XATTR); 989#endif
1177 err = inode->i_op->mkdir(inode, dentry, 0700); 990 if (!dentry->d_inode) {
1178 mutex_unlock(&inode->i_mutex);
1179 if (err) {
1180 dput(dentry);
1181 dentry = NULL;
1182 }
1183
1184 if (dentry && dentry->d_inode)
1185 reiserfs_warning(s,
1186 "Created %s on %s - reserved for "
1187 "xattr storage.",
1188 PRIVROOT_NAME,
1189 reiserfs_bdevname
1190 (inode->i_sb));
1191 } else if (!dentry->d_inode) {
1192 dput(dentry); 991 dput(dentry);
1193 dentry = NULL; 992 dentry = NULL;
1194 } 993 }
@@ -1197,73 +996,41 @@ int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1197 996
1198 if (!err && dentry) { 997 if (!err && dentry) {
1199 s->s_root->d_op = &xattr_lookup_poison_ops; 998 s->s_root->d_op = &xattr_lookup_poison_ops;
1200 reiserfs_mark_inode_private(dentry->d_inode); 999 dentry->d_inode->i_flags |= S_PRIVATE;
1201 REISERFS_SB(s)->priv_root = dentry; 1000 REISERFS_SB(s)->priv_root = dentry;
1202 } else if (!(mount_flags & MS_RDONLY)) { /* xattrs are unavailable */ 1001#ifdef CONFIG_REISERFS_FS_XATTR
1203 /* If we're read-only it just means that the dir hasn't been 1002 /* xattrs are unavailable */
1204 * created. Not an error -- just no xattrs on the fs. We'll 1003 } else if (!(mount_flags & MS_RDONLY)) {
1205 * check again if we go read-write */ 1004 /* If we're read-only it just means that the dir
1206 reiserfs_warning(s, "xattrs/ACLs enabled and couldn't " 1005 * hasn't been created. Not an error -- just no
1207 "find/create .reiserfs_priv. Failing mount."); 1006 * xattrs on the fs. We'll check again if we
1007 * go read-write */
1008 reiserfs_warning(s, "jdm-20006",
1009 "xattrs/ACLs enabled and couldn't "
1010 "find/create .reiserfs_priv. "
1011 "Failing mount.");
1208 err = -EOPNOTSUPP; 1012 err = -EOPNOTSUPP;
1013#endif
1209 } 1014 }
1210 } 1015 }
1211 1016
1212 error: 1017#ifdef CONFIG_REISERFS_FS_XATTR
1213 /* This is only nonzero if there was an error initializing the xattr 1018 if (!err)
1214 * directory or if there is a condition where we don't support them. */ 1019 s->s_xattr = reiserfs_xattr_handlers;
1020
1021error:
1215 if (err) { 1022 if (err) {
1216 clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1217 clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt)); 1023 clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt));
1218 clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt)); 1024 clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt));
1219 } 1025 }
1026#endif
1220 1027
1221 /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */ 1028 /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */
1222 s->s_flags = s->s_flags & ~MS_POSIXACL; 1029 s->s_flags = s->s_flags & ~MS_POSIXACL;
1030#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1223 if (reiserfs_posixacl(s)) 1031 if (reiserfs_posixacl(s))
1224 s->s_flags |= MS_POSIXACL; 1032 s->s_flags |= MS_POSIXACL;
1033#endif
1225 1034
1226 return err; 1035 return err;
1227} 1036}
1228
1229static int reiserfs_check_acl(struct inode *inode, int mask)
1230{
1231 struct posix_acl *acl;
1232 int error = -EAGAIN; /* do regular unix permission checks by default */
1233
1234 reiserfs_read_lock_xattr_i(inode);
1235 reiserfs_read_lock_xattrs(inode->i_sb);
1236
1237 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
1238
1239 reiserfs_read_unlock_xattrs(inode->i_sb);
1240 reiserfs_read_unlock_xattr_i(inode);
1241
1242 if (acl) {
1243 if (!IS_ERR(acl)) {
1244 error = posix_acl_permission(inode, acl, mask);
1245 posix_acl_release(acl);
1246 } else if (PTR_ERR(acl) != -ENODATA)
1247 error = PTR_ERR(acl);
1248 }
1249
1250 return error;
1251}
1252
1253int reiserfs_permission(struct inode *inode, int mask)
1254{
1255 /*
1256 * We don't do permission checks on the internal objects.
1257 * Permissions are determined by the "owning" object.
1258 */
1259 if (is_reiserfs_priv_object(inode))
1260 return 0;
1261
1262 /*
1263 * Stat data v1 doesn't support ACLs.
1264 */
1265 if (get_inode_sd_version(inode) == STAT_DATA_V1)
1266 return generic_permission(inode, mask, NULL);
1267 else
1268 return generic_permission(inode, mask, reiserfs_check_acl);
1269}
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index b7e4fa4539d..d423416d93d 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -10,15 +10,17 @@
10#include <linux/reiserfs_acl.h> 10#include <linux/reiserfs_acl.h>
11#include <asm/uaccess.h> 11#include <asm/uaccess.h>
12 12
13static int reiserfs_set_acl(struct inode *inode, int type, 13static int reiserfs_set_acl(struct reiserfs_transaction_handle *th,
14 struct inode *inode, int type,
14 struct posix_acl *acl); 15 struct posix_acl *acl);
15 16
16static int 17static int
17xattr_set_acl(struct inode *inode, int type, const void *value, size_t size) 18xattr_set_acl(struct inode *inode, int type, const void *value, size_t size)
18{ 19{
19 struct posix_acl *acl; 20 struct posix_acl *acl;
20 int error; 21 int error, error2;
21 22 struct reiserfs_transaction_handle th;
23 size_t jcreate_blocks;
22 if (!reiserfs_posixacl(inode->i_sb)) 24 if (!reiserfs_posixacl(inode->i_sb))
23 return -EOPNOTSUPP; 25 return -EOPNOTSUPP;
24 if (!is_owner_or_cap(inode)) 26 if (!is_owner_or_cap(inode))
@@ -36,7 +38,21 @@ xattr_set_acl(struct inode *inode, int type, const void *value, size_t size)
36 } else 38 } else
37 acl = NULL; 39 acl = NULL;
38 40
39 error = reiserfs_set_acl(inode, type, acl); 41 /* Pessimism: We can't assume that anything from the xattr root up
42 * has been created. */
43
44 jcreate_blocks = reiserfs_xattr_jcreate_nblocks(inode) +
45 reiserfs_xattr_nblocks(inode, size) * 2;
46
47 reiserfs_write_lock(inode->i_sb);
48 error = journal_begin(&th, inode->i_sb, jcreate_blocks);
49 if (error == 0) {
50 error = reiserfs_set_acl(&th, inode, type, acl);
51 error2 = journal_end(&th, inode->i_sb, jcreate_blocks);
52 if (error2)
53 error = error2;
54 }
55 reiserfs_write_unlock(inode->i_sb);
40 56
41 release_and_out: 57 release_and_out:
42 posix_acl_release(acl); 58 posix_acl_release(acl);
@@ -172,6 +188,29 @@ static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
172 return ERR_PTR(-EINVAL); 188 return ERR_PTR(-EINVAL);
173} 189}
174 190
191static inline void iset_acl(struct inode *inode, struct posix_acl **i_acl,
192 struct posix_acl *acl)
193{
194 spin_lock(&inode->i_lock);
195 if (*i_acl != ERR_PTR(-ENODATA))
196 posix_acl_release(*i_acl);
197 *i_acl = posix_acl_dup(acl);
198 spin_unlock(&inode->i_lock);
199}
200
201static inline struct posix_acl *iget_acl(struct inode *inode,
202 struct posix_acl **i_acl)
203{
204 struct posix_acl *acl = ERR_PTR(-ENODATA);
205
206 spin_lock(&inode->i_lock);
207 if (*i_acl != ERR_PTR(-ENODATA))
208 acl = posix_acl_dup(*i_acl);
209 spin_unlock(&inode->i_lock);
210
211 return acl;
212}
213
175/* 214/*
176 * Inode operation get_posix_acl(). 215 * Inode operation get_posix_acl().
177 * 216 *
@@ -199,11 +238,11 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
199 return ERR_PTR(-EINVAL); 238 return ERR_PTR(-EINVAL);
200 } 239 }
201 240
202 if (IS_ERR(*p_acl)) { 241 acl = iget_acl(inode, p_acl);
203 if (PTR_ERR(*p_acl) == -ENODATA) 242 if (acl && !IS_ERR(acl))
204 return NULL; 243 return acl;
205 } else if (*p_acl != NULL) 244 else if (PTR_ERR(acl) == -ENODATA)
206 return posix_acl_dup(*p_acl); 245 return NULL;
207 246
208 size = reiserfs_xattr_get(inode, name, NULL, 0); 247 size = reiserfs_xattr_get(inode, name, NULL, 0);
209 if (size < 0) { 248 if (size < 0) {
@@ -229,7 +268,7 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
229 } else { 268 } else {
230 acl = posix_acl_from_disk(value, retval); 269 acl = posix_acl_from_disk(value, retval);
231 if (!IS_ERR(acl)) 270 if (!IS_ERR(acl))
232 *p_acl = posix_acl_dup(acl); 271 iset_acl(inode, p_acl, acl);
233 } 272 }
234 273
235 kfree(value); 274 kfree(value);
@@ -243,12 +282,13 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int type)
243 * BKL held [before 2.5.x] 282 * BKL held [before 2.5.x]
244 */ 283 */
245static int 284static int
246reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl) 285reiserfs_set_acl(struct reiserfs_transaction_handle *th, struct inode *inode,
286 int type, struct posix_acl *acl)
247{ 287{
248 char *name; 288 char *name;
249 void *value = NULL; 289 void *value = NULL;
250 struct posix_acl **p_acl; 290 struct posix_acl **p_acl;
251 size_t size; 291 size_t size = 0;
252 int error; 292 int error;
253 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); 293 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
254 294
@@ -285,31 +325,28 @@ reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
285 value = posix_acl_to_disk(acl, &size); 325 value = posix_acl_to_disk(acl, &size);
286 if (IS_ERR(value)) 326 if (IS_ERR(value))
287 return (int)PTR_ERR(value); 327 return (int)PTR_ERR(value);
288 error = reiserfs_xattr_set(inode, name, value, size, 0); 328 }
289 } else { 329
290 error = reiserfs_xattr_del(inode, name); 330 error = reiserfs_xattr_set_handle(th, inode, name, value, size, 0);
291 if (error == -ENODATA) { 331
292 /* This may seem odd here, but it means that the ACL was set 332 /*
293 * with a value representable with mode bits. If there was 333 * Ensure that the inode gets dirtied if we're only using
294 * an ACL before, reiserfs_xattr_del already dirtied the inode. 334 * the mode bits and an old ACL didn't exist. We don't need
295 */ 335 * to check if the inode is hashed here since we won't get
336 * called by reiserfs_inherit_default_acl().
337 */
338 if (error == -ENODATA) {
339 error = 0;
340 if (type == ACL_TYPE_ACCESS) {
341 inode->i_ctime = CURRENT_TIME_SEC;
296 mark_inode_dirty(inode); 342 mark_inode_dirty(inode);
297 error = 0;
298 } 343 }
299 } 344 }
300 345
301 kfree(value); 346 kfree(value);
302 347
303 if (!error) { 348 if (!error)
304 /* Release the old one */ 349 iset_acl(inode, p_acl, acl);
305 if (!IS_ERR(*p_acl) && *p_acl)
306 posix_acl_release(*p_acl);
307
308 if (acl == NULL)
309 *p_acl = ERR_PTR(-ENODATA);
310 else
311 *p_acl = posix_acl_dup(acl);
312 }
313 350
314 return error; 351 return error;
315} 352}
@@ -317,7 +354,8 @@ reiserfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
317/* dir->i_mutex: locked, 354/* dir->i_mutex: locked,
318 * inode is new and not released into the wild yet */ 355 * inode is new and not released into the wild yet */
319int 356int
320reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry, 357reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
358 struct inode *dir, struct dentry *dentry,
321 struct inode *inode) 359 struct inode *inode)
322{ 360{
323 struct posix_acl *acl; 361 struct posix_acl *acl;
@@ -335,8 +373,8 @@ reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
335 /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This 373 /* Don't apply ACLs to objects in the .reiserfs_priv tree.. This
336 * would be useless since permissions are ignored, and a pain because 374 * would be useless since permissions are ignored, and a pain because
337 * it introduces locking cycles */ 375 * it introduces locking cycles */
338 if (is_reiserfs_priv_object(dir)) { 376 if (IS_PRIVATE(dir)) {
339 reiserfs_mark_inode_private(inode); 377 inode->i_flags |= S_PRIVATE;
340 goto apply_umask; 378 goto apply_umask;
341 } 379 }
342 380
@@ -354,7 +392,8 @@ reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
354 392
355 /* Copy the default ACL to the default ACL of a new directory */ 393 /* Copy the default ACL to the default ACL of a new directory */
356 if (S_ISDIR(inode->i_mode)) { 394 if (S_ISDIR(inode->i_mode)) {
357 err = reiserfs_set_acl(inode, ACL_TYPE_DEFAULT, acl); 395 err = reiserfs_set_acl(th, inode, ACL_TYPE_DEFAULT,
396 acl);
358 if (err) 397 if (err)
359 goto cleanup; 398 goto cleanup;
360 } 399 }
@@ -375,9 +414,9 @@ reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
375 414
376 /* If we need an ACL.. */ 415 /* If we need an ACL.. */
377 if (need_acl > 0) { 416 if (need_acl > 0) {
378 err = 417 err = reiserfs_set_acl(th, inode,
379 reiserfs_set_acl(inode, ACL_TYPE_ACCESS, 418 ACL_TYPE_ACCESS,
380 acl_copy); 419 acl_copy);
381 if (err) 420 if (err)
382 goto cleanup_copy; 421 goto cleanup_copy;
383 } 422 }
@@ -395,25 +434,45 @@ reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
395 return err; 434 return err;
396} 435}
397 436
398/* Looks up and caches the result of the default ACL. 437/* This is used to cache the default acl before a new object is created.
399 * We do this so that we don't need to carry the xattr_sem into 438 * The biggest reason for this is to get an idea of how many blocks will
400 * reiserfs_new_inode if we don't need to */ 439 * actually be required for the create operation if we must inherit an ACL.
440 * An ACL write can add up to 3 object creations and an additional file write
441 * so we'd prefer not to reserve that many blocks in the journal if we can.
442 * It also has the advantage of not loading the ACL with a transaction open,
443 * this may seem silly, but if the owner of the directory is doing the
444 * creation, the ACL may not be loaded since the permissions wouldn't require
445 * it.
446 * We return the number of blocks required for the transaction.
447 */
401int reiserfs_cache_default_acl(struct inode *inode) 448int reiserfs_cache_default_acl(struct inode *inode)
402{ 449{
403 int ret = 0; 450 struct posix_acl *acl;
404 if (reiserfs_posixacl(inode->i_sb) && !is_reiserfs_priv_object(inode)) { 451 int nblocks = 0;
405 struct posix_acl *acl; 452
406 reiserfs_read_lock_xattr_i(inode); 453 if (IS_PRIVATE(inode))
407 reiserfs_read_lock_xattrs(inode->i_sb); 454 return 0;
408 acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT); 455
409 reiserfs_read_unlock_xattrs(inode->i_sb); 456 acl = reiserfs_get_acl(inode, ACL_TYPE_DEFAULT);
410 reiserfs_read_unlock_xattr_i(inode); 457
411 ret = (acl && !IS_ERR(acl)); 458 if (acl && !IS_ERR(acl)) {
412 if (ret) 459 int size = reiserfs_acl_size(acl->a_count);
413 posix_acl_release(acl); 460
461 /* Other xattrs can be created during inode creation. We don't
462 * want to claim too many blocks, so we check to see if we
463 * we need to create the tree to the xattrs, and then we
464 * just want two files. */
465 nblocks = reiserfs_xattr_jcreate_nblocks(inode);
466 nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
467
468 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
469
470 /* We need to account for writes + bitmaps for two files */
471 nblocks += reiserfs_xattr_nblocks(inode, size) * 4;
472 posix_acl_release(acl);
414 } 473 }
415 474
416 return ret; 475 return nblocks;
417} 476}
418 477
419int reiserfs_acl_chmod(struct inode *inode) 478int reiserfs_acl_chmod(struct inode *inode)
@@ -429,9 +488,7 @@ int reiserfs_acl_chmod(struct inode *inode)
429 return 0; 488 return 0;
430 } 489 }
431 490
432 reiserfs_read_lock_xattrs(inode->i_sb);
433 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); 491 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
434 reiserfs_read_unlock_xattrs(inode->i_sb);
435 if (!acl) 492 if (!acl)
436 return 0; 493 return 0;
437 if (IS_ERR(acl)) 494 if (IS_ERR(acl))
@@ -442,18 +499,20 @@ int reiserfs_acl_chmod(struct inode *inode)
442 return -ENOMEM; 499 return -ENOMEM;
443 error = posix_acl_chmod_masq(clone, inode->i_mode); 500 error = posix_acl_chmod_masq(clone, inode->i_mode);
444 if (!error) { 501 if (!error) {
445 int lock = !has_xattr_dir(inode); 502 struct reiserfs_transaction_handle th;
446 reiserfs_write_lock_xattr_i(inode); 503 size_t size = reiserfs_xattr_nblocks(inode,
447 if (lock) 504 reiserfs_acl_size(clone->a_count));
448 reiserfs_write_lock_xattrs(inode->i_sb); 505 reiserfs_write_lock(inode->i_sb);
449 else 506 error = journal_begin(&th, inode->i_sb, size * 2);
450 reiserfs_read_lock_xattrs(inode->i_sb); 507 if (!error) {
451 error = reiserfs_set_acl(inode, ACL_TYPE_ACCESS, clone); 508 int error2;
452 if (lock) 509 error = reiserfs_set_acl(&th, inode, ACL_TYPE_ACCESS,
453 reiserfs_write_unlock_xattrs(inode->i_sb); 510 clone);
454 else 511 error2 = journal_end(&th, inode->i_sb, size * 2);
455 reiserfs_read_unlock_xattrs(inode->i_sb); 512 if (error2)
456 reiserfs_write_unlock_xattr_i(inode); 513 error = error2;
514 }
515 reiserfs_write_unlock(inode->i_sb);
457 } 516 }
458 posix_acl_release(clone); 517 posix_acl_release(clone);
459 return error; 518 return error;
@@ -477,38 +536,22 @@ posix_acl_access_set(struct inode *inode, const char *name,
477 return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 536 return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
478} 537}
479 538
480static int posix_acl_access_del(struct inode *inode, const char *name) 539static size_t posix_acl_access_list(struct inode *inode, char *list,
540 size_t list_size, const char *name,
541 size_t name_len)
481{ 542{
482 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); 543 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
483 struct posix_acl **acl = &reiserfs_i->i_acl_access;
484 if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
485 return -EINVAL;
486 if (!IS_ERR(*acl) && *acl) {
487 posix_acl_release(*acl);
488 *acl = ERR_PTR(-ENODATA);
489 }
490
491 return 0;
492}
493
494static int
495posix_acl_access_list(struct inode *inode, const char *name, int namelen,
496 char *out)
497{
498 int len = namelen;
499 if (!reiserfs_posixacl(inode->i_sb)) 544 if (!reiserfs_posixacl(inode->i_sb))
500 return 0; 545 return 0;
501 if (out) 546 if (list && size <= list_size)
502 memcpy(out, name, len); 547 memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
503 548 return size;
504 return len;
505} 549}
506 550
507struct reiserfs_xattr_handler posix_acl_access_handler = { 551struct xattr_handler reiserfs_posix_acl_access_handler = {
508 .prefix = POSIX_ACL_XATTR_ACCESS, 552 .prefix = POSIX_ACL_XATTR_ACCESS,
509 .get = posix_acl_access_get, 553 .get = posix_acl_access_get,
510 .set = posix_acl_access_set, 554 .set = posix_acl_access_set,
511 .del = posix_acl_access_del,
512 .list = posix_acl_access_list, 555 .list = posix_acl_access_list,
513}; 556};
514 557
@@ -530,37 +573,21 @@ posix_acl_default_set(struct inode *inode, const char *name,
530 return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 573 return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
531} 574}
532 575
533static int posix_acl_default_del(struct inode *inode, const char *name) 576static size_t posix_acl_default_list(struct inode *inode, char *list,
577 size_t list_size, const char *name,
578 size_t name_len)
534{ 579{
535 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode); 580 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
536 struct posix_acl **acl = &reiserfs_i->i_acl_default;
537 if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
538 return -EINVAL;
539 if (!IS_ERR(*acl) && *acl) {
540 posix_acl_release(*acl);
541 *acl = ERR_PTR(-ENODATA);
542 }
543
544 return 0;
545}
546
547static int
548posix_acl_default_list(struct inode *inode, const char *name, int namelen,
549 char *out)
550{
551 int len = namelen;
552 if (!reiserfs_posixacl(inode->i_sb)) 581 if (!reiserfs_posixacl(inode->i_sb))
553 return 0; 582 return 0;
554 if (out) 583 if (list && size <= list_size)
555 memcpy(out, name, len); 584 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
556 585 return size;
557 return len;
558} 586}
559 587
560struct reiserfs_xattr_handler posix_acl_default_handler = { 588struct xattr_handler reiserfs_posix_acl_default_handler = {
561 .prefix = POSIX_ACL_XATTR_DEFAULT, 589 .prefix = POSIX_ACL_XATTR_DEFAULT,
562 .get = posix_acl_default_get, 590 .get = posix_acl_default_get,
563 .set = posix_acl_default_set, 591 .set = posix_acl_default_set,
564 .del = posix_acl_default_del,
565 .list = posix_acl_default_list, 592 .list = posix_acl_default_list,
566}; 593};
diff --git a/fs/reiserfs/xattr_security.c b/fs/reiserfs/xattr_security.c
index 056008db137..4d3c20e787c 100644
--- a/fs/reiserfs/xattr_security.c
+++ b/fs/reiserfs/xattr_security.c
@@ -4,6 +4,7 @@
4#include <linux/pagemap.h> 4#include <linux/pagemap.h>
5#include <linux/xattr.h> 5#include <linux/xattr.h>
6#include <linux/reiserfs_xattr.h> 6#include <linux/reiserfs_xattr.h>
7#include <linux/security.h>
7#include <asm/uaccess.h> 8#include <asm/uaccess.h>
8 9
9static int 10static int
@@ -12,7 +13,7 @@ security_get(struct inode *inode, const char *name, void *buffer, size_t size)
12 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 13 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
13 return -EINVAL; 14 return -EINVAL;
14 15
15 if (is_reiserfs_priv_object(inode)) 16 if (IS_PRIVATE(inode))
16 return -EPERM; 17 return -EPERM;
17 18
18 return reiserfs_xattr_get(inode, name, buffer, size); 19 return reiserfs_xattr_get(inode, name, buffer, size);
@@ -25,41 +26,84 @@ security_set(struct inode *inode, const char *name, const void *buffer,
25 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 26 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
26 return -EINVAL; 27 return -EINVAL;
27 28
28 if (is_reiserfs_priv_object(inode)) 29 if (IS_PRIVATE(inode))
29 return -EPERM; 30 return -EPERM;
30 31
31 return reiserfs_xattr_set(inode, name, buffer, size, flags); 32 return reiserfs_xattr_set(inode, name, buffer, size, flags);
32} 33}
33 34
34static int security_del(struct inode *inode, const char *name) 35static size_t security_list(struct inode *inode, char *list, size_t list_len,
36 const char *name, size_t namelen)
35{ 37{
36 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 38 const size_t len = namelen + 1;
37 return -EINVAL;
38 39
39 if (is_reiserfs_priv_object(inode)) 40 if (IS_PRIVATE(inode))
40 return -EPERM; 41 return 0;
42
43 if (list && len <= list_len) {
44 memcpy(list, name, namelen);
45 list[namelen] = '\0';
46 }
41 47
42 return 0; 48 return len;
43} 49}
44 50
45static int 51/* Initializes the security context for a new inode and returns the number
46security_list(struct inode *inode, const char *name, int namelen, char *out) 52 * of blocks needed for the transaction. If successful, reiserfs_security
53 * must be released using reiserfs_security_free when the caller is done. */
54int reiserfs_security_init(struct inode *dir, struct inode *inode,
55 struct reiserfs_security_handle *sec)
47{ 56{
48 int len = namelen; 57 int blocks = 0;
58 int error = security_inode_init_security(inode, dir, &sec->name,
59 &sec->value, &sec->length);
60 if (error) {
61 if (error == -EOPNOTSUPP)
62 error = 0;
49 63
50 if (is_reiserfs_priv_object(inode)) 64 sec->name = NULL;
51 return 0; 65 sec->value = NULL;
66 sec->length = 0;
67 return error;
68 }
52 69
53 if (out) 70 if (sec->length) {
54 memcpy(out, name, len); 71 blocks = reiserfs_xattr_jcreate_nblocks(inode) +
72 reiserfs_xattr_nblocks(inode, sec->length);
73 /* We don't want to count the directories twice if we have
74 * a default ACL. */
75 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
76 }
77 return blocks;
78}
55 79
56 return len; 80int reiserfs_security_write(struct reiserfs_transaction_handle *th,
81 struct inode *inode,
82 struct reiserfs_security_handle *sec)
83{
84 int error;
85 if (strlen(sec->name) < sizeof(XATTR_SECURITY_PREFIX))
86 return -EINVAL;
87
88 error = reiserfs_xattr_set_handle(th, inode, sec->name, sec->value,
89 sec->length, XATTR_CREATE);
90 if (error == -ENODATA || error == -EOPNOTSUPP)
91 error = 0;
92
93 return error;
94}
95
96void reiserfs_security_free(struct reiserfs_security_handle *sec)
97{
98 kfree(sec->name);
99 kfree(sec->value);
100 sec->name = NULL;
101 sec->value = NULL;
57} 102}
58 103
59struct reiserfs_xattr_handler security_handler = { 104struct xattr_handler reiserfs_xattr_security_handler = {
60 .prefix = XATTR_SECURITY_PREFIX, 105 .prefix = XATTR_SECURITY_PREFIX,
61 .get = security_get, 106 .get = security_get,
62 .set = security_set, 107 .set = security_set,
63 .del = security_del,
64 .list = security_list, 108 .list = security_list,
65}; 109};
diff --git a/fs/reiserfs/xattr_trusted.c b/fs/reiserfs/xattr_trusted.c
index 60abe2bb1f9..a865042f75e 100644
--- a/fs/reiserfs/xattr_trusted.c
+++ b/fs/reiserfs/xattr_trusted.c
@@ -13,10 +13,7 @@ trusted_get(struct inode *inode, const char *name, void *buffer, size_t size)
13 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 13 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
14 return -EINVAL; 14 return -EINVAL;
15 15
16 if (!reiserfs_xattrs(inode->i_sb)) 16 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
17 return -EOPNOTSUPP;
18
19 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
20 return -EPERM; 17 return -EPERM;
21 18
22 return reiserfs_xattr_get(inode, name, buffer, size); 19 return reiserfs_xattr_get(inode, name, buffer, size);
@@ -29,50 +26,30 @@ trusted_set(struct inode *inode, const char *name, const void *buffer,
29 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 26 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
30 return -EINVAL; 27 return -EINVAL;
31 28
32 if (!reiserfs_xattrs(inode->i_sb)) 29 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
33 return -EOPNOTSUPP;
34
35 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
36 return -EPERM; 30 return -EPERM;
37 31
38 return reiserfs_xattr_set(inode, name, buffer, size, flags); 32 return reiserfs_xattr_set(inode, name, buffer, size, flags);
39} 33}
40 34
41static int trusted_del(struct inode *inode, const char *name) 35static size_t trusted_list(struct inode *inode, char *list, size_t list_size,
36 const char *name, size_t name_len)
42{ 37{
43 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 38 const size_t len = name_len + 1;
44 return -EINVAL;
45 39
46 if (!reiserfs_xattrs(inode->i_sb)) 40 if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
47 return -EOPNOTSUPP;
48
49 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode)))
50 return -EPERM;
51
52 return 0;
53}
54
55static int
56trusted_list(struct inode *inode, const char *name, int namelen, char *out)
57{
58 int len = namelen;
59
60 if (!reiserfs_xattrs(inode->i_sb))
61 return 0; 41 return 0;
62 42
63 if (!(capable(CAP_SYS_ADMIN) || is_reiserfs_priv_object(inode))) 43 if (list && len <= list_size) {
64 return 0; 44 memcpy(list, name, name_len);
65 45 list[name_len] = '\0';
66 if (out) 46 }
67 memcpy(out, name, len);
68
69 return len; 47 return len;
70} 48}
71 49
72struct reiserfs_xattr_handler trusted_handler = { 50struct xattr_handler reiserfs_xattr_trusted_handler = {
73 .prefix = XATTR_TRUSTED_PREFIX, 51 .prefix = XATTR_TRUSTED_PREFIX,
74 .get = trusted_get, 52 .get = trusted_get,
75 .set = trusted_set, 53 .set = trusted_set,
76 .del = trusted_del,
77 .list = trusted_list, 54 .list = trusted_list,
78}; 55};
diff --git a/fs/reiserfs/xattr_user.c b/fs/reiserfs/xattr_user.c
index 1384efcb938..e3238dc4f3d 100644
--- a/fs/reiserfs/xattr_user.c
+++ b/fs/reiserfs/xattr_user.c
@@ -6,10 +6,6 @@
6#include <linux/reiserfs_xattr.h> 6#include <linux/reiserfs_xattr.h>
7#include <asm/uaccess.h> 7#include <asm/uaccess.h>
8 8
9#ifdef CONFIG_REISERFS_FS_POSIX_ACL
10# include <linux/reiserfs_acl.h>
11#endif
12
13static int 9static int
14user_get(struct inode *inode, const char *name, void *buffer, size_t size) 10user_get(struct inode *inode, const char *name, void *buffer, size_t size)
15{ 11{
@@ -25,7 +21,6 @@ static int
25user_set(struct inode *inode, const char *name, const void *buffer, 21user_set(struct inode *inode, const char *name, const void *buffer,
26 size_t size, int flags) 22 size_t size, int flags)
27{ 23{
28
29 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 24 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
30 return -EINVAL; 25 return -EINVAL;
31 26
@@ -34,33 +29,23 @@ user_set(struct inode *inode, const char *name, const void *buffer,
34 return reiserfs_xattr_set(inode, name, buffer, size, flags); 29 return reiserfs_xattr_set(inode, name, buffer, size, flags);
35} 30}
36 31
37static int user_del(struct inode *inode, const char *name) 32static size_t user_list(struct inode *inode, char *list, size_t list_size,
33 const char *name, size_t name_len)
38{ 34{
39 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 35 const size_t len = name_len + 1;
40 return -EINVAL;
41
42 if (!reiserfs_xattrs_user(inode->i_sb))
43 return -EOPNOTSUPP;
44 return 0;
45}
46 36
47static int
48user_list(struct inode *inode, const char *name, int namelen, char *out)
49{
50 int len = namelen;
51 if (!reiserfs_xattrs_user(inode->i_sb)) 37 if (!reiserfs_xattrs_user(inode->i_sb))
52 return 0; 38 return 0;
53 39 if (list && len <= list_size) {
54 if (out) 40 memcpy(list, name, name_len);
55 memcpy(out, name, len); 41 list[name_len] = '\0';
56 42 }
57 return len; 43 return len;
58} 44}
59 45
60struct reiserfs_xattr_handler user_handler = { 46struct xattr_handler reiserfs_xattr_user_handler = {
61 .prefix = XATTR_USER_PREFIX, 47 .prefix = XATTR_USER_PREFIX,
62 .get = user_get, 48 .get = user_get,
63 .set = user_set, 49 .set = user_set,
64 .del = user_del,
65 .list = user_list, 50 .list = user_list,
66}; 51};
diff --git a/fs/seq_file.c b/fs/seq_file.c
index a1a4cfe1921..7f40f30c55c 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -513,7 +513,7 @@ int seq_bitmap(struct seq_file *m, const unsigned long *bits,
513} 513}
514EXPORT_SYMBOL(seq_bitmap); 514EXPORT_SYMBOL(seq_bitmap);
515 515
516int seq_bitmap_list(struct seq_file *m, unsigned long *bits, 516int seq_bitmap_list(struct seq_file *m, const unsigned long *bits,
517 unsigned int nr_bits) 517 unsigned int nr_bits)
518{ 518{
519 if (m->count < m->size) { 519 if (m->count < m->size) {
diff --git a/fs/smbfs/dir.c b/fs/smbfs/dir.c
index e7ddd0328dd..3e4803b4427 100644
--- a/fs/smbfs/dir.c
+++ b/fs/smbfs/dir.c
@@ -277,7 +277,7 @@ static int smb_hash_dentry(struct dentry *, struct qstr *);
277static int smb_compare_dentry(struct dentry *, struct qstr *, struct qstr *); 277static int smb_compare_dentry(struct dentry *, struct qstr *, struct qstr *);
278static int smb_delete_dentry(struct dentry *); 278static int smb_delete_dentry(struct dentry *);
279 279
280static struct dentry_operations smbfs_dentry_operations = 280static const struct dentry_operations smbfs_dentry_operations =
281{ 281{
282 .d_revalidate = smb_lookup_validate, 282 .d_revalidate = smb_lookup_validate,
283 .d_hash = smb_hash_dentry, 283 .d_hash = smb_hash_dentry,
@@ -285,7 +285,7 @@ static struct dentry_operations smbfs_dentry_operations =
285 .d_delete = smb_delete_dentry, 285 .d_delete = smb_delete_dentry,
286}; 286};
287 287
288static struct dentry_operations smbfs_dentry_operations_case = 288static const struct dentry_operations smbfs_dentry_operations_case =
289{ 289{
290 .d_revalidate = smb_lookup_validate, 290 .d_revalidate = smb_lookup_validate,
291 .d_delete = smb_delete_dentry, 291 .d_delete = smb_delete_dentry,
diff --git a/fs/super.c b/fs/super.c
index 6ce501447ad..2ba481518ba 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -197,7 +197,7 @@ void deactivate_super(struct super_block *s)
197 if (atomic_dec_and_lock(&s->s_active, &sb_lock)) { 197 if (atomic_dec_and_lock(&s->s_active, &sb_lock)) {
198 s->s_count -= S_BIAS-1; 198 s->s_count -= S_BIAS-1;
199 spin_unlock(&sb_lock); 199 spin_unlock(&sb_lock);
200 DQUOT_OFF(s, 0); 200 vfs_dq_off(s, 0);
201 down_write(&s->s_umount); 201 down_write(&s->s_umount);
202 fs->kill_sb(s); 202 fs->kill_sb(s);
203 put_filesystem(fs); 203 put_filesystem(fs);
@@ -266,7 +266,7 @@ EXPORT_SYMBOL(unlock_super);
266void __fsync_super(struct super_block *sb) 266void __fsync_super(struct super_block *sb)
267{ 267{
268 sync_inodes_sb(sb, 0); 268 sync_inodes_sb(sb, 0);
269 DQUOT_SYNC(sb); 269 vfs_dq_sync(sb);
270 lock_super(sb); 270 lock_super(sb);
271 if (sb->s_dirt && sb->s_op->write_super) 271 if (sb->s_dirt && sb->s_op->write_super)
272 sb->s_op->write_super(sb); 272 sb->s_op->write_super(sb);
@@ -655,7 +655,7 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
655 mark_files_ro(sb); 655 mark_files_ro(sb);
656 else if (!fs_may_remount_ro(sb)) 656 else if (!fs_may_remount_ro(sb))
657 return -EBUSY; 657 return -EBUSY;
658 retval = DQUOT_OFF(sb, 1); 658 retval = vfs_dq_off(sb, 1);
659 if (retval < 0 && retval != -ENOSYS) 659 if (retval < 0 && retval != -ENOSYS)
660 return -EBUSY; 660 return -EBUSY;
661 } 661 }
@@ -670,11 +670,11 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
670 } 670 }
671 sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK); 671 sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
672 if (remount_rw) 672 if (remount_rw)
673 DQUOT_ON_REMOUNT(sb); 673 vfs_dq_quota_on_remount(sb);
674 return 0; 674 return 0;
675} 675}
676 676
677static void do_emergency_remount(unsigned long foo) 677static void do_emergency_remount(struct work_struct *work)
678{ 678{
679 struct super_block *sb; 679 struct super_block *sb;
680 680
@@ -697,12 +697,19 @@ static void do_emergency_remount(unsigned long foo)
697 spin_lock(&sb_lock); 697 spin_lock(&sb_lock);
698 } 698 }
699 spin_unlock(&sb_lock); 699 spin_unlock(&sb_lock);
700 kfree(work);
700 printk("Emergency Remount complete\n"); 701 printk("Emergency Remount complete\n");
701} 702}
702 703
703void emergency_remount(void) 704void emergency_remount(void)
704{ 705{
705 pdflush_operation(do_emergency_remount, 0); 706 struct work_struct *work;
707
708 work = kmalloc(sizeof(*work), GFP_ATOMIC);
709 if (work) {
710 INIT_WORK(work, do_emergency_remount);
711 schedule_work(work);
712 }
706} 713}
707 714
708/* 715/*
@@ -831,7 +838,8 @@ int get_sb_bdev(struct file_system_type *fs_type,
831 bdev->bd_super = s; 838 bdev->bd_super = s;
832 } 839 }
833 840
834 return simple_set_mnt(mnt, s); 841 simple_set_mnt(mnt, s);
842 return 0;
835 843
836error_s: 844error_s:
837 error = PTR_ERR(s); 845 error = PTR_ERR(s);
@@ -877,7 +885,8 @@ int get_sb_nodev(struct file_system_type *fs_type,
877 return error; 885 return error;
878 } 886 }
879 s->s_flags |= MS_ACTIVE; 887 s->s_flags |= MS_ACTIVE;
880 return simple_set_mnt(mnt, s); 888 simple_set_mnt(mnt, s);
889 return 0;
881} 890}
882 891
883EXPORT_SYMBOL(get_sb_nodev); 892EXPORT_SYMBOL(get_sb_nodev);
@@ -909,7 +918,8 @@ int get_sb_single(struct file_system_type *fs_type,
909 s->s_flags |= MS_ACTIVE; 918 s->s_flags |= MS_ACTIVE;
910 } 919 }
911 do_remount_sb(s, flags, data, 0); 920 do_remount_sb(s, flags, data, 0);
912 return simple_set_mnt(mnt, s); 921 simple_set_mnt(mnt, s);
922 return 0;
913} 923}
914 924
915EXPORT_SYMBOL(get_sb_single); 925EXPORT_SYMBOL(get_sb_single);
diff --git a/fs/sync.c b/fs/sync.c
index a16d53e5fe9..7abc65fbf21 100644
--- a/fs/sync.c
+++ b/fs/sync.c
@@ -25,7 +25,7 @@ static void do_sync(unsigned long wait)
25{ 25{
26 wakeup_pdflush(0); 26 wakeup_pdflush(0);
27 sync_inodes(0); /* All mappings, inodes and their blockdevs */ 27 sync_inodes(0); /* All mappings, inodes and their blockdevs */
28 DQUOT_SYNC(NULL); 28 vfs_dq_sync(NULL);
29 sync_supers(); /* Write the superblocks */ 29 sync_supers(); /* Write the superblocks */
30 sync_filesystems(0); /* Start syncing the filesystems */ 30 sync_filesystems(0); /* Start syncing the filesystems */
31 sync_filesystems(wait); /* Waitingly sync the filesystems */ 31 sync_filesystems(wait); /* Waitingly sync the filesystems */
@@ -42,9 +42,21 @@ SYSCALL_DEFINE0(sync)
42 return 0; 42 return 0;
43} 43}
44 44
45static void do_sync_work(struct work_struct *work)
46{
47 do_sync(0);
48 kfree(work);
49}
50
45void emergency_sync(void) 51void emergency_sync(void)
46{ 52{
47 pdflush_operation(do_sync, 0); 53 struct work_struct *work;
54
55 work = kmalloc(sizeof(*work), GFP_ATOMIC);
56 if (work) {
57 INIT_WORK(work, do_sync_work);
58 schedule_work(work);
59 }
48} 60}
49 61
50/* 62/*
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index f2c478c3424..07703d3ff4a 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -21,15 +21,28 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/mm.h>
24 25
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
26 27
27#include "sysfs.h" 28#include "sysfs.h"
28 29
30/*
31 * There's one bin_buffer for each open file.
32 *
33 * filp->private_data points to bin_buffer and
34 * sysfs_dirent->s_bin_attr.buffers points to a the bin_buffer s
35 * sysfs_dirent->s_bin_attr.buffers is protected by sysfs_bin_lock
36 */
37static DEFINE_MUTEX(sysfs_bin_lock);
38
29struct bin_buffer { 39struct bin_buffer {
30 struct mutex mutex; 40 struct mutex mutex;
31 void *buffer; 41 void *buffer;
32 int mmapped; 42 int mmapped;
43 struct vm_operations_struct *vm_ops;
44 struct file *file;
45 struct hlist_node list;
33}; 46};
34 47
35static int 48static int
@@ -168,6 +181,175 @@ out_free:
168 return count; 181 return count;
169} 182}
170 183
184static void bin_vma_open(struct vm_area_struct *vma)
185{
186 struct file *file = vma->vm_file;
187 struct bin_buffer *bb = file->private_data;
188 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
189
190 if (!bb->vm_ops || !bb->vm_ops->open)
191 return;
192
193 if (!sysfs_get_active_two(attr_sd))
194 return;
195
196 bb->vm_ops->open(vma);
197
198 sysfs_put_active_two(attr_sd);
199}
200
201static void bin_vma_close(struct vm_area_struct *vma)
202{
203 struct file *file = vma->vm_file;
204 struct bin_buffer *bb = file->private_data;
205 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
206
207 if (!bb->vm_ops || !bb->vm_ops->close)
208 return;
209
210 if (!sysfs_get_active_two(attr_sd))
211 return;
212
213 bb->vm_ops->close(vma);
214
215 sysfs_put_active_two(attr_sd);
216}
217
218static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
219{
220 struct file *file = vma->vm_file;
221 struct bin_buffer *bb = file->private_data;
222 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
223 int ret;
224
225 if (!bb->vm_ops || !bb->vm_ops->fault)
226 return VM_FAULT_SIGBUS;
227
228 if (!sysfs_get_active_two(attr_sd))
229 return VM_FAULT_SIGBUS;
230
231 ret = bb->vm_ops->fault(vma, vmf);
232
233 sysfs_put_active_two(attr_sd);
234 return ret;
235}
236
237static int bin_page_mkwrite(struct vm_area_struct *vma, struct page *page)
238{
239 struct file *file = vma->vm_file;
240 struct bin_buffer *bb = file->private_data;
241 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
242 int ret;
243
244 if (!bb->vm_ops)
245 return -EINVAL;
246
247 if (!bb->vm_ops->page_mkwrite)
248 return 0;
249
250 if (!sysfs_get_active_two(attr_sd))
251 return -EINVAL;
252
253 ret = bb->vm_ops->page_mkwrite(vma, page);
254
255 sysfs_put_active_two(attr_sd);
256 return ret;
257}
258
259static int bin_access(struct vm_area_struct *vma, unsigned long addr,
260 void *buf, int len, int write)
261{
262 struct file *file = vma->vm_file;
263 struct bin_buffer *bb = file->private_data;
264 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
265 int ret;
266
267 if (!bb->vm_ops || !bb->vm_ops->access)
268 return -EINVAL;
269
270 if (!sysfs_get_active_two(attr_sd))
271 return -EINVAL;
272
273 ret = bb->vm_ops->access(vma, addr, buf, len, write);
274
275 sysfs_put_active_two(attr_sd);
276 return ret;
277}
278
279#ifdef CONFIG_NUMA
280static int bin_set_policy(struct vm_area_struct *vma, struct mempolicy *new)
281{
282 struct file *file = vma->vm_file;
283 struct bin_buffer *bb = file->private_data;
284 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
285 int ret;
286
287 if (!bb->vm_ops || !bb->vm_ops->set_policy)
288 return 0;
289
290 if (!sysfs_get_active_two(attr_sd))
291 return -EINVAL;
292
293 ret = bb->vm_ops->set_policy(vma, new);
294
295 sysfs_put_active_two(attr_sd);
296 return ret;
297}
298
299static struct mempolicy *bin_get_policy(struct vm_area_struct *vma,
300 unsigned long addr)
301{
302 struct file *file = vma->vm_file;
303 struct bin_buffer *bb = file->private_data;
304 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
305 struct mempolicy *pol;
306
307 if (!bb->vm_ops || !bb->vm_ops->get_policy)
308 return vma->vm_policy;
309
310 if (!sysfs_get_active_two(attr_sd))
311 return vma->vm_policy;
312
313 pol = bb->vm_ops->get_policy(vma, addr);
314
315 sysfs_put_active_two(attr_sd);
316 return pol;
317}
318
319static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
320 const nodemask_t *to, unsigned long flags)
321{
322 struct file *file = vma->vm_file;
323 struct bin_buffer *bb = file->private_data;
324 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
325 int ret;
326
327 if (!bb->vm_ops || !bb->vm_ops->migrate)
328 return 0;
329
330 if (!sysfs_get_active_two(attr_sd))
331 return 0;
332
333 ret = bb->vm_ops->migrate(vma, from, to, flags);
334
335 sysfs_put_active_two(attr_sd);
336 return ret;
337}
338#endif
339
340static struct vm_operations_struct bin_vm_ops = {
341 .open = bin_vma_open,
342 .close = bin_vma_close,
343 .fault = bin_fault,
344 .page_mkwrite = bin_page_mkwrite,
345 .access = bin_access,
346#ifdef CONFIG_NUMA
347 .set_policy = bin_set_policy,
348 .get_policy = bin_get_policy,
349 .migrate = bin_migrate,
350#endif
351};
352
171static int mmap(struct file *file, struct vm_area_struct *vma) 353static int mmap(struct file *file, struct vm_area_struct *vma)
172{ 354{
173 struct bin_buffer *bb = file->private_data; 355 struct bin_buffer *bb = file->private_data;
@@ -179,18 +361,37 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
179 mutex_lock(&bb->mutex); 361 mutex_lock(&bb->mutex);
180 362
181 /* need attr_sd for attr, its parent for kobj */ 363 /* need attr_sd for attr, its parent for kobj */
364 rc = -ENODEV;
182 if (!sysfs_get_active_two(attr_sd)) 365 if (!sysfs_get_active_two(attr_sd))
183 return -ENODEV; 366 goto out_unlock;
184 367
185 rc = -EINVAL; 368 rc = -EINVAL;
186 if (attr->mmap) 369 if (!attr->mmap)
187 rc = attr->mmap(kobj, attr, vma); 370 goto out_put;
371
372 rc = attr->mmap(kobj, attr, vma);
373 if (rc)
374 goto out_put;
188 375
189 if (rc == 0 && !bb->mmapped) 376 /*
190 bb->mmapped = 1; 377 * PowerPC's pci_mmap of legacy_mem uses shmem_zero_setup()
191 else 378 * to satisfy versions of X which crash if the mmap fails: that
192 sysfs_put_active_two(attr_sd); 379 * substitutes a new vm_file, and we don't then want bin_vm_ops.
380 */
381 if (vma->vm_file != file)
382 goto out_put;
193 383
384 rc = -EINVAL;
385 if (bb->mmapped && bb->vm_ops != vma->vm_ops)
386 goto out_put;
387
388 rc = 0;
389 bb->mmapped = 1;
390 bb->vm_ops = vma->vm_ops;
391 vma->vm_ops = &bin_vm_ops;
392out_put:
393 sysfs_put_active_two(attr_sd);
394out_unlock:
194 mutex_unlock(&bb->mutex); 395 mutex_unlock(&bb->mutex);
195 396
196 return rc; 397 return rc;
@@ -223,8 +424,13 @@ static int open(struct inode * inode, struct file * file)
223 goto err_out; 424 goto err_out;
224 425
225 mutex_init(&bb->mutex); 426 mutex_init(&bb->mutex);
427 bb->file = file;
226 file->private_data = bb; 428 file->private_data = bb;
227 429
430 mutex_lock(&sysfs_bin_lock);
431 hlist_add_head(&bb->list, &attr_sd->s_bin_attr.buffers);
432 mutex_unlock(&sysfs_bin_lock);
433
228 /* open succeeded, put active references */ 434 /* open succeeded, put active references */
229 sysfs_put_active_two(attr_sd); 435 sysfs_put_active_two(attr_sd);
230 return 0; 436 return 0;
@@ -237,11 +443,12 @@ static int open(struct inode * inode, struct file * file)
237 443
238static int release(struct inode * inode, struct file * file) 444static int release(struct inode * inode, struct file * file)
239{ 445{
240 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
241 struct bin_buffer *bb = file->private_data; 446 struct bin_buffer *bb = file->private_data;
242 447
243 if (bb->mmapped) 448 mutex_lock(&sysfs_bin_lock);
244 sysfs_put_active_two(attr_sd); 449 hlist_del(&bb->list);
450 mutex_unlock(&sysfs_bin_lock);
451
245 kfree(bb->buffer); 452 kfree(bb->buffer);
246 kfree(bb); 453 kfree(bb);
247 return 0; 454 return 0;
@@ -256,6 +463,26 @@ const struct file_operations bin_fops = {
256 .release = release, 463 .release = release,
257}; 464};
258 465
466
467void unmap_bin_file(struct sysfs_dirent *attr_sd)
468{
469 struct bin_buffer *bb;
470 struct hlist_node *tmp;
471
472 if (sysfs_type(attr_sd) != SYSFS_KOBJ_BIN_ATTR)
473 return;
474
475 mutex_lock(&sysfs_bin_lock);
476
477 hlist_for_each_entry(bb, tmp, &attr_sd->s_bin_attr.buffers, list) {
478 struct inode *inode = bb->file->f_path.dentry->d_inode;
479
480 unmap_mapping_range(inode->i_mapping, 0, 0, 1);
481 }
482
483 mutex_unlock(&sysfs_bin_lock);
484}
485
259/** 486/**
260 * sysfs_create_bin_file - create binary file for object. 487 * sysfs_create_bin_file - create binary file for object.
261 * @kobj: object. 488 * @kobj: object.
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 82d3b79d0e0..d88d0fac9fa 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -302,7 +302,7 @@ static void sysfs_d_iput(struct dentry * dentry, struct inode * inode)
302 iput(inode); 302 iput(inode);
303} 303}
304 304
305static struct dentry_operations sysfs_dentry_ops = { 305static const struct dentry_operations sysfs_dentry_ops = {
306 .d_iput = sysfs_d_iput, 306 .d_iput = sysfs_d_iput,
307}; 307};
308 308
@@ -434,6 +434,26 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
434} 434}
435 435
436/** 436/**
437 * sysfs_pathname - return full path to sysfs dirent
438 * @sd: sysfs_dirent whose path we want
439 * @path: caller allocated buffer
440 *
441 * Gives the name "/" to the sysfs_root entry; any path returned
442 * is relative to wherever sysfs is mounted.
443 *
444 * XXX: does no error checking on @path size
445 */
446static char *sysfs_pathname(struct sysfs_dirent *sd, char *path)
447{
448 if (sd->s_parent) {
449 sysfs_pathname(sd->s_parent, path);
450 strcat(path, "/");
451 }
452 strcat(path, sd->s_name);
453 return path;
454}
455
456/**
437 * sysfs_add_one - add sysfs_dirent to parent 457 * sysfs_add_one - add sysfs_dirent to parent
438 * @acxt: addrm context to use 458 * @acxt: addrm context to use
439 * @sd: sysfs_dirent to be added 459 * @sd: sysfs_dirent to be added
@@ -458,8 +478,16 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
458 int ret; 478 int ret;
459 479
460 ret = __sysfs_add_one(acxt, sd); 480 ret = __sysfs_add_one(acxt, sd);
461 WARN(ret == -EEXIST, KERN_WARNING "sysfs: duplicate filename '%s' " 481 if (ret == -EEXIST) {
462 "can not be created\n", sd->s_name); 482 char *path = kzalloc(PATH_MAX, GFP_KERNEL);
483 WARN(1, KERN_WARNING
484 "sysfs: cannot create duplicate filename '%s'\n",
485 (path == NULL) ? sd->s_name :
486 strcat(strcat(sysfs_pathname(acxt->parent_sd, path), "/"),
487 sd->s_name));
488 kfree(path);
489 }
490
463 return ret; 491 return ret;
464} 492}
465 493
@@ -581,6 +609,7 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
581 609
582 sysfs_drop_dentry(sd); 610 sysfs_drop_dentry(sd);
583 sysfs_deactivate(sd); 611 sysfs_deactivate(sd);
612 unmap_bin_file(sd);
584 sysfs_put(sd); 613 sysfs_put(sd);
585 } 614 }
586} 615}
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 1f4a3f87726..289c43a4726 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -659,13 +659,16 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
659EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group); 659EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
660 660
661struct sysfs_schedule_callback_struct { 661struct sysfs_schedule_callback_struct {
662 struct kobject *kobj; 662 struct list_head workq_list;
663 struct kobject *kobj;
663 void (*func)(void *); 664 void (*func)(void *);
664 void *data; 665 void *data;
665 struct module *owner; 666 struct module *owner;
666 struct work_struct work; 667 struct work_struct work;
667}; 668};
668 669
670static DEFINE_MUTEX(sysfs_workq_mutex);
671static LIST_HEAD(sysfs_workq);
669static void sysfs_schedule_callback_work(struct work_struct *work) 672static void sysfs_schedule_callback_work(struct work_struct *work)
670{ 673{
671 struct sysfs_schedule_callback_struct *ss = container_of(work, 674 struct sysfs_schedule_callback_struct *ss = container_of(work,
@@ -674,6 +677,9 @@ static void sysfs_schedule_callback_work(struct work_struct *work)
674 (ss->func)(ss->data); 677 (ss->func)(ss->data);
675 kobject_put(ss->kobj); 678 kobject_put(ss->kobj);
676 module_put(ss->owner); 679 module_put(ss->owner);
680 mutex_lock(&sysfs_workq_mutex);
681 list_del(&ss->workq_list);
682 mutex_unlock(&sysfs_workq_mutex);
677 kfree(ss); 683 kfree(ss);
678} 684}
679 685
@@ -695,15 +701,25 @@ static void sysfs_schedule_callback_work(struct work_struct *work)
695 * until @func returns. 701 * until @func returns.
696 * 702 *
697 * Returns 0 if the request was submitted, -ENOMEM if storage could not 703 * Returns 0 if the request was submitted, -ENOMEM if storage could not
698 * be allocated, -ENODEV if a reference to @owner isn't available. 704 * be allocated, -ENODEV if a reference to @owner isn't available,
705 * -EAGAIN if a callback has already been scheduled for @kobj.
699 */ 706 */
700int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), 707int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
701 void *data, struct module *owner) 708 void *data, struct module *owner)
702{ 709{
703 struct sysfs_schedule_callback_struct *ss; 710 struct sysfs_schedule_callback_struct *ss, *tmp;
704 711
705 if (!try_module_get(owner)) 712 if (!try_module_get(owner))
706 return -ENODEV; 713 return -ENODEV;
714
715 mutex_lock(&sysfs_workq_mutex);
716 list_for_each_entry_safe(ss, tmp, &sysfs_workq, workq_list)
717 if (ss->kobj == kobj) {
718 mutex_unlock(&sysfs_workq_mutex);
719 return -EAGAIN;
720 }
721 mutex_unlock(&sysfs_workq_mutex);
722
707 ss = kmalloc(sizeof(*ss), GFP_KERNEL); 723 ss = kmalloc(sizeof(*ss), GFP_KERNEL);
708 if (!ss) { 724 if (!ss) {
709 module_put(owner); 725 module_put(owner);
@@ -715,6 +731,10 @@ int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
715 ss->data = data; 731 ss->data = data;
716 ss->owner = owner; 732 ss->owner = owner;
717 INIT_WORK(&ss->work, sysfs_schedule_callback_work); 733 INIT_WORK(&ss->work, sysfs_schedule_callback_work);
734 INIT_LIST_HEAD(&ss->workq_list);
735 mutex_lock(&sysfs_workq_mutex);
736 list_add_tail(&ss->workq_list, &sysfs_workq);
737 mutex_unlock(&sysfs_workq_mutex);
718 schedule_work(&ss->work); 738 schedule_work(&ss->work);
719 return 0; 739 return 0;
720} 740}
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index dfa3d94cfc7..555f0ff988d 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -147,6 +147,7 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
147{ 147{
148 struct bin_attribute *bin_attr; 148 struct bin_attribute *bin_attr;
149 149
150 inode->i_private = sysfs_get(sd);
150 inode->i_mapping->a_ops = &sysfs_aops; 151 inode->i_mapping->a_ops = &sysfs_aops;
151 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 152 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
152 inode->i_op = &sysfs_inode_operations; 153 inode->i_op = &sysfs_inode_operations;
@@ -214,6 +215,22 @@ struct inode * sysfs_get_inode(struct sysfs_dirent *sd)
214 return inode; 215 return inode;
215} 216}
216 217
218/*
219 * The sysfs_dirent serves as both an inode and a directory entry for sysfs.
220 * To prevent the sysfs inode numbers from being freed prematurely we take a
221 * reference to sysfs_dirent from the sysfs inode. A
222 * super_operations.delete_inode() implementation is needed to drop that
223 * reference upon inode destruction.
224 */
225void sysfs_delete_inode(struct inode *inode)
226{
227 struct sysfs_dirent *sd = inode->i_private;
228
229 truncate_inode_pages(&inode->i_data, 0);
230 clear_inode(inode);
231 sysfs_put(sd);
232}
233
217int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name) 234int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name)
218{ 235{
219 struct sysfs_addrm_cxt acxt; 236 struct sysfs_addrm_cxt acxt;
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index ab343e371d6..49749955cca 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -17,11 +17,10 @@
17#include <linux/pagemap.h> 17#include <linux/pagemap.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/magic.h>
20 21
21#include "sysfs.h" 22#include "sysfs.h"
22 23
23/* Random magic number */
24#define SYSFS_MAGIC 0x62656572
25 24
26static struct vfsmount *sysfs_mount; 25static struct vfsmount *sysfs_mount;
27struct super_block * sysfs_sb = NULL; 26struct super_block * sysfs_sb = NULL;
@@ -30,6 +29,7 @@ struct kmem_cache *sysfs_dir_cachep;
30static const struct super_operations sysfs_ops = { 29static const struct super_operations sysfs_ops = {
31 .statfs = simple_statfs, 30 .statfs = simple_statfs,
32 .drop_inode = generic_delete_inode, 31 .drop_inode = generic_delete_inode,
32 .delete_inode = sysfs_delete_inode,
33}; 33};
34 34
35struct sysfs_dirent sysfs_root = { 35struct sysfs_dirent sysfs_root = {
@@ -53,7 +53,9 @@ static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
53 sysfs_sb = sb; 53 sysfs_sb = sb;
54 54
55 /* get root inode, initialize and unlock it */ 55 /* get root inode, initialize and unlock it */
56 mutex_lock(&sysfs_mutex);
56 inode = sysfs_get_inode(&sysfs_root); 57 inode = sysfs_get_inode(&sysfs_root);
58 mutex_unlock(&sysfs_mutex);
57 if (!inode) { 59 if (!inode) {
58 pr_debug("sysfs: could not get root inode\n"); 60 pr_debug("sysfs: could not get root inode\n");
59 return -ENOMEM; 61 return -ENOMEM;
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 93c6d6b27c4..3fa0d98481e 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -28,6 +28,7 @@ struct sysfs_elem_attr {
28 28
29struct sysfs_elem_bin_attr { 29struct sysfs_elem_bin_attr {
30 struct bin_attribute *bin_attr; 30 struct bin_attribute *bin_attr;
31 struct hlist_head buffers;
31}; 32};
32 33
33/* 34/*
@@ -145,6 +146,7 @@ static inline void __sysfs_put(struct sysfs_dirent *sd)
145 * inode.c 146 * inode.c
146 */ 147 */
147struct inode *sysfs_get_inode(struct sysfs_dirent *sd); 148struct inode *sysfs_get_inode(struct sysfs_dirent *sd);
149void sysfs_delete_inode(struct inode *inode);
148int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); 150int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
149int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name); 151int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
150int sysfs_inode_init(void); 152int sysfs_inode_init(void);
@@ -163,6 +165,7 @@ int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
163 * bin.c 165 * bin.c
164 */ 166 */
165extern const struct file_operations bin_fops; 167extern const struct file_operations bin_fops;
168void unmap_bin_file(struct sysfs_dirent *attr_sd);
166 169
167/* 170/*
168 * symlink.c 171 * symlink.c
diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c
index a1f1ef33e81..33e047b59b8 100644
--- a/fs/sysv/namei.c
+++ b/fs/sysv/namei.c
@@ -38,7 +38,7 @@ static int sysv_hash(struct dentry *dentry, struct qstr *qstr)
38 return 0; 38 return 0;
39} 39}
40 40
41struct dentry_operations sysv_dentry_operations = { 41const struct dentry_operations sysv_dentry_operations = {
42 .d_hash = sysv_hash, 42 .d_hash = sysv_hash,
43}; 43};
44 44
diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
index 38ebe3f85b3..5784a318c88 100644
--- a/fs/sysv/sysv.h
+++ b/fs/sysv/sysv.h
@@ -170,7 +170,7 @@ extern const struct file_operations sysv_file_operations;
170extern const struct file_operations sysv_dir_operations; 170extern const struct file_operations sysv_dir_operations;
171extern const struct address_space_operations sysv_aops; 171extern const struct address_space_operations sysv_aops;
172extern const struct super_operations sysv_sops; 172extern const struct super_operations sysv_sops;
173extern struct dentry_operations sysv_dentry_operations; 173extern const struct dentry_operations sysv_dentry_operations;
174 174
175 175
176enum { 176enum {
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 1182b66a549..c5c98355459 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -2034,7 +2034,8 @@ static int ubifs_get_sb(struct file_system_type *fs_type, int flags,
2034 /* 'fill_super()' opens ubi again so we must close it here */ 2034 /* 'fill_super()' opens ubi again so we must close it here */
2035 ubi_close_volume(ubi); 2035 ubi_close_volume(ubi);
2036 2036
2037 return simple_set_mnt(mnt, sb); 2037 simple_set_mnt(mnt, sb);
2038 return 0;
2038 2039
2039out_deact: 2040out_deact:
2040 up_write(&sb->s_umount); 2041 up_write(&sb->s_umount);
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index 1b809bd494b..2bb788a2acb 100644
--- a/fs/udf/balloc.c
+++ b/fs/udf/balloc.c
@@ -206,7 +206,7 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
206 ((char *)bh->b_data)[(bit + i) >> 3]); 206 ((char *)bh->b_data)[(bit + i) >> 3]);
207 } else { 207 } else {
208 if (inode) 208 if (inode)
209 DQUOT_FREE_BLOCK(inode, 1); 209 vfs_dq_free_block(inode, 1);
210 udf_add_free_space(sbi, sbi->s_partition, 1); 210 udf_add_free_space(sbi, sbi->s_partition, 1);
211 } 211 }
212 } 212 }
@@ -261,11 +261,11 @@ static int udf_bitmap_prealloc_blocks(struct super_block *sb,
261 while (bit < (sb->s_blocksize << 3) && block_count > 0) { 261 while (bit < (sb->s_blocksize << 3) && block_count > 0) {
262 if (!udf_test_bit(bit, bh->b_data)) 262 if (!udf_test_bit(bit, bh->b_data))
263 goto out; 263 goto out;
264 else if (DQUOT_PREALLOC_BLOCK(inode, 1)) 264 else if (vfs_dq_prealloc_block(inode, 1))
265 goto out; 265 goto out;
266 else if (!udf_clear_bit(bit, bh->b_data)) { 266 else if (!udf_clear_bit(bit, bh->b_data)) {
267 udf_debug("bit already cleared for block %d\n", bit); 267 udf_debug("bit already cleared for block %d\n", bit);
268 DQUOT_FREE_BLOCK(inode, 1); 268 vfs_dq_free_block(inode, 1);
269 goto out; 269 goto out;
270 } 270 }
271 block_count--; 271 block_count--;
@@ -393,7 +393,7 @@ got_block:
393 /* 393 /*
394 * Check quota for allocation of this block. 394 * Check quota for allocation of this block.
395 */ 395 */
396 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) { 396 if (inode && vfs_dq_alloc_block(inode, 1)) {
397 mutex_unlock(&sbi->s_alloc_mutex); 397 mutex_unlock(&sbi->s_alloc_mutex);
398 *err = -EDQUOT; 398 *err = -EDQUOT;
399 return 0; 399 return 0;
@@ -452,7 +452,7 @@ static void udf_table_free_blocks(struct super_block *sb,
452 /* We do this up front - There are some error conditions that 452 /* We do this up front - There are some error conditions that
453 could occure, but.. oh well */ 453 could occure, but.. oh well */
454 if (inode) 454 if (inode)
455 DQUOT_FREE_BLOCK(inode, count); 455 vfs_dq_free_block(inode, count);
456 if (udf_add_free_space(sbi, sbi->s_partition, count)) 456 if (udf_add_free_space(sbi, sbi->s_partition, count))
457 mark_buffer_dirty(sbi->s_lvid_bh); 457 mark_buffer_dirty(sbi->s_lvid_bh);
458 458
@@ -700,7 +700,7 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
700 epos.offset -= adsize; 700 epos.offset -= adsize;
701 701
702 alloc_count = (elen >> sb->s_blocksize_bits); 702 alloc_count = (elen >> sb->s_blocksize_bits);
703 if (inode && DQUOT_PREALLOC_BLOCK(inode, 703 if (inode && vfs_dq_prealloc_block(inode,
704 alloc_count > block_count ? block_count : alloc_count)) 704 alloc_count > block_count ? block_count : alloc_count))
705 alloc_count = 0; 705 alloc_count = 0;
706 else if (alloc_count > block_count) { 706 else if (alloc_count > block_count) {
@@ -806,7 +806,7 @@ static int udf_table_new_block(struct super_block *sb,
806 goal_eloc.logicalBlockNum++; 806 goal_eloc.logicalBlockNum++;
807 goal_elen -= sb->s_blocksize; 807 goal_elen -= sb->s_blocksize;
808 808
809 if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) { 809 if (inode && vfs_dq_alloc_block(inode, 1)) {
810 brelse(goal_epos.bh); 810 brelse(goal_epos.bh);
811 mutex_unlock(&sbi->s_alloc_mutex); 811 mutex_unlock(&sbi->s_alloc_mutex);
812 *err = -EDQUOT; 812 *err = -EDQUOT;
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c
index 31fc84297dd..47dbe5613f9 100644
--- a/fs/udf/ialloc.c
+++ b/fs/udf/ialloc.c
@@ -36,8 +36,8 @@ void udf_free_inode(struct inode *inode)
36 * Note: we must free any quota before locking the superblock, 36 * Note: we must free any quota before locking the superblock,
37 * as writing the quota to disk may need the lock as well. 37 * as writing the quota to disk may need the lock as well.
38 */ 38 */
39 DQUOT_FREE_INODE(inode); 39 vfs_dq_free_inode(inode);
40 DQUOT_DROP(inode); 40 vfs_dq_drop(inode);
41 41
42 clear_inode(inode); 42 clear_inode(inode);
43 43
@@ -154,8 +154,8 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
154 insert_inode_hash(inode); 154 insert_inode_hash(inode);
155 mark_inode_dirty(inode); 155 mark_inode_dirty(inode);
156 156
157 if (DQUOT_ALLOC_INODE(inode)) { 157 if (vfs_dq_alloc_inode(inode)) {
158 DQUOT_DROP(inode); 158 vfs_dq_drop(inode);
159 inode->i_flags |= S_NOQUOTA; 159 inode->i_flags |= S_NOQUOTA;
160 inode->i_nlink = 0; 160 inode->i_nlink = 0;
161 iput(inode); 161 iput(inode);
diff --git a/fs/ufs/balloc.c b/fs/ufs/balloc.c
index 0d9ada17373..54c16ec95df 100644
--- a/fs/ufs/balloc.c
+++ b/fs/ufs/balloc.c
@@ -85,7 +85,7 @@ void ufs_free_fragments(struct inode *inode, u64 fragment, unsigned count)
85 "bit already cleared for fragment %u", i); 85 "bit already cleared for fragment %u", i);
86 } 86 }
87 87
88 DQUOT_FREE_BLOCK (inode, count); 88 vfs_dq_free_block(inode, count);
89 89
90 90
91 fs32_add(sb, &ucg->cg_cs.cs_nffree, count); 91 fs32_add(sb, &ucg->cg_cs.cs_nffree, count);
@@ -195,7 +195,7 @@ do_more:
195 ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno); 195 ubh_setblock(UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
196 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD) 196 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
197 ufs_clusteracct (sb, ucpi, blkno, 1); 197 ufs_clusteracct (sb, ucpi, blkno, 1);
198 DQUOT_FREE_BLOCK(inode, uspi->s_fpb); 198 vfs_dq_free_block(inode, uspi->s_fpb);
199 199
200 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1); 200 fs32_add(sb, &ucg->cg_cs.cs_nbfree, 1);
201 uspi->cs_total.cs_nbfree++; 201 uspi->cs_total.cs_nbfree++;
@@ -556,7 +556,7 @@ static u64 ufs_add_fragments(struct inode *inode, u64 fragment,
556 fs32_add(sb, &ucg->cg_frsum[fragsize - count], 1); 556 fs32_add(sb, &ucg->cg_frsum[fragsize - count], 1);
557 for (i = oldcount; i < newcount; i++) 557 for (i = oldcount; i < newcount; i++)
558 ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i); 558 ubh_clrbit (UCPI_UBH(ucpi), ucpi->c_freeoff, fragno + i);
559 if(DQUOT_ALLOC_BLOCK(inode, count)) { 559 if (vfs_dq_alloc_block(inode, count)) {
560 *err = -EDQUOT; 560 *err = -EDQUOT;
561 return 0; 561 return 0;
562 } 562 }
@@ -664,7 +664,7 @@ cg_found:
664 for (i = count; i < uspi->s_fpb; i++) 664 for (i = count; i < uspi->s_fpb; i++)
665 ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i); 665 ubh_setbit (UCPI_UBH(ucpi), ucpi->c_freeoff, goal + i);
666 i = uspi->s_fpb - count; 666 i = uspi->s_fpb - count;
667 DQUOT_FREE_BLOCK(inode, i); 667 vfs_dq_free_block(inode, i);
668 668
669 fs32_add(sb, &ucg->cg_cs.cs_nffree, i); 669 fs32_add(sb, &ucg->cg_cs.cs_nffree, i);
670 uspi->cs_total.cs_nffree += i; 670 uspi->cs_total.cs_nffree += i;
@@ -676,7 +676,7 @@ cg_found:
676 result = ufs_bitmap_search (sb, ucpi, goal, allocsize); 676 result = ufs_bitmap_search (sb, ucpi, goal, allocsize);
677 if (result == INVBLOCK) 677 if (result == INVBLOCK)
678 return 0; 678 return 0;
679 if(DQUOT_ALLOC_BLOCK(inode, count)) { 679 if (vfs_dq_alloc_block(inode, count)) {
680 *err = -EDQUOT; 680 *err = -EDQUOT;
681 return 0; 681 return 0;
682 } 682 }
@@ -747,7 +747,7 @@ gotit:
747 ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno); 747 ubh_clrblock (UCPI_UBH(ucpi), ucpi->c_freeoff, blkno);
748 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD) 748 if ((UFS_SB(sb)->s_flags & UFS_CG_MASK) == UFS_CG_44BSD)
749 ufs_clusteracct (sb, ucpi, blkno, -1); 749 ufs_clusteracct (sb, ucpi, blkno, -1);
750 if(DQUOT_ALLOC_BLOCK(inode, uspi->s_fpb)) { 750 if (vfs_dq_alloc_block(inode, uspi->s_fpb)) {
751 *err = -EDQUOT; 751 *err = -EDQUOT;
752 return INVBLOCK; 752 return INVBLOCK;
753 } 753 }
diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c
index 6f5dcf00609..3527c00fef0 100644
--- a/fs/ufs/ialloc.c
+++ b/fs/ufs/ialloc.c
@@ -95,8 +95,8 @@ void ufs_free_inode (struct inode * inode)
95 95
96 is_directory = S_ISDIR(inode->i_mode); 96 is_directory = S_ISDIR(inode->i_mode);
97 97
98 DQUOT_FREE_INODE(inode); 98 vfs_dq_free_inode(inode);
99 DQUOT_DROP(inode); 99 vfs_dq_drop(inode);
100 100
101 clear_inode (inode); 101 clear_inode (inode);
102 102
@@ -355,8 +355,8 @@ cg_found:
355 355
356 unlock_super (sb); 356 unlock_super (sb);
357 357
358 if (DQUOT_ALLOC_INODE(inode)) { 358 if (vfs_dq_alloc_inode(inode)) {
359 DQUOT_DROP(inode); 359 vfs_dq_drop(inode);
360 err = -EDQUOT; 360 err = -EDQUOT;
361 goto fail_without_unlock; 361 goto fail_without_unlock;
362 } 362 }
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c
index 39f87789856..3d2512c21f0 100644
--- a/fs/ufs/inode.c
+++ b/fs/ufs/inode.c
@@ -622,7 +622,6 @@ static int ufs1_read_inode(struct inode *inode, struct ufs_inode *ufs_inode)
622 struct ufs_inode_info *ufsi = UFS_I(inode); 622 struct ufs_inode_info *ufsi = UFS_I(inode);
623 struct super_block *sb = inode->i_sb; 623 struct super_block *sb = inode->i_sb;
624 mode_t mode; 624 mode_t mode;
625 unsigned i;
626 625
627 /* 626 /*
628 * Copy data to the in-core inode. 627 * Copy data to the in-core inode.
@@ -655,11 +654,12 @@ static int ufs1_read_inode(struct inode *inode, struct ufs_inode *ufs_inode)
655 654
656 655
657 if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) { 656 if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
658 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++) 657 memcpy(ufsi->i_u1.i_data, &ufs_inode->ui_u2.ui_addr,
659 ufsi->i_u1.i_data[i] = ufs_inode->ui_u2.ui_addr.ui_db[i]; 658 sizeof(ufs_inode->ui_u2.ui_addr));
660 } else { 659 } else {
661 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++) 660 memcpy(ufsi->i_u1.i_symlink, ufs_inode->ui_u2.ui_symlink,
662 ufsi->i_u1.i_symlink[i] = ufs_inode->ui_u2.ui_symlink[i]; 661 sizeof(ufs_inode->ui_u2.ui_symlink) - 1);
662 ufsi->i_u1.i_symlink[sizeof(ufs_inode->ui_u2.ui_symlink) - 1] = 0;
663 } 663 }
664 return 0; 664 return 0;
665} 665}
@@ -669,7 +669,6 @@ static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode)
669 struct ufs_inode_info *ufsi = UFS_I(inode); 669 struct ufs_inode_info *ufsi = UFS_I(inode);
670 struct super_block *sb = inode->i_sb; 670 struct super_block *sb = inode->i_sb;
671 mode_t mode; 671 mode_t mode;
672 unsigned i;
673 672
674 UFSD("Reading ufs2 inode, ino %lu\n", inode->i_ino); 673 UFSD("Reading ufs2 inode, ino %lu\n", inode->i_ino);
675 /* 674 /*
@@ -704,12 +703,12 @@ static int ufs2_read_inode(struct inode *inode, struct ufs2_inode *ufs2_inode)
704 */ 703 */
705 704
706 if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) { 705 if (S_ISCHR(mode) || S_ISBLK(mode) || inode->i_blocks) {
707 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++) 706 memcpy(ufsi->i_u1.u2_i_data, &ufs2_inode->ui_u2.ui_addr,
708 ufsi->i_u1.u2_i_data[i] = 707 sizeof(ufs2_inode->ui_u2.ui_addr));
709 ufs2_inode->ui_u2.ui_addr.ui_db[i];
710 } else { 708 } else {
711 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++) 709 memcpy(ufsi->i_u1.i_symlink, ufs2_inode->ui_u2.ui_symlink,
712 ufsi->i_u1.i_symlink[i] = ufs2_inode->ui_u2.ui_symlink[i]; 710 sizeof(ufs2_inode->ui_u2.ui_symlink) - 1);
711 ufsi->i_u1.i_symlink[sizeof(ufs2_inode->ui_u2.ui_symlink) - 1] = 0;
713 } 712 }
714 return 0; 713 return 0;
715} 714}
@@ -781,7 +780,6 @@ static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode)
781{ 780{
782 struct super_block *sb = inode->i_sb; 781 struct super_block *sb = inode->i_sb;
783 struct ufs_inode_info *ufsi = UFS_I(inode); 782 struct ufs_inode_info *ufsi = UFS_I(inode);
784 unsigned i;
785 783
786 ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode); 784 ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode);
787 ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink); 785 ufs_inode->ui_nlink = cpu_to_fs16(sb, inode->i_nlink);
@@ -809,12 +807,12 @@ static void ufs1_update_inode(struct inode *inode, struct ufs_inode *ufs_inode)
809 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */ 807 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
810 ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.i_data[0]; 808 ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.i_data[0];
811 } else if (inode->i_blocks) { 809 } else if (inode->i_blocks) {
812 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++) 810 memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.i_data,
813 ufs_inode->ui_u2.ui_addr.ui_db[i] = ufsi->i_u1.i_data[i]; 811 sizeof(ufs_inode->ui_u2.ui_addr));
814 } 812 }
815 else { 813 else {
816 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++) 814 memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
817 ufs_inode->ui_u2.ui_symlink[i] = ufsi->i_u1.i_symlink[i]; 815 sizeof(ufs_inode->ui_u2.ui_symlink));
818 } 816 }
819 817
820 if (!inode->i_nlink) 818 if (!inode->i_nlink)
@@ -825,7 +823,6 @@ static void ufs2_update_inode(struct inode *inode, struct ufs2_inode *ufs_inode)
825{ 823{
826 struct super_block *sb = inode->i_sb; 824 struct super_block *sb = inode->i_sb;
827 struct ufs_inode_info *ufsi = UFS_I(inode); 825 struct ufs_inode_info *ufsi = UFS_I(inode);
828 unsigned i;
829 826
830 UFSD("ENTER\n"); 827 UFSD("ENTER\n");
831 ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode); 828 ufs_inode->ui_mode = cpu_to_fs16(sb, inode->i_mode);
@@ -850,11 +847,11 @@ static void ufs2_update_inode(struct inode *inode, struct ufs2_inode *ufs_inode)
850 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */ 847 /* ufs_inode->ui_u2.ui_addr.ui_db[0] = cpu_to_fs32(sb, inode->i_rdev); */
851 ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.u2_i_data[0]; 848 ufs_inode->ui_u2.ui_addr.ui_db[0] = ufsi->i_u1.u2_i_data[0];
852 } else if (inode->i_blocks) { 849 } else if (inode->i_blocks) {
853 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR); i++) 850 memcpy(&ufs_inode->ui_u2.ui_addr, ufsi->i_u1.u2_i_data,
854 ufs_inode->ui_u2.ui_addr.ui_db[i] = ufsi->i_u1.u2_i_data[i]; 851 sizeof(ufs_inode->ui_u2.ui_addr));
855 } else { 852 } else {
856 for (i = 0; i < (UFS_NDADDR + UFS_NINDIR) * 4; i++) 853 memcpy(&ufs_inode->ui_u2.ui_symlink, ufsi->i_u1.i_symlink,
857 ufs_inode->ui_u2.ui_symlink[i] = ufsi->i_u1.i_symlink[i]; 854 sizeof(ufs_inode->ui_u2.ui_symlink));
858 } 855 }
859 856
860 if (!inode->i_nlink) 857 if (!inode->i_nlink)
diff --git a/fs/ufs/namei.c b/fs/ufs/namei.c
index e3a9b1fac75..23119fe7ad6 100644
--- a/fs/ufs/namei.c
+++ b/fs/ufs/namei.c
@@ -147,7 +147,7 @@ static int ufs_symlink (struct inode * dir, struct dentry * dentry,
147 } else { 147 } else {
148 /* fast symlink */ 148 /* fast symlink */
149 inode->i_op = &ufs_fast_symlink_inode_operations; 149 inode->i_op = &ufs_fast_symlink_inode_operations;
150 memcpy((char*)&UFS_I(inode)->i_u1.i_data,symname,l); 150 memcpy(UFS_I(inode)->i_u1.i_symlink, symname, l);
151 inode->i_size = l-1; 151 inode->i_size = l-1;
152 } 152 }
153 mark_inode_dirty(inode); 153 mark_inode_dirty(inode);
diff --git a/fs/ufs/super.c b/fs/ufs/super.c
index 261a1c2f22d..e1c1fc5ee23 100644
--- a/fs/ufs/super.c
+++ b/fs/ufs/super.c
@@ -636,6 +636,7 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)
636 unsigned block_size, super_block_size; 636 unsigned block_size, super_block_size;
637 unsigned flags; 637 unsigned flags;
638 unsigned super_block_offset; 638 unsigned super_block_offset;
639 unsigned maxsymlen;
639 int ret = -EINVAL; 640 int ret = -EINVAL;
640 641
641 uspi = NULL; 642 uspi = NULL;
@@ -1069,6 +1070,16 @@ magic_found:
1069 uspi->s_maxsymlinklen = 1070 uspi->s_maxsymlinklen =
1070 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen); 1071 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
1071 1072
1073 if (uspi->fs_magic == UFS2_MAGIC)
1074 maxsymlen = 2 * 4 * (UFS_NDADDR + UFS_NINDIR);
1075 else
1076 maxsymlen = 4 * (UFS_NDADDR + UFS_NINDIR);
1077 if (uspi->s_maxsymlinklen > maxsymlen) {
1078 ufs_warning(sb, __func__, "ufs_read_super: excessive maximum "
1079 "fast symlink size (%u)\n", uspi->s_maxsymlinklen);
1080 uspi->s_maxsymlinklen = maxsymlen;
1081 }
1082
1072 inode = ufs_iget(sb, UFS_ROOTINO); 1083 inode = ufs_iget(sb, UFS_ROOTINO);
1073 if (IS_ERR(inode)) { 1084 if (IS_ERR(inode)) {
1074 ret = PTR_ERR(inode); 1085 ret = PTR_ERR(inode);
diff --git a/fs/ufs/ufs.h b/fs/ufs/ufs.h
index 11c035168ea..69b3427d788 100644
--- a/fs/ufs/ufs.h
+++ b/fs/ufs/ufs.h
@@ -23,7 +23,7 @@ struct ufs_sb_info {
23struct ufs_inode_info { 23struct ufs_inode_info {
24 union { 24 union {
25 __fs32 i_data[15]; 25 __fs32 i_data[15];
26 __u8 i_symlink[4*15]; 26 __u8 i_symlink[2 * 4 * 15];
27 __fs64 u2_i_data[15]; 27 __fs64 u2_i_data[15];
28 } i_u1; 28 } i_u1;
29 __u32 i_flags; 29 __u32 i_flags;