aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/autofs4/inode.c2
-rw-r--r--fs/btrfs/compression.c2
-rw-r--r--fs/btrfs/dev-replace.c5
-rw-r--r--fs/btrfs/disk-io.c5
-rw-r--r--fs/btrfs/extent-tree.c5
-rw-r--r--fs/btrfs/ioctl.c37
-rw-r--r--fs/btrfs/print-tree.c9
-rw-r--r--fs/btrfs/raid56.c5
-rw-r--r--fs/btrfs/super.c7
-rw-r--r--fs/btrfs/sysfs.c32
-rw-r--r--fs/btrfs/sysfs.h4
-rw-r--r--fs/btrfs/transaction.c12
-rw-r--r--fs/btrfs/volumes.c30
-rw-r--r--fs/btrfs/zlib.c2
-rw-r--r--fs/f2fs/data.c23
-rw-r--r--fs/f2fs/dir.c2
-rw-r--r--fs/f2fs/f2fs.h6
-rw-r--r--fs/f2fs/file.c12
-rw-r--r--fs/f2fs/inode.c1
-rw-r--r--fs/f2fs/namei.c13
-rw-r--r--fs/f2fs/node.c2
-rw-r--r--fs/f2fs/segment.c5
-rw-r--r--fs/f2fs/super.c4
-rw-r--r--fs/kernfs/file.c69
-rw-r--r--fs/kernfs/mount.c30
-rw-r--r--fs/nfsd/nfs4proc.c9
-rw-r--r--fs/nfsd/nfs4xdr.c17
-rw-r--r--fs/proc/stat.c22
-rw-r--r--fs/seq_file.c30
29 files changed, 272 insertions, 130 deletions
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index d7bd395ab586..1c55388ae633 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -210,7 +210,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
210 int pipefd; 210 int pipefd;
211 struct autofs_sb_info *sbi; 211 struct autofs_sb_info *sbi;
212 struct autofs_info *ino; 212 struct autofs_info *ino;
213 int pgrp; 213 int pgrp = 0;
214 bool pgrp_set = false; 214 bool pgrp_set = false;
215 int ret = -EINVAL; 215 int ret = -EINVAL;
216 216
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index 92371c414228..1daea0b47187 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -821,7 +821,7 @@ static void free_workspace(int type, struct list_head *workspace)
821 821
822 spin_lock(workspace_lock); 822 spin_lock(workspace_lock);
823 if (*num_workspace < num_online_cpus()) { 823 if (*num_workspace < num_online_cpus()) {
824 list_add_tail(workspace, idle_workspace); 824 list_add(workspace, idle_workspace);
825 (*num_workspace)++; 825 (*num_workspace)++;
826 spin_unlock(workspace_lock); 826 spin_unlock(workspace_lock);
827 goto wake; 827 goto wake;
diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c
index 2af6e66fe788..eea26e1b2fda 100644
--- a/fs/btrfs/dev-replace.c
+++ b/fs/btrfs/dev-replace.c
@@ -36,6 +36,7 @@
36#include "check-integrity.h" 36#include "check-integrity.h"
37#include "rcu-string.h" 37#include "rcu-string.h"
38#include "dev-replace.h" 38#include "dev-replace.h"
39#include "sysfs.h"
39 40
40static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, 41static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
41 int scrub_ret); 42 int scrub_ret);
@@ -562,6 +563,10 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
562 fs_info->fs_devices->latest_bdev = tgt_device->bdev; 563 fs_info->fs_devices->latest_bdev = tgt_device->bdev;
563 list_add(&tgt_device->dev_alloc_list, &fs_info->fs_devices->alloc_list); 564 list_add(&tgt_device->dev_alloc_list, &fs_info->fs_devices->alloc_list);
564 565
566 /* replace the sysfs entry */
567 btrfs_kobj_rm_device(fs_info, src_device);
568 btrfs_kobj_add_device(fs_info, tgt_device);
569
565 btrfs_rm_dev_replace_blocked(fs_info); 570 btrfs_rm_dev_replace_blocked(fs_info);
566 571
567 btrfs_rm_dev_replace_srcdev(fs_info, src_device); 572 btrfs_rm_dev_replace_srcdev(fs_info, src_device);
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 8bb4aa19898f..08e65e9cf2aa 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -369,7 +369,8 @@ static int verify_parent_transid(struct extent_io_tree *io_tree,
369out: 369out:
370 unlock_extent_cached(io_tree, eb->start, eb->start + eb->len - 1, 370 unlock_extent_cached(io_tree, eb->start, eb->start + eb->len - 1,
371 &cached_state, GFP_NOFS); 371 &cached_state, GFP_NOFS);
372 btrfs_tree_read_unlock_blocking(eb); 372 if (need_lock)
373 btrfs_tree_read_unlock_blocking(eb);
373 return ret; 374 return ret;
374} 375}
375 376
@@ -2904,7 +2905,9 @@ retry_root_backup:
2904 if (ret) 2905 if (ret)
2905 goto fail_qgroup; 2906 goto fail_qgroup;
2906 2907
2908 mutex_lock(&fs_info->cleaner_mutex);
2907 ret = btrfs_recover_relocation(tree_root); 2909 ret = btrfs_recover_relocation(tree_root);
2910 mutex_unlock(&fs_info->cleaner_mutex);
2908 if (ret < 0) { 2911 if (ret < 0) {
2909 printk(KERN_WARNING 2912 printk(KERN_WARNING
2910 "BTRFS: failed to recover relocation\n"); 2913 "BTRFS: failed to recover relocation\n");
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 99c253918208..813537f362f9 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -5678,7 +5678,6 @@ void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
5678 struct btrfs_caching_control *next; 5678 struct btrfs_caching_control *next;
5679 struct btrfs_caching_control *caching_ctl; 5679 struct btrfs_caching_control *caching_ctl;
5680 struct btrfs_block_group_cache *cache; 5680 struct btrfs_block_group_cache *cache;
5681 struct btrfs_space_info *space_info;
5682 5681
5683 down_write(&fs_info->commit_root_sem); 5682 down_write(&fs_info->commit_root_sem);
5684 5683
@@ -5701,9 +5700,6 @@ void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans,
5701 5700
5702 up_write(&fs_info->commit_root_sem); 5701 up_write(&fs_info->commit_root_sem);
5703 5702
5704 list_for_each_entry_rcu(space_info, &fs_info->space_info, list)
5705 percpu_counter_set(&space_info->total_bytes_pinned, 0);
5706
5707 update_global_block_rsv(fs_info); 5703 update_global_block_rsv(fs_info);
5708} 5704}
5709 5705
@@ -5741,6 +5737,7 @@ static int unpin_extent_range(struct btrfs_root *root, u64 start, u64 end)
5741 spin_lock(&cache->lock); 5737 spin_lock(&cache->lock);
5742 cache->pinned -= len; 5738 cache->pinned -= len;
5743 space_info->bytes_pinned -= len; 5739 space_info->bytes_pinned -= len;
5740 percpu_counter_add(&space_info->total_bytes_pinned, -len);
5744 if (cache->ro) { 5741 if (cache->ro) {
5745 space_info->bytes_readonly += len; 5742 space_info->bytes_readonly += len;
5746 readonly = true; 5743 readonly = true;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 0d321c23069a..47aceb494d1d 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -136,19 +136,22 @@ static unsigned int btrfs_flags_to_ioctl(unsigned int flags)
136void btrfs_update_iflags(struct inode *inode) 136void btrfs_update_iflags(struct inode *inode)
137{ 137{
138 struct btrfs_inode *ip = BTRFS_I(inode); 138 struct btrfs_inode *ip = BTRFS_I(inode);
139 139 unsigned int new_fl = 0;
140 inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
141 140
142 if (ip->flags & BTRFS_INODE_SYNC) 141 if (ip->flags & BTRFS_INODE_SYNC)
143 inode->i_flags |= S_SYNC; 142 new_fl |= S_SYNC;
144 if (ip->flags & BTRFS_INODE_IMMUTABLE) 143 if (ip->flags & BTRFS_INODE_IMMUTABLE)
145 inode->i_flags |= S_IMMUTABLE; 144 new_fl |= S_IMMUTABLE;
146 if (ip->flags & BTRFS_INODE_APPEND) 145 if (ip->flags & BTRFS_INODE_APPEND)
147 inode->i_flags |= S_APPEND; 146 new_fl |= S_APPEND;
148 if (ip->flags & BTRFS_INODE_NOATIME) 147 if (ip->flags & BTRFS_INODE_NOATIME)
149 inode->i_flags |= S_NOATIME; 148 new_fl |= S_NOATIME;
150 if (ip->flags & BTRFS_INODE_DIRSYNC) 149 if (ip->flags & BTRFS_INODE_DIRSYNC)
151 inode->i_flags |= S_DIRSYNC; 150 new_fl |= S_DIRSYNC;
151
152 set_mask_bits(&inode->i_flags,
153 S_SYNC | S_APPEND | S_IMMUTABLE | S_NOATIME | S_DIRSYNC,
154 new_fl);
152} 155}
153 156
154/* 157/*
@@ -3139,7 +3142,6 @@ out:
3139static void clone_update_extent_map(struct inode *inode, 3142static void clone_update_extent_map(struct inode *inode,
3140 const struct btrfs_trans_handle *trans, 3143 const struct btrfs_trans_handle *trans,
3141 const struct btrfs_path *path, 3144 const struct btrfs_path *path,
3142 struct btrfs_file_extent_item *fi,
3143 const u64 hole_offset, 3145 const u64 hole_offset,
3144 const u64 hole_len) 3146 const u64 hole_len)
3145{ 3147{
@@ -3154,7 +3156,11 @@ static void clone_update_extent_map(struct inode *inode,
3154 return; 3156 return;
3155 } 3157 }
3156 3158
3157 if (fi) { 3159 if (path) {
3160 struct btrfs_file_extent_item *fi;
3161
3162 fi = btrfs_item_ptr(path->nodes[0], path->slots[0],
3163 struct btrfs_file_extent_item);
3158 btrfs_extent_item_to_extent_map(inode, path, fi, false, em); 3164 btrfs_extent_item_to_extent_map(inode, path, fi, false, em);
3159 em->generation = -1; 3165 em->generation = -1;
3160 if (btrfs_file_extent_type(path->nodes[0], fi) == 3166 if (btrfs_file_extent_type(path->nodes[0], fi) ==
@@ -3508,18 +3514,15 @@ process_slot:
3508 btrfs_item_ptr_offset(leaf, slot), 3514 btrfs_item_ptr_offset(leaf, slot),
3509 size); 3515 size);
3510 inode_add_bytes(inode, datal); 3516 inode_add_bytes(inode, datal);
3511 extent = btrfs_item_ptr(leaf, slot,
3512 struct btrfs_file_extent_item);
3513 } 3517 }
3514 3518
3515 /* If we have an implicit hole (NO_HOLES feature). */ 3519 /* If we have an implicit hole (NO_HOLES feature). */
3516 if (drop_start < new_key.offset) 3520 if (drop_start < new_key.offset)
3517 clone_update_extent_map(inode, trans, 3521 clone_update_extent_map(inode, trans,
3518 path, NULL, drop_start, 3522 NULL, drop_start,
3519 new_key.offset - drop_start); 3523 new_key.offset - drop_start);
3520 3524
3521 clone_update_extent_map(inode, trans, path, 3525 clone_update_extent_map(inode, trans, path, 0, 0);
3522 extent, 0, 0);
3523 3526
3524 btrfs_mark_buffer_dirty(leaf); 3527 btrfs_mark_buffer_dirty(leaf);
3525 btrfs_release_path(path); 3528 btrfs_release_path(path);
@@ -3562,12 +3565,10 @@ process_slot:
3562 btrfs_end_transaction(trans, root); 3565 btrfs_end_transaction(trans, root);
3563 goto out; 3566 goto out;
3564 } 3567 }
3568 clone_update_extent_map(inode, trans, NULL, last_dest_end,
3569 destoff + len - last_dest_end);
3565 ret = clone_finish_inode_update(trans, inode, destoff + len, 3570 ret = clone_finish_inode_update(trans, inode, destoff + len,
3566 destoff, olen); 3571 destoff, olen);
3567 if (ret)
3568 goto out;
3569 clone_update_extent_map(inode, trans, path, NULL, last_dest_end,
3570 destoff + len - last_dest_end);
3571 } 3572 }
3572 3573
3573out: 3574out:
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index 6efd70d3b64f..9626b4ad3b9a 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -54,7 +54,7 @@ static void print_extent_data_ref(struct extent_buffer *eb,
54 btrfs_extent_data_ref_count(eb, ref)); 54 btrfs_extent_data_ref_count(eb, ref));
55} 55}
56 56
57static void print_extent_item(struct extent_buffer *eb, int slot) 57static void print_extent_item(struct extent_buffer *eb, int slot, int type)
58{ 58{
59 struct btrfs_extent_item *ei; 59 struct btrfs_extent_item *ei;
60 struct btrfs_extent_inline_ref *iref; 60 struct btrfs_extent_inline_ref *iref;
@@ -63,7 +63,6 @@ static void print_extent_item(struct extent_buffer *eb, int slot)
63 struct btrfs_disk_key key; 63 struct btrfs_disk_key key;
64 unsigned long end; 64 unsigned long end;
65 unsigned long ptr; 65 unsigned long ptr;
66 int type;
67 u32 item_size = btrfs_item_size_nr(eb, slot); 66 u32 item_size = btrfs_item_size_nr(eb, slot);
68 u64 flags; 67 u64 flags;
69 u64 offset; 68 u64 offset;
@@ -88,7 +87,8 @@ static void print_extent_item(struct extent_buffer *eb, int slot)
88 btrfs_extent_refs(eb, ei), btrfs_extent_generation(eb, ei), 87 btrfs_extent_refs(eb, ei), btrfs_extent_generation(eb, ei),
89 flags); 88 flags);
90 89
91 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) { 90 if ((type == BTRFS_EXTENT_ITEM_KEY) &&
91 flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
92 struct btrfs_tree_block_info *info; 92 struct btrfs_tree_block_info *info;
93 info = (struct btrfs_tree_block_info *)(ei + 1); 93 info = (struct btrfs_tree_block_info *)(ei + 1);
94 btrfs_tree_block_key(eb, info, &key); 94 btrfs_tree_block_key(eb, info, &key);
@@ -223,7 +223,8 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
223 btrfs_disk_root_refs(l, ri)); 223 btrfs_disk_root_refs(l, ri));
224 break; 224 break;
225 case BTRFS_EXTENT_ITEM_KEY: 225 case BTRFS_EXTENT_ITEM_KEY:
226 print_extent_item(l, i); 226 case BTRFS_METADATA_ITEM_KEY:
227 print_extent_item(l, i, type);
227 break; 228 break;
228 case BTRFS_TREE_BLOCK_REF_KEY: 229 case BTRFS_TREE_BLOCK_REF_KEY:
229 printk(KERN_INFO "\t\ttree block backref\n"); 230 printk(KERN_INFO "\t\ttree block backref\n");
diff --git a/fs/btrfs/raid56.c b/fs/btrfs/raid56.c
index 4055291a523e..4a88f073fdd7 100644
--- a/fs/btrfs/raid56.c
+++ b/fs/btrfs/raid56.c
@@ -1956,9 +1956,10 @@ static int __raid56_parity_recover(struct btrfs_raid_bio *rbio)
1956 * pages are going to be uptodate. 1956 * pages are going to be uptodate.
1957 */ 1957 */
1958 for (stripe = 0; stripe < bbio->num_stripes; stripe++) { 1958 for (stripe = 0; stripe < bbio->num_stripes; stripe++) {
1959 if (rbio->faila == stripe || 1959 if (rbio->faila == stripe || rbio->failb == stripe) {
1960 rbio->failb == stripe) 1960 atomic_inc(&rbio->bbio->error);
1961 continue; 1961 continue;
1962 }
1962 1963
1963 for (pagenr = 0; pagenr < nr_pages; pagenr++) { 1964 for (pagenr = 0; pagenr < nr_pages; pagenr++) {
1964 struct page *p; 1965 struct page *p;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 4662d92a4b73..8e16bca69c56 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -522,9 +522,10 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
522 case Opt_ssd_spread: 522 case Opt_ssd_spread:
523 btrfs_set_and_info(root, SSD_SPREAD, 523 btrfs_set_and_info(root, SSD_SPREAD,
524 "use spread ssd allocation scheme"); 524 "use spread ssd allocation scheme");
525 btrfs_set_opt(info->mount_opt, SSD);
525 break; 526 break;
526 case Opt_nossd: 527 case Opt_nossd:
527 btrfs_clear_and_info(root, NOSSD, 528 btrfs_set_and_info(root, NOSSD,
528 "not using ssd allocation scheme"); 529 "not using ssd allocation scheme");
529 btrfs_clear_opt(info->mount_opt, SSD); 530 btrfs_clear_opt(info->mount_opt, SSD);
530 break; 531 break;
@@ -1467,7 +1468,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
1467 goto restore; 1468 goto restore;
1468 1469
1469 /* recover relocation */ 1470 /* recover relocation */
1471 mutex_lock(&fs_info->cleaner_mutex);
1470 ret = btrfs_recover_relocation(root); 1472 ret = btrfs_recover_relocation(root);
1473 mutex_unlock(&fs_info->cleaner_mutex);
1471 if (ret) 1474 if (ret)
1472 goto restore; 1475 goto restore;
1473 1476
@@ -1808,6 +1811,8 @@ static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
1808 list_for_each_entry(dev, head, dev_list) { 1811 list_for_each_entry(dev, head, dev_list) {
1809 if (dev->missing) 1812 if (dev->missing)
1810 continue; 1813 continue;
1814 if (!dev->name)
1815 continue;
1811 if (!first_dev || dev->devid < first_dev->devid) 1816 if (!first_dev || dev->devid < first_dev->devid)
1812 first_dev = dev; 1817 first_dev = dev;
1813 } 1818 }
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index df39458f1487..78699364f537 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -605,14 +605,37 @@ static void init_feature_attrs(void)
605 } 605 }
606} 606}
607 607
608static int add_device_membership(struct btrfs_fs_info *fs_info) 608int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
609 struct btrfs_device *one_device)
610{
611 struct hd_struct *disk;
612 struct kobject *disk_kobj;
613
614 if (!fs_info->device_dir_kobj)
615 return -EINVAL;
616
617 if (one_device) {
618 disk = one_device->bdev->bd_part;
619 disk_kobj = &part_to_dev(disk)->kobj;
620
621 sysfs_remove_link(fs_info->device_dir_kobj,
622 disk_kobj->name);
623 }
624
625 return 0;
626}
627
628int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
629 struct btrfs_device *one_device)
609{ 630{
610 int error = 0; 631 int error = 0;
611 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; 632 struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
612 struct btrfs_device *dev; 633 struct btrfs_device *dev;
613 634
614 fs_info->device_dir_kobj = kobject_create_and_add("devices", 635 if (!fs_info->device_dir_kobj)
636 fs_info->device_dir_kobj = kobject_create_and_add("devices",
615 &fs_info->super_kobj); 637 &fs_info->super_kobj);
638
616 if (!fs_info->device_dir_kobj) 639 if (!fs_info->device_dir_kobj)
617 return -ENOMEM; 640 return -ENOMEM;
618 641
@@ -623,6 +646,9 @@ static int add_device_membership(struct btrfs_fs_info *fs_info)
623 if (!dev->bdev) 646 if (!dev->bdev)
624 continue; 647 continue;
625 648
649 if (one_device && one_device != dev)
650 continue;
651
626 disk = dev->bdev->bd_part; 652 disk = dev->bdev->bd_part;
627 disk_kobj = &part_to_dev(disk)->kobj; 653 disk_kobj = &part_to_dev(disk)->kobj;
628 654
@@ -666,7 +692,7 @@ int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
666 if (error) 692 if (error)
667 goto failure; 693 goto failure;
668 694
669 error = add_device_membership(fs_info); 695 error = btrfs_kobj_add_device(fs_info, NULL);
670 if (error) 696 if (error)
671 goto failure; 697 goto failure;
672 698
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h
index 9ab576318a84..ac46df37504c 100644
--- a/fs/btrfs/sysfs.h
+++ b/fs/btrfs/sysfs.h
@@ -66,4 +66,8 @@ char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
66extern const char * const btrfs_feature_set_names[3]; 66extern const char * const btrfs_feature_set_names[3];
67extern struct kobj_type space_info_ktype; 67extern struct kobj_type space_info_ktype;
68extern struct kobj_type btrfs_raid_ktype; 68extern struct kobj_type btrfs_raid_ktype;
69int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info,
70 struct btrfs_device *one_device);
71int btrfs_kobj_rm_device(struct btrfs_fs_info *fs_info,
72 struct btrfs_device *one_device);
69#endif /* _BTRFS_SYSFS_H_ */ 73#endif /* _BTRFS_SYSFS_H_ */
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 511839c04f11..5f379affdf23 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -386,11 +386,13 @@ start_transaction(struct btrfs_root *root, u64 num_items, unsigned int type,
386 bool reloc_reserved = false; 386 bool reloc_reserved = false;
387 int ret; 387 int ret;
388 388
389 /* Send isn't supposed to start transactions. */
390 ASSERT(current->journal_info != (void *)BTRFS_SEND_TRANS_STUB);
391
389 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state)) 392 if (test_bit(BTRFS_FS_STATE_ERROR, &root->fs_info->fs_state))
390 return ERR_PTR(-EROFS); 393 return ERR_PTR(-EROFS);
391 394
392 if (current->journal_info && 395 if (current->journal_info) {
393 current->journal_info != (void *)BTRFS_SEND_TRANS_STUB) {
394 WARN_ON(type & TRANS_EXTWRITERS); 396 WARN_ON(type & TRANS_EXTWRITERS);
395 h = current->journal_info; 397 h = current->journal_info;
396 h->use_count++; 398 h->use_count++;
@@ -491,6 +493,7 @@ again:
491 smp_mb(); 493 smp_mb();
492 if (cur_trans->state >= TRANS_STATE_BLOCKED && 494 if (cur_trans->state >= TRANS_STATE_BLOCKED &&
493 may_wait_transaction(root, type)) { 495 may_wait_transaction(root, type)) {
496 current->journal_info = h;
494 btrfs_commit_transaction(h, root); 497 btrfs_commit_transaction(h, root);
495 goto again; 498 goto again;
496 } 499 }
@@ -1615,11 +1618,6 @@ static int btrfs_flush_all_pending_stuffs(struct btrfs_trans_handle *trans,
1615 int ret; 1618 int ret;
1616 1619
1617 ret = btrfs_run_delayed_items(trans, root); 1620 ret = btrfs_run_delayed_items(trans, root);
1618 /*
1619 * running the delayed items may have added new refs. account
1620 * them now so that they hinder processing of more delayed refs
1621 * as little as possible.
1622 */
1623 if (ret) 1621 if (ret)
1624 return ret; 1622 return ret;
1625 1623
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index c83b24251e53..6104676857f5 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -40,6 +40,7 @@
40#include "rcu-string.h" 40#include "rcu-string.h"
41#include "math.h" 41#include "math.h"
42#include "dev-replace.h" 42#include "dev-replace.h"
43#include "sysfs.h"
43 44
44static int init_first_rw_device(struct btrfs_trans_handle *trans, 45static int init_first_rw_device(struct btrfs_trans_handle *trans,
45 struct btrfs_root *root, 46 struct btrfs_root *root,
@@ -554,12 +555,14 @@ static struct btrfs_fs_devices *clone_fs_devices(struct btrfs_fs_devices *orig)
554 * This is ok to do without rcu read locked because we hold the 555 * This is ok to do without rcu read locked because we hold the
555 * uuid mutex so nothing we touch in here is going to disappear. 556 * uuid mutex so nothing we touch in here is going to disappear.
556 */ 557 */
557 name = rcu_string_strdup(orig_dev->name->str, GFP_NOFS); 558 if (orig_dev->name) {
558 if (!name) { 559 name = rcu_string_strdup(orig_dev->name->str, GFP_NOFS);
559 kfree(device); 560 if (!name) {
560 goto error; 561 kfree(device);
562 goto error;
563 }
564 rcu_assign_pointer(device->name, name);
561 } 565 }
562 rcu_assign_pointer(device->name, name);
563 566
564 list_add(&device->dev_list, &fs_devices->devices); 567 list_add(&device->dev_list, &fs_devices->devices);
565 device->fs_devices = fs_devices; 568 device->fs_devices = fs_devices;
@@ -1680,6 +1683,9 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
1680 if (device->bdev) 1683 if (device->bdev)
1681 device->fs_devices->open_devices--; 1684 device->fs_devices->open_devices--;
1682 1685
1686 /* remove sysfs entry */
1687 btrfs_kobj_rm_device(root->fs_info, device);
1688
1683 call_rcu(&device->rcu, free_device); 1689 call_rcu(&device->rcu, free_device);
1684 1690
1685 num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1; 1691 num_devices = btrfs_super_num_devices(root->fs_info->super_copy) - 1;
@@ -2143,9 +2149,14 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
2143 total_bytes = btrfs_super_num_devices(root->fs_info->super_copy); 2149 total_bytes = btrfs_super_num_devices(root->fs_info->super_copy);
2144 btrfs_set_super_num_devices(root->fs_info->super_copy, 2150 btrfs_set_super_num_devices(root->fs_info->super_copy,
2145 total_bytes + 1); 2151 total_bytes + 1);
2152
2153 /* add sysfs device entry */
2154 btrfs_kobj_add_device(root->fs_info, device);
2155
2146 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex); 2156 mutex_unlock(&root->fs_info->fs_devices->device_list_mutex);
2147 2157
2148 if (seeding_dev) { 2158 if (seeding_dev) {
2159 char fsid_buf[BTRFS_UUID_UNPARSED_SIZE];
2149 ret = init_first_rw_device(trans, root, device); 2160 ret = init_first_rw_device(trans, root, device);
2150 if (ret) { 2161 if (ret) {
2151 btrfs_abort_transaction(trans, root, ret); 2162 btrfs_abort_transaction(trans, root, ret);
@@ -2156,6 +2167,14 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
2156 btrfs_abort_transaction(trans, root, ret); 2167 btrfs_abort_transaction(trans, root, ret);
2157 goto error_trans; 2168 goto error_trans;
2158 } 2169 }
2170
2171 /* Sprouting would change fsid of the mounted root,
2172 * so rename the fsid on the sysfs
2173 */
2174 snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU",
2175 root->fs_info->fsid);
2176 if (kobject_rename(&root->fs_info->super_kobj, fsid_buf))
2177 goto error_trans;
2159 } else { 2178 } else {
2160 ret = btrfs_add_device(trans, root, device); 2179 ret = btrfs_add_device(trans, root, device);
2161 if (ret) { 2180 if (ret) {
@@ -2205,6 +2224,7 @@ error_trans:
2205 unlock_chunks(root); 2224 unlock_chunks(root);
2206 btrfs_end_transaction(trans, root); 2225 btrfs_end_transaction(trans, root);
2207 rcu_string_free(device->name); 2226 rcu_string_free(device->name);
2227 btrfs_kobj_rm_device(root->fs_info, device);
2208 kfree(device); 2228 kfree(device);
2209error: 2229error:
2210 blkdev_put(bdev, FMODE_EXCL); 2230 blkdev_put(bdev, FMODE_EXCL);
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 4f196314c0c1..b67d8fc81277 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -136,7 +136,7 @@ static int zlib_compress_pages(struct list_head *ws,
136 if (workspace->def_strm.total_in > 8192 && 136 if (workspace->def_strm.total_in > 8192 &&
137 workspace->def_strm.total_in < 137 workspace->def_strm.total_in <
138 workspace->def_strm.total_out) { 138 workspace->def_strm.total_out) {
139 ret = -EIO; 139 ret = -E2BIG;
140 goto out; 140 goto out;
141 } 141 }
142 /* we need another page for writing out. Test this 142 /* we need another page for writing out. Test this
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 0924521306b4..f8cf619edb5f 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -608,8 +608,8 @@ static int __allocate_data_block(struct dnode_of_data *dn)
608 * b. do not use extent cache for better performance 608 * b. do not use extent cache for better performance
609 * c. give the block addresses to blockdev 609 * c. give the block addresses to blockdev
610 */ 610 */
611static int get_data_block(struct inode *inode, sector_t iblock, 611static int __get_data_block(struct inode *inode, sector_t iblock,
612 struct buffer_head *bh_result, int create) 612 struct buffer_head *bh_result, int create, bool fiemap)
613{ 613{
614 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); 614 struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
615 unsigned int blkbits = inode->i_sb->s_blocksize_bits; 615 unsigned int blkbits = inode->i_sb->s_blocksize_bits;
@@ -637,7 +637,7 @@ static int get_data_block(struct inode *inode, sector_t iblock,
637 err = 0; 637 err = 0;
638 goto unlock_out; 638 goto unlock_out;
639 } 639 }
640 if (dn.data_blkaddr == NEW_ADDR) 640 if (dn.data_blkaddr == NEW_ADDR && !fiemap)
641 goto put_out; 641 goto put_out;
642 642
643 if (dn.data_blkaddr != NULL_ADDR) { 643 if (dn.data_blkaddr != NULL_ADDR) {
@@ -671,7 +671,7 @@ get_next:
671 err = 0; 671 err = 0;
672 goto unlock_out; 672 goto unlock_out;
673 } 673 }
674 if (dn.data_blkaddr == NEW_ADDR) 674 if (dn.data_blkaddr == NEW_ADDR && !fiemap)
675 goto put_out; 675 goto put_out;
676 676
677 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode)); 677 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
@@ -708,10 +708,23 @@ out:
708 return err; 708 return err;
709} 709}
710 710
711static int get_data_block(struct inode *inode, sector_t iblock,
712 struct buffer_head *bh_result, int create)
713{
714 return __get_data_block(inode, iblock, bh_result, create, false);
715}
716
717static int get_data_block_fiemap(struct inode *inode, sector_t iblock,
718 struct buffer_head *bh_result, int create)
719{
720 return __get_data_block(inode, iblock, bh_result, create, true);
721}
722
711int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 723int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
712 u64 start, u64 len) 724 u64 start, u64 len)
713{ 725{
714 return generic_block_fiemap(inode, fieinfo, start, len, get_data_block); 726 return generic_block_fiemap(inode, fieinfo,
727 start, len, get_data_block_fiemap);
715} 728}
716 729
717static int f2fs_read_data_page(struct file *file, struct page *page) 730static int f2fs_read_data_page(struct file *file, struct page *page)
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 966acb039e3b..a4addd72ebbd 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -376,11 +376,11 @@ static struct page *init_inode_metadata(struct inode *inode,
376 376
377put_error: 377put_error:
378 f2fs_put_page(page, 1); 378 f2fs_put_page(page, 1);
379error:
379 /* once the failed inode becomes a bad inode, i_mode is S_IFREG */ 380 /* once the failed inode becomes a bad inode, i_mode is S_IFREG */
380 truncate_inode_pages(&inode->i_data, 0); 381 truncate_inode_pages(&inode->i_data, 0);
381 truncate_blocks(inode, 0); 382 truncate_blocks(inode, 0);
382 remove_dirty_dir_inode(inode); 383 remove_dirty_dir_inode(inode);
383error:
384 remove_inode_page(inode); 384 remove_inode_page(inode);
385 return ERR_PTR(err); 385 return ERR_PTR(err);
386} 386}
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e51c732b0dd9..58df97e174d0 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -342,9 +342,6 @@ struct f2fs_sm_info {
342 struct dirty_seglist_info *dirty_info; /* dirty segment information */ 342 struct dirty_seglist_info *dirty_info; /* dirty segment information */
343 struct curseg_info *curseg_array; /* active segment information */ 343 struct curseg_info *curseg_array; /* active segment information */
344 344
345 struct list_head wblist_head; /* list of under-writeback pages */
346 spinlock_t wblist_lock; /* lock for checkpoint */
347
348 block_t seg0_blkaddr; /* block address of 0'th segment */ 345 block_t seg0_blkaddr; /* block address of 0'th segment */
349 block_t main_blkaddr; /* start block address of main area */ 346 block_t main_blkaddr; /* start block address of main area */
350 block_t ssa_blkaddr; /* start block address of SSA area */ 347 block_t ssa_blkaddr; /* start block address of SSA area */
@@ -644,7 +641,8 @@ static inline void f2fs_unlock_all(struct f2fs_sb_info *sbi)
644 */ 641 */
645static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 642static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
646{ 643{
647 WARN_ON((nid >= NM_I(sbi)->max_nid)); 644 if (unlikely(nid < F2FS_ROOT_INO(sbi)))
645 return -EINVAL;
648 if (unlikely(nid >= NM_I(sbi)->max_nid)) 646 if (unlikely(nid >= NM_I(sbi)->max_nid))
649 return -EINVAL; 647 return -EINVAL;
650 return 0; 648 return 0;
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c58e33075719..7d8b96275092 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -659,16 +659,19 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
659 off_start = offset & (PAGE_CACHE_SIZE - 1); 659 off_start = offset & (PAGE_CACHE_SIZE - 1);
660 off_end = (offset + len) & (PAGE_CACHE_SIZE - 1); 660 off_end = (offset + len) & (PAGE_CACHE_SIZE - 1);
661 661
662 f2fs_lock_op(sbi);
663
662 for (index = pg_start; index <= pg_end; index++) { 664 for (index = pg_start; index <= pg_end; index++) {
663 struct dnode_of_data dn; 665 struct dnode_of_data dn;
664 666
665 f2fs_lock_op(sbi); 667 if (index == pg_end && !off_end)
668 goto noalloc;
669
666 set_new_dnode(&dn, inode, NULL, NULL, 0); 670 set_new_dnode(&dn, inode, NULL, NULL, 0);
667 ret = f2fs_reserve_block(&dn, index); 671 ret = f2fs_reserve_block(&dn, index);
668 f2fs_unlock_op(sbi);
669 if (ret) 672 if (ret)
670 break; 673 break;
671 674noalloc:
672 if (pg_start == pg_end) 675 if (pg_start == pg_end)
673 new_size = offset + len; 676 new_size = offset + len;
674 else if (index == pg_start && off_start) 677 else if (index == pg_start && off_start)
@@ -683,8 +686,9 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
683 i_size_read(inode) < new_size) { 686 i_size_read(inode) < new_size) {
684 i_size_write(inode, new_size); 687 i_size_write(inode, new_size);
685 mark_inode_dirty(inode); 688 mark_inode_dirty(inode);
686 f2fs_write_inode(inode, NULL); 689 update_inode_page(inode);
687 } 690 }
691 f2fs_unlock_op(sbi);
688 692
689 return ret; 693 return ret;
690} 694}
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index adc622c6bdce..2cf6962f6cc8 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -78,6 +78,7 @@ static int do_read_inode(struct inode *inode)
78 if (check_nid_range(sbi, inode->i_ino)) { 78 if (check_nid_range(sbi, inode->i_ino)) {
79 f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu", 79 f2fs_msg(inode->i_sb, KERN_ERR, "bad inode number: %lu",
80 (unsigned long) inode->i_ino); 80 (unsigned long) inode->i_ino);
81 WARN_ON(1);
81 return -EINVAL; 82 return -EINVAL;
82 } 83 }
83 84
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 9138c32aa698..a6bdddc33ce2 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -417,9 +417,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
417 } 417 }
418 418
419 f2fs_set_link(new_dir, new_entry, new_page, old_inode); 419 f2fs_set_link(new_dir, new_entry, new_page, old_inode);
420 down_write(&F2FS_I(old_inode)->i_sem);
421 F2FS_I(old_inode)->i_pino = new_dir->i_ino;
422 up_write(&F2FS_I(old_inode)->i_sem);
423 420
424 new_inode->i_ctime = CURRENT_TIME; 421 new_inode->i_ctime = CURRENT_TIME;
425 down_write(&F2FS_I(new_inode)->i_sem); 422 down_write(&F2FS_I(new_inode)->i_sem);
@@ -448,6 +445,10 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
448 } 445 }
449 } 446 }
450 447
448 down_write(&F2FS_I(old_inode)->i_sem);
449 file_lost_pino(old_inode);
450 up_write(&F2FS_I(old_inode)->i_sem);
451
451 old_inode->i_ctime = CURRENT_TIME; 452 old_inode->i_ctime = CURRENT_TIME;
452 mark_inode_dirty(old_inode); 453 mark_inode_dirty(old_inode);
453 454
@@ -457,9 +458,6 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
457 if (old_dir != new_dir) { 458 if (old_dir != new_dir) {
458 f2fs_set_link(old_inode, old_dir_entry, 459 f2fs_set_link(old_inode, old_dir_entry,
459 old_dir_page, new_dir); 460 old_dir_page, new_dir);
460 down_write(&F2FS_I(old_inode)->i_sem);
461 F2FS_I(old_inode)->i_pino = new_dir->i_ino;
462 up_write(&F2FS_I(old_inode)->i_sem);
463 update_inode_page(old_inode); 461 update_inode_page(old_inode);
464 } else { 462 } else {
465 kunmap(old_dir_page); 463 kunmap(old_dir_page);
@@ -474,7 +472,8 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
474 return 0; 472 return 0;
475 473
476put_out_dir: 474put_out_dir:
477 f2fs_put_page(new_page, 1); 475 kunmap(new_page);
476 f2fs_put_page(new_page, 0);
478out_dir: 477out_dir:
479 if (old_dir_entry) { 478 if (old_dir_entry) {
480 kunmap(old_dir_page); 479 kunmap(old_dir_page);
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 9dfb9a042fd2..4b697ccc9b0c 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -42,6 +42,8 @@ bool available_free_memory(struct f2fs_sb_info *sbi, int type)
42 mem_size = (nm_i->nat_cnt * sizeof(struct nat_entry)) >> 12; 42 mem_size = (nm_i->nat_cnt * sizeof(struct nat_entry)) >> 12;
43 res = mem_size < ((val.totalram * nm_i->ram_thresh / 100) >> 2); 43 res = mem_size < ((val.totalram * nm_i->ram_thresh / 100) >> 2);
44 } else if (type == DIRTY_DENTS) { 44 } else if (type == DIRTY_DENTS) {
45 if (sbi->sb->s_bdi->dirty_exceeded)
46 return false;
45 mem_size = get_pages(sbi, F2FS_DIRTY_DENTS); 47 mem_size = get_pages(sbi, F2FS_DIRTY_DENTS);
46 res = mem_size < ((val.totalram * nm_i->ram_thresh / 100) >> 1); 48 res = mem_size < ((val.totalram * nm_i->ram_thresh / 100) >> 1);
47 } 49 }
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index f25f0e07e26f..d04613df710a 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -272,14 +272,15 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi)
272 return -ENOMEM; 272 return -ENOMEM;
273 spin_lock_init(&fcc->issue_lock); 273 spin_lock_init(&fcc->issue_lock);
274 init_waitqueue_head(&fcc->flush_wait_queue); 274 init_waitqueue_head(&fcc->flush_wait_queue);
275 sbi->sm_info->cmd_control_info = fcc;
275 fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi, 276 fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi,
276 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev)); 277 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev));
277 if (IS_ERR(fcc->f2fs_issue_flush)) { 278 if (IS_ERR(fcc->f2fs_issue_flush)) {
278 err = PTR_ERR(fcc->f2fs_issue_flush); 279 err = PTR_ERR(fcc->f2fs_issue_flush);
279 kfree(fcc); 280 kfree(fcc);
281 sbi->sm_info->cmd_control_info = NULL;
280 return err; 282 return err;
281 } 283 }
282 sbi->sm_info->cmd_control_info = fcc;
283 284
284 return err; 285 return err;
285} 286}
@@ -1885,8 +1886,6 @@ int build_segment_manager(struct f2fs_sb_info *sbi)
1885 1886
1886 /* init sm info */ 1887 /* init sm info */
1887 sbi->sm_info = sm_info; 1888 sbi->sm_info = sm_info;
1888 INIT_LIST_HEAD(&sm_info->wblist_head);
1889 spin_lock_init(&sm_info->wblist_lock);
1890 sm_info->seg0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr); 1889 sm_info->seg0_blkaddr = le32_to_cpu(raw_super->segment0_blkaddr);
1891 sm_info->main_blkaddr = le32_to_cpu(raw_super->main_blkaddr); 1890 sm_info->main_blkaddr = le32_to_cpu(raw_super->main_blkaddr);
1892 sm_info->segment_count = le32_to_cpu(raw_super->segment_count); 1891 sm_info->segment_count = le32_to_cpu(raw_super->segment_count);
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index b2b18637cb9e..8f96d9372ade 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -689,9 +689,7 @@ static struct inode *f2fs_nfs_get_inode(struct super_block *sb,
689 struct f2fs_sb_info *sbi = F2FS_SB(sb); 689 struct f2fs_sb_info *sbi = F2FS_SB(sb);
690 struct inode *inode; 690 struct inode *inode;
691 691
692 if (unlikely(ino < F2FS_ROOT_INO(sbi))) 692 if (check_nid_range(sbi, ino))
693 return ERR_PTR(-ESTALE);
694 if (unlikely(ino >= NM_I(sbi)->max_nid))
695 return ERR_PTR(-ESTALE); 693 return ERR_PTR(-ESTALE);
696 694
697 /* 695 /*
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index e3d37f607f97..d895b4b7b661 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -39,6 +39,19 @@ struct kernfs_open_node {
39 struct list_head files; /* goes through kernfs_open_file.list */ 39 struct list_head files; /* goes through kernfs_open_file.list */
40}; 40};
41 41
42/*
43 * kernfs_notify() may be called from any context and bounces notifications
44 * through a work item. To minimize space overhead in kernfs_node, the
45 * pending queue is implemented as a singly linked list of kernfs_nodes.
46 * The list is terminated with the self pointer so that whether a
47 * kernfs_node is on the list or not can be determined by testing the next
48 * pointer for NULL.
49 */
50#define KERNFS_NOTIFY_EOL ((void *)&kernfs_notify_list)
51
52static DEFINE_SPINLOCK(kernfs_notify_lock);
53static struct kernfs_node *kernfs_notify_list = KERNFS_NOTIFY_EOL;
54
42static struct kernfs_open_file *kernfs_of(struct file *file) 55static struct kernfs_open_file *kernfs_of(struct file *file)
43{ 56{
44 return ((struct seq_file *)file->private_data)->private; 57 return ((struct seq_file *)file->private_data)->private;
@@ -783,24 +796,25 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
783 return DEFAULT_POLLMASK|POLLERR|POLLPRI; 796 return DEFAULT_POLLMASK|POLLERR|POLLPRI;
784} 797}
785 798
786/** 799static void kernfs_notify_workfn(struct work_struct *work)
787 * kernfs_notify - notify a kernfs file
788 * @kn: file to notify
789 *
790 * Notify @kn such that poll(2) on @kn wakes up.
791 */
792void kernfs_notify(struct kernfs_node *kn)
793{ 800{
794 struct kernfs_root *root = kernfs_root(kn); 801 struct kernfs_node *kn;
795 struct kernfs_open_node *on; 802 struct kernfs_open_node *on;
796 struct kernfs_super_info *info; 803 struct kernfs_super_info *info;
797 unsigned long flags; 804repeat:
798 805 /* pop one off the notify_list */
799 if (WARN_ON(kernfs_type(kn) != KERNFS_FILE)) 806 spin_lock_irq(&kernfs_notify_lock);
807 kn = kernfs_notify_list;
808 if (kn == KERNFS_NOTIFY_EOL) {
809 spin_unlock_irq(&kernfs_notify_lock);
800 return; 810 return;
811 }
812 kernfs_notify_list = kn->attr.notify_next;
813 kn->attr.notify_next = NULL;
814 spin_unlock_irq(&kernfs_notify_lock);
801 815
802 /* kick poll */ 816 /* kick poll */
803 spin_lock_irqsave(&kernfs_open_node_lock, flags); 817 spin_lock_irq(&kernfs_open_node_lock);
804 818
805 on = kn->attr.open; 819 on = kn->attr.open;
806 if (on) { 820 if (on) {
@@ -808,12 +822,12 @@ void kernfs_notify(struct kernfs_node *kn)
808 wake_up_interruptible(&on->poll); 822 wake_up_interruptible(&on->poll);
809 } 823 }
810 824
811 spin_unlock_irqrestore(&kernfs_open_node_lock, flags); 825 spin_unlock_irq(&kernfs_open_node_lock);
812 826
813 /* kick fsnotify */ 827 /* kick fsnotify */
814 mutex_lock(&kernfs_mutex); 828 mutex_lock(&kernfs_mutex);
815 829
816 list_for_each_entry(info, &root->supers, node) { 830 list_for_each_entry(info, &kernfs_root(kn)->supers, node) {
817 struct inode *inode; 831 struct inode *inode;
818 struct dentry *dentry; 832 struct dentry *dentry;
819 833
@@ -833,6 +847,33 @@ void kernfs_notify(struct kernfs_node *kn)
833 } 847 }
834 848
835 mutex_unlock(&kernfs_mutex); 849 mutex_unlock(&kernfs_mutex);
850 kernfs_put(kn);
851 goto repeat;
852}
853
854/**
855 * kernfs_notify - notify a kernfs file
856 * @kn: file to notify
857 *
858 * Notify @kn such that poll(2) on @kn wakes up. Maybe be called from any
859 * context.
860 */
861void kernfs_notify(struct kernfs_node *kn)
862{
863 static DECLARE_WORK(kernfs_notify_work, kernfs_notify_workfn);
864 unsigned long flags;
865
866 if (WARN_ON(kernfs_type(kn) != KERNFS_FILE))
867 return;
868
869 spin_lock_irqsave(&kernfs_notify_lock, flags);
870 if (!kn->attr.notify_next) {
871 kernfs_get(kn);
872 kn->attr.notify_next = kernfs_notify_list;
873 kernfs_notify_list = kn;
874 schedule_work(&kernfs_notify_work);
875 }
876 spin_unlock_irqrestore(&kernfs_notify_lock, flags);
836} 877}
837EXPORT_SYMBOL_GPL(kernfs_notify); 878EXPORT_SYMBOL_GPL(kernfs_notify);
838 879
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index d171b98a6cdd..f973ae9b05f1 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -211,6 +211,36 @@ void kernfs_kill_sb(struct super_block *sb)
211 kernfs_put(root_kn); 211 kernfs_put(root_kn);
212} 212}
213 213
214/**
215 * kernfs_pin_sb: try to pin the superblock associated with a kernfs_root
216 * @kernfs_root: the kernfs_root in question
217 * @ns: the namespace tag
218 *
219 * Pin the superblock so the superblock won't be destroyed in subsequent
220 * operations. This can be used to block ->kill_sb() which may be useful
221 * for kernfs users which dynamically manage superblocks.
222 *
223 * Returns NULL if there's no superblock associated to this kernfs_root, or
224 * -EINVAL if the superblock is being freed.
225 */
226struct super_block *kernfs_pin_sb(struct kernfs_root *root, const void *ns)
227{
228 struct kernfs_super_info *info;
229 struct super_block *sb = NULL;
230
231 mutex_lock(&kernfs_mutex);
232 list_for_each_entry(info, &root->supers, node) {
233 if (info->ns == ns) {
234 sb = info->sb;
235 if (!atomic_inc_not_zero(&info->sb->s_active))
236 sb = ERR_PTR(-EINVAL);
237 break;
238 }
239 }
240 mutex_unlock(&kernfs_mutex);
241 return sb;
242}
243
214void __init kernfs_init(void) 244void __init kernfs_init(void)
215{ 245{
216 kernfs_node_cache = kmem_cache_create("kernfs_node_cache", 246 kernfs_node_cache = kmem_cache_create("kernfs_node_cache",
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 6851b003f2a4..8f029db5d271 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -617,15 +617,6 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
617 617
618 switch (create->cr_type) { 618 switch (create->cr_type) {
619 case NF4LNK: 619 case NF4LNK:
620 /* ugh! we have to null-terminate the linktext, or
621 * vfs_symlink() will choke. it is always safe to
622 * null-terminate by brute force, since at worst we
623 * will overwrite the first byte of the create namelen
624 * in the XDR buffer, which has already been extracted
625 * during XDR decode.
626 */
627 create->cr_linkname[create->cr_linklen] = 0;
628
629 status = nfsd_symlink(rqstp, &cstate->current_fh, 620 status = nfsd_symlink(rqstp, &cstate->current_fh,
630 create->cr_name, create->cr_namelen, 621 create->cr_name, create->cr_namelen,
631 create->cr_linkname, create->cr_linklen, 622 create->cr_linkname, create->cr_linklen,
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 83baf2bfe9e9..b56b1cc02718 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -600,7 +600,18 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create
600 READ_BUF(4); 600 READ_BUF(4);
601 create->cr_linklen = be32_to_cpup(p++); 601 create->cr_linklen = be32_to_cpup(p++);
602 READ_BUF(create->cr_linklen); 602 READ_BUF(create->cr_linklen);
603 SAVEMEM(create->cr_linkname, create->cr_linklen); 603 /*
604 * The VFS will want a null-terminated string, and
605 * null-terminating in place isn't safe since this might
606 * end on a page boundary:
607 */
608 create->cr_linkname =
609 kmalloc(create->cr_linklen + 1, GFP_KERNEL);
610 if (!create->cr_linkname)
611 return nfserr_jukebox;
612 memcpy(create->cr_linkname, p, create->cr_linklen);
613 create->cr_linkname[create->cr_linklen] = '\0';
614 defer_free(argp, kfree, create->cr_linkname);
604 break; 615 break;
605 case NF4BLK: 616 case NF4BLK:
606 case NF4CHR: 617 case NF4CHR:
@@ -2630,7 +2641,7 @@ nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr)
2630{ 2641{
2631 __be32 *p; 2642 __be32 *p;
2632 2643
2633 p = xdr_reserve_space(xdr, 6); 2644 p = xdr_reserve_space(xdr, 20);
2634 if (!p) 2645 if (!p)
2635 return NULL; 2646 return NULL;
2636 *p++ = htonl(2); 2647 *p++ = htonl(2);
@@ -3267,7 +3278,7 @@ nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd
3267 3278
3268 wire_count = htonl(maxcount); 3279 wire_count = htonl(maxcount);
3269 write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4); 3280 write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4);
3270 xdr_truncate_encode(xdr, length_offset + 4 + maxcount); 3281 xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4));
3271 if (maxcount & 3) 3282 if (maxcount & 3)
3272 write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, 3283 write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount,
3273 &zero, 4 - (maxcount&3)); 3284 &zero, 4 - (maxcount&3));
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 9d231e9e5f0e..bf2d03f8fd3e 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -184,29 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
184 184
185static int stat_open(struct inode *inode, struct file *file) 185static int stat_open(struct inode *inode, struct file *file)
186{ 186{
187 size_t size = 1024 + 128 * num_possible_cpus(); 187 size_t size = 1024 + 128 * num_online_cpus();
188 char *buf;
189 struct seq_file *m;
190 int res;
191 188
192 /* minimum size to display an interrupt count : 2 bytes */ 189 /* minimum size to display an interrupt count : 2 bytes */
193 size += 2 * nr_irqs; 190 size += 2 * nr_irqs;
194 191 return single_open_size(file, show_stat, NULL, size);
195 /* don't ask for more than the kmalloc() max size */
196 if (size > KMALLOC_MAX_SIZE)
197 size = KMALLOC_MAX_SIZE;
198 buf = kmalloc(size, GFP_KERNEL);
199 if (!buf)
200 return -ENOMEM;
201
202 res = single_open(file, show_stat, NULL);
203 if (!res) {
204 m = file->private_data;
205 m->buf = buf;
206 m->size = ksize(buf);
207 } else
208 kfree(buf);
209 return res;
210} 192}
211 193
212static const struct file_operations proc_stat_operations = { 194static const struct file_operations proc_stat_operations = {
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 1d641bb108d2..3857b720cb1b 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -8,8 +8,10 @@
8#include <linux/fs.h> 8#include <linux/fs.h>
9#include <linux/export.h> 9#include <linux/export.h>
10#include <linux/seq_file.h> 10#include <linux/seq_file.h>
11#include <linux/vmalloc.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12#include <linux/cred.h> 13#include <linux/cred.h>
14#include <linux/mm.h>
13 15
14#include <asm/uaccess.h> 16#include <asm/uaccess.h>
15#include <asm/page.h> 17#include <asm/page.h>
@@ -30,6 +32,16 @@ static void seq_set_overflow(struct seq_file *m)
30 m->count = m->size; 32 m->count = m->size;
31} 33}
32 34
35static void *seq_buf_alloc(unsigned long size)
36{
37 void *buf;
38
39 buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
40 if (!buf && size > PAGE_SIZE)
41 buf = vmalloc(size);
42 return buf;
43}
44
33/** 45/**
34 * seq_open - initialize sequential file 46 * seq_open - initialize sequential file
35 * @file: file we initialize 47 * @file: file we initialize
@@ -96,7 +108,7 @@ static int traverse(struct seq_file *m, loff_t offset)
96 return 0; 108 return 0;
97 } 109 }
98 if (!m->buf) { 110 if (!m->buf) {
99 m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); 111 m->buf = seq_buf_alloc(m->size = PAGE_SIZE);
100 if (!m->buf) 112 if (!m->buf)
101 return -ENOMEM; 113 return -ENOMEM;
102 } 114 }
@@ -135,9 +147,9 @@ static int traverse(struct seq_file *m, loff_t offset)
135 147
136Eoverflow: 148Eoverflow:
137 m->op->stop(m, p); 149 m->op->stop(m, p);
138 kfree(m->buf); 150 kvfree(m->buf);
139 m->count = 0; 151 m->count = 0;
140 m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); 152 m->buf = seq_buf_alloc(m->size <<= 1);
141 return !m->buf ? -ENOMEM : -EAGAIN; 153 return !m->buf ? -ENOMEM : -EAGAIN;
142} 154}
143 155
@@ -192,7 +204,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
192 204
193 /* grab buffer if we didn't have one */ 205 /* grab buffer if we didn't have one */
194 if (!m->buf) { 206 if (!m->buf) {
195 m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL); 207 m->buf = seq_buf_alloc(m->size = PAGE_SIZE);
196 if (!m->buf) 208 if (!m->buf)
197 goto Enomem; 209 goto Enomem;
198 } 210 }
@@ -232,9 +244,9 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
232 if (m->count < m->size) 244 if (m->count < m->size)
233 goto Fill; 245 goto Fill;
234 m->op->stop(m, p); 246 m->op->stop(m, p);
235 kfree(m->buf); 247 kvfree(m->buf);
236 m->count = 0; 248 m->count = 0;
237 m->buf = kmalloc(m->size <<= 1, GFP_KERNEL); 249 m->buf = seq_buf_alloc(m->size <<= 1);
238 if (!m->buf) 250 if (!m->buf)
239 goto Enomem; 251 goto Enomem;
240 m->version = 0; 252 m->version = 0;
@@ -350,7 +362,7 @@ EXPORT_SYMBOL(seq_lseek);
350int seq_release(struct inode *inode, struct file *file) 362int seq_release(struct inode *inode, struct file *file)
351{ 363{
352 struct seq_file *m = file->private_data; 364 struct seq_file *m = file->private_data;
353 kfree(m->buf); 365 kvfree(m->buf);
354 kfree(m); 366 kfree(m);
355 return 0; 367 return 0;
356} 368}
@@ -605,13 +617,13 @@ EXPORT_SYMBOL(single_open);
605int single_open_size(struct file *file, int (*show)(struct seq_file *, void *), 617int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
606 void *data, size_t size) 618 void *data, size_t size)
607{ 619{
608 char *buf = kmalloc(size, GFP_KERNEL); 620 char *buf = seq_buf_alloc(size);
609 int ret; 621 int ret;
610 if (!buf) 622 if (!buf)
611 return -ENOMEM; 623 return -ENOMEM;
612 ret = single_open(file, show, data); 624 ret = single_open(file, show, data);
613 if (ret) { 625 if (ret) {
614 kfree(buf); 626 kvfree(buf);
615 return ret; 627 return ret;
616 } 628 }
617 ((struct seq_file *)file->private_data)->buf = buf; 629 ((struct seq_file *)file->private_data)->buf = buf;