storage/reflink: factor out _ficlone()

This commit is contained in:
Rusty Bird 2018-09-11 23:50:13 +00:00
parent 69af0a48ec
commit edda3a1734
No known key found for this signature in database
GPG Key ID: 469D78F47AAF2ADF

View File

@ -403,6 +403,13 @@ def _update_loopdev_sizes(img):
with open('/dev/' + sys_path.split('/')[3]) as dev_io: with open('/dev/' + sys_path.split('/')[3]) as dev_io:
fcntl.ioctl(dev_io.fileno(), LOOP_SET_CAPACITY) fcntl.ioctl(dev_io.fileno(), LOOP_SET_CAPACITY)
def _attempt_ficlone(src, dst):
try:
fcntl.ioctl(dst.fileno(), FICLONE, src.fileno())
return True
except OSError:
return False
def _copy_file(src, dst): def _copy_file(src, dst):
''' Copy src to dst as a reflink if possible, sparse if not. ''' ''' Copy src to dst as a reflink if possible, sparse if not. '''
if not os.path.exists(src): if not os.path.exists(src):
@ -424,9 +431,4 @@ def is_reflink_supported(dst_dir, src_dir=None):
dst = tempfile.TemporaryFile(dir=dst_dir) dst = tempfile.TemporaryFile(dir=dst_dir)
src = tempfile.TemporaryFile(dir=src_dir) src = tempfile.TemporaryFile(dir=src_dir)
src.write(b'foo') # don't let any filesystem get clever with empty files src.write(b'foo') # don't let any filesystem get clever with empty files
return _attempt_ficlone(src, dst)
try:
fcntl.ioctl(dst.fileno(), FICLONE, src.fileno())
return True
except OSError:
return False