diff mbox series

[XEN,v5] tools/lsevtchn: Use errno macro to handle hypercall error cases

Message ID f7bc11cc63a7b8596eb7a7c17f1e5c910f0009e5.1722263364.git.matthew.barnes@cloud.com (mailing list archive)
State Superseded
Headers show
Series [XEN,v5] tools/lsevtchn: Use errno macro to handle hypercall error cases | expand

Commit Message

Matthew Barnes July 29, 2024, 2:34 p.m. UTC
Currently, lsevtchn aborts its event channel enumeration when it hits
an event channel that is owned by Xen.

lsevtchn does not distinguish between different hypercall errors, which
results in lsevtchn missing potential relevant event channels with
higher port numbers.

Use the errno macro to distinguish between hypercall errors, and
continue event channel enumeration if the hypercall error is not
critical to enumeration.

Signed-off-by: Matthew Barnes <matthew.barnes@cloud.com>
---
Changes in v5:
- Code style changes to switch statement

Changes in v4:
- Catch non-critical errors and fail on everything else, instead of
  catching few known critical errors and ignoring everything else
- Use 'perror' to describe miscellaneous critical errors
- Return appropriate error code from lsevtchn tool
- Tweak commit description
---
 tools/xcutils/lsevtchn.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

Comments

Jan Beulich July 29, 2024, 2:44 p.m. UTC | #1
On 29.07.2024 16:34, Matthew Barnes wrote:
> @@ -58,7 +80,8 @@ int main(int argc, char **argv)
>          printf("\n");
>      }
>  
> +out:

Sorry didn't pay attention here (and can likely be taken care of when
committing, unless other comments arise): Labels want to be indented
by at least one blank. See ./CODING_STYLE.

Jan
diff mbox series

Patch

diff --git a/tools/xcutils/lsevtchn.c b/tools/xcutils/lsevtchn.c
index d1710613ddc5..b7d1b3d424ae 100644
--- a/tools/xcutils/lsevtchn.c
+++ b/tools/xcutils/lsevtchn.c
@@ -3,6 +3,7 @@ 
 #include <stdint.h>
 #include <string.h>
 #include <stdio.h>
+#include <errno.h>
 
 #include <xenctrl.h>
 
@@ -24,7 +25,28 @@  int main(int argc, char **argv)
         status.port = port;
         rc = xc_evtchn_status(xch, &status);
         if ( rc < 0 )
-            break;
+        {
+            switch ( errno )
+            {
+            case EACCES: /* Xen-owned evtchn */
+                continue;
+
+            case EINVAL: /* Port enumeration has ended */
+                rc = 0;
+                break;
+
+            case ESRCH:
+                perror("Domain ID does not correspond to valid domain");
+                rc = ESRCH;
+                break;
+
+            default:
+                perror(NULL);
+                rc = errno;
+                break;
+            }
+            goto out;
+        }
 
         if ( status.status == EVTCHNSTAT_closed )
             continue;
@@ -58,7 +80,8 @@  int main(int argc, char **argv)
         printf("\n");
     }
 
+out:
     xc_interface_close(xch);
 
-    return 0;
+    return rc;
 }