All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cluster-devel] cluster/dlm/tests/usertest Makefile flood.c
@ 2007-01-09 14:17 pcaulfield
  0 siblings, 0 replies; only message in thread
From: pcaulfield @ 2007-01-09 14:17 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	pcaulfield at sourceware.org	2007-01-09 14:17:37

Modified files:
	dlm/tests/usertest: Makefile 
Added files:
	dlm/tests/usertest: flood.c 

Log message:
	Add flood program back.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tests/usertest/flood.c.diff?cvsroot=cluster&r1=1.1&r2=1.2
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tests/usertest/Makefile.diff?cvsroot=cluster&r1=1.6&r2=1.7

--- cluster/dlm/tests/usertest/flood.c	2005/12/13 11:20:23	1.1
+++ cluster/dlm/tests/usertest/flood.c	2007/01/09 14:17:37	1.2
@@ -0,0 +1,163 @@
+/* Flood the DLM !
+   but not too much...
+*/
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/poll.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <limits.h>
+#include <unistd.h>
+#include <errno.h>
+#include <getopt.h>
+
+#include "libdlm.h"
+
+static pthread_cond_t  cond;
+static pthread_mutex_t mutex;
+
+static int count = 0;
+
+static void usage(char *prog, FILE *file)
+{
+    fprintf(file, "Usage:\n");
+    fprintf(file, "%s [mcnpquhV] <lockname>\n", prog);
+    fprintf(file, "\n");
+    fprintf(file, "   -V         Show version of %s\n", prog);
+    fprintf(file, "   -h         Show this help information\n");
+    fprintf(file, "   -m <num>   Maximum number of locks to hold (default MAX_INT)\n");
+    fprintf(file, "   -i <num>   Show progress in <n> increments (default 1000)\n");
+    fprintf(file, "   -n <num>   Number of resources (default 10)\n");
+    fprintf(file, "   -q         Quit\n");
+
+
+    fprintf(file, "\n");
+
+}
+
+static void ast_routine(void *arg)
+{
+    struct dlm_lksb *lksb = arg;
+
+    if (lksb->sb_status == 0) {
+	dlm_unlock(lksb->sb_lkid, 0, lksb, lksb);
+	return;
+    }
+
+    if (lksb->sb_status == EUNLOCK) {
+	    count--;
+	    free(lksb);
+    }
+
+}
+
+int main(int argc, char *argv[])
+{
+    int  flags = 0;
+    int  lockops = 0;
+    int  maxlocks = INT_MAX;
+    int  rescount = 10;
+    int  increment = 1000;
+    int  quiet = 0;
+    int  status;
+    int  i;
+    int  mode = LKM_CRMODE;
+    signed char opt;
+    char **resources;
+
+    /* Deal with command-line arguments */
+    opterr = 0;
+    optind = 0;
+    while ((opt=getopt(argc,argv,"?m:i:qn:vV")) != EOF)
+    {
+	switch(opt)
+	{
+	case 'h':
+	    usage(argv[0], stdout);
+	    exit(0);
+
+	case '?':
+	    usage(argv[0], stderr);
+	    exit(0);
+
+	case 'm':
+	    maxlocks = atoi(optarg);
+	    break;
+
+	case 'i':
+	    increment = atoi(optarg);
+	    break;
+
+	case 'n':
+	    rescount = atoi(optarg);
+	    break;
+
+	case 'q':
+	    quiet = 1;
+	    break;
+
+	case 'V':
+	    printf("\nflood version 0.2\n\n");
+	    exit(1);
+	    break;
+	}
+    }
+
+    resources = malloc(sizeof(char*) * rescount);
+    for (i=0; i < rescount; i++) {
+	    char resname[256];
+	    sprintf(resname, "TESTLOCK%d", i);
+	    resources[i] = strdup(resname);
+    }
+
+    pthread_cond_init(&cond, NULL);
+    pthread_mutex_init(&mutex, NULL);
+    pthread_mutex_lock(&mutex);
+
+    dlm_pthread_init();
+
+    while (1) {
+	    char *resource = resources[rand() % rescount];
+	    struct dlm_lksb *lksb = malloc(sizeof(struct dlm_lksb));
+	    if (!lksb)
+		    exit(1);
+
+	    status = dlm_lock(mode,
+			      lksb,
+			      flags,
+			      resource,
+			      strlen(resource),
+			      0, // Parent,
+			      ast_routine,
+			      lksb,
+			      NULL, // bast_routine,
+			      NULL); // Range
+	    if (status == -1)
+	    {
+		    perror("lock failed");
+		    return -1;
+	    }
+
+	    count++;
+	    lockops++;
+	    if ((lockops % increment) == 0 && !quiet)
+		    fprintf(stderr, "%d lockops, %d locks\n", lockops, count);
+
+	    while (count > maxlocks) {
+		    sleep(1);
+	    }
+
+    }
+
+    return 0;
+}
+
--- cluster/dlm/tests/usertest/Makefile	2006/12/07 19:50:49	1.6
+++ cluster/dlm/tests/usertest/Makefile	2007/01/09 14:17:37	1.7
@@ -12,7 +12,7 @@
 top_srcdir = ../../..
 UNINSTALL=${top_srcdir}/scripts/uninstall.pl
 
-BINARIES=dlmtest asttest lstest pingtest lvb dlmtest2
+BINARIES=dlmtest asttest lstest pingtest lvb dlmtest2 flood
 
 all: $(BINARIES)
 
@@ -32,6 +32,9 @@
 dlmtest2: dlmtest2.c
 	$(CC) $(CFLAGS) -o $@ $< -ldlm -lpthread
 
+flood: flood.c
+	$(CC) $(CFLAGS) -o $@ $< -ldlm -lpthread
+
 asttest: asttest.c
 	$(CC) $(CFLAGS) -o $@ $< -ldlm -lpthread
 



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-01-09 14:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-09 14:17 [Cluster-devel] cluster/dlm/tests/usertest Makefile flood.c pcaulfield

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.