diff options
| author | Rick Harris <rconradharris@gmail.com> | 2012-02-27 21:01:49 +0000 |
|---|---|---|
| committer | Rick Harris <rconradharris@gmail.com> | 2012-02-27 21:14:48 +0000 |
| commit | 6315eb5086a96e4ba614ba01c9bbfaec8bd8504b (patch) | |
| tree | 4361a2edfe4c8b1f8333bacef51c0c503c894adf /nova/virt | |
| parent | b88cd9439c2d655b4dcf5e6cb214a1e4aeffa9b7 (diff) | |
| download | nova-6315eb5086a96e4ba614ba01c9bbfaec8bd8504b.tar.gz nova-6315eb5086a96e4ba614ba01c9bbfaec8bd8504b.tar.xz nova-6315eb5086a96e4ba614ba01c9bbfaec8bd8504b.zip | |
Adds temporary chown to sparse_copy.
`sparse_copy` needs read and write access to the devices. Since we
cannot shell out to a run-as-root command here, we temporarily take
ownership of the device.
Change-Id: I891c38dbcba7177286dca729684c88ac065bd085
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/xenapi/vm_utils.py | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index e000e4ab1..3c5264f97 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -1651,25 +1651,30 @@ def _sparse_copy(src_path, dst_path, virtual_size, block_size=4096): "virtual_size=%(virtual_size)d block_size=%(block_size)d"), locals()) - with open(src_path, "r") as src: - with open(dst_path, "w") as dst: - data = src.read(min(block_size, left)) - while data: - if data == EMPTY_BLOCK: - dst.seek(block_size, os.SEEK_CUR) - left -= block_size - bytes_read += block_size - skipped_bytes += block_size - else: - dst.write(data) - data_len = len(data) - left -= data_len - bytes_read += data_len - - if left <= 0: - break - - data = src.read(min(block_size, left)) + # NOTE(sirp): we need read/write access to the devices; since we don't have + # the luxury of shelling out to a sudo'd command, we temporarily take + # ownership of the devices. + with utils.temporary_chown(src_path): + with utils.temporary_chown(dst_path): + with open(src_path, "r") as src: + with open(dst_path, "w") as dst: + data = src.read(min(block_size, left)) + while data: + if data == EMPTY_BLOCK: + dst.seek(block_size, os.SEEK_CUR) + left -= block_size + bytes_read += block_size + skipped_bytes += block_size + else: + dst.write(data) + data_len = len(data) + left -= data_len + bytes_read += data_len + + if left <= 0: + break + + data = src.read(min(block_size, left)) duration = time.time() - start_time compression_pct = float(skipped_bytes) / bytes_read * 100 |
