pnfs: readwrite uses pnfs_layout_state
nfs41_lock_stateid_arg() is now called only once in handle_read()/handle_write(), and pnfs_read()/pnfs_write() no longer depend on nfs41_open_state Signed-off-by: Casey Bodley <cbodley@citi.umich.edu>
This commit is contained in:
parent
8c3da98cde
commit
c9585d937f
5 changed files with 87 additions and 69 deletions
|
|
@ -62,20 +62,18 @@ out:
|
|||
/* NFS41_READ */
|
||||
static int read_from_mds(
|
||||
IN nfs41_session *session,
|
||||
IN nfs41_open_state *state,
|
||||
IN nfs41_path_fh *file,
|
||||
IN stateid_arg *stateid,
|
||||
IN uint64_t offset,
|
||||
IN uint32_t length,
|
||||
OUT unsigned char *buffer,
|
||||
OUT ULONG *len_out)
|
||||
{
|
||||
stateid_arg stateid;
|
||||
int status = 0;
|
||||
bool_t eof;
|
||||
unsigned char *p = buffer;
|
||||
ULONG to_rcv = length, reloffset = 0, len = 0;
|
||||
const uint32_t maxreadsize = max_read_size(session, &state->file.fh);
|
||||
|
||||
nfs41_lock_stateid_arg(state, &stateid);
|
||||
const uint32_t maxreadsize = max_read_size(session, &file->fh);
|
||||
|
||||
if (to_rcv > maxreadsize)
|
||||
dprintf(1, "handle_nfs41_read: reading %d in chunks of %d\n",
|
||||
|
|
@ -84,11 +82,11 @@ static int read_from_mds(
|
|||
while(to_rcv > 0) {
|
||||
uint32_t bytes_read = 0, chunk = min(to_rcv, maxreadsize);
|
||||
|
||||
status = nfs41_read(session, &state->file, &stateid,
|
||||
status = nfs41_read(session, file, stateid,
|
||||
offset + reloffset, chunk, p, &bytes_read, &eof);
|
||||
if (status == NFS4ERR_OPENMODE && !len) {
|
||||
stateid.type = STATEID_SPECIAL;
|
||||
memcpy(&stateid.stateid, &special_read_stateid, sizeof(stateid4));
|
||||
stateid->type = STATEID_SPECIAL;
|
||||
memcpy(&stateid->stateid, &special_read_stateid, sizeof(stateid4));
|
||||
continue;
|
||||
} else if (status && !len) {
|
||||
status = nfs_to_windows_error(status, ERROR_NET_WRITE_FAULT);
|
||||
|
|
@ -117,24 +115,25 @@ out:
|
|||
static int read_from_pnfs(
|
||||
IN nfs41_root *root,
|
||||
IN nfs41_open_state *state,
|
||||
IN const stateid_arg *stateid,
|
||||
IN uint64_t offset,
|
||||
IN uint32_t length,
|
||||
OUT unsigned char *buffer,
|
||||
OUT ULONG *len_out)
|
||||
{
|
||||
pnfs_file_layout *layout;
|
||||
pnfs_layout_state *layout;
|
||||
enum pnfs_status pnfsstat;
|
||||
int status = NO_ERROR;
|
||||
|
||||
pnfsstat = pnfs_open_state_layout(state->session->client->layouts,
|
||||
pnfsstat = pnfs_layout_state_open(state->session->client->layouts,
|
||||
state->session, state, PNFS_IOMODE_READ, offset, length, &layout);
|
||||
if (pnfsstat) {
|
||||
status = ERROR_NOT_SUPPORTED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
pnfsstat = pnfs_read(root, state->session, state,
|
||||
layout, offset, length, buffer, len_out);
|
||||
pnfsstat = pnfs_read(root, state->session, &state->file,
|
||||
stateid, layout, offset, length, buffer, len_out);
|
||||
switch (pnfsstat) {
|
||||
case PNFS_SUCCESS:
|
||||
break;
|
||||
|
|
@ -152,11 +151,14 @@ out:
|
|||
static int handle_read(nfs41_upcall *upcall)
|
||||
{
|
||||
readwrite_upcall_args *args = &upcall->args.rw;
|
||||
stateid_arg stateid;
|
||||
ULONG pnfs_bytes_read = 0;
|
||||
int status = NO_ERROR;
|
||||
|
||||
nfs41_lock_stateid_arg(args->state, &stateid);
|
||||
|
||||
#ifdef PNFS_ENABLE_READ
|
||||
status = read_from_pnfs(args->root, args->state,
|
||||
status = read_from_pnfs(args->root, args->state, &stateid,
|
||||
args->offset, args->len, args->buffer, &args->out_len);
|
||||
|
||||
if (status == NO_ERROR || status == ERROR_HANDLE_EOF)
|
||||
|
|
@ -172,8 +174,8 @@ static int handle_read(nfs41_upcall *upcall)
|
|||
}
|
||||
#endif
|
||||
|
||||
status = read_from_mds(args->state->session, args->state,
|
||||
args->offset, args->len, args->buffer, &args->out_len);
|
||||
status = read_from_mds(args->state->session, &args->state->file,
|
||||
&stateid, args->offset, args->len, args->buffer, &args->out_len);
|
||||
|
||||
args->out_len += pnfs_bytes_read;
|
||||
out:
|
||||
|
|
@ -184,22 +186,20 @@ out:
|
|||
/* NFS41_WRITE */
|
||||
static int write_to_mds(
|
||||
IN nfs41_session *session,
|
||||
IN nfs41_open_state *state,
|
||||
IN nfs41_path_fh *file,
|
||||
IN stateid_arg *stateid,
|
||||
IN uint64_t offset,
|
||||
IN uint32_t length,
|
||||
IN unsigned char *buffer,
|
||||
OUT ULONG *len_out)
|
||||
{
|
||||
stateid_arg stateid;
|
||||
nfs41_write_verf verf;
|
||||
enum stable_how4 stable, committed;
|
||||
unsigned char *p;
|
||||
const uint32_t maxwritesize = max_write_size(session, &state->file.fh);
|
||||
const uint32_t maxwritesize = max_write_size(session, &file->fh);
|
||||
uint32_t to_send, reloffset, len;
|
||||
int status = 0;
|
||||
|
||||
nfs41_lock_stateid_arg(state, &stateid);
|
||||
|
||||
retry_write:
|
||||
p = buffer;
|
||||
to_send = length;
|
||||
|
|
@ -215,7 +215,7 @@ retry_write:
|
|||
while(to_send > 0) {
|
||||
uint32_t bytes_written = 0, chunk = min(to_send, maxwritesize);
|
||||
|
||||
status = nfs41_write(session, &state->file, &stateid, p, chunk,
|
||||
status = nfs41_write(session, file, stateid, p, chunk,
|
||||
offset + reloffset, stable, &bytes_written, &verf);
|
||||
if (status && !len)
|
||||
goto out;
|
||||
|
|
@ -232,7 +232,7 @@ retry_write:
|
|||
}
|
||||
if (committed == UNSTABLE4) {
|
||||
dprintf(1, "sending COMMIT for offset=%d and len=%d\n", offset, len);
|
||||
status = nfs41_commit(session, &state->file, offset, len, 1);
|
||||
status = nfs41_commit(session, file, offset, len, 1);
|
||||
}
|
||||
out:
|
||||
*len_out = len;
|
||||
|
|
@ -242,24 +242,25 @@ out:
|
|||
static int write_to_pnfs(
|
||||
IN nfs41_root *root,
|
||||
IN nfs41_open_state *state,
|
||||
IN const stateid_arg *stateid,
|
||||
IN uint64_t offset,
|
||||
IN uint32_t length,
|
||||
IN unsigned char *buffer,
|
||||
OUT ULONG *len_out)
|
||||
{
|
||||
pnfs_file_layout *layout;
|
||||
pnfs_layout_state *layout;
|
||||
enum pnfs_status pnfsstat;
|
||||
int status = NO_ERROR;
|
||||
|
||||
pnfsstat = pnfs_open_state_layout(state->session->client->layouts,
|
||||
pnfsstat = pnfs_layout_state_open(state->session->client->layouts,
|
||||
state->session, state, PNFS_IOMODE_RW, offset, length, &layout);
|
||||
if (pnfsstat) {
|
||||
status = ERROR_NOT_SUPPORTED;
|
||||
goto out;
|
||||
}
|
||||
|
||||
pnfsstat = pnfs_write(root, state->session, state,
|
||||
layout, offset, length, buffer, len_out);
|
||||
pnfsstat = pnfs_write(root, state->session, &state->file,
|
||||
stateid, layout, offset, length, buffer, len_out);
|
||||
if (pnfsstat) {
|
||||
status = ERROR_WRITE_FAULT;
|
||||
goto out;
|
||||
|
|
@ -271,11 +272,14 @@ out:
|
|||
static int handle_write(nfs41_upcall *upcall)
|
||||
{
|
||||
readwrite_upcall_args *args = &upcall->args.rw;
|
||||
stateid_arg stateid;
|
||||
ULONG pnfs_bytes_written = 0;
|
||||
int status;
|
||||
|
||||
nfs41_lock_stateid_arg(args->state, &stateid);
|
||||
|
||||
#ifdef PNFS_ENABLE_WRITE
|
||||
status = write_to_pnfs(args->root, args->state,
|
||||
status = write_to_pnfs(args->root, args->state, &stateid,
|
||||
args->offset, args->len, args->buffer, &args->out_len);
|
||||
|
||||
if (status == NO_ERROR)
|
||||
|
|
@ -291,8 +295,8 @@ static int handle_write(nfs41_upcall *upcall)
|
|||
}
|
||||
#endif
|
||||
|
||||
status = write_to_mds(args->state->session, args->state,
|
||||
args->offset, args->len, args->buffer, &args->out_len);
|
||||
status = write_to_mds(args->state->session, &args->state->file,
|
||||
&stateid, args->offset, args->len, args->buffer, &args->out_len);
|
||||
|
||||
args->out_len += pnfs_bytes_written;
|
||||
out:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue