]> git.proxmox.com Git - librados2-perl.git/commitdiff
avoid memory leak, add debug helper DPRINTF
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 20 Jan 2014 07:35:11 +0000 (08:35 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 20 Jan 2014 07:35:11 +0000 (08:35 +0100)
RADOS.xs

index fa472c4afdf03f76618e11f9d35fd6f87aa664c5..438bcb716510687c9e7c375a80033e9ee161eb61 100644 (file)
--- a/RADOS.xs
+++ b/RADOS.xs
@@ -6,6 +6,11 @@
 
 #include <rados/librados.h>
 
+#define DEBUG_RADOS 0
+
+#define DPRINTF(fmt, ...)\
+       do { if (DEBUG_RADOS) { printf("debug: " fmt, ## __VA_ARGS__); } } while (0)
+
 MODULE = PVE::RADOS            PACKAGE = PVE::RADOS
 
 rados_t 
@@ -19,7 +24,7 @@ CODE:
     if (ret == 0)
         RETVAL = clu;
     else {
-        warn("rados_create failed (ret=%d)\n", ret);
+        die("rados_create failed - %s\n", strerror(-ret));
         RETVAL = NULL;
     }
 }
@@ -33,20 +38,22 @@ char *value
 PROTOTYPE: $$$
 CODE:
 {
+    DPRINTF("pve_rados_conf_set %s = %s\n", key, value);
+
     int res = rados_conf_set(cluster, key, value);
     if (res < 0) {              
         die("rados_conf_set failed - %s\n", strerror(-res));
     }
 }
 
-
-
 void
 pve_rados_connect(cluster) 
 rados_t cluster
 PROTOTYPE: $
 CODE:
 {
+    DPRINTF("pve_rados_connect\n");
+
     rados_conf_read_file(cluster, NULL);
  
     int res = rados_connect(cluster);
@@ -61,6 +68,7 @@ rados_t cluster
 PROTOTYPE: $
 CODE:
 {
+    DPRINTF("pve_rados_shutdown");
     rados_shutdown(cluster);
 }
 
@@ -86,6 +94,7 @@ CODE:
             die("too many arguments");
         }
         cmd[cmdlen] = SvPV_nolen(arg);
+        DPRINTF("pve_rados_mon_command%zd %s\n", cmdlen, cmd[cmdlen]);
         cmdlen++;
     } 
 
@@ -95,8 +104,10 @@ CODE:
                                 &outs, &outslen);
 
     if (ret < 0) {
-        die("mon_command failed - %s\n", outs);
+        char msg[4096];
+        snprintf(msg, sizeof(msg), "mon_command failed - %s\n", outs);
         rados_buffer_free(outs);
+        die(msg);
     }
  
     RETVAL = newSVpv(outbuf, outbuflen);
@@ -112,6 +123,9 @@ PROTOTYPE: $
 CODE:
 {
     struct rados_cluster_stat_t result;
+
+    DPRINTF("pve_rados_cluster_stat");
+
     int ret = rados_cluster_stat(cluster, &result);
   
     if(ret != 0) {