예제 #1
0
    def test_one_cluster(self, qcow2_compat):
        with namedTemporaryDir() as tmpdir:
            # Write full clusters so we dont fail when qemu change the
            # implemention of writing partial cluster.
            offset = 64 * KiB
            length = 64 * KiB
            size = MiB

            image = os.path.join(tmpdir, "base.img")
            op = qemuimg.create(image, size=size, format=self.FORMAT,
                                qcow2Compat=qcow2_compat)
            op.run()

            qemuio.write_pattern(
                image,
                self.FORMAT,
                offset=offset,
                len=length,
                pattern=0xf0)

            expected = [
                # run 1 - empty
                {
                    "start": 0,
                    "length": length,
                    "data": False,
                    "zero": True,
                },
                # run 2 - data
                {
                    "start": offset,
                    "length": length,
                    "data": True,
                    "zero": False,
                },
                # run 3 - empty
                {
                    "start": offset + length,
                    "length": size - offset - length,
                    "data": False,
                    "zero": True,
                },
            ]

            self.check_map(qemuimg.map(image), expected)
예제 #2
0
파일: qemuimg_test.py 프로젝트: nirs/vdsm
    def test_empty_image(self, qcow2_compat):
        with namedTemporaryDir() as tmpdir:
            size = 1048576
            image = os.path.join(tmpdir, "base.img")
            op = qemuimg.create(image, size=size, format=self.FORMAT,
                                qcow2Compat=qcow2_compat)
            op.run()

            expected = [
                # single run - empty
                {
                    "start": 0,
                    "length": size,
                    "data": False,
                    "zero": True,
                },
            ]

            self.check_map(qemuimg.map(image), expected)
예제 #3
0
파일: qcow2.py 프로젝트: xin49/vdsm
def estimate_size(filename):
    """
    Estimate the required size of a new qcow2 file converted from source image
    filename. Source image can be raw, qcow2, or compressed qcow2, on any
    storage type.
    """
    info = qemuimg.info(filename)
    if "backingfile" in info:
        raise ValueError("Estimate size not supported for images with "
                         "a backing file")

    # Get used clusters and virtual size of destination volume.
    virtual_size = info['virtualsize']
    meta_size = _estimate_metadata_size(virtual_size)
    runs = qemuimg.map(filename)
    used_clusters = count_clusters(runs)

    # Return the estimated size.
    return meta_size + used_clusters * CLUSTER_SIZE
예제 #4
0
파일: qemuimg_test.py 프로젝트: nirs/vdsm
    def test_one_block(self, offset, length, expected_length, qcow2_compat):
        with namedTemporaryDir() as tmpdir:
            size = 1048576
            image = os.path.join(tmpdir, "base.img")
            op = qemuimg.create(image, size=size, format=self.FORMAT,
                                qcow2Compat=qcow2_compat)
            op.run()

            qemuio.write_pattern(
                image,
                self.FORMAT,
                offset=offset,
                len=length,
                pattern=0xf0)

            expected = [
                # run 1 - empty
                {
                    "start": 0,
                    "length": offset,
                    "data": False,
                    "zero": True,
                },
                # run 2 - data
                {
                    "start": offset,
                    "length": expected_length,
                    "data": True,
                    "zero": False,
                },
                # run 3 - empty
                {
                    "start": offset + expected_length,
                    "length": size - offset - expected_length,
                    "data": False,
                    "zero": True,
                },
            ]

            self.check_map(qemuimg.map(image), expected)