Skip to content

Commit a26ea93

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse
Pull fuse updates from Miklos Szeredi: "This contains two patchsets from Maxim Patlasov. The first reworks the request throttling so that only async requests are throttled. Wakeup of waiting async requests is also optimized. The second series adds support for async processing of direct IO which optimizes direct IO and enables the use of the AIO userspace interface." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: fuse: add flag to turn on async direct IO fuse: truncate file if async dio failed fuse: optimize short direct reads fuse: enable asynchronous processing direct IO fuse: make fuse_direct_io() aware about AIO fuse: add support of async IO fuse: move fuse_release_user_pages() up fuse: optimize wake_up fuse: implement exclusive wakeup for blocked_waitq fuse: skip blocking on allocations of synchronous requests fuse: add flag fc->initialized fuse: make request allocations for background processing explicit
2 parents c818c77 + 60b9df7 commit a26ea93

7 files changed

Lines changed: 362 additions & 72 deletions

File tree

‎fs/fuse/cuse.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,23 @@ static ssize_t cuse_read(struct file *file, char __user *buf, size_t count,
9292
{
9393
loff_t pos = 0;
9494
struct iovec iov = { .iov_base = buf, .iov_len = count };
95+
struct fuse_io_priv io = { .async = 0, .file = file };
9596

96-
return fuse_direct_io(file, &iov, 1, count, &pos, 0);
97+
return fuse_direct_io(&io, &iov, 1, count, &pos, 0);
9798
}
9899

99100
static ssize_t cuse_write(struct file *file, const char __user *buf,
100101
size_t count, loff_t *ppos)
101102
{
102103
loff_t pos = 0;
103104
struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = count };
105+
struct fuse_io_priv io = { .async = 0, .file = file };
104106

105107
/*
106108
* No locking or generic_write_checks(), the server is
107109
* responsible for locking and sanity checks.
108110
*/
109-
return fuse_direct_io(file, &iov, 1, count, &pos, 1);
111+
return fuse_direct_io(&io, &iov, 1, count, &pos, 1);
110112
}
111113

112114
static int cuse_open(struct inode *inode, struct file *file)
@@ -422,7 +424,7 @@ static int cuse_send_init(struct cuse_conn *cc)
422424

423425
BUILD_BUG_ON(CUSE_INIT_INFO_MAX > PAGE_SIZE);
424426

425-
req = fuse_get_req(fc, 1);
427+
req = fuse_get_req_for_background(fc, 1);
426428
if (IS_ERR(req)) {
427429
rc = PTR_ERR(req);
428430
goto err;
@@ -504,7 +506,7 @@ static int cuse_channel_open(struct inode *inode, struct file *file)
504506
cc->fc.release = cuse_fc_release;
505507

506508
cc->fc.connected = 1;
507-
cc->fc.blocked = 0;
509+
cc->fc.initialized = 1;
508510
rc = cuse_send_init(cc);
509511
if (rc) {
510512
fuse_conn_put(&cc->fc);

‎fs/fuse/dev.c‎

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static void restore_sigs(sigset_t *oldset)
111111
sigprocmask(SIG_SETMASK, oldset, NULL);
112112
}
113113

114-
static void __fuse_get_request(struct fuse_req *req)
114+
void __fuse_get_request(struct fuse_req *req)
115115
{
116116
atomic_inc(&req->count);
117117
}
@@ -130,40 +130,66 @@ static void fuse_req_init_context(struct fuse_req *req)
130130
req->in.h.pid = current->pid;
131131
}
132132

133-
struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages)
133+
static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
134+
{
135+
return !fc->initialized || (for_background && fc->blocked);
136+
}
137+
138+
static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
139+
bool for_background)
134140
{
135141
struct fuse_req *req;
136-
sigset_t oldset;
137-
int intr;
138142
int err;
139-
140143
atomic_inc(&fc->num_waiting);
141-
block_sigs(&oldset);
142-
intr = wait_event_interruptible(fc->blocked_waitq, !fc->blocked);
143-
restore_sigs(&oldset);
144-
err = -EINTR;
145-
if (intr)
146-
goto out;
144+
145+
if (fuse_block_alloc(fc, for_background)) {
146+
sigset_t oldset;
147+
int intr;
148+
149+
block_sigs(&oldset);
150+
intr = wait_event_interruptible_exclusive(fc->blocked_waitq,
151+
!fuse_block_alloc(fc, for_background));
152+
restore_sigs(&oldset);
153+
err = -EINTR;
154+
if (intr)
155+
goto out;
156+
}
147157

148158
err = -ENOTCONN;
149159
if (!fc->connected)
150160
goto out;
151161

152162
req = fuse_request_alloc(npages);
153163
err = -ENOMEM;
154-
if (!req)
164+
if (!req) {
165+
if (for_background)
166+
wake_up(&fc->blocked_waitq);
155167
goto out;
168+
}
156169

157170
fuse_req_init_context(req);
158171
req->waiting = 1;
172+
req->background = for_background;
159173
return req;
160174

161175
out:
162176
atomic_dec(&fc->num_waiting);
163177
return ERR_PTR(err);
164178
}
179+
180+
struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned npages)
181+
{
182+
return __fuse_get_req(fc, npages, false);
183+
}
165184
EXPORT_SYMBOL_GPL(fuse_get_req);
166185

186+
struct fuse_req *fuse_get_req_for_background(struct fuse_conn *fc,
187+
unsigned npages)
188+
{
189+
return __fuse_get_req(fc, npages, true);
190+
}
191+
EXPORT_SYMBOL_GPL(fuse_get_req_for_background);
192+
167193
/*
168194
* Return request in fuse_file->reserved_req. However that may
169195
* currently be in use. If that is the case, wait for it to become
@@ -225,19 +251,31 @@ struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
225251
struct fuse_req *req;
226252

227253
atomic_inc(&fc->num_waiting);
228-
wait_event(fc->blocked_waitq, !fc->blocked);
254+
wait_event(fc->blocked_waitq, fc->initialized);
229255
req = fuse_request_alloc(0);
230256
if (!req)
231257
req = get_reserved_req(fc, file);
232258

233259
fuse_req_init_context(req);
234260
req->waiting = 1;
261+
req->background = 0;
235262
return req;
236263
}
237264

238265
void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
239266
{
240267
if (atomic_dec_and_test(&req->count)) {
268+
if (unlikely(req->background)) {
269+
/*
270+
* We get here in the unlikely case that a background
271+
* request was allocated but not sent
272+
*/
273+
spin_lock(&fc->lock);
274+
if (!fc->blocked)
275+
wake_up(&fc->blocked_waitq);
276+
spin_unlock(&fc->lock);
277+
}
278+
241279
if (req->waiting)
242280
atomic_dec(&fc->num_waiting);
243281

@@ -335,10 +373,15 @@ __releases(fc->lock)
335373
list_del(&req->intr_entry);
336374
req->state = FUSE_REQ_FINISHED;
337375
if (req->background) {
338-
if (fc->num_background == fc->max_background) {
376+
req->background = 0;
377+
378+
if (fc->num_background == fc->max_background)
339379
fc->blocked = 0;
340-
wake_up_all(&fc->blocked_waitq);
341-
}
380+
381+
/* Wake up next waiter, if any */
382+
if (!fc->blocked && waitqueue_active(&fc->blocked_waitq))
383+
wake_up(&fc->blocked_waitq);
384+
342385
if (fc->num_background == fc->congestion_threshold &&
343386
fc->connected && fc->bdi_initialized) {
344387
clear_bdi_congested(&fc->bdi, BLK_RW_SYNC);
@@ -442,6 +485,7 @@ __acquires(fc->lock)
442485

443486
static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req)
444487
{
488+
BUG_ON(req->background);
445489
spin_lock(&fc->lock);
446490
if (!fc->connected)
447491
req->out.h.error = -ENOTCONN;
@@ -469,7 +513,7 @@ EXPORT_SYMBOL_GPL(fuse_request_send);
469513
static void fuse_request_send_nowait_locked(struct fuse_conn *fc,
470514
struct fuse_req *req)
471515
{
472-
req->background = 1;
516+
BUG_ON(!req->background);
473517
fc->num_background++;
474518
if (fc->num_background == fc->max_background)
475519
fc->blocked = 1;
@@ -2071,6 +2115,7 @@ void fuse_abort_conn(struct fuse_conn *fc)
20712115
if (fc->connected) {
20722116
fc->connected = 0;
20732117
fc->blocked = 0;
2118+
fc->initialized = 1;
20742119
end_io_requests(fc);
20752120
end_queued_requests(fc);
20762121
end_polls(fc);
@@ -2089,6 +2134,7 @@ int fuse_dev_release(struct inode *inode, struct file *file)
20892134
spin_lock(&fc->lock);
20902135
fc->connected = 0;
20912136
fc->blocked = 0;
2137+
fc->initialized = 1;
20922138
end_queued_requests(fc);
20932139
end_polls(fc);
20942140
wake_up_all(&fc->blocked_waitq);

‎fs/fuse/dir.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,10 +1562,9 @@ void fuse_release_nowrite(struct inode *inode)
15621562
* vmtruncate() doesn't allow for this case, so do the rlimit checking
15631563
* and the actual truncation by hand.
15641564
*/
1565-
static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
1566-
struct file *file)
1565+
int fuse_do_setattr(struct inode *inode, struct iattr *attr,
1566+
struct file *file)
15671567
{
1568-
struct inode *inode = entry->d_inode;
15691568
struct fuse_conn *fc = get_fuse_conn(inode);
15701569
struct fuse_req *req;
15711570
struct fuse_setattr_in inarg;
@@ -1574,9 +1573,6 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
15741573
loff_t oldsize;
15751574
int err;
15761575

1577-
if (!fuse_allow_current_process(fc))
1578-
return -EACCES;
1579-
15801576
if (!(fc->flags & FUSE_DEFAULT_PERMISSIONS))
15811577
attr->ia_valid |= ATTR_FORCE;
15821578

@@ -1671,10 +1667,15 @@ static int fuse_do_setattr(struct dentry *entry, struct iattr *attr,
16711667

16721668
static int fuse_setattr(struct dentry *entry, struct iattr *attr)
16731669
{
1670+
struct inode *inode = entry->d_inode;
1671+
1672+
if (!fuse_allow_current_process(get_fuse_conn(inode)))
1673+
return -EACCES;
1674+
16741675
if (attr->ia_valid & ATTR_FILE)
1675-
return fuse_do_setattr(entry, attr, attr->ia_file);
1676+
return fuse_do_setattr(inode, attr, attr->ia_file);
16761677
else
1677-
return fuse_do_setattr(entry, attr, NULL);
1678+
return fuse_do_setattr(inode, attr, NULL);
16781679
}
16791680

16801681
static int fuse_getattr(struct vfsmount *mnt, struct dentry *entry,

0 commit comments

Comments
 (0)