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.


Context-based output infrastructure (V3_Print, etc) and modifications to use it
[palacios.git] / palacios / src / devices / lnx_virtio_balloon.c
index f6608d2..653bc5e 100644 (file)
@@ -119,7 +119,7 @@ static int get_desc_count(struct virtio_queue * q, int index) {
 static int handle_kick(struct guest_info * core, struct virtio_balloon_state * virtio) {
     struct virtio_queue * q = virtio->cur_queue;
 
-    PrintDebug("VIRTIO BALLOON KICK: cur_index=%d (mod=%d), avail_index=%d\n", 
+    PrintDebug(core->vm_info, core, "VIRTIO BALLOON KICK: cur_index=%d (mod=%d), avail_index=%d\n", 
               q->cur_avail_idx, q->cur_avail_idx % QUEUE_SIZE, q->avail->index);
 
     while (q->cur_avail_idx < q->avail->index) {
@@ -130,32 +130,32 @@ static int handle_kick(struct guest_info * core, struct virtio_balloon_state * v
        uint32_t req_len = 0;
 
 
-       PrintDebug("Descriptor Count=%d, index=%d\n", desc_cnt, q->cur_avail_idx % QUEUE_SIZE);
+       PrintDebug(core->vm_info, core, "Descriptor Count=%d, index=%d\n", desc_cnt, q->cur_avail_idx % QUEUE_SIZE);
 
        for (i = 0; i < desc_cnt; i++) {
            addr_t page_addr;
            tmp_desc = &(q->desc[desc_idx]);
            
-           PrintDebug("Header Descriptor (ptr=%p) gpa=%p, len=%d, flags=%x, next=%d\n", 
+           PrintDebug(core->vm_info, core, "Header Descriptor (ptr=%p) gpa=%p, len=%d, flags=%x, next=%d\n", 
                       tmp_desc, 
                       (void *)(addr_t)(tmp_desc->addr_gpa), tmp_desc->length, 
                       tmp_desc->flags, tmp_desc->next);
        
 
            if (v3_gpa_to_hva(core, tmp_desc->addr_gpa, (addr_t *)&(page_addr)) == -1) {
-               PrintError("Could not translate block header address\n");
+               PrintError(core->vm_info, core, "Could not translate block header address\n");
                return -1;
            }
 
            /*      
               if (handle_balloon_op(virtio, tmp_desc, buf_desc, status_desc) == -1) {
-              PrintError("Error handling balloon operation\n");
+              PrintError(core->vm_info, core, "Error handling balloon operation\n");
               return -1;
               }
            */
 
-           PrintDebug("Guest Balloon Currently Ignored\n");
-           PrintDebug("\t Requested=%d, Allocated=%d\n", 
+           PrintDebug(core->vm_info, core, "Guest Balloon Currently Ignored\n");
+           PrintDebug(core->vm_info, core, "\t Requested=%d, Allocated=%d\n", 
                       virtio->balloon_cfg.requested_pages, 
                       virtio->balloon_cfg.allocated_pages);
 
@@ -171,7 +171,7 @@ static int handle_kick(struct guest_info * core, struct virtio_balloon_state * v
     }
 
     if (!(q->avail->flags & VIRTIO_NO_IRQ_FLAG)) {
-       PrintDebug("Raising IRQ %d\n",  virtio->pci_dev->config_header.intr_line);
+       PrintDebug(core->vm_info, core, "Raising IRQ %d\n",  virtio->pci_dev->config_header.intr_line);
        v3_pci_raise_irq(virtio->pci_bus, virtio->pci_dev, 0);
        virtio->virtio_cfg.pci_isr = VIRTIO_ISR_ACTIVE;
     }
@@ -184,7 +184,7 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src,
     int port_idx = port % virtio->io_range_size;
 
 
-    PrintDebug("VIRTIO BALLOON Write for port %d (index=%d) len=%d, value=%x\n", 
+    PrintDebug(core->vm_info, core, "VIRTIO BALLOON Write for port %d (index=%d) len=%d, value=%x\n", 
               port, port_idx,  length, *(uint32_t *)src);
 
 
@@ -192,7 +192,7 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src,
     switch (port_idx) {
        case GUEST_FEATURES_PORT:
            if (length != 4) {
-               PrintError("Illegal write length for guest features\n");
+               PrintError(core->vm_info, core, "Illegal write length for guest features\n");
                return -1;
            }
            
@@ -217,32 +217,32 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src,
                virtio->cur_queue->ring_used_addr = (virtio->cur_queue->ring_used_addr + 0xfff) & ~0xfff;
 
                if (v3_gpa_to_hva(core, virtio->cur_queue->ring_desc_addr, (addr_t *)&(virtio->cur_queue->desc)) == -1) {
-                   PrintError("Could not translate ring descriptor address\n");
+                   PrintError(core->vm_info, core, "Could not translate ring descriptor address\n");
                    return -1;
                }
 
 
                if (v3_gpa_to_hva(core, virtio->cur_queue->ring_avail_addr, (addr_t *)&(virtio->cur_queue->avail)) == -1) {
-                   PrintError("Could not translate ring available address\n");
+                   PrintError(core->vm_info, core, "Could not translate ring available address\n");
                    return -1;
                }
 
 
                if (v3_gpa_to_hva(core, virtio->cur_queue->ring_used_addr, (addr_t *)&(virtio->cur_queue->used)) == -1) {
-                   PrintError("Could not translate ring used address\n");
+                   PrintError(core->vm_info, core, "Could not translate ring used address\n");
                    return -1;
                }
 
-               PrintDebug("RingDesc_addr=%p, Avail_addr=%p, Used_addr=%p\n",
+               PrintDebug(core->vm_info, core, "RingDesc_addr=%p, Avail_addr=%p, Used_addr=%p\n",
                           (void *)(virtio->cur_queue->ring_desc_addr),
                           (void *)(virtio->cur_queue->ring_avail_addr),
                           (void *)(virtio->cur_queue->ring_used_addr));
 
-               PrintDebug("RingDesc=%p, Avail=%p, Used=%p\n", 
+               PrintDebug(core->vm_info, core, "RingDesc=%p, Avail=%p, Used=%p\n", 
                           virtio->cur_queue->desc, virtio->cur_queue->avail, virtio->cur_queue->used);
 
            } else {
-               PrintError("Illegal write length for page frame number\n");
+               PrintError(core->vm_info, core, "Illegal write length for page frame number\n");
                return -1;
            }
            break;
@@ -250,7 +250,7 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src,
            virtio->virtio_cfg.vring_queue_selector = *(uint16_t *)src;
 
            if (virtio->virtio_cfg.vring_queue_selector > 1) {
-               PrintError("Virtio Balloon device only uses 2 queue, selected %d\n", 
+               PrintError(core->vm_info, core, "Virtio Balloon device only uses 2 queue, selected %d\n", 
                           virtio->virtio_cfg.vring_queue_selector);
                return -1;
            }
@@ -259,9 +259,9 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src,
 
            break;
        case VRING_Q_NOTIFY_PORT:
-           PrintDebug("Handling Kick\n");
+           PrintDebug(core->vm_info, core, "Handling Kick\n");
            if (handle_kick(core, virtio) == -1) {
-               PrintError("Could not handle Balloon Notification\n");
+               PrintError(core->vm_info, core, "Could not handle Balloon Notification\n");
                return -1;
            }
            break;
@@ -269,7 +269,7 @@ static int virtio_io_write(struct guest_info * core, uint16_t port, void * src,
            virtio->virtio_cfg.status = *(uint8_t *)src;
 
            if (virtio->virtio_cfg.status == 0) {
-               PrintDebug("Resetting device\n");
+               PrintDebug(core->vm_info, core, "Resetting device\n");
                virtio_reset(virtio);
            }
 
@@ -292,13 +292,13 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u
     int port_idx = port % virtio->io_range_size;
 
 
-    PrintDebug("VIRTIO BALLOON Read  for port %d (index =%d), length=%d\n", 
+    PrintDebug(core->vm_info, core, "VIRTIO BALLOON Read  for port %d (index =%d), length=%d\n", 
               port, port_idx, length);
 
     switch (port_idx) {
        case HOST_FEATURES_PORT:
            if (length != 4) {
-               PrintError("Illegal read length for host features\n");
+               PrintError(core->vm_info, core, "Illegal read length for host features\n");
                return -1;
            }
 
@@ -307,7 +307,7 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u
            break;
        case VRING_PG_NUM_PORT:
            if (length != 4) {
-               PrintError("Illegal read length for page frame number\n");
+               PrintError(core->vm_info, core, "Illegal read length for page frame number\n");
                return -1;
            }
 
@@ -316,7 +316,7 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u
            break;
        case VRING_SIZE_PORT:
            if (length != 2) {
-               PrintError("Illegal read length for vring size\n");
+               PrintError(core->vm_info, core, "Illegal read length for vring size\n");
                return -1;
            }
                
@@ -326,7 +326,7 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u
 
        case VIRTIO_STATUS_PORT:
            if (length != 1) {
-               PrintError("Illegal read length for status\n");
+               PrintError(core->vm_info, core, "Illegal read length for status\n");
                return -1;
            }
 
@@ -348,7 +348,7 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u
                memcpy(dst, cfg_ptr + cfg_offset, length);
                
            } else {
-               PrintError("Read of Unhandled Virtio Read\n");
+               PrintError(core->vm_info, core, "Read of Unhandled Virtio Read\n");
                return -1;
            }
          
@@ -377,7 +377,7 @@ static struct v3_device_ops dev_ops = {
 static int set_size(struct virtio_balloon_state * virtio, addr_t size) {
     virtio->balloon_cfg.requested_pages = size / PAGE_SIZE; // number of pages
 
-    PrintDebug("Requesting %d pages\n", virtio->balloon_cfg.requested_pages);
+    PrintDebug(VM_NONE, VCORE_NONE, "Requesting %d pages\n", virtio->balloon_cfg.requested_pages);
 
     v3_pci_raise_irq(virtio->pci_bus, virtio->pci_dev, 0);
     virtio->virtio_cfg.pci_isr = VIRTIO_ISR_ACTIVE | VIRTIO_ISR_CFG_CHANGED;
@@ -416,10 +416,10 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct pci_device * pci_dev = NULL;
     char * dev_id = v3_cfg_val(cfg, "ID");
 
-    PrintDebug("Initializing VIRTIO Balloon device\n");
+    PrintDebug(vm, VCORE_NONE, "Initializing VIRTIO Balloon device\n");
 
     if (pci_bus == NULL) {
-       PrintError("VirtIO devices require a PCI Bus");
+       PrintError(vm, VCORE_NONE, "VirtIO devices require a PCI Bus");
        return -1;
     }
 
@@ -427,7 +427,7 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     virtio_state = (struct virtio_balloon_state *)V3_Malloc(sizeof(struct virtio_balloon_state));
 
     if (!virtio_state) {
-       PrintError("Cannot allocate in init\n");
+       PrintError(vm, VCORE_NONE, "Cannot allocate in init\n");
        return -1;
     }
 
@@ -437,7 +437,7 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, virtio_state);
 
     if (dev == NULL) {
-       PrintError("Could not attach device %s\n", dev_id);
+       PrintError(vm, VCORE_NONE, "Could not attach device %s\n", dev_id);
        V3_Free(virtio_state);
        return -1;
     }
@@ -485,7 +485,7 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
                                         NULL, NULL, NULL, NULL, virtio_state);
 
        if (!pci_dev) {
-           PrintError("Could not register PCI Device\n");
+           PrintError(vm, VCORE_NONE, "Could not register PCI Device\n");
            v3_remove_device(dev);
            return -1;
        }