Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_block.c
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
#include "debug.h" | #include "debug.h" | ||||
#include "pci_emul.h" | #include "pci_emul.h" | ||||
#include "virtio.h" | #include "virtio.h" | ||||
#include "block_if.h" | #include "block_if.h" | ||||
#define VTBLK_BSIZE 512 | #define VTBLK_BSIZE 512 | ||||
#define VTBLK_RINGSZ 128 | #define VTBLK_RINGSZ 128 | ||||
#ifdef BHYVE_SNAPSHOT | |||||
#include "snapshot.h" | |||||
#endif | |||||
_Static_assert(VTBLK_RINGSZ <= BLOCKIF_RING_MAX, "Each ring entry must be able to queue a request"); | _Static_assert(VTBLK_RINGSZ <= BLOCKIF_RING_MAX, "Each ring entry must be able to queue a request"); | ||||
#define VTBLK_S_OK 0 | #define VTBLK_S_OK 0 | ||||
#define VTBLK_S_IOERR 1 | #define VTBLK_S_IOERR 1 | ||||
#define VTBLK_S_UNSUPP 2 | #define VTBLK_S_UNSUPP 2 | ||||
#define VTBLK_BLK_ID_BYTES 20 + 1 | #define VTBLK_BLK_ID_BYTES 20 + 1 | ||||
▲ Show 20 Lines • Show All 366 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
char bident[sizeof("XX:X:X")]; | char bident[sizeof("XX:X:X")]; | ||||
struct blockif_ctxt *bctxt; | struct blockif_ctxt *bctxt; | ||||
MD5_CTX mdctx; | MD5_CTX mdctx; | ||||
u_char digest[16]; | u_char digest[16]; | ||||
struct pci_vtblk_softc *sc; | struct pci_vtblk_softc *sc; | ||||
off_t size; | off_t size; | ||||
int i, sectsz, sts, sto; | int i, sectsz, sts, sto; | ||||
#ifdef BHYVE_SNAPSHOT | |||||
struct vm_snapshot_dev_info *dev_info; | |||||
#endif | |||||
if (opts == NULL) { | if (opts == NULL) { | ||||
WPRINTF(("virtio-block: backing device required")); | WPRINTF(("virtio-block: backing device required")); | ||||
return (1); | return (1); | ||||
} | } | ||||
/* | /* | ||||
* The supplied backing file has to exist | * The supplied backing file has to exist | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | #endif | ||||
pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); | pci_set_cfgdata16(pi, PCIR_SUBVEND_0, VIRTIO_VENDOR); | ||||
if (vi_intr_init(&sc->vbsc_vs, 1, fbsdrun_virtio_msix())) { | if (vi_intr_init(&sc->vbsc_vs, 1, fbsdrun_virtio_msix())) { | ||||
blockif_close(sc->bc); | blockif_close(sc->bc); | ||||
free(sc); | free(sc); | ||||
return (1); | return (1); | ||||
} | } | ||||
vi_set_io_bar(&sc->vbsc_vs, 0); | vi_set_io_bar(&sc->vbsc_vs, 0); | ||||
#ifdef BHYVE_SNAPSHOT | |||||
dev_info = calloc(1, sizeof(*dev_info)); | |||||
if (!dev_info) { | |||||
fprintf(stderr, "Error allocating space for snapshot struct"); | |||||
free(sc); | |||||
return (1); | |||||
} | |||||
dev_info->dev_name = pi->pi_d->pe_emu; | |||||
dev_info->was_restored = 0; | |||||
dev_info->snapshot_cb = pci_snapshot; | |||||
dev_info->meta_data = pi; | |||||
insert_registered_devs(dev_info); | |||||
#endif | |||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
pci_vtblk_cfgwrite(void *vsc, int offset, int size, uint32_t value) | pci_vtblk_cfgwrite(void *vsc, int offset, int size, uint32_t value) | ||||
{ | { | ||||
DPRINTF(("vtblk: write to readonly reg %d", offset)); | DPRINTF(("vtblk: write to readonly reg %d", offset)); | ||||
Show All 25 Lines |