Revision a2771c83

b/lib/hypervisor/hv_chroot.py
180 180
      - finally unmount the instance dir
181 181

  
182 182
    """
183
    if retry:
184
      return
185 183
    root_dir = "%s/%s" % (self._ROOT_DIR, instance.name)
186
    if not os.path.exists(root_dir):
184
    if not os.path.exists(root_dir) or not self._IsDirLive(root_dir):
187 185
      return
188 186

  
189
    if self._IsDirLive(root_dir):
187
    # Run the chroot stop script only once
188
    if not retry and not force:
190 189
      result = utils.RunCmd(["chroot", root_dir, "/ganeti-chroot", "stop"])
191 190
      if result.failed:
192 191
        raise HypervisorError("Can't run the chroot stop script: %s" %
193 192
                              result.output)
194
      retry = 20
195
      while not force and self._IsDirLive(root_dir) and retry > 0:
196
        time.sleep(1)
197
        retry -= 1
198
        if retry < 10:
199
          result = utils.RunCmd(["fuser", "-k", "-TERM", "-m", root_dir])
200
      retry = 5
201
      while force and self._IsDirLive(root_dir) and retry > 0:
202
        time.sleep(1)
203
        retry -= 1
204
        utils.RunCmd(["fuser", "-k", "-KILL", "-m", root_dir])
205
      if self._IsDirLive(root_dir):
193

  
194
    if not force:
195
      utils.RunCmd(["fuser", "-k", "-TERM", "-m", root_dir])
196
    else:
197
      utils.RunCmd(["fuser", "-k", "-KILL", "-m", root_dir])
198
      # 2 seconds at most should be enough for KILL to take action
199
      time.sleep(2)
200

  
201
    if self._IsDirLive(root_dir):
202
      if force:
206 203
        raise HypervisorError("Can't stop the processes using the chroot")
204
      return
205

  
207 206
    for mpath in self._GetMountSubdirs(root_dir):
208 207
      utils.RunCmd(["umount", mpath])
209
    retry = 10
210
    while retry > 0:
211
      result = utils.RunCmd(["umount", root_dir])
212
      if not result.failed:
213
        break
214
      retry -= 1
215
      time.sleep(1)
216
    if result.failed:
217
      logging.error("Processes still alive in the chroot: %s",
218
                    utils.RunCmd("fuser -vm %s" % root_dir).output)
219
      raise HypervisorError("Can't umount the chroot dir: %s" % result.output)
208

  
209
    result = utils.RunCmd(["umount", root_dir])
210
    if result.failed and force:
211
      msg = ("Processes still alive in the chroot: %s" %
212
             utils.RunCmd("fuser -vm %s" % root_dir).output)
213
      logging.error(msg)
214
      raise HypervisorError("Can't umount the chroot dir: %s (%s)" %
215
                            (result.output, msg))
220 216

  
221 217
  def RebootInstance(self, instance):
222 218
    """Reboot an instance.

Also available in: Unified diff