From caf5faf55670ab212868498e421bedc074fafd89 Mon Sep 17 00:00:00 2001 From: Pierre Libeau Date: Fri, 6 Aug 2021 09:01:40 +0000 Subject: [PATCH] Move file system freeze after end of mirroring The file system before the start of mirroring generates kernel task blocked for more than 120 seconds. The file system freeze after the start of mirroring and just before stopping the mirror between the original disk and copy of disk reduce the time of the freeze. Related-Bug: #1939116 Change-Id: I067382ec676b65f8698772a262c5e4cea7a1216d --- nova/tests/unit/virt/libvirt/test_driver.py | 8 +++--- nova/virt/libvirt/driver.py | 27 +++++++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 4062d96604..7cdc6e114e 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -19715,9 +19715,10 @@ class LibvirtConnTestCase(test.NoDBTestCase, mock.patch('nova.virt.libvirt.utils.get_disk_backing_file'), mock.patch('nova.virt.libvirt.utils.create_cow_image'), mock.patch('nova.virt.libvirt.utils.extract_snapshot'), - mock.patch.object(drvr, '_set_quiesced') + mock.patch.object(drvr, '_set_quiesced'), + mock.patch.object(drvr, '_can_quiesce') ) as (mock_define, mock_size, mock_backing, mock_create_cow, - mock_snapshot, mock_quiesce): + mock_snapshot, mock_quiesce, mock_can_quiesce): xmldoc = "" srcfile = "/first/path" @@ -19732,7 +19733,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, guest = libvirt_guest.Guest(mock_dom) if not can_quiesce: - mock_quiesce.side_effect = ( + mock_can_quiesce.side_effect = ( exception.InstanceQuiesceNotSupported( instance_id=self.test_instance['id'], reason='test')) @@ -19763,6 +19764,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, mock_define.assert_called_once_with(xmldoc) mock_quiesce.assert_any_call(mock.ANY, self.test_instance, mock.ANY, True) + if can_quiesce: mock_quiesce.assert_any_call(mock.ANY, self.test_instance, mock.ANY, False) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 65f4e44f27..187182375d 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -3164,14 +3164,15 @@ class LibvirtDriver(driver.ComputeDriver): libvirt_utils.create_cow_image(src_back_path, disk_delta, src_disk_size) - quiesced = False try: - self._set_quiesced(context, instance, image_meta, True) - quiesced = True + self._can_quiesce(instance, image_meta) except exception.NovaException as err: - if self._requires_quiesce(image_meta): + if image_meta.properties.get('os_require_quiesce', False): + LOG.error('Quiescing instance failed but image property ' + '"os_require_quiesce" is set: %(reason)s.', + {'reason': err}, instance=instance) raise - LOG.info('Skipping quiescing instance: %(reason)s.', + LOG.info('Quiescing instance not available: %(reason)s.', {'reason': err}, instance=instance) try: @@ -3192,12 +3193,24 @@ class LibvirtDriver(driver.ComputeDriver): while not dev.is_job_complete(): time.sleep(0.5) + finally: + quiesced = False + try: + # NOTE: The freeze FS is applied after the end of + # the mirroring of the disk to minimize the time of + # the freeze. The mirror between both disks is finished, + # sync continuously, and stopped after abort_job(). + self.quiesce(context, instance, image_meta) + quiesced = True + except exception.NovaException as err: + LOG.info('Skipping quiescing instance: %(reason)s.', + {'reason': err}, instance=instance) + dev.abort_job() nova.privsep.path.chown(disk_delta, uid=os.getuid()) - finally: self._host.write_instance_config(xml) if quiesced: - self._set_quiesced(context, instance, image_meta, False) + self.unquiesce(context, instance, image_meta) # Convert the delta (CoW) image with a backing file to a flat # image with no backing file.