]> sourceware.org Git - lvm2.git/commitdiff
Add lvm_lv_get_tags(), lvm_lv_add_tag(), and lvm_lv_remove_tag().
authorDave Wysochanski <dwysocha@redhat.com>
Wed, 24 Feb 2010 18:16:26 +0000 (18:16 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Wed, 24 Feb 2010 18:16:26 +0000 (18:16 +0000)
Add lvm2app functions to manage LV tags.
For lvm_lv_get_tags(), we return a list of tags, similar to other
functions that return lists.  An empty list is returned if there
are no tags.  NULL is returned if there is a problem obtaining
the list of tags.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
liblvm/.exported_symbols
liblvm/lvm2app.h
liblvm/lvm_lv.c

index 7431248911f776f644ce2d7d2c7467ed885c145f..9b61d452c1538b880d8f5e2b731fe0efbab264bb 100644 (file)
@@ -26,6 +26,9 @@ lvm_lv_get_name
 lvm_lv_get_size
 lvm_lv_is_active
 lvm_lv_is_suspended
+lvm_lv_add_tag
+lvm_lv_remove_tag
+lvm_lv_get_tags
 lvm_vg_create
 lvm_vg_extend
 lvm_vg_reduce
index 41ce18c9aed8b2b3ed14b99a696c50d63576544b..e0523012762e36f2c448babcb5d06bd45e8b69a3 100644 (file)
@@ -834,6 +834,54 @@ uint64_t lvm_lv_is_active(const lv_t lv);
  */
 uint64_t lvm_lv_is_suspended(const lv_t lv);
 
+/**
+ * Add/remove a tag to/from a LV.
+ *
+ * These functions require calling lvm_vg_write to commit the change to disk.
+ * After successfully adding/removing a tag, use lvm_vg_write to commit the
+ * new VG to disk.  Upon failure, retry the operation or release the VG handle
+ * with lvm_vg_close.
+ *
+ * \param   lv
+ * Logical volume handle.
+ *
+ * \param   tag
+ * Tag to add/remove to/from LV.
+ *
+ * \return
+ * 0 (success) or -1 (failure).
+ */
+int lvm_lv_add_tag(lv_t lv, const char *tag);
+int lvm_lv_remove_tag(lv_t lv, const char *tag);
+
+/**
+ * Return the list of logical volume tags.
+ *
+ * The memory allocated for the list is tied to the vg_t handle and will be
+ * released when lvm_vg_close is called.
+ *
+ * To process the list, use the dm_list iterator functions.  For example:
+ *      lv_t lv;
+ *      struct dm_list *tags;
+ *      struct lvm_str_list *strl;
+ *
+ *      tags = lvm_lv_get_tags(lv);
+ *     dm_list_iterate_items(strl, tags) {
+ *             tag = strl->str;
+ *              // do something with tag
+ *      }
+ *
+ *
+ * \return
+ * A list with entries of type struct lvm_str_list, containing the
+ * tag strings attached to volume group.
+ * If no tags are attached to the LV, an empty list is returned
+ * (check with dm_list_empty()).
+ * If there is a problem obtaining the list of tags, NULL is returned.
+ */
+struct dm_list *lvm_lv_get_tags(const lv_t lv);
+
+
 /**
  * Resize logical volume to new_size bytes.
  *
index 7a37d2c8f274160cd1bac8807d8b79f3e7049e76..86175aeb6ffe1f889179855f37ecf949451291fb 100644 (file)
 #include "segtype.h"
 #include "locking.h"
 #include "activate.h"
+#include "lvm_misc.h"
 
 #include <string.h>
 
+static int _lv_check_handle(const lv_t lv, const int vg_writeable)
+{
+       if (!lv || !lv->vg || vg_read_error(lv->vg))
+               return -1;
+       if (vg_writeable && !vg_check_write_mode(lv->vg))
+               return -1;
+       return 0;
+}
+
 /* FIXME: have lib/report/report.c _disp function call lv_size()? */
 uint64_t lvm_lv_get_size(const lv_t lv)
 {
@@ -68,6 +78,31 @@ uint64_t lvm_lv_is_suspended(const lv_t lv)
        return 0;
 }
 
+int lvm_lv_add_tag(lv_t lv, const char *tag)
+{
+       if (_lv_check_handle(lv, 1))
+               return -1;
+       if (!lv_change_tag(lv, tag, 1))
+               return -1;
+       return 0;
+}
+
+
+int lvm_lv_remove_tag(lv_t lv, const char *tag)
+{
+       if (_lv_check_handle(lv, 1))
+               return -1;
+       if (!lv_change_tag(lv, tag, 0))
+               return -1;
+       return 0;
+}
+
+
+struct dm_list *lvm_lv_get_tags(const lv_t lv)
+{
+       return tag_list_copy(lv->vg->vgmem, &lv->tags);
+}
+
 /* Set defaults for non-segment specific LV parameters */
 static void _lv_set_default_params(struct lvcreate_params *lp,
                                   vg_t vg, const char *lvname,
This page took 0.035516 seconds and 5 git commands to generate.