[Libguestfs] [nbdkit PATCH v2 3/5] python: Update internals to plugin API level 2

Eric Blake eblake at redhat.com
Wed Apr 11 05:03:40 UTC 2018


Adjust internal functions in preparation for FUA support; although
at this point, the default plugins.c can_fua implementation
correctly reports python as needing emulation, and we can assert
that we aren't seeing a FUA flag.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 plugins/python/python.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/plugins/python/python.c b/plugins/python/python.c
index d75b36a..a50bf85 100644
--- a/plugins/python/python.c
+++ b/plugins/python/python.c
@@ -49,6 +49,7 @@
 #include <assert.h>
 #include <errno.h>

+#define NBDKIT_API_VERSION 2
 #include <nbdkit-plugin.h>

 /* XXX Apparently global state is technically wrong in Python 3, see:
@@ -430,12 +431,13 @@ py_get_size (void *handle)

 static int
 py_pread (void *handle, void *buf,
-          uint32_t count, uint64_t offset)
+          uint32_t count, uint64_t offset, uint32_t flags)
 {
   PyObject *obj = handle;
   PyObject *fn;
   PyObject *r;

+  assert (!flags);
   if (!callback_defined ("pread", &fn)) {
     nbdkit_error ("%s: missing callback: %s", script, "pread");
     return -1;
@@ -469,12 +471,13 @@ py_pread (void *handle, void *buf,

 static int
 py_pwrite (void *handle, const void *buf,
-           uint32_t count, uint64_t offset)
+           uint32_t count, uint64_t offset, uint32_t flags)
 {
   PyObject *obj = handle;
   PyObject *fn;
   PyObject *r;

+  assert (!flags);
   if (callback_defined ("pwrite", &fn)) {
     PyErr_Clear ();

@@ -495,12 +498,13 @@ py_pwrite (void *handle, const void *buf,
 }

 static int
-py_flush (void *handle)
+py_flush (void *handle, uint32_t flags)
 {
   PyObject *obj = handle;
   PyObject *fn;
   PyObject *r;

+  assert (!flags);
   if (callback_defined ("flush", &fn)) {
     PyErr_Clear ();

@@ -519,12 +523,13 @@ py_flush (void *handle)
 }

 static int
-py_trim (void *handle, uint32_t count, uint64_t offset)
+py_trim (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
 {
   PyObject *obj = handle;
   PyObject *fn;
   PyObject *r;

+  assert (!flags);
   if (callback_defined ("trim", &fn)) {
     PyErr_Clear ();

@@ -543,14 +548,16 @@ py_trim (void *handle, uint32_t count, uint64_t offset)
 }

 static int
-py_zero (void *handle, uint32_t count, uint64_t offset, int may_trim)
+py_zero (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
 {
   PyObject *obj = handle;
   PyObject *fn;
   PyObject *args;
   PyObject *kwargs;
   PyObject *r;
+  int may_trim = (flags & NBDKIT_FLAG_MAY_TRIM) != 0;

+  assert (!(flags & ~NBDKIT_FLAG_MAY_TRIM));
   if (callback_defined ("zero", &fn)) {
     static int zero_may_trim = -1;

-- 
2.14.3




More information about the Libguestfs mailing list