mirror of https://gitee.com/openkylin/libvirt.git
storage: open secret driver connection at time of use
Instead of passing around a virConnectPtr object, just open a connection to the secret driver at time of use. Opening connections on demand will be beneficial when the secret driver is in a separate daemon. It also solves the problem that a number of callers just pass in a NULL connection today which prevents secret lookup working at all. Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
2870419eb9
commit
a494f7fd4f
|
@ -273,13 +273,13 @@ virStorageBackendISCSICheckPool(virStoragePoolObjPtr pool,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendISCSISetAuth(const char *portal,
|
virStorageBackendISCSISetAuth(const char *portal,
|
||||||
virConnectPtr conn,
|
|
||||||
virStoragePoolSourcePtr source)
|
virStoragePoolSourcePtr source)
|
||||||
{
|
{
|
||||||
unsigned char *secret_value = NULL;
|
unsigned char *secret_value = NULL;
|
||||||
size_t secret_size;
|
size_t secret_size;
|
||||||
virStorageAuthDefPtr authdef = source->auth;
|
virStorageAuthDefPtr authdef = source->auth;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
|
if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -292,12 +292,9 @@ virStorageBackendISCSISetAuth(const char *portal,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conn) {
|
conn = virGetConnectSecret();
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
if (!conn)
|
||||||
_("iscsi 'chap' authentication not supported "
|
|
||||||
"for autostarted pools"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
|
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
|
||||||
VIR_SECRET_USAGE_TYPE_ISCSI,
|
VIR_SECRET_USAGE_TYPE_ISCSI,
|
||||||
|
@ -322,11 +319,12 @@ virStorageBackendISCSISetAuth(const char *portal,
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_DISPOSE_N(secret_value, secret_size);
|
VIR_DISPOSE_N(secret_value, secret_size);
|
||||||
|
virObjectUnref(conn);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendISCSIStartPool(virConnectPtr conn,
|
virStorageBackendISCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool)
|
virStoragePoolObjPtr pool)
|
||||||
{
|
{
|
||||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||||
|
@ -362,7 +360,7 @@ virStorageBackendISCSIStartPool(virConnectPtr conn,
|
||||||
if (virISCSINodeNew(portal, def->source.devices[0].path) < 0)
|
if (virISCSINodeNew(portal, def->source.devices[0].path) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virStorageBackendISCSISetAuth(portal, conn, &def->source) < 0)
|
if (virStorageBackendISCSISetAuth(portal, &def->source) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virISCSIConnectionLogin(portal,
|
if (virISCSIConnectionLogin(portal,
|
||||||
|
|
|
@ -997,7 +997,7 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (vol->target.encryption &&
|
if (vol->target.encryption &&
|
||||||
virStorageBackendCreateVolUsingQemuImg(conn, pool, vol, NULL, 0) < 0)
|
virStorageBackendCreateVolUsingQemuImg(pool, vol, NULL, 0) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((fd = virStorageBackendVolOpen(vol->target.path, &sb,
|
if ((fd = virStorageBackendVolOpen(vol->target.path, &sb,
|
||||||
|
|
|
@ -71,7 +71,6 @@ virStorageBackendRBDRADOSConfSet(rados_t cluster,
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
||||||
virConnectPtr conn,
|
|
||||||
virStoragePoolSourcePtr source)
|
virStoragePoolSourcePtr source)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
@ -87,6 +86,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
||||||
const char *mon_op_timeout = "30";
|
const char *mon_op_timeout = "30";
|
||||||
const char *osd_op_timeout = "30";
|
const char *osd_op_timeout = "30";
|
||||||
const char *rbd_default_format = "2";
|
const char *rbd_default_format = "2";
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
if (authdef) {
|
if (authdef) {
|
||||||
VIR_DEBUG("Using cephx authorization, username: %s", authdef->username);
|
VIR_DEBUG("Using cephx authorization, username: %s", authdef->username);
|
||||||
|
@ -96,12 +96,9 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conn) {
|
conn = virGetConnectSecret();
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
if (!conn)
|
||||||
_("'ceph' authentication not supported "
|
|
||||||
"for autostarted pools"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
|
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
|
||||||
VIR_SECRET_USAGE_TYPE_CEPH,
|
VIR_SECRET_USAGE_TYPE_CEPH,
|
||||||
|
@ -201,6 +198,7 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
|
||||||
VIR_DISPOSE_N(secret_value, secret_value_size);
|
VIR_DISPOSE_N(secret_value, secret_value_size);
|
||||||
VIR_DISPOSE_STRING(rados_key);
|
VIR_DISPOSE_STRING(rados_key);
|
||||||
|
|
||||||
|
virObjectUnref(conn);
|
||||||
virBufferFreeAndReset(&mon_host);
|
virBufferFreeAndReset(&mon_host);
|
||||||
VIR_FREE(mon_buff);
|
VIR_FREE(mon_buff);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -252,8 +250,7 @@ virStorageBackendRBDFreeState(virStorageBackendRBDStatePtr *ptr)
|
||||||
|
|
||||||
|
|
||||||
static virStorageBackendRBDStatePtr
|
static virStorageBackendRBDStatePtr
|
||||||
virStorageBackendRBDNewState(virConnectPtr conn,
|
virStorageBackendRBDNewState(virStoragePoolObjPtr pool)
|
||||||
virStoragePoolObjPtr pool)
|
|
||||||
{
|
{
|
||||||
virStorageBackendRBDStatePtr ptr;
|
virStorageBackendRBDStatePtr ptr;
|
||||||
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
||||||
|
@ -261,7 +258,7 @@ virStorageBackendRBDNewState(virConnectPtr conn,
|
||||||
if (VIR_ALLOC(ptr) < 0)
|
if (VIR_ALLOC(ptr) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virStorageBackendRBDOpenRADOSConn(ptr, conn, &def->source) < 0)
|
if (virStorageBackendRBDOpenRADOSConn(ptr, &def->source) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virStorageBackendRBDOpenIoCTX(ptr, pool) < 0)
|
if (virStorageBackendRBDOpenIoCTX(ptr, pool) < 0)
|
||||||
|
@ -423,7 +420,7 @@ volStorageBackendRBDRefreshVolInfo(virStorageVolDefPtr vol,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDRefreshPool(virConnectPtr conn,
|
virStorageBackendRBDRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool)
|
virStoragePoolObjPtr pool)
|
||||||
{
|
{
|
||||||
size_t max_size = 1024;
|
size_t max_size = 1024;
|
||||||
|
@ -436,7 +433,7 @@ virStorageBackendRBDRefreshPool(virConnectPtr conn,
|
||||||
struct rados_cluster_stat_t clusterstat;
|
struct rados_cluster_stat_t clusterstat;
|
||||||
struct rados_pool_stat_t poolstat;
|
struct rados_pool_stat_t poolstat;
|
||||||
|
|
||||||
if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
|
if (!(ptr = virStorageBackendRBDNewState(pool)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((r = rados_cluster_stat(ptr->cluster, &clusterstat)) < 0) {
|
if ((r = rados_cluster_stat(ptr->cluster, &clusterstat)) < 0) {
|
||||||
|
@ -605,7 +602,7 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDDeleteVol(virConnectPtr conn,
|
virStorageBackendRBDDeleteVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
|
@ -623,7 +620,7 @@ virStorageBackendRBDDeleteVol(virConnectPtr conn,
|
||||||
if (flags & VIR_STORAGE_VOL_DELETE_ZEROED)
|
if (flags & VIR_STORAGE_VOL_DELETE_ZEROED)
|
||||||
VIR_WARN("%s", "This storage backend does not support zeroed removal of volumes");
|
VIR_WARN("%s", "This storage backend does not support zeroed removal of volumes");
|
||||||
|
|
||||||
if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
|
if (!(ptr = virStorageBackendRBDNewState(pool)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (flags & VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS) {
|
if (flags & VIR_STORAGE_VOL_DELETE_WITH_SNAPSHOTS) {
|
||||||
|
@ -685,7 +682,7 @@ static int virStorageBackendRBDCreateImage(rados_ioctx_t io,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDBuildVol(virConnectPtr conn,
|
virStorageBackendRBDBuildVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
|
@ -718,7 +715,7 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
|
if (!(ptr = virStorageBackendRBDNewState(pool)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((r = virStorageBackendRBDCreateImage(ptr->ioctx, vol->name,
|
if ((r = virStorageBackendRBDCreateImage(ptr->ioctx, vol->name,
|
||||||
|
@ -1041,7 +1038,7 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDBuildVolFrom(virConnectPtr conn,
|
virStorageBackendRBDBuildVolFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr newvol,
|
virStorageVolDefPtr newvol,
|
||||||
virStorageVolDefPtr origvol,
|
virStorageVolDefPtr origvol,
|
||||||
|
@ -1056,7 +1053,7 @@ virStorageBackendRBDBuildVolFrom(virConnectPtr conn,
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
|
if (!(ptr = virStorageBackendRBDNewState(pool)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((virStorageBackendRBDCloneImage(ptr->ioctx, origvol->name,
|
if ((virStorageBackendRBDCloneImage(ptr->ioctx, origvol->name,
|
||||||
|
@ -1071,14 +1068,14 @@ virStorageBackendRBDBuildVolFrom(virConnectPtr conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDRefreshVol(virConnectPtr conn,
|
virStorageBackendRBDRefreshVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
||||||
virStorageVolDefPtr vol)
|
virStorageVolDefPtr vol)
|
||||||
{
|
{
|
||||||
virStorageBackendRBDStatePtr ptr = NULL;
|
virStorageBackendRBDStatePtr ptr = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
|
if (!(ptr = virStorageBackendRBDNewState(pool)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (volStorageBackendRBDRefreshVolInfo(vol, pool, ptr) < 0)
|
if (volStorageBackendRBDRefreshVolInfo(vol, pool, ptr) < 0)
|
||||||
|
@ -1105,7 +1102,7 @@ virStorageBackendRBDResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(0, -1);
|
||||||
|
|
||||||
if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
|
if (!(ptr = virStorageBackendRBDNewState(pool)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
|
if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
|
||||||
|
@ -1204,7 +1201,7 @@ virStorageBackendRBDVolWipeDiscard(rbd_image_t image,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendRBDVolWipe(virConnectPtr conn,
|
virStorageBackendRBDVolWipe(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
unsigned int algorithm,
|
unsigned int algorithm,
|
||||||
|
@ -1222,7 +1219,7 @@ virStorageBackendRBDVolWipe(virConnectPtr conn,
|
||||||
|
|
||||||
VIR_DEBUG("Wiping RBD image %s/%s", def->source.name, vol->name);
|
VIR_DEBUG("Wiping RBD image %s/%s", def->source.name, vol->name);
|
||||||
|
|
||||||
if (!(ptr = virStorageBackendRBDNewState(conn, pool)))
|
if (!(ptr = virStorageBackendRBDNewState(pool)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
|
if ((r = rbd_open(ptr->ioctx, vol->name, &image, NULL)) < 0) {
|
||||||
|
|
|
@ -497,7 +497,7 @@ virStorageGenerateSecretUUID(virConnectPtr conn,
|
||||||
_("unable to generate uuid"));
|
_("unable to generate uuid"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tmp = conn->secretDriver->secretLookupByUUID(conn, uuid);
|
tmp = virSecretLookupByUUID(conn, uuid);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -511,8 +511,7 @@ virStorageGenerateSecretUUID(virConnectPtr conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageGenerateQcowEncryption(virConnectPtr conn,
|
virStorageGenerateQcowEncryption(virStorageVolDefPtr vol)
|
||||||
virStorageVolDefPtr vol)
|
|
||||||
{
|
{
|
||||||
virSecretDefPtr def = NULL;
|
virSecretDefPtr def = NULL;
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
@ -522,15 +521,11 @@ virStorageGenerateQcowEncryption(virConnectPtr conn,
|
||||||
char *xml;
|
char *xml;
|
||||||
unsigned char value[VIR_STORAGE_QCOW_PASSPHRASE_SIZE];
|
unsigned char value[VIR_STORAGE_QCOW_PASSPHRASE_SIZE];
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
if (conn->secretDriver == NULL ||
|
conn = virGetConnectSecret();
|
||||||
conn->secretDriver->secretLookupByUUID == NULL ||
|
if (!conn)
|
||||||
conn->secretDriver->secretDefineXML == NULL ||
|
return -1;
|
||||||
conn->secretDriver->secretSetValue == NULL) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("secret storage not supported"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
enc = vol->target.encryption;
|
enc = vol->target.encryption;
|
||||||
if (enc->nsecrets != 0) {
|
if (enc->nsecrets != 0) {
|
||||||
|
@ -557,7 +552,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn,
|
||||||
if (xml == NULL)
|
if (xml == NULL)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
secret = conn->secretDriver->secretDefineXML(conn, xml, 0);
|
secret = virSecretDefineXML(conn, xml, 0);
|
||||||
if (secret == NULL) {
|
if (secret == NULL) {
|
||||||
VIR_FREE(xml);
|
VIR_FREE(xml);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -567,7 +562,7 @@ virStorageGenerateQcowEncryption(virConnectPtr conn,
|
||||||
if (virStorageGenerateQcowPassphrase(value) < 0)
|
if (virStorageGenerateQcowPassphrase(value) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (conn->secretDriver->secretSetValue(secret, value, sizeof(value), 0) < 0)
|
if (virSecretSetValue(secret, value, sizeof(value), 0) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
enc_secret->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
|
enc_secret->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
|
||||||
|
@ -582,11 +577,11 @@ virStorageGenerateQcowEncryption(virConnectPtr conn,
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (secret != NULL) {
|
if (secret != NULL) {
|
||||||
if (ret != 0 &&
|
if (ret != 0)
|
||||||
conn->secretDriver->secretUndefine != NULL)
|
virSecretUndefine(secret);
|
||||||
conn->secretDriver->secretUndefine(secret);
|
|
||||||
virObjectUnref(secret);
|
virObjectUnref(secret);
|
||||||
}
|
}
|
||||||
|
virObjectUnref(conn);
|
||||||
virBufferFreeAndReset(&buf);
|
virBufferFreeAndReset(&buf);
|
||||||
virSecretDefFree(def);
|
virSecretDefFree(def);
|
||||||
VIR_FREE(enc_secret);
|
VIR_FREE(enc_secret);
|
||||||
|
@ -942,7 +937,6 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr enc,
|
||||||
static int
|
static int
|
||||||
storageBackendCreateQemuImgCheckEncryption(int format,
|
storageBackendCreateQemuImgCheckEncryption(int format,
|
||||||
const char *type,
|
const char *type,
|
||||||
virConnectPtr conn,
|
|
||||||
virStorageVolDefPtr vol)
|
virStorageVolDefPtr vol)
|
||||||
{
|
{
|
||||||
virStorageEncryptionPtr enc = vol->target.encryption;
|
virStorageEncryptionPtr enc = vol->target.encryption;
|
||||||
|
@ -962,7 +956,7 @@ storageBackendCreateQemuImgCheckEncryption(int format,
|
||||||
}
|
}
|
||||||
if (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT ||
|
if (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT ||
|
||||||
enc->nsecrets == 0) {
|
enc->nsecrets == 0) {
|
||||||
if (virStorageGenerateQcowEncryption(conn, vol) < 0)
|
if (virStorageGenerateQcowEncryption(vol) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (format == VIR_STORAGE_FILE_RAW) {
|
} else if (format == VIR_STORAGE_FILE_RAW) {
|
||||||
|
@ -1178,8 +1172,7 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cmd,
|
||||||
* volume definitions and imgformat
|
* volume definitions and imgformat
|
||||||
*/
|
*/
|
||||||
virCommandPtr
|
virCommandPtr
|
||||||
virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
|
virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
||||||
virStoragePoolObjPtr pool,
|
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
|
@ -1264,7 +1257,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
|
||||||
|
|
||||||
if (info.encryption &&
|
if (info.encryption &&
|
||||||
storageBackendCreateQemuImgCheckEncryption(info.format, type,
|
storageBackendCreateQemuImgCheckEncryption(info.format, type,
|
||||||
conn, vol) < 0)
|
vol) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1317,8 +1310,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
|
||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
storageBackendCreateQemuImgSecretPath(virConnectPtr conn,
|
storageBackendCreateQemuImgSecretPath(virStoragePoolObjPtr pool,
|
||||||
virStoragePoolObjPtr pool,
|
|
||||||
virStorageVolDefPtr vol)
|
virStorageVolDefPtr vol)
|
||||||
{
|
{
|
||||||
virStorageEncryptionPtr enc = vol->target.encryption;
|
virStorageEncryptionPtr enc = vol->target.encryption;
|
||||||
|
@ -1326,6 +1318,7 @@ storageBackendCreateQemuImgSecretPath(virConnectPtr conn,
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
uint8_t *secret = NULL;
|
uint8_t *secret = NULL;
|
||||||
size_t secretlen = 0;
|
size_t secretlen = 0;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
if (!enc) {
|
if (!enc) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
@ -1333,14 +1326,9 @@ storageBackendCreateQemuImgSecretPath(virConnectPtr conn,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!conn || !conn->secretDriver ||
|
conn = virGetConnectSecret();
|
||||||
!conn->secretDriver->secretLookupByUUID ||
|
if (!conn)
|
||||||
!conn->secretDriver->secretLookupByUsage ||
|
|
||||||
!conn->secretDriver->secretGetValue) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("unable to look up encryption secret"));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(secretPath = virStoragePoolObjBuildTempFilePath(pool, vol)))
|
if (!(secretPath = virStoragePoolObjBuildTempFilePath(pool, vol)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -1374,6 +1362,7 @@ storageBackendCreateQemuImgSecretPath(virConnectPtr conn,
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
virObjectUnref(conn);
|
||||||
VIR_DISPOSE_N(secret, secretlen);
|
VIR_DISPOSE_N(secret, secretlen);
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
|
||||||
|
@ -1387,7 +1376,7 @@ storageBackendCreateQemuImgSecretPath(virConnectPtr conn,
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
storageBackendCreateQemuImg(virConnectPtr conn,
|
storageBackendCreateQemuImg(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
|
@ -1417,11 +1406,11 @@ storageBackendCreateQemuImg(virConnectPtr conn,
|
||||||
vol->target.encryption &&
|
vol->target.encryption &&
|
||||||
vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
|
vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
|
||||||
if (!(secretPath =
|
if (!(secretPath =
|
||||||
storageBackendCreateQemuImgSecretPath(conn, pool, vol)))
|
storageBackendCreateQemuImgSecretPath(pool, vol)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, pool, vol, inputvol,
|
cmd = virStorageBackendCreateQemuImgCmdFromVol(pool, vol, inputvol,
|
||||||
flags, create_tool,
|
flags, create_tool,
|
||||||
imgformat, secretPath);
|
imgformat, secretPath);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
|
@ -1442,7 +1431,6 @@ storageBackendCreateQemuImg(virConnectPtr conn,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virStorageBackendCreateVolUsingQemuImg
|
* virStorageBackendCreateVolUsingQemuImg
|
||||||
* @conn: Connection pointer
|
|
||||||
* @pool: Storage Pool Object
|
* @pool: Storage Pool Object
|
||||||
* @vol: Volume definition
|
* @vol: Volume definition
|
||||||
* @inputvol: Volume to use for creation
|
* @inputvol: Volume to use for creation
|
||||||
|
@ -1458,8 +1446,7 @@ storageBackendCreateQemuImg(virConnectPtr conn,
|
||||||
* Returns: 0 on success, -1 on failure.
|
* Returns: 0 on success, -1 on failure.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virStorageBackendCreateVolUsingQemuImg(virConnectPtr conn,
|
virStorageBackendCreateVolUsingQemuImg(virStoragePoolObjPtr pool,
|
||||||
virStoragePoolObjPtr pool,
|
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
|
@ -1472,7 +1459,7 @@ virStorageBackendCreateVolUsingQemuImg(virConnectPtr conn,
|
||||||
changeFormat = true;
|
changeFormat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = storageBackendCreateQemuImg(conn, pool, vol, inputvol, flags);
|
ret = storageBackendCreateQemuImg(NULL, pool, vol, inputvol, flags);
|
||||||
|
|
||||||
if (changeFormat)
|
if (changeFormat)
|
||||||
vol->target.format = VIR_STORAGE_FILE_NONE;
|
vol->target.format = VIR_STORAGE_FILE_NONE;
|
||||||
|
@ -2290,7 +2277,6 @@ virStorageBackendVolDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
|
|
||||||
|
|
||||||
/* storageBackendLoadDefaultSecrets:
|
/* storageBackendLoadDefaultSecrets:
|
||||||
* @conn: Connection pointer to fetch secret
|
|
||||||
* @vol: volume being refreshed
|
* @vol: volume being refreshed
|
||||||
*
|
*
|
||||||
* If the volume had a secret generated, we need to regenerate the
|
* If the volume had a secret generated, we need to regenerate the
|
||||||
|
@ -2300,15 +2286,19 @@ virStorageBackendVolDeleteLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
* -1 on failures w/ error message set
|
* -1 on failures w/ error message set
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
storageBackendLoadDefaultSecrets(virConnectPtr conn,
|
storageBackendLoadDefaultSecrets(virStorageVolDefPtr vol)
|
||||||
virStorageVolDefPtr vol)
|
|
||||||
{
|
{
|
||||||
virSecretPtr sec;
|
virSecretPtr sec;
|
||||||
virStorageEncryptionSecretPtr encsec = NULL;
|
virStorageEncryptionSecretPtr encsec = NULL;
|
||||||
|
virConnectPtr conn = NULL;
|
||||||
|
|
||||||
if (!vol->target.encryption || vol->target.encryption->nsecrets != 0)
|
if (!vol->target.encryption || vol->target.encryption->nsecrets != 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
conn = virGetConnectSecret();
|
||||||
|
if (!conn)
|
||||||
|
return -1;
|
||||||
|
|
||||||
/* The encryption secret for qcow2 and luks volumes use the path
|
/* 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,
|
* 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).
|
* then we cannot generate the secret after a refresh (or restart).
|
||||||
|
@ -2316,8 +2306,10 @@ storageBackendLoadDefaultSecrets(virConnectPtr conn,
|
||||||
* a usage string that although matched with the secret usage string,
|
* 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,
|
* didn't contain the path to the volume. We won't error in that case,
|
||||||
* but we also cannot find the secret. */
|
* but we also cannot find the secret. */
|
||||||
if (!(sec = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_VOLUME,
|
sec = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_VOLUME,
|
||||||
vol->target.path)))
|
vol->target.path);
|
||||||
|
virObjectUnref(conn);
|
||||||
|
if (!sec)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
|
if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
|
||||||
|
@ -2343,7 +2335,7 @@ storageBackendLoadDefaultSecrets(virConnectPtr conn,
|
||||||
* Update info about a volume's capacity/allocation
|
* Update info about a volume's capacity/allocation
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virStorageBackendVolRefreshLocal(virConnectPtr conn,
|
virStorageBackendVolRefreshLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
||||||
virStorageVolDefPtr vol)
|
virStorageVolDefPtr vol)
|
||||||
{
|
{
|
||||||
|
@ -2356,13 +2348,12 @@ virStorageBackendVolRefreshLocal(virConnectPtr conn,
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Load any secrets if possible */
|
/* Load any secrets if possible */
|
||||||
return storageBackendLoadDefaultSecrets(conn, vol);
|
return storageBackendLoadDefaultSecrets(vol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
storageBackendResizeQemuImg(virConnectPtr conn,
|
storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
|
||||||
virStoragePoolObjPtr pool,
|
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
unsigned long long capacity)
|
unsigned long long capacity)
|
||||||
{
|
{
|
||||||
|
@ -2386,14 +2377,14 @@ storageBackendResizeQemuImg(virConnectPtr conn,
|
||||||
else
|
else
|
||||||
type = virStorageFileFormatTypeToString(vol->target.format);
|
type = virStorageFileFormatTypeToString(vol->target.format);
|
||||||
|
|
||||||
storageBackendLoadDefaultSecrets(conn, vol);
|
storageBackendLoadDefaultSecrets(vol);
|
||||||
|
|
||||||
if (storageBackendCreateQemuImgCheckEncryption(vol->target.format,
|
if (storageBackendCreateQemuImgCheckEncryption(vol->target.format,
|
||||||
type, NULL, vol) < 0)
|
type, vol) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(secretPath =
|
if (!(secretPath =
|
||||||
storageBackendCreateQemuImgSecretPath(conn, pool, vol)))
|
storageBackendCreateQemuImgSecretPath(pool, vol)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virAsprintf(&secretAlias, "%s_luks0", vol->name) < 0)
|
if (virAsprintf(&secretAlias, "%s_luks0", vol->name) < 0)
|
||||||
|
@ -2438,7 +2429,7 @@ storageBackendResizeQemuImg(virConnectPtr conn,
|
||||||
* Resize a volume
|
* Resize a volume
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virStorageBackendVolResizeLocal(virConnectPtr conn,
|
virStorageBackendVolResizeLocal(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
unsigned long long capacity,
|
unsigned long long capacity,
|
||||||
|
@ -2459,7 +2450,7 @@ virStorageBackendVolResizeLocal(virConnectPtr conn,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return storageBackendResizeQemuImg(conn, pool, vol, capacity);
|
return storageBackendResizeQemuImg(pool, vol, capacity);
|
||||||
} else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
|
} else if (vol->target.format == VIR_STORAGE_FILE_PLOOP) {
|
||||||
return storagePloopResize(vol, capacity);
|
return storagePloopResize(vol, capacity);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2470,7 +2461,7 @@ virStorageBackendVolResizeLocal(virConnectPtr conn,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return storageBackendResizeQemuImg(conn, pool, vol, capacity);
|
return storageBackendResizeQemuImg(pool, vol, capacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
/* File creation/cloning functions used for cloning between backends */
|
/* File creation/cloning functions used for cloning between backends */
|
||||||
|
|
||||||
int
|
int
|
||||||
virStorageBackendCreateVolUsingQemuImg(virConnectPtr conn,
|
virStorageBackendCreateVolUsingQemuImg(virStoragePoolObjPtr pool,
|
||||||
virStoragePoolObjPtr pool,
|
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
|
@ -166,8 +165,7 @@ char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
|
||||||
bool loop);
|
bool loop);
|
||||||
|
|
||||||
virCommandPtr
|
virCommandPtr
|
||||||
virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn,
|
virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
||||||
virStoragePoolObjPtr pool,
|
|
||||||
virStorageVolDefPtr vol,
|
virStorageVolDefPtr vol,
|
||||||
virStorageVolDefPtr inputvol,
|
virStorageVolDefPtr inputvol,
|
||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
|
|
|
@ -47,16 +47,12 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
virConnectPtr conn;
|
|
||||||
|
|
||||||
virStorageVolDefPtr vol = NULL, inputvol = NULL;
|
virStorageVolDefPtr vol = NULL, inputvol = NULL;
|
||||||
virStoragePoolDefPtr def = NULL;
|
virStoragePoolDefPtr def = NULL;
|
||||||
virStoragePoolDefPtr inputpool = NULL;
|
virStoragePoolDefPtr inputpool = NULL;
|
||||||
virStoragePoolObjPtr obj = NULL;
|
virStoragePoolObjPtr obj = NULL;
|
||||||
|
|
||||||
if (!(conn = virGetConnect()))
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!(def = virStoragePoolDefParseFile(poolxml)))
|
if (!(def = virStoragePoolDefParseFile(poolxml)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -84,7 +80,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||||
testSetVolumeType(vol, def);
|
testSetVolumeType(vol, def);
|
||||||
testSetVolumeType(inputvol, inputpool);
|
testSetVolumeType(inputvol, inputpool);
|
||||||
|
|
||||||
cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, obj, vol,
|
cmd = virStorageBackendCreateQemuImgCmdFromVol(obj, vol,
|
||||||
inputvol, flags,
|
inputvol, flags,
|
||||||
create_tool, imgformat,
|
create_tool, imgformat,
|
||||||
NULL);
|
NULL);
|
||||||
|
@ -111,7 +107,6 @@ testCompareXMLToArgvFiles(bool shouldFail,
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
VIR_FREE(actualCmdline);
|
VIR_FREE(actualCmdline);
|
||||||
virStoragePoolObjEndAPI(&obj);
|
virStoragePoolObjEndAPI(&obj);
|
||||||
virObjectUnref(conn);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue