xen-hvm.c: Improve the return method for xen_hvm_init()
PATCH 1/1 xen-hvm.c: Improve the return method for xen_hvm_init()
When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too, then user can know the failure result more clearly.
xen_hvm_init() may also return -errno, which may let upper caller think more (e.g. free some other related resources and try again), although at present, all related upper callers still exit(1).
It is not a normal function which does not release related resources, if return -1. So need give the related comments for it.
It passes common test under fedora 20 x86_64:
"./configure --enable-xen && make -j4 && make check" execute result: "echo $? == 0".
--- xen-hvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
xen-hvm.c +3 -1
@@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,0 ); } +/* return value: 0 is OK, -errno is failure, -1 is critical issue -- exit(1) */ int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {
@@ -998,6 +999,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, state->xenstore =xs_daemon_open ();if (state->xenstore ==NULL ) {perror ("xen: xenstore open" ); +xc_evtchn_close (state->xce_handle);g_free (state);return -errno; }
@@ -1069,7 +1071,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,/* Initialize backend core & drivers */ if (xen_be_init () !=0 ) {fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__); -exit (1 ); +return -1 ; }xen_be_register ("console" , &xen_console_ops);xen_be_register ("vkbd" , &xen_kbdmouse_ops);
Signature · 1 line
1.9.3
Oh, sorry, forgot Cc to qemu trivial.
Thanks.
Quoted 51 lines · Chen Gang
When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too, then user can know the failure result more clearly.
xen_hvm_init()may also return -errno, which may let upper caller think more (e.g. free some other related resources and try again), although at present, all related upper callers still exit(1).It is not a normal function which does not release related resources, if return -1. So need give the related comments for it.
It passes common test under fedora 20
x86_64:"./configure --enable-xen && make -j4 && make check" execute result: "echo $? == 0".
Signed-off-by Chen Gang <[email protected]>--- xen-hvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen-hvm.c +3
-1@@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,0 ); } +/* return value: 0 is OK, -errno is failure, -1 is critical issue -- exit(1) */ int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {@@ -998,6 +999,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, state->xenstore =xs_daemon_open ();if (state->xenstore ==NULL ) {perror ("xen: xenstore open" ); +xc_evtchn_close (state->xce_handle);g_free (state);return -errno; }@@ -1069,7 +1071,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,/* Initialize backend core & drivers */ if (xen_be_init () !=0 ) {fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__); -exit (1 ); +return -1 ; }xen_be_register ("console" , &xen_console_ops);xen_be_register ("vkbd" , &xen_kbdmouse_ops);
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
Quoted 7 lines · Chen Gang
Oh, sorry, forgot Cc to qemu trivial.
Thanks.
Quoted 3 lines · Chen Gang
When failure occurs, it need use "return -1" instead of exit(1), so can let upper caller has chance to print failure information, too, then user can know the failure result more clearly.
good point
Quoted 3 lines
Quoted 3 lines
xen_hvm_init()may also return -errno, which may let upper caller think more (e.g. free some other related resources and try again), although at present, all related upper callers still exit(1).
I think we should return -1 in the other cases too
Quoted 21 lines
Quoted 21 lines
It is not a normal function which does not release related resources, if return -1. So need give the related comments for it.
It passes common test under fedora 20
x86_64:"./configure --enable-xen && make -j4 && make check" execute result: "echo $? == 0".
Signed-off-by Chen Gang <[email protected]>--- xen-hvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)xen-hvm.c +0
-0@@ -978,6 +978,7 @@ static void xen_wakeup_notifier(Notifier *notifier, void *data)xc_set_hvm_param (xen_xc, xen_domid,HVM_PARAM_ACPI_S_STATE ,0 ); }
Quoted 12 lines
xen-hvm.c int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, · line 1005
Quoted 12 lines
xen-hvm.c +2
-0+/* return value: 0 is OK, -errno is failure, -1 is critical issue -- exit(1) */ int xen_hvm_init (ram_addr_t *below_4g_mem_size,ram_addr_t *above_4g_mem_size,MemoryRegion **ram_memory) {@@ -998,6 +999,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, state->xenstore =xs_daemon_open ();if (state->xenstore ==NULL ) {perror ("xen: xenstore open" ); +xc_evtchn_close (state->xce_handle);g_free (state);return -errno; }
just return -1 and do the same in the above check (xce_handle == XC_HANDLER_INITIAL_VALUE)
Quoted 16 lines
Quoted 10 lines
xen-hvm.c +1
-1@@ -1069,7 +1071,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size,/* Initialize backend core & drivers */ if (xen_be_init () !=0 ) {fprintf (stderr,"%s: xen backend core setup failed\n" , __FUNCTION__); -exit (1 ); +return -1 ; }xen_be_register ("console" , &xen_console_ops);xen_be_register ("vkbd" , &xen_kbdmouse_ops);Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed
Quoted 2 lines · Stefano Stabellini
Quoted 1 line · Chen Gang
On 9/3/14 0:22, Chen Gang wrote:
[...]
Quoted 6 lines
Quoted 3 lines
Quoted 3 lines
xen_hvm_init()may also return -errno, which may let upper caller think more (e.g. free some other related resources and try again), although at present, all related upper callers still exit(1).I think we should return -1 in the other cases too
[...]
Quoted 13 lines
Quoted 8 lines
xen-hvm.c int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, · line 1005
Quoted 8 lines
xen-hvm.c +1
-0@@ -998,6 +999,7 @@ int xen_hvm_init(ram_addr_t *below_4g_mem_size, ram_addr_t *above_4g_mem_size, state->xenstore =xs_daemon_open ();if (state->xenstore ==NULL ) {perror ("xen: xenstore open" ); +xc_evtchn_close (state->xce_handle);g_free (state);return -errno; }just return -1 and do the same in the above check (
xce_handle==XC_HANDLER_INITIAL_VALUE)
OK thanks, what you said sounds OK to me. I shall send patch v2 for it within the 2 days (within 2014-09-05).
Thanks.
Signature · 3 lines
Chen Gang Open, share, and attitude like air, water, and life which God blessed