tools/lsevtchn: Use errno macro to handle hypercall error cases
PATCH v4 1/1 tools/lsevtchn: Use errno macro to handle hypercall error cases
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.
---
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 | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
tools/xcutils/lsevtchn.c +20 -2
@@ -3,6 +3,7 @@#include <stdint.h> #include <string.h> #include <stdio.h> +#include <errno.h> #include <xenctrl.h>
@@ -24,7 +25,23 @@ int main(int argc, char **argv) status.port = port; rc =xc_evtchn_status (xch, &status);if ( rc <0 ) -break ; + { +switch ( errno ) { +case EACCES :continue ;/* Xen-owned evtchn */ +case EINVAL :/* Port enumeration has ended */ + rc =0 ; + goto out; + +case ESRCH : +perror ("Domain ID does not correspond to valid domain" ); + rc =ESRCH ; + goto out; +default : +perror (NULL ); + rc = errno; + goto out; + } + }if ( status.status == EVTCHNSTAT_closed )continue ;
@@ -58,7 +75,8 @@ int main(int argc, char **argv)printf ("\n" ); } +out:xc_interface_close (xch); -return 0 ; +return rc; }
Signature · 1 line
2.34.1
Quoted 12 lines · Matthew Barnes
tools/xcutils/lsevtchn.c +7
-1@@ -24,7 +25,23 @@ int main(int argc, char **argv) status.port = port; rc =xc_evtchn_status (xch, &status);if ( rc <0 ) -break ; + { +switch ( errno ) { +case EACCES :continue ;/* Xen-owned evtchn */ +case EINVAL :/* Port enumeration has ended */ + rc =0 ; + goto out; +
tools/xcutils/lsevtchn.c int main(int argc, char **argv) · line 44
Quoted 10 lines
tools/xcutils/lsevtchn.c +10
-0+case ESRCH : +perror ("Domain ID does not correspond to valid domain" ); + rc =ESRCH ; + goto out; +default : +perror (NULL ); + rc = errno; + goto out; + } + }
There are a number of style violations here: Opening figure brace placement, indentation of the case labels, placement of the "continue", lack of blank lines between non-fall-through case blocks. Also why three "goto out" when one would do?
Jan
Quoted 20 lines · Jan Beulich
Quoted 19 lines · Matthew Barnes
tools/xcutils/lsevtchn.c +14
-1@@ -24,7 +25,23 @@ int main(int argc, char **argv) status.port = port; rc =xc_evtchn_status (xch, &status);if ( rc <0 ) -break ; + { +switch ( errno ) { +case EACCES :continue ;/* Xen-owned evtchn */ +case EINVAL :/* Port enumeration has ended */ + rc =0 ; + goto out; + +case ESRCH : +perror ("Domain ID does not correspond to valid domain" ); + rc =ESRCH ; + goto out; +default : +perror (NULL ); + rc = errno;
Quoted 8 lines
tools/xcutils/lsevtchn.c int main(int argc, char **argv) · line 44
Quoted 3 lines
tools/xcutils/lsevtchn.c +3
-0+ goto out; + } + }There are a number of style violations here: Opening figure brace placement, indentation of the case labels, placement of the "continue", lack of blank lines between non-fall-through case blocks. Also why three "goto out" when one would do?
There's no particular reason why three "goto out"s were used.
I will tweak these style decisions in patch v5.
Matt