-
Notifications
You must be signed in to change notification settings - Fork 328
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
virtio-blk: implement DISCARD #272
Conversation
f0b688c
to
6d0f4d1
Compare
@@ -340,8 +396,16 @@ pci_vtblk_init(struct pci_devinst *pi, char *opts) | |||
|
|||
pthread_mutex_init(&sc->vsc_mtx, NULL); | |||
|
|||
/* Customise the capabilities per-device */ | |||
vi_consts = (struct virtio_consts*)malloc(sizeof(struct virtio_consts)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not testing for malloc failure here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh yes good point. I've added and force-pushed a NULL check on the next line ⬇️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. There is a calloc a few lines above also unchecked. But that’s unrelated to this PR
11dae8f
to
e90eb74
Compare
The protocol defines DISCARD in v1.1: https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.pdf In this simple implementation we advertise a maximum of 1 segment per request, which fits the backend API `block_delete(_, offset, length)`. Experimentally Linux 5.4.9 seems to send one request at a time (tested by deleting files and then executing `fstrim`) Note we only advertise the feature if the backing file itself supports it. Signed-off-by: David Scott <[email protected]>
e90eb74
to
de9ab9a
Compare
Signed-off-by: David Scott <[email protected]>
40d3953
to
63de6b5
Compare
Thanks! |
The protocol defines DISCARD in v1.1:
https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.pdf
In this simple implementation we advertise a maximum of 1 segment per request, which fits the backend API
block_delete(_, offset, length)
. Experimentally Linux 5.4.9 seems to send one request at a time (tested by deleting files and then executingfstrim
)Note we only advertise the feature if the backing file itself supports it.
Switching from AHCI
virtio-blk
works around the known deadlock in the AHCI implementation #94Signed-off-by: David Scott [email protected]