mirror of https://gitee.com/openkylin/libvirt.git
conf: use disk source accessors in conf/
Part of a series of cleanups to use new accessor methods. Several places in domain_conf.c still open-code raw field access, but that code will be touched later with the diskDef struct split so I'm avoiding churn here. * src/conf/domain_audit.c (virDomainAuditStart): Use accessors. * src/conf/domain_conf.c (virDomainDiskIndexByName) (virDomainDiskPathByName, virDomainDiskDefForeachPath) (virDomainDiskSourceIsBlockType): Likewise. * src/conf/snapshot_conf.c (virDomainSnapshotAlignDisks): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
1014c34e3c
commit
a9ab99cac2
|
@ -799,9 +799,10 @@ virDomainAuditStart(virDomainObjPtr vm, const char *reason, bool success)
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < vm->def->ndisks; i++) {
|
for (i = 0; i < vm->def->ndisks; i++) {
|
||||||
virDomainDiskDefPtr disk = vm->def->disks[i];
|
const char *src = virDomainDiskGetSource(vm->def->disks[i]);
|
||||||
if (disk->src) /* Skips CDROM without media initially inserted */
|
|
||||||
virDomainAuditDisk(vm, NULL, disk->src, "start", true);
|
if (src) /* Skips CDROM without media initially inserted */
|
||||||
|
virDomainAuditDisk(vm, NULL, src, "start", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < vm->def->nfss; i++) {
|
for (i = 0; i < vm->def->nfss; i++) {
|
||||||
|
|
|
@ -10283,8 +10283,7 @@ virDomainDiskIndexByName(virDomainDefPtr def, const char *name,
|
||||||
if (*name != '/') {
|
if (*name != '/') {
|
||||||
if (STREQ(vdisk->dst, name))
|
if (STREQ(vdisk->dst, name))
|
||||||
return i;
|
return i;
|
||||||
} else if (vdisk->src &&
|
} else if (STREQ_NULLABLE(virDomainDiskGetSource(vdisk), name)) {
|
||||||
STREQ(vdisk->src, name)) {
|
|
||||||
if (allow_ambiguous)
|
if (allow_ambiguous)
|
||||||
return i;
|
return i;
|
||||||
if (candidate >= 0)
|
if (candidate >= 0)
|
||||||
|
@ -10303,7 +10302,7 @@ virDomainDiskPathByName(virDomainDefPtr def, const char *name)
|
||||||
{
|
{
|
||||||
int idx = virDomainDiskIndexByName(def, name, true);
|
int idx = virDomainDiskIndexByName(def, name, true);
|
||||||
|
|
||||||
return idx < 0 ? NULL : def->disks[idx]->src;
|
return idx < 0 ? NULL : virDomainDiskGetSource(def->disks[idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int virDomainDiskInsert(virDomainDefPtr def,
|
int virDomainDiskInsert(virDomainDefPtr def,
|
||||||
|
@ -18618,14 +18617,16 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t depth = 0;
|
size_t depth = 0;
|
||||||
virStorageFileMetadata *tmp;
|
virStorageFileMetadata *tmp;
|
||||||
|
const char *path = virDomainDiskGetSource(disk);
|
||||||
|
int type = virDomainDiskGetType(disk);
|
||||||
|
|
||||||
if (!disk->src || disk->type == VIR_DOMAIN_DISK_TYPE_NETWORK ||
|
if (!path || type == VIR_DOMAIN_DISK_TYPE_NETWORK ||
|
||||||
(disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
|
(type == VIR_DOMAIN_DISK_TYPE_VOLUME &&
|
||||||
disk->srcpool &&
|
disk->srcpool &&
|
||||||
disk->srcpool->mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT))
|
disk->srcpool->mode == VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (iter(disk, disk->src, 0, opaque) < 0)
|
if (iter(disk, path, 0, opaque) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
tmp = disk->backingChain;
|
tmp = disk->backingChain;
|
||||||
|
@ -19495,16 +19496,17 @@ virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
|
||||||
/* No reason to think the disk source is block type if
|
/* No reason to think the disk source is block type if
|
||||||
* the source is empty
|
* the source is empty
|
||||||
*/
|
*/
|
||||||
if (!def->src)
|
if (!virDomainDiskGetSource(def))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (def->type == VIR_DOMAIN_DISK_TYPE_BLOCK)
|
if (virDomainDiskGetType(def) == VIR_DOMAIN_DISK_TYPE_BLOCK)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/* For volume types, check the srcpool.
|
/* For volume types, check the srcpool.
|
||||||
* If it's a block type source pool, then it's possible
|
* If it's a block type source pool, then it's possible
|
||||||
*/
|
*/
|
||||||
if (def->type == VIR_DOMAIN_DISK_TYPE_VOLUME && def->srcpool &&
|
if (virDomainDiskGetType(def) == VIR_DOMAIN_DISK_TYPE_VOLUME &&
|
||||||
|
def->srcpool &&
|
||||||
def->srcpool->voltype == VIR_STORAGE_VOL_BLOCK) {
|
def->srcpool->voltype == VIR_STORAGE_VOL_BLOCK) {
|
||||||
/* We don't think the volume accessed by remote URI is
|
/* We don't think the volume accessed by remote URI is
|
||||||
* block type source, since we can't/shouldn't manage it
|
* block type source, since we can't/shouldn't manage it
|
||||||
|
|
|
@ -558,7 +558,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def,
|
||||||
|
|
||||||
if (disk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL &&
|
if (disk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL &&
|
||||||
!disk->file) {
|
!disk->file) {
|
||||||
const char *original = def->dom->disks[i]->src;
|
const char *original = virDomainDiskGetSource(def->dom->disks[i]);
|
||||||
const char *tmp;
|
const char *tmp;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue