lib: Make g_lock_unlock use TDB_DATA
[Samba.git] / source3 / lib / g_lock.c
blob653ec34bb7f95c4ade1592773606c8bf1c1e0524
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 "lib/util/server_id.h"
23 #include "dbwrap/dbwrap.h"
24 #include "dbwrap/dbwrap_open.h"
25 #include "dbwrap/dbwrap_watch.h"
26 #include "g_lock.h"
27 #include "util_tdb.h"
28 #include "../lib/util/tevent_ntstatus.h"
29 #include "messages.h"
30 #include "serverid.h"
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.
43 #define G_LOCK_REC_LENGTH (SERVER_ID_BUF_LENGTH+1)
45 static void g_lock_rec_put(uint8_t buf[G_LOCK_REC_LENGTH],
46 const struct g_lock_rec rec)
48 SCVAL(buf, 0, rec.lock_type);
49 server_id_put(buf+1, rec.pid);
52 static void g_lock_rec_get(struct g_lock_rec *rec,
53 const uint8_t buf[G_LOCK_REC_LENGTH])
55 rec->lock_type = CVAL(buf, 0);
56 server_id_get(&rec->pid, buf+1);
59 struct g_lock {
60 uint8_t *recsbuf;
61 size_t num_recs;
62 uint8_t *data;
63 size_t datalen;
66 static bool g_lock_parse(uint8_t *buf, size_t buflen, struct g_lock *lck)
68 size_t found_recs, data_ofs;
70 if (buflen < sizeof(uint32_t)) {
71 *lck = (struct g_lock) {0};
72 return true;
75 found_recs = IVAL(buf, 0);
77 buf += sizeof(uint32_t);
78 buflen -= sizeof(uint32_t);
79 if (found_recs > buflen/G_LOCK_REC_LENGTH) {
80 return false;
83 data_ofs = found_recs * G_LOCK_REC_LENGTH;
85 *lck = (struct g_lock) {
86 .recsbuf = buf, .num_recs = found_recs,
87 .data = buf+data_ofs, .datalen = buflen-data_ofs
90 return true;
93 static void g_lock_get_rec(struct g_lock *lck, size_t i,
94 struct g_lock_rec *rec)
96 if (i >= lck->num_recs) {
97 abort();
99 g_lock_rec_get(rec, lck->recsbuf + i*G_LOCK_REC_LENGTH);
102 static void g_lock_rec_del(struct g_lock *lck, size_t i)
104 if (i >= lck->num_recs) {
105 abort();
107 lck->num_recs -= 1;
108 if (i < lck->num_recs) {
109 uint8_t *recptr = lck->recsbuf + i*G_LOCK_REC_LENGTH;
110 memcpy(recptr, lck->recsbuf + lck->num_recs*G_LOCK_REC_LENGTH,
111 G_LOCK_REC_LENGTH);
115 static NTSTATUS g_lock_store(struct db_record *rec, struct g_lock *lck,
116 struct g_lock_rec *add)
118 uint8_t sizebuf[4];
119 uint8_t addbuf[G_LOCK_REC_LENGTH];
121 struct TDB_DATA dbufs[] = {
122 { .dptr = sizebuf, .dsize = sizeof(sizebuf) },
123 { .dptr = lck->recsbuf,
124 .dsize = lck->num_recs * G_LOCK_REC_LENGTH },
125 { 0 },
126 { .dptr = lck->data, .dsize = lck->datalen }
129 if (add != NULL) {
130 g_lock_rec_put(addbuf, *add);
132 dbufs[2] = (TDB_DATA) {
133 .dptr = addbuf, .dsize = G_LOCK_REC_LENGTH
136 lck->num_recs += 1;
139 SIVAL(sizebuf, 0, lck->num_recs);
141 return dbwrap_record_storev(rec, dbufs, ARRAY_SIZE(dbufs), 0);
144 struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx,
145 struct messaging_context *msg)
147 struct g_lock_ctx *result;
148 struct db_context *backend;
149 char *db_path;
151 result = talloc(mem_ctx, struct g_lock_ctx);
152 if (result == NULL) {
153 return NULL;
155 result->msg = msg;
157 db_path = lock_path("g_lock.tdb");
158 if (db_path == NULL) {
159 TALLOC_FREE(result);
160 return NULL;
163 backend = db_open(result, db_path, 0,
164 TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
165 O_RDWR|O_CREAT, 0600,
166 DBWRAP_LOCK_ORDER_3,
167 DBWRAP_FLAG_NONE);
168 TALLOC_FREE(db_path);
169 if (backend == NULL) {
170 DEBUG(1, ("g_lock_init: Could not open g_lock.tdb\n"));
171 TALLOC_FREE(result);
172 return NULL;
175 result->db = db_open_watched(result, backend, msg);
176 if (result->db == NULL) {
177 DBG_WARNING("g_lock_init: db_open_watched failed\n");
178 TALLOC_FREE(result);
179 return NULL;
181 return result;
184 static bool g_lock_conflicts(enum g_lock_type l1, enum g_lock_type l2)
187 * Only tested write locks so far. Very likely this routine
188 * needs to be fixed for read locks....
190 if ((l1 == G_LOCK_READ) && (l2 == G_LOCK_READ)) {
191 return false;
193 return true;
196 static NTSTATUS g_lock_trylock(struct db_record *rec, struct server_id self,
197 enum g_lock_type type,
198 struct server_id *blocker)
200 TDB_DATA data;
201 size_t i;
202 struct g_lock lck;
203 struct g_lock_rec _mylock;
204 struct g_lock_rec *mylock = NULL;
205 NTSTATUS status;
206 bool modified = false;
207 bool ok;
209 data = dbwrap_record_get_value(rec);
211 ok = g_lock_parse(data.dptr, data.dsize, &lck);
212 if (!ok) {
213 return NT_STATUS_INTERNAL_DB_CORRUPTION;
216 if ((type == G_LOCK_READ) && (lck.num_recs > 0)) {
217 struct g_lock_rec check_rec;
220 * Read locks can stay around forever if the process
221 * dies. Do a heuristic check for process existence:
222 * Check one random process for existence. Hopefully
223 * this will keep runaway read locks under control.
225 i = generate_random() % lck.num_recs;
227 g_lock_get_rec(&lck, i, &check_rec);
229 if (!serverid_exists(&check_rec.pid)) {
230 g_lock_rec_del(&lck, i);
231 modified = true;
235 i = 0;
237 while (i < lck.num_recs) {
238 struct g_lock_rec lock;
240 g_lock_get_rec(&lck, i, &lock);
242 if (serverid_equal(&self, &lock.pid)) {
243 if (lock.lock_type == type) {
244 status = NT_STATUS_WAS_LOCKED;
245 goto done;
247 if (mylock != NULL) {
248 status = NT_STATUS_INTERNAL_DB_CORRUPTION;
249 goto done;
251 _mylock = lock;
252 mylock = &_mylock;
254 * Remove "our" lock entry. Re-add it later
255 * with our new lock type.
257 g_lock_rec_del(&lck, i);
258 modified = true;
259 continue;
262 if (g_lock_conflicts(type, lock.lock_type)) {
263 struct server_id pid = lock.pid;
266 * As the serverid_exists might recurse into
267 * the g_lock code, we use
268 * SERVERID_UNIQUE_ID_NOT_TO_VERIFY to avoid the loop
270 pid.unique_id = SERVERID_UNIQUE_ID_NOT_TO_VERIFY;
272 if (serverid_exists(&pid)) {
273 status = NT_STATUS_LOCK_NOT_GRANTED;
274 *blocker = lock.pid;
275 goto done;
279 * Delete stale conflicting entry
281 g_lock_rec_del(&lck, i);
282 modified = true;
283 continue;
285 i++;
288 modified = true;
290 _mylock = (struct g_lock_rec) {
291 .pid = self,
292 .lock_type = type
294 mylock = &_mylock;
296 status = NT_STATUS_OK;
297 done:
298 if (modified) {
299 NTSTATUS store_status;
301 store_status = g_lock_store(rec, &lck, mylock);
302 if (!NT_STATUS_IS_OK(store_status)) {
303 DBG_WARNING("g_lock_record_store failed: %s\n",
304 nt_errstr(store_status));
305 status = store_status;
308 return status;
311 struct g_lock_lock_state {
312 struct tevent_context *ev;
313 struct g_lock_ctx *ctx;
314 TDB_DATA key;
315 enum g_lock_type type;
318 static void g_lock_lock_retry(struct tevent_req *subreq);
320 struct g_lock_lock_fn_state {
321 struct g_lock_lock_state *state;
322 struct server_id self;
324 struct tevent_req *watch_req;
325 NTSTATUS status;
328 static void g_lock_lock_fn(struct db_record *rec, void *private_data)
330 struct g_lock_lock_fn_state *state = private_data;
331 struct server_id blocker;
333 state->status = g_lock_trylock(rec, state->self, state->state->type,
334 &blocker);
335 if (!NT_STATUS_EQUAL(state->status, NT_STATUS_LOCK_NOT_GRANTED)) {
336 return;
339 state->watch_req = dbwrap_watched_watch_send(
340 state->state, state->state->ev, rec, blocker);
343 struct tevent_req *g_lock_lock_send(TALLOC_CTX *mem_ctx,
344 struct tevent_context *ev,
345 struct g_lock_ctx *ctx,
346 TDB_DATA key,
347 enum g_lock_type type)
349 struct tevent_req *req;
350 struct g_lock_lock_state *state;
351 struct g_lock_lock_fn_state fn_state;
352 NTSTATUS status;
354 req = tevent_req_create(mem_ctx, &state, struct g_lock_lock_state);
355 if (req == NULL) {
356 return NULL;
358 state->ev = ev;
359 state->ctx = ctx;
360 state->key = key;
361 state->type = type;
363 fn_state = (struct g_lock_lock_fn_state) {
364 .state = state, .self = messaging_server_id(ctx->msg)
367 status = dbwrap_do_locked(ctx->db, key, g_lock_lock_fn, &fn_state);
368 if (tevent_req_nterror(req, status)) {
369 DBG_DEBUG("dbwrap_do_locked failed: %s\n",
370 nt_errstr(status));
371 return tevent_req_post(req, ev);
374 if (NT_STATUS_IS_OK(fn_state.status)) {
375 tevent_req_done(req);
376 return tevent_req_post(req, ev);
378 if (!NT_STATUS_EQUAL(fn_state.status, NT_STATUS_LOCK_NOT_GRANTED)) {
379 tevent_req_nterror(req, fn_state.status);
380 return tevent_req_post(req, ev);
383 if (tevent_req_nomem(fn_state.watch_req, req)) {
384 return tevent_req_post(req, ev);
387 if (!tevent_req_set_endtime(
388 fn_state.watch_req, state->ev,
389 timeval_current_ofs(5 + sys_random() % 5, 0))) {
390 tevent_req_oom(req);
391 return tevent_req_post(req, ev);
393 tevent_req_set_callback(fn_state.watch_req, g_lock_lock_retry, req);
394 return req;
397 static void g_lock_lock_retry(struct tevent_req *subreq)
399 struct tevent_req *req = tevent_req_callback_data(
400 subreq, struct tevent_req);
401 struct g_lock_lock_state *state = tevent_req_data(
402 req, struct g_lock_lock_state);
403 struct g_lock_lock_fn_state fn_state;
404 NTSTATUS status;
406 status = dbwrap_watched_watch_recv(subreq, NULL, NULL);
407 DBG_DEBUG("watch_recv returned %s\n", nt_errstr(status));
408 TALLOC_FREE(subreq);
410 if (!NT_STATUS_IS_OK(status) &&
411 !NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
412 tevent_req_nterror(req, status);
413 return;
416 fn_state = (struct g_lock_lock_fn_state) {
417 .state = state, .self = messaging_server_id(state->ctx->msg)
420 status = dbwrap_do_locked(state->ctx->db, state->key,
421 g_lock_lock_fn, &fn_state);
422 if (tevent_req_nterror(req, status)) {
423 DBG_DEBUG("dbwrap_do_locked failed: %s\n",
424 nt_errstr(status));
425 return;
428 if (NT_STATUS_IS_OK(fn_state.status)) {
429 tevent_req_done(req);
430 return;
432 if (!NT_STATUS_EQUAL(fn_state.status, NT_STATUS_LOCK_NOT_GRANTED)) {
433 tevent_req_nterror(req, fn_state.status);
434 return;
437 if (tevent_req_nomem(fn_state.watch_req, req)) {
438 return;
441 if (!tevent_req_set_endtime(
442 fn_state.watch_req, state->ev,
443 timeval_current_ofs(5 + sys_random() % 5, 0))) {
444 tevent_req_oom(req);
445 return;
447 tevent_req_set_callback(fn_state.watch_req, g_lock_lock_retry, req);
450 NTSTATUS g_lock_lock_recv(struct tevent_req *req)
452 return tevent_req_simple_recv_ntstatus(req);
455 NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
456 enum g_lock_type type, struct timeval timeout)
458 TALLOC_CTX *frame = talloc_stackframe();
459 struct tevent_context *ev;
460 struct tevent_req *req;
461 struct timeval end;
462 NTSTATUS status = NT_STATUS_NO_MEMORY;
464 ev = samba_tevent_context_init(frame);
465 if (ev == NULL) {
466 goto fail;
468 req = g_lock_lock_send(frame, ev, ctx, key, type);
469 if (req == NULL) {
470 goto fail;
472 end = timeval_current_ofs(timeout.tv_sec, timeout.tv_usec);
473 if (!tevent_req_set_endtime(req, ev, end)) {
474 goto fail;
476 if (!tevent_req_poll_ntstatus(req, ev, &status)) {
477 goto fail;
479 status = g_lock_lock_recv(req);
480 fail:
481 TALLOC_FREE(frame);
482 return status;
485 struct g_lock_unlock_state {
486 TDB_DATA key;
487 struct server_id self;
488 NTSTATUS status;
491 static void g_lock_unlock_fn(struct db_record *rec,
492 void *private_data)
494 struct g_lock_unlock_state *state = private_data;
495 TDB_DATA value;
496 struct g_lock lck;
497 size_t i;
498 bool ok;
500 value = dbwrap_record_get_value(rec);
502 ok = g_lock_parse(value.dptr, value.dsize, &lck);
503 if (!ok) {
504 DBG_DEBUG("g_lock_get for %s failed\n",
505 hex_encode_talloc(talloc_tos(),
506 state->key.dptr,
507 state->key.dsize));
508 state->status = NT_STATUS_FILE_INVALID;
509 return;
511 for (i=0; i<lck.num_recs; i++) {
512 struct g_lock_rec lockrec;
513 g_lock_get_rec(&lck, i, &lockrec);
514 if (serverid_equal(&state->self, &lockrec.pid)) {
515 break;
518 if (i == lck.num_recs) {
519 DBG_DEBUG("Lock not found, num_rec=%zu\n", lck.num_recs);
520 state->status = NT_STATUS_NOT_FOUND;
521 return;
524 g_lock_rec_del(&lck, i);
526 if ((lck.num_recs == 0) && (lck.datalen == 0)) {
527 state->status = dbwrap_record_delete(rec);
528 return;
530 state->status = g_lock_store(rec, &lck, NULL);
533 NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, TDB_DATA key)
535 struct g_lock_unlock_state state = {
536 .self = messaging_server_id(ctx->msg), .key = key
538 NTSTATUS status;
540 status = dbwrap_do_locked(ctx->db, key, g_lock_unlock_fn, &state);
541 if (!NT_STATUS_IS_OK(status)) {
542 DBG_WARNING("dbwrap_do_locked failed: %s\n",
543 nt_errstr(status));
544 return status;
546 if (!NT_STATUS_IS_OK(state.status)) {
547 DBG_WARNING("g_lock_unlock_fn failed: %s\n",
548 nt_errstr(state.status));
549 return state.status;
552 return NT_STATUS_OK;
555 struct g_lock_write_data_state {
556 const char *name;
557 struct server_id self;
558 const uint8_t *data;
559 size_t datalen;
560 NTSTATUS status;
563 static void g_lock_write_data_fn(struct db_record *rec,
564 void *private_data)
566 struct g_lock_write_data_state *state = private_data;
567 TDB_DATA value;
568 struct g_lock lck;
569 size_t i;
570 bool ok;
572 value = dbwrap_record_get_value(rec);
574 ok = g_lock_parse(value.dptr, value.dsize, &lck);
575 if (!ok) {
576 DBG_DEBUG("g_lock_parse for %s failed\n", state->name);
577 state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
578 return;
580 for (i=0; i<lck.num_recs; i++) {
581 struct g_lock_rec lockrec;
582 g_lock_get_rec(&lck, i, &lockrec);
583 if ((lockrec.lock_type == G_LOCK_WRITE) &&
584 serverid_equal(&state->self, &lockrec.pid)) {
585 break;
588 if (i == lck.num_recs) {
589 DBG_DEBUG("Not locked by us\n");
590 state->status = NT_STATUS_NOT_LOCKED;
591 return;
594 lck.data = discard_const_p(uint8_t, state->data);
595 lck.datalen = state->datalen;
596 state->status = g_lock_store(rec, &lck, NULL);
599 NTSTATUS g_lock_write_data(struct g_lock_ctx *ctx, const char *name,
600 const uint8_t *buf, size_t buflen)
602 struct g_lock_write_data_state state = {
603 .name = name, .self = messaging_server_id(ctx->msg),
604 .data = buf, .datalen = buflen
606 NTSTATUS status;
608 status = dbwrap_do_locked(ctx->db, string_term_tdb_data(name),
609 g_lock_write_data_fn, &state);
610 if (!NT_STATUS_IS_OK(status)) {
611 DBG_WARNING("dbwrap_do_locked failed: %s\n",
612 nt_errstr(status));
613 return status;
615 if (!NT_STATUS_IS_OK(state.status)) {
616 DBG_WARNING("g_lock_write_data_fn failed: %s\n",
617 nt_errstr(state.status));
618 return state.status;
621 return NT_STATUS_OK;
624 struct g_lock_locks_state {
625 int (*fn)(const char *name, void *private_data);
626 void *private_data;
629 static int g_lock_locks_fn(struct db_record *rec, void *priv)
631 TDB_DATA key;
632 struct g_lock_locks_state *state = (struct g_lock_locks_state *)priv;
634 key = dbwrap_record_get_key(rec);
635 if ((key.dsize == 0) || (key.dptr[key.dsize-1] != 0)) {
636 DEBUG(1, ("invalid key in g_lock.tdb, ignoring\n"));
637 return 0;
639 return state->fn((char *)key.dptr, state->private_data);
642 int g_lock_locks(struct g_lock_ctx *ctx,
643 int (*fn)(const char *name, void *private_data),
644 void *private_data)
646 struct g_lock_locks_state state;
647 NTSTATUS status;
648 int count;
650 state.fn = fn;
651 state.private_data = private_data;
653 status = dbwrap_traverse_read(ctx->db, g_lock_locks_fn, &state, &count);
654 if (!NT_STATUS_IS_OK(status)) {
655 return -1;
657 return count;
660 struct g_lock_dump_state {
661 TALLOC_CTX *mem_ctx;
662 const char *name;
663 void (*fn)(const struct g_lock_rec *locks,
664 size_t num_locks,
665 const uint8_t *data,
666 size_t datalen,
667 void *private_data);
668 void *private_data;
669 NTSTATUS status;
672 static void g_lock_dump_fn(TDB_DATA key, TDB_DATA data,
673 void *private_data)
675 struct g_lock_dump_state *state = private_data;
676 struct g_lock_rec *recs;
677 struct g_lock lck;
678 size_t i;
679 bool ok;
681 ok = g_lock_parse(data.dptr, data.dsize, &lck);
682 if (!ok) {
683 DBG_DEBUG("g_lock_parse failed for %s\n",
684 state->name);
685 state->status = NT_STATUS_INTERNAL_DB_CORRUPTION;
686 return;
689 recs = talloc_array(state->mem_ctx, struct g_lock_rec, lck.num_recs);
690 if (recs == NULL) {
691 DBG_DEBUG("talloc failed\n");
692 state->status = NT_STATUS_NO_MEMORY;
693 return;
696 for (i=0; i<lck.num_recs; i++) {
697 g_lock_get_rec(&lck, i, &recs[i]);
700 state->fn(recs, lck.num_recs, lck.data, lck.datalen,
701 state->private_data);
703 TALLOC_FREE(recs);
705 state->status = NT_STATUS_OK;
708 NTSTATUS g_lock_dump(struct g_lock_ctx *ctx, const char *name,
709 void (*fn)(const struct g_lock_rec *locks,
710 size_t num_locks,
711 const uint8_t *data,
712 size_t datalen,
713 void *private_data),
714 void *private_data)
716 struct g_lock_dump_state state = {
717 .mem_ctx = ctx, .name = name,
718 .fn = fn, .private_data = private_data
720 NTSTATUS status;
722 status = dbwrap_parse_record(ctx->db, string_term_tdb_data(name),
723 g_lock_dump_fn, &state);
724 if (!NT_STATUS_IS_OK(status)) {
725 DBG_DEBUG("dbwrap_parse_record returned %s\n",
726 nt_errstr(status));
727 return status;
729 if (!NT_STATUS_IS_OK(state.status)) {
730 DBG_DEBUG("g_lock_dump_fn returned %s\n",
731 nt_errstr(state.status));
732 return state.status;
734 return NT_STATUS_OK;
737 static bool g_lock_init_all(TALLOC_CTX *mem_ctx,
738 struct tevent_context **pev,
739 struct messaging_context **pmsg,
740 struct g_lock_ctx **pg_ctx)
742 struct tevent_context *ev = NULL;
743 struct messaging_context *msg = NULL;
744 struct g_lock_ctx *g_ctx = NULL;
746 ev = samba_tevent_context_init(mem_ctx);
747 if (ev == NULL) {
748 d_fprintf(stderr, "ERROR: could not init event context\n");
749 goto fail;
751 msg = messaging_init(mem_ctx, ev);
752 if (msg == NULL) {
753 d_fprintf(stderr, "ERROR: could not init messaging context\n");
754 goto fail;
756 g_ctx = g_lock_ctx_init(mem_ctx, msg);
757 if (g_ctx == NULL) {
758 d_fprintf(stderr, "ERROR: could not init g_lock context\n");
759 goto fail;
762 *pev = ev;
763 *pmsg = msg;
764 *pg_ctx = g_ctx;
765 return true;
766 fail:
767 TALLOC_FREE(g_ctx);
768 TALLOC_FREE(msg);
769 TALLOC_FREE(ev);
770 return false;
773 NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
774 struct timeval timeout,
775 void (*fn)(void *private_data), void *private_data)
777 struct tevent_context *ev = NULL;
778 struct messaging_context *msg = NULL;
779 struct g_lock_ctx *g_ctx = NULL;
780 NTSTATUS status;
782 if (!g_lock_init_all(talloc_tos(), &ev, &msg, &g_ctx)) {
783 status = NT_STATUS_ACCESS_DENIED;
784 goto done;
787 status = g_lock_lock(g_ctx, string_term_tdb_data(name), lock_type,
788 timeout);
789 if (!NT_STATUS_IS_OK(status)) {
790 goto done;
792 fn(private_data);
793 g_lock_unlock(g_ctx, string_term_tdb_data(name));
795 done:
796 TALLOC_FREE(g_ctx);
797 TALLOC_FREE(msg);
798 TALLOC_FREE(ev);
799 return status;