Exemple #1
0
    def _get_owner(self, dataset):
        mountpoint = None
        if dataset["mounted"]["value"] == "yes":
            if dataset["mountpoint"]["value"] == "legacy":
                for m in (getmntinfo() if getmntinfo else []):
                    if m.source == dataset["name"]:
                        mountpoint = m.dest
                        break
            else:
                mountpoint = dataset["mountpoint"]["value"]
        if mountpoint is None:
            logger.debug(
                "Unable to get mountpoint for dataset %r, assuming owner = root",
                dataset["name"])
            uid = 0
        else:
            try:
                stat_info = os.stat(mountpoint)
            except Exception:
                logger.debug(
                    "Unable to stat mountpoint %r, assuming owner = root",
                    mountpoint)
                uid = 0
            else:
                uid = stat_info.st_uid

        return uid
Exemple #2
0
def validate_disk(name):
    """
    Given the geom of a disk, let's see if it's appropriate.
    Innappropriate disks are too small (4gbytes and less),
    or are already mounted / in use by a pool.  (That latter
    being somewhat harder to tell...)
    XXX How inefficient is this?
    """
    min_disk_size = 4 * 1024 * 1024 * 1024
    used_disks = []
    # Start with zfs disks
    pools = list(zfs.pools)
    for pool in zfs.pools:
        for disk in pool.disks:
            # Remove the beginning "/dev/"
            disk_name = disk[5:]
            x = geom.geom_by_name("DEV", disk_name)
            used_disks.append(DiskRealName(x))

    # Now let's go for the mounted disks
    mounts = bsd.getmntinfo()
    for mount in mounts:
        if mount.fstype in ("tmpfs", "devfs"):
            # It's not a real disk!
            continue
        if mount.source.startswith("/dev/"):
            disk_name = mount.source[5:]
            x = geom.geom_by_name("DEV", disk_name)
            used_disks.append(DiskRealName(x))

    if name in used_disks:
        raise ValidationError(code=ValidationCode.DiskInUse,
                              message="Disk {} is in use".format(name))

    try:
        disk = Utils.Disk(name)
    except RuntimeError:
        LogIt(
            "Could not find information about disk {} in validate_disk".format(
                name))
        raise ValidationError(
            code=ValidationCode.DiskNoInfo,
            message="No information available for disk {}".format(name))
    if disk.size < min_disk_size:
        LogIt("Disk {} is too small ({}, need 4G at least)".format(
            name, disk.smart_size))
        raise ValidationError(
            code=ValidationCode.DiskTooSmall,
            message="Disk {} is too small ({}, need 4G at least)".format(
                name, disk.smart_size))
    return
Exemple #3
0
    def _get_owner(self, dataset):
        mountpoint = None
        if dataset["mounted"]["value"] == "yes":
            if dataset["mountpoint"]["value"] == "legacy":
                for m in getmntinfo():
                    if m.source == dataset["name"]["value"]:
                        mountpoint = m.dest
                        break
            else:
                mountpoint = dataset["mountpoint"]["value"]
        if mountpoint is None:
            logger.debug("Unable to get mountpoint for dataset %r, assuming owner = root", dataset["name"]["value"])
            uid = 0
        else:
            try:
                stat_info = os.stat(mountpoint)
            except Exception:
                logger.debug("Unable to stat mountpoint %r, assuming owner = root", mountpoint)
                uid = 0
            else:
                uid = stat_info.st_uid

        return uid