Hi, all I rewrite sfex_stat command for current version that was originally included in the sfex-1.3.
The sfex_stat command is useful for confirms the lock status when the trouble occurred. Please see attached patch and let me know if you have any comments. Best Regards, -- NAKAHIRA Kazutomo Infrastructure Software Technology Unit NTT Open Source Software Center
exporting patch: # HG changeset patch # User NAKAHIRA Kazutomo <nakahira.kazut...@oss.ntt.co.jp> # Date 1291166215 -32400 # Node ID 6a8d6fcc32cc4f21830e304b06aef543525b618b # Parent 282d7683ffee5918ae5ca3b2fc08441888c7c43e sfex: add the sfex_stat command diff -r 282d7683ffee -r 6a8d6fcc32cc resource-agents.spec --- a/resource-agents.spec Tue Nov 30 15:48:21 2010 +0900 +++ b/resource-agents.spec Wed Dec 01 10:16:55 2010 +0900 @@ -186,6 +186,7 @@ %{_sbindir}/ocf-tester %{_sbindir}/ocft %{_sbindir}/sfex_init +%{_sbindir}/sfex_stat %{_includedir}/heartbeat %dir %attr (1755, root, root) %{_var}/run/resource-agents diff -r 282d7683ffee -r 6a8d6fcc32cc tools/Makefile.am --- a/tools/Makefile.am Tue Nov 30 15:48:21 2010 +0900 +++ b/tools/Makefile.am Wed Dec 01 10:16:55 2010 +0900 @@ -31,7 +31,7 @@ if BUILD_SFEX halib_PROGRAMS += sfex_daemon -sbin_PROGRAMS += sfex_init +sbin_PROGRAMS += sfex_init sfex_stat endif if USE_LIBNET @@ -56,6 +56,10 @@ sfex_init_CFLAGS = -D_GNU_SOURCE sfex_init_LDADD = $(GLIBLIB) -lplumb -lplumbgpl +sfex_stat_SOURCES = sfex_stat.c sfex.h sfex_lib.c sfex_lib.h +sfex_stat_CFLAGS = -D_GNU_SOURCE +sfex_stat_LDADD = $(GLIBLIB) -lplumb -lplumbgpl + findif_SOURCES = findif.c if BUILD_TICKLE diff -r 282d7683ffee -r 6a8d6fcc32cc tools/sfex_daemon.c --- a/tools/sfex_daemon.c Tue Nov 30 15:48:21 2010 +0900 +++ b/tools/sfex_daemon.c Wed Dec 01 10:16:55 2010 +0900 @@ -39,33 +39,6 @@ fprintf(dist, "usage: %s [-i <index>] [-c <collision_timeout>] [-t <lock_timeout>] <device>\n", progname); } -static int lock_index_check(void) -{ - if (read_controldata(&cdata) == -1) { - cl_log(LOG_ERR, "%s\n", "read_controldata failed in lock_index_check"); - return -1; - } -#ifdef SFEX_DEBUG - cl_log(LOG_INFO, "version: %d\n", cdata.version); - cl_log(LOG_INFO, "revision: %d\n", cdata.revision); - cl_log(LOG_INFO, "blocksize: %d\n", cdata.blocksize); - cl_log(LOG_INFO, "numlocks: %d\n", cdata.numlocks); -#endif - - if (lock_index > cdata.numlocks) { - cl_log(LOG_ERR, "index %d is too large. %d locks are stored.\n", - lock_index, cdata.numlocks); - return -1; - /*exit(EXIT_FAILURE);*/ - } - - if (cdata.blocksize != sector_size) { - cl_log(LOG_ERR, "sector_size is not the same as the blocksize.\n"); - return -1; - } - return 0; -} - static void acquire_lock(void) { if (read_lockdata(&cdata, &ldata, lock_index) == -1) { @@ -334,7 +307,7 @@ } #endif - ret = lock_index_check(); + ret = lock_index_check(&cdata, lock_index); if (ret == -1) exit(EXIT_FAILURE); diff -r 282d7683ffee -r 6a8d6fcc32cc tools/sfex_lib.c --- a/tools/sfex_lib.c Tue Nov 30 15:48:21 2010 +0900 +++ b/tools/sfex_lib.c Wed Dec 01 10:16:55 2010 +0900 @@ -2,7 +2,7 @@ * * Shared Disk File EXclusiveness Control Program(SF-EX) * - * lib.c --- Libraries for other SF-EX modules. + * sfex_lib.c --- Libraries for other SF-EX modules. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -168,7 +168,7 @@ * * cdata --- pointer of control data * - * device --- name of target file. + * device --- name of target file */ void write_controldata (const sfex_controldata * cdata) @@ -288,7 +288,7 @@ * * read sfex_controldata structure from file. * - * cdata --- pointer for control data. + * cdata --- pointer for control data * * device --- file name for reading */ @@ -432,3 +432,40 @@ #endif return 0; } + +/* + * lock_index_check --- check the value of index + * + * The lock_index_check function checks whether the value of index exceeds + * the number of lock data on the shared disk. + * + * cdata --- pointer for control data + * + * index --- index number + */ +int +lock_index_check(sfex_controldata * cdata, int index) +{ + if (read_controldata(cdata) == -1) { + cl_log(LOG_ERR, "%s\n", "read_controldata failed in lock_index_check"); + return -1; + } +#ifdef SFEX_DEBUG + cl_log(LOG_INFO, "version: %d\n", cdata->version); + cl_log(LOG_INFO, "revision: %d\n", cdata->revision); + cl_log(LOG_INFO, "blocksize: %d\n", cdata->blocksize); + cl_log(LOG_INFO, "numlocks: %d\n", cdata->numlocks); +#endif + + if (index > cdata->numlocks) { + cl_log(LOG_ERR, "index %d is too large. %d locks are stored.\n", + index, cdata->numlocks); + return -1; + } + + if (cdata->blocksize != sector_size) { + cl_log(LOG_ERR, "sector_size is not the same as the blocksize.\n"); + return -1; + } + return 0; +} diff -r 282d7683ffee -r 6a8d6fcc32cc tools/sfex_lib.h --- a/tools/sfex_lib.h Tue Nov 30 15:48:21 2010 +0900 +++ b/tools/sfex_lib.h Wed Dec 01 10:16:55 2010 +0900 @@ -2,7 +2,7 @@ * * Shared Disk File EXclusiveness Control Program(SF-EX) * - * lib.h --- Prototypes for lib.c. + * sfex_lib.h --- Prototypes for lib.c. * * Copyright (c) 2007 NIPPON TELEGRAPH AND TELEPHONE CORPORATION * @@ -37,5 +37,6 @@ int read_controldata(sfex_controldata *cdata); int read_lockdata(const sfex_controldata *cdata, sfex_lockdata *ldata, int index); int prepare_lock(const char *device); +int lock_index_check(sfex_controldata * cdata, int index); #endif /* LIB_H */ diff -r 282d7683ffee -r 6a8d6fcc32cc tools/sfex_stat.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/sfex_stat.c Wed Dec 01 10:16:55 2010 +0900 @@ -0,0 +1,218 @@ +/*------------------------------------------------------------------------- + * + * Shared Disk File EXclusiveness Control Program(SF-EX) + * + * sfex_stat.c --- Display lock status. This is a part of the SF-EX. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + * + * Copyright (c) 2007 NIPPON TELEGRAPH AND TELEPHONE CORPORATION + * + * $Id$ + * + *------------------------------------------------------------------------- + * + * sfex_stat [-i <index>] <device> + * + * -i <index> --- The index is number of the resource that display the lock. + * This number is specified by the integer of one or more. When two or more + * resources are exclusively controlled by one meta-data, this option is used. + * Default is 1. + * + * <device> --- This is file path which stored meta-data. It is usually + * expressed in "/dev/...", because it is partition on the shared disk. + * + * exit code --- 0 - Normal end. Own node is holding lock. 2 - Normal + * end. Own node does not hold a lock. 3 - Error occurs while processing + * it. The content of the error is displayed into stderr. 4 - The mistake + * is found in the command line parameter. + * + *-------------------------------------------------------------------------*/ + +#include <config.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <errno.h> +#include <string.h> +#include <limits.h> +#if HAVE_UNISTD_H +# include <unistd.h> +#endif + +#include "sfex.h" +#include "sfex_lib.h" + +const char *progname; +char *nodename; + +void print_controldata(const sfex_controldata *cdata); +void print_lockdata(const sfex_lockdata *ldata, int index); + +/* + * print_controldata --- print sfex control data to the display + * + * print sfex_controldata to the display. + * + * cdata --- pointer for control data + */ +void +print_controldata(const sfex_controldata *cdata) +{ + printf("control data:\n"); + printf(" magic: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", + cdata->magic[0], cdata->magic[1], cdata->magic[2], cdata->magic[3]); + printf(" version: %d\n", cdata->version); + printf(" revision: %d\n", cdata->revision); + printf(" blocksize: %d\n", (int)cdata->blocksize); + printf(" numlocks: %d\n", cdata->numlocks); +} + +/* + * print_lockdata --- print sfex lock data to the display + * + * print sfex_lockdata to the display. + * + * ldata --- pointer for lock data + * + * index --- index number + */ +void +print_lockdata(const sfex_lockdata *ldata, int index) +{ + printf("lock data #%d:\n", index); + printf(" status: %s\n", ldata->status == SFEX_STATUS_UNLOCK ? "unlock" : "lock"); + printf(" count: %d\n", ldata->count); + printf(" nodename: %s\n",ldata->nodename); +} + +/* + * usage --- display command line syntax + * + * display command line syntax. By the purpose, it can specify destination + * stream. stdout or stderr is set usually. + * + * dist --- destination stream of the command line syntax, such as stderr. + * + * retrun value --- void + */ +static void usage(FILE *dist) { + fprintf(dist, "usage: %s [-i <index>] <device>\n", progname); +} + +/* + * main --- main function + * + * entry point of sfex_stat command. + * + * exit code --- 0 - Normal end. Own node is holding lock. 2 - Normal + * end. Own node dose not hold a lock. 3 - Error occurs while processing + * it. The content of the error is displayed into stderr. 4 - The mistake + * is found in the command line parameter. + */ +int +main(int argc, char *argv[]) { + sfex_controldata cdata; + sfex_lockdata ldata; + int ret = 0; + + /* command line parameter */ + int index = 1; /* default 1st lock */ + const char *device; + + /* + * startup process + */ + + /* get a program name */ + progname = get_progname(argv[0]); + + /* enable the cl_log output from the sfex library */ + cl_log_set_entity(progname); + /* The cl_log is output only to the standard error output */ + cl_log_enable_stderr(TRUE); + + /* read command line option */ + opterr = 0; + while (1) { + int c = getopt(argc, argv, "hi:"); + if (c == -1) + break; + switch (c) { + case 'h': /* help */ + usage(stdout); + exit(0); + case 'i': /* -i <index> */ + { + unsigned long l = strtoul(optarg, NULL, 10); + if (l < SFEX_MIN_NUMLOCKS || l > SFEX_MAX_NUMLOCKS) { + fprintf(stderr, + "%s: ERROR: index %s is out of range or invalid. it must be integer value between %lu and %lu.\n", + progname, optarg, + (unsigned long)SFEX_MIN_NUMLOCKS, + (unsigned long)SFEX_MAX_NUMLOCKS); + exit(4); + } + index = l; + } + break; + case '?': /* error */ + usage(stderr); + exit(4); + } + } + + /* check parameter except the option */ + if (optind >= argc) { + fprintf(stderr, "%s: ERROR: no device specified.\n", progname); + usage(stderr); + exit(4); + } else if (optind + 1 < argc) { + fprintf(stderr, "%s: ERROR: too many arguments.\n", progname); + usage(stderr); + exit(4); + } + device = argv[optind]; + + /* + * main processes start + */ + + /* get a node name */ + nodename = get_nodename(); + + prepare_lock(device); + + ret = lock_index_check(&cdata, index); + if (ret == -1) + exit(EXIT_FAILURE); + + /* read lock data */ + read_lockdata(&cdata, &ldata, index); + + /* display status */ + print_controldata(&cdata); + print_lockdata(&ldata, index); + + /* check current lock status */ + if (ldata.status != SFEX_STATUS_LOCK || strcmp(ldata.nodename, nodename)) { + fprintf(stdout, "status is UNLOCKED.\n"); + exit(2); + } else { + fprintf(stdout, "status is LOCKED.\n"); + exit(0); + } +}
_______________________________________________________ Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev Home Page: http://linux-ha.org/