From cdbba101f48bef68b46363a64880b51fa647ad45 Mon Sep 17 00:00:00 2001 From: Matthew Macy Date: Sun, 13 Oct 2019 19:19:39 -0700 Subject: [PATCH] Move zfs_onexit_fd_hold to platform code FreeBSD has a very different implementation. Reviewed-by: Ryan Moeller Reviewed-by: Brian Behlendorf Signed-off-by: Matt Macy Closes #9442 --- module/os/linux/zfs/Makefile.in | 1 + module/os/linux/zfs/zfs_onexit_os.c | 69 +++++++++++++++++++++++++++++ module/zfs/zfs_onexit.c | 33 -------------- 3 files changed, 70 insertions(+), 33 deletions(-) create mode 100644 module/os/linux/zfs/zfs_onexit_os.c diff --git a/module/os/linux/zfs/Makefile.in b/module/os/linux/zfs/Makefile.in index c7ff191db..ade6a20e9 100644 --- a/module/os/linux/zfs/Makefile.in +++ b/module/os/linux/zfs/Makefile.in @@ -24,6 +24,7 @@ $(MODULE)-objs += ../os/linux/zfs/zfs_ctldir.o $(MODULE)-objs += ../os/linux/zfs/zfs_debug.o $(MODULE)-objs += ../os/linux/zfs/zfs_dir.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_onexit_os.c b/module/os/linux/zfs/zfs_onexit_os.c new file mode 100644 index 000000000..0c33de7fe --- /dev/null +++ b/module/os/linux/zfs/zfs_onexit_os.c @@ -0,0 +1,69 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include + +/* + * 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) +{ + file_t *fp; + zfs_onexit_t *zo = NULL; + int error; + + fp = getf(fd); + if (fp == NULL) + return (SET_ERROR(EBADF)); + + error = zfsdev_getminor(fp->f_file, 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) +{ + releasef(fd); +} diff --git a/module/zfs/zfs_onexit.c b/module/zfs/zfs_onexit.c index 31f77ce81..9f1f6e4e0 100644 --- a/module/zfs/zfs_onexit.c +++ b/module/zfs/zfs_onexit.c @@ -111,39 +111,6 @@ zfs_onexit_minor_to_state(minor_t minor, zfs_onexit_t **zo) return (0); } -/* - * 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) -{ - file_t *fp; - zfs_onexit_t *zo; - int error; - - fp = getf(fd); - if (fp == NULL) - return (SET_ERROR(EBADF)); - - error = zfsdev_getminor(fp->f_file, minorp); - if (error == 0) - error = zfs_onexit_minor_to_state(*minorp, &zo); - - if (error) - zfs_onexit_fd_rele(fd); - - return (error); -} - -void -zfs_onexit_fd_rele(int fd) -{ - releasef(fd); -} - /* * Add a callback to be invoked when the calling process exits. */ -- 2.40.0