Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/bhyve/pci_virtio_block.c
Show First 20 Lines • Show All 447 Lines • ▼ Show 20 Lines | vi_interrupt(&sc->vbsc_vs, VIRTIO_PCI_ISR_CONFIG, | ||||
sc->vbsc_vs.vs_msix_cfg_idx); | sc->vbsc_vs.vs_msix_cfg_idx); | ||||
} | } | ||||
static int | static int | ||||
pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) | pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) | ||||
{ | { | ||||
char bident[sizeof("XX:X:X")]; | char bident[sizeof("XX:X:X")]; | ||||
struct blockif_ctxt *bctxt; | struct blockif_ctxt *bctxt; | ||||
const char *path; | const char *path, *serial; | ||||
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; | ||||
/* | /* | ||||
* The supplied backing file has to exist | * The supplied backing file has to exist | ||||
Show All 28 Lines | pci_vtblk_init(struct vmctx *ctx, struct pci_devinst *pi, nvlist_t *nvl) | ||||
/* init virtio softc and virtqueues */ | /* init virtio softc and virtqueues */ | ||||
vi_softc_linkup(&sc->vbsc_vs, &sc->vbsc_consts, sc, pi, &sc->vbsc_vq); | vi_softc_linkup(&sc->vbsc_vs, &sc->vbsc_consts, sc, pi, &sc->vbsc_vq); | ||||
sc->vbsc_vs.vs_mtx = &sc->vsc_mtx; | sc->vbsc_vs.vs_mtx = &sc->vsc_mtx; | ||||
sc->vbsc_vq.vq_qsize = VTBLK_RINGSZ; | sc->vbsc_vq.vq_qsize = VTBLK_RINGSZ; | ||||
/* sc->vbsc_vq.vq_notify = we have no per-queue notify */ | /* sc->vbsc_vq.vq_notify = we have no per-queue notify */ | ||||
/* | /* | ||||
* Create an identifier for the backing file. Use parts of the | * If an explicit identifier is not given, create an | ||||
* md5 sum of the filename | * identifier using parts of the md5 sum of the filename. | ||||
*/ | */ | ||||
bzero(sc->vbsc_ident, VTBLK_BLK_ID_BYTES); | |||||
if ((serial = get_config_value_node(nvl, "serial")) != NULL || | |||||
(serial = get_config_value_node(nvl, "ser")) != NULL) { | |||||
strlcpy(sc->vbsc_ident, serial, VTBLK_BLK_ID_BYTES); | |||||
} else { | |||||
path = get_config_value_node(nvl, "path"); | path = get_config_value_node(nvl, "path"); | ||||
MD5Init(&mdctx); | MD5Init(&mdctx); | ||||
MD5Update(&mdctx, path, strlen(path)); | MD5Update(&mdctx, path, strlen(path)); | ||||
MD5Final(digest, &mdctx); | MD5Final(digest, &mdctx); | ||||
snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES, | snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES, | ||||
"BHYVE-%02X%02X-%02X%02X-%02X%02X", | "BHYVE-%02X%02X-%02X%02X-%02X%02X", | ||||
digest[0], digest[1], digest[2], digest[3], digest[4], digest[5]); | digest[0], digest[1], digest[2], digest[3], digest[4], | ||||
digest[5]); | |||||
} | |||||
/* setup virtio block config space */ | /* setup virtio block config space */ | ||||
sc->vbsc_cfg.vbc_capacity = size / VTBLK_BSIZE; /* 512-byte units */ | sc->vbsc_cfg.vbc_capacity = size / VTBLK_BSIZE; /* 512-byte units */ | ||||
sc->vbsc_cfg.vbc_size_max = 0; /* not negotiated */ | sc->vbsc_cfg.vbc_size_max = 0; /* not negotiated */ | ||||
/* | /* | ||||
* If Linux is presented with a seg_max greater than the virtio queue | * If Linux is presented with a seg_max greater than the virtio queue | ||||
* size, it can stumble into situations where it violates its own | * size, it can stumble into situations where it violates its own | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |