sys/dev/disk/dm: Change table SLIST to TAILQ
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sat, 24 Oct 2015 13:38:30 +0000 (22:38 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Sun, 25 Oct 2015 10:26:01 +0000 (19:26 +0900)
TAILQ is more flexible and better for what it's trying to do.

sys/dev/disk/dm/device-mapper.c
sys/dev/disk/dm/dm.h
sys/dev/disk/dm/dm_ioctl.c
sys/dev/disk/dm/dm_table.c
sys/dev/disk/dm/doc/design.txt
sys/dev/disk/dm/doc/proposal-dm.txt

index 89288a4..6eb4ae1 100644 (file)
@@ -435,7 +435,7 @@ dmstrategy(struct dev_strategy_args *ap)
        /*
         * Find out what tables I want to select.
         */
-       SLIST_FOREACH(table_en, tbl, next) {
+       TAILQ_FOREACH(table_en, tbl, next) {
                /*
                 * I need need number of bytes not blocks.
                 */
@@ -521,7 +521,7 @@ dmdump(struct dev_dump_args *ap)
        /*
         * Find out what tables I want to select.
         */
-       SLIST_FOREACH(table_en, tbl, next) {
+       TAILQ_FOREACH(table_en, tbl, next) {
                /*
                 * I need need number of bytes not blocks.
                 */
index 0644680..4a5024a 100644 (file)
@@ -82,12 +82,12 @@ typedef struct dm_table_entry {
 
        struct dm_target *target;      /* Link to table target. */
        void *target_config;           /* Target specific data. */
-       SLIST_ENTRY(dm_table_entry) next;
+       TAILQ_ENTRY(dm_table_entry) next;
 
        TAILQ_HEAD(, dm_mapping) pdev_maps;
 } dm_table_entry_t;
 
-SLIST_HEAD(dm_table, dm_table_entry);
+TAILQ_HEAD(dm_table, dm_table_entry);
 
 typedef struct dm_table dm_table_t;
 
index c65c1d7..4792c10 100644 (file)
@@ -55,7 +55,7 @@
  * dm_table_get_entry. Between these to calls tables can'tbe switched
  * or destroyed.
  *
- * dm_table_head_init initialize talbe_entries SLISTS and io_cv.
+ * dm_table_head_init initialize talbe_entries TAILQS and io_cv.
  *
  * dm_table_head_destroy destroy cv.
  *
@@ -608,7 +608,7 @@ dm_table_deps_ioctl(prop_dictionary_t dm_dict)
 
        tbl = dm_table_get_entry(&dmv->table_head, table_type);
 
-       SLIST_FOREACH(table_en, tbl, next)
+       TAILQ_FOREACH(table_en, tbl, next)
                dm_table_deps(table_en, cmd_array);
 
        dm_table_release(&dmv->table_head, table_type);
@@ -661,7 +661,7 @@ int
 dm_table_load_ioctl(prop_dictionary_t dm_dict)
 {
        dm_dev_t *dmv;
-       dm_table_entry_t *table_en, *last_table;
+       dm_table_entry_t *table_en;
        dm_table_t *tbl;
        dm_target_t *target;
 
@@ -680,7 +680,6 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
        name = NULL;
        uuid = NULL;
        dmv = NULL;
-       last_table = NULL;
        str = NULL;
 
        /*
@@ -763,11 +762,7 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
                prop_dictionary_get_cstring(target_dict,
                    DM_TABLE_PARAMS, &str);
 
-               if (SLIST_EMPTY(tbl))
-                       /* insert this table to head */
-                       SLIST_INSERT_HEAD(tbl, table_en, next);
-               else
-                       SLIST_INSERT_AFTER(last_table, table_en, next);
+               TAILQ_INSERT_TAIL(tbl, table_en, next);
 
                /*
                 * Params string is different for every target,
@@ -785,7 +780,6 @@ dm_table_load_ioctl(prop_dictionary_t dm_dict)
                        dm_dev_unbusy(dmv);
                        return ret;
                }
-               last_table = table_en;
                kfree(str, M_TEMP);
        }
        prop_object_iterator_release(iter);
@@ -890,7 +884,7 @@ dm_table_status_ioctl(prop_dictionary_t dm_dict)
 
        tbl = dm_table_get_entry(&dmv->table_head, table_type);
 
-       SLIST_FOREACH(table_en, tbl, next) {
+       TAILQ_FOREACH(table_en, tbl, next) {
                target_dict = prop_dictionary_create();
                aprint_debug("%016" PRIu64 ", length %016" PRIu64
                    ", target %s\n", table_en->start, table_en->length,
@@ -975,12 +969,12 @@ dm_message_ioctl(prop_dictionary_t dm_dict)
        ret = EINVAL;
 
        if (sector == 0) {
-               if (!SLIST_EMPTY(tbl)) {
-                       table_en = SLIST_FIRST(tbl);
+               if (!TAILQ_EMPTY(tbl)) {
+                       table_en = TAILQ_FIRST(tbl);
                        found = 1;
                }
        } else {
-               SLIST_FOREACH(table_en, tbl, next) {
+               TAILQ_FOREACH(table_en, tbl, next) {
                        table_start = table_en->start;
                        table_end = table_start + table_en->length;
 
index 19be150..dae2fc4 100644 (file)
@@ -140,8 +140,8 @@ dm_table_destroy(dm_table_head_t *head, uint8_t table_id)
 
        tbl = &head->tables[id];
 
-       while ((table_en = SLIST_FIRST(tbl)) != NULL) {
-               SLIST_REMOVE(tbl, table_en, dm_table_entry, next);
+       while ((table_en = TAILQ_FIRST(tbl)) != NULL) {
+               TAILQ_REMOVE(tbl, table_en, next);
                /*
                 * Remove target specific config data. After successfull
                 * call table_en->target_config must be set to NULL.
@@ -155,7 +155,7 @@ dm_table_destroy(dm_table_head_t *head, uint8_t table_id)
 
                kfree(table_en, M_DM);
        }
-       KKASSERT(SLIST_EMPTY(tbl));
+       KKASSERT(TAILQ_EMPTY(tbl));
 
        lockmgr(&head->table_mtx, LK_RELEASE);
 
@@ -180,7 +180,7 @@ _dm_table_size(dm_table_head_t *head, int table)
         * Find out what tables I want to select.
         * if length => rawblkno then we should used that table.
         */
-       SLIST_FOREACH(table_en, tbl, next) {
+       TAILQ_FOREACH(table_en, tbl, next) {
                length += table_en->length;
        }
 
@@ -218,7 +218,7 @@ dm_table_get_target_count(dm_table_head_t *head, uint8_t table_id)
 
        tbl = dm_table_get_entry(head, table_id);
 
-       SLIST_FOREACH(table_en, tbl, next)
+       TAILQ_FOREACH(table_en, tbl, next)
            target_count++;
 
        dm_table_unbusy(head);
@@ -238,8 +238,8 @@ dm_table_head_init(dm_table_head_t *head)
        head->io_cnt = 0;
 
        /* Initialize tables. */
-       SLIST_INIT(&head->tables[0]);
-       SLIST_INIT(&head->tables[1]);
+       TAILQ_INIT(&head->tables[0]);
+       TAILQ_INIT(&head->tables[1]);
 
        lockinit(&head->table_mtx, "dmtbl", 0, LK_CANRECURSE);
 }
index 7922be5..73c4e05 100644 (file)
      Implementation:
        Kernel driver will find device with name from struct dm_ioctl-name/uuid.
        Table is added to the inactive slot. Every device can have more than one 
-       table loaded. Tables are stored in SLIST. This ioctl also open physical 
+       table loaded. Tables are stored in TAILQ. This ioctl also open physical
        device spedcified in table and add it to dm_device specific pdev list.
 
  11) DM_TABLE_CLEAR
index b9dbe89..f00c8e6 100644 (file)
@@ -18,9 +18,9 @@ struct dm_table_entry {
 
        struct dm_target *target;
        void *target_config;
-       SLIST_ENTRY(dm_table_entry) next;
+       TAILQ_ENTRY(dm_table_entry) next;
 };
-SLIST(dm_table, dm_table_entry);
+TAILQ_HEAD(dm_table, dm_table_entry);
 
 
 struct dm_pdev {