From 40a1fefcf952e442d85271baca9ea4f57e4ba3eb Mon Sep 17 00:00:00 2001 From: abhishekkekane Date: Fri, 3 Apr 2015 00:24:38 -0700 Subject: [PATCH] Truncate instance files before deleting In the resize operation, during copying files from source to destination compute node scp/rsync processes are not aborted after the instance is deleted because linux kernel doesn't delete instance files physically until all processes using the file handle is closed completely. Hence rsync/scp process keeps on running until it transfers 100% of file data. In this patch truncate command is used to set the size of the file to 0 bytes before deleting the instance files in the delete operation. It aborts rsync/scp process and doesn't copy the file to the destination node. Previously rsync/scp copies 100% of file data but after adding truncate command, if the instance is deleted during copying files using rsync process doesn't copy the disk file. Also timing wise, rsync/scp processes are aborted early as compared to copying 100% of file but the difference is not that big, it's merely 10-15% gain in time. DocImpact: Add following command in compute.filters truncate: CommandFilter, truncate, root Closes-bug: #1387543 --- etc/nova/rootwrap.d/compute.filters | 3 +++ nova/virt/libvirt/driver.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/etc/nova/rootwrap.d/compute.filters b/etc/nova/rootwrap.d/compute.filters index acb5b25..8945aad 100644 --- a/etc/nova/rootwrap.d/compute.filters +++ b/etc/nova/rootwrap.d/compute.filters @@ -235,3 +235,6 @@ ploop: CommandFilter, ploop, root # nova/virt/libvirt/utils.py: 'xend', 'status' xend: CommandFilter, xend, root + +# nova/virt/libvirt/driver.py: +truncate: CommandFilter, truncate, root diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index eedd51f..42d2a90 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -6623,6 +6623,13 @@ class LibvirtDriver(driver.ComputeDriver): instance=instance) remaining_path = target_del try: + # truncate the instance files to 0 size + for dir_name, __, file_list in os.walk(target_del): + for file_name in file_list: + file_path = "%s/%s" % (dir_name, file_name) + utils.execute('truncate', '-s', '0', file_path, + run_as_root=True) + shutil.rmtree(target_del) except OSError as e: LOG.error(_LE('Failed to cleanup directory %(target)s: ' -- 1.9.1