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)
This commit is contained in:
Kenneth D. Merry 2016-06-23 20:05:59 +00:00
parent cc4eb1ea10
commit a02e196edd
3 changed files with 10 additions and 17 deletions

View File

@ -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) {

View File

@ -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 */

View File

@ -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,