vos: Get stdin and stdout block sizes with USD_IOCTL()

Use the USD_IOCTL() function to get the block size when writing to
stdout or reading from stdin, as well as regular files.

This makes the code more consistent and eliminates the need to pass the
block size to the ReceiveFile() and SendFile() functions.

Change-Id: If45e93530ded3edc8673370cd88f18228bc21827
Reviewed-on: https://gerrit.openafs.org/14757
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Marcio Brito Barbosa <mbarbosa@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Michael Meffie 2021-08-16 14:24:38 -04:00
parent 1b826118fd
commit 60425f1e8f

View File

@ -302,14 +302,29 @@ IsPartValid(afs_int32 partId, afs_uint32 server, afs_int32 *code)
return success;
}
/*sends the contents of file associated with <fd> and <blksize> to Rx Stream
* associated with <call> */
/**
* Send the contents of a dump file to the volume server.
*
* @param[in] ufd usd file handle opened for read
* @param[in] call rx call object
*
* @returns status
* @retval 0 success
* @retval -1 error
*/
static int
SendFile(usd_handle_t ufd, struct rx_call *call, long blksize)
SendFile(usd_handle_t ufd, struct rx_call *call)
{
char *buffer = (char *)0;
afs_int32 error = 0;
char *buffer = NULL;
afs_int32 error;
afs_uint32 nbytes;
long blksize = 0;
error = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
if (error != 0) {
fprintf(STDERR, "Failed to get block size; error=%d\n", error);
return -1;
}
buffer = malloc(blksize);
if (!buffer) {
@ -355,7 +370,6 @@ WriteData(struct rx_call *call, void *rock)
{
char *filename = (char *) rock;
usd_handle_t ufd = NULL;
long blksize;
afs_int32 error = 0;
afs_int32 code;
afs_int64 currOffset;
@ -364,12 +378,8 @@ WriteData(struct rx_call *call, void *rock)
if (!filename || !*filename) {
usd_StandardInput(&ufd);
blksize = 4096;
} else {
code = usd_Open(filename, USD_OPEN_RDONLY, 0, &ufd);
if (code == 0) {
code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
}
if (code) {
fprintf(STDERR, "Could not access file '%s': %s\n", filename,
afs_error_message(code));
@ -387,7 +397,7 @@ WriteData(struct rx_call *call, void *rock)
}
USD_SEEK(ufd, 0, SEEK_SET, &currOffset);
}
code = SendFile(ufd, call, blksize);
code = SendFile(ufd, call);
if (code) {
error = code;
goto wfail;
@ -404,16 +414,31 @@ WriteData(struct rx_call *call, void *rock)
return error;
}
/* Receive data from <call> stream into file associated
* with <fd> <blksize>
/**
* Receive the contents of a dump from volume server and write
* to a file handle.
*
* @param[in] ufd usd file handle opened for write
* @param[in] call rx call object
*
* @returns status
* @retval 0 success
* @retval -1 error
*/
static int
ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
ReceiveFile(usd_handle_t ufd, struct rx_call *call)
{
char *buffer = NULL;
afs_int32 bytesread;
afs_uint32 bytesleft, w;
afs_int32 error = 0;
afs_int32 error;
long blksize = 0;
error = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
if (error != 0) {
fprintf(STDERR, "Failed to get block size; error=%d\n", error);
ERROR_EXIT(-1);
}
buffer = malloc(blksize);
if (!buffer) {
@ -457,12 +482,10 @@ DumpFunction(struct rx_call *call, void *rock)
afs_int32 error = 0;
afs_int32 code;
afs_int64 size;
long blksize;
/* Open the output file */
if (!filename || !*filename) {
usd_StandardOutput(&ufd);
blksize = 4096;
} else {
code =
usd_Open(filename, USD_OPEN_CREATE | USD_OPEN_RDWR, 0666, &ufd);
@ -470,9 +493,6 @@ DumpFunction(struct rx_call *call, void *rock)
size = 0;
code = USD_IOCTL(ufd, USD_IOCTL_SETSIZE, &size);
}
if (code == 0) {
code = USD_IOCTL(ufd, USD_IOCTL_GETBLKSIZE, &blksize);
}
if (code) {
fprintf(STDERR, "Could not create file '%s': %s\n", filename,
afs_error_message(code));
@ -480,7 +500,7 @@ DumpFunction(struct rx_call *call, void *rock)
}
}
code = ReceiveFile(ufd, call, blksize);
code = ReceiveFile(ufd, call);
if (code)
ERROR_EXIT(code);