Debian Codegraph @

test/nfstest_ssc

raw
1 #!/usr/bin/env python3
2 #===============================================================================
3 # Copyright 2016 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 ctypes
19 import struct
20 import traceback
21 from formatstr import *
22 import nfstest_config as c
23 from baseobj import BaseObj
24 from packet.nfs.nfs3_const import *
25 from packet.nfs.nfs4_const import *
26 from nfstest.test_util import TestUtil
27 from fcntl import fcntl,F_RDLCK,F_WRLCK,F_SETLK
28 from multiprocessing import Process,JoinableQueue
29
30 # Module constants
31 __author__ = "Jorge Mora (%s)" % c.NFSTEST_AUTHOR_EMAIL
32 __copyright__ = "Copyright (C) 2016 NetApp, Inc."
33 __license__ = "GPL v2"
34 __version__ = "1.2"
35
36 USAGE = """%prog --server <server> [options]
37
38 Server side copy tests
39 ======================
40 Verify correct functionality of server side copy
41
42 Copying a file via NFS the client reads the data from the source file and
43 then writes the same data to the destination file which is located in the
44 same server or it could be located in a different server. Either way the
45 file data is transferred twice, once for reading and the second for writing.
46 Server side copy allows unnecessary network traffic to be eliminated.
47 The intra-server copy allows the client to request the server to perform
48 the copy internally thus avoiding any data being sent through the network
49 at all. In the case for the inter-server copy where the destination server
50 is different from the source server, the client authorizes both servers
51 to interact directly with one another.
52
53 The system call copy_file_range is used to send both intra and inter
54 server side copy requests to the correct server.
55
56 Basic server side copy tests verify the actual file range from the source
57 file(s) are copied correctly to the destination file(s). Most tests deal
58 with a single source and destination file while verifying the data is copied
59 correctly. Also it verifies the data is copied starting from the correct
60 source offset and it is copied to the correct offset on the destination file.
61 Other tests deal with multiple files: copying multiple source files to a
62 single destination file, a single source file to multiple destination files,
63 or N number of source files to M number of destination files.
64
65 Some tests include testing at the protocol level by taking a packet trace
66 and inspecting the actual packets sent to the server or servers. For the
67 intra-server side copy, these tests verify the COPY/CLONE operation is sent
68 to the server with correct arguments. For the inter-server side copy, these
69 tests verify the COPY_NOTIFY operation is sent to the source server with
70 correct arguments to authorize the source server to allow the destination
71 server to copy the data directly; then the client sends the COPY operation
72 to the destination server so it could initiate the actual copy.
73
74 The server side copy could either be synchronous or asynchronous depending
75 on both client and server(s). The client could issue either a synchronous
76 or asynchronous copy and the server could either copy the file data in either
77 mode depending on implementation or other factors. In either case, the tests
78 verify the correct functionality for both cases. The CB_OFFLOAD operation is
79 used by the destination server to report the actual results of the copy when
80 it is done. The client could also actively query the destination server for
81 status on a current asynchronous copy using the OFFLOAD_STATUS operation.
82 Also the client has a mechanism to cancel a given asynchronous copy using
83 the OFFLOAD_CANCEL operation.
84
85 Negative testing is included whenever possible since some testing cannot be
86 done at the protocol level because the copy_file_range system call does some
87 error checking of its own and the NFS client won't even send a COPY_NOTIFY
88 or COPY operation to the server letting the server deal with the
89 error. Negative tests include trying to copy an invalid source range, having
90 an invalid value for either the offset or the length, trying to copy a region
91 on a source file opened as write only, a destination file opened as read only
92 or the file is a non-regular file type.
93
94 Examples:
95 The only required option is --server
96 $ %prog --server 192.168.0.11
97
98 Notes:
99 The user id in the local host and the host specified by --dst-server must
100 have access to run commands as root using the 'sudo' command without
101 the need for a password.
102
103 The user id must be able to 'ssh' to remote host without the need for
104 a password.
105
106 Valid only for NFS version 4.2 and above."""
107
108 # Test script ID
109 SCRIPT_ID = "SSC"
110
111 DATA_PATTERN = b"ABCDE"
112 NCOPIES = 4
113
114 INTRA_TESTS = [
115 "intra01",
116 "intra02",
117 "intra03",
118 "intra04",
119 "intra05",
120 "intra06",
121 "intra07",
122 "intra08",
123 "intra09",
124 "intra10",
125 "intra11",
126 "intra12",
127 "intra13",
128 "intra14",
129 "intra15",
130 ]
131 NINTRA_TESTS = ["intra09", "intra10", "intra11", "intra12", "intra13"]
132 PINTRA_TESTS = list(sorted(set(INTRA_TESTS).difference(NINTRA_TESTS)))
133
134 INTER_TESTS = [
135 "inter01",
136 "inter02",
137 "inter03",
138 "inter04",
139 "inter05",
140 "inter06",
141 "inter07",
142 "inter08",
143 "inter09",
144 "inter10",
145 "inter11",
146 "inter12",
147 "inter13",
148 "inter14",
149 "inter15",
150 ]
151 NINTER_TESTS = ["inter09", "inter10", "inter11", "inter12"]
152 PINTER_TESTS = list(sorted(set(INTER_TESTS).difference(NINTER_TESTS)))
153
154 # Include the test groups in the list of test names
155 # so they are displayed in the help
156 TESTNAMES = ["intra", "pintra", "nintra"] + INTRA_TESTS + \
157 ["inter", "pinter", "ninter"] + INTER_TESTS + \
158 ["positive", "negative"]
159
160 TESTGROUPS = {
161 "intra": {
162 "tests": INTRA_TESTS,
163 "desc": "Run all intra server side copy tests: ",
164 },
165 "pintra": {
166 "tests": PINTRA_TESTS,
167 "desc": "Run all positive intra server side copy tests: ",
168 },
169 "nintra": {
170 "tests": NINTRA_TESTS,
171 "desc": "Run all negative intra server side copy tests: ",
172 },
173 "inter": {
174 "tests": INTER_TESTS,
175 "desc": "Run all inter server side copy tests: ",
176 },
177 "pinter": {
178 "tests": PINTER_TESTS,
179 "desc": "Run all positive inter server side copy tests: ",
180 },
181 "ninter": {
182 "tests": NINTER_TESTS,
183 "desc": "Run all negative inter server side copy tests: ",
184 },
185 "positive": {
186 "tests": PINTRA_TESTS + PINTER_TESTS,
187 "desc": "Run all positive server side copy tests: ",
188 },
189 "negative": {
190 "tests": NINTRA_TESTS + NINTER_TESTS,
191 "desc": "Run all negative server side copy tests: ",
192 },
193 }
194
195 def ptr_contents(ptr):
196 """Return the contents of the ctypes pointer"""
197 if ptr is None:
198 return "NULL"
199 return ptr.contents.value
200
201 def getlock(fd, lock_type, offset=0, length=0):
202 """Get byte range lock on file given by file descriptor"""
203 lockdata = struct.pack("hhllhh", lock_type, 0, offset, length, 0, 0)
204 out = fcntl(fd, F_SETLK, lockdata)
205 return struct.unpack("hhllhh", out)
206
207 class FileObj(BaseObj):
208 """File object"""
209 _attrlist = ("fd", "filename", "absfile", "locktype", "filesize",
210 "datarange", "filehandle", "stateid", "cstateid", "copyidx")
211 def __init__(self, **kwargs):
212 self.fd = kwargs.get("fd") # Open file descriptor
213 self.filename = kwargs.get("filename") # File name
214 self.absfile = kwargs.get("absfile") # Absolute path for file
215 self.locktype = kwargs.get("locktype") # Locking type
216 self.filesize = kwargs.get("filesize", 0) # File size
217 self.datarange = kwargs.get("datarange") # List of unmodified data ranges
218 self.filehandle = kwargs.get("filehandle") # File handle
219 self.stateid = kwargs.get("stateid") # Stateid for I/O operations
220 self.cstateid = kwargs.get("cstateid") # Stateid list used by COPY
221 self.copyidx = kwargs.get("copyidx") # COPY index where this file was used
222
223 class CopyItem(BaseObj):
224 """Copy Item object"""
225 _attrlist = ("src_file", "src_offset", "src_lstid", "dst_file",
226 "dst_offset", "dst_lstid", "ncount", "nbytes", "count",
227 "copyid")
228 def __init__(self, **kwargs):
229 self.src_file = kwargs.get("src_file") # Source FileObj
230 self.src_offset = kwargs.get("src_offset") # Source offset of COPY
231 self.src_lstid = kwargs.get("src_lstid") # Source lock stateid
232 self.src_off = kwargs.get("src_off") # Source offset modified by COPY
233 self.src_tell = kwargs.get("src_tell") # Source offset position after COPY
234 self.dst_file = kwargs.get("dst_file") # Destination FileObj
235 self.dst_offset = kwargs.get("dst_offset") # Destination offset of COPY
236 self.dst_lstid = kwargs.get("dst_lstid") # Destination lock stateid
237 self.dst_off = kwargs.get("dst_off") # Destination offset modified by COPY
238 self.dst_tell = kwargs.get("dst_tell") # Destination offset position after COPY
239 self.locking = kwargs.get("locking") # Locking is used if set
240 self.ncount = kwargs.get("ncount") # Locking length
241 self.nbytes = kwargs.get("nbytes") # Number of bytes to copy
242 self.count = kwargs.get("count") # Number of bytes returned by copy
243 self.copyid = kwargs.get("copyid") # Callback id from async COPY
244 self.errorno = kwargs.get("errorno") # Error number return from COPY
245
246 def file_locks(self):
247 """Lock the source and destination files"""
248 if self.locking:
249 self.dprint("DBG3", "Lock src file %s %d@%d" % (self.src_file.absfile, self.ncount, self.src_offset))
250 getlock(self.src_file.fd, self.src_file.locktype, self.src_offset, self.ncount)
251 self.dprint("DBG3", "Lock dst file %s %d@%d" % (self.dst_file.absfile, self.ncount, self.dst_offset))
252 getlock(self.dst_file.fd, self.dst_file.locktype, self.dst_offset, self.ncount)
253
254 class SSCTest(TestUtil):
255 """SSCTest object
256
257 SSCTest() -> New test object
258
259 Usage:
260 x = SSCTest(testnames=["intra01", "intra02", "intra03", ...])
261
262 # Run all the tests
263 x.run_tests()
264 x.exit()
265 """
266 def __init__(self, **kwargs):
267 """Constructor
268
269 Initialize object's private data.
270 """
271 self.dst = None # Host object to mount the destination server
272 self.queue = None # Inter-processes queue
273 self.copyitems = [] # List of CopyItem objects
274 self.inter_ssc = False # True if at least one inter-SSC test is given
275
276 # Instantiate base object constructor
277 TestUtil.__init__(self, **kwargs)
278 self.opts.version = "%prog " + __version__
279
280 # Set default script options
281 # Tests are valid for NFSv4.2 and beyond
282 self.opts.set_defaults(nfsversion=4.2)
283 # Inter-SSC copy length must be greater than 14*rsize, so set filesize
284 # default to have a minimum copy length of 16*rsize for the smallest
285 # possible copy which is for the inter14 test with copy length of
286 # filesize/ncopies
287 self.opts.set_defaults(filesize="%sk" % (NCOPIES*16*4))
288
289 # Options specific for this test script
290 hmsg = "Destination server for inter server side copy [default: %default]"
291 self.test_opgroup.add_option("--dst-server", default=None, help=hmsg)
292 hmsg = "Destination export for inter server side copy [default: %default]"
293 self.test_opgroup.add_option("--dst-export", default=None, help=hmsg)
294 hmsg = "Number of concurrent copies to use on intra14 and inter14 tests [default: %default]"
295 self.test_opgroup.add_option("--ncopies", type="int", default=NCOPIES, help=hmsg)
296 hmsg = "Number of source files to use concurrently on intra15 and inter15 tests [default: %default]"
297 self.test_opgroup.add_option("--src-files", type="int", default=3, help=hmsg)
298 hmsg = "Number of destination files to use concurrently on intra15 and inter15 tests [default: %default]"
299 self.test_opgroup.add_option("--dst-files", type="int", default=2, help=hmsg)
300 hmsg = "Write destination file before copy_file_range [default: %default]"
301 self.test_opgroup.add_option("--pre-write", type="int", default=1, help=hmsg)
302 hmsg = "Lock files [default: %default]"
303 self.test_opgroup.add_option("--locks", type="int", default=1, help=hmsg)
304
305 self.scan_options()
306
307 try:
308 # Define prototype for copy_file_range
309 self.libc.copy_file_range.restype = ctypes.c_ssize_t
310 self.libc.copy_file_range.argtypes = [
311 ctypes.c_int,
312 ctypes.POINTER(ctypes.c_longlong),
313 ctypes.c_int,
314 ctypes.POINTER(ctypes.c_longlong),
315 ctypes.c_size_t,
316 ctypes.c_uint,
317 ]
318 self._use_copy_file_range = True
319 except:
320 # Set correct copy_file_range system call number since
321 # copy_file_range has no wrapper function in libc
322 arch = os.uname()[4]
323 if arch == "x86_64":
324 self.NR_copy_file_range = 326
325 elif arch == "x86_32":
326 self.NR_copy_file_range = 377
327 else:
328 self.config("Machine architecture not supported: %s" % arch)
329
330 # Define prototype for syscall to use it as copy_file_range
331 self.libc.syscall.restype = ctypes.c_ssize_t
332 self.libc.syscall.argtypes = [
333 ctypes.c_int,
334 ctypes.c_int,
335 ctypes.POINTER(ctypes.c_longlong),
336 ctypes.c_int,
337 ctypes.POINTER(ctypes.c_longlong),
338 ctypes.c_size_t,
339 ctypes.c_uint,
340 ]
341 self._use_copy_file_range = False
342
343 # For tests copying data starting from a non-zero source offset,
344 # copy the bytes right up to the end of the source file
345 self.s_offset = int(self.filesize/2)
346 self.s_nbytes = self.filesize - self.s_offset
347
348 # Remove all INTER-SSC tests if dst-server is not given
349 # and requested to run all tests or either positive or negative tests
350 if self.dst_server is None and self.runtest in ("all", "positive", "negative"):
351 for tname in INTER_TESTS:
352 if tname in self.testlist:
353 self.testlist.remove(tname)
354
355 # Find if there is at least one INTER-SSC test to run
356 self.inter_ssc = bool(set(self.testlist).intersection(INTER_TESTS))
357
358 if self.inter_ssc and self.dst_server is None:
359 self.opts.error("option dst-server is required for inter-ssc tests")
360
361 if self.inter_ssc and self.dst_server is not None:
362 if self.dst_export is None:
363 self.opts.error("option dst-export is required when dst-server is given")
364 mtpoint = self.mtpoint + "_dst"
365 self.dst = self.create_host("", server=self.dst_server, export=self.dst_export, mtpoint=mtpoint)
366 ipv6 = self.proto[-1] == "6"
367 self.dst.server_ipaddr = self.get_ip_address(host=self.dst_server, ipv6=ipv6)
368 dst_srv = self.create_host(self.dst_server)
369
370 # Disable createtraces option but save it first for tests that do not
371 # check the NFS packets to verify the assertion
372 self._createtraces = self.createtraces
373 self.createtraces = False
374
375 def copy_file_range(self, srcfd, srcoff, dstfd, dstoff, count, flags):
376 """Wrapper for copy_file_range system call"""
377 if self._use_copy_file_range:
378 return self.libc.copy_file_range(srcfd, srcoff, dstfd, dstoff, count, flags)
379 else:
380 return self.libc.syscall(self.NR_copy_file_range, srcfd, srcoff, dstfd, dstoff, count, flags)
381
382 def setup(self):
383 """Setup test environment"""
384 nfiles = 1
385 file_list = []
386 run_set = set(self.testlist)
387
388 # Get correct number of source files to create
389 if run_set.intersection(["intra10"]):
390 nfiles = 2
391 if run_set.intersection(["intra15", "inter15"]):
392 nfiles = max(nfiles, self.src_files)
393
394 # Call base object's setup method
395 super(SSCTest, self).setup(nfiles=nfiles)
396 rsize = self.mount_opts.get('rsize', 0)
397 if rsize > 0 and self.inter_ssc:
398 if NCOPIES > 2 and run_set.intersection(["inter14"]):
399 min_filesize = 14*NCOPIES*rsize
400 else:
401 min_filesize = 14*2*rsize
402 if self.filesize <= min_filesize:
403 self.opts.error("inter-SSC copy length must be greater than " \
404 "14*rsize, change mount rsize option or --filesize so " \
405 "that --filesize > %s" % str_units(min_filesize))
406
407 # Create necessary files in the destination server
408 if run_set.intersection(["inter10"]):
409 while len(self.files) < 2:
410 self.get_filename()
411 file_list.append(self.files[1])
412 if self.dst and file_list:
413 self.dst.umount()
414 self.dst.mount()
415 for filename in file_list:
416 dstfile = self.dst.abspath(filename)
417 self.dst.remove_list.append(dstfile)
418 self.dprint("DBG2", "Creating file [%s] %d@%d" % (dstfile, self.filesize, 0))
419 fd = os.open(dstfile, os.O_WRONLY|os.O_CREAT|os.O_TRUNC)
420 self.write_data(fd)
421 os.close(fd)
422 self.dst.umount()
423
424 def copy_list(self):
425 """Generator to yield all CopyItem objects"""
426 for item in self.copyitems:
427 yield item
428
429 def src_file_list(self):
430 """Generator to yield all source FileObj objects"""
431 flist = []
432 for item in self.copyitems:
433 src_file = item.src_file
434 if src_file not in flist:
435 flist.append(src_file)
436 yield src_file
437
438 def dst_file_list(self):
439 """Generator to yield all destination FileObj objects"""
440 flist = []
441 for item in self.copyitems:
442 dst_file = item.dst_file
443 if dst_file not in flist:
444 flist.append(dst_file)
445 yield dst_file
446
447 def src_get_file(self, index):
448 """Get the source FileObj given by the index"""
449 for item in self.src_file_list():
450 if index == 0:
451 return item
452 index -= 1
453 return
454
455 def dst_get_file(self, index):
456 """Get the destination FileObj given by the index"""
457 for item in self.dst_file_list():
458 if index == 0:
459 return item
460 index -= 1
461 return
462
463 def close_files(self):
464 """Close all opened files"""
465 for item in list(self.src_file_list()) + list(self.dst_file_list()):
466 if item.fd:
467 os.close(item.fd)
468 item.fd = None
469
470 def find_v3_open(self, filename, dirfh=None, **kwargs):
471 """Find the call and its corresponding reply for the NFSv3 OPEN of the
472 given file going to the server specified by the ipaddr and port.
473 """
474 save_index = self.pktt.get_index()
475 mstr = "nfs.name == '%s'" % filename
476 if dirfh is not None:
477 mstr = "crc32(nfs.fh) == 0x%08x and " % crc32(dirfh) + mstr
478 (pktcall, pktreply) = self.find_nfs_op(NFSPROC3_LOOKUP, ipaddr=kwargs["ipaddr"], port=kwargs["port"], match=mstr)
479 if pktcall is None:
480 self.pktt.rewind(save_index)
481 (pktcall, pktreply) = self.find_nfs_op(NFSPROC3_CREATE, ipaddr=kwargs["ipaddr"], port=kwargs["port"], match=mstr)
482 self.opencall = pktcall
483 self.openreply = pktreply
484 if pktreply:
485 self.filehandle = pktreply.nfs.fh
486
487 def pkt_locks(self, fhandle, **kwargs):
488 """Search the packets for the lock stateid given by the file handle"""
489 if fhandle is None:
490 return
491 kwargs["match"] = "crc32(nfs.fh) == 0x%08x" % crc32(fhandle)
492 self.find_nfs_op(OP_LOCK, **kwargs)
493 if self.pktreply:
494 self.pktt.rewind(self.pktcall.record.index+1)
495 return self.pktreply.NFSop.stateid.other
496
497 def get_io(self, op):
498 """Search all packets for given I/O operation and return
499 a dictionary where the key is the file handle and the
500 value is the index of the last packet found
501 """
502 index_map = {}
503 self.pktt.rewind()
504 if self.nfs_version < 4:
505 if op == OP_READ:
506 op = NFSPROC3_READ
507 elif op == OP_WRITE:
508 op = NFSPROC3_WRITE
509 mstr = "nfs.argop == %d" % op
510 while self.pktt.match(mstr):
511 index = self.pktt.get_index()
512 fhandle = self.pktt.pkt.NFSop.fh
513 if index_map.get(fhandle) is None:
514 index_map[fhandle] = index
515 else:
516 index_map[fhandle] = max(index, index_map[fhandle])
517 return index_map
518
519 def run_copy_file_range(self, tid):
520 """Run copy_file_range in a different process"""
521 try:
522 copyobj = self.copyitems[tid]
523 nbytes = copyobj.nbytes
524 srcoff = copyobj.src_offset
525 dstoff = copyobj.dst_offset
526 sname = copyobj.src_file.filename
527 dname = copyobj.dst_file.filename
528 errstr = ""
529 errorno = None
530 src_off = None
531 dst_off = None
532
533 # Lock both source and destination files
534 copyobj.file_locks()
535 soff = ctypes.pointer(ctypes.c_longlong(srcoff))
536 doff = ctypes.pointer(ctypes.c_longlong(dstoff))
537 self.dprint("DBG1", "COPY %s -> %s with size = %d, offset(%s -> %s) (%d)" % (sname, dname, nbytes, srcoff, dstoff, tid))
538 count = self.copy_file_range(copyobj.src_file.fd, soff, copyobj.dst_file.fd, doff, nbytes, 0)
539 if count == -1:
540 errorno = ctypes.get_errno()
541 errstr = " [%s]" % errno.errorcode.get(errorno, errorno)
542 src_tell = os.lseek(copyobj.src_file.fd, 0, os.SEEK_CUR)
543 dst_tell = os.lseek(copyobj.dst_file.fd, 0, os.SEEK_CUR)
544 src_off = ptr_contents(soff)
545 dst_off = ptr_contents(doff)
546 self.dprint("DBG2", "COPY returns %d%s (soff:%s, doff:%s) (spos:%d, dpos:%d) (%d)" % (count, errstr, src_off, dst_off, src_tell, dst_tell, tid))
547 except:
548 self.queue.put([tid, 1, traceback.format_exc()])
549 return 1
550 self.queue.put([tid, 0, count, src_off, src_tell, dst_off, dst_tell, errorno])
551 return 0
552
553 def basic_ssc(self, **kwargs):
554 """Basic server side copy test"""
555 # When using src_seek set src_off to None (NULL value on copy_file_range)
556 # When using dst_seek set dst_off to None (NULL value on copy_file_range)
557 count = None # Number of bytes returned by copy_file_range
558 srcoff = None # C style pointer to source offset (None -> NULL)
559 dstoff = None # C style pointer to destination offset (None -> NULL)
560 srclock = F_WRLCK # Source lock type
561 dstlock = F_WRLCK # Destination lock type
562 errorno = 0 # Error number if copy_file_range fails
563 nbytes = kwargs.get("nbytes", self.filesize) # Number of bytes to copy
564 srcopen = kwargs.get("srcopen", os.O_RDONLY) # Open mode for source file
565 dstopen = kwargs.get("dstopen", os.O_WRONLY|os.O_CREAT) # Open mode for destination file
566 src_off = kwargs.get("src_off", 0) # Source offset to use in copy_file_range
567 dst_off = kwargs.get("dst_off", 0) # Destination offset to use in copy_file_range
568 src_seek = kwargs.get("src_seek", 0) # Source offset to seek to before copy_file_range
569 dst_seek = kwargs.get("dst_seek", 0) # Destination offset to seek to before copy_file_range
570 failure = kwargs.get("failure", 0) # Error number of expected failure
571 enforce = kwargs.get("enforce", 1) # Enforce expected failure when True(1)
572 dstfail = kwargs.get("dstfail", 0) # Failure is caused by the destination file
573 copymsg = kwargs.get("copymsg", "") # Specific assertion message on COPY success test
574 write = kwargs.get("write", self.pre_write) # Write before copy_file_range
575 inter = kwargs.get("inter", 0) # Inter-server side copy test when True(1)
576 src_doff = kwargs.get("src_doff", 0) # Use multiple source offsets when True(1)
577 ncopies = kwargs.get("ncopies", 1) # Number of copies to start concurrently
578 nsfiles = kwargs.get("nsfiles", 1) # Number of source files to use concurrently
579 ndfiles = kwargs.get("ndfiles", 1) # Number of destination files to use concurrently
580 samefile = kwargs.get("samefile", 0) # Use same file name for both source and destination
581
582 # Get the correct number of copies the client will send
583 ncopies = max(ncopies, max(nsfiles, ndfiles))
584
585 verify_data = failure
586 if failure:
587 # Expecting a failure
588 ncopies = 1
589
590 if srcopen & os.O_WRONLY:
591 srcostr = "writing"
592 elif srcopen & os.O_RDWR:
593 srcostr = "read and write"
594 else:
595 srcostr = "reading"
596 srclock = F_RDLCK
597
598 if dstopen & os.O_WRONLY:
599 dstostr = "writing"
600 elif dstopen & os.O_RDWR:
601 dstostr = "read and write"
602 else:
603 dstostr = "reading"
604 dstlock = F_RDLCK
605
606 if dstfail:
607 openstr = dstostr
608 strfile = "destination"
609 else:
610 openstr = srcostr
611 strfile = "source"
612
613 # Convert source and destination offsets to C style pointers
614 # as needed by copy_file_range
615 if src_off is None:
616 src_offset = src_seek
617 else:
618 src_offset = src_off
619 srcoff = ctypes.pointer(ctypes.c_longlong(src_off))
620 if dst_off is None:
621 dst_offset = dst_seek
622 else:
623 dst_offset = dst_off
624 dstoff = ctypes.pointer(ctypes.c_longlong(dst_off))
625
626 # Number of bytes expected to be copied
627 ncount = nbytes - max(src_offset + nbytes - self.filesize, 0)
628
629 # Unmount the source and destination
630 self.umount()
631 if inter and self.dst:
632 self.dst.umount()
633
634 # Start packet trace
635 self.trace_start(clients=[])
636
637 # Mount source
638 self.mount()
639 if inter and self.dst:
640 # Mount destination
641 self.dst.mount()
642
643 try:
644 ####################################################################
645 # Main test
646 ####################################################################
647 # Destination file
648 if samefile:
649 dstname = self.files[0]
650 elif dstostr == "reading":
651 dstname = self.files[1]
652 # Do not try to write any data before the copy_file_range
653 write = 0
654 else:
655 # Get a new name
656 dstname = None
657
658 sindex = 0 # Index for source file
659 dindex = 0 # Index for destination file
660 smult = 0 # Multiplier for source offset
661 dmult = 0 # Multiplier for destination offset
662 fsize = 0 # Initial file size of destination file
663 if write:
664 fsize = self.filesize
665
666 # Create list of copy objects
667 self.copyitems = []
668 for i in range(ncopies):
669 # Source file
670 srcobj = self.src_get_file(sindex)
671 if srcobj is None:
672 # Create FileObj for source file
673 src_name = self.files[sindex]
674 srcobj = FileObj(
675 filename = src_name,
676 absfile = self.abspath(src_name),
677 locktype = srclock,
678 filesize = self.filesize,
679 )
680
681 # Destination file
682 dstobj = self.dst_get_file(dindex)
683 if dstobj is None:
684 if dstname is None:
685 self.get_filename()
686 dst_name = self.filename
687 else:
688 dst_name = dstname
689 if inter and self.dst:
690 dst_file = self.dst.abspath(dst_name)
691 if dstname is None:
692 self.dst.remove_list.append(dst_file)
693 else:
694 dst_file = self.abspath(dst_name)
695 # Create FileObj for destination file
696 dstobj = FileObj(
697 filename = dst_name,
698 absfile = dst_file,
699 locktype = dstlock,
700 filesize = fsize,
701 )
702
703 # Create CopyItem object
704 copyobj = CopyItem(
705 src_file = srcobj,
706 src_offset = src_offset + smult*ncount,
707 dst_file = dstobj,
708 dst_offset = dst_offset + dmult*ncount,
709 nbytes = nbytes,
710 ncount = ncount,
711 locking = self.locks,
712 )
713 # Add the CopyItem to the copyitems list
714 self.copyitems.append(copyobj)
715 sindex += 1
716 if sindex >= nsfiles:
717 # Wrap around and start with the first source file
718 if src_doff:
719 smult += 1
720 sindex = 0
721 dindex += 1
722 if dindex >= ndfiles:
723 # Wrap around and start with the first destination file
724 dmult += 1
725 dindex = 0
726
727 # Open source files
728 for srcobj in self.src_file_list():
729 self.dprint("DBG2", "Open src file %s for %s" % (srcobj.absfile, srcostr))
730 srcobj.fd = os.open(srcobj.absfile, srcopen)
731 if src_seek > 0:
732 self.dprint("DBG3", "Seek src file %s to offset %s" % (srcobj.absfile, src_seek))
733 os.lseek(srcobj.fd, src_seek, os.SEEK_SET)
734
735 # Open destination files
736 for dstobj in self.dst_file_list():
737 self.dprint("DBG2", "Open dst file %s for %s" % (dstobj.absfile, dstostr))
738 dstobj.fd = os.open(dstobj.absfile, dstopen)
739
740 if write:
741 # Writing file before copy_file_range
742 self.dprint("DBG3", "Write dst file %s %d@%d" % (dstobj.absfile, self.filesize, 0))
743 self.write_data(dstobj.fd, pattern=DATA_PATTERN)
744 if dst_seek > 0:
745 self.dprint("DBG3", "Seek dst file %s to offset %s" % (dstobj.absfile, dst_seek))
746 os.lseek(dstobj.fd, dst_seek, os.SEEK_SET)
747 else:
748 os.lseek(dstobj.fd, 0, os.SEEK_SET)
749
750 # Flush log file descriptor to make sure debug info is not written
751 # multiple times to the log file
752 self.flush_log()
753
754 # Start all copies concurrently
755 # all copies but the first are executed in their own processes
756 pid_list = []
757 process_list = []
758 self.queue = JoinableQueue()
759 for i in range(1, ncopies):
760 process = Process(target=self.run_copy_file_range, args=(i,))
761 process_list.append(process)
762 process.start()
763
764 # The first copy is executed in the main process
765 errstr = ""
766 copyobj = self.copyitems[0]
767 copyobj.file_locks()
768 sname = copyobj.src_file.filename
769 dname = copyobj.dst_file.filename
770 self.dprint("DBG1", "COPY %s -> %s with size = %d, offset(%s -> %s)" % (sname, dname, copyobj.nbytes, copyobj.src_offset, dst_off))
771 count = self.copy_file_range(copyobj.src_file.fd, srcoff, copyobj.dst_file.fd, dstoff, copyobj.nbytes, 0)
772 if count == -1:
773 errorno = ctypes.get_errno()
774 errstr = " [%s]" % errno.errorcode.get(errorno, errorno)
775 s_off = ptr_contents(srcoff)
776 d_off = ptr_contents(dstoff)
777 src_tell = os.lseek(copyobj.src_file.fd, 0, os.SEEK_CUR)
778 dst_tell = os.lseek(copyobj.dst_file.fd, 0, os.SEEK_CUR)
779 self.dprint("DBG2", "COPY returns %d%s off(src:%s, dst:%s) pos(src:%d, dst:%d)" % (count, errstr, s_off, d_off, src_tell, dst_tell))
780 copyobj.count = count
781 copyobj.src_off = s_off
782 copyobj.dst_off = d_off
783 copyobj.src_tell = src_tell
784 copyobj.dst_tell = dst_tell
785 copyobj.errorno = errorno
786
787 # Get the results from the child processes
788 ret_list = []
789 while len(ret_list) < len(process_list):
790 time.sleep(0.1)
791 while not self.queue.empty():
792 # Get any pending messages from any of the processes
793 data = self.queue.get()
794 ret_list.append(data)
795
796 # Wait for all child processes to finish
797 for process in process_list:
798 if not process.is_alive():
799 process.join()
800 if len(process_list) == 0:
801 break
802
803 for data in ret_list:
804 # Inter-process message format is a list:
805 # [thread_id, msg_type, message]
806 # thread_id: 1-N (0 is reserved for main process)
807 # msg_type: 0(success/errno), 1(unknown error)
808 if data[1] == 0:
809 # Success/errno
810 self.copyitems[data[0]].count = data[2]
811 self.copyitems[data[0]].src_off = data[3]
812 self.copyitems[data[0]].src_tell = data[4]
813 self.copyitems[data[0]].dst_off = data[5]
814 self.copyitems[data[0]].dst_tell = data[6]
815 self.copyitems[data[0]].errorno = data[7]
816 elif data[1] == 1:
817 # Unexpected error on child process
818 raise Exception(data[2])
819
820 if copymsg:
821 # Specific assertion message
822 msg = copymsg
823 else:
824 # Default assertion message
825 msg = "%s file is opened for %s" % (strfile, openstr)
826
827 for copyobj in self.copy_list():
828 count = copyobj.count
829 errorno = copyobj.errorno
830 if failure:
831 # Expecting a failure
832 errstr = errno.errorcode.get(failure, "errno=%d"%failure)
833 if count == -1:
834 fmsg = ", expecting %s but got %s" % (errstr, errno.errorcode.get(errorno, errorno))
835 else:
836 verify_data = 0 # The copy succeeded so test the results
837 fmsg = ", expecting %s but it succeeded" % errstr
838 if enforce:
839 expr = count == -1 and errorno == failure
840 amsg = "COPY(copy_file_range) should fail with %s when %s" % (errstr, msg)
841 elif count == -1:
842 expr = errorno == failure
843 amsg = "COPY(copy_file_range) may fail with %s when %s" % (errstr, msg)
844 else:
845 expr = True
846 amsg = "COPY(copy_file_range) may succeed when %s" % msg
847 self.test(expr, amsg, failmsg=fmsg)
848 else:
849 # Expecting a success
850 fmsg = ", failed with %s" % errno.errorcode.get(errorno, errorno)
851 self.test(count >= 0, "COPY(copy_file_range) should succeed when %s" % msg, failmsg=fmsg)
852 if count >= 0:
853 fmsg = ", expecting <= %s but got %s" % (copyobj.nbytes, count)
854 self.test(count <= copyobj.nbytes, "COPY(copy_file_range) should return correct number of bytes actually copied", failmsg=fmsg)
855
856 if count < 0:
857 # Make sure expected offsets or offset position is correct
858 count = 0
859
860 # Source assertions
861 src_offpos = src_seek
862 if isinstance(copyobj.src_off, str) and copyobj.src_off == "NULL":
863 # File descriptor is only modified if using a NULL pointer
864 src_offpos += count
865 else:
866 # Offset pointer is modified
867 src_exp_off = copyobj.src_offset + count
868 fmsg = ", expecting %d but got %d" % (src_exp_off, copyobj.src_off)
869 self.test(src_exp_off == copyobj.src_off, "Source offset pointer should be correct after copy_file_range", failmsg=fmsg)
870 fmsg = ", expecting %d but got %d" % (src_offpos, copyobj.src_tell)
871 self.test(src_offpos == copyobj.src_tell, "Source file descriptor offset position should be correct after copy_file_range", failmsg=fmsg)
872
873 # Destination assertions
874 dst_offpos = dst_seek
875 if isinstance(copyobj.dst_off, str) and copyobj.dst_off == "NULL":
876 # File descriptor is only modified if using a NULL pointer
877 dst_offpos += count
878 else:
879 # Offset pointer is modified
880 dst_exp_off = copyobj.dst_offset + count
881 fmsg = ", expecting %d but got %d" % (dst_exp_off, copyobj.dst_off)
882 self.test(dst_exp_off == copyobj.dst_off, "Destination offset pointer should be correct after copy_file_range", failmsg=fmsg)
883 fmsg = ", expecting %d but got %d" % (dst_offpos, copyobj.dst_tell)
884 self.test(dst_offpos == copyobj.dst_tell, "Destination file descriptor offset position should be correct after copy_file_range", failmsg=fmsg)
885 except Exception:
886 self.test(False, traceback.format_exc())
887 finally:
888 self.close_files()
889 self.trace_stop()
890
891 try:
892 ####################################################################
893 # Verify written data by copy_file_range
894 ####################################################################
895 if verify_data or errorno or count is None:
896 # No need to check anything else.
897 # This will execute corresponding finally block and then return
898 return
899
900 # Get expected destination file size
901 for copyobj in self.copy_list():
902 dstobj = copyobj.dst_file
903 dstobj.filesize = max(dstobj.filesize, copyobj.dst_offset + copyobj.count)
904
905 for copyobj in self.copy_list():
906 srcobj = copyobj.src_file
907 dstobj = copyobj.dst_file
908 dst_offset = copyobj.dst_offset
909
910 # Ranges of unmodified data -- start with full file
911 if dstobj.datarange is None:
912 dstobj.datarange = [[0, dstobj.filesize]]
913 if copyobj.count <= 0:
914 continue
915
916 try:
917 # Find out which file ranges were not modified by the copy
918 rindex = 0
919 for rng in dstobj.datarange:
920 rindex += 1
921 if dst_offset >= rng[0] and dst_offset < rng[0] + rng[1]:
922 # Split the range
923 lcnt = rng[1]
924 dstoff = dst_offset + copyobj.count
925 if dst_offset == 0:
926 rng[0] = dstoff
927 rng[1] = max(0, lcnt - dstoff)
928 elif rng[0] + dst_offset >= dstoff:
929 rng[1] = max(0, lcnt - rng[0])
930 rng[0] = dstoff
931 else:
932 rng[1] = dst_offset
933 dstobj.datarange.insert(rindex, [dstoff, lcnt - dstoff])
934 break
935
936 if srcobj.fd is None:
937 # Open source file to compare its data with the
938 # destination file
939 srcobj.fd = os.open(srcobj.absfile, os.O_RDONLY)
940 if dstobj.fd is None:
941 # Open destination file to compare its data with the
942 # source file
943 dstobj.fd = os.open(dstobj.absfile, os.O_RDONLY)
944 dstst = os.fstat(dstobj.fd)
945 fmsg = ", expecting file size = %d but got %d" % (dstobj.filesize, dstst.st_size)
946 self.test(dstobj.filesize == dstst.st_size, "Destination file should have the correct size", failmsg=fmsg)
947 except Exception:
948 self.test(False, traceback.format_exc())
949
950 for copyobj in self.copy_list():
951 srcobj = copyobj.src_file
952 dstobj = copyobj.dst_file
953 try:
954 expr = True
955 soff = copyobj.src_offset
956 doff = copyobj.dst_offset
957 rsize = copyobj.count # Number of bytes to compare
958 while rsize > 0:
959 os.lseek(srcobj.fd, soff, os.SEEK_SET)
960 os.lseek(dstobj.fd, doff, os.SEEK_SET)
961 sdata = os.read(srcobj.fd, rsize)
962 ddata = os.read(dstobj.fd, rsize)
963 cnt = min(len(sdata), len(ddata))
964 if len(sdata) == 0 or len(ddata) == 0 or sdata[:cnt] != ddata[:cnt]:
965 expr = False
966 break
967 soff += cnt
968 doff += cnt
969 rsize -= cnt
970 if rsize < copyobj.count:
971 self.test(expr, "Destination file data written by COPY should be correct")
972 except Exception:
973 self.test(False, traceback.format_exc())
974
975 if write or (dst_off is not None and dst_off > 0):
976 # Verify destination file was not modified outside the
977 # file ranges from the copies
978 for dstobj in self.dst_file_list():
979 expr = True
980 if dstobj.fd is None:
981 # File is not opened
982 continue
983 for drange in dstobj.datarange:
984 # Verify data range was not modified
985 doff = drange[0]
986 moffset = doff + drange[1]
987 while doff < moffset:
988 rsize = moffset - doff
989 os.lseek(dstobj.fd, doff, os.SEEK_SET)
990 ddata = os.read(dstobj.fd, rsize)
991 cnt = len(ddata)
992 if write:
993 sdata = self.data_pattern(doff, cnt, DATA_PATTERN)
994 elif samefile:
995 sdata = self.data_pattern(doff, cnt)
996 else:
997 sdata = self.data_pattern(doff, cnt, b"\x00")
998 if sdata != ddata:
999 expr = False
1000 break
1001 doff += cnt
1002 self.test(expr, "Destination file data not written by COPY should not be modified")
1003 except Exception:
1004 self.test(False, traceback.format_exc())
1005 finally:
1006 self.close_files()
1007 self.umount()
1008 if inter and self.dst:
1009 self.dst.umount()
1010
1011 try:
1012 ####################################################################
1013 # Verify correct packets are sent to server(s)
1014 ####################################################################
1015 copy_index = None
1016 nfs_error_list = [NFS4ERR_NOENT, NFS4ERR_NOTSUPP]
1017 if samefile or failure == errno.EINVAL or \
1018 (src_off is not None and ((src_off + nbytes) > self.filesize)):
1019 nfs_error_list.append(NFS4ERR_INVAL)
1020 self.set_nfserr_list(nfs4list=nfs_error_list)
1021 self.trace_open()
1022 # Search some packets on source server
1023 args = {"ipaddr": self.server_ipaddr, "port": self.port, "noreset":True}
1024
1025 # Save packets from mount command to use buffered matching
1026 oplist = [OP_EXCHANGE_ID, OP_CREATE_SESSION, OP_PUTROOTFH, OP_CREATE, OP_LOOKUP, OP_SETCLIENTID]
1027 self.set_pktlist(ops=oplist)
1028
1029 # Get attributes from mount packets (source server)
1030 src_clientid = self.get_clientid()
1031 src_sessionid = self.get_sessionid(clientid=src_clientid)
1032 src_rootfh = self.get_rootfh(sessionid=src_sessionid)
1033 src_export = os.path.join(self.export, self.datadir)
1034 src_topfh = self.get_pathfh(src_export, dirfh=src_rootfh)
1035
1036 diff_server = False
1037 if inter and self.dst:
1038 # Get attributes from mount packets (destination server)
1039 self.pktt.rewind()
1040 dst_ipaddr = self.dst.server_ipaddr
1041 dst_clientid = self.get_clientid(ipaddr=dst_ipaddr)
1042 dst_sessionid = self.get_sessionid(clientid=dst_clientid, ipaddr=None)
1043 dst_rootfh = self.get_rootfh(sessionid=dst_sessionid, ipaddr=None)
1044 if dst_rootfh is not None:
1045 dst_ipaddr = self.pktcall.ip.dst
1046 dst_export = os.path.join(self.dst_export, self.datadir)
1047 dst_topfh = self.get_pathfh(dst_export, dirfh=dst_rootfh, ipaddr=dst_ipaddr)
1048 args["fh"] = dst_topfh
1049 if src_clientid is not None and dst_clientid is not None and src_clientid != dst_clientid:
1050 diff_server = True
1051 if self.nfs_version < 4:
1052 #XXX how to check if two different servers on NFSv3?
1053 diff_server = True
1054 if inter and not diff_server:
1055 self.test(False, "Source and destination must be different servers for inter-SSC tests")
1056 return
1057
1058 # Disable buffered matching
1059 self.pktt.set_pktlist()
1060 self.pktt.rewind()
1061
1062 # Get list of operations to test and enable buffered matching
1063 oplist = [OP_OPEN, OP_COPY, OP_COPY_NOTIFY, OP_CLONE, OP_LOCK, OP_COMMIT, OP_CLOSE, OP_ILLEGAL]
1064 cblist = [OP_CB_OFFLOAD]
1065 pclist = [NFSPROC3_LOOKUP, NFSPROC3_CREATE]
1066 self.set_pktlist(ops=oplist, cbs=cblist, procs=pclist, pktdisp=self.pktdisp)
1067
1068 # Search all OPENs for the source files and get the correct
1069 # stateid to use in I/O operations (COPY_NOTIFY or COPY)
1070 open_index = 0
1071 noreset = False
1072 for srcobj in self.src_file_list():
1073 self.get_stateid(srcobj.filename, noreset=noreset, fh=src_topfh)
1074 if self.opencall is None:
1075 # Search NFSv3 packets
1076 self.find_v3_open(srcobj.filename, dirfh=src_topfh, **args)
1077 # Save index right after the OPEN call
1078 open_index = self.opencall.record.index + 1
1079 noreset = True
1080 srcobj.filehandle = self.filehandle
1081 srcobj.stateid = self.stateid
1082 if inter and self.dst:
1083 srcobj.cstateid = []
1084 else:
1085 srcobj.cstateid = [self.stateid]
1086 save_index = self.pktt.get_index()
1087 # Search for the correct source lock for each copy
1088 while True:
1089 stateid = self.pkt_locks(self.filehandle, **args)
1090 if stateid is None:
1091 break
1092 for cobj in self.copy_list():
1093 off = self.pktcall.NFSop.offset
1094 if cobj.src_file == srcobj and cobj.src_offset == off:
1095 cobj.src_lstid = stateid
1096 break
1097 self.pktt.rewind(save_index)
1098
1099 if inter and self.dst and diff_server:
1100 # Inter server side copy -- look for COPY_NOTIFY
1101 svrstr = "destination "
1102 args["ipaddr"] = dst_ipaddr
1103 args["port"] = self.dst.port
1104 for i in range(ncopies):
1105 (pktcall, pktreply) = self.find_nfs_op(OP_COPY_NOTIFY, status=None)
1106 # Old behavior: COPY_NOTIFY is sent whether it can copy data or not
1107 # New behavior: COPY_NOTIFY is not sent if data cannot be copied
1108 if ncount == 0 and not pktcall:
1109 self.test(not pktcall, "COPY_NOTIFY may not be sent to source server")
1110 else:
1111 self.test(pktcall, "COPY_NOTIFY may be sent to source server")
1112 if pktcall:
1113 save_index = pktcall.record.index + 1
1114 stateid = pktcall.NFSop.stateid.other
1115 fhandle = pktcall.NFSop.fh
1116
1117 if nsfiles == 1:
1118 srcobj = self.src_get_file(0)
1119 fmsg1 = ", expecting %s but got %s" % (self.stid_str(srcobj.stateid), self.stid_str(stateid))
1120 fmsg2 = ", expecting 0x%08x but got 0x%08x" % (crc32(srcobj.filehandle), crc32(fhandle))
1121 else:
1122 srcobj = None
1123 for srcobj in self.src_file_list():
1124 if srcobj.filehandle == fhandle:
1125 break
1126 fmsg1 = ", expecting source stateid but got %s" % self.stid_str(stateid)
1127 fmsg2 = ", expecting source file handle but got 0x%08x" % crc32(fhandle)
1128
1129 estateid = srcobj.stateid
1130 for copyobj in self.copy_list():
1131 if stateid == copyobj.src_lstid:
1132 estateid = copyobj.src_lstid
1133 break
1134
1135 self.test(srcobj and stateid == estateid, "COPY_NOTIFY should be sent with correct stateid", failmsg=fmsg1)
1136 self.test(srcobj, "COPY_NOTIFY should be sent with correct source file handle", failmsg=fmsg2)
1137
1138 if srcobj and pktreply:
1139 status = pktreply.NFSop.status
1140 fmsg = ", expecting NFS4_OK but got %s" % status
1141 self.test(status == NFS4_OK, "COPY_NOTIFY should succeed", failmsg=fmsg)
1142 if status != NFS4_OK:
1143 break
1144
1145 # The COPY_NOTIFY stateid should be the source stateid in COPY
1146 # This operation does not have offsets so there is
1147 # no way to match it to the COPY operation exactly
1148 # thus the COPY_NOTIFY stateid is save in a list
1149 # to match the correct one on the COPY operation
1150 srcobj.cstateid.append(pktreply.NFSop.stateid.other)
1151 self.stid_map[pktreply.NFSop.stateid.other] = "COPY_NOTIFY stateid"
1152
1153 self.pktt.rewind(save_index)
1154 else:
1155 svrstr = ""
1156
1157 # Search all OPENs for the destination files and get the correct
1158 # stateid to use in COPY
1159 self.pktt.rewind(open_index)
1160 for dstobj in self.dst_file_list():
1161 self.get_stateid(dstobj.filename, **args, write=True)
1162 if self.opencall is None:
1163 # Search NFSv3 packets
1164 self.find_v3_open(dstobj.filename, dirfh=src_topfh, **args)
1165 dstobj.filehandle = self.filehandle
1166 if self.stateid != self.lock_stateid:
1167 # Don't save the lock stateid in the FileObj
1168 # save it instead in the CopyItem object
1169 dstobj.stateid = self.stateid
1170 save_index = self.pktt.get_index()
1171 # Find correct destination lock stateid
1172 while True:
1173 stateid = self.pkt_locks(self.filehandle, **args)
1174 if stateid is None:
1175 break
1176 for cobj in self.copy_list():
1177 off = self.pktcall.NFSop.offset
1178 if cobj.dst_file == dstobj and cobj.dst_offset == off:
1179 cobj.dst_lstid = stateid
1180 break
1181 self.pktt.rewind(save_index)
1182
1183 # Verify COPY is sent to destination
1184 cindex_list = list(range(ncopies))
1185 save_index = self.pktt.get_index()
1186 for i in range(ncopies):
1187 clone = True
1188 opstr = "CLONE"
1189 self.pktt.rewind(save_index)
1190 # The client may use the CLONE operation first
1191 (pktcall, pktreply) = self.find_nfs_op(OP_CLONE, ipaddr=args["ipaddr"], port=args["port"], status=None)
1192 if pktreply is None or pktreply.nfs.status != NFS4_OK:
1193 # No CLONE operation found or it failed, search for COPY
1194 self.pktt.rewind(save_index)
1195 (p_call, p_reply) = self.find_nfs_op(OP_COPY, ipaddr=args["ipaddr"], port=args["port"], status=None)
1196 if p_call is not None or pktcall is None:
1197 # The COPY operation was found or neither the COPY
1198 # or the CLONE operations were found
1199 clone = False
1200 opstr = "COPY"
1201 pktcall = p_call
1202 pktreply = p_reply
1203 # Old behavior: COPY is sent whether it can copy data or not
1204 # New behavior: COPY is not sent if data cannot be copied
1205 if ncount == 0 and not pktcall:
1206 self.test(not pktcall, "%s may not be sent to %sserver" % (opstr, svrstr))
1207 else:
1208 self.test(pktcall, "%s may be sent to %sserver" % (opstr, svrstr))
1209 if pktcall:
1210 save_index = pktcall.record.index + 1
1211 src_fhandle = pktcall.NFSop.sfh
1212 dst_fhandle = pktcall.NFSop.fh
1213 src_stateid = pktcall.NFSop.src_stateid.other
1214 dst_stateid = pktcall.NFSop.dst_stateid.other
1215 src_offset = pktcall.NFSop.src_offset
1216 dst_offset = pktcall.NFSop.dst_offset
1217
1218 if copy_index is None:
1219 copy_index = pktcall.record.index
1220 else:
1221 copy_index = min(copy_index, pktcall.record.index)
1222
1223 index = 0
1224 if ncopies == 1:
1225 # There should only be one copy so use the first object
1226 copyobj = self.copyitems[0]
1227 if len(copyobj.src_file.cstateid) > 0:
1228 cstateid = copyobj.src_file.cstateid[0]
1229 else:
1230 cstateid = copyobj.src_file.stateid
1231 else:
1232 copyobj = None
1233 # Get the correct copy object
1234 for item in self.copy_list():
1235 if item.src_file.filehandle == src_fhandle and \
1236 item.dst_file.filehandle == dst_fhandle and \
1237 item.src_offset == src_offset and \
1238 item.dst_offset == dst_offset:
1239 copyobj = item
1240 break
1241 index += 1
1242 # Get the correct source state id to use in COPY
1243 cstateid = copyobj.src_file.stateid
1244 for stateid in copyobj.src_file.cstateid:
1245 if stateid == src_stateid:
1246 cstateid = stateid
1247 break
1248
1249 # Search the lock state ids for correct source state id
1250 for item in self.copy_list():
1251 if src_stateid == item.src_lstid:
1252 cstateid = item.src_lstid
1253 break
1254
1255 if copyobj is None:
1256 # Expected COPY was not found, so use next available
1257 copyobj = self.copyitems[cindex_list.pop(0)]
1258 else:
1259 # Save the first COPY index to test the WRITEs are
1260 # sent before the COPY
1261 if copyobj.dst_file.copyidx is None:
1262 copyobj.dst_file.copyidx = pktcall.record.index
1263 else:
1264 copyobj.dst_file.copyidx = min(copyobj.dst_file.copyidx, pktcall.record.index)
1265
1266 try:
1267 # Remove current copy index from list so when copyobj
1268 # is None the next available is used
1269 cindex_list.remove(index)
1270 except:
1271 pass
1272
1273 if samefile and not inter:
1274 copyobj.dst_file.filehandle = copyobj.src_file.filehandle
1275
1276 fmsg = ", expecting 0x%08x but got 0x%08x" % (crc32(copyobj.src_file.filehandle), crc32(src_fhandle))
1277 self.test(src_fhandle == copyobj.src_file.filehandle, "%s should be sent with correct source file handle" % opstr, failmsg=fmsg)
1278 fmsg = ", expecting 0x%08x but got 0x%08x" % (crc32(copyobj.dst_file.filehandle), crc32(dst_fhandle))
1279 self.test(dst_fhandle == copyobj.dst_file.filehandle, "%s should be sent with correct destination file handle" % opstr, failmsg=fmsg)
1280
1281 if samefile and not inter:
1282 dst_stid = src_stateid
1283 elif copyobj.dst_lstid is None:
1284 dst_stid = copyobj.dst_file.stateid
1285 else:
1286 dst_stid = copyobj.dst_lstid
1287 fmsg = ", expecting %s but got %s" % (self.stid_str(cstateid), self.stid_str(src_stateid))
1288 self.test(src_stateid == cstateid, "%s should be sent with correct source stateid" % opstr, failmsg=fmsg)
1289 fmsg = ", expecting %s but got %s" % (self.stid_str(dst_stid), self.stid_str(dst_stateid))
1290 self.test(dst_stateid == dst_stid, "%s should be sent with correct destination stateid" % opstr, failmsg=fmsg)
1291
1292 fmsg = ", expecting %s but got %s" % (copyobj.src_offset, src_offset)
1293 self.test(src_offset == copyobj.src_offset, "%s should be sent with correct source offset" % opstr, failmsg=fmsg)
1294 fmsg = ", expecting %s but got %s" % (copyobj.dst_offset, dst_offset)
1295 self.test(dst_offset == copyobj.dst_offset, "%s should be sent with correct destination offset" % opstr, failmsg=fmsg)
1296 fmsg = ", expecting %s but got %s" % (self.filesize, pktcall.NFSop.count)
1297 # Old behavior: COPY is sent with all bytes: nbytes
1298 # New behavior: COPY is send with the bytes that it could write: ncount
1299 expr = pktcall.NFSop.count in (copyobj.ncount, copyobj.nbytes)
1300 self.test(expr, "%s should be sent with correct number of bytes to copy" % opstr, failmsg=fmsg)
1301
1302 if pktreply:
1303 status = pktreply.NFSop.status
1304 fmsg = ", expecting NFS4_OK but got %s" % status
1305 if samefile and not enforce:
1306 errm = "NFS4ERR_INVAL"
1307 expr = (status == NFS4ERR_INVAL)
1308 if clone:
1309 errm += " or NFS4ERR_NOTSUPP"
1310 expr = (status in (NFS4ERR_INVAL, NFS4ERR_NOTSUPP))
1311 amsg = "%s should failed with %s" % (opstr, errm)
1312 fmsg = ", expecting NFS4ERR_INVAL but got %s" % nfsstat4.get(status, status)
1313 self.test(expr, amsg, failmsg=fmsg)
1314 else:
1315 self.test(status == NFS4_OK, "%s should succeed" % opstr, failmsg=fmsg)
1316 if status != NFS4_OK and enforce:
1317 if clone:
1318 # XXX If CLONE fails with NFS4ERR_NOTSUPP, expecting a COPY
1319 # XXX If CLONE fails with other than NFS4ERR_NOTSUPP???
1320 self.test(False, "COPY should be sent to %sserver when CLONE returns an error" % svrstr)
1321 return
1322
1323 if not clone:
1324 expcount = None
1325 expr = pktreply.NFSop.synchronous
1326 expcount = pktreply.NFSop.count
1327 committed = pktreply.NFSop.committed
1328 verifier = pktreply.NFSop.verifier
1329 if pktreply.NFSop.stateid is None:
1330 # This is a synchronous copy,
1331 # use results from the COPY reply
1332 opstr = "COPY"
1333 self.test(expr, "COPY should return synchronous=1 when no callback id is returned")
1334 else:
1335 # This is an asynchronous copy,
1336 # use results from the CB_OFFLOAD call
1337 opstr = "CB_OFFLOAD"
1338 copyobj.copyid = pktreply.NFSop.stateid
1339 self.test(not expr, "COPY should return synchronous=0 when a callback id is returned")
1340
1341 # Rewind to after the COPY call because the
1342 # CB_OFFLOAD could come before the COPY reply
1343 self.pktt.rewind(pktcall.record.index + 1)
1344
1345 # Look for CB_OFFLOAD to get the actual result of the COPY
1346 mstr = "crc32(nfs.stateid.other) == 0x%08x" % crc32(copyobj.copyid.other)
1347 (pktcall, pktreply) = self.find_nfs_op(OP_CB_OFFLOAD, ipaddr=self.client_ipaddr, port=None, nfs_version=None, match=mstr)
1348 self.test(pktcall, "CB_OFFLOAD should be sent by %sserver when COPY returns synchronous=0" % svrstr)
1349 if pktcall is not None:
1350 ehandle = copyobj.dst_file.filehandle
1351 fhandle = pktcall.NFSop.fh
1352 fmsg = ", expecting 0x%08x but got 0x%08x" % (crc32(ehandle), crc32(fhandle))
1353 self.test(ehandle == fhandle, "CB_OFFLOAD should return the correct file handle", failmsg=fmsg)
1354 status = pktcall.NFSop.status
1355 expcount = pktcall.NFSop.count
1356 if status == NFS4_OK or copyobj.count == 0:
1357 fmsg = ", expecting NFS4_OK but got %s" % status
1358 self.test(status == NFS4_OK, "CB_OFFLOAD should return the correct COPY status", failmsg=fmsg)
1359 if status == NFS4_OK:
1360 committed = pktcall.NFSop.committed
1361 verifier = pktcall.NFSop.verifier
1362 cbid = pktcall.NFSop.info.stateid
1363 fmsg = ""
1364 if cbid is not None:
1365 fmsg = " but got 0x%08x" % crc32(cbid.other)
1366 self.test(cbid is None, "CB_OFFLOAD should not return a callback id", failmsg=fmsg)
1367 if pktreply:
1368 status = pktreply.NFSop.status
1369 fmsg = ", expecting NFS4_OK but got %s" % status
1370 self.test(status == NFS4_OK, "CB_OFFLOAD should be replied by the client with correct status", failmsg=fmsg)
1371 else:
1372 self.test(False, "CB_OFFLOAD reply packet not found")
1373
1374 if expcount is not None:
1375 fmsg = ", expecting %s but got %s" % (copyobj.count, expcount)
1376 self.test(expcount == copyobj.count, "%s should return correct number of bytes actually copied" % opstr, failmsg=fmsg)
1377
1378 fmsg = ", expecting <= %s but got %s" % (copyobj.nbytes, expcount)
1379 self.test(expcount <= copyobj.nbytes, "%s should return at most the number of bytes requested" % opstr, failmsg=fmsg)
1380
1381 ccall = self.getop(pktcall, OP_COMMIT)
1382 if ccall:
1383 # COMMIT is in the same compound as COPY/CB_OFFLOAD
1384 pcall = pktcall
1385 preply = pktreply
1386 self.test(True, "COMMIT is sent to %sserver in the same compound as %s" % (svrstr, opstr))
1387 creply = self.getop(pktreply, OP_COMMIT)
1388 pcall.NFSop = ccall
1389 preply.NFSop = creply
1390 else:
1391 # Search for COMMIT after the COPY/CB_OFFLOAD
1392 mstr = "crc32(nfs.fh) == 0x%08x" % crc32(dst_fhandle)
1393 (pcall, preply) = self.find_nfs_op(OP_COMMIT, ipaddr=args["ipaddr"], port=args["port"], match=mstr)
1394 if committed == UNSTABLE4:
1395 self.test(pcall, "COMMIT should be sent to %sserver when %s returns UNSTABLE4" % (svrstr, opstr))
1396 else:
1397 self.test(not pcall, "COMMIT should not be sent to %sserver when %s does not return UNSTABLE4" % (svrstr, opstr))
1398
1399 if preply:
1400 expr = preply.NFSop.verifier == verifier
1401 self.test(expr, "COMMIT should return the same verifier as the %s" % opstr)
1402 if pcall:
1403 self.pktt.rewind(pcall.record.index + 1)
1404 else:
1405 self.test(False, "%s reply packet not found" % opstr)
1406
1407 # Disable buffered matching
1408 self.pktt.set_pktlist()
1409
1410 if clone:
1411 opstr = "CLONE"
1412 else:
1413 opstr = "COPY"
1414
1415 if (copy_index is None or samefile) and nbytes > 0:
1416 # COPY/CLONE not sent by the client so verify system call
1417 # falls back to copy the file(s) via the client
1418 # Verify client sends the reads to the source server
1419 if svrstr == "":
1420 svr_str = ""
1421 else:
1422 svr_str = "source "
1423 index_map = self.get_io(OP_READ)
1424 for fhandle in index_map.keys():
1425 expr = False
1426 for copyobj in self.copy_list():
1427 if fhandle == copyobj.src_file.filehandle:
1428 expr = True
1429 break
1430 if samefile:
1431 self.test(expr, "READs should be sent to %sserver when %s fails" % (svr_str, opstr))
1432 else:
1433 self.test(expr, "READs should be sent to %sserver when %s is not supported" % (svr_str, opstr))
1434
1435 # Verify client sends the writes to the destination server
1436 index_map = self.get_io(OP_WRITE)
1437 for fhandle in index_map.keys():
1438 expr = False
1439 for copyobj in self.copy_list():
1440 if fhandle == copyobj.dst_file.filehandle:
1441 expr = True
1442 break
1443 if samefile:
1444 self.test(expr, "WRITEs should be sent to %sserver when %s fails" % (svrstr, opstr))
1445 else:
1446 self.test(expr, "WRITEs should be sent to %sserver when %s is not supported" % (svrstr, opstr))
1447 elif copy_index is not None:
1448 # COPY/CLONE is sent by the client
1449 if write:
1450 # Verify all WRITEs are sent before the COPY
1451 index_map = self.get_io(OP_WRITE)
1452 wcount = len(index_map)
1453 for fhandle in index_map.keys():
1454 index = index_map[fhandle]
1455 for copyobj in self.copy_list():
1456 if fhandle == copyobj.dst_file.filehandle:
1457 expr = wcount > 0 and index <= copyobj.dst_file.copyidx
1458 self.test(expr, "WRITEs should be sent to %sserver before the %s" % (svrstr, opstr))
1459 break
1460
1461 if inter and self.dst and diff_server:
1462 svrstr = "source "
1463 else:
1464 svrstr = ""
1465
1466 self.pktt.rewind(copy_index)
1467 self.find_nfs_op(OP_READ, src_ipaddr=self.client_ipaddr, call_only=1)
1468 self.test(not self.pktt.pkt, "READs should not be sent to %sserver after the %s" % (svrstr, opstr))
1469 except Exception:
1470 self.test(False, traceback.format_exc())
1471
1472 #======================================================================
1473 # INTRA Server Side Copy
1474 #======================================================================
1475 def intra01_test(self):
1476 """Verify intra server side COPY succeeds"""
1477 self.test_group("Verify intra server side COPY succeeds")
1478 self.basic_ssc()
1479
1480 def intra02_test(self):
1481 """Verify intra server side COPY succeeds when using source offset"""
1482 self.test_group("Verify intra server side COPY succeeds when using source offset")
1483 self.basic_ssc(src_off=self.s_offset, nbytes=self.s_nbytes)
1484
1485 def intra03_test(self):
1486 """Verify intra server side COPY succeeds when using destination offset"""
1487 self.test_group("Verify intra server side COPY succeeds when using destination offset")
1488 self.basic_ssc(dst_off=int(self.filesize/2))
1489
1490 def intra04_test(self):
1491 """Verify intra server side COPY succeeds when using NULL as source offset"""
1492 self.test_group("Verify intra server side COPY succeeds when using NULL as source offset")
1493 self.basic_ssc(src_off=None, src_seek=self.s_offset, nbytes=self.s_nbytes)
1494
1495 def intra05_test(self):
1496 """Verify intra server side COPY succeeds when using NULL as destination
1497 offset
1498 """
1499 self.test_group("Verify intra server side COPY succeeds when using NULL as destination offset")
1500 self.basic_ssc(dst_off=None, dst_seek=int(self.filesize/2))
1501
1502 def intra06_test(self):
1503 """Verify intra server side COPY succeeds when using count = 0"""
1504 self.test_group("Verify intra server side COPY succeeds when using count = 0")
1505 self.basic_ssc(nbytes=0)
1506
1507 def intra07_test(self):
1508 """Verify intra server side COPY succeeds when the source file is opened
1509 as read/write
1510 """
1511 self.test_group("Verify intra server side COPY succeeds when the source file is opened as read/write")
1512 self.basic_ssc(srcopen=os.O_RDWR)
1513
1514 def intra08_test(self):
1515 """Verify intra server side COPY succeeds when the destination file is
1516 opened as read/write
1517 """
1518 self.test_group("Verify intra server side COPY succeeds when the destination file is opened as read/write")
1519 self.basic_ssc(dstopen=os.O_RDWR|os.O_CREAT)
1520
1521 def intra09_test(self):
1522 """Verify intra server side COPY fails when the source file is opened
1523 as write only
1524 """
1525 self.test_group("Verify intra server side COPY fails when the source file is opened as write only")
1526 self.basic_ssc(srcopen=os.O_WRONLY, failure=errno.EBADF)
1527
1528 def intra10_test(self):
1529 """Verify intra server side COPY fails when the destination file is opened
1530 as read only
1531 """
1532 self.test_group("Verify intra server side COPY fails when the destination file is opened as read only")
1533 self.basic_ssc(dstopen=os.O_RDONLY, failure=errno.EBADF, dstfail=1)
1534
1535 def intra11_test(self):
1536 """Verify intra server side COPY succeeds when source offset is beyond the
1537 end of the file
1538 """
1539 self.test_group("Verify intra server side COPY succeeds when source offset is beyond the end of the file")
1540 msg = "source offset is beyond the end of the file"
1541 self.basic_ssc(src_off=self.filesize, copymsg=msg)
1542
1543 def intra12_test(self):
1544 """Verify intra server side COPY succeeds when source offset plus count
1545 is beyond the end of the file
1546 """
1547 self.test_group("Verify intra server side COPY succeeds when source offset plus count is beyond the end of the file")
1548 msg = "source offset plus count is beyond the end of the file"
1549 self.basic_ssc(src_off=self.s_offset, nbytes=self.filesize, copymsg=msg)
1550
1551 def intra13_test(self):
1552 """Verify intra server side COPY may fail when both source and destination
1553 files point to the same file
1554 """
1555 self.test_group("Verify intra server side COPY may fail when both source and destination files point to the same file")
1556 msg = "both source and destination files point to the same file"
1557 self.test_info("==== %s test 01 (dst_off = 0)" % self.testname)
1558 self.basic_ssc(samefile=1, write=0, failure=errno.EINVAL, enforce=0, copymsg=msg)
1559 self.test_info("==== %s test 02 (dst_off > 0)" % self.testname)
1560 self.basic_ssc(samefile=1, write=0, failure=errno.EINVAL, enforce=0, copymsg=msg, dst_off=int(self.filesize/2))
1561
1562 def intra14_test(self):
1563 """Verify intra server side COPY succeeds when using multiple source and
1564 destination offsets
1565 """
1566 self.test_group("Verify intra server side COPY succeeds when using multiple source and destination offsets")
1567 self.basic_ssc(ncopies=self.ncopies, nbytes=int(self.filesize/self.ncopies), src_doff=1)
1568
1569 def intra15_test(self):
1570 """Verify intra server side COPY succeeds when using multiple source and
1571 destination files
1572 """
1573 self.test_group("Verify intra server side COPY succeeds when using multiple source and destination files")
1574 self.basic_ssc(nsfiles=self.src_files, ndfiles=self.dst_files)
1575
1576 #======================================================================
1577 # INTER Server Side Copy
1578 #======================================================================
1579 def inter01_test(self):
1580 """Verify inter server side COPY succeeds"""
1581 self.test_group("Verify inter server side COPY succeeds")
1582 self.basic_ssc(inter=1)
1583
1584 def inter02_test(self):
1585 """Verify inter server side COPY succeeds when using source offset"""
1586 self.test_group("Verify inter server side COPY succeeds when using source offset")
1587 self.basic_ssc(src_off=self.s_offset, nbytes=self.s_nbytes, inter=1)
1588
1589 def inter03_test(self):
1590 """Verify inter server side COPY succeeds when using destination offset"""
1591 self.test_group("Verify inter server side COPY succeeds when using destination offset")
1592 self.basic_ssc(dst_off=int(self.filesize/2), inter=1)
1593
1594 def inter04_test(self):
1595 """Verify inter server side COPY succeeds when using NULL as source offset"""
1596 self.test_group("Verify inter server side COPY succeeds when using NULL as source offset")
1597 self.basic_ssc(src_off=None, src_seek=self.s_offset, nbytes=self.s_nbytes, inter=1)
1598
1599 def inter05_test(self):
1600 """Verify inter server side COPY succeeds when using NULL as destination
1601 offset
1602 """
1603 self.test_group("Verify inter server side COPY succeeds when using NULL as destination offset")
1604 self.basic_ssc(dst_off=None, dst_seek=int(self.filesize/2), inter=1)
1605
1606 def inter06_test(self):
1607 """Verify inter server side COPY succeeds when using count = 0"""
1608 self.test_group("Verify inter server side COPY succeeds when using count = 0")
1609 self.basic_ssc(nbytes=0, inter=1)
1610
1611 def inter07_test(self):
1612 """Verify inter server side COPY succeeds when the source file is opened
1613 as read/write
1614 """
1615 self.test_group("Verify inter server side COPY succeeds when the source file is opened as read/write")
1616 self.basic_ssc(srcopen=os.O_RDWR, inter=1)
1617
1618 def inter08_test(self):
1619 """Verify inter server side COPY succeeds when the destination file is
1620 opened as read/write
1621 """
1622 self.test_group("Verify inter server side COPY succeeds when the destination file is opened as read/write")
1623 self.basic_ssc(dstopen=os.O_RDWR|os.O_CREAT, inter=1)
1624
1625 def inter09_test(self):
1626 """Verify inter server side COPY fails when the source file is opened
1627 as write only
1628 """
1629 self.test_group("Verify inter server side COPY fails when the source file is opened as write only")
1630 self.basic_ssc(srcopen=os.O_WRONLY, failure=errno.EBADF, inter=1)
1631
1632 def inter10_test(self):
1633 """Verify inter server side COPY fails when the destination file is opened
1634 as read only
1635 """
1636 self.test_group("Verify inter server side COPY fails when the destination file is opened as read only")
1637 self.basic_ssc(dstopen=os.O_RDONLY, failure=errno.EBADF, dstfail=1, inter=1)
1638
1639 def inter11_test(self):
1640 """Verify inter server side COPY succeeds when source offset is beyond the
1641 end of the file
1642 """
1643 self.test_group("Verify inter server side COPY succeeds when source offset is beyond the end of the file")
1644 msg = "source offset is beyond the end of the file"
1645 self.basic_ssc(src_off=self.filesize, copymsg=msg, inter=1)
1646
1647 def inter12_test(self):
1648 """Verify inter server side COPY succeeds when source offset plus count
1649 is beyond the end of the file
1650 """
1651 self.test_group("Verify inter server side COPY succeeds when source offset plus count is beyond the end of the file")
1652 msg = "source offset plus count is beyond the end of the file"
1653 self.basic_ssc(src_off=self.s_offset, nbytes=self.filesize, copymsg=msg, inter=1)
1654
1655 def inter13_test(self):
1656 """Verify inter server side COPY succeeds when both source and destination
1657 file names are the same
1658 """
1659 self.test_group("Verify inter server side COPY succeeds when both source and destination file names are the same")
1660 msg = "both source and destination file names are the same"
1661 self.basic_ssc(samefile=1, copymsg=msg, inter=1)
1662
1663 def inter14_test(self):
1664 """Verify inter server side COPY succeeds when using multiple source and
1665 destination offsets
1666 """
1667 self.test_group("Verify inter server side COPY succeeds when using multiple source and destination offsets")
1668 self.basic_ssc(ncopies=self.ncopies, nbytes=int(self.filesize/self.ncopies), src_doff=1, inter=1)
1669
1670 def inter15_test(self):
1671 """Verify inter server side COPY succeeds when using multiple source and
1672 destination files
1673 """
1674 self.test_group("Verify inter server side COPY succeeds when using multiple source and destination files")
1675 self.basic_ssc(nsfiles=self.src_files, ndfiles=self.dst_files, inter=1)
1676
1677 ################################################################################
1678 # Entry point
1679 x = SSCTest(usage=USAGE, testnames=TESTNAMES, testgroups=TESTGROUPS, sid=SCRIPT_ID)
1680
1681 try:
1682 x.setup()
1683
1684 # Run all the tests
1685 x.run_tests()
1686 except Exception:
1687 x.test(False, traceback.format_exc())
1688 finally:
1689 x.cleanup()
1690 x.exit()