xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Yanzhang Li " <liyz@pku.edu.cn>
To: xen-devel@lists.xen.org
Subject: Suggestion: Improve hypercall Interface to get real return value
Date: Wed, 5 Dec 2012 14:21:20 +0800 (CST)	[thread overview]
Message-ID: <1141524074.6.1354688480672.JavaMail.root@bj-mail05.pku.edu.cn> (raw)

Hello everyone,

I am a user of Xen and I have encountered a problem when trying to get the return value from hypercall in TOOLS. I found that when programs in TOOLS called hypercall and failed, it would get return value -1 instead of the real return value given by Hypervisor.

The reason is that the hypercall interface of TOOLS uses ioctl to call hypercall, and ioctl will only return -1 when failure occurs. The related code is in xen-4.2.0/tools/libxc/xc_linux_osdep.c:
    static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
    {
        int fd = (int)h;
        return ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
    }

While I don't think this is a good idea, because some tools may wish to use real return value. For example, in xen-4.2.0/tools/memshr/interface.c, the function memshr_vbd_issue_ro_request will switch variable ret which comes from return value of hypercall do_memory_op:
    switch(ret)
    {
        case XENMEM_SHARING_OP_S_HANDLE_INVALID:
            ……
            break;
        case XENMEM_SHARING_OP_C_HANDLE_INVALID:
            ……
            break;
        default:
            break;
}

So I think if we could modify the interface a little bit to return the real error number, it would be beneficial to many TOOLS developers including myself. My suggested modification is simple:
    static int linux_privcmd_hypercall(xc_interface *xch, xc_osdep_handle h, privcmd_hypercall_t *hypercall)
    {
        int fd = (int)h;
        int ret = ioctl(fd, IOCTL_PRIVCMD_HYPERCALL, hypercall);
        if (ret < 0)
            return -errno;
        return ret;
    }

Do you think this would be a good modification? 
Also, I am curious why the original design didn't do that. Is it a bug or is it designed that way intentionally?
Any suggestions and comments will be highly appreciated.

Thanks!
Best Regards,
Yanzhang Li

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

             reply	other threads:[~2012-12-05  6:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-05  6:21 Yanzhang Li  [this message]
2012-12-05 11:05 ` Suggestion: Improve hypercall Interface to get real return value George Dunlap
2012-12-05 11:54   ` Mats Petersson
     [not found] <1320657526.120.1354947728395.JavaMail.root@bj-mail05.pku.edu.cn>
2012-12-08  6:44 ` Yanzhang Li 

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1141524074.6.1354688480672.JavaMail.root@bj-mail05.pku.edu.cn \
    --to=liyz@pku.edu.cn \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).