Skip to contentSkip to conversation

lvm2app: Implement lvm_pv_remove

PATCH New Tony Asleson 1 participant 3 messages Apr 2, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 lvm2app: Implement lvm_pv_remove

Code move and changes to support calling code from command line and from library interface.

---
 lib/metadata/metadata.h |   4 ++
 lib/metadata/pv_manip.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++
 liblvm/lvm2app.h        |  16 +++++-
 liblvm/lvm_pv.c         |   8 +++
 tools/pvremove.c        | 135 +++---------------------------------------------
 5 files changed, 163 insertions(+), 130 deletions(-)
lib/metadata/metadata.h +4 -0
index 0c13a97..35be923 100644
@@ -341,6 +341,10 @@ int vg_validate(struct volume_group *vg);
 
 int pv_write_orphan(struct cmd_context *cmd, struct physical_volume *pv);
 
+int pvremove_single(struct cmd_context *cmd, const char *pv_name,
+			   void *handle __attribute__((unused)), unsigned force_count,
+			   unsigned prompt);
+
 /* 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 +130 -0

139 lines not on this page · raw message

liblvm/lvm2app.h +14 -2
index a17d5ac..5fe41ac 100644
@@ -544,14 +544,15 @@ struct dm_list *lvm_vg_list_lvs(vg_t vg);
  * \return
  * A list of lvm_pv_list structures containing pv handles for all physical
  * volumes. If no PVs exist or a global lock was unable to be obtained a
- * NULL is returned.
+ * NULL is returned.  Do not attempt to remove one of the PVs until after the
+ * call to lvm_list_pvs_free has been made.
  */
 struct dm_list *lvm_list_pvs(lvm_t libh);
 
 /**
  * Free the resources used by acquiring the pvlist.  This should be called as
  * soon as possible after processing the needed information from the pv list as
- * a global locks are held.
+ * a global lock is held.
  *
  * \param	pvlist
  * PV list to be freed
@@ -562,6 +563,17 @@ struct dm_list *lvm_list_pvs(lvm_t libh);
 int lvm_list_pvs_free(struct dm_list *pvlist);
 
 /**
+ *  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.
+ *  \param	libh	Library handle
+ *  \param	pv_name	The physical volume name
+ *  \return
+ *  0 on success, else -1 with library errno and text set.
+ */
+int lvm_pv_remove(lvm_t libh, const char *pv_name);
+
+/**
  * Return a list of PV handles for a given VG handle.
  *
  * \memberof vg_t
liblvm/lvm_pv.c +8 -0
index dcb1a29..390c2b7 100644
@@ -75,6 +75,14 @@ struct lvm_list_wrapper
 	struct dm_list vgslist;
 };
 
+int lvm_pv_remove(lvm_t libh, const char *pv_name)
+{
+	struct cmd_context *cmd = (struct cmd_context *)libh;
+	if ( 1 != pvremove_single(cmd, pv_name, NULL, 0, 0)) {
+		return -1;
+	}
+	return 0;
+}
 
 struct dm_list *lvm_list_pvs(lvm_t libh)
 {
tools/pvremove.c +7 -128

157 lines not on this page · raw message

Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 2/3 python-lvm: Add bindings for lvm_pv_remove

Method off of base lvm namespace "pvRemove".

---
 python/liblvm.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
python/liblvm.c +20 -0
index 928cab0..9d0d8f8 100644
@@ -244,6 +244,25 @@ liblvm_lvm_list_pvs(void)
 }
 
 static PyObject *
+liblvm_lvm_pv_remove(PyObject *self, PyObject *arg)
+{
+	const char *pv_name;
+	LVM_VALID();
+
+	if (!PyArg_ParseTuple(arg, "s", &pv_name))
+			return NULL;
+
+	int rc = lvm_pv_remove(libh, pv_name);
+	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;
@@ -1664,6 +1683,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 },
+	{ "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 },
 	{ "vgNameFromDevice",	(PyCFunction)liblvm_lvm_vgname_from_device, METH_VARARGS },
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 3/3 lvm2app: Set suppress to 1

In reply to Tony Asleson

Removes printing to stdout/stderr etc.

---
 liblvm/lvm_base.c | 6 ++++++
 1 file changed, 6 insertions(+)
liblvm/lvm_base.c +6 -0
index 53be709..67ed023 100644
@@ -66,6 +66,12 @@ lvm_t lvm_init(const char *system_dir)
 	 */
 	cmd->cmd_line = "liblvm";
 
+	/*
+	 * Turn off writing to stderr etc., not sure if there is a better way
+	 * to do this?
+	 */
+	log_suppress(1);
+
 	return (lvm_t) cmd;
 }
 
Signature · 1 line
1.8.1.4