libxc: avoid clobbering errno in xc_domain_pod_target()
PATCH 1/1 libxc: avoid clobbering errno in xc_domain_pod_target()
do_memory_op() supplies return value and has errno set the usual way. Don't overwrite errno with 1 (aka EPERM on at least Linux).
---
An alternative would be to let go of the DPRINTK() and leave errno and err alone altogether. While the hypervisor side of the hypercall gives the impression of being able to return positive values as of 637a283f17eb ("PoD: Allow pod_set_cache_target hypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here.
tools/libs/ctrl/xc_domain.c +2 -1
@@ -1231,10 +1231,11 @@ static int xc_domain_pod_target(xc_interif ( err <0 ) { + err = errno;DPRINTF ("Failed %s_pod_target dom %d\n" , (op==XENMEM_set_pod_target)?"set" :"get" , domid); - errno = -err; + errno = err; err =-1 ; }else
Quoted 15 lines · Jan Beulich
do_memory_op()supplies return value and has errno set the usual way. Don't overwrite errno with 1 (aka EPERM on at least Linux).Signed-off-by Jan Beulich <[email protected]>---
An alternative would be to let go of theDPRINTK()and leave errno and err alone altogether. While the hypervisor side of the hypercall gives the impression of being able to return positive values as of637a283f17eb("PoD: Allowpod_set_cache_targethypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here.
tools/libs/ctrl/xc_domain.c static int xc_domain_pod_target(xc_inter · line 1238
Quoted 9 lines
tools/libs/ctrl/xc_domain.c +2
-1@@ -1231,10 +1231,11 @@ static int xc_domain_pod_target(xc_interif ( err <0 ) { + err = errno;DPRINTF ("Failed %s_pod_target dom %d\n" , (op==XENMEM_set_pod_target)?"set" :"get" , domid); - errno = -err; + errno = err;
DPRINTF() won't change errno, so I think you should just drop the line overwriting errno.
Juergen
Quoted 13 lines · Juergen Gross
Quoted 12 lines · Jan Beulich
do_memory_op()supplies return value and has errno set the usual way. Don't overwrite errno with 1 (aka EPERM on at least Linux).Signed-off-by Jan Beulich <[email protected]>---
An alternative would be to let go of theDPRINTK()and leave errno and err alone altogether. While the hypervisor side of the hypercall gives the impression of being able to return positive values as of637a283f17eb("PoD: Allowpod_set_cache_targethypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here.
Quoted 14 lines
tools/libs/ctrl/xc_domain.c static int xc_domain_pod_target(xc_inter · line 1237
Quoted 11 lines
tools/libs/ctrl/xc_domain.c +2
-1@@ -1231,10 +1231,11 @@ static int xc_domain_pod_target(xc_inter if ( err < 0 ) { + err = errno; DPRINTF("Failed %s_pod_target dom %d\n", (op==XENMEM_set_pod_target)?"set":"get", domid); - errno = -err; + errno = err;
DPRINTF()won't change errno, so I think you should just drop the line overwriting errno.
In fact you added the 3rd layer of errno saving here. :-)
DPRINTF() and friends will save errno, and the underlying xc_report*() functions will do so, too.
Writing a patch to remove the saving at the macro layer...
Juergen
Quoted 29 lines · Juergen Gross
Quoted 13 lines · Juergen Gross
Quoted 12 lines · Jan Beulich
do_memory_op()supplies return value and has errno set the usual way. Don't overwrite errno with 1 (aka EPERM on at least Linux).Signed-off-by Jan Beulich <[email protected]>---
An alternative would be to let go of theDPRINTK()and leave errno and err alone altogether. While the hypervisor side of the hypercall gives the impression of being able to return positive values as of637a283f17eb("PoD: Allowpod_set_cache_targethypercall to be preempted"), due to the use of "rc >= 0" there, afaict that's not actually the case. IOW "err" can really only be 0 or -1 here.Quoted 14 lines
tools/libs/ctrl/xc_domain.c static int xc_domain_pod_target(xc_inter · line 1237
Quoted 11 lines
tools/libs/ctrl/xc_domain.c +2
-1@@ -1231,10 +1231,11 @@ static int xc_domain_pod_target(xc_inter if ( err < 0 ) { + err = errno; DPRINTF("Failed %s_pod_target dom %d\n", (op==XENMEM_set_pod_target)?"set":"get", domid); - errno = -err; + errno = err;
DPRINTF()won't change errno, so I think you should just drop the line overwriting errno.
Quoted 4 lines
In fact you added the 3rd layer of errno saving here. :-)
DPRINTF()and friends will save errno, and the underlying xc_report*() functions will do so, too.
I guess I should have checked ... Question is then whether setting "err" to 0 on the "else" path could/should then also be dropped (its setting to -1 clearly can be, and I already have it that way for v2).
Jan