free_nfs_cb_data(data);
}
+static void nfs_fill_READ3args(READ3args *args, struct nfsfh *fh, uint64_t offset, uint64_t count)
+{
+ memset(args, 0, sizeof(READ3args));
+ args->file = fh->fh;
+ args->offset = offset;
+ args->count = count;
+}
+
static void nfs_pread_mcb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
{
struct nfs_mcb_data *mdata = private_data;
data->error = 1;
} else {
if (res->READ3res_u.resok.count > 0) {
- memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count);
- if ((unsigned)data->max_offset < mdata->offset + res->READ3res_u.resok.count) {
- data->max_offset = mdata->offset + res->READ3res_u.resok.count;
+ if (res->READ3res_u.resok.count <= mdata->count) {
+ memcpy(&data->buffer[mdata->offset - data->start_offset], res->READ3res_u.resok.data.data_val, res->READ3res_u.resok.count);
+ if (data->max_offset < mdata->offset + res->READ3res_u.resok.count) {
+ data->max_offset = mdata->offset + res->READ3res_u.resok.count;
+ }
+ } else {
+ rpc_set_error(nfs->rpc, "NFS: Read overflow. Server has sent more data than requested!");
+ data->error = 1;
}
}
}
if (count <= nfs_get_readmax(nfs)) {
READ3args args;
-
- memset(&args, 0, sizeof(READ3args));
- args.file = nfsfh->fh;
- args.offset = offset;
- args.count = count;
+ nfs_fill_READ3args(&args, nfsfh, offset, count);
if (rpc_nfs3_read_async(nfs->rpc, nfs_pread_cb, &args, data) != 0) {
rpc_set_error(nfs->rpc, "RPC error: Failed to send READ call for %s", data->path);
mdata->offset = offset;
mdata->count = readcount;
- memset(&args, 0, sizeof(READ3args));
- args.file = nfsfh->fh;
- args.offset = offset;
- args.count = readcount;
+ nfs_fill_READ3args(&args, nfsfh, offset, readcount);
if (rpc_nfs3_read_async(nfs->rpc, nfs_pread_mcb, &args, mdata) != 0) {
rpc_set_error(nfs->rpc, "RPC error: Failed to send READ call for %s", data->path);
free_nfs_cb_data(data);
}
+static void nfs_fill_WRITE3args (WRITE3args *args, struct nfsfh *fh, uint64_t offset, uint64_t count,
+ void *buf)
+{
+ memset(args, 0, sizeof(WRITE3args));
+ args->file = fh->fh;
+ args->offset = offset;
+ args->count = count;
+ args->stable = fh->is_sync?FILE_SYNC:UNSTABLE;
+ args->data.data_len = count;
+ args->data.data_val = buf;
+}
+
static void nfs_pwrite_mcb(struct rpc_context *rpc, int status, void *command_data, void *private_data)
{
struct nfs_mcb_data *mdata = private_data;
data->error = 1;
} else {
if (res->WRITE3res_u.resok.count > 0) {
- if ((unsigned)data->max_offset < mdata->offset + res->WRITE3res_u.resok.count) {
+ if (data->max_offset < mdata->offset + res->WRITE3res_u.resok.count) {
data->max_offset = mdata->offset + res->WRITE3res_u.resok.count;
}
}
if (count <= nfs_get_writemax(nfs)) {
WRITE3args args;
-
- memset(&args, 0, sizeof(WRITE3args));
- args.file = nfsfh->fh;
- args.offset = offset;
- args.count = count;
- args.stable = nfsfh->is_sync?FILE_SYNC:UNSTABLE;
- args.data.data_len = count;
- args.data.data_val = buf;
+ nfs_fill_WRITE3args(&args, nfsfh, offset, count, buf);
if (rpc_nfs3_write_async(nfs->rpc, nfs_pwrite_cb, &args, data) != 0) {
rpc_set_error(nfs->rpc, "RPC error: Failed to send WRITE call for %s", data->path);
mdata->offset = offset;
mdata->count = writecount;
- memset(&args, 0, sizeof(WRITE3args));
- args.file = nfsfh->fh;
- args.offset = offset;
- args.count = writecount;
- args.stable = nfsfh->is_sync?FILE_SYNC:UNSTABLE;
- args.data.data_len = writecount;
- args.data.data_val = &buf[offset - data->start_offset];
+ nfs_fill_WRITE3args(&args, nfsfh, offset, writecount, &buf[offset - data->start_offset]);
if (rpc_nfs3_write_async(nfs->rpc, nfs_pwrite_mcb, &args, mdata) != 0) {
rpc_set_error(nfs->rpc, "RPC error: Failed to send WRITE call for %s", data->path);
rdpe_cb_data->getattrcount--;
if (status == RPC_STATUS_ERROR) {
+ rpc_set_error(nfs->rpc, "LOOKUP during READDIRPLUS emulation "
+ "failed with RPC_STATUS_ERROR");
rdpe_cb_data->status = RPC_STATUS_ERROR;
}
if (status == RPC_STATUS_CANCEL) {
+ rpc_set_error(nfs->rpc, "LOOKUP during READDIRPLUS emulation "
+ "failed with RPC_STATUS_CANCEL");
rdpe_cb_data->status = RPC_STATUS_CANCEL;
}
if (status == RPC_STATUS_SUCCESS && res->status == NFS3_OK) {
if (rdpe_cb_data->getattrcount == 0) {
if (rdpe_cb_data->status != RPC_STATUS_SUCCESS) {
- data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc), data->private_data);
+ rpc_set_error(nfs->rpc, "READDIRPLUS emulation "
+ "failed: %s", rpc_get_error(rpc));
+ data->cb(-ENOMEM, nfs, rpc_get_error(nfs->rpc),
+ data->private_data);
nfs_free_nfsdir(nfsdir);
} else {
data->cb(0, nfs, nfsdir, data->private_data);