_get_pvs: Remove unused variable
PATCH 1/4 _get_pvs: Remove unused variable
Signed-off-by Tony Asleson <[email protected]>
--- lib/metadata/metadata.c | 1 - 1 file changed, 1 deletion(-)
lib/metadata/metadata.c +0 -1
@@ -3671,7 +3671,6 @@ static int _get_pvs(struct cmd_context *cmd, int warnings, struct dm_list *pvslist, struct dm_list *vgslist) { struct str_list *strl; -struct dm_list *uninitialized_var (results );const char *vgname, *vgid;struct pv_list *pvl, *pvl_copy;struct dm_list *vgids;
Signature · 1 line
1.8.1.4
PATCH 2/4 lib2app: Fix warnings in lvm_list_pvs_free
Signed-off-by Tony Asleson <[email protected]>
--- liblvm/lvm_pv.c | 2 -- 1 file changed, 2 deletions(-)
liblvm/lvm_pv.c +0 -2
@@ -116,9 +116,7 @@ int lvm_list_pvs_free(struct dm_list *pvlist)int rc =0 ;struct lvm_list_wrapper *to_delete =NULL ;struct vg_list *vgl =NULL ; -struct vg_list *tmp_vgl =NULL ;struct pv_list *pvl =NULL ; -struct pv_list *tmp_pvl =NULL ;struct cmd_context *cmd =NULL ;if (pvlist ) {
Signature · 1 line
1.8.1.4
PATCH 3/4 lib2app: Added PV create.
In reply to Tony AslesonSigned-off-by Tony Asleson <[email protected]>
--- lib/metadata/metadata.h | 3 +++ lib/metadata/pv_manip.c | 22 ++++++++++++++++++++++ liblvm/lvm2app.h | 10 ++++++++++ liblvm/lvm_pv.c | 26 ++++++++++++++++++++++++++ tools/pvcreate.c | 11 ++--------- 5 files changed, 63 insertions(+), 9 deletions(-)
lib/metadata/metadata.h +3 -0
@@ -345,6 +345,9 @@ int pvremove_single(struct cmd_context *cmd, const char *pv_name, void *handle __attribute__((unused)), unsigned force_count, unsigned prompt); +int pvcreate_locked (struct cmd_context *cmd,const char *pv_name, +struct pvcreate_params *pp); +/* Manipulate PV structures */ int pv_add (struct volume_group *vg,struct physical_volume *pv);int pv_remove (struct volume_group *vg,struct physical_volume *pv);
lib/metadata/pv_manip.c +22 -0
@@ -20,6 +20,8 @@#include "locking.h" #include "defaults.h" #include "lvmetad.h" +#include "display.h" +#include "label.h" static struct pv_segment *_alloc_pv_segment(struct dm_pool *mem, struct physical_volume *pv,
@@ -672,3 +674,23 @@ out:return ret; } + +int pvcreate_locked (struct cmd_context *cmd,const char *pv_name, +struct pvcreate_params *pp) +{ +int ret =ECMD_PROCESSED ; + +if (!lock_vol (cmd,VG_ORPHANS ,LCK_VG_WRITE )) { +log_error ("Can't get lock for orphan PVs" ); +return ECMD_FAILED ; + } + +if (!(pvcreate_single (cmd, pv_name, pp,1 ))) { + stack; + ret =ECMD_FAILED ; + } + +unlock_vg (cmd,VG_ORPHANS ); + +return ret; +}
liblvm/lvm2app.h +10 -0
@@ -563,6 +563,16 @@ struct dm_list *lvm_list_pvs(lvm_t libh);int lvm_list_pvs_free (struct dm_list *pvlist);/** +* Create a physical volume. +* \param libh Library handle +* \param pv_name The physical volume name +* \param size Size of physical volume, 0 = use all available. +* \return +* 0 on success, else -1 with library errno and text set. +*/ +int lvm_pv_create (lvm_t libh,const char *pv_name,uint64_t size); + +/** * Remove a physical volume. * Note: You cannot remove a PV while iterating through the list of PVs as * locks are held for the PV list.
liblvm/lvm_pv.c +26 -0
@@ -226,3 +226,29 @@ int lvm_pv_resize(const pv_t pv, uint64_t new_size)return 0 ; } } + +int lvm_pv_create (lvm_t libh,const char *pv_name,uint64_t size) +{ +int rc =-1 ; +struct pvcreate_params pp; +struct cmd_context *cmd = (struct cmd_context *)libh; +uint64_t size_sectors = size; + +pvcreate_params_set_defaults (&pp); + +if (size_sectors !=0 ) { +if ( size_sectors %SECTOR_SIZE ) { +log_errno (EINVAL ,"Size not a multiple of 512" ); +return -1 ; + } + size_sectors = size_sectors >>SECTOR_SHIFT ; + } + + pp.size = size_sectors; + +if (ECMD_PROCESSED ==pvcreate_locked (cmd, pv_name, &pp)) { + rc =0 ; + } + +return rc; +}
tools/pvcreate.c +2 -9
@@ -15,6 +15,7 @@#include "tools.h" #include "metadata-exported.h" +#include "metadata.h" /* * Intial sanity checking of recovery-related command-line arguments.
@@ -96,7 +97,6 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)int i;int ret =ECMD_PROCESSED ;struct pvcreate_params pp; -struct physical_volume *pv;pvcreate_params_set_defaults (&pp);
@@ -108,19 +108,12 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv) }for (i =0 ; i < argc; i++) { -if (!lock_vol (cmd,VG_ORPHANS ,LCK_VG_WRITE )) { -log_error ("Can't get lock for orphan PVs" ); -return ECMD_FAILED ; - } -dm_unescape_colons_and_at_signs (argv[i],NULL ,NULL ); -if (!(pv =pvcreate_single (cmd, argv[i], &pp,1 ))) { - stack; +if (ECMD_PROCESSED !=pvcreate_locked (cmd, argv[i], &pp)) { ret =ECMD_FAILED ; } -unlock_vg (cmd,VG_ORPHANS );if (sigint_caught ())return ret; }
Signature · 1 line
1.8.1.4
PATCH 4/4 python-lvm: Add pvCreate python method
In reply to Tony AslesonAdded to base namespace.
Signed-off-by Tony Asleson <[email protected]>
--- python/liblvm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
python/liblvm.c +21 -0
@@ -263,6 +263,26 @@ liblvm_lvm_pv_remove(PyObject *self, PyObject *arg) }static PyObject * +liblvm_lvm_pv_create (PyObject *self,PyObject *arg) +{ +const char *pv_name; +uint64_t size; +LVM_VALID (); + +if (!PyArg_ParseTuple (arg,"sl" , &pv_name, &size)) +return NULL ; + +int rc =lvm_pv_create (libh, pv_name, size); +if (0 != rc) { +PyErr_SetObject (LibLVMError,liblvm_get_last_error ()); +return NULL ; + } + +Py_INCREF (Py_None); +return Py_None; +} + +static PyObject *liblvm_lvm_percent_to_float (PyObject *self,PyObject *arg) {double converted;
@@ -1683,6 +1703,7 @@ static PyMethodDef Liblvm_methods[] = { { "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 }, { "vgNameFromPvid", (PyCFunction)liblvm_lvm_vgname_from_pvid, METH_VARARGS },
Signature · 1 line
1.8.1.4