Commit dfee9c25 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'fuse-update-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse

Pull fuse updates from Miklos Szeredi:
 "Scalability and performance improvements, as well as minor bug fixes
  and cleanups"

* tag 'fuse-update-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse: (25 commits)
  fuse: cache readdir calls if filesystem opts out of opendir
  fuse: support clients that don't implement 'opendir'
  fuse: lift bad inode checks into callers
  fuse: multiplex cached/direct_io file operations
  fuse add copy_file_range to direct io fops
  fuse: use iov_iter based generic splice helpers
  fuse: Switch to using async direct IO for FOPEN_DIRECT_IO
  fuse: use atomic64_t for khctr
  fuse: clean up aborted
  fuse: Protect ff->reserved_req via corresponding fi->lock
  fuse: Protect fi->nlookup with fi->lock
  fuse: Introduce fi->lock to protect write related fields
  fuse: Convert fc->attr_version into atomic64_t
  fuse: Add fuse_inode argument to fuse_prepare_release()
  fuse: Verify userspace asks to requeue interrupt that we really sent
  fuse: Do some refactoring in fuse_dev_do_write()
  fuse: Wake up req->waitq of only if not background
  fuse: Optimize request_end() by not taking fiq->waitq.lock
  fuse: Kill fasync only if interrupt is queued in queue_interrupt()
  fuse: Remove stale comment in end_requests()
  ...
parents 7b47a9e7 fabf7e02
...@@ -35,7 +35,9 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf, ...@@ -35,7 +35,9 @@ static ssize_t fuse_conn_abort_write(struct file *file, const char __user *buf,
{ {
struct fuse_conn *fc = fuse_ctl_file_conn_get(file); struct fuse_conn *fc = fuse_ctl_file_conn_get(file);
if (fc) { if (fc) {
fuse_abort_conn(fc, true); if (fc->abort_err)
fc->aborted = true;
fuse_abort_conn(fc);
fuse_conn_put(fc); fuse_conn_put(fc);
} }
return count; return count;
......
...@@ -141,10 +141,11 @@ static int cuse_open(struct inode *inode, struct file *file) ...@@ -141,10 +141,11 @@ static int cuse_open(struct inode *inode, struct file *file)
static int cuse_release(struct inode *inode, struct file *file) static int cuse_release(struct inode *inode, struct file *file)
{ {
struct fuse_inode *fi = get_fuse_inode(inode);
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
struct fuse_conn *fc = ff->fc; struct fuse_conn *fc = ff->fc;
fuse_sync_release(ff, file->f_flags); fuse_sync_release(fi, ff, file->f_flags);
fuse_conn_put(fc); fuse_conn_put(fc);
return 0; return 0;
...@@ -407,7 +408,7 @@ static void cuse_process_init_reply(struct fuse_conn *fc, struct fuse_req *req) ...@@ -407,7 +408,7 @@ static void cuse_process_init_reply(struct fuse_conn *fc, struct fuse_req *req)
err_region: err_region:
unregister_chrdev_region(devt, 1); unregister_chrdev_region(devt, 1);
err: err:
fuse_abort_conn(fc, false); fuse_abort_conn(fc);
goto out; goto out;
} }
...@@ -586,7 +587,7 @@ static ssize_t cuse_class_abort_store(struct device *dev, ...@@ -586,7 +587,7 @@ static ssize_t cuse_class_abort_store(struct device *dev,
{ {
struct cuse_conn *cc = dev_get_drvdata(dev); struct cuse_conn *cc = dev_get_drvdata(dev);
fuse_abort_conn(&cc->fc, false); fuse_abort_conn(&cc->fc);
return count; return count;
} }
static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store); static DEVICE_ATTR(abort, 0200, NULL, cuse_class_abort_store);
......
...@@ -251,17 +251,18 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc, ...@@ -251,17 +251,18 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc,
struct file *file) struct file *file)
{ {
struct fuse_req *req = NULL; struct fuse_req *req = NULL;
struct fuse_inode *fi = get_fuse_inode(file_inode(file));
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
do { do {
wait_event(fc->reserved_req_waitq, ff->reserved_req); wait_event(fc->reserved_req_waitq, ff->reserved_req);
spin_lock(&fc->lock); spin_lock(&fi->lock);
if (ff->reserved_req) { if (ff->reserved_req) {
req = ff->reserved_req; req = ff->reserved_req;
ff->reserved_req = NULL; ff->reserved_req = NULL;
req->stolen_file = get_file(file); req->stolen_file = get_file(file);
} }
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
} while (!req); } while (!req);
return req; return req;
...@@ -273,16 +274,17 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc, ...@@ -273,16 +274,17 @@ static struct fuse_req *get_reserved_req(struct fuse_conn *fc,
static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req) static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req)
{ {
struct file *file = req->stolen_file; struct file *file = req->stolen_file;
struct fuse_inode *fi = get_fuse_inode(file_inode(file));
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
WARN_ON(req->max_pages); WARN_ON(req->max_pages);
spin_lock(&fc->lock); spin_lock(&fi->lock);
memset(req, 0, sizeof(*req)); memset(req, 0, sizeof(*req));
fuse_request_init(req, NULL, NULL, 0); fuse_request_init(req, NULL, NULL, 0);
BUG_ON(ff->reserved_req); BUG_ON(ff->reserved_req);
ff->reserved_req = req; ff->reserved_req = req;
wake_up_all(&fc->reserved_req_waitq); wake_up_all(&fc->reserved_req_waitq);
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
fput(file); fput(file);
} }
...@@ -431,10 +433,16 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) ...@@ -431,10 +433,16 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
if (test_and_set_bit(FR_FINISHED, &req->flags)) if (test_and_set_bit(FR_FINISHED, &req->flags))
goto put_request; goto put_request;
/*
* test_and_set_bit() implies smp_mb() between bit
* changing and below intr_entry check. Pairs with
* smp_mb() from queue_interrupt().
*/
if (!list_empty(&req->intr_entry)) {
spin_lock(&fiq->waitq.lock); spin_lock(&fiq->waitq.lock);
list_del_init(&req->intr_entry); list_del_init(&req->intr_entry);
spin_unlock(&fiq->waitq.lock); spin_unlock(&fiq->waitq.lock);
}
WARN_ON(test_bit(FR_PENDING, &req->flags)); WARN_ON(test_bit(FR_PENDING, &req->flags));
WARN_ON(test_bit(FR_SENT, &req->flags)); WARN_ON(test_bit(FR_SENT, &req->flags));
if (test_bit(FR_BACKGROUND, &req->flags)) { if (test_bit(FR_BACKGROUND, &req->flags)) {
...@@ -462,27 +470,43 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req) ...@@ -462,27 +470,43 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
fc->active_background--; fc->active_background--;
flush_bg_queue(fc); flush_bg_queue(fc);
spin_unlock(&fc->bg_lock); spin_unlock(&fc->bg_lock);
} } else {
/* Wake up waiter sleeping in request_wait_answer() */
wake_up(&req->waitq); wake_up(&req->waitq);
}
if (req->end) if (req->end)
req->end(fc, req); req->end(fc, req);
put_request: put_request:
fuse_put_request(fc, req); fuse_put_request(fc, req);
} }
static void queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req) static int queue_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req)
{ {
spin_lock(&fiq->waitq.lock); spin_lock(&fiq->waitq.lock);
if (test_bit(FR_FINISHED, &req->flags)) { /* Check for we've sent request to interrupt this req */
if (unlikely(!test_bit(FR_INTERRUPTED, &req->flags))) {
spin_unlock(&fiq->waitq.lock); spin_unlock(&fiq->waitq.lock);
return; return -EINVAL;
} }
if (list_empty(&req->intr_entry)) { if (list_empty(&req->intr_entry)) {
list_add_tail(&req->intr_entry, &fiq->interrupts); list_add_tail(&req->intr_entry, &fiq->interrupts);
/*
* Pairs with smp_mb() implied by test_and_set_bit()
* from request_end().
*/
smp_mb();
if (test_bit(FR_FINISHED, &req->flags)) {
list_del_init(&req->intr_entry);
spin_unlock(&fiq->waitq.lock);
return 0;
}
wake_up_locked(&fiq->waitq); wake_up_locked(&fiq->waitq);
kill_fasync(&fiq->fasync, SIGIO, POLL_IN);
} }
spin_unlock(&fiq->waitq.lock); spin_unlock(&fiq->waitq.lock);
kill_fasync(&fiq->fasync, SIGIO, POLL_IN); return 0;
} }
static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req) static void request_wait_answer(struct fuse_conn *fc, struct fuse_req *req)
...@@ -1306,7 +1330,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, ...@@ -1306,7 +1330,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
goto err_unlock; goto err_unlock;
if (!fiq->connected) { if (!fiq->connected) {
err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV; err = fc->aborted ? -ECONNABORTED : -ENODEV;
goto err_unlock; goto err_unlock;
} }
...@@ -1353,7 +1377,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file, ...@@ -1353,7 +1377,7 @@ static ssize_t fuse_dev_do_read(struct fuse_dev *fud, struct file *file,
spin_lock(&fpq->lock); spin_lock(&fpq->lock);
clear_bit(FR_LOCKED, &req->flags); clear_bit(FR_LOCKED, &req->flags);
if (!fpq->connected) { if (!fpq->connected) {
err = (fc->aborted && fc->abort_err) ? -ECONNABORTED : -ENODEV; err = fc->aborted ? -ECONNABORTED : -ENODEV;
goto out_end; goto out_end;
} }
if (err) { if (err) {
...@@ -1900,16 +1924,17 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, ...@@ -1900,16 +1924,17 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
struct fuse_req *req; struct fuse_req *req;
struct fuse_out_header oh; struct fuse_out_header oh;
err = -EINVAL;
if (nbytes < sizeof(struct fuse_out_header)) if (nbytes < sizeof(struct fuse_out_header))
return -EINVAL; goto out;
err = fuse_copy_one(cs, &oh, sizeof(oh)); err = fuse_copy_one(cs, &oh, sizeof(oh));
if (err) if (err)
goto err_finish; goto copy_finish;
err = -EINVAL; err = -EINVAL;
if (oh.len != nbytes) if (oh.len != nbytes)
goto err_finish; goto copy_finish;
/* /*
* Zero oh.unique indicates unsolicited notification message * Zero oh.unique indicates unsolicited notification message
...@@ -1917,41 +1942,40 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, ...@@ -1917,41 +1942,40 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
*/ */
if (!oh.unique) { if (!oh.unique) {
err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs); err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs);
return err ? err : nbytes; goto out;
} }
err = -EINVAL; err = -EINVAL;
if (oh.error <= -1000 || oh.error > 0) if (oh.error <= -1000 || oh.error > 0)
goto err_finish; goto copy_finish;
spin_lock(&fpq->lock); spin_lock(&fpq->lock);
err = -ENOENT; req = NULL;
if (!fpq->connected) if (fpq->connected)
goto err_unlock_pq;
req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT); req = request_find(fpq, oh.unique & ~FUSE_INT_REQ_BIT);
if (!req)
goto err_unlock_pq; err = -ENOENT;
if (!req) {
spin_unlock(&fpq->lock);
goto copy_finish;
}
/* Is it an interrupt reply ID? */ /* Is it an interrupt reply ID? */
if (oh.unique & FUSE_INT_REQ_BIT) { if (oh.unique & FUSE_INT_REQ_BIT) {
__fuse_get_request(req); __fuse_get_request(req);
spin_unlock(&fpq->lock); spin_unlock(&fpq->lock);
err = 0;
if (nbytes != sizeof(struct fuse_out_header))
err = -EINVAL; err = -EINVAL;
if (nbytes != sizeof(struct fuse_out_header)) { else if (oh.error == -ENOSYS)
fuse_put_request(fc, req);
goto err_finish;
}
if (oh.error == -ENOSYS)
fc->no_interrupt = 1; fc->no_interrupt = 1;
else if (oh.error == -EAGAIN) else if (oh.error == -EAGAIN)
queue_interrupt(&fc->iq, req); err = queue_interrupt(&fc->iq, req);
fuse_put_request(fc, req); fuse_put_request(fc, req);
fuse_copy_finish(cs); goto copy_finish;
return nbytes;
} }
clear_bit(FR_SENT, &req->flags); clear_bit(FR_SENT, &req->flags);
...@@ -1977,14 +2001,12 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud, ...@@ -1977,14 +2001,12 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
spin_unlock(&fpq->lock); spin_unlock(&fpq->lock);
request_end(fc, req); request_end(fc, req);
out:
return err ? err : nbytes; return err ? err : nbytes;
err_unlock_pq: copy_finish:
spin_unlock(&fpq->lock);
err_finish:
fuse_copy_finish(cs); fuse_copy_finish(cs);
return err; goto out;
} }
static ssize_t fuse_dev_write(struct kiocb *iocb, struct iov_iter *from) static ssize_t fuse_dev_write(struct kiocb *iocb, struct iov_iter *from)
...@@ -2109,11 +2131,7 @@ static __poll_t fuse_dev_poll(struct file *file, poll_table *wait) ...@@ -2109,11 +2131,7 @@ static __poll_t fuse_dev_poll(struct file *file, poll_table *wait)
return mask; return mask;
} }
/* /* Abort all requests on the given list (pending or processing) */
* Abort all requests on the given list (pending or processing)
*
* This function releases and reacquires fc->lock
*/
static void end_requests(struct fuse_conn *fc, struct list_head *head) static void end_requests(struct fuse_conn *fc, struct list_head *head)
{ {
while (!list_empty(head)) { while (!list_empty(head)) {
...@@ -2159,7 +2177,7 @@ static void end_polls(struct fuse_conn *fc) ...@@ -2159,7 +2177,7 @@ static void end_polls(struct fuse_conn *fc)
* is OK, the request will in that case be removed from the list before we touch * is OK, the request will in that case be removed from the list before we touch
* it. * it.
*/ */
void fuse_abort_conn(struct fuse_conn *fc, bool is_abort) void fuse_abort_conn(struct fuse_conn *fc)
{ {
struct fuse_iqueue *fiq = &fc->iq; struct fuse_iqueue *fiq = &fc->iq;
...@@ -2175,7 +2193,6 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort) ...@@ -2175,7 +2193,6 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
fc->connected = 0; fc->connected = 0;
spin_unlock(&fc->bg_lock); spin_unlock(&fc->bg_lock);
fc->aborted = is_abort;
fuse_set_initialized(fc); fuse_set_initialized(fc);
list_for_each_entry(fud, &fc->devices, entry) { list_for_each_entry(fud, &fc->devices, entry) {
struct fuse_pqueue *fpq = &fud->pq; struct fuse_pqueue *fpq = &fud->pq;
...@@ -2253,7 +2270,7 @@ int fuse_dev_release(struct inode *inode, struct file *file) ...@@ -2253,7 +2270,7 @@ int fuse_dev_release(struct inode *inode, struct file *file)
/* Are we the last open device? */ /* Are we the last open device? */
if (atomic_dec_and_test(&fc->dev_count)) { if (atomic_dec_and_test(&fc->dev_count)) {
WARN_ON(fc->iq.fasync != NULL); WARN_ON(fc->iq.fasync != NULL);
fuse_abort_conn(fc, false); fuse_abort_conn(fc);
} }
fuse_dev_free(fud); fuse_dev_free(fud);
} }
......
...@@ -149,21 +149,6 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args, ...@@ -149,21 +149,6 @@ static void fuse_lookup_init(struct fuse_conn *fc, struct fuse_args *args,
args->out.args[0].value = outarg; args->out.args[0].value = outarg;
} }
u64 fuse_get_attr_version(struct fuse_conn *fc)
{
u64 curr_version;
/*
* The spin lock isn't actually needed on 64bit archs, but we
* don't yet care too much about such optimizations.
*/
spin_lock(&fc->lock);
curr_version = fc->attr_version;
spin_unlock(&fc->lock);
return curr_version;
}
/* /*
* Check whether the dentry is still valid * Check whether the dentry is still valid
* *
...@@ -222,9 +207,9 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) ...@@ -222,9 +207,9 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
fuse_queue_forget(fc, forget, outarg.nodeid, 1); fuse_queue_forget(fc, forget, outarg.nodeid, 1);
goto invalid; goto invalid;
} }
spin_lock(&fc->lock); spin_lock(&fi->lock);
fi->nlookup++; fi->nlookup++;
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
} }
kfree(forget); kfree(forget);
if (ret == -ENOMEM) if (ret == -ENOMEM)
...@@ -400,6 +385,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, ...@@ -400,6 +385,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
struct fuse_create_in inarg; struct fuse_create_in inarg;
struct fuse_open_out outopen; struct fuse_open_out outopen;
struct fuse_entry_out outentry; struct fuse_entry_out outentry;
struct fuse_inode *fi;
struct fuse_file *ff; struct fuse_file *ff;
/* Userspace expects S_IFREG in create mode */ /* Userspace expects S_IFREG in create mode */
...@@ -451,7 +437,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, ...@@ -451,7 +437,7 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
&outentry.attr, entry_attr_timeout(&outentry), 0); &outentry.attr, entry_attr_timeout(&outentry), 0);
if (!inode) { if (!inode) {
flags &= ~(O_CREAT | O_EXCL | O_TRUNC); flags &= ~(O_CREAT | O_EXCL | O_TRUNC);
fuse_sync_release(ff, flags); fuse_sync_release(NULL, ff, flags);
fuse_queue_forget(fc, forget, outentry.nodeid, 1); fuse_queue_forget(fc, forget, outentry.nodeid, 1);
err = -ENOMEM; err = -ENOMEM;
goto out_err; goto out_err;
...@@ -462,7 +448,8 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry, ...@@ -462,7 +448,8 @@ static int fuse_create_open(struct inode *dir, struct dentry *entry,
fuse_dir_changed(dir); fuse_dir_changed(dir);
err = finish_open(file, entry, generic_file_open); err = finish_open(file, entry, generic_file_open);
if (err) { if (err) {
fuse_sync_release(ff, flags); fi = get_fuse_inode(inode);
fuse_sync_release(fi, ff, flags);
} else { } else {
file->private_data = ff; file->private_data = ff;
fuse_finish_open(inode, file); fuse_finish_open(inode, file);
...@@ -671,8 +658,8 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) ...@@ -671,8 +658,8 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)
struct inode *inode = d_inode(entry); struct inode *inode = d_inode(entry);
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock); spin_lock(&fi->lock);
fi->attr_version = ++fc->attr_version; fi->attr_version = atomic64_inc_return(&fc->attr_version);
/* /*
* If i_nlink == 0 then unlink doesn't make sense, yet this can * If i_nlink == 0 then unlink doesn't make sense, yet this can
* happen if userspace filesystem is careless. It would be * happen if userspace filesystem is careless. It would be
...@@ -681,7 +668,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry) ...@@ -681,7 +668,7 @@ static int fuse_unlink(struct inode *dir, struct dentry *entry)
*/ */
if (inode->i_nlink > 0) if (inode->i_nlink > 0)
drop_nlink(inode); drop_nlink(inode);
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
fuse_invalidate_attr(inode); fuse_invalidate_attr(inode);
fuse_dir_changed(dir); fuse_dir_changed(dir);
fuse_invalidate_entry_cache(entry); fuse_invalidate_entry_cache(entry);
...@@ -825,10 +812,10 @@ static int fuse_link(struct dentry *entry, struct inode *newdir, ...@@ -825,10 +812,10 @@ static int fuse_link(struct dentry *entry, struct inode *newdir,
if (!err) { if (!err) {
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock); spin_lock(&fi->lock);
fi->attr_version = ++fc->attr_version; fi->attr_version = atomic64_inc_return(&fc->attr_version);
inc_nlink(inode); inc_nlink(inode);
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
fuse_invalidate_attr(inode); fuse_invalidate_attr(inode);
fuse_update_ctime(inode); fuse_update_ctime(inode);
} else if (err == -EINTR) { } else if (err == -EINTR) {
...@@ -1356,15 +1343,14 @@ static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr, ...@@ -1356,15 +1343,14 @@ static void iattr_to_fattr(struct fuse_conn *fc, struct iattr *iattr,
*/ */
void fuse_set_nowrite(struct inode *inode) void fuse_set_nowrite(struct inode *inode)
{ {
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
BUG_ON(!inode_is_locked(inode)); BUG_ON(!inode_is_locked(inode));
spin_lock(&fc->lock); spin_lock(&fi->lock);
BUG_ON(fi->writectr < 0); BUG_ON(fi->writectr < 0);
fi->writectr += FUSE_NOWRITE; fi->writectr += FUSE_NOWRITE;
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE); wait_event(fi->page_waitq, fi->writectr == FUSE_NOWRITE);
} }
...@@ -1385,11 +1371,11 @@ static void __fuse_release_nowrite(struct inode *inode) ...@@ -1385,11 +1371,11 @@ static void __fuse_release_nowrite(struct inode *inode)
void fuse_release_nowrite(struct inode *inode) void fuse_release_nowrite(struct inode *inode)
{ {
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock); spin_lock(&fi->lock);
__fuse_release_nowrite(inode); __fuse_release_nowrite(inode);
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
} }
static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args, static void fuse_setattr_fill(struct fuse_conn *fc, struct fuse_args *args,
...@@ -1524,7 +1510,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, ...@@ -1524,7 +1510,7 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
goto error; goto error;
} }
spin_lock(&fc->lock); spin_lock(&fi->lock);
/* the kernel maintains i_mtime locally */ /* the kernel maintains i_mtime locally */
if (trust_local_cmtime) { if (trust_local_cmtime) {
if (attr->ia_valid & ATTR_MTIME) if (attr->ia_valid & ATTR_MTIME)
...@@ -1542,10 +1528,10 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr, ...@@ -1542,10 +1528,10 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
i_size_write(inode, outarg.attr.size); i_size_write(inode, outarg.attr.size);
if (is_truncate) { if (is_truncate) {
/* NOTE: this may release/reacquire fc->lock */ /* NOTE: this may release/reacquire fi->lock */
__fuse_release_nowrite(inode); __fuse_release_nowrite(inode);
} }
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
/* /*
* Only call invalidate_inode_pages2() after removing * Only call invalidate_inode_pages2() after removing
......
This diff is collapsed.
...@@ -96,7 +96,7 @@ struct fuse_inode { ...@@ -96,7 +96,7 @@ struct fuse_inode {
union { union {
/* Write related fields (regular file only) */ /* Write related fields (regular file only) */
struct { struct {
/* Files usable in writepage. Protected by fc->lock */ /* Files usable in writepage. Protected by fi->lock */
struct list_head write_files; struct list_head write_files;
/* Writepages pending on truncate or fsync */ /* Writepages pending on truncate or fsync */
...@@ -144,6 +144,9 @@ struct fuse_inode { ...@@ -144,6 +144,9 @@ struct fuse_inode {
/** Lock for serializing lookup and readdir for back compatibility*/ /** Lock for serializing lookup and readdir for back compatibility*/
struct mutex mutex; struct mutex mutex;
/** Lock to protect write related fields */
spinlock_t lock;
}; };
/** FUSE inode state bits */ /** FUSE inode state bits */
...@@ -163,7 +166,10 @@ struct fuse_file { ...@@ -163,7 +166,10 @@ struct fuse_file {
/** Fuse connection for this file */ /** Fuse connection for this file */
struct fuse_conn *fc; struct fuse_conn *fc;
/** Request reserved for flush and release */ /*
* Request reserved for flush and release.
* Modified under relative fuse_inode::lock.
*/
struct fuse_req *reserved_req; struct fuse_req *reserved_req;
/** Kernel file handle guaranteed to be unique */ /** Kernel file handle guaranteed to be unique */
...@@ -538,7 +544,7 @@ struct fuse_conn { ...@@ -538,7 +544,7 @@ struct fuse_conn {
struct fuse_iqueue iq; struct fuse_iqueue iq;
/** The next unique kernel file handle */ /** The next unique kernel file handle */
u64 khctr; atomic64_t khctr;
/** rbtree of fuse_files waiting for poll events indexed by ph */ /** rbtree of fuse_files waiting for poll events indexed by ph */
struct rb_root polled_files; struct rb_root polled_files;
...@@ -624,6 +630,9 @@ struct fuse_conn { ...@@ -624,6 +630,9 @@ struct fuse_conn {
/** Is open/release not implemented by fs? */ /** Is open/release not implemented by fs? */
unsigned no_open:1; unsigned no_open:1;
/** Is opendir/releasedir not implemented by fs? */
unsigned no_opendir:1;
/** Is fsync not implemented by fs? */ /** Is fsync not implemented by fs? */
unsigned no_fsync:1; unsigned no_fsync:1;
...@@ -730,7 +739,7 @@ struct fuse_conn { ...@@ -730,7 +739,7 @@ struct fuse_conn {
struct fuse_req *destroy_req; struct fuse_req *destroy_req;
/** Version counter for attribute changes */ /** Version counter for attribute changes */
u64 attr_version; atomic64_t attr_version;
/** Called on final put */ /** Called on final put */
void (*release)(struct fuse_conn *); void (*release)(struct fuse_conn *);
...@@ -770,6 +779,11 @@ static inline int invalid_nodeid(u64 nodeid) ...@@ -770,6 +779,11 @@ static inline int invalid_nodeid(u64 nodeid)
return !nodeid || nodeid == FUSE_ROOT_ID; return !nodeid || nodeid == FUSE_ROOT_ID;
} }
static inline u64 fuse_get_attr_version(struct fuse_conn *fc)
{
return atomic64_read(&fc->attr_version);
}
/** Device operations */ /** Device operations */
extern const struct file_operations fuse_dev_operations; extern const struct file_operations fuse_dev_operations;
...@@ -817,7 +831,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc); ...@@ -817,7 +831,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc);
void fuse_file_free(struct fuse_file *ff); void fuse_file_free(struct fuse_file *ff);
void fuse_finish_open(struct inode *inode, struct file *file); void fuse_finish_open(struct inode *inode, struct file *file);
void fuse_sync_release(struct fuse_file *ff, int flags); void fuse_sync_release(struct fuse_inode *fi, struct fuse_file *ff, int flags);
/** /**
* Send RELEASE or RELEASEDIR request * Send RELEASE or RELEASEDIR request
...@@ -936,7 +950,7 @@ void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req); ...@@ -936,7 +950,7 @@ void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req);
bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req); bool fuse_request_queue_background(struct fuse_conn *fc, struct fuse_req *req);
/* Abort all requests */ /* Abort all requests */
void fuse_abort_conn(struct fuse_conn *fc, bool is_abort); void fuse_abort_conn(struct fuse_conn *fc);
void fuse_wait_aborted(struct fuse_conn *fc); void fuse_wait_aborted(struct fuse_conn *fc);
/** /**
...@@ -1000,8 +1014,6 @@ void fuse_flush_writepages(struct inode *inode); ...@@ -1000,8 +1014,6 @@ void fuse_flush_writepages(struct inode *inode);
void fuse_set_nowrite(struct inode *inode); void fuse_set_nowrite(struct inode *inode);
void fuse_release_nowrite(struct inode *inode); void fuse_release_nowrite(struct inode *inode);
u64 fuse_get_attr_version(struct fuse_conn *fc);
/** /**
* File-system tells the kernel to invalidate cache for the given node id. * File-system tells the kernel to invalidate cache for the given node id.
*/ */
......
...@@ -97,6 +97,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb) ...@@ -97,6 +97,7 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)
fi->orig_ino = 0; fi->orig_ino = 0;
fi->state = 0; fi->state = 0;
mutex_init(&fi->mutex); mutex_init(&fi->mutex);
spin_lock_init(&fi->lock);
fi->forget = fuse_alloc_forget(); fi->forget = fuse_alloc_forget();
if (!fi->forget) { if (!fi->forget) {
kmem_cache_free(fuse_inode_cachep, inode); kmem_cache_free(fuse_inode_cachep, inode);
...@@ -163,7 +164,9 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr, ...@@ -163,7 +164,9 @@ void fuse_change_attributes_common(struct inode *inode, struct fuse_attr *attr,
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
fi->attr_version = ++fc->attr_version; lockdep_assert_held(&fi->lock);
fi->attr_version = atomic64_inc_return(&fc->attr_version);
fi->i_time = attr_valid; fi->i_time = attr_valid;
WRITE_ONCE(fi->inval_mask, 0); WRITE_ONCE(fi->inval_mask, 0);
...@@ -209,10 +212,10 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, ...@@ -209,10 +212,10 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
loff_t oldsize; loff_t oldsize;
struct timespec64 old_mtime; struct timespec64 old_mtime;
spin_lock(&fc->lock); spin_lock(&fi->lock);
if ((attr_version != 0 && fi->attr_version > attr_version) || if ((attr_version != 0 && fi->attr_version > attr_version) ||
test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) { test_bit(FUSE_I_SIZE_UNSTABLE, &fi->state)) {
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
return; return;
} }
...@@ -227,7 +230,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, ...@@ -227,7 +230,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
*/ */
if (!is_wb || !S_ISREG(inode->i_mode)) if (!is_wb || !S_ISREG(inode->i_mode))
i_size_write(inode, attr->size); i_size_write(inode, attr->size);
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
if (!is_wb && S_ISREG(inode->i_mode)) { if (!is_wb && S_ISREG(inode->i_mode)) {
bool inval = false; bool inval = false;
...@@ -322,9 +325,9 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid, ...@@ -322,9 +325,9 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
} }
fi = get_fuse_inode(inode); fi = get_fuse_inode(inode);
spin_lock(&fc->lock); spin_lock(&fi->lock);
fi->nlookup++; fi->nlookup++;
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
fuse_change_attributes(inode, attr, attr_valid, attr_version); fuse_change_attributes(inode, attr, attr_valid, attr_version);
return inode; return inode;
...@@ -376,7 +379,7 @@ void fuse_unlock_inode(struct inode *inode, bool locked) ...@@ -376,7 +379,7 @@ void fuse_unlock_inode(struct inode *inode, bool locked)
static void fuse_umount_begin(struct super_block *sb) static void fuse_umount_begin(struct super_block *sb)
{ {
fuse_abort_conn(get_fuse_conn_super(sb), false); fuse_abort_conn(get_fuse_conn_super(sb));
} }
static void fuse_send_destroy(struct fuse_conn *fc) static void fuse_send_destroy(struct fuse_conn *fc)
...@@ -619,12 +622,12 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns) ...@@ -619,12 +622,12 @@ void fuse_conn_init(struct fuse_conn *fc, struct user_namespace *user_ns)
atomic_set(&fc->num_waiting, 0); atomic_set(&fc->num_waiting, 0);
fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND; fc->max_background = FUSE_DEFAULT_MAX_BACKGROUND;
fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD; fc->congestion_threshold = FUSE_DEFAULT_CONGESTION_THRESHOLD;
fc->khctr = 0; atomic64_set(&fc->khctr, 0);
fc->polled_files = RB_ROOT; fc->polled_files = RB_ROOT;
fc->blocked = 0; fc->blocked = 0;
fc->initialized = 0; fc->initialized = 0;
fc->connected = 1; fc->connected = 1;
fc->attr_version = 1; atomic64_set(&fc->attr_version, 1);
get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key));
fc->pid_ns = get_pid_ns(task_active_pid_ns(current)); fc->pid_ns = get_pid_ns(task_active_pid_ns(current));
fc->user_ns = get_user_ns(user_ns); fc->user_ns = get_user_ns(user_ns);
...@@ -969,7 +972,8 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req) ...@@ -969,7 +972,8 @@ static void fuse_send_init(struct fuse_conn *fc, struct fuse_req *req)
FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO | FUSE_DO_READDIRPLUS | FUSE_READDIRPLUS_AUTO | FUSE_ASYNC_DIO |
FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT | FUSE_WRITEBACK_CACHE | FUSE_NO_OPEN_SUPPORT |
FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL | FUSE_PARALLEL_DIROPS | FUSE_HANDLE_KILLPRIV | FUSE_POSIX_ACL |
FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS; FUSE_ABORT_ERROR | FUSE_MAX_PAGES | FUSE_CACHE_SYMLINKS |
FUSE_NO_OPENDIR_SUPPORT;
req->in.h.opcode = FUSE_INIT; req->in.h.opcode = FUSE_INIT;
req->in.numargs = 1; req->in.numargs = 1;
req->in.args[0].size = sizeof(*arg); req->in.args[0].size = sizeof(*arg);
...@@ -1242,7 +1246,7 @@ static void fuse_sb_destroy(struct super_block *sb) ...@@ -1242,7 +1246,7 @@ static void fuse_sb_destroy(struct super_block *sb)
if (fc) { if (fc) {
fuse_send_destroy(fc); fuse_send_destroy(fc);
fuse_abort_conn(fc, false); fuse_abort_conn(fc);
fuse_wait_aborted(fc); fuse_wait_aborted(fc);
down_write(&fc->killsb); down_write(&fc->killsb);
......
...@@ -213,9 +213,9 @@ static int fuse_direntplus_link(struct file *file, ...@@ -213,9 +213,9 @@ static int fuse_direntplus_link(struct file *file,
} }
fi = get_fuse_inode(inode); fi = get_fuse_inode(inode);
spin_lock(&fc->lock); spin_lock(&fi->lock);
fi->nlookup++; fi->nlookup++;
spin_unlock(&fc->lock); spin_unlock(&fi->lock);
forget_all_cached_acls(inode); forget_all_cached_acls(inode);
fuse_change_attributes(inode, &o->attr, fuse_change_attributes(inode, &o->attr,
......
...@@ -122,6 +122,9 @@ ...@@ -122,6 +122,9 @@
* - add FOPEN_CACHE_DIR * - add FOPEN_CACHE_DIR
* - add FUSE_MAX_PAGES, add max_pages to init_out * - add FUSE_MAX_PAGES, add max_pages to init_out
* - add FUSE_CACHE_SYMLINKS * - add FUSE_CACHE_SYMLINKS
*
* 7.29
* - add FUSE_NO_OPENDIR_SUPPORT flag
*/ */
#ifndef _LINUX_FUSE_H #ifndef _LINUX_FUSE_H
...@@ -157,7 +160,7 @@ ...@@ -157,7 +160,7 @@
#define FUSE_KERNEL_VERSION 7 #define FUSE_KERNEL_VERSION 7
/** Minor version number of this interface */ /** Minor version number of this interface */
#define FUSE_KERNEL_MINOR_VERSION 28 #define FUSE_KERNEL_MINOR_VERSION 29
/** The node ID of the root inode */ /** The node ID of the root inode */
#define FUSE_ROOT_ID 1 #define FUSE_ROOT_ID 1
...@@ -259,6 +262,7 @@ struct fuse_file_lock { ...@@ -259,6 +262,7 @@ struct fuse_file_lock {
* FUSE_ABORT_ERROR: reading the device after abort returns ECONNABORTED * FUSE_ABORT_ERROR: reading the device after abort returns ECONNABORTED
* FUSE_MAX_PAGES: init_out.max_pages contains the max number of req pages * FUSE_MAX_PAGES: init_out.max_pages contains the max number of req pages
* FUSE_CACHE_SYMLINKS: cache READLINK responses * FUSE_CACHE_SYMLINKS: cache READLINK responses
* FUSE_NO_OPENDIR_SUPPORT: kernel supports zero-message opendir
*/ */
#define FUSE_ASYNC_READ (1 << 0) #define FUSE_ASYNC_READ (1 << 0)
#define FUSE_POSIX_LOCKS (1 << 1) #define FUSE_POSIX_LOCKS (1 << 1)
...@@ -284,6 +288,7 @@ struct fuse_file_lock { ...@@ -284,6 +288,7 @@ struct fuse_file_lock {
#define FUSE_ABORT_ERROR (1 << 21) #define FUSE_ABORT_ERROR (1 << 21)
#define FUSE_MAX_PAGES (1 << 22) #define FUSE_MAX_PAGES (1 << 22)
#define FUSE_CACHE_SYMLINKS (1 << 23) #define FUSE_CACHE_SYMLINKS (1 << 23)
#define FUSE_NO_OPENDIR_SUPPORT (1 << 24)
/** /**
* CUSE INIT request/reply flags * CUSE INIT request/reply flags
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment