Skip to content

Commit 6ff958e

Browse files
Miklos SzerediLinus Torvalds
authored andcommitted
fuse: add atomic open+truncate support
This patch allows fuse filesystems to implement open(..., O_TRUNC) as a single request, instead of separate truncate and open requests. Signed-off-by: Miklos Szeredi <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 17637cb commit 6ff958e

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

fs/fuse/dir.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,9 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
10831083
return err;
10841084
}
10851085

1086+
if ((attr->ia_valid & ATTR_OPEN) && fc->atomic_o_trunc)
1087+
return 0;
1088+
10861089
if (attr->ia_valid & ATTR_SIZE) {
10871090
unsigned long limit;
10881091
if (IS_SWAPFILE(inode))

fs/fuse/file.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ static int fuse_send_open(struct inode *inode, struct file *file, int isdir,
2828
return PTR_ERR(req);
2929

3030
memset(&inarg, 0, sizeof(inarg));
31-
inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC);
31+
inarg.flags = file->f_flags & ~(O_CREAT | O_EXCL | O_NOCTTY);
32+
if (!fc->atomic_o_trunc)
33+
inarg.flags &= ~O_TRUNC;
3234
req->in.h.opcode = isdir ? FUSE_OPENDIR : FUSE_OPEN;
3335
req->in.h.nodeid = get_node_id(inode);
3436
req->in.numargs = 1;

fs/fuse/fuse_i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ struct fuse_conn {
320320
/** Do readpages asynchronously? Only set in INIT */
321321
unsigned async_read : 1;
322322

323+
/** Do not send separate SETATTR request before open(O_TRUNC) */
324+
unsigned atomic_o_trunc : 1;
325+
323326
/*
324327
* The following bitfields are only for optimization purposes
325328
* and hence races in setting them will not cause malfunction

fs/fuse/inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ static void process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
531531
fc->async_read = 1;
532532
if (!(arg->flags & FUSE_POSIX_LOCKS))
533533
fc->no_lock = 1;
534+
if (arg->flags & FUSE_ATOMIC_O_TRUNC)
535+
fc->atomic_o_trunc = 1;
534536
} else {
535537
ra_pages = fc->max_read / PAGE_CACHE_SIZE;
536538
fc->no_lock = 1;
@@ -553,7 +555,8 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
553555
arg->major = FUSE_KERNEL_VERSION;
554556
arg->minor = FUSE_KERNEL_MINOR_VERSION;
555557
arg->max_readahead = fc->bdi.ra_pages * PAGE_CACHE_SIZE;
556-
arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_FILE_OPS;
558+
arg->flags |= FUSE_ASYNC_READ | FUSE_POSIX_LOCKS | FUSE_FILE_OPS |
559+
FUSE_ATOMIC_O_TRUNC;
557560
req->in.h.opcode = FUSE_INIT;
558561
req->in.numargs = 1;
559562
req->in.args[0].size = sizeof(*arg);

include/linux/fuse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct fuse_file_lock {
101101
#define FUSE_ASYNC_READ (1 << 0)
102102
#define FUSE_POSIX_LOCKS (1 << 1)
103103
#define FUSE_FILE_OPS (1 << 2)
104+
#define FUSE_ATOMIC_O_TRUNC (1 << 3)
104105

105106
/**
106107
* Release flags

0 commit comments

Comments
 (0)