Skip to content

Commit 0b295dd

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse
Pull fuse fix from Miklos Szeredi: "This makes sure userspace filesystems are not broken by the parallel lookups and readdir feature" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: fuse: serialize dirops by default
2 parents 236bfd8 + 5c672ab commit 0b295dd

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

fs/fuse/dir.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
341341
struct dentry *newent;
342342
bool outarg_valid = true;
343343

344+
fuse_lock_inode(dir);
344345
err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
345346
&outarg, &inode);
347+
fuse_unlock_inode(dir);
346348
if (err == -ENOENT) {
347349
outarg_valid = false;
348350
err = 0;
@@ -1341,7 +1343,9 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx)
13411343
fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
13421344
FUSE_READDIR);
13431345
}
1346+
fuse_lock_inode(inode);
13441347
fuse_request_send(fc, req);
1348+
fuse_unlock_inode(inode);
13451349
nbytes = req->out.args[0].size;
13461350
err = req->out.h.error;
13471351
fuse_put_request(fc, req);

fs/fuse/fuse_i.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ struct fuse_inode {
110110

111111
/** Miscellaneous bits describing inode state */
112112
unsigned long state;
113+
114+
/** Lock for serializing lookup and readdir for back compatibility*/
115+
struct mutex mutex;
113116
};
114117

115118
/** FUSE inode state bits */
@@ -540,6 +543,9 @@ struct fuse_conn {
540543
/** write-back cache policy (default is write-through) */
541544
unsigned writeback_cache:1;
542545

546+
/** allow parallel lookups and readdir (default is serialized) */
547+
unsigned parallel_dirops:1;
548+
543549
/*
544550
* The following bitfields are only for optimization purposes
545551
* and hence races in setting them will not cause malfunction
@@ -956,4 +962,7 @@ int fuse_do_setattr(struct inode *inode, struct iattr *attr,
956962

957963
void fuse_set_initialized(struct fuse_conn *fc);
958964

965+
void fuse_unlock_inode(struct inode *inode);
966+
void fuse_lock_inode(struct inode *inode);
967+
959968
#endif /* _FS_FUSE_I_H */

fs/fuse/inode.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)
9797
INIT_LIST_HEAD(&fi->queued_writes);
9898
INIT_LIST_HEAD(&fi->writepages);
9999
init_waitqueue_head(&fi->page_waitq);
100+
mutex_init(&fi->mutex);
100101
fi->forget = fuse_alloc_forget();
101102
if (!fi->forget) {
102103
kmem_cache_free(fuse_inode_cachep, inode);
@@ -117,6 +118,7 @@ static void fuse_destroy_inode(struct inode *inode)
117118
struct fuse_inode *fi = get_fuse_inode(inode);
118119
BUG_ON(!list_empty(&fi->write_files));
119120
BUG_ON(!list_empty(&fi->queued_writes));
121+
mutex_destroy(&fi->mutex);
120122
kfree(fi->forget);
121123
call_rcu(&inode->i_rcu, fuse_i_callback);
122124
}
@@ -351,6 +353,18 @@ int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
351353
return 0;
352354
}
353355

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+
354368
static void fuse_umount_begin(struct super_block *sb)
355369
{
356370
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)
898912
fc->async_dio = 1;
899913
if (arg->flags & FUSE_WRITEBACK_CACHE)
900914
fc->writeback_cache = 1;
915+
if (arg->flags & FUSE_PARALLEL_DIROPS)
916+
fc->parallel_dirops = 1;
901917
if (arg->time_gran && arg->time_gran <= 1000000000)
902918
fc->sb->s_time_gran = arg->time_gran;
903919
} else {
@@ -928,7 +944,8 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
928944
FUSE_SPLICE_WRITE | FUSE_SPLICE_MOVE | FUSE_SPLICE_READ |
929945
FUSE_FLOCK_LOCKS | FUSE_IOCTL_DIR | FUSE_AUTO_INVAL_DATA |
930946
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;
932949
req->in.h.opcode = FUSE_INIT;
933950
req->in.numargs = 1;
934951
req->in.args[0].size = sizeof(*arg);

include/uapi/linux/fuse.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@
105105
*
106106
* 7.24
107107
* - add FUSE_LSEEK for SEEK_HOLE and SEEK_DATA support
108+
*
109+
* 7.25
110+
* - add FUSE_PARALLEL_DIROPS
108111
*/
109112

110113
#ifndef _LINUX_FUSE_H
@@ -140,7 +143,7 @@
140143
#define FUSE_KERNEL_VERSION 7
141144

142145
/** Minor version number of this interface */
143-
#define FUSE_KERNEL_MINOR_VERSION 24
146+
#define FUSE_KERNEL_MINOR_VERSION 25
144147

145148
/** The node ID of the root inode */
146149
#define FUSE_ROOT_ID 1
@@ -234,6 +237,7 @@ struct fuse_file_lock {
234237
* FUSE_ASYNC_DIO: asynchronous direct I/O submission
235238
* FUSE_WRITEBACK_CACHE: use writeback cache for buffered writes
236239
* FUSE_NO_OPEN_SUPPORT: kernel supports zero-message opens
240+
* FUSE_PARALLEL_DIROPS: allow parallel lookups and readdir
237241
*/
238242
#define FUSE_ASYNC_READ (1 << 0)
239243
#define FUSE_POSIX_LOCKS (1 << 1)
@@ -253,6 +257,7 @@ struct fuse_file_lock {
253257
#define FUSE_ASYNC_DIO (1 << 15)
254258
#define FUSE_WRITEBACK_CACHE (1 << 16)
255259
#define FUSE_NO_OPEN_SUPPORT (1 << 17)
260+
#define FUSE_PARALLEL_DIROPS (1 << 18)
256261

257262
/**
258263
* CUSE INIT request/reply flags

0 commit comments

Comments
 (0)