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.
32 obdio_test_fixed_extent (struct obdio_conn *conn,
33 uint32_t myhid, uint32_t mypid,
34 int reps, int locked, uint64_t oid,
35 uint64_t offset, uint32_t size)
37 struct lustre_handle fh;
38 struct lustre_handle lh;
47 rc = obdio_open (conn, oid, &fh);
49 fprintf (stderr, "Failed to open object "LPX64": %s\n",
50 oid, strerror (errno));
54 buffer = obdio_alloc_aligned_buffer (&space, size);
56 fprintf (stderr, "Can't allocate buffer size %d\n", size);
61 for (i = 0; i < reps; i++) {
62 ibuf = (uint32_t *) buffer;
63 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
72 rc = obdio_enqueue (conn, oid, LCK_PW, offset, size, &lh);
74 fprintf (stderr, "Error on enqueue "LPX64" @ "LPU64" for %u: %s\n",
75 oid, offset, size, strerror (errno));
80 rc = obdio_pwrite (conn, oid, buffer, size, offset);
82 fprintf (stderr, "Error writing "LPX64" @ "LPU64" for %u: %s\n",
83 oid, offset, size, strerror (errno));
85 obdio_cancel (conn, &lh);
90 memset (buffer, 0xbb, size);
92 rc = obdio_pread (conn, oid, buffer, size, offset);
94 fprintf (stderr, "Error reading "LPX64" @ "LPU64" for %u: %s\n",
95 oid, offset, size, strerror (errno));
97 obdio_cancel (conn, &lh);
103 rc = obdio_cancel (conn, &lh);
105 fprintf (stderr, "Error on cancel "LPX64" @ "LPU64" for %u: %s\n",
106 oid, offset, size, strerror (errno));
112 ibuf = (uint32_t *) buffer;
113 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
114 if (ibuf[0] != myhid ||
118 fprintf (stderr, "Error checking "LPX64" @ "LPU64" for %u, chunk %d\n",
119 oid, offset, size, j);
120 fprintf (stderr, "Expected [%x,%x,%x,%x], got [%x,%x,%x,%x]\n",
121 myhid, mypid, i, j, ibuf[0], ibuf[1], ibuf[2], ibuf[3]);
131 rc2 = obdio_close (conn, oid, &fh);
133 fprintf (stderr, "Error closing object "LPX64": %s\n",
134 oid, strerror (errno));
139 parse_kmg (uint64_t *valp, char *str)
144 switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod))
179 usage (char *cmdname, int help)
181 char *name = strrchr (cmdname, '/');
186 fprintf (help ? stdout : stderr,
187 "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n",
192 main (int argc, char **argv)
194 uint32_t mypid = getpid ();
195 uint32_t myhid = gethostid ();
197 uint64_t base_offset = 0;
204 struct obdio_conn *conn;
211 while ((c = getopt (argc, argv, "hi:s:o:d:n:l")) != -1)
218 switch (sscanf (optarg, "%i.%i", &v1, &v2)) {
227 fprintf (stderr, "Can't parse id %s\n",
234 if (parse_kmg (&val, optarg) != 0) {
235 fprintf (stderr, "Can't parse size %s\n",
239 size = (uint32_t)val;
244 if (parse_kmg (&val, optarg) != 0) {
245 fprintf (stderr, "Can't parse offset %s\n",
253 device = strtol (optarg, &end, 0);
254 if (end == optarg || *end != 0 || device < 0) {
255 fprintf (stderr, "Can't parse device %s\n",
261 if (parse_kmg (&val, optarg) != 0) {
262 fprintf (stderr, "Can't parse reps %s\n",
279 fprintf (stderr, "No %s specified\n",
281 device < 0 ? "device" : "object id");
285 oid = strtoull (argv[optind], &end, 0);
286 if (end == argv[optind] || *end != 0) {
287 fprintf (stderr, "Can't parse object id %s\n",
292 conn = obdio_connect (device);
296 rc = obdio_test_fixed_extent (conn, myhid, mypid, reps, locked,
297 oid, base_offset, size);
299 obdio_disconnect (conn);
301 return (rc == 0 ? 0 : 1);