]> git.proxmox.com Git - librados2-perl.git/blame - RADOS.xs
bump version to 1.4.1
[librados2-perl.git] / RADOS.xs
CommitLineData
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
14MODULE = PVE::RADOS PACKAGE = PVE::RADOS
15
fb22f3c5 16rados_t
c0a9abbd
AA
17pve_rados_create(user)
18SV *user
19PROTOTYPE: $
27bfc7c6 20CODE:
fb22f3c5 21{
c0a9abbd 22 char *u = NULL;
fb22f3c5 23 rados_t clu = NULL;
c0a9abbd
AA
24
25 if (SvOK(user)) {
26 u = SvPV_nolen(user);
27 }
28
29 int ret = rados_create(&clu, u);
fb22f3c5 30
27bfc7c6
DM
31 if (ret == 0)
32 RETVAL = clu;
33 else {
4bf97564 34 die("rados_create failed - %s\n", strerror(-ret));
27bfc7c6
DM
35 RETVAL = NULL;
36 }
37}
38OUTPUT: RETVAL
39
94ea1b8f 40void
fb22f3c5 41pve_rados_conf_set(cluster, key, value)
612779b1
DM
42rados_t cluster
43char *key
44char *value
45PROTOTYPE: $$$
46CODE:
47{
4bf97564
DM
48 DPRINTF("pve_rados_conf_set %s = %s\n", key, value);
49
94ea1b8f 50 int res = rados_conf_set(cluster, key, value);
fb22f3c5 51 if (res < 0) {
94ea1b8f
DM
52 die("rados_conf_set failed - %s\n", strerror(-res));
53 }
612779b1 54}
612779b1 55
94ea1b8f 56void
eb351948 57pve_rados_conf_read_file(cluster, path)
27bfc7c6 58rados_t cluster
eb351948
AA
59SV *path
60PROTOTYPE: $$
27bfc7c6
DM
61CODE:
62{
eb351948 63 char *p = NULL;
4bf97564 64
eb351948
AA
65 if (SvOK(path)) {
66 p = SvPV_nolen(path);
67 }
68
69 DPRINTF("pve_rados_conf_read_file %s\n", p);
70
71 int res = rados_conf_read_file(cluster, p);
9539bd37
DM
72 if (res < 0) {
73 die("rados_conf_read_file failed - %s\n", strerror(-res));
74 }
eb351948
AA
75}
76
77void
78pve_rados_connect(cluster)
79rados_t cluster
80PROTOTYPE: $
81CODE:
82{
83 DPRINTF("pve_rados_connect\n");
fb22f3c5 84
eb351948 85 int res = rados_connect(cluster);
94ea1b8f
DM
86 if (res < 0) {
87 die("rados_connect failed - %s\n", strerror(-res));
27bfc7c6
DM
88 }
89}
27bfc7c6
DM
90
91void
fb22f3c5 92pve_rados_shutdown(cluster)
27bfc7c6
DM
93rados_t cluster
94PROTOTYPE: $
95CODE:
96{
4bf97564 97 DPRINTF("pve_rados_shutdown");
27bfc7c6
DM
98 rados_shutdown(cluster);
99}
100
f65e5245 101HV *
fb22f3c5 102pve_rados_mon_command(cluster, cmds)
27bfc7c6
DM
103rados_t cluster
104AV *cmds
105PROTOTYPE: $$
106CODE:
107{
108 const char *cmd[64];
109 size_t cmdlen = 0;
110
111 char *outbuf =NULL;
112 size_t outbuflen = 0;
113 char *outs = NULL;
114 size_t outslen = 0;
115
116 SV *arg;
117
118 while ((arg = av_pop(cmds)) && (arg != &PL_sv_undef)) {
119 if (cmdlen >= 63) {
120 die("too many arguments");
121 }
122 cmd[cmdlen] = SvPV_nolen(arg);
4bf97564 123 DPRINTF("pve_rados_mon_command%zd %s\n", cmdlen, cmd[cmdlen]);
27bfc7c6 124 cmdlen++;
fb22f3c5 125 }
27bfc7c6 126
9f08da02
TL
127 int ret = rados_mon_command(
128 cluster,
129 cmd,
130 cmdlen,
131 NULL,
132 0,
133 &outbuf,
134 &outbuflen,
135 &outs,
136 &outslen
137 );
27bfc7c6 138
f65e5245 139 HV * rh = (HV *)sv_2mortal((SV *)newHV());
fb22f3c5 140
f65e5245
AL
141 (void)hv_store(rh, "return_code", 11, newSViv(ret), 0);
142 (void)hv_store(rh, "status_message", 14, newSVpv(outs, outslen), 0);
143 (void)hv_store(rh, "data", 4, newSVpv(outbuf, outbuflen), 0);
144 RETVAL = rh;
27bfc7c6
DM
145
146 rados_buffer_free(outbuf);
43ab5a2c 147 rados_buffer_free(outs);
27bfc7c6
DM
148}
149OUTPUT: RETVAL
150
fb22f3c5
AA
151HV *
152pve_rados_cluster_stat(cluster)
27bfc7c6
DM
153rados_t cluster
154PROTOTYPE: $
155CODE:
156{
157 struct rados_cluster_stat_t result;
4bf97564
DM
158
159 DPRINTF("pve_rados_cluster_stat");
160
27bfc7c6 161 int ret = rados_cluster_stat(cluster, &result);
fb22f3c5 162
27bfc7c6
DM
163 if(ret != 0) {
164 warn("rados_cluster_stat failed (ret=%d)\n", ret);
165 XSRETURN_UNDEF;
166 }
167 HV * rh = (HV *)sv_2mortal((SV *)newHV());
168
eeba774b
DM
169 (void)hv_store(rh, "kb", 2, newSViv(result.kb), 0);
170 (void)hv_store(rh, "kb_used", 7, newSViv(result.kb_used), 0);
171 (void)hv_store(rh, "kb_avail", 8, newSViv(result.kb_avail), 0);
172 (void)hv_store(rh, "num_objects", 11, newSViv(result.num_objects), 0);
27bfc7c6
DM
173
174 RETVAL = rh;
175}
176OUTPUT: RETVAL