All of lore.kernel.org
 help / color / mirror / Atom feed
From: teigland@sourceware.org <teigland@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] cluster/dlm/tests/usertest Makefile alternate- ...
Date: 31 Jan 2007 18:47:41 -0000	[thread overview]
Message-ID: <20070131184741.6844.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	teigland at sourceware.org	2007-01-31 18:47:41

Modified files:
	dlm/tests/usertest: Makefile 
Added files:
	dlm/tests/usertest: alternate-lvb.c 

Log message:
	test program like gfs's 'alternate' but using an lvb instead of a file.
	nodes take turns incrementing the counter in the lvb

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tests/usertest/alternate-lvb.c.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tests/usertest/Makefile.diff?cvsroot=cluster&r1=1.7&r2=1.8

/cvs/cluster/cluster/dlm/tests/usertest/alternate-lvb.c,v  -->  standard output
revision 1.1
--- cluster/dlm/tests/usertest/alternate-lvb.c
+++ -	2007-01-31 18:47:41.809138000 +0000
@@ -0,0 +1,177 @@
+/******************************************************************************
+*******************************************************************************
+**
+**    Copyright 2001 Sistina Software, Inc.
+**
+**    This is free software released under the GNU General Public License.
+**    There is no warranty for this software.  See the file COPYING for
+**    details.
+**
+*******************************************************************************
+******************************************************************************/
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <syslog.h>
+#include <asm/types.h>
+#include <sys/socket.h>
+#include <sys/poll.h>
+#include <sys/un.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+
+#include "libdlm.h"
+
+#define die(fmt, args...) \
+do \
+{ \
+  fprintf(stderr, "%s: ", prog_name); \
+  fprintf(stderr, fmt, ##args); \
+  exit(EXIT_FAILURE); \
+} \
+while (0)
+
+static char *prog_name;
+static dlm_lshandle_t *dh;
+static int verbose;
+
+static struct dlm_lksb lksb;
+static char lvb[32];
+
+int main(int argc, char *argv[])
+{
+	unsigned long long offset;
+	unsigned long long num, last_num = 0;
+	unsigned int id, clients, sleep = 0;
+	unsigned long long skip = 0;
+	char *name;
+	int rv;
+
+	prog_name = argv[0];
+	verbose = 0;
+
+	if (argc < 5)
+		die("name offset id clients [sleep]\n");
+
+	name = argv[1];
+	offset = atoll(argv[2]);
+	id = atoi(argv[3]);
+	clients = atoi(argv[4]);
+
+	if (argc > 5)
+		sleep = atoi(argv[5]);
+
+	printf("Joining \"alternate\" lockspace...\n");
+
+	dh = dlm_create_lockspace("alternate", 0600);
+	if (!dh) {
+		printf("dlm_create_lockspace error %d %d\n", (int) dh, errno);
+		return -ENOTCONN;
+	}
+
+	rv = dlm_ls_pthread_init(dh);
+	if (rv < 0) {
+		printf("dlm_ls_pthread_init error %d %d\n", rv, errno);
+		dlm_release_lockspace("alternate", dh, 1);
+		return rv;
+	}
+
+	memset(&lksb, 0, sizeof(lksb));
+	memset(&lvb, 0, sizeof(lvb));
+	lksb.sb_lvbptr = lvb;
+
+	if (verbose)
+		printf("request NL\n");
+
+	rv = dlm_ls_lock_wait(dh, LKM_NLMODE, &lksb, LKF_VALBLK,
+			      name, strlen(name), 0, NULL, NULL, NULL);
+
+	while (1) {
+		if (verbose)
+			printf("convert NL->PR\n");
+
+		rv = dlm_ls_lock_wait(dh, LKM_PRMODE, &lksb,
+				      LKF_VALBLK | LKF_CONVERT,
+			      	      name, strlen(name),
+				      0, NULL, NULL, NULL);
+		if (rv)
+			printf("lock1 error: %d %d\n", rv, lksb.sb_status);
+
+		memcpy(&num, &lvb, sizeof(num));
+
+		if (verbose)
+			printf("read lvb %llu\n", num);
+
+		/* it's our turn */
+		if (num % clients == id) {
+			if (last_num && last_num + clients != num + 1)
+				die("bad: num %llu last_num %llu\n",
+				    num, last_num);
+
+			if (verbose)
+				printf("convert PR->EX\n");
+
+			rv = dlm_ls_lock_wait(dh, LKM_EXMODE, &lksb,
+				      	      LKF_VALBLK | LKF_CONVERT,
+					      name, strlen(name),
+					      0, NULL, NULL, NULL);
+			if (rv)
+				printf("lock2 error: %d %d\n", rv,
+					lksb.sb_status);
+
+			memcpy(&num, &lvb, sizeof(num));
+			if (num % clients != id)
+				die("bad2: num %llu\n", num);
+
+			num++;
+
+			memcpy(&lvb, &num, sizeof(num));
+			printf("%llu %llu\n", num, skip);
+
+			if (verbose)
+				printf("convert EX->NL\n");
+
+			rv = dlm_ls_lock_wait(dh, LKM_NLMODE, &lksb,
+				      	      LKF_VALBLK | LKF_CONVERT,
+					      name, strlen(name),
+					      0, NULL, NULL, NULL);
+			if (rv)
+				printf("lock3 error: %d %d\n", rv,
+					lksb.sb_status);
+
+			last_num = num;
+			skip = 0;
+		} else {
+			skip++;
+
+			if (verbose)
+				printf("convert PR->NL, skip %llu\n", skip);
+
+			rv = dlm_ls_lock_wait(dh, LKM_NLMODE, &lksb,
+				      	      LKF_VALBLK | LKF_CONVERT,
+					      name, strlen(name),
+					      0, NULL, NULL, NULL);
+			if (rv)
+				printf("lock4 error: %d %d\n", rv,
+					lksb.sb_status);
+		}
+
+		if (sleep)
+			usleep(sleep);
+	}
+
+	dlm_ls_unlock_wait(dh, lksb.sb_lkid, 0, &lksb);
+	dlm_release_lockspace("alternate", dh, 1);
+
+	exit(EXIT_SUCCESS);
+}
+
--- cluster/dlm/tests/usertest/Makefile	2007/01/09 14:17:37	1.7
+++ cluster/dlm/tests/usertest/Makefile	2007/01/31 18:47:41	1.8
@@ -12,7 +12,7 @@
 top_srcdir = ../../..
 UNINSTALL=${top_srcdir}/scripts/uninstall.pl
 
-BINARIES=dlmtest asttest lstest pingtest lvb dlmtest2 flood
+BINARIES=dlmtest asttest lstest pingtest lvb dlmtest2 flood alternate-lvb
 
 all: $(BINARIES)
 
@@ -32,6 +32,9 @@
 dlmtest2: dlmtest2.c
 	$(CC) $(CFLAGS) -o $@ $< -ldlm -lpthread
 
+alternate-lvb: alternate-lvb.c
+	$(CC) $(CFLAGS) -o $@ $< -ldlm -lpthread
+
 flood: flood.c
 	$(CC) $(CFLAGS) -o $@ $< -ldlm -lpthread
 



                 reply	other threads:[~2007-01-31 18:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070131184741.6844.qmail@sourceware.org \
    --to=teigland@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.