Skip to contentSkip to conversation

Implement activation related liblvm APIs.

PATCH New Dave Wysochanski 1 participant 5 messages Jul 26, 2009

lore
Share & tools
lore
#0 lore raw

cover Implement activation related liblvm APIs.

This patch set implements lvm_lv_activate, lvm_lv_deactivate, lvm_lv_is_suspended and lvm_lv_is_active.

Applies cleanly on:
commit ac1f36ae761cb803250042fefcfd1ec5148ff659

Author: Dave Wysochanski <[email protected]>
Date:   Sun Jul 26 16:49:52 2009 +0000

A few more lvm.h updates that got missed.

#1 lore raw

PATCH 1/4 Implement lvm_lv_activate and lvm_lv_deactivate liblvm calls.

Limited implementation but other types of activation should probably have separate calls. We also currently do not handle pvmoves or lvconverts.

---
 liblvm/.exported_symbols |    2 ++
 liblvm/lvm.h             |   25 +++++++++++++++++++++++++
 liblvm/lvm_lv.c          |   44 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 0 deletions(-)
liblvm/.exported_symbols +2 -0
index d0e87df..6708154 100644
@@ -12,6 +12,8 @@ lvm_vg_get_extent_size
 lvm_vg_get_extent_count
 lvm_vg_get_free_extent_count
 lvm_vg_get_pv_count
+lvm_lv_activate
+lvm_lv_deactivate
 lvm_lv_get_uuid
 lvm_lv_get_name
 lvm_lv_get_size
liblvm/lvm.h +25 -0
index ac64ca2..c5c4486 100644
@@ -441,6 +441,31 @@ struct dm_list *lvm_vg_list_lvs(vg_t *vg);
 lv_t *lvm_vg_create_lv_linear(vg_t *vg, const char *name, uint64_t size);
 
 /**
+ * Activate a logical volume.
+ *
+ * This API is the equivalent of the lvm command "lvchange -ay".
+ *
+ * NOTE: This API cannot currently handle LVs with an in-progress pvmove or
+ * lvconvert.
+ *
+ * \param   lv
+ *          Logical volume handle.
+ * \return  Status code of 1 (success) or 0 (failure).
+ */
+int lvm_lv_activate(lv_t *lv);
+
+/**
+ * Deactivate a logical volume.
+ *
+ * This API is the equivalent of the lvm command "lvchange -an".
+ *
+ * \param   lv
+ *          Logical volume handle.
+ * \return  Status code of 1 (success) or 0 (failure).
+ */
+int lvm_lv_deactivate(lv_t *lv);
+
+/**
  * Remove a logical volume from a volume group.
  *
  * This function commits the change to disk and does _not_ require calling
liblvm/lvm_lv.c +44 -0

53 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#2 lore raw

PATCH 2/4 Add lvm_lv_is_active and lvm_lv_is_suspended.

Return whether an LV is active in the kernel (live table) or suspended (table suspend).

---
 liblvm/.exported_symbols |    2 ++
 liblvm/lvm.h             |   18 ++++++++++++++++++
 liblvm/lvm_lv.c          |   19 +++++++++++++++++++
 3 files changed, 39 insertions(+), 0 deletions(-)
liblvm/.exported_symbols +2 -0
index 6708154..9911423 100644
@@ -17,6 +17,8 @@ lvm_lv_deactivate
 lvm_lv_get_uuid
 lvm_lv_get_name
 lvm_lv_get_size
+lvm_lv_is_active
+lvm_lv_is_suspended
 lvm_vg_create
 lvm_vg_extend
 lvm_vg_set_extent_size
liblvm/lvm.h +18 -0
index c5c4486..2e8d5c6 100644
@@ -514,6 +514,24 @@ char *lvm_lv_get_name(const lv_t *lv);
  */
 uint64_t lvm_lv_get_size(const lv_t *lv);
 
+/**
+ * Get the current activation state of a logical volume.
+ *
+ * \param   lv
+ *          Logical volume handle.
+ * \return  1 if the LV is active in the kernel, 0 if not
+ */
+uint64_t lvm_lv_is_active(const lv_t *lv);
+
+/**
+ * Get the current suspended state of a logical volume.
+ *
+ * \param   lv
+ *          Logical volume handle.
+ * \return  1 if the LV is suspended in the kernel, 0 if not
+ */
+uint64_t lvm_lv_is_suspended(const lv_t *lv);
+
 /************************** physical volume handling ************************/
 
 /**
liblvm/lvm_lv.c +19 -0
index 4a12030..7d0ec01 100644
@@ -19,6 +19,7 @@
 #include "defaults.h"
 #include "segtype.h"
 #include "locking.h"
+#include "activate.h"
 
 #include <string.h>
 
@@ -49,6 +50,24 @@ char *lvm_lv_get_name(const lv_t *lv)
 	return name;
 }
 
+uint64_t lvm_lv_is_active(const lv_t *lv)
+{
+	struct lvinfo info;
+	if (lv_info(lv->vg->cmd, lv, &info, 1, 0) &&
+	    info.exists && info.live_table)
+		return 1;
+	return 0;
+}
+
+uint64_t lvm_lv_is_suspended(const lv_t *lv)
+{
+	struct lvinfo info;
+	if (lv_info(lv->vg->cmd, lv, &info, 1, 0) &&
+	    info.exists && info.suspended)
+		return 1;
+	return 0;
+}
+
 /* Set defaults for non-segment specific LV parameters */
 static void _lv_set_default_params(struct lvcreate_params *lp,
 				   vg_t *vg, const char *lvname,
Signature · 1 line
1.6.0.6
#3 lore raw

PATCH 3/4 Update test/api/test.c to call lv_deactivate and lv_activate.

---
 test/api/test.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)
test/api/test.c +44 -0
index 289278d..a97a192 100644
@@ -50,6 +50,10 @@ static int lvm_split(char *str, int *argc, char **argv, int max)
 
 static void _show_help(void)
 {
+	printf("'lv_activate vgname lvname: "
+	       "Activate an LV\n");
+	printf("'lv_deactivate vgname lvname: "
+	       "Deactivate an LV\n");
 	printf("'vg_remove_lv vgname lvname': "
 	       "Remove a LV\n");
 	printf("'vg_create_lv_linear vgname lvname size_in_bytes': "
@@ -317,6 +321,42 @@ static void _lvs_in_vg(char **argv, int argc)
 	}
 }
 
+static void _lv_deactivate(char **argv, int argc)
+{
+	lv_t *lv;
+
+	if (argc < 3) {
+		printf("Please enter vgname, lvname\n");
+		return;
+	}
+	if (!(lv = _lookup_lv_by_name(argv[2])))
+		return;
+	if (!lvm_lv_deactivate(lv))
+		printf("Error ");
+	else {
+		printf("Success ");
+	}
+	printf("De-activating LV %s in VG %s\n",
+		argv[2], argv[1]);
+}
+static void _lv_activate(char **argv, int argc)
+{
+	lv_t *lv;
+
+	if (argc < 3) {
+		printf("Please enter vgname, lvname\n");
+		return;
+	}
+	if (!(lv = _lookup_lv_by_name(argv[2])))
+		return;
+	if (!lvm_lv_activate(lv))
+		printf("Error ");
+	else {
+		printf("Success ");
+	}
+	printf("activating LV %s in VG %s\n",
+		argv[2], argv[1]);
+}
 static void _vg_remove_lv(char **argv, int argc)
 {
 	lv_t *lv;
@@ -404,6 +444,10 @@ static int lvmapi_test_shell(lvm_t libh)
 			_vg_open(argv, argc, libh);
 		} else if (!strcmp(argv[0], "vg_close")) {
 			_vg_close(argv, argc);
+		} else if (!strcmp(argv[0], "lv_activate")) {
+			_lv_activate(argv, argc);
+		} else if (!strcmp(argv[0], "lv_deactivate")) {
+			_lv_deactivate(argv, argc);
 		} else if (!strcmp(argv[0], "vg_remove_lv")) {
 			_vg_remove_lv(argv, argc);
 		} else if (!strcmp(argv[0], "vgs_open")) {
Signature · 1 line
1.6.0.6
#4 lore raw

PATCH 4/4 Update test/api/test.c to display lvm_lv_is_active and lvm_lv_is_suspended.

---
 test/api/test.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
test/api/test.c +5 -2
index a97a192..90aff67 100644
@@ -315,9 +315,12 @@ static void _lvs_in_vg(char **argv, int argc)
 	}
 	printf("LVs in VG %s:\n", lvm_vg_get_name(vg));
 	dm_list_iterate_items(lvl, lvs) {
-		printf("%s/%s (%s): size=%"PRIu64"\n", lvm_vg_get_name(vg),
+		printf("%s/%s (%s): size=%"PRIu64", %sACTIVE / %sSUSPENDED\n",
+			lvm_vg_get_name(vg),
 			lvm_lv_get_name(lvl->lv), lvm_lv_get_uuid(lvl->lv),
-			lvm_lv_get_size(lvl->lv));
+			lvm_lv_get_size(lvl->lv),
+			lvm_lv_is_active(lvl->lv) ? "" : "IN",
+			lvm_lv_is_suspended(lvl->lv) ? "" : "NOT ");
 	}
 }
 
Signature · 1 line
1.6.0.6