locktest: don't assume that F_OPEN should use O_RDWR
authorJeff Layton <jlayton@poochiereds.net>
Tue, 13 May 2014 05:30:18 +0000 (15:30 +1000)
committerDave Chinner <david@fromorbit.com>
Tue, 13 May 2014 05:30:18 +0000 (15:30 +1000)
In a later patch, I'll be adding a test for F_GETLK that will require
that we open the file with a different f_mode. Change do_open not to
assume that the it needs to open the file O_RDWR.

While we're at it, fix a bug in do_open. Just because we pass in '0' for
the flags, doesn't mean that this is the initial open.  Move the exit(1)
for that case to the caller.

Signed-off-by: Jeff Layton <jlayton@poochiereds.net>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
src/locktest.c

index d6198b6c1f1b4c37f080d766426a10fa5a203225..b440a43e39475f6c773194f339d7add9f136a799 100644 (file)
@@ -73,7 +73,7 @@ extern int h_errno;
        
 #define HANDLE              int
 #define INVALID_HANDLE      -1
        
 #define HANDLE              int
 #define INVALID_HANDLE      -1
-#define OPEN(N,F)           (open(N, F|O_CREAT|O_RDWR|O_BINARY| \
+#define OPEN(N,F)           (open(N, F|O_CREAT|O_BINARY| \
                             (D_flag ? O_DIRECT : 0), 0644))
 #define SEEK(H, O)          (lseek(H, O, SEEK_SET))
 #define READ(H, B, L)       (read(H, B, L))
                             (D_flag ? O_DIRECT : 0), 0644))
 #define SEEK(H, O)          (lseek(H, O, SEEK_SET))
 #define READ(H, B, L)       (read(H, B, L))
@@ -512,35 +512,35 @@ static int64_t tests[][6] =
                {27,    WRLOCK, 1,              5,              FAIL,           CLIENT, },
                {27,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {27,    WRLOCK, 1,              5,              PASS,           CLIENT, },
                {27,    WRLOCK, 1,              5,              FAIL,           CLIENT, },
                {27,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {27,    WRLOCK, 1,              5,              PASS,           CLIENT, },
-               {27,    F_OPEN, 0,              0,              PASS,           SERVER, },
+               {27,    F_OPEN, O_RDWR,         0,              PASS,           SERVER, },
                {27,    UNLOCK, 1,              5,              PASS,           CLIENT, },
        /* Acquire two read locks, close one file and then reopen to check that first lock still exists */
                {28,    RDLOCK, 1,              5,              PASS,           SERVER, },
                {28,    RDLOCK, 1,              5,              PASS,           CLIENT, },
                {28,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {27,    UNLOCK, 1,              5,              PASS,           CLIENT, },
        /* Acquire two read locks, close one file and then reopen to check that first lock still exists */
                {28,    RDLOCK, 1,              5,              PASS,           SERVER, },
                {28,    RDLOCK, 1,              5,              PASS,           CLIENT, },
                {28,    F_CLOSE,0,              0,              PASS,           SERVER, },
-               {28,    F_OPEN, 0,              0,              PASS,           SERVER, },
+               {28,    F_OPEN, O_RDWR,         0,              PASS,           SERVER, },
                {28,    WRLOCK, 0,              0,              FAIL,           SERVER, },
                {28,    UNLOCK, 1,              5,              PASS,           SERVER, },
 #ifdef macosx
        /* Close the opened file and open the file with SHLOCK, other client will try to open with SHLOCK too */
                {29,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {28,    WRLOCK, 0,              0,              FAIL,           SERVER, },
                {28,    UNLOCK, 1,              5,              PASS,           SERVER, },
 #ifdef macosx
        /* Close the opened file and open the file with SHLOCK, other client will try to open with SHLOCK too */
                {29,    F_CLOSE,0,              0,              PASS,           SERVER, },
-               {29,    F_OPEN, O_SHLOCK|O_NONBLOCK,    0,      PASS,           SERVER, },
+               {29,    F_OPEN, O_RDWR|O_SHLOCK|O_NONBLOCK,     0,      PASS,           SERVER, },
                {29,    F_CLOSE,0,              0,              PASS,           CLIENT, },
                {29,    F_CLOSE,0,              0,              PASS,           CLIENT, },
-               {29,    F_OPEN, O_SHLOCK|O_NONBLOCK,    0,      PASS,           CLIENT, },
+               {29,    F_OPEN, O_RDWR|O_SHLOCK|O_NONBLOCK,     0,      PASS,           CLIENT, },
        /* Close the opened file and open the file with SHLOCK, other client will try to open with EXLOCK */
                {30,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {30,    F_CLOSE,0,              0,              PASS,           CLIENT, },
        /* Close the opened file and open the file with SHLOCK, other client will try to open with EXLOCK */
                {30,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {30,    F_CLOSE,0,              0,              PASS,           CLIENT, },
-               {30,    F_OPEN, O_SHLOCK|O_NONBLOCK,    0,      PASS,           SERVER, },
-               {30,    F_OPEN, O_EXLOCK|O_NONBLOCK,    0,      FAIL,           CLIENT, },
+               {30,    F_OPEN, O_RDWR|O_SHLOCK|O_NONBLOCK,     0,      PASS,           SERVER, },
+               {30,    F_OPEN, O_RDWR|O_EXLOCK|O_NONBLOCK,     0,      FAIL,           CLIENT, },
        /* Close the opened file and open the file with EXLOCK, other client will try to open with EXLOCK too */
                {31,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {31,    F_CLOSE,0,              0,              FAIL,           CLIENT, },
        /* Close the opened file and open the file with EXLOCK, other client will try to open with EXLOCK too */
                {31,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {31,    F_CLOSE,0,              0,              FAIL,           CLIENT, },
-               {31,    F_OPEN, O_EXLOCK|O_NONBLOCK,    0,      PASS,           SERVER, },
-               {31,    F_OPEN, O_EXLOCK|O_NONBLOCK,    0,      FAIL,           CLIENT, },
+               {31,    F_OPEN, O_RDWR|O_EXLOCK|O_NONBLOCK,     0,      PASS,           SERVER, },
+               {31,    F_OPEN, O_RDWR|O_EXLOCK|O_NONBLOCK,     0,      FAIL,           CLIENT, },
                {31,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {31,    F_CLOSE,0,              0,              FAIL,           CLIENT, },
                {31,    F_CLOSE,0,              0,              PASS,           SERVER, },
                {31,    F_CLOSE,0,              0,              FAIL,           CLIENT, },
-               {31,    F_OPEN, 0,              0,              PASS,           SERVER, },
-               {31,    F_OPEN, 0,              0,              PASS,           CLIENT, },
+               {31,    F_OPEN, O_RDWR,         0,              PASS,           SERVER, },
+               {31,    F_OPEN, O_RDWR,         0,              PASS,           CLIENT, },
 #endif /* macosx */
        /* indicate end of array */
                {0,0,0,0,0,SERVER},
 #endif /* macosx */
        /* indicate end of array */
                {0,0,0,0,0,SERVER},
@@ -615,8 +615,6 @@ int do_open(int flag)
 {
     if ((f_fd = OPEN(filename, flag)) == INVALID_HANDLE) {
        perror("shared file create");
 {
     if ((f_fd = OPEN(filename, flag)) == INVALID_HANDLE) {
        perror("shared file create");
-       if (!flag)      /* Only exit if the first open fails */
-           exit(1);
        closed = 0;
        return FAIL;
        /*NOTREACHED*/
        closed = 0;
        return FAIL;
        /*NOTREACHED*/
@@ -858,7 +856,8 @@ main(int argc, char *argv[])
     }
 
     filename=argv[optind];
     }
 
     filename=argv[optind];
-    do_open(0);
+    if (do_open(O_RDWR) == FAIL)
+       exit(1);
 
     /*
      * +10 is slop for the iteration number if do_write() ... never
 
     /*
      * +10 is slop for the iteration number if do_write() ... never