Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/dm dm: Simplify list eviction code



details:   https://anonhg.NetBSD.org/src/rev/e5a251929962
branches:  trunk
changeset: 1005411:e5a251929962
user:      tkusumi <tkusumi%NetBSD.org@localhost>
date:      Sat Dec 07 06:26:31 2019 +0000

description:
dm: Simplify list eviction code

taken-from: DragonFlyBSD

diffstat:

 sys/dev/dm/dm_pdev.c   |  16 ++++++++--------
 sys/dev/dm/dm_table.c  |  11 +++++------
 sys/dev/dm/dm_target.c |  13 ++++++-------
 3 files changed, 19 insertions(+), 21 deletions(-)

diffs (115 lines):

diff -r 9f1e82235112 -r e5a251929962 sys/dev/dm/dm_pdev.c
--- a/sys/dev/dm/dm_pdev.c      Sat Dec 07 04:55:01 2019 +0000
+++ b/sys/dev/dm/dm_pdev.c      Sat Dec 07 06:26:31 2019 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_pdev.c,v 1.16 2019/12/06 16:46:14 tkusumi Exp $      */
+/*        $NetBSD: dm_pdev.c,v 1.17 2019/12/07 06:26:31 tkusumi Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dm_pdev.c,v 1.16 2019/12/06 16:46:14 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_pdev.c,v 1.17 2019/12/07 06:26:31 tkusumi Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -188,16 +188,16 @@
 int
 dm_pdev_destroy(void)
 {
-       dm_pdev_t *dm_pdev;
+       dm_pdev_t *dmp;
 
        mutex_enter(&dm_pdev_mutex);
-       while (!SLIST_EMPTY(&dm_pdev_list)) {   /* List Deletion. */
-               dm_pdev = SLIST_FIRST(&dm_pdev_list);
 
-               SLIST_REMOVE_HEAD(&dm_pdev_list, next_pdev);
+       while ((dmp = SLIST_FIRST(&dm_pdev_list)) != NULL) {
+               SLIST_REMOVE(&dm_pdev_list, dmp, dm_pdev, next_pdev);
+               dm_pdev_rem(dmp);
+       }
+       KASSERT(SLIST_EMPTY(&dm_pdev_list));
 
-               dm_pdev_rem(dm_pdev);
-       }
        mutex_exit(&dm_pdev_mutex);
 
        mutex_destroy(&dm_pdev_mutex);
diff -r 9f1e82235112 -r e5a251929962 sys/dev/dm/dm_table.c
--- a/sys/dev/dm/dm_table.c     Sat Dec 07 04:55:01 2019 +0000
+++ b/sys/dev/dm/dm_table.c     Sat Dec 07 06:26:31 2019 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_table.c,v 1.10 2019/12/05 16:59:43 tkusumi Exp $      */
+/*        $NetBSD: dm_table.c,v 1.11 2019/12/07 06:26:31 tkusumi Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dm_table.c,v 1.10 2019/12/05 16:59:43 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_table.c,v 1.11 2019/12/07 06:26:31 tkusumi Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -160,15 +160,14 @@
 
        tbl = &head->tables[id];
 
-       while (!SLIST_EMPTY(tbl)) {     /* List Deletion. */
-               table_en = SLIST_FIRST(tbl);
+       while ((table_en = SLIST_FIRST(tbl)) != NULL) {
+               SLIST_REMOVE(tbl, table_en, dm_table_entry, next);
                if (table_en->target->destroy(table_en) == 0)
                        table_en->target_config = NULL;
 
-               SLIST_REMOVE_HEAD(tbl, next);
-
                kmem_free(table_en, sizeof(*table_en));
        }
+       KASSERT(SLIST_EMPTY(tbl));
 
        mutex_exit(&head->table_mtx);
 
diff -r 9f1e82235112 -r e5a251929962 sys/dev/dm/dm_target.c
--- a/sys/dev/dm/dm_target.c    Sat Dec 07 04:55:01 2019 +0000
+++ b/sys/dev/dm/dm_target.c    Sat Dec 07 06:26:31 2019 +0000
@@ -1,4 +1,4 @@
-/*        $NetBSD: dm_target.c,v 1.23 2019/12/06 16:11:59 tkusumi Exp $      */
+/*        $NetBSD: dm_target.c,v 1.24 2019/12/07 06:26:31 tkusumi Exp $      */
 
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dm_target.c,v 1.23 2019/12/06 16:11:59 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dm_target.c,v 1.24 2019/12/07 06:26:31 tkusumi Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -220,14 +220,13 @@
        dm_target_t *dm_target;
 
        mutex_enter(&dm_target_mutex);
-       while (TAILQ_FIRST(&dm_target_list) != NULL) {
-               dm_target = TAILQ_FIRST(&dm_target_list);
 
-               TAILQ_REMOVE(&dm_target_list, TAILQ_FIRST(&dm_target_list),
-                   dm_target_next);
-
+       while ((dm_target = TAILQ_FIRST(&dm_target_list)) != NULL) {
+               TAILQ_REMOVE(&dm_target_list, dm_target, dm_target_next);
                (void)kmem_free(dm_target, sizeof(dm_target_t));
        }
+       KASSERT(TAILQ_EMPTY(&dm_target_list));
+
        mutex_exit(&dm_target_mutex);
 
        mutex_destroy(&dm_target_mutex);



Home | Main Index | Thread Index | Old Index