Commit 4250c066 authored by Maxim Patlasov's avatar Maxim Patlasov Committed by Miklos Szeredi

fuse: general infrastructure for pages[] of variable size

The patch removes inline array of FUSE_MAX_PAGES_PER_REQ page pointers from
fuse_req. Instead of that, req->pages may now point either to small inline
array or to an array allocated dynamically.

This essentially means that all callers of fuse_request_alloc[_nofs] should
pass the number of pages needed explicitly.

The patch doesn't make any logic changes.
Signed-off-by: default avatarMaxim Patlasov <mpatlasov@parallels.com>
Signed-off-by: default avatarMiklos Szeredi <mszeredi@suse.cz>
parent 0b05b183
...@@ -34,34 +34,55 @@ static struct fuse_conn *fuse_get_conn(struct file *file) ...@@ -34,34 +34,55 @@ static struct fuse_conn *fuse_get_conn(struct file *file)
return file->private_data; return file->private_data;
} }
static void fuse_request_init(struct fuse_req *req) static void fuse_request_init(struct fuse_req *req, struct page **pages,
unsigned npages)
{ {
memset(req, 0, sizeof(*req)); memset(req, 0, sizeof(*req));
memset(pages, 0, sizeof(*pages) * npages);
INIT_LIST_HEAD(&req->list); INIT_LIST_HEAD(&req->list);
INIT_LIST_HEAD(&req->intr_entry); INIT_LIST_HEAD(&req->intr_entry);
init_waitqueue_head(&req->waitq); init_waitqueue_head(&req->waitq);
atomic_set(&req->count, 1); atomic_set(&req->count, 1);
req->pages = pages;
req->max_pages = npages;
} }
struct fuse_req *fuse_request_alloc(void) static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
{ {
struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, GFP_KERNEL); struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, flags);
if (req) if (req) {
fuse_request_init(req); struct page **pages;
if (npages <= FUSE_REQ_INLINE_PAGES)
pages = req->inline_pages;
else
pages = kmalloc(sizeof(struct page *) * npages, flags);
if (!pages) {
kmem_cache_free(fuse_req_cachep, req);
return NULL;
}
fuse_request_init(req, pages, npages);
}
return req; return req;
} }
struct fuse_req *fuse_request_alloc(unsigned npages)
{
return __fuse_request_alloc(npages, GFP_KERNEL);
}
EXPORT_SYMBOL_GPL(fuse_request_alloc); EXPORT_SYMBOL_GPL(fuse_request_alloc);
struct fuse_req *fuse_request_alloc_nofs(void) struct fuse_req *fuse_request_alloc_nofs(unsigned npages)
{ {
struct fuse_req *req = kmem_cache_alloc(fuse_req_cachep, GFP_NOFS); return __fuse_request_alloc(npages, GFP_NOFS);
if (req)
fuse_request_init(req);
return req;
} }
void fuse_request_free(struct fuse_req *req) void fuse_request_free(struct fuse_req *req)
{ {
if (req->pages != req->inline_pages)
kfree(req->pages);
kmem_cache_free(fuse_req_cachep, req); kmem_cache_free(fuse_req_cachep, req);
} }
...@@ -116,7 +137,7 @@ struct fuse_req *fuse_get_req(struct fuse_conn *fc) ...@@ -116,7 +137,7 @@ struct fuse_req *fuse_get_req(struct fuse_conn *fc)
if (!fc->connected) if (!fc->connected)
goto out; goto out;
req = fuse_request_alloc(); req = fuse_request_alloc(FUSE_MAX_PAGES_PER_REQ);
err = -ENOMEM; err = -ENOMEM;
if (!req) if (!req)
goto out; goto out;
...@@ -165,7 +186,7 @@ static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req) ...@@ -165,7 +186,7 @@ static void put_reserved_req(struct fuse_conn *fc, struct fuse_req *req)
struct fuse_file *ff = file->private_data; struct fuse_file *ff = file->private_data;
spin_lock(&fc->lock); spin_lock(&fc->lock);
fuse_request_init(req); fuse_request_init(req, req->pages, req->max_pages);
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);
...@@ -192,7 +213,7 @@ struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file) ...@@ -192,7 +213,7 @@ struct fuse_req *fuse_get_req_nofail(struct fuse_conn *fc, struct file *file)
atomic_inc(&fc->num_waiting); atomic_inc(&fc->num_waiting);
wait_event(fc->blocked_waitq, !fc->blocked); wait_event(fc->blocked_waitq, !fc->blocked);
req = fuse_request_alloc(); req = fuse_request_alloc(FUSE_MAX_PAGES_PER_REQ);
if (!req) if (!req)
req = get_reserved_req(fc, file); req = get_reserved_req(fc, file);
......
...@@ -57,7 +57,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc) ...@@ -57,7 +57,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
return NULL; return NULL;
ff->fc = fc; ff->fc = fc;
ff->reserved_req = fuse_request_alloc(); ff->reserved_req = fuse_request_alloc(0);
if (unlikely(!ff->reserved_req)) { if (unlikely(!ff->reserved_req)) {
kfree(ff); kfree(ff);
return NULL; return NULL;
...@@ -1272,7 +1272,7 @@ static int fuse_writepage_locked(struct page *page) ...@@ -1272,7 +1272,7 @@ static int fuse_writepage_locked(struct page *page)
set_page_writeback(page); set_page_writeback(page);
req = fuse_request_alloc_nofs(); req = fuse_request_alloc_nofs(1);
if (!req) if (!req)
goto err; goto err;
......
...@@ -44,6 +44,9 @@ ...@@ -44,6 +44,9 @@
doing the mount will be allowed to access the filesystem */ doing the mount will be allowed to access the filesystem */
#define FUSE_ALLOW_OTHER (1 << 1) #define FUSE_ALLOW_OTHER (1 << 1)
/** Number of page pointers embedded in fuse_req */
#define FUSE_REQ_INLINE_PAGES 1
/** List of active connections */ /** List of active connections */
extern struct list_head fuse_conn_list; extern struct list_head fuse_conn_list;
...@@ -291,7 +294,13 @@ struct fuse_req { ...@@ -291,7 +294,13 @@ struct fuse_req {
} misc; } misc;
/** page vector */ /** page vector */
struct page *pages[FUSE_MAX_PAGES_PER_REQ]; struct page **pages;
/** size of the 'pages' array */
unsigned max_pages;
/** inline page vector */
struct page *inline_pages[FUSE_REQ_INLINE_PAGES];
/** number of pages in vector */ /** number of pages in vector */
unsigned num_pages; unsigned num_pages;
...@@ -664,9 +673,9 @@ void fuse_ctl_cleanup(void); ...@@ -664,9 +673,9 @@ void fuse_ctl_cleanup(void);
/** /**
* Allocate a request * Allocate a request
*/ */
struct fuse_req *fuse_request_alloc(void); struct fuse_req *fuse_request_alloc(unsigned npages);
struct fuse_req *fuse_request_alloc_nofs(void); struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
/** /**
* Free a request * Free a request
......
...@@ -1037,12 +1037,12 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1037,12 +1037,12 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
/* only now - we want root dentry with NULL ->d_op */ /* only now - we want root dentry with NULL ->d_op */
sb->s_d_op = &fuse_dentry_operations; sb->s_d_op = &fuse_dentry_operations;
init_req = fuse_request_alloc(); init_req = fuse_request_alloc(0);
if (!init_req) if (!init_req)
goto err_put_root; goto err_put_root;
if (is_bdev) { if (is_bdev) {
fc->destroy_req = fuse_request_alloc(); fc->destroy_req = fuse_request_alloc(0);
if (!fc->destroy_req) if (!fc->destroy_req)
goto err_free_init_req; goto err_free_init_req;
} }
......
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