Switch from using make_dev_p() to make_dev_s() to close races.
This commit is contained in:
parent
e5185f3e2f
commit
b39dea9308
@ -589,7 +589,6 @@ zvol_create_minor(const char *name)
|
||||
minor_t minor = 0;
|
||||
char chrbuf[30], blkbuf[30];
|
||||
#else
|
||||
struct cdev *dev;
|
||||
struct g_provider *pp;
|
||||
struct g_geom *gp;
|
||||
uint64_t volsize, mode;
|
||||
@ -688,18 +687,25 @@ zvol_create_minor(const char *name)
|
||||
bioq_init(&zv->zv_queue);
|
||||
mtx_init(&zv->zv_queue_mtx, "zvol", NULL, MTX_DEF);
|
||||
} else if (zv->zv_volmode == ZFS_VOLMODE_DEV) {
|
||||
error = make_dev_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK,
|
||||
&dev, &zvol_cdevsw, NULL, UID_ROOT, GID_OPERATOR,
|
||||
0640, "%s/%s", ZVOL_DRIVER, name);
|
||||
struct make_dev_args args;
|
||||
|
||||
make_dev_args_init(&args);
|
||||
args.mda_flags = MAKEDEV_CHECKNAME | MAKEDEV_WAITOK;
|
||||
args.mda_devsw = &zvol_cdevsw;
|
||||
args.mda_cr = NULL;
|
||||
args.mda_uid = UID_ROOT;
|
||||
args.mda_gid = GID_OPERATOR;
|
||||
args.mda_mode = 0640;
|
||||
args.mda_si_drv2 = zv;
|
||||
error = make_dev_s(&args, &zv->zv_dev,
|
||||
"%s/%s", ZVOL_DRIVER, name);
|
||||
if (error != 0) {
|
||||
kmem_free(zv, sizeof(*zv));
|
||||
dmu_objset_disown(os, FTAG);
|
||||
mutex_exit(&zfsdev_state_lock);
|
||||
return (error);
|
||||
}
|
||||
zv->zv_dev = dev;
|
||||
dev->si_iosize_max = MAXPHYS;
|
||||
dev->si_drv2 = zv;
|
||||
zv->zv_dev->si_iosize_max = MAXPHYS;
|
||||
}
|
||||
LIST_INSERT_HEAD(&all_zvols, zv, zv_links);
|
||||
#endif /* illumos */
|
||||
@ -2965,18 +2971,24 @@ zvol_rename_minor(zvol_state_t *zv, const char *newname)
|
||||
g_error_provider(pp, 0);
|
||||
g_topology_unlock();
|
||||
} else if (zv->zv_volmode == ZFS_VOLMODE_DEV) {
|
||||
struct make_dev_args args;
|
||||
|
||||
dev = zv->zv_dev;
|
||||
ASSERT(dev != NULL);
|
||||
zv->zv_dev = NULL;
|
||||
destroy_dev(dev);
|
||||
|
||||
if (make_dev_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK,
|
||||
&dev, &zvol_cdevsw, NULL, UID_ROOT, GID_OPERATOR,
|
||||
0640, "%s/%s", ZVOL_DRIVER, newname) == 0) {
|
||||
zv->zv_dev = dev;
|
||||
dev->si_iosize_max = MAXPHYS;
|
||||
dev->si_drv2 = zv;
|
||||
}
|
||||
make_dev_args_init(&args);
|
||||
args.mda_flags = MAKEDEV_CHECKNAME | MAKEDEV_WAITOK;
|
||||
args.mda_devsw = &zvol_cdevsw;
|
||||
args.mda_cr = NULL;
|
||||
args.mda_uid = UID_ROOT;
|
||||
args.mda_gid = GID_OPERATOR;
|
||||
args.mda_mode = 0640;
|
||||
args.mda_si_drv2 = zv;
|
||||
if (make_dev_s(&args, &zv->zv_dev,
|
||||
"%s/%s", ZVOL_DRIVER, newname) == 0)
|
||||
zv->zv_dev->si_iosize_max = MAXPHYS;
|
||||
}
|
||||
strlcpy(zv->zv_name, newname, sizeof(zv->zv_name));
|
||||
}
|
||||
@ -3023,16 +3035,10 @@ zvol_rename_minors(const char *oldname, const char *newname)
|
||||
static int
|
||||
zvol_d_open(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
zvol_state_t *zv;
|
||||
zvol_state_t *zv = dev->si_drv2;
|
||||
int err = 0;
|
||||
|
||||
mutex_enter(&zfsdev_state_lock);
|
||||
zv = dev->si_drv2;
|
||||
if (zv == NULL) {
|
||||
mutex_exit(&zfsdev_state_lock);
|
||||
return(ENXIO); /* zvol_create_minor() not done yet */
|
||||
}
|
||||
|
||||
if (zv->zv_total_opens == 0)
|
||||
err = zvol_first_open(zv);
|
||||
if (err) {
|
||||
@ -3070,16 +3076,9 @@ zvol_d_open(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
static int
|
||||
zvol_d_close(struct cdev *dev, int flags, int fmt, struct thread *td)
|
||||
{
|
||||
zvol_state_t *zv;
|
||||
int err = 0;
|
||||
zvol_state_t *zv = dev->si_drv2;
|
||||
|
||||
mutex_enter(&zfsdev_state_lock);
|
||||
zv = dev->si_drv2;
|
||||
if (zv == NULL) {
|
||||
mutex_exit(&zfsdev_state_lock);
|
||||
return(ENXIO);
|
||||
}
|
||||
|
||||
if (zv->zv_flags & ZVOL_EXCL) {
|
||||
ASSERT(zv->zv_total_opens == 1);
|
||||
zv->zv_flags &= ~ZVOL_EXCL;
|
||||
|
Loading…
Reference in New Issue
Block a user