diff options
Diffstat (limited to 'fs')
55 files changed, 732 insertions, 307 deletions
@@ -1021,6 +1021,7 @@ void aio_complete(struct kiocb *iocb, long res, long res2) | |||
1021 | 1021 | ||
1022 | /* everything turned out well, dispose of the aiocb. */ | 1022 | /* everything turned out well, dispose of the aiocb. */ |
1023 | kiocb_free(iocb); | 1023 | kiocb_free(iocb); |
1024 | put_reqs_available(ctx, 1); | ||
1024 | 1025 | ||
1025 | /* | 1026 | /* |
1026 | * We have to order our ring_info tail store above and test | 1027 | * We have to order our ring_info tail store above and test |
@@ -1062,6 +1063,9 @@ static long aio_read_events_ring(struct kioctx *ctx, | |||
1062 | if (head == tail) | 1063 | if (head == tail) |
1063 | goto out; | 1064 | goto out; |
1064 | 1065 | ||
1066 | head %= ctx->nr_events; | ||
1067 | tail %= ctx->nr_events; | ||
1068 | |||
1065 | while (ret < nr) { | 1069 | while (ret < nr) { |
1066 | long avail; | 1070 | long avail; |
1067 | struct io_event *ev; | 1071 | struct io_event *ev; |
@@ -1100,8 +1104,6 @@ static long aio_read_events_ring(struct kioctx *ctx, | |||
1100 | flush_dcache_page(ctx->ring_pages[0]); | 1104 | flush_dcache_page(ctx->ring_pages[0]); |
1101 | 1105 | ||
1102 | pr_debug("%li h%u t%u\n", ret, head, tail); | 1106 | pr_debug("%li h%u t%u\n", ret, head, tail); |
1103 | |||
1104 | put_reqs_available(ctx, ret); | ||
1105 | out: | 1107 | out: |
1106 | mutex_unlock(&ctx->ring_lock); | 1108 | mutex_unlock(&ctx->ring_lock); |
1107 | 1109 | ||
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 | ||
40 | static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, | 41 | static 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, | |||
369 | out: | 369 | out: |
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) | |||
136 | void btrfs_update_iflags(struct inode *inode) | 136 | void 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: | |||
3139 | static void clone_update_extent_map(struct inode *inode, | 3142 | static 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 | ||
3573 | out: | 3574 | out: |
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 | ||
57 | static void print_extent_item(struct extent_buffer *eb, int slot) | 57 | static 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 | ||
608 | static int add_device_membership(struct btrfs_fs_info *fs_info) | 608 | int 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 | |||
628 | int 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); | |||
66 | extern const char * const btrfs_feature_set_names[3]; | 66 | extern const char * const btrfs_feature_set_names[3]; |
67 | extern struct kobj_type space_info_ktype; | 67 | extern struct kobj_type space_info_ktype; |
68 | extern struct kobj_type btrfs_raid_ktype; | 68 | extern struct kobj_type btrfs_raid_ktype; |
69 | int btrfs_kobj_add_device(struct btrfs_fs_info *fs_info, | ||
70 | struct btrfs_device *one_device); | ||
71 | int 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 | ||
44 | static int init_first_rw_device(struct btrfs_trans_handle *trans, | 45 | static 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); |
2209 | error: | 2229 | error: |
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/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index 0227b45ef00a..15e9505aa35f 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c | |||
@@ -290,7 +290,8 @@ int | |||
290 | cifsConvertToUTF16(__le16 *target, const char *source, int srclen, | 290 | cifsConvertToUTF16(__le16 *target, const char *source, int srclen, |
291 | const struct nls_table *cp, int mapChars) | 291 | const struct nls_table *cp, int mapChars) |
292 | { | 292 | { |
293 | int i, j, charlen; | 293 | int i, charlen; |
294 | int j = 0; | ||
294 | char src_char; | 295 | char src_char; |
295 | __le16 dst_char; | 296 | __le16 dst_char; |
296 | wchar_t tmp; | 297 | wchar_t tmp; |
@@ -298,12 +299,11 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen, | |||
298 | if (!mapChars) | 299 | if (!mapChars) |
299 | return cifs_strtoUTF16(target, source, PATH_MAX, cp); | 300 | return cifs_strtoUTF16(target, source, PATH_MAX, cp); |
300 | 301 | ||
301 | for (i = 0, j = 0; i < srclen; j++) { | 302 | for (i = 0; i < srclen; j++) { |
302 | src_char = source[i]; | 303 | src_char = source[i]; |
303 | charlen = 1; | 304 | charlen = 1; |
304 | switch (src_char) { | 305 | switch (src_char) { |
305 | case 0: | 306 | case 0: |
306 | put_unaligned(0, &target[j]); | ||
307 | goto ctoUTF16_out; | 307 | goto ctoUTF16_out; |
308 | case ':': | 308 | case ':': |
309 | dst_char = cpu_to_le16(UNI_COLON); | 309 | dst_char = cpu_to_le16(UNI_COLON); |
@@ -350,6 +350,7 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen, | |||
350 | } | 350 | } |
351 | 351 | ||
352 | ctoUTF16_out: | 352 | ctoUTF16_out: |
353 | put_unaligned(0, &target[j]); /* Null terminate target unicode string */ | ||
353 | return j; | 354 | return j; |
354 | } | 355 | } |
355 | 356 | ||
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 2c90d07c0b3a..888398067420 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c | |||
@@ -725,6 +725,19 @@ out_nls: | |||
725 | goto out; | 725 | goto out; |
726 | } | 726 | } |
727 | 727 | ||
728 | static ssize_t | ||
729 | cifs_loose_read_iter(struct kiocb *iocb, struct iov_iter *iter) | ||
730 | { | ||
731 | ssize_t rc; | ||
732 | struct inode *inode = file_inode(iocb->ki_filp); | ||
733 | |||
734 | rc = cifs_revalidate_mapping(inode); | ||
735 | if (rc) | ||
736 | return rc; | ||
737 | |||
738 | return generic_file_read_iter(iocb, iter); | ||
739 | } | ||
740 | |||
728 | static ssize_t cifs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) | 741 | static ssize_t cifs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) |
729 | { | 742 | { |
730 | struct inode *inode = file_inode(iocb->ki_filp); | 743 | struct inode *inode = file_inode(iocb->ki_filp); |
@@ -881,7 +894,7 @@ const struct inode_operations cifs_symlink_inode_ops = { | |||
881 | const struct file_operations cifs_file_ops = { | 894 | const struct file_operations cifs_file_ops = { |
882 | .read = new_sync_read, | 895 | .read = new_sync_read, |
883 | .write = new_sync_write, | 896 | .write = new_sync_write, |
884 | .read_iter = generic_file_read_iter, | 897 | .read_iter = cifs_loose_read_iter, |
885 | .write_iter = cifs_file_write_iter, | 898 | .write_iter = cifs_file_write_iter, |
886 | .open = cifs_open, | 899 | .open = cifs_open, |
887 | .release = cifs_close, | 900 | .release = cifs_close, |
@@ -939,7 +952,7 @@ const struct file_operations cifs_file_direct_ops = { | |||
939 | const struct file_operations cifs_file_nobrl_ops = { | 952 | const struct file_operations cifs_file_nobrl_ops = { |
940 | .read = new_sync_read, | 953 | .read = new_sync_read, |
941 | .write = new_sync_write, | 954 | .write = new_sync_write, |
942 | .read_iter = generic_file_read_iter, | 955 | .read_iter = cifs_loose_read_iter, |
943 | .write_iter = cifs_file_write_iter, | 956 | .write_iter = cifs_file_write_iter, |
944 | .open = cifs_open, | 957 | .open = cifs_open, |
945 | .release = cifs_close, | 958 | .release = cifs_close, |
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 264ece71bdb2..68559fd557fb 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c | |||
@@ -374,7 +374,7 @@ cifs_create_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, | |||
374 | oparms.cifs_sb = cifs_sb; | 374 | oparms.cifs_sb = cifs_sb; |
375 | oparms.desired_access = GENERIC_WRITE; | 375 | oparms.desired_access = GENERIC_WRITE; |
376 | oparms.create_options = create_options; | 376 | oparms.create_options = create_options; |
377 | oparms.disposition = FILE_OPEN; | 377 | oparms.disposition = FILE_CREATE; |
378 | oparms.path = path; | 378 | oparms.path = path; |
379 | oparms.fid = &fid; | 379 | oparms.fid = &fid; |
380 | oparms.reconnect = false; | 380 | oparms.reconnect = false; |
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c index 0762d143e252..fca382037ddd 100644 --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c | |||
@@ -194,7 +194,16 @@ static void ext4_init_block_bitmap(struct super_block *sb, | |||
194 | if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) { | 194 | if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) { |
195 | ext4_error(sb, "Checksum bad for group %u", block_group); | 195 | ext4_error(sb, "Checksum bad for group %u", block_group); |
196 | grp = ext4_get_group_info(sb, block_group); | 196 | grp = ext4_get_group_info(sb, block_group); |
197 | if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) | ||
198 | percpu_counter_sub(&sbi->s_freeclusters_counter, | ||
199 | grp->bb_free); | ||
197 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); | 200 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); |
201 | if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) { | ||
202 | int count; | ||
203 | count = ext4_free_inodes_count(sb, gdp); | ||
204 | percpu_counter_sub(&sbi->s_freeinodes_counter, | ||
205 | count); | ||
206 | } | ||
198 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); | 207 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); |
199 | return; | 208 | return; |
200 | } | 209 | } |
@@ -359,6 +368,7 @@ static void ext4_validate_block_bitmap(struct super_block *sb, | |||
359 | { | 368 | { |
360 | ext4_fsblk_t blk; | 369 | ext4_fsblk_t blk; |
361 | struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); | 370 | struct ext4_group_info *grp = ext4_get_group_info(sb, block_group); |
371 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
362 | 372 | ||
363 | if (buffer_verified(bh)) | 373 | if (buffer_verified(bh)) |
364 | return; | 374 | return; |
@@ -369,6 +379,9 @@ static void ext4_validate_block_bitmap(struct super_block *sb, | |||
369 | ext4_unlock_group(sb, block_group); | 379 | ext4_unlock_group(sb, block_group); |
370 | ext4_error(sb, "bg %u: block %llu: invalid block bitmap", | 380 | ext4_error(sb, "bg %u: block %llu: invalid block bitmap", |
371 | block_group, blk); | 381 | block_group, blk); |
382 | if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) | ||
383 | percpu_counter_sub(&sbi->s_freeclusters_counter, | ||
384 | grp->bb_free); | ||
372 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); | 385 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); |
373 | return; | 386 | return; |
374 | } | 387 | } |
@@ -376,6 +389,9 @@ static void ext4_validate_block_bitmap(struct super_block *sb, | |||
376 | desc, bh))) { | 389 | desc, bh))) { |
377 | ext4_unlock_group(sb, block_group); | 390 | ext4_unlock_group(sb, block_group); |
378 | ext4_error(sb, "bg %u: bad block bitmap checksum", block_group); | 391 | ext4_error(sb, "bg %u: bad block bitmap checksum", block_group); |
392 | if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) | ||
393 | percpu_counter_sub(&sbi->s_freeclusters_counter, | ||
394 | grp->bb_free); | ||
379 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); | 395 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); |
380 | return; | 396 | return; |
381 | } | 397 | } |
diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 3f5c188953a4..0b7e28e7eaa4 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c | |||
@@ -966,10 +966,10 @@ retry: | |||
966 | continue; | 966 | continue; |
967 | } | 967 | } |
968 | 968 | ||
969 | if (ei->i_es_lru_nr == 0 || ei == locked_ei) | 969 | if (ei->i_es_lru_nr == 0 || ei == locked_ei || |
970 | !write_trylock(&ei->i_es_lock)) | ||
970 | continue; | 971 | continue; |
971 | 972 | ||
972 | write_lock(&ei->i_es_lock); | ||
973 | shrunk = __es_try_to_reclaim_extents(ei, nr_to_scan); | 973 | shrunk = __es_try_to_reclaim_extents(ei, nr_to_scan); |
974 | if (ei->i_es_lru_nr == 0) | 974 | if (ei->i_es_lru_nr == 0) |
975 | list_del_init(&ei->i_es_lru); | 975 | list_del_init(&ei->i_es_lru); |
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index 0ee59a6644e2..5b87fc36aab8 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c | |||
@@ -71,6 +71,7 @@ static unsigned ext4_init_inode_bitmap(struct super_block *sb, | |||
71 | struct ext4_group_desc *gdp) | 71 | struct ext4_group_desc *gdp) |
72 | { | 72 | { |
73 | struct ext4_group_info *grp; | 73 | struct ext4_group_info *grp; |
74 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
74 | J_ASSERT_BH(bh, buffer_locked(bh)); | 75 | J_ASSERT_BH(bh, buffer_locked(bh)); |
75 | 76 | ||
76 | /* If checksum is bad mark all blocks and inodes use to prevent | 77 | /* If checksum is bad mark all blocks and inodes use to prevent |
@@ -78,7 +79,16 @@ static unsigned ext4_init_inode_bitmap(struct super_block *sb, | |||
78 | if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) { | 79 | if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) { |
79 | ext4_error(sb, "Checksum bad for group %u", block_group); | 80 | ext4_error(sb, "Checksum bad for group %u", block_group); |
80 | grp = ext4_get_group_info(sb, block_group); | 81 | grp = ext4_get_group_info(sb, block_group); |
82 | if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) | ||
83 | percpu_counter_sub(&sbi->s_freeclusters_counter, | ||
84 | grp->bb_free); | ||
81 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); | 85 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); |
86 | if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) { | ||
87 | int count; | ||
88 | count = ext4_free_inodes_count(sb, gdp); | ||
89 | percpu_counter_sub(&sbi->s_freeinodes_counter, | ||
90 | count); | ||
91 | } | ||
82 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); | 92 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); |
83 | return 0; | 93 | return 0; |
84 | } | 94 | } |
@@ -116,6 +126,7 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group) | |||
116 | struct buffer_head *bh = NULL; | 126 | struct buffer_head *bh = NULL; |
117 | ext4_fsblk_t bitmap_blk; | 127 | ext4_fsblk_t bitmap_blk; |
118 | struct ext4_group_info *grp; | 128 | struct ext4_group_info *grp; |
129 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
119 | 130 | ||
120 | desc = ext4_get_group_desc(sb, block_group, NULL); | 131 | desc = ext4_get_group_desc(sb, block_group, NULL); |
121 | if (!desc) | 132 | if (!desc) |
@@ -185,6 +196,12 @@ verify: | |||
185 | ext4_error(sb, "Corrupt inode bitmap - block_group = %u, " | 196 | ext4_error(sb, "Corrupt inode bitmap - block_group = %u, " |
186 | "inode_bitmap = %llu", block_group, bitmap_blk); | 197 | "inode_bitmap = %llu", block_group, bitmap_blk); |
187 | grp = ext4_get_group_info(sb, block_group); | 198 | grp = ext4_get_group_info(sb, block_group); |
199 | if (!EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) { | ||
200 | int count; | ||
201 | count = ext4_free_inodes_count(sb, desc); | ||
202 | percpu_counter_sub(&sbi->s_freeinodes_counter, | ||
203 | count); | ||
204 | } | ||
188 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); | 205 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); |
189 | return NULL; | 206 | return NULL; |
190 | } | 207 | } |
@@ -321,6 +338,12 @@ out: | |||
321 | fatal = err; | 338 | fatal = err; |
322 | } else { | 339 | } else { |
323 | ext4_error(sb, "bit already cleared for inode %lu", ino); | 340 | ext4_error(sb, "bit already cleared for inode %lu", ino); |
341 | if (gdp && !EXT4_MB_GRP_IBITMAP_CORRUPT(grp)) { | ||
342 | int count; | ||
343 | count = ext4_free_inodes_count(sb, gdp); | ||
344 | percpu_counter_sub(&sbi->s_freeinodes_counter, | ||
345 | count); | ||
346 | } | ||
324 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); | 347 | set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state); |
325 | } | 348 | } |
326 | 349 | ||
@@ -851,6 +874,13 @@ got: | |||
851 | goto out; | 874 | goto out; |
852 | } | 875 | } |
853 | 876 | ||
877 | BUFFER_TRACE(group_desc_bh, "get_write_access"); | ||
878 | err = ext4_journal_get_write_access(handle, group_desc_bh); | ||
879 | if (err) { | ||
880 | ext4_std_error(sb, err); | ||
881 | goto out; | ||
882 | } | ||
883 | |||
854 | /* We may have to initialize the block bitmap if it isn't already */ | 884 | /* We may have to initialize the block bitmap if it isn't already */ |
855 | if (ext4_has_group_desc_csum(sb) && | 885 | if (ext4_has_group_desc_csum(sb) && |
856 | gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { | 886 | gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { |
@@ -887,13 +917,6 @@ got: | |||
887 | } | 917 | } |
888 | } | 918 | } |
889 | 919 | ||
890 | BUFFER_TRACE(group_desc_bh, "get_write_access"); | ||
891 | err = ext4_journal_get_write_access(handle, group_desc_bh); | ||
892 | if (err) { | ||
893 | ext4_std_error(sb, err); | ||
894 | goto out; | ||
895 | } | ||
896 | |||
897 | /* Update the relevant bg descriptor fields */ | 920 | /* Update the relevant bg descriptor fields */ |
898 | if (ext4_has_group_desc_csum(sb)) { | 921 | if (ext4_has_group_desc_csum(sb)) { |
899 | int free; | 922 | int free; |
diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c index 8a57e9fcd1b9..fd69da194826 100644 --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c | |||
@@ -389,7 +389,13 @@ static int ext4_alloc_branch(handle_t *handle, struct inode *inode, | |||
389 | return 0; | 389 | return 0; |
390 | failed: | 390 | failed: |
391 | for (; i >= 0; i--) { | 391 | for (; i >= 0; i--) { |
392 | if (i != indirect_blks && branch[i].bh) | 392 | /* |
393 | * We want to ext4_forget() only freshly allocated indirect | ||
394 | * blocks. Buffer for new_blocks[i-1] is at branch[i].bh and | ||
395 | * buffer at branch[0].bh is indirect block / inode already | ||
396 | * existing before ext4_alloc_branch() was called. | ||
397 | */ | ||
398 | if (i > 0 && i != indirect_blks && branch[i].bh) | ||
393 | ext4_forget(handle, 1, inode, branch[i].bh, | 399 | ext4_forget(handle, 1, inode, branch[i].bh, |
394 | branch[i].bh->b_blocknr); | 400 | branch[i].bh->b_blocknr); |
395 | ext4_free_blocks(handle, inode, NULL, new_blocks[i], | 401 | ext4_free_blocks(handle, inode, NULL, new_blocks[i], |
@@ -1310,16 +1316,24 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode, | |||
1310 | blk = *i_data; | 1316 | blk = *i_data; |
1311 | if (level > 0) { | 1317 | if (level > 0) { |
1312 | ext4_lblk_t first2; | 1318 | ext4_lblk_t first2; |
1319 | ext4_lblk_t count2; | ||
1320 | |||
1313 | bh = sb_bread(inode->i_sb, le32_to_cpu(blk)); | 1321 | bh = sb_bread(inode->i_sb, le32_to_cpu(blk)); |
1314 | if (!bh) { | 1322 | if (!bh) { |
1315 | EXT4_ERROR_INODE_BLOCK(inode, le32_to_cpu(blk), | 1323 | EXT4_ERROR_INODE_BLOCK(inode, le32_to_cpu(blk), |
1316 | "Read failure"); | 1324 | "Read failure"); |
1317 | return -EIO; | 1325 | return -EIO; |
1318 | } | 1326 | } |
1319 | first2 = (first > offset) ? first - offset : 0; | 1327 | if (first > offset) { |
1328 | first2 = first - offset; | ||
1329 | count2 = count; | ||
1330 | } else { | ||
1331 | first2 = 0; | ||
1332 | count2 = count - (offset - first); | ||
1333 | } | ||
1320 | ret = free_hole_blocks(handle, inode, bh, | 1334 | ret = free_hole_blocks(handle, inode, bh, |
1321 | (__le32 *)bh->b_data, level - 1, | 1335 | (__le32 *)bh->b_data, level - 1, |
1322 | first2, count - offset, | 1336 | first2, count2, |
1323 | inode->i_sb->s_blocksize >> 2); | 1337 | inode->i_sb->s_blocksize >> 2); |
1324 | if (ret) { | 1338 | if (ret) { |
1325 | brelse(bh); | 1339 | brelse(bh); |
@@ -1329,8 +1343,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode, | |||
1329 | if (level == 0 || | 1343 | if (level == 0 || |
1330 | (bh && all_zeroes((__le32 *)bh->b_data, | 1344 | (bh && all_zeroes((__le32 *)bh->b_data, |
1331 | (__le32 *)bh->b_data + addr_per_block))) { | 1345 | (__le32 *)bh->b_data + addr_per_block))) { |
1332 | ext4_free_data(handle, inode, parent_bh, &blk, &blk+1); | 1346 | ext4_free_data(handle, inode, parent_bh, |
1333 | *i_data = 0; | 1347 | i_data, i_data + 1); |
1334 | } | 1348 | } |
1335 | brelse(bh); | 1349 | brelse(bh); |
1336 | bh = NULL; | 1350 | bh = NULL; |
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 59e31622cc6e..2dcb936be90e 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c | |||
@@ -722,6 +722,7 @@ void ext4_mb_generate_buddy(struct super_block *sb, | |||
722 | void *buddy, void *bitmap, ext4_group_t group) | 722 | void *buddy, void *bitmap, ext4_group_t group) |
723 | { | 723 | { |
724 | struct ext4_group_info *grp = ext4_get_group_info(sb, group); | 724 | struct ext4_group_info *grp = ext4_get_group_info(sb, group); |
725 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
725 | ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb); | 726 | ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb); |
726 | ext4_grpblk_t i = 0; | 727 | ext4_grpblk_t i = 0; |
727 | ext4_grpblk_t first; | 728 | ext4_grpblk_t first; |
@@ -751,14 +752,17 @@ void ext4_mb_generate_buddy(struct super_block *sb, | |||
751 | 752 | ||
752 | if (free != grp->bb_free) { | 753 | if (free != grp->bb_free) { |
753 | ext4_grp_locked_error(sb, group, 0, 0, | 754 | ext4_grp_locked_error(sb, group, 0, 0, |
754 | "%u clusters in bitmap, %u in gd; " | 755 | "block bitmap and bg descriptor " |
755 | "block bitmap corrupt.", | 756 | "inconsistent: %u vs %u free clusters", |
756 | free, grp->bb_free); | 757 | free, grp->bb_free); |
757 | /* | 758 | /* |
758 | * If we intend to continue, we consider group descriptor | 759 | * If we intend to continue, we consider group descriptor |
759 | * corrupt and update bb_free using bitmap value | 760 | * corrupt and update bb_free using bitmap value |
760 | */ | 761 | */ |
761 | grp->bb_free = free; | 762 | grp->bb_free = free; |
763 | if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp)) | ||
764 | percpu_counter_sub(&sbi->s_freeclusters_counter, | ||
765 | grp->bb_free); | ||
762 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); | 766 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, &grp->bb_state); |
763 | } | 767 | } |
764 | mb_set_largest_free_order(sb, grp); | 768 | mb_set_largest_free_order(sb, grp); |
@@ -1431,6 +1435,7 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, | |||
1431 | right_is_free = !mb_test_bit(last + 1, e4b->bd_bitmap); | 1435 | right_is_free = !mb_test_bit(last + 1, e4b->bd_bitmap); |
1432 | 1436 | ||
1433 | if (unlikely(block != -1)) { | 1437 | if (unlikely(block != -1)) { |
1438 | struct ext4_sb_info *sbi = EXT4_SB(sb); | ||
1434 | ext4_fsblk_t blocknr; | 1439 | ext4_fsblk_t blocknr; |
1435 | 1440 | ||
1436 | blocknr = ext4_group_first_block_no(sb, e4b->bd_group); | 1441 | blocknr = ext4_group_first_block_no(sb, e4b->bd_group); |
@@ -1441,6 +1446,9 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b, | |||
1441 | "freeing already freed block " | 1446 | "freeing already freed block " |
1442 | "(bit %u); block bitmap corrupt.", | 1447 | "(bit %u); block bitmap corrupt.", |
1443 | block); | 1448 | block); |
1449 | if (!EXT4_MB_GRP_BBITMAP_CORRUPT(e4b->bd_info)) | ||
1450 | percpu_counter_sub(&sbi->s_freeclusters_counter, | ||
1451 | e4b->bd_info->bb_free); | ||
1444 | /* Mark the block group as corrupt. */ | 1452 | /* Mark the block group as corrupt. */ |
1445 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, | 1453 | set_bit(EXT4_GROUP_INFO_BBITMAP_CORRUPT_BIT, |
1446 | &e4b->bd_info->bb_state); | 1454 | &e4b->bd_info->bb_state); |
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index b9b9aabfb4d2..6df7bc611dbd 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c | |||
@@ -1525,8 +1525,6 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, | |||
1525 | arg = JBD2_DEFAULT_MAX_COMMIT_AGE; | 1525 | arg = JBD2_DEFAULT_MAX_COMMIT_AGE; |
1526 | sbi->s_commit_interval = HZ * arg; | 1526 | sbi->s_commit_interval = HZ * arg; |
1527 | } else if (token == Opt_max_batch_time) { | 1527 | } else if (token == Opt_max_batch_time) { |
1528 | if (arg == 0) | ||
1529 | arg = EXT4_DEF_MAX_BATCH_TIME; | ||
1530 | sbi->s_max_batch_time = arg; | 1528 | sbi->s_max_batch_time = arg; |
1531 | } else if (token == Opt_min_batch_time) { | 1529 | } else if (token == Opt_min_batch_time) { |
1532 | sbi->s_min_batch_time = arg; | 1530 | sbi->s_min_batch_time = arg; |
@@ -2809,10 +2807,11 @@ static void print_daily_error_info(unsigned long arg) | |||
2809 | es = sbi->s_es; | 2807 | es = sbi->s_es; |
2810 | 2808 | ||
2811 | if (es->s_error_count) | 2809 | if (es->s_error_count) |
2812 | ext4_msg(sb, KERN_NOTICE, "error count: %u", | 2810 | /* fsck newer than v1.41.13 is needed to clean this condition. */ |
2811 | ext4_msg(sb, KERN_NOTICE, "error count since last fsck: %u", | ||
2813 | le32_to_cpu(es->s_error_count)); | 2812 | le32_to_cpu(es->s_error_count)); |
2814 | if (es->s_first_error_time) { | 2813 | if (es->s_first_error_time) { |
2815 | printk(KERN_NOTICE "EXT4-fs (%s): initial error at %u: %.*s:%d", | 2814 | printk(KERN_NOTICE "EXT4-fs (%s): initial error at time %u: %.*s:%d", |
2816 | sb->s_id, le32_to_cpu(es->s_first_error_time), | 2815 | sb->s_id, le32_to_cpu(es->s_first_error_time), |
2817 | (int) sizeof(es->s_first_error_func), | 2816 | (int) sizeof(es->s_first_error_func), |
2818 | es->s_first_error_func, | 2817 | es->s_first_error_func, |
@@ -2826,7 +2825,7 @@ static void print_daily_error_info(unsigned long arg) | |||
2826 | printk("\n"); | 2825 | printk("\n"); |
2827 | } | 2826 | } |
2828 | if (es->s_last_error_time) { | 2827 | if (es->s_last_error_time) { |
2829 | printk(KERN_NOTICE "EXT4-fs (%s): last error at %u: %.*s:%d", | 2828 | printk(KERN_NOTICE "EXT4-fs (%s): last error at time %u: %.*s:%d", |
2830 | sb->s_id, le32_to_cpu(es->s_last_error_time), | 2829 | sb->s_id, le32_to_cpu(es->s_last_error_time), |
2831 | (int) sizeof(es->s_last_error_func), | 2830 | (int) sizeof(es->s_last_error_func), |
2832 | es->s_last_error_func, | 2831 | es->s_last_error_func, |
@@ -3880,38 +3879,19 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3880 | goto failed_mount2; | 3879 | goto failed_mount2; |
3881 | } | 3880 | } |
3882 | } | 3881 | } |
3883 | |||
3884 | /* | ||
3885 | * set up enough so that it can read an inode, | ||
3886 | * and create new inode for buddy allocator | ||
3887 | */ | ||
3888 | sbi->s_gdb_count = db_count; | ||
3889 | if (!test_opt(sb, NOLOAD) && | ||
3890 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) | ||
3891 | sb->s_op = &ext4_sops; | ||
3892 | else | ||
3893 | sb->s_op = &ext4_nojournal_sops; | ||
3894 | |||
3895 | ext4_ext_init(sb); | ||
3896 | err = ext4_mb_init(sb); | ||
3897 | if (err) { | ||
3898 | ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)", | ||
3899 | err); | ||
3900 | goto failed_mount2; | ||
3901 | } | ||
3902 | |||
3903 | if (!ext4_check_descriptors(sb, &first_not_zeroed)) { | 3882 | if (!ext4_check_descriptors(sb, &first_not_zeroed)) { |
3904 | ext4_msg(sb, KERN_ERR, "group descriptors corrupted!"); | 3883 | ext4_msg(sb, KERN_ERR, "group descriptors corrupted!"); |
3905 | goto failed_mount2a; | 3884 | goto failed_mount2; |
3906 | } | 3885 | } |
3907 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) | 3886 | if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) |
3908 | if (!ext4_fill_flex_info(sb)) { | 3887 | if (!ext4_fill_flex_info(sb)) { |
3909 | ext4_msg(sb, KERN_ERR, | 3888 | ext4_msg(sb, KERN_ERR, |
3910 | "unable to initialize " | 3889 | "unable to initialize " |
3911 | "flex_bg meta info!"); | 3890 | "flex_bg meta info!"); |
3912 | goto failed_mount2a; | 3891 | goto failed_mount2; |
3913 | } | 3892 | } |
3914 | 3893 | ||
3894 | sbi->s_gdb_count = db_count; | ||
3915 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); | 3895 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
3916 | spin_lock_init(&sbi->s_next_gen_lock); | 3896 | spin_lock_init(&sbi->s_next_gen_lock); |
3917 | 3897 | ||
@@ -3946,6 +3926,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) | |||
3946 | sbi->s_stripe = ext4_get_stripe_size(sbi); | 3926 | sbi->s_stripe = ext4_get_stripe_size(sbi); |
3947 | sbi->s_extent_max_zeroout_kb = 32; | 3927 | sbi->s_extent_max_zeroout_kb = 32; |
3948 | 3928 | ||
3929 | /* | ||
3930 | * set up enough so that it can read an inode | ||
3931 | */ | ||
3932 | if (!test_opt(sb, NOLOAD) && | ||
3933 | EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)) | ||
3934 | sb->s_op = &ext4_sops; | ||
3935 | else | ||
3936 | sb->s_op = &ext4_nojournal_sops; | ||
3949 | sb->s_export_op = &ext4_export_ops; | 3937 | sb->s_export_op = &ext4_export_ops; |
3950 | sb->s_xattr = ext4_xattr_handlers; | 3938 | sb->s_xattr = ext4_xattr_handlers; |
3951 | #ifdef CONFIG_QUOTA | 3939 | #ifdef CONFIG_QUOTA |
@@ -4135,13 +4123,21 @@ no_journal: | |||
4135 | if (err) { | 4123 | if (err) { |
4136 | ext4_msg(sb, KERN_ERR, "failed to reserve %llu clusters for " | 4124 | ext4_msg(sb, KERN_ERR, "failed to reserve %llu clusters for " |
4137 | "reserved pool", ext4_calculate_resv_clusters(sb)); | 4125 | "reserved pool", ext4_calculate_resv_clusters(sb)); |
4138 | goto failed_mount5; | 4126 | goto failed_mount4a; |
4139 | } | 4127 | } |
4140 | 4128 | ||
4141 | err = ext4_setup_system_zone(sb); | 4129 | err = ext4_setup_system_zone(sb); |
4142 | if (err) { | 4130 | if (err) { |
4143 | ext4_msg(sb, KERN_ERR, "failed to initialize system " | 4131 | ext4_msg(sb, KERN_ERR, "failed to initialize system " |
4144 | "zone (%d)", err); | 4132 | "zone (%d)", err); |
4133 | goto failed_mount4a; | ||
4134 | } | ||
4135 | |||
4136 | ext4_ext_init(sb); | ||
4137 | err = ext4_mb_init(sb); | ||
4138 | if (err) { | ||
4139 | ext4_msg(sb, KERN_ERR, "failed to initialize mballoc (%d)", | ||
4140 | err); | ||
4145 | goto failed_mount5; | 4141 | goto failed_mount5; |
4146 | } | 4142 | } |
4147 | 4143 | ||
@@ -4218,8 +4214,11 @@ failed_mount8: | |||
4218 | failed_mount7: | 4214 | failed_mount7: |
4219 | ext4_unregister_li_request(sb); | 4215 | ext4_unregister_li_request(sb); |
4220 | failed_mount6: | 4216 | failed_mount6: |
4221 | ext4_release_system_zone(sb); | 4217 | ext4_mb_release(sb); |
4222 | failed_mount5: | 4218 | failed_mount5: |
4219 | ext4_ext_release(sb); | ||
4220 | ext4_release_system_zone(sb); | ||
4221 | failed_mount4a: | ||
4223 | dput(sb->s_root); | 4222 | dput(sb->s_root); |
4224 | sb->s_root = NULL; | 4223 | sb->s_root = NULL; |
4225 | failed_mount4: | 4224 | failed_mount4: |
@@ -4243,14 +4242,11 @@ failed_mount3: | |||
4243 | percpu_counter_destroy(&sbi->s_extent_cache_cnt); | 4242 | percpu_counter_destroy(&sbi->s_extent_cache_cnt); |
4244 | if (sbi->s_mmp_tsk) | 4243 | if (sbi->s_mmp_tsk) |
4245 | kthread_stop(sbi->s_mmp_tsk); | 4244 | kthread_stop(sbi->s_mmp_tsk); |
4246 | failed_mount2a: | ||
4247 | ext4_mb_release(sb); | ||
4248 | failed_mount2: | 4245 | failed_mount2: |
4249 | for (i = 0; i < db_count; i++) | 4246 | for (i = 0; i < db_count; i++) |
4250 | brelse(sbi->s_group_desc[i]); | 4247 | brelse(sbi->s_group_desc[i]); |
4251 | ext4_kvfree(sbi->s_group_desc); | 4248 | ext4_kvfree(sbi->s_group_desc); |
4252 | failed_mount: | 4249 | failed_mount: |
4253 | ext4_ext_release(sb); | ||
4254 | if (sbi->s_chksum_driver) | 4250 | if (sbi->s_chksum_driver) |
4255 | crypto_free_shash(sbi->s_chksum_driver); | 4251 | crypto_free_shash(sbi->s_chksum_driver); |
4256 | if (sbi->s_proc) { | 4252 | if (sbi->s_proc) { |
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 | */ |
611 | static int get_data_block(struct inode *inode, sector_t iblock, | 611 | static 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 | ||
711 | static 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 | |||
717 | static 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 | |||
711 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, | 723 | int 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 | ||
717 | static int f2fs_read_data_page(struct file *file, struct page *page) | 730 | static 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 | ||
377 | put_error: | 377 | put_error: |
378 | f2fs_put_page(page, 1); | 378 | f2fs_put_page(page, 1); |
379 | error: | ||
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); |
383 | error: | ||
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 | */ |
645 | static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) | 642 | static 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 | 674 | noalloc: | |
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 | ||
476 | put_out_dir: | 474 | put_out_dir: |
477 | f2fs_put_page(new_page, 1); | 475 | kunmap(new_page); |
476 | f2fs_put_page(new_page, 0); | ||
478 | out_dir: | 477 | out_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/jbd2/transaction.c b/fs/jbd2/transaction.c index 38cfcf5f6fce..6f0f590cc5a3 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c | |||
@@ -1588,9 +1588,12 @@ int jbd2_journal_stop(handle_t *handle) | |||
1588 | * to perform a synchronous write. We do this to detect the | 1588 | * to perform a synchronous write. We do this to detect the |
1589 | * case where a single process is doing a stream of sync | 1589 | * case where a single process is doing a stream of sync |
1590 | * writes. No point in waiting for joiners in that case. | 1590 | * writes. No point in waiting for joiners in that case. |
1591 | * | ||
1592 | * Setting max_batch_time to 0 disables this completely. | ||
1591 | */ | 1593 | */ |
1592 | pid = current->pid; | 1594 | pid = current->pid; |
1593 | if (handle->h_sync && journal->j_last_sync_writer != pid) { | 1595 | if (handle->h_sync && journal->j_last_sync_writer != pid && |
1596 | journal->j_max_batch_time) { | ||
1594 | u64 commit_time, trans_time; | 1597 | u64 commit_time, trans_time; |
1595 | 1598 | ||
1596 | journal->j_last_sync_writer = pid; | 1599 | journal->j_last_sync_writer = pid; |
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 | |||
52 | static DEFINE_SPINLOCK(kernfs_notify_lock); | ||
53 | static struct kernfs_node *kernfs_notify_list = KERNFS_NOTIFY_EOL; | ||
54 | |||
42 | static struct kernfs_open_file *kernfs_of(struct file *file) | 55 | static 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 | /** | 799 | static 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 | */ | ||
792 | void 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; | 804 | repeat: |
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 | */ | ||
861 | void 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 | } |
837 | EXPORT_SYMBOL_GPL(kernfs_notify); | 878 | EXPORT_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 | */ | ||
226 | struct 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 | |||
214 | void __init kernfs_init(void) | 244 | void __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/mbcache.c b/fs/mbcache.c index bf166e388f0d..187477ded6b3 100644 --- a/fs/mbcache.c +++ b/fs/mbcache.c | |||
@@ -73,6 +73,7 @@ | |||
73 | #include <linux/mbcache.h> | 73 | #include <linux/mbcache.h> |
74 | #include <linux/init.h> | 74 | #include <linux/init.h> |
75 | #include <linux/blockgroup_lock.h> | 75 | #include <linux/blockgroup_lock.h> |
76 | #include <linux/log2.h> | ||
76 | 77 | ||
77 | #ifdef MB_CACHE_DEBUG | 78 | #ifdef MB_CACHE_DEBUG |
78 | # define mb_debug(f...) do { \ | 79 | # define mb_debug(f...) do { \ |
@@ -93,7 +94,7 @@ | |||
93 | 94 | ||
94 | #define MB_CACHE_WRITER ((unsigned short)~0U >> 1) | 95 | #define MB_CACHE_WRITER ((unsigned short)~0U >> 1) |
95 | 96 | ||
96 | #define MB_CACHE_ENTRY_LOCK_BITS __builtin_log2(NR_BG_LOCKS) | 97 | #define MB_CACHE_ENTRY_LOCK_BITS ilog2(NR_BG_LOCKS) |
97 | #define MB_CACHE_ENTRY_LOCK_INDEX(ce) \ | 98 | #define MB_CACHE_ENTRY_LOCK_INDEX(ce) \ |
98 | (hash_long((unsigned long)ce, MB_CACHE_ENTRY_LOCK_BITS)) | 99 | (hash_long((unsigned long)ce, MB_CACHE_ENTRY_LOCK_BITS)) |
99 | 100 | ||
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index c496f8a74639..9927913c97c2 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -147,6 +147,17 @@ int nfs_sync_mapping(struct address_space *mapping) | |||
147 | return ret; | 147 | return ret; |
148 | } | 148 | } |
149 | 149 | ||
150 | static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) | ||
151 | { | ||
152 | struct nfs_inode *nfsi = NFS_I(inode); | ||
153 | |||
154 | if (inode->i_mapping->nrpages == 0) | ||
155 | flags &= ~NFS_INO_INVALID_DATA; | ||
156 | nfsi->cache_validity |= flags; | ||
157 | if (flags & NFS_INO_INVALID_DATA) | ||
158 | nfs_fscache_invalidate(inode); | ||
159 | } | ||
160 | |||
150 | /* | 161 | /* |
151 | * Invalidate the local caches | 162 | * Invalidate the local caches |
152 | */ | 163 | */ |
@@ -162,17 +173,16 @@ static void nfs_zap_caches_locked(struct inode *inode) | |||
162 | 173 | ||
163 | memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf)); | 174 | memset(NFS_I(inode)->cookieverf, 0, sizeof(NFS_I(inode)->cookieverf)); |
164 | if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) { | 175 | if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)) { |
165 | nfs_fscache_invalidate(inode); | 176 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR |
166 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | ||
167 | | NFS_INO_INVALID_DATA | 177 | | NFS_INO_INVALID_DATA |
168 | | NFS_INO_INVALID_ACCESS | 178 | | NFS_INO_INVALID_ACCESS |
169 | | NFS_INO_INVALID_ACL | 179 | | NFS_INO_INVALID_ACL |
170 | | NFS_INO_REVAL_PAGECACHE; | 180 | | NFS_INO_REVAL_PAGECACHE); |
171 | } else | 181 | } else |
172 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | 182 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR |
173 | | NFS_INO_INVALID_ACCESS | 183 | | NFS_INO_INVALID_ACCESS |
174 | | NFS_INO_INVALID_ACL | 184 | | NFS_INO_INVALID_ACL |
175 | | NFS_INO_REVAL_PAGECACHE; | 185 | | NFS_INO_REVAL_PAGECACHE); |
176 | nfs_zap_label_cache_locked(nfsi); | 186 | nfs_zap_label_cache_locked(nfsi); |
177 | } | 187 | } |
178 | 188 | ||
@@ -187,8 +197,7 @@ void nfs_zap_mapping(struct inode *inode, struct address_space *mapping) | |||
187 | { | 197 | { |
188 | if (mapping->nrpages != 0) { | 198 | if (mapping->nrpages != 0) { |
189 | spin_lock(&inode->i_lock); | 199 | spin_lock(&inode->i_lock); |
190 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_DATA; | 200 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA); |
191 | nfs_fscache_invalidate(inode); | ||
192 | spin_unlock(&inode->i_lock); | 201 | spin_unlock(&inode->i_lock); |
193 | } | 202 | } |
194 | } | 203 | } |
@@ -209,7 +218,7 @@ EXPORT_SYMBOL_GPL(nfs_zap_acl_cache); | |||
209 | void nfs_invalidate_atime(struct inode *inode) | 218 | void nfs_invalidate_atime(struct inode *inode) |
210 | { | 219 | { |
211 | spin_lock(&inode->i_lock); | 220 | spin_lock(&inode->i_lock); |
212 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ATIME; | 221 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATIME); |
213 | spin_unlock(&inode->i_lock); | 222 | spin_unlock(&inode->i_lock); |
214 | } | 223 | } |
215 | EXPORT_SYMBOL_GPL(nfs_invalidate_atime); | 224 | EXPORT_SYMBOL_GPL(nfs_invalidate_atime); |
@@ -369,7 +378,7 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st | |||
369 | inode->i_mode = fattr->mode; | 378 | inode->i_mode = fattr->mode; |
370 | if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 | 379 | if ((fattr->valid & NFS_ATTR_FATTR_MODE) == 0 |
371 | && nfs_server_capable(inode, NFS_CAP_MODE)) | 380 | && nfs_server_capable(inode, NFS_CAP_MODE)) |
372 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 381 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
373 | /* Why so? Because we want revalidate for devices/FIFOs, and | 382 | /* Why so? Because we want revalidate for devices/FIFOs, and |
374 | * that's precisely what we have in nfs_file_inode_operations. | 383 | * that's precisely what we have in nfs_file_inode_operations. |
375 | */ | 384 | */ |
@@ -415,36 +424,36 @@ nfs_fhget(struct super_block *sb, struct nfs_fh *fh, struct nfs_fattr *fattr, st | |||
415 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) | 424 | if (fattr->valid & NFS_ATTR_FATTR_ATIME) |
416 | inode->i_atime = fattr->atime; | 425 | inode->i_atime = fattr->atime; |
417 | else if (nfs_server_capable(inode, NFS_CAP_ATIME)) | 426 | else if (nfs_server_capable(inode, NFS_CAP_ATIME)) |
418 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 427 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
419 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) | 428 | if (fattr->valid & NFS_ATTR_FATTR_MTIME) |
420 | inode->i_mtime = fattr->mtime; | 429 | inode->i_mtime = fattr->mtime; |
421 | else if (nfs_server_capable(inode, NFS_CAP_MTIME)) | 430 | else if (nfs_server_capable(inode, NFS_CAP_MTIME)) |
422 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 431 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
423 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) | 432 | if (fattr->valid & NFS_ATTR_FATTR_CTIME) |
424 | inode->i_ctime = fattr->ctime; | 433 | inode->i_ctime = fattr->ctime; |
425 | else if (nfs_server_capable(inode, NFS_CAP_CTIME)) | 434 | else if (nfs_server_capable(inode, NFS_CAP_CTIME)) |
426 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 435 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
427 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) | 436 | if (fattr->valid & NFS_ATTR_FATTR_CHANGE) |
428 | inode->i_version = fattr->change_attr; | 437 | inode->i_version = fattr->change_attr; |
429 | else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR)) | 438 | else if (nfs_server_capable(inode, NFS_CAP_CHANGE_ATTR)) |
430 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 439 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
431 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) | 440 | if (fattr->valid & NFS_ATTR_FATTR_SIZE) |
432 | inode->i_size = nfs_size_to_loff_t(fattr->size); | 441 | inode->i_size = nfs_size_to_loff_t(fattr->size); |
433 | else | 442 | else |
434 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR | 443 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR |
435 | | NFS_INO_REVAL_PAGECACHE; | 444 | | NFS_INO_REVAL_PAGECACHE); |
436 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) | 445 | if (fattr->valid & NFS_ATTR_FATTR_NLINK) |
437 | set_nlink(inode, fattr->nlink); | 446 | set_nlink(inode, fattr->nlink); |
438 | else if (nfs_server_capable(inode, NFS_CAP_NLINK)) | 447 | else if (nfs_server_capable(inode, NFS_CAP_NLINK)) |
439 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 448 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
440 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) | 449 | if (fattr->valid & NFS_ATTR_FATTR_OWNER) |
441 | inode->i_uid = fattr->uid; | 450 | inode->i_uid = fattr->uid; |
442 | else if (nfs_server_capable(inode, NFS_CAP_OWNER)) | 451 | else if (nfs_server_capable(inode, NFS_CAP_OWNER)) |
443 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 452 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
444 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) | 453 | if (fattr->valid & NFS_ATTR_FATTR_GROUP) |
445 | inode->i_gid = fattr->gid; | 454 | inode->i_gid = fattr->gid; |
446 | else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP)) | 455 | else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP)) |
447 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR; | 456 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ATTR); |
448 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) | 457 | if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED) |
449 | inode->i_blocks = fattr->du.nfs2.blocks; | 458 | inode->i_blocks = fattr->du.nfs2.blocks; |
450 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { | 459 | if (fattr->valid & NFS_ATTR_FATTR_SPACE_USED) { |
@@ -550,6 +559,9 @@ static int nfs_vmtruncate(struct inode * inode, loff_t offset) | |||
550 | 559 | ||
551 | spin_lock(&inode->i_lock); | 560 | spin_lock(&inode->i_lock); |
552 | i_size_write(inode, offset); | 561 | i_size_write(inode, offset); |
562 | /* Optimisation */ | ||
563 | if (offset == 0) | ||
564 | NFS_I(inode)->cache_validity &= ~NFS_INO_INVALID_DATA; | ||
553 | spin_unlock(&inode->i_lock); | 565 | spin_unlock(&inode->i_lock); |
554 | 566 | ||
555 | truncate_pagecache(inode, offset); | 567 | truncate_pagecache(inode, offset); |
@@ -578,7 +590,8 @@ void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr) | |||
578 | inode->i_uid = attr->ia_uid; | 590 | inode->i_uid = attr->ia_uid; |
579 | if ((attr->ia_valid & ATTR_GID) != 0) | 591 | if ((attr->ia_valid & ATTR_GID) != 0) |
580 | inode->i_gid = attr->ia_gid; | 592 | inode->i_gid = attr->ia_gid; |
581 | NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL; | 593 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_ACCESS |
594 | | NFS_INO_INVALID_ACL); | ||
582 | spin_unlock(&inode->i_lock); | 595 | spin_unlock(&inode->i_lock); |
583 | } | 596 | } |
584 | if ((attr->ia_valid & ATTR_SIZE) != 0) { | 597 | if ((attr->ia_valid & ATTR_SIZE) != 0) { |
@@ -1101,7 +1114,7 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr | |||
1101 | && inode->i_version == fattr->pre_change_attr) { | 1114 | && inode->i_version == fattr->pre_change_attr) { |
1102 | inode->i_version = fattr->change_attr; | 1115 | inode->i_version = fattr->change_attr; |
1103 | if (S_ISDIR(inode->i_mode)) | 1116 | if (S_ISDIR(inode->i_mode)) |
1104 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; | 1117 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA); |
1105 | ret |= NFS_INO_INVALID_ATTR; | 1118 | ret |= NFS_INO_INVALID_ATTR; |
1106 | } | 1119 | } |
1107 | /* If we have atomic WCC data, we may update some attributes */ | 1120 | /* If we have atomic WCC data, we may update some attributes */ |
@@ -1117,7 +1130,7 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr | |||
1117 | && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) { | 1130 | && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) { |
1118 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); | 1131 | memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); |
1119 | if (S_ISDIR(inode->i_mode)) | 1132 | if (S_ISDIR(inode->i_mode)) |
1120 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; | 1133 | nfs_set_cache_invalid(inode, NFS_INO_INVALID_DATA); |
1121 | ret |= NFS_INO_INVALID_ATTR; | 1134 | ret |= NFS_INO_INVALID_ATTR; |
1122 | } | 1135 | } |
1123 | if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE) | 1136 | if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE) |
@@ -1128,9 +1141,6 @@ static unsigned long nfs_wcc_update_inode(struct inode *inode, struct nfs_fattr | |||
1128 | ret |= NFS_INO_INVALID_ATTR; | 1141 | ret |= NFS_INO_INVALID_ATTR; |
1129 | } | 1142 | } |
1130 | 1143 | ||
1131 | if (nfsi->cache_validity & NFS_INO_INVALID_DATA) | ||
1132 | nfs_fscache_invalidate(inode); | ||
1133 | |||
1134 | return ret; | 1144 | return ret; |
1135 | } | 1145 | } |
1136 | 1146 | ||
@@ -1189,7 +1199,7 @@ static int nfs_check_inode_attributes(struct inode *inode, struct nfs_fattr *fat | |||
1189 | invalid |= NFS_INO_INVALID_ATIME; | 1199 | invalid |= NFS_INO_INVALID_ATIME; |
1190 | 1200 | ||
1191 | if (invalid != 0) | 1201 | if (invalid != 0) |
1192 | nfsi->cache_validity |= invalid; | 1202 | nfs_set_cache_invalid(inode, invalid); |
1193 | 1203 | ||
1194 | nfsi->read_cache_jiffies = fattr->time_start; | 1204 | nfsi->read_cache_jiffies = fattr->time_start; |
1195 | return 0; | 1205 | return 0; |
@@ -1402,13 +1412,11 @@ EXPORT_SYMBOL_GPL(nfs_refresh_inode); | |||
1402 | 1412 | ||
1403 | static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr *fattr) | 1413 | static int nfs_post_op_update_inode_locked(struct inode *inode, struct nfs_fattr *fattr) |
1404 | { | 1414 | { |
1405 | struct nfs_inode *nfsi = NFS_I(inode); | 1415 | unsigned long invalid = NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE; |
1406 | 1416 | ||
1407 | nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE; | 1417 | if (S_ISDIR(inode->i_mode)) |
1408 | if (S_ISDIR(inode->i_mode)) { | 1418 | invalid |= NFS_INO_INVALID_DATA; |
1409 | nfsi->cache_validity |= NFS_INO_INVALID_DATA; | 1419 | nfs_set_cache_invalid(inode, invalid); |
1410 | nfs_fscache_invalidate(inode); | ||
1411 | } | ||
1412 | if ((fattr->valid & NFS_ATTR_FATTR) == 0) | 1420 | if ((fattr->valid & NFS_ATTR_FATTR) == 0) |
1413 | return 0; | 1421 | return 0; |
1414 | return nfs_refresh_inode_locked(inode, fattr); | 1422 | return nfs_refresh_inode_locked(inode, fattr); |
@@ -1601,6 +1609,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1601 | if ((nfsi->npages == 0) || new_isize > cur_isize) { | 1609 | if ((nfsi->npages == 0) || new_isize > cur_isize) { |
1602 | i_size_write(inode, new_isize); | 1610 | i_size_write(inode, new_isize); |
1603 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; | 1611 | invalid |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA; |
1612 | invalid &= ~NFS_INO_REVAL_PAGECACHE; | ||
1604 | } | 1613 | } |
1605 | dprintk("NFS: isize change on server for file %s/%ld " | 1614 | dprintk("NFS: isize change on server for file %s/%ld " |
1606 | "(%Ld to %Ld)\n", | 1615 | "(%Ld to %Ld)\n", |
@@ -1702,10 +1711,7 @@ static int nfs_update_inode(struct inode *inode, struct nfs_fattr *fattr) | |||
1702 | invalid &= ~NFS_INO_INVALID_DATA; | 1711 | invalid &= ~NFS_INO_INVALID_DATA; |
1703 | if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) || | 1712 | if (!NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) || |
1704 | (save_cache_validity & NFS_INO_REVAL_FORCED)) | 1713 | (save_cache_validity & NFS_INO_REVAL_FORCED)) |
1705 | nfsi->cache_validity |= invalid; | 1714 | nfs_set_cache_invalid(inode, invalid); |
1706 | |||
1707 | if (invalid & NFS_INO_INVALID_DATA) | ||
1708 | nfs_fscache_invalidate(inode); | ||
1709 | 1715 | ||
1710 | return 0; | 1716 | return 0; |
1711 | out_err: | 1717 | out_err: |
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index f63cb87cd730..ba2affa51941 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h | |||
@@ -230,7 +230,7 @@ int nfs_atomic_open(struct inode *, struct dentry *, struct file *, | |||
230 | extern struct file_system_type nfs4_fs_type; | 230 | extern struct file_system_type nfs4_fs_type; |
231 | 231 | ||
232 | /* nfs4namespace.c */ | 232 | /* nfs4namespace.c */ |
233 | struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *, struct inode *, struct qstr *); | 233 | struct rpc_clnt *nfs4_negotiate_security(struct rpc_clnt *, struct inode *, struct qstr *); |
234 | struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *, | 234 | struct vfsmount *nfs4_submount(struct nfs_server *, struct dentry *, |
235 | struct nfs_fh *, struct nfs_fattr *); | 235 | struct nfs_fh *, struct nfs_fattr *); |
236 | int nfs4_replace_transport(struct nfs_server *server, | 236 | int nfs4_replace_transport(struct nfs_server *server, |
diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c index 3d5dbf80d46a..3d83cb1fdc70 100644 --- a/fs/nfs/nfs4namespace.c +++ b/fs/nfs/nfs4namespace.c | |||
@@ -139,16 +139,22 @@ static size_t nfs_parse_server_name(char *string, size_t len, | |||
139 | * @server: NFS server struct | 139 | * @server: NFS server struct |
140 | * @flavors: List of security tuples returned by SECINFO procedure | 140 | * @flavors: List of security tuples returned by SECINFO procedure |
141 | * | 141 | * |
142 | * Return the pseudoflavor of the first security mechanism in | 142 | * Return an rpc client that uses the first security mechanism in |
143 | * "flavors" that is locally supported. Return RPC_AUTH_UNIX if | 143 | * "flavors" that is locally supported. The "flavors" array |
144 | * no matching flavor is found in the array. The "flavors" array | ||
145 | * is searched in the order returned from the server, per RFC 3530 | 144 | * is searched in the order returned from the server, per RFC 3530 |
146 | * recommendation. | 145 | * recommendation and each flavor is checked for membership in the |
146 | * sec= mount option list if it exists. | ||
147 | * | ||
148 | * Return -EPERM if no matching flavor is found in the array. | ||
149 | * | ||
150 | * Please call rpc_shutdown_client() when you are done with this rpc client. | ||
151 | * | ||
147 | */ | 152 | */ |
148 | static rpc_authflavor_t nfs_find_best_sec(struct nfs_server *server, | 153 | static struct rpc_clnt *nfs_find_best_sec(struct rpc_clnt *clnt, |
154 | struct nfs_server *server, | ||
149 | struct nfs4_secinfo_flavors *flavors) | 155 | struct nfs4_secinfo_flavors *flavors) |
150 | { | 156 | { |
151 | rpc_authflavor_t pseudoflavor; | 157 | rpc_authflavor_t pflavor; |
152 | struct nfs4_secinfo4 *secinfo; | 158 | struct nfs4_secinfo4 *secinfo; |
153 | unsigned int i; | 159 | unsigned int i; |
154 | 160 | ||
@@ -159,62 +165,73 @@ static rpc_authflavor_t nfs_find_best_sec(struct nfs_server *server, | |||
159 | case RPC_AUTH_NULL: | 165 | case RPC_AUTH_NULL: |
160 | case RPC_AUTH_UNIX: | 166 | case RPC_AUTH_UNIX: |
161 | case RPC_AUTH_GSS: | 167 | case RPC_AUTH_GSS: |
162 | pseudoflavor = rpcauth_get_pseudoflavor(secinfo->flavor, | 168 | pflavor = rpcauth_get_pseudoflavor(secinfo->flavor, |
163 | &secinfo->flavor_info); | 169 | &secinfo->flavor_info); |
164 | /* make sure pseudoflavor matches sec= mount opt */ | 170 | /* does the pseudoflavor match a sec= mount opt? */ |
165 | if (pseudoflavor != RPC_AUTH_MAXFLAVOR && | 171 | if (pflavor != RPC_AUTH_MAXFLAVOR && |
166 | nfs_auth_info_match(&server->auth_info, | 172 | nfs_auth_info_match(&server->auth_info, pflavor)) { |
167 | pseudoflavor)) | 173 | struct rpc_clnt *new; |
168 | return pseudoflavor; | 174 | struct rpc_cred *cred; |
169 | break; | 175 | |
176 | /* Cloning creates an rpc_auth for the flavor */ | ||
177 | new = rpc_clone_client_set_auth(clnt, pflavor); | ||
178 | if (IS_ERR(new)) | ||
179 | continue; | ||
180 | /** | ||
181 | * Check that the user actually can use the | ||
182 | * flavor. This is mostly for RPC_AUTH_GSS | ||
183 | * where cr_init obtains a gss context | ||
184 | */ | ||
185 | cred = rpcauth_lookupcred(new->cl_auth, 0); | ||
186 | if (IS_ERR(cred)) { | ||
187 | rpc_shutdown_client(new); | ||
188 | continue; | ||
189 | } | ||
190 | put_rpccred(cred); | ||
191 | return new; | ||
192 | } | ||
170 | } | 193 | } |
171 | } | 194 | } |
172 | 195 | return ERR_PTR(-EPERM); | |
173 | /* if there were any sec= options then nothing matched */ | ||
174 | if (server->auth_info.flavor_len > 0) | ||
175 | return -EPERM; | ||
176 | |||
177 | return RPC_AUTH_UNIX; | ||
178 | } | 196 | } |
179 | 197 | ||
180 | static rpc_authflavor_t nfs4_negotiate_security(struct inode *inode, struct qstr *name) | 198 | /** |
199 | * nfs4_negotiate_security - in response to an NFS4ERR_WRONGSEC on lookup, | ||
200 | * return an rpc_clnt that uses the best available security flavor with | ||
201 | * respect to the secinfo flavor list and the sec= mount options. | ||
202 | * | ||
203 | * @clnt: RPC client to clone | ||
204 | * @inode: directory inode | ||
205 | * @name: lookup name | ||
206 | * | ||
207 | * Please call rpc_shutdown_client() when you are done with this rpc client. | ||
208 | */ | ||
209 | struct rpc_clnt * | ||
210 | nfs4_negotiate_security(struct rpc_clnt *clnt, struct inode *inode, | ||
211 | struct qstr *name) | ||
181 | { | 212 | { |
182 | struct page *page; | 213 | struct page *page; |
183 | struct nfs4_secinfo_flavors *flavors; | 214 | struct nfs4_secinfo_flavors *flavors; |
184 | rpc_authflavor_t flavor; | 215 | struct rpc_clnt *new; |
185 | int err; | 216 | int err; |
186 | 217 | ||
187 | page = alloc_page(GFP_KERNEL); | 218 | page = alloc_page(GFP_KERNEL); |
188 | if (!page) | 219 | if (!page) |
189 | return -ENOMEM; | 220 | return ERR_PTR(-ENOMEM); |
221 | |||
190 | flavors = page_address(page); | 222 | flavors = page_address(page); |
191 | 223 | ||
192 | err = nfs4_proc_secinfo(inode, name, flavors); | 224 | err = nfs4_proc_secinfo(inode, name, flavors); |
193 | if (err < 0) { | 225 | if (err < 0) { |
194 | flavor = err; | 226 | new = ERR_PTR(err); |
195 | goto out; | 227 | goto out; |
196 | } | 228 | } |
197 | 229 | ||
198 | flavor = nfs_find_best_sec(NFS_SERVER(inode), flavors); | 230 | new = nfs_find_best_sec(clnt, NFS_SERVER(inode), flavors); |
199 | 231 | ||
200 | out: | 232 | out: |
201 | put_page(page); | 233 | put_page(page); |
202 | return flavor; | 234 | return new; |
203 | } | ||
204 | |||
205 | /* | ||
206 | * Please call rpc_shutdown_client() when you are done with this client. | ||
207 | */ | ||
208 | struct rpc_clnt *nfs4_create_sec_client(struct rpc_clnt *clnt, struct inode *inode, | ||
209 | struct qstr *name) | ||
210 | { | ||
211 | rpc_authflavor_t flavor; | ||
212 | |||
213 | flavor = nfs4_negotiate_security(inode, name); | ||
214 | if ((int)flavor < 0) | ||
215 | return ERR_PTR((int)flavor); | ||
216 | |||
217 | return rpc_clone_client_set_auth(clnt, flavor); | ||
218 | } | 235 | } |
219 | 236 | ||
220 | static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, | 237 | static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, |
@@ -397,11 +414,6 @@ struct vfsmount *nfs4_submount(struct nfs_server *server, struct dentry *dentry, | |||
397 | 414 | ||
398 | if (client->cl_auth->au_flavor != flavor) | 415 | if (client->cl_auth->au_flavor != flavor) |
399 | flavor = client->cl_auth->au_flavor; | 416 | flavor = client->cl_auth->au_flavor; |
400 | else { | ||
401 | rpc_authflavor_t new = nfs4_negotiate_security(dir, name); | ||
402 | if ((int)new >= 0) | ||
403 | flavor = new; | ||
404 | } | ||
405 | mnt = nfs_do_submount(dentry, fh, fattr, flavor); | 417 | mnt = nfs_do_submount(dentry, fh, fattr, flavor); |
406 | out: | 418 | out: |
407 | rpc_shutdown_client(client); | 419 | rpc_shutdown_client(client); |
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 285ad5334018..4bf3d97cc5a0 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -3247,7 +3247,7 @@ static int nfs4_proc_lookup_common(struct rpc_clnt **clnt, struct inode *dir, | |||
3247 | err = -EPERM; | 3247 | err = -EPERM; |
3248 | if (client != *clnt) | 3248 | if (client != *clnt) |
3249 | goto out; | 3249 | goto out; |
3250 | client = nfs4_create_sec_client(client, dir, name); | 3250 | client = nfs4_negotiate_security(client, dir, name); |
3251 | if (IS_ERR(client)) | 3251 | if (IS_ERR(client)) |
3252 | return PTR_ERR(client); | 3252 | return PTR_ERR(client); |
3253 | 3253 | ||
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 3ee5af4e738e..98ff061ccaf3 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
@@ -934,12 +934,14 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode) | |||
934 | 934 | ||
935 | if (nfs_have_delegated_attributes(inode)) | 935 | if (nfs_have_delegated_attributes(inode)) |
936 | goto out; | 936 | goto out; |
937 | if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE)) | 937 | if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) |
938 | return false; | 938 | return false; |
939 | smp_rmb(); | 939 | smp_rmb(); |
940 | if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) | 940 | if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) |
941 | return false; | 941 | return false; |
942 | out: | 942 | out: |
943 | if (nfsi->cache_validity & NFS_INO_INVALID_DATA) | ||
944 | return false; | ||
943 | return PageUptodate(page) != 0; | 945 | return PageUptodate(page) != 0; |
944 | } | 946 | } |
945 | 947 | ||
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/ocfs2/dlm/dlmcommon.h b/fs/ocfs2/dlm/dlmcommon.h index a106b3f2b22a..fae17c640df3 100644 --- a/fs/ocfs2/dlm/dlmcommon.h +++ b/fs/ocfs2/dlm/dlmcommon.h | |||
@@ -331,6 +331,7 @@ struct dlm_lock_resource | |||
331 | u16 state; | 331 | u16 state; |
332 | char lvb[DLM_LVB_LEN]; | 332 | char lvb[DLM_LVB_LEN]; |
333 | unsigned int inflight_locks; | 333 | unsigned int inflight_locks; |
334 | unsigned int inflight_assert_workers; | ||
334 | unsigned long refmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; | 335 | unsigned long refmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; |
335 | }; | 336 | }; |
336 | 337 | ||
@@ -910,6 +911,9 @@ void dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm, | |||
910 | void dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, | 911 | void dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, |
911 | struct dlm_lock_resource *res); | 912 | struct dlm_lock_resource *res); |
912 | 913 | ||
914 | void __dlm_lockres_grab_inflight_worker(struct dlm_ctxt *dlm, | ||
915 | struct dlm_lock_resource *res); | ||
916 | |||
913 | void dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock); | 917 | void dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock); |
914 | void dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock); | 918 | void dlm_queue_bast(struct dlm_ctxt *dlm, struct dlm_lock *lock); |
915 | void __dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock); | 919 | void __dlm_queue_ast(struct dlm_ctxt *dlm, struct dlm_lock *lock); |
diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c index 3087a21d32f9..82abf0cc9a12 100644 --- a/fs/ocfs2/dlm/dlmmaster.c +++ b/fs/ocfs2/dlm/dlmmaster.c | |||
@@ -581,6 +581,7 @@ static void dlm_init_lockres(struct dlm_ctxt *dlm, | |||
581 | atomic_set(&res->asts_reserved, 0); | 581 | atomic_set(&res->asts_reserved, 0); |
582 | res->migration_pending = 0; | 582 | res->migration_pending = 0; |
583 | res->inflight_locks = 0; | 583 | res->inflight_locks = 0; |
584 | res->inflight_assert_workers = 0; | ||
584 | 585 | ||
585 | res->dlm = dlm; | 586 | res->dlm = dlm; |
586 | 587 | ||
@@ -683,6 +684,43 @@ void dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm, | |||
683 | wake_up(&res->wq); | 684 | wake_up(&res->wq); |
684 | } | 685 | } |
685 | 686 | ||
687 | void __dlm_lockres_grab_inflight_worker(struct dlm_ctxt *dlm, | ||
688 | struct dlm_lock_resource *res) | ||
689 | { | ||
690 | assert_spin_locked(&res->spinlock); | ||
691 | res->inflight_assert_workers++; | ||
692 | mlog(0, "%s:%.*s: inflight assert worker++: now %u\n", | ||
693 | dlm->name, res->lockname.len, res->lockname.name, | ||
694 | res->inflight_assert_workers); | ||
695 | } | ||
696 | |||
697 | static void dlm_lockres_grab_inflight_worker(struct dlm_ctxt *dlm, | ||
698 | struct dlm_lock_resource *res) | ||
699 | { | ||
700 | spin_lock(&res->spinlock); | ||
701 | __dlm_lockres_grab_inflight_worker(dlm, res); | ||
702 | spin_unlock(&res->spinlock); | ||
703 | } | ||
704 | |||
705 | static void __dlm_lockres_drop_inflight_worker(struct dlm_ctxt *dlm, | ||
706 | struct dlm_lock_resource *res) | ||
707 | { | ||
708 | assert_spin_locked(&res->spinlock); | ||
709 | BUG_ON(res->inflight_assert_workers == 0); | ||
710 | res->inflight_assert_workers--; | ||
711 | mlog(0, "%s:%.*s: inflight assert worker--: now %u\n", | ||
712 | dlm->name, res->lockname.len, res->lockname.name, | ||
713 | res->inflight_assert_workers); | ||
714 | } | ||
715 | |||
716 | static void dlm_lockres_drop_inflight_worker(struct dlm_ctxt *dlm, | ||
717 | struct dlm_lock_resource *res) | ||
718 | { | ||
719 | spin_lock(&res->spinlock); | ||
720 | __dlm_lockres_drop_inflight_worker(dlm, res); | ||
721 | spin_unlock(&res->spinlock); | ||
722 | } | ||
723 | |||
686 | /* | 724 | /* |
687 | * lookup a lock resource by name. | 725 | * lookup a lock resource by name. |
688 | * may already exist in the hashtable. | 726 | * may already exist in the hashtable. |
@@ -1603,7 +1641,8 @@ send_response: | |||
1603 | mlog(ML_ERROR, "failed to dispatch assert master work\n"); | 1641 | mlog(ML_ERROR, "failed to dispatch assert master work\n"); |
1604 | response = DLM_MASTER_RESP_ERROR; | 1642 | response = DLM_MASTER_RESP_ERROR; |
1605 | dlm_lockres_put(res); | 1643 | dlm_lockres_put(res); |
1606 | } | 1644 | } else |
1645 | dlm_lockres_grab_inflight_worker(dlm, res); | ||
1607 | } else { | 1646 | } else { |
1608 | if (res) | 1647 | if (res) |
1609 | dlm_lockres_put(res); | 1648 | dlm_lockres_put(res); |
@@ -2118,6 +2157,8 @@ static void dlm_assert_master_worker(struct dlm_work_item *item, void *data) | |||
2118 | dlm_lockres_release_ast(dlm, res); | 2157 | dlm_lockres_release_ast(dlm, res); |
2119 | 2158 | ||
2120 | put: | 2159 | put: |
2160 | dlm_lockres_drop_inflight_worker(dlm, res); | ||
2161 | |||
2121 | dlm_lockres_put(res); | 2162 | dlm_lockres_put(res); |
2122 | 2163 | ||
2123 | mlog(0, "finished with dlm_assert_master_worker\n"); | 2164 | mlog(0, "finished with dlm_assert_master_worker\n"); |
@@ -3088,11 +3129,15 @@ static int dlm_add_migration_mle(struct dlm_ctxt *dlm, | |||
3088 | /* remove it so that only one mle will be found */ | 3129 | /* remove it so that only one mle will be found */ |
3089 | __dlm_unlink_mle(dlm, tmp); | 3130 | __dlm_unlink_mle(dlm, tmp); |
3090 | __dlm_mle_detach_hb_events(dlm, tmp); | 3131 | __dlm_mle_detach_hb_events(dlm, tmp); |
3091 | ret = DLM_MIGRATE_RESPONSE_MASTERY_REF; | 3132 | if (tmp->type == DLM_MLE_MASTER) { |
3092 | mlog(0, "%s:%.*s: master=%u, newmaster=%u, " | 3133 | ret = DLM_MIGRATE_RESPONSE_MASTERY_REF; |
3093 | "telling master to get ref for cleared out mle " | 3134 | mlog(0, "%s:%.*s: master=%u, newmaster=%u, " |
3094 | "during migration\n", dlm->name, namelen, name, | 3135 | "telling master to get ref " |
3095 | master, new_master); | 3136 | "for cleared out mle during " |
3137 | "migration\n", dlm->name, | ||
3138 | namelen, name, master, | ||
3139 | new_master); | ||
3140 | } | ||
3096 | } | 3141 | } |
3097 | spin_unlock(&tmp->spinlock); | 3142 | spin_unlock(&tmp->spinlock); |
3098 | } | 3143 | } |
diff --git a/fs/ocfs2/dlm/dlmrecovery.c b/fs/ocfs2/dlm/dlmrecovery.c index 5de019437ea5..45067faf5695 100644 --- a/fs/ocfs2/dlm/dlmrecovery.c +++ b/fs/ocfs2/dlm/dlmrecovery.c | |||
@@ -1708,7 +1708,8 @@ int dlm_master_requery_handler(struct o2net_msg *msg, u32 len, void *data, | |||
1708 | mlog_errno(-ENOMEM); | 1708 | mlog_errno(-ENOMEM); |
1709 | /* retry!? */ | 1709 | /* retry!? */ |
1710 | BUG(); | 1710 | BUG(); |
1711 | } | 1711 | } else |
1712 | __dlm_lockres_grab_inflight_worker(dlm, res); | ||
1712 | } else /* put.. incase we are not the master */ | 1713 | } else /* put.. incase we are not the master */ |
1713 | dlm_lockres_put(res); | 1714 | dlm_lockres_put(res); |
1714 | spin_unlock(&res->spinlock); | 1715 | spin_unlock(&res->spinlock); |
diff --git a/fs/ocfs2/dlm/dlmthread.c b/fs/ocfs2/dlm/dlmthread.c index 9db869de829d..69aac6f088ad 100644 --- a/fs/ocfs2/dlm/dlmthread.c +++ b/fs/ocfs2/dlm/dlmthread.c | |||
@@ -259,12 +259,15 @@ static void dlm_run_purge_list(struct dlm_ctxt *dlm, | |||
259 | * refs on it. */ | 259 | * refs on it. */ |
260 | unused = __dlm_lockres_unused(lockres); | 260 | unused = __dlm_lockres_unused(lockres); |
261 | if (!unused || | 261 | if (!unused || |
262 | (lockres->state & DLM_LOCK_RES_MIGRATING)) { | 262 | (lockres->state & DLM_LOCK_RES_MIGRATING) || |
263 | (lockres->inflight_assert_workers != 0)) { | ||
263 | mlog(0, "%s: res %.*s is in use or being remastered, " | 264 | mlog(0, "%s: res %.*s is in use or being remastered, " |
264 | "used %d, state %d\n", dlm->name, | 265 | "used %d, state %d, assert master workers %u\n", |
265 | lockres->lockname.len, lockres->lockname.name, | 266 | dlm->name, lockres->lockname.len, |
266 | !unused, lockres->state); | 267 | lockres->lockname.name, |
267 | list_move_tail(&dlm->purge_list, &lockres->purge); | 268 | !unused, lockres->state, |
269 | lockres->inflight_assert_workers); | ||
270 | list_move_tail(&lockres->purge, &dlm->purge_list); | ||
268 | spin_unlock(&lockres->spinlock); | 271 | spin_unlock(&lockres->spinlock); |
269 | continue; | 272 | continue; |
270 | } | 273 | } |
diff --git a/fs/ocfs2/dlm/dlmunlock.c b/fs/ocfs2/dlm/dlmunlock.c index 5698b52cf5c9..2e3c9dbab68c 100644 --- a/fs/ocfs2/dlm/dlmunlock.c +++ b/fs/ocfs2/dlm/dlmunlock.c | |||
@@ -191,7 +191,9 @@ static enum dlm_status dlmunlock_common(struct dlm_ctxt *dlm, | |||
191 | DLM_UNLOCK_CLEAR_CONVERT_TYPE); | 191 | DLM_UNLOCK_CLEAR_CONVERT_TYPE); |
192 | } else if (status == DLM_RECOVERING || | 192 | } else if (status == DLM_RECOVERING || |
193 | status == DLM_MIGRATING || | 193 | status == DLM_MIGRATING || |
194 | status == DLM_FORWARD) { | 194 | status == DLM_FORWARD || |
195 | status == DLM_NOLOCKMGR | ||
196 | ) { | ||
195 | /* must clear the actions because this unlock | 197 | /* must clear the actions because this unlock |
196 | * is about to be retried. cannot free or do | 198 | * is about to be retried. cannot free or do |
197 | * any list manipulation. */ | 199 | * any list manipulation. */ |
@@ -200,7 +202,8 @@ static enum dlm_status dlmunlock_common(struct dlm_ctxt *dlm, | |||
200 | res->lockname.name, | 202 | res->lockname.name, |
201 | status==DLM_RECOVERING?"recovering": | 203 | status==DLM_RECOVERING?"recovering": |
202 | (status==DLM_MIGRATING?"migrating": | 204 | (status==DLM_MIGRATING?"migrating": |
203 | "forward")); | 205 | (status == DLM_FORWARD ? "forward" : |
206 | "nolockmanager"))); | ||
204 | actions = 0; | 207 | actions = 0; |
205 | } | 208 | } |
206 | if (flags & LKM_CANCEL) | 209 | if (flags & LKM_CANCEL) |
@@ -364,7 +367,10 @@ static enum dlm_status dlm_send_remote_unlock_request(struct dlm_ctxt *dlm, | |||
364 | * updated state to the recovery master. this thread | 367 | * updated state to the recovery master. this thread |
365 | * just needs to finish out the operation and call | 368 | * just needs to finish out the operation and call |
366 | * the unlockast. */ | 369 | * the unlockast. */ |
367 | ret = DLM_NORMAL; | 370 | if (dlm_is_node_dead(dlm, owner)) |
371 | ret = DLM_NORMAL; | ||
372 | else | ||
373 | ret = DLM_NOLOCKMGR; | ||
368 | } else { | 374 | } else { |
369 | /* something bad. this will BUG in ocfs2 */ | 375 | /* something bad. this will BUG in ocfs2 */ |
370 | ret = dlm_err_to_dlm_status(tmpret); | 376 | ret = dlm_err_to_dlm_status(tmpret); |
@@ -638,7 +644,9 @@ retry: | |||
638 | 644 | ||
639 | if (status == DLM_RECOVERING || | 645 | if (status == DLM_RECOVERING || |
640 | status == DLM_MIGRATING || | 646 | status == DLM_MIGRATING || |
641 | status == DLM_FORWARD) { | 647 | status == DLM_FORWARD || |
648 | status == DLM_NOLOCKMGR) { | ||
649 | |||
642 | /* We want to go away for a tiny bit to allow recovery | 650 | /* We want to go away for a tiny bit to allow recovery |
643 | * / migration to complete on this resource. I don't | 651 | * / migration to complete on this resource. I don't |
644 | * know of any wait queue we could sleep on as this | 652 | * know of any wait queue we could sleep on as this |
@@ -650,7 +658,7 @@ retry: | |||
650 | msleep(50); | 658 | msleep(50); |
651 | 659 | ||
652 | mlog(0, "retrying unlock due to pending recovery/" | 660 | mlog(0, "retrying unlock due to pending recovery/" |
653 | "migration/in-progress\n"); | 661 | "migration/in-progress/reconnect\n"); |
654 | goto retry; | 662 | goto retry; |
655 | } | 663 | } |
656 | 664 | ||
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c index 2060fc398445..8add6f1030d7 100644 --- a/fs/ocfs2/namei.c +++ b/fs/ocfs2/namei.c | |||
@@ -205,6 +205,21 @@ static struct inode *ocfs2_get_init_inode(struct inode *dir, umode_t mode) | |||
205 | return inode; | 205 | return inode; |
206 | } | 206 | } |
207 | 207 | ||
208 | static void ocfs2_cleanup_add_entry_failure(struct ocfs2_super *osb, | ||
209 | struct dentry *dentry, struct inode *inode) | ||
210 | { | ||
211 | struct ocfs2_dentry_lock *dl = dentry->d_fsdata; | ||
212 | |||
213 | ocfs2_simple_drop_lockres(osb, &dl->dl_lockres); | ||
214 | ocfs2_lock_res_free(&dl->dl_lockres); | ||
215 | BUG_ON(dl->dl_count != 1); | ||
216 | spin_lock(&dentry_attach_lock); | ||
217 | dentry->d_fsdata = NULL; | ||
218 | spin_unlock(&dentry_attach_lock); | ||
219 | kfree(dl); | ||
220 | iput(inode); | ||
221 | } | ||
222 | |||
208 | static int ocfs2_mknod(struct inode *dir, | 223 | static int ocfs2_mknod(struct inode *dir, |
209 | struct dentry *dentry, | 224 | struct dentry *dentry, |
210 | umode_t mode, | 225 | umode_t mode, |
@@ -231,6 +246,7 @@ static int ocfs2_mknod(struct inode *dir, | |||
231 | sigset_t oldset; | 246 | sigset_t oldset; |
232 | int did_block_signals = 0; | 247 | int did_block_signals = 0; |
233 | struct posix_acl *default_acl = NULL, *acl = NULL; | 248 | struct posix_acl *default_acl = NULL, *acl = NULL; |
249 | struct ocfs2_dentry_lock *dl = NULL; | ||
234 | 250 | ||
235 | trace_ocfs2_mknod(dir, dentry, dentry->d_name.len, dentry->d_name.name, | 251 | trace_ocfs2_mknod(dir, dentry, dentry->d_name.len, dentry->d_name.name, |
236 | (unsigned long long)OCFS2_I(dir)->ip_blkno, | 252 | (unsigned long long)OCFS2_I(dir)->ip_blkno, |
@@ -423,6 +439,8 @@ static int ocfs2_mknod(struct inode *dir, | |||
423 | goto leave; | 439 | goto leave; |
424 | } | 440 | } |
425 | 441 | ||
442 | dl = dentry->d_fsdata; | ||
443 | |||
426 | status = ocfs2_add_entry(handle, dentry, inode, | 444 | status = ocfs2_add_entry(handle, dentry, inode, |
427 | OCFS2_I(inode)->ip_blkno, parent_fe_bh, | 445 | OCFS2_I(inode)->ip_blkno, parent_fe_bh, |
428 | &lookup); | 446 | &lookup); |
@@ -469,6 +487,9 @@ leave: | |||
469 | * ocfs2_delete_inode will mutex_lock again. | 487 | * ocfs2_delete_inode will mutex_lock again. |
470 | */ | 488 | */ |
471 | if ((status < 0) && inode) { | 489 | if ((status < 0) && inode) { |
490 | if (dl) | ||
491 | ocfs2_cleanup_add_entry_failure(osb, dentry, inode); | ||
492 | |||
472 | OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SKIP_ORPHAN_DIR; | 493 | OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SKIP_ORPHAN_DIR; |
473 | clear_nlink(inode); | 494 | clear_nlink(inode); |
474 | iput(inode); | 495 | iput(inode); |
@@ -991,6 +1012,65 @@ leave: | |||
991 | return status; | 1012 | return status; |
992 | } | 1013 | } |
993 | 1014 | ||
1015 | static int ocfs2_check_if_ancestor(struct ocfs2_super *osb, | ||
1016 | u64 src_inode_no, u64 dest_inode_no) | ||
1017 | { | ||
1018 | int ret = 0, i = 0; | ||
1019 | u64 parent_inode_no = 0; | ||
1020 | u64 child_inode_no = src_inode_no; | ||
1021 | struct inode *child_inode; | ||
1022 | |||
1023 | #define MAX_LOOKUP_TIMES 32 | ||
1024 | while (1) { | ||
1025 | child_inode = ocfs2_iget(osb, child_inode_no, 0, 0); | ||
1026 | if (IS_ERR(child_inode)) { | ||
1027 | ret = PTR_ERR(child_inode); | ||
1028 | break; | ||
1029 | } | ||
1030 | |||
1031 | ret = ocfs2_inode_lock(child_inode, NULL, 0); | ||
1032 | if (ret < 0) { | ||
1033 | iput(child_inode); | ||
1034 | if (ret != -ENOENT) | ||
1035 | mlog_errno(ret); | ||
1036 | break; | ||
1037 | } | ||
1038 | |||
1039 | ret = ocfs2_lookup_ino_from_name(child_inode, "..", 2, | ||
1040 | &parent_inode_no); | ||
1041 | ocfs2_inode_unlock(child_inode, 0); | ||
1042 | iput(child_inode); | ||
1043 | if (ret < 0) { | ||
1044 | ret = -ENOENT; | ||
1045 | break; | ||
1046 | } | ||
1047 | |||
1048 | if (parent_inode_no == dest_inode_no) { | ||
1049 | ret = 1; | ||
1050 | break; | ||
1051 | } | ||
1052 | |||
1053 | if (parent_inode_no == osb->root_inode->i_ino) { | ||
1054 | ret = 0; | ||
1055 | break; | ||
1056 | } | ||
1057 | |||
1058 | child_inode_no = parent_inode_no; | ||
1059 | |||
1060 | if (++i >= MAX_LOOKUP_TIMES) { | ||
1061 | mlog(ML_NOTICE, "max lookup times reached, filesystem " | ||
1062 | "may have nested directories, " | ||
1063 | "src inode: %llu, dest inode: %llu.\n", | ||
1064 | (unsigned long long)src_inode_no, | ||
1065 | (unsigned long long)dest_inode_no); | ||
1066 | ret = 0; | ||
1067 | break; | ||
1068 | } | ||
1069 | } | ||
1070 | |||
1071 | return ret; | ||
1072 | } | ||
1073 | |||
994 | /* | 1074 | /* |
995 | * The only place this should be used is rename! | 1075 | * The only place this should be used is rename! |
996 | * if they have the same id, then the 1st one is the only one locked. | 1076 | * if they have the same id, then the 1st one is the only one locked. |
@@ -1002,6 +1082,7 @@ static int ocfs2_double_lock(struct ocfs2_super *osb, | |||
1002 | struct inode *inode2) | 1082 | struct inode *inode2) |
1003 | { | 1083 | { |
1004 | int status; | 1084 | int status; |
1085 | int inode1_is_ancestor, inode2_is_ancestor; | ||
1005 | struct ocfs2_inode_info *oi1 = OCFS2_I(inode1); | 1086 | struct ocfs2_inode_info *oi1 = OCFS2_I(inode1); |
1006 | struct ocfs2_inode_info *oi2 = OCFS2_I(inode2); | 1087 | struct ocfs2_inode_info *oi2 = OCFS2_I(inode2); |
1007 | struct buffer_head **tmpbh; | 1088 | struct buffer_head **tmpbh; |
@@ -1015,9 +1096,26 @@ static int ocfs2_double_lock(struct ocfs2_super *osb, | |||
1015 | if (*bh2) | 1096 | if (*bh2) |
1016 | *bh2 = NULL; | 1097 | *bh2 = NULL; |
1017 | 1098 | ||
1018 | /* we always want to lock the one with the lower lockid first. */ | 1099 | /* we always want to lock the one with the lower lockid first. |
1100 | * and if they are nested, we lock ancestor first */ | ||
1019 | if (oi1->ip_blkno != oi2->ip_blkno) { | 1101 | if (oi1->ip_blkno != oi2->ip_blkno) { |
1020 | if (oi1->ip_blkno < oi2->ip_blkno) { | 1102 | inode1_is_ancestor = ocfs2_check_if_ancestor(osb, oi2->ip_blkno, |
1103 | oi1->ip_blkno); | ||
1104 | if (inode1_is_ancestor < 0) { | ||
1105 | status = inode1_is_ancestor; | ||
1106 | goto bail; | ||
1107 | } | ||
1108 | |||
1109 | inode2_is_ancestor = ocfs2_check_if_ancestor(osb, oi1->ip_blkno, | ||
1110 | oi2->ip_blkno); | ||
1111 | if (inode2_is_ancestor < 0) { | ||
1112 | status = inode2_is_ancestor; | ||
1113 | goto bail; | ||
1114 | } | ||
1115 | |||
1116 | if ((inode1_is_ancestor == 1) || | ||
1117 | (oi1->ip_blkno < oi2->ip_blkno && | ||
1118 | inode2_is_ancestor == 0)) { | ||
1021 | /* switch id1 and id2 around */ | 1119 | /* switch id1 and id2 around */ |
1022 | tmpbh = bh2; | 1120 | tmpbh = bh2; |
1023 | bh2 = bh1; | 1121 | bh2 = bh1; |
@@ -1098,6 +1196,7 @@ static int ocfs2_rename(struct inode *old_dir, | |||
1098 | struct ocfs2_dir_lookup_result old_entry_lookup = { NULL, }; | 1196 | struct ocfs2_dir_lookup_result old_entry_lookup = { NULL, }; |
1099 | struct ocfs2_dir_lookup_result orphan_insert = { NULL, }; | 1197 | struct ocfs2_dir_lookup_result orphan_insert = { NULL, }; |
1100 | struct ocfs2_dir_lookup_result target_insert = { NULL, }; | 1198 | struct ocfs2_dir_lookup_result target_insert = { NULL, }; |
1199 | bool should_add_orphan = false; | ||
1101 | 1200 | ||
1102 | /* At some point it might be nice to break this function up a | 1201 | /* At some point it might be nice to break this function up a |
1103 | * bit. */ | 1202 | * bit. */ |
@@ -1134,6 +1233,21 @@ static int ocfs2_rename(struct inode *old_dir, | |||
1134 | goto bail; | 1233 | goto bail; |
1135 | } | 1234 | } |
1136 | rename_lock = 1; | 1235 | rename_lock = 1; |
1236 | |||
1237 | /* here we cannot guarantee the inodes haven't just been | ||
1238 | * changed, so check if they are nested again */ | ||
1239 | status = ocfs2_check_if_ancestor(osb, new_dir->i_ino, | ||
1240 | old_inode->i_ino); | ||
1241 | if (status < 0) { | ||
1242 | mlog_errno(status); | ||
1243 | goto bail; | ||
1244 | } else if (status == 1) { | ||
1245 | status = -EPERM; | ||
1246 | trace_ocfs2_rename_not_permitted( | ||
1247 | (unsigned long long)old_inode->i_ino, | ||
1248 | (unsigned long long)new_dir->i_ino); | ||
1249 | goto bail; | ||
1250 | } | ||
1137 | } | 1251 | } |
1138 | 1252 | ||
1139 | /* if old and new are the same, this'll just do one lock. */ | 1253 | /* if old and new are the same, this'll just do one lock. */ |
@@ -1304,6 +1418,7 @@ static int ocfs2_rename(struct inode *old_dir, | |||
1304 | mlog_errno(status); | 1418 | mlog_errno(status); |
1305 | goto bail; | 1419 | goto bail; |
1306 | } | 1420 | } |
1421 | should_add_orphan = true; | ||
1307 | } | 1422 | } |
1308 | } else { | 1423 | } else { |
1309 | BUG_ON(new_dentry->d_parent->d_inode != new_dir); | 1424 | BUG_ON(new_dentry->d_parent->d_inode != new_dir); |
@@ -1348,17 +1463,6 @@ static int ocfs2_rename(struct inode *old_dir, | |||
1348 | goto bail; | 1463 | goto bail; |
1349 | } | 1464 | } |
1350 | 1465 | ||
1351 | if (S_ISDIR(new_inode->i_mode) || | ||
1352 | (ocfs2_read_links_count(newfe) == 1)) { | ||
1353 | status = ocfs2_orphan_add(osb, handle, new_inode, | ||
1354 | newfe_bh, orphan_name, | ||
1355 | &orphan_insert, orphan_dir); | ||
1356 | if (status < 0) { | ||
1357 | mlog_errno(status); | ||
1358 | goto bail; | ||
1359 | } | ||
1360 | } | ||
1361 | |||
1362 | /* change the dirent to point to the correct inode */ | 1466 | /* change the dirent to point to the correct inode */ |
1363 | status = ocfs2_update_entry(new_dir, handle, &target_lookup_res, | 1467 | status = ocfs2_update_entry(new_dir, handle, &target_lookup_res, |
1364 | old_inode); | 1468 | old_inode); |
@@ -1373,6 +1477,15 @@ static int ocfs2_rename(struct inode *old_dir, | |||
1373 | else | 1477 | else |
1374 | ocfs2_add_links_count(newfe, -1); | 1478 | ocfs2_add_links_count(newfe, -1); |
1375 | ocfs2_journal_dirty(handle, newfe_bh); | 1479 | ocfs2_journal_dirty(handle, newfe_bh); |
1480 | if (should_add_orphan) { | ||
1481 | status = ocfs2_orphan_add(osb, handle, new_inode, | ||
1482 | newfe_bh, orphan_name, | ||
1483 | &orphan_insert, orphan_dir); | ||
1484 | if (status < 0) { | ||
1485 | mlog_errno(status); | ||
1486 | goto bail; | ||
1487 | } | ||
1488 | } | ||
1376 | } else { | 1489 | } else { |
1377 | /* if the name was not found in new_dir, add it now */ | 1490 | /* if the name was not found in new_dir, add it now */ |
1378 | status = ocfs2_add_entry(handle, new_dentry, old_inode, | 1491 | status = ocfs2_add_entry(handle, new_dentry, old_inode, |
@@ -1642,6 +1755,7 @@ static int ocfs2_symlink(struct inode *dir, | |||
1642 | struct ocfs2_dir_lookup_result lookup = { NULL, }; | 1755 | struct ocfs2_dir_lookup_result lookup = { NULL, }; |
1643 | sigset_t oldset; | 1756 | sigset_t oldset; |
1644 | int did_block_signals = 0; | 1757 | int did_block_signals = 0; |
1758 | struct ocfs2_dentry_lock *dl = NULL; | ||
1645 | 1759 | ||
1646 | trace_ocfs2_symlink_begin(dir, dentry, symname, | 1760 | trace_ocfs2_symlink_begin(dir, dentry, symname, |
1647 | dentry->d_name.len, dentry->d_name.name); | 1761 | dentry->d_name.len, dentry->d_name.name); |
@@ -1830,6 +1944,8 @@ static int ocfs2_symlink(struct inode *dir, | |||
1830 | goto bail; | 1944 | goto bail; |
1831 | } | 1945 | } |
1832 | 1946 | ||
1947 | dl = dentry->d_fsdata; | ||
1948 | |||
1833 | status = ocfs2_add_entry(handle, dentry, inode, | 1949 | status = ocfs2_add_entry(handle, dentry, inode, |
1834 | le64_to_cpu(fe->i_blkno), parent_fe_bh, | 1950 | le64_to_cpu(fe->i_blkno), parent_fe_bh, |
1835 | &lookup); | 1951 | &lookup); |
@@ -1864,6 +1980,9 @@ bail: | |||
1864 | if (xattr_ac) | 1980 | if (xattr_ac) |
1865 | ocfs2_free_alloc_context(xattr_ac); | 1981 | ocfs2_free_alloc_context(xattr_ac); |
1866 | if ((status < 0) && inode) { | 1982 | if ((status < 0) && inode) { |
1983 | if (dl) | ||
1984 | ocfs2_cleanup_add_entry_failure(osb, dentry, inode); | ||
1985 | |||
1867 | OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SKIP_ORPHAN_DIR; | 1986 | OCFS2_I(inode)->ip_flags |= OCFS2_INODE_SKIP_ORPHAN_DIR; |
1868 | clear_nlink(inode); | 1987 | clear_nlink(inode); |
1869 | iput(inode); | 1988 | iput(inode); |
diff --git a/fs/ocfs2/ocfs2_trace.h b/fs/ocfs2/ocfs2_trace.h index 1b60c62aa9d6..6cb019b7c6a8 100644 --- a/fs/ocfs2/ocfs2_trace.h +++ b/fs/ocfs2/ocfs2_trace.h | |||
@@ -2292,6 +2292,8 @@ TRACE_EVENT(ocfs2_rename, | |||
2292 | __entry->new_len, __get_str(new_name)) | 2292 | __entry->new_len, __get_str(new_name)) |
2293 | ); | 2293 | ); |
2294 | 2294 | ||
2295 | DEFINE_OCFS2_ULL_ULL_EVENT(ocfs2_rename_not_permitted); | ||
2296 | |||
2295 | TRACE_EVENT(ocfs2_rename_target_exists, | 2297 | TRACE_EVENT(ocfs2_rename_target_exists, |
2296 | TP_PROTO(int new_len, const char *new_name), | 2298 | TP_PROTO(int new_len, const char *new_name), |
2297 | TP_ARGS(new_len, new_name), | 2299 | TP_ARGS(new_len, new_name), |
diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c index 714e53b9cc66..636aab69ead5 100644 --- a/fs/ocfs2/refcounttree.c +++ b/fs/ocfs2/refcounttree.c | |||
@@ -4288,9 +4288,16 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir, | |||
4288 | goto out; | 4288 | goto out; |
4289 | } | 4289 | } |
4290 | 4290 | ||
4291 | error = ocfs2_rw_lock(inode, 1); | ||
4292 | if (error) { | ||
4293 | mlog_errno(error); | ||
4294 | goto out; | ||
4295 | } | ||
4296 | |||
4291 | error = ocfs2_inode_lock(inode, &old_bh, 1); | 4297 | error = ocfs2_inode_lock(inode, &old_bh, 1); |
4292 | if (error) { | 4298 | if (error) { |
4293 | mlog_errno(error); | 4299 | mlog_errno(error); |
4300 | ocfs2_rw_unlock(inode, 1); | ||
4294 | goto out; | 4301 | goto out; |
4295 | } | 4302 | } |
4296 | 4303 | ||
@@ -4302,6 +4309,7 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir, | |||
4302 | up_write(&OCFS2_I(inode)->ip_xattr_sem); | 4309 | up_write(&OCFS2_I(inode)->ip_xattr_sem); |
4303 | 4310 | ||
4304 | ocfs2_inode_unlock(inode, 1); | 4311 | ocfs2_inode_unlock(inode, 1); |
4312 | ocfs2_rw_unlock(inode, 1); | ||
4305 | brelse(old_bh); | 4313 | brelse(old_bh); |
4306 | 4314 | ||
4307 | if (error) { | 4315 | if (error) { |
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index c7a89cea5c5d..ddb662b32447 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c | |||
@@ -1925,15 +1925,11 @@ static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err) | |||
1925 | 1925 | ||
1926 | ocfs2_shutdown_local_alloc(osb); | 1926 | ocfs2_shutdown_local_alloc(osb); |
1927 | 1927 | ||
1928 | ocfs2_truncate_log_shutdown(osb); | ||
1929 | |||
1928 | /* This will disable recovery and flush any recovery work. */ | 1930 | /* This will disable recovery and flush any recovery work. */ |
1929 | ocfs2_recovery_exit(osb); | 1931 | ocfs2_recovery_exit(osb); |
1930 | 1932 | ||
1931 | /* | ||
1932 | * During dismount, when it recovers another node it will call | ||
1933 | * ocfs2_recover_orphans and queue delayed work osb_truncate_log_wq. | ||
1934 | */ | ||
1935 | ocfs2_truncate_log_shutdown(osb); | ||
1936 | |||
1937 | ocfs2_journal_shutdown(osb); | 1933 | ocfs2_journal_shutdown(osb); |
1938 | 1934 | ||
1939 | ocfs2_sync_blockdev(sb); | 1935 | ocfs2_sync_blockdev(sb); |
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 | ||
185 | static int stat_open(struct inode *inode, struct file *file) | 185 | static 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 | ||
212 | static const struct file_operations proc_stat_operations = { | 194 | static 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 | ||
35 | static 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 | ||
136 | Eoverflow: | 148 | Eoverflow: |
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); | |||
350 | int seq_release(struct inode *inode, struct file *file) | 362 | int 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); | |||
605 | int single_open_size(struct file *file, int (*show)(struct seq_file *, void *), | 617 | int 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; |