All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ross Lagerwall <ross.lagerwall@citrix.com>
To: Pawel Wieczorkiewicz <wipawel@amazon.de>,
	<xen-devel@lists.xenproject.org>
Cc: wipawel@amazon.com, "Ian Jackson" <ian.jackson@eu.citrix.com>,
	mpohlack@amazon.com, "Wei Liu" <wl@xen.org>,
	"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
Subject: Re: [Xen-devel] [PATCH v4 12/12] livepatch: Add python bindings for livepatch operations
Date: Mon, 30 Sep 2019 16:13:54 +0100	[thread overview]
Message-ID: <257215dc-4219-cae7-5d3d-af806664a5e3@citrix.com> (raw)
In-Reply-To: <20190928151305.127380-13-wipawel@amazon.de>

On 9/28/19 4:13 PM, Pawel Wieczorkiewicz wrote:
> Extend the XC python bindings library to support also all common
> livepatch operations and actions.
> 
> Add the python bindings for the following operations:
> - status (pyxc_livepatch_status):
>    Requires a payload name as an input.
>    Returns a status dict containing a state string and a return code
>    integer.
> - action (pyxc_livepatch_action):
>    Requires a payload name and an action id as an input. Timeout and
>    flags are optional parameters.
>    Returns None or throws an exception.
> - upload (pyxc_livepatch_upload):
>    Requires a payload name and a module's filename as an input.
>    Returns None or throws an exception.
> - list (pyxc_livepatch_list):
>    Takes no parameters.
>    Returns a list of dicts containing each payload's:
>    * name as a string
>    * state as a string
>    * return code as an integer
>    * list of metadata key=value strings
> 
> Each functions throws an exception error based on the errno value
> received from its corresponding libxc function call.
> 
snip> +static PyObject *pyxc_livepatch_upload(XcObject *self,
> +                                       PyObject *args,
> +                                       PyObject *kwds)
> +{
> +    unsigned char *fbuf = MAP_FAILED;
> +    char *name, *filename;
> +    struct stat buf;
> +    int fd = 0, rc = -1, saved_errno;
> +    ssize_t len;
> +
> +    static char *kwd_list[] = { "name", "filename", NULL };
> +
> +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "ss", kwd_list,
> +                                      &name, &filename))
> +        goto error;
> +
> +    fd = open(filename, O_RDONLY);
> +    if ( fd < 0 )
> +        goto error;
> +
> +    if ( fstat(fd, &buf) != 0 )
> +        goto error;
> +
> +    len = buf.st_size;
> +    fbuf = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0);
> +    if ( fbuf == MAP_FAILED )
> +        goto error;
> +
> +    rc = xc_livepatch_upload(self->xc_handle, name, fbuf, len);
> +
> +    saved_errno = errno;
> +    munmap(fbuf, len);
> +    close(fd);
> +    errno = saved_errno;
> +
> +error:
> +    return rc ? pyxc_error_to_exception(self->xc_handle) : Py_None;
> +}
> +
The fstat() and mmap() error paths leak fd on error.

Regards,
-- 
Ross Lagerwall

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-09-30 15:14 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-28 15:12 [Xen-devel] [PATCH v4 00/12] livepatch: new features and fixes Pawel Wieczorkiewicz
2019-09-28 15:12 ` [Xen-devel] [PATCH v4 01/12] livepatch: Always check hypervisor build ID upon livepatch upload Pawel Wieczorkiewicz
2019-09-28 15:12 ` [Xen-devel] [PATCH v4 02/12] livepatch: Allow to override inter-modules buildid dependency Pawel Wieczorkiewicz
2019-09-30 11:05   ` Jan Beulich
2019-09-30 11:14     ` Wieczorkiewicz, Pawel
2019-09-30 11:21       ` Jan Beulich
2019-11-08 10:36   ` Ross Lagerwall
2019-09-28 15:12 ` [Xen-devel] [PATCH v4 03/12] livepatch: Export payload structure via livepatch_payload.h Pawel Wieczorkiewicz
2019-09-28 15:12 ` [Xen-devel] [PATCH v4 04/12] livepatch: Implement pre-|post- apply|revert hooks Pawel Wieczorkiewicz
2019-11-08 10:43   ` Ross Lagerwall
2019-09-28 15:12 ` [Xen-devel] [PATCH v4 05/12] livepatch: Add support for apply|revert action replacement hooks Pawel Wieczorkiewicz
2019-09-28 15:12 ` [Xen-devel] [PATCH v4 06/12] livepatch: Do not enforce ELF_LIVEPATCH_FUNC section presence Pawel Wieczorkiewicz
2019-09-28 15:13 ` [Xen-devel] [PATCH v4 07/12] livepatch: Add per-function applied/reverted state tracking marker Pawel Wieczorkiewicz
2019-11-08 10:52   ` Ross Lagerwall
2019-09-28 15:13 ` [Xen-devel] [PATCH v4 08/12] livepatch: Add support for inline asm livepatching expectations Pawel Wieczorkiewicz
2019-09-28 15:13 ` [Xen-devel] [PATCH v4 09/12] livepatch: Add support for modules .modinfo section metadata Pawel Wieczorkiewicz
2019-09-28 15:13 ` [Xen-devel] [PATCH v4 10/12] livepatch: Handle arbitrary size names with the list operation Pawel Wieczorkiewicz
2019-09-30  8:50   ` Jan Beulich
2019-09-30 10:58     ` Wieczorkiewicz, Pawel
2019-09-30 11:11       ` Jan Beulich
2019-09-28 15:13 ` [Xen-devel] [PATCH v4 11/12] livepatch: Add metadata runtime retrieval mechanism Pawel Wieczorkiewicz
2019-09-28 15:13 ` [Xen-devel] [PATCH v4 12/12] livepatch: Add python bindings for livepatch operations Pawel Wieczorkiewicz
2019-09-30 15:13   ` Ross Lagerwall [this message]
2019-10-01  7:44     ` Wieczorkiewicz, Pawel
2019-10-18 14:25 ` [Xen-devel] [PATCH v4 00/12] livepatch: new features and fixes Konrad Rzeszutek Wilk
2019-10-18 15:34   ` Ross Lagerwall
2019-10-19 10:18     ` Wieczorkiewicz, Pawel
2019-10-19 13:46       ` Jürgen Groß

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=257215dc-4219-cae7-5d3d-af806664a5e3@citrix.com \
    --to=ross.lagerwall@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=marmarek@invisiblethingslab.com \
    --cc=mpohlack@amazon.com \
    --cc=wipawel@amazon.com \
    --cc=wipawel@amazon.de \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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 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.