NFS: refactor nfs_direct_free_user_pages
Clean-up and fix a minor bug: the logic was dirtying page cache pages on both read and write operations. Signed-off-by: Chuck Lever <cel@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
committed by
Trond Myklebust
parent
51a7bc6cae
commit
9c93ab7dff
@@ -126,16 +126,21 @@ ssize_t nfs_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, loff_
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nfs_free_user_pages(struct page **pages, int npages, int do_dirty)
|
static void nfs_direct_dirty_pages(struct page **pages, int npages)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < npages; i++) {
|
for (i = 0; i < npages; i++) {
|
||||||
struct page *page = pages[i];
|
struct page *page = pages[i];
|
||||||
if (do_dirty && !PageCompound(page))
|
if (!PageCompound(page))
|
||||||
set_page_dirty_lock(page);
|
set_page_dirty_lock(page);
|
||||||
page_cache_release(page);
|
|
||||||
}
|
}
|
||||||
kfree(pages);
|
}
|
||||||
|
|
||||||
|
static void nfs_direct_release_pages(struct page **pages, int npages)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < npages; i++)
|
||||||
|
page_cache_release(pages[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int nfs_get_user_pages(int rw, unsigned long user_addr, size_t size, struct page ***pages)
|
static inline int nfs_get_user_pages(int rw, unsigned long user_addr, size_t size, struct page ***pages)
|
||||||
@@ -162,7 +167,7 @@ static inline int nfs_get_user_pages(int rw, unsigned long user_addr, size_t siz
|
|||||||
* end of a mapping; return EFAULT.
|
* end of a mapping; return EFAULT.
|
||||||
*/
|
*/
|
||||||
if (result >= 0) {
|
if (result >= 0) {
|
||||||
nfs_free_user_pages(*pages, result, 0);
|
nfs_direct_release_pages(*pages, result);
|
||||||
result = -EFAULT;
|
result = -EFAULT;
|
||||||
} else
|
} else
|
||||||
kfree(*pages);
|
kfree(*pages);
|
||||||
@@ -238,8 +243,6 @@ out:
|
|||||||
*/
|
*/
|
||||||
static void nfs_direct_complete(struct nfs_direct_req *dreq)
|
static void nfs_direct_complete(struct nfs_direct_req *dreq)
|
||||||
{
|
{
|
||||||
nfs_free_user_pages(dreq->pages, dreq->npages, 1);
|
|
||||||
|
|
||||||
if (dreq->iocb) {
|
if (dreq->iocb) {
|
||||||
long res = (long) dreq->error;
|
long res = (long) dreq->error;
|
||||||
if (!res)
|
if (!res)
|
||||||
@@ -311,9 +314,12 @@ static void nfs_direct_read_result(struct rpc_task *task, void *calldata)
|
|||||||
|
|
||||||
spin_unlock(&dreq->lock);
|
spin_unlock(&dreq->lock);
|
||||||
|
|
||||||
if (put_dreq(dreq))
|
if (put_dreq(dreq)) {
|
||||||
|
nfs_direct_dirty_pages(dreq->pages, dreq->npages);
|
||||||
|
nfs_direct_release_pages(dreq->pages, dreq->npages);
|
||||||
nfs_direct_complete(dreq);
|
nfs_direct_complete(dreq);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const struct rpc_call_ops nfs_read_direct_ops = {
|
static const struct rpc_call_ops nfs_read_direct_ops = {
|
||||||
.rpc_call_done = nfs_direct_read_result,
|
.rpc_call_done = nfs_direct_read_result,
|
||||||
@@ -422,6 +428,7 @@ static void nfs_direct_free_writedata(struct nfs_direct_req *dreq)
|
|||||||
list_del(&data->pages);
|
list_del(&data->pages);
|
||||||
nfs_writedata_release(data);
|
nfs_writedata_release(data);
|
||||||
}
|
}
|
||||||
|
nfs_direct_release_pages(dreq->pages, dreq->npages);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
|
#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
|
||||||
|
Reference in New Issue
Block a user