Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Add lock to vnet
[palacios.git] / palacios / src / devices / lnx_virtio_nic.c
index 26b32f6..d3d5cfb 100644 (file)
@@ -85,6 +85,8 @@ struct virtio_net_state {
 
     struct v3_dev_net_ops * net_ops;
 
+    v3_lock_t lock;
+
     void * backend_data;
     struct virtio_dev_state * virtio_dev;
     struct list_head dev_link;
@@ -120,6 +122,10 @@ static int virtio_init_state(struct virtio_net_state * virtio)
     //virtio->virtio_cfg.status = VIRTIO_NET_S_LINK_UP;
     virtio->virtio_cfg.pci_isr = 0;
 
+    if (v3_lock_init(&(virtio->lock)) == -1){
+        PrintError("Virtio NIC: Failure to init lock for net_state\n");
+    }
+
     virtio->pkt_sent = virtio->pkt_recv = virtio->pkt_drop = 0;
 
     return 0;
@@ -476,14 +482,15 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) {
     uint32_t hdr_len = sizeof(struct virtio_net_hdr);
     uint32_t data_len = size;
     uint32_t offset = 0;
+    unsigned long flags;
+
+    flags = v3_lock_irqsave(virtio->lock);
        
     PrintDebug("VIRTIO NIC:  sending packet to virtio nic %p, size:%d", virtio, size);
 
     virtio->pkt_recv ++;
-
     data_len -= hdr_len;
 
-
     build_receive_header(&hdr, buf, 1);
 
     if (q->ring_avail_addr == 0) {
@@ -554,6 +561,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) {
     }
 #endif
 
+    v3_unlock_irqrestore(virtio->lock, flags);
     
     return offset;
 }