All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH v2 6/8] qom: introduce qdev_new_dynamic()
Date: Fri, 15 Nov 2024 17:26:42 +0000	[thread overview]
Message-ID: <ZzeEUgv0npL4IfFn@redhat.com> (raw)
In-Reply-To: <ZzZh2GHJm1L-mq5D@x1n>

On Thu, Nov 14, 2024 at 03:47:20PM -0500, Peter Xu wrote:
> On Mon, Nov 11, 2024 at 03:55:53PM +0000, Daniel P. Berrangé wrote:
> > qdev_new() has a failure scenario where it will assert() if given
> > an abstract type. Callers which are creating qdevs based on user
> > input, or unknown/untrusted type names, must manually check the
> > result of qdev_class_is_abstract() before calling qdev_new()
> > to propagate an Error, instead of asserting.
> > 
> > Introduce a qdev_new_dynamic() method which is a counterpart to
> > qdev_new() that directly returns an Error, instead of asserting.
> > This new method is to be used where the typename is specified
> > dynamically by code separate from the immediate caller.
> > 
> > Do likewise with qdev_try_new_dynamic() as a counterpart to
> > qdev_try_new().
> 
> Since at it, would it make sense to simply replace qdev_try_new() with
> qdev_new_dynamic(), assuming it plays similar role of "it can fail" version
> of qdev_new()?

That is tricky as callers of qdev_try_new have to distinguish between
expected failures and unexpected failures.

That said you made me look at the usage patterns and I concluded these
xxx_try_new() methods are a bad design for other reasons, so I have
simply eliminated them entirely in v3.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2024-11-15 17:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-11 15:55 [PATCH v2 0/8] Require error handling for dynamically created objects Daniel P. Berrangé
2024-11-11 15:55 ` [PATCH v2 1/8] qom: refactor checking abstract property when creating instances Daniel P. Berrangé
2024-11-14 19:58   ` Peter Xu
2024-11-15 10:41     ` Daniel P. Berrangé
2024-11-11 15:55 ` [PATCH v2 2/8] qom: allow failure of object_new_with_class Daniel P. Berrangé
2024-11-14 20:04   ` Peter Xu
2024-11-11 15:55 ` [PATCH v2 3/8] qom: introduce object_new_dynamic() Daniel P. Berrangé
2024-11-14 20:15   ` Peter Xu
2024-11-11 15:55 ` [PATCH v2 4/8] convert code to object_new_dynamic() where appropriate Daniel P. Berrangé
2024-11-14 20:24   ` Peter Xu
2024-11-11 15:55 ` [PATCH v2 5/8] qom: enforce use of static, const string with object_new() Daniel P. Berrangé
2024-11-14 20:28   ` Peter Xu
2024-11-11 15:55 ` [PATCH v2 6/8] qom: introduce qdev_new_dynamic() Daniel P. Berrangé
2024-11-14 20:47   ` Peter Xu
2024-11-15 17:26     ` Daniel P. Berrangé [this message]
2024-11-11 15:55 ` [PATCH v2 7/8] convert code to qdev_new_dynamic() where appropriate Daniel P. Berrangé
2024-11-14 21:00   ` Peter Xu
2024-11-11 15:55 ` [PATCH v2 8/8] hw: enforce use of static, const string with qdev_new() Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZzeEUgv0npL4IfFn@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.