All of lore.kernel.org
 help / color / mirror / Atom feed
* ioctl handling in netbsd_privcmd_hypercall()
@ 2012-01-18 16:21 Olaf Hering
  2012-01-18 17:37 ` Roger Pau Monné
  0 siblings, 1 reply; 4+ messages in thread
From: Olaf Hering @ 2012-01-18 16:21 UTC (permalink / raw)
  To: xen-devel


I was looking at the slightly broken error handling in the new
xc_mem_paging_load() function and stumbled over the ioctl() handling in
netbsd_privcmd_hypercall().

Is ioctl() on NetBSD special? I would have expected it returns -1 on
error and the caller can deal with errno if it actually wants to.
But instead it returns the negative errno value or what the hypervisor
returned.

static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
{   
    int fd = (int)h;
    int error = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);

    if (error < 0)
        return -errno;
    else
        return hypercall->retval;
}

I think do_domctl() is supposed to return -1 on error and let the caller
decide what to do. At least thats how its appearently done on Linux and
Solaris.

Olaf

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ioctl handling in netbsd_privcmd_hypercall()
  2012-01-18 16:21 ioctl handling in netbsd_privcmd_hypercall() Olaf Hering
@ 2012-01-18 17:37 ` Roger Pau Monné
  2012-01-18 18:01   ` Olaf Hering
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2012-01-18 17:37 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel

2012/1/18 Olaf Hering <olaf@aepfle.de>:
>
> I was looking at the slightly broken error handling in the new
> xc_mem_paging_load() function and stumbled over the ioctl() handling in
> netbsd_privcmd_hypercall().
>
> Is ioctl() on NetBSD special? I would have expected it returns -1 on
> error and the caller can deal with errno if it actually wants to.
> But instead it returns the negative errno value or what the hypervisor
> returned.

I haven't done this code, so I don't know if there are some hidden
subtleties here, but according to NetBSD ioctl(2) man page[0], it
returns -1 on error and errno is set to indicate the error.

> static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
> {
>    int fd = (int)h;
>    int error = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
>
>    if (error < 0)
>        return -errno;
>    else
>        return hypercall->retval;
> }
>
> I think do_domctl() is supposed to return -1 on error and let the caller
> decide what to do. At least thats how its appearently done on Linux and
> Solaris.

[0] http://netbsd.gw.com/cgi-bin/man-cgi?ioctl+.amd64+NetBSD-current

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ioctl handling in netbsd_privcmd_hypercall()
  2012-01-18 17:37 ` Roger Pau Monné
@ 2012-01-18 18:01   ` Olaf Hering
  2012-01-19 10:11     ` Roger Pau Monné
  0 siblings, 1 reply; 4+ messages in thread
From: Olaf Hering @ 2012-01-18 18:01 UTC (permalink / raw)
  To: Roger Pau Monné; +Cc: xen-devel

On Wed, Jan 18, Roger Pau Monné wrote:

> 2012/1/18 Olaf Hering <olaf@aepfle.de>:
> >
> > I was looking at the slightly broken error handling in the new
> > xc_mem_paging_load() function and stumbled over the ioctl() handling in
> > netbsd_privcmd_hypercall().
> >
> > Is ioctl() on NetBSD special? I would have expected it returns -1 on
> > error and the caller can deal with errno if it actually wants to.
> > But instead it returns the negative errno value or what the hypervisor
> > returned.
> 
> I haven't done this code, so I don't know if there are some hidden
> subtleties here, but according to NetBSD ioctl(2) man page[0], it
> returns -1 on error and errno is set to indicate the error.

Could you check wether a "return ioctl(....);" works as well?

Olaf

> > static int netbsd_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
> > {
> >    int fd = (int)h;
> >    int error = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
> >
> >    if (error < 0)
> >        return -errno;
> >    else
> >        return hypercall->retval;
> > }
> >
> > I think do_domctl() is supposed to return -1 on error and let the caller
> > decide what to do. At least thats how its appearently done on Linux and
> > Solaris.
> 
> [0] http://netbsd.gw.com/cgi-bin/man-cgi?ioctl+.amd64+NetBSD-current

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ioctl handling in netbsd_privcmd_hypercall()
  2012-01-18 18:01   ` Olaf Hering
@ 2012-01-19 10:11     ` Roger Pau Monné
  0 siblings, 0 replies; 4+ messages in thread
From: Roger Pau Monné @ 2012-01-19 10:11 UTC (permalink / raw)
  To: Olaf Hering; +Cc: xen-devel

2012/1/18 Olaf Hering <olaf@aepfle.de>:
> On Wed, Jan 18, Roger Pau Monné wrote:
>
>> 2012/1/18 Olaf Hering <olaf@aepfle.de>:
>> >
>> > I was looking at the slightly broken error handling in the new
>> > xc_mem_paging_load() function and stumbled over the ioctl() handling in
>> > netbsd_privcmd_hypercall().
>> >
>> > Is ioctl() on NetBSD special? I would have expected it returns -1 on
>> > error and the caller can deal with errno if it actually wants to.
>> > But instead it returns the negative errno value or what the hypervisor
>> > returned.
>>
>> I haven't done this code, so I don't know if there are some hidden
>> subtleties here, but according to NetBSD ioctl(2) man page[0], it
>> returns -1 on error and errno is set to indicate the error.
>
> Could you check wether a "return ioctl(....);" works as well?

I've checked it, and realized why NetBSD needs to return
hypercall->retval, that's because Linux ioctls return < 0 on error,
and >= 0 on success (you can return a meaningful value from ioctl[0]),
but NetBSD ioctls only return < 0 on error, or 0 on success. I've
spotted that memory operations return the size of the memory region on
success, that's why NetBSD needs to return hypercall->retval. What I
don't know if why it returns -errno on error, it should return the
return value of the ioctl call (error variable). I will submit a patch
adding a comment to netbsd_privcmd_hypercall and another one to return
error instead of -errno.

[0] http://linux.die.net/man/2/ioctl

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-19 10:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-18 16:21 ioctl handling in netbsd_privcmd_hypercall() Olaf Hering
2012-01-18 17:37 ` Roger Pau Monné
2012-01-18 18:01   ` Olaf Hering
2012-01-19 10:11     ` Roger Pau Monné

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.