diff options
author | mav <mav@FreeBSD.org> | 2016-04-04 09:49:45 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2016-04-04 09:49:45 +0000 |
commit | 2bf9d9f9112abee39df3ec7690c3774fe5c22965 (patch) | |
tree | f734437f64c45ab5c45f89616a7a17b9a9bab317 /sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c | |
parent | 2eb569b3860d22a7311a972388eda6d51981961f (diff) | |
download | FreeBSD-src-2bf9d9f9112abee39df3ec7690c3774fe5c22965.zip FreeBSD-src-2bf9d9f9112abee39df3ec7690c3774fe5c22965.tar.gz |
MFC r297420: Switch from using make_dev_p() to make_dev_s() to close races.
Diffstat (limited to 'sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c')
-rw-r--r-- | sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c index df8a9a4..b9bf457 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c @@ -587,7 +587,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; @@ -686,18 +685,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 */ @@ -2952,18 +2958,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)); } @@ -3010,16 +3022,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) { @@ -3057,16 +3063,9 @@ out: 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; |