def umount(self, directory_set = None): """Unmounts the mount points in our target. On error returns a set containing the directories that could not be unmounted""" # Go through all the mount points that we recorded during the mount # function if directory_set == None: directory_set = set() loop_tries = 8 for x in range(0, loop_tries): local_set = set() for mount_point in self.mounted: if os.path.exists(mount_point): result = pdk_utils.umount(mount_point) if not result: local_set.add(mount_point) pdk_utils.umountAllInPath(self.path, local_set) if not local_set: # Success. All directories could be un-mounted break else: for directory in local_set: print _("Failed to umount FileSystem directory: %s") % directory cmd_line = "lsof | grep %s" % directory print _("Execing: %s") % cmd_line os.system(cmd_line) print _("Sleeping for 5 seconds, try %s of %s") % (x+1, loop_tries) time.sleep(5) directory_set.update(local_set) return directory_set
def umount_container(self): if self.tmp_path: result = pdk_utils.umount(self.tmp_path) if not result: print >> sys.stderr, _("Error unmounting: %s") % self.tmp_path raise EnvironmentError, _("Error unmounting: %s") % self.tmp_path os.rmdir(self.tmp_path) self.tmp_path = ''
def delete_target(self, name, do_pop=True, callback = None): target = self.targets[name] self.umountTarget(target) seen_paths = [] while True: try: pdk_utils.rmtree(os.path.join(self.path, 'targets', name), callback = callback) break except OSError, e: # See if we get a resource busy error, if so we think it is a # mounted filesystem issue if e.errno == errno.EBUSY: if e.filename in seen_paths: raise OSError, e else: seen_paths.append(e.filename) pdk_utils.umount(e.filename) else: raise OSError, e