xfstests: randholes: encapsulate direct I/O setup code
authorAlex Elder <aelder@sgi.com>
Thu, 14 Oct 2010 14:50:27 +0000 (14:50 +0000)
committerAlex Elder <aelder@sgi.com>
Tue, 19 Oct 2010 15:05:11 +0000 (10:05 -0500)
Pull the code used to get alignment information for direct I/O into
a separate function.

Signed-off-by: Alex Elder <aelder@sgi.com>
Acked-by: Dave Chinner <david@fromorbit.com>
src/randholes.c

index 45e234592169037d886abd612035780ba71bcdd4..b4c3470a2461ec4a3848332c79fbe7f0aaa6ccc3 100644 (file)
@@ -270,6 +270,22 @@ readblks(int fd)
         return err;
 }
 
+int
+direct_setup(char *filename, int fd)
+{
+       if (xfscntl(filename, fd, DIOINFO, &diob) < 0) {
+               perror("xfscntl(FIOINFO)");
+               return 1;
+       }
+       if (blocksize % diob.d_miniosz) {
+               fprintf(stderr, "blocksize %d must be a multiple of "
+                       "%d for direct I/O\n", blocksize, diob.d_miniosz);
+               return 1;
+       }
+
+       return 0;
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -374,19 +390,9 @@ main(int argc, char *argv[])
                }
        }
 
-       if (direct) {
-               if (xfscntl(filename, fd, DIOINFO, &diob) < 0) {
-                       perror("xfscntl(FIOINFO)");
-                       return 1;
-               }
-               if (blocksize % diob.d_miniosz) {
-                       fprintf(stderr,
-                               "blocksize %d must be a multiple of %d for direct I/O\n",
-                               blocksize,
-                               diob.d_miniosz);
-                       return 1;
-               }
-       }
+       if (direct && direct_setup(filename, fd))
+               return 1;
+
         printf(test?"write (skipped)\n":"write\n");
        writeblks(filename, fd);
         printf("readback\n");