Skip to content

Commit

Permalink
fuse: simplify request allocation
Browse files Browse the repository at this point in the history
Page arrays are not allocated together with the request anymore.  Get rid
of the dead code

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
  • Loading branch information
Miklos Szeredi committed Sep 10, 2019
1 parent 66abc35 commit 7213394
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 59 deletions.
61 changes: 11 additions & 50 deletions fs/fuse/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,59 +40,26 @@ static struct fuse_dev *fuse_get_dev(struct file *file)
return READ_ONCE(file->private_data);
}

static void fuse_request_init(struct fuse_req *req, struct page **pages,
struct fuse_page_desc *page_descs,
unsigned npages)
static void fuse_request_init(struct fuse_req *req)
{
INIT_LIST_HEAD(&req->list);
INIT_LIST_HEAD(&req->intr_entry);
init_waitqueue_head(&req->waitq);
refcount_set(&req->count, 1);
req->pages = pages;
req->page_descs = page_descs;
req->max_pages = npages;
__set_bit(FR_PENDING, &req->flags);
}

static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
static struct fuse_req *fuse_request_alloc(gfp_t flags)
{
struct fuse_req *req = kmem_cache_zalloc(fuse_req_cachep, flags);
if (req) {
struct page **pages = NULL;
struct fuse_page_desc *page_descs = NULL;

WARN_ON(npages > FUSE_MAX_MAX_PAGES);
if (npages > FUSE_REQ_INLINE_PAGES) {
pages = fuse_pages_alloc(npages, flags, &page_descs);
if (!pages) {
kmem_cache_free(fuse_req_cachep, req);
return NULL;
}
__set_bit(FR_ALLOC_PAGES, &req->flags);
} else if (npages) {
pages = req->inline_pages;
page_descs = req->inline_page_descs;
}
if (req)
fuse_request_init(req);

fuse_request_init(req, pages, page_descs, npages);
}
return req;
}

static struct fuse_req *fuse_request_alloc(unsigned int npages)
{
return __fuse_request_alloc(npages, GFP_KERNEL);
}

static void fuse_req_pages_free(struct fuse_req *req)
{
if (test_bit(FR_ALLOC_PAGES, &req->flags))
kfree(req->pages);
}

static void fuse_request_free(struct fuse_req *req)
{
fuse_req_pages_free(req);
kmem_cache_free(fuse_req_cachep, req);
}

Expand Down Expand Up @@ -135,8 +102,7 @@ static void fuse_drop_waiting(struct fuse_conn *fc)

static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req);

static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
bool for_background)
static struct fuse_req *fuse_get_req(struct fuse_conn *fc, bool for_background)
{
struct fuse_req *req;
int err;
Expand All @@ -159,7 +125,7 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
if (fc->conn_error)
goto out;

req = fuse_request_alloc(npages);
req = fuse_request_alloc(GFP_KERNEL);
err = -ENOMEM;
if (!req) {
if (for_background)
Expand Down Expand Up @@ -187,11 +153,6 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
return ERR_PTR(err);
}

static struct fuse_req *fuse_get_req(struct fuse_conn *fc, unsigned int npages)
{
return __fuse_get_req(fc, npages, false);
}

static void fuse_put_request(struct fuse_conn *fc, struct fuse_req *req)
{
if (refcount_dec_and_test(&req->count)) {
Expand Down Expand Up @@ -517,7 +478,7 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)

if (args->force) {
atomic_inc(&fc->num_waiting);
req = __fuse_request_alloc(0, GFP_KERNEL | __GFP_NOFAIL);
req = fuse_request_alloc(GFP_KERNEL | __GFP_NOFAIL);

if (!args->nocreds)
fuse_force_creds(fc, req);
Expand All @@ -526,7 +487,7 @@ ssize_t fuse_simple_request(struct fuse_conn *fc, struct fuse_args *args)
__set_bit(FR_FORCE, &req->flags);
} else {
WARN_ON(args->nocreds);
req = fuse_get_req(fc, 0);
req = fuse_get_req(fc, false);
if (IS_ERR(req))
return PTR_ERR(req);
}
Expand Down Expand Up @@ -597,13 +558,13 @@ int fuse_simple_background(struct fuse_conn *fc, struct fuse_args *args,

if (args->force) {
WARN_ON(!args->nocreds);
req = __fuse_request_alloc(0, gfp_flags);
req = fuse_request_alloc(gfp_flags);
if (!req)
return -ENOMEM;
__set_bit(FR_BACKGROUND, &req->flags);
} else {
WARN_ON(args->nocreds);
req = __fuse_get_req(fc, 0, true);
req = fuse_get_req(fc, true);
if (IS_ERR(req))
return PTR_ERR(req);
}
Expand All @@ -629,7 +590,7 @@ static int fuse_simple_notify_reply(struct fuse_conn *fc,
struct fuse_iqueue *fiq = &fc->iq;
int err = 0;

req = fuse_get_req(fc, 0);
req = fuse_get_req(fc, false);
if (IS_ERR(req))
return PTR_ERR(req);

Expand Down
4 changes: 2 additions & 2 deletions fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include <linux/falloc.h>
#include <linux/uio.h>

struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
struct fuse_page_desc **desc)
static struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
struct fuse_page_desc **desc)
{
struct page **pages;

Expand Down
7 changes: 0 additions & 7 deletions fs/fuse/fuse_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ enum fuse_req_flag {
FR_SENT,
FR_FINISHED,
FR_PRIVATE,
FR_ALLOC_PAGES,
};

/**
Expand Down Expand Up @@ -921,12 +920,6 @@ void fuse_dev_cleanup(void);
int fuse_ctl_init(void);
void __exit fuse_ctl_cleanup(void);

/**
* Allocate a request
*/
struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags,
struct fuse_page_desc **desc);

/**
* Simple request sending that does request allocation and freeing
*/
Expand Down

0 comments on commit 7213394

Please sign in to comment.