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

Re: [libvirt] [libvirt-python PATCH v2] override: Implement bindings for virDomainGetFSInfo as domain.fsInfo



On 11/24/14, 11:30 , "Pavel Hrdina" <phrdina redhat com> wrote:

>On 11/22/2014 02:28 AM, Tomoki Sekiyama wrote:
>> Implement the function which returns a list of tuples, that contains
>>members
>> of virDomainFSInfo struct.
>>
>> Signed-off-by: Tomoki Sekiyama <tomoki sekiyama hds com>
>> ---
>>   generator.py             |    5 +++
>>   libvirt-override-api.xml |    6 ++++
>>   libvirt-override.c       |   70
>>++++++++++++++++++++++++++++++++++++++++++++++
>>   sanitytest.py            |    5 +++
>>   4 files changed, 85 insertions(+), 1 deletion(-)
>>
>> diff --git a/generator.py b/generator.py
>> index c66c6d4..20df54f 100755
>> --- a/generator.py
>> +++ b/generator.py
>> @@ -476,6 +476,7 @@ skip_impl = (
>>       'virNetworkGetDHCPLeases',
>>       'virDomainBlockCopy',
>>       'virNodeAllocPages',
>> +    'virDomainGetFSInfo',
>>   )
>>
>>   lxc_skip_impl = (
>> @@ -586,6 +587,7 @@ skip_function = (
>>
>>       'virNetworkDHCPLeaseFree', # only useful in C, python code uses
>>list
>>       'virDomainStatsRecordListFree', # only useful in C, python uses
>>dict
>> +    'virDomainFSInfoFree', # only useful in C, python code uses list
>>   )
>>
>>   lxc_skip_function = (
>> @@ -1107,6 +1109,9 @@ def nameFixup(name, classe, type, file):
>>       elif name[0:20] == "virDomainGetCPUStats":
>>           func = name[9:]
>>           func = func[0:1].lower() + func[1:]
>> +    elif name[0:18] == "virDomainGetFSInfo":
>> +        func = name[12:]
>> +        func = func[0:2].lower() + func[2:]
>>       elif name[0:12] == "virDomainGet":
>>           func = name[12:]
>>           func = func[0:1].lower() + func[1:]
>> diff --git a/libvirt-override-api.xml b/libvirt-override-api.xml
>> index 4fe3c4d..439cb40 100644
>> --- a/libvirt-override-api.xml
>> +++ b/libvirt-override-api.xml
>> @@ -658,5 +658,11 @@
>>         <arg name='flags' type='unsigned int' info='an OR&apos;ed set
>>of virNodeAllocPagesFlags'/>
>>         <return type='int' info='the number of nodes successfully
>>adjusted or -1 in case of an error'/>
>>       </function>
>> +    <function name="virDomainGetFSInfo" file='python'>
>> +      <info>Get a list of mapping information for each mounted file
>>systems within the specified guest and the disks.</info>
>> +      <arg name='domain' type='virDomainPtr' info='pointer to domain
>>object'/>
>> +      <arg name='flags' type='unsigned int' info='unused, pass 0'/>
>> +      <return type='char *' info="list of mounted filesystems
>>information"/>
>> +    </function>
>>     </symbols>
>>   </api>
>> diff --git a/libvirt-override.c b/libvirt-override.c
>> index 8895289..a91bf0d 100644
>> --- a/libvirt-override.c
>> +++ b/libvirt-override.c
>> @@ -8266,6 +8266,73 @@ libvirt_virNodeAllocPages(PyObject *self
>>ATTRIBUTE_UNUSED,
>>   }
>>   #endif /* LIBVIR_CHECK_VERSION(1, 2, 8) */
>>
>> +#if LIBVIR_CHECK_VERSION(1, 2, 11)
>> +
>> +static PyObject *
>> +libvirt_virDomainGetFSInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject
>>*args) {
>> +    virDomainPtr domain;
>> +    PyObject *pyobj_domain;
>> +    unsigned int flags;
>> +    virDomainFSInfoPtr *fsinfo = NULL;
>> +    char **dev;
>> +    int c_retval, i;
>> +    PyObject *py_retval;
>
>This should be initialized to NULL ... [1]
>
>> +
>> +    if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainFSInfo",
>> +        &pyobj_domain, &flags))
>> +        return NULL;
>> +    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
>> +
>> +    LIBVIRT_BEGIN_ALLOW_THREADS;
>> +    c_retval = virDomainGetFSInfo(domain, &fsinfo, flags);
>> +    LIBVIRT_END_ALLOW_THREADS;
>> +
>> +    if (c_retval < 0)
>> +        goto cleanup;
>> +
>> +    /* convert to a Python list */
>> +    if ((py_retval = PyList_New(c_retval)) == NULL)
>> +        goto cleanup;
>> +
>> +    for (i = 0; i < c_retval; i++) {
>> +        virDomainFSInfoPtr fs = fsinfo[i];
>> +        PyObject *info, *alias;
>> +
>> +        if (fs == NULL)
>> +            goto cleanup;
>> +        info = PyTuple_New(4);
>> +        if (info == NULL)
>> +            goto cleanup;
>> +        PyList_SetItem(py_retval, i, info);
>> +        alias = PyList_New(0);
>> +        if (alias == NULL)
>> +            goto cleanup;
>> +
>> +        PyTuple_SetItem(info, 0,
>>libvirt_constcharPtrWrap(fs->mountpoint));
>> +        PyTuple_SetItem(info, 1, libvirt_constcharPtrWrap(fs->name));
>> +        PyTuple_SetItem(info, 2, libvirt_constcharPtrWrap(fs->type));
>
>There should be fstype instead of type.
>
>> +        PyTuple_SetItem(info, 3, alias);
>> +
>> +        for (dev = fs->devAlias; dev && *dev; dev++)
>>+            if (PyList_Append(alias, libvirt_constcharPtrWrap(*dev)) <
>>0)
>> +                goto cleanup;
>> +    }
>> +
>> +    for (i = 0; i < c_retval; i++)
>> +        virDomainFSInfoFree(fsinfo[i]);
>> +    VIR_FREE(fsinfo);
>> +    return py_retval;
>> +
>> + cleanup:
>> +    for (i = 0; i < c_retval; i++)
>> +        virDomainFSInfoFree(fsinfo[i]);
>> +    VIR_FREE(fsinfo);
>> +    Py_XDECREF(py_retval);
>
>[1] ... otherwise there it will crash with segfautl.
>
>> +    return VIR_PY_NONE;
>> +}
>> +
>> +#endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
>> +
>>   
>>/************************************************************************
>>    *									*
>>    *			The registration stuff				*
>> @@ -8459,6 +8526,9 @@ static PyMethodDef libvirtMethods[] = {
>>   #if LIBVIR_CHECK_VERSION(1, 2, 9)
>>       {(char *) "virNodeAllocPages", libvirt_virNodeAllocPages,
>>METH_VARARGS, NULL},
>>   #endif /* LIBVIR_CHECK_VERSION(1, 2, 9) */
>> +#if LIBVIR_CHECK_VERSION(1, 2, 11)
>> +    {(char *) "virDomainGetFSInfo", libvirt_virDomainGetFSInfo,
>>METH_VARARGS, NULL},
>> +#endif /* LIBVIR_CHECK_VERSION(1, 2, 11) */
>>       {NULL, NULL, 0, NULL}
>>   };
>>
>> diff --git a/sanitytest.py b/sanitytest.py
>> index b161696..f5337fc 100644
>> --- a/sanitytest.py
>> +++ b/sanitytest.py
>> @@ -137,6 +137,9 @@ for cname in wantfunctions:
>>       if name[0:28] == "virDomainStatsRecordListFree":
>>           continue
>>
>> +    if name[0:19] == "virDomainFSInfoFree":
>> +        continue
>> +
>>       if name[0:21] == "virDomainListGetStats":
>>           name = "virConnectDomainListGetStats"
>>
>> @@ -269,7 +272,7 @@ for name in sorted(basicklassmap):
>>       func = func[0:1].lower() + func[1:]
>>       if func[0:8] == "nWFilter":
>>           func = "nwfilter" + func[8:]
>> -    if func[0:8] == "fSFreeze" or func[0:6] == "fSThaw":
>> +    if func[0:8] == "fSFreeze" or func[0:6] == "fSThaw" or func[0:6]
>>== "fSInfo":
>>           func = "fs" + func[2:]
>>
>>       if klass == "virNetwork":
>>
>
>ACK with the changes. I'll update the commit and push it.

Whoa, it seems I forgot to git-add some of the changes. Sorry about this.
And thank you for fixing this up.


Thanks,
Tomoki Sekiyama



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