xref: /onnv-gate/usr/src/uts/common/fs/smbsrv/smb_server.c (revision 10717:fe0545fc3cdd)
16139Sjb150015 /*
26139Sjb150015  * CDDL HEADER START
36139Sjb150015  *
46139Sjb150015  * The contents of this file are subject to the terms of the
56139Sjb150015  * Common Development and Distribution License (the "License").
66139Sjb150015  * You may not use this file except in compliance with the License.
76139Sjb150015  *
86139Sjb150015  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96139Sjb150015  * or http://www.opensolaris.org/os/licensing.
106139Sjb150015  * See the License for the specific language governing permissions
116139Sjb150015  * and limitations under the License.
126139Sjb150015  *
136139Sjb150015  * When distributing Covered Code, include this CDDL HEADER in each
146139Sjb150015  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156139Sjb150015  * If applicable, add the following below this CDDL HEADER, with the
166139Sjb150015  * fields enclosed by brackets "[]" replaced with your own identifying
176139Sjb150015  * information: Portions Copyright [yyyy] [name of copyright owner]
186139Sjb150015  *
196139Sjb150015  * CDDL HEADER END
206139Sjb150015  */
216139Sjb150015 /*
228670SJose.Borrego@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
236139Sjb150015  * Use is subject to license terms.
246139Sjb150015  */
256139Sjb150015 
266139Sjb150015 /*
276139Sjb150015  * General Structures Layout
286139Sjb150015  * -------------------------
296139Sjb150015  *
306139Sjb150015  * This is a simplified diagram showing the relationship between most of the
316139Sjb150015  * main structures.
326139Sjb150015  *
336139Sjb150015  * +-------------------+
346139Sjb150015  * |     SMB_SERVER    |
356139Sjb150015  * +-------------------+
366139Sjb150015  *          |
376139Sjb150015  *          |
386139Sjb150015  *          v
396139Sjb150015  * +-------------------+       +-------------------+      +-------------------+
406139Sjb150015  * |     SESSION       |<----->|     SESSION       |......|      SESSION      |
416139Sjb150015  * +-------------------+       +-------------------+      +-------------------+
426139Sjb150015  *          |
436139Sjb150015  *          |
446139Sjb150015  *          v
456139Sjb150015  * +-------------------+       +-------------------+      +-------------------+
466139Sjb150015  * |       USER        |<----->|       USER        |......|       USER        |
476139Sjb150015  * +-------------------+       +-------------------+      +-------------------+
486139Sjb150015  *          |
496139Sjb150015  *          |
506139Sjb150015  *          v
516139Sjb150015  * +-------------------+       +-------------------+      +-------------------+
526139Sjb150015  * |       TREE        |<----->|       TREE        |......|       TREE        |
536139Sjb150015  * +-------------------+       +-------------------+      +-------------------+
546139Sjb150015  *      |         |
556139Sjb150015  *      |         |
566139Sjb150015  *      |         v
576139Sjb150015  *      |     +-------+       +-------+      +-------+
586139Sjb150015  *      |     | OFILE |<----->| OFILE |......| OFILE |
596139Sjb150015  *      |     +-------+       +-------+      +-------+
606139Sjb150015  *      |
616139Sjb150015  *      |
626139Sjb150015  *      v
636139Sjb150015  *  +-------+       +------+      +------+
646139Sjb150015  *  | ODIR  |<----->| ODIR |......| ODIR |
656139Sjb150015  *  +-------+       +------+      +------+
666139Sjb150015  *
676139Sjb150015  *
686139Sjb150015  * Module Interface Overview
696139Sjb150015  * -------------------------
706139Sjb150015  *
716139Sjb150015  *
726139Sjb150015  *	    +===================================+
736139Sjb150015  *	    |		 smbd daemon		|
746139Sjb150015  *	    +===================================+
756139Sjb150015  *	      |		     |		      ^
766139Sjb150015  *	      |		     |		      |
776139Sjb150015  * User	      |		     |		      |
786139Sjb150015  * -----------|--------------|----------------|--------------------------------
796139Sjb150015  * Kernel     |		     |		      |
806139Sjb150015  *            |		     |		      |
816139Sjb150015  *	      |		     |		      |
826139Sjb150015  *  +=========|==============|================|=================+
836139Sjb150015  *  |	      v		     v		      |			|
846139Sjb150015  *  | +-----------+ +--------------------+ +------------------+ |
856139Sjb150015  *  | |     IO    | | Kernel Door Server | | User Door Servers|	|
866139Sjb150015  *  | | Interface | |     Interface      | |   Interface      | |
876139Sjb150015  *  | +-----------+ +--------------------+ +------------------+ |
886139Sjb150015  *  |		|	     |		      ^		^	|
896139Sjb150015  *  |		v	     v		      |		|	|    +=========+
906139Sjb150015  *  |	     +-----------------------------------+	|	|    |	       |
916139Sjb150015  *  |	     + SMB Server Management (this file) |<------------------|	 ZFS   |
926139Sjb150015  *  |	     +-----------------------------------+	|	|    |	       |
936139Sjb150015  *  |							|	|    |  Module |
946139Sjb150015  *  |	     +-----------------------------------+	|	|    |	       |
956139Sjb150015  *  |	     +     SMB Server Internal Layers    |------+	|    +=========+
966139Sjb150015  *  |	     +-----------------------------------+		|
976139Sjb150015  *  |								|
986139Sjb150015  *  |								|
996139Sjb150015  *  +===========================================================+
1006139Sjb150015  *
1016139Sjb150015  *
1026139Sjb150015  * Server State Machine
1036139Sjb150015  * --------------------
1046139Sjb150015  *                                  |
1056139Sjb150015  *                                  | T0
1066139Sjb150015  *                                  |
1076139Sjb150015  *                                  v
1086139Sjb150015  *                    +-----------------------------+
1096139Sjb150015  *		      |   SMB_SERVER_STATE_CREATED  |
1106139Sjb150015  *		      +-----------------------------+
1116139Sjb150015  *				    |
1126139Sjb150015  *				    | T1
1136139Sjb150015  *				    |
1146139Sjb150015  *				    v
1156139Sjb150015  *		      +-----------------------------+
1166139Sjb150015  *		      | SMB_SERVER_STATE_CONFIGURED |
1176139Sjb150015  *		      +-----------------------------+
1186139Sjb150015  *				    |
1196139Sjb150015  *				    | T2
1206139Sjb150015  *				    |
1216139Sjb150015  *				    v
1226139Sjb150015  *		      +-----------------------------+
1236139Sjb150015  *		      |  SMB_SERVER_STATE_RUNNING   |
1246139Sjb150015  *		      +-----------------------------+
1256139Sjb150015  *				    |
1266139Sjb150015  *				    | T3
1276139Sjb150015  *				    |
1286139Sjb150015  *				    v
1296139Sjb150015  *		      +-----------------------------+
1306139Sjb150015  *		      |  SMB_SERVER_STATE_DELETING  |
1316139Sjb150015  *                    +-----------------------------+
1326139Sjb150015  *				    |
1336139Sjb150015  *				    |
1346139Sjb150015  *				    |
1356139Sjb150015  *				    v
1366139Sjb150015  *
1376139Sjb150015  * States
1386139Sjb150015  * ------
1396139Sjb150015  *
1406139Sjb150015  * SMB_SERVER_STATE_CREATED
1416139Sjb150015  *
1426139Sjb150015  *    This is the state of the server just after creation.
1436139Sjb150015  *
1446139Sjb150015  * SMB_SERVER_STATE_CONFIGURED
1456139Sjb150015  *
1466139Sjb150015  *    The server has been configured.
1476139Sjb150015  *
1486139Sjb150015  * SMB_SERVER_STATE_RUNNING
1496139Sjb150015  *
1506139Sjb150015  *    The server has been started. While in this state the threads listening on
1516139Sjb150015  *    the sockets car be started. The smbd daemon does so through an Ioctl:
1526139Sjb150015  *
1536139Sjb150015  *	smb_drv_ioctl(SMB_IOC_NBT_LISTEN) --> smb_server_nbt_listen()
1546139Sjb150015  *	smb_drv_ioctl(SMB_IOC_TCP_LISTEN) --> smb_server_nbt_listen()
1556139Sjb150015  *
1566139Sjb150015  *    When a client establishes a connection the thread listening leaves
1576139Sjb150015  *    temporarily the kernel. While in user space it creates a thread for the
1586139Sjb150015  *    new session. It then returns to kernel with the result of the thread
1596139Sjb150015  *    creation. If the creation failed the new session context is destroyed
1606139Sjb150015  *    before returning listening.
1616139Sjb150015  *
1626139Sjb150015  *    The new created thread enters the kernel though an Ioctl:
1636139Sjb150015  *
1646139Sjb150015  *	smb_drv_ioctl(SMB_IOC_NBT_RECEIVE) --> smb_server_nbt_receive()
1656139Sjb150015  *	smb_drv_ioctl(SMB_IOC_TCP_RECEIVE) --> smb_server_tcp_receive()
1666139Sjb150015  *
1676139Sjb150015  * SMB_SERVER_STATE_STOPPING
1686139Sjb150015  *
1696139Sjb150015  *    The threads listening on the NBT and TCP sockets are being terminated.
1706139Sjb150015  *
1716139Sjb150015  *
1726139Sjb150015  * Transitions
1736139Sjb150015  * -----------
1746139Sjb150015  *
1756139Sjb150015  * Transition T0
1766139Sjb150015  *
1776139Sjb150015  *    The daemon smbd triggers its creation by opening the smbsrv device. If
1786139Sjb150015  *    the zone where the daemon lives doesn't have an smb server yet it is
1796139Sjb150015  *    created.
1806139Sjb150015  *
1816139Sjb150015  *		smb_drv_open() --> smb_server_create()
1826139Sjb150015  *
1836139Sjb150015  * Transition T1
1846139Sjb150015  *
1856139Sjb150015  *    This transition occurs in smb_server_configure(). It is triggered by the
1866139Sjb150015  *    daemon through an Ioctl.
1876139Sjb150015  *
1886139Sjb150015  *	smb_drv_ioctl(SMB_IOC_CONFIG) --> smb_server_configure()
1896139Sjb150015  *
1906139Sjb150015  * Transition T2
1916139Sjb150015  *
1926139Sjb150015  *    This transition occurs in smb_server_start(). It is triggered by the
1936139Sjb150015  *    daemon through an Ioctl.
1946139Sjb150015  *
1956139Sjb150015  *	smb_drv_ioctl(SMB_IOC_START) --> smb_server_start()
1966139Sjb150015  *
1976139Sjb150015  * Transition T3
1986139Sjb150015  *
1996139Sjb150015  *    This transition occurs in smb_server_delete(). It is triggered by the
2006139Sjb150015  *    daemon when closing the smbsrv device
2016139Sjb150015  *
2026139Sjb150015  *		smb_drv_close() --> smb_server_delete()
2036139Sjb150015  *
2046139Sjb150015  * Comments
2056139Sjb150015  * --------
2066139Sjb150015  *
2076139Sjb150015  * This files assumes that there will one SMB server per zone. For now the
2086139Sjb150015  * smb server works only in global zone. There's nothing in this file preventing
2096139Sjb150015  * an smb server from being created in a non global zone. That limitation is
2106139Sjb150015  * enforced in user space.
2116139Sjb150015  */
2126139Sjb150015 
2136139Sjb150015 #include <sys/strsubr.h>
2146139Sjb150015 #include <sys/cmn_err.h>
2156139Sjb150015 #include <sys/priv.h>
2166139Sjb150015 #include <sys/socketvar.h>
2176139Sjb150015 #include <sys/zone.h>
2186139Sjb150015 #include <smbsrv/smb_kproto.h>
2196139Sjb150015 #include <smbsrv/netbios.h>
2206139Sjb150015 #include <smbsrv/smb_incl.h>
2216139Sjb150015 #include <smbsrv/cifs.h>
2226139Sjb150015 #include <smbsrv/smb_fsops.h>
2237052Samw #include <smbsrv/smb_share.h>
2246139Sjb150015 #include <smbsrv/smb_door_svc.h>
2256432Sas200622 #include <smbsrv/smb_kstat.h>
2266139Sjb150015 
2276139Sjb150015 extern void smb_dispatch_kstat_init(void);
2286139Sjb150015 extern void smb_dispatch_kstat_fini(void);
2296139Sjb150015 extern void smb_reply_notify_change_request(smb_request_t *);
2306139Sjb150015 
2316139Sjb150015 static int smb_server_kstat_init(smb_server_t *);
2326139Sjb150015 static void smb_server_kstat_fini(smb_server_t *);
2336139Sjb150015 static int smb_server_kstat_update_info(kstat_t *, int);
2346139Sjb150015 static void smb_server_timers(smb_thread_t *, void *);
2356139Sjb150015 static int smb_server_listen(smb_server_t *, smb_listener_daemon_t *,
2368670SJose.Borrego@Sun.COM     in_port_t, int, int);
2376139Sjb150015 static int smb_server_lookup(smb_server_t **);
2386139Sjb150015 static void smb_server_release(smb_server_t *);
2399832Samw@Sun.COM static void smb_server_store_cfg(smb_server_t *, smb_ioc_cfg_t *);
2406139Sjb150015 static void smb_server_stop(smb_server_t *);
2416139Sjb150015 static int smb_server_fsop_start(smb_server_t *);
2426139Sjb150015 static void smb_server_fsop_stop(smb_server_t *);
2436139Sjb150015 
2447619SJose.Borrego@Sun.COM static void smb_server_disconnect_share(char *, smb_server_t *);
2457619SJose.Borrego@Sun.COM static void smb_server_thread_unexport(smb_thread_t *, void *);
2467619SJose.Borrego@Sun.COM 
24710122SJordan.Brown@Sun.COM static void smb_server_enum_private(smb_session_list_t *, smb_svcenum_t *);
24810122SJordan.Brown@Sun.COM static int smb_server_sesion_disconnect(smb_session_list_t *, const char *,
24910122SJordan.Brown@Sun.COM     const char *);
25010122SJordan.Brown@Sun.COM static int smb_server_fclose(smb_session_list_t *, uint32_t);
25110122SJordan.Brown@Sun.COM 
2526139Sjb150015 static smb_llist_t	smb_servers;
2536139Sjb150015 
2546139Sjb150015 /*
2556139Sjb150015  * *****************************************************************************
2566139Sjb150015  * **************** Functions called from the device interface *****************
2576139Sjb150015  * *****************************************************************************
2586139Sjb150015  *
25910122SJordan.Brown@Sun.COM  * These functions typically have to determine the relevant smb server
26010122SJordan.Brown@Sun.COM  * to which the call applies.
2616139Sjb150015  */
2626139Sjb150015 
2636139Sjb150015 /*
2646139Sjb150015  * smb_server_svc_init
2656139Sjb150015  *
2667348SJose.Borrego@Sun.COM  * This function must be called from smb_drv_attach().
2676139Sjb150015  */
2686139Sjb150015 int
2696139Sjb150015 smb_server_svc_init(void)
2706139Sjb150015 {
2716139Sjb150015 	int	rc = 0;
2726139Sjb150015 
2736139Sjb150015 	while (rc == 0) {
2748934SJose.Borrego@Sun.COM 		if (rc = smb_mbc_init())
2758934SJose.Borrego@Sun.COM 			continue;
2766139Sjb150015 		if (rc = smb_vop_init())
2776139Sjb150015 			continue;
2786139Sjb150015 		if (rc = smb_node_init())
2796496Sjb150015 			continue;
2806139Sjb150015 		if (rc = smb_fem_init())
2816496Sjb150015 			continue;
2827348SJose.Borrego@Sun.COM 		if (rc = smb_user_init())
2837348SJose.Borrego@Sun.COM 			continue;
2846139Sjb150015 		if (rc = smb_notify_init())
2856496Sjb150015 			continue;
2866496Sjb150015 		if (rc = smb_net_init())
2876496Sjb150015 			continue;
2886139Sjb150015 		smb_llist_constructor(&smb_servers, sizeof (smb_server_t),
2896139Sjb150015 		    offsetof(smb_server_t, sv_lnd));
2906139Sjb150015 		return (0);
2916139Sjb150015 	}
2926496Sjb150015 	smb_net_fini();
2936139Sjb150015 	smb_notify_fini();
2947348SJose.Borrego@Sun.COM 	smb_user_fini();
2956139Sjb150015 	smb_fem_fini();
2966139Sjb150015 	smb_node_fini();
2976139Sjb150015 	smb_vop_fini();
2988934SJose.Borrego@Sun.COM 	smb_mbc_fini();
2996139Sjb150015 	return (rc);
3006139Sjb150015 }
3016139Sjb150015 
3026139Sjb150015 /*
3036139Sjb150015  * smb_server_svc_fini
3046139Sjb150015  *
3056139Sjb150015  * This function must called from smb_drv_detach(). It will fail if servers
3066139Sjb150015  * still exist.
3076139Sjb150015  */
3086139Sjb150015 int
3096139Sjb150015 smb_server_svc_fini(void)
3106139Sjb150015 {
3116139Sjb150015 	int	rc = EBUSY;
3126139Sjb150015 
3136139Sjb150015 	if (smb_llist_get_count(&smb_servers) == 0) {
3146496Sjb150015 		smb_net_fini();
3156139Sjb150015 		smb_notify_fini();
3167348SJose.Borrego@Sun.COM 		smb_user_fini();
3176139Sjb150015 		smb_fem_fini();
3186139Sjb150015 		smb_node_fini();
3196139Sjb150015 		smb_vop_fini();
3208934SJose.Borrego@Sun.COM 		smb_mbc_fini();
3216139Sjb150015 		smb_llist_destructor(&smb_servers);
3226139Sjb150015 		rc = 0;
3236139Sjb150015 	}
3246139Sjb150015 	return (rc);
3256139Sjb150015 }
3266139Sjb150015 
3276139Sjb150015 /*
3286139Sjb150015  * smb_server_create
3296139Sjb150015  *
3306139Sjb150015  * This function will fail if there's already a server associated with the
3316139Sjb150015  * caller's zone.
3326139Sjb150015  */
3336139Sjb150015 int
3346139Sjb150015 smb_server_create(void)
3356139Sjb150015 {
3366139Sjb150015 	zoneid_t	zid;
3376139Sjb150015 	smb_server_t	*sv;
3386139Sjb150015 
3396139Sjb150015 	zid = getzoneid();
3406139Sjb150015 
3416139Sjb150015 	smb_llist_enter(&smb_servers, RW_WRITER);
3426139Sjb150015 	sv = smb_llist_head(&smb_servers);
3436139Sjb150015 	while (sv) {
3446139Sjb150015 		ASSERT(sv->sv_magic == SMB_SERVER_MAGIC);
3456139Sjb150015 		if (sv->sv_zid == zid) {
3466139Sjb150015 			smb_llist_exit(&smb_servers);
3478167Samw@Sun.COM 			return (EPERM);
3486139Sjb150015 		}
3496139Sjb150015 		sv = smb_llist_next(&smb_servers, sv);
3506139Sjb150015 	}
3516139Sjb150015 
3526139Sjb150015 	sv = kmem_zalloc(sizeof (smb_server_t), KM_NOSLEEP);
3536139Sjb150015 	if (sv == NULL) {
3546139Sjb150015 		smb_llist_exit(&smb_servers);
3556139Sjb150015 		return (ENOMEM);
3566139Sjb150015 	}
3576139Sjb150015 
3586139Sjb150015 	smb_llist_constructor(&sv->sv_vfs_list, sizeof (smb_vfs_t),
3596139Sjb150015 	    offsetof(smb_vfs_t, sv_lnd));
3606139Sjb150015 
3617619SJose.Borrego@Sun.COM 	smb_slist_constructor(&sv->sv_unexport_list, sizeof (smb_unexport_t),
3627619SJose.Borrego@Sun.COM 	    offsetof(smb_unexport_t, ux_lnd));
3637619SJose.Borrego@Sun.COM 
3646139Sjb150015 	smb_session_list_constructor(&sv->sv_nbt_daemon.ld_session_list);
3656139Sjb150015 	smb_session_list_constructor(&sv->sv_tcp_daemon.ld_session_list);
3666139Sjb150015 
3677619SJose.Borrego@Sun.COM 	sv->si_cache_unexport = kmem_cache_create("smb_unexport_cache",
3687619SJose.Borrego@Sun.COM 	    sizeof (smb_unexport_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3696139Sjb150015 	sv->si_cache_vfs = kmem_cache_create("smb_vfs_cache",
3706139Sjb150015 	    sizeof (smb_vfs_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3716139Sjb150015 	sv->si_cache_request = kmem_cache_create("smb_request_cache",
3726139Sjb150015 	    sizeof (smb_request_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3736139Sjb150015 	sv->si_cache_session = kmem_cache_create("smb_session_cache",
3746139Sjb150015 	    sizeof (smb_session_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3756139Sjb150015 	sv->si_cache_user = kmem_cache_create("smb_user_cache",
3766139Sjb150015 	    sizeof (smb_user_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3776139Sjb150015 	sv->si_cache_tree = kmem_cache_create("smb_tree_cache",
3786139Sjb150015 	    sizeof (smb_tree_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3796139Sjb150015 	sv->si_cache_ofile = kmem_cache_create("smb_ofile_cache",
3806139Sjb150015 	    sizeof (smb_ofile_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3816139Sjb150015 	sv->si_cache_odir = kmem_cache_create("smb_odir_cache",
3826139Sjb150015 	    sizeof (smb_odir_t), 8, NULL, NULL, NULL, NULL, NULL, 0);
3836139Sjb150015 
3846139Sjb150015 	smb_thread_init(&sv->si_thread_timers,
3856139Sjb150015 	    "smb_timers", smb_server_timers, sv,
3866139Sjb150015 	    NULL, NULL);
3876139Sjb150015 
3887619SJose.Borrego@Sun.COM 	smb_thread_init(&sv->si_thread_unexport, "smb_thread_unexport",
3897619SJose.Borrego@Sun.COM 	    smb_server_thread_unexport, sv, NULL, NULL);
3907619SJose.Borrego@Sun.COM 
3916432Sas200622 	sv->sv_pid = curproc->p_pid;
3926139Sjb150015 
3937588Samw@Sun.COM 	smb_kdoor_clnt_init();
3947052Samw 	smb_opipe_door_init();
3956139Sjb150015 	(void) smb_server_kstat_init(sv);
3966139Sjb150015 
3976139Sjb150015 	mutex_init(&sv->sv_mutex, NULL, MUTEX_DEFAULT, NULL);
3986139Sjb150015 	cv_init(&sv->sv_cv, NULL, CV_DEFAULT, NULL);
3996139Sjb150015 	sv->sv_state = SMB_SERVER_STATE_CREATED;
4006139Sjb150015 	sv->sv_magic = SMB_SERVER_MAGIC;
4016139Sjb150015 	sv->sv_zid = zid;
4026139Sjb150015 
4036139Sjb150015 	smb_llist_insert_tail(&smb_servers, sv);
4046139Sjb150015 	smb_llist_exit(&smb_servers);
4056139Sjb150015 	return (0);
4066139Sjb150015 }
4076139Sjb150015 
4086139Sjb150015 /*
4096139Sjb150015  * smb_server_delete
4106139Sjb150015  *
4116139Sjb150015  * This function will delete the server passed in. It will make sure that all
4126139Sjb150015  * activity associated that server has ceased before destroying it.
4136139Sjb150015  */
4146139Sjb150015 int
4156139Sjb150015 smb_server_delete(void)
4166139Sjb150015 {
4176139Sjb150015 	smb_server_t	*sv;
4187619SJose.Borrego@Sun.COM 	smb_unexport_t	*ux;
4196139Sjb150015 	int		rc;
4206139Sjb150015 
4216139Sjb150015 	rc = smb_server_lookup(&sv);
4226139Sjb150015 	if (rc != 0)
4236139Sjb150015 		return (rc);
4246139Sjb150015 
4256139Sjb150015 	mutex_enter(&sv->sv_mutex);
4266139Sjb150015 	switch (sv->sv_state) {
4276139Sjb150015 	case SMB_SERVER_STATE_RUNNING:
4286139Sjb150015 	{
4296139Sjb150015 		boolean_t	nbt = B_FALSE;
4306139Sjb150015 		boolean_t	tcp = B_FALSE;
4316139Sjb150015 
4326139Sjb150015 		if (sv->sv_nbt_daemon.ld_kth) {
4336139Sjb150015 			tsignal(sv->sv_nbt_daemon.ld_kth, SIGINT);
4346139Sjb150015 			nbt = B_TRUE;
4356139Sjb150015 		}
4366139Sjb150015 		if (sv->sv_tcp_daemon.ld_kth) {
4376139Sjb150015 			tsignal(sv->sv_tcp_daemon.ld_kth, SIGINT);
4386139Sjb150015 			tcp = B_TRUE;
4396139Sjb150015 		}
4406139Sjb150015 		sv->sv_state = SMB_SERVER_STATE_DELETING;
4416139Sjb150015 		mutex_exit(&sv->sv_mutex);
4426139Sjb150015 		if (nbt)
4436139Sjb150015 			thread_join(sv->sv_nbt_daemon.ld_ktdid);
4446139Sjb150015 		if (tcp)
4456139Sjb150015 			thread_join(sv->sv_tcp_daemon.ld_ktdid);
4466139Sjb150015 		mutex_enter(&sv->sv_mutex);
4476139Sjb150015 		break;
4486139Sjb150015 	}
4496139Sjb150015 	case SMB_SERVER_STATE_CONFIGURED:
4506139Sjb150015 	case SMB_SERVER_STATE_CREATED:
4516139Sjb150015 		sv->sv_state = SMB_SERVER_STATE_DELETING;
4526139Sjb150015 		break;
4536139Sjb150015 	default:
4546139Sjb150015 		ASSERT(sv->sv_state == SMB_SERVER_STATE_DELETING);
4556139Sjb150015 		mutex_exit(&sv->sv_mutex);
4566139Sjb150015 		smb_server_release(sv);
4576139Sjb150015 		return (ENOTTY);
4586139Sjb150015 	}
4596139Sjb150015 
4606139Sjb150015 	ASSERT(sv->sv_state == SMB_SERVER_STATE_DELETING);
4616139Sjb150015 
4626139Sjb150015 	sv->sv_refcnt--;
4636139Sjb150015 	while (sv->sv_refcnt)
4646139Sjb150015 		cv_wait(&sv->sv_cv, &sv->sv_mutex);
4656139Sjb150015 
4666139Sjb150015 	mutex_exit(&sv->sv_mutex);
4676139Sjb150015 
4686139Sjb150015 	smb_llist_enter(&smb_servers, RW_WRITER);
4696139Sjb150015 	smb_llist_remove(&smb_servers, sv);
4706139Sjb150015 	smb_llist_exit(&smb_servers);
4716139Sjb150015 
4726139Sjb150015 	smb_server_stop(sv);
4736139Sjb150015 	rw_destroy(&sv->sv_cfg_lock);
4747052Samw 	smb_opipe_door_fini();
4757588Samw@Sun.COM 	smb_kdoor_clnt_fini();
4766139Sjb150015 	smb_server_kstat_fini(sv);
4776139Sjb150015 	smb_llist_destructor(&sv->sv_vfs_list);
4787619SJose.Borrego@Sun.COM 
4797619SJose.Borrego@Sun.COM 	while ((ux = list_head(&sv->sv_unexport_list.sl_list)) != NULL) {
4807619SJose.Borrego@Sun.COM 		smb_slist_remove(&sv->sv_unexport_list, ux);
4817619SJose.Borrego@Sun.COM 		kmem_cache_free(sv->si_cache_unexport, ux);
4827619SJose.Borrego@Sun.COM 	}
4837619SJose.Borrego@Sun.COM 	smb_slist_destructor(&sv->sv_unexport_list);
4847619SJose.Borrego@Sun.COM 
4857619SJose.Borrego@Sun.COM 	kmem_cache_destroy(sv->si_cache_unexport);
4866139Sjb150015 	kmem_cache_destroy(sv->si_cache_vfs);
4876139Sjb150015 	kmem_cache_destroy(sv->si_cache_request);
4886139Sjb150015 	kmem_cache_destroy(sv->si_cache_session);
4896139Sjb150015 	kmem_cache_destroy(sv->si_cache_user);
4906139Sjb150015 	kmem_cache_destroy(sv->si_cache_tree);
4916139Sjb150015 	kmem_cache_destroy(sv->si_cache_ofile);
4926139Sjb150015 	kmem_cache_destroy(sv->si_cache_odir);
4936139Sjb150015 
4946139Sjb150015 	smb_thread_destroy(&sv->si_thread_timers);
4957619SJose.Borrego@Sun.COM 	smb_thread_destroy(&sv->si_thread_unexport);
4966139Sjb150015 	mutex_destroy(&sv->sv_mutex);
4976139Sjb150015 	cv_destroy(&sv->sv_cv);
4986139Sjb150015 	sv->sv_magic = 0;
4996139Sjb150015 	kmem_free(sv, sizeof (smb_server_t));
5006139Sjb150015 
5016139Sjb150015 	return (0);
5026139Sjb150015 }
5036139Sjb150015 
5046139Sjb150015 /*
5056139Sjb150015  * smb_server_configure
5066139Sjb150015  */
5076139Sjb150015 int
5089832Samw@Sun.COM smb_server_configure(smb_ioc_cfg_t *ioc)
5096139Sjb150015 {
5106139Sjb150015 	int		rc = 0;
5116139Sjb150015 	smb_server_t	*sv;
5126139Sjb150015 
5136139Sjb150015 	rc = smb_server_lookup(&sv);
5146139Sjb150015 	if (rc)
5156139Sjb150015 		return (rc);
5166139Sjb150015 
5176139Sjb150015 	mutex_enter(&sv->sv_mutex);
5186139Sjb150015 	switch (sv->sv_state) {
5196139Sjb150015 	case SMB_SERVER_STATE_CREATED:
5209832Samw@Sun.COM 		smb_server_store_cfg(sv, ioc);
5216139Sjb150015 		sv->sv_state = SMB_SERVER_STATE_CONFIGURED;
5226139Sjb150015 		break;
5236139Sjb150015 
5246139Sjb150015 	case SMB_SERVER_STATE_CONFIGURED:
5259832Samw@Sun.COM 		smb_server_store_cfg(sv, ioc);
5266139Sjb150015 		break;
5276139Sjb150015 
5286139Sjb150015 	case SMB_SERVER_STATE_RUNNING:
5296139Sjb150015 		rw_enter(&sv->sv_cfg_lock, RW_WRITER);
5309832Samw@Sun.COM 		smb_server_store_cfg(sv, ioc);
5316139Sjb150015 		rw_exit(&sv->sv_cfg_lock);
5326139Sjb150015 		break;
5336139Sjb150015 
5346139Sjb150015 	default:
5356139Sjb150015 		ASSERT(sv->sv_state == SMB_SERVER_STATE_DELETING);
5366139Sjb150015 		rc = EFAULT;
5376139Sjb150015 		break;
5386139Sjb150015 	}
5396139Sjb150015 	mutex_exit(&sv->sv_mutex);
5406139Sjb150015 
5416139Sjb150015 	smb_server_release(sv);
5426139Sjb150015 
5436139Sjb150015 	return (rc);
5446139Sjb150015 }
5456139Sjb150015 
5466139Sjb150015 /*
5476139Sjb150015  * smb_server_start
5486139Sjb150015  */
5496139Sjb150015 int
5509832Samw@Sun.COM smb_server_start(smb_ioc_start_t *ioc)
5516139Sjb150015 {
5526139Sjb150015 	int		rc = 0;
5536139Sjb150015 	smb_server_t	*sv;
5546139Sjb150015 
5556139Sjb150015 	rc = smb_server_lookup(&sv);
5566139Sjb150015 	if (rc)
5576139Sjb150015 		return (rc);
5586139Sjb150015 
5596139Sjb150015 	mutex_enter(&sv->sv_mutex);
5606139Sjb150015 	switch (sv->sv_state) {
5616139Sjb150015 	case SMB_SERVER_STATE_CONFIGURED:
5626139Sjb150015 
5636139Sjb150015 		sv->sv_thread_pool = taskq_create("smb_workers",
5646139Sjb150015 		    sv->sv_cfg.skc_maxworkers, SMB_WORKER_PRIORITY,
5656139Sjb150015 		    sv->sv_cfg.skc_maxworkers, INT_MAX,
5666139Sjb150015 		    TASKQ_DYNAMIC|TASKQ_PREPOPULATE);
5676139Sjb150015 
5688670SJose.Borrego@Sun.COM 		sv->sv_session = smb_session_create(NULL, 0, sv, 0);
5697588Samw@Sun.COM 
5707588Samw@Sun.COM 		if (sv->sv_thread_pool == NULL || sv->sv_session == NULL) {
5716139Sjb150015 			rc = ENOMEM;
5726139Sjb150015 			break;
5736139Sjb150015 		}
5746139Sjb150015 
5756139Sjb150015 		if (rc = smb_server_fsop_start(sv))
5766139Sjb150015 			break;
5776139Sjb150015 		ASSERT(sv->sv_lmshrd == NULL);
5789832Samw@Sun.COM 		sv->sv_lmshrd = smb_kshare_init(ioc->lmshrd);
5796139Sjb150015 		if (sv->sv_lmshrd == NULL)
5806139Sjb150015 			break;
5819832Samw@Sun.COM 		if (rc = smb_kdoor_clnt_open(ioc->udoor))
5826139Sjb150015 			break;
5836139Sjb150015 		if (rc = smb_thread_start(&sv->si_thread_timers))
5846139Sjb150015 			break;
5857619SJose.Borrego@Sun.COM 		if (rc = smb_thread_start(&sv->si_thread_unexport))
5867619SJose.Borrego@Sun.COM 			break;
5879832Samw@Sun.COM 		if (rc = smb_opipe_door_open(ioc->opipe)) {
5887052Samw 			cmn_err(CE_WARN, "Cannot open opipe door");
5896139Sjb150015 			break;
5906139Sjb150015 		}
5919832Samw@Sun.COM 
5929832Samw@Sun.COM 		(void) oem_language_set("english");
5939832Samw@Sun.COM 
5946139Sjb150015 		sv->sv_state = SMB_SERVER_STATE_RUNNING;
5956139Sjb150015 		mutex_exit(&sv->sv_mutex);
5966139Sjb150015 		smb_server_release(sv);
5976139Sjb150015 		return (0);
5986139Sjb150015 	default:
5996139Sjb150015 		ASSERT((sv->sv_state == SMB_SERVER_STATE_CREATED) ||
6006139Sjb150015 		    (sv->sv_state == SMB_SERVER_STATE_RUNNING) ||
6016139Sjb150015 		    (sv->sv_state == SMB_SERVER_STATE_DELETING));
6026139Sjb150015 		mutex_exit(&sv->sv_mutex);
6036139Sjb150015 		smb_server_release(sv);
6046139Sjb150015 		return (ENOTTY);
6056139Sjb150015 	}
6066139Sjb150015 
6076139Sjb150015 	smb_server_stop(sv);
6086139Sjb150015 	mutex_exit(&sv->sv_mutex);
6096139Sjb150015 	smb_server_release(sv);
6106139Sjb150015 	return (rc);
6116139Sjb150015 }
6126139Sjb150015 
6136139Sjb150015 /*
6146139Sjb150015  * smb_server_nbt_listen: SMB-over-NetBIOS service
6156139Sjb150015  *
6166139Sjb150015  * Traditional SMB service over NetBIOS (port 139), which requires
6176139Sjb150015  * that a NetBIOS session be established.
6186139Sjb150015  */
6196139Sjb150015 int
6209832Samw@Sun.COM smb_server_nbt_listen(smb_ioc_listen_t *ioc)
6216139Sjb150015 {
6226139Sjb150015 	smb_server_t	*sv;
6236139Sjb150015 	int		rc;
6246139Sjb150015 
6256139Sjb150015 	rc = smb_server_lookup(&sv);
6266139Sjb150015 	if (rc)
6276139Sjb150015 		return (rc);
6286139Sjb150015 
6296139Sjb150015 	mutex_enter(&sv->sv_mutex);
6306139Sjb150015 	switch (sv->sv_state) {
6316139Sjb150015 	case SMB_SERVER_STATE_RUNNING:
6326139Sjb150015 		if ((sv->sv_nbt_daemon.ld_kth != NULL) &&
6336139Sjb150015 		    (sv->sv_nbt_daemon.ld_kth != curthread)) {
6346139Sjb150015 			mutex_exit(&sv->sv_mutex);
6359422SAfshin.Ardakani@Sun.COM 			smb_server_release(sv);
6366139Sjb150015 			return (EACCES);
6376139Sjb150015 		} else {
6386139Sjb150015 			sv->sv_nbt_daemon.ld_kth = curthread;
6396139Sjb150015 			sv->sv_nbt_daemon.ld_ktdid = curthread->t_did;
6406139Sjb150015 		}
6416139Sjb150015 		break;
6426139Sjb150015 	default:
6436139Sjb150015 		ASSERT((sv->sv_state == SMB_SERVER_STATE_CREATED) ||
6446139Sjb150015 		    (sv->sv_state == SMB_SERVER_STATE_CONFIGURED) ||
6456139Sjb150015 		    (sv->sv_state == SMB_SERVER_STATE_DELETING));
6466139Sjb150015 		mutex_exit(&sv->sv_mutex);
6476139Sjb150015 		smb_server_release(sv);
6486139Sjb150015 		return (EFAULT);
6496139Sjb150015 	}
6506139Sjb150015 	mutex_exit(&sv->sv_mutex);
6516139Sjb150015 
6528670SJose.Borrego@Sun.COM 	/*
6538670SJose.Borrego@Sun.COM 	 * netbios must be ipv4
6548670SJose.Borrego@Sun.COM 	 */
655*10717Samw@Sun.COM 	rc = smb_server_listen(sv, &sv->sv_nbt_daemon, IPPORT_NETBIOS_SSN,
6569832Samw@Sun.COM 	    AF_INET, ioc->error);
6576139Sjb150015 
6586139Sjb150015 	if (rc) {
6596139Sjb150015 		mutex_enter(&sv->sv_mutex);
6606139Sjb150015 		sv->sv_nbt_daemon.ld_kth = NULL;
6616139Sjb150015 		mutex_exit(&sv->sv_mutex);
6626139Sjb150015 	}
6636139Sjb150015 
6646139Sjb150015 	smb_server_release(sv);
6656139Sjb150015 	return (rc);
6666139Sjb150015 }
6676139Sjb150015 
6686139Sjb150015 int
6699832Samw@Sun.COM smb_server_tcp_listen(smb_ioc_listen_t *ioc)
6706139Sjb150015 {
6716139Sjb150015 	smb_server_t	*sv;
6726139Sjb150015 	int		rc;
6736139Sjb150015 
6746139Sjb150015 	rc = smb_server_lookup(&sv);
6756139Sjb150015 	if (rc)
6766139Sjb150015 		return (rc);
6776139Sjb150015 
6786139Sjb150015 	mutex_enter(&sv->sv_mutex);
6796139Sjb150015 	switch (sv->sv_state) {
6806139Sjb150015 	case SMB_SERVER_STATE_RUNNING:
6816139Sjb150015 		if ((sv->sv_tcp_daemon.ld_kth) &&
6826139Sjb150015 		    (sv->sv_tcp_daemon.ld_kth != curthread)) {
6836139Sjb150015 			mutex_exit(&sv->sv_mutex);
6849422SAfshin.Ardakani@Sun.COM 			smb_server_release(sv);
6856139Sjb150015 			return (EACCES);
6866139Sjb150015 		} else {
6876139Sjb150015 			sv->sv_tcp_daemon.ld_kth = curthread;
6886139Sjb150015 			sv->sv_tcp_daemon.ld_ktdid = curthread->t_did;
6896139Sjb150015 		}
6906139Sjb150015 		break;
6916139Sjb150015 	default:
6926139Sjb150015 		ASSERT((sv->sv_state == SMB_SERVER_STATE_CREATED) ||
6936139Sjb150015 		    (sv->sv_state == SMB_SERVER_STATE_CONFIGURED) ||
6946139Sjb150015 		    (sv->sv_state == SMB_SERVER_STATE_DELETING));
6956139Sjb150015 		mutex_exit(&sv->sv_mutex);
6969422SAfshin.Ardakani@Sun.COM 		smb_server_release(sv);
6976139Sjb150015 		return (EFAULT);
6986139Sjb150015 	}
6996139Sjb150015 	mutex_exit(&sv->sv_mutex);
7006139Sjb150015 
7018670SJose.Borrego@Sun.COM 	if (sv->sv_cfg.skc_ipv6_enable)
7028670SJose.Borrego@Sun.COM 		rc = smb_server_listen(sv, &sv->sv_tcp_daemon,
703*10717Samw@Sun.COM 		    IPPORT_SMB, AF_INET6, ioc->error);
7048670SJose.Borrego@Sun.COM 	else
7058670SJose.Borrego@Sun.COM 		rc = smb_server_listen(sv, &sv->sv_tcp_daemon,
706*10717Samw@Sun.COM 		    IPPORT_SMB, AF_INET, ioc->error);
7076139Sjb150015 	if (rc) {
7086139Sjb150015 		mutex_enter(&sv->sv_mutex);
7096139Sjb150015 		sv->sv_tcp_daemon.ld_kth = NULL;
7106139Sjb150015 		mutex_exit(&sv->sv_mutex);
7116139Sjb150015 	}
7126139Sjb150015 
7136139Sjb150015 	smb_server_release(sv);
7146139Sjb150015 	return (rc);
7156139Sjb150015 }
7166139Sjb150015 
7176139Sjb150015 /*
7186139Sjb150015  * smb_server_nbt_receive
7196139Sjb150015  */
7206139Sjb150015 int
7216139Sjb150015 smb_server_nbt_receive(void)
7226139Sjb150015 {
7236139Sjb150015 	int		rc;
7246139Sjb150015 	smb_server_t	*sv;
7256139Sjb150015 
7269422SAfshin.Ardakani@Sun.COM 	if ((rc = smb_server_lookup(&sv)) == 0) {
7279422SAfshin.Ardakani@Sun.COM 		rc = smb_session_daemon(&sv->sv_nbt_daemon.ld_session_list);
7289422SAfshin.Ardakani@Sun.COM 		smb_server_release(sv);
7299422SAfshin.Ardakani@Sun.COM 	}
7306139Sjb150015 
7316139Sjb150015 	return (rc);
7326139Sjb150015 }
7336139Sjb150015 
7346139Sjb150015 /*
7356139Sjb150015  * smb_server_tcp_receive
7366139Sjb150015  */
7376139Sjb150015 int
7386139Sjb150015 smb_server_tcp_receive(void)
7396139Sjb150015 {
7406139Sjb150015 	int		rc;
7416139Sjb150015 	smb_server_t	*sv;
7426139Sjb150015 
7439422SAfshin.Ardakani@Sun.COM 	if ((rc = smb_server_lookup(&sv)) == 0) {
7449422SAfshin.Ardakani@Sun.COM 		rc = smb_session_daemon(&sv->sv_tcp_daemon.ld_session_list);
7459422SAfshin.Ardakani@Sun.COM 		smb_server_release(sv);
7469422SAfshin.Ardakani@Sun.COM 	}
7476139Sjb150015 
7486139Sjb150015 	return (rc);
7496139Sjb150015 }
7506139Sjb150015 
7516139Sjb150015 int
7529832Samw@Sun.COM smb_server_set_gmtoff(smb_ioc_gmt_t *ioc)
7536139Sjb150015 {
7546139Sjb150015 	int		rc;
7556139Sjb150015 	smb_server_t	*sv;
7566139Sjb150015 
7579422SAfshin.Ardakani@Sun.COM 	if ((rc = smb_server_lookup(&sv)) == 0) {
7589832Samw@Sun.COM 		sv->si_gmtoff = ioc->offset;
7599422SAfshin.Ardakani@Sun.COM 		smb_server_release(sv);
7609422SAfshin.Ardakani@Sun.COM 	}
7616139Sjb150015 
7626139Sjb150015 	return (rc);
7636139Sjb150015 }
7646139Sjb150015 
7659832Samw@Sun.COM int
76610122SJordan.Brown@Sun.COM smb_server_numopen(smb_ioc_opennum_t *ioc)
7679832Samw@Sun.COM {
7689832Samw@Sun.COM 	smb_server_t	*sv;
7699832Samw@Sun.COM 	int		rc;
7709832Samw@Sun.COM 
7719832Samw@Sun.COM 	if ((rc = smb_server_lookup(&sv)) == 0) {
77210122SJordan.Brown@Sun.COM 		ioc->open_users = sv->sv_open_users;
77310122SJordan.Brown@Sun.COM 		ioc->open_trees = sv->sv_open_trees;
77410122SJordan.Brown@Sun.COM 		ioc->open_files = sv->sv_open_files;
7759832Samw@Sun.COM 		smb_server_release(sv);
7769832Samw@Sun.COM 	}
7779832Samw@Sun.COM 	return (rc);
7789832Samw@Sun.COM }
7799832Samw@Sun.COM 
7806139Sjb150015 /*
78110122SJordan.Brown@Sun.COM  * Enumerate objects within the server.  The svcenum provides the
78210122SJordan.Brown@Sun.COM  * enumeration context, i.e. what the caller want to get back.
78310122SJordan.Brown@Sun.COM  */
78410122SJordan.Brown@Sun.COM int
78510122SJordan.Brown@Sun.COM smb_server_enum(smb_ioc_svcenum_t *ioc)
78610122SJordan.Brown@Sun.COM {
78710122SJordan.Brown@Sun.COM 	smb_svcenum_t		*svcenum = &ioc->svcenum;
78810122SJordan.Brown@Sun.COM 	smb_server_t		*sv;
78910122SJordan.Brown@Sun.COM 	smb_session_list_t	*se;
79010122SJordan.Brown@Sun.COM 	int			rc;
79110122SJordan.Brown@Sun.COM 
79210122SJordan.Brown@Sun.COM 	switch (svcenum->se_type) {
79310122SJordan.Brown@Sun.COM 	case SMB_SVCENUM_TYPE_USER:
79410122SJordan.Brown@Sun.COM 	case SMB_SVCENUM_TYPE_TREE:
79510122SJordan.Brown@Sun.COM 	case SMB_SVCENUM_TYPE_FILE:
79610122SJordan.Brown@Sun.COM 		break;
79710122SJordan.Brown@Sun.COM 	default:
79810122SJordan.Brown@Sun.COM 		return (EINVAL);
79910122SJordan.Brown@Sun.COM 	}
80010122SJordan.Brown@Sun.COM 
80110122SJordan.Brown@Sun.COM 	if ((rc = smb_server_lookup(&sv)) != 0)
80210122SJordan.Brown@Sun.COM 		return (rc);
80310122SJordan.Brown@Sun.COM 
80410122SJordan.Brown@Sun.COM 	svcenum->se_bavail = svcenum->se_buflen;
80510122SJordan.Brown@Sun.COM 	svcenum->se_bused = 0;
80610122SJordan.Brown@Sun.COM 	svcenum->se_nitems = 0;
80710122SJordan.Brown@Sun.COM 
80810122SJordan.Brown@Sun.COM 	se = &sv->sv_nbt_daemon.ld_session_list;
80910122SJordan.Brown@Sun.COM 	smb_server_enum_private(se, svcenum);
81010122SJordan.Brown@Sun.COM 
81110122SJordan.Brown@Sun.COM 	se = &sv->sv_tcp_daemon.ld_session_list;
81210122SJordan.Brown@Sun.COM 	smb_server_enum_private(se, svcenum);
81310122SJordan.Brown@Sun.COM 
81410122SJordan.Brown@Sun.COM 	smb_server_release(sv);
81510122SJordan.Brown@Sun.COM 	return (0);
81610122SJordan.Brown@Sun.COM }
81710122SJordan.Brown@Sun.COM 
81810122SJordan.Brown@Sun.COM /*
81910122SJordan.Brown@Sun.COM  * Look for sessions to disconnect by client and user name.
82010122SJordan.Brown@Sun.COM  */
82110122SJordan.Brown@Sun.COM int
82210122SJordan.Brown@Sun.COM smb_server_session_close(smb_ioc_session_t *ioc)
82310122SJordan.Brown@Sun.COM {
82410122SJordan.Brown@Sun.COM 	smb_session_list_t	*se;
82510122SJordan.Brown@Sun.COM 	smb_server_t		*sv;
82610122SJordan.Brown@Sun.COM 	int			nbt_cnt;
82710122SJordan.Brown@Sun.COM 	int			tcp_cnt;
82810122SJordan.Brown@Sun.COM 	int			rc;
82910122SJordan.Brown@Sun.COM 
83010122SJordan.Brown@Sun.COM 	if ((rc = smb_server_lookup(&sv)) != 0)
83110122SJordan.Brown@Sun.COM 		return (rc);
83210122SJordan.Brown@Sun.COM 
83310122SJordan.Brown@Sun.COM 	se = &sv->sv_nbt_daemon.ld_session_list;
83410122SJordan.Brown@Sun.COM 	nbt_cnt = smb_server_sesion_disconnect(se, ioc->client, ioc->username);
83510122SJordan.Brown@Sun.COM 
83610122SJordan.Brown@Sun.COM 	se = &sv->sv_tcp_daemon.ld_session_list;
83710122SJordan.Brown@Sun.COM 	tcp_cnt = smb_server_sesion_disconnect(se, ioc->client, ioc->username);
83810122SJordan.Brown@Sun.COM 
83910122SJordan.Brown@Sun.COM 	smb_server_release(sv);
84010122SJordan.Brown@Sun.COM 
84110122SJordan.Brown@Sun.COM 	if ((nbt_cnt == 0) && (tcp_cnt == 0))
84210122SJordan.Brown@Sun.COM 		return (ENOENT);
84310122SJordan.Brown@Sun.COM 	return (0);
84410122SJordan.Brown@Sun.COM }
84510122SJordan.Brown@Sun.COM 
84610122SJordan.Brown@Sun.COM /*
84710122SJordan.Brown@Sun.COM  * Close a file by uniqid.
84810122SJordan.Brown@Sun.COM  */
84910122SJordan.Brown@Sun.COM int
85010122SJordan.Brown@Sun.COM smb_server_file_close(smb_ioc_fileid_t *ioc)
85110122SJordan.Brown@Sun.COM {
85210122SJordan.Brown@Sun.COM 	uint32_t		uniqid = ioc->uniqid;
85310122SJordan.Brown@Sun.COM 	smb_session_list_t	*se;
85410122SJordan.Brown@Sun.COM 	smb_server_t		*sv;
85510122SJordan.Brown@Sun.COM 	int			rc;
85610122SJordan.Brown@Sun.COM 
85710122SJordan.Brown@Sun.COM 	if ((rc = smb_server_lookup(&sv)) != 0)
85810122SJordan.Brown@Sun.COM 		return (rc);
85910122SJordan.Brown@Sun.COM 
86010122SJordan.Brown@Sun.COM 	se = &sv->sv_nbt_daemon.ld_session_list;
86110122SJordan.Brown@Sun.COM 	rc = smb_server_fclose(se, uniqid);
86210122SJordan.Brown@Sun.COM 
86310122SJordan.Brown@Sun.COM 	if (rc == ENOENT) {
86410122SJordan.Brown@Sun.COM 		se = &sv->sv_tcp_daemon.ld_session_list;
86510122SJordan.Brown@Sun.COM 		rc = smb_server_fclose(se, uniqid);
86610122SJordan.Brown@Sun.COM 	}
86710122SJordan.Brown@Sun.COM 
86810122SJordan.Brown@Sun.COM 	smb_server_release(sv);
86910122SJordan.Brown@Sun.COM 	return (rc);
87010122SJordan.Brown@Sun.COM }
87110122SJordan.Brown@Sun.COM 
87210122SJordan.Brown@Sun.COM /*
8736139Sjb150015  * These functions determine the relevant smb server to which the call apply.
8746139Sjb150015  */
8756139Sjb150015 
8766139Sjb150015 uint32_t
8776139Sjb150015 smb_server_get_session_count(void)
8786139Sjb150015 {
8796139Sjb150015 	smb_server_t	*sv;
8806139Sjb150015 	uint32_t	counter = 0;
8816139Sjb150015 
8826139Sjb150015 	if (smb_server_lookup(&sv))
8836139Sjb150015 		return (0);
8846139Sjb150015 
8856139Sjb150015 	rw_enter(&sv->sv_nbt_daemon.ld_session_list.se_lock, RW_READER);
8866139Sjb150015 	counter = sv->sv_nbt_daemon.ld_session_list.se_act.count;
8876139Sjb150015 	rw_exit(&sv->sv_nbt_daemon.ld_session_list.se_lock);
8886139Sjb150015 	rw_enter(&sv->sv_tcp_daemon.ld_session_list.se_lock, RW_READER);
8896139Sjb150015 	counter += sv->sv_tcp_daemon.ld_session_list.se_act.count;
8906139Sjb150015 	rw_exit(&sv->sv_tcp_daemon.ld_session_list.se_lock);
8916139Sjb150015 
8926139Sjb150015 	smb_server_release(sv);
8936139Sjb150015 
8946139Sjb150015 	return (counter);
8956139Sjb150015 }
8966139Sjb150015 
8976139Sjb150015 /*
8987619SJose.Borrego@Sun.COM  * smb_server_disconnect_share
8996139Sjb150015  *
9006139Sjb150015  * Disconnects the specified share. This function should be called after the
9016139Sjb150015  * share passed in has been made unavailable by the "share manager".
9026139Sjb150015  */
9037619SJose.Borrego@Sun.COM static void
9047619SJose.Borrego@Sun.COM smb_server_disconnect_share(char *sharename, smb_server_t *sv)
9056139Sjb150015 {
9066139Sjb150015 	smb_session_disconnect_share(&sv->sv_nbt_daemon.ld_session_list,
9076139Sjb150015 	    sharename);
9086139Sjb150015 	smb_session_disconnect_share(&sv->sv_tcp_daemon.ld_session_list,
9096139Sjb150015 	    sharename);
9106139Sjb150015 }
9116139Sjb150015 
9126139Sjb150015 /*
9136139Sjb150015  * smb_server_share_export()
9146139Sjb150015  *
9156139Sjb150015  * This function handles kernel processing at share enable time.
9166139Sjb150015  *
9176139Sjb150015  * At share-enable time (LMSHRD_ADD), the file system corresponding to
9186139Sjb150015  * the share is checked for characteristics that are required for SMB
9196139Sjb150015  * sharing.  If this check passes, then a hold is taken on the root vnode
9206139Sjb150015  * of the file system (or a reference count on the corresponding smb_vfs_t
9216139Sjb150015  * is bumped), preventing an unmount.  (See smb_vfs_hold()).
9226139Sjb150015  */
9236139Sjb150015 
9246139Sjb150015 int
9259832Samw@Sun.COM smb_server_share_export(smb_ioc_share_t *ioc)
9266139Sjb150015 {
9276139Sjb150015 	smb_server_t	*sv;
9289422SAfshin.Ardakani@Sun.COM 	int		error = 0;
9296139Sjb150015 	smb_node_t	*fnode = NULL;
9306139Sjb150015 	smb_node_t	*dnode;
9316139Sjb150015 	char		last_comp[MAXNAMELEN];
9326139Sjb150015 	smb_request_t	*sr;
9336139Sjb150015 
9346139Sjb150015 	if (smb_server_lookup(&sv))
9356139Sjb150015 		return (EINVAL);
9366139Sjb150015 
9379832Samw@Sun.COM 	mutex_enter(&sv->sv_mutex);
9389832Samw@Sun.COM 	switch (sv->sv_state) {
9399832Samw@Sun.COM 	case SMB_SERVER_STATE_RUNNING:
9409832Samw@Sun.COM 		break;
9419832Samw@Sun.COM 	default:
9429832Samw@Sun.COM 		mutex_exit(&sv->sv_mutex);
9439832Samw@Sun.COM 		return (ENOTACTIVE);
9449832Samw@Sun.COM 	}
9459832Samw@Sun.COM 	mutex_exit(&sv->sv_mutex);
9469832Samw@Sun.COM 
9476139Sjb150015 	sr = smb_request_alloc(sv->sv_session, 0);
9486139Sjb150015 	if (sr == NULL) {
9496139Sjb150015 		smb_server_release(sv);
9506139Sjb150015 		return (ENOMEM);
9516139Sjb150015 	}
9526139Sjb150015 
9536139Sjb150015 	sr->user_cr = kcred;
9546139Sjb150015 
9559832Samw@Sun.COM 	error = smb_pathname_reduce(sr, kcred, ioc->path,
9569832Samw@Sun.COM 	    NULL, NULL, &dnode, last_comp);
9576139Sjb150015 
9586139Sjb150015 	if (error) {
9596139Sjb150015 		smb_request_free(sr);
9606139Sjb150015 		smb_server_release(sv);
9616139Sjb150015 		return (error);
9626139Sjb150015 	}
9636139Sjb150015 
9649231SAfshin.Ardakani@Sun.COM 	error = smb_fsop_lookup(sr, sr->user_cr, SMB_FOLLOW_LINKS,
96510001SJoyce.McIntosh@Sun.COM 	    sv->si_root_smb_node, dnode, last_comp, &fnode);
9666139Sjb150015 
9676139Sjb150015 	smb_node_release(dnode);
9686139Sjb150015 
9696139Sjb150015 	if (error) {
9706139Sjb150015 		smb_request_free(sr);
9716139Sjb150015 		smb_server_release(sv);
9726139Sjb150015 		return (error);
9736139Sjb150015 	}
9746139Sjb150015 
9756139Sjb150015 	ASSERT(fnode->vp && fnode->vp->v_vfsp);
9766139Sjb150015 
9776139Sjb150015 #ifdef SMB_ENFORCE_NODEV
9789422SAfshin.Ardakani@Sun.COM 	if (vfs_optionisset(fnode->vp->v_vfsp, MNTOPT_NODEVICES, NULL) == 0) {
9796139Sjb150015 		smb_node_release(fnode);
9806139Sjb150015 		smb_request_free(sr);
9816139Sjb150015 		smb_server_release(sv);
9829422SAfshin.Ardakani@Sun.COM 		return (EINVAL);
9836139Sjb150015 	}
9849422SAfshin.Ardakani@Sun.COM #endif /* SMB_ENFORCE_NODEV */
9859422SAfshin.Ardakani@Sun.COM 
9869422SAfshin.Ardakani@Sun.COM 	if (!smb_vfs_hold(sv, fnode->vp->v_vfsp))
9879422SAfshin.Ardakani@Sun.COM 		error = ENOMEM;
9886139Sjb150015 
9896139Sjb150015 	/*
9906139Sjb150015 	 * The refcount on the smb_vfs has been incremented.
9916139Sjb150015 	 * If it wasn't already, a hold has also been taken
9926139Sjb150015 	 * on the root vnode of the file system.
9936139Sjb150015 	 */
9946139Sjb150015 
9956139Sjb150015 	smb_node_release(fnode);
9966139Sjb150015 	smb_request_free(sr);
9976139Sjb150015 	smb_server_release(sv);
9989422SAfshin.Ardakani@Sun.COM 	return (error);
9996139Sjb150015 }
10006139Sjb150015 
10016139Sjb150015 /*
10026139Sjb150015  * smb_server_share_unexport()
10036139Sjb150015  *
10047619SJose.Borrego@Sun.COM  * This function is invoked when a share is disabled to disconnect trees
10057619SJose.Borrego@Sun.COM  * and close files.  Cleaning up may involve VOP and/or VFS calls, which
10067619SJose.Borrego@Sun.COM  * may conflict/deadlock with stuck threads if something is amiss with the
10077619SJose.Borrego@Sun.COM  * file system.  Queueing the request for asynchronous processing allows the
10087619SJose.Borrego@Sun.COM  * call to return immediately so that, if the unshare is being done in the
10097619SJose.Borrego@Sun.COM  * context of a forced unmount, the forced unmount will always be able to
10107619SJose.Borrego@Sun.COM  * proceed (unblocking stuck I/O and eventually allowing all blocked unshare
10117619SJose.Borrego@Sun.COM  * processes to complete).
10126139Sjb150015  *
10137619SJose.Borrego@Sun.COM  * The path lookup to find the root vnode of the VFS in question and the
10147619SJose.Borrego@Sun.COM  * release of this vnode are done synchronously prior to any associated
10157619SJose.Borrego@Sun.COM  * unmount.  Doing these asynchronous to an associated unmount could run
10167619SJose.Borrego@Sun.COM  * the risk of a spurious EBUSY for a standard unmount or an EIO during
10177619SJose.Borrego@Sun.COM  * the path lookup due to a forced unmount finishing first.
10186139Sjb150015  */
10196139Sjb150015 
10206139Sjb150015 int
10219832Samw@Sun.COM smb_server_share_unexport(smb_ioc_share_t *ioc)
10226139Sjb150015 {
10236139Sjb150015 	smb_server_t	*sv;
10247619SJose.Borrego@Sun.COM 	smb_request_t	*sr;
10257619SJose.Borrego@Sun.COM 	smb_unexport_t	*ux;
10266139Sjb150015 	smb_node_t	*fnode = NULL;
10276139Sjb150015 	smb_node_t	*dnode;
10286139Sjb150015 	char		last_comp[MAXNAMELEN];
10297619SJose.Borrego@Sun.COM 	int		rc;
10306139Sjb150015 
10317619SJose.Borrego@Sun.COM 	if ((rc = smb_server_lookup(&sv)))
10327619SJose.Borrego@Sun.COM 		return (rc);
10336139Sjb150015 
10349832Samw@Sun.COM 	mutex_enter(&sv->sv_mutex);
10359832Samw@Sun.COM 	switch (sv->sv_state) {
10369832Samw@Sun.COM 	case SMB_SERVER_STATE_RUNNING:
10379832Samw@Sun.COM 		break;
10389832Samw@Sun.COM 	default:
10399832Samw@Sun.COM 		mutex_exit(&sv->sv_mutex);
10409832Samw@Sun.COM 		return (ENOTACTIVE);
10419832Samw@Sun.COM 	}
10429832Samw@Sun.COM 	mutex_exit(&sv->sv_mutex);
10439832Samw@Sun.COM 
10446139Sjb150015 	sr = smb_request_alloc(sv->sv_session, 0);
10457619SJose.Borrego@Sun.COM 
10466139Sjb150015 	if (sr == NULL) {
10476139Sjb150015 		smb_server_release(sv);
10486139Sjb150015 		return (ENOMEM);
10496139Sjb150015 	}
10507619SJose.Borrego@Sun.COM 
10516139Sjb150015 	sr->user_cr = kcred;
10526139Sjb150015 
10539832Samw@Sun.COM 	rc = smb_pathname_reduce(sr, kcred, ioc->path, NULL, NULL,
10549832Samw@Sun.COM 	    &dnode, last_comp);
10556139Sjb150015 
10567619SJose.Borrego@Sun.COM 	if (rc) {
10576139Sjb150015 		smb_request_free(sr);
10586139Sjb150015 		smb_server_release(sv);
10597619SJose.Borrego@Sun.COM 		return (rc);
10606139Sjb150015 	}
10616139Sjb150015 
10629231SAfshin.Ardakani@Sun.COM 	rc = smb_fsop_lookup(sr, kcred, SMB_FOLLOW_LINKS, sv->si_root_smb_node,
106310001SJoyce.McIntosh@Sun.COM 	    dnode, last_comp, &fnode);
10646139Sjb150015 
10656139Sjb150015 	smb_node_release(dnode);
10667619SJose.Borrego@Sun.COM 	smb_request_free(sr);
10676139Sjb150015 
10687619SJose.Borrego@Sun.COM 	if (rc) {
10696139Sjb150015 		smb_server_release(sv);
10707619SJose.Borrego@Sun.COM 		return (rc);
10716139Sjb150015 	}
10726139Sjb150015 
10736139Sjb150015 	ASSERT(fnode->vp && fnode->vp->v_vfsp);
10746139Sjb150015 
10756139Sjb150015 	smb_vfs_rele(sv, fnode->vp->v_vfsp);
10767619SJose.Borrego@Sun.COM 
10776139Sjb150015 	smb_node_release(fnode);
10787619SJose.Borrego@Sun.COM 
10797619SJose.Borrego@Sun.COM 	ux = kmem_cache_alloc(sv->si_cache_unexport, KM_SLEEP);
10807619SJose.Borrego@Sun.COM 
10819832Samw@Sun.COM 	(void) strlcpy(ux->ux_sharename, ioc->name, MAXNAMELEN);
10827619SJose.Borrego@Sun.COM 
10837619SJose.Borrego@Sun.COM 	smb_slist_insert_tail(&sv->sv_unexport_list, ux);
10847619SJose.Borrego@Sun.COM 	smb_thread_signal(&sv->si_thread_unexport);
10857619SJose.Borrego@Sun.COM 
10866139Sjb150015 	smb_server_release(sv);
10876139Sjb150015 	return (0);
10886139Sjb150015 }
10896139Sjb150015 
10906139Sjb150015 /*
10917619SJose.Borrego@Sun.COM  * smb_server_thread_unexport
10927619SJose.Borrego@Sun.COM  *
10937619SJose.Borrego@Sun.COM  * This function processes the unexport event list and disconnects shares
10947619SJose.Borrego@Sun.COM  * asynchronously.  The function executes as a zone-specific thread.
10957619SJose.Borrego@Sun.COM  *
10967619SJose.Borrego@Sun.COM  * The server arg passed in is safe to use without a reference count, because
10977619SJose.Borrego@Sun.COM  * the server cannot be deleted until smb_thread_stop()/destroy() return,
10987619SJose.Borrego@Sun.COM  * which is also when the thread exits.
10997619SJose.Borrego@Sun.COM  */
11007619SJose.Borrego@Sun.COM 
11017619SJose.Borrego@Sun.COM static void
11027619SJose.Borrego@Sun.COM smb_server_thread_unexport(smb_thread_t *thread, void *arg)
11037619SJose.Borrego@Sun.COM {
11047619SJose.Borrego@Sun.COM 	smb_server_t *sv = (smb_server_t *)arg;
11057619SJose.Borrego@Sun.COM 	smb_unexport_t	*ux;
11067619SJose.Borrego@Sun.COM 
11077619SJose.Borrego@Sun.COM 	while (smb_thread_continue(thread)) {
11087619SJose.Borrego@Sun.COM 		while ((ux = list_head(&sv->sv_unexport_list.sl_list))
11097619SJose.Borrego@Sun.COM 		    != NULL) {
11107619SJose.Borrego@Sun.COM 			smb_slist_remove(&sv->sv_unexport_list, ux);
11117619SJose.Borrego@Sun.COM 			smb_server_disconnect_share(ux->ux_sharename, sv);
11127619SJose.Borrego@Sun.COM 			kmem_cache_free(sv->si_cache_unexport, ux);
11137619SJose.Borrego@Sun.COM 		}
11147619SJose.Borrego@Sun.COM 	}
11157619SJose.Borrego@Sun.COM }
11167619SJose.Borrego@Sun.COM 
11177619SJose.Borrego@Sun.COM /*
11186139Sjb150015  * This is a special interface that will be utilized by ZFS to cause a share to
11196139Sjb150015  * be added/removed.
11206139Sjb150015  *
11216139Sjb150015  * arg is either a lmshare_info_t or share_name from userspace.
11226139Sjb150015  * It will need to be copied into the kernel.   It is lmshare_info_t
11236139Sjb150015  * for add operations and share_name for delete operations.
11246139Sjb150015  */
11256139Sjb150015 int
11266139Sjb150015 smb_server_share(void *arg, boolean_t add_share)
11276139Sjb150015 {
11286139Sjb150015 	smb_server_t	*sv;
11296139Sjb150015 	int		rc;
11306139Sjb150015 
11316139Sjb150015 	rc = smb_server_lookup(&sv);
11326139Sjb150015 	if (rc == 0) {
11336139Sjb150015 		mutex_enter(&sv->sv_mutex);
11349832Samw@Sun.COM 		switch (sv->sv_state) {
11359832Samw@Sun.COM 		case SMB_SERVER_STATE_RUNNING:
11366139Sjb150015 			mutex_exit(&sv->sv_mutex);
11379832Samw@Sun.COM 			(void) smb_kshare_upcall(sv->sv_lmshrd, arg, add_share);
11389832Samw@Sun.COM 			break;
11399832Samw@Sun.COM 		default:
11406139Sjb150015 			mutex_exit(&sv->sv_mutex);
11419832Samw@Sun.COM 			break;
11426139Sjb150015 		}
11436139Sjb150015 		smb_server_release(sv);
11446139Sjb150015 	}
11459832Samw@Sun.COM 	return (0);
11466139Sjb150015 }
11476139Sjb150015 
11486139Sjb150015 /*
11496139Sjb150015  * *****************************************************************************
11506139Sjb150015  * **************** Functions called from the internal layers ******************
11516139Sjb150015  * *****************************************************************************
11526139Sjb150015  *
11536139Sjb150015  * These functions are provided the relevant smb server by the caller.
11546139Sjb150015  */
11556139Sjb150015 
11566139Sjb150015 void
11576139Sjb150015 smb_server_reconnection_check(smb_server_t *sv, smb_session_t *session)
11586139Sjb150015 {
11596139Sjb150015 	ASSERT(sv == session->s_server);
11606139Sjb150015 
11616139Sjb150015 	smb_session_reconnection_check(&sv->sv_nbt_daemon.ld_session_list,
11626139Sjb150015 	    session);
11636139Sjb150015 	smb_session_reconnection_check(&sv->sv_tcp_daemon.ld_session_list,
11646139Sjb150015 	    session);
11656139Sjb150015 }
11666139Sjb150015 
11676139Sjb150015 void
11686139Sjb150015 smb_server_get_cfg(smb_server_t *sv, smb_kmod_cfg_t *cfg)
11696139Sjb150015 {
11706139Sjb150015 	rw_enter(&sv->sv_cfg_lock, RW_READER);
11716139Sjb150015 	bcopy(&sv->sv_cfg, cfg, sizeof (*cfg));
11726139Sjb150015 	rw_exit(&sv->sv_cfg_lock);
11736139Sjb150015 }
11746139Sjb150015 
11756139Sjb150015 /*
11766139Sjb150015  * *****************************************************************************
11776139Sjb150015  * *************************** Static Functions ********************************
11786139Sjb150015  * *****************************************************************************
11796139Sjb150015  */
11806139Sjb150015 
11816139Sjb150015 static void
11826139Sjb150015 smb_server_timers(smb_thread_t *thread, void *arg)
11836139Sjb150015 {
11846139Sjb150015 	smb_server_t	*sv = (smb_server_t *)arg;
11856139Sjb150015 
11866139Sjb150015 	ASSERT(sv != NULL);
11876139Sjb150015 
11886139Sjb150015 	while (smb_thread_continue_timedwait(thread, 1 /* Seconds */)) {
11896139Sjb150015 		smb_session_timers(&sv->sv_nbt_daemon.ld_session_list);
11906139Sjb150015 		smb_session_timers(&sv->sv_tcp_daemon.ld_session_list);
11916139Sjb150015 	}
11926139Sjb150015 }
11936139Sjb150015 
11946139Sjb150015 /*
11956139Sjb150015  * smb_server_kstat_init
11966139Sjb150015  */
11976139Sjb150015 static int
11986139Sjb150015 smb_server_kstat_init(smb_server_t *sv)
11996139Sjb150015 {
12006432Sas200622 	(void) snprintf(sv->sv_ksp_name, sizeof (sv->sv_ksp_name), "%s%d",
12016432Sas200622 	    SMBSRV_KSTAT_NAME, sv->sv_zid);
12026139Sjb150015 
12036432Sas200622 	sv->sv_ksp = kstat_create(SMBSRV_KSTAT_MODULE, 0, sv->sv_ksp_name,
12046432Sas200622 	    SMBSRV_KSTAT_CLASS, KSTAT_TYPE_NAMED,
12056432Sas200622 	    sizeof (sv->sv_ks_data) / sizeof (kstat_named_t),
12066139Sjb150015 	    KSTAT_FLAG_VIRTUAL);
12076139Sjb150015 
12086139Sjb150015 	if (sv->sv_ksp) {
12096139Sjb150015 		(void) strlcpy(sv->sv_ks_data.open_files.name, "open_files",
12106139Sjb150015 		    sizeof (sv->sv_ks_data.open_files.name));
12116139Sjb150015 		sv->sv_ks_data.open_files.data_type = KSTAT_DATA_UINT32;
12126139Sjb150015 		(void) strlcpy(sv->sv_ks_data.open_trees.name, "connections",
12136139Sjb150015 		    sizeof (sv->sv_ks_data.open_trees.name));
12146139Sjb150015 		sv->sv_ks_data.open_trees.data_type = KSTAT_DATA_UINT32;
12156139Sjb150015 		(void) strlcpy(sv->sv_ks_data.open_users.name, "sessions",
12166139Sjb150015 		    sizeof (sv->sv_ks_data.open_users.name));
12176139Sjb150015 		sv->sv_ks_data.open_users.data_type = KSTAT_DATA_UINT32;
12186139Sjb150015 
12196139Sjb150015 		mutex_init(&sv->sv_ksp_mutex, NULL, MUTEX_DEFAULT, NULL);
12206139Sjb150015 		sv->sv_ksp->ks_lock = &sv->sv_ksp_mutex;
12216139Sjb150015 		sv->sv_ksp->ks_data = (void *)&sv->sv_ks_data;
12226139Sjb150015 		sv->sv_ksp->ks_update = smb_server_kstat_update_info;
12236139Sjb150015 		kstat_install(sv->sv_ksp);
12246139Sjb150015 	}
12256139Sjb150015 
12266139Sjb150015 	/* create and initialize smb kstats - smb_dispatch stats */
12276139Sjb150015 	smb_dispatch_kstat_init();
12286139Sjb150015 
12296139Sjb150015 	return (0);
12306139Sjb150015 }
12316139Sjb150015 
12326139Sjb150015 /*
12336139Sjb150015  * smb_server_kstat_fini
12346139Sjb150015  */
12356139Sjb150015 static void
12366139Sjb150015 smb_server_kstat_fini(smb_server_t *sv)
12376139Sjb150015 {
12386139Sjb150015 	if (sv->sv_ksp) {
12396139Sjb150015 		kstat_delete(sv->sv_ksp);
12406139Sjb150015 		mutex_destroy(&sv->sv_ksp_mutex);
12416139Sjb150015 		sv->sv_ksp = NULL;
12426139Sjb150015 	}
12436139Sjb150015 	smb_dispatch_kstat_fini();
12446139Sjb150015 }
12456139Sjb150015 
12466139Sjb150015 /* ARGSUSED */
12476139Sjb150015 static int
12486139Sjb150015 smb_server_kstat_update_info(kstat_t *ksp, int rw)
12496139Sjb150015 {
12506139Sjb150015 	smb_server_t	*sv;
12516139Sjb150015 
12526139Sjb150015 	if (rw == KSTAT_WRITE) {
12536139Sjb150015 		return (EACCES);
12546139Sjb150015 	} else {
12556139Sjb150015 		ASSERT(MUTEX_HELD(ksp->ks_lock));
12566139Sjb150015 
12576139Sjb150015 		_NOTE(LINTED("pointer cast may result in improper alignment"))
12586139Sjb150015 		sv = (smb_server_t *)((uint8_t *)(ksp->ks_data) -
12596139Sjb150015 		    offsetof(smb_server_t, sv_ks_data));
12606139Sjb150015 
12616139Sjb150015 		ASSERT(sv->sv_magic == SMB_SERVER_MAGIC);
12626139Sjb150015 
12636139Sjb150015 		sv->sv_ks_data.open_files.value.ui32 = sv->sv_open_files;
12646139Sjb150015 		sv->sv_ks_data.open_trees.value.ui32 = sv->sv_open_trees;
12656139Sjb150015 		sv->sv_ks_data.open_users.value.ui32 = sv->sv_open_users;
12666139Sjb150015 	}
12676139Sjb150015 	return (0);
12686139Sjb150015 }
12696139Sjb150015 
12706139Sjb150015 /*
12716139Sjb150015  * smb_server_stop
12726139Sjb150015  *
12736139Sjb150015  * The mutex of the server must have been entered before calling this function.
12746139Sjb150015  */
12756139Sjb150015 static void
12766139Sjb150015 smb_server_stop(smb_server_t *sv)
12776139Sjb150015 {
12786139Sjb150015 	ASSERT(sv->sv_magic == SMB_SERVER_MAGIC);
12796139Sjb150015 
12807052Samw 	smb_opipe_door_close();
12816139Sjb150015 	smb_thread_stop(&sv->si_thread_timers);
12827619SJose.Borrego@Sun.COM 	smb_thread_stop(&sv->si_thread_unexport);
12837588Samw@Sun.COM 	smb_kdoor_clnt_close();
12846771Sjb150015 	smb_kshare_fini(sv->sv_lmshrd);
12856849Sjb150015 	sv->sv_lmshrd = NULL;
12866139Sjb150015 	smb_server_fsop_stop(sv);
12877588Samw@Sun.COM 
12886139Sjb150015 	if (sv->sv_session) {
12896139Sjb150015 		smb_session_delete(sv->sv_session);
12906139Sjb150015 		sv->sv_session = NULL;
12916139Sjb150015 	}
12927588Samw@Sun.COM 
12937588Samw@Sun.COM 	if (sv->sv_thread_pool) {
12947588Samw@Sun.COM 		taskq_destroy(sv->sv_thread_pool);
12957588Samw@Sun.COM 		sv->sv_thread_pool = NULL;
12967588Samw@Sun.COM 	}
12976139Sjb150015 }
12986139Sjb150015 
12996139Sjb150015 static int
13006139Sjb150015 smb_server_listen(
13016139Sjb150015     smb_server_t		*sv,
13026139Sjb150015     smb_listener_daemon_t	*ld,
13036139Sjb150015     in_port_t			port,
13048670SJose.Borrego@Sun.COM     int				family,
13056139Sjb150015     int				pthread_create_error)
13066139Sjb150015 {
13076139Sjb150015 	int			rc;
13088348SEric.Yu@Sun.COM 	ksocket_t		s_so;
13099021Samw@Sun.COM 	const uint32_t		on = 1;
13109021Samw@Sun.COM 	const uint32_t		off = 0;
13116139Sjb150015 	smb_session_t		*session;
13126139Sjb150015 
13136139Sjb150015 	if (pthread_create_error) {
13146139Sjb150015 		/*
13156139Sjb150015 		 * Delete the last session created. The user space thread
13166139Sjb150015 		 * creation failed.
13176139Sjb150015 		 */
13186139Sjb150015 		smb_session_list_delete_tail(&ld->ld_session_list);
13196139Sjb150015 	}
13206139Sjb150015 
13216139Sjb150015 	if (ld->ld_so == NULL) {
13226139Sjb150015 		/* First time listener */
13238670SJose.Borrego@Sun.COM 		if (family == AF_INET) {
13248670SJose.Borrego@Sun.COM 			ld->ld_sin.sin_family = (uint32_t)family;
13258670SJose.Borrego@Sun.COM 			ld->ld_sin.sin_port = htons(port);
13268670SJose.Borrego@Sun.COM 			ld->ld_sin.sin_addr.s_addr = htonl(INADDR_ANY);
13278670SJose.Borrego@Sun.COM 		} else {
13288670SJose.Borrego@Sun.COM 			ld->ld_sin6.sin6_family = (uint32_t)family;
13298670SJose.Borrego@Sun.COM 			ld->ld_sin6.sin6_port = htons(port);
13308670SJose.Borrego@Sun.COM 			(void) memset(&ld->ld_sin6.sin6_addr.s6_addr, 0,
13318670SJose.Borrego@Sun.COM 			    sizeof (ld->ld_sin6.sin6_addr.s6_addr));
13328670SJose.Borrego@Sun.COM 		}
13338670SJose.Borrego@Sun.COM 		ld->ld_so = smb_socreate(family, SOCK_STREAM, 0);
13346139Sjb150015 		if (ld->ld_so) {
13356139Sjb150015 
13368348SEric.Yu@Sun.COM 			(void) ksocket_setsockopt(ld->ld_so, SOL_SOCKET,
13379021Samw@Sun.COM 			    SO_MAC_EXEMPT, &off, sizeof (off), CRED());
13389021Samw@Sun.COM 			(void) ksocket_setsockopt(ld->ld_so, SOL_SOCKET,
13399021Samw@Sun.COM 			    SO_REUSEADDR, &on, sizeof (on), CRED());
13409021Samw@Sun.COM 
13418670SJose.Borrego@Sun.COM 			if (family == AF_INET) {
13428670SJose.Borrego@Sun.COM 				rc = ksocket_bind(ld->ld_so,
13438670SJose.Borrego@Sun.COM 				    (struct sockaddr *)&ld->ld_sin,
13448670SJose.Borrego@Sun.COM 				    sizeof (ld->ld_sin), CRED());
13458670SJose.Borrego@Sun.COM 			} else {
13468670SJose.Borrego@Sun.COM 				rc = ksocket_bind(ld->ld_so,
13478670SJose.Borrego@Sun.COM 				    (struct sockaddr *)&ld->ld_sin6,
13488670SJose.Borrego@Sun.COM 				    sizeof (ld->ld_sin6), CRED());
13498670SJose.Borrego@Sun.COM 			}
13506139Sjb150015 			if (rc == 0) {
13518348SEric.Yu@Sun.COM 				rc =  ksocket_listen(ld->ld_so, 20, CRED());
13526139Sjb150015 				if (rc < 0) {
13536139Sjb150015 					cmn_err(CE_WARN,
13546139Sjb150015 					    "Port %d: listen failed", port);
13556139Sjb150015 					smb_soshutdown(ld->ld_so);
13566139Sjb150015 					smb_sodestroy(ld->ld_so);
13576139Sjb150015 					ld->ld_so = NULL;
13586139Sjb150015 					return (rc);
13596139Sjb150015 				}
13606139Sjb150015 			} else {
13616139Sjb150015 				cmn_err(CE_WARN,
13626139Sjb150015 				    "Port %d: bind failed", port);
13636139Sjb150015 				smb_soshutdown(ld->ld_so);
13646139Sjb150015 				smb_sodestroy(ld->ld_so);
13656139Sjb150015 				ld->ld_so = NULL;
13666139Sjb150015 				return (rc);
13676139Sjb150015 			}
13686139Sjb150015 		} else {
13696139Sjb150015 			cmn_err(CE_WARN,
13706139Sjb150015 			    "Port %d: socket create failed", port);
13716139Sjb150015 			return (ENOMEM);
13726139Sjb150015 		}
13736139Sjb150015 	}
13746139Sjb150015 
13756139Sjb150015 	DTRACE_PROBE1(so__wait__accept, struct sonode *, ld->ld_so);
13766139Sjb150015 
13776139Sjb150015 	for (;;) {
13788348SEric.Yu@Sun.COM 		rc = ksocket_accept(ld->ld_so, NULL, NULL, &s_so, CRED());
13796139Sjb150015 		if (rc == 0) {
13806139Sjb150015 			uint32_t	txbuf_size = 128*1024;
13816139Sjb150015 			uint32_t	on = 1;
13826139Sjb150015 
13836139Sjb150015 			DTRACE_PROBE1(so__accept, struct sonode *, s_so);
13846139Sjb150015 
13858348SEric.Yu@Sun.COM 			(void) ksocket_setsockopt(s_so, IPPROTO_TCP,
13869021Samw@Sun.COM 			    TCP_NODELAY, &on, sizeof (on), CRED());
13878348SEric.Yu@Sun.COM 			(void) ksocket_setsockopt(s_so, SOL_SOCKET,
13889021Samw@Sun.COM 			    SO_KEEPALIVE, &on, sizeof (on), CRED());
13898348SEric.Yu@Sun.COM 			(void) ksocket_setsockopt(s_so, SOL_SOCKET, SO_SNDBUF,
13908348SEric.Yu@Sun.COM 			    (const void *)&txbuf_size, sizeof (txbuf_size),
13918348SEric.Yu@Sun.COM 			    CRED());
13926139Sjb150015 			/*
13936139Sjb150015 			 * Create a session for this connection.
13946139Sjb150015 			 */
13958670SJose.Borrego@Sun.COM 			session = smb_session_create(s_so, port, sv, family);
13966139Sjb150015 			if (session) {
13976139Sjb150015 				smb_session_list_append(&ld->ld_session_list,
13986139Sjb150015 				    session);
13996139Sjb150015 				break;
14006139Sjb150015 			} else {
14016139Sjb150015 				smb_soshutdown(s_so);
14026139Sjb150015 				smb_sodestroy(s_so);
14036139Sjb150015 			}
14046139Sjb150015 			continue;
14056139Sjb150015 		}
14066139Sjb150015 		smb_session_list_signal(&ld->ld_session_list);
14076139Sjb150015 		smb_soshutdown(ld->ld_so);
14086139Sjb150015 		smb_sodestroy(ld->ld_so);
14096139Sjb150015 		ld->ld_so = NULL;
14106139Sjb150015 		break;
14116139Sjb150015 	}
14126139Sjb150015 
14136139Sjb150015 	return (rc);
14146139Sjb150015 }
14156139Sjb150015 
14166139Sjb150015 /*
14176139Sjb150015  * smb_server_lookup
14186139Sjb150015  *
14196139Sjb150015  * This function tries to find the server associated with the zone of the
14206139Sjb150015  * caller.
14216139Sjb150015  */
14226139Sjb150015 static int
14236139Sjb150015 smb_server_lookup(smb_server_t **psv)
14246139Sjb150015 {
14256139Sjb150015 	zoneid_t	zid;
14266139Sjb150015 	smb_server_t	*sv;
14276139Sjb150015 
14286139Sjb150015 	zid = getzoneid();
14296139Sjb150015 
14306139Sjb150015 	smb_llist_enter(&smb_servers, RW_READER);
14316139Sjb150015 	sv = smb_llist_head(&smb_servers);
14326139Sjb150015 	while (sv) {
14336139Sjb150015 		ASSERT(sv->sv_magic == SMB_SERVER_MAGIC);
14346139Sjb150015 		if (sv->sv_zid == zid) {
14356139Sjb150015 			mutex_enter(&sv->sv_mutex);
14366139Sjb150015 			if (sv->sv_state != SMB_SERVER_STATE_DELETING) {
14376139Sjb150015 				sv->sv_refcnt++;
14386139Sjb150015 				mutex_exit(&sv->sv_mutex);
14396139Sjb150015 				smb_llist_exit(&smb_servers);
14406139Sjb150015 				*psv = sv;
14416139Sjb150015 				return (0);
14426139Sjb150015 			}
14436139Sjb150015 			mutex_exit(&sv->sv_mutex);
14446139Sjb150015 			break;
14456139Sjb150015 		}
14466139Sjb150015 		sv = smb_llist_next(&smb_servers, sv);
14476139Sjb150015 	}
14486139Sjb150015 	smb_llist_exit(&smb_servers);
14496139Sjb150015 	return (EPERM);
14506139Sjb150015 }
14516139Sjb150015 
14526139Sjb150015 /*
14536139Sjb150015  * smb_server_release
14546139Sjb150015  *
14556139Sjb150015  * This function decrements the reference count of the server and signals its
14566139Sjb150015  * condition variable if the state of the server is SMB_SERVER_STATE_DELETING.
14576139Sjb150015  */
14586139Sjb150015 static void
14596139Sjb150015 smb_server_release(smb_server_t *sv)
14606139Sjb150015 {
14616139Sjb150015 	ASSERT(sv->sv_magic == SMB_SERVER_MAGIC);
14626139Sjb150015 
14636139Sjb150015 	mutex_enter(&sv->sv_mutex);
14646139Sjb150015 	ASSERT(sv->sv_refcnt);
14656139Sjb150015 	sv->sv_refcnt--;
14666139Sjb150015 	if ((sv->sv_refcnt == 0) && (sv->sv_state == SMB_SERVER_STATE_DELETING))
14676139Sjb150015 		cv_signal(&sv->sv_cv);
14686139Sjb150015 	mutex_exit(&sv->sv_mutex);
14696139Sjb150015 }
14706139Sjb150015 
147110122SJordan.Brown@Sun.COM /*
147210122SJordan.Brown@Sun.COM  * Enumerate the users associated with a session list.
147310122SJordan.Brown@Sun.COM  */
147410122SJordan.Brown@Sun.COM static void
147510122SJordan.Brown@Sun.COM smb_server_enum_private(smb_session_list_t *se, smb_svcenum_t *svcenum)
14766139Sjb150015 {
147710122SJordan.Brown@Sun.COM 	smb_session_t	*sn;
147810122SJordan.Brown@Sun.COM 	smb_llist_t	*ulist;
147910122SJordan.Brown@Sun.COM 	smb_user_t	*user;
148010122SJordan.Brown@Sun.COM 	int		rc = 0;
14816139Sjb150015 
14826139Sjb150015 	rw_enter(&se->se_lock, RW_READER);
14836139Sjb150015 	sn = list_head(&se->se_act.lst);
148410122SJordan.Brown@Sun.COM 
148510122SJordan.Brown@Sun.COM 	while (sn != NULL) {
14866139Sjb150015 		ASSERT(sn->s_magic == SMB_SESSION_MAGIC);
14876139Sjb150015 		ulist = &sn->s_user_list;
14886139Sjb150015 		smb_llist_enter(ulist, RW_READER);
14896139Sjb150015 		user = smb_llist_head(ulist);
149010122SJordan.Brown@Sun.COM 
149110122SJordan.Brown@Sun.COM 		while (user != NULL) {
149210122SJordan.Brown@Sun.COM 			if (smb_user_hold(user)) {
149310122SJordan.Brown@Sun.COM 				rc = smb_user_enum(user, svcenum);
149410122SJordan.Brown@Sun.COM 				smb_user_release(user);
149510122SJordan.Brown@Sun.COM 			}
149610122SJordan.Brown@Sun.COM 
149710122SJordan.Brown@Sun.COM 			user = smb_llist_next(ulist, user);
149810122SJordan.Brown@Sun.COM 		}
149910122SJordan.Brown@Sun.COM 
150010122SJordan.Brown@Sun.COM 		smb_llist_exit(ulist);
150110122SJordan.Brown@Sun.COM 
150210122SJordan.Brown@Sun.COM 		if (rc != 0)
150310122SJordan.Brown@Sun.COM 			break;
150410122SJordan.Brown@Sun.COM 
150510122SJordan.Brown@Sun.COM 		sn = list_next(&se->se_act.lst, sn);
150610122SJordan.Brown@Sun.COM 	}
150710122SJordan.Brown@Sun.COM 
150810122SJordan.Brown@Sun.COM 	rw_exit(&se->se_lock);
150910122SJordan.Brown@Sun.COM }
151010122SJordan.Brown@Sun.COM 
151110122SJordan.Brown@Sun.COM /*
151210122SJordan.Brown@Sun.COM  * Disconnect sessions associated with the specified client and username.
151310122SJordan.Brown@Sun.COM  * Empty strings are treated as wildcards.
151410122SJordan.Brown@Sun.COM  */
151510122SJordan.Brown@Sun.COM static int
151610122SJordan.Brown@Sun.COM smb_server_sesion_disconnect(smb_session_list_t *se,
151710122SJordan.Brown@Sun.COM     const char *client, const char *name)
151810122SJordan.Brown@Sun.COM {
151910122SJordan.Brown@Sun.COM 	smb_session_t	*sn;
152010122SJordan.Brown@Sun.COM 	smb_llist_t	*ulist;
152110122SJordan.Brown@Sun.COM 	smb_user_t	*user;
152210122SJordan.Brown@Sun.COM 	boolean_t	match;
152310122SJordan.Brown@Sun.COM 	int		count = 0;
152410122SJordan.Brown@Sun.COM 
152510122SJordan.Brown@Sun.COM 	rw_enter(&se->se_lock, RW_READER);
152610122SJordan.Brown@Sun.COM 	sn = list_head(&se->se_act.lst);
152710122SJordan.Brown@Sun.COM 
152810122SJordan.Brown@Sun.COM 	while (sn != NULL) {
152910122SJordan.Brown@Sun.COM 		ASSERT(sn->s_magic == SMB_SESSION_MAGIC);
153010122SJordan.Brown@Sun.COM 
153110122SJordan.Brown@Sun.COM 		if ((*client != '\0') && (!smb_session_isclient(sn, client))) {
153210122SJordan.Brown@Sun.COM 			sn = list_next(&se->se_act.lst, sn);
153310122SJordan.Brown@Sun.COM 			continue;
153410122SJordan.Brown@Sun.COM 		}
153510122SJordan.Brown@Sun.COM 
153610122SJordan.Brown@Sun.COM 		ulist = &sn->s_user_list;
153710122SJordan.Brown@Sun.COM 		smb_llist_enter(ulist, RW_READER);
153810122SJordan.Brown@Sun.COM 		user = smb_llist_head(ulist);
153910122SJordan.Brown@Sun.COM 
154010122SJordan.Brown@Sun.COM 		while (user != NULL) {
154110122SJordan.Brown@Sun.COM 			if (smb_user_hold(user)) {
154210122SJordan.Brown@Sun.COM 				match = (*name == '\0');
154310122SJordan.Brown@Sun.COM 				if (!match)
154410122SJordan.Brown@Sun.COM 					match = smb_user_namecmp(user, name);
154510122SJordan.Brown@Sun.COM 
154610122SJordan.Brown@Sun.COM 				if (match) {
154710122SJordan.Brown@Sun.COM 					smb_llist_exit(ulist);
154810122SJordan.Brown@Sun.COM 					smb_user_logoff(user);
154910122SJordan.Brown@Sun.COM 					++count;
155010122SJordan.Brown@Sun.COM 					smb_user_release(user);
155110122SJordan.Brown@Sun.COM 					smb_llist_enter(ulist, RW_READER);
155210122SJordan.Brown@Sun.COM 					user = smb_llist_head(ulist);
155310122SJordan.Brown@Sun.COM 					continue;
15546139Sjb150015 				}
155510122SJordan.Brown@Sun.COM 
155610122SJordan.Brown@Sun.COM 				smb_user_release(user);
15576139Sjb150015 			}
155810122SJordan.Brown@Sun.COM 
15596139Sjb150015 			user = smb_llist_next(ulist, user);
15606139Sjb150015 		}
156110122SJordan.Brown@Sun.COM 
15626139Sjb150015 		smb_llist_exit(ulist);
15637961SNatalie.Li@Sun.COM 		sn = list_next(&se->se_act.lst, sn);
15646139Sjb150015 	}
156510122SJordan.Brown@Sun.COM 
15666139Sjb150015 	rw_exit(&se->se_lock);
156710122SJordan.Brown@Sun.COM 	return (count);
156810122SJordan.Brown@Sun.COM }
156910122SJordan.Brown@Sun.COM 
157010122SJordan.Brown@Sun.COM /*
157110122SJordan.Brown@Sun.COM  * Close a file by its unique id.
157210122SJordan.Brown@Sun.COM  */
157310122SJordan.Brown@Sun.COM static int
157410122SJordan.Brown@Sun.COM smb_server_fclose(smb_session_list_t *se, uint32_t uniqid)
157510122SJordan.Brown@Sun.COM {
157610122SJordan.Brown@Sun.COM 	smb_session_t	*sn;
157710122SJordan.Brown@Sun.COM 	smb_llist_t	*ulist;
157810122SJordan.Brown@Sun.COM 	smb_user_t	*user;
157910122SJordan.Brown@Sun.COM 	int		rc = ENOENT;
158010122SJordan.Brown@Sun.COM 
158110122SJordan.Brown@Sun.COM 	rw_enter(&se->se_lock, RW_READER);
158210122SJordan.Brown@Sun.COM 	sn = list_head(&se->se_act.lst);
158310122SJordan.Brown@Sun.COM 
158410122SJordan.Brown@Sun.COM 	while ((sn != NULL) && (rc == ENOENT)) {
158510122SJordan.Brown@Sun.COM 		ASSERT(sn->s_magic == SMB_SESSION_MAGIC);
158610122SJordan.Brown@Sun.COM 		ulist = &sn->s_user_list;
158710122SJordan.Brown@Sun.COM 		smb_llist_enter(ulist, RW_READER);
158810122SJordan.Brown@Sun.COM 		user = smb_llist_head(ulist);
158910122SJordan.Brown@Sun.COM 
159010122SJordan.Brown@Sun.COM 		while ((user != NULL) && (rc == ENOENT)) {
159110122SJordan.Brown@Sun.COM 			if (smb_user_hold(user)) {
159210122SJordan.Brown@Sun.COM 				rc = smb_user_fclose(user, uniqid);
159310122SJordan.Brown@Sun.COM 				smb_user_release(user);
159410122SJordan.Brown@Sun.COM 			}
159510122SJordan.Brown@Sun.COM 
159610122SJordan.Brown@Sun.COM 			user = smb_llist_next(ulist, user);
159710122SJordan.Brown@Sun.COM 		}
159810122SJordan.Brown@Sun.COM 
159910122SJordan.Brown@Sun.COM 		smb_llist_exit(ulist);
160010122SJordan.Brown@Sun.COM 		sn = list_next(&se->se_act.lst, sn);
160110122SJordan.Brown@Sun.COM 	}
160210122SJordan.Brown@Sun.COM 
160310122SJordan.Brown@Sun.COM 	rw_exit(&se->se_lock);
160410122SJordan.Brown@Sun.COM 	return (rc);
16056139Sjb150015 }
16066139Sjb150015 
16076139Sjb150015 static void
16089832Samw@Sun.COM smb_server_store_cfg(smb_server_t *sv, smb_ioc_cfg_t *ioc)
16096139Sjb150015 {
16109832Samw@Sun.COM 	if (ioc->maxconnections == 0)
16119832Samw@Sun.COM 		ioc->maxconnections = 0xFFFFFFFF;
16126139Sjb150015 
16136139Sjb150015 	smb_session_correct_keep_alive_values(
16149832Samw@Sun.COM 	    &sv->sv_nbt_daemon.ld_session_list, ioc->keepalive);
16156139Sjb150015 	smb_session_correct_keep_alive_values(
16169832Samw@Sun.COM 	    &sv->sv_tcp_daemon.ld_session_list, ioc->keepalive);
16176139Sjb150015 
16189832Samw@Sun.COM 	sv->sv_cfg.skc_maxworkers = ioc->maxworkers;
16199832Samw@Sun.COM 	sv->sv_cfg.skc_maxconnections = ioc->maxconnections;
16209832Samw@Sun.COM 	sv->sv_cfg.skc_keepalive = ioc->keepalive;
16219832Samw@Sun.COM 	sv->sv_cfg.skc_restrict_anon = ioc->restrict_anon;
16229832Samw@Sun.COM 	sv->sv_cfg.skc_signing_enable = ioc->signing_enable;
16239832Samw@Sun.COM 	sv->sv_cfg.skc_signing_required = ioc->signing_required;
16249832Samw@Sun.COM 	sv->sv_cfg.skc_oplock_enable = ioc->oplock_enable;
16259832Samw@Sun.COM 	sv->sv_cfg.skc_sync_enable = ioc->sync_enable;
16269832Samw@Sun.COM 	sv->sv_cfg.skc_secmode = ioc->secmode;
16279832Samw@Sun.COM 	sv->sv_cfg.skc_ipv6_enable = ioc->ipv6_enable;
16289832Samw@Sun.COM 	(void) strlcpy(sv->sv_cfg.skc_nbdomain, ioc->nbdomain,
16299832Samw@Sun.COM 	    sizeof (sv->sv_cfg.skc_nbdomain));
16309832Samw@Sun.COM 	(void) strlcpy(sv->sv_cfg.skc_fqdn, ioc->fqdn,
16319832Samw@Sun.COM 	    sizeof (sv->sv_cfg.skc_fqdn));
16329832Samw@Sun.COM 	(void) strlcpy(sv->sv_cfg.skc_hostname, ioc->hostname,
16339832Samw@Sun.COM 	    sizeof (sv->sv_cfg.skc_hostname));
16349832Samw@Sun.COM 	(void) strlcpy(sv->sv_cfg.skc_system_comment, ioc->system_comment,
16359832Samw@Sun.COM 	    sizeof (sv->sv_cfg.skc_system_comment));
16366139Sjb150015 }
16376139Sjb150015 
16386139Sjb150015 static int
16396139Sjb150015 smb_server_fsop_start(smb_server_t *sv)
16406139Sjb150015 {
16416139Sjb150015 	int	error;
16426139Sjb150015 
16436139Sjb150015 	error = smb_node_root_init(rootdir, sv, &sv->si_root_smb_node);
16446139Sjb150015 	if (error != 0)
16456139Sjb150015 		sv->si_root_smb_node = NULL;
16466139Sjb150015 
16476139Sjb150015 	return (error);
16486139Sjb150015 }
16496139Sjb150015 
16506139Sjb150015 static void
16516139Sjb150015 smb_server_fsop_stop(smb_server_t *sv)
16526139Sjb150015 {
16536139Sjb150015 	if (sv->si_root_smb_node != NULL) {
16546139Sjb150015 		smb_vfs_rele_all(sv);
16556139Sjb150015 		smb_node_release(sv->si_root_smb_node);
16566139Sjb150015 		sv->si_root_smb_node = NULL;
16576139Sjb150015 	}
16586139Sjb150015 }
1659