aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/Kconfig4
-rw-r--r--fs/binfmt_elf.c4
-rw-r--r--fs/block_dev.c8
-rw-r--r--fs/char_dev.c6
-rw-r--r--fs/coda/psdev.c8
-rw-r--r--fs/compat.c4
-rw-r--r--fs/compat_ioctl.c8
-rw-r--r--fs/configfs/mount.c13
-rw-r--r--fs/debugfs/inode.c13
-rw-r--r--fs/dlm/lockspace.c50
-rw-r--r--fs/ecryptfs/inode.c20
-rw-r--r--fs/ecryptfs/main.c129
-rw-r--r--fs/ecryptfs/super.c1
-rw-r--r--fs/fat/fatent.c28
-rw-r--r--fs/fs-writeback.c2
-rw-r--r--fs/fuse/inode.c26
-rw-r--r--fs/gfs2/Makefile2
-rw-r--r--fs/gfs2/bmap.c37
-rw-r--r--fs/gfs2/bmap.h2
-rw-r--r--fs/gfs2/daemon.c50
-rw-r--r--fs/gfs2/daemon.h1
-rw-r--r--fs/gfs2/dir.c4
-rw-r--r--fs/gfs2/eaops.c84
-rw-r--r--fs/gfs2/eattr.c2
-rw-r--r--fs/gfs2/glock.c83
-rw-r--r--fs/gfs2/glops.c110
-rw-r--r--fs/gfs2/incore.h47
-rw-r--r--fs/gfs2/inode.c41
-rw-r--r--fs/gfs2/inode.h12
-rw-r--r--fs/gfs2/locking/dlm/mount.c5
-rw-r--r--fs/gfs2/locking/dlm/plock.c18
-rw-r--r--fs/gfs2/locking/dlm/sysfs.c38
-rw-r--r--fs/gfs2/locking/dlm/thread.c9
-rw-r--r--fs/gfs2/log.c119
-rw-r--r--fs/gfs2/log.h14
-rw-r--r--fs/gfs2/lops.c71
-rw-r--r--fs/gfs2/main.c3
-rw-r--r--fs/gfs2/meta_io.c97
-rw-r--r--fs/gfs2/meta_io.h1
-rw-r--r--fs/gfs2/ops_address.c649
-rw-r--r--fs/gfs2/ops_address.h7
-rw-r--r--fs/gfs2/ops_file.c229
-rw-r--r--fs/gfs2/ops_file.h24
-rw-r--r--fs/gfs2/ops_fstype.c73
-rw-r--r--fs/gfs2/ops_inode.c20
-rw-r--r--fs/gfs2/ops_inode.h6
-rw-r--r--fs/gfs2/ops_super.c1
-rw-r--r--fs/gfs2/ops_vm.c169
-rw-r--r--fs/gfs2/ops_vm.h18
-rw-r--r--fs/gfs2/quota.c29
-rw-r--r--fs/gfs2/recovery.c18
-rw-r--r--fs/gfs2/rgrp.c104
-rw-r--r--fs/gfs2/rgrp.h4
-rw-r--r--fs/gfs2/super.c25
-rw-r--r--fs/gfs2/sys.c36
-rw-r--r--fs/gfs2/trans.c5
-rw-r--r--fs/gfs2/trans.h1
-rw-r--r--fs/hfs/bfind.c12
-rw-r--r--fs/hfs/brec.c15
-rw-r--r--fs/hfs/btree.c20
-rw-r--r--fs/hfs/hfs.h5
-rw-r--r--fs/jbd/transaction.c2
-rw-r--r--fs/namei.c4
-rw-r--r--fs/namespace.c11
-rw-r--r--fs/nfs/nfs4_fs.h1
-rw-r--r--fs/nfs/nfs4proc.c34
-rw-r--r--fs/nfs/nfs4renewd.c2
-rw-r--r--fs/nfs/nfs4state.c5
-rw-r--r--fs/nfs/super.c12
-rw-r--r--fs/nfsd/nfs3xdr.c5
-rw-r--r--fs/nfsd/nfsxdr.c5
-rw-r--r--fs/ocfs2/cluster/masklog.c4
-rw-r--r--fs/ocfs2/cluster/sys.c83
-rw-r--r--fs/openpromfs/inode.c2
-rw-r--r--fs/partitions/check.c327
-rw-r--r--fs/proc/array.c4
-rw-r--r--fs/read_write.c63
-rw-r--r--fs/splice.c8
-rw-r--r--fs/sysfs/dir.c10
-rw-r--r--fs/sysfs/file.c67
-rw-r--r--fs/sysfs/symlink.c88
-rw-r--r--fs/xfs/linux-2.6/xfs_file.c16
82 files changed, 1560 insertions, 1837 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
index 487236c65837..781b47d2f9f2 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1112,8 +1112,8 @@ config HFS_FS
1112 help 1112 help
1113 If you say Y here, you will be able to mount Macintosh-formatted 1113 If you say Y here, you will be able to mount Macintosh-formatted
1114 floppy disks and hard drive partitions with full read-write access. 1114 floppy disks and hard drive partitions with full read-write access.
1115 Please read <file:fs/hfs/HFS.txt> to learn about the available mount 1115 Please read <file:Documentation/filesystems/hfs.txt> to learn about
1116 options. 1116 the available mount options.
1117 1117
1118 To compile this file system support as a module, choose M here: the 1118 To compile this file system support as a module, choose M here: the
1119 module will be called hfs. 1119 module will be called hfs.
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index ba8de7ca260b..f0b3171842f2 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -1384,7 +1384,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
1384 prstatus->pr_sigpend = p->pending.signal.sig[0]; 1384 prstatus->pr_sigpend = p->pending.signal.sig[0];
1385 prstatus->pr_sighold = p->blocked.sig[0]; 1385 prstatus->pr_sighold = p->blocked.sig[0];
1386 prstatus->pr_pid = task_pid_vnr(p); 1386 prstatus->pr_pid = task_pid_vnr(p);
1387 prstatus->pr_ppid = task_pid_vnr(p->parent); 1387 prstatus->pr_ppid = task_pid_vnr(p->real_parent);
1388 prstatus->pr_pgrp = task_pgrp_vnr(p); 1388 prstatus->pr_pgrp = task_pgrp_vnr(p);
1389 prstatus->pr_sid = task_session_vnr(p); 1389 prstatus->pr_sid = task_session_vnr(p);
1390 if (thread_group_leader(p)) { 1390 if (thread_group_leader(p)) {
@@ -1430,7 +1430,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
1430 psinfo->pr_psargs[len] = 0; 1430 psinfo->pr_psargs[len] = 0;
1431 1431
1432 psinfo->pr_pid = task_pid_vnr(p); 1432 psinfo->pr_pid = task_pid_vnr(p);
1433 psinfo->pr_ppid = task_pid_vnr(p->parent); 1433 psinfo->pr_ppid = task_pid_vnr(p->real_parent);
1434 psinfo->pr_pgrp = task_pgrp_vnr(p); 1434 psinfo->pr_pgrp = task_pgrp_vnr(p);
1435 psinfo->pr_sid = task_session_vnr(p); 1435 psinfo->pr_sid = task_session_vnr(p);
1436 1436
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 993f78c55221..e48a630ae266 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -738,9 +738,9 @@ EXPORT_SYMBOL(bd_release);
738static struct kobject *bdev_get_kobj(struct block_device *bdev) 738static struct kobject *bdev_get_kobj(struct block_device *bdev)
739{ 739{
740 if (bdev->bd_contains != bdev) 740 if (bdev->bd_contains != bdev)
741 return kobject_get(&bdev->bd_part->kobj); 741 return kobject_get(&bdev->bd_part->dev.kobj);
742 else 742 else
743 return kobject_get(&bdev->bd_disk->kobj); 743 return kobject_get(&bdev->bd_disk->dev.kobj);
744} 744}
745 745
746static struct kobject *bdev_get_holder(struct block_device *bdev) 746static struct kobject *bdev_get_holder(struct block_device *bdev)
@@ -1176,7 +1176,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
1176 ret = -ENXIO; 1176 ret = -ENXIO;
1177 goto out_first; 1177 goto out_first;
1178 } 1178 }
1179 kobject_get(&p->kobj); 1179 kobject_get(&p->dev.kobj);
1180 bdev->bd_part = p; 1180 bdev->bd_part = p;
1181 bd_set_size(bdev, (loff_t) p->nr_sects << 9); 1181 bd_set_size(bdev, (loff_t) p->nr_sects << 9);
1182 } 1182 }
@@ -1299,7 +1299,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
1299 module_put(owner); 1299 module_put(owner);
1300 1300
1301 if (bdev->bd_contains != bdev) { 1301 if (bdev->bd_contains != bdev) {
1302 kobject_put(&bdev->bd_part->kobj); 1302 kobject_put(&bdev->bd_part->dev.kobj);
1303 bdev->bd_part = NULL; 1303 bdev->bd_part = NULL;
1304 } 1304 }
1305 bdev->bd_disk = NULL; 1305 bdev->bd_disk = NULL;
diff --git a/fs/char_dev.c b/fs/char_dev.c
index c3bfa76765c4..2c7a8b5b4598 100644
--- a/fs/char_dev.c
+++ b/fs/char_dev.c
@@ -510,9 +510,8 @@ struct cdev *cdev_alloc(void)
510{ 510{
511 struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL); 511 struct cdev *p = kzalloc(sizeof(struct cdev), GFP_KERNEL);
512 if (p) { 512 if (p) {
513 p->kobj.ktype = &ktype_cdev_dynamic;
514 INIT_LIST_HEAD(&p->list); 513 INIT_LIST_HEAD(&p->list);
515 kobject_init(&p->kobj); 514 kobject_init(&p->kobj, &ktype_cdev_dynamic);
516 } 515 }
517 return p; 516 return p;
518} 517}
@@ -529,8 +528,7 @@ void cdev_init(struct cdev *cdev, const struct file_operations *fops)
529{ 528{
530 memset(cdev, 0, sizeof *cdev); 529 memset(cdev, 0, sizeof *cdev);
531 INIT_LIST_HEAD(&cdev->list); 530 INIT_LIST_HEAD(&cdev->list);
532 cdev->kobj.ktype = &ktype_cdev_default; 531 kobject_init(&cdev->kobj, &ktype_cdev_default);
533 kobject_init(&cdev->kobj);
534 cdev->ops = fops; 532 cdev->ops = fops;
535} 533}
536 534
diff --git a/fs/coda/psdev.c b/fs/coda/psdev.c
index dcc6aead70f5..e3eb3556622b 100644
--- a/fs/coda/psdev.c
+++ b/fs/coda/psdev.c
@@ -362,8 +362,8 @@ static int init_coda_psdev(void)
362 goto out_chrdev; 362 goto out_chrdev;
363 } 363 }
364 for (i = 0; i < MAX_CODADEVS; i++) 364 for (i = 0; i < MAX_CODADEVS; i++)
365 class_device_create(coda_psdev_class, NULL, 365 device_create(coda_psdev_class, NULL,
366 MKDEV(CODA_PSDEV_MAJOR,i), NULL, "cfs%d", i); 366 MKDEV(CODA_PSDEV_MAJOR,i), "cfs%d", i);
367 coda_sysctl_init(); 367 coda_sysctl_init();
368 goto out; 368 goto out;
369 369
@@ -405,7 +405,7 @@ static int __init init_coda(void)
405 return 0; 405 return 0;
406out: 406out:
407 for (i = 0; i < MAX_CODADEVS; i++) 407 for (i = 0; i < MAX_CODADEVS; i++)
408 class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i)); 408 device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
409 class_destroy(coda_psdev_class); 409 class_destroy(coda_psdev_class);
410 unregister_chrdev(CODA_PSDEV_MAJOR, "coda"); 410 unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
411 coda_sysctl_clean(); 411 coda_sysctl_clean();
@@ -424,7 +424,7 @@ static void __exit exit_coda(void)
424 printk("coda: failed to unregister filesystem\n"); 424 printk("coda: failed to unregister filesystem\n");
425 } 425 }
426 for (i = 0; i < MAX_CODADEVS; i++) 426 for (i = 0; i < MAX_CODADEVS; i++)
427 class_device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i)); 427 device_destroy(coda_psdev_class, MKDEV(CODA_PSDEV_MAJOR, i));
428 class_destroy(coda_psdev_class); 428 class_destroy(coda_psdev_class);
429 unregister_chrdev(CODA_PSDEV_MAJOR, "coda"); 429 unregister_chrdev(CODA_PSDEV_MAJOR, "coda");
430 coda_sysctl_clean(); 430 coda_sysctl_clean();
diff --git a/fs/compat.c b/fs/compat.c
index 15078ce4c04a..5216c3fd7517 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1104,10 +1104,6 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
1104 if (ret < 0) 1104 if (ret < 0)
1105 goto out; 1105 goto out;
1106 1106
1107 ret = security_file_permission(file, type == READ ? MAY_READ:MAY_WRITE);
1108 if (ret)
1109 goto out;
1110
1111 fnv = NULL; 1107 fnv = NULL;
1112 if (type == READ) { 1108 if (type == READ) {
1113 fn = file->f_op->read; 1109 fn = file->f_op->read;
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index e8b7c3a98a54..da8cb3b3592c 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -10,6 +10,8 @@
10 * ioctls. 10 * ioctls.
11 */ 11 */
12 12
13#include <linux/joystick.h>
14
13#include <linux/types.h> 15#include <linux/types.h>
14#include <linux/compat.h> 16#include <linux/compat.h>
15#include <linux/kernel.h> 17#include <linux/kernel.h>
@@ -2642,6 +2644,12 @@ COMPATIBLE_IOCTL(VIDEO_SET_ATTRIBUTES)
2642COMPATIBLE_IOCTL(VIDEO_GET_SIZE) 2644COMPATIBLE_IOCTL(VIDEO_GET_SIZE)
2643COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE) 2645COMPATIBLE_IOCTL(VIDEO_GET_FRAME_RATE)
2644 2646
2647/* joystick */
2648COMPATIBLE_IOCTL(JSIOCGVERSION)
2649COMPATIBLE_IOCTL(JSIOCGAXES)
2650COMPATIBLE_IOCTL(JSIOCGBUTTONS)
2651COMPATIBLE_IOCTL(JSIOCGNAME(0))
2652
2645/* now things that need handlers */ 2653/* now things that need handlers */
2646HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob) 2654HANDLE_IOCTL(MEMREADOOB32, mtd_rw_oob)
2647HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob) 2655HANDLE_IOCTL(MEMWRITEOOB32, mtd_rw_oob)
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 3bf0278ea843..de3b31d0a37d 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -128,7 +128,7 @@ void configfs_release_fs(void)
128} 128}
129 129
130 130
131static decl_subsys(config, NULL, NULL); 131static struct kobject *config_kobj;
132 132
133static int __init configfs_init(void) 133static int __init configfs_init(void)
134{ 134{
@@ -140,9 +140,8 @@ static int __init configfs_init(void)
140 if (!configfs_dir_cachep) 140 if (!configfs_dir_cachep)
141 goto out; 141 goto out;
142 142
143 kobj_set_kset_s(&config_subsys, kernel_subsys); 143 config_kobj = kobject_create_and_add("config", kernel_kobj);
144 err = subsystem_register(&config_subsys); 144 if (!config_kobj) {
145 if (err) {
146 kmem_cache_destroy(configfs_dir_cachep); 145 kmem_cache_destroy(configfs_dir_cachep);
147 configfs_dir_cachep = NULL; 146 configfs_dir_cachep = NULL;
148 goto out; 147 goto out;
@@ -151,7 +150,7 @@ static int __init configfs_init(void)
151 err = register_filesystem(&configfs_fs_type); 150 err = register_filesystem(&configfs_fs_type);
152 if (err) { 151 if (err) {
153 printk(KERN_ERR "configfs: Unable to register filesystem!\n"); 152 printk(KERN_ERR "configfs: Unable to register filesystem!\n");
154 subsystem_unregister(&config_subsys); 153 kobject_put(config_kobj);
155 kmem_cache_destroy(configfs_dir_cachep); 154 kmem_cache_destroy(configfs_dir_cachep);
156 configfs_dir_cachep = NULL; 155 configfs_dir_cachep = NULL;
157 goto out; 156 goto out;
@@ -160,7 +159,7 @@ static int __init configfs_init(void)
160 err = configfs_inode_init(); 159 err = configfs_inode_init();
161 if (err) { 160 if (err) {
162 unregister_filesystem(&configfs_fs_type); 161 unregister_filesystem(&configfs_fs_type);
163 subsystem_unregister(&config_subsys); 162 kobject_put(config_kobj);
164 kmem_cache_destroy(configfs_dir_cachep); 163 kmem_cache_destroy(configfs_dir_cachep);
165 configfs_dir_cachep = NULL; 164 configfs_dir_cachep = NULL;
166 } 165 }
@@ -171,7 +170,7 @@ out:
171static void __exit configfs_exit(void) 170static void __exit configfs_exit(void)
172{ 171{
173 unregister_filesystem(&configfs_fs_type); 172 unregister_filesystem(&configfs_fs_type);
174 subsystem_unregister(&config_subsys); 173 kobject_put(config_kobj);
175 kmem_cache_destroy(configfs_dir_cachep); 174 kmem_cache_destroy(configfs_dir_cachep);
176 configfs_dir_cachep = NULL; 175 configfs_dir_cachep = NULL;
177 configfs_inode_exit(); 176 configfs_inode_exit();
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 6a713b33992f..d26e2826ba5b 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -426,20 +426,19 @@ exit:
426} 426}
427EXPORT_SYMBOL_GPL(debugfs_rename); 427EXPORT_SYMBOL_GPL(debugfs_rename);
428 428
429static decl_subsys(debug, NULL, NULL); 429static struct kobject *debug_kobj;
430 430
431static int __init debugfs_init(void) 431static int __init debugfs_init(void)
432{ 432{
433 int retval; 433 int retval;
434 434
435 kobj_set_kset_s(&debug_subsys, kernel_subsys); 435 debug_kobj = kobject_create_and_add("debug", kernel_kobj);
436 retval = subsystem_register(&debug_subsys); 436 if (!debug_kobj)
437 if (retval) 437 return -EINVAL;
438 return retval;
439 438
440 retval = register_filesystem(&debug_fs_type); 439 retval = register_filesystem(&debug_fs_type);
441 if (retval) 440 if (retval)
442 subsystem_unregister(&debug_subsys); 441 kobject_put(debug_kobj);
443 return retval; 442 return retval;
444} 443}
445 444
@@ -447,7 +446,7 @@ static void __exit debugfs_exit(void)
447{ 446{
448 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 447 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
449 unregister_filesystem(&debug_fs_type); 448 unregister_filesystem(&debug_fs_type);
450 subsystem_unregister(&debug_subsys); 449 kobject_put(debug_kobj);
451} 450}
452 451
453core_initcall(debugfs_init); 452core_initcall(debugfs_init);
diff --git a/fs/dlm/lockspace.c b/fs/dlm/lockspace.c
index 6353a8384520..5c108c49cb8c 100644
--- a/fs/dlm/lockspace.c
+++ b/fs/dlm/lockspace.c
@@ -166,26 +166,7 @@ static struct kobj_type dlm_ktype = {
166 .release = lockspace_kobj_release, 166 .release = lockspace_kobj_release,
167}; 167};
168 168
169static struct kset dlm_kset = { 169static struct kset *dlm_kset;
170 .ktype = &dlm_ktype,
171};
172
173static int kobject_setup(struct dlm_ls *ls)
174{
175 char lsname[DLM_LOCKSPACE_LEN];
176 int error;
177
178 memset(lsname, 0, DLM_LOCKSPACE_LEN);
179 snprintf(lsname, DLM_LOCKSPACE_LEN, "%s", ls->ls_name);
180
181 error = kobject_set_name(&ls->ls_kobj, "%s", lsname);
182 if (error)
183 return error;
184
185 ls->ls_kobj.kset = &dlm_kset;
186 ls->ls_kobj.ktype = &dlm_ktype;
187 return 0;
188}
189 170
190static int do_uevent(struct dlm_ls *ls, int in) 171static int do_uevent(struct dlm_ls *ls, int in)
191{ 172{
@@ -220,24 +201,22 @@ static int do_uevent(struct dlm_ls *ls, int in)
220 201
221int dlm_lockspace_init(void) 202int dlm_lockspace_init(void)
222{ 203{
223 int error;
224
225 ls_count = 0; 204 ls_count = 0;
226 mutex_init(&ls_lock); 205 mutex_init(&ls_lock);
227 INIT_LIST_HEAD(&lslist); 206 INIT_LIST_HEAD(&lslist);
228 spin_lock_init(&lslist_lock); 207 spin_lock_init(&lslist_lock);
229 208
230 kobject_set_name(&dlm_kset.kobj, "dlm"); 209 dlm_kset = kset_create_and_add("dlm", NULL, kernel_kobj);
231 kobj_set_kset_s(&dlm_kset, kernel_subsys); 210 if (!dlm_kset) {
232 error = kset_register(&dlm_kset); 211 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
233 if (error) 212 return -ENOMEM;
234 printk("dlm_lockspace_init: cannot register kset %d\n", error); 213 }
235 return error; 214 return 0;
236} 215}
237 216
238void dlm_lockspace_exit(void) 217void dlm_lockspace_exit(void)
239{ 218{
240 kset_unregister(&dlm_kset); 219 kset_unregister(dlm_kset);
241} 220}
242 221
243static int dlm_scand(void *data) 222static int dlm_scand(void *data)
@@ -549,13 +528,12 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
549 goto out_delist; 528 goto out_delist;
550 } 529 }
551 530
552 error = kobject_setup(ls); 531 ls->ls_kobj.kset = dlm_kset;
553 if (error) 532 error = kobject_init_and_add(&ls->ls_kobj, &dlm_ktype, NULL,
554 goto out_stop; 533 "%s", ls->ls_name);
555
556 error = kobject_register(&ls->ls_kobj);
557 if (error) 534 if (error)
558 goto out_stop; 535 goto out_stop;
536 kobject_uevent(&ls->ls_kobj, KOBJ_ADD);
559 537
560 /* let kobject handle freeing of ls if there's an error */ 538 /* let kobject handle freeing of ls if there's an error */
561 do_unreg = 1; 539 do_unreg = 1;
@@ -601,7 +579,7 @@ static int new_lockspace(char *name, int namelen, void **lockspace,
601 kfree(ls->ls_rsbtbl); 579 kfree(ls->ls_rsbtbl);
602 out_lsfree: 580 out_lsfree:
603 if (do_unreg) 581 if (do_unreg)
604 kobject_unregister(&ls->ls_kobj); 582 kobject_put(&ls->ls_kobj);
605 else 583 else
606 kfree(ls); 584 kfree(ls);
607 out: 585 out:
@@ -750,7 +728,7 @@ static int release_lockspace(struct dlm_ls *ls, int force)
750 dlm_clear_members(ls); 728 dlm_clear_members(ls);
751 dlm_clear_members_gone(ls); 729 dlm_clear_members_gone(ls);
752 kfree(ls->ls_node_array); 730 kfree(ls->ls_node_array);
753 kobject_unregister(&ls->ls_kobj); 731 kobject_put(&ls->ls_kobj);
754 /* The ls structure will be freed when the kobject is done with */ 732 /* The ls structure will be freed when the kobject is done with */
755 733
756 mutex_lock(&ls_lock); 734 mutex_lock(&ls_lock);
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 0b1ab016fa2e..5a719180983c 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -120,22 +120,9 @@ ecryptfs_do_create(struct inode *directory_inode,
120 rc = ecryptfs_create_underlying_file(lower_dir_dentry->d_inode, 120 rc = ecryptfs_create_underlying_file(lower_dir_dentry->d_inode,
121 ecryptfs_dentry, mode, nd); 121 ecryptfs_dentry, mode, nd);
122 if (rc) { 122 if (rc) {
123 struct inode *ecryptfs_inode = ecryptfs_dentry->d_inode; 123 printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
124 struct ecryptfs_inode_info *inode_info = 124 "rc = [%d]\n", __FUNCTION__, rc);
125 ecryptfs_inode_to_private(ecryptfs_inode); 125 goto out_lock;
126
127 printk(KERN_WARNING "%s: Error creating underlying file; "
128 "rc = [%d]; checking for existing\n", __FUNCTION__, rc);
129 if (inode_info) {
130 mutex_lock(&inode_info->lower_file_mutex);
131 if (!inode_info->lower_file) {
132 mutex_unlock(&inode_info->lower_file_mutex);
133 printk(KERN_ERR "%s: Failure to set underlying "
134 "file; rc = [%d]\n", __FUNCTION__, rc);
135 goto out_lock;
136 }
137 mutex_unlock(&inode_info->lower_file_mutex);
138 }
139 } 126 }
140 rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry, 127 rc = ecryptfs_interpose(lower_dentry, ecryptfs_dentry,
141 directory_inode->i_sb, 0); 128 directory_inode->i_sb, 0);
@@ -451,6 +438,7 @@ static int ecryptfs_unlink(struct inode *dir, struct dentry *dentry)
451 dentry->d_inode->i_nlink = 438 dentry->d_inode->i_nlink =
452 ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink; 439 ecryptfs_inode_to_lower(dentry->d_inode)->i_nlink;
453 dentry->d_inode->i_ctime = dir->i_ctime; 440 dentry->d_inode->i_ctime = dir->i_ctime;
441 d_drop(dentry);
454out_unlock: 442out_unlock:
455 unlock_parent(lower_dentry); 443 unlock_parent(lower_dentry);
456 return rc; 444 return rc;
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index e5580bcb923a..0249aa4ae181 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -734,127 +734,40 @@ static int ecryptfs_init_kmem_caches(void)
734 return 0; 734 return 0;
735} 735}
736 736
737struct ecryptfs_obj { 737static struct kobject *ecryptfs_kobj;
738 char *name;
739 struct list_head slot_list;
740 struct kobject kobj;
741};
742
743struct ecryptfs_attribute {
744 struct attribute attr;
745 ssize_t(*show) (struct ecryptfs_obj *, char *);
746 ssize_t(*store) (struct ecryptfs_obj *, const char *, size_t);
747};
748 738
749static ssize_t 739static ssize_t version_show(struct kobject *kobj,
750ecryptfs_attr_store(struct kobject *kobj, 740 struct kobj_attribute *attr, char *buff)
751 struct attribute *attr, const char *buf, size_t len)
752{ 741{
753 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj, 742 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
754 kobj);
755 struct ecryptfs_attribute *attribute =
756 container_of(attr, struct ecryptfs_attribute, attr);
757
758 return (attribute->store ? attribute->store(obj, buf, len) : 0);
759} 743}
760 744
761static ssize_t 745static struct kobj_attribute version_attr = __ATTR_RO(version);
762ecryptfs_attr_show(struct kobject *kobj, struct attribute *attr, char *buf)
763{
764 struct ecryptfs_obj *obj = container_of(kobj, struct ecryptfs_obj,
765 kobj);
766 struct ecryptfs_attribute *attribute =
767 container_of(attr, struct ecryptfs_attribute, attr);
768
769 return (attribute->show ? attribute->show(obj, buf) : 0);
770}
771 746
772static struct sysfs_ops ecryptfs_sysfs_ops = { 747static struct attribute *attributes[] = {
773 .show = ecryptfs_attr_show, 748 &version_attr.attr,
774 .store = ecryptfs_attr_store 749 NULL,
775}; 750};
776 751
777static struct kobj_type ecryptfs_ktype = { 752static struct attribute_group attr_group = {
778 .sysfs_ops = &ecryptfs_sysfs_ops 753 .attrs = attributes,
779}; 754};
780 755
781static decl_subsys(ecryptfs, &ecryptfs_ktype, NULL);
782
783static ssize_t version_show(struct ecryptfs_obj *obj, char *buff)
784{
785 return snprintf(buff, PAGE_SIZE, "%d\n", ECRYPTFS_VERSIONING_MASK);
786}
787
788static struct ecryptfs_attribute sysfs_attr_version = __ATTR_RO(version);
789
790static struct ecryptfs_version_str_map_elem {
791 u32 flag;
792 char *str;
793} ecryptfs_version_str_map[] = {
794 {ECRYPTFS_VERSIONING_PASSPHRASE, "passphrase"},
795 {ECRYPTFS_VERSIONING_PUBKEY, "pubkey"},
796 {ECRYPTFS_VERSIONING_PLAINTEXT_PASSTHROUGH, "plaintext passthrough"},
797 {ECRYPTFS_VERSIONING_POLICY, "policy"},
798 {ECRYPTFS_VERSIONING_XATTR, "metadata in extended attribute"},
799 {ECRYPTFS_VERSIONING_MULTKEY, "multiple keys per file"}
800};
801
802static ssize_t version_str_show(struct ecryptfs_obj *obj, char *buff)
803{
804 int i;
805 int remaining = PAGE_SIZE;
806 int total_written = 0;
807
808 buff[0] = '\0';
809 for (i = 0; i < ARRAY_SIZE(ecryptfs_version_str_map); i++) {
810 int entry_size;
811
812 if (!(ECRYPTFS_VERSIONING_MASK
813 & ecryptfs_version_str_map[i].flag))
814 continue;
815 entry_size = strlen(ecryptfs_version_str_map[i].str);
816 if ((entry_size + 2) > remaining)
817 goto out;
818 memcpy(buff, ecryptfs_version_str_map[i].str, entry_size);
819 buff[entry_size++] = '\n';
820 buff[entry_size] = '\0';
821 buff += entry_size;
822 total_written += entry_size;
823 remaining -= entry_size;
824 }
825out:
826 return total_written;
827}
828
829static struct ecryptfs_attribute sysfs_attr_version_str = __ATTR_RO(version_str);
830
831static int do_sysfs_registration(void) 756static int do_sysfs_registration(void)
832{ 757{
833 int rc; 758 int rc;
834 759
835 rc = subsystem_register(&ecryptfs_subsys); 760 ecryptfs_kobj = kobject_create_and_add("ecryptfs", fs_kobj);
836 if (rc) { 761 if (!ecryptfs_kobj) {
837 printk(KERN_ERR 762 printk(KERN_ERR "Unable to create ecryptfs kset\n");
838 "Unable to register ecryptfs sysfs subsystem\n"); 763 rc = -ENOMEM;
839 goto out;
840 }
841 rc = sysfs_create_file(&ecryptfs_subsys.kobj,
842 &sysfs_attr_version.attr);
843 if (rc) {
844 printk(KERN_ERR
845 "Unable to create ecryptfs version attribute\n");
846 subsystem_unregister(&ecryptfs_subsys);
847 goto out; 764 goto out;
848 } 765 }
849 rc = sysfs_create_file(&ecryptfs_subsys.kobj, 766 rc = sysfs_create_group(ecryptfs_kobj, &attr_group);
850 &sysfs_attr_version_str.attr);
851 if (rc) { 767 if (rc) {
852 printk(KERN_ERR 768 printk(KERN_ERR
853 "Unable to create ecryptfs version_str attribute\n"); 769 "Unable to create ecryptfs version attributes\n");
854 sysfs_remove_file(&ecryptfs_subsys.kobj, 770 kobject_put(ecryptfs_kobj);
855 &sysfs_attr_version.attr);
856 subsystem_unregister(&ecryptfs_subsys);
857 goto out;
858 } 771 }
859out: 772out:
860 return rc; 773 return rc;
@@ -862,11 +775,8 @@ out:
862 775
863static void do_sysfs_unregistration(void) 776static void do_sysfs_unregistration(void)
864{ 777{
865 sysfs_remove_file(&ecryptfs_subsys.kobj, 778 sysfs_remove_group(ecryptfs_kobj, &attr_group);
866 &sysfs_attr_version.attr); 779 kobject_put(ecryptfs_kobj);
867 sysfs_remove_file(&ecryptfs_subsys.kobj,
868 &sysfs_attr_version_str.attr);
869 subsystem_unregister(&ecryptfs_subsys);
870} 780}
871 781
872static int __init ecryptfs_init(void) 782static int __init ecryptfs_init(void)
@@ -894,7 +804,6 @@ static int __init ecryptfs_init(void)
894 printk(KERN_ERR "Failed to register filesystem\n"); 804 printk(KERN_ERR "Failed to register filesystem\n");
895 goto out_free_kmem_caches; 805 goto out_free_kmem_caches;
896 } 806 }
897 kobj_set_kset_s(&ecryptfs_subsys, fs_subsys);
898 rc = do_sysfs_registration(); 807 rc = do_sysfs_registration();
899 if (rc) { 808 if (rc) {
900 printk(KERN_ERR "sysfs registration failed\n"); 809 printk(KERN_ERR "sysfs registration failed\n");
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c
index f8cdab2bee3d..4859c4eecd65 100644
--- a/fs/ecryptfs/super.c
+++ b/fs/ecryptfs/super.c
@@ -86,7 +86,6 @@ static void ecryptfs_destroy_inode(struct inode *inode)
86 fput(inode_info->lower_file); 86 fput(inode_info->lower_file);
87 inode_info->lower_file = NULL; 87 inode_info->lower_file = NULL;
88 d_drop(lower_dentry); 88 d_drop(lower_dentry);
89 d_delete(lower_dentry);
90 } 89 }
91 } 90 }
92 mutex_unlock(&inode_info->lower_file_mutex); 91 mutex_unlock(&inode_info->lower_file_mutex);
diff --git a/fs/fat/fatent.c b/fs/fat/fatent.c
index 2c1b73fb82ae..5fb366992b73 100644
--- a/fs/fat/fatent.c
+++ b/fs/fat/fatent.c
@@ -590,21 +590,49 @@ error:
590 590
591EXPORT_SYMBOL_GPL(fat_free_clusters); 591EXPORT_SYMBOL_GPL(fat_free_clusters);
592 592
593/* 128kb is the whole sectors for FAT12 and FAT16 */
594#define FAT_READA_SIZE (128 * 1024)
595
596static void fat_ent_reada(struct super_block *sb, struct fat_entry *fatent,
597 unsigned long reada_blocks)
598{
599 struct fatent_operations *ops = MSDOS_SB(sb)->fatent_ops;
600 sector_t blocknr;
601 int i, offset;
602
603 ops->ent_blocknr(sb, fatent->entry, &offset, &blocknr);
604
605 for (i = 0; i < reada_blocks; i++)
606 sb_breadahead(sb, blocknr + i);
607}
608
593int fat_count_free_clusters(struct super_block *sb) 609int fat_count_free_clusters(struct super_block *sb)
594{ 610{
595 struct msdos_sb_info *sbi = MSDOS_SB(sb); 611 struct msdos_sb_info *sbi = MSDOS_SB(sb);
596 struct fatent_operations *ops = sbi->fatent_ops; 612 struct fatent_operations *ops = sbi->fatent_ops;
597 struct fat_entry fatent; 613 struct fat_entry fatent;
614 unsigned long reada_blocks, reada_mask, cur_block;
598 int err = 0, free; 615 int err = 0, free;
599 616
600 lock_fat(sbi); 617 lock_fat(sbi);
601 if (sbi->free_clusters != -1) 618 if (sbi->free_clusters != -1)
602 goto out; 619 goto out;
603 620
621 reada_blocks = FAT_READA_SIZE >> sb->s_blocksize_bits;
622 reada_mask = reada_blocks - 1;
623 cur_block = 0;
624
604 free = 0; 625 free = 0;
605 fatent_init(&fatent); 626 fatent_init(&fatent);
606 fatent_set_entry(&fatent, FAT_START_ENT); 627 fatent_set_entry(&fatent, FAT_START_ENT);
607 while (fatent.entry < sbi->max_cluster) { 628 while (fatent.entry < sbi->max_cluster) {
629 /* readahead of fat blocks */
630 if ((cur_block & reada_mask) == 0) {
631 unsigned long rest = sbi->fat_length - cur_block;
632 fat_ent_reada(sb, &fatent, min(reada_blocks, rest));
633 }
634 cur_block++;
635
608 err = fat_ent_read_block(sb, &fatent); 636 err = fat_ent_read_block(sb, &fatent);
609 if (err) 637 if (err)
610 goto out; 638 goto out;
diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
index 0fca82021d76..300324bd563c 100644
--- a/fs/fs-writeback.c
+++ b/fs/fs-writeback.c
@@ -482,8 +482,6 @@ sync_sb_inodes(struct super_block *sb, struct writeback_control *wbc)
482 if (wbc->nr_to_write <= 0) 482 if (wbc->nr_to_write <= 0)
483 break; 483 break;
484 } 484 }
485 if (!list_empty(&sb->s_more_io))
486 wbc->more_io = 1;
487 return; /* Leave any unwritten inodes on s_io */ 485 return; /* Leave any unwritten inodes on s_io */
488} 486}
489 487
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 84f9f7dfdf5b..e5e80d1a4687 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -744,9 +744,6 @@ static inline void unregister_fuseblk(void)
744} 744}
745#endif 745#endif
746 746
747static decl_subsys(fuse, NULL, NULL);
748static decl_subsys(connections, NULL, NULL);
749
750static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo) 747static void fuse_inode_init_once(struct kmem_cache *cachep, void *foo)
751{ 748{
752 struct inode * inode = foo; 749 struct inode * inode = foo;
@@ -791,32 +788,37 @@ static void fuse_fs_cleanup(void)
791 kmem_cache_destroy(fuse_inode_cachep); 788 kmem_cache_destroy(fuse_inode_cachep);
792} 789}
793 790
791static struct kobject *fuse_kobj;
792static struct kobject *connections_kobj;
793
794static int fuse_sysfs_init(void) 794static int fuse_sysfs_init(void)
795{ 795{
796 int err; 796 int err;
797 797
798 kobj_set_kset_s(&fuse_subsys, fs_subsys); 798 fuse_kobj = kobject_create_and_add("fuse", fs_kobj);
799 err = subsystem_register(&fuse_subsys); 799 if (!fuse_kobj) {
800 if (err) 800 err = -ENOMEM;
801 goto out_err; 801 goto out_err;
802 }
802 803
803 kobj_set_kset_s(&connections_subsys, fuse_subsys); 804 connections_kobj = kobject_create_and_add("connections", fuse_kobj);
804 err = subsystem_register(&connections_subsys); 805 if (!connections_kobj) {
805 if (err) 806 err = -ENOMEM;
806 goto out_fuse_unregister; 807 goto out_fuse_unregister;
808 }
807 809
808 return 0; 810 return 0;
809 811
810 out_fuse_unregister: 812 out_fuse_unregister:
811 subsystem_unregister(&fuse_subsys); 813 kobject_put(fuse_kobj);
812 out_err: 814 out_err:
813 return err; 815 return err;
814} 816}
815 817
816static void fuse_sysfs_cleanup(void) 818static void fuse_sysfs_cleanup(void)
817{ 819{
818 subsystem_unregister(&connections_subsys); 820 kobject_put(connections_kobj);
819 subsystem_unregister(&fuse_subsys); 821 kobject_put(fuse_kobj);
820} 822}
821 823
822static int __init fuse_init(void) 824static int __init fuse_init(void)
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index 04ad0caebedb..8fff11058cee 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -2,7 +2,7 @@ obj-$(CONFIG_GFS2_FS) += gfs2.o
2gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \ 2gfs2-y := acl.o bmap.o daemon.o dir.o eaops.o eattr.o glock.o \
3 glops.o inode.o lm.o log.o lops.o locking.o main.o meta_io.o \ 3 glops.o inode.o lm.o log.o lops.o locking.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 ops_vm.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_NOLOCK) += locking/nolock/ 8obj-$(CONFIG_GFS2_FS_LOCKING_NOLOCK) += locking/nolock/
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 93fa427bb5f5..e4effc47abfc 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -59,7 +59,6 @@ struct strip_mine {
59static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh, 59static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
60 u64 block, struct page *page) 60 u64 block, struct page *page)
61{ 61{
62 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
63 struct inode *inode = &ip->i_inode; 62 struct inode *inode = &ip->i_inode;
64 struct buffer_head *bh; 63 struct buffer_head *bh;
65 int release = 0; 64 int release = 0;
@@ -95,7 +94,7 @@ static int gfs2_unstuffer_page(struct gfs2_inode *ip, struct buffer_head *dibh,
95 set_buffer_uptodate(bh); 94 set_buffer_uptodate(bh);
96 if (!gfs2_is_jdata(ip)) 95 if (!gfs2_is_jdata(ip))
97 mark_buffer_dirty(bh); 96 mark_buffer_dirty(bh);
98 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) 97 if (!gfs2_is_writeback(ip))
99 gfs2_trans_add_bh(ip->i_gl, bh, 0); 98 gfs2_trans_add_bh(ip->i_gl, bh, 0);
100 99
101 if (release) { 100 if (release) {
@@ -453,8 +452,8 @@ static inline void bmap_unlock(struct inode *inode, int create)
453 * Returns: errno 452 * Returns: errno
454 */ 453 */
455 454
456int gfs2_block_map(struct inode *inode, u64 lblock, int create, 455int gfs2_block_map(struct inode *inode, sector_t lblock,
457 struct buffer_head *bh_map) 456 struct buffer_head *bh_map, int create)
458{ 457{
459 struct gfs2_inode *ip = GFS2_I(inode); 458 struct gfs2_inode *ip = GFS2_I(inode);
460 struct gfs2_sbd *sdp = GFS2_SB(inode); 459 struct gfs2_sbd *sdp = GFS2_SB(inode);
@@ -470,6 +469,7 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int create,
470 unsigned int maxlen = bh_map->b_size >> inode->i_blkbits; 469 unsigned int maxlen = bh_map->b_size >> inode->i_blkbits;
471 struct metapath mp; 470 struct metapath mp;
472 u64 size; 471 u64 size;
472 struct buffer_head *dibh = NULL;
473 473
474 BUG_ON(maxlen == 0); 474 BUG_ON(maxlen == 0);
475 475
@@ -500,6 +500,8 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int create,
500 error = gfs2_meta_inode_buffer(ip, &bh); 500 error = gfs2_meta_inode_buffer(ip, &bh);
501 if (error) 501 if (error)
502 goto out_fail; 502 goto out_fail;
503 dibh = bh;
504 get_bh(dibh);
503 505
504 for (x = 0; x < end_of_metadata; x++) { 506 for (x = 0; x < end_of_metadata; x++) {
505 lookup_block(ip, bh, x, &mp, create, &new, &dblock); 507 lookup_block(ip, bh, x, &mp, create, &new, &dblock);
@@ -518,13 +520,8 @@ int gfs2_block_map(struct inode *inode, u64 lblock, int create,
518 if (boundary) 520 if (boundary)
519 set_buffer_boundary(bh_map); 521 set_buffer_boundary(bh_map);
520 if (new) { 522 if (new) {
521 struct buffer_head *dibh; 523 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
522 error = gfs2_meta_inode_buffer(ip, &dibh); 524 gfs2_dinode_out(ip, dibh->b_data);
523 if (!error) {
524 gfs2_trans_add_bh(ip->i_gl, dibh, 1);
525 gfs2_dinode_out(ip, dibh->b_data);
526 brelse(dibh);
527 }
528 set_buffer_new(bh_map); 525 set_buffer_new(bh_map);
529 goto out_brelse; 526 goto out_brelse;
530 } 527 }
@@ -545,6 +542,8 @@ out_brelse:
545out_ok: 542out_ok:
546 error = 0; 543 error = 0;
547out_fail: 544out_fail:
545 if (dibh)
546 brelse(dibh);
548 bmap_unlock(inode, create); 547 bmap_unlock(inode, create);
549 return error; 548 return error;
550} 549}
@@ -560,7 +559,7 @@ int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsi
560 BUG_ON(!new); 559 BUG_ON(!new);
561 560
562 bh.b_size = 1 << (inode->i_blkbits + 5); 561 bh.b_size = 1 << (inode->i_blkbits + 5);
563 ret = gfs2_block_map(inode, lblock, create, &bh); 562 ret = gfs2_block_map(inode, lblock, &bh, create);
564 *extlen = bh.b_size >> inode->i_blkbits; 563 *extlen = bh.b_size >> inode->i_blkbits;
565 *dblock = bh.b_blocknr; 564 *dblock = bh.b_blocknr;
566 if (buffer_new(&bh)) 565 if (buffer_new(&bh))
@@ -684,7 +683,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
684 if (metadata) 683 if (metadata)
685 revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs; 684 revokes = (height) ? sdp->sd_inptrs : sdp->sd_diptrs;
686 685
687 error = gfs2_rindex_hold(sdp, &ip->i_alloc.al_ri_gh); 686 error = gfs2_rindex_hold(sdp, &ip->i_alloc->al_ri_gh);
688 if (error) 687 if (error)
689 return error; 688 return error;
690 689
@@ -786,7 +785,7 @@ out_rg_gunlock:
786out_rlist: 785out_rlist:
787 gfs2_rlist_free(&rlist); 786 gfs2_rlist_free(&rlist);
788out: 787out:
789 gfs2_glock_dq_uninit(&ip->i_alloc.al_ri_gh); 788 gfs2_glock_dq_uninit(&ip->i_alloc->al_ri_gh);
790 return error; 789 return error;
791} 790}
792 791
@@ -879,7 +878,6 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
879{ 878{
880 struct inode *inode = mapping->host; 879 struct inode *inode = mapping->host;
881 struct gfs2_inode *ip = GFS2_I(inode); 880 struct gfs2_inode *ip = GFS2_I(inode);
882 struct gfs2_sbd *sdp = GFS2_SB(inode);
883 loff_t from = inode->i_size; 881 loff_t from = inode->i_size;
884 unsigned long index = from >> PAGE_CACHE_SHIFT; 882 unsigned long index = from >> PAGE_CACHE_SHIFT;
885 unsigned offset = from & (PAGE_CACHE_SIZE-1); 883 unsigned offset = from & (PAGE_CACHE_SIZE-1);
@@ -911,7 +909,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
911 err = 0; 909 err = 0;
912 910
913 if (!buffer_mapped(bh)) { 911 if (!buffer_mapped(bh)) {
914 gfs2_get_block(inode, iblock, bh, 0); 912 gfs2_block_map(inode, iblock, bh, 0);
915 /* unmapped? It's a hole - nothing to do */ 913 /* unmapped? It's a hole - nothing to do */
916 if (!buffer_mapped(bh)) 914 if (!buffer_mapped(bh))
917 goto unlock; 915 goto unlock;
@@ -931,7 +929,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
931 err = 0; 929 err = 0;
932 } 930 }
933 931
934 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) 932 if (!gfs2_is_writeback(ip))
935 gfs2_trans_add_bh(ip->i_gl, bh, 0); 933 gfs2_trans_add_bh(ip->i_gl, bh, 0);
936 934
937 zero_user_page(page, offset, length, KM_USER0); 935 zero_user_page(page, offset, length, KM_USER0);
@@ -1224,8 +1222,13 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
1224 do_div(lblock_stop, bsize); 1222 do_div(lblock_stop, bsize);
1225 } else { 1223 } else {
1226 unsigned int shift = sdp->sd_sb.sb_bsize_shift; 1224 unsigned int shift = sdp->sd_sb.sb_bsize_shift;
1225 u64 end_of_file = (ip->i_di.di_size + sdp->sd_sb.sb_bsize - 1) >> shift;
1227 lblock = offset >> shift; 1226 lblock = offset >> shift;
1228 lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift; 1227 lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift;
1228 if (lblock_stop > end_of_file) {
1229 *alloc_required = 1;
1230 return 0;
1231 }
1229 } 1232 }
1230 1233
1231 for (; lblock < lblock_stop; lblock += extlen) { 1234 for (; lblock < lblock_stop; lblock += extlen) {
diff --git a/fs/gfs2/bmap.h b/fs/gfs2/bmap.h
index ac2fd04370dc..4e6cde2943bd 100644
--- a/fs/gfs2/bmap.h
+++ b/fs/gfs2/bmap.h
@@ -15,7 +15,7 @@ struct gfs2_inode;
15struct page; 15struct page;
16 16
17int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page); 17int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page);
18int gfs2_block_map(struct inode *inode, u64 lblock, int create, struct buffer_head *bh); 18int gfs2_block_map(struct inode *inode, sector_t lblock, struct buffer_head *bh, int create);
19int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen); 19int gfs2_extent_map(struct inode *inode, u64 lblock, int *new, u64 *dblock, unsigned *extlen);
20 20
21int gfs2_truncatei(struct gfs2_inode *ip, u64 size); 21int gfs2_truncatei(struct gfs2_inode *ip, u64 size);
diff --git a/fs/gfs2/daemon.c b/fs/gfs2/daemon.c
index 3731ab0771d5..e51991947d2c 100644
--- a/fs/gfs2/daemon.c
+++ b/fs/gfs2/daemon.c
@@ -83,56 +83,6 @@ int gfs2_recoverd(void *data)
83} 83}
84 84
85/** 85/**
86 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
87 * @sdp: Pointer to GFS2 superblock
88 *
89 * Also, periodically check to make sure that we're using the most recent
90 * journal index.
91 */
92
93int gfs2_logd(void *data)
94{
95 struct gfs2_sbd *sdp = data;
96 struct gfs2_holder ji_gh;
97 unsigned long t;
98 int need_flush;
99
100 while (!kthread_should_stop()) {
101 /* Advance the log tail */
102
103 t = sdp->sd_log_flush_time +
104 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
105
106 gfs2_ail1_empty(sdp, DIO_ALL);
107 gfs2_log_lock(sdp);
108 need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks);
109 gfs2_log_unlock(sdp);
110 if (need_flush || time_after_eq(jiffies, t)) {
111 gfs2_log_flush(sdp, NULL);
112 sdp->sd_log_flush_time = jiffies;
113 }
114
115 /* Check for latest journal index */
116
117 t = sdp->sd_jindex_refresh_time +
118 gfs2_tune_get(sdp, gt_jindex_refresh_secs) * HZ;
119
120 if (time_after_eq(jiffies, t)) {
121 if (!gfs2_jindex_hold(sdp, &ji_gh))
122 gfs2_glock_dq_uninit(&ji_gh);
123 sdp->sd_jindex_refresh_time = jiffies;
124 }
125
126 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
127 if (freezing(current))
128 refrigerator();
129 schedule_timeout_interruptible(t);
130 }
131
132 return 0;
133}
134
135/**
136 * gfs2_quotad - Write cached quota changes into the quota file 86 * gfs2_quotad - Write cached quota changes into the quota file
137 * @sdp: Pointer to GFS2 superblock 87 * @sdp: Pointer to GFS2 superblock
138 * 88 *
diff --git a/fs/gfs2/daemon.h b/fs/gfs2/daemon.h
index 0de9b3557955..4be084fb6a62 100644
--- a/fs/gfs2/daemon.h
+++ b/fs/gfs2/daemon.h
@@ -12,7 +12,6 @@
12 12
13int gfs2_glockd(void *data); 13int gfs2_glockd(void *data);
14int gfs2_recoverd(void *data); 14int gfs2_recoverd(void *data);
15int gfs2_logd(void *data);
16int gfs2_quotad(void *data); 15int gfs2_quotad(void *data);
17 16
18#endif /* __DAEMON_DOT_H__ */ 17#endif /* __DAEMON_DOT_H__ */
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 9949bb746a52..57e2ed932adc 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -1876,7 +1876,7 @@ static int leaf_dealloc(struct gfs2_inode *dip, u32 index, u32 len,
1876 if (error) 1876 if (error)
1877 goto out; 1877 goto out;
1878 1878
1879 error = gfs2_rindex_hold(sdp, &dip->i_alloc.al_ri_gh); 1879 error = gfs2_rindex_hold(sdp, &dip->i_alloc->al_ri_gh);
1880 if (error) 1880 if (error)
1881 goto out_qs; 1881 goto out_qs;
1882 1882
@@ -1949,7 +1949,7 @@ out_rg_gunlock:
1949 gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs); 1949 gfs2_glock_dq_m(rlist.rl_rgrps, rlist.rl_ghs);
1950out_rlist: 1950out_rlist:
1951 gfs2_rlist_free(&rlist); 1951 gfs2_rlist_free(&rlist);
1952 gfs2_glock_dq_uninit(&dip->i_alloc.al_ri_gh); 1952 gfs2_glock_dq_uninit(&dip->i_alloc->al_ri_gh);
1953out_qs: 1953out_qs:
1954 gfs2_quota_unhold(dip); 1954 gfs2_quota_unhold(dip);
1955out: 1955out:
diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c
index aa8dbf303f6d..f114ba2b3557 100644
--- a/fs/gfs2/eaops.c
+++ b/fs/gfs2/eaops.c
@@ -56,46 +56,6 @@ unsigned int gfs2_ea_name2type(const char *name, const char **truncated_name)
56 return type; 56 return type;
57} 57}
58 58
59static int user_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
60{
61 struct inode *inode = &ip->i_inode;
62 int error = permission(inode, MAY_READ, NULL);
63 if (error)
64 return error;
65
66 return gfs2_ea_get_i(ip, er);
67}
68
69static int user_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
70{
71 struct inode *inode = &ip->i_inode;
72
73 if (S_ISREG(inode->i_mode) ||
74 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
75 int error = permission(inode, MAY_WRITE, NULL);
76 if (error)
77 return error;
78 } else
79 return -EPERM;
80
81 return gfs2_ea_set_i(ip, er);
82}
83
84static int user_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
85{
86 struct inode *inode = &ip->i_inode;
87
88 if (S_ISREG(inode->i_mode) ||
89 (S_ISDIR(inode->i_mode) && !(inode->i_mode & S_ISVTX))) {
90 int error = permission(inode, MAY_WRITE, NULL);
91 if (error)
92 return error;
93 } else
94 return -EPERM;
95
96 return gfs2_ea_remove_i(ip, er);
97}
98
99static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er) 59static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
100{ 60{
101 if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) && 61 if (!GFS2_ACL_IS_ACCESS(er->er_name, er->er_name_len) &&
@@ -108,8 +68,6 @@ static int system_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
108 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len))) 68 GFS2_ACL_IS_DEFAULT(er->er_name, er->er_name_len)))
109 return -EOPNOTSUPP; 69 return -EOPNOTSUPP;
110 70
111
112
113 return gfs2_ea_get_i(ip, er); 71 return gfs2_ea_get_i(ip, er);
114} 72}
115 73
@@ -170,40 +128,10 @@ static int system_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
170 return gfs2_ea_remove_i(ip, er); 128 return gfs2_ea_remove_i(ip, er);
171} 129}
172 130
173static int security_eo_get(struct gfs2_inode *ip, struct gfs2_ea_request *er)
174{
175 struct inode *inode = &ip->i_inode;
176 int error = permission(inode, MAY_READ, NULL);
177 if (error)
178 return error;
179
180 return gfs2_ea_get_i(ip, er);
181}
182
183static int security_eo_set(struct gfs2_inode *ip, struct gfs2_ea_request *er)
184{
185 struct inode *inode = &ip->i_inode;
186 int error = permission(inode, MAY_WRITE, NULL);
187 if (error)
188 return error;
189
190 return gfs2_ea_set_i(ip, er);
191}
192
193static int security_eo_remove(struct gfs2_inode *ip, struct gfs2_ea_request *er)
194{
195 struct inode *inode = &ip->i_inode;
196 int error = permission(inode, MAY_WRITE, NULL);
197 if (error)
198 return error;
199
200 return gfs2_ea_remove_i(ip, er);
201}
202
203static const struct gfs2_eattr_operations gfs2_user_eaops = { 131static const struct gfs2_eattr_operations gfs2_user_eaops = {
204 .eo_get = user_eo_get, 132 .eo_get = gfs2_ea_get_i,
205 .eo_set = user_eo_set, 133 .eo_set = gfs2_ea_set_i,
206 .eo_remove = user_eo_remove, 134 .eo_remove = gfs2_ea_remove_i,
207 .eo_name = "user", 135 .eo_name = "user",
208}; 136};
209 137
@@ -215,9 +143,9 @@ const struct gfs2_eattr_operations gfs2_system_eaops = {
215}; 143};
216 144
217static const struct gfs2_eattr_operations gfs2_security_eaops = { 145static const struct gfs2_eattr_operations gfs2_security_eaops = {
218 .eo_get = security_eo_get, 146 .eo_get = gfs2_ea_get_i,
219 .eo_set = security_eo_set, 147 .eo_set = gfs2_ea_set_i,
220 .eo_remove = security_eo_remove, 148 .eo_remove = gfs2_ea_remove_i,
221 .eo_name = "security", 149 .eo_name = "security",
222}; 150};
223 151
diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c
index 2a7435b5c4dc..bee99704ea10 100644
--- a/fs/gfs2/eattr.c
+++ b/fs/gfs2/eattr.c
@@ -1418,7 +1418,7 @@ out:
1418static int ea_dealloc_block(struct gfs2_inode *ip) 1418static int ea_dealloc_block(struct gfs2_inode *ip)
1419{ 1419{
1420 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1420 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1421 struct gfs2_alloc *al = &ip->i_alloc; 1421 struct gfs2_alloc *al = ip->i_alloc;
1422 struct gfs2_rgrpd *rgd; 1422 struct gfs2_rgrpd *rgd;
1423 struct buffer_head *dibh; 1423 struct buffer_head *dibh;
1424 int error; 1424 int error;
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index a37efe4aae6f..80e09c50590a 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -217,7 +217,6 @@ int gfs2_glock_put(struct gfs2_glock *gl)
217 if (atomic_dec_and_test(&gl->gl_ref)) { 217 if (atomic_dec_and_test(&gl->gl_ref)) {
218 hlist_del(&gl->gl_list); 218 hlist_del(&gl->gl_list);
219 write_unlock(gl_lock_addr(gl->gl_hash)); 219 write_unlock(gl_lock_addr(gl->gl_hash));
220 BUG_ON(spin_is_locked(&gl->gl_spin));
221 gfs2_assert(sdp, gl->gl_state == LM_ST_UNLOCKED); 220 gfs2_assert(sdp, gl->gl_state == LM_ST_UNLOCKED);
222 gfs2_assert(sdp, list_empty(&gl->gl_reclaim)); 221 gfs2_assert(sdp, list_empty(&gl->gl_reclaim));
223 gfs2_assert(sdp, list_empty(&gl->gl_holders)); 222 gfs2_assert(sdp, list_empty(&gl->gl_holders));
@@ -346,7 +345,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
346 gl->gl_object = NULL; 345 gl->gl_object = NULL;
347 gl->gl_sbd = sdp; 346 gl->gl_sbd = sdp;
348 gl->gl_aspace = NULL; 347 gl->gl_aspace = NULL;
349 lops_init_le(&gl->gl_le, &gfs2_glock_lops);
350 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func); 348 INIT_DELAYED_WORK(&gl->gl_work, glock_work_func);
351 349
352 /* If this glock protects actual on-disk data or metadata blocks, 350 /* If this glock protects actual on-disk data or metadata blocks,
@@ -461,7 +459,6 @@ static void wait_on_holder(struct gfs2_holder *gh)
461 459
462static void gfs2_demote_wake(struct gfs2_glock *gl) 460static void gfs2_demote_wake(struct gfs2_glock *gl)
463{ 461{
464 BUG_ON(!spin_is_locked(&gl->gl_spin));
465 gl->gl_demote_state = LM_ST_EXCLUSIVE; 462 gl->gl_demote_state = LM_ST_EXCLUSIVE;
466 clear_bit(GLF_DEMOTE, &gl->gl_flags); 463 clear_bit(GLF_DEMOTE, &gl->gl_flags);
467 smp_mb__after_clear_bit(); 464 smp_mb__after_clear_bit();
@@ -507,21 +504,12 @@ static int rq_mutex(struct gfs2_holder *gh)
507static int rq_promote(struct gfs2_holder *gh) 504static int rq_promote(struct gfs2_holder *gh)
508{ 505{
509 struct gfs2_glock *gl = gh->gh_gl; 506 struct gfs2_glock *gl = gh->gh_gl;
510 struct gfs2_sbd *sdp = gl->gl_sbd;
511 507
512 if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) { 508 if (!relaxed_state_ok(gl->gl_state, gh->gh_state, gh->gh_flags)) {
513 if (list_empty(&gl->gl_holders)) { 509 if (list_empty(&gl->gl_holders)) {
514 gl->gl_req_gh = gh; 510 gl->gl_req_gh = gh;
515 set_bit(GLF_LOCK, &gl->gl_flags); 511 set_bit(GLF_LOCK, &gl->gl_flags);
516 spin_unlock(&gl->gl_spin); 512 spin_unlock(&gl->gl_spin);
517
518 if (atomic_read(&sdp->sd_reclaim_count) >
519 gfs2_tune_get(sdp, gt_reclaim_limit) &&
520 !(gh->gh_flags & LM_FLAG_PRIORITY)) {
521 gfs2_reclaim_glock(sdp);
522 gfs2_reclaim_glock(sdp);
523 }
524
525 gfs2_glock_xmote_th(gh->gh_gl, gh); 513 gfs2_glock_xmote_th(gh->gh_gl, gh);
526 spin_lock(&gl->gl_spin); 514 spin_lock(&gl->gl_spin);
527 } 515 }
@@ -567,7 +555,10 @@ static int rq_demote(struct gfs2_glock *gl)
567 gfs2_demote_wake(gl); 555 gfs2_demote_wake(gl);
568 return 0; 556 return 0;
569 } 557 }
558
570 set_bit(GLF_LOCK, &gl->gl_flags); 559 set_bit(GLF_LOCK, &gl->gl_flags);
560 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
561
571 if (gl->gl_demote_state == LM_ST_UNLOCKED || 562 if (gl->gl_demote_state == LM_ST_UNLOCKED ||
572 gl->gl_state != LM_ST_EXCLUSIVE) { 563 gl->gl_state != LM_ST_EXCLUSIVE) {
573 spin_unlock(&gl->gl_spin); 564 spin_unlock(&gl->gl_spin);
@@ -576,7 +567,9 @@ static int rq_demote(struct gfs2_glock *gl)
576 spin_unlock(&gl->gl_spin); 567 spin_unlock(&gl->gl_spin);
577 gfs2_glock_xmote_th(gl, NULL); 568 gfs2_glock_xmote_th(gl, NULL);
578 } 569 }
570
579 spin_lock(&gl->gl_spin); 571 spin_lock(&gl->gl_spin);
572 clear_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
580 573
581 return 0; 574 return 0;
582} 575}
@@ -598,23 +591,18 @@ static void run_queue(struct gfs2_glock *gl)
598 if (!list_empty(&gl->gl_waiters1)) { 591 if (!list_empty(&gl->gl_waiters1)) {
599 gh = list_entry(gl->gl_waiters1.next, 592 gh = list_entry(gl->gl_waiters1.next,
600 struct gfs2_holder, gh_list); 593 struct gfs2_holder, gh_list);
601 594 blocked = rq_mutex(gh);
602 if (test_bit(HIF_MUTEX, &gh->gh_iflags))
603 blocked = rq_mutex(gh);
604 else
605 gfs2_assert_warn(gl->gl_sbd, 0);
606
607 } else if (test_bit(GLF_DEMOTE, &gl->gl_flags)) { 595 } else if (test_bit(GLF_DEMOTE, &gl->gl_flags)) {
608 blocked = rq_demote(gl); 596 blocked = rq_demote(gl);
597 if (gl->gl_waiters2 && !blocked) {
598 set_bit(GLF_DEMOTE, &gl->gl_flags);
599 gl->gl_demote_state = LM_ST_UNLOCKED;
600 }
601 gl->gl_waiters2 = 0;
609 } else if (!list_empty(&gl->gl_waiters3)) { 602 } else if (!list_empty(&gl->gl_waiters3)) {
610 gh = list_entry(gl->gl_waiters3.next, 603 gh = list_entry(gl->gl_waiters3.next,
611 struct gfs2_holder, gh_list); 604 struct gfs2_holder, gh_list);
612 605 blocked = rq_promote(gh);
613 if (test_bit(HIF_PROMOTE, &gh->gh_iflags))
614 blocked = rq_promote(gh);
615 else
616 gfs2_assert_warn(gl->gl_sbd, 0);
617
618 } else 606 } else
619 break; 607 break;
620 608
@@ -632,27 +620,21 @@ static void run_queue(struct gfs2_glock *gl)
632 620
633static void gfs2_glmutex_lock(struct gfs2_glock *gl) 621static void gfs2_glmutex_lock(struct gfs2_glock *gl)
634{ 622{
635 struct gfs2_holder gh;
636
637 gfs2_holder_init(gl, 0, 0, &gh);
638 set_bit(HIF_MUTEX, &gh.gh_iflags);
639 if (test_and_set_bit(HIF_WAIT, &gh.gh_iflags))
640 BUG();
641
642 spin_lock(&gl->gl_spin); 623 spin_lock(&gl->gl_spin);
643 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) { 624 if (test_and_set_bit(GLF_LOCK, &gl->gl_flags)) {
625 struct gfs2_holder gh;
626
627 gfs2_holder_init(gl, 0, 0, &gh);
628 set_bit(HIF_WAIT, &gh.gh_iflags);
644 list_add_tail(&gh.gh_list, &gl->gl_waiters1); 629 list_add_tail(&gh.gh_list, &gl->gl_waiters1);
630 spin_unlock(&gl->gl_spin);
631 wait_on_holder(&gh);
632 gfs2_holder_uninit(&gh);
645 } else { 633 } else {
646 gl->gl_owner_pid = current->pid; 634 gl->gl_owner_pid = current->pid;
647 gl->gl_ip = (unsigned long)__builtin_return_address(0); 635 gl->gl_ip = (unsigned long)__builtin_return_address(0);
648 clear_bit(HIF_WAIT, &gh.gh_iflags); 636 spin_unlock(&gl->gl_spin);
649 smp_mb();
650 wake_up_bit(&gh.gh_iflags, HIF_WAIT);
651 } 637 }
652 spin_unlock(&gl->gl_spin);
653
654 wait_on_holder(&gh);
655 gfs2_holder_uninit(&gh);
656} 638}
657 639
658/** 640/**
@@ -691,7 +673,6 @@ static void gfs2_glmutex_unlock(struct gfs2_glock *gl)
691 gl->gl_owner_pid = 0; 673 gl->gl_owner_pid = 0;
692 gl->gl_ip = 0; 674 gl->gl_ip = 0;
693 run_queue(gl); 675 run_queue(gl);
694 BUG_ON(!spin_is_locked(&gl->gl_spin));
695 spin_unlock(&gl->gl_spin); 676 spin_unlock(&gl->gl_spin);
696} 677}
697 678
@@ -722,7 +703,10 @@ static void handle_callback(struct gfs2_glock *gl, unsigned int state,
722 } 703 }
723 } else if (gl->gl_demote_state != LM_ST_UNLOCKED && 704 } else if (gl->gl_demote_state != LM_ST_UNLOCKED &&
724 gl->gl_demote_state != state) { 705 gl->gl_demote_state != state) {
725 gl->gl_demote_state = LM_ST_UNLOCKED; 706 if (test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags))
707 gl->gl_waiters2 = 1;
708 else
709 gl->gl_demote_state = LM_ST_UNLOCKED;
726 } 710 }
727 spin_unlock(&gl->gl_spin); 711 spin_unlock(&gl->gl_spin);
728} 712}
@@ -943,8 +927,8 @@ static void gfs2_glock_drop_th(struct gfs2_glock *gl)
943 const struct gfs2_glock_operations *glops = gl->gl_ops; 927 const struct gfs2_glock_operations *glops = gl->gl_ops;
944 unsigned int ret; 928 unsigned int ret;
945 929
946 if (glops->go_drop_th) 930 if (glops->go_xmote_th)
947 glops->go_drop_th(gl); 931 glops->go_xmote_th(gl);
948 932
949 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags)); 933 gfs2_assert_warn(sdp, test_bit(GLF_LOCK, &gl->gl_flags));
950 gfs2_assert_warn(sdp, list_empty(&gl->gl_holders)); 934 gfs2_assert_warn(sdp, list_empty(&gl->gl_holders));
@@ -1156,8 +1140,6 @@ restart:
1156 return -EIO; 1140 return -EIO;
1157 } 1141 }
1158 1142
1159 set_bit(HIF_PROMOTE, &gh->gh_iflags);
1160
1161 spin_lock(&gl->gl_spin); 1143 spin_lock(&gl->gl_spin);
1162 add_to_queue(gh); 1144 add_to_queue(gh);
1163 run_queue(gl); 1145 run_queue(gl);
@@ -1248,12 +1230,11 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
1248 list_del_init(&gh->gh_list); 1230 list_del_init(&gh->gh_list);
1249 1231
1250 if (list_empty(&gl->gl_holders)) { 1232 if (list_empty(&gl->gl_holders)) {
1251 spin_unlock(&gl->gl_spin); 1233 if (glops->go_unlock) {
1252 1234 spin_unlock(&gl->gl_spin);
1253 if (glops->go_unlock)
1254 glops->go_unlock(gh); 1235 glops->go_unlock(gh);
1255 1236 spin_lock(&gl->gl_spin);
1256 spin_lock(&gl->gl_spin); 1237 }
1257 gl->gl_stamp = jiffies; 1238 gl->gl_stamp = jiffies;
1258 } 1239 }
1259 1240
@@ -1910,8 +1891,6 @@ static int dump_glock(struct glock_iter *gi, struct gfs2_glock *gl)
1910 print_dbg(gi, " req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no"); 1891 print_dbg(gi, " req_bh = %s\n", (gl->gl_req_bh) ? "yes" : "no");
1911 print_dbg(gi, " lvb_count = %d\n", atomic_read(&gl->gl_lvb_count)); 1892 print_dbg(gi, " lvb_count = %d\n", atomic_read(&gl->gl_lvb_count));
1912 print_dbg(gi, " object = %s\n", (gl->gl_object) ? "yes" : "no"); 1893 print_dbg(gi, " object = %s\n", (gl->gl_object) ? "yes" : "no");
1913 print_dbg(gi, " le = %s\n",
1914 (list_empty(&gl->gl_le.le_list)) ? "no" : "yes");
1915 print_dbg(gi, " reclaim = %s\n", 1894 print_dbg(gi, " reclaim = %s\n",
1916 (list_empty(&gl->gl_reclaim)) ? "no" : "yes"); 1895 (list_empty(&gl->gl_reclaim)) ? "no" : "yes");
1917 if (gl->gl_aspace) 1896 if (gl->gl_aspace)
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 4670dcb2a877..c663b7a0f410 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -56,7 +56,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
56 bd = list_entry(head->next, struct gfs2_bufdata, 56 bd = list_entry(head->next, struct gfs2_bufdata,
57 bd_ail_gl_list); 57 bd_ail_gl_list);
58 bh = bd->bd_bh; 58 bh = bd->bd_bh;
59 gfs2_remove_from_ail(NULL, bd); 59 gfs2_remove_from_ail(bd);
60 bd->bd_bh = NULL; 60 bd->bd_bh = NULL;
61 bh->b_private = NULL; 61 bh->b_private = NULL;
62 bd->bd_blkno = bh->b_blocknr; 62 bd->bd_blkno = bh->b_blocknr;
@@ -86,15 +86,10 @@ static void gfs2_pte_inval(struct gfs2_glock *gl)
86 if (!ip || !S_ISREG(inode->i_mode)) 86 if (!ip || !S_ISREG(inode->i_mode))
87 return; 87 return;
88 88
89 if (!test_bit(GIF_PAGED, &ip->i_flags))
90 return;
91
92 unmap_shared_mapping_range(inode->i_mapping, 0, 0); 89 unmap_shared_mapping_range(inode->i_mapping, 0, 0);
93
94 if (test_bit(GIF_SW_PAGED, &ip->i_flags)) 90 if (test_bit(GIF_SW_PAGED, &ip->i_flags))
95 set_bit(GLF_DIRTY, &gl->gl_flags); 91 set_bit(GLF_DIRTY, &gl->gl_flags);
96 92
97 clear_bit(GIF_SW_PAGED, &ip->i_flags);
98} 93}
99 94
100/** 95/**
@@ -143,44 +138,34 @@ static void meta_go_inval(struct gfs2_glock *gl, int flags)
143static void inode_go_sync(struct gfs2_glock *gl) 138static void inode_go_sync(struct gfs2_glock *gl)
144{ 139{
145 struct gfs2_inode *ip = gl->gl_object; 140 struct gfs2_inode *ip = gl->gl_object;
141 struct address_space *metamapping = gl->gl_aspace->i_mapping;
142 int error;
143
144 if (gl->gl_state != LM_ST_UNLOCKED)
145 gfs2_pte_inval(gl);
146 if (gl->gl_state != LM_ST_EXCLUSIVE)
147 return;
146 148
147 if (ip && !S_ISREG(ip->i_inode.i_mode)) 149 if (ip && !S_ISREG(ip->i_inode.i_mode))
148 ip = NULL; 150 ip = NULL;
149 151
150 if (test_bit(GLF_DIRTY, &gl->gl_flags)) { 152 if (test_bit(GLF_DIRTY, &gl->gl_flags)) {
151 if (ip && !gfs2_is_jdata(ip))
152 filemap_fdatawrite(ip->i_inode.i_mapping);
153 gfs2_log_flush(gl->gl_sbd, gl); 153 gfs2_log_flush(gl->gl_sbd, gl);
154 if (ip && gfs2_is_jdata(ip)) 154 filemap_fdatawrite(metamapping);
155 filemap_fdatawrite(ip->i_inode.i_mapping);
156 gfs2_meta_sync(gl);
157 if (ip) { 155 if (ip) {
158 struct address_space *mapping = ip->i_inode.i_mapping; 156 struct address_space *mapping = ip->i_inode.i_mapping;
159 int error = filemap_fdatawait(mapping); 157 filemap_fdatawrite(mapping);
158 error = filemap_fdatawait(mapping);
160 mapping_set_error(mapping, error); 159 mapping_set_error(mapping, error);
161 } 160 }
161 error = filemap_fdatawait(metamapping);
162 mapping_set_error(metamapping, error);
162 clear_bit(GLF_DIRTY, &gl->gl_flags); 163 clear_bit(GLF_DIRTY, &gl->gl_flags);
163 gfs2_ail_empty_gl(gl); 164 gfs2_ail_empty_gl(gl);
164 } 165 }
165} 166}
166 167
167/** 168/**
168 * inode_go_xmote_th - promote/demote a glock
169 * @gl: the glock
170 * @state: the requested state
171 * @flags:
172 *
173 */
174
175static void inode_go_xmote_th(struct gfs2_glock *gl)
176{
177 if (gl->gl_state != LM_ST_UNLOCKED)
178 gfs2_pte_inval(gl);
179 if (gl->gl_state == LM_ST_EXCLUSIVE)
180 inode_go_sync(gl);
181}
182
183/**
184 * inode_go_xmote_bh - After promoting/demoting a glock 169 * inode_go_xmote_bh - After promoting/demoting a glock
185 * @gl: the glock 170 * @gl: the glock
186 * 171 *
@@ -201,22 +186,6 @@ static void inode_go_xmote_bh(struct gfs2_glock *gl)
201} 186}
202 187
203/** 188/**
204 * inode_go_drop_th - unlock a glock
205 * @gl: the glock
206 *
207 * Invoked from rq_demote().
208 * Another node needs the lock in EXCLUSIVE mode, or lock (unused for too long)
209 * is being purged from our node's glock cache; we're dropping lock.
210 */
211
212static void inode_go_drop_th(struct gfs2_glock *gl)
213{
214 gfs2_pte_inval(gl);
215 if (gl->gl_state == LM_ST_EXCLUSIVE)
216 inode_go_sync(gl);
217}
218
219/**
220 * inode_go_inval - prepare a inode glock to be released 189 * inode_go_inval - prepare a inode glock to be released
221 * @gl: the glock 190 * @gl: the glock
222 * @flags: 191 * @flags:
@@ -234,10 +203,8 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
234 set_bit(GIF_INVALID, &ip->i_flags); 203 set_bit(GIF_INVALID, &ip->i_flags);
235 } 204 }
236 205
237 if (ip && S_ISREG(ip->i_inode.i_mode)) { 206 if (ip && S_ISREG(ip->i_inode.i_mode))
238 truncate_inode_pages(ip->i_inode.i_mapping, 0); 207 truncate_inode_pages(ip->i_inode.i_mapping, 0);
239 clear_bit(GIF_PAGED, &ip->i_flags);
240 }
241} 208}
242 209
243/** 210/**
@@ -294,23 +261,6 @@ static int inode_go_lock(struct gfs2_holder *gh)
294} 261}
295 262
296/** 263/**
297 * inode_go_unlock - operation done before an inode lock is unlocked by a
298 * process
299 * @gl: the glock
300 * @flags:
301 *
302 */
303
304static void inode_go_unlock(struct gfs2_holder *gh)
305{
306 struct gfs2_glock *gl = gh->gh_gl;
307 struct gfs2_inode *ip = gl->gl_object;
308
309 if (ip)
310 gfs2_meta_cache_flush(ip);
311}
312
313/**
314 * rgrp_go_demote_ok - Check to see if it's ok to unlock a RG's glock 264 * rgrp_go_demote_ok - Check to see if it's ok to unlock a RG's glock
315 * @gl: the glock 265 * @gl: the glock
316 * 266 *
@@ -350,14 +300,14 @@ static void rgrp_go_unlock(struct gfs2_holder *gh)
350} 300}
351 301
352/** 302/**
353 * trans_go_xmote_th - promote/demote the transaction glock 303 * trans_go_sync - promote/demote the transaction glock
354 * @gl: the glock 304 * @gl: the glock
355 * @state: the requested state 305 * @state: the requested state
356 * @flags: 306 * @flags:
357 * 307 *
358 */ 308 */
359 309
360static void trans_go_xmote_th(struct gfs2_glock *gl) 310static void trans_go_sync(struct gfs2_glock *gl)
361{ 311{
362 struct gfs2_sbd *sdp = gl->gl_sbd; 312 struct gfs2_sbd *sdp = gl->gl_sbd;
363 313
@@ -384,7 +334,6 @@ static void trans_go_xmote_bh(struct gfs2_glock *gl)
384 334
385 if (gl->gl_state != LM_ST_UNLOCKED && 335 if (gl->gl_state != LM_ST_UNLOCKED &&
386 test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) { 336 test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
387 gfs2_meta_cache_flush(GFS2_I(sdp->sd_jdesc->jd_inode));
388 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 337 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
389 338
390 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 339 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
@@ -402,24 +351,6 @@ static void trans_go_xmote_bh(struct gfs2_glock *gl)
402} 351}
403 352
404/** 353/**
405 * trans_go_drop_th - unlock the transaction glock
406 * @gl: the glock
407 *
408 * We want to sync the device even with localcaching. Remember
409 * that localcaching journal replay only marks buffers dirty.
410 */
411
412static void trans_go_drop_th(struct gfs2_glock *gl)
413{
414 struct gfs2_sbd *sdp = gl->gl_sbd;
415
416 if (test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
417 gfs2_meta_syncfs(sdp);
418 gfs2_log_shutdown(sdp);
419 }
420}
421
422/**
423 * quota_go_demote_ok - Check to see if it's ok to unlock a quota glock 354 * quota_go_demote_ok - Check to see if it's ok to unlock a quota glock
424 * @gl: the glock 355 * @gl: the glock
425 * 356 *
@@ -433,25 +364,21 @@ static int quota_go_demote_ok(struct gfs2_glock *gl)
433 364
434const struct gfs2_glock_operations gfs2_meta_glops = { 365const struct gfs2_glock_operations gfs2_meta_glops = {
435 .go_xmote_th = meta_go_sync, 366 .go_xmote_th = meta_go_sync,
436 .go_drop_th = meta_go_sync,
437 .go_type = LM_TYPE_META, 367 .go_type = LM_TYPE_META,
438}; 368};
439 369
440const struct gfs2_glock_operations gfs2_inode_glops = { 370const struct gfs2_glock_operations gfs2_inode_glops = {
441 .go_xmote_th = inode_go_xmote_th, 371 .go_xmote_th = inode_go_sync,
442 .go_xmote_bh = inode_go_xmote_bh, 372 .go_xmote_bh = inode_go_xmote_bh,
443 .go_drop_th = inode_go_drop_th,
444 .go_inval = inode_go_inval, 373 .go_inval = inode_go_inval,
445 .go_demote_ok = inode_go_demote_ok, 374 .go_demote_ok = inode_go_demote_ok,
446 .go_lock = inode_go_lock, 375 .go_lock = inode_go_lock,
447 .go_unlock = inode_go_unlock,
448 .go_type = LM_TYPE_INODE, 376 .go_type = LM_TYPE_INODE,
449 .go_min_hold_time = HZ / 10, 377 .go_min_hold_time = HZ / 10,
450}; 378};
451 379
452const struct gfs2_glock_operations gfs2_rgrp_glops = { 380const struct gfs2_glock_operations gfs2_rgrp_glops = {
453 .go_xmote_th = meta_go_sync, 381 .go_xmote_th = meta_go_sync,
454 .go_drop_th = meta_go_sync,
455 .go_inval = meta_go_inval, 382 .go_inval = meta_go_inval,
456 .go_demote_ok = rgrp_go_demote_ok, 383 .go_demote_ok = rgrp_go_demote_ok,
457 .go_lock = rgrp_go_lock, 384 .go_lock = rgrp_go_lock,
@@ -461,9 +388,8 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = {
461}; 388};
462 389
463const struct gfs2_glock_operations gfs2_trans_glops = { 390const struct gfs2_glock_operations gfs2_trans_glops = {
464 .go_xmote_th = trans_go_xmote_th, 391 .go_xmote_th = trans_go_sync,
465 .go_xmote_bh = trans_go_xmote_bh, 392 .go_xmote_bh = trans_go_xmote_bh,
466 .go_drop_th = trans_go_drop_th,
467 .go_type = LM_TYPE_NONDISK, 393 .go_type = LM_TYPE_NONDISK,
468}; 394};
469 395
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index eaddfb5a8e6f..513aaf0dc0ab 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -131,7 +131,6 @@ struct gfs2_bufdata {
131struct gfs2_glock_operations { 131struct gfs2_glock_operations {
132 void (*go_xmote_th) (struct gfs2_glock *gl); 132 void (*go_xmote_th) (struct gfs2_glock *gl);
133 void (*go_xmote_bh) (struct gfs2_glock *gl); 133 void (*go_xmote_bh) (struct gfs2_glock *gl);
134 void (*go_drop_th) (struct gfs2_glock *gl);
135 void (*go_inval) (struct gfs2_glock *gl, int flags); 134 void (*go_inval) (struct gfs2_glock *gl, int flags);
136 int (*go_demote_ok) (struct gfs2_glock *gl); 135 int (*go_demote_ok) (struct gfs2_glock *gl);
137 int (*go_lock) (struct gfs2_holder *gh); 136 int (*go_lock) (struct gfs2_holder *gh);
@@ -141,10 +140,6 @@ struct gfs2_glock_operations {
141}; 140};
142 141
143enum { 142enum {
144 /* Actions */
145 HIF_MUTEX = 0,
146 HIF_PROMOTE = 1,
147
148 /* States */ 143 /* States */
149 HIF_HOLDER = 6, 144 HIF_HOLDER = 6,
150 HIF_FIRST = 7, 145 HIF_FIRST = 7,
@@ -171,6 +166,8 @@ enum {
171 GLF_DEMOTE = 3, 166 GLF_DEMOTE = 3,
172 GLF_PENDING_DEMOTE = 4, 167 GLF_PENDING_DEMOTE = 4,
173 GLF_DIRTY = 5, 168 GLF_DIRTY = 5,
169 GLF_DEMOTE_IN_PROGRESS = 6,
170 GLF_LFLUSH = 7,
174}; 171};
175 172
176struct gfs2_glock { 173struct gfs2_glock {
@@ -190,6 +187,7 @@ struct gfs2_glock {
190 struct list_head gl_holders; 187 struct list_head gl_holders;
191 struct list_head gl_waiters1; /* HIF_MUTEX */ 188 struct list_head gl_waiters1; /* HIF_MUTEX */
192 struct list_head gl_waiters3; /* HIF_PROMOTE */ 189 struct list_head gl_waiters3; /* HIF_PROMOTE */
190 int gl_waiters2; /* GIF_DEMOTE */
193 191
194 const struct gfs2_glock_operations *gl_ops; 192 const struct gfs2_glock_operations *gl_ops;
195 193
@@ -210,7 +208,6 @@ struct gfs2_glock {
210 struct gfs2_sbd *gl_sbd; 208 struct gfs2_sbd *gl_sbd;
211 209
212 struct inode *gl_aspace; 210 struct inode *gl_aspace;
213 struct gfs2_log_element gl_le;
214 struct list_head gl_ail_list; 211 struct list_head gl_ail_list;
215 atomic_t gl_ail_count; 212 atomic_t gl_ail_count;
216 struct delayed_work gl_work; 213 struct delayed_work gl_work;
@@ -239,7 +236,6 @@ struct gfs2_alloc {
239enum { 236enum {
240 GIF_INVALID = 0, 237 GIF_INVALID = 0,
241 GIF_QD_LOCKED = 1, 238 GIF_QD_LOCKED = 1,
242 GIF_PAGED = 2,
243 GIF_SW_PAGED = 3, 239 GIF_SW_PAGED = 3,
244}; 240};
245 241
@@ -268,14 +264,10 @@ struct gfs2_inode {
268 struct gfs2_glock *i_gl; /* Move into i_gh? */ 264 struct gfs2_glock *i_gl; /* Move into i_gh? */
269 struct gfs2_holder i_iopen_gh; 265 struct gfs2_holder i_iopen_gh;
270 struct gfs2_holder i_gh; /* for prepare/commit_write only */ 266 struct gfs2_holder i_gh; /* for prepare/commit_write only */
271 struct gfs2_alloc i_alloc; 267 struct gfs2_alloc *i_alloc;
272 u64 i_last_rg_alloc; 268 u64 i_last_rg_alloc;
273 269
274 spinlock_t i_spin;
275 struct rw_semaphore i_rw_mutex; 270 struct rw_semaphore i_rw_mutex;
276 unsigned long i_last_pfault;
277
278 struct buffer_head *i_cache[GFS2_MAX_META_HEIGHT];
279}; 271};
280 272
281/* 273/*
@@ -287,19 +279,12 @@ static inline struct gfs2_inode *GFS2_I(struct inode *inode)
287 return container_of(inode, struct gfs2_inode, i_inode); 279 return container_of(inode, struct gfs2_inode, i_inode);
288} 280}
289 281
290/* To be removed? */ 282static inline struct gfs2_sbd *GFS2_SB(const struct inode *inode)
291static inline struct gfs2_sbd *GFS2_SB(struct inode *inode)
292{ 283{
293 return inode->i_sb->s_fs_info; 284 return inode->i_sb->s_fs_info;
294} 285}
295 286
296enum {
297 GFF_DID_DIRECT_ALLOC = 0,
298 GFF_EXLOCK = 1,
299};
300
301struct gfs2_file { 287struct gfs2_file {
302 unsigned long f_flags; /* GFF_... */
303 struct mutex f_fl_mutex; 288 struct mutex f_fl_mutex;
304 struct gfs2_holder f_fl_gh; 289 struct gfs2_holder f_fl_gh;
305}; 290};
@@ -373,8 +358,17 @@ struct gfs2_ail {
373 u64 ai_sync_gen; 358 u64 ai_sync_gen;
374}; 359};
375 360
361struct gfs2_journal_extent {
362 struct list_head extent_list;
363
364 unsigned int lblock; /* First logical block */
365 u64 dblock; /* First disk block */
366 u64 blocks;
367};
368
376struct gfs2_jdesc { 369struct gfs2_jdesc {
377 struct list_head jd_list; 370 struct list_head jd_list;
371 struct list_head extent_list;
378 372
379 struct inode *jd_inode; 373 struct inode *jd_inode;
380 unsigned int jd_jid; 374 unsigned int jd_jid;
@@ -421,13 +415,9 @@ struct gfs2_args {
421struct gfs2_tune { 415struct gfs2_tune {
422 spinlock_t gt_spin; 416 spinlock_t gt_spin;
423 417
424 unsigned int gt_ilimit;
425 unsigned int gt_ilimit_tries;
426 unsigned int gt_ilimit_min;
427 unsigned int gt_demote_secs; /* Cache retention for unheld glock */ 418 unsigned int gt_demote_secs; /* Cache retention for unheld glock */
428 unsigned int gt_incore_log_blocks; 419 unsigned int gt_incore_log_blocks;
429 unsigned int gt_log_flush_secs; 420 unsigned int gt_log_flush_secs;
430 unsigned int gt_jindex_refresh_secs; /* Check for new journal index */
431 421
432 unsigned int gt_recoverd_secs; 422 unsigned int gt_recoverd_secs;
433 unsigned int gt_logd_secs; 423 unsigned int gt_logd_secs;
@@ -443,10 +433,8 @@ struct gfs2_tune {
443 unsigned int gt_new_files_jdata; 433 unsigned int gt_new_files_jdata;
444 unsigned int gt_new_files_directio; 434 unsigned int gt_new_files_directio;
445 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */ 435 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */
446 unsigned int gt_lockdump_size;
447 unsigned int gt_stall_secs; /* Detects trouble! */ 436 unsigned int gt_stall_secs; /* Detects trouble! */
448 unsigned int gt_complain_secs; 437 unsigned int gt_complain_secs;
449 unsigned int gt_reclaim_limit; /* Max num of glocks in reclaim list */
450 unsigned int gt_statfs_quantum; 438 unsigned int gt_statfs_quantum;
451 unsigned int gt_statfs_slow; 439 unsigned int gt_statfs_slow;
452}; 440};
@@ -539,7 +527,6 @@ struct gfs2_sbd {
539 /* StatFS stuff */ 527 /* StatFS stuff */
540 528
541 spinlock_t sd_statfs_spin; 529 spinlock_t sd_statfs_spin;
542 struct mutex sd_statfs_mutex;
543 struct gfs2_statfs_change_host sd_statfs_master; 530 struct gfs2_statfs_change_host sd_statfs_master;
544 struct gfs2_statfs_change_host sd_statfs_local; 531 struct gfs2_statfs_change_host sd_statfs_local;
545 unsigned long sd_statfs_sync_time; 532 unsigned long sd_statfs_sync_time;
@@ -602,20 +589,18 @@ struct gfs2_sbd {
602 unsigned int sd_log_commited_databuf; 589 unsigned int sd_log_commited_databuf;
603 unsigned int sd_log_commited_revoke; 590 unsigned int sd_log_commited_revoke;
604 591
605 unsigned int sd_log_num_gl;
606 unsigned int sd_log_num_buf; 592 unsigned int sd_log_num_buf;
607 unsigned int sd_log_num_revoke; 593 unsigned int sd_log_num_revoke;
608 unsigned int sd_log_num_rg; 594 unsigned int sd_log_num_rg;
609 unsigned int sd_log_num_databuf; 595 unsigned int sd_log_num_databuf;
610 596
611 struct list_head sd_log_le_gl;
612 struct list_head sd_log_le_buf; 597 struct list_head sd_log_le_buf;
613 struct list_head sd_log_le_revoke; 598 struct list_head sd_log_le_revoke;
614 struct list_head sd_log_le_rg; 599 struct list_head sd_log_le_rg;
615 struct list_head sd_log_le_databuf; 600 struct list_head sd_log_le_databuf;
616 struct list_head sd_log_le_ordered; 601 struct list_head sd_log_le_ordered;
617 602
618 unsigned int sd_log_blks_free; 603 atomic_t sd_log_blks_free;
619 struct mutex sd_log_reserve_mutex; 604 struct mutex sd_log_reserve_mutex;
620 605
621 u64 sd_log_sequence; 606 u64 sd_log_sequence;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 5f6dc32946cd..728d3169e7bd 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -31,7 +31,6 @@
31#include "log.h" 31#include "log.h"
32#include "meta_io.h" 32#include "meta_io.h"
33#include "ops_address.h" 33#include "ops_address.h"
34#include "ops_file.h"
35#include "ops_inode.h" 34#include "ops_inode.h"
36#include "quota.h" 35#include "quota.h"
37#include "rgrp.h" 36#include "rgrp.h"
@@ -132,15 +131,21 @@ static struct inode *gfs2_iget_skip(struct super_block *sb,
132 131
133void gfs2_set_iop(struct inode *inode) 132void gfs2_set_iop(struct inode *inode)
134{ 133{
134 struct gfs2_sbd *sdp = GFS2_SB(inode);
135 umode_t mode = inode->i_mode; 135 umode_t mode = inode->i_mode;
136 136
137 if (S_ISREG(mode)) { 137 if (S_ISREG(mode)) {
138 inode->i_op = &gfs2_file_iops; 138 inode->i_op = &gfs2_file_iops;
139 inode->i_fop = &gfs2_file_fops; 139 if (sdp->sd_args.ar_localflocks)
140 inode->i_mapping->a_ops = &gfs2_file_aops; 140 inode->i_fop = &gfs2_file_fops_nolock;
141 else
142 inode->i_fop = &gfs2_file_fops;
141 } else if (S_ISDIR(mode)) { 143 } else if (S_ISDIR(mode)) {
142 inode->i_op = &gfs2_dir_iops; 144 inode->i_op = &gfs2_dir_iops;
143 inode->i_fop = &gfs2_dir_fops; 145 if (sdp->sd_args.ar_localflocks)
146 inode->i_fop = &gfs2_dir_fops_nolock;
147 else
148 inode->i_fop = &gfs2_dir_fops;
144 } else if (S_ISLNK(mode)) { 149 } else if (S_ISLNK(mode)) {
145 inode->i_op = &gfs2_symlink_iops; 150 inode->i_op = &gfs2_symlink_iops;
146 } else { 151 } else {
@@ -291,12 +296,10 @@ static int gfs2_dinode_in(struct gfs2_inode *ip, const void *buf)
291 di->di_entries = be32_to_cpu(str->di_entries); 296 di->di_entries = be32_to_cpu(str->di_entries);
292 297
293 di->di_eattr = be64_to_cpu(str->di_eattr); 298 di->di_eattr = be64_to_cpu(str->di_eattr);
294 return 0; 299 if (S_ISREG(ip->i_inode.i_mode))
295} 300 gfs2_set_aops(&ip->i_inode);
296 301
297static void gfs2_inode_bh(struct gfs2_inode *ip, struct buffer_head *bh) 302 return 0;
298{
299 ip->i_cache[0] = bh;
300} 303}
301 304
302/** 305/**
@@ -366,7 +369,8 @@ int gfs2_dinode_dealloc(struct gfs2_inode *ip)
366 if (error) 369 if (error)
367 goto out_rg_gunlock; 370 goto out_rg_gunlock;
368 371
369 gfs2_trans_add_gl(ip->i_gl); 372 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
373 set_bit(GLF_LFLUSH, &ip->i_gl->gl_flags);
370 374
371 gfs2_free_di(rgd, ip); 375 gfs2_free_di(rgd, ip);
372 376
@@ -707,9 +711,10 @@ static int alloc_dinode(struct gfs2_inode *dip, u64 *no_addr, u64 *generation)
707 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 711 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
708 int error; 712 int error;
709 713
710 gfs2_alloc_get(dip); 714 if (gfs2_alloc_get(dip) == NULL)
715 return -ENOMEM;
711 716
712 dip->i_alloc.al_requested = RES_DINODE; 717 dip->i_alloc->al_requested = RES_DINODE;
713 error = gfs2_inplace_reserve(dip); 718 error = gfs2_inplace_reserve(dip);
714 if (error) 719 if (error)
715 goto out; 720 goto out;
@@ -855,7 +860,7 @@ static int link_dinode(struct gfs2_inode *dip, const struct qstr *name,
855 860
856 error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name); 861 error = alloc_required = gfs2_diradd_alloc_required(&dip->i_inode, name);
857 if (alloc_required < 0) 862 if (alloc_required < 0)
858 goto fail; 863 goto fail_quota_locks;
859 if (alloc_required) { 864 if (alloc_required) {
860 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid); 865 error = gfs2_quota_check(dip, dip->i_inode.i_uid, dip->i_inode.i_gid);
861 if (error) 866 if (error)
@@ -896,7 +901,7 @@ fail_end_trans:
896 gfs2_trans_end(sdp); 901 gfs2_trans_end(sdp);
897 902
898fail_ipreserv: 903fail_ipreserv:
899 if (dip->i_alloc.al_rgd) 904 if (dip->i_alloc->al_rgd)
900 gfs2_inplace_release(dip); 905 gfs2_inplace_release(dip);
901 906
902fail_quota_locks: 907fail_quota_locks:
@@ -966,7 +971,7 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
966 struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 }; 971 struct gfs2_inum_host inum = { .no_addr = 0, .no_formal_ino = 0 };
967 int error; 972 int error;
968 u64 generation; 973 u64 generation;
969 struct buffer_head *bh=NULL; 974 struct buffer_head *bh = NULL;
970 975
971 if (!name->len || name->len > GFS2_FNAMESIZE) 976 if (!name->len || name->len > GFS2_FNAMESIZE)
972 return ERR_PTR(-ENAMETOOLONG); 977 return ERR_PTR(-ENAMETOOLONG);
@@ -1003,8 +1008,6 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
1003 if (IS_ERR(inode)) 1008 if (IS_ERR(inode))
1004 goto fail_gunlock2; 1009 goto fail_gunlock2;
1005 1010
1006 gfs2_inode_bh(GFS2_I(inode), bh);
1007
1008 error = gfs2_inode_refresh(GFS2_I(inode)); 1011 error = gfs2_inode_refresh(GFS2_I(inode));
1009 if (error) 1012 if (error)
1010 goto fail_gunlock2; 1013 goto fail_gunlock2;
@@ -1021,6 +1024,8 @@ struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name,
1021 if (error) 1024 if (error)
1022 goto fail_gunlock2; 1025 goto fail_gunlock2;
1023 1026
1027 if (bh)
1028 brelse(bh);
1024 if (!inode) 1029 if (!inode)
1025 return ERR_PTR(-ENOMEM); 1030 return ERR_PTR(-ENOMEM);
1026 return inode; 1031 return inode;
@@ -1032,6 +1037,8 @@ fail_gunlock2:
1032fail_gunlock: 1037fail_gunlock:
1033 gfs2_glock_dq(ghs); 1038 gfs2_glock_dq(ghs);
1034fail: 1039fail:
1040 if (bh)
1041 brelse(bh);
1035 return ERR_PTR(error); 1042 return ERR_PTR(error);
1036} 1043}
1037 1044
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index 351ac87ab384..d44650662615 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -20,6 +20,18 @@ static inline int gfs2_is_jdata(const struct gfs2_inode *ip)
20 return ip->i_di.di_flags & GFS2_DIF_JDATA; 20 return ip->i_di.di_flags & GFS2_DIF_JDATA;
21} 21}
22 22
23static inline int gfs2_is_writeback(const struct gfs2_inode *ip)
24{
25 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
26 return (sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK) && !gfs2_is_jdata(ip);
27}
28
29static inline int gfs2_is_ordered(const struct gfs2_inode *ip)
30{
31 const struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
32 return (sdp->sd_args.ar_data == GFS2_DATA_ORDERED) && !gfs2_is_jdata(ip);
33}
34
23static inline int gfs2_is_dir(const struct gfs2_inode *ip) 35static inline int gfs2_is_dir(const struct gfs2_inode *ip)
24{ 36{
25 return S_ISDIR(ip->i_inode.i_mode); 37 return S_ISDIR(ip->i_inode.i_mode);
diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c
index 41c5b04caaba..f2efff424224 100644
--- a/fs/gfs2/locking/dlm/mount.c
+++ b/fs/gfs2/locking/dlm/mount.c
@@ -67,6 +67,11 @@ static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir)
67 memset(data, 0, 256); 67 memset(data, 0, 256);
68 strncpy(data, data_arg, 255); 68 strncpy(data, data_arg, 255);
69 69
70 if (!strlen(data)) {
71 log_error("no mount options, (u)mount helpers not installed");
72 return -EINVAL;
73 }
74
70 for (options = data; (x = strsep(&options, ":")); ) { 75 for (options = data; (x = strsep(&options, ":")); ) {
71 if (!*x) 76 if (!*x)
72 continue; 77 continue;
diff --git a/fs/gfs2/locking/dlm/plock.c b/fs/gfs2/locking/dlm/plock.c
index 1f7b038530b4..2ebd374b3143 100644
--- a/fs/gfs2/locking/dlm/plock.c
+++ b/fs/gfs2/locking/dlm/plock.c
@@ -89,15 +89,19 @@ int gdlm_plock(void *lockspace, struct lm_lockname *name,
89 op->info.number = name->ln_number; 89 op->info.number = name->ln_number;
90 op->info.start = fl->fl_start; 90 op->info.start = fl->fl_start;
91 op->info.end = fl->fl_end; 91 op->info.end = fl->fl_end;
92 op->info.owner = (__u64)(long) fl->fl_owner;
93 if (fl->fl_lmops && fl->fl_lmops->fl_grant) { 92 if (fl->fl_lmops && fl->fl_lmops->fl_grant) {
93 /* fl_owner is lockd which doesn't distinguish
94 processes on the nfs client */
95 op->info.owner = (__u64) fl->fl_pid;
94 xop->callback = fl->fl_lmops->fl_grant; 96 xop->callback = fl->fl_lmops->fl_grant;
95 locks_init_lock(&xop->flc); 97 locks_init_lock(&xop->flc);
96 locks_copy_lock(&xop->flc, fl); 98 locks_copy_lock(&xop->flc, fl);
97 xop->fl = fl; 99 xop->fl = fl;
98 xop->file = file; 100 xop->file = file;
99 } else 101 } else {
102 op->info.owner = (__u64)(long) fl->fl_owner;
100 xop->callback = NULL; 103 xop->callback = NULL;
104 }
101 105
102 send_op(op); 106 send_op(op);
103 107
@@ -203,7 +207,10 @@ int gdlm_punlock(void *lockspace, struct lm_lockname *name,
203 op->info.number = name->ln_number; 207 op->info.number = name->ln_number;
204 op->info.start = fl->fl_start; 208 op->info.start = fl->fl_start;
205 op->info.end = fl->fl_end; 209 op->info.end = fl->fl_end;
206 op->info.owner = (__u64)(long) fl->fl_owner; 210 if (fl->fl_lmops && fl->fl_lmops->fl_grant)
211 op->info.owner = (__u64) fl->fl_pid;
212 else
213 op->info.owner = (__u64)(long) fl->fl_owner;
207 214
208 send_op(op); 215 send_op(op);
209 wait_event(recv_wq, (op->done != 0)); 216 wait_event(recv_wq, (op->done != 0));
@@ -242,7 +249,10 @@ int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
242 op->info.number = name->ln_number; 249 op->info.number = name->ln_number;
243 op->info.start = fl->fl_start; 250 op->info.start = fl->fl_start;
244 op->info.end = fl->fl_end; 251 op->info.end = fl->fl_end;
245 op->info.owner = (__u64)(long) fl->fl_owner; 252 if (fl->fl_lmops && fl->fl_lmops->fl_grant)
253 op->info.owner = (__u64) fl->fl_pid;
254 else
255 op->info.owner = (__u64)(long) fl->fl_owner;
246 256
247 send_op(op); 257 send_op(op);
248 wait_event(recv_wq, (op->done != 0)); 258 wait_event(recv_wq, (op->done != 0));
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
index ae9e6a25fe2b..a87b09839761 100644
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ b/fs/gfs2/locking/dlm/sysfs.c
@@ -189,51 +189,39 @@ static struct kobj_type gdlm_ktype = {
189 .sysfs_ops = &gdlm_attr_ops, 189 .sysfs_ops = &gdlm_attr_ops,
190}; 190};
191 191
192static struct kset gdlm_kset = { 192static struct kset *gdlm_kset;
193 .ktype = &gdlm_ktype,
194};
195 193
196int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj) 194int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
197{ 195{
198 int error; 196 int error;
199 197
200 error = kobject_set_name(&ls->kobj, "%s", "lock_module"); 198 ls->kobj.kset = gdlm_kset;
201 if (error) { 199 error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj,
202 log_error("can't set kobj name %d", error); 200 "lock_module");
203 return error;
204 }
205
206 ls->kobj.kset = &gdlm_kset;
207 ls->kobj.ktype = &gdlm_ktype;
208 ls->kobj.parent = fskobj;
209
210 error = kobject_register(&ls->kobj);
211 if (error) 201 if (error)
212 log_error("can't register kobj %d", error); 202 log_error("can't register kobj %d", error);
203 kobject_uevent(&ls->kobj, KOBJ_ADD);
213 204
214 return error; 205 return error;
215} 206}
216 207
217void gdlm_kobject_release(struct gdlm_ls *ls) 208void gdlm_kobject_release(struct gdlm_ls *ls)
218{ 209{
219 kobject_unregister(&ls->kobj); 210 kobject_put(&ls->kobj);
220} 211}
221 212
222int gdlm_sysfs_init(void) 213int gdlm_sysfs_init(void)
223{ 214{
224 int error; 215 gdlm_kset = kset_create_and_add("lock_dlm", NULL, kernel_kobj);
225 216 if (!gdlm_kset) {
226 kobject_set_name(&gdlm_kset.kobj, "lock_dlm"); 217 printk(KERN_WARNING "%s: can not create kset\n", __FUNCTION__);
227 kobj_set_kset_s(&gdlm_kset, kernel_subsys); 218 return -ENOMEM;
228 error = kset_register(&gdlm_kset); 219 }
229 if (error) 220 return 0;
230 printk("lock_dlm: cannot register kset %d\n", error);
231
232 return error;
233} 221}
234 222
235void gdlm_sysfs_exit(void) 223void gdlm_sysfs_exit(void)
236{ 224{
237 kset_unregister(&gdlm_kset); 225 kset_unregister(gdlm_kset);
238} 226}
239 227
diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c
index bd938f06481d..521694fc19d6 100644
--- a/fs/gfs2/locking/dlm/thread.c
+++ b/fs/gfs2/locking/dlm/thread.c
@@ -273,18 +273,13 @@ static int gdlm_thread(void *data, int blist)
273 struct gdlm_ls *ls = (struct gdlm_ls *) data; 273 struct gdlm_ls *ls = (struct gdlm_ls *) data;
274 struct gdlm_lock *lp = NULL; 274 struct gdlm_lock *lp = NULL;
275 uint8_t complete, blocking, submit, drop; 275 uint8_t complete, blocking, submit, drop;
276 DECLARE_WAITQUEUE(wait, current);
277 276
278 /* Only thread1 is allowed to do blocking callbacks since gfs 277 /* Only thread1 is allowed to do blocking callbacks since gfs
279 may wait for a completion callback within a blocking cb. */ 278 may wait for a completion callback within a blocking cb. */
280 279
281 while (!kthread_should_stop()) { 280 while (!kthread_should_stop()) {
282 set_current_state(TASK_INTERRUPTIBLE); 281 wait_event_interruptible(ls->thread_wait,
283 add_wait_queue(&ls->thread_wait, &wait); 282 !no_work(ls, blist) || kthread_should_stop());
284 if (no_work(ls, blist))
285 schedule();
286 remove_wait_queue(&ls->thread_wait, &wait);
287 set_current_state(TASK_RUNNING);
288 283
289 complete = blocking = submit = drop = 0; 284 complete = blocking = submit = drop = 0;
290 285
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 7df702473252..161ab6f2058e 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -16,6 +16,8 @@
16#include <linux/crc32.h> 16#include <linux/crc32.h>
17#include <linux/lm_interface.h> 17#include <linux/lm_interface.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/kthread.h>
20#include <linux/freezer.h>
19 21
20#include "gfs2.h" 22#include "gfs2.h"
21#include "incore.h" 23#include "incore.h"
@@ -68,14 +70,12 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
68 * 70 *
69 */ 71 */
70 72
71void gfs2_remove_from_ail(struct address_space *mapping, struct gfs2_bufdata *bd) 73void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
72{ 74{
73 bd->bd_ail = NULL; 75 bd->bd_ail = NULL;
74 list_del_init(&bd->bd_ail_st_list); 76 list_del_init(&bd->bd_ail_st_list);
75 list_del_init(&bd->bd_ail_gl_list); 77 list_del_init(&bd->bd_ail_gl_list);
76 atomic_dec(&bd->bd_gl->gl_ail_count); 78 atomic_dec(&bd->bd_gl->gl_ail_count);
77 if (mapping)
78 gfs2_meta_cache_flush(GFS2_I(mapping->host));
79 brelse(bd->bd_bh); 79 brelse(bd->bd_bh);
80} 80}
81 81
@@ -92,8 +92,6 @@ static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
92 struct buffer_head *bh; 92 struct buffer_head *bh;
93 int retry; 93 int retry;
94 94
95 BUG_ON(!spin_is_locked(&sdp->sd_log_lock));
96
97 do { 95 do {
98 retry = 0; 96 retry = 0;
99 97
@@ -210,7 +208,7 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp, int flags)
210 gfs2_log_unlock(sdp); 208 gfs2_log_unlock(sdp);
211} 209}
212 210
213int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) 211static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
214{ 212{
215 struct gfs2_ail *ai, *s; 213 struct gfs2_ail *ai, *s;
216 int ret; 214 int ret;
@@ -248,7 +246,7 @@ static void gfs2_ail2_empty_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
248 bd = list_entry(head->prev, struct gfs2_bufdata, 246 bd = list_entry(head->prev, struct gfs2_bufdata,
249 bd_ail_st_list); 247 bd_ail_st_list);
250 gfs2_assert(sdp, bd->bd_ail == ai); 248 gfs2_assert(sdp, bd->bd_ail == ai);
251 gfs2_remove_from_ail(bd->bd_bh->b_page->mapping, bd); 249 gfs2_remove_from_ail(bd);
252 } 250 }
253} 251}
254 252
@@ -303,7 +301,7 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
303 301
304 mutex_lock(&sdp->sd_log_reserve_mutex); 302 mutex_lock(&sdp->sd_log_reserve_mutex);
305 gfs2_log_lock(sdp); 303 gfs2_log_lock(sdp);
306 while(sdp->sd_log_blks_free <= (blks + reserved_blks)) { 304 while(atomic_read(&sdp->sd_log_blks_free) <= (blks + reserved_blks)) {
307 gfs2_log_unlock(sdp); 305 gfs2_log_unlock(sdp);
308 gfs2_ail1_empty(sdp, 0); 306 gfs2_ail1_empty(sdp, 0);
309 gfs2_log_flush(sdp, NULL); 307 gfs2_log_flush(sdp, NULL);
@@ -312,7 +310,7 @@ int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks)
312 gfs2_ail1_start(sdp, 0); 310 gfs2_ail1_start(sdp, 0);
313 gfs2_log_lock(sdp); 311 gfs2_log_lock(sdp);
314 } 312 }
315 sdp->sd_log_blks_free -= blks; 313 atomic_sub(blks, &sdp->sd_log_blks_free);
316 gfs2_log_unlock(sdp); 314 gfs2_log_unlock(sdp);
317 mutex_unlock(&sdp->sd_log_reserve_mutex); 315 mutex_unlock(&sdp->sd_log_reserve_mutex);
318 316
@@ -332,27 +330,23 @@ void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks)
332{ 330{
333 331
334 gfs2_log_lock(sdp); 332 gfs2_log_lock(sdp);
335 sdp->sd_log_blks_free += blks; 333 atomic_add(blks, &sdp->sd_log_blks_free);
336 gfs2_assert_withdraw(sdp, 334 gfs2_assert_withdraw(sdp,
337 sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); 335 atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
338 gfs2_log_unlock(sdp); 336 gfs2_log_unlock(sdp);
339 up_read(&sdp->sd_log_flush_lock); 337 up_read(&sdp->sd_log_flush_lock);
340} 338}
341 339
342static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn) 340static u64 log_bmap(struct gfs2_sbd *sdp, unsigned int lbn)
343{ 341{
344 struct inode *inode = sdp->sd_jdesc->jd_inode; 342 struct gfs2_journal_extent *je;
345 int error; 343
346 struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 }; 344 list_for_each_entry(je, &sdp->sd_jdesc->extent_list, extent_list) {
347 345 if (lbn >= je->lblock && lbn < je->lblock + je->blocks)
348 bh_map.b_size = 1 << inode->i_blkbits; 346 return je->dblock + lbn - je->lblock;
349 error = gfs2_block_map(inode, lbn, 0, &bh_map); 347 }
350 if (error || !bh_map.b_blocknr) 348
351 printk(KERN_INFO "error=%d, dbn=%llu lbn=%u", error, 349 return -1;
352 (unsigned long long)bh_map.b_blocknr, lbn);
353 gfs2_assert_withdraw(sdp, !error && bh_map.b_blocknr);
354
355 return bh_map.b_blocknr;
356} 350}
357 351
358/** 352/**
@@ -561,8 +555,8 @@ static void log_pull_tail(struct gfs2_sbd *sdp, unsigned int new_tail)
561 ail2_empty(sdp, new_tail); 555 ail2_empty(sdp, new_tail);
562 556
563 gfs2_log_lock(sdp); 557 gfs2_log_lock(sdp);
564 sdp->sd_log_blks_free += dist; 558 atomic_add(dist, &sdp->sd_log_blks_free);
565 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <= sdp->sd_jdesc->jd_blocks); 559 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= sdp->sd_jdesc->jd_blocks);
566 gfs2_log_unlock(sdp); 560 gfs2_log_unlock(sdp);
567 561
568 sdp->sd_log_tail = new_tail; 562 sdp->sd_log_tail = new_tail;
@@ -652,7 +646,7 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
652 get_bh(bh); 646 get_bh(bh);
653 gfs2_log_unlock(sdp); 647 gfs2_log_unlock(sdp);
654 lock_buffer(bh); 648 lock_buffer(bh);
655 if (test_clear_buffer_dirty(bh)) { 649 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) {
656 bh->b_end_io = end_buffer_write_sync; 650 bh->b_end_io = end_buffer_write_sync;
657 submit_bh(WRITE, bh); 651 submit_bh(WRITE, bh);
658 } else { 652 } else {
@@ -694,20 +688,16 @@ static void gfs2_ordered_wait(struct gfs2_sbd *sdp)
694 * 688 *
695 */ 689 */
696 690
697void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) 691void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
698{ 692{
699 struct gfs2_ail *ai; 693 struct gfs2_ail *ai;
700 694
701 down_write(&sdp->sd_log_flush_lock); 695 down_write(&sdp->sd_log_flush_lock);
702 696
703 if (gl) { 697 /* Log might have been flushed while we waited for the flush lock */
704 gfs2_log_lock(sdp); 698 if (gl && !test_bit(GLF_LFLUSH, &gl->gl_flags)) {
705 if (list_empty(&gl->gl_le.le_list)) { 699 up_write(&sdp->sd_log_flush_lock);
706 gfs2_log_unlock(sdp); 700 return;
707 up_write(&sdp->sd_log_flush_lock);
708 return;
709 }
710 gfs2_log_unlock(sdp);
711 } 701 }
712 702
713 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL); 703 ai = kzalloc(sizeof(struct gfs2_ail), GFP_NOFS | __GFP_NOFAIL);
@@ -739,7 +729,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
739 log_flush_commit(sdp); 729 log_flush_commit(sdp);
740 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){ 730 else if (sdp->sd_log_tail != current_tail(sdp) && !sdp->sd_log_idle){
741 gfs2_log_lock(sdp); 731 gfs2_log_lock(sdp);
742 sdp->sd_log_blks_free--; /* Adjust for unreserved buffer */ 732 atomic_dec(&sdp->sd_log_blks_free); /* Adjust for unreserved buffer */
743 gfs2_log_unlock(sdp); 733 gfs2_log_unlock(sdp);
744 log_write_header(sdp, 0, PULL); 734 log_write_header(sdp, 0, PULL);
745 } 735 }
@@ -767,7 +757,7 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
767static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 757static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
768{ 758{
769 unsigned int reserved; 759 unsigned int reserved;
770 unsigned int old; 760 unsigned int unused;
771 761
772 gfs2_log_lock(sdp); 762 gfs2_log_lock(sdp);
773 763
@@ -779,14 +769,11 @@ static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr)
779 sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm; 769 sdp->sd_log_commited_revoke += tr->tr_num_revoke - tr->tr_num_revoke_rm;
780 gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0); 770 gfs2_assert_withdraw(sdp, ((int)sdp->sd_log_commited_revoke) >= 0);
781 reserved = calc_reserved(sdp); 771 reserved = calc_reserved(sdp);
782 old = sdp->sd_log_blks_free; 772 unused = sdp->sd_log_blks_reserved - reserved + tr->tr_reserved;
783 sdp->sd_log_blks_free += tr->tr_reserved - 773 gfs2_assert_withdraw(sdp, unused >= 0);
784 (reserved - sdp->sd_log_blks_reserved); 774 atomic_add(unused, &sdp->sd_log_blks_free);
785 775 gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <=
786 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free >= old);
787 gfs2_assert_withdraw(sdp, sdp->sd_log_blks_free <=
788 sdp->sd_jdesc->jd_blocks); 776 sdp->sd_jdesc->jd_blocks);
789
790 sdp->sd_log_blks_reserved = reserved; 777 sdp->sd_log_blks_reserved = reserved;
791 778
792 gfs2_log_unlock(sdp); 779 gfs2_log_unlock(sdp);
@@ -825,7 +812,6 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp)
825 down_write(&sdp->sd_log_flush_lock); 812 down_write(&sdp->sd_log_flush_lock);
826 813
827 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); 814 gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved);
828 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_gl);
829 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf); 815 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_buf);
830 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); 816 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
831 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg); 817 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_rg);
@@ -838,7 +824,7 @@ void gfs2_log_shutdown(struct gfs2_sbd *sdp)
838 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT, 824 log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT,
839 (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL); 825 (sdp->sd_log_tail == current_tail(sdp)) ? 0 : PULL);
840 826
841 gfs2_assert_warn(sdp, sdp->sd_log_blks_free == sdp->sd_jdesc->jd_blocks); 827 gfs2_assert_warn(sdp, atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks);
842 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); 828 gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail);
843 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); 829 gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list));
844 830
@@ -866,3 +852,42 @@ void gfs2_meta_syncfs(struct gfs2_sbd *sdp)
866 } 852 }
867} 853}
868 854
855
856/**
857 * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks
858 * @sdp: Pointer to GFS2 superblock
859 *
860 * Also, periodically check to make sure that we're using the most recent
861 * journal index.
862 */
863
864int gfs2_logd(void *data)
865{
866 struct gfs2_sbd *sdp = data;
867 unsigned long t;
868 int need_flush;
869
870 while (!kthread_should_stop()) {
871 /* Advance the log tail */
872
873 t = sdp->sd_log_flush_time +
874 gfs2_tune_get(sdp, gt_log_flush_secs) * HZ;
875
876 gfs2_ail1_empty(sdp, DIO_ALL);
877 gfs2_log_lock(sdp);
878 need_flush = sdp->sd_log_num_buf > gfs2_tune_get(sdp, gt_incore_log_blocks);
879 gfs2_log_unlock(sdp);
880 if (need_flush || time_after_eq(jiffies, t)) {
881 gfs2_log_flush(sdp, NULL);
882 sdp->sd_log_flush_time = jiffies;
883 }
884
885 t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
886 if (freezing(current))
887 refrigerator();
888 schedule_timeout_interruptible(t);
889 }
890
891 return 0;
892}
893
diff --git a/fs/gfs2/log.h b/fs/gfs2/log.h
index dae282400627..771152816508 100644
--- a/fs/gfs2/log.h
+++ b/fs/gfs2/log.h
@@ -48,8 +48,6 @@ static inline void gfs2_log_pointers_init(struct gfs2_sbd *sdp,
48unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, 48unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
49 unsigned int ssize); 49 unsigned int ssize);
50 50
51int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags);
52
53int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks); 51int gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks);
54void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks); 52void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks);
55void gfs2_log_incr_head(struct gfs2_sbd *sdp); 53void gfs2_log_incr_head(struct gfs2_sbd *sdp);
@@ -57,11 +55,19 @@ void gfs2_log_incr_head(struct gfs2_sbd *sdp);
57struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp); 55struct buffer_head *gfs2_log_get_buf(struct gfs2_sbd *sdp);
58struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp, 56struct buffer_head *gfs2_log_fake_buf(struct gfs2_sbd *sdp,
59 struct buffer_head *real); 57 struct buffer_head *real);
60void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl); 58void __gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl);
59
60static inline void gfs2_log_flush(struct gfs2_sbd *sbd, struct gfs2_glock *gl)
61{
62 if (!gl || test_bit(GLF_LFLUSH, &gl->gl_flags))
63 __gfs2_log_flush(sbd, gl);
64}
65
61void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans); 66void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *trans);
62void gfs2_remove_from_ail(struct address_space *mapping, struct gfs2_bufdata *bd); 67void gfs2_remove_from_ail(struct gfs2_bufdata *bd);
63 68
64void gfs2_log_shutdown(struct gfs2_sbd *sdp); 69void gfs2_log_shutdown(struct gfs2_sbd *sdp);
65void gfs2_meta_syncfs(struct gfs2_sbd *sdp); 70void gfs2_meta_syncfs(struct gfs2_sbd *sdp);
71int gfs2_logd(void *data);
66 72
67#endif /* __LOG_DOT_H__ */ 73#endif /* __LOG_DOT_H__ */
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 6c27cea761c6..fae59d69d01a 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -87,6 +87,7 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
87 } 87 }
88 bd->bd_ail = ai; 88 bd->bd_ail = ai;
89 list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list); 89 list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list);
90 clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
90 gfs2_log_unlock(sdp); 91 gfs2_log_unlock(sdp);
91 unlock_buffer(bh); 92 unlock_buffer(bh);
92} 93}
@@ -124,49 +125,6 @@ static struct buffer_head *gfs2_get_log_desc(struct gfs2_sbd *sdp, u32 ld_type)
124 return bh; 125 return bh;
125} 126}
126 127
127static void __glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
128{
129 struct gfs2_glock *gl;
130 struct gfs2_trans *tr = current->journal_info;
131
132 tr->tr_touched = 1;
133
134 gl = container_of(le, struct gfs2_glock, gl_le);
135 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl)))
136 return;
137
138 if (!list_empty(&le->le_list))
139 return;
140
141 gfs2_glock_hold(gl);
142 set_bit(GLF_DIRTY, &gl->gl_flags);
143 sdp->sd_log_num_gl++;
144 list_add(&le->le_list, &sdp->sd_log_le_gl);
145}
146
147static void glock_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
148{
149 gfs2_log_lock(sdp);
150 __glock_lo_add(sdp, le);
151 gfs2_log_unlock(sdp);
152}
153
154static void glock_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
155{
156 struct list_head *head = &sdp->sd_log_le_gl;
157 struct gfs2_glock *gl;
158
159 while (!list_empty(head)) {
160 gl = list_entry(head->next, struct gfs2_glock, gl_le.le_list);
161 list_del_init(&gl->gl_le.le_list);
162 sdp->sd_log_num_gl--;
163
164 gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(gl));
165 gfs2_glock_put(gl);
166 }
167 gfs2_assert_warn(sdp, !sdp->sd_log_num_gl);
168}
169
170static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le) 128static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
171{ 129{
172 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le); 130 struct gfs2_bufdata *bd = container_of(le, struct gfs2_bufdata, bd_le);
@@ -182,7 +140,8 @@ static void buf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
182 list_add(&bd->bd_list_tr, &tr->tr_list_buf); 140 list_add(&bd->bd_list_tr, &tr->tr_list_buf);
183 if (!list_empty(&le->le_list)) 141 if (!list_empty(&le->le_list))
184 goto out; 142 goto out;
185 __glock_lo_add(sdp, &bd->bd_gl->gl_le); 143 set_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
144 set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
186 gfs2_meta_check(sdp, bd->bd_bh); 145 gfs2_meta_check(sdp, bd->bd_bh);
187 gfs2_pin(sdp, bd->bd_bh); 146 gfs2_pin(sdp, bd->bd_bh);
188 sdp->sd_log_num_buf++; 147 sdp->sd_log_num_buf++;
@@ -556,17 +515,20 @@ static void databuf_lo_add(struct gfs2_sbd *sdp, struct gfs2_log_element *le)
556 515
557 lock_buffer(bd->bd_bh); 516 lock_buffer(bd->bd_bh);
558 gfs2_log_lock(sdp); 517 gfs2_log_lock(sdp);
559 if (!list_empty(&bd->bd_list_tr)) 518 if (tr) {
560 goto out; 519 if (!list_empty(&bd->bd_list_tr))
561 tr->tr_touched = 1; 520 goto out;
562 if (gfs2_is_jdata(ip)) { 521 tr->tr_touched = 1;
563 tr->tr_num_buf++; 522 if (gfs2_is_jdata(ip)) {
564 list_add(&bd->bd_list_tr, &tr->tr_list_buf); 523 tr->tr_num_buf++;
524 list_add(&bd->bd_list_tr, &tr->tr_list_buf);
525 }
565 } 526 }
566 if (!list_empty(&le->le_list)) 527 if (!list_empty(&le->le_list))
567 goto out; 528 goto out;
568 529
569 __glock_lo_add(sdp, &bd->bd_gl->gl_le); 530 set_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags);
531 set_bit(GLF_DIRTY, &bd->bd_gl->gl_flags);
570 if (gfs2_is_jdata(ip)) { 532 if (gfs2_is_jdata(ip)) {
571 gfs2_pin(sdp, bd->bd_bh); 533 gfs2_pin(sdp, bd->bd_bh);
572 tr->tr_num_databuf_new++; 534 tr->tr_num_databuf_new++;
@@ -773,12 +735,6 @@ static void databuf_lo_after_commit(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
773} 735}
774 736
775 737
776const struct gfs2_log_operations gfs2_glock_lops = {
777 .lo_add = glock_lo_add,
778 .lo_after_commit = glock_lo_after_commit,
779 .lo_name = "glock",
780};
781
782const struct gfs2_log_operations gfs2_buf_lops = { 738const struct gfs2_log_operations gfs2_buf_lops = {
783 .lo_add = buf_lo_add, 739 .lo_add = buf_lo_add,
784 .lo_incore_commit = buf_lo_incore_commit, 740 .lo_incore_commit = buf_lo_incore_commit,
@@ -816,7 +772,6 @@ const struct gfs2_log_operations gfs2_databuf_lops = {
816}; 772};
817 773
818const struct gfs2_log_operations *gfs2_log_ops[] = { 774const struct gfs2_log_operations *gfs2_log_ops[] = {
819 &gfs2_glock_lops,
820 &gfs2_databuf_lops, 775 &gfs2_databuf_lops,
821 &gfs2_buf_lops, 776 &gfs2_buf_lops,
822 &gfs2_rg_lops, 777 &gfs2_rg_lops,
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 7ecfe0d3a491..9c7765c12d62 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -29,9 +29,8 @@ static void gfs2_init_inode_once(struct kmem_cache *cachep, void *foo)
29 struct gfs2_inode *ip = foo; 29 struct gfs2_inode *ip = foo;
30 30
31 inode_init_once(&ip->i_inode); 31 inode_init_once(&ip->i_inode);
32 spin_lock_init(&ip->i_spin);
33 init_rwsem(&ip->i_rw_mutex); 32 init_rwsem(&ip->i_rw_mutex);
34 memset(ip->i_cache, 0, sizeof(ip->i_cache)); 33 ip->i_alloc = NULL;
35} 34}
36 35
37static void gfs2_init_glock_once(struct kmem_cache *cachep, void *foo) 36static void gfs2_init_glock_once(struct kmem_cache *cachep, void *foo)
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 4da423985e4f..85aea27b4a86 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -50,6 +50,7 @@ static int gfs2_aspace_writepage(struct page *page,
50static const struct address_space_operations aspace_aops = { 50static const struct address_space_operations aspace_aops = {
51 .writepage = gfs2_aspace_writepage, 51 .writepage = gfs2_aspace_writepage,
52 .releasepage = gfs2_releasepage, 52 .releasepage = gfs2_releasepage,
53 .sync_page = block_sync_page,
53}; 54};
54 55
55/** 56/**
@@ -221,13 +222,14 @@ int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,
221 struct buffer_head **bhp) 222 struct buffer_head **bhp)
222{ 223{
223 *bhp = getbuf(gl, blkno, CREATE); 224 *bhp = getbuf(gl, blkno, CREATE);
224 if (!buffer_uptodate(*bhp)) 225 if (!buffer_uptodate(*bhp)) {
225 ll_rw_block(READ_META, 1, bhp); 226 ll_rw_block(READ_META, 1, bhp);
226 if (flags & DIO_WAIT) { 227 if (flags & DIO_WAIT) {
227 int error = gfs2_meta_wait(gl->gl_sbd, *bhp); 228 int error = gfs2_meta_wait(gl->gl_sbd, *bhp);
228 if (error) { 229 if (error) {
229 brelse(*bhp); 230 brelse(*bhp);
230 return error; 231 return error;
232 }
231 } 233 }
232 } 234 }
233 235
@@ -282,7 +284,7 @@ void gfs2_attach_bufdata(struct gfs2_glock *gl, struct buffer_head *bh,
282 return; 284 return;
283 } 285 }
284 286
285 bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL), 287 bd = kmem_cache_zalloc(gfs2_bufdata_cachep, GFP_NOFS | __GFP_NOFAIL);
286 bd->bd_bh = bh; 288 bd->bd_bh = bh;
287 bd->bd_gl = gl; 289 bd->bd_gl = gl;
288 290
@@ -317,7 +319,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
317 } 319 }
318 if (bd) { 320 if (bd) {
319 if (bd->bd_ail) { 321 if (bd->bd_ail) {
320 gfs2_remove_from_ail(NULL, bd); 322 gfs2_remove_from_ail(bd);
321 bh->b_private = NULL; 323 bh->b_private = NULL;
322 bd->bd_bh = NULL; 324 bd->bd_bh = NULL;
323 bd->bd_blkno = bh->b_blocknr; 325 bd->bd_blkno = bh->b_blocknr;
@@ -358,32 +360,6 @@ void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen)
358} 360}
359 361
360/** 362/**
361 * gfs2_meta_cache_flush - get rid of any references on buffers for this inode
362 * @ip: The GFS2 inode
363 *
364 * This releases buffers that are in the most-recently-used array of
365 * blocks used for indirect block addressing for this inode.
366 */
367
368void gfs2_meta_cache_flush(struct gfs2_inode *ip)
369{
370 struct buffer_head **bh_slot;
371 unsigned int x;
372
373 spin_lock(&ip->i_spin);
374
375 for (x = 0; x < GFS2_MAX_META_HEIGHT; x++) {
376 bh_slot = &ip->i_cache[x];
377 if (*bh_slot) {
378 brelse(*bh_slot);
379 *bh_slot = NULL;
380 }
381 }
382
383 spin_unlock(&ip->i_spin);
384}
385
386/**
387 * gfs2_meta_indirect_buffer - Get a metadata buffer 363 * gfs2_meta_indirect_buffer - Get a metadata buffer
388 * @ip: The GFS2 inode 364 * @ip: The GFS2 inode
389 * @height: The level of this buf in the metadata (indir addr) tree (if any) 365 * @height: The level of this buf in the metadata (indir addr) tree (if any)
@@ -391,8 +367,6 @@ void gfs2_meta_cache_flush(struct gfs2_inode *ip)
391 * @new: Non-zero if we may create a new buffer 367 * @new: Non-zero if we may create a new buffer
392 * @bhp: the buffer is returned here 368 * @bhp: the buffer is returned here
393 * 369 *
394 * Try to use the gfs2_inode's MRU metadata tree cache.
395 *
396 * Returns: errno 370 * Returns: errno
397 */ 371 */
398 372
@@ -401,58 +375,25 @@ int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
401{ 375{
402 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 376 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
403 struct gfs2_glock *gl = ip->i_gl; 377 struct gfs2_glock *gl = ip->i_gl;
404 struct buffer_head *bh = NULL, **bh_slot = ip->i_cache + height; 378 struct buffer_head *bh;
405 int in_cache = 0; 379 int ret = 0;
406
407 BUG_ON(!gl);
408 BUG_ON(!sdp);
409
410 spin_lock(&ip->i_spin);
411 if (*bh_slot && (*bh_slot)->b_blocknr == num) {
412 bh = *bh_slot;
413 get_bh(bh);
414 in_cache = 1;
415 }
416 spin_unlock(&ip->i_spin);
417
418 if (!bh)
419 bh = getbuf(gl, num, CREATE);
420
421 if (!bh)
422 return -ENOBUFS;
423 380
424 if (new) { 381 if (new) {
425 if (gfs2_assert_warn(sdp, height)) 382 BUG_ON(height == 0);
426 goto err; 383 bh = gfs2_meta_new(gl, num);
427 meta_prep_new(bh);
428 gfs2_trans_add_bh(ip->i_gl, bh, 1); 384 gfs2_trans_add_bh(ip->i_gl, bh, 1);
429 gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN); 385 gfs2_metatype_set(bh, GFS2_METATYPE_IN, GFS2_FORMAT_IN);
430 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header)); 386 gfs2_buffer_clear_tail(bh, sizeof(struct gfs2_meta_header));
431 } else { 387 } else {
432 u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI; 388 u32 mtype = height ? GFS2_METATYPE_IN : GFS2_METATYPE_DI;
433 if (!buffer_uptodate(bh)) { 389 ret = gfs2_meta_read(gl, num, DIO_WAIT, &bh);
434 ll_rw_block(READ_META, 1, &bh); 390 if (ret == 0 && gfs2_metatype_check(sdp, bh, mtype)) {
435 if (gfs2_meta_wait(sdp, bh)) 391 brelse(bh);
436 goto err; 392 ret = -EIO;
437 } 393 }
438 if (gfs2_metatype_check(sdp, bh, mtype))
439 goto err;
440 }
441
442 if (!in_cache) {
443 spin_lock(&ip->i_spin);
444 if (*bh_slot)
445 brelse(*bh_slot);
446 *bh_slot = bh;
447 get_bh(bh);
448 spin_unlock(&ip->i_spin);
449 } 394 }
450
451 *bhp = bh; 395 *bhp = bh;
452 return 0; 396 return ret;
453err:
454 brelse(bh);
455 return -EIO;
456} 397}
457 398
458/** 399/**
diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h
index b7048222ebb4..73e3b1c76fe1 100644
--- a/fs/gfs2/meta_io.h
+++ b/fs/gfs2/meta_io.h
@@ -56,7 +56,6 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr,
56 56
57void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen); 57void gfs2_meta_wipe(struct gfs2_inode *ip, u64 bstart, u32 blen);
58 58
59void gfs2_meta_cache_flush(struct gfs2_inode *ip);
60int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num, 59int gfs2_meta_indirect_buffer(struct gfs2_inode *ip, int height, u64 num,
61 int new, struct buffer_head **bhp); 60 int new, struct buffer_head **bhp);
62 61
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index 9679f8b9870d..38dbe99a30ed 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -20,6 +20,8 @@
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> 22#include <linux/lm_interface.h>
23#include <linux/backing-dev.h>
24#include <linux/pagevec.h>
23 25
24#include "gfs2.h" 26#include "gfs2.h"
25#include "incore.h" 27#include "incore.h"
@@ -32,7 +34,6 @@
32#include "quota.h" 34#include "quota.h"
33#include "trans.h" 35#include "trans.h"
34#include "rgrp.h" 36#include "rgrp.h"
35#include "ops_file.h"
36#include "super.h" 37#include "super.h"
37#include "util.h" 38#include "util.h"
38#include "glops.h" 39#include "glops.h"
@@ -58,22 +59,6 @@ static void gfs2_page_add_databufs(struct gfs2_inode *ip, struct page *page,
58} 59}
59 60
60/** 61/**
61 * gfs2_get_block - Fills in a buffer head with details about a block
62 * @inode: The inode
63 * @lblock: The block number to look up
64 * @bh_result: The buffer head to return the result in
65 * @create: Non-zero if we may add block to the file
66 *
67 * Returns: errno
68 */
69
70int gfs2_get_block(struct inode *inode, sector_t lblock,
71 struct buffer_head *bh_result, int create)
72{
73 return gfs2_block_map(inode, lblock, create, bh_result);
74}
75
76/**
77 * gfs2_get_block_noalloc - Fills in a buffer head with details about a block 62 * gfs2_get_block_noalloc - Fills in a buffer head with details about a block
78 * @inode: The inode 63 * @inode: The inode
79 * @lblock: The block number to look up 64 * @lblock: The block number to look up
@@ -88,7 +73,7 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
88{ 73{
89 int error; 74 int error;
90 75
91 error = gfs2_block_map(inode, lblock, 0, bh_result); 76 error = gfs2_block_map(inode, lblock, bh_result, 0);
92 if (error) 77 if (error)
93 return error; 78 return error;
94 if (!buffer_mapped(bh_result)) 79 if (!buffer_mapped(bh_result))
@@ -99,20 +84,19 @@ static int gfs2_get_block_noalloc(struct inode *inode, sector_t lblock,
99static int gfs2_get_block_direct(struct inode *inode, sector_t lblock, 84static int gfs2_get_block_direct(struct inode *inode, sector_t lblock,
100 struct buffer_head *bh_result, int create) 85 struct buffer_head *bh_result, int create)
101{ 86{
102 return gfs2_block_map(inode, lblock, 0, bh_result); 87 return gfs2_block_map(inode, lblock, bh_result, 0);
103} 88}
104 89
105/** 90/**
106 * gfs2_writepage - Write complete page 91 * gfs2_writepage_common - Common bits of writepage
107 * @page: Page to write 92 * @page: The page to be written
93 * @wbc: The writeback control
108 * 94 *
109 * Returns: errno 95 * Returns: 1 if writepage is ok, otherwise an error code or zero if no error.
110 *
111 * Some of this is copied from block_write_full_page() although we still
112 * call it to do most of the work.
113 */ 96 */
114 97
115static int gfs2_writepage(struct page *page, struct writeback_control *wbc) 98static int gfs2_writepage_common(struct page *page,
99 struct writeback_control *wbc)
116{ 100{
117 struct inode *inode = page->mapping->host; 101 struct inode *inode = page->mapping->host;
118 struct gfs2_inode *ip = GFS2_I(inode); 102 struct gfs2_inode *ip = GFS2_I(inode);
@@ -120,41 +104,133 @@ static int gfs2_writepage(struct page *page, struct writeback_control *wbc)
120 loff_t i_size = i_size_read(inode); 104 loff_t i_size = i_size_read(inode);
121 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT; 105 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
122 unsigned offset; 106 unsigned offset;
123 int error; 107 int ret = -EIO;
124 int done_trans = 0;
125 108
126 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl))) { 109 if (gfs2_assert_withdraw(sdp, gfs2_glock_is_held_excl(ip->i_gl)))
127 unlock_page(page); 110 goto out;
128 return -EIO; 111 ret = 0;
129 }
130 if (current->journal_info) 112 if (current->journal_info)
131 goto out_ignore; 113 goto redirty;
132
133 /* Is the page fully outside i_size? (truncate in progress) */ 114 /* Is the page fully outside i_size? (truncate in progress) */
134 offset = i_size & (PAGE_CACHE_SIZE-1); 115 offset = i_size & (PAGE_CACHE_SIZE-1);
135 if (page->index > end_index || (page->index == end_index && !offset)) { 116 if (page->index > end_index || (page->index == end_index && !offset)) {
136 page->mapping->a_ops->invalidatepage(page, 0); 117 page->mapping->a_ops->invalidatepage(page, 0);
137 unlock_page(page); 118 goto out;
138 return 0; /* don't care */ 119 }
120 return 1;
121redirty:
122 redirty_page_for_writepage(wbc, page);
123out:
124 unlock_page(page);
125 return 0;
126}
127
128/**
129 * gfs2_writeback_writepage - Write page for writeback mappings
130 * @page: The page
131 * @wbc: The writeback control
132 *
133 */
134
135static int gfs2_writeback_writepage(struct page *page,
136 struct writeback_control *wbc)
137{
138 int ret;
139
140 ret = gfs2_writepage_common(page, wbc);
141 if (ret <= 0)
142 return ret;
143
144 ret = mpage_writepage(page, gfs2_get_block_noalloc, wbc);
145 if (ret == -EAGAIN)
146 ret = block_write_full_page(page, gfs2_get_block_noalloc, wbc);
147 return ret;
148}
149
150/**
151 * gfs2_ordered_writepage - Write page for ordered data files
152 * @page: The page to write
153 * @wbc: The writeback control
154 *
155 */
156
157static int gfs2_ordered_writepage(struct page *page,
158 struct writeback_control *wbc)
159{
160 struct inode *inode = page->mapping->host;
161 struct gfs2_inode *ip = GFS2_I(inode);
162 int ret;
163
164 ret = gfs2_writepage_common(page, wbc);
165 if (ret <= 0)
166 return ret;
167
168 if (!page_has_buffers(page)) {
169 create_empty_buffers(page, inode->i_sb->s_blocksize,
170 (1 << BH_Dirty)|(1 << BH_Uptodate));
139 } 171 }
172 gfs2_page_add_databufs(ip, page, 0, inode->i_sb->s_blocksize-1);
173 return block_write_full_page(page, gfs2_get_block_noalloc, wbc);
174}
140 175
141 if ((sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) && 176/**
142 PageChecked(page)) { 177 * __gfs2_jdata_writepage - The core of jdata writepage
178 * @page: The page to write
179 * @wbc: The writeback control
180 *
181 * This is shared between writepage and writepages and implements the
182 * core of the writepage operation. If a transaction is required then
183 * PageChecked will have been set and the transaction will have
184 * already been started before this is called.
185 */
186
187static int __gfs2_jdata_writepage(struct page *page, struct writeback_control *wbc)
188{
189 struct inode *inode = page->mapping->host;
190 struct gfs2_inode *ip = GFS2_I(inode);
191 struct gfs2_sbd *sdp = GFS2_SB(inode);
192
193 if (PageChecked(page)) {
143 ClearPageChecked(page); 194 ClearPageChecked(page);
144 error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0);
145 if (error)
146 goto out_ignore;
147 if (!page_has_buffers(page)) { 195 if (!page_has_buffers(page)) {
148 create_empty_buffers(page, inode->i_sb->s_blocksize, 196 create_empty_buffers(page, inode->i_sb->s_blocksize,
149 (1 << BH_Dirty)|(1 << BH_Uptodate)); 197 (1 << BH_Dirty)|(1 << BH_Uptodate));
150 } 198 }
151 gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1); 199 gfs2_page_add_databufs(ip, page, 0, sdp->sd_vfs->s_blocksize-1);
200 }
201 return block_write_full_page(page, gfs2_get_block_noalloc, wbc);
202}
203
204/**
205 * gfs2_jdata_writepage - Write complete page
206 * @page: Page to write
207 *
208 * Returns: errno
209 *
210 */
211
212static int gfs2_jdata_writepage(struct page *page, struct writeback_control *wbc)
213{
214 struct inode *inode = page->mapping->host;
215 struct gfs2_sbd *sdp = GFS2_SB(inode);
216 int error;
217 int done_trans = 0;
218
219 error = gfs2_writepage_common(page, wbc);
220 if (error <= 0)
221 return error;
222
223 if (PageChecked(page)) {
224 if (wbc->sync_mode != WB_SYNC_ALL)
225 goto out_ignore;
226 error = gfs2_trans_begin(sdp, RES_DINODE + 1, 0);
227 if (error)
228 goto out_ignore;
152 done_trans = 1; 229 done_trans = 1;
153 } 230 }
154 error = block_write_full_page(page, gfs2_get_block_noalloc, wbc); 231 error = __gfs2_jdata_writepage(page, wbc);
155 if (done_trans) 232 if (done_trans)
156 gfs2_trans_end(sdp); 233 gfs2_trans_end(sdp);
157 gfs2_meta_cache_flush(ip);
158 return error; 234 return error;
159 235
160out_ignore: 236out_ignore:
@@ -164,29 +240,190 @@ out_ignore:
164} 240}
165 241
166/** 242/**
167 * gfs2_writepages - Write a bunch of dirty pages back to disk 243 * gfs2_writeback_writepages - Write a bunch of dirty pages back to disk
168 * @mapping: The mapping to write 244 * @mapping: The mapping to write
169 * @wbc: Write-back control 245 * @wbc: Write-back control
170 * 246 *
171 * For journaled files and/or ordered writes this just falls back to the 247 * For the data=writeback case we can already ignore buffer heads
172 * kernel's default writepages path for now. We will probably want to change
173 * that eventually (i.e. when we look at allocate on flush).
174 *
175 * For the data=writeback case though we can already ignore buffer heads
176 * and write whole extents at once. This is a big reduction in the 248 * and write whole extents at once. This is a big reduction in the
177 * number of I/O requests we send and the bmap calls we make in this case. 249 * number of I/O requests we send and the bmap calls we make in this case.
178 */ 250 */
179static int gfs2_writepages(struct address_space *mapping, 251static int gfs2_writeback_writepages(struct address_space *mapping,
180 struct writeback_control *wbc) 252 struct writeback_control *wbc)
253{
254 return mpage_writepages(mapping, wbc, gfs2_get_block_noalloc);
255}
256
257/**
258 * gfs2_write_jdata_pagevec - Write back a pagevec's worth of pages
259 * @mapping: The mapping
260 * @wbc: The writeback control
261 * @writepage: The writepage function to call for each page
262 * @pvec: The vector of pages
263 * @nr_pages: The number of pages to write
264 *
265 * Returns: non-zero if loop should terminate, zero otherwise
266 */
267
268static int gfs2_write_jdata_pagevec(struct address_space *mapping,
269 struct writeback_control *wbc,
270 struct pagevec *pvec,
271 int nr_pages, pgoff_t end)
181{ 272{
182 struct inode *inode = mapping->host; 273 struct inode *inode = mapping->host;
183 struct gfs2_inode *ip = GFS2_I(inode);
184 struct gfs2_sbd *sdp = GFS2_SB(inode); 274 struct gfs2_sbd *sdp = GFS2_SB(inode);
275 loff_t i_size = i_size_read(inode);
276 pgoff_t end_index = i_size >> PAGE_CACHE_SHIFT;
277 unsigned offset = i_size & (PAGE_CACHE_SIZE-1);
278 unsigned nrblocks = nr_pages * (PAGE_CACHE_SIZE/inode->i_sb->s_blocksize);
279 struct backing_dev_info *bdi = mapping->backing_dev_info;
280 int i;
281 int ret;
282
283 ret = gfs2_trans_begin(sdp, nrblocks, 0);
284 if (ret < 0)
285 return ret;
286
287 for(i = 0; i < nr_pages; i++) {
288 struct page *page = pvec->pages[i];
289
290 lock_page(page);
291
292 if (unlikely(page->mapping != mapping)) {
293 unlock_page(page);
294 continue;
295 }
296
297 if (!wbc->range_cyclic && page->index > end) {
298 ret = 1;
299 unlock_page(page);
300 continue;
301 }
302
303 if (wbc->sync_mode != WB_SYNC_NONE)
304 wait_on_page_writeback(page);
305
306 if (PageWriteback(page) ||
307 !clear_page_dirty_for_io(page)) {
308 unlock_page(page);
309 continue;
310 }
311
312 /* Is the page fully outside i_size? (truncate in progress) */
313 if (page->index > end_index || (page->index == end_index && !offset)) {
314 page->mapping->a_ops->invalidatepage(page, 0);
315 unlock_page(page);
316 continue;
317 }
318
319 ret = __gfs2_jdata_writepage(page, wbc);
320
321 if (ret || (--(wbc->nr_to_write) <= 0))
322 ret = 1;
323 if (wbc->nonblocking && bdi_write_congested(bdi)) {
324 wbc->encountered_congestion = 1;
325 ret = 1;
326 }
327
328 }
329 gfs2_trans_end(sdp);
330 return ret;
331}
332
333/**
334 * gfs2_write_cache_jdata - Like write_cache_pages but different
335 * @mapping: The mapping to write
336 * @wbc: The writeback control
337 * @writepage: The writepage function to call
338 * @data: The data to pass to writepage
339 *
340 * The reason that we use our own function here is that we need to
341 * start transactions before we grab page locks. This allows us
342 * to get the ordering right.
343 */
344
345static int gfs2_write_cache_jdata(struct address_space *mapping,
346 struct writeback_control *wbc)
347{
348 struct backing_dev_info *bdi = mapping->backing_dev_info;
349 int ret = 0;
350 int done = 0;
351 struct pagevec pvec;
352 int nr_pages;
353 pgoff_t index;
354 pgoff_t end;
355 int scanned = 0;
356 int range_whole = 0;
357
358 if (wbc->nonblocking && bdi_write_congested(bdi)) {
359 wbc->encountered_congestion = 1;
360 return 0;
361 }
362
363 pagevec_init(&pvec, 0);
364 if (wbc->range_cyclic) {
365 index = mapping->writeback_index; /* Start from prev offset */
366 end = -1;
367 } else {
368 index = wbc->range_start >> PAGE_CACHE_SHIFT;
369 end = wbc->range_end >> PAGE_CACHE_SHIFT;
370 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
371 range_whole = 1;
372 scanned = 1;
373 }
185 374
186 if (sdp->sd_args.ar_data == GFS2_DATA_WRITEBACK && !gfs2_is_jdata(ip)) 375retry:
187 return mpage_writepages(mapping, wbc, gfs2_get_block_noalloc); 376 while (!done && (index <= end) &&
377 (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
378 PAGECACHE_TAG_DIRTY,
379 min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
380 scanned = 1;
381 ret = gfs2_write_jdata_pagevec(mapping, wbc, &pvec, nr_pages, end);
382 if (ret)
383 done = 1;
384 if (ret > 0)
385 ret = 0;
386
387 pagevec_release(&pvec);
388 cond_resched();
389 }
390
391 if (!scanned && !done) {
392 /*
393 * We hit the last page and there is more work to be done: wrap
394 * back to the start of the file
395 */
396 scanned = 1;
397 index = 0;
398 goto retry;
399 }
400
401 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
402 mapping->writeback_index = index;
403 return ret;
404}
405
406
407/**
408 * gfs2_jdata_writepages - Write a bunch of dirty pages back to disk
409 * @mapping: The mapping to write
410 * @wbc: The writeback control
411 *
412 */
188 413
189 return generic_writepages(mapping, wbc); 414static int gfs2_jdata_writepages(struct address_space *mapping,
415 struct writeback_control *wbc)
416{
417 struct gfs2_inode *ip = GFS2_I(mapping->host);
418 struct gfs2_sbd *sdp = GFS2_SB(mapping->host);
419 int ret;
420
421 ret = gfs2_write_cache_jdata(mapping, wbc);
422 if (ret == 0 && wbc->sync_mode == WB_SYNC_ALL) {
423 gfs2_log_flush(sdp, ip->i_gl);
424 ret = gfs2_write_cache_jdata(mapping, wbc);
425 }
426 return ret;
190} 427}
191 428
192/** 429/**
@@ -231,62 +468,107 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
231 468
232 469
233/** 470/**
234 * gfs2_readpage - readpage with locking 471 * __gfs2_readpage - readpage
235 * @file: The file to read a page for. N.B. This may be NULL if we are 472 * @file: The file to read a page for
236 * reading an internal file.
237 * @page: The page to read 473 * @page: The page to read
238 * 474 *
239 * Returns: errno 475 * This is the core of gfs2's readpage. Its used by the internal file
476 * reading code as in that case we already hold the glock. Also its
477 * called by gfs2_readpage() once the required lock has been granted.
478 *
240 */ 479 */
241 480
242static int gfs2_readpage(struct file *file, struct page *page) 481static int __gfs2_readpage(void *file, struct page *page)
243{ 482{
244 struct gfs2_inode *ip = GFS2_I(page->mapping->host); 483 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
245 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host); 484 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
246 struct gfs2_file *gf = NULL;
247 struct gfs2_holder gh;
248 int error; 485 int error;
249 int do_unlock = 0;
250
251 if (likely(file != &gfs2_internal_file_sentinel)) {
252 if (file) {
253 gf = file->private_data;
254 if (test_bit(GFF_EXLOCK, &gf->f_flags))
255 /* gfs2_sharewrite_fault has grabbed the ip->i_gl already */
256 goto skip_lock;
257 }
258 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh);
259 do_unlock = 1;
260 error = gfs2_glock_nq_atime(&gh);
261 if (unlikely(error))
262 goto out_unlock;
263 }
264 486
265skip_lock:
266 if (gfs2_is_stuffed(ip)) { 487 if (gfs2_is_stuffed(ip)) {
267 error = stuffed_readpage(ip, page); 488 error = stuffed_readpage(ip, page);
268 unlock_page(page); 489 unlock_page(page);
269 } else 490 } else {
270 error = mpage_readpage(page, gfs2_get_block); 491 error = mpage_readpage(page, gfs2_block_map);
492 }
271 493
272 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 494 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
273 error = -EIO; 495 return -EIO;
496
497 return error;
498}
499
500/**
501 * gfs2_readpage - read a page of a file
502 * @file: The file to read
503 * @page: The page of the file
504 *
505 * This deals with the locking required. We use a trylock in order to
506 * avoid the page lock / glock ordering problems returning AOP_TRUNCATED_PAGE
507 * in the event that we are unable to get the lock.
508 */
509
510static int gfs2_readpage(struct file *file, struct page *page)
511{
512 struct gfs2_inode *ip = GFS2_I(page->mapping->host);
513 struct gfs2_holder gh;
514 int error;
274 515
275 if (do_unlock) { 516 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME|LM_FLAG_TRY_1CB, &gh);
276 gfs2_glock_dq_m(1, &gh); 517 error = gfs2_glock_nq_atime(&gh);
277 gfs2_holder_uninit(&gh); 518 if (unlikely(error)) {
519 unlock_page(page);
520 goto out;
278 } 521 }
522 error = __gfs2_readpage(file, page);
523 gfs2_glock_dq(&gh);
279out: 524out:
280 return error; 525 gfs2_holder_uninit(&gh);
281out_unlock:
282 unlock_page(page);
283 if (error == GLR_TRYFAILED) { 526 if (error == GLR_TRYFAILED) {
284 error = AOP_TRUNCATED_PAGE;
285 yield(); 527 yield();
528 return AOP_TRUNCATED_PAGE;
286 } 529 }
287 if (do_unlock) 530 return error;
288 gfs2_holder_uninit(&gh); 531}
289 goto out; 532
533/**
534 * gfs2_internal_read - read an internal file
535 * @ip: The gfs2 inode
536 * @ra_state: The readahead state (or NULL for no readahead)
537 * @buf: The buffer to fill
538 * @pos: The file position
539 * @size: The amount to read
540 *
541 */
542
543int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
544 char *buf, loff_t *pos, unsigned size)
545{
546 struct address_space *mapping = ip->i_inode.i_mapping;
547 unsigned long index = *pos / PAGE_CACHE_SIZE;
548 unsigned offset = *pos & (PAGE_CACHE_SIZE - 1);
549 unsigned copied = 0;
550 unsigned amt;
551 struct page *page;
552 void *p;
553
554 do {
555 amt = size - copied;
556 if (offset + size > PAGE_CACHE_SIZE)
557 amt = PAGE_CACHE_SIZE - offset;
558 page = read_cache_page(mapping, index, __gfs2_readpage, NULL);
559 if (IS_ERR(page))
560 return PTR_ERR(page);
561 p = kmap_atomic(page, KM_USER0);
562 memcpy(buf + copied, p + offset, amt);
563 kunmap_atomic(p, KM_USER0);
564 mark_page_accessed(page);
565 page_cache_release(page);
566 copied += amt;
567 index++;
568 offset = 0;
569 } while(copied < size);
570 (*pos) += size;
571 return size;
290} 572}
291 573
292/** 574/**
@@ -300,10 +582,9 @@ out_unlock:
300 * Any I/O we ignore at this time will be done via readpage later. 582 * Any I/O we ignore at this time will be done via readpage later.
301 * 2. We don't handle stuffed files here we let readpage do the honours. 583 * 2. We don't handle stuffed files here we let readpage do the honours.
302 * 3. mpage_readpages() does most of the heavy lifting in the common case. 584 * 3. mpage_readpages() does most of the heavy lifting in the common case.
303 * 4. gfs2_get_block() is relied upon to set BH_Boundary in the right places. 585 * 4. gfs2_block_map() is relied upon to set BH_Boundary in the right places.
304 * 5. We use LM_FLAG_TRY_1CB here, effectively we then have lock-ahead as
305 * well as read-ahead.
306 */ 586 */
587
307static int gfs2_readpages(struct file *file, struct address_space *mapping, 588static int gfs2_readpages(struct file *file, struct address_space *mapping,
308 struct list_head *pages, unsigned nr_pages) 589 struct list_head *pages, unsigned nr_pages)
309{ 590{
@@ -311,42 +592,20 @@ static int gfs2_readpages(struct file *file, struct address_space *mapping,
311 struct gfs2_inode *ip = GFS2_I(inode); 592 struct gfs2_inode *ip = GFS2_I(inode);
312 struct gfs2_sbd *sdp = GFS2_SB(inode); 593 struct gfs2_sbd *sdp = GFS2_SB(inode);
313 struct gfs2_holder gh; 594 struct gfs2_holder gh;
314 int ret = 0; 595 int ret;
315 int do_unlock = 0;
316 596
317 if (likely(file != &gfs2_internal_file_sentinel)) { 597 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, GL_ATIME, &gh);
318 if (file) { 598 ret = gfs2_glock_nq_atime(&gh);
319 struct gfs2_file *gf = file->private_data; 599 if (unlikely(ret))
320 if (test_bit(GFF_EXLOCK, &gf->f_flags)) 600 goto out_uninit;
321 goto skip_lock;
322 }
323 gfs2_holder_init(ip->i_gl, LM_ST_SHARED,
324 LM_FLAG_TRY_1CB|GL_ATIME, &gh);
325 do_unlock = 1;
326 ret = gfs2_glock_nq_atime(&gh);
327 if (ret == GLR_TRYFAILED)
328 goto out_noerror;
329 if (unlikely(ret))
330 goto out_unlock;
331 }
332skip_lock:
333 if (!gfs2_is_stuffed(ip)) 601 if (!gfs2_is_stuffed(ip))
334 ret = mpage_readpages(mapping, pages, nr_pages, gfs2_get_block); 602 ret = mpage_readpages(mapping, pages, nr_pages, gfs2_block_map);
335 603 gfs2_glock_dq(&gh);
336 if (do_unlock) { 604out_uninit:
337 gfs2_glock_dq_m(1, &gh); 605 gfs2_holder_uninit(&gh);
338 gfs2_holder_uninit(&gh);
339 }
340out:
341 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 606 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
342 ret = -EIO; 607 ret = -EIO;
343 return ret; 608 return ret;
344out_noerror:
345 ret = 0;
346out_unlock:
347 if (do_unlock)
348 gfs2_holder_uninit(&gh);
349 goto out;
350} 609}
351 610
352/** 611/**
@@ -382,20 +641,11 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
382 if (unlikely(error)) 641 if (unlikely(error))
383 goto out_uninit; 642 goto out_uninit;
384 643
385 error = -ENOMEM;
386 page = __grab_cache_page(mapping, index);
387 *pagep = page;
388 if (!page)
389 goto out_unlock;
390
391 gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks); 644 gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks);
392
393 error = gfs2_write_alloc_required(ip, pos, len, &alloc_required); 645 error = gfs2_write_alloc_required(ip, pos, len, &alloc_required);
394 if (error) 646 if (error)
395 goto out_putpage; 647 goto out_unlock;
396
397 648
398 ip->i_alloc.al_requested = 0;
399 if (alloc_required) { 649 if (alloc_required) {
400 al = gfs2_alloc_get(ip); 650 al = gfs2_alloc_get(ip);
401 651
@@ -424,40 +674,47 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
424 if (error) 674 if (error)
425 goto out_trans_fail; 675 goto out_trans_fail;
426 676
677 error = -ENOMEM;
678 page = __grab_cache_page(mapping, index);
679 *pagep = page;
680 if (unlikely(!page))
681 goto out_endtrans;
682
427 if (gfs2_is_stuffed(ip)) { 683 if (gfs2_is_stuffed(ip)) {
684 error = 0;
428 if (pos + len > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) { 685 if (pos + len > sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode)) {
429 error = gfs2_unstuff_dinode(ip, page); 686 error = gfs2_unstuff_dinode(ip, page);
430 if (error == 0) 687 if (error == 0)
431 goto prepare_write; 688 goto prepare_write;
432 } else if (!PageUptodate(page)) 689 } else if (!PageUptodate(page)) {
433 error = stuffed_readpage(ip, page); 690 error = stuffed_readpage(ip, page);
691 }
434 goto out; 692 goto out;
435 } 693 }
436 694
437prepare_write: 695prepare_write:
438 error = block_prepare_write(page, from, to, gfs2_get_block); 696 error = block_prepare_write(page, from, to, gfs2_block_map);
439
440out: 697out:
441 if (error) { 698 if (error == 0)
442 gfs2_trans_end(sdp); 699 return 0;
700
701 page_cache_release(page);
702 if (pos + len > ip->i_inode.i_size)
703 vmtruncate(&ip->i_inode, ip->i_inode.i_size);
704out_endtrans:
705 gfs2_trans_end(sdp);
443out_trans_fail: 706out_trans_fail:
444 if (alloc_required) { 707 if (alloc_required) {
445 gfs2_inplace_release(ip); 708 gfs2_inplace_release(ip);
446out_qunlock: 709out_qunlock:
447 gfs2_quota_unlock(ip); 710 gfs2_quota_unlock(ip);
448out_alloc_put: 711out_alloc_put:
449 gfs2_alloc_put(ip); 712 gfs2_alloc_put(ip);
450 } 713 }
451out_putpage:
452 page_cache_release(page);
453 if (pos + len > ip->i_inode.i_size)
454 vmtruncate(&ip->i_inode, ip->i_inode.i_size);
455out_unlock: 714out_unlock:
456 gfs2_glock_dq_m(1, &ip->i_gh); 715 gfs2_glock_dq(&ip->i_gh);
457out_uninit: 716out_uninit:
458 gfs2_holder_uninit(&ip->i_gh); 717 gfs2_holder_uninit(&ip->i_gh);
459 }
460
461 return error; 718 return error;
462} 719}
463 720
@@ -565,7 +822,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
565 struct gfs2_inode *ip = GFS2_I(inode); 822 struct gfs2_inode *ip = GFS2_I(inode);
566 struct gfs2_sbd *sdp = GFS2_SB(inode); 823 struct gfs2_sbd *sdp = GFS2_SB(inode);
567 struct buffer_head *dibh; 824 struct buffer_head *dibh;
568 struct gfs2_alloc *al = &ip->i_alloc; 825 struct gfs2_alloc *al = ip->i_alloc;
569 struct gfs2_dinode *di; 826 struct gfs2_dinode *di;
570 unsigned int from = pos & (PAGE_CACHE_SIZE - 1); 827 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
571 unsigned int to = from + len; 828 unsigned int to = from + len;
@@ -585,19 +842,16 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
585 if (gfs2_is_stuffed(ip)) 842 if (gfs2_is_stuffed(ip))
586 return gfs2_stuffed_write_end(inode, dibh, pos, len, copied, page); 843 return gfs2_stuffed_write_end(inode, dibh, pos, len, copied, page);
587 844
588 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip)) 845 if (!gfs2_is_writeback(ip))
589 gfs2_page_add_databufs(ip, page, from, to); 846 gfs2_page_add_databufs(ip, page, from, to);
590 847
591 ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata); 848 ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
592 849
593 if (likely(ret >= 0)) { 850 if (likely(ret >= 0) && (inode->i_size > ip->i_di.di_size)) {
594 copied = ret; 851 di = (struct gfs2_dinode *)dibh->b_data;
595 if ((pos + copied) > inode->i_size) { 852 ip->i_di.di_size = inode->i_size;
596 di = (struct gfs2_dinode *)dibh->b_data; 853 di->di_size = cpu_to_be64(inode->i_size);
597 ip->i_di.di_size = inode->i_size; 854 mark_inode_dirty(inode);
598 di->di_size = cpu_to_be64(inode->i_size);
599 mark_inode_dirty(inode);
600 }
601 } 855 }
602 856
603 if (inode == sdp->sd_rindex) 857 if (inode == sdp->sd_rindex)
@@ -606,7 +860,7 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
606 brelse(dibh); 860 brelse(dibh);
607 gfs2_trans_end(sdp); 861 gfs2_trans_end(sdp);
608failed: 862failed:
609 if (al->al_requested) { 863 if (al) {
610 gfs2_inplace_release(ip); 864 gfs2_inplace_release(ip);
611 gfs2_quota_unlock(ip); 865 gfs2_quota_unlock(ip);
612 gfs2_alloc_put(ip); 866 gfs2_alloc_put(ip);
@@ -625,11 +879,7 @@ failed:
625 879
626static int gfs2_set_page_dirty(struct page *page) 880static int gfs2_set_page_dirty(struct page *page)
627{ 881{
628 struct gfs2_inode *ip = GFS2_I(page->mapping->host); 882 SetPageChecked(page);
629 struct gfs2_sbd *sdp = GFS2_SB(page->mapping->host);
630
631 if (sdp->sd_args.ar_data == GFS2_DATA_ORDERED || gfs2_is_jdata(ip))
632 SetPageChecked(page);
633 return __set_page_dirty_buffers(page); 883 return __set_page_dirty_buffers(page);
634} 884}
635 885
@@ -653,7 +903,7 @@ static sector_t gfs2_bmap(struct address_space *mapping, sector_t lblock)
653 return 0; 903 return 0;
654 904
655 if (!gfs2_is_stuffed(ip)) 905 if (!gfs2_is_stuffed(ip))
656 dblock = generic_block_bmap(mapping, lblock, gfs2_get_block); 906 dblock = generic_block_bmap(mapping, lblock, gfs2_block_map);
657 907
658 gfs2_glock_dq_uninit(&i_gh); 908 gfs2_glock_dq_uninit(&i_gh);
659 909
@@ -719,13 +969,9 @@ static int gfs2_ok_for_dio(struct gfs2_inode *ip, int rw, loff_t offset)
719{ 969{
720 /* 970 /*
721 * Should we return an error here? I can't see that O_DIRECT for 971 * Should we return an error here? I can't see that O_DIRECT for
722 * a journaled file makes any sense. For now we'll silently fall 972 * a stuffed file makes any sense. For now we'll silently fall
723 * back to buffered I/O, likewise we do the same for stuffed 973 * back to buffered I/O
724 * files since they are (a) small and (b) unaligned.
725 */ 974 */
726 if (gfs2_is_jdata(ip))
727 return 0;
728
729 if (gfs2_is_stuffed(ip)) 975 if (gfs2_is_stuffed(ip))
730 return 0; 976 return 0;
731 977
@@ -836,9 +1082,23 @@ cannot_release:
836 return 0; 1082 return 0;
837} 1083}
838 1084
839const struct address_space_operations gfs2_file_aops = { 1085static const struct address_space_operations gfs2_writeback_aops = {
840 .writepage = gfs2_writepage, 1086 .writepage = gfs2_writeback_writepage,
841 .writepages = gfs2_writepages, 1087 .writepages = gfs2_writeback_writepages,
1088 .readpage = gfs2_readpage,
1089 .readpages = gfs2_readpages,
1090 .sync_page = block_sync_page,
1091 .write_begin = gfs2_write_begin,
1092 .write_end = gfs2_write_end,
1093 .bmap = gfs2_bmap,
1094 .invalidatepage = gfs2_invalidatepage,
1095 .releasepage = gfs2_releasepage,
1096 .direct_IO = gfs2_direct_IO,
1097 .migratepage = buffer_migrate_page,
1098};
1099
1100static const struct address_space_operations gfs2_ordered_aops = {
1101 .writepage = gfs2_ordered_writepage,
842 .readpage = gfs2_readpage, 1102 .readpage = gfs2_readpage,
843 .readpages = gfs2_readpages, 1103 .readpages = gfs2_readpages,
844 .sync_page = block_sync_page, 1104 .sync_page = block_sync_page,
@@ -849,5 +1109,34 @@ const struct address_space_operations gfs2_file_aops = {
849 .invalidatepage = gfs2_invalidatepage, 1109 .invalidatepage = gfs2_invalidatepage,
850 .releasepage = gfs2_releasepage, 1110 .releasepage = gfs2_releasepage,
851 .direct_IO = gfs2_direct_IO, 1111 .direct_IO = gfs2_direct_IO,
1112 .migratepage = buffer_migrate_page,
852}; 1113};
853 1114
1115static const struct address_space_operations gfs2_jdata_aops = {
1116 .writepage = gfs2_jdata_writepage,
1117 .writepages = gfs2_jdata_writepages,
1118 .readpage = gfs2_readpage,
1119 .readpages = gfs2_readpages,
1120 .sync_page = block_sync_page,
1121 .write_begin = gfs2_write_begin,
1122 .write_end = gfs2_write_end,
1123 .set_page_dirty = gfs2_set_page_dirty,
1124 .bmap = gfs2_bmap,
1125 .invalidatepage = gfs2_invalidatepage,
1126 .releasepage = gfs2_releasepage,
1127};
1128
1129void gfs2_set_aops(struct inode *inode)
1130{
1131 struct gfs2_inode *ip = GFS2_I(inode);
1132
1133 if (gfs2_is_writeback(ip))
1134 inode->i_mapping->a_ops = &gfs2_writeback_aops;
1135 else if (gfs2_is_ordered(ip))
1136 inode->i_mapping->a_ops = &gfs2_ordered_aops;
1137 else if (gfs2_is_jdata(ip))
1138 inode->i_mapping->a_ops = &gfs2_jdata_aops;
1139 else
1140 BUG();
1141}
1142
diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h
index fa1b5b3d28b9..5da21285bba4 100644
--- a/fs/gfs2/ops_address.h
+++ b/fs/gfs2/ops_address.h
@@ -14,9 +14,10 @@
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/mm.h> 15#include <linux/mm.h>
16 16
17extern const struct address_space_operations gfs2_file_aops;
18extern int gfs2_get_block(struct inode *inode, sector_t lblock,
19 struct buffer_head *bh_result, int create);
20extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask); 17extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask);
18extern int gfs2_internal_read(struct gfs2_inode *ip,
19 struct file_ra_state *ra_state,
20 char *buf, loff_t *pos, unsigned size);
21extern void gfs2_set_aops(struct inode *inode);
21 22
22#endif /* __OPS_ADDRESS_DOT_H__ */ 23#endif /* __OPS_ADDRESS_DOT_H__ */
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index bb11fd6752d3..f4842f2548cd 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -33,57 +33,12 @@
33#include "lm.h" 33#include "lm.h"
34#include "log.h" 34#include "log.h"
35#include "meta_io.h" 35#include "meta_io.h"
36#include "ops_file.h"
37#include "ops_vm.h"
38#include "quota.h" 36#include "quota.h"
39#include "rgrp.h" 37#include "rgrp.h"
40#include "trans.h" 38#include "trans.h"
41#include "util.h" 39#include "util.h"
42#include "eaops.h" 40#include "eaops.h"
43 41#include "ops_address.h"
44/*
45 * Most fields left uninitialised to catch anybody who tries to
46 * use them. f_flags set to prevent file_accessed() from touching
47 * any other part of this. Its use is purely as a flag so that we
48 * know (in readpage()) whether or not do to locking.
49 */
50struct file gfs2_internal_file_sentinel = {
51 .f_flags = O_NOATIME|O_RDONLY,
52};
53
54static int gfs2_read_actor(read_descriptor_t *desc, struct page *page,
55 unsigned long offset, unsigned long size)
56{
57 char *kaddr;
58 unsigned long count = desc->count;
59
60 if (size > count)
61 size = count;
62
63 kaddr = kmap(page);
64 memcpy(desc->arg.data, kaddr + offset, size);
65 kunmap(page);
66
67 desc->count = count - size;
68 desc->written += size;
69 desc->arg.buf += size;
70 return size;
71}
72
73int gfs2_internal_read(struct gfs2_inode *ip, struct file_ra_state *ra_state,
74 char *buf, loff_t *pos, unsigned size)
75{
76 struct inode *inode = &ip->i_inode;
77 read_descriptor_t desc;
78 desc.written = 0;
79 desc.arg.data = buf;
80 desc.count = size;
81 desc.error = 0;
82 do_generic_mapping_read(inode->i_mapping, ra_state,
83 &gfs2_internal_file_sentinel, pos, &desc,
84 gfs2_read_actor);
85 return desc.written ? desc.written : desc.error;
86}
87 42
88/** 43/**
89 * gfs2_llseek - seek to a location in a file 44 * gfs2_llseek - seek to a location in a file
@@ -214,7 +169,7 @@ static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
214 if (put_user(fsflags, ptr)) 169 if (put_user(fsflags, ptr))
215 error = -EFAULT; 170 error = -EFAULT;
216 171
217 gfs2_glock_dq_m(1, &gh); 172 gfs2_glock_dq(&gh);
218 gfs2_holder_uninit(&gh); 173 gfs2_holder_uninit(&gh);
219 return error; 174 return error;
220} 175}
@@ -291,7 +246,16 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
291 if (error) 246 if (error)
292 goto out; 247 goto out;
293 } 248 }
294 249 if ((flags ^ new_flags) & GFS2_DIF_JDATA) {
250 if (flags & GFS2_DIF_JDATA)
251 gfs2_log_flush(sdp, ip->i_gl);
252 error = filemap_fdatawrite(inode->i_mapping);
253 if (error)
254 goto out;
255 error = filemap_fdatawait(inode->i_mapping);
256 if (error)
257 goto out;
258 }
295 error = gfs2_trans_begin(sdp, RES_DINODE, 0); 259 error = gfs2_trans_begin(sdp, RES_DINODE, 0);
296 if (error) 260 if (error)
297 goto out; 261 goto out;
@@ -303,6 +267,7 @@ static int do_gfs2_set_flags(struct file *filp, u32 reqflags, u32 mask)
303 gfs2_dinode_out(ip, bh->b_data); 267 gfs2_dinode_out(ip, bh->b_data);
304 brelse(bh); 268 brelse(bh);
305 gfs2_set_inode_flags(inode); 269 gfs2_set_inode_flags(inode);
270 gfs2_set_aops(inode);
306out_trans_end: 271out_trans_end:
307 gfs2_trans_end(sdp); 272 gfs2_trans_end(sdp);
308out: 273out:
@@ -338,6 +303,128 @@ static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
338 return -ENOTTY; 303 return -ENOTTY;
339} 304}
340 305
306/**
307 * gfs2_allocate_page_backing - Use bmap to allocate blocks
308 * @page: The (locked) page to allocate backing for
309 *
310 * We try to allocate all the blocks required for the page in
311 * one go. This might fail for various reasons, so we keep
312 * trying until all the blocks to back this page are allocated.
313 * If some of the blocks are already allocated, thats ok too.
314 */
315
316static int gfs2_allocate_page_backing(struct page *page)
317{
318 struct inode *inode = page->mapping->host;
319 struct buffer_head bh;
320 unsigned long size = PAGE_CACHE_SIZE;
321 u64 lblock = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
322
323 do {
324 bh.b_state = 0;
325 bh.b_size = size;
326 gfs2_block_map(inode, lblock, &bh, 1);
327 if (!buffer_mapped(&bh))
328 return -EIO;
329 size -= bh.b_size;
330 lblock += (bh.b_size >> inode->i_blkbits);
331 } while(size > 0);
332 return 0;
333}
334
335/**
336 * gfs2_page_mkwrite - Make a shared, mmap()ed, page writable
337 * @vma: The virtual memory area
338 * @page: The page which is about to become writable
339 *
340 * When the page becomes writable, we need to ensure that we have
341 * blocks allocated on disk to back that page.
342 */
343
344static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct page *page)
345{
346 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
347 struct gfs2_inode *ip = GFS2_I(inode);
348 struct gfs2_sbd *sdp = GFS2_SB(inode);
349 unsigned long last_index;
350 u64 pos = page->index << (PAGE_CACHE_SIZE - inode->i_blkbits);
351 unsigned int data_blocks, ind_blocks, rblocks;
352 int alloc_required = 0;
353 struct gfs2_holder gh;
354 struct gfs2_alloc *al;
355 int ret;
356
357 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, GL_ATIME, &gh);
358 ret = gfs2_glock_nq_atime(&gh);
359 if (ret)
360 goto out;
361
362 set_bit(GIF_SW_PAGED, &ip->i_flags);
363 gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
364 ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required);
365 if (ret || !alloc_required)
366 goto out_unlock;
367 ret = -ENOMEM;
368 al = gfs2_alloc_get(ip);
369 if (al == NULL)
370 goto out_unlock;
371
372 ret = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
373 if (ret)
374 goto out_alloc_put;
375 ret = gfs2_quota_check(ip, ip->i_inode.i_uid, ip->i_inode.i_gid);
376 if (ret)
377 goto out_quota_unlock;
378 al->al_requested = data_blocks + ind_blocks;
379 ret = gfs2_inplace_reserve(ip);
380 if (ret)
381 goto out_quota_unlock;
382
383 rblocks = RES_DINODE + ind_blocks;
384 if (gfs2_is_jdata(ip))
385 rblocks += data_blocks ? data_blocks : 1;
386 if (ind_blocks || data_blocks)
387 rblocks += RES_STATFS + RES_QUOTA;
388 ret = gfs2_trans_begin(sdp, rblocks, 0);
389 if (ret)
390 goto out_trans_fail;
391
392 lock_page(page);
393 ret = -EINVAL;
394 last_index = ip->i_inode.i_size >> PAGE_CACHE_SHIFT;
395 if (page->index > last_index)
396 goto out_unlock_page;
397 ret = 0;
398 if (!PageUptodate(page) || page->mapping != ip->i_inode.i_mapping)
399 goto out_unlock_page;
400 if (gfs2_is_stuffed(ip)) {
401 ret = gfs2_unstuff_dinode(ip, page);
402 if (ret)
403 goto out_unlock_page;
404 }
405 ret = gfs2_allocate_page_backing(page);
406
407out_unlock_page:
408 unlock_page(page);
409 gfs2_trans_end(sdp);
410out_trans_fail:
411 gfs2_inplace_release(ip);
412out_quota_unlock:
413 gfs2_quota_unlock(ip);
414out_alloc_put:
415 gfs2_alloc_put(ip);
416out_unlock:
417 gfs2_glock_dq(&gh);
418out:
419 gfs2_holder_uninit(&gh);
420 return ret;
421}
422
423static struct vm_operations_struct gfs2_vm_ops = {
424 .fault = filemap_fault,
425 .page_mkwrite = gfs2_page_mkwrite,
426};
427
341 428
342/** 429/**
343 * gfs2_mmap - 430 * gfs2_mmap -
@@ -360,14 +447,7 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
360 return error; 447 return error;
361 } 448 }
362 449
363 /* This is VM_MAYWRITE instead of VM_WRITE because a call 450 vma->vm_ops = &gfs2_vm_ops;
364 to mprotect() can turn on VM_WRITE later. */
365
366 if ((vma->vm_flags & (VM_MAYSHARE | VM_MAYWRITE)) ==
367 (VM_MAYSHARE | VM_MAYWRITE))
368 vma->vm_ops = &gfs2_vm_ops_sharewrite;
369 else
370 vma->vm_ops = &gfs2_vm_ops_private;
371 451
372 gfs2_glock_dq_uninit(&i_gh); 452 gfs2_glock_dq_uninit(&i_gh);
373 453
@@ -538,15 +618,6 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
538 if (__mandatory_lock(&ip->i_inode)) 618 if (__mandatory_lock(&ip->i_inode))
539 return -ENOLCK; 619 return -ENOLCK;
540 620
541 if (sdp->sd_args.ar_localflocks) {
542 if (IS_GETLK(cmd)) {
543 posix_test_lock(file, fl);
544 return 0;
545 } else {
546 return posix_lock_file_wait(file, fl);
547 }
548 }
549
550 if (cmd == F_CANCELLK) { 621 if (cmd == F_CANCELLK) {
551 /* Hack: */ 622 /* Hack: */
552 cmd = F_SETLK; 623 cmd = F_SETLK;
@@ -632,16 +703,12 @@ static void do_unflock(struct file *file, struct file_lock *fl)
632static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) 703static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
633{ 704{
634 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); 705 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
635 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
636 706
637 if (!(fl->fl_flags & FL_FLOCK)) 707 if (!(fl->fl_flags & FL_FLOCK))
638 return -ENOLCK; 708 return -ENOLCK;
639 if (__mandatory_lock(&ip->i_inode)) 709 if (__mandatory_lock(&ip->i_inode))
640 return -ENOLCK; 710 return -ENOLCK;
641 711
642 if (sdp->sd_args.ar_localflocks)
643 return flock_lock_file_wait(file, fl);
644
645 if (fl->fl_type == F_UNLCK) { 712 if (fl->fl_type == F_UNLCK) {
646 do_unflock(file, fl); 713 do_unflock(file, fl);
647 return 0; 714 return 0;
@@ -678,3 +745,27 @@ const struct file_operations gfs2_dir_fops = {
678 .flock = gfs2_flock, 745 .flock = gfs2_flock,
679}; 746};
680 747
748const struct file_operations gfs2_file_fops_nolock = {
749 .llseek = gfs2_llseek,
750 .read = do_sync_read,
751 .aio_read = generic_file_aio_read,
752 .write = do_sync_write,
753 .aio_write = generic_file_aio_write,
754 .unlocked_ioctl = gfs2_ioctl,
755 .mmap = gfs2_mmap,
756 .open = gfs2_open,
757 .release = gfs2_close,
758 .fsync = gfs2_fsync,
759 .splice_read = generic_file_splice_read,
760 .splice_write = generic_file_splice_write,
761 .setlease = gfs2_setlease,
762};
763
764const struct file_operations gfs2_dir_fops_nolock = {
765 .readdir = gfs2_readdir,
766 .unlocked_ioctl = gfs2_ioctl,
767 .open = gfs2_open,
768 .release = gfs2_close,
769 .fsync = gfs2_fsync,
770};
771
diff --git a/fs/gfs2/ops_file.h b/fs/gfs2/ops_file.h
deleted file mode 100644
index 7e5d8ec9c846..000000000000
--- a/fs/gfs2/ops_file.h
+++ /dev/null
@@ -1,24 +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 __OPS_FILE_DOT_H__
11#define __OPS_FILE_DOT_H__
12
13#include <linux/fs.h>
14struct gfs2_inode;
15
16extern struct file gfs2_internal_file_sentinel;
17extern int gfs2_internal_read(struct gfs2_inode *ip,
18 struct file_ra_state *ra_state,
19 char *buf, loff_t *pos, unsigned size);
20extern void gfs2_set_inode_flags(struct inode *inode);
21extern const struct file_operations gfs2_file_fops;
22extern const struct file_operations gfs2_dir_fops;
23
24#endif /* __OPS_FILE_DOT_H__ */
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 17de58e83d92..43d511bba52d 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -21,6 +21,7 @@
21 21
22#include "gfs2.h" 22#include "gfs2.h"
23#include "incore.h" 23#include "incore.h"
24#include "bmap.h"
24#include "daemon.h" 25#include "daemon.h"
25#include "glock.h" 26#include "glock.h"
26#include "glops.h" 27#include "glops.h"
@@ -59,7 +60,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
59 60
60 mutex_init(&sdp->sd_inum_mutex); 61 mutex_init(&sdp->sd_inum_mutex);
61 spin_lock_init(&sdp->sd_statfs_spin); 62 spin_lock_init(&sdp->sd_statfs_spin);
62 mutex_init(&sdp->sd_statfs_mutex);
63 63
64 spin_lock_init(&sdp->sd_rindex_spin); 64 spin_lock_init(&sdp->sd_rindex_spin);
65 mutex_init(&sdp->sd_rindex_mutex); 65 mutex_init(&sdp->sd_rindex_mutex);
@@ -77,7 +77,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
77 77
78 spin_lock_init(&sdp->sd_log_lock); 78 spin_lock_init(&sdp->sd_log_lock);
79 79
80 INIT_LIST_HEAD(&sdp->sd_log_le_gl);
81 INIT_LIST_HEAD(&sdp->sd_log_le_buf); 80 INIT_LIST_HEAD(&sdp->sd_log_le_buf);
82 INIT_LIST_HEAD(&sdp->sd_log_le_revoke); 81 INIT_LIST_HEAD(&sdp->sd_log_le_revoke);
83 INIT_LIST_HEAD(&sdp->sd_log_le_rg); 82 INIT_LIST_HEAD(&sdp->sd_log_le_rg);
@@ -303,6 +302,67 @@ out:
303 return error; 302 return error;
304} 303}
305 304
305/**
306 * map_journal_extents - create a reusable "extent" mapping from all logical
307 * blocks to all physical blocks for the given journal. This will save
308 * us time when writing journal blocks. Most journals will have only one
309 * extent that maps all their logical blocks. That's because gfs2.mkfs
310 * arranges the journal blocks sequentially to maximize performance.
311 * So the extent would map the first block for the entire file length.
312 * However, gfs2_jadd can happen while file activity is happening, so
313 * those journals may not be sequential. Less likely is the case where
314 * the users created their own journals by mounting the metafs and
315 * laying it out. But it's still possible. These journals might have
316 * several extents.
317 *
318 * TODO: This should be done in bigger chunks rather than one block at a time,
319 * but since it's only done at mount time, I'm not worried about the
320 * time it takes.
321 */
322static int map_journal_extents(struct gfs2_sbd *sdp)
323{
324 struct gfs2_jdesc *jd = sdp->sd_jdesc;
325 unsigned int lb;
326 u64 db, prev_db; /* logical block, disk block, prev disk block */
327 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
328 struct gfs2_journal_extent *jext = NULL;
329 struct buffer_head bh;
330 int rc = 0;
331
332 prev_db = 0;
333
334 for (lb = 0; lb < ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift; lb++) {
335 bh.b_state = 0;
336 bh.b_blocknr = 0;
337 bh.b_size = 1 << ip->i_inode.i_blkbits;
338 rc = gfs2_block_map(jd->jd_inode, lb, &bh, 0);
339 db = bh.b_blocknr;
340 if (rc || !db) {
341 printk(KERN_INFO "GFS2 journal mapping error %d: lb="
342 "%u db=%llu\n", rc, lb, (unsigned long long)db);
343 break;
344 }
345 if (!prev_db || db != prev_db + 1) {
346 jext = kzalloc(sizeof(struct gfs2_journal_extent),
347 GFP_KERNEL);
348 if (!jext) {
349 printk(KERN_INFO "GFS2 error: out of memory "
350 "mapping journal extents.\n");
351 rc = -ENOMEM;
352 break;
353 }
354 jext->dblock = db;
355 jext->lblock = lb;
356 jext->blocks = 1;
357 list_add_tail(&jext->extent_list, &jd->extent_list);
358 } else {
359 jext->blocks++;
360 }
361 prev_db = db;
362 }
363 return rc;
364}
365
306static int init_journal(struct gfs2_sbd *sdp, int undo) 366static int init_journal(struct gfs2_sbd *sdp, int undo)
307{ 367{
308 struct gfs2_holder ji_gh; 368 struct gfs2_holder ji_gh;
@@ -340,7 +400,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
340 400
341 if (sdp->sd_args.ar_spectator) { 401 if (sdp->sd_args.ar_spectator) {
342 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0); 402 sdp->sd_jdesc = gfs2_jdesc_find(sdp, 0);
343 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; 403 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
344 } else { 404 } else {
345 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) { 405 if (sdp->sd_lockstruct.ls_jid >= gfs2_jindex_size(sdp)) {
346 fs_err(sdp, "can't mount journal #%u\n", 406 fs_err(sdp, "can't mount journal #%u\n",
@@ -377,7 +437,10 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
377 sdp->sd_jdesc->jd_jid, error); 437 sdp->sd_jdesc->jd_jid, error);
378 goto fail_jinode_gh; 438 goto fail_jinode_gh;
379 } 439 }
380 sdp->sd_log_blks_free = sdp->sd_jdesc->jd_blocks; 440 atomic_set(&sdp->sd_log_blks_free, sdp->sd_jdesc->jd_blocks);
441
442 /* Map the extents for this journal's blocks */
443 map_journal_extents(sdp);
381 } 444 }
382 445
383 if (sdp->sd_lockstruct.ls_first) { 446 if (sdp->sd_lockstruct.ls_first) {
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 291f0c7eaa3b..9f71372c1757 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -61,7 +61,7 @@ static int gfs2_create(struct inode *dir, struct dentry *dentry,
61 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0); 61 inode = gfs2_createi(ghs, &dentry->d_name, S_IFREG | mode, 0);
62 if (!IS_ERR(inode)) { 62 if (!IS_ERR(inode)) {
63 gfs2_trans_end(sdp); 63 gfs2_trans_end(sdp);
64 if (dip->i_alloc.al_rgd) 64 if (dip->i_alloc->al_rgd)
65 gfs2_inplace_release(dip); 65 gfs2_inplace_release(dip);
66 gfs2_quota_unlock(dip); 66 gfs2_quota_unlock(dip);
67 gfs2_alloc_put(dip); 67 gfs2_alloc_put(dip);
@@ -113,8 +113,18 @@ static struct dentry *gfs2_lookup(struct inode *dir, struct dentry *dentry,
113 if (inode && IS_ERR(inode)) 113 if (inode && IS_ERR(inode))
114 return ERR_PTR(PTR_ERR(inode)); 114 return ERR_PTR(PTR_ERR(inode));
115 115
116 if (inode) 116 if (inode) {
117 struct gfs2_glock *gl = GFS2_I(inode)->i_gl;
118 struct gfs2_holder gh;
119 int error;
120 error = gfs2_glock_nq_init(gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
121 if (error) {
122 iput(inode);
123 return ERR_PTR(error);
124 }
125 gfs2_glock_dq_uninit(&gh);
117 return d_splice_alias(inode, dentry); 126 return d_splice_alias(inode, dentry);
127 }
118 d_add(dentry, inode); 128 d_add(dentry, inode);
119 129
120 return NULL; 130 return NULL;
@@ -366,7 +376,7 @@ static int gfs2_symlink(struct inode *dir, struct dentry *dentry,
366 } 376 }
367 377
368 gfs2_trans_end(sdp); 378 gfs2_trans_end(sdp);
369 if (dip->i_alloc.al_rgd) 379 if (dip->i_alloc->al_rgd)
370 gfs2_inplace_release(dip); 380 gfs2_inplace_release(dip);
371 gfs2_quota_unlock(dip); 381 gfs2_quota_unlock(dip);
372 gfs2_alloc_put(dip); 382 gfs2_alloc_put(dip);
@@ -442,7 +452,7 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
442 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */ 452 gfs2_assert_withdraw(sdp, !error); /* dip already pinned */
443 453
444 gfs2_trans_end(sdp); 454 gfs2_trans_end(sdp);
445 if (dip->i_alloc.al_rgd) 455 if (dip->i_alloc->al_rgd)
446 gfs2_inplace_release(dip); 456 gfs2_inplace_release(dip);
447 gfs2_quota_unlock(dip); 457 gfs2_quota_unlock(dip);
448 gfs2_alloc_put(dip); 458 gfs2_alloc_put(dip);
@@ -548,7 +558,7 @@ static int gfs2_mknod(struct inode *dir, struct dentry *dentry, int mode,
548 } 558 }
549 559
550 gfs2_trans_end(sdp); 560 gfs2_trans_end(sdp);
551 if (dip->i_alloc.al_rgd) 561 if (dip->i_alloc->al_rgd)
552 gfs2_inplace_release(dip); 562 gfs2_inplace_release(dip);
553 gfs2_quota_unlock(dip); 563 gfs2_quota_unlock(dip);
554 gfs2_alloc_put(dip); 564 gfs2_alloc_put(dip);
diff --git a/fs/gfs2/ops_inode.h b/fs/gfs2/ops_inode.h
index 34f0caac1a03..fd8cee231e1d 100644
--- a/fs/gfs2/ops_inode.h
+++ b/fs/gfs2/ops_inode.h
@@ -16,5 +16,11 @@ extern const struct inode_operations gfs2_file_iops;
16extern const struct inode_operations gfs2_dir_iops; 16extern const struct inode_operations gfs2_dir_iops;
17extern const struct inode_operations gfs2_symlink_iops; 17extern const struct inode_operations gfs2_symlink_iops;
18extern const struct inode_operations gfs2_dev_iops; 18extern const struct inode_operations gfs2_dev_iops;
19extern const struct file_operations gfs2_file_fops;
20extern const struct file_operations gfs2_dir_fops;
21extern const struct file_operations gfs2_file_fops_nolock;
22extern const struct file_operations gfs2_dir_fops_nolock;
23
24extern void gfs2_set_inode_flags(struct inode *inode);
19 25
20#endif /* __OPS_INODE_DOT_H__ */ 26#endif /* __OPS_INODE_DOT_H__ */
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c
index 950f31460e8b..5e524217944a 100644
--- a/fs/gfs2/ops_super.c
+++ b/fs/gfs2/ops_super.c
@@ -487,7 +487,6 @@ static struct inode *gfs2_alloc_inode(struct super_block *sb)
487 if (ip) { 487 if (ip) {
488 ip->i_flags = 0; 488 ip->i_flags = 0;
489 ip->i_gl = NULL; 489 ip->i_gl = NULL;
490 ip->i_last_pfault = jiffies;
491 } 490 }
492 return &ip->i_inode; 491 return &ip->i_inode;
493} 492}
diff --git a/fs/gfs2/ops_vm.c b/fs/gfs2/ops_vm.c
deleted file mode 100644
index 927d739d4685..000000000000
--- a/fs/gfs2/ops_vm.c
+++ /dev/null
@@ -1,169 +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/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
14#include <linux/mm.h>
15#include <linux/pagemap.h>
16#include <linux/gfs2_ondisk.h>
17#include <linux/lm_interface.h>
18
19#include "gfs2.h"
20#include "incore.h"
21#include "bmap.h"
22#include "glock.h"
23#include "inode.h"
24#include "ops_vm.h"
25#include "quota.h"
26#include "rgrp.h"
27#include "trans.h"
28#include "util.h"
29
30static int gfs2_private_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
31{
32 struct gfs2_inode *ip = GFS2_I(vma->vm_file->f_mapping->host);
33
34 set_bit(GIF_PAGED, &ip->i_flags);
35 return filemap_fault(vma, vmf);
36}
37
38static int alloc_page_backing(struct gfs2_inode *ip, struct page *page)
39{
40 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
41 unsigned long index = page->index;
42 u64 lblock = index << (PAGE_CACHE_SHIFT -
43 sdp->sd_sb.sb_bsize_shift);
44 unsigned int blocks = PAGE_CACHE_SIZE >> sdp->sd_sb.sb_bsize_shift;
45 struct gfs2_alloc *al;
46 unsigned int data_blocks, ind_blocks;
47 unsigned int x;
48 int error;
49
50 al = gfs2_alloc_get(ip);
51
52 error = gfs2_quota_lock(ip, NO_QUOTA_CHANGE, NO_QUOTA_CHANGE);
53 if (error)
54 goto out;
55
56 error = gfs2_quota_check(ip, ip->i_inode.i_uid, ip->i_inode.i_gid);
57 if (error)
58 goto out_gunlock_q;
59
60 gfs2_write_calc_reserv(ip, PAGE_CACHE_SIZE, &data_blocks, &ind_blocks);
61
62 al->al_requested = data_blocks + ind_blocks;
63
64 error = gfs2_inplace_reserve(ip);
65 if (error)
66 goto out_gunlock_q;
67
68 error = gfs2_trans_begin(sdp, al->al_rgd->rd_length +
69 ind_blocks + RES_DINODE +
70 RES_STATFS + RES_QUOTA, 0);
71 if (error)
72 goto out_ipres;
73
74 if (gfs2_is_stuffed(ip)) {
75 error = gfs2_unstuff_dinode(ip, NULL);
76 if (error)
77 goto out_trans;
78 }
79
80 for (x = 0; x < blocks; ) {
81 u64 dblock;
82 unsigned int extlen;
83 int new = 1;
84
85 error = gfs2_extent_map(&ip->i_inode, lblock, &new, &dblock, &extlen);
86 if (error)
87 goto out_trans;
88
89 lblock += extlen;
90 x += extlen;
91 }
92
93 gfs2_assert_warn(sdp, al->al_alloced);
94
95out_trans:
96 gfs2_trans_end(sdp);
97out_ipres:
98 gfs2_inplace_release(ip);
99out_gunlock_q:
100 gfs2_quota_unlock(ip);
101out:
102 gfs2_alloc_put(ip);
103 return error;
104}
105
106static int gfs2_sharewrite_fault(struct vm_area_struct *vma,
107 struct vm_fault *vmf)
108{
109 struct file *file = vma->vm_file;
110 struct gfs2_file *gf = file->private_data;
111 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
112 struct gfs2_holder i_gh;
113 int alloc_required;
114 int error;
115 int ret = 0;
116
117 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
118 if (error)
119 goto out;
120
121 set_bit(GIF_PAGED, &ip->i_flags);
122 set_bit(GIF_SW_PAGED, &ip->i_flags);
123
124 error = gfs2_write_alloc_required(ip,
125 (u64)vmf->pgoff << PAGE_CACHE_SHIFT,
126 PAGE_CACHE_SIZE, &alloc_required);
127 if (error) {
128 ret = VM_FAULT_OOM; /* XXX: are these right? */
129 goto out_unlock;
130 }
131
132 set_bit(GFF_EXLOCK, &gf->f_flags);
133 ret = filemap_fault(vma, vmf);
134 clear_bit(GFF_EXLOCK, &gf->f_flags);
135 if (ret & VM_FAULT_ERROR)
136 goto out_unlock;
137
138 if (alloc_required) {
139 /* XXX: do we need to drop page lock around alloc_page_backing?*/
140 error = alloc_page_backing(ip, vmf->page);
141 if (error) {
142 /*
143 * VM_FAULT_LOCKED should always be the case for
144 * filemap_fault, but it may not be in a future
145 * implementation.
146 */
147 if (ret & VM_FAULT_LOCKED)
148 unlock_page(vmf->page);
149 page_cache_release(vmf->page);
150 ret = VM_FAULT_OOM;
151 goto out_unlock;
152 }
153 set_page_dirty(vmf->page);
154 }
155
156out_unlock:
157 gfs2_glock_dq_uninit(&i_gh);
158out:
159 return ret;
160}
161
162struct vm_operations_struct gfs2_vm_ops_private = {
163 .fault = gfs2_private_fault,
164};
165
166struct vm_operations_struct gfs2_vm_ops_sharewrite = {
167 .fault = gfs2_sharewrite_fault,
168};
169
diff --git a/fs/gfs2/ops_vm.h b/fs/gfs2/ops_vm.h
deleted file mode 100644
index 4ae8f43ed5e3..000000000000
--- a/fs/gfs2/ops_vm.h
+++ /dev/null
@@ -1,18 +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 __OPS_VM_DOT_H__
11#define __OPS_VM_DOT_H__
12
13#include <linux/mm.h>
14
15extern struct vm_operations_struct gfs2_vm_ops_private;
16extern struct vm_operations_struct gfs2_vm_ops_sharewrite;
17
18#endif /* __OPS_VM_DOT_H__ */
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index addb51e0f135..a08dabd6ce90 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -59,7 +59,6 @@
59#include "super.h" 59#include "super.h"
60#include "trans.h" 60#include "trans.h"
61#include "inode.h" 61#include "inode.h"
62#include "ops_file.h"
63#include "ops_address.h" 62#include "ops_address.h"
64#include "util.h" 63#include "util.h"
65 64
@@ -274,10 +273,10 @@ static int bh_get(struct gfs2_quota_data *qd)
274 } 273 }
275 274
276 block = qd->qd_slot / sdp->sd_qc_per_block; 275 block = qd->qd_slot / sdp->sd_qc_per_block;
277 offset = qd->qd_slot % sdp->sd_qc_per_block;; 276 offset = qd->qd_slot % sdp->sd_qc_per_block;
278 277
279 bh_map.b_size = 1 << ip->i_inode.i_blkbits; 278 bh_map.b_size = 1 << ip->i_inode.i_blkbits;
280 error = gfs2_block_map(&ip->i_inode, block, 0, &bh_map); 279 error = gfs2_block_map(&ip->i_inode, block, &bh_map, 0);
281 if (error) 280 if (error)
282 goto fail; 281 goto fail;
283 error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh); 282 error = gfs2_meta_read(ip->i_gl, bh_map.b_blocknr, DIO_WAIT, &bh);
@@ -454,7 +453,7 @@ static void qdsb_put(struct gfs2_quota_data *qd)
454int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid) 453int gfs2_quota_hold(struct gfs2_inode *ip, u32 uid, u32 gid)
455{ 454{
456 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 455 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
457 struct gfs2_alloc *al = &ip->i_alloc; 456 struct gfs2_alloc *al = ip->i_alloc;
458 struct gfs2_quota_data **qd = al->al_qd; 457 struct gfs2_quota_data **qd = al->al_qd;
459 int error; 458 int error;
460 459
@@ -502,7 +501,7 @@ out:
502void gfs2_quota_unhold(struct gfs2_inode *ip) 501void gfs2_quota_unhold(struct gfs2_inode *ip)
503{ 502{
504 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 503 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
505 struct gfs2_alloc *al = &ip->i_alloc; 504 struct gfs2_alloc *al = ip->i_alloc;
506 unsigned int x; 505 unsigned int x;
507 506
508 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags)); 507 gfs2_assert_warn(sdp, !test_bit(GIF_QD_LOCKED, &ip->i_flags));
@@ -646,7 +645,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
646 } 645 }
647 646
648 if (!buffer_mapped(bh)) { 647 if (!buffer_mapped(bh)) {
649 gfs2_get_block(inode, iblock, bh, 1); 648 gfs2_block_map(inode, iblock, bh, 1);
650 if (!buffer_mapped(bh)) 649 if (!buffer_mapped(bh))
651 goto unlock; 650 goto unlock;
652 } 651 }
@@ -793,11 +792,9 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
793 struct gfs2_holder i_gh; 792 struct gfs2_holder i_gh;
794 struct gfs2_quota_host q; 793 struct gfs2_quota_host q;
795 char buf[sizeof(struct gfs2_quota)]; 794 char buf[sizeof(struct gfs2_quota)];
796 struct file_ra_state ra_state;
797 int error; 795 int error;
798 struct gfs2_quota_lvb *qlvb; 796 struct gfs2_quota_lvb *qlvb;
799 797
800 file_ra_state_init(&ra_state, sdp->sd_quota_inode->i_mapping);
801restart: 798restart:
802 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh); 799 error = gfs2_glock_nq_init(qd->qd_gl, LM_ST_SHARED, 0, q_gh);
803 if (error) 800 if (error)
@@ -820,8 +817,8 @@ restart:
820 817
821 memset(buf, 0, sizeof(struct gfs2_quota)); 818 memset(buf, 0, sizeof(struct gfs2_quota));
822 pos = qd2offset(qd); 819 pos = qd2offset(qd);
823 error = gfs2_internal_read(ip, &ra_state, buf, 820 error = gfs2_internal_read(ip, NULL, buf, &pos,
824 &pos, sizeof(struct gfs2_quota)); 821 sizeof(struct gfs2_quota));
825 if (error < 0) 822 if (error < 0)
826 goto fail_gunlock; 823 goto fail_gunlock;
827 824
@@ -856,7 +853,7 @@ fail:
856int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) 853int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
857{ 854{
858 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 855 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
859 struct gfs2_alloc *al = &ip->i_alloc; 856 struct gfs2_alloc *al = ip->i_alloc;
860 unsigned int x; 857 unsigned int x;
861 int error = 0; 858 int error = 0;
862 859
@@ -924,7 +921,7 @@ static int need_sync(struct gfs2_quota_data *qd)
924 921
925void gfs2_quota_unlock(struct gfs2_inode *ip) 922void gfs2_quota_unlock(struct gfs2_inode *ip)
926{ 923{
927 struct gfs2_alloc *al = &ip->i_alloc; 924 struct gfs2_alloc *al = ip->i_alloc;
928 struct gfs2_quota_data *qda[4]; 925 struct gfs2_quota_data *qda[4];
929 unsigned int count = 0; 926 unsigned int count = 0;
930 unsigned int x; 927 unsigned int x;
@@ -972,7 +969,7 @@ static int print_message(struct gfs2_quota_data *qd, char *type)
972int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid) 969int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
973{ 970{
974 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 971 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
975 struct gfs2_alloc *al = &ip->i_alloc; 972 struct gfs2_alloc *al = ip->i_alloc;
976 struct gfs2_quota_data *qd; 973 struct gfs2_quota_data *qd;
977 s64 value; 974 s64 value;
978 unsigned int x; 975 unsigned int x;
@@ -1016,10 +1013,9 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
1016void gfs2_quota_change(struct gfs2_inode *ip, s64 change, 1013void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1017 u32 uid, u32 gid) 1014 u32 uid, u32 gid)
1018{ 1015{
1019 struct gfs2_alloc *al = &ip->i_alloc; 1016 struct gfs2_alloc *al = ip->i_alloc;
1020 struct gfs2_quota_data *qd; 1017 struct gfs2_quota_data *qd;
1021 unsigned int x; 1018 unsigned int x;
1022 unsigned int found = 0;
1023 1019
1024 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change)) 1020 if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change))
1025 return; 1021 return;
@@ -1032,7 +1028,6 @@ void gfs2_quota_change(struct gfs2_inode *ip, s64 change,
1032 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) || 1028 if ((qd->qd_id == uid && test_bit(QDF_USER, &qd->qd_flags)) ||
1033 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) { 1029 (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))) {
1034 do_qc(qd, change); 1030 do_qc(qd, change);
1035 found++;
1036 } 1031 }
1037 } 1032 }
1038} 1033}
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index beb6c7ac0086..b249e294a95b 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -391,7 +391,7 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header_host *hea
391 lblock = head->lh_blkno; 391 lblock = head->lh_blkno;
392 gfs2_replay_incr_blk(sdp, &lblock); 392 gfs2_replay_incr_blk(sdp, &lblock);
393 bh_map.b_size = 1 << ip->i_inode.i_blkbits; 393 bh_map.b_size = 1 << ip->i_inode.i_blkbits;
394 error = gfs2_block_map(&ip->i_inode, lblock, 0, &bh_map); 394 error = gfs2_block_map(&ip->i_inode, lblock, &bh_map, 0);
395 if (error) 395 if (error)
396 return error; 396 return error;
397 if (!bh_map.b_blocknr) { 397 if (!bh_map.b_blocknr) {
@@ -504,13 +504,21 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
504 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) 504 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
505 ro = 1; 505 ro = 1;
506 } else { 506 } else {
507 if (sdp->sd_vfs->s_flags & MS_RDONLY) 507 if (sdp->sd_vfs->s_flags & MS_RDONLY) {
508 ro = 1; 508 /* check if device itself is read-only */
509 ro = bdev_read_only(sdp->sd_vfs->s_bdev);
510 if (!ro) {
511 fs_info(sdp, "recovery required on "
512 "read-only filesystem.\n");
513 fs_info(sdp, "write access will be "
514 "enabled during recovery.\n");
515 }
516 }
509 } 517 }
510 518
511 if (ro) { 519 if (ro) {
512 fs_warn(sdp, "jid=%u: Can't replay: read-only FS\n", 520 fs_warn(sdp, "jid=%u: Can't replay: read-only block "
513 jd->jd_jid); 521 "device\n", jd->jd_jid);
514 error = -EROFS; 522 error = -EROFS;
515 goto fail_gunlock_tr; 523 goto fail_gunlock_tr;
516 } 524 }
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 708c287e1d0e..3552110b2e5f 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -25,10 +25,10 @@
25#include "rgrp.h" 25#include "rgrp.h"
26#include "super.h" 26#include "super.h"
27#include "trans.h" 27#include "trans.h"
28#include "ops_file.h"
29#include "util.h" 28#include "util.h"
30#include "log.h" 29#include "log.h"
31#include "inode.h" 30#include "inode.h"
31#include "ops_address.h"
32 32
33#define BFITNOENT ((u32)~0) 33#define BFITNOENT ((u32)~0)
34#define NO_BLOCK ((u64)~0) 34#define NO_BLOCK ((u64)~0)
@@ -126,41 +126,43 @@ static unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd, unsigned char *buffer,
126 * Return: the block number (bitmap buffer scope) that was found 126 * Return: the block number (bitmap buffer scope) that was found
127 */ 127 */
128 128
129static u32 gfs2_bitfit(struct gfs2_rgrpd *rgd, unsigned char *buffer, 129static u32 gfs2_bitfit(unsigned char *buffer, unsigned int buflen, u32 goal,
130 unsigned int buflen, u32 goal, 130 unsigned char old_state)
131 unsigned char old_state)
132{ 131{
133 unsigned char *byte, *end, alloc; 132 unsigned char *byte;
134 u32 blk = goal; 133 u32 blk = goal;
135 unsigned int bit; 134 unsigned int bit, bitlong;
135 unsigned long *plong, plong55;
136 136
137 byte = buffer + (goal / GFS2_NBBY); 137 byte = buffer + (goal / GFS2_NBBY);
138 plong = (unsigned long *)(buffer + (goal / GFS2_NBBY));
138 bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; 139 bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE;
139 end = buffer + buflen; 140 bitlong = bit;
140 alloc = (old_state == GFS2_BLKST_FREE) ? 0x55 : 0; 141#if BITS_PER_LONG == 32
141 142 plong55 = 0x55555555;
142 while (byte < end) { 143#else
143 /* If we're looking for a free block we can eliminate all 144 plong55 = 0x5555555555555555;
144 bitmap settings with 0x55, which represents four data 145#endif
145 blocks in a row. If we're looking for a data block, we can 146 while (byte < buffer + buflen) {
146 eliminate 0x00 which corresponds to four free blocks. */ 147
147 if ((*byte & 0x55) == alloc) { 148 if (bitlong == 0 && old_state == 0 && *plong == plong55) {
148 blk += (8 - bit) >> 1; 149 plong++;
149 150 byte += sizeof(unsigned long);
150 bit = 0; 151 blk += sizeof(unsigned long) * GFS2_NBBY;
151 byte++;
152
153 continue; 152 continue;
154 } 153 }
155
156 if (((*byte >> bit) & GFS2_BIT_MASK) == old_state) 154 if (((*byte >> bit) & GFS2_BIT_MASK) == old_state)
157 return blk; 155 return blk;
158
159 bit += GFS2_BIT_SIZE; 156 bit += GFS2_BIT_SIZE;
160 if (bit >= 8) { 157 if (bit >= 8) {
161 bit = 0; 158 bit = 0;
162 byte++; 159 byte++;
163 } 160 }
161 bitlong += GFS2_BIT_SIZE;
162 if (bitlong >= sizeof(unsigned long) * 8) {
163 bitlong = 0;
164 plong++;
165 }
164 166
165 blk++; 167 blk++;
166 } 168 }
@@ -817,11 +819,9 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
817 819
818struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip) 820struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip)
819{ 821{
820 struct gfs2_alloc *al = &ip->i_alloc; 822 BUG_ON(ip->i_alloc != NULL);
821 823 ip->i_alloc = kzalloc(sizeof(struct gfs2_alloc), GFP_KERNEL);
822 /* FIXME: Should assert that the correct locks are held here... */ 824 return ip->i_alloc;
823 memset(al, 0, sizeof(*al));
824 return al;
825} 825}
826 826
827/** 827/**
@@ -1059,26 +1059,34 @@ static struct inode *get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1059 struct inode *inode = NULL; 1059 struct inode *inode = NULL;
1060 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1060 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1061 struct gfs2_rgrpd *rgd, *begin = NULL; 1061 struct gfs2_rgrpd *rgd, *begin = NULL;
1062 struct gfs2_alloc *al = &ip->i_alloc; 1062 struct gfs2_alloc *al = ip->i_alloc;
1063 int flags = LM_FLAG_TRY; 1063 int flags = LM_FLAG_TRY;
1064 int skipped = 0; 1064 int skipped = 0;
1065 int loops = 0; 1065 int loops = 0;
1066 int error; 1066 int error, rg_locked;
1067 1067
1068 /* Try recently successful rgrps */ 1068 /* Try recently successful rgrps */
1069 1069
1070 rgd = recent_rgrp_first(sdp, ip->i_last_rg_alloc); 1070 rgd = recent_rgrp_first(sdp, ip->i_last_rg_alloc);
1071 1071
1072 while (rgd) { 1072 while (rgd) {
1073 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, 1073 rg_locked = 0;
1074 LM_FLAG_TRY, &al->al_rgd_gh); 1074
1075 if (gfs2_glock_is_locked_by_me(rgd->rd_gl)) {
1076 rg_locked = 1;
1077 error = 0;
1078 } else {
1079 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE,
1080 LM_FLAG_TRY, &al->al_rgd_gh);
1081 }
1075 switch (error) { 1082 switch (error) {
1076 case 0: 1083 case 0:
1077 if (try_rgrp_fit(rgd, al)) 1084 if (try_rgrp_fit(rgd, al))
1078 goto out; 1085 goto out;
1079 if (rgd->rd_flags & GFS2_RDF_CHECK) 1086 if (rgd->rd_flags & GFS2_RDF_CHECK)
1080 inode = try_rgrp_unlink(rgd, last_unlinked); 1087 inode = try_rgrp_unlink(rgd, last_unlinked);
1081 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1088 if (!rg_locked)
1089 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1082 if (inode) 1090 if (inode)
1083 return inode; 1091 return inode;
1084 rgd = recent_rgrp_next(rgd, 1); 1092 rgd = recent_rgrp_next(rgd, 1);
@@ -1098,15 +1106,23 @@ static struct inode *get_local_rgrp(struct gfs2_inode *ip, u64 *last_unlinked)
1098 begin = rgd = forward_rgrp_get(sdp); 1106 begin = rgd = forward_rgrp_get(sdp);
1099 1107
1100 for (;;) { 1108 for (;;) {
1101 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, flags, 1109 rg_locked = 0;
1102 &al->al_rgd_gh); 1110
1111 if (gfs2_glock_is_locked_by_me(rgd->rd_gl)) {
1112 rg_locked = 1;
1113 error = 0;
1114 } else {
1115 error = gfs2_glock_nq_init(rgd->rd_gl, LM_ST_EXCLUSIVE, flags,
1116 &al->al_rgd_gh);
1117 }
1103 switch (error) { 1118 switch (error) {
1104 case 0: 1119 case 0:
1105 if (try_rgrp_fit(rgd, al)) 1120 if (try_rgrp_fit(rgd, al))
1106 goto out; 1121 goto out;
1107 if (rgd->rd_flags & GFS2_RDF_CHECK) 1122 if (rgd->rd_flags & GFS2_RDF_CHECK)
1108 inode = try_rgrp_unlink(rgd, last_unlinked); 1123 inode = try_rgrp_unlink(rgd, last_unlinked);
1109 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1124 if (!rg_locked)
1125 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1110 if (inode) 1126 if (inode)
1111 return inode; 1127 return inode;
1112 break; 1128 break;
@@ -1158,7 +1174,7 @@ out:
1158int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line) 1174int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file, unsigned int line)
1159{ 1175{
1160 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1176 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1161 struct gfs2_alloc *al = &ip->i_alloc; 1177 struct gfs2_alloc *al = ip->i_alloc;
1162 struct inode *inode; 1178 struct inode *inode;
1163 int error = 0; 1179 int error = 0;
1164 u64 last_unlinked = NO_BLOCK; 1180 u64 last_unlinked = NO_BLOCK;
@@ -1204,7 +1220,7 @@ try_again:
1204void gfs2_inplace_release(struct gfs2_inode *ip) 1220void gfs2_inplace_release(struct gfs2_inode *ip)
1205{ 1221{
1206 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1222 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1207 struct gfs2_alloc *al = &ip->i_alloc; 1223 struct gfs2_alloc *al = ip->i_alloc;
1208 1224
1209 if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1) 1225 if (gfs2_assert_warn(sdp, al->al_alloced <= al->al_requested) == -1)
1210 fs_warn(sdp, "al_alloced = %u, al_requested = %u " 1226 fs_warn(sdp, "al_alloced = %u, al_requested = %u "
@@ -1213,7 +1229,8 @@ void gfs2_inplace_release(struct gfs2_inode *ip)
1213 al->al_line); 1229 al->al_line);
1214 1230
1215 al->al_rgd = NULL; 1231 al->al_rgd = NULL;
1216 gfs2_glock_dq_uninit(&al->al_rgd_gh); 1232 if (al->al_rgd_gh.gh_gl)
1233 gfs2_glock_dq_uninit(&al->al_rgd_gh);
1217 if (ip != GFS2_I(sdp->sd_rindex)) 1234 if (ip != GFS2_I(sdp->sd_rindex))
1218 gfs2_glock_dq_uninit(&al->al_ri_gh); 1235 gfs2_glock_dq_uninit(&al->al_ri_gh);
1219} 1236}
@@ -1301,11 +1318,10 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
1301 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone 1318 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone
1302 bitmaps, so we must search the originals for that. */ 1319 bitmaps, so we must search the originals for that. */
1303 if (old_state != GFS2_BLKST_UNLINKED && bi->bi_clone) 1320 if (old_state != GFS2_BLKST_UNLINKED && bi->bi_clone)
1304 blk = gfs2_bitfit(rgd, bi->bi_clone + bi->bi_offset, 1321 blk = gfs2_bitfit(bi->bi_clone + bi->bi_offset,
1305 bi->bi_len, goal, old_state); 1322 bi->bi_len, goal, old_state);
1306 else 1323 else
1307 blk = gfs2_bitfit(rgd, 1324 blk = gfs2_bitfit(bi->bi_bh->b_data + bi->bi_offset,
1308 bi->bi_bh->b_data + bi->bi_offset,
1309 bi->bi_len, goal, old_state); 1325 bi->bi_len, goal, old_state);
1310 if (blk != BFITNOENT) 1326 if (blk != BFITNOENT)
1311 break; 1327 break;
@@ -1394,7 +1410,7 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
1394u64 gfs2_alloc_data(struct gfs2_inode *ip) 1410u64 gfs2_alloc_data(struct gfs2_inode *ip)
1395{ 1411{
1396 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1412 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1397 struct gfs2_alloc *al = &ip->i_alloc; 1413 struct gfs2_alloc *al = ip->i_alloc;
1398 struct gfs2_rgrpd *rgd = al->al_rgd; 1414 struct gfs2_rgrpd *rgd = al->al_rgd;
1399 u32 goal, blk; 1415 u32 goal, blk;
1400 u64 block; 1416 u64 block;
@@ -1439,7 +1455,7 @@ u64 gfs2_alloc_data(struct gfs2_inode *ip)
1439u64 gfs2_alloc_meta(struct gfs2_inode *ip) 1455u64 gfs2_alloc_meta(struct gfs2_inode *ip)
1440{ 1456{
1441 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1457 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1442 struct gfs2_alloc *al = &ip->i_alloc; 1458 struct gfs2_alloc *al = ip->i_alloc;
1443 struct gfs2_rgrpd *rgd = al->al_rgd; 1459 struct gfs2_rgrpd *rgd = al->al_rgd;
1444 u32 goal, blk; 1460 u32 goal, blk;
1445 u64 block; 1461 u64 block;
@@ -1485,7 +1501,7 @@ u64 gfs2_alloc_meta(struct gfs2_inode *ip)
1485u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation) 1501u64 gfs2_alloc_di(struct gfs2_inode *dip, u64 *generation)
1486{ 1502{
1487 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode); 1503 struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
1488 struct gfs2_alloc *al = &dip->i_alloc; 1504 struct gfs2_alloc *al = dip->i_alloc;
1489 struct gfs2_rgrpd *rgd = al->al_rgd; 1505 struct gfs2_rgrpd *rgd = al->al_rgd;
1490 u32 blk; 1506 u32 blk;
1491 u64 block; 1507 u64 block;
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index b4c6adfc6f2e..149bb161f4b6 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -32,7 +32,9 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd);
32struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip); 32struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
33static inline void gfs2_alloc_put(struct gfs2_inode *ip) 33static inline void gfs2_alloc_put(struct gfs2_inode *ip)
34{ 34{
35 return; /* So we can see where ip->i_alloc is used */ 35 BUG_ON(ip->i_alloc == NULL);
36 kfree(ip->i_alloc);
37 ip->i_alloc = NULL;
36} 38}
37 39
38int gfs2_inplace_reserve_i(struct gfs2_inode *ip, 40int gfs2_inplace_reserve_i(struct gfs2_inode *ip,
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index dd3e737f528e..ef0562c3bc71 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 * 4 *
5 * This copyrighted material is made available to anyone wishing to use, 5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions 6 * modify, copy, or redistribute it subject to the terms and conditions
@@ -51,13 +51,9 @@ void gfs2_tune_init(struct gfs2_tune *gt)
51{ 51{
52 spin_lock_init(&gt->gt_spin); 52 spin_lock_init(&gt->gt_spin);
53 53
54 gt->gt_ilimit = 100;
55 gt->gt_ilimit_tries = 3;
56 gt->gt_ilimit_min = 1;
57 gt->gt_demote_secs = 300; 54 gt->gt_demote_secs = 300;
58 gt->gt_incore_log_blocks = 1024; 55 gt->gt_incore_log_blocks = 1024;
59 gt->gt_log_flush_secs = 60; 56 gt->gt_log_flush_secs = 60;
60 gt->gt_jindex_refresh_secs = 60;
61 gt->gt_recoverd_secs = 60; 57 gt->gt_recoverd_secs = 60;
62 gt->gt_logd_secs = 1; 58 gt->gt_logd_secs = 1;
63 gt->gt_quotad_secs = 5; 59 gt->gt_quotad_secs = 5;
@@ -71,10 +67,8 @@ void gfs2_tune_init(struct gfs2_tune *gt)
71 gt->gt_new_files_jdata = 0; 67 gt->gt_new_files_jdata = 0;
72 gt->gt_new_files_directio = 0; 68 gt->gt_new_files_directio = 0;
73 gt->gt_max_readahead = 1 << 18; 69 gt->gt_max_readahead = 1 << 18;
74 gt->gt_lockdump_size = 131072;
75 gt->gt_stall_secs = 600; 70 gt->gt_stall_secs = 600;
76 gt->gt_complain_secs = 10; 71 gt->gt_complain_secs = 10;
77 gt->gt_reclaim_limit = 5000;
78 gt->gt_statfs_quantum = 30; 72 gt->gt_statfs_quantum = 30;
79 gt->gt_statfs_slow = 0; 73 gt->gt_statfs_slow = 0;
80} 74}
@@ -393,6 +387,7 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
393 if (!jd) 387 if (!jd)
394 break; 388 break;
395 389
390 INIT_LIST_HEAD(&jd->extent_list);
396 jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL); 391 jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1, NULL);
397 if (!jd->jd_inode || IS_ERR(jd->jd_inode)) { 392 if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
398 if (!jd->jd_inode) 393 if (!jd->jd_inode)
@@ -422,8 +417,9 @@ int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
422 417
423void gfs2_jindex_free(struct gfs2_sbd *sdp) 418void gfs2_jindex_free(struct gfs2_sbd *sdp)
424{ 419{
425 struct list_head list; 420 struct list_head list, *head;
426 struct gfs2_jdesc *jd; 421 struct gfs2_jdesc *jd;
422 struct gfs2_journal_extent *jext;
427 423
428 spin_lock(&sdp->sd_jindex_spin); 424 spin_lock(&sdp->sd_jindex_spin);
429 list_add(&list, &sdp->sd_jindex_list); 425 list_add(&list, &sdp->sd_jindex_list);
@@ -433,6 +429,14 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp)
433 429
434 while (!list_empty(&list)) { 430 while (!list_empty(&list)) {
435 jd = list_entry(list.next, struct gfs2_jdesc, jd_list); 431 jd = list_entry(list.next, struct gfs2_jdesc, jd_list);
432 head = &jd->extent_list;
433 while (!list_empty(head)) {
434 jext = list_entry(head->next,
435 struct gfs2_journal_extent,
436 extent_list);
437 list_del(&jext->extent_list);
438 kfree(jext);
439 }
436 list_del(&jd->jd_list); 440 list_del(&jd->jd_list);
437 iput(jd->jd_inode); 441 iput(jd->jd_inode);
438 kfree(jd); 442 kfree(jd);
@@ -543,7 +547,6 @@ int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
543 if (error) 547 if (error)
544 return error; 548 return error;
545 549
546 gfs2_meta_cache_flush(ip);
547 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA); 550 j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
548 551
549 error = gfs2_find_jhead(sdp->sd_jdesc, &head); 552 error = gfs2_find_jhead(sdp->sd_jdesc, &head);
@@ -686,9 +689,7 @@ void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
686 if (error) 689 if (error)
687 return; 690 return;
688 691
689 mutex_lock(&sdp->sd_statfs_mutex);
690 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); 692 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
691 mutex_unlock(&sdp->sd_statfs_mutex);
692 693
693 spin_lock(&sdp->sd_statfs_spin); 694 spin_lock(&sdp->sd_statfs_spin);
694 l_sc->sc_total += total; 695 l_sc->sc_total += total;
@@ -736,9 +737,7 @@ int gfs2_statfs_sync(struct gfs2_sbd *sdp)
736 if (error) 737 if (error)
737 goto out_bh2; 738 goto out_bh2;
738 739
739 mutex_lock(&sdp->sd_statfs_mutex);
740 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1); 740 gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
741 mutex_unlock(&sdp->sd_statfs_mutex);
742 741
743 spin_lock(&sdp->sd_statfs_spin); 742 spin_lock(&sdp->sd_statfs_spin);
744 m_sc->sc_total += l_sc->sc_total; 743 m_sc->sc_total += l_sc->sc_total;
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 06e0b7768d97..eaa3b7b2f99e 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -32,7 +32,8 @@ spinlock_t gfs2_sys_margs_lock;
32 32
33static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) 33static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
34{ 34{
35 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_vfs->s_id); 35 return snprintf(buf, PAGE_SIZE, "%u:%u\n",
36 MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev));
36} 37}
37 38
38static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) 39static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
@@ -221,9 +222,7 @@ static struct kobj_type gfs2_ktype = {
221 .sysfs_ops = &gfs2_attr_ops, 222 .sysfs_ops = &gfs2_attr_ops,
222}; 223};
223 224
224static struct kset gfs2_kset = { 225static struct kset *gfs2_kset;
225 .ktype = &gfs2_ktype,
226};
227 226
228/* 227/*
229 * display struct lm_lockstruct fields 228 * display struct lm_lockstruct fields
@@ -427,13 +426,11 @@ TUNE_ATTR_2(name, name##_store)
427TUNE_ATTR(demote_secs, 0); 426TUNE_ATTR(demote_secs, 0);
428TUNE_ATTR(incore_log_blocks, 0); 427TUNE_ATTR(incore_log_blocks, 0);
429TUNE_ATTR(log_flush_secs, 0); 428TUNE_ATTR(log_flush_secs, 0);
430TUNE_ATTR(jindex_refresh_secs, 0);
431TUNE_ATTR(quota_warn_period, 0); 429TUNE_ATTR(quota_warn_period, 0);
432TUNE_ATTR(quota_quantum, 0); 430TUNE_ATTR(quota_quantum, 0);
433TUNE_ATTR(atime_quantum, 0); 431TUNE_ATTR(atime_quantum, 0);
434TUNE_ATTR(max_readahead, 0); 432TUNE_ATTR(max_readahead, 0);
435TUNE_ATTR(complain_secs, 0); 433TUNE_ATTR(complain_secs, 0);
436TUNE_ATTR(reclaim_limit, 0);
437TUNE_ATTR(statfs_slow, 0); 434TUNE_ATTR(statfs_slow, 0);
438TUNE_ATTR(new_files_jdata, 0); 435TUNE_ATTR(new_files_jdata, 0);
439TUNE_ATTR(new_files_directio, 0); 436TUNE_ATTR(new_files_directio, 0);
@@ -450,13 +447,11 @@ static struct attribute *tune_attrs[] = {
450 &tune_attr_demote_secs.attr, 447 &tune_attr_demote_secs.attr,
451 &tune_attr_incore_log_blocks.attr, 448 &tune_attr_incore_log_blocks.attr,
452 &tune_attr_log_flush_secs.attr, 449 &tune_attr_log_flush_secs.attr,
453 &tune_attr_jindex_refresh_secs.attr,
454 &tune_attr_quota_warn_period.attr, 450 &tune_attr_quota_warn_period.attr,
455 &tune_attr_quota_quantum.attr, 451 &tune_attr_quota_quantum.attr,
456 &tune_attr_atime_quantum.attr, 452 &tune_attr_atime_quantum.attr,
457 &tune_attr_max_readahead.attr, 453 &tune_attr_max_readahead.attr,
458 &tune_attr_complain_secs.attr, 454 &tune_attr_complain_secs.attr,
459 &tune_attr_reclaim_limit.attr,
460 &tune_attr_statfs_slow.attr, 455 &tune_attr_statfs_slow.attr,
461 &tune_attr_quota_simul_sync.attr, 456 &tune_attr_quota_simul_sync.attr,
462 &tune_attr_quota_cache_secs.attr, 457 &tune_attr_quota_cache_secs.attr,
@@ -495,14 +490,9 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
495{ 490{
496 int error; 491 int error;
497 492
498 sdp->sd_kobj.kset = &gfs2_kset; 493 sdp->sd_kobj.kset = gfs2_kset;
499 sdp->sd_kobj.ktype = &gfs2_ktype; 494 error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
500 495 "%s", sdp->sd_table_name);
501 error = kobject_set_name(&sdp->sd_kobj, "%s", sdp->sd_table_name);
502 if (error)
503 goto fail;
504
505 error = kobject_register(&sdp->sd_kobj);
506 if (error) 496 if (error)
507 goto fail; 497 goto fail;
508 498
@@ -522,6 +512,7 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
522 if (error) 512 if (error)
523 goto fail_args; 513 goto fail_args;
524 514
515 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
525 return 0; 516 return 0;
526 517
527fail_args: 518fail_args:
@@ -531,7 +522,7 @@ fail_counters:
531fail_lockstruct: 522fail_lockstruct:
532 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); 523 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
533fail_reg: 524fail_reg:
534 kobject_unregister(&sdp->sd_kobj); 525 kobject_put(&sdp->sd_kobj);
535fail: 526fail:
536 fs_err(sdp, "error %d adding sysfs files", error); 527 fs_err(sdp, "error %d adding sysfs files", error);
537 return error; 528 return error;
@@ -543,21 +534,22 @@ void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
543 sysfs_remove_group(&sdp->sd_kobj, &args_group); 534 sysfs_remove_group(&sdp->sd_kobj, &args_group);
544 sysfs_remove_group(&sdp->sd_kobj, &counters_group); 535 sysfs_remove_group(&sdp->sd_kobj, &counters_group);
545 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); 536 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
546 kobject_unregister(&sdp->sd_kobj); 537 kobject_put(&sdp->sd_kobj);
547} 538}
548 539
549int gfs2_sys_init(void) 540int gfs2_sys_init(void)
550{ 541{
551 gfs2_sys_margs = NULL; 542 gfs2_sys_margs = NULL;
552 spin_lock_init(&gfs2_sys_margs_lock); 543 spin_lock_init(&gfs2_sys_margs_lock);
553 kobject_set_name(&gfs2_kset.kobj, "gfs2"); 544 gfs2_kset = kset_create_and_add("gfs2", NULL, fs_kobj);
554 kobj_set_kset_s(&gfs2_kset, fs_subsys); 545 if (!gfs2_kset)
555 return kset_register(&gfs2_kset); 546 return -ENOMEM;
547 return 0;
556} 548}
557 549
558void gfs2_sys_uninit(void) 550void gfs2_sys_uninit(void)
559{ 551{
560 kfree(gfs2_sys_margs); 552 kfree(gfs2_sys_margs);
561 kset_unregister(&gfs2_kset); 553 kset_unregister(gfs2_kset);
562} 554}
563 555
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index 717983e2c2ae..73e5d92a657c 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -114,11 +114,6 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
114 gfs2_log_flush(sdp, NULL); 114 gfs2_log_flush(sdp, NULL);
115} 115}
116 116
117void gfs2_trans_add_gl(struct gfs2_glock *gl)
118{
119 lops_add(gl->gl_sbd, &gl->gl_le);
120}
121
122/** 117/**
123 * gfs2_trans_add_bh - Add a to-be-modified buffer to the current transaction 118 * gfs2_trans_add_bh - Add a to-be-modified buffer to the current transaction
124 * @gl: the glock the buffer belongs to 119 * @gl: the glock the buffer belongs to
diff --git a/fs/gfs2/trans.h b/fs/gfs2/trans.h
index 043d5f4b9c4c..e826f0dab80a 100644
--- a/fs/gfs2/trans.h
+++ b/fs/gfs2/trans.h
@@ -30,7 +30,6 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
30 30
31void gfs2_trans_end(struct gfs2_sbd *sdp); 31void gfs2_trans_end(struct gfs2_sbd *sdp);
32 32
33void gfs2_trans_add_gl(struct gfs2_glock *gl);
34void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta); 33void gfs2_trans_add_bh(struct gfs2_glock *gl, struct buffer_head *bh, int meta);
35void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd); 34void gfs2_trans_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd);
36void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno); 35void gfs2_trans_add_unrevoke(struct gfs2_sbd *sdp, u64 blkno);
diff --git a/fs/hfs/bfind.c b/fs/hfs/bfind.c
index f13f1494d4fe..f8452a0eab56 100644
--- a/fs/hfs/bfind.c
+++ b/fs/hfs/bfind.c
@@ -52,6 +52,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
52 rec = (e + b) / 2; 52 rec = (e + b) / 2;
53 len = hfs_brec_lenoff(bnode, rec, &off); 53 len = hfs_brec_lenoff(bnode, rec, &off);
54 keylen = hfs_brec_keylen(bnode, rec); 54 keylen = hfs_brec_keylen(bnode, rec);
55 if (keylen == HFS_BAD_KEYLEN) {
56 res = -EINVAL;
57 goto done;
58 }
55 hfs_bnode_read(bnode, fd->key, off, keylen); 59 hfs_bnode_read(bnode, fd->key, off, keylen);
56 cmpval = bnode->tree->keycmp(fd->key, fd->search_key); 60 cmpval = bnode->tree->keycmp(fd->key, fd->search_key);
57 if (!cmpval) { 61 if (!cmpval) {
@@ -67,6 +71,10 @@ int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd)
67 if (rec != e && e >= 0) { 71 if (rec != e && e >= 0) {
68 len = hfs_brec_lenoff(bnode, e, &off); 72 len = hfs_brec_lenoff(bnode, e, &off);
69 keylen = hfs_brec_keylen(bnode, e); 73 keylen = hfs_brec_keylen(bnode, e);
74 if (keylen == HFS_BAD_KEYLEN) {
75 res = -EINVAL;
76 goto done;
77 }
70 hfs_bnode_read(bnode, fd->key, off, keylen); 78 hfs_bnode_read(bnode, fd->key, off, keylen);
71 } 79 }
72done: 80done:
@@ -198,6 +206,10 @@ int hfs_brec_goto(struct hfs_find_data *fd, int cnt)
198 206
199 len = hfs_brec_lenoff(bnode, fd->record, &off); 207 len = hfs_brec_lenoff(bnode, fd->record, &off);
200 keylen = hfs_brec_keylen(bnode, fd->record); 208 keylen = hfs_brec_keylen(bnode, fd->record);
209 if (keylen == HFS_BAD_KEYLEN) {
210 res = -EINVAL;
211 goto out;
212 }
201 fd->keyoffset = off; 213 fd->keyoffset = off;
202 fd->keylength = keylen; 214 fd->keylength = keylen;
203 fd->entryoffset = off + keylen; 215 fd->entryoffset = off + keylen;
diff --git a/fs/hfs/brec.c b/fs/hfs/brec.c
index 5c87cf4801fc..8626ee375ea8 100644
--- a/fs/hfs/brec.c
+++ b/fs/hfs/brec.c
@@ -44,10 +44,21 @@ u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec)
44 recoff = hfs_bnode_read_u16(node, node->tree->node_size - (rec + 1) * 2); 44 recoff = hfs_bnode_read_u16(node, node->tree->node_size - (rec + 1) * 2);
45 if (!recoff) 45 if (!recoff)
46 return 0; 46 return 0;
47 if (node->tree->attributes & HFS_TREE_BIGKEYS) 47 if (node->tree->attributes & HFS_TREE_BIGKEYS) {
48 retval = hfs_bnode_read_u16(node, recoff) + 2; 48 retval = hfs_bnode_read_u16(node, recoff) + 2;
49 else 49 if (retval > node->tree->max_key_len + 2) {
50 printk(KERN_ERR "hfs: keylen %d too large\n",
51 retval);
52 retval = HFS_BAD_KEYLEN;
53 }
54 } else {
50 retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1; 55 retval = (hfs_bnode_read_u8(node, recoff) | 1) + 1;
56 if (retval > node->tree->max_key_len + 1) {
57 printk(KERN_ERR "hfs: keylen %d too large\n",
58 retval);
59 retval = HFS_BAD_KEYLEN;
60 }
61 }
51 } 62 }
52 return retval; 63 return retval;
53} 64}
diff --git a/fs/hfs/btree.c b/fs/hfs/btree.c
index 8a3a650abc87..110dd3515dc8 100644
--- a/fs/hfs/btree.c
+++ b/fs/hfs/btree.c
@@ -61,7 +61,7 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
61 mapping = tree->inode->i_mapping; 61 mapping = tree->inode->i_mapping;
62 page = read_mapping_page(mapping, 0, NULL); 62 page = read_mapping_page(mapping, 0, NULL);
63 if (IS_ERR(page)) 63 if (IS_ERR(page))
64 goto free_tree; 64 goto free_inode;
65 65
66 /* Load the header */ 66 /* Load the header */
67 head = (struct hfs_btree_header_rec *)(kmap(page) + sizeof(struct hfs_bnode_desc)); 67 head = (struct hfs_btree_header_rec *)(kmap(page) + sizeof(struct hfs_bnode_desc));
@@ -81,6 +81,17 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
81 goto fail_page; 81 goto fail_page;
82 if (!tree->node_count) 82 if (!tree->node_count)
83 goto fail_page; 83 goto fail_page;
84 if ((id == HFS_EXT_CNID) && (tree->max_key_len != HFS_MAX_EXT_KEYLEN)) {
85 printk(KERN_ERR "hfs: invalid extent max_key_len %d\n",
86 tree->max_key_len);
87 goto fail_page;
88 }
89 if ((id == HFS_CAT_CNID) && (tree->max_key_len != HFS_MAX_CAT_KEYLEN)) {
90 printk(KERN_ERR "hfs: invalid catalog max_key_len %d\n",
91 tree->max_key_len);
92 goto fail_page;
93 }
94
84 tree->node_size_shift = ffs(size) - 1; 95 tree->node_size_shift = ffs(size) - 1;
85 tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; 96 tree->pages_per_bnode = (tree->node_size + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
86 97
@@ -88,11 +99,12 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke
88 page_cache_release(page); 99 page_cache_release(page);
89 return tree; 100 return tree;
90 101
91 fail_page: 102fail_page:
92 tree->inode->i_mapping->a_ops = &hfs_aops;
93 page_cache_release(page); 103 page_cache_release(page);
94 free_tree: 104free_inode:
105 tree->inode->i_mapping->a_ops = &hfs_aops;
95 iput(tree->inode); 106 iput(tree->inode);
107free_tree:
96 kfree(tree); 108 kfree(tree);
97 return NULL; 109 return NULL;
98} 110}
diff --git a/fs/hfs/hfs.h b/fs/hfs/hfs.h
index 1445e3a56ed4..c6aae61adfe6 100644
--- a/fs/hfs/hfs.h
+++ b/fs/hfs/hfs.h
@@ -28,6 +28,8 @@
28#define HFS_MAX_NAMELEN 128 28#define HFS_MAX_NAMELEN 128
29#define HFS_MAX_VALENCE 32767U 29#define HFS_MAX_VALENCE 32767U
30 30
31#define HFS_BAD_KEYLEN 0xFF
32
31/* Meanings of the drAtrb field of the MDB, 33/* Meanings of the drAtrb field of the MDB,
32 * Reference: _Inside Macintosh: Files_ p. 2-61 34 * Reference: _Inside Macintosh: Files_ p. 2-61
33 */ 35 */
@@ -167,6 +169,9 @@ typedef union hfs_btree_key {
167 struct hfs_ext_key ext; 169 struct hfs_ext_key ext;
168} hfs_btree_key; 170} hfs_btree_key;
169 171
172#define HFS_MAX_CAT_KEYLEN (sizeof(struct hfs_cat_key) - sizeof(u8))
173#define HFS_MAX_EXT_KEYLEN (sizeof(struct hfs_ext_key) - sizeof(u8))
174
170typedef union hfs_btree_key btree_key; 175typedef union hfs_btree_key btree_key;
171 176
172struct hfs_extent { 177struct hfs_extent {
diff --git a/fs/jbd/transaction.c b/fs/jbd/transaction.c
index 08ff6c7028cc..038ed7436199 100644
--- a/fs/jbd/transaction.c
+++ b/fs/jbd/transaction.c
@@ -288,10 +288,12 @@ handle_t *journal_start(journal_t *journal, int nblocks)
288 jbd_free_handle(handle); 288 jbd_free_handle(handle);
289 current->journal_info = NULL; 289 current->journal_info = NULL;
290 handle = ERR_PTR(err); 290 handle = ERR_PTR(err);
291 goto out;
291 } 292 }
292 293
293 lock_acquire(&handle->h_lockdep_map, 0, 0, 0, 2, _THIS_IP_); 294 lock_acquire(&handle->h_lockdep_map, 0, 0, 0, 2, _THIS_IP_);
294 295
296out:
295 return handle; 297 return handle;
296} 298}
297 299
diff --git a/fs/namei.c b/fs/namei.c
index 3b993db26cee..73e2e665817a 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1605,7 +1605,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
1605 if (S_ISLNK(inode->i_mode)) 1605 if (S_ISLNK(inode->i_mode))
1606 return -ELOOP; 1606 return -ELOOP;
1607 1607
1608 if (S_ISDIR(inode->i_mode) && (flag & FMODE_WRITE)) 1608 if (S_ISDIR(inode->i_mode) && (acc_mode & MAY_WRITE))
1609 return -EISDIR; 1609 return -EISDIR;
1610 1610
1611 /* 1611 /*
@@ -1620,7 +1620,7 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
1620 return -EACCES; 1620 return -EACCES;
1621 1621
1622 flag &= ~O_TRUNC; 1622 flag &= ~O_TRUNC;
1623 } else if (IS_RDONLY(inode) && (flag & FMODE_WRITE)) 1623 } else if (IS_RDONLY(inode) && (acc_mode & MAY_WRITE))
1624 return -EROFS; 1624 return -EROFS;
1625 1625
1626 error = vfs_permission(nd, acc_mode); 1626 error = vfs_permission(nd, acc_mode);
diff --git a/fs/namespace.c b/fs/namespace.c
index 06083885b21e..61bf376e29e8 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -41,8 +41,8 @@ static struct kmem_cache *mnt_cache __read_mostly;
41static struct rw_semaphore namespace_sem; 41static struct rw_semaphore namespace_sem;
42 42
43/* /sys/fs */ 43/* /sys/fs */
44decl_subsys(fs, NULL, NULL); 44struct kobject *fs_kobj;
45EXPORT_SYMBOL_GPL(fs_subsys); 45EXPORT_SYMBOL_GPL(fs_kobj);
46 46
47static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry) 47static inline unsigned long hash(struct vfsmount *mnt, struct dentry *dentry)
48{ 48{
@@ -1861,10 +1861,9 @@ void __init mnt_init(void)
1861 if (err) 1861 if (err)
1862 printk(KERN_WARNING "%s: sysfs_init error: %d\n", 1862 printk(KERN_WARNING "%s: sysfs_init error: %d\n",
1863 __FUNCTION__, err); 1863 __FUNCTION__, err);
1864 err = subsystem_register(&fs_subsys); 1864 fs_kobj = kobject_create_and_add("fs", NULL);
1865 if (err) 1865 if (!fs_kobj)
1866 printk(KERN_WARNING "%s: subsystem_register error: %d\n", 1866 printk(KERN_WARNING "%s: kobj create error\n", __FUNCTION__);
1867 __FUNCTION__, err);
1868 init_rootfs(); 1867 init_rootfs();
1869 init_mount_tree(); 1868 init_mount_tree();
1870} 1869}
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h
index b35069a2aa9e..bd1b9d663fb9 100644
--- a/fs/nfs/nfs4_fs.h
+++ b/fs/nfs/nfs4_fs.h
@@ -115,6 +115,7 @@ struct nfs4_lock_state {
115#define NFS_LOCK_INITIALIZED 1 115#define NFS_LOCK_INITIALIZED 1
116 int ls_flags; 116 int ls_flags;
117 struct nfs_seqid_counter ls_seqid; 117 struct nfs_seqid_counter ls_seqid;
118 struct rpc_sequence ls_sequence;
118 struct nfs_unique_id ls_id; 119 struct nfs_unique_id ls_id;
119 nfs4_stateid ls_stateid; 120 nfs4_stateid ls_stateid;
120 atomic_t ls_count; 121 atomic_t ls_count;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index f03d9d5f5ba4..9e2e1c7291db 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -741,10 +741,10 @@ static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
741 if (data->rpc_status == 0) { 741 if (data->rpc_status == 0) {
742 memcpy(data->o_res.stateid.data, data->c_res.stateid.data, 742 memcpy(data->o_res.stateid.data, data->c_res.stateid.data,
743 sizeof(data->o_res.stateid.data)); 743 sizeof(data->o_res.stateid.data));
744 nfs_confirm_seqid(&data->owner->so_seqid, 0);
744 renew_lease(data->o_res.server, data->timestamp); 745 renew_lease(data->o_res.server, data->timestamp);
745 data->rpc_done = 1; 746 data->rpc_done = 1;
746 } 747 }
747 nfs_confirm_seqid(&data->owner->so_seqid, data->rpc_status);
748 nfs_increment_open_seqid(data->rpc_status, data->c_arg.seqid); 748 nfs_increment_open_seqid(data->rpc_status, data->c_arg.seqid);
749} 749}
750 750
@@ -759,7 +759,6 @@ static void nfs4_open_confirm_release(void *calldata)
759 /* In case of error, no cleanup! */ 759 /* In case of error, no cleanup! */
760 if (!data->rpc_done) 760 if (!data->rpc_done)
761 goto out_free; 761 goto out_free;
762 nfs_confirm_seqid(&data->owner->so_seqid, 0);
763 state = nfs4_opendata_to_nfs4_state(data); 762 state = nfs4_opendata_to_nfs4_state(data);
764 if (!IS_ERR(state)) 763 if (!IS_ERR(state))
765 nfs4_close_state(&data->path, state, data->o_arg.open_flags); 764 nfs4_close_state(&data->path, state, data->o_arg.open_flags);
@@ -886,7 +885,6 @@ static void nfs4_open_release(void *calldata)
886 /* In case we need an open_confirm, no cleanup! */ 885 /* In case we need an open_confirm, no cleanup! */
887 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM) 886 if (data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)
888 goto out_free; 887 goto out_free;
889 nfs_confirm_seqid(&data->owner->so_seqid, 0);
890 state = nfs4_opendata_to_nfs4_state(data); 888 state = nfs4_opendata_to_nfs4_state(data);
891 if (!IS_ERR(state)) 889 if (!IS_ERR(state))
892 nfs4_close_state(&data->path, state, data->o_arg.open_flags); 890 nfs4_close_state(&data->path, state, data->o_arg.open_flags);
@@ -3333,6 +3331,12 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
3333 3331
3334 p->arg.fh = NFS_FH(inode); 3332 p->arg.fh = NFS_FH(inode);
3335 p->arg.fl = &p->fl; 3333 p->arg.fl = &p->fl;
3334 if (!(lsp->ls_seqid.flags & NFS_SEQID_CONFIRMED)) {
3335 p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid);
3336 if (p->arg.open_seqid == NULL)
3337 goto out_free;
3338
3339 }
3336 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid); 3340 p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
3337 if (p->arg.lock_seqid == NULL) 3341 if (p->arg.lock_seqid == NULL)
3338 goto out_free; 3342 goto out_free;
@@ -3345,6 +3349,8 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
3345 memcpy(&p->fl, fl, sizeof(p->fl)); 3349 memcpy(&p->fl, fl, sizeof(p->fl));
3346 return p; 3350 return p;
3347out_free: 3351out_free:
3352 if (p->arg.open_seqid != NULL)
3353 nfs_free_seqid(p->arg.open_seqid);
3348 kfree(p); 3354 kfree(p);
3349 return NULL; 3355 return NULL;
3350} 3356}
@@ -3361,23 +3367,23 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
3361 .rpc_cred = sp->so_cred, 3367 .rpc_cred = sp->so_cred,
3362 }; 3368 };
3363 3369
3364 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
3365 return;
3366 dprintk("%s: begin!\n", __FUNCTION__); 3370 dprintk("%s: begin!\n", __FUNCTION__);
3367 /* Do we need to do an open_to_lock_owner? */ 3371 /* Do we need to do an open_to_lock_owner? */
3368 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) { 3372 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED)) {
3369 data->arg.open_seqid = nfs_alloc_seqid(&sp->so_seqid); 3373 if (nfs_wait_on_sequence(data->arg.open_seqid, task) != 0)
3370 if (data->arg.open_seqid == NULL) { 3374 return;
3371 data->rpc_status = -ENOMEM;
3372 task->tk_action = NULL;
3373 goto out;
3374 }
3375 data->arg.open_stateid = &state->stateid; 3375 data->arg.open_stateid = &state->stateid;
3376 data->arg.new_lock_owner = 1; 3376 data->arg.new_lock_owner = 1;
3377 /* Retest in case we raced... */
3378 if (!(data->arg.lock_seqid->sequence->flags & NFS_SEQID_CONFIRMED))
3379 goto do_rpc;
3377 } 3380 }
3381 if (nfs_wait_on_sequence(data->arg.lock_seqid, task) != 0)
3382 return;
3383 data->arg.new_lock_owner = 0;
3384do_rpc:
3378 data->timestamp = jiffies; 3385 data->timestamp = jiffies;
3379 rpc_call_setup(task, &msg, 0); 3386 rpc_call_setup(task, &msg, 0);
3380out:
3381 dprintk("%s: done!, ret = %d\n", __FUNCTION__, data->rpc_status); 3387 dprintk("%s: done!, ret = %d\n", __FUNCTION__, data->rpc_status);
3382} 3388}
3383 3389
@@ -3413,8 +3419,6 @@ static void nfs4_lock_release(void *calldata)
3413 struct nfs4_lockdata *data = calldata; 3419 struct nfs4_lockdata *data = calldata;
3414 3420
3415 dprintk("%s: begin!\n", __FUNCTION__); 3421 dprintk("%s: begin!\n", __FUNCTION__);
3416 if (data->arg.open_seqid != NULL)
3417 nfs_free_seqid(data->arg.open_seqid);
3418 if (data->cancelled != 0) { 3422 if (data->cancelled != 0) {
3419 struct rpc_task *task; 3423 struct rpc_task *task;
3420 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp, 3424 task = nfs4_do_unlck(&data->fl, data->ctx, data->lsp,
@@ -3424,6 +3428,8 @@ static void nfs4_lock_release(void *calldata)
3424 dprintk("%s: cancelling lock!\n", __FUNCTION__); 3428 dprintk("%s: cancelling lock!\n", __FUNCTION__);
3425 } else 3429 } else
3426 nfs_free_seqid(data->arg.lock_seqid); 3430 nfs_free_seqid(data->arg.lock_seqid);
3431 if (data->arg.open_seqid != NULL)
3432 nfs_free_seqid(data->arg.open_seqid);
3427 nfs4_put_lock_state(data->lsp); 3433 nfs4_put_lock_state(data->lsp);
3428 put_nfs_open_context(data->ctx); 3434 put_nfs_open_context(data->ctx);
3429 kfree(data); 3435 kfree(data);
diff --git a/fs/nfs/nfs4renewd.c b/fs/nfs/nfs4renewd.c
index 3ea352d82eba..5e2e4af1a0e6 100644
--- a/fs/nfs/nfs4renewd.c
+++ b/fs/nfs/nfs4renewd.c
@@ -133,9 +133,7 @@ nfs4_renewd_prepare_shutdown(struct nfs_server *server)
133void 133void
134nfs4_kill_renewd(struct nfs_client *clp) 134nfs4_kill_renewd(struct nfs_client *clp)
135{ 135{
136 down_read(&clp->cl_sem);
137 cancel_delayed_work_sync(&clp->cl_renewd); 136 cancel_delayed_work_sync(&clp->cl_renewd);
138 up_read(&clp->cl_sem);
139} 137}
140 138
141/* 139/*
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 23a9a36556bf..5a39c6f78acf 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -509,7 +509,10 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
509 lsp = kzalloc(sizeof(*lsp), GFP_KERNEL); 509 lsp = kzalloc(sizeof(*lsp), GFP_KERNEL);
510 if (lsp == NULL) 510 if (lsp == NULL)
511 return NULL; 511 return NULL;
512 lsp->ls_seqid.sequence = &state->owner->so_sequence; 512 rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue");
513 spin_lock_init(&lsp->ls_sequence.lock);
514 INIT_LIST_HEAD(&lsp->ls_sequence.list);
515 lsp->ls_seqid.sequence = &lsp->ls_sequence;
513 atomic_set(&lsp->ls_count, 1); 516 atomic_set(&lsp->ls_count, 1);
514 lsp->ls_owner = fl_owner; 517 lsp->ls_owner = fl_owner;
515 spin_lock(&clp->cl_lock); 518 spin_lock(&clp->cl_lock);
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index ea929207f274..0b0c72a072ff 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -1475,7 +1475,7 @@ static int nfs_xdev_get_sb(struct file_system_type *fs_type, int flags,
1475 error = PTR_ERR(mntroot); 1475 error = PTR_ERR(mntroot);
1476 goto error_splat_super; 1476 goto error_splat_super;
1477 } 1477 }
1478 if (mntroot->d_inode->i_op != server->nfs_client->rpc_ops->dir_inode_ops) { 1478 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1479 dput(mntroot); 1479 dput(mntroot);
1480 error = -ESTALE; 1480 error = -ESTALE;
1481 goto error_splat_super; 1481 goto error_splat_super;
@@ -1826,6 +1826,11 @@ static int nfs4_xdev_get_sb(struct file_system_type *fs_type, int flags,
1826 error = PTR_ERR(mntroot); 1826 error = PTR_ERR(mntroot);
1827 goto error_splat_super; 1827 goto error_splat_super;
1828 } 1828 }
1829 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1830 dput(mntroot);
1831 error = -ESTALE;
1832 goto error_splat_super;
1833 }
1829 1834
1830 s->s_flags |= MS_ACTIVE; 1835 s->s_flags |= MS_ACTIVE;
1831 mnt->mnt_sb = s; 1836 mnt->mnt_sb = s;
@@ -1900,6 +1905,11 @@ static int nfs4_referral_get_sb(struct file_system_type *fs_type, int flags,
1900 error = PTR_ERR(mntroot); 1905 error = PTR_ERR(mntroot);
1901 goto error_splat_super; 1906 goto error_splat_super;
1902 } 1907 }
1908 if (mntroot->d_inode->i_op != NFS_SB(s)->nfs_client->rpc_ops->dir_inode_ops) {
1909 dput(mntroot);
1910 error = -ESTALE;
1911 goto error_splat_super;
1912 }
1903 1913
1904 s->s_flags |= MS_ACTIVE; 1914 s->s_flags |= MS_ACTIVE;
1905 mnt->mnt_sb = s; 1915 mnt->mnt_sb = s;
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 2d116d2298f8..f917fd25858a 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -388,8 +388,11 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
388 * Round the length of the data which was specified up to 388 * Round the length of the data which was specified up to
389 * the next multiple of XDR units and then compare that 389 * the next multiple of XDR units and then compare that
390 * against the length which was actually received. 390 * against the length which was actually received.
391 * Note that when RPCSEC/GSS (for example) is used, the
392 * data buffer can be padded so dlen might be larger
393 * than required. It must never be smaller.
391 */ 394 */
392 if (dlen != XDR_QUADLEN(len)*4) 395 if (dlen < XDR_QUADLEN(len)*4)
393 return 0; 396 return 0;
394 397
395 if (args->count > max_blocksize) { 398 if (args->count > max_blocksize) {
diff --git a/fs/nfsd/nfsxdr.c b/fs/nfsd/nfsxdr.c
index 986f9b32083c..b86e3658a0af 100644
--- a/fs/nfsd/nfsxdr.c
+++ b/fs/nfsd/nfsxdr.c
@@ -313,8 +313,11 @@ nfssvc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
313 * Round the length of the data which was specified up to 313 * Round the length of the data which was specified up to
314 * the next multiple of XDR units and then compare that 314 * the next multiple of XDR units and then compare that
315 * against the length which was actually received. 315 * against the length which was actually received.
316 * Note that when RPCSEC/GSS (for example) is used, the
317 * data buffer can be padded so dlen might be larger
318 * than required. It must never be smaller.
316 */ 319 */
317 if (dlen != XDR_QUADLEN(len)*4) 320 if (dlen < XDR_QUADLEN(len)*4)
318 return 0; 321 return 0;
319 322
320 rqstp->rq_vec[0].iov_base = (void*)p; 323 rqstp->rq_vec[0].iov_base = (void*)p;
diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c
index a4882c8df945..23c732f27529 100644
--- a/fs/ocfs2/cluster/masklog.c
+++ b/fs/ocfs2/cluster/masklog.c
@@ -146,7 +146,7 @@ static struct kset mlog_kset = {
146 .kobj = {.ktype = &mlog_ktype}, 146 .kobj = {.ktype = &mlog_ktype},
147}; 147};
148 148
149int mlog_sys_init(struct kset *o2cb_subsys) 149int mlog_sys_init(struct kset *o2cb_kset)
150{ 150{
151 int i = 0; 151 int i = 0;
152 152
@@ -157,7 +157,7 @@ int mlog_sys_init(struct kset *o2cb_subsys)
157 mlog_attr_ptrs[i] = NULL; 157 mlog_attr_ptrs[i] = NULL;
158 158
159 kobject_set_name(&mlog_kset.kobj, "logmask"); 159 kobject_set_name(&mlog_kset.kobj, "logmask");
160 kobj_set_kset_s(&mlog_kset, *o2cb_subsys); 160 mlog_kset.kobj.kset = o2cb_kset;
161 return kset_register(&mlog_kset); 161 return kset_register(&mlog_kset);
162} 162}
163 163
diff --git a/fs/ocfs2/cluster/sys.c b/fs/ocfs2/cluster/sys.c
index 64f6f378fd09..a4b07730b2e1 100644
--- a/fs/ocfs2/cluster/sys.c
+++ b/fs/ocfs2/cluster/sys.c
@@ -28,96 +28,55 @@
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/kobject.h> 29#include <linux/kobject.h>
30#include <linux/sysfs.h> 30#include <linux/sysfs.h>
31#include <linux/fs.h>
31 32
32#include "ocfs2_nodemanager.h" 33#include "ocfs2_nodemanager.h"
33#include "masklog.h" 34#include "masklog.h"
34#include "sys.h" 35#include "sys.h"
35 36
36struct o2cb_attribute {
37 struct attribute attr;
38 ssize_t (*show)(char *buf);
39 ssize_t (*store)(const char *buf, size_t count);
40};
41
42#define O2CB_ATTR(_name, _mode, _show, _store) \
43struct o2cb_attribute o2cb_attr_##_name = __ATTR(_name, _mode, _show, _store)
44
45#define to_o2cb_attr(_attr) container_of(_attr, struct o2cb_attribute, attr)
46 37
47static ssize_t o2cb_interface_revision_show(char *buf) 38static ssize_t version_show(struct kobject *kobj, struct kobj_attribute *attr,
39 char *buf)
48{ 40{
49 return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION); 41 return snprintf(buf, PAGE_SIZE, "%u\n", O2NM_API_VERSION);
50} 42}
51 43static struct kobj_attribute attr_version =
52static O2CB_ATTR(interface_revision, S_IFREG | S_IRUGO, o2cb_interface_revision_show, NULL); 44 __ATTR(interface_revision, S_IFREG | S_IRUGO, version_show, NULL);
53 45
54static struct attribute *o2cb_attrs[] = { 46static struct attribute *o2cb_attrs[] = {
55 &o2cb_attr_interface_revision.attr, 47 &attr_version.attr,
56 NULL, 48 NULL,
57}; 49};
58 50
59static ssize_t 51static struct attribute_group o2cb_attr_group = {
60o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer); 52 .attrs = o2cb_attrs,
61static ssize_t
62o2cb_store(struct kobject * kobj, struct attribute * attr,
63 const char * buffer, size_t count);
64static struct sysfs_ops o2cb_sysfs_ops = {
65 .show = o2cb_show,
66 .store = o2cb_store,
67}; 53};
68 54
69static struct kobj_type o2cb_subsys_type = { 55static struct kset *o2cb_kset;
70 .default_attrs = o2cb_attrs,
71 .sysfs_ops = &o2cb_sysfs_ops,
72};
73
74/* gives us o2cb_subsys */
75static decl_subsys(o2cb, NULL, NULL);
76
77static ssize_t
78o2cb_show(struct kobject * kobj, struct attribute * attr, char * buffer)
79{
80 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
81 struct kset *sbs = to_kset(kobj);
82
83 BUG_ON(sbs != &o2cb_subsys);
84
85 if (o2cb_attr->show)
86 return o2cb_attr->show(buffer);
87 return -EIO;
88}
89
90static ssize_t
91o2cb_store(struct kobject * kobj, struct attribute * attr,
92 const char * buffer, size_t count)
93{
94 struct o2cb_attribute *o2cb_attr = to_o2cb_attr(attr);
95 struct kset *sbs = to_kset(kobj);
96
97 BUG_ON(sbs != &o2cb_subsys);
98
99 if (o2cb_attr->store)
100 return o2cb_attr->store(buffer, count);
101 return -EIO;
102}
103 56
104void o2cb_sys_shutdown(void) 57void o2cb_sys_shutdown(void)
105{ 58{
106 mlog_sys_shutdown(); 59 mlog_sys_shutdown();
107 subsystem_unregister(&o2cb_subsys); 60 kset_unregister(o2cb_kset);
108} 61}
109 62
110int o2cb_sys_init(void) 63int o2cb_sys_init(void)
111{ 64{
112 int ret; 65 int ret;
113 66
114 o2cb_subsys.kobj.ktype = &o2cb_subsys_type; 67 o2cb_kset = kset_create_and_add("o2cb", NULL, fs_kobj);
115 ret = subsystem_register(&o2cb_subsys); 68 if (!o2cb_kset)
69 return -ENOMEM;
70
71 ret = sysfs_create_group(&o2cb_kset->kobj, &o2cb_attr_group);
116 if (ret) 72 if (ret)
117 return ret; 73 goto error;
118 74
119 ret = mlog_sys_init(&o2cb_subsys); 75 ret = mlog_sys_init(o2cb_kset);
120 if (ret) 76 if (ret)
121 subsystem_unregister(&o2cb_subsys); 77 goto error;
78 return 0;
79error:
80 kset_unregister(o2cb_kset);
122 return ret; 81 return ret;
123} 82}
diff --git a/fs/openpromfs/inode.c b/fs/openpromfs/inode.c
index d88173840082..6b7ff1618945 100644
--- a/fs/openpromfs/inode.c
+++ b/fs/openpromfs/inode.c
@@ -131,7 +131,7 @@ static void property_stop(struct seq_file *f, void *v)
131 /* Nothing to do */ 131 /* Nothing to do */
132} 132}
133 133
134static struct seq_operations property_op = { 134static const struct seq_operations property_op = {
135 .start = property_start, 135 .start = property_start,
136 .next = property_next, 136 .next = property_next,
137 .stop = property_stop, 137 .stop = property_stop,
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 722e12e5acc7..739da701ae7b 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -195,96 +195,45 @@ check_partition(struct gendisk *hd, struct block_device *bdev)
195 return ERR_PTR(res); 195 return ERR_PTR(res);
196} 196}
197 197
198/* 198static ssize_t part_start_show(struct device *dev,
199 * sysfs bindings for partitions 199 struct device_attribute *attr, char *buf)
200 */
201
202struct part_attribute {
203 struct attribute attr;
204 ssize_t (*show)(struct hd_struct *,char *);
205 ssize_t (*store)(struct hd_struct *,const char *, size_t);
206};
207
208static ssize_t
209part_attr_show(struct kobject * kobj, struct attribute * attr, char * page)
210{ 200{
211 struct hd_struct * p = container_of(kobj,struct hd_struct,kobj); 201 struct hd_struct *p = dev_to_part(dev);
212 struct part_attribute * part_attr = container_of(attr,struct part_attribute,attr);
213 ssize_t ret = 0;
214 if (part_attr->show)
215 ret = part_attr->show(p, page);
216 return ret;
217}
218static ssize_t
219part_attr_store(struct kobject * kobj, struct attribute * attr,
220 const char *page, size_t count)
221{
222 struct hd_struct * p = container_of(kobj,struct hd_struct,kobj);
223 struct part_attribute * part_attr = container_of(attr,struct part_attribute,attr);
224 ssize_t ret = 0;
225 202
226 if (part_attr->store) 203 return sprintf(buf, "%llu\n",(unsigned long long)p->start_sect);
227 ret = part_attr->store(p, page, count);
228 return ret;
229} 204}
230 205
231static struct sysfs_ops part_sysfs_ops = { 206static ssize_t part_size_show(struct device *dev,
232 .show = part_attr_show, 207 struct device_attribute *attr, char *buf)
233 .store = part_attr_store,
234};
235
236static ssize_t part_uevent_store(struct hd_struct * p,
237 const char *page, size_t count)
238{ 208{
239 kobject_uevent(&p->kobj, KOBJ_ADD); 209 struct hd_struct *p = dev_to_part(dev);
240 return count; 210 return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
241} 211}
242static ssize_t part_dev_read(struct hd_struct * p, char *page) 212
243{ 213static ssize_t part_stat_show(struct device *dev,
244 struct gendisk *disk = container_of(p->kobj.parent,struct gendisk,kobj); 214 struct device_attribute *attr, char *buf)
245 dev_t dev = MKDEV(disk->major, disk->first_minor + p->partno);
246 return print_dev_t(page, dev);
247}
248static ssize_t part_start_read(struct hd_struct * p, char *page)
249{
250 return sprintf(page, "%llu\n",(unsigned long long)p->start_sect);
251}
252static ssize_t part_size_read(struct hd_struct * p, char *page)
253{
254 return sprintf(page, "%llu\n",(unsigned long long)p->nr_sects);
255}
256static ssize_t part_stat_read(struct hd_struct * p, char *page)
257{ 215{
258 return sprintf(page, "%8u %8llu %8u %8llu\n", 216 struct hd_struct *p = dev_to_part(dev);
217
218 return sprintf(buf, "%8u %8llu %8u %8llu\n",
259 p->ios[0], (unsigned long long)p->sectors[0], 219 p->ios[0], (unsigned long long)p->sectors[0],
260 p->ios[1], (unsigned long long)p->sectors[1]); 220 p->ios[1], (unsigned long long)p->sectors[1]);
261} 221}
262static struct part_attribute part_attr_uevent = {
263 .attr = {.name = "uevent", .mode = S_IWUSR },
264 .store = part_uevent_store
265};
266static struct part_attribute part_attr_dev = {
267 .attr = {.name = "dev", .mode = S_IRUGO },
268 .show = part_dev_read
269};
270static struct part_attribute part_attr_start = {
271 .attr = {.name = "start", .mode = S_IRUGO },
272 .show = part_start_read
273};
274static struct part_attribute part_attr_size = {
275 .attr = {.name = "size", .mode = S_IRUGO },
276 .show = part_size_read
277};
278static struct part_attribute part_attr_stat = {
279 .attr = {.name = "stat", .mode = S_IRUGO },
280 .show = part_stat_read
281};
282 222
283#ifdef CONFIG_FAIL_MAKE_REQUEST 223#ifdef CONFIG_FAIL_MAKE_REQUEST
224static ssize_t part_fail_show(struct device *dev,
225 struct device_attribute *attr, char *buf)
226{
227 struct hd_struct *p = dev_to_part(dev);
284 228
285static ssize_t part_fail_store(struct hd_struct * p, 229 return sprintf(buf, "%d\n", p->make_it_fail);
230}
231
232static ssize_t part_fail_store(struct device *dev,
233 struct device_attribute *attr,
286 const char *buf, size_t count) 234 const char *buf, size_t count)
287{ 235{
236 struct hd_struct *p = dev_to_part(dev);
288 int i; 237 int i;
289 238
290 if (count > 0 && sscanf(buf, "%d", &i) > 0) 239 if (count > 0 && sscanf(buf, "%d", &i) > 0)
@@ -292,50 +241,53 @@ static ssize_t part_fail_store(struct hd_struct * p,
292 241
293 return count; 242 return count;
294} 243}
295static ssize_t part_fail_read(struct hd_struct * p, char *page) 244#endif
296{
297 return sprintf(page, "%d\n", p->make_it_fail);
298}
299static struct part_attribute part_attr_fail = {
300 .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
301 .store = part_fail_store,
302 .show = part_fail_read
303};
304 245
246static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
247static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
248static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
249#ifdef CONFIG_FAIL_MAKE_REQUEST
250static struct device_attribute dev_attr_fail =
251 __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store);
305#endif 252#endif
306 253
307static struct attribute * default_attrs[] = { 254static struct attribute *part_attrs[] = {
308 &part_attr_uevent.attr, 255 &dev_attr_start.attr,
309 &part_attr_dev.attr, 256 &dev_attr_size.attr,
310 &part_attr_start.attr, 257 &dev_attr_stat.attr,
311 &part_attr_size.attr,
312 &part_attr_stat.attr,
313#ifdef CONFIG_FAIL_MAKE_REQUEST 258#ifdef CONFIG_FAIL_MAKE_REQUEST
314 &part_attr_fail.attr, 259 &dev_attr_fail.attr,
315#endif 260#endif
316 NULL, 261 NULL
317}; 262};
318 263
319extern struct kset block_subsys; 264static struct attribute_group part_attr_group = {
265 .attrs = part_attrs,
266};
320 267
321static void part_release(struct kobject *kobj) 268static struct attribute_group *part_attr_groups[] = {
269 &part_attr_group,
270 NULL
271};
272
273static void part_release(struct device *dev)
322{ 274{
323 struct hd_struct * p = container_of(kobj,struct hd_struct,kobj); 275 struct hd_struct *p = dev_to_part(dev);
324 kfree(p); 276 kfree(p);
325} 277}
326 278
327struct kobj_type ktype_part = { 279struct device_type part_type = {
280 .name = "partition",
281 .groups = part_attr_groups,
328 .release = part_release, 282 .release = part_release,
329 .default_attrs = default_attrs,
330 .sysfs_ops = &part_sysfs_ops,
331}; 283};
332 284
333static inline void partition_sysfs_add_subdir(struct hd_struct *p) 285static inline void partition_sysfs_add_subdir(struct hd_struct *p)
334{ 286{
335 struct kobject *k; 287 struct kobject *k;
336 288
337 k = kobject_get(&p->kobj); 289 k = kobject_get(&p->dev.kobj);
338 p->holder_dir = kobject_add_dir(k, "holders"); 290 p->holder_dir = kobject_create_and_add("holders", k);
339 kobject_put(k); 291 kobject_put(k);
340} 292}
341 293
@@ -343,15 +295,16 @@ static inline void disk_sysfs_add_subdirs(struct gendisk *disk)
343{ 295{
344 struct kobject *k; 296 struct kobject *k;
345 297
346 k = kobject_get(&disk->kobj); 298 k = kobject_get(&disk->dev.kobj);
347 disk->holder_dir = kobject_add_dir(k, "holders"); 299 disk->holder_dir = kobject_create_and_add("holders", k);
348 disk->slave_dir = kobject_add_dir(k, "slaves"); 300 disk->slave_dir = kobject_create_and_add("slaves", k);
349 kobject_put(k); 301 kobject_put(k);
350} 302}
351 303
352void delete_partition(struct gendisk *disk, int part) 304void delete_partition(struct gendisk *disk, int part)
353{ 305{
354 struct hd_struct *p = disk->part[part-1]; 306 struct hd_struct *p = disk->part[part-1];
307
355 if (!p) 308 if (!p)
356 return; 309 return;
357 if (!p->nr_sects) 310 if (!p->nr_sects)
@@ -361,113 +314,55 @@ void delete_partition(struct gendisk *disk, int part)
361 p->nr_sects = 0; 314 p->nr_sects = 0;
362 p->ios[0] = p->ios[1] = 0; 315 p->ios[0] = p->ios[1] = 0;
363 p->sectors[0] = p->sectors[1] = 0; 316 p->sectors[0] = p->sectors[1] = 0;
364 sysfs_remove_link(&p->kobj, "subsystem"); 317 kobject_put(p->holder_dir);
365 kobject_unregister(p->holder_dir); 318 device_del(&p->dev);
366 kobject_uevent(&p->kobj, KOBJ_REMOVE); 319 put_device(&p->dev);
367 kobject_del(&p->kobj);
368 kobject_put(&p->kobj);
369} 320}
370 321
371void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags) 322void add_partition(struct gendisk *disk, int part, sector_t start, sector_t len, int flags)
372{ 323{
373 struct hd_struct *p; 324 struct hd_struct *p;
325 int err;
374 326
375 p = kzalloc(sizeof(*p), GFP_KERNEL); 327 p = kzalloc(sizeof(*p), GFP_KERNEL);
376 if (!p) 328 if (!p)
377 return; 329 return;
378 330
379 p->start_sect = start; 331 p->start_sect = start;
380 p->nr_sects = len; 332 p->nr_sects = len;
381 p->partno = part; 333 p->partno = part;
382 p->policy = disk->policy; 334 p->policy = disk->policy;
383 335
384 if (isdigit(disk->kobj.k_name[strlen(disk->kobj.k_name)-1])) 336 if (isdigit(disk->dev.bus_id[strlen(disk->dev.bus_id)-1]))
385 kobject_set_name(&p->kobj, "%sp%d", 337 snprintf(p->dev.bus_id, BUS_ID_SIZE,
386 kobject_name(&disk->kobj), part); 338 "%sp%d", disk->dev.bus_id, part);
387 else 339 else
388 kobject_set_name(&p->kobj, "%s%d", 340 snprintf(p->dev.bus_id, BUS_ID_SIZE,
389 kobject_name(&disk->kobj),part); 341 "%s%d", disk->dev.bus_id, part);
390 p->kobj.parent = &disk->kobj; 342
391 p->kobj.ktype = &ktype_part; 343 device_initialize(&p->dev);
392 kobject_init(&p->kobj); 344 p->dev.devt = MKDEV(disk->major, disk->first_minor + part);
393 kobject_add(&p->kobj); 345 p->dev.class = &block_class;
394 if (!disk->part_uevent_suppress) 346 p->dev.type = &part_type;
395 kobject_uevent(&p->kobj, KOBJ_ADD); 347 p->dev.parent = &disk->dev;
396 sysfs_create_link(&p->kobj, &block_subsys.kobj, "subsystem"); 348 disk->part[part-1] = p;
349
350 /* delay uevent until 'holders' subdir is created */
351 p->dev.uevent_suppress = 1;
352 device_add(&p->dev);
353 partition_sysfs_add_subdir(p);
354 p->dev.uevent_suppress = 0;
397 if (flags & ADDPART_FLAG_WHOLEDISK) { 355 if (flags & ADDPART_FLAG_WHOLEDISK) {
398 static struct attribute addpartattr = { 356 static struct attribute addpartattr = {
399 .name = "whole_disk", 357 .name = "whole_disk",
400 .mode = S_IRUSR | S_IRGRP | S_IROTH, 358 .mode = S_IRUSR | S_IRGRP | S_IROTH,
401 }; 359 };
402 360 err = sysfs_create_file(&p->dev.kobj, &addpartattr);
403 sysfs_create_file(&p->kobj, &addpartattr);
404 } 361 }
405 partition_sysfs_add_subdir(p);
406 disk->part[part-1] = p;
407}
408 362
409static char *make_block_name(struct gendisk *disk) 363 /* suppress uevent if the disk supresses it */
410{ 364 if (!disk->dev.uevent_suppress)
411 char *name; 365 kobject_uevent(&p->dev.kobj, KOBJ_ADD);
412 static char *block_str = "block:";
413 int size;
414 char *s;
415
416 size = strlen(block_str) + strlen(disk->disk_name) + 1;
417 name = kmalloc(size, GFP_KERNEL);
418 if (!name)
419 return NULL;
420 strcpy(name, block_str);
421 strcat(name, disk->disk_name);
422 /* ewww... some of these buggers have / in name... */
423 s = strchr(name, '/');
424 if (s)
425 *s = '!';
426 return name;
427}
428
429static int disk_sysfs_symlinks(struct gendisk *disk)
430{
431 struct device *target = get_device(disk->driverfs_dev);
432 int err;
433 char *disk_name = NULL;
434
435 if (target) {
436 disk_name = make_block_name(disk);
437 if (!disk_name) {
438 err = -ENOMEM;
439 goto err_out;
440 }
441
442 err = sysfs_create_link(&disk->kobj, &target->kobj, "device");
443 if (err)
444 goto err_out_disk_name;
445
446 err = sysfs_create_link(&target->kobj, &disk->kobj, disk_name);
447 if (err)
448 goto err_out_dev_link;
449 }
450
451 err = sysfs_create_link(&disk->kobj, &block_subsys.kobj,
452 "subsystem");
453 if (err)
454 goto err_out_disk_name_lnk;
455
456 kfree(disk_name);
457
458 return 0;
459
460err_out_disk_name_lnk:
461 if (target) {
462 sysfs_remove_link(&target->kobj, disk_name);
463err_out_dev_link:
464 sysfs_remove_link(&disk->kobj, "device");
465err_out_disk_name:
466 kfree(disk_name);
467err_out:
468 put_device(target);
469 }
470 return err;
471} 366}
472 367
473/* Not exported, helper to add_disk(). */ 368/* Not exported, helper to add_disk(). */
@@ -479,19 +374,29 @@ void register_disk(struct gendisk *disk)
479 struct hd_struct *p; 374 struct hd_struct *p;
480 int err; 375 int err;
481 376
482 kobject_set_name(&disk->kobj, "%s", disk->disk_name); 377 disk->dev.parent = disk->driverfs_dev;
483 /* ewww... some of these buggers have / in name... */ 378 disk->dev.devt = MKDEV(disk->major, disk->first_minor);
484 s = strchr(disk->kobj.k_name, '/'); 379
380 strlcpy(disk->dev.bus_id, disk->disk_name, KOBJ_NAME_LEN);
381 /* ewww... some of these buggers have / in the name... */
382 s = strchr(disk->dev.bus_id, '/');
485 if (s) 383 if (s)
486 *s = '!'; 384 *s = '!';
487 if ((err = kobject_add(&disk->kobj))) 385
386 /* delay uevents, until we scanned partition table */
387 disk->dev.uevent_suppress = 1;
388
389 if (device_add(&disk->dev))
488 return; 390 return;
489 err = disk_sysfs_symlinks(disk); 391#ifndef CONFIG_SYSFS_DEPRECATED
392 err = sysfs_create_link(block_depr, &disk->dev.kobj,
393 kobject_name(&disk->dev.kobj));
490 if (err) { 394 if (err) {
491 kobject_del(&disk->kobj); 395 device_del(&disk->dev);
492 return; 396 return;
493 } 397 }
494 disk_sysfs_add_subdirs(disk); 398#endif
399 disk_sysfs_add_subdirs(disk);
495 400
496 /* No minors to use for partitions */ 401 /* No minors to use for partitions */
497 if (disk->minors == 1) 402 if (disk->minors == 1)
@@ -505,25 +410,23 @@ void register_disk(struct gendisk *disk)
505 if (!bdev) 410 if (!bdev)
506 goto exit; 411 goto exit;
507 412
508 /* scan partition table, but suppress uevents */
509 bdev->bd_invalidated = 1; 413 bdev->bd_invalidated = 1;
510 disk->part_uevent_suppress = 1;
511 err = blkdev_get(bdev, FMODE_READ, 0); 414 err = blkdev_get(bdev, FMODE_READ, 0);
512 disk->part_uevent_suppress = 0;
513 if (err < 0) 415 if (err < 0)
514 goto exit; 416 goto exit;
515 blkdev_put(bdev); 417 blkdev_put(bdev);
516 418
517exit: 419exit:
518 /* announce disk after possible partitions are already created */ 420 /* announce disk after possible partitions are created */
519 kobject_uevent(&disk->kobj, KOBJ_ADD); 421 disk->dev.uevent_suppress = 0;
422 kobject_uevent(&disk->dev.kobj, KOBJ_ADD);
520 423
521 /* announce possible partitions */ 424 /* announce possible partitions */
522 for (i = 1; i < disk->minors; i++) { 425 for (i = 1; i < disk->minors; i++) {
523 p = disk->part[i-1]; 426 p = disk->part[i-1];
524 if (!p || !p->nr_sects) 427 if (!p || !p->nr_sects)
525 continue; 428 continue;
526 kobject_uevent(&p->kobj, KOBJ_ADD); 429 kobject_uevent(&p->dev.kobj, KOBJ_ADD);
527 } 430 }
528} 431}
529 432
@@ -602,19 +505,11 @@ void del_gendisk(struct gendisk *disk)
602 disk_stat_set_all(disk, 0); 505 disk_stat_set_all(disk, 0);
603 disk->stamp = 0; 506 disk->stamp = 0;
604 507
605 kobject_uevent(&disk->kobj, KOBJ_REMOVE); 508 kobject_put(disk->holder_dir);
606 kobject_unregister(disk->holder_dir); 509 kobject_put(disk->slave_dir);
607 kobject_unregister(disk->slave_dir); 510 disk->driverfs_dev = NULL;
608 if (disk->driverfs_dev) { 511#ifndef CONFIG_SYSFS_DEPRECATED
609 char *disk_name = make_block_name(disk); 512 sysfs_remove_link(block_depr, disk->dev.bus_id);
610 sysfs_remove_link(&disk->kobj, "device"); 513#endif
611 if (disk_name) { 514 device_del(&disk->dev);
612 sysfs_remove_link(&disk->driverfs_dev->kobj, disk_name);
613 kfree(disk_name);
614 }
615 put_device(disk->driverfs_dev);
616 disk->driverfs_dev = NULL;
617 }
618 sysfs_remove_link(&disk->kobj, "subsystem");
619 kobject_del(&disk->kobj);
620} 515}
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 65c62e1bfd6f..eb97f2897e2b 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -169,7 +169,7 @@ static inline char *task_state(struct task_struct *p, char *buffer)
169 ppid = pid_alive(p) ? 169 ppid = pid_alive(p) ?
170 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0; 170 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
171 tpid = pid_alive(p) && p->ptrace ? 171 tpid = pid_alive(p) && p->ptrace ?
172 task_ppid_nr_ns(rcu_dereference(p->parent), ns) : 0; 172 task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0;
173 buffer += sprintf(buffer, 173 buffer += sprintf(buffer,
174 "State:\t%s\n" 174 "State:\t%s\n"
175 "Tgid:\t%d\n" 175 "Tgid:\t%d\n"
@@ -464,8 +464,8 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
464 } 464 }
465 465
466 sid = task_session_nr_ns(task, ns); 466 sid = task_session_nr_ns(task, ns);
467 ppid = task_tgid_nr_ns(task->real_parent, ns);
467 pgid = task_pgrp_nr_ns(task, ns); 468 pgid = task_pgrp_nr_ns(task, ns);
468 ppid = task_ppid_nr_ns(task, ns);
469 469
470 unlock_task_sighand(task, &flags); 470 unlock_task_sighand(task, &flags);
471 } 471 }
diff --git a/fs/read_write.c b/fs/read_write.c
index ea1f94cc722e..c4d3d17923f1 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -197,25 +197,27 @@ int rw_verify_area(int read_write, struct file *file, loff_t *ppos, size_t count
197{ 197{
198 struct inode *inode; 198 struct inode *inode;
199 loff_t pos; 199 loff_t pos;
200 int retval = -EINVAL;
200 201
201 inode = file->f_path.dentry->d_inode; 202 inode = file->f_path.dentry->d_inode;
202 if (unlikely((ssize_t) count < 0)) 203 if (unlikely((ssize_t) count < 0))
203 goto Einval; 204 return retval;
204 pos = *ppos; 205 pos = *ppos;
205 if (unlikely((pos < 0) || (loff_t) (pos + count) < 0)) 206 if (unlikely((pos < 0) || (loff_t) (pos + count) < 0))
206 goto Einval; 207 return retval;
207 208
208 if (unlikely(inode->i_flock && mandatory_lock(inode))) { 209 if (unlikely(inode->i_flock && mandatory_lock(inode))) {
209 int retval = locks_mandatory_area( 210 retval = locks_mandatory_area(
210 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE, 211 read_write == READ ? FLOCK_VERIFY_READ : FLOCK_VERIFY_WRITE,
211 inode, file, pos, count); 212 inode, file, pos, count);
212 if (retval < 0) 213 if (retval < 0)
213 return retval; 214 return retval;
214 } 215 }
216 retval = security_file_permission(file,
217 read_write == READ ? MAY_READ : MAY_WRITE);
218 if (retval)
219 return retval;
215 return count > MAX_RW_COUNT ? MAX_RW_COUNT : count; 220 return count > MAX_RW_COUNT ? MAX_RW_COUNT : count;
216
217Einval:
218 return -EINVAL;
219} 221}
220 222
221static void wait_on_retry_sync_kiocb(struct kiocb *iocb) 223static void wait_on_retry_sync_kiocb(struct kiocb *iocb)
@@ -267,18 +269,15 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
267 ret = rw_verify_area(READ, file, pos, count); 269 ret = rw_verify_area(READ, file, pos, count);
268 if (ret >= 0) { 270 if (ret >= 0) {
269 count = ret; 271 count = ret;
270 ret = security_file_permission (file, MAY_READ); 272 if (file->f_op->read)
271 if (!ret) { 273 ret = file->f_op->read(file, buf, count, pos);
272 if (file->f_op->read) 274 else
273 ret = file->f_op->read(file, buf, count, pos); 275 ret = do_sync_read(file, buf, count, pos);
274 else 276 if (ret > 0) {
275 ret = do_sync_read(file, buf, count, pos); 277 fsnotify_access(file->f_path.dentry);
276 if (ret > 0) { 278 add_rchar(current, ret);
277 fsnotify_access(file->f_path.dentry);
278 add_rchar(current, ret);
279 }
280 inc_syscr(current);
281 } 279 }
280 inc_syscr(current);
282 } 281 }
283 282
284 return ret; 283 return ret;
@@ -325,18 +324,15 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_
325 ret = rw_verify_area(WRITE, file, pos, count); 324 ret = rw_verify_area(WRITE, file, pos, count);
326 if (ret >= 0) { 325 if (ret >= 0) {
327 count = ret; 326 count = ret;
328 ret = security_file_permission (file, MAY_WRITE); 327 if (file->f_op->write)
329 if (!ret) { 328 ret = file->f_op->write(file, buf, count, pos);
330 if (file->f_op->write) 329 else
331 ret = file->f_op->write(file, buf, count, pos); 330 ret = do_sync_write(file, buf, count, pos);
332 else 331 if (ret > 0) {
333 ret = do_sync_write(file, buf, count, pos); 332 fsnotify_modify(file->f_path.dentry);
334 if (ret > 0) { 333 add_wchar(current, ret);
335 fsnotify_modify(file->f_path.dentry);
336 add_wchar(current, ret);
337 }
338 inc_syscw(current);
339 } 334 }
335 inc_syscw(current);
340 } 336 }
341 337
342 return ret; 338 return ret;
@@ -603,9 +599,6 @@ static ssize_t do_readv_writev(int type, struct file *file,
603 ret = rw_verify_area(type, file, pos, tot_len); 599 ret = rw_verify_area(type, file, pos, tot_len);
604 if (ret < 0) 600 if (ret < 0)
605 goto out; 601 goto out;
606 ret = security_file_permission(file, type == READ ? MAY_READ : MAY_WRITE);
607 if (ret)
608 goto out;
609 602
610 fnv = NULL; 603 fnv = NULL;
611 if (type == READ) { 604 if (type == READ) {
@@ -737,10 +730,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
737 goto fput_in; 730 goto fput_in;
738 count = retval; 731 count = retval;
739 732
740 retval = security_file_permission (in_file, MAY_READ);
741 if (retval)
742 goto fput_in;
743
744 /* 733 /*
745 * Get output file, and verify that it is ok.. 734 * Get output file, and verify that it is ok..
746 */ 735 */
@@ -759,10 +748,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
759 goto fput_out; 748 goto fput_out;
760 count = retval; 749 count = retval;
761 750
762 retval = security_file_permission (out_file, MAY_WRITE);
763 if (retval)
764 goto fput_out;
765
766 if (!max) 751 if (!max)
767 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes); 752 max = min(in_inode->i_sb->s_maxbytes, out_inode->i_sb->s_maxbytes);
768 753
diff --git a/fs/splice.c b/fs/splice.c
index 6bdcb6107bc3..56b802bfbfa4 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -908,10 +908,6 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
908 if (unlikely(ret < 0)) 908 if (unlikely(ret < 0))
909 return ret; 909 return ret;
910 910
911 ret = security_file_permission(out, MAY_WRITE);
912 if (unlikely(ret < 0))
913 return ret;
914
915 return out->f_op->splice_write(pipe, out, ppos, len, flags); 911 return out->f_op->splice_write(pipe, out, ppos, len, flags);
916} 912}
917 913
@@ -934,10 +930,6 @@ static long do_splice_to(struct file *in, loff_t *ppos,
934 if (unlikely(ret < 0)) 930 if (unlikely(ret < 0))
935 return ret; 931 return ret;
936 932
937 ret = security_file_permission(in, MAY_READ);
938 if (unlikely(ret < 0))
939 return ret;
940
941 return in->f_op->splice_read(in, ppos, pipe, len, flags); 933 return in->f_op->splice_read(in, ppos, pipe, len, flags);
942} 934}
943 935
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 337162935d21..4948d9bc405d 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -440,7 +440,7 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
440/** 440/**
441 * sysfs_remove_one - remove sysfs_dirent from parent 441 * sysfs_remove_one - remove sysfs_dirent from parent
442 * @acxt: addrm context to use 442 * @acxt: addrm context to use
443 * @sd: sysfs_dirent to be added 443 * @sd: sysfs_dirent to be removed
444 * 444 *
445 * Mark @sd removed and drop nlink of parent inode if @sd is a 445 * Mark @sd removed and drop nlink of parent inode if @sd is a
446 * directory. @sd is unlinked from the children list. 446 * directory. @sd is unlinked from the children list.
@@ -678,8 +678,10 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
678 sd = sysfs_find_dirent(parent_sd, dentry->d_name.name); 678 sd = sysfs_find_dirent(parent_sd, dentry->d_name.name);
679 679
680 /* no such entry */ 680 /* no such entry */
681 if (!sd) 681 if (!sd) {
682 ret = ERR_PTR(-ENOENT);
682 goto out_unlock; 683 goto out_unlock;
684 }
683 685
684 /* attach dentry and inode */ 686 /* attach dentry and inode */
685 inode = sysfs_get_inode(sd); 687 inode = sysfs_get_inode(sd);
@@ -781,6 +783,7 @@ int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
781 old_dentry = sysfs_get_dentry(sd); 783 old_dentry = sysfs_get_dentry(sd);
782 if (IS_ERR(old_dentry)) { 784 if (IS_ERR(old_dentry)) {
783 error = PTR_ERR(old_dentry); 785 error = PTR_ERR(old_dentry);
786 old_dentry = NULL;
784 goto out; 787 goto out;
785 } 788 }
786 789
@@ -848,6 +851,7 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
848 old_dentry = sysfs_get_dentry(sd); 851 old_dentry = sysfs_get_dentry(sd);
849 if (IS_ERR(old_dentry)) { 852 if (IS_ERR(old_dentry)) {
850 error = PTR_ERR(old_dentry); 853 error = PTR_ERR(old_dentry);
854 old_dentry = NULL;
851 goto out; 855 goto out;
852 } 856 }
853 old_parent = old_dentry->d_parent; 857 old_parent = old_dentry->d_parent;
@@ -855,6 +859,7 @@ int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj)
855 new_parent = sysfs_get_dentry(new_parent_sd); 859 new_parent = sysfs_get_dentry(new_parent_sd);
856 if (IS_ERR(new_parent)) { 860 if (IS_ERR(new_parent)) {
857 error = PTR_ERR(new_parent); 861 error = PTR_ERR(new_parent);
862 new_parent = NULL;
858 goto out; 863 goto out;
859 } 864 }
860 865
@@ -878,7 +883,6 @@ again:
878 error = 0; 883 error = 0;
879 d_add(new_dentry, NULL); 884 d_add(new_dentry, NULL);
880 d_move(old_dentry, new_dentry); 885 d_move(old_dentry, new_dentry);
881 dput(new_dentry);
882 886
883 /* Remove from old parent's list and insert into new parent's list. */ 887 /* Remove from old parent's list and insert into new parent's list. */
884 sysfs_unlink_sibling(sd); 888 sysfs_unlink_sibling(sd);
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 4045bdcc4b33..8acf82bba44c 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -20,43 +20,6 @@
20 20
21#include "sysfs.h" 21#include "sysfs.h"
22 22
23#define to_sattr(a) container_of(a,struct subsys_attribute, attr)
24
25/*
26 * Subsystem file operations.
27 * These operations allow subsystems to have files that can be
28 * read/written.
29 */
30static ssize_t
31subsys_attr_show(struct kobject * kobj, struct attribute * attr, char * page)
32{
33 struct kset *kset = to_kset(kobj);
34 struct subsys_attribute * sattr = to_sattr(attr);
35 ssize_t ret = -EIO;
36
37 if (sattr->show)
38 ret = sattr->show(kset, page);
39 return ret;
40}
41
42static ssize_t
43subsys_attr_store(struct kobject * kobj, struct attribute * attr,
44 const char * page, size_t count)
45{
46 struct kset *kset = to_kset(kobj);
47 struct subsys_attribute * sattr = to_sattr(attr);
48 ssize_t ret = -EIO;
49
50 if (sattr->store)
51 ret = sattr->store(kset, page, count);
52 return ret;
53}
54
55static struct sysfs_ops subsys_sysfs_ops = {
56 .show = subsys_attr_show,
57 .store = subsys_attr_store,
58};
59
60/* 23/*
61 * There's one sysfs_buffer for each open file and one 24 * There's one sysfs_buffer for each open file and one
62 * sysfs_open_dirent for each sysfs_dirent with one or more open 25 * sysfs_open_dirent for each sysfs_dirent with one or more open
@@ -66,7 +29,7 @@ static struct sysfs_ops subsys_sysfs_ops = {
66 * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open 29 * sysfs_dirent->s_attr.open points to sysfs_open_dirent. s_attr.open
67 * is protected by sysfs_open_dirent_lock. 30 * is protected by sysfs_open_dirent_lock.
68 */ 31 */
69static spinlock_t sysfs_open_dirent_lock = SPIN_LOCK_UNLOCKED; 32static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
70 33
71struct sysfs_open_dirent { 34struct sysfs_open_dirent {
72 atomic_t refcnt; 35 atomic_t refcnt;
@@ -354,31 +317,23 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
354{ 317{
355 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; 318 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
356 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj; 319 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;
357 struct sysfs_buffer * buffer; 320 struct sysfs_buffer *buffer;
358 struct sysfs_ops * ops = NULL; 321 struct sysfs_ops *ops;
359 int error; 322 int error = -EACCES;
360 323
361 /* need attr_sd for attr and ops, its parent for kobj */ 324 /* need attr_sd for attr and ops, its parent for kobj */
362 if (!sysfs_get_active_two(attr_sd)) 325 if (!sysfs_get_active_two(attr_sd))
363 return -ENODEV; 326 return -ENODEV;
364 327
365 /* if the kobject has no ktype, then we assume that it is a subsystem 328 /* every kobject with an attribute needs a ktype assigned */
366 * itself, and use ops for it. 329 if (kobj->ktype && kobj->ktype->sysfs_ops)
367 */
368 if (kobj->kset && kobj->kset->ktype)
369 ops = kobj->kset->ktype->sysfs_ops;
370 else if (kobj->ktype)
371 ops = kobj->ktype->sysfs_ops; 330 ops = kobj->ktype->sysfs_ops;
372 else 331 else {
373 ops = &subsys_sysfs_ops; 332 printk(KERN_ERR "missing sysfs attribute operations for "
374 333 "kobject: %s\n", kobject_name(kobj));
375 error = -EACCES; 334 WARN_ON(1);
376
377 /* No sysfs operations, either from having no subsystem,
378 * or the subsystem have no operations.
379 */
380 if (!ops)
381 goto err_out; 335 goto err_out;
336 }
382 337
383 /* File needs write support. 338 /* File needs write support.
384 * The inode's perms must say it's ok, 339 * The inode's perms must say it's ok,
diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
index 3eac20c63c41..5f66c4466151 100644
--- a/fs/sysfs/symlink.c
+++ b/fs/sysfs/symlink.c
@@ -19,39 +19,6 @@
19 19
20#include "sysfs.h" 20#include "sysfs.h"
21 21
22static int object_depth(struct sysfs_dirent *sd)
23{
24 int depth = 0;
25
26 for (; sd->s_parent; sd = sd->s_parent)
27 depth++;
28
29 return depth;
30}
31
32static int object_path_length(struct sysfs_dirent * sd)
33{
34 int length = 1;
35
36 for (; sd->s_parent; sd = sd->s_parent)
37 length += strlen(sd->s_name) + 1;
38
39 return length;
40}
41
42static void fill_object_path(struct sysfs_dirent *sd, char *buffer, int length)
43{
44 --length;
45 for (; sd->s_parent; sd = sd->s_parent) {
46 int cur = strlen(sd->s_name);
47
48 /* back up enough to print this bus id with '/' */
49 length -= cur;
50 strncpy(buffer + length, sd->s_name, cur);
51 *(buffer + --length) = '/';
52 }
53}
54
55/** 22/**
56 * sysfs_create_link - create symlink between two objects. 23 * sysfs_create_link - create symlink between two objects.
57 * @kobj: object whose directory we're creating the link in. 24 * @kobj: object whose directory we're creating the link in.
@@ -112,7 +79,6 @@ int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char
112 return error; 79 return error;
113} 80}
114 81
115
116/** 82/**
117 * sysfs_remove_link - remove symlink in object's directory. 83 * sysfs_remove_link - remove symlink in object's directory.
118 * @kobj: object we're acting for. 84 * @kobj: object we're acting for.
@@ -124,24 +90,54 @@ void sysfs_remove_link(struct kobject * kobj, const char * name)
124 sysfs_hash_and_remove(kobj->sd, name); 90 sysfs_hash_and_remove(kobj->sd, name);
125} 91}
126 92
127static int sysfs_get_target_path(struct sysfs_dirent * parent_sd, 93static int sysfs_get_target_path(struct sysfs_dirent *parent_sd,
128 struct sysfs_dirent * target_sd, char *path) 94 struct sysfs_dirent *target_sd, char *path)
129{ 95{
130 char * s; 96 struct sysfs_dirent *base, *sd;
131 int depth, size; 97 char *s = path;
98 int len = 0;
99
100 /* go up to the root, stop at the base */
101 base = parent_sd;
102 while (base->s_parent) {
103 sd = target_sd->s_parent;
104 while (sd->s_parent && base != sd)
105 sd = sd->s_parent;
106
107 if (base == sd)
108 break;
109
110 strcpy(s, "../");
111 s += 3;
112 base = base->s_parent;
113 }
114
115 /* determine end of target string for reverse fillup */
116 sd = target_sd;
117 while (sd->s_parent && sd != base) {
118 len += strlen(sd->s_name) + 1;
119 sd = sd->s_parent;
120 }
132 121
133 depth = object_depth(parent_sd); 122 /* check limits */
134 size = object_path_length(target_sd) + depth * 3 - 1; 123 if (len < 2)
135 if (size > PATH_MAX) 124 return -EINVAL;
125 len--;
126 if ((s - path) + len > PATH_MAX)
136 return -ENAMETOOLONG; 127 return -ENAMETOOLONG;
137 128
138 pr_debug("%s: depth = %d, size = %d\n", __FUNCTION__, depth, size); 129 /* reverse fillup of target string from target to base */
130 sd = target_sd;
131 while (sd->s_parent && sd != base) {
132 int slen = strlen(sd->s_name);
139 133
140 for (s = path; depth--; s += 3) 134 len -= slen;
141 strcpy(s,"../"); 135 strncpy(s + len, sd->s_name, slen);
136 if (len)
137 s[--len] = '/';
142 138
143 fill_object_path(target_sd, path, size); 139 sd = sd->s_parent;
144 pr_debug("%s: path = '%s'\n", __FUNCTION__, path); 140 }
145 141
146 return 0; 142 return 0;
147} 143}
diff --git a/fs/xfs/linux-2.6/xfs_file.c b/fs/xfs/linux-2.6/xfs_file.c
index 4847eb83fc18..21a1c2b1c5fc 100644
--- a/fs/xfs/linux-2.6/xfs_file.c
+++ b/fs/xfs/linux-2.6/xfs_file.c
@@ -261,9 +261,9 @@ xfs_file_readdir(
261#else 261#else
262 262
263struct hack_dirent { 263struct hack_dirent {
264 int namlen;
265 loff_t offset;
266 u64 ino; 264 u64 ino;
265 loff_t offset;
266 int namlen;
267 unsigned int d_type; 267 unsigned int d_type;
268 char name[]; 268 char name[];
269}; 269};
@@ -285,8 +285,10 @@ xfs_hack_filldir(
285{ 285{
286 struct hack_callback *buf = __buf; 286 struct hack_callback *buf = __buf;
287 struct hack_dirent *de = (struct hack_dirent *)(buf->dirent + buf->used); 287 struct hack_dirent *de = (struct hack_dirent *)(buf->dirent + buf->used);
288 unsigned int reclen;
288 289
289 if (buf->used + sizeof(struct hack_dirent) + namlen > buf->len) 290 reclen = ALIGN(sizeof(struct hack_dirent) + namlen, sizeof(u64));
291 if (buf->used + reclen > buf->len)
290 return -EINVAL; 292 return -EINVAL;
291 293
292 de->namlen = namlen; 294 de->namlen = namlen;
@@ -294,7 +296,7 @@ xfs_hack_filldir(
294 de->ino = ino; 296 de->ino = ino;
295 de->d_type = d_type; 297 de->d_type = d_type;
296 memcpy(de->name, name, namlen); 298 memcpy(de->name, name, namlen);
297 buf->used += sizeof(struct hack_dirent) + namlen; 299 buf->used += reclen;
298 return 0; 300 return 0;
299} 301}
300 302
@@ -334,7 +336,8 @@ xfs_file_readdir(
334 offset = filp->f_pos; 336 offset = filp->f_pos;
335 337
336 while (!eof) { 338 while (!eof) {
337 int reclen; 339 unsigned int reclen;
340
338 start_offset = offset; 341 start_offset = offset;
339 342
340 buf.used = 0; 343 buf.used = 0;
@@ -355,7 +358,8 @@ xfs_file_readdir(
355 goto done; 358 goto done;
356 } 359 }
357 360
358 reclen = sizeof(struct hack_dirent) + de->namlen; 361 reclen = ALIGN(sizeof(struct hack_dirent) + de->namlen,
362 sizeof(u64));
359 size -= reclen; 363 size -= reclen;
360 de = (struct hack_dirent *)((char *)de + reclen); 364 de = (struct hack_dirent *)((char *)de + reclen);
361 curr_offset = de->offset /* & 0x7fffffff */; 365 curr_offset = de->offset /* & 0x7fffffff */;