s3: Remove the dependency of g_lock on procid_self
authorVolker Lendecke <vl@samba.org>
Sun, 27 Jun 2010 13:36:38 +0000 (15:36 +0200)
committerVolker Lendecke <vl@samba.org>
Sat, 28 Aug 2010 10:28:53 +0000 (12:28 +0200)
procid_self() references global vars, don't depend on them unnecessarily

source3/include/g_lock.h
source3/lib/g_lock.c
source3/utils/net_g_lock.c
source3/utils/net_registry.c

index becb71bb670dba1f0f1faddf007d3413f724052f..40922308a1116d0411b4227304c363b4b00a330f 100644 (file)
@@ -44,7 +44,7 @@ NTSTATUS g_lock_get(struct g_lock_ctx *ctx, const char *name,
                struct server_id *pid);
 
 NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
-                  struct timeval timeout,
+                  struct timeval timeout, struct server_id self,
                   void (*fn)(void *private_data), void *private_data);
 
 int g_lock_locks(struct g_lock_ctx *ctx,
index 49f719b5fc57a5de4b3463905234146e65d5abe8..42bf3b091624173e92ffeb1ab063f34aa12718fd 100644 (file)
@@ -206,7 +206,7 @@ again:
                goto done;
        }
 
-       self = procid_self();
+       self = messaging_server_id(ctx->msg);
        our_index = -1;
 
        for (i=0; i<num_locks; i++) {
@@ -312,8 +312,8 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
 
 #ifdef CLUSTER_SUPPORT
        if (lp_clustering()) {
-               status = ctdb_watch_us(
-                       messaging_ctdbd_connection(procid_self()));
+               struct server_id my_id = messaging_server_id(ctx->msg);
+               status = ctdb_watch_us(messaging_ctdbd_connection(my_id));
                if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(10, ("could not register retry with ctdb: %s\n",
                                   nt_errstr(status)));
@@ -388,9 +388,11 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name,
 
 #ifdef CLUSTER_SUPPORT
                if (lp_clustering()) {
+                       struct server_id my_id;
                        struct ctdbd_connection *conn;
 
-                       conn = messaging_ctdbd_connection(procid_self());
+                       my_id = messaging_server_id(ctx->msg);
+                       conn = messaging_ctdbd_connection(my_id);
 
                        r_fds = &_r_fds;
                        FD_ZERO(r_fds);
@@ -591,11 +593,12 @@ NTSTATUS g_lock_unlock(struct g_lock_ctx *ctx, const char *name)
 {
        NTSTATUS status;
 
-       status = g_lock_force_unlock(ctx, name, procid_self());
+       status = g_lock_force_unlock(ctx, name, messaging_server_id(ctx->msg));
 
 #ifdef CLUSTER_SUPPORT
        if (lp_clustering()) {
-               ctdb_unwatch(messaging_ctdbd_connection(procid_self()));
+               struct server_id my_id = messaging_server_id(ctx->msg);
+               ctdb_unwatch(messaging_ctdbd_connection(my_id));
        }
 #endif
        return status;
@@ -708,6 +711,7 @@ NTSTATUS g_lock_get(struct g_lock_ctx *ctx, const char *name,
 static bool g_lock_init_all(TALLOC_CTX *mem_ctx,
                            struct tevent_context **pev,
                            struct messaging_context **pmsg,
+                           const struct server_id self,
                            struct g_lock_ctx **pg_ctx)
 {
        struct tevent_context *ev = NULL;
@@ -719,7 +723,7 @@ static bool g_lock_init_all(TALLOC_CTX *mem_ctx,
                d_fprintf(stderr, "ERROR: could not init event context\n");
                goto fail;
        }
-       msg = messaging_init(mem_ctx, procid_self(), ev);
+       msg = messaging_init(mem_ctx, self, ev);
        if (msg == NULL) {
                d_fprintf(stderr, "ERROR: could not init messaging context\n");
                goto fail;
@@ -742,7 +746,7 @@ fail:
 }
 
 NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
-                  struct timeval timeout,
+                  struct timeval timeout, const struct server_id self,
                   void (*fn)(void *private_data), void *private_data)
 {
        struct tevent_context *ev = NULL;
@@ -750,7 +754,7 @@ NTSTATUS g_lock_do(const char *name, enum g_lock_type lock_type,
        struct g_lock_ctx *g_ctx = NULL;
        NTSTATUS status;
 
-       if (!g_lock_init_all(talloc_tos(), &ev, &msg, &g_ctx)) {
+       if (!g_lock_init_all(talloc_tos(), &ev, &msg, self, &g_ctx)) {
                status = NT_STATUS_ACCESS_DENIED;
                goto done;
        }
index a683b552de474523928af2052c55c9438d5ad3da..937c11c0c49e4c1ebb748c7c7a45806c2e4e24f7 100644 (file)
@@ -90,7 +90,7 @@ static int net_g_lock_do(struct net_context *c, int argc, const char **argv)
 
        status = g_lock_do(name, G_LOCK_WRITE,
                           timeval_set(timeout / 1000, timeout % 1000),
-                          net_g_lock_do_fn, &state);
+                          procid_self(), net_g_lock_do_fn, &state);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, "ERROR: g_lock_do failed: %s\n",
                          nt_errstr(status));
index 4a6af959dc185fabc748e2750fc1a4cca21a43e7..f90d05454b456279ade4cab66aabc84d3343a6da 100644 (file)
@@ -488,7 +488,7 @@ static int net_registry_increment(struct net_context *c, int argc,
        }
 
        status = g_lock_do("registry_increment_lock", G_LOCK_WRITE,
-                          timeval_set(600, 0),
+                          timeval_set(600, 0), procid_self(),
                           net_registry_increment_fn, &state);
        if (!NT_STATUS_IS_OK(status)) {
                d_fprintf(stderr, _("g_lock_do failed: %s\n"),