diff mbox series

[XEN,2/2] tools/lsevtchn: Use evtchn port upper bound for evtchn enumeration

Message ID bc201c67ef728ebaf678eac4d97e6800a95e8081.1712840924.git.matthew.barnes@cloud.com (mailing list archive)
State Superseded
Headers show
Series Enumerate all allocated evtchns in lsevtchn | expand

Commit Message

Matthew Barnes April 11, 2024, 3:24 p.m. UTC
lsevtchn terminates the loop when the hypercall returns an error, even
if there are still event channels with higher port numbers to be
enumerated over.

Use the highest allocated event channel port number for a given domain
to bound the loop so that all relevant event channels can be enumerated
over.

Signed-off-by: Matthew Barnes <matthew.barnes@cloud.com>
---
 tools/xcutils/lsevtchn.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Jan Beulich April 18, 2024, 2:34 p.m. UTC | #1
On 11.04.2024 17:24, Matthew Barnes wrote:
> --- a/tools/xcutils/lsevtchn.c
> +++ b/tools/xcutils/lsevtchn.c
> @@ -11,6 +11,7 @@ int main(int argc, char **argv)
>      xc_interface *xch;
>      int domid, port, rc;
>      xc_evtchn_status_t status;
> +    xc_domaininfo_t info;
>  
>      domid = (argc > 1) ? strtol(argv[1], NULL, 10) : 0;
>  
> @@ -18,13 +19,16 @@ int main(int argc, char **argv)
>      if ( !xch )
>          errx(1, "failed to open control interface");
>  
> -    for ( port = 0; ; port++ )
> +    if ( xc_domain_getinfo_single(xch, domid, &info) < 0 )
> +        errx(1, "failed to fetch domain info");

This being backed by a domctl will make things fail when run on a DomU,
which aiui is supposed to be a valid environment to run lsevtchn in
(to obtain information just for the local domain). Imo instead of trying
to figure out the highest valid port number (which at least in principle
may even be dynamic, and hence the value returned by be stale by the
time it is being used), the loop below needs to continue until receiving
a specific indicator (special error code most likely).

Jan

> +    for ( port = 0; port <= info.highest_evtchn_port; port++ )
>      {
>          status.dom = domid;
>          status.port = port;
>          rc = xc_evtchn_status(xch, &status);
>          if ( rc < 0 )
> -            break;
> +            continue;
>  
>          if ( status.status == EVTCHNSTAT_closed )
>              continue;
diff mbox series

Patch

diff --git a/tools/xcutils/lsevtchn.c b/tools/xcutils/lsevtchn.c
index d1710613ddc5..7f8ad7c8e7ce 100644
--- a/tools/xcutils/lsevtchn.c
+++ b/tools/xcutils/lsevtchn.c
@@ -11,6 +11,7 @@  int main(int argc, char **argv)
     xc_interface *xch;
     int domid, port, rc;
     xc_evtchn_status_t status;
+    xc_domaininfo_t info;
 
     domid = (argc > 1) ? strtol(argv[1], NULL, 10) : 0;
 
@@ -18,13 +19,16 @@  int main(int argc, char **argv)
     if ( !xch )
         errx(1, "failed to open control interface");
 
-    for ( port = 0; ; port++ )
+    if ( xc_domain_getinfo_single(xch, domid, &info) < 0 )
+        errx(1, "failed to fetch domain info");
+
+    for ( port = 0; port <= info.highest_evtchn_port; port++ )
     {
         status.dom = domid;
         status.port = port;
         rc = xc_evtchn_status(xch, &status);
         if ( rc < 0 )
-            break;
+            continue;
 
         if ( status.status == EVTCHNSTAT_closed )
             continue;