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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* 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 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
* A few excerpts from smb_kutil.c
*/
#include <sys/param.h>
#include <sys/types.h>
#include <sys/atomic.h>
#include <sys/debug.h>
#include <sys/time.h>
#include <sys/stddef.h>
#include <smbsrv/smb_kproto.h>
/*
* smb_llist_constructor
*
* This function initializes a locked list.
*/
void
smb_llist_constructor(
smb_llist_t *ll,
size_t size,
size_t offset)
{
rw_init(&ll->ll_lock, NULL, RW_DEFAULT, NULL);
mutex_init(&ll->ll_mutex, NULL, MUTEX_DEFAULT, NULL);
list_create(&ll->ll_list, size, offset);
list_create(&ll->ll_deleteq, sizeof (smb_dtor_t),
offsetof(smb_dtor_t, dt_lnd));
ll->ll_count = 0;
ll->ll_wrop = 0;
ll->ll_deleteq_count = 0;
ll->ll_flushing = B_FALSE;
}
/*
* Flush the delete queue and destroy a locked list.
*/
void
smb_llist_destructor(
smb_llist_t *ll)
{
/* smb_llist_flush(ll); */
ASSERT(ll->ll_count == 0);
ASSERT(ll->ll_deleteq_count == 0);
rw_destroy(&ll->ll_lock);
list_destroy(&ll->ll_list);
list_destroy(&ll->ll_deleteq);
mutex_destroy(&ll->ll_mutex);
}
void
smb_llist_enter(smb_llist_t *ll, krw_t mode)
{
rw_enter(&ll->ll_lock, mode);
}
/*
* Exit the list lock and process the delete queue.
*/
void
smb_llist_exit(smb_llist_t *ll)
{
rw_exit(&ll->ll_lock);
/* smb_llist_flush(ll); */
}
/*
* smb_llist_upgrade
*
* This function tries to upgrade the lock of the locked list. It assumes the
* locked has already been entered in RW_READER mode. It first tries using the
* Solaris function rw_tryupgrade(). If that call fails the lock is released
* and reentered in RW_WRITER mode. In that last case a window is opened during
* which the contents of the list may have changed. The return code indicates
* whether or not the list was modified when the lock was exited.
*/
int smb_llist_upgrade(
smb_llist_t *ll)
{
uint64_t wrop;
if (rw_tryupgrade(&ll->ll_lock) != 0) {
return (0);
}
wrop = ll->ll_wrop;
rw_exit(&ll->ll_lock);
rw_enter(&ll->ll_lock, RW_WRITER);
return (wrop != ll->ll_wrop);
}
/*
* smb_llist_insert_head
*
* This function inserts the object passed a the beginning of the list. This
* function assumes the lock of the list has already been entered.
*/
void
smb_llist_insert_head(
smb_llist_t *ll,
void *obj)
{
list_insert_head(&ll->ll_list, obj);
++ll->ll_wrop;
++ll->ll_count;
}
/*
* smb_llist_insert_tail
*
* This function appends to the object passed to the list. This function assumes
* the lock of the list has already been entered.
*
*/
void
smb_llist_insert_tail(
smb_llist_t *ll,
void *obj)
{
list_insert_tail(&ll->ll_list, obj);
++ll->ll_wrop;
++ll->ll_count;
}
/*
* smb_llist_remove
*
* This function removes the object passed from the list. This function assumes
* the lock of the list has already been entered.
*/
void
smb_llist_remove(
smb_llist_t *ll,
void *obj)
{
list_remove(&ll->ll_list, obj);
++ll->ll_wrop;
--ll->ll_count;
}
/*
* smb_llist_get_count
*
* This function returns the number of elements in the specified list.
*/
uint32_t
smb_llist_get_count(
smb_llist_t *ll)
{
return (ll->ll_count);
}
|