1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* 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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright 2013 Nexenta Systems, Inc. All rights reserved.
*/
#include <sys/vfs.h>
#include <smbsrv/smb_ktypes.h>
#include <smbsrv/smb_kproto.h>
static smb_vfs_t *smb_vfs_find(smb_export_t *, vfs_t *);
static void smb_vfs_destroy(smb_vfs_t *);
/*
* If a hold on the specified VFS has already been taken
* then only increment the reference count of the corresponding
* smb_vfs_t structure. If no smb_vfs_t structure has been created
* yet for the specified VFS then create one and take a hold on
* the VFS.
*/
int
smb_vfs_hold(smb_export_t *se, vfs_t *vfsp)
{
smb_vfs_t *smb_vfs;
vnode_t *rootvp;
int rc;
if (se == NULL || vfsp == NULL)
return (EINVAL);
smb_llist_enter(&se->e_vfs_list, RW_WRITER);
if ((smb_vfs = smb_vfs_find(se, vfsp)) != NULL) {
smb_vfs->sv_refcnt++;
DTRACE_PROBE1(smb_vfs_hold_hit, smb_vfs_t *, smb_vfs);
smb_llist_exit(&se->e_vfs_list);
return (0);
}
if ((rc = VFS_ROOT(vfsp, &rootvp)) != 0) {
smb_llist_exit(&se->e_vfs_list);
return (rc);
}
smb_vfs = kmem_cache_alloc(smb_kshare_cache_vfs, KM_SLEEP);
bzero(smb_vfs, sizeof (smb_vfs_t));
smb_vfs->sv_magic = SMB_VFS_MAGIC;
smb_vfs->sv_refcnt = 1;
smb_vfs->sv_vfsp = vfsp;
/*
* We have a hold on the root vnode of the file system
* from the VFS_ROOT call above.
*/
smb_vfs->sv_rootvp = rootvp;
smb_llist_insert_head(&se->e_vfs_list, smb_vfs);
DTRACE_PROBE1(smb_vfs_hold_miss, smb_vfs_t *, smb_vfs);
smb_llist_exit(&se->e_vfs_list);
return (0);
}
/*
* smb_vfs_rele
*
* Decrements the reference count of the fs passed in. If the reference count
* drops to zero the smb_vfs_t structure associated with the fs is freed.
*/
void
smb_vfs_rele(smb_export_t *se, vfs_t *vfsp)
{
smb_vfs_t *smb_vfs;
ASSERT(vfsp);
smb_llist_enter(&se->e_vfs_list, RW_WRITER);
smb_vfs = smb_vfs_find(se, vfsp);
DTRACE_PROBE1(smb_vfs_release, smb_vfs_t *, smb_vfs);
if (smb_vfs) {
ASSERT(smb_vfs->sv_refcnt);
if (--smb_vfs->sv_refcnt == 0) {
smb_llist_remove(&se->e_vfs_list, smb_vfs);
smb_llist_exit(&se->e_vfs_list);
smb_vfs_destroy(smb_vfs);
return;
}
}
smb_llist_exit(&se->e_vfs_list);
}
/*
* smb_vfs_rele_all()
*
* Release all holds on root vnodes of file systems which were taken
* due to the existence of at least one enabled share on the file system.
* Called at driver close time.
*/
void
smb_vfs_rele_all(smb_export_t *se)
{
smb_vfs_t *smb_vfs;
smb_llist_enter(&se->e_vfs_list, RW_WRITER);
while ((smb_vfs = smb_llist_head(&se->e_vfs_list)) != NULL) {
ASSERT(smb_vfs->sv_magic == SMB_VFS_MAGIC);
DTRACE_PROBE1(smb_vfs_rele_all_hit, smb_vfs_t *, smb_vfs);
smb_llist_remove(&se->e_vfs_list, smb_vfs);
smb_vfs_destroy(smb_vfs);
}
smb_llist_exit(&se->e_vfs_list);
}
/*
* Goes through the list of smb_vfs_t structure and returns the one matching
* the vnode passed in. If no match is found a NULL pointer is returned.
*
* The list of smb_vfs_t structures has to have been entered prior calling
* this function.
*/
static smb_vfs_t *
smb_vfs_find(smb_export_t *se, vfs_t *vfsp)
{
smb_vfs_t *smb_vfs;
smb_vfs = smb_llist_head(&se->e_vfs_list);
while (smb_vfs) {
ASSERT(smb_vfs->sv_magic == SMB_VFS_MAGIC);
if (smb_vfs->sv_vfsp == vfsp)
return (smb_vfs);
smb_vfs = smb_llist_next(&se->e_vfs_list, smb_vfs);
}
return (NULL);
}
static void
smb_vfs_destroy(smb_vfs_t *smb_vfs)
{
VN_RELE(smb_vfs->sv_rootvp);
smb_vfs->sv_magic = (uint32_t)~SMB_VFS_MAGIC;
kmem_cache_free(smb_kshare_cache_vfs, smb_vfs);
}
|