#define DRIVER_NAME "EVDI"
-#define LOG(fmt, ...) \
+#define LOGDEBUG(fmt, ...) \
+ printk(KERN_DEBUG "%s: " fmt, DRIVER_NAME, ##__VA_ARGS__)
+
+#define LOGERR(fmt, ...) \
printk(KERN_ERR "%s: " fmt, DRIVER_NAME, ##__VA_ARGS__)
#define NUM_OF_EVDI 2
ret = virtqueue_add_inbuf(vevdi->rvq, vevdi->sg_read,
1, &vevdi->read_msginfo, GFP_ATOMIC);
if (ret < 0) {
- LOG("failed to add buffer to virtqueue.(%d)\n", ret);
+ LOGERR("failed to add buffer to virtqueue.(%d)\n", ret);
return ret;
}
return ret;
}
+#define HEADER_SIZE 4
+#define ID_SIZE 10
+#define GUEST_CONNECTION_CATEGORY "guest"
+static void send_guest_connected_msg(bool connected)
+{
+ int err;
+ struct msg_info* _msg;
+ char connect = (char)connected;
+ if (vevdi == NULL) {
+ LOGERR("invalid evdi handle\n");
+ return;
+ }
+
+ _msg = &vevdi->send_msginfo;
+
+ memset(_msg, 0, sizeof(vevdi->send_msginfo));
+
+ memcpy(_msg->buf, GUEST_CONNECTION_CATEGORY, 7);
+ memcpy(_msg->buf + ID_SIZE + 3, &connect, 1);
+ _msg->route = route_control_server;
+ _msg->use = ID_SIZE + HEADER_SIZE;
+ _msg->count = 1;
+ _msg->index = 0;
+ _msg->cclisn = 0;
+
+ err = virtqueue_add_outbuf(vevdi->svq, vevdi->sg_send, 1,
+ _msg, GFP_ATOMIC);
+
+ LOGERR("send guest connection message to qemu with (%d)\n", connected);
+
+ if (err < 0) {
+ LOGERR("failed to add buffer to virtqueue (err = %d)\n", err);
+ return;
+ }
+
+ virtqueue_kick(vevdi->svq);
+}
+
static int evdi_open(struct inode* inode, struct file* filp)
{
struct cdev *cdev = inode->i_cdev;
evdi_info = NULL;
- LOG("evdi_open\n");
+ LOGDEBUG("evdi_open\n");
for (i = 0; i < NUM_OF_EVDI; i++)
{
- LOG("evdi info index = %d, cdev dev = %d, inode dev = %d\n",
+ LOGDEBUG("evdi info index = %d, cdev dev = %d, inode dev = %d\n",
i, pevdi_info[i]->cdev.dev, cdev->dev);
if (pevdi_info[i]->cdev.dev == cdev->dev)
evdi_info->guest_connected = true;
+ send_guest_connected_msg(true);
ret = _make_buf_and_kick();
if (ret < 0)
return ret;
- LOG("evdi_opened\n");
+ LOGDEBUG("evdi_opened\n");
return 0;
}
evdi_info = filp->private_data;
evdi_info->guest_connected = false;
- LOG("evdi_closed\n");
+ send_guest_connected_msg(false);
+
+ LOGDEBUG("evdi_closed\n");
return 0;
}
{
if (filp->f_flags & O_NONBLOCK)
{
- LOG("list is empty, return EAGAIN\n");
+ LOGERR("list is empty, return EAGAIN\n");
return -EAGAIN;
}
return -EFAULT;
next = list_first_entry(&vevdi->read_list, struct msg_buf, list);
if (next == NULL) {
- LOG("invliad list entry\n");
+ LOGERR("invliad list entry\n");
return -EFAULT;
}
if (add_inbuf(vevdi->rvq, &vevdi->read_msginfo) < 0)
{
- LOG("failed add_buf\n");
+ LOGERR("failed add_buf\n");
}
spin_unlock_irqrestore(&pevdi_info[EVID_READ]->inbuf_lock, flags);
-
- //LOG("evdi_read count = %d!\n", ++g_read_count);
-
if (ret < 0)
return -EFAULT;
int err = 0;
ssize_t ret = 0;
- //LOG("start of evdi_write len= %d, msglen = %d\n", len, sizeof(vevdi->send_msginfo));
-
if (vevdi == NULL) {
- LOG("invalid evdi handle\n");
+ LOGERR("invalid evdi handle\n");
return 0;
}
memset(&vevdi->send_msginfo, 0, sizeof(vevdi->send_msginfo));
ret = copy_from_user(&vevdi->send_msginfo, ubuf, sizeof(vevdi->send_msginfo));
- //LOG("copy_from_user ret = %d, msg = %s", ret, vevdi->send_msginfo.buf);
+ LOGDEBUG("copy_from_user ret = %d, msg = %s", ret, vevdi->send_msginfo.buf);
if (ret) {
ret = -EFAULT;
&_msg, GFP_ATOMIC);*/
if (err < 0) {
- LOG("failed to add buffer to virtqueue (err = %d)\n", err);
+ LOGERR("failed to add buffer to virtqueue (err = %d)\n", err);
return 0;
}
if (has_readdata(evdi))
{
- LOG("POLLIN | POLLRDNORM\n");
+ LOGDEBUG("POLLIN | POLLRDNORM\n");
ret |= POLLIN | POLLRDNORM;
}
_msg = (struct msg_info*) virtqueue_get_buf(vevdi->rvq, &len);
if (_msg == NULL ) {
- LOG("failed to virtqueue_get_buf\n");
+ LOGERR("failed to virtqueue_get_buf\n");
return;
}
int i, ret;
if (alloc_chrdev_region(&evdi_dev_number, 0, NUM_OF_EVDI, DEVICE_NAME) < 0) {
- LOG("fail to alloc_chrdev_region\n");
+ LOGERR("fail to alloc_chrdev_region\n");
return -1;
}
pevdi_info[i] = kmalloc(sizeof(struct virtevdi_info), GFP_KERNEL);
if (!pevdi_info[i]) {
- LOG("Bad malloc\n");
+ LOGERR("Bad malloc\n");
return -ENOMEM;
}
spin_lock_init(&pevdi_info[i]->outvq_lock);
if (ret == -1) {
- LOG("Bad cdev\n");
+ LOGERR("Bad cdev\n");
return ret;
}
ret = _init_device();
if (ret)
{
- LOG("failed to _init_device\n");
+ LOGERR("failed to _init_device\n");
return ret;
}
ret = init_vqs(vevdi);
kfree(vevdi);
dev->priv = NULL;
- LOG("failed to init_vqs\n");
+ LOGERR("failed to init_vqs\n");
return ret;
}
- LOG("EVDI Probe completed");
+ LOGDEBUG("EVDI Probe completed");
return 0;
}
struct virtio_evdi* _evdi = dev->priv;
if (!_evdi)
{
- LOG("evdi is NULL\n");
+ LOGERR("evdi is NULL\n");
return;
}
kfree(_evdi);
- LOG("driver is removed.\n");
+ LOGDEBUG("driver is removed.\n");
}
MODULE_DEVICE_TABLE(virtio, id_table);
static int __init evdi_init(void)
{
- LOG("EVDI driver initialized.\n");
+ LOGDEBUG("EVDI driver initialized.\n");
return register_virtio_driver(&virtio_evdi_driver);
}
unregister_virtio_driver(&virtio_evdi_driver);
- LOG("EVDI driver is destroyed.\n");
+ LOGDEBUG("EVDI driver is destroyed.\n");
}
module_init(evdi_init);