def parse_stripe_configuration()

in FSxL-Compression/fsx_lustre_migrate_files.py [0:0]


def parse_stripe_configuration(file_path):
    cmd = ["/usr/bin/lfs", "getstripe", "-vy", file_path]
    p = subprocess.run(cmd, stdout=PIPE, stderr=STDOUT)

    if "no stripe info" in str(p.stdout):
        # symlink file
        logger.warning("Failed to fetch stripe configuration for file: %s. This may be a symlink file. Skipping",
            file_path)
        sys.exit()

    stripe_conf = yaml.safe_load(p.stdout)
    if not stripe_conf.get("composite_header"):
        is_PFL = False
        # non-PFL, regular stripe configuration
        return is_PFL, {
                "lmm_stripe_count": stripe_conf.get("lmm_stripe_count"),
                "lmm_stripe_size": stripe_conf.get("lmm_stripe_size")
        }

    # PFL layout
    is_PFL = True
    stripe_conf = stripe_conf.get("composite_header")
    lcm_entry_count = int(stripe_conf.get("lcm_entry_count"))

    stripe_configuration = []
    for i in range(lcm_entry_count):
        component_key = "component{}".format(i)
        component_object = stripe_conf.get(component_key)
        start_bytes = component_object.get("lcme_extent.e_start")
        end_bytes = component_object.get("lcme_extent.e_end")
        if end_bytes == "EOF":
            end_bytes = "-1"
        sub_layout = component_object.get("sub_layout")
        lmm_stripe_count = sub_layout.get("lmm_stripe_count")
        lmm_stripe_size = sub_layout.get("lmm_stripe_size")
        ost_start = sub_layout.get("lmm_stripe_offset")
        fid = sub_layout.get("lmm_fid")

        stripe_configuration.append({
            "lmm_stripe_count": lmm_stripe_count,
            "lmm_stripe_size": lmm_stripe_size,
            "start_bytes": start_bytes,
            "end_bytes": end_bytes
        })
    return is_PFL, stripe_configuration