Message ID | 20230426145932.3340-3-alejandro.vallejo@cloud.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Rationalize usage of xc_domain_getinfo{,list}() | expand |
On 26/04/2023 3:59 pm, Alejandro Vallejo wrote: > It's a stricter version of xc_domain_getinfo() where the returned domid > always matches the requested domid or the error code shows an error instead. > A few patches ahead usages of xc_domain_getinfo() are removed until only > xc_domain_getinfo_single() and xc_domain_getinfolist() remain. > > Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com> > --- > Cc: Andrew Cooper <andrew.cooper3@citrix.com> > Cc: Wei Liu <wl@xen.org> > Cc: Anthony PERARD <anthony.perard@citrix.com> > Cc: Juergen Gross <jgross@suse.com> > --- > tools/include/xenctrl.h | 16 ++++++++++++++++ > tools/libs/ctrl/xc_domain.c | 22 ++++++++++++++++++++++ > 2 files changed, 38 insertions(+) > > diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h > index 90b33aa3a7..73b07955c6 100644 > --- a/tools/include/xenctrl.h > +++ b/tools/include/xenctrl.h > @@ -696,6 +696,22 @@ int xc_vcpu_getaffinity(xc_interface *xch, > int xc_domain_get_guest_width(xc_interface *xch, uint32_t domid, > unsigned int *guest_width); > > +/** > + * This function will return information about a single domain. It looks > + * up the domain by the provided domid and succeeds if the domain exists > + * and is accesible by the current domain, or fails otherwise. A buffer > + * may optionally passed on the `info` parameter in order to retrieve > + * information about the domain. The buffer is ignored if NULL is > + * passed instead. > + * > + * @parm xch a handle to an open hypervisor interface > + * @parm domid domid to lookup > + * @parm info Optional domain information buffer (may be NULL) > + * @return 0 on success, otherwise the call failed and info is undefined > + */ > +int xc_domain_getinfo_single(xc_interface *xch, > + uint32_t domid, > + xc_domaininfo_t *info); > > /** > * This function will return information about one or more domains. It is > diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c > index e939d07157..3ff91023bf 100644 > --- a/tools/libs/ctrl/xc_domain.c > +++ b/tools/libs/ctrl/xc_domain.c > @@ -345,6 +345,28 @@ int xc_dom_vuart_init(xc_interface *xch, > return rc; > } > > +int xc_domain_getinfo_single(xc_interface *xch, > + uint32_t domid, > + xc_domaininfo_t *info) > +{ > + struct xen_domctl domctl = { > + .cmd = XEN_DOMCTL_getdomaininfo, > + .domain = domid, > + }; > + > + int rc = do_domctl(xch, &domctl); Minor style. Should have a newline here, and drop the one 2 lines up. By and large, this library is mostly Xen style and we're trying to make it more consistent than it is, so we want extra spaces in the if conditions below. Otherwise, LGTM. Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> > + if (rc < 0) > + return rc; > + > + if (domctl.u.getdomaininfo.domain != domid) > + return -ESRCH; > + > + if (info) > + *info = domctl.u.getdomaininfo; > + > + return rc; > +} > + > int xc_domain_getinfo(xc_interface *xch, > uint32_t first_domid, > unsigned int max_doms,
diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 90b33aa3a7..73b07955c6 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -696,6 +696,22 @@ int xc_vcpu_getaffinity(xc_interface *xch, int xc_domain_get_guest_width(xc_interface *xch, uint32_t domid, unsigned int *guest_width); +/** + * This function will return information about a single domain. It looks + * up the domain by the provided domid and succeeds if the domain exists + * and is accesible by the current domain, or fails otherwise. A buffer + * may optionally passed on the `info` parameter in order to retrieve + * information about the domain. The buffer is ignored if NULL is + * passed instead. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domid to lookup + * @parm info Optional domain information buffer (may be NULL) + * @return 0 on success, otherwise the call failed and info is undefined + */ +int xc_domain_getinfo_single(xc_interface *xch, + uint32_t domid, + xc_domaininfo_t *info); /** * This function will return information about one or more domains. It is diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index e939d07157..3ff91023bf 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -345,6 +345,28 @@ int xc_dom_vuart_init(xc_interface *xch, return rc; } +int xc_domain_getinfo_single(xc_interface *xch, + uint32_t domid, + xc_domaininfo_t *info) +{ + struct xen_domctl domctl = { + .cmd = XEN_DOMCTL_getdomaininfo, + .domain = domid, + }; + + int rc = do_domctl(xch, &domctl); + if (rc < 0) + return rc; + + if (domctl.u.getdomaininfo.domain != domid) + return -ESRCH; + + if (info) + *info = domctl.u.getdomaininfo; + + return rc; +} + int xc_domain_getinfo(xc_interface *xch, uint32_t first_domid, unsigned int max_doms,
It's a stricter version of xc_domain_getinfo() where the returned domid always matches the requested domid or the error code shows an error instead. A few patches ahead usages of xc_domain_getinfo() are removed until only xc_domain_getinfo_single() and xc_domain_getinfolist() remain. Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com> --- Cc: Andrew Cooper <andrew.cooper3@citrix.com> Cc: Wei Liu <wl@xen.org> Cc: Anthony PERARD <anthony.perard@citrix.com> Cc: Juergen Gross <jgross@suse.com> --- tools/include/xenctrl.h | 16 ++++++++++++++++ tools/libs/ctrl/xc_domain.c | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+)