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

Qcow2 support #1

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Qcow2 support #1

wants to merge 17 commits into from

Conversation

AnthoineB
Copy link
Member

This PR contains different parts:

  1. Tapdisk adaptation to gcc-11. Few warnings/errors are fixed with commit f03fb5f.
  2. Tapdisk cleanup: 3100fcc, 4b00977, ed5b8d7, 8187679, 576172f, 63fb9a9.
  3. Tapdisk use-after-free fix: 4a20003.
  4. Qcow2 sources:
  1. Tapdisk multithread protection: bf0f129, 1fc1d3c, f2b8b40
  2. Tapdisk's Qcow2 driver: d784290

Errors come from -Wstringop-truncation with gcc-8 and above.

Signed-off-by: Anthoine Bourgeois <[email protected]>
Signed-off-by: Anthoine Bourgeois <[email protected]>
Signed-off-by: Anthoine Bourgeois <[email protected]>
Signed-off-by: Anthoine Bourgeois <[email protected]>
Function tapdisk_xenblkif_make_vbd_request will release
tapreq->msg and reinsert it in the reqs_free array if the
request is a BLKIF_OP_WRITE_BARRIER without any segment.
But tapdisk_xenblkif_queue_request will use it to check if
it must send the request to VBD layer.

This bug triggers a crash when DEBUG is defined in td-reqs.c
because DEBUG will poison the msg memory.
Without DEBUG, the code reads freed memory that still contains
unchanged data.

Signed-off-by: Anthoine Bourgeois <[email protected]>
fail label already set vreq->error with err, so remove the
first assignment in both paths that lead to fail label.

Signed-off-by: Anthoine Bourgeois <[email protected]>
This commit includes a list of files imported from qemu to build
the qcow2 library for tapdisk.
A small script helps to import files and diff them to ease the
sources management.

Signed-off-by: Anthoine Bourgeois <[email protected]>
This commit modify sources from qemu to disable some features
unneeded for tapdisk.

Signed-off-by: Anthoine Bourgeois <[email protected]>
XCP-ng-8.3 doesn't have components recent enough for qemu sources.
Fix a few things to support old tools.

Signed-off-by: Anthoine Bourgeois <[email protected]>
Add a mutex to protect vbd structure from qcow2 concurrency.

Signed-off-by: Anthoine Bourgeois <[email protected]>
Add a mutex to protect blktap structure from qcow2 concurrency.

Signed-off-by: Anthoine Bourgeois <[email protected]>
Add a mutex to protect blkif structure from qcow2 concurrency.

Signed-off-by: Anthoine Bourgeois <[email protected]>
Signed-off-by: Anthoine Bourgeois <[email protected]>
Copy link

@TSnake41 TSnake41 left a comment

Choose a reason for hiding this comment

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

Did a quick review of this PR if I see things to improve.

Aside this review, I am not completely convinced of directly picking a large part of QEMU code.
I think it would be better to maintain a set of patches for QEMU code and fetching a specific (working) QEMU version on what we apply the patches. It will make maintenance easier in the long term.

#define QCOW2_OP_READ 1
#define QCOW2_OP_WRITE 2

#define QCOW2_FLAG_OPEN_RDONLY 1
Copy link

@TSnake41 TSnake41 Jan 28, 2025

Choose a reason for hiding this comment

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

Using 1 << 0, 1 << 1, ... style would be preferable than raw decimals.

For reference, Xen headers uses a variant of it with a intermediate macro
e.g

/* xen_pci_sharedinfo flags */
#define _XEN_PCIF_active     (0)
#define XEN_PCIF_active      (1<<_XEN_PCIF_active)
#define _XEN_PCIB_AERHANDLER (1)
#define XEN_PCIB_AERHANDLER  (1<<_XEN_PCIB_AERHANDLER)
#define _XEN_PCIB_active     (2)
#define XEN_PCIB_active      (1<<_XEN_PCIB_active)


struct qcow2_request {
int error;
uint8_t op;

Choose a reason for hiding this comment

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

Is there a reason to use uint8_t here specifically ?
I think unsigned int would fit better to make the structure layout less complex and potentially more efficient.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see anything objectionable about using a signed integer of explicit size here. Generally it's even good for storing constants and operations. And regarding performance, I doubt it will help anything regarding buffer reads/writes or writing data to disk.

Error *local_err = NULL;
BlockConf *conf = NULL;
bool writethrough;
#define AIO_NATIVE

Choose a reason for hiding this comment

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

These macros will always be defined (is it temporary ?).
(#else part will never be compiled)

.disk_type = "tapdisk_qcow2",
.flags = 0,
.private_data_size = sizeof(struct qcow2_state),
.td_open = _qcow2_open,
Copy link

@TSnake41 TSnake41 Jan 28, 2025

Choose a reason for hiding this comment

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

assuming that this can be called multiples times, static variables are going to be overwritten, causing potentially various tricky issues

Copy link
Member

Choose a reason for hiding this comment

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

What can be called multiple times? And what could overwrite these fields? They are normally set only one time.
I don't see any other changes to these fields in the blktap code.

bql_unlock();
}

static pthread_t thread;
Copy link

@TSnake41 TSnake41 Jan 28, 2025

Choose a reason for hiding this comment

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

You probably want to ensure that these variables don't get overwritten (see .td_open = _qcow2_open) comment

Copy link
Member

@Wescoeur Wescoeur Jan 30, 2025

Choose a reason for hiding this comment

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

Same questions here. What's the issue?

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