Whamcloud - gitweb
- fixed typo in lconf LMV:clanup_module()
[fs/lustre-release.git] / lustre / utils / obdio.c
index 65a4cac..f10dff3 100644 (file)
 #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, 
+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)
 {
-        struct lustre_handle fh;
         struct lustre_handle lh;
         void                *space;
         void                *buffer;
         uint32_t            *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) {
                 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;
                 for (j = 0; j < size / (4 * sizeof (*ibuf)); j++) {
@@ -70,69 +60,71 @@ 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;
                 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);
 }
 
@@ -177,20 +169,20 @@ 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 ();
@@ -214,7 +206,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,7 +222,7 @@ main (int argc, char **argv)
                                 return (1);
                         }
                         break;
-                        
+
                 case 's':
                         if (parse_kmg (&val, optarg) != 0) {
                                 fprintf (stderr, "Can't parse size %s\n",
@@ -240,7 +232,7 @@ main (int argc, char **argv)
                         size = (uint32_t)val;
                         set_size++;
                         break;
-                        
+
                 case 'o':
                         if (parse_kmg (&val, optarg) != 0) {
                                 fprintf (stderr, "Can't parse offset %s\n",
@@ -282,22 +274,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);
+
+        rc = obdio_test_fixed_extent(conn, myhid, mypid, reps, locked,
+                                     oid, base_offset, size);
+
+        obdio_disconnect(conn, 0);
 
         return (rc == 0 ? 0 : 1);
 }