From a02e196edd4a89d7c2582312d8e77c84f215487b Mon Sep 17 00:00:00 2001 From: "Kenneth D. Merry" Date: Thu, 23 Jun 2016 20:05:59 +0000 Subject: [PATCH] Switch geom_disk over to using a pool mutex. The GEOM disk d_mtx is only acquired on disk creation and destruction. It is a good candidate for replacement with a pool mutex. This eliminates the mutex initialization and teardown and the mutex and name variables themselves from struct disk. sys/geom/geom_disk.h: Take d_mtx and d_mtx_name out of struct disk. sys/geom/geom_disk.c: Use mtx_pool_lock() and mtx_pool_unlock() to guard the disk initialization state instead of a dedicated mutex. This allows removing the initialization and destruction of d_mtx. sys/sys/param.h: Bump __FreeBSD_version to 1100119 for the change to struct disk. Suggested by: jhb Sponsored by: Spectra Logic Approved by: re (gjb) --- sys/geom/geom_disk.c | 23 +++++++++-------------- sys/geom/geom_disk.h | 2 -- sys/sys/param.h | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c index 37770f938c5..e4b1e141b54 100644 --- a/sys/geom/geom_disk.c +++ b/sys/geom/geom_disk.c @@ -670,7 +670,7 @@ g_disk_create(void *arg, int flag) g_topology_assert(); dp = arg; - mtx_lock(&dp->d_mtx); + mtx_pool_lock(mtxpool_sleep, dp); dp->d_init_level = DISK_INIT_START; /* @@ -678,12 +678,12 @@ g_disk_create(void *arg, int flag) * call the user's callback to tell him we've cleaned things up. */ if (dp->d_goneflag != 0) { - mtx_unlock(&dp->d_mtx); + mtx_pool_unlock(mtxpool_sleep, dp); if (dp->d_gone != NULL) dp->d_gone(dp); return; } - mtx_unlock(&dp->d_mtx); + mtx_pool_unlock(mtxpool_sleep, dp); sc = g_malloc(sizeof(*sc), M_WAITOK | M_ZERO); mtx_init(&sc->start_mtx, "g_disk_start", NULL, MTX_DEF); @@ -721,7 +721,7 @@ g_disk_create(void *arg, int flag) dp->d_geom = gp; g_error_provider(pp, 0); - mtx_lock(&dp->d_mtx); + mtx_pool_lock(mtxpool_sleep, dp); dp->d_init_level = DISK_INIT_DONE; /* @@ -729,11 +729,11 @@ g_disk_create(void *arg, int flag) * process for it. */ if (dp->d_goneflag != 0) { - mtx_unlock(&dp->d_mtx); + mtx_pool_unlock(mtxpool_sleep, dp); g_wither_provider(pp, ENXIO); return; } - mtx_unlock(&dp->d_mtx); + mtx_pool_unlock(mtxpool_sleep, dp); } @@ -786,8 +786,6 @@ g_disk_destroy(void *ptr, int flag) g_wither_geom(gp, ENXIO); } - mtx_destroy(&dp->d_mtx); - g_free(dp); } @@ -852,9 +850,6 @@ disk_create(struct disk *dp, int version) DEVSTAT_TYPE_DIRECT, DEVSTAT_PRIORITY_MAX); dp->d_geom = NULL; - snprintf(dp->d_mtx_name, sizeof(dp->d_mtx_name), "%s%ddlk", - dp->d_name, dp->d_unit); - mtx_init(&dp->d_mtx, dp->d_mtx_name, NULL, MTX_DEF); dp->d_init_level = DISK_INIT_NONE; g_disk_ident_adjust(dp->d_ident, sizeof(dp->d_ident)); @@ -878,7 +873,7 @@ disk_gone(struct disk *dp) struct g_geom *gp; struct g_provider *pp; - mtx_lock(&dp->d_mtx); + mtx_pool_lock(mtxpool_sleep, dp); dp->d_goneflag = 1; /* @@ -897,10 +892,10 @@ disk_gone(struct disk *dp) * has not been fully setup in any case. */ if (dp->d_init_level < DISK_INIT_DONE) { - mtx_unlock(&dp->d_mtx); + mtx_pool_unlock(mtxpool_sleep, dp); return; } - mtx_unlock(&dp->d_mtx); + mtx_pool_unlock(mtxpool_sleep, dp); gp = dp->d_geom; if (gp != NULL) { diff --git a/sys/geom/geom_disk.h b/sys/geom/geom_disk.h index 8549348faf6..5fce5b93f69 100644 --- a/sys/geom/geom_disk.h +++ b/sys/geom/geom_disk.h @@ -72,8 +72,6 @@ struct disk { struct devstat *d_devstat; int d_goneflag; int d_destroyed; - struct mtx d_mtx; - char d_mtx_name[24]; disk_init_level d_init_level; /* Shared fields */ diff --git a/sys/sys/param.h b/sys/sys/param.h index 203b6efdb9d..e254573a606 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1100118 /* Master, propagated to newvers */ +#define __FreeBSD_version 1100119 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,