[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v4 12/12] livepatch: Add python bindings for livepatch operations



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@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.