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 obdio_test_fixed_extent (struct obdio_conn *conn,
34 uint32_t myhid, uint32_t mypid,
35 int reps, int locked, uint64_t oid,
36 uint64_t offset, uint32_t size)
38 struct lustre_handle lh;
46 buffer = obdio_alloc_aligned_buffer (&space, size);
48 fprintf (stderr, "Can't allocate buffer size %d\n", size);
52 for (i = 0; i < reps; i++) {
53 ibuf = (uint32_t *) buffer;
54 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
63 rc = obdio_enqueue(conn, oid, LCK_PW, offset, size,&lh);
65 fprintf(stderr, "Error on enqueue "LPX64" @ "
67 oid, offset, size, strerror (errno));
72 rc = obdio_pwrite (conn, oid, buffer, size, offset);
74 fprintf(stderr, "Error writing "LPX64" @ "LPU64
76 oid, offset, size, strerror (errno));
78 obdio_cancel (conn, &lh);
83 memset (buffer, 0xbb, size);
85 rc = obdio_pread (conn, oid, buffer, size, offset);
87 fprintf(stderr, "Error reading "LPX64" @ "LPU64
89 oid, offset, size, strerror (errno));
91 obdio_cancel (conn, &lh);
97 rc = obdio_cancel (conn, &lh);
99 fprintf(stderr, "Error on cancel "LPX64" @ "
100 LPU64" for %u: %s\n",
101 oid, offset, size, strerror (errno));
107 ibuf = (uint32_t *) buffer;
108 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
109 if (ibuf[0] != myhid ||
113 fprintf(stderr, "Error checking "LPX64" @ "
114 LPU64" for %u, chunk %d\n",
115 oid, offset, size, j);
116 fprintf(stderr, "Expected [%x,%x,%x,%x], "
117 "got [%x,%x,%x,%x]\n",
119 ibuf[0], ibuf[1], ibuf[2], ibuf[3]);
132 parse_kmg (uint64_t *valp, char *str)
137 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
172 usage (char *cmdname, int help)
174 char *name = strrchr (cmdname, '/');
179 fprintf (help ? stdout : stderr,
180 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
185 main (int argc, char **argv)
187 uint32_t mypid = getpid ();
188 uint32_t myhid = gethostid ();
190 uint64_t base_offset = 0;
197 struct obdio_conn *conn;
204 while ((c = getopt (argc, argv, "hi:s:o:d:n:l")) != -1)
211 switch (sscanf (optarg, "%i.%i", &v1, &v2)) {
220 fprintf (stderr, "Can't parse id %s\n",
227 if (parse_kmg (&val, optarg) != 0) {
228 fprintf (stderr, "Can't parse size %s\n",
232 size = (uint32_t)val;
237 if (parse_kmg (&val, optarg) != 0) {
238 fprintf (stderr, "Can't parse offset %s\n",
246 device = strtol (optarg, &end, 0);
247 if (end == optarg || *end != 0 || device < 0) {
248 fprintf (stderr, "Can't parse device %s\n",
254 if (parse_kmg (&val, optarg) != 0) {
255 fprintf (stderr, "Can't parse reps %s\n",
272 fprintf (stderr, "No %s specified\n",
274 device < 0 ? "device" : "object id");
278 oid = strtoull (argv[optind], &end, 0);
279 if (end == argv[optind] || *end != 0) {
280 fprintf (stderr, "Can't parse object id %s\n",
285 conn = obdio_connect (device);
289 rc = obdio_test_fixed_extent(conn, myhid, mypid, reps, locked,
290 oid, base_offset, size);
292 obdio_disconnect(conn, 0);
294 return (rc == 0 ? 0 : 1);