svn commit: r297548 - stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs
Alexander Motin
mav at FreeBSD.org
Mon Apr 4 09:49:46 UTC 2016
Author: mav
Date: Mon Apr 4 09:49:45 2016
New Revision: 297548
URL: https://svnweb.freebsd.org/changeset/base/297548
Log:
MFC r297420: Switch from using make_dev_p() to make_dev_s() to close races.
Modified:
stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c
==============================================================================
--- stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Mon Apr 4 09:48:58 2016 (r297547)
+++ stable/10/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zvol.c Mon Apr 4 09:49:45 2016 (r297548)
@@ -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, cons
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,
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;
More information about the svn-src-stable-10
mailing list