[Libguestfs] [PATCH nbdkit v2 02/10] python: Add various constants to the API.

Richard W.M. Jones rjones at redhat.com
Fri Nov 22 20:50:00 UTC 2019


On Fri, Nov 22, 2019 at 10:05:15PM +0200, Nir Soffer wrote:
> On Fri, Nov 22, 2019 at 9:54 PM Richard W.M. Jones <rjones at redhat.com> wrote:
> >
> > These are accessible from the plugin by:
> >
> >   import nbdkit
> >
> >   if flags & nbdkit.FLAG_MAY_TRIM:
> >   &c.
> 
> Nice way to expose the flags!
> 
> > Many (all?) of these are not yet useful for plugins, some will never
> > be useful, but they only consume a tiny bit of memory and it's nice to
> > have the complete set available for future use.
> > ---
> >  plugins/python/python.c | 27 +++++++++++++++++++++++++++
> >  1 file changed, 27 insertions(+)
> >
> > diff --git a/plugins/python/python.c b/plugins/python/python.c
> > index d65ac45..69cf4e9 100644
> > --- a/plugins/python/python.c
> > +++ b/plugins/python/python.c
> > @@ -231,6 +231,33 @@ create_nbdkit_module (void)
> >      nbdkit_error ("could not create the nbdkit API module");
> >      exit (EXIT_FAILURE);
> >    }
> > +
> > +  /* Constants corresponding to various flags. */
> > +  PyModule_AddIntConstant (m, "THREAD_MODEL_SERIALIZE_CONNECTIONS",
> > +                           NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS);
> 
> This can fail and needs cleanup. Very unlikely and a lot of code in
> the standard library have
> this issue.
> 
> In sanlock we do:
> 
>     if (PyModule_AddIntConstant(m, "LSFLAG_ADD", SANLK_LSF_ADD))
>         return -1;
> 
> And the caller decref the module object and return NULL.
> 
> See
> https://github.com/nirs/sanlock/blob/53f7f0284c084ac2e4542fd1f71d0406075adb5d/python/sanlock.c#L1846
> https://github.com/nirs/sanlock/blob/53f7f0284c084ac2e4542fd1f71d0406075adb5d/python/sanlock.c#L1763

Yes I can make this change.  It's worth it in case there is some
subtle Python API change in future that we need to be aware of.

We can in fact exit if load() fails so I guess we don't need to bother
doing the PY_DECREF for this case.

Thanks,

Rich.

> > +  PyModule_AddIntConstant (m, "THREAD_MODEL_SERIALIZE_ALL_REQUESTS",
> > +                           NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS);
> > +  PyModule_AddIntConstant (m, "THREAD_MODEL_SERIALIZE_REQUESTS",
> > +                           NBDKIT_THREAD_MODEL_SERIALIZE_REQUESTS);
> > +  PyModule_AddIntConstant (m, "THREAD_MODEL_PARALLEL",
> > +                           NBDKIT_THREAD_MODEL_PARALLEL);
> > +
> > +  PyModule_AddIntConstant (m, "FLAG_MAY_TRIM",  NBDKIT_FLAG_MAY_TRIM);
> > +  PyModule_AddIntConstant (m, "FLAG_FUA",       NBDKIT_FLAG_FUA);
> > +  PyModule_AddIntConstant (m, "FLAG_REQ_ONE",   NBDKIT_FLAG_REQ_ONE);
> > +  PyModule_AddIntConstant (m, "FLAG_FAST_ZERO", NBDKIT_FLAG_FAST_ZERO);
> > +
> > +  PyModule_AddIntConstant (m, "FUA_NONE",       NBDKIT_FUA_NONE);
> > +  PyModule_AddIntConstant (m, "FUA_EMULATE",    NBDKIT_FUA_EMULATE);
> > +  PyModule_AddIntConstant (m, "FUA_NATIVE",     NBDKIT_FUA_NATIVE);
> > +
> > +  PyModule_AddIntConstant (m, "CACHE_NONE",     NBDKIT_CACHE_NONE);
> > +  PyModule_AddIntConstant (m, "CACHE_EMULATE",  NBDKIT_CACHE_EMULATE);
> > +  PyModule_AddIntConstant (m, "CACHE_NATIVE",   NBDKIT_CACHE_NATIVE);
> > +
> > +  PyModule_AddIntConstant (m, "EXTENT_HOLE",    NBDKIT_EXTENT_HOLE);
> > +  PyModule_AddIntConstant (m, "EXTENT_ZERO",    NBDKIT_EXTENT_ZERO);
> > +
> >    return m;
> >  }
> >
> > --
> > 2.23.0
> >

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v




More information about the Libguestfs mailing list