Received: from [140.186.70.92] (port=53155 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OSQ5t-0002yM-0M for qemu-devel@nongnu.org; Sat, 26 Jun 2010 03:46:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OSQ5r-0001Ff-UW for qemu-devel@nongnu.org; Sat, 26 Jun 2010 03:46:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47386) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OSQ5r-0001FV-MJ for qemu-devel@nongnu.org; Sat, 26 Jun 2010 03:46:27 -0400 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH 5/7] add qdev property type "cpu" References: <1277470342-5861-1-git-send-email-pbonzini@redhat.com> <1277470342-5861-6-git-send-email-pbonzini@redhat.com> Date: Sat, 26 Jun 2010 09:46:22 +0200 In-Reply-To: <1277470342-5861-6-git-send-email-pbonzini@redhat.com> (Paolo Bonzini's message of "Fri, 25 Jun 2010 14:52:20 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Amit Shah , Isaku Yamahata , qemu-devel@nongnu.org Paolo Bonzini writes: [...] > diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c > index 5a8739d..2759c83 100644 > --- a/hw/qdev-properties.c > +++ b/hw/qdev-properties.c > @@ -1,6 +1,7 @@ > #include "net.h" > #include "qdev.h" > #include "qerror.h" > +#include "cpus.h" > > void *qdev_get_prop_ptr(DeviceState *dev, Property *prop) > { > @@ -281,6 +282,44 @@ PropertyInfo qdev_prop_string = { > .free = free_string, > }; > > +/* --- cpu --- */ > + > +static int parse_cpu(DeviceState *dev, Property *prop, const char *str) > +{ > + CPUState **ptr = qdev_get_prop_ptr(dev, prop); > + char *end; > + int id; > + > + if (!*str) > + return -ENOENT; > + > + id = strtol (str, &end, 0); > + if (*end) > + return -ENOENT; > + > + *ptr = cpu_get_by_id(id); > + if (*ptr == NULL) > + return -ENOENT; > + return 0; > +} > + > +static int print_cpu(DeviceState *dev, Property *prop, char *dest, size_t len) > +{ > + CPUState **ptr = qdev_get_prop_ptr(dev, prop); > + if (*ptr) > + return snprintf(dest, len, "CPU #%d", cpu_get_id(*ptr)); > + else > + return snprintf(dest, len, "CPU #"); > +} Hmm. Parse method doesn't accept output of the print method. Not so nice. Is the "CPU #" decoration essential? Oh, and beware of the Secret Tab Police. [...]