New: Fast copy using reflink on btrfs volumes

Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
Taloth Saldono
2020-06-10 20:48:54 +02:00
committed by Qstick
parent 4af4d45873
commit 7002628514
7 changed files with 358 additions and 4 deletions
@@ -284,18 +284,45 @@ namespace NzbDrone.Common.Disk
var targetDriveFormat = targetMount?.DriveFormat ?? string.Empty;
var isCifs = targetDriveFormat == "cifs";
var isBtrfs = sourceDriveFormat == "btrfs" && targetDriveFormat == "btrfs";
if (mode.HasFlag(TransferMode.Copy))
{
if (isBtrfs)
{
if (_diskProvider.TryCreateRefLink(sourcePath, targetPath))
{
return TransferMode.Copy;
}
}
TryCopyFileVerified(sourcePath, targetPath, originalSize);
return TransferMode.Copy;
}
if (mode.HasFlag(TransferMode.Move))
{
if (isBtrfs)
{
if (isSameMount && _diskProvider.TryRenameFile(sourcePath, targetPath))
{
_logger.Trace("Renamed [{0}] to [{1}].", sourcePath, targetPath);
return TransferMode.Move;
}
if (_diskProvider.TryCreateRefLink(sourcePath, targetPath))
{
_logger.Trace("Reflink successful, deleting source [{0}].", sourcePath);
_diskProvider.DeleteFile(sourcePath);
return TransferMode.Move;
}
}
if (isCifs && !isSameMount)
{
_logger.Trace("On cifs mount. Starting verified copy [{0}] to [{1}].", sourcePath, targetPath);
TryCopyFileVerified(sourcePath, targetPath, originalSize);
_logger.Trace("Copy successful, deleting source [{0}].", sourcePath);
_diskProvider.DeleteFile(sourcePath);
return TransferMode.Move;
}