4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/utils/obdbarrier.c
36 * Author: Eric Barton <eeb@clusterfs.com>
44 #include <liblustre.h>
48 parse_kmg (__u64 *valp, char *str)
53 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
88 usage (char *cmdname, int help)
90 char *name = strrchr (cmdname, '/');
95 fprintf (help ? stdout : stderr,
96 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
101 exponential_modulus (int i, int base)
116 main (int argc, char **argv)
118 __u64 bid = (((__u64)gethostid()) << 32) | getpid ();
126 struct obdio_conn *conn;
127 struct obdio_barrier *b;
133 setvbuf (stdout, NULL, _IOLBF, 0);
134 memset (hostname, 0, sizeof (hostname));
135 gethostname (hostname, sizeof (hostname));
136 hostname[sizeof(hostname) - 1] = 0;
138 while ((c = getopt (argc, argv, "hsi:d:n:p:")) != -1)
145 bid = strtoll (optarg, &end, 0);
146 if (end == optarg || *end != 0) {
147 fprintf (stderr, "Can't parse id %s\n",
159 device = strtol (optarg, &end, 0);
160 if (end == optarg || *end != 0 || device < 0) {
161 fprintf (stderr, "Can't parse device %s\n",
168 if (parse_kmg (&val, optarg) != 0) {
169 fprintf (stderr, "Can't parse reps %s\n",
177 npeers = strtol (optarg, &end, 0);
178 if (end == optarg || *end != 0 || npeers <= 0) {
179 fprintf (stderr, "Can't parse npeers %s\n",
190 if ((!setup && !set_bid) ||
194 fprintf (stderr, "%s not specified\n",
195 (!setup && !set_bid) ? "id" :
196 npeers <= 0 ? "npeers" :
197 device < 0 ? "device" : "object id");
201 oid = strtoull (argv[optind], &end, 0);
202 if (end == argv[optind] || *end != 0) {
203 fprintf (stderr, "Can't parse object id %s\n",
208 conn = obdio_connect (device);
212 b = obdio_new_barrier (oid, bid, npeers);
218 rc = obdio_setup_barrier (conn, b);
220 printf ("Setup barrier: -d %d -i "LPX64" -p %d -n1 "LPX64"\n",
221 device, bid, npeers, oid);
223 for (c = 0; c < reps; c++) {
224 rc = obdio_barrier (conn, b);
227 if (exponential_modulus (c, 10))
228 printf ("%s: Barrier %d\n", hostname, c);
234 obdio_disconnect(conn, 0);
236 return (rc == 0 ? 0 : 1);