From owner-svn-src-head@FreeBSD.ORG Wed Jul 24 09:59:16 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id C8A52EF3; Wed, 24 Jul 2013 09:59:16 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id B9F7226A2; Wed, 24 Jul 2013 09:59:16 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r6O9xGDw005671; Wed, 24 Jul 2013 09:59:16 GMT (envelope-from avg@svn.freebsd.org) Received: (from avg@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r6O9xGQe005670; Wed, 24 Jul 2013 09:59:16 GMT (envelope-from avg@svn.freebsd.org) Message-Id: <201307240959.r6O9xGQe005670@svn.freebsd.org> From: Andriy Gapon Date: Wed, 24 Jul 2013 09:59:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r253606 - head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Jul 2013 09:59:17 -0000 Author: avg Date: Wed Jul 24 09:59:16 2013 New Revision: 253606 URL: http://svnweb.freebsd.org/changeset/base/253606 Log: zfs module: perform cleanup during shutdown in addition to module unload - move init and fini code into separate functions (like it is done upstream) - invoke fini code via shutdown_post_sync event hook This should make zfs close its underlying devices during shutdown, which may be important for their drivers. MFC after: 20 days Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c ============================================================================== --- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c Wed Jul 24 09:50:44 2013 (r253605) +++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c Wed Jul 24 09:59:16 2013 (r253606) @@ -6187,54 +6187,96 @@ _info(struct modinfo *modinfop) } #endif /* sun */ -static int -zfs_modevent(module_t mod, int type, void *unused __unused) +static int zfs__init(void); +static int zfs__fini(void); +static void zfs_shutdown(void *, int); + +static eventhandler_tag zfs_shutdown_event_tag; + +int +zfs__init(void) { - int error = 0; - switch (type) { - case MOD_LOAD: - zfs_root_token = root_mount_hold("ZFS"); + zfs_root_token = root_mount_hold("ZFS"); - mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL); + mutex_init(&zfs_share_lock, NULL, MUTEX_DEFAULT, NULL); - spa_init(FREAD | FWRITE); - zfs_init(); - zvol_init(); - zfs_ioctl_init(); + spa_init(FREAD | FWRITE); + zfs_init(); + zvol_init(); + zfs_ioctl_init(); - tsd_create(&zfs_fsyncer_key, NULL); - tsd_create(&rrw_tsd_key, rrw_tsd_destroy); - tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy); + tsd_create(&zfs_fsyncer_key, NULL); + tsd_create(&rrw_tsd_key, rrw_tsd_destroy); + tsd_create(&zfs_allow_log_key, zfs_allow_log_destroy); - printf("ZFS storage pool version: features support (" SPA_VERSION_STRING ")\n"); - root_mount_rel(zfs_root_token); + printf("ZFS storage pool version: features support (" SPA_VERSION_STRING ")\n"); + root_mount_rel(zfs_root_token); - zfsdev_init(); - break; - case MOD_UNLOAD: - if (spa_busy() || zfs_busy() || zvol_busy() || - zio_injection_enabled) { - error = EBUSY; - break; - } - - zfsdev_fini(); - zvol_fini(); - zfs_fini(); - spa_fini(); - - tsd_destroy(&zfs_fsyncer_key); - tsd_destroy(&rrw_tsd_key); - tsd_destroy(&zfs_allow_log_key); + zfsdev_init(); - mutex_destroy(&zfs_share_lock); - break; + return (0); +} + +int +zfs__fini(void) +{ + if (spa_busy() || zfs_busy() || zvol_busy() || + zio_injection_enabled) { + return (EBUSY); + } + + zfsdev_fini(); + zvol_fini(); + zfs_fini(); + spa_fini(); + + tsd_destroy(&zfs_fsyncer_key); + tsd_destroy(&rrw_tsd_key); + tsd_destroy(&zfs_allow_log_key); + + mutex_destroy(&zfs_share_lock); + + return (0); +} + +static void +zfs_shutdown(void *arg __unused, int howto __unused) +{ + + /* + * ZFS fini routines can not properly work in a panic-ed system. + */ + if (panicstr == NULL) + (void)zfs__fini(); +} + + +static int +zfs_modevent(module_t mod, int type, void *unused __unused) +{ + int err; + + switch (type) { + case MOD_LOAD: + err = zfs__init(); + if (err == 0) + zfs_shutdown_event_tag = EVENTHANDLER_REGISTER( + shutdown_post_sync, zfs_shutdown, NULL, + SHUTDOWN_PRI_FIRST); + return (err); + case MOD_UNLOAD: + err = zfs__fini(); + if (err == 0 && zfs_shutdown_event_tag != NULL) + EVENTHANDLER_DEREGISTER(shutdown_post_sync, + zfs_shutdown_event_tag); + return (err); + case MOD_SHUTDOWN: + return (0); default: - error = EOPNOTSUPP; break; } - return (error); + return (EOPNOTSUPP); } static moduledata_t zfs_mod = {