From: "Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
To: Pawel Wieczorkiewicz <wipawel@amazon.de>
Cc: wipawel@amazon.com, Wei Liu <wl@xen.org>,
Ian Jackson <ian.jackson@eu.citrix.com>,
mpohlack@amazon.com, xen-devel@lists.xen.org,
xen-devel@lists.xenproject.org
Subject: Re: [Xen-devel] [PATCH 14/14] livepatch: Add python bindings for livepatch operations
Date: Thu, 22 Aug 2019 23:55:42 +0200 [thread overview]
Message-ID: <20190822215542.GN1457@mail-itl> (raw)
In-Reply-To: <20190821081931.90887-15-wipawel@amazon.de>
[-- Attachment #1.1: Type: text/plain, Size: 5309 bytes --]
On Wed, Aug 21, 2019 at 08:19:31AM +0000, 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 a return code integer.
> - upload (pyxc_livepatch_upload):
> Requires a payload name and a module's filename as an input.
> Returns a return code integer.
> - 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.
>
> Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
> Reviewed-by: Martin Mazein <amazein@amazon.de>
> Reviewed-by: Andra-Irina Paraschiv <andraprs@amazon.com>
> Reviewed-by: Leonard Foerster <foersleo@amazon.de>
> Reviewed-by: Norbert Manthey <nmanthey@amazon.de>
> ---
> tools/python/xen/lowlevel/xc/xc.c | 273 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 273 insertions(+)
>
> diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
> index 7f0358ba9c..368739b996 100644
> --- a/tools/python/xen/lowlevel/xc/xc.c
> +++ b/tools/python/xen/lowlevel/xc/xc.c
(...)
> +static PyObject *pyxc_livepatch_list(XcObject *self)
> +{
> + PyObject *list;
> + unsigned int nr, done, left, i;
> + xen_livepatch_status_t *info = NULL;
> + char *name = NULL;
> + char *metadata = NULL;
> + uint32_t *len = NULL;
> + uint32_t *metadata_len = NULL;
> + uint64_t name_total_size, metadata_total_size;
> + off_t name_off, metadata_off;
> + int rc;
> +
> + rc = xc_livepatch_list_get_sizes(self->xc_handle, &nr,
> + &name_total_size, &metadata_total_size);
> + if ( rc )
> + goto error;
> +
> + if ( nr == 0 )
> + return PyList_New(0);
> +
> + rc = ENOMEM;
> + info = malloc(nr * sizeof(*info));
> + if ( !info )
> + goto error;
> +
> + name = malloc(name_total_size * sizeof(*name));
> + if ( !name )
> + goto error;
> +
> + len = malloc(nr * sizeof(*len));
> + if ( !len )
> + goto error;
> +
> + metadata = malloc(metadata_total_size * sizeof(*metadata));
> + if ( !metadata )
> + goto error;
> +
> + metadata_len = malloc(nr * sizeof(*metadata_len));
> + if ( !metadata_len )
> + goto error;
> +
> + rc = xc_livepatch_list(self->xc_handle, nr, 0, info,
> + name, len, name_total_size,
> + metadata, metadata_len, metadata_total_size,
> + &done, &left);
> + if ( rc )
> + goto error;
> +
> + list = PyList_New(0);
Previous remark stays:
Better use PyList_New(done) and later PyList_SetItem() instead of PyList_Append().
> + name_off = metadata_off = 0;
> + for ( i = 0; i < done; i++ )
> + {
> + PyObject *info_dict, *metadata_list;
> + char *name_str, *metadata_str;
> +
> + name_str = name + name_off;
> + metadata_str = metadata + metadata_off;
> +
> + metadata_list = PyList_New(0);
> + for ( char *s = metadata_str; s < metadata_str + metadata_len[i]; s += strlen(s) + 1 )
> + {
> + PyObject *field = Py_BuildValue("s", s);
> + if ( field == NULL )
> + {
> + Py_DECREF(list);
> + Py_DECREF(metadata_list);
> + rc = EFAULT;
> + goto error;
> + }
> +
> + PyList_Append(metadata_list, field);
> + Py_DECREF(field);
> + }
> +
> + info_dict = Py_BuildValue(
> + "{s:s,s:i,s:i,s:N}",
> + "name", name_str,
> + "state", info[i].state,
> + "rc", info[i].rc,
> + "metadata", metadata_list);
> +
> + if ( info_dict == NULL )
> + {
> + Py_DECREF(list);
> + Py_DECREF(metadata_list);
> + rc = EFAULT;
> + goto error;
> + }
> + PyList_Append(list, info_dict);
> + Py_DECREF(info_dict);
> +
> + name_off += len[i];
> + metadata_off += metadata_len[i];
> + }
> +
> +error:
> + free(info);
> + free(name);
> + free(len);
> + free(metadata);
> + free(metadata_len);
> + return rc ? pyxc_error_to_exception(self->xc_handle) : list;
> +}
> +
> static PyMethodDef pyxc_methods[] = {
> { "domain_create",
> (PyCFunction)pyxc_domain_create,
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 157 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-08-22 21:56 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-21 8:19 [Xen-devel] [PATCH 00/14] livepatch: new features and fixes Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 01/14] livepatch: Always check hypervisor build ID upon hotpatch upload Pawel Wieczorkiewicz
2019-08-21 18:16 ` Konrad Rzeszutek Wilk
2019-08-21 8:19 ` [Xen-devel] [PATCH 02/14] livepatch: Allow to override inter-modules buildid dependency Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 03/14] python: Add XC binding for Xen build ID Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 04/14] livepatch: Export payload structure via livepatch_payload.h Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 05/14] livepatch: Implement pre-|post- apply|revert hooks Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 06/14] livepatch: Add support for apply|revert action replacement hooks Pawel Wieczorkiewicz
2019-08-21 18:31 ` Konrad Rzeszutek Wilk
2019-08-21 19:06 ` Wieczorkiewicz, Pawel
2019-08-26 14:30 ` Konrad Rzeszutek Wilk
2019-08-21 8:19 ` [Xen-devel] [PATCH 07/14] livepatch: Do not enforce ELF_LIVEPATCH_FUNC section presence Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 08/14] livepatch: always print XENLOG_ERR information Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 09/14] livepatch: Add per-function applied/reverted state tracking marker Pawel Wieczorkiewicz
2019-08-21 18:28 ` Konrad Rzeszutek Wilk
2019-08-21 19:00 ` Wieczorkiewicz, Pawel
2019-08-21 21:34 ` Julien Grall
2019-08-22 7:44 ` Wieczorkiewicz, Pawel
2019-08-22 10:07 ` Julien Grall
2019-08-22 10:20 ` Wieczorkiewicz, Pawel
2019-08-22 10:43 ` Julien Grall
2019-08-22 11:15 ` Wieczorkiewicz, Pawel
2019-08-22 15:02 ` Julien Grall
2019-08-22 10:29 ` Julien Grall
2019-08-22 11:02 ` Wieczorkiewicz, Pawel
2019-08-22 15:30 ` Julien Grall
2019-08-22 15:42 ` Wieczorkiewicz, Pawel
2019-08-21 8:19 ` [Xen-devel] [PATCH 10/14] livepatch: Add support for inline asm hotpatching expectations Pawel Wieczorkiewicz
2019-08-21 18:30 ` Konrad Rzeszutek Wilk
2019-08-21 19:02 ` Wieczorkiewicz, Pawel
2019-08-22 10:31 ` Julien Grall
2019-08-22 11:03 ` Wieczorkiewicz, Pawel
2019-08-21 8:19 ` [Xen-devel] [PATCH 11/14] livepatch: Add support for modules .modinfo section metadata Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 12/14] livepatch: Handle arbitrary size names with the list operation Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 13/14] livepatch: Add metadata runtime retrieval mechanism Pawel Wieczorkiewicz
2019-08-21 8:19 ` [Xen-devel] [PATCH 14/14] livepatch: Add python bindings for livepatch operations Pawel Wieczorkiewicz
2019-08-22 21:55 ` Marek Marczykowski-Górecki [this message]
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 00/12] livepatch: new features and fixes Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 01/12] livepatch: Always check hypervisor build ID upon hotpatch upload Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 02/12] livepatch: Allow to override inter-modules buildid dependency Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 03/12] livepatch: Export payload structure via livepatch_payload.h Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 04/12] livepatch: Implement pre-|post- apply|revert hooks Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 05/12] livepatch: Add support for apply|revert action replacement hooks Pawel Wieczorkiewicz
2019-08-27 16:58 ` Konrad Rzeszutek Wilk
2019-08-28 7:37 ` Wieczorkiewicz, Pawel
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 06/12] livepatch: Do not enforce ELF_LIVEPATCH_FUNC section presence Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 07/12] livepatch: Add per-function applied/reverted state tracking marker Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 08/12] livepatch: Add support for inline asm hotpatching expectations Pawel Wieczorkiewicz
2019-08-29 14:34 ` Konrad Rzeszutek Wilk
2019-08-29 15:29 ` Wieczorkiewicz, Pawel
2019-08-29 15:58 ` Konrad Rzeszutek Wilk
2019-08-29 16:16 ` Wieczorkiewicz, Pawel
2019-08-29 17:49 ` Konrad Rzeszutek Wilk
2019-08-29 19:07 ` Wieczorkiewicz, Pawel
2019-08-29 20:48 ` Konrad Rzeszutek Wilk
2019-09-05 18:05 ` Konrad Rzeszutek Wilk
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 09/12] livepatch: Add support for modules .modinfo section metadata Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 10/12] livepatch: Handle arbitrary size names with the list operation Pawel Wieczorkiewicz
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 11/12] livepatch: Add metadata runtime retrieval mechanism Pawel Wieczorkiewicz
2019-08-29 20:48 ` Konrad Rzeszutek Wilk
2019-08-27 8:46 ` [Xen-devel] [PATCH v2 12/12] livepatch: Add python bindings for livepatch operations Pawel Wieczorkiewicz
2019-08-28 13:21 ` Marek Marczykowski-Górecki
2019-08-29 19:23 ` [Xen-devel] [PATCH v2 00/12] livepatch: new features and fixes Konrad Rzeszutek Wilk
2019-09-05 19:13 ` Konrad Rzeszutek Wilk
2019-09-06 22:52 ` Julien Grall
2019-09-06 22:42 ` Julien Grall
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=20190822215542.GN1457@mail-itl \
--to=marmarek@invisiblethingslab.com \
--cc=ian.jackson@eu.citrix.com \
--cc=mpohlack@amazon.com \
--cc=wipawel@amazon.com \
--cc=wipawel@amazon.de \
--cc=wl@xen.org \
--cc=xen-devel@lists.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.