From: Wouter Verhelst Date: Sat, 28 May 2011 08:47:21 +0000 (+0200) Subject: Merge branch 'alex' X-Git-Url: http://git.alex.org.uk?hp=ebb917056caed73a8df55fd5fd725e849365ab35 Merge branch 'alex' --- diff --git a/autogen.sh b/autogen.sh index 2d041fd..0719077 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,4 +1,4 @@ #!/bin/sh set -ex -make -C man -f Makefile.am nbd-server.1.sh.in nbd-server.5.sh.in nbd-client.8.sh.in +make -C man -f Makefile.am nbd-server.1.sh.in nbd-server.5.sh.in nbd-client.8.sh.in nbd-trdump.8.sh.in exec autoreconf -f -i diff --git a/configure.ac b/configure.ac index ef131f5..3c29625 100644 --- a/configure.ac +++ b/configure.ac @@ -123,6 +123,6 @@ AC_TYPE_PID_T nbd_server_CPPFLAGS=$nbd_server_CPPFLAGS" -DSYSCONFDIR='\"$sysconfdir\"'" AC_SUBST(nbd_server_CPPFLAGS) AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([Makefile doc/Doxyfile man/Makefile man/nbd-client.8.sh man/nbd-server.5.sh man/nbd-server.1.sh]) +AC_CONFIG_FILES([Makefile doc/Doxyfile man/Makefile man/nbd-client.8.sh man/nbd-server.5.sh man/nbd-server.1.sh man/nbd-trdump.8.sh]) AC_OUTPUT diff --git a/man/Makefile.am b/man/Makefile.am index 0ee8d62..2d1de20 100644 --- a/man/Makefile.am +++ b/man/Makefile.am @@ -1,8 +1,8 @@ -man_MANS = nbd-server.1 nbd-server.5 nbd-client.8 +man_MANS = nbd-server.1 nbd-server.5 nbd-client.8 nbd-trdump.8 CLEANFILES = manpage.links manpage.refs -DISTCLEANFILES = nbd-server.1 nbd-client.8 nbd-server.5 -MAINTAINERCLEANFILES = nbd-server.1.sh.in nbd-client.8.sh.in nbd-server.5.sh.in -EXTRA_DIST = nbd-server.1.in.sgml nbd-client.8.in.sgml nbd-server.5.in.sgml nbd-server.1.sh.in nbd-server.5.sh.in nbd-client.8.sh.in sh.tmpl +DISTCLEANFILES = nbd-server.1 nbd-client.8 nbd-server.5 nbd-trdump.8 +MAINTAINERCLEANFILES = nbd-server.1.sh.in nbd-client.8.sh.in nbd-server.5.sh.in nbd-trdump.8.sh.in +EXTRA_DIST = nbd-server.1.in.sgml nbd-client.8.in.sgml nbd-server.5.in.sgml nbd-trdump.8.in.sgml nbd-server.1.sh.in nbd-server.5.sh.in nbd-client.8.sh.in nbd-trdump.8.sh.in sh.tmpl nbd-server.1: nbd-server.1.sh sh nbd-server.1.sh > nbd-server.1 @@ -10,6 +10,8 @@ nbd-server.5: nbd-server.5.sh sh nbd-server.5.sh > nbd-server.5 nbd-client.8: nbd-client.8.sh sh nbd-client.8.sh > nbd-client.8 +nbd-trdump.8: nbd-trdump.8.sh + sh nbd-trdump.8.sh > nbd-trdump.8 nbd-server.1.sh.in: nbd-server.1.in.sgml sh.tmpl LC_ALL=C docbook2man nbd-server.1.in.sgml cat sh.tmpl > nbd-server.1.sh.in @@ -28,3 +30,9 @@ nbd-server.5.sh.in: nbd-server.5.in.sgml sh.tmpl cat NBD-SERVER.5 >> nbd-server.5.sh.in echo "EOF" >> nbd-server.5.sh.in rm NBD-SERVER.5 +nbd-trdump.8.sh.in: nbd-trdump.8.in.sgml sh.tmpl + LC_ALL=C docbook2man nbd-trdump.8.in.sgml + cat sh.tmpl > nbd-trdump.8.sh.in + cat NBD-TRDUMP.8 >> nbd-trdump.8.sh.in + echo "EOF" >> nbd-trdump.8.sh.in + rm NBD-TRDUMP.8 diff --git a/man/nbd-server.1.in.sgml b/man/nbd-server.1.in.sgml index 047fcb6..7a5832e 100644 --- a/man/nbd-server.1.in.sgml +++ b/man/nbd-server.1.in.sgml @@ -274,7 +274,7 @@ manpage.1: manpage.sgml SEE ALSO - nbd-client (8), nbd-server (5) + nbd-client (8), nbd-server (5), nbd-trdump (8) diff --git a/man/nbd-server.5.in.sgml b/man/nbd-server.5.in.sgml index 32ce37f..1bc1980 100644 --- a/man/nbd-server.5.in.sgml +++ b/man/nbd-server.5.in.sgml @@ -691,7 +691,7 @@ manpage.1: manpage.sgml SEE ALSO - nbd-server (1), nbd-client (8) + nbd-server (1), nbd-client (8), nbd-trdump (8) diff --git a/man/nbd-trdump.8.in.sgml b/man/nbd-trdump.8.in.sgml new file mode 100644 index 0000000..d047f59 --- /dev/null +++ b/man/nbd-trdump.8.in.sgml @@ -0,0 +1,143 @@ + manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + --> + + + Wouter"> + Verhelst"> + + $Date$"> + + 8"> + wouter@debian.org"> + + NBD-TRDUMP"> + + + Debian GNU/Linux"> + GNU"> +]> + + + +
+ &dhemail; +
+ + &dhfirstname; + &dhsurname; + + + 2001 + &dhusername; + + &dhdate; +
+ + &dhucpackage; + + &dhsection; + + + &dhpackage; + + translate an nbd transaction log into human readable form + + + + &dhpackage; + + + + DESCRIPTION + + &dhpackage; translates + a transaction log produced by nbd-server + (specifically by the transactionlog + configuration directive) into human readable form. + + The command acts as a traditional UNIX filter, i.e. the + transaction log must be supplied on standard input, and the + human readable output is sent to standard output. + + + OUTPUT + + The following may be output: + + + + + + A request packet sent from the client to the server. + + + + + + A reply packet sent from the server to the client. + + + + + + The handle of the packet. + + + + + + The command sent. + + + + + + The offet from the start of the disk. + + + + + + The length of data. + + + + + + The error returned. + + + + + + SEE ALSO + + nbd-server (1). + + + + AUTHOR + The NBD kernel module and the NBD tools have been written by + Pavel Macheck (pavel@ucw.cz). + + The kernel module is now maintained by Paul Clements + (Paul.Clements@steeleye.com), while the userland tools are maintained by + Wouter Verhelst (wouter@debian.org) + + This manual page was written by &dhusername; (&dhemail;) for + the &debian; system (but may be used by others). Permission is + granted to copy, distribute and/or modify this document under the + terms of the GNU General Public License, + version 2, as published by the Free Software Foundation. + + +
diff --git a/nbd-server.c b/nbd-server.c index 3343d9d..6d734b3 100644 --- a/nbd-server.c +++ b/nbd-server.c @@ -261,6 +261,22 @@ typedef struct { is PARAM_BOOL. */ } PARAM; +static inline const char * getcommandname(uint64_t command) { + switch (command) { + case NBD_CMD_READ: + return "NBD_CMD_READ"; + case NBD_CMD_WRITE: + return "NBD_CMD_WRITE"; + case NBD_CMD_DISC: + return "NBD_CMD_DISC"; + case NBD_CMD_FLUSH: + return "NBD_CMD_FLUSH"; + default: + break; + } + return "UNKNOWN"; +} + /** * Check whether a client is allowed to connect. Works with an authorization * file which contains one line per machine, no wildcards. @@ -1458,32 +1474,15 @@ int mainloop(CLIENT *client) { request.from = ntohll(request.from); request.type = ntohl(request.type); command = request.type & NBD_CMD_MASK_COMMAND; - - if (command==NBD_CMD_DISC) { - msg2(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; - } - len = ntohl(request.len); + DEBUG("%s from %llu (%llu) len %d, ", getcommandname(command), + (unsigned long long)request.from, + (unsigned long long)request.from / 512, (unsigned int)len); + if (request.magic != htonl(NBD_REQUEST_MAGIC)) err("Not enough magic."); - if (len > BUFSIZE - sizeof(struct nbd_reply)) { - currlen = BUFSIZE - sizeof(struct nbd_reply); - msg2(LOG_INFO, "oversized request (this is not a problem)"); - } else { - currlen = len; - } - DEBUG("%s from %llu (%llu) len %d, ", command ? "WRITE" : - "READ", (unsigned long long)request.from, - (unsigned long long)request.from / 512, (unsigned int)len); + memcpy(reply.handle, request.handle, sizeof(reply.handle)); if ((command==NBD_CMD_WRITE) || (command==NBD_CMD_READ)) { @@ -1498,9 +1497,28 @@ int mainloop(CLIENT *client) { ERROR(client, reply, EINVAL); continue; } + + currlen = len; + if (currlen > BUFSIZE - sizeof(struct nbd_reply)) { + currlen = BUFSIZE - sizeof(struct nbd_reply); + msg2(LOG_INFO, "oversized request (this is not a problem)"); + } } - if (command==NBD_CMD_WRITE) { + switch (command) { + + case NBD_CMD_DISC: + msg2(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) { readit(client->net, buf, currlen); @@ -1517,15 +1535,14 @@ int mainloop(CLIENT *client) { ERROR(client, reply, errno); continue; } - SEND(client->net, reply); - DEBUG("OK!\n"); len -= currlen; currlen = (len < BUFSIZE) ? len : BUFSIZE; } + SEND(client->net, reply); + DEBUG("OK!\n"); continue; - } - if (command==NBD_CMD_FLUSH) { + case NBD_CMD_FLUSH: DEBUG("fl: "); if (expflush(client)) { DEBUG("Flush failed: %m"); @@ -1535,9 +1552,8 @@ int mainloop(CLIENT *client) { SEND(client->net, reply); DEBUG("OK!\n"); continue; - } - if (command==NBD_CMD_READ) { + case NBD_CMD_READ: DEBUG("exp->buf, "); memcpy(buf, &reply, sizeof(struct nbd_reply)); if (client->transactionlogfd != -1) @@ -1561,9 +1577,11 @@ int mainloop(CLIENT *client) { } DEBUG("OK!\n"); continue; - } - DEBUG ("Ignoring unknown command\n"); + default: + DEBUG ("Ignoring unknown command\n"); + continue; + } } return 0; }