Skip to content

Commit

Permalink
nbd-server: Kill dead mainloop()
Browse files Browse the repository at this point in the history
Unused since commit 6c2d851.  Be the chainsaw mentioned in the comment :)

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Alex Bligh <alex@alex.org.uk>
  • Loading branch information
abligh committed Dec 15, 2016
1 parent b7ffc95 commit 21476f1
Showing 1 changed file with 0 additions and 196 deletions.
196 changes: 0 additions & 196 deletions nbd-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -2071,202 +2071,6 @@ static int mainloop_threaded(CLIENT* client) {
}
}

/** sending macro. */
#define SEND(cl,reply) { socket_write( cl, &reply, sizeof( reply )); \
if (client->transactionlogfd != -1) \
writeit(client->transactionlogfd, &reply, sizeof(reply)); }
/** error macro. */
#define ERROR(client,reply,errcode) { reply.error = nbd_errno(errcode); SEND(client,reply); reply.error = 0; }
/**
* Serve a file to a single client.
*
* @todo This beast needs to be split up in many tiny little manageable
* pieces. Preferably with a chainsaw.
*
* @param client The client we're going to serve to.
* @return when the client disconnects
**/
int mainloop(CLIENT *client) {
struct nbd_request request;
struct nbd_reply reply;
gboolean go_on=TRUE;
#ifdef DODBG
int i = 0;
#endif
send_export_info(client);
DEBUG("Entering request loop!\n");
reply.magic = htonl(NBD_REPLY_MAGIC);
reply.error = 0;
while (go_on) {
char buf[BUFSIZE];
char* p;
size_t len;
size_t currlen;
size_t writelen;
uint16_t command;
#ifdef DODBG
i++;
printf("%d: ", i);
#endif
socket_read(client, &request, sizeof(request));
if (client->transactionlogfd != -1)
writeit(client->transactionlogfd, &request, sizeof(request));

request.from = ntohll(request.from);
request.type = ntohl(request.type);
command = request.type & NBD_CMD_MASK_COMMAND;
len = ntohl(request.len);

DEBUG("%s from %llu (%llu) len %u, ", getcommandname(command),
(unsigned long long)request.from,
(unsigned long long)request.from / 512, len);

if (request.magic != htonl(NBD_REQUEST_MAGIC))
err("Not enough magic.");

memcpy(reply.handle, request.handle, sizeof(reply.handle));

if ((command==NBD_CMD_WRITE) || (command==NBD_CMD_READ) ||
(command==NBD_CMD_TRIM) || (command==NBD_CMD_WRITE_ZEROES)) {
if (request.from + len < request.from) { // 64 bit overflow!!
DEBUG("[Number too large!]");
ERROR(client, reply, EINVAL);
continue;
}

if (((off_t)request.from + len) > client->exportsize) {
DEBUG("[RANGE!]");
ERROR(client, reply, (command==NBD_CMD_WRITE || command==NBD_CMD_WRITE_ZEROES) ? ENOSPC : EINVAL);
continue;
}

currlen = len;
if (currlen > BUFSIZE - sizeof(struct nbd_reply)) {
currlen = BUFSIZE - sizeof(struct nbd_reply);
if(!logged_oversized) {
msg(LOG_DEBUG, "oversized request (this is not a problem)");
logged_oversized = true;
}
}
}

switch (command) {

case NBD_CMD_DISC:
msg(LOG_INFO, "Disconnect request received.");
if (client->server->flags & F_COPYONWRITE) {
if (client->difmap) g_free(client->difmap) ;
close(client->difffile);
unlink(client->difffilename);
free(client->difffilename);
}
go_on=FALSE;
continue;

case NBD_CMD_WRITE:
DEBUG("wr: net->buf, ");
while(len > 0) {
socket_read(client, buf, currlen);
DEBUG("buf->exp, ");
if ((client->server->flags & F_READONLY) ||
(client->server->flags & F_AUTOREADONLY)) {
DEBUG("[WRITE to READONLY!]");
ERROR(client, reply, EPERM);
consume(client, len-currlen, buf, BUFSIZE);
continue;
}
if (expwrite(request.from, buf, currlen, client,
request.type & NBD_CMD_FLAG_FUA)) {
DEBUG("Write failed: %m" );
ERROR(client, reply, errno);
consume(client, len-currlen, buf, BUFSIZE);
continue;
}
len -= currlen;
request.from += currlen;
currlen = (len < BUFSIZE) ? len : BUFSIZE;
}
SEND(client, reply);
DEBUG("OK!\n");
continue;

case NBD_CMD_FLUSH:
DEBUG("fl: ");
if (expflush(client)) {
DEBUG("Flush failed: %m");
ERROR(client, reply, errno);
continue;
}
SEND(client, reply);
DEBUG("OK!\n");
continue;

case NBD_CMD_READ:
DEBUG("exp->buf, ");
if (client->transactionlogfd != -1)
writeit(client->transactionlogfd, &reply, sizeof(reply));
socket_write(client, &reply, sizeof(reply));
p = buf;
writelen = currlen;
while(len > 0) {
if (expread(request.from, p, currlen, client)) {
DEBUG("Read failed: %m");
ERROR(client, reply, errno);
continue;
}

DEBUG("buf->net, ");
socket_write(client, buf, writelen);
len -= currlen;
request.from += currlen;
currlen = (len < BUFSIZE) ? len : BUFSIZE;
p = buf;
writelen = currlen;
}
DEBUG("OK!\n");
continue;

case NBD_CMD_TRIM:
/* The kernel module sets discard_zeroes_data == 0,
* so it is okay to do nothing. */
if ((client->server->flags & F_READONLY) ||
(client->server->flags & F_AUTOREADONLY)) {
DEBUG("[TRIM to READONLY!]");
ERROR(client, reply, EPERM);
continue;
}
if (exptrim(&request, client)) {
DEBUG("Trim failed: %m");
ERROR(client, reply, errno);
continue;
}
SEND(client, reply);
continue;

case NBD_CMD_WRITE_ZEROES:
if ((client->server->flags & F_READONLY) ||
(client->server->flags & F_AUTOREADONLY)) {
DEBUG("[WRITE_ZEROES to READONLY!]");
ERROR(client, reply, EPERM);
continue;
}
if (expwrite_zeroes(&request, client,
request.type & NBD_CMD_FLAG_FUA)) {
DEBUG("Write zeroes failed: %m");
ERROR(client, reply, errno);
continue;
}
SEND(client, reply);
continue;

default:
DEBUG ("Ignoring unknown command\n");
continue;
}
}
return 0;
}

/**
* Set up client export array, which is an array of FILE_INFO.
* Also, split a single exportfile into multiple ones, if that was asked.
Expand Down

0 comments on commit 21476f1

Please sign in to comment.