From 3236da8bb7ed93dda8f6d6c769a33e3fe23d53d9 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Wed, 22 Apr 2015 18:10:50 +0200 Subject: [PATCH] parallels: Introduce parallelsDomObjFromDomain() 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 --- 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 8a3caa4864..ff9d47d9d8 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 4797794661..8bbfe8588e 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, ...) -- GitLab