> On 15 Dec 2016, at 15:53, Eric Blake <ebl...@redhat.com> wrote: > > Unused since commit 6c2d8511. Be the chainsaw mentioned in the comment :) > > Signed-off-by: Eric Blake <ebl...@redhat.com>
Signed-off-by: Alex Bligh <a...@alex.org.uk> Will wait for Wouter's say so before applying, given the chain-saw nature. Alex > --- > > Applies to the master branch; will cause a (trivial) merge conflict with > the extensions-write-zeroes branch. > > > nbd-server.c | 173 ----------------------------------------------------------- > 1 file changed, 173 deletions(-) > > diff --git a/nbd-server.c b/nbd-server.c > index 3dcfadd..fec397b 100644 > --- a/nbd-server.c > +++ b/nbd-server.c > @@ -2019,179 +2019,6 @@ static int mainloop_threaded(CLIENT* client) { > 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)) { > - 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) ? > 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; > - > - default: > - DEBUG ("Ignoring unknown command\n"); > - continue; > - } > - } > - return 0; > -} > > /** > * Set up client export array, which is an array of FILE_INFO. > -- > 2.9.3 > > > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, SlashDot.org! http://sdm.link/slashdot > _______________________________________________ > Nbd-general mailing list > Nbd-general@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/nbd-general > -- Alex Bligh ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ Nbd-general mailing list Nbd-general@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nbd-general