static int
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
- virConnectPtr conn,
virStoragePoolSourcePtr source)
{
int ret = -1;
const char *mon_op_timeout = "30";
const char *osd_op_timeout = "30";
const char *rbd_default_format = "2";
+ virConnectPtr conn = NULL;
if (authdef) {
VIR_DEBUG("Using cephx authorization, username: %s", authdef->username);
goto cleanup;
}
- if (!conn) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("'ceph' authentication not supported "
- "for autostarted pools"));
+ conn = virGetConnectSecret();
+ if (!conn)
return -1;
- }
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
VIR_SECRET_USAGE_TYPE_CEPH,
VIR_DISPOSE_N(secret_value, secret_value_size);
VIR_DISPOSE_STRING(rados_key);
+ virObjectUnref(conn);
virBufferFreeAndReset(&mon_host);
VIR_FREE(mon_buff);
return ret;
static virStorageBackendRBDStatePtr
-virStorageBackendRBDNewState(virConnectPtr conn,
- virStoragePoolObjPtr pool)
+virStorageBackendRBDNewState(virStoragePoolObjPtr pool)
{
virStorageBackendRBDStatePtr ptr;
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
if (VIR_ALLOC(ptr) < 0)
return NULL;
- if (virStorageBackendRBDOpenRADOSConn(ptr, conn, &def->source) < 0)
+ if (virStorageBackendRBDOpenRADOSConn(ptr, &def->source) < 0)
goto error;
if (virStorageBackendRBDOpenIoCTX(ptr, pool) < 0)
}
static int
-virStorageBackendRBDRefreshPool(virConnectPtr conn,
+virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool)
{
size_t max_size = 1024;
struct rados_cluster_stat_t clusterstat;
struct rados_pool_stat_t poolstat;
- if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
+ if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
if ((r = rados_cluster_stat(ptr->cluster, &clusterstat)) < 0) {
}
static int
-virStorageBackendRBDDeleteVol(virConnectPtr conn,
+virStorageBackendRBDDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
unsigned int flags)
if (flags & VIR_STORAGE_VOL_DELETE_ZEROED)
VIR_WARN("%s", "This storage backend does not support zeroed removal of volumes");
- if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
+ if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
if (flags & VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS) {
}
static int
-virStorageBackendRBDBuildVol(virConnectPtr conn,
+virStorageBackendRBDBuildVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
unsigned int flags)
goto cleanup;
}
- if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
+ if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
if ((r = virStorageBackendRBDCreateImage(ptr->ioctx, vol->name,
}
static int
-virStorageBackendRBDBuildVolFrom(virConnectPtr conn,
+virStorageBackendRBDBuildVolFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
virStorageVolDefPtr newvol,
virStorageVolDefPtr origvol,
virCheckFlags(0, -1);
- if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
+ if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
if ((virStorageBackendRBDCloneImage(ptr->ioctx, origvol->name,
}
static int
-virStorageBackendRBDRefreshVol(virConnectPtr conn,
+virStorageBackendRBDRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
virStorageVolDefPtr vol)
{
virStorageBackendRBDStatePtr ptr = NULL;
int ret = -1;
- if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
+ if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
if (volStorageBackendRBDRefreshVolInfo(vol, pool, ptr) < 0)
virCheckFlags(0, -1);
- if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
+ if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
}
static int
-virStorageBackendRBDVolWipe(virConnectPtr conn,
+virStorageBackendRBDVolWipe(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
unsigned int algorithm,
VIR_DEBUG("Wiping RBD image %s/%s", def->source.name, vol->name);
- if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
+ if (!(ptr = virStorageBackendRBDNewState(pool)))
goto cleanup;
if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
_("unable to generate uuid"));
return -1;
}
- tmp = conn->secretDriver->secretLookupByUUID(conn, uuid);
+ tmp = virSecretLookupByUUID(conn, uuid);
if (tmp == NULL)
return 0;
}
static int
-virStorageGenerateQcowEncryption(virConnectPtr conn,
- virStorageVolDefPtr vol)
+virStorageGenerateQcowEncryption(virStorageVolDefPtr vol)
{
virSecretDefPtr def = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
char *xml;
unsigned char value[VIR_STORAGE_QCOW_PASSPHRASE_SIZE];
int ret = -1;
+ virConnectPtr conn = NULL;
- if (conn->secretDriver == NULL ||
- conn->secretDriver->secretLookupByUUID == NULL ||
- conn->secretDriver->secretDefineXML == NULL ||
- conn->secretDriver->secretSetValue == NULL) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("secret storage not supported"));
- goto cleanup;
- }
+ conn = virGetConnectSecret();
+ if (!conn)
+ return -1;
enc = vol->target.encryption;
if (enc->nsecrets != 0) {
if (xml == NULL)
goto cleanup;
- secret = conn->secretDriver->secretDefineXML(conn, xml, 0);
+ secret = virSecretDefineXML(conn, xml, 0);
if (secret == NULL) {
VIR_FREE(xml);
goto cleanup;
if (virStorageGenerateQcowPassphrase(value) < 0)
goto cleanup;
- if (conn->secretDriver->secretSetValue(secret, value, sizeof(value), 0) < 0)
+ if (virSecretSetValue(secret, value, sizeof(value), 0) < 0)
goto cleanup;
enc_secret->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
cleanup:
if (secret != NULL) {
- if (ret != 0 &&
- conn->secretDriver->secretUndefine != NULL)
- conn->secretDriver->secretUndefine(secret);
+ if (ret != 0)
+ virSecretUndefine(secret);
virObjectUnref(secret);
}
+ virObjectUnref(conn);
virBufferFreeAndReset(&buf);
virSecretDefFree(def);
VIR_FREE(enc_secret);
static int
storageBackendCreateQemuImgCheckEncryption(int format,
const char *type,
- virConnectPtr conn,
virStorageVolDefPtr vol)
{
virStorageEncryptionPtr enc = vol->target.encryption;
}
if (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT ||
enc->nsecrets == 0) {
- if (virStorageGenerateQcowEncryption(conn, vol) < 0)
+ if (virStorageGenerateQcowEncryption(vol) < 0)
return -1;
}
} else if (format == VIR_STORAGE_FILE_RAW) {
* volume definitions and imgformat
*/
virCommandPtr
-virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
- virStoragePoolObjPtr pool,
+virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
unsigned int flags,
if (info.encryption &&
storageBackendCreateQemuImgCheckEncryption(info.format, type,
- conn, vol) < 0)
+ vol) < 0)
return NULL;
static char *
-storageBackendCreateQemuImgSecretPath(virConnectPtr conn,
- virStoragePoolObjPtr pool,
+storageBackendCreateQemuImgSecretPath(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol)
{
virStorageEncryptionPtr enc = vol->target.encryption;
int fd = -1;
uint8_t *secret = NULL;
size_t secretlen = 0;
+ virConnectPtr conn = NULL;
if (!enc) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
return NULL;
}
- if (!conn || !conn->secretDriver ||
- !conn->secretDriver->secretLookupByUUID ||
- !conn->secretDriver->secretLookupByUsage ||
- !conn->secretDriver->secretGetValue) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("unable to look up encryption secret"));
+ conn = virGetConnectSecret();
+ if (!conn)
return NULL;
- }
if (!(secretPath = virStoragePoolObjBuildTempFilePath(pool, vol)))
goto cleanup;
}
cleanup:
+ virObjectUnref(conn);
VIR_DISPOSE_N(secret, secretlen);
VIR_FORCE_CLOSE(fd);
static int
-storageBackendCreateQemuImg(virConnectPtr conn,
+storageBackendCreateQemuImg(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
vol->target.encryption &&
vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
if (!(secretPath =
- storageBackendCreateQemuImgSecretPath(conn, pool, vol)))
+ storageBackendCreateQemuImgSecretPath(pool, vol)))
goto cleanup;
}
- cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, pool, vol, inputvol,
+ cmd = virStorageBackendCreateQemuImgCmdFromVol(pool, vol, inputvol,
flags, create_tool,
imgformat, secretPath);
if (!cmd)
/**
* virStorageBackendCreateVolUsingQemuImg
- * @conn: Connection pointer
* @pool: Storage Pool Object
* @vol: Volume definition
* @inputvol: Volume to use for creation
* Returns: 0 on success, -1 on failure.
*/
int
-virStorageBackendCreateVolUsingQemuImg(virConnectPtr conn,
- virStoragePoolObjPtr pool,
+virStorageBackendCreateVolUsingQemuImg(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
unsigned int flags)
changeFormat = true;
}
- ret = storageBackendCreateQemuImg(conn, pool, vol, inputvol, flags);
+ ret = storageBackendCreateQemuImg(NULL, pool, vol, inputvol, flags);
if (changeFormat)
vol->target.format = VIR_STORAGE_FILE_NONE;
/* storageBackendLoadDefaultSecrets:
- * @conn: Connection pointer to fetch secret
* @vol: volume being refreshed
*
* If the volume had a secret generated, we need to regenerate the
* -1 on failures w/ error message set
*/
static int
-storageBackendLoadDefaultSecrets(virConnectPtr conn,
- virStorageVolDefPtr vol)
+storageBackendLoadDefaultSecrets(virStorageVolDefPtr vol)
{
virSecretPtr sec;
virStorageEncryptionSecretPtr encsec = NULL;
+ virConnectPtr conn = NULL;
if (!vol->target.encryption || vol->target.encryption->nsecrets != 0)
return 0;
+ conn = virGetConnectSecret();
+ if (!conn)
+ return -1;
+
/* The encryption secret for qcow2 and luks volumes use the path
* to the volume, so look for a secret with the path. If not found,
* then we cannot generate the secret after a refresh (or restart).
* a usage string that although matched with the secret usage string,
* didn't contain the path to the volume. We won't error in that case,
* but we also cannot find the secret. */
- if (!(sec = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_VOLUME,
- vol->target.path)))
+ sec = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_VOLUME,
+ vol->target.path);
+ virObjectUnref(conn);
+ if (!sec)
return 0;
if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
* Update info about a volume's capacity/allocation
*/
int
-virStorageBackendVolRefreshLocal(virConnectPtr conn,
+virStorageBackendVolRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
virStorageVolDefPtr vol)
{
return ret;
/* Load any secrets if possible */
- return storageBackendLoadDefaultSecrets(conn, vol);
+ return storageBackendLoadDefaultSecrets(vol);
}
static int
-storageBackendResizeQemuImg(virConnectPtr conn,
- virStoragePoolObjPtr pool,
+storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
unsigned long long capacity)
{
else
type = virStorageFileFormatTypeToString(vol->target.format);
- storageBackendLoadDefaultSecrets(conn, vol);
+ storageBackendLoadDefaultSecrets(vol);
if (storageBackendCreateQemuImgCheckEncryption(vol->target.format,
- type, NULL, vol) < 0)
+ type, vol) < 0)
goto cleanup;
if (!(secretPath =
- storageBackendCreateQemuImgSecretPath(conn, pool, vol)))
+ storageBackendCreateQemuImgSecretPath(pool, vol)))
goto cleanup;
if (virAsprintf(&secretAlias, "%s_luks0", vol->name) < 0)
* Resize a volume
*/
int
-virStorageBackendVolResizeLocal(virConnectPtr conn,
+virStorageBackendVolResizeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol,
unsigned long long capacity,
return -1;
}
- return storageBackendResizeQemuImg(conn, pool, vol, capacity);
+ return storageBackendResizeQemuImg(pool, vol, capacity);
} else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
return storagePloopResize(vol, capacity);
} else {
return -1;
}
- return storageBackendResizeQemuImg(conn, pool, vol, capacity);
+ return storageBackendResizeQemuImg(pool, vol, capacity);
}
}