Move code from connectGetVersion callback to vzInitVersion function Move variable contains version number to connection structure. --- src/vz/vz_driver.c | 50 +++++++------------------------------------------- src/vz/vz_utils.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/vz/vz_utils.h | 3 +++ 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index f7a8617..82eba27 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -62,7 +62,6 @@ VIR_LOG_INIT("parallels.parallels_driver"); #define PRLCTL "prlctl" -#define PRLSRVCTL "prlsrvctl" static int vzConnectClose(virConnectPtr conn); @@ -238,6 +237,9 @@ vzOpenDefault(virConnectPtr conn) if (prlsdkConnect(privconn) < 0) goto err_free; + if (vzInitVersion(privconn) < 0) + goto error; + if (!(privconn->caps = vzBuildCapabilities())) goto error; @@ -342,49 +344,11 @@ vzConnectClose(virConnectPtr conn) } static int -vzConnectGetVersion(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned long *hvVer) +vzConnectGetVersion(virConnectPtr conn, unsigned long *hvVer) { - char *output, *sVer, *tmp; - const char *searchStr = "prlsrvctl version "; - int ret = -1; - - output = vzGetOutput(PRLSRVCTL, "--help", NULL); - - if (!output) { - vzParseError(); - goto cleanup; - } - - if (!(sVer = strstr(output, searchStr))) { - vzParseError(); - goto cleanup; - } - - sVer = sVer + strlen(searchStr); - - /* parallels server has versions number like 6.0.17977.782218, - * so libvirt can handle only first two numbers. */ - if (!(tmp = strchr(sVer, '.'))) { - vzParseError(); - goto cleanup; - } - - if (!(tmp = strchr(tmp + 1, '.'))) { - vzParseError(); - goto cleanup; - } - - tmp[0] = '\0'; - if (virParseVersionString(sVer, hvVer, true) < 0) { - vzParseError(); - goto cleanup; - } - - ret = 0; - - cleanup: - VIR_FREE(output); - return ret; + vzConnPtr privconn = conn->privateData; + *hvVer = privconn->vzVersion; + return 0; } diff --git a/src/vz/vz_utils.c b/src/vz/vz_utils.c index a1ddad0..cf37597 100644 --- a/src/vz/vz_utils.c +++ b/src/vz/vz_utils.c @@ -34,6 +34,7 @@ #include "datatypes.h" #define VIR_FROM_THIS VIR_FROM_PARALLELS +#define PRLSRVCTL "prlsrvctl" /** * vzDomObjFromDomain: @@ -178,3 +179,49 @@ vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid) VIR_FREE(pdom); return NULL; } + +int +vzInitVersion(vzConnPtr privconn) +{ + char *output, *sVer, *tmp; + const char *searchStr = "prlsrvctl version "; + int ret = -1; + + output = vzGetOutput(PRLSRVCTL, "--help", NULL); + + if (!output) { + vzParseError(); + goto cleanup; + } + + if (!(sVer = strstr(output, searchStr))) { + vzParseError(); + goto cleanup; + } + + sVer = sVer + strlen(searchStr); + + /* parallels server has versions number like 6.0.17977.782218 or 7.0.0, + * In libvirt we handle only first two numbers. */ + if (!(tmp = strchr(sVer, '.'))) { + vzParseError(); + goto cleanup; + } + + if (!(tmp = strchr(tmp + 1, '.'))) { + vzParseError(); + goto cleanup; + } + + tmp[0] = '\0'; + if (virParseVersionString(sVer, &(privconn->vzVersion), true) < 0) { + vzParseError(); + goto cleanup; + } + + ret = 0; + + cleanup: + VIR_FREE(output); + return ret; +} diff --git a/src/vz/vz_utils.h b/src/vz/vz_utils.h index 0976193..694f204 100644 --- a/src/vz/vz_utils.h +++ b/src/vz/vz_utils.h @@ -59,6 +59,7 @@ struct _vzConn { virDomainXMLOptionPtr xmlopt; virObjectEventStatePtr domainEventState; const char *drivername; + unsigned long vzVersion; }; typedef struct _vzConn vzConn; @@ -94,6 +95,8 @@ virDomainObjPtr vzNewDomain(vzConnPtr privconn, char *name, const unsigned char *uuid); +int +vzInitVersion(vzConnPtr privconn); # define PARALLELS_BLOCK_STATS_FOREACH(OP) \ OP(rd_req, VIR_DOMAIN_BLOCK_STATS_READ_REQ, "read_requests") \ -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list