Beispiel #1
0
def handle_exception(options, ex):
    """ Handles the given exceptions by printing an
        warning if force is active or raising it
    """
    if options.force:
        log_warning(options, ex)
    else:
        raise
Beispiel #2
0
def unregister_targets_direct(options, config):
    """ unregister a given configured at SCST. This
	function bypasses the information given by the monitor. Therefore
	this function can be used to unregister a target if dedupv1d is not
	available
    """
    try:
        for (tid, t) in iscsi_scst.get_targets().items():
            try:
                log_verbose(options, "Remove target %s" % (t.name()))
                iscsi_scst.unregister_target(t)
            except scst.ScstException as e:
                log_warning(options, "Failed to unregister target %s: %s" % (t.name(), str(e)))
    except scst.ScstException as e:
        log_warning("Failed to unregister targets: %s" % (str(e)))
Beispiel #3
0
def unregister_targets(monitor, options, config):
    """ unregisters the targets configured at SCST. This
	function bypasses the information given by the monitor. Therefore
	this function can be used to unregister the targets if dedupv1d is not
	available
    """
    try:
        for (tid, t) in target.read_all_targets(monitor).items():
            try:
                if iscsi_scst.is_target_registered(t):
                    iscsi_scst.unregister_target(t)

                group_name = "Default_" + t.name()
                if len(t.volumes()) > 0 and scst.exists_group(group_name):
                    scst.rm_group(group_name)

                log_verbose(options, "Target %s unregistered" % t.name())
            except scst.ScstException as e:
                if options.force:
                    log_warning("Failed to unregister target %s: %s" % (t.name(), str(e)))
                else:
                    raise scst.ScstException("Failed to unregister target %s" % (t.name()), e)
    except IOError as e:
        handle_exception(options, e)
Beispiel #4
0
def stop_device(dedupv1_root, monitor, options, config, writeback_stop = False):
    """ stops dedupv1d.
        This function can take a very long time to finish when writeback_stop is True. In this case
        the dedup1d is not existing before all open chunk and block index data is written into the persistent index
    """
    def on_stop():
        dirty_file = config.get("daemon.dirtyfile")

        if os.path.exists(dirty_file):
            dirty_data = DirtyFileData()
            content = open(dirty_file, "r").read()
            read_sized_message(dirty_data, content)
            if not dirty_data.stopped:
                raise Exception("dedupv1d stopped with errors")
        log_info(options, "\ndedupv1d stopped")

    lock_filename = config.get("daemon.lockfile")
    pid = None
    not_running = not is_running(config)
    if not_running:
        if options.force:
            log_warning(options, "dedupv1d not running")
        else:
            raise Exception("dedupv1d not running")
    else:
        pid = get_daemon_pid(config)

    try:
        session_count = 0
        for (tid, t) in iscsi_scst.get_targets().items():
            session_count = session_count + len(t["sessions"])
            for session in t["sessions"]:
                log_warning(options, "Target %s has still open session with initiator %s" % (t["name"], session["initiator"]))

        if session_count > 0:
            if options.force:
                log_warning(options, "iSCSI targets have still open sessions")
            else:
                raise Exception("iSCSI targets have still open sessions")

    except scst.ScstException as e:
        handle_exception(options, e)

    if options.force:
        try:
            unregister_users(monitor, options, config)
        except Exception as e:
            if not_running:
                log_verbose(options, "Unregister users failed")
            else:
                log_warning(options, "Unregister users failed")

        try:
            unregister_volumes(monitor, options, config)
        except Exception as e:
            if not_running:
                log_verbose(options, "Unregister volumes failed")
            else:
                log_warning(options, "Unregister volumes failed")

        try:
            unregister_targets(monitor, options, config)
        except:
            if not_running:
                log_verbose(options, "Unregister targets failed")
            else:
                log_warning(options, "Unregister targets failed")

        try:
            unregister_groups(monitor, options, config)
        except:
            if not_running:
                log_verbose(options, "Unregister groups failed")
            else:
                log_warning(options, "Unregister groups failed")
    else:
        unregister_users(monitor, options, config)
        unregister_volumes(monitor, options, config)
        unregister_targets(monitor, options, config)
        unregister_groups(monitor, options, config)

    try:
        new_state = "stop"
        if writeback_stop:
            new_state = "writeback-stop"
        try:
            monitor.read("status", [("change-state", new_state)])
        except MonitorException:
            if not options.force:
                raise

    except OSError:
        if options.force:
            log_warning(options, "dedupv1d crashed")
    try:
        if pid:
            # Here we do trick with with the dots so we dont
            # se log_info, but it should only be done when not in
            # raw mode
            if not options.raw:
                print "dedupv1d stopping",

            for i in xrange(128):
                if not is_process_running(pid):
                    on_stop()
                    break
                if not options.raw:
                    sys.stdout.write(".")
                    sys.stdout.flush()
                time.sleep(2 * i) #exp backoff
    finally:
        # We have to remove the lock file here, cause the daemon
        # might not have the permission to do it. The file is created by
        # the daemon starting process with the uid of this script, but the
        # daemon might run under a different uid.
        if os.path.exists(lock_filename):
            os.remove(lock_filename)