1 Commits

Author SHA1 Message Date
Patrick J Cherry
102738d9ad Updated logging output during readloop() and writeloop() failures
There's a handy SHOW_ERRNO macro we can use to get consistent logging
for system call failures from readloop() and writeloop().
2018-04-27 10:45:42 +01:00
3 changed files with 30 additions and 30 deletions

View File

@@ -148,8 +148,6 @@ int readloop(int filedes, void *buffer, size_t size)
ssize_t result = read(filedes, buffer + readden, size - readden);
if (result == 0 /* EOF */ ) {
warn("end-of-file detected while reading after %i bytes",
readden);
return -1;
}
@@ -224,8 +222,7 @@ int splice_via_pipe_loop(int fd_in, int fd_out, size_t len)
while (spliced < len) {
ssize_t run = len - spliced;
ssize_t s2, s1 =
spliceloop(fd_in, NULL, pipefd[1], NULL, run,
ssize_t s2, s1 = spliceloop(fd_in, NULL, pipefd[1], NULL, run,
SPLICE_F_NONBLOCK);
/*if (run > 65535)
run = 65535; */

View File

@@ -76,7 +76,7 @@ int socket_nbd_read_hello(int fd, uint64_t * out_size,
if (0 > readloop(fd, &init_raw, sizeof(init_raw))) {
warn("Couldn't read init");
warn(SHOW_ERRNO("Couldn't read init"));
return 0;
}
@@ -130,7 +130,7 @@ void read_reply(int fd, uint64_t request_raw_handle,
ERROR_IF_NEGATIVE(readloop
(fd, &reply_raw, sizeof(struct nbd_reply_raw)),
"Couldn't read reply");
SHOW_ERRNO("Couldn't read reply"));
nbd_r2h_reply(&reply_raw, reply);
@@ -171,14 +171,15 @@ void socket_nbd_read(int fd, uint64_t from, uint32_t len, int out_fd,
fill_request(&request_raw, REQUEST_READ, 0, from, len);
FATAL_IF_NEGATIVE(writeloop(fd, &request_raw, sizeof(request_raw)),
"Couldn't write request");
SHOW_ERRNO("Couldn't write request"));
wait_for_data(fd, timeout_secs);
read_reply(fd, request_raw.handle.w, &reply);
if (out_buf) {
FATAL_IF_NEGATIVE(readloop(fd, out_buf, len), "Read failed");
FATAL_IF_NEGATIVE(readloop(fd, out_buf, len),
SHOW_ERRNO("Read failed"));
} else {
FATAL_IF_NEGATIVE(splice_via_pipe_loop(fd, out_fd, len),
"Splice failed");
@@ -193,10 +194,11 @@ void socket_nbd_write(int fd, uint64_t from, uint32_t len, int in_fd,
fill_request(&request_raw, REQUEST_WRITE, 0, from, len);
ERROR_IF_NEGATIVE(writeloop(fd, &request_raw, sizeof(request_raw)),
"Couldn't write request");
SHOW_ERRNO("Couldn't write request"));
if (in_buf) {
ERROR_IF_NEGATIVE(writeloop(fd, in_buf, len), "Write failed");
ERROR_IF_NEGATIVE(writeloop(fd, in_buf, len),
SHOW_ERRNO("Write failed"));
} else {
ERROR_IF_NEGATIVE(splice_via_pipe_loop(in_fd, fd, len),
"Splice failed");
@@ -217,7 +219,8 @@ int socket_nbd_disconnect(int fd)
* the mirror without affecting the main server.
*/
FATAL_IF_NEGATIVE(writeloop(fd, &request_raw, sizeof(request_raw)),
"Failed to write the disconnect request.");
SHOW_ERRNO
("Failed to write the disconnect request."));
return success;
}

View File

@@ -152,7 +152,7 @@ void write_not_zeroes(struct client *client, uint64_t from, uint64_t len)
(dst), \
(len) \
), \
"read failed %ld+%d", from, (len) \
SHOW_ERRNO("read failed %ld+%d", from, (len)) \
)
if (bitset_is_set_at(map, from)) {
@@ -232,13 +232,13 @@ int client_read_request(struct client *client,
*disconnected = 1;
switch (errno) {
case 0:
warn("EOF while reading request");
warn(SHOW_ERRNO("EOF while reading request"));
return 0;
case ECONNRESET:
warn("Connection reset while" " reading request");
warn(SHOW_ERRNO("Connection reset while reading request"));
return 0;
case ETIMEDOUT:
warn("Connection timed out while" " reading request");
warn(SHOW_ERRNO("Connection timed out while reading request"));
return 0;
default:
/* FIXME: I've seen this happen, but I
@@ -248,7 +248,7 @@ int client_read_request(struct client *client,
* again. It should *probably* be an
* error() call, but I want to be sure.
* */
fatal("Error reading request: %d, %s", errno, strerror(errno));
fatal(SHOW_ERRNO("Error reading request"));
}
}
@@ -271,16 +271,17 @@ int fd_write_reply(int fd, uint64_t handle, int error)
if (-1 == writeloop(fd, &reply_raw, sizeof(reply_raw))) {
switch (errno) {
case ECONNRESET:
error("Connection reset while writing reply");
error(SHOW_ERRNO("Connection reset while writing reply"));
break;
case EBADF:
fatal("Tried to write to an invalid file descriptor");
fatal(SHOW_ERRNO
("Tried to write to an invalid file descriptor"));
break;
case EPIPE:
error("Remote end closed");
error(SHOW_ERRNO("Remote end closed"));
break;
default:
fatal("Unhandled error while writing: %d", errno);
fatal(SHOW_ERRNO("Unhandled error while writing"));
}
}
@@ -318,7 +319,7 @@ void client_write_init(struct client *client, uint64_t size)
ERROR_IF_NEGATIVE(writeloop
(client->socket, &init_raw, sizeof(init_raw)),
"Couldn't send hello");
SHOW_ERRNO("Couldn't send hello"));
}
@@ -329,8 +330,7 @@ void client_write_init(struct client *client, uint64_t size)
void client_flush(struct client *client, size_t len)
{
int devnull = open("/dev/null", O_WRONLY);
FATAL_IF_NEGATIVE(devnull,
"Couldn't open /dev/null: %s", strerror(errno));
FATAL_IF_NEGATIVE(devnull, SHOW_ERRNO("Couldn't open /dev/null"));
int pipes[2];
pipe(pipes);
@@ -341,12 +341,12 @@ void client_flush(struct client *client, size_t len)
ssize_t received = splice(client->socket, NULL,
pipes[1], NULL,
len - spliced, flags);
FATAL_IF_NEGATIVE(received, "splice error: %s", strerror(errno));
FATAL_IF_NEGATIVE(received, SHOW_ERRNO("splice error"));
ssize_t junked = 0;
while (junked < received) {
ssize_t junk;
junk = splice(pipes[0], NULL, devnull, NULL, received, flags);
FATAL_IF_NEGATIVE(junk, "splice error: %s", strerror(errno));
FATAL_IF_NEGATIVE(junk, SHOW_ERRNO("splice error"));
junked += junk;
}
spliced += received;
@@ -459,8 +459,8 @@ void client_reply_to_write(struct client *client,
ERROR_IF_NEGATIVE(readloop(client->socket,
client->mapped + request.from,
request.len),
"reading write data failed from=%ld, len=%d",
request.from, request.len);
SHOW_ERRNO("reading write data failed from=%ld, len=%d",
request.from, request.len));
/* the allocation_map is shared between client threads, and may be
* being built. We need to reflect the write in it, as it may be in
@@ -693,8 +693,8 @@ void *client_serve(void *client_uncast)
&client->fileno,
&client->mapped_size,
(void **) &client->mapped),
"Couldn't open/mmap file %s: %s",
client->serve->filename, strerror(errno)
SHOW_ERRNO("Couldn't open/mmap file %s",
client->serve->filename)
);
FATAL_IF_NEGATIVE(madvise