Debian Codegraph @

test/nfstest_delegation

raw
1 #!/usr/bin/env python3
2 #===============================================================================
3 # Copyright 2012 NetApp, Inc. All Rights Reserved,
4 # contribution by Jorge Mora <[email protected]>
5 #
6 # This program is free software; you can redistribute it and/or modify it under
7 # the terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 #===============================================================================
15 import os
16 import time
17 import errno
18 import fcntl
19 import struct
20 import traceback
21 import nfstest_config as c
22 from packet.nfs.nfs3_const import *
23 from packet.nfs.nfs4_const import *
24 from nfstest.test_util import TestUtil
25
26 # Module constants
27 __author__ = "Jorge Mora (%s)" % c.NFSTEST_AUTHOR_EMAIL
28 __copyright__ = "Copyright (C) 2012 NetApp, Inc."
29 __license__ = "GPL v2"
30 __version__ = "1.9"
31
32 USAGE = """%prog --server <server> [--client <client>] [options]
33
34 Delegation tests
35 ================
36 Basic delegation tests verify that a correct delegation is granted when
37 opening a file for reading or writing. Also, another OPEN should not be
38 sent for the same file when the client is holding a delegation. Verify
39 that the stateid of all I/O operations should be the delegation stateid.
40 Reads from a different process on the same file should not cause the client
41 to send additional READ packets when the client is holding a read delegation.
42 Furthermore, a LOCK packet should not be sent to the server when the client
43 is holding a delegation.
44
45 Recall delegation tests verify the delegation is recalled when a conflicting
46 operation is sent to the server from a different client. Conflicting operations
47 are reading, writing, removing, renaming and changing the permissions on the
48 same file. Note that reading a file from a different client can only recall
49 a write delegation. Removing the delegated file from a different client
50 recalls the delegation and the server may or may not allow any more writes
51 from the client after the delegation has been returned. Renaming either the
52 delegated file (as source) or into the delegated file (as target) recalls
53 the delegation. In the case where the delegated file is the target of rename,
54 the existing target is removed before the rename occurs, therefore the server
55 may or may not allow nay more writes from the client after the delegation has
56 been removed just like in the case when removing the delegated file.
57
58 Also, verify that a read delegation is not recalled when a different client is
59 granted a read delegation. After a delegation is recalled, the client may send
60 an OPEN with CLAIM_DELEGATE_CUR before returning the delegation specially when
61 there is a open pending on the client. In addition, the stateid returned by the
62 new open should be the same as the original OPEN stateid. Also, a delegation
63 should not be granted when re-opening the file before returning the delegation.
64 The client may flush all written data before returning the WRITE delegation.
65 The LOCK should be sent as well before returning a delegation which has been
66 recalled. Finally, a delegation should not be granted on the second client who
67 cause the delegation recall on the first client.
68
69 Examples:
70 Run the basic delegation tests (no client option):
71 %prog --server 192.168.0.2 --export /exports
72
73 Use short options instead:
74 %prog -s 192.168.0.2 -e /exports
75
76 Run both the basic and recall tests using positional arguments with
77 nfsversion=3 for the second client:
78 %prog -s 192.168.0.2 -e /exports --client 192.168.0.10:::3
79
80 Use named arguments instead:
81 %prog -s 192.168.0.2 -e /exports --client 192.168.0.10:nfsversion=3
82
83 Notes:
84 The user id in the local host and the host specified by --client must
85 have access to run commands as root using the 'sudo' command without
86 the need for a password.
87
88 The user id must be able to 'ssh' to remote host without the need for
89 a password."""
90
91 # Test script ID
92 SCRIPT_ID = "DELEGATION"
93
94 # Test group flags
95 GROUP_BASIC = (1 << 0) # Basic tests
96 GROUP_RECALL = (1 << 1) # Recall tests
97 GROUP_RDELEG = (1 << 2) # Read delegation tests
98 GROUP_WDELEG = (1 << 3) # Write delegation tests
99 GROUP_IOREAD = (1 << 4) # Tests with READ open
100 GROUP_IOWRTE = (1 << 5) # Tests with WRITE open
101 GROUP_IORWRD = (1 << 6) # Tests with RDWR open while reading
102 GROUP_IORWWR = (1 << 7) # Tests with RDWR open while writing
103 GROUP_STAT = (1 << 8) # Tests with file stat before open
104 GROUP_LOCK = (1 << 9) # Tests with file lock after open
105 GROUP_CTREAD = (1 << 10) # Recall tests with conflicting READ
106 GROUP_CTWRTE = (1 << 11) # Recall tests with conflicting WRITE
107 GROUP_SETATTR = (1 << 12) # Recall tests by SETATTR
108 GROUP_REMOVE = (1 << 13) # Recall tests by removing the file
109 GROUP_RENAME = (1 << 14) # Recall tests by renaming the file
110 GROUP_PENDING = (1 << 15) # Recall tests having a pending open
111 GROUP_TARGET = (1 << 16) # Recall tests by renaming into the file
112
113 TESTNAMES_ALL = [
114 ( "basic01", GROUP_BASIC|GROUP_RDELEG|GROUP_IOREAD ),
115 ( "basic02", GROUP_BASIC|GROUP_WDELEG|GROUP_IOWRTE ),
116 ( "basic03", GROUP_BASIC|GROUP_RDELEG|GROUP_IOREAD|GROUP_STAT ),
117 ( "basic04", GROUP_BASIC|GROUP_WDELEG|GROUP_IOWRTE|GROUP_STAT ),
118 ( "basic05", GROUP_BASIC|GROUP_RDELEG|GROUP_IOREAD|GROUP_LOCK ),
119 ( "basic06", GROUP_BASIC|GROUP_WDELEG|GROUP_IOWRTE|GROUP_LOCK ),
120 ( "basic07", GROUP_BASIC|GROUP_WDELEG|GROUP_IORWRD ),
121 ( "basic08", GROUP_BASIC|GROUP_WDELEG|GROUP_IORWWR ),
122 ( "basic09", GROUP_BASIC|GROUP_WDELEG|GROUP_IORWRD|GROUP_STAT ),
123 ( "basic10", GROUP_BASIC|GROUP_WDELEG|GROUP_IORWWR|GROUP_STAT ),
124 ( "basic11", GROUP_BASIC|GROUP_WDELEG|GROUP_IORWRD|GROUP_LOCK ),
125 ( "basic12", GROUP_BASIC|GROUP_WDELEG|GROUP_IORWWR|GROUP_LOCK ),
126 ( "recall01", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_CTWRTE ),
127 ( "recall02", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_CTWRTE ),
128 ( "recall03", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_CTWRTE ),
129 ( "recall04", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_CTWRTE ),
130 ( "recall05", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_CTREAD ),
131 ( "recall06", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_CTREAD ),
132 ( "recall07", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_SETATTR ),
133 ( "recall08", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_SETATTR ),
134 ( "recall09", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_SETATTR ),
135 ( "recall10", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_SETATTR ),
136 ( "recall11", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_REMOVE ),
137 ( "recall12", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_REMOVE ),
138 ( "recall13", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_REMOVE ),
139 ( "recall14", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_REMOVE ),
140 ( "recall15", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_RENAME ),
141 ( "recall16", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_RENAME ),
142 ( "recall17", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_RENAME ),
143 ( "recall18", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_RENAME ),
144 ( "recall19", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_RENAME|GROUP_TARGET ),
145 ( "recall20", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_RENAME|GROUP_TARGET ),
146 ( "recall21", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_RENAME|GROUP_TARGET ),
147 ( "recall22", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_RENAME|GROUP_TARGET ),
148 ( "recall23", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_CTWRTE|GROUP_PENDING ),
149 ( "recall24", GROUP_RECALL|GROUP_RDELEG|GROUP_IOREAD|GROUP_CTWRTE|GROUP_PENDING ),
150 ( "recall25", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_CTWRTE|GROUP_PENDING ),
151 ( "recall26", GROUP_RECALL|GROUP_WDELEG|GROUP_IOWRTE|GROUP_CTWRTE|GROUP_PENDING ),
152 ( "recall27", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_CTREAD ),
153 ( "recall28", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_CTREAD ),
154 ( "recall29", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_CTWRTE ),
155 ( "recall30", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_CTWRTE ),
156 ( "recall31", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_CTREAD ),
157 ( "recall32", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_CTREAD ),
158 ( "recall33", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_CTWRTE ),
159 ( "recall34", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_CTWRTE ),
160 ( "recall35", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_SETATTR ),
161 ( "recall36", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_SETATTR ),
162 ( "recall37", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_SETATTR ),
163 ( "recall38", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_SETATTR ),
164 ( "recall39", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_REMOVE ),
165 ( "recall40", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_REMOVE ),
166 ( "recall41", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_REMOVE ),
167 ( "recall42", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_REMOVE ),
168 ( "recall43", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_RENAME ),
169 ( "recall44", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_RENAME ),
170 ( "recall45", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_RENAME ),
171 ( "recall46", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_RENAME ),
172 ( "recall47", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_RENAME|GROUP_TARGET ),
173 ( "recall48", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_RENAME|GROUP_TARGET ),
174 ( "recall49", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_RENAME|GROUP_TARGET ),
175 ( "recall50", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_RENAME|GROUP_TARGET ),
176 ( "recall51", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_CTWRTE|GROUP_PENDING ),
177 ( "recall52", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWRD|GROUP_CTWRTE|GROUP_PENDING ),
178 ( "recall53", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_CTWRTE|GROUP_PENDING ),
179 ( "recall54", GROUP_RECALL|GROUP_WDELEG|GROUP_IORWWR|GROUP_CTWRTE|GROUP_PENDING ),
180 ]
181
182 TESTNAMES_DICT = dict(TESTNAMES_ALL)
183
184 def group_test(tname, group):
185 """Return True if test belongs to the given group"""
186 testgroup = TESTNAMES_DICT.get(tname)
187 if testgroup is not None and (testgroup & group) == group:
188 return True
189 return False
190
191 def group_list(group):
192 """Return a list of tests belonging to the given group"""
193 return [x[0] for x in TESTNAMES_ALL if group_test(x[0], group)]
194
195 TESTNAMES_BASIC = group_list(GROUP_BASIC)
196 TESTNAMES_RECALL = group_list(GROUP_RECALL)
197
198 # Include the test groups in the list of test names
199 # so they are displayed in the help
200 GTESTS = ["recall", "setattr", "remove", "rename", "pending"]
201 TESTNAMES = ["basic", "stat", "lock"] + TESTNAMES_BASIC + GTESTS + \
202 TESTNAMES_RECALL + ["read_deleg", "write_deleg"]
203
204 TESTGROUPS = {
205 "basic": {
206 "tests": TESTNAMES_BASIC,
207 "desc": "Run all basic delegation tests: ",
208 },
209 "stat": {
210 "tests": group_list(GROUP_STAT),
211 "desc": "Run all basic delegation tests with file stat: ",
212 },
213 "lock": {
214 "tests": group_list(GROUP_LOCK),
215 "desc": "Run all basic delegation tests with file lock: ",
216 },
217 "recall": {
218 "tests": TESTNAMES_RECALL,
219 "desc": "Run all recall delegation tests: ",
220 },
221 "setattr": {
222 "tests": group_list(GROUP_SETATTR),
223 "desc": "Run all tests using SETATTR to recall the delegation: ",
224 },
225 "remove": {
226 "tests": group_list(GROUP_REMOVE),
227 "desc": "Run all tests recalling the delegation by removing the delegated file: ",
228 },
229 "rename": {
230 "tests": group_list(GROUP_RENAME),
231 "desc": "Run all tests recalling the delegation by renaming the delegated file: ",
232 },
233 "pending": {
234 "tests": group_list(GROUP_PENDING),
235 "desc": "Run all recall delegation tests having a pending open: ",
236 },
237 "read_deleg": {
238 "tests": group_list(GROUP_RDELEG),
239 "desc": "Run all read delegation tests: ",
240 },
241 "write_deleg": {
242 "tests": group_list(GROUP_WDELEG),
243 "desc": "Run all write delegation tests: ",
244 },
245 }
246
247 # Dictionary having the number of clients required by each test
248 TEST_CLIENT_DICT = {x:1 for x in TESTNAMES_RECALL}
249
250 PATTERN = b'FF00'
251
252 OPEN_STID = 0
253 LOCK_STID = 1
254 DELEG_STID = 2
255 stid_map = {
256 OPEN_STID : "OPEN",
257 LOCK_STID : "LOCK",
258 DELEG_STID : "DELEG",
259 }
260
261 OPEN_READ = 0
262 OPEN_WRITE = 1
263 OPEN_RDWR = 2
264
265 open_flags = {
266 OPEN_READ : os.O_RDONLY,
267 OPEN_WRITE : os.O_WRONLY|os.O_CREAT,
268 OPEN_RDWR : os.O_RDWR|os.O_CREAT,
269 }
270
271 open_str = {
272 OPEN_READ : "READ",
273 OPEN_WRITE : "WRITE",
274 OPEN_RDWR : "RDWR",
275 }
276
277 deleg_map = {
278 OPEN_READ : OPEN_DELEGATE_READ,
279 OPEN_WRITE : OPEN_DELEGATE_WRITE,
280 OPEN_RDWR : OPEN_DELEGATE_WRITE,
281 }
282
283 deleg_str = {
284 OPEN_DELEGATE_READ : "READ",
285 OPEN_DELEGATE_WRITE : "WRITE",
286 }
287
288 def file_lock(fd, open_type, absfile, lock_offset=0, lock_len=0):
289 """Lock file given by the file descriptor"""
290 lock_type = fcntl.F_RDLCK if open_type == OPEN_READ else fcntl.F_WRLCK
291 lockdata = struct.pack('hhllhh', lock_type, 0, lock_offset, lock_len, 0, 0)
292 return fcntl.fcntl(fd, fcntl.F_SETLK, lockdata)
293
294 class BaseName(Exception):
295 """Exception used to stop recall tests when --basename option is set"""
296 pass
297
298 class DelegTest(TestUtil):
299 """DelegTest object
300
301 DelegTest() -> New test object
302
303 Usage:
304 x = DelegTest(testnames=['basic', 'basic_lock', ...])
305
306 # Run all the tests
307 x.run_tests(deleg=deleg_mode)
308 x.exit()
309 """
310 def __init__(self, **kwargs):
311 """Constructor
312
313 Initialize object's private data.
314 """
315 TestUtil.__init__(self, **kwargs)
316 self.test_opgroup.version = "%prog " + __version__
317
318 # Options specific for this test script
319 hhelp = "Remote NFS client and options used for recall delegation tests. " \
320 "Clients are separated by a ',' and each client definition is " \
321 "a list of arguments separated by a ':' given in the following " \
322 "order if positional arguments is used (see examples): " \
323 "clientname:server:export:nfsversion:port:proto:sec:mtpoint " \
324 "[default: '%default']"
325 self.test_opgroup.add_option("--client", default='nfsversion=3:proto=tcp:port=2049', help=hhelp)
326 hhelp = "Comma separated list of valid NFS versions to use in the " \
327 "--client option. An NFS version from this list, which is " \
328 "different than that given by --nfsversion, is selected and " \
329 "included in the --client option [default: %default]"
330 self.test_opgroup.add_option("--client-nfsvers", default="4.0,4.1", help=hhelp)
331 hhelp = "Starting offset for lock [default: %default]"
332 self.test_opgroup.add_option("--lock-offset", type="int", default=0, help=hhelp)
333 hhelp = "Starting offset for lock on pending open [default: %default]"
334 self.test_opgroup.add_option("--lock-poffset", type="int", default=8192, help=hhelp)
335 hhelp = "Number of bytes to lock [default: %default]"
336 self.test_opgroup.add_option("--lock-len", type="int", default=4096, help=hhelp)
337 hhelp = "Truncate file when writing from the second file for the recall tests"
338 self.test_opgroup.add_option("--truncate", action="store_true", default=False, help=hhelp)
339 hhelp = "Seconds to delay after setup so all opens are released [default: %default]"
340 self.test_opgroup.add_option("--setup-delay", type="float", default=4.0, help=hhelp)
341 self.scan_options()
342
343 if len(self.basename) > 0:
344 self.setup_delay = 0.0
345
346 self.rfindex = 1
347 self.nrfiles = 1
348 for tname in self.testlist:
349 if group_test(tname, GROUP_RDELEG) or \
350 group_test(tname, GROUP_STAT) or \
351 group_test(tname, GROUP_REMOVE) or \
352 group_test(tname, GROUP_RENAME) or \
353 group_test(tname, GROUP_IORWRD) or \
354 group_test(tname, GROUP_CTREAD):
355 self.nrfiles += 1
356
357 if group_test(tname, GROUP_TARGET):
358 self.nrfiles += 1
359
360 # Disable createtraces option
361 self.createtraces = False
362
363 # Local rexec object
364 self.lexecobj = None
365
366 # Find how many remote Rexec objects should be started
367 nclients = 0
368 for tname in self.testlist:
369 nclients = max(nclients, TEST_CLIENT_DICT.get(tname, 0))
370
371 # Process the --client option
372 client_list = self.process_client_option(count=nclients, remote=None)
373 if self.client_nfsvers is not None:
374 nfsvers_list = self.str_list(self.client_nfsvers)
375 for client_args in client_list:
376 if self.proto[-1] == "6" and len(client_args.get("proto")) and client_args["proto"][-1] != 6:
377 client_args["proto"] += "6"
378 for nfsver in nfsvers_list:
379 if nfsver != self.nfsversion:
380 client_args["nfsversion"] = nfsver
381 break
382 else:
383 self.opts.error("At least one NFS version in --client-nfsvers '%s' " \
384 "must be different then --nfsversion %s" % \
385 (self.client_nfsvers, self.nfsversion))
386
387 # Remove all client specs which are not valid -- when mount is 0 that
388 # means it is the same client as the main client with the same mount
389 # options.
390 index = 0
391 while index < len(client_list):
392 if client_list[index].get("mount", 0) == 0:
393 client_list.pop(index)
394 continue
395 index += 1
396
397 self.verify_client_option(TEST_CLIENT_DICT)
398
399 # Start remote procedure server(s) remotely
400 try:
401 self.clientobj = None
402 for client_args in client_list:
403 client_name = client_args.pop("client", "")
404 self.create_host(client_name, **client_args)
405 self.create_rexec(client_name)
406 except:
407 self.test(False, traceback.format_exc())
408
409 # Verify the lock ranges do not overlap
410 end1 = self.lock_offset + self.lock_len - 1
411 end2 = self.lock_poffset + self.lock_len - 1
412 if end1 >= self.lock_poffset and end2 >= self.lock_offset:
413 # Ranges overlap
414 self.opts.error("Lock ranges overlap: (lock-offset, lock-len) and (lock-poffset, lock-len)")
415
416 def setup(self):
417 """Setup test environment"""
418 # Call base object's setup method
419 super(DelegTest, self).setup(nfiles=self.nrfiles)
420 # Delay so all opens are released and delegations could be granted
421 time.sleep(self.setup_delay)
422
423 def lock_file(self, fd, open_type, absfile, lock_offset=0, lock_len=0):
424 """Lock file given by the file descriptor.
425
426 fd:
427 Opened file descriptor of file
428 open_type:
429 Open type
430 absfile:
431 File path to display as debug info
432 lock_offset:
433 Lock offset [default: 0]
434 lock_len:
435 Lock length [default: 0]
436 """
437 lock_str = "F_RDLCK" if open_type == OPEN_READ else "F_WRLCK"
438 try:
439 fmsg = ""
440 self.dprint('DBG3', "Lock %s (F_SETLK, %s) start=%d len=%d" % (absfile, lock_str, lock_offset, lock_len))
441 file_lock(fd, open_type, absfile, lock_offset, lock_len)
442 except OSError as exerr:
443 fmsg = ", failed with %s" % exerr
444 dmsg = "Lock file with %s" % lock_str
445 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
446
447 def open_file(self, absfile, open_type, io_type=None, lock=False, lexec=False, msg=''):
448 """Open file, lock it and do some I/O on the file.
449 Return the file descriptor of the opened file.
450
451 absfile:
452 File name to open
453 open_type:
454 Open type
455 io_type:
456 I/O type
457 lock:
458 Get a lock on the file if true [default: False]
459 lexec:
460 Use different process to open file [default: False]
461 msg:
462 Message to append on debug message [default: '']
463 """
464 pidstr = " from a different process" if lexec else ""
465 msg = msg if len(msg) == 0 else " %s" % msg
466 mode_str = open_str[open_type]
467 if io_type is None:
468 io_type = OPEN_READ if open_type == OPEN_READ else OPEN_WRITE
469 io_str = open_str[io_type].capitalize()
470
471 try:
472 fmsg = ""
473 dmsg = "Open file for %s%s%s" % (mode_str, pidstr, msg)
474 self.dprint('DBG2', "%s [%s]" % (dmsg, absfile))
475 if lexec:
476 fd = self.lexecobj.run(os.open, absfile, open_flags[open_type])
477 else:
478 fd = os.open(absfile, open_flags[open_type])
479 except OSError as exerr:
480 fmsg = ", failed with %s" % exerr
481 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
482
483 if lock:
484 self.lock_file(fd, io_type, absfile, self.lock_offset, self.lock_len)
485
486 try:
487 fmsg = ""
488 dmsg = "%s file%s%s" % (io_str, pidstr, msg)
489 self.dprint("DBG3", "%s [%s]" % (dmsg, absfile))
490 # Read/Write file
491 if io_type == OPEN_READ:
492 if lexec:
493 self.lexecobj.run(os.read, fd, self.rsize)
494 else:
495 os.read(fd, self.rsize)
496 else:
497 data = self.data_pattern(0, self.wsize, PATTERN)
498 if lexec:
499 self.lexecobj.run(os.write, fd, data)
500 else:
501 os.write(fd, data)
502 except OSError as exerr:
503 fmsg = ", failed with %s" % exerr
504 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
505
506 self.delay_io()
507 return fd
508
509 def get_deleg_remote(self):
510 """Get a read delegation on the remote client."""
511 fdko = None
512 absfile = self.clientobj.abspath(self.filename)
513 if self.clientobj and self.clientobj.nfs_version < 4:
514 # There are no delegations in NFSv3 so there is no need
515 # to open a file so the open owner sticks around
516 self.dprint("DBG2", "Open file on the remote client [%s]" % absfile)
517 else:
518 # Open file so open owner sticks around so a delegation
519 # is granted when opening the file under test
520 fdko = self.rexecobj.run(os.open, self.clientobj.abspath(self.files[0]), os.O_RDONLY)
521 self.dprint("DBG2", "Get a read delegation on the remote client [%s]" % absfile)
522 # Open the file under test
523 fdrd = self.rexecobj.run(os.open, absfile, os.O_RDONLY)
524 self.dprint("DBG3", "Read %s on the remote client" % absfile)
525 data = self.rexecobj.run(os.read, fdrd, 1024)
526 self.dprint("DBG4", "Close %s on the remote client" % absfile)
527 self.rexecobj.run(os.close, fdrd)
528 if fdko is not None:
529 self.rexecobj.run(os.close, fdko)
530
531 def setup_test(self, io_type, mount=False, nfiles=0, lexec=False):
532 """Setup test by mounting server and hold open a file so that the open
533 owner sticks around so a delegation is granted on next open using
534 the same open owner -- this is done to avoid a bug on the client
535 where open owner is reaped at close
536 """
537 self.umount()
538 if mount and self.clientobj is not None:
539 # Unmount server on remote client
540 self.clientobj.umount()
541
542 if lexec and self.lexecobj is None:
543 # Start local rexec connection just once
544 rexecobj_save = self.rexecobj
545 self.lexecobj = self.create_rexec()
546 self.rexecobj = rexecobj_save
547 self.lexecobj.rimport("fcntl")
548 self.lexecobj.rcode(file_lock)
549
550 self.trace_start()
551 self.mount()
552 if mount and self.clientobj is not None:
553 # Mount server on remote client
554 self.clientobj.mount()
555
556 if io_type == OPEN_READ or nfiles > 0:
557 # Use existing file
558 self.filename = self.files[self.rfindex]
559 self.absfile = self.abspath(self.filename)
560 self.rfindex += 1
561 else:
562 # Create new file
563 self.get_filename()
564
565 # Hold a file open so that the open owner sticks around
566 # (bug on the client where OO's are reaped at close)
567 self.dprint('DBG4', "Open %s so open owner sticks around" % self.abspath(self.files[0]))
568 self.fdko = open(self.abspath(self.files[0]), 'r')
569
570 def verify_io_requests(self, iomode, deleg_stid, filehandles, src_ipaddr=None, maxindex=None):
571 """Verify I/O is sent to the correct server."""
572 nio = 0
573 dsindex = 0
574 for fh in filehandles:
575 if self.dslist:
576 # The address is one of the DS's connection
577 ds = self.dslist[dsindex]
578 else:
579 # The address is the mounted server
580 ds = [{"ipaddr": self.server_ipaddr, "port": self.port}]
581 for item in ds:
582 save_index = self.pktt.get_index()
583 nio += self.verify_io(iomode, deleg_stid, item["ipaddr"], item["port"], filehandle=fh, src_ipaddr=src_ipaddr, maxindex=maxindex, pattern=PATTERN)
584 self.pktt.rewind(save_index)
585 dsindex += 1
586 return nio
587
588 def verify_open(self, fh, stat=False):
589 """Verify OPEN call"""
590 self.test(self.opencall, "OPEN should be sent")
591 if self.opencall is None:
592 return
593 elif stat and self.nfs_version > 4.0:
594 expr = self.opencall.NFSop.claim.claim == CLAIM_FH
595 self.test(expr, "OPEN should be sent with CLAIM_FH")
596 expr = self.opencall.NFSop.fh == fh
597 self.test(expr, "OPEN should be sent with the filehandle of the file to be opened")
598 else:
599 expr = self.opencall.NFSop.claim.claim == CLAIM_NULL
600 self.test(expr, "OPEN should be sent with CLAIM_NULL")
601 if expr:
602 expr = self.opencall.NFSop.claim.name == self.filename
603 self.test(expr, "OPEN should be sent with the name of the file to be opened")
604 expr = self.opencall.NFSop.fh != fh
605 self.test(expr, "OPEN should be sent with the filehandle of the directory")
606
607 def find_ios(self, op_type, filehandle, ipaddr, port):
608 """Return a list of all I/O packets"""
609 ret = {}
610 # Matched all packets sent to the server given by ipaddr and port
611 src = "IP.src == '%s' and " % self.client_ipaddr
612 dst = self.pktt.ip_tcp_dst_expr(ipaddr, port)
613 fh = " and NFS.fh == b'%s' and " % self.pktt.escape(filehandle)
614 nfsver = self.match_nfs_version(self.nfs_version, False)
615 matchstr = src + dst + nfsver + fh + "NFS.argop == %d" % op_type
616
617 save_index = self.pktt.get_index()
618 self.pktt.clear_xid_list()
619 try:
620 # Matched all I/O packets and their replies
621 while self.pktt.match(matchstr, reply=True):
622 pkt = self.pktt.pkt
623 xid = pkt.rpc.xid
624 if pkt.rpc.type == 0:
625 # Save I/O call info
626 nfsop = pkt.NFSop
627 info = {
628 "stateid": nfsop.stateid,
629 "count": nfsop.count,
630 "nfsidx": pkt.NFSidx,
631 "callidx": pkt.record.index,
632 }
633 if ret.get(xid) is None:
634 ret[xid] = info
635 else:
636 ret[xid].update(info)
637 else:
638 # Save I/O reply status
639 idx = ret[xid].get("nfsidx")
640 if idx is not None and len(pkt.nfs.array) > idx:
641 nfsop = pkt.nfs.array[idx]
642 ret[xid]["status"] = nfsop.status
643 except:
644 self.test(False, traceback.format_exc())
645 finally:
646 self.pktt.rewind(save_index)
647 # Return the list of I/O packets having status values
648 return [item for item in ret.values() if item.get("status") is not None]
649
650 def find_io_counts(self, io_list, stateid, status):
651 """Return the number of matched stateid and matched status packets"""
652 stid = 0 # Number of I/O packets matching the stateid
653 stat = 0 # Number of I/O packets matching the status
654 okct = 0 # Number of I/O packets with status = NFS4_OK
655 for item in io_list:
656 istatus = item.get('status')
657 if istatus is None:
658 continue
659 if item.get('stateid') == stateid:
660 stid += 1
661 if istatus == status:
662 stat += 1
663 if istatus == NFS4_OK:
664 okct += 1
665 return (stid, stat, okct)
666
667 def verify_io_per_server(self, io_list, op_type, stid_type, stateid, status, ds=False, delegret=False):
668 """Verify I/O packets for a given server"""
669 dr_str = " after returning the delegation" if delegret else ""
670 io_str = "READ" if op_type == OP_READ else "WRITE"
671 st_str = stid_map.get(stid_type)
672 sv_str = "server"
673 if self.layout and self.dslist:
674 sv_str = "DS" if ds else "MDS"
675
676 if io_list:
677 nlen = len(io_list)
678 (stid, stat, okct) = self.find_io_counts(io_list, stateid, status[0])
679 self.test(stid == nlen, "%ss should be sent to the %s with the %s stateid%s" % (io_str, sv_str, st_str, dr_str))
680 if delegret and okct == nlen and stat == 0:
681 # The RFC allows servers to process I/O operations successfully
682 # when the file has been removed. In this case all I/O operations
683 # have succeeded but an error was expected for those servers
684 # failing I/O operations when the file is removed.
685 self.test(True, "%ss may return NFS4_OK from the %s%s" % (io_str, sv_str, dr_str))
686 else:
687 # Check if all I/O operations returned one of the expected
688 # status codes
689 idx = 0
690 if stat != nlen:
691 for i in range(1, len(status)):
692 (stid, stat, okct) = self.find_io_counts(io_list, stateid, status[i])
693 if stat == nlen:
694 idx = i
695 break
696 self.test(stat == nlen, "%ss should return %s from the %s%s" % (io_str, nfsstat4.get(status[idx], status[idx]), sv_str, dr_str))
697
698 def verify_io_packets(self, op_type, open_fh, stid_type, stateid, status=[NFS4_OK], ds_status=[NFS4_OK], delegret=False):
699 """Verify I/O packets"""
700 io_list = []
701 if self.layout and self.dslist:
702 # Get I/O packets sent to the DS
703 dsindex = 0
704 for fh in self.layout['filehandles']:
705 for item in self.dslist[dsindex]:
706 if item is not None:
707 io_list += self.find_ios(op_type, fh, item['ipaddr'], item['port'])
708 dsindex += 1
709 # Verify I/O packets sent to the DS
710 self.verify_io_per_server(io_list, op_type, stid_type, stateid, ds_status, ds=True, delegret=delegret)
711
712 # Verify I/O packets sent to the server (or MDS if pNFS is available)
713 io_list = self.find_ios(op_type, open_fh, self.server_ipaddr, self.port)
714 self.verify_io_per_server(io_list, op_type, stid_type, stateid, status, delegret=delegret)
715
716 def verify_lock(self, io_type, mode_str, open_stid, offset, start_index, max_index, msg="", locker=None, lock_stid=None):
717 """Verify correct lock is sent to the server"""
718 lock_stateid = None
719 self.pktt.rewind(start_index)
720 # Find LOCK call and reply using the lock offset
721 mstr = "NFS.offset == %d" % offset
722 (lockcall, lockreply) = self.find_nfs_op(OP_LOCK, match=mstr, status=None, src_ipaddr=self.client_ipaddr, maxindex=max_index)
723 self.test(lockcall, "LOCK should be sent before returning the %s delegation%s" % (mode_str, msg))
724 if lockcall:
725 # Verify lock info sent to the server
726 ltype = READ_LT if io_type == OPEN_READ else WRITE_LT
727 self.test(lockcall.NFSop.locktype == ltype, "LOCK should be sent with correct lock type")
728 self.test(lockcall.NFSop.length == self.lock_len, "LOCK should be sent with correct lock range")
729 pktlocker = lockcall.NFSop.locker
730 if pktlocker.new_lock_owner:
731 lowner = pktlocker.open_owner
732 else:
733 lowner = pktlocker.lock_owner
734 self.test(lowner.stateid == open_stid, "LOCK should be sent with correct OPEN stateid")
735 if locker is not None:
736 # Verify lock has a different lock owner than the one given
737 if locker.new_lock_owner and pktlocker.new_lock_owner:
738 # Both locks are sent with new lock owners
739 expr = locker.open_owner.lock_owner != pktlocker.open_owner.lock_owner.owner
740 elif not locker.new_lock_owner and not pktlocker.new_lock_owner:
741 # Both locks are sent with existing lock owners
742 expr = locker.lock_owner.stateid != pktlocker.lock_owner.lock_owner.stateid
743 else:
744 # One lock is sent with a new lock owner and the other
745 # with and existing lock owner
746 expr = True
747 self.test(expr, "LOCK should be sent with a different open owner")
748 if lockreply:
749 # Verify lock reply
750 lstatus = lockreply.nfs.status
751 fmsg = ", failed with %s" % nfsstat4.get(lstatus, lstatus)
752 self.test(lstatus == NFS4_OK, "LOCK should return NFS4_OK", failmsg=fmsg)
753 if lockreply.nfs.status == NFS4_OK:
754 lock_stateid = lockreply.NFSop.stateid.other
755 if lock_stid is not None:
756 # Verify lock stateid is different than the one given
757 expr = lock_stid != lock_stateid
758 self.test(expr, "LOCK should return a different lock stateid")
759 return lock_stateid
760
761 def basic_deleg_test(self, open_type, io_type=None, lock=False, stat=False, nfiles=0):
762 """Basic delegation tests"""
763 try:
764 fds = []
765 extra_str = ""
766 self.fdko = None
767 deleg_type = deleg_map[open_type]
768 mode_str = deleg_str[deleg_type]
769 if io_type is None:
770 io_type = OPEN_READ if open_type == OPEN_READ else OPEN_WRITE
771 if open_type == OPEN_RDWR:
772 io_str = "reading" if io_type == OPEN_READ else "writing"
773 extra_str = " using RDWR open while %s" % io_str
774 if lock:
775 extra_str += " with file lock"
776 elif stat:
777 extra_str += " with file stat"
778 self.test_group("Basic %s delegation test%s" % (mode_str, extra_str))
779 self.setup_test(io_type, nfiles=nfiles, lexec=True)
780
781 if stat:
782 try:
783 fmsg = ""
784 dmsg = "Stat file to cache file metadata"
785 self.dprint('DBG3', "%s [%s]" % (dmsg, self.absfile))
786 fstat = os.stat(self.absfile)
787 except OSError as exerr:
788 fmsg = ", failed with %s" % exerr
789 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
790
791 # Open file, should get a DELEGATION
792 fds.append(self.open_file(self.absfile, open_type, io_type, lock=lock))
793
794 # Open same file on same process for reading
795 fds.append(self.open_file(self.absfile, OPEN_READ, msg="on same process"))
796
797 if open_type == OPEN_WRITE:
798 # Open same file on same process for writing
799 fds.append(self.open_file(self.absfile, OPEN_WRITE, msg="on same process"))
800
801 # Access file from a different process
802 fd = self.open_file(self.absfile, OPEN_READ, lexec=True)
803 self.lexecobj.run(os.close, fd)
804
805 if open_type == OPEN_WRITE:
806 # Open same file on different process for writing
807 fd = self.open_file(self.absfile, OPEN_WRITE, lexec=True)
808 self.lexecobj.run(os.close, fd)
809 except Exception:
810 self.test(False, traceback.format_exc())
811 return
812 finally:
813 if self.fdko:
814 # Close open owner file
815 self.fdko.close()
816 # Close open files
817 for fd in fds:
818 os.close(fd)
819 self.umount()
820 self.trace_stop()
821
822 try:
823 self.trace_open()
824 self.set_pktlist()
825
826 filehandle = None
827 if stat:
828 # Find the LOOKUP for the file under test
829 while True:
830 (lookupcall, lookupreply) = self.find_nfs_op(OP_LOOKUP, src_ipaddr=self.client_ipaddr)
831 if lookupcall is None or lookupcall.NFSop.name == self.filename:
832 # Found LOOKUP for the filename or the end of the
833 # trace file has been reached
834 break
835 self.test(lookupcall, "LOOKUP operation should be sent")
836 if lookupreply:
837 # GETFH should be the operation following the LOOKUP
838 getfh_obj = self.getop(lookupreply, OP_GETFH)
839 if getfh_obj:
840 # Get the file handle for the file under test
841 filehandle = getfh_obj.fh
842 else:
843 # Could not find GETFH
844 self.test(False, "Could not find GETFH operation in the LOOKUP compound")
845
846 (fh, op_stid, deleg_stid) = self.find_open(filename=self.filename, claimfh=filehandle, deleg_type=deleg_type, anyclaim=True)
847 self.verify_open(fh, stat)
848 self.test(deleg_stid != None, "%s delegation should be granted" % mode_str)
849 save_index = self.pktt.get_index()
850 if deleg_stid is None:
851 # Delegation was not granted
852 return
853
854 filehandles = [fh]
855 self.find_layoutget(fh)
856 (devcall, devreply, dslist) = self.find_getdeviceinfo()
857 self.pktt.rewind(save_index)
858 if self.layout:
859 filehandles = self.layout['filehandles']
860
861 # Find any other OPENs for the same file
862 olist = self.find_open(filename=self.filename)
863 self.test(olist[0] is None, "OPEN should not be sent for the same file")
864
865 if lock:
866 # Rewind trace file
867 self.pktt.rewind()
868 (lockcall, lockreply) = self.find_nfs_op(OP_LOCK, src_ipaddr=self.client_ipaddr)
869 self.test(lockcall is None, "LOCK should not be sent to the server")
870
871 # Verify I/O packets
872 op_type = OP_READ if open_type == OPEN_READ else OP_WRITE
873 self.verify_io_packets(op_type, fh, DELEG_STID, deleg_stid)
874
875 # Rewind trace file to saved packet index
876 if deleg_type == OPEN_DELEGATE_READ:
877 self.pktt.rewind(save_index)
878 nio = self.verify_io_requests(deleg_type, deleg_stid, filehandles, src_ipaddr=self.client_ipaddr)
879 if nio > 0:
880 unique_io_list = sorted(set(self.test_offsets))
881 expr = len(self.test_offsets) == len(unique_io_list)
882 self.test(expr, "%s should not be sent when reading delegated file from a different process" % mode_str)
883
884 # Find CLOSE request and reply
885 self.verify_close(fh, op_stid, pindex=save_index)
886
887 if self.pktcall:
888 # Find DELEGRETURN request and reply
889 self.pktt.rewind(self.pktcall.record.index)
890 match_str = "NFS.fh == b'%s'" % self.pktt.escape(fh)
891 (delegreturncall, delegreturnreply) = self.find_nfs_op(OP_DELEGRETURN, src_ipaddr=self.client_ipaddr, match=match_str)
892 self.test(delegreturncall, "DELEGRETURN should be sent after the close")
893 if delegreturncall:
894 expr = delegreturncall.NFSop.stateid.other == deleg_stid
895 self.test(expr, "DELEGRETURN should be sent with the delegation stateid")
896 except Exception:
897 self.test(False, traceback.format_exc())
898 finally:
899 self.pktt.close()
900
901 def get_conflict_pkts(self, conflict_op, conflict_match):
902 """Get conflicting operation packets"""
903 pkt_call = None
904 pktcall = None
905 pktreply = None
906 while True:
907 pkt_call = self.pktt.match(conflict_match)
908 if pkt_call is None:
909 break
910 elif pktcall is None:
911 # Get the first OPEN call for testing CB_RECALL
912 pktcall = pkt_call
913
914 # Make sure conflicting operation reply status from the
915 # second client is not NFS4ERR_DELAY
916 xid = pkt_call.rpc.xid
917 matchstr = "RPC.xid == %d and NFS.status in (%d, %d) and NFS.resop == %d" % (xid, NFS4_OK, NFS4ERR_DELAY, conflict_op)
918 pktreply = self.pktt.match(matchstr)
919 if pktreply is None or pktreply.nfs.status == NFS4_OK:
920 break
921 return pktcall, pktreply
922
923 def recall_deleg_test(self, open_type, io_type=None, conflict_type=OP_WRITE, lock=False, nfiles=0, target=False, claim_cur=None):
924 """Delegation recall tests"""
925 if self.clientobj is None:
926 return
927 try:
928 fd = None
929 fdsec = None
930 self.fdko = None
931 extra_str = ""
932 deleg_type = deleg_map[open_type]
933 mode_str = deleg_str[deleg_type]
934 nfs_version = self.clientobj.nfs_version
935 sipaddr = self.clientobj.ipaddr
936 sproto = self.clientobj.proto
937 sport = self.clientobj.port
938 if io_type is None:
939 io_type = OPEN_READ if open_type == OPEN_READ else OPEN_WRITE
940 io_str = open_str[io_type]
941 op_type = OP_READ if io_type == OPEN_READ else OP_WRITE
942 if conflict_type == OP_SETATTR:
943 conflict_str = "SETATTR (chmod)"
944 conflict_op = OP_SETATTR if nfs_version > 3 else NFSPROC3_SETATTR
945 elif conflict_type == OP_REMOVE:
946 conflict_str = "REMOVE"
947 conflict_op = OP_REMOVE if nfs_version > 3 else NFSPROC3_REMOVE
948 elif conflict_type == OP_RENAME:
949 conflict_str = "RENAME"
950 conflict_op = OP_RENAME if nfs_version > 3 else NFSPROC3_RENAME
951 conflict_str += " (DST)" if target else " (SRC)"
952 elif nfs_version < 4:
953 if conflict_type == OP_READ:
954 conflict_str = "READ"
955 conflict_op = NFSPROC3_READ
956 # Use an existing file because reading an empty file
957 # in NFSv3 will not send the READ procedure
958 nfiles = 1
959 else:
960 conflict_str = "WRITE"
961 conflict_op = NFSPROC3_WRITE
962 else:
963 nfiles = 1 if conflict_type == OP_READ else 0
964 ctype = "READ" if conflict_type == OP_READ else "WRITE"
965 conflict_str = "OPEN (%s)" % ctype
966 conflict_op = OP_OPEN
967
968 if open_type == OPEN_RDWR:
969 iostr = "reading" if io_type == OPEN_READ else "writing"
970 extra_str = " using RDWR open while %s" % iostr
971
972 lock_str = " with file lock" if lock else ""
973
974 claim_str = ""
975 if claim_cur == os.O_RDONLY:
976 claim_io = "READ"
977 claim_str = ", having a pending READ open"
978 elif claim_cur == os.O_WRONLY:
979 claim_io = "WRITE"
980 claim_str = ", having a pending WRITE open"
981
982 # Flag to read same file from another client to test the
983 # delegation should not be recalled
984 other_read_deleg = deleg_type == OPEN_DELEGATE_READ and claim_cur is None
985
986 extra_str += "%s%s" % (lock_str, claim_str)
987 self.test_group("Recall %s delegation with %s%s" % (mode_str, conflict_str, extra_str))
988 self.setup_test(io_type, mount=True, nfiles=nfiles, lexec=(claim_cur is not None))
989
990 # Open file, should get a DELEGATION
991 try:
992 fmsg = ""
993 dmsg = "Open file for %s" % open_str[open_type]
994 self.dprint('DBG2', "%s [%s]" % (dmsg, self.absfile))
995 fd = os.open(self.absfile, open_flags[open_type])
996 except OSError as exerr:
997 fmsg = ", failed with %s" % exerr
998 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
999
1000 if lock:
1001 self.lock_file(fd, io_type, self.absfile, self.lock_offset, self.lock_len)
1002
1003 iosize = int(self.PAGESIZE/2)
1004
1005 cio_type = None
1006 if claim_cur is not None:
1007 try:
1008 fmsg = ""
1009 dmsg = "Open file for %s in a different process" % claim_io
1010 self.dprint('DBG2', "%s [%s]" % (dmsg, self.absfile))
1011 fdsec = self.lexecobj.run(os.open, self.absfile, claim_cur)
1012 except OSError as exerr:
1013 fmsg = ", failed with %s" % exerr
1014 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
1015
1016 try:
1017 fmsg = ""
1018 dmsg = "Lock file in a different process"
1019 cio_type = OPEN_READ if claim_cur == os.O_RDONLY else OPEN_WRITE
1020 cio_lstr = "F_RDLCK" if claim_cur == os.O_RDONLY else "F_WRLCK"
1021 self.dprint('DBG3', "Lock %s in a different process (F_SETLK, %s) start=%d len=%d" % (self.absfile, cio_lstr, self.lock_poffset, self.lock_len))
1022 self.lexecobj.run(file_lock, fdsec, cio_type, self.absfile, self.lock_poffset, self.lock_len)
1023 except IOError as exerr:
1024 fmsg = ", failed with %s" % exerr
1025 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
1026
1027 if len(self.basename) > 0:
1028 if conflict_type == OP_RENAME and not target:
1029 aname = self.absfile
1030 fname = self.filename
1031 self.get_filename()
1032 self.absfile = aname
1033 self.filename = fname
1034 raise BaseName
1035
1036 try:
1037 # Read/Write file
1038 fmsg = ""
1039 dmsg = "%s file on client holding delegation" % io_str.capitalize()
1040 self.dprint("DBG3", "%s [%s]" % (dmsg, self.absfile))
1041 if io_type == OPEN_READ:
1042 os.read(fd, iosize)
1043 else:
1044 os.write(fd, self.data_pattern(0, iosize, PATTERN))
1045 except OSError as exerr:
1046 fmsg = ", failed with %s" % exerr
1047 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
1048 self.delay_io()
1049
1050 # Read same file from another client -- delegation should not be
1051 # recalled and delegation should be granted
1052 if other_read_deleg:
1053 # Other READ opens will not recall the delegation
1054 self.get_deleg_remote()
1055
1056 # Absolute path name for remote file
1057 r_absfile = self.clientobj.abspath(self.filename)
1058
1059 try:
1060 fmsg = ""
1061 if conflict_type == OP_SETATTR:
1062 dmsg = "Change permissions on the file from another client"
1063 self.dprint("DBG2", "%s to recall delegation [%s]" % (dmsg, r_absfile))
1064 self.rexecobj.run(os.chmod, r_absfile, 0o777)
1065 elif conflict_type == OP_REMOVE:
1066 dmsg = "Remove the file from another client"
1067 self.dprint("DBG2", "%s to recall delegation [%s]" % (dmsg, r_absfile))
1068 self.rexecobj.run(os.unlink, r_absfile)
1069 elif conflict_type == OP_RENAME:
1070 if target:
1071 fname = self.files[self.rfindex]
1072 self.rfindex += 1
1073 srcname = self.clientobj.abspath(fname)
1074 dmsg = "Rename into the file (DST) from another client"
1075 self.dprint("DBG2", "%s to recall delegation [%s -> %s]" % (dmsg, fname, self.filename))
1076 self.rexecobj.run(os.rename, srcname, r_absfile)
1077 else:
1078 aname = self.absfile
1079 fname = self.filename
1080 self.get_filename()
1081 dmsg = "Rename the file (SRC) from another client"
1082 self.dprint("DBG2", "%s to recall delegation [%s -> %s]" % (dmsg, fname, self.filename))
1083 newname = self.clientobj.abspath(self.filename)
1084 self.absfile = aname
1085 self.filename = fname
1086 self.rexecobj.run(os.rename, r_absfile, newname)
1087 elif conflict_type == OP_READ:
1088 dmsg = "Read same file from another client"
1089 self.dprint("DBG2", "%s to recall delegation [%s]" % (dmsg, r_absfile))
1090 fdrd = self.rexecobj.run(os.open, r_absfile, os.O_RDONLY)
1091 data = self.rexecobj.run(os.read, fdrd, 1024)
1092 self.rexecobj.run(os.close, fdrd)
1093 elif self.truncate:
1094 dmsg = "Write same file (truncate before writing) from another client"
1095 self.dprint("DBG2", "%s to recall delegation [%s]" % (dmsg, r_absfile))
1096 fdwr = self.rexecobj.run(os.open, r_absfile, os.O_WRONLY|os.O_TRUNC)
1097 count = self.rexecobj.run(os.write, fdwr, self.data_pattern(0, 1024, b"x"))
1098 self.rexecobj.run(os.close, fdwr)
1099 else:
1100 dmsg = "Write same file from another client"
1101 self.dprint("DBG2", "%s to recall delegation [%s]" % (dmsg, r_absfile))
1102 fdwr = self.rexecobj.run(os.open, r_absfile, os.O_WRONLY|os.O_APPEND)
1103 count = self.rexecobj.run(os.write, fdwr, self.data_pattern(0, 1024, b"X"))
1104 self.rexecobj.run(os.close, fdwr)
1105 except OSError as exerr:
1106 fmsg = ", failed with %s" % exerr
1107 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
1108
1109 try:
1110 fmsg = ""
1111 error = None
1112 dmsg = "%s file after conflicting operation" % io_str.capitalize()
1113 self.dprint("DBG3", "%s [%s]" % (dmsg, self.absfile))
1114 # Check for errors since the server may return an error
1115 # when the file has been removed by another client
1116 expfail = conflict_type == OP_REMOVE or (conflict_type == OP_RENAME and target)
1117 # Read/Write file
1118 if io_type == OPEN_READ:
1119 os.read(fd, self.filesize - iosize)
1120 else:
1121 os.write(fd, self.data_pattern(iosize, self.filesize - iosize, PATTERN))
1122 # Flush data so if there is an error on a write it will
1123 # happened here instead on the close
1124 os.fdatasync(fd)
1125 except OSError as exerr:
1126 if expfail:
1127 expected = errno.errorcode[errno.ESTALE]
1128 error = errno.errorcode[exerr.errno]
1129 fmsg = ": expecting %s, got %s" % (expected, error)
1130 self.dprint("DBG3", "%s returns: %s" % (dmsg, str(exerr)))
1131 self.test(exerr.errno == errno.ESTALE, "%s may return an error" % dmsg, failmsg=fmsg)
1132 else:
1133 fmsg = ", failed with %s" % exerr
1134 if not expfail:
1135 self.test(len(fmsg) == 0, "%s should succeed" % dmsg, failmsg=fmsg)
1136 elif error is None:
1137 self.test(len(fmsg) == 0, "%s may succeed" % dmsg, failmsg=fmsg)
1138 self.delay_io()
1139 except BaseName:
1140 pass
1141 except:
1142 self.test(False, traceback.format_exc())
1143 finally:
1144 if fd:
1145 # Close file
1146 self.dprint('DBG4', "Close %s" % self.absfile)
1147 os.close(fd)
1148 if self.fdko:
1149 # Close open owner file
1150 self.fdko.close()
1151 if fdsec:
1152 self.dprint('DBG4', "Close %s on second process" % self.absfile)
1153 self.lexecobj.run(os.close, fdsec)
1154 self.umount()
1155 if self.clientobj:
1156 self.clientobj.umount()
1157 self.trace_stop()
1158
1159 try:
1160 if conflict_type == OP_REMOVE or (conflict_type == OP_RENAME and target):
1161 self.set_nfserr_list(
1162 nfs3list=[NFS3ERR_NOENT, NFS3ERR_JUKEBOX],
1163 nfs4list=[NFS4ERR_NOENT, NFS4ERR_DELAY, NFS4ERR_STALE, NFS4ERR_BAD_STATEID],
1164 )
1165 else:
1166 self.set_nfserr_list(
1167 nfs3list=[NFS3ERR_NOENT, NFS3ERR_JUKEBOX],
1168 nfs4list=[NFS4ERR_NOENT, NFS4ERR_DELAY],
1169 )
1170 self.trace_open()
1171 self.set_pktlist()
1172
1173 # Find OPEN on second mount
1174 (open2fh, open2stid, deleg2stid) = self.find_open(filename=self.filename, src_ipaddr=self.clientobj.ipaddr, nfs_version=self.clientobj.nfs_version)
1175 self.pktt.rewind(0)
1176
1177 # Find OPEN on main mount
1178 (open_fh, open_stid, deleg_stid) = self.find_open(filename=self.filename, deleg_type=deleg_type, src_ipaddr=self.client_ipaddr)
1179 self.verify_open(open_fh)
1180 self.test(deleg_stid != None, "%s delegation should be granted" % mode_str)
1181 save_index = self.pktt.get_index()
1182 open1_index = save_index
1183 if deleg_stid is None:
1184 # Delegation was not granted
1185 return
1186
1187 if open2fh is None:
1188 open2fh = open_fh
1189
1190 open_stateid = None
1191 if open_stid is not None:
1192 open_stateid = self.openreply.NFSop.stateid
1193
1194 filehandles = [open_fh]
1195 self.find_layoutget(open_fh)
1196 (devcall, devreply, dslist) = self.find_getdeviceinfo()
1197 self.pktt.rewind(save_index)
1198 if self.layout:
1199 filehandles = self.layout['filehandles']
1200
1201 fh1 = None
1202 if other_read_deleg:
1203 # Find OPEN (READ) call from the second client
1204 (fh1, op_stid1, deleg_stid1) = self.find_open(filename=self.filename, src_ipaddr=sipaddr, port=sport, proto=sproto, nfs_version=nfs_version)
1205 save_index = self.pktt.get_index() + 1
1206
1207 # Find DELEGRETURN request and reply
1208 (delegreturncall, delegreturnreply) = self.find_nfs_op(OP_DELEGRETURN, src_ipaddr=self.client_ipaddr)
1209 if delegreturncall:
1210 delegreturn_index = delegreturncall.record.index
1211 self.pktt.rewind(save_index)
1212
1213 # Find OPEN call from the second client
1214 src_other_client_str = "IP.dst == '%s'" % self.server_ipaddr
1215 if sproto in ("tcp", "udp"):
1216 src_other_client_str += " and %s.dst_port == %d" % (sproto.upper(), sport)
1217 src_other_client_str += " and IP.src == '%s' and " % sipaddr
1218 nfsver = self.match_nfs_version(nfs_version)
1219 conflict_match_str = src_other_client_str + nfsver + "NFS.argop == %d" % conflict_op
1220 if conflict_op == OP_OPEN:
1221 conflict_match_str += " and (NFS.claim.name == '%s' or" % self.filename
1222 conflict_match_str += " (NFS.fh == b'%s' and NFS.claim.claim == %d))" % (self.pktt.escape(open2fh), CLAIM_FH)
1223 elif target and conflict_type == OP_RENAME:
1224 conflict_match_str += " and NFS.newname == '%s'" % self.filename
1225 elif conflict_type in [OP_REMOVE, OP_RENAME]:
1226 conflict_match_str += " and NFS.name == '%s'" % self.filename
1227 elif conflict_op in [NFSPROC3_READ, NFSPROC3_WRITE]:
1228 if fh1 is None:
1229 # Find the NFSv3 LOOKUP to get the file handle
1230 (fh1, op_stid1, deleg_stid1) = self.find_open(filename=self.filename, src_ipaddr=sipaddr, port=sport, proto=sproto, nfs_version=nfs_version)
1231 expr = fh1 is not None
1232 self.test(expr, "LOOKUP should be sent from second client")
1233 if expr:
1234 conflict_match_str += " and NFS.fh == b'%s'" % self.pktt.escape(fh1)
1235
1236 silly_op = OP_RENAME if nfs_version > 3 else NFSPROC3_RENAME
1237 silly_match_str = src_other_client_str + nfsver + "NFS.argop == %d" % silly_op
1238 silly_match_str += " and NFS.name == '%s'" % self.filename
1239
1240 opencall = None
1241 openreply = None
1242 silly_rename = False
1243 if target and conflict_type == OP_RENAME:
1244 # Look for silly rename before looking for RENAME(DST)
1245 opencall, openreply = self.get_conflict_pkts(silly_op, silly_match_str)
1246 if opencall:
1247 self.dprint('DBG2', "Silly RENAME found instead of RENAME(DST)")
1248 silly_rename = True
1249 conflict_op == silly_op
1250 conflict_str = "RENAME"
1251
1252 if opencall is None:
1253 # Get conflicting operation packets
1254 opencall, openreply = self.get_conflict_pkts(conflict_op, conflict_match_str)
1255
1256 if opencall is None and conflict_type == OP_REMOVE and not (target and conflict_type == OP_RENAME):
1257 # REMOVE call was not found, look for a silly rename
1258 opencall, openreply = self.get_conflict_pkts(silly_op, silly_match_str)
1259 if opencall:
1260 self.dprint('DBG2', "Silly RENAME found instead of REMOVE")
1261 silly_rename = True
1262 conflict_op == silly_op
1263 conflict_str = "RENAME"
1264
1265 if opencall is None:
1266 self.test(False, "%s should be sent from second client" % conflict_str)
1267 return
1268 conflict_index = opencall.record.index + 1
1269 self.pktt.rewind(conflict_index)
1270
1271 # Boolean for pending test which should not recall the delegation
1272 read_write = deleg_type == OPEN_DELEGATE_READ and claim_cur == os.O_WRONLY
1273
1274 if other_read_deleg:
1275 self.pktt.rewind(save_index)
1276 # Verify no CB_RECALL is sent to client under test
1277 (cbcall, cbreply) = self.find_nfs_op(OP_CB_RECALL, ipaddr=self.client_ipaddr, port=None, src_ipaddr=self.server_ipaddr, maxindex=conflict_index, first_call=True, nfs_version=None)
1278 self.test(cbcall is None, "CB_RECALL should not be sent to the client after a READ OPEN is received from a second client")
1279 if deleg_stid1 != None:
1280 self.test(cbcall is None, "CB_RECALL should not be sent to the client after a second client is granted a READ delegation")
1281 self.pktt.rewind(conflict_index)
1282
1283 lock_stid = None
1284 if lock:
1285 self.pktt.rewind(save_index)
1286 # Verify no CB_RECALL is sent to client under test
1287 (cbcall, cbreply) = self.find_nfs_op(OP_CB_RECALL, ipaddr=self.client_ipaddr, port=None, src_ipaddr=self.server_ipaddr, maxindex=conflict_index, first_call=True, nfs_version=None)
1288 self.test(cbcall is None, "%s delegation should not be recalled after locking the file" % mode_str)
1289
1290 (lockcall, lockreply) = self.find_nfs_op(OP_LOCK, src_ipaddr=self.client_ipaddr, maxindex=conflict_index)
1291 if read_write:
1292 self.test(lockcall, "LOCK should be sent when holding a %s delegation and the file is opened on the same client for writing" % mode_str)
1293 if lockreply:
1294 lock_stid = lockreply.NFSop.stateid.other
1295 else:
1296 self.test(lockcall is None, "LOCK should not be sent when holding a %s delegation on the file" % mode_str)
1297 self.pktt.rewind(conflict_index)
1298
1299 wrdexpr = False
1300 deleg2_stid = None
1301 open2_stid = None
1302 mode2_str = mode_str
1303 if read_write:
1304 # The client returns the delegation
1305 self.test(delegreturncall, "DELEGRETURN should be sent when the file is opened on the same client for writing")
1306 if delegreturncall:
1307 expr = delegreturncall.NFSop.stateid.other == deleg_stid
1308 self.test(expr, "DELEGRETURN should be sent with the %s delegation stateid" % mode_str)
1309
1310 # Find if there is an open after DELEGRETURN but before
1311 # the conflicting operation
1312 s_index = self.pktt.get_index()
1313 self.pktt.rewind(delegreturncall.record.index)
1314 (o_fh, o_stid, deleg2_stid) = self.find_open(filename=self.filename, claimfh=open_fh, anyclaim=True, src_ipaddr=self.client_ipaddr, maxindex=opencall.record.index)
1315 if deleg2_stid is not None:
1316 # Server returned a delegation for the new open
1317 open2_stid = o_stid
1318 deleg_type = self.openreply.NFSop.delegation.deleg_type
1319 mode2_str = deleg_str[self.openreply.NFSop.delegation.deleg_type]
1320 wrdexpr = (self.opencall.NFSop.access == OPEN4_SHARE_ACCESS_WRITE and deleg_type == OPEN_DELEGATE_READ)
1321
1322 # Find the DELEGRETURN for this new delegation
1323 (delegreturncall, delegreturnreply) = self.find_nfs_op(OP_DELEGRETURN, src_ipaddr=self.client_ipaddr)
1324 if delegreturncall:
1325 # Change index to second DELEGRETURN
1326 delegreturn_index = delegreturncall.record.index
1327 self.pktt.rewind(s_index)
1328
1329 self.test(opencall, "%s should be sent from second client" % conflict_str)
1330 if conflict_op == OP_SETATTR:
1331 expr = opencall.NFSop.stateid.seqid == self.stateid_anonymous.seqid \
1332 and opencall.NFSop.stateid.other == self.stateid_anonymous.other
1333 self.test(expr, "%s should be sent with the special anonymous stateid (0, 0)" % conflict_str)
1334 elif conflict_op == OP_REMOVE:
1335 expr = opencall.NFSop.name == self.filename
1336 self.test(expr, "%s should be sent with file holding the delegation as the name" % conflict_str)
1337 elif conflict_op == OP_RENAME:
1338 if target and not silly_rename:
1339 expr = opencall.NFSop.newname == self.filename
1340 self.test(expr, "%s should be sent with file holding the delegation as the target" % conflict_str)
1341 else:
1342 expr = opencall.NFSop.name == self.filename
1343 self.test(expr, "%s should be sent with file holding the delegation as the source" % conflict_str)
1344
1345 # Find CB_RECALL sent to client under test
1346 (cbcall, cbreply) = self.find_nfs_op(OP_CB_RECALL, ipaddr=self.client_ipaddr, port=None, src_ipaddr=self.server_ipaddr, first_call=True, nfs_version=None)
1347 if read_write and not deleg2_stid:
1348 # The client has returned the delegation so no CB_RECALL
1349 self.test(cbcall is None, "CB_RECALL should not be sent to the client after a conflicting %s is received from a second client" % conflict_str)
1350 self.test(openreply, "%s reply should be sent to the second client" % conflict_str)
1351 # Verify I/O packets
1352 stid_type = LOCK_STID if lock and lock_stid else OPEN_STID
1353 stateid = lock_stid if stid_type == LOCK_STID else open_stid
1354 self.verify_io_packets(op_type, open_fh, stid_type, stateid, delegret=True)
1355 else:
1356 self.test(cbcall, "CB_RECALL should be sent to the client after a conflicting %s is received from a second client" % conflict_str)
1357 if cbcall is None:
1358 return
1359 cbrecall_index = self.pktt.get_index()
1360 if deleg2_stid is None:
1361 expr = cbcall.NFSop.stateid.other == deleg_stid
1362 else:
1363 expr = cbcall.NFSop.stateid.other == deleg2_stid
1364 mode_str = mode2_str
1365 self.test(expr, "CB_RECALL should recall %s delegation granted to client" % mode_str)
1366 self.test(cbreply, "CB_RECALL reply should be sent to the server")
1367 if cbreply:
1368 self.test(cbreply.NFSop.status == NFS4_OK, "CB_RECALL should return NFS4_OK")
1369
1370 # Find OPEN sent from the client right before returning the delegation
1371 (fh, op_stid2, deleg_stid2) = self.find_open(filename=self.filename, deleg_stateid=deleg_stid, src_ipaddr=self.client_ipaddr, fh=open_fh)
1372 open_index = self.pktt.get_index()
1373 if fh is not None or (not wrdexpr and claim_cur in [os.O_RDONLY, os.O_WRONLY]):
1374 expr1 = deleg_type == OPEN_DELEGATE_READ and claim_cur == os.O_RDONLY
1375 expr2 = deleg_type == OPEN_DELEGATE_WRITE and claim_cur == os.O_WRONLY
1376 # OPEN is only sent if main open and pending open are different
1377 if not (op_stid2 is None and (expr1 or expr2)):
1378 self.test(op_stid2, "OPEN with CLAIM_DELEGATE_CUR is sent before returning the %s delegation after CB_RECALL" % mode_str)
1379 if fh is not None:
1380 self.test(op_stid2 == open_stid, "OPEN stateid should be the same as the original OPEN stateid")
1381 op_stateid = self.openreply.NFSop.stateid
1382 expr = op_stateid.seqid == open_stateid.seqid + 1
1383 self.test(expr, "OPEN stateid seqid should be increased by one from the original OPEN stateid")
1384 self.test(deleg_stid2 is None, "Delegation should not be granted when re-opening the file before returning the %s delegation after CB_RECALL" % mode_str)
1385
1386 if deleg_type == OPEN_DELEGATE_WRITE:
1387 # Find out how much data has already been flushed right
1388 # before getting the CB_RECALL
1389 self.pktt.rewind(open1_index)
1390 nio = self.verify_io_requests(deleg_type, deleg_stid, filehandles, src_ipaddr=self.client_ipaddr, maxindex=cbrecall_index)
1391 if iosize > sum(self.test_counts):
1392 # Not all data has been flushed,
1393 # so find the WRITEs before DELEGRETURN
1394 self.pktt.rewind(cbrecall_index)
1395 nio = self.verify_io_requests(deleg_type, deleg_stid, filehandles, src_ipaddr=self.client_ipaddr, maxindex=open_index)
1396 if nio > 0:
1397 # Make this test optional since latest kernels do not
1398 # flush the data before returning the delegation
1399 self.test(True, "Client flushes written data before returning the WRITE delegation")
1400 else:
1401 self.test(True, "Client has already flushed all written data before CB_RECALL")
1402 self.pktt.rewind(open_index)
1403
1404 lock_stid2 = lock_stid
1405 lock_stid = None
1406 locker = None
1407 if lock and delegreturncall and not wrdexpr:
1408 # Verify the LOCK before DELEGRETURN
1409 lop_stid = lock_stid2 if lock_stid2 else open_stid if op_stid2 is None else op_stid2
1410 lock_stid = self.verify_lock(io_type, mode_str, lop_stid, self.lock_offset, open_index, delegreturn_index)
1411 if self.pktcall:
1412 # Save lock owner
1413 locker = self.pktcall.NFSop.locker
1414 if cio_type is not None:
1415 # Verify the LOCK before DELEGRETURN -- second process
1416 msg = " for the second process"
1417 lop_stid = lop_stid if open2_stid is None else open2_stid
1418 self.verify_lock(cio_type, mode_str, lop_stid, self.lock_poffset, open_index, delegreturn_index, msg=msg, locker=locker, lock_stid=lock_stid)
1419
1420 self.test(delegreturncall, "DELEGRETURN should be sent")
1421 if delegreturncall is None:
1422 return
1423 deleg_stid = deleg_stid if deleg2_stid is None else deleg2_stid
1424 expr = delegreturncall.NFSop.stateid.other == deleg_stid
1425 self.test(expr, "DELEGRETURN should be sent with the stateid of %s delegation being recalled" % mode_str)
1426
1427 self.pktt.rewind(delegreturn_index)
1428
1429 # Find conflicting operation reply from the second client
1430 self.test(openreply != None, "%s reply should be sent to the second client after the %s delegation has been returned" % (conflict_str, mode_str))
1431 if openreply is None:
1432 return
1433 mds_stat = [NFS4_OK, NFS3_OK]
1434 ds_stat = [NFS4_OK]
1435 if wrdexpr and lock_stid2:
1436 stid_type = LOCK_STID if lock and lock_stid2 else OPEN_STID
1437 stateid = lock_stid2 if stid_type == LOCK_STID else open_stid
1438 else:
1439 stid_type = LOCK_STID if lock and lock_stid else OPEN_STID
1440 stateid = lock_stid if stid_type == LOCK_STID else open_stid
1441 if conflict_op == OP_OPEN:
1442 self.test(openreply.NFSop.delegation.deleg_type == OPEN_DELEGATE_NONE, "Delegation should not be granted for the second client")
1443 elif conflict_type == OP_REMOVE or (conflict_type == OP_RENAME and target):
1444 ds_stat = [NFS4ERR_STALE, NFS4ERR_BAD_STATEID]
1445 mds_stat = [NFS4ERR_STALE]
1446
1447 # Verify I/O packets
1448 save_index = self.pktt.get_index()
1449 self.verify_io_packets(op_type, open_fh, stid_type, stateid, status=mds_stat, ds_status=ds_stat, delegret=True)
1450
1451 # Find CLOSE request and reply
1452 self.verify_close(open_fh, open_stid, pindex=save_index)
1453 except Exception:
1454 self.test(False, traceback.format_exc())
1455 finally:
1456 self.pktt.close()
1457
1458 def basic01_test(self):
1459 """Basic read delegation test"""
1460 self.basic_deleg_test(OPEN_READ)
1461
1462 def basic02_test(self):
1463 """Basic write delegation test"""
1464 self.basic_deleg_test(OPEN_WRITE)
1465
1466 def basic03_test(self):
1467 """Basic read delegation test with file stat"""
1468 self.basic_deleg_test(OPEN_READ, stat=True)
1469
1470 def basic04_test(self):
1471 """Basic write delegation test with file stat"""
1472 self.basic_deleg_test(OPEN_WRITE, stat=True, nfiles=1)
1473
1474 def basic05_test(self):
1475 """Basic read delegation test with file lock"""
1476 self.basic_deleg_test(OPEN_READ, lock=True)
1477
1478 def basic06_test(self):
1479 """Basic write delegation test with file lock"""
1480 self.basic_deleg_test(OPEN_WRITE, lock=True)
1481
1482 def basic07_test(self):
1483 """Basic write delegation test using RDWR open while reading"""
1484 self.basic_deleg_test(OPEN_RDWR, io_type=OPEN_READ)
1485
1486 def basic08_test(self):
1487 """Basic write delegation test using RDWR open while writing"""
1488 self.basic_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE)
1489
1490 def basic09_test(self):
1491 """Basic write delegation test using RDWR open while reading with file stat"""
1492 self.basic_deleg_test(OPEN_RDWR, io_type=OPEN_READ, stat=True)
1493
1494 def basic10_test(self):
1495 """Basic write delegation test using RDWR open while writing with file stat"""
1496 self.basic_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, stat=True, nfiles=1)
1497
1498 def basic11_test(self):
1499 """Basic write delegation test using RDWR open while reading with file lock"""
1500 self.basic_deleg_test(OPEN_RDWR, io_type=OPEN_READ, lock=True)
1501
1502 def basic12_test(self):
1503 """Basic write delegation test using RDWR open while writing with file lock"""
1504 self.basic_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, lock=True)
1505
1506 def recall01_test(self):
1507 """Recall read delegation by writing from a second client"""
1508 self.recall_deleg_test(OPEN_READ)
1509
1510 def recall02_test(self):
1511 """Recall write delegation by writing from a second client"""
1512 self.recall_deleg_test(OPEN_WRITE)
1513
1514 def recall03_test(self):
1515 """Recall read delegation by writing from a second client with file lock"""
1516 self.recall_deleg_test(OPEN_READ, lock=True)
1517
1518 def recall04_test(self):
1519 """Recall write delegation by writing from a second client with file lock"""
1520 self.recall_deleg_test(OPEN_WRITE, lock=True)
1521
1522 def recall05_test(self):
1523 """Recall write delegation by reading from a second client"""
1524 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_READ)
1525
1526 def recall06_test(self):
1527 """Recall write delegation by reading from a second client with file lock"""
1528 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_READ, lock=True)
1529
1530 def recall07_test(self):
1531 """Recall read delegation by changing the permissions to the file"""
1532 self.recall_deleg_test(OPEN_READ, conflict_type=OP_SETATTR)
1533
1534 def recall08_test(self):
1535 """Recall write delegation by changing the permissions to the file"""
1536 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_SETATTR)
1537
1538 def recall09_test(self):
1539 """Recall read delegation by changing the permissions to the file with file lock"""
1540 self.recall_deleg_test(OPEN_READ, conflict_type=OP_SETATTR, lock=True)
1541
1542 def recall10_test(self):
1543 """Recall write delegation by changing the permissions to the file with file lock"""
1544 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_SETATTR, lock=True)
1545
1546 def recall11_test(self):
1547 """Recall read delegation by removing the file"""
1548 self.recall_deleg_test(OPEN_READ, conflict_type=OP_REMOVE, nfiles=1)
1549
1550 def recall12_test(self):
1551 """Recall write delegation by removing the file"""
1552 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_REMOVE, nfiles=1)
1553
1554 def recall13_test(self):
1555 """Recall read delegation by removing the file with file lock"""
1556 self.recall_deleg_test(OPEN_READ, conflict_type=OP_REMOVE, nfiles=1, lock=True)
1557
1558 def recall14_test(self):
1559 """Recall write delegation by removing the file with file lock"""
1560 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_REMOVE, nfiles=1, lock=True)
1561
1562 def recall15_test(self):
1563 """Recall read delegation by renaming the file"""
1564 self.recall_deleg_test(OPEN_READ, conflict_type=OP_RENAME, nfiles=1)
1565
1566 def recall16_test(self):
1567 """Recall write delegation by renaming the file"""
1568 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_RENAME, nfiles=1)
1569
1570 def recall17_test(self):
1571 """Recall read delegation by renaming the file with file lock"""
1572 self.recall_deleg_test(OPEN_READ, conflict_type=OP_RENAME, nfiles=1, lock=True)
1573
1574 def recall18_test(self):
1575 """Recall write delegation by renaming the file with file lock"""
1576 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_RENAME, nfiles=1, lock=True)
1577
1578 def recall19_test(self):
1579 """Recall read delegation by renaming into the file"""
1580 self.recall_deleg_test(OPEN_READ, conflict_type=OP_RENAME, nfiles=2, target=True)
1581
1582 def recall20_test(self):
1583 """Recall write delegation by renaming into the file"""
1584 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_RENAME, nfiles=2, target=True)
1585
1586 def recall21_test(self):
1587 """Recall read delegation by renaming into the file with file lock"""
1588 self.recall_deleg_test(OPEN_READ, conflict_type=OP_RENAME, nfiles=2, target=True, lock=True)
1589
1590 def recall22_test(self):
1591 """Recall write delegation by renaming into the file with file lock"""
1592 self.recall_deleg_test(OPEN_WRITE, conflict_type=OP_RENAME, nfiles=2, target=True, lock=True)
1593
1594 def recall23_test(self):
1595 """Recall read delegation by writing from a second client with file lock,
1596 having a pending read open"""
1597 self.recall_deleg_test(OPEN_READ, claim_cur=os.O_RDONLY, lock=True)
1598
1599 def recall24_test(self):
1600 """Recall read delegation by writing from a second client with file lock,
1601 having a pending write open.
1602 Delegation is returned by the client when the second open is done so
1603 there is no delegation recall"""
1604 self.recall_deleg_test(OPEN_READ, claim_cur=os.O_WRONLY, lock=True)
1605
1606 def recall25_test(self):
1607 """Recall write delegation by writing from a second client with file lock,
1608 having a pending read open"""
1609 self.recall_deleg_test(OPEN_WRITE, claim_cur=os.O_RDONLY, lock=True)
1610
1611 def recall26_test(self):
1612 """Recall write delegation by writing from a second client with file lock,
1613 having a pending write open"""
1614 self.recall_deleg_test(OPEN_WRITE, claim_cur=os.O_WRONLY, lock=True)
1615
1616 def recall27_test(self):
1617 """Recall write delegation by reading from a second client using RDWR
1618 open while reading"""
1619 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_READ)
1620
1621 def recall28_test(self):
1622 """Recall write delegation by reading from a second client using RDWR
1623 open while writing"""
1624 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_READ)
1625
1626 def recall29_test(self):
1627 """Recall write delegation by writing from a second client using RDWR
1628 open while reading"""
1629 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_WRITE)
1630
1631 def recall30_test(self):
1632 """Recall write delegation by writing from a second client using RDWR
1633 open while writing"""
1634 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_WRITE)
1635
1636 def recall31_test(self):
1637 """Recall write delegation by reading from a second client using RDWR
1638 open while reading with file lock"""
1639 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_READ, lock=True)
1640
1641 def recall32_test(self):
1642 """Recall write delegation by reading from a second client using RDWR
1643 open while writing with file lock"""
1644 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_READ, lock=True)
1645
1646 def recall33_test(self):
1647 """Recall write delegation by writing from a second client using RDWR
1648 open while reading with file lock"""
1649 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_WRITE, lock=True)
1650
1651 def recall34_test(self):
1652 """Recall write delegation by writing from a second client using RDWR
1653 open while writing with file lock"""
1654 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_WRITE, lock=True)
1655
1656 def recall35_test(self):
1657 """Recall write delegation by changing the permissions to the file
1658 from a second client using RDWR open while reading"""
1659 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_SETATTR)
1660
1661 def recall36_test(self):
1662 """Recall write delegation by changing the permissions to the file
1663 from a second client using RDWR open while writing"""
1664 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_SETATTR)
1665
1666 def recall37_test(self):
1667 """Recall write delegation by changing the permissions to the file
1668 from a second client using RDWR open while reading with file lock"""
1669 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_SETATTR, lock=True)
1670
1671 def recall38_test(self):
1672 """Recall write delegation by changing the permissions to the file
1673 from a second client using RDWR open while writing with file lock"""
1674 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_SETATTR, lock=True)
1675
1676 def recall39_test(self):
1677 """Recall write delegation by removing the file from a second client
1678 using RDWR open while reading"""
1679 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_REMOVE, nfiles=1)
1680
1681 def recall40_test(self):
1682 """Recall write delegation by removing the file from a second client
1683 using RDWR open while writing"""
1684 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_REMOVE, nfiles=1)
1685
1686 def recall41_test(self):
1687 """Recall write delegation by removing the file from a second client
1688 using RDWR open while reading with file lock"""
1689 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_REMOVE, nfiles=1, lock=True)
1690
1691 def recall42_test(self):
1692 """Recall write delegation by removing the file from a second client
1693 using RDWR open while writing with file lock"""
1694 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_REMOVE, nfiles=1, lock=True)
1695
1696 def recall43_test(self):
1697 """Recall write delegation by renaming the file from a second client
1698 using RDWR open while reading"""
1699 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_RENAME, nfiles=1)
1700
1701 def recall44_test(self):
1702 """Recall write delegation by renaming the file from a second client
1703 using RDWR open while writing"""
1704 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_RENAME, nfiles=1)
1705
1706 def recall45_test(self):
1707 """Recall write delegation by renaming the file from a second client
1708 using RDWR open while reading with file lock"""
1709 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_RENAME, nfiles=1, lock=True)
1710
1711 def recall46_test(self):
1712 """Recall write delegation by renaming the file from a second client
1713 using RDWR open while writing with file lock"""
1714 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_RENAME, nfiles=1, lock=True)
1715
1716 def recall47_test(self):
1717 """Recall write delegation by renaming the file from a second client
1718 using RDWR open while reading"""
1719 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_RENAME, nfiles=2, target=True)
1720
1721 def recall48_test(self):
1722 """Recall write delegation by renaming the file from a second client
1723 using RDWR open while writing"""
1724 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_RENAME, nfiles=2, target=True)
1725
1726 def recall49_test(self):
1727 """Recall write delegation by renaming the file from a second client
1728 using RDWR open while reading with file lock"""
1729 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, conflict_type=OP_RENAME, nfiles=2, target=True, lock=True)
1730
1731 def recall50_test(self):
1732 """Recall write delegation by renaming the file from a second client
1733 using RDWR open while writing with file lock"""
1734 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, conflict_type=OP_RENAME, nfiles=2, target=True, lock=True)
1735
1736 def recall51_test(self):
1737 """Recall write delegation by writing from a second client using RDWR
1738 open while reading with file lock, having a pending read open"""
1739 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, claim_cur=os.O_RDONLY, lock=True)
1740
1741 def recall52_test(self):
1742 """Recall write delegation by writing from a second client using RDWR
1743 open while reading with file lock, having a pending write open"""
1744 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_READ, claim_cur=os.O_WRONLY, lock=True)
1745
1746 def recall53_test(self):
1747 """Recall write delegation by writing from a second client using RDWR
1748 open while writing with file lock, having a pending read open"""
1749 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, claim_cur=os.O_RDONLY, lock=True)
1750
1751 def recall54_test(self):
1752 """Recall write delegation by writing from a second client using RDWR
1753 open while writing with file lock, having a pending write open"""
1754 self.recall_deleg_test(OPEN_RDWR, io_type=OPEN_WRITE, claim_cur=os.O_WRONLY, lock=True)
1755
1756 ################################################################################
1757 # Entry point
1758 x = DelegTest(usage=USAGE, testnames=TESTNAMES, testgroups=TESTGROUPS, sid=SCRIPT_ID)
1759
1760 try:
1761 x.setup()
1762
1763 # Run all the tests
1764 x.run_tests()
1765 except Exception:
1766 x.test(False, traceback.format_exc())
1767 finally:
1768 if x.clientobj is not None and x.clientobj.mounted:
1769 # Unmount server on remote client
1770 x.clientobj.umount()
1771 x.cleanup()
1772 x.exit()