Copy data from one regular mmap-like fd to another by using a high-performance copy_file_range(2) syscall that gives filesystems an opportunity to implement the use of reflinks or server-side copy. This should work on Linux >= 4.5 only.
(source_fd, target_fd)
| 65 | |
| 66 | if hasattr(os, 'copy_file_range'): |
| 67 | def _copy_file_range(source_fd, target_fd): |
| 68 | """ |
| 69 | Copy data from one regular mmap-like fd to another by using a |
| 70 | high-performance copy_file_range(2) syscall that gives filesystems |
| 71 | an opportunity to implement the use of reflinks or server-side |
| 72 | copy. |
| 73 | This should work on Linux >= 4.5 only. |
| 74 | """ |
| 75 | blocksize = _get_copy_blocksize(source_fd) |
| 76 | offset = 0 |
| 77 | while True: |
| 78 | sent = os.copy_file_range(source_fd, target_fd, blocksize, |
| 79 | offset_dst=offset) |
| 80 | if sent == 0: |
| 81 | break # EOF |
| 82 | offset += sent |
| 83 | else: |
| 84 | _copy_file_range = None |
| 85 |
no test coverage detected