mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
storage_backend_rbd: check the return value of rados_conf_set
We had a lot of rados_conf_set and check works. Use helper virStorageBackendRBDRADOSConfSet for them. Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
This commit is contained in:
parent
b87a11340f
commit
17879605fe
@ -51,6 +51,23 @@ struct _virStorageBackendRBDState {
|
|||||||
typedef struct _virStorageBackendRBDState virStorageBackendRBDState;
|
typedef struct _virStorageBackendRBDState virStorageBackendRBDState;
|
||||||
typedef virStorageBackendRBDState *virStorageBackendRBDStatePtr;
|
typedef virStorageBackendRBDState *virStorageBackendRBDStatePtr;
|
||||||
|
|
||||||
|
static int
|
||||||
|
virStorageBackendRBDRADOSConfSet(rados_t cluster,
|
||||||
|
const char *option,
|
||||||
|
const char *value)
|
||||||
|
{
|
||||||
|
VIR_DEBUG("Setting RADOS option '%s' to '%s'",
|
||||||
|
option, value);
|
||||||
|
if (rados_conf_set(cluster, option, value) < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("failed to set RADOS option: %s"),
|
||||||
|
option);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
||||||
virConnectPtr conn,
|
virConnectPtr conn,
|
||||||
@ -93,20 +110,13 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
|||||||
if (!(rados_key = virStringEncodeBase64(secret_value, secret_value_size)))
|
if (!(rados_key = virStringEncodeBase64(secret_value, secret_value_size)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Found cephx key: %s", rados_key);
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
if (rados_conf_set(ptr->cluster, "key", rados_key) < 0) {
|
"key", rados_key) < 0)
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("failed to set RADOS option: %s"),
|
|
||||||
"rados_key");
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (rados_conf_set(ptr->cluster, "auth_supported", "cephx") < 0) {
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
"auth_supported", "cephx") < 0)
|
||||||
_("failed to set RADOS option: %s"),
|
|
||||||
"auth_supported");
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
VIR_DEBUG("Not using cephx authorization");
|
VIR_DEBUG("Not using cephx authorization");
|
||||||
if (rados_create(&ptr->cluster, NULL) < 0) {
|
if (rados_create(&ptr->cluster, NULL) < 0) {
|
||||||
@ -114,12 +124,9 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
|||||||
_("failed to create the RADOS cluster"));
|
_("failed to create the RADOS cluster"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (rados_conf_set(ptr->cluster, "auth_supported", "none") < 0) {
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
"auth_supported", "none") < 0)
|
||||||
_("failed to set RADOS option: %s"),
|
|
||||||
"auth_supported");
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration",
|
VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration",
|
||||||
@ -145,35 +152,40 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
mon_buff = virBufferContentAndReset(&mon_host);
|
mon_buff = virBufferContentAndReset(&mon_host);
|
||||||
VIR_DEBUG("RADOS mon_host has been set to: %s", mon_buff);
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
if (rados_conf_set(ptr->cluster, "mon_host", mon_buff) < 0) {
|
"mon_host",
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
mon_buff) < 0)
|
||||||
_("failed to set RADOS option: %s"),
|
|
||||||
"mon_host");
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set timeout options for librados.
|
* Set timeout options for librados.
|
||||||
* In case the Ceph cluster is down libvirt won't block forever.
|
* In case the Ceph cluster is down libvirt won't block forever.
|
||||||
* Operations in librados will return -ETIMEDOUT when the timeout is reached.
|
* Operations in librados will return -ETIMEDOUT when the timeout is reached.
|
||||||
*/
|
*/
|
||||||
VIR_DEBUG("Setting RADOS option client_mount_timeout to %s", client_mount_timeout);
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
rados_conf_set(ptr->cluster, "client_mount_timeout", client_mount_timeout);
|
"client_mount_timeout",
|
||||||
|
client_mount_timeout) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Setting RADOS option rados_mon_op_timeout to %s", mon_op_timeout);
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
rados_conf_set(ptr->cluster, "rados_mon_op_timeout", mon_op_timeout);
|
"rados_mon_op_timeout",
|
||||||
|
mon_op_timeout) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Setting RADOS option rados_osd_op_timeout to %s", osd_op_timeout);
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
rados_conf_set(ptr->cluster, "rados_osd_op_timeout", osd_op_timeout);
|
"rados_osd_op_timeout",
|
||||||
|
osd_op_timeout) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Librbd supports creating RBD format 2 images. We no longer have to invoke
|
* Librbd supports creating RBD format 2 images. We no longer have to invoke
|
||||||
* rbd_create3(), we can tell librbd to default to format 2.
|
* rbd_create3(), we can tell librbd to default to format 2.
|
||||||
* This leaves us to simply use rbd_create() and use the default behavior of librbd
|
* This leaves us to simply use rbd_create() and use the default behavior of librbd
|
||||||
*/
|
*/
|
||||||
VIR_DEBUG("Setting RADOS option rbd_default_format to %s", rbd_default_format);
|
if (virStorageBackendRBDRADOSConfSet(ptr->cluster,
|
||||||
rados_conf_set(ptr->cluster, "rbd_default_format", rbd_default_format);
|
"rbd_default_format",
|
||||||
|
rbd_default_format) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
ptr->starttime = time(0);
|
ptr->starttime = time(0);
|
||||||
if ((r = rados_connect(ptr->cluster)) < 0) {
|
if ((r = rados_connect(ptr->cluster)) < 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user