This function is practically copied over from qemu driver. Its only purpose in life is to lookup a domain object and print an error if no object is found. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/parallels/parallels_utils.c | 32 ++++++++++++++++++++++++++++++++ src/parallels/parallels_utils.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/parallels/parallels_utils.c b/src/parallels/parallels_utils.c index 8a3caa4..ff9d47d 100644 --- a/src/parallels/parallels_utils.c +++ b/src/parallels/parallels_utils.c @@ -30,9 +30,41 @@ #include "virjson.h" #include "parallels_utils.h" #include "virstring.h" +#include "datatypes.h" #define VIR_FROM_THIS VIR_FROM_PARALLELS +/** + * parallelsDomObjFromDomain: + * @domain: Domain pointer that has to be looked up + * + * This function looks up @domain and returns the appropriate virDomainObjPtr + * that has to be unlocked by virObjectUnlock(). + * + * Returns the domain object without incremented reference counter which is locked + * on success, NULL otherwise. + */ +virDomainObjPtr +parallelsDomObjFromDomain(virDomainPtr domain) +{ + virDomainObjPtr vm; + parallelsConnPtr privconn = domain->conn->privateData; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + vm = virDomainObjListFindByUUID(privconn->domains, domain->uuid); + if (!vm) { + virUUIDFormat(domain->uuid, uuidstr); + virReportError(VIR_ERR_NO_DOMAIN, + _("no domain with matching uuid '%s' (%s)"), + uuidstr, domain->name); + return NULL; + } + + return vm; + +} + + static int parallelsDoCmdRun(char **outbuf, const char *binary, va_list list) { diff --git a/src/parallels/parallels_utils.h b/src/parallels/parallels_utils.h index 4797794..8bbfe85 100644 --- a/src/parallels/parallels_utils.h +++ b/src/parallels/parallels_utils.h @@ -91,6 +91,8 @@ virDrvOpenStatus parallelsNetworkOpen(virConnectPtr conn, unsigned int flags); int parallelsNetworkClose(virConnectPtr conn); extern virNetworkDriver parallelsNetworkDriver; +virDomainObjPtr parallelsDomObjFromDomain(virDomainPtr domain); + virJSONValuePtr parallelsParseOutput(const char *binary, ...) ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL; char * parallelsGetOutput(const char *binary, ...) -- 2.0.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list