}
-static int blk_free(struct vm_device * dev) {
- return -1;
+static int blk_free(struct blk_state * blk) {
+ V3_FreePages((void *)blk->blk_base_addr, blk->capacity / 4096);
+
+ V3_Free(blk);
+ return 0;
}
static struct v3_device_ops dev_ops = {
- .free = blk_free,
+ .free = (int (*)(void *))blk_free,
};
memset(blk->blk_space, 0, capacity);
- struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, blk);
+ struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, blk);
- if (v3_attach_device(vm, dev) == -1) {
+ if (dev == NULL) {
PrintError("Could not attach device %s\n", dev_id);
+ V3_Free(blk);
return -1;
}
&blk_ops, frontend_cfg, blk) == -1) {
PrintError("Could not connect %s to frontend %s\n",
dev_id, v3_cfg_val(frontend_cfg, "tag"));
+ v3_remove_device(dev);
return -1;
}