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 fh;
39 struct lustre_handle lh;
48 rc = obdio_open (conn, oid, &fh);
50 fprintf (stderr, "Failed to open object "LPX64": %s\n",
51 oid, strerror (errno));
55 buffer = obdio_alloc_aligned_buffer (&space, size);
57 fprintf (stderr, "Can't allocate buffer size %d\n", size);
62 for (i = 0; i < reps; i++) {
63 ibuf = (uint32_t *) buffer;
64 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
73 rc = obdio_enqueue (conn, oid, LCK_PW, offset, size, &lh);
75 fprintf (stderr, "Error on enqueue "LPX64" @ "LPU64" for %u: %s\n",
76 oid, offset, size, strerror (errno));
81 rc = obdio_pwrite (conn, oid, buffer, size, offset);
83 fprintf (stderr, "Error writing "LPX64" @ "LPU64" for %u: %s\n",
84 oid, offset, size, strerror (errno));
86 obdio_cancel (conn, &lh);
91 memset (buffer, 0xbb, size);
93 rc = obdio_pread (conn, oid, buffer, size, offset);
95 fprintf (stderr, "Error reading "LPX64" @ "LPU64" for %u: %s\n",
96 oid, offset, size, strerror (errno));
98 obdio_cancel (conn, &lh);
104 rc = obdio_cancel (conn, &lh);
106 fprintf (stderr, "Error on cancel "LPX64" @ "LPU64" for %u: %s\n",
107 oid, offset, size, strerror (errno));
113 ibuf = (uint32_t *) buffer;
114 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
115 if (ibuf[0] != myhid ||
119 fprintf (stderr, "Error checking "LPX64" @ "LPU64" for %u, chunk %d\n",
120 oid, offset, size, j);
121 fprintf (stderr, "Expected [%x,%x,%x,%x], got [%x,%x,%x,%x]\n",
122 myhid, mypid, i, j, ibuf[0], ibuf[1], ibuf[2], ibuf[3]);
132 rc2 = obdio_close (conn, oid, &fh);
134 fprintf (stderr, "Error closing object "LPX64": %s\n",
135 oid, strerror (errno));
140 parse_kmg (uint64_t *valp, char *str)
145 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
180 usage (char *cmdname, int help)
182 char *name = strrchr (cmdname, '/');
187 fprintf (help ? stdout : stderr,
188 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
193 main (int argc, char **argv)
195 uint32_t mypid = getpid ();
196 uint32_t myhid = gethostid ();
198 uint64_t base_offset = 0;
205 struct obdio_conn *conn;
212 while ((c = getopt (argc, argv, "hi:s:o:d:n:l")) != -1)
219 switch (sscanf (optarg, "%i.%i", &v1, &v2)) {
228 fprintf (stderr, "Can't parse id %s\n",
235 if (parse_kmg (&val, optarg) != 0) {
236 fprintf (stderr, "Can't parse size %s\n",
240 size = (uint32_t)val;
245 if (parse_kmg (&val, optarg) != 0) {
246 fprintf (stderr, "Can't parse offset %s\n",
254 device = strtol (optarg, &end, 0);
255 if (end == optarg || *end != 0 || device < 0) {
256 fprintf (stderr, "Can't parse device %s\n",
262 if (parse_kmg (&val, optarg) != 0) {
263 fprintf (stderr, "Can't parse reps %s\n",
280 fprintf (stderr, "No %s specified\n",
282 device < 0 ? "device" : "object id");
286 oid = strtoull (argv[optind], &end, 0);
287 if (end == argv[optind] || *end != 0) {
288 fprintf (stderr, "Can't parse object id %s\n",
293 conn = obdio_connect (device);
297 rc = obdio_test_fixed_extent (conn, myhid, mypid, reps, locked,
298 oid, base_offset, size);
300 obdio_disconnect (conn);
302 return (rc == 0 ? 0 : 1);