[PATCH] ctdb: add --rundir switch to override CTDB_RUNDIR
Michael Adam
obnox at samba.org
Wed Sep 9 08:34:48 UTC 2015
On 2015-09-09 at 18:08 +1000, Martin Schwenke wrote:
> On Tue, 8 Sep 2015 10:58:54 +0200, Michael Adam <obnox at samba.org> wrote:
>
> > Needed to be able to run ctdb without prior install (e.g. in
> > selftest).
>
> I can't think of a better way of doing this but it requires a bit more
> thought. The --rundir option you're proposing only influences the
> location of the lock file used in ctdb_tcp_listen_automatic().
>
> The existing tests that use multiple ctdbd's on a single node insist
> that the --listen option is used to provide the "private" node IP
> address. This avoids the "automatic" case. However, I can see that we
> would want to test the "automatic" code under socket wrapper, or
> whatever.
Thanks for that hint ... I wasn't aware. :-)
> Other things that currently live in CTDB_RUNDIR are the PID file and
> the socket. These don't follow the proposed --rundir option. This
> means that we get a bit of confusion. We already have --pidfile and
> --socket options. --socket is only used for testing, like --rundir
> would be, so we could drop --socket and just have the socket location
> follow --rundir. In ctdbd_wrapper, we could still build and export the
> value of CTDB_SOCKET (based on CTDB_RUNDIR) so that calls to "ctdb"
> succeed (I've now remembered that this is the 2nd use of CTDB_SOCKET).
>
> The PID file is more problematic. First of all, the main reason the
> --pidfile option exists is so that we don't create the PID file by
> default when testing (and we don't have access to the compile-time
> CTDB_RUNDIR). At the moment we load the configuration in the initscript
> so that we can get (things including) CTDB_PIDFILE. The initscript
> uses the PID file to check the status of ctdbd. We then pass the PID
> file location to ctdbd_wrapper, which means we only need to "construct"
> it once and consistency is guaranteed. However, given that we load
> configuration in both places (initscript, ctdbd_wrapper), we could
> build the PID file location from a CTDB_RUNDIR configuration variable
> in both places.
>
> So, we could push this patch and then make some additional changes to
> get more consistency...
Since my patch just changes the only place in the code that used
CTDB_RUNDIR before to use the value possibly overridden by
--rundir now, I'd suggest to push it now and make the other
possible users of rundir (pid, socket) more systematic later.
> Whatever we decide, we also need to check that this allocation
> succeeded:
>
> + lock_path = talloc_asprintf(ctdb, "%s/.socket_lock", ctdb->run_dir);
Oh, indeed. Thanks!
Updated patch attached.
Michael
-------------- next part --------------
From 533e9b876757e27f973c4cfa08d0c249cf8a1b33 Mon Sep 17 00:00:00 2001
From: Michael Adam <obnox at samba.org>
Date: Tue, 8 Sep 2015 09:59:06 +0200
Subject: [PATCH] ctdb: make it possible to override compiled-in CTDB_RUNDIR in
ctdbd.
This adds a new command line switch --rundir to ctdbd.
It is needed to be able to run ctdb (in selftest) withour prior install.
Signed-off-by: Michael Adam <obnox at samba.org>
---
ctdb/doc/ctdbd.1.xml | 13 +++++++++++++
ctdb/include/ctdb_private.h | 1 +
ctdb/server/ctdbd.c | 6 ++++++
ctdb/tcp/tcp_connect.c | 15 +++++++++++++--
4 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/ctdb/doc/ctdbd.1.xml b/ctdb/doc/ctdbd.1.xml
index 7a3844b..884dd43 100644
--- a/ctdb/doc/ctdbd.1.xml
+++ b/ctdb/doc/ctdbd.1.xml
@@ -126,6 +126,19 @@
</varlistentry>
<varlistentry>
+ <term>--rundir=<parameter>DIRECTORY</parameter></term>
+ <listitem>
+ <para>
+ DIRECTORY where CTDB creates a lockfile when it starts listening
+ on sockets.
+ </para>
+ <para>
+ The default is <filename>/var/run/ctdb</filename>.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term>--listen=<parameter>IPADDR</parameter></term>
<listitem>
<para>
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 42b87ca..842bb94 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -456,6 +456,7 @@ struct ctdb_context {
const char *db_directory;
const char *db_directory_persistent;
const char *db_directory_state;
+ const char *run_dir;
struct tdb_wrap *db_persistent_health;
uint32_t db_persistent_startup_generation;
uint64_t db_persistent_check_errors;
diff --git a/ctdb/server/ctdbd.c b/ctdb/server/ctdbd.c
index ec285c0..9cbc32a 100644
--- a/ctdb/server/ctdbd.c
+++ b/ctdb/server/ctdbd.c
@@ -38,6 +38,7 @@ static struct {
const char *db_dir;
const char *db_dir_persistent;
const char *db_dir_state;
+ const char *run_dir;
const char *public_interface;
const char *single_public_ip;
int valgrinding;
@@ -60,6 +61,7 @@ static struct {
.db_dir_persistent = CTDB_VARDIR "/persistent",
.db_dir_state = CTDB_VARDIR "/state",
.script_log_level = DEBUG_ERR,
+ .run_dir = CTDB_RUNDIR,
};
int script_log_level;
@@ -133,6 +135,7 @@ int main(int argc, const char *argv[])
&options.max_persistent_check_errors, 0,
"max allowed persistent check errors (default 0)", NULL },
{ "sloppy-start", 0, POPT_ARG_NONE, &fast_start, 0, "Do not perform full recovery on start", NULL },
+ { "rundir", 0, POPT_ARG_STRING, &options.run_dir, 0, "directory for temporary runtime files", NULL },
POPT_TABLEEND
};
int opt, ret;
@@ -258,6 +261,9 @@ int main(int argc, const char *argv[])
ctdb->db_directory_state = options.db_dir_state;
mkdir_p_or_die(ctdb->db_directory_state, 0700);
+ ctdb->run_dir = options.run_dir;
+ mkdir_p_or_die(ctdb->run_dir, 0700);
+
if (options.public_interface) {
ctdb->default_public_interface = talloc_strdup(ctdb, options.public_interface);
CTDB_NO_MEMORY(ctdb, ctdb->default_public_interface);
diff --git a/ctdb/tcp/tcp_connect.c b/ctdb/tcp/tcp_connect.c
index b106f22..886b3be 100644
--- a/ctdb/tcp/tcp_connect.c
+++ b/ctdb/tcp/tcp_connect.c
@@ -257,18 +257,26 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
struct ctdb_tcp);
ctdb_sock_addr sock;
int lock_fd, i;
- const char *lock_path = CTDB_RUNDIR "/.socket_lock";
+ char *lock_path;
struct flock lock;
int one = 1;
int sock_size;
struct tevent_fd *fde;
+ lock_path = talloc_asprintf(ctdb, "%s/.socket_lock", ctdb->run_dir);
+ if (lock_path == NULL) {
+ DEBUG(DEBUG_CRIT, ("Out of memory at %s:%d.\n",
+ __FILE__, __LINE__));
+ return -1;
+ }
+
/* If there are no nodes, then it won't be possible to find
* the first one. Log a failure and short circuit the whole
* process.
*/
if (ctdb->num_nodes == 0) {
DEBUG(DEBUG_CRIT,("No nodes available to attempt bind to - is the nodes file empty?\n"));
+ TALLOC_FREE(lock_path);
return -1;
}
@@ -279,6 +287,7 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
lock_fd = open(lock_path, O_RDWR|O_CREAT, 0666);
if (lock_fd == -1) {
DEBUG(DEBUG_CRIT,("Unable to open %s\n", lock_path));
+ TALLOC_FREE(lock_path);
return -1;
}
@@ -291,6 +300,7 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
if (fcntl(lock_fd, F_SETLKW, &lock) != 0) {
DEBUG(DEBUG_CRIT,("Unable to lock %s\n", lock_path));
close(lock_fd);
+ TALLOC_FREE(lock_path);
return -1;
}
@@ -372,7 +382,7 @@ static int ctdb_tcp_listen_automatic(struct ctdb_context *ctdb)
tevent_fd_set_auto_close(fde);
close(lock_fd);
-
+ TALLOC_FREE(lock_path);
return 0;
failed:
@@ -381,6 +391,7 @@ failed:
close(ctcp->listen_fd);
ctcp->listen_fd = -1;
}
+ TALLOC_FREE(lock_path);
return -1;
}
--
2.4.3
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150909/d750f413/attachment.sig>
More information about the samba-technical
mailing list