]>
Commit | Line | Data |
---|---|---|
27bfc7c6 DM |
1 | #include "EXTERN.h" |
2 | #include "perl.h" | |
3 | #include "XSUB.h" | |
4 | ||
5 | #include "ppport.h" | |
6 | ||
7 | #include <rados/librados.h> | |
8 | ||
4bf97564 DM |
9 | #define DEBUG_RADOS 0 |
10 | ||
11 | #define DPRINTF(fmt, ...)\ | |
12 | do { if (DEBUG_RADOS) { printf("debug: " fmt, ## __VA_ARGS__); } } while (0) | |
13 | ||
27bfc7c6 DM |
14 | MODULE = PVE::RADOS PACKAGE = PVE::RADOS |
15 | ||
612779b1 DM |
16 | rados_t |
17 | pve_rados_create() | |
27bfc7c6 DM |
18 | PROTOTYPE: |
19 | CODE: | |
20 | { | |
21 | rados_t clu = NULL; | |
22 | int ret = rados_create(&clu, NULL); | |
23 | ||
24 | if (ret == 0) | |
25 | RETVAL = clu; | |
26 | else { | |
4bf97564 | 27 | die("rados_create failed - %s\n", strerror(-ret)); |
27bfc7c6 DM |
28 | RETVAL = NULL; |
29 | } | |
30 | } | |
31 | OUTPUT: RETVAL | |
32 | ||
94ea1b8f | 33 | void |
612779b1 DM |
34 | pve_rados_conf_set(cluster, key, value) |
35 | rados_t cluster | |
36 | char *key | |
37 | char *value | |
38 | PROTOTYPE: $$$ | |
39 | CODE: | |
40 | { | |
4bf97564 DM |
41 | DPRINTF("pve_rados_conf_set %s = %s\n", key, value); |
42 | ||
94ea1b8f DM |
43 | int res = rados_conf_set(cluster, key, value); |
44 | if (res < 0) { | |
45 | die("rados_conf_set failed - %s\n", strerror(-res)); | |
46 | } | |
612779b1 | 47 | } |
612779b1 | 48 | |
94ea1b8f DM |
49 | void |
50 | pve_rados_connect(cluster) | |
27bfc7c6 DM |
51 | rados_t cluster |
52 | PROTOTYPE: $ | |
53 | CODE: | |
54 | { | |
4bf97564 DM |
55 | DPRINTF("pve_rados_connect\n"); |
56 | ||
9539bd37 DM |
57 | int res = rados_conf_read_file(cluster, NULL); |
58 | if (res < 0) { | |
59 | die("rados_conf_read_file failed - %s\n", strerror(-res)); | |
60 | } | |
27bfc7c6 | 61 | |
9539bd37 | 62 | res = rados_connect(cluster); |
94ea1b8f DM |
63 | if (res < 0) { |
64 | die("rados_connect failed - %s\n", strerror(-res)); | |
27bfc7c6 DM |
65 | } |
66 | } | |
27bfc7c6 DM |
67 | |
68 | void | |
69 | pve_rados_shutdown(cluster) | |
70 | rados_t cluster | |
71 | PROTOTYPE: $ | |
72 | CODE: | |
73 | { | |
4bf97564 | 74 | DPRINTF("pve_rados_shutdown"); |
27bfc7c6 DM |
75 | rados_shutdown(cluster); |
76 | } | |
77 | ||
78 | SV * | |
79 | pve_rados_mon_command(cluster, cmds) | |
80 | rados_t cluster | |
81 | AV *cmds | |
82 | PROTOTYPE: $$ | |
83 | CODE: | |
84 | { | |
85 | const char *cmd[64]; | |
86 | size_t cmdlen = 0; | |
87 | ||
88 | char *outbuf =NULL; | |
89 | size_t outbuflen = 0; | |
90 | char *outs = NULL; | |
91 | size_t outslen = 0; | |
92 | ||
93 | SV *arg; | |
94 | ||
95 | while ((arg = av_pop(cmds)) && (arg != &PL_sv_undef)) { | |
96 | if (cmdlen >= 63) { | |
97 | die("too many arguments"); | |
98 | } | |
99 | cmd[cmdlen] = SvPV_nolen(arg); | |
4bf97564 | 100 | DPRINTF("pve_rados_mon_command%zd %s\n", cmdlen, cmd[cmdlen]); |
27bfc7c6 DM |
101 | cmdlen++; |
102 | } | |
103 | ||
104 | int ret = rados_mon_command(cluster, cmd, cmdlen, | |
105 | NULL, 0, | |
106 | &outbuf, &outbuflen, | |
107 | &outs, &outslen); | |
108 | ||
109 | if (ret < 0) { | |
4bf97564 DM |
110 | char msg[4096]; |
111 | snprintf(msg, sizeof(msg), "mon_command failed - %s\n", outs); | |
27bfc7c6 | 112 | rados_buffer_free(outs); |
4bf97564 | 113 | die(msg); |
27bfc7c6 DM |
114 | } |
115 | ||
27bfc7c6 DM |
116 | RETVAL = newSVpv(outbuf, outbuflen); |
117 | ||
118 | rados_buffer_free(outbuf); | |
119 | } | |
120 | OUTPUT: RETVAL | |
121 | ||
122 | HV * | |
123 | pve_rados_cluster_stat(cluster) | |
124 | rados_t cluster | |
125 | PROTOTYPE: $ | |
126 | CODE: | |
127 | { | |
128 | struct rados_cluster_stat_t result; | |
4bf97564 DM |
129 | |
130 | DPRINTF("pve_rados_cluster_stat"); | |
131 | ||
27bfc7c6 DM |
132 | int ret = rados_cluster_stat(cluster, &result); |
133 | ||
134 | if(ret != 0) { | |
135 | warn("rados_cluster_stat failed (ret=%d)\n", ret); | |
136 | XSRETURN_UNDEF; | |
137 | } | |
138 | HV * rh = (HV *)sv_2mortal((SV *)newHV()); | |
139 | ||
eeba774b DM |
140 | (void)hv_store(rh, "kb", 2, newSViv(result.kb), 0); |
141 | (void)hv_store(rh, "kb_used", 7, newSViv(result.kb_used), 0); | |
142 | (void)hv_store(rh, "kb_avail", 8, newSViv(result.kb_avail), 0); | |
143 | (void)hv_store(rh, "num_objects", 11, newSViv(result.num_objects), 0); | |
27bfc7c6 DM |
144 | |
145 | RETVAL = rh; | |
146 | } | |
147 | OUTPUT: RETVAL |