Debian Codegraph @

xlators/cluster/afr/src/afr-lk-common.c

raw
1 /*
2 Copyright (c) 2008-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
11 #include "afr-transaction.h"
12 #include "afr-messages.h"
13
14 #include <signal.h>
15
16 #define LOCKED_NO 0x0 /* no lock held */
17 #define LOCKED_YES 0x1 /* for DATA, METADATA, ENTRY and higher_path */
18 #define LOCKED_LOWER 0x2 /* for lower path */
19
20 static void
21 afr_lockee_cleanup(afr_lockee_t *lockee)
22 {
23 if (lockee->fd) {
24 fd_unref(lockee->fd);
25 lockee->fd = NULL;
26 } else {
27 loc_wipe(&lockee->loc);
28 }
29
30 GF_FREE(lockee->basename);
31 lockee->basename = NULL;
32 GF_FREE(lockee->locked_nodes);
33 lockee->locked_nodes = NULL;
34
35 return;
36 }
37
38 void
39 afr_lockees_cleanup(afr_internal_lock_t *int_lock)
40 {
41 int i = 0;
42
43 for (i = 0; i < int_lock->lockee_count; i++) {
44 afr_lockee_cleanup(&int_lock->lockee[i]);
45 }
46
47 return;
48 }
49 int
50 afr_entry_lockee_cmp(const void *l1, const void *l2)
51 {
52 const afr_lockee_t *r1 = l1;
53 const afr_lockee_t *r2 = l2;
54 int ret = 0;
55 uuid_t gfid1 = {0};
56 uuid_t gfid2 = {0};
57
58 loc_gfid((loc_t *)&r1->loc, gfid1);
59 loc_gfid((loc_t *)&r2->loc, gfid2);
60 ret = gf_uuid_compare(gfid1, gfid2);
61 /*Entrylks with NULL basename are the 'smallest'*/
62 if (ret == 0) {
63 if (!r1->basename)
64 return -1;
65 if (!r2->basename)
66 return 1;
67 ret = strcmp(r1->basename, r2->basename);
68 }
69
70 if (ret <= 0)
71 return -1;
72 else
73 return 1;
74 }
75
76 static int
77 afr_lock_blocking(call_frame_t *frame, xlator_t *this, int child_index);
78
79 void
80 afr_set_lk_owner(call_frame_t *frame, xlator_t *this, void *lk_owner)
81 {
82 gf_msg_trace(this->name, 0, "Setting lk-owner=%llu",
83 (unsigned long long)(unsigned long)lk_owner);
84
85 set_lk_owner_from_ptr(&frame->root->lk_owner, lk_owner);
86 }
87
88 static int32_t
89 internal_lock_count(call_frame_t *frame, xlator_t *this)
90 {
91 afr_local_t *local = NULL;
92 afr_private_t *priv = NULL;
93 int32_t call_count = 0;
94 int i = 0;
95
96 local = frame->local;
97 priv = this->private;
98
99 for (i = 0; i < priv->child_count; i++) {
100 if (local->child_up[i])
101 ++call_count;
102 }
103
104 return call_count;
105 }
106
107 int
108 afr_add_entry_lockee(afr_local_t *local, loc_t *loc, char *basename,
109 int child_count)
110 {
111 int ret = -ENOMEM;
112 afr_internal_lock_t *int_lock = &local->internal_lock;
113 afr_lockee_t *lockee = &int_lock->lockee[int_lock->lockee_count];
114
115 GF_ASSERT(int_lock->lockee_count < AFR_LOCKEE_COUNT_MAX);
116 loc_copy(&lockee->loc, loc);
117 lockee->basename = (basename) ? gf_strdup(basename) : NULL;
118 if (basename && !lockee->basename)
119 goto out;
120
121 lockee->locked_count = 0;
122 lockee->locked_nodes = GF_CALLOC(child_count, sizeof(*lockee->locked_nodes),
123 gf_afr_mt_afr_node_character);
124
125 if (!lockee->locked_nodes)
126 goto out;
127
128 ret = 0;
129 int_lock->lockee_count++;
130 out:
131 if (ret) {
132 afr_lockee_cleanup(lockee);
133 }
134 return ret;
135 }
136
137 int
138 afr_add_inode_lockee(afr_local_t *local, int child_count)
139 {
140 int ret = -ENOMEM;
141 afr_internal_lock_t *int_lock = &local->internal_lock;
142 afr_lockee_t *lockee = &int_lock->lockee[int_lock->lockee_count];
143
144 if (local->fd) {
145 lockee->fd = fd_ref(local->fd);
146 } else {
147 loc_copy(&lockee->loc, &local->loc);
148 }
149
150 lockee->locked_count = 0;
151 lockee->locked_nodes = GF_CALLOC(child_count, sizeof(*lockee->locked_nodes),
152 gf_afr_mt_afr_node_character);
153
154 if (!lockee->locked_nodes)
155 goto out;
156
157 ret = 0;
158 int_lock->lockee_count++;
159 out:
160 if (ret) {
161 afr_lockee_cleanup(lockee);
162 }
163 return ret;
164 }
165
166 static int
167 initialize_internal_lock_variables(call_frame_t *frame, xlator_t *this)
168 {
169 afr_local_t *local = NULL;
170 afr_internal_lock_t *int_lock = NULL;
171 afr_private_t *priv = NULL;
172
173 int i = 0;
174
175 priv = this->private;
176 local = frame->local;
177 int_lock = &local->internal_lock;
178
179 int_lock->lock_count = 0;
180 int_lock->lock_op_ret = -1;
181 int_lock->lock_op_errno = 0;
182 int_lock->lk_attempted_count = 0;
183
184 for (i = 0; i < AFR_LOCKEE_COUNT_MAX; i++) {
185 if (!int_lock->lockee[i].locked_nodes)
186 break;
187 int_lock->lockee[i].locked_count = 0;
188 memset(int_lock->lockee[i].locked_nodes, 0,
189 sizeof(*int_lock->lockee[i].locked_nodes) * priv->child_count);
190 }
191
192 return 0;
193 }
194
195 static int
196 afr_lockee_locked_nodes_count(afr_internal_lock_t *int_lock)
197 {
198 int call_count = 0;
199 int i = 0;
200
201 for (i = 0; i < int_lock->lockee_count; i++)
202 call_count += int_lock->lockee[i].locked_count;
203
204 return call_count;
205 }
206
207 int
208 afr_locked_nodes_count(unsigned char *locked_nodes, int child_count)
209
210 {
211 int i = 0;
212 int call_count = 0;
213
214 for (i = 0; i < child_count; i++) {
215 if (locked_nodes[i] & LOCKED_YES)
216 call_count++;
217 }
218
219 return call_count;
220 }
221
222 static void
223 afr_log_locks_failure(call_frame_t *frame, char *where, char *what,
224 int op_errno)
225 {
226 xlator_t *this = frame->this;
227 gf_lkowner_t *lk_owner = &frame->root->lk_owner;
228 afr_local_t *local = frame->local;
229 const char *fop = NULL;
230 char *gfid = NULL;
231 const char *name = NULL;
232
233 fop = gf_fop_list[local->op];
234
235 switch (local->transaction.type) {
236 case AFR_ENTRY_RENAME_TRANSACTION:
237 case AFR_ENTRY_TRANSACTION:
238 switch (local->op) {
239 case GF_FOP_LINK:
240 gfid = uuid_utoa(local->newloc.pargfid);
241 name = local->newloc.name;
242 break;
243 default:
244 gfid = uuid_utoa(local->loc.pargfid);
245 name = local->loc.name;
246 break;
247 }
248 gf_msg(this->name, GF_LOG_WARNING, op_errno,
249 AFR_MSG_INTERNAL_LKS_FAILED,
250 "Unable to do entry %s with lk-owner:%s on %s "
251 "while attempting %s on {pgfid:%s, name:%s}.",
252 what, lkowner_utoa(lk_owner), where, fop, gfid, name);
253 break;
254 case AFR_DATA_TRANSACTION:
255 case AFR_METADATA_TRANSACTION:
256 gfid = uuid_utoa(local->inode->gfid);
257 gf_msg(this->name, GF_LOG_WARNING, op_errno,
258 AFR_MSG_INTERNAL_LKS_FAILED,
259 "Unable to do inode %s with lk-owner:%s on %s "
260 "while attempting %s on gfid:%s.",
261 what, lkowner_utoa(lk_owner), where, fop, gfid);
262 break;
263 }
264 }
265
266 static int32_t
267 afr_unlock_common_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
268 int32_t op_ret, int32_t op_errno, dict_t *xdata)
269 {
270 afr_local_t *local = NULL;
271 afr_private_t *priv = NULL;
272 afr_internal_lock_t *int_lock = NULL;
273 int lockee_num = 0;
274 int call_count = 0;
275 int child_index = 0;
276 int ret = 0;
277
278 local = frame->local;
279 int_lock = &local->internal_lock;
280 priv = this->private;
281 lockee_num = (int)((long)cookie) / priv->child_count;
282 child_index = (int)((long)cookie) % priv->child_count;
283
284 if (op_ret < 0 && op_errno != ENOTCONN && op_errno != EBADFD) {
285 afr_log_locks_failure(frame, priv->children[child_index]->name,
286 "unlock", op_errno);
287 }
288
289 int_lock->lockee[lockee_num].locked_nodes[child_index] &= LOCKED_NO;
290 if (local->transaction.type == AFR_DATA_TRANSACTION && op_ret != 1)
291 ret = afr_write_subvol_reset(frame, this);
292
293 LOCK(&frame->lock);
294 {
295 call_count = --int_lock->lk_call_count;
296 }
297 UNLOCK(&frame->lock);
298
299 if (call_count == 0) {
300 int_lock->lock_cbk(frame, this);
301 }
302
303 return ret;
304 }
305
306 static void
307 afr_internal_lock_wind(call_frame_t *frame,
308 int32_t (*cbk)(call_frame_t *, void *, xlator_t *,
309 int32_t, int32_t, dict_t *),
310 void *cookie, int child, int lockee_num,
311 gf_boolean_t blocking, gf_boolean_t unlock)
312 {
313 afr_local_t *local = frame->local;
314 xlator_t *this = frame->this;
315 afr_private_t *priv = this->private;
316 afr_internal_lock_t *int_lock = &local->internal_lock;
317 entrylk_cmd cmd = ENTRYLK_LOCK_NB;
318 int32_t cmd1 = F_SETLK;
319 struct gf_flock flock;
320
321 switch (local->transaction.type) {
322 case AFR_ENTRY_TRANSACTION:
323 case AFR_ENTRY_RENAME_TRANSACTION:
324 if (unlock) {
325 cmd = ENTRYLK_UNLOCK;
326 } else if (blocking) { /*Doesn't make sense to have blocking
327 unlock*/
328 cmd = ENTRYLK_LOCK;
329 }
330
331 if (local->fd) {
332 STACK_WIND_COOKIE(frame, cbk, cookie, priv->children[child],
333 priv->children[child]->fops->fentrylk,
334 int_lock->domain,
335 int_lock->lockee[lockee_num].fd,
336 int_lock->lockee[lockee_num].basename, cmd,
337 ENTRYLK_WRLCK, NULL);
338 } else {
339 STACK_WIND_COOKIE(frame, cbk, cookie, priv->children[child],
340 priv->children[child]->fops->entrylk,
341 int_lock->domain,
342 &int_lock->lockee[lockee_num].loc,
343 int_lock->lockee[lockee_num].basename, cmd,
344 ENTRYLK_WRLCK, NULL);
345 }
346 break;
347
348 case AFR_DATA_TRANSACTION:
349 case AFR_METADATA_TRANSACTION:
350 gf_flock_copy(&flock, &int_lock->lockee[lockee_num].flock);
351 if (unlock) {
352 flock.l_type = F_UNLCK;
353 } else if (blocking) { /*Doesn't make sense to have blocking
354 unlock*/
355 cmd1 = F_SETLKW;
356 }
357
358 if (local->fd) {
359 STACK_WIND_COOKIE(
360 frame, cbk, cookie, priv->children[child],
361 priv->children[child]->fops->finodelk, int_lock->domain,
362 int_lock->lockee[lockee_num].fd, cmd1, &flock, NULL);
363 } else {
364 STACK_WIND_COOKIE(
365 frame, cbk, cookie, priv->children[child],
366 priv->children[child]->fops->inodelk, int_lock->domain,
367 &int_lock->lockee[lockee_num].loc, cmd1, &flock, NULL);
368 }
369 break;
370 }
371 }
372
373 static int
374 afr_unlock_now(call_frame_t *frame, xlator_t *this)
375 {
376 afr_internal_lock_t *int_lock = NULL;
377 afr_local_t *local = NULL;
378 afr_private_t *priv = NULL;
379 int call_count = 0;
380 int child_index = 0;
381 int lockee_num = 0;
382 int i = -1;
383
384 local = frame->local;
385 int_lock = &local->internal_lock;
386 priv = this->private;
387
388 call_count = afr_lockee_locked_nodes_count(int_lock);
389
390 int_lock->lk_call_count = call_count;
391
392 if (!call_count) {
393 gf_msg_trace(this->name, 0, "No internal locks unlocked");
394 int_lock->lock_cbk(frame, this);
395 goto out;
396 }
397
398 for (i = 0; i < int_lock->lockee_count * priv->child_count; i++) {
399 lockee_num = i / priv->child_count;
400 child_index = i % priv->child_count;
401 if (int_lock->lockee[lockee_num].locked_nodes[child_index] &
402 LOCKED_YES) {
403 afr_internal_lock_wind(frame, afr_unlock_common_cbk,
404 (void *)(long)i, child_index, lockee_num,
405 _gf_false, _gf_true);
406 if (!--call_count)
407 break;
408 }
409 }
410
411 out:
412 return 0;
413 }
414
415 static int32_t
416 afr_lock_cbk(call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret,
417 int32_t op_errno, dict_t *xdata)
418 {
419 afr_internal_lock_t *int_lock = NULL;
420 afr_local_t *local = NULL;
421 afr_private_t *priv = NULL;
422 int cky = (long)cookie;
423 int child_index = 0;
424 int lockee_num = 0;
425
426 priv = this->private;
427 local = frame->local;
428 int_lock = &local->internal_lock;
429
430 child_index = ((int)cky) % priv->child_count;
431 lockee_num = ((int)cky) / priv->child_count;
432
433 LOCK(&frame->lock);
434 {
435 if (op_ret == -1) {
436 if (op_errno == ENOSYS) {
437 /* return ENOTSUP */
438 gf_msg(this->name, GF_LOG_ERROR, ENOSYS,
439 AFR_MSG_LOCK_XLATOR_NOT_LOADED,
440 "subvolume does not support locking. "
441 "please load features/locks xlator on server");
442 local->op_ret = op_ret;
443 int_lock->lock_op_ret = op_ret;
444 }
445
446 local->op_errno = op_errno;
447 int_lock->lock_op_errno = op_errno;
448 }
449
450 int_lock->lk_attempted_count++;
451 }
452 UNLOCK(&frame->lock);
453
454 if ((op_ret == -1) && (op_errno == ENOSYS)) {
455 afr_unlock_now(frame, this);
456 } else {
457 if (op_ret == 0) {
458 int_lock->lockee[lockee_num]
459 .locked_nodes[child_index] |= LOCKED_YES;
460 int_lock->lockee[lockee_num].locked_count++;
461 int_lock->lock_count++;
462 if (local->transaction.type == AFR_DATA_TRANSACTION) {
463 LOCK(&local->inode->lock);
464 {
465 local->inode_ctx->lock_count++;
466 }
467 UNLOCK(&local->inode->lock);
468 }
469 }
470 afr_lock_blocking(frame, this, cky + 1);
471 }
472
473 return 0;
474 }
475
476 static gf_boolean_t
477 _is_lock_wind_needed(afr_local_t *local, int child_index)
478 {
479 if (!local->child_up[child_index])
480 return _gf_false;
481
482 return _gf_true;
483 }
484
485 static gf_boolean_t
486 is_blocking_locks_count_sufficient(call_frame_t *frame, xlator_t *this)
487 {
488 afr_local_t *local = NULL;
489 afr_private_t *priv = NULL;
490 afr_internal_lock_t *int_lock = NULL;
491 int child = 0;
492 int nlockee = 0;
493 int lockee_count = 0;
494 gf_boolean_t ret = _gf_true;
495
496 local = frame->local;
497 priv = this->private;
498 int_lock = &local->internal_lock;
499 lockee_count = int_lock->lockee_count;
500
501 if (int_lock->lock_count == 0) {
502 afr_log_locks_failure(frame, "any subvolume", "lock",
503 int_lock->lock_op_errno);
504 return _gf_false;
505 }
506 /* For FOPS that take multiple sets of locks (mkdir, rename),
507 * there must be at least one brick on which the locks from
508 * all lock sets were successful. */
509 for (child = 0; child < priv->child_count; child++) {
510 ret = _gf_true;
511 for (nlockee = 0; nlockee < lockee_count; nlockee++) {
512 if (!(int_lock->lockee[nlockee].locked_nodes[child] & LOCKED_YES))
513 ret = _gf_false;
514 }
515 if (ret)
516 return ret;
517 }
518 if (!ret)
519 afr_log_locks_failure(frame, "all", "lock", int_lock->lock_op_errno);
520
521 return ret;
522 }
523
524 static int
525 afr_lock_blocking(call_frame_t *frame, xlator_t *this, int cookie)
526 {
527 afr_internal_lock_t *int_lock = NULL;
528 afr_local_t *local = NULL;
529 afr_private_t *priv = NULL;
530 uint64_t ctx = 0;
531 int child_index = 0;
532 int lockee_num = 0;
533
534 local = frame->local;
535 int_lock = &local->internal_lock;
536 priv = this->private;
537 child_index = cookie % priv->child_count;
538 lockee_num = cookie / priv->child_count;
539
540 if (local->fd) {
541 ctx = fd_ctx_get(local->fd, this);
542
543 if (!ctx) {
544 gf_msg(this->name, GF_LOG_INFO, 0, AFR_MSG_FD_CTX_GET_FAILED,
545 "unable to get fd ctx for fd=%p", local->fd);
546
547 local->op_ret = -1;
548 int_lock->lock_op_ret = -1;
549
550 afr_unlock_now(frame, this);
551
552 return 0;
553 }
554 }
555
556 if (int_lock->lk_expected_count == int_lock->lk_attempted_count) {
557 if (!is_blocking_locks_count_sufficient(frame, this)) {
558 local->op_ret = -1;
559 int_lock->lock_op_ret = -1;
560
561 afr_unlock_now(frame, this);
562
563 return 0;
564 }
565 }
566
567 if (int_lock->lk_expected_count == int_lock->lk_attempted_count) {
568 /* we're done locking */
569
570 gf_msg_debug(this->name, 0, "we're done locking");
571
572 int_lock->lock_op_ret = 0;
573 int_lock->lock_cbk(frame, this);
574 return 0;
575 }
576
577 if (!_is_lock_wind_needed(local, child_index)) {
578 afr_lock_blocking(frame, this, cookie + 1);
579 return 0;
580 }
581
582 afr_internal_lock_wind(frame, afr_lock_cbk, (void *)(long)cookie,
583 child_index, lockee_num, _gf_true, _gf_false);
584
585 return 0;
586 }
587
588 int32_t
589 afr_blocking_lock(call_frame_t *frame, xlator_t *this)
590 {
591 afr_internal_lock_t *int_lock = NULL;
592 afr_local_t *local = NULL;
593 afr_private_t *priv = NULL;
594 int up_count = 0;
595
596 priv = this->private;
597 local = frame->local;
598 int_lock = &local->internal_lock;
599
600 up_count = AFR_COUNT(local->child_up, priv->child_count);
601 int_lock->lk_call_count = int_lock->lk_expected_count =
602 (int_lock->lockee_count * up_count);
603 initialize_internal_lock_variables(frame, this);
604
605 afr_lock_blocking(frame, this, 0);
606
607 return 0;
608 }
609
610 static int32_t
611 afr_nb_internal_lock_cbk(call_frame_t *frame, void *cookie, xlator_t *this,
612 int32_t op_ret, int32_t op_errno, dict_t *xdata)
613 {
614 afr_internal_lock_t *int_lock = NULL;
615 afr_local_t *local = NULL;
616 int call_count = 0;
617 int child_index = 0;
618 int lockee_num = 0;
619 afr_private_t *priv = NULL;
620
621 priv = this->private;
622
623 child_index = ((long)cookie) % priv->child_count;
624 lockee_num = ((long)cookie) / priv->child_count;
625
626 local = frame->local;
627 int_lock = &local->internal_lock;
628
629 if (op_ret == 0 && local->transaction.type == AFR_DATA_TRANSACTION) {
630 LOCK(&local->inode->lock);
631 {
632 local->inode_ctx->lock_count++;
633 }
634 UNLOCK(&local->inode->lock);
635 }
636
637 LOCK(&frame->lock);
638 {
639 if (op_ret < 0) {
640 if (op_errno == ENOSYS) {
641 /* return ENOTSUP */
642 gf_msg(this->name, GF_LOG_ERROR, ENOSYS,
643 AFR_MSG_LOCK_XLATOR_NOT_LOADED,
644 "subvolume does not support "
645 "locking. please load features/locks"
646 " xlator on server");
647 local->op_ret = op_ret;
648 int_lock->lock_op_ret = op_ret;
649
650 int_lock->lock_op_errno = op_errno;
651 local->op_errno = op_errno;
652 }
653 } else if (op_ret == 0) {
654 int_lock->lockee[lockee_num]
655 .locked_nodes[child_index] |= LOCKED_YES;
656 int_lock->lockee[lockee_num].locked_count++;
657 int_lock->lock_count++;
658 }
659
660 call_count = --int_lock->lk_call_count;
661 }
662 UNLOCK(&frame->lock);
663
664 if (call_count == 0) {
665 gf_msg_trace(this->name, 0, "Last locking reply received");
666 /* all locks successful. Proceed to call FOP */
667 if (int_lock->lock_count == int_lock->lk_expected_count) {
668 gf_msg_trace(this->name, 0, "All servers locked. Calling the cbk");
669 int_lock->lock_op_ret = 0;
670 int_lock->lock_cbk(frame, this);
671 }
672 /* Not all locks were successful. Unlock and try locking
673 again, this time with serially blocking locks */
674 else {
675 gf_msg_trace(this->name, 0,
676 "%d servers locked. Trying again "
677 "with blocking calls",
678 int_lock->lock_count);
679
680 afr_unlock_now(frame, this);
681 }
682 }
683
684 return 0;
685 }
686
687 int
688 afr_lock_nonblocking(call_frame_t *frame, xlator_t *this)
689 {
690 afr_internal_lock_t *int_lock = NULL;
691 afr_local_t *local = NULL;
692 afr_private_t *priv = NULL;
693 afr_fd_ctx_t *fd_ctx = NULL;
694 int child = 0;
695 int lockee_num = 0;
696 int32_t call_count = 0;
697 int i = 0;
698 int ret = 0;
699
700 local = frame->local;
701 int_lock = &local->internal_lock;
702 priv = this->private;
703
704 initialize_internal_lock_variables(frame, this);
705
706 if (local->fd) {
707 fd_ctx = afr_fd_ctx_get(local->fd, this);
708 if (!fd_ctx) {
709 gf_msg(this->name, GF_LOG_INFO, 0, AFR_MSG_FD_CTX_GET_FAILED,
710 "unable to get fd ctx for fd=%p", local->fd);
711
712 local->op_ret = -1;
713 int_lock->lock_op_ret = -1;
714 local->op_errno = EINVAL;
715 int_lock->lock_op_errno = EINVAL;
716
717 afr_unlock_now(frame, this);
718 ret = -1;
719 goto out;
720 }
721 }
722
723 call_count = int_lock->lockee_count * internal_lock_count(frame, this);
724 int_lock->lk_call_count = call_count;
725 int_lock->lk_expected_count = call_count;
726
727 if (!call_count) {
728 gf_msg(this->name, GF_LOG_INFO, 0, AFR_MSG_INFO_COMMON,
729 "fd not open on any subvolumes. aborting.");
730 afr_unlock_now(frame, this);
731 goto out;
732 }
733
734 /* Send non-blocking lock calls only on up children
735 and where the fd has been opened */
736 for (i = 0; i < int_lock->lockee_count * priv->child_count; i++) {
737 child = i % priv->child_count;
738 lockee_num = i / priv->child_count;
739 if (local->child_up[child]) {
740 afr_internal_lock_wind(frame, afr_nb_internal_lock_cbk,
741 (void *)(long)i, child, lockee_num,
742 _gf_false, _gf_false);
743 if (!--call_count)
744 break;
745 }
746 }
747 out:
748 return ret;
749 }
750
751 int32_t
752 afr_unlock(call_frame_t *frame, xlator_t *this)
753 {
754 afr_local_t *local = NULL;
755 afr_lock_t *lock = NULL;
756
757 local = frame->local;
758
759 if (!local->transaction.eager_lock_on)
760 goto out;
761 lock = &local->inode_ctx->lock[local->transaction.type];
762 LOCK(&local->inode->lock);
763 {
764 list_del_init(&local->transaction.owner_list);
765 if (list_empty(&lock->owners) && list_empty(&lock->post_op)) {
766 local->transaction.do_eager_unlock = _gf_true;
767 /*TODO: Need to get metadata use on_disk and inherit/uninherit
768 *GF_ASSERT (!local->inode_ctx->on_disk[local->transaction.type]);
769 *GF_ASSERT (!local->inode_ctx->inherited[local->transaction.type]);
770 */
771 GF_ASSERT(lock->release);
772 }
773 }
774 UNLOCK(&local->inode->lock);
775 if (!local->transaction.do_eager_unlock) {
776 local->internal_lock.lock_cbk(frame, this);
777 return 0;
778 }
779
780 out:
781 afr_unlock_now(frame, this);
782 return 0;
783 }