From 80e47b704eed25ffdc080eee10119947b919bf86 Mon Sep 17 00:00:00 2001 From: adilger Date: Tue, 4 Mar 2003 17:30:44 +0000 Subject: [PATCH] Remove extraneous whitespace. --- lustre/utils/obdbarrier.c | 88 +++++----- lustre/utils/obdio.c | 42 ++--- lustre/utils/obdiolib.c | 400 +++++++++++++++++++++++----------------------- 3 files changed, 265 insertions(+), 265 deletions(-) diff --git a/lustre/utils/obdbarrier.c b/lustre/utils/obdbarrier.c index 3363824..4373071 100644 --- a/lustre/utils/obdbarrier.c +++ b/lustre/utils/obdbarrier.c @@ -70,13 +70,13 @@ parse_kmg (uint64_t *valp, char *str) } void -usage (char *cmdname, int help) +usage (char *cmdname, int help) { char *name = strrchr (cmdname, '/'); - + if (name == NULL) name = cmdname; - + fprintf (help ? stdout : stderr, "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n", name); @@ -85,32 +85,32 @@ usage (char *cmdname, int help) int exponential_modulus (int i, int base) { - int top = base; - int mod = 1; - - for (;;) { - if (i < top) - return (i%mod == 0); - - mod = top; - top *= base; - } + int top = base; + int mod = 1; + + for (;;) { + if (i < top) + return (i%mod == 0); + + mod = top; + top *= base; + } } int -main (int argc, char **argv) +main (int argc, char **argv) { uint64_t bid = (((uint64_t)gethostid()) << 32) | getpid (); int set_bid = 0; uint64_t oid; - int setup = 0; + int setup = 0; int device = -1; - int npeers = 0; + int npeers = 0; int reps = 1; char hostname[128]; struct obdio_conn *conn; - struct obdio_barrier *b; - char *end; + struct obdio_barrier *b; + char *end; uint64_t val; int rc; int c; @@ -119,13 +119,13 @@ main (int argc, char **argv) memset (hostname, 0, sizeof (hostname)); gethostname (hostname, sizeof (hostname)); hostname[sizeof(hostname) - 1] = 0; - + while ((c = getopt (argc, argv, "hsi:d:n:p:")) != -1) switch (c) { case 'h': usage (argv[0], 1); return (0); - + case 'i': bid = strtoll (optarg, &end, 0); if (end == optarg || *end != 0) { @@ -135,11 +135,11 @@ main (int argc, char **argv) } set_bid = 1; break; - + case 's': - setup = 1; + setup = 1; break; - + case 'd': device = strtol (optarg, &end, 0); if (end == optarg || *end != 0 || device < 0) { @@ -160,7 +160,7 @@ main (int argc, char **argv) case 'p': npeers = strtol (optarg, &end, 0); - if (end == optarg || *end != 0 || npeers <= 0) { + if (end == optarg || *end != 0 || npeers <= 0) { fprintf (stderr, "Can't parse npeers %s\n", optarg); return (1); @@ -174,7 +174,7 @@ main (int argc, char **argv) if ((!setup && !set_bid) || npeers <= 0 || - device < 0 || + device < 0 || optind == argc) { fprintf (stderr, "%s not specified\n", (!setup && !set_bid) ? "id" : @@ -182,40 +182,40 @@ main (int argc, char **argv) device < 0 ? "device" : "object id"); return (1); } - + oid = strtoull (argv[optind], &end, 0); if (end == argv[optind] || *end != 0) { fprintf (stderr, "Can't parse object id %s\n", argv[optind]); return (1); } - + conn = obdio_connect (device); if (conn == NULL) return (1); - b = obdio_new_barrier (oid, bid, npeers); - if (b == NULL) - return (1); + b = obdio_new_barrier (oid, bid, npeers); + if (b == NULL) + return (1); rc = 0; - if (setup) { - rc = obdio_setup_barrier (conn, b); + if (setup) { + rc = obdio_setup_barrier (conn, b); if (rc == 0) printf ("Setup barrier: -d %d -i "LPX64" -p %d -n1 "LPX64"\n", device, bid, npeers, oid); - } else { - for (c = 0; c < reps; c++) { - rc = obdio_barrier (conn, b); - if (rc != 0) - break; - if (exponential_modulus (c, 10)) - printf ("%s: Barrier %d\n", hostname, c); - } - } - - free (b); - + } else { + for (c = 0; c < reps; c++) { + rc = obdio_barrier (conn, b); + if (rc != 0) + break; + if (exponential_modulus (c, 10)) + printf ("%s: Barrier %d\n", hostname, c); + } + } + + free (b); + obdio_disconnect (conn); return (rc == 0 ? 0 : 1); diff --git a/lustre/utils/obdio.c b/lustre/utils/obdio.c index 65a4cac..8264761 100644 --- a/lustre/utils/obdio.c +++ b/lustre/utils/obdio.c @@ -30,9 +30,9 @@ #include "obdiolib.h" int -obdio_test_fixed_extent (struct obdio_conn *conn, - uint32_t myhid, uint32_t mypid, - int reps, int locked, uint64_t oid, +obdio_test_fixed_extent (struct obdio_conn *conn, + uint32_t myhid, uint32_t mypid, + int reps, int locked, uint64_t oid, uint64_t offset, uint32_t size) { struct lustre_handle fh; @@ -44,7 +44,7 @@ obdio_test_fixed_extent (struct obdio_conn *conn, int j; int rc; int rc2; - + rc = obdio_open (conn, oid, &fh); if (rc != 0) { fprintf (stderr, "Failed to open object "LPX64": %s\n", @@ -58,7 +58,7 @@ obdio_test_fixed_extent (struct obdio_conn *conn, rc = -1; goto out_0; } - + for (i = 0; i < reps; i++) { ibuf = (uint32_t *) buffer; for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) { @@ -77,7 +77,7 @@ obdio_test_fixed_extent (struct obdio_conn *conn, goto out_1; } } - + rc = obdio_pwrite (conn, oid, buffer, size, offset); if (rc != 0) { fprintf (stderr, "Error writing "LPX64" @ "LPU64" for %u: %s\n", @@ -87,9 +87,9 @@ obdio_test_fixed_extent (struct obdio_conn *conn, rc = -1; goto out_1; } - + memset (buffer, 0xbb, size); - + rc = obdio_pread (conn, oid, buffer, size, offset); if (rc != 0) { fprintf (stderr, "Error reading "LPX64" @ "LPU64" for %u: %s\n", @@ -109,7 +109,7 @@ obdio_test_fixed_extent (struct obdio_conn *conn, goto out_1; } } - + ibuf = (uint32_t *) buffer; for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) { if (ibuf[0] != myhid || @@ -177,20 +177,20 @@ parse_kmg (uint64_t *valp, char *str) } void -usage (char *cmdname, int help) +usage (char *cmdname, int help) { char *name = strrchr (cmdname, '/'); - + if (name == NULL) name = cmdname; - + fprintf (help ? stdout : stderr, "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n", name); } int -main (int argc, char **argv) +main (int argc, char **argv) { uint32_t mypid = getpid (); uint32_t myhid = gethostid (); @@ -214,7 +214,7 @@ main (int argc, char **argv) case 'h': usage (argv[0], 1); return (0); - + case 'i': switch (sscanf (optarg, "%i.%i", &v1, &v2)) { case 1: @@ -230,7 +230,7 @@ main (int argc, char **argv) return (1); } break; - + case 's': if (parse_kmg (&val, optarg) != 0) { fprintf (stderr, "Can't parse size %s\n", @@ -240,7 +240,7 @@ main (int argc, char **argv) size = (uint32_t)val; set_size++; break; - + case 'o': if (parse_kmg (&val, optarg) != 0) { fprintf (stderr, "Can't parse offset %s\n", @@ -282,21 +282,21 @@ main (int argc, char **argv) device < 0 ? "device" : "object id"); return (1); } - + oid = strtoull (argv[optind], &end, 0); if (end == argv[optind] || *end != 0) { fprintf (stderr, "Can't parse object id %s\n", argv[optind]); return (1); } - + conn = obdio_connect (device); if (conn == NULL) return (1); - - rc = obdio_test_fixed_extent (conn, myhid, mypid, reps, locked, + + rc = obdio_test_fixed_extent (conn, myhid, mypid, reps, locked, oid, base_offset, size); - + obdio_disconnect (conn); return (rc == 0 ? 0 : 1); diff --git a/lustre/utils/obdiolib.c b/lustre/utils/obdiolib.c index 0404808..8c79c67 100644 --- a/lustre/utils/obdiolib.c +++ b/lustre/utils/obdiolib.c @@ -44,30 +44,30 @@ obdio_iocinit (struct obdio_conn *conn) } int -obdio_ioctl (struct obdio_conn *conn, int cmd) +obdio_ioctl (struct obdio_conn *conn, int cmd) { char *buf = conn->oc_buffer; int rc; int rc2; - + rc = obd_ioctl_pack (&conn->oc_data, &buf, sizeof (conn->oc_buffer)); if (rc != 0) { - fprintf (stderr, "obdio_ioctl: obd_ioctl_pack: %d (%s)\n", + fprintf (stderr, "obdio_ioctl: obd_ioctl_pack: %d (%s)\n", rc, strerror (errno)); abort (); } - + rc = ioctl (conn->oc_fd, cmd, buf); if (rc != 0) return (rc); - + rc2 = obd_ioctl_unpack (&conn->oc_data, buf, sizeof (conn->oc_buffer)); if (rc2 != 0) { fprintf (stderr, "obdio_ioctl: obd_ioctl_unpack: %d (%s)\n", rc2, strerror (errno)); abort (); } - + return (rc); } @@ -83,9 +83,9 @@ obdio_connect (int device) return (NULL); } memset (conn, 0, sizeof (*conn)); - - conn->oc_fd = open ("/dev/obd", O_RDWR); - if (conn->oc_fd < 0) { + + conn->oc_fd = open ("/dev/obd", O_RDWR); + if (conn->oc_fd < 0) { fprintf (stderr, "obdio_connect: Can't open /dev/obd: %s\n", strerror (errno)); goto failed; @@ -99,7 +99,7 @@ obdio_connect (int device) device, strerror (errno)); goto failed; } - + obdio_iocinit (conn); rc = obdio_ioctl (conn, OBD_IOC_CONNECT); if (rc != 0) { @@ -107,18 +107,18 @@ obdio_connect (int device) device, strerror (errno)); goto failed; } - + conn->oc_conn_addr = conn->oc_data.ioc_addr; conn->oc_conn_cookie = conn->oc_data.ioc_cookie; return (conn); - + failed: free (conn); return (NULL); } void -obdio_disconnect (struct obdio_conn *conn) +obdio_disconnect (struct obdio_conn *conn) { close (conn->oc_fd); /* obdclass will automatically close on last ref */ @@ -126,18 +126,18 @@ obdio_disconnect (struct obdio_conn *conn) } int -obdio_open (struct obdio_conn *conn, uint64_t oid, struct lustre_handle *fh) +obdio_open (struct obdio_conn *conn, uint64_t oid, struct lustre_handle *fh) { int rc; - + obdio_iocinit (conn); - + conn->oc_data.ioc_obdo1.o_id = oid; conn->oc_data.ioc_obdo1.o_mode = S_IFREG; conn->oc_data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; - + rc = obdio_ioctl (conn, OBD_IOC_OPEN); - + if (rc == 0) memcpy (fh, obdo_handle(&conn->oc_data.ioc_obdo1), sizeof (*fh)); @@ -145,26 +145,26 @@ obdio_open (struct obdio_conn *conn, uint64_t oid, struct lustre_handle *fh) } int -obdio_close (struct obdio_conn *conn, uint64_t oid, struct lustre_handle *fh) +obdio_close (struct obdio_conn *conn, uint64_t oid, struct lustre_handle *fh) { obdio_iocinit (conn); - + conn->oc_data.ioc_obdo1.o_id = oid; conn->oc_data.ioc_obdo1.o_mode = S_IFREG; memcpy (obdo_handle (&conn->oc_data.ioc_obdo1), fh, sizeof (*fh)); - conn->oc_data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | + conn->oc_data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLHANDLE; - + return (obdio_ioctl (conn, OBD_IOC_CLOSE)); } int -obdio_pread (struct obdio_conn *conn, uint64_t oid, - char *buffer, uint32_t count, uint64_t offset) +obdio_pread (struct obdio_conn *conn, uint64_t oid, + char *buffer, uint32_t count, uint64_t offset) { obdio_iocinit (conn); - + conn->oc_data.ioc_obdo1.o_id = oid; conn->oc_data.ioc_obdo1.o_mode = S_IFREG; conn->oc_data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; @@ -178,11 +178,11 @@ obdio_pread (struct obdio_conn *conn, uint64_t oid, } int -obdio_pwrite (struct obdio_conn *conn, uint64_t oid, - char *buffer, uint32_t count, uint64_t offset) +obdio_pwrite (struct obdio_conn *conn, uint64_t oid, + char *buffer, uint32_t count, uint64_t offset) { obdio_iocinit (conn); - + conn->oc_data.ioc_obdo1.o_id = oid; conn->oc_data.ioc_obdo1.o_mode = S_IFREG; conn->oc_data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; @@ -201,9 +201,9 @@ obdio_enqueue (struct obdio_conn *conn, uint64_t oid, struct lustre_handle *lh) { int rc; - + obdio_iocinit (conn); - + conn->oc_data.ioc_obdo1.o_id = oid; conn->oc_data.ioc_obdo1.o_mode = S_IFREG; conn->oc_data.ioc_obdo1.o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLMODE; @@ -211,12 +211,12 @@ obdio_enqueue (struct obdio_conn *conn, uint64_t oid, conn->oc_data.ioc_conn1 = mode; conn->oc_data.ioc_count = count; conn->oc_data.ioc_offset = offset; - + rc = obdio_ioctl (conn, ECHO_IOC_ENQUEUE); - + if (rc == 0) memcpy (lh, obdo_handle (&conn->oc_data.ioc_obdo1), sizeof (*lh)); - + return (rc); } @@ -227,40 +227,40 @@ obdio_cancel (struct obdio_conn *conn, struct lustre_handle *lh) memcpy (obdo_handle (&conn->oc_data.ioc_obdo1), lh, sizeof (*lh)); conn->oc_data.ioc_obdo1.o_valid = OBD_MD_FLHANDLE; - + return (obdio_ioctl (conn, ECHO_IOC_CANCEL)); } void * -obdio_alloc_aligned_buffer (void **spacep, int size) +obdio_alloc_aligned_buffer (void **spacep, int size) { int pagesize = getpagesize(); void *space = malloc (size + pagesize - 1); - + *spacep = space; if (space == NULL) return (NULL); - + return ((void *)(((unsigned long)space + pagesize - 1) & ~(pagesize - 1))); } struct obdio_barrier * -obdio_new_barrier (uint64_t oid, uint64_t id, int npeers) +obdio_new_barrier (uint64_t oid, uint64_t id, int npeers) { - struct obdio_barrier *b; - - b = (struct obdio_barrier *)malloc (sizeof (*b)); - if (b == NULL) { - fprintf (stderr, "obdio_new_barrier "LPX64": Can't allocate\n", oid); - return (NULL); - } - - b->ob_id = id; - b->ob_oid = oid; - b->ob_npeers = npeers; - b->ob_ordinal = 0; - b->ob_count = 0; - return (b); + struct obdio_barrier *b; + + b = (struct obdio_barrier *)malloc (sizeof (*b)); + if (b == NULL) { + fprintf (stderr, "obdio_new_barrier "LPX64": Can't allocate\n", oid); + return (NULL); + } + + b->ob_id = id; + b->ob_oid = oid; + b->ob_npeers = npeers; + b->ob_ordinal = 0; + b->ob_count = 0; + return (b); } int @@ -273,86 +273,86 @@ obdio_setup_barrier (struct obdio_conn *conn, struct obdio_barrier *b) void *space; struct obdio_barrier *fileb; - if (b->ob_ordinal != 0 || - b->ob_count != 0) { - fprintf (stderr, "obdio_setup_barrier: invalid parameter\n"); - abort (); - } - + if (b->ob_ordinal != 0 || + b->ob_count != 0) { + fprintf (stderr, "obdio_setup_barrier: invalid parameter\n"); + abort (); + } + rc = obdio_open (conn, b->ob_oid, &fh); if (rc != 0) { fprintf (stderr, "obdio_setup_barrier "LPX64": Failed to open object: %s\n", b->ob_oid, strerror (errno)); return (rc); } - + fileb = (struct obdio_barrier *) obdio_alloc_aligned_buffer (&space, getpagesize ()); if (fileb == NULL) { fprintf (stderr, "obdio_setup_barrier "LPX64": Can't allocate page buffer\n", - b->ob_oid); + b->ob_oid); rc = -1; goto out_0; } - + memset (fileb, 0, getpagesize ()); - *fileb = *b; - + *fileb = *b; + rc = obdio_enqueue (conn, b->ob_oid, LCK_PW, 0, getpagesize (), &lh); if (rc != 0) { fprintf (stderr, "obdio_setup_barrier "LPX64": Error on enqueue: %s\n", b->ob_oid, strerror (errno)); goto out_1; } - + rc = obdio_pwrite (conn, b->ob_oid, (void *)fileb, getpagesize (), 0); - if (rc != 0) - fprintf (stderr, "obdio_setup_barrier "LPX64": Error on write: %s\n", - b->ob_oid, strerror (errno)); - - rc2 = obdio_cancel (conn, &lh); - if (rc == 0 && rc2 != 0) { - fprintf (stderr, "obdio_setup_barrier "LPX64": Error on cancel: %s\n", - b->ob_oid, strerror (errno)); - rc = rc2; - } + if (rc != 0) + fprintf (stderr, "obdio_setup_barrier "LPX64": Error on write: %s\n", + b->ob_oid, strerror (errno)); + + rc2 = obdio_cancel (conn, &lh); + if (rc == 0 && rc2 != 0) { + fprintf (stderr, "obdio_setup_barrier "LPX64": Error on cancel: %s\n", + b->ob_oid, strerror (errno)); + rc = rc2; + } out_1: - free (space); + free (space); out_0: - rc2 = obdio_close (conn, b->ob_oid, &fh); - if (rc == 0 && rc2 != 0) { - fprintf (stderr, "obdio_setup_barrier "LPX64": Error on close: %s\n", - b->ob_oid, strerror (errno)); - rc = rc2; - } - - return (rc); + rc2 = obdio_close (conn, b->ob_oid, &fh); + if (rc == 0 && rc2 != 0) { + fprintf (stderr, "obdio_setup_barrier "LPX64": Error on close: %s\n", + b->ob_oid, strerror (errno)); + rc = rc2; + } + + return (rc); } int obdio_barrier (struct obdio_conn *conn, struct obdio_barrier *b) { struct lustre_handle fh; - struct lustre_handle lh; - int rc; - int rc2; + struct lustre_handle lh; + int rc; + int rc2; void *space; struct obdio_barrier *fileb; - char *mode; - - rc = obdio_open (conn, b->ob_oid, &fh); - if (rc != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on open: %s\n", - b->ob_oid, strerror (errno)); - return (rc); - } - + char *mode; + + rc = obdio_open (conn, b->ob_oid, &fh); + if (rc != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on open: %s\n", + b->ob_oid, strerror (errno)); + return (rc); + } + fileb = (struct obdio_barrier *) obdio_alloc_aligned_buffer (&space, getpagesize ()); - if (fileb == NULL) { - fprintf (stderr, "obdio_barrier "LPX64": Can't allocate page buffer\n", - b->ob_oid); - rc = -1; - goto out_0; - } + if (fileb == NULL) { + fprintf (stderr, "obdio_barrier "LPX64": Can't allocate page buffer\n", + b->ob_oid); + rc = -1; + goto out_0; + } rc = obdio_enqueue (conn, b->ob_oid, LCK_PW, 0, getpagesize (), &lh); if (rc != 0) { @@ -360,107 +360,107 @@ obdio_barrier (struct obdio_conn *conn, struct obdio_barrier *b) b->ob_oid, strerror (errno)); goto out_1; } - - memset (fileb, 0xeb, getpagesize ()); - rc = obdio_pread (conn, b->ob_oid, (void *)fileb, getpagesize (), 0); - if (rc != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on initial read: %s\n", - b->ob_oid, strerror (errno)); - goto out_2; - } - - if (fileb->ob_id != b->ob_id || - fileb->ob_oid != b->ob_oid || - fileb->ob_npeers != b->ob_npeers || - fileb->ob_count >= b->ob_npeers || - fileb->ob_ordinal != b->ob_ordinal) { - fprintf (stderr, "obdio_barrier "LPX64": corrupt on initial read\n", b->ob_id); - fprintf (stderr, " got ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", - fileb->ob_id, fileb->ob_oid, fileb->ob_npeers, - fileb->ob_ordinal, fileb->ob_count); - fprintf (stderr, " expected ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", - b->ob_id, b->ob_oid, b->ob_npeers, - b->ob_ordinal, b->ob_count); - rc = -1; - goto out_2; - } - - fileb->ob_count++; - if (fileb->ob_count == fileb->ob_npeers) { /* I'm the last joiner */ - fileb->ob_count = 0; /* join count for next barrier */ - fileb->ob_ordinal++; /* signal all joined */ - } - - rc = obdio_pwrite (conn, b->ob_oid, (void *)fileb, getpagesize (), 0); - if (rc != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on initial write: %s\n", - b->ob_oid, strerror (errno)); - goto out_2; - } - - mode = "PW"; - b->ob_ordinal++; /* now I wait... */ - while (fileb->ob_ordinal != b->ob_ordinal) { - - rc = obdio_cancel (conn, &lh); - if (rc != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on %s cancel: %s\n", - b->ob_oid, mode, strerror (errno)); - goto out_1; - } - - mode = "PR"; - rc = obdio_enqueue (conn, b->ob_oid, LCK_PR, 0, getpagesize (), &lh); - if (rc != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on PR enqueue: %s\n", - b->ob_oid, strerror (errno)); - goto out_1; - } - - memset (fileb, 0xeb, getpagesize ()); - rc = obdio_pread (conn, b->ob_oid, (void *)fileb, getpagesize (), 0); - if (rc != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on read: %s\n", - b->ob_oid, strerror (errno)); - goto out_2; - } - - if (fileb->ob_id != b->ob_id || - fileb->ob_oid != b->ob_oid || - fileb->ob_npeers != b->ob_npeers || - fileb->ob_count >= b->ob_npeers || - (fileb->ob_ordinal != b->ob_ordinal - 1 && - fileb->ob_ordinal != b->ob_ordinal)) { - fprintf (stderr, "obdio_barrier "LPX64": corrupt\n", b->ob_id); - fprintf (stderr, " got ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", - fileb->ob_id, fileb->ob_oid, fileb->ob_npeers, - fileb->ob_ordinal, fileb->ob_count); - fprintf (stderr, " expected ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", - b->ob_id, b->ob_oid, b->ob_npeers, - b->ob_ordinal, b->ob_count); - rc = -1; - goto out_2; - } - } - + + memset (fileb, 0xeb, getpagesize ()); + rc = obdio_pread (conn, b->ob_oid, (void *)fileb, getpagesize (), 0); + if (rc != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on initial read: %s\n", + b->ob_oid, strerror (errno)); + goto out_2; + } + + if (fileb->ob_id != b->ob_id || + fileb->ob_oid != b->ob_oid || + fileb->ob_npeers != b->ob_npeers || + fileb->ob_count >= b->ob_npeers || + fileb->ob_ordinal != b->ob_ordinal) { + fprintf (stderr, "obdio_barrier "LPX64": corrupt on initial read\n", b->ob_id); + fprintf (stderr, " got ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", + fileb->ob_id, fileb->ob_oid, fileb->ob_npeers, + fileb->ob_ordinal, fileb->ob_count); + fprintf (stderr, " expected ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", + b->ob_id, b->ob_oid, b->ob_npeers, + b->ob_ordinal, b->ob_count); + rc = -1; + goto out_2; + } + + fileb->ob_count++; + if (fileb->ob_count == fileb->ob_npeers) { /* I'm the last joiner */ + fileb->ob_count = 0; /* join count for next barrier */ + fileb->ob_ordinal++; /* signal all joined */ + } + + rc = obdio_pwrite (conn, b->ob_oid, (void *)fileb, getpagesize (), 0); + if (rc != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on initial write: %s\n", + b->ob_oid, strerror (errno)); + goto out_2; + } + + mode = "PW"; + b->ob_ordinal++; /* now I wait... */ + while (fileb->ob_ordinal != b->ob_ordinal) { + + rc = obdio_cancel (conn, &lh); + if (rc != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on %s cancel: %s\n", + b->ob_oid, mode, strerror (errno)); + goto out_1; + } + + mode = "PR"; + rc = obdio_enqueue (conn, b->ob_oid, LCK_PR, 0, getpagesize (), &lh); + if (rc != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on PR enqueue: %s\n", + b->ob_oid, strerror (errno)); + goto out_1; + } + + memset (fileb, 0xeb, getpagesize ()); + rc = obdio_pread (conn, b->ob_oid, (void *)fileb, getpagesize (), 0); + if (rc != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on read: %s\n", + b->ob_oid, strerror (errno)); + goto out_2; + } + + if (fileb->ob_id != b->ob_id || + fileb->ob_oid != b->ob_oid || + fileb->ob_npeers != b->ob_npeers || + fileb->ob_count >= b->ob_npeers || + (fileb->ob_ordinal != b->ob_ordinal - 1 && + fileb->ob_ordinal != b->ob_ordinal)) { + fprintf (stderr, "obdio_barrier "LPX64": corrupt\n", b->ob_id); + fprintf (stderr, " got ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", + fileb->ob_id, fileb->ob_oid, fileb->ob_npeers, + fileb->ob_ordinal, fileb->ob_count); + fprintf (stderr, " expected ["LPX64","LPX64","LPX64","LPX64","LPX64"]\n", + b->ob_id, b->ob_oid, b->ob_npeers, + b->ob_ordinal, b->ob_count); + rc = -1; + goto out_2; + } + } + out_2: - rc2 = obdio_cancel (conn, &lh); - if (rc == 0 && rc2 != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on cancel: %s\n", - b->ob_oid, strerror (errno)); - rc = rc2; - } + rc2 = obdio_cancel (conn, &lh); + if (rc == 0 && rc2 != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on cancel: %s\n", + b->ob_oid, strerror (errno)); + rc = rc2; + } out_1: - free (space); + free (space); out_0: - rc2 = obdio_close (conn, b->ob_oid, &fh); - if (rc == 0 && rc2 != 0) { - fprintf (stderr, "obdio_barrier "LPX64": Error on close: %s\n", - b->ob_oid, strerror (errno)); - rc = rc2; - } - - return (rc); + rc2 = obdio_close (conn, b->ob_oid, &fh); + if (rc == 0 && rc2 != 0) { + fprintf (stderr, "obdio_barrier "LPX64": Error on close: %s\n", + b->ob_oid, strerror (errno)); + rc = rc2; + } + + return (rc); } - + -- 1.8.3.1