Received: from eggs.gnu.org ([2001:4830:134:3::10]:45500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQOJD-0003VB-MT for qemu-devel@nongnu.org; Wed, 19 Mar 2014 17:46:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQOJ4-0001l7-Cu for qemu-devel@nongnu.org; Wed, 19 Mar 2014 17:45:59 -0400 Received: from cantor2.suse.de ([195.135.220.15]:58532 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQOJ4-0001l0-1x for qemu-devel@nongnu.org; Wed, 19 Mar 2014 17:45:50 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 19 Mar 2014 22:45:38 +0100 Message-Id: <1395265542-384-4-git-send-email-afaerber@suse.de> In-Reply-To: <1395265542-384-1-git-send-email-afaerber@suse.de> References: <1395265542-384-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-2.0 3/7] qom: Split object_property_set_link() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , Stefan Hajnoczi From: Stefan Hajnoczi The path resolution logic in object_property_set_link() should be a separate function. This makes the code easier to read and maintain. Signed-off-by: Stefan Hajnoczi Reviewed-by: Paolo Bonzini Signed-off-by: Andreas F=C3=A4rber --- qom/object.c | 60 ++++++++++++++++++++++++++++++++++++++++--------------= ------ 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/qom/object.c b/qom/object.c index a2a1ffa..2877a00 100644 --- a/qom/object.c +++ b/qom/object.c @@ -1039,17 +1039,50 @@ static void object_get_link_property(Object *obj,= Visitor *v, void *opaque, } } =20 +/* + * object_resolve_link: + * + * Lookup an object and ensure its type matches the link property type. = This + * is similar to object_resolve_path() except type verification against = the + * link property is performed. + * + * Returns: The matched object or NULL on path lookup failures. + */ +static Object *object_resolve_link(Object *obj, const char *name, + const char *path, Error **errp) +{ + const char *type; + gchar *target_type; + bool ambiguous =3D false; + Object *target; + + /* Go from link to FOO. */ + type =3D object_property_get_type(obj, name, NULL); + target_type =3D g_strndup(&type[5], strlen(type) - 6); + target =3D object_resolve_path_type(path, target_type, &ambiguous); + + if (ambiguous) { + error_set(errp, QERR_AMBIGUOUS_PATH, path); + } else if (!target) { + target =3D object_resolve_path(path, &ambiguous); + if (target || ambiguous) { + error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, target_ty= pe); + } else { + error_set(errp, QERR_DEVICE_NOT_FOUND, path); + } + target =3D NULL; + } + g_free(target_type); + + return target; +} + static void object_set_link_property(Object *obj, Visitor *v, void *opaq= ue, const char *name, Error **errp) { Object **child =3D opaque; Object *old_target; - bool ambiguous =3D false; - const char *type; char *path; - gchar *target_type; - - type =3D object_property_get_type(obj, name, NULL); =20 visit_type_str(v, &path, name, errp); =20 @@ -1059,24 +1092,11 @@ static void object_set_link_property(Object *obj,= Visitor *v, void *opaque, if (strcmp(path, "") !=3D 0) { Object *target; =20 - /* Go from link to FOO. */ - target_type =3D g_strndup(&type[5], strlen(type) - 6); - target =3D object_resolve_path_type(path, target_type, &ambiguou= s); - - if (ambiguous) { - error_set(errp, QERR_AMBIGUOUS_PATH, path); - } else if (target) { + target =3D object_resolve_link(obj, name, path, errp); + if (target) { object_ref(target); *child =3D target; - } else { - target =3D object_resolve_path(path, &ambiguous); - if (target || ambiguous) { - error_set(errp, QERR_INVALID_PARAMETER_TYPE, name, targe= t_type); - } else { - error_set(errp, QERR_DEVICE_NOT_FOUND, path); - } } - g_free(target_type); } =20 g_free(path); --=20 1.8.4.5