*tag_name = '\0';
tag_name++;
}
- if (realpath(arg, tmp))
- virtio_9p__init(kvm, tmp, tag_name);
- else
+ if (realpath(arg, tmp)) {
+ if (virtio_9p__init(kvm, tmp, tag_name) < 0)
+ die("Unable to initialize virtio 9p");
+ } else
die("Failed resolving 9p path");
return 0;
}
#define VIRTIO_P9_VERSION "9P2000"
#define MAX_TAG_LEN 32
-
struct p9_msg {
u32 size;
u8 cmd;
struct kvm;
-void virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name);
+int virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name);
int virtio_p9_pdu_readf(struct p9_pdu *pdu, const char *fmt, ...);
int virtio_p9_pdu_writef(struct p9_pdu *pdu, const char *fmt, ...);
+
#endif
.io_out = virtio_p9_pci_io_out,
};
-void virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name)
+int virtio_9p__init(struct kvm *kvm, const char *root, const char *tag_name)
{
+ struct p9_dev *p9dev;
u8 pin, line, dev;
- u32 i, root_len;
u16 p9_base_addr;
- struct p9_dev *p9dev;
+ u32 i, root_len;
+ int err = 0;
p9dev = calloc(1, sizeof(*p9dev));
if (!p9dev)
- return;
+ return -ENOMEM;
+
if (!tag_name)
tag_name = VIRTIO_P9_DEFAULT_TAG;
+
p9dev->config = calloc(1, sizeof(*p9dev->config) + strlen(tag_name) + 1);
- if (p9dev->config == NULL)
+ if (p9dev->config == NULL) {
+ err = -ENOMEM;
goto free_p9dev;
+ }
strcpy(p9dev->root_dir, root);
root_len = strlen(root);
p9dev->fids[i].path = p9dev->fids[i].abs_path + root_len;
}
p9dev->config->tag_len = strlen(tag_name);
- if (p9dev->config->tag_len > MAX_TAG_LEN)
+ if (p9dev->config->tag_len > MAX_TAG_LEN) {
+ err = -EINVAL;
goto free_p9dev_config;
+ }
memcpy(p9dev->config->tag, tag_name, strlen(tag_name));
p9dev->features |= 1 << VIRTIO_9P_MOUNT_TAG;
- if (irq__register_device(VIRTIO_ID_9P, &dev, &pin, &line) < 0)
+ err = irq__register_device(VIRTIO_ID_9P, &dev, &pin, &line);
+ if (err < 0)
goto free_p9dev_config;
- p9_base_addr = ioport__register(IOPORT_EMPTY,
- &virtio_p9_io_ops,
- IOPORT_SIZE, p9dev);
- p9dev->base_addr = p9_base_addr;
+ p9_base_addr = ioport__register(IOPORT_EMPTY, &virtio_p9_io_ops, IOPORT_SIZE, p9dev);
+
+ p9dev->base_addr = p9_base_addr;
+
p9dev->pci_hdr = (struct pci_device_header) {
.vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET,
.device_id = PCI_DEVICE_ID_VIRTIO_P9,
};
pci__register(&p9dev->pci_hdr, dev);
- return;
+ return err;
+
free_p9dev_config:
free(p9dev->config);
free_p9dev:
free(p9dev);
+ return err;
}