Debian Codegraph @

test/nfstest_pnfs

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 math
17 import time
18 import fcntl
19 import struct
20 import traceback
21 import nfstest_config as c
22 from packet.nfs.nfs4_const import *
23 from formatstr import ordinal_number
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.5"
31
32 USAGE = """%prog --server <server> [options]
33
34 Basic pNFS functional tests
35 ===========================
36 Verify basic pNFS functionality for file (both READ and WRITE), including
37 opening a second file within the same mount and having a lock on the file.
38 Also, verify basic pNFS functionality for a file opened for both READ and
39 WRITE while reading the file first and then writing to it or the other way
40 around by writing to the file fist and then reading the file. These tests
41 verify proper functionality of pNFS and NFSv4.1 as well.
42
43 Examples:
44 The only required option is --server
45 $ %prog --server 192.168.0.11
46
47 Notes:
48 The user id in the local host must have access to run commands as root
49 using the 'sudo' command without the need for a password."""
50
51 # Test script ID
52 SCRIPT_ID = "PNFS"
53
54 TESTNAMES = [
55 'read',
56 'write',
57 'read_write',
58 'write_read',
59 'read_lock',
60 'write_lock',
61 'setattr',
62 'setattr_lock',
63 'rw_read',
64 'rw_write',
65 #'read_holes',
66 'one_ds',
67 'rsize',
68 'wsize',
69 'rwsize',
70 'nfsvers',
71 ]
72
73 class pNFSTest(TestUtil):
74 """pNFSTest object
75
76 pNFSTest() -> New test object
77
78 Usage:
79 x = pNFSTest()
80
81 # Verify pNFS functionality for file given by filename
82 x.verify_file(filename, iomode)
83
84 # Verify pNFS functionality for file given by openfh structure on all DS's
85 x.verify_pnfs_functionality(openfh, iomode, filesize, multipath_ds_list, newgetdev, nocreate, nocreate_list, write_list)
86
87 # Verify DESTROY_SESSION should be sent to MDS and all DS's on umount
88 x.verify_destroy_session()
89
90 # Verify client only connects to the DS with I/O -- writing to first stripe only
91 x.verify_ds_connect_needed(layout, multipath_ds_list, ds_index=0)
92
93 # Verify client only connects to the DS with I/O -- writing to second stripe only
94 x.verify_ds_connect_needed(layout, multipath_ds_list, ds_index=1)
95
96 x.exit()
97 """
98 def __init__(self, **kwargs):
99 """Constructor
100
101 Initialize object's private data.
102 """
103 TestUtil.__init__(self, **kwargs)
104 self.opts.version = "%prog " + __version__
105 self.scan_options()
106
107 # Disable createtraces option
108 self.createtraces = False
109
110 self.deviceids = {}
111 self.stripe_size = None
112 if self.nfs_version < 4.1:
113 self.config("Cannot use %s for pNFS testing" % self.nfsstr())
114
115 def get_ds_io_list(self, offset, size, nds):
116 """Get a list of DS's where I/O is sent"""
117 stripe_size = self.layout['stripe_size']
118 first_index = self.layout['first_stripe_index']
119
120 # Get first DS index where I/O is sent
121 N = (first_index + int(offset / stripe_size)) % nds
122 # Get last DS index + 1
123 M = int(math.ceil((1.0*offset+size) / stripe_size))
124 M = (first_index + M) % nds
125
126 ds_io_list = []
127 if (size > 0 and M == N) or (nds > 1 and size > (nds-1)*stripe_size):
128 # Size is large enough to read/write to all DS's
129 ds_io_list += [True for i in range(nds)]
130 elif M < N:
131 # Wrapped around
132 ds_io_list += [True for i in range(M)]
133 ds_io_list += [False for i in range(N-M)]
134 ds_io_list += [True for i in range(nds-N)]
135 else:
136 ds_io_list += [False for i in range(N)]
137 ds_io_list += [True for i in range(M-N)]
138 ds_io_list += [False for i in range(nds-M)]
139 return ds_io_list
140
141 def verify_stateid(self, openfh, sent_stateid):
142 """Return expected stateid of I/O and verify it with stateid sent
143 and return strings indicating which stateid is expected and
144 which stateid was actually sent.
145 """
146 open_stateid = openfh['open_stateid']
147 lock_stateid = openfh['lock_stateid']
148 deleg_stateid = openfh['deleg_stateid']
149 stateid_map = {
150 open_stateid: "OPEN",
151 lock_stateid: "LOCK",
152 deleg_stateid: "DELEG",
153 }
154
155 if deleg_stateid is not None:
156 stateid = deleg_stateid
157 stid_str = 'DELEG'
158 elif lock_stateid is not None:
159 stateid = lock_stateid
160 stid_str = 'LOCK'
161 else:
162 stateid = open_stateid
163 stid_str = 'OPEN'
164
165 stid_failmsg = None
166 if sent_stateid != None:
167 stid = stateid_map.get(sent_stateid, None)
168 if stid != None:
169 stid_failmsg = " - (not the %s stateid)" % stid
170
171 return (stateid, stid_str, stid_failmsg)
172
173 def verify_pnfs_functionality(self, openfh, iomode, filesize, multipath_ds_list, newgetdev=False, nocreate=False, nocreate_list=[], write_list=[], max_iosize=None, nmax_iosize=None):
174 """Verify pNFS functionality traffic going to the data servers.
175 It checks traffic to all DS's (EXCHANGE_ID, CREATE_SESSION,
176 READ/WRITE, COMMIT and LAYOUTCOMMIT).
177
178 openfh:
179 Open information for file (filehandle, open/delegation/lock
180 stateids, and delegation type)
181 iomode:
182 Expected iomode for layoutget
183 filesize:
184 File size used to verify correct LAYOUTCOMMIT last write offset
185 and GETATTR file size
186 multipath_ds_list:
187 List of DS's as returned by GETDEVICEINFO
188 newgetdev:
189 Get new device info [default: False]
190 nocreate:
191 Used to verify the client does not connect to MDS nor any DS
192 when set to True [default: False]
193 Option nocreate_list overwrites this value when checking DS's
194 nocreate_list:
195 List of booleans to control which DS the client does not connect.
196 Used when expecting the client to connect only to certain DS's
197 and not all [default: []]
198 write_list:
199 List of booleans to control which DS the client writes to.
200 Used when expecting write traffic only to certain DS's and
201 not all [default: []]
202 max_iosize:
203 Maximum number of bytes expected in each request [default: None]
204 nmax_iosize:
205 The number of bytes expected in each request should not be
206 restricted by this [default: None]
207 """
208 # Save current packet index
209 save_index = self.pktt.get_index()
210 self.writeverf = None
211 self.need_commit = False
212 self.need_lcommit = False
213 self.mdsd_lcommit = False
214 self.test_seqid = True
215 self.test_stateid = True
216 self.test_pattern = True
217 self.test_niomiss = 0
218 self.test_stripe = True
219 self.test_verf = True
220 self.max_iosize = 0
221 self.error_hash = {}
222 self.test_commit_full = True
223 self.test_commit_verf = True
224 self.test_no_commit = False
225 self.stateid = None
226 test_pattern = True
227 io_str = 'READ' if iomode == LAYOUTIOMODE4_READ else 'WRITE'
228 io_op = OP_READ if iomode == LAYOUTIOMODE4_READ else OP_WRITE
229
230 if self.layout is None or self.layout.get('dense') is None:
231 return
232
233 layout_dense = 'dense' if self.layout['dense'] else 'sparse'
234 filehandle = openfh['filehandle']
235
236 # Get expected stateid
237 (stateid, stid_str, stid_failmsg) = self.verify_stateid(openfh, self.stateid)
238
239 # Get number of DS's in layout
240 nds = len(multipath_ds_list)
241
242 # Check if file size is big enough to send traffic to all DS's
243 self.dprint('DBG2', "Number of DataServers %d" % nds)
244 self.dprint('DBG2', "Stripe size %d" % self.layout['stripe_size'])
245 self.dprint('DBG2', "First stripe index %d" % self.layout['first_stripe_index'])
246 self.dprint('DBG2', "Using %s layouts" % layout_dense)
247 self.dprint('DBG2', "Commit thru MDS is %s" % self.layout['commit_mds'])
248 self.dprint('DBG2', "Device ID: 0x%s" % self.layout['deviceid'])
249 if filesize < (nds-1) * self.layout['stripe_size'] + 1:
250 N = int(filesize / (self.layout['stripe_size'] + 1)) + 1
251 if len(nocreate_list) == 0:
252 nocreate_list = [False for i in range(N)]
253 nocreate_list += [True for i in range(N, nds)]
254 if len(write_list) == 0:
255 write_list = [True for i in range(N)]
256 write_list += [False for i in range(N, nds)]
257 self.warning("File size is too small to send traffic to all DS's")
258
259 if write_list:
260 # Find max ds index
261 nds = 0
262 index = 0
263 for item in write_list:
264 if item:
265 nds = index
266 index += 1
267
268 ds_index = 0
269 dsio_list = []
270 for ds_list in multipath_ds_list:
271 ds_traffic = False
272 dsio_list.append(0)
273 for item in ds_list:
274 if not self.layout['commit_mds']:
275 self.writeverf = None
276
277 # Get ip address and port for DS
278 ipaddr, port = self.get_addr_port(item.addr)
279 self.dprint('DBG2', "DataServer(%d) ipaddr: %s, port: %d" % (ds_index, ipaddr, port))
280
281 # Rewind trace file to saved packet index
282 self.pktt.rewind(save_index)
283
284 if nocreate_list:
285 # nocreate_list takes precedence over newgetdev
286 newgetdev = False
287 nocreate = nocreate_list[ds_index]
288
289 if len(ds_list) > 1:
290 # Mulipath DS, so find out if any address on given
291 # DS has any traffic
292 (pktcall, pktreply) = self.find_nfs_op(io_op, ipaddr=ipaddr, port=port)
293 if pktcall:
294 ds_traffic = True
295 self.pktt.rewind(save_index)
296 elif ds_traffic or item != ds_list[-1]:
297 continue
298
299 # Verify NFSv4.1 create session to DS
300 self.verify_create_session(ipaddr, port, ds=True, nocreate=(nocreate and not newgetdev), ds_index=ds_index)
301 if self.sessionid:
302 self.session_ids[self.sessionid] = "DS(%d)" % ds_index
303
304 # Find all I/O requests and replies for current DS
305 self.test_pattern = True
306 nio = self.verify_io(iomode, stateid, ipaddr, port, ds_index=ds_index)
307 dsio_list[ds_index] += nio
308 if len(write_list) > 0:
309 if write_list[ds_index] and not self.test_pattern:
310 test_pattern = False
311 elif not self.test_pattern:
312 test_pattern = False
313
314 if not self.layout['commit_mds']:
315 # Rewind trace file to saved packet index
316 self.pktt.rewind(save_index)
317
318 # Verify commits
319 self.verify_commit(ipaddr, port, self.get_filehandle(ds_index))
320 ds_index += 1
321
322 if len(write_list) == 0:
323 # Option is not given so expect writes to all DS's
324 write_list = [True for i in range(ds_index)]
325
326 do_write = True
327 no_write = True
328 index = 0
329 nio_total = 0
330 for nio in dsio_list:
331 if write_list[index] and nio == 0:
332 do_write = False
333 elif not write_list[index] and nio > 0:
334 no_write = False
335 index += 1
336 nio_total += nio
337 if nio_total == 0:
338 if iomode == LAYOUTIOMODE4_READ and stid_str == 'DELEG' and openfh['deleg_type'] == OPEN_DELEGATE_WRITE:
339 self.test(True, "%s should not be sent to DS when holding a write delegation" % io_str)
340 elif openfh.get('dtcached'):
341 self.test(True, "%s should not be sent to DS if data has been cached" % io_str)
342 else:
343 self.test(False, "%s should have been sent to at least one DS" % io_str)
344 return
345
346 for err in self.error_hash:
347 self.test(False, "%s fails with %s, number of failures found: %d" % (io_str, err, self.error_hash[err]))
348
349 # Get stateid messages
350 (stateid, stid_str, stid_failmsg) = self.verify_stateid(openfh, self.stateid)
351
352 self.test(do_write and no_write, "%s should only be sent to the DS with I/O" % io_str)
353 self.test(self.test_seqid, "%s stateid seqid should be 0" % io_str)
354 self.test(self.test_stateid, "%s stateid should be the %s stateid" % (io_str, stid_str), failmsg=stid_failmsg)
355 if nio_total - self.test_niomiss > 0:
356 self.test(test_pattern, "%s data should be correct for the given DS and offset" % io_str)
357 self.test(self.test_stripe, "%s offset and server/fh should be correct for %s layouts" % (io_str, layout_dense))
358 if max_iosize != None:
359 rsize = "rsize" if iomode == LAYOUTIOMODE4_READ else "wsize"
360 self.test(self.max_iosize <= max_iosize, "%s bytes in each packet should be less than or equal to mount option %s" % (io_str, rsize))
361 elif nmax_iosize != None:
362 rsize = "wsize" if iomode == LAYOUTIOMODE4_READ else "rsize"
363 self.test(self.max_iosize > nmax_iosize, "%s bytes in each packet should not be restricted by mount option %s" % (io_str, rsize))
364 if iomode == LAYOUTIOMODE4_RW:
365 self.test(self.test_verf, "WRITE verifier should be the same between write calls for given DS")
366
367 if self.layout['commit_mds']:
368 # Commit thru MDS
369 self.pktt.rewind(save_index)
370 self.verify_commit(self.server_ipaddr, self.port, filehandle)
371 if self.need_commit:
372 self.test(self.test_commit_full, "COMMIT should commit full file to MDS when NFL4_UFLG_COMMIT_THRU_MDS is set")
373 self.test(self.test_commit_verf, "COMMIT should be sent with WRITE writeverf to MDS when NFL4_UFLG_COMMIT_THRU_MDS is set")
374 else:
375 self.test(self.test_no_commit, "COMMIT should not be sent (DATA_SYNC4 or FILE_SYNC4)")
376
377 # Make sure no COMMITs are sent to any DS
378 ds_index = 0
379 ncommits = 0
380 for ds_list in multipath_ds_list:
381 for item in ds_list:
382 # Get ip address and port for DS
383 ipaddr, port = self.get_addr_port(item.addr)
384
385 # Rewind trace file to saved packet index
386 self.pktt.rewind(save_index)
387
388 # Verify commits to DS
389 ncommits += self.verify_commit(ipaddr, port, self.get_filehandle(ds_index))
390
391 ds_index += 1
392
393 self.test(ncommits == 0, "COMMIT should not be sent to any DS when NFL4_UFLG_COMMIT_THRU_MDS is set")
394 else:
395 # Commit thru DS
396 if self.need_commit:
397 self.test(self.test_commit_full, "COMMIT should commit full file for given DS")
398 self.test(self.test_commit_verf, "COMMIT should be sent with WRITE writeverf for given DS")
399 else:
400 self.test(self.test_no_commit, "COMMIT should not be sent (DATA_SYNC4 or FILE_SYNC4)")
401 # Make sure no COMMITs are sent to the MDS
402 self.pktt.rewind(save_index)
403 ncommits = self.verify_commit(self.server_ipaddr, self.port, filehandle)
404 self.test(ncommits == 0, "COMMIT should not be sent to MDS when NFL4_UFLG_COMMIT_THRU_MDS is not set")
405
406 # Rewind trace file to saved packet index
407 self.pktt.rewind(save_index)
408
409 # Verify LAYOUTCOMMIT
410 self.verify_layoutcommit(filehandle, filesize)
411
412 def verify_file(self, filename, iomode, **kwargs):
413 """Verify pNFS functionality for file given by filename. It checks
414 traffic to MDS (EXCHANGE_ID, CREATE_SESSION, OPEN, LAYOUTGET,
415 GETDEVICEINFO) taking into account if file has already been
416 opened before within the same session. Then it calls method
417 x.verify_pnfs_functionality() to verify pNFS functionality traffic
418 going to the data servers.
419
420 filename:
421 Verify pNFS functionality of traffic given by this file name
422 iomode:
423 Expected iomode for layoutget
424 filesize:
425 File size used to verify correct LAYOUTCOMMIT last write offset
426 and GETATTR file size [default: --filesize option]
427 multipath_ds_list:
428 List of DS's as returned by GETDEVICEINFO [default: []]
429 nolayoutget:
430 Verify that LAYOUTGET is not sent
431 nocreate:
432 Used to verify the client does not connect to MDS nor any DS
433 when set to True [default: False]
434 Option nocreate_list overwrites this value when checking DS's
435 nocreate_list:
436 List of booleans to control which DS the client does not connect.
437 Used when expecting the client to connect only to certain DS's
438 and not all [default: []]
439 write_list:
440 List of booleans to control which DS the client writes to.
441 Used when expecting write traffic only to certain DS's and
442 not all [default: []]
443 lock:
444 Find LOCK packets [default: False]
445 layout_stateid:
446 Stateid to use on LAYOUTGET [default: open/delegation stateid]
447 openfh:
448 Open information for file (filehandle, open/delegation/lock stateids,
449 and delegation type) if file has been previously opened [default: {}]
450 max_iosize:
451 Maximum number of bytes expected in each request [default: None]
452 nmax_iosize:
453 The number of bytes expected in each request should not be
454 restricted by this [default: None]
455 noclose:
456 Do not verify a CLOSE if true [default: False]
457 delegreturn:
458 Find DELEGRETURN request [default: False]
459 verify_close:
460 Verify file close [default: True]
461 offset:
462 Verify file for I/O starting at this offset [default: None]
463 size:
464 Size of I/O when offset option is given [default: None]
465
466 Return a tuple (multipath_ds_list, openfh).
467 """
468 # Process named arguments
469 filesize = kwargs.pop('filesize', self.filesize)
470 multipath_ds_list = kwargs.pop('multipath_ds_list', [])
471 nolayoutget = kwargs.pop('nolayoutget', False)
472 nocreate = kwargs.pop('nocreate', False)
473 nocreate_list = kwargs.pop('nocreate_list', [])
474 write_list = kwargs.pop('write_list', [])
475 lock = kwargs.pop('lock', False)
476 layout_stateid = kwargs.pop('layout_stateid', None)
477 openfh = kwargs.pop('openfh', {})
478 max_iosize = kwargs.pop('max_iosize', None)
479 nmax_iosize = kwargs.pop('nmax_iosize', None)
480 noclose = kwargs.pop('noclose', False)
481 delegreturn = kwargs.pop('delegreturn', False)
482 verify_close = kwargs.pop('verify_close', True)
483 offset = kwargs.pop('offset', None)
484 size = kwargs.pop('size', None)
485
486 self.session_ids = {}
487
488 if len(multipath_ds_list) == 0:
489 # Clear list of device ids
490 self.deviceids = {}
491
492 if not nocreate:
493 # Verify NFSv4.1 create session to MDS
494 self.verify_create_session(self.server_ipaddr, self.port)
495 if self.sessionid:
496 self.session_ids[self.sessionid] = "MDS"
497
498 # Find OPEN request
499 (filehandle, open_stateid, deleg_stateid) = self.find_open(filename=filename, claimfh=openfh.get('fh'), anyclaim=True)
500 if deleg_stateid:
501 deleg_type = self.pktt.pkt.NFSop.delegation.deleg_type
502 else:
503 deleg_type = iomode
504 if 'filehandle' in openfh:
505 self.test(not filehandle, "OPEN should not be sent for the same file")
506 filehandle = openfh['filehandle']
507 open_stateid = openfh['open_stateid']
508 deleg_stateid = openfh['deleg_stateid']
509 deleg_type = openfh['deleg_type']
510 else:
511 self.test(filehandle, "OPEN should be sent")
512 if filehandle:
513 openfh['filehandle'] = filehandle
514 openfh['open_stateid'] = open_stateid
515 openfh['deleg_stateid'] = deleg_stateid
516 openfh['deleg_type'] = deleg_type
517
518 lock_stateid = None
519 if lock:
520 (pktcall, pktreply) = self.find_nfs_op(OP_LOCK)
521 if deleg_stateid is None:
522 self.test(pktcall, "LOCK should be sent")
523 if pktcall:
524 if pktreply:
525 lock_stateid = pktreply.NFSop.stateid.other
526 else:
527 self.test(False, "LOCK reply was not found")
528 else:
529 self.test(pktcall is None, "LOCK should not be sent -- delegation has been granted")
530 else:
531 lock_stateid = None
532 openfh['lock_stateid'] = lock_stateid
533
534 # Find LAYOUTGET request
535 openfh['nolayoutget'] = nolayoutget
536 openfh['layout_stateid'] = layout_stateid
537 if not self.verify_layoutget(filehandle, iomode, openfh=openfh):
538 return (multipath_ds_list, openfh)
539 nolayoutget = openfh['nolayoutget']
540
541 need_getdev = False
542 if not nolayoutget and not (self.layout['deviceid'] in self.deviceids):
543 need_getdev = True
544
545 if self.layout and not nolayoutget:
546 # Added to the list of deviceids
547 self.deviceids[self.layout['deviceid']] = True
548 # Find GETDEVICEINFO request
549 (pktcall, pktreply, dslist) = self.find_getdeviceinfo(deviceid=self.layout['deviceid'], usecache=False)
550
551 # Test GETDEVICEINFO for correct layout type
552 if nolayoutget:
553 # Expecting no LAYOUTGET and thus no GETDEVICEINFO
554 pass
555 elif nocreate and not need_getdev:
556 # Verify GETDEVICEINFO is not sent again
557 msg = 'the same' if 'samefile' in openfh else 'second'
558 self.test(not pktcall, "GETDEVICEINFO should not be sent for %s file" % msg)
559 else:
560 msg = ' for new deviceid' if nocreate else ''
561 self.test(pktcall, "GETDEVICEINFO should be sent%s" % msg)
562 if not pktcall:
563 devinfo = self.device_info.get(self.layout['deviceid'])
564 if devinfo:
565 self.dprint('DBG3', "Using cached values for GETDEVICEINFO")
566 pktcall = devinfo['call']
567 pktreply = devinfo['reply']
568 if pktcall:
569 xid = pktcall.rpc.xid
570 self.test(pktcall.NFSop.type == LAYOUT4_NFSV4_1_FILES, "GETDEVICEINFO layout type should be LAYOUT4_NFSV4_1_FILES")
571 if getattr(self, 'ca_maxrespsz', None) is not None:
572 tmsg = "GETDEVICEINFO maxcount should be less than or equal to max_response_size in CREATE_SESSION reply"
573 fmsg = " - (%d > %d)" % (pktcall.NFSop.maxcount, self.ca_maxrespsz)
574 self.test(pktcall.NFSop.maxcount <= self.ca_maxrespsz, tmsg, failmsg=fmsg)
575
576 # Find GETDEVICEINFO reply
577 if pktreply:
578 if pktreply.nfs.status:
579 self.test(False, "GETDEVICEINFO returned %s(%d)" % (nfsstat4[pktreply.nfs.status], pktreply.nfs.status))
580 else:
581 gdir_device = pktreply.NFSop.device_addr
582
583 # Test GETDEVICEINFO reply for correct layout type
584 self.test(gdir_device.type == LAYOUT4_NFSV4_1_FILES, "GETDEVICEINFO reply layout type should be LAYOUT4_NFSV4_1_FILES")
585
586 da_addr_body = gdir_device.body
587 self.stripe_indices = da_addr_body.stripe_indices
588 nindices = len(self.stripe_indices)
589 mp_ds_list = da_addr_body.multipath_ds_list
590 ds_index = 0
591 if multipath_ds_list:
592 # Make sure only connect to dataservers which have
593 # not yet connected -- when the deviceid is
594 # different but has some dataservers which have
595 # a connection already
596 need_getdev = False
597 for ds_list in mp_ds_list:
598 for dsentry in ds_list:
599 dsfound = False
600 if len(nocreate_list) <= ds_index:
601 nocreate_list.append(nocreate)
602 for dslist in multipath_ds_list:
603 for ds_entry in dslist:
604 if dsentry.netid == ds_entry.netid and dsentry.addr == ds_entry.addr:
605 dsfound = True
606 if not dsfound:
607 nocreate_list[ds_index] = False
608 ds_index += 1
609 multipath_ds_list = mp_ds_list
610 else:
611 self.test(False, "GETDEVICEINFO reply was not found")
612
613 # Save current packet index
614 save_index = self.pktt.get_index()
615
616 if not nolayoutget or 'samefile' in openfh:
617 if len(write_list) == 0 and offset is not None and size is not None:
618 nds = len(multipath_ds_list)
619 if nds > 1:
620 write_list = self.get_ds_io_list(offset, size, nds)
621 nocreate_list = [not x for x in write_list]
622 self.verify_pnfs_functionality(openfh, iomode, filesize, multipath_ds_list, need_getdev, nocreate, nocreate_list, write_list, max_iosize, nmax_iosize)
623 # Rewind trace file to saved packet index
624 self.pktt.rewind(save_index)
625
626 if verify_close:
627 self.verify_close(openfh, delegreturn, noclose)
628
629 return (multipath_ds_list, openfh)
630
631 def verify_close(self, openfh, delegreturn, noclose):
632 # Save current packet index
633 save_index = self.pktt.get_index()
634 filehandle = openfh['filehandle']
635 open_stateid = openfh['open_stateid']
636 deleg_stateid = openfh['deleg_stateid']
637 fhandlestr = "NFS.fh == b'%s'" % self.pktt.escape(filehandle)
638
639 if delegreturn:
640 # Find DELEGRETURN request
641 (pktcall, pktreply) = self.find_nfs_op(OP_DELEGRETURN, match=fhandlestr)
642 if pktcall:
643 self.test(pktcall.NFSop.stateid == deleg_stateid, "DELEGRETURN should use the delegation stateid")
644 else:
645 self.test(False, "DELEGRETURN should be sent")
646 elif not noclose:
647 # Find CLOSE request
648 (pktcall, pktreply) = self.find_nfs_op(OP_CLOSE, match=fhandlestr)
649 if pktcall:
650 self.test(pktcall.NFSop.stateid == open_stateid, "CLOSE should use the open stateid")
651 else:
652 self.test(False, "CLOSE should be sent")
653
654 # Find if there is a DELEGRETURN
655 self.pktt.rewind(save_index)
656 (pktcall, pktreply) = self.find_nfs_op(OP_DELEGRETURN, match=fhandlestr)
657 if pktcall:
658 # Delegation has been returned
659 self.test(pktcall.NFSop.stateid == deleg_stateid, "DELEGRETURN should use the delegation stateid")
660
661 # Rewind trace file to saved packet index
662 self.pktt.rewind(save_index)
663
664 def verify_destroy_session(self):
665 """Verify DESTROY_SESSION should be sent to MDS and all DS's on umount."""
666 # Find all DESTROY_SESSION requests
667 xids = {}
668 if len(self.session_ids) == 0:
669 self.test(False, "No session ids to look for on DESTROY_SESSION")
670 return
671 while self.pktt.match("NFS.argop == %d" % OP_DESTROY_SESSION, reply=True):
672 pkt = self.pktt.pkt
673 if pkt.rpc.type == 0:
674 sessionid = pkt.NFSop.sessionid
675 server = self.session_ids.pop(sessionid, None)
676 if server is not None:
677 xids[pkt.rpc.xid] = server
678 self.test(True, "DESTROY_SESSION should be sent to %s on umount" % server)
679 else:
680 xid = pkt.rpc.xid
681 server = xids.pop(xid, None)
682 if server is not None:
683 fmsg = " - failed with %s(%d)" % (pkt.nfs.status, pkt.nfs.status)
684 self.test(pkt.nfs.status == 0, "DESTROY_SESSION should succeed for %s" % server, failmsg=fmsg)
685 for server in self.session_ids.values():
686 self.test(False, "DESTROY_SESSION should be sent to %s on umount" % server)
687 if len(xids) > 0:
688 self.test(False, "Could not find all replies to DESTROY_SESSION")
689
690 def nfsvers_test(self):
691 """Verify file created with pNFS is read correctly from different versions
692 of NFS. Also, verify files created with different versions of NFS are
693 read correctly from pNFS
694 """
695 if self.nii_server[:5] == 'pynfs':
696 # pyNFS does not support different versions of NFS
697 run_test = False
698 if len(self.testlist) > 1:
699 return
700 else:
701 run_test = True
702
703 self.test_group("Verify file created with pNFS is read correctly from different versions of NFS")
704 if not run_test:
705 self.test(False, "pyNFS does not support different versions of NFS")
706 return
707
708 try:
709 self.trace_start()
710 testfile = self.abspath(self.files[0])
711 orig_data = self.data_pattern(0, self.filesize)
712 files = []
713 vers = []
714 for version in (4.0, 3):
715 try:
716 self.umount()
717 self.mount(nfsversion=version)
718 except Exception:
719 if version == 4.0 and self.perror.find("incorrect mount option") >= 0:
720 try:
721 self.dprint('DBG4', "NFSv4 mount using vers=4.0 is not supported, using vers=4 instead")
722 self.mount(nfsversion=4)
723 except Exception:
724 pass
725 if self.returncode:
726 self.warning(self.perror)
727 continue
728
729 ver = self.nfsstr(version)
730 vers.append(ver)
731
732 fstat = os.stat(testfile)
733 self.test(fstat.st_size == self.filesize, "Size of file on %s should be correct" % ver, failmsg=", expecting %d and got %d" % (self.filesize, fstat.st_size))
734 self.dprint('DBG2', "Read file %s @0" % testfile)
735 fd = open(testfile, "rb")
736 try:
737 data = fd.read()
738 finally:
739 fd.close()
740 self.test(data == orig_data, "Data written using pNFS is read correctly from %s" % ver)
741
742 # Create file using current NFS version
743 self.create_file(dlevels=['DBG1'])
744 files.append(self.absfile)
745 self.umount()
746 except Exception:
747 self.test(False, traceback.format_exc())
748 finally:
749 self.trace_stop()
750 self.trace_open()
751 self.pktt.close()
752
753 self.test_group("Verify files created with different versions of NFS are read correctly from pNFS")
754 try:
755 self.mount()
756 index = 0
757 self.trace_start()
758 for testfile in files:
759 fstat = os.stat(testfile)
760 self.test(fstat.st_size == self.filesize, "Size of file on pNFS should be correct", failmsg=", expecting %d and got %d" % (self.filesize, fstat.st_size))
761 self.dprint('DBG2', "Read file %s @0" % testfile)
762 fd = open(testfile, "rb")
763 try:
764 data = fd.read()
765 finally:
766 fd.close()
767 self.test(data == orig_data, "Data written using %s is read correctly from pNFS" % vers[index])
768 index += 1
769 self.umount()
770 except Exception:
771 self.test(False, traceback.format_exc())
772 finally:
773 self.trace_stop()
774 self.trace_open()
775 self.pktt.close()
776
777 def verify_ds_connect_needed(self, stripe_index=0):
778 """Verify client only connects to the DS with I/O by writing only
779 to the DS given by stripe_index and verifying client only connects
780 to such DS.
781 Test will not run if only one DS is available or the stripe_index
782 if out of bounds.
783
784 stripe_index:
785 Stripe index to use for writing [default: 0]
786 """
787 run_test = True
788 ds_count = len(getattr(self, "dslist", []))
789
790 if ds_count < 2 or ds_count <= stripe_index:
791 # Nothing to verify, server has only one DS or not enough DS's
792 run_test = False
793 if len(self.testlist) > 1:
794 return
795
796 self.test_group("Verify client only connects to the DS with I/O -- writing to %s stripe only" % ordinal_number(stripe_index+1))
797
798 try:
799 if not run_test:
800 msg = "Server does not have enough data servers" if ds_count <= stripe_index else "Server has only one data server"
801 self.test(False, msg + ", unable to perform test")
802 return
803
804 if self.stripe_size is None:
805 self.test(False, "Unable to get stripe size")
806 return
807
808 self.umount()
809 self.trace_start()
810 self.mount()
811
812 # Create file on Nth stripe only
813 self.dprint('DBG1', "Create file on %s stripe only [stripe size: %d]" % (ordinal_number(stripe_index+1), self.stripe_size))
814 wsize = int(self.stripe_size/2)
815 offset = stripe_index * self.stripe_size
816 self.create_file(offset=offset, size=wsize, dlevels=['DBG1'])
817 filesize = offset + wsize
818
819 # Get list of DS with I/O
820 write_list = self.get_ds_io_list(offset, wsize, ds_count)
821 nocreate_list = [not x for x in write_list]
822
823 self.umount()
824 self.trace_stop()
825 self.trace_open()
826 self.set_pktlist()
827
828 self.find_getdeviceinfo(usecache=False)
829 self.pktt.rewind()
830 self.verify_file(self.filename, iomode=LAYOUTIOMODE4_RW, filesize=filesize, nocreate_list=nocreate_list, write_list=write_list)
831 layout_list = [self.layout]
832 self.verify_layoutreturn(layout_list)
833 except Exception:
834 self.test(False, traceback.format_exc())
835 finally:
836 self.pktt.close()
837
838 def read_file(self, filename, msg=None):
839 """Read whole file"""
840 msg = msg if msg else "Open file [%s] for reading" % filename
841 self.dprint('DBG1', msg)
842 fd = os.open(self.abspath(filename), os.O_RDONLY)
843 try:
844 while len(os.read(fd, self.rsize)): pass
845 finally:
846 os.close(fd)
847
848 def basic_pnfs(self, write=False, swrite=False):
849 """Basic pNFS test"""
850 try:
851 wstr = "WRITE" if write else "READ"
852 self.test_group("Verify traffic for file using pNFS - %s" % wstr)
853 iomode = LAYOUTIOMODE4_RW if write else LAYOUTIOMODE4_READ
854 swstr = "WRITE" if swrite else "READ"
855 siomode = LAYOUTIOMODE4_RW if swrite else LAYOUTIOMODE4_READ
856 self.umount()
857 self.trace_start()
858 self.mount()
859 if write:
860 # Create file
861 filename = self.create_file(dlevels=['DBG1'])
862 # Create second file on same session
863 filename2 = self.create_file(dlevels=['DBG1'])
864 else:
865 # Read file
866 filename = self.files[0]
867 self.read_file(filename)
868 # Read second file on same session
869 filename2 = self.files[1]
870 self.read_file(filename2)
871
872 if swrite or write:
873 # Insert a marker in the packet trace
874 self.insert_trace_marker()
875
876 if swrite:
877 self.dprint('DBG1', "Open first file again on same session [%s] writing %d@%d" % (filename, self.filesize, 0))
878 fd = os.open(self.abspath(filename), os.O_WRONLY|os.O_CREAT|os.O_SYNC)
879 try:
880 os.write(fd, self.data_pattern(0, self.filesize))
881 finally:
882 os.close(fd)
883 elif write:
884 # Open first file again for reading only when first open was for writing
885 self.read_file(filename, msg="Open first file again on same session [%s] for reading" % filename)
886
887 self.umount()
888 self.trace_stop()
889
890 # Verify network traffic
891 self.trace_open()
892 self.set_pktlist()
893 self.find_getdeviceinfo(usecache=False)
894 if swrite or write:
895 # Find trace marker and set the default maxindex to use
896 self.pktt.maxindex = self.get_marker_index()
897 self.pktt.rewind()
898 (multipath_ds_list, openfh) = self.verify_file(filename, iomode=iomode)
899 layout = self.layout
900 layout_list = [self.layout]
901 session_ids = self.session_ids
902
903 self.test_group("Verify traffic for second file using pNFS within the same mount - %s" % wstr)
904 self.verify_file(filename2, iomode=iomode, nocreate=True, multipath_ds_list=multipath_ds_list)
905 layout_list.append(self.layout)
906
907 if swrite or write:
908 if write and 'deleg_stateid' in openfh and openfh['deleg_stateid'] is not None:
909 # Client should not send another open while holding a delegation
910 # unless holding a read delegation and second open is for writing
911 delegreturn = True
912 else:
913 # Client should send another open
914 delegreturn = False
915 openfh['fh'] = openfh.pop('filehandle')
916 openfh.pop('open_stateid')
917
918 self.test_group("Verify traffic for first file opened again using pNFS within the same mount - %s" % swstr)
919 openfh['samefile'] = True
920 openfh['dtcached'] = True
921 self.pktt.maxindex = None
922 self.pktt.rewind(self.trace_marker_index)
923 self.verify_file(filename, iomode=siomode, nocreate=True, multipath_ds_list=multipath_ds_list, openfh=openfh, delegreturn=delegreturn)
924
925 self.verify_layoutreturn(layout_list)
926
927 self.session_ids = session_ids
928 self.verify_destroy_session()
929 except Exception:
930 self.test(False, traceback.format_exc())
931 finally:
932 self.pktt.close()
933
934 def do_lock(self, iomode, setattr=False):
935 """Verify traffic for locked file using pNFS."""
936 if iomode == LAYOUTIOMODE4_READ:
937 mode_str = 'READ'
938 open_type = os.O_RDONLY
939 lock_type = fcntl.F_RDLCK
940 else:
941 mode_str = 'WRITE'
942 open_type = os.O_WRONLY|os.O_CREAT|os.O_SYNC
943 lock_type = fcntl.F_WRLCK
944
945 self.test_group("Verify traffic for locked file using pNFS - %s" % mode_str)
946 self.umount()
947 self.trace_start()
948 self.mount()
949 filename = self.files[0]
950 absfile = self.abspath(filename)
951 self.dprint('DBG1', "Open file [%s]" % filename)
952 fd = os.open(absfile, open_type)
953
954 try:
955 self.dprint('DBG2', "Lock file (F_SETLKW)")
956 haslock = True
957 lockdata = struct.pack('hhllhh', lock_type, 0, 0, 0, 0, 0)
958 rv = fcntl.fcntl(fd, fcntl.F_SETLKW, lockdata)
959 except Exception as e:
960 self.warning("Unable to get lock on file: %r" % e)
961 haslock = False
962
963 if setattr:
964 self.dprint('DBG2', "Truncating file to 0 bytes")
965 os.ftruncate(fd, 0)
966 elif iomode == LAYOUTIOMODE4_READ:
967 self.dprint('DBG2', "Reading %d@0" % self.filesize)
968 os.read(fd, self.filesize)
969 else:
970 self.dprint('DBG2', "Writing %d@%d" % (self.filesize, 0))
971 os.write(fd, self.data_pattern(0, self.filesize))
972
973 os.close(fd)
974 self.umount()
975 self.trace_stop()
976
977 if haslock:
978 self.trace_open()
979 self.set_pktlist()
980 self.find_getdeviceinfo(usecache=False)
981 self.pktt.rewind()
982 (multipath_ds_list, openfh) = self.verify_file(filename, iomode=iomode, lock=True)
983 layout_list = [self.layout]
984 self.verify_layoutreturn(layout_list)
985 self.pktt.close()
986
987 def do_setattr(self, size=0, lock=False):
988 """Verify setattr traffic for file using pNFS."""
989 lock_str = "locked " if lock else ""
990 self.test_group("Verify setattr traffic for %sfile using pNFS" % lock_str)
991 self.umount()
992 self.trace_start()
993 self.mount()
994 filename = self.files[2]
995 absfile = self.abspath(filename)
996 self.dprint('DBG1', "Open file [%s]" % filename)
997 fd = os.open(absfile, os.O_WRONLY|os.O_CREAT|os.O_SYNC)
998
999 haslock = False
1000 if lock:
1001 try:
1002 self.dprint('DBG2', "Lock file (F_SETLKW)")
1003 lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0)
1004 rv = fcntl.fcntl(fd, fcntl.F_SETLKW, lockdata)
1005 haslock = True
1006 except Exception as e:
1007 self.test(False, "Unable to get lock on file: %r" % e)
1008
1009 self.dprint('DBG2', "Truncating file to %d bytes" % size)
1010 os.ftruncate(fd, size)
1011 os.close(fd)
1012 fstat = os.stat(absfile)
1013 self.umount()
1014 self.trace_stop()
1015
1016 self.trace_open()
1017 self.set_pktlist()
1018 self.find_getdeviceinfo(usecache=False)
1019 self.pktt.rewind()
1020 (multipath_ds_list, openfh) = self.verify_file(filename, iomode=LAYOUTIOMODE4_RW, nolayoutget=True, lock=haslock, verify_close=False)
1021
1022 fhandle_str = "NFS.fh == b'%s'" % self.pktt.escape(openfh['filehandle'])
1023 (pktcall, pktreply) = self.find_nfs_op(OP_SETATTR, status=None, match=fhandle_str)
1024 self.test(pktcall, "SETATTR should be sent to MDS")
1025 if pktcall:
1026 sent_stateid = pktcall.NFSop.stateid.other
1027 (stateid, stid_str, stid_failmsg) = self.verify_stateid(openfh, sent_stateid)
1028 self.test(sent_stateid == stateid, "SETATTR stateid should be the %s stateid" % stid_str, failmsg=stid_failmsg)
1029 set_size = pktcall.NFSop.attributes[FATTR4_SIZE]
1030 self.test(set_size == size, "SETATTR should be sent with correct size", failmsg=", expecting %d and got %d" % (size, set_size))
1031 self.test(pktreply.NFSop.status == 0, "SETATTR should succeed", failmsg=", expecting status = %d and got %d" % (0, pktreply.NFSop.status))
1032 if fstat:
1033 self.test(fstat.st_size == size, "Size of file after SETATTR should be correct", failmsg=", expecting %d and got %d" % (size, fstat.st_size))
1034 else:
1035 self.test(False, "Unable to get size of file")
1036
1037 self.verify_close(openfh, False, False)
1038 self.pktt.close()
1039
1040 def read_test(self):
1041 """Verify basic pNFS functionality on a couple of files opened for
1042 reading within the same mount.
1043 """
1044 self.basic_pnfs(write=False)
1045
1046 def write_test(self):
1047 """Verify basic pNFS functionality on a couple of files opened for
1048 writing and then re-opening the first file for writing within
1049 the same mount.
1050 """
1051 self.basic_pnfs(write=True, swrite=True)
1052
1053 def read_write_test(self):
1054 """Verify basic pNFS functionality on a couple of files opened for
1055 reading and then re-opening the first file for writing within
1056 the same mount.
1057 """
1058 self.basic_pnfs(write=False, swrite=True)
1059
1060 def write_read_test(self):
1061 """Verify basic pNFS functionality on a couple of files opened for
1062 writing and then re-opening the first file for reading within
1063 the same mount.
1064 """
1065 self.basic_pnfs(write=True, swrite=False)
1066
1067 def read_lock_test(self):
1068 """Verify traffic for locked file opened for reading using pNFS."""
1069 self.do_lock(LAYOUTIOMODE4_READ)
1070
1071 def write_lock_test(self):
1072 """Verify traffic for locked file opened for writing using pNFS."""
1073 self.do_lock(LAYOUTIOMODE4_RW)
1074
1075 def setattr_test(self):
1076 """Verify setattr traffic for file using pNFS."""
1077 self.do_setattr(size=int(self.filesize/2), lock=False)
1078
1079 def setattr_lock_test(self):
1080 """Verify setattr traffic for locked file using pNFS."""
1081 self.do_setattr(size=0, lock=True)
1082
1083 def rw_read_test(self):
1084 """Verify traffic for file opened for read and write: reading file first."""
1085 try:
1086 self.test_group("Verify traffic for file opened for read and write: reading file first")
1087 self.umount()
1088 self.trace_start()
1089 self.mount()
1090 filename = self.files[0]
1091 self.dprint('DBG1', "Open file [%s] for both reading and writing" % filename)
1092 fd = os.open(self.abspath(filename), os.O_RDWR|os.O_CREAT|os.O_SYNC)
1093 try:
1094 rsize = 0
1095 self.dprint('DBG2', "Reading file %d@0" % self.rsize)
1096 rsize = len(os.read(fd, self.rsize))
1097
1098 # Insert a marker in the packet trace
1099 self.insert_trace_marker()
1100
1101 offset = int(self.filesize/2)
1102 self.dprint('DBG2', "Writing %d@%d" % (self.wsize, offset))
1103 os.lseek(fd, offset, 0)
1104 os.write(fd, self.data_pattern(offset, self.wsize))
1105 finally:
1106 os.close(fd)
1107 self.umount()
1108 self.trace_stop()
1109
1110 self.trace_open()
1111 self.set_pktlist()
1112 self.find_getdeviceinfo(usecache=False)
1113 # Find trace marker and set the default maxindex to use
1114 self.pktt.maxindex = self.get_marker_index()
1115 self.pktt.rewind()
1116 (multipath_ds_list, openfh) = self.verify_file(filename, iomode=LAYOUTIOMODE4_READ, noclose=True, offset=0, size=rsize)
1117 layout_list = [self.layout]
1118
1119 # Re-position trace file after the last READ call/reply
1120 self.pktt.rewind()
1121 while self.pktt.match("NFS.op == %d" % OP_READ):
1122 pass
1123
1124 self.test_group("Verify traffic for file opened for read and write: writing file after read")
1125 self.pktt.maxindex = None
1126 self.pktt.rewind(self.trace_marker_index)
1127 if openfh != None and openfh.get('layout') and openfh['layout']['iomode'] == LAYOUTIOMODE4_READ:
1128 # Got READ layout, expect a WRITE layout
1129 t_layout = openfh.pop('layout')
1130 layout_stateid = t_layout['stateid']
1131 else:
1132 # Client should use same WRITE layout
1133 layout_stateid = None
1134
1135 openfh['samefile'] = True
1136 self.verify_file(filename, iomode=LAYOUTIOMODE4_RW, nocreate=True, multipath_ds_list=multipath_ds_list, openfh=openfh, layout_stateid=layout_stateid, offset=offset, size=self.wsize)
1137 self.verify_layoutreturn(layout_list)
1138 except Exception:
1139 self.test(False, traceback.format_exc())
1140 finally:
1141 self.pktt.close()
1142
1143 def rw_write_test(self):
1144 """Verify traffic for file opened for read and write: writing file first."""
1145 try:
1146 self.test_group("Verify traffic for file opened for read and write: writing file first")
1147 self.umount()
1148 self.trace_start()
1149 self.mount()
1150 filename = self.files[0]
1151 self.dprint('DBG1', "Open file [%s] for both reading and writing" % filename)
1152 fd = os.open(self.abspath(filename), os.O_RDWR|os.O_CREAT|os.O_SYNC)
1153 try:
1154 rsize = 0
1155 offset = int(self.filesize/2)
1156 self.dprint('DBG2', "Writing %d@%d" % (self.wsize, offset))
1157 os.lseek(fd, offset, 0)
1158 os.write(fd, self.data_pattern(offset, self.wsize))
1159 # Flush data to make sure the client sends the write first
1160 os.fsync(fd)
1161
1162 # Insert a marker in the packet trace
1163 self.insert_trace_marker()
1164
1165 self.dprint('DBG2', "Reading file %d@0" % self.rsize)
1166 os.lseek(fd, 0, 0)
1167 rsize = len(os.read(fd, self.rsize))
1168 finally:
1169 os.close(fd)
1170 self.umount()
1171 self.trace_stop()
1172
1173 self.trace_open()
1174 self.set_pktlist()
1175 self.find_getdeviceinfo(usecache=False)
1176 # Find trace marker and set the default maxindex to use
1177 self.pktt.maxindex = self.get_marker_index()
1178 self.pktt.rewind()
1179 (multipath_ds_list, openfh) = self.verify_file(filename, iomode=LAYOUTIOMODE4_RW, noclose=True, offset=offset, size=self.wsize)
1180 layout_list = [self.layout]
1181 if openfh is None:
1182 return
1183
1184 if openfh.get('layout'):
1185 # The file has not been closed, so layout still valid
1186 openfh['layout']['return_on_close'] = False
1187
1188 # Re-position trace file after the last WRITE call/reply
1189 self.pktt.rewind()
1190 while self.pktt.match("NFS.op == %d" % OP_WRITE):
1191 pass
1192
1193 self.test_group("Verify traffic for file opened for read and write: reading file after write")
1194 openfh['samefile'] = True
1195 nds = len(multipath_ds_list)
1196 self.pktt.maxindex = None
1197 self.pktt.rewind(self.trace_marker_index)
1198 self.verify_file(filename, iomode=LAYOUTIOMODE4_READ, nocreate=True, multipath_ds_list=multipath_ds_list, openfh=openfh, offset=0, size=rsize)
1199 self.verify_layoutreturn(layout_list)
1200 except Exception:
1201 self.test(False, traceback.format_exc())
1202 finally:
1203 self.pktt.close()
1204
1205 def read_holes_test(self):
1206 """Verify client correctly handles read with holes."""
1207 try:
1208 self.test_group("Verify client correctly handles read with holes")
1209 if self.stripe_size is None:
1210 self.test(False, "Unable to get stripe size")
1211 return
1212 self.umount()
1213 self.trace_start()
1214 self.mount()
1215 filename = self.get_filename()
1216
1217 # Do not use O_SYNC to avoid the client sending a LAYOUTCOMMIT before sending
1218 # the READ's -- READ replies will have eof set
1219 # Use O_TRUNC to force the client to ask for RW layout by truncating the file
1220 self.dprint('DBG1', "Open file [%s] for both reading and writing" % self.absfile)
1221 fd = os.open(self.absfile, os.O_RDWR|os.O_CREAT|os.O_TRUNC)
1222 try:
1223 self.dprint('DBG2', "Writing %d@%d" % (self.stripe_size, self.stripe_size))
1224 os.lseek(fd, self.stripe_size, 0)
1225 os.write(fd, self.data_pattern(self.stripe_size, self.stripe_size))
1226 # Make sure client sends the write to server before the read
1227 #os.fsync(fd) # XXX cannot flush because it will not return eof on read
1228 time.sleep(5)
1229
1230 self.dprint('DBG2', "Reading file %d@0" % self.rsize)
1231 os.lseek(fd, 0, 0)
1232 data = os.read(fd, self.rsize)
1233 finally:
1234 os.close(fd)
1235
1236 self.umount()
1237 self.trace_stop()
1238 self.trace_open()
1239 self.set_pktlist()
1240
1241 self.test(data == bytes(self.rsize), "Client should read a hole at the beginning of the file after writing")
1242
1243 (filehandle, open_stateid, deleg_stateid) = self.find_open(filename=filename)
1244 openfh = {"open_stateid": open_stateid, "deleg_stateid": deleg_stateid}
1245 self.verify_layoutget(filehandle, LAYOUTIOMODE4_RW, openfh=openfh)
1246 (pktcall, pktreply, dslist) = self.find_getdeviceinfo(usecache=False)
1247 nds = len(dslist)
1248 if self.layout is None:
1249 ids0 = 0
1250 else:
1251 ids0 = self.layout['first_stripe_index']
1252
1253 if nds > 1:
1254 save_index = self.pktt.get_index()
1255 ids1 = (ids0 + 1) % nds
1256
1257 ipaddr = dslist[ids1]['ipaddr']
1258 port = dslist[ids1]['port']
1259 # Find WRITE call and reply
1260 (pktcall, pktreply) = self.find_nfs_op(OP_WRITE, ipaddr=ipaddr, port=port)
1261 self.test(pktreply, "Client should send a WRITE to the second DS")
1262 self.pktt.rewind(save_index)
1263
1264 ipaddr = dslist[ids0]['ipaddr']
1265 port = dslist[ids0]['port']
1266 # Find WRITE call and reply
1267 (pktcall, pktreply) = self.find_nfs_op(OP_WRITE, ipaddr=ipaddr, port=port)
1268 self.test(not pktreply, "Client should not send a WRITE to the first DS")
1269 self.pktt.rewind(save_index)
1270
1271 if nds > 0:
1272 # Find READ call and reply
1273 ipaddr = dslist[ids0]['ipaddr']
1274 port = dslist[ids0]['port']
1275 (pktcall, pktreply) = self.find_nfs_op(OP_READ, ipaddr=ipaddr, port=port)
1276 self.test(pktreply, "Client should send a READ to the first DS")
1277 if pktreply:
1278 self.test(pktreply.NFSop.eof and len(data) == self.rsize, "Client should ignore EOF marker in READ reply for hole")
1279 self.test(len(pktreply.NFSop.data) == 0 and len(data) == self.rsize, "Client should ignore data returned in the READ reply for hole")
1280 else:
1281 self.test(False, "Could not get DS list from GETDEVICEINFO")
1282 except Exception:
1283 self.test(False, traceback.format_exc())
1284 finally:
1285 self.pktt.close()
1286
1287 def one_ds_test(self):
1288 """Verify client only connects to the DS with I/O."""
1289 index = 0
1290 while index < len(getattr(self, "dslist", [])):
1291 # Verify client only connects to the DS with I/O -- writing to Nth stripe only
1292 self.verify_ds_connect_needed(stripe_index=index)
1293 index += 1
1294
1295 def verify_rwsize(self, rsize=None, wsize=None):
1296 """Verify traffic for file using pNFS when mount option rsize < 4096 and/or wsize < 4096."""
1297 rsize_list = []
1298 mtopts = "hard,intr"
1299 r_max_iosize = None
1300 w_max_iosize = None
1301 if rsize:
1302 rsize_list.append("rsize < 4096")
1303 mtopts += ",rsize=1024"
1304 r_max_iosize = 1024
1305 if wsize:
1306 rsize_list.append("wsize < 4096")
1307 mtopts += ",wsize=1024"
1308 w_max_iosize = 1024
1309
1310 self.test_group("Verify traffic for file using pNFS when mount option %s" % " and ".join(rsize_list))
1311 try:
1312 self.umount()
1313 self.trace_start()
1314 self.mount(mtopts=mtopts)
1315
1316 # Read file
1317 filename1 = self.files[0]
1318 absfile = self.abspath(filename1)
1319 self.dprint('DBG1', "Open file [%s] for reading" % absfile)
1320 fd = os.open(absfile, os.O_RDONLY)
1321 os.read(fd, self.filesize)
1322 os.close(fd)
1323
1324 # Write file
1325 filename2 = self.create_file(dlevels=['DBG1'])
1326
1327 self.umount()
1328 self.trace_stop()
1329
1330 # Verify network traffic
1331 self.trace_open()
1332 self.set_pktlist()
1333 self.find_getdeviceinfo(usecache=False)
1334 self.pktt.rewind()
1335 self.test_info("Verify READ traffic ========================================")
1336 (multipath_ds_list, openfh) = self.verify_file(filename1, iomode=LAYOUTIOMODE4_READ, max_iosize=r_max_iosize, nmax_iosize=w_max_iosize)
1337 layout_list = [self.layout]
1338 self.test_info("Verify WRITE traffic =======================================")
1339 self.verify_file(filename2, iomode=LAYOUTIOMODE4_RW, nocreate=True, multipath_ds_list=multipath_ds_list, max_iosize=w_max_iosize, nmax_iosize=r_max_iosize)
1340 layout_list.append(self.layout)
1341 self.verify_layoutreturn(layout_list)
1342 except Exception:
1343 self.test(False, traceback.format_exc())
1344 finally:
1345 self.pktt.close()
1346
1347 def rsize_test(self):
1348 """Verify traffic for file using pNFS when mount option rsize < 4096."""
1349 self.verify_rwsize(rsize=1024)
1350
1351 def wsize_test(self):
1352 """Verify traffic for file using pNFS when mount option wsize < 4096."""
1353 self.verify_rwsize(wsize=1024)
1354
1355 def rwsize_test(self):
1356 """Verify traffic for file using pNFS when mount option rsize < 4096 and wsize < 4096."""
1357 self.verify_rwsize(rsize=1024, wsize=1024)
1358
1359 ################################################################################
1360 # Entry point
1361 NFILES = 3
1362 x = pNFSTest(usage=USAGE, testnames=TESTNAMES, sid=SCRIPT_ID)
1363
1364 try:
1365 x.trace_start()
1366 x.setup(nfiles=NFILES)
1367 x.trace_stop()
1368 for i in range(NFILES):
1369 try:
1370 x.trace_open()
1371 x.set_pktlist()
1372 (pktcall, pktreply) = x.find_exchange_id()
1373 x.dprint('INFO', "Client implementation: %s" % x.nii_name)
1374 x.dprint('INFO', "Server implementation: %s" % x.nii_server)
1375 (filehandle, open_stateid, deleg_stateid) = x.find_open(filename=x.files[i])
1376 x.find_layoutget(filehandle)
1377 x.stripe_size = x.layout['stripe_size']
1378 x.find_getdeviceinfo()
1379 break
1380 except Exception:
1381 pass
1382 finally:
1383 x.pktt.close()
1384
1385 # Run all the tests
1386 x.run_tests()
1387 except Exception:
1388 x.test(False, traceback.format_exc())
1389 finally:
1390 x.cleanup()
1391 x.exit()