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/obdio.c
38 * Author: Eric Barton <eeb@clusterfs.com>
46 #include <liblustre.h>
50 obdio_test_fixed_extent (struct obdio_conn *conn,
51 __u32 myhid, __u32 mypid,
52 int reps, int locked, __u64 oid,
53 __u64 offset, __u32 size)
55 struct lustre_handle lh;
63 space = obdio_alloc_aligned_buffer (&buffer, size);
65 fprintf (stderr, "Can't allocate buffer size %d\n", size);
69 for (i = 0; i < reps; i++) {
70 ibuf = (__u32 *) buffer;
71 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
80 rc = obdio_enqueue(conn, oid, LCK_PW, offset, size,&lh);
82 fprintf(stderr, "Error on enqueue "LPX64" @ "
84 oid, offset, size, strerror (errno));
89 rc = obdio_pwrite (conn, oid, buffer, size, offset);
91 fprintf(stderr, "Error writing "LPX64" @ "LPU64
93 oid, offset, size, strerror (errno));
95 obdio_cancel (conn, &lh);
100 memset (buffer, 0xbb, size);
102 rc = obdio_pread (conn, oid, buffer, size, offset);
104 fprintf(stderr, "Error reading "LPX64" @ "LPU64
106 oid, offset, size, strerror (errno));
108 obdio_cancel (conn, &lh);
114 rc = obdio_cancel (conn, &lh);
116 fprintf(stderr, "Error on cancel "LPX64" @ "
117 LPU64" for %u: %s\n",
118 oid, offset, size, strerror (errno));
124 ibuf = (__u32 *) buffer;
125 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
126 if (ibuf[0] != myhid ||
130 fprintf(stderr, "Error checking "LPX64" @ "
131 LPU64" for %u, chunk %d\n",
132 oid, offset, size, j);
133 fprintf(stderr, "Expected [%x,%x,%x,%x], "
134 "got [%x,%x,%x,%x]\n",
136 ibuf[0], ibuf[1], ibuf[2], ibuf[3]);
149 parse_kmg (__u64 *valp, char *str)
154 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
189 usage (char *cmdname, int help)
191 char *name = strrchr (cmdname, '/');
196 fprintf (help ? stdout : stderr,
197 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
202 main (int argc, char **argv)
204 __u32 mypid = getpid ();
205 __u32 myhid = gethostid ();
207 __u64 base_offset = 0;
214 struct obdio_conn *conn;
221 while ((c = getopt (argc, argv, "hi:s:o:d:n:l")) != -1)
228 switch (sscanf (optarg, "%i.%i", &v1, &v2)) {
237 fprintf (stderr, "Can't parse id %s\n",
244 if (parse_kmg (&val, optarg) != 0) {
245 fprintf (stderr, "Can't parse size %s\n",
254 if (parse_kmg (&val, optarg) != 0) {
255 fprintf (stderr, "Can't parse offset %s\n",
263 device = strtol (optarg, &end, 0);
264 if (end == optarg || *end != 0 || device < 0) {
265 fprintf (stderr, "Can't parse device %s\n",
271 if (parse_kmg (&val, optarg) != 0) {
272 fprintf (stderr, "Can't parse reps %s\n",
289 fprintf (stderr, "No %s specified\n",
291 device < 0 ? "device" : "object id");
295 oid = strtoull (argv[optind], &end, 0);
296 if (end == argv[optind] || *end != 0) {
297 fprintf (stderr, "Can't parse object id %s\n",
302 conn = obdio_connect (device);
306 rc = obdio_test_fixed_extent(conn, myhid, mypid, reps, locked,
307 oid, base_offset, size);
309 obdio_disconnect(conn, 0);
311 return (rc == 0 ? 0 : 1);