[PATCH] Cleanups and bug fix for 13042
Volker Lendecke
Volker.Lendecke at SerNet.DE
Mon Sep 25 12:45:12 UTC 2017
Hi!
Review appreciated!
Thanks, Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From da0938d5db87dc6bf7836507d8f8408685bdc12c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 10:38:14 +0200
Subject: [PATCH 1/4] ctdbd: Fix a typo
Signed-off-by: Volker Lendecke <vl at samba.org>
---
ctdb/server/ctdb_daemon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index c72f41a4b9e..dda09655e7f 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -1744,7 +1744,7 @@ struct ctdb_client *ctdb_find_client_by_pid(struct ctdb_context *ctdb, pid_t pid
/* This control is used by samba when probing if a process (of a samba daemon)
exists on the node.
Samba does this when it needs/wants to check if a subrecord in one of the
- databases is still valied, or if it is stale and can be removed.
+ databases is still valid, or if it is stale and can be removed.
If the node is in unhealthy or stopped state we just kill of the samba
process holding this sub-record and return to the calling samba that
the process does not exist.
--
2.11.0
From ec90b9b9a2ad29ea7d2432a3c27f992b33cdfbe0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Thu, 21 Sep 2017 11:51:09 -0700
Subject: [PATCH 2/4] ctdb: Centralize ctdb_version_string
Whenever the current git hash changes, we recompile ctdb.c and
ctdb_daemon.c. As both have quite a few warnings with -Wall, this
makes it quite difficult to see the real warnings that pop up during
development. Centralize the ctdb_version_string to just a single file
without warnings.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
ctdb/common/version.c | 20 ++++++++++++++++++++
ctdb/common/version.h | 18 ++++++++++++++++++
ctdb/server/ctdb_daemon.c | 4 ++--
ctdb/tools/ctdb.c | 4 ++--
ctdb/wscript | 2 +-
5 files changed, 43 insertions(+), 5 deletions(-)
create mode 100644 ctdb/common/version.c
create mode 100644 ctdb/common/version.h
diff --git a/ctdb/common/version.c b/ctdb/common/version.c
new file mode 100644
index 00000000000..e34e98c09ef
--- /dev/null
+++ b/ctdb/common/version.c
@@ -0,0 +1,20 @@
+/*
+ CTDB version string
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "ctdb_version.h"
+
+const char ctdb_version_string[] = CTDB_VERSION_STRING;
diff --git a/ctdb/common/version.h b/ctdb/common/version.h
new file mode 100644
index 00000000000..1cf1c5d0cab
--- /dev/null
+++ b/ctdb/common/version.h
@@ -0,0 +1,18 @@
+/*
+ CTDB version string
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+extern const char ctdb_version_string[];
diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index dda09655e7f..185982e65bd 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -36,7 +36,7 @@
#include "lib/util/blocking.h"
#include "lib/util/become_daemon.h"
-#include "ctdb_version.h"
+#include "common/version.h"
#include "ctdb_private.h"
#include "ctdb_client.h"
@@ -1206,7 +1206,7 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
ctdb->ctdbd_pid = getpid();
DEBUG(DEBUG_ERR, ("Starting CTDBD (Version %s) as PID: %u\n",
- CTDB_VERSION_STRING, ctdb->ctdbd_pid));
+ ctdb_version_string, ctdb->ctdbd_pid));
ctdb_create_pidfile(ctdb);
/* create a unix domain stream socket to listen to */
diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c
index f8f9a18fa7e..a135da2a8b8 100644
--- a/ctdb/tools/ctdb.c
+++ b/ctdb/tools/ctdb.c
@@ -30,7 +30,7 @@
#include <tevent.h>
#include <tdb.h>
-#include "ctdb_version.h"
+#include "common/version.h"
#include "lib/util/debug.h"
#include "lib/util/samba_util.h"
#include "lib/util/sys_rw.h"
@@ -725,7 +725,7 @@ static int run_helper(TALLOC_CTX *mem_ctx, const char *command,
static int control_version(TALLOC_CTX *mem_ctx, struct ctdb_context *ctdb,
int argc, const char **argv)
{
- printf("%s\n", CTDB_VERSION_STRING);
+ printf("%s\n", ctdb_version_string);
return 0;
}
diff --git a/ctdb/wscript b/ctdb/wscript
index 2679c56db30..0523bde5449 100644
--- a/ctdb/wscript
+++ b/ctdb/wscript
@@ -386,7 +386,7 @@ def build(bld):
logging.c rb_tree.c tunable.c
pidfile.c run_proc.c
hash_count.c run_event.c
- sock_client.c'''),
+ sock_client.c version.c'''),
deps='''samba-util sys_rw tevent-util
replace talloc tevent tdb''')
--
2.11.0
From ad013eace4ae7208afd81b04e5e486fb3a1fddae Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 13:26:20 +0200
Subject: [PATCH 3/4] lib: Add "unique_id" to ctdbd_process_exists
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13042
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/include/ctdbd_conn.h | 2 +-
source3/lib/ctdb_dummy.c | 3 ++-
source3/lib/ctdbd_conn.c | 3 ++-
source3/lib/serverid.c | 2 +-
4 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/source3/include/ctdbd_conn.h b/source3/include/ctdbd_conn.h
index 4e7c1b05ddd..f6040ad833b 100644
--- a/source3/include/ctdbd_conn.h
+++ b/source3/include/ctdbd_conn.h
@@ -50,7 +50,7 @@ int ctdbd_messaging_send_iov(struct ctdbd_connection *conn,
const struct iovec *iov, int iovlen);
bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
- pid_t pid);
+ pid_t pid, uint64_t unique_id);
char *ctdbd_dbpath(struct ctdbd_connection *conn,
TALLOC_CTX *mem_ctx, uint32_t db_id);
diff --git a/source3/lib/ctdb_dummy.c b/source3/lib/ctdb_dummy.c
index 8a06b0cc7cf..144c8507758 100644
--- a/source3/lib/ctdb_dummy.c
+++ b/source3/lib/ctdb_dummy.c
@@ -62,7 +62,8 @@ int ctdbd_register_ips(struct ctdbd_connection *conn,
return ENOSYS;
}
-bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid)
+bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
+ pid_t pid, uint64_t unique_id)
{
return false;
}
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index bab489e71dd..2a7fd444b77 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -781,7 +781,8 @@ static int ctdbd_control(struct ctdbd_connection *conn,
/*
* see if a remote process exists
*/
-bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn, pid_t pid)
+bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
+ pid_t pid, uint64_t unique_id)
{
int32_t cstatus = 0;
int ret;
diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c
index ca4bb271807..73004489bef 100644
--- a/source3/lib/serverid.c
+++ b/source3/lib/serverid.c
@@ -199,7 +199,7 @@ bool serverid_exists(const struct server_id *id)
if (lp_clustering()) {
return ctdbd_process_exists(messaging_ctdb_connection(),
- id->vnn, id->pid);
+ id->vnn, id->pid, id->unique_id);
}
return false;
--
2.11.0
From 5dd4fb1df143e82b3a74e51cb2ce0196a1fef10e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Tue, 29 Aug 2017 13:31:07 +0200
Subject: [PATCH 4/4] lib: Use CTDB_CONTROL_CHECK_PID_SRVID
Also check the unique ID for remote server ids, just like we do for
local server ids
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13042
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/lib/ctdbd_conn.c | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c
index 2a7fd444b77..521e0168ca3 100644
--- a/source3/lib/ctdbd_conn.c
+++ b/source3/lib/ctdbd_conn.c
@@ -784,12 +784,27 @@ static int ctdbd_control(struct ctdbd_connection *conn,
bool ctdbd_process_exists(struct ctdbd_connection *conn, uint32_t vnn,
pid_t pid, uint64_t unique_id)
{
+ uint8_t buf[sizeof(pid)+sizeof(unique_id)];
int32_t cstatus = 0;
int ret;
- ret = ctdbd_control(conn, vnn, CTDB_CONTROL_PROCESS_EXISTS, 0, 0,
- (TDB_DATA) { .dptr = (uint8_t *)&pid,
- .dsize = sizeof(pid) },
+ if (unique_id == SERVERID_UNIQUE_ID_NOT_TO_VERIFY) {
+ ret = ctdbd_control(conn, vnn, CTDB_CONTROL_PROCESS_EXISTS,
+ 0, 0,
+ (TDB_DATA) { .dptr = (uint8_t *)&pid,
+ .dsize = sizeof(pid) },
+ NULL, NULL, &cstatus);
+ if (ret != 0) {
+ return false;
+ }
+ return (cstatus == 0);
+ }
+
+ memcpy(buf, &pid, sizeof(pid));
+ memcpy(buf+sizeof(pid), &unique_id, sizeof(unique_id));
+
+ ret = ctdbd_control(conn, vnn, CTDB_CONTROL_CHECK_PID_SRVID, 0, 0,
+ (TDB_DATA) { .dptr = buf, .dsize = sizeof(buf) },
NULL, NULL, &cstatus);
if (ret != 0) {
return false;
--
2.11.0
More information about the samba-technical
mailing list