diff options
Diffstat (limited to 'fs')
93 files changed, 1199 insertions, 944 deletions
@@ -793,6 +793,8 @@ void exit_aio(struct mm_struct *mm) | |||
793 | 793 | ||
794 | for (i = 0; i < table->nr; ++i) { | 794 | for (i = 0; i < table->nr; ++i) { |
795 | struct kioctx *ctx = table->table[i]; | 795 | struct kioctx *ctx = table->table[i]; |
796 | struct completion requests_done = | ||
797 | COMPLETION_INITIALIZER_ONSTACK(requests_done); | ||
796 | 798 | ||
797 | if (!ctx) | 799 | if (!ctx) |
798 | continue; | 800 | continue; |
@@ -804,7 +806,10 @@ void exit_aio(struct mm_struct *mm) | |||
804 | * that it needs to unmap the area, just set it to 0. | 806 | * that it needs to unmap the area, just set it to 0. |
805 | */ | 807 | */ |
806 | ctx->mmap_size = 0; | 808 | ctx->mmap_size = 0; |
807 | kill_ioctx(mm, ctx, NULL); | 809 | kill_ioctx(mm, ctx, &requests_done); |
810 | |||
811 | /* Wait until all IO for the context are done. */ | ||
812 | wait_for_completion(&requests_done); | ||
808 | } | 813 | } |
809 | 814 | ||
810 | RCU_INIT_POINTER(mm->ioctx_table, NULL); | 815 | RCU_INIT_POINTER(mm->ioctx_table, NULL); |
@@ -1111,6 +1116,12 @@ static long aio_read_events_ring(struct kioctx *ctx, | |||
1111 | tail = ring->tail; | 1116 | tail = ring->tail; |
1112 | kunmap_atomic(ring); | 1117 | kunmap_atomic(ring); |
1113 | 1118 | ||
1119 | /* | ||
1120 | * Ensure that once we've read the current tail pointer, that | ||
1121 | * we also see the events that were stored up to the tail. | ||
1122 | */ | ||
1123 | smp_rmb(); | ||
1124 | |||
1114 | pr_debug("h%u t%u m%u\n", head, tail, ctx->nr_events); | 1125 | pr_debug("h%u t%u m%u\n", head, tail, ctx->nr_events); |
1115 | 1126 | ||
1116 | if (head == tail) | 1127 | if (head == tail) |
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 43527fd78825..56b8522d5767 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -234,8 +234,17 @@ static inline int btrfs_inode_in_log(struct inode *inode, u64 generation) | |||
234 | BTRFS_I(inode)->last_sub_trans <= | 234 | BTRFS_I(inode)->last_sub_trans <= |
235 | BTRFS_I(inode)->last_log_commit && | 235 | BTRFS_I(inode)->last_log_commit && |
236 | BTRFS_I(inode)->last_sub_trans <= | 236 | BTRFS_I(inode)->last_sub_trans <= |
237 | BTRFS_I(inode)->root->last_log_commit) | 237 | BTRFS_I(inode)->root->last_log_commit) { |
238 | return 1; | 238 | /* |
239 | * After a ranged fsync we might have left some extent maps | ||
240 | * (that fall outside the fsync's range). So return false | ||
241 | * here if the list isn't empty, to make sure btrfs_log_inode() | ||
242 | * will be called and process those extent maps. | ||
243 | */ | ||
244 | smp_mb(); | ||
245 | if (list_empty(&BTRFS_I(inode)->extent_tree.modified_extents)) | ||
246 | return 1; | ||
247 | } | ||
239 | return 0; | 248 | return 0; |
240 | } | 249 | } |
241 | 250 | ||
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 36861b7a6757..ff1cc0399b9a 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c | |||
@@ -1966,7 +1966,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
1966 | 1966 | ||
1967 | btrfs_init_log_ctx(&ctx); | 1967 | btrfs_init_log_ctx(&ctx); |
1968 | 1968 | ||
1969 | ret = btrfs_log_dentry_safe(trans, root, dentry, &ctx); | 1969 | ret = btrfs_log_dentry_safe(trans, root, dentry, start, end, &ctx); |
1970 | if (ret < 0) { | 1970 | if (ret < 0) { |
1971 | /* Fallthrough and commit/free transaction. */ | 1971 | /* Fallthrough and commit/free transaction. */ |
1972 | ret = 1; | 1972 | ret = 1; |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9c194bd74d6e..016c403bfe7e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -778,8 +778,12 @@ retry: | |||
778 | ins.offset, | 778 | ins.offset, |
779 | BTRFS_ORDERED_COMPRESSED, | 779 | BTRFS_ORDERED_COMPRESSED, |
780 | async_extent->compress_type); | 780 | async_extent->compress_type); |
781 | if (ret) | 781 | if (ret) { |
782 | btrfs_drop_extent_cache(inode, async_extent->start, | ||
783 | async_extent->start + | ||
784 | async_extent->ram_size - 1, 0); | ||
782 | goto out_free_reserve; | 785 | goto out_free_reserve; |
786 | } | ||
783 | 787 | ||
784 | /* | 788 | /* |
785 | * clear dirty, set writeback and unlock the pages. | 789 | * clear dirty, set writeback and unlock the pages. |
@@ -971,14 +975,14 @@ static noinline int cow_file_range(struct inode *inode, | |||
971 | ret = btrfs_add_ordered_extent(inode, start, ins.objectid, | 975 | ret = btrfs_add_ordered_extent(inode, start, ins.objectid, |
972 | ram_size, cur_alloc_size, 0); | 976 | ram_size, cur_alloc_size, 0); |
973 | if (ret) | 977 | if (ret) |
974 | goto out_reserve; | 978 | goto out_drop_extent_cache; |
975 | 979 | ||
976 | if (root->root_key.objectid == | 980 | if (root->root_key.objectid == |
977 | BTRFS_DATA_RELOC_TREE_OBJECTID) { | 981 | BTRFS_DATA_RELOC_TREE_OBJECTID) { |
978 | ret = btrfs_reloc_clone_csums(inode, start, | 982 | ret = btrfs_reloc_clone_csums(inode, start, |
979 | cur_alloc_size); | 983 | cur_alloc_size); |
980 | if (ret) | 984 | if (ret) |
981 | goto out_reserve; | 985 | goto out_drop_extent_cache; |
982 | } | 986 | } |
983 | 987 | ||
984 | if (disk_num_bytes < cur_alloc_size) | 988 | if (disk_num_bytes < cur_alloc_size) |
@@ -1006,6 +1010,8 @@ static noinline int cow_file_range(struct inode *inode, | |||
1006 | out: | 1010 | out: |
1007 | return ret; | 1011 | return ret; |
1008 | 1012 | ||
1013 | out_drop_extent_cache: | ||
1014 | btrfs_drop_extent_cache(inode, start, start + ram_size - 1, 0); | ||
1009 | out_reserve: | 1015 | out_reserve: |
1010 | btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1); | 1016 | btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1); |
1011 | out_unlock: | 1017 | out_unlock: |
@@ -4242,7 +4248,8 @@ out: | |||
4242 | btrfs_abort_transaction(trans, root, ret); | 4248 | btrfs_abort_transaction(trans, root, ret); |
4243 | } | 4249 | } |
4244 | error: | 4250 | error: |
4245 | if (last_size != (u64)-1) | 4251 | if (last_size != (u64)-1 && |
4252 | root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID) | ||
4246 | btrfs_ordered_update_i_size(inode, last_size, NULL); | 4253 | btrfs_ordered_update_i_size(inode, last_size, NULL); |
4247 | btrfs_free_path(path); | 4254 | btrfs_free_path(path); |
4248 | return err; | 4255 | return err; |
@@ -5627,6 +5634,17 @@ int btrfs_set_inode_index(struct inode *dir, u64 *index) | |||
5627 | return ret; | 5634 | return ret; |
5628 | } | 5635 | } |
5629 | 5636 | ||
5637 | static int btrfs_insert_inode_locked(struct inode *inode) | ||
5638 | { | ||
5639 | struct btrfs_iget_args args; | ||
5640 | args.location = &BTRFS_I(inode)->location; | ||
5641 | args.root = BTRFS_I(inode)->root; | ||
5642 | |||
5643 | return insert_inode_locked4(inode, | ||
5644 | btrfs_inode_hash(inode->i_ino, BTRFS_I(inode)->root), | ||
5645 | btrfs_find_actor, &args); | ||
5646 | } | ||
5647 | |||
5630 | static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | 5648 | static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, |
5631 | struct btrfs_root *root, | 5649 | struct btrfs_root *root, |
5632 | struct inode *dir, | 5650 | struct inode *dir, |
@@ -5719,10 +5737,19 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
5719 | sizes[1] = name_len + sizeof(*ref); | 5737 | sizes[1] = name_len + sizeof(*ref); |
5720 | } | 5738 | } |
5721 | 5739 | ||
5740 | location = &BTRFS_I(inode)->location; | ||
5741 | location->objectid = objectid; | ||
5742 | location->offset = 0; | ||
5743 | btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY); | ||
5744 | |||
5745 | ret = btrfs_insert_inode_locked(inode); | ||
5746 | if (ret < 0) | ||
5747 | goto fail; | ||
5748 | |||
5722 | path->leave_spinning = 1; | 5749 | path->leave_spinning = 1; |
5723 | ret = btrfs_insert_empty_items(trans, root, path, key, sizes, nitems); | 5750 | ret = btrfs_insert_empty_items(trans, root, path, key, sizes, nitems); |
5724 | if (ret != 0) | 5751 | if (ret != 0) |
5725 | goto fail; | 5752 | goto fail_unlock; |
5726 | 5753 | ||
5727 | inode_init_owner(inode, dir, mode); | 5754 | inode_init_owner(inode, dir, mode); |
5728 | inode_set_bytes(inode, 0); | 5755 | inode_set_bytes(inode, 0); |
@@ -5745,11 +5772,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
5745 | btrfs_mark_buffer_dirty(path->nodes[0]); | 5772 | btrfs_mark_buffer_dirty(path->nodes[0]); |
5746 | btrfs_free_path(path); | 5773 | btrfs_free_path(path); |
5747 | 5774 | ||
5748 | location = &BTRFS_I(inode)->location; | ||
5749 | location->objectid = objectid; | ||
5750 | location->offset = 0; | ||
5751 | btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY); | ||
5752 | |||
5753 | btrfs_inherit_iflags(inode, dir); | 5775 | btrfs_inherit_iflags(inode, dir); |
5754 | 5776 | ||
5755 | if (S_ISREG(mode)) { | 5777 | if (S_ISREG(mode)) { |
@@ -5760,7 +5782,6 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
5760 | BTRFS_INODE_NODATASUM; | 5782 | BTRFS_INODE_NODATASUM; |
5761 | } | 5783 | } |
5762 | 5784 | ||
5763 | btrfs_insert_inode_hash(inode); | ||
5764 | inode_tree_add(inode); | 5785 | inode_tree_add(inode); |
5765 | 5786 | ||
5766 | trace_btrfs_inode_new(inode); | 5787 | trace_btrfs_inode_new(inode); |
@@ -5775,6 +5796,9 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | |||
5775 | btrfs_ino(inode), root->root_key.objectid, ret); | 5796 | btrfs_ino(inode), root->root_key.objectid, ret); |
5776 | 5797 | ||
5777 | return inode; | 5798 | return inode; |
5799 | |||
5800 | fail_unlock: | ||
5801 | unlock_new_inode(inode); | ||
5778 | fail: | 5802 | fail: |
5779 | if (dir && name) | 5803 | if (dir && name) |
5780 | BTRFS_I(dir)->index_cnt--; | 5804 | BTRFS_I(dir)->index_cnt--; |
@@ -5909,28 +5933,28 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, | |||
5909 | goto out_unlock; | 5933 | goto out_unlock; |
5910 | } | 5934 | } |
5911 | 5935 | ||
5912 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); | ||
5913 | if (err) { | ||
5914 | drop_inode = 1; | ||
5915 | goto out_unlock; | ||
5916 | } | ||
5917 | |||
5918 | /* | 5936 | /* |
5919 | * If the active LSM wants to access the inode during | 5937 | * If the active LSM wants to access the inode during |
5920 | * d_instantiate it needs these. Smack checks to see | 5938 | * d_instantiate it needs these. Smack checks to see |
5921 | * if the filesystem supports xattrs by looking at the | 5939 | * if the filesystem supports xattrs by looking at the |
5922 | * ops vector. | 5940 | * ops vector. |
5923 | */ | 5941 | */ |
5924 | |||
5925 | inode->i_op = &btrfs_special_inode_operations; | 5942 | inode->i_op = &btrfs_special_inode_operations; |
5926 | err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); | 5943 | init_special_inode(inode, inode->i_mode, rdev); |
5944 | |||
5945 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); | ||
5927 | if (err) | 5946 | if (err) |
5928 | drop_inode = 1; | 5947 | goto out_unlock_inode; |
5929 | else { | 5948 | |
5930 | init_special_inode(inode, inode->i_mode, rdev); | 5949 | err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); |
5950 | if (err) { | ||
5951 | goto out_unlock_inode; | ||
5952 | } else { | ||
5931 | btrfs_update_inode(trans, root, inode); | 5953 | btrfs_update_inode(trans, root, inode); |
5954 | unlock_new_inode(inode); | ||
5932 | d_instantiate(dentry, inode); | 5955 | d_instantiate(dentry, inode); |
5933 | } | 5956 | } |
5957 | |||
5934 | out_unlock: | 5958 | out_unlock: |
5935 | btrfs_end_transaction(trans, root); | 5959 | btrfs_end_transaction(trans, root); |
5936 | btrfs_balance_delayed_items(root); | 5960 | btrfs_balance_delayed_items(root); |
@@ -5940,6 +5964,12 @@ out_unlock: | |||
5940 | iput(inode); | 5964 | iput(inode); |
5941 | } | 5965 | } |
5942 | return err; | 5966 | return err; |
5967 | |||
5968 | out_unlock_inode: | ||
5969 | drop_inode = 1; | ||
5970 | unlock_new_inode(inode); | ||
5971 | goto out_unlock; | ||
5972 | |||
5943 | } | 5973 | } |
5944 | 5974 | ||
5945 | static int btrfs_create(struct inode *dir, struct dentry *dentry, | 5975 | static int btrfs_create(struct inode *dir, struct dentry *dentry, |
@@ -5974,15 +6004,6 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
5974 | goto out_unlock; | 6004 | goto out_unlock; |
5975 | } | 6005 | } |
5976 | drop_inode_on_err = 1; | 6006 | drop_inode_on_err = 1; |
5977 | |||
5978 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); | ||
5979 | if (err) | ||
5980 | goto out_unlock; | ||
5981 | |||
5982 | err = btrfs_update_inode(trans, root, inode); | ||
5983 | if (err) | ||
5984 | goto out_unlock; | ||
5985 | |||
5986 | /* | 6007 | /* |
5987 | * If the active LSM wants to access the inode during | 6008 | * If the active LSM wants to access the inode during |
5988 | * d_instantiate it needs these. Smack checks to see | 6009 | * d_instantiate it needs these. Smack checks to see |
@@ -5991,14 +6012,23 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
5991 | */ | 6012 | */ |
5992 | inode->i_fop = &btrfs_file_operations; | 6013 | inode->i_fop = &btrfs_file_operations; |
5993 | inode->i_op = &btrfs_file_inode_operations; | 6014 | inode->i_op = &btrfs_file_inode_operations; |
6015 | inode->i_mapping->a_ops = &btrfs_aops; | ||
6016 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; | ||
6017 | |||
6018 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); | ||
6019 | if (err) | ||
6020 | goto out_unlock_inode; | ||
6021 | |||
6022 | err = btrfs_update_inode(trans, root, inode); | ||
6023 | if (err) | ||
6024 | goto out_unlock_inode; | ||
5994 | 6025 | ||
5995 | err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); | 6026 | err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); |
5996 | if (err) | 6027 | if (err) |
5997 | goto out_unlock; | 6028 | goto out_unlock_inode; |
5998 | 6029 | ||
5999 | inode->i_mapping->a_ops = &btrfs_aops; | ||
6000 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; | ||
6001 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; | 6030 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; |
6031 | unlock_new_inode(inode); | ||
6002 | d_instantiate(dentry, inode); | 6032 | d_instantiate(dentry, inode); |
6003 | 6033 | ||
6004 | out_unlock: | 6034 | out_unlock: |
@@ -6010,6 +6040,11 @@ out_unlock: | |||
6010 | btrfs_balance_delayed_items(root); | 6040 | btrfs_balance_delayed_items(root); |
6011 | btrfs_btree_balance_dirty(root); | 6041 | btrfs_btree_balance_dirty(root); |
6012 | return err; | 6042 | return err; |
6043 | |||
6044 | out_unlock_inode: | ||
6045 | unlock_new_inode(inode); | ||
6046 | goto out_unlock; | ||
6047 | |||
6013 | } | 6048 | } |
6014 | 6049 | ||
6015 | static int btrfs_link(struct dentry *old_dentry, struct inode *dir, | 6050 | static int btrfs_link(struct dentry *old_dentry, struct inode *dir, |
@@ -6117,25 +6152,30 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
6117 | } | 6152 | } |
6118 | 6153 | ||
6119 | drop_on_err = 1; | 6154 | drop_on_err = 1; |
6155 | /* these must be set before we unlock the inode */ | ||
6156 | inode->i_op = &btrfs_dir_inode_operations; | ||
6157 | inode->i_fop = &btrfs_dir_file_operations; | ||
6120 | 6158 | ||
6121 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); | 6159 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); |
6122 | if (err) | 6160 | if (err) |
6123 | goto out_fail; | 6161 | goto out_fail_inode; |
6124 | |||
6125 | inode->i_op = &btrfs_dir_inode_operations; | ||
6126 | inode->i_fop = &btrfs_dir_file_operations; | ||
6127 | 6162 | ||
6128 | btrfs_i_size_write(inode, 0); | 6163 | btrfs_i_size_write(inode, 0); |
6129 | err = btrfs_update_inode(trans, root, inode); | 6164 | err = btrfs_update_inode(trans, root, inode); |
6130 | if (err) | 6165 | if (err) |
6131 | goto out_fail; | 6166 | goto out_fail_inode; |
6132 | 6167 | ||
6133 | err = btrfs_add_link(trans, dir, inode, dentry->d_name.name, | 6168 | err = btrfs_add_link(trans, dir, inode, dentry->d_name.name, |
6134 | dentry->d_name.len, 0, index); | 6169 | dentry->d_name.len, 0, index); |
6135 | if (err) | 6170 | if (err) |
6136 | goto out_fail; | 6171 | goto out_fail_inode; |
6137 | 6172 | ||
6138 | d_instantiate(dentry, inode); | 6173 | d_instantiate(dentry, inode); |
6174 | /* | ||
6175 | * mkdir is special. We're unlocking after we call d_instantiate | ||
6176 | * to avoid a race with nfsd calling d_instantiate. | ||
6177 | */ | ||
6178 | unlock_new_inode(inode); | ||
6139 | drop_on_err = 0; | 6179 | drop_on_err = 0; |
6140 | 6180 | ||
6141 | out_fail: | 6181 | out_fail: |
@@ -6145,6 +6185,10 @@ out_fail: | |||
6145 | btrfs_balance_delayed_items(root); | 6185 | btrfs_balance_delayed_items(root); |
6146 | btrfs_btree_balance_dirty(root); | 6186 | btrfs_btree_balance_dirty(root); |
6147 | return err; | 6187 | return err; |
6188 | |||
6189 | out_fail_inode: | ||
6190 | unlock_new_inode(inode); | ||
6191 | goto out_fail; | ||
6148 | } | 6192 | } |
6149 | 6193 | ||
6150 | /* helper for btfs_get_extent. Given an existing extent in the tree, | 6194 | /* helper for btfs_get_extent. Given an existing extent in the tree, |
@@ -8100,6 +8144,7 @@ int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, | |||
8100 | 8144 | ||
8101 | set_nlink(inode, 1); | 8145 | set_nlink(inode, 1); |
8102 | btrfs_i_size_write(inode, 0); | 8146 | btrfs_i_size_write(inode, 0); |
8147 | unlock_new_inode(inode); | ||
8103 | 8148 | ||
8104 | err = btrfs_subvol_inherit_props(trans, new_root, parent_root); | 8149 | err = btrfs_subvol_inherit_props(trans, new_root, parent_root); |
8105 | if (err) | 8150 | if (err) |
@@ -8760,12 +8805,6 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
8760 | goto out_unlock; | 8805 | goto out_unlock; |
8761 | } | 8806 | } |
8762 | 8807 | ||
8763 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); | ||
8764 | if (err) { | ||
8765 | drop_inode = 1; | ||
8766 | goto out_unlock; | ||
8767 | } | ||
8768 | |||
8769 | /* | 8808 | /* |
8770 | * If the active LSM wants to access the inode during | 8809 | * If the active LSM wants to access the inode during |
8771 | * d_instantiate it needs these. Smack checks to see | 8810 | * d_instantiate it needs these. Smack checks to see |
@@ -8774,23 +8813,22 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
8774 | */ | 8813 | */ |
8775 | inode->i_fop = &btrfs_file_operations; | 8814 | inode->i_fop = &btrfs_file_operations; |
8776 | inode->i_op = &btrfs_file_inode_operations; | 8815 | inode->i_op = &btrfs_file_inode_operations; |
8816 | inode->i_mapping->a_ops = &btrfs_aops; | ||
8817 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; | ||
8818 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; | ||
8819 | |||
8820 | err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); | ||
8821 | if (err) | ||
8822 | goto out_unlock_inode; | ||
8777 | 8823 | ||
8778 | err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); | 8824 | err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); |
8779 | if (err) | 8825 | if (err) |
8780 | drop_inode = 1; | 8826 | goto out_unlock_inode; |
8781 | else { | ||
8782 | inode->i_mapping->a_ops = &btrfs_aops; | ||
8783 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; | ||
8784 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; | ||
8785 | } | ||
8786 | if (drop_inode) | ||
8787 | goto out_unlock; | ||
8788 | 8827 | ||
8789 | path = btrfs_alloc_path(); | 8828 | path = btrfs_alloc_path(); |
8790 | if (!path) { | 8829 | if (!path) { |
8791 | err = -ENOMEM; | 8830 | err = -ENOMEM; |
8792 | drop_inode = 1; | 8831 | goto out_unlock_inode; |
8793 | goto out_unlock; | ||
8794 | } | 8832 | } |
8795 | key.objectid = btrfs_ino(inode); | 8833 | key.objectid = btrfs_ino(inode); |
8796 | key.offset = 0; | 8834 | key.offset = 0; |
@@ -8799,9 +8837,8 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
8799 | err = btrfs_insert_empty_item(trans, root, path, &key, | 8837 | err = btrfs_insert_empty_item(trans, root, path, &key, |
8800 | datasize); | 8838 | datasize); |
8801 | if (err) { | 8839 | if (err) { |
8802 | drop_inode = 1; | ||
8803 | btrfs_free_path(path); | 8840 | btrfs_free_path(path); |
8804 | goto out_unlock; | 8841 | goto out_unlock_inode; |
8805 | } | 8842 | } |
8806 | leaf = path->nodes[0]; | 8843 | leaf = path->nodes[0]; |
8807 | ei = btrfs_item_ptr(leaf, path->slots[0], | 8844 | ei = btrfs_item_ptr(leaf, path->slots[0], |
@@ -8825,12 +8862,15 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
8825 | inode_set_bytes(inode, name_len); | 8862 | inode_set_bytes(inode, name_len); |
8826 | btrfs_i_size_write(inode, name_len); | 8863 | btrfs_i_size_write(inode, name_len); |
8827 | err = btrfs_update_inode(trans, root, inode); | 8864 | err = btrfs_update_inode(trans, root, inode); |
8828 | if (err) | 8865 | if (err) { |
8829 | drop_inode = 1; | 8866 | drop_inode = 1; |
8867 | goto out_unlock_inode; | ||
8868 | } | ||
8869 | |||
8870 | unlock_new_inode(inode); | ||
8871 | d_instantiate(dentry, inode); | ||
8830 | 8872 | ||
8831 | out_unlock: | 8873 | out_unlock: |
8832 | if (!err) | ||
8833 | d_instantiate(dentry, inode); | ||
8834 | btrfs_end_transaction(trans, root); | 8874 | btrfs_end_transaction(trans, root); |
8835 | if (drop_inode) { | 8875 | if (drop_inode) { |
8836 | inode_dec_link_count(inode); | 8876 | inode_dec_link_count(inode); |
@@ -8838,6 +8878,11 @@ out_unlock: | |||
8838 | } | 8878 | } |
8839 | btrfs_btree_balance_dirty(root); | 8879 | btrfs_btree_balance_dirty(root); |
8840 | return err; | 8880 | return err; |
8881 | |||
8882 | out_unlock_inode: | ||
8883 | drop_inode = 1; | ||
8884 | unlock_new_inode(inode); | ||
8885 | goto out_unlock; | ||
8841 | } | 8886 | } |
8842 | 8887 | ||
8843 | static int __btrfs_prealloc_file_range(struct inode *inode, int mode, | 8888 | static int __btrfs_prealloc_file_range(struct inode *inode, int mode, |
@@ -9021,14 +9066,6 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
9021 | goto out; | 9066 | goto out; |
9022 | } | 9067 | } |
9023 | 9068 | ||
9024 | ret = btrfs_init_inode_security(trans, inode, dir, NULL); | ||
9025 | if (ret) | ||
9026 | goto out; | ||
9027 | |||
9028 | ret = btrfs_update_inode(trans, root, inode); | ||
9029 | if (ret) | ||
9030 | goto out; | ||
9031 | |||
9032 | inode->i_fop = &btrfs_file_operations; | 9069 | inode->i_fop = &btrfs_file_operations; |
9033 | inode->i_op = &btrfs_file_inode_operations; | 9070 | inode->i_op = &btrfs_file_inode_operations; |
9034 | 9071 | ||
@@ -9036,9 +9073,16 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
9036 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; | 9073 | inode->i_mapping->backing_dev_info = &root->fs_info->bdi; |
9037 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; | 9074 | BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; |
9038 | 9075 | ||
9076 | ret = btrfs_init_inode_security(trans, inode, dir, NULL); | ||
9077 | if (ret) | ||
9078 | goto out_inode; | ||
9079 | |||
9080 | ret = btrfs_update_inode(trans, root, inode); | ||
9081 | if (ret) | ||
9082 | goto out_inode; | ||
9039 | ret = btrfs_orphan_add(trans, inode); | 9083 | ret = btrfs_orphan_add(trans, inode); |
9040 | if (ret) | 9084 | if (ret) |
9041 | goto out; | 9085 | goto out_inode; |
9042 | 9086 | ||
9043 | /* | 9087 | /* |
9044 | * We set number of links to 0 in btrfs_new_inode(), and here we set | 9088 | * We set number of links to 0 in btrfs_new_inode(), and here we set |
@@ -9048,6 +9092,7 @@ static int btrfs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
9048 | * d_tmpfile() -> inode_dec_link_count() -> drop_nlink() | 9092 | * d_tmpfile() -> inode_dec_link_count() -> drop_nlink() |
9049 | */ | 9093 | */ |
9050 | set_nlink(inode, 1); | 9094 | set_nlink(inode, 1); |
9095 | unlock_new_inode(inode); | ||
9051 | d_tmpfile(dentry, inode); | 9096 | d_tmpfile(dentry, inode); |
9052 | mark_inode_dirty(inode); | 9097 | mark_inode_dirty(inode); |
9053 | 9098 | ||
@@ -9057,8 +9102,12 @@ out: | |||
9057 | iput(inode); | 9102 | iput(inode); |
9058 | btrfs_balance_delayed_items(root); | 9103 | btrfs_balance_delayed_items(root); |
9059 | btrfs_btree_balance_dirty(root); | 9104 | btrfs_btree_balance_dirty(root); |
9060 | |||
9061 | return ret; | 9105 | return ret; |
9106 | |||
9107 | out_inode: | ||
9108 | unlock_new_inode(inode); | ||
9109 | goto out; | ||
9110 | |||
9062 | } | 9111 | } |
9063 | 9112 | ||
9064 | static const struct inode_operations btrfs_dir_inode_operations = { | 9113 | static const struct inode_operations btrfs_dir_inode_operations = { |
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index fce6fd0e3f50..8a8e29878c34 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -1019,8 +1019,10 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em) | |||
1019 | return false; | 1019 | return false; |
1020 | 1020 | ||
1021 | next = defrag_lookup_extent(inode, em->start + em->len); | 1021 | next = defrag_lookup_extent(inode, em->start + em->len); |
1022 | if (!next || next->block_start >= EXTENT_MAP_LAST_BYTE || | 1022 | if (!next || next->block_start >= EXTENT_MAP_LAST_BYTE) |
1023 | (em->block_start + em->block_len == next->block_start)) | 1023 | ret = false; |
1024 | else if ((em->block_start + em->block_len == next->block_start) && | ||
1025 | (em->block_len > 128 * 1024 && next->block_len > 128 * 1024)) | ||
1024 | ret = false; | 1026 | ret = false; |
1025 | 1027 | ||
1026 | free_extent_map(next); | 1028 | free_extent_map(next); |
@@ -1055,7 +1057,6 @@ static int should_defrag_range(struct inode *inode, u64 start, int thresh, | |||
1055 | } | 1057 | } |
1056 | 1058 | ||
1057 | next_mergeable = defrag_check_next_extent(inode, em); | 1059 | next_mergeable = defrag_check_next_extent(inode, em); |
1058 | |||
1059 | /* | 1060 | /* |
1060 | * we hit a real extent, if it is big or the next extent is not a | 1061 | * we hit a real extent, if it is big or the next extent is not a |
1061 | * real extent, don't bother defragging it | 1062 | * real extent, don't bother defragging it |
@@ -1702,7 +1703,7 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file, | |||
1702 | ~(BTRFS_SUBVOL_CREATE_ASYNC | BTRFS_SUBVOL_RDONLY | | 1703 | ~(BTRFS_SUBVOL_CREATE_ASYNC | BTRFS_SUBVOL_RDONLY | |
1703 | BTRFS_SUBVOL_QGROUP_INHERIT)) { | 1704 | BTRFS_SUBVOL_QGROUP_INHERIT)) { |
1704 | ret = -EOPNOTSUPP; | 1705 | ret = -EOPNOTSUPP; |
1705 | goto out; | 1706 | goto free_args; |
1706 | } | 1707 | } |
1707 | 1708 | ||
1708 | if (vol_args->flags & BTRFS_SUBVOL_CREATE_ASYNC) | 1709 | if (vol_args->flags & BTRFS_SUBVOL_CREATE_ASYNC) |
@@ -1712,27 +1713,31 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file, | |||
1712 | if (vol_args->flags & BTRFS_SUBVOL_QGROUP_INHERIT) { | 1713 | if (vol_args->flags & BTRFS_SUBVOL_QGROUP_INHERIT) { |
1713 | if (vol_args->size > PAGE_CACHE_SIZE) { | 1714 | if (vol_args->size > PAGE_CACHE_SIZE) { |
1714 | ret = -EINVAL; | 1715 | ret = -EINVAL; |
1715 | goto out; | 1716 | goto free_args; |
1716 | } | 1717 | } |
1717 | inherit = memdup_user(vol_args->qgroup_inherit, vol_args->size); | 1718 | inherit = memdup_user(vol_args->qgroup_inherit, vol_args->size); |
1718 | if (IS_ERR(inherit)) { | 1719 | if (IS_ERR(inherit)) { |
1719 | ret = PTR_ERR(inherit); | 1720 | ret = PTR_ERR(inherit); |
1720 | goto out; | 1721 | goto free_args; |
1721 | } | 1722 | } |
1722 | } | 1723 | } |
1723 | 1724 | ||
1724 | ret = btrfs_ioctl_snap_create_transid(file, vol_args->name, | 1725 | ret = btrfs_ioctl_snap_create_transid(file, vol_args->name, |
1725 | vol_args->fd, subvol, ptr, | 1726 | vol_args->fd, subvol, ptr, |
1726 | readonly, inherit); | 1727 | readonly, inherit); |
1728 | if (ret) | ||
1729 | goto free_inherit; | ||
1727 | 1730 | ||
1728 | if (ret == 0 && ptr && | 1731 | if (ptr && copy_to_user(arg + |
1729 | copy_to_user(arg + | 1732 | offsetof(struct btrfs_ioctl_vol_args_v2, |
1730 | offsetof(struct btrfs_ioctl_vol_args_v2, | 1733 | transid), |
1731 | transid), ptr, sizeof(*ptr))) | 1734 | ptr, sizeof(*ptr))) |
1732 | ret = -EFAULT; | 1735 | ret = -EFAULT; |
1733 | out: | 1736 | |
1734 | kfree(vol_args); | 1737 | free_inherit: |
1735 | kfree(inherit); | 1738 | kfree(inherit); |
1739 | free_args: | ||
1740 | kfree(vol_args); | ||
1736 | return ret; | 1741 | return ret; |
1737 | } | 1742 | } |
1738 | 1743 | ||
@@ -2652,7 +2657,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) | |||
2652 | vol_args = memdup_user(arg, sizeof(*vol_args)); | 2657 | vol_args = memdup_user(arg, sizeof(*vol_args)); |
2653 | if (IS_ERR(vol_args)) { | 2658 | if (IS_ERR(vol_args)) { |
2654 | ret = PTR_ERR(vol_args); | 2659 | ret = PTR_ERR(vol_args); |
2655 | goto out; | 2660 | goto err_drop; |
2656 | } | 2661 | } |
2657 | 2662 | ||
2658 | vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; | 2663 | vol_args->name[BTRFS_PATH_NAME_MAX] = '\0'; |
@@ -2670,6 +2675,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg) | |||
2670 | 2675 | ||
2671 | out: | 2676 | out: |
2672 | kfree(vol_args); | 2677 | kfree(vol_args); |
2678 | err_drop: | ||
2673 | mnt_drop_write_file(file); | 2679 | mnt_drop_write_file(file); |
2674 | return ret; | 2680 | return ret; |
2675 | } | 2681 | } |
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index 7e0e6e3029dd..1d1ba083ca6e 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c | |||
@@ -94,8 +94,10 @@ | |||
94 | #define LOG_WALK_REPLAY_ALL 3 | 94 | #define LOG_WALK_REPLAY_ALL 3 |
95 | 95 | ||
96 | static int btrfs_log_inode(struct btrfs_trans_handle *trans, | 96 | static int btrfs_log_inode(struct btrfs_trans_handle *trans, |
97 | struct btrfs_root *root, struct inode *inode, | 97 | struct btrfs_root *root, struct inode *inode, |
98 | int inode_only); | 98 | int inode_only, |
99 | const loff_t start, | ||
100 | const loff_t end); | ||
99 | static int link_to_fixup_dir(struct btrfs_trans_handle *trans, | 101 | static int link_to_fixup_dir(struct btrfs_trans_handle *trans, |
100 | struct btrfs_root *root, | 102 | struct btrfs_root *root, |
101 | struct btrfs_path *path, u64 objectid); | 103 | struct btrfs_path *path, u64 objectid); |
@@ -3858,8 +3860,10 @@ process: | |||
3858 | * This handles both files and directories. | 3860 | * This handles both files and directories. |
3859 | */ | 3861 | */ |
3860 | static int btrfs_log_inode(struct btrfs_trans_handle *trans, | 3862 | static int btrfs_log_inode(struct btrfs_trans_handle *trans, |
3861 | struct btrfs_root *root, struct inode *inode, | 3863 | struct btrfs_root *root, struct inode *inode, |
3862 | int inode_only) | 3864 | int inode_only, |
3865 | const loff_t start, | ||
3866 | const loff_t end) | ||
3863 | { | 3867 | { |
3864 | struct btrfs_path *path; | 3868 | struct btrfs_path *path; |
3865 | struct btrfs_path *dst_path; | 3869 | struct btrfs_path *dst_path; |
@@ -3876,6 +3880,7 @@ static int btrfs_log_inode(struct btrfs_trans_handle *trans, | |||
3876 | int ins_nr; | 3880 | int ins_nr; |
3877 | bool fast_search = false; | 3881 | bool fast_search = false; |
3878 | u64 ino = btrfs_ino(inode); | 3882 | u64 ino = btrfs_ino(inode); |
3883 | struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; | ||
3879 | 3884 | ||
3880 | path = btrfs_alloc_path(); | 3885 | path = btrfs_alloc_path(); |
3881 | if (!path) | 3886 | if (!path) |
@@ -4049,13 +4054,35 @@ log_extents: | |||
4049 | goto out_unlock; | 4054 | goto out_unlock; |
4050 | } | 4055 | } |
4051 | } else if (inode_only == LOG_INODE_ALL) { | 4056 | } else if (inode_only == LOG_INODE_ALL) { |
4052 | struct extent_map_tree *tree = &BTRFS_I(inode)->extent_tree; | ||
4053 | struct extent_map *em, *n; | 4057 | struct extent_map *em, *n; |
4054 | 4058 | ||
4055 | write_lock(&tree->lock); | 4059 | write_lock(&em_tree->lock); |
4056 | list_for_each_entry_safe(em, n, &tree->modified_extents, list) | 4060 | /* |
4057 | list_del_init(&em->list); | 4061 | * We can't just remove every em if we're called for a ranged |
4058 | write_unlock(&tree->lock); | 4062 | * fsync - that is, one that doesn't cover the whole possible |
4063 | * file range (0 to LLONG_MAX). This is because we can have | ||
4064 | * em's that fall outside the range we're logging and therefore | ||
4065 | * their ordered operations haven't completed yet | ||
4066 | * (btrfs_finish_ordered_io() not invoked yet). This means we | ||
4067 | * didn't get their respective file extent item in the fs/subvol | ||
4068 | * tree yet, and need to let the next fast fsync (one which | ||
4069 | * consults the list of modified extent maps) find the em so | ||
4070 | * that it logs a matching file extent item and waits for the | ||
4071 | * respective ordered operation to complete (if it's still | ||
4072 | * running). | ||
4073 | * | ||
4074 | * Removing every em outside the range we're logging would make | ||
4075 | * the next fast fsync not log their matching file extent items, | ||
4076 | * therefore making us lose data after a log replay. | ||
4077 | */ | ||
4078 | list_for_each_entry_safe(em, n, &em_tree->modified_extents, | ||
4079 | list) { | ||
4080 | const u64 mod_end = em->mod_start + em->mod_len - 1; | ||
4081 | |||
4082 | if (em->mod_start >= start && mod_end <= end) | ||
4083 | list_del_init(&em->list); | ||
4084 | } | ||
4085 | write_unlock(&em_tree->lock); | ||
4059 | } | 4086 | } |
4060 | 4087 | ||
4061 | if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->i_mode)) { | 4088 | if (inode_only == LOG_INODE_ALL && S_ISDIR(inode->i_mode)) { |
@@ -4065,6 +4092,7 @@ log_extents: | |||
4065 | goto out_unlock; | 4092 | goto out_unlock; |
4066 | } | 4093 | } |
4067 | } | 4094 | } |
4095 | |||
4068 | BTRFS_I(inode)->logged_trans = trans->transid; | 4096 | BTRFS_I(inode)->logged_trans = trans->transid; |
4069 | BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans; | 4097 | BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans; |
4070 | out_unlock: | 4098 | out_unlock: |
@@ -4161,7 +4189,10 @@ out: | |||
4161 | */ | 4189 | */ |
4162 | static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | 4190 | static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, |
4163 | struct btrfs_root *root, struct inode *inode, | 4191 | struct btrfs_root *root, struct inode *inode, |
4164 | struct dentry *parent, int exists_only, | 4192 | struct dentry *parent, |
4193 | const loff_t start, | ||
4194 | const loff_t end, | ||
4195 | int exists_only, | ||
4165 | struct btrfs_log_ctx *ctx) | 4196 | struct btrfs_log_ctx *ctx) |
4166 | { | 4197 | { |
4167 | int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL; | 4198 | int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL; |
@@ -4207,7 +4238,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
4207 | if (ret) | 4238 | if (ret) |
4208 | goto end_no_trans; | 4239 | goto end_no_trans; |
4209 | 4240 | ||
4210 | ret = btrfs_log_inode(trans, root, inode, inode_only); | 4241 | ret = btrfs_log_inode(trans, root, inode, inode_only, start, end); |
4211 | if (ret) | 4242 | if (ret) |
4212 | goto end_trans; | 4243 | goto end_trans; |
4213 | 4244 | ||
@@ -4235,7 +4266,8 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, | |||
4235 | 4266 | ||
4236 | if (BTRFS_I(inode)->generation > | 4267 | if (BTRFS_I(inode)->generation > |
4237 | root->fs_info->last_trans_committed) { | 4268 | root->fs_info->last_trans_committed) { |
4238 | ret = btrfs_log_inode(trans, root, inode, inode_only); | 4269 | ret = btrfs_log_inode(trans, root, inode, inode_only, |
4270 | 0, LLONG_MAX); | ||
4239 | if (ret) | 4271 | if (ret) |
4240 | goto end_trans; | 4272 | goto end_trans; |
4241 | } | 4273 | } |
@@ -4269,13 +4301,15 @@ end_no_trans: | |||
4269 | */ | 4301 | */ |
4270 | int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, | 4302 | int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, |
4271 | struct btrfs_root *root, struct dentry *dentry, | 4303 | struct btrfs_root *root, struct dentry *dentry, |
4304 | const loff_t start, | ||
4305 | const loff_t end, | ||
4272 | struct btrfs_log_ctx *ctx) | 4306 | struct btrfs_log_ctx *ctx) |
4273 | { | 4307 | { |
4274 | struct dentry *parent = dget_parent(dentry); | 4308 | struct dentry *parent = dget_parent(dentry); |
4275 | int ret; | 4309 | int ret; |
4276 | 4310 | ||
4277 | ret = btrfs_log_inode_parent(trans, root, dentry->d_inode, parent, | 4311 | ret = btrfs_log_inode_parent(trans, root, dentry->d_inode, parent, |
4278 | 0, ctx); | 4312 | start, end, 0, ctx); |
4279 | dput(parent); | 4313 | dput(parent); |
4280 | 4314 | ||
4281 | return ret; | 4315 | return ret; |
@@ -4512,6 +4546,7 @@ int btrfs_log_new_name(struct btrfs_trans_handle *trans, | |||
4512 | root->fs_info->last_trans_committed)) | 4546 | root->fs_info->last_trans_committed)) |
4513 | return 0; | 4547 | return 0; |
4514 | 4548 | ||
4515 | return btrfs_log_inode_parent(trans, root, inode, parent, 1, NULL); | 4549 | return btrfs_log_inode_parent(trans, root, inode, parent, 0, |
4550 | LLONG_MAX, 1, NULL); | ||
4516 | } | 4551 | } |
4517 | 4552 | ||
diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h index 7f5b41bd5373..e2e798ae7cd7 100644 --- a/fs/btrfs/tree-log.h +++ b/fs/btrfs/tree-log.h | |||
@@ -59,6 +59,8 @@ int btrfs_free_log_root_tree(struct btrfs_trans_handle *trans, | |||
59 | int btrfs_recover_log_trees(struct btrfs_root *tree_root); | 59 | int btrfs_recover_log_trees(struct btrfs_root *tree_root); |
60 | int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, | 60 | int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, |
61 | struct btrfs_root *root, struct dentry *dentry, | 61 | struct btrfs_root *root, struct dentry *dentry, |
62 | const loff_t start, | ||
63 | const loff_t end, | ||
62 | struct btrfs_log_ctx *ctx); | 64 | struct btrfs_log_ctx *ctx); |
63 | int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, | 65 | int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, |
64 | struct btrfs_root *root, | 66 | struct btrfs_root *root, |
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 340a92d08e84..2c2d6d1d8eee 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -529,12 +529,12 @@ static noinline int device_list_add(const char *path, | |||
529 | */ | 529 | */ |
530 | 530 | ||
531 | /* | 531 | /* |
532 | * As of now don't allow update to btrfs_fs_device through | 532 | * For now, we do allow update to btrfs_fs_device through the |
533 | * the btrfs dev scan cli, after FS has been mounted. | 533 | * btrfs dev scan cli after FS has been mounted. We're still |
534 | * tracking a problem where systems fail mount by subvolume id | ||
535 | * when we reject replacement on a mounted FS. | ||
534 | */ | 536 | */ |
535 | if (fs_devices->opened) { | 537 | if (!fs_devices->opened && found_transid < device->generation) { |
536 | return -EBUSY; | ||
537 | } else { | ||
538 | /* | 538 | /* |
539 | * That is if the FS is _not_ mounted and if you | 539 | * That is if the FS is _not_ mounted and if you |
540 | * are here, that means there is more than one | 540 | * are here, that means there is more than one |
@@ -542,8 +542,7 @@ static noinline int device_list_add(const char *path, | |||
542 | * with larger generation number or the last-in if | 542 | * with larger generation number or the last-in if |
543 | * generation are equal. | 543 | * generation are equal. |
544 | */ | 544 | */ |
545 | if (found_transid < device->generation) | 545 | return -EEXIST; |
546 | return -EEXIST; | ||
547 | } | 546 | } |
548 | 547 | ||
549 | name = rcu_string_strdup(path, GFP_NOFS); | 548 | name = rcu_string_strdup(path, GFP_NOFS); |
diff --git a/fs/buffer.c b/fs/buffer.c index 8f05111bbb8b..3588a80854b2 100644 --- a/fs/buffer.c +++ b/fs/buffer.c | |||
@@ -1022,7 +1022,8 @@ grow_dev_page(struct block_device *bdev, sector_t block, | |||
1022 | bh = page_buffers(page); | 1022 | bh = page_buffers(page); |
1023 | if (bh->b_size == size) { | 1023 | if (bh->b_size == size) { |
1024 | end_block = init_page_buffers(page, bdev, | 1024 | end_block = init_page_buffers(page, bdev, |
1025 | index << sizebits, size); | 1025 | (sector_t)index << sizebits, |
1026 | size); | ||
1026 | goto done; | 1027 | goto done; |
1027 | } | 1028 | } |
1028 | if (!try_to_free_buffers(page)) | 1029 | if (!try_to_free_buffers(page)) |
@@ -1043,7 +1044,8 @@ grow_dev_page(struct block_device *bdev, sector_t block, | |||
1043 | */ | 1044 | */ |
1044 | spin_lock(&inode->i_mapping->private_lock); | 1045 | spin_lock(&inode->i_mapping->private_lock); |
1045 | link_dev_buffers(page, bh); | 1046 | link_dev_buffers(page, bh); |
1046 | end_block = init_page_buffers(page, bdev, index << sizebits, size); | 1047 | end_block = init_page_buffers(page, bdev, (sector_t)index << sizebits, |
1048 | size); | ||
1047 | spin_unlock(&inode->i_mapping->private_lock); | 1049 | spin_unlock(&inode->i_mapping->private_lock); |
1048 | done: | 1050 | done: |
1049 | ret = (block < end_block) ? 1 : -ENXIO; | 1051 | ret = (block < end_block) ? 1 : -ENXIO; |
diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c index d749731dc0ee..fbb08e97438d 100644 --- a/fs/cachefiles/bind.c +++ b/fs/cachefiles/bind.c | |||
@@ -50,18 +50,18 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args) | |||
50 | cache->brun_percent < 100); | 50 | cache->brun_percent < 100); |
51 | 51 | ||
52 | if (*args) { | 52 | if (*args) { |
53 | pr_err("'bind' command doesn't take an argument"); | 53 | pr_err("'bind' command doesn't take an argument\n"); |
54 | return -EINVAL; | 54 | return -EINVAL; |
55 | } | 55 | } |
56 | 56 | ||
57 | if (!cache->rootdirname) { | 57 | if (!cache->rootdirname) { |
58 | pr_err("No cache directory specified"); | 58 | pr_err("No cache directory specified\n"); |
59 | return -EINVAL; | 59 | return -EINVAL; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* don't permit already bound caches to be re-bound */ | 62 | /* don't permit already bound caches to be re-bound */ |
63 | if (test_bit(CACHEFILES_READY, &cache->flags)) { | 63 | if (test_bit(CACHEFILES_READY, &cache->flags)) { |
64 | pr_err("Cache already bound"); | 64 | pr_err("Cache already bound\n"); |
65 | return -EBUSY; | 65 | return -EBUSY; |
66 | } | 66 | } |
67 | 67 | ||
@@ -248,7 +248,7 @@ error_open_root: | |||
248 | kmem_cache_free(cachefiles_object_jar, fsdef); | 248 | kmem_cache_free(cachefiles_object_jar, fsdef); |
249 | error_root_object: | 249 | error_root_object: |
250 | cachefiles_end_secure(cache, saved_cred); | 250 | cachefiles_end_secure(cache, saved_cred); |
251 | pr_err("Failed to register: %d", ret); | 251 | pr_err("Failed to register: %d\n", ret); |
252 | return ret; | 252 | return ret; |
253 | } | 253 | } |
254 | 254 | ||
diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c index b078d3081d6c..ce1b115dcc28 100644 --- a/fs/cachefiles/daemon.c +++ b/fs/cachefiles/daemon.c | |||
@@ -315,7 +315,7 @@ static unsigned int cachefiles_daemon_poll(struct file *file, | |||
315 | static int cachefiles_daemon_range_error(struct cachefiles_cache *cache, | 315 | static int cachefiles_daemon_range_error(struct cachefiles_cache *cache, |
316 | char *args) | 316 | char *args) |
317 | { | 317 | { |
318 | pr_err("Free space limits must be in range 0%%<=stop<cull<run<100%%"); | 318 | pr_err("Free space limits must be in range 0%%<=stop<cull<run<100%%\n"); |
319 | 319 | ||
320 | return -EINVAL; | 320 | return -EINVAL; |
321 | } | 321 | } |
@@ -475,12 +475,12 @@ static int cachefiles_daemon_dir(struct cachefiles_cache *cache, char *args) | |||
475 | _enter(",%s", args); | 475 | _enter(",%s", args); |
476 | 476 | ||
477 | if (!*args) { | 477 | if (!*args) { |
478 | pr_err("Empty directory specified"); | 478 | pr_err("Empty directory specified\n"); |
479 | return -EINVAL; | 479 | return -EINVAL; |
480 | } | 480 | } |
481 | 481 | ||
482 | if (cache->rootdirname) { | 482 | if (cache->rootdirname) { |
483 | pr_err("Second cache directory specified"); | 483 | pr_err("Second cache directory specified\n"); |
484 | return -EEXIST; | 484 | return -EEXIST; |
485 | } | 485 | } |
486 | 486 | ||
@@ -503,12 +503,12 @@ static int cachefiles_daemon_secctx(struct cachefiles_cache *cache, char *args) | |||
503 | _enter(",%s", args); | 503 | _enter(",%s", args); |
504 | 504 | ||
505 | if (!*args) { | 505 | if (!*args) { |
506 | pr_err("Empty security context specified"); | 506 | pr_err("Empty security context specified\n"); |
507 | return -EINVAL; | 507 | return -EINVAL; |
508 | } | 508 | } |
509 | 509 | ||
510 | if (cache->secctx) { | 510 | if (cache->secctx) { |
511 | pr_err("Second security context specified"); | 511 | pr_err("Second security context specified\n"); |
512 | return -EINVAL; | 512 | return -EINVAL; |
513 | } | 513 | } |
514 | 514 | ||
@@ -531,7 +531,7 @@ static int cachefiles_daemon_tag(struct cachefiles_cache *cache, char *args) | |||
531 | _enter(",%s", args); | 531 | _enter(",%s", args); |
532 | 532 | ||
533 | if (!*args) { | 533 | if (!*args) { |
534 | pr_err("Empty tag specified"); | 534 | pr_err("Empty tag specified\n"); |
535 | return -EINVAL; | 535 | return -EINVAL; |
536 | } | 536 | } |
537 | 537 | ||
@@ -562,12 +562,12 @@ static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args) | |||
562 | goto inval; | 562 | goto inval; |
563 | 563 | ||
564 | if (!test_bit(CACHEFILES_READY, &cache->flags)) { | 564 | if (!test_bit(CACHEFILES_READY, &cache->flags)) { |
565 | pr_err("cull applied to unready cache"); | 565 | pr_err("cull applied to unready cache\n"); |
566 | return -EIO; | 566 | return -EIO; |
567 | } | 567 | } |
568 | 568 | ||
569 | if (test_bit(CACHEFILES_DEAD, &cache->flags)) { | 569 | if (test_bit(CACHEFILES_DEAD, &cache->flags)) { |
570 | pr_err("cull applied to dead cache"); | 570 | pr_err("cull applied to dead cache\n"); |
571 | return -EIO; | 571 | return -EIO; |
572 | } | 572 | } |
573 | 573 | ||
@@ -587,11 +587,11 @@ static int cachefiles_daemon_cull(struct cachefiles_cache *cache, char *args) | |||
587 | 587 | ||
588 | notdir: | 588 | notdir: |
589 | path_put(&path); | 589 | path_put(&path); |
590 | pr_err("cull command requires dirfd to be a directory"); | 590 | pr_err("cull command requires dirfd to be a directory\n"); |
591 | return -ENOTDIR; | 591 | return -ENOTDIR; |
592 | 592 | ||
593 | inval: | 593 | inval: |
594 | pr_err("cull command requires dirfd and filename"); | 594 | pr_err("cull command requires dirfd and filename\n"); |
595 | return -EINVAL; | 595 | return -EINVAL; |
596 | } | 596 | } |
597 | 597 | ||
@@ -614,7 +614,7 @@ static int cachefiles_daemon_debug(struct cachefiles_cache *cache, char *args) | |||
614 | return 0; | 614 | return 0; |
615 | 615 | ||
616 | inval: | 616 | inval: |
617 | pr_err("debug command requires mask"); | 617 | pr_err("debug command requires mask\n"); |
618 | return -EINVAL; | 618 | return -EINVAL; |
619 | } | 619 | } |
620 | 620 | ||
@@ -634,12 +634,12 @@ static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args) | |||
634 | goto inval; | 634 | goto inval; |
635 | 635 | ||
636 | if (!test_bit(CACHEFILES_READY, &cache->flags)) { | 636 | if (!test_bit(CACHEFILES_READY, &cache->flags)) { |
637 | pr_err("inuse applied to unready cache"); | 637 | pr_err("inuse applied to unready cache\n"); |
638 | return -EIO; | 638 | return -EIO; |
639 | } | 639 | } |
640 | 640 | ||
641 | if (test_bit(CACHEFILES_DEAD, &cache->flags)) { | 641 | if (test_bit(CACHEFILES_DEAD, &cache->flags)) { |
642 | pr_err("inuse applied to dead cache"); | 642 | pr_err("inuse applied to dead cache\n"); |
643 | return -EIO; | 643 | return -EIO; |
644 | } | 644 | } |
645 | 645 | ||
@@ -659,11 +659,11 @@ static int cachefiles_daemon_inuse(struct cachefiles_cache *cache, char *args) | |||
659 | 659 | ||
660 | notdir: | 660 | notdir: |
661 | path_put(&path); | 661 | path_put(&path); |
662 | pr_err("inuse command requires dirfd to be a directory"); | 662 | pr_err("inuse command requires dirfd to be a directory\n"); |
663 | return -ENOTDIR; | 663 | return -ENOTDIR; |
664 | 664 | ||
665 | inval: | 665 | inval: |
666 | pr_err("inuse command requires dirfd and filename"); | 666 | pr_err("inuse command requires dirfd and filename\n"); |
667 | return -EINVAL; | 667 | return -EINVAL; |
668 | } | 668 | } |
669 | 669 | ||
diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h index 3d50998abf57..8c52472d2efa 100644 --- a/fs/cachefiles/internal.h +++ b/fs/cachefiles/internal.h | |||
@@ -255,7 +255,7 @@ extern int cachefiles_remove_object_xattr(struct cachefiles_cache *cache, | |||
255 | 255 | ||
256 | #define cachefiles_io_error(___cache, FMT, ...) \ | 256 | #define cachefiles_io_error(___cache, FMT, ...) \ |
257 | do { \ | 257 | do { \ |
258 | pr_err("I/O Error: " FMT, ##__VA_ARGS__); \ | 258 | pr_err("I/O Error: " FMT"\n", ##__VA_ARGS__); \ |
259 | fscache_io_error(&(___cache)->cache); \ | 259 | fscache_io_error(&(___cache)->cache); \ |
260 | set_bit(CACHEFILES_DEAD, &(___cache)->flags); \ | 260 | set_bit(CACHEFILES_DEAD, &(___cache)->flags); \ |
261 | } while (0) | 261 | } while (0) |
diff --git a/fs/cachefiles/main.c b/fs/cachefiles/main.c index 180edfb45f66..711f13d8c2de 100644 --- a/fs/cachefiles/main.c +++ b/fs/cachefiles/main.c | |||
@@ -84,7 +84,7 @@ error_proc: | |||
84 | error_object_jar: | 84 | error_object_jar: |
85 | misc_deregister(&cachefiles_dev); | 85 | misc_deregister(&cachefiles_dev); |
86 | error_dev: | 86 | error_dev: |
87 | pr_err("failed to register: %d", ret); | 87 | pr_err("failed to register: %d\n", ret); |
88 | return ret; | 88 | return ret; |
89 | } | 89 | } |
90 | 90 | ||
diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c index 5bf2b41e66d3..dad7d9542a24 100644 --- a/fs/cachefiles/namei.c +++ b/fs/cachefiles/namei.c | |||
@@ -543,7 +543,7 @@ lookup_again: | |||
543 | next, next->d_inode, next->d_inode->i_ino); | 543 | next, next->d_inode, next->d_inode->i_ino); |
544 | 544 | ||
545 | } else if (!S_ISDIR(next->d_inode->i_mode)) { | 545 | } else if (!S_ISDIR(next->d_inode->i_mode)) { |
546 | pr_err("inode %lu is not a directory", | 546 | pr_err("inode %lu is not a directory\n", |
547 | next->d_inode->i_ino); | 547 | next->d_inode->i_ino); |
548 | ret = -ENOBUFS; | 548 | ret = -ENOBUFS; |
549 | goto error; | 549 | goto error; |
@@ -574,7 +574,7 @@ lookup_again: | |||
574 | } else if (!S_ISDIR(next->d_inode->i_mode) && | 574 | } else if (!S_ISDIR(next->d_inode->i_mode) && |
575 | !S_ISREG(next->d_inode->i_mode) | 575 | !S_ISREG(next->d_inode->i_mode) |
576 | ) { | 576 | ) { |
577 | pr_err("inode %lu is not a file or directory", | 577 | pr_err("inode %lu is not a file or directory\n", |
578 | next->d_inode->i_ino); | 578 | next->d_inode->i_ino); |
579 | ret = -ENOBUFS; | 579 | ret = -ENOBUFS; |
580 | goto error; | 580 | goto error; |
@@ -768,7 +768,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, | |||
768 | ASSERT(subdir->d_inode); | 768 | ASSERT(subdir->d_inode); |
769 | 769 | ||
770 | if (!S_ISDIR(subdir->d_inode->i_mode)) { | 770 | if (!S_ISDIR(subdir->d_inode->i_mode)) { |
771 | pr_err("%s is not a directory", dirname); | 771 | pr_err("%s is not a directory\n", dirname); |
772 | ret = -EIO; | 772 | ret = -EIO; |
773 | goto check_error; | 773 | goto check_error; |
774 | } | 774 | } |
@@ -779,7 +779,8 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache, | |||
779 | !subdir->d_inode->i_op->lookup || | 779 | !subdir->d_inode->i_op->lookup || |
780 | !subdir->d_inode->i_op->mkdir || | 780 | !subdir->d_inode->i_op->mkdir || |
781 | !subdir->d_inode->i_op->create || | 781 | !subdir->d_inode->i_op->create || |
782 | !subdir->d_inode->i_op->rename || | 782 | (!subdir->d_inode->i_op->rename && |
783 | !subdir->d_inode->i_op->rename2) || | ||
783 | !subdir->d_inode->i_op->rmdir || | 784 | !subdir->d_inode->i_op->rmdir || |
784 | !subdir->d_inode->i_op->unlink) | 785 | !subdir->d_inode->i_op->unlink) |
785 | goto check_error; | 786 | goto check_error; |
@@ -795,13 +796,13 @@ check_error: | |||
795 | mkdir_error: | 796 | mkdir_error: |
796 | mutex_unlock(&dir->d_inode->i_mutex); | 797 | mutex_unlock(&dir->d_inode->i_mutex); |
797 | dput(subdir); | 798 | dput(subdir); |
798 | pr_err("mkdir %s failed with error %d", dirname, ret); | 799 | pr_err("mkdir %s failed with error %d\n", dirname, ret); |
799 | return ERR_PTR(ret); | 800 | return ERR_PTR(ret); |
800 | 801 | ||
801 | lookup_error: | 802 | lookup_error: |
802 | mutex_unlock(&dir->d_inode->i_mutex); | 803 | mutex_unlock(&dir->d_inode->i_mutex); |
803 | ret = PTR_ERR(subdir); | 804 | ret = PTR_ERR(subdir); |
804 | pr_err("Lookup %s failed with error %d", dirname, ret); | 805 | pr_err("Lookup %s failed with error %d\n", dirname, ret); |
805 | return ERR_PTR(ret); | 806 | return ERR_PTR(ret); |
806 | 807 | ||
807 | nomem_d_alloc: | 808 | nomem_d_alloc: |
@@ -891,7 +892,7 @@ lookup_error: | |||
891 | if (ret == -EIO) { | 892 | if (ret == -EIO) { |
892 | cachefiles_io_error(cache, "Lookup failed"); | 893 | cachefiles_io_error(cache, "Lookup failed"); |
893 | } else if (ret != -ENOMEM) { | 894 | } else if (ret != -ENOMEM) { |
894 | pr_err("Internal error: %d", ret); | 895 | pr_err("Internal error: %d\n", ret); |
895 | ret = -EIO; | 896 | ret = -EIO; |
896 | } | 897 | } |
897 | 898 | ||
@@ -950,7 +951,7 @@ error: | |||
950 | } | 951 | } |
951 | 952 | ||
952 | if (ret != -ENOMEM) { | 953 | if (ret != -ENOMEM) { |
953 | pr_err("Internal error: %d", ret); | 954 | pr_err("Internal error: %d\n", ret); |
954 | ret = -EIO; | 955 | ret = -EIO; |
955 | } | 956 | } |
956 | 957 | ||
diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c index 4b1fb5ca65b8..25e745b8eb1b 100644 --- a/fs/cachefiles/rdwr.c +++ b/fs/cachefiles/rdwr.c | |||
@@ -151,7 +151,6 @@ static void cachefiles_read_copier(struct fscache_operation *_op) | |||
151 | struct cachefiles_one_read *monitor; | 151 | struct cachefiles_one_read *monitor; |
152 | struct cachefiles_object *object; | 152 | struct cachefiles_object *object; |
153 | struct fscache_retrieval *op; | 153 | struct fscache_retrieval *op; |
154 | struct pagevec pagevec; | ||
155 | int error, max; | 154 | int error, max; |
156 | 155 | ||
157 | op = container_of(_op, struct fscache_retrieval, op); | 156 | op = container_of(_op, struct fscache_retrieval, op); |
@@ -160,8 +159,6 @@ static void cachefiles_read_copier(struct fscache_operation *_op) | |||
160 | 159 | ||
161 | _enter("{ino=%lu}", object->backer->d_inode->i_ino); | 160 | _enter("{ino=%lu}", object->backer->d_inode->i_ino); |
162 | 161 | ||
163 | pagevec_init(&pagevec, 0); | ||
164 | |||
165 | max = 8; | 162 | max = 8; |
166 | spin_lock_irq(&object->work_lock); | 163 | spin_lock_irq(&object->work_lock); |
167 | 164 | ||
@@ -396,7 +393,6 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op, | |||
396 | { | 393 | { |
397 | struct cachefiles_object *object; | 394 | struct cachefiles_object *object; |
398 | struct cachefiles_cache *cache; | 395 | struct cachefiles_cache *cache; |
399 | struct pagevec pagevec; | ||
400 | struct inode *inode; | 396 | struct inode *inode; |
401 | sector_t block0, block; | 397 | sector_t block0, block; |
402 | unsigned shift; | 398 | unsigned shift; |
@@ -427,8 +423,6 @@ int cachefiles_read_or_alloc_page(struct fscache_retrieval *op, | |||
427 | op->op.flags |= FSCACHE_OP_ASYNC; | 423 | op->op.flags |= FSCACHE_OP_ASYNC; |
428 | op->op.processor = cachefiles_read_copier; | 424 | op->op.processor = cachefiles_read_copier; |
429 | 425 | ||
430 | pagevec_init(&pagevec, 0); | ||
431 | |||
432 | /* we assume the absence or presence of the first block is a good | 426 | /* we assume the absence or presence of the first block is a good |
433 | * enough indication for the page as a whole | 427 | * enough indication for the page as a whole |
434 | * - TODO: don't use bmap() for this as it is _not_ actually good | 428 | * - TODO: don't use bmap() for this as it is _not_ actually good |
diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c index 1ad51ffbb275..acbc1f094fb1 100644 --- a/fs/cachefiles/xattr.c +++ b/fs/cachefiles/xattr.c | |||
@@ -51,7 +51,7 @@ int cachefiles_check_object_type(struct cachefiles_object *object) | |||
51 | } | 51 | } |
52 | 52 | ||
53 | if (ret != -EEXIST) { | 53 | if (ret != -EEXIST) { |
54 | pr_err("Can't set xattr on %*.*s [%lu] (err %d)", | 54 | pr_err("Can't set xattr on %*.*s [%lu] (err %d)\n", |
55 | dentry->d_name.len, dentry->d_name.len, | 55 | dentry->d_name.len, dentry->d_name.len, |
56 | dentry->d_name.name, dentry->d_inode->i_ino, | 56 | dentry->d_name.name, dentry->d_inode->i_ino, |
57 | -ret); | 57 | -ret); |
@@ -64,7 +64,7 @@ int cachefiles_check_object_type(struct cachefiles_object *object) | |||
64 | if (ret == -ERANGE) | 64 | if (ret == -ERANGE) |
65 | goto bad_type_length; | 65 | goto bad_type_length; |
66 | 66 | ||
67 | pr_err("Can't read xattr on %*.*s [%lu] (err %d)", | 67 | pr_err("Can't read xattr on %*.*s [%lu] (err %d)\n", |
68 | dentry->d_name.len, dentry->d_name.len, | 68 | dentry->d_name.len, dentry->d_name.len, |
69 | dentry->d_name.name, dentry->d_inode->i_ino, | 69 | dentry->d_name.name, dentry->d_inode->i_ino, |
70 | -ret); | 70 | -ret); |
@@ -85,14 +85,14 @@ error: | |||
85 | return ret; | 85 | return ret; |
86 | 86 | ||
87 | bad_type_length: | 87 | bad_type_length: |
88 | pr_err("Cache object %lu type xattr length incorrect", | 88 | pr_err("Cache object %lu type xattr length incorrect\n", |
89 | dentry->d_inode->i_ino); | 89 | dentry->d_inode->i_ino); |
90 | ret = -EIO; | 90 | ret = -EIO; |
91 | goto error; | 91 | goto error; |
92 | 92 | ||
93 | bad_type: | 93 | bad_type: |
94 | xtype[2] = 0; | 94 | xtype[2] = 0; |
95 | pr_err("Cache object %*.*s [%lu] type %s not %s", | 95 | pr_err("Cache object %*.*s [%lu] type %s not %s\n", |
96 | dentry->d_name.len, dentry->d_name.len, | 96 | dentry->d_name.len, dentry->d_name.len, |
97 | dentry->d_name.name, dentry->d_inode->i_ino, | 97 | dentry->d_name.name, dentry->d_inode->i_ino, |
98 | xtype, type); | 98 | xtype, type); |
@@ -293,7 +293,7 @@ error: | |||
293 | return ret; | 293 | return ret; |
294 | 294 | ||
295 | bad_type_length: | 295 | bad_type_length: |
296 | pr_err("Cache object %lu xattr length incorrect", | 296 | pr_err("Cache object %lu xattr length incorrect\n", |
297 | dentry->d_inode->i_ino); | 297 | dentry->d_inode->i_ino); |
298 | ret = -EIO; | 298 | ret = -EIO; |
299 | goto error; | 299 | goto error; |
diff --git a/fs/cifs/Kconfig b/fs/cifs/Kconfig index 603f18a65c12..a2172f3f69e3 100644 --- a/fs/cifs/Kconfig +++ b/fs/cifs/Kconfig | |||
@@ -22,6 +22,11 @@ config CIFS | |||
22 | support for OS/2 and Windows ME and similar servers is provided as | 22 | support for OS/2 and Windows ME and similar servers is provided as |
23 | well. | 23 | well. |
24 | 24 | ||
25 | The module also provides optional support for the followon | ||
26 | protocols for CIFS including SMB3, which enables | ||
27 | useful performance and security features (see the description | ||
28 | of CONFIG_CIFS_SMB2). | ||
29 | |||
25 | The cifs module provides an advanced network file system | 30 | The cifs module provides an advanced network file system |
26 | client for mounting to CIFS compliant servers. It includes | 31 | client for mounting to CIFS compliant servers. It includes |
27 | support for DFS (hierarchical name space), secure per-user | 32 | support for DFS (hierarchical name space), secure per-user |
@@ -121,7 +126,8 @@ config CIFS_ACL | |||
121 | depends on CIFS_XATTR && KEYS | 126 | depends on CIFS_XATTR && KEYS |
122 | help | 127 | help |
123 | Allows fetching CIFS/NTFS ACL from the server. The DACL blob | 128 | Allows fetching CIFS/NTFS ACL from the server. The DACL blob |
124 | is handed over to the application/caller. | 129 | is handed over to the application/caller. See the man |
130 | page for getcifsacl for more information. | ||
125 | 131 | ||
126 | config CIFS_DEBUG | 132 | config CIFS_DEBUG |
127 | bool "Enable CIFS debugging routines" | 133 | bool "Enable CIFS debugging routines" |
@@ -162,7 +168,7 @@ config CIFS_NFSD_EXPORT | |||
162 | Allows NFS server to export a CIFS mounted share (nfsd over cifs) | 168 | Allows NFS server to export a CIFS mounted share (nfsd over cifs) |
163 | 169 | ||
164 | config CIFS_SMB2 | 170 | config CIFS_SMB2 |
165 | bool "SMB2 network file system support" | 171 | bool "SMB2 and SMB3 network file system support" |
166 | depends on CIFS && INET | 172 | depends on CIFS && INET |
167 | select NLS | 173 | select NLS |
168 | select KEYS | 174 | select KEYS |
@@ -170,16 +176,21 @@ config CIFS_SMB2 | |||
170 | select DNS_RESOLVER | 176 | select DNS_RESOLVER |
171 | 177 | ||
172 | help | 178 | help |
173 | This enables experimental support for the SMB2 (Server Message Block | 179 | This enables support for the Server Message Block version 2 |
174 | version 2) protocol. The SMB2 protocol is the successor to the | 180 | family of protocols, including SMB3. SMB3 support is |
175 | popular CIFS and SMB network file sharing protocols. SMB2 is the | 181 | enabled on mount by specifying "vers=3.0" in the mount |
176 | native file sharing mechanism for recent versions of Windows | 182 | options. These protocols are the successors to the popular |
177 | operating systems (since Vista). SMB2 enablement will eventually | 183 | CIFS and SMB network file sharing protocols. SMB3 is the |
178 | allow users better performance, security and features, than would be | 184 | native file sharing mechanism for the more recent |
179 | possible with cifs. Note that smb2 mount options also are simpler | 185 | versions of Windows (Windows 8 and Windows 2012 and |
180 | (compared to cifs) due to protocol improvements. | 186 | later) and Samba server and many others support SMB3 well. |
181 | 187 | In general SMB3 enables better performance, security | |
182 | Unless you are a developer or tester, say N. | 188 | and features, than would be possible with CIFS (Note that |
189 | when mounting to Samba, due to the CIFS POSIX extensions, | ||
190 | CIFS mounts can provide slightly better POSIX compatibility | ||
191 | than SMB3 mounts do though). Note that SMB2/SMB3 mount | ||
192 | options are also slightly simpler (compared to CIFS) due | ||
193 | to protocol improvements. | ||
183 | 194 | ||
184 | config CIFS_FSCACHE | 195 | config CIFS_FSCACHE |
185 | bool "Provide CIFS client caching support" | 196 | bool "Provide CIFS client caching support" |
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h index b0fafa499505..002e0c173939 100644 --- a/fs/cifs/cifsfs.h +++ b/fs/cifs/cifsfs.h | |||
@@ -136,5 +136,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg); | |||
136 | extern const struct export_operations cifs_export_ops; | 136 | extern const struct export_operations cifs_export_ops; |
137 | #endif /* CONFIG_CIFS_NFSD_EXPORT */ | 137 | #endif /* CONFIG_CIFS_NFSD_EXPORT */ |
138 | 138 | ||
139 | #define CIFS_VERSION "2.04" | 139 | #define CIFS_VERSION "2.05" |
140 | #endif /* _CIFSFS_H */ | 140 | #endif /* _CIFSFS_H */ |
diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index dfc731b02aa9..25b8392bfdd2 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h | |||
@@ -70,11 +70,6 @@ | |||
70 | #define SERVER_NAME_LENGTH 40 | 70 | #define SERVER_NAME_LENGTH 40 |
71 | #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1) | 71 | #define SERVER_NAME_LEN_WITH_NULL (SERVER_NAME_LENGTH + 1) |
72 | 72 | ||
73 | /* used to define string lengths for reversing unicode strings */ | ||
74 | /* (256+1)*2 = 514 */ | ||
75 | /* (max path length + 1 for null) * 2 for unicode */ | ||
76 | #define MAX_NAME 514 | ||
77 | |||
78 | /* SMB echo "timeout" -- FIXME: tunable? */ | 73 | /* SMB echo "timeout" -- FIXME: tunable? */ |
79 | #define SMB_ECHO_INTERVAL (60 * HZ) | 74 | #define SMB_ECHO_INTERVAL (60 * HZ) |
80 | 75 | ||
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 03ed8a09581c..36ca2045009b 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c | |||
@@ -1600,6 +1600,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1600 | tmp_end++; | 1600 | tmp_end++; |
1601 | if (!(tmp_end < end && tmp_end[1] == delim)) { | 1601 | if (!(tmp_end < end && tmp_end[1] == delim)) { |
1602 | /* No it is not. Set the password to NULL */ | 1602 | /* No it is not. Set the password to NULL */ |
1603 | kfree(vol->password); | ||
1603 | vol->password = NULL; | 1604 | vol->password = NULL; |
1604 | break; | 1605 | break; |
1605 | } | 1606 | } |
@@ -1637,6 +1638,7 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, | |||
1637 | options = end; | 1638 | options = end; |
1638 | } | 1639 | } |
1639 | 1640 | ||
1641 | kfree(vol->password); | ||
1640 | /* Now build new password string */ | 1642 | /* Now build new password string */ |
1641 | temp_len = strlen(value); | 1643 | temp_len = strlen(value); |
1642 | vol->password = kzalloc(temp_len+1, GFP_KERNEL); | 1644 | vol->password = kzalloc(temp_len+1, GFP_KERNEL); |
diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index 3db0c5fd9a11..6cbd9c688cfe 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c | |||
@@ -497,6 +497,14 @@ cifs_atomic_open(struct inode *inode, struct dentry *direntry, | |||
497 | goto out; | 497 | goto out; |
498 | } | 498 | } |
499 | 499 | ||
500 | if (file->f_flags & O_DIRECT && | ||
501 | CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) { | ||
502 | if (CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) | ||
503 | file->f_op = &cifs_file_direct_nobrl_ops; | ||
504 | else | ||
505 | file->f_op = &cifs_file_direct_ops; | ||
506 | } | ||
507 | |||
500 | file_info = cifs_new_fileinfo(&fid, file, tlink, oplock); | 508 | file_info = cifs_new_fileinfo(&fid, file, tlink, oplock); |
501 | if (file_info == NULL) { | 509 | if (file_info == NULL) { |
502 | if (server->ops->close) | 510 | if (server->ops->close) |
diff --git a/fs/cifs/file.c b/fs/cifs/file.c index d5fec92e0360..5f29354b072a 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c | |||
@@ -467,6 +467,14 @@ int cifs_open(struct inode *inode, struct file *file) | |||
467 | cifs_dbg(FYI, "inode = 0x%p file flags are 0x%x for %s\n", | 467 | cifs_dbg(FYI, "inode = 0x%p file flags are 0x%x for %s\n", |
468 | inode, file->f_flags, full_path); | 468 | inode, file->f_flags, full_path); |
469 | 469 | ||
470 | if (file->f_flags & O_DIRECT && | ||
471 | cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) { | ||
472 | if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL) | ||
473 | file->f_op = &cifs_file_direct_nobrl_ops; | ||
474 | else | ||
475 | file->f_op = &cifs_file_direct_ops; | ||
476 | } | ||
477 | |||
470 | if (server->oplocks) | 478 | if (server->oplocks) |
471 | oplock = REQ_OPLOCK; | 479 | oplock = REQ_OPLOCK; |
472 | else | 480 | else |
@@ -3560,15 +3568,9 @@ static int cifs_readpages(struct file *file, struct address_space *mapping, | |||
3560 | lru_cache_add_file(page); | 3568 | lru_cache_add_file(page); |
3561 | unlock_page(page); | 3569 | unlock_page(page); |
3562 | page_cache_release(page); | 3570 | page_cache_release(page); |
3563 | if (rc == -EAGAIN) | ||
3564 | list_add_tail(&page->lru, &tmplist); | ||
3565 | } | 3571 | } |
3572 | /* Fallback to the readpage in error/reconnect cases */ | ||
3566 | kref_put(&rdata->refcount, cifs_readdata_release); | 3573 | kref_put(&rdata->refcount, cifs_readdata_release); |
3567 | if (rc == -EAGAIN) { | ||
3568 | /* Re-add pages to the page_list and retry */ | ||
3569 | list_splice(&tmplist, page_list); | ||
3570 | continue; | ||
3571 | } | ||
3572 | break; | 3574 | break; |
3573 | } | 3575 | } |
3574 | 3576 | ||
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 949ec909ec9a..7899a40465b3 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c | |||
@@ -1720,7 +1720,10 @@ cifs_rename2(struct inode *source_dir, struct dentry *source_dentry, | |||
1720 | unlink_target: | 1720 | unlink_target: |
1721 | /* Try unlinking the target dentry if it's not negative */ | 1721 | /* Try unlinking the target dentry if it's not negative */ |
1722 | if (target_dentry->d_inode && (rc == -EACCES || rc == -EEXIST)) { | 1722 | if (target_dentry->d_inode && (rc == -EACCES || rc == -EEXIST)) { |
1723 | tmprc = cifs_unlink(target_dir, target_dentry); | 1723 | if (d_is_dir(target_dentry)) |
1724 | tmprc = cifs_rmdir(target_dir, target_dentry); | ||
1725 | else | ||
1726 | tmprc = cifs_unlink(target_dir, target_dentry); | ||
1724 | if (tmprc) | 1727 | if (tmprc) |
1725 | goto cifs_rename_exit; | 1728 | goto cifs_rename_exit; |
1726 | rc = cifs_do_rename(xid, source_dentry, from_name, | 1729 | rc = cifs_do_rename(xid, source_dentry, from_name, |
diff --git a/fs/cifs/link.c b/fs/cifs/link.c index 68559fd557fb..5657416d3483 100644 --- a/fs/cifs/link.c +++ b/fs/cifs/link.c | |||
@@ -213,8 +213,12 @@ create_mf_symlink(const unsigned int xid, struct cifs_tcon *tcon, | |||
213 | if (rc) | 213 | if (rc) |
214 | goto out; | 214 | goto out; |
215 | 215 | ||
216 | rc = tcon->ses->server->ops->create_mf_symlink(xid, tcon, cifs_sb, | 216 | if (tcon->ses->server->ops->create_mf_symlink) |
217 | fromName, buf, &bytes_written); | 217 | rc = tcon->ses->server->ops->create_mf_symlink(xid, tcon, |
218 | cifs_sb, fromName, buf, &bytes_written); | ||
219 | else | ||
220 | rc = -EOPNOTSUPP; | ||
221 | |||
218 | if (rc) | 222 | if (rc) |
219 | goto out; | 223 | goto out; |
220 | 224 | ||
@@ -339,9 +343,11 @@ cifs_query_mf_symlink(unsigned int xid, struct cifs_tcon *tcon, | |||
339 | if (rc) | 343 | if (rc) |
340 | return rc; | 344 | return rc; |
341 | 345 | ||
342 | if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) | 346 | if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) { |
347 | rc = -ENOENT; | ||
343 | /* it's not a symlink */ | 348 | /* it's not a symlink */ |
344 | goto out; | 349 | goto out; |
350 | } | ||
345 | 351 | ||
346 | io_parms.netfid = fid.netfid; | 352 | io_parms.netfid = fid.netfid; |
347 | io_parms.pid = current->tgid; | 353 | io_parms.pid = current->tgid; |
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c index 6834b9c3bec1..b333ff60781d 100644 --- a/fs/cifs/netmisc.c +++ b/fs/cifs/netmisc.c | |||
@@ -925,11 +925,23 @@ cifs_NTtimeToUnix(__le64 ntutc) | |||
925 | /* BB what about the timezone? BB */ | 925 | /* BB what about the timezone? BB */ |
926 | 926 | ||
927 | /* Subtract the NTFS time offset, then convert to 1s intervals. */ | 927 | /* Subtract the NTFS time offset, then convert to 1s intervals. */ |
928 | u64 t; | 928 | s64 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET; |
929 | |||
930 | /* | ||
931 | * Unfortunately can not use normal 64 bit division on 32 bit arch, but | ||
932 | * the alternative, do_div, does not work with negative numbers so have | ||
933 | * to special case them | ||
934 | */ | ||
935 | if (t < 0) { | ||
936 | t = -t; | ||
937 | ts.tv_nsec = (long)(do_div(t, 10000000) * 100); | ||
938 | ts.tv_nsec = -ts.tv_nsec; | ||
939 | ts.tv_sec = -t; | ||
940 | } else { | ||
941 | ts.tv_nsec = (long)do_div(t, 10000000) * 100; | ||
942 | ts.tv_sec = t; | ||
943 | } | ||
929 | 944 | ||
930 | t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET; | ||
931 | ts.tv_nsec = do_div(t, 10000000) * 100; | ||
932 | ts.tv_sec = t; | ||
933 | return ts; | 945 | return ts; |
934 | } | 946 | } |
935 | 947 | ||
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c index 798c80a41c88..b334a89d6a66 100644 --- a/fs/cifs/readdir.c +++ b/fs/cifs/readdir.c | |||
@@ -596,8 +596,8 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos, | |||
596 | if (server->ops->dir_needs_close(cfile)) { | 596 | if (server->ops->dir_needs_close(cfile)) { |
597 | cfile->invalidHandle = true; | 597 | cfile->invalidHandle = true; |
598 | spin_unlock(&cifs_file_list_lock); | 598 | spin_unlock(&cifs_file_list_lock); |
599 | if (server->ops->close) | 599 | if (server->ops->close_dir) |
600 | server->ops->close(xid, tcon, &cfile->fid); | 600 | server->ops->close_dir(xid, tcon, &cfile->fid); |
601 | } else | 601 | } else |
602 | spin_unlock(&cifs_file_list_lock); | 602 | spin_unlock(&cifs_file_list_lock); |
603 | if (cfile->srch_inf.ntwrk_buf_start) { | 603 | if (cfile->srch_inf.ntwrk_buf_start) { |
diff --git a/fs/cifs/sess.c b/fs/cifs/sess.c index 39ee32688eac..57db63ff88da 100644 --- a/fs/cifs/sess.c +++ b/fs/cifs/sess.c | |||
@@ -243,10 +243,11 @@ static void decode_ascii_ssetup(char **pbcc_area, __u16 bleft, | |||
243 | kfree(ses->serverOS); | 243 | kfree(ses->serverOS); |
244 | 244 | ||
245 | ses->serverOS = kzalloc(len + 1, GFP_KERNEL); | 245 | ses->serverOS = kzalloc(len + 1, GFP_KERNEL); |
246 | if (ses->serverOS) | 246 | if (ses->serverOS) { |
247 | strncpy(ses->serverOS, bcc_ptr, len); | 247 | strncpy(ses->serverOS, bcc_ptr, len); |
248 | if (strncmp(ses->serverOS, "OS/2", 4) == 0) | 248 | if (strncmp(ses->serverOS, "OS/2", 4) == 0) |
249 | cifs_dbg(FYI, "OS/2 server\n"); | 249 | cifs_dbg(FYI, "OS/2 server\n"); |
250 | } | ||
250 | 251 | ||
251 | bcc_ptr += len + 1; | 252 | bcc_ptr += len + 1; |
252 | bleft -= len + 1; | 253 | bleft -= len + 1; |
@@ -744,14 +745,6 @@ out: | |||
744 | sess_free_buffer(sess_data); | 745 | sess_free_buffer(sess_data); |
745 | } | 746 | } |
746 | 747 | ||
747 | #else | ||
748 | |||
749 | static void | ||
750 | sess_auth_lanman(struct sess_data *sess_data) | ||
751 | { | ||
752 | sess_data->result = -EOPNOTSUPP; | ||
753 | sess_data->func = NULL; | ||
754 | } | ||
755 | #endif | 748 | #endif |
756 | 749 | ||
757 | static void | 750 | static void |
@@ -1102,15 +1095,6 @@ out: | |||
1102 | ses->auth_key.response = NULL; | 1095 | ses->auth_key.response = NULL; |
1103 | } | 1096 | } |
1104 | 1097 | ||
1105 | #else | ||
1106 | |||
1107 | static void | ||
1108 | sess_auth_kerberos(struct sess_data *sess_data) | ||
1109 | { | ||
1110 | cifs_dbg(VFS, "Kerberos negotiated but upcall support disabled!\n"); | ||
1111 | sess_data->result = -ENOSYS; | ||
1112 | sess_data->func = NULL; | ||
1113 | } | ||
1114 | #endif /* ! CONFIG_CIFS_UPCALL */ | 1098 | #endif /* ! CONFIG_CIFS_UPCALL */ |
1115 | 1099 | ||
1116 | /* | 1100 | /* |
diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c index 1a6df4b03f67..52131d8cb4d5 100644 --- a/fs/cifs/smb1ops.c +++ b/fs/cifs/smb1ops.c | |||
@@ -586,7 +586,7 @@ cifs_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, | |||
586 | tmprc = CIFS_open(xid, &oparms, &oplock, NULL); | 586 | tmprc = CIFS_open(xid, &oparms, &oplock, NULL); |
587 | if (tmprc == -EOPNOTSUPP) | 587 | if (tmprc == -EOPNOTSUPP) |
588 | *symlink = true; | 588 | *symlink = true; |
589 | else | 589 | else if (tmprc == 0) |
590 | CIFSSMBClose(xid, tcon, fid.netfid); | 590 | CIFSSMBClose(xid, tcon, fid.netfid); |
591 | } | 591 | } |
592 | 592 | ||
diff --git a/fs/cifs/smb2file.c b/fs/cifs/smb2file.c index 3f17b4550831..45992944e238 100644 --- a/fs/cifs/smb2file.c +++ b/fs/cifs/smb2file.c | |||
@@ -50,7 +50,7 @@ smb2_open_file(const unsigned int xid, struct cifs_open_parms *oparms, | |||
50 | goto out; | 50 | goto out; |
51 | } | 51 | } |
52 | 52 | ||
53 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | 53 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
54 | GFP_KERNEL); | 54 | GFP_KERNEL); |
55 | if (smb2_data == NULL) { | 55 | if (smb2_data == NULL) { |
56 | rc = -ENOMEM; | 56 | rc = -ENOMEM; |
diff --git a/fs/cifs/smb2inode.c b/fs/cifs/smb2inode.c index 0150182a4494..899bbc86f73e 100644 --- a/fs/cifs/smb2inode.c +++ b/fs/cifs/smb2inode.c | |||
@@ -131,7 +131,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, | |||
131 | *adjust_tz = false; | 131 | *adjust_tz = false; |
132 | *symlink = false; | 132 | *symlink = false; |
133 | 133 | ||
134 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | 134 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
135 | GFP_KERNEL); | 135 | GFP_KERNEL); |
136 | if (smb2_data == NULL) | 136 | if (smb2_data == NULL) |
137 | return -ENOMEM; | 137 | return -ENOMEM; |
diff --git a/fs/cifs/smb2maperror.c b/fs/cifs/smb2maperror.c index af59d03db492..8257a5a97cc0 100644 --- a/fs/cifs/smb2maperror.c +++ b/fs/cifs/smb2maperror.c | |||
@@ -256,6 +256,8 @@ static const struct status_to_posix_error smb2_error_map_table[] = { | |||
256 | {STATUS_DLL_MIGHT_BE_INCOMPATIBLE, -EIO, | 256 | {STATUS_DLL_MIGHT_BE_INCOMPATIBLE, -EIO, |
257 | "STATUS_DLL_MIGHT_BE_INCOMPATIBLE"}, | 257 | "STATUS_DLL_MIGHT_BE_INCOMPATIBLE"}, |
258 | {STATUS_STOPPED_ON_SYMLINK, -EOPNOTSUPP, "STATUS_STOPPED_ON_SYMLINK"}, | 258 | {STATUS_STOPPED_ON_SYMLINK, -EOPNOTSUPP, "STATUS_STOPPED_ON_SYMLINK"}, |
259 | {STATUS_IO_REPARSE_TAG_NOT_HANDLED, -EOPNOTSUPP, | ||
260 | "STATUS_REPARSE_NOT_HANDLED"}, | ||
259 | {STATUS_DEVICE_REQUIRES_CLEANING, -EIO, | 261 | {STATUS_DEVICE_REQUIRES_CLEANING, -EIO, |
260 | "STATUS_DEVICE_REQUIRES_CLEANING"}, | 262 | "STATUS_DEVICE_REQUIRES_CLEANING"}, |
261 | {STATUS_DEVICE_DOOR_OPEN, -EIO, "STATUS_DEVICE_DOOR_OPEN"}, | 263 | {STATUS_DEVICE_DOOR_OPEN, -EIO, "STATUS_DEVICE_DOOR_OPEN"}, |
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 5a48aa290dfe..f522193b7184 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c | |||
@@ -389,7 +389,7 @@ smb2_query_file_info(const unsigned int xid, struct cifs_tcon *tcon, | |||
389 | int rc; | 389 | int rc; |
390 | struct smb2_file_all_info *smb2_data; | 390 | struct smb2_file_all_info *smb2_data; |
391 | 391 | ||
392 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | 392 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
393 | GFP_KERNEL); | 393 | GFP_KERNEL); |
394 | if (smb2_data == NULL) | 394 | if (smb2_data == NULL) |
395 | return -ENOMEM; | 395 | return -ENOMEM; |
@@ -1035,7 +1035,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, | |||
1035 | if (keep_size == false) | 1035 | if (keep_size == false) |
1036 | return -EOPNOTSUPP; | 1036 | return -EOPNOTSUPP; |
1037 | 1037 | ||
1038 | /* | 1038 | /* |
1039 | * Must check if file sparse since fallocate -z (zero range) assumes | 1039 | * Must check if file sparse since fallocate -z (zero range) assumes |
1040 | * non-sparse allocation | 1040 | * non-sparse allocation |
1041 | */ | 1041 | */ |
diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index fa0dd044213b..74b3a6684383 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c | |||
@@ -530,7 +530,7 @@ SMB2_sess_setup(const unsigned int xid, struct cifs_ses *ses, | |||
530 | struct smb2_sess_setup_rsp *rsp = NULL; | 530 | struct smb2_sess_setup_rsp *rsp = NULL; |
531 | struct kvec iov[2]; | 531 | struct kvec iov[2]; |
532 | int rc = 0; | 532 | int rc = 0; |
533 | int resp_buftype; | 533 | int resp_buftype = CIFS_NO_BUFFER; |
534 | __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */ | 534 | __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */ |
535 | struct TCP_Server_Info *server = ses->server; | 535 | struct TCP_Server_Info *server = ses->server; |
536 | u16 blob_length = 0; | 536 | u16 blob_length = 0; |
@@ -1403,8 +1403,7 @@ SMB2_close(const unsigned int xid, struct cifs_tcon *tcon, | |||
1403 | rsp = (struct smb2_close_rsp *)iov[0].iov_base; | 1403 | rsp = (struct smb2_close_rsp *)iov[0].iov_base; |
1404 | 1404 | ||
1405 | if (rc != 0) { | 1405 | if (rc != 0) { |
1406 | if (tcon) | 1406 | cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE); |
1407 | cifs_stats_fail_inc(tcon, SMB2_CLOSE_HE); | ||
1408 | goto close_exit; | 1407 | goto close_exit; |
1409 | } | 1408 | } |
1410 | 1409 | ||
@@ -1533,7 +1532,7 @@ SMB2_query_info(const unsigned int xid, struct cifs_tcon *tcon, | |||
1533 | { | 1532 | { |
1534 | return query_info(xid, tcon, persistent_fid, volatile_fid, | 1533 | return query_info(xid, tcon, persistent_fid, volatile_fid, |
1535 | FILE_ALL_INFORMATION, | 1534 | FILE_ALL_INFORMATION, |
1536 | sizeof(struct smb2_file_all_info) + MAX_NAME * 2, | 1535 | sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
1537 | sizeof(struct smb2_file_all_info), data); | 1536 | sizeof(struct smb2_file_all_info), data); |
1538 | } | 1537 | } |
1539 | 1538 | ||
diff --git a/fs/dcache.c b/fs/dcache.c index d30ce699ae4b..cb25a1a5e307 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -106,8 +106,7 @@ static inline struct hlist_bl_head *d_hash(const struct dentry *parent, | |||
106 | unsigned int hash) | 106 | unsigned int hash) |
107 | { | 107 | { |
108 | hash += (unsigned long) parent / L1_CACHE_BYTES; | 108 | hash += (unsigned long) parent / L1_CACHE_BYTES; |
109 | hash = hash + (hash >> d_hash_shift); | 109 | return dentry_hashtable + hash_32(hash, d_hash_shift); |
110 | return dentry_hashtable + (hash & d_hash_mask); | ||
111 | } | 110 | } |
112 | 111 | ||
113 | /* Statistics gathering. */ | 112 | /* Statistics gathering. */ |
@@ -2373,7 +2372,8 @@ void dentry_update_name_case(struct dentry *dentry, struct qstr *name) | |||
2373 | } | 2372 | } |
2374 | EXPORT_SYMBOL(dentry_update_name_case); | 2373 | EXPORT_SYMBOL(dentry_update_name_case); |
2375 | 2374 | ||
2376 | static void switch_names(struct dentry *dentry, struct dentry *target) | 2375 | static void switch_names(struct dentry *dentry, struct dentry *target, |
2376 | bool exchange) | ||
2377 | { | 2377 | { |
2378 | if (dname_external(target)) { | 2378 | if (dname_external(target)) { |
2379 | if (dname_external(dentry)) { | 2379 | if (dname_external(dentry)) { |
@@ -2407,13 +2407,19 @@ static void switch_names(struct dentry *dentry, struct dentry *target) | |||
2407 | */ | 2407 | */ |
2408 | unsigned int i; | 2408 | unsigned int i; |
2409 | BUILD_BUG_ON(!IS_ALIGNED(DNAME_INLINE_LEN, sizeof(long))); | 2409 | BUILD_BUG_ON(!IS_ALIGNED(DNAME_INLINE_LEN, sizeof(long))); |
2410 | if (!exchange) { | ||
2411 | memcpy(dentry->d_iname, target->d_name.name, | ||
2412 | target->d_name.len + 1); | ||
2413 | dentry->d_name.hash_len = target->d_name.hash_len; | ||
2414 | return; | ||
2415 | } | ||
2410 | for (i = 0; i < DNAME_INLINE_LEN / sizeof(long); i++) { | 2416 | for (i = 0; i < DNAME_INLINE_LEN / sizeof(long); i++) { |
2411 | swap(((long *) &dentry->d_iname)[i], | 2417 | swap(((long *) &dentry->d_iname)[i], |
2412 | ((long *) &target->d_iname)[i]); | 2418 | ((long *) &target->d_iname)[i]); |
2413 | } | 2419 | } |
2414 | } | 2420 | } |
2415 | } | 2421 | } |
2416 | swap(dentry->d_name.len, target->d_name.len); | 2422 | swap(dentry->d_name.hash_len, target->d_name.hash_len); |
2417 | } | 2423 | } |
2418 | 2424 | ||
2419 | static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) | 2425 | static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) |
@@ -2443,25 +2449,29 @@ static void dentry_lock_for_move(struct dentry *dentry, struct dentry *target) | |||
2443 | } | 2449 | } |
2444 | } | 2450 | } |
2445 | 2451 | ||
2446 | static void dentry_unlock_parents_for_move(struct dentry *dentry, | 2452 | static void dentry_unlock_for_move(struct dentry *dentry, struct dentry *target) |
2447 | struct dentry *target) | ||
2448 | { | 2453 | { |
2449 | if (target->d_parent != dentry->d_parent) | 2454 | if (target->d_parent != dentry->d_parent) |
2450 | spin_unlock(&dentry->d_parent->d_lock); | 2455 | spin_unlock(&dentry->d_parent->d_lock); |
2451 | if (target->d_parent != target) | 2456 | if (target->d_parent != target) |
2452 | spin_unlock(&target->d_parent->d_lock); | 2457 | spin_unlock(&target->d_parent->d_lock); |
2458 | spin_unlock(&target->d_lock); | ||
2459 | spin_unlock(&dentry->d_lock); | ||
2453 | } | 2460 | } |
2454 | 2461 | ||
2455 | /* | 2462 | /* |
2456 | * When switching names, the actual string doesn't strictly have to | 2463 | * When switching names, the actual string doesn't strictly have to |
2457 | * be preserved in the target - because we're dropping the target | 2464 | * be preserved in the target - because we're dropping the target |
2458 | * anyway. As such, we can just do a simple memcpy() to copy over | 2465 | * anyway. As such, we can just do a simple memcpy() to copy over |
2459 | * the new name before we switch. | 2466 | * the new name before we switch, unless we are going to rehash |
2460 | * | 2467 | * it. Note that if we *do* unhash the target, we are not allowed |
2461 | * Note that we have to be a lot more careful about getting the hash | 2468 | * to rehash it without giving it a new name/hash key - whether |
2462 | * switched - we have to switch the hash value properly even if it | 2469 | * we swap or overwrite the names here, resulting name won't match |
2463 | * then no longer matches the actual (corrupted) string of the target. | 2470 | * the reality in filesystem; it's only there for d_path() purposes. |
2464 | * The hash value has to match the hash queue that the dentry is on.. | 2471 | * Note that all of this is happening under rename_lock, so the |
2472 | * any hash lookup seeing it in the middle of manipulations will | ||
2473 | * be discarded anyway. So we do not care what happens to the hash | ||
2474 | * key in that case. | ||
2465 | */ | 2475 | */ |
2466 | /* | 2476 | /* |
2467 | * __d_move - move a dentry | 2477 | * __d_move - move a dentry |
@@ -2507,36 +2517,30 @@ static void __d_move(struct dentry *dentry, struct dentry *target, | |||
2507 | d_hash(dentry->d_parent, dentry->d_name.hash)); | 2517 | d_hash(dentry->d_parent, dentry->d_name.hash)); |
2508 | } | 2518 | } |
2509 | 2519 | ||
2510 | list_del(&dentry->d_u.d_child); | ||
2511 | list_del(&target->d_u.d_child); | ||
2512 | |||
2513 | /* Switch the names.. */ | 2520 | /* Switch the names.. */ |
2514 | switch_names(dentry, target); | 2521 | switch_names(dentry, target, exchange); |
2515 | swap(dentry->d_name.hash, target->d_name.hash); | ||
2516 | 2522 | ||
2517 | /* ... and switch the parents */ | 2523 | /* ... and switch them in the tree */ |
2518 | if (IS_ROOT(dentry)) { | 2524 | if (IS_ROOT(dentry)) { |
2525 | /* splicing a tree */ | ||
2519 | dentry->d_parent = target->d_parent; | 2526 | dentry->d_parent = target->d_parent; |
2520 | target->d_parent = target; | 2527 | target->d_parent = target; |
2521 | INIT_LIST_HEAD(&target->d_u.d_child); | 2528 | list_del_init(&target->d_u.d_child); |
2529 | list_move(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); | ||
2522 | } else { | 2530 | } else { |
2531 | /* swapping two dentries */ | ||
2523 | swap(dentry->d_parent, target->d_parent); | 2532 | swap(dentry->d_parent, target->d_parent); |
2524 | 2533 | list_move(&target->d_u.d_child, &target->d_parent->d_subdirs); | |
2525 | /* And add them back to the (new) parent lists */ | 2534 | list_move(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); |
2526 | list_add(&target->d_u.d_child, &target->d_parent->d_subdirs); | 2535 | if (exchange) |
2536 | fsnotify_d_move(target); | ||
2537 | fsnotify_d_move(dentry); | ||
2527 | } | 2538 | } |
2528 | 2539 | ||
2529 | list_add(&dentry->d_u.d_child, &dentry->d_parent->d_subdirs); | ||
2530 | |||
2531 | write_seqcount_end(&target->d_seq); | 2540 | write_seqcount_end(&target->d_seq); |
2532 | write_seqcount_end(&dentry->d_seq); | 2541 | write_seqcount_end(&dentry->d_seq); |
2533 | 2542 | ||
2534 | dentry_unlock_parents_for_move(dentry, target); | 2543 | dentry_unlock_for_move(dentry, target); |
2535 | if (exchange) | ||
2536 | fsnotify_d_move(target); | ||
2537 | spin_unlock(&target->d_lock); | ||
2538 | fsnotify_d_move(dentry); | ||
2539 | spin_unlock(&dentry->d_lock); | ||
2540 | } | 2544 | } |
2541 | 2545 | ||
2542 | /* | 2546 | /* |
@@ -2634,39 +2638,6 @@ out_err: | |||
2634 | return ret; | 2638 | return ret; |
2635 | } | 2639 | } |
2636 | 2640 | ||
2637 | /* | ||
2638 | * Prepare an anonymous dentry for life in the superblock's dentry tree as a | ||
2639 | * named dentry in place of the dentry to be replaced. | ||
2640 | * returns with anon->d_lock held! | ||
2641 | */ | ||
2642 | static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon) | ||
2643 | { | ||
2644 | struct dentry *dparent; | ||
2645 | |||
2646 | dentry_lock_for_move(anon, dentry); | ||
2647 | |||
2648 | write_seqcount_begin(&dentry->d_seq); | ||
2649 | write_seqcount_begin_nested(&anon->d_seq, DENTRY_D_LOCK_NESTED); | ||
2650 | |||
2651 | dparent = dentry->d_parent; | ||
2652 | |||
2653 | switch_names(dentry, anon); | ||
2654 | swap(dentry->d_name.hash, anon->d_name.hash); | ||
2655 | |||
2656 | dentry->d_parent = dentry; | ||
2657 | list_del_init(&dentry->d_u.d_child); | ||
2658 | anon->d_parent = dparent; | ||
2659 | list_move(&anon->d_u.d_child, &dparent->d_subdirs); | ||
2660 | |||
2661 | write_seqcount_end(&dentry->d_seq); | ||
2662 | write_seqcount_end(&anon->d_seq); | ||
2663 | |||
2664 | dentry_unlock_parents_for_move(anon, dentry); | ||
2665 | spin_unlock(&dentry->d_lock); | ||
2666 | |||
2667 | /* anon->d_lock still locked, returns locked */ | ||
2668 | } | ||
2669 | |||
2670 | /** | 2641 | /** |
2671 | * d_splice_alias - splice a disconnected dentry into the tree if one exists | 2642 | * d_splice_alias - splice a disconnected dentry into the tree if one exists |
2672 | * @inode: the inode which may have a disconnected dentry | 2643 | * @inode: the inode which may have a disconnected dentry |
@@ -2712,11 +2683,8 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) | |||
2712 | return ERR_PTR(-EIO); | 2683 | return ERR_PTR(-EIO); |
2713 | } | 2684 | } |
2714 | write_seqlock(&rename_lock); | 2685 | write_seqlock(&rename_lock); |
2715 | __d_materialise_dentry(dentry, new); | 2686 | __d_move(new, dentry, false); |
2716 | write_sequnlock(&rename_lock); | 2687 | write_sequnlock(&rename_lock); |
2717 | __d_drop(new); | ||
2718 | _d_rehash(new); | ||
2719 | spin_unlock(&new->d_lock); | ||
2720 | spin_unlock(&inode->i_lock); | 2688 | spin_unlock(&inode->i_lock); |
2721 | security_d_instantiate(new, inode); | 2689 | security_d_instantiate(new, inode); |
2722 | iput(inode); | 2690 | iput(inode); |
@@ -2776,9 +2744,8 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode) | |||
2776 | } else if (IS_ROOT(alias)) { | 2744 | } else if (IS_ROOT(alias)) { |
2777 | /* Is this an anonymous mountpoint that we | 2745 | /* Is this an anonymous mountpoint that we |
2778 | * could splice into our tree? */ | 2746 | * could splice into our tree? */ |
2779 | __d_materialise_dentry(dentry, alias); | 2747 | __d_move(alias, dentry, false); |
2780 | write_sequnlock(&rename_lock); | 2748 | write_sequnlock(&rename_lock); |
2781 | __d_drop(alias); | ||
2782 | goto found; | 2749 | goto found; |
2783 | } else { | 2750 | } else { |
2784 | /* Nope, but we must(!) avoid directory | 2751 | /* Nope, but we must(!) avoid directory |
@@ -2804,13 +2771,9 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode) | |||
2804 | actual = __d_instantiate_unique(dentry, inode); | 2771 | actual = __d_instantiate_unique(dentry, inode); |
2805 | if (!actual) | 2772 | if (!actual) |
2806 | actual = dentry; | 2773 | actual = dentry; |
2807 | else | ||
2808 | BUG_ON(!d_unhashed(actual)); | ||
2809 | 2774 | ||
2810 | spin_lock(&actual->d_lock); | 2775 | d_rehash(actual); |
2811 | found: | 2776 | found: |
2812 | _d_rehash(actual); | ||
2813 | spin_unlock(&actual->d_lock); | ||
2814 | spin_unlock(&inode->i_lock); | 2777 | spin_unlock(&inode->i_lock); |
2815 | out_nolock: | 2778 | out_nolock: |
2816 | if (actual == dentry) { | 2779 | if (actual == dentry) { |
diff --git a/fs/direct-io.c b/fs/direct-io.c index c3116404ab49..e181b6b2e297 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c | |||
@@ -158,7 +158,7 @@ static inline int dio_refill_pages(struct dio *dio, struct dio_submit *sdio) | |||
158 | { | 158 | { |
159 | ssize_t ret; | 159 | ssize_t ret; |
160 | 160 | ||
161 | ret = iov_iter_get_pages(sdio->iter, dio->pages, DIO_PAGES, | 161 | ret = iov_iter_get_pages(sdio->iter, dio->pages, LONG_MAX, DIO_PAGES, |
162 | &sdio->from); | 162 | &sdio->from); |
163 | 163 | ||
164 | if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) { | 164 | if (ret < 0 && sdio->blocks_available && (dio->rw & WRITE)) { |
diff --git a/fs/eventpoll.c b/fs/eventpoll.c index b10b48c2a7af..7bcfff900f05 100644 --- a/fs/eventpoll.c +++ b/fs/eventpoll.c | |||
@@ -1852,7 +1852,8 @@ SYSCALL_DEFINE4(epoll_ctl, int, epfd, int, op, int, fd, | |||
1852 | goto error_tgt_fput; | 1852 | goto error_tgt_fput; |
1853 | 1853 | ||
1854 | /* Check if EPOLLWAKEUP is allowed */ | 1854 | /* Check if EPOLLWAKEUP is allowed */ |
1855 | ep_take_care_of_epollwakeup(&epds); | 1855 | if (ep_op_has_event(op)) |
1856 | ep_take_care_of_epollwakeup(&epds); | ||
1856 | 1857 | ||
1857 | /* | 1858 | /* |
1858 | * We have to check that the file structure underneath the file descriptor | 1859 | * We have to check that the file structure underneath the file descriptor |
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 90a3cdca3f88..603e4ebbd0ac 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -3240,6 +3240,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3240 | &new.de, &new.inlined); | 3240 | &new.de, &new.inlined); |
3241 | if (IS_ERR(new.bh)) { | 3241 | if (IS_ERR(new.bh)) { |
3242 | retval = PTR_ERR(new.bh); | 3242 | retval = PTR_ERR(new.bh); |
3243 | new.bh = NULL; | ||
3243 | goto end_rename; | 3244 | goto end_rename; |
3244 | } | 3245 | } |
3245 | if (new.bh) { | 3246 | if (new.bh) { |
@@ -3386,6 +3387,7 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry, | |||
3386 | &new.de, &new.inlined); | 3387 | &new.de, &new.inlined); |
3387 | if (IS_ERR(new.bh)) { | 3388 | if (IS_ERR(new.bh)) { |
3388 | retval = PTR_ERR(new.bh); | 3389 | retval = PTR_ERR(new.bh); |
3390 | new.bh = NULL; | ||
3389 | goto end_rename; | 3391 | goto end_rename; |
3390 | } | 3392 | } |
3391 | 3393 | ||
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index bb0e80f03e2e..1e43b905ff98 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c | |||
@@ -575,6 +575,7 @@ handle_bb: | |||
575 | bh = bclean(handle, sb, block); | 575 | bh = bclean(handle, sb, block); |
576 | if (IS_ERR(bh)) { | 576 | if (IS_ERR(bh)) { |
577 | err = PTR_ERR(bh); | 577 | err = PTR_ERR(bh); |
578 | bh = NULL; | ||
578 | goto out; | 579 | goto out; |
579 | } | 580 | } |
580 | overhead = ext4_group_overhead_blocks(sb, group); | 581 | overhead = ext4_group_overhead_blocks(sb, group); |
@@ -603,6 +604,7 @@ handle_ib: | |||
603 | bh = bclean(handle, sb, block); | 604 | bh = bclean(handle, sb, block); |
604 | if (IS_ERR(bh)) { | 605 | if (IS_ERR(bh)) { |
605 | err = PTR_ERR(bh); | 606 | err = PTR_ERR(bh); |
607 | bh = NULL; | ||
606 | goto out; | 608 | goto out; |
607 | } | 609 | } |
608 | 610 | ||
diff --git a/fs/f2fs/Kconfig b/fs/f2fs/Kconfig index 214fe1054fce..736a348509f7 100644 --- a/fs/f2fs/Kconfig +++ b/fs/f2fs/Kconfig | |||
@@ -23,7 +23,7 @@ config F2FS_STAT_FS | |||
23 | mounted as f2fs. Each file shows the whole f2fs information. | 23 | mounted as f2fs. Each file shows the whole f2fs information. |
24 | 24 | ||
25 | /sys/kernel/debug/f2fs/status includes: | 25 | /sys/kernel/debug/f2fs/status includes: |
26 | - major file system information managed by f2fs currently | 26 | - major filesystem information managed by f2fs currently |
27 | - average SIT information about whole segments | 27 | - average SIT information about whole segments |
28 | - current memory footprint consumed by f2fs. | 28 | - current memory footprint consumed by f2fs. |
29 | 29 | ||
@@ -68,6 +68,6 @@ config F2FS_CHECK_FS | |||
68 | bool "F2FS consistency checking feature" | 68 | bool "F2FS consistency checking feature" |
69 | depends on F2FS_FS | 69 | depends on F2FS_FS |
70 | help | 70 | help |
71 | Enables BUG_ONs which check the file system consistency in runtime. | 71 | Enables BUG_ONs which check the filesystem consistency in runtime. |
72 | 72 | ||
73 | If you want to improve the performance, say N. | 73 | If you want to improve the performance, say N. |
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 6aeed5bada52..ec3b7a5381fa 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c | |||
@@ -160,14 +160,11 @@ static int f2fs_write_meta_page(struct page *page, | |||
160 | goto redirty_out; | 160 | goto redirty_out; |
161 | if (wbc->for_reclaim) | 161 | if (wbc->for_reclaim) |
162 | goto redirty_out; | 162 | goto redirty_out; |
163 | 163 | if (unlikely(f2fs_cp_error(sbi))) | |
164 | /* Should not write any meta pages, if any IO error was occurred */ | 164 | goto redirty_out; |
165 | if (unlikely(is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ERROR_FLAG))) | ||
166 | goto no_write; | ||
167 | 165 | ||
168 | f2fs_wait_on_page_writeback(page, META); | 166 | f2fs_wait_on_page_writeback(page, META); |
169 | write_meta_page(sbi, page); | 167 | write_meta_page(sbi, page); |
170 | no_write: | ||
171 | dec_page_count(sbi, F2FS_DIRTY_META); | 168 | dec_page_count(sbi, F2FS_DIRTY_META); |
172 | unlock_page(page); | 169 | unlock_page(page); |
173 | return 0; | 170 | return 0; |
@@ -348,7 +345,7 @@ bool exist_written_data(struct f2fs_sb_info *sbi, nid_t ino, int mode) | |||
348 | return e ? true : false; | 345 | return e ? true : false; |
349 | } | 346 | } |
350 | 347 | ||
351 | static void release_dirty_inode(struct f2fs_sb_info *sbi) | 348 | void release_dirty_inode(struct f2fs_sb_info *sbi) |
352 | { | 349 | { |
353 | struct ino_entry *e, *tmp; | 350 | struct ino_entry *e, *tmp; |
354 | int i; | 351 | int i; |
@@ -446,8 +443,8 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) | |||
446 | struct f2fs_orphan_block *orphan_blk = NULL; | 443 | struct f2fs_orphan_block *orphan_blk = NULL; |
447 | unsigned int nentries = 0; | 444 | unsigned int nentries = 0; |
448 | unsigned short index; | 445 | unsigned short index; |
449 | unsigned short orphan_blocks = (unsigned short)((sbi->n_orphans + | 446 | unsigned short orphan_blocks = |
450 | (F2FS_ORPHANS_PER_BLOCK - 1)) / F2FS_ORPHANS_PER_BLOCK); | 447 | (unsigned short)GET_ORPHAN_BLOCKS(sbi->n_orphans); |
451 | struct page *page = NULL; | 448 | struct page *page = NULL; |
452 | struct ino_entry *orphan = NULL; | 449 | struct ino_entry *orphan = NULL; |
453 | 450 | ||
@@ -737,7 +734,7 @@ retry: | |||
737 | /* | 734 | /* |
738 | * Freeze all the FS-operations for checkpoint. | 735 | * Freeze all the FS-operations for checkpoint. |
739 | */ | 736 | */ |
740 | static void block_operations(struct f2fs_sb_info *sbi) | 737 | static int block_operations(struct f2fs_sb_info *sbi) |
741 | { | 738 | { |
742 | struct writeback_control wbc = { | 739 | struct writeback_control wbc = { |
743 | .sync_mode = WB_SYNC_ALL, | 740 | .sync_mode = WB_SYNC_ALL, |
@@ -745,6 +742,7 @@ static void block_operations(struct f2fs_sb_info *sbi) | |||
745 | .for_reclaim = 0, | 742 | .for_reclaim = 0, |
746 | }; | 743 | }; |
747 | struct blk_plug plug; | 744 | struct blk_plug plug; |
745 | int err = 0; | ||
748 | 746 | ||
749 | blk_start_plug(&plug); | 747 | blk_start_plug(&plug); |
750 | 748 | ||
@@ -754,11 +752,15 @@ retry_flush_dents: | |||
754 | if (get_pages(sbi, F2FS_DIRTY_DENTS)) { | 752 | if (get_pages(sbi, F2FS_DIRTY_DENTS)) { |
755 | f2fs_unlock_all(sbi); | 753 | f2fs_unlock_all(sbi); |
756 | sync_dirty_dir_inodes(sbi); | 754 | sync_dirty_dir_inodes(sbi); |
755 | if (unlikely(f2fs_cp_error(sbi))) { | ||
756 | err = -EIO; | ||
757 | goto out; | ||
758 | } | ||
757 | goto retry_flush_dents; | 759 | goto retry_flush_dents; |
758 | } | 760 | } |
759 | 761 | ||
760 | /* | 762 | /* |
761 | * POR: we should ensure that there is no dirty node pages | 763 | * POR: we should ensure that there are no dirty node pages |
762 | * until finishing nat/sit flush. | 764 | * until finishing nat/sit flush. |
763 | */ | 765 | */ |
764 | retry_flush_nodes: | 766 | retry_flush_nodes: |
@@ -767,9 +769,16 @@ retry_flush_nodes: | |||
767 | if (get_pages(sbi, F2FS_DIRTY_NODES)) { | 769 | if (get_pages(sbi, F2FS_DIRTY_NODES)) { |
768 | up_write(&sbi->node_write); | 770 | up_write(&sbi->node_write); |
769 | sync_node_pages(sbi, 0, &wbc); | 771 | sync_node_pages(sbi, 0, &wbc); |
772 | if (unlikely(f2fs_cp_error(sbi))) { | ||
773 | f2fs_unlock_all(sbi); | ||
774 | err = -EIO; | ||
775 | goto out; | ||
776 | } | ||
770 | goto retry_flush_nodes; | 777 | goto retry_flush_nodes; |
771 | } | 778 | } |
779 | out: | ||
772 | blk_finish_plug(&plug); | 780 | blk_finish_plug(&plug); |
781 | return err; | ||
773 | } | 782 | } |
774 | 783 | ||
775 | static void unblock_operations(struct f2fs_sb_info *sbi) | 784 | static void unblock_operations(struct f2fs_sb_info *sbi) |
@@ -813,8 +822,11 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
813 | discard_next_dnode(sbi, NEXT_FREE_BLKADDR(sbi, curseg)); | 822 | discard_next_dnode(sbi, NEXT_FREE_BLKADDR(sbi, curseg)); |
814 | 823 | ||
815 | /* Flush all the NAT/SIT pages */ | 824 | /* Flush all the NAT/SIT pages */ |
816 | while (get_pages(sbi, F2FS_DIRTY_META)) | 825 | while (get_pages(sbi, F2FS_DIRTY_META)) { |
817 | sync_meta_pages(sbi, META, LONG_MAX); | 826 | sync_meta_pages(sbi, META, LONG_MAX); |
827 | if (unlikely(f2fs_cp_error(sbi))) | ||
828 | return; | ||
829 | } | ||
818 | 830 | ||
819 | next_free_nid(sbi, &last_nid); | 831 | next_free_nid(sbi, &last_nid); |
820 | 832 | ||
@@ -825,7 +837,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
825 | ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi)); | 837 | ckpt->elapsed_time = cpu_to_le64(get_mtime(sbi)); |
826 | ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi)); | 838 | ckpt->valid_block_count = cpu_to_le64(valid_user_blocks(sbi)); |
827 | ckpt->free_segment_count = cpu_to_le32(free_segments(sbi)); | 839 | ckpt->free_segment_count = cpu_to_le32(free_segments(sbi)); |
828 | for (i = 0; i < 3; i++) { | 840 | for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) { |
829 | ckpt->cur_node_segno[i] = | 841 | ckpt->cur_node_segno[i] = |
830 | cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE)); | 842 | cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_NODE)); |
831 | ckpt->cur_node_blkoff[i] = | 843 | ckpt->cur_node_blkoff[i] = |
@@ -833,7 +845,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
833 | ckpt->alloc_type[i + CURSEG_HOT_NODE] = | 845 | ckpt->alloc_type[i + CURSEG_HOT_NODE] = |
834 | curseg_alloc_type(sbi, i + CURSEG_HOT_NODE); | 846 | curseg_alloc_type(sbi, i + CURSEG_HOT_NODE); |
835 | } | 847 | } |
836 | for (i = 0; i < 3; i++) { | 848 | for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) { |
837 | ckpt->cur_data_segno[i] = | 849 | ckpt->cur_data_segno[i] = |
838 | cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA)); | 850 | cpu_to_le32(curseg_segno(sbi, i + CURSEG_HOT_DATA)); |
839 | ckpt->cur_data_blkoff[i] = | 851 | ckpt->cur_data_blkoff[i] = |
@@ -848,24 +860,23 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
848 | 860 | ||
849 | /* 2 cp + n data seg summary + orphan inode blocks */ | 861 | /* 2 cp + n data seg summary + orphan inode blocks */ |
850 | data_sum_blocks = npages_for_summary_flush(sbi); | 862 | data_sum_blocks = npages_for_summary_flush(sbi); |
851 | if (data_sum_blocks < 3) | 863 | if (data_sum_blocks < NR_CURSEG_DATA_TYPE) |
852 | set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); | 864 | set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); |
853 | else | 865 | else |
854 | clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); | 866 | clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); |
855 | 867 | ||
856 | orphan_blocks = (sbi->n_orphans + F2FS_ORPHANS_PER_BLOCK - 1) | 868 | orphan_blocks = GET_ORPHAN_BLOCKS(sbi->n_orphans); |
857 | / F2FS_ORPHANS_PER_BLOCK; | ||
858 | ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks + | 869 | ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks + |
859 | orphan_blocks); | 870 | orphan_blocks); |
860 | 871 | ||
861 | if (is_umount) { | 872 | if (is_umount) { |
862 | set_ckpt_flags(ckpt, CP_UMOUNT_FLAG); | 873 | set_ckpt_flags(ckpt, CP_UMOUNT_FLAG); |
863 | ckpt->cp_pack_total_block_count = cpu_to_le32(2 + | 874 | ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS+ |
864 | cp_payload_blks + data_sum_blocks + | 875 | cp_payload_blks + data_sum_blocks + |
865 | orphan_blocks + NR_CURSEG_NODE_TYPE); | 876 | orphan_blocks + NR_CURSEG_NODE_TYPE); |
866 | } else { | 877 | } else { |
867 | clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG); | 878 | clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG); |
868 | ckpt->cp_pack_total_block_count = cpu_to_le32(2 + | 879 | ckpt->cp_pack_total_block_count = cpu_to_le32(F2FS_CP_PACKS + |
869 | cp_payload_blks + data_sum_blocks + | 880 | cp_payload_blks + data_sum_blocks + |
870 | orphan_blocks); | 881 | orphan_blocks); |
871 | } | 882 | } |
@@ -924,6 +935,9 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
924 | /* wait for previous submitted node/meta pages writeback */ | 935 | /* wait for previous submitted node/meta pages writeback */ |
925 | wait_on_all_pages_writeback(sbi); | 936 | wait_on_all_pages_writeback(sbi); |
926 | 937 | ||
938 | if (unlikely(f2fs_cp_error(sbi))) | ||
939 | return; | ||
940 | |||
927 | filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LONG_MAX); | 941 | filemap_fdatawait_range(NODE_MAPPING(sbi), 0, LONG_MAX); |
928 | filemap_fdatawait_range(META_MAPPING(sbi), 0, LONG_MAX); | 942 | filemap_fdatawait_range(META_MAPPING(sbi), 0, LONG_MAX); |
929 | 943 | ||
@@ -934,15 +948,17 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
934 | /* Here, we only have one bio having CP pack */ | 948 | /* Here, we only have one bio having CP pack */ |
935 | sync_meta_pages(sbi, META_FLUSH, LONG_MAX); | 949 | sync_meta_pages(sbi, META_FLUSH, LONG_MAX); |
936 | 950 | ||
937 | if (!is_set_ckpt_flags(ckpt, CP_ERROR_FLAG)) { | 951 | release_dirty_inode(sbi); |
938 | clear_prefree_segments(sbi); | 952 | |
939 | release_dirty_inode(sbi); | 953 | if (unlikely(f2fs_cp_error(sbi))) |
940 | F2FS_RESET_SB_DIRT(sbi); | 954 | return; |
941 | } | 955 | |
956 | clear_prefree_segments(sbi); | ||
957 | F2FS_RESET_SB_DIRT(sbi); | ||
942 | } | 958 | } |
943 | 959 | ||
944 | /* | 960 | /* |
945 | * We guarantee that this checkpoint procedure should not fail. | 961 | * We guarantee that this checkpoint procedure will not fail. |
946 | */ | 962 | */ |
947 | void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | 963 | void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) |
948 | { | 964 | { |
@@ -952,7 +968,13 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
952 | trace_f2fs_write_checkpoint(sbi->sb, is_umount, "start block_ops"); | 968 | trace_f2fs_write_checkpoint(sbi->sb, is_umount, "start block_ops"); |
953 | 969 | ||
954 | mutex_lock(&sbi->cp_mutex); | 970 | mutex_lock(&sbi->cp_mutex); |
955 | block_operations(sbi); | 971 | |
972 | if (!sbi->s_dirty) | ||
973 | goto out; | ||
974 | if (unlikely(f2fs_cp_error(sbi))) | ||
975 | goto out; | ||
976 | if (block_operations(sbi)) | ||
977 | goto out; | ||
956 | 978 | ||
957 | trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish block_ops"); | 979 | trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish block_ops"); |
958 | 980 | ||
@@ -976,9 +998,9 @@ void write_checkpoint(struct f2fs_sb_info *sbi, bool is_umount) | |||
976 | do_checkpoint(sbi, is_umount); | 998 | do_checkpoint(sbi, is_umount); |
977 | 999 | ||
978 | unblock_operations(sbi); | 1000 | unblock_operations(sbi); |
979 | mutex_unlock(&sbi->cp_mutex); | ||
980 | |||
981 | stat_inc_cp_count(sbi->stat_info); | 1001 | stat_inc_cp_count(sbi->stat_info); |
1002 | out: | ||
1003 | mutex_unlock(&sbi->cp_mutex); | ||
982 | trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish checkpoint"); | 1004 | trace_f2fs_write_checkpoint(sbi->sb, is_umount, "finish checkpoint"); |
983 | } | 1005 | } |
984 | 1006 | ||
@@ -999,8 +1021,8 @@ void init_ino_entry_info(struct f2fs_sb_info *sbi) | |||
999 | * for cp pack we can have max 1020*504 orphan entries | 1021 | * for cp pack we can have max 1020*504 orphan entries |
1000 | */ | 1022 | */ |
1001 | sbi->n_orphans = 0; | 1023 | sbi->n_orphans = 0; |
1002 | sbi->max_orphans = (sbi->blocks_per_seg - 2 - NR_CURSEG_TYPE) | 1024 | sbi->max_orphans = (sbi->blocks_per_seg - F2FS_CP_PACKS - |
1003 | * F2FS_ORPHANS_PER_BLOCK; | 1025 | NR_CURSEG_TYPE) * F2FS_ORPHANS_PER_BLOCK; |
1004 | } | 1026 | } |
1005 | 1027 | ||
1006 | int __init create_checkpoint_caches(void) | 1028 | int __init create_checkpoint_caches(void) |
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 03313099c51c..76de83e25a89 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c | |||
@@ -53,7 +53,7 @@ static void f2fs_write_end_io(struct bio *bio, int err) | |||
53 | struct page *page = bvec->bv_page; | 53 | struct page *page = bvec->bv_page; |
54 | 54 | ||
55 | if (unlikely(err)) { | 55 | if (unlikely(err)) { |
56 | SetPageError(page); | 56 | set_page_dirty(page); |
57 | set_bit(AS_EIO, &page->mapping->flags); | 57 | set_bit(AS_EIO, &page->mapping->flags); |
58 | f2fs_stop_checkpoint(sbi); | 58 | f2fs_stop_checkpoint(sbi); |
59 | } | 59 | } |
@@ -691,7 +691,7 @@ get_next: | |||
691 | allocated = true; | 691 | allocated = true; |
692 | blkaddr = dn.data_blkaddr; | 692 | blkaddr = dn.data_blkaddr; |
693 | } | 693 | } |
694 | /* Give more consecutive addresses for the read ahead */ | 694 | /* Give more consecutive addresses for the readahead */ |
695 | if (blkaddr == (bh_result->b_blocknr + ofs)) { | 695 | if (blkaddr == (bh_result->b_blocknr + ofs)) { |
696 | ofs++; | 696 | ofs++; |
697 | dn.ofs_in_node++; | 697 | dn.ofs_in_node++; |
@@ -739,7 +739,7 @@ static int f2fs_read_data_page(struct file *file, struct page *page) | |||
739 | 739 | ||
740 | trace_f2fs_readpage(page, DATA); | 740 | trace_f2fs_readpage(page, DATA); |
741 | 741 | ||
742 | /* If the file has inline data, try to read it directlly */ | 742 | /* If the file has inline data, try to read it directly */ |
743 | if (f2fs_has_inline_data(inode)) | 743 | if (f2fs_has_inline_data(inode)) |
744 | ret = f2fs_read_inline_data(inode, page); | 744 | ret = f2fs_read_inline_data(inode, page); |
745 | else | 745 | else |
@@ -836,10 +836,19 @@ write: | |||
836 | 836 | ||
837 | /* Dentry blocks are controlled by checkpoint */ | 837 | /* Dentry blocks are controlled by checkpoint */ |
838 | if (S_ISDIR(inode->i_mode)) { | 838 | if (S_ISDIR(inode->i_mode)) { |
839 | if (unlikely(f2fs_cp_error(sbi))) | ||
840 | goto redirty_out; | ||
839 | err = do_write_data_page(page, &fio); | 841 | err = do_write_data_page(page, &fio); |
840 | goto done; | 842 | goto done; |
841 | } | 843 | } |
842 | 844 | ||
845 | /* we should bypass data pages to proceed the kworkder jobs */ | ||
846 | if (unlikely(f2fs_cp_error(sbi))) { | ||
847 | SetPageError(page); | ||
848 | unlock_page(page); | ||
849 | return 0; | ||
850 | } | ||
851 | |||
843 | if (!wbc->for_reclaim) | 852 | if (!wbc->for_reclaim) |
844 | need_balance_fs = true; | 853 | need_balance_fs = true; |
845 | else if (has_not_enough_free_secs(sbi, 0)) | 854 | else if (has_not_enough_free_secs(sbi, 0)) |
@@ -927,7 +936,7 @@ static void f2fs_write_failed(struct address_space *mapping, loff_t to) | |||
927 | 936 | ||
928 | if (to > inode->i_size) { | 937 | if (to > inode->i_size) { |
929 | truncate_pagecache(inode, inode->i_size); | 938 | truncate_pagecache(inode, inode->i_size); |
930 | truncate_blocks(inode, inode->i_size); | 939 | truncate_blocks(inode, inode->i_size, true); |
931 | } | 940 | } |
932 | } | 941 | } |
933 | 942 | ||
@@ -946,7 +955,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, | |||
946 | 955 | ||
947 | f2fs_balance_fs(sbi); | 956 | f2fs_balance_fs(sbi); |
948 | repeat: | 957 | repeat: |
949 | err = f2fs_convert_inline_data(inode, pos + len); | 958 | err = f2fs_convert_inline_data(inode, pos + len, NULL); |
950 | if (err) | 959 | if (err) |
951 | goto fail; | 960 | goto fail; |
952 | 961 | ||
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index a441ba33be11..fecebdbfd781 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c | |||
@@ -32,7 +32,7 @@ static void update_general_status(struct f2fs_sb_info *sbi) | |||
32 | struct f2fs_stat_info *si = F2FS_STAT(sbi); | 32 | struct f2fs_stat_info *si = F2FS_STAT(sbi); |
33 | int i; | 33 | int i; |
34 | 34 | ||
35 | /* valid check of the segment numbers */ | 35 | /* validation check of the segment numbers */ |
36 | si->hit_ext = sbi->read_hit_ext; | 36 | si->hit_ext = sbi->read_hit_ext; |
37 | si->total_ext = sbi->total_hit_ext; | 37 | si->total_ext = sbi->total_hit_ext; |
38 | si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES); | 38 | si->ndirty_node = get_pages(sbi, F2FS_DIRTY_NODES); |
@@ -152,7 +152,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) | |||
152 | si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(TOTAL_SEGS(sbi)); | 152 | si->base_mem += NR_DIRTY_TYPE * f2fs_bitmap_size(TOTAL_SEGS(sbi)); |
153 | si->base_mem += f2fs_bitmap_size(TOTAL_SECS(sbi)); | 153 | si->base_mem += f2fs_bitmap_size(TOTAL_SECS(sbi)); |
154 | 154 | ||
155 | /* buld nm */ | 155 | /* build nm */ |
156 | si->base_mem += sizeof(struct f2fs_nm_info); | 156 | si->base_mem += sizeof(struct f2fs_nm_info); |
157 | si->base_mem += __bitmap_size(sbi, NAT_BITMAP); | 157 | si->base_mem += __bitmap_size(sbi, NAT_BITMAP); |
158 | 158 | ||
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index bcf893c3d903..155fb056b7f1 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c | |||
@@ -124,7 +124,7 @@ static struct f2fs_dir_entry *find_in_block(struct page *dentry_page, | |||
124 | 124 | ||
125 | /* | 125 | /* |
126 | * For the most part, it should be a bug when name_len is zero. | 126 | * For the most part, it should be a bug when name_len is zero. |
127 | * We stop here for figuring out where the bugs are occurred. | 127 | * We stop here for figuring out where the bugs has occurred. |
128 | */ | 128 | */ |
129 | f2fs_bug_on(!de->name_len); | 129 | f2fs_bug_on(!de->name_len); |
130 | 130 | ||
@@ -391,7 +391,7 @@ put_error: | |||
391 | error: | 391 | error: |
392 | /* once the failed inode becomes a bad inode, i_mode is S_IFREG */ | 392 | /* once the failed inode becomes a bad inode, i_mode is S_IFREG */ |
393 | truncate_inode_pages(&inode->i_data, 0); | 393 | truncate_inode_pages(&inode->i_data, 0); |
394 | truncate_blocks(inode, 0); | 394 | truncate_blocks(inode, 0, false); |
395 | remove_dirty_dir_inode(inode); | 395 | remove_dirty_dir_inode(inode); |
396 | remove_inode_page(inode); | 396 | remove_inode_page(inode); |
397 | return ERR_PTR(err); | 397 | return ERR_PTR(err); |
@@ -563,7 +563,7 @@ fail: | |||
563 | } | 563 | } |
564 | 564 | ||
565 | /* | 565 | /* |
566 | * It only removes the dentry from the dentry page,corresponding name | 566 | * It only removes the dentry from the dentry page, corresponding name |
567 | * entry in name page does not need to be touched during deletion. | 567 | * entry in name page does not need to be touched during deletion. |
568 | */ | 568 | */ |
569 | void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, | 569 | void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page, |
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 4dab5338a97a..e921242186f6 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -24,7 +24,7 @@ | |||
24 | #define f2fs_bug_on(condition) BUG_ON(condition) | 24 | #define f2fs_bug_on(condition) BUG_ON(condition) |
25 | #define f2fs_down_write(x, y) down_write_nest_lock(x, y) | 25 | #define f2fs_down_write(x, y) down_write_nest_lock(x, y) |
26 | #else | 26 | #else |
27 | #define f2fs_bug_on(condition) | 27 | #define f2fs_bug_on(condition) WARN_ON(condition) |
28 | #define f2fs_down_write(x, y) down_write(x) | 28 | #define f2fs_down_write(x, y) down_write(x) |
29 | #endif | 29 | #endif |
30 | 30 | ||
@@ -395,7 +395,7 @@ enum count_type { | |||
395 | }; | 395 | }; |
396 | 396 | ||
397 | /* | 397 | /* |
398 | * The below are the page types of bios used in submti_bio(). | 398 | * The below are the page types of bios used in submit_bio(). |
399 | * The available types are: | 399 | * The available types are: |
400 | * DATA User data pages. It operates as async mode. | 400 | * DATA User data pages. It operates as async mode. |
401 | * NODE Node pages. It operates as async mode. | 401 | * NODE Node pages. It operates as async mode. |
@@ -470,7 +470,7 @@ struct f2fs_sb_info { | |||
470 | struct list_head dir_inode_list; /* dir inode list */ | 470 | struct list_head dir_inode_list; /* dir inode list */ |
471 | spinlock_t dir_inode_lock; /* for dir inode list lock */ | 471 | spinlock_t dir_inode_lock; /* for dir inode list lock */ |
472 | 472 | ||
473 | /* basic file system units */ | 473 | /* basic filesystem units */ |
474 | unsigned int log_sectors_per_block; /* log2 sectors per block */ | 474 | unsigned int log_sectors_per_block; /* log2 sectors per block */ |
475 | unsigned int log_blocksize; /* log2 block size */ | 475 | unsigned int log_blocksize; /* log2 block size */ |
476 | unsigned int blocksize; /* block size */ | 476 | unsigned int blocksize; /* block size */ |
@@ -799,7 +799,7 @@ static inline block_t __start_cp_addr(struct f2fs_sb_info *sbi) | |||
799 | 799 | ||
800 | /* | 800 | /* |
801 | * odd numbered checkpoint should at cp segment 0 | 801 | * odd numbered checkpoint should at cp segment 0 |
802 | * and even segent must be at cp segment 1 | 802 | * and even segment must be at cp segment 1 |
803 | */ | 803 | */ |
804 | if (!(ckpt_version & 1)) | 804 | if (!(ckpt_version & 1)) |
805 | start_addr += sbi->blocks_per_seg; | 805 | start_addr += sbi->blocks_per_seg; |
@@ -1096,6 +1096,11 @@ static inline int f2fs_readonly(struct super_block *sb) | |||
1096 | return sb->s_flags & MS_RDONLY; | 1096 | return sb->s_flags & MS_RDONLY; |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | static inline bool f2fs_cp_error(struct f2fs_sb_info *sbi) | ||
1100 | { | ||
1101 | return is_set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); | ||
1102 | } | ||
1103 | |||
1099 | static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) | 1104 | static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) |
1100 | { | 1105 | { |
1101 | set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); | 1106 | set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); |
@@ -1117,7 +1122,7 @@ static inline void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi) | |||
1117 | */ | 1122 | */ |
1118 | int f2fs_sync_file(struct file *, loff_t, loff_t, int); | 1123 | int f2fs_sync_file(struct file *, loff_t, loff_t, int); |
1119 | void truncate_data_blocks(struct dnode_of_data *); | 1124 | void truncate_data_blocks(struct dnode_of_data *); |
1120 | int truncate_blocks(struct inode *, u64); | 1125 | int truncate_blocks(struct inode *, u64, bool); |
1121 | void f2fs_truncate(struct inode *); | 1126 | void f2fs_truncate(struct inode *); |
1122 | int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); | 1127 | int f2fs_getattr(struct vfsmount *, struct dentry *, struct kstat *); |
1123 | int f2fs_setattr(struct dentry *, struct iattr *); | 1128 | int f2fs_setattr(struct dentry *, struct iattr *); |
@@ -1202,10 +1207,8 @@ int sync_node_pages(struct f2fs_sb_info *, nid_t, struct writeback_control *); | |||
1202 | bool alloc_nid(struct f2fs_sb_info *, nid_t *); | 1207 | bool alloc_nid(struct f2fs_sb_info *, nid_t *); |
1203 | void alloc_nid_done(struct f2fs_sb_info *, nid_t); | 1208 | void alloc_nid_done(struct f2fs_sb_info *, nid_t); |
1204 | void alloc_nid_failed(struct f2fs_sb_info *, nid_t); | 1209 | void alloc_nid_failed(struct f2fs_sb_info *, nid_t); |
1205 | void recover_node_page(struct f2fs_sb_info *, struct page *, | ||
1206 | struct f2fs_summary *, struct node_info *, block_t); | ||
1207 | void recover_inline_xattr(struct inode *, struct page *); | 1210 | void recover_inline_xattr(struct inode *, struct page *); |
1208 | bool recover_xattr_data(struct inode *, struct page *, block_t); | 1211 | void recover_xattr_data(struct inode *, struct page *, block_t); |
1209 | int recover_inode_page(struct f2fs_sb_info *, struct page *); | 1212 | int recover_inode_page(struct f2fs_sb_info *, struct page *); |
1210 | int restore_node_summary(struct f2fs_sb_info *, unsigned int, | 1213 | int restore_node_summary(struct f2fs_sb_info *, unsigned int, |
1211 | struct f2fs_summary_block *); | 1214 | struct f2fs_summary_block *); |
@@ -1238,8 +1241,6 @@ void write_data_page(struct page *, struct dnode_of_data *, block_t *, | |||
1238 | void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *); | 1241 | void rewrite_data_page(struct page *, block_t, struct f2fs_io_info *); |
1239 | void recover_data_page(struct f2fs_sb_info *, struct page *, | 1242 | void recover_data_page(struct f2fs_sb_info *, struct page *, |
1240 | struct f2fs_summary *, block_t, block_t); | 1243 | struct f2fs_summary *, block_t, block_t); |
1241 | void rewrite_node_page(struct f2fs_sb_info *, struct page *, | ||
1242 | struct f2fs_summary *, block_t, block_t); | ||
1243 | void allocate_data_block(struct f2fs_sb_info *, struct page *, | 1244 | void allocate_data_block(struct f2fs_sb_info *, struct page *, |
1244 | block_t, block_t *, struct f2fs_summary *, int); | 1245 | block_t, block_t *, struct f2fs_summary *, int); |
1245 | void f2fs_wait_on_page_writeback(struct page *, enum page_type); | 1246 | void f2fs_wait_on_page_writeback(struct page *, enum page_type); |
@@ -1262,6 +1263,7 @@ int ra_meta_pages(struct f2fs_sb_info *, int, int, int); | |||
1262 | long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); | 1263 | long sync_meta_pages(struct f2fs_sb_info *, enum page_type, long); |
1263 | void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); | 1264 | void add_dirty_inode(struct f2fs_sb_info *, nid_t, int type); |
1264 | void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); | 1265 | void remove_dirty_inode(struct f2fs_sb_info *, nid_t, int type); |
1266 | void release_dirty_inode(struct f2fs_sb_info *); | ||
1265 | bool exist_written_data(struct f2fs_sb_info *, nid_t, int); | 1267 | bool exist_written_data(struct f2fs_sb_info *, nid_t, int); |
1266 | int acquire_orphan_inode(struct f2fs_sb_info *); | 1268 | int acquire_orphan_inode(struct f2fs_sb_info *); |
1267 | void release_orphan_inode(struct f2fs_sb_info *); | 1269 | void release_orphan_inode(struct f2fs_sb_info *); |
@@ -1439,8 +1441,8 @@ extern const struct inode_operations f2fs_special_inode_operations; | |||
1439 | */ | 1441 | */ |
1440 | bool f2fs_may_inline(struct inode *); | 1442 | bool f2fs_may_inline(struct inode *); |
1441 | int f2fs_read_inline_data(struct inode *, struct page *); | 1443 | int f2fs_read_inline_data(struct inode *, struct page *); |
1442 | int f2fs_convert_inline_data(struct inode *, pgoff_t); | 1444 | int f2fs_convert_inline_data(struct inode *, pgoff_t, struct page *); |
1443 | int f2fs_write_inline_data(struct inode *, struct page *, unsigned int); | 1445 | int f2fs_write_inline_data(struct inode *, struct page *, unsigned int); |
1444 | void truncate_inline_data(struct inode *, u64); | 1446 | void truncate_inline_data(struct inode *, u64); |
1445 | int recover_inline_data(struct inode *, struct page *); | 1447 | bool recover_inline_data(struct inode *, struct page *); |
1446 | #endif | 1448 | #endif |
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 208f1a9bd569..060aee65aee8 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c | |||
@@ -41,6 +41,11 @@ static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma, | |||
41 | 41 | ||
42 | sb_start_pagefault(inode->i_sb); | 42 | sb_start_pagefault(inode->i_sb); |
43 | 43 | ||
44 | /* force to convert with normal data indices */ | ||
45 | err = f2fs_convert_inline_data(inode, MAX_INLINE_DATA + 1, page); | ||
46 | if (err) | ||
47 | goto out; | ||
48 | |||
44 | /* block allocation */ | 49 | /* block allocation */ |
45 | f2fs_lock_op(sbi); | 50 | f2fs_lock_op(sbi); |
46 | set_new_dnode(&dn, inode, NULL, NULL, 0); | 51 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
@@ -110,6 +115,25 @@ static int get_parent_ino(struct inode *inode, nid_t *pino) | |||
110 | return 1; | 115 | return 1; |
111 | } | 116 | } |
112 | 117 | ||
118 | static inline bool need_do_checkpoint(struct inode *inode) | ||
119 | { | ||
120 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | ||
121 | bool need_cp = false; | ||
122 | |||
123 | if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) | ||
124 | need_cp = true; | ||
125 | else if (file_wrong_pino(inode)) | ||
126 | need_cp = true; | ||
127 | else if (!space_for_roll_forward(sbi)) | ||
128 | need_cp = true; | ||
129 | else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino)) | ||
130 | need_cp = true; | ||
131 | else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi))) | ||
132 | need_cp = true; | ||
133 | |||
134 | return need_cp; | ||
135 | } | ||
136 | |||
113 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | 137 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) |
114 | { | 138 | { |
115 | struct inode *inode = file->f_mapping->host; | 139 | struct inode *inode = file->f_mapping->host; |
@@ -154,23 +178,12 @@ int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) | |||
154 | /* guarantee free sections for fsync */ | 178 | /* guarantee free sections for fsync */ |
155 | f2fs_balance_fs(sbi); | 179 | f2fs_balance_fs(sbi); |
156 | 180 | ||
157 | down_read(&fi->i_sem); | ||
158 | |||
159 | /* | 181 | /* |
160 | * Both of fdatasync() and fsync() are able to be recovered from | 182 | * Both of fdatasync() and fsync() are able to be recovered from |
161 | * sudden-power-off. | 183 | * sudden-power-off. |
162 | */ | 184 | */ |
163 | if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) | 185 | down_read(&fi->i_sem); |
164 | need_cp = true; | 186 | need_cp = need_do_checkpoint(inode); |
165 | else if (file_wrong_pino(inode)) | ||
166 | need_cp = true; | ||
167 | else if (!space_for_roll_forward(sbi)) | ||
168 | need_cp = true; | ||
169 | else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino)) | ||
170 | need_cp = true; | ||
171 | else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi))) | ||
172 | need_cp = true; | ||
173 | |||
174 | up_read(&fi->i_sem); | 187 | up_read(&fi->i_sem); |
175 | 188 | ||
176 | if (need_cp) { | 189 | if (need_cp) { |
@@ -288,7 +301,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) | |||
288 | if (err && err != -ENOENT) { | 301 | if (err && err != -ENOENT) { |
289 | goto fail; | 302 | goto fail; |
290 | } else if (err == -ENOENT) { | 303 | } else if (err == -ENOENT) { |
291 | /* direct node is not exist */ | 304 | /* direct node does not exists */ |
292 | if (whence == SEEK_DATA) { | 305 | if (whence == SEEK_DATA) { |
293 | pgofs = PGOFS_OF_NEXT_DNODE(pgofs, | 306 | pgofs = PGOFS_OF_NEXT_DNODE(pgofs, |
294 | F2FS_I(inode)); | 307 | F2FS_I(inode)); |
@@ -417,7 +430,7 @@ out: | |||
417 | f2fs_put_page(page, 1); | 430 | f2fs_put_page(page, 1); |
418 | } | 431 | } |
419 | 432 | ||
420 | int truncate_blocks(struct inode *inode, u64 from) | 433 | int truncate_blocks(struct inode *inode, u64 from, bool lock) |
421 | { | 434 | { |
422 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 435 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); |
423 | unsigned int blocksize = inode->i_sb->s_blocksize; | 436 | unsigned int blocksize = inode->i_sb->s_blocksize; |
@@ -433,14 +446,16 @@ int truncate_blocks(struct inode *inode, u64 from) | |||
433 | free_from = (pgoff_t) | 446 | free_from = (pgoff_t) |
434 | ((from + blocksize - 1) >> (sbi->log_blocksize)); | 447 | ((from + blocksize - 1) >> (sbi->log_blocksize)); |
435 | 448 | ||
436 | f2fs_lock_op(sbi); | 449 | if (lock) |
450 | f2fs_lock_op(sbi); | ||
437 | 451 | ||
438 | set_new_dnode(&dn, inode, NULL, NULL, 0); | 452 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
439 | err = get_dnode_of_data(&dn, free_from, LOOKUP_NODE); | 453 | err = get_dnode_of_data(&dn, free_from, LOOKUP_NODE); |
440 | if (err) { | 454 | if (err) { |
441 | if (err == -ENOENT) | 455 | if (err == -ENOENT) |
442 | goto free_next; | 456 | goto free_next; |
443 | f2fs_unlock_op(sbi); | 457 | if (lock) |
458 | f2fs_unlock_op(sbi); | ||
444 | trace_f2fs_truncate_blocks_exit(inode, err); | 459 | trace_f2fs_truncate_blocks_exit(inode, err); |
445 | return err; | 460 | return err; |
446 | } | 461 | } |
@@ -458,7 +473,8 @@ int truncate_blocks(struct inode *inode, u64 from) | |||
458 | f2fs_put_dnode(&dn); | 473 | f2fs_put_dnode(&dn); |
459 | free_next: | 474 | free_next: |
460 | err = truncate_inode_blocks(inode, free_from); | 475 | err = truncate_inode_blocks(inode, free_from); |
461 | f2fs_unlock_op(sbi); | 476 | if (lock) |
477 | f2fs_unlock_op(sbi); | ||
462 | done: | 478 | done: |
463 | /* lastly zero out the first data page */ | 479 | /* lastly zero out the first data page */ |
464 | truncate_partial_data_page(inode, from); | 480 | truncate_partial_data_page(inode, from); |
@@ -475,7 +491,7 @@ void f2fs_truncate(struct inode *inode) | |||
475 | 491 | ||
476 | trace_f2fs_truncate(inode); | 492 | trace_f2fs_truncate(inode); |
477 | 493 | ||
478 | if (!truncate_blocks(inode, i_size_read(inode))) { | 494 | if (!truncate_blocks(inode, i_size_read(inode), true)) { |
479 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; | 495 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
480 | mark_inode_dirty(inode); | 496 | mark_inode_dirty(inode); |
481 | } | 497 | } |
@@ -533,7 +549,7 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr) | |||
533 | 549 | ||
534 | if ((attr->ia_valid & ATTR_SIZE) && | 550 | if ((attr->ia_valid & ATTR_SIZE) && |
535 | attr->ia_size != i_size_read(inode)) { | 551 | attr->ia_size != i_size_read(inode)) { |
536 | err = f2fs_convert_inline_data(inode, attr->ia_size); | 552 | err = f2fs_convert_inline_data(inode, attr->ia_size, NULL); |
537 | if (err) | 553 | if (err) |
538 | return err; | 554 | return err; |
539 | 555 | ||
@@ -622,7 +638,7 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len) | |||
622 | loff_t off_start, off_end; | 638 | loff_t off_start, off_end; |
623 | int ret = 0; | 639 | int ret = 0; |
624 | 640 | ||
625 | ret = f2fs_convert_inline_data(inode, MAX_INLINE_DATA + 1); | 641 | ret = f2fs_convert_inline_data(inode, MAX_INLINE_DATA + 1, NULL); |
626 | if (ret) | 642 | if (ret) |
627 | return ret; | 643 | return ret; |
628 | 644 | ||
@@ -678,7 +694,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset, | |||
678 | if (ret) | 694 | if (ret) |
679 | return ret; | 695 | return ret; |
680 | 696 | ||
681 | ret = f2fs_convert_inline_data(inode, offset + len); | 697 | ret = f2fs_convert_inline_data(inode, offset + len, NULL); |
682 | if (ret) | 698 | if (ret) |
683 | return ret; | 699 | return ret; |
684 | 700 | ||
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index d7947d90ccc3..943a31db7cc3 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c | |||
@@ -58,7 +58,7 @@ static int gc_thread_func(void *data) | |||
58 | * 3. IO subsystem is idle by checking the # of requests in | 58 | * 3. IO subsystem is idle by checking the # of requests in |
59 | * bdev's request list. | 59 | * bdev's request list. |
60 | * | 60 | * |
61 | * Note) We have to avoid triggering GCs too much frequently. | 61 | * Note) We have to avoid triggering GCs frequently. |
62 | * Because it is possible that some segments can be | 62 | * Because it is possible that some segments can be |
63 | * invalidated soon after by user update or deletion. | 63 | * invalidated soon after by user update or deletion. |
64 | * So, I'd like to wait some time to collect dirty segments. | 64 | * So, I'd like to wait some time to collect dirty segments. |
@@ -222,7 +222,7 @@ static unsigned int get_cb_cost(struct f2fs_sb_info *sbi, unsigned int segno) | |||
222 | 222 | ||
223 | u = (vblocks * 100) >> sbi->log_blocks_per_seg; | 223 | u = (vblocks * 100) >> sbi->log_blocks_per_seg; |
224 | 224 | ||
225 | /* Handle if the system time is changed by user */ | 225 | /* Handle if the system time has changed by the user */ |
226 | if (mtime < sit_i->min_mtime) | 226 | if (mtime < sit_i->min_mtime) |
227 | sit_i->min_mtime = mtime; | 227 | sit_i->min_mtime = mtime; |
228 | if (mtime > sit_i->max_mtime) | 228 | if (mtime > sit_i->max_mtime) |
@@ -593,7 +593,7 @@ next_step: | |||
593 | 593 | ||
594 | if (phase == 2) { | 594 | if (phase == 2) { |
595 | inode = f2fs_iget(sb, dni.ino); | 595 | inode = f2fs_iget(sb, dni.ino); |
596 | if (IS_ERR(inode)) | 596 | if (IS_ERR(inode) || is_bad_inode(inode)) |
597 | continue; | 597 | continue; |
598 | 598 | ||
599 | start_bidx = start_bidx_of_node(nofs, F2FS_I(inode)); | 599 | start_bidx = start_bidx_of_node(nofs, F2FS_I(inode)); |
@@ -693,7 +693,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi) | |||
693 | gc_more: | 693 | gc_more: |
694 | if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) | 694 | if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) |
695 | goto stop; | 695 | goto stop; |
696 | if (unlikely(is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ERROR_FLAG))) | 696 | if (unlikely(f2fs_cp_error(sbi))) |
697 | goto stop; | 697 | goto stop; |
698 | 698 | ||
699 | if (gc_type == BG_GC && has_not_enough_free_secs(sbi, nfree)) { | 699 | if (gc_type == BG_GC && has_not_enough_free_secs(sbi, nfree)) { |
diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h index 5d5eb6047bf4..16f0b2b22999 100644 --- a/fs/f2fs/gc.h +++ b/fs/f2fs/gc.h | |||
@@ -91,7 +91,7 @@ static inline bool has_enough_invalid_blocks(struct f2fs_sb_info *sbi) | |||
91 | block_t invalid_user_blocks = sbi->user_block_count - | 91 | block_t invalid_user_blocks = sbi->user_block_count - |
92 | written_block_count(sbi); | 92 | written_block_count(sbi); |
93 | /* | 93 | /* |
94 | * Background GC is triggered with the following condition. | 94 | * Background GC is triggered with the following conditions. |
95 | * 1. There are a number of invalid blocks. | 95 | * 1. There are a number of invalid blocks. |
96 | * 2. There is not enough free space. | 96 | * 2. There is not enough free space. |
97 | */ | 97 | */ |
diff --git a/fs/f2fs/hash.c b/fs/f2fs/hash.c index 948d17bf7281..a844fcfb9a8d 100644 --- a/fs/f2fs/hash.c +++ b/fs/f2fs/hash.c | |||
@@ -42,7 +42,8 @@ static void TEA_transform(unsigned int buf[4], unsigned int const in[]) | |||
42 | buf[1] += b1; | 42 | buf[1] += b1; |
43 | } | 43 | } |
44 | 44 | ||
45 | static void str2hashbuf(const char *msg, size_t len, unsigned int *buf, int num) | 45 | static void str2hashbuf(const unsigned char *msg, size_t len, |
46 | unsigned int *buf, int num) | ||
46 | { | 47 | { |
47 | unsigned pad, val; | 48 | unsigned pad, val; |
48 | int i; | 49 | int i; |
@@ -73,9 +74,9 @@ f2fs_hash_t f2fs_dentry_hash(const struct qstr *name_info) | |||
73 | { | 74 | { |
74 | __u32 hash; | 75 | __u32 hash; |
75 | f2fs_hash_t f2fs_hash; | 76 | f2fs_hash_t f2fs_hash; |
76 | const char *p; | 77 | const unsigned char *p; |
77 | __u32 in[8], buf[4]; | 78 | __u32 in[8], buf[4]; |
78 | const char *name = name_info->name; | 79 | const unsigned char *name = name_info->name; |
79 | size_t len = name_info->len; | 80 | size_t len = name_info->len; |
80 | 81 | ||
81 | if ((len <= 2) && (name[0] == '.') && | 82 | if ((len <= 2) && (name[0] == '.') && |
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 5beeccef9ae1..3e8ecdf3742b 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c | |||
@@ -68,7 +68,7 @@ out: | |||
68 | 68 | ||
69 | static int __f2fs_convert_inline_data(struct inode *inode, struct page *page) | 69 | static int __f2fs_convert_inline_data(struct inode *inode, struct page *page) |
70 | { | 70 | { |
71 | int err; | 71 | int err = 0; |
72 | struct page *ipage; | 72 | struct page *ipage; |
73 | struct dnode_of_data dn; | 73 | struct dnode_of_data dn; |
74 | void *src_addr, *dst_addr; | 74 | void *src_addr, *dst_addr; |
@@ -86,6 +86,10 @@ static int __f2fs_convert_inline_data(struct inode *inode, struct page *page) | |||
86 | goto out; | 86 | goto out; |
87 | } | 87 | } |
88 | 88 | ||
89 | /* someone else converted inline_data already */ | ||
90 | if (!f2fs_has_inline_data(inode)) | ||
91 | goto out; | ||
92 | |||
89 | /* | 93 | /* |
90 | * i_addr[0] is not used for inline data, | 94 | * i_addr[0] is not used for inline data, |
91 | * so reserving new block will not destroy inline data | 95 | * so reserving new block will not destroy inline data |
@@ -124,9 +128,10 @@ out: | |||
124 | return err; | 128 | return err; |
125 | } | 129 | } |
126 | 130 | ||
127 | int f2fs_convert_inline_data(struct inode *inode, pgoff_t to_size) | 131 | int f2fs_convert_inline_data(struct inode *inode, pgoff_t to_size, |
132 | struct page *page) | ||
128 | { | 133 | { |
129 | struct page *page; | 134 | struct page *new_page = page; |
130 | int err; | 135 | int err; |
131 | 136 | ||
132 | if (!f2fs_has_inline_data(inode)) | 137 | if (!f2fs_has_inline_data(inode)) |
@@ -134,17 +139,20 @@ int f2fs_convert_inline_data(struct inode *inode, pgoff_t to_size) | |||
134 | else if (to_size <= MAX_INLINE_DATA) | 139 | else if (to_size <= MAX_INLINE_DATA) |
135 | return 0; | 140 | return 0; |
136 | 141 | ||
137 | page = grab_cache_page(inode->i_mapping, 0); | 142 | if (!page || page->index != 0) { |
138 | if (!page) | 143 | new_page = grab_cache_page(inode->i_mapping, 0); |
139 | return -ENOMEM; | 144 | if (!new_page) |
145 | return -ENOMEM; | ||
146 | } | ||
140 | 147 | ||
141 | err = __f2fs_convert_inline_data(inode, page); | 148 | err = __f2fs_convert_inline_data(inode, new_page); |
142 | f2fs_put_page(page, 1); | 149 | if (!page || page->index != 0) |
150 | f2fs_put_page(new_page, 1); | ||
143 | return err; | 151 | return err; |
144 | } | 152 | } |
145 | 153 | ||
146 | int f2fs_write_inline_data(struct inode *inode, | 154 | int f2fs_write_inline_data(struct inode *inode, |
147 | struct page *page, unsigned size) | 155 | struct page *page, unsigned size) |
148 | { | 156 | { |
149 | void *src_addr, *dst_addr; | 157 | void *src_addr, *dst_addr; |
150 | struct page *ipage; | 158 | struct page *ipage; |
@@ -199,7 +207,7 @@ void truncate_inline_data(struct inode *inode, u64 from) | |||
199 | f2fs_put_page(ipage, 1); | 207 | f2fs_put_page(ipage, 1); |
200 | } | 208 | } |
201 | 209 | ||
202 | int recover_inline_data(struct inode *inode, struct page *npage) | 210 | bool recover_inline_data(struct inode *inode, struct page *npage) |
203 | { | 211 | { |
204 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 212 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); |
205 | struct f2fs_inode *ri = NULL; | 213 | struct f2fs_inode *ri = NULL; |
@@ -218,7 +226,7 @@ int recover_inline_data(struct inode *inode, struct page *npage) | |||
218 | ri = F2FS_INODE(npage); | 226 | ri = F2FS_INODE(npage); |
219 | 227 | ||
220 | if (f2fs_has_inline_data(inode) && | 228 | if (f2fs_has_inline_data(inode) && |
221 | ri && ri->i_inline & F2FS_INLINE_DATA) { | 229 | ri && (ri->i_inline & F2FS_INLINE_DATA)) { |
222 | process_inline: | 230 | process_inline: |
223 | ipage = get_node_page(sbi, inode->i_ino); | 231 | ipage = get_node_page(sbi, inode->i_ino); |
224 | f2fs_bug_on(IS_ERR(ipage)); | 232 | f2fs_bug_on(IS_ERR(ipage)); |
@@ -230,7 +238,7 @@ process_inline: | |||
230 | memcpy(dst_addr, src_addr, MAX_INLINE_DATA); | 238 | memcpy(dst_addr, src_addr, MAX_INLINE_DATA); |
231 | update_inode(inode, ipage); | 239 | update_inode(inode, ipage); |
232 | f2fs_put_page(ipage, 1); | 240 | f2fs_put_page(ipage, 1); |
233 | return -1; | 241 | return true; |
234 | } | 242 | } |
235 | 243 | ||
236 | if (f2fs_has_inline_data(inode)) { | 244 | if (f2fs_has_inline_data(inode)) { |
@@ -242,10 +250,10 @@ process_inline: | |||
242 | clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); | 250 | clear_inode_flag(F2FS_I(inode), FI_INLINE_DATA); |
243 | update_inode(inode, ipage); | 251 | update_inode(inode, ipage); |
244 | f2fs_put_page(ipage, 1); | 252 | f2fs_put_page(ipage, 1); |
245 | } else if (ri && ri->i_inline & F2FS_INLINE_DATA) { | 253 | } else if (ri && (ri->i_inline & F2FS_INLINE_DATA)) { |
246 | truncate_blocks(inode, 0); | 254 | truncate_blocks(inode, 0, false); |
247 | set_inode_flag(F2FS_I(inode), FI_INLINE_DATA); | 255 | set_inode_flag(F2FS_I(inode), FI_INLINE_DATA); |
248 | goto process_inline; | 256 | goto process_inline; |
249 | } | 257 | } |
250 | return 0; | 258 | return false; |
251 | } | 259 | } |
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 27b03776ffd2..ee103fd7283c 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c | |||
@@ -134,9 +134,7 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode, | |||
134 | return 0; | 134 | return 0; |
135 | out: | 135 | out: |
136 | clear_nlink(inode); | 136 | clear_nlink(inode); |
137 | unlock_new_inode(inode); | 137 | iget_failed(inode); |
138 | make_bad_inode(inode); | ||
139 | iput(inode); | ||
140 | alloc_nid_failed(sbi, ino); | 138 | alloc_nid_failed(sbi, ino); |
141 | return err; | 139 | return err; |
142 | } | 140 | } |
@@ -229,7 +227,7 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) | |||
229 | f2fs_delete_entry(de, page, inode); | 227 | f2fs_delete_entry(de, page, inode); |
230 | f2fs_unlock_op(sbi); | 228 | f2fs_unlock_op(sbi); |
231 | 229 | ||
232 | /* In order to evict this inode, we set it dirty */ | 230 | /* In order to evict this inode, we set it dirty */ |
233 | mark_inode_dirty(inode); | 231 | mark_inode_dirty(inode); |
234 | fail: | 232 | fail: |
235 | trace_f2fs_unlink_exit(inode, err); | 233 | trace_f2fs_unlink_exit(inode, err); |
@@ -267,9 +265,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, | |||
267 | return err; | 265 | return err; |
268 | out: | 266 | out: |
269 | clear_nlink(inode); | 267 | clear_nlink(inode); |
270 | unlock_new_inode(inode); | 268 | iget_failed(inode); |
271 | make_bad_inode(inode); | ||
272 | iput(inode); | ||
273 | alloc_nid_failed(sbi, inode->i_ino); | 269 | alloc_nid_failed(sbi, inode->i_ino); |
274 | return err; | 270 | return err; |
275 | } | 271 | } |
@@ -308,9 +304,7 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
308 | out_fail: | 304 | out_fail: |
309 | clear_inode_flag(F2FS_I(inode), FI_INC_LINK); | 305 | clear_inode_flag(F2FS_I(inode), FI_INC_LINK); |
310 | clear_nlink(inode); | 306 | clear_nlink(inode); |
311 | unlock_new_inode(inode); | 307 | iget_failed(inode); |
312 | make_bad_inode(inode); | ||
313 | iput(inode); | ||
314 | alloc_nid_failed(sbi, inode->i_ino); | 308 | alloc_nid_failed(sbi, inode->i_ino); |
315 | return err; | 309 | return err; |
316 | } | 310 | } |
@@ -354,9 +348,7 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry, | |||
354 | return 0; | 348 | return 0; |
355 | out: | 349 | out: |
356 | clear_nlink(inode); | 350 | clear_nlink(inode); |
357 | unlock_new_inode(inode); | 351 | iget_failed(inode); |
358 | make_bad_inode(inode); | ||
359 | iput(inode); | ||
360 | alloc_nid_failed(sbi, inode->i_ino); | 352 | alloc_nid_failed(sbi, inode->i_ino); |
361 | return err; | 353 | return err; |
362 | } | 354 | } |
@@ -688,9 +680,7 @@ release_out: | |||
688 | out: | 680 | out: |
689 | f2fs_unlock_op(sbi); | 681 | f2fs_unlock_op(sbi); |
690 | clear_nlink(inode); | 682 | clear_nlink(inode); |
691 | unlock_new_inode(inode); | 683 | iget_failed(inode); |
692 | make_bad_inode(inode); | ||
693 | iput(inode); | ||
694 | alloc_nid_failed(sbi, inode->i_ino); | 684 | alloc_nid_failed(sbi, inode->i_ino); |
695 | return err; | 685 | return err; |
696 | } | 686 | } |
@@ -704,7 +694,6 @@ const struct inode_operations f2fs_dir_inode_operations = { | |||
704 | .mkdir = f2fs_mkdir, | 694 | .mkdir = f2fs_mkdir, |
705 | .rmdir = f2fs_rmdir, | 695 | .rmdir = f2fs_rmdir, |
706 | .mknod = f2fs_mknod, | 696 | .mknod = f2fs_mknod, |
707 | .rename = f2fs_rename, | ||
708 | .rename2 = f2fs_rename2, | 697 | .rename2 = f2fs_rename2, |
709 | .tmpfile = f2fs_tmpfile, | 698 | .tmpfile = f2fs_tmpfile, |
710 | .getattr = f2fs_getattr, | 699 | .getattr = f2fs_getattr, |
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index d3d90d284631..45378196e19a 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
@@ -237,7 +237,7 @@ retry: | |||
237 | nat_get_blkaddr(e) != NULL_ADDR && | 237 | nat_get_blkaddr(e) != NULL_ADDR && |
238 | new_blkaddr == NEW_ADDR); | 238 | new_blkaddr == NEW_ADDR); |
239 | 239 | ||
240 | /* increament version no as node is removed */ | 240 | /* increment version no as node is removed */ |
241 | if (nat_get_blkaddr(e) != NEW_ADDR && new_blkaddr == NULL_ADDR) { | 241 | if (nat_get_blkaddr(e) != NEW_ADDR && new_blkaddr == NULL_ADDR) { |
242 | unsigned char version = nat_get_version(e); | 242 | unsigned char version = nat_get_version(e); |
243 | nat_set_version(e, inc_node_version(version)); | 243 | nat_set_version(e, inc_node_version(version)); |
@@ -274,7 +274,7 @@ int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink) | |||
274 | } | 274 | } |
275 | 275 | ||
276 | /* | 276 | /* |
277 | * This function returns always success | 277 | * This function always returns success |
278 | */ | 278 | */ |
279 | void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni) | 279 | void get_node_info(struct f2fs_sb_info *sbi, nid_t nid, struct node_info *ni) |
280 | { | 280 | { |
@@ -650,7 +650,7 @@ static int truncate_partial_nodes(struct dnode_of_data *dn, | |||
650 | 650 | ||
651 | /* get indirect nodes in the path */ | 651 | /* get indirect nodes in the path */ |
652 | for (i = 0; i < idx + 1; i++) { | 652 | for (i = 0; i < idx + 1; i++) { |
653 | /* refernece count'll be increased */ | 653 | /* reference count'll be increased */ |
654 | pages[i] = get_node_page(sbi, nid[i]); | 654 | pages[i] = get_node_page(sbi, nid[i]); |
655 | if (IS_ERR(pages[i])) { | 655 | if (IS_ERR(pages[i])) { |
656 | err = PTR_ERR(pages[i]); | 656 | err = PTR_ERR(pages[i]); |
@@ -823,22 +823,26 @@ int truncate_xattr_node(struct inode *inode, struct page *page) | |||
823 | */ | 823 | */ |
824 | void remove_inode_page(struct inode *inode) | 824 | void remove_inode_page(struct inode *inode) |
825 | { | 825 | { |
826 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | ||
827 | struct page *page; | ||
828 | nid_t ino = inode->i_ino; | ||
829 | struct dnode_of_data dn; | 826 | struct dnode_of_data dn; |
830 | 827 | ||
831 | page = get_node_page(sbi, ino); | 828 | set_new_dnode(&dn, inode, NULL, NULL, inode->i_ino); |
832 | if (IS_ERR(page)) | 829 | if (get_dnode_of_data(&dn, 0, LOOKUP_NODE)) |
833 | return; | 830 | return; |
834 | 831 | ||
835 | if (truncate_xattr_node(inode, page)) { | 832 | if (truncate_xattr_node(inode, dn.inode_page)) { |
836 | f2fs_put_page(page, 1); | 833 | f2fs_put_dnode(&dn); |
837 | return; | 834 | return; |
838 | } | 835 | } |
839 | /* 0 is possible, after f2fs_new_inode() is failed */ | 836 | |
837 | /* remove potential inline_data blocks */ | ||
838 | if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || | ||
839 | S_ISLNK(inode->i_mode)) | ||
840 | truncate_data_blocks_range(&dn, 1); | ||
841 | |||
842 | /* 0 is possible, after f2fs_new_inode() has failed */ | ||
840 | f2fs_bug_on(inode->i_blocks != 0 && inode->i_blocks != 1); | 843 | f2fs_bug_on(inode->i_blocks != 0 && inode->i_blocks != 1); |
841 | set_new_dnode(&dn, inode, page, page, ino); | 844 | |
845 | /* will put inode & node pages */ | ||
842 | truncate_node(&dn); | 846 | truncate_node(&dn); |
843 | } | 847 | } |
844 | 848 | ||
@@ -1129,8 +1133,11 @@ continue_unlock: | |||
1129 | set_fsync_mark(page, 0); | 1133 | set_fsync_mark(page, 0); |
1130 | set_dentry_mark(page, 0); | 1134 | set_dentry_mark(page, 0); |
1131 | } | 1135 | } |
1132 | NODE_MAPPING(sbi)->a_ops->writepage(page, wbc); | 1136 | |
1133 | wrote++; | 1137 | if (NODE_MAPPING(sbi)->a_ops->writepage(page, wbc)) |
1138 | unlock_page(page); | ||
1139 | else | ||
1140 | wrote++; | ||
1134 | 1141 | ||
1135 | if (--wbc->nr_to_write == 0) | 1142 | if (--wbc->nr_to_write == 0) |
1136 | break; | 1143 | break; |
@@ -1212,6 +1219,8 @@ static int f2fs_write_node_page(struct page *page, | |||
1212 | 1219 | ||
1213 | if (unlikely(sbi->por_doing)) | 1220 | if (unlikely(sbi->por_doing)) |
1214 | goto redirty_out; | 1221 | goto redirty_out; |
1222 | if (unlikely(f2fs_cp_error(sbi))) | ||
1223 | goto redirty_out; | ||
1215 | 1224 | ||
1216 | f2fs_wait_on_page_writeback(page, NODE); | 1225 | f2fs_wait_on_page_writeback(page, NODE); |
1217 | 1226 | ||
@@ -1540,15 +1549,6 @@ void alloc_nid_failed(struct f2fs_sb_info *sbi, nid_t nid) | |||
1540 | kmem_cache_free(free_nid_slab, i); | 1549 | kmem_cache_free(free_nid_slab, i); |
1541 | } | 1550 | } |
1542 | 1551 | ||
1543 | void recover_node_page(struct f2fs_sb_info *sbi, struct page *page, | ||
1544 | struct f2fs_summary *sum, struct node_info *ni, | ||
1545 | block_t new_blkaddr) | ||
1546 | { | ||
1547 | rewrite_node_page(sbi, page, sum, ni->blk_addr, new_blkaddr); | ||
1548 | set_node_addr(sbi, ni, new_blkaddr, false); | ||
1549 | clear_node_page_dirty(page); | ||
1550 | } | ||
1551 | |||
1552 | void recover_inline_xattr(struct inode *inode, struct page *page) | 1552 | void recover_inline_xattr(struct inode *inode, struct page *page) |
1553 | { | 1553 | { |
1554 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 1554 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); |
@@ -1557,40 +1557,33 @@ void recover_inline_xattr(struct inode *inode, struct page *page) | |||
1557 | struct page *ipage; | 1557 | struct page *ipage; |
1558 | struct f2fs_inode *ri; | 1558 | struct f2fs_inode *ri; |
1559 | 1559 | ||
1560 | if (!f2fs_has_inline_xattr(inode)) | ||
1561 | return; | ||
1562 | |||
1563 | if (!IS_INODE(page)) | ||
1564 | return; | ||
1565 | |||
1566 | ri = F2FS_INODE(page); | ||
1567 | if (!(ri->i_inline & F2FS_INLINE_XATTR)) | ||
1568 | return; | ||
1569 | |||
1570 | ipage = get_node_page(sbi, inode->i_ino); | 1560 | ipage = get_node_page(sbi, inode->i_ino); |
1571 | f2fs_bug_on(IS_ERR(ipage)); | 1561 | f2fs_bug_on(IS_ERR(ipage)); |
1572 | 1562 | ||
1563 | ri = F2FS_INODE(page); | ||
1564 | if (!(ri->i_inline & F2FS_INLINE_XATTR)) { | ||
1565 | clear_inode_flag(F2FS_I(inode), FI_INLINE_XATTR); | ||
1566 | goto update_inode; | ||
1567 | } | ||
1568 | |||
1573 | dst_addr = inline_xattr_addr(ipage); | 1569 | dst_addr = inline_xattr_addr(ipage); |
1574 | src_addr = inline_xattr_addr(page); | 1570 | src_addr = inline_xattr_addr(page); |
1575 | inline_size = inline_xattr_size(inode); | 1571 | inline_size = inline_xattr_size(inode); |
1576 | 1572 | ||
1577 | f2fs_wait_on_page_writeback(ipage, NODE); | 1573 | f2fs_wait_on_page_writeback(ipage, NODE); |
1578 | memcpy(dst_addr, src_addr, inline_size); | 1574 | memcpy(dst_addr, src_addr, inline_size); |
1579 | 1575 | update_inode: | |
1580 | update_inode(inode, ipage); | 1576 | update_inode(inode, ipage); |
1581 | f2fs_put_page(ipage, 1); | 1577 | f2fs_put_page(ipage, 1); |
1582 | } | 1578 | } |
1583 | 1579 | ||
1584 | bool recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr) | 1580 | void recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr) |
1585 | { | 1581 | { |
1586 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); | 1582 | struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb); |
1587 | nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid; | 1583 | nid_t prev_xnid = F2FS_I(inode)->i_xattr_nid; |
1588 | nid_t new_xnid = nid_of_node(page); | 1584 | nid_t new_xnid = nid_of_node(page); |
1589 | struct node_info ni; | 1585 | struct node_info ni; |
1590 | 1586 | ||
1591 | if (!f2fs_has_xattr_block(ofs_of_node(page))) | ||
1592 | return false; | ||
1593 | |||
1594 | /* 1: invalidate the previous xattr nid */ | 1587 | /* 1: invalidate the previous xattr nid */ |
1595 | if (!prev_xnid) | 1588 | if (!prev_xnid) |
1596 | goto recover_xnid; | 1589 | goto recover_xnid; |
@@ -1618,7 +1611,6 @@ recover_xnid: | |||
1618 | set_node_addr(sbi, &ni, blkaddr, false); | 1611 | set_node_addr(sbi, &ni, blkaddr, false); |
1619 | 1612 | ||
1620 | update_inode_page(inode); | 1613 | update_inode_page(inode); |
1621 | return true; | ||
1622 | } | 1614 | } |
1623 | 1615 | ||
1624 | int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) | 1616 | int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) |
@@ -1637,7 +1629,7 @@ int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) | |||
1637 | if (!ipage) | 1629 | if (!ipage) |
1638 | return -ENOMEM; | 1630 | return -ENOMEM; |
1639 | 1631 | ||
1640 | /* Should not use this inode from free nid list */ | 1632 | /* Should not use this inode from free nid list */ |
1641 | remove_free_nid(NM_I(sbi), ino); | 1633 | remove_free_nid(NM_I(sbi), ino); |
1642 | 1634 | ||
1643 | SetPageUptodate(ipage); | 1635 | SetPageUptodate(ipage); |
@@ -1651,6 +1643,7 @@ int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) | |||
1651 | dst->i_blocks = cpu_to_le64(1); | 1643 | dst->i_blocks = cpu_to_le64(1); |
1652 | dst->i_links = cpu_to_le32(1); | 1644 | dst->i_links = cpu_to_le32(1); |
1653 | dst->i_xattr_nid = 0; | 1645 | dst->i_xattr_nid = 0; |
1646 | dst->i_inline = src->i_inline & F2FS_INLINE_XATTR; | ||
1654 | 1647 | ||
1655 | new_ni = old_ni; | 1648 | new_ni = old_ni; |
1656 | new_ni.ino = ino; | 1649 | new_ni.ino = ino; |
@@ -1659,13 +1652,14 @@ int recover_inode_page(struct f2fs_sb_info *sbi, struct page *page) | |||
1659 | WARN_ON(1); | 1652 | WARN_ON(1); |
1660 | set_node_addr(sbi, &new_ni, NEW_ADDR, false); | 1653 | set_node_addr(sbi, &new_ni, NEW_ADDR, false); |
1661 | inc_valid_inode_count(sbi); | 1654 | inc_valid_inode_count(sbi); |
1655 | set_page_dirty(ipage); | ||
1662 | f2fs_put_page(ipage, 1); | 1656 | f2fs_put_page(ipage, 1); |
1663 | return 0; | 1657 | return 0; |
1664 | } | 1658 | } |
1665 | 1659 | ||
1666 | /* | 1660 | /* |
1667 | * ra_sum_pages() merge contiguous pages into one bio and submit. | 1661 | * ra_sum_pages() merge contiguous pages into one bio and submit. |
1668 | * these pre-readed pages are alloced in bd_inode's mapping tree. | 1662 | * these pre-read pages are allocated in bd_inode's mapping tree. |
1669 | */ | 1663 | */ |
1670 | static int ra_sum_pages(struct f2fs_sb_info *sbi, struct page **pages, | 1664 | static int ra_sum_pages(struct f2fs_sb_info *sbi, struct page **pages, |
1671 | int start, int nrpages) | 1665 | int start, int nrpages) |
@@ -1709,7 +1703,7 @@ int restore_node_summary(struct f2fs_sb_info *sbi, | |||
1709 | for (i = 0; !err && i < last_offset; i += nrpages, addr += nrpages) { | 1703 | for (i = 0; !err && i < last_offset; i += nrpages, addr += nrpages) { |
1710 | nrpages = min(last_offset - i, bio_blocks); | 1704 | nrpages = min(last_offset - i, bio_blocks); |
1711 | 1705 | ||
1712 | /* read ahead node pages */ | 1706 | /* readahead node pages */ |
1713 | nrpages = ra_sum_pages(sbi, pages, addr, nrpages); | 1707 | nrpages = ra_sum_pages(sbi, pages, addr, nrpages); |
1714 | if (!nrpages) | 1708 | if (!nrpages) |
1715 | return -ENOMEM; | 1709 | return -ENOMEM; |
@@ -1967,7 +1961,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) | |||
1967 | nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nat_blocks; | 1961 | nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nat_blocks; |
1968 | 1962 | ||
1969 | /* not used nids: 0, node, meta, (and root counted as valid node) */ | 1963 | /* not used nids: 0, node, meta, (and root counted as valid node) */ |
1970 | nm_i->available_nids = nm_i->max_nid - 3; | 1964 | nm_i->available_nids = nm_i->max_nid - F2FS_RESERVED_NODE_NUM; |
1971 | nm_i->fcnt = 0; | 1965 | nm_i->fcnt = 0; |
1972 | nm_i->nat_cnt = 0; | 1966 | nm_i->nat_cnt = 0; |
1973 | nm_i->ram_thresh = DEF_RAM_THRESHOLD; | 1967 | nm_i->ram_thresh = DEF_RAM_THRESHOLD; |
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index fe1c6d921ba2..756c41cd2582 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c | |||
@@ -62,8 +62,10 @@ static int recover_dentry(struct page *ipage, struct inode *inode) | |||
62 | } | 62 | } |
63 | retry: | 63 | retry: |
64 | de = f2fs_find_entry(dir, &name, &page); | 64 | de = f2fs_find_entry(dir, &name, &page); |
65 | if (de && inode->i_ino == le32_to_cpu(de->ino)) | 65 | if (de && inode->i_ino == le32_to_cpu(de->ino)) { |
66 | clear_inode_flag(F2FS_I(inode), FI_INC_LINK); | ||
66 | goto out_unmap_put; | 67 | goto out_unmap_put; |
68 | } | ||
67 | if (de) { | 69 | if (de) { |
68 | einode = f2fs_iget(inode->i_sb, le32_to_cpu(de->ino)); | 70 | einode = f2fs_iget(inode->i_sb, le32_to_cpu(de->ino)); |
69 | if (IS_ERR(einode)) { | 71 | if (IS_ERR(einode)) { |
@@ -300,14 +302,19 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, | |||
300 | struct node_info ni; | 302 | struct node_info ni; |
301 | int err = 0, recovered = 0; | 303 | int err = 0, recovered = 0; |
302 | 304 | ||
303 | recover_inline_xattr(inode, page); | 305 | /* step 1: recover xattr */ |
304 | 306 | if (IS_INODE(page)) { | |
305 | if (recover_inline_data(inode, page)) | 307 | recover_inline_xattr(inode, page); |
308 | } else if (f2fs_has_xattr_block(ofs_of_node(page))) { | ||
309 | recover_xattr_data(inode, page, blkaddr); | ||
306 | goto out; | 310 | goto out; |
311 | } | ||
307 | 312 | ||
308 | if (recover_xattr_data(inode, page, blkaddr)) | 313 | /* step 2: recover inline data */ |
314 | if (recover_inline_data(inode, page)) | ||
309 | goto out; | 315 | goto out; |
310 | 316 | ||
317 | /* step 3: recover data indices */ | ||
311 | start = start_bidx_of_node(ofs_of_node(page), fi); | 318 | start = start_bidx_of_node(ofs_of_node(page), fi); |
312 | end = start + ADDRS_PER_PAGE(page, fi); | 319 | end = start + ADDRS_PER_PAGE(page, fi); |
313 | 320 | ||
@@ -364,8 +371,6 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, | |||
364 | fill_node_footer(dn.node_page, dn.nid, ni.ino, | 371 | fill_node_footer(dn.node_page, dn.nid, ni.ino, |
365 | ofs_of_node(page), false); | 372 | ofs_of_node(page), false); |
366 | set_page_dirty(dn.node_page); | 373 | set_page_dirty(dn.node_page); |
367 | |||
368 | recover_node_page(sbi, dn.node_page, &sum, &ni, blkaddr); | ||
369 | err: | 374 | err: |
370 | f2fs_put_dnode(&dn); | 375 | f2fs_put_dnode(&dn); |
371 | f2fs_unlock_op(sbi); | 376 | f2fs_unlock_op(sbi); |
@@ -452,6 +457,9 @@ int recover_fsync_data(struct f2fs_sb_info *sbi) | |||
452 | /* step #1: find fsynced inode numbers */ | 457 | /* step #1: find fsynced inode numbers */ |
453 | sbi->por_doing = true; | 458 | sbi->por_doing = true; |
454 | 459 | ||
460 | /* prevent checkpoint */ | ||
461 | mutex_lock(&sbi->cp_mutex); | ||
462 | |||
455 | blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); | 463 | blkaddr = NEXT_FREE_BLKADDR(sbi, curseg); |
456 | 464 | ||
457 | err = find_fsync_dnodes(sbi, &inode_list); | 465 | err = find_fsync_dnodes(sbi, &inode_list); |
@@ -465,7 +473,8 @@ int recover_fsync_data(struct f2fs_sb_info *sbi) | |||
465 | 473 | ||
466 | /* step #2: recover data */ | 474 | /* step #2: recover data */ |
467 | err = recover_data(sbi, &inode_list, CURSEG_WARM_NODE); | 475 | err = recover_data(sbi, &inode_list, CURSEG_WARM_NODE); |
468 | f2fs_bug_on(!list_empty(&inode_list)); | 476 | if (!err) |
477 | f2fs_bug_on(!list_empty(&inode_list)); | ||
469 | out: | 478 | out: |
470 | destroy_fsync_dnodes(&inode_list); | 479 | destroy_fsync_dnodes(&inode_list); |
471 | kmem_cache_destroy(fsync_entry_slab); | 480 | kmem_cache_destroy(fsync_entry_slab); |
@@ -482,8 +491,13 @@ out: | |||
482 | /* Flush all the NAT/SIT pages */ | 491 | /* Flush all the NAT/SIT pages */ |
483 | while (get_pages(sbi, F2FS_DIRTY_META)) | 492 | while (get_pages(sbi, F2FS_DIRTY_META)) |
484 | sync_meta_pages(sbi, META, LONG_MAX); | 493 | sync_meta_pages(sbi, META, LONG_MAX); |
494 | set_ckpt_flags(sbi->ckpt, CP_ERROR_FLAG); | ||
495 | mutex_unlock(&sbi->cp_mutex); | ||
485 | } else if (need_writecp) { | 496 | } else if (need_writecp) { |
497 | mutex_unlock(&sbi->cp_mutex); | ||
486 | write_checkpoint(sbi, false); | 498 | write_checkpoint(sbi, false); |
499 | } else { | ||
500 | mutex_unlock(&sbi->cp_mutex); | ||
487 | } | 501 | } |
488 | return err; | 502 | return err; |
489 | } | 503 | } |
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 0dfeebae2a50..0aa337cd5bba 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c | |||
@@ -62,7 +62,7 @@ static inline unsigned long __reverse_ffs(unsigned long word) | |||
62 | } | 62 | } |
63 | 63 | ||
64 | /* | 64 | /* |
65 | * __find_rev_next(_zero)_bit is copied from lib/find_next_bit.c becasue | 65 | * __find_rev_next(_zero)_bit is copied from lib/find_next_bit.c because |
66 | * f2fs_set_bit makes MSB and LSB reversed in a byte. | 66 | * f2fs_set_bit makes MSB and LSB reversed in a byte. |
67 | * Example: | 67 | * Example: |
68 | * LSB <--> MSB | 68 | * LSB <--> MSB |
@@ -808,7 +808,7 @@ static void __refresh_next_blkoff(struct f2fs_sb_info *sbi, | |||
808 | } | 808 | } |
809 | 809 | ||
810 | /* | 810 | /* |
811 | * This function always allocates a used segment (from dirty seglist) by SSR | 811 | * This function always allocates a used segment(from dirty seglist) by SSR |
812 | * manner, so it should recover the existing segment information of valid blocks | 812 | * manner, so it should recover the existing segment information of valid blocks |
813 | */ | 813 | */ |
814 | static void change_curseg(struct f2fs_sb_info *sbi, int type, bool reuse) | 814 | static void change_curseg(struct f2fs_sb_info *sbi, int type, bool reuse) |
@@ -1103,55 +1103,6 @@ void recover_data_page(struct f2fs_sb_info *sbi, | |||
1103 | mutex_unlock(&curseg->curseg_mutex); | 1103 | mutex_unlock(&curseg->curseg_mutex); |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | void rewrite_node_page(struct f2fs_sb_info *sbi, | ||
1107 | struct page *page, struct f2fs_summary *sum, | ||
1108 | block_t old_blkaddr, block_t new_blkaddr) | ||
1109 | { | ||
1110 | struct sit_info *sit_i = SIT_I(sbi); | ||
1111 | int type = CURSEG_WARM_NODE; | ||
1112 | struct curseg_info *curseg; | ||
1113 | unsigned int segno, old_cursegno; | ||
1114 | block_t next_blkaddr = next_blkaddr_of_node(page); | ||
1115 | unsigned int next_segno = GET_SEGNO(sbi, next_blkaddr); | ||
1116 | struct f2fs_io_info fio = { | ||
1117 | .type = NODE, | ||
1118 | .rw = WRITE_SYNC, | ||
1119 | }; | ||
1120 | |||
1121 | curseg = CURSEG_I(sbi, type); | ||
1122 | |||
1123 | mutex_lock(&curseg->curseg_mutex); | ||
1124 | mutex_lock(&sit_i->sentry_lock); | ||
1125 | |||
1126 | segno = GET_SEGNO(sbi, new_blkaddr); | ||
1127 | old_cursegno = curseg->segno; | ||
1128 | |||
1129 | /* change the current segment */ | ||
1130 | if (segno != curseg->segno) { | ||
1131 | curseg->next_segno = segno; | ||
1132 | change_curseg(sbi, type, true); | ||
1133 | } | ||
1134 | curseg->next_blkoff = GET_BLKOFF_FROM_SEG0(sbi, new_blkaddr); | ||
1135 | __add_sum_entry(sbi, type, sum); | ||
1136 | |||
1137 | /* change the current log to the next block addr in advance */ | ||
1138 | if (next_segno != segno) { | ||
1139 | curseg->next_segno = next_segno; | ||
1140 | change_curseg(sbi, type, true); | ||
1141 | } | ||
1142 | curseg->next_blkoff = GET_BLKOFF_FROM_SEG0(sbi, next_blkaddr); | ||
1143 | |||
1144 | /* rewrite node page */ | ||
1145 | set_page_writeback(page); | ||
1146 | f2fs_submit_page_mbio(sbi, page, new_blkaddr, &fio); | ||
1147 | f2fs_submit_merged_bio(sbi, NODE, WRITE); | ||
1148 | refresh_sit_entry(sbi, old_blkaddr, new_blkaddr); | ||
1149 | locate_dirty_segment(sbi, old_cursegno); | ||
1150 | |||
1151 | mutex_unlock(&sit_i->sentry_lock); | ||
1152 | mutex_unlock(&curseg->curseg_mutex); | ||
1153 | } | ||
1154 | |||
1155 | static inline bool is_merged_page(struct f2fs_sb_info *sbi, | 1106 | static inline bool is_merged_page(struct f2fs_sb_info *sbi, |
1156 | struct page *page, enum page_type type) | 1107 | struct page *page, enum page_type type) |
1157 | { | 1108 | { |
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 55973f7b0330..ff483257283b 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h | |||
@@ -549,7 +549,7 @@ static inline void verify_block_addr(struct f2fs_sb_info *sbi, block_t blk_addr) | |||
549 | } | 549 | } |
550 | 550 | ||
551 | /* | 551 | /* |
552 | * Summary block is always treated as invalid block | 552 | * Summary block is always treated as an invalid block |
553 | */ | 553 | */ |
554 | static inline void check_block_count(struct f2fs_sb_info *sbi, | 554 | static inline void check_block_count(struct f2fs_sb_info *sbi, |
555 | int segno, struct f2fs_sit_entry *raw_sit) | 555 | int segno, struct f2fs_sit_entry *raw_sit) |
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 657582fc7601..41bdf511003d 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c | |||
@@ -432,9 +432,15 @@ static void f2fs_put_super(struct super_block *sb) | |||
432 | stop_gc_thread(sbi); | 432 | stop_gc_thread(sbi); |
433 | 433 | ||
434 | /* We don't need to do checkpoint when it's clean */ | 434 | /* We don't need to do checkpoint when it's clean */ |
435 | if (sbi->s_dirty && get_pages(sbi, F2FS_DIRTY_NODES)) | 435 | if (sbi->s_dirty) |
436 | write_checkpoint(sbi, true); | 436 | write_checkpoint(sbi, true); |
437 | 437 | ||
438 | /* | ||
439 | * normally superblock is clean, so we need to release this. | ||
440 | * In addition, EIO will skip do checkpoint, we need this as well. | ||
441 | */ | ||
442 | release_dirty_inode(sbi); | ||
443 | |||
438 | iput(sbi->node_inode); | 444 | iput(sbi->node_inode); |
439 | iput(sbi->meta_inode); | 445 | iput(sbi->meta_inode); |
440 | 446 | ||
@@ -457,9 +463,6 @@ int f2fs_sync_fs(struct super_block *sb, int sync) | |||
457 | 463 | ||
458 | trace_f2fs_sync_fs(sb, sync); | 464 | trace_f2fs_sync_fs(sb, sync); |
459 | 465 | ||
460 | if (!sbi->s_dirty && !get_pages(sbi, F2FS_DIRTY_NODES)) | ||
461 | return 0; | ||
462 | |||
463 | if (sync) { | 466 | if (sync) { |
464 | mutex_lock(&sbi->gc_mutex); | 467 | mutex_lock(&sbi->gc_mutex); |
465 | write_checkpoint(sbi, false); | 468 | write_checkpoint(sbi, false); |
@@ -505,8 +508,8 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) | |||
505 | buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count; | 508 | buf->f_bfree = buf->f_blocks - valid_user_blocks(sbi) - ovp_count; |
506 | buf->f_bavail = user_block_count - valid_user_blocks(sbi); | 509 | buf->f_bavail = user_block_count - valid_user_blocks(sbi); |
507 | 510 | ||
508 | buf->f_files = sbi->total_node_count; | 511 | buf->f_files = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; |
509 | buf->f_ffree = sbi->total_node_count - valid_inode_count(sbi); | 512 | buf->f_ffree = buf->f_files - valid_inode_count(sbi); |
510 | 513 | ||
511 | buf->f_namelen = F2FS_NAME_LEN; | 514 | buf->f_namelen = F2FS_NAME_LEN; |
512 | buf->f_fsid.val[0] = (u32)id; | 515 | buf->f_fsid.val[0] = (u32)id; |
@@ -663,7 +666,7 @@ restore_gc: | |||
663 | if (need_restart_gc) { | 666 | if (need_restart_gc) { |
664 | if (start_gc_thread(sbi)) | 667 | if (start_gc_thread(sbi)) |
665 | f2fs_msg(sbi->sb, KERN_WARNING, | 668 | f2fs_msg(sbi->sb, KERN_WARNING, |
666 | "background gc thread is stop"); | 669 | "background gc thread has stopped"); |
667 | } else if (need_stop_gc) { | 670 | } else if (need_stop_gc) { |
668 | stop_gc_thread(sbi); | 671 | stop_gc_thread(sbi); |
669 | } | 672 | } |
@@ -812,7 +815,7 @@ static int sanity_check_ckpt(struct f2fs_sb_info *sbi) | |||
812 | if (unlikely(fsmeta >= total)) | 815 | if (unlikely(fsmeta >= total)) |
813 | return 1; | 816 | return 1; |
814 | 817 | ||
815 | if (unlikely(is_set_ckpt_flags(ckpt, CP_ERROR_FLAG))) { | 818 | if (unlikely(f2fs_cp_error(sbi))) { |
816 | f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck"); | 819 | f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck"); |
817 | return 1; | 820 | return 1; |
818 | } | 821 | } |
@@ -899,8 +902,10 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | |||
899 | struct buffer_head *raw_super_buf; | 902 | struct buffer_head *raw_super_buf; |
900 | struct inode *root; | 903 | struct inode *root; |
901 | long err = -EINVAL; | 904 | long err = -EINVAL; |
905 | bool retry = true; | ||
902 | int i; | 906 | int i; |
903 | 907 | ||
908 | try_onemore: | ||
904 | /* allocate memory for f2fs-specific super block info */ | 909 | /* allocate memory for f2fs-specific super block info */ |
905 | sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); | 910 | sbi = kzalloc(sizeof(struct f2fs_sb_info), GFP_KERNEL); |
906 | if (!sbi) | 911 | if (!sbi) |
@@ -1080,9 +1085,11 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) | |||
1080 | /* recover fsynced data */ | 1085 | /* recover fsynced data */ |
1081 | if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { | 1086 | if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { |
1082 | err = recover_fsync_data(sbi); | 1087 | err = recover_fsync_data(sbi); |
1083 | if (err) | 1088 | if (err) { |
1084 | f2fs_msg(sb, KERN_ERR, | 1089 | f2fs_msg(sb, KERN_ERR, |
1085 | "Cannot recover all fsync data errno=%ld", err); | 1090 | "Cannot recover all fsync data errno=%ld", err); |
1091 | goto free_kobj; | ||
1092 | } | ||
1086 | } | 1093 | } |
1087 | 1094 | ||
1088 | /* | 1095 | /* |
@@ -1123,6 +1130,13 @@ free_sb_buf: | |||
1123 | brelse(raw_super_buf); | 1130 | brelse(raw_super_buf); |
1124 | free_sbi: | 1131 | free_sbi: |
1125 | kfree(sbi); | 1132 | kfree(sbi); |
1133 | |||
1134 | /* give only one another chance */ | ||
1135 | if (retry) { | ||
1136 | retry = 0; | ||
1137 | shrink_dcache_sb(sb); | ||
1138 | goto try_onemore; | ||
1139 | } | ||
1126 | return err; | 1140 | return err; |
1127 | } | 1141 | } |
1128 | 1142 | ||
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 8bea941ee309..728a5dc3dc16 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c | |||
@@ -528,7 +528,7 @@ static int __f2fs_setxattr(struct inode *inode, int index, | |||
528 | int free; | 528 | int free; |
529 | /* | 529 | /* |
530 | * If value is NULL, it is remove operation. | 530 | * If value is NULL, it is remove operation. |
531 | * In case of update operation, we caculate free. | 531 | * In case of update operation, we calculate free. |
532 | */ | 532 | */ |
533 | free = MIN_OFFSET(inode) - ((char *)last - (char *)base_addr); | 533 | free = MIN_OFFSET(inode) - ((char *)last - (char *)base_addr); |
534 | if (found) | 534 | if (found) |
diff --git a/fs/fscache/object.c b/fs/fscache/object.c index d3b4539f1651..da032daf0e0d 100644 --- a/fs/fscache/object.c +++ b/fs/fscache/object.c | |||
@@ -982,6 +982,7 @@ nomem: | |||
982 | submit_op_failed: | 982 | submit_op_failed: |
983 | clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); | 983 | clear_bit(FSCACHE_OBJECT_IS_LIVE, &object->flags); |
984 | spin_unlock(&cookie->lock); | 984 | spin_unlock(&cookie->lock); |
985 | fscache_unuse_cookie(object); | ||
985 | kfree(op); | 986 | kfree(op); |
986 | _leave(" [EIO]"); | 987 | _leave(" [EIO]"); |
987 | return transit_to(KILL_OBJECT); | 988 | return transit_to(KILL_OBJECT); |
diff --git a/fs/fscache/page.c b/fs/fscache/page.c index 85332b9d19d1..de33b3fccca6 100644 --- a/fs/fscache/page.c +++ b/fs/fscache/page.c | |||
@@ -44,6 +44,19 @@ void __fscache_wait_on_page_write(struct fscache_cookie *cookie, struct page *pa | |||
44 | EXPORT_SYMBOL(__fscache_wait_on_page_write); | 44 | EXPORT_SYMBOL(__fscache_wait_on_page_write); |
45 | 45 | ||
46 | /* | 46 | /* |
47 | * wait for a page to finish being written to the cache. Put a timeout here | ||
48 | * since we might be called recursively via parent fs. | ||
49 | */ | ||
50 | static | ||
51 | bool release_page_wait_timeout(struct fscache_cookie *cookie, struct page *page) | ||
52 | { | ||
53 | wait_queue_head_t *wq = bit_waitqueue(&cookie->flags, 0); | ||
54 | |||
55 | return wait_event_timeout(*wq, !__fscache_check_page_write(cookie, page), | ||
56 | HZ); | ||
57 | } | ||
58 | |||
59 | /* | ||
47 | * decide whether a page can be released, possibly by cancelling a store to it | 60 | * decide whether a page can be released, possibly by cancelling a store to it |
48 | * - we're allowed to sleep if __GFP_WAIT is flagged | 61 | * - we're allowed to sleep if __GFP_WAIT is flagged |
49 | */ | 62 | */ |
@@ -115,7 +128,10 @@ page_busy: | |||
115 | } | 128 | } |
116 | 129 | ||
117 | fscache_stat(&fscache_n_store_vmscan_wait); | 130 | fscache_stat(&fscache_n_store_vmscan_wait); |
118 | __fscache_wait_on_page_write(cookie, page); | 131 | if (!release_page_wait_timeout(cookie, page)) |
132 | _debug("fscache writeout timeout page: %p{%lx}", | ||
133 | page, page->index); | ||
134 | |||
119 | gfp &= ~__GFP_WAIT; | 135 | gfp &= ~__GFP_WAIT; |
120 | goto try_again; | 136 | goto try_again; |
121 | } | 137 | } |
@@ -182,7 +198,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie) | |||
182 | { | 198 | { |
183 | struct fscache_operation *op; | 199 | struct fscache_operation *op; |
184 | struct fscache_object *object; | 200 | struct fscache_object *object; |
185 | bool wake_cookie; | 201 | bool wake_cookie = false; |
186 | 202 | ||
187 | _enter("%p", cookie); | 203 | _enter("%p", cookie); |
188 | 204 | ||
@@ -212,15 +228,16 @@ int __fscache_attr_changed(struct fscache_cookie *cookie) | |||
212 | 228 | ||
213 | __fscache_use_cookie(cookie); | 229 | __fscache_use_cookie(cookie); |
214 | if (fscache_submit_exclusive_op(object, op) < 0) | 230 | if (fscache_submit_exclusive_op(object, op) < 0) |
215 | goto nobufs; | 231 | goto nobufs_dec; |
216 | spin_unlock(&cookie->lock); | 232 | spin_unlock(&cookie->lock); |
217 | fscache_stat(&fscache_n_attr_changed_ok); | 233 | fscache_stat(&fscache_n_attr_changed_ok); |
218 | fscache_put_operation(op); | 234 | fscache_put_operation(op); |
219 | _leave(" = 0"); | 235 | _leave(" = 0"); |
220 | return 0; | 236 | return 0; |
221 | 237 | ||
222 | nobufs: | 238 | nobufs_dec: |
223 | wake_cookie = __fscache_unuse_cookie(cookie); | 239 | wake_cookie = __fscache_unuse_cookie(cookie); |
240 | nobufs: | ||
224 | spin_unlock(&cookie->lock); | 241 | spin_unlock(&cookie->lock); |
225 | kfree(op); | 242 | kfree(op); |
226 | if (wake_cookie) | 243 | if (wake_cookie) |
diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 912061ac4baf..caa8d95b24e8 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c | |||
@@ -1305,6 +1305,7 @@ static int fuse_get_user_pages(struct fuse_req *req, struct iov_iter *ii, | |||
1305 | size_t start; | 1305 | size_t start; |
1306 | ssize_t ret = iov_iter_get_pages(ii, | 1306 | ssize_t ret = iov_iter_get_pages(ii, |
1307 | &req->pages[req->num_pages], | 1307 | &req->pages[req->num_pages], |
1308 | *nbytesp - nbytes, | ||
1308 | req->max_pages - req->num_pages, | 1309 | req->max_pages - req->num_pages, |
1309 | &start); | 1310 | &start); |
1310 | if (ret < 0) | 1311 | if (ret < 0) |
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c index e6ee5b6e8d99..f0b945ab853e 100644 --- a/fs/gfs2/bmap.c +++ b/fs/gfs2/bmap.c | |||
@@ -359,7 +359,7 @@ static inline void release_metapath(struct metapath *mp) | |||
359 | * Returns: The length of the extent (minimum of one block) | 359 | * Returns: The length of the extent (minimum of one block) |
360 | */ | 360 | */ |
361 | 361 | ||
362 | static inline unsigned int gfs2_extent_length(void *start, unsigned int len, __be64 *ptr, unsigned limit, int *eob) | 362 | static inline unsigned int gfs2_extent_length(void *start, unsigned int len, __be64 *ptr, size_t limit, int *eob) |
363 | { | 363 | { |
364 | const __be64 *end = (start + len); | 364 | const __be64 *end = (start + len); |
365 | const __be64 *first = ptr; | 365 | const __be64 *first = ptr; |
@@ -449,7 +449,7 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, | |||
449 | struct buffer_head *bh_map, struct metapath *mp, | 449 | struct buffer_head *bh_map, struct metapath *mp, |
450 | const unsigned int sheight, | 450 | const unsigned int sheight, |
451 | const unsigned int height, | 451 | const unsigned int height, |
452 | const unsigned int maxlen) | 452 | const size_t maxlen) |
453 | { | 453 | { |
454 | struct gfs2_inode *ip = GFS2_I(inode); | 454 | struct gfs2_inode *ip = GFS2_I(inode); |
455 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 455 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
@@ -483,7 +483,8 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock, | |||
483 | } else { | 483 | } else { |
484 | /* Need to allocate indirect blocks */ | 484 | /* Need to allocate indirect blocks */ |
485 | ptrs_per_blk = height > 1 ? sdp->sd_inptrs : sdp->sd_diptrs; | 485 | ptrs_per_blk = height > 1 ? sdp->sd_inptrs : sdp->sd_diptrs; |
486 | dblks = min(maxlen, ptrs_per_blk - mp->mp_list[end_of_metadata]); | 486 | dblks = min(maxlen, (size_t)(ptrs_per_blk - |
487 | mp->mp_list[end_of_metadata])); | ||
487 | if (height == ip->i_height) { | 488 | if (height == ip->i_height) { |
488 | /* Writing into existing tree, extend tree down */ | 489 | /* Writing into existing tree, extend tree down */ |
489 | iblks = height - sheight; | 490 | iblks = height - sheight; |
@@ -605,7 +606,7 @@ int gfs2_block_map(struct inode *inode, sector_t lblock, | |||
605 | struct gfs2_inode *ip = GFS2_I(inode); | 606 | struct gfs2_inode *ip = GFS2_I(inode); |
606 | struct gfs2_sbd *sdp = GFS2_SB(inode); | 607 | struct gfs2_sbd *sdp = GFS2_SB(inode); |
607 | unsigned int bsize = sdp->sd_sb.sb_bsize; | 608 | unsigned int bsize = sdp->sd_sb.sb_bsize; |
608 | const unsigned int maxlen = bh_map->b_size >> inode->i_blkbits; | 609 | const size_t maxlen = bh_map->b_size >> inode->i_blkbits; |
609 | const u64 *arr = sdp->sd_heightsize; | 610 | const u64 *arr = sdp->sd_heightsize; |
610 | __be64 *ptr; | 611 | __be64 *ptr; |
611 | u64 size; | 612 | u64 size; |
diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c index 26b3f952e6b1..7f4ed3daa38c 100644 --- a/fs/gfs2/file.c +++ b/fs/gfs2/file.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/dlm.h> | 26 | #include <linux/dlm.h> |
27 | #include <linux/dlm_plock.h> | 27 | #include <linux/dlm_plock.h> |
28 | #include <linux/aio.h> | 28 | #include <linux/aio.h> |
29 | #include <linux/delay.h> | ||
29 | 30 | ||
30 | #include "gfs2.h" | 31 | #include "gfs2.h" |
31 | #include "incore.h" | 32 | #include "incore.h" |
@@ -979,9 +980,10 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) | |||
979 | unsigned int state; | 980 | unsigned int state; |
980 | int flags; | 981 | int flags; |
981 | int error = 0; | 982 | int error = 0; |
983 | int sleeptime; | ||
982 | 984 | ||
983 | state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; | 985 | state = (fl->fl_type == F_WRLCK) ? LM_ST_EXCLUSIVE : LM_ST_SHARED; |
984 | flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY) | GL_EXACT; | 986 | flags = (IS_SETLKW(cmd) ? 0 : LM_FLAG_TRY_1CB) | GL_EXACT; |
985 | 987 | ||
986 | mutex_lock(&fp->f_fl_mutex); | 988 | mutex_lock(&fp->f_fl_mutex); |
987 | 989 | ||
@@ -1001,7 +1003,14 @@ static int do_flock(struct file *file, int cmd, struct file_lock *fl) | |||
1001 | gfs2_holder_init(gl, state, flags, fl_gh); | 1003 | gfs2_holder_init(gl, state, flags, fl_gh); |
1002 | gfs2_glock_put(gl); | 1004 | gfs2_glock_put(gl); |
1003 | } | 1005 | } |
1004 | error = gfs2_glock_nq(fl_gh); | 1006 | for (sleeptime = 1; sleeptime <= 4; sleeptime <<= 1) { |
1007 | error = gfs2_glock_nq(fl_gh); | ||
1008 | if (error != GLR_TRYFAILED) | ||
1009 | break; | ||
1010 | fl_gh->gh_flags = LM_FLAG_TRY | GL_EXACT; | ||
1011 | fl_gh->gh_error = 0; | ||
1012 | msleep(sleeptime); | ||
1013 | } | ||
1005 | if (error) { | 1014 | if (error) { |
1006 | gfs2_holder_uninit(fl_gh); | 1015 | gfs2_holder_uninit(fl_gh); |
1007 | if (error == GLR_TRYFAILED) | 1016 | if (error == GLR_TRYFAILED) |
@@ -1024,7 +1033,7 @@ static void do_unflock(struct file *file, struct file_lock *fl) | |||
1024 | mutex_lock(&fp->f_fl_mutex); | 1033 | mutex_lock(&fp->f_fl_mutex); |
1025 | flock_lock_file_wait(file, fl); | 1034 | flock_lock_file_wait(file, fl); |
1026 | if (fl_gh->gh_gl) { | 1035 | if (fl_gh->gh_gl) { |
1027 | gfs2_glock_dq_wait(fl_gh); | 1036 | gfs2_glock_dq(fl_gh); |
1028 | gfs2_holder_uninit(fl_gh); | 1037 | gfs2_holder_uninit(fl_gh); |
1029 | } | 1038 | } |
1030 | mutex_unlock(&fp->f_fl_mutex); | 1039 | mutex_unlock(&fp->f_fl_mutex); |
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h index 67d310c9ada3..39e7e9959b74 100644 --- a/fs/gfs2/incore.h +++ b/fs/gfs2/incore.h | |||
@@ -262,6 +262,9 @@ struct gfs2_holder { | |||
262 | unsigned long gh_ip; | 262 | unsigned long gh_ip; |
263 | }; | 263 | }; |
264 | 264 | ||
265 | /* Number of quota types we support */ | ||
266 | #define GFS2_MAXQUOTAS 2 | ||
267 | |||
265 | /* Resource group multi-block reservation, in order of appearance: | 268 | /* Resource group multi-block reservation, in order of appearance: |
266 | 269 | ||
267 | Step 1. Function prepares to write, allocates a mb, sets the size hint. | 270 | Step 1. Function prepares to write, allocates a mb, sets the size hint. |
@@ -282,8 +285,8 @@ struct gfs2_blkreserv { | |||
282 | u64 rs_inum; /* Inode number for reservation */ | 285 | u64 rs_inum; /* Inode number for reservation */ |
283 | 286 | ||
284 | /* ancillary quota stuff */ | 287 | /* ancillary quota stuff */ |
285 | struct gfs2_quota_data *rs_qa_qd[2 * MAXQUOTAS]; | 288 | struct gfs2_quota_data *rs_qa_qd[2 * GFS2_MAXQUOTAS]; |
286 | struct gfs2_holder rs_qa_qd_ghs[2 * MAXQUOTAS]; | 289 | struct gfs2_holder rs_qa_qd_ghs[2 * GFS2_MAXQUOTAS]; |
287 | unsigned int rs_qa_qd_num; | 290 | unsigned int rs_qa_qd_num; |
288 | }; | 291 | }; |
289 | 292 | ||
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c index e62e59477884..fc8ac2ee0667 100644 --- a/fs/gfs2/inode.c +++ b/fs/gfs2/inode.c | |||
@@ -626,8 +626,10 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry, | |||
626 | if (!IS_ERR(inode)) { | 626 | if (!IS_ERR(inode)) { |
627 | d = d_splice_alias(inode, dentry); | 627 | d = d_splice_alias(inode, dentry); |
628 | error = PTR_ERR(d); | 628 | error = PTR_ERR(d); |
629 | if (IS_ERR(d)) | 629 | if (IS_ERR(d)) { |
630 | inode = ERR_CAST(d); | ||
630 | goto fail_gunlock; | 631 | goto fail_gunlock; |
632 | } | ||
631 | error = 0; | 633 | error = 0; |
632 | if (file) { | 634 | if (file) { |
633 | if (S_ISREG(inode->i_mode)) { | 635 | if (S_ISREG(inode->i_mode)) { |
@@ -840,8 +842,10 @@ static struct dentry *__gfs2_lookup(struct inode *dir, struct dentry *dentry, | |||
840 | int error; | 842 | int error; |
841 | 843 | ||
842 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); | 844 | inode = gfs2_lookupi(dir, &dentry->d_name, 0); |
843 | if (!inode) | 845 | if (inode == NULL) { |
846 | d_add(dentry, NULL); | ||
844 | return NULL; | 847 | return NULL; |
848 | } | ||
845 | if (IS_ERR(inode)) | 849 | if (IS_ERR(inode)) |
846 | return ERR_CAST(inode); | 850 | return ERR_CAST(inode); |
847 | 851 | ||
@@ -854,7 +858,6 @@ static struct dentry *__gfs2_lookup(struct inode *dir, struct dentry *dentry, | |||
854 | 858 | ||
855 | d = d_splice_alias(inode, dentry); | 859 | d = d_splice_alias(inode, dentry); |
856 | if (IS_ERR(d)) { | 860 | if (IS_ERR(d)) { |
857 | iput(inode); | ||
858 | gfs2_glock_dq_uninit(&gh); | 861 | gfs2_glock_dq_uninit(&gh); |
859 | return d; | 862 | return d; |
860 | } | 863 | } |
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 2607ff13d486..a346f56c4c6d 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c | |||
@@ -1294,7 +1294,7 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root) | |||
1294 | int val; | 1294 | int val; |
1295 | 1295 | ||
1296 | if (is_ancestor(root, sdp->sd_master_dir)) | 1296 | if (is_ancestor(root, sdp->sd_master_dir)) |
1297 | seq_printf(s, ",meta"); | 1297 | seq_puts(s, ",meta"); |
1298 | if (args->ar_lockproto[0]) | 1298 | if (args->ar_lockproto[0]) |
1299 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); | 1299 | seq_printf(s, ",lockproto=%s", args->ar_lockproto); |
1300 | if (args->ar_locktable[0]) | 1300 | if (args->ar_locktable[0]) |
@@ -1302,13 +1302,13 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root) | |||
1302 | if (args->ar_hostdata[0]) | 1302 | if (args->ar_hostdata[0]) |
1303 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); | 1303 | seq_printf(s, ",hostdata=%s", args->ar_hostdata); |
1304 | if (args->ar_spectator) | 1304 | if (args->ar_spectator) |
1305 | seq_printf(s, ",spectator"); | 1305 | seq_puts(s, ",spectator"); |
1306 | if (args->ar_localflocks) | 1306 | if (args->ar_localflocks) |
1307 | seq_printf(s, ",localflocks"); | 1307 | seq_puts(s, ",localflocks"); |
1308 | if (args->ar_debug) | 1308 | if (args->ar_debug) |
1309 | seq_printf(s, ",debug"); | 1309 | seq_puts(s, ",debug"); |
1310 | if (args->ar_posix_acl) | 1310 | if (args->ar_posix_acl) |
1311 | seq_printf(s, ",acl"); | 1311 | seq_puts(s, ",acl"); |
1312 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { | 1312 | if (args->ar_quota != GFS2_QUOTA_DEFAULT) { |
1313 | char *state; | 1313 | char *state; |
1314 | switch (args->ar_quota) { | 1314 | switch (args->ar_quota) { |
@@ -1328,7 +1328,7 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root) | |||
1328 | seq_printf(s, ",quota=%s", state); | 1328 | seq_printf(s, ",quota=%s", state); |
1329 | } | 1329 | } |
1330 | if (args->ar_suiddir) | 1330 | if (args->ar_suiddir) |
1331 | seq_printf(s, ",suiddir"); | 1331 | seq_puts(s, ",suiddir"); |
1332 | if (args->ar_data != GFS2_DATA_DEFAULT) { | 1332 | if (args->ar_data != GFS2_DATA_DEFAULT) { |
1333 | char *state; | 1333 | char *state; |
1334 | switch (args->ar_data) { | 1334 | switch (args->ar_data) { |
@@ -1345,7 +1345,7 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root) | |||
1345 | seq_printf(s, ",data=%s", state); | 1345 | seq_printf(s, ",data=%s", state); |
1346 | } | 1346 | } |
1347 | if (args->ar_discard) | 1347 | if (args->ar_discard) |
1348 | seq_printf(s, ",discard"); | 1348 | seq_puts(s, ",discard"); |
1349 | val = sdp->sd_tune.gt_logd_secs; | 1349 | val = sdp->sd_tune.gt_logd_secs; |
1350 | if (val != 30) | 1350 | if (val != 30) |
1351 | seq_printf(s, ",commit=%d", val); | 1351 | seq_printf(s, ",commit=%d", val); |
@@ -1376,11 +1376,11 @@ static int gfs2_show_options(struct seq_file *s, struct dentry *root) | |||
1376 | seq_printf(s, ",errors=%s", state); | 1376 | seq_printf(s, ",errors=%s", state); |
1377 | } | 1377 | } |
1378 | if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) | 1378 | if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) |
1379 | seq_printf(s, ",nobarrier"); | 1379 | seq_puts(s, ",nobarrier"); |
1380 | if (test_bit(SDF_DEMOTE, &sdp->sd_flags)) | 1380 | if (test_bit(SDF_DEMOTE, &sdp->sd_flags)) |
1381 | seq_printf(s, ",demote_interface_used"); | 1381 | seq_puts(s, ",demote_interface_used"); |
1382 | if (args->ar_rgrplvb) | 1382 | if (args->ar_rgrplvb) |
1383 | seq_printf(s, ",rgrplvb"); | 1383 | seq_puts(s, ",rgrplvb"); |
1384 | return 0; | 1384 | return 0; |
1385 | } | 1385 | } |
1386 | 1386 | ||
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c index 8f27c93f8d2e..ec9e082f9ecd 100644 --- a/fs/lockd/svc.c +++ b/fs/lockd/svc.c | |||
@@ -253,13 +253,11 @@ static int lockd_up_net(struct svc_serv *serv, struct net *net) | |||
253 | 253 | ||
254 | error = make_socks(serv, net); | 254 | error = make_socks(serv, net); |
255 | if (error < 0) | 255 | if (error < 0) |
256 | goto err_socks; | 256 | goto err_bind; |
257 | set_grace_period(net); | 257 | set_grace_period(net); |
258 | dprintk("lockd_up_net: per-net data created; net=%p\n", net); | 258 | dprintk("lockd_up_net: per-net data created; net=%p\n", net); |
259 | return 0; | 259 | return 0; |
260 | 260 | ||
261 | err_socks: | ||
262 | svc_rpcb_cleanup(serv, net); | ||
263 | err_bind: | 261 | err_bind: |
264 | ln->nlmsvc_users--; | 262 | ln->nlmsvc_users--; |
265 | return error; | 263 | return error; |
diff --git a/fs/namei.c b/fs/namei.c index a996bb48dfab..a7b05bf82d31 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/device_cgroup.h> | 34 | #include <linux/device_cgroup.h> |
35 | #include <linux/fs_struct.h> | 35 | #include <linux/fs_struct.h> |
36 | #include <linux/posix_acl.h> | 36 | #include <linux/posix_acl.h> |
37 | #include <linux/hash.h> | ||
37 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
38 | 39 | ||
39 | #include "internal.h" | 40 | #include "internal.h" |
@@ -643,24 +644,22 @@ static int complete_walk(struct nameidata *nd) | |||
643 | 644 | ||
644 | static __always_inline void set_root(struct nameidata *nd) | 645 | static __always_inline void set_root(struct nameidata *nd) |
645 | { | 646 | { |
646 | if (!nd->root.mnt) | 647 | get_fs_root(current->fs, &nd->root); |
647 | get_fs_root(current->fs, &nd->root); | ||
648 | } | 648 | } |
649 | 649 | ||
650 | static int link_path_walk(const char *, struct nameidata *); | 650 | static int link_path_walk(const char *, struct nameidata *); |
651 | 651 | ||
652 | static __always_inline void set_root_rcu(struct nameidata *nd) | 652 | static __always_inline unsigned set_root_rcu(struct nameidata *nd) |
653 | { | 653 | { |
654 | if (!nd->root.mnt) { | 654 | struct fs_struct *fs = current->fs; |
655 | struct fs_struct *fs = current->fs; | 655 | unsigned seq, res; |
656 | unsigned seq; | ||
657 | 656 | ||
658 | do { | 657 | do { |
659 | seq = read_seqcount_begin(&fs->seq); | 658 | seq = read_seqcount_begin(&fs->seq); |
660 | nd->root = fs->root; | 659 | nd->root = fs->root; |
661 | nd->seq = __read_seqcount_begin(&nd->root.dentry->d_seq); | 660 | res = __read_seqcount_begin(&nd->root.dentry->d_seq); |
662 | } while (read_seqcount_retry(&fs->seq, seq)); | 661 | } while (read_seqcount_retry(&fs->seq, seq)); |
663 | } | 662 | return res; |
664 | } | 663 | } |
665 | 664 | ||
666 | static void path_put_conditional(struct path *path, struct nameidata *nd) | 665 | static void path_put_conditional(struct path *path, struct nameidata *nd) |
@@ -860,7 +859,8 @@ follow_link(struct path *link, struct nameidata *nd, void **p) | |||
860 | return PTR_ERR(s); | 859 | return PTR_ERR(s); |
861 | } | 860 | } |
862 | if (*s == '/') { | 861 | if (*s == '/') { |
863 | set_root(nd); | 862 | if (!nd->root.mnt) |
863 | set_root(nd); | ||
864 | path_put(&nd->path); | 864 | path_put(&nd->path); |
865 | nd->path = nd->root; | 865 | nd->path = nd->root; |
866 | path_get(&nd->root); | 866 | path_get(&nd->root); |
@@ -1137,13 +1137,15 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, | |||
1137 | */ | 1137 | */ |
1138 | *inode = path->dentry->d_inode; | 1138 | *inode = path->dentry->d_inode; |
1139 | } | 1139 | } |
1140 | return read_seqretry(&mount_lock, nd->m_seq) && | 1140 | return !read_seqretry(&mount_lock, nd->m_seq) && |
1141 | !(path->dentry->d_flags & DCACHE_NEED_AUTOMOUNT); | 1141 | !(path->dentry->d_flags & DCACHE_NEED_AUTOMOUNT); |
1142 | } | 1142 | } |
1143 | 1143 | ||
1144 | static int follow_dotdot_rcu(struct nameidata *nd) | 1144 | static int follow_dotdot_rcu(struct nameidata *nd) |
1145 | { | 1145 | { |
1146 | set_root_rcu(nd); | 1146 | struct inode *inode = nd->inode; |
1147 | if (!nd->root.mnt) | ||
1148 | set_root_rcu(nd); | ||
1147 | 1149 | ||
1148 | while (1) { | 1150 | while (1) { |
1149 | if (nd->path.dentry == nd->root.dentry && | 1151 | if (nd->path.dentry == nd->root.dentry && |
@@ -1155,6 +1157,7 @@ static int follow_dotdot_rcu(struct nameidata *nd) | |||
1155 | struct dentry *parent = old->d_parent; | 1157 | struct dentry *parent = old->d_parent; |
1156 | unsigned seq; | 1158 | unsigned seq; |
1157 | 1159 | ||
1160 | inode = parent->d_inode; | ||
1158 | seq = read_seqcount_begin(&parent->d_seq); | 1161 | seq = read_seqcount_begin(&parent->d_seq); |
1159 | if (read_seqcount_retry(&old->d_seq, nd->seq)) | 1162 | if (read_seqcount_retry(&old->d_seq, nd->seq)) |
1160 | goto failed; | 1163 | goto failed; |
@@ -1164,6 +1167,7 @@ static int follow_dotdot_rcu(struct nameidata *nd) | |||
1164 | } | 1167 | } |
1165 | if (!follow_up_rcu(&nd->path)) | 1168 | if (!follow_up_rcu(&nd->path)) |
1166 | break; | 1169 | break; |
1170 | inode = nd->path.dentry->d_inode; | ||
1167 | nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); | 1171 | nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); |
1168 | } | 1172 | } |
1169 | while (d_mountpoint(nd->path.dentry)) { | 1173 | while (d_mountpoint(nd->path.dentry)) { |
@@ -1173,11 +1177,12 @@ static int follow_dotdot_rcu(struct nameidata *nd) | |||
1173 | break; | 1177 | break; |
1174 | nd->path.mnt = &mounted->mnt; | 1178 | nd->path.mnt = &mounted->mnt; |
1175 | nd->path.dentry = mounted->mnt.mnt_root; | 1179 | nd->path.dentry = mounted->mnt.mnt_root; |
1180 | inode = nd->path.dentry->d_inode; | ||
1176 | nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); | 1181 | nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq); |
1177 | if (!read_seqretry(&mount_lock, nd->m_seq)) | 1182 | if (read_seqretry(&mount_lock, nd->m_seq)) |
1178 | goto failed; | 1183 | goto failed; |
1179 | } | 1184 | } |
1180 | nd->inode = nd->path.dentry->d_inode; | 1185 | nd->inode = inode; |
1181 | return 0; | 1186 | return 0; |
1182 | 1187 | ||
1183 | failed: | 1188 | failed: |
@@ -1256,7 +1261,8 @@ static void follow_mount(struct path *path) | |||
1256 | 1261 | ||
1257 | static void follow_dotdot(struct nameidata *nd) | 1262 | static void follow_dotdot(struct nameidata *nd) |
1258 | { | 1263 | { |
1259 | set_root(nd); | 1264 | if (!nd->root.mnt) |
1265 | set_root(nd); | ||
1260 | 1266 | ||
1261 | while(1) { | 1267 | while(1) { |
1262 | struct dentry *old = nd->path.dentry; | 1268 | struct dentry *old = nd->path.dentry; |
@@ -1634,8 +1640,7 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd) | |||
1634 | 1640 | ||
1635 | static inline unsigned int fold_hash(unsigned long hash) | 1641 | static inline unsigned int fold_hash(unsigned long hash) |
1636 | { | 1642 | { |
1637 | hash += hash >> (8*sizeof(int)); | 1643 | return hash_64(hash, 32); |
1638 | return hash; | ||
1639 | } | 1644 | } |
1640 | 1645 | ||
1641 | #else /* 32-bit case */ | 1646 | #else /* 32-bit case */ |
@@ -1669,9 +1674,9 @@ EXPORT_SYMBOL(full_name_hash); | |||
1669 | 1674 | ||
1670 | /* | 1675 | /* |
1671 | * Calculate the length and hash of the path component, and | 1676 | * Calculate the length and hash of the path component, and |
1672 | * return the length of the component; | 1677 | * return the "hash_len" as the result. |
1673 | */ | 1678 | */ |
1674 | static inline unsigned long hash_name(const char *name, unsigned int *hashp) | 1679 | static inline u64 hash_name(const char *name) |
1675 | { | 1680 | { |
1676 | unsigned long a, b, adata, bdata, mask, hash, len; | 1681 | unsigned long a, b, adata, bdata, mask, hash, len; |
1677 | const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; | 1682 | const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; |
@@ -1691,9 +1696,8 @@ static inline unsigned long hash_name(const char *name, unsigned int *hashp) | |||
1691 | mask = create_zero_mask(adata | bdata); | 1696 | mask = create_zero_mask(adata | bdata); |
1692 | 1697 | ||
1693 | hash += a & zero_bytemask(mask); | 1698 | hash += a & zero_bytemask(mask); |
1694 | *hashp = fold_hash(hash); | 1699 | len += find_zero(mask); |
1695 | 1700 | return hashlen_create(fold_hash(hash), len); | |
1696 | return len + find_zero(mask); | ||
1697 | } | 1701 | } |
1698 | 1702 | ||
1699 | #else | 1703 | #else |
@@ -1711,7 +1715,7 @@ EXPORT_SYMBOL(full_name_hash); | |||
1711 | * We know there's a real path component here of at least | 1715 | * We know there's a real path component here of at least |
1712 | * one character. | 1716 | * one character. |
1713 | */ | 1717 | */ |
1714 | static inline unsigned long hash_name(const char *name, unsigned int *hashp) | 1718 | static inline u64 hash_name(const char *name) |
1715 | { | 1719 | { |
1716 | unsigned long hash = init_name_hash(); | 1720 | unsigned long hash = init_name_hash(); |
1717 | unsigned long len = 0, c; | 1721 | unsigned long len = 0, c; |
@@ -1722,8 +1726,7 @@ static inline unsigned long hash_name(const char *name, unsigned int *hashp) | |||
1722 | hash = partial_name_hash(c, hash); | 1726 | hash = partial_name_hash(c, hash); |
1723 | c = (unsigned char)name[len]; | 1727 | c = (unsigned char)name[len]; |
1724 | } while (c && c != '/'); | 1728 | } while (c && c != '/'); |
1725 | *hashp = end_name_hash(hash); | 1729 | return hashlen_create(end_name_hash(hash), len); |
1726 | return len; | ||
1727 | } | 1730 | } |
1728 | 1731 | ||
1729 | #endif | 1732 | #endif |
@@ -1748,20 +1751,17 @@ static int link_path_walk(const char *name, struct nameidata *nd) | |||
1748 | 1751 | ||
1749 | /* At this point we know we have a real path component. */ | 1752 | /* At this point we know we have a real path component. */ |
1750 | for(;;) { | 1753 | for(;;) { |
1751 | struct qstr this; | 1754 | u64 hash_len; |
1752 | long len; | ||
1753 | int type; | 1755 | int type; |
1754 | 1756 | ||
1755 | err = may_lookup(nd); | 1757 | err = may_lookup(nd); |
1756 | if (err) | 1758 | if (err) |
1757 | break; | 1759 | break; |
1758 | 1760 | ||
1759 | len = hash_name(name, &this.hash); | 1761 | hash_len = hash_name(name); |
1760 | this.name = name; | ||
1761 | this.len = len; | ||
1762 | 1762 | ||
1763 | type = LAST_NORM; | 1763 | type = LAST_NORM; |
1764 | if (name[0] == '.') switch (len) { | 1764 | if (name[0] == '.') switch (hashlen_len(hash_len)) { |
1765 | case 2: | 1765 | case 2: |
1766 | if (name[1] == '.') { | 1766 | if (name[1] == '.') { |
1767 | type = LAST_DOTDOT; | 1767 | type = LAST_DOTDOT; |
@@ -1775,29 +1775,32 @@ static int link_path_walk(const char *name, struct nameidata *nd) | |||
1775 | struct dentry *parent = nd->path.dentry; | 1775 | struct dentry *parent = nd->path.dentry; |
1776 | nd->flags &= ~LOOKUP_JUMPED; | 1776 | nd->flags &= ~LOOKUP_JUMPED; |
1777 | if (unlikely(parent->d_flags & DCACHE_OP_HASH)) { | 1777 | if (unlikely(parent->d_flags & DCACHE_OP_HASH)) { |
1778 | struct qstr this = { { .hash_len = hash_len }, .name = name }; | ||
1778 | err = parent->d_op->d_hash(parent, &this); | 1779 | err = parent->d_op->d_hash(parent, &this); |
1779 | if (err < 0) | 1780 | if (err < 0) |
1780 | break; | 1781 | break; |
1782 | hash_len = this.hash_len; | ||
1783 | name = this.name; | ||
1781 | } | 1784 | } |
1782 | } | 1785 | } |
1783 | 1786 | ||
1784 | nd->last = this; | 1787 | nd->last.hash_len = hash_len; |
1788 | nd->last.name = name; | ||
1785 | nd->last_type = type; | 1789 | nd->last_type = type; |
1786 | 1790 | ||
1787 | if (!name[len]) | 1791 | name += hashlen_len(hash_len); |
1792 | if (!*name) | ||
1788 | return 0; | 1793 | return 0; |
1789 | /* | 1794 | /* |
1790 | * If it wasn't NUL, we know it was '/'. Skip that | 1795 | * If it wasn't NUL, we know it was '/'. Skip that |
1791 | * slash, and continue until no more slashes. | 1796 | * slash, and continue until no more slashes. |
1792 | */ | 1797 | */ |
1793 | do { | 1798 | do { |
1794 | len++; | 1799 | name++; |
1795 | } while (unlikely(name[len] == '/')); | 1800 | } while (unlikely(*name == '/')); |
1796 | if (!name[len]) | 1801 | if (!*name) |
1797 | return 0; | 1802 | return 0; |
1798 | 1803 | ||
1799 | name += len; | ||
1800 | |||
1801 | err = walk_component(nd, &next, LOOKUP_FOLLOW); | 1804 | err = walk_component(nd, &next, LOOKUP_FOLLOW); |
1802 | if (err < 0) | 1805 | if (err < 0) |
1803 | return err; | 1806 | return err; |
@@ -1852,7 +1855,7 @@ static int path_init(int dfd, const char *name, unsigned int flags, | |||
1852 | if (*name=='/') { | 1855 | if (*name=='/') { |
1853 | if (flags & LOOKUP_RCU) { | 1856 | if (flags & LOOKUP_RCU) { |
1854 | rcu_read_lock(); | 1857 | rcu_read_lock(); |
1855 | set_root_rcu(nd); | 1858 | nd->seq = set_root_rcu(nd); |
1856 | } else { | 1859 | } else { |
1857 | set_root(nd); | 1860 | set_root(nd); |
1858 | path_get(&nd->root); | 1861 | path_get(&nd->root); |
@@ -1903,7 +1906,14 @@ static int path_init(int dfd, const char *name, unsigned int flags, | |||
1903 | } | 1906 | } |
1904 | 1907 | ||
1905 | nd->inode = nd->path.dentry->d_inode; | 1908 | nd->inode = nd->path.dentry->d_inode; |
1906 | return 0; | 1909 | if (!(flags & LOOKUP_RCU)) |
1910 | return 0; | ||
1911 | if (likely(!read_seqcount_retry(&nd->path.dentry->d_seq, nd->seq))) | ||
1912 | return 0; | ||
1913 | if (!(nd->flags & LOOKUP_ROOT)) | ||
1914 | nd->root.mnt = NULL; | ||
1915 | rcu_read_unlock(); | ||
1916 | return -ECHILD; | ||
1907 | } | 1917 | } |
1908 | 1918 | ||
1909 | static inline int lookup_last(struct nameidata *nd, struct path *path) | 1919 | static inline int lookup_last(struct nameidata *nd, struct path *path) |
diff --git a/fs/namespace.c b/fs/namespace.c index a01c7730e9af..ef42d9bee212 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -1217,6 +1217,11 @@ static void namespace_unlock(void) | |||
1217 | head.first->pprev = &head.first; | 1217 | head.first->pprev = &head.first; |
1218 | INIT_HLIST_HEAD(&unmounted); | 1218 | INIT_HLIST_HEAD(&unmounted); |
1219 | 1219 | ||
1220 | /* undo decrements we'd done in umount_tree() */ | ||
1221 | hlist_for_each_entry(mnt, &head, mnt_hash) | ||
1222 | if (mnt->mnt_ex_mountpoint.mnt) | ||
1223 | mntget(mnt->mnt_ex_mountpoint.mnt); | ||
1224 | |||
1220 | up_write(&namespace_sem); | 1225 | up_write(&namespace_sem); |
1221 | 1226 | ||
1222 | synchronize_rcu(); | 1227 | synchronize_rcu(); |
@@ -1253,6 +1258,9 @@ void umount_tree(struct mount *mnt, int how) | |||
1253 | hlist_add_head(&p->mnt_hash, &tmp_list); | 1258 | hlist_add_head(&p->mnt_hash, &tmp_list); |
1254 | } | 1259 | } |
1255 | 1260 | ||
1261 | hlist_for_each_entry(p, &tmp_list, mnt_hash) | ||
1262 | list_del_init(&p->mnt_child); | ||
1263 | |||
1256 | if (how) | 1264 | if (how) |
1257 | propagate_umount(&tmp_list); | 1265 | propagate_umount(&tmp_list); |
1258 | 1266 | ||
@@ -1263,9 +1271,9 @@ void umount_tree(struct mount *mnt, int how) | |||
1263 | p->mnt_ns = NULL; | 1271 | p->mnt_ns = NULL; |
1264 | if (how < 2) | 1272 | if (how < 2) |
1265 | p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; | 1273 | p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; |
1266 | list_del_init(&p->mnt_child); | ||
1267 | if (mnt_has_parent(p)) { | 1274 | if (mnt_has_parent(p)) { |
1268 | put_mountpoint(p->mnt_mp); | 1275 | put_mountpoint(p->mnt_mp); |
1276 | mnt_add_count(p->mnt_parent, -1); | ||
1269 | /* move the reference to mountpoint into ->mnt_ex_mountpoint */ | 1277 | /* move the reference to mountpoint into ->mnt_ex_mountpoint */ |
1270 | p->mnt_ex_mountpoint.dentry = p->mnt_mountpoint; | 1278 | p->mnt_ex_mountpoint.dentry = p->mnt_mountpoint; |
1271 | p->mnt_ex_mountpoint.mnt = &p->mnt_parent->mnt; | 1279 | p->mnt_ex_mountpoint.mnt = &p->mnt_parent->mnt; |
diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 1c5ff6d58385..6a4f3666e273 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c | |||
@@ -1412,24 +1412,18 @@ int nfs_fs_proc_net_init(struct net *net) | |||
1412 | p = proc_create("volumes", S_IFREG|S_IRUGO, | 1412 | p = proc_create("volumes", S_IFREG|S_IRUGO, |
1413 | nn->proc_nfsfs, &nfs_volume_list_fops); | 1413 | nn->proc_nfsfs, &nfs_volume_list_fops); |
1414 | if (!p) | 1414 | if (!p) |
1415 | goto error_2; | 1415 | goto error_1; |
1416 | return 0; | 1416 | return 0; |
1417 | 1417 | ||
1418 | error_2: | ||
1419 | remove_proc_entry("servers", nn->proc_nfsfs); | ||
1420 | error_1: | 1418 | error_1: |
1421 | remove_proc_entry("fs/nfsfs", NULL); | 1419 | remove_proc_subtree("nfsfs", net->proc_net); |
1422 | error_0: | 1420 | error_0: |
1423 | return -ENOMEM; | 1421 | return -ENOMEM; |
1424 | } | 1422 | } |
1425 | 1423 | ||
1426 | void nfs_fs_proc_net_exit(struct net *net) | 1424 | void nfs_fs_proc_net_exit(struct net *net) |
1427 | { | 1425 | { |
1428 | struct nfs_net *nn = net_generic(net, nfs_net_id); | 1426 | remove_proc_subtree("nfsfs", net->proc_net); |
1429 | |||
1430 | remove_proc_entry("volumes", nn->proc_nfsfs); | ||
1431 | remove_proc_entry("servers", nn->proc_nfsfs); | ||
1432 | remove_proc_entry("fs/nfsfs", NULL); | ||
1433 | } | 1427 | } |
1434 | 1428 | ||
1435 | /* | 1429 | /* |
diff --git a/fs/nfs/filelayout/filelayout.c b/fs/nfs/filelayout/filelayout.c index 1359c4a27393..90978075f730 100644 --- a/fs/nfs/filelayout/filelayout.c +++ b/fs/nfs/filelayout/filelayout.c | |||
@@ -1269,11 +1269,12 @@ filelayout_search_commit_reqs(struct nfs_commit_info *cinfo, struct page *page) | |||
1269 | static void filelayout_retry_commit(struct nfs_commit_info *cinfo, int idx) | 1269 | static void filelayout_retry_commit(struct nfs_commit_info *cinfo, int idx) |
1270 | { | 1270 | { |
1271 | struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; | 1271 | struct pnfs_ds_commit_info *fl_cinfo = cinfo->ds; |
1272 | struct pnfs_commit_bucket *bucket = fl_cinfo->buckets; | 1272 | struct pnfs_commit_bucket *bucket; |
1273 | struct pnfs_layout_segment *freeme; | 1273 | struct pnfs_layout_segment *freeme; |
1274 | int i; | 1274 | int i; |
1275 | 1275 | ||
1276 | for (i = idx; i < fl_cinfo->nbuckets; i++, bucket++) { | 1276 | for (i = idx; i < fl_cinfo->nbuckets; i++) { |
1277 | bucket = &fl_cinfo->buckets[i]; | ||
1277 | if (list_empty(&bucket->committing)) | 1278 | if (list_empty(&bucket->committing)) |
1278 | continue; | 1279 | continue; |
1279 | nfs_retry_commit(&bucket->committing, bucket->clseg, cinfo); | 1280 | nfs_retry_commit(&bucket->committing, bucket->clseg, cinfo); |
diff --git a/fs/nfs/nfs4_fs.h b/fs/nfs/nfs4_fs.h index 92193eddb41d..a8b855ab4e22 100644 --- a/fs/nfs/nfs4_fs.h +++ b/fs/nfs/nfs4_fs.h | |||
@@ -130,16 +130,15 @@ enum { | |||
130 | */ | 130 | */ |
131 | 131 | ||
132 | struct nfs4_lock_state { | 132 | struct nfs4_lock_state { |
133 | struct list_head ls_locks; /* Other lock stateids */ | 133 | struct list_head ls_locks; /* Other lock stateids */ |
134 | struct nfs4_state * ls_state; /* Pointer to open state */ | 134 | struct nfs4_state * ls_state; /* Pointer to open state */ |
135 | #define NFS_LOCK_INITIALIZED 0 | 135 | #define NFS_LOCK_INITIALIZED 0 |
136 | #define NFS_LOCK_LOST 1 | 136 | #define NFS_LOCK_LOST 1 |
137 | unsigned long ls_flags; | 137 | unsigned long ls_flags; |
138 | struct nfs_seqid_counter ls_seqid; | 138 | struct nfs_seqid_counter ls_seqid; |
139 | nfs4_stateid ls_stateid; | 139 | nfs4_stateid ls_stateid; |
140 | atomic_t ls_count; | 140 | atomic_t ls_count; |
141 | fl_owner_t ls_owner; | 141 | fl_owner_t ls_owner; |
142 | struct work_struct ls_release; | ||
143 | }; | 142 | }; |
144 | 143 | ||
145 | /* bits for nfs4_state->flags */ | 144 | /* bits for nfs4_state->flags */ |
diff --git a/fs/nfs/nfs4client.c b/fs/nfs/nfs4client.c index 53e435a95260..ffdb28d86cf8 100644 --- a/fs/nfs/nfs4client.c +++ b/fs/nfs/nfs4client.c | |||
@@ -482,6 +482,16 @@ int nfs40_walk_client_list(struct nfs_client *new, | |||
482 | 482 | ||
483 | spin_lock(&nn->nfs_client_lock); | 483 | spin_lock(&nn->nfs_client_lock); |
484 | list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) { | 484 | list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) { |
485 | |||
486 | if (pos->rpc_ops != new->rpc_ops) | ||
487 | continue; | ||
488 | |||
489 | if (pos->cl_proto != new->cl_proto) | ||
490 | continue; | ||
491 | |||
492 | if (pos->cl_minorversion != new->cl_minorversion) | ||
493 | continue; | ||
494 | |||
485 | /* If "pos" isn't marked ready, we can't trust the | 495 | /* If "pos" isn't marked ready, we can't trust the |
486 | * remaining fields in "pos" */ | 496 | * remaining fields in "pos" */ |
487 | if (pos->cl_cons_state > NFS_CS_READY) { | 497 | if (pos->cl_cons_state > NFS_CS_READY) { |
@@ -501,15 +511,6 @@ int nfs40_walk_client_list(struct nfs_client *new, | |||
501 | if (pos->cl_cons_state != NFS_CS_READY) | 511 | if (pos->cl_cons_state != NFS_CS_READY) |
502 | continue; | 512 | continue; |
503 | 513 | ||
504 | if (pos->rpc_ops != new->rpc_ops) | ||
505 | continue; | ||
506 | |||
507 | if (pos->cl_proto != new->cl_proto) | ||
508 | continue; | ||
509 | |||
510 | if (pos->cl_minorversion != new->cl_minorversion) | ||
511 | continue; | ||
512 | |||
513 | if (pos->cl_clientid != new->cl_clientid) | 514 | if (pos->cl_clientid != new->cl_clientid) |
514 | continue; | 515 | continue; |
515 | 516 | ||
@@ -622,6 +623,16 @@ int nfs41_walk_client_list(struct nfs_client *new, | |||
622 | 623 | ||
623 | spin_lock(&nn->nfs_client_lock); | 624 | spin_lock(&nn->nfs_client_lock); |
624 | list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) { | 625 | list_for_each_entry(pos, &nn->nfs_client_list, cl_share_link) { |
626 | |||
627 | if (pos->rpc_ops != new->rpc_ops) | ||
628 | continue; | ||
629 | |||
630 | if (pos->cl_proto != new->cl_proto) | ||
631 | continue; | ||
632 | |||
633 | if (pos->cl_minorversion != new->cl_minorversion) | ||
634 | continue; | ||
635 | |||
625 | /* If "pos" isn't marked ready, we can't trust the | 636 | /* If "pos" isn't marked ready, we can't trust the |
626 | * remaining fields in "pos", especially the client | 637 | * remaining fields in "pos", especially the client |
627 | * ID and serverowner fields. Wait for CREATE_SESSION | 638 | * ID and serverowner fields. Wait for CREATE_SESSION |
@@ -647,15 +658,6 @@ int nfs41_walk_client_list(struct nfs_client *new, | |||
647 | if (pos->cl_cons_state != NFS_CS_READY) | 658 | if (pos->cl_cons_state != NFS_CS_READY) |
648 | continue; | 659 | continue; |
649 | 660 | ||
650 | if (pos->rpc_ops != new->rpc_ops) | ||
651 | continue; | ||
652 | |||
653 | if (pos->cl_proto != new->cl_proto) | ||
654 | continue; | ||
655 | |||
656 | if (pos->cl_minorversion != new->cl_minorversion) | ||
657 | continue; | ||
658 | |||
659 | if (!nfs4_match_clientids(pos, new)) | 661 | if (!nfs4_match_clientids(pos, new)) |
660 | continue; | 662 | continue; |
661 | 663 | ||
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 7dd8aca31c29..6ca0c8e7a945 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -2226,9 +2226,13 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata, | |||
2226 | ret = _nfs4_proc_open(opendata); | 2226 | ret = _nfs4_proc_open(opendata); |
2227 | if (ret != 0) { | 2227 | if (ret != 0) { |
2228 | if (ret == -ENOENT) { | 2228 | if (ret == -ENOENT) { |
2229 | d_drop(opendata->dentry); | 2229 | dentry = opendata->dentry; |
2230 | d_add(opendata->dentry, NULL); | 2230 | if (dentry->d_inode) |
2231 | nfs_set_verifier(opendata->dentry, | 2231 | d_delete(dentry); |
2232 | else if (d_unhashed(dentry)) | ||
2233 | d_add(dentry, NULL); | ||
2234 | |||
2235 | nfs_set_verifier(dentry, | ||
2232 | nfs_save_change_attribute(opendata->dir->d_inode)); | 2236 | nfs_save_change_attribute(opendata->dir->d_inode)); |
2233 | } | 2237 | } |
2234 | goto out; | 2238 | goto out; |
@@ -2614,23 +2618,23 @@ static void nfs4_close_prepare(struct rpc_task *task, void *data) | |||
2614 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); | 2618 | is_rdwr = test_bit(NFS_O_RDWR_STATE, &state->flags); |
2615 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); | 2619 | is_rdonly = test_bit(NFS_O_RDONLY_STATE, &state->flags); |
2616 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); | 2620 | is_wronly = test_bit(NFS_O_WRONLY_STATE, &state->flags); |
2617 | /* Calculate the current open share mode */ | ||
2618 | calldata->arg.fmode = 0; | ||
2619 | if (is_rdonly || is_rdwr) | ||
2620 | calldata->arg.fmode |= FMODE_READ; | ||
2621 | if (is_wronly || is_rdwr) | ||
2622 | calldata->arg.fmode |= FMODE_WRITE; | ||
2623 | /* Calculate the change in open mode */ | 2621 | /* Calculate the change in open mode */ |
2622 | calldata->arg.fmode = 0; | ||
2624 | if (state->n_rdwr == 0) { | 2623 | if (state->n_rdwr == 0) { |
2625 | if (state->n_rdonly == 0) { | 2624 | if (state->n_rdonly == 0) |
2626 | call_close |= is_rdonly || is_rdwr; | 2625 | call_close |= is_rdonly; |
2627 | calldata->arg.fmode &= ~FMODE_READ; | 2626 | else if (is_rdonly) |
2628 | } | 2627 | calldata->arg.fmode |= FMODE_READ; |
2629 | if (state->n_wronly == 0) { | 2628 | if (state->n_wronly == 0) |
2630 | call_close |= is_wronly || is_rdwr; | 2629 | call_close |= is_wronly; |
2631 | calldata->arg.fmode &= ~FMODE_WRITE; | 2630 | else if (is_wronly) |
2632 | } | 2631 | calldata->arg.fmode |= FMODE_WRITE; |
2633 | } | 2632 | } else if (is_rdwr) |
2633 | calldata->arg.fmode |= FMODE_READ|FMODE_WRITE; | ||
2634 | |||
2635 | if (calldata->arg.fmode == 0) | ||
2636 | call_close |= is_rdwr; | ||
2637 | |||
2634 | if (!nfs4_valid_open_stateid(state)) | 2638 | if (!nfs4_valid_open_stateid(state)) |
2635 | call_close = 0; | 2639 | call_close = 0; |
2636 | spin_unlock(&state->owner->so_lock); | 2640 | spin_unlock(&state->owner->so_lock); |
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c index a043f618cd5a..22fe35104c0c 100644 --- a/fs/nfs/nfs4state.c +++ b/fs/nfs/nfs4state.c | |||
@@ -799,18 +799,6 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) | |||
799 | return NULL; | 799 | return NULL; |
800 | } | 800 | } |
801 | 801 | ||
802 | static void | ||
803 | free_lock_state_work(struct work_struct *work) | ||
804 | { | ||
805 | struct nfs4_lock_state *lsp = container_of(work, | ||
806 | struct nfs4_lock_state, ls_release); | ||
807 | struct nfs4_state *state = lsp->ls_state; | ||
808 | struct nfs_server *server = state->owner->so_server; | ||
809 | struct nfs_client *clp = server->nfs_client; | ||
810 | |||
811 | clp->cl_mvops->free_lock_state(server, lsp); | ||
812 | } | ||
813 | |||
814 | /* | 802 | /* |
815 | * Return a compatible lock_state. If no initialized lock_state structure | 803 | * Return a compatible lock_state. If no initialized lock_state structure |
816 | * exists, return an uninitialized one. | 804 | * exists, return an uninitialized one. |
@@ -832,7 +820,6 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f | |||
832 | if (lsp->ls_seqid.owner_id < 0) | 820 | if (lsp->ls_seqid.owner_id < 0) |
833 | goto out_free; | 821 | goto out_free; |
834 | INIT_LIST_HEAD(&lsp->ls_locks); | 822 | INIT_LIST_HEAD(&lsp->ls_locks); |
835 | INIT_WORK(&lsp->ls_release, free_lock_state_work); | ||
836 | return lsp; | 823 | return lsp; |
837 | out_free: | 824 | out_free: |
838 | kfree(lsp); | 825 | kfree(lsp); |
@@ -896,12 +883,13 @@ void nfs4_put_lock_state(struct nfs4_lock_state *lsp) | |||
896 | if (list_empty(&state->lock_states)) | 883 | if (list_empty(&state->lock_states)) |
897 | clear_bit(LK_STATE_IN_USE, &state->flags); | 884 | clear_bit(LK_STATE_IN_USE, &state->flags); |
898 | spin_unlock(&state->state_lock); | 885 | spin_unlock(&state->state_lock); |
899 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) | 886 | server = state->owner->so_server; |
900 | queue_work(nfsiod_workqueue, &lsp->ls_release); | 887 | if (test_bit(NFS_LOCK_INITIALIZED, &lsp->ls_flags)) { |
901 | else { | 888 | struct nfs_client *clp = server->nfs_client; |
902 | server = state->owner->so_server; | 889 | |
890 | clp->cl_mvops->free_lock_state(server, lsp); | ||
891 | } else | ||
903 | nfs4_free_lock_state(server, lsp); | 892 | nfs4_free_lock_state(server, lsp); |
904 | } | ||
905 | } | 893 | } |
906 | 894 | ||
907 | static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) | 895 | static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) |
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c index f9821ce6658a..b01f6e100ee8 100644 --- a/fs/nfsd/nfs4xdr.c +++ b/fs/nfsd/nfs4xdr.c | |||
@@ -2657,6 +2657,7 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, | |||
2657 | struct xdr_stream *xdr = cd->xdr; | 2657 | struct xdr_stream *xdr = cd->xdr; |
2658 | int start_offset = xdr->buf->len; | 2658 | int start_offset = xdr->buf->len; |
2659 | int cookie_offset; | 2659 | int cookie_offset; |
2660 | u32 name_and_cookie; | ||
2660 | int entry_bytes; | 2661 | int entry_bytes; |
2661 | __be32 nfserr = nfserr_toosmall; | 2662 | __be32 nfserr = nfserr_toosmall; |
2662 | __be64 wire_offset; | 2663 | __be64 wire_offset; |
@@ -2718,7 +2719,14 @@ nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, | |||
2718 | cd->rd_maxcount -= entry_bytes; | 2719 | cd->rd_maxcount -= entry_bytes; |
2719 | if (!cd->rd_dircount) | 2720 | if (!cd->rd_dircount) |
2720 | goto fail; | 2721 | goto fail; |
2721 | cd->rd_dircount--; | 2722 | /* |
2723 | * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so | ||
2724 | * let's always let through the first entry, at least: | ||
2725 | */ | ||
2726 | name_and_cookie = 4 * XDR_QUADLEN(namlen) + 8; | ||
2727 | if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) | ||
2728 | goto fail; | ||
2729 | cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); | ||
2722 | cd->cookie_offset = cookie_offset; | 2730 | cd->cookie_offset = cookie_offset; |
2723 | skip_entry: | 2731 | skip_entry: |
2724 | cd->common.err = nfs_ok; | 2732 | cd->common.err = nfs_ok; |
@@ -3096,7 +3104,8 @@ static __be32 nfsd4_encode_splice_read( | |||
3096 | 3104 | ||
3097 | buf->page_len = maxcount; | 3105 | buf->page_len = maxcount; |
3098 | buf->len += maxcount; | 3106 | buf->len += maxcount; |
3099 | xdr->page_ptr += (maxcount + PAGE_SIZE - 1) / PAGE_SIZE; | 3107 | xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) |
3108 | / PAGE_SIZE; | ||
3100 | 3109 | ||
3101 | /* Use rest of head for padding and remaining ops: */ | 3110 | /* Use rest of head for padding and remaining ops: */ |
3102 | buf->tail[0].iov_base = xdr->p; | 3111 | buf->tail[0].iov_base = xdr->p; |
@@ -3321,6 +3330,10 @@ nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4 | |||
3321 | } | 3330 | } |
3322 | maxcount = min_t(int, maxcount-16, bytes_left); | 3331 | maxcount = min_t(int, maxcount-16, bytes_left); |
3323 | 3332 | ||
3333 | /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ | ||
3334 | if (!readdir->rd_dircount) | ||
3335 | readdir->rd_dircount = INT_MAX; | ||
3336 | |||
3324 | readdir->xdr = xdr; | 3337 | readdir->xdr = xdr; |
3325 | readdir->rd_maxcount = maxcount; | 3338 | readdir->rd_maxcount = maxcount; |
3326 | readdir->common.err = 0; | 3339 | readdir->common.err = 0; |
diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index 6252b173a465..d071e7f23de2 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/buffer_head.h> | 24 | #include <linux/buffer_head.h> |
25 | #include <linux/gfp.h> | 25 | #include <linux/gfp.h> |
26 | #include <linux/mpage.h> | 26 | #include <linux/mpage.h> |
27 | #include <linux/pagemap.h> | ||
27 | #include <linux/writeback.h> | 28 | #include <linux/writeback.h> |
28 | #include <linux/aio.h> | 29 | #include <linux/aio.h> |
29 | #include "nilfs.h" | 30 | #include "nilfs.h" |
@@ -219,10 +220,10 @@ static int nilfs_writepage(struct page *page, struct writeback_control *wbc) | |||
219 | 220 | ||
220 | static int nilfs_set_page_dirty(struct page *page) | 221 | static int nilfs_set_page_dirty(struct page *page) |
221 | { | 222 | { |
223 | struct inode *inode = page->mapping->host; | ||
222 | int ret = __set_page_dirty_nobuffers(page); | 224 | int ret = __set_page_dirty_nobuffers(page); |
223 | 225 | ||
224 | if (page_has_buffers(page)) { | 226 | if (page_has_buffers(page)) { |
225 | struct inode *inode = page->mapping->host; | ||
226 | unsigned nr_dirty = 0; | 227 | unsigned nr_dirty = 0; |
227 | struct buffer_head *bh, *head; | 228 | struct buffer_head *bh, *head; |
228 | 229 | ||
@@ -245,6 +246,10 @@ static int nilfs_set_page_dirty(struct page *page) | |||
245 | 246 | ||
246 | if (nr_dirty) | 247 | if (nr_dirty) |
247 | nilfs_set_file_dirty(inode, nr_dirty); | 248 | nilfs_set_file_dirty(inode, nr_dirty); |
249 | } else if (ret) { | ||
250 | unsigned nr_dirty = 1 << (PAGE_CACHE_SHIFT - inode->i_blkbits); | ||
251 | |||
252 | nilfs_set_file_dirty(inode, nr_dirty); | ||
248 | } | 253 | } |
249 | return ret; | 254 | return ret; |
250 | } | 255 | } |
diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c index 238a5930cb3c..9d7e2b9659cb 100644 --- a/fs/notify/fdinfo.c +++ b/fs/notify/fdinfo.c | |||
@@ -42,7 +42,7 @@ static int show_mark_fhandle(struct seq_file *m, struct inode *inode) | |||
42 | { | 42 | { |
43 | struct { | 43 | struct { |
44 | struct file_handle handle; | 44 | struct file_handle handle; |
45 | u8 pad[64]; | 45 | u8 pad[MAX_HANDLE_SZ]; |
46 | } f; | 46 | } f; |
47 | int size, ret, i; | 47 | int size, ret, i; |
48 | 48 | ||
@@ -50,7 +50,7 @@ static int show_mark_fhandle(struct seq_file *m, struct inode *inode) | |||
50 | size = f.handle.handle_bytes >> 2; | 50 | size = f.handle.handle_bytes >> 2; |
51 | 51 | ||
52 | ret = exportfs_encode_inode_fh(inode, (struct fid *)f.handle.f_handle, &size, 0); | 52 | ret = exportfs_encode_inode_fh(inode, (struct fid *)f.handle.f_handle, &size, 0); |
53 | if ((ret == 255) || (ret == -ENOSPC)) { | 53 | if ((ret == FILEID_INVALID) || (ret < 0)) { |
54 | WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret); | 54 | WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret); |
55 | return 0; | 55 | return 0; |
56 | } | 56 | } |
diff --git a/fs/ocfs2/dlm/dlmmaster.c b/fs/ocfs2/dlm/dlmmaster.c index 3ec906ef5d9a..12ba682fc53c 100644 --- a/fs/ocfs2/dlm/dlmmaster.c +++ b/fs/ocfs2/dlm/dlmmaster.c | |||
@@ -655,12 +655,9 @@ void dlm_lockres_clear_refmap_bit(struct dlm_ctxt *dlm, | |||
655 | clear_bit(bit, res->refmap); | 655 | clear_bit(bit, res->refmap); |
656 | } | 656 | } |
657 | 657 | ||
658 | 658 | static void __dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, | |
659 | void dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, | ||
660 | struct dlm_lock_resource *res) | 659 | struct dlm_lock_resource *res) |
661 | { | 660 | { |
662 | assert_spin_locked(&res->spinlock); | ||
663 | |||
664 | res->inflight_locks++; | 661 | res->inflight_locks++; |
665 | 662 | ||
666 | mlog(0, "%s: res %.*s, inflight++: now %u, %ps()\n", dlm->name, | 663 | mlog(0, "%s: res %.*s, inflight++: now %u, %ps()\n", dlm->name, |
@@ -668,6 +665,13 @@ void dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, | |||
668 | __builtin_return_address(0)); | 665 | __builtin_return_address(0)); |
669 | } | 666 | } |
670 | 667 | ||
668 | void dlm_lockres_grab_inflight_ref(struct dlm_ctxt *dlm, | ||
669 | struct dlm_lock_resource *res) | ||
670 | { | ||
671 | assert_spin_locked(&res->spinlock); | ||
672 | __dlm_lockres_grab_inflight_ref(dlm, res); | ||
673 | } | ||
674 | |||
671 | void dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm, | 675 | void dlm_lockres_drop_inflight_ref(struct dlm_ctxt *dlm, |
672 | struct dlm_lock_resource *res) | 676 | struct dlm_lock_resource *res) |
673 | { | 677 | { |
@@ -894,10 +898,8 @@ lookup: | |||
894 | /* finally add the lockres to its hash bucket */ | 898 | /* finally add the lockres to its hash bucket */ |
895 | __dlm_insert_lockres(dlm, res); | 899 | __dlm_insert_lockres(dlm, res); |
896 | 900 | ||
897 | /* Grab inflight ref to pin the resource */ | 901 | /* since this lockres is new it doesn't not require the spinlock */ |
898 | spin_lock(&res->spinlock); | 902 | __dlm_lockres_grab_inflight_ref(dlm, res); |
899 | dlm_lockres_grab_inflight_ref(dlm, res); | ||
900 | spin_unlock(&res->spinlock); | ||
901 | 903 | ||
902 | /* get an extra ref on the mle in case this is a BLOCK | 904 | /* get an extra ref on the mle in case this is a BLOCK |
903 | * if so, the creator of the BLOCK may try to put the last | 905 | * if so, the creator of the BLOCK may try to put the last |
@@ -2037,6 +2039,10 @@ kill: | |||
2037 | "and killing the other node now! This node is OK and can continue.\n"); | 2039 | "and killing the other node now! This node is OK and can continue.\n"); |
2038 | __dlm_print_one_lock_resource(res); | 2040 | __dlm_print_one_lock_resource(res); |
2039 | spin_unlock(&res->spinlock); | 2041 | spin_unlock(&res->spinlock); |
2042 | spin_lock(&dlm->master_lock); | ||
2043 | if (mle) | ||
2044 | __dlm_put_mle(mle); | ||
2045 | spin_unlock(&dlm->master_lock); | ||
2040 | spin_unlock(&dlm->spinlock); | 2046 | spin_unlock(&dlm->spinlock); |
2041 | *ret_data = (void *)res; | 2047 | *ret_data = (void *)res; |
2042 | dlm_put(dlm); | 2048 | dlm_put(dlm); |
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index ddb662b32447..4142546aedae 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c | |||
@@ -2532,6 +2532,7 @@ static void ocfs2_delete_osb(struct ocfs2_super *osb) | |||
2532 | kfree(osb->journal); | 2532 | kfree(osb->journal); |
2533 | kfree(osb->local_alloc_copy); | 2533 | kfree(osb->local_alloc_copy); |
2534 | kfree(osb->uuid_str); | 2534 | kfree(osb->uuid_str); |
2535 | kfree(osb->vol_label); | ||
2535 | ocfs2_put_dlm_debug(osb->osb_dlm_debug); | 2536 | ocfs2_put_dlm_debug(osb->osb_dlm_debug); |
2536 | memset(osb, 0, sizeof(struct ocfs2_super)); | 2537 | memset(osb, 0, sizeof(struct ocfs2_super)); |
2537 | } | 2538 | } |
diff --git a/fs/pnode.c b/fs/pnode.c index 302bf22c4a30..aae331a5d03b 100644 --- a/fs/pnode.c +++ b/fs/pnode.c | |||
@@ -381,6 +381,7 @@ static void __propagate_umount(struct mount *mnt) | |||
381 | * other children | 381 | * other children |
382 | */ | 382 | */ |
383 | if (child && list_empty(&child->mnt_mounts)) { | 383 | if (child && list_empty(&child->mnt_mounts)) { |
384 | list_del_init(&child->mnt_child); | ||
384 | hlist_del_init_rcu(&child->mnt_hash); | 385 | hlist_del_init_rcu(&child->mnt_hash); |
385 | hlist_add_before_rcu(&child->mnt_hash, &mnt->mnt_hash); | 386 | hlist_add_before_rcu(&child->mnt_hash, &mnt->mnt_hash); |
386 | } | 387 | } |
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index dfc791c42d64..c34156888d70 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c | |||
@@ -931,23 +931,32 @@ static int pagemap_pte_hole(unsigned long start, unsigned long end, | |||
931 | while (addr < end) { | 931 | while (addr < end) { |
932 | struct vm_area_struct *vma = find_vma(walk->mm, addr); | 932 | struct vm_area_struct *vma = find_vma(walk->mm, addr); |
933 | pagemap_entry_t pme = make_pme(PM_NOT_PRESENT(pm->v2)); | 933 | pagemap_entry_t pme = make_pme(PM_NOT_PRESENT(pm->v2)); |
934 | unsigned long vm_end; | 934 | /* End of address space hole, which we mark as non-present. */ |
935 | unsigned long hole_end; | ||
935 | 936 | ||
936 | if (!vma) { | 937 | if (vma) |
937 | vm_end = end; | 938 | hole_end = min(end, vma->vm_start); |
938 | } else { | 939 | else |
939 | vm_end = min(end, vma->vm_end); | 940 | hole_end = end; |
940 | if (vma->vm_flags & VM_SOFTDIRTY) | 941 | |
941 | pme.pme |= PM_STATUS2(pm->v2, __PM_SOFT_DIRTY); | 942 | for (; addr < hole_end; addr += PAGE_SIZE) { |
943 | err = add_to_pagemap(addr, &pme, pm); | ||
944 | if (err) | ||
945 | goto out; | ||
942 | } | 946 | } |
943 | 947 | ||
944 | for (; addr < vm_end; addr += PAGE_SIZE) { | 948 | if (!vma) |
949 | break; | ||
950 | |||
951 | /* Addresses in the VMA. */ | ||
952 | if (vma->vm_flags & VM_SOFTDIRTY) | ||
953 | pme.pme |= PM_STATUS2(pm->v2, __PM_SOFT_DIRTY); | ||
954 | for (; addr < min(end, vma->vm_end); addr += PAGE_SIZE) { | ||
945 | err = add_to_pagemap(addr, &pme, pm); | 955 | err = add_to_pagemap(addr, &pme, pm); |
946 | if (err) | 956 | if (err) |
947 | goto out; | 957 | goto out; |
948 | } | 958 | } |
949 | } | 959 | } |
950 | |||
951 | out: | 960 | out: |
952 | return err; | 961 | return err; |
953 | } | 962 | } |
@@ -65,7 +65,7 @@ int sync_filesystem(struct super_block *sb) | |||
65 | return ret; | 65 | return ret; |
66 | return __sync_filesystem(sb, 1); | 66 | return __sync_filesystem(sb, 1); |
67 | } | 67 | } |
68 | EXPORT_SYMBOL_GPL(sync_filesystem); | 68 | EXPORT_SYMBOL(sync_filesystem); |
69 | 69 | ||
70 | static void sync_inodes_one_sb(struct super_block *sb, void *arg) | 70 | static void sync_inodes_one_sb(struct super_block *sb, void *arg) |
71 | { | 71 | { |
diff --git a/fs/udf/ialloc.c b/fs/udf/ialloc.c index 6eaf5edf1ea1..e77db621ec89 100644 --- a/fs/udf/ialloc.c +++ b/fs/udf/ialloc.c | |||
@@ -45,7 +45,7 @@ void udf_free_inode(struct inode *inode) | |||
45 | udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1); | 45 | udf_free_blocks(sb, NULL, &UDF_I(inode)->i_location, 0, 1); |
46 | } | 46 | } |
47 | 47 | ||
48 | struct inode *udf_new_inode(struct inode *dir, umode_t mode, int *err) | 48 | struct inode *udf_new_inode(struct inode *dir, umode_t mode) |
49 | { | 49 | { |
50 | struct super_block *sb = dir->i_sb; | 50 | struct super_block *sb = dir->i_sb; |
51 | struct udf_sb_info *sbi = UDF_SB(sb); | 51 | struct udf_sb_info *sbi = UDF_SB(sb); |
@@ -55,14 +55,12 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode, int *err) | |||
55 | struct udf_inode_info *iinfo; | 55 | struct udf_inode_info *iinfo; |
56 | struct udf_inode_info *dinfo = UDF_I(dir); | 56 | struct udf_inode_info *dinfo = UDF_I(dir); |
57 | struct logicalVolIntegrityDescImpUse *lvidiu; | 57 | struct logicalVolIntegrityDescImpUse *lvidiu; |
58 | int err; | ||
58 | 59 | ||
59 | inode = new_inode(sb); | 60 | inode = new_inode(sb); |
60 | 61 | ||
61 | if (!inode) { | 62 | if (!inode) |
62 | *err = -ENOMEM; | 63 | return ERR_PTR(-ENOMEM); |
63 | return NULL; | ||
64 | } | ||
65 | *err = -ENOSPC; | ||
66 | 64 | ||
67 | iinfo = UDF_I(inode); | 65 | iinfo = UDF_I(inode); |
68 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) { | 66 | if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) { |
@@ -80,21 +78,22 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode, int *err) | |||
80 | } | 78 | } |
81 | if (!iinfo->i_ext.i_data) { | 79 | if (!iinfo->i_ext.i_data) { |
82 | iput(inode); | 80 | iput(inode); |
83 | *err = -ENOMEM; | 81 | return ERR_PTR(-ENOMEM); |
84 | return NULL; | ||
85 | } | 82 | } |
86 | 83 | ||
84 | err = -ENOSPC; | ||
87 | block = udf_new_block(dir->i_sb, NULL, | 85 | block = udf_new_block(dir->i_sb, NULL, |
88 | dinfo->i_location.partitionReferenceNum, | 86 | dinfo->i_location.partitionReferenceNum, |
89 | start, err); | 87 | start, &err); |
90 | if (*err) { | 88 | if (err) { |
91 | iput(inode); | 89 | iput(inode); |
92 | return NULL; | 90 | return ERR_PTR(err); |
93 | } | 91 | } |
94 | 92 | ||
95 | lvidiu = udf_sb_lvidiu(sb); | 93 | lvidiu = udf_sb_lvidiu(sb); |
96 | if (lvidiu) { | 94 | if (lvidiu) { |
97 | iinfo->i_unique = lvid_get_unique_id(sb); | 95 | iinfo->i_unique = lvid_get_unique_id(sb); |
96 | inode->i_generation = iinfo->i_unique; | ||
98 | mutex_lock(&sbi->s_alloc_mutex); | 97 | mutex_lock(&sbi->s_alloc_mutex); |
99 | if (S_ISDIR(mode)) | 98 | if (S_ISDIR(mode)) |
100 | le32_add_cpu(&lvidiu->numDirs, 1); | 99 | le32_add_cpu(&lvidiu->numDirs, 1); |
@@ -123,9 +122,12 @@ struct inode *udf_new_inode(struct inode *dir, umode_t mode, int *err) | |||
123 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; | 122 | iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG; |
124 | inode->i_mtime = inode->i_atime = inode->i_ctime = | 123 | inode->i_mtime = inode->i_atime = inode->i_ctime = |
125 | iinfo->i_crtime = current_fs_time(inode->i_sb); | 124 | iinfo->i_crtime = current_fs_time(inode->i_sb); |
126 | insert_inode_hash(inode); | 125 | if (unlikely(insert_inode_locked(inode) < 0)) { |
126 | make_bad_inode(inode); | ||
127 | iput(inode); | ||
128 | return ERR_PTR(-EIO); | ||
129 | } | ||
127 | mark_inode_dirty(inode); | 130 | mark_inode_dirty(inode); |
128 | 131 | ||
129 | *err = 0; | ||
130 | return inode; | 132 | return inode; |
131 | } | 133 | } |
diff --git a/fs/udf/inode.c b/fs/udf/inode.c index 236cd48184c2..08598843288f 100644 --- a/fs/udf/inode.c +++ b/fs/udf/inode.c | |||
@@ -51,7 +51,6 @@ MODULE_LICENSE("GPL"); | |||
51 | 51 | ||
52 | static umode_t udf_convert_permissions(struct fileEntry *); | 52 | static umode_t udf_convert_permissions(struct fileEntry *); |
53 | static int udf_update_inode(struct inode *, int); | 53 | static int udf_update_inode(struct inode *, int); |
54 | static void udf_fill_inode(struct inode *, struct buffer_head *); | ||
55 | static int udf_sync_inode(struct inode *inode); | 54 | static int udf_sync_inode(struct inode *inode); |
56 | static int udf_alloc_i_data(struct inode *inode, size_t size); | 55 | static int udf_alloc_i_data(struct inode *inode, size_t size); |
57 | static sector_t inode_getblk(struct inode *, sector_t, int *, int *); | 56 | static sector_t inode_getblk(struct inode *, sector_t, int *, int *); |
@@ -1271,12 +1270,33 @@ update_time: | |||
1271 | return 0; | 1270 | return 0; |
1272 | } | 1271 | } |
1273 | 1272 | ||
1274 | static void __udf_read_inode(struct inode *inode) | 1273 | /* |
1274 | * Maximum length of linked list formed by ICB hierarchy. The chosen number is | ||
1275 | * arbitrary - just that we hopefully don't limit any real use of rewritten | ||
1276 | * inode on write-once media but avoid looping for too long on corrupted media. | ||
1277 | */ | ||
1278 | #define UDF_MAX_ICB_NESTING 1024 | ||
1279 | |||
1280 | static int udf_read_inode(struct inode *inode) | ||
1275 | { | 1281 | { |
1276 | struct buffer_head *bh = NULL; | 1282 | struct buffer_head *bh = NULL; |
1277 | struct fileEntry *fe; | 1283 | struct fileEntry *fe; |
1284 | struct extendedFileEntry *efe; | ||
1278 | uint16_t ident; | 1285 | uint16_t ident; |
1279 | struct udf_inode_info *iinfo = UDF_I(inode); | 1286 | struct udf_inode_info *iinfo = UDF_I(inode); |
1287 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); | ||
1288 | struct kernel_lb_addr *iloc = &iinfo->i_location; | ||
1289 | unsigned int link_count; | ||
1290 | unsigned int indirections = 0; | ||
1291 | int ret = -EIO; | ||
1292 | |||
1293 | reread: | ||
1294 | if (iloc->logicalBlockNum >= | ||
1295 | sbi->s_partmaps[iloc->partitionReferenceNum].s_partition_len) { | ||
1296 | udf_debug("block=%d, partition=%d out of range\n", | ||
1297 | iloc->logicalBlockNum, iloc->partitionReferenceNum); | ||
1298 | return -EIO; | ||
1299 | } | ||
1280 | 1300 | ||
1281 | /* | 1301 | /* |
1282 | * Set defaults, but the inode is still incomplete! | 1302 | * Set defaults, but the inode is still incomplete! |
@@ -1290,78 +1310,54 @@ static void __udf_read_inode(struct inode *inode) | |||
1290 | * i_nlink = 1 | 1310 | * i_nlink = 1 |
1291 | * i_op = NULL; | 1311 | * i_op = NULL; |
1292 | */ | 1312 | */ |
1293 | bh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 0, &ident); | 1313 | bh = udf_read_ptagged(inode->i_sb, iloc, 0, &ident); |
1294 | if (!bh) { | 1314 | if (!bh) { |
1295 | udf_err(inode->i_sb, "(ino %ld) failed !bh\n", inode->i_ino); | 1315 | udf_err(inode->i_sb, "(ino %ld) failed !bh\n", inode->i_ino); |
1296 | make_bad_inode(inode); | 1316 | return -EIO; |
1297 | return; | ||
1298 | } | 1317 | } |
1299 | 1318 | ||
1300 | if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && | 1319 | if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE && |
1301 | ident != TAG_IDENT_USE) { | 1320 | ident != TAG_IDENT_USE) { |
1302 | udf_err(inode->i_sb, "(ino %ld) failed ident=%d\n", | 1321 | udf_err(inode->i_sb, "(ino %ld) failed ident=%d\n", |
1303 | inode->i_ino, ident); | 1322 | inode->i_ino, ident); |
1304 | brelse(bh); | 1323 | goto out; |
1305 | make_bad_inode(inode); | ||
1306 | return; | ||
1307 | } | 1324 | } |
1308 | 1325 | ||
1309 | fe = (struct fileEntry *)bh->b_data; | 1326 | fe = (struct fileEntry *)bh->b_data; |
1327 | efe = (struct extendedFileEntry *)bh->b_data; | ||
1310 | 1328 | ||
1311 | if (fe->icbTag.strategyType == cpu_to_le16(4096)) { | 1329 | if (fe->icbTag.strategyType == cpu_to_le16(4096)) { |
1312 | struct buffer_head *ibh; | 1330 | struct buffer_head *ibh; |
1313 | 1331 | ||
1314 | ibh = udf_read_ptagged(inode->i_sb, &iinfo->i_location, 1, | 1332 | ibh = udf_read_ptagged(inode->i_sb, iloc, 1, &ident); |
1315 | &ident); | ||
1316 | if (ident == TAG_IDENT_IE && ibh) { | 1333 | if (ident == TAG_IDENT_IE && ibh) { |
1317 | struct buffer_head *nbh = NULL; | ||
1318 | struct kernel_lb_addr loc; | 1334 | struct kernel_lb_addr loc; |
1319 | struct indirectEntry *ie; | 1335 | struct indirectEntry *ie; |
1320 | 1336 | ||
1321 | ie = (struct indirectEntry *)ibh->b_data; | 1337 | ie = (struct indirectEntry *)ibh->b_data; |
1322 | loc = lelb_to_cpu(ie->indirectICB.extLocation); | 1338 | loc = lelb_to_cpu(ie->indirectICB.extLocation); |
1323 | 1339 | ||
1324 | if (ie->indirectICB.extLength && | 1340 | if (ie->indirectICB.extLength) { |
1325 | (nbh = udf_read_ptagged(inode->i_sb, &loc, 0, | 1341 | brelse(ibh); |
1326 | &ident))) { | 1342 | memcpy(&iinfo->i_location, &loc, |
1327 | if (ident == TAG_IDENT_FE || | 1343 | sizeof(struct kernel_lb_addr)); |
1328 | ident == TAG_IDENT_EFE) { | 1344 | if (++indirections > UDF_MAX_ICB_NESTING) { |
1329 | memcpy(&iinfo->i_location, | 1345 | udf_err(inode->i_sb, |
1330 | &loc, | 1346 | "too many ICBs in ICB hierarchy" |
1331 | sizeof(struct kernel_lb_addr)); | 1347 | " (max %d supported)\n", |
1332 | brelse(bh); | 1348 | UDF_MAX_ICB_NESTING); |
1333 | brelse(ibh); | 1349 | goto out; |
1334 | brelse(nbh); | ||
1335 | __udf_read_inode(inode); | ||
1336 | return; | ||
1337 | } | 1350 | } |
1338 | brelse(nbh); | 1351 | brelse(bh); |
1352 | goto reread; | ||
1339 | } | 1353 | } |
1340 | } | 1354 | } |
1341 | brelse(ibh); | 1355 | brelse(ibh); |
1342 | } else if (fe->icbTag.strategyType != cpu_to_le16(4)) { | 1356 | } else if (fe->icbTag.strategyType != cpu_to_le16(4)) { |
1343 | udf_err(inode->i_sb, "unsupported strategy type: %d\n", | 1357 | udf_err(inode->i_sb, "unsupported strategy type: %d\n", |
1344 | le16_to_cpu(fe->icbTag.strategyType)); | 1358 | le16_to_cpu(fe->icbTag.strategyType)); |
1345 | brelse(bh); | 1359 | goto out; |
1346 | make_bad_inode(inode); | ||
1347 | return; | ||
1348 | } | 1360 | } |
1349 | udf_fill_inode(inode, bh); | ||
1350 | |||
1351 | brelse(bh); | ||
1352 | } | ||
1353 | |||
1354 | static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | ||
1355 | { | ||
1356 | struct fileEntry *fe; | ||
1357 | struct extendedFileEntry *efe; | ||
1358 | struct udf_sb_info *sbi = UDF_SB(inode->i_sb); | ||
1359 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
1360 | unsigned int link_count; | ||
1361 | |||
1362 | fe = (struct fileEntry *)bh->b_data; | ||
1363 | efe = (struct extendedFileEntry *)bh->b_data; | ||
1364 | |||
1365 | if (fe->icbTag.strategyType == cpu_to_le16(4)) | 1361 | if (fe->icbTag.strategyType == cpu_to_le16(4)) |
1366 | iinfo->i_strat4096 = 0; | 1362 | iinfo->i_strat4096 = 0; |
1367 | else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */ | 1363 | else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */ |
@@ -1378,11 +1374,10 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1378 | if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_EFE)) { | 1374 | if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_EFE)) { |
1379 | iinfo->i_efe = 1; | 1375 | iinfo->i_efe = 1; |
1380 | iinfo->i_use = 0; | 1376 | iinfo->i_use = 0; |
1381 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - | 1377 | ret = udf_alloc_i_data(inode, inode->i_sb->s_blocksize - |
1382 | sizeof(struct extendedFileEntry))) { | 1378 | sizeof(struct extendedFileEntry)); |
1383 | make_bad_inode(inode); | 1379 | if (ret) |
1384 | return; | 1380 | goto out; |
1385 | } | ||
1386 | memcpy(iinfo->i_ext.i_data, | 1381 | memcpy(iinfo->i_ext.i_data, |
1387 | bh->b_data + sizeof(struct extendedFileEntry), | 1382 | bh->b_data + sizeof(struct extendedFileEntry), |
1388 | inode->i_sb->s_blocksize - | 1383 | inode->i_sb->s_blocksize - |
@@ -1390,11 +1385,10 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1390 | } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) { | 1385 | } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) { |
1391 | iinfo->i_efe = 0; | 1386 | iinfo->i_efe = 0; |
1392 | iinfo->i_use = 0; | 1387 | iinfo->i_use = 0; |
1393 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - | 1388 | ret = udf_alloc_i_data(inode, inode->i_sb->s_blocksize - |
1394 | sizeof(struct fileEntry))) { | 1389 | sizeof(struct fileEntry)); |
1395 | make_bad_inode(inode); | 1390 | if (ret) |
1396 | return; | 1391 | goto out; |
1397 | } | ||
1398 | memcpy(iinfo->i_ext.i_data, | 1392 | memcpy(iinfo->i_ext.i_data, |
1399 | bh->b_data + sizeof(struct fileEntry), | 1393 | bh->b_data + sizeof(struct fileEntry), |
1400 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); | 1394 | inode->i_sb->s_blocksize - sizeof(struct fileEntry)); |
@@ -1404,18 +1398,18 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1404 | iinfo->i_lenAlloc = le32_to_cpu( | 1398 | iinfo->i_lenAlloc = le32_to_cpu( |
1405 | ((struct unallocSpaceEntry *)bh->b_data)-> | 1399 | ((struct unallocSpaceEntry *)bh->b_data)-> |
1406 | lengthAllocDescs); | 1400 | lengthAllocDescs); |
1407 | if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - | 1401 | ret = udf_alloc_i_data(inode, inode->i_sb->s_blocksize - |
1408 | sizeof(struct unallocSpaceEntry))) { | 1402 | sizeof(struct unallocSpaceEntry)); |
1409 | make_bad_inode(inode); | 1403 | if (ret) |
1410 | return; | 1404 | goto out; |
1411 | } | ||
1412 | memcpy(iinfo->i_ext.i_data, | 1405 | memcpy(iinfo->i_ext.i_data, |
1413 | bh->b_data + sizeof(struct unallocSpaceEntry), | 1406 | bh->b_data + sizeof(struct unallocSpaceEntry), |
1414 | inode->i_sb->s_blocksize - | 1407 | inode->i_sb->s_blocksize - |
1415 | sizeof(struct unallocSpaceEntry)); | 1408 | sizeof(struct unallocSpaceEntry)); |
1416 | return; | 1409 | return 0; |
1417 | } | 1410 | } |
1418 | 1411 | ||
1412 | ret = -EIO; | ||
1419 | read_lock(&sbi->s_cred_lock); | 1413 | read_lock(&sbi->s_cred_lock); |
1420 | i_uid_write(inode, le32_to_cpu(fe->uid)); | 1414 | i_uid_write(inode, le32_to_cpu(fe->uid)); |
1421 | if (!uid_valid(inode->i_uid) || | 1415 | if (!uid_valid(inode->i_uid) || |
@@ -1441,8 +1435,10 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1441 | read_unlock(&sbi->s_cred_lock); | 1435 | read_unlock(&sbi->s_cred_lock); |
1442 | 1436 | ||
1443 | link_count = le16_to_cpu(fe->fileLinkCount); | 1437 | link_count = le16_to_cpu(fe->fileLinkCount); |
1444 | if (!link_count) | 1438 | if (!link_count) { |
1445 | link_count = 1; | 1439 | ret = -ESTALE; |
1440 | goto out; | ||
1441 | } | ||
1446 | set_nlink(inode, link_count); | 1442 | set_nlink(inode, link_count); |
1447 | 1443 | ||
1448 | inode->i_size = le64_to_cpu(fe->informationLength); | 1444 | inode->i_size = le64_to_cpu(fe->informationLength); |
@@ -1488,6 +1484,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1488 | iinfo->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs); | 1484 | iinfo->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs); |
1489 | iinfo->i_checkpoint = le32_to_cpu(efe->checkpoint); | 1485 | iinfo->i_checkpoint = le32_to_cpu(efe->checkpoint); |
1490 | } | 1486 | } |
1487 | inode->i_generation = iinfo->i_unique; | ||
1491 | 1488 | ||
1492 | switch (fe->icbTag.fileType) { | 1489 | switch (fe->icbTag.fileType) { |
1493 | case ICBTAG_FILE_TYPE_DIRECTORY: | 1490 | case ICBTAG_FILE_TYPE_DIRECTORY: |
@@ -1537,8 +1534,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1537 | default: | 1534 | default: |
1538 | udf_err(inode->i_sb, "(ino %ld) failed unknown file type=%d\n", | 1535 | udf_err(inode->i_sb, "(ino %ld) failed unknown file type=%d\n", |
1539 | inode->i_ino, fe->icbTag.fileType); | 1536 | inode->i_ino, fe->icbTag.fileType); |
1540 | make_bad_inode(inode); | 1537 | goto out; |
1541 | return; | ||
1542 | } | 1538 | } |
1543 | if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { | 1539 | if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { |
1544 | struct deviceSpec *dsea = | 1540 | struct deviceSpec *dsea = |
@@ -1549,8 +1545,12 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh) | |||
1549 | le32_to_cpu(dsea->minorDeviceIdent))); | 1545 | le32_to_cpu(dsea->minorDeviceIdent))); |
1550 | /* Developer ID ??? */ | 1546 | /* Developer ID ??? */ |
1551 | } else | 1547 | } else |
1552 | make_bad_inode(inode); | 1548 | goto out; |
1553 | } | 1549 | } |
1550 | ret = 0; | ||
1551 | out: | ||
1552 | brelse(bh); | ||
1553 | return ret; | ||
1554 | } | 1554 | } |
1555 | 1555 | ||
1556 | static int udf_alloc_i_data(struct inode *inode, size_t size) | 1556 | static int udf_alloc_i_data(struct inode *inode, size_t size) |
@@ -1664,7 +1664,7 @@ static int udf_update_inode(struct inode *inode, int do_sync) | |||
1664 | FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); | 1664 | FE_PERM_U_DELETE | FE_PERM_U_CHATTR)); |
1665 | fe->permissions = cpu_to_le32(udfperms); | 1665 | fe->permissions = cpu_to_le32(udfperms); |
1666 | 1666 | ||
1667 | if (S_ISDIR(inode->i_mode)) | 1667 | if (S_ISDIR(inode->i_mode) && inode->i_nlink > 0) |
1668 | fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1); | 1668 | fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1); |
1669 | else | 1669 | else |
1670 | fe->fileLinkCount = cpu_to_le16(inode->i_nlink); | 1670 | fe->fileLinkCount = cpu_to_le16(inode->i_nlink); |
@@ -1830,32 +1830,23 @@ struct inode *udf_iget(struct super_block *sb, struct kernel_lb_addr *ino) | |||
1830 | { | 1830 | { |
1831 | unsigned long block = udf_get_lb_pblock(sb, ino, 0); | 1831 | unsigned long block = udf_get_lb_pblock(sb, ino, 0); |
1832 | struct inode *inode = iget_locked(sb, block); | 1832 | struct inode *inode = iget_locked(sb, block); |
1833 | int err; | ||
1833 | 1834 | ||
1834 | if (!inode) | 1835 | if (!inode) |
1835 | return NULL; | 1836 | return ERR_PTR(-ENOMEM); |
1836 | |||
1837 | if (inode->i_state & I_NEW) { | ||
1838 | memcpy(&UDF_I(inode)->i_location, ino, sizeof(struct kernel_lb_addr)); | ||
1839 | __udf_read_inode(inode); | ||
1840 | unlock_new_inode(inode); | ||
1841 | } | ||
1842 | 1837 | ||
1843 | if (is_bad_inode(inode)) | 1838 | if (!(inode->i_state & I_NEW)) |
1844 | goto out_iput; | 1839 | return inode; |
1845 | 1840 | ||
1846 | if (ino->logicalBlockNum >= UDF_SB(sb)-> | 1841 | memcpy(&UDF_I(inode)->i_location, ino, sizeof(struct kernel_lb_addr)); |
1847 | s_partmaps[ino->partitionReferenceNum].s_partition_len) { | 1842 | err = udf_read_inode(inode); |
1848 | udf_debug("block=%d, partition=%d out of range\n", | 1843 | if (err < 0) { |
1849 | ino->logicalBlockNum, ino->partitionReferenceNum); | 1844 | iget_failed(inode); |
1850 | make_bad_inode(inode); | 1845 | return ERR_PTR(err); |
1851 | goto out_iput; | ||
1852 | } | 1846 | } |
1847 | unlock_new_inode(inode); | ||
1853 | 1848 | ||
1854 | return inode; | 1849 | return inode; |
1855 | |||
1856 | out_iput: | ||
1857 | iput(inode); | ||
1858 | return NULL; | ||
1859 | } | 1850 | } |
1860 | 1851 | ||
1861 | int udf_add_aext(struct inode *inode, struct extent_position *epos, | 1852 | int udf_add_aext(struct inode *inode, struct extent_position *epos, |
diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 83a06001742b..c12e260fd6c4 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c | |||
@@ -270,9 +270,8 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, | |||
270 | NULL, 0), | 270 | NULL, 0), |
271 | }; | 271 | }; |
272 | inode = udf_iget(dir->i_sb, lb); | 272 | inode = udf_iget(dir->i_sb, lb); |
273 | if (!inode) { | 273 | if (IS_ERR(inode)) |
274 | return ERR_PTR(-EACCES); | 274 | return inode; |
275 | } | ||
276 | } else | 275 | } else |
277 | #endif /* UDF_RECOVERY */ | 276 | #endif /* UDF_RECOVERY */ |
278 | 277 | ||
@@ -285,9 +284,8 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, | |||
285 | 284 | ||
286 | loc = lelb_to_cpu(cfi.icb.extLocation); | 285 | loc = lelb_to_cpu(cfi.icb.extLocation); |
287 | inode = udf_iget(dir->i_sb, &loc); | 286 | inode = udf_iget(dir->i_sb, &loc); |
288 | if (!inode) { | 287 | if (IS_ERR(inode)) |
289 | return ERR_PTR(-EACCES); | 288 | return ERR_CAST(inode); |
290 | } | ||
291 | } | 289 | } |
292 | 290 | ||
293 | return d_splice_alias(inode, dentry); | 291 | return d_splice_alias(inode, dentry); |
@@ -550,32 +548,18 @@ static int udf_delete_entry(struct inode *inode, struct fileIdentDesc *fi, | |||
550 | return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); | 548 | return udf_write_fi(inode, cfi, fi, fibh, NULL, NULL); |
551 | } | 549 | } |
552 | 550 | ||
553 | static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode, | 551 | static int udf_add_nondir(struct dentry *dentry, struct inode *inode) |
554 | bool excl) | ||
555 | { | 552 | { |
553 | struct udf_inode_info *iinfo = UDF_I(inode); | ||
554 | struct inode *dir = dentry->d_parent->d_inode; | ||
556 | struct udf_fileident_bh fibh; | 555 | struct udf_fileident_bh fibh; |
557 | struct inode *inode; | ||
558 | struct fileIdentDesc cfi, *fi; | 556 | struct fileIdentDesc cfi, *fi; |
559 | int err; | 557 | int err; |
560 | struct udf_inode_info *iinfo; | ||
561 | |||
562 | inode = udf_new_inode(dir, mode, &err); | ||
563 | if (!inode) { | ||
564 | return err; | ||
565 | } | ||
566 | |||
567 | iinfo = UDF_I(inode); | ||
568 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
569 | inode->i_data.a_ops = &udf_adinicb_aops; | ||
570 | else | ||
571 | inode->i_data.a_ops = &udf_aops; | ||
572 | inode->i_op = &udf_file_inode_operations; | ||
573 | inode->i_fop = &udf_file_operations; | ||
574 | mark_inode_dirty(inode); | ||
575 | 558 | ||
576 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); | 559 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); |
577 | if (!fi) { | 560 | if (unlikely(!fi)) { |
578 | inode_dec_link_count(inode); | 561 | inode_dec_link_count(inode); |
562 | unlock_new_inode(inode); | ||
579 | iput(inode); | 563 | iput(inode); |
580 | return err; | 564 | return err; |
581 | } | 565 | } |
@@ -589,23 +573,21 @@ static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode, | |||
589 | if (fibh.sbh != fibh.ebh) | 573 | if (fibh.sbh != fibh.ebh) |
590 | brelse(fibh.ebh); | 574 | brelse(fibh.ebh); |
591 | brelse(fibh.sbh); | 575 | brelse(fibh.sbh); |
576 | unlock_new_inode(inode); | ||
592 | d_instantiate(dentry, inode); | 577 | d_instantiate(dentry, inode); |
593 | 578 | ||
594 | return 0; | 579 | return 0; |
595 | } | 580 | } |
596 | 581 | ||
597 | static int udf_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) | 582 | static int udf_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
583 | bool excl) | ||
598 | { | 584 | { |
599 | struct inode *inode; | 585 | struct inode *inode = udf_new_inode(dir, mode); |
600 | struct udf_inode_info *iinfo; | ||
601 | int err; | ||
602 | 586 | ||
603 | inode = udf_new_inode(dir, mode, &err); | 587 | if (IS_ERR(inode)) |
604 | if (!inode) | 588 | return PTR_ERR(inode); |
605 | return err; | ||
606 | 589 | ||
607 | iinfo = UDF_I(inode); | 590 | if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) |
608 | if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
609 | inode->i_data.a_ops = &udf_adinicb_aops; | 591 | inode->i_data.a_ops = &udf_adinicb_aops; |
610 | else | 592 | else |
611 | inode->i_data.a_ops = &udf_aops; | 593 | inode->i_data.a_ops = &udf_aops; |
@@ -613,7 +595,25 @@ static int udf_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
613 | inode->i_fop = &udf_file_operations; | 595 | inode->i_fop = &udf_file_operations; |
614 | mark_inode_dirty(inode); | 596 | mark_inode_dirty(inode); |
615 | 597 | ||
598 | return udf_add_nondir(dentry, inode); | ||
599 | } | ||
600 | |||
601 | static int udf_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) | ||
602 | { | ||
603 | struct inode *inode = udf_new_inode(dir, mode); | ||
604 | |||
605 | if (IS_ERR(inode)) | ||
606 | return PTR_ERR(inode); | ||
607 | |||
608 | if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
609 | inode->i_data.a_ops = &udf_adinicb_aops; | ||
610 | else | ||
611 | inode->i_data.a_ops = &udf_aops; | ||
612 | inode->i_op = &udf_file_inode_operations; | ||
613 | inode->i_fop = &udf_file_operations; | ||
614 | mark_inode_dirty(inode); | ||
616 | d_tmpfile(dentry, inode); | 615 | d_tmpfile(dentry, inode); |
616 | unlock_new_inode(inode); | ||
617 | return 0; | 617 | return 0; |
618 | } | 618 | } |
619 | 619 | ||
@@ -621,44 +621,16 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, | |||
621 | dev_t rdev) | 621 | dev_t rdev) |
622 | { | 622 | { |
623 | struct inode *inode; | 623 | struct inode *inode; |
624 | struct udf_fileident_bh fibh; | ||
625 | struct fileIdentDesc cfi, *fi; | ||
626 | int err; | ||
627 | struct udf_inode_info *iinfo; | ||
628 | 624 | ||
629 | if (!old_valid_dev(rdev)) | 625 | if (!old_valid_dev(rdev)) |
630 | return -EINVAL; | 626 | return -EINVAL; |
631 | 627 | ||
632 | err = -EIO; | 628 | inode = udf_new_inode(dir, mode); |
633 | inode = udf_new_inode(dir, mode, &err); | 629 | if (IS_ERR(inode)) |
634 | if (!inode) | 630 | return PTR_ERR(inode); |
635 | goto out; | ||
636 | 631 | ||
637 | iinfo = UDF_I(inode); | ||
638 | init_special_inode(inode, mode, rdev); | 632 | init_special_inode(inode, mode, rdev); |
639 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); | 633 | return udf_add_nondir(dentry, inode); |
640 | if (!fi) { | ||
641 | inode_dec_link_count(inode); | ||
642 | iput(inode); | ||
643 | return err; | ||
644 | } | ||
645 | cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); | ||
646 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); | ||
647 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | ||
648 | cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL); | ||
649 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | ||
650 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
651 | mark_inode_dirty(dir); | ||
652 | mark_inode_dirty(inode); | ||
653 | |||
654 | if (fibh.sbh != fibh.ebh) | ||
655 | brelse(fibh.ebh); | ||
656 | brelse(fibh.sbh); | ||
657 | d_instantiate(dentry, inode); | ||
658 | err = 0; | ||
659 | |||
660 | out: | ||
661 | return err; | ||
662 | } | 634 | } |
663 | 635 | ||
664 | static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | 636 | static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
@@ -670,10 +642,9 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
670 | struct udf_inode_info *dinfo = UDF_I(dir); | 642 | struct udf_inode_info *dinfo = UDF_I(dir); |
671 | struct udf_inode_info *iinfo; | 643 | struct udf_inode_info *iinfo; |
672 | 644 | ||
673 | err = -EIO; | 645 | inode = udf_new_inode(dir, S_IFDIR | mode); |
674 | inode = udf_new_inode(dir, S_IFDIR | mode, &err); | 646 | if (IS_ERR(inode)) |
675 | if (!inode) | 647 | return PTR_ERR(inode); |
676 | goto out; | ||
677 | 648 | ||
678 | iinfo = UDF_I(inode); | 649 | iinfo = UDF_I(inode); |
679 | inode->i_op = &udf_dir_inode_operations; | 650 | inode->i_op = &udf_dir_inode_operations; |
@@ -681,6 +652,7 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
681 | fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err); | 652 | fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err); |
682 | if (!fi) { | 653 | if (!fi) { |
683 | inode_dec_link_count(inode); | 654 | inode_dec_link_count(inode); |
655 | unlock_new_inode(inode); | ||
684 | iput(inode); | 656 | iput(inode); |
685 | goto out; | 657 | goto out; |
686 | } | 658 | } |
@@ -699,6 +671,7 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
699 | if (!fi) { | 671 | if (!fi) { |
700 | clear_nlink(inode); | 672 | clear_nlink(inode); |
701 | mark_inode_dirty(inode); | 673 | mark_inode_dirty(inode); |
674 | unlock_new_inode(inode); | ||
702 | iput(inode); | 675 | iput(inode); |
703 | goto out; | 676 | goto out; |
704 | } | 677 | } |
@@ -710,6 +683,7 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | |||
710 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | 683 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); |
711 | inc_nlink(dir); | 684 | inc_nlink(dir); |
712 | mark_inode_dirty(dir); | 685 | mark_inode_dirty(dir); |
686 | unlock_new_inode(inode); | ||
713 | d_instantiate(dentry, inode); | 687 | d_instantiate(dentry, inode); |
714 | if (fibh.sbh != fibh.ebh) | 688 | if (fibh.sbh != fibh.ebh) |
715 | brelse(fibh.ebh); | 689 | brelse(fibh.ebh); |
@@ -876,14 +850,11 @@ out: | |||
876 | static int udf_symlink(struct inode *dir, struct dentry *dentry, | 850 | static int udf_symlink(struct inode *dir, struct dentry *dentry, |
877 | const char *symname) | 851 | const char *symname) |
878 | { | 852 | { |
879 | struct inode *inode; | 853 | struct inode *inode = udf_new_inode(dir, S_IFLNK | S_IRWXUGO); |
880 | struct pathComponent *pc; | 854 | struct pathComponent *pc; |
881 | const char *compstart; | 855 | const char *compstart; |
882 | struct udf_fileident_bh fibh; | ||
883 | struct extent_position epos = {}; | 856 | struct extent_position epos = {}; |
884 | int eoffset, elen = 0; | 857 | int eoffset, elen = 0; |
885 | struct fileIdentDesc *fi; | ||
886 | struct fileIdentDesc cfi; | ||
887 | uint8_t *ea; | 858 | uint8_t *ea; |
888 | int err; | 859 | int err; |
889 | int block; | 860 | int block; |
@@ -892,9 +863,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
892 | struct udf_inode_info *iinfo; | 863 | struct udf_inode_info *iinfo; |
893 | struct super_block *sb = dir->i_sb; | 864 | struct super_block *sb = dir->i_sb; |
894 | 865 | ||
895 | inode = udf_new_inode(dir, S_IFLNK | S_IRWXUGO, &err); | 866 | if (IS_ERR(inode)) |
896 | if (!inode) | 867 | return PTR_ERR(inode); |
897 | goto out; | ||
898 | 868 | ||
899 | iinfo = UDF_I(inode); | 869 | iinfo = UDF_I(inode); |
900 | down_write(&iinfo->i_data_sem); | 870 | down_write(&iinfo->i_data_sem); |
@@ -1012,32 +982,15 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry, | |||
1012 | mark_inode_dirty(inode); | 982 | mark_inode_dirty(inode); |
1013 | up_write(&iinfo->i_data_sem); | 983 | up_write(&iinfo->i_data_sem); |
1014 | 984 | ||
1015 | fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err); | 985 | err = udf_add_nondir(dentry, inode); |
1016 | if (!fi) | ||
1017 | goto out_fail; | ||
1018 | cfi.icb.extLength = cpu_to_le32(sb->s_blocksize); | ||
1019 | cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location); | ||
1020 | if (UDF_SB(inode->i_sb)->s_lvid_bh) { | ||
1021 | *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse = | ||
1022 | cpu_to_le32(lvid_get_unique_id(sb)); | ||
1023 | } | ||
1024 | udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL); | ||
1025 | if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) | ||
1026 | mark_inode_dirty(dir); | ||
1027 | if (fibh.sbh != fibh.ebh) | ||
1028 | brelse(fibh.ebh); | ||
1029 | brelse(fibh.sbh); | ||
1030 | d_instantiate(dentry, inode); | ||
1031 | err = 0; | ||
1032 | |||
1033 | out: | 986 | out: |
1034 | kfree(name); | 987 | kfree(name); |
1035 | return err; | 988 | return err; |
1036 | 989 | ||
1037 | out_no_entry: | 990 | out_no_entry: |
1038 | up_write(&iinfo->i_data_sem); | 991 | up_write(&iinfo->i_data_sem); |
1039 | out_fail: | ||
1040 | inode_dec_link_count(inode); | 992 | inode_dec_link_count(inode); |
993 | unlock_new_inode(inode); | ||
1041 | iput(inode); | 994 | iput(inode); |
1042 | goto out; | 995 | goto out; |
1043 | } | 996 | } |
@@ -1222,7 +1175,7 @@ static struct dentry *udf_get_parent(struct dentry *child) | |||
1222 | struct udf_fileident_bh fibh; | 1175 | struct udf_fileident_bh fibh; |
1223 | 1176 | ||
1224 | if (!udf_find_entry(child->d_inode, &dotdot, &fibh, &cfi)) | 1177 | if (!udf_find_entry(child->d_inode, &dotdot, &fibh, &cfi)) |
1225 | goto out_unlock; | 1178 | return ERR_PTR(-EACCES); |
1226 | 1179 | ||
1227 | if (fibh.sbh != fibh.ebh) | 1180 | if (fibh.sbh != fibh.ebh) |
1228 | brelse(fibh.ebh); | 1181 | brelse(fibh.ebh); |
@@ -1230,12 +1183,10 @@ static struct dentry *udf_get_parent(struct dentry *child) | |||
1230 | 1183 | ||
1231 | tloc = lelb_to_cpu(cfi.icb.extLocation); | 1184 | tloc = lelb_to_cpu(cfi.icb.extLocation); |
1232 | inode = udf_iget(child->d_inode->i_sb, &tloc); | 1185 | inode = udf_iget(child->d_inode->i_sb, &tloc); |
1233 | if (!inode) | 1186 | if (IS_ERR(inode)) |
1234 | goto out_unlock; | 1187 | return ERR_CAST(inode); |
1235 | 1188 | ||
1236 | return d_obtain_alias(inode); | 1189 | return d_obtain_alias(inode); |
1237 | out_unlock: | ||
1238 | return ERR_PTR(-EACCES); | ||
1239 | } | 1190 | } |
1240 | 1191 | ||
1241 | 1192 | ||
@@ -1252,8 +1203,8 @@ static struct dentry *udf_nfs_get_inode(struct super_block *sb, u32 block, | |||
1252 | loc.partitionReferenceNum = partref; | 1203 | loc.partitionReferenceNum = partref; |
1253 | inode = udf_iget(sb, &loc); | 1204 | inode = udf_iget(sb, &loc); |
1254 | 1205 | ||
1255 | if (inode == NULL) | 1206 | if (IS_ERR(inode)) |
1256 | return ERR_PTR(-ENOMEM); | 1207 | return ERR_CAST(inode); |
1257 | 1208 | ||
1258 | if (generation && inode->i_generation != generation) { | 1209 | if (generation && inode->i_generation != generation) { |
1259 | iput(inode); | 1210 | iput(inode); |
diff --git a/fs/udf/super.c b/fs/udf/super.c index 813da94d447b..5401fc33f5cc 100644 --- a/fs/udf/super.c +++ b/fs/udf/super.c | |||
@@ -961,12 +961,14 @@ struct inode *udf_find_metadata_inode_efe(struct super_block *sb, | |||
961 | 961 | ||
962 | metadata_fe = udf_iget(sb, &addr); | 962 | metadata_fe = udf_iget(sb, &addr); |
963 | 963 | ||
964 | if (metadata_fe == NULL) | 964 | if (IS_ERR(metadata_fe)) { |
965 | udf_warn(sb, "metadata inode efe not found\n"); | 965 | udf_warn(sb, "metadata inode efe not found\n"); |
966 | else if (UDF_I(metadata_fe)->i_alloc_type != ICBTAG_FLAG_AD_SHORT) { | 966 | return metadata_fe; |
967 | } | ||
968 | if (UDF_I(metadata_fe)->i_alloc_type != ICBTAG_FLAG_AD_SHORT) { | ||
967 | udf_warn(sb, "metadata inode efe does not have short allocation descriptors!\n"); | 969 | udf_warn(sb, "metadata inode efe does not have short allocation descriptors!\n"); |
968 | iput(metadata_fe); | 970 | iput(metadata_fe); |
969 | metadata_fe = NULL; | 971 | return ERR_PTR(-EIO); |
970 | } | 972 | } |
971 | 973 | ||
972 | return metadata_fe; | 974 | return metadata_fe; |
@@ -978,6 +980,7 @@ static int udf_load_metadata_files(struct super_block *sb, int partition) | |||
978 | struct udf_part_map *map; | 980 | struct udf_part_map *map; |
979 | struct udf_meta_data *mdata; | 981 | struct udf_meta_data *mdata; |
980 | struct kernel_lb_addr addr; | 982 | struct kernel_lb_addr addr; |
983 | struct inode *fe; | ||
981 | 984 | ||
982 | map = &sbi->s_partmaps[partition]; | 985 | map = &sbi->s_partmaps[partition]; |
983 | mdata = &map->s_type_specific.s_metadata; | 986 | mdata = &map->s_type_specific.s_metadata; |
@@ -986,22 +989,24 @@ static int udf_load_metadata_files(struct super_block *sb, int partition) | |||
986 | udf_debug("Metadata file location: block = %d part = %d\n", | 989 | udf_debug("Metadata file location: block = %d part = %d\n", |
987 | mdata->s_meta_file_loc, map->s_partition_num); | 990 | mdata->s_meta_file_loc, map->s_partition_num); |
988 | 991 | ||
989 | mdata->s_metadata_fe = udf_find_metadata_inode_efe(sb, | 992 | fe = udf_find_metadata_inode_efe(sb, mdata->s_meta_file_loc, |
990 | mdata->s_meta_file_loc, map->s_partition_num); | 993 | map->s_partition_num); |
991 | 994 | if (IS_ERR(fe)) { | |
992 | if (mdata->s_metadata_fe == NULL) { | ||
993 | /* mirror file entry */ | 995 | /* mirror file entry */ |
994 | udf_debug("Mirror metadata file location: block = %d part = %d\n", | 996 | udf_debug("Mirror metadata file location: block = %d part = %d\n", |
995 | mdata->s_mirror_file_loc, map->s_partition_num); | 997 | mdata->s_mirror_file_loc, map->s_partition_num); |
996 | 998 | ||
997 | mdata->s_mirror_fe = udf_find_metadata_inode_efe(sb, | 999 | fe = udf_find_metadata_inode_efe(sb, mdata->s_mirror_file_loc, |
998 | mdata->s_mirror_file_loc, map->s_partition_num); | 1000 | map->s_partition_num); |
999 | 1001 | ||
1000 | if (mdata->s_mirror_fe == NULL) { | 1002 | if (IS_ERR(fe)) { |
1001 | udf_err(sb, "Both metadata and mirror metadata inode efe can not found\n"); | 1003 | udf_err(sb, "Both metadata and mirror metadata inode efe can not found\n"); |
1002 | return -EIO; | 1004 | return PTR_ERR(fe); |
1003 | } | 1005 | } |
1004 | } | 1006 | mdata->s_mirror_fe = fe; |
1007 | } else | ||
1008 | mdata->s_metadata_fe = fe; | ||
1009 | |||
1005 | 1010 | ||
1006 | /* | 1011 | /* |
1007 | * bitmap file entry | 1012 | * bitmap file entry |
@@ -1015,15 +1020,16 @@ static int udf_load_metadata_files(struct super_block *sb, int partition) | |||
1015 | udf_debug("Bitmap file location: block = %d part = %d\n", | 1020 | udf_debug("Bitmap file location: block = %d part = %d\n", |
1016 | addr.logicalBlockNum, addr.partitionReferenceNum); | 1021 | addr.logicalBlockNum, addr.partitionReferenceNum); |
1017 | 1022 | ||
1018 | mdata->s_bitmap_fe = udf_iget(sb, &addr); | 1023 | fe = udf_iget(sb, &addr); |
1019 | if (mdata->s_bitmap_fe == NULL) { | 1024 | if (IS_ERR(fe)) { |
1020 | if (sb->s_flags & MS_RDONLY) | 1025 | if (sb->s_flags & MS_RDONLY) |
1021 | udf_warn(sb, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n"); | 1026 | udf_warn(sb, "bitmap inode efe not found but it's ok since the disc is mounted read-only\n"); |
1022 | else { | 1027 | else { |
1023 | udf_err(sb, "bitmap inode efe not found and attempted read-write mount\n"); | 1028 | udf_err(sb, "bitmap inode efe not found and attempted read-write mount\n"); |
1024 | return -EIO; | 1029 | return PTR_ERR(fe); |
1025 | } | 1030 | } |
1026 | } | 1031 | } else |
1032 | mdata->s_bitmap_fe = fe; | ||
1027 | } | 1033 | } |
1028 | 1034 | ||
1029 | udf_debug("udf_load_metadata_files Ok\n"); | 1035 | udf_debug("udf_load_metadata_files Ok\n"); |
@@ -1111,13 +1117,15 @@ static int udf_fill_partdesc_info(struct super_block *sb, | |||
1111 | phd->unallocSpaceTable.extPosition), | 1117 | phd->unallocSpaceTable.extPosition), |
1112 | .partitionReferenceNum = p_index, | 1118 | .partitionReferenceNum = p_index, |
1113 | }; | 1119 | }; |
1120 | struct inode *inode; | ||
1114 | 1121 | ||
1115 | map->s_uspace.s_table = udf_iget(sb, &loc); | 1122 | inode = udf_iget(sb, &loc); |
1116 | if (!map->s_uspace.s_table) { | 1123 | if (IS_ERR(inode)) { |
1117 | udf_debug("cannot load unallocSpaceTable (part %d)\n", | 1124 | udf_debug("cannot load unallocSpaceTable (part %d)\n", |
1118 | p_index); | 1125 | p_index); |
1119 | return -EIO; | 1126 | return PTR_ERR(inode); |
1120 | } | 1127 | } |
1128 | map->s_uspace.s_table = inode; | ||
1121 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; | 1129 | map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE; |
1122 | udf_debug("unallocSpaceTable (part %d) @ %ld\n", | 1130 | udf_debug("unallocSpaceTable (part %d) @ %ld\n", |
1123 | p_index, map->s_uspace.s_table->i_ino); | 1131 | p_index, map->s_uspace.s_table->i_ino); |
@@ -1144,14 +1152,15 @@ static int udf_fill_partdesc_info(struct super_block *sb, | |||
1144 | phd->freedSpaceTable.extPosition), | 1152 | phd->freedSpaceTable.extPosition), |
1145 | .partitionReferenceNum = p_index, | 1153 | .partitionReferenceNum = p_index, |
1146 | }; | 1154 | }; |
1155 | struct inode *inode; | ||
1147 | 1156 | ||
1148 | map->s_fspace.s_table = udf_iget(sb, &loc); | 1157 | inode = udf_iget(sb, &loc); |
1149 | if (!map->s_fspace.s_table) { | 1158 | if (IS_ERR(inode)) { |
1150 | udf_debug("cannot load freedSpaceTable (part %d)\n", | 1159 | udf_debug("cannot load freedSpaceTable (part %d)\n", |
1151 | p_index); | 1160 | p_index); |
1152 | return -EIO; | 1161 | return PTR_ERR(inode); |
1153 | } | 1162 | } |
1154 | 1163 | map->s_fspace.s_table = inode; | |
1155 | map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE; | 1164 | map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE; |
1156 | udf_debug("freedSpaceTable (part %d) @ %ld\n", | 1165 | udf_debug("freedSpaceTable (part %d) @ %ld\n", |
1157 | p_index, map->s_fspace.s_table->i_ino); | 1166 | p_index, map->s_fspace.s_table->i_ino); |
@@ -1178,6 +1187,7 @@ static void udf_find_vat_block(struct super_block *sb, int p_index, | |||
1178 | struct udf_part_map *map = &sbi->s_partmaps[p_index]; | 1187 | struct udf_part_map *map = &sbi->s_partmaps[p_index]; |
1179 | sector_t vat_block; | 1188 | sector_t vat_block; |
1180 | struct kernel_lb_addr ino; | 1189 | struct kernel_lb_addr ino; |
1190 | struct inode *inode; | ||
1181 | 1191 | ||
1182 | /* | 1192 | /* |
1183 | * VAT file entry is in the last recorded block. Some broken disks have | 1193 | * VAT file entry is in the last recorded block. Some broken disks have |
@@ -1186,10 +1196,13 @@ static void udf_find_vat_block(struct super_block *sb, int p_index, | |||
1186 | ino.partitionReferenceNum = type1_index; | 1196 | ino.partitionReferenceNum = type1_index; |
1187 | for (vat_block = start_block; | 1197 | for (vat_block = start_block; |
1188 | vat_block >= map->s_partition_root && | 1198 | vat_block >= map->s_partition_root && |
1189 | vat_block >= start_block - 3 && | 1199 | vat_block >= start_block - 3; vat_block--) { |
1190 | !sbi->s_vat_inode; vat_block--) { | ||
1191 | ino.logicalBlockNum = vat_block - map->s_partition_root; | 1200 | ino.logicalBlockNum = vat_block - map->s_partition_root; |
1192 | sbi->s_vat_inode = udf_iget(sb, &ino); | 1201 | inode = udf_iget(sb, &ino); |
1202 | if (!IS_ERR(inode)) { | ||
1203 | sbi->s_vat_inode = inode; | ||
1204 | break; | ||
1205 | } | ||
1193 | } | 1206 | } |
1194 | } | 1207 | } |
1195 | 1208 | ||
@@ -2205,10 +2218,10 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent) | |||
2205 | /* assign inodes by physical block number */ | 2218 | /* assign inodes by physical block number */ |
2206 | /* perhaps it's not extensible enough, but for now ... */ | 2219 | /* perhaps it's not extensible enough, but for now ... */ |
2207 | inode = udf_iget(sb, &rootdir); | 2220 | inode = udf_iget(sb, &rootdir); |
2208 | if (!inode) { | 2221 | if (IS_ERR(inode)) { |
2209 | udf_err(sb, "Error in udf_iget, block=%d, partition=%d\n", | 2222 | udf_err(sb, "Error in udf_iget, block=%d, partition=%d\n", |
2210 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); | 2223 | rootdir.logicalBlockNum, rootdir.partitionReferenceNum); |
2211 | ret = -EIO; | 2224 | ret = PTR_ERR(inode); |
2212 | goto error_out; | 2225 | goto error_out; |
2213 | } | 2226 | } |
2214 | 2227 | ||
diff --git a/fs/udf/udfdecl.h b/fs/udf/udfdecl.h index be7dabbbcb49..742557be9936 100644 --- a/fs/udf/udfdecl.h +++ b/fs/udf/udfdecl.h | |||
@@ -143,7 +143,6 @@ extern int udf_expand_file_adinicb(struct inode *); | |||
143 | extern struct buffer_head *udf_expand_dir_adinicb(struct inode *, int *, int *); | 143 | extern struct buffer_head *udf_expand_dir_adinicb(struct inode *, int *, int *); |
144 | extern struct buffer_head *udf_bread(struct inode *, int, int, int *); | 144 | extern struct buffer_head *udf_bread(struct inode *, int, int, int *); |
145 | extern int udf_setsize(struct inode *, loff_t); | 145 | extern int udf_setsize(struct inode *, loff_t); |
146 | extern void udf_read_inode(struct inode *); | ||
147 | extern void udf_evict_inode(struct inode *); | 146 | extern void udf_evict_inode(struct inode *); |
148 | extern int udf_write_inode(struct inode *, struct writeback_control *wbc); | 147 | extern int udf_write_inode(struct inode *, struct writeback_control *wbc); |
149 | extern long udf_block_map(struct inode *, sector_t); | 148 | extern long udf_block_map(struct inode *, sector_t); |
@@ -209,7 +208,7 @@ extern int udf_CS0toUTF8(struct ustr *, const struct ustr *); | |||
209 | 208 | ||
210 | /* ialloc.c */ | 209 | /* ialloc.c */ |
211 | extern void udf_free_inode(struct inode *); | 210 | extern void udf_free_inode(struct inode *); |
212 | extern struct inode *udf_new_inode(struct inode *, umode_t, int *); | 211 | extern struct inode *udf_new_inode(struct inode *, umode_t); |
213 | 212 | ||
214 | /* truncate.c */ | 213 | /* truncate.c */ |
215 | extern void udf_truncate_tail_extent(struct inode *); | 214 | extern void udf_truncate_tail_extent(struct inode *); |
diff --git a/fs/ufs/ialloc.c b/fs/ufs/ialloc.c index a9cc75ffa925..7caa01652888 100644 --- a/fs/ufs/ialloc.c +++ b/fs/ufs/ialloc.c | |||
@@ -298,7 +298,10 @@ cg_found: | |||
298 | ufsi->i_oeftflag = 0; | 298 | ufsi->i_oeftflag = 0; |
299 | ufsi->i_dir_start_lookup = 0; | 299 | ufsi->i_dir_start_lookup = 0; |
300 | memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1)); | 300 | memset(&ufsi->i_u1, 0, sizeof(ufsi->i_u1)); |
301 | insert_inode_hash(inode); | 301 | if (insert_inode_locked(inode) < 0) { |
302 | err = -EIO; | ||
303 | goto failed; | ||
304 | } | ||
302 | mark_inode_dirty(inode); | 305 | mark_inode_dirty(inode); |
303 | 306 | ||
304 | if (uspi->fs_magic == UFS2_MAGIC) { | 307 | if (uspi->fs_magic == UFS2_MAGIC) { |
@@ -337,6 +340,7 @@ cg_found: | |||
337 | fail_remove_inode: | 340 | fail_remove_inode: |
338 | unlock_ufs(sb); | 341 | unlock_ufs(sb); |
339 | clear_nlink(inode); | 342 | clear_nlink(inode); |
343 | unlock_new_inode(inode); | ||
340 | iput(inode); | 344 | iput(inode); |
341 | UFSD("EXIT (FAILED): err %d\n", err); | 345 | UFSD("EXIT (FAILED): err %d\n", err); |
342 | return ERR_PTR(err); | 346 | return ERR_PTR(err); |
diff --git a/fs/ufs/inode.c b/fs/ufs/inode.c index 7c580c97990e..be7d42c7d938 100644 --- a/fs/ufs/inode.c +++ b/fs/ufs/inode.c | |||
@@ -902,9 +902,6 @@ void ufs_evict_inode(struct inode * inode) | |||
902 | invalidate_inode_buffers(inode); | 902 | invalidate_inode_buffers(inode); |
903 | clear_inode(inode); | 903 | clear_inode(inode); |
904 | 904 | ||
905 | if (want_delete) { | 905 | if (want_delete) |
906 | lock_ufs(inode->i_sb); | 906 | ufs_free_inode(inode); |
907 | ufs_free_inode (inode); | ||
908 | unlock_ufs(inode->i_sb); | ||
909 | } | ||
910 | } | 907 | } |
diff --git a/fs/ufs/namei.c b/fs/ufs/namei.c index 90d74b8f8eba..fd65deb4b5f0 100644 --- a/fs/ufs/namei.c +++ b/fs/ufs/namei.c | |||
@@ -38,10 +38,12 @@ static inline int ufs_add_nondir(struct dentry *dentry, struct inode *inode) | |||
38 | { | 38 | { |
39 | int err = ufs_add_link(dentry, inode); | 39 | int err = ufs_add_link(dentry, inode); |
40 | if (!err) { | 40 | if (!err) { |
41 | unlock_new_inode(inode); | ||
41 | d_instantiate(dentry, inode); | 42 | d_instantiate(dentry, inode); |
42 | return 0; | 43 | return 0; |
43 | } | 44 | } |
44 | inode_dec_link_count(inode); | 45 | inode_dec_link_count(inode); |
46 | unlock_new_inode(inode); | ||
45 | iput(inode); | 47 | iput(inode); |
46 | return err; | 48 | return err; |
47 | } | 49 | } |
@@ -126,12 +128,12 @@ static int ufs_symlink (struct inode * dir, struct dentry * dentry, | |||
126 | if (l > sb->s_blocksize) | 128 | if (l > sb->s_blocksize) |
127 | goto out_notlocked; | 129 | goto out_notlocked; |
128 | 130 | ||
129 | lock_ufs(dir->i_sb); | ||
130 | inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO); | 131 | inode = ufs_new_inode(dir, S_IFLNK | S_IRWXUGO); |
131 | err = PTR_ERR(inode); | 132 | err = PTR_ERR(inode); |
132 | if (IS_ERR(inode)) | 133 | if (IS_ERR(inode)) |
133 | goto out; | 134 | goto out_notlocked; |
134 | 135 | ||
136 | lock_ufs(dir->i_sb); | ||
135 | if (l > UFS_SB(sb)->s_uspi->s_maxsymlinklen) { | 137 | if (l > UFS_SB(sb)->s_uspi->s_maxsymlinklen) { |
136 | /* slow symlink */ | 138 | /* slow symlink */ |
137 | inode->i_op = &ufs_symlink_inode_operations; | 139 | inode->i_op = &ufs_symlink_inode_operations; |
@@ -155,6 +157,7 @@ out_notlocked: | |||
155 | 157 | ||
156 | out_fail: | 158 | out_fail: |
157 | inode_dec_link_count(inode); | 159 | inode_dec_link_count(inode); |
160 | unlock_new_inode(inode); | ||
158 | iput(inode); | 161 | iput(inode); |
159 | goto out; | 162 | goto out; |
160 | } | 163 | } |
@@ -181,13 +184,9 @@ static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode) | |||
181 | struct inode * inode; | 184 | struct inode * inode; |
182 | int err; | 185 | int err; |
183 | 186 | ||
184 | lock_ufs(dir->i_sb); | ||
185 | inode_inc_link_count(dir); | ||
186 | |||
187 | inode = ufs_new_inode(dir, S_IFDIR|mode); | 187 | inode = ufs_new_inode(dir, S_IFDIR|mode); |
188 | err = PTR_ERR(inode); | ||
189 | if (IS_ERR(inode)) | 188 | if (IS_ERR(inode)) |
190 | goto out_dir; | 189 | return PTR_ERR(inode); |
191 | 190 | ||
192 | inode->i_op = &ufs_dir_inode_operations; | 191 | inode->i_op = &ufs_dir_inode_operations; |
193 | inode->i_fop = &ufs_dir_operations; | 192 | inode->i_fop = &ufs_dir_operations; |
@@ -195,6 +194,9 @@ static int ufs_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode) | |||
195 | 194 | ||
196 | inode_inc_link_count(inode); | 195 | inode_inc_link_count(inode); |
197 | 196 | ||
197 | lock_ufs(dir->i_sb); | ||
198 | inode_inc_link_count(dir); | ||
199 | |||
198 | err = ufs_make_empty(inode, dir); | 200 | err = ufs_make_empty(inode, dir); |
199 | if (err) | 201 | if (err) |
200 | goto out_fail; | 202 | goto out_fail; |
@@ -211,8 +213,8 @@ out: | |||
211 | out_fail: | 213 | out_fail: |
212 | inode_dec_link_count(inode); | 214 | inode_dec_link_count(inode); |
213 | inode_dec_link_count(inode); | 215 | inode_dec_link_count(inode); |
216 | unlock_new_inode(inode); | ||
214 | iput (inode); | 217 | iput (inode); |
215 | out_dir: | ||
216 | inode_dec_link_count(dir); | 218 | inode_dec_link_count(dir); |
217 | unlock_ufs(dir->i_sb); | 219 | unlock_ufs(dir->i_sb); |
218 | goto out; | 220 | goto out; |
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c index de2d26d32844..86df952d3e24 100644 --- a/fs/xfs/libxfs/xfs_bmap.c +++ b/fs/xfs/libxfs/xfs_bmap.c | |||
@@ -5424,7 +5424,7 @@ xfs_bmap_shift_extents( | |||
5424 | struct xfs_bmap_free *flist, | 5424 | struct xfs_bmap_free *flist, |
5425 | int num_exts) | 5425 | int num_exts) |
5426 | { | 5426 | { |
5427 | struct xfs_btree_cur *cur; | 5427 | struct xfs_btree_cur *cur = NULL; |
5428 | struct xfs_bmbt_rec_host *gotp; | 5428 | struct xfs_bmbt_rec_host *gotp; |
5429 | struct xfs_bmbt_irec got; | 5429 | struct xfs_bmbt_irec got; |
5430 | struct xfs_bmbt_irec left; | 5430 | struct xfs_bmbt_irec left; |
@@ -5435,7 +5435,7 @@ xfs_bmap_shift_extents( | |||
5435 | int error = 0; | 5435 | int error = 0; |
5436 | int i; | 5436 | int i; |
5437 | int whichfork = XFS_DATA_FORK; | 5437 | int whichfork = XFS_DATA_FORK; |
5438 | int logflags; | 5438 | int logflags = 0; |
5439 | xfs_filblks_t blockcount = 0; | 5439 | xfs_filblks_t blockcount = 0; |
5440 | int total_extents; | 5440 | int total_extents; |
5441 | 5441 | ||
@@ -5478,16 +5478,11 @@ xfs_bmap_shift_extents( | |||
5478 | } | 5478 | } |
5479 | } | 5479 | } |
5480 | 5480 | ||
5481 | /* We are going to change core inode */ | ||
5482 | logflags = XFS_ILOG_CORE; | ||
5483 | if (ifp->if_flags & XFS_IFBROOT) { | 5481 | if (ifp->if_flags & XFS_IFBROOT) { |
5484 | cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); | 5482 | cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); |
5485 | cur->bc_private.b.firstblock = *firstblock; | 5483 | cur->bc_private.b.firstblock = *firstblock; |
5486 | cur->bc_private.b.flist = flist; | 5484 | cur->bc_private.b.flist = flist; |
5487 | cur->bc_private.b.flags = 0; | 5485 | cur->bc_private.b.flags = 0; |
5488 | } else { | ||
5489 | cur = NULL; | ||
5490 | logflags |= XFS_ILOG_DEXT; | ||
5491 | } | 5486 | } |
5492 | 5487 | ||
5493 | /* | 5488 | /* |
@@ -5545,11 +5540,14 @@ xfs_bmap_shift_extents( | |||
5545 | blockcount = left.br_blockcount + | 5540 | blockcount = left.br_blockcount + |
5546 | got.br_blockcount; | 5541 | got.br_blockcount; |
5547 | xfs_iext_remove(ip, *current_ext, 1, 0); | 5542 | xfs_iext_remove(ip, *current_ext, 1, 0); |
5543 | logflags |= XFS_ILOG_CORE; | ||
5548 | if (cur) { | 5544 | if (cur) { |
5549 | error = xfs_btree_delete(cur, &i); | 5545 | error = xfs_btree_delete(cur, &i); |
5550 | if (error) | 5546 | if (error) |
5551 | goto del_cursor; | 5547 | goto del_cursor; |
5552 | XFS_WANT_CORRUPTED_GOTO(i == 1, del_cursor); | 5548 | XFS_WANT_CORRUPTED_GOTO(i == 1, del_cursor); |
5549 | } else { | ||
5550 | logflags |= XFS_ILOG_DEXT; | ||
5553 | } | 5551 | } |
5554 | XFS_IFORK_NEXT_SET(ip, whichfork, | 5552 | XFS_IFORK_NEXT_SET(ip, whichfork, |
5555 | XFS_IFORK_NEXTENTS(ip, whichfork) - 1); | 5553 | XFS_IFORK_NEXTENTS(ip, whichfork) - 1); |
@@ -5575,6 +5573,7 @@ xfs_bmap_shift_extents( | |||
5575 | got.br_startoff = startoff; | 5573 | got.br_startoff = startoff; |
5576 | } | 5574 | } |
5577 | 5575 | ||
5576 | logflags |= XFS_ILOG_CORE; | ||
5578 | if (cur) { | 5577 | if (cur) { |
5579 | error = xfs_bmbt_update(cur, got.br_startoff, | 5578 | error = xfs_bmbt_update(cur, got.br_startoff, |
5580 | got.br_startblock, | 5579 | got.br_startblock, |
@@ -5582,6 +5581,8 @@ xfs_bmap_shift_extents( | |||
5582 | got.br_state); | 5581 | got.br_state); |
5583 | if (error) | 5582 | if (error) |
5584 | goto del_cursor; | 5583 | goto del_cursor; |
5584 | } else { | ||
5585 | logflags |= XFS_ILOG_DEXT; | ||
5585 | } | 5586 | } |
5586 | 5587 | ||
5587 | (*current_ext)++; | 5588 | (*current_ext)++; |
@@ -5597,6 +5598,7 @@ del_cursor: | |||
5597 | xfs_btree_del_cursor(cur, | 5598 | xfs_btree_del_cursor(cur, |
5598 | error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR); | 5599 | error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR); |
5599 | 5600 | ||
5600 | xfs_trans_log_inode(tp, ip, logflags); | 5601 | if (logflags) |
5602 | xfs_trans_log_inode(tp, ip, logflags); | ||
5601 | return error; | 5603 | return error; |
5602 | } | 5604 | } |
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c index 11e9b4caa54f..b984647c24db 100644 --- a/fs/xfs/xfs_aops.c +++ b/fs/xfs/xfs_aops.c | |||
@@ -1753,11 +1753,72 @@ xfs_vm_readpages( | |||
1753 | return mpage_readpages(mapping, pages, nr_pages, xfs_get_blocks); | 1753 | return mpage_readpages(mapping, pages, nr_pages, xfs_get_blocks); |
1754 | } | 1754 | } |
1755 | 1755 | ||
1756 | /* | ||
1757 | * This is basically a copy of __set_page_dirty_buffers() with one | ||
1758 | * small tweak: buffers beyond EOF do not get marked dirty. If we mark them | ||
1759 | * dirty, we'll never be able to clean them because we don't write buffers | ||
1760 | * beyond EOF, and that means we can't invalidate pages that span EOF | ||
1761 | * that have been marked dirty. Further, the dirty state can leak into | ||
1762 | * the file interior if the file is extended, resulting in all sorts of | ||
1763 | * bad things happening as the state does not match the underlying data. | ||
1764 | * | ||
1765 | * XXX: this really indicates that bufferheads in XFS need to die. Warts like | ||
1766 | * this only exist because of bufferheads and how the generic code manages them. | ||
1767 | */ | ||
1768 | STATIC int | ||
1769 | xfs_vm_set_page_dirty( | ||
1770 | struct page *page) | ||
1771 | { | ||
1772 | struct address_space *mapping = page->mapping; | ||
1773 | struct inode *inode = mapping->host; | ||
1774 | loff_t end_offset; | ||
1775 | loff_t offset; | ||
1776 | int newly_dirty; | ||
1777 | |||
1778 | if (unlikely(!mapping)) | ||
1779 | return !TestSetPageDirty(page); | ||
1780 | |||
1781 | end_offset = i_size_read(inode); | ||
1782 | offset = page_offset(page); | ||
1783 | |||
1784 | spin_lock(&mapping->private_lock); | ||
1785 | if (page_has_buffers(page)) { | ||
1786 | struct buffer_head *head = page_buffers(page); | ||
1787 | struct buffer_head *bh = head; | ||
1788 | |||
1789 | do { | ||
1790 | if (offset < end_offset) | ||
1791 | set_buffer_dirty(bh); | ||
1792 | bh = bh->b_this_page; | ||
1793 | offset += 1 << inode->i_blkbits; | ||
1794 | } while (bh != head); | ||
1795 | } | ||
1796 | newly_dirty = !TestSetPageDirty(page); | ||
1797 | spin_unlock(&mapping->private_lock); | ||
1798 | |||
1799 | if (newly_dirty) { | ||
1800 | /* sigh - __set_page_dirty() is static, so copy it here, too */ | ||
1801 | unsigned long flags; | ||
1802 | |||
1803 | spin_lock_irqsave(&mapping->tree_lock, flags); | ||
1804 | if (page->mapping) { /* Race with truncate? */ | ||
1805 | WARN_ON_ONCE(!PageUptodate(page)); | ||
1806 | account_page_dirtied(page, mapping); | ||
1807 | radix_tree_tag_set(&mapping->page_tree, | ||
1808 | page_index(page), PAGECACHE_TAG_DIRTY); | ||
1809 | } | ||
1810 | spin_unlock_irqrestore(&mapping->tree_lock, flags); | ||
1811 | __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); | ||
1812 | } | ||
1813 | return newly_dirty; | ||
1814 | } | ||
1815 | |||
1756 | const struct address_space_operations xfs_address_space_operations = { | 1816 | const struct address_space_operations xfs_address_space_operations = { |
1757 | .readpage = xfs_vm_readpage, | 1817 | .readpage = xfs_vm_readpage, |
1758 | .readpages = xfs_vm_readpages, | 1818 | .readpages = xfs_vm_readpages, |
1759 | .writepage = xfs_vm_writepage, | 1819 | .writepage = xfs_vm_writepage, |
1760 | .writepages = xfs_vm_writepages, | 1820 | .writepages = xfs_vm_writepages, |
1821 | .set_page_dirty = xfs_vm_set_page_dirty, | ||
1761 | .releasepage = xfs_vm_releasepage, | 1822 | .releasepage = xfs_vm_releasepage, |
1762 | .invalidatepage = xfs_vm_invalidatepage, | 1823 | .invalidatepage = xfs_vm_invalidatepage, |
1763 | .write_begin = xfs_vm_write_begin, | 1824 | .write_begin = xfs_vm_write_begin, |
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index 2f1e30d39a35..1707980f9a4b 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c | |||
@@ -1470,6 +1470,26 @@ xfs_collapse_file_space( | |||
1470 | start_fsb = XFS_B_TO_FSB(mp, offset + len); | 1470 | start_fsb = XFS_B_TO_FSB(mp, offset + len); |
1471 | shift_fsb = XFS_B_TO_FSB(mp, len); | 1471 | shift_fsb = XFS_B_TO_FSB(mp, len); |
1472 | 1472 | ||
1473 | /* | ||
1474 | * Writeback the entire file and force remove any post-eof blocks. The | ||
1475 | * writeback prevents changes to the extent list via concurrent | ||
1476 | * writeback and the eofblocks trim prevents the extent shift algorithm | ||
1477 | * from running into a post-eof delalloc extent. | ||
1478 | * | ||
1479 | * XXX: This is a temporary fix until the extent shift loop below is | ||
1480 | * converted to use offsets and lookups within the ILOCK rather than | ||
1481 | * carrying around the index into the extent list for the next | ||
1482 | * iteration. | ||
1483 | */ | ||
1484 | error = filemap_write_and_wait(VFS_I(ip)->i_mapping); | ||
1485 | if (error) | ||
1486 | return error; | ||
1487 | if (xfs_can_free_eofblocks(ip, true)) { | ||
1488 | error = xfs_free_eofblocks(mp, ip, false); | ||
1489 | if (error) | ||
1490 | return error; | ||
1491 | } | ||
1492 | |||
1473 | error = xfs_free_file_space(ip, offset, len); | 1493 | error = xfs_free_file_space(ip, offset, len); |
1474 | if (error) | 1494 | if (error) |
1475 | return error; | 1495 | return error; |
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index 076b1708d134..de5368c803f9 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c | |||
@@ -291,12 +291,22 @@ xfs_file_read_iter( | |||
291 | if (inode->i_mapping->nrpages) { | 291 | if (inode->i_mapping->nrpages) { |
292 | ret = filemap_write_and_wait_range( | 292 | ret = filemap_write_and_wait_range( |
293 | VFS_I(ip)->i_mapping, | 293 | VFS_I(ip)->i_mapping, |
294 | pos, -1); | 294 | pos, pos + size - 1); |
295 | if (ret) { | 295 | if (ret) { |
296 | xfs_rw_iunlock(ip, XFS_IOLOCK_EXCL); | 296 | xfs_rw_iunlock(ip, XFS_IOLOCK_EXCL); |
297 | return ret; | 297 | return ret; |
298 | } | 298 | } |
299 | truncate_pagecache_range(VFS_I(ip), pos, -1); | 299 | |
300 | /* | ||
301 | * Invalidate whole pages. This can return an error if | ||
302 | * we fail to invalidate a page, but this should never | ||
303 | * happen on XFS. Warn if it does fail. | ||
304 | */ | ||
305 | ret = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping, | ||
306 | pos >> PAGE_CACHE_SHIFT, | ||
307 | (pos + size - 1) >> PAGE_CACHE_SHIFT); | ||
308 | WARN_ON_ONCE(ret); | ||
309 | ret = 0; | ||
300 | } | 310 | } |
301 | xfs_rw_ilock_demote(ip, XFS_IOLOCK_EXCL); | 311 | xfs_rw_ilock_demote(ip, XFS_IOLOCK_EXCL); |
302 | } | 312 | } |
@@ -632,10 +642,19 @@ xfs_file_dio_aio_write( | |||
632 | 642 | ||
633 | if (mapping->nrpages) { | 643 | if (mapping->nrpages) { |
634 | ret = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, | 644 | ret = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, |
635 | pos, -1); | 645 | pos, pos + count - 1); |
636 | if (ret) | 646 | if (ret) |
637 | goto out; | 647 | goto out; |
638 | truncate_pagecache_range(VFS_I(ip), pos, -1); | 648 | /* |
649 | * Invalidate whole pages. This can return an error if | ||
650 | * we fail to invalidate a page, but this should never | ||
651 | * happen on XFS. Warn if it does fail. | ||
652 | */ | ||
653 | ret = invalidate_inode_pages2_range(VFS_I(ip)->i_mapping, | ||
654 | pos >> PAGE_CACHE_SHIFT, | ||
655 | (pos + count - 1) >> PAGE_CACHE_SHIFT); | ||
656 | WARN_ON_ONCE(ret); | ||
657 | ret = 0; | ||
639 | } | 658 | } |
640 | 659 | ||
641 | /* | 660 | /* |