subreq = g_lock_lock_send(state, ev,
context->db.g_ctx,
string_term_tdb_data(context->db.key_name),
- G_LOCK_WRITE);
+ G_LOCK_WRITE,
+ NULL, NULL);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
subreq = g_lock_lock_send(state, ev,
context->db.g_ctx,
string_term_tdb_data(context->db.key_name),
- gtype);
+ gtype,
+ NULL, NULL);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
struct tevent_context *ev,
struct g_lock_ctx *ctx,
TDB_DATA key,
- enum g_lock_type type);
+ enum g_lock_type type,
+ g_lock_lock_cb_fn_t cb_fn,
+ void *cb_private);
NTSTATUS g_lock_lock_recv(struct tevent_req *req);
NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, TDB_DATA key,
enum g_lock_type lock_type, struct timeval timeout);
struct tevent_context *ev,
struct g_lock_ctx *ctx,
TDB_DATA key,
- enum g_lock_type type)
+ enum g_lock_type type,
+ g_lock_lock_cb_fn_t cb_fn,
+ void *cb_private)
{
struct tevent_req *req;
struct g_lock_lock_state *state;
state->ctx = ctx;
state->key = key;
state->type = type;
+ state->cb_fn = cb_fn;
+ state->cb_private = cb_private;
fn_state = (struct g_lock_lock_fn_state) {
.req_state = state,
};
+ /*
+ * We allow a cn_fn only for G_LOCK_WRITE for now.
+ *
+ * It's all we currently need and it makes a few things
+ * easier to implement.
+ */
+ if (unlikely(cb_fn != NULL && type != G_LOCK_WRITE)) {
+ tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER_6);
+ return tevent_req_post(req, ev);
+ }
+
status = dbwrap_do_locked(ctx->db, key, g_lock_lock_fn, &fn_state);
if (tevent_req_nterror(req, status)) {
DBG_DEBUG("dbwrap_do_locked failed: %s\n",
NTSTATUS status;
if (tevent_req_is_nterror(req, &status)) {
+ if (NT_STATUS_EQUAL(status, NT_STATUS_WAS_UNLOCKED)) {
+ return NT_STATUS_OK;
+ }
return status;
}
if (ev == NULL) {
goto fail;
}
- req = g_lock_lock_send(frame, ev, ctx, key, type);
+ req = g_lock_lock_send(frame, ev, ctx, key, type, cb_fn, cb_private);
if (req == NULL) {
goto fail;
}
goto fail;
}
- req = g_lock_lock_send(ev, ev, ctx, key, G_LOCK_WRITE);
+ req = g_lock_lock_send(ev, ev, ctx, key, G_LOCK_WRITE, NULL, NULL);
if (req == NULL) {
fprintf(stderr, "g_lock_lock send failed\n");
goto fail;
goto fail;
}
- req = g_lock_lock_send(ev, ev, ctx, key, G_LOCK_WRITE);
+ req = g_lock_lock_send(ev, ev, ctx, key, G_LOCK_WRITE, NULL, NULL);
if (req == NULL) {
fprintf(stderr, "g_lock_lock send failed\n");
goto fail;
ev,
ctx,
key,
- G_LOCK_UPGRADE);
+ G_LOCK_UPGRADE,
+ NULL, NULL);
if (req == NULL) {
fprintf(stderr, "g_lock_lock_send(UPGRADE) failed\n");
exit(1);