From nobody Wed Nov 27 09:35:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1551278355794197.1808966525474; Wed, 27 Feb 2019 06:39:15 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03EE830A04E7; Wed, 27 Feb 2019 14:39:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CE3935DF4C; Wed, 27 Feb 2019 14:39:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 70910181A00A; Wed, 27 Feb 2019 14:39:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1REdC15017258 for ; Wed, 27 Feb 2019 09:39:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4CD5861374; Wed, 27 Feb 2019 14:39:12 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71BC361359 for ; Wed, 27 Feb 2019 14:39:07 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 27 Feb 2019 15:39:01 +0100 Message-Id: <1f4925e22e988ee6f29540cf4910c3dbcfebe3b6.1551278135.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] Drop some useless comparisons and checks X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 27 Feb 2019 14:39:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In these cases the check that is removed has been done a few lines above already (as can even be seen in the context). Drop them. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- examples/dommigrate/dommigrate.c | 3 +-- src/conf/nwfilter_conf.c | 4 +--- src/qemu/qemu_command.c | 3 +-- src/qemu/qemu_hotplug.c | 20 +++++++++----------- src/util/virresctrl.c | 2 +- tools/virsh-snapshot.c | 5 ++--- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/examples/dommigrate/dommigrate.c b/examples/dommigrate/dommigr= ate.c index 1b6072d138..60cfb3fb83 100644 --- a/examples/dommigrate/dommigrate.c +++ b/examples/dommigrate/dommigrate.c @@ -37,51 +37,50 @@ int main(int argc, char *argv[]) { char *src_uri, *dst_uri, *domname; int ret =3D 0; virConnectPtr conn =3D NULL; virDomainPtr dom =3D NULL; =20 if (argc < 4) { ret =3D usage(argv[0], 1); goto out; } =20 src_uri =3D argv[1]; dst_uri =3D argv[2]; domname =3D argv[3]; =20 printf("Attempting to connect to the source hypervisor...\n"); conn =3D virConnectOpenAuth(src_uri, virConnectAuthPtrDefault, 0); if (!conn) { ret =3D 1; fprintf(stderr, "No connection to the source hypervisor: %s.\n", virGetLastErrorMessage()); goto out; } =20 printf("Attempting to retrieve domain %s...\n", domname); dom =3D virDomainLookupByName(conn, domname); if (!dom) { fprintf(stderr, "Failed to find domain %s.\n", domname); goto cleanup; } =20 printf("Attempting to migrate %s to %s...\n", domname, dst_uri); if ((ret =3D virDomainMigrateToURI(dom, dst_uri, VIR_MIGRATE_PEER2PEER, NULL, 0)) !=3D 0) { fprintf(stderr, "Failed to migrate domain %s.\n", domname); goto cleanup; } =20 printf("Migration finished with success.\n"); =20 cleanup: if (dom !=3D NULL) virDomainFree(dom); - if (conn !=3D NULL) - virConnectClose(conn); + virConnectClose(conn); =20 out: return ret; } diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 7cad3ccc57..3f28c7b451 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -2610,128 +2610,126 @@ static virNWFilterDefPtr virNWFilterDefParseXML(xmlXPathContextPtr ctxt) { virNWFilterDefPtr ret; xmlNodePtr curr =3D ctxt->node; char *uuid =3D NULL; char *chain =3D NULL; char *chain_pri_s =3D NULL; virNWFilterEntryPtr entry; int chain_priority; const char *name_prefix; =20 if (VIR_ALLOC(ret) < 0) return NULL; =20 ret->name =3D virXPathString("string(./@name)", ctxt); if (!ret->name) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("filter has no name")); goto cleanup; } =20 chain_pri_s =3D virXPathString("string(./@priority)", ctxt); if (chain_pri_s) { if (virStrToLong_i(chain_pri_s, NULL, 10, &chain_priority) < 0) { virReportError(VIR_ERR_INVALID_ARG, _("Could not parse chain priority '%s'"), chain_pri_s); goto cleanup; } if (chain_priority < NWFILTER_MIN_FILTER_PRIORITY || chain_priority > NWFILTER_MAX_FILTER_PRIORITY) { virReportError(VIR_ERR_INVALID_ARG, _("Priority '%d' is outside valid " "range of [%d,%d]"), chain_priority, NWFILTER_MIN_FILTER_PRIORITY, NWFILTER_MAX_FILTER_PRIORITY); goto cleanup; } } =20 chain =3D virXPathString("string(./@chain)", ctxt); if (chain) { name_prefix =3D virNWFilterIsAllowedChain(chain); if (name_prefix =3D=3D NULL) goto cleanup; ret->chainsuffix =3D chain; =20 if (chain_pri_s) { ret->chainPriority =3D chain_priority; } else { /* assign default priority if none can be found via lookup */ - if (!name_prefix || - intMapGetByString(chain_priorities, name_prefix, 0, - &ret->chainPriority) < 0) { + if (intMapGetByString(chain_priorities, name_prefix, 0, &ret->= chainPriority) < 0) { /* assign default chain priority */ ret->chainPriority =3D (NWFILTER_MAX_FILTER_PRIORITY + NWFILTER_MIN_FILTER_PRIORITY) / 2; } } chain =3D NULL; } else { if (VIR_STRDUP(ret->chainsuffix, virNWFilterChainSuffixTypeToString(VIR_NWFILTER_CHA= INSUFFIX_ROOT)) < 0) goto cleanup; } =20 uuid =3D virXPathString("string(./uuid)", ctxt); ret->uuid_specified =3D (uuid !=3D NULL); if (uuid =3D=3D NULL) { if (virUUIDGenerate(ret->uuid) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("unable to generate uuid")); goto cleanup; } } else { if (virUUIDParse(uuid, ret->uuid) < 0) { virReportError(VIR_ERR_XML_ERROR, "%s", _("malformed uuid element")); goto cleanup; } VIR_FREE(uuid); } =20 curr =3D curr->children; =20 while (curr !=3D NULL) { if (curr->type =3D=3D XML_ELEMENT_NODE) { if (VIR_ALLOC(entry) < 0) goto cleanup; =20 if (virXMLNodeNameEqual(curr, "rule")) { if (!(entry->rule =3D virNWFilterRuleParse(curr))) { virNWFilterEntryFree(entry); goto cleanup; } } else if (virXMLNodeNameEqual(curr, "filterref")) { if (!(entry->include =3D virNWFilterIncludeParse(curr))) { virNWFilterEntryFree(entry); goto cleanup; } } =20 if (entry->rule || entry->include) { if (VIR_APPEND_ELEMENT_COPY(ret->filterEntries, ret->nentries, entry) < 0) { virNWFilterEntryFree(entry); goto cleanup; } } else { virNWFilterEntryFree(entry); } } curr =3D curr->next; } =20 VIR_FREE(chain); VIR_FREE(chain_pri_s); =20 return ret; =20 cleanup: virNWFilterDefFree(ret); VIR_FREE(chain); VIR_FREE(uuid); VIR_FREE(chain_pri_s); return NULL; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 74f34af292..ee70444bd4 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4201,31 +4201,30 @@ static int qemuBuildNVRAMCommandLine(virCommandPtr cmd, const virDomainDef *def, virQEMUCapsPtr qemuCaps) { if (!def->nvram) return 0; =20 if (qemuDomainIsPSeries(def)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_NVRAM)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("nvram device is not supported by " "this QEMU binary")); return -1; } =20 char *optstr; virCommandAddArg(cmd, "-global"); optstr =3D qemuBuildNVRAMDevStr(def->nvram); if (!optstr) return -1; - if (optstr) - virCommandAddArg(cmd, optstr); + virCommandAddArg(cmd, optstr); VIR_FREE(optstr); } else { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("nvram device is only supported for PPC64")); return -1; } =20 return 0; } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 00dbff6b2a..19b7e6e8ea 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3502,52 +3502,50 @@ static int qemuDomainChangeNetBridge(virDomainObjPtr vm, virDomainNetDefPtr olddev, virDomainNetDefPtr newdev) { int ret =3D -1; const char *oldbridge =3D virDomainNetGetActualBridgeName(olddev); const char *newbridge =3D virDomainNetGetActualBridgeName(newdev); =20 if (!oldbridge || !newbridge) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge nam= e")); goto cleanup; } =20 VIR_DEBUG("Change bridge for interface %s: %s -> %s", olddev->ifname, oldbridge, newbridge); =20 if (virNetDevExists(newbridge) !=3D 1) { virReportError(VIR_ERR_OPERATION_FAILED, _("bridge %s doesn't exist"), newbridge); goto cleanup; } =20 - if (oldbridge) { - ret =3D virNetDevBridgeRemovePort(oldbridge, olddev->ifname); - virDomainAuditNet(vm, olddev, NULL, "detach", ret =3D=3D 0); - if (ret < 0) { - /* warn but continue - possibly the old network - * had been destroyed and reconstructed, leaving the - * tap device orphaned. - */ - VIR_WARN("Unable to detach device %s from bridge %s", - olddev->ifname, oldbridge); - } + ret =3D virNetDevBridgeRemovePort(oldbridge, olddev->ifname); + virDomainAuditNet(vm, olddev, NULL, "detach", ret =3D=3D 0); + if (ret < 0) { + /* warn but continue - possibly the old network + * had been destroyed and reconstructed, leaving the + * tap device orphaned. + */ + VIR_WARN("Unable to detach device %s from bridge %s", + olddev->ifname, oldbridge); } =20 ret =3D virNetDevBridgeAddPort(newbridge, olddev->ifname); virDomainAuditNet(vm, NULL, newdev, "attach", ret =3D=3D 0); if (ret < 0) { ret =3D virNetDevBridgeAddPort(oldbridge, olddev->ifname); virDomainAuditNet(vm, NULL, olddev, "attach", ret =3D=3D 0); if (ret < 0) { virReportError(VIR_ERR_OPERATION_FAILED, _("unable to recover former state by adding por= t " "to bridge %s"), oldbridge); } goto cleanup; } /* caller will replace entire olddev with newdev in domain nets list */ ret =3D 0; cleanup: return ret; } diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 97891b2f8f..0857d4e882 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -2111,57 +2111,57 @@ static int virResctrlAllocMemoryBandwidth(virResctrlInfoPtr resctrl, virResctrlAllocPtr alloc, virResctrlAllocPtr free) { size_t i; virResctrlAllocMemBWPtr mem_bw_alloc =3D alloc->mem_bw; virResctrlAllocMemBWPtr mem_bw_free =3D free->mem_bw; virResctrlInfoMemBWPtr mem_bw_info =3D resctrl->membw_info; =20 if (!mem_bw_alloc) return 0; =20 - if (mem_bw_alloc && !mem_bw_info) { + if (!mem_bw_info) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("RDT Memory Bandwidth allocation unsupported")); return -1; } =20 for (i =3D 0; i < mem_bw_alloc->nbandwidths; i++) { if (!mem_bw_alloc->bandwidths[i]) continue; =20 if (*(mem_bw_alloc->bandwidths[i]) % mem_bw_info->bandwidth_granul= arity) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Memory Bandwidth allocation of size " "%u is not divisible by granularity %u"), *(mem_bw_alloc->bandwidths[i]), mem_bw_info->bandwidth_granularity); return -1; } if (*(mem_bw_alloc->bandwidths[i]) < mem_bw_info->min_bandwidth) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Memory Bandwidth allocation of size " "%u is smaller than the minimum " "allowed allocation %u"), *(mem_bw_alloc->bandwidths[i]), mem_bw_info->min_bandwidth); return -1; } if (i > mem_bw_info->max_id) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("bandwidth controller id %zd does not " "exist, max controller id %u"), i, mem_bw_info->max_id); return -1; } if (*(mem_bw_alloc->bandwidths[i]) > *(mem_bw_free->bandwidths[i])= ) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Not enough room for allocation of %u%% " "bandwidth on node %zd, available bandwidth %= u%%"), *(mem_bw_alloc->bandwidths[i]), i, *(mem_bw_free->bandwidths[i])); return -1; } } return 0; } diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index e38ebb1f28..025321c58e 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1046,323 +1046,322 @@ static virshSnapshotListPtr virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom, virDomainSnapshotPtr from, unsigned int orig_flags, bool tree) { size_t i; char **names =3D NULL; int count =3D -1; bool descendants =3D false; bool roots =3D false; virDomainSnapshotPtr *snaps; virshSnapshotListPtr snaplist =3D vshMalloc(ctl, sizeof(*snaplist)); virshSnapshotListPtr ret =3D NULL; const char *fromname =3D NULL; int start_index =3D -1; int deleted =3D 0; bool filter_fallback =3D false; unsigned int flags =3D orig_flags; virshControlPtr priv =3D ctl->privData; =20 /* Try the interface available in 0.9.13 and newer. */ if (!priv->useSnapshotOld) { if (from) count =3D virDomainSnapshotListAllChildren(from, &snaps, flags= ); else count =3D virDomainListAllSnapshots(dom, &snaps, flags); /* If we failed because of flags added in 1.0.1, we can do * fallback filtering. */ if (count < 0 && last_error->code =3D=3D VIR_ERR_INVALID_ARG && flags & (VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS | VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION)) { flags &=3D ~(VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS | VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION); vshResetLibvirtError(); filter_fallback =3D true; if (from) count =3D virDomainSnapshotListAllChildren(from, &snaps, f= lags); else count =3D virDomainListAllSnapshots(dom, &snaps, flags); } } if (count >=3D 0) { /* When mixing --from and --tree, we also want a copy of from * in the list, but with no parent for that one entry. */ snaplist->snaps =3D vshCalloc(ctl, count + (tree && from), sizeof(*snaplist->snaps)); snaplist->nsnaps =3D count; for (i =3D 0; i < count; i++) snaplist->snaps[i].snap =3D snaps[i]; VIR_FREE(snaps); if (tree) { for (i =3D 0; i < count; i++) { if (virshGetSnapshotParent(ctl, snaplist->snaps[i].snap, &snaplist->snaps[i].parent) < 0) goto cleanup; } if (from) { snaplist->snaps[snaplist->nsnaps++].snap =3D from; virDomainSnapshotRef(from); } } goto success; } =20 /* Assume that if we got this far, then the --no-leaves and * --no-metadata flags were not supported. Disable groups that * have no impact. */ /* XXX should we emulate --no-leaves? */ if (flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES && flags & VIR_DOMAIN_SNAPSHOT_LIST_LEAVES) flags &=3D ~(VIR_DOMAIN_SNAPSHOT_LIST_NO_LEAVES | VIR_DOMAIN_SNAPSHOT_LIST_LEAVES); if (flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA && flags & VIR_DOMAIN_SNAPSHOT_LIST_METADATA) flags &=3D ~(VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA | VIR_DOMAIN_SNAPSHOT_LIST_METADATA); if (flags & VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA) { /* We can emulate --no-metadata if --metadata was supported, * since it was an all-or-none attribute on old servers. */ count =3D virDomainSnapshotNum(dom, VIR_DOMAIN_SNAPSHOT_LIST_METADATA); if (count < 0) goto cleanup; if (count > 0) return snaplist; flags &=3D ~VIR_DOMAIN_SNAPSHOT_LIST_NO_METADATA; } if (flags & (VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS | VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION)) { flags &=3D ~(VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS | VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION); filter_fallback =3D true; } =20 /* This uses the interfaces available in 0.8.0-0.9.6 * (virDomainSnapshotListNames, global list only) and in * 0.9.7-0.9.12 (addition of virDomainSnapshotListChildrenNames * for child listing, and new flags), as follows, with [*] by the * combinations that need parent info (either for filtering * purposes or for the resulting tree listing): * old new * list global as-is global as-is * list --roots *global + filter global + flags * list --from *global + filter child as-is * list --from --descendants *global + filter child + flags * list --tree *global as-is *global as-is * list --tree --from *global + filter *child + flags * * Additionally, when --tree and --from are both used, from is * added to the final list as the only element without a parent. * Otherwise, --from does not appear in the final list. */ if (from) { fromname =3D virDomainSnapshotGetName(from); if (!fromname) { vshError(ctl, "%s", _("Could not get snapshot name")); goto cleanup; } descendants =3D (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) || = tree; if (tree) flags |=3D VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS; =20 /* Determine if we can use the new child listing API. */ if (priv->useSnapshotOld || ((count =3D virDomainSnapshotNumChildren(from, flags)) < 0 && last_error->code =3D=3D VIR_ERR_NO_SUPPORT)) { /* We can emulate --from. */ /* XXX can we also emulate --leaves? */ vshResetLibvirtError(); priv->useSnapshotOld =3D true; flags &=3D ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS; goto global; } if (tree && count >=3D 0) count++; } else { global: /* Global listing (including fallback when --from failed with * child listing). */ count =3D virDomainSnapshotNum(dom, flags); =20 /* Fall back to simulation if --roots was unsupported. */ /* XXX can we also emulate --leaves? */ if (!from && count < 0 && last_error->code =3D=3D VIR_ERR_INVALID_= ARG && (flags & VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)) { vshResetLibvirtError(); roots =3D true; flags &=3D ~VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; count =3D virDomainSnapshotNum(dom, flags); } } =20 if (count < 0) { if (!last_error) vshError(ctl, _("failed to collect snapshot list")); goto cleanup; } =20 if (!count) goto success; =20 names =3D vshCalloc(ctl, sizeof(*names), count); =20 /* Now that we have a count, collect the list. */ if (from && !priv->useSnapshotOld) { if (tree) { - if (count) - count =3D virDomainSnapshotListChildrenNames(from, names += 1, - count - 1, flag= s); + count =3D virDomainSnapshotListChildrenNames(from, names + 1, + count - 1, flags); if (count >=3D 0) { count++; names[0] =3D vshStrdup(ctl, fromname); } } else { count =3D virDomainSnapshotListChildrenNames(from, names, count, flags); } } else { count =3D virDomainSnapshotListNames(dom, names, count, flags); } if (count < 0) goto cleanup; =20 snaplist->snaps =3D vshCalloc(ctl, sizeof(*snaplist->snaps), count); snaplist->nsnaps =3D count; for (i =3D 0; i < count; i++) { snaplist->snaps[i].snap =3D virDomainSnapshotLookupByName(dom, names[i], = 0); if (!snaplist->snaps[i].snap) goto cleanup; } =20 /* Collect parents when needed. With the new API, --tree and * --from together put from as the first element without a parent; * with the old API we still need to do a post-process filtering * based on all parent information. */ if (tree || (from && priv->useSnapshotOld) || roots) { for (i =3D (from && !priv->useSnapshotOld); i < count; i++) { if (from && priv->useSnapshotOld && STREQ(names[i], fromname))= { start_index =3D i; if (tree) continue; } if (virshGetSnapshotParent(ctl, snaplist->snaps[i].snap, &snaplist->snaps[i].parent) < 0) goto cleanup; if ((from && ((tree && !snaplist->snaps[i].parent) || (!descendants && STRNEQ_NULLABLE(fromname, snaplist->snaps[i].parent)))) || (roots && snaplist->snaps[i].parent)) { virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; } } } if (tree) goto success; =20 if (priv->useSnapshotOld && descendants) { bool changed =3D false; bool remaining =3D false; =20 /* Make multiple passes over the list - first pass finds * direct children and NULLs out all roots and from, remaining * passes NULL out any undecided entry whose parent is not * still in list. We mark known descendants by clearing * snaps[i].parents. Sorry, this is O(n^3) - hope your * hierarchy isn't huge. XXX Is it worth making O(n^2 log n) * by using qsort and bsearch? */ if (start_index < 0) { vshError(ctl, _("snapshot %s disappeared from list"), fromname= ); goto cleanup; } for (i =3D 0; i < count; i++) { if (i =3D=3D start_index || !snaplist->snaps[i].parent) { VIR_FREE(names[i]); virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; } else if (STREQ(snaplist->snaps[i].parent, fromname)) { VIR_FREE(snaplist->snaps[i].parent); changed =3D true; } else { remaining =3D true; } } if (!changed) { ret =3D vshMalloc(ctl, sizeof(*snaplist)); goto cleanup; } while (changed && remaining) { changed =3D remaining =3D false; for (i =3D 0; i < count; i++) { bool found_parent =3D false; size_t j; =20 if (!names[i] || !snaplist->snaps[i].parent) continue; for (j =3D 0; j < count; j++) { if (!names[j] || i =3D=3D j) continue; if (STREQ(snaplist->snaps[i].parent, names[j])) { found_parent =3D true; if (!snaplist->snaps[j].parent) VIR_FREE(snaplist->snaps[i].parent); else remaining =3D true; break; } } if (!found_parent) { changed =3D true; VIR_FREE(names[i]); virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; } } } } =20 success: if (filter_fallback) { /* Older API didn't filter on status or location, but the * information is available in domain XML. */ if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS)) orig_flags |=3D VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS; if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION)) orig_flags |=3D VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION; for (i =3D 0; i < snaplist->nsnaps; i++) { switch (virshSnapshotFilter(ctl, snaplist->snaps[i].snap, orig_flags)) { case 1: break; case 0: virshDomainSnapshotFree(snaplist->snaps[i].snap); snaplist->snaps[i].snap =3D NULL; VIR_FREE(snaplist->snaps[i].parent); deleted++; break; default: goto cleanup; } } } qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps), virshSnapSorter); snaplist->nsnaps -=3D deleted; =20 VIR_STEAL_PTR(ret, snaplist); =20 cleanup: virshSnapshotListFree(snaplist); if (names && count > 0) for (i =3D 0; i < count; i++) VIR_FREE(names[i]); VIR_FREE(names); return ret; } --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list