virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
virStoragePoolDefPtr def)
{
- int ret = -1;
- int r = 0;
+ int rc, ret = -1;
virStoragePoolSourcePtr source = &def->source;
virStorageAuthDefPtr authdef = source->auth;
unsigned char *secret_value = NULL;
if (authdef) {
VIR_DEBUG("Using cephx authorization, username: %s", authdef->username);
- if ((r = rados_create(&ptr->cluster, authdef->username)) < 0) {
- virReportSystemError(-r, "%s", _("failed to initialize RADOS"));
+ if ((rc = rados_create(&ptr->cluster, authdef->username)) < 0) {
+ virReportSystemError(-rc, "%s", _("failed to initialize RADOS"));
goto cleanup;
}
}
ptr->starttime = time(0);
- if ((r = rados_connect(ptr->cluster)) < 0) {
- virReportSystemError(-r, _("failed to connect to the RADOS monitor on: %s"),
+ if ((rc = rados_connect(ptr->cluster)) < 0) {
+ virReportSystemError(-rc, _("failed to connect to the RADOS monitor on: %s"),
mon_buff);
goto cleanup;
}
virStoragePoolObjPtr pool)
{
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
- int r = rados_ioctx_create(ptr->cluster, def->source.name, &ptr->ioctx);
- if (r < 0) {
- virReportSystemError(-r, _("failed to create the RBD IoCTX. Does the pool '%s' exist?"),
+ int rc = rados_ioctx_create(ptr->cluster, def->source.name, &ptr->ioctx);
+ if (rc < 0) {
+ virReportSystemError(-rc, _("failed to create the RBD IoCTX. Does the pool '%s' exist?"),
def->source.name);
}
- return r;
+ return rc;
}
static void
const char *volname,
uint64_t *features)
{
- int r;
+ int rc;
- if ((r = rbd_get_features(image, features)) < 0) {
- virReportSystemError(-r, _("failed to get the features of RBD image "
+ if ((rc = rbd_get_features(image, features)) < 0) {
+ virReportSystemError(-rc, _("failed to get the features of RBD image "
"%s"), volname);
return -1;
}
rbd_image_t *image,
rbd_image_info_t *info)
{
- int r;
+ int rc;
size_t allocation = 0;
- if ((r = rbd_diff_iterate2(image, NULL, 0, info->size, 0, 1,
+ if ((rc = rbd_diff_iterate2(image, NULL, 0, info->size, 0, 1,
&virStorageBackendRBDRefreshVolInfoCb,
&allocation)) < 0) {
- virReportSystemError(-r, _("failed to iterate RBD image '%s'"),
+ virReportSystemError(-rc, _("failed to iterate RBD image '%s'"),
vol->name);
return -1;
}
virStoragePoolObjPtr pool,
virStorageBackendRBDStatePtr ptr)
{
- int ret = -1;
+ int rc, ret = -1;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
- int r = 0;
rbd_image_t image = NULL;
rbd_image_info_t info;
uint64_t features;
uint64_t flags;
- if ((r = rbd_open_read_only(ptr->ioctx, vol->name, &image, NULL)) < 0) {
- ret = -r;
- virReportSystemError(-r, _("failed to open the RBD image '%s'"),
+ if ((rc = rbd_open_read_only(ptr->ioctx, vol->name, &image, NULL)) < 0) {
+ ret = -rc;
+ virReportSystemError(-rc, _("failed to open the RBD image '%s'"),
vol->name);
goto cleanup;
}
- if ((r = rbd_stat(image, &info, sizeof(info))) < 0) {
- ret = -r;
- virReportSystemError(-r, _("failed to stat the RBD image '%s'"),
+ if ((rc = rbd_stat(image, &info, sizeof(info))) < 0) {
+ ret = -rc;
+ virReportSystemError(-rc, _("failed to stat the RBD image '%s'"),
vol->name);
goto cleanup;
}
static int
virStorageBackendRBDRefreshPool(virStoragePoolObjPtr pool)
{
- int ret = -1;
- int r = 0;
+ int rc, ret = -1;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStorageBackendRBDStatePtr ptr = NULL;
struct rados_cluster_stat_t clusterstat;
if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
- if ((r = rados_cluster_stat(ptr->cluster, &clusterstat)) < 0) {
- virReportSystemError(-r, "%s", _("failed to stat the RADOS cluster"));
+ if ((rc = rados_cluster_stat(ptr->cluster, &clusterstat)) < 0) {
+ virReportSystemError(-rc, "%s", _("failed to stat the RADOS cluster"));
goto cleanup;
}
- if ((r = rados_ioctx_pool_stat(ptr->ioctx, &poolstat)) < 0) {
- virReportSystemError(-r, _("failed to stat the RADOS pool '%s'"),
+ if ((rc = rados_ioctx_pool_stat(ptr->ioctx, &poolstat)) < 0) {
+ virReportSystemError(-rc, _("failed to stat the RADOS pool '%s'"),
def->source.name);
goto cleanup;
}
vol->name = g_steal_pointer(&names[i]);
- r = volStorageBackendRBDRefreshVolInfo(vol, pool, ptr);
+ rc = volStorageBackendRBDRefreshVolInfo(vol, pool, ptr);
/* It could be that a volume has been deleted through a different route
* then libvirt and that will cause a -ENOENT to be returned.
*
* Do not error out and simply ignore the volume
*/
- if (r < 0) {
- if (r == -ENOENT || r == -ETIMEDOUT)
+ if (rc < 0) {
+ if (rc == -ENOENT || rc == -ETIMEDOUT)
continue;
goto cleanup;
virStoragePoolSourcePtr source,
virStorageVolDefPtr vol)
{
- int ret = -1;
- int r = 0;
+ int rc, ret = -1;
int max_snaps = 128;
int snap_count, protected;
size_t i;
rbd_image_t image = NULL;
g_autofree rbd_snap_info_t *snaps = NULL;
- if ((r = rbd_open(ioctx, vol->name, &image, NULL)) < 0) {
- virReportSystemError(-r, _("failed to open the RBD image '%s'"),
+ if ((rc = rbd_open(ioctx, vol->name, &image, NULL)) < 0) {
+ virReportSystemError(-rc, _("failed to open the RBD image '%s'"),
vol->name);
goto cleanup;
}
source->name, vol->name);
for (i = 0; i < snap_count; i++) {
- if ((r = rbd_snap_is_protected(image, snaps[i].name, &protected)) < 0) {
- virReportSystemError(-r, _("failed to verify if snapshot '%s/%s@%s' is protected"),
+ if ((rc = rbd_snap_is_protected(image, snaps[i].name, &protected)) < 0) {
+ virReportSystemError(-rc, _("failed to verify if snapshot '%s/%s@%s' is protected"),
source->name, vol->name,
snaps[i].name);
goto cleanup;
"unprotected", source->name, vol->name,
snaps[i].name);
- if ((r = rbd_snap_unprotect(image, snaps[i].name)) < 0) {
- virReportSystemError(-r, _("failed to unprotect snapshot '%s/%s@%s'"),
+ if ((rc = rbd_snap_unprotect(image, snaps[i].name)) < 0) {
+ virReportSystemError(-rc, _("failed to unprotect snapshot '%s/%s@%s'"),
source->name, vol->name,
snaps[i].name);
goto cleanup;
VIR_DEBUG("Removing snapshot %s/%s@%s", source->name,
vol->name, snaps[i].name);
- if ((r = rbd_snap_remove(image, snaps[i].name)) < 0) {
- virReportSystemError(-r, _("failed to remove snapshot '%s/%s@%s'"),
+ if ((rc = rbd_snap_remove(image, snaps[i].name)) < 0) {
+ virReportSystemError(-rc, _("failed to remove snapshot '%s/%s@%s'"),
source->name, vol->name,
snaps[i].name);
goto cleanup;
virStorageVolDefPtr vol,
unsigned int flags)
{
- int ret = -1;
- int r = 0;
+ int rc, ret = -1;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStorageBackendRBDStatePtr ptr = NULL;
VIR_DEBUG("Removing volume %s/%s", def->source.name, vol->name);
- r = rbd_remove(ptr->ioctx, vol->name);
- if (r < 0 && (-r) != ENOENT) {
- virReportSystemError(-r, _("failed to remove volume '%s/%s'"),
+ rc = rbd_remove(ptr->ioctx, vol->name);
+ if (rc < 0 && (-rc) != ENOENT) {
+ virReportSystemError(-rc, _("failed to remove volume '%s/%s'"),
def->source.name, vol->name);
goto cleanup;
}
{
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
virStorageBackendRBDStatePtr ptr = NULL;
- int ret = -1;
- int r = 0;
+ int rc, ret = -1;
VIR_DEBUG("Creating RBD image %s/%s with size %llu",
def->source.name, vol->name, vol->target.capacity);
if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
- if ((r = virStorageBackendRBDCreateImage(ptr->ioctx, vol->name,
+ if ((rc = virStorageBackendRBDCreateImage(ptr->ioctx, vol->name,
vol->target.capacity)) < 0) {
- virReportSystemError(-r, _("failed to create volume '%s/%s'"),
+ virReportSystemError(-rc, _("failed to create volume '%s/%s'"),
def->source.name, vol->name);
goto cleanup;
}
uint64_t *stripe_unit,
uint64_t *stripe_count)
{
- int r = 0;
+ int rc = 0;
uint8_t oldformat;
- if ((r = rbd_get_old_format(image, &oldformat)) < 0) {
- virReportSystemError(-r, _("failed to get the format of RBD image %s"),
+ if ((rc = rbd_get_old_format(image, &oldformat)) < 0) {
+ virReportSystemError(-rc, _("failed to get the format of RBD image %s"),
volname);
return -1;
}
if (volStorageBackendRBDGetFeatures(image, volname, features) < 0)
return -1;
- if ((r = rbd_get_stripe_unit(image, stripe_unit)) < 0) {
- virReportSystemError(-r, _("failed to get the stripe unit of RBD image %s"),
+ if ((rc = rbd_get_stripe_unit(image, stripe_unit)) < 0) {
+ virReportSystemError(-rc, _("failed to get the stripe unit of RBD image %s"),
volname);
return -1;
}
- if ((r = rbd_get_stripe_count(image, stripe_count)) < 0) {
- virReportSystemError(-r, _("failed to get the stripe count of RBD image %s"),
+ if ((rc = rbd_get_stripe_count(image, stripe_count)) < 0) {
+ virReportSystemError(-rc, _("failed to get the stripe count of RBD image %s"),
volname);
return -1;
}
char *imgname,
virBufferPtr snapname)
{
- int r = -1;
- int ret = -1;
+ int rc, ret = -1;
int snap_count;
int max_snaps = 128;
size_t i;
rbd_image_info_t info;
g_autofree rbd_snap_info_t *snaps = NULL;
- if ((r = rbd_stat(image, &info, sizeof(info))) < 0) {
- virReportSystemError(-r, _("failed to stat the RBD image %s"),
+ if ((rc = rbd_stat(image, &info, sizeof(info))) < 0) {
+ virReportSystemError(-rc, _("failed to stat the RBD image %s"),
imgname);
goto cleanup;
}
* is available
*/
#if LIBRBD_VERSION_CODE > 265
- r = rbd_diff_iterate2(image, snaps[i].name, 0, info.size, 0, 1,
+ rc = rbd_diff_iterate2(image, snaps[i].name, 0, info.size, 0, 1,
virStorageBackendRBDIterateCb, (void *)&diff);
#else
- r = rbd_diff_iterate(image, snaps[i].name, 0, info.size,
+ rc = rbd_diff_iterate(image, snaps[i].name, 0, info.size,
virStorageBackendRBDIterateCb, (void *)&diff);
#endif
- if (r < 0) {
- virReportSystemError(-r, _("failed to iterate RBD snapshot %s@%s"),
+ if (rc < 0) {
+ virReportSystemError(-rc, _("failed to iterate RBD snapshot %s@%s"),
imgname, snaps[i].name);
goto cleanup;
}
char *imgname,
char *snapname)
{
- int r = -1;
+ int rc = -1;
VIR_DEBUG("Creating RBD snapshot %s@%s", imgname, snapname);
- if ((r = rbd_snap_create(image, snapname)) < 0) {
- virReportSystemError(-r, _("failed to create RBD snapshot %s@%s"),
+ if ((rc = rbd_snap_create(image, snapname)) < 0) {
+ virReportSystemError(-rc, _("failed to create RBD snapshot %s@%s"),
imgname, snapname);
return -1;
}
char *imgname,
char *snapname)
{
- int r = -1;
+ int rc = -1;
int protected;
VIR_DEBUG("Querying if RBD snapshot %s@%s is protected", imgname, snapname);
- if ((r = rbd_snap_is_protected(image, snapname, &protected)) < 0) {
- virReportSystemError(-r, _("failed to verify if RBD snapshot %s@%s "
+ if ((rc = rbd_snap_is_protected(image, snapname, &protected)) < 0) {
+ virReportSystemError(-rc, _("failed to verify if RBD snapshot %s@%s "
"is protected"), imgname, snapname);
return -1;
}
VIR_DEBUG("RBD Snapshot %s@%s is not protected, protecting",
imgname, snapname);
- if ((r = rbd_snap_protect(image, snapname)) < 0) {
- virReportSystemError(-r, _("failed to protect RBD snapshot %s@%s"),
+ if ((rc = rbd_snap_protect(image, snapname)) < 0) {
+ virReportSystemError(-rc, _("failed to protect RBD snapshot %s@%s"),
imgname, snapname);
return -1;
}
char *origvol,
char *newvol)
{
- int r = -1;
- int ret = -1;
+ int rc, ret = -1;
int order = 0;
uint64_t features;
uint64_t stripe_count;
rbd_image_t image = NULL;
g_autofree char *snapname_buff = NULL;
- if ((r = rbd_open(io, origvol, &image, NULL)) < 0) {
- virReportSystemError(-r, _("failed to open the RBD image %s"),
+ if ((rc = rbd_open(io, origvol, &image, NULL)) < 0) {
+ virReportSystemError(-rc, _("failed to open the RBD image %s"),
origvol);
goto cleanup;
}
* RBD snapshots have to be 'protected' before they can be used
* as a parent snapshot for a child image
*/
- if ((r = virStorageBackendRBDSnapshotProtect(image, origvol, snapname_buff)) < 0)
+ if ((rc = virStorageBackendRBDSnapshotProtect(image, origvol, snapname_buff)) < 0)
goto cleanup;
VIR_DEBUG("Performing RBD clone from %s to %s", origvol, newvol);
- if ((r = rbd_clone2(io, origvol, snapname_buff, io, newvol, features,
+ if ((rc = rbd_clone2(io, origvol, snapname_buff, io, newvol, features,
&order, stripe_unit, stripe_count)) < 0) {
- virReportSystemError(-r, _("failed to clone RBD volume %s to %s"),
+ virReportSystemError(-rc, _("failed to clone RBD volume %s to %s"),
origvol, newvol);
goto cleanup;
}
{
virStorageBackendRBDStatePtr ptr = NULL;
rbd_image_t image = NULL;
- int ret = -1;
- int r = 0;
+ int rc, ret = -1;
virCheckFlags(0, -1);
if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
- if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
- virReportSystemError(-r, _("failed to open the RBD image '%s'"),
+ if ((rc = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
+ virReportSystemError(-rc, _("failed to open the RBD image '%s'"),
vol->name);
goto cleanup;
}
- if ((r = rbd_resize(image, capacity)) < 0) {
- virReportSystemError(-r, _("failed to resize the RBD image '%s'"),
+ if ((rc = rbd_resize(image, capacity)) < 0) {
+ virReportSystemError(-rc, _("failed to resize the RBD image '%s'"),
vol->name);
goto cleanup;
}
rbd_image_info_t *info,
uint64_t stripe_count)
{
- int r = -1;
+ int rc;
unsigned long long offset = 0;
unsigned long long length;
g_autofree char *writebuf = NULL;
while (offset < info->size) {
length = MIN((info->size - offset), (info->obj_size * stripe_count));
- if ((r = rbd_write(image, offset, length, writebuf)) < 0) {
- virReportSystemError(-r, _("writing %llu bytes failed on "
+ if ((rc = rbd_write(image, offset, length, writebuf)) < 0) {
+ virReportSystemError(-rc, _("writing %llu bytes failed on "
"RBD image %s at offset %llu"),
length, imgname, offset);
return -1;
rbd_image_info_t *info,
uint64_t stripe_count)
{
- int r = -1;
+ int rc = -1;
unsigned long long offset = 0;
unsigned long long length;
while (offset < info->size) {
length = MIN((info->size - offset), (info->obj_size * stripe_count));
- if ((r = rbd_discard(image, offset, length)) < 0) {
- virReportSystemError(-r, _("discarding %llu bytes failed on "
+ if ((rc = rbd_discard(image, offset, length)) < 0) {
+ virReportSystemError(-rc, _("discarding %llu bytes failed on "
"RBD image %s at offset %llu"),
length, imgname, offset);
return -1;
rbd_image_t image = NULL;
rbd_image_info_t info;
uint64_t stripe_count;
- int r = -1;
- int ret = -1;
+ int rc, ret = -1;
virCheckFlags(0, -1);
if (!ptr)
goto cleanup;
- if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
- virReportSystemError(-r, _("failed to open the RBD image %s"),
+ if ((rc = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
+ virReportSystemError(-rc, _("failed to open the RBD image %s"),
vol->name);
goto cleanup;
}
- if ((r = rbd_stat(image, &info, sizeof(info))) < 0) {
- virReportSystemError(-r, _("failed to stat the RBD image %s"),
+ if ((rc = rbd_stat(image, &info, sizeof(info))) < 0) {
+ virReportSystemError(-rc, _("failed to stat the RBD image %s"),
vol->name);
goto cleanup;
}
- if ((r = rbd_get_stripe_count(image, &stripe_count)) < 0) {
- virReportSystemError(-r, _("failed to get stripe count of RBD image %s"),
+ if ((rc = rbd_get_stripe_count(image, &stripe_count)) < 0) {
+ virReportSystemError(-rc, _("failed to get stripe count of RBD image %s"),
vol->name);
goto cleanup;
}
switch ((virStorageVolWipeAlgorithm) algorithm) {
case VIR_STORAGE_VOL_WIPE_ALG_ZERO:
- r = virStorageBackendRBDVolWipeZero(image, vol->name,
+ rc = virStorageBackendRBDVolWipeZero(image, vol->name,
&info, stripe_count);
break;
case VIR_STORAGE_VOL_WIPE_ALG_TRIM:
- r = virStorageBackendRBDVolWipeDiscard(image, vol->name,
+ rc = virStorageBackendRBDVolWipeDiscard(image, vol->name,
&info, stripe_count);
break;
case VIR_STORAGE_VOL_WIPE_ALG_NNSA:
goto cleanup;
}
- if (r < 0) {
- virReportSystemError(-r, _("failed to wipe RBD image %s"),
+ if (rc < 0) {
+ virReportSystemError(-rc, _("failed to wipe RBD image %s"),
vol->name);
goto cleanup;
}