Re: [Qemu-devel] [PATCH v3 3/7] qom: create objects in two phases

2015-05-12 Thread Daniel P. Berrange
On Fri, May 08, 2015 at 04:40:51PM +0200, Paolo Bonzini wrote:
 
 
 On 08/05/2015 16:37, Andreas Färber wrote:
  Hi,
  
  Can we *please* find a better subject for this? To me, creating QOM
  objects in two phases is about instance_init vs. realize, and thus I was
  pretty upset that Paolo dared to apply this without asking me first.
 
 Oops, sorry.  I very much understand where you came from, now.

Ok, I'll change this to say something like

  create most objects before creating chardev backends

to better describe what its trying to achieve.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|



Re: [Qemu-devel] [PATCH v3 3/7] qom: create objects in two phases

2015-05-08 Thread Paolo Bonzini


On 08/05/2015 16:37, Andreas Färber wrote:
 Hi,
 
 Can we *please* find a better subject for this? To me, creating QOM
 objects in two phases is about instance_init vs. realize, and thus I was
 pretty upset that Paolo dared to apply this without asking me first.

Oops, sorry.  I very much understand where you came from, now.

Thanks,

Paolo



Re: [Qemu-devel] [PATCH v3 3/7] qom: create objects in two phases

2015-05-08 Thread Andreas Färber
Hi,

Can we *please* find a better subject for this? To me, creating QOM
objects in two phases is about instance_init vs. realize, and thus I was
pretty upset that Paolo dared to apply this without asking me first.

Am 01.05.2015 um 12:30 schrieb Daniel P. Berrange:
 Some types of object must be created before chardevs, other types of
 object must be created after chardevs. As such there is no option but
 to create objects in two phases.
 
 This takes the decision to create as many object types as possible
 in the first phase, and only delay those which have a dependency on
 the chardevs. Hopefully the set which need delaying will remain
 small.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  vl.c | 40 +++-
  1 file changed, 39 insertions(+), 1 deletion(-)
 
 diff --git a/vl.c b/vl.c
 index 74c2681..ee2f70a 100644
 --- a/vl.c
 +++ b/vl.c
 @@ -2591,6 +2591,33 @@ static int machine_set_property(const char *name, 
 const char *value,
  return 0;
  }
  
 +
 +/**

Accidental documentation comment?

 + * Initial object creation happens before all other
 + * QEMU data types are created. The majority of objects
 + * can be created at this point. The rng-egd object
 + * cannot be created here, as it depends on the chardev
 + * already existing.
 + */
 +static bool object_create_initial(const char *type)
 +{
 +if (g_str_equal(type, rng-egd)) {
 +return false;
 +}
 +return true;
 +}
 +
 +
 +/**

Ditto?

 + * The remainder of object creation happens after the
 + * creation of chardev, fsdev and device data types.
 + */
 +static bool object_create_delayed(const char *type)
 +{
 +return !object_create_initial(type);
 +}
 +
 +
  static int object_create(QemuOpts *opts, void *opaque)
  {
  Error *err = NULL;
 @@ -2599,6 +2626,7 @@ static int object_create(QemuOpts *opts, void *opaque)
  void *dummy = NULL;
  OptsVisitor *ov;
  QDict *pdict;
 +bool (*type_predicate)(const char *) = opaque;
  
  ov = opts_visitor_new(opts);
  pdict = qemu_opts_to_qdict(opts, NULL);
 @@ -2613,6 +2641,9 @@ static int object_create(QemuOpts *opts, void *opaque)
  if (err) {
  goto out;
  }
 +if (!type_predicate(type)) {
 +goto out;
 +}
  
  qdict_del(pdict, id);
  visit_type_str(opts_get_visitor(ov), id, id, err);
 @@ -4008,6 +4039,12 @@ int main(int argc, char **argv, char **envp)
  
  socket_init();
  
 +if (qemu_opts_foreach(qemu_find_opts(object),
 +  object_create,
 +  object_create_initial, 0) != 0) {
 +exit(1);
 +}
 +
  if (qemu_opts_foreach(qemu_find_opts(chardev), chardev_init_func, 
 NULL, 1) != 0)
  exit(1);
  #ifdef CONFIG_VIRTFS
 @@ -4027,7 +4064,8 @@ int main(int argc, char **argv, char **envp)
  }
  
  if (qemu_opts_foreach(qemu_find_opts(object),
 -  object_create, NULL, 0) != 0) {
 +  object_create,
 +  object_create_delayed, 0) != 0) {
  exit(1);
  }
  

Otherwise looks okay and there's a pattern emerging of not qom:.

Regards,
Andreas

-- 
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Jennifer Guild, Dilip Upmanyu,
Graham Norton; HRB 21284 (AG Nürnberg)



[Qemu-devel] [PATCH v3 3/7] qom: create objects in two phases

2015-05-01 Thread Daniel P. Berrange
Some types of object must be created before chardevs, other types of
object must be created after chardevs. As such there is no option but
to create objects in two phases.

This takes the decision to create as many object types as possible
in the first phase, and only delay those which have a dependency on
the chardevs. Hopefully the set which need delaying will remain
small.

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 vl.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/vl.c b/vl.c
index 74c2681..ee2f70a 100644
--- a/vl.c
+++ b/vl.c
@@ -2591,6 +2591,33 @@ static int machine_set_property(const char *name, const 
char *value,
 return 0;
 }
 
+
+/**
+ * Initial object creation happens before all other
+ * QEMU data types are created. The majority of objects
+ * can be created at this point. The rng-egd object
+ * cannot be created here, as it depends on the chardev
+ * already existing.
+ */
+static bool object_create_initial(const char *type)
+{
+if (g_str_equal(type, rng-egd)) {
+return false;
+}
+return true;
+}
+
+
+/**
+ * The remainder of object creation happens after the
+ * creation of chardev, fsdev and device data types.
+ */
+static bool object_create_delayed(const char *type)
+{
+return !object_create_initial(type);
+}
+
+
 static int object_create(QemuOpts *opts, void *opaque)
 {
 Error *err = NULL;
@@ -2599,6 +2626,7 @@ static int object_create(QemuOpts *opts, void *opaque)
 void *dummy = NULL;
 OptsVisitor *ov;
 QDict *pdict;
+bool (*type_predicate)(const char *) = opaque;
 
 ov = opts_visitor_new(opts);
 pdict = qemu_opts_to_qdict(opts, NULL);
@@ -2613,6 +2641,9 @@ static int object_create(QemuOpts *opts, void *opaque)
 if (err) {
 goto out;
 }
+if (!type_predicate(type)) {
+goto out;
+}
 
 qdict_del(pdict, id);
 visit_type_str(opts_get_visitor(ov), id, id, err);
@@ -4008,6 +4039,12 @@ int main(int argc, char **argv, char **envp)
 
 socket_init();
 
+if (qemu_opts_foreach(qemu_find_opts(object),
+  object_create,
+  object_create_initial, 0) != 0) {
+exit(1);
+}
+
 if (qemu_opts_foreach(qemu_find_opts(chardev), chardev_init_func, NULL, 
1) != 0)
 exit(1);
 #ifdef CONFIG_VIRTFS
@@ -4027,7 +4064,8 @@ int main(int argc, char **argv, char **envp)
 }
 
 if (qemu_opts_foreach(qemu_find_opts(object),
-  object_create, NULL, 0) != 0) {
+  object_create,
+  object_create_delayed, 0) != 0) {
 exit(1);
 }
 
-- 
2.1.0