Bug Summary

File:xlators/features/locks/src/common.c
Location:line 398, column 9
Description:Null pointer passed as an argument to a 'nonnull' parameter

Annotated Source Code

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
30
31static int
32__is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock);
33static void
34__insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock);
35static int
36pl_send_prelock_unlock (xlator_t *this, pl_inode_t *pl_inode,
37 posix_lock_t *old_lock);
38static pl_dom_list_t *
39__allocate_domain (const char *volume)
40{
41 pl_dom_list_t *dom = NULL((void*)0);
42
43 dom = GF_CALLOC (1, sizeof (*dom),__gf_calloc (1, sizeof (*dom), gf_locks_mt_pl_dom_list_t)
44 gf_locks_mt_pl_dom_list_t)__gf_calloc (1, sizeof (*dom), gf_locks_mt_pl_dom_list_t);
45 if (!dom)
46 goto out;
47
48 dom->domain = gf_strdup(volume);
49 if (!dom->domain)
50 goto out;
51
52 gf_log ("posix-locks", GF_LOG_TRACE,do { do { if (0) printf ("New domain allocated: %s", dom->
domain); } while (0); _gf_log ("posix-locks", "common.c", __FUNCTION__
, 53, GF_LOG_TRACE, "New domain allocated: %s", dom->domain
); } while (0)
53 "New domain allocated: %s", dom->domain)do { do { if (0) printf ("New domain allocated: %s", dom->
domain); } while (0); _gf_log ("posix-locks", "common.c", __FUNCTION__
, 53, GF_LOG_TRACE, "New domain allocated: %s", dom->domain
); } while (0)
;
54
55 INIT_LIST_HEAD (&dom->inode_list)do { (&dom->inode_list)->next = (&dom->inode_list
)->prev = &dom->inode_list; } while (0)
;
56 INIT_LIST_HEAD (&dom->entrylk_list)do { (&dom->entrylk_list)->next = (&dom->entrylk_list
)->prev = &dom->entrylk_list; } while (0)
;
57 INIT_LIST_HEAD (&dom->blocked_entrylks)do { (&dom->blocked_entrylks)->next = (&dom->
blocked_entrylks)->prev = &dom->blocked_entrylks; }
while (0)
;
58 INIT_LIST_HEAD (&dom->inodelk_list)do { (&dom->inodelk_list)->next = (&dom->inodelk_list
)->prev = &dom->inodelk_list; } while (0)
;
59 INIT_LIST_HEAD (&dom->blocked_inodelks)do { (&dom->blocked_inodelks)->next = (&dom->
blocked_inodelks)->prev = &dom->blocked_inodelks; }
while (0)
;
60
61out:
62 if (dom && (NULL((void*)0) == dom->domain)) {
63 GF_FREE (dom)__gf_free (dom);
64 dom = NULL((void*)0);
65 }
66
67 return dom;
68}
69
70/* Returns domain for the lock. If domain is not present,
71 * allocates a domain and returns it
72 */
73pl_dom_list_t *
74get_domain (pl_inode_t *pl_inode, const char *volume)
75{
76 pl_dom_list_t *dom = NULL((void*)0);
77
78 GF_VALIDATE_OR_GOTO (POSIX_LOCKS, pl_inode, out)do { if (!pl_inode) { (*__errno_location ()) = 22; do { do { if
(0) printf ("invalid argument: " "pl_inode"); } while (0); _gf_log_callingfn
("posix-locks", "common.c", __FUNCTION__, 78, GF_LOG_ERROR, "invalid argument: "
"pl_inode"); } while (0); goto out; } } while (0)
;
79 GF_VALIDATE_OR_GOTO (POSIX_LOCKS, volume, out)do { if (!volume) { (*__errno_location ()) = 22; do { do { if
(0) printf ("invalid argument: " "volume"); } while (0); _gf_log_callingfn
("posix-locks", "common.c", __FUNCTION__, 79, GF_LOG_ERROR, "invalid argument: "
"volume"); } while (0); goto out; } } while (0)
;
80
81 pthread_mutex_lock (&pl_inode->mutex);
82 {
83 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))))
{
84 if (strcmp (dom->domain, volume) == 0)
85 goto unlock;
86 }
87
88 dom = __allocate_domain (volume);
89 if (dom)
90 list_add (&dom->inode_list, &pl_inode->dom_list);
91 }
92unlock:
93 pthread_mutex_unlock (&pl_inode->mutex);
94 if (dom) {
95 gf_log (POSIX_LOCKS, GF_LOG_TRACE, "Domain %s found", volume)do { do { if (0) printf ("Domain %s found", volume); } while (
0); _gf_log ("posix-locks", "common.c", __FUNCTION__, 95, GF_LOG_TRACE
, "Domain %s found", volume); } while (0)
;
96 } else {
97 gf_log (POSIX_LOCKS, GF_LOG_TRACE, "Domain %s not found", volume)do { do { if (0) printf ("Domain %s not found", volume); } while
(0); _gf_log ("posix-locks", "common.c", __FUNCTION__, 97, GF_LOG_TRACE
, "Domain %s not found", volume); } while (0)
;
98 }
99out:
100 return dom;
101}
102
103unsigned long
104fd_to_fdnum (fd_t *fd)
105{
106 return ((unsigned long) fd);
107}
108
109fd_t *
110fd_from_fdnum (posix_lock_t *lock)
111{
112 return ((fd_t *) lock->fd_num);
113}
114
115int
116__pl_inode_is_empty (pl_inode_t *pl_inode)
117{
118 pl_dom_list_t *dom = NULL((void*)0);
119 int is_empty = 1;
120
121 if (!list_empty (&pl_inode->ext_list))
122 is_empty = 0;
123
124 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))))
{
125 if (!list_empty (&dom->entrylk_list))
126 is_empty = 0;
127
128 if (!list_empty (&dom->inodelk_list))
129 is_empty = 0;
130 }
131
132 return is_empty;
133}
134
135void
136pl_print_locker (char *str, int size, xlator_t *this, call_frame_t *frame)
137{
138 snprintf (str, size, "Pid=%llu, lk-owner=%s, Transport=%p, Frame=%llu",
139 (unsigned long long) frame->root->pid,
140 lkowner_utoa (&frame->root->lk_owner),
141 (void *)frame->root->trans,
142 (unsigned long long) frame->root->unique);
143}
144
145
146void
147pl_print_lockee (char *str, int size, fd_t *fd, loc_t *loc)
148{
149 inode_t *inode = NULL((void*)0);
150 char *ipath = NULL((void*)0);
151 int ret = 0;
152
153 if (fd)
154 inode = fd->inode;
155 if (loc)
156 inode = loc->inode;
157
158 if (!inode) {
159 snprintf (str, size, "<nul>");
160 return;
161 }
162
163 if (loc && loc->path) {
164 ipath = gf_strdup (loc->path);
165 } else {
166 ret = inode_path (inode, NULL((void*)0), &ipath);
167 if (ret <= 0)
168 ipath = NULL((void*)0);
169 }
170
171 snprintf (str, size, "gfid=%s, fd=%p, path=%s",
172 uuid_utoa (inode->gfid), fd,
173 ipath ? ipath : "<nul>");
174
175 GF_FREE (ipath)__gf_free (ipath);
176}
177
178
179void
180pl_print_lock (char *str, int size, int cmd,
181 struct gf_flock *flock, gf_lkowner_t *owner)
182{
183 char *cmd_str = NULL((void*)0);
184 char *type_str = NULL((void*)0);
185
186 switch (cmd) {
187#if F_GETLK12 != F_GETLK6412
188 case F_GETLK6412:
189#endif
190 case F_GETLK12:
191 cmd_str = "GETLK";
192 break;
193
194#if F_SETLK13 != F_SETLK6413
195 case F_SETLK6413:
196#endif
197 case F_SETLK13:
198 cmd_str = "SETLK";
199 break;
200
201#if F_SETLKW14 != F_SETLKW6414
202 case F_SETLKW6414:
203#endif
204 case F_SETLKW14:
205 cmd_str = "SETLKW";
206 break;
207
208 default:
209 cmd_str = "UNKNOWN";
210 break;
211 }
212
213 switch (flock->l_type) {
214 case F_RDLCK0:
215 type_str = "READ";
216 break;
217 case F_WRLCK1:
218 type_str = "WRITE";
219 break;
220 case F_UNLCK2:
221 type_str = "UNLOCK";
222 break;
223 default:
224 type_str = "UNKNOWN";
225 break;
226 }
227
228 snprintf (str, size, "lock=FCNTL, cmd=%s, type=%s, "
229 "start=%llu, len=%llu, pid=%llu, lk-owner=%s",
230 cmd_str, type_str, (unsigned long long) flock->l_start,
231 (unsigned long long) flock->l_len,
232 (unsigned long long) flock->l_pid,
233 lkowner_utoa (owner));
234}
235
236
237void
238pl_trace_in (xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc,
239 int cmd, struct gf_flock *flock, const char *domain)
240{
241 posix_locks_private_t *priv = NULL((void*)0);
242 char pl_locker[256];
243 char pl_lockee[256];
244 char pl_lock[256];
245
246 priv = this->private;
247
248 if (!priv->trace)
249 return;
250
251 pl_print_locker (pl_locker, 256, this, frame);
252 pl_print_lockee (pl_lockee, 256, fd, loc);
253 if (domain)
254 pl_print_inodelk (pl_lock, 256, cmd, flock, domain);
255 else
256 pl_print_lock (pl_lock, 256, cmd, flock, &frame->root->lk_owner);
257
258 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log (this->
name, "common.c", __FUNCTION__, 260, GF_LOG_INFO, "[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0)
259 "[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}",do { do { if (0) printf ("[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log (this->
name, "common.c", __FUNCTION__, 260, GF_LOG_INFO, "[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0)
260 pl_locker, pl_lockee, pl_lock)do { do { if (0) printf ("[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log (this->
name, "common.c", __FUNCTION__, 260, GF_LOG_INFO, "[REQUEST] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0)
;
261}
262
263
264void
265pl_print_verdict (char *str, int size, int op_ret, int op_errno)
266{
267 char *verdict = NULL((void*)0);
268
269 if (op_ret == 0) {
270 verdict = "GRANTED";
271 } else {
272 switch (op_errno) {
273 case EAGAIN11:
274 verdict = "TRYAGAIN";
275 break;
276 default:
277 verdict = strerror (op_errno);
278 }
279 }
280
281 snprintf (str, size, "%s", verdict);
282}
283
284
285void
286pl_trace_out (xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc,
287 int cmd, struct gf_flock *flock, int op_ret, int op_errno, const char *domain)
288
289{
290 posix_locks_private_t *priv = NULL((void*)0);
291 char pl_locker[256];
292 char pl_lockee[256];
293 char pl_lock[256];
294 char verdict[32];
295
296 priv = this->private;
297
298 if (!priv->trace)
299 return;
300
301 pl_print_locker (pl_locker, 256, this, frame);
302 pl_print_lockee (pl_lockee, 256, fd, loc);
303 if (domain)
304 pl_print_inodelk (pl_lock, 256, cmd, flock, domain);
305 else
306 pl_print_lock (pl_lock, 256, cmd, flock, &frame->root->lk_owner);
307
308 pl_print_verdict (verdict, 32, op_ret, op_errno);
309
310 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("[%s] Locker = {%s} Lockee = {%s} Lock = {%s}"
, verdict, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log
(this->name, "common.c", __FUNCTION__, 312, GF_LOG_INFO, "[%s] Locker = {%s} Lockee = {%s} Lock = {%s}"
, verdict, pl_locker, pl_lockee, pl_lock); } while (0)
311 "[%s] Locker = {%s} Lockee = {%s} Lock = {%s}",do { do { if (0) printf ("[%s] Locker = {%s} Lockee = {%s} Lock = {%s}"
, verdict, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log
(this->name, "common.c", __FUNCTION__, 312, GF_LOG_INFO, "[%s] Locker = {%s} Lockee = {%s} Lock = {%s}"
, verdict, pl_locker, pl_lockee, pl_lock); } while (0)
312 verdict, pl_locker, pl_lockee, pl_lock)do { do { if (0) printf ("[%s] Locker = {%s} Lockee = {%s} Lock = {%s}"
, verdict, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log
(this->name, "common.c", __FUNCTION__, 312, GF_LOG_INFO, "[%s] Locker = {%s} Lockee = {%s} Lock = {%s}"
, verdict, pl_locker, pl_lockee, pl_lock); } while (0)
;
313}
314
315
316void
317pl_trace_block (xlator_t *this, call_frame_t *frame, fd_t *fd, loc_t *loc,
318 int cmd, struct gf_flock *flock, const char *domain)
319
320{
321 posix_locks_private_t *priv = NULL((void*)0);
322 char pl_locker[256];
323 char pl_lockee[256];
324 char pl_lock[256];
325
326 priv = this->private;
327
328 if (!priv->trace)
329 return;
330
331 pl_print_locker (pl_locker, 256, this, frame);
332 pl_print_lockee (pl_lockee, 256, fd, loc);
333 if (domain)
334 pl_print_inodelk (pl_lock, 256, cmd, flock, domain);
335 else
336 pl_print_lock (pl_lock, 256, cmd, flock, &frame->root->lk_owner);
337
338 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log (this->
name, "common.c", __FUNCTION__, 340, GF_LOG_INFO, "[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0)
339 "[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}",do { do { if (0) printf ("[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log (this->
name, "common.c", __FUNCTION__, 340, GF_LOG_INFO, "[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0)
340 pl_locker, pl_lockee, pl_lock)do { do { if (0) printf ("[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0); _gf_log (this->
name, "common.c", __FUNCTION__, 340, GF_LOG_INFO, "[BLOCKED] Locker = {%s} Lockee = {%s} Lock = {%s}"
, pl_locker, pl_lockee, pl_lock); } while (0)
;
341}
342
343
344void
345pl_trace_flush (xlator_t *this, call_frame_t *frame, fd_t *fd)
346{
347 posix_locks_private_t *priv = NULL((void*)0);
348 char pl_locker[256];
349 char pl_lockee[256];
350 pl_inode_t *pl_inode = NULL((void*)0);
351
352 priv = this->private;
353
354 if (!priv->trace)
355 return;
356
357 pl_inode = pl_inode_get (this, fd->inode);
358
359 if (pl_inode && __pl_inode_is_empty (pl_inode))
360 return;
361
362 pl_print_locker (pl_locker, 256, this, frame);
363 pl_print_lockee (pl_lockee, 256, fd, NULL((void*)0));
364
365 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("[FLUSH] Locker = {%s} Lockee = {%s}"
, pl_locker, pl_lockee); } while (0); _gf_log (this->name,
"common.c", __FUNCTION__, 367, GF_LOG_INFO, "[FLUSH] Locker = {%s} Lockee = {%s}"
, pl_locker, pl_lockee); } while (0)
366 "[FLUSH] Locker = {%s} Lockee = {%s}",do { do { if (0) printf ("[FLUSH] Locker = {%s} Lockee = {%s}"
, pl_locker, pl_lockee); } while (0); _gf_log (this->name,
"common.c", __FUNCTION__, 367, GF_LOG_INFO, "[FLUSH] Locker = {%s} Lockee = {%s}"
, pl_locker, pl_lockee); } while (0)
367 pl_locker, pl_lockee)do { do { if (0) printf ("[FLUSH] Locker = {%s} Lockee = {%s}"
, pl_locker, pl_lockee); } while (0); _gf_log (this->name,
"common.c", __FUNCTION__, 367, GF_LOG_INFO, "[FLUSH] Locker = {%s} Lockee = {%s}"
, pl_locker, pl_lockee); } while (0)
;
368}
369
370void
371pl_trace_release (xlator_t *this, fd_t *fd)
372{
373 posix_locks_private_t *priv = NULL((void*)0);
374 char pl_lockee[256];
375
376 priv = this->private;
377
378 if (!priv->trace)
379 return;
380
381 pl_print_lockee (pl_lockee, 256, fd, NULL((void*)0));
382
383 gf_log (this->name, GF_LOG_INFO,do { do { if (0) printf ("[RELEASE] Lockee = {%s}", pl_lockee
); } while (0); _gf_log (this->name, "common.c", __FUNCTION__
, 384, GF_LOG_INFO, "[RELEASE] Lockee = {%s}", pl_lockee); } while
(0)
384 "[RELEASE] Lockee = {%s}", pl_lockee)do { do { if (0) printf ("[RELEASE] Lockee = {%s}", pl_lockee
); } while (0); _gf_log (this->name, "common.c", __FUNCTION__
, 384, GF_LOG_INFO, "[RELEASE] Lockee = {%s}", pl_lockee); } while
(0)
;
385}
386
387
388void
389pl_update_refkeeper (xlator_t *this, inode_t *inode)
390{
391 pl_inode_t *pl_inode = NULL((void*)0);
392 int is_empty = 0;
393 int need_unref = 0;
394 int need_ref = 0;
395
396 pl_inode = pl_inode_get (this, inode);
397
398 pthread_mutex_lock (&pl_inode->mutex);
Null pointer passed as an argument to a 'nonnull' parameter
399 {
400 is_empty = __pl_inode_is_empty (pl_inode);
401
402 if (is_empty && pl_inode->refkeeper) {
403 need_unref = 1;
404 pl_inode->refkeeper = NULL((void*)0);
405 }
406
407 if (!is_empty && !pl_inode->refkeeper) {
408 need_ref = 1;
409 pl_inode->refkeeper = inode;
410 }
411 }
412 pthread_mutex_unlock (&pl_inode->mutex);
413
414 if (need_unref)
415 inode_unref (inode);
416
417 if (need_ref)
418 inode_ref (inode);
419}
420
421
422pl_inode_t *
423pl_inode_get (xlator_t *this, inode_t *inode)
424{
425 uint64_t tmp_pl_inode = 0;
426 pl_inode_t *pl_inode = NULL((void*)0);
427 int ret = 0;
428
429 LOCK (&inode->lock)pthread_spin_lock (&inode->lock);
430 {
431 ret = __inode_ctx_get (inode, this, &tmp_pl_inode)__inode_ctx_get2(inode,this,&tmp_pl_inode,0);
432 if (ret == 0) {
433 pl_inode = (pl_inode_t *)(long)tmp_pl_inode;
434 goto unlock;
435 }
436 pl_inode = GF_CALLOC (1, sizeof (*pl_inode),__gf_calloc (1, sizeof (*pl_inode), gf_locks_mt_pl_inode_t)
437 gf_locks_mt_pl_inode_t)__gf_calloc (1, sizeof (*pl_inode), gf_locks_mt_pl_inode_t);
438 if (!pl_inode) {
439 goto unlock;
440 }
441
442 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("Allocating new pl inode"); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 443, GF_LOG_TRACE
, "Allocating new pl inode"); } while (0)
443 "Allocating new pl inode")do { do { if (0) printf ("Allocating new pl inode"); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 443, GF_LOG_TRACE
, "Allocating new pl inode"); } while (0)
;
444
445 pthread_mutex_init (&pl_inode->mutex, NULL((void*)0));
446
447 INIT_LIST_HEAD (&pl_inode->dom_list)do { (&pl_inode->dom_list)->next = (&pl_inode->
dom_list)->prev = &pl_inode->dom_list; } while (0)
;
448 INIT_LIST_HEAD (&pl_inode->ext_list)do { (&pl_inode->ext_list)->next = (&pl_inode->
ext_list)->prev = &pl_inode->ext_list; } while (0)
;
449 INIT_LIST_HEAD (&pl_inode->rw_list)do { (&pl_inode->rw_list)->next = (&pl_inode->
rw_list)->prev = &pl_inode->rw_list; } while (0)
;
450 INIT_LIST_HEAD (&pl_inode->reservelk_list)do { (&pl_inode->reservelk_list)->next = (&pl_inode
->reservelk_list)->prev = &pl_inode->reservelk_list
; } while (0)
;
451 INIT_LIST_HEAD (&pl_inode->blocked_reservelks)do { (&pl_inode->blocked_reservelks)->next = (&
pl_inode->blocked_reservelks)->prev = &pl_inode->
blocked_reservelks; } while (0)
;
452 INIT_LIST_HEAD (&pl_inode->blocked_calls)do { (&pl_inode->blocked_calls)->next = (&pl_inode
->blocked_calls)->prev = &pl_inode->blocked_calls
; } while (0)
;
453
454 __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode));
455 }
456unlock:
457 UNLOCK (&inode->lock)pthread_spin_unlock (&inode->lock);
458
459 return pl_inode;
460}
461
462
463/* Create a new posix_lock_t */
464posix_lock_t *
465new_posix_lock (struct gf_flock *flock, void *transport, pid_t client_pid,
466 gf_lkowner_t *owner, fd_t *fd)
467{
468 posix_lock_t *lock = NULL((void*)0);
469
470 GF_VALIDATE_OR_GOTO (POSIX_LOCKS, flock, out)do { if (!flock) { (*__errno_location ()) = 22; do { do { if (
0) printf ("invalid argument: " "flock"); } while (0); _gf_log_callingfn
("posix-locks", "common.c", __FUNCTION__, 470, GF_LOG_ERROR,
"invalid argument: " "flock"); } while (0); goto out; } } while
(0)
;
471 GF_VALIDATE_OR_GOTO (POSIX_LOCKS, transport, out)do { if (!transport) { (*__errno_location ()) = 22; do { do {
if (0) printf ("invalid argument: " "transport"); } while (0
); _gf_log_callingfn ("posix-locks", "common.c", __FUNCTION__
, 471, GF_LOG_ERROR, "invalid argument: " "transport"); } while
(0); goto out; } } while (0)
;
472 GF_VALIDATE_OR_GOTO (POSIX_LOCKS, fd, out)do { if (!fd) { (*__errno_location ()) = 22; do { do { if (0)
printf ("invalid argument: " "fd"); } while (0); _gf_log_callingfn
("posix-locks", "common.c", __FUNCTION__, 472, GF_LOG_ERROR,
"invalid argument: " "fd"); } while (0); goto out; } } while
(0)
;
473
474 lock = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
475 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
476 if (!lock) {
477 goto out;
478 }
479
480 lock->fl_start = flock->l_start;
481 lock->fl_type = flock->l_type;
482
483 if (flock->l_len == 0)
484 lock->fl_end = LLONG_MAX9223372036854775807LL;
485 else
486 lock->fl_end = flock->l_start + flock->l_len - 1;
487
488 lock->transport = transport;
489 lock->fd_num = fd_to_fdnum (fd);
490 lock->fd = fd;
491 lock->client_pid = client_pid;
492 lock->owner = *owner;
493
494 INIT_LIST_HEAD (&lock->list)do { (&lock->list)->next = (&lock->list)->
prev = &lock->list; } while (0)
;
495
496out:
497 return lock;
498}
499
500
501/* Delete a lock from the inode's lock list */
502void
503__delete_lock (pl_inode_t *pl_inode, posix_lock_t *lock)
504{
505 list_del_init (&lock->list);
506}
507
508
509/* Destroy a posix_lock */
510void
511__destroy_lock (posix_lock_t *lock)
512{
513 GF_FREE (lock)__gf_free (lock);
514}
515
516
517/* Convert a posix_lock to a struct gf_flock */
518void
519posix_lock_to_flock (posix_lock_t *lock, struct gf_flock *flock)
520{
521 flock->l_pid = lock->client_pid;
522 flock->l_type = lock->fl_type;
523 flock->l_start = lock->fl_start;
524 flock->l_owner = lock->owner;
525
526 if (lock->fl_end == LLONG_MAX9223372036854775807LL)
527 flock->l_len = 0;
528 else
529 flock->l_len = lock->fl_end - lock->fl_start + 1;
530}
531
532/* Insert the lock into the inode's lock list */
533static void
534__insert_lock (pl_inode_t *pl_inode, posix_lock_t *lock)
535{
536 if (lock->blocked)
537 gettimeofday (&lock->blkd_time, NULL((void*)0));
538 else
539 gettimeofday (&lock->granted_time, NULL((void*)0));
540
541 list_add_tail (&lock->list, &pl_inode->ext_list);
542
543 return;
544}
545
546
547/* Return true if the locks overlap, false otherwise */
548int
549locks_overlap (posix_lock_t *l1, posix_lock_t *l2)
550{
551 /*
552 Note:
553 FUSE always gives us absolute offsets, so no need to worry
554 about SEEK_CUR or SEEK_END
555 */
556
557 return ((l1->fl_end >= l2->fl_start) &&
558 (l2->fl_end >= l1->fl_start));
559}
560
561
562/* Return true if the locks have the same owner */
563int
564same_owner (posix_lock_t *l1, posix_lock_t *l2)
565{
566
567 return (is_same_lkowner (&l1->owner, &l2->owner) &&
568 (l1->transport == l2->transport));
569
570}
571
572
573/* Delete all F_UNLCK locks */
574void
575__delete_unlck_locks (pl_inode_t *pl_inode)
576{
577 posix_lock_t *l = NULL((void*)0);
578 posix_lock_t *tmp = NULL((void*)0);
579
580 list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list)for (l = ((typeof(*l) *)((char *)((&pl_inode->ext_list
)->next)-(unsigned long)(&((typeof(*l) *)0)->list))
), tmp = ((typeof(*l) *)((char *)(l->list.next)-(unsigned long
)(&((typeof(*l) *)0)->list))); &l->list != (&
pl_inode->ext_list); l = tmp, tmp = ((typeof(*tmp) *)((char
*)(tmp->list.next)-(unsigned long)(&((typeof(*tmp) *)
0)->list))))
{
581 if (l->fl_type == F_UNLCK2) {
582 __delete_lock (pl_inode, l);
583 __destroy_lock (l);
584 }
585 }
586}
587
588
589/* Add two locks */
590static posix_lock_t *
591add_locks (posix_lock_t *l1, posix_lock_t *l2)
592{
593 posix_lock_t *sum = NULL((void*)0);
594
595 sum = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
596 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
597 if (!sum)
598 return NULL((void*)0);
599
600 sum->fl_start = min (l1->fl_start, l2->fl_start)((l1->fl_start)<(l2->fl_start)?(l1->fl_start):(l2
->fl_start))
;
601 sum->fl_end = max (l1->fl_end, l2->fl_end)((l1->fl_end)>(l2->fl_end)?(l1->fl_end):(l2->fl_end
))
;
602
603 return sum;
604}
605
606/* Subtract two locks */
607struct _values {
608 posix_lock_t *locks[3];
609};
610
611/* {big} must always be contained inside {small} */
612static struct _values
613subtract_locks (posix_lock_t *big, posix_lock_t *small)
614{
615
616 struct _values v = { .locks = {0, 0, 0} };
617
618 if ((big->fl_start == small->fl_start) &&
619 (big->fl_end == small->fl_end)) {
620 /* both edges coincide with big */
621 v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
622 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
623 if (!v.locks[0])
624 goto out;
625 memcpy (v.locks[0], big, sizeof (posix_lock_t));
626 v.locks[0]->fl_type = small->fl_type;
627 goto done;
628 }
629
630 if ((small->fl_start > big->fl_start) &&
631 (small->fl_end < big->fl_end)) {
632 /* both edges lie inside big */
633 v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
634 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
635 if (!v.locks[0])
636 goto out;
637
638 v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
639 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
640 if (!v.locks[1])
641 goto out;
642
643 v.locks[2] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
644 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
645 if (!v.locks[1])
646 goto out;
647
648 memcpy (v.locks[0], big, sizeof (posix_lock_t));
649 v.locks[0]->fl_end = small->fl_start - 1;
650
651 memcpy (v.locks[1], small, sizeof (posix_lock_t));
652
653 memcpy (v.locks[2], big, sizeof (posix_lock_t));
654 v.locks[2]->fl_start = small->fl_end + 1;
655 goto done;
656
657 }
658
659 /* one edge coincides with big */
660 if (small->fl_start == big->fl_start) {
661 v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
662 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
663 if (!v.locks[0])
664 goto out;
665
666 v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
667 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
668 if (!v.locks[1])
669 goto out;
670
671 memcpy (v.locks[0], big, sizeof (posix_lock_t));
672 v.locks[0]->fl_start = small->fl_end + 1;
673
674 memcpy (v.locks[1], small, sizeof (posix_lock_t));
675 goto done;
676 }
677
678 if (small->fl_end == big->fl_end) {
679 v.locks[0] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
680 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
681 if (!v.locks[0])
682 goto out;
683
684 v.locks[1] = GF_CALLOC (1, sizeof (posix_lock_t),__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
685 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (posix_lock_t), gf_locks_mt_posix_lock_t
)
;
686 if (!v.locks[1])
687 goto out;
688
689 memcpy (v.locks[0], big, sizeof (posix_lock_t));
690 v.locks[0]->fl_end = small->fl_start - 1;
691
692 memcpy (v.locks[1], small, sizeof (posix_lock_t));
693 goto done;
694 }
695
696 GF_ASSERT (0)do { if (!(0)) { do { do { if (0) printf ("Assertion failed: "
"0"); } while (0); _gf_log_callingfn ("", "common.c", __FUNCTION__
, 696, GF_LOG_ERROR, "Assertion failed: " "0"); } while (0); }
} while (0)
;
697 gf_log (POSIX_LOCKS, GF_LOG_ERROR, "Unexpected case in subtract_locks")do { do { if (0) printf ("Unexpected case in subtract_locks")
; } while (0); _gf_log ("posix-locks", "common.c", __FUNCTION__
, 697, GF_LOG_ERROR, "Unexpected case in subtract_locks"); } while
(0)
;
698
699out:
700 if (v.locks[0]) {
701 GF_FREE (v.locks[0])__gf_free (v.locks[0]);
702 v.locks[0] = NULL((void*)0);
703 }
704 if (v.locks[1]) {
705 GF_FREE (v.locks[1])__gf_free (v.locks[1]);
706 v.locks[1] = NULL((void*)0);
707 }
708 if (v.locks[2]) {
709 GF_FREE (v.locks[2])__gf_free (v.locks[2]);
710 v.locks[2] = NULL((void*)0);
711 }
712
713done:
714 return v;
715}
716
717static posix_lock_t *
718first_conflicting_overlap (pl_inode_t *pl_inode, posix_lock_t *lock)
719{
720 posix_lock_t *l = NULL((void*)0);
721 posix_lock_t *conf = NULL((void*)0);
722
723 pthread_mutex_lock (&pl_inode->mutex);
724 {
725 list_for_each_entry (l, &pl_inode->ext_list, list)for (l = ((typeof(*l) *)((char *)((&pl_inode->ext_list
)->next)-(unsigned long)(&((typeof(*l) *)0)->list))
); &l->list != (&pl_inode->ext_list); l = ((typeof
(*l) *)((char *)(l->list.next)-(unsigned long)(&((typeof
(*l) *)0)->list))))
{
726 if (l->blocked)
727 continue;
728
729 if (locks_overlap (l, lock)) {
730 if (same_owner (l, lock))
731 continue;
732
733 if ((l->fl_type == F_WRLCK1) ||
734 (lock->fl_type == F_WRLCK1)) {
735 conf = l;
736 goto unlock;
737 }
738 }
739 }
740 }
741unlock:
742 pthread_mutex_unlock (&pl_inode->mutex);
743
744 return conf;
745}
746
747/*
748 Start searching from {begin}, and return the first lock that
749 conflicts, NULL if no conflict
750 If {begin} is NULL, then start from the beginning of the list
751*/
752static posix_lock_t *
753first_overlap (pl_inode_t *pl_inode, posix_lock_t *lock)
754{
755 posix_lock_t *l = NULL((void*)0);
756
757 list_for_each_entry (l, &pl_inode->ext_list, list)for (l = ((typeof(*l) *)((char *)((&pl_inode->ext_list
)->next)-(unsigned long)(&((typeof(*l) *)0)->list))
); &l->list != (&pl_inode->ext_list); l = ((typeof
(*l) *)((char *)(l->list.next)-(unsigned long)(&((typeof
(*l) *)0)->list))))
{
758 if (l->blocked)
759 continue;
760
761 if (locks_overlap (l, lock))
762 return l;
763 }
764
765 return NULL((void*)0);
766}
767
768
769
770/* Return true if lock is grantable */
771static int
772__is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock)
773{
774 posix_lock_t *l = NULL((void*)0);
775 int ret = 1;
776
777 list_for_each_entry (l, &pl_inode->ext_list, list)for (l = ((typeof(*l) *)((char *)((&pl_inode->ext_list
)->next)-(unsigned long)(&((typeof(*l) *)0)->list))
); &l->list != (&pl_inode->ext_list); l = ((typeof
(*l) *)((char *)(l->list.next)-(unsigned long)(&((typeof
(*l) *)0)->list))))
{
778 if (!l->blocked && locks_overlap (lock, l)) {
779 if (((l->fl_type == F_WRLCK1)
780 || (lock->fl_type == F_WRLCK1))
781 && (lock->fl_type != F_UNLCK2)
782 && !same_owner (l, lock)) {
783 ret = 0;
784 break;
785 }
786 }
787 }
788 return ret;
789}
790
791
792extern void do_blocked_rw (pl_inode_t *);
793
794
795static void
796__insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock)
797{
798 posix_lock_t *conf = NULL((void*)0);
799 posix_lock_t *t = NULL((void*)0);
800 posix_lock_t *sum = NULL((void*)0);
801 int i = 0;
802 struct _values v = { .locks = {0, 0, 0} };
803
804 list_for_each_entry_safe (conf, t, &pl_inode->ext_list, list)for (conf = ((typeof(*conf) *)((char *)((&pl_inode->ext_list
)->next)-(unsigned long)(&((typeof(*conf) *)0)->list
))), t = ((typeof(*conf) *)((char *)(conf->list.next)-(unsigned
long)(&((typeof(*conf) *)0)->list))); &conf->list
!= (&pl_inode->ext_list); conf = t, t = ((typeof(*t) *
)((char *)(t->list.next)-(unsigned long)(&((typeof(*t)
*)0)->list))))
{
805 if (conf->blocked)
806 continue;
807 if (!locks_overlap (conf, lock))
808 continue;
809
810 if (same_owner (conf, lock)) {
811 if (conf->fl_type == lock->fl_type) {
812 sum = add_locks (lock, conf);
813
814 sum->fl_type = lock->fl_type;
815 sum->transport = lock->transport;
816 sum->fd_num = lock->fd_num;
817 sum->client_pid = lock->client_pid;
818 sum->owner = lock->owner;
819
820 __delete_lock (pl_inode, conf);
821 __destroy_lock (conf);
822
823 __destroy_lock (lock);
824 INIT_LIST_HEAD (&sum->list)do { (&sum->list)->next = (&sum->list)->prev
= &sum->list; } while (0)
;
825 posix_lock_to_flock (sum, &sum->user_flock);
826 __insert_and_merge (pl_inode, sum);
827
828 return;
829 } else {
830 sum = add_locks (lock, conf);
831
832 sum->fl_type = conf->fl_type;
833 sum->transport = conf->transport;
834 sum->fd_num = conf->fd_num;
835 sum->client_pid = conf->client_pid;
836 sum->owner = conf->owner;
837
838 v = subtract_locks (sum, lock);
839
840 __delete_lock (pl_inode, conf);
841 __destroy_lock (conf);
842
843 __delete_lock (pl_inode, lock);
844 __destroy_lock (lock);
845
846 __destroy_lock (sum);
847
848 for (i = 0; i < 3; i++) {
849 if (!v.locks[i])
850 continue;
851
852 INIT_LIST_HEAD (&v.locks[i]->list)do { (&v.locks[i]->list)->next = (&v.locks[i]->
list)->prev = &v.locks[i]->list; } while (0)
;
853 posix_lock_to_flock (v.locks[i],
854 &v.locks[i]->user_flock);
855 __insert_and_merge (pl_inode,
856 v.locks[i]);
857 }
858
859 __delete_unlck_locks (pl_inode);
860 return;
861 }
862 }
863
864 if (lock->fl_type == F_UNLCK2) {
865 continue;
866 }
867
868 if ((conf->fl_type == F_RDLCK0) && (lock->fl_type == F_RDLCK0)) {
869 __insert_lock (pl_inode, lock);
870 return;
871 }
872 }
873
874 /* no conflicts, so just insert */
875 if (lock->fl_type != F_UNLCK2) {
876 __insert_lock (pl_inode, lock);
877 } else {
878 __destroy_lock (lock);
879 }
880}
881
882
883void
884__grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode, struct list_head *granted)
885{
886 struct list_head tmp_list;
887 posix_lock_t *l = NULL((void*)0);
888 posix_lock_t *tmp = NULL((void*)0);
889 posix_lock_t *conf = NULL((void*)0);
890
891 INIT_LIST_HEAD (&tmp_list)do { (&tmp_list)->next = (&tmp_list)->prev = &
tmp_list; } while (0)
;
892
893 list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list)for (l = ((typeof(*l) *)((char *)((&pl_inode->ext_list
)->next)-(unsigned long)(&((typeof(*l) *)0)->list))
), tmp = ((typeof(*l) *)((char *)(l->list.next)-(unsigned long
)(&((typeof(*l) *)0)->list))); &l->list != (&
pl_inode->ext_list); l = tmp, tmp = ((typeof(*tmp) *)((char
*)(tmp->list.next)-(unsigned long)(&((typeof(*tmp) *)
0)->list))))
{
894 if (l->blocked) {
895 conf = first_overlap (pl_inode, l);
896 if (conf)
897 continue;
898
899 l->blocked = 0;
900 list_move_tail (&l->list, &tmp_list);
901 }
902 }
903
904 list_for_each_entry_safe (l, tmp, &tmp_list, list)for (l = ((typeof(*l) *)((char *)((&tmp_list)->next)-(
unsigned long)(&((typeof(*l) *)0)->list))), tmp = ((typeof
(*l) *)((char *)(l->list.next)-(unsigned long)(&((typeof
(*l) *)0)->list))); &l->list != (&tmp_list); l =
tmp, tmp = ((typeof(*tmp) *)((char *)(tmp->list.next)-(unsigned
long)(&((typeof(*tmp) *)0)->list))))
{
905 list_del_init (&l->list);
906
907 if (__is_lock_grantable (pl_inode, l)) {
908 conf = GF_CALLOC (1, sizeof (*conf),__gf_calloc (1, sizeof (*conf), gf_locks_mt_posix_lock_t)
909 gf_locks_mt_posix_lock_t)__gf_calloc (1, sizeof (*conf), gf_locks_mt_posix_lock_t);
910
911 if (!conf) {
912 l->blocked = 1;
913 __insert_lock (pl_inode, l);
914 continue;
915 }
916
917 conf->frame = l->frame;
918 l->frame = NULL((void*)0);
919
920 posix_lock_to_flock (l, &conf->user_flock);
921
922 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Granted", l->fl_type == 2 ? "Unlock" : "Lock"
, l->client_pid, lkowner_utoa (&l->owner), l->user_flock
.l_start, l->user_flock.l_len); } while (0); _gf_log (this
->name, "common.c", __FUNCTION__, 927, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"
"ll" "d"" - %""ll" "d"" => Granted", l->fl_type == 2 ? "Unlock"
: "Lock", l->client_pid, lkowner_utoa (&l->owner),
l->user_flock.l_start, l->user_flock.l_len); } while (
0)
923 "%s (pid=%d) lk-owner:%s %"PRId64" - %"PRId64" => Granted",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Granted", l->fl_type == 2 ? "Unlock" : "Lock"
, l->client_pid, lkowner_utoa (&l->owner), l->user_flock
.l_start, l->user_flock.l_len); } while (0); _gf_log (this
->name, "common.c", __FUNCTION__, 927, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"
"ll" "d"" - %""ll" "d"" => Granted", l->fl_type == 2 ? "Unlock"
: "Lock", l->client_pid, lkowner_utoa (&l->owner),
l->user_flock.l_start, l->user_flock.l_len); } while (
0)
924 l->fl_type == F_UNLCK ? "Unlock" : "Lock",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Granted", l->fl_type == 2 ? "Unlock" : "Lock"
, l->client_pid, lkowner_utoa (&l->owner), l->user_flock
.l_start, l->user_flock.l_len); } while (0); _gf_log (this
->name, "common.c", __FUNCTION__, 927, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"
"ll" "d"" - %""ll" "d"" => Granted", l->fl_type == 2 ? "Unlock"
: "Lock", l->client_pid, lkowner_utoa (&l->owner),
l->user_flock.l_start, l->user_flock.l_len); } while (
0)
925 l->client_pid, lkowner_utoa (&l->owner),do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Granted", l->fl_type == 2 ? "Unlock" : "Lock"
, l->client_pid, lkowner_utoa (&l->owner), l->user_flock
.l_start, l->user_flock.l_len); } while (0); _gf_log (this
->name, "common.c", __FUNCTION__, 927, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"
"ll" "d"" - %""ll" "d"" => Granted", l->fl_type == 2 ? "Unlock"
: "Lock", l->client_pid, lkowner_utoa (&l->owner),
l->user_flock.l_start, l->user_flock.l_len); } while (
0)
926 l->user_flock.l_start,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Granted", l->fl_type == 2 ? "Unlock" : "Lock"
, l->client_pid, lkowner_utoa (&l->owner), l->user_flock
.l_start, l->user_flock.l_len); } while (0); _gf_log (this
->name, "common.c", __FUNCTION__, 927, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"
"ll" "d"" - %""ll" "d"" => Granted", l->fl_type == 2 ? "Unlock"
: "Lock", l->client_pid, lkowner_utoa (&l->owner),
l->user_flock.l_start, l->user_flock.l_len); } while (
0)
927 l->user_flock.l_len)do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Granted", l->fl_type == 2 ? "Unlock" : "Lock"
, l->client_pid, lkowner_utoa (&l->owner), l->user_flock
.l_start, l->user_flock.l_len); } while (0); _gf_log (this
->name, "common.c", __FUNCTION__, 927, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"
"ll" "d"" - %""ll" "d"" => Granted", l->fl_type == 2 ? "Unlock"
: "Lock", l->client_pid, lkowner_utoa (&l->owner),
l->user_flock.l_start, l->user_flock.l_len); } while (
0)
;
928
929 __insert_and_merge (pl_inode, l);
930
931 list_add (&conf->list, granted);
932 } else {
933 l->blocked = 1;
934 __insert_lock (pl_inode, l);
935 }
936 }
937}
938
939
940void
941grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode)
942{
943 struct list_head granted_list;
944 posix_lock_t *tmp = NULL((void*)0);
945 posix_lock_t *lock = NULL((void*)0);
946
947 INIT_LIST_HEAD (&granted_list)do { (&granted_list)->next = (&granted_list)->prev
= &granted_list; } while (0)
;
948
949 pthread_mutex_lock (&pl_inode->mutex);
950 {
951 __grant_blocked_locks (this, pl_inode, &granted_list);
952 }
953 pthread_mutex_unlock (&pl_inode->mutex);
954
955 list_for_each_entry_safe (lock, tmp, &granted_list, list)for (lock = ((typeof(*lock) *)((char *)((&granted_list)->
next)-(unsigned long)(&((typeof(*lock) *)0)->list))), tmp
= ((typeof(*lock) *)((char *)(lock->list.next)-(unsigned long
)(&((typeof(*lock) *)0)->list))); &lock->list !=
(&granted_list); lock = tmp, tmp = ((typeof(*tmp) *)((char
*)(tmp->list.next)-(unsigned long)(&((typeof(*tmp) *)
0)->list))))
{
956 list_del_init (&lock->list);
957
958 pl_trace_out (this, lock->frame, NULL((void*)0), NULL((void*)0), F_SETLKW14,
959 &lock->user_flock, 0, 0, NULL((void*)0));
960
961 STACK_UNWIND_STRICT (lk, lock->frame, 0, 0,do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((
void*)0); xlator_t *old_THIS = ((void*)0); if (!lock->frame
) { do { do { if (0) printf ("!frame"); } while (0); _gf_log (
"stack", "common.c", __FUNCTION__, 962, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_lk_cbk_t )lock->frame->
ret; _parent = lock->frame->parent; pthread_spin_lock (
&lock->frame->root->stack_lock); { _parent->ref_count
--; } pthread_spin_unlock (&lock->frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = _parent->this; lock->frame->complete = _gf_true
; lock->frame->unwind_from = __FUNCTION__; if (lock->
frame->this->ctx->measure_latency) gf_latency_end (lock
->frame); fn (_parent, lock->frame->cookie, _parent->
this, 0, 0, &lock->user_flock, ((void*)0)); (*__glusterfs_this_location
()) = old_THIS; } while (0)
962 &lock->user_flock, NULL)do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((
void*)0); xlator_t *old_THIS = ((void*)0); if (!lock->frame
) { do { do { if (0) printf ("!frame"); } while (0); _gf_log (
"stack", "common.c", __FUNCTION__, 962, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_lk_cbk_t )lock->frame->
ret; _parent = lock->frame->parent; pthread_spin_lock (
&lock->frame->root->stack_lock); { _parent->ref_count
--; } pthread_spin_unlock (&lock->frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = _parent->this; lock->frame->complete = _gf_true
; lock->frame->unwind_from = __FUNCTION__; if (lock->
frame->this->ctx->measure_latency) gf_latency_end (lock
->frame); fn (_parent, lock->frame->cookie, _parent->
this, 0, 0, &lock->user_flock, ((void*)0)); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
963
964 GF_FREE (lock)__gf_free (lock);
965 }
966
967 return;
968}
969
970static int
971pl_send_prelock_unlock (xlator_t *this, pl_inode_t *pl_inode,
972 posix_lock_t *old_lock)
973{
974 struct gf_flock flock = {0,};
975 posix_lock_t *unlock_lock = NULL((void*)0);
976
977 struct list_head granted_list;
978 posix_lock_t *tmp = NULL((void*)0);
979 posix_lock_t *lock = NULL((void*)0);
980
981 int ret = -1;
982
983 INIT_LIST_HEAD (&granted_list)do { (&granted_list)->next = (&granted_list)->prev
= &granted_list; } while (0)
;
984
985 flock.l_type = F_UNLCK2;
986 flock.l_whence = old_lock->user_flock.l_whence;
987 flock.l_start = old_lock->user_flock.l_start;
988 flock.l_len = old_lock->user_flock.l_len;
989
990
991 unlock_lock = new_posix_lock (&flock, old_lock->transport,
992 old_lock->client_pid, &old_lock->owner,
993 old_lock->fd);
994 GF_VALIDATE_OR_GOTO (this->name, unlock_lock, out)do { if (!unlock_lock) { (*__errno_location ()) = 22; do { do
{ if (0) printf ("invalid argument: " "unlock_lock"); } while
(0); _gf_log_callingfn (this->name, "common.c", __FUNCTION__
, 994, GF_LOG_ERROR, "invalid argument: " "unlock_lock"); } while
(0); goto out; } } while (0)
;
995 ret = 0;
996
997 __insert_and_merge (pl_inode, unlock_lock);
998
999 __grant_blocked_locks (this, pl_inode, &granted_list);
1000
1001 list_for_each_entry_safe (lock, tmp, &granted_list, list)for (lock = ((typeof(*lock) *)((char *)((&granted_list)->
next)-(unsigned long)(&((typeof(*lock) *)0)->list))), tmp
= ((typeof(*lock) *)((char *)(lock->list.next)-(unsigned long
)(&((typeof(*lock) *)0)->list))); &lock->list !=
(&granted_list); lock = tmp, tmp = ((typeof(*tmp) *)((char
*)(tmp->list.next)-(unsigned long)(&((typeof(*tmp) *)
0)->list))))
{
1002 list_del_init (&lock->list);
1003
1004 pl_trace_out (this, lock->frame, NULL((void*)0), NULL((void*)0), F_SETLKW14,
1005 &lock->user_flock, 0, 0, NULL((void*)0));
1006
1007 STACK_UNWIND_STRICT (lk, lock->frame, 0, 0,do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((
void*)0); xlator_t *old_THIS = ((void*)0); if (!lock->frame
) { do { do { if (0) printf ("!frame"); } while (0); _gf_log (
"stack", "common.c", __FUNCTION__, 1008, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_lk_cbk_t )lock->frame->
ret; _parent = lock->frame->parent; pthread_spin_lock (
&lock->frame->root->stack_lock); { _parent->ref_count
--; } pthread_spin_unlock (&lock->frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = _parent->this; lock->frame->complete = _gf_true
; lock->frame->unwind_from = __FUNCTION__; if (lock->
frame->this->ctx->measure_latency) gf_latency_end (lock
->frame); fn (_parent, lock->frame->cookie, _parent->
this, 0, 0, &lock->user_flock, ((void*)0)); (*__glusterfs_this_location
()) = old_THIS; } while (0)
1008 &lock->user_flock, NULL)do { fop_lk_cbk_t fn = ((void*)0); call_frame_t *_parent = ((
void*)0); xlator_t *old_THIS = ((void*)0); if (!lock->frame
) { do { do { if (0) printf ("!frame"); } while (0); _gf_log (
"stack", "common.c", __FUNCTION__, 1008, GF_LOG_CRITICAL, "!frame"
); } while (0); break; } fn = (fop_lk_cbk_t )lock->frame->
ret; _parent = lock->frame->parent; pthread_spin_lock (
&lock->frame->root->stack_lock); { _parent->ref_count
--; } pthread_spin_unlock (&lock->frame->root->stack_lock
); old_THIS = (*__glusterfs_this_location()); (*__glusterfs_this_location
()) = _parent->this; lock->frame->complete = _gf_true
; lock->frame->unwind_from = __FUNCTION__; if (lock->
frame->this->ctx->measure_latency) gf_latency_end (lock
->frame); fn (_parent, lock->frame->cookie, _parent->
this, 0, 0, &lock->user_flock, ((void*)0)); (*__glusterfs_this_location
()) = old_THIS; } while (0)
;
1009
1010 GF_FREE (lock)__gf_free (lock);
1011 }
1012
1013out:
1014 return ret;
1015}
1016
1017int
1018pl_setlk (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock,
1019 int can_block)
1020{
1021 int ret = 0;
1022
1023 errno(*__errno_location ()) = 0;
1024
1025 pthread_mutex_lock (&pl_inode->mutex);
1026 {
1027 /* Send unlock before the actual lock to
1028 prevent lock upgrade / downgrade
1029 problems only if:
1030 - it is a blocking call
1031 - it has other conflicting locks
1032 */
1033
1034 if (can_block &&
1035 !(__is_lock_grantable (pl_inode, lock))) {
1036 ret = pl_send_prelock_unlock (this, pl_inode,
1037 lock);
1038 if (ret)
1039 gf_log (this->name, GF_LOG_DEBUG,do { do { if (0) printf ("Could not send pre-lock " "unlock")
; } while (0); _gf_log (this->name, "common.c", __FUNCTION__
, 1041, GF_LOG_DEBUG, "Could not send pre-lock " "unlock"); }
while (0)
1040 "Could not send pre-lock "do { do { if (0) printf ("Could not send pre-lock " "unlock")
; } while (0); _gf_log (this->name, "common.c", __FUNCTION__
, 1041, GF_LOG_DEBUG, "Could not send pre-lock " "unlock"); }
while (0)
1041 "unlock")do { do { if (0) printf ("Could not send pre-lock " "unlock")
; } while (0); _gf_log (this->name, "common.c", __FUNCTION__
, 1041, GF_LOG_DEBUG, "Could not send pre-lock " "unlock"); }
while (0)
;
1042 }
1043
1044 if (__is_lock_grantable (pl_inode, lock)) {
1045 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => OK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1051, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => OK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1046 "%s (pid=%d) lk-owner:%s %"PRId64" - %"PRId64" => OK",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => OK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1051, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => OK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1047 lock->fl_type == F_UNLCK ? "Unlock" : "Lock",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => OK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1051, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => OK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1048 lock->client_pid,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => OK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1051, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => OK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1049 lkowner_utoa (&lock->owner),do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => OK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1051, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => OK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1050 lock->user_flock.l_start,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => OK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1051, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => OK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1051 lock->user_flock.l_len)do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => OK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1051, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => OK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
;
1052 __insert_and_merge (pl_inode, lock);
1053 } else if (can_block) {
1054 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Blocked", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1060, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => Blocked"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1055 "%s (pid=%d) lk-owner:%s %"PRId64" - %"PRId64" => Blocked",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Blocked", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1060, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => Blocked"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1056 lock->fl_type == F_UNLCK ? "Unlock" : "Lock",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Blocked", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1060, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => Blocked"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1057 lock->client_pid,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Blocked", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1060, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => Blocked"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1058 lkowner_utoa (&lock->owner),do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Blocked", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1060, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => Blocked"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1059 lock->user_flock.l_start,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Blocked", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1060, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => Blocked"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1060 lock->user_flock.l_len)do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => Blocked", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1060, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => Blocked"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
;
1061 lock->blocked = 1;
1062 __insert_lock (pl_inode, lock);
1063 ret = -1;
1064 } else {
1065 gf_log (this->name, GF_LOG_TRACE,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => NOK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1071, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => NOK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1066 "%s (pid=%d) lk-owner:%s %"PRId64" - %"PRId64" => NOK",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => NOK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1071, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => NOK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1067 lock->fl_type == F_UNLCK ? "Unlock" : "Lock",do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => NOK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1071, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => NOK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1068 lock->client_pid,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => NOK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1071, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => NOK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1069 lkowner_utoa (&lock->owner),do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => NOK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1071, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => NOK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1070 lock->user_flock.l_start,do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => NOK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1071, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => NOK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
1071 lock->user_flock.l_len)do { do { if (0) printf ("%s (pid=%d) lk-owner:%s %""ll" "d"" - %"
"ll" "d"" => NOK", lock->fl_type == 2 ? "Unlock" : "Lock"
, lock->client_pid, lkowner_utoa (&lock->owner), lock
->user_flock.l_start, lock->user_flock.l_len); } while (
0); _gf_log (this->name, "common.c", __FUNCTION__, 1071, GF_LOG_TRACE
, "%s (pid=%d) lk-owner:%s %""ll" "d"" - %""ll" "d"" => NOK"
, lock->fl_type == 2 ? "Unlock" : "Lock", lock->client_pid
, lkowner_utoa (&lock->owner), lock->user_flock.l_start
, lock->user_flock.l_len); } while (0)
;
1072 errno(*__errno_location ()) = EAGAIN11;
1073 ret = -1;
1074 }
1075 }
1076 pthread_mutex_unlock (&pl_inode->mutex);
1077
1078 grant_blocked_locks (this, pl_inode);
1079
1080 do_blocked_rw (pl_inode);
1081
1082 return ret;
1083}
1084
1085
1086posix_lock_t *
1087pl_getlk (pl_inode_t *pl_inode, posix_lock_t *lock)
1088{
1089 posix_lock_t *conf = NULL((void*)0);
1090
1091 conf = first_conflicting_overlap (pl_inode, lock);
1092
1093 if (conf == NULL((void*)0)) {
1094 lock->fl_type = F_UNLCK2;
1095 return lock;
1096 }
1097
1098 return conf;
1099}