From: Mikhail Feoktistov <mfeoktistov@xxxxxxxxxxxxx> Move code from connectGetVersion callback to vzInitVersion function --- 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 6de7cb9..5d48d7e 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); @@ -234,6 +233,9 @@ vzOpenDefault(virConnectPtr conn) if (prlsdkConnect(privconn) < 0) goto err_free; + if (vzInitVersion(privconn) < 0) + goto error; + if (!(privconn->caps = vzBuildCapabilities())) goto error; @@ -345,49 +347,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 ed100ac..fbade2e 100644 --- a/src/vz/vz_utils.h +++ b/src/vz/vz_utils.h @@ -62,6 +62,7 @@ struct _vzConn { const char *drivername; /* Immutable pointer, self-locking APIs */ virConnectCloseCallbackDataPtr closeCallback; + unsigned long vzVersion; }; typedef struct _vzConn vzConn; @@ -97,6 +98,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") \ -- 2.4.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list