aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/file.c2
-rw-r--r--fs/btrfs/inode.c191
-rw-r--r--fs/btrfs/ioctl.c32
-rw-r--r--fs/btrfs/tree-log.c77
-rw-r--r--fs/btrfs/tree-log.h2
-rw-r--r--fs/dcache.c11
-rw-r--r--fs/eventpoll.c3
-rw-r--r--fs/namei.c96
-rw-r--r--fs/nfs/client.c12
-rw-r--r--fs/nfs/filelayout/filelayout.c5
-rw-r--r--fs/nfs/nfs4_fs.h13
-rw-r--r--fs/nfs/nfs4state.c24
-rw-r--r--fs/notify/fdinfo.c4
13 files changed, 285 insertions, 187 deletions
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,
1006out: 1010out:
1007 return ret; 1011 return ret;
1008 1012
1013out_drop_extent_cache:
1014 btrfs_drop_extent_cache(inode, start, start + ram_size - 1, 0);
1009out_reserve: 1015out_reserve:
1010 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1); 1016 btrfs_free_reserved_extent(root, ins.objectid, ins.offset, 1);
1011out_unlock: 1017out_unlock:
@@ -4242,7 +4248,8 @@ out:
4242 btrfs_abort_transaction(trans, root, ret); 4248 btrfs_abort_transaction(trans, root, ret);
4243 } 4249 }
4244error: 4250error:
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
5637static 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
5630static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, 5648static 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
5800fail_unlock:
5801 unlock_new_inode(inode);
5778fail: 5802fail:
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
5934out_unlock: 5958out_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
5968out_unlock_inode:
5969 drop_inode = 1;
5970 unlock_new_inode(inode);
5971 goto out_unlock;
5972
5943} 5973}
5944 5974
5945static int btrfs_create(struct inode *dir, struct dentry *dentry, 5975static 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
6004out_unlock: 6034out_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
6044out_unlock_inode:
6045 unlock_new_inode(inode);
6046 goto out_unlock;
6047
6013} 6048}
6014 6049
6015static int btrfs_link(struct dentry *old_dentry, struct inode *dir, 6050static 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
6141out_fail: 6181out_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
6189out_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
8831out_unlock: 8873out_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
8882out_unlock_inode:
8883 drop_inode = 1;
8884 unlock_new_inode(inode);
8885 goto out_unlock;
8841} 8886}
8842 8887
8843static int __btrfs_prealloc_file_range(struct inode *inode, int mode, 8888static 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
9107out_inode:
9108 unlock_new_inode(inode);
9109 goto out;
9110
9062} 9111}
9063 9112
9064static const struct inode_operations btrfs_dir_inode_operations = { 9113static 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;
1733out: 1736
1734 kfree(vol_args); 1737free_inherit:
1735 kfree(inherit); 1738 kfree(inherit);
1739free_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
2671out: 2676out:
2672 kfree(vol_args); 2677 kfree(vol_args);
2678err_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..d296efe2d3e7 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
96static int btrfs_log_inode(struct btrfs_trans_handle *trans, 96static 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);
99static int link_to_fixup_dir(struct btrfs_trans_handle *trans, 101static 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 */
3860static int btrfs_log_inode(struct btrfs_trans_handle *trans, 3862static 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,8 +4092,19 @@ log_extents:
4065 goto out_unlock; 4092 goto out_unlock;
4066 } 4093 }
4067 } 4094 }
4068 BTRFS_I(inode)->logged_trans = trans->transid; 4095
4069 BTRFS_I(inode)->last_log_commit = BTRFS_I(inode)->last_sub_trans; 4096 write_lock(&em_tree->lock);
4097 /*
4098 * If we're doing a ranged fsync and there are still modified extents
4099 * in the list, we must run on the next fsync call as it might cover
4100 * those extents (a full fsync or an fsync for other range).
4101 */
4102 if (list_empty(&em_tree->modified_extents)) {
4103 BTRFS_I(inode)->logged_trans = trans->transid;
4104 BTRFS_I(inode)->last_log_commit =
4105 BTRFS_I(inode)->last_sub_trans;
4106 }
4107 write_unlock(&em_tree->lock);
4070out_unlock: 4108out_unlock:
4071 if (unlikely(err)) 4109 if (unlikely(err))
4072 btrfs_put_logged_extents(&logged_list); 4110 btrfs_put_logged_extents(&logged_list);
@@ -4161,7 +4199,10 @@ out:
4161 */ 4199 */
4162static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans, 4200static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4163 struct btrfs_root *root, struct inode *inode, 4201 struct btrfs_root *root, struct inode *inode,
4164 struct dentry *parent, int exists_only, 4202 struct dentry *parent,
4203 const loff_t start,
4204 const loff_t end,
4205 int exists_only,
4165 struct btrfs_log_ctx *ctx) 4206 struct btrfs_log_ctx *ctx)
4166{ 4207{
4167 int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL; 4208 int inode_only = exists_only ? LOG_INODE_EXISTS : LOG_INODE_ALL;
@@ -4207,7 +4248,7 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4207 if (ret) 4248 if (ret)
4208 goto end_no_trans; 4249 goto end_no_trans;
4209 4250
4210 ret = btrfs_log_inode(trans, root, inode, inode_only); 4251 ret = btrfs_log_inode(trans, root, inode, inode_only, start, end);
4211 if (ret) 4252 if (ret)
4212 goto end_trans; 4253 goto end_trans;
4213 4254
@@ -4235,7 +4276,8 @@ static int btrfs_log_inode_parent(struct btrfs_trans_handle *trans,
4235 4276
4236 if (BTRFS_I(inode)->generation > 4277 if (BTRFS_I(inode)->generation >
4237 root->fs_info->last_trans_committed) { 4278 root->fs_info->last_trans_committed) {
4238 ret = btrfs_log_inode(trans, root, inode, inode_only); 4279 ret = btrfs_log_inode(trans, root, inode, inode_only,
4280 0, LLONG_MAX);
4239 if (ret) 4281 if (ret)
4240 goto end_trans; 4282 goto end_trans;
4241 } 4283 }
@@ -4269,13 +4311,15 @@ end_no_trans:
4269 */ 4311 */
4270int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, 4312int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans,
4271 struct btrfs_root *root, struct dentry *dentry, 4313 struct btrfs_root *root, struct dentry *dentry,
4314 const loff_t start,
4315 const loff_t end,
4272 struct btrfs_log_ctx *ctx) 4316 struct btrfs_log_ctx *ctx)
4273{ 4317{
4274 struct dentry *parent = dget_parent(dentry); 4318 struct dentry *parent = dget_parent(dentry);
4275 int ret; 4319 int ret;
4276 4320
4277 ret = btrfs_log_inode_parent(trans, root, dentry->d_inode, parent, 4321 ret = btrfs_log_inode_parent(trans, root, dentry->d_inode, parent,
4278 0, ctx); 4322 start, end, 0, ctx);
4279 dput(parent); 4323 dput(parent);
4280 4324
4281 return ret; 4325 return ret;
@@ -4512,6 +4556,7 @@ int btrfs_log_new_name(struct btrfs_trans_handle *trans,
4512 root->fs_info->last_trans_committed)) 4556 root->fs_info->last_trans_committed))
4513 return 0; 4557 return 0;
4514 4558
4515 return btrfs_log_inode_parent(trans, root, inode, parent, 1, NULL); 4559 return btrfs_log_inode_parent(trans, root, inode, parent, 0,
4560 LLONG_MAX, 1, NULL);
4516} 4561}
4517 4562
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,
59int btrfs_recover_log_trees(struct btrfs_root *tree_root); 59int btrfs_recover_log_trees(struct btrfs_root *tree_root);
60int btrfs_log_dentry_safe(struct btrfs_trans_handle *trans, 60int 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);
63int btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans, 65int 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/dcache.c b/fs/dcache.c
index d30ce699ae4b..7a5b51440afa 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. */
@@ -2656,6 +2655,12 @@ static void __d_materialise_dentry(struct dentry *dentry, struct dentry *anon)
2656 dentry->d_parent = dentry; 2655 dentry->d_parent = dentry;
2657 list_del_init(&dentry->d_u.d_child); 2656 list_del_init(&dentry->d_u.d_child);
2658 anon->d_parent = dparent; 2657 anon->d_parent = dparent;
2658 if (likely(!d_unhashed(anon))) {
2659 hlist_bl_lock(&anon->d_sb->s_anon);
2660 __hlist_bl_del(&anon->d_hash);
2661 anon->d_hash.pprev = NULL;
2662 hlist_bl_unlock(&anon->d_sb->s_anon);
2663 }
2659 list_move(&anon->d_u.d_child, &dparent->d_subdirs); 2664 list_move(&anon->d_u.d_child, &dparent->d_subdirs);
2660 2665
2661 write_seqcount_end(&dentry->d_seq); 2666 write_seqcount_end(&dentry->d_seq);
@@ -2714,7 +2719,6 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
2714 write_seqlock(&rename_lock); 2719 write_seqlock(&rename_lock);
2715 __d_materialise_dentry(dentry, new); 2720 __d_materialise_dentry(dentry, new);
2716 write_sequnlock(&rename_lock); 2721 write_sequnlock(&rename_lock);
2717 __d_drop(new);
2718 _d_rehash(new); 2722 _d_rehash(new);
2719 spin_unlock(&new->d_lock); 2723 spin_unlock(&new->d_lock);
2720 spin_unlock(&inode->i_lock); 2724 spin_unlock(&inode->i_lock);
@@ -2778,7 +2782,6 @@ struct dentry *d_materialise_unique(struct dentry *dentry, struct inode *inode)
2778 * could splice into our tree? */ 2782 * could splice into our tree? */
2779 __d_materialise_dentry(dentry, alias); 2783 __d_materialise_dentry(dentry, alias);
2780 write_sequnlock(&rename_lock); 2784 write_sequnlock(&rename_lock);
2781 __d_drop(alias);
2782 goto found; 2785 goto found;
2783 } else { 2786 } else {
2784 /* Nope, but we must(!) avoid directory 2787 /* Nope, but we must(!) avoid directory
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/namei.c b/fs/namei.c
index a996bb48dfab..01d03892316c 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
644static __always_inline void set_root(struct nameidata *nd) 645static __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
650static int link_path_walk(const char *, struct nameidata *); 650static int link_path_walk(const char *, struct nameidata *);
651 651
652static __always_inline void set_root_rcu(struct nameidata *nd) 652static __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
666static void path_put_conditional(struct path *path, struct nameidata *nd) 665static 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
1144static int follow_dotdot_rcu(struct nameidata *nd) 1144static 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
1183failed: 1188failed:
@@ -1256,7 +1261,8 @@ static void follow_mount(struct path *path)
1256 1261
1257static void follow_dotdot(struct nameidata *nd) 1262static 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
1635static inline unsigned int fold_hash(unsigned long hash) 1641static 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 */
1674static inline unsigned long hash_name(const char *name, unsigned int *hashp) 1679static 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 */
1714static inline unsigned long hash_name(const char *name, unsigned int *hashp) 1718static 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
1909static inline int lookup_last(struct nameidata *nd, struct path *path) 1919static inline int lookup_last(struct nameidata *nd, struct path *path)
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
1418error_2:
1419 remove_proc_entry("servers", nn->proc_nfsfs);
1420error_1: 1418error_1:
1421 remove_proc_entry("fs/nfsfs", NULL); 1419 remove_proc_subtree("nfsfs", net->proc_net);
1422error_0: 1420error_0:
1423 return -ENOMEM; 1421 return -ENOMEM;
1424} 1422}
1425 1423
1426void nfs_fs_proc_net_exit(struct net *net) 1424void 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)
1269static void filelayout_retry_commit(struct nfs_commit_info *cinfo, int idx) 1269static 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
132struct nfs4_lock_state { 132struct 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/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
802static void
803free_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;
837out_free: 824out_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
907static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src) 895static void nfs4_fl_copy_lock(struct file_lock *dst, struct file_lock *src)
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 }