]> sourceware.org Git - lvm2.git/commitdiff
Add simple function for lookup of some free device_id
authorZdenek Kabelac <zkabelac@redhat.com>
Mon, 3 Oct 2011 18:39:17 +0000 (18:39 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Mon, 3 Oct 2011 18:39:17 +0000 (18:39 +0000)
Initial simple implementation for finding some free device_id.

lib/metadata/metadata.h
lib/metadata/thin_manip.c

index e984ba83de7e05f375d867c90969f22add1487bd..d1b1b1f33c83809bb61dad9b548c71031a3e2d95 100644 (file)
@@ -374,6 +374,9 @@ struct lv_segment *find_seg_by_le(const struct logical_volume *lv, uint32_t le);
 /* Find pool LV segment given a thin pool data or metadata segment. */
 struct lv_segment *find_pool_seg(const struct lv_segment *seg);
 
+/* Find some unused device_id for thin pool LV segment. */
+uint32_t get_free_pool_device_id(struct lv_segment *thin_pool_seg);
+
 /*
  * Remove a dev_dir if present.
  */
index 2412db6c3668fa333304c6056f0b30708185838e..ead12181629e65605eb25f1423c30c2eee944ef3 100644 (file)
@@ -80,3 +80,40 @@ struct lv_segment *find_pool_seg(const struct lv_segment *seg)
 
         return pool_seg;
 }
+
+/*
+ * Find a free device_id for given thin_pool segment.
+ *
+ * \return
+ * Free device id, or 0 if free device_id is not found.
+ *
+ * FIXME: Improve naive search and keep the value cached
+ * and updated during VG lifetime (so no const for lv_segment)
+ */
+uint32_t get_free_pool_device_id(struct lv_segment *thin_pool_seg)
+{
+       uint32_t dev_id, max_id = 0;
+       struct dm_list *h;
+
+       if (!seg_is_thin_pool(thin_pool_seg)) {
+               log_error("Segment in %s is not a thin pool segment.",
+                         pool_seg->lv->name);
+               return 0;
+       }
+
+       dm_list_iterate(h, &thin_pool_seg->lv->segs_using_this_lv) {
+               dev_id = dm_list_item(h, struct seg_list)->seg->device_id;
+               if (dev_id > max_id)
+                       max_id = dev_id;
+       }
+
+       if (++max_id >= (1 << 24)) {
+               // FIXME: try to find empty holes....
+               log_error("Free device_id exhausted...");
+               return 0;
+       }
+
+       log_debug("Found free pool device_id %u.", max_id);
+
+       return max_id;
+}
This page took 0.039728 seconds and 5 git commands to generate.