Commit 29a8bfe5 authored by Trond Myklebust's avatar Trond Myklebust

pNFS: Refactor nfs4_layoutget_release()

Move the actual freeing of the struct nfs4_layoutget into fs/nfs/pnfs.c
where it can be reused by the layoutget on open code.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
parent 2409a976
...@@ -8692,58 +8692,13 @@ size_t max_response_pages(struct nfs_server *server) ...@@ -8692,58 +8692,13 @@ size_t max_response_pages(struct nfs_server *server)
return nfs_page_array_len(0, max_resp_sz); return nfs_page_array_len(0, max_resp_sz);
} }
static void nfs4_free_pages(struct page **pages, size_t size)
{
int i;
if (!pages)
return;
for (i = 0; i < size; i++) {
if (!pages[i])
break;
__free_page(pages[i]);
}
kfree(pages);
}
struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags)
{
struct page **pages;
int i;
pages = kcalloc(size, sizeof(struct page *), gfp_flags);
if (!pages) {
dprintk("%s: can't alloc array of %zu pages\n", __func__, size);
return NULL;
}
for (i = 0; i < size; i++) {
pages[i] = alloc_page(gfp_flags);
if (!pages[i]) {
dprintk("%s: failed to allocate page\n", __func__);
nfs4_free_pages(pages, size);
return NULL;
}
}
return pages;
}
static void nfs4_layoutget_release(void *calldata) static void nfs4_layoutget_release(void *calldata)
{ {
struct nfs4_layoutget *lgp = calldata; struct nfs4_layoutget *lgp = calldata;
struct inode *inode = lgp->args.inode;
size_t max_pages = lgp->args.layout.pglen / PAGE_SIZE;
dprintk("--> %s\n", __func__); dprintk("--> %s\n", __func__);
nfs4_sequence_free_slot(&lgp->res.seq_res); nfs4_sequence_free_slot(&lgp->res.seq_res);
nfs4_free_pages(lgp->args.layout.pages, max_pages); pnfs_layoutget_free(lgp);
if (inode)
pnfs_put_layout_hdr(NFS_I(inode)->layout);
put_rpccred(lgp->cred);
put_nfs_open_context(lgp->args.ctx);
kfree(calldata);
dprintk("<-- %s\n", __func__); dprintk("<-- %s\n", __func__);
} }
......
...@@ -931,6 +931,44 @@ pnfs_find_server(struct inode *inode, struct nfs_open_context *ctx) ...@@ -931,6 +931,44 @@ pnfs_find_server(struct inode *inode, struct nfs_open_context *ctx)
return server; return server;
} }
static void nfs4_free_pages(struct page **pages, size_t size)
{
int i;
if (!pages)
return;
for (i = 0; i < size; i++) {
if (!pages[i])
break;
__free_page(pages[i]);
}
kfree(pages);
}
static struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags)
{
struct page **pages;
int i;
pages = kcalloc(size, sizeof(struct page *), gfp_flags);
if (!pages) {
dprintk("%s: can't alloc array of %zu pages\n", __func__, size);
return NULL;
}
for (i = 0; i < size; i++) {
pages[i] = alloc_page(gfp_flags);
if (!pages[i]) {
dprintk("%s: failed to allocate page\n", __func__);
nfs4_free_pages(pages, size);
return NULL;
}
}
return pages;
}
static struct nfs4_layoutget * static struct nfs4_layoutget *
pnfs_alloc_init_layoutget_args(struct inode *ino, pnfs_alloc_init_layoutget_args(struct inode *ino,
struct nfs_open_context *ctx, struct nfs_open_context *ctx,
...@@ -982,6 +1020,18 @@ pnfs_alloc_init_layoutget_args(struct inode *ino, ...@@ -982,6 +1020,18 @@ pnfs_alloc_init_layoutget_args(struct inode *ino,
return lgp; return lgp;
} }
void pnfs_layoutget_free(struct nfs4_layoutget *lgp)
{
size_t max_pages = lgp->args.layout.pglen / PAGE_SIZE;
nfs4_free_pages(lgp->args.layout.pages, max_pages);
if (lgp->args.inode)
pnfs_put_layout_hdr(NFS_I(lgp->args.inode)->layout);
put_rpccred(lgp->cred);
put_nfs_open_context(lgp->args.ctx);
kfree(lgp);
}
static void pnfs_clear_layoutcommit(struct inode *inode, static void pnfs_clear_layoutcommit(struct inode *inode,
struct list_head *head) struct list_head *head)
{ {
......
...@@ -227,7 +227,6 @@ extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *); ...@@ -227,7 +227,6 @@ extern void pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *);
/* nfs4proc.c */ /* nfs4proc.c */
extern size_t max_response_pages(struct nfs_server *server); extern size_t max_response_pages(struct nfs_server *server);
extern struct page **nfs4_alloc_pages(size_t size, gfp_t gfp_flags);
extern int nfs4_proc_getdeviceinfo(struct nfs_server *server, extern int nfs4_proc_getdeviceinfo(struct nfs_server *server,
struct pnfs_device *dev, struct pnfs_device *dev,
struct rpc_cred *cred); struct rpc_cred *cred);
...@@ -251,6 +250,7 @@ size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio, ...@@ -251,6 +250,7 @@ size_t pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio,
struct nfs_page *prev, struct nfs_page *req); struct nfs_page *prev, struct nfs_page *req);
void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg); void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg);
struct pnfs_layout_segment *pnfs_layout_process(struct nfs4_layoutget *lgp); struct pnfs_layout_segment *pnfs_layout_process(struct nfs4_layoutget *lgp);
void pnfs_layoutget_free(struct nfs4_layoutget *lgp);
void pnfs_free_lseg_list(struct list_head *tmp_list); void pnfs_free_lseg_list(struct list_head *tmp_list);
void pnfs_destroy_layout(struct nfs_inode *); void pnfs_destroy_layout(struct nfs_inode *);
void pnfs_destroy_all_layouts(struct nfs_client *); void pnfs_destroy_all_layouts(struct nfs_client *);
......
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