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/obdio.c
36 * Author: Eric Barton <eeb@clusterfs.com>
44 #include <liblustre.h>
48 obdio_test_fixed_extent (struct obdio_conn *conn,
49 __u32 myhid, __u32 mypid,
50 int reps, int locked, __u64 oid,
51 __u64 offset, __u32 size)
53 struct lustre_handle lh;
61 space = obdio_alloc_aligned_buffer (&buffer, size);
63 fprintf (stderr, "Can't allocate buffer size %d\n", size);
67 for (i = 0; i < reps; i++) {
68 ibuf = (__u32 *) buffer;
69 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
78 rc = obdio_enqueue(conn, oid, LCK_PW, offset, size,&lh);
80 fprintf(stderr, "Error on enqueue "LPX64" @ "
82 oid, offset, size, strerror (errno));
87 rc = obdio_pwrite (conn, oid, buffer, size, offset);
89 fprintf(stderr, "Error writing "LPX64" @ "LPU64
91 oid, offset, size, strerror (errno));
93 obdio_cancel (conn, &lh);
98 memset (buffer, 0xbb, size);
100 rc = obdio_pread (conn, oid, buffer, size, offset);
102 fprintf(stderr, "Error reading "LPX64" @ "LPU64
104 oid, offset, size, strerror (errno));
106 obdio_cancel (conn, &lh);
112 rc = obdio_cancel (conn, &lh);
114 fprintf(stderr, "Error on cancel "LPX64" @ "
115 LPU64" for %u: %s\n",
116 oid, offset, size, strerror (errno));
122 ibuf = (__u32 *) buffer;
123 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
124 if (ibuf[0] != myhid ||
128 fprintf(stderr, "Error checking "LPX64" @ "
129 LPU64" for %u, chunk %d\n",
130 oid, offset, size, j);
131 fprintf(stderr, "Expected [%x,%x,%x,%x], "
132 "got [%x,%x,%x,%x]\n",
134 ibuf[0], ibuf[1], ibuf[2], ibuf[3]);
147 parse_kmg (__u64 *valp, char *str)
152 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
187 usage (char *cmdname, int help)
189 char *name = strrchr (cmdname, '/');
194 fprintf (help ? stdout : stderr,
195 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
200 main (int argc, char **argv)
202 __u32 mypid = getpid ();
203 __u32 myhid = gethostid ();
205 __u64 base_offset = 0;
212 struct obdio_conn *conn;
219 while ((c = getopt (argc, argv, "hi:s:o:d:n:l")) != -1)
226 switch (sscanf (optarg, "%i.%i", &v1, &v2)) {
235 fprintf (stderr, "Can't parse id %s\n",
242 if (parse_kmg (&val, optarg) != 0) {
243 fprintf (stderr, "Can't parse size %s\n",
252 if (parse_kmg (&val, optarg) != 0) {
253 fprintf (stderr, "Can't parse offset %s\n",
261 device = strtol (optarg, &end, 0);
262 if (end == optarg || *end != 0 || device < 0) {
263 fprintf (stderr, "Can't parse device %s\n",
269 if (parse_kmg (&val, optarg) != 0) {
270 fprintf (stderr, "Can't parse reps %s\n",
287 fprintf (stderr, "No %s specified\n",
289 device < 0 ? "device" : "object id");
293 oid = strtoull (argv[optind], &end, 0);
294 if (end == argv[optind] || *end != 0) {
295 fprintf (stderr, "Can't parse object id %s\n",
300 conn = obdio_connect (device);
304 rc = obdio_test_fixed_extent(conn, myhid, mypid, reps, locked,
305 oid, base_offset, size);
307 obdio_disconnect(conn, 0);
309 return (rc == 0 ? 0 : 1);