mirror of
https://github.com/samba-team/samba.git
synced 2025-03-26 18:50:30 +03:00
merge from tridge
(This used to be ctdb commit a5cdd8b2d91478393a7f0e760d6bbe5eb93a989c)
This commit is contained in:
commit
bab73533ce
@ -43,7 +43,7 @@ CTDB_OBJ = $(CTDB_COMMON_OBJ) $(CTDB_TAKEOVER_OBJ) $(CTDB_TCP_OBJ) $(POPT_OBJ)
|
||||
|
||||
OBJS = @TDB_OBJ@ @TALLOC_OBJ@ @LIBREPLACEOBJ@ @INFINIBAND_WRAPPER_OBJ@ $(EXTRA_OBJ) @EVENTS_OBJ@ $(CTDB_OBJ) $(UTIL_OBJ)
|
||||
|
||||
TEST_BINS=bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_fetch bin/lockwait @INFINIBAND_BINS@
|
||||
TEST_BINS=bin/ctdbd_test bin/ctdb_bench bin/ctdb_fetch @INFINIBAND_BINS@
|
||||
BINS = bin/ctdb
|
||||
SBINS = bin/ctdbd
|
||||
|
||||
@ -64,10 +64,6 @@ showflags:
|
||||
dirs:
|
||||
@mkdir -p $(DIRS)
|
||||
|
||||
bin/ctdb_test: $(OBJS) tests/ctdb_test.o
|
||||
@echo Linking $@
|
||||
@$(CC) $(CFLAGS) -o $@ tests/ctdb_test.o $(OBJS) $(LIB_FLAGS)
|
||||
|
||||
bin/ctdbd: $(OBJS) direct/ctdbd.o
|
||||
@echo Linking $@
|
||||
@$(CC) $(CFLAGS) -o $@ direct/ctdbd.o $(OBJS) $(LIB_FLAGS)
|
||||
@ -92,10 +88,6 @@ bin/ibwrapper_test: $(OBJS) ib/ibwrapper_test.o
|
||||
@echo Linking $@
|
||||
@$(CC) $(CFLAGS) -o $@ ib/ibwrapper_test.o $(OBJS) $(LIB_FLAGS)
|
||||
|
||||
bin/lockwait: $(OBJS) tests/lockwait.o
|
||||
@echo Linking $@
|
||||
@$(CC) $(CFLAGS) -o $@ tests/lockwait.o $(OBJS) $(LIB_FLAGS)
|
||||
|
||||
clean:
|
||||
rm -f *.o */*.o */*/*.o
|
||||
rm -f $(BINS) $(SBINS) $(TEST_BINS)
|
||||
@ -116,12 +108,12 @@ install: all
|
||||
install -m755 bin/ctdbd $(DESTDIR)$(sbindir)
|
||||
install -m644 include/ctdb.h $(DESTDIR)$(includedir)
|
||||
install -m644 include/ctdb_private.h $(DESTDIR)$(includedir) # for samba3
|
||||
install -m755 tools/events $(DESTDIR)$(etcdir)/ctdb
|
||||
install -m755 tools/functions $(DESTDIR)$(etcdir)/ctdb
|
||||
install -m755 tools/statd-callout $(DESTDIR)$(etcdir)/ctdb
|
||||
install -m755 tools/events.d/samba $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
install -m755 tools/events.d/nfs $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
install -m755 tools/events.d/nfslock $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
install -m755 config/events $(DESTDIR)$(etcdir)/ctdb
|
||||
install -m755 config/functions $(DESTDIR)$(etcdir)/ctdb
|
||||
install -m755 config/statd-callout $(DESTDIR)$(etcdir)/ctdb
|
||||
install -m755 config/events.d/samba $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
install -m755 config/events.d/nfs $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
install -m755 config/events.d/nfslock $(DESTDIR)$(etcdir)/ctdb/events.d
|
||||
install -m755 tools/onnode.ssh $(DESTDIR)$(bindir)
|
||||
install -m755 tools/onnode.rsh $(DESTDIR)$(bindir)
|
||||
cd $(DESTDIR)$(bindir) && ln -sf onnode.ssh onnode
|
||||
|
@ -65,6 +65,7 @@ else
|
||||
fi
|
||||
|
||||
start() {
|
||||
killall -q ctdbd
|
||||
echo -n $"Starting ctdbd service: "
|
||||
case $init_style in
|
||||
suse)
|
||||
@ -119,13 +120,17 @@ case "$1" in
|
||||
restart
|
||||
;;
|
||||
status)
|
||||
rhstatus
|
||||
status
|
||||
;;
|
||||
condrestart)
|
||||
ctdb status > /dev/null && restart || :
|
||||
;;
|
||||
cron)
|
||||
# used from cron to auto-restart ctdb
|
||||
ctdb status > /dev/null || start
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|restart|status|condrestart}"
|
||||
echo $"Usage: $0 {start|stop|restart|status|cron|condrestart}"
|
||||
exit 1
|
||||
esac
|
||||
|
@ -5,6 +5,20 @@
|
||||
# there is no default
|
||||
# CTDB_RECOVERY_LOCK="/some/place/on/shared/storage"
|
||||
|
||||
# should ctdb do IP takeover? If it should, then specify a file
|
||||
# containing the list of public IP addresses that ctdb will manage
|
||||
# Note that these IPs must be different from those in $NODES above
|
||||
# there is no default
|
||||
# PUBLIC_ADDRESSES=/etc/ctdb/public_addresses
|
||||
|
||||
# when doing IP takeover you also must specify what network interface
|
||||
# to use for the public addresses
|
||||
# there is no default
|
||||
# PUBLIC_INTERFACE=eth0
|
||||
|
||||
# should ctdb manage starting/stopping the Samba service for you?
|
||||
# default is to not manage Samba
|
||||
# CTDB_MANAGES_SAMBA=yes
|
||||
|
||||
# the NODES file must be specified or ctdb won't start
|
||||
# it should contain a list of IPs that ctdb will use
|
||||
@ -29,17 +43,6 @@
|
||||
# defaults to tcp
|
||||
# TRANSPORT="tcp"
|
||||
|
||||
# should ctdb do IP takeover? If it should, then specify a file
|
||||
# containing the list of public IP addresses that ctdb will manage
|
||||
# Note that these IPs must be different from those in $NODES above
|
||||
# there is no default
|
||||
# PUBLIC_ADDRESSES=/etc/ctdb/public_addresses
|
||||
|
||||
# when doing IP takeover you also must specify what network interface
|
||||
# to use for the public addresses
|
||||
# there is no default
|
||||
# PUBLIC_INTERFACE=eth0
|
||||
|
||||
# where to log messages
|
||||
# the default is /var/log/log.ctdb
|
||||
# LOGFILE=/var/log/log.ctdb
|
@ -33,8 +33,8 @@ case $cmd in
|
||||
# restart NFS to ensure that all TCP connections to the released ip
|
||||
# are closed
|
||||
[ -f /etc/ctdb/state/nfs/restart ] && {
|
||||
( /sbin/service nfs status > /dev/null 2>&1 &&
|
||||
/sbin/service nfs restart > /dev/null 2>&1 ) &
|
||||
( service nfs status > /dev/null 2>&1 &&
|
||||
service nfs restart > /dev/null 2>&1 ) &
|
||||
} > /dev/null 2>&1
|
||||
/bin/rm -f /etc/ctdb/state/nfs/restart
|
||||
;;
|
@ -9,8 +9,14 @@ PATH=/bin:/usr/bin:$PATH
|
||||
cmd="$1"
|
||||
shift
|
||||
|
||||
[ "$CTDB_MANAGES_SAMBA" = "yes" ] || exit 0
|
||||
|
||||
case $cmd in
|
||||
startup)
|
||||
# start Samba service
|
||||
service smb start
|
||||
service winbind start
|
||||
|
||||
# wait for the Samba tcp ports to become available
|
||||
smb_ports=`testparm -stv 2> /dev/null | egrep '\s*smb ports =' | cut -d= -f2`
|
||||
ctdb_wait_tcp_ports "Samba" $smb_ports
|
||||
@ -35,7 +41,8 @@ case $cmd in
|
||||
|
||||
shutdown)
|
||||
# shutdown Samba when ctdb goes down
|
||||
killall -q smbd nmbd winbindd
|
||||
service smb stop
|
||||
service winbind stop
|
||||
;;
|
||||
esac
|
||||
|
@ -1,6 +1,20 @@
|
||||
# utility functions for ctdb event scripts
|
||||
|
||||
|
||||
######################################################
|
||||
# simulate /sbin/service on platforms that don't have it
|
||||
service() {
|
||||
service_name="$1"
|
||||
op="$2"
|
||||
if [ -x /sbin/service ]; then
|
||||
/sbin/service "$service_name" "$op"
|
||||
elif [ -x /etc/init.d/$service_name ]; then
|
||||
/etc/init.d/$service_name "$op"
|
||||
elif [ -x /etc/rc.d/init.d/$service_name ]; then
|
||||
/etc/init.d/$service_name "$op"
|
||||
fi
|
||||
}
|
||||
|
||||
######################################################
|
||||
# wait for a set of tcp ports
|
||||
# usage: ctdb_wait_tcp_ports SERICE_NAME <ports...>
|
@ -1,7 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
# this script needs to be installed so that statd points to it with the -H
|
||||
# command line argument. The easiest way to do that is
|
||||
# command line argument. The easiest way to do that is to put something like this in
|
||||
# /etc/sysconfig/nfs:
|
||||
# STATD_HOSTNAME="myhostname -H /etc/ctdb/statd-callout"
|
||||
|
||||
|
||||
. /etc/sysconfig/nfs
|
||||
|
@ -12,7 +12,7 @@ AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
|
||||
AC_DEFUN([SMB_EXT_LIB], [echo -n ""])
|
||||
AC_DEFUN([SMB_ENABLE], [echo -n ""])
|
||||
AC_INIT(ctdb.h)
|
||||
AC_CONFIG_SRCDIR([tests/ctdb_test.c])
|
||||
AC_CONFIG_SRCDIR([common/ctdb.c])
|
||||
|
||||
AC_LIBREPLACE_ALL_CHECKS
|
||||
|
||||
|
@ -57,8 +57,8 @@ mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d
|
||||
|
||||
make DESTDIR=$RPM_BUILD_ROOT install
|
||||
|
||||
install -m644 tools/ctdb.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ctdb
|
||||
install -m755 packaging/ctdb.init $RPM_BUILD_ROOT%{initdir}/ctdb
|
||||
install -m644 config/ctdb.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ctdb
|
||||
install -m755 config/ctdb.init $RPM_BUILD_ROOT%{initdir}/ctdb
|
||||
|
||||
# Remove "*.old" files
|
||||
find $RPM_BUILD_ROOT -name "*.old" -exec rm -f {} \;
|
||||
|
@ -1,245 +0,0 @@
|
||||
/*
|
||||
test a lock wait idea
|
||||
|
||||
Copyright (C) Andrew Tridgell 2006
|
||||
|
||||
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 2 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, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
#include "lib/events/events.h"
|
||||
#include "system/filesys.h"
|
||||
#include "system/wait.h"
|
||||
#include "popt.h"
|
||||
#include "cmdline.h"
|
||||
|
||||
|
||||
struct lockwait_handle {
|
||||
struct fd_event *fde;
|
||||
int fd[2];
|
||||
pid_t child;
|
||||
void *private_data;
|
||||
void (*callback)(void *);
|
||||
};
|
||||
|
||||
static void lockwait_handler(struct event_context *ev, struct fd_event *fde,
|
||||
uint16_t flags, void *private_data)
|
||||
{
|
||||
struct lockwait_handle *h = talloc_get_type(private_data,
|
||||
struct lockwait_handle);
|
||||
void (*callback)(void *) = h->callback;
|
||||
void *p = h->private_data;
|
||||
talloc_set_destructor(h, NULL);
|
||||
close(h->fd[0]);
|
||||
talloc_free(h);
|
||||
callback(p);
|
||||
waitpid(h->child, NULL, 0);
|
||||
}
|
||||
|
||||
static int lockwait_destructor(struct lockwait_handle *h)
|
||||
{
|
||||
close(h->fd[0]);
|
||||
kill(h->child, SIGKILL);
|
||||
waitpid(h->child, NULL, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct lockwait_handle *lockwait(struct event_context *ev,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
int fd, off_t ofs, size_t len,
|
||||
void (*callback)(void *), void *private_data)
|
||||
{
|
||||
struct lockwait_handle *h;
|
||||
int ret;
|
||||
|
||||
h = talloc_zero(mem_ctx, struct lockwait_handle);
|
||||
if (h == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = pipe(h->fd);
|
||||
if (ret != 0) {
|
||||
talloc_free(h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
h->child = fork();
|
||||
if (h->child == (pid_t)-1) {
|
||||
close(h->fd[0]);
|
||||
close(h->fd[1]);
|
||||
talloc_free(h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
h->callback = callback;
|
||||
h->private_data = private_data;
|
||||
|
||||
if (h->child == 0) {
|
||||
/* in child */
|
||||
struct flock lock;
|
||||
close(h->fd[0]);
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = ofs;
|
||||
lock.l_len = len;
|
||||
lock.l_pid = 0;
|
||||
fcntl(fd,F_SETLKW,&lock);
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
close(h->fd[1]);
|
||||
talloc_set_destructor(h, lockwait_destructor);
|
||||
|
||||
h->fde = event_add_fd(ev, h, h->fd[0], EVENT_FD_READ, lockwait_handler, h);
|
||||
if (h->fde == NULL) {
|
||||
talloc_free(h);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void fcntl_lock_callback(void *p)
|
||||
{
|
||||
int *got_lock = (int *)p;
|
||||
*got_lock = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
get an fcntl lock - waiting if necessary
|
||||
*/
|
||||
static int fcntl_lock(struct event_context *ev,
|
||||
int fd, int op, off_t offset, off_t count, int type)
|
||||
{
|
||||
struct flock lock;
|
||||
int ret;
|
||||
int use_lockwait = (op == F_SETLKW);
|
||||
int got_lock = 0;
|
||||
|
||||
lock.l_type = type;
|
||||
lock.l_whence = SEEK_SET;
|
||||
lock.l_start = offset;
|
||||
lock.l_len = count;
|
||||
lock.l_pid = 0;
|
||||
|
||||
do {
|
||||
ret = fcntl(fd,use_lockwait?F_SETLK:op,&lock);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (ret == -1 &&
|
||||
(errno == EACCES || errno == EAGAIN || errno == EDEADLK)) {
|
||||
struct lockwait_handle *h;
|
||||
h = lockwait(ev, ev, fd, offset, count,
|
||||
fcntl_lock_callback, &got_lock);
|
||||
if (h == NULL) {
|
||||
errno = ENOLCK;
|
||||
return -1;
|
||||
}
|
||||
/* in real code we would return to the event loop */
|
||||
while (!got_lock) {
|
||||
event_loop_once(ev);
|
||||
}
|
||||
got_lock = 0;
|
||||
}
|
||||
} while (!got_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void child(struct event_context *ev, int n)
|
||||
{
|
||||
int fd;
|
||||
int count=0;
|
||||
struct timeval tv;
|
||||
fd = open("test.dat", O_CREAT|O_RDWR, 0666);
|
||||
if (fd == -1) {
|
||||
perror("test.dat");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tv = timeval_current();
|
||||
|
||||
while (timeval_elapsed(&tv) < 10) {
|
||||
int ret;
|
||||
ret = fcntl_lock(ev, fd, F_SETLKW, 0, 1, F_WRLCK);
|
||||
if (ret != 0) {
|
||||
printf("Failed to get lock in child %d!\n", n);
|
||||
break;
|
||||
}
|
||||
fcntl_lock(ev, fd, F_SETLK, 0, 1, F_UNLCK);
|
||||
count++;
|
||||
}
|
||||
|
||||
printf("child %2d %.0f ops/sec\n", n, count/timeval_elapsed(&tv));
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
static int timelimit = 10;
|
||||
|
||||
/*
|
||||
main program
|
||||
*/
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
pid_t *pids;
|
||||
int nprogs = 2;
|
||||
int i;
|
||||
struct event_context *ev;
|
||||
struct poptOption popt_options[] = {
|
||||
POPT_AUTOHELP
|
||||
{ "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
|
||||
{ "num-progs", 'n', POPT_ARG_INT, &nprogs, 0, "num_progs", "integer" },
|
||||
POPT_TABLEEND
|
||||
};
|
||||
poptContext pc;
|
||||
int opt;
|
||||
|
||||
pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
|
||||
|
||||
while ((opt = poptGetNextOpt(pc)) != -1) {
|
||||
switch (opt) {
|
||||
default:
|
||||
fprintf(stderr, "Invalid option %s: %s\n",
|
||||
poptBadOption(pc, 0), poptStrerror(opt));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
ev = event_context_init(NULL);
|
||||
|
||||
pids = talloc_array(ev, pid_t, nprogs);
|
||||
|
||||
/* create N processes fighting over the same lock */
|
||||
for (i=0;i<nprogs;i++) {
|
||||
pids[i] = fork();
|
||||
if (pids[i] == 0) {
|
||||
child(ev, i);
|
||||
}
|
||||
}
|
||||
|
||||
printf("Waiting for %d children ...\n", nprogs);
|
||||
|
||||
/* wait for our kids to finish playing */
|
||||
for (i=0;i<nprogs;i++) {
|
||||
waitpid(pids[i], NULL, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
CTDB="./bin/ctdb"
|
||||
export CTDB
|
||||
|
||||
$CTDB status | egrep "^vnn:" | sed -e "s/^vnn://" -e "s/ .*$//" | while read NODE; do
|
||||
xterm -geometry 30x25 -e "watch -n1 \"$CTDB -n $NODE status\"" &
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user