fuse update for 4.19

This contains various bug fixes and cleanups.
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYIAB0WIQSQHSd0lITzzeNWNm3h3BK/laaZPAUCW3xvGwAKCRDh3BK/laaZ
 PKECAP9qUpdtQ5RaIL/y9OGZzJLSZbBZuK3LGNY2u2B3EfrSjgEAvhkhXyOQgvVi
 kgYLNszbg/C+w8U4Xc5GWB6cjNm6rwE=
 =GJI7
 -----END PGP SIGNATURE-----

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

Pull fuse update from Miklos Szeredi:
 "Various bug fixes and cleanups"

* tag 'fuse-update-4.19' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse:
  fuse: reduce allocation size for splice_write
  fuse: use kvmalloc to allocate array of pipe_buffer structs.
  fuse: convert last timespec use to timespec64
  fs: fuse: Adding new return type vm_fault_t
  fuse: simplify fuse_abort_conn()
  fuse: Add missed unlock_page() to fuse_readpages_fill()
  fuse: Don't access pipe->buffers without pipe_lock()
  fuse: fix initial parallel dirops
  fuse: Fix oops at process_init_reply()
  fuse: umount should wait for all requests
  fuse: fix unlocked access to processing queue
  fuse: fix double request_end()
This commit is contained in:
Linus Torvalds 2018-08-21 18:47:36 -07:00
commit ad1d697358
5 changed files with 81 additions and 53 deletions

View File

@ -127,6 +127,16 @@ static bool fuse_block_alloc(struct fuse_conn *fc, bool for_background)
return !fc->initialized || (for_background && fc->blocked); return !fc->initialized || (for_background && fc->blocked);
} }
static void fuse_drop_waiting(struct fuse_conn *fc)
{
if (fc->connected) {
atomic_dec(&fc->num_waiting);
} else if (atomic_dec_and_test(&fc->num_waiting)) {
/* wake up aborters */
wake_up_all(&fc->blocked_waitq);
}
}
static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages, static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
bool for_background) bool for_background)
{ {
@ -175,7 +185,7 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
return req; return req;
out: out:
atomic_dec(&fc->num_waiting); fuse_drop_waiting(fc);
return ERR_PTR(err); return ERR_PTR(err);
} }
@ -285,7 +295,7 @@ void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
if (test_bit(FR_WAITING, &req->flags)) { if (test_bit(FR_WAITING, &req->flags)) {
__clear_bit(FR_WAITING, &req->flags); __clear_bit(FR_WAITING, &req->flags);
atomic_dec(&fc->num_waiting); fuse_drop_waiting(fc);
} }
if (req->stolen_file) if (req->stolen_file)
@ -371,7 +381,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
struct fuse_iqueue *fiq = &fc->iq; struct fuse_iqueue *fiq = &fc->iq;
if (test_and_set_bit(FR_FINISHED, &req->flags)) if (test_and_set_bit(FR_FINISHED, &req->flags))
return; goto put_request;
spin_lock(&fiq->waitq.lock); spin_lock(&fiq->waitq.lock);
list_del_init(&req->intr_entry); list_del_init(&req->intr_entry);
@ -400,6 +410,7 @@ static void request_end(struct fuse_conn *fc, struct fuse_req *req)
wake_up(&req->waitq); wake_up(&req->waitq);
if (req->end) if (req->end)
req->end(fc, req); req->end(fc, req);
put_request:
fuse_put_request(fc, req); fuse_put_request(fc, req);
} }
@ -1362,8 +1373,8 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
if (!fud) if (!fud)
return -EPERM; return -EPERM;
bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer), bufs = kvmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
GFP_KERNEL); GFP_KERNEL);
if (!bufs) if (!bufs)
return -ENOMEM; return -ENOMEM;
@ -1396,7 +1407,7 @@ out:
for (; page_nr < cs.nr_segs; page_nr++) for (; page_nr < cs.nr_segs; page_nr++)
put_page(bufs[page_nr].page); put_page(bufs[page_nr].page);
kfree(bufs); kvfree(bufs);
return ret; return ret;
} }
@ -1944,12 +1955,15 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
if (!fud) if (!fud)
return -EPERM; return -EPERM;
bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer),
GFP_KERNEL);
if (!bufs)
return -ENOMEM;
pipe_lock(pipe); pipe_lock(pipe);
bufs = kvmalloc_array(pipe->nrbufs, sizeof(struct pipe_buffer),
GFP_KERNEL);
if (!bufs) {
pipe_unlock(pipe);
return -ENOMEM;
}
nbuf = 0; nbuf = 0;
rem = 0; rem = 0;
for (idx = 0; idx < pipe->nrbufs && rem < len; idx++) for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)
@ -2003,7 +2017,7 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe,
pipe_buf_release(pipe, &bufs[idx]); pipe_buf_release(pipe, &bufs[idx]);
out: out:
kfree(bufs); kvfree(bufs);
return ret; return ret;
} }
@ -2087,8 +2101,7 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
if (fc->connected) { if (fc->connected) {
struct fuse_dev *fud; struct fuse_dev *fud;
struct fuse_req *req, *next; struct fuse_req *req, *next;
LIST_HEAD(to_end1); LIST_HEAD(to_end);
LIST_HEAD(to_end2);
fc->connected = 0; fc->connected = 0;
fc->blocked = 0; fc->blocked = 0;
@ -2105,11 +2118,12 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
set_bit(FR_ABORTED, &req->flags); set_bit(FR_ABORTED, &req->flags);
if (!test_bit(FR_LOCKED, &req->flags)) { if (!test_bit(FR_LOCKED, &req->flags)) {
set_bit(FR_PRIVATE, &req->flags); set_bit(FR_PRIVATE, &req->flags);
list_move(&req->list, &to_end1); __fuse_get_request(req);
list_move(&req->list, &to_end);
} }
spin_unlock(&req->waitq.lock); spin_unlock(&req->waitq.lock);
} }
list_splice_init(&fpq->processing, &to_end2); list_splice_tail_init(&fpq->processing, &to_end);
spin_unlock(&fpq->lock); spin_unlock(&fpq->lock);
} }
fc->max_background = UINT_MAX; fc->max_background = UINT_MAX;
@ -2117,9 +2131,9 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
spin_lock(&fiq->waitq.lock); spin_lock(&fiq->waitq.lock);
fiq->connected = 0; fiq->connected = 0;
list_splice_init(&fiq->pending, &to_end2); list_for_each_entry(req, &fiq->pending, list)
list_for_each_entry(req, &to_end2, list)
clear_bit(FR_PENDING, &req->flags); clear_bit(FR_PENDING, &req->flags);
list_splice_tail_init(&fiq->pending, &to_end);
while (forget_pending(fiq)) while (forget_pending(fiq))
kfree(dequeue_forget(fiq, 1, NULL)); kfree(dequeue_forget(fiq, 1, NULL));
wake_up_all_locked(&fiq->waitq); wake_up_all_locked(&fiq->waitq);
@ -2129,19 +2143,18 @@ void fuse_abort_conn(struct fuse_conn *fc, bool is_abort)
wake_up_all(&fc->blocked_waitq); wake_up_all(&fc->blocked_waitq);
spin_unlock(&fc->lock); spin_unlock(&fc->lock);
while (!list_empty(&to_end1)) { end_requests(fc, &to_end);
req = list_first_entry(&to_end1, struct fuse_req, list);
__fuse_get_request(req);
list_del_init(&req->list);
request_end(fc, req);
}
end_requests(fc, &to_end2);
} else { } else {
spin_unlock(&fc->lock); spin_unlock(&fc->lock);
} }
} }
EXPORT_SYMBOL_GPL(fuse_abort_conn); EXPORT_SYMBOL_GPL(fuse_abort_conn);
void fuse_wait_aborted(struct fuse_conn *fc)
{
wait_event(fc->blocked_waitq, atomic_read(&fc->num_waiting) == 0);
}
int fuse_dev_release(struct inode *inode, struct file *file) int fuse_dev_release(struct inode *inode, struct file *file)
{ {
struct fuse_dev *fud = fuse_get_dev(file); struct fuse_dev *fud = fuse_get_dev(file);
@ -2149,9 +2162,15 @@ int fuse_dev_release(struct inode *inode, struct file *file)
if (fud) { if (fud) {
struct fuse_conn *fc = fud->fc; struct fuse_conn *fc = fud->fc;
struct fuse_pqueue *fpq = &fud->pq; struct fuse_pqueue *fpq = &fud->pq;
LIST_HEAD(to_end);
spin_lock(&fpq->lock);
WARN_ON(!list_empty(&fpq->io)); WARN_ON(!list_empty(&fpq->io));
end_requests(fc, &fpq->processing); list_splice_init(&fpq->processing, &to_end);
spin_unlock(&fpq->lock);
end_requests(fc, &to_end);
/* 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);

View File

@ -355,11 +355,12 @@ static struct dentry *fuse_lookup(struct inode *dir, struct dentry *entry,
struct inode *inode; struct inode *inode;
struct dentry *newent; struct dentry *newent;
bool outarg_valid = true; bool outarg_valid = true;
bool locked;
fuse_lock_inode(dir); locked = fuse_lock_inode(dir);
err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name, err = fuse_lookup_name(dir->i_sb, get_node_id(dir), &entry->d_name,
&outarg, &inode); &outarg, &inode);
fuse_unlock_inode(dir); fuse_unlock_inode(dir, locked);
if (err == -ENOENT) { if (err == -ENOENT) {
outarg_valid = false; outarg_valid = false;
err = 0; err = 0;
@ -1347,6 +1348,7 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx)
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_req *req; struct fuse_req *req;
u64 attr_version = 0; u64 attr_version = 0;
bool locked;
if (is_bad_inode(inode)) if (is_bad_inode(inode))
return -EIO; return -EIO;
@ -1374,9 +1376,9 @@ static int fuse_readdir(struct file *file, struct dir_context *ctx)
fuse_read_fill(req, file, ctx->pos, PAGE_SIZE, fuse_read_fill(req, file, ctx->pos, PAGE_SIZE,
FUSE_READDIR); FUSE_READDIR);
} }
fuse_lock_inode(inode); locked = fuse_lock_inode(inode);
fuse_request_send(fc, req); fuse_request_send(fc, req);
fuse_unlock_inode(inode); fuse_unlock_inode(inode, locked);
nbytes = req->out.args[0].size; nbytes = req->out.args[0].size;
err = req->out.h.error; err = req->out.h.error;
fuse_put_request(fc, req); fuse_put_request(fc, req);

View File

@ -867,6 +867,7 @@ static int fuse_readpages_fill(void *_data, struct page *page)
} }
if (WARN_ON(req->num_pages >= req->max_pages)) { if (WARN_ON(req->num_pages >= req->max_pages)) {
unlock_page(page);
fuse_put_request(fc, req); fuse_put_request(fc, req);
return -EIO; return -EIO;
} }
@ -2049,7 +2050,7 @@ static void fuse_vma_close(struct vm_area_struct *vma)
* - sync(2) * - sync(2)
* - try_to_free_pages() with order > PAGE_ALLOC_COSTLY_ORDER * - try_to_free_pages() with order > PAGE_ALLOC_COSTLY_ORDER
*/ */
static int fuse_page_mkwrite(struct vm_fault *vmf) static vm_fault_t fuse_page_mkwrite(struct vm_fault *vmf)
{ {
struct page *page = vmf->page; struct page *page = vmf->page;
struct inode *inode = file_inode(vmf->vma->vm_file); struct inode *inode = file_inode(vmf->vma->vm_file);

View File

@ -862,6 +862,7 @@ void fuse_request_send_background_locked(struct fuse_conn *fc,
/* 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, bool is_abort);
void fuse_wait_aborted(struct fuse_conn *fc);
/** /**
* Invalidate inode attributes * Invalidate inode attributes
@ -974,8 +975,8 @@ int fuse_do_setattr(struct dentry *dentry, struct iattr *attr,
void fuse_set_initialized(struct fuse_conn *fc); void fuse_set_initialized(struct fuse_conn *fc);
void fuse_unlock_inode(struct inode *inode); void fuse_unlock_inode(struct inode *inode, bool locked);
void fuse_lock_inode(struct inode *inode); bool fuse_lock_inode(struct inode *inode);
int fuse_setxattr(struct inode *inode, const char *name, const void *value, int fuse_setxattr(struct inode *inode, const char *name, const void *value,
size_t size, int flags); size_t size, int flags);

View File

@ -208,7 +208,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
bool is_wb = fc->writeback_cache; bool is_wb = fc->writeback_cache;
loff_t oldsize; loff_t oldsize;
struct timespec old_mtime; struct timespec64 old_mtime;
spin_lock(&fc->lock); spin_lock(&fc->lock);
if ((attr_version != 0 && fi->attr_version > attr_version) || if ((attr_version != 0 && fi->attr_version > attr_version) ||
@ -217,7 +217,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
return; return;
} }
old_mtime = timespec64_to_timespec(inode->i_mtime); old_mtime = inode->i_mtime;
fuse_change_attributes_common(inode, attr, attr_valid); fuse_change_attributes_common(inode, attr, attr_valid);
oldsize = inode->i_size; oldsize = inode->i_size;
@ -237,7 +237,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
truncate_pagecache(inode, attr->size); truncate_pagecache(inode, attr->size);
inval = true; inval = true;
} else if (fc->auto_inval_data) { } else if (fc->auto_inval_data) {
struct timespec new_mtime = { struct timespec64 new_mtime = {
.tv_sec = attr->mtime, .tv_sec = attr->mtime,
.tv_nsec = attr->mtimensec, .tv_nsec = attr->mtimensec,
}; };
@ -246,7 +246,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr,
* Auto inval mode also checks and invalidates if mtime * Auto inval mode also checks and invalidates if mtime
* has changed. * has changed.
*/ */
if (!timespec_equal(&old_mtime, &new_mtime)) if (!timespec64_equal(&old_mtime, &new_mtime))
inval = true; inval = true;
} }
@ -357,15 +357,21 @@ int fuse_reverse_inval_inode(struct super_block *sb, u64 nodeid,
return 0; return 0;
} }
void fuse_lock_inode(struct inode *inode) bool fuse_lock_inode(struct inode *inode)
{ {
if (!get_fuse_conn(inode)->parallel_dirops) bool locked = false;
if (!get_fuse_conn(inode)->parallel_dirops) {
mutex_lock(&get_fuse_inode(inode)->mutex); mutex_lock(&get_fuse_inode(inode)->mutex);
locked = true;
}
return locked;
} }
void fuse_unlock_inode(struct inode *inode) void fuse_unlock_inode(struct inode *inode, bool locked)
{ {
if (!get_fuse_conn(inode)->parallel_dirops) if (locked)
mutex_unlock(&get_fuse_inode(inode)->mutex); mutex_unlock(&get_fuse_inode(inode)->mutex);
} }
@ -391,9 +397,6 @@ static void fuse_put_super(struct super_block *sb)
{ {
struct fuse_conn *fc = get_fuse_conn_super(sb); struct fuse_conn *fc = get_fuse_conn_super(sb);
fuse_send_destroy(fc);
fuse_abort_conn(fc, false);
mutex_lock(&fuse_mutex); mutex_lock(&fuse_mutex);
list_del(&fc->entry); list_del(&fc->entry);
fuse_ctl_remove_conn(fc); fuse_ctl_remove_conn(fc);
@ -1210,16 +1213,25 @@ static struct dentry *fuse_mount(struct file_system_type *fs_type,
return mount_nodev(fs_type, flags, raw_data, fuse_fill_super); return mount_nodev(fs_type, flags, raw_data, fuse_fill_super);
} }
static void fuse_kill_sb_anon(struct super_block *sb) static void fuse_sb_destroy(struct super_block *sb)
{ {
struct fuse_conn *fc = get_fuse_conn_super(sb); struct fuse_conn *fc = get_fuse_conn_super(sb);
if (fc) { if (fc) {
fuse_send_destroy(fc);
fuse_abort_conn(fc, false);
fuse_wait_aborted(fc);
down_write(&fc->killsb); down_write(&fc->killsb);
fc->sb = NULL; fc->sb = NULL;
up_write(&fc->killsb); up_write(&fc->killsb);
} }
}
static void fuse_kill_sb_anon(struct super_block *sb)
{
fuse_sb_destroy(sb);
kill_anon_super(sb); kill_anon_super(sb);
} }
@ -1242,14 +1254,7 @@ static struct dentry *fuse_mount_blk(struct file_system_type *fs_type,
static void fuse_kill_sb_blk(struct super_block *sb) static void fuse_kill_sb_blk(struct super_block *sb)
{ {
struct fuse_conn *fc = get_fuse_conn_super(sb); fuse_sb_destroy(sb);
if (fc) {
down_write(&fc->killsb);
fc->sb = NULL;
up_write(&fc->killsb);
}
kill_block_super(sb); kill_block_super(sb);
} }