From mboxrd@z Thu Jan 1 00:00:00 1970 From: teigland@sourceware.org Date: 5 Jun 2007 18:27:27 -0000 Subject: [Cluster-devel] cluster/dlm Makefile tool/Makefile tool/main.c Message-ID: <20070605182727.2535.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: cluster Branch: RHEL5 Changes by: teigland at sourceware.org 2007-06-05 18:27:27 Modified files: dlm : Makefile Added files: dlm/tool : Makefile main.c Log message: add dlm_tool, can be used to join/leave lockspace Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/Makefile.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.7&r2=1.7.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tool/Makefile.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=NONE&r2=1.2.2.1 http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tool/main.c.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=NONE&r2=1.2.2.1 --- cluster/dlm/Makefile 2006/08/11 15:18:06 1.7 +++ cluster/dlm/Makefile 2007/06/05 18:27:26 1.7.2.1 @@ -13,15 +13,19 @@ all: ${MAKE} -C lib all + ${MAKE} -C tool all install: all ${MAKE} -C lib install + ${MAKE} -C tool install uninstall: ${MAKE} -C lib uninstall + ${MAKE} -C tool uninstall clean: ${MAKE} -C lib clean + ${MAKE} -C tool clean rm -f *~ distclean: clean /cvs/cluster/cluster/dlm/tool/Makefile,v --> standard output revision 1.2.2.1 --- cluster/dlm/tool/Makefile +++ - 2007-06-05 18:27:27.416542000 +0000 @@ -0,0 +1,35 @@ +############################################################################### +############################################################################### +## +## Copyright (C) 2005 Red Hat, Inc. All rights reserved. +## +## This copyrighted material is made available to anyone wishing to use, +## modify, copy, or redistribute it subject to the terms and conditions +## of the GNU General Public License v.2. +## +############################################################################### +############################################################################### + +top_srcdir=.. +include ${top_srcdir}/make/defines.mk + +CFLAGS += -g -I. -I../lib/ +LDFLAGS += -ldlm + +TARGET=dlm_tool + +all: ${TARGET} + +dlm_tool: main.o + $(CC) $(LDFLAGS) -o $@ $^ + +main.o: main.c + $(CC) $(CFLAGS) -c -o $@ $< + +clean: + rm -f *.o dlm_tool + +install: all + install -d ${sbindir} + install dlm_tool ${sbindir} + /cvs/cluster/cluster/dlm/tool/main.c,v --> standard output revision 1.2.2.1 --- cluster/dlm/tool/main.c +++ - 2007-06-05 18:27:27.496074000 +0000 @@ -0,0 +1,194 @@ +/****************************************************************************** +******************************************************************************* +** +** Copyright (C) 2007 Red Hat, Inc. All rights reserved. +** +** This copyrighted material is made available to anyone wishing to use, +** modify, copy, or redistribute it subject to the terms and conditions +** of the GNU General Public License v.2. +** +******************************************************************************* +******************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libdlm.h" + +#define OPTION_STRING "hVvd:" + +#define OP_JOIN 1 +#define OP_LEAVE 2 +#define OP_JOINLEAVE 3 + +static char *prog_name; +static char *lsname; +static int operation; +static int opt_ind; +static int verbose; +static int opt_dir = 0; + +static void print_usage(void) +{ + printf("Usage:\n"); + printf("\n"); + printf("%s [options] [join|leave]\n", prog_name); + printf("\n"); + printf("Options:\n"); + printf(" -v Verbose output, extra event information\n"); + printf(" -h Print this help, then exit\n"); + printf(" -V Print program version information, then exit\n"); + printf(" -d Resource directory off/on (0/1), default 0\n"); + printf("\n"); +} + +static void decode_arguments(int argc, char **argv) +{ + int cont = 1; + int optchar; + + while (cont) { + optchar = getopt(argc, argv, OPTION_STRING); + + switch (optchar) { + case 'v': + verbose = 1; + break; + + case 'h': + print_usage(); + exit(EXIT_SUCCESS); + break; + + case 'd': + opt_dir = atoi(optarg); + break; + + case 'V': + printf("%s (built %s %s)\n", + prog_name, __DATE__, __TIME__); + /* printf("%s\n", REDHAT_COPYRIGHT); */ + exit(EXIT_SUCCESS); + break; + + case ':': + case '?': + fprintf(stderr, "Please use '-h' for usage.\n"); + exit(EXIT_FAILURE); + break; + + case EOF: + cont = 0; + break; + + default: + fprintf(stderr, "unknown option: %c\n", optchar); + exit(EXIT_FAILURE); + break; + }; + } + + while (optind < argc) { + if (!strncmp(argv[optind], "join", 4) && + (strlen(argv[optind]) == 4)) { + operation = OP_JOIN; + opt_ind = optind + 1; + break; + } else if (!strncmp(argv[optind], "leave", 5) && + (strlen(argv[optind]) == 5)) { + operation = OP_LEAVE; + opt_ind = optind + 1; + break; + } else if (!strncmp(argv[optind], "joinleave", 9) && + (strlen(argv[optind]) == 9)) { + operation = OP_JOINLEAVE; + opt_ind = optind + 1; + break; + } + optind++; + } + + if (!operation || !opt_ind) { + print_usage(); + exit(EXIT_FAILURE); + } + + if (optind < argc - 1) + lsname = argv[opt_ind]; + else { + fprintf(stderr, "lockspace name required\n"); + exit(EXIT_FAILURE); + } +} + +void do_join(char *name) +{ + dlm_lshandle_t *dh; + + printf("Joining lockspace \"%s\"\n", name); + fflush(stdout); + + dh = dlm_new_lockspace(name, 0600, DLM_LSFL_NODIR); + if (!dh) { + fprintf(stderr, "dlm_create_lockspace %s error %lu %d\n", + name, (unsigned long) dh, errno); + exit(-1); + } + + dlm_close_lockspace(dh); + /* there's no autofree so the ls should stay around */ + printf("done\n"); +} + +void do_leave(char *name) +{ + dlm_lshandle_t *dh; + + printf("Leaving lockspace \"%s\"\n", name); + fflush(stdout); + + dh = dlm_open_lockspace(name); + if (!dh) { + fprintf(stderr, "dlm_open_lockspace %s error %lu %d\n", + name, (unsigned long) dh, errno); + exit(-1); + } + + dlm_release_lockspace(name, dh, 1); + printf("done\n"); +} + +int main(int argc, char **argv) +{ + prog_name = argv[0]; + decode_arguments(argc, argv); + /* check_name(lsname); */ + + switch (operation) { + case OP_JOIN: + do_join(lsname); + break; + + case OP_LEAVE: + do_leave(lsname); + break; + + case OP_JOINLEAVE: + do_join(lsname); + do_leave(lsname); + break; + } + + return 0; +} +