X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Fobdio.c;h=c7b33f3b084246bed339f6f498541773cef843ab;hb=1b2547843817b4b7adbeb87ea9b070d9cac35c90;hp=65a4cac0fd4f6f426119a0a27e390903bd92f0cb;hpb=040033cef24c5aca2967daf2da7a862abcd074cf;p=fs%2Flustre-release.git diff --git a/lustre/utils/obdio.c b/lustre/utils/obdio.c index 65a4cac..c7b33f3 100644 --- a/lustre/utils/obdio.c +++ b/lustre/utils/obdio.c @@ -1,24 +1,39 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: +/* + * GPL HEADER START * - * Copyright (C) 2002 Cluster File Systems, Inc. - * Author: Eric Barton + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * This file is part of Lustre, http://www.lustre.org. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). * - * Lustre is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. * + * GPL HEADER END + */ +/* + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * lustre/utils/obdio.c + * + * Author: Eric Barton */ #include @@ -30,37 +45,27 @@ #include "obdiolib.h" int -obdio_test_fixed_extent (struct obdio_conn *conn, - uint32_t myhid, uint32_t mypid, - int reps, int locked, uint64_t oid, - uint64_t offset, uint32_t size) +obdio_test_fixed_extent (struct obdio_conn *conn, + __u32 myhid, __u32 mypid, + int reps, int locked, __u64 oid, + __u64 offset, __u32 size) { - struct lustre_handle fh; struct lustre_handle lh; void *space; void *buffer; - uint32_t *ibuf; + __u32 *ibuf; int i; int j; - int rc; - int rc2; - - rc = obdio_open (conn, oid, &fh); - if (rc != 0) { - fprintf (stderr, "Failed to open object "LPX64": %s\n", - oid, strerror (errno)); - return (rc); - } + int rc = 0; - buffer = obdio_alloc_aligned_buffer (&space, size); - if (buffer == NULL) { + space = obdio_alloc_aligned_buffer (&buffer, size); + if (space == NULL) { fprintf (stderr, "Can't allocate buffer size %d\n", size); - rc = -1; - goto out_0; + return (-1); } - + for (i = 0; i < reps; i++) { - ibuf = (uint32_t *) buffer; + ibuf = (__u32 *) buffer; for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) { ibuf[0] = myhid; ibuf[1] = mypid; @@ -70,76 +75,78 @@ obdio_test_fixed_extent (struct obdio_conn *conn, } if (locked) { - rc = obdio_enqueue (conn, oid, LCK_PW, offset, size, &lh); + rc = obdio_enqueue(conn, oid, LCK_PW, offset, size,&lh); if (rc != 0) { - fprintf (stderr, "Error on enqueue "LPX64" @ "LPU64" for %u: %s\n", - oid, offset, size, strerror (errno)); - goto out_1; + fprintf(stderr, "Error on enqueue "LPX64" @ " + LPU64" for %u: %s\n", + oid, offset, size, strerror (errno)); + goto out; } } - + rc = obdio_pwrite (conn, oid, buffer, size, offset); if (rc != 0) { - fprintf (stderr, "Error writing "LPX64" @ "LPU64" for %u: %s\n", - oid, offset, size, strerror (errno)); + fprintf(stderr, "Error writing "LPX64" @ "LPU64 + " for %u: %s\n", + oid, offset, size, strerror (errno)); if (locked) obdio_cancel (conn, &lh); rc = -1; - goto out_1; + goto out; } - + memset (buffer, 0xbb, size); - + rc = obdio_pread (conn, oid, buffer, size, offset); if (rc != 0) { - fprintf (stderr, "Error reading "LPX64" @ "LPU64" for %u: %s\n", - oid, offset, size, strerror (errno)); + fprintf(stderr, "Error reading "LPX64" @ "LPU64 + " for %u: %s\n", + oid, offset, size, strerror (errno)); if (locked) obdio_cancel (conn, &lh); rc = -1; - goto out_1; + goto out; } if (locked) { rc = obdio_cancel (conn, &lh); if (rc != 0) { - fprintf (stderr, "Error on cancel "LPX64" @ "LPU64" for %u: %s\n", - oid, offset, size, strerror (errno)); + fprintf(stderr, "Error on cancel "LPX64" @ " + LPU64" for %u: %s\n", + oid, offset, size, strerror (errno)); rc = -1; - goto out_1; + goto out; } } - - ibuf = (uint32_t *) buffer; + + ibuf = (__u32 *) buffer; for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) { if (ibuf[0] != myhid || ibuf[1] != mypid || ibuf[2] != i || ibuf[3] != j) { - fprintf (stderr, "Error checking "LPX64" @ "LPU64" for %u, chunk %d\n", - oid, offset, size, j); - fprintf (stderr, "Expected [%x,%x,%x,%x], got [%x,%x,%x,%x]\n", - myhid, mypid, i, j, ibuf[0], ibuf[1], ibuf[2], ibuf[3]); + fprintf(stderr, "Error checking "LPX64" @ " + LPU64" for %u, chunk %d\n", + oid, offset, size, j); + fprintf(stderr, "Expected [%x,%x,%x,%x], " + "got [%x,%x,%x,%x]\n", + myhid, mypid, i, j, + ibuf[0], ibuf[1], ibuf[2], ibuf[3]); rc = -1; - goto out_1; + goto out; } ibuf += 4; } } - out_1: + out: free (space); - out_0: - rc2 = obdio_close (conn, oid, &fh); - if (rc2 != 0) - fprintf (stderr, "Error closing object "LPX64": %s\n", - oid, strerror (errno)); return (rc); } int -parse_kmg (uint64_t *valp, char *str) +parse_kmg (__u64 *valp, char *str) { - uint64_t val; + __u64 val; char mod[32]; switch (sscanf (str, LPU64"%1[gGmMkK]", &val, mod)) @@ -177,33 +184,33 @@ parse_kmg (uint64_t *valp, char *str) } void -usage (char *cmdname, int help) +usage (char *cmdname, int help) { char *name = strrchr (cmdname, '/'); - + if (name == NULL) name = cmdname; - + fprintf (help ? stdout : stderr, "usage: %s -d device -s size -o offset [-i id][-n reps][-l] oid\n", name); } int -main (int argc, char **argv) +main (int argc, char **argv) { - uint32_t mypid = getpid (); - uint32_t myhid = gethostid (); - uint64_t oid; - uint64_t base_offset = 0; - uint32_t size = 0; + __u32 mypid = getpid (); + __u32 myhid = gethostid (); + __u64 oid; + __u64 base_offset = 0; + __u32 size = 0; int set_size = 0; int device = -1; int reps = 1; int locked = 0; char *end; struct obdio_conn *conn; - uint64_t val; + __u64 val; int v1; int v2; int rc; @@ -214,7 +221,7 @@ main (int argc, char **argv) case 'h': usage (argv[0], 1); return (0); - + case 'i': switch (sscanf (optarg, "%i.%i", &v1, &v2)) { case 1: @@ -230,17 +237,17 @@ main (int argc, char **argv) return (1); } break; - + case 's': if (parse_kmg (&val, optarg) != 0) { fprintf (stderr, "Can't parse size %s\n", optarg); return (1); } - size = (uint32_t)val; + size = (__u32)val; set_size++; break; - + case 'o': if (parse_kmg (&val, optarg) != 0) { fprintf (stderr, "Can't parse offset %s\n", @@ -282,24 +289,22 @@ main (int argc, char **argv) device < 0 ? "device" : "object id"); return (1); } - + oid = strtoull (argv[optind], &end, 0); if (end == argv[optind] || *end != 0) { fprintf (stderr, "Can't parse object id %s\n", argv[optind]); return (1); } - + conn = obdio_connect (device); if (conn == NULL) return (1); - - rc = obdio_test_fixed_extent (conn, myhid, mypid, reps, locked, - oid, base_offset, size); - - obdio_disconnect (conn); - return (rc == 0 ? 0 : 1); -} + rc = obdio_test_fixed_extent(conn, myhid, mypid, reps, locked, + oid, base_offset, size); + obdio_disconnect(conn, 0); + return (rc == 0 ? 0 : 1); +}