From d8aee57e7b17412d955f94fc44a520d4ae99c8e6 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 14 Mar 2010 01:55:15 +0100 Subject: [PATCH] ConfigWriter: add an LV reservation manager This patch adds an LV reservation manager to be used for LV names. Since we now have four such managers, we create a list for easier release. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/config.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/config.py b/lib/config.py index d1f061c36..c0dc69d46 100644 --- a/lib/config.py +++ b/lib/config.py @@ -125,6 +125,9 @@ class TemporaryReservationManager: class ConfigWriter: """The interface to the cluster configuration. + @ivar _temporary_lvs: reservation manager for temporary LVs + @ivar _all_rms: a list of all temporary reservation managers + """ def __init__(self, cfg_file=None, offline=False): self.write_count = 0 @@ -139,6 +142,9 @@ class ConfigWriter: self._temporary_drbds = {} self._temporary_macs = TemporaryReservationManager() self._temporary_secrets = TemporaryReservationManager() + self._temporary_lvs = TemporaryReservationManager() + self._all_rms = [self._temporary_ids, self._temporary_macs, + self._temporary_secrets, self._temporary_lvs] # Note: in order to prevent errors when resolving our name in # _DistributeConfig, we compute it here once and reuse it; it's # better to raise an error before starting to modify the config @@ -190,6 +196,20 @@ class ConfigWriter: else: self._temporary_macs.Reserve(mac, ec_id) + @locking.ssynchronized(_config_lock, shared=1) + def ReserveLV(self, lv_name, ec_id): + """Reserve an VG/LV pair for an instance. + + @type lv_name: string + @param lv_name: the logical volume name to reserve + + """ + all_lvs = self._AllLVs() + if lv_name in all_lvs: + raise errors.ReservationError("LV already in use") + else: + self._temporary_lvs.Reserve(lv_name, ec_id) + @locking.ssynchronized(_config_lock, shared=1) def GenerateDRBDSecret(self, ec_id): """Generate a DRBD secret. @@ -1451,6 +1471,5 @@ class ConfigWriter: """Drop per-execution-context reservations """ - self._temporary_ids.DropECReservations(ec_id) - self._temporary_macs.DropECReservations(ec_id) - self._temporary_secrets.DropECReservations(ec_id) + for rm in self._all_rms: + rm.DropECReservations(ec_id) -- GitLab