svn commit: r334940 - head/usr.sbin/bhyve
Pedro Giffuni
pfg at FreeBSD.org
Mon Jun 11 02:44:37 UTC 2018
On 10/06/2018 21:41, Marcelo Araujo wrote:
>
>
> 2018-06-11 10:25 GMT+08:00 Pedro Giffuni <pfg at freebsd.org
> <mailto:pfg at freebsd.org>>:
>
>
>
> On 10/06/2018 21:09, Marcelo Araujo wrote:
>
> Author: araujo
> Date: Mon Jun 11 02:09:20 2018
> New Revision: 334940
> URL: https://svnweb.freebsd.org/changeset/base/334940
> <https://svnweb.freebsd.org/changeset/base/334940>
>
> Log:
> - Add bhyve virtio-scsi storage backend support.
> Example of configuration:
> ctl.conf:
> portal-group pg0 {
> discovery-auth-group no-authentication
> listen 0.0.0.0
> listen [::]
> }
> target iqn.2012-06.com.example:target0 {
> auth-group no-authentication
> portal-group pg0
> port ioctl/5/3
> lun 0 {
> path /z/test.img
> size 8G
> }
> lun 1 {
> path /z/test1.img
> size 8G
> }
> }
> bhyve <...> -s 4,virtio-scsi,/dev/cam/ctl5.3,iid=3 <VM_NAME>
> From inside guest:
> root@:~ # zpool status test
> pool: test
> state: ONLINE
> scan: none requested
> config:
> NAME STATE READ WRITE CKSUM
> test ONLINE 0 0 0
> da0 ONLINE 0 0 0
> da1 ONLINE 0 0 0
> dmesg:
> da0 at vtscsi0 bus 0 scbus0 target 0 lun 0
> da0: <FREEBSD CTLDISK 0001> Fixed Direct Access SPC-5 SCSI
> device
> da0: Serial Number MYSERIAL0000
> da0: 300.000MB/s transfers
> da0: Command Queueing enabled
> da0: 8192MB (16777216 512 byte sectors)
> da1 at vtscsi0 bus 0 scbus0 target 0 lun 1
> da1: <FREEBSD CTLDISK 0001> Fixed Direct Access SPC-5 SCSI
> device
> da1: Serial Number MYSERIAL0001
> da1: 300.000MB/s transfers
> da1: Command Queueing enabled
> da1: 8192MB (16777216 512 byte sectors)
> Discussed with: grehan
> Reviewed by: mav
> Obtained from: TrueOS
> Relnotes: Yes
> Sponsored by: iXsystems Inc.
> Tested with: FreeBSD HEAD, Fedora 28 (Workstation) and
> Ubuntu 18.04.
> Differential Revision: https://reviews.freebsd.org/D15276
> <https://reviews.freebsd.org/D15276>
>
> Added:
> head/usr.sbin/bhyve/iov.c (contents, props changed)
> head/usr.sbin/bhyve/iov.h (contents, props changed)
> head/usr.sbin/bhyve/pci_virtio_scsi.c (contents, props
> changed)
> Modified:
> head/usr.sbin/bhyve/Makefile
> head/usr.sbin/bhyve/bhyve.8
> head/usr.sbin/bhyve/virtio.h
>
> ...
>
>
> Added: head/usr.sbin/bhyve/pci_virtio_scsi.c
> ==============================================================================
> --- /dev/null 00:00:00 1970 (empty, because file is newly
> added)
> +++ head/usr.sbin/bhyve/pci_virtio_scsi.c Mon Jun 11 02:09:20
> 2018 (r334940)
> @@ -0,0 +1,718 @@
> +/*-
> + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
> + *
> + * Copyright (c) 2016 Jakub Klama <jceel at FreeBSD.org>.
> + * Copyright (c) 2018 Marcelo Araujo <araujo at FreeBSD.org>.
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or
> without
> + * modification, are permitted provided that the following
> conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above
> copyright
> + * notice, this list of conditions and the following
> disclaimer
> + * in this position and unchanged.
> + * 2. Redistributions in binary form must reproduce the above
> copyright
> + * notice, this list of conditions and the following
> disclaimer in the
> + * documentation and/or other materials provided with the
> distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS
> ``AS IS'' AND
> + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
> LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
> PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
> CONTRIBUTORS BE LIABLE
> + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
> OR CONSEQUENTIAL
> + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> SUBSTITUTE GOODS
> + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> INTERRUPTION)
> + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> CONTRACT, STRICT
> + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> ARISING IN ANY WAY
> + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include <sys/cdefs.h>
> +__FBSDID("$FreeBSD$");
> +
> +#include <sys/param.h>
> +#include <sys/linker_set.h>
> +#include <sys/types.h>
> +#include <sys/uio.h>
> +#include <sys/time.h>
> +#include <sys/queue.h>
> +#include <sys/sbuf.h>
> +
> +#include <errno.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <stdbool.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <assert.h>
> +#include <pthread.h>
> +#include <pthread_np.h>
> +
> +#include <cam/scsi/scsi_all.h>
> +#include <cam/scsi/scsi_message.h>
> +#include <cam/ctl/ctl.h>
> +#include <cam/ctl/ctl_io.h>
> +#include <cam/ctl/ctl_backend.h>
> +#include <cam/ctl/ctl_ioctl.h>
> +#include <cam/ctl/ctl_util.h>
> +#include <cam/ctl/ctl_scsi_all.h>
> +#include <camlib.h>
> +
> +#include "bhyverun.h"
> +#include "pci_emul.h"
> +#include "virtio.h"
> +#include "iov.h"
> +
> +#define VTSCSI_RINGSZ 64
> +#define VTSCSI_REQUESTQ 1
> +#define VTSCSI_THR_PER_Q 16
> +#define VTSCSI_MAXQ (VTSCSI_REQUESTQ + 2)
> +#define VTSCSI_MAXSEG 64
> +
> +#define VTSCSI_IN_HEADER_LEN(_sc) \
> + (sizeof(struct pci_vtscsi_req_cmd_rd) +
> _sc->vss_config.cdb_size)
> +
> +#define VTSCSI_OUT_HEADER_LEN(_sc) \
> + (sizeof(struct pci_vtscsi_req_cmd_wr) +
> _sc->vss_config.sense_size)
> +
> +#define VIRTIO_SCSI_MAX_CHANNEL 0
> +#define VIRTIO_SCSI_MAX_TARGET 0
> +#define VIRTIO_SCSI_MAX_LUN 16383
> +
> +#define VIRTIO_SCSI_F_INOUT (1 << 0)
> +#define VIRTIO_SCSI_F_HOTPLUG (1 << 1)
> +#define VIRTIO_SCSI_F_CHANGE (1 << 2)
> +
>
> TABS missing inconsistently after #define above ...
>
>
> +static int pci_vtscsi_debug = 0;
> +#define DPRINTF(params) if (pci_vtscsi_debug) printf params
> +#define WPRINTF(params) printf params
> +
> +struct pci_vtscsi_config {
> + uint32_t num_queues;
> + uint32_t seg_max;
> + uint32_t max_sectors;
> + uint32_t cmd_per_lun;
> + uint32_t event_info_size;
> + uint32_t sense_size;
> + uint32_t cdb_size;
> + uint16_t max_channel;
> + uint16_t max_target;
> + uint32_t max_lun;
> +} __attribute__((packed));
> +
> +struct pci_vtscsi_queue {
> + struct pci_vtscsi_softc * vsq_sc;
> + struct vqueue_info * vsq_vq;
> + int vsq_ctl_fd;
> + pthread_mutex_t vsq_mtx;
> + pthread_mutex_t vsq_qmtx;
> + pthread_cond_t vsq_cv;
> + STAILQ_HEAD(, pci_vtscsi_request) vsq_requests;
> + LIST_HEAD(, pci_vtscsi_worker) vsq_workers;
> +};
> +
> +struct pci_vtscsi_worker {
> + struct pci_vtscsi_queue * vsw_queue;
> + pthread_t vsw_thread;
> + bool vsw_exiting;
> + LIST_ENTRY(pci_vtscsi_worker) vsw_link;
> +};
> +
> +struct pci_vtscsi_request {
> + struct pci_vtscsi_queue * vsr_queue;
> + struct iovec vsr_iov_in[VTSCSI_MAXSEG];
> + int vsr_niov_in;
> + struct iovec vsr_iov_out[VTSCSI_MAXSEG];
> + int vsr_niov_out;
> + uint32_t vsr_idx;
> + STAILQ_ENTRY(pci_vtscsi_request) vsr_link;
> +};
> +
> +/*
> + * Per-device softc
> + */
> +struct pci_vtscsi_softc {
> + struct virtio_softc vss_vs;
> + struct vqueue_info vss_vq[VTSCSI_MAXQ];
> + struct pci_vtscsi_queue vss_queues[VTSCSI_REQUESTQ];
> + pthread_mutex_t vss_mtx;
> + int vss_iid;
> + int vss_ctl_fd;
> + uint32_t vss_features;
> + struct pci_vtscsi_config vss_config;
> +};
> +
> +#define VIRTIO_SCSI_T_TMF 0
> +#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
> +#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
> +#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
> +#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
> +#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
> +#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
> +#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
> +#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
> +
> +/* command-specific response values */
> +#define VIRTIO_SCSI_S_FUNCTION_COMPLETE 0
> +#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
> +#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
> +
>
> and here above ...
>
>
> +struct pci_vtscsi_ctrl_tmf {
> + uint32_t type;
> + uint32_t subtype;
> + uint8_t lun[8];
> + uint64_t id;
> + uint8_t response;
> +} __attribute__((packed));
> +
> +#define VIRTIO_SCSI_T_AN_QUERY 1
> +#define VIRTIO_SCSI_EVT_ASYNC_OPERATIONAL_CHANGE 2
> +#define VIRTIO_SCSI_EVT_ASYNC_POWER_MGMT 4
> +#define VIRTIO_SCSI_EVT_ASYNC_EXTERNAL_REQUEST 8
> +#define VIRTIO_SCSI_EVT_ASYNC_MEDIA_CHANGE 16
> +#define VIRTIO_SCSI_EVT_ASYNC_MULTI_HOST 32
> +#define VIRTIO_SCSI_EVT_ASYNC_DEVICE_BUSY 64
> +
> +struct pci_vtscsi_ctrl_an {
> + uint32_t type;
> + uint8_t lun[8];
> + uint32_t event_requested;
> + uint32_t event_actual;
> + uint8_t response;
> +} __attribute__((packed));
> +
> +/* command-specific response values */
> +#define VIRTIO_SCSI_S_OK 0
> +#define VIRTIO_SCSI_S_OVERRUN 1
> +#define VIRTIO_SCSI_S_ABORTED 2
> +#define VIRTIO_SCSI_S_BAD_TARGET 3
> +#define VIRTIO_SCSI_S_RESET 4
> +#define VIRTIO_SCSI_S_BUSY 5
> +#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
> +#define VIRTIO_SCSI_S_TARGET_FAILURE 7
> +#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
> +#define VIRTIO_SCSI_S_FAILURE 9
> +#define VIRTIO_SCSI_S_INCORRECT_LUN 12
> +
> +/* task_attr */
> +#define VIRTIO_SCSI_S_SIMPLE 0
> +#define VIRTIO_SCSI_S_ORDERED 1
> +#define VIRTIO_SCSI_S_HEAD 2
> +#define VIRTIO_SCSI_S_ACA 3
> +
>
> And here ...
>
> Pedro.
>
> _______________________________________________
> svn-src-head at freebsd.org <mailto:svn-src-head at freebsd.org> mailing
> list
> https://lists.freebsd.org/mailman/listinfo/svn-src-head
> <https://lists.freebsd.org/mailman/listinfo/svn-src-head>
> To unsubscribe, send any mail to
> "svn-src-head-unsubscribe at freebsd.org
> <mailto:svn-src-head-unsubscribe at freebsd.org>"
>
>
> Hi Pedro,
>
> I think it is the email message that messed up with it.
Hmm... could be, sorry for the false alarm!
Pedro.
More information about the svn-src-all
mailing list