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