[PATCH 1/7] nbd-trdump: Add support for WRITE_ZEROES and TRIM
Support for pretty-printing NBD_CMD_TRIM and NBD_CMD_WRITE_ZEROES is
missing in nbd-trdump.
Thus:
- move the existing getcommandname() helper function into a new
nbd-helper.h header file.
- use the helper function in nbd-trdump
- in nbd-trdump: change ctest from "char *" to "const char *"
Signed-off-by: Manfred Spraul <manfred.spraul@de.bosch.com>
---
nbd-helper.h | 33 +++++++++++++++++++++++++++++++++
nbd-server.c | 26 +-------------------------
nbd-trdump.c | 22 ++++------------------
3 files changed, 38 insertions(+), 43 deletions(-)
create mode 100644 nbd-helper.h
diff --git a/nbd-helper.h b/nbd-helper.h
new file mode 100644
index 0000000..7b7b75d
--- /dev/null
+++ b/nbd-helper.h
@@ -0,0 +1,33 @@
+#ifndef NBD_HELPER_H
+#define NBD_HELPER_H
+
+#include "nbd.h"
+
+/* Functions */
+
+/**
+ * Translate a command name into human readable form
+ *
+ * @param command The command number (after applying NBD_CMD_MASK_COMMAND)
+ * @return pointer to the command name
+ **/
+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";
+ case NBD_CMD_TRIM:
+ return "NBD_CMD_TRIM";
+ case NBD_CMD_WRITE_ZEROES:
+ return "NBD_CMD_WRITE_ZEROES";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+#endif //NBD_HELPER_H
diff --git a/nbd-server.c b/nbd-server.c
index 1eff99d..3c3589e 100644
--- a/nbd-server.c
+++ b/nbd-server.c
@@ -129,6 +129,7 @@
#include "netdb-compat.h"
#include "backend.h"
#include "treefiles.h"
+#include "nbd-helper.h"
#ifdef WITH_SDP
#include <sdp_inet.h>
@@ -285,31 +286,6 @@ struct generic_conf {
gint threads; /**< maximum number of parallel threads we want to run */
};
-/**
- * Translate a command name into human readable form
- *
- * @param command The command number (after applying NBD_CMD_MASK_COMMAND)
- * @return pointer to the command name
- **/
-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";
- case NBD_CMD_TRIM:
- return "NBD_CMD_TRIM";
- case NBD_CMD_WRITE_ZEROES:
- return "NBD_CMD_WRITE_ZEROES";
- default:
- return "UNKNOWN";
- }
-}
-
#if HAVE_GNUTLS
static int writeit_tls(gnutls_session_t s, void *buf, size_t len) {
ssize_t res;
diff --git a/nbd-trdump.c b/nbd-trdump.c
index 1185224..8131698 100644
--- a/nbd-trdump.c
+++ b/nbd-trdump.c
@@ -17,6 +17,7 @@
#undef ISSERVER
#include "cliserv.h"
#include "nbd.h"
+#include "nbd-helper.h"
static inline void doread(int f, void *buf, size_t len) {
ssize_t res;
@@ -42,7 +43,7 @@ int main(int argc, char**argv) {
uint32_t command;
uint32_t len;
uint64_t offset;
- char * ctext;
+ const char * ctext;
int readfd = 0; /* stdin */
if(argc > 1) {
@@ -68,23 +69,8 @@ int main(int argc, char**argv) {
len = ntohl(req.len);
command = ntohl(req.type);
- switch (command & NBD_CMD_MASK_COMMAND) {
- case NBD_CMD_READ:
- ctext="NBD_CMD_READ";
- break;
- case NBD_CMD_WRITE:
- ctext="NBD_CMD_WRITE";
- break;
- case NBD_CMD_DISC:
- ctext="NBD_CMD_DISC";
- break;
- case NBD_CMD_FLUSH:
- ctext="NBD_CMD_FLUSH";
- break;
- default:
- ctext="UNKNOWN";
- break;
- }
+ ctext = getcommandname(command & NBD_CMD_MASK_COMMAND);
+
printf("> H=%016llx C=0x%08x (%13s+%4s) O=%016llx L=%08x\n",
(long long unsigned int) handle,
command,
--
2.33.1
Reply to: