提交 ce59515c 编写于 作者: A Anna Schumaker 提交者: Trond Myklebust

NFS: Create a common rpcsetup function for reads and writes

Write adds a little bit of code dealing with flush flags, but since
"how" will always be 0 when reading we can share the code.
Signed-off-by: NAnna Schumaker <Anna.Schumaker@Netapp.com>
Signed-off-by: NTrond Myklebust <trond.myklebust@primarydata.com>
上级 6f92fa45
...@@ -242,6 +242,8 @@ struct nfs_rw_header *nfs_rw_header_alloc(const struct nfs_rw_ops *); ...@@ -242,6 +242,8 @@ struct nfs_rw_header *nfs_rw_header_alloc(const struct nfs_rw_ops *);
void nfs_rw_header_free(struct nfs_pgio_header *); void nfs_rw_header_free(struct nfs_pgio_header *);
struct nfs_pgio_data *nfs_pgio_data_alloc(struct nfs_pgio_header *, unsigned int); struct nfs_pgio_data *nfs_pgio_data_alloc(struct nfs_pgio_header *, unsigned int);
void nfs_pgio_data_release(struct nfs_pgio_data *); void nfs_pgio_data_release(struct nfs_pgio_data *);
void nfs_pgio_rpcsetup(struct nfs_pgio_data *, unsigned int, unsigned int, int,
struct nfs_commit_info *);
static inline void nfs_iocounter_init(struct nfs_io_counter *c) static inline void nfs_iocounter_init(struct nfs_io_counter *c)
{ {
...@@ -446,6 +448,7 @@ extern void nfs_init_commit(struct nfs_commit_data *data, ...@@ -446,6 +448,7 @@ extern void nfs_init_commit(struct nfs_commit_data *data,
struct nfs_commit_info *cinfo); struct nfs_commit_info *cinfo);
int nfs_scan_commit_list(struct list_head *src, struct list_head *dst, int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
struct nfs_commit_info *cinfo, int max); struct nfs_commit_info *cinfo, int max);
unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
int nfs_scan_commit(struct inode *inode, struct list_head *dst, int nfs_scan_commit(struct inode *inode, struct list_head *dst,
struct nfs_commit_info *cinfo); struct nfs_commit_info *cinfo);
void nfs_mark_request_commit(struct nfs_page *req, void nfs_mark_request_commit(struct nfs_page *req,
......
...@@ -388,6 +388,50 @@ void nfs_pgio_data_release(struct nfs_pgio_data *data) ...@@ -388,6 +388,50 @@ void nfs_pgio_data_release(struct nfs_pgio_data *data)
} }
EXPORT_SYMBOL_GPL(nfs_pgio_data_release); EXPORT_SYMBOL_GPL(nfs_pgio_data_release);
/**
* nfs_pgio_rpcsetup - Set up arguments for a pageio call
* @data: The pageio data
* @count: Number of bytes to read
* @offset: Initial offset
* @how: How to commit data (writes only)
* @cinfo: Commit information for the call (writes only)
*/
void nfs_pgio_rpcsetup(struct nfs_pgio_data *data,
unsigned int count, unsigned int offset,
int how, struct nfs_commit_info *cinfo)
{
struct nfs_page *req = data->header->req;
/* Set up the RPC argument and reply structs
* NB: take care not to mess about with data->commit et al. */
data->args.fh = NFS_FH(data->header->inode);
data->args.offset = req_offset(req) + offset;
/* pnfs_set_layoutcommit needs this */
data->mds_offset = data->args.offset;
data->args.pgbase = req->wb_pgbase + offset;
data->args.pages = data->pages.pagevec;
data->args.count = count;
data->args.context = get_nfs_open_context(req->wb_context);
data->args.lock_context = req->wb_lock_context;
data->args.stable = NFS_UNSTABLE;
switch (how & (FLUSH_STABLE | FLUSH_COND_STABLE)) {
case 0:
break;
case FLUSH_COND_STABLE:
if (nfs_reqs_to_commit(cinfo))
break;
default:
data->args.stable = NFS_FILE_SYNC;
}
data->res.fattr = &data->fattr;
data->res.count = count;
data->res.eof = 0;
data->res.verf = &data->verf;
nfs_fattr_init(&data->fattr);
}
/** /**
* nfs_pgio_prepare - Prepare pageio data to go over the wire * nfs_pgio_prepare - Prepare pageio data to go over the wire
* @task: The current task * @task: The current task
......
...@@ -192,28 +192,6 @@ int nfs_initiate_read(struct rpc_clnt *clnt, ...@@ -192,28 +192,6 @@ int nfs_initiate_read(struct rpc_clnt *clnt,
} }
EXPORT_SYMBOL_GPL(nfs_initiate_read); EXPORT_SYMBOL_GPL(nfs_initiate_read);
/*
* Set up the NFS read request struct
*/
static void nfs_read_rpcsetup(struct nfs_pgio_data *data,
unsigned int count, unsigned int offset)
{
struct nfs_page *req = data->header->req;
data->args.fh = NFS_FH(data->header->inode);
data->args.offset = req_offset(req) + offset;
data->args.pgbase = req->wb_pgbase + offset;
data->args.pages = data->pages.pagevec;
data->args.count = count;
data->args.context = get_nfs_open_context(req->wb_context);
data->args.lock_context = req->wb_lock_context;
data->res.fattr = &data->fattr;
data->res.count = count;
data->res.eof = 0;
nfs_fattr_init(&data->fattr);
}
static int nfs_do_read(struct nfs_pgio_data *data, static int nfs_do_read(struct nfs_pgio_data *data,
const struct rpc_call_ops *call_ops) const struct rpc_call_ops *call_ops)
{ {
...@@ -305,7 +283,7 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc, ...@@ -305,7 +283,7 @@ static int nfs_pagein_multi(struct nfs_pageio_descriptor *desc,
return -ENOMEM; return -ENOMEM;
} }
data->pages.pagevec[0] = page; data->pages.pagevec[0] = page;
nfs_read_rpcsetup(data, len, offset); nfs_pgio_rpcsetup(data, len, offset, 0, NULL);
list_add(&data->list, &hdr->rpc_list); list_add(&data->list, &hdr->rpc_list);
nbytes -= len; nbytes -= len;
offset += len; offset += len;
...@@ -340,7 +318,7 @@ static int nfs_pagein_one(struct nfs_pageio_descriptor *desc, ...@@ -340,7 +318,7 @@ static int nfs_pagein_one(struct nfs_pageio_descriptor *desc,
*pages++ = req->wb_page; *pages++ = req->wb_page;
} }
nfs_read_rpcsetup(data, desc->pg_count, 0); nfs_pgio_rpcsetup(data, desc->pg_count, 0, 0, NULL);
list_add(&data->list, &hdr->rpc_list); list_add(&data->list, &hdr->rpc_list);
desc->pg_rpc_callops = &nfs_pgio_common_ops; desc->pg_rpc_callops = &nfs_pgio_common_ops;
return 0; return 0;
......
...@@ -603,7 +603,7 @@ static void nfs_write_completion(struct nfs_pgio_header *hdr) ...@@ -603,7 +603,7 @@ static void nfs_write_completion(struct nfs_pgio_header *hdr)
} }
#if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4) #if IS_ENABLED(CONFIG_NFS_V3) || IS_ENABLED(CONFIG_NFS_V4)
static unsigned long unsigned long
nfs_reqs_to_commit(struct nfs_commit_info *cinfo) nfs_reqs_to_commit(struct nfs_commit_info *cinfo)
{ {
return cinfo->mds->ncommit; return cinfo->mds->ncommit;
...@@ -660,7 +660,7 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, ...@@ -660,7 +660,7 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst,
} }
#else #else
static unsigned long nfs_reqs_to_commit(struct nfs_commit_info *cinfo) unsigned long nfs_reqs_to_commit(struct nfs_commit_info *cinfo)
{ {
return 0; return 0;
} }
...@@ -987,44 +987,6 @@ int nfs_initiate_write(struct rpc_clnt *clnt, ...@@ -987,44 +987,6 @@ int nfs_initiate_write(struct rpc_clnt *clnt,
} }
EXPORT_SYMBOL_GPL(nfs_initiate_write); EXPORT_SYMBOL_GPL(nfs_initiate_write);
/*
* Set up the argument/result storage required for the RPC call.
*/
static void nfs_write_rpcsetup(struct nfs_pgio_data *data,
unsigned int count, unsigned int offset,
int how, struct nfs_commit_info *cinfo)
{
struct nfs_page *req = data->header->req;
/* Set up the RPC argument and reply structs
* NB: take care not to mess about with data->commit et al. */
data->args.fh = NFS_FH(data->header->inode);
data->args.offset = req_offset(req) + offset;
/* pnfs_set_layoutcommit needs this */
data->mds_offset = data->args.offset;
data->args.pgbase = req->wb_pgbase + offset;
data->args.pages = data->pages.pagevec;
data->args.count = count;
data->args.context = get_nfs_open_context(req->wb_context);
data->args.lock_context = req->wb_lock_context;
data->args.stable = NFS_UNSTABLE;
switch (how & (FLUSH_STABLE | FLUSH_COND_STABLE)) {
case 0:
break;
case FLUSH_COND_STABLE:
if (nfs_reqs_to_commit(cinfo))
break;
default:
data->args.stable = NFS_FILE_SYNC;
}
data->res.fattr = &data->fattr;
data->res.count = count;
data->res.verf = &data->verf;
nfs_fattr_init(&data->fattr);
}
static int nfs_do_write(struct nfs_pgio_data *data, static int nfs_do_write(struct nfs_pgio_data *data,
const struct rpc_call_ops *call_ops, const struct rpc_call_ops *call_ops,
int how) int how)
...@@ -1129,7 +1091,7 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc, ...@@ -1129,7 +1091,7 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc,
return -ENOMEM; return -ENOMEM;
} }
data->pages.pagevec[0] = page; data->pages.pagevec[0] = page;
nfs_write_rpcsetup(data, len, offset, desc->pg_ioflags, &cinfo); nfs_pgio_rpcsetup(data, len, offset, desc->pg_ioflags, &cinfo);
list_add(&data->list, &hdr->rpc_list); list_add(&data->list, &hdr->rpc_list);
requests++; requests++;
nbytes -= len; nbytes -= len;
...@@ -1179,7 +1141,7 @@ static int nfs_flush_one(struct nfs_pageio_descriptor *desc, ...@@ -1179,7 +1141,7 @@ static int nfs_flush_one(struct nfs_pageio_descriptor *desc,
desc->pg_ioflags &= ~FLUSH_COND_STABLE; desc->pg_ioflags &= ~FLUSH_COND_STABLE;
/* Set up the argument struct */ /* Set up the argument struct */
nfs_write_rpcsetup(data, desc->pg_count, 0, desc->pg_ioflags, &cinfo); nfs_pgio_rpcsetup(data, desc->pg_count, 0, desc->pg_ioflags, &cinfo);
list_add(&data->list, &hdr->rpc_list); list_add(&data->list, &hdr->rpc_list);
desc->pg_rpc_callops = &nfs_pgio_common_ops; desc->pg_rpc_callops = &nfs_pgio_common_ops;
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册