Revision 7548396c

b/lib/hypervisor/hv_kvm.py
45 45

  
46 46
  _ROOT_DIR = constants.RUN_GANETI_DIR + "/kvm-hypervisor"
47 47
  _PIDS_DIR = _ROOT_DIR + "/pid" # contains live instances pids
48
  _UIDS_DIR = _ROOT_DIR + "/uid" # contains instances reserved uids
48 49
  _CTRL_DIR = _ROOT_DIR + "/ctrl" # contains instances control sockets
49 50
  _CONF_DIR = _ROOT_DIR + "/conf" # contains instances startup data
50
  _DIRS = [_ROOT_DIR, _PIDS_DIR, _CTRL_DIR, _CONF_DIR]
51
  _DIRS = [_ROOT_DIR, _PIDS_DIR, _UIDS_DIR, _CTRL_DIR, _CONF_DIR]
51 52

  
52 53
  PARAMETERS = {
53 54
    constants.HV_KERNEL_PATH: hv_base.OPT_FILE_CHECK,
......
110 111
    return utils.PathJoin(cls._PIDS_DIR, instance_name)
111 112

  
112 113
  @classmethod
114
  def _InstanceUidFile(cls, instance_name):
115
    """Returns the instance uidfile.
116

  
117
    """
118
    return utils.PathJoin(cls._UIDS_DIR, instance_name)
119

  
120
  @classmethod
113 121
  def _InstancePidInfo(cls, pid):
114 122
    """Check pid file for instance information.
115 123

  
......
218 226
    return utils.PathJoin(cls._CONF_DIR, "%s.runtime" % instance_name)
219 227

  
220 228
  @classmethod
229
  def _TryReadUidFile(cls, uid_file):
230
    """Try to read a uid file
231

  
232
    """
233
    if os.path.exists(uid_file):
234
      try:
235
        uid = int(utils.ReadFile(uid_file))
236
      except EnvironmentError:
237
        logging.warning("Can't read uid file", exc_info=True)
238
        return None
239
      except (TypeError, ValueError):
240
        logging.warning("Can't parse uid file contents", exc_info=True)
241
        return None
242
    return uid
243

  
244
  @classmethod
221 245
  def _RemoveInstanceRuntimeFiles(cls, pidfile, instance_name):
222 246
    """Removes an instance's rutime sockets/files.
223 247

  
......
226 250
    utils.RemoveFile(cls._InstanceMonitor(instance_name))
227 251
    utils.RemoveFile(cls._InstanceSerial(instance_name))
228 252
    utils.RemoveFile(cls._InstanceKVMRuntime(instance_name))
253
    uid_file = cls._InstanceUidFile(instance_name)
254
    uid = cls._TryReadUidFile(uid_file)
255
    utils.RemoveFile(uid_file)
256
    if uid is not None:
257
      uidpool.ReleaseUid(uid)
229 258

  
230 259
  def _WriteNetScript(self, instance, seq, nic):
231 260
    """Write a script to connect a net interface to the proper bridge.

Also available in: Unified diff