With this information it's easier for the user to debug what is
going wrong.
---
src/storage/storage_backend_rbd.c | 119 +++++++++++++++++++++----------------
1 file changed, 68 insertions(+), 51 deletions(-)
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 1b35cc4..bd21873 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -51,6 +51,7 @@ static int
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
virStoragePoolObjPtr pool)
{
int ret = -1;
+ int r = 0;
unsigned char *secret_value = NULL;
size_t secret_value_size;
char *rados_key = NULL;
@@ -65,10 +66,10 @@ static int
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
if (pool->def->source.auth.cephx.username != NULL) {
VIR_DEBUG("Using cephx authorization");
- if (rados_create(&ptr->cluster,
- pool->def->source.auth.cephx.username) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to initialize RADOS"));
+ r = rados_create(&ptr->cluster,
pool->def->source.auth.cephx.username);
+ if (r < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to initialize RADOS: %d"), r);
goto cleanup;
}
@@ -198,10 +199,11 @@ static int
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
}
ptr->starttime = time(0);
- if (rados_connect(ptr->cluster) < 0) {
+ r = rados_connect(ptr->cluster);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to connect to the RADOS monitor on: %s"),
- mon_buff);
+ _("failed to connect to the RADOS monitor on: %s: %d"),
+ mon_buff, r);
goto cleanup;
}
@@ -248,18 +250,22 @@ static int volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr
vol,
virStorageBackendRBDStatePtr ptr)
{
int ret = -1;
+ int r = 0;
rbd_image_t image;
- if (rbd_open(ptr->ioctx, vol->name, &image, NULL) < 0) {
+
+ r = rbd_open(ptr->ioctx, vol->name, &image, NULL);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to open the RBD image '%s'"),
- vol->name);
+ _("failed to open the RBD image '%s': %d"),
+ vol->name, r);
return ret;
}
rbd_image_info_t info;
- if (rbd_stat(image, &info, sizeof(info)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to stat the RBD image"));
+ r = rbd_stat(image, &info, sizeof(info));
+ if (r < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to stat the RBD image: %d"), r);
goto cleanup;
}
@@ -297,6 +303,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
size_t max_size = 1024;
int ret = -1;
int len = -1;
+ int r = 0;
char *name, *names = NULL;
virStorageBackendRBDState ptr;
ptr.cluster = NULL;
@@ -306,26 +313,28 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
goto cleanup;
}
- if (rados_ioctx_create(ptr.cluster,
- pool->def->source.name, &ptr.ioctx) < 0) {
+ r = rados_ioctx_create(ptr.cluster, pool->def->source.name, &ptr.ioctx);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to create the RBD IoCTX. Does the pool '%s'
exist?"),
- pool->def->source.name);
+ _("failed to create the RBD IoCTX. Does the pool '%s'
exist?: %d"),
+ pool->def->source.name, r);
goto cleanup;
}
struct rados_cluster_stat_t clusterstat;
- if (rados_cluster_stat(ptr.cluster, &clusterstat) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to stat the RADOS cluster"));
+ r = rados_cluster_stat(ptr.cluster, &clusterstat);
+ if (r < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to stat the RADOS cluster: %d"), r);
goto cleanup;
}
struct rados_pool_stat_t poolstat;
- if (rados_ioctx_pool_stat(ptr.ioctx, &poolstat) < 0) {
+ r = rados_ioctx_pool_stat(ptr.ioctx, &poolstat);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to stat the RADOS pool '%s'"),
- pool->def->source.name);
+ _("failed to stat the RADOS pool '%s': %d"),
+ pool->def->source.name, r);
goto cleanup;
}
@@ -398,6 +407,7 @@ static int virStorageBackendRBDDeleteVol(virConnectPtr conn,
unsigned int flags)
{
int ret = -1;
+ int r = 0;
virStorageBackendRBDState ptr;
ptr.cluster = NULL;
ptr.ioctx = NULL;
@@ -412,19 +422,20 @@ static int virStorageBackendRBDDeleteVol(virConnectPtr conn,
goto cleanup;
}
- if (rados_ioctx_create(ptr.cluster,
- pool->def->source.name, &ptr.ioctx) < 0) {
+ r = rados_ioctx_create(ptr.cluster, pool->def->source.name, &ptr.ioctx);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to create the RBD IoCTX. Does the pool '%s'
exist?"),
- pool->def->source.name);
+ _("failed to create the RBD IoCTX. Does the pool '%s'
exist?: %d"),
+ pool->def->source.name, r);
goto cleanup;
}
- if (rbd_remove(ptr.ioctx, vol->name) < 0) {
+ r = rbd_remove(ptr.ioctx, vol->name);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to remove volume '%s/%s'"),
+ _("failed to remove volume '%s/%s': %d"),
pool->def->source.name,
- vol->name);
+ vol->name, r);
goto cleanup;
}
@@ -488,6 +499,7 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
ptr.cluster = NULL;
ptr.ioctx = NULL;
int ret = -1;
+ int r = 0;
VIR_DEBUG("Creating RBD image %s/%s with size %llu",
pool->def->source.name,
@@ -498,11 +510,11 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0)
goto cleanup;
- if (rados_ioctx_create(ptr.cluster,
- pool->def->source.name, &ptr.ioctx) < 0) {
+ r = rados_ioctx_create(ptr.cluster, pool->def->source.name, &ptr.ioctx);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to create the RBD IoCTX. Does the pool '%s'
exist?"),
- pool->def->source.name);
+ _("failed to create the RBD IoCTX. Does the pool '%s'
exist?: %d"),
+ pool->def->source.name, r);
goto cleanup;
}
@@ -512,11 +524,12 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
goto cleanup;
}
- if (virStorageBackendRBDCreateImage(ptr.ioctx, vol->name, vol->capacity) <
0) {
+ r = virStorageBackendRBDCreateImage(ptr.ioctx, vol->name, vol->capacity);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to create volume '%s/%s'"),
+ _("failed to create volume '%s/%s': %d"),
pool->def->source.name,
- vol->name);
+ vol->name, r);
goto cleanup;
}
@@ -538,16 +551,17 @@ static int virStorageBackendRBDRefreshVol(virConnectPtr conn,
ptr.cluster = NULL;
ptr.ioctx = NULL;
int ret = -1;
+ int r = 0;
if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) {
goto cleanup;
}
- if (rados_ioctx_create(ptr.cluster,
- pool->def->source.name, &ptr.ioctx) < 0) {
+ r = rados_ioctx_create(ptr.cluster, pool->def->source.name, &ptr.ioctx);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to create the RBD IoCTX. Does the pool '%s'
exist?"),
- pool->def->source.name);
+ _("failed to create the RBD IoCTX. Does the pool '%s'
exist?: %d"),
+ pool->def->source.name, r);
goto cleanup;
}
@@ -573,6 +587,7 @@ static int virStorageBackendRBDResizeVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
ptr.ioctx = NULL;
rbd_image_t image = NULL;
int ret = -1;
+ int r = 0;
virCheckFlags(0, -1);
@@ -580,25 +595,27 @@ static int virStorageBackendRBDResizeVol(virConnectPtr conn
ATTRIBUTE_UNUSED,
goto cleanup;
}
- if (rados_ioctx_create(ptr.cluster,
- pool->def->source.name, &ptr.ioctx) < 0) {
+ r = rados_ioctx_create(ptr.cluster, pool->def->source.name, &ptr.ioctx);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to create the RBD IoCTX. Does the pool '%s'
exist?"),
- pool->def->source.name);
+ _("failed to create the RBD IoCTX. Does the pool '%s'
exist?: %d"),
+ pool->def->source.name, r);
goto cleanup;
}
- if (rbd_open(ptr.ioctx, vol->name, &image, NULL) < 0) {
+ r = rbd_open(ptr.ioctx, vol->name, &image, NULL);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to open the RBD image '%s'"),
- vol->name);
+ _("failed to open the RBD image '%s': %d"),
+ vol->name, r);
goto cleanup;
}
- if (rbd_resize(image, capacity) < 0) {
+ r = rbd_resize(image, capacity);
+ if (r < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to resize the RBD image '%s'"),
- vol->name);
+ _("failed to resize the RBD image '%s': %d"),
+ vol->name, r);
goto cleanup;
}
--
1.7.9.5