mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
Move zfsdev_state_{init,destroy} to common code
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ryan Moeller <freqlabs@FreeBSD.org> Closes #11833
This commit is contained in:
committed by
Brian Behlendorf
parent
1dff545278
commit
a631283b74
@@ -87,69 +87,20 @@ zfs_vfs_rele(zfsvfs_t *zfsvfs)
|
||||
deactivate_super(zfsvfs->z_sb);
|
||||
}
|
||||
|
||||
static int
|
||||
zfsdev_state_init(struct file *filp)
|
||||
void
|
||||
zfsdev_private_set_state(void *priv, zfsdev_state_t *zs)
|
||||
{
|
||||
zfsdev_state_t *zs, *zsprev = NULL;
|
||||
minor_t minor;
|
||||
boolean_t newzs = B_FALSE;
|
||||
|
||||
ASSERT(MUTEX_HELD(&zfsdev_state_lock));
|
||||
|
||||
minor = zfsdev_minor_alloc();
|
||||
if (minor == 0)
|
||||
return (SET_ERROR(ENXIO));
|
||||
|
||||
for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
|
||||
if (zs->zs_minor == -1)
|
||||
break;
|
||||
zsprev = zs;
|
||||
}
|
||||
|
||||
if (!zs) {
|
||||
zs = kmem_zalloc(sizeof (zfsdev_state_t), KM_SLEEP);
|
||||
newzs = B_TRUE;
|
||||
}
|
||||
struct file *filp = priv;
|
||||
|
||||
filp->private_data = zs;
|
||||
|
||||
zfs_onexit_init((zfs_onexit_t **)&zs->zs_onexit);
|
||||
zfs_zevent_init((zfs_zevent_t **)&zs->zs_zevent);
|
||||
|
||||
/*
|
||||
* In order to provide for lock-free concurrent read access
|
||||
* to the minor list in zfsdev_get_state(), new entries
|
||||
* must be completely written before linking them into the
|
||||
* list whereas existing entries are already linked; the last
|
||||
* operation must be updating zs_minor (from -1 to the new
|
||||
* value).
|
||||
*/
|
||||
if (newzs) {
|
||||
zs->zs_minor = minor;
|
||||
smp_wmb();
|
||||
zsprev->zs_next = zs;
|
||||
} else {
|
||||
smp_wmb();
|
||||
zs->zs_minor = minor;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
zfsdev_state_destroy(struct file *filp)
|
||||
zfsdev_state_t *
|
||||
zfsdev_private_get_state(void *priv)
|
||||
{
|
||||
zfsdev_state_t *zs = filp->private_data;
|
||||
struct file *filp = priv;
|
||||
|
||||
ASSERT(zs != NULL);
|
||||
ASSERT3S(zs->zs_minor, >, 0);
|
||||
|
||||
zfs_onexit_destroy(zs->zs_onexit);
|
||||
zfs_zevent_destroy(zs->zs_zevent);
|
||||
zs->zs_onexit = NULL;
|
||||
zs->zs_zevent = NULL;
|
||||
membar_producer();
|
||||
zs->zs_minor = -1;
|
||||
return (filp->private_data);
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
Reference in New Issue
Block a user