4 * Takes an nbd transaction log file on stdin and translates it into something
12 #include <sys/types.h>
19 static inline void doread(int f, void *buf, size_t len) {
23 if((res=read(f, buf, len)) <=0) {
26 perror ("Error reading transactions");
34 int main(int argc, char**argv) {
35 struct nbd_request req;
44 int readfd = 0; /* stdin */
48 if(strcmp(argv[1], "--help") && strcmp(argv[1], "-h")) {
49 printf("E: unknown option %s.\n", argv[1]);
52 printf("This is nbd-trdump, part of nbd %s.\n", PACKAGE_VERSION);
53 printf("Use: %s < transactionlog\n", argv[0]);
58 /* Read a request or reply from the transaction file */
59 doread(readfd, &magic, sizeof(magic));
62 case NBD_REQUEST_MAGIC:
63 doread(readfd, sizeof(magic)+(char *)(&req), sizeof(struct nbd_request)-sizeof(magic));
64 handle = ntohll(*((long long int *)(req.handle)));
65 offset = ntohll(req.from);
67 command = ntohl(req.type);
69 switch (command & NBD_CMD_MASK_COMMAND) {
74 ctext="NBD_CMD_WRITE";
80 ctext="NBD_CMD_FLUSH";
86 printf("> H=%016llx C=0x%08x (%13s+%4s) O=%016llx L=%08x\n",
87 (long long unsigned int) handle,
90 (command & NBD_CMD_FLAG_FUA)?"FUA":"NONE",
91 (long long unsigned int) offset,
96 doread(readfd, sizeof(magic)+(char *)(&rep), sizeof(struct nbd_reply)-sizeof(magic));
97 handle = ntohll(*((long long int *)(rep.handle)));
98 error = ntohl(rep.error);
100 printf("< H=%016llx E=0x%08x\n",
101 (long long unsigned int) handle,
106 printf("? Unknown transaction type %08x\n",magic);