From 6da9686ca64ef2a559d7120910d15cb495bc3b50 Mon Sep 17 00:00:00 2001 From: Zhiteng Huang Date: Wed, 21 Nov 2012 01:02:37 +0800 Subject: [PATCH] Remove redundant db.volume_update() in volume manager create_volume() Since scheduler has already updated db to set the 'host' field and recorded 'scheduled_at' time, it's not necessary to do db.volume_update() again in volume manager create_volume() method. Also let volume api to update db when creating volume from snapshot while snapshot_same_host is true, thus the behavior is consistent (updating db when placement decision is made). Change-Id: I43aaee8e2a5d0ceadb98bd608cc147467488349e --- cinder/tests/test_volume.py | 1 + cinder/volume/api.py | 8 +++++--- cinder/volume/manager.py | 3 --- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 2b1231330..c5188d8e2 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -85,6 +85,7 @@ class VolumeTestCase(test.TestCase): vol['availability_zone'] = FLAGS.storage_availability_zone vol['status'] = "creating" vol['attach_status'] = "detached" + vol['host'] = FLAGS.host if metadata is not None: vol['metadata'] = metadata return db.volume_create(context.get_admin_context(), vol) diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 627f17b35..1bdb165cf 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -207,12 +207,14 @@ class API(base.Base): snapshot_ref = self.db.snapshot_get(context, snapshot_id) src_volume_ref = self.db.volume_get(context, snapshot_ref['volume_id']) - volume_ref = self.db.volume_get(context, - volume_id) + now = timeutils.utcnow() + values = {'host': src_volume_ref['host'], 'scheduled_at': now} + volume_ref = self.db.volume_update(context, volume_id, values) + # bypass scheduler and send request directly to volume self.volume_rpcapi.create_volume(context, volume_ref, - src_volume_ref['host'], + volume_ref['host'], snapshot_id, image_id) else: diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 7e5c2bb56..40913763b 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -125,9 +125,6 @@ class VolumeManager(manager.SchedulerDependentManager): self._notify_about_volume_usage(context, volume_ref, "create.start") LOG.info(_("volume %s: creating"), volume_ref['name']) - self.db.volume_update(context, - volume_id, - {'host': self.host}) # NOTE(vish): so we don't have to get volume from db again # before passing it to the driver. volume_ref['host'] = self.host -- 2.45.2