4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
27 #include <smbsrv/smb_ktypes.h>
28 #include <smbsrv/smb_kproto.h>
30 static smb_vfs_t
*smb_vfs_find(smb_export_t
*, vfs_t
*);
31 static void smb_vfs_destroy(smb_vfs_t
*);
34 * If a hold on the specified VFS has already been taken
35 * then only increment the reference count of the corresponding
36 * smb_vfs_t structure. If no smb_vfs_t structure has been created
37 * yet for the specified VFS then create one and take a hold on
41 smb_vfs_hold(smb_export_t
*se
, vfs_t
*vfsp
)
47 if (se
== NULL
|| vfsp
== NULL
)
50 smb_llist_enter(&se
->e_vfs_list
, RW_WRITER
);
52 if ((smb_vfs
= smb_vfs_find(se
, vfsp
)) != NULL
) {
54 DTRACE_PROBE1(smb_vfs_hold_hit
, smb_vfs_t
*, smb_vfs
);
55 smb_llist_exit(&se
->e_vfs_list
);
59 if ((rc
= VFS_ROOT(vfsp
, &rootvp
)) != 0) {
60 smb_llist_exit(&se
->e_vfs_list
);
64 smb_vfs
= kmem_cache_alloc(smb_kshare_cache_vfs
, KM_SLEEP
);
66 bzero(smb_vfs
, sizeof (smb_vfs_t
));
68 smb_vfs
->sv_magic
= SMB_VFS_MAGIC
;
69 smb_vfs
->sv_refcnt
= 1;
70 smb_vfs
->sv_vfsp
= vfsp
;
72 * We have a hold on the root vnode of the file system
73 * from the VFS_ROOT call above.
75 smb_vfs
->sv_rootvp
= rootvp
;
77 smb_llist_insert_head(&se
->e_vfs_list
, smb_vfs
);
78 DTRACE_PROBE1(smb_vfs_hold_miss
, smb_vfs_t
*, smb_vfs
);
79 smb_llist_exit(&se
->e_vfs_list
);
87 * Decrements the reference count of the fs passed in. If the reference count
88 * drops to zero the smb_vfs_t structure associated with the fs is freed.
91 smb_vfs_rele(smb_export_t
*se
, vfs_t
*vfsp
)
97 smb_llist_enter(&se
->e_vfs_list
, RW_WRITER
);
98 smb_vfs
= smb_vfs_find(se
, vfsp
);
99 DTRACE_PROBE1(smb_vfs_release
, smb_vfs_t
*, smb_vfs
);
101 ASSERT(smb_vfs
->sv_refcnt
);
102 if (--smb_vfs
->sv_refcnt
== 0) {
103 smb_llist_remove(&se
->e_vfs_list
, smb_vfs
);
104 smb_llist_exit(&se
->e_vfs_list
);
105 smb_vfs_destroy(smb_vfs
);
109 smb_llist_exit(&se
->e_vfs_list
);
115 * Release all holds on root vnodes of file systems which were taken
116 * due to the existence of at least one enabled share on the file system.
117 * Called at driver close time.
120 smb_vfs_rele_all(smb_export_t
*se
)
124 smb_llist_enter(&se
->e_vfs_list
, RW_WRITER
);
125 while ((smb_vfs
= smb_llist_head(&se
->e_vfs_list
)) != NULL
) {
127 ASSERT(smb_vfs
->sv_magic
== SMB_VFS_MAGIC
);
128 DTRACE_PROBE1(smb_vfs_rele_all_hit
, smb_vfs_t
*, smb_vfs
);
129 smb_llist_remove(&se
->e_vfs_list
, smb_vfs
);
130 smb_vfs_destroy(smb_vfs
);
132 smb_llist_exit(&se
->e_vfs_list
);
136 * Goes through the list of smb_vfs_t structure and returns the one matching
137 * the vnode passed in. If no match is found a NULL pointer is returned.
139 * The list of smb_vfs_t structures has to have been entered prior calling
143 smb_vfs_find(smb_export_t
*se
, vfs_t
*vfsp
)
147 smb_vfs
= smb_llist_head(&se
->e_vfs_list
);
149 ASSERT(smb_vfs
->sv_magic
== SMB_VFS_MAGIC
);
150 if (smb_vfs
->sv_vfsp
== vfsp
)
152 smb_vfs
= smb_llist_next(&se
->e_vfs_list
, smb_vfs
);
159 smb_vfs_destroy(smb_vfs_t
*smb_vfs
)
161 VN_RELE(smb_vfs
->sv_rootvp
);
162 smb_vfs
->sv_magic
= (uint32_t)~SMB_VFS_MAGIC
;
163 kmem_cache_free(smb_kshare_cache_vfs
, smb_vfs
);