* Re: [RFC-v2 6/6] virtio-scsi: Fix incorrect VirtIOSCSI->cmd_vqs[0] definition
From: Nicholas A. Bellinger @ 2012-08-18 21:47 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Stefan Hajnoczi, kvm-devel, Michael S. Tsirkin, Jan Kiszka,
qemu-devel, lf-virt, Anthony Liguori, target-devel, Zhi Yong Wu,
Christoph Hellwig
In-Reply-To: <502FE488.3000303@redhat.com>
On Sat, 2012-08-18 at 20:52 +0200, Paolo Bonzini wrote:
> Il 14/08/2012 22:20, Nicholas A. Bellinger ha scritto:
> >>> > > Since virtio_scsi currently assumes a single vqs for data, this patch
> >>> > > simply changes ->cmd_vqs[1] to handle the single VirtQueue.
>
> Wrong, multiqueue works just fine. :) It's just the kernel driver that
> doesn't support it yet.
>
<nod>
> >>> > > Cc: Paolo Bonzini <pbonzini@redhat.com>
> >>> > > Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> >>> > > Cc: Michael S. Tsirkin <mst@redhat.com>
> >>> > > Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
> >> >
> >> > This is a bugfix we need even without vhost, right?
> >> >
> > I believe so, as it appears to be stomping past the end of memory for
> > every virtio-scsi initialization regardless of vhost usage..
>
> You just did a wrong merge. When commit d2ad7dd (virtio-scsi: add
> multiqueue capability, 2012-04-06) changed cmd_vq from pointer to array
> of pointers, you should have moved the following fields to the middle of
> the struct, just like that commit did.
Ahh, I see how virtio_scsi_init() -> virtio_common_init() are setting up
the memory now.. Apologies, my mistake.
So moving the vhost-scsi related structure members ahead of the
VirtQueue releated definitions for RFC-v3, and dropping this patch.
Thanks Paolo!
--nab
^ permalink raw reply
* Re: [GIT PULL] tcm_vhost: Initial merge of vhost level target fabric driver
From: Nicholas A. Bellinger @ 2012-08-18 22:31 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Jens Axboe, kvm-devel, linux-scsi, qemu-devel, Zhi Yong Wu,
target-devel, Anthony Liguori, Paolo Bonzini, lf-virt,
Christoph Hellwig, LKML
In-Reply-To: <20120818200432.GA26215@redhat.com>
On Sat, 2012-08-18 at 23:04 +0300, Michael S. Tsirkin wrote:
> Hi Nicholas,
> I just noticed this problem in the interface:
>
> +#include <linux/vhost.h>
> +
> +/*
> + * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
> + *
> + * ABI Rev 0: July 2012 version starting point for v3.6-rc merge
> candidate +
> + * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl
> usage
> + */
> +
> +#define VHOST_SCSI_ABI_VERSION 0
> +
> +struct vhost_scsi_target {
> + int abi_version;
> + unsigned char vhost_wwpn[TRANSPORT_IQN_LEN];
> + unsigned short vhost_tpgt;
> +};
> +
>
> Here TRANSPORT_IQN_LEN is 224, which is a multiple of 4.
> Since vhost_tpgt is 2 bytes and abi_version is 4, the total size would
> be 230. But gcc needs struct size be aligned to first field size, which
> is 4 bytes, so it pads the structure by extra 2 bytes to the total of
> 232.
>
> This padding is very undesirable in an ABI:
> - it can not be initialized easily
> - it can not be checked easily
> - it can leak information between kernel and userspace
>
Hmmmm, yes. Very good reasons to avoid ABI ambiguity ..
> Simplest solution is probably just to make the padding
> explicit:
>
> +struct vhost_scsi_target {
> + int abi_version;
> + unsigned char vhost_wwpn[TRANSPORT_IQN_LEN];
> + unsigned short vhost_tpgt;
> + unsigned short reserved;
> +};
> +
>
> I think we should fix this buglet before it goes out to users.
>
<nod>, fixing this up in target-pending/master now w/ your reported-by
+signoff, and will change vhost-scsi's copy of these defs for next
week's RFC-v3 posting.
Thanks MST!
--nab
^ permalink raw reply
* Re: [RFC-v2 3/6] vhost-scsi: add -vhost-scsi host device for use with tcm-vhost
From: Nicholas A. Bellinger @ 2012-08-18 23:38 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Stefan Hajnoczi, kvm-devel, qemu-devel, Zhi Yong Wu,
Anthony Liguori, target-devel, Paolo Bonzini, lf-virt
In-Reply-To: <20120818191028.GA17770@redhat.com>
On Sat, 2012-08-18 at 22:10 +0300, Michael S. Tsirkin wrote:
> On Tue, Aug 14, 2012 at 02:12:29PM -0700, Nicholas A. Bellinger wrote:
> > On Mon, 2012-08-13 at 11:59 +0300, Michael S. Tsirkin wrote:
> > > On Mon, Aug 13, 2012 at 08:35:14AM +0000, Nicholas A. Bellinger wrote:
<SNIP>
> >
> > > > + if (ret < 0) {
> > > > + fprintf(stderr, "vhost-scsi: vhost initialization failed: %s\n",
> > > > + strerror(-ret));
> > >
> > > errors should go to monitor, here and elsewhere.
> > >
> >
> > I think this means using monitor_printf() right..?
> >
> > Looking at that now..
>
>
> error_report is handier.
>
Converted all fprintf(stderr, ...) -> error_report() usage for RFC-v3.
Thanks MST!
^ permalink raw reply
* Re: [RFC-v2 3/6] vhost-scsi: add -vhost-scsi host device for use with tcm-vhost
From: Nicholas A. Bellinger @ 2012-08-19 0:36 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Anthony Liguori, Stefan Hajnoczi, kvm-devel, Jan Kiszka,
qemu-devel, Zhi Yong Wu, Anthony Liguori, target-devel,
Paolo Bonzini, lf-virt, Christoph Hellwig
In-Reply-To: <20120818191243.GB17770@redhat.com>
On Sat, 2012-08-18 at 22:12 +0300, Michael S. Tsirkin wrote:
> On Tue, Aug 14, 2012 at 01:31:14PM -0700, Nicholas A. Bellinger wrote:
> > On Mon, 2012-08-13 at 11:53 +0300, Michael S. Tsirkin wrote:
> > > On Mon, Aug 13, 2012 at 08:35:14AM +0000, Nicholas A. Bellinger wrote:
> > > > From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
<SNIP>
> > > > +static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
> > > > + uint16_t tpgt)
> > > > +{
> > > > + VHostSCSI *vs = g_malloc0(sizeof(*vs));
> > > > + int ret;
> > > > +
> > > > + /* TODO set up vhost-scsi device and bind to tcm_vhost/$wwpm/tpgt_$tpgt */
> > > > + fprintf(stderr, "wwpn = \"%s\" tpgt = \"%u\"\n", id, tpgt);
> > > > +
> > > > + ret = vhost_dev_init(&vs->dev, -1, "/dev/vhost-scsi", false);
> > >
> > > This -1 is a hack. You need to support passing in fd from
> > > the monitor, and pass it here.
> > >
> >
> > Mmm, looking at how vhost_net_init + tap.c does this, but am not quite
> > what fd needs to be propagated up for virtio-scsi -> vhost-scsi..
> >
> > Can you please elaborate on this one a bit more..?
> >
>
> The idea is to allow running as a user without access to
> /dev/vhost-scsi.
> For this, allow passing in the fd of /dev/vhost-scsi through unix domain sockets.
>
Ah, that is a pretty neat trick.. So for vhost-scsi code, this would
mean something along the lines of the following, yes..?
Thanks MST!
diff --git a/hw/vhost-scsi.c b/hw/vhost-scsi.c
index 4206a75..8af8758 100644
--- a/hw/vhost-scsi.c
+++ b/hw/vhost-scsi.c
@@ -21,6 +21,7 @@ struct VHostSCSI {
const char *id;
const char *wwpn;
uint16_t tpgt;
+ int vhostfd;
struct vhost_dev dev;
struct vhost_virtqueue vqs[VHOST_SCSI_VQ_NUM];
QLIST_ENTRY(VHostSCSI) list;
@@ -114,13 +115,32 @@ void vhost_scsi_stop(VHostSCSI *vs, VirtIODevice *vdev)
}
static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
- uint16_t tpgt)
+ uint16_t tpgt, const char *vhostfd_str)
{
- VHostSCSI *vs = g_malloc0(sizeof(*vs));
+ VHostSCSI *vs;
int ret;
+ vs = g_malloc0(sizeof(*vs));
+ if (!vs) {
+ error_report("vhost-scsi: unable to allocate *vs\n");
+ return NULL;
+ }
+ vs->vhostfd = -1;
+
+ if (vhostfd_str) {
+ if (!qemu_isdigit(vhostfd_str[0])) {
+ error_report("vhost-scsi: passed vhostfd value is not a digit\n");
+ return NULL;
+ }
+
+ vs->vhostfd = qemu_parse_fd(vhostfd_str);
+ if (vs->vhostfd == -1) {
+ error_report("vhost-scsi: unable to parse vs->vhostfd\n");
+ return NULL;
+ }
+ }
/* TODO set up vhost-scsi device and bind to tcm_vhost/$wwpm/tpgt_$tpgt */
- ret = vhost_dev_init(&vs->dev, -1, "/dev/vhost-scsi", false);
+ ret = vhost_dev_init(&vs->dev, vs->vhostfd, "/dev/vhost-scsi", false);
if (ret < 0) {
error_report("vhost-scsi: vhost initialization failed: %s\n",
strerror(-ret));
@@ -140,7 +160,7 @@ static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
VHostSCSI *vhost_scsi_add_opts(QemuOpts *opts)
{
const char *id;
- const char *wwpn;
+ const char *wwpn, *vhostfd;
uint64_t tpgt;
id = qemu_opts_id(opts);
@@ -164,6 +184,7 @@ VHostSCSI *vhost_scsi_add_opts(QemuOpts *opts)
error_report("vhost-scsi: \"%s\" needs a 16-bit tpgt\n", id);
return NULL;
}
+ vhostfd = qemu_opt_get(opts, "vhostfd");
- return vhost_scsi_add(id, wwpn, tpgt);
+ return vhost_scsi_add(id, wwpn, tpgt, vhostfd);
}
diff --git a/qemu-config.c b/qemu-config.c
index 33399ea..2d4884c 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -636,6 +636,9 @@ QemuOptsList qemu_vhost_scsi_opts = {
}, {
.name = "tpgt",
.type = QEMU_OPT_NUMBER,
+ }, {
+ .name = "vhostfd",
+ .type = QEMU_OPT_STRING,
},
{ /* end of list */ }
},
^ permalink raw reply related
* Re: [RFC-v2 3/6] vhost-scsi: add -vhost-scsi host device for use with tcm-vhost
From: Michael S. Tsirkin @ 2012-08-19 8:44 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: Anthony Liguori, Stefan Hajnoczi, kvm-devel, Jan Kiszka,
qemu-devel, Zhi Yong Wu, Anthony Liguori, target-devel,
Paolo Bonzini, lf-virt, Christoph Hellwig
In-Reply-To: <1345336586.25161.373.camel@haakon2.linux-iscsi.org>
On Sat, Aug 18, 2012 at 05:36:26PM -0700, Nicholas A. Bellinger wrote:
> On Sat, 2012-08-18 at 22:12 +0300, Michael S. Tsirkin wrote:
> > On Tue, Aug 14, 2012 at 01:31:14PM -0700, Nicholas A. Bellinger wrote:
> > > On Mon, 2012-08-13 at 11:53 +0300, Michael S. Tsirkin wrote:
> > > > On Mon, Aug 13, 2012 at 08:35:14AM +0000, Nicholas A. Bellinger wrote:
> > > > > From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> <SNIP>
>
> > > > > +static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
> > > > > + uint16_t tpgt)
> > > > > +{
> > > > > + VHostSCSI *vs = g_malloc0(sizeof(*vs));
> > > > > + int ret;
> > > > > +
> > > > > + /* TODO set up vhost-scsi device and bind to tcm_vhost/$wwpm/tpgt_$tpgt */
> > > > > + fprintf(stderr, "wwpn = \"%s\" tpgt = \"%u\"\n", id, tpgt);
> > > > > +
> > > > > + ret = vhost_dev_init(&vs->dev, -1, "/dev/vhost-scsi", false);
> > > >
> > > > This -1 is a hack. You need to support passing in fd from
> > > > the monitor, and pass it here.
> > > >
> > >
> > > Mmm, looking at how vhost_net_init + tap.c does this, but am not quite
> > > what fd needs to be propagated up for virtio-scsi -> vhost-scsi..
> > >
> > > Can you please elaborate on this one a bit more..?
> > >
> >
> > The idea is to allow running as a user without access to
> > /dev/vhost-scsi.
> > For this, allow passing in the fd of /dev/vhost-scsi through unix domain sockets.
> >
>
> Ah, that is a pretty neat trick.. So for vhost-scsi code, this would
> mean something along the lines of the following, yes..?
Yes but with one correction. See below.
> Thanks MST!
> diff --git a/hw/vhost-scsi.c b/hw/vhost-scsi.c
> index 4206a75..8af8758 100644
> --- a/hw/vhost-scsi.c
> +++ b/hw/vhost-scsi.c
> @@ -21,6 +21,7 @@ struct VHostSCSI {
> const char *id;
> const char *wwpn;
> uint16_t tpgt;
> + int vhostfd;
> struct vhost_dev dev;
> struct vhost_virtqueue vqs[VHOST_SCSI_VQ_NUM];
> QLIST_ENTRY(VHostSCSI) list;
> @@ -114,13 +115,32 @@ void vhost_scsi_stop(VHostSCSI *vs, VirtIODevice *vdev)
> }
>
> static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
> - uint16_t tpgt)
> + uint16_t tpgt, const char *vhostfd_str)
> {
> - VHostSCSI *vs = g_malloc0(sizeof(*vs));
> + VHostSCSI *vs;
> int ret;
>
> + vs = g_malloc0(sizeof(*vs));
> + if (!vs) {
> + error_report("vhost-scsi: unable to allocate *vs\n");
> + return NULL;
> + }
> + vs->vhostfd = -1;
> +
> + if (vhostfd_str) {
> + if (!qemu_isdigit(vhostfd_str[0])) {
> + error_report("vhost-scsi: passed vhostfd value is not a digit\n");
> + return NULL;
This let you use an fd which was open at exec
but does not allow for fd to be open later in
case device is hot-plugged.
See net_handle_fd_param - I think you can just rename it
qemu_handle_fd_param to avoid code duplication.
> + }
> +
> + vs->vhostfd = qemu_parse_fd(vhostfd_str);
> + if (vs->vhostfd == -1) {
> + error_report("vhost-scsi: unable to parse vs->vhostfd\n");
> + return NULL;
> + }
> + }
> /* TODO set up vhost-scsi device and bind to tcm_vhost/$wwpm/tpgt_$tpgt */
> - ret = vhost_dev_init(&vs->dev, -1, "/dev/vhost-scsi", false);
> + ret = vhost_dev_init(&vs->dev, vs->vhostfd, "/dev/vhost-scsi", false);
> if (ret < 0) {
> error_report("vhost-scsi: vhost initialization failed: %s\n",
> strerror(-ret));
> @@ -140,7 +160,7 @@ static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
> VHostSCSI *vhost_scsi_add_opts(QemuOpts *opts)
> {
> const char *id;
> - const char *wwpn;
> + const char *wwpn, *vhostfd;
> uint64_t tpgt;
>
> id = qemu_opts_id(opts);
> @@ -164,6 +184,7 @@ VHostSCSI *vhost_scsi_add_opts(QemuOpts *opts)
> error_report("vhost-scsi: \"%s\" needs a 16-bit tpgt\n", id);
> return NULL;
> }
> + vhostfd = qemu_opt_get(opts, "vhostfd");
>
> - return vhost_scsi_add(id, wwpn, tpgt);
> + return vhost_scsi_add(id, wwpn, tpgt, vhostfd);
> }
> diff --git a/qemu-config.c b/qemu-config.c
> index 33399ea..2d4884c 100644
> --- a/qemu-config.c
> +++ b/qemu-config.c
> @@ -636,6 +636,9 @@ QemuOptsList qemu_vhost_scsi_opts = {
> }, {
> .name = "tpgt",
> .type = QEMU_OPT_NUMBER,
> + }, {
> + .name = "vhostfd",
> + .type = QEMU_OPT_STRING,
> },
> { /* end of list */ }
> },
^ permalink raw reply
* Re: [PATCH v7 2/4] virtio_balloon: introduce migration primitives to balloon pages
From: Rusty Russell @ 2012-08-20 2:29 UTC (permalink / raw)
To: Michael S. Tsirkin, Rafael Aquini
Cc: Rik van Riel, Konrad Rzeszutek Wilk, Minchan Kim, linux-kernel,
virtualization, linux-mm, Andi Kleen, Andrew Morton
In-Reply-To: <20120815144019.GH3068@redhat.com>
On Wed, 15 Aug 2012 17:40:19 +0300, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Wed, Aug 15, 2012 at 09:34:58AM -0300, Rafael Aquini wrote:
> > On Tue, Aug 14, 2012 at 10:31:09PM +0300, Michael S. Tsirkin wrote:
> > > > > now CPU1 executes the next instruction:
> > > > >
> > > > > }
> > > > >
> > > > > which would normally return to function's caller,
> > > > > but it has been overwritten by CPU2 so we get corruption.
> > > > >
> > > > > No?
> > > >
> > > > At the point CPU2 is unloading the module, it will be kept looping at the
> > > > snippet Rusty pointed out because the isolation / migration steps do not mess
> > > > with 'vb->num_pages'. The driver will only unload after leaking the total amount
> > > > of balloon's inflated pages, which means (for this hypothetical case) CPU2 will
> > > > wait until CPU1 finishes the putaback procedure.
> > > >
> > >
> > > Yes but only until unlock finishes. The last return from function
> > > is not guarded and can be overwritten.
> >
> > CPU1 will be returning to putback_balloon_page() which code is located at core
> > mm/compaction.c, outside the driver.
>
> Sorry, I don't seem to be able to articulate this clearly.
> But this is a correctness issue so I am compelled to try again.
But if there are 0 balloon pages, how is it migrating a page?
> In the end the rule is simple: you can not
> prevent module unloading from within module
> itself. It always must be the caller of your
> module that uses some lock to do this.
Not quite. If you clean up everything in your cleanup function, it also
works, which is what this does, right?
Cheers,
Rusty.
^ permalink raw reply
* Re: [PATCH v7 2/4] virtio_balloon: introduce migration primitives to balloon pages
From: Michael S. Tsirkin @ 2012-08-20 5:12 UTC (permalink / raw)
To: Rusty Russell
Cc: Rik van Riel, Rafael Aquini, Konrad Rzeszutek Wilk, Minchan Kim,
linux-kernel, virtualization, linux-mm, Andi Kleen, Andrew Morton
In-Reply-To: <87fw7i5ma0.fsf@rustcorp.com.au>
On Mon, Aug 20, 2012 at 11:59:11AM +0930, Rusty Russell wrote:
> On Wed, 15 Aug 2012 17:40:19 +0300, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> > On Wed, Aug 15, 2012 at 09:34:58AM -0300, Rafael Aquini wrote:
> > > On Tue, Aug 14, 2012 at 10:31:09PM +0300, Michael S. Tsirkin wrote:
> > > > > > now CPU1 executes the next instruction:
> > > > > >
> > > > > > }
> > > > > >
> > > > > > which would normally return to function's caller,
> > > > > > but it has been overwritten by CPU2 so we get corruption.
> > > > > >
> > > > > > No?
> > > > >
> > > > > At the point CPU2 is unloading the module, it will be kept looping at the
> > > > > snippet Rusty pointed out because the isolation / migration steps do not mess
> > > > > with 'vb->num_pages'. The driver will only unload after leaking the total amount
> > > > > of balloon's inflated pages, which means (for this hypothetical case) CPU2 will
> > > > > wait until CPU1 finishes the putaback procedure.
> > > > >
> > > >
> > > > Yes but only until unlock finishes. The last return from function
> > > > is not guarded and can be overwritten.
> > >
> > > CPU1 will be returning to putback_balloon_page() which code is located at core
> > > mm/compaction.c, outside the driver.
> >
> > Sorry, I don't seem to be able to articulate this clearly.
> > But this is a correctness issue so I am compelled to try again.
>
> But if there are 0 balloon pages, how is it migrating a page?
It could be we just finished migrating a page
dropped page lock and are 1 instruction away from
returning from callback.
> > In the end the rule is simple: you can not
> > prevent module unloading from within module
> > itself. It always must be the caller of your
> > module that uses some lock to do this.
>
> Not quite. If you clean up everything in your cleanup function, it also
> works,
No, we also need a way to make sure we returned
to caller, this is missing here.
> which is what this does, right?
>
> Cheers,
> Rusty.
This makes sure callback was invoked but not that it returned
to caller.
All will be well if callbacks are done in rcu critical section
and we synchronise it before unload.
--
MST
^ permalink raw reply
* Re: [RFC-v2 3/6] vhost-scsi: add -vhost-scsi host device for use with tcm-vhost
From: Paolo Bonzini @ 2012-08-20 9:02 UTC (permalink / raw)
To: Nicholas A. Bellinger, Anthony Liguori
Cc: Stefan Hajnoczi, kvm-devel, Michael S. Tsirkin, Jan Kiszka,
qemu-devel, Zhi Yong Wu, Anthony Liguori, target-devel, lf-virt,
Christoph Hellwig
In-Reply-To: <1344846917-7411-4-git-send-email-nab@linux-iscsi.org>
Il 13/08/2012 10:35, Nicholas A. Bellinger ha scritto:
> From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> This patch adds a new type of host device that drives the vhost_scsi
> device. The syntax to add vhost-scsi is:
>
> qemu -vhost-scsi id=vhost-scsi0,wwpn=...,tpgt=123
>
> The virtio-scsi emulated device will make use of vhost-scsi to process
> virtio-scsi requests inside the kernel and hand them to the in-kernel
> SCSI target stack using the tcm_vhost fabric driver.
>
> The tcm_vhost driver was merged into the upstream linux kernel for 3.6-rc2,
> and the commit can be found here:
>
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=commitdiff;h=057cbf49a1f08297
>
> Changelog v1 -> v2:
>
> - Expose ABI version via VHOST_SCSI_GET_ABI_VERSION + use Rev 0 as
> starting point for v3.6-rc code (Stefan + ALiguori + nab)
> - Fix upstream qemu conflict in hw/qdev-properties.c
> - Make GET_ABI_VERSION use int (nab + mst)
> - Fix vhost-scsi case lables in configure (reported by paolo)
> - Convert qdev_prop_vhost_scsi to use ->get() + ->set() following
> qdev_prop_netdev (reported by paolo)
> - Fix typo in qemu-options.hx definition of vhost-scsi (reported by paolo)
>
> Changelog v0 -> v1:
>
> - Add VHOST_SCSI_SET_ENDPOINT call (stefan)
> - Enable vhost notifiers for multiple queues (Zhi)
> - clear vhost-scsi endpoint on stopped (Zhi)
> - Add CONFIG_VHOST_SCSI for QEMU build configure (nab)
> - Rename vhost_vring_target -> vhost_scsi_target (mst + nab)
> - Add support for VHOST_SCSI_GET_ABI_VERSION ioctl (aliguori + nab)
>
> Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> Cc: Anthony Liguori <aliguori@us.ibm.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
> ---
> configure | 10 +++
> hw/Makefile.objs | 1 +
> hw/qdev-properties.c | 40 ++++++++++++
> hw/qdev.h | 3 +
> hw/vhost-scsi.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/vhost-scsi.h | 50 +++++++++++++++
> qemu-common.h | 1 +
> qemu-config.c | 16 +++++
> qemu-options.hx | 4 +
> vl.c | 18 +++++
> 10 files changed, 313 insertions(+), 0 deletions(-)
> create mode 100644 hw/vhost-scsi.c
> create mode 100644 hw/vhost-scsi.h
>
> diff --git a/configure b/configure
> index f0dbc03..1f03202 100755
> --- a/configure
> +++ b/configure
> @@ -168,6 +168,7 @@ libattr=""
> xfs=""
>
> vhost_net="no"
> +vhost_scsi="no"
> kvm="no"
> gprof="no"
> debug_tcg="no"
> @@ -513,6 +514,7 @@ Haiku)
> usb="linux"
> kvm="yes"
> vhost_net="yes"
> + vhost_scsi="yes"
> if [ "$cpu" = "i386" -o "$cpu" = "x86_64" ] ; then
> audio_possible_drivers="$audio_possible_drivers fmod"
> fi
> @@ -818,6 +820,10 @@ for opt do
> ;;
> --enable-vhost-net) vhost_net="yes"
> ;;
> + --disable-vhost-scsi) vhost_scsi="no"
> + ;;
> + --enable-vhost-scsi) vhost_scsi="yes"
> + ;;
> --disable-opengl) opengl="no"
> ;;
> --enable-opengl) opengl="yes"
> @@ -3116,6 +3122,7 @@ echo "posix_madvise $posix_madvise"
> echo "uuid support $uuid"
> echo "libcap-ng support $cap_ng"
> echo "vhost-net support $vhost_net"
> +echo "vhost-scsi support $vhost_scsi"
> echo "Trace backend $trace_backend"
> echo "Trace output file $trace_file-<pid>"
> echo "spice support $spice"
> @@ -3828,6 +3835,9 @@ case "$target_arch2" in
> if test "$vhost_net" = "yes" ; then
> echo "CONFIG_VHOST_NET=y" >> $config_target_mak
> fi
> + if test "$vhost_scsi" = "yes" ; then
> + echo "CONFIG_VHOST_SCSI=y" >> $config_target_mak
> + fi
> fi
> esac
> case "$target_arch2" in
> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> index 3ba5dd0..6ab75ec 100644
> --- a/hw/Makefile.objs
> +++ b/hw/Makefile.objs
> @@ -169,6 +169,7 @@ obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o
> obj-$(CONFIG_VIRTIO) += virtio-serial-bus.o virtio-scsi.o
> obj-$(CONFIG_SOFTMMU) += vhost_net.o
> obj-$(CONFIG_VHOST_NET) += vhost.o
> +obj-$(CONFIG_VHOST_SCSI) += vhost-scsi.o
> obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/
> obj-$(CONFIG_NO_PCI) += pci-stub.o
> obj-$(CONFIG_VGA) += vga.o
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 8aca0d4..0266266 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -4,6 +4,7 @@
> #include "blockdev.h"
> #include "hw/block-common.h"
> #include "net/hub.h"
> +#include "vhost-scsi.h"
>
> void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
> {
> @@ -696,6 +697,45 @@ PropertyInfo qdev_prop_vlan = {
> .set = set_vlan,
> };
>
> +/* --- vhost-scsi --- */
> +
> +static int parse_vhost_scsi_dev(DeviceState *dev, const char *str, void **ptr)
> +{
> + VHostSCSI *p;
> +
> + p = find_vhost_scsi(str);
> + if (p == NULL)
> + return -ENOENT;
> +
> + *ptr = p;
> + return 0;
> +}
> +
> +static const char *print_vhost_scsi_dev(void *ptr)
> +{
> + VHostSCSI *p = ptr;
> +
> + return (p) ? vhost_scsi_get_id(p) : "<null>";
> +}
> +
> +static void get_vhost_scsi_dev(Object *obj, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> + get_pointer(obj, v, opaque, print_vhost_scsi_dev, name, errp);
> +}
> +
> +static void set_vhost_scsi_dev(Object *obj, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> + set_pointer(obj, v, opaque, parse_vhost_scsi_dev, name, errp);
> +}
> +
> +PropertyInfo qdev_prop_vhost_scsi = {
> + .name = "vhost-scsi",
> + .get = get_vhost_scsi_dev,
> + .set = set_vhost_scsi_dev,
> +};
> +
> /* --- pointer --- */
>
> /* Not a proper property, just for dirty hacks. TODO Remove it! */
> diff --git a/hw/qdev.h b/hw/qdev.h
> index d699194..d5873bb 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -238,6 +238,7 @@ extern PropertyInfo qdev_prop_vlan;
> extern PropertyInfo qdev_prop_pci_devfn;
> extern PropertyInfo qdev_prop_blocksize;
> extern PropertyInfo qdev_prop_pci_host_devaddr;
> +extern PropertyInfo qdev_prop_vhost_scsi;
>
> #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
> .name = (_name), \
> @@ -305,6 +306,8 @@ extern PropertyInfo qdev_prop_pci_host_devaddr;
> DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t)
> #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
> DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
> +#define DEFINE_PROP_VHOST_SCSI(_n, _s, _f) \
> + DEFINE_PROP(_n, _s, _f, qdev_prop_vhost_scsi, VHostSCSI*)
>
> #define DEFINE_PROP_END_OF_LIST() \
> {}
> diff --git a/hw/vhost-scsi.c b/hw/vhost-scsi.c
> new file mode 100644
> index 0000000..7145b2d
> --- /dev/null
> +++ b/hw/vhost-scsi.c
> @@ -0,0 +1,170 @@
> +/*
> + * vhost_scsi host device
> + *
> + * Copyright IBM, Corp. 2011
> + *
> + * Authors:
> + * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#include <sys/ioctl.h>
> +#include "config.h"
> +#include "qemu-queue.h"
> +#include "vhost-scsi.h"
> +#include "vhost.h"
> +
> +struct VHostSCSI {
> + const char *id;
> + const char *wwpn;
> + uint16_t tpgt;
> + struct vhost_dev dev;
> + struct vhost_virtqueue vqs[3];
> + QLIST_ENTRY(VHostSCSI) list;
> +};
> +
> +static QLIST_HEAD(, VHostSCSI) vhost_scsi_list =
> + QLIST_HEAD_INITIALIZER(vhost_scsi_list);
> +
> +VHostSCSI *find_vhost_scsi(const char *id)
> +{
> + VHostSCSI *vs;
> +
> + QLIST_FOREACH(vs, &vhost_scsi_list, list) {
> + if (strcmp(id, vs->id) == 0) {
> + return vs;
> + }
> + }
> + return NULL;
> +}
> +
> +const char *vhost_scsi_get_id(VHostSCSI *vs)
> +{
> + return vs->id;
> +}
> +
> +int vhost_scsi_start(VHostSCSI *vs, VirtIODevice *vdev)
> +{
> + int ret, abi_version;
> + struct vhost_scsi_target backend;
> +
> + if (!vhost_dev_query(&vs->dev, vdev)) {
> + return -ENOTSUP;
> + }
> +
> + vs->dev.nvqs = 3;
> + vs->dev.vqs = vs->vqs;
> +
> + ret = vhost_dev_enable_notifiers(&vs->dev, vdev);
> + if (ret < 0) {
> + return ret;
> + }
> +
> + ret = vhost_dev_start(&vs->dev, vdev);
> + if (ret < 0) {
> + return ret;
> + }
> +
> + memset(&backend, 0, sizeof(backend));
> + ret = ioctl(vs->dev.control, VHOST_SCSI_GET_ABI_VERSION, &abi_version);
> + if (ret < 0) {
> + ret = -errno;
> + vhost_dev_stop(&vs->dev, vdev);
> + return ret;
> + }
> + if (abi_version > VHOST_SCSI_ABI_VERSION) {
> + fprintf(stderr, "The running tcm_vhost kernel abi_version: %d is greater"
> + " than vhost_scsi userspace supports: %d\n", abi_version,
> + VHOST_SCSI_ABI_VERSION);
> + ret = -ENOSYS;
> + vhost_dev_stop(&vs->dev, vdev);
> + return ret;
> + }
> + fprintf(stdout, "TCM_vHost ABI version: %d\n", abi_version);
> +
> + pstrcpy((char *)backend.vhost_wwpn, sizeof(backend.vhost_wwpn), vs->wwpn);
> + backend.vhost_tpgt = vs->tpgt;
> + ret = ioctl(vs->dev.control, VHOST_SCSI_SET_ENDPOINT, &backend);
> + if (ret < 0) {
> + ret = -errno;
> + vhost_dev_stop(&vs->dev, vdev);
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> +void vhost_scsi_stop(VHostSCSI *vs, VirtIODevice *vdev)
> +{
> + int ret;
> + struct vhost_scsi_target backend;
> +
> + pstrcpy((char *)backend.vhost_wwpn, sizeof(backend.vhost_wwpn), vs->wwpn);
> + backend.vhost_tpgt = vs->tpgt;
> + ret = ioctl(vs->dev.control, VHOST_SCSI_CLEAR_ENDPOINT, &backend);
> + if (ret < 0) {
> + fprintf(stderr, "Failed to clear endpoint\n");
> + }
> +
> + vhost_dev_stop(&vs->dev, vdev);
> +}
> +
> +static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
> + uint16_t tpgt)
> +{
> + VHostSCSI *vs = g_malloc0(sizeof(*vs));
> + int ret;
> +
> + /* TODO set up vhost-scsi device and bind to tcm_vhost/$wwpm/tpgt_$tpgt */
> + fprintf(stderr, "wwpn = \"%s\" tpgt = \"%u\"\n", id, tpgt);
> +
> + ret = vhost_dev_init(&vs->dev, -1, "/dev/vhost-scsi", false);
> + if (ret < 0) {
> + fprintf(stderr, "vhost-scsi: vhost initialization failed: %s\n",
> + strerror(-ret));
> + return NULL;
> + }
> + vs->dev.backend_features = 0;
> + vs->dev.acked_features = 0;
> +
> + vs->id = g_strdup(id);
> + vs->wwpn = g_strdup(wwpn);
> + vs->tpgt = tpgt;
> + QLIST_INSERT_HEAD(&vhost_scsi_list, vs, list);
> +
> + return vs;
> +}
> +
> +VHostSCSI *vhost_scsi_add_opts(QemuOpts *opts)
> +{
> + const char *id;
> + const char *wwpn;
> + uint64_t tpgt;
> +
> + id = qemu_opts_id(opts);
> + if (!id) {
> + fprintf(stderr, "vhost-scsi: no id specified\n");
> + return NULL;
> + }
> + if (find_vhost_scsi(id)) {
> + fprintf(stderr, "duplicate vhost-scsi: \"%s\"\n", id);
> + return NULL;
> + }
> +
> + wwpn = qemu_opt_get(opts, "wwpn");
> + if (!wwpn) {
> + fprintf(stderr, "vhost-scsi: \"%s\" missing wwpn\n", id);
> + return NULL;
> + }
> +
> + tpgt = qemu_opt_get_number(opts, "tpgt", UINT64_MAX);
> + if (tpgt > UINT16_MAX) {
> + fprintf(stderr, "vhost-scsi: \"%s\" needs a 16-bit tpgt\n", id);
> + return NULL;
> + }
> +
> + return vhost_scsi_add(id, wwpn, tpgt);
> +}
> diff --git a/hw/vhost-scsi.h b/hw/vhost-scsi.h
> new file mode 100644
> index 0000000..f3096dc
> --- /dev/null
> +++ b/hw/vhost-scsi.h
> @@ -0,0 +1,50 @@
> +/*
> + * vhost_scsi host device
> + *
> + * Copyright IBM, Corp. 2011
> + *
> + * Authors:
> + * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2 or later.
> + * See the COPYING.LIB file in the top-level directory.
> + *
> + */
> +
> +#ifndef VHOST_SCSI_H
> +#define VHOST_SCSI_H
> +
> +#include "qemu-common.h"
> +#include "qemu-option.h"
> +
> +/*
> + * Used by QEMU userspace to ensure a consistent vhost-scsi ABI.
> + *
> + * ABI Rev 0: July 2012 version starting point for v3.6-rc merge candidate +
> + * RFC-v2 vhost-scsi userspace. Add GET_ABI_VERSION ioctl usage
> + */
> +
> +#define VHOST_SCSI_ABI_VERSION 0
> +
> +/* TODO #include <linux/vhost.h> properly */
> +/* For VHOST_SCSI_SET_ENDPOINT/VHOST_SCSI_CLEAR_ENDPOINT ioctl */
> +struct vhost_scsi_target {
> + int abi_version;
> + unsigned char vhost_wwpn[224];
> + unsigned short vhost_tpgt;
> +};
> +
> +#define VHOST_VIRTIO 0xAF
> +#define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
> +#define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
> +#define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, struct vhost_scsi_target)
> +
> +VHostSCSI *find_vhost_scsi(const char *id);
> +const char *vhost_scsi_get_id(VHostSCSI *vs);
> +
> +VHostSCSI *vhost_scsi_add_opts(QemuOpts *opts);
> +
> +int vhost_scsi_start(VHostSCSI *vs, VirtIODevice *vdev);
> +void vhost_scsi_stop(VHostSCSI *vs, VirtIODevice *vdev);
> +
> +#endif
> diff --git a/qemu-common.h b/qemu-common.h
> index f9deca6..ec36002 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -280,6 +280,7 @@ typedef struct EventNotifier EventNotifier;
> typedef struct VirtIODevice VirtIODevice;
> typedef struct QEMUSGList QEMUSGList;
> typedef struct SHPCDevice SHPCDevice;
> +typedef struct VHostSCSI VHostSCSI;
>
> typedef uint64_t pcibus_t;
>
> diff --git a/qemu-config.c b/qemu-config.c
> index 5c3296b..33399ea 100644
> --- a/qemu-config.c
> +++ b/qemu-config.c
> @@ -626,6 +626,21 @@ QemuOptsList qemu_boot_opts = {
> },
> };
>
> +QemuOptsList qemu_vhost_scsi_opts = {
> + .name = "vhost-scsi",
> + .head = QTAILQ_HEAD_INITIALIZER(qemu_vhost_scsi_opts.head),
> + .desc = {
> + {
> + .name = "wwpn",
> + .type = QEMU_OPT_STRING,
> + }, {
> + .name = "tpgt",
> + .type = QEMU_OPT_NUMBER,
> + },
> + { /* end of list */ }
> + },
> +};
> +
> static QemuOptsList *vm_config_groups[32] = {
> &qemu_drive_opts,
> &qemu_chardev_opts,
> @@ -641,6 +656,7 @@ static QemuOptsList *vm_config_groups[32] = {
> &qemu_machine_opts,
> &qemu_boot_opts,
> &qemu_iscsi_opts,
> + &qemu_vhost_scsi_opts,
> NULL,
> };
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 47cb5bd..4e7a03c 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -565,6 +565,10 @@ possible drivers and properties, use @code{-device ?} and
> ETEXI
>
> DEFHEADING()
> +DEF("vhost-scsi", HAS_ARG, QEMU_OPTION_vhost_scsi,
> + "-vhost-scsi wwpn=string0,tpgt=number0\n"
> + " add vhost-scsi device\n",
> + QEMU_ARCH_ALL)
>
> DEFHEADING(File system options:)
>
> diff --git a/vl.c b/vl.c
> index 91076f0..61c8284 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -144,6 +144,7 @@ int main(int argc, char **argv)
> #include "qemu-options.h"
> #include "qmp-commands.h"
> #include "main-loop.h"
> +#include "hw/vhost-scsi.h"
> #ifdef CONFIG_VIRTFS
> #include "fsdev/qemu-fsdev.h"
> #endif
> @@ -1858,6 +1859,14 @@ static int fsdev_init_func(QemuOpts *opts, void *opaque)
> }
> #endif
>
> +static int vhost_scsi_init_func(QemuOpts *opts, void *opaque)
> +{
> + if (!vhost_scsi_add_opts(opts)) {
> + return -1;
> + }
> + return 0;
> +}
> +
> static int mon_init_func(QemuOpts *opts, void *opaque)
> {
> CharDriverState *chr;
> @@ -2617,6 +2626,11 @@ int main(int argc, char **argv, char **envp)
> }
> break;
> #endif
> + case QEMU_OPTION_vhost_scsi:
> + if (!qemu_opts_parse(qemu_find_opts("vhost-scsi"), optarg, 0)) {
> + exit(1);
> + }
> + break;
> #ifdef CONFIG_SLIRP
> case QEMU_OPTION_tftp:
> legacy_tftp_prefix = optarg;
> @@ -3337,6 +3351,10 @@ int main(int argc, char **argv, char **envp)
> exit(1);
> }
> #endif
> + if (qemu_opts_foreach(qemu_find_opts("vhost-scsi"),
> + vhost_scsi_init_func, NULL, 1)) {
> + exit(1);
> + }
>
> os_daemonize();
>
>
Anthony, do you think your -object patches are going to go in? Perhaps
we should reuse that option instead of inventing <option-of-the-day>
every time.
Paolo
^ permalink raw reply
* [PATCH] virtio-scsi spec: add per-LUN parameter query
From: Cong Meng @ 2012-08-20 9:03 UTC (permalink / raw)
To: Rusty Russell
Cc: stefanha, zwanp, linuxram, qemu-devel, virtualization, Cong Meng,
Paolo Bonzini
Each virtio scsi HBA has global request queue limits. But the passthrough
LUNs (scsi-generic) come from different host HBAs may have different request
queue limits. If the guest sends commands that exceed the host limits, the
commands will be rejected by host HAB.
To address this issue, this patch adds a per-LUN parameter query via the control
queue, and defines some parameter query types. The driver can query and set the
needed per-LUN parameters if the device enables this feature.
Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
--
virtio-spec.lyx | 218 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 218 insertions(+), 0 deletions(-)
diff --git a/virtio-spec.lyx b/virtio-spec.lyx
index 7a073f4..6d23ab9 100644
--- a/virtio-spec.lyx
+++ b/virtio-spec.lyx
@@ -58,6 +58,7 @@
\html_be_strict false
\author -608949062 "Rusty Russell,,,"
\author 1531152142 "Paolo Bonzini,,,"
+\author 2090695081 "Cong Meng,,,"
\end_header
\begin_body
@@ -7028,6 +7029,19 @@ VIRTIO_SCSI_F_CHANGE
(2) The host will report changes to LUN parameters via a VIRTIO_SCSI_T_PARAM_CHA
NGE event.
+\change_inserted 2090695081 1345439613
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted 2090695081 1345442620
+VIRTIO_SCSI_F_PER_LUN_QUERY
+\begin_inset space ~
+\end_inset
+
+(3) The host will support the per-LUN parameter query.
+
\change_unchanged
\end_layout
@@ -8178,6 +8192,210 @@ response
\begin_layout Standard
No command-specific values are defined for the response byte.
+\change_inserted 2090695081 1345439679
+
+\end_layout
+
+\end_deeper
+\begin_layout Description
+
+\change_inserted 2090695081 1345441715
+Per
+\begin_inset space \space{}
+\end_inset
+
+LUN
+\begin_inset space \space{}
+\end_inset
+
+query
+\begin_inset space ~
+\end_inset
+
+
+\end_layout
+
+\begin_deeper
+\begin_layout Standard
+
+\change_inserted 2090695081 1345440230
+\begin_inset listings
+inline false
+status open
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441722
+
+#define VIRTIO_SCSI_T_PER_LUN_QUERY 3
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345440248
+
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441801
+
+/* query type */
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441725
+
+#define VIRTIO_SCSI_T_PLQ_MAX_SECTORS 0
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441726
+
+#define VIRTIO_SCSI_T_PLQ_MAX_SEGMENTS 1
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441727
+
+#define VIRTIO_SCSI_T_PLQ_MAX_SEGMENT_SIZE 2
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345440248
+
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441729
+
+struct virtio_scsi_ctrl_plq {
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345440248
+
+ // Read-only part
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345440248
+
+ u32 type;
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441767
+
+ u8 lun[8];
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345441807
+
+ u32 query_type;
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345440248
+
+ // Write-only part
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345440248
+
+ u8 response;
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345445844
+
+ u32 parameter;
+\end_layout
+
+\begin_layout Plain Layout
+
+\change_inserted 2090695081 1345440248
+
+}
+\end_layout
+
+\end_inset
+
+
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 2090695081 1345443439
+The type field should be VIRTIO_SCSI_T_PER_LUN_QUERY.
+
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 2090695081 1345445951
+The query_type field is defined as below:
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted 2090695081 1345445082
+VIRTIO_SCSI_T_PLQ_MAX_SECTORS: Maximum request size of the LUN's request
+ queue.
+ The unit is KB (1024 bytes).
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted 2090695081 1345446052
+VIRTIO_SCSI_T_PLQ_MAX_SEGMENTS: Maximum sg list segments of the LUN's request
+ queue.
+\end_layout
+
+\begin_layout Itemize
+
+\change_inserted 2090695081 1345445058
+VIRTIO_SCSI_T_PLQ_MAX_SEGMENT_SIZE: Maximum segment size of the LUN's request
+ queue.
+ The unit is byte.
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 2090695081 1345445877
+By sending this command, the driver asks the specified LUN to report the
+ parameter specified by the query_type field.
+ The device responds by writing the parameter that it supports into the
+ parameter field, and VIRTIO_SCSI_S_OK into the response field.
+ Otherwise the device should write the corresponding failure response value
+ into the response field.
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 2090695081 1345443070
+All fields of the read-only part are written by the driver.
+ All fields of the write-only part are written by the device.
+\end_layout
+
+\begin_layout Standard
+
+\change_inserted 2090695081 1345440259
+No command-specific values are defined for the response byte.
\end_layout
\end_deeper
--
1.7.7.6
^ permalink raw reply related
* Re: [RFC-v2 4/6] virtio-scsi: Add start/stop functionality for vhost-scsi
From: Paolo Bonzini @ 2012-08-20 9:04 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: Stefan Hajnoczi, kvm-devel, Michael S. Tsirkin, Jan Kiszka,
qemu-devel, Zhi Yong Wu, Anthony Liguori, target-devel, lf-virt,
Christoph Hellwig
In-Reply-To: <1344846917-7411-5-git-send-email-nab@linux-iscsi.org>
Il 13/08/2012 10:35, Nicholas A. Bellinger ha scritto:
> From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>
> This patch starts and stops vhost as the virtio device transitions
> through its status phases. Vhost can only be started once the guest
> reports its driver has successfully initialized, which means the
> virtqueues have been set up by the guest.
>
> v2: - Squash virtio-scsi: use the vhost-scsi host device from stefan (nab)
> - Fix up virtio_scsi_properties[] conflict w/ upstream qemu (nab)
> - Drop usage of to_virtio_scsi() in virtio_scsi_set_status()
> (reported by paolo)
> - Use modern VirtIOSCSIConf define in virtio-scsi.h (reported by paolo)
> - Use s->conf->vhost_scsi instead of proxyconf->vhost_scsi in
> virtio_scsi_init() (reported by paolo)
> - Only register QEMU SCSI bus is vhost-scsi is not active (reported
> by paolo)
How much of the functionality of virtio-scsi.[ch] is still in use at
this point? Would it make more sense to use a separate vhost-scsi-pci
device instead?
Especially since advertising VIRTIO_SCSI_F_HOTPLUG and
VIRTIO_SCSI_F_CHANGE is probably wrong for vhost-scsi...
Paolo
> Cc: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> Cc: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
> ---
> hw/virtio-pci.c | 1 +
> hw/virtio-scsi.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
> hw/virtio-scsi.h | 1 +
> 3 files changed, 50 insertions(+), 0 deletions(-)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 125eded..b29fc3b 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -1036,6 +1036,7 @@ static void virtio_scsi_exit_pci(PCIDevice *pci_dev)
> }
>
> static Property virtio_scsi_properties[] = {
> + DEFINE_PROP_VHOST_SCSI("vhost-scsi", VirtIOPCIProxy, scsi.vhost_scsi),
> DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
> DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, DEV_NVECTORS_UNSPECIFIED),
> DEFINE_VIRTIO_SCSI_PROPERTIES(VirtIOPCIProxy, host_features, scsi),
> diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
> index 5f737ac..8130956 100644
> --- a/hw/virtio-scsi.c
> +++ b/hw/virtio-scsi.c
> @@ -13,9 +13,13 @@
> *
> */
>
> +#include "qemu-common.h"
> +#include "qemu-error.h"
> +#include "vhost-scsi.h"
> #include "virtio-scsi.h"
> #include <hw/scsi.h>
> #include <hw/scsi-defs.h>
> +#include "vhost.h"
>
> #define VIRTIO_SCSI_VQ_SIZE 128
> #define VIRTIO_SCSI_CDB_SIZE 32
> @@ -147,6 +151,9 @@ typedef struct {
> VirtQueue *ctrl_vq;
> VirtQueue *event_vq;
> VirtQueue *cmd_vqs[0];
> +
> + bool vhost_started;
> + VHostSCSI *vhost_scsi;
> } VirtIOSCSI;
>
> typedef struct VirtIOSCSIReq {
> @@ -699,6 +706,38 @@ static struct SCSIBusInfo virtio_scsi_scsi_info = {
> .load_request = virtio_scsi_load_request,
> };
>
> +static bool virtio_scsi_started(VirtIOSCSI *s, uint8_t val)
> +{
> + return (val & VIRTIO_CONFIG_S_DRIVER_OK) && s->vdev.vm_running;
> +}
> +
> +static void virtio_scsi_set_status(VirtIODevice *vdev, uint8_t val)
> +{
> + VirtIOSCSI *s = (VirtIOSCSI *)vdev;
> + bool start = virtio_scsi_started(s, val);
> +
> + if (s->vhost_started == start) {
> + return;
> + }
> +
> + if (start) {
> + int ret;
> +
> + ret = vhost_scsi_start(s->vhost_scsi, vdev);
> + if (ret < 0) {
> + error_report("virtio-scsi: unable to start vhost: %s\n",
> + strerror(-ret));
> +
> + /* There is no userspace virtio-scsi fallback so exit */
> + exit(1);
> + }
> + } else {
> + vhost_scsi_stop(s->vhost_scsi, vdev);
> + }
> +
> + s->vhost_started = start;
> +}
> +
> VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
> {
> VirtIOSCSI *s;
> @@ -712,12 +751,17 @@ VirtIODevice *virtio_scsi_init(DeviceState *dev, VirtIOSCSIConf *proxyconf)
>
> s->qdev = dev;
> s->conf = proxyconf;
> + s->vhost_started = false;
> + s->vhost_scsi = s->conf->vhost_scsi;
>
> /* TODO set up vdev function pointers */
> s->vdev.get_config = virtio_scsi_get_config;
> s->vdev.set_config = virtio_scsi_set_config;
> s->vdev.get_features = virtio_scsi_get_features;
> s->vdev.reset = virtio_scsi_reset;
> + if (s->vhost_scsi) {
> + s->vdev.set_status = virtio_scsi_set_status;
> + }
>
> s->ctrl_vq = virtio_add_queue(&s->vdev, VIRTIO_SCSI_VQ_SIZE,
> virtio_scsi_handle_ctrl);
> @@ -743,5 +787,9 @@ void virtio_scsi_exit(VirtIODevice *vdev)
> {
> VirtIOSCSI *s = (VirtIOSCSI *)vdev;
> unregister_savevm(s->qdev, "virtio-scsi", s);
> +
> + /* This will stop vhost backend if appropriate. */
> + virtio_scsi_set_status(vdev, 0);
> +
> virtio_cleanup(vdev);
> }
> diff --git a/hw/virtio-scsi.h b/hw/virtio-scsi.h
> index 4bc889d..74e9422 100644
> --- a/hw/virtio-scsi.h
> +++ b/hw/virtio-scsi.h
> @@ -22,6 +22,7 @@
> #define VIRTIO_ID_SCSI 8
>
> struct VirtIOSCSIConf {
> + VHostSCSI *vhost_scsi;
> uint32_t num_queues;
> uint32_t max_sectors;
> uint32_t cmd_per_lun;
>
^ permalink raw reply
* Re: [RFC-v2 4/6] virtio-scsi: Add start/stop functionality for vhost-scsi
From: Stefan Hajnoczi @ 2012-08-20 11:31 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Stefan Hajnoczi, kvm-devel, Michael S. Tsirkin, Jan Kiszka,
qemu-devel, Zhi Yong Wu, Anthony Liguori, target-devel, lf-virt,
Christoph Hellwig
In-Reply-To: <5031FD9E.9080204@redhat.com>
On Mon, Aug 20, 2012 at 10:04 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Il 13/08/2012 10:35, Nicholas A. Bellinger ha scritto:
>> From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
>>
>> This patch starts and stops vhost as the virtio device transitions
>> through its status phases. Vhost can only be started once the guest
>> reports its driver has successfully initialized, which means the
>> virtqueues have been set up by the guest.
>>
>> v2: - Squash virtio-scsi: use the vhost-scsi host device from stefan (nab)
>> - Fix up virtio_scsi_properties[] conflict w/ upstream qemu (nab)
>> - Drop usage of to_virtio_scsi() in virtio_scsi_set_status()
>> (reported by paolo)
>> - Use modern VirtIOSCSIConf define in virtio-scsi.h (reported by paolo)
>> - Use s->conf->vhost_scsi instead of proxyconf->vhost_scsi in
>> virtio_scsi_init() (reported by paolo)
>> - Only register QEMU SCSI bus is vhost-scsi is not active (reported
>> by paolo)
>
> How much of the functionality of virtio-scsi.[ch] is still in use at
> this point? Would it make more sense to use a separate vhost-scsi-pci
> device instead?
Since the SCSI target lives in the kernel, almost everything is driven
from tcm_vhost.ko. tcm_vhost.ko basically implements the full device
so I see the argument for -device vhost-scsi-pci.
> Especially since advertising VIRTIO_SCSI_F_HOTPLUG and
> VIRTIO_SCSI_F_CHANGE is probably wrong for vhost-scsi...
vhost participates in feature bit negotiation, see
VHOST_GET_FEATURES/VHOST_SET_FEATURES ioctls.
Stefan
^ permalink raw reply
* Re: [RFC-v2 4/6] virtio-scsi: Add start/stop functionality for vhost-scsi
From: Michael S. Tsirkin @ 2012-08-20 11:57 UTC (permalink / raw)
To: Stefan Hajnoczi
Cc: Stefan Hajnoczi, kvm-devel, Jan Kiszka, qemu-devel, Zhi Yong Wu,
Anthony Liguori, target-devel, Paolo Bonzini, lf-virt,
Christoph Hellwig
In-Reply-To: <CAJSP0QUPX2CiNrBAxD=vvEcV_32Qf-=Ed3=Ck5c+wKsSDZ4heQ@mail.gmail.com>
On Mon, Aug 20, 2012 at 12:31:01PM +0100, Stefan Hajnoczi wrote:
> On Mon, Aug 20, 2012 at 10:04 AM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> > Il 13/08/2012 10:35, Nicholas A. Bellinger ha scritto:
> >> From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> >>
> >> This patch starts and stops vhost as the virtio device transitions
> >> through its status phases. Vhost can only be started once the guest
> >> reports its driver has successfully initialized, which means the
> >> virtqueues have been set up by the guest.
> >>
> >> v2: - Squash virtio-scsi: use the vhost-scsi host device from stefan (nab)
> >> - Fix up virtio_scsi_properties[] conflict w/ upstream qemu (nab)
> >> - Drop usage of to_virtio_scsi() in virtio_scsi_set_status()
> >> (reported by paolo)
> >> - Use modern VirtIOSCSIConf define in virtio-scsi.h (reported by paolo)
> >> - Use s->conf->vhost_scsi instead of proxyconf->vhost_scsi in
> >> virtio_scsi_init() (reported by paolo)
> >> - Only register QEMU SCSI bus is vhost-scsi is not active (reported
> >> by paolo)
> >
> > How much of the functionality of virtio-scsi.[ch] is still in use at
> > this point? Would it make more sense to use a separate vhost-scsi-pci
> > device instead?
>
> Since the SCSI target lives in the kernel, almost everything is driven
> from tcm_vhost.ko. tcm_vhost.ko basically implements the full device
> so I see the argument for -device vhost-scsi-pci.
A bit unhappy that there is no virtio in the name since it is
implementing virtio protocol.
> > Especially since advertising VIRTIO_SCSI_F_HOTPLUG and
> > VIRTIO_SCSI_F_CHANGE is probably wrong for vhost-scsi...
>
> vhost participates in feature bit negotiation, see
> VHOST_GET_FEATURES/VHOST_SET_FEATURES ioctls.
>
> Stefan
^ permalink raw reply
* Re: [RFC-v2 4/6] virtio-scsi: Add start/stop functionality for vhost-scsi
From: Paolo Bonzini @ 2012-08-20 12:00 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Stefan Hajnoczi, kvm-devel, qemu-devel, Zhi Yong Wu,
Anthony Liguori, target-devel, Jan Kiszka, lf-virt,
Christoph Hellwig
In-Reply-To: <20120820115704.GA3580@redhat.com>
Il 20/08/2012 13:57, Michael S. Tsirkin ha scritto:
>>> > > How much of the functionality of virtio-scsi.[ch] is still in use at
>>> > > this point? Would it make more sense to use a separate vhost-scsi-pci
>>> > > device instead?
>> >
>> > Since the SCSI target lives in the kernel, almost everything is driven
>> > from tcm_vhost.ko. tcm_vhost.ko basically implements the full device
>> > so I see the argument for -device vhost-scsi-pci.
> A bit unhappy that there is no virtio in the name since it is
> implementing virtio protocol.
>
Yeah, but vhost \subseteq virtio...
Paolo
^ permalink raw reply
* Re: [PATCH] virtio-scsi spec: add per-LUN parameter query
From: Paolo Bonzini @ 2012-08-20 13:18 UTC (permalink / raw)
To: Cong Meng; +Cc: stefanha, zwanp, linuxram, qemu-devel, virtualization
In-Reply-To: <1345453404-15244-1-git-send-email-mc@linux.vnet.ibm.com>
Il 20/08/2012 11:03, Cong Meng ha scritto:
> Each virtio scsi HBA has global request queue limits. But the passthrough
> LUNs (scsi-generic) come from different host HBAs may have different request
> queue limits. If the guest sends commands that exceed the host limits, the
> commands will be rejected by host HAB.
>
> To address this issue, this patch adds a per-LUN parameter query via the control
> queue, and defines some parameter query types. The driver can query and set the
> needed per-LUN parameters if the device enables this feature.
>
> Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
> --
> virtio-spec.lyx | 218 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 218 insertions(+), 0 deletions(-)
Do you have kernel and QEMU patches for this? That would help me
evaluate whether the interface is the correct one.
In any case, I'd rather have a single command returning all three values
(VIRTIO_SCSI_T_LUN_QUEUE_PARAMS), since it's unlikely that you need just
one.
Paolo
^ permalink raw reply
* Re: [PATCH] virtio-scsi spec: add per-LUN parameter query
From: McPacino @ 2012-08-20 14:44 UTC (permalink / raw)
To: Paolo Bonzini
Cc: stefanha, zwanp, linuxram, qemu-devel, virtualization, Cong Meng
In-Reply-To: <50323926.8000205@redhat.com>
[-- Attachment #1.1: Type: text/plain, Size: 1571 bytes --]
在 2012-8-20 下午9:18,"Paolo Bonzini" <pbonzini@redhat.com>写道:
>
> Il 20/08/2012 11:03, Cong Meng ha scritto:
> > Each virtio scsi HBA has global request queue limits. But the
passthrough
> > LUNs (scsi-generic) come from different host HBAs may have different
request
> > queue limits. If the guest sends commands that exceed the host limits,
the
> > commands will be rejected by host HAB.
> >
> > To address this issue, this patch adds a per-LUN parameter query via
the control
> > queue, and defines some parameter query types. The driver can query and
set the
> > needed per-LUN parameters if the device enables this feature.
> >
> > Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
> > --
> > virtio-spec.lyx | 218
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 files changed, 218 insertions(+), 0 deletions(-)
>
> Do you have kernel and QEMU patches for this? That would help me
> evaluate whether the interface is the correct one.
>
yes,I have a demo. I will post it after I polish it tomorrow.
> In any case, I'd rather have a single command returning all three values
> (VIRTIO_SCSI_T_LUN_QUEUE_PARAMS), since it's unlikely that you need just
> one.
I intend to seperat them one by one. As there is opportunity that other new
parameters are needed for other features.
Thanks.
Cong.
>
> Paolo
> _______________________________________________
> Virtualization mailing list
> Virtualization@lists.linux-foundation.org
> https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[-- Attachment #1.2: Type: text/html, Size: 2149 bytes --]
[-- Attachment #2: Type: text/plain, Size: 183 bytes --]
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [PATCH] virtio-scsi spec: add per-LUN parameter query
From: Paolo Bonzini @ 2012-08-20 15:57 UTC (permalink / raw)
To: McPacino; +Cc: stefanha, zwanp, linuxram, qemu-devel, virtualization, Cong Meng
In-Reply-To: <CAOKNXO7PLs8ansCf0YajruO=yX8B_FAeZ==iuYwN2mAqoOLVuQ@mail.gmail.com>
Il 20/08/2012 16:44, McPacino ha scritto:
>
> 在 2012-8-20 下午9:18,"Paolo Bonzini" <pbonzini@redhat.com
> <mailto:pbonzini@redhat.com>>写道:
>>
>> Il 20/08/2012 11:03, Cong Meng ha scritto:
>> > Each virtio scsi HBA has global request queue limits. But the
> passthrough
>> > LUNs (scsi-generic) come from different host HBAs may have different
> request
>> > queue limits. If the guest sends commands that exceed the host
> limits, the
>> > commands will be rejected by host HAB.
>> >
>> > To address this issue, this patch adds a per-LUN parameter query via
> the control
>> > queue, and defines some parameter query types. The driver can query
> and set the
>> > needed per-LUN parameters if the device enables this feature.
>> >
>> > Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com
> <mailto:mc@linux.vnet.ibm.com>>
>> > --
>> > virtio-spec.lyx | 218
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> > 1 files changed, 218 insertions(+), 0 deletions(-)
>>
>> Do you have kernel and QEMU patches for this? That would help me
>> evaluate whether the interface is the correct one.
>>
> yes,I have a demo. I will post it after I polish it tomorrow.
>
>> In any case, I'd rather have a single command returning all three values
>> (VIRTIO_SCSI_T_LUN_QUEUE_PARAMS), since it's unlikely that you need just
>> one.
>
> I intend to seperat them one by one. As there is opportunity that other
> new parameters are needed for other features.
You can use more feature bits to dictate which bits are present.
Paolo
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply
* Re: [RFC-v2 3/6] vhost-scsi: add -vhost-scsi host device for use with tcm-vhost
From: Nicholas A. Bellinger @ 2012-08-20 22:24 UTC (permalink / raw)
To: Michael S. Tsirkin
Cc: Anthony Liguori, Stefan Hajnoczi, kvm-devel, Jan Kiszka,
qemu-devel, Zhi Yong Wu, Anthony Liguori, target-devel,
Paolo Bonzini, lf-virt, Christoph Hellwig
In-Reply-To: <20120819084426.GB26215@redhat.com>
On Sun, 2012-08-19 at 11:44 +0300, Michael S. Tsirkin wrote:
> On Sat, Aug 18, 2012 at 05:36:26PM -0700, Nicholas A. Bellinger wrote:
> > On Sat, 2012-08-18 at 22:12 +0300, Michael S. Tsirkin wrote:
> > > On Tue, Aug 14, 2012 at 01:31:14PM -0700, Nicholas A. Bellinger wrote:
> > > > On Mon, 2012-08-13 at 11:53 +0300, Michael S. Tsirkin wrote:
> > > > > On Mon, Aug 13, 2012 at 08:35:14AM +0000, Nicholas A. Bellinger wrote:
> > > > > > From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
<SNIP>
> > > > Mmm, looking at how vhost_net_init + tap.c does this, but am not quite
> > > > what fd needs to be propagated up for virtio-scsi -> vhost-scsi..
> > > >
> > > > Can you please elaborate on this one a bit more..?
> > > >
> > >
> > > The idea is to allow running as a user without access to
> > > /dev/vhost-scsi.
> > > For this, allow passing in the fd of /dev/vhost-scsi through unix domain sockets.
> > >
> >
> > Ah, that is a pretty neat trick.. So for vhost-scsi code, this would
> > mean something along the lines of the following, yes..?
>
> Yes but with one correction. See below.
>
> > Thanks MST!
>
> > diff --git a/hw/vhost-scsi.c b/hw/vhost-scsi.c
> > index 4206a75..8af8758 100644
> > --- a/hw/vhost-scsi.c
> > +++ b/hw/vhost-scsi.c
> > @@ -21,6 +21,7 @@ struct VHostSCSI {
> > const char *id;
> > const char *wwpn;
> > uint16_t tpgt;
> > + int vhostfd;
> > struct vhost_dev dev;
> > struct vhost_virtqueue vqs[VHOST_SCSI_VQ_NUM];
> > QLIST_ENTRY(VHostSCSI) list;
> > @@ -114,13 +115,32 @@ void vhost_scsi_stop(VHostSCSI *vs, VirtIODevice *vdev)
> > }
> >
> > static VHostSCSI *vhost_scsi_add(const char *id, const char *wwpn,
> > - uint16_t tpgt)
> > + uint16_t tpgt, const char *vhostfd_str)
> > {
> > - VHostSCSI *vs = g_malloc0(sizeof(*vs));
> > + VHostSCSI *vs;
> > int ret;
> >
> > + vs = g_malloc0(sizeof(*vs));
> > + if (!vs) {
> > + error_report("vhost-scsi: unable to allocate *vs\n");
> > + return NULL;
> > + }
> > + vs->vhostfd = -1;
> > +
> > + if (vhostfd_str) {
> > + if (!qemu_isdigit(vhostfd_str[0])) {
> > + error_report("vhost-scsi: passed vhostfd value is not a digit\n");
> > + return NULL;
>
> This let you use an fd which was open at exec
> but does not allow for fd to be open later in
> case device is hot-plugged.
>
> See net_handle_fd_param - I think you can just rename it
> qemu_handle_fd_param to avoid code duplication.
>
OK, so monitor_get_fd() will set this up for the case where the device
is hot-plugged. That makes alot more sense now..
So renaming net_handle_fd_param -> qemu_handle_fd_param + moving into
cutils.c, and will include as a leading patch for RFC-v3.
Thanks MST!
--nab
^ permalink raw reply
* Re: [RFC PATCH 0/6] virtio-trace: Support virtio-trace
From: Rusty Russell @ 2012-08-21 2:17 UTC (permalink / raw)
To: Amit Shah, Yoshihiro YUNOMAE
Cc: Arnd Bergmann, qemu-devel, Frederic Weisbecker, yrl.pp-manager.tt,
linux-kernel, Borislav Petkov, virtualization, Herbert Xu,
Franch Ch. Eigler, Ingo Molnar, Mathieu Desnoyers, Steven Rostedt,
Anthony Liguori, Greg Kroah-Hartman
In-Reply-To: <20120809101620.GN3280@amit.redhat.com>
On Thu, 9 Aug 2012 15:46:20 +0530, Amit Shah <amit.shah@redhat.com> wrote:
> Hi,
>
> On (Tue) 24 Jul 2012 [11:36:57], Yoshihiro YUNOMAE wrote:
> > Hi All,
> >
> > The following patch set provides a low-overhead system for collecting kernel
> > tracing data of guests by a host in a virtualization environment.
>
> So I just have one minor comment, please post a non-RFC version of the
> patch.
>
> Since you have an ACK from Steven for the ftrace patch, I guess Rusty
> can push this in via his virtio tree?
>
> I'll ack the virtio-console bits in the next series you send.
You didn't Ack, BTW. At least, AFAICT.
Cheers,
Rusty.
^ permalink raw reply
* Re: [RFC PATCH 0/6] virtio-trace: Support virtio-trace
From: Amit Shah @ 2012-08-21 5:09 UTC (permalink / raw)
To: Rusty Russell
Cc: Arnd Bergmann, qemu-devel, Frederic Weisbecker, yrl.pp-manager.tt,
linux-kernel, Borislav Petkov, virtualization, Herbert Xu,
Franch Ch. Eigler, Ingo Molnar, Mathieu Desnoyers, Steven Rostedt,
Anthony Liguori, Greg Kroah-Hartman
In-Reply-To: <87393h3s5v.fsf@rustcorp.com.au>
On (Tue) 21 Aug 2012 [11:47:16], Rusty Russell wrote:
> On Thu, 9 Aug 2012 15:46:20 +0530, Amit Shah <amit.shah@redhat.com> wrote:
> > Hi,
> >
> > On (Tue) 24 Jul 2012 [11:36:57], Yoshihiro YUNOMAE wrote:
> > > Hi All,
> > >
> > > The following patch set provides a low-overhead system for collecting kernel
> > > tracing data of guests by a host in a virtualization environment.
> >
> > So I just have one minor comment, please post a non-RFC version of the
> > patch.
> >
> > Since you have an ACK from Steven for the ftrace patch, I guess Rusty
> > can push this in via his virtio tree?
> >
> > I'll ack the virtio-console bits in the next series you send.
>
> You didn't Ack, BTW. At least, AFAICT.
Ah, sorry. Will do that now.
Amit
^ permalink raw reply
* Re: [PATCH V2 0/6] virtio-trace: Support virtio-trace
From: Amit Shah @ 2012-08-21 5:16 UTC (permalink / raw)
To: Yoshihiro YUNOMAE
Cc: Arnd Bergmann, qemu-devel, Frederic Weisbecker, linux-kernel,
Borislav Petkov, virtualization, Herbert Xu, Franch Ch. Eigler,
Ingo Molnar, Mathieu Desnoyers, Steven Rostedt, Anthony Liguori,
Greg Kroah-Hartman, Masami Hiramatsu, yrl.pp-manager.tt
In-Reply-To: <20120809123029.8542.38311.stgit@ltc189.sdl.hitachi.co.jp>
On (Thu) 09 Aug 2012 [21:30:29], Yoshihiro YUNOMAE wrote:
> Hi All,
>
> The following patch set provides a low-overhead system for collecting kernel
> tracing data of guests by a host in a virtualization environment.
ACK this series.
I ran it through the virtio-serial test suite, and there's no
regression in existing functionality.
I encourage you to check out the virtio-serial test suite[1] as well
as the virtio-serial unit tests in the autotest[2] code, and
contribute to them to add tests for the new functionality you've
added.
[1]
http://fedorapeople.org/cgit/amitshah/public_git/test-virtserial.git/
[2]
https://github.com/autotest/autotest/blob/e91cd67b845b291622c8d079a8289c4b0cb1e6ae/client/tests/kvm/tests/virtio_console.py
Thanks,
Amit
^ permalink raw reply
* Re: [PATCH v7 2/4] virtio_balloon: introduce migration primitives to balloon pages
From: Rusty Russell @ 2012-08-21 5:31 UTC (permalink / raw)
To: Michael S. Tsirkin, Mel Gorman
Cc: Rik van Riel, Rafael Aquini, Konrad Rzeszutek Wilk, Minchan Kim,
linux-kernel, virtualization, linux-mm, Andi Kleen, Andrew Morton
In-Reply-To: <20120815112851.GA2707@redhat.com>
On Wed, 15 Aug 2012 14:28:51 +0300, "Michael S. Tsirkin" <mst@redhat.com> wrote:
> On Wed, Aug 15, 2012 at 12:16:51PM +0100, Mel Gorman wrote:
> > I was thinking of exactly that page->mapping == balloon_mapping check. As I
> > do not know how many active balloon drivers there might be I cannot guess
> > in advance how much of a scalability problem it will be.
>
> Not at all sure multiple drivers are worth supporting, but multiple
> *devices* is I think worth supporting, if for no other reason than that
> they can work today. For that, we need a device pointer which Rafael
> wants to put into the mapping, this means multiple balloon mappings.
Rafael, please make sure that the balloon driver fails on the second and
subsequent balloon devices.
Michael, we only allow multiple balloon devices because it fell out of
the implementation. If it causes us even the slightest issue, we should
not support it. It's not a sensible setup.
Cheers,
Rusty.
^ permalink raw reply
* [PATCH 1/2 v1] blkdrv: Add queue limits parameters for sg block drive
From: Cong Meng @ 2012-08-21 8:23 UTC (permalink / raw)
To: Paolo Bonzini
Cc: stefanha, zwanp, linuxram, qemu-devel, virtualization, Cong Meng
This patch adds some queue limit parameters into block drive. And inits them
for sg block drive. Some interfaces are also added for accessing them.
Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
---
block/raw-posix.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
block_int.h | 4 +++
blockdev.c | 15 +++++++++++++
hw/block-common.h | 3 ++
4 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 0dce089..a086f89 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -53,6 +53,7 @@
#include <linux/cdrom.h>
#include <linux/fd.h>
#include <linux/fs.h>
+#include <dirent.h>
#endif
#ifdef CONFIG_FIEMAP
#include <linux/fiemap.h>
@@ -829,6 +830,62 @@ static int hdev_probe_device(const char *filename)
return 0;
}
+static void read_queue_limit(char *path, const char *filename, unsigned int *val)
+{
+ FILE *f;
+ char *tail = path + strlen(path);
+
+ pstrcat(path, MAXPATHLEN, filename);
+ f = fopen(path, "r");
+ if (!f) {
+ goto out;
+ }
+
+ fscanf(f, "%u", val);
+ fclose(f);
+
+out:
+ *tail = 0;
+}
+
+static void sg_get_queue_limits(BlockDriverState *bs, const char *filename)
+{
+ DIR *ffs;
+ struct dirent *d;
+ char path[MAXPATHLEN];
+
+ snprintf(path, MAXPATHLEN,
+ "/sys/class/scsi_generic/sg%s/device/block/",
+ filename + strlen("/dev/sg"));
+
+ ffs = opendir(path);
+ if (!ffs) {
+ return;
+ }
+
+ for (;;) {
+ d = readdir(ffs);
+ if (!d) {
+ return;
+ }
+
+ if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) {
+ continue;
+ }
+
+ break;
+ }
+
+ closedir(ffs);
+
+ pstrcat(path, MAXPATHLEN, d->d_name);
+ pstrcat(path, MAXPATHLEN, "/queue/");
+
+ read_queue_limit(path, "max_sectors_kb", &bs->max_sectors);
+ read_queue_limit(path, "max_segments", &bs->max_segments);
+ read_queue_limit(path, "max_segment_size", &bs->max_segment_size);
+}
+
static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVRawState *s = bs->opaque;
@@ -868,6 +925,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
temp = realpath(filename, resolved_path);
if (temp && strstart(temp, "/dev/sg", NULL)) {
bs->sg = 1;
+ sg_get_queue_limits(bs, temp);
}
}
#endif
diff --git a/block_int.h b/block_int.h
index d72317f..a9d07a2 100644
--- a/block_int.h
+++ b/block_int.h
@@ -333,6 +333,10 @@ struct BlockDriverState {
/* long-running background operation */
BlockJob *job;
+
+ unsigned int max_sectors;
+ unsigned int max_segments;
+ unsigned int max_segment_size;
};
int get_tmp_filename(char *filename, int size);
diff --git a/blockdev.c b/blockdev.c
index 3d75015..e17edbf 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -1191,3 +1191,18 @@ BlockJobInfoList *qmp_query_block_jobs(Error **errp)
bdrv_iterate(do_qmp_query_block_jobs_one, &prev);
return dummy.next;
}
+
+unsigned int get_queue_max_sectors(BlockDriverState *bs)
+{
+ return (bs->file && bs->file->sg) ? bs->file->max_sectors : 0;
+}
+
+unsigned int get_queue_max_segments(BlockDriverState *bs)
+{
+ return (bs->file && bs->file->sg) ? bs->file->max_segments : 0;
+}
+
+unsigned int get_queue_max_segment_size(BlockDriverState *bs)
+{
+ return (bs->file && bs->file->sg) ? bs->file->max_segment_size : 0;
+}
diff --git a/hw/block-common.h b/hw/block-common.h
index bb808f7..d47fcd7 100644
--- a/hw/block-common.h
+++ b/hw/block-common.h
@@ -76,4 +76,7 @@ void hd_geometry_guess(BlockDriverState *bs,
int *ptrans);
int hd_bios_chs_auto_trans(uint32_t cyls, uint32_t heads, uint32_t secs);
+unsigned int get_queue_max_sectors(BlockDriverState *bs);
+unsigned int get_queue_max_segments(BlockDriverState *bs);
+unsigned int get_queue_max_segment_size(BlockDriverState *bs);
#endif
--
1.7.7.6
^ permalink raw reply related
* [PATCH 2/2 v1] virtio-scsi: set per-LUN queue limits for sg devices
From: Cong Meng @ 2012-08-21 8:23 UTC (permalink / raw)
To: Paolo Bonzini
Cc: stefanha, zwanp, linuxram, qemu-devel, virtualization, Cong Meng
In-Reply-To: <1345537427-21601-1-git-send-email-mc@linux.vnet.ibm.com>
Each virtio scsi HBA has global request queue limits. But the passthrough
LUNs (scsi-generic) come from different host HBAs may have different request
queue limits. If the guest sends commands that exceed the host limits, the
commands will be rejected by host HAB.
To address the issue, this patch responses the newly added virtio control
queue request by returning the per-LUN queue limits.
Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
---
hw/virtio-scsi.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index c4a5b22..3c0bd99 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -28,6 +28,7 @@
#define VIRTIO_SCSI_F_INOUT 0
#define VIRTIO_SCSI_F_HOTPLUG 1
#define VIRTIO_SCSI_F_CHANGE 2
+#define VIRTIO_SCSI_F_LUN_QUERY 3
/* Response codes */
#define VIRTIO_SCSI_S_OK 0
@@ -48,6 +49,7 @@
#define VIRTIO_SCSI_T_TMF 0
#define VIRTIO_SCSI_T_AN_QUERY 1
#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
+#define VIRTIO_SCSI_T_LUN_QUERY 3
/* Valid TMF subtypes. */
#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
@@ -66,6 +68,11 @@
#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
#define VIRTIO_SCSI_T_PARAM_CHANGE 3
+/* LUN Query */
+#define VIRTIO_SCSI_T_LQ_MAX_SECTORS 0
+#define VIRTIO_SCSI_T_LQ_MAX_SEGMENTS 1
+#define VIRTIO_SCSI_T_LQ_MAX_SEGMENT_SIZE 2
+
/* Reasons for transport reset event */
#define VIRTIO_SCSI_EVT_RESET_HARD 0
#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
@@ -115,6 +122,18 @@ typedef struct {
uint8_t response;
} QEMU_PACKED VirtIOSCSICtrlANResp;
+/* LUN qeury */
+typedef struct {
+ uint32_t type;
+ uint8_t lun[8];
+ uint32_t subtype;
+} QEMU_PACKED VirtIOSCSICtrlLQReq;
+
+typedef struct {
+ uint32_t response;
+ uint32_t value;
+} QEMU_PACKED VirtIOSCSICtrlLQResp;
+
typedef struct {
uint32_t event;
uint8_t lun[8];
@@ -160,6 +179,7 @@ typedef struct VirtIOSCSIReq {
VirtIOSCSICmdReq *cmd;
VirtIOSCSICtrlTMFReq *tmf;
VirtIOSCSICtrlANReq *an;
+ VirtIOSCSICtrlLQReq *lq;
} req;
union {
char *buf;
@@ -167,6 +187,7 @@ typedef struct VirtIOSCSIReq {
VirtIOSCSICtrlTMFResp *tmf;
VirtIOSCSICtrlANResp *an;
VirtIOSCSIEvent *event;
+ VirtIOSCSICtrlLQResp *lq;
} resp;
} VirtIOSCSIReq;
@@ -285,6 +306,43 @@ static void *virtio_scsi_load_request(QEMUFile *f, SCSIRequest *sreq)
return req;
}
+static void virtio_scsi_do_lun_query(VirtIOSCSI *s, VirtIOSCSIReq *req)
+{
+ SCSIDevice *d = virtio_scsi_device_find(s, req->req.lq->lun);
+
+ if (!d) {
+ goto fail;
+ }
+
+ switch (req->req.lq->subtype) {
+ case VIRTIO_SCSI_T_LQ_MAX_SECTORS:
+ req->resp.lq->value = get_queue_max_sectors(d->conf.bs);
+ if (!req->resp.lq->value) {
+ goto fail;
+ }
+ break;
+ case VIRTIO_SCSI_T_LQ_MAX_SEGMENTS:
+ req->resp.lq->value = get_queue_max_segments(d->conf.bs);
+ if (!req->resp.lq->value) {
+ goto fail;
+ }
+ break;
+ case VIRTIO_SCSI_T_LQ_MAX_SEGMENT_SIZE:
+ req->resp.lq->value = get_queue_max_segment_size(d->conf.bs);
+ if (!req->resp.lq->value) {
+ goto fail;
+ }
+ break;
+ default:
+ goto fail;
+ }
+
+ req->resp.lq->response = VIRTIO_SCSI_S_OK;
+ return;
+fail:
+ req->resp.lq->response = VIRTIO_SCSI_S_FAILURE;
+}
+
static void virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSIReq *req)
{
SCSIDevice *d = virtio_scsi_device_find(s, req->req.tmf->lun);
@@ -414,6 +472,12 @@ static void virtio_scsi_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
}
req->resp.an->event_actual = 0;
req->resp.an->response = VIRTIO_SCSI_S_OK;
+ } else if (req->req.lq->type == VIRTIO_SCSI_T_LUN_QUERY) {
+ if (out_size < sizeof(VirtIOSCSICtrlLQReq) ||
+ in_size < sizeof(VirtIOSCSICtrlLQResp)) {
+ virtio_scsi_bad_req();
+ }
+ virtio_scsi_do_lun_query(s, req);
}
virtio_scsi_complete_req(req);
}
@@ -557,6 +621,7 @@ static uint32_t virtio_scsi_get_features(VirtIODevice *vdev,
{
requested_features |= (1UL << VIRTIO_SCSI_F_HOTPLUG);
requested_features |= (1UL << VIRTIO_SCSI_F_CHANGE);
+ requested_features |= (1UL << VIRTIO_SCSI_F_LUN_QUERY);
return requested_features;
}
--
1.7.7.6
^ permalink raw reply related
* [PATCH v1] virtio-scsi: get and set the queue limits for sg device
From: Cong Meng @ 2012-08-21 8:26 UTC (permalink / raw)
To: Paolo Bonzini
Cc: stefanha, linux-kernel, zwanp, linuxram, qemu-devel,
virtualization, Cong Meng
Each virtio scsi HBA has global request queue limits. But the passthrough
LUNs (scsi-generic) come from different host HBAs may have different request
queue limits. If the guest sends commands that exceed the host limits, the
commands will be rejected by host HAB.
This patch addresses this issue by getting the per-LUN queue limits via the the
newly added virtio control request, then setting them properly.
Signed-off-by: Cong Meng <mc@linux.vnet.ibm.com>
---
drivers/scsi/virtio_scsi.c | 113 +++++++++++++++++++++++++++++++++++++------
include/linux/virtio_scsi.h | 18 +++++++
2 files changed, 116 insertions(+), 15 deletions(-)
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 173cb39..ec5066f 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -35,12 +35,14 @@ struct virtio_scsi_cmd {
struct virtio_scsi_cmd_req cmd;
struct virtio_scsi_ctrl_tmf_req tmf;
struct virtio_scsi_ctrl_an_req an;
+ struct virtio_scsi_ctrl_lq_req lq;
} req;
union {
struct virtio_scsi_cmd_resp cmd;
struct virtio_scsi_ctrl_tmf_resp tmf;
struct virtio_scsi_ctrl_an_resp an;
struct virtio_scsi_event evt;
+ struct virtio_scsi_ctrl_lq_resp lq;
} resp;
} ____cacheline_aligned_in_smp;
@@ -469,6 +471,46 @@ out:
return ret;
}
+static u32 virtscsi_lun_query(struct scsi_device *sdev, u32 *value, u32 subtype)
+{
+ struct Scsi_Host *shost = sdev->host;
+ struct virtio_scsi *vscsi = shost_priv(shost);
+ DECLARE_COMPLETION_ONSTACK(comp);
+ struct virtio_scsi_cmd *cmd;
+ struct virtio_scsi_target_state *tgt = vscsi->tgt[sdev->id];
+ unsigned int ret = VIRTIO_SCSI_S_FAILURE;
+
+ cmd = mempool_alloc(virtscsi_cmd_pool, GFP_ATOMIC);
+ if (!cmd)
+ goto out;
+
+ memset(cmd, 0, sizeof(*cmd));
+ cmd->comp = ∁
+ cmd->req.lq = (struct virtio_scsi_ctrl_lq_req){
+ .type = VIRTIO_SCSI_T_LUN_QUERY,
+ .subtype = subtype,
+ .lun[0] = 1,
+ .lun[1] = sdev->id,
+ .lun[2] = (sdev->lun >> 8) | 0x40,
+ .lun[3] = sdev->lun & 0xff,
+ };
+
+ if (virtscsi_kick_cmd(tgt, &vscsi->ctrl_vq, cmd, sizeof cmd->req.lq,
+ sizeof cmd->resp.lq, GFP_NOIO) < 0) {
+ goto out;
+ }
+
+ wait_for_completion(&comp);
+
+ ret = cmd->resp.lq.response;
+ if (ret == VIRTIO_SCSI_S_OK) {
+ *value = cmd->resp.lq.value;
+ }
+out:
+ mempool_free(cmd, virtscsi_cmd_pool);
+ return ret;
+}
+
static int virtscsi_device_reset(struct scsi_cmnd *sc)
{
struct virtio_scsi *vscsi = shost_priv(sc->device->host);
@@ -516,20 +558,6 @@ static int virtscsi_abort(struct scsi_cmnd *sc)
return virtscsi_tmf(vscsi, cmd);
}
-static struct scsi_host_template virtscsi_host_template = {
- .module = THIS_MODULE,
- .name = "Virtio SCSI HBA",
- .proc_name = "virtio_scsi",
- .queuecommand = virtscsi_queuecommand,
- .this_id = -1,
- .eh_abort_handler = virtscsi_abort,
- .eh_device_reset_handler = virtscsi_device_reset,
-
- .can_queue = 1024,
- .dma_boundary = UINT_MAX,
- .use_clustering = ENABLE_CLUSTERING,
-};
-
#define virtscsi_config_get(vdev, fld) \
({ \
typeof(((struct virtio_scsi_config *)0)->fld) __val; \
@@ -547,6 +575,60 @@ static struct scsi_host_template virtscsi_host_template = {
&__val, sizeof(__val)); \
})
+static u32 virtscsi_max_sectors(struct scsi_device *sdev, u32 *value)
+{
+ return virtscsi_lun_query(sdev, value, VIRTIO_SCSI_T_LQ_MAX_SECTORS);
+}
+
+static u32 virtscsi_max_segments(struct scsi_device *sdev, u32 *value)
+{
+ return virtscsi_lun_query(sdev, value, VIRTIO_SCSI_T_LQ_MAX_SEGMENTS);
+}
+
+static u32 virtscsi_max_segment_size(struct scsi_device *sdev, u32 *value)
+{
+ return virtscsi_lun_query(sdev, value, VIRTIO_SCSI_T_LQ_MAX_SEGMENT_SIZE);
+}
+
+static int virtscsi_slave_alloc(struct scsi_device *sdev)
+{
+ struct Scsi_Host *shost = sdev->host;
+ struct virtio_scsi *vscsi = shost_priv(shost);
+ struct virtio_device *vdev = vscsi->vdev;
+ struct request_queue *q = sdev->request_queue;
+ unsigned int max_sectors, max_segments, max_segment_size;
+
+ if (!virtio_has_feature(vdev, VIRTIO_SCSI_F_LUN_QUERY))
+ goto out;
+
+ if (virtscsi_max_sectors(sdev, &max_sectors) ||
+ virtscsi_max_segments(sdev, &max_segments) ||
+ virtscsi_max_segment_size(sdev, &max_segment_size)) {
+ goto out;
+ }
+
+ blk_queue_max_hw_sectors(q, max_sectors);
+ blk_queue_max_segments(q, max_segments - 2);
+ blk_queue_max_segment_size(q, max_segment_size);
+out:
+ return 0;
+}
+
+static struct scsi_host_template virtscsi_host_template = {
+ .module = THIS_MODULE,
+ .name = "Virtio SCSI HBA",
+ .proc_name = "virtio_scsi",
+ .queuecommand = virtscsi_queuecommand,
+ .slave_alloc = virtscsi_slave_alloc,
+ .this_id = -1,
+ .eh_abort_handler = virtscsi_abort,
+ .eh_device_reset_handler = virtscsi_device_reset,
+
+ .can_queue = 1024,
+ .dma_boundary = UINT_MAX,
+ .use_clustering = ENABLE_CLUSTERING,
+};
+
static void virtscsi_init_vq(struct virtio_scsi_vq *virtscsi_vq,
struct virtqueue *vq)
{
@@ -728,7 +810,8 @@ static struct virtio_device_id id_table[] = {
};
static unsigned int features[] = {
- VIRTIO_SCSI_F_HOTPLUG
+ VIRTIO_SCSI_F_HOTPLUG,
+ VIRTIO_SCSI_F_LUN_QUERY
};
static struct virtio_driver virtio_scsi_driver = {
diff --git a/include/linux/virtio_scsi.h b/include/linux/virtio_scsi.h
index dc8d305..c14c3ee 100644
--- a/include/linux/virtio_scsi.h
+++ b/include/linux/virtio_scsi.h
@@ -50,6 +50,17 @@ struct virtio_scsi_ctrl_an_resp {
u8 response;
} __packed;
+struct virtio_scsi_ctrl_lq_req {
+ u32 type;
+ u8 lun[8];
+ u32 subtype;
+} __packed;
+
+struct virtio_scsi_ctrl_lq_resp {
+ u32 response;
+ u32 value;
+} __packed;
+
struct virtio_scsi_event {
u32 event;
u8 lun[8];
@@ -72,6 +83,7 @@ struct virtio_scsi_config {
/* Feature Bits */
#define VIRTIO_SCSI_F_INOUT 0
#define VIRTIO_SCSI_F_HOTPLUG 1
+#define VIRTIO_SCSI_F_LUN_QUERY 3
/* Response codes */
#define VIRTIO_SCSI_S_OK 0
@@ -92,6 +104,7 @@ struct virtio_scsi_config {
#define VIRTIO_SCSI_T_TMF 0
#define VIRTIO_SCSI_T_AN_QUERY 1
#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
+#define VIRTIO_SCSI_T_LUN_QUERY 3
/* Valid TMF subtypes. */
#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
@@ -103,6 +116,11 @@ struct virtio_scsi_config {
#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
+/* LUN Query */
+#define VIRTIO_SCSI_T_LQ_MAX_SECTORS 0
+#define VIRTIO_SCSI_T_LQ_MAX_SEGMENTS 1
+#define VIRTIO_SCSI_T_LQ_MAX_SEGMENT_SIZE 2
+
/* Events. */
#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
#define VIRTIO_SCSI_T_NO_EVENT 0
--
1.7.7.6
^ permalink raw reply related
* Re: [PATCH 1/2 v1] blkdrv: Add queue limits parameters for sg block drive
From: Paolo Bonzini @ 2012-08-21 8:48 UTC (permalink / raw)
To: Cong Meng; +Cc: stefanha, zwanp, linuxram, qemu-devel, virtualization
In-Reply-To: <1345537427-21601-1-git-send-email-mc@linux.vnet.ibm.com>
Il 21/08/2012 10:23, Cong Meng ha scritto:
> +static void sg_get_queue_limits(BlockDriverState *bs, const char *filename)
> +{
> + DIR *ffs;
> + struct dirent *d;
> + char path[MAXPATHLEN];
> +
> + snprintf(path, MAXPATHLEN,
> + "/sys/class/scsi_generic/sg%s/device/block/",
> + filename + strlen("/dev/sg"));
> +
> + ffs = opendir(path);
> + if (!ffs) {
> + return;
> + }
> +
> + for (;;) {
> + d = readdir(ffs);
> + if (!d) {
> + return;
> + }
> +
> + if (strcmp(d->d_name, ".") == 0 || strcmp(d->d_name, "..") == 0) {
> + continue;
> + }
> +
> + break;
> + }
> +
> + closedir(ffs);
> +
> + pstrcat(path, MAXPATHLEN, d->d_name);
> + pstrcat(path, MAXPATHLEN, "/queue/");
> +
> + read_queue_limit(path, "max_sectors_kb", &bs->max_sectors);
> + read_queue_limit(path, "max_segments", &bs->max_segments);
> + read_queue_limit(path, "max_segment_size", &bs->max_segment_size);
> +}
Using /sys/dev/block or /sys/dev/char seems easier, and lets you
retrieve the parameters for block devices too.
However, I'm worried of the consequences this has for migration. You
could have the same physical disk accessed with two different HBAs, with
different limits. So I don't know if this can really be solved at all.
Paolo
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox