]> sourceware.org Git - lvm2.git/commitdiff
Add registration of thin_pool segment
authorZdenek Kabelac <zkabelac@redhat.com>
Thu, 25 Aug 2011 10:00:09 +0000 (10:00 +0000)
committerZdenek Kabelac <zkabelac@redhat.com>
Thu, 25 Aug 2011 10:00:09 +0000 (10:00 +0000)
Register thin and thin_pool segment via multiple_segtypes.

lib/commands/toolcontext.c
lib/metadata/segtype.h
lib/thin/thin.c

index 520e260424b53c6911f2fb3ef24a75d13080b019..a91ccc7d838004e66017bf4c8b4bc9a8a9ef8e85 100644 (file)
@@ -1030,6 +1030,11 @@ static int _init_segtypes(struct cmd_context *cmd)
                return 0;
 #endif
 
+#ifdef THIN_INTERNAL
+       if (!init_thin_segtypes(cmd, &seglib))
+               return 0;
+#endif
+
 #ifdef HAVE_LIBDL
        /* Load any formats in shared libs unless static */
        if (!is_static() &&
index 24847dfe21750193ccbe3b2aeac7c44f7b11ecd9..7ce111bdb728dc9e492bb1b8074bc5fb0f69a654 100644 (file)
@@ -40,6 +40,7 @@ struct dev_manager;
 #define SEG_REPLICATOR_DEV     0x00000200U
 #define SEG_RAID               0x00000400U
 #define SEG_THIN               0x00000800U
+#define SEG_THIN_POOL          0x00001000U
 #define SEG_UNKNOWN            0x80000000U
 
 #define seg_is_mirrored(seg)   ((seg)->segtype->flags & SEG_AREAS_MIRRORED ? 1 : 0)
@@ -50,6 +51,7 @@ struct dev_manager;
 #define seg_is_virtual(seg)    ((seg)->segtype->flags & SEG_VIRTUAL ? 1 : 0)
 #define seg_is_raid(seg)       ((seg)->segtype->flags & SEG_RAID ? 1 : 0)
 #define seg_is_thin(seg)       ((seg)->segtype->flags & SEG_THIN ? 1 : 0)
+#define seg_is_thin_pool(seg)  ((seg)->segtype->flags & SEG_THIN_POOL ? 1 : 0)
 #define seg_can_split(seg)     ((seg)->segtype->flags & SEG_CAN_SPLIT ? 1 : 0)
 #define seg_cannot_be_zeroed(seg) ((seg)->segtype->flags & SEG_CANNOT_BE_ZEROED ? 1 : 0)
 #define seg_monitored(seg)     ((seg)->segtype->flags & SEG_MONITORED ? 1 : 0)
@@ -59,6 +61,7 @@ struct dev_manager;
 #define segtype_is_mirrored(segtype)   ((segtype)->flags & SEG_AREAS_MIRRORED ? 1 : 0)
 #define segtype_is_raid(segtype)       ((segtype)->flags & SEG_RAID ? 1 : 0)
 #define segtype_is_thin(segtype)       ((segtype)->flags & SEG_THIN ? 1 : 0)
+#define segtype_is_thin_pool(segtype)  ((segtype)->flags & SEG_THIN_POOL ? 1 : 0)
 #define segtype_is_virtual(segtype)    ((segtype)->flags & SEG_VIRTUAL ? 1 : 0)
 
 struct segment_type {
@@ -137,6 +140,10 @@ int init_raid_segtypes(struct cmd_context *cmd, struct segtype_library *seglib);
 int init_replicator_segtype(struct cmd_context *cmd, struct segtype_library *seglib);
 #endif
 
+#ifdef THIN_INTERNAL
+int init_thin_segtypes(struct cmd_context *cmd, struct segtype_library *seglib);
+#endif
+
 #ifdef SNAPSHOT_INTERNAL
 struct segment_type *init_snapshot_segtype(struct cmd_context *cmd);
 #endif
@@ -149,8 +156,4 @@ struct segment_type *init_mirrored_segtype(struct cmd_context *cmd);
 struct segment_type *init_crypt_segtype(struct cmd_context *cmd);
 #endif
 
-#ifdef THIN_INTERNAL
-struct segment_type *init_thin_segtype(struct cmd_context *cmd);
-#endif
-
 #endif
index 1bdf98650c68958f82f26ee087368947415a5936..fec274ec00108ff3fdc58764affb98b173369860 100644 (file)
 /* Dm kernel module name for thin provisiong */
 #define THIN_MODULE "thin-pool"
 
+static const char *_thin_pool_name(const struct lv_segment *seg)
+{
+       return seg->segtype->name;
+}
+
+
+static int _thin_pool_text_import(struct lv_segment *seg, const struct config_node *sn,
+                       struct dm_hash_table *pv_hash __attribute__((unused)))
+{
+       return 1;
+}
+
+static int _thin_pool_text_export(const struct lv_segment *seg, struct formatter *f)
+{
+       return 1;
+}
 
 static const char *_thin_name(const struct lv_segment *seg)
 {
@@ -67,7 +83,7 @@ static int _thin_target_present(struct cmd_context *cmd,
        static int _present = 0;
 
        if (!_checked) {
-               _present = target_present(cmd, "thin-pool", 1);
+               _present = target_present(cmd, THIN_MODULE, 1);
                _checked = 1;
        }
 
@@ -93,6 +109,14 @@ static void _thin_destroy(struct segment_type *segtype)
        dm_free(segtype);
 }
 
+static struct segtype_handler _thin_pool_ops = {
+       .name = _thin_pool_name,
+       .text_import = _thin_pool_text_import,
+       .text_export = _thin_pool_text_export,
+       .modules_needed = _thin_modules_needed,
+       .destroy = _thin_destroy,
+};
+
 static struct segtype_handler _thin_ops = {
        .name = _thin_name,
        .text_import = _thin_text_import,
@@ -106,30 +130,48 @@ static struct segtype_handler _thin_ops = {
 };
 
 #ifdef THIN_INTERNAL
-struct segment_type *init_thin_segtype(struct cmd_context *cmd)
-#else                          /* Shared */
-struct segment_type *init_segtype(struct cmd_context *cmd);
-struct segment_type *init_segtype(struct cmd_context *cmd)
+int init_thin_segtypes(struct cmd_context *cmd, struct segtype_library *seglib)
+#else /* Shared */
+int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *seglib);
+int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *seglib)
 #endif
 {
-       struct segment_type *segtype = dm_zalloc(sizeof(*segtype));
-
-       if (!segtype)
-               return_NULL;
-
-       segtype->cmd = cmd;
-       segtype->ops = &_thin_ops;
-       segtype->name = "thin";
-       segtype->private = NULL;
-       segtype->flags = SEG_THIN;
+       static const struct {
+               struct segtype_handler *ops;
+               const char name[16];
+               uint32_t flags;
+       } reg_segtypes[] = {
+               { &_thin_pool_ops, "thin_pool", SEG_THIN_POOL },
+               { &_thin_ops, "thin", SEG_THIN }
+       };
+
+       struct segment_type *segtype;
+       unsigned i;
+
+       for (i = 0; i < sizeof(reg_segtypes)/sizeof(reg_segtypes[0]); ++i) {
+               segtype = dm_zalloc(sizeof(*segtype));
+
+               if (!segtype) {
+                       log_error("Failed to allocate memory for %s segtype",
+                                 reg_segtypes[i].name);
+                       return 0;
+               }
+
+               segtype->ops = reg_segtypes[i].ops;
+               segtype->name = reg_segtypes[i].name;
+               segtype->flags = reg_segtypes[i].flags;
 
 #ifdef DEVMAPPER_SUPPORT
 #  ifdef DMEVENTD
-       if (_get_thin_dso_path(cmd))
-               segtype->flags |= SEG_MONITORED;
+               if (_get_thin_dso_path(cmd))
+                       segtype->flags |= SEG_MONITORED;
 #  endif       /* DMEVENTD */
 #endif
-       log_very_verbose("Initialised segtype: %s", segtype->name);
+               if (!lvm_register_segtype(seglib, segtype))
+                       return_0;
 
-       return segtype;
+               log_very_verbose("Initialised segtype: %s", segtype->name);
+       }
+
+       return 1;
 }
This page took 0.037832 seconds and 5 git commands to generate.