mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Re-share zfsdev_getminor and zfs_onexit_fd_hold
By adding a zfs_file_private accessor to the common interfaces and some extensions to FreeBSD platform code it is now possible to share the implementations for the aforementioned functions. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Matt Macy <mmacy@FreeBSD.org> Closes #10073
This commit is contained in:
@@ -7154,6 +7154,41 @@ pool_status_check(const char *name, zfs_ioc_namecheck_t type,
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
zfsdev_getminor(int fd, minor_t *minorp)
|
||||
{
|
||||
zfsdev_state_t *zs, *fpd;
|
||||
zfs_file_t *fp;
|
||||
int rc;
|
||||
|
||||
ASSERT(!MUTEX_HELD(&zfsdev_state_lock));
|
||||
|
||||
if ((rc = zfs_file_get(fd, &fp)))
|
||||
return (rc);
|
||||
|
||||
fpd = zfs_file_private(fp);
|
||||
if (fpd == NULL)
|
||||
return (SET_ERROR(EBADF));
|
||||
|
||||
mutex_enter(&zfsdev_state_lock);
|
||||
|
||||
for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
|
||||
|
||||
if (zs->zs_minor == -1)
|
||||
continue;
|
||||
|
||||
if (fpd == zs) {
|
||||
*minorp = fpd->zs_minor;
|
||||
mutex_exit(&zfsdev_state_lock);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
mutex_exit(&zfsdev_state_lock);
|
||||
|
||||
return (SET_ERROR(EBADF));
|
||||
}
|
||||
|
||||
static void *
|
||||
zfsdev_get_state_impl(minor_t minor, enum zfsdev_state_type which)
|
||||
{
|
||||
|
||||
@@ -101,6 +101,38 @@ zfs_onexit_destroy(zfs_onexit_t *zo)
|
||||
kmem_free(zo, sizeof (zfs_onexit_t));
|
||||
}
|
||||
|
||||
/*
|
||||
* Consumers might need to operate by minor number instead of fd, since
|
||||
* they might be running in another thread (e.g. txg_sync_thread). Callers
|
||||
* of this function must call zfs_onexit_fd_rele() when they're finished
|
||||
* using the minor number.
|
||||
*/
|
||||
int
|
||||
zfs_onexit_fd_hold(int fd, minor_t *minorp)
|
||||
{
|
||||
zfs_onexit_t *zo = NULL;
|
||||
int error;
|
||||
|
||||
error = zfsdev_getminor(fd, minorp);
|
||||
if (error) {
|
||||
zfs_onexit_fd_rele(fd);
|
||||
return (error);
|
||||
}
|
||||
|
||||
zo = zfsdev_get_state(*minorp, ZST_ONEXIT);
|
||||
if (zo == NULL) {
|
||||
zfs_onexit_fd_rele(fd);
|
||||
return (SET_ERROR(EBADF));
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
zfs_onexit_fd_rele(int fd)
|
||||
{
|
||||
zfs_file_put(fd);
|
||||
}
|
||||
|
||||
static int
|
||||
zfs_onexit_minor_to_state(minor_t minor, zfs_onexit_t **zo)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user