Deleted Added
full compact
pci_virtio_block.c (347436) pci_virtio_block.c (348375)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2011 NetApp, Inc.
5 * All rights reserved.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2011 NetApp, Inc.
5 * All rights reserved.
6 * Copyright (c) 2019 Joyent, Inc.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the

--- 6 unchanged lines hidden (view full) ---

20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the

--- 6 unchanged lines hidden (view full) ---

21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
28 * $FreeBSD: stable/11/usr.sbin/bhyve/pci_virtio_block.c 347436 2019-05-10 16:36:38Z jhb $
29 * $FreeBSD: stable/11/usr.sbin/bhyve/pci_virtio_block.c 348375 2019-05-29 23:11:07Z jhb $
29 */
30
31#include <sys/cdefs.h>
30 */
31
32#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: stable/11/usr.sbin/bhyve/pci_virtio_block.c 347436 2019-05-10 16:36:38Z jhb $");
33__FBSDID("$FreeBSD: stable/11/usr.sbin/bhyve/pci_virtio_block.c 348375 2019-05-29 23:11:07Z jhb $");
33
34#include <sys/param.h>
35#include <sys/linker_set.h>
36#include <sys/stat.h>
37#include <sys/uio.h>
38#include <sys/ioctl.h>
39#include <sys/disk.h>
40

--- 9 unchanged lines hidden (view full) ---

50#include <pthread.h>
51#include <md5.h>
52
53#include "bhyverun.h"
54#include "pci_emul.h"
55#include "virtio.h"
56#include "block_if.h"
57
34
35#include <sys/param.h>
36#include <sys/linker_set.h>
37#include <sys/stat.h>
38#include <sys/uio.h>
39#include <sys/ioctl.h>
40#include <sys/disk.h>
41

--- 9 unchanged lines hidden (view full) ---

51#include <pthread.h>
52#include <md5.h>
53
54#include "bhyverun.h"
55#include "pci_emul.h"
56#include "virtio.h"
57#include "block_if.h"
58
58#define VTBLK_RINGSZ 64
59#define VTBLK_RINGSZ 128
59
60
61_Static_assert(VTBLK_RINGSZ <= BLOCKIF_RING_MAX, "Each ring entry must be able to queue a request");
62
60#define VTBLK_S_OK 0
61#define VTBLK_S_IOERR 1
62#define VTBLK_S_UNSUPP 2
63
64#define VTBLK_BLK_ID_BYTES 20 + 1
65
66/* Capability bits */
67#define VTBLK_F_SEG_MAX (1 << 2) /* Maximum request segments */

--- 278 unchanged lines hidden (view full) ---

346 MD5Final(digest, &mdctx);
347 snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES,
348 "BHYVE-%02X%02X-%02X%02X-%02X%02X",
349 digest[0], digest[1], digest[2], digest[3], digest[4], digest[5]);
350
351 /* setup virtio block config space */
352 sc->vbsc_cfg.vbc_capacity = size / DEV_BSIZE; /* 512-byte units */
353 sc->vbsc_cfg.vbc_size_max = 0; /* not negotiated */
63#define VTBLK_S_OK 0
64#define VTBLK_S_IOERR 1
65#define VTBLK_S_UNSUPP 2
66
67#define VTBLK_BLK_ID_BYTES 20 + 1
68
69/* Capability bits */
70#define VTBLK_F_SEG_MAX (1 << 2) /* Maximum request segments */

--- 278 unchanged lines hidden (view full) ---

349 MD5Final(digest, &mdctx);
350 snprintf(sc->vbsc_ident, VTBLK_BLK_ID_BYTES,
351 "BHYVE-%02X%02X-%02X%02X-%02X%02X",
352 digest[0], digest[1], digest[2], digest[3], digest[4], digest[5]);
353
354 /* setup virtio block config space */
355 sc->vbsc_cfg.vbc_capacity = size / DEV_BSIZE; /* 512-byte units */
356 sc->vbsc_cfg.vbc_size_max = 0; /* not negotiated */
354 sc->vbsc_cfg.vbc_seg_max = BLOCKIF_IOV_MAX;
357
358 /*
359 * If Linux is presented with a seg_max greater than the virtio queue
360 * size, it can stumble into situations where it violates its own
361 * invariants and panics. For safety, we keep seg_max clamped, paying
362 * heed to the two extra descriptors needed for the header and status
363 * of a request.
364 */
365 sc->vbsc_cfg.vbc_seg_max = MIN(VTBLK_RINGSZ - 2, BLOCKIF_IOV_MAX);
355 sc->vbsc_cfg.vbc_geometry.cylinders = 0; /* no geometry */
356 sc->vbsc_cfg.vbc_geometry.heads = 0;
357 sc->vbsc_cfg.vbc_geometry.sectors = 0;
358 sc->vbsc_cfg.vbc_blk_size = sectsz;
359 sc->vbsc_cfg.vbc_topology.physical_block_exp =
360 (sts > sectsz) ? (ffsll(sts / sectsz) - 1) : 0;
361 sc->vbsc_cfg.vbc_topology.alignment_offset =
362 (sto != 0) ? ((sts - sto) / sectsz) : 0;

--- 51 unchanged lines hidden ---
366 sc->vbsc_cfg.vbc_geometry.cylinders = 0; /* no geometry */
367 sc->vbsc_cfg.vbc_geometry.heads = 0;
368 sc->vbsc_cfg.vbc_geometry.sectors = 0;
369 sc->vbsc_cfg.vbc_blk_size = sectsz;
370 sc->vbsc_cfg.vbc_topology.physical_block_exp =
371 (sts > sectsz) ? (ffsll(sts / sectsz) - 1) : 0;
372 sc->vbsc_cfg.vbc_topology.alignment_offset =
373 (sto != 0) ? ((sts - sto) / sectsz) : 0;

--- 51 unchanged lines hidden ---