python-lvm: Correct names
PATCH 1/4 python-lvm: Correct names
The existing names do not follow accepted guidelines.
--- python/liblvm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
python/liblvm.c +7 -7
@@ -1846,7 +1846,7 @@ static PyMethodDef _liblvm_pvseg_methods[] = {static PyTypeObject _LibLVMvgType = {PyObject_HEAD_INIT (&PyType_Type) - .tp_name ="liblvm.Liblvm_vg" , + .tp_name ="lvm.Liblvm_vg" , .tp_basicsize =sizeof (vgobject), .tp_new = PyType_GenericNew, .tp_dealloc = (destructor )liblvm_vg_dealloc,
@@ -1857,7 +1857,7 @@ static PyTypeObject _LibLVMvgType = {static PyTypeObject _LibLVMlvType = {PyObject_HEAD_INIT (&PyType_Type) - .tp_name ="liblvm.Liblvm_lv" , + .tp_name ="lvm.Liblvm_lv" , .tp_basicsize =sizeof (lvobject), .tp_new = PyType_GenericNew, .tp_dealloc = (destructor )liblvm_lv_dealloc,
@@ -1868,7 +1868,7 @@ static PyTypeObject _LibLVMlvType = {static PyTypeObject _LibLVMpvlistType = {PyObject_HEAD_INIT (&PyType_Type) - .tp_name ="liblvm.Liblvm_pvlist" , + .tp_name ="lvm.Liblvm_pvlist" , .tp_basicsize =sizeof (pvslistobject), .tp_new = PyType_GenericNew, .tp_dealloc = (destructor )_liblvm_pvlist_dealloc,
@@ -1879,7 +1879,7 @@ static PyTypeObject _LibLVMpvlistType = {static PyTypeObject _LibLVMpvType = {PyObject_HEAD_INIT (&PyType_Type) - .tp_name ="liblvm.Liblvm_pv" , + .tp_name ="lvm.Liblvm_pv" , .tp_basicsize =sizeof (pvobject), .tp_new = PyType_GenericNew, .tp_dealloc = (destructor )_liblvm_pv_dealloc,
@@ -1890,7 +1890,7 @@ static PyTypeObject _LibLVMpvType = {static PyTypeObject _LibLVMlvsegType = {PyObject_HEAD_INIT (&PyType_Type) - .tp_name ="liblvm.Liblvm_lvseg" , + .tp_name ="lvm.Liblvm_lvseg" , .tp_basicsize =sizeof (lvsegobject), .tp_new = PyType_GenericNew, .tp_dealloc = (destructor )_liblvm_lvseg_dealloc,
@@ -1901,7 +1901,7 @@ static PyTypeObject _LibLVMlvsegType = {static PyTypeObject _LibLVMpvsegType = {PyObject_HEAD_INIT (&PyType_Type) - .tp_name ="liblvm.Liblvm_pvseg" , + .tp_name ="lvm.Liblvm_pvseg" , .tp_basicsize =sizeof (pvsegobject), .tp_new = PyType_GenericNew, .tp_dealloc = (destructor )_liblvm_pvseg_dealloc,
@@ -1952,7 +1952,7 @@ PyMODINIT_FUNC initlvm(void) LVM_THIN_DISCARDS_PASSDOWN) < 0)return ; -if ((_LibLVMError =PyErr_NewException ("Liblvm._LibLVMError" ,NULL ,NULL ))) { +if ((_LibLVMError =PyErr_NewException ("lvm.LibLVMError" ,NULL ,NULL ))) {/* Each call to PyModule_AddObject decrefs it; compensate: */ Py_INCREF (_LibLVMError);Py_INCREF (_LibLVMError);
Signature · 1 line
1.8.2.1
PATCH 2/4 python-lvm: Robustness improvements.
Add checks so if a user recycles the library handle any left over references to old libraries are caught.
--- python/liblvm.c | 219 ++++++++++++++++++++++++++------------------------------ 1 file changed, 103 insertions(+), 116 deletions(-)
python/liblvm.c +103 -116
@@ -30,11 +30,13 @@ static lvm_t _libh;typedef struct {PyObject_HEAD vg_t vg; /* vg handle */ +lvm_t libh_copy; }vgobject ;typedef struct {PyObject_HEAD struct dm_list *pvslist; +lvm_t libh_copy; }pvslistobject ; typedef struct {
@@ -71,9 +73,14 @@ static PyTypeObject _LibLVMpvsegType;static PyObject *_LibLVMError; -#define LVM_VALID () \ +#define LVM_VALID (ptr) \ do { \ - if (!_libh) { \ + if (ptr && _libh) { \ + if (ptr != _libh) { \ + PyErr_SetString(PyExc_UnboundLocalError, "LVM handle reference stale"); \ + return NULL; \ + } \ + } else if (!_libh) { \ PyErr_SetString(PyExc_UnboundLocalError, "LVM handle invalid"); \ return NULL; \ } \
@@ -99,17 +106,42 @@ static vgobject *_create_py_vg(void) {vgobject *vgobj =PyObject_New (vgobject, &_LibLVMvgType); -if (vgobj) +if (vgobj) { vgobj->vg =NULL ; + vgobj->libh_copy = _libh; + }return vgobj; } +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; +} +static PyObject *_liblvm_get_last_error (void ) {PyObject *info; -LVM_VALID (); +LVM_VALID (NULL );if (!(info =PyTuple_New (2 )))return NULL ;
@@ -122,7 +154,7 @@ static PyObject *_liblvm_get_last_error(void)static PyObject *_liblvm_library_get_version (void ) { -LVM_VALID (); +LVM_VALID (NULL );return Py_BuildValue ("s" ,lvm_library_get_version ()); }
@@ -131,7 +163,7 @@ static const char _gc_doc[] = "Garbage collect the C library";static PyObject *_liblvm_lvm_gc (void ) { -LVM_VALID (); +LVM_VALID (NULL );lvm_quit (_libh);
@@ -152,7 +184,7 @@ static PyObject *_liblvm_lvm_list_vg_names(void)PyObject * pytuple;int i =0 ; -LVM_VALID (); +LVM_VALID (NULL );if (!(vgnames =lvm_list_vg_names (_libh))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ());
@@ -177,7 +209,7 @@ static PyObject *_liblvm_lvm_list_vg_uuids(void)PyObject * pytuple;int i =0 ; -LVM_VALID (); +LVM_VALID (NULL );if (!(uuids =lvm_list_vg_uuids (_libh))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ());
@@ -261,23 +293,16 @@ static PyObject *_liblvm_pvlist_dealloc(pvslistobject *self)static PyObject *_liblvm_lvm_list_pvs (void ) { -pvslistobject *pvslistobj; - -LVM_VALID (); - -if (!(pvslistobj =PyObject_New (pvslistobject, &_LibLVMpvlistType))) -return NULL ; +LVM_VALID (NULL ); - pvslistobj->pvslist =NULL ; - -return (PyObject *)pvslistobj; +return (PyObject *)_create_py_pvlist (); }static PyObject *_liblvm_lvm_pv_remove (PyObject *self,PyObject *arg) {const char *pv_name; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (arg,"s" , &pv_name))return NULL ;
@@ -297,7 +322,7 @@ static PyObject *_liblvm_lvm_pv_create(PyObject *self, PyObject *arg)const char *pv_name;unsigned long long size; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (arg,"sK" , &pv_name, &size))return NULL ;
@@ -317,7 +342,7 @@ static PyObject *_liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)double converted;int percent; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (arg,"i" , &percent))return NULL ;
@@ -332,7 +357,7 @@ static PyObject *_liblvm_lvm_vgname_from_pvid(PyObject *self, PyObject *arg)const char *pvid;const char *vgname; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (arg,"s" , &pvid))return NULL ;
@@ -350,7 +375,7 @@ static PyObject *_liblvm_lvm_vgname_from_device(PyObject *self, PyObject *arg)const char *device;const char *vgname; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (arg,"s" , &device))return NULL ;
@@ -370,7 +395,7 @@ static PyObject *_liblvm_lvm_config_find_bool(PyObject *self, PyObject *arg)int rval;PyObject *rc; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (arg,"s" , &config))return NULL ;
@@ -390,7 +415,7 @@ static PyObject *_liblvm_lvm_config_find_bool(PyObject *self, PyObject *arg)static PyObject *_liblvm_lvm_config_reload (void ) { -LVM_VALID (); +LVM_VALID (NULL );if (lvm_config_reload (_libh) ==-1 ) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ());
@@ -405,7 +430,7 @@ static PyObject *_liblvm_lvm_config_reload(void)static PyObject *_liblvm_lvm_scan (void ) { -LVM_VALID (); +LVM_VALID (NULL );if (lvm_scan (_libh) ==-1 ) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ());
@@ -421,7 +446,7 @@ static PyObject *_liblvm_lvm_config_override(PyObject *self, PyObject *arg) {const char *config; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (arg,"s" , &config))return NULL ;
@@ -447,7 +472,7 @@ static PyObject *_liblvm_lvm_vg_open(PyObject *self, PyObject *args)vgobject *vgobj; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (args,"s|s" , &vgname, &mode))return NULL ;
@@ -472,7 +497,7 @@ static PyObject *_liblvm_lvm_vg_create(PyObject *self, PyObject *args)const char *vgname;vgobject *vgobj; -LVM_VALID (); +LVM_VALID (NULL );if (!PyArg_ParseTuple (args,"s" , &vgname))return NULL ;
@@ -495,6 +520,7 @@ static void liblvm_vg_dealloc(vgobject *self)if (self->vg !=NULL ) {lvm_vg_close (self->vg); self->vg =NULL ; + self->libh_copy =NULL ; }PyObject_Del (self);
@@ -504,20 +530,20 @@ static void liblvm_vg_dealloc(vgobject *self)#define VG_VALID (vgobject) \ do { \ - LVM_VALID(); \ - if (!vgobject->vg) { \ + if (!vgobject || !vgobject->vg) { \ PyErr_SetString(PyExc_UnboundLocalError, "VG object invalid"); \ return NULL; \ } \ + LVM_VALID(vgobject->libh_copy); \ } while (0)#define PVSLIST_VALID (pvslistobject) \ do { \ - LVM_VALID(); \ - if (!pvslistobject->pvslist) { \ + if (!pvslistobject || !pvslistobject->pvslist) { \ PyErr_SetString(PyExc_UnboundLocalError, "PVS object invalid"); \ return NULL; \ } \ + LVM_VALID(pvslistobject->libh_copy); \ } while (0)static PyObject *_liblvm_lvm_vg_close (vgobject *self)
@@ -526,6 +552,7 @@ static PyObject *_liblvm_lvm_vg_close(vgobject *self)if (self->vg) {lvm_vg_close (self->vg); self->vg =NULL ; + self->libh_copy =NULL ; }Py_INCREF (Py_None);
@@ -941,15 +968,11 @@ static PyObject *_liblvm_lvm_vg_list_lvs(vgobject *self) dm_list_iterate_items(lvl, lvs) {/* Create and initialize the object */ -if (!(lvobj =PyObject_New (lvobject, &_LibLVMlvType))) { +if (!(lvobj =_create_py_lv (self, lvl->lv))) {Py_DECREF (pytuple);return NULL ; } - lvobj->parent_vgobj = self; -Py_INCREF (lvobj->parent_vgobj); - - lvobj->lv = lvl->lv;PyTuple_SET_ITEM (pytuple, i, (PyObject *) lvobj); i++; }
@@ -986,29 +1009,19 @@ static PyObject *_liblvm_lvm_vg_create_lv_linear(vgobject *self, PyObject *args) {const char *vgname;unsigned long long size; -lvobject *lvobj; +lv_t lv;VG_VALID (self);if (!PyArg_ParseTuple (args,"sK" , &vgname, &size))return NULL ; -if (!(lvobj =PyObject_New (lvobject, &_LibLVMlvType))) -return NULL ; - -/* Initialize the parent ptr in case lv create fails and we dealloc lvobj */ - lvobj->parent_vgobj =NULL ; - -if (!(lvobj->lv =lvm_vg_create_lv_linear (self->vg, vgname, size))) { +if (!(lv =lvm_vg_create_lv_linear (self->vg, vgname, size))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj);return NULL ; } - lvobj->parent_vgobj = self; -Py_INCREF (lvobj->parent_vgobj); - -return (PyObject *)lvobj; +return (PyObject *)_create_py_lv (self, lv); }static PyObject *_liblvm_lvm_vg_create_lv_thinpool (vgobject *self,PyObject *args)
@@ -1019,7 +1032,7 @@ static PyObject *_liblvm_lvm_vg_create_lv_thinpool(vgobject *self, PyObject *argunsigned long chunk_size =0 ;int skip_zero =0 ;lvm_thin_discards_t discard =LVM_THIN_DISCARDS_PASSDOWN ; -lvobject *lvobj; +lv_t lv;lv_create_params_t lvp =NULL ;struct lvm_property_value prop_value;
@@ -1029,17 +1042,10 @@ static PyObject *_liblvm_lvm_vg_create_lv_thinpool(vgobject *self, PyObject *arg &meta_size, &discard, &skip_zero))return NULL ; -if (!(lvobj =PyObject_New (lvobject, &_LibLVMlvType))) -return NULL ; - -/* Initialize the parent ptr in case lv create fails and we dealloc lvobj */ - lvobj->parent_vgobj =NULL ; -if (!(lvp =lvm_lv_params_create_thin_pool (self->vg, pool_name, size, chunk_size, meta_size, discard))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj);return NULL ; }
@@ -1051,23 +1057,20 @@ static PyObject *_liblvm_lvm_vg_create_lv_thinpool(vgobject *self, PyObject *argif (lvm_lv_params_set_property (lvp,"skip_zero" , &prop_value) ==-1 ) { -PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj); -return NULL ; + goto error; } } } -if (!(lvobj->lv =lvm_lv_create (lvp))) { -PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj); -return NULL ; +if (!(lv =lvm_lv_create (lvp))) { + goto error; } - lvobj->parent_vgobj = self; -Py_INCREF (lvobj->parent_vgobj); +return (PyObject *)_create_py_lv (self, lv); -return (PyObject *)lvobj; +error: +PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); +return NULL ; }static PyObject *_liblvm_lvm_vg_create_lv_thin (vgobject *self,PyObject *args)
@@ -1075,7 +1078,7 @@ static PyObject *_liblvm_lvm_vg_create_lv_thin(vgobject *self, PyObject *args)const char *pool_name;const char *lv_name;unsigned long long size =0 ; -lvobject *lvobj; +lv_t lv;lv_create_params_t lvp =NULL ;VG_VALID (self);
@@ -1083,28 +1086,17 @@ static PyObject *_liblvm_lvm_vg_create_lv_thin(vgobject *self, PyObject *args)if (!PyArg_ParseTuple (args,"ssK" , &pool_name, &lv_name, &size))return NULL ; -if (!(lvobj =PyObject_New (lvobject, &_LibLVMlvType))) -return NULL ; - -/* Initialize the parent ptr in case lv create fails and we dealloc lvobj */ - lvobj->parent_vgobj =NULL ; -if (!(lvp =lvm_lv_params_create_thin (self->vg, pool_name, lv_name,size))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj);return NULL ; } -if (!(lvobj->lv =lvm_lv_create (lvp))) { +if (!(lv =lvm_lv_create (lvp))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj);return NULL ; } - lvobj->parent_vgobj = self; -Py_INCREF (lvobj->parent_vgobj); - -return (PyObject *)lvobj; +return (PyObject *)_create_py_lv (self, lv); }static void liblvm_lv_dealloc (lvobject *self)
@@ -1157,7 +1149,6 @@ typedef pv_t (*pv_fetch_by_N)(vg_t vg, const char *id);static PyObject *_liblvm_lvm_lv_from_N (vgobject *self,PyObject *arg,lv_fetch_by_N method) {const char *id; -lvobject *lvobj;lv_t lv =NULL ;VG_VALID (self);
@@ -1170,15 +1161,7 @@ static PyObject *_liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_breturn NULL ; } -if (!(lvobj =PyObject_New (lvobject, &_LibLVMlvType))) -return NULL ; - - lvobj->parent_vgobj = self; -Py_INCREF (lvobj->parent_vgobj); - - lvobj->lv = lv; - -return (PyObject *)lvobj; +return (PyObject *)_create_py_lv (self, lv); }static PyObject *_liblvm_lvm_lv_from_name (vgobject *self,PyObject *arg)
@@ -1242,12 +1225,12 @@ static void _liblvm_pv_dealloc(pvobject *self)/* LV Methods */ #define LV_VALID (lvobject) \ - do { \ - VG_VALID(lvobject->parent_vgobj); \ - if (!lvobject->lv) { \ + do { \ + if (!lvobject || !lvobject->lv) { \ PyErr_SetString(PyExc_UnboundLocalError, "LV object invalid"); \ - return NULL; \ - } \ + return NULL; \ + }\ + VG_VALID(lvobject->parent_vgobj); \ } while (0)static PyObject *_liblvm_lvm_lv_get_attr (lvobject *self)
@@ -1510,7 +1493,7 @@ static PyObject *_liblvm_lvm_lv_snapshot(lvobject *self, PyObject *args) {const char *snap_name;unsigned long long size =0 ; -lvobject *lvobj; +lv_t lv;lv_create_params_t lvp =NULL ;LV_VALID (self);
@@ -1518,43 +1501,33 @@ static PyObject *_liblvm_lvm_lv_snapshot(lvobject *self, PyObject *args)if (!PyArg_ParseTuple (args,"s|K" , &snap_name, &size))return NULL ; -if (!(lvobj =PyObject_New (lvobject, &_LibLVMlvType))) -return NULL ; - - lvobj->parent_vgobj =NULL ; -if (!(lvp =lvm_lv_params_create_snapshot (self->lv, snap_name, size))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj);return NULL ; } -if (!(lvobj->lv =lvm_lv_create (lvp))) { +if (!(lv =lvm_lv_create (lvp))) {PyErr_SetObject (_LibLVMError,_liblvm_get_last_error ()); -Py_DECREF (lvobj);return NULL ; } - lvobj->parent_vgobj = self->parent_vgobj; -Py_INCREF (lvobj->parent_vgobj); - -return (PyObject *)lvobj; +return (PyObject *)_create_py_lv (self->parent_vgobj, lv); }/* PV Methods */ #define PV_VALID (pvobject) \ do { \ + if (!pvobject || !pvobject->pv) { \ + PyErr_SetString(PyExc_UnboundLocalError, "PV object invalid"); \ + return NULL; \ + } \ if (pvobject->parent_vgobj) { \ VG_VALID(pvobject->parent_vgobj); \ } \ if (pvobject->parent_pvslistobj) { \ PVSLIST_VALID(pvobject->parent_pvslistobj); \ } \ - if (!pvobject->pv) { \ - PyErr_SetString(PyExc_UnboundLocalError, "PV object invalid"); \ - return NULL; \ - } \ } while (0)static PyObject *_liblvm_lvm_pv_get_name (pvobject *self)
@@ -1673,7 +1646,14 @@ static PyObject *_liblvm_lvm_pv_list_pvsegs(pvobject *self)* No way to close/destroy an lvseg, just need to make sure parents are * still good */ -#define LVSEG_VALID (lvsegobject) LV_VALID(lvsegobject->parent_lvobj) +#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)static void _liblvm_lvseg_dealloc (lvsegobject *self) {
@@ -1702,7 +1682,14 @@ static PyObject *_liblvm_lvm_lvseg_get_property(lvsegobject *self, PyObject *arg* No way to close/destroy a pvseg, just need to make sure parents are * still good */ -#define PVSEG_VALID (pvsegobject) PV_VALID(pvsegobject->parent_pvobj) +#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)static void _liblvm_pvseg_dealloc (pvsegobject *self) {
Signature · 1 line
1.8.2.1
PATCH 3/4 vgreduce: Move _vgreduce_single functionality
In reply to Tony AslesonMoving the core functionality of vgreduce single into lib/metadata/vg.c so that the command line and lvm2app library can call the same core functionality. New function is vgreduce_single.
--- lib/metadata/metadata-exported.h | 4 ++ lib/metadata/vg.c | 87 ++++++++++++++++++++++++++++++++++++++++ tools/vgreduce.c | 81 ++----------------------------------- 3 files changed, 95 insertions(+), 77 deletions(-)
lib/metadata/metadata-exported.h +4 -0
@@ -587,6 +587,10 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg,int vg_extend (struct volume_group *vg,int pv_count,const char *const *pv_names,struct pvcreate_params *pp);int vg_reduce (struct volume_group *vg,const char *pv_name); + +int vgreduce_single (struct cmd_context *cmd,struct volume_group *vg, +struct physical_volume *pv); +int vg_change_tag (struct volume_group *vg,const char *tag,int add_tag);int vg_split_mdas (struct cmd_context *cmd,struct volume_group *vg_from,struct volume_group *vg_to);
lib/metadata/vg.c +87 -0
96 lines not on this page · raw message
tools/vgreduce.c +4 -77
92 lines not on this page · raw message
Signature · 1 line
1.8.2.1
PATCH 4/4 metadata.c: Call refactored vgreduce_single
In reply to Tony AslesonReplace the code with the refactored vgreduce_single instead of calling its own implementation.
NOTE: This change although it works is incomplete because in the case where we return an error "Cannot remove final metadata area on ..." the vg pointer that was passed in is modified significantly and thus cannot be used again by the caller.
--- lib/metadata/metadata.c | 35 ++--------------------------------- lib/metadata/vg.c | 6 ++++++ 2 files changed, 8 insertions(+), 33 deletions(-)
lib/metadata/metadata.c +2 -33
@@ -685,51 +685,20 @@ int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_namesreturn 1 ; } -/* FIXME: use this inside vgreduce_single? */ int vg_reduce (struct volume_group *vg,const char *pv_name) {struct physical_volume *pv;struct pv_list *pvl; -if (_vg_bad_status_bits (vg,RESIZEABLE_VG )) -return 0 ; - -if (!archive (vg)) - goto bad; - -/* remove each pv */ if (!(pvl =find_pv_in_vg (vg, pv_name))) {log_error ("Physical volume %s not in volume group %s." , pv_name, vg->name); - goto bad; +return 0 ; } pv = pvl->pv; -if (pv_pe_alloc_count (pv)) { -log_error ("Physical volume %s still in use." , - pv_name); - goto bad; - } - -if (!dev_get_size (pv_dev (pv), &pv->size)) { -log_error ("%s: Couldn't get size." , pv_name); - goto bad; - } - - vg->free_count -=pv_pe_count (pv) -pv_pe_alloc_count (pv); - vg->extent_count -=pv_pe_count (pv); -del_pvl_from_vgs (vg, pvl); - -/* add pv to the remove_pvs list */ -dm_list_add (&vg->removed_pvs, &pvl->list); - -return 1 ; - - bad: -log_error ("Unable to remove physical volume '%s' from " -"volume group '%s'." , pv_name, vg->name); -return 0 ; +return vgreduce_single (vg->cmd, vg, pv); }int lv_change_tag (struct logical_volume *lv,const char *tag,int add_tag)
lib/metadata/vg.c +6 -0
@@ -642,6 +642,12 @@ int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,if (vg_read_error (orphan_vg)) goto bad; +/* +* FIXME: The vg has been modified up to this point and will get modified +* further in the call to vg_split_mdas. When we hit this error we leave +* the vg pointer in this inconsistent state which is a problem when the +* user is a lvm2app library user. +*/ if (!vg_split_mdas (cmd, vg, orphan_vg) || !vg->pv_count) {log_error ("Cannot remove final metadata area on \"%s\" from \"%s\"" , name, vg->name);
Signature · 1 line
1.8.2.1