tevent: add tevent_req_defer_callback()
[Samba/gebeck_regimport.git] / source3 / lib / g_lock.c
blob4bda7c8e6c9f37285f7eccb4fb413e4aebde90bc
1 /*
2 Unix SMB/CIFS implementation.
3 global locks based on dbwrap and messaging
4 Copyright (C) 2009 by Volker Lendecke
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "system/filesys.h"
22 #include "g_lock.h"
23 #include "util_tdb.h"
24 #include "ctdbd_conn.h"
25 #include "../lib/util/select.h"
26 #include "system/select.h"
27 #include "messages.h"
29 static NTSTATUS g_lock_force_unlock(struct g_lock_ctx *ctx, const char *name,
30 struct server_id pid);
32 struct g_lock_ctx {
33 struct db_context *db;
34 struct messaging_context *msg;
38 * The "g_lock.tdb" file contains records, indexed by the 0-terminated
39 * lockname. The record contains an array of "struct g_lock_rec"
40 * structures. Waiters have the lock_type with G_LOCK_PENDING or'ed.
43 struct g_lock_rec {
44 enum g_lock_type lock_type;
45 struct server_id pid;
48 struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
49 struct messaging_context *msg)
51 struct g_lock_ctx *result;
53 result = talloc(mem_ctx, struct g_lock_ctx);
54 if (result == NULL) {
55 return NULL;
57 result->msg = msg;
59 result->db = db_open(result, lock_path("g_lock.tdb"), 0,
60 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
61 O_RDWR|O_CREAT, 0600);
62 if (result->db == NULL) {
63 DEBUG(1, ("g_lock_init: Could not open g_lock.tdb"));
64 TALLOC_FREE(result);
65 return NULL;
67 return result;
70 static bool g_lock_conflicts(enum g_lock_type lock_type,
71 const struct g_lock_rec *rec)
73 enum g_lock_type rec_lock = rec->lock_type;
75 if ((rec_lock & G_LOCK_PENDING) != 0) {
76 return false;
80 * Only tested write locks so far. Very likely this routine
81 * needs to be fixed for read locks....
83 if ((lock_type == G_LOCK_READ) && (rec_lock == G_LOCK_READ)) {
84 return false;
86 return true;
89 static bool g_lock_parse(TALLOC_CTX *mem_ctx, TDB_DATA data,
90 int *pnum_locks, struct g_lock_rec **plocks)
92 int i, num_locks;
93 struct g_lock_rec *locks;
95 if ((data.dsize % sizeof(struct g_lock_rec)) != 0) {
96 DEBUG(1, ("invalid lock record length %d\n", (int)data.dsize));
97 return false;
100 num_locks = data.dsize / sizeof(struct g_lock_rec);
101 locks = talloc_array(mem_ctx, struct g_lock_rec, num_locks);
102 if (locks == NULL) {
103 DEBUG(1, ("talloc failed\n"));
104 return false;
107 memcpy(locks, data.dptr, data.dsize);
109 DEBUG(10, ("locks:\n"));
110 for (i=0; i<num_locks; i++) {
111 DEBUGADD(10, ("%s: %s %s\n",
112 server_id_str(talloc_tos(), &locks[i].pid),
113 ((locks[i].lock_type & 1) == G_LOCK_READ) ?
114 "read" : "write",
115 (locks[i].lock_type & G_LOCK_PENDING) ?
116 "(pending)" : "(owner)"));
118 if (((locks[i].lock_type & G_LOCK_PENDING) == 0)
119 && !process_exists(locks[i].pid)) {
121 DEBUGADD(10, ("lock owner %s died -- discarding\n",
122 server_id_str(talloc_tos(),
123 &locks[i].pid)));
125 if (i < (num_locks-1)) {
126 locks[i] = locks[num_locks-1];
128 num_locks -= 1;
132 *plocks = locks;
133 *pnum_locks = num_locks;
134 return true;
137 static void g_lock_cleanup(int *pnum_locks, struct g_lock_rec *locks)
139 int i, num_locks;
141 num_locks = *pnum_locks;
143 DEBUG(10, ("g_lock_cleanup: %d locks\n", num_locks));
145 for (i=0; i<num_locks; i++) {
146 if (process_exists(locks[i].pid)) {
147 continue;
149 DEBUGADD(10, ("%s does not exist -- discarding\n",
150 server_id_str(talloc_tos(), &locks[i].pid)));
152 if (i < (num_locks-1)) {
153 locks[i] = locks[num_locks-1];
155 num_locks -= 1;
157 *pnum_locks = num_locks;
158 return;
161 static struct g_lock_rec *g_lock_addrec(TALLOC_CTX *mem_ctx,
162 struct g_lock_rec *locks,
163 int *pnum_locks,
164 const struct server_id pid,
165 enum g_lock_type lock_type)
167 struct g_lock_rec *result;
168 int num_locks = *pnum_locks;
170 result = talloc_realloc(mem_ctx, locks, struct g_lock_rec,
171 num_locks+1);
172 if (result == NULL) {
173 return NULL;
176 result[num_locks].pid = pid;
177 result[num_locks].lock_type = lock_type;
178 *pnum_locks += 1;
179 return result;
182 static void g_lock_got_retry(struct messaging_context *msg,
183 void *private_data,
184 uint32_t msg_type,
185 struct server_id server_id,
186 DATA_BLOB *data);
188 static NTSTATUS g_lock_trylock(struct g_lock_ctx *ctx, const char *name,
189 enum g_lock_type lock_type)
191 struct db_record *rec = NULL;
192 struct g_lock_rec *locks = NULL;
193 int i, num_locks;
194 struct server_id self;
195 int our_index;
196 TDB_DATA data;
197 NTSTATUS status = NT_STATUS_OK;
198 NTSTATUS store_status;
200 again:
201 rec = ctx->db->fetch_locked(ctx->db, talloc_tos(),
202 string_term_tdb_data(name));
203 if (rec == NULL) {
204 DEBUG(10, ("fetch_locked(\"%s\") failed\n", name));
205 status = NT_STATUS_LOCK_NOT_GRANTED;
206 goto done;
209 if (!g_lock_parse(talloc_tos(), rec->value, &num_locks, &locks)) {
210 DEBUG(10, ("g_lock_parse for %s failed\n", name));
211 status = NT_STATUS_INTERNAL_ERROR;
212 goto done;
215 self = messaging_server_id(ctx->msg);
216 our_index = -1;
218 for (i=0; i<num_locks; i++) {
219 if (procid_equal(&self, &locks[i].pid)) {
220 if (our_index != -1) {
221 DEBUG(1, ("g_lock_trylock: Added ourself "
222 "twice!\n"));
223 status = NT_STATUS_INTERNAL_ERROR;
224 goto done;
226 if ((locks[i].lock_type & G_LOCK_PENDING) == 0) {
227 DEBUG(1, ("g_lock_trylock: Found ourself not "
228 "pending!\n"));
229 status = NT_STATUS_INTERNAL_ERROR;
230 goto done;
233 our_index = i;
235 /* never conflict with ourself */
236 continue;
238 if (g_lock_conflicts(lock_type, &locks[i])) {
239 struct server_id pid = locks[i].pid;
241 if (!process_exists(pid)) {
242 TALLOC_FREE(locks);
243 TALLOC_FREE(rec);
244 status = g_lock_force_unlock(ctx, name, pid);
245 if (!NT_STATUS_IS_OK(status)) {
246 DEBUG(1, ("Could not unlock dead lock "
247 "holder!\n"));
248 goto done;
250 goto again;
252 lock_type |= G_LOCK_PENDING;
256 if (our_index == -1) {
257 /* First round, add ourself */
259 locks = g_lock_addrec(talloc_tos(), locks, &num_locks,
260 self, lock_type);
261 if (locks == NULL) {
262 DEBUG(10, ("g_lock_addrec failed\n"));
263 status = NT_STATUS_NO_MEMORY;
264 goto done;
266 } else {
268 * Retry. We were pending last time. Overwrite the
269 * stored lock_type with what we calculated, we might
270 * have acquired the lock this time.
272 locks[our_index].lock_type = lock_type;
275 if (NT_STATUS_IS_OK(status) && ((lock_type & G_LOCK_PENDING) == 0)) {
277 * Walk through the list of locks, search for dead entries
279 g_lock_cleanup(&num_locks, locks);
282 data = make_tdb_data((uint8_t *)locks, num_locks * sizeof(*locks));
283 store_status = rec->store(rec, data, 0);
284 if (!NT_STATUS_IS_OK(store_status)) {
285 DEBUG(1, ("rec->store failed: %s\n",
286 nt_errstr(store_status)));
287 status = store_status;
290 done:
291 TALLOC_FREE(locks);
292 TALLOC_FREE(rec);
294 if (NT_STATUS_IS_OK(status) && (lock_type & G_LOCK_PENDING) != 0) {
295 return STATUS_PENDING;
298 return NT_STATUS_OK;
301 NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
302 enum g_lock_type lock_type, struct timeval timeout)
304 struct tevent_timer *te = NULL;
305 NTSTATUS status;
306 bool retry = false;
307 struct timeval timeout_end;
308 struct timeval time_now;
310 DEBUG(10, ("Trying to acquire lock %d for %s\n", (int)lock_type,
311 name));
313 if (lock_type & ~1) {
314 DEBUG(1, ("Got invalid lock type %d for %s\n",
315 (int)lock_type, name));
316 return NT_STATUS_INVALID_PARAMETER;
319 #ifdef CLUSTER_SUPPORT
320 if (lp_clustering()) {
321 status = ctdb_watch_us(messaging_ctdbd_connection());
322 if (!NT_STATUS_IS_OK(status)) {
323 DEBUG(10, ("could not register retry with ctdb: %s\n",
324 nt_errstr(status)));
325 goto done;
328 #endif
330 status = messaging_register(ctx->msg, &retry, MSG_DBWRAP_G_LOCK_RETRY,
331 g_lock_got_retry);
332 if (!NT_STATUS_IS_OK(status)) {
333 DEBUG(10, ("messaging_register failed: %s\n",
334 nt_errstr(status)));
335 return status;
338 time_now = timeval_current();
339 timeout_end = timeval_sum(&time_now, &timeout);
341 while (true) {
342 struct pollfd *pollfds;
343 int num_pollfds;
344 int saved_errno;
345 int ret;
346 struct timeval timeout_remaining, select_timeout;
348 status = g_lock_trylock(ctx, name, lock_type);
349 if (NT_STATUS_IS_OK(status)) {
350 DEBUG(10, ("Got lock %s\n", name));
351 break;
353 if (!NT_STATUS_EQUAL(status, STATUS_PENDING)) {
354 DEBUG(10, ("g_lock_trylock failed: %s\n",
355 nt_errstr(status)));
356 break;
359 DEBUG(10, ("g_lock_trylock: Did not get lock, waiting...\n"));
361 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
362 * !!! HACK ALERT --- FIX ME !!!
363 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364 * What we really want to do here is to react to
365 * MSG_DBWRAP_G_LOCK_RETRY messages that are either sent
366 * by a client doing g_lock_unlock or by ourselves when
367 * we receive a CTDB_SRVID_SAMBA_NOTIFY or
368 * CTDB_SRVID_RECONFIGURE message from ctdbd, i.e. when
369 * either a client holding a lock or a complete node
370 * has died.
372 * Doing this properly involves calling tevent_loop_once(),
373 * but doing this here with the main ctdbd messaging context
374 * creates a nested event loop when g_lock_lock() is called
375 * from the main event loop, e.g. in a tcon_and_X where the
376 * share_info.tdb needs to be initialized and is locked by
377 * another process, or when the remore registry is accessed
378 * for writing and some other process already holds a lock
379 * on the registry.tdb.
381 * So as a quick fix, we act a little coarsely here: we do
382 * a select on the ctdb connection fd and when it is readable
383 * or we get EINTR, then we retry without actually parsing
384 * any ctdb packages or dispatching messages. This means that
385 * we retry more often than intended by design, but this does
386 * not harm and it is unobtrusive. When we have finished,
387 * the main loop will pick up all the messages and ctdb
388 * packets. The only extra twist is that we cannot use timed
389 * events here but have to handcode a timeout.
393 * We allocate 2 entries here. One is needed anyway for
394 * sys_poll and in the clustering case we might have to add
395 * the ctdb fd. This avoids the realloc then.
397 pollfds = talloc_array(talloc_tos(), struct pollfd, 2);
398 if (pollfds == NULL) {
399 status = NT_STATUS_NO_MEMORY;
400 break;
402 num_pollfds = 0;
404 #ifdef CLUSTER_SUPPORT
405 if (lp_clustering()) {
406 struct ctdbd_connection *conn;
407 conn = messaging_ctdbd_connection();
409 pollfds[0].fd = ctdbd_conn_get_fd(conn);
410 pollfds[0].events = POLLIN|POLLHUP;
412 num_pollfds += 1;
414 #endif
416 time_now = timeval_current();
417 timeout_remaining = timeval_until(&time_now, &timeout_end);
418 select_timeout = timeval_set(60, 0);
420 select_timeout = timeval_min(&select_timeout,
421 &timeout_remaining);
423 ret = sys_poll(pollfds, num_pollfds,
424 timeval_to_msec(select_timeout));
427 * We're not *really interested in the actual flags. We just
428 * need to retry this whole thing.
430 saved_errno = errno;
431 TALLOC_FREE(pollfds);
432 errno = saved_errno;
434 if (ret == -1) {
435 if (errno != EINTR) {
436 DEBUG(1, ("error calling select: %s\n",
437 strerror(errno)));
438 status = NT_STATUS_INTERNAL_ERROR;
439 break;
442 * errno == EINTR:
443 * This means a signal was received.
444 * It might have been a MSG_DBWRAP_G_LOCK_RETRY message.
445 * ==> retry
447 } else if (ret == 0) {
448 if (timeval_expired(&timeout_end)) {
449 DEBUG(10, ("g_lock_lock timed out\n"));
450 status = NT_STATUS_LOCK_NOT_GRANTED;
451 break;
452 } else {
453 DEBUG(10, ("select returned 0 but timeout not "
454 "not expired, retrying\n"));
456 } else if (ret != 1) {
457 DEBUG(1, ("invalid return code of select: %d\n", ret));
458 status = NT_STATUS_INTERNAL_ERROR;
459 break;
462 * ret == 1:
463 * This means ctdbd has sent us some data.
464 * Might be a CTDB_SRVID_RECONFIGURE or a
465 * CTDB_SRVID_SAMBA_NOTIFY message.
466 * ==> retry
470 #ifdef CLUSTER_SUPPORT
471 done:
472 #endif
474 if (!NT_STATUS_IS_OK(status)) {
475 NTSTATUS unlock_status;
477 unlock_status = g_lock_unlock(ctx, name);
479 if (!NT_STATUS_IS_OK(unlock_status)) {
480 DEBUG(1, ("Could not remove ourself from the locking "
481 "db: %s\n", nt_errstr(status)));
485 messaging_deregister(ctx->msg, MSG_DBWRAP_G_LOCK_RETRY, &retry);
486 TALLOC_FREE(te);
488 return status;
491 static void g_lock_got_retry(struct messaging_context *msg,
492 void *private_data,
493 uint32_t msg_type,
494 struct server_id server_id,
495 DATA_BLOB *data)
497 bool *pretry = (bool *)private_data;
499 DEBUG(10, ("Got retry message from pid %s\n",
500 server_id_str(talloc_tos(), &server_id)));
502 *pretry = true;
505 static NTSTATUS g_lock_force_unlock(struct g_lock_ctx *ctx, const char *name,
506 struct server_id pid)
508 struct db_record *rec = NULL;
509 struct g_lock_rec *locks = NULL;
510 int i, num_locks;
511 enum g_lock_type lock_type;
512 NTSTATUS status;
514 rec = ctx->db->fetch_locked(ctx->db, talloc_tos(),
515 string_term_tdb_data(name));
516 if (rec == NULL) {
517 DEBUG(10, ("fetch_locked(\"%s\") failed\n", name));
518 status = NT_STATUS_INTERNAL_ERROR;
519 goto done;
522 if (!g_lock_parse(talloc_tos(), rec->value, &num_locks, &locks)) {
523 DEBUG(10, ("g_lock_parse for %s failed\n", name));
524 status = NT_STATUS_INTERNAL_ERROR;
525 goto done;
528 for (i=0; i<num_locks; i++) {
529 if (procid_equal(&pid, &locks[i].pid)) {
530 break;
534 if (i == num_locks) {
535 DEBUG(10, ("g_lock_force_unlock: Lock not found\n"));
536 status = NT_STATUS_INTERNAL_ERROR;
537 goto done;
540 lock_type = locks[i].lock_type;
542 if (i < (num_locks-1)) {
543 locks[i] = locks[num_locks-1];
545 num_locks -= 1;
547 if (num_locks == 0) {
548 status = rec->delete_rec(rec);
549 } else {
550 TDB_DATA data;
551 data = make_tdb_data((uint8_t *)locks,
552 sizeof(struct g_lock_rec) * num_locks);
553 status = rec->store(rec, data, 0);
556 if (!NT_STATUS_IS_OK(status)) {
557 DEBUG(1, ("g_lock_force_unlock: Could not store record: %s\n",
558 nt_errstr(status)));
559 goto done;
562 TALLOC_FREE(rec);
564 if ((lock_type & G_LOCK_PENDING) == 0) {
565 int num_wakeups = 0;
568 * We've been the lock holder. Others to retry. Don't
569 * tell all others to avoid a thundering herd. In case
570 * this leads to a complete stall because we miss some
571 * processes, the loop in g_lock_lock tries at least
572 * once a minute.
575 for (i=0; i<num_locks; i++) {
576 if ((locks[i].lock_type & G_LOCK_PENDING) == 0) {
577 continue;
579 if (!process_exists(locks[i].pid)) {
580 continue;
584 * Ping all waiters to retry
586 status = messaging_send(ctx->msg, locks[i].pid,
587 MSG_DBWRAP_G_LOCK_RETRY,
588 &data_blob_null);
589 if (!NT_STATUS_IS_OK(status)) {
590 DEBUG(1, ("sending retry to %s failed: %s\n",
591 server_id_str(talloc_tos(),
592 &locks[i].pid),
593 nt_errstr(status)));
594 } else {
595 num_wakeups += 1;
597 if (num_wakeups > 5) {
598 break;
602 done:
604 * For the error path, TALLOC_FREE(rec) as well. In the good
605 * path we have already freed it.
607 TALLOC_FREE(rec);
609 TALLOC_FREE(locks);
610 return status;
613 NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name)
615 NTSTATUS status;
617 status = g_lock_force_unlock(ctx, name, messaging_server_id(ctx->msg));
619 #ifdef CLUSTER_SUPPORT
620 if (lp_clustering()) {
621 ctdb_unwatch(messaging_ctdbd_connection());
623 #endif
624 return status;
627 struct g_lock_locks_state {
628 int (*fn)(const char *name, void *private_data);
629 void *private_data;
632 static int g_lock_locks_fn(struct db_record *rec, void *priv)
634 struct g_lock_locks_state *state = (struct g_lock_locks_state *)priv;
636 if ((rec->key.dsize == 0) || (rec->key.dptr[rec->key.dsize-1] != 0)) {
637 DEBUG(1, ("invalid key in g_lock.tdb, ignoring\n"));
638 return 0;
640 return state->fn((char *)rec->key.dptr, state->private_data);
643 int g_lock_locks(struct g_lock_ctx *ctx,
644 int (*fn)(const char *name, void *private_data),
645 void *private_data)
647 struct g_lock_locks_state state;
649 state.fn = fn;
650 state.private_data = private_data;
652 return ctx->db->traverse_read(ctx->db, g_lock_locks_fn, &state);
655 NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
656 int (*fn)(struct server_id pid,
657 enum g_lock_type lock_type,
658 void *private_data),
659 void *private_data)
661 TDB_DATA data;
662 int i, num_locks;
663 struct g_lock_rec *locks = NULL;
664 bool ret;
666 if (ctx->db->fetch(ctx->db, talloc_tos(), string_term_tdb_data(name),
667 &data) != 0) {
668 return NT_STATUS_NOT_FOUND;
671 if ((data.dsize == 0) || (data.dptr == NULL)) {
672 return NT_STATUS_OK;
675 ret = g_lock_parse(talloc_tos(), data, &num_locks, &locks);
677 TALLOC_FREE(data.dptr);
679 if (!ret) {
680 DEBUG(10, ("g_lock_parse for %s failed\n", name));
681 return NT_STATUS_INTERNAL_ERROR;
684 for (i=0; i<num_locks; i++) {
685 if (fn(locks[i].pid, locks[i].lock_type, private_data) != 0) {
686 break;
689 TALLOC_FREE(locks);
690 return NT_STATUS_OK;
693 struct g_lock_get_state {
694 bool found;
695 struct server_id *pid;
698 static int g_lock_get_fn(struct server_id pid, enum g_lock_type lock_type,
699 void *priv)
701 struct g_lock_get_state *state = (struct g_lock_get_state *)priv;
703 if ((lock_type & G_LOCK_PENDING) != 0) {
704 return 0;
707 state->found = true;
708 *state->pid = pid;
709 return 1;
712 NTSTATUS g_lock_get(struct g_lock_ctx *ctx, const char *name,
713 struct server_id *pid)
715 struct g_lock_get_state state;
716 NTSTATUS status;
718 state.found = false;
719 state.pid = pid;
721 status = g_lock_dump(ctx, name, g_lock_get_fn, &state);
722 if (!NT_STATUS_IS_OK(status)) {
723 return status;
725 if (!state.found) {
726 return NT_STATUS_NOT_FOUND;
728 return NT_STATUS_OK;
731 static bool g_lock_init_all(TALLOC_CTX *mem_ctx,
732 struct tevent_context **pev,
733 struct messaging_context **pmsg,
734 const struct server_id self,
735 struct g_lock_ctx **pg_ctx)
737 struct tevent_context *ev = NULL;
738 struct messaging_context *msg = NULL;
739 struct g_lock_ctx *g_ctx = NULL;
741 ev = tevent_context_init(mem_ctx);
742 if (ev == NULL) {
743 d_fprintf(stderr, "ERROR: could not init event context\n");
744 goto fail;
746 msg = messaging_init(mem_ctx, self, ev);
747 if (msg == NULL) {
748 d_fprintf(stderr, "ERROR: could not init messaging context\n");
749 goto fail;
751 g_ctx = g_lock_ctx_init(mem_ctx, msg);
752 if (g_ctx == NULL) {
753 d_fprintf(stderr, "ERROR: could not init g_lock context\n");
754 goto fail;
757 *pev = ev;
758 *pmsg = msg;
759 *pg_ctx = g_ctx;
760 return true;
761 fail:
762 TALLOC_FREE(g_ctx);
763 TALLOC_FREE(msg);
764 TALLOC_FREE(ev);
765 return false;
768 NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
769 struct timeval timeout, const struct server_id self,
770 void (*fn)(void *private_data), void *private_data)
772 struct tevent_context *ev = NULL;
773 struct messaging_context *msg = NULL;
774 struct g_lock_ctx *g_ctx = NULL;
775 NTSTATUS status;
777 if (!g_lock_init_all(talloc_tos(), &ev, &msg, self, &g_ctx)) {
778 status = NT_STATUS_ACCESS_DENIED;
779 goto done;
782 status = g_lock_lock(g_ctx, name, lock_type, timeout);
783 if (!NT_STATUS_IS_OK(status)) {
784 goto done;
786 fn(private_data);
787 g_lock_unlock(g_ctx, name);
789 done:
790 TALLOC_FREE(g_ctx);
791 TALLOC_FREE(msg);
792 TALLOC_FREE(ev);
793 return status;