1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/utils/obdbarrier.c
38 * Author: Eric Barton <eeb@clusterfs.com>
46 #include <liblustre.h>
50 parse_kmg (__u64 *valp, char *str)
55 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
90 usage (char *cmdname, int help)
92 char *name = strrchr (cmdname, '/');
97 fprintf (help ? stdout : stderr,
98 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
103 exponential_modulus (int i, int base)
118 main (int argc, char **argv)
120 __u64 bid = (((__u64)gethostid()) << 32) | getpid ();
128 struct obdio_conn *conn;
129 struct obdio_barrier *b;
135 setvbuf (stdout, NULL, _IOLBF, 0);
136 memset (hostname, 0, sizeof (hostname));
137 gethostname (hostname, sizeof (hostname));
138 hostname[sizeof(hostname) - 1] = 0;
140 while ((c = getopt (argc, argv, "hsi:d:n:p:")) != -1)
147 bid = strtoll (optarg, &end, 0);
148 if (end == optarg || *end != 0) {
149 fprintf (stderr, "Can't parse id %s\n",
161 device = strtol (optarg, &end, 0);
162 if (end == optarg || *end != 0 || device < 0) {
163 fprintf (stderr, "Can't parse device %s\n",
170 if (parse_kmg (&val, optarg) != 0) {
171 fprintf (stderr, "Can't parse reps %s\n",
179 npeers = strtol (optarg, &end, 0);
180 if (end == optarg || *end != 0 || npeers <= 0) {
181 fprintf (stderr, "Can't parse npeers %s\n",
192 if ((!setup && !set_bid) ||
196 fprintf (stderr, "%s not specified\n",
197 (!setup && !set_bid) ? "id" :
198 npeers <= 0 ? "npeers" :
199 device < 0 ? "device" : "object id");
203 oid = strtoull (argv[optind], &end, 0);
204 if (end == argv[optind] || *end != 0) {
205 fprintf (stderr, "Can't parse object id %s\n",
210 conn = obdio_connect (device);
214 b = obdio_new_barrier (oid, bid, npeers);
220 rc = obdio_setup_barrier (conn, b);
222 printf ("Setup barrier: -d %d -i "LPX64" -p %d -n1 "LPX64"\n",
223 device, bid, npeers, oid);
225 for (c = 0; c < reps; c++) {
226 rc = obdio_barrier (conn, b);
229 if (exponential_modulus (c, 10))
230 printf ("%s: Barrier %d\n", hostname, c);
236 obdio_disconnect(conn, 0);
238 return (rc == 0 ? 0 : 1);