packaging: Remove ExclusiveArch in spec
[platform/upstream/nbd.git] / nbd-helper.h
1 #ifndef NBD_HELPER_H
2 #define NBD_HELPER_H
3
4 #include "nbd.h"
5
6 /* Constants and macros */
7
8 /*
9  * Constants for nbd_request.magic == NBD_TRACELOG_MAGIC
10  */
11 /* 1) stored in nbd_req.type */
12 enum {
13         /* enable/disable logging actual data.
14          * nbd_request.len is the new value (true/false)
15          */
16         NBD_TRACELOG_SET_DATALOG = 1
17 };
18
19 /* 2) Must be in nbd_req.from */
20 #define NBD_TRACELOG_FROM_MAGIC 0x4A93BA39A54F31B6ULL
21
22 /* Functions */
23
24 /**
25  * Translate a command name into human readable form
26  *
27  * @param command The command number (after applying NBD_CMD_MASK_COMMAND)
28  * @return pointer to the command name
29  **/
30 #define ENUM2STR(x)     case x: return #x
31 static inline const char * getcommandname(uint32_t command) {
32         switch (command) {
33         ENUM2STR(NBD_CMD_READ);
34         ENUM2STR(NBD_CMD_WRITE);
35         ENUM2STR(NBD_CMD_DISC);
36         ENUM2STR(NBD_CMD_FLUSH);
37         ENUM2STR(NBD_CMD_TRIM);
38         ENUM2STR(NBD_CMD_CACHE);
39         ENUM2STR(NBD_CMD_WRITE_ZEROES);
40         ENUM2STR(NBD_CMD_BLOCK_STATUS);
41         ENUM2STR(NBD_CMD_RESIZE);
42         default:
43                 return "UNKNOWN";
44         }
45 }
46
47 /**
48  * Translate a tracelog parameter name into human readable form
49  *
50  * @type tracelog parameter number from struct nbd_req.type
51  * @return pointer to the name
52  **/
53 static inline const char * gettracelogname(uint32_t type) {
54         switch (type) {
55         ENUM2STR(NBD_TRACELOG_SET_DATALOG);
56         default:
57                 return "UNKNOWN";
58         }
59 }
60
61 static inline const char *getstructreplname(uint16_t type) {
62         switch(type) {
63         ENUM2STR(NBD_REPLY_TYPE_NONE);
64         ENUM2STR(NBD_REPLY_TYPE_OFFSET_DATA);
65         ENUM2STR(NBD_REPLY_TYPE_OFFSET_HOLE);
66         ENUM2STR(NBD_REPLY_TYPE_BLOCK_STATUS);
67
68         ENUM2STR(NBD_REPLY_TYPE_ERROR);
69         ENUM2STR(NBD_REPLY_TYPE_ERROR_OFFSET);
70         default:
71                 return "UNKNOWN";
72         }
73 }
74
75 #undef ENUM2STR
76
77 #endif //NBD_HELPER_H