1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
5 * Author: Eric Barton <eeb@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 parse_kmg (uint64_t *valp, char *str)
37 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
72 usage (char *cmdname, int help)
74 char *name = strrchr (cmdname, '/');
79 fprintf (help ? stdout : stderr,
80 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
85 exponential_modulus (int i, int base)
100 main (int argc, char **argv)
102 uint64_t bid = (((uint64_t)gethostid()) << 32) | getpid ();
110 struct obdio_conn *conn;
111 struct obdio_barrier *b;
117 setvbuf (stdout, NULL, _IOLBF, 0);
118 memset (hostname, 0, sizeof (hostname));
119 gethostname (hostname, sizeof (hostname));
120 hostname[sizeof(hostname) - 1] = 0;
122 while ((c = getopt (argc, argv, "hsi:d:n:p:")) != -1)
129 bid = strtoll (optarg, &end, 0);
130 if (end == optarg || *end != 0) {
131 fprintf (stderr, "Can't parse id %s\n",
143 device = strtol (optarg, &end, 0);
144 if (end == optarg || *end != 0 || device < 0) {
145 fprintf (stderr, "Can't parse device %s\n",
152 if (parse_kmg (&val, optarg) != 0) {
153 fprintf (stderr, "Can't parse reps %s\n",
161 npeers = strtol (optarg, &end, 0);
162 if (end == optarg || *end != 0 || npeers <= 0) {
163 fprintf (stderr, "Can't parse npeers %s\n",
174 if ((!setup && !set_bid) ||
178 fprintf (stderr, "%s not specified\n",
179 (!setup && !set_bid) ? "id" :
180 npeers <= 0 ? "npeers" :
181 device < 0 ? "device" : "object id");
185 oid = strtoull (argv[optind], &end, 0);
186 if (end == argv[optind] || *end != 0) {
187 fprintf (stderr, "Can't parse object id %s\n",
192 conn = obdio_connect (device);
196 b = obdio_new_barrier (oid, bid, npeers);
202 rc = obdio_setup_barrier (conn, b);
204 printf ("Setup barrier: -d %d -i "LPX64" -p %d -n1 "LPX64"\n",
205 device, bid, npeers, oid);
207 for (c = 0; c < reps; c++) {
208 rc = obdio_barrier (conn, b);
211 if (exponential_modulus (c, 10))
212 printf ("%s: Barrier %d\n", hostname, c);
218 obdio_disconnect (conn);
220 return (rc == 0 ? 0 : 1);