提交 7c34bb26 编写于 作者: D Daniel P. Berrange

Filter out stale domains from xenstore listing

The xenstore database sometimes has stale domain IDs which are not
present in the hypervisor anymore. Filter these out to avoid causing
confusion

* src/xen/xs_internal.c: Filter domain IDs against HV's list
* src/xen/xen_hypervisor.h, src/xen/xen_hypervisor.c: Add new
  xenHypervisorHasDomain() method for checking ID validity
上级 2659b3f5
...@@ -2789,6 +2789,28 @@ xenHypervisorDomainGetOSType (virDomainPtr dom) ...@@ -2789,6 +2789,28 @@ xenHypervisorDomainGetOSType (virDomainPtr dom)
return ostype; return ostype;
} }
int
xenHypervisorHasDomain(virConnectPtr conn,
int id)
{
xenUnifiedPrivatePtr priv;
xen_getdomaininfo dominfo;
priv = (xenUnifiedPrivatePtr) conn->privateData;
if (priv->handle < 0)
return 0;
XEN_GETDOMAININFO_CLEAR(dominfo);
if (virXen_getdomaininfo(priv->handle, id, &dominfo) < 0)
return 0;
if (XEN_GETDOMAININFO_DOMAIN(dominfo) != id)
return 0;
return 1;
}
virDomainPtr virDomainPtr
xenHypervisorLookupDomainByID(virConnectPtr conn, xenHypervisorLookupDomainByID(virConnectPtr conn,
int id) int id)
......
...@@ -23,7 +23,9 @@ int xenHypervisorInit (void); ...@@ -23,7 +23,9 @@ int xenHypervisorInit (void);
virCapsPtr xenHypervisorMakeCapabilities (virConnectPtr conn); virCapsPtr xenHypervisorMakeCapabilities (virConnectPtr conn);
/* The following calls are made directly by the Xen proxy: */ /* The following calls are made directly by the Xen proxy: */
int
xenHypervisorHasDomain(virConnectPtr conn,
int id);
virDomainPtr virDomainPtr
xenHypervisorLookupDomainByID (virConnectPtr conn, xenHypervisorLookupDomainByID (virConnectPtr conn,
int id); int id);
......
...@@ -543,8 +543,9 @@ int ...@@ -543,8 +543,9 @@ int
xenStoreNumOfDomains(virConnectPtr conn) xenStoreNumOfDomains(virConnectPtr conn)
{ {
unsigned int num; unsigned int num;
char **idlist; char **idlist = NULL, *endptr;
int ret = -1; int i, ret = -1, realnum = 0;
long id;
xenUnifiedPrivatePtr priv; xenUnifiedPrivatePtr priv;
if (conn == NULL) { if (conn == NULL) {
...@@ -557,10 +558,22 @@ xenStoreNumOfDomains(virConnectPtr conn) ...@@ -557,10 +558,22 @@ xenStoreNumOfDomains(virConnectPtr conn)
virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); virXenStoreError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
return(-1); return(-1);
} }
idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num); idlist = xs_directory(priv->xshandle, 0, "/local/domain", &num);
if (idlist) { if (idlist) {
free(idlist); for (i = 0; i < num; i++) {
ret = num; id = strtol(idlist[i], &endptr, 10);
if ((endptr == idlist[i]) || (*endptr != 0))
goto out;
/* Sometimes xenstore has stale domain IDs, so filter
against the hypervisor's info */
if (xenHypervisorHasDomain(conn, (int)id))
realnum++;
}
out:
VIR_FREE (idlist);
ret = realnum;
} }
return(ret); return(ret);
} }
...@@ -577,7 +590,7 @@ xenStoreNumOfDomains(virConnectPtr conn) ...@@ -577,7 +590,7 @@ xenStoreNumOfDomains(virConnectPtr conn)
* Returns the number of domain found or -1 in case of error * Returns the number of domain found or -1 in case of error
*/ */
static int static int
xenStoreDoListDomains(xenUnifiedPrivatePtr priv, int *ids, int maxids) xenStoreDoListDomains(virConnectPtr conn, xenUnifiedPrivatePtr priv, int *ids, int maxids)
{ {
char **idlist = NULL, *endptr; char **idlist = NULL, *endptr;
unsigned int num, i; unsigned int num, i;
...@@ -595,6 +608,10 @@ xenStoreDoListDomains(xenUnifiedPrivatePtr priv, int *ids, int maxids) ...@@ -595,6 +608,10 @@ xenStoreDoListDomains(xenUnifiedPrivatePtr priv, int *ids, int maxids)
id = strtol(idlist[i], &endptr, 10); id = strtol(idlist[i], &endptr, 10);
if ((endptr == idlist[i]) || (*endptr != 0)) if ((endptr == idlist[i]) || (*endptr != 0))
goto out; goto out;
/* Sometimes xenstore has stale domain IDs, so filter
against the hypervisor's info */
if (xenHypervisorHasDomain(conn, (int)id))
ids[ret++] = (int) id; ids[ret++] = (int) id;
} }
...@@ -627,7 +644,7 @@ xenStoreListDomains(virConnectPtr conn, int *ids, int maxids) ...@@ -627,7 +644,7 @@ xenStoreListDomains(virConnectPtr conn, int *ids, int maxids)
priv = (xenUnifiedPrivatePtr) conn->privateData; priv = (xenUnifiedPrivatePtr) conn->privateData;
xenUnifiedLock(priv); xenUnifiedLock(priv);
ret = xenStoreDoListDomains(priv, ids, maxids); ret = xenStoreDoListDomains(conn, priv, ids, maxids);
xenUnifiedUnlock(priv); xenUnifiedUnlock(priv);
return(ret); return(ret);
...@@ -1299,7 +1316,7 @@ retry: ...@@ -1299,7 +1316,7 @@ retry:
virReportOOMError(NULL); virReportOOMError(NULL);
return -1; return -1;
} }
nread = xenStoreDoListDomains(priv, new_domids, new_domain_cnt); nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
if (nread != new_domain_cnt) { if (nread != new_domain_cnt) {
// mismatch. retry this read // mismatch. retry this read
VIR_FREE(new_domids); VIR_FREE(new_domids);
...@@ -1380,7 +1397,7 @@ retry: ...@@ -1380,7 +1397,7 @@ retry:
virReportOOMError(NULL); virReportOOMError(NULL);
return -1; return -1;
} }
nread = xenStoreDoListDomains(priv, new_domids, new_domain_cnt); nread = xenStoreDoListDomains(conn, priv, new_domids, new_domain_cnt);
if (nread != new_domain_cnt) { if (nread != new_domain_cnt) {
// mismatch. retry this read // mismatch. retry this read
VIR_FREE(new_domids); VIR_FREE(new_domids);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册