summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2016-04-15 17:44:14 +1000
committerMartin Schwenke <martins@samba.org>2016-07-05 10:53:14 +0200
commitf721035d4339d910c3cf479eee93b6539f2ef05a (patch)
treef56702c08db839d7f74c5a7e262baed59542fdf3 /ctdb
parent37f587de7afd01d0b663be722a28acffc7da9c39 (diff)
downloadsamba-f721035d4339d910c3cf479eee93b6539f2ef05a.tar.gz
ctdb-client: Fix implementation of transaction start
Since g_lock checks if the process exists in case of conflicting lock, there is no need to register srvid. Transaction start returns a transaction handle and transaction commit/cancel will free that handle. Since we cannot call async code in a talloc destructor, this avoids the use of talloc destructor for cancelling the transaction. If user frees the transaction handle instead of calling transaction cancel, it will leave stale g_lock lock. This stale g_lock lock will get cleaned up on next transaction attempt. Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/client/client_db.c55
1 files changed, 2 insertions, 53 deletions
diff --git a/ctdb/client/client_db.c b/ctdb/client/client_db.c
index cb51b43f8d0..e3b0ea1c187 100644
--- a/ctdb/client/client_db.c
+++ b/ctdb/client/client_db.c
@@ -1619,9 +1619,7 @@ struct ctdb_transaction_start_state {
};
static void ctdb_transaction_g_lock_attached(struct tevent_req *subreq);
-static void ctdb_transaction_register_done(struct tevent_req *subreq);
static void ctdb_transaction_g_lock_done(struct tevent_req *subreq);
-static int ctdb_transaction_handle_destructor(struct ctdb_transaction_handle *h);
struct tevent_req *ctdb_transaction_start_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
@@ -1691,7 +1689,6 @@ static void ctdb_transaction_g_lock_attached(struct tevent_req *subreq)
subreq, struct tevent_req);
struct ctdb_transaction_start_state *state = tevent_req_data(
req, struct ctdb_transaction_start_state);
- struct ctdb_req_control request;
bool status;
int ret;
@@ -1702,42 +1699,9 @@ static void ctdb_transaction_g_lock_attached(struct tevent_req *subreq)
return;
}
- ctdb_req_control_register_srvid(&request, state->h->sid.unique_id);
- subreq = ctdb_client_control_send(state, state->ev, state->client,
- state->destnode, state->timeout,
- &request);
- if (tevent_req_nomem(subreq, req)) {
- return;
- }
- tevent_req_set_callback(subreq, ctdb_transaction_register_done, req);
-}
-
-static void ctdb_transaction_register_done(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(
- subreq, struct tevent_req);
- struct ctdb_transaction_start_state *state = tevent_req_data(
- req, struct ctdb_transaction_start_state);
- struct ctdb_reply_control *reply;
- bool status;
- int ret;
-
- status = ctdb_client_control_recv(subreq, &ret, state, &reply);
- TALLOC_FREE(subreq);
- if (! status) {
- tevent_req_error(req, ret);
- return;
- }
-
- ret = ctdb_reply_control_register_srvid(reply);
- talloc_free(reply);
- if (ret != 0) {
- tevent_req_error(req, ret);
- return;
- }
-
subreq = ctdb_g_lock_lock_send(state, state->ev, state->client,
- state->h->db_g_lock, state->h->lock_name,
+ state->h->db_g_lock,
+ state->h->lock_name,
&state->h->sid, state->h->readonly);
if (tevent_req_nomem(subreq, req)) {
return;
@@ -1778,24 +1742,9 @@ struct ctdb_transaction_handle *ctdb_transaction_start_recv(
return NULL;
}
- talloc_set_destructor(h, ctdb_transaction_handle_destructor);
return h;
}
-static int ctdb_transaction_handle_destructor(struct ctdb_transaction_handle *h)
-{
- int ret;
-
- ret = ctdb_ctrl_deregister_srvid(h, h->ev, h->client, h->client->pnn,
- tevent_timeval_zero(),
- h->sid.unique_id);
- if (ret != 0) {
- DEBUG(DEBUG_WARNING, ("Failed to deregister SRVID\n"));
- }
-
- return 0;
-}
-
int ctdb_transaction_start(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
struct ctdb_client_context *client,
struct timeval timeout,