File: | xlators/features/locks/src/clear.c |
Location: | line 248, column 9 |
Description: | The left operand of '-' is a garbage value |
1 | /* | |||||
2 | Copyright (c) 2006-2012 Red Hat, Inc. <http://www.redhat.com> | |||||
3 | This file is part of GlusterFS. | |||||
4 | ||||||
5 | This file is licensed to you under your choice of the GNU Lesser | |||||
6 | General Public License, version 3 or any later version (LGPLv3 or | |||||
7 | later), or the GNU General Public License, version 2 (GPLv2), in all | |||||
8 | cases as published by the Free Software Foundation. | |||||
9 | */ | |||||
10 | #include <unistd.h> | |||||
11 | #include <fcntl.h> | |||||
12 | #include <limits.h> | |||||
13 | #include <pthread.h> | |||||
14 | ||||||
15 | #ifndef _CONFIG_H | |||||
16 | #define _CONFIG_H | |||||
17 | #include "config.h" | |||||
18 | #endif | |||||
19 | ||||||
20 | #include "glusterfs.h" | |||||
21 | #include "compat.h" | |||||
22 | #include "xlator.h" | |||||
23 | #include "inode.h" | |||||
24 | #include "logging.h" | |||||
25 | #include "common-utils.h" | |||||
26 | ||||||
27 | #include "locks.h" | |||||
28 | #include "common.h" | |||||
29 | #include "statedump.h" | |||||
30 | #include "clear.h" | |||||
31 | ||||||
32 | int | |||||
33 | clrlk_get_kind (char *kind) | |||||
34 | { | |||||
35 | char *clrlk_kinds[CLRLK_KIND_MAX] = {"dummy", "blocked", "granted", | |||||
36 | "all"}; | |||||
37 | int ret_kind = CLRLK_KIND_MAX; | |||||
38 | int i = 0; | |||||
39 | ||||||
40 | for (i = CLRLK_BLOCKED; i < CLRLK_KIND_MAX; i++) { | |||||
41 | if (!strcmp (clrlk_kinds[i], kind)) { | |||||
42 | ret_kind = i; | |||||
43 | break; | |||||
44 | } | |||||
45 | } | |||||
46 | ||||||
47 | return ret_kind; | |||||
48 | } | |||||
49 | ||||||
50 | int | |||||
51 | clrlk_get_type (char *type) | |||||
52 | { | |||||
53 | char *clrlk_types[CLRLK_TYPE_MAX] = {"inode", "entry", "posix"}; | |||||
54 | int ret_type = CLRLK_TYPE_MAX; | |||||
55 | int i = 0; | |||||
56 | ||||||
57 | for (i = CLRLK_INODE; i < CLRLK_TYPE_MAX; i++) { | |||||
58 | if (!strcmp (clrlk_types[i], type)) { | |||||
59 | ret_type = i; | |||||
60 | break; | |||||
61 | } | |||||
62 | } | |||||
63 | ||||||
64 | return ret_type; | |||||
65 | } | |||||
66 | ||||||
67 | int | |||||
68 | clrlk_get_lock_range (char *range_str, struct gf_flock *ulock, | |||||
69 | gf_boolean_t *chk_range) | |||||
70 | { | |||||
71 | int ret = -1; | |||||
72 | ||||||
73 | if (!chk_range) | |||||
74 | goto out; | |||||
75 | ||||||
76 | if (!range_str) { | |||||
77 | ret = 0; | |||||
78 | *chk_range = _gf_false; | |||||
79 | goto out; | |||||
80 | } | |||||
81 | ||||||
82 | if (sscanf (range_str, "%hd,%"PRId64"ll" "d""-""%"PRId64"ll" "d", &ulock->l_whence, | |||||
83 | &ulock->l_start, &ulock->l_len) != 3) { | |||||
84 | goto out; | |||||
85 | } | |||||
86 | ||||||
87 | ret = 0; | |||||
88 | *chk_range = _gf_true; | |||||
89 | out: | |||||
90 | return ret; | |||||
91 | } | |||||
92 | ||||||
93 | int | |||||
94 | clrlk_parse_args (const char* cmd, clrlk_args *args) | |||||
95 | { | |||||
96 | char *opts = NULL((void*)0); | |||||
97 | char *cur = NULL((void*)0); | |||||
98 | char *tok = NULL((void*)0); | |||||
99 | char *sptr = NULL((void*)0); | |||||
100 | char *free_ptr = NULL((void*)0); | |||||
101 | char kw[KW_MAX] = {[KW_TYPE] = 't', | |||||
102 | [KW_KIND] = 'k', | |||||
103 | }; | |||||
104 | int ret = -1; | |||||
105 | int i = 0; | |||||
106 | ||||||
107 | GF_ASSERT (cmd)do { if (!(cmd)) { do { do { if (0) printf ("Assertion failed: " "cmd"); } while (0); _gf_log_callingfn ("", "clear.c", __FUNCTION__ , 107, GF_LOG_ERROR, "Assertion failed: " "cmd"); } while (0) ; } } while (0); | |||||
108 | free_ptr = opts = GF_CALLOC (1, strlen (cmd), gf_common_mt_char)__gf_calloc (1, strlen (cmd), gf_common_mt_char); | |||||
109 | if (!opts) | |||||
110 | goto out; | |||||
111 | ||||||
112 | if (sscanf (cmd, GF_XATTR_CLRLK_CMD"glusterfs.clrlk"".%s", opts) < 1) { | |||||
113 | ret = -1; | |||||
114 | goto out; | |||||
115 | } | |||||
116 | ||||||
117 | /*clr_lk_prefix.ttype.kkind.args, args - type specific*/ | |||||
118 | cur = opts; | |||||
119 | for (i = 0; i < KW_MAX && (tok = strtok_r (cur, ".", &sptr)); | |||||
120 | cur = NULL((void*)0), i++) { | |||||
121 | if (tok[0] != kw[i]) { | |||||
122 | ret = -1; | |||||
123 | goto out; | |||||
124 | } | |||||
125 | if (i == KW_TYPE) | |||||
126 | args->type = clrlk_get_type (tok+1); | |||||
127 | if (i == KW_KIND) | |||||
128 | args->kind = clrlk_get_kind (tok+1); | |||||
129 | } | |||||
130 | ||||||
131 | if ((args->type == CLRLK_TYPE_MAX) || (args->kind == CLRLK_KIND_MAX)) | |||||
132 | goto out; | |||||
133 | ||||||
134 | /*optional args, neither range nor basename can 'legally' contain | |||||
135 | * "/" in them*/ | |||||
136 | tok = strtok_r (NULL((void*)0), "/", &sptr); | |||||
137 | if (tok) | |||||
138 | args->opts = gf_strdup (tok); | |||||
139 | ||||||
140 | ret = 0; | |||||
141 | out: | |||||
142 | GF_FREE (free_ptr)__gf_free (free_ptr); | |||||
143 | return ret; | |||||
144 | } | |||||
145 | ||||||
146 | int | |||||
147 | clrlk_clear_posixlk (xlator_t *this, pl_inode_t *pl_inode, clrlk_args *args, | |||||
148 | int *blkd, int *granted, int *op_errno) | |||||
149 | { | |||||
150 | posix_lock_t *plock = NULL((void*)0); | |||||
151 | posix_lock_t *tmp = NULL((void*)0); | |||||
152 | struct gf_flock ulock = {0, }; | |||||
153 | int ret = -1; | |||||
154 | int bcount = 0; | |||||
155 | int gcount = 0; | |||||
156 | gf_boolean_t chk_range = _gf_false; | |||||
157 | ||||||
158 | if (clrlk_get_lock_range (args->opts, &ulock, &chk_range)) { | |||||
159 | *op_errno = EINVAL22; | |||||
160 | goto out; | |||||
161 | } | |||||
162 | ||||||
163 | pthread_mutex_lock (&pl_inode->mutex); | |||||
164 | { | |||||
165 | list_for_each_entry_safe (plock, tmp, &pl_inode->ext_list,for (plock = ((typeof(*plock) *)((char *)((&pl_inode-> ext_list)->next)-(unsigned long)(&((typeof(*plock) *)0 )->list))), tmp = ((typeof(*plock) *)((char *)(plock->list .next)-(unsigned long)(&((typeof(*plock) *)0)->list))) ; &plock->list != (&pl_inode->ext_list); plock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long)(&((typeof(*tmp) *)0)->list)))) | |||||
166 | list)for (plock = ((typeof(*plock) *)((char *)((&pl_inode-> ext_list)->next)-(unsigned long)(&((typeof(*plock) *)0 )->list))), tmp = ((typeof(*plock) *)((char *)(plock->list .next)-(unsigned long)(&((typeof(*plock) *)0)->list))) ; &plock->list != (&pl_inode->ext_list); plock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long)(&((typeof(*tmp) *)0)->list)))) { | |||||
167 | if ((plock->blocked && | |||||
168 | !(args->kind & CLRLK_BLOCKED)) || | |||||
169 | (!plock->blocked && | |||||
170 | !(args->kind & CLRLK_GRANTED))) | |||||
171 | continue; | |||||
172 | ||||||
173 | if (chk_range && | |||||
174 | (plock->user_flock.l_whence != ulock.l_whence | |||||
175 | || plock->user_flock.l_start != ulock.l_start | |||||
176 | || plock->user_flock.l_len != ulock.l_len)) | |||||
177 | continue; | |||||
178 | ||||||
179 | list_del_init (&plock->list); | |||||
180 | if (plock->blocked) { | |||||
181 | bcount++; | |||||
182 | pl_trace_out (this, plock->frame, NULL((void*)0), NULL((void*)0), | |||||
183 | F_SETLKW14, &plock->user_flock, | |||||
184 | -1, EAGAIN11, NULL((void*)0)); | |||||
185 | ||||||
186 | STACK_UNWIND_STRICT (lk, plock->frame, -1, EAGAIN,do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = (( void*)0); xlator_t *old_THIS = ((void*)0); if (!plock->frame ) { do { do { if (0) printf ("!frame"); } while (0); _gf_log ( "stack", "clear.c", __FUNCTION__, 187, GF_LOG_CRITICAL, "!frame" ); } while (0); break; } fn = (fop_lk_cbk_t )plock->frame-> ret; _parent = plock->frame->parent; pthread_spin_lock ( &plock->frame->root->stack_lock); { _parent-> ref_count--; } pthread_spin_unlock (&plock->frame-> root->stack_lock); old_THIS = (*__glusterfs_this_location( )); (*__glusterfs_this_location()) = _parent->this; plock-> frame->complete = _gf_true; plock->frame->unwind_from = __FUNCTION__; if (plock->frame->this->ctx->measure_latency ) gf_latency_end (plock->frame); fn (_parent, plock->frame ->cookie, _parent->this, -1, 11, &plock->user_flock , ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0) | |||||
187 | &plock->user_flock, NULL)do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = (( void*)0); xlator_t *old_THIS = ((void*)0); if (!plock->frame ) { do { do { if (0) printf ("!frame"); } while (0); _gf_log ( "stack", "clear.c", __FUNCTION__, 187, GF_LOG_CRITICAL, "!frame" ); } while (0); break; } fn = (fop_lk_cbk_t )plock->frame-> ret; _parent = plock->frame->parent; pthread_spin_lock ( &plock->frame->root->stack_lock); { _parent-> ref_count--; } pthread_spin_unlock (&plock->frame-> root->stack_lock); old_THIS = (*__glusterfs_this_location( )); (*__glusterfs_this_location()) = _parent->this; plock-> frame->complete = _gf_true; plock->frame->unwind_from = __FUNCTION__; if (plock->frame->this->ctx->measure_latency ) gf_latency_end (plock->frame); fn (_parent, plock->frame ->cookie, _parent->this, -1, 11, &plock->user_flock , ((void*)0)); (*__glusterfs_this_location()) = old_THIS; } while (0); | |||||
188 | ||||||
189 | } else { | |||||
190 | gcount++; | |||||
191 | } | |||||
192 | GF_FREE (plock)__gf_free (plock); | |||||
193 | } | |||||
194 | } | |||||
195 | pthread_mutex_unlock (&pl_inode->mutex); | |||||
196 | grant_blocked_locks (this, pl_inode); | |||||
197 | ret = 0; | |||||
198 | out: | |||||
199 | *blkd = bcount; | |||||
200 | *granted = gcount; | |||||
201 | return ret; | |||||
202 | } | |||||
203 | ||||||
204 | /* Returns 0 on success and -1 on failure */ | |||||
205 | int | |||||
206 | clrlk_clear_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t *dom, | |||||
207 | clrlk_args *args, int *blkd, int *granted, int *op_errno) | |||||
208 | { | |||||
209 | pl_inode_lock_t *ilock = NULL((void*)0); | |||||
210 | pl_inode_lock_t *tmp = NULL((void*)0); | |||||
211 | struct gf_flock ulock = {0, }; | |||||
212 | int ret = -1; | |||||
213 | int bcount = 0; | |||||
214 | int gcount = 0; | |||||
215 | gf_boolean_t chk_range = _gf_false; | |||||
216 | struct list_head released; | |||||
217 | ||||||
218 | INIT_LIST_HEAD (&released)do { (&released)->next = (&released)->prev = & released; } while (0); | |||||
219 | if (clrlk_get_lock_range (args->opts, &ulock, &chk_range)) { | |||||
| ||||||
220 | *op_errno = EINVAL22; | |||||
221 | goto out; | |||||
222 | } | |||||
223 | ||||||
224 | if (args->kind & CLRLK_BLOCKED) | |||||
225 | goto blkd; | |||||
226 | ||||||
227 | if (args->kind & CLRLK_GRANTED) | |||||
228 | goto granted; | |||||
229 | ||||||
230 | blkd: | |||||
231 | pthread_mutex_lock (&pl_inode->mutex); | |||||
232 | { | |||||
233 | list_for_each_entry_safe (ilock, tmp, &dom->blocked_inodelks,for (ilock = ((typeof(*ilock) *)((char *)((&dom->blocked_inodelks )->next)-(unsigned long)(&((typeof(*ilock) *)0)->blocked_locks ))), tmp = ((typeof(*ilock) *)((char *)(ilock->blocked_locks .next)-(unsigned long)(&((typeof(*ilock) *)0)->blocked_locks ))); &ilock->blocked_locks != (&dom->blocked_inodelks ); ilock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->blocked_locks .next)-(unsigned long)(&((typeof(*tmp) *)0)->blocked_locks )))) | |||||
234 | blocked_locks)for (ilock = ((typeof(*ilock) *)((char *)((&dom->blocked_inodelks )->next)-(unsigned long)(&((typeof(*ilock) *)0)->blocked_locks ))), tmp = ((typeof(*ilock) *)((char *)(ilock->blocked_locks .next)-(unsigned long)(&((typeof(*ilock) *)0)->blocked_locks ))); &ilock->blocked_locks != (&dom->blocked_inodelks ); ilock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->blocked_locks .next)-(unsigned long)(&((typeof(*tmp) *)0)->blocked_locks )))) { | |||||
235 | if (chk_range && | |||||
236 | (ilock->user_flock.l_whence != ulock.l_whence | |||||
237 | || ilock->user_flock.l_start != ulock.l_start | |||||
238 | || ilock->user_flock.l_len != ulock.l_len)) | |||||
239 | continue; | |||||
240 | ||||||
241 | bcount++; | |||||
242 | list_del_init (&ilock->blocked_locks); | |||||
243 | list_add (&ilock->blocked_locks, &released); | |||||
244 | } | |||||
245 | } | |||||
246 | pthread_mutex_unlock (&pl_inode->mutex); | |||||
247 | ||||||
248 | list_for_each_entry_safe (ilock, tmp, &released, blocked_locks)for (ilock = ((typeof(*ilock) *)((char *)((&released)-> next)-(unsigned long)(&((typeof(*ilock) *)0)->blocked_locks ))), tmp = ((typeof(*ilock) *)((char *)(ilock->blocked_locks .next)-(unsigned long)(&((typeof(*ilock) *)0)->blocked_locks ))); &ilock->blocked_locks != (&released); ilock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->blocked_locks. next)-(unsigned long)(&((typeof(*tmp) *)0)->blocked_locks )))) { | |||||
| ||||||
249 | list_del_init (&ilock->blocked_locks); | |||||
250 | pl_trace_out (this, ilock->frame, NULL((void*)0), NULL((void*)0), F_SETLKW14, | |||||
251 | &ilock->user_flock, -1, EAGAIN11, | |||||
252 | ilock->volume); | |||||
253 | STACK_UNWIND_STRICT (inodelk, ilock->frame, -1,do { fop_inodelk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((void*)0); xlator_t *old_THIS = ((void*)0); if (!ilock-> frame) { do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack", "clear.c", __FUNCTION__, 254, GF_LOG_CRITICAL, "!frame" ); } while (0); break; } fn = (fop_inodelk_cbk_t )ilock->frame ->ret; _parent = ilock->frame->parent; pthread_spin_lock (&ilock->frame->root->stack_lock); { _parent-> ref_count--; } pthread_spin_unlock (&ilock->frame-> root->stack_lock); old_THIS = (*__glusterfs_this_location( )); (*__glusterfs_this_location()) = _parent->this; ilock-> frame->complete = _gf_true; ilock->frame->unwind_from = __FUNCTION__; if (ilock->frame->this->ctx->measure_latency ) gf_latency_end (ilock->frame); fn (_parent, ilock->frame ->cookie, _parent->this, -1, 11, ((void*)0)); (*__glusterfs_this_location ()) = old_THIS; } while (0) | |||||
254 | EAGAIN, NULL)do { fop_inodelk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((void*)0); xlator_t *old_THIS = ((void*)0); if (!ilock-> frame) { do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack", "clear.c", __FUNCTION__, 254, GF_LOG_CRITICAL, "!frame" ); } while (0); break; } fn = (fop_inodelk_cbk_t )ilock->frame ->ret; _parent = ilock->frame->parent; pthread_spin_lock (&ilock->frame->root->stack_lock); { _parent-> ref_count--; } pthread_spin_unlock (&ilock->frame-> root->stack_lock); old_THIS = (*__glusterfs_this_location( )); (*__glusterfs_this_location()) = _parent->this; ilock-> frame->complete = _gf_true; ilock->frame->unwind_from = __FUNCTION__; if (ilock->frame->this->ctx->measure_latency ) gf_latency_end (ilock->frame); fn (_parent, ilock->frame ->cookie, _parent->this, -1, 11, ((void*)0)); (*__glusterfs_this_location ()) = old_THIS; } while (0); | |||||
255 | //No need to take lock as the locks are only in one list | |||||
256 | __pl_inodelk_unref (ilock); | |||||
257 | } | |||||
258 | ||||||
259 | if (!(args->kind & CLRLK_GRANTED)) { | |||||
260 | ret = 0; | |||||
261 | goto out; | |||||
262 | } | |||||
263 | ||||||
264 | granted: | |||||
265 | pthread_mutex_lock (&pl_inode->mutex); | |||||
266 | { | |||||
267 | list_for_each_entry_safe (ilock, tmp, &dom->inodelk_list,for (ilock = ((typeof(*ilock) *)((char *)((&dom->inodelk_list )->next)-(unsigned long)(&((typeof(*ilock) *)0)->list ))), tmp = ((typeof(*ilock) *)((char *)(ilock->list.next)- (unsigned long)(&((typeof(*ilock) *)0)->list))); & ilock->list != (&dom->inodelk_list); ilock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long )(&((typeof(*tmp) *)0)->list)))) | |||||
268 | list)for (ilock = ((typeof(*ilock) *)((char *)((&dom->inodelk_list )->next)-(unsigned long)(&((typeof(*ilock) *)0)->list ))), tmp = ((typeof(*ilock) *)((char *)(ilock->list.next)- (unsigned long)(&((typeof(*ilock) *)0)->list))); & ilock->list != (&dom->inodelk_list); ilock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned long )(&((typeof(*tmp) *)0)->list)))) { | |||||
269 | if (chk_range && | |||||
270 | (ilock->user_flock.l_whence != ulock.l_whence | |||||
271 | || ilock->user_flock.l_start != ulock.l_start | |||||
272 | || ilock->user_flock.l_len != ulock.l_len)) | |||||
273 | continue; | |||||
274 | ||||||
275 | gcount++; | |||||
276 | list_del_init (&ilock->list); | |||||
277 | list_add (&ilock->list, &released); | |||||
278 | } | |||||
279 | } | |||||
280 | pthread_mutex_unlock (&pl_inode->mutex); | |||||
281 | ||||||
282 | list_for_each_entry_safe (ilock, tmp, &released, list)for (ilock = ((typeof(*ilock) *)((char *)((&released)-> next)-(unsigned long)(&((typeof(*ilock) *)0)->list))), tmp = ((typeof(*ilock) *)((char *)(ilock->list.next)-(unsigned long)(&((typeof(*ilock) *)0)->list))); &ilock-> list != (&released); ilock = tmp, tmp = ((typeof(*tmp) *) ((char *)(tmp->list.next)-(unsigned long)(&((typeof(*tmp ) *)0)->list)))) { | |||||
283 | list_del_init (&ilock->list); | |||||
284 | //No need to take lock as the locks are only in one list | |||||
285 | __pl_inodelk_unref (ilock); | |||||
286 | } | |||||
287 | ||||||
288 | ret = 0; | |||||
289 | out: | |||||
290 | grant_blocked_inode_locks (this, pl_inode, dom); | |||||
291 | *blkd = bcount; | |||||
292 | *granted = gcount; | |||||
293 | return ret; | |||||
294 | } | |||||
295 | ||||||
296 | /* Returns 0 on success and -1 on failure */ | |||||
297 | int | |||||
298 | clrlk_clear_entrylk (xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t *dom, | |||||
299 | clrlk_args *args, int *blkd, int *granted, int *op_errno) | |||||
300 | { | |||||
301 | pl_entry_lock_t *elock = NULL((void*)0); | |||||
302 | pl_entry_lock_t *tmp = NULL((void*)0); | |||||
303 | int bcount = 0; | |||||
304 | int gcount = 0; | |||||
305 | int ret = -1; | |||||
306 | struct list_head removed; | |||||
307 | struct list_head released; | |||||
308 | ||||||
309 | INIT_LIST_HEAD (&released)do { (&released)->next = (&released)->prev = & released; } while (0); | |||||
310 | if (args->kind & CLRLK_BLOCKED) | |||||
311 | goto blkd; | |||||
312 | ||||||
313 | if (args->kind & CLRLK_GRANTED) | |||||
314 | goto granted; | |||||
315 | ||||||
316 | blkd: | |||||
317 | pthread_mutex_lock (&pl_inode->mutex); | |||||
318 | { | |||||
319 | list_for_each_entry_safe (elock, tmp, &dom->blocked_entrylks,for (elock = ((typeof(*elock) *)((char *)((&dom->blocked_entrylks )->next)-(unsigned long)(&((typeof(*elock) *)0)->blocked_locks ))), tmp = ((typeof(*elock) *)((char *)(elock->blocked_locks .next)-(unsigned long)(&((typeof(*elock) *)0)->blocked_locks ))); &elock->blocked_locks != (&dom->blocked_entrylks ); elock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->blocked_locks .next)-(unsigned long)(&((typeof(*tmp) *)0)->blocked_locks )))) | |||||
320 | blocked_locks)for (elock = ((typeof(*elock) *)((char *)((&dom->blocked_entrylks )->next)-(unsigned long)(&((typeof(*elock) *)0)->blocked_locks ))), tmp = ((typeof(*elock) *)((char *)(elock->blocked_locks .next)-(unsigned long)(&((typeof(*elock) *)0)->blocked_locks ))); &elock->blocked_locks != (&dom->blocked_entrylks ); elock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->blocked_locks .next)-(unsigned long)(&((typeof(*tmp) *)0)->blocked_locks )))) { | |||||
321 | if (args->opts) { | |||||
322 | if (!elock->basename || | |||||
323 | strcmp (elock->basename, args->opts)) | |||||
324 | continue; | |||||
325 | } | |||||
326 | ||||||
327 | bcount++; | |||||
328 | ||||||
329 | list_del_init (&elock->blocked_locks); | |||||
330 | list_add_tail (&elock->blocked_locks, &released); | |||||
331 | } | |||||
332 | } | |||||
333 | pthread_mutex_unlock (&pl_inode->mutex); | |||||
334 | ||||||
335 | list_for_each_entry_safe (elock, tmp, &released, blocked_locks)for (elock = ((typeof(*elock) *)((char *)((&released)-> next)-(unsigned long)(&((typeof(*elock) *)0)->blocked_locks ))), tmp = ((typeof(*elock) *)((char *)(elock->blocked_locks .next)-(unsigned long)(&((typeof(*elock) *)0)->blocked_locks ))); &elock->blocked_locks != (&released); elock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->blocked_locks. next)-(unsigned long)(&((typeof(*tmp) *)0)->blocked_locks )))) { | |||||
336 | list_del_init (&elock->blocked_locks); | |||||
337 | entrylk_trace_out (this, elock->frame, elock->volume, NULL((void*)0), NULL((void*)0), | |||||
338 | elock->basename, ENTRYLK_LOCK, elock->type, | |||||
339 | -1, EAGAIN11); | |||||
340 | STACK_UNWIND_STRICT (entrylk, elock->frame, -1, EAGAIN, NULL)do { fop_entrylk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((void*)0); xlator_t *old_THIS = ((void*)0); if (!elock-> frame) { do { do { if (0) printf ("!frame"); } while (0); _gf_log ("stack", "clear.c", __FUNCTION__, 340, GF_LOG_CRITICAL, "!frame" ); } while (0); break; } fn = (fop_entrylk_cbk_t )elock->frame ->ret; _parent = elock->frame->parent; pthread_spin_lock (&elock->frame->root->stack_lock); { _parent-> ref_count--; } pthread_spin_unlock (&elock->frame-> root->stack_lock); old_THIS = (*__glusterfs_this_location( )); (*__glusterfs_this_location()) = _parent->this; elock-> frame->complete = _gf_true; elock->frame->unwind_from = __FUNCTION__; if (elock->frame->this->ctx->measure_latency ) gf_latency_end (elock->frame); fn (_parent, elock->frame ->cookie, _parent->this, -1, 11, ((void*)0)); (*__glusterfs_this_location ()) = old_THIS; } while (0); | |||||
341 | GF_FREE ((char *) elock->basename)__gf_free ((char *) elock->basename); | |||||
342 | GF_FREE (elock)__gf_free (elock); | |||||
343 | } | |||||
344 | ||||||
345 | if (!(args->kind & CLRLK_GRANTED)) { | |||||
346 | ret = 0; | |||||
347 | goto out; | |||||
348 | } | |||||
349 | ||||||
350 | granted: | |||||
351 | INIT_LIST_HEAD (&removed)do { (&removed)->next = (&removed)->prev = & removed; } while (0); | |||||
352 | pthread_mutex_lock (&pl_inode->mutex); | |||||
353 | { | |||||
354 | list_for_each_entry_safe (elock, tmp, &dom->entrylk_list,for (elock = ((typeof(*elock) *)((char *)((&dom->entrylk_list )->next)-(unsigned long)(&((typeof(*elock) *)0)->domain_list ))), tmp = ((typeof(*elock) *)((char *)(elock->domain_list .next)-(unsigned long)(&((typeof(*elock) *)0)->domain_list ))); &elock->domain_list != (&dom->entrylk_list ); elock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->domain_list .next)-(unsigned long)(&((typeof(*tmp) *)0)->domain_list )))) | |||||
355 | domain_list)for (elock = ((typeof(*elock) *)((char *)((&dom->entrylk_list )->next)-(unsigned long)(&((typeof(*elock) *)0)->domain_list ))), tmp = ((typeof(*elock) *)((char *)(elock->domain_list .next)-(unsigned long)(&((typeof(*elock) *)0)->domain_list ))); &elock->domain_list != (&dom->entrylk_list ); elock = tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->domain_list .next)-(unsigned long)(&((typeof(*tmp) *)0)->domain_list )))) { | |||||
356 | if (args->opts) { | |||||
357 | if (!elock->basename || | |||||
358 | strcmp (elock->basename, args->opts)) | |||||
359 | continue; | |||||
360 | } | |||||
361 | ||||||
362 | gcount++; | |||||
363 | list_del_init (&elock->domain_list); | |||||
364 | list_add_tail (&elock->domain_list, &removed); | |||||
365 | } | |||||
366 | } | |||||
367 | pthread_mutex_unlock (&pl_inode->mutex); | |||||
368 | ||||||
369 | list_for_each_entry_safe (elock, tmp, &removed, domain_list)for (elock = ((typeof(*elock) *)((char *)((&removed)-> next)-(unsigned long)(&((typeof(*elock) *)0)->domain_list ))), tmp = ((typeof(*elock) *)((char *)(elock->domain_list .next)-(unsigned long)(&((typeof(*elock) *)0)->domain_list ))); &elock->domain_list != (&removed); elock = tmp , tmp = ((typeof(*tmp) *)((char *)(tmp->domain_list.next)- (unsigned long)(&((typeof(*tmp) *)0)->domain_list)))) { | |||||
370 | grant_blocked_entry_locks (this, pl_inode, elock, dom); | |||||
371 | } | |||||
372 | ||||||
373 | ret = 0; | |||||
374 | out: | |||||
375 | *blkd = bcount; | |||||
376 | *granted = gcount; | |||||
377 | return ret; | |||||
378 | } | |||||
379 | ||||||
380 | int | |||||
381 | clrlk_clear_lks_in_all_domains (xlator_t *this, pl_inode_t *pl_inode, | |||||
382 | clrlk_args *args, int *blkd, int *granted, | |||||
383 | int *op_errno) | |||||
384 | { | |||||
385 | pl_dom_list_t *dom = NULL((void*)0); | |||||
386 | int ret = -1; | |||||
387 | int tmp_bcount = 0; | |||||
388 | int tmp_gcount = 0; | |||||
389 | ||||||
390 | if (list_empty (&pl_inode->dom_list)) { | |||||
391 | ret = 0; | |||||
392 | goto out; | |||||
393 | } | |||||
394 | ||||||
395 | list_for_each_entry (dom, &pl_inode->dom_list, inode_list)for (dom = ((typeof(*dom) *)((char *)((&pl_inode->dom_list )->next)-(unsigned long)(&((typeof(*dom) *)0)->inode_list ))); &dom->inode_list != (&pl_inode->dom_list); dom = ((typeof(*dom) *)((char *)(dom->inode_list.next)-(unsigned long)(&((typeof(*dom) *)0)->inode_list)))) { | |||||
396 | tmp_bcount = tmp_gcount = 0; | |||||
397 | ||||||
398 | switch (args->type) | |||||
399 | { | |||||
400 | case CLRLK_INODE: | |||||
401 | ret = clrlk_clear_inodelk (this, pl_inode, dom, args, | |||||
402 | &tmp_bcount, &tmp_gcount, | |||||
403 | op_errno); | |||||
404 | if (ret) | |||||
405 | goto out; | |||||
406 | break; | |||||
407 | case CLRLK_ENTRY: | |||||
408 | ret = clrlk_clear_entrylk (this, pl_inode, dom, args, | |||||
409 | &tmp_bcount, &tmp_gcount, | |||||
410 | op_errno); | |||||
411 | if (ret) | |||||
412 | goto out; | |||||
413 | break; | |||||
414 | } | |||||
415 | ||||||
416 | *blkd += tmp_bcount; | |||||
417 | *granted += tmp_gcount; | |||||
418 | } | |||||
419 | ||||||
420 | ret = 0; | |||||
421 | out: | |||||
422 | return ret; | |||||
423 | } |