Commit ec0e388d authored by Trond Myklebust's avatar Trond Myklebust

Make the NFSv4 write code use the stateid if it exists.

parent 47462c3c
...@@ -55,7 +55,8 @@ extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus); ...@@ -55,7 +55,8 @@ extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
extern struct rpc_procinfo nfs4_procedures[]; extern struct rpc_procinfo nfs4_procedures[];
static nfs4_stateid zero_stateid = static nfs4_stateid zero_stateid =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static spinlock_t renew_lock = SPIN_LOCK_UNLOCKED; static spinlock_t renew_lock = SPIN_LOCK_UNLOCKED;
static void static void
...@@ -1067,6 +1068,7 @@ nfs4_proc_write(struct inode *inode, struct rpc_cred *cred, ...@@ -1067,6 +1068,7 @@ nfs4_proc_write(struct inode *inode, struct rpc_cred *cred,
struct page *page, struct nfs_writeverf *verf) struct page *page, struct nfs_writeverf *verf)
{ {
struct nfs_server *server = NFS_SERVER(inode); struct nfs_server *server = NFS_SERVER(inode);
struct nfs4_shareowner *sp;
uint64_t offset = page_offset(page) + base; uint64_t offset = page_offset(page) + base;
struct nfs_writeargs arg = { struct nfs_writeargs arg = {
.fh = NFS_FH(inode), .fh = NFS_FH(inode),
...@@ -1090,6 +1092,19 @@ nfs4_proc_write(struct inode *inode, struct rpc_cred *cred, ...@@ -1090,6 +1092,19 @@ nfs4_proc_write(struct inode *inode, struct rpc_cred *cred,
int rpcflags = (flags & NFS_RW_SWAP) ? NFS_RPC_SWAPFLAGS : 0; int rpcflags = (flags & NFS_RW_SWAP) ? NFS_RPC_SWAPFLAGS : 0;
dprintk("NFS call write %d @ %Ld\n", count, (long long)offset); dprintk("NFS call write %d @ %Ld\n", count, (long long)offset);
/*
* Try first to use O_WRONLY, then O_RDWR stateid.
*/
sp = nfs4_get_inode_share(inode, O_WRONLY);
if (!sp)
sp = nfs4_get_inode_share(inode, O_RDWR);
if (sp)
memcpy(arg.stateid,sp->so_stateid, sizeof(nfs4_stateid));
else
memcpy(arg.stateid, zero_stateid, sizeof(nfs4_stateid));
fattr->valid = 0; fattr->valid = 0;
return rpc_call_sync(server->client, &msg, rpcflags); return rpc_call_sync(server->client, &msg, rpcflags);
} }
...@@ -1531,6 +1546,7 @@ nfs4_proc_write_setup(struct nfs_write_data *data, unsigned int count, int how) ...@@ -1531,6 +1546,7 @@ nfs4_proc_write_setup(struct nfs_write_data *data, unsigned int count, int how)
}; };
struct inode *inode = data->inode; struct inode *inode = data->inode;
struct nfs_page *req = nfs_list_entry(data->pages.next); struct nfs_page *req = nfs_list_entry(data->pages.next);
struct nfs4_shareowner *sp;
int stable; int stable;
int flags; int flags;
...@@ -1553,6 +1569,20 @@ nfs4_proc_write_setup(struct nfs_write_data *data, unsigned int count, int how) ...@@ -1553,6 +1569,20 @@ nfs4_proc_write_setup(struct nfs_write_data *data, unsigned int count, int how)
data->res.verf = &data->verf; data->res.verf = &data->verf;
data->timestamp = jiffies; data->timestamp = jiffies;
if(req->wb_file) {
unsigned int oflags = req->wb_file->f_flags;
sp = nfs4_get_inode_share(inode, oflags);
} else {
sp = nfs4_get_inode_share(inode, O_WRONLY);
if (!sp)
sp = nfs4_get_inode_share(inode, O_RDWR);
}
if (sp)
memcpy(data->args.stateid,sp->so_stateid, sizeof(nfs4_stateid));
else
memcpy(data->args.stateid, zero_stateid, sizeof(nfs4_stateid));
/* Set the initial flags for the task. */ /* Set the initial flags for the task. */
flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC; flags = (how & FLUSH_SYNC) ? 0 : RPC_TASK_ASYNC;
......
...@@ -837,10 +837,7 @@ encode_write(struct xdr_stream *xdr, struct nfs_writeargs *args) ...@@ -837,10 +837,7 @@ encode_write(struct xdr_stream *xdr, struct nfs_writeargs *args)
RESERVE_SPACE(36); RESERVE_SPACE(36);
WRITE32(OP_WRITE); WRITE32(OP_WRITE);
WRITE32(0xffffffff); /* magic stateid -1 */ WRITEMEM(args->stateid, sizeof(nfs4_stateid));
WRITE32(0xffffffff);
WRITE32(0xffffffff);
WRITE32(0xffffffff);
WRITE64(args->offset); WRITE64(args->offset);
WRITE32(args->stable); WRITE32(args->stable);
WRITE32(args->count); WRITE32(args->count);
......
...@@ -180,6 +180,7 @@ struct nfs_readres { ...@@ -180,6 +180,7 @@ struct nfs_readres {
struct nfs_writeargs { struct nfs_writeargs {
struct nfs_fh * fh; struct nfs_fh * fh;
nfs4_stateid stateid;
__u64 offset; __u64 offset;
__u32 count; __u32 count;
enum nfs3_stable_how stable; enum nfs3_stable_how stable;
......
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