mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-10-19 07:33:46 +03:00
Miscellaneous for-loop syntax clean-ups
Checking whether x > 0 before looping over [0..x] items doesn't make sense and multi-line body must have curly brackets around it. Best viewed with '-w'. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
@@ -22363,17 +22363,20 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 0; n < def->ngraphics; n++)
|
for (n = 0; n < def->ngraphics; n++) {
|
||||||
if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0)
|
if (virDomainGraphicsDefFormat(buf, def->graphics[n], flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
for (n = 0; n < def->nsounds; n++)
|
for (n = 0; n < def->nsounds; n++) {
|
||||||
if (virDomainSoundDefFormat(buf, def->sounds[n], flags) < 0)
|
if (virDomainSoundDefFormat(buf, def->sounds[n], flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
for (n = 0; n < def->nvideos; n++)
|
for (n = 0; n < def->nvideos; n++) {
|
||||||
if (virDomainVideoDefFormat(buf, def->videos[n], flags) < 0)
|
if (virDomainVideoDefFormat(buf, def->videos[n], flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
for (n = 0; n < def->nhostdevs; n++) {
|
for (n = 0; n < def->nhostdevs; n++) {
|
||||||
/* If parent.type != NONE, this is just a pointer to the
|
/* If parent.type != NONE, this is just a pointer to the
|
||||||
@@ -22386,16 +22389,18 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (n = 0; n < def->nredirdevs; n++)
|
for (n = 0; n < def->nredirdevs; n++) {
|
||||||
if (virDomainRedirdevDefFormat(buf, def->redirdevs[n], flags) < 0)
|
if (virDomainRedirdevDefFormat(buf, def->redirdevs[n], flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (def->redirfilter)
|
if (def->redirfilter)
|
||||||
virDomainRedirFilterDefFormat(buf, def->redirfilter);
|
virDomainRedirFilterDefFormat(buf, def->redirfilter);
|
||||||
|
|
||||||
for (n = 0; n < def->nhubs; n++)
|
for (n = 0; n < def->nhubs; n++) {
|
||||||
if (virDomainHubDefFormat(buf, def->hubs[n], flags) < 0)
|
if (virDomainHubDefFormat(buf, def->hubs[n], flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (def->watchdog)
|
if (def->watchdog)
|
||||||
virDomainWatchdogDefFormat(buf, def->watchdog, flags);
|
virDomainWatchdogDefFormat(buf, def->watchdog, flags);
|
||||||
@@ -22411,17 +22416,20 @@ virDomainDefFormatInternal(virDomainDefPtr def,
|
|||||||
if (def->nvram)
|
if (def->nvram)
|
||||||
virDomainNVRAMDefFormat(buf, def->nvram, flags);
|
virDomainNVRAMDefFormat(buf, def->nvram, flags);
|
||||||
|
|
||||||
for (n = 0; n < def->npanics; n++)
|
for (n = 0; n < def->npanics; n++) {
|
||||||
if (virDomainPanicDefFormat(buf, def->panics[n]) < 0)
|
if (virDomainPanicDefFormat(buf, def->panics[n]) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
for (n = 0; n < def->nshmems; n++)
|
for (n = 0; n < def->nshmems; n++) {
|
||||||
if (virDomainShmemDefFormat(buf, def->shmems[n], flags) < 0)
|
if (virDomainShmemDefFormat(buf, def->shmems[n], flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
for (n = 0; n < def->nmems; n++)
|
for (n = 0; n < def->nmems; n++) {
|
||||||
if (virDomainMemoryDefFormat(buf, def->mems[n], flags) < 0)
|
if (virDomainMemoryDefFormat(buf, def->mems[n], flags) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
virBufferAdjustIndent(buf, -2);
|
||||||
virBufferAddLit(buf, "</devices>\n");
|
virBufferAddLit(buf, "</devices>\n");
|
||||||
|
@@ -2774,23 +2774,21 @@ virQEMUCapsLoadCache(virQEMUCapsPtr qemuCaps, const char *filename,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
VIR_DEBUG("Got flags %d", n);
|
VIR_DEBUG("Got flags %d", n);
|
||||||
if (n > 0) {
|
for (i = 0; i < n; i++) {
|
||||||
for (i = 0; i < n; i++) {
|
int flag;
|
||||||
int flag;
|
if (!(str = virXMLPropString(nodes[i], "name"))) {
|
||||||
if (!(str = virXMLPropString(nodes[i], "name"))) {
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
_("missing flag name in QEMU capabilities cache"));
|
||||||
_("missing flag name in QEMU capabilities cache"));
|
goto cleanup;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
flag = virQEMUCapsTypeFromString(str);
|
|
||||||
if (flag < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Unknown qemu capabilities flag %s"), str);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
VIR_FREE(str);
|
|
||||||
virQEMUCapsSet(qemuCaps, flag);
|
|
||||||
}
|
}
|
||||||
|
flag = virQEMUCapsTypeFromString(str);
|
||||||
|
if (flag < 0) {
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Unknown qemu capabilities flag %s"), str);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
VIR_FREE(str);
|
||||||
|
virQEMUCapsSet(qemuCaps, flag);
|
||||||
}
|
}
|
||||||
VIR_FREE(nodes);
|
VIR_FREE(nodes);
|
||||||
|
|
||||||
|
@@ -566,37 +566,35 @@ virStorageBackendRBDCleanupSnapshots(rados_ioctx_t ioctx,
|
|||||||
VIR_DEBUG("Found %d snapshots for volume %s/%s", snap_count,
|
VIR_DEBUG("Found %d snapshots for volume %s/%s", snap_count,
|
||||||
source->name, vol->name);
|
source->name, vol->name);
|
||||||
|
|
||||||
if (snap_count > 0) {
|
for (i = 0; i < snap_count; i++) {
|
||||||
for (i = 0; i < snap_count; i++) {
|
if ((r = rbd_snap_is_protected(image, snaps[i].name, &protected)) < 0) {
|
||||||
if ((r = rbd_snap_is_protected(image, snaps[i].name, &protected)) < 0) {
|
virReportSystemError(-r, _("failed to verify if snapshot '%s/%s@%s' is protected"),
|
||||||
virReportSystemError(-r, _("failed to verify if snapshot '%s/%s@%s' is protected"),
|
source->name, vol->name,
|
||||||
|
snaps[i].name);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (protected == 1) {
|
||||||
|
VIR_DEBUG("Snapshot %s/%s@%s is protected needs to be "
|
||||||
|
"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'"),
|
||||||
source->name, vol->name,
|
source->name, vol->name,
|
||||||
snaps[i].name);
|
snaps[i].name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (protected == 1) {
|
VIR_DEBUG("Removing snapshot %s/%s@%s", source->name,
|
||||||
VIR_DEBUG("Snapshot %s/%s@%s is protected needs to be "
|
vol->name, snaps[i].name);
|
||||||
"unprotected", source->name, vol->name,
|
|
||||||
snaps[i].name);
|
|
||||||
|
|
||||||
if ((r = rbd_snap_unprotect(image, snaps[i].name)) < 0) {
|
if ((r = rbd_snap_remove(image, snaps[i].name)) < 0) {
|
||||||
virReportSystemError(-r, _("failed to unprotect snapshot '%s/%s@%s'"),
|
virReportSystemError(-r, _("failed to remove snapshot '%s/%s@%s'"),
|
||||||
source->name, vol->name,
|
source->name, vol->name,
|
||||||
snaps[i].name);
|
snaps[i].name);
|
||||||
goto cleanup;
|
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'"),
|
|
||||||
source->name, vol->name,
|
|
||||||
snaps[i].name);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5541,11 +5541,9 @@ vboxDomainSnapshotGet(vboxGlobalData *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (count > 0) {
|
for (i = 0; i < count; i++) {
|
||||||
for (i = 0; i < count; i++) {
|
if (snapshots[i] != snapshot)
|
||||||
if (snapshots[i] != snapshot)
|
VBOX_RELEASE(snapshots[i]);
|
||||||
VBOX_RELEASE(snapshots[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
VIR_FREE(snapshots);
|
VIR_FREE(snapshots);
|
||||||
return snapshot;
|
return snapshot;
|
||||||
@@ -6255,10 +6253,8 @@ static int vboxDomainSnapshotListNames(virDomainPtr dom, char **names,
|
|||||||
ret = nameslen;
|
ret = nameslen;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (count > 0) {
|
for (i = 0; i < count; i++)
|
||||||
for (i = 0; i < count; i++)
|
VBOX_RELEASE(snapshots[i]);
|
||||||
VBOX_RELEASE(snapshots[i]);
|
|
||||||
}
|
|
||||||
VIR_FREE(snapshots);
|
VIR_FREE(snapshots);
|
||||||
VBOX_RELEASE(machine);
|
VBOX_RELEASE(machine);
|
||||||
vboxIIDUnalloc(&iid);
|
vboxIIDUnalloc(&iid);
|
||||||
|
Reference in New Issue
Block a user