Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_block.c
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | #define VBH_FLAG_BARRIER 0x80000000 /* OR'ed into vbh_type */ | ||||
uint32_t vbh_type; | uint32_t vbh_type; | ||||
uint32_t vbh_ioprio; | uint32_t vbh_ioprio; | ||||
uint64_t vbh_sector; | uint64_t vbh_sector; | ||||
} __packed; | } __packed; | ||||
/* | /* | ||||
* Debug printf | * Debug printf | ||||
*/ | */ | ||||
static int pci_vtblk_debug; | static int pci_vtblk_debug = 0 ; | ||||
#define DPRINTF(params) if (pci_vtblk_debug) PRINTLN params | #define DPRINTF(params) if (pci_vtblk_debug) PRINTLN params | ||||
#define WPRINTF(params) PRINTLN params | #define WPRINTF(params) PRINTLN params | ||||
struct pci_vtblk_ioreq { | struct pci_vtblk_ioreq { | ||||
struct blockif_req io_req; | struct blockif_req io_req; | ||||
struct pci_vtblk_softc *io_sc; | struct pci_vtblk_softc *io_sc; | ||||
uint8_t *io_status; | uint8_t *io_status; | ||||
uint16_t io_idx; | uint16_t io_idx; | ||||
}; | }; | ||||
/* | /* | ||||
* Per-device softc | * Per-device softc | ||||
*/ | */ | ||||
struct pci_vtblk_softc { | struct pci_vtblk_softc { | ||||
struct virtio_softc vbsc_vs; | struct virtio_softc vbsc_vs; | ||||
pthread_mutex_t vsc_mtx; | pthread_mutex_t vsc_mtx; | ||||
block_backend_t *vbsc_be; | |||||
struct vqueue_info vbsc_vq; | struct vqueue_info vbsc_vq; | ||||
struct vtblk_config vbsc_cfg; | struct vtblk_config vbsc_cfg; | ||||
struct blockif_ctxt *bc; | |||||
char vbsc_ident[VTBLK_BLK_ID_BYTES]; | char vbsc_ident[VTBLK_BLK_ID_BYTES]; | ||||
freqlabs: Likewise here. | |||||
Done Inline ActionsWell, here struct blockif_ctxt *bc can go, because it is not referenced. wjw_digiware.nl: Well, here `struct blockif_ctxt *bc` can go, because it is not referenced.
But note that… | |||||
struct pci_vtblk_ioreq vbsc_ios[VTBLK_RINGSZ]; | struct pci_vtblk_ioreq vbsc_ios[VTBLK_RINGSZ]; | ||||
}; | }; | ||||
static void pci_vtblk_reset(void *); | static void pci_vtblk_reset(void *); | ||||
static void pci_vtblk_notify(void *, struct vqueue_info *); | static void pci_vtblk_notify(void *, struct vqueue_info *); | ||||
static int pci_vtblk_cfgread(void *, int, int, uint32_t *); | static int pci_vtblk_cfgread(void *, int, int, uint32_t *); | ||||
static int pci_vtblk_cfgwrite(void *, int, int, uint32_t); | static int pci_vtblk_cfgwrite(void *, int, int, uint32_t); | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | pci_vtblk_proc(struct pci_vtblk_softc *sc, struct vqueue_info *vq) | ||||
io->io_req.br_resid = iolen; | io->io_req.br_resid = iolen; | ||||
DPRINTF(("virtio-block: %s op, %zd bytes, %d segs, offset %ld", | DPRINTF(("virtio-block: %s op, %zd bytes, %d segs, offset %ld", | ||||
writeop ? "write" : "read/ident", iolen, i - 1, | writeop ? "write" : "read/ident", iolen, i - 1, | ||||
io->io_req.br_offset)); | io->io_req.br_offset)); | ||||
switch (type) { | switch (type) { | ||||
case VBH_OP_READ: | case VBH_OP_READ: | ||||
err = blockif_read(sc->bc, &io->io_req); | err = blockbe_read(sc->vbsc_be, &io->io_req); | ||||
break; | break; | ||||
case VBH_OP_WRITE: | case VBH_OP_WRITE: | ||||
err = blockif_write(sc->bc, &io->io_req); | err = blockbe_write(sc->vbsc_be, &io->io_req); | ||||
break; | break; | ||||
case VBH_OP_FLUSH: | case VBH_OP_FLUSH: | ||||
case VBH_OP_FLUSH_OUT: | case VBH_OP_FLUSH_OUT: | ||||
err = blockif_flush(sc->bc, &io->io_req); | err = blockbe_flush(sc->vbsc_be, &io->io_req); | ||||
break; | break; | ||||
case VBH_OP_IDENT: | case VBH_OP_IDENT: | ||||
/* Assume a single buffer */ | /* Assume a single buffer */ | ||||
/* S/n equal to buffer is not zero-terminated. */ | /* S/n equal to buffer is not zero-terminated. */ | ||||
memset(iov[1].iov_base, 0, iov[1].iov_len); | memset(iov[1].iov_base, 0, iov[1].iov_len); | ||||
strncpy(iov[1].iov_base, sc->vbsc_ident, | strncpy(iov[1].iov_base, sc->vbsc_ident, | ||||
MIN(iov[1].iov_len, sizeof(sc->vbsc_ident))); | MIN(iov[1].iov_len, sizeof(sc->vbsc_ident))); | ||||
pci_vtblk_done(&io->io_req, 0); | pci_vtblk_done(&io->io_req, 0); | ||||
Show All 12 Lines | pci_vtblk_notify(void *vsc, struct vqueue_info *vq) | ||||
while (vq_has_descs(vq)) | while (vq_has_descs(vq)) | ||||
pci_vtblk_proc(sc, vq); | pci_vtblk_proc(sc, vq); | ||||
} | } | ||||
static int | static int | ||||
pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | ||||
{ | { | ||||
char bident[sizeof("XX:X:X")]; | char pci_ident[sizeof("XX:X:X")]; | ||||
struct blockif_ctxt *bctxt; | char be_ident[16]; | ||||
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, res, sectsz, sts, sto; | ||||
if (opts == NULL) { | if (opts == NULL) { | ||||
WPRINTF(("virtio-block: backing device required")); | WPRINTF(("virtio-block: backing device required")); | ||||
return (1); | return (1); | ||||
} | } | ||||
sc = calloc(1, sizeof(struct pci_vtblk_softc)); | |||||
/* | /* | ||||
* The supplied backing file has to exist | * The supplied backing file has to exist | ||||
*/ | */ | ||||
snprintf(bident, sizeof(bident), "%d:%d", pi->pi_slot, pi->pi_func); | snprintf(pci_ident, sizeof(pci_ident), "%d:%d", pi->pi_slot, pi->pi_func); | ||||
bctxt = blockif_open(opts, bident); | snprintf(be_ident, sizeof(be_ident), "%s", "blk-local"); | ||||
if (bctxt == NULL) { | res = blockbe_open(&sc->vbsc_be, opts, pci_ident); | ||||
perror("Could not open backing file"); | if (res != 0) { | ||||
perror("virtio_block:_Could not open backing file"); | |||||
return (1); | return (1); | ||||
free(sc); | |||||
} | } | ||||
size = blockif_size(bctxt); | size = blockbe_size(sc->vbsc_be); | ||||
sectsz = blockif_sectsz(bctxt); | sectsz = blockbe_sectsz(sc->vbsc_be); | ||||
blockif_psectsz(bctxt, &sts, &sto); | blockbe_psectsz(sc->vbsc_be, &sts, &sto); | ||||
sc = calloc(1, sizeof(struct pci_vtblk_softc)); | |||||
sc->bc = bctxt; | |||||
for (i = 0; i < VTBLK_RINGSZ; i++) { | for (i = 0; i < VTBLK_RINGSZ; i++) { | ||||
struct pci_vtblk_ioreq *io = &sc->vbsc_ios[i]; | struct pci_vtblk_ioreq *io = &sc->vbsc_ios[i]; | ||||
io->io_req.br_callback = pci_vtblk_done; | io->io_req.br_callback = pci_vtblk_done; | ||||
io->io_req.br_param = io; | io->io_req.br_param = io; | ||||
io->io_sc = sc; | io->io_sc = sc; | ||||
io->io_idx = i; | io->io_idx = i; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, char *opts) | ||||
*/ | */ | ||||
pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_BLOCK); | pci_set_cfgdata16(pi, PCIR_DEVICE, VIRTIO_DEV_BLOCK); | ||||
pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); | pci_set_cfgdata16(pi, PCIR_VENDOR, VIRTIO_VENDOR); | ||||
pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE); | pci_set_cfgdata8(pi, PCIR_CLASS, PCIC_STORAGE); | ||||
pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_BLOCK); | pci_set_cfgdata16(pi, PCIR_SUBDEV_0, VIRTIO_TYPE_BLOCK); | ||||
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); | blockbe_close(sc->vbsc_be); | ||||
free(sc); | free(sc); | ||||
return (1); | return (1); | ||||
} | } | ||||
vi_set_io_bar(&sc->vbsc_vs, 0); | vi_set_io_bar(&sc->vbsc_vs, 0); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
Show All 26 Lines |
Likewise here.