diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2016-06-30 07:10:49 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2016-06-30 07:10:49 -0400 |
commit | 5c672ab3f0ee0f78f7acad183f34db0f8781a200 (patch) | |
tree | 8504dad9b399cbef1a3e252c7253325d51740eae /fs | |
parent | 4c2e07c6a29e0129e975727b9f57eede813eea85 (diff) |
fuse: serialize dirops by default
Negotiate with userspace filesystems whether they support parallel readdir
and lookup. Disable parallelism by default for fear of breaking fuse
filesystems.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Fixes: 9902af79c01a ("parallel lookups: actual switch to rwsem")
Fixes: d9b3dbdcfd62 ("fuse: switch to ->iterate_shared()")
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fuse/dir.c | 4 | ||||
-rw-r--r-- | fs/fuse/fuse_i.h | 9 | ||||
-rw-r--r-- | fs/fuse/inode.c | 19 |
3 files changed, 31 insertions, 1 deletions
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index ccd4971cc6c1..264f07c7754e 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c | |||
@@ -341,8 +341,10 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry, | |||
341 | struct dentry *newent; | 341 | struct dentry *newent; |
342 | bool outarg_valid = true; | 342 | bool outarg_valid = true; |
343 | 343 | ||
344 | fuse_lock_inode(dir); | ||
344 | err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name, | 345 | err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name, |
345 | &outarg, &inode); | 346 | &outarg, &inode); |
347 | fuse_unlock_inode(dir); | ||
346 | if (err == -ENOENT) { | 348 | if (err == -ENOENT) { |
347 | outarg_valid = false; | 349 | outarg_valid = false; |
348 | err = 0; | 350 | err = 0; |
@@ -1341,7 +1343,9 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx) | |||
1341 | fuse_read_fill(req, file, ctx->pos, PAGE_SIZE, | 1343 | fuse_read_fill(req, file, ctx->pos, PAGE_SIZE, |
1342 | FUSE_READDIR); | 1344 | FUSE_READDIR); |
1343 | } | 1345 | } |
1346 | fuse_lock_inode(inode); | ||
1344 | fuse_request_send(fc, req); | 1347 | fuse_request_send(fc, req); |
1348 | fuse_unlock_inode(inode); | ||
1345 | nbytes = req->out.args[0].size; | 1349 | nbytes = req->out.args[0].size; |
1346 | err = req->out.h.error; | 1350 | err = req->out.h.error; |
1347 | fuse_put_request(fc, req); | 1351 | fuse_put_request(fc, req); |
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index eddbe02c4028..929c383432b0 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h | |||
@@ -110,6 +110,9 @@ struct fuse_inode { | |||
110 | 110 | ||
111 | /** Miscellaneous bits describing inode state */ | 111 | /** Miscellaneous bits describing inode state */ |
112 | unsigned long state; | 112 | unsigned long state; |
113 | |||
114 | /** Lock for serializing lookup and readdir for back compatibility*/ | ||
115 | struct mutex mutex; | ||
113 | }; | 116 | }; |
114 | 117 | ||
115 | /** FUSE inode state bits */ | 118 | /** FUSE inode state bits */ |
@@ -540,6 +543,9 @@ struct fuse_conn { | |||
540 | /** write-back cache policy (default is write-through) */ | 543 | /** write-back cache policy (default is write-through) */ |
541 | unsigned writeback_cache:1; | 544 | unsigned writeback_cache:1; |
542 | 545 | ||
546 | /** allow parallel lookups and readdir (default is serialized) */ | ||
547 | unsigned parallel_dirops:1; | ||
548 | |||
543 | /* | 549 | /* |
544 | * The following bitfields are only for optimization purposes | 550 | * The following bitfields are only for optimization purposes |
545 | * and hence races in setting them will not cause malfunction | 551 | * and hence races in setting them will not cause malfunction |
@@ -956,4 +962,7 @@ int fuse_do_setattr(struct inode *inode, struct iattr *attr, | |||
956 | 962 | ||
957 | void fuse_set_initialized(struct fuse_conn *fc); | 963 | void fuse_set_initialized(struct fuse_conn *fc); |
958 | 964 | ||
965 | void fuse_unlock_inode(struct inode *inode); | ||
966 | void fuse_lock_inode(struct inode *inode); | ||
967 | |||
959 | #endif /* _FS_FUSE_I_H */ | 968 | #endif /* _FS_FUSE_I_H */ |
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 1ce67668a8e1..9961d8432ce3 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c | |||
@@ -97,6 +97,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb) | |||
97 | INIT_LIST_HEAD(&fi->queued_writes); | 97 | INIT_LIST_HEAD(&fi->queued_writes); |
98 | INIT_LIST_HEAD(&fi->writepages); | 98 | INIT_LIST_HEAD(&fi->writepages); |
99 | init_waitqueue_head(&fi->page_waitq); | 99 | init_waitqueue_head(&fi->page_waitq); |
100 | mutex_init(&fi->mutex); | ||
100 | fi->forget = fuse_alloc_forget(); | 101 | fi->forget = fuse_alloc_forget(); |
101 | if (!fi->forget) { | 102 | if (!fi->forget) { |
102 | kmem_cache_free(fuse_inode_cachep, inode); | 103 | kmem_cache_free(fuse_inode_cachep, inode); |
@@ -117,6 +118,7 @@ static void fuse_destroy_inode(struct inode *inode) | |||
117 | struct fuse_inode *fi = get_fuse_inode(inode); | 118 | struct fuse_inode *fi = get_fuse_inode(inode); |
118 | BUG_ON(!list_empty(&fi->write_files)); | 119 | BUG_ON(!list_empty(&fi->write_files)); |
119 | BUG_ON(!list_empty(&fi->queued_writes)); | 120 | BUG_ON(!list_empty(&fi->queued_writes)); |
121 | mutex_destroy(&fi->mutex); | ||
120 | kfree(fi->forget); | 122 | kfree(fi->forget); |
121 | call_rcu(&inode->i_rcu, fuse_i_callback); | 123 | call_rcu(&inode->i_rcu, fuse_i_callback); |
122 | } | 124 | } |
@@ -351,6 +353,18 @@ int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid, | |||
351 | return 0; | 353 | return 0; |
352 | } | 354 | } |
353 | 355 | ||
356 | void fuse_lock_inode(struct inode *inode) | ||
357 | { | ||
358 | if (!get_fuse_conn(inode)->parallel_dirops) | ||
359 | mutex_lock(&get_fuse_inode(inode)->mutex); | ||
360 | } | ||
361 | |||
362 | void fuse_unlock_inode(struct inode *inode) | ||
363 | { | ||
364 | if (!get_fuse_conn(inode)->parallel_dirops) | ||
365 | mutex_unlock(&get_fuse_inode(inode)->mutex); | ||
366 | } | ||
367 | |||
354 | static void fuse_umount_begin(struct super_block *sb) | 368 | static void fuse_umount_begin(struct super_block *sb) |
355 | { | 369 | { |
356 | fuse_abort_conn(get_fuse_conn_super(sb)); | 370 | fuse_abort_conn(get_fuse_conn_super(sb)); |
@@ -898,6 +912,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req) | |||
898 | fc->async_dio = 1; | 912 | fc->async_dio = 1; |
899 | if (arg->flags & FUSE_WRITEBACK_CACHE) | 913 | if (arg->flags & FUSE_WRITEBACK_CACHE) |
900 | fc->writeback_cache = 1; | 914 | fc->writeback_cache = 1; |
915 | if (arg->flags & FUSE_PARALLEL_DIROPS) | ||
916 | fc->parallel_dirops = 1; | ||
901 | if (arg->time_gran && arg->time_gran <= 1000000000) | 917 | if (arg->time_gran && arg->time_gran <= 1000000000) |
902 | fc->sb->s_time_gran = arg->time_gran; | 918 | fc->sb->s_time_gran = arg->time_gran; |
903 | } else { | 919 | } else { |
@@ -928,7 +944,8 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req) | |||
928 | FUSE_SPLICE_WRITE | FUSE_SPLICE_MOVE | FUSE_SPLICE_READ | | 944 | FUSE_SPLICE_WRITE | FUSE_SPLICE_MOVE | FUSE_SPLICE_READ | |
929 | FUSE_FLOCK_LOCKS | FUSE_IOCTL_DIR | FUSE_AUTO_INVAL_DATA | | 945 | FUSE_FLOCK_LOCKS | FUSE_IOCTL_DIR | FUSE_AUTO_INVAL_DATA | |
930 | FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO | | 946 | FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO | |
931 | FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT; | 947 | FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT | |
948 | FUSE_PARALLEL_DIROPS; | ||
932 | req->in.h.opcode = FUSE_INIT; | 949 | req->in.h.opcode = FUSE_INIT; |
933 | req->in.numargs = 1; | 950 | req->in.numargs = 1; |
934 | req->in.args[0].size = sizeof(*arg); | 951 | req->in.args[0].size = sizeof(*arg); |