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.
29 #include <liblustre.h>
33 parse_kmg (uint64_t *valp, char *str)
38 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
73 usage (char *cmdname, int help)
75 char *name = strrchr (cmdname, '/');
80 fprintf (help ? stdout : stderr,
81 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
86 exponential_modulus (int i, int base)
101 main (int argc, char **argv)
103 uint64_t bid = (((uint64_t)gethostid()) << 32) | getpid ();
111 struct obdio_conn *conn;
112 struct obdio_barrier *b;
118 setvbuf (stdout, NULL, _IOLBF, 0);
119 memset (hostname, 0, sizeof (hostname));
120 gethostname (hostname, sizeof (hostname));
121 hostname[sizeof(hostname) - 1] = 0;
123 while ((c = getopt (argc, argv, "hsi:d:n:p:")) != -1)
130 bid = strtoll (optarg, &end, 0);
131 if (end == optarg || *end != 0) {
132 fprintf (stderr, "Can't parse id %s\n",
144 device = strtol (optarg, &end, 0);
145 if (end == optarg || *end != 0 || device < 0) {
146 fprintf (stderr, "Can't parse device %s\n",
153 if (parse_kmg (&val, optarg) != 0) {
154 fprintf (stderr, "Can't parse reps %s\n",
162 npeers = strtol (optarg, &end, 0);
163 if (end == optarg || *end != 0 || npeers <= 0) {
164 fprintf (stderr, "Can't parse npeers %s\n",
175 if ((!setup && !set_bid) ||
179 fprintf (stderr, "%s not specified\n",
180 (!setup && !set_bid) ? "id" :
181 npeers <= 0 ? "npeers" :
182 device < 0 ? "device" : "object id");
186 oid = strtoull (argv[optind], &end, 0);
187 if (end == argv[optind] || *end != 0) {
188 fprintf (stderr, "Can't parse object id %s\n",
193 conn = obdio_connect (device);
197 b = obdio_new_barrier (oid, bid, npeers);
203 rc = obdio_setup_barrier (conn, b);
205 printf ("Setup barrier: -d %d -i "LPX64" -p %d -n1 "LPX64"\n",
206 device, bid, npeers, oid);
208 for (c = 0; c < reps; c++) {
209 rc = obdio_barrier (conn, b);
212 if (exponential_modulus (c, 10))
213 printf ("%s: Barrier %d\n", hostname, c);
219 obdio_disconnect(conn, 0);
221 return (rc == 0 ? 0 : 1);