Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returns the number of allocated clusters in a Qcow #70

Draft
wants to merge 2 commits into
base: 3.2.3-8.3
Choose a base branch
from

Conversation

gthvn1
Copy link

@gthvn1 gthvn1 commented Oct 29, 2024

This script returns the number of allocated clusters in a Qcow file.
We probably won't use it like this but more probably as a library for the next qcow2util implementation.
I opened it because it is easier to discuss on a PR and like that we keep a backup while waiting to see what we do with it...

Last commit: 9207abe
"fix(linstor): check if resource is tiebreaker (#62)"

Signed-off-by: Ronan Abhamon <[email protected]>
@gthvn1 gthvn1 marked this pull request as draft October 29, 2024 18:20
@gthvn1 gthvn1 self-assigned this Oct 29, 2024
@gthvn1 gthvn1 force-pushed the gtn-get-allocated-clusters branch 2 times, most recently from 8259021 to 303c6b0 Compare November 1, 2024 10:56
@gthvn1
Copy link
Author

gthvn1 commented Nov 1, 2024

I will probably put functions into a class and pass the filename during the init(). The init will update a header, L1 table and L2 table. So we won't pass the file and header every time and the Qcow file will be hold only during the init.

Copy link
Member

@stormi stormi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: your PR is targeting a 8.2 maintenance branch.

@gthvn1
Copy link
Author

gthvn1 commented Nov 4, 2024

Note: your PR is targeting a 8.2 maintenance branch.

Ok noted 👍 . I took the default branch presented on the github page. But in fact it doesn't matter a lot because we will only took the class to add it to the future qcowutil.py file. So this PR probably won't be merged as is.

@gthvn1 gthvn1 force-pushed the gtn-get-allocated-clusters branch 8 times, most recently from 248cbc5 to 7254eea Compare November 12, 2024 08:48
@gthvn1 gthvn1 changed the base branch from 2.30.8-8.2 to 3.2.3-8.3 November 12, 2024 08:49
@gthvn1 gthvn1 force-pushed the gtn-get-allocated-clusters branch 3 times, most recently from 7b63087 to 6febcd4 Compare November 15, 2024 12:37
This script can returns:
- the number of allocated clusters in a Qcow file.
- the number of newly allocated clusters in a Qcow file
  compared to a reference one (like the backing file).
- it can erase all data and set clusters as unallocated
- it can set/unset/get the hidden property.
  - for now it creates the custom header if not found but it can easily
    be changed. It also moves the backing file name because when a
    snapshot is created the hidden custom header is ignored so we need
    to make space to crate it again.

NOTE: This script is a POC to validate that all helpers from vhd util
are also doable with qcow file. It will be used in another file.

Signed-off-by: Guillaume <[email protected]>
@gthvn1 gthvn1 force-pushed the gtn-get-allocated-clusters branch from 6febcd4 to 881b48a Compare November 15, 2024 13:08
@Wescoeur Wescoeur deleted the branch 3.2.3-8.3 November 29, 2024 15:11
@Wescoeur Wescoeur closed this Nov 29, 2024
@Wescoeur Wescoeur reopened this Nov 29, 2024
with open(self.filename, "rb+") as qcow2_file:
if self.header["version"] == 3:
qcow2_file.seek(100) # 100 is the offset of header_length
header_length = int.from_bytes(qcow2_file.read(4))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we need to add the endianess: header_length = int.from_bytes(qcow2_file.read(4), 'big')

custom_data_offset = 0

while True:
ext_type = int.from_bytes(qcow2_file.read(4))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here a below

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants