aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libvfio-user.h16
-rw-r--r--lib/cap.c44
-rw-r--r--lib/dma.c22
-rw-r--r--lib/dma.h4
-rw-r--r--lib/irq.c44
-rw-r--r--lib/libvfio-user.c112
-rw-r--r--lib/migration.c30
-rw-r--r--lib/pci.c52
-rw-r--r--lib/private.h2
-rw-r--r--lib/python_bindings.c8
-rw-r--r--lib/tran_sock.c22
-rw-r--r--samples/client.c2
-rw-r--r--samples/gpio-pci-idio-16.c4
-rw-r--r--samples/null.c4
-rw-r--r--samples/server.c16
15 files changed, 189 insertions, 193 deletions
diff --git a/include/libvfio-user.h b/include/libvfio-user.h
index 4735991..f6a073c 100644
--- a/include/libvfio-user.h
+++ b/include/libvfio-user.h
@@ -41,6 +41,7 @@
#include <stdint.h>
#include <sys/uio.h>
#include <unistd.h>
+#include <syslog.h>
#include "pci.h"
#include "pci_caps/pm.h"
@@ -110,19 +111,14 @@ vfu_pci_get_config_space(vfu_ctx_t *vfu_ctx);
#define VFU_DMA_REGIONS 0x10
-typedef enum {
- VFU_ERR,
- VFU_INF,
- VFU_DBG
-} vfu_log_lvl_t;
-
/**
* Callback function signature for log function
* @pvt: private pointer
+ * @level: log level as defined in syslog(3)
* @vfu_log_fn_t: typedef for log function.
* @msg: message
*/
-typedef void (vfu_log_fn_t) (void *pvt, vfu_log_lvl_t lvl, const char *msg);
+typedef void (vfu_log_fn_t) (void *pvt, int level, const char *msg);
/**
* Callback function that gets called when a capability is accessed. The
@@ -261,10 +257,10 @@ vfu_create_ctx(vfu_trans_t trans, const char *path,
* Setup logging information.
* @vfu_ctx: the libvfio-user context
* @log: logging function
- * @log_lvl: logging level
+ * @level: logging level as defined in syslog(3)
*/
int
-vfu_setup_log(vfu_ctx_t *vfu_ctx, vfu_log_fn_t *log, vfu_log_lvl_t log_lvl);
+vfu_setup_log(vfu_ctx_t *vfu_ctx, vfu_log_fn_t *log, int level);
//TODO: Check other PCI header registers suitable to be filled by device.
// Or should we pass whole vfu_pci_hdr_t to be filled by user.
@@ -637,7 +633,7 @@ uint8_t *
vfu_ctx_get_cap(vfu_ctx_t *vfu_ctx, uint8_t id);
void
-vfu_log(vfu_ctx_t *vfu_ctx, vfu_log_lvl_t lvl, const char *fmt, ...);
+vfu_log(vfu_ctx_t *vfu_ctx, int level, const char *fmt, ...);
#ifdef __cplusplus
}
diff --git a/lib/cap.c b/lib/cap.c
index 0bb975a..aad9f0a 100644
--- a/lib/cap.c
+++ b/lib/cap.c
@@ -182,16 +182,16 @@ handle_pmcs_write(vfu_ctx_t *vfu_ctx, struct pmcap *pm,
{
if (pm->pmcs.ps != pmcs->ps) {
- vfu_log(vfu_ctx, VFU_DBG, "power state set to %#x\n", pmcs->ps);
+ vfu_log(vfu_ctx, LOG_DEBUG, "power state set to %#x\n", pmcs->ps);
}
if (pm->pmcs.pmee != pmcs->pmee) {
- vfu_log(vfu_ctx, VFU_DBG, "PME enable set to %#x\n", pmcs->pmee);
+ vfu_log(vfu_ctx, LOG_DEBUG, "PME enable set to %#x\n", pmcs->pmee);
}
if (pm->pmcs.dse != pmcs->dse) {
- vfu_log(vfu_ctx, VFU_DBG, "data select set to %#x\n", pmcs->dse);
+ vfu_log(vfu_ctx, LOG_DEBUG, "data select set to %#x\n", pmcs->dse);
}
if (pm->pmcs.pmes != pmcs->pmes) {
- vfu_log(vfu_ctx, VFU_DBG, "PME status set to %#x\n", pmcs->pmes);
+ vfu_log(vfu_ctx, LOG_DEBUG, "PME status set to %#x\n", pmcs->pmes);
}
pm->pmcs = *pmcs;
return 0;
@@ -227,16 +227,16 @@ handle_mxc_write(vfu_ctx_t *vfu_ctx, struct msixcap *msix,
assert(mxc != NULL);
if (mxc->mxe != msix->mxc.mxe) {
- vfu_log(vfu_ctx, VFU_DBG, "%s MSI-X\n",
+ vfu_log(vfu_ctx, LOG_DEBUG, "%s MSI-X\n",
mxc->mxe ? "enable" : "disable");
msix->mxc.mxe = mxc->mxe;
}
if (mxc->fm != msix->mxc.fm) {
if (mxc->fm) {
- vfu_log(vfu_ctx, VFU_DBG, "all MSI-X vectors masked\n");
+ vfu_log(vfu_ctx, LOG_DEBUG, "all MSI-X vectors masked\n");
} else {
- vfu_log(vfu_ctx, VFU_DBG,
+ vfu_log(vfu_ctx, LOG_DEBUG,
"vector's mask bit determines whether vector is masked\n");
}
msix->mxc.fm = mxc->fm;
@@ -256,12 +256,12 @@ handle_msix_write(vfu_ctx_t *vfu_ctx, uint8_t *cap, char *const buf,
case offsetof(struct msixcap, mxc):
return handle_mxc_write(vfu_ctx, msix, (struct mxc *)buf);
default:
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"invalid MSI-X write offset %ld\n", offset);
return -EINVAL;
}
}
- vfu_log(vfu_ctx, VFU_ERR, "invalid MSI-X write size %lu\n", count);
+ vfu_log(vfu_ctx, LOG_ERR, "invalid MSI-X write size %lu\n", count);
return -EINVAL;
}
@@ -274,63 +274,63 @@ handle_px_pxdc_write(vfu_ctx_t *vfu_ctx, struct pxcap *px,
if (p->cere != px->pxdc.cere) {
px->pxdc.cere = p->cere;
- vfu_log(vfu_ctx, VFU_DBG, "CERE %s\n", p->cere ? "enable" : "disable");
+ vfu_log(vfu_ctx, LOG_DEBUG, "CERE %s\n", p->cere ? "enable" : "disable");
}
if (p->nfere != px->pxdc.nfere) {
px->pxdc.nfere = p->nfere;
- vfu_log(vfu_ctx, VFU_DBG, "NFERE %s\n",
+ vfu_log(vfu_ctx, LOG_DEBUG, "NFERE %s\n",
p->nfere ? "enable" : "disable");
}
if (p->fere != px->pxdc.fere) {
px->pxdc.fere = p->fere;
- vfu_log(vfu_ctx, VFU_DBG, "FERE %s\n", p->fere ? "enable" : "disable");
+ vfu_log(vfu_ctx, LOG_DEBUG, "FERE %s\n", p->fere ? "enable" : "disable");
}
if (p->urre != px->pxdc.urre) {
px->pxdc.urre = p->urre;
- vfu_log(vfu_ctx, VFU_DBG, "URRE %s\n", p->urre ? "enable" : "disable");
+ vfu_log(vfu_ctx, LOG_DEBUG, "URRE %s\n", p->urre ? "enable" : "disable");
}
if (p->ero != px->pxdc.ero) {
px->pxdc.ero = p->ero;
- vfu_log(vfu_ctx, VFU_DBG, "ERO %s\n", p->ero ? "enable" : "disable");
+ vfu_log(vfu_ctx, LOG_DEBUG, "ERO %s\n", p->ero ? "enable" : "disable");
}
if (p->mps != px->pxdc.mps) {
px->pxdc.mps = p->mps;
- vfu_log(vfu_ctx, VFU_DBG, "MPS set to %d\n", p->mps);
+ vfu_log(vfu_ctx, LOG_DEBUG, "MPS set to %d\n", p->mps);
}
if (p->ete != px->pxdc.ete) {
px->pxdc.ete = p->ete;
- vfu_log(vfu_ctx, VFU_DBG, "ETE %s\n", p->ete ? "enable" : "disable");
+ vfu_log(vfu_ctx, LOG_DEBUG, "ETE %s\n", p->ete ? "enable" : "disable");
}
if (p->pfe != px->pxdc.pfe) {
px->pxdc.pfe = p->pfe;
- vfu_log(vfu_ctx, VFU_DBG, "PFE %s\n", p->pfe ? "enable" : "disable");
+ vfu_log(vfu_ctx, LOG_DEBUG, "PFE %s\n", p->pfe ? "enable" : "disable");
}
if (p->appme != px->pxdc.appme) {
px->pxdc.appme = p->appme;
- vfu_log(vfu_ctx, VFU_DBG, "APPME %s\n",
+ vfu_log(vfu_ctx, LOG_DEBUG, "APPME %s\n",
p->appme ? "enable" : "disable");
}
if (p->ens != px->pxdc.ens) {
px->pxdc.ens = p->ens;
- vfu_log(vfu_ctx, VFU_DBG, "ENS %s\n", p->ens ? "enable" : "disable");
+ vfu_log(vfu_ctx, LOG_DEBUG, "ENS %s\n", p->ens ? "enable" : "disable");
}
if (p->mrrs != px->pxdc.mrrs) {
px->pxdc.mrrs = p->mrrs;
- vfu_log(vfu_ctx, VFU_DBG, "MRRS set to %d\n", p->mrrs);
+ vfu_log(vfu_ctx, LOG_DEBUG, "MRRS set to %d\n", p->mrrs);
}
if (p->iflr) {
- vfu_log(vfu_ctx, VFU_DBG,
+ vfu_log(vfu_ctx, LOG_DEBUG,
"initiate function level reset\n");
}
@@ -465,7 +465,7 @@ caps_create(vfu_ctx_t *vfu_ctx, vfu_cap_t **vfu_caps, int nr_caps, int *err)
next += size;
assert(next % 4 == 0); /* FIXME */
- vfu_log(vfu_ctx, VFU_DBG, "initialized capability %s %#x-%#x\n",
+ vfu_log(vfu_ctx, LOG_DEBUG, "initialized capability %s %#x-%#x\n",
cap_handlers[id].name, caps->caps[i].start, caps->caps[i].end);
}
caps->nr_caps = nr_caps;
diff --git a/lib/dma.c b/lib/dma.c
index 061106f..0bb623c 100644
--- a/lib/dma.c
+++ b/lib/dma.c
@@ -101,13 +101,13 @@ _dma_controller_do_remove_region(dma_controller_t *dma,
err = dma_unmap_region(region, region->virt_addr, region->size);
if (err != 0) {
- vfu_log(dma->vfu_ctx, VFU_DBG, "failed to unmap fd=%d vaddr=%p-%p\n",
+ vfu_log(dma->vfu_ctx, LOG_DEBUG, "failed to unmap fd=%d vaddr=%p-%p\n",
region->fd, region->virt_addr,
region->virt_addr + region->size - 1);
}
if (region->fd != -1) {
if (close(region->fd) == -1) {
- vfu_log(dma->vfu_ctx, VFU_DBG,
+ vfu_log(dma->vfu_ctx, LOG_DEBUG,
"failed to close fd %d: %m\n", region->fd);
}
}
@@ -160,7 +160,7 @@ dma_controller_remove_region(dma_controller_t *dma,
if (region->refcnt > 0) {
err = unmap_dma(data, region->dma_addr, region->size);
if (err != 0) {
- vfu_log(dma->vfu_ctx, VFU_ERR,
+ vfu_log(dma->vfu_ctx, LOG_ERR,
"failed to notify of removal of DMA region %#lx-%#lx: %s\n",
region->dma_addr, region->dma_addr + region->size,
strerror(-err));
@@ -194,7 +194,7 @@ dma_controller_remove_regions(dma_controller_t *dma)
for (i = 0; i < dma->nregions; i++) {
dma_memory_region_t *region = &dma->regions[i];
- vfu_log(dma->vfu_ctx, VFU_INF, "unmap vaddr=%p IOVA=%lx",
+ vfu_log(dma->vfu_ctx, LOG_INFO, "unmap vaddr=%p IOVA=%lx",
region->virt_addr, region->dma_addr);
_dma_controller_do_remove_region(dma, region);
@@ -229,7 +229,7 @@ dma_controller_add_region(dma_controller_t *dma,
/* First check if this is the same exact region. */
if (region->dma_addr == dma_addr && region->size == size) {
if (offset != region->offset) {
- vfu_log(dma->vfu_ctx, VFU_ERR,
+ vfu_log(dma->vfu_ctx, LOG_ERR,
"bad offset for new DMA region %#lx-%#lx, want=%ld, existing=%ld\n",
dma_addr, dma_addr + size, offset, region->offset);
goto err;
@@ -241,7 +241,7 @@ dma_controller_add_region(dma_controller_t *dma,
* the same file, however in the majority of cases we'll be
* using a single fd.
*/
- vfu_log(dma->vfu_ctx, VFU_ERR,
+ vfu_log(dma->vfu_ctx, LOG_ERR,
"bad fd=%d for new DMA region %#lx-%#lx, existing fd=%d\n",
fd, offset, offset + size, region->fd);
goto err;
@@ -254,7 +254,7 @@ dma_controller_add_region(dma_controller_t *dma,
dma_addr < region->dma_addr + region->size) ||
(region->dma_addr >= dma_addr &&
region->dma_addr < dma_addr + size)) {
- vfu_log(dma->vfu_ctx, VFU_INF,
+ vfu_log(dma->vfu_ctx, LOG_INFO,
"new DMA region %#lx+%#lx overlaps with DMA region %#lx-%#lx\n",
dma_addr, size, region->dma_addr, region->size);
goto err;
@@ -263,7 +263,7 @@ dma_controller_add_region(dma_controller_t *dma,
if (dma->nregions == dma->max_regions) {
idx = dma->max_regions;
- vfu_log(dma->vfu_ctx, VFU_ERR,
+ vfu_log(dma->vfu_ctx, LOG_ERR,
"reached maxed regions, recompile with higher number of DMA regions\n");
goto err;
}
@@ -274,7 +274,7 @@ dma_controller_add_region(dma_controller_t *dma,
if (fd != -1) {
page_size = fd_get_blocksize(fd);
if (page_size < 0) {
- vfu_log(dma->vfu_ctx, VFU_ERR, "bad page size %d\n", page_size);
+ vfu_log(dma->vfu_ctx, LOG_ERR, "bad page size %d\n", page_size);
goto err;
}
}
@@ -291,12 +291,12 @@ dma_controller_add_region(dma_controller_t *dma,
region->virt_addr = dma_map_region(region, PROT_READ | PROT_WRITE,
0, region->size);
if (region->virt_addr == MAP_FAILED) {
- vfu_log(dma->vfu_ctx, VFU_ERR,
+ vfu_log(dma->vfu_ctx, LOG_ERR,
"failed to memory map DMA region %#lx-%#lx: %s\n",
dma_addr, dma_addr + size, strerror(errno));
if (region->fd != -1) {
if (close(region->fd) == -1) {
- vfu_log(dma->vfu_ctx, VFU_DBG,
+ vfu_log(dma->vfu_ctx, LOG_DEBUG,
"failed to close fd %d: %m\n", region->fd);
}
}
diff --git a/lib/dma.h b/lib/dma.h
index dacf5bf..cd71e4e 100644
--- a/lib/dma.h
+++ b/lib/dma.h
@@ -238,7 +238,7 @@ dma_map_sg(dma_controller_t *dma, const dma_sg_t *sg, struct iovec *iov,
int i;
for (i = 0; i < cnt; i++) {
- vfu_log(dma->vfu_ctx, VFU_DBG, "map %#lx-%#lx\n",
+ vfu_log(dma->vfu_ctx, LOG_DEBUG, "map %#lx-%#lx\n",
sg->dma_addr + sg->offset, sg->dma_addr + sg->offset + sg->length);
region = &dma->regions[sg[i].region];
iov[i].iov_base = region->virt_addr + sg[i].offset;
@@ -271,7 +271,7 @@ dma_unmap_sg(dma_controller_t *dma, const dma_sg_t *sg,
/* bad region */
continue;
}
- vfu_log(dma->vfu_ctx, VFU_DBG, "unmap %#lx-%#lx\n",
+ vfu_log(dma->vfu_ctx, LOG_DEBUG, "unmap %#lx-%#lx\n",
sg[i].dma_addr + sg[i].offset, sg[i].dma_addr + sg[i].offset + sg[i].length);
r->refcnt--;
}
diff --git a/lib/irq.c b/lib/irq.c
index 426e0ae..aae5f26 100644
--- a/lib/irq.c
+++ b/lib/irq.c
@@ -65,13 +65,13 @@ irqs_disable(vfu_ctx_t *vfu_ctx, uint32_t index)
case VFIO_PCI_INTX_IRQ_INDEX:
case VFIO_PCI_MSI_IRQ_INDEX:
case VFIO_PCI_MSIX_IRQ_INDEX:
- vfu_log(vfu_ctx, VFU_DBG, "disabling IRQ %s",
+ vfu_log(vfu_ctx, LOG_DEBUG, "disabling IRQ %s",
vfio_irq_idx_to_str(index));
vfu_ctx->irqs->type = IRQ_NONE;
for (i = 0; i < vfu_ctx->irqs->max_ivs; i++) {
if (vfu_ctx->irqs->efds[i] >= 0) {
if (close(vfu_ctx->irqs->efds[i]) == -1) {
- vfu_log(vfu_ctx, VFU_DBG, "failed to close IRQ fd %d: %m",
+ vfu_log(vfu_ctx, LOG_DEBUG, "failed to close IRQ fd %d: %m",
vfu_ctx->irqs->efds[i]);
}
vfu_ctx->irqs->efds[i] = -1;
@@ -89,7 +89,7 @@ irqs_disable(vfu_ctx_t *vfu_ctx, uint32_t index)
if (irq_efd != NULL) {
if (*irq_efd != -1) {
if (close(*irq_efd) == -1) {
- vfu_log(vfu_ctx, VFU_DBG, "failed to close IRQ fd %d: %m",
+ vfu_log(vfu_ctx, LOG_DEBUG, "failed to close IRQ fd %d: %m",
*irq_efd);
}
*irq_efd = -1;
@@ -97,7 +97,7 @@ irqs_disable(vfu_ctx_t *vfu_ctx, uint32_t index)
return 0;
}
- vfu_log(vfu_ctx, VFU_DBG, "failed to disable IRQs");
+ vfu_log(vfu_ctx, LOG_DEBUG, "failed to disable IRQs");
return -EINVAL;
}
@@ -115,7 +115,7 @@ irqs_set_data_none(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set)
val = 1;
ret = eventfd_write(efd, val);
if (ret == -1) {
- vfu_log(vfu_ctx, VFU_DBG,
+ vfu_log(vfu_ctx, LOG_DEBUG,
"IRQ: failed to set data to none: %m");
return -errno;
}
@@ -142,7 +142,7 @@ irqs_set_data_bool(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set, void *data)
val = 1;
ret = eventfd_write(efd, val);
if (ret == -1) {
- vfu_log(vfu_ctx, VFU_DBG,
+ vfu_log(vfu_ctx, LOG_DEBUG,
"IRQ: failed to set data to bool: %m");
return -errno;
}
@@ -166,7 +166,7 @@ irqs_set_data_eventfd(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set,
efd = vfu_ctx->irqs->efds[i];
if (efd >= 0) {
if (close(efd) == -1) {
- vfu_log(vfu_ctx, VFU_DBG, "failed to close IRQ fd %d: %m", efd);
+ vfu_log(vfu_ctx, LOG_DEBUG, "failed to close IRQ fd %d: %m", efd);
}
vfu_ctx->irqs->efds[i] = -1;
@@ -177,7 +177,7 @@ irqs_set_data_eventfd(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set,
* nr_fds == irq_set->count.
*/
vfu_ctx->irqs->efds[i] = consume_fd(data, irq_set->count, j);
- vfu_log(vfu_ctx, VFU_DBG, "event fd[%d]=%d", i, vfu_ctx->irqs->efds[i]);
+ vfu_log(vfu_ctx, LOG_DEBUG, "event fd[%d]=%d", i, vfu_ctx->irqs->efds[i]);
}
return 0;
@@ -195,7 +195,7 @@ irqs_trigger(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set, void *data)
return irqs_disable(vfu_ctx, irq_set->index);
}
- vfu_log(vfu_ctx, VFU_DBG, "setting IRQ %s flags=%#x",
+ vfu_log(vfu_ctx, LOG_DEBUG, "setting IRQ %s flags=%#x",
vfio_irq_idx_to_str(irq_set->index), irq_set->flags);
switch (irq_set->flags & VFIO_IRQ_SET_DATA_TYPE_MASK) {
@@ -227,7 +227,7 @@ dev_set_irqs_validate(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set)
// Ensure index is within bounds.
if (irq_set->index >= VFU_DEV_NUM_IRQS) {
- vfu_log(vfu_ctx, VFU_DBG, "bad IRQ index %d\n", irq_set->index);
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad IRQ index %d\n", irq_set->index);
return -EINVAL;
}
@@ -237,39 +237,39 @@ dev_set_irqs_validate(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set)
if ((a_type != VFIO_IRQ_SET_ACTION_MASK) &&
(a_type != VFIO_IRQ_SET_ACTION_UNMASK) &&
(a_type != VFIO_IRQ_SET_ACTION_TRIGGER)) {
- vfu_log(vfu_ctx, VFU_DBG, "bad IRQ action mask %d\n", a_type);
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad IRQ action mask %d\n", a_type);
return -EINVAL;
}
// Only one of NONE/BOOL/EVENTFD is valid.
if ((d_type != VFIO_IRQ_SET_DATA_NONE) &&
(d_type != VFIO_IRQ_SET_DATA_BOOL) &&
(d_type != VFIO_IRQ_SET_DATA_EVENTFD)) {
- vfu_log(vfu_ctx, VFU_DBG, "bad IRQ data %d\n", d_type);
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad IRQ data %d\n", d_type);
return -EINVAL;
}
// Ensure irq_set's start and count are within bounds.
if ((irq_set->start >= vfu_ctx->irq_count[irq_set->index]) ||
(irq_set->start + irq_set->count > vfu_ctx->irq_count[irq_set->index])) {
- vfu_log(vfu_ctx, VFU_DBG, "bad IRQ start/count\n");
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad IRQ start/count\n");
return -EINVAL;
}
// Only TRIGGER is valid for ERR/REQ.
if (((irq_set->index == VFIO_PCI_ERR_IRQ_INDEX) ||
(irq_set->index == VFIO_PCI_REQ_IRQ_INDEX)) &&
(a_type != VFIO_IRQ_SET_ACTION_TRIGGER)) {
- vfu_log(vfu_ctx, VFU_DBG, "bad IRQ trigger w/o ERR/REQ\n");
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad IRQ trigger w/o ERR/REQ\n");
return -EINVAL;
}
// count == 0 is only valid with ACTION_TRIGGER and DATA_NONE.
if ((irq_set->count == 0) && ((a_type != VFIO_IRQ_SET_ACTION_TRIGGER) ||
(d_type != VFIO_IRQ_SET_DATA_NONE))) {
- vfu_log(vfu_ctx, VFU_DBG, "bad IRQ count %d\n", irq_set->count);
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad IRQ count %d\n", irq_set->count);
return -EINVAL;
}
// If IRQs are set, ensure index matches what's enabled for the device.
if ((irq_set->count != 0) && (vfu_ctx->irqs->type != IRQ_NONE) &&
(irq_set->index != LM2VFIO_IRQT(vfu_ctx->irqs->type))) {
- vfu_log(vfu_ctx, VFU_DBG, "bad IRQ index\n");
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad IRQ index\n");
return -EINVAL;
}
@@ -311,7 +311,7 @@ dev_get_irqinfo(vfu_ctx_t *vfu_ctx, struct vfio_irq_info *irq_info_in,
// Ensure provided argsz is sufficiently big and index is within bounds.
if ((irq_info_in->argsz < sizeof(struct vfio_irq_info)) ||
(irq_info_in->index >= VFU_DEV_NUM_IRQS)) {
- vfu_log(vfu_ctx, VFU_DBG, "bad irq_info (size=%d index=%d)\n",
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad irq_info (size=%d index=%d)\n",
irq_info_in->argsz, irq_info_in->index);
return -EINVAL;
}
@@ -348,7 +348,7 @@ handle_device_set_irqs(vfu_ctx_t *vfu_ctx, uint32_t size,
assert(irq_set != NULL);
if (size < sizeof *irq_set || size != irq_set->argsz) {
- vfu_log(vfu_ctx, VFU_ERR, "bad size %d", size);
+ vfu_log(vfu_ctx, LOG_ERR, "bad size %d", size);
return -EINVAL;
}
@@ -356,7 +356,7 @@ handle_device_set_irqs(vfu_ctx_t *vfu_ctx, uint32_t size,
case VFIO_IRQ_SET_DATA_EVENTFD:
data = fds;
if (nr_fds != irq_set->count) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"bad number of FDs, expected=%u, actual=%d", nr_fds,
irq_set->count);
return -EINVAL;
@@ -366,7 +366,7 @@ handle_device_set_irqs(vfu_ctx_t *vfu_ctx, uint32_t size,
data = irq_set + 1;
break;
default:
- vfu_log(vfu_ctx, VFU_ERR, "invalid IRQ type %d",
+ vfu_log(vfu_ctx, LOG_ERR, "invalid IRQ type %d",
irq_set->flags & VFIO_IRQ_SET_DATA_TYPE_MASK);
return -EINVAL;
}
@@ -383,7 +383,7 @@ validate_irq_subindex(vfu_ctx_t *vfu_ctx, uint32_t subindex)
}
if ((subindex >= vfu_ctx->irqs->max_ivs)) {
- vfu_log(vfu_ctx, VFU_ERR, "bad IRQ %d, max=%d\n", subindex,
+ vfu_log(vfu_ctx, LOG_ERR, "bad IRQ %d, max=%d\n", subindex,
vfu_ctx->irqs->max_ivs);
/* FIXME should return -errno */
errno = EINVAL;
@@ -405,7 +405,7 @@ vfu_irq_trigger(vfu_ctx_t *vfu_ctx, uint32_t subindex)
}
if (vfu_ctx->irqs->efds[subindex] == -1) {
- vfu_log(vfu_ctx, VFU_ERR, "no fd for interrupt %d\n", subindex);
+ vfu_log(vfu_ctx, LOG_ERR, "no fd for interrupt %d\n", subindex);
/* FIXME should return -errno */
errno = ENOENT;
return -1;
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 70b019b..45e5472 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -58,7 +58,7 @@
#include "irq.h"
void
-vfu_log(vfu_ctx_t *vfu_ctx, vfu_log_lvl_t lvl, const char *fmt, ...)
+vfu_log(vfu_ctx_t *vfu_ctx, int level, const char *fmt, ...)
{
va_list ap;
char buf[BUFSIZ];
@@ -66,14 +66,14 @@ vfu_log(vfu_ctx_t *vfu_ctx, vfu_log_lvl_t lvl, const char *fmt, ...)
assert(vfu_ctx != NULL);
- if (vfu_ctx->log == NULL || lvl > vfu_ctx->log_lvl || fmt == NULL) {
+ if (vfu_ctx->log == NULL || level > vfu_ctx->log_level || fmt == NULL) {
return;
}
va_start(ap, fmt);
vsnprintf(buf, sizeof buf, fmt, ap);
va_end(ap);
- vfu_ctx->log(vfu_ctx->pvt, lvl, buf);
+ vfu_ctx->log(vfu_ctx->pvt, level, buf);
errno = _errno;
}
@@ -149,7 +149,7 @@ dev_get_caps(vfu_ctx_t *vfu_ctx, vfu_reg_info_t *vfu_reg, bool is_migr_reg,
for (i = 0; i < nr_mmap_areas; i++) {
sparse->areas[i].offset = mmap_areas->areas[i].start;
sparse->areas[i].size = mmap_areas->areas[i].size;
- vfu_log(vfu_ctx, VFU_DBG, "%s: area %d %#llx-%#llx", __func__,
+ vfu_log(vfu_ctx, LOG_DEBUG, "%s: area %d %#llx-%#llx", __func__,
i, sparse->areas[i].offset,
sparse->areas[i].offset + sparse->areas[i].size);
}
@@ -225,7 +225,7 @@ dev_get_reginfo(vfu_ctx_t *vfu_ctx, uint32_t index,
vfu_reg = &vfu_ctx->reg_info[index];
if (index >= vfu_ctx->nr_regions) {
- vfu_log(vfu_ctx, VFU_DBG, "bad region index %d", index);
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad region index %d", index);
return -EINVAL;
}
@@ -247,7 +247,7 @@ dev_get_reginfo(vfu_ctx_t *vfu_ctx, uint32_t index,
dev_get_caps(vfu_ctx, vfu_reg, is_migr_reg(vfu_ctx, index), *vfio_reg);
}
- vfu_log(vfu_ctx, VFU_DBG, "region_info[%d] offset %#llx flags %#x size %llu "
+ vfu_log(vfu_ctx, LOG_DEBUG, "region_info[%d] offset %#llx flags %#x size %llu "
"argsz %u",
(*vfio_reg)->index, (*vfio_reg)->offset, (*vfio_reg)->flags,
(*vfio_reg)->size, (*vfio_reg)->argsz);
@@ -294,7 +294,7 @@ handle_pci_config_space_access(vfu_ctx_t *vfu_ctx, char *buf, size_t count,
if (is_write) {
ret = cap_maybe_access(vfu_ctx, vfu_ctx->caps, buf, count, pos);
if (ret < 0) {
- vfu_log(vfu_ctx, VFU_ERR, "bad access to capabilities %#lx-%#lx\n",
+ vfu_log(vfu_ctx, LOG_ERR, "bad access to capabilities %#lx-%#lx\n",
pos, pos + count);
return ret;
}
@@ -316,12 +316,12 @@ do_access(vfu_ctx_t *vfu_ctx, char *buf, uint8_t count, uint64_t pos, bool is_wr
idx = vfu_get_region(pos, count, &offset);
if (idx < 0) {
- vfu_log(vfu_ctx, VFU_ERR, "invalid region %d", idx);
+ vfu_log(vfu_ctx, LOG_ERR, "invalid region %d", idx);
return idx;
}
if (idx < 0 || idx >= (int)vfu_ctx->nr_regions) {
- vfu_log(vfu_ctx, VFU_ERR, "bad region %d", idx);
+ vfu_log(vfu_ctx, LOG_ERR, "bad region %d", idx);
return -EINVAL;
}
@@ -332,7 +332,7 @@ do_access(vfu_ctx_t *vfu_ctx, char *buf, uint8_t count, uint64_t pos, bool is_wr
if (is_migr_reg(vfu_ctx, idx)) {
if (offset + count > vfu_ctx->reg_info[idx].size) {
- vfu_log(vfu_ctx, VFU_ERR, "read %#lx-%#lx past end of migration region (%#x)",
+ vfu_log(vfu_ctx, LOG_ERR, "read %#lx-%#lx past end of migration region (%#x)",
offset, offset + count - 1,
vfu_ctx->reg_info[idx].size);
return -EINVAL;
@@ -353,7 +353,7 @@ do_access(vfu_ctx_t *vfu_ctx, char *buf, uint8_t count, uint64_t pos, bool is_wr
is_write);
}
- vfu_log(vfu_ctx, VFU_ERR, "no callback for region %d", idx);
+ vfu_log(vfu_ctx, LOG_ERR, "no callback for region %d", idx);
return -EINVAL;
}
@@ -397,7 +397,7 @@ _vfu_access(vfu_ctx_t *vfu_ctx, char *buf, uint32_t count, uint64_t *ppos,
}
ret = do_access(vfu_ctx, buf, size, *ppos, is_write);
if (ret <= 0) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to %s %#lx-%#lx: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to %s %#lx-%#lx: %s",
is_write ? "write to" : "read from", *ppos, *ppos + size - 1,
strerror(-ret));
/*
@@ -406,7 +406,7 @@ _vfu_access(vfu_ctx_t *vfu_ctx, char *buf, uint32_t count, uint64_t *ppos,
return -EFAULT;
}
if (ret != (int)size) {
- vfu_log(vfu_ctx, VFU_DBG, "bad read %d != %ld", ret, size);
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad read %d != %ld", ret, size);
}
count -= size;
done += size;
@@ -427,7 +427,7 @@ vfu_access(vfu_ctx_t *vfu_ctx, bool is_write, char *rwbuf, uint32_t count,
assert(rwbuf != NULL);
assert(pos != NULL);
- vfu_log(vfu_ctx, VFU_DBG, "%s %#lx-%#lx", is_write ? "W" : "R", *pos,
+ vfu_log(vfu_ctx, LOG_DEBUG, "%s %#lx-%#lx", is_write ? "W" : "R", *pos,
*pos + count - 1);
#ifdef VFU_VERBOSE_LOGGING
@@ -440,7 +440,7 @@ vfu_access(vfu_ctx_t *vfu_ctx, bool is_write, char *rwbuf, uint32_t count,
ret = vfu_pci_hdr_access(vfu_ctx, &_count, pos, is_write, rwbuf);
if (ret != 0) {
/* FIXME shouldn't we fail here? */
- vfu_log(vfu_ctx, VFU_ERR, "failed to access PCI header: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to access PCI header: %s",
strerror(-ret));
#ifdef VFU_VERBOSE_LOGGING
dump_buffer("buffer write", rwbuf, _count);
@@ -494,7 +494,7 @@ handle_device_get_info(vfu_ctx_t *vfu_ctx, uint32_t size,
dev_info->num_regions = vfu_ctx->nr_regions;
dev_info->num_irqs = VFU_DEV_NUM_IRQS;
- vfu_log(vfu_ctx, VFU_DBG, "sent devinfo flags %#x, num_regions %d, num_irqs"
+ vfu_log(vfu_ctx, LOG_DEBUG, "sent devinfo flags %#x, num_regions %d, num_irqs"
" %d", dev_info->flags, dev_info->num_regions, dev_info->num_irqs);
return 0;
@@ -543,7 +543,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
}
if (size % sizeof(struct vfio_user_dma_region) != 0) {
- vfu_log(vfu_ctx, VFU_ERR, "bad size of DMA regions %d", size);
+ vfu_log(vfu_ctx, LOG_ERR, "bad size of DMA regions %d", size);
return -EINVAL;
}
@@ -572,7 +572,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
if (fd != -1) {
close(fd);
}
- vfu_log(vfu_ctx, VFU_INF,
+ vfu_log(vfu_ctx, LOG_INFO,
"failed to add DMA region %#lx-%#lx offset=%#lx fd=%d: %s",
dma_regions[i].addr,
dma_regions[i].addr + dma_regions[i].size - 1,
@@ -580,7 +580,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
strerror(-ret));
break;
}
- vfu_log(vfu_ctx, VFU_DBG,
+ vfu_log(vfu_ctx, LOG_DEBUG,
"added DMA region %#lx-%#lx offset=%#lx fd=%d",
dma_regions[i].addr,
dma_regions[i].addr + dma_regions[i].size - 1,
@@ -591,14 +591,14 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
dma_regions[i].size,
vfu_ctx->unmap_dma, vfu_ctx->pvt);
if (ret < 0) {
- vfu_log(vfu_ctx, VFU_INF,
+ vfu_log(vfu_ctx, LOG_INFO,
"failed to remove DMA region %#lx-%#lx: %s",
dma_regions[i].addr,
dma_regions[i].addr + dma_regions[i].size - 1,
strerror(-ret));
break;
}
- vfu_log(vfu_ctx, VFU_DBG,
+ vfu_log(vfu_ctx, LOG_DEBUG,
"removed DMA region %#lx-%#lx",
dma_regions[i].addr,
dma_regions[i].addr + dma_regions[i].size - 1);
@@ -617,7 +617,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
static int
handle_device_reset(vfu_ctx_t *vfu_ctx)
{
- vfu_log(vfu_ctx, VFU_DBG, "Device reset called by client");
+ vfu_log(vfu_ctx, LOG_DEBUG, "Device reset called by client");
if (vfu_ctx->reset != NULL) {
return vfu_ctx->reset(vfu_ctx->pvt);
}
@@ -631,19 +631,19 @@ validate_region_access(vfu_ctx_t *vfu_ctx, uint32_t size, uint16_t cmd,
assert(region_access != NULL);
if (size < sizeof *region_access) {
- vfu_log(vfu_ctx, VFU_ERR, "message size too small (%d)", size);
+ vfu_log(vfu_ctx, LOG_ERR, "message size too small (%d)", size);
return -EINVAL;
}
if (region_access->region > vfu_ctx->nr_regions || region_access->count <= 0) {
- vfu_log(vfu_ctx, VFU_ERR, "bad region %d and/or count %d",
+ vfu_log(vfu_ctx, LOG_ERR, "bad region %d and/or count %d",
region_access->region, region_access->count);
return -EINVAL;
}
if (device_is_stopped_and_copying(vfu_ctx->migration) &&
!is_migr_reg(vfu_ctx, region_access->region)) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"cannot access region %d while device in stop-and-copy state",
region_access->region);
return -EINVAL;
@@ -652,7 +652,7 @@ validate_region_access(vfu_ctx_t *vfu_ctx, uint32_t size, uint16_t cmd,
if (cmd == VFIO_USER_REGION_WRITE &&
size - sizeof *region_access != region_access->count)
{
- vfu_log(vfu_ctx, VFU_ERR, "bad region access, expected %lu, actual %d",
+ vfu_log(vfu_ctx, LOG_ERR, "bad region access, expected %lu, actual %d",
size - sizeof *region_access, region_access->count);
return -EINVAL;
}
@@ -697,7 +697,7 @@ handle_region_access(vfu_ctx_t *vfu_ctx, uint32_t size, uint16_t cmd,
ret = vfu_access(vfu_ctx, cmd == VFIO_USER_REGION_WRITE, buf, count, &offset);
if (ret != (int)region_access->count) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to %s %#x-%#lx: %d",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to %s %#x-%#lx: %d",
cmd == VFIO_USER_REGION_WRITE ? "write" : "read",
region_access->count,
region_access->offset + region_access->count - 1, ret);
@@ -770,7 +770,7 @@ handle_dirty_pages(vfu_ctx_t *vfu_ctx, uint32_t size,
assert(dirty_bitmap != NULL);
if (size < sizeof *dirty_bitmap || size != dirty_bitmap->argsz) {
- vfu_log(vfu_ctx, VFU_ERR, "invalid header size %u", size);
+ vfu_log(vfu_ctx, LOG_ERR, "invalid header size %u", size);
return -EINVAL;
}
@@ -784,7 +784,7 @@ handle_dirty_pages(vfu_ctx_t *vfu_ctx, uint32_t size,
(struct vfio_iommu_type1_dirty_bitmap_get*)(dirty_bitmap + 1),
size - sizeof *dirty_bitmap);
} else {
- vfu_log(vfu_ctx, VFU_ERR, "bad flags %#x", dirty_bitmap->flags);
+ vfu_log(vfu_ctx, LOG_ERR, "bad flags %#x", dirty_bitmap->flags);
ret = -EINVAL;
}
@@ -805,17 +805,17 @@ validate_header(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size)
assert(hdr != NULL);
if (size < sizeof hdr) {
- vfu_log(vfu_ctx, VFU_ERR, "short header read %ld", size);
+ vfu_log(vfu_ctx, LOG_ERR, "short header read %ld", size);
return -EINVAL;
}
if (hdr->flags.type != VFIO_USER_F_TYPE_COMMAND) {
- vfu_log(vfu_ctx, VFU_ERR, "header not a request");
+ vfu_log(vfu_ctx, LOG_ERR, "header not a request");
return -EINVAL;
}
if (hdr->msg_size < sizeof hdr) {
- vfu_log(vfu_ctx, VFU_ERR, "bad size in header %d", hdr->msg_size);
+ vfu_log(vfu_ctx, LOG_ERR, "bad size in header %d", hdr->msg_size);
return -EINVAL;
}
@@ -842,7 +842,7 @@ get_next_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, int *fds,
return 0;
}
if (ret != -EINTR) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to receive request: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to receive request: %s",
strerror(-ret));
}
return ret;
@@ -852,9 +852,9 @@ get_next_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, int *fds,
return -EINTR;
}
if (errno == 0) {
- vfu_log(vfu_ctx, VFU_INF, "vfio-user client closed connection");
+ vfu_log(vfu_ctx, LOG_INFO, "vfio-user client closed connection");
} else {
- vfu_log(vfu_ctx, VFU_ERR, "end of file: %m");
+ vfu_log(vfu_ctx, LOG_ERR, "end of file: %m");
}
return -ENOTCONN;
}
@@ -906,7 +906,7 @@ exec_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size,
goto reply;
}
if (ret != (int)hdr->msg_size) {
- vfu_log(vfu_ctx, VFU_ERR, "short read, expected=%d, actual=%d",
+ vfu_log(vfu_ctx, LOG_ERR, "short read, expected=%d, actual=%d",
hdr->msg_size, ret);
ret = -EINVAL;
goto reply;
@@ -915,7 +915,7 @@ exec_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size,
if (device_is_stopped_and_copying(vfu_ctx->migration)
&& !(hdr->cmd == VFIO_USER_REGION_READ || hdr->cmd == VFIO_USER_REGION_WRITE)) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"bad command %d while device in stop-and-copy state", hdr->cmd);
ret = -EINVAL;
goto reply;
@@ -982,7 +982,7 @@ exec_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size,
}
break;
default:
- vfu_log(vfu_ctx, VFU_ERR, "bad command %d", hdr->cmd);
+ vfu_log(vfu_ctx, LOG_ERR, "bad command %d", hdr->cmd);
ret = -EINVAL;
goto reply;
}
@@ -1033,7 +1033,7 @@ process_request(vfu_ctx_t *vfu_ctx)
for (i = 0; i < nr_fds; i++) {
if (fds[i] != -1) {
- vfu_log(vfu_ctx, VFU_INF, "closing fd=%d", fds[i]);
+ vfu_log(vfu_ctx, LOG_INFO, "closing fd=%d", fds[i]);
close(fds[i]);
}
}
@@ -1044,7 +1044,7 @@ process_request(vfu_ctx_t *vfu_ctx)
*/
if (ret < 0) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to handle command %d: %s", hdr.cmd,
+ vfu_log(vfu_ctx, LOG_ERR, "failed to handle command %d: %s", hdr.cmd,
strerror(-ret));
} else {
ret = 0;
@@ -1054,7 +1054,7 @@ process_request(vfu_ctx_t *vfu_ctx)
ret = vfu_send_iovec(vfu_ctx->conn_fd, hdr.msg_id, true,
0, iovecs, nr_iovecs, NULL, 0, -ret);
if (unlikely(ret < 0)) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to complete command: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to complete command: %s",
strerror(-ret));
}
if (iovecs != NULL && iovecs != _iovecs) {
@@ -1092,7 +1092,7 @@ prepare_ctx(vfu_ctx_t *vfu_ctx)
if (vfu_ctx->conn_fd < 0) {
err = vfu_ctx->conn_fd;
if (err != EINTR) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to attach: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to attach: %s",
strerror(-err));
}
return err;
@@ -1210,7 +1210,7 @@ vfu_mmap(vfu_ctx_t *vfu_ctx, off_t offset, size_t length)
{
if ((vfu_ctx == NULL) || (length == 0) || !PAGE_ALIGNED(offset)) {
if (vfu_ctx != NULL) {
- vfu_log(vfu_ctx, VFU_DBG, "bad device mmap region %#lx-%#lx\n",
+ vfu_log(vfu_ctx, LOG_DEBUG, "bad device mmap region %#lx-%#lx\n",
offset, offset + length);
}
errno = EINVAL;
@@ -1311,7 +1311,7 @@ vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt,
// Set other context data.
vfu_ctx->pvt = pvt;
vfu_ctx->flags = flags;
- vfu_ctx->log_lvl = VFU_ERR;
+ vfu_ctx->log_level = LOG_ERR;
vfu_ctx->uuid = strdup(path);
if (vfu_ctx->uuid == NULL) {
@@ -1353,15 +1353,15 @@ out:
}
int
-vfu_setup_log(vfu_ctx_t *vfu_ctx, vfu_log_fn_t *log, vfu_log_lvl_t log_lvl)
+vfu_setup_log(vfu_ctx_t *vfu_ctx, vfu_log_fn_t *log, int log_level)
{
- if (log_lvl != VFU_ERR && log_lvl != VFU_INF && log_lvl != VFU_DBG) {
+ if (log_level != LOG_ERR && log_level != LOG_INFO && log_level != LOG_DEBUG) {
return ERROR(EINVAL);
}
vfu_ctx->log = log;
- vfu_ctx->log_lvl = log_lvl;
+ vfu_ctx->log_level = log_level;
return 0;
}
@@ -1382,7 +1382,7 @@ vfu_pci_setup_config_hdr(vfu_ctx_t *vfu_ctx, vfu_pci_hdr_id_t id,
* clean up and redo it.
*/
if (vfu_ctx->pci_config_space != NULL) {
- vfu_log(vfu_ctx, VFU_ERR, "PCI configuration space header already setup");
+ vfu_log(vfu_ctx, LOG_ERR, "PCI configuration space header already setup");
return ERROR(EEXIST);
}
@@ -1396,7 +1396,7 @@ vfu_pci_setup_config_hdr(vfu_ctx_t *vfu_ctx, vfu_pci_hdr_id_t id,
size = PCI_CFG_SPACE_EXP_SIZE;
break;
default:
- vfu_log(vfu_ctx, VFU_ERR, "invalid PCI type %d", pci_type);
+ vfu_log(vfu_ctx, LOG_ERR, "invalid PCI type %d", pci_type);
return ERROR(EINVAL);
}
@@ -1423,18 +1423,18 @@ vfu_pci_setup_caps(vfu_ctx_t *vfu_ctx, vfu_cap_t **caps, int nr_caps)
assert(vfu_ctx != NULL);
if (vfu_ctx->caps != NULL) {
- vfu_log(vfu_ctx, VFU_ERR, "capabilities are already setup");
+ vfu_log(vfu_ctx, LOG_ERR, "capabilities are already setup");
return ERROR(EEXIST);
}
if (caps == NULL || nr_caps == 0) {
- vfu_log(vfu_ctx, VFU_ERR, "Invalid args passed");
+ vfu_log(vfu_ctx, LOG_ERR, "Invalid args passed");
return ERROR(EINVAL);
}
vfu_ctx->caps = caps_create(vfu_ctx, caps, nr_caps, &ret);
if (vfu_ctx->caps == NULL) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to create PCI capabilities: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to create PCI capabilities: %s",
strerror(ret));
return ERROR(ret);
}
@@ -1501,7 +1501,7 @@ vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size,
}
break;
default:
- vfu_log(vfu_ctx, VFU_ERR, "Invalid region index %d", region_idx);
+ vfu_log(vfu_ctx, LOG_ERR, "Invalid region index %d", region_idx);
return ERROR(EINVAL);
}
@@ -1547,7 +1547,7 @@ vfu_setup_device_nr_irqs(vfu_ctx_t *vfu_ctx, enum vfu_dev_irq_type type,
assert(vfu_ctx != NULL);
if (type < VFU_DEV_INTX_IRQ || type > VFU_DEV_REQ_IRQ) {
- vfu_log(vfu_ctx, VFU_ERR, "Invalid IRQ index %d, should be between "
+ vfu_log(vfu_ctx, LOG_ERR, "Invalid IRQ index %d, should be between "
"(%d to %d)", type, VFU_DEV_INTX_IRQ,
VFU_DEV_REQ_IRQ);
return ERROR(EINVAL);
@@ -1569,7 +1569,7 @@ vfu_setup_device_migration(vfu_ctx_t *vfu_ctx, vfu_migration_t *migration)
//FIXME: Validate args.
if (vfu_ctx->migr_reg != NULL) {
- vfu_log(vfu_ctx, VFU_ERR, "device migration is already setup");
+ vfu_log(vfu_ctx, LOG_ERR, "device migration is already setup");
return ERROR(EEXIST);
}
@@ -1588,7 +1588,7 @@ vfu_setup_device_migration(vfu_ctx_t *vfu_ctx, vfu_migration_t *migration)
vfu_ctx->migration = init_migration(migration, &ret);
if (vfu_ctx->migration == NULL) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to initialize device migration");
+ vfu_log(vfu_ctx, LOG_ERR, "failed to initialize device migration");
free(migr_reg->mmap_areas);
return ERROR(ret);
}
diff --git a/lib/migration.c b/lib/migration.c
index 2c99c3a..a33722a 100644
--- a/lib/migration.c
+++ b/lib/migration.c
@@ -138,14 +138,14 @@ handle_device_state(vfu_ctx_t *vfu_ctx, void *pvt,
}
if (*device_state & ~VFIO_DEVICE_STATE_MASK) {
- vfu_log(vfu_ctx, VFU_ERR, "bad device state %#x", *device_state);
+ vfu_log(vfu_ctx, LOG_ERR, "bad device state %#x", *device_state);
return -EINVAL;
}
if (!_migr_state_transition_is_valid(migr->info.device_state,
*device_state)) {
/* TODO print descriptive device state names instead of raw value */
- vfu_log(vfu_ctx, VFU_ERR, "bad transition from state %d to state %d",
+ vfu_log(vfu_ctx, LOG_ERR, "bad transition from state %d to state %d",
migr->info.device_state, *device_state);
return -EINVAL;
}
@@ -179,7 +179,7 @@ handle_device_state(vfu_ctx_t *vfu_ctx, void *pvt,
if (ret == 0) {
migr->info.device_state = *device_state;
} else if (ret < 0) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to transition to state %d: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to transition to state %d: %s",
*device_state, strerror(-ret));
}
@@ -249,7 +249,7 @@ handle_data_offset_when_saving(vfu_ctx_t *vfu_ctx, void *pvt,
assert(migr != NULL);
if (is_write) {
- vfu_log(vfu_ctx, VFU_ERR, "data_offset is RO when saving");
+ vfu_log(vfu_ctx, LOG_ERR, "data_offset is RO when saving");
return -EINVAL;
}
@@ -267,7 +267,7 @@ handle_data_offset_when_saving(vfu_ctx_t *vfu_ctx, void *pvt,
*/
break;
default:
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"reading data_offset out of sequence is undefined");
return -EINVAL;
}
@@ -291,7 +291,7 @@ handle_data_offset(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
break;
case VFIO_DEVICE_STATE_RESUMING:
if (is_write) {
- vfu_log(vfu_ctx, VFU_ERR, "bad write to migration data_offset");
+ vfu_log(vfu_ctx, LOG_ERR, "bad write to migration data_offset");
ret = -EINVAL;
} else {
ret = 0;
@@ -299,7 +299,7 @@ handle_data_offset(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
break;
default:
/* TODO improve error message */
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"bad access to migration data_offset in state %d",
migr->info.device_state);
ret = -EINVAL;
@@ -320,13 +320,13 @@ handle_data_size_when_saving(vfu_ctx_t *vfu_ctx, struct migration *migr,
if (is_write) {
/* TODO improve error message */
- vfu_log(vfu_ctx, VFU_ERR, "data_size is RO when saving");
+ vfu_log(vfu_ctx, LOG_ERR, "data_size is RO when saving");
return -EINVAL;
}
if (migr->iter.state != VFIO_USER_MIGR_ITER_STATE_STARTED &&
migr->iter.state != VFIO_USER_MIGR_ITER_STATE_DATA_PREPARED) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"reading data_size ouf of sequence is undefined");
return -EINVAL;
}
@@ -368,7 +368,7 @@ handle_data_size(vfu_ctx_t *vfu_ctx, void *pvt, struct migration *migr,
break;
default:
/* TODO improve error message */
- vfu_log(vfu_ctx, VFU_ERR, "bad access to data_size");
+ vfu_log(vfu_ctx, LOG_ERR, "bad access to data_size");
ret = -EINVAL;
}
@@ -391,7 +391,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
switch (pos) {
case offsetof(struct vfio_device_migration_info, device_state):
if (count != sizeof(migr->info.device_state)) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"bad device_state access size %ld", count);
return -EINVAL;
}
@@ -399,7 +399,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
break;
case offsetof(struct vfio_device_migration_info, pending_bytes):
if (count != sizeof(migr->info.pending_bytes)) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"bad pending_bytes access size %ld", count);
return -EINVAL;
}
@@ -407,7 +407,7 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
break;
case offsetof(struct vfio_device_migration_info, data_offset):
if (count != sizeof(migr->info.data_offset)) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"bad data_offset access size %ld", count);
return -EINVAL;
}
@@ -415,14 +415,14 @@ handle_region_access_registers(vfu_ctx_t *vfu_ctx, void *pvt,
break;
case offsetof(struct vfio_device_migration_info, data_size):
if (count != sizeof(migr->info.data_size)) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"bad data_size access size %ld", count);
return -EINVAL;
}
ret = handle_data_size(vfu_ctx, pvt, migr, (__u64*)buf, is_write);
break;
default:
- vfu_log(vfu_ctx, VFU_ERR, "bad migration region register offset %#lx",
+ vfu_log(vfu_ctx, LOG_ERR, "bad migration region register offset %#lx",
pos);
return -EINVAL;
}
diff --git a/lib/pci.c b/lib/pci.c
index 0a944e3..b4cffb1 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -62,7 +62,7 @@ vfu_pci_hdr_write_bar(vfu_ctx_t *vfu_ctx, uint16_t bar_index, const char *buf)
cfg_addr = *(uint32_t *) buf;
- vfu_log(vfu_ctx, VFU_DBG, "BAR%d addr 0x%x\n", bar_index, cfg_addr);
+ vfu_log(vfu_ctx, LOG_DEBUG, "BAR%d addr 0x%x\n", bar_index, cfg_addr);
if (cfg_addr == 0xffffffff) {
cfg_addr = ~(reg_info[bar_index].size) + 1;
@@ -89,7 +89,7 @@ handle_command_write(vfu_ctx_t *ctx, vfu_pci_config_space_t *pci,
assert(ctx != NULL);
if (count != 2) {
- vfu_log(ctx, VFU_ERR, "bad write command size %lu\n", count);
+ vfu_log(ctx, LOG_ERR, "bad write command size %lu\n", count);
return -EINVAL;
}
@@ -101,88 +101,88 @@ handle_command_write(vfu_ctx_t *ctx, vfu_pci_config_space_t *pci,
if ((v & PCI_COMMAND_IO) == PCI_COMMAND_IO) {
if (!pci->hdr.cmd.iose) {
pci->hdr.cmd.iose = 0x1;
- vfu_log(ctx, VFU_INF, "I/O space enabled\n");
+ vfu_log(ctx, LOG_INFO, "I/O space enabled\n");
}
v &= ~PCI_COMMAND_IO;
} else {
if (pci->hdr.cmd.iose) {
pci->hdr.cmd.iose = 0x0;
- vfu_log(ctx, VFU_INF, "I/O space disabled\n");
+ vfu_log(ctx, LOG_INFO, "I/O space disabled\n");
}
}
if ((v & PCI_COMMAND_MEMORY) == PCI_COMMAND_MEMORY) {
if (!pci->hdr.cmd.mse) {
pci->hdr.cmd.mse = 0x1;
- vfu_log(ctx, VFU_INF, "memory space enabled\n");
+ vfu_log(ctx, LOG_INFO, "memory space enabled\n");
}
v &= ~PCI_COMMAND_MEMORY;
} else {
if (pci->hdr.cmd.mse) {
pci->hdr.cmd.mse = 0x0;
- vfu_log(ctx, VFU_INF, "memory space disabled\n");
+ vfu_log(ctx, LOG_INFO, "memory space disabled\n");
}
}
if ((v & PCI_COMMAND_MASTER) == PCI_COMMAND_MASTER) {
if (!pci->hdr.cmd.bme) {
pci->hdr.cmd.bme = 0x1;
- vfu_log(ctx, VFU_INF, "bus master enabled\n");
+ vfu_log(ctx, LOG_INFO, "bus master enabled\n");
}
v &= ~PCI_COMMAND_MASTER;
} else {
if (pci->hdr.cmd.bme) {
pci->hdr.cmd.bme = 0x0;
- vfu_log(ctx, VFU_INF, "bus master disabled\n");
+ vfu_log(ctx, LOG_INFO, "bus master disabled\n");
}
}
if ((v & PCI_COMMAND_SERR) == PCI_COMMAND_SERR) {
if (!pci->hdr.cmd.see) {
pci->hdr.cmd.see = 0x1;
- vfu_log(ctx, VFU_INF, "SERR# enabled\n");
+ vfu_log(ctx, LOG_INFO, "SERR# enabled\n");
}
v &= ~PCI_COMMAND_SERR;
} else {
if (pci->hdr.cmd.see) {
pci->hdr.cmd.see = 0x0;
- vfu_log(ctx, VFU_INF, "SERR# disabled\n");
+ vfu_log(ctx, LOG_INFO, "SERR# disabled\n");
}
}
if ((v & PCI_COMMAND_INTX_DISABLE) == PCI_COMMAND_INTX_DISABLE) {
if (!pci->hdr.cmd.id) {
pci->hdr.cmd.id = 0x1;
- vfu_log(ctx, VFU_INF, "INTx emulation disabled\n");
+ vfu_log(ctx, LOG_INFO, "INTx emulation disabled\n");
}
v &= ~PCI_COMMAND_INTX_DISABLE;
} else {
if (pci->hdr.cmd.id) {
pci->hdr.cmd.id = 0x0;
- vfu_log(ctx, VFU_INF, "INTx emulation enabled\n");
+ vfu_log(ctx, LOG_INFO, "INTx emulation enabled\n");
}
}
if ((v & PCI_COMMAND_INVALIDATE) == PCI_COMMAND_INVALIDATE) {
if (!pci->hdr.cmd.mwie) {
pci->hdr.cmd.mwie = 1U;
- vfu_log(ctx, VFU_INF, "memory write and invalidate enabled\n");
+ vfu_log(ctx, LOG_INFO, "memory write and invalidate enabled\n");
}
v &= ~PCI_COMMAND_INVALIDATE;
} else {
if (pci->hdr.cmd.mwie) {
pci->hdr.cmd.mwie = 0;
- vfu_log(ctx, VFU_INF, "memory write and invalidate disabled");
+ vfu_log(ctx, LOG_INFO, "memory write and invalidate disabled");
}
}
if ((v & PCI_COMMAND_VGA_PALETTE) == PCI_COMMAND_VGA_PALETTE) {
- vfu_log(ctx, VFU_INF, "enabling VGA palette snooping ignored\n");
+ vfu_log(ctx, LOG_INFO, "enabling VGA palette snooping ignored\n");
v &= ~PCI_COMMAND_VGA_PALETTE;
}
if (v != 0) {
- vfu_log(ctx, VFU_ERR, "unconsumed command flags %x\n", v);
+ vfu_log(ctx, LOG_ERR, "unconsumed command flags %x\n", v);
return -EINVAL;
}
@@ -199,20 +199,20 @@ handle_erom_write(vfu_ctx_t *ctx, vfu_pci_config_space_t *pci,
assert(pci != NULL);
if (count != 0x4) {
- vfu_log(ctx, VFU_ERR, "bad EROM count %lu\n", count);
+ vfu_log(ctx, LOG_ERR, "bad EROM count %lu\n", count);
return -EINVAL;
}
v = *(uint32_t*)buf;
if (v == (uint32_t)PCI_ROM_ADDRESS_MASK) {
- vfu_log(ctx, VFU_INF, "write mask to EROM ignored\n");
+ vfu_log(ctx, LOG_INFO, "write mask to EROM ignored\n");
} else if (v == 0) {
- vfu_log(ctx, VFU_INF, "cleared EROM\n");
+ vfu_log(ctx, LOG_INFO, "cleared EROM\n");
pci->hdr.erom = 0;
} else if (v == (uint32_t)~PCI_ROM_ADDRESS_ENABLE) {
- vfu_log(ctx, VFU_INF, "EROM disable ignored\n");
+ vfu_log(ctx, LOG_INFO, "EROM disable ignored\n");
} else {
- vfu_log(ctx, VFU_ERR, "bad write to EROM 0x%x bytes\n", v);
+ vfu_log(ctx, LOG_ERR, "bad write to EROM 0x%x bytes\n", v);
return -EINVAL;
}
return 0;
@@ -235,19 +235,19 @@ vfu_pci_hdr_write(vfu_ctx_t *vfu_ctx, uint16_t offset,
ret = handle_command_write(vfu_ctx, pci, buf, count);
break;
case PCI_STATUS:
- vfu_log(vfu_ctx, VFU_INF, "write to status ignored\n");
+ vfu_log(vfu_ctx, LOG_INFO, "write to status ignored\n");
break;
case PCI_INTERRUPT_PIN:
- vfu_log(vfu_ctx, VFU_ERR, "attempt to write read-only field IPIN\n");
+ vfu_log(vfu_ctx, LOG_ERR, "attempt to write read-only field IPIN\n");
ret = -EINVAL;
break;
case PCI_INTERRUPT_LINE:
pci->hdr.intr.iline = buf[0];
- vfu_log(vfu_ctx, VFU_DBG, "ILINE=%0x\n", pci->hdr.intr.iline);
+ vfu_log(vfu_ctx, LOG_DEBUG, "ILINE=%0x\n", pci->hdr.intr.iline);
break;
case PCI_LATENCY_TIMER:
pci->hdr.mlt = (uint8_t)buf[0];
- vfu_log(vfu_ctx, VFU_INF, "set to latency timer to %hhx\n", pci->hdr.mlt);
+ vfu_log(vfu_ctx, LOG_INFO, "set to latency timer to %hhx\n", pci->hdr.mlt);
break;
case PCI_BASE_ADDRESS_0:
case PCI_BASE_ADDRESS_1:
@@ -261,7 +261,7 @@ vfu_pci_hdr_write(vfu_ctx_t *vfu_ctx, uint16_t offset,
ret = handle_erom_write(vfu_ctx, pci, buf, count);
break;
default:
- vfu_log(vfu_ctx, VFU_INF, "PCI config write %#x-%#lx not handled\n",
+ vfu_log(vfu_ctx, LOG_INFO, "PCI config write %#x-%#lx not handled\n",
offset, offset + count);
ret = -EINVAL;
}
diff --git a/lib/private.h b/lib/private.h
index 2f51594..dfe8b85 100644
--- a/lib/private.h
+++ b/lib/private.h
@@ -105,7 +105,7 @@ struct vfu_ctx {
int fd;
int conn_fd;
vfu_reset_cb_t *reset;
- vfu_log_lvl_t log_lvl;
+ int log_level;
vfu_log_fn_t *log;
size_t nr_regions;
vfu_reg_info_t *reg_info;
diff --git a/lib/python_bindings.c b/lib/python_bindings.c
index 87abc78..a1d6212 100644
--- a/lib/python_bindings.c
+++ b/lib/python_bindings.c
@@ -129,7 +129,7 @@ struct _region_info {
static const struct _region_info _0_ri;
static PyObject *log_fn;
-static vfu_log_lvl_t log_lvl = VFU_ERR;
+static int log_level = LOG_ERR;
static void
_log_fn(void *pvt, const char *msg)
@@ -148,7 +148,7 @@ _log_fn(void *pvt, const char *msg)
static PyObject *
libvfio_user_run(PyObject *self, PyObject *args, PyObject *kwargs)
{
- static char *kwlist[] = {"vid", "did", "uuid", "log", "log_lvl",
+ static char *kwlist[] = {"vid", "did", "uuid", "log", "log_level",
"bar0", "bar1", "bar2", "bar3", "bar4", "bar5", "rom", "cfg", "vga",
"intx", "msi", "msix", "err", "req",
NULL};
@@ -166,7 +166,7 @@ libvfio_user_run(PyObject *self, PyObject *args, PyObject *kwargs)
&dev_info.pci_info.id.did,
&dev_info.uuid,
&log_fn,
- &log_lvl,
+ &log_level,
&_ri[0].perm, &_ri[0].size, &_ri[0].fn,
&_ri[1].perm, &_ri[1].size, &_ri[1].fn,
&_ri[2].perm, &_ri[2].size, &_ri[2].fn,
@@ -216,7 +216,7 @@ libvfio_user_run(PyObject *self, PyObject *args, PyObject *kwargs)
return NULL;
}
dev_info.log = _log_fn;
- dev_info.log_lvl = log_lvl;
+ dev_info.log_level = log_level;
}
err = vfu_ctx_run(&dev_info);
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index 7649244..a7d6505 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -462,27 +462,27 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
(void **)&cversion, &vlen);
if (ret < 0) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to receive version: %s",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to receive version: %s",
strerror(-ret));
return ret;
}
if (hdr.cmd != VFIO_USER_VERSION) {
- vfu_log(vfu_ctx, VFU_ERR, "msg%hx: invalid cmd %hu (expected %hu)",
+ vfu_log(vfu_ctx, LOG_ERR, "msg%hx: invalid cmd %hu (expected %hu)",
*msg_idp, hdr.cmd, VFIO_USER_VERSION);
ret = -EINVAL;
goto out;
}
if (vlen < sizeof (*cversion)) {
- vfu_log(vfu_ctx, VFU_ERR,
+ vfu_log(vfu_ctx, LOG_ERR,
"msg%hx (VFIO_USER_VERSION): invalid size %lu", *msg_idp, vlen);
ret = -EINVAL;
goto out;
}
if (cversion->major != LIB_VFIO_USER_MAJOR) {
- vfu_log(vfu_ctx, VFU_ERR, "unsupported client major %hu (must be %hu)",
+ vfu_log(vfu_ctx, LOG_ERR, "unsupported client major %hu (must be %hu)",
cversion->major, LIB_VFIO_USER_MAJOR);
ret = -ENOTSUP;
goto out;
@@ -496,7 +496,7 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
size_t pgsize = 0;
if (json_str[len - 1] != '\0') {
- vfu_log(vfu_ctx, VFU_ERR, "ignoring invalid JSON from client");
+ vfu_log(vfu_ctx, LOG_ERR, "ignoring invalid JSON from client");
ret = -EINVAL;
goto out;
}
@@ -507,10 +507,10 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
if (ret < 0) {
/* No client-supplied strings in the log for release build. */
#ifdef DEBUG
- vfu_log(vfu_ctx, VFU_ERR, "failed to parse client JSON \"%s\"",
+ vfu_log(vfu_ctx, LOG_ERR, "failed to parse client JSON \"%s\"",
json_str);
#else
- vfu_log(vfu_ctx, VFU_ERR, "failed to parse client JSON");
+ vfu_log(vfu_ctx, LOG_ERR, "failed to parse client JSON");
#endif
goto out;
}
@@ -519,7 +519,7 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
ret = migration_set_pgsize(vfu_ctx->migration, pgsize);
if (ret != 0) {
- vfu_log(vfu_ctx, VFU_ERR, "refusing client page size of %zu",
+ vfu_log(vfu_ctx, LOG_ERR, "refusing client page size of %zu",
pgsize);
goto out;
}
@@ -528,7 +528,7 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
// FIXME: is the code resilient against ->client_max_fds == 0?
if (vfu_ctx->client_max_fds < 0 ||
vfu_ctx->client_max_fds > VFIO_USER_CLIENT_MAX_FDS_LIMIT) {
- vfu_log(vfu_ctx, VFU_ERR, "refusing client max_fds of %d",
+ vfu_log(vfu_ctx, LOG_ERR, "refusing client max_fds of %d",
vfu_ctx->client_max_fds);
ret = -EINVAL;
goto out;
@@ -601,7 +601,7 @@ negotiate(vfu_ctx_t *vfu_ctx, int sock)
ret = recv_version(vfu_ctx, sock, &msg_id, &client_version);
if (ret < 0) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to recv version: %s", strerror(-ret));
+ vfu_log(vfu_ctx, LOG_ERR, "failed to recv version: %s", strerror(-ret));
return ret;
}
@@ -610,7 +610,7 @@ negotiate(vfu_ctx_t *vfu_ctx, int sock)
free(client_version);
if (ret < 0) {
- vfu_log(vfu_ctx, VFU_ERR, "failed to send version: %s", strerror(-ret));
+ vfu_log(vfu_ctx, LOG_ERR, "failed to send version: %s", strerror(-ret));
}
return ret;
diff --git a/samples/client.c b/samples/client.c
index 7002582..99289cb 100644
--- a/samples/client.c
+++ b/samples/client.c
@@ -58,7 +58,7 @@ static char *irq_to_str[] = {
};
void
-vfu_log(UNUSED vfu_ctx_t *vfu_ctx, UNUSED vfu_log_lvl_t lvl,
+vfu_log(UNUSED vfu_ctx_t *vfu_ctx, UNUSED int level,
const char *fmt, ...)
{
va_list ap;
diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c
index be8ecdb..149bb59 100644
--- a/samples/gpio-pci-idio-16.c
+++ b/samples/gpio-pci-idio-16.c
@@ -46,7 +46,7 @@
#include "tran_sock.h"
static void
-_log(UNUSED void *pvt, UNUSED vfu_log_lvl_t lvl, char const *msg)
+_log(UNUSED void *pvt, UNUSED int level, char const *msg)
{
fprintf(stderr, "gpio: %s\n", msg);
}
@@ -109,7 +109,7 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "failed to initialize device emulation");
}
- ret = vfu_setup_log(vfu_ctx, _log, verbose ? VFU_DBG : VFU_ERR);
+ ret = vfu_setup_log(vfu_ctx, _log, verbose ? LOG_DEBUG : LOG_ERR);
if (ret < 0) {
err(EXIT_FAILURE, "failed to setup log");
}
diff --git a/samples/null.c b/samples/null.c
index adf3a46..fda260e 100644
--- a/samples/null.c
+++ b/samples/null.c
@@ -43,7 +43,7 @@
#include "tran_sock.h"
static void
-null_log(UNUSED void *pvt, UNUSED vfu_log_lvl_t lvl, char const *msg)
+null_log(UNUSED void *pvt, UNUSED int level, char const *msg)
{
fprintf(stderr, "null: %s", msg);
}
@@ -86,7 +86,7 @@ int main(int argc, char **argv)
err(EXIT_FAILURE, "failed to create libvfio-user context");
}
- ret = vfu_setup_log(vfu_ctx, null_log, VFU_DBG);
+ ret = vfu_setup_log(vfu_ctx, null_log, LOG_DEBUG);
if (ret < 0) {
err(EXIT_FAILURE, "failed to setup log");
}
diff --git a/samples/server.c b/samples/server.c
index ccfad1c..aeb9e69 100644
--- a/samples/server.c
+++ b/samples/server.c
@@ -70,7 +70,7 @@ struct server_data {
};
static void
-_log(UNUSED void *pvt, UNUSED vfu_log_lvl_t lvl, char const *msg)
+_log(UNUSED void *pvt, UNUSED int level, char const *msg)
{
fprintf(stderr, "server: %s\n", msg);
}
@@ -79,10 +79,10 @@ static int
arm_timer(struct server_data *server_data, time_t t)
{
struct itimerval new = {.it_value.tv_sec = t - time(NULL) };
- vfu_log(server_data->vfu_ctx, VFU_DBG,
+ vfu_log(server_data->vfu_ctx, LOG_DEBUG,
"arming timer to trigger in %ld seconds", new.it_value.tv_sec);
if (setitimer(ITIMER_REAL, &new, NULL) != 0) {
- vfu_log(server_data->vfu_ctx, VFU_ERR, "failed to arm timer: %m");
+ vfu_log(server_data->vfu_ctx, LOG_ERR, "failed to arm timer: %m");
return -errno;
}
return 0;
@@ -95,7 +95,7 @@ bar0_access(void *pvt, char * const buf, size_t count, loff_t offset,
struct server_data *server_data = pvt;
if (count != sizeof(time_t) || offset != 0) {
- vfu_log(server_data->vfu_ctx, VFU_ERR, "bad BAR0 access %#lx-%#lx",
+ vfu_log(server_data->vfu_ctx, LOG_ERR, "bad BAR0 access %#lx-%#lx",
offset, offset + count - 1);
errno = EINVAL;
return -1;
@@ -303,7 +303,7 @@ migration_read_data(void *pvt, void *buf, __u64 size, __u64 offset)
struct server_data *server_data = pvt;
if (server_data->migration.data_size < size) {
- vfu_log(server_data->vfu_ctx, VFU_ERR,
+ vfu_log(server_data->vfu_ctx, LOG_ERR,
"invalid migration data read %#llx-%#llx",
offset, offset + size - 1);
return -EINVAL;
@@ -328,7 +328,7 @@ migration_write_data(void *pvt, void *data, __u64 size, __u64 offset)
assert(data != NULL);
if (offset + size > server_data->migration.migr_data_len) {
- vfu_log(server_data->vfu_ctx, VFU_ERR,
+ vfu_log(server_data->vfu_ctx, LOG_ERR,
"invalid write %#llx-%#llx", offset, offset + size - 1);
}
@@ -347,7 +347,7 @@ migration_data_written(void *pvt, __u64 count, __u64 offset)
assert(server_data != NULL);
if (offset + count > server_data->migration.migr_data_len) {
- vfu_log(server_data->vfu_ctx, VFU_ERR,
+ vfu_log(server_data->vfu_ctx, LOG_ERR,
"bad migration data range %#llx-%#llx",
offset, offset + count - 1);
return -EINVAL;
@@ -417,7 +417,7 @@ int main(int argc, char *argv[])
err(EXIT_FAILURE, "failed to initialize device emulation\n");
}
- ret = vfu_setup_log(vfu_ctx, _log, verbose ? VFU_DBG : VFU_ERR);
+ ret = vfu_setup_log(vfu_ctx, _log, verbose ? LOG_DEBUG : LOG_ERR);
if (ret < 0) {
err(EXIT_FAILURE, "failed to setup log");
}