1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 #
  26 
  27 
  28 # LOCK nfsv4 C program assertions
  29 
  30 Note: cache invalidation is by means similar to those used in
  31   Cthon - lock suite.
  32 
  33 Lock Scenarios:
  34 The following test scenario is run with (exhaustive) combinations of
  35  parameters obtained from the following sets:
  36 Warning: I still need to adjust the expected values according to
  37  parameters oflags and mode.
  38 
  39 Values shown are for:
  40 
  41 mode={0600 0400 0200 000)
  42 oflags={O_EXCL|O_RDWR  O_RDWR  O_WRONLY  O_RDONLY}
  43 
  44 Scenario A)
  45  prep) All done by the parent (before spawning a child)
  46   - open file1 (fd_i) with mode 600 and oflags O_CREAT|O_TRUNC|O_RDWR
  47   - using fd_i, write a test message
  48   - link file1 to file2 (hard link)
  49 
  50  Assertions:
  51  a) Parent open file1 (get fd1) with provided parameters oflag and mode.
  52   Expect OK when mode=0600, {mode, oflags}={0400, O_RDONLY} |
  53    {0200, O_WRONLY}. Else expect EACCES.
  54  b) Parent opens (fd2) file2 (hard link) with same parameters used in file1.
  55   Expect same results as with file1
  56   If operation successful, then forks a child,
  57   else finish this scenario (no fds available to continue).
  58  c) fcntl F_SETLK-F_RDLCK on fd2 in parent (whole file), expect OK when
  59   file is read enabled, else EBADF,  then wait for child next step
  60  d) child fcntl F_SETLK-F_RDLCK fd1 (whole file) and verifies if it can
  61   write & read using fds 1 & 2. Expect fcntl results as in assertion (c).
  62   READ Expect OK when: mode = 0600 & oflags != O_WRONLY,
  63    mode = 0400 & oflags = O_RDONLY. Else, expect EBADF
  64   WRITE Expect OK when: mode = 0600 & oflags != O_RDONLY,
  65    mode = 0200 & oflags = O_WRONLY. Else, expect EBADF
  66  e) parent tries fcntl F_SETLK-F_WRLCK first 1K of file on fds 1 & 2,
  67   wait for child next step. Expect EAGAIN on both fds, except when file is
  68   O_RDONLY when it should be EBADF.
  69  f) child tries fcntl F_SETLK-F_UNLCK first 1K of file on fds 1 & 2,
  70   Expect OK on fd1 and fd2 (no previous lock).
  71  g) parent tries fcntl F_SETLK-F_WRLCK first 1K of file on fds 1 & 2,
  72   Expect OK on both fds.
  73  h) parent tries read and write on fds 1 & 2. then waits for child tasks.
  74   READ Expect OK when: mode = 0600 & oflags != O_WRONLY,
  75    mode = 0400 & oflags = O_RDONLY. Else, expect EBADF
  76   WRITE Expect OK when: mode = 0600 & oflags != O_RDONLY,
  77    mode = 0200 & oflags = O_WRONLY. Else, expect EBADF
  78  i) child tries fcntl F_SETLK-F_RDLCK first 1K on both fds. Expected EAGAIN
  79   except when file was O_WRONLY when it should be EBADF.
  80  j) child tries fcntl F_SETLK-F_WRLCK first 1K on both fds. Expected EAGAIN.
  81  k) child tries fcntl F_SETLK-F_WRLCK from 1K+1 to 2k 1K on both fds.
  82   Expected EAGAIN.
  83  l) parent tries fcntl F_SETLK-F_UNLCK from 1K+1 to EOF and wait for child
  84   Expected OK.
  85  m) child tries fcntl F_SETLK-F_RDLCK from 1K+1 to 2k on both fds. Expected
  86 OK.
  87  n) child tries fcntl F_SETLK-F_WRLCK from 1K+1 to 2k on both fds. Expected
  88 OK.
  89  o) parent tries fcntl F_SETLK-F_RDLCK first 1K of file on fds 1 & 2,
  90   wait for child. Expect OK on both fds.
  91  p) child tries fcntl F_SETLK-F_WRLCK whole file on both fds. Expected
  92 EAGAIN.
  93  q) child tries fcntl F_SETLK-F_RDLCK whole file on both fds. Expected OK.
  94  r) parent tries fcntl F_SETLK-F_UNLCK whole file on fds 1 & 2,
  95   wait for child. Expect OK on both fds.
  96  s) child tries fcntl F_SETLK-F_WRLCK whole file on both fds. Expected OK.
  97  t) parent tries fcntl F_SETLK-F_WRLCK whole file on fds 1 & 2,
  98   expect EAGAIN on both fds. Then kills child.
  99  u) parent tries fcntl F_SETLK-F_WRLCK whole file on fds 1 & 2,
 100   expect OK on both fds. Then closes fds, expected OK.
 101  v) parent opens file1 and file2, then tries fcntl F_SETLK-F_WRLCK whole
 102 file
 103   on fds 1 & 2, expect OK on both fds. tries fcntl F_SETLK-F_UNLCK whole
 104   file on fds 1 & 2, expect OK on both fds. Finally, close fds 1 & 2,
 105   expects OK on both fds.
 106 
 107  clean) - close fd_i
 108   - unlink file1 and file2
 109 
 110 Note 1) all writes and reads are preceded by lseek to offset 0, unless
 111  specified
 112 Note 2) if environment var SYNCWRITE is defined, writes are followed
 113  by fsync() and invalidating the cache and a read on fd_i to compare
 114  data on server. And reads are preceded by invalidating the cache
 115  to force read from server.
 116 
 117 Scenario B) is same as A), but with child changing UID and GID before
 118  tests start.
 119 
 120   replace step (v) in scenario A with:
 121  v) child opens a file3 (different from file1) same mode and oflags as
 122   file1 and tries fcntl F_SETLK-F_RDLCK whole file. Expected OK.
 123  w) parent opens same file, same permissions and tries fcntl
 124   F_SETLK-F_WRLCK whole
 125 
 126   file, expected EAGAIN. Then tries fcntl F_SETLK-F_RDLCK whole file,
 127   expected OK. Then waits for child.
 128  x) child tries fcntl F_SETLK-F_WRLCK whole file, expected EAGAIN.
 129  y) parent tries fcntl F_SETLK-F_UNLCK whole file, expected OK. Wait
 130   for child.
 131  z) child tries fcntl F_SETLK-F_WRLCK whole file, expected OK. Sleep
 132   for long time.
 133  t) parent kills child, then tries fcntl F_SETLK-F_WRLCK whole file,
 134   expect OK. Then closes fd, expected OK.
 135  v) parent opens file3, then tries fcntl F_SETLK-F_WRLCK whole file,
 136   expect OK. Then, tries fcntl F_SETLK-F_UNLCK whole file, expect OK.
 137   Then closes fd, expected OK.
 138 
 139  clean) - close fd_i
 140   - unlink file1, file2 and file3
 141 
 142 Note 1) all writes and reads are preceded by lseek to offset 0, unless
 143  specified
 144 Note 2) if environment var SYNCWRITE is defined, writes are followed
 145  by fsync() and invalidating the cache and a read on fd_i to compare
 146  data on server. And reads are preceded by invalidating the cache
 147  to force read from server.
 148 
 149 Scenario C) Process A opens a file and forks process B, using mode 600.
 150         Files are have flags O_CREAT|O_TRUNC|O_RDWR. N is a big number
 151  say 10000.
 152  a) child tries fcntl F_SETLK-F_RDLCK whole file, then fcntl
 153   F_SETLK-F_UNLCK whole file for N times then waits. Expect OK.
 154  b) concurrently to step (a) parent close and reopens the file N times,
 155   then tries fcntl F_SETLK-F_RDLCK whole file and waits. Expect OK.
 156  c) parent tries fcntl F_SETLK-F_WRLCK whole file, expect OK and waits
 157  d) child tries fcntl F_SETLK-F_RDLCK whole file, expect EBADF and wait
 158  e) parent tries fcntl F_SETLK-F_RDLCK whole file, then
 159   tries fcntl F_SETLK-F_UNLCK whole file, then
 160   tries fcntl F_SETLK-F_RDLCK whole file,
 161   looping unlocking relocking file N times and waits expect OK
 162  f) child tries fcntl F_SETLK-F_RDLCK whole file, then
 163   tries fcntl F_SETLK-F_UNLCK whole file, then
 164   tries fcntl F_SETLK-F_RDLCK whole file,
 165   looping unlocking relocking file N times and waits expect OK
 166  g) parent tries fcntl F_SETLK-F_UNLCK whole file, expect OK and waits
 167  h) child tries fcntl F_SETLK-F_WRLCK whole file, expect OK and sleeps
 168   3 minutes
 169  i) parent tries fcntl F_SETLK-F_RDLCK whole file, expect EBADF and waits
 170  j) child tries fcntl F_SETLK-F_UNLCK whole file, then waits. Expect OK.
 171  k) parent kills child, then tries fcntl F_SETLK-F_WRLCK whole file,
 172   expect OK.
 173 
 174  clean) - close fd
 175   - unlink file
 176 
 177 Note 1) all writes and reads are preceded by lseek to offset 0, unless
 178  specified
 179 Note 2) if environment var SYNCWRITE is defined, writes are followed
 180  by fsync() and invalidating the cache and a read on fd_i to compare
 181  data on server. And reads are preceded by invalidating the cache
 182  to force read from server.