From: Ján Tomko Date: Tue, 13 Aug 2019 13:14:05 +0000 (+0200) Subject: util: introduce virPCIDeviceConfigOpenTry X-Git-Tag: v5.7.0-rc1~231 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17317a4bc6011b92ab802072c3de446fbba79361;p=thirdparty%2Flibvirt.git util: introduce virPCIDeviceConfigOpenTry For callers that only need read-only access and don't want an error reported. Signed-off-by: Ján Tomko Reviewed-by: Michal Privoznik --- diff --git a/src/util/virpci.c b/src/util/virpci.c index e45dfbc631..2758ee6f49 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -320,6 +320,12 @@ virPCIDeviceConfigOpen(virPCIDevicePtr dev, bool fatal) return virPCIDeviceConfigOpenInternal(dev, false, fatal); } +static int +virPCIDeviceConfigOpenTry(virPCIDevicePtr dev) +{ + return virPCIDeviceConfigOpenInternal(dev, true, false); +} + static int virPCIDeviceConfigOpenWrite(virPCIDevicePtr dev) { @@ -692,7 +698,7 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevicePtr check, void *data) if (dev->address.domain != check->address.domain) return 0; - if ((fd = virPCIDeviceConfigOpen(check, false)) < 0) + if ((fd = virPCIDeviceConfigOpenTry(check)) < 0) return 0; /* Is it a bridge? */ @@ -740,7 +746,7 @@ virPCIDeviceIsParent(virPCIDevicePtr dev, virPCIDevicePtr check, void *data) int bestfd; uint8_t best_secondary; - if ((bestfd = virPCIDeviceConfigOpen(*best, false)) < 0) + if ((bestfd = virPCIDeviceConfigOpenTry(*best)) < 0) goto cleanup; best_secondary = virPCIDeviceRead8(*best, bestfd, PCI_SECONDARY_BUS); virPCIDeviceConfigClose(*best, bestfd);