Re: [PATCH V2 6/7] hw/block/nvme: support namespace attachment command

2021-02-26 Thread Minwoo Im
On 21-02-27 02:59:35, Keith Busch wrote:
> On Thu, Feb 11, 2021 at 01:09:36AM +0900, Minwoo Im wrote:
> > @@ -183,6 +183,7 @@ static const uint32_t nvme_cse_acs[256] = {
> >  [NVME_ADM_CMD_SET_FEATURES] = NVME_CMD_EFF_CSUPP,
> >  [NVME_ADM_CMD_GET_FEATURES] = NVME_CMD_EFF_CSUPP,
> >  [NVME_ADM_CMD_ASYNC_EV_REQ] = NVME_CMD_EFF_CSUPP,
> > +[NVME_ADM_CMD_NS_ATTACHMENT]= NVME_CMD_EFF_CSUPP,
> 
> Missing NVME_CMD_EFF_NIC for the attachment command.

Will do that!

> >  };
> >  
> >  static const uint32_t nvme_cse_iocs_none[256];
> > @@ -3766,6 +3767,62 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest 
> > *req)
> >  return NVME_NO_COMPLETE;
> >  }
> >  
> > +static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns);
> > +static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
> > +{
> > +NvmeNamespace *ns;
> > +NvmeCtrl *ctrl;
> > +uint16_t list[NVME_CONTROLLER_LIST_SIZE] = {};
> > +uint32_t nsid = le32_to_cpu(req->cmd.nsid);
> > +uint32_t dw10 = le32_to_cpu(req->cmd.cdw10);
> > +bool attach = !(dw10 & 0xf);
> > +uint16_t *nr_ids = [0];
> > +uint16_t *ids = [1];
> > +uint16_t ret;
> > +int i;
> > +
> > +trace_pci_nvme_ns_attachment(nvme_cid(req), dw10 & 0xf);
> > +
> > +ns = nvme_subsys_ns(n->subsys, nsid);
> > +if (!ns) {
> > +return NVME_INVALID_FIELD | NVME_DNR;
> > +}
> > +
> > +ret = nvme_dma(n, (uint8_t *)list, 4096,
> > +   DMA_DIRECTION_TO_DEVICE, req);
> > +if (ret) {
> > +return ret;
> > +}
> > +
> > +if (!*nr_ids) {
> > +return NVME_NS_CTRL_LIST_INVALID | NVME_DNR;
> > +}
> > +
> > +for (i = 0; i < *nr_ids; i++) {
> > +ctrl = nvme_subsys_ctrl(n->subsys, ids[i]);
> > +if (!ctrl) {
> > +return NVME_NS_CTRL_LIST_INVALID | NVME_DNR;
> > +}
> > +
> > +if (attach) {
> > +if (nvme_ns_is_attached(ctrl, ns)) {
> > +return NVME_NS_ALREADY_ATTACHED | NVME_DNR;
> > +}
> > +
> > +nvme_ns_attach(ctrl, ns);
> > +__nvme_select_ns_iocs(ctrl, ns);
> > +} else {
> > +if (!nvme_ns_is_attached(ctrl, ns)) {
> > +return NVME_NS_NOT_ATTACHED | NVME_DNR;
> > +}
> > +
> > +nvme_ns_detach(ctrl, ns);
> > +}
> > +}
> > +
> > +return NVME_SUCCESS;
> > +}
> 
> Every controller that has newly attached the namespace needs to emit the
> Namespace Notify AER in order for the host to react correctly to the
> command.

Okay. will prepare next series.

Thanks!



Re: [PATCH v2 31/31] qom: Drop QemuOpts based interfaces

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> user_creatable_add_opts() has only a single user left, which is a test
> case. Rewrite the test to use user_creatable_add_type() instead (which
> is the remaining function that doesn't require a QAPI schema) and drop
> the QemuOpts related functions.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  include/qom/object_interfaces.h | 59 
>  qom/object_interfaces.c | 81 -
>  tests/check-qom-proplist.c  | 42 -
>  3 files changed, 20 insertions(+), 162 deletions(-)

Yay!

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 30/31] vl: QAPIfy -object

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This switches the system emulator from a QemuOpts-based parser for
> -object to user_creatable_parse_str() which uses a keyval parser and
> enforces the QAPI schema.
> 
> Apart from being a cleanup, this makes non-scalar properties accessible.
> 
> This adopts a similar model as -blockdev uses: When parsing the option,
> create the ObjectOptions and queue them. At the later point where we
> used to create objects for the collected QemuOpts, the ObjectOptions
> queue is processed instead.
> 
> A complication compared to -blockdev is that object definitions are
> supported in -readconfig and -writeconfig.
> 
> After this patch, -readconfig still works, though it still goes through
> the QemuOpts parser, which means that improvements like non-scalar
> properties are still not available in config files.
> 
> -writeconfig stops working for -object. Tough luck. It has never
> supported all options (not even the common ones), so supporting one less
> isn't the end of the world. As object definitions from -readconfig still
> go through QemuOpts, they are still included in -writeconfig output,
> which at least prevents destroying your existing configuration when you
> just wanted to add another option.

And Paolo has submitted a patch deprecating it.

> 
> Signed-off-by: Kevin Wolf 
> ---
>  softmmu/vl.c | 109 +++
>  1 file changed, 84 insertions(+), 25 deletions(-)
> 
Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 29/31] qom: Add user_creatable_parse_str()

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> The system emulator has a more complicated way of handling command line
> options in that it reorders options before it processes them. This means
> that parsing object options and creating the object happen at two
> different points. Split the parsing part into a separate function that
> can be reused by the system emulator command line.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  include/qom/object_interfaces.h | 15 +++
>  qom/object_interfaces.c | 20 ++--
>  2 files changed, 29 insertions(+), 6 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 28/31] hmp: QAPIfy object_add

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This switches the HMP command object_add from a QemuOpts-based parser to
> user_creatable_add_from_str() which uses a keyval parser and enforces
> the QAPI schema.
> 
> Apart from being a cleanup, this makes non-scalar properties and help
> accessible. In order for help to be printed to the monitor instead of
> stdout, the printf() calls in the help functions are changed to
> qemu_printf().
> 
> Signed-off-by: Kevin Wolf 
> ---
>  monitor/hmp-cmds.c  | 17 ++---
>  qom/object_interfaces.c | 11 ++-
>  hmp-commands.hx |  2 +-
>  3 files changed, 9 insertions(+), 21 deletions(-)
> 
Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 27/31] qom: Add user_creatable_add_from_str()

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This is a version of user_creatable_process_cmdline() with an Error
> parameter that never calls exit() and is therefore usable in HMP.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  include/qom/object_interfaces.h | 16 
>  qom/object_interfaces.c | 29 -
>  2 files changed, 40 insertions(+), 5 deletions(-)
> 

> +/**
> + * user_creatable_add_from_str:
> + * @optarg: the object definition string as passed on the command line
> + * @errp: if an error occurs, a pointer to an area to store the error
> + *
> + * Create an instance of the user creatable object by parsing optarg
> + * with a keyval parser and implicit key 'qom-type', converting the
> + * result to ObjectOptions and calling into qmp_object_add().
> + *
> + * If a help option is given, print help instead.
> + *
> + * Returns: true when an object was successfully created, false when an error
> + * occurred (*errp is set then) or help was printed (*errp is not set).
> + */
> +bool user_creatable_add_from_str(const char *optarg, Error **errp);

This could be used to fix the exit status 2 issue in qemu-img convert,
if you rearrange the series a bit.

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 26/31] qemu-nbd: Use user_creatable_process_cmdline() for --object

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This switches qemu-nbd from a QemuOpts-based parser for --object to
> user_creatable_process_cmdline() which uses a keyval parser and enforces
> the QAPI schema.
> 
> Apart from being a cleanup, this makes non-scalar properties accessible.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qemu-nbd.c | 34 +++---
>  1 file changed, 3 insertions(+), 31 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 25/31] qemu-img: Use user_creatable_process_cmdline() for --object

2021-02-26 Thread Eric Blake
On 2/26/21 3:56 PM, Eric Blake wrote:
> On 2/24/21 7:52 AM, Kevin Wolf wrote:
>> This switches qemu-img from a QemuOpts-based parser for --object to
>> user_creatable_process_cmdline() which uses a keyval parser and enforces
>> the QAPI schema.
>>
>> Apart from being a cleanup, this makes non-scalar properties accessible.
>>
>> Signed-off-by: Kevin Wolf 
>> ---
>>  qemu-img.c | 239 -
>>  1 file changed, 33 insertions(+), 206 deletions(-)
>>
> 
>> @@ -1423,15 +1373,9 @@ static int img_compare(int argc, char **argv)
>>  case 'U':
>>  force_share = true;
>>  break;
>> -case OPTION_OBJECT: {
>> -QemuOpts *opts;
>> -opts = qemu_opts_parse_noisily(_object_opts,
>> -   optarg, true);
>> -if (!opts) {
>> -ret = 2;
>> -goto out4;
> 
> Our exit status here of 2 on failure appears to be intentional (since we
> reserve 0 for identical, 1 for mismatch, >1 for error)...
> 
>> -}
>> -}   break;
>> +case OPTION_OBJECT:
>> +user_creatable_process_cmdline(optarg);
>> +break;
> 
> ...but becomes 1 here.  Does that matter?
> 
> /me goes and tests...
> 
> Ouch: with current qemu.git master and none of this series applied:
> 
> $ ./qemu-img compare --object foo,id=x /dev/null /dev/null
> qemu-img: invalid object type: foo
> $ echo $?
> 1

Okay, that didn't do what I expected, but this does:

$ ./qemu-img compare --object foo,id=1 /dev/null /dev/null
qemu-img: Parameter 'id' expects an identifier
Identifiers consist of letters, digits, '-', '.', '_', starting with a
letter.
$ echo $?
2

> $ gdb --args ./qemu-img compare --object foo,id=x /dev/null /dev/null
> (gdb) b qemu_opts_pars
> (gdb) r
> (gdb) fin
> Run till exit from #0  qemu_opts_parse_noisily (
> list=0x5578f020 , params=0x7fffd8a8
> "foo,id=x",
> permit_abbrev=true) at ../util/qemu-option.c:948
> 0x555805f9 in img_compare (argc=5, argv=0x7fffd480)
> at ../qemu-img.c:1428
> 1428  opts = qemu_opts_parse_noisily(_object_opts,
> Value returned is $1 = (QemuOpts *) 0x5583b4b0
> (gdb) p *opts
> $3 = {id = 0x557a0d58  "`\264\203UUU", list = 0x51,

and this may be my confusion with gdb.  Right after 'fin', *opts is not
the same as *$1 (apparently gdb has stopped at a point where the 'opts'
currently in scope is not the opts set by qemu_opts_parse_noisily, but
before the opts in scope has actually been assigned the returned value).

> 
> That looks buggy.  qemu_opts_parse_noisily() is NOT returning NULL, but
> rather a pointer to something garbage (that id pointing to a garbage
> string in the middle of qemu_trace_opts is fishy), and so we've been
> exiting with status 1 in spite of the code.
> 
> Looks like we'll want a separate patch fixing that first.

So I was wrong on when qemu_opts_parse_noisily() returns NULL - it does
NOT reject unknown object names (that was the job of the
qemu_opts_foreach call later), but merely rejects bad/duplicate ids.
Thus this code was indeed giving an exit status of 2 when actually
triggered correctly,

> 
>>  case OPTION_IMAGE_OPTS:
>>  image_opts = true;
>>  break;
>> @@ -1450,13 +1394,6 @@ static int img_compare(int argc, char **argv)
>>  filename1 = argv[optind++];
>>  filename2 = argv[optind++];
>>  
>> -if (qemu_opts_foreach(_object_opts,
>> -  user_creatable_add_opts_foreach,
>> -  qemu_img_object_print_help, _fatal)) {
>> -ret = 2;
>> -goto out4;
> 
> Same deal with return value.  Except here we used _fatal (which
> forces an exit status of 1 rather than returning), and so never even
> reach the ret=2 code.  Looks like we broke that in commit 334c43e2c3,
> where we used to pass NULL instead of _fatal (although that commit
> was in turn fixing another problem).

...and THIS spot is why my original attempt to prove that your code was
causing a regression was seeing an exit status of 1, where I instead
ended up proving that we already regressed.

> 
> The rest of this patch looks fine, although maybe
> user_creatable_process_cmdline() should be given an 'int status'
> parameter for specifying 1 vs. 2 (or any other non-zero value) if we
> intend to fix the status of qemu-img compare failures.  (Thankfully,
> even though qemu-img check also has a variety of documented return
> values other than 1, at least it documented 1 as internal errors and was
> already using 1 for --object failures).
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 25/31] qemu-img: Use user_creatable_process_cmdline() for --object

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This switches qemu-img from a QemuOpts-based parser for --object to
> user_creatable_process_cmdline() which uses a keyval parser and enforces
> the QAPI schema.
> 
> Apart from being a cleanup, this makes non-scalar properties accessible.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qemu-img.c | 239 -
>  1 file changed, 33 insertions(+), 206 deletions(-)
> 

> @@ -1423,15 +1373,9 @@ static int img_compare(int argc, char **argv)
>  case 'U':
>  force_share = true;
>  break;
> -case OPTION_OBJECT: {
> -QemuOpts *opts;
> -opts = qemu_opts_parse_noisily(_object_opts,
> -   optarg, true);
> -if (!opts) {
> -ret = 2;
> -goto out4;

Our exit status here of 2 on failure appears to be intentional (since we
reserve 0 for identical, 1 for mismatch, >1 for error)...

> -}
> -}   break;
> +case OPTION_OBJECT:
> +user_creatable_process_cmdline(optarg);
> +break;

...but becomes 1 here.  Does that matter?

/me goes and tests...

Ouch: with current qemu.git master and none of this series applied:

$ ./qemu-img compare --object foo,id=x /dev/null /dev/null
qemu-img: invalid object type: foo
$ echo $?
1
$ gdb --args ./qemu-img compare --object foo,id=x /dev/null /dev/null
(gdb) b qemu_opts_pars
(gdb) r
(gdb) fin
Run till exit from #0  qemu_opts_parse_noisily (
list=0x5578f020 , params=0x7fffd8a8
"foo,id=x",
permit_abbrev=true) at ../util/qemu-option.c:948
0x555805f9 in img_compare (argc=5, argv=0x7fffd480)
at ../qemu-img.c:1428
1428opts = qemu_opts_parse_noisily(_object_opts,
Value returned is $1 = (QemuOpts *) 0x5583b4b0
(gdb) p *opts
$3 = {id = 0x557a0d58  "`\264\203UUU", list = 0x51,
  loc = {kind = (unknown: 0x557f08f0), num = 21845,
ptr = 0x5578f020 , prev = 0x0}, head = {
tqh_first = 0x0, tqh_circ = {tql_next = 0x0, tql_prev = 0x0}}, next = {
tqe_next = 0x5583b500, tqe_circ = {tql_next = 0x5583b500,
  tql_prev = 0x5583b528}}}
(gdb)

That looks buggy.  qemu_opts_parse_noisily() is NOT returning NULL, but
rather a pointer to something garbage (that id pointing to a garbage
string in the middle of qemu_trace_opts is fishy), and so we've been
exiting with status 1 in spite of the code.

Looks like we'll want a separate patch fixing that first.

>  case OPTION_IMAGE_OPTS:
>  image_opts = true;
>  break;
> @@ -1450,13 +1394,6 @@ static int img_compare(int argc, char **argv)
>  filename1 = argv[optind++];
>  filename2 = argv[optind++];
>  
> -if (qemu_opts_foreach(_object_opts,
> -  user_creatable_add_opts_foreach,
> -  qemu_img_object_print_help, _fatal)) {
> -ret = 2;
> -goto out4;

Same deal with return value.  Except here we used _fatal (which
forces an exit status of 1 rather than returning), and so never even
reach the ret=2 code.  Looks like we broke that in commit 334c43e2c3,
where we used to pass NULL instead of _fatal (although that commit
was in turn fixing another problem).

The rest of this patch looks fine, although maybe
user_creatable_process_cmdline() should be given an 'int status'
parameter for specifying 1 vs. 2 (or any other non-zero value) if we
intend to fix the status of qemu-img compare failures.  (Thankfully,
even though qemu-img check also has a variety of documented return
values other than 1, at least it documented 1 as internal errors and was
already using 1 for --object failures).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 24/31] qemu-io: Use user_creatable_process_cmdline() for --object

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This switches qemu-io from a QemuOpts-based parser for --object to
> user_creatable_process_cmdline() which uses a keyval parser and enforces
> the QAPI schema.
> 
> Apart from being a cleanup, this makes non-scalar properties accessible.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qemu-io.c | 33 +++--
>  1 file changed, 3 insertions(+), 30 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 23/31] qom: Factor out user_creatable_process_cmdline()

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> The implementation for --object can be shared between
> qemu-storage-daemon and other binaries, so move it into a function in
> qom/object_interfaces.c that is accessible from everywhere.
> 
> This also requires moving the implementation of qmp_object_add() into a
> new user_creatable_add_qapi(), because qom/qom-qmp-cmds.c is not linked
> for tools.
> 
> user_creatable_print_help_from_qdict() can become static now.
> 
> Signed-off-by: Kevin Wolf 
> ---
Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 22/31] qom: Remove user_creatable_add_dict()

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This function is now unused and can be removed.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  include/qom/object_interfaces.h | 18 --
>  qom/object_interfaces.c | 32 
>  2 files changed, 50 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 21/31] qemu-storage-daemon: Implement --object with qmp_object_add()

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This QAPIfies --object and ensures that QMP and the command line option
> behave the same.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  storage-daemon/qemu-storage-daemon.c | 21 ++---
>  1 file changed, 10 insertions(+), 11 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 20/31] qom: Make "object" QemuOptsList optional

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This code is going away anyway, but for a few more commits, we'll be in
> a state where some binaries still use QemuOpts and others don't. If the
> "object" QemuOptsList doesn't even exist, we don't have to remove (or
> fail to remove, and therefore abort) a user creatable object from it.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qom/object_interfaces.c | 7 +--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 19/31] qapi/qom: QAPIfy object-add

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This converts object-add from 'gen': false to the ObjectOptions QAPI
> type. As an immediate benefit, clients can now use QAPI schema
> introspection for user creatable QOM objects.
> 
> It is also the first step towards making the QAPI schema the only
> external interface for the creation of user creatable objects. Once all
> other places (HMP and command lines of the system emulator and all
> tools) go through QAPI, too, some object implementations can be
> simplified because some checks (e.g. that mandatory options are set) are
> already performed by QAPI, and in another step, QOM boilerplate code
> could be generated from the schema.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json| 11 +--
>  include/qom/object_interfaces.h  |  7 ---
>  hw/block/xen-block.c | 16 
>  monitor/misc.c   |  2 --
>  qom/qom-qmp-cmds.c   | 25 +++--
>  storage-daemon/qemu-storage-daemon.c |  2 --
>  6 files changed, 32 insertions(+), 31 deletions(-)
> 
> +++ b/qapi/qom.json
> @@ -839,13 +839,6 @@
>  #
>  # Create a QOM object.
>  #
> -# @qom-type: the class name for the object to be created
> -#
> -# @id: the name of the new object
> -#
> -# Additional arguments depend on qom-type and are passed to the backend
> -# unchanged.
> -#
>  # Returns: Nothing on success
>  #  Error if @qom-type is not a valid class name
>  #
> @@ -859,9 +852,7 @@
>  # <- { "return": {} }
>  #
>  ##
> -{ 'command': 'object-add',
> -  'data': {'qom-type': 'str', 'id': 'str'},
> -  'gen': false } # so we can get the additional arguments
> +{ 'command': 'object-add', 'data': 'ObjectOptions', 'boxed': true }

So much more concise ;)  A grep for TYPE_USER_CREATABLE doesn't seem to
turn up any *_class_init() functions that your earlier patches in the
series missed, so I think you captured an accurate 1:1 mapping.  There
is include/chardev/char.h with the comment about "TODO: eventually use
TYPE_USER_CREATABLE" which may point to the next item to be added to
ObjectOptions, but that's not for this series.

> +++ b/qom/qom-qmp-cmds.c

>  
> -void qmp_object_add(QDict *qdict, QObject **ret_data, Error **errp)
> +void qmp_object_add(ObjectOptions *options, Error **errp)
>  {
> -user_creatable_add_dict(qdict, false, errp);
> +Visitor *v;
> +QObject *qobj;
> +QDict *props;
> +Object *obj;
> +
> +v = qobject_output_visitor_new();
> +visit_type_ObjectOptions(v, NULL, , _abort);
> +visit_complete(v, );
> +visit_free(v);

This part is nice...

> +
> +props = qobject_to(QDict, qobj);
> +qdict_del(props, "qom-type");
> +qdict_del(props, "id");

...while this part makes it seem like we still have more cleanup to come
later.  But hey, progress!

> +
> +v = qobject_input_visitor_new(QOBJECT(props));
> +obj = user_creatable_add_type(ObjectType_str(options->qom_type),
> +  options->id, props, v, errp);
> +object_unref(obj);
> +visit_free(v);
>  }
>  

Once you address Paolo's comment, you can also add

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 18/31] qapi/qom: Add ObjectOptions for x-remote-object

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the x-remote-object
> object.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json | 20 ++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index f8ff322df0..6793342e81 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -641,6 +641,20 @@
>  { 'struct': 'PrManagerHelperProperties',
>'data': { 'path': 'str' } }
>  
> +##
> +# @RemoteObjectProperties:
> +#
> +# Properties for x-remote-object objects.
> +#
> +# @fd: file descriptor name previously passed via 'getfd' command
> +#
> +# @devid: the id of the device to be associated with the file descriptor
> +#
> +# Since: 6.0
> +##
> +{ 'struct': 'RemoteObjectProperties',
> +  'data': { 'fd': 'str', 'devid': 'str' } }
> +

Matches hw/remote/remote-obj.c:remote_object_class_init().

>  ##
>  # @RngProperties:
>  #
> @@ -762,7 +776,8 @@
>  'tls-creds-anon',
>  'tls-creds-psk',
>  'tls-creds-x509',
> -'tls-cipher-suites'
> +'tls-cipher-suites',
> +'x-remote-object'
>] }
>  
>  ##
> @@ -815,7 +830,8 @@
>'tls-creds-anon': 'TlsCredsAnonProperties',
>'tls-creds-psk':  'TlsCredsPskProperties',
>'tls-creds-x509': 'TlsCredsX509Properties',
> -  'tls-cipher-suites':  'TlsCredsProperties'
> +  'tls-cipher-suites':  'TlsCredsProperties',
> +  'x-remote-object':'RemoteObjectProperties'
>} }
>  
>  ##
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 17/31] qapi/qom: Add ObjectOptions for input-*

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the input-* objects.
> 
> ui.json cannot be included in qom.json because the storage daemon can't
> use it, so move GrabToggleKeys to common.json.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/common.json | 12 ++
>  qapi/qom.json| 58 
>  qapi/ui.json | 13 +--
>  3 files changed, 71 insertions(+), 12 deletions(-)
> 

> +##
> +# @InputBarrierProperties:
> +#
> +# Properties for input-barrier objects.
> +#
> +# @name: the screen name as declared in the screens section of barrier.conf
> +#
> +# @server: hostname of the Barrier server (default: "localhost")
> +#
> +# @port: TCP port of the Barrier server (default: "24800")

I can understand this being a string (if non-numeric, it can be treated
as a well-known service name instead), but...

> +#
> +# @x-origin: x coordinate of the leftmost pixel on the guest screen
> +#(default: "0")

...why are these other fields a string instead of an integer?  But you
are just doing faithful translation of what we already have.

Bummer - our naming for this member implies that it is experimental,
which is a misnomer (it is quite stable, when viewed in tandem with
y-origin).  Not your fault.  Would 'origin-x' and 'origin-y' be any
better as new aliases in a followup patch?

> +#
> +# @y-origin: y coordinate of he topmost pixel on the guest screen (default: 
> "0")

"the", long line

> +#
> +# @width: the width of secondary screen in pixels (default: "1920")
> +#
> +# @height: the height of secondary screen in pixels (default: "1080")
> +#
> +# Since: 4.2
> +##
> +{ 'struct': 'InputBarrierProperties',
> +  'data': { 'name': 'str',
> +'*server': 'str',
> +'*port': 'str',
> +'*x-origin': 'str',
> +'*y-origin': 'str',
> +'*width': 'str',
> +'*height': 'str' } }

Matches ui/input-barrier.c:input_barrier_class_init().

> +
> +##
> +# @InputLinuxProperties:
> +#
> +# Properties for input-linux objects.
> +#
> +# @evdev: the path of the host evdev device to use
> +#
> +# @grab_all: if true, grab is toggled for all devices (e.g. both keyboard and
> +#mouse) instead of just one device (default: false)

We have inconsistent naming within this object (see grab-toggle); a good
followup would be an alias for 'grab-all'.

> +#
> +# @repeat: enables auto-repeat events (default: false)
> +#
> +# @grab-toggle: the key or key combination that toggles device grab
> +#   (default: ctrl-ctrl)
> +#
> +# Since: 2.6
> +##
> +{ 'struct': 'InputLinuxProperties',
> +  'data': { 'evdev': 'str',
> +'*grab_all': 'bool',
> +'*repeat': 'bool',
> +'*grab-toggle': 'GrabToggleKeys' } }

matches ui/input-linux.c.

> +
>  ##
>  # @IothreadProperties:
>  #
> @@ -689,6 +743,8 @@
>  'filter-redirector',
>  'filter-replay',
>  'filter-rewriter',
> +'input-barrier',
> +'input-linux',
>  'iothread',
>  'memory-backend-file',
>  'memory-backend-memfd',
> @@ -741,6 +797,8 @@
>'filter-redirector':  'FilterRedirectorProperties',
>'filter-replay':  'NetfilterProperties',
>'filter-rewriter':'FilterRewriterProperties',
> +  'input-barrier':  'InputBarrierProperties',
> +  'input-linux':'InputLinuxProperties',
>'iothread':   'IothreadProperties',
>'memory-backend-file':'MemoryBackendFileProperties',
>'memory-backend-memfd':   'MemoryBackendMemfdProperties',

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 16/31] qapi/qom: Add ObjectOptions for confidential-guest-support

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the objects implementing
> the confidential-guest-support interface.
> 
> pef-guest and s390x-pv-guest don't have any properties, so they only
> need to be added to the ObjectType enum without adding a new branch to
> ObjectOptions.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json | 37 +
>  1 file changed, 37 insertions(+)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index e7184122e9..d5f68b5c89 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -633,6 +633,38 @@
>'base': 'RngProperties',
>'data': { '*filename': 'str' } }
>  
> +##
> +# @SevGuestProperties:
> +#
> +# Properties for sev-guest objects.
> +#
> +# @sev-device: SEV device to use (default: "/dev/sev")
> +#
> +# @dh-cert-file: guest owners DH certificate (encoded with base64)
> +#
> +# @session-file: guest owners session parameters (encoded with base64)

Matches target/i386/sev.c:sev_guest_class_init()...

> +#
> +# @policy: SEV policy value (default: 0x1)
> +#
> +# @handle: SEV firmware handle (default: 0)
> +#
> +# @cbitpos: C-bit location in page table entry (default: 0)
> +#
> +# @reduced-phys-bits: number of bits in physical addresses that become
> +# unavailable when SEV is enabled

...and sev_guest_instance_init().

> +#
> +# Since: 2.12
> +##
> +{ 'struct': 'SevGuestProperties',
> +  'data': { '*sev-device': 'str',
> +'*dh-cert-file': 'str',
> +'*session-file': 'str',
> +'*policy': 'uint32',
> +'*handle': 'uint32',
> +'*cbitpos': 'uint32',
> +'reduced-phys-bits': 'uint32' },
> +  'if': 'defined(CONFIG_SEV)' }
> +
>  ##
>  # @ObjectType:
>  #
> @@ -661,12 +693,15 @@
>  'memory-backend-file',
>  'memory-backend-memfd',
>  'memory-backend-ram',
> +{'name': 'pef-guest', 'if': 'defined(CONFIG_PSERIES)' },
>  'pr-manager-helper',
>  'rng-builtin',
>  'rng-egd',
>  'rng-random',
>  'secret',
>  'secret_keyring',
> +{'name': 'sev-guest', 'if': 'defined(CONFIG_SEV)' },
> +'s390-pv-guest',
>  'throttle-group',
>  'tls-creds-anon',
>  'tls-creds-psk',
> @@ -716,6 +751,8 @@
>'rng-random': 'RngRandomProperties',
>'secret': 'SecretProperties',
>'secret_keyring': 'SecretKeyringProperties',
> +  'sev-guest':  { 'type': 'SevGuestProperties',
> +  'if': 'defined(CONFIG_SEV)' },
>'throttle-group': 'ThrottleGroupProperties',
>'tls-creds-anon': 'TlsCredsAnonProperties',
>'tls-creds-psk':  'TlsCredsPskProperties',
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 15/31] qapi/qom: Add ObjectOptions for pr-manager-helper

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the pr-manager-helper
> object.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json | 14 ++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index e3357f5123..e7184122e9 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -575,6 +575,18 @@
>  '*hugetlbsize': 'size',
>  '*seal': 'bool' } }
>  
> +##
> +# @PrManagerHelperProperties:
> +#
> +# Properties for pr-manager-helper objects.
> +#
> +# @path: the path to a Unix domain socket for connecting to the external 
> helper
> +#
> +# Since: 2.11
> +##
> +{ 'struct': 'PrManagerHelperProperties',
> +  'data': { 'path': 'str' } }
> +

Matches scsi/pr-manager-helper.c:pr_manager_helper_class_init().

>  ##
>  # @RngProperties:
>  #
> @@ -649,6 +661,7 @@
>  'memory-backend-file',
>  'memory-backend-memfd',
>  'memory-backend-ram',
> +'pr-manager-helper',
>  'rng-builtin',
>  'rng-egd',
>  'rng-random',
> @@ -697,6 +710,7 @@
>'memory-backend-file':'MemoryBackendFileProperties',
>'memory-backend-memfd':   'MemoryBackendMemfdProperties',
>'memory-backend-ram': 'MemoryBackendProperties',
> +  'pr-manager-helper':  'PrManagerHelperProperties',
>'rng-builtin':'RngProperties',
>'rng-egd':'RngEgdProperties',
>'rng-random': 'RngRandomProperties',
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 14/31] qapi/qom: Add ObjectOptions for filter-*

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the filter-* objects.
> 
> Some parts of the interface (in particular NetfilterProperties.position)
> are very unusual for QAPI, but for now just describe the existing
> interface.
> 
> net.json can't be included in qom.json because the storage daemon
> doesn't have it. NetFilterDirection is still required in the new object
> property definitions in qom.json, so move this enum to common.json.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/common.json |  20 +++
>  qapi/net.json|  20 ---
>  qapi/qom.json| 143 +++
>  3 files changed, 163 insertions(+), 20 deletions(-)
> 

> +++ b/qapi/qom.json
> @@ -313,6 +313,137 @@
>'data': { 'addr': 'str' ,
>  '*id-list': 'str' } }
>  
> +##
> +# @NetfilterInsert:
> +#
> +# Indicates where to insert a netfilter relative to a given other filter.
> +#
> +# @before: insert before the specified filter
> +#
> +# @behind: insert behind the specified filter
> +#
> +# Since: 5.0
> +##
> +{ 'enum': 'NetfilterInsert',
> +  'data': [ 'before', 'behind' ] }
> +
> +##
> +# @NetfilterProperties:
> +#
> +# Properties for objects of classes derived from netfilter.
> +#
> +# @netdev: id of the network device backend to filter
> +#
> +# @queue: indicates which queue(s) to filter (default: all)
> +#
> +# @status: indicates whether the filter is enabled ("on") or disabled ("off")
> +#  (default: "on")

An enum would be nicer than 'str', but your commit message is accurate.

> +#
> +# @position: specifies where the filter should be inserted in the filter 
> list.
> +#"head" means the filter is inserted at the head of the filter 
> list,
> +#before any existing filters.
> +#"tail" means the filter is inserted at the tail of the filter 
> list,
> +#behind any existing filters (default).
> +#"id=" means the filter is inserted before or behind the 
> filter
> +#specified by , depending on the @insert property.
> +#(default: "tail")
> +#

Wow, you're not kidding about this not being typical QAPI.  Oh well.

> +# @insert: where to insert the filter relative to the filter given in 
> @position.
> +#  Ignored if @position is "head" or "tail". (default: behind)

Back to the question of if it is worth updating the QAPI generator to
allow a flat union as the branch of yet another flat union.  If we did
that, we could have (untested):

{ 'enum': 'NetfilterPosition', 'data': [ 'head', 'tail', 'id' ] }
{ 'union': 'NetfilterBase',
  'base': { 'position': 'NetfilterPosition',
'netdev'..., 'queue', 'status'... },
  'discriminator': 'position',
  'data': { 'head': {}, 'tail': {},
'id': { '*insert': 'NetfilterInsert', 'id': 'str' } }

but that is a change to our existing id=xyz parsing, so we may need an
alias or deprecation period...

> +#
> +# Since: 2.5
> +##
> +{ 'struct': 'NetfilterProperties',
> +  'data': { 'netdev': 'str',
> +'*queue': 'NetFilterDirection',
> +'*status': 'str',
> +'*position': 'str',
> +'*insert': 'NetfilterInsert' } }
> +
> +##
> +# @FilterBufferProperties:
> +#
> +# Properties for filter-buffer objects.
> +#
> +# @interval: a non-zero interval in microseconds.  All packets arriving in 
> the
> +#given interval are delayed until the end of the interval.
> +#
> +# Since: 2.5
> +##
> +{ 'struct': 'FilterBufferProperties',
> +  'base': 'NetfilterProperties',
> +  'data': { 'interval': 'uint32' } }

matches net/filter-buffer.c:filter_buffer_class_init().

> +
> +##
> +# @FilterDumpProperties:
> +#
> +# Properties for filter-dump objects.
> +#
> +# @file: the filename where the dumped packets should be stored
> +#
> +# @maxlen: maximum number of bytes in a packet that are stored (default: 
> 65536)
> +#
> +# Since: 2.5
> +##
> +{ 'struct': 'FilterDumpProperties',
> +  'base': 'NetfilterProperties',
> +  'data': { 'file': 'str',
> +'*maxlen': 'uint32' } }

Matches net/dump.c:filter_dump_class_init().

> +
> +##
> +# @FilterMirrorProperties:
> +#
> +# Properties for filter-mirror objects.
> +#
> +# @outdev: the name of a character device backend to which all incoming 
> packets
> +#  are mirrored
> +#
> +# @vnet_hdr_support: if true, vnet header support is enabled (default: false)
> +#
> +# Since: 2.6
> +##
> +{ 'struct': 'FilterMirrorProperties',
> +  'base': 'NetfilterProperties',
> +  'data': { 'outdev': 'str',
> +'*vnet_hdr_support': 'bool' } }

Matches filter-mirror.c:filter_mirror_class_init().  For the future, can
we rename to vnet-hdr-support?

> +
> +##
> +# @FilterRedirectorProperties:
> +#
> +# Properties for filter-redirector objects.
> +#
> +# At least one of @indev or @outdev must be present.  If both are present, 
> they
> +# must not refer to the same character device backend.
> +#
> +# @indev: the name of 

Re: [PATCH v2 13/31] qapi/qom: Add ObjectOptions for colo-compare

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the colo-compare object.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json | 49 +
>  1 file changed, 49 insertions(+)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 4b1cd4b8dc..8e4414f843 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -222,6 +222,53 @@
>'data': { 'if': 'str',
>  'canbus': 'str' } }
>  
> +##
> +# @ColoCompareProperties:
> +#
> +# Properties for colo-compare objects.
> +#
> +# @primary_in: name of the character device backend to use for the primary
> +#  input (incoming packets are redirected to @outdev)
> +#
> +# @secondary_in: name of the character device backend to use for secondary
> +#input (incoming packets are only compared to the input on
> +#@primary_in and then dropped)
> +#

Idea for future improvement: use aliases to shift over to 'primary-in',
'secondary-in', and so on as our preferred name.  But not for this
patch, which is a mechanical conversion of what exists.

> +# @outdev: name of the character device backend to use for output
> +#
> +# @iothread: name of the iothread to run in
> +#
> +# @notify_dev: name of the character device backend to be used to communicate
> +#  with the remote colo-frame (only for Xen COLO)
> +#
> +# @compare_timeout: the maximum time to hold a packet from @primary_in for
> +#   comparison with an incoming packet on @secondary_in in
> +#   milliseconds (default: 3000)
> +#
> +# @expired_scan_cycle: the interval at which colo-compare checks whether
> +#  packets from @primary have timed out, in milliseconds
> +#  (default: 3000)
> +#
> +# @max_queue_size: the maximum number of packets to keep in the queue for
> +#  comparing with incoming packets from @secondary_in.  If 
> the
> +#  queue is full and addtional packets are received, the
> +#  addtional packets are dropped. (default: 1024)
> +#
> +# @vnet_hdr_support: if true, vnet header support is enabled (default: false)
> +#
> +# Since: 2.8
> +##
> +{ 'struct': 'ColoCompareProperties',
> +  'data': { 'primary_in': 'str',
> +'secondary_in': 'str',
> +'outdev': 'str',
> +'iothread': 'str',
> +'*notify_dev': 'str',
> +'*compare_timeout': 'uint64',
> +'*expired_scan_cycle': 'uint32',
> +'*max_queue_size': 'uint32',
> +'*vnet_hdr_support': 'bool' } }

Matches net/colo-compare.c:colo_compare_init().

> +
>  ##
>  # @CryptodevBackendProperties:
>  #
> @@ -456,6 +503,7 @@
>  'authz-simple',
>  'can-bus',
>  'can-host-socketcan',
> +'colo-compare',
>  'cryptodev-backend',
>  'cryptodev-backend-builtin',
>  'cryptodev-vhost-user',
> @@ -497,6 +545,7 @@
>'authz-pam':  'AuthZPAMProperties',
>'authz-simple':   'AuthZSimpleProperties',
>'can-host-socketcan': 'CanHostSocketcanProperties',
> +  'colo-compare':   'ColoCompareProperties',
>'cryptodev-backend':  'CryptodevBackendProperties',
>'cryptodev-backend-builtin':  'CryptodevBackendProperties',
>'cryptodev-vhost-user':   'CryptodevVhostUserProperties',

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 12/31] qapi/qom: Add ObjectOptions for can-*

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the can-* objects.
> 
> can-bus doesn't have any properties, so it only needs to be added to the
> ObjectType enum without adding a new branch to ObjectOptions.

I somewhat prefer

'can-bus': {},

to make it explicit that we thought about it, but since we allow
defaulted union branches, your approach works too.

> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json | 18 ++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index f22b7aa99b..4b1cd4b8dc 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -207,6 +207,21 @@
>'returns': [ 'ObjectPropertyInfo' ],
>'allow-preconfig': true }
>  
> +##
> +# @CanHostSocketcanProperties:
> +#
> +# Properties for can-host-socketcan objects.
> +#
> +# @if: interface name of the host system CAN bus to connect to
> +#
> +# @canbus: object ID of the can-bus object to connect to the host interface
> +#
> +# Since: 2.12
> +##
> +{ 'struct': 'CanHostSocketcanProperties',
> +  'data': { 'if': 'str',
> +'canbus': 'str' } }
> +

Okay, matches net/can/can_socketcan.c:can_host_socketcan_class_init()
(after chasing down the parent class in
net/can/can_host.c:can_host_class_init() to find "canbus").

>  ##
>  # @CryptodevBackendProperties:
>  #
> @@ -439,6 +454,8 @@
>  'authz-listfile',
>  'authz-pam',
>  'authz-simple',
> +'can-bus',
> +'can-host-socketcan',
>  'cryptodev-backend',
>  'cryptodev-backend-builtin',
>  'cryptodev-vhost-user',
> @@ -479,6 +496,7 @@
>'authz-listfile': 'AuthZListFileProperties',
>'authz-pam':  'AuthZPAMProperties',
>'authz-simple':   'AuthZSimpleProperties',
> +  'can-host-socketcan': 'CanHostSocketcanProperties',
>'cryptodev-backend':  'CryptodevBackendProperties',
>'cryptodev-backend-builtin':  'CryptodevBackendProperties',
>'cryptodev-vhost-user':   'CryptodevVhostUserProperties',
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 11/31] qapi/qom: Add ObjectOptions for tls-*, deprecate 'loaded'

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the tls-* objects.
> 
> The 'loaded' property doesn't seem to make sense as an external
> interface: It is automatically set to true in ucc->complete, and
> explicitly setting it to true earlier just means that additional options
> will be silently ignored.
> 
> In other words, the 'loaded' property is useless. Mark it as deprecated
> in the schema from the start.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/crypto.json | 98 
>  qapi/qom.json| 12 +-
>  2 files changed, 108 insertions(+), 2 deletions(-)
> 
> diff --git a/qapi/crypto.json b/qapi/crypto.json
> index 0fef3de66d..7116ae9a46 100644
> --- a/qapi/crypto.json
> +++ b/qapi/crypto.json
> @@ -442,3 +442,101 @@
>  { 'struct': 'SecretKeyringProperties',
>'base': 'SecretCommonProperties',
>'data': { 'serial': 'int32' } }
> +
> +##
> +# @TlsCredsProperties:
> +#
> +# Properties for objects of classes derived from tls-creds.
> +#
> +# @verify-peer: if true the peer credentials will be verified once the
> +#   handshake is completed.  This is a no-op for anonymous
> +#   credentials. (default: true)
> +#
> +# @dir: the path of the directory that contains the credential files
> +#
> +# @endpoint: whether the QEMU network backend that uses the credentials will 
> be
> +#acting as a client or as a server (default: client)
> +#
> +# @priority: a gnutls priority string as described at
> +#https://gnutls.org/manual/html_node/Priority-Strings.html
> +#
> +# Since: 2.5
> +##
> +{ 'struct': 'TlsCredsProperties',
> +  'data': { '*verify-peer': 'bool',
> +'*dir': 'str',
> +'*endpoint': 'QCryptoTLSCredsEndpoint',
> +'*priority': 'str' } }

Matches crypto/tlscreds.c:qcrypto_tls_creds_class_init().

> +
> +##
> +# @TlsCredsAnonProperties:
> +#
> +# Properties for tls-creds-anon objects.
> +#
> +# @loaded: if true, the credentials are loaded immediately when applying this
> +#  option and will ignore options that are processed later. Don't 
> use;
> +#  only provided for compatibility. (default: false)
> +#
> +# Features:
> +# @deprecated: Member @loaded is deprecated.  Setting true doesn't make 
> sense,
> +#  and false is already the default.
> +#
> +# Since: 2.5
> +##
> +{ 'struct': 'TlsCredsAnonProperties',
> +  'base': 'TlsCredsProperties',
> +  'data': { '*loaded': { 'type': 'bool', 'features': ['deprecated'] } } }

Since we documented that 'verify-peer' is a no-op for this struct, is it
worth altering our type hierarchy to make it explicit, as in:

TlsCredsCommonProperties - dir, endpoint, priority
TlsCredsProperties - TlsCredsCommonProperties + verify-peer
TlsCredsAnonProperties - TlsCredsCommonProperties + loaded
TlsCredsPskProperties - TlsCredsProperties + loaded, username

But even if not, this matches
crypto/tlscredsanon.c:qcrypto_tls_creds_anon_class_init().

> +
> +##
> +# @TlsCredsPskProperties:
> +#
> +# Properties for tls-creds-psk objects.
> +#
> +# @loaded: if true, the credentials are loaded immediately when applying this
> +#  option and will ignore options that are processed later. Don't 
> use;
> +#  only provided for compatibility. (default: false)
> +#
> +# @username: the username which will be sent to the server.  For clients 
> only.
> +#If absent, "qemu" is sent and the property will read back as an
> +#empty string.
> +#
> +# Features:
> +# @deprecated: Member @loaded is deprecated.  Setting true doesn't make 
> sense,
> +#  and false is already the default.
> +#
> +# Since: 3.0
> +##
> +{ 'struct': 'TlsCredsPskProperties',
> +  'base': 'TlsCredsProperties',
> +  'data': { '*loaded': { 'type': 'bool', 'features': ['deprecated'] },
> +'*username': 'str' } }

This matches crypto/tlscredspsk.c:qcrypto_tls_creds_psk_class_init().

Do we want to use QAPI type inheritance to declare a union where
'endpoint' is the union discriminator, and 'username' is only present
for 'endpoint':'client'?  (Hmm, we'd have to improve the QAPI code
generator to allow a flat union as the branch of yet another flat union...)

> +
> +##
> +# @TlsCredsX509Properties:
> +#
> +# Properties for tls-creds-x509 objects.
> +#
> +# @loaded: if true, the credentials are loaded immediately when applying this
> +#  option and will ignore options that are processed later. Don't 
> use;
> +#  only provided for compatibility. (default: false)
> +#
> +# @sanity-check: if true, perform some sanity checks before using the
> +#credentials (default: true)
> +#
> +# @passwordid: For the server-key.pem and client-key.pem files which contain
> +#  sensitive private keys, it is possible to use an encrypted
> +#  version by providing the @passwordid parameter.  This provides
> +#  the ID of a previously 

Re: [PATCH v2 10/31] qapi/qom: Add ObjectOptions for secret*, deprecate 'loaded'

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the secret* objects.
> 
> The 'loaded' property doesn't seem to make sense as an external
> interface: It is automatically set to true in ucc->complete, and
> explicitly setting it to true earlier just means that additional options
> will be silently ignored.
> 
> In other words, the 'loaded' property is useless. Mark it as deprecated
> in the schema from the start.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/crypto.json   | 61 ++
>  qapi/qom.json  |  5 
>  docs/system/deprecated.rst | 11 +++
>  3 files changed, 77 insertions(+)
> 
> diff --git a/qapi/crypto.json b/qapi/crypto.json
> index 2aebe6fa20..0fef3de66d 100644
> --- a/qapi/crypto.json
> +++ b/qapi/crypto.json
> @@ -381,3 +381,64 @@
>'discriminator': 'format',
>'data': {
>'luks': 'QCryptoBlockAmendOptionsLUKS' } }
> +
> +##
> +# @SecretCommonProperties:
> +#
> +# Properties for objects of classes derived from secret-common.
> +#
> +# @loaded: if true, the secret is loaded immediately when applying this 
> option
> +#  and will probably fail when processing the next option. Don't use;
> +#  only provided for compatibility. (default: false)
> +#
> +# @format: the data format that the secret is provided in (default: raw)
> +#
> +# @keyid: the name of another secret that should be used to decrypt the
> +# provided data. If not present, the data is assumed to be 
> unencrypted.
> +#
> +# @iv: the random initialization vector used for encryption of this 
> particular
> +#  secret. Should be a base64 encrypted string of the 16-byte IV. 
> Mandatory
> +#  if @keyid is given. Ignored if @keyid is absent.
> +#
> +# Features:
> +# @deprecated: Member @loaded is deprecated.  Setting true doesn't make 
> sense,
> +#  and false is already the default.
> +#
> +# Since: 2.6
> +##
> +{ 'struct': 'SecretCommonProperties',
> +  'data': { '*loaded': { 'type': 'bool', 'features': ['deprecated'] },
> +'*format': 'QCryptoSecretFormat',
> +'*keyid': 'str',
> +'*iv': 'str' } }

Matches crypto/secret_common.c:qcrypto_secret_class_init(), and I concur
with the deprecation.

> +
> +##
> +# @SecretProperties:
> +#
> +# Properties for secret objects.
> +#
> +# Either @data or @file must be provided, but not both.
> +#
> +# @data: the associated with the secret from
> +#
> +# @file: the filename to load the data associated with the secret from
> +#
> +# Since: 2.6
> +##
> +{ 'struct': 'SecretProperties',
> +  'base': 'SecretCommonProperties',
> +  'data': { '*data': 'str',
> +'*file': 'str' } }

Matches crypto/secret.c:qcrypto_secret_class_init() (ugh, we really do
reuse the same static function name in two different files, but not your
fault)

> +
> +##
> +# @SecretKeyringProperties:
> +#
> +# Properties for secret_keyring objects.
> +#
> +# @serial: serial number that identifies a key to get from the kernel
> +#
> +# Since: 5.1
> +##
> +{ 'struct': 'SecretKeyringProperties',
> +  'base': 'SecretCommonProperties',
> +  'data': { 'serial': 'int32' } }

Matches crypto/secret_keyring.c:qcrypto_secret_keyring_class_init().

> diff --git a/qapi/qom.json b/qapi/qom.json
> index 449dca8ec5..2668ad8369 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -7,6 +7,7 @@
>  { 'include': 'authz.json' }
>  { 'include': 'block-core.json' }
>  { 'include': 'common.json' }
> +{ 'include': 'crypto.json' }
>  
>  ##
>  # = QEMU Object Model (QOM)
> @@ -449,6 +450,8 @@
>  'rng-builtin',
>  'rng-egd',
>  'rng-random',
> +'secret',
> +'secret_keyring',

What is stopping us from naming this 'secret-keyring'?

>  'throttle-group'
>] }
>  
> @@ -483,6 +486,8 @@
>'rng-builtin':'RngProperties',
>'rng-egd':'RngEgdProperties',
>'rng-random': 'RngRandomProperties',
> +  'secret': 'SecretProperties',
> +  'secret_keyring': 'SecretKeyringProperties',
>'throttle-group': 'ThrottleGroupProperties'
>} }
>  
> diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
> index 79991c2893..78b175cb59 100644
> --- a/docs/system/deprecated.rst
> +++ b/docs/system/deprecated.rst
> @@ -155,6 +155,17 @@ other options have been processed.  This will either 
> have no effect (if
>  ``opened`` was the last option) or cause errors.  The property is therefore
>  useless and should not be specified.
>  
> +``loaded`` property of ``secret`` and ``secret_keyring`` objects (since 
> 6.0.0)
> +''
> +
> +The only effect of specifying ``loaded=on`` in the command line or QMP
> +``object-add`` is that the secret is loaded immediately, possibly before all
> +other options have been processed.  This will either have no 

Re: [PATCH V2 6/7] hw/block/nvme: support namespace attachment command

2021-02-26 Thread Keith Busch
On Thu, Feb 11, 2021 at 01:09:36AM +0900, Minwoo Im wrote:
> @@ -183,6 +183,7 @@ static const uint32_t nvme_cse_acs[256] = {
>  [NVME_ADM_CMD_SET_FEATURES] = NVME_CMD_EFF_CSUPP,
>  [NVME_ADM_CMD_GET_FEATURES] = NVME_CMD_EFF_CSUPP,
>  [NVME_ADM_CMD_ASYNC_EV_REQ] = NVME_CMD_EFF_CSUPP,
> +[NVME_ADM_CMD_NS_ATTACHMENT]= NVME_CMD_EFF_CSUPP,

Missing NVME_CMD_EFF_NIC for the attachment command.

>  };
>  
>  static const uint32_t nvme_cse_iocs_none[256];
> @@ -3766,6 +3767,62 @@ static uint16_t nvme_aer(NvmeCtrl *n, NvmeRequest *req)
>  return NVME_NO_COMPLETE;
>  }
>  
> +static void __nvme_select_ns_iocs(NvmeCtrl *n, NvmeNamespace *ns);
> +static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)
> +{
> +NvmeNamespace *ns;
> +NvmeCtrl *ctrl;
> +uint16_t list[NVME_CONTROLLER_LIST_SIZE] = {};
> +uint32_t nsid = le32_to_cpu(req->cmd.nsid);
> +uint32_t dw10 = le32_to_cpu(req->cmd.cdw10);
> +bool attach = !(dw10 & 0xf);
> +uint16_t *nr_ids = [0];
> +uint16_t *ids = [1];
> +uint16_t ret;
> +int i;
> +
> +trace_pci_nvme_ns_attachment(nvme_cid(req), dw10 & 0xf);
> +
> +ns = nvme_subsys_ns(n->subsys, nsid);
> +if (!ns) {
> +return NVME_INVALID_FIELD | NVME_DNR;
> +}
> +
> +ret = nvme_dma(n, (uint8_t *)list, 4096,
> +   DMA_DIRECTION_TO_DEVICE, req);
> +if (ret) {
> +return ret;
> +}
> +
> +if (!*nr_ids) {
> +return NVME_NS_CTRL_LIST_INVALID | NVME_DNR;
> +}
> +
> +for (i = 0; i < *nr_ids; i++) {
> +ctrl = nvme_subsys_ctrl(n->subsys, ids[i]);
> +if (!ctrl) {
> +return NVME_NS_CTRL_LIST_INVALID | NVME_DNR;
> +}
> +
> +if (attach) {
> +if (nvme_ns_is_attached(ctrl, ns)) {
> +return NVME_NS_ALREADY_ATTACHED | NVME_DNR;
> +}
> +
> +nvme_ns_attach(ctrl, ns);
> +__nvme_select_ns_iocs(ctrl, ns);
> +} else {
> +if (!nvme_ns_is_attached(ctrl, ns)) {
> +return NVME_NS_NOT_ATTACHED | NVME_DNR;
> +}
> +
> +nvme_ns_detach(ctrl, ns);
> +}
> +}
> +
> +return NVME_SUCCESS;
> +}

Every controller that has newly attached the namespace needs to emit the
Namespace Notify AER in order for the host to react correctly to the
command.



Re: [PATCH v4 0/8] hw/sh4: Kconfig cleanups

2021-02-26 Thread Philippe Mathieu-Daudé
On 2/22/21 3:15 PM, Philippe Mathieu-Daudé wrote:

> Philippe Mathieu-Daudé (8):
>   hw/sh4: Add missing license
>   hw/sh4: Add missing Kconfig dependency on SH7750 for the R2D board
>   hw/intc: Introduce SH_INTC Kconfig entry
>   hw/char: Introduce SH_SCI Kconfig entry
>   hw/timer: Introduce SH_TIMER Kconfig entry
>   hw/block: Introduce TC58128 eeprom Kconfig entry
>   hw/pci-host: Introduce SH_PCI Kconfig entry
>   hw/sh4: Remove now unused CONFIG_SH4 from Kconfig
> 
>  include/hw/sh4/sh.h   | 31 ---
>  hw/block/tc58128.c| 26 ++
>  hw/{sh4 => pci-host}/sh_pci.c |  0
>  MAINTAINERS   |  6 ++
>  hw/block/Kconfig  |  3 +++
>  hw/block/meson.build  |  2 +-
>  hw/char/Kconfig   |  3 +++
>  hw/char/meson.build   |  2 +-
>  hw/intc/Kconfig   |  3 +++
>  hw/intc/meson.build   |  2 +-
>  hw/pci-host/Kconfig   |  4 
>  hw/pci-host/meson.build   |  1 +
>  hw/sh4/Kconfig| 12 ++--
>  hw/sh4/meson.build|  1 -
>  hw/timer/Kconfig  |  4 
>  hw/timer/meson.build  |  2 +-
>  16 files changed, 88 insertions(+), 14 deletions(-)
>  rename hw/{sh4 => pci-host}/sh_pci.c (100%)

As SH4 is not very active, I'm queuing this and will send a pull
request in a few days.



Re: [PATCH v2 09/31] qapi/qom: Add ObjectOptions for throttle-group

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the throttle-group object.
> 
> The only purpose of the x-* properties is to make the nested options in
> 'limits' available for a command line parser that doesn't support
> structs. Any parser that will use the QAPI schema will supports structs,
> though, so they will not be needed in the schema in the future.
> 
> To keep the conversion straightforward, add them to the schema anyway.
> We can then remove the options and adjust documentation, test cases etc.
> in a separate patch.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/block-core.json | 27 +++
>  qapi/qom.json|  7 +--
>  2 files changed, 32 insertions(+), 2 deletions(-)
> 
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index 9f555d5c1d..a67fa0cc59 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -2504,6 +2504,33 @@
>  '*bps-write-max' : 'int', '*bps-write-max-length' : 'int',
>  '*iops-size' : 'int' } }
>  
> +##
> +# @ThrottleGroupProperties:
> +#
> +# Properties for throttle-group objects.

Corresponds to block/throttle-groups.c:throttle_group_obj_class_init()
with its ThrottleParamInfo struct for the x- fields, and limits as-is.

> +#
> +# The options starting with x- are aliases for the same key without x- in
> +# the @limits object. As indicated by the x- prefix, this is not a stable
> +# interface and may be removed or changed incompatibly in the future. Use
> +# @limits for a supported stable interface.
> +#
> +# @limits: limits to apply for this throttle group

And I did check that qapi/block-core.json:ThrottleLimits has the same
fields as the ThrottleParamInfo x- fields.  All this duplication!  But
we're getting to a state where it will be easier to clean up the cruft.

> +#
> +# Since: 2.11
> +##
> +{ 'struct': 'ThrottleGroupProperties',
> +  'data': { '*limits': 'ThrottleLimits',
> +'*x-iops-total' : 'int', '*x-iops-total-max' : 'int',
> +'*x-iops-total-max-length' : 'int', '*x-iops-read' : 'int',
> +'*x-iops-read-max' : 'int', '*x-iops-read-max-length' : 'int',
> +'*x-iops-write' : 'int', '*x-iops-write-max' : 'int',
> +'*x-iops-write-max-length' : 'int', '*x-bps-total' : 'int',
> +'*x-bps-total-max' : 'int', '*x-bps-total-max-length' : 'int',
> +'*x-bps-read' : 'int', '*x-bps-read-max' : 'int',
> +'*x-bps-read-max-length' : 'int', '*x-bps-write' : 'int',
> +'*x-bps-write-max' : 'int', '*x-bps-write-max-length' : 'int',
> +'*x-iops-size' : 'int' } }
> +
>  ##
>  # @block-stream:
>  #
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 73f28f9608..449dca8ec5 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -5,6 +5,7 @@
>  # See the COPYING file in the top-level directory.
>  
>  { 'include': 'authz.json' }
> +{ 'include': 'block-core.json' }
>  { 'include': 'common.json' }
>  
>  ##
> @@ -447,7 +448,8 @@
>  'memory-backend-ram',
>  'rng-builtin',
>  'rng-egd',
> -'rng-random'
> +'rng-random',
> +'throttle-group'
>] }
>  
>  ##
> @@ -480,7 +482,8 @@
>'memory-backend-ram': 'MemoryBackendProperties',
>'rng-builtin':'RngProperties',
>'rng-egd':'RngEgdProperties',
> -  'rng-random': 'RngRandomProperties'
> +  'rng-random': 'RngRandomProperties',
> +  'throttle-group': 'ThrottleGroupProperties'
>} }
>  
>  ##
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 08/31] qapi/qom: Add ObjectOptions for rng-*, deprecate 'opened'

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the rng-* objects.
> 
> The 'opened' property doesn't seem to make sense as an external
> interface: It is automatically set to true in ucc->complete, and
> explicitly setting it to true earlier just means that trying to set
> additional options will result in an error. After the property has once
> been set to true (i.e. when the object construction has completed), it
> can never be reset to false. In other words, the 'opened' property is
> useless. Mark it as deprecated in the schema from the start.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json  | 56 --
>  docs/system/deprecated.rst |  9 ++
>  2 files changed, 63 insertions(+), 2 deletions(-)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 1a869006a1..73f28f9608 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -380,6 +380,52 @@
>  '*hugetlbsize': 'size',
>  '*seal': 'bool' } }
>  
> +##
> +# @RngProperties:
> +#
> +# Properties for objects of classes derived from rng.
> +#
> +# @opened: if true, the device is opened immediately when applying this 
> option
> +#  and will probably fail when processing the next option. Don't use;
> +#  only provided for compatibility. (default: false)
> +#
> +# Features:
> +# @deprecated: Member @opened is deprecated.  Setting true doesn't make 
> sense,
> +#  and false is already the default.
> +#
> +# Since: 1.3
> +##
> +{ 'struct': 'RngProperties',
> +  'data': { '*opened': { 'type': 'bool', 'features': ['deprecated'] } } }

Matches backends/rng.c:rng_backend_class_init(), and I concur with the
deprecation.

> +
> +##
> +# @RngEgdProperties:
> +#
> +# Properties for rng-egd objects.
> +#
> +# @chardev: the name of a character device backend that provides the 
> connection
> +#   to the RNG daemon
> +#
> +# Since: 1.3
> +##
> +{ 'struct': 'RngEgdProperties',
> +  'base': 'RngProperties',
> +  'data': { 'chardev': 'str' } }

Matches backends/rng-egd.c:rng_egd_class_init().

> +
> +##
> +# @RngRandomProperties:
> +#
> +# Properties for rng-random objects.
> +#
> +# @filename: the filename of the device on the host to obtain entropy from
> +#(default: "/dev/urandom")
> +#
> +# Since: 1.3
> +##
> +{ 'struct': 'RngRandomProperties',
> +  'base': 'RngProperties',
> +  'data': { '*filename': 'str' } }

Matches backends/rng-random.c:rng_random_class_init().

> +
>  ##
>  # @ObjectType:
>  #
> @@ -398,7 +444,10 @@
>  'iothread',
>  'memory-backend-file',
>  'memory-backend-memfd',
> -'memory-backend-ram'
> +'memory-backend-ram',
> +'rng-builtin',
> +'rng-egd',
> +'rng-random'
>] }
>  
>  ##
> @@ -428,7 +477,10 @@
>'iothread':   'IothreadProperties',
>'memory-backend-file':'MemoryBackendFileProperties',
>'memory-backend-memfd':   'MemoryBackendMemfdProperties',
> -  'memory-backend-ram': 'MemoryBackendProperties'
> +  'memory-backend-ram': 'MemoryBackendProperties',
> +  'rng-builtin':'RngProperties',
> +  'rng-egd':'RngEgdProperties',
> +  'rng-random': 'RngRandomProperties'
>} }
>  
>  ##
> diff --git a/docs/system/deprecated.rst b/docs/system/deprecated.rst
> index 00b694e053..79991c2893 100644
> --- a/docs/system/deprecated.rst
> +++ b/docs/system/deprecated.rst
> @@ -146,6 +146,15 @@ library enabled as a cryptography provider.
>  Neither the ``nettle`` library, or the built-in cryptography provider are
>  supported on FIPS enabled hosts.
>  
> +``opened`` property of ``rng-*`` objects (since 6.0.0)
> +''
> +
> +The only effect of specifying ``opened=on`` in the command line or QMP
> +``object-add`` is that the device is opened immediately, possibly before all
> +other options have been processed.  This will either have no effect (if
> +``opened`` was the last option) or cause errors.  The property is therefore
> +useless and should not be specified.

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 07/31] qapi/qom: Add ObjectOptions for memory-backend-*

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the memory-backend-*
> objects.
> 
> HostMemPolicy has to be moved to an include file that can be used by the
> storage daemon, too, because ObjectOptions must be the same in all
> binaries if we don't want to compile the whole code multiple times.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/common.json  |  20 
>  qapi/machine.json |  22 +
>  qapi/qom.json | 118 +-
>  3 files changed, 138 insertions(+), 22 deletions(-)
> 

> +++ b/qapi/qom.json

> +##
> +# @MemoryBackendProperties:
> +#
> +# Properties for objects of classes derived from memory-backend.
> +#
> +# @merge: if true, mark the memory as mergeable (default depends on the 
> machine
> +# type)
> +#
> +# @dump: if true, include the memory in core dumps (default depends on the
> +#machine type)

Interesting choice to flip the description text from its previous
wording, but fine by me:
object_class_property_set_description(oc, "dump",
"Set to 'off' to exclude from core dump");

> +#
> +# @host-nodes: the list of NUMA host nodes to bind the memory to
> +#
> +# @policy: the NUMA policy (default: 'default')
> +#
> +# @prealloc: if true, preallocate memory (default: false)

Not quite in the same order as
backends/hostmem.c:host_memory_backend_class_init() (alphabetic here
instead of matching the C code declaration order), but that doesn't
impact QMP semantics, and I was able to match everything up in the end.

> +#
> +# @prealloc-threads: number of CPU threads to use for prealloc (default: 1)
> +#
> +# @share: if false, the memory is private to QEMU; if true, it is shared
> +# (default: false)
> +#
> +# @size: size of the memory region in bytes
> +#
> +# @x-use-canonical-path-for-ramblock-id: if true, the canoncial path is used
> +#for ramblock-id. Disable this for 
> 4.0
> +#machine types or older to allow
> +#migration with newer QEMU versions.
> +#(default: false generally, but true
> +#for machine types <= 4.0)

The comment in the C code mentions that in spite of the x- prefix, we
have to treat this as a stable interface until 4.0 machines disappear.
Do we need any of that sentiment in the documentation here?

> +#
> +# Since: 2.1
> +##
> +{ 'struct': 'MemoryBackendProperties',
> +  'data': { '*dump': 'bool',
> +'*host-nodes': ['uint16'],
> +'*merge': 'bool',
> +'*policy': 'HostMemPolicy',
> +'*prealloc': 'bool',
> +'*prealloc-threads': 'uint32',
> +'*share': 'bool',
> +'size': 'size',
> +'*x-use-canonical-path-for-ramblock-id': 'bool' } }
> +
> +##
> +# @MemoryBackendFileProperties:
> +#
> +# Properties for memory-backend-file objects.
> +#
> +# @align: the base address alignment when QEMU mmap(2) @mem-path. Some
> +# backend store specified by @mem-path requires an alignment 
> different

Grammar feels off.  Would it read better as

...when QEMU mmap(2)s @mem-path.  Some backend stores specified by
@mem-path require an...

> +# than the default one used by QEMU, e.g. the device DAX /dev/dax0.0
> +# requires 2M alignment rather than 4K. In such cases, users can
> +# specify the required alignment via this option.
> +# 0 selects a default alignment (currently the page size). (default: 
> 0)

Again, not in the same order as
backends/hostmem-file.c:file_backend_class_init(), but it matches up.

> +#
> +# @discard-data: if true, the file contents can be destroyed when QEMU exits,
> +#to avoid unnecessarily flushing data to the backing file. 
> Note
> +#that ``discard-data`` is only an optimization, and QEMU 
> might
> +#not discard file contents if it aborts unexpectedly or is
> +#terminated using SIGKILL. (default: false)
> +#
> +# @mem-path: the path to either a shared memory or huge page filesystem mount
> +#
> +# @pmem: specifies whether the backing file specified by @mem-path is in
> +#host persistent memory that can be accessed using the SNIA NVM
> +#programming model (e.g. Intel NVDIMM).
> +#
> +# @readonly: if true, the backing file is opened read-only; if false, it is
> +#opened read-write. (default: false)
> +#
> +# Since: 2.1
> +##
> +{ 'struct': 'MemoryBackendFileProperties',
> +  'base': 'MemoryBackendProperties',
> +  'data': { '*align': 'size',
> +'*discard-data': 'bool',
> +'mem-path': 'str',
> +'*pmem': 'bool',

To match the C code, this should be
 '*pmem': { 'type':'bool', 'if':'defined(CONFIG_LIBPMEM)' },

> +'*readonly': 'bool' } }
> +
> +##
> +# @MemoryBackendMemfdProperties:
> 

Re: [PATCH v2 06/31] qapi/qom: Add ObjectOptions for dbus-vmstate

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the dbus-vmstate object.
> 
> A list represented as a comma separated string is clearly not very
> QAPI-like, but for now just describe the existing interface.

Does your alias proposal give us a path forward for improving that down
the road?  Or maybe it's not an alias we need, but a new field with
better QAPI-like semantics, deprecate the old one, and wait out the 2
release cycles?

> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json | 18 ++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 1dbc95fb53..a6a5049707 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -232,6 +232,22 @@
>'base': 'CryptodevBackendProperties',
>'data': { 'chardev': 'str' } }
>  
> +##
> +# @DBusVMStateProperties:
> +#
> +# Properties for dbus-vmstate objects.
> +#
> +# @addr: the name of the DBus bus to connect to
> +#
> +# @id-list: a comma separated list of DBus IDs of helpers whose data should 
> be
> +#   included in the VM state on migration
> +#
> +# Since: 5.0
> +##
> +{ 'struct': 'DBusVMStateProperties',
> +  'data': { 'addr': 'str' ,
> +'*id-list': 'str' } }

Matches backends/dbus-vmstate.c:dbus_vmstate_class_init(), including
splitting id-list into a GHashTable with get_id_list_set().

Since there is benefit to documenting/converting our existing API in
this series without dragging it out by also trying to fix the warts,

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 05/31] qapi/qom: Add ObjectOptions for cryptodev-*

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the cryptodev-* objects.
> 
> These interfaces have some questionable aspects (cryptodev-backend is
> really an abstract base class without function, and the queues option
> only makes sense for cryptodev-vhost-user), but as the goal is to
> represent the existing interface in QAPI, leave these things in place.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/qom.json | 34 ++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/qapi/qom.json b/qapi/qom.json
> index 30ed179bc1..1dbc95fb53 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -204,6 +204,34 @@
>'returns': [ 'ObjectPropertyInfo' ],
>'allow-preconfig': true }
>  
> +##
> +# @CryptodevBackendProperties:
> +#
> +# Properties for cryptodev-backend and cryptodev-backend-builtin objects.
> +#
> +# @queues: the number of queues for the cryptodev backend. Ignored for
> +#  cryptodev-backend and must be 1 for cryptodev-backend-builtin.
> +#  (default: 1)
> +#
> +# Since: 2.8
> +##
> +{ 'struct': 'CryptodevBackendProperties',
> +  'data': { '*queues': 'uint32' } }

Matches backend/cryptodev.c:cryptodev_backend_class_init() and
backend/cryptodev-builtin.c:cryptodev_builtin_class_init().

> +
> +##
> +# @CryptodevVhostUserProperties:
> +#
> +# Properties for cryptodev-vhost-user objects.
> +#
> +# @chardev: the name of a unix domain socket character device that connects 
> to

Should that b s/unix/Unix/ ?

> +#   the vhost-user server
> +#
> +# Since: 2.12
> +##
> +{ 'struct': 'CryptodevVhostUserProperties',
> +  'base': 'CryptodevBackendProperties',
> +  'data': { 'chardev': 'str' } }

Matches backend/cryptodev-vhost-user.c:cryptodev_vhost_user_init_class().

> +
>  ##
>  # @IothreadProperties:
>  #
> @@ -239,6 +267,9 @@
>  'authz-listfile',
>  'authz-pam',
>  'authz-simple',
> +'cryptodev-backend',
> +'cryptodev-backend-builtin',
> +'cryptodev-vhost-user',
>  'iothread'
>] }
>  
> @@ -262,6 +293,9 @@
>'authz-listfile': 'AuthZListFileProperties',
>'authz-pam':  'AuthZPAMProperties',
>'authz-simple':   'AuthZSimpleProperties',
> +  'cryptodev-backend':  'CryptodevBackendProperties',
> +  'cryptodev-backend-builtin':  'CryptodevBackendProperties',
> +  'cryptodev-vhost-user':   'CryptodevVhostUserProperties',
>'iothread':   'IothreadProperties'
>} }
>  
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH v2 04/31] qapi/qom: Add ObjectOptions for authz-*

2021-02-26 Thread Eric Blake
On 2/24/21 7:52 AM, Kevin Wolf wrote:
> This adds a QAPI schema for the properties of the authz-* objects.
> 
> Signed-off-by: Kevin Wolf 
> ---
>  qapi/authz.json  | 62 
>  qapi/qom.json| 10 +
>  storage-daemon/qapi/qapi-schema.json |  1 +
>  3 files changed, 73 insertions(+)
> 
> diff --git a/qapi/authz.json b/qapi/authz.json
> index 42afe752d1..99d49aa563 100644
> --- a/qapi/authz.json
> +++ b/qapi/authz.json
> @@ -59,3 +59,65 @@
>  ##
>  { 'struct': 'QAuthZListRuleListHack',
>'data': { 'unused': ['QAuthZListRule'] } }

This hack is no longer necessary...

> +
> +##
> +# @AuthZListProperties:
> +#
> +# Properties for authz-list objects.
> +#
> +# @policy: Default policy to apply when no rule matches (default: deny)
> +#
> +# @rules: Authorization rules based on matching user
> +#
> +# Since: 4.0
> +##
> +{ 'struct': 'AuthZListProperties',
> +  'data': { '*policy': 'QAuthZListPolicy',
> +'*rules': ['QAuthZListRule'] } }

...now that we have a real type using the same array and forcing the
QAPI generator to instantiate it.

Matches authz/list.c:qauthz_list_class_init().

> +
> +##
> +# @AuthZListFileProperties:
> +#
> +# Properties for authz-listfile objects.
> +#
> +# @filename: File name to load the configuration from. The file must
> +#contain valid JSON for AuthZListProperties.
> +#
> +# @refresh: If true, inotify is used to monitor the file, automatically
> +#   reloading changes. If an error occurs during reloading, all
> +#   authorizations will fail until the file is next successfully
> +#   loaded. (default: true if the binary was built with
> +#   CONFIG_INOTIFY1, false otherwise)
> +#
> +# Since: 4.0
> +##
> +{ 'struct': 'AuthZListFileProperties',
> +  'data': { 'filename': 'str',
> +'*refresh': 'bool' } }

Matches authz/listfile.c:qauthz_list_file_class_init().

> +
> +##
> +# @AuthZPAMProperties:
> +#
> +# Properties for authz-pam objects.
> +#
> +# @service: PAM service name to use for authorization
> +#
> +# Since: 4.0
> +##
> +{ 'struct': 'AuthZPAMProperties',
> +  'data': { 'service': 'str' } }

Matches authz/pamacct.c:qauthz_pam_class_init().

> +
> +##
> +# @AuthZSimpleProperties:
> +#
> +# Properties for authz-simple objects.
> +#
> +# @identity: Identifies the allowed user. Its format depends on the network
> +#service that authorization object is associated with. For
> +#authorizing based on TLS x509 certificates, the identity must be
> +#the x509 distinguished name.
> +#
> +# Since: 4.0
> +##
> +{ 'struct': 'AuthZSimpleProperties',
> +  'data': { 'identity': 'str' } }

Matches authz/simple.c:qauthz_simple_class_init().

> diff --git a/qapi/qom.json b/qapi/qom.json
> index bf2ecb34be..30ed179bc1 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -4,6 +4,8 @@
>  # This work is licensed under the terms of the GNU GPL, version 2 or later.
>  # See the COPYING file in the top-level directory.
>  
> +{ 'include': 'authz.json' }
> +
>  ##
>  # = QEMU Object Model (QOM)
>  ##
> @@ -233,6 +235,10 @@
>  ##
>  { 'enum': 'ObjectType',
>'data': [
> +'authz-list',
> +'authz-listfile',
> +'authz-pam',
> +'authz-simple',
>  'iothread'
>] }
>  
> @@ -252,6 +258,10 @@
>  'id': 'str' },
>'discriminator': 'qom-type',
>'data': {
> +  'authz-list': 'AuthZListProperties',
> +  'authz-listfile': 'AuthZListFileProperties',
> +  'authz-pam':  'AuthZPAMProperties',
> +  'authz-simple':   'AuthZSimpleProperties',
>'iothread':   'IothreadProperties'
>} }
>  
> diff --git a/storage-daemon/qapi/qapi-schema.json 
> b/storage-daemon/qapi/qapi-schema.json
> index 28117c3aac..67749d1101 100644
> --- a/storage-daemon/qapi/qapi-schema.json
> +++ b/storage-daemon/qapi/qapi-schema.json
> @@ -26,6 +26,7 @@
>  { 'include': '../../qapi/crypto.json' }
>  { 'include': '../../qapi/introspect.json' }
>  { 'include': '../../qapi/job.json' }
> +{ 'include': '../../qapi/authz.json' }
>  { 'include': '../../qapi/qom.json' }
>  { 'include': '../../qapi/sockets.json' }
>  { 'include': '../../qapi/transaction.json' }
> 

Once you delete the dead QAPI hack,
Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH] storage-daemon: include current command line option in the errors

2021-02-26 Thread Eric Blake
On 2/26/21 5:03 AM, Paolo Bonzini wrote:
> Use the location management facilities that the emulator uses, so that
> the current command line option appears in the error message.
> 
> Before:
> 
>   $ storage-daemon/qemu-storage-daemon --nbd key..=
>   qemu-storage-daemon: Invalid parameter 'key..'
> 
> After:
> 
>   $ storage-daemon/qemu-storage-daemon --nbd key..=
>   qemu-storage-daemon: --nbd key..=: Invalid parameter 'key..'
> 
> Signed-off-by: Paolo Bonzini 
> ---
>  storage-daemon/qemu-storage-daemon.c | 17 -
>  1 file changed, 16 insertions(+), 1 deletion(-)
> 

Reviewed-by: Eric Blake 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.   +1-919-301-3226
Virtualization:  qemu.org | libvirt.org




Re: [PATCH 2/2] hw/block/nvme: add 'nvme_ana_inject_state' HMP command

2021-02-26 Thread Minwoo Im
On 21-02-14 20:24:00, Minwoo Im wrote:
> Human Monitor Interface(HMP) is there for easy human debugging.  This
> patch added a HMP command 'nvme_ana_inject_state'.  This can be executed
> from the QEMU monitor.  This command will have the following syntax:
> 
>   # nvme_ana_inject_state   
>   (qemu) nvme_ana_inject_state nvme0 1 inaccessible
> 
> The example above will make ANA group #1 transitioned to
> ANA_INACCESSIBLE state for `nvme0` controller device.  Additionally,
> device will notify to the host that ANA has been changed via
> Asynchronous Event Notifier(AEN).  Then the host will figure out another
> path to I/O for the namespace by reading the log page for ANA
> information again, and this is what we call the multipath I/O.
> 
> This feature is good to debug the host multipath I/O by controlling the
> device ANA group state transition.  The path-related errors can be
> tested and debugged by this feature.  Also, the HMP command interafce
> will make us not to build QEMU itself again to control things in device.
> 
> This interface supports Persistent Loss state transition, but it's not
> going to be persistent: volatile of qemu perspective.
> 
> Cc: Dr . David Alan Gilbert 
> Signed-off-by: Minwoo Im 

Hello Keith,

Do you have any comments about this injection method?  As discussed
ealier, I've tried to introduce a natural way to control some of device
status like ANA state which device can behave properly.

It would be great if I can have your feedback on this :)

Thanks!



Re: [PATCH V2 0/6] hw/block/nvme: support namespace attachment

2021-02-26 Thread Minwoo Im
On 21-02-11 01:09:30, Minwoo Im wrote:
> Hello,
> 
> This series supports namespace attachment: attach and detach.  This is
> the second version series with a fix a bug on choosing a controller to
> attach for a namespace in the attach command handler.

Keith,

Could you please have a look at this series and give some comments :) ?



Re: block/throttle and burst bucket

2021-02-26 Thread Peter Lieven
Am 26.02.21 um 10:27 schrieb Alberto Garcia:
> On Thu 25 Feb 2021 06:34:48 PM CET, Peter Lieven  wrote:
>> I was wondering if there is a way to check from outside (qmp etc.) if
>> a throttled block device has exceeded the iops_max_length seconds of
>> time bursting up to iops_max and is now hard limited to the iops limit
>> that is supplied?
>>
>> Would it be also a good idea to exetend the accounting to account for
>> requests that must have waited before being sent out to the backend
>> device?
> No, there's no such interface as far as I'm aware. I think one problem
> is that throttling is now done using a filter, that can be inserted
> anywhere in the node graph, and accounting is done at the BlockBackend
> level.
>
> We don't even have a query-block-throttle function. I actually started
> to write one six years ago but it was never finished.


A quick idea that came to my mind was to add an option to emit a QMP event if 
the burst_bucket is exhausted

and hard limits are enforced.


There seems to be something wrong in the throttling code anyway. Throttling 
causes addtional i/o latency always even if

the actual iops rate is far away from the limits and ever more far away from 
the burst limits. I will dig into this.


My wishlist:

 - have a possibility to query the throttling state.

 - have counters for no of delayed ops and for how long they were delayed.

 - have counters for untrottled <= 4k request performance for a backend storage 
device.


The later two seem not trivial as you mentioned.


Peter






Re: [RFC PATCH v2 3/4] block: Support multiple reopening with x-blockdev-reopen

2021-02-26 Thread Alberto Garcia
On Wed 24 Feb 2021 01:33:05 PM CET, Kevin Wolf  wrote:
>> >   { 'command': 'x-blockdev-reopen',
>> > -  'data': 'BlockdevOptions', 'boxed': true }
>> > +  'data': { 'options': ['BlockdevOptions'] } }
>> 
>> Do we also want to drop x- prefix?
>
> libvirt really wants to have a stable blockdev-reopen interface in 6.0
> because enabling the incremental backup code depends on this (they
> just toggle the readonly flag if I understand correctly, so most of
> the work we're currently doing isn't even relevant at this moment for
> libvirt).
>
> Given that the soft freeze is coming closer (March 16), I wonder if we
> should just make this API change and declare the interface stable. We
> can then make Vladimir's fixes and the file reopening on top of it -
> if it's in time for 6.0, that would be good, but if not we could move
> it to 6.1 without impacting libvirt.

I expect to publish the new version of my patches next week, although
they still apply on top of Vladimir's code, which is not rebased.

We can of course simply update the API and implement the functionality
later, but apart from dropping the prefix we would also be changing the
parameters so qmp_x_blockdev_reopen() would also need to be modified.

Berto



Re: [PATCH v2 19/31] qapi/qom: QAPIfy object-add

2021-02-26 Thread Paolo Bonzini

On 24/02/21 14:52, Kevin Wolf wrote:

+v = qobject_output_visitor_new();
+visit_type_ObjectOptions(v, NULL, , _abort);
+visit_complete(v, );
+visit_free(v);
+
+props = qobject_to(QDict, qobj);
+qdict_del(props, "qom-type");
+qdict_del(props, "id");
+
+v = qobject_input_visitor_new(QOBJECT(props));
+obj = user_creatable_add_type(ObjectType_str(options->qom_type),
+  options->id, props, v, errp);
+object_unref(obj);


Please add a check in object_property_add_child that the id is well 
formed (using the id_wellformed function).  This is pre-existing, but it 
becomes a regression for -object later in the series.


Thanks,

Paolo




[PATCH] storage-daemon: include current command line option in the errors

2021-02-26 Thread Paolo Bonzini
Use the location management facilities that the emulator uses, so that
the current command line option appears in the error message.

Before:

  $ storage-daemon/qemu-storage-daemon --nbd key..=
  qemu-storage-daemon: Invalid parameter 'key..'

After:

  $ storage-daemon/qemu-storage-daemon --nbd key..=
  qemu-storage-daemon: --nbd key..=: Invalid parameter 'key..'

Signed-off-by: Paolo Bonzini 
---
 storage-daemon/qemu-storage-daemon.c | 17 -
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/storage-daemon/qemu-storage-daemon.c 
b/storage-daemon/qemu-storage-daemon.c
index 9021a46b3a..a8f8d83f6f 100644
--- a/storage-daemon/qemu-storage-daemon.c
+++ b/storage-daemon/qemu-storage-daemon.c
@@ -152,6 +152,20 @@ static void init_qmp_commands(void)
  qmp_marshal_qmp_capabilities, QCO_ALLOW_PRECONFIG);
 }
 
+static int getopt_set_loc(int argc, char **argv, const char *optstring,
+  const struct option *longopts)
+{
+int c, save_index;
+
+optarg = NULL;
+save_index = optind;
+c = getopt_long(argc, argv, optstring, longopts, NULL);
+if (optarg) {
+loc_set_cmdline(argv, save_index, MAX(1, optind - save_index));
+}
+return c;
+}
+
 static void process_options(int argc, char *argv[])
 {
 int c;
@@ -174,7 +188,7 @@ static void process_options(int argc, char *argv[])
  * they are given on the command lines. This means that things must be
  * defined first before they can be referenced in another option.
  */
-while ((c = getopt_long(argc, argv, "hT:V", long_options, NULL)) != -1) {
+while ((c = getopt_set_loc(argc, argv, "hT:V", long_options)) != -1) {
 switch (c) {
 case '?':
 exit(EXIT_FAILURE);
@@ -283,6 +297,7 @@ static void process_options(int argc, char *argv[])
 error_report("Unexpected argument: %s", argv[optind]);
 exit(EXIT_FAILURE);
 }
+loc_set_none();
 }
 
 int main(int argc, char *argv[])
-- 
2.26.2




Re: block/throttle and burst bucket

2021-02-26 Thread Alberto Garcia
On Thu 25 Feb 2021 06:34:48 PM CET, Peter Lieven  wrote:
> I was wondering if there is a way to check from outside (qmp etc.) if
> a throttled block device has exceeded the iops_max_length seconds of
> time bursting up to iops_max and is now hard limited to the iops limit
> that is supplied?
>
> Would it be also a good idea to exetend the accounting to account for
> requests that must have waited before being sent out to the backend
> device?

No, there's no such interface as far as I'm aware. I think one problem
is that throttling is now done using a filter, that can be inserted
anywhere in the node graph, and accounting is done at the BlockBackend
level.

We don't even have a query-block-throttle function. I actually started
to write one six years ago but it was never finished.

Berto



Re: [PATCH v2 4/6] parallels: support bitmap extension for read-only mode

2021-02-26 Thread Denis V. Lunev
On 2/24/21 1:47 PM, Vladimir Sementsov-Ogievskiy wrote:
> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> ---
>  block/parallels.h |   6 +-
>  block/parallels-ext.c | 300 ++
>  block/parallels.c |  18 +++
>  block/meson.build |   3 +-
>  4 files changed, 325 insertions(+), 2 deletions(-)
>  create mode 100644 block/parallels-ext.c
>
> diff --git a/block/parallels.h b/block/parallels.h
> index 9a9209e320..f22f43f988 100644
> --- a/block/parallels.h
> +++ b/block/parallels.h
> @@ -48,7 +48,8 @@ typedef struct ParallelsHeader {
>  uint64_t nb_sectors;
>  uint32_t inuse;
>  uint32_t data_off;
> -char padding[12];
> +uint32_t flags;
> +uint64_t ext_off;
>  } QEMU_PACKED ParallelsHeader;
>  
>  typedef enum ParallelsPreallocMode {
> @@ -85,4 +86,7 @@ typedef struct BDRVParallelsState {
>  Error *migration_blocker;
>  } BDRVParallelsState;
>  
> +int parallels_read_format_extension(BlockDriverState *bs,
> +int64_t ext_off, Error **errp);
> +
>  #endif
> diff --git a/block/parallels-ext.c b/block/parallels-ext.c
> new file mode 100644
> index 00..e0dd0975c6
> --- /dev/null
> +++ b/block/parallels-ext.c
> @@ -0,0 +1,300 @@
> +/*
> + * Support of Parallels Format Extension. It's a part of Parallels format
> + * driver.
> + *
> + * Copyright (c) 2021 Virtuozzo International GmbH
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a 
> copy
> + * of this software and associated documentation files (the "Software"), to 
> deal
> + * in the Software without restriction, including without limitation the 
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "block/block_int.h"
> +#include "parallels.h"
> +#include "crypto/hash.h"
> +#include "qemu/uuid.h"
> +
> +#define PARALLELS_FORMAT_EXTENSION_MAGIC 0xAB234CEF23DCEA87ULL
> +
> +#define PARALLELS_END_OF_FEATURES_MAGIC 0x0ULL
> +#define PARALLELS_DIRTY_BITMAP_FEATURE_MAGIC 0x20385FAE252CB34AULL
> +
> +typedef struct ParallelsFormatExtensionHeader {
> +uint64_t magic; /* PARALLELS_FORMAT_EXTENSION_MAGIC */
> +uint8_t check_sum[16];
> +} QEMU_PACKED ParallelsFormatExtensionHeader;
> +
> +typedef struct ParallelsFeatureHeader {
> +uint64_t magic;
> +uint64_t flags;
> +uint32_t data_size;
> +uint32_t _unused;
> +} QEMU_PACKED ParallelsFeatureHeader;
> +
> +typedef struct ParallelsDirtyBitmapFeature {
> +uint64_t size;
> +uint8_t id[16];
> +uint32_t granularity;
> +uint32_t l1_size;
> +/* L1 table follows */
> +} QEMU_PACKED ParallelsDirtyBitmapFeature;
> +
> +/* Given L1 table read bitmap data from the image and populate @bitmap */
> +static int parallels_load_bitmap_data(BlockDriverState *bs,
> +  const uint64_t *l1_table,
> +  uint32_t l1_size,
> +  BdrvDirtyBitmap *bitmap,
> +  Error **errp)
> +{
> +BDRVParallelsState *s = bs->opaque;
> +int ret = 0;
> +uint64_t offset, limit;
> +uint64_t bm_size = bdrv_dirty_bitmap_size(bitmap);
> +uint8_t *buf = NULL;
> +uint64_t i, tab_size =
> +DIV_ROUND_UP(bdrv_dirty_bitmap_serialization_size(bitmap, 0, 
> bm_size),
> + s->cluster_size);
> +
> +if (tab_size != l1_size) {
> +error_setg(errp, "Bitmap table size %" PRIu32 " does not correspond "
> +   "to bitmap size and cluster size. Expected %" PRIu64,
> +   l1_size, tab_size);
> +return -EINVAL;
> +}
> +
> +buf = qemu_blockalign(bs, s->cluster_size);
> +limit = bdrv_dirty_bitmap_serialization_coverage(s->cluster_size, 
> bitmap);
> +for (i = 0, offset = 0; i < tab_size; ++i, offset += limit) {
> +uint64_t count = MIN(bm_size - offset, limit);
> +uint64_t entry = l1_table[i];
> +
> +if (entry == 0) {
> +/* No need to deserialize zeros because @bitmap is cleared. */
> +continue;
> +}
> 

Re: [PATCH v2 6/6] iotests: add parallels-read-bitmap test

2021-02-26 Thread Denis V. Lunev
On 2/24/21 1:47 PM, Vladimir Sementsov-Ogievskiy wrote:
> Test support for reading bitmap from parallels image format.
> parallels-with-bitmap.bz2 is generated on Virtuozzo by
> parallels-with-bitmap.sh
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy 
> ---
>  .../sample_images/parallels-with-bitmap.bz2   | Bin 0 -> 203 bytes
>  .../sample_images/parallels-with-bitmap.sh|  51 
>  .../qemu-iotests/tests/parallels-read-bitmap  |  55 ++
>  .../tests/parallels-read-bitmap.out   |   6 ++
>  4 files changed, 112 insertions(+)
>  create mode 100644 tests/qemu-iotests/sample_images/parallels-with-bitmap.bz2
>  create mode 100755 tests/qemu-iotests/sample_images/parallels-with-bitmap.sh
>  create mode 100755 tests/qemu-iotests/tests/parallels-read-bitmap
>  create mode 100644 tests/qemu-iotests/tests/parallels-read-bitmap.out
>
> diff --git a/tests/qemu-iotests/sample_images/parallels-with-bitmap.bz2 
> b/tests/qemu-iotests/sample_images/parallels-with-bitmap.bz2
> new file mode 100644
> index 
> ..54892fd4d01bf743d395bd4f3d896494146ab5a9
> GIT binary patch
> literal 203
> zcmV;+05tzXT4*^jL0KkKS@=;0bpT+Hf7|^?Km zk&7Szk`SoS002EkfMftPG z5P$(X{` zv(i3x^K~wt!aLPcRBP+PckUsIh6*LgjYSh0`}#7hMC9NR5D)+W0d&8Mxgwk>NPH-R
> Fx`3oHQ9u9y
>
> literal 0
> HcmV?d1
>
> diff --git a/tests/qemu-iotests/sample_images/parallels-with-bitmap.sh 
> b/tests/qemu-iotests/sample_images/parallels-with-bitmap.sh
> new file mode 100755
> index 00..30615aa6bd
> --- /dev/null
> +++ b/tests/qemu-iotests/sample_images/parallels-with-bitmap.sh
> @@ -0,0 +1,51 @@
> +#!/bin/bash
> +#
> +# Test parallels load bitmap
> +#
> +# Copyright (c) 2021 Virtuozzo International GmbH.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see .
> +#
> +
> +CT=parallels-with-bitmap-ct
> +DIR=$PWD/parallels-with-bitmap-dir
> +IMG=$DIR/root.hds
> +XML=$DIR/DiskDescriptor.xml
> +TARGET=parallels-with-bitmap.bz2
> +
> +rm -rf $DIR
> +
> +prlctl create $CT --vmtype ct
> +prlctl set $CT --device-add hdd --image $DIR --recreate --size 2G
> +
> +# cleanup the image
> +qemu-img create -f parallels $IMG 64G
> +
> +# create bitmap
> +prlctl backup $CT
> +
> +prlctl set $CT --device-del hdd1
> +prlctl destroy $CT
> +
> +dev=$(ploop mount $XML | sed -n 's/^Adding delta 
> dev=\(\/dev\/ploop[0-9]\+\).*/\1/p')
> +dd if=/dev/zero of=$dev bs=64K seek=5 count=2 oflag=direct
> +dd if=/dev/zero of=$dev bs=64K seek=30 count=1 oflag=direct
> +dd if=/dev/zero of=$dev bs=64K seek=10 count=3 oflag=direct
> +ploop umount $XML  # bitmap name will be in the output
> +
> +bzip2 -z $IMG
> +
> +mv $IMG.bz2 $TARGET
> +
> +rm -rf $DIR
> diff --git a/tests/qemu-iotests/tests/parallels-read-bitmap 
> b/tests/qemu-iotests/tests/parallels-read-bitmap
> new file mode 100755
> index 00..af6b9c5db3
> --- /dev/null
> +++ b/tests/qemu-iotests/tests/parallels-read-bitmap
> @@ -0,0 +1,55 @@
> +#!/usr/bin/env python3
> +#
> +# Test parallels load bitmap
> +#
> +# Copyright (c) 2021 Virtuozzo International GmbH.
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see .
> +#
> +
> +import json
> +import iotests
> +from iotests import qemu_nbd_popen, qemu_img_pipe, log, file_path
> +
> +iotests.script_initialize(supported_fmts=['parallels'])
> +
> +nbd_sock = file_path('nbd-sock', base_dir=iotests.sock_dir)
> +disk = iotests.file_path('disk')
> +bitmap = 'e4f2eed0-37fe-4539-b50b-85d2e7fd235f'
> +nbd_opts = f'driver=nbd,server.type=unix,server.path={nbd_sock}' \
> +f',x-dirty-bitmap=qemu:dirty-bitmap:{bitmap}'
> +
> +
> +iotests.unarchive_sample_image('parallels-with-bitmap', disk)
> +
> +
> +with qemu_nbd_popen('--read-only', f'--socket={nbd_sock}',
> +f'--bitmap={bitmap}', 

Re: [RFC PATCH 2/3] hw/block/pflash: Move code around

2021-02-26 Thread David Edmondson
On Friday, 2021-02-26 at 00:02:37 +01, Philippe Mathieu-Daudé wrote:

> First do the block checks, so we know if it is read-only or not.
> Then create the MemoryRegion. This will allow optimization in
> the next commit.
>
> Signed-off-by: Philippe Mathieu-Daudé 

Reviewed-by: David Edmondson 

> ---
>  hw/block/pflash_cfi01.c | 24 
>  hw/block/pflash_cfi02.c | 18 +-
>  2 files changed, 21 insertions(+), 21 deletions(-)
>
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 22287a1522e..a5fa8d8b74a 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -731,18 +731,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error 
> **errp)
>  }
>  device_len = sector_len_per_device * blocks_per_device;
>  
> -memory_region_init_rom_device(
> ->mem, OBJECT(dev),
> -_cfi01_ops,
> -pfl,
> -pfl->name, total_len, errp);
> -if (*errp) {
> -return;
> -}
> -
> -pfl->storage = memory_region_get_ram_ptr(>mem);
> -sysbus_init_mmio(SYS_BUS_DEVICE(dev), >mem);
> -
>  if (pfl->blk) {
>  uint64_t perm;
>  pfl->ro = !blk_supports_write_perm(pfl->blk);
> @@ -755,6 +743,18 @@ static void pflash_cfi01_realize(DeviceState *dev, Error 
> **errp)
>  pfl->ro = 0;
>  }
>  
> +memory_region_init_rom_device(
> +>mem, OBJECT(dev),
> +_cfi01_ops,
> +pfl,
> +pfl->name, total_len, errp);
> +if (*errp) {
> +return;
> +}
> +
> +pfl->storage = memory_region_get_ram_ptr(>mem);
> +sysbus_init_mmio(SYS_BUS_DEVICE(dev), >mem);
> +
>  if (pfl->blk) {
>  if (!blk_check_size_and_read_all(pfl->blk, pfl->storage, total_len,
>   errp)) {
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 7962cff7455..4f62ce8917d 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -791,15 +791,6 @@ static void pflash_cfi02_realize(DeviceState *dev, Error 
> **errp)
>  return;
>  }
>  
> -memory_region_init_rom_device(>orig_mem, OBJECT(pfl),
> -  _cfi02_ops, pfl, pfl->name,
> -  pfl->chip_len, errp);
> -if (*errp) {
> -return;
> -}
> -
> -pfl->storage = memory_region_get_ram_ptr(>orig_mem);
> -
>  if (pfl->blk) {
>  uint64_t perm;
>  pfl->ro = !blk_supports_write_perm(pfl->blk);
> @@ -812,6 +803,15 @@ static void pflash_cfi02_realize(DeviceState *dev, Error 
> **errp)
>  pfl->ro = 0;
>  }
>  
> +memory_region_init_rom_device(>orig_mem, OBJECT(pfl),
> +  _cfi02_ops, pfl, pfl->name,
> +  pfl->chip_len, errp);
> +if (*errp) {
> +return;
> +}
> +
> +pfl->storage = memory_region_get_ram_ptr(>orig_mem);
> +
>  if (pfl->blk) {
>  if (!blk_check_size_and_read_all(pfl->blk, pfl->storage,
>   pfl->chip_len, errp)) {
> -- 
> 2.26.2

dme.
-- 
She's as sweet as Tupelo honey, she's an angel of the first degree.



Re: [RFC PATCH 3/3] hw/block/pflash: use memory_region_init_rom_device_from_file()

2021-02-26 Thread David Edmondson
On Friday, 2021-02-26 at 00:02:38 +01, Philippe Mathieu-Daudé wrote:

> If the block drive is read-only we will model a "protected" flash
> device. We can thus use memory_region_init_rom_device_from_file()
> which mmap the backing file when creating the MemoryRegion.
> If the same backing file is used by multiple QEMU instances, this
> reduces the memory footprint (this is often the case with the
> CODE flash image from OVMF and AAVMF).
>
> Suggested-by: Stefan Hajnoczi 
> Signed-off-by: Philippe Mathieu-Daudé 
> ---
>  hw/block/pflash_cfi01.c | 20 ++--
>  hw/block/pflash_cfi02.c | 18 ++
>  2 files changed, 28 insertions(+), 10 deletions(-)
>
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index a5fa8d8b74a..5757391df1c 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -743,11 +743,19 @@ static void pflash_cfi01_realize(DeviceState *dev, 
> Error **errp)
>  pfl->ro = 0;
>  }
>  
> -memory_region_init_rom_device(
> ->mem, OBJECT(dev),
> -_cfi01_ops,
> -pfl,
> -pfl->name, total_len, errp);
> +if (pfl->blk && pfl->ro) {
> +memory_region_init_rom_device_from_file(>mem, OBJECT(dev),
> +_cfi01_ops, pfl,
> +pfl->name, total_len,
> +qemu_real_host_page_size,
> +RAM_SHARED,
> +blk_bs(pfl->blk)->filename,

How will this behave if someone does:

-drive file=OVMF_CODE.fd.qcow2,index=0,if=pflash,format=qcow2,readonly=on

Honestly, I'm not sure why they would, but it works today.

> +true, errp);
> +} else {
> +memory_region_init_rom_device(>mem, OBJECT(dev),
> +  _cfi01_ops, pfl,
> +  pfl->name, total_len, errp);
> +}
>  if (*errp) {
>  return;
>  }
> @@ -755,7 +763,7 @@ static void pflash_cfi01_realize(DeviceState *dev, Error 
> **errp)
>  pfl->storage = memory_region_get_ram_ptr(>mem);
>  sysbus_init_mmio(SYS_BUS_DEVICE(dev), >mem);
>  
> -if (pfl->blk) {
> +if (pfl->blk && !pfl->ro) {
>  if (!blk_check_size_and_read_all(pfl->blk, pfl->storage, total_len,
>   errp)) {
>  vmstate_unregister_ram(>mem, DEVICE(pfl));
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 4f62ce8917d..d57f64d7732 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -803,16 +803,26 @@ static void pflash_cfi02_realize(DeviceState *dev, 
> Error **errp)
>  pfl->ro = 0;
>  }
>  
> -memory_region_init_rom_device(>orig_mem, OBJECT(pfl),
> -  _cfi02_ops, pfl, pfl->name,
> -  pfl->chip_len, errp);
> +if (pfl->blk && pfl->ro) {
> +memory_region_init_rom_device_from_file(>orig_mem, OBJECT(pfl),
> +_cfi02_ops, pfl,
> +pfl->name, pfl->chip_len,
> +qemu_real_host_page_size,
> +RAM_SHARED,
> +blk_bs(pfl->blk)->filename,
> +true, errp);
> +} else {
> +memory_region_init_rom_device(>orig_mem, OBJECT(pfl),
> +  _cfi02_ops, pfl, pfl->name,
> +  pfl->chip_len, errp);
> +}
>  if (*errp) {
>  return;
>  }
>  
>  pfl->storage = memory_region_get_ram_ptr(>orig_mem);
>  
> -if (pfl->blk) {
> +if (pfl->blk && !pfl->ro) {
>  if (!blk_check_size_and_read_all(pfl->blk, pfl->storage,
>   pfl->chip_len, errp)) {
>  vmstate_unregister_ram(>orig_mem, DEVICE(pfl));
> -- 
> 2.26.2

dme.
-- 
And you're standing here beside me, I love the passing of time.