removing copies from readdir path

This commit is contained in:
Olga Kornievskaia 2011-09-27 12:21:26 -04:00
parent 7e52f53097
commit 27030b1764
4 changed files with 66 additions and 30 deletions

View file

@ -85,7 +85,7 @@ static unsigned int WINAPI thread_main(void *args)
// buffer used to send downcall content, need to dynamically allocated
// as we don't know the length of the buffer (ie. size of directory listing
unsigned char *inbuf = NULL;
DWORD inbuf_len, outbuf_len;
DWORD inbuf_len = UPCALL_BUF_SIZE, outbuf_len;
nfs41_upcall upcall;
pipe = CreateFile(NFS41_USER_DEVICE_NAME_A, GENERIC_READ | GENERIC_WRITE,
@ -130,11 +130,6 @@ write_downcall:
"get_last_error=%d\n", upcall.xid, opcode2string(upcall.opcode),
upcall.status, upcall.last_error);
if (upcall.opcode == NFS41_DIR_QUERY)
inbuf_len = UPCALL_BUF_SIZE + upcall.args.readdir.query_reply_len;
else
inbuf_len = UPCALL_BUF_SIZE;
inbuf = malloc(inbuf_len);
if (inbuf == NULL) {
upcall.status = GetLastError();

View file

@ -63,13 +63,15 @@ static int parse_readdir(unsigned char *buffer, uint32_t length, nfs41_upcall *u
if (status) goto out;
status = safe_read(&buffer, &length, &args->single, sizeof(args->single));
if (status) goto out;
status = safe_read(&buffer, &length, &args->kbuf, sizeof(args->kbuf));
if (status) goto out;
args->root = upcall->root_ref;
args->state = upcall->state_ref;
dprintf(1, "parsing NFS41_DIR_QUERY: info_class=%d buf_len=%d "
"filter='%s'\n\tInitial\\Restart\\Single %d\\%d\\%d\n",
"filter='%s'\n\tInitial\\Restart\\Single %d\\%d\\%d buf=%p\n",
args->query_class, args->buf_len, args->filter,
args->initial, args->restart, args->single);
args->initial, args->restart, args->single, args->kbuf);
out:
return status;
}
@ -479,13 +481,13 @@ static int handle_readdir(nfs41_upcall *upcall)
goto out;
}
entry_buf = malloc(max(args->buf_len, 4096));
entry_buf = malloc(args->buf_len);
if (entry_buf == NULL) {
status = GetLastError();
goto out_free_cookie;
}
fetch_entries:
entry_buf_len = max(args->buf_len, 4096);
entry_buf_len = args->buf_len;
init_getattr_request(&attr_request);
attr_request.arr[0] |= FATTR4_WORD0_RDATTR_ERROR;
@ -550,20 +552,11 @@ fetch_entries:
if (entry_buf_len) {
unsigned char *entry_pos = entry_buf;
unsigned char *dst_pos;
unsigned char *dst_pos = args->kbuf;
uint32_t dst_len = args->buf_len;
nfs41_readdir_entry *entry;
PULONG offset, last_offset = NULL;
if (args->buf == NULL) {
args->buf = malloc(args->buf_len);
if (args->buf == NULL) {
status = GetLastError();
goto out_free_cookie;
}
}
dst_pos = args->buf;
for (;;) {
entry = (nfs41_readdir_entry*)entry_pos;
offset = (PULONG)dst_pos; /* ULONG NextEntryOffset */
@ -625,7 +618,6 @@ out:
dprintf(1, "error code %d.\n", status);
break;
}
free(args->buf);
args->buf = NULL;
} else {
dprintf(1, "success!\n");
@ -642,10 +634,6 @@ static int marshall_readdir(unsigned char *buffer, uint32_t *length, nfs41_upcal
readdir_upcall_args *args = &upcall->args.readdir;
status = safe_write(&buffer, length, &args->query_reply_len, sizeof(args->query_reply_len));
if (status) goto out;
status = safe_write(&buffer, length, args->buf, args->query_reply_len);
out:
free(args->buf);
return status;
}

View file

@ -132,6 +132,7 @@ typedef struct __readdir_upcall_args {
BOOLEAN initial;
BOOLEAN restart;
BOOLEAN single;
unsigned char *kbuf;
} readdir_upcall_args;
typedef struct __symlink_upcall_args {