]> sourceware.org Git - lvm2.git/commitdiff
Implement lvm_lv_activate and lvm_lv_deactivate liblvm calls.
authorDave Wysochanski <dwysocha@redhat.com>
Sun, 26 Jul 2009 20:57:37 +0000 (20:57 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Sun, 26 Jul 2009 20:57:37 +0000 (20:57 +0000)
Limited implementation but other types of activation should probably have
separate calls.  We also currently do not handle pvmoves or lvconverts.

Author: Dave Wysochanski <dwysocha@redhat.com>

liblvm/.exported_symbols
liblvm/lvm.h
liblvm/lvm_lv.c

index d0e87df64bad99f9b38d3029d5373a44184b7d12..6708154d08c9b107c59eaa33b466faa5f5f79e3e 100644 (file)
@@ -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
index 3aa49afbb4cf0ac4ac1c4b3036bff8e99471c94e..13c723d2746a8e0e6757ce9f6e8f4a07ab35e176 100644 (file)
@@ -442,6 +442,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  0 (success) or -1 (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  0 (success) or -1 (failure).
+ */
+int lvm_lv_deactivate(lv_t *lv);
+
 /**
  * Remove a logical volume from a volume group.
  *
index e66789413abc24dbae5e942d0f1c9782949bd877..78057afe8fe96b2f9ae683042e62ef45511c3e83 100644 (file)
@@ -18,6 +18,8 @@
 #include "lvm-string.h"
 #include "defaults.h"
 #include "segtype.h"
+#include "locking.h"
+
 #include <string.h>
 
 /* FIXME: have lib/report/report.c _disp function call lv_size()? */
@@ -104,3 +106,51 @@ int lvm_vg_remove_lv(lv_t *lv)
                return -1;
        return 0;
 }
+
+int lvm_lv_activate(lv_t *lv)
+{
+       if (!lv || !lv->vg || vg_read_error(lv->vg) || !lv->vg->cmd)
+               return -1;
+
+       /* FIXME: handle pvmove stuff later */
+       if (lv->status & LOCKED) {
+               log_error("Unable to activate locked LV\n");
+               return -1;
+       }
+
+       /* FIXME: handle lvconvert stuff later */
+       if (lv->status & CONVERTING) {
+               log_error("Unable to activate LV with in-progress lvconvert\n");
+               return -1;
+       }
+
+       if (lv_is_origin(lv)) {
+               log_verbose("Activating logical volume \"%s\" "
+                           "exclusively", lv->name);
+               if (!activate_lv_excl(lv->vg->cmd, lv)) {
+                       log_error("Activate exclusive failed.\n");
+                       return -1;
+               }
+       } else {
+               log_verbose("Activating logical volume \"%s\"",
+                           lv->name);
+               if (!activate_lv(lv->vg->cmd, lv)) {
+                       log_error("Activate failed.\n");
+                       return -1;
+               }
+       }
+       return 0;
+}
+
+int lvm_lv_deactivate(lv_t *lv)
+{
+       if (!lv || !lv->vg || vg_read_error(lv->vg) || !lv->vg->cmd)
+               return -1;
+
+       log_verbose("Deactivating logical volume \"%s\"", lv->name);
+       if (!deactivate_lv(lv->vg->cmd, lv)) {
+               log_error("Deactivate failed.\n");
+               return -1;
+       }
+       return 0;
+}
This page took 0.036531 seconds and 5 git commands to generate.