[tip:tools/kvm] kvm tools: virtio-net has to open tap device before vhost-net init.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  7d362922421bad3adf4a5821b65aad9f6ac74c3f
Gitweb:     http://git.kernel.org/tip/7d362922421bad3adf4a5821b65aad9f6ac74c3f
Author:     Ying-Shiuan Pan <yingshiuan.pan@xxxxxxxxx>
AuthorDate: Fri, 1 Nov 2013 10:50:59 +0800
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Tue, 28 Jan 2014 14:44:06 +0200

kvm tools: virtio-net has to open tap device before vhost-net init.

Enabling vhost-net encounted an error:
  Fatal: VHOST_NET_SET_BACKEND failed 88

The reason is that vhost-net requires tap_fd for VHOST_NET_SET_BACKEND,
however tap_fd is opened after VIRTIO_CONFIG_S_DRIVER_OK. Because the
initialization needs to know the guest features, I suppose the initialization
could be moved to set_guest_features(). Therefore, initialization can be
finished before status VIRTIO_CONFIG_S_DRIVER_OK, and tap_fd can be set
before vhost-net sets backend.

Signed-off-by: Ying-Shiuan Pan <yspan@xxxxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/virtio/net.c | 31 ++++++++++---------------------
 1 file changed, 10 insertions(+), 21 deletions(-)

diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index 3715aaf..dfc4aad 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -389,6 +389,16 @@ static void set_guest_features(struct kvm *kvm, void *dev, u32 features)
 	struct net_dev *ndev = dev;
 
 	ndev->features = features;
+
+	if (ndev->mode == NET_MODE_TAP) {
+		if (!virtio_net__tap_init(ndev))
+			die_perror("You have requested a TAP device, but creation of one has failed because");
+	} else {
+		ndev->info.vnet_hdr_len = has_virtio_feature(ndev, VIRTIO_NET_F_MRG_RXBUF) ?
+						sizeof(struct virtio_net_hdr_mrg_rxbuf) :
+						sizeof(struct virtio_net_hdr);
+		uip_init(&ndev->info);
+	}
 }
 
 static bool is_ctrl_vq(struct net_dev *ndev, u32 vq)
@@ -530,8 +540,6 @@ static int set_size_vq(struct kvm *kvm, void *dev, u32 vq, int size)
 	return size;
 }
 
-static void notify_status(struct kvm *kvm, void *dev, u8 status);
-
 static struct virtio_ops net_dev_virtio_ops = (struct virtio_ops) {
 	.get_config		= get_config,
 	.get_host_features	= get_host_features,
@@ -543,7 +551,6 @@ static struct virtio_ops net_dev_virtio_ops = (struct virtio_ops) {
 	.notify_vq		= notify_vq,
 	.notify_vq_gsi		= notify_vq_gsi,
 	.notify_vq_eventfd	= notify_vq_eventfd,
-	.notify_status		= notify_status,
 };
 
 static void virtio_net__vhost_init(struct kvm *kvm, struct net_dev *ndev)
@@ -731,24 +738,6 @@ static int virtio_net__init_one(struct virtio_net_params *params)
 	return 0;
 }
 
-static void notify_status(struct kvm *kvm, void *dev, u8 status)
-{
-	struct net_dev *ndev = dev;
-
-	if (!(status & VIRTIO_CONFIG_S_DRIVER_OK))
-		return;
-
-	if (ndev->mode == NET_MODE_TAP) {
-		if (!virtio_net__tap_init(ndev))
-			die_perror("You have requested a TAP device, but creation of one has failed because");
-	} else {
-		ndev->info.vnet_hdr_len = has_virtio_feature(ndev, VIRTIO_NET_F_MRG_RXBUF) ?
-						sizeof(struct virtio_net_hdr_mrg_rxbuf) :
-						sizeof(struct virtio_net_hdr);
-		uip_init(&ndev->info);
-	}
-}
-
 int virtio_net__init(struct kvm *kvm)
 {
 	int i;
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux