Beispiel #1
0
def is_rotational_device(device):
    """Returns whether the given device is a rotational device.

    Args:
        device: The device.

    Returns:
        True if is a rotational device, else False.
    """
    printf('Checking whether device {} is a rotational device'.format(device),
           print_type=PrintType.DEBUG_LOG)

    device_name = match_regex(device, 'device_name')

    if not device_name:
        return False

    out, rc = run_command(
        'cat /sys/block/{}/queue/rotational'.format(device_name))

    if rc != 0:
        return False

    if int(out) == 1:
        printf('Device {} is a rotational device'.format(device),
               print_type=PrintType.DEBUG_LOG)
    else:
        printf('Device {} is not a rotational device'.format(device),
               print_type=PrintType.DEBUG_LOG)

    return int(out) == 1
Beispiel #2
0
def get_device_scheduler(device):
    """Returns the current scheduler for the device.

    Args:
        device: The device.

    Returns:
        The current scheduler.
    """
    printf('Retrieving schedulers for device {}'.format(device),
           print_type=PrintType.DEBUG_LOG)

    device_name = match_regex(device, 'device_name')

    out, rc = run_command(
        'cat /sys/block/{}/queue/scheduler'.format(device_name))

    if rc != 0:
        printf('Unable to find schedulers for device',
               print_type=PrintType.ERROR_LOG)
        return []

    l, r = out.index('['), out.index(']')
    ret = out[l + 1:r]

    printf('Found the current scheduler for device {}: '
           '{}'.format(device, ret),
           print_type=PrintType.DEBUG_LOG)

    return ret
Beispiel #3
0
def get_schedulers_for_device(device):
    """Returns a list of available schedulers for a given device.

    Args:
        device: The device.

    Returns:
        A list of schedulers.
    """
    printf('Retrieving schedulers for device {}'.format(device),
           print_type=PrintType.DEBUG_LOG)

    device_name = match_regex(device, 'device_name')

    out, rc = run_command(
        'cat /sys/block/{}/queue/scheduler'.format(device_name))

    if rc != 0:
        printf('Unable to find schedulers for device',
               print_type=PrintType.ERROR_LOG)
        return []

    ret = out.strip().replace('[', '').replace(']', '')

    printf('Found the following schedulers for device {}: '
           '{}'.format(device, ret),
           print_type=PrintType.DEBUG_LOG)

    return ret.split()
Beispiel #4
0
    def _try_process(self, job_type, file, device, scheduler, enable_blktrace):
        """Attempts to process a job with retrying if failure.

        Args:
            job_type: The job type.
            file: The input file.
            device: The device to execute on.
            scheduler: The scheduler to execute with.
            enable_blktrace: Whether blktrace is enabled.

        Returns:
            The output of processing the job.

        Raises:
            RetryCountExceededError: If job fails and retry counts are exceeded.
        """
        retry_count = SettingsManager.get('retry_count')

        for retry in range(retry_count):
            if retry != 0:
                printf('Retrying job...', print_type=PrintType.DEBUG_LOG)

            job = job_type(file, device, scheduler)

            try:
                ret = job.process(enable_blktrace)

                if SettingsManager.get('cleanup_files'):
                    device_name = match_regex(device, 'device_name')
                    files = get_formatter('cleanup_blktrace').format(
                        device_name)
                    cleanup_files(files)

                return ret
            except (JobExecutionError, OutputParsingError) as err:
                printf('Unable to run job \n{}'.format(err),
                       print_type=PrintType.ERROR_LOG)

        raise RetryCountExceededError(
            'Unable to run job, exceeded retry counts')
Beispiel #5
0
def change_scheduler(device, scheduler):
    """Changes the I/O scheduler for the given device.

    Args:
        device: The device.
        scheduler: The I/O scheduler.

    Returns:
        True if successful, else False.
    """
    printf('Changing scheduler for device {} to {}'.format(device, scheduler),
           print_type=PrintType.DEBUG_LOG)

    command = 'bash -c "echo {} > /sys/block/{}/queue/scheduler"' \
              .format(scheduler, match_regex(device, 'device_name'))

    _, rc = run_command(command)

    if rc != 0:
        raise SchedulerChangeError(
            'Unable to change scheduler to {} for device {}'.format(
                scheduler, device))
Beispiel #6
0
def change_nomerges(device, nomerges):
    """Changes the nomerges setting for the given device.

    Args:
        device: The device.
        nomerges: The nomerges setting.

    Returns:
        True if successful, else False.
    """
    printf('Changing nomerges for device {} to {}'.format(device, nomerges),
           print_type=PrintType.DEBUG_LOG)

    command = 'bash -c "echo {} > /sys/block/{}/queue/nomerges"' \
              .format(nomerges, match_regex(device, 'device_name'))

    _, rc = run_command(command)

    if rc != 0:
        raise DeviceSettingChangeError(
            'Unable to change nomerges to {} for device {}'.format(
                nomerges, device))
Beispiel #7
0
def get_device_nomerges(device):
    """Returns the current nomerges for the device.

    Args:
        device: The device.

    Returns:
        The current nomerges setting.
    """
    printf('Retrieving nomerges for device {}'.format(device),
           print_type=PrintType.DEBUG_LOG)

    device_name = match_regex(device, 'device_name')

    out, rc = run_command(
        'cat /sys/block/{}/queue/nomerges'.format(device_name))

    if rc != 0:
        printf('Unable to find nomerges for device',
               print_type=PrintType.ERROR_LOG)
        return []

    return int(out)
Beispiel #8
0
    def _interpolate_text(self, text, device, scheduler, sp):
        """Interpolates text.

        Args:
            text: The text to interpolate.
            device: The device.
            scheduler: The scheduler.
            sp: The permutated template settings.

        Returns:
            The interpolated text.
        """
        tf = get_formatter('template')
        device_name = match_regex(device, 'device_name')

        text = text.replace(tf.format('device'), device)
        text = text.replace(tf.format('device_name'), device_name)
        text = text.replace(tf.format('scheduler'), scheduler)

        for setting in sp:
            name, value = setting.split('=')
            text = text.replace(tf.format(name), value)

        return text