Exemple #1
0
def mount_and_select_hosting_volume(pv_hosting_volumes, required_size):
    """Mount each hosting volume to find available space"""
    for volume in pv_hosting_volumes:
        hvol = volume['name']
        mntdir = os.path.join(HOSTVOL_MOUNTDIR, hvol)
        mount_glusterfs(volume, mntdir)

        with statfile_lock:
            # Stat done before `os.path.exists` to prevent ignoring
            # file not exists even in case of ENOTCONN
            mntdir_stat = retry_errors(os.statvfs, [mntdir], [ENOTCONN])
            with SizeAccounting(hvol, mntdir) as acc:
                acc.update_summary(mntdir_stat.f_bavail * mntdir_stat.f_bsize)
                pv_stats = acc.get_stats()
                reserved_size = pv_stats[
                    "free_size_bytes"] * RESERVED_SIZE_PERCENTAGE / 100

            logging.debug(
                logf("pv stats",
                     hostvol=hvol,
                     total_size_bytes=pv_stats["total_size_bytes"],
                     used_size_bytes=pv_stats["used_size_bytes"],
                     free_size_bytes=pv_stats["free_size_bytes"],
                     number_of_pvs=pv_stats["number_of_pvs"],
                     required_size=required_size,
                     reserved_size=reserved_size))

            if required_size < (pv_stats["free_size_bytes"] - reserved_size):
                return hvol

    return None
Exemple #2
0
def is_hosting_volume_free(hostvol, requested_pvsize):
    """Check if host volume is free to expand or create (external)volume"""

    mntdir = os.path.join(HOSTVOL_MOUNTDIR, hostvol)
    with statfile_lock:

        # Stat done before `os.path.exists` to prevent ignoring
        # file not exists even in case of ENOTCONN
        mntdir_stat = retry_errors(os.statvfs, [mntdir], [ENOTCONN])
        with SizeAccounting(hostvol, mntdir) as acc:
            acc.update_summary(mntdir_stat.f_bavail * mntdir_stat.f_bsize)
            pv_stats = acc.get_stats()
            reserved_size = pv_stats[
                "free_size_bytes"] * RESERVED_SIZE_PERCENTAGE / 100

        logging.debug(
            logf("pv stats",
                 hostvol=hostvol,
                 total_size_bytes=pv_stats["total_size_bytes"],
                 used_size_bytes=pv_stats["used_size_bytes"],
                 free_size_bytes=pv_stats["free_size_bytes"],
                 number_of_pvs=pv_stats["number_of_pvs"],
                 required_size=requested_pvsize,
                 reserved_size=reserved_size))

        if requested_pvsize < (pv_stats["free_size_bytes"] - reserved_size):
            return True

        return False
Exemple #3
0
def update_free_size(hostvol, pvname, sizechange):
    """Update the free size in respective host volume's stats.db file"""

    mntdir = os.path.join(HOSTVOL_MOUNTDIR, hostvol)

    # Check for mount availability before updating the free size
    retry_errors(os.statvfs, [mntdir], [ENOTCONN])

    with statfile_lock:
        with SizeAccounting(hostvol, mntdir) as acc:
            # Reclaim space
            if sizechange > 0:
                acc.remove_pv_record(pvname)
            else:
                acc.update_pv_record(pvname, -sizechange)