Commit 0b632204 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse

Pull fuse fixes from Miklos Szeredi:
 "This contains miscellaneous fixes"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse:
  fuse: replace count*size kzalloc by kcalloc
  fuse: release temporary page if fuse_writepage_locked() failed
  fuse: restructure ->rename2()
  fuse: avoid scheduling while atomic
  fuse: handle large user and group ID
  fuse: inode: drop cast
  fuse: ignore entry-timeout on LOOKUP_REVAL
  fuse: timeout comparison fix
parents 5615f9f8 f2b3455e
...@@ -643,9 +643,8 @@ struct fuse_copy_state { ...@@ -643,9 +643,8 @@ struct fuse_copy_state {
unsigned long seglen; unsigned long seglen;
unsigned long addr; unsigned long addr;
struct page *pg; struct page *pg;
void *mapaddr;
void *buf;
unsigned len; unsigned len;
unsigned offset;
unsigned move_pages:1; unsigned move_pages:1;
}; };
...@@ -666,23 +665,17 @@ static void fuse_copy_finish(struct fuse_copy_state *cs) ...@@ -666,23 +665,17 @@ static void fuse_copy_finish(struct fuse_copy_state *cs)
if (cs->currbuf) { if (cs->currbuf) {
struct pipe_buffer *buf = cs->currbuf; struct pipe_buffer *buf = cs->currbuf;
if (!cs->write) { if (cs->write)
kunmap_atomic(cs->mapaddr);
} else {
kunmap_atomic(cs->mapaddr);
buf->len = PAGE_SIZE - cs->len; buf->len = PAGE_SIZE - cs->len;
}
cs->currbuf = NULL; cs->currbuf = NULL;
cs->mapaddr = NULL; } else if (cs->pg) {
} else if (cs->mapaddr) {
kunmap_atomic(cs->mapaddr);
if (cs->write) { if (cs->write) {
flush_dcache_page(cs->pg); flush_dcache_page(cs->pg);
set_page_dirty_lock(cs->pg); set_page_dirty_lock(cs->pg);
} }
put_page(cs->pg); put_page(cs->pg);
cs->mapaddr = NULL;
} }
cs->pg = NULL;
} }
/* /*
...@@ -691,7 +684,7 @@ static void fuse_copy_finish(struct fuse_copy_state *cs) ...@@ -691,7 +684,7 @@ static void fuse_copy_finish(struct fuse_copy_state *cs)
*/ */
static int fuse_copy_fill(struct fuse_copy_state *cs) static int fuse_copy_fill(struct fuse_copy_state *cs)
{ {
unsigned long offset; struct page *page;
int err; int err;
unlock_request(cs->fc, cs->req); unlock_request(cs->fc, cs->req);
...@@ -706,14 +699,12 @@ static int fuse_copy_fill(struct fuse_copy_state *cs) ...@@ -706,14 +699,12 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
BUG_ON(!cs->nr_segs); BUG_ON(!cs->nr_segs);
cs->currbuf = buf; cs->currbuf = buf;
cs->mapaddr = kmap_atomic(buf->page); cs->pg = buf->page;
cs->offset = buf->offset;
cs->len = buf->len; cs->len = buf->len;
cs->buf = cs->mapaddr + buf->offset;
cs->pipebufs++; cs->pipebufs++;
cs->nr_segs--; cs->nr_segs--;
} else { } else {
struct page *page;
if (cs->nr_segs == cs->pipe->buffers) if (cs->nr_segs == cs->pipe->buffers)
return -EIO; return -EIO;
...@@ -726,8 +717,8 @@ static int fuse_copy_fill(struct fuse_copy_state *cs) ...@@ -726,8 +717,8 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
buf->len = 0; buf->len = 0;
cs->currbuf = buf; cs->currbuf = buf;
cs->mapaddr = kmap_atomic(page); cs->pg = page;
cs->buf = cs->mapaddr; cs->offset = 0;
cs->len = PAGE_SIZE; cs->len = PAGE_SIZE;
cs->pipebufs++; cs->pipebufs++;
cs->nr_segs++; cs->nr_segs++;
...@@ -740,14 +731,13 @@ static int fuse_copy_fill(struct fuse_copy_state *cs) ...@@ -740,14 +731,13 @@ static int fuse_copy_fill(struct fuse_copy_state *cs)
cs->iov++; cs->iov++;
cs->nr_segs--; cs->nr_segs--;
} }
err = get_user_pages_fast(cs->addr, 1, cs->write, &cs->pg); err = get_user_pages_fast(cs->addr, 1, cs->write, &page);
if (err < 0) if (err < 0)
return err; return err;
BUG_ON(err != 1); BUG_ON(err != 1);
offset = cs->addr % PAGE_SIZE; cs->pg = page;
cs->mapaddr = kmap_atomic(cs->pg); cs->offset = cs->addr % PAGE_SIZE;
cs->buf = cs->mapaddr + offset; cs->len = min(PAGE_SIZE - cs->offset, cs->seglen);
cs->len = min(PAGE_SIZE - offset, cs->seglen);
cs->seglen -= cs->len; cs->seglen -= cs->len;
cs->addr += cs->len; cs->addr += cs->len;
} }
...@@ -760,15 +750,20 @@ static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size) ...@@ -760,15 +750,20 @@ static int fuse_copy_do(struct fuse_copy_state *cs, void **val, unsigned *size)
{ {
unsigned ncpy = min(*size, cs->len); unsigned ncpy = min(*size, cs->len);
if (val) { if (val) {
void *pgaddr = kmap_atomic(cs->pg);
void *buf = pgaddr + cs->offset;
if (cs->write) if (cs->write)
memcpy(cs->buf, *val, ncpy); memcpy(buf, *val, ncpy);
else else
memcpy(*val, cs->buf, ncpy); memcpy(*val, buf, ncpy);
kunmap_atomic(pgaddr);
*val += ncpy; *val += ncpy;
} }
*size -= ncpy; *size -= ncpy;
cs->len -= ncpy; cs->len -= ncpy;
cs->buf += ncpy; cs->offset += ncpy;
return ncpy; return ncpy;
} }
...@@ -874,8 +869,8 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep) ...@@ -874,8 +869,8 @@ static int fuse_try_move_page(struct fuse_copy_state *cs, struct page **pagep)
out_fallback_unlock: out_fallback_unlock:
unlock_page(newpage); unlock_page(newpage);
out_fallback: out_fallback:
cs->mapaddr = kmap_atomic(buf->page); cs->pg = buf->page;
cs->buf = cs->mapaddr + buf->offset; cs->offset = buf->offset;
err = lock_request(cs->fc, cs->req); err = lock_request(cs->fc, cs->req);
if (err) if (err)
......
...@@ -198,7 +198,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags) ...@@ -198,7 +198,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
inode = ACCESS_ONCE(entry->d_inode); inode = ACCESS_ONCE(entry->d_inode);
if (inode && is_bad_inode(inode)) if (inode && is_bad_inode(inode))
goto invalid; goto invalid;
else if (fuse_dentry_time(entry) < get_jiffies_64()) { else if (time_before64(fuse_dentry_time(entry), get_jiffies_64()) ||
(flags & LOOKUP_REVAL)) {
int err; int err;
struct fuse_entry_out outarg; struct fuse_entry_out outarg;
struct fuse_req *req; struct fuse_req *req;
...@@ -814,13 +815,6 @@ static int fuse_rename_common(struct inode *olddir, struct dentry *oldent, ...@@ -814,13 +815,6 @@ static int fuse_rename_common(struct inode *olddir, struct dentry *oldent,
return err; return err;
} }
static int fuse_rename(struct inode *olddir, struct dentry *oldent,
struct inode *newdir, struct dentry *newent)
{
return fuse_rename_common(olddir, oldent, newdir, newent, 0,
FUSE_RENAME, sizeof(struct fuse_rename_in));
}
static int fuse_rename2(struct inode *olddir, struct dentry *oldent, static int fuse_rename2(struct inode *olddir, struct dentry *oldent,
struct inode *newdir, struct dentry *newent, struct inode *newdir, struct dentry *newent,
unsigned int flags) unsigned int flags)
...@@ -831,17 +825,30 @@ static int fuse_rename2(struct inode *olddir, struct dentry *oldent, ...@@ -831,17 +825,30 @@ static int fuse_rename2(struct inode *olddir, struct dentry *oldent,
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE)) if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
return -EINVAL; return -EINVAL;
if (fc->no_rename2 || fc->minor < 23) if (flags) {
return -EINVAL; if (fc->no_rename2 || fc->minor < 23)
return -EINVAL;
err = fuse_rename_common(olddir, oldent, newdir, newent, flags, err = fuse_rename_common(olddir, oldent, newdir, newent, flags,
FUSE_RENAME2, sizeof(struct fuse_rename2_in)); FUSE_RENAME2,
if (err == -ENOSYS) { sizeof(struct fuse_rename2_in));
fc->no_rename2 = 1; if (err == -ENOSYS) {
err = -EINVAL; fc->no_rename2 = 1;
err = -EINVAL;
}
} else {
err = fuse_rename_common(olddir, oldent, newdir, newent, 0,
FUSE_RENAME,
sizeof(struct fuse_rename_in));
} }
return err; return err;
}
static int fuse_rename(struct inode *olddir, struct dentry *oldent,
struct inode *newdir, struct dentry *newent)
{
return fuse_rename2(olddir, oldent, newdir, newent, 0);
} }
static int fuse_link(struct dentry *entry, struct inode *newdir, static int fuse_link(struct dentry *entry, struct inode *newdir,
...@@ -985,7 +992,7 @@ int fuse_update_attributes(struct inode *inode, struct kstat *stat, ...@@ -985,7 +992,7 @@ int fuse_update_attributes(struct inode *inode, struct kstat *stat,
int err; int err;
bool r; bool r;
if (fi->i_time < get_jiffies_64()) { if (time_before64(fi->i_time, get_jiffies_64())) {
r = true; r = true;
err = fuse_do_getattr(inode, stat, file); err = fuse_do_getattr(inode, stat, file);
} else { } else {
...@@ -1171,7 +1178,7 @@ static int fuse_permission(struct inode *inode, int mask) ...@@ -1171,7 +1178,7 @@ static int fuse_permission(struct inode *inode, int mask)
((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) { ((mask & MAY_EXEC) && S_ISREG(inode->i_mode))) {
struct fuse_inode *fi = get_fuse_inode(inode); struct fuse_inode *fi = get_fuse_inode(inode);
if (fi->i_time < get_jiffies_64()) { if (time_before64(fi->i_time, get_jiffies_64())) {
refreshed = true; refreshed = true;
err = fuse_perm_getattr(inode, mask); err = fuse_perm_getattr(inode, mask);
......
...@@ -1687,7 +1687,7 @@ static int fuse_writepage_locked(struct page *page) ...@@ -1687,7 +1687,7 @@ static int fuse_writepage_locked(struct page *page)
error = -EIO; error = -EIO;
req->ff = fuse_write_file_get(fc, fi); req->ff = fuse_write_file_get(fc, fi);
if (!req->ff) if (!req->ff)
goto err_free; goto err_nofile;
fuse_write_fill(req, req->ff, page_offset(page), 0); fuse_write_fill(req, req->ff, page_offset(page), 0);
...@@ -1715,6 +1715,8 @@ static int fuse_writepage_locked(struct page *page) ...@@ -1715,6 +1715,8 @@ static int fuse_writepage_locked(struct page *page)
return 0; return 0;
err_nofile:
__free_page(tmp_page);
err_free: err_free:
fuse_request_free(req); fuse_request_free(req);
err: err:
...@@ -1955,8 +1957,8 @@ static int fuse_writepages(struct address_space *mapping, ...@@ -1955,8 +1957,8 @@ static int fuse_writepages(struct address_space *mapping,
data.ff = NULL; data.ff = NULL;
err = -ENOMEM; err = -ENOMEM;
data.orig_pages = kzalloc(sizeof(struct page *) * data.orig_pages = kcalloc(FUSE_MAX_PAGES_PER_REQ,
FUSE_MAX_PAGES_PER_REQ, sizeof(struct page *),
GFP_NOFS); GFP_NOFS);
if (!data.orig_pages) if (!data.orig_pages)
goto out; goto out;
......
...@@ -478,6 +478,17 @@ static const match_table_t tokens = { ...@@ -478,6 +478,17 @@ static const match_table_t tokens = {
{OPT_ERR, NULL} {OPT_ERR, NULL}
}; };
static int fuse_match_uint(substring_t *s, unsigned int *res)
{
int err = -ENOMEM;
char *buf = match_strdup(s);
if (buf) {
err = kstrtouint(buf, 10, res);
kfree(buf);
}
return err;
}
static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev) static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev)
{ {
char *p; char *p;
...@@ -488,6 +499,7 @@ static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev) ...@@ -488,6 +499,7 @@ static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev)
while ((p = strsep(&opt, ",")) != NULL) { while ((p = strsep(&opt, ",")) != NULL) {
int token; int token;
int value; int value;
unsigned uv;
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
if (!*p) if (!*p)
continue; continue;
...@@ -511,18 +523,18 @@ static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev) ...@@ -511,18 +523,18 @@ static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev)
break; break;
case OPT_USER_ID: case OPT_USER_ID:
if (match_int(&args[0], &value)) if (fuse_match_uint(&args[0], &uv))
return 0; return 0;
d->user_id = make_kuid(current_user_ns(), value); d->user_id = make_kuid(current_user_ns(), uv);
if (!uid_valid(d->user_id)) if (!uid_valid(d->user_id))
return 0; return 0;
d->user_id_present = 1; d->user_id_present = 1;
break; break;
case OPT_GROUP_ID: case OPT_GROUP_ID:
if (match_int(&args[0], &value)) if (fuse_match_uint(&args[0], &uv))
return 0; return 0;
d->group_id = make_kgid(current_user_ns(), value); d->group_id = make_kgid(current_user_ns(), uv);
if (!gid_valid(d->group_id)) if (!gid_valid(d->group_id))
return 0; return 0;
d->group_id_present = 1; d->group_id_present = 1;
...@@ -1006,7 +1018,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1006,7 +1018,7 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
sb->s_flags &= ~(MS_NOSEC | MS_I_VERSION); sb->s_flags &= ~(MS_NOSEC | MS_I_VERSION);
if (!parse_fuse_opt((char *) data, &d, is_bdev)) if (!parse_fuse_opt(data, &d, is_bdev))
goto err; goto err;
if (is_bdev) { if (is_bdev) {
......
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