summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Macy <[email protected]>2020-02-28 14:50:32 -0800
committerGitHub <[email protected]>2020-02-28 14:50:32 -0800
commitae9f92f6f31c81f4d1aa4602f812f912b4392e7c (patch)
tree1d9c28079e96eb6746a53140d7c2c02e5f945b8c
parent9cdf7b1f6b00cdd0a31d07e3fbc679d0e9eff247 (diff)
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 <[email protected]> Signed-off-by: Matt Macy <[email protected]> Closes #10073
-rw-r--r--include/sys/zfs_file.h1
-rw-r--r--module/os/linux/zfs/Makefile.in1
-rw-r--r--module/os/linux/zfs/zfs_file_os.c13
-rw-r--r--module/os/linux/zfs/zfs_ioctl_os.c35
-rw-r--r--module/os/linux/zfs/zfs_onexit_os.c64
-rw-r--r--module/zfs/zfs_ioctl.c35
-rw-r--r--module/zfs/zfs_onexit.c32
7 files changed, 81 insertions, 100 deletions
diff --git a/include/sys/zfs_file.h b/include/sys/zfs_file.h
index 6b33420e3..d117933a6 100644
--- a/include/sys/zfs_file.h
+++ b/include/sys/zfs_file.h
@@ -57,5 +57,6 @@ int zfs_file_unlink(const char *);
int zfs_file_get(int fd, zfs_file_t **fp);
void zfs_file_put(int fd);
+void *zfs_file_private(zfs_file_t *fp);
#endif /* _SYS_ZFS_FILE_H */
diff --git a/module/os/linux/zfs/Makefile.in b/module/os/linux/zfs/Makefile.in
index 9f2dc699b..8c11a1ee6 100644
--- a/module/os/linux/zfs/Makefile.in
+++ b/module/os/linux/zfs/Makefile.in
@@ -25,7 +25,6 @@ $(MODULE)-objs += ../os/linux/zfs/zfs_debug.o
$(MODULE)-objs += ../os/linux/zfs/zfs_dir.o
$(MODULE)-objs += ../os/linux/zfs/zfs_file_os.o
$(MODULE)-objs += ../os/linux/zfs/zfs_ioctl_os.o
-$(MODULE)-objs += ../os/linux/zfs/zfs_onexit_os.o
$(MODULE)-objs += ../os/linux/zfs/zfs_sysfs.o
$(MODULE)-objs += ../os/linux/zfs/zfs_vfsops.o
$(MODULE)-objs += ../os/linux/zfs/zfs_vnops.o
diff --git a/module/os/linux/zfs/zfs_file_os.c b/module/os/linux/zfs/zfs_file_os.c
index 1c9b84d66..99c6ffc95 100644
--- a/module/os/linux/zfs/zfs_file_os.c
+++ b/module/os/linux/zfs/zfs_file_os.c
@@ -374,6 +374,19 @@ zfs_file_off(zfs_file_t *fp)
}
/*
+ * Request file pointer private data
+ *
+ * fp - pointer to file
+ *
+ * Returns pointer to file private data.
+ */
+void *
+zfs_file_private(zfs_file_t *fp)
+{
+ return (fp->private_data);
+}
+
+/*
* unlink file
*
* path - fully qualified file path
diff --git a/module/os/linux/zfs/zfs_ioctl_os.c b/module/os/linux/zfs/zfs_ioctl_os.c
index f31fd7ac9..acaead68f 100644
--- a/module/os/linux/zfs/zfs_ioctl_os.c
+++ b/module/os/linux/zfs/zfs_ioctl_os.c
@@ -201,41 +201,6 @@ out:
}
-int
-zfsdev_getminor(int fd, minor_t *minorp)
-{
- zfsdev_state_t *zs, *fpd;
- struct file *fp;
- int rc;
-
- ASSERT(!MUTEX_HELD(&zfsdev_state_lock));
-
- if ((rc = zfs_file_get(fd, &fp)))
- return (rc);
-
- fpd = fp->private_data;
- 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));
-}
-
void
zfs_ioctl_init_os(void)
{
diff --git a/module/os/linux/zfs/zfs_onexit_os.c b/module/os/linux/zfs/zfs_onexit_os.c
deleted file mode 100644
index 879ea28ec..000000000
--- a/module/os/linux/zfs/zfs_onexit_os.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013 by Delphix. All rights reserved.
- */
-
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/errno.h>
-#include <sys/kmem.h>
-#include <sys/sunddi.h>
-#include <sys/zfs_ioctl.h>
-#include <sys/zfs_onexit.h>
-
-/*
- * 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);
-}
diff --git a/module/zfs/zfs_ioctl.c b/module/zfs/zfs_ioctl.c
index 6f5faf357..d57aef509 100644
--- a/module/zfs/zfs_ioctl.c
+++ b/module/zfs/zfs_ioctl.c
@@ -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)
{
diff --git a/module/zfs/zfs_onexit.c b/module/zfs/zfs_onexit.c
index 9f1f6e4e0..bf86446d4 100644
--- a/module/zfs/zfs_onexit.c
+++ b/module/zfs/zfs_onexit.c
@@ -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)
{