2012-10-12 05:08:47 +04:00
/*
* Liblvm - - Python interface to LVM2 API .
*
2013-06-18 23:13:27 +04:00
* Copyright ( C ) 2010 , 2013 Red Hat , Inc . All rights reserved .
2012-10-12 05:08:47 +04:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation , either version 2.1 of the License , or
* ( at your option ) any later version .
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Lesser General Public License for more details .
* You should have received a copy of the GNU Lesser General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
*
* Authors : Lars Sjostrom ( lars sjostrom redhat com )
* Andy Grover ( agrover redhat com )
* Tony Asleson ( tasleson redhat com )
*/
# include <Python.h>
# include "lvm2app.h"
2013-09-11 03:05:28 +04:00
# include "defaults.h"
2012-10-12 05:08:47 +04:00
2014-09-02 17:42:01 +04:00
# if PY_MAJOR_VERSION >= 3
# define IS_PY3K
# define PYINTTYPE_CHECK PyLong_Check
# define PYINTTYPE_ASLONG PyLong_AsLong
# define PYINTTYPE_FROMLONG PyLong_FromLong
# define PYSTRYPE_CHECK PyUnicode_Check
# define PYSTRTYPE_ASSTRING PyUnicode_AsUTF8
# define PYSTRTYPE_FROMSTRING PyUnicode_FromString
# else
# define PYINTTYPE_CHECK PyInt_Check
# define PYINTTYPE_ASLONG PyInt_AsLong
# define PYINTTYPE_FROMLONG PyInt_FromLong
# define PYSTRYPE_CHECK PyString_Check
# define PYSTRTYPE_ASSTRING PyString_AsString
# define PYSTRTYPE_FROMSTRING PyString_FromString
# endif
2013-07-19 17:33:26 +04:00
static lvm_t _libh ;
2012-10-16 00:26:01 +04:00
2012-10-12 05:08:47 +04:00
typedef struct {
PyObject_HEAD
2012-12-14 22:32:35 +04:00
vg_t vg ; /* vg handle */
2013-08-01 00:16:01 +04:00
lvm_t libh_copy ;
2012-10-12 05:08:47 +04:00
} vgobject ;
2013-03-20 01:37:04 +04:00
typedef struct {
PyObject_HEAD
struct dm_list * pvslist ;
2013-08-01 00:16:01 +04:00
lvm_t libh_copy ;
2013-03-20 01:37:04 +04:00
} pvslistobject ;
2012-10-12 05:08:47 +04:00
typedef struct {
PyObject_HEAD
2012-12-14 22:32:35 +04:00
lv_t lv ; /* lv handle */
vgobject * parent_vgobj ;
2012-10-12 05:08:47 +04:00
} lvobject ;
typedef struct {
PyObject_HEAD
2012-12-14 22:32:35 +04:00
pv_t pv ; /* pv handle */
vgobject * parent_vgobj ;
2013-03-20 01:37:04 +04:00
pvslistobject * parent_pvslistobj ;
2012-10-12 05:08:47 +04:00
} pvobject ;
typedef struct {
PyObject_HEAD
2012-12-14 22:32:35 +04:00
lvseg_t lv_seg ; /* lv segment handle */
lvobject * parent_lvobj ;
2012-10-12 05:08:47 +04:00
} lvsegobject ;
typedef struct {
PyObject_HEAD
2012-12-14 22:32:35 +04:00
pvseg_t pv_seg ; /* pv segment handle */
pvobject * parent_pvobj ;
2012-10-12 05:08:47 +04:00
} pvsegobject ;
2013-07-19 17:33:26 +04:00
static PyTypeObject _LibLVMvgType ;
static PyTypeObject _LibLVMlvType ;
static PyTypeObject _LibLVMpvlistType ;
static PyTypeObject _LibLVMpvType ;
static PyTypeObject _LibLVMlvsegType ;
static PyTypeObject _LibLVMpvsegType ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
static PyObject * _LibLVMError ;
2012-10-12 05:08:47 +04:00
2013-08-01 00:16:01 +04:00
# define LVM_VALID(ptr) \
2013-07-19 17:33:26 +04:00
do { \
2016-05-11 21:42:00 +03:00
if ( ! _libh ) { \
_libh = lvm_init ( NULL ) ; \
} \
2013-08-01 00:16:01 +04:00
if ( ptr & & _libh ) { \
if ( ptr ! = _libh ) { \
PyErr_SetString ( PyExc_UnboundLocalError , " LVM handle reference stale " ) ; \
return NULL ; \
} \
} else if ( ! _libh ) { \
2012-10-16 00:26:01 +04:00
PyErr_SetString ( PyExc_UnboundLocalError , " LVM handle invalid " ) ; \
2013-07-19 17:33:26 +04:00
return NULL ; \
} \
2012-10-12 05:08:47 +04:00
} while ( 0 )
2013-06-18 23:13:27 +04:00
/**
* Ensure that we initialize all the bits to a sane state .
*/
2013-07-19 17:33:26 +04:00
static pvobject * _create_py_pv ( void )
2013-06-18 23:13:27 +04:00
{
2013-07-19 17:33:26 +04:00
pvobject * pvobj = PyObject_New ( pvobject , & _LibLVMpvType ) ;
2013-06-18 23:13:27 +04:00
if ( pvobj ) {
pvobj - > pv = NULL ;
pvobj - > parent_vgobj = NULL ;
pvobj - > parent_pvslistobj = NULL ;
}
2013-07-19 17:33:26 +04:00
2013-06-18 23:13:27 +04:00
return pvobj ;
}
2013-07-19 17:33:26 +04:00
static vgobject * _create_py_vg ( void )
2013-06-18 23:13:27 +04:00
{
2013-07-19 17:33:26 +04:00
vgobject * vgobj = PyObject_New ( vgobject , & _LibLVMvgType ) ;
2013-08-01 00:16:01 +04:00
if ( vgobj ) {
2013-06-18 23:13:27 +04:00
vgobj - > vg = NULL ;
2013-08-01 00:16:01 +04:00
vgobj - > libh_copy = _libh ;
}
2013-07-19 17:33:26 +04:00
2013-06-18 23:13:27 +04:00
return vgobj ;
}
2013-08-01 00:16:01 +04:00
static pvslistobject * _create_py_pvlist ( void )
{
pvslistobject * pvlistobj = PyObject_New ( pvslistobject , & _LibLVMpvlistType ) ;
if ( pvlistobj ) {
pvlistobj - > pvslist = NULL ;
pvlistobj - > libh_copy = _libh ;
}
return pvlistobj ;
}
static lvobject * _create_py_lv ( vgobject * parent , lv_t lv )
{
lvobject * lvobj = PyObject_New ( lvobject , & _LibLVMlvType ) ;
if ( lvobj ) {
lvobj - > parent_vgobj = parent ;
Py_INCREF ( lvobj - > parent_vgobj ) ;
lvobj - > lv = lv ;
}
return lvobj ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_get_last_error ( void )
2012-10-12 05:08:47 +04:00
{
PyObject * info ;
2013-09-26 21:19:18 +04:00
const char * msg = NULL ;
2012-10-12 05:08:47 +04:00
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( ! ( info = PyTuple_New ( 2 ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2014-09-02 17:42:01 +04:00
PyTuple_SetItem ( info , 0 , PYINTTYPE_FROMLONG ( ( long ) lvm_errno ( _libh ) ) ) ;
2013-09-26 21:19:18 +04:00
msg = lvm_errmsg ( _libh ) ;
2014-09-02 17:42:01 +04:00
PyTuple_SetItem ( info , 1 , ( ( msg ) ? PYSTRTYPE_FROMSTRING ( msg ) :
PYSTRTYPE_FROMSTRING ( " Memory error while retrieving error message " ) ) ) ;
2012-10-12 05:08:47 +04:00
return info ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_library_get_version ( void )
2012-10-12 05:08:47 +04:00
{
return Py_BuildValue ( " s " , lvm_library_get_version ( ) ) ;
}
2013-07-19 17:33:26 +04:00
static const char _gc_doc [ ] = " Garbage collect the C library " ;
2013-07-19 00:53:43 +04:00
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_gc ( void )
2013-07-19 00:53:43 +04:00
{
2016-05-11 21:42:00 +03:00
if ( _libh ) {
lvm_quit ( _libh ) ;
_libh = NULL ;
2013-07-19 00:53:43 +04:00
}
2013-07-19 17:33:26 +04:00
2013-07-19 00:53:43 +04:00
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2013-07-19 00:53:43 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_list_vg_names ( void )
2012-10-12 05:08:47 +04:00
{
struct dm_list * vgnames ;
struct lvm_str_list * strl ;
PyObject * pytuple ;
int i = 0 ;
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( ! ( vgnames = lvm_list_vg_names ( _libh ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( vgnames ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
dm_list_iterate_items ( strl , vgnames ) {
2014-09-02 17:42:01 +04:00
PyTuple_SET_ITEM ( pytuple , i , PYSTRTYPE_FROMSTRING ( strl - > str ) ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_list_vg_uuids ( void )
2012-10-12 05:08:47 +04:00
{
struct dm_list * uuids ;
struct lvm_str_list * strl ;
PyObject * pytuple ;
int i = 0 ;
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( ! ( uuids = lvm_list_vg_uuids ( _libh ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( uuids ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
dm_list_iterate_items ( strl , uuids ) {
2014-09-02 17:42:01 +04:00
PyTuple_SET_ITEM ( pytuple , i , PYSTRTYPE_FROMSTRING ( strl - > str ) ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pvlist_get ( pvslistobject * pvsobj )
2013-03-20 01:37:04 +04:00
{
struct lvm_pv_list * pvl ;
PyObject * pytuple ;
pvobject * pvobj ;
int i = 0 ;
/* unlike other LVM api calls, if there are no results, we get NULL */
2013-07-19 17:33:26 +04:00
pvsobj - > pvslist = lvm_list_pvs ( _libh ) ;
2013-03-20 01:37:04 +04:00
if ( ! pvsobj - > pvslist )
return Py_BuildValue ( " () " ) ;
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( pvsobj - > pvslist ) ) ) )
2013-03-20 01:37:04 +04:00
return NULL ;
dm_list_iterate_items ( pvl , pvsobj - > pvslist ) {
/* Create and initialize the object */
2013-07-19 17:33:26 +04:00
if ( ! ( pvobj = _create_py_pv ( ) ) ) {
2013-03-20 01:37:04 +04:00
Py_DECREF ( pytuple ) ;
return NULL ;
}
/* We don't have a parent vg object to be concerned about */
pvobj - > parent_vgobj = NULL ;
pvobj - > parent_pvslistobj = pvsobj ;
Py_INCREF ( pvobj - > parent_pvslistobj ) ;
pvobj - > pv = pvl - > pv ;
PyTuple_SET_ITEM ( pytuple , i , ( PyObject * ) pvobj ) ;
i + + ;
}
return pytuple ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pvlist_put ( pvslistobject * self )
2013-03-20 01:37:04 +04:00
{
if ( self - > pvslist ) {
2013-07-19 17:33:26 +04:00
if ( lvm_list_pvs_free ( self - > pvslist ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2013-03-20 01:37:04 +04:00
return NULL ;
}
self - > pvslist = NULL ;
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2013-03-20 01:37:04 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
2013-03-20 01:37:04 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_pvlist_dealloc ( pvslistobject * self )
2013-03-20 01:37:04 +04:00
{
2013-07-19 17:33:26 +04:00
if ( self - > pvslist )
_liblvm_lvm_pvlist_put ( self ) ;
2013-03-20 01:37:04 +04:00
PyObject_Del ( self ) ;
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2013-03-20 01:37:04 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_list_pvs ( void )
2013-03-20 01:37:04 +04:00
{
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2013-03-20 01:37:04 +04:00
2013-08-01 00:16:01 +04:00
return ( PyObject * ) _create_py_pvlist ( ) ;
2013-03-20 01:37:04 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_remove ( PyObject * self , PyObject * arg )
2013-04-03 00:10:57 +04:00
{
const char * pv_name ;
2013-07-19 17:33:26 +04:00
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2013-04-03 00:10:57 +04:00
if ( ! PyArg_ParseTuple ( arg , " s " , & pv_name ) )
2013-07-19 17:33:26 +04:00
return NULL ;
2013-04-03 00:10:57 +04:00
2013-07-19 17:33:26 +04:00
if ( lvm_pv_remove ( _libh , pv_name ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2013-04-03 00:10:57 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2013-04-03 00:10:57 +04:00
return Py_None ;
}
2013-09-11 03:05:28 +04:00
static int _set_pv_numeric_prop ( pv_create_params_t pv_params , const char * name ,
unsigned long long value )
{
2014-11-13 19:42:09 +03:00
struct lvm_property_value prop_value = {
. is_integer = 1 ,
. value . integer = value ,
} ;
2013-09-11 03:05:28 +04:00
return lvm_pv_params_set_property ( pv_params , name , & prop_value ) ;
}
# define SET_PV_PROP(params, name, value) \
do { \
if ( _set_pv_numeric_prop ( params , name , value ) = = - 1 ) \
goto error ; \
} while ( 0 ) \
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_create ( PyObject * self , PyObject * arg )
2013-04-04 01:54:12 +04:00
{
const char * pv_name ;
2013-09-11 03:05:28 +04:00
unsigned long long size = 0 ;
unsigned long long pvmetadatacopies = DEFAULT_PVMETADATACOPIES ;
unsigned long long pvmetadatasize = DEFAULT_PVMETADATASIZE ;
unsigned long long data_alignment = 0 ;
unsigned long long data_alignment_offset = 0 ;
unsigned long long zero = 1 ;
pv_create_params_t pv_params = NULL ;
2013-07-19 17:33:26 +04:00
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2013-04-04 01:54:12 +04:00
2013-09-11 03:05:28 +04:00
if ( ! PyArg_ParseTuple ( arg , " s|KKKKKK " , & pv_name , & size , & pvmetadatacopies ,
& pvmetadatasize , & data_alignment ,
& data_alignment_offset , & zero ) )
2013-07-19 17:33:26 +04:00
return NULL ;
2013-04-04 01:54:12 +04:00
2013-09-11 03:05:28 +04:00
pv_params = lvm_pv_params_create ( _libh , pv_name ) ;
if ( ! pv_params ) {
goto error ;
2013-04-04 01:54:12 +04:00
}
2013-09-11 03:05:28 +04:00
SET_PV_PROP ( pv_params , " size " , size ) ;
SET_PV_PROP ( pv_params , " pvmetadatacopies " , pvmetadatacopies ) ;
SET_PV_PROP ( pv_params , " pvmetadatasize " , pvmetadatasize ) ;
SET_PV_PROP ( pv_params , " data_alignment " , data_alignment ) ;
SET_PV_PROP ( pv_params , " data_alignment_offset " , data_alignment_offset ) ;
SET_PV_PROP ( pv_params , " zero " , zero ) ;
if ( lvm_pv_create_adv ( pv_params ) ) {
goto error ;
}
2013-07-19 17:33:26 +04:00
2013-09-11 03:05:28 +04:00
Py_INCREF ( Py_None ) ;
2013-04-04 01:54:12 +04:00
return Py_None ;
2013-09-11 03:05:28 +04:00
error :
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
2013-04-04 01:54:12 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_percent_to_float ( PyObject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
double converted ;
int percent ;
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
if ( ! PyArg_ParseTuple ( arg , " i " , & percent ) )
return NULL ;
converted = lvm_percent_to_float ( percent ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_BuildValue ( " d " , converted ) ;
}
2013-09-26 20:39:40 +04:00
static PyObject * _liblvm_lvm_vg_name_validate ( PyObject * self , PyObject * arg )
{
const char * name ;
LVM_VALID ( NULL ) ;
if ( ! PyArg_ParseTuple ( arg , " s " , & name ) )
return NULL ;
if ( lvm_vg_name_validate ( _libh , name ) < 0 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vgname_from_pvid ( PyObject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
const char * pvid ;
const char * vgname ;
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
if ( ! PyArg_ParseTuple ( arg , " s " , & pvid ) )
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( vgname = lvm_vgname_from_pvid ( _libh , pvid ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
return Py_BuildValue ( " s " , vgname ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vgname_from_device ( PyObject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
const char * device ;
const char * vgname ;
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
if ( ! PyArg_ParseTuple ( arg , " s " , & device ) )
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( vgname = lvm_vgname_from_device ( _libh , device ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
return Py_BuildValue ( " s " , vgname ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_config_find_bool ( PyObject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
const char * config ;
int rval ;
PyObject * rc ;
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
if ( ! PyArg_ParseTuple ( arg , " s " , & config ) )
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ( rval = lvm_config_find_bool ( _libh , config , - 10 ) ) = = - 10 ) {
2012-10-12 05:08:47 +04:00
/* Retrieving error information yields no error in this case */
PyErr_Format ( PyExc_ValueError , " config path not found " ) ;
return NULL ;
}
rc = ( rval ) ? Py_True : Py_False ;
Py_INCREF ( rc ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return rc ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_config_reload ( void )
2012-10-12 05:08:47 +04:00
{
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( lvm_config_reload ( _libh ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_scan ( void )
2012-10-12 05:08:47 +04:00
{
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( lvm_scan ( _libh ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_config_override ( PyObject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
const char * config ;
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
if ( ! PyArg_ParseTuple ( arg , " s " , & config ) )
return NULL ;
2013-07-19 17:33:26 +04:00
if ( lvm_config_override ( _libh , config ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
/* ----------------------------------------------------------------------
* VG object initialization / deallocation
*/
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_open ( PyObject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * vgname ;
const char * mode = NULL ;
2012-10-16 00:26:01 +04:00
vgobject * vgobj ;
2012-10-12 05:08:47 +04:00
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " s|s " , & vgname , & mode ) )
2012-10-12 05:08:47 +04:00
return NULL ;
if ( mode = = NULL )
mode = " r " ;
2013-07-19 17:33:26 +04:00
if ( ! ( vgobj = _create_py_vg ( ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( vgobj - > vg = lvm_vg_open ( _libh , vgname , mode , 0 ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-26 02:31:11 +04:00
Py_DECREF ( vgobj ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2012-10-16 00:26:01 +04:00
return ( PyObject * ) vgobj ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_create ( PyObject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * vgname ;
2012-10-16 00:26:01 +04:00
vgobject * vgobj ;
2012-10-12 05:08:47 +04:00
2013-08-01 00:16:01 +04:00
LVM_VALID ( NULL ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & vgname ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( vgobj = _create_py_vg ( ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( vgobj - > vg = lvm_vg_create ( _libh , vgname ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-26 02:31:11 +04:00
Py_DECREF ( vgobj ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2012-10-16 00:26:01 +04:00
return ( PyObject * ) vgobj ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static void liblvm_vg_dealloc ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
/* if already closed, don't reclose it */
2013-06-18 23:13:27 +04:00
if ( self - > vg ! = NULL ) {
2012-10-12 05:08:47 +04:00
lvm_vg_close ( self - > vg ) ;
2013-06-18 23:13:27 +04:00
self - > vg = NULL ;
2013-08-01 00:16:01 +04:00
self - > libh_copy = NULL ;
2013-06-18 23:13:27 +04:00
}
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
PyObject_Del ( self ) ;
}
/* VG Methods */
2013-07-19 17:33:26 +04:00
# define VG_VALID(vgobject) \
do { \
2013-08-01 00:16:01 +04:00
if ( ! vgobject | | ! vgobject - > vg ) { \
2012-10-12 05:08:47 +04:00
PyErr_SetString ( PyExc_UnboundLocalError , " VG object invalid " ) ; \
2013-07-19 17:33:26 +04:00
return NULL ; \
} \
2013-08-01 00:16:01 +04:00
LVM_VALID ( vgobject - > libh_copy ) ; \
2012-10-12 05:08:47 +04:00
} while ( 0 )
2013-07-19 17:33:26 +04:00
# define PVSLIST_VALID(pvslistobject) \
do { \
2013-08-01 00:16:01 +04:00
if ( ! pvslistobject | | ! pvslistobject - > pvslist ) { \
2013-03-20 01:37:04 +04:00
PyErr_SetString ( PyExc_UnboundLocalError , " PVS object invalid " ) ; \
2013-07-19 17:33:26 +04:00
return NULL ; \
} \
2013-08-01 00:16:01 +04:00
LVM_VALID ( pvslistobject - > libh_copy ) ; \
2013-03-20 01:37:04 +04:00
} while ( 0 )
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_close ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
/* if already closed, don't reclose it */
2013-07-19 17:33:26 +04:00
if ( self - > vg ) {
2014-10-26 09:25:30 +03:00
if ( lvm_vg_close ( self - > vg ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
}
2013-07-19 17:33:26 +04:00
self - > vg = NULL ;
2013-08-01 00:16:01 +04:00
self - > libh_copy = NULL ;
2013-07-19 17:33:26 +04:00
}
2012-10-12 05:08:47 +04:00
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_name ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
return Py_BuildValue ( " s " , lvm_vg_get_name ( self - > vg ) ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_uuid ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
return Py_BuildValue ( " s " , lvm_vg_get_uuid ( self - > vg ) ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_remove ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( lvm_vg_remove ( self - > vg ) = = - 1 )
2012-10-12 05:08:47 +04:00
goto error ;
if ( lvm_vg_write ( self - > vg ) = = - 1 )
goto error ;
2012-10-26 02:31:11 +04:00
/* Not much you can do with a vg that is removed so close it */
2014-10-26 09:25:30 +03:00
return _liblvm_lvm_vg_close ( self ) ;
2012-10-12 05:08:47 +04:00
error :
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_extend ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * device ;
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " s " , & device ) ) {
return NULL ;
}
2013-07-19 17:33:26 +04:00
if ( lvm_vg_extend ( self - > vg , device ) = = - 1 )
2012-10-12 05:08:47 +04:00
goto error ;
if ( lvm_vg_write ( self - > vg ) = = - 1 )
goto error ;
Py_INCREF ( Py_None ) ;
return Py_None ;
error :
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_reduce ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * device ;
VG_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & device ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( lvm_vg_reduce ( self - > vg , device ) = = - 1 )
2012-10-12 05:08:47 +04:00
goto error ;
if ( lvm_vg_write ( self - > vg ) = = - 1 )
goto error ;
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
error :
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_add_tag ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * tag ;
int rval ;
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " s " , & tag ) ) {
return NULL ;
}
if ( ( rval = lvm_vg_add_tag ( self - > vg , tag ) ) = = - 1 )
goto error ;
if ( lvm_vg_write ( self - > vg ) = = - 1 )
goto error ;
return Py_BuildValue ( " i " , rval ) ;
error :
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_remove_tag ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * tag ;
VG_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & tag ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( lvm_vg_remove_tag ( self - > vg , tag ) = = - 1 )
2012-10-12 05:08:47 +04:00
goto error ;
if ( lvm_vg_write ( self - > vg ) = = - 1 )
goto error ;
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
error :
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
return NULL ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_is_clustered ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
PyObject * rval ;
VG_VALID ( self ) ;
rval = ( lvm_vg_is_clustered ( self - > vg ) = = 1 ) ? Py_True : Py_False ;
Py_INCREF ( rval ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return rval ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_is_exported ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
PyObject * rval ;
VG_VALID ( self ) ;
rval = ( lvm_vg_is_exported ( self - > vg ) = = 1 ) ? Py_True : Py_False ;
Py_INCREF ( rval ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return rval ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_is_partial ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
PyObject * rval ;
VG_VALID ( self ) ;
rval = ( lvm_vg_is_partial ( self - > vg ) = = 1 ) ? Py_True : Py_False ;
Py_INCREF ( rval ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return rval ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_seqno ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_seqno ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_size ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_size ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_free_size ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_free_size ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_extent_size ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_extent_size ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_extent_count ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_extent_count ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_free_extent_count ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_free_extent_count ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
/* Builds a python tuple ([string|number], bool) from a struct lvm_property_value */
2013-07-19 17:33:26 +04:00
static PyObject * get_property ( struct lvm_property_value * prop )
2012-10-12 05:08:47 +04:00
{
PyObject * pytuple ;
PyObject * setable ;
2012-10-16 00:34:43 +04:00
if ( ! prop - > is_valid ) {
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( 2 ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2015-05-04 22:55:00 +03:00
if ( prop - > is_integer ) {
if ( prop - > is_signed ) {
PyTuple_SET_ITEM ( pytuple , 0 , Py_BuildValue ( " L " , prop - > value . signed_integer ) ) ;
} else {
PyTuple_SET_ITEM ( pytuple , 0 , Py_BuildValue ( " K " , prop - > value . integer ) ) ;
}
} else {
2015-05-04 23:19:48 +03:00
if ( prop - > value . string ) {
PyTuple_SET_ITEM ( pytuple , 0 , PYSTRTYPE_FROMSTRING ( prop - > value . string ) ) ;
} else {
PyTuple_SET_ITEM ( pytuple , 0 , Py_None ) ;
}
2015-05-04 22:55:00 +03:00
}
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( prop - > is_settable )
2012-10-12 05:08:47 +04:00
setable = Py_True ;
2013-07-19 17:33:26 +04:00
else
2012-10-12 05:08:47 +04:00
setable = Py_False ;
Py_INCREF ( setable ) ;
PyTuple_SET_ITEM ( pytuple , 1 , setable ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return pytuple ;
}
/* This will return a tuple of (value, bool) with the value being a string or
integer and bool indicating if property is settable */
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_property ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * name ;
struct lvm_property_value prop_value ;
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
prop_value = lvm_vg_get_property ( self - > vg , name ) ;
2013-07-19 17:33:26 +04:00
2012-10-16 00:26:01 +04:00
return get_property ( & prop_value ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_set_property ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * property_name = NULL ;
PyObject * variant_type_arg = NULL ;
struct lvm_property_value lvm_property ;
char * string_value = NULL ;
2013-07-19 17:33:26 +04:00
int temp_py_int ;
unsigned long long temp_py_long ;
2012-10-12 05:08:47 +04:00
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " sO " , & property_name , & variant_type_arg ) )
return NULL ;
lvm_property = lvm_vg_get_property ( self - > vg , property_name ) ;
2013-07-19 17:33:26 +04:00
if ( ! lvm_property . is_valid )
2012-10-12 05:08:47 +04:00
goto lvmerror ;
2014-09-02 17:42:01 +04:00
if ( PYSTRYPE_CHECK ( variant_type_arg ) ) {
2012-10-12 05:08:47 +04:00
if ( ! lvm_property . is_string ) {
PyErr_Format ( PyExc_ValueError , " Property requires string value " ) ;
goto bail ;
}
2014-09-02 17:42:01 +04:00
if ( ! ( string_value = PYSTRTYPE_ASSTRING ( variant_type_arg ) ) ) {
2012-10-12 05:08:47 +04:00
PyErr_NoMemory ( ) ;
goto bail ;
}
2013-07-19 17:33:26 +04:00
lvm_property . value . string = string_value ;
2012-10-12 05:08:47 +04:00
} else {
if ( ! lvm_property . is_integer ) {
PyErr_Format ( PyExc_ValueError , " Property requires numeric value " ) ;
goto bail ;
}
2014-09-02 17:42:01 +04:00
if ( PYINTTYPE_CHECK ( variant_type_arg ) ) {
temp_py_int = PYINTTYPE_ASLONG ( variant_type_arg ) ;
2012-10-12 05:08:47 +04:00
/* -1 could be valid, need to see if an exception was gen. */
2013-07-19 17:33:26 +04:00
if ( temp_py_int = = - 1 & & PyErr_Occurred ( ) )
2012-10-16 00:34:43 +04:00
goto bail ;
2012-10-12 05:08:47 +04:00
if ( temp_py_int < 0 ) {
PyErr_Format ( PyExc_ValueError , " Positive integers only! " ) ;
goto bail ;
}
lvm_property . value . integer = temp_py_int ;
2012-10-16 00:34:43 +04:00
} else if ( PyObject_IsInstance ( variant_type_arg , ( PyObject * ) & PyLong_Type ) ) {
2013-06-18 23:13:27 +04:00
/* If PyLong_AsUnsignedLongLong function fails an OverflowError is
* raised and ( unsigned long long ) - 1 is returned
*/
2013-07-19 17:33:26 +04:00
if ( ( temp_py_long = PyLong_AsUnsignedLongLong ( variant_type_arg ) ) = = ~ 0ULL )
2012-10-12 05:08:47 +04:00
goto bail ;
lvm_property . value . integer = temp_py_long ;
} else {
PyErr_Format ( PyExc_ValueError , " supported value types are numeric and string " ) ;
goto bail ;
}
}
2013-07-19 17:33:26 +04:00
if ( lvm_vg_set_property ( self - > vg , property_name , & lvm_property ) = = - 1 )
2012-10-12 05:08:47 +04:00
goto lvmerror ;
2013-07-19 17:33:26 +04:00
if ( lvm_vg_write ( self - > vg ) = = - 1 )
2012-10-12 05:08:47 +04:00
goto lvmerror ;
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
lvmerror :
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
bail :
return NULL ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_pv_count ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_pv_count ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_max_pv ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_max_pv ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_max_lv ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
VG_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_vg_get_max_lv ( self - > vg ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_set_extent_size ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
2013-07-25 23:54:57 +04:00
unsigned int new_size ;
2012-10-12 05:08:47 +04:00
VG_VALID ( self ) ;
2013-07-25 23:54:57 +04:00
if ( ! PyArg_ParseTuple ( args , " I " , & new_size ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( lvm_vg_set_extent_size ( self - > vg , new_size ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_list_lvs ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
struct dm_list * lvs ;
struct lvm_lv_list * lvl ;
PyObject * pytuple ;
2012-10-17 23:55:25 +04:00
lvobject * lvobj ;
2012-10-12 05:08:47 +04:00
int i = 0 ;
2012-10-17 23:55:25 +04:00
VG_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
/* unlike other LVM api calls, if there are no results, we get NULL */
2013-07-19 17:33:26 +04:00
if ( ! ( lvs = lvm_vg_list_lvs ( self - > vg ) ) )
2012-10-12 05:08:47 +04:00
return Py_BuildValue ( " () " ) ;
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( lvs ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
dm_list_iterate_items ( lvl , lvs ) {
/* Create and initialize the object */
2013-08-01 00:16:01 +04:00
if ( ! ( lvobj = _create_py_lv ( self , lvl - > lv ) ) ) {
2012-10-12 05:08:47 +04:00
Py_DECREF ( pytuple ) ;
return NULL ;
}
2012-10-17 23:55:25 +04:00
PyTuple_SET_ITEM ( pytuple , i , ( PyObject * ) lvobj ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_get_tags ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
2014-01-31 01:09:28 +04:00
struct dm_list * tagsl ;
2012-10-12 05:08:47 +04:00
struct lvm_str_list * strl ;
PyObject * pytuple ;
int i = 0 ;
VG_VALID ( self ) ;
2014-01-31 01:09:28 +04:00
if ( ! ( tagsl = lvm_vg_get_tags ( self - > vg ) ) ) {
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2014-01-31 01:09:28 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( tagsl ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2014-01-31 01:09:28 +04:00
dm_list_iterate_items ( strl , tagsl ) {
2014-09-02 17:42:01 +04:00
PyTuple_SET_ITEM ( pytuple , i , PYSTRTYPE_FROMSTRING ( strl - > str ) ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_create_lv_linear ( vgobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * vgname ;
2013-07-25 23:54:57 +04:00
unsigned long long size ;
2013-08-01 00:16:01 +04:00
lv_t lv ;
2012-10-12 05:08:47 +04:00
2012-10-17 23:55:25 +04:00
VG_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
2013-07-25 23:54:57 +04:00
if ( ! PyArg_ParseTuple ( args , " sK " , & vgname , & size ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-08-01 00:16:01 +04:00
if ( ! ( lv = lvm_vg_create_lv_linear ( self - > vg , vgname , size ) ) ) {
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-08-01 00:16:01 +04:00
return ( PyObject * ) _create_py_lv ( self , lv ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_create_lv_thinpool ( vgobject * self , PyObject * args )
2013-05-04 03:37:52 +04:00
{
2013-07-25 23:54:57 +04:00
unsigned long long size = 0 ;
unsigned long long meta_size = 0 ;
2013-05-04 03:37:52 +04:00
const char * pool_name ;
2013-07-25 23:54:57 +04:00
unsigned long chunk_size = 0 ;
2013-05-04 03:37:52 +04:00
int skip_zero = 0 ;
lvm_thin_discards_t discard = LVM_THIN_DISCARDS_PASSDOWN ;
2013-08-01 00:16:01 +04:00
lv_t lv ;
2013-05-04 03:37:52 +04:00
lv_create_params_t lvp = NULL ;
struct lvm_property_value prop_value ;
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " sK|kKii " , & pool_name , & size , & chunk_size ,
2013-07-19 17:33:26 +04:00
& meta_size , & discard , & skip_zero ) )
2013-05-04 03:37:52 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( lvp = lvm_lv_params_create_thin_pool ( self - > vg , pool_name , size , chunk_size ,
meta_size , discard ) ) ) {
2013-05-04 03:37:52 +04:00
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
}
2013-05-04 03:37:52 +04:00
2013-07-19 17:33:26 +04:00
if ( skip_zero ) {
prop_value = lvm_lv_params_get_property ( lvp , " skip_zero " ) ;
2013-05-04 03:37:52 +04:00
2013-07-19 17:33:26 +04:00
if ( prop_value . is_valid ) {
prop_value . value . integer = 1 ;
2013-05-04 03:37:52 +04:00
2013-07-19 17:33:26 +04:00
if ( lvm_lv_params_set_property ( lvp , " skip_zero " ,
& prop_value ) = = - 1 ) {
2013-08-01 00:16:01 +04:00
goto error ;
2013-07-19 17:33:26 +04:00
}
}
}
2013-08-01 00:16:01 +04:00
if ( ! ( lv = lvm_lv_create ( lvp ) ) ) {
goto error ;
2013-05-04 03:37:52 +04:00
}
2013-08-01 00:16:01 +04:00
return ( PyObject * ) _create_py_lv ( self , lv ) ;
2013-05-04 03:37:52 +04:00
2013-08-01 00:16:01 +04:00
error :
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
2013-05-04 03:37:52 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_create_lv_thin ( vgobject * self , PyObject * args )
2013-05-04 03:37:52 +04:00
{
const char * pool_name ;
const char * lv_name ;
2013-07-25 23:54:57 +04:00
unsigned long long size = 0 ;
2013-08-01 00:16:01 +04:00
lv_t lv ;
2013-05-04 03:37:52 +04:00
lv_create_params_t lvp = NULL ;
VG_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " ssK " , & pool_name , & lv_name , & size ) )
2013-05-04 03:37:52 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( lvp = lvm_lv_params_create_thin ( self - > vg , pool_name , lv_name , size ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
}
2013-05-04 03:37:52 +04:00
2013-08-01 00:16:01 +04:00
if ( ! ( lv = lvm_lv_create ( lvp ) ) ) {
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
2013-05-04 03:37:52 +04:00
}
2013-08-01 00:16:01 +04:00
return ( PyObject * ) _create_py_lv ( self , lv ) ;
2013-05-04 03:37:52 +04:00
}
2013-07-19 17:33:26 +04:00
static void liblvm_lv_dealloc ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-26 02:31:11 +04:00
/* We can dealloc an object that didn't get fully created */
2014-01-31 01:09:28 +04:00
if ( self - > parent_vgobj ) {
2012-10-26 02:31:11 +04:00
Py_DECREF ( self - > parent_vgobj ) ;
2014-01-31 01:09:28 +04:00
}
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
PyObject_Del ( self ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_list_pvs ( vgobject * self )
2012-10-12 05:08:47 +04:00
{
struct dm_list * pvs ;
struct lvm_pv_list * pvl ;
PyObject * pytuple ;
2012-10-17 23:55:25 +04:00
pvobject * pvobj ;
2012-10-12 05:08:47 +04:00
int i = 0 ;
2012-10-17 23:55:25 +04:00
VG_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
/* unlike other LVM api calls, if there are no results, we get NULL */
2013-07-19 17:33:26 +04:00
if ( ! ( pvs = lvm_vg_list_pvs ( self - > vg ) ) )
2012-10-12 05:08:47 +04:00
return Py_BuildValue ( " () " ) ;
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( pvs ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
dm_list_iterate_items ( pvl , pvs ) {
/* Create and initialize the object */
2013-07-19 17:33:26 +04:00
if ( ! ( pvobj = _create_py_pv ( ) ) ) {
2012-10-12 05:08:47 +04:00
Py_DECREF ( pytuple ) ;
return NULL ;
}
2012-10-17 23:55:25 +04:00
pvobj - > parent_vgobj = self ;
Py_INCREF ( pvobj - > parent_vgobj ) ;
pvobj - > pv = pvl - > pv ;
PyTuple_SET_ITEM ( pytuple , i , ( PyObject * ) pvobj ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
typedef lv_t ( * lv_fetch_by_N ) ( vg_t vg , const char * id ) ;
typedef pv_t ( * pv_fetch_by_N ) ( vg_t vg , const char * id ) ;
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_from_N ( vgobject * self , PyObject * arg , lv_fetch_by_N method )
2012-10-12 05:08:47 +04:00
{
const char * id ;
lv_t lv = NULL ;
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( arg , " s " , & id ) )
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( lv = method ( self - > vg , id ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-08-01 00:16:01 +04:00
return ( PyObject * ) _create_py_lv ( self , lv ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_from_name ( vgobject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
2013-07-19 17:33:26 +04:00
return _liblvm_lvm_lv_from_N ( self , arg , lvm_lv_from_name ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_from_uuid ( vgobject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
2013-07-19 17:33:26 +04:00
return _liblvm_lvm_lv_from_N ( self , arg , lvm_lv_from_uuid ) ;
2012-10-12 05:08:47 +04:00
}
2013-09-26 20:39:40 +04:00
static PyObject * _liblvm_lvm_lv_name_validate ( vgobject * self , PyObject * args )
{
const char * name ;
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
if ( lvm_lv_name_validate ( self - > vg , name ) < 0 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
}
Py_INCREF ( Py_None ) ;
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_from_N ( vgobject * self , PyObject * arg , pv_fetch_by_N method )
2012-10-12 05:08:47 +04:00
{
const char * id ;
pvobject * rc ;
pv_t pv = NULL ;
VG_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( arg , " s " , & id ) )
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( pv = method ( self - > vg , id ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2013-07-19 17:33:26 +04:00
if ( ! ( rc = _create_py_pv ( ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2012-10-17 23:55:25 +04:00
Py_INCREF ( self ) ;
2012-10-12 05:08:47 +04:00
rc - > pv = pv ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return ( PyObject * ) rc ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_from_name ( vgobject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
2013-07-19 17:33:26 +04:00
return _liblvm_lvm_pv_from_N ( self , arg , lvm_pv_from_name ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_from_uuid ( vgobject * self , PyObject * arg )
2012-10-12 05:08:47 +04:00
{
2013-07-19 17:33:26 +04:00
return _liblvm_lvm_pv_from_N ( self , arg , lvm_pv_from_uuid ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static void _liblvm_pv_dealloc ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
2014-01-31 01:09:28 +04:00
if ( self - > parent_vgobj ) {
2013-03-20 01:37:04 +04:00
Py_DECREF ( self - > parent_vgobj ) ;
2014-01-31 01:09:28 +04:00
}
2013-03-20 01:37:04 +04:00
2014-01-31 01:09:28 +04:00
if ( self - > parent_pvslistobj ) {
2013-03-20 01:37:04 +04:00
Py_DECREF ( self - > parent_pvslistobj ) ;
2014-01-31 01:09:28 +04:00
}
2013-03-20 01:37:04 +04:00
self - > parent_vgobj = NULL ;
self - > parent_pvslistobj = NULL ;
2012-10-12 05:08:47 +04:00
PyObject_Del ( self ) ;
}
/* LV Methods */
2013-07-19 17:33:26 +04:00
# define LV_VALID(lvobject) \
2013-08-01 00:16:01 +04:00
do { \
if ( ! lvobject | | ! lvobject - > lv ) { \
2012-10-12 05:08:47 +04:00
PyErr_SetString ( PyExc_UnboundLocalError , " LV object invalid " ) ; \
2013-08-01 00:16:01 +04:00
return NULL ; \
} \
VG_VALID ( lvobject - > parent_vgobj ) ; \
2012-10-12 05:08:47 +04:00
} while ( 0 )
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_get_attr ( lvobject * self )
2013-04-10 22:38:18 +04:00
{
LV_VALID ( self ) ;
return Py_BuildValue ( " s " , lvm_lv_get_attr ( self - > lv ) ) ;
}
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_get_origin ( lvobject * self )
2013-04-12 00:49:08 +04:00
{
LV_VALID ( self ) ;
return Py_BuildValue ( " s " , lvm_lv_get_origin ( self - > lv ) ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_get_name ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
LV_VALID ( self ) ;
return Py_BuildValue ( " s " , lvm_lv_get_name ( self - > lv ) ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_get_uuid ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
LV_VALID ( self ) ;
return Py_BuildValue ( " s " , lvm_lv_get_uuid ( self - > lv ) ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_activate ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( lvm_lv_activate ( self - > lv ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_deactivate ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( lvm_lv_deactivate ( self - > lv ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_vg_remove_lv ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( lvm_vg_remove_lv ( self - > lv ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
self - > lv = NULL ;
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
/* This will return a tuple of (value, bool) with the value being a string or
integer and bool indicating if property is settable */
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_get_property ( lvobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * name ;
struct lvm_property_value prop_value ;
LV_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
prop_value = lvm_lv_get_property ( self - > lv , name ) ;
2013-07-19 17:33:26 +04:00
2012-10-16 00:26:01 +04:00
return get_property ( & prop_value ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_get_size ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
LV_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_lv_get_size ( self - > lv ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_is_active ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
PyObject * rval ;
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
rval = ( lvm_lv_is_active ( self - > lv ) = = 1 ) ? Py_True : Py_False ;
2012-10-12 05:08:47 +04:00
Py_INCREF ( rval ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return rval ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_is_suspended ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
PyObject * rval ;
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
rval = ( lvm_lv_is_suspended ( self - > lv ) = = 1 ) ? Py_True : Py_False ;
2012-10-12 05:08:47 +04:00
Py_INCREF ( rval ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return rval ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_add_tag ( lvobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * tag ;
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & tag ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2015-04-07 23:25:20 +03:00
if ( lvm_lv_add_tag ( self - > lv , tag ) = = - 1 )
2015-04-10 19:01:46 +03:00
goto error ;
2015-04-07 23:25:20 +03:00
2015-04-10 19:01:46 +03:00
if ( lvm_vg_write ( self - > parent_vgobj - > vg ) = = - 1 )
2015-04-07 23:25:20 +03:00
goto error ;
2012-10-12 05:08:47 +04:00
Py_INCREF ( Py_None ) ;
return Py_None ;
2015-04-07 23:25:20 +03:00
error :
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_remove_tag ( lvobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * tag ;
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & tag ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2015-04-07 23:25:20 +03:00
if ( lvm_lv_remove_tag ( self - > lv , tag ) = = - 1 )
2015-04-10 19:01:46 +03:00
goto error ;
2012-10-12 05:08:47 +04:00
2015-04-10 19:01:46 +03:00
if ( lvm_vg_write ( self - > parent_vgobj - > vg ) = = - 1 )
goto error ;
2013-07-19 17:33:26 +04:00
2015-04-07 23:25:20 +03:00
Py_INCREF ( Py_None ) ;
2012-10-12 05:08:47 +04:00
return Py_None ;
2015-04-07 23:25:20 +03:00
error :
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_get_tags ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
2014-01-31 01:09:28 +04:00
struct dm_list * tagsl ;
2012-10-12 05:08:47 +04:00
struct lvm_str_list * strl ;
PyObject * pytuple ;
int i = 0 ;
LV_VALID ( self ) ;
2014-01-31 01:09:28 +04:00
if ( ! ( tagsl = lvm_lv_get_tags ( self - > lv ) ) ) {
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
2014-01-31 01:09:28 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( tagsl ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2014-01-31 01:09:28 +04:00
dm_list_iterate_items ( strl , tagsl ) {
2014-09-02 17:42:01 +04:00
PyTuple_SET_ITEM ( pytuple , i , PYSTRTYPE_FROMSTRING ( strl - > str ) ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_rename ( lvobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * new_name ;
LV_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " s " , & new_name ) )
return NULL ;
2013-07-19 17:33:26 +04:00
if ( lvm_lv_rename ( self - > lv , new_name ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_resize ( lvobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
2013-07-25 23:54:57 +04:00
unsigned long long new_size ;
2012-10-12 05:08:47 +04:00
LV_VALID ( self ) ;
2013-07-25 23:54:57 +04:00
if ( ! PyArg_ParseTuple ( args , " K " , & new_size ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( lvm_lv_resize ( self - > lv , new_size ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_list_lvsegs ( lvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-12-14 22:32:35 +04:00
struct dm_list * lvsegs ;
lvseg_list_t * lvsegl ;
2012-10-12 05:08:47 +04:00
PyObject * pytuple ;
2012-10-17 23:55:25 +04:00
lvsegobject * lvsegobj ;
2012-10-12 05:08:47 +04:00
int i = 0 ;
2012-10-17 23:55:25 +04:00
LV_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( ! ( lvsegs = lvm_lv_list_lvsegs ( self - > lv ) ) )
2012-10-12 05:08:47 +04:00
return Py_BuildValue ( " () " ) ;
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( lvsegs ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
dm_list_iterate_items ( lvsegl , lvsegs ) {
/* Create and initialize the object */
2013-07-19 17:33:26 +04:00
if ( ! ( lvsegobj = PyObject_New ( lvsegobject , & _LibLVMlvsegType ) ) ) {
2012-10-12 05:08:47 +04:00
Py_DECREF ( pytuple ) ;
return NULL ;
}
2012-10-17 23:55:25 +04:00
lvsegobj - > parent_lvobj = self ;
Py_INCREF ( lvsegobj - > parent_lvobj ) ;
lvsegobj - > lv_seg = lvsegl - > lvseg ;
PyTuple_SET_ITEM ( pytuple , i , ( PyObject * ) lvsegobj ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lv_snapshot ( lvobject * self , PyObject * args )
2012-12-14 05:39:09 +04:00
{
2013-06-07 00:41:35 +04:00
const char * snap_name ;
2013-07-25 23:54:57 +04:00
unsigned long long size = 0 ;
2013-08-01 00:16:01 +04:00
lv_t lv ;
2013-06-07 00:41:35 +04:00
lv_create_params_t lvp = NULL ;
2012-12-14 05:39:09 +04:00
LV_VALID ( self ) ;
2013-07-19 17:33:26 +04:00
if ( ! PyArg_ParseTuple ( args , " s|K " , & snap_name , & size ) )
2012-12-14 05:39:09 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( ! ( lvp = lvm_lv_params_create_snapshot ( self - > lv , snap_name , size ) ) ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
}
2013-08-01 00:16:01 +04:00
if ( ! ( lv = lvm_lv_create ( lvp ) ) ) {
2013-07-19 17:33:26 +04:00
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
return NULL ;
2012-12-14 05:39:09 +04:00
}
2013-08-01 00:16:01 +04:00
return ( PyObject * ) _create_py_lv ( self - > parent_vgobj , lv ) ;
2012-12-14 05:39:09 +04:00
}
2012-10-12 05:08:47 +04:00
/* PV Methods */
2013-07-19 17:33:26 +04:00
# define PV_VALID(pvobject) \
do { \
2013-08-01 00:16:01 +04:00
if ( ! pvobject | | ! pvobject - > pv ) { \
PyErr_SetString ( PyExc_UnboundLocalError , " PV object invalid " ) ; \
return NULL ; \
} \
2013-07-19 17:33:26 +04:00
if ( pvobject - > parent_vgobj ) { \
VG_VALID ( pvobject - > parent_vgobj ) ; \
} \
if ( pvobject - > parent_pvslistobj ) { \
PVSLIST_VALID ( pvobject - > parent_pvslistobj ) ; \
} \
2012-10-12 05:08:47 +04:00
} while ( 0 )
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_get_name ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
return Py_BuildValue ( " s " , lvm_pv_get_name ( self - > pv ) ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_get_uuid ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
return Py_BuildValue ( " s " , lvm_pv_get_uuid ( self - > pv ) ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_get_mda_count ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_pv_get_mda_count ( self - > pv ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_get_property ( pvobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * name ;
struct lvm_property_value prop_value ;
PV_VALID ( self ) ;
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
prop_value = lvm_pv_get_property ( self - > pv , name ) ;
2013-07-19 17:33:26 +04:00
2012-10-16 00:26:01 +04:00
return get_property ( & prop_value ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_get_dev_size ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_pv_get_dev_size ( self - > pv ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_get_size ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_pv_get_size ( self - > pv ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_get_free ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2012-12-06 04:31:30 +04:00
return Py_BuildValue ( " K " , ( unsigned long long ) lvm_pv_get_free ( self - > pv ) ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_resize ( pvobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
2013-07-25 23:54:57 +04:00
unsigned long long new_size ;
2012-10-12 05:08:47 +04:00
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2013-07-25 23:54:57 +04:00
if ( ! PyArg_ParseTuple ( args , " K " , & new_size ) )
2012-10-12 05:08:47 +04:00
return NULL ;
2013-07-19 17:33:26 +04:00
if ( lvm_pv_resize ( self - > pv , new_size ) = = - 1 ) {
PyErr_SetObject ( _LibLVMError , _liblvm_get_last_error ( ) ) ;
2012-10-12 05:08:47 +04:00
return NULL ;
}
Py_INCREF ( Py_None ) ;
2013-07-19 17:33:26 +04:00
2012-10-12 05:08:47 +04:00
return Py_None ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pv_list_pvsegs ( pvobject * self )
2012-10-12 05:08:47 +04:00
{
struct dm_list * pvsegs ;
pvseg_list_t * pvsegl ;
PyObject * pytuple ;
2012-10-17 23:55:25 +04:00
pvsegobject * pvsegobj ;
2012-10-12 05:08:47 +04:00
int i = 0 ;
2012-10-17 23:55:25 +04:00
PV_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
2013-07-19 17:33:26 +04:00
if ( ! ( pvsegs = lvm_pv_list_pvsegs ( self - > pv ) ) )
2012-10-12 05:08:47 +04:00
return Py_BuildValue ( " () " ) ;
2013-07-19 17:33:26 +04:00
if ( ! ( pytuple = PyTuple_New ( dm_list_size ( pvsegs ) ) ) )
2012-10-12 05:08:47 +04:00
return NULL ;
dm_list_iterate_items ( pvsegl , pvsegs ) {
/* Create and initialize the object */
2013-07-19 17:33:26 +04:00
if ( ! ( pvsegobj = PyObject_New ( pvsegobject , & _LibLVMpvsegType ) ) ) {
2012-10-12 05:08:47 +04:00
Py_DECREF ( pytuple ) ;
return NULL ;
}
2012-10-17 23:55:25 +04:00
pvsegobj - > parent_pvobj = self ;
Py_INCREF ( pvsegobj - > parent_pvobj ) ;
pvsegobj - > pv_seg = pvsegl - > pvseg ;
PyTuple_SET_ITEM ( pytuple , i , ( PyObject * ) pvsegobj ) ;
2012-10-12 05:08:47 +04:00
i + + ;
}
return pytuple ;
}
/* LV seg methods */
2012-10-17 23:55:25 +04:00
/*
* No way to close / destroy an lvseg , just need to make sure parents are
* still good
*/
2013-08-01 00:16:01 +04:00
# define LVSEG_VALID(lvsegobject) \
do { \
if ( ! lvsegobject | | ! lvsegobject - > parent_lvobj ) { \
PyErr_SetString ( PyExc_UnboundLocalError , " LV segment object invalid " ) ; \
return NULL ; \
} \
LV_VALID ( lvsegobject - > parent_lvobj ) ; \
} while ( 0 )
2012-10-17 23:55:25 +04:00
2013-07-19 17:33:26 +04:00
static void _liblvm_lvseg_dealloc ( lvsegobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
Py_DECREF ( self - > parent_lvobj ) ;
2012-10-12 05:08:47 +04:00
PyObject_Del ( self ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_lvseg_get_property ( lvsegobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * name ;
struct lvm_property_value prop_value ;
2012-10-17 23:55:25 +04:00
LVSEG_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
prop_value = lvm_lvseg_get_property ( self - > lv_seg , name ) ;
2013-07-19 17:33:26 +04:00
2012-10-16 00:26:01 +04:00
return get_property ( & prop_value ) ;
2012-10-12 05:08:47 +04:00
}
/* PV seg methods */
2012-10-17 23:55:25 +04:00
/*
* No way to close / destroy a pvseg , just need to make sure parents are
* still good
*/
2013-08-01 00:16:01 +04:00
# define PVSEG_VALID(pvsegobject) \
do { \
if ( ! pvsegobject | | ! pvsegobject - > parent_pvobj ) { \
PyErr_SetString ( PyExc_UnboundLocalError , " PV segment object invalid " ) ; \
return NULL ; \
} \
PV_VALID ( pvsegobject - > parent_pvobj ) ; \
} while ( 0 )
2012-10-17 23:55:25 +04:00
2013-07-19 17:33:26 +04:00
static void _liblvm_pvseg_dealloc ( pvsegobject * self )
2012-10-12 05:08:47 +04:00
{
2012-10-17 23:55:25 +04:00
Py_DECREF ( self - > parent_pvobj ) ;
2012-10-12 05:08:47 +04:00
PyObject_Del ( self ) ;
}
2013-07-19 17:33:26 +04:00
static PyObject * _liblvm_lvm_pvseg_get_property ( pvsegobject * self , PyObject * args )
2012-10-12 05:08:47 +04:00
{
const char * name ;
struct lvm_property_value prop_value ;
2012-10-17 23:55:25 +04:00
PVSEG_VALID ( self ) ;
2012-10-12 05:08:47 +04:00
if ( ! PyArg_ParseTuple ( args , " s " , & name ) )
return NULL ;
prop_value = lvm_pvseg_get_property ( self - > pv_seg , name ) ;
2013-07-19 17:33:26 +04:00
2012-10-16 00:26:01 +04:00
return get_property ( & prop_value ) ;
2012-10-12 05:08:47 +04:00
}
/* ----------------------------------------------------------------------
* Method tables and other bureaucracy
*/
2013-07-19 17:33:26 +04:00
static PyMethodDef _Liblvm_methods [ ] = {
2012-10-12 05:08:47 +04:00
/* LVM methods */
2013-07-19 17:33:26 +04:00
{ " getVersion " , ( PyCFunction ) _liblvm_library_get_version , METH_NOARGS } ,
{ " gc " , ( PyCFunction ) _liblvm_lvm_gc , METH_NOARGS , _gc_doc } ,
{ " vgOpen " , ( PyCFunction ) _liblvm_lvm_vg_open , METH_VARARGS } ,
{ " vgCreate " , ( PyCFunction ) _liblvm_lvm_vg_create , METH_VARARGS } ,
{ " configFindBool " , ( PyCFunction ) _liblvm_lvm_config_find_bool , METH_VARARGS } ,
{ " configReload " , ( PyCFunction ) _liblvm_lvm_config_reload , METH_NOARGS } ,
{ " configOverride " , ( PyCFunction ) _liblvm_lvm_config_override , METH_VARARGS } ,
{ " scan " , ( PyCFunction ) _liblvm_lvm_scan , METH_NOARGS } ,
{ " listVgNames " , ( PyCFunction ) _liblvm_lvm_list_vg_names , METH_NOARGS } ,
{ " listVgUuids " , ( PyCFunction ) _liblvm_lvm_list_vg_uuids , METH_NOARGS } ,
{ " listPvs " , ( PyCFunction ) _liblvm_lvm_list_pvs , METH_NOARGS } ,
{ " pvCreate " , ( PyCFunction ) _liblvm_lvm_pv_create , METH_VARARGS } ,
{ " pvRemove " , ( PyCFunction ) _liblvm_lvm_pv_remove , METH_VARARGS } ,
{ " percentToFloat " , ( PyCFunction ) _liblvm_lvm_percent_to_float , METH_VARARGS } ,
2013-09-26 20:39:40 +04:00
{ " vgNameValidate " , ( PyCFunction ) _liblvm_lvm_vg_name_validate , METH_VARARGS } ,
2013-07-19 17:33:26 +04:00
{ " vgNameFromPvid " , ( PyCFunction ) _liblvm_lvm_vgname_from_pvid , METH_VARARGS } ,
{ " vgNameFromDevice " , ( PyCFunction ) _liblvm_lvm_vgname_from_device , METH_VARARGS } ,
2012-12-14 22:32:35 +04:00
{ NULL , NULL } /* sentinel */
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyMethodDef _liblvm_vg_methods [ ] = {
2012-10-12 05:08:47 +04:00
/* vg methods */
2013-07-19 17:33:26 +04:00
{ " getName " , ( PyCFunction ) _liblvm_lvm_vg_get_name , METH_NOARGS } ,
{ " getUuid " , ( PyCFunction ) _liblvm_lvm_vg_get_uuid , METH_NOARGS } ,
{ " close " , ( PyCFunction ) _liblvm_lvm_vg_close , METH_NOARGS } ,
{ " remove " , ( PyCFunction ) _liblvm_lvm_vg_remove , METH_NOARGS } ,
{ " extend " , ( PyCFunction ) _liblvm_lvm_vg_extend , METH_VARARGS } ,
{ " reduce " , ( PyCFunction ) _liblvm_lvm_vg_reduce , METH_VARARGS } ,
{ " addTag " , ( PyCFunction ) _liblvm_lvm_vg_add_tag , METH_VARARGS } ,
{ " removeTag " , ( PyCFunction ) _liblvm_lvm_vg_remove_tag , METH_VARARGS } ,
{ " setExtentSize " , ( PyCFunction ) _liblvm_lvm_vg_set_extent_size , METH_VARARGS } ,
{ " isClustered " , ( PyCFunction ) _liblvm_lvm_vg_is_clustered , METH_NOARGS } ,
{ " isExported " , ( PyCFunction ) _liblvm_lvm_vg_is_exported , METH_NOARGS } ,
{ " isPartial " , ( PyCFunction ) _liblvm_lvm_vg_is_partial , METH_NOARGS } ,
{ " getSeqno " , ( PyCFunction ) _liblvm_lvm_vg_get_seqno , METH_NOARGS } ,
{ " getSize " , ( PyCFunction ) _liblvm_lvm_vg_get_size , METH_NOARGS } ,
{ " getFreeSize " , ( PyCFunction ) _liblvm_lvm_vg_get_free_size , METH_NOARGS } ,
{ " getExtentSize " , ( PyCFunction ) _liblvm_lvm_vg_get_extent_size , METH_NOARGS } ,
{ " getExtentCount " , ( PyCFunction ) _liblvm_lvm_vg_get_extent_count , METH_NOARGS } ,
{ " getFreeExtentCount " , ( PyCFunction ) _liblvm_lvm_vg_get_free_extent_count , METH_NOARGS } ,
{ " getProperty " , ( PyCFunction ) _liblvm_lvm_vg_get_property , METH_VARARGS } ,
{ " setProperty " , ( PyCFunction ) _liblvm_lvm_vg_set_property , METH_VARARGS } ,
{ " getPvCount " , ( PyCFunction ) _liblvm_lvm_vg_get_pv_count , METH_NOARGS } ,
{ " getMaxPv " , ( PyCFunction ) _liblvm_lvm_vg_get_max_pv , METH_NOARGS } ,
{ " getMaxLv " , ( PyCFunction ) _liblvm_lvm_vg_get_max_lv , METH_NOARGS } ,
{ " listLVs " , ( PyCFunction ) _liblvm_lvm_vg_list_lvs , METH_NOARGS } ,
{ " listPVs " , ( PyCFunction ) _liblvm_lvm_vg_list_pvs , METH_NOARGS } ,
{ " lvFromName " , ( PyCFunction ) _liblvm_lvm_lv_from_name , METH_VARARGS } ,
{ " lvFromUuid " , ( PyCFunction ) _liblvm_lvm_lv_from_uuid , METH_VARARGS } ,
2013-09-26 20:39:40 +04:00
{ " lvNameValidate " , ( PyCFunction ) _liblvm_lvm_lv_name_validate , METH_VARARGS } ,
2013-07-19 17:33:26 +04:00
{ " pvFromName " , ( PyCFunction ) _liblvm_lvm_pv_from_name , METH_VARARGS } ,
{ " pvFromUuid " , ( PyCFunction ) _liblvm_lvm_pv_from_uuid , METH_VARARGS } ,
{ " getTags " , ( PyCFunction ) _liblvm_lvm_vg_get_tags , METH_NOARGS } ,
{ " createLvLinear " , ( PyCFunction ) _liblvm_lvm_vg_create_lv_linear , METH_VARARGS } ,
{ " createLvThinpool " , ( PyCFunction ) _liblvm_lvm_vg_create_lv_thinpool , METH_VARARGS } ,
{ " createLvThin " , ( PyCFunction ) _liblvm_lvm_vg_create_lv_thin , METH_VARARGS } ,
2012-12-14 22:32:35 +04:00
{ NULL , NULL } /* sentinel */
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyMethodDef _liblvm_lv_methods [ ] = {
2012-10-12 05:08:47 +04:00
/* lv methods */
2013-07-19 17:33:26 +04:00
{ " getAttr " , ( PyCFunction ) _liblvm_lvm_lv_get_attr , METH_NOARGS } ,
{ " getName " , ( PyCFunction ) _liblvm_lvm_lv_get_name , METH_NOARGS } ,
{ " getOrigin " , ( PyCFunction ) _liblvm_lvm_lv_get_origin , METH_NOARGS } ,
{ " getUuid " , ( PyCFunction ) _liblvm_lvm_lv_get_uuid , METH_NOARGS } ,
{ " activate " , ( PyCFunction ) _liblvm_lvm_lv_activate , METH_NOARGS } ,
{ " deactivate " , ( PyCFunction ) _liblvm_lvm_lv_deactivate , METH_NOARGS } ,
{ " remove " , ( PyCFunction ) _liblvm_lvm_vg_remove_lv , METH_NOARGS } ,
{ " getProperty " , ( PyCFunction ) _liblvm_lvm_lv_get_property , METH_VARARGS } ,
{ " getSize " , ( PyCFunction ) _liblvm_lvm_lv_get_size , METH_NOARGS } ,
{ " isActive " , ( PyCFunction ) _liblvm_lvm_lv_is_active , METH_NOARGS } ,
{ " isSuspended " , ( PyCFunction ) _liblvm_lvm_lv_is_suspended , METH_NOARGS } ,
{ " addTag " , ( PyCFunction ) _liblvm_lvm_lv_add_tag , METH_VARARGS } ,
{ " removeTag " , ( PyCFunction ) _liblvm_lvm_lv_remove_tag , METH_VARARGS } ,
{ " getTags " , ( PyCFunction ) _liblvm_lvm_lv_get_tags , METH_NOARGS } ,
{ " rename " , ( PyCFunction ) _liblvm_lvm_lv_rename , METH_VARARGS } ,
{ " resize " , ( PyCFunction ) _liblvm_lvm_lv_resize , METH_VARARGS } ,
{ " listLVsegs " , ( PyCFunction ) _liblvm_lvm_lv_list_lvsegs , METH_NOARGS } ,
{ " snapshot " , ( PyCFunction ) _liblvm_lvm_lv_snapshot , METH_VARARGS } ,
2012-12-14 22:32:35 +04:00
{ NULL , NULL } /* sentinel */
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyMethodDef _liblvm_pv_list_methods [ ] = {
2013-03-20 01:37:04 +04:00
/* pv list methods */
2013-07-19 17:33:26 +04:00
{ " __enter__ " , ( PyCFunction ) _liblvm_lvm_pvlist_get , METH_VARARGS } ,
{ " __exit__ " , ( PyCFunction ) _liblvm_lvm_pvlist_put , METH_VARARGS } ,
{ " open " , ( PyCFunction ) _liblvm_lvm_pvlist_get , METH_VARARGS } ,
{ " close " , ( PyCFunction ) _liblvm_lvm_pvlist_put , METH_VARARGS } ,
2013-03-20 01:37:04 +04:00
{ NULL , NULL }
} ;
2013-07-19 17:33:26 +04:00
static PyMethodDef _liblvm_pv_methods [ ] = {
2012-10-12 05:08:47 +04:00
/* pv methods */
2013-07-19 17:33:26 +04:00
{ " getName " , ( PyCFunction ) _liblvm_lvm_pv_get_name , METH_NOARGS } ,
{ " getUuid " , ( PyCFunction ) _liblvm_lvm_pv_get_uuid , METH_NOARGS } ,
{ " getMdaCount " , ( PyCFunction ) _liblvm_lvm_pv_get_mda_count , METH_NOARGS } ,
{ " getProperty " , ( PyCFunction ) _liblvm_lvm_pv_get_property , METH_VARARGS } ,
{ " getSize " , ( PyCFunction ) _liblvm_lvm_pv_get_size , METH_NOARGS } ,
{ " getDevSize " , ( PyCFunction ) _liblvm_lvm_pv_get_dev_size , METH_NOARGS } ,
{ " getFree " , ( PyCFunction ) _liblvm_lvm_pv_get_free , METH_NOARGS } ,
{ " resize " , ( PyCFunction ) _liblvm_lvm_pv_resize , METH_VARARGS } ,
{ " listPVsegs " , ( PyCFunction ) _liblvm_lvm_pv_list_pvsegs , METH_NOARGS } ,
2012-12-14 22:32:35 +04:00
{ NULL , NULL } /* sentinel */
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyMethodDef _liblvm_lvseg_methods [ ] = {
{ " getProperty " , ( PyCFunction ) _liblvm_lvm_lvseg_get_property , METH_VARARGS } ,
2012-12-14 22:32:35 +04:00
{ NULL , NULL } /* sentinel */
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyMethodDef _liblvm_pvseg_methods [ ] = {
{ " getProperty " , ( PyCFunction ) _liblvm_lvm_pvseg_get_property , METH_VARARGS } ,
2012-12-14 22:32:35 +04:00
{ NULL , NULL } /* sentinel */
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyTypeObject _LibLVMvgType = {
2014-09-02 17:42:01 +04:00
PyVarObject_HEAD_INIT ( & PyType_Type , 0 )
2013-07-31 20:56:41 +04:00
. tp_name = " lvm.Liblvm_vg " ,
2012-10-12 05:08:47 +04:00
. tp_basicsize = sizeof ( vgobject ) ,
. tp_new = PyType_GenericNew ,
. tp_dealloc = ( destructor ) liblvm_vg_dealloc ,
. tp_flags = Py_TPFLAGS_DEFAULT ,
. tp_doc = " LVM Volume Group object " ,
2013-07-19 17:33:26 +04:00
. tp_methods = _liblvm_vg_methods ,
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyTypeObject _LibLVMlvType = {
2014-09-02 17:42:01 +04:00
PyVarObject_HEAD_INIT ( & PyType_Type , 0 )
2013-07-31 20:56:41 +04:00
. tp_name = " lvm.Liblvm_lv " ,
2012-10-12 05:08:47 +04:00
. tp_basicsize = sizeof ( lvobject ) ,
. tp_new = PyType_GenericNew ,
. tp_dealloc = ( destructor ) liblvm_lv_dealloc ,
. tp_flags = Py_TPFLAGS_DEFAULT ,
. tp_doc = " LVM Logical Volume object " ,
2013-07-19 17:33:26 +04:00
. tp_methods = _liblvm_lv_methods ,
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyTypeObject _LibLVMpvlistType = {
2014-09-02 17:42:01 +04:00
PyVarObject_HEAD_INIT ( & PyType_Type , 0 )
2013-07-31 20:56:41 +04:00
. tp_name = " lvm.Liblvm_pvlist " ,
2013-07-19 17:33:26 +04:00
. tp_basicsize = sizeof ( pvslistobject ) ,
. tp_new = PyType_GenericNew ,
. tp_dealloc = ( destructor ) _liblvm_pvlist_dealloc ,
. tp_flags = Py_TPFLAGS_DEFAULT ,
. tp_doc = " LVM Physical Volume list object " ,
. tp_methods = _liblvm_pv_list_methods ,
2013-03-20 01:37:04 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyTypeObject _LibLVMpvType = {
2014-09-02 17:42:01 +04:00
PyVarObject_HEAD_INIT ( & PyType_Type , 0 )
2013-07-31 20:56:41 +04:00
. tp_name = " lvm.Liblvm_pv " ,
2012-10-12 05:08:47 +04:00
. tp_basicsize = sizeof ( pvobject ) ,
. tp_new = PyType_GenericNew ,
2013-07-19 17:33:26 +04:00
. tp_dealloc = ( destructor ) _liblvm_pv_dealloc ,
2012-10-12 05:08:47 +04:00
. tp_flags = Py_TPFLAGS_DEFAULT ,
. tp_doc = " LVM Physical Volume object " ,
2013-07-19 17:33:26 +04:00
. tp_methods = _liblvm_pv_methods ,
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyTypeObject _LibLVMlvsegType = {
2014-09-02 17:42:01 +04:00
PyVarObject_HEAD_INIT ( & PyType_Type , 0 )
2013-07-31 20:56:41 +04:00
. tp_name = " lvm.Liblvm_lvseg " ,
2012-10-12 05:08:47 +04:00
. tp_basicsize = sizeof ( lvsegobject ) ,
. tp_new = PyType_GenericNew ,
2013-07-19 17:33:26 +04:00
. tp_dealloc = ( destructor ) _liblvm_lvseg_dealloc ,
2012-10-12 05:08:47 +04:00
. tp_flags = Py_TPFLAGS_DEFAULT ,
. tp_doc = " LVM Logical Volume Segment object " ,
2013-07-19 17:33:26 +04:00
. tp_methods = _liblvm_lvseg_methods ,
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static PyTypeObject _LibLVMpvsegType = {
2014-09-02 17:42:01 +04:00
PyVarObject_HEAD_INIT ( & PyType_Type , 0 )
2013-07-31 20:56:41 +04:00
. tp_name = " lvm.Liblvm_pvseg " ,
2012-10-12 05:08:47 +04:00
. tp_basicsize = sizeof ( pvsegobject ) ,
. tp_new = PyType_GenericNew ,
2013-07-19 17:33:26 +04:00
. tp_dealloc = ( destructor ) _liblvm_pvseg_dealloc ,
2012-10-12 05:08:47 +04:00
. tp_flags = Py_TPFLAGS_DEFAULT ,
. tp_doc = " LVM Physical Volume Segment object " ,
2013-07-19 17:33:26 +04:00
. tp_methods = _liblvm_pvseg_methods ,
2012-10-12 05:08:47 +04:00
} ;
2013-07-19 17:33:26 +04:00
static void _liblvm_cleanup ( void )
2012-10-16 00:26:01 +04:00
{
2013-07-19 17:33:26 +04:00
if ( _libh ) {
lvm_quit ( _libh ) ;
_libh = NULL ;
2013-07-19 00:53:43 +04:00
}
2012-10-16 00:26:01 +04:00
}
2014-09-02 17:42:01 +04:00
# ifdef IS_PY3K
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT ,
" lvm " ,
" Liblvm module " ,
- 1 ,
_Liblvm_methods ,
NULL ,
NULL ,
NULL ,
NULL
} ;
# define MODINITERROR return NULL
PyObject *
PyInit_lvm ( void )
# else
# define MODINITERROR return
2014-11-08 17:33:17 +03:00
PyMODINIT_FUNC initlvm ( void ) ;
2013-07-19 17:33:26 +04:00
PyMODINIT_FUNC initlvm ( void )
2014-09-02 17:42:01 +04:00
# endif
2012-10-12 05:08:47 +04:00
{
PyObject * m ;
2013-07-19 17:33:26 +04:00
if ( PyType_Ready ( & _LibLVMvgType ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-07-19 17:33:26 +04:00
if ( PyType_Ready ( & _LibLVMlvType ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-07-19 17:33:26 +04:00
if ( PyType_Ready ( & _LibLVMpvType ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-07-19 17:33:26 +04:00
if ( PyType_Ready ( & _LibLVMlvsegType ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-07-19 17:33:26 +04:00
if ( PyType_Ready ( & _LibLVMpvsegType ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-07-19 17:33:26 +04:00
if ( PyType_Ready ( & _LibLVMpvlistType ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2012-10-12 05:08:47 +04:00
2014-09-02 17:42:01 +04:00
# ifdef IS_PY3K
m = PyModule_Create ( & moduledef ) ;
# else
m = Py_InitModule3 ( " lvm " , _Liblvm_methods , " Liblvm module " ) ;
# endif
if ( m = = NULL )
MODINITERROR ;
2013-05-04 03:37:52 +04:00
2013-07-19 17:33:26 +04:00
if ( PyModule_AddIntConstant ( m , " THIN_DISCARDS_IGNORE " ,
LVM_THIN_DISCARDS_IGNORE ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-05-04 03:37:52 +04:00
2013-07-19 17:33:26 +04:00
if ( PyModule_AddIntConstant ( m , " THIN_DISCARDS_NO_PASSDOWN " ,
LVM_THIN_DISCARDS_NO_PASSDOWN ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-05-04 03:37:52 +04:00
2013-07-19 17:33:26 +04:00
if ( PyModule_AddIntConstant ( m , " THIN_DISCARDS_PASSDOWN " ,
LVM_THIN_DISCARDS_PASSDOWN ) < 0 )
2014-09-02 17:42:01 +04:00
MODINITERROR ;
2013-05-04 03:37:52 +04:00
2014-11-08 17:33:17 +03:00
if ( ( _LibLVMError = PyErr_NewException ( ( char * ) " lvm.LibLVMError " , NULL , NULL ) ) ) {
2012-10-12 05:08:47 +04:00
/* Each call to PyModule_AddObject decrefs it; compensate: */
2013-07-19 17:33:26 +04:00
Py_INCREF ( _LibLVMError ) ;
Py_INCREF ( _LibLVMError ) ;
PyModule_AddObject ( m , " error " , _LibLVMError ) ;
2013-07-25 02:29:41 +04:00
PyModule_AddObject ( m , " LibLVMError " , _LibLVMError ) ;
2012-10-12 05:08:47 +04:00
}
2013-07-19 17:33:26 +04:00
Py_AtExit ( _liblvm_cleanup ) ;
2014-09-02 17:42:01 +04:00
# ifdef IS_PY3K
return m ;
# endif
2012-10-12 05:08:47 +04:00
}