From 69f614623d044b9fcb1dcc1aa14f363c689efaad Mon Sep 17 00:00:00 2001 From: Eric Chanudet Date: Mon, 10 Jun 2019 16:48:17 -0400 Subject: [PATCH] surfman: xc_domain_getinfo usage. xc_domain_getinfo(h, domid, n, info): will return the number of xc_dominfo_t written in info and fill info starting with the first domain with domain_id >= domid. In practice, this means, xc_domain_getinfo(h, domid, 1, info), may fill the info struct for a domain which domain_id != domid. This is a problem for xc_domid_exists() which makes that assumption. Since libsurfman provides xc_domid_getinfo() handle the case in it and use the exported function across surfman. The main in this is xc_domid_getinfo() will return -ENOENT if the domain associated with the domid in argument does not exist. Signed-off-by: Eric Chanudet (cherry picked from commit 64793ffacfc1b6aefb03d2a936665d46e473c5b4) Signed-off-by: Eric Chanudet --- libsurfman/src/xc.c | 15 +++++++++------ surfman/src/domain.c | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/libsurfman/src/xc.c b/libsurfman/src/xc.c index 97bf118..c2614a6 100644 --- a/libsurfman/src/xc.c +++ b/libsurfman/src/xc.c @@ -37,18 +37,21 @@ void xc_init (void) } } -int xc_domid_exists (int domid) +int xc_domid_getinfo(int domid, xc_dominfo_t *info) { - xc_dominfo_t info; int rc; - rc = xc_domain_getinfo (xch, domid, 1, &info); - return rc >= 0 ? info.domid == (domid_t)domid : 0; + rc = xc_domain_getinfo (xch, domid, 1, info); + if (rc == 1) + return info->domid == (domid_t)domid ? 1 : -ENOENT; + return rc; } -int xc_domid_getinfo(int domid, xc_dominfo_t *info) +int xc_domid_exists(int domid) { - return xc_domain_getinfo (xch, domid, 1, info); + xc_dominfo_t info = { 0 }; + + return !!xc_domid_getinfo(domid, &info); } void *xc_mmap_foreign(void *addr, size_t length, int prot, diff --git a/surfman/src/domain.c b/surfman/src/domain.c index e811dbc..a1d08ae 100644 --- a/surfman/src/domain.c +++ b/surfman/src/domain.c @@ -35,7 +35,7 @@ domain_dying (struct domain *d) { xc_dominfo_t info; - if (!xc_domid_getinfo (d->domid, &info)) + if (xc_domid_getinfo (d->domid, &info) != 1) return 0; return info.dying; }