On Thu, Nov 21, 2019 at 4:52 PM Richard W.M. Jones <rjones(a)redhat.com> wrote:
 On Thu, Nov 21, 2019 at 02:17:43PM +0000, Daniel P. Berrangé wrote:
 > I would define a new 'api_version()' method for your python
 > plugins.
 >
 > Existing plugins don't implement that of course so when your
 > C code invokes that it'll get an exception, and can assume
 > the classic API contract for pwrite().
 >
 > If the plugin implements  'api_version()' returning '1' (or
 > whatever), then this should inform the C code that the plugin
 > has the 4 arg variant of pwrite().
 I suspect this has to be the way to go.  One reason is that
 the V1 zero API is defined as:
   def zero(h, count, offset, may_trim=False):
 but in V2 we'd like to replace the fourth parameter with a flags
 bitmask.  I believe pure introspection can never detect this. 
You can with:
   def using_api_v2(module):
       sig = inspect.signature(module.zero)
       return "flags" in sig.parameters
See 
https://www.redhat.com/archives/libguestfs/2019-November/msg00130.html
using it to discover if ImageTransfer supports "format" argument.
But I would add:
    API_VERSION = 2
And query it from the python plugin when importing the module.
Nir