From nobody Tue Nov 26 18:24:17 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1706024180; cv=none; d=zohomail.com; s=zohoarc; b=niYjGFyRDkYbQkxMtzH02134EmjsvR1zdrhtxS8NUG5+kx0E0wNEvDanaAUSS3NXoRskN/r+8GlZbsXOSXQosm1Dp/7cYWS2AfMeVHebyj9GhEdetfyHuUtPJWjIfgUsdWF8Jnp98D9HO1zg0zVCcCx2HcIqUiTKceGyQM3OKj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706024180; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XyDmVSFodOYjD4FiRaNUUzftXSYkP1NTnuHNRCor0SU=; b=IJSybHh9cbhEYDuMB16BQnMesT/T6R/rhtdC1wTK+APeKXjW2yJdZfK+gvKWSJv9KdbSmguCR1VaVcDviRMSvITTG2R8rCs4vKIeUVT4m61Qe6qW7ov38urfXN/kCrBB/9sGC8gi2rUn3+pAhsYhVLRIgP2IUOklycoB3bJryD4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706024180432973.8265020756085; Tue, 23 Jan 2024 07:36:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rSIod-0005vm-8S; Tue, 23 Jan 2024 10:35:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rSIoQ-0005pf-I3 for qemu-devel@nongnu.org; Tue, 23 Jan 2024 10:35:42 -0500 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rSIoN-0007De-6a for qemu-devel@nongnu.org; Tue, 23 Jan 2024 10:35:42 -0500 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-55a50649ff6so4849059a12.3 for ; Tue, 23 Jan 2024 07:35:37 -0800 (PST) Received: from localhost.localdomain (adsl-138.37.6.1.tellas.gr. [37.6.1.138]) by smtp.gmail.com with ESMTPSA id cf15-20020a0564020b8f00b0055c903e61easm484663edb.82.2024.01.23.07.35.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 07:35:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1706024135; x=1706628935; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XyDmVSFodOYjD4FiRaNUUzftXSYkP1NTnuHNRCor0SU=; b=CIS43d6FXvqw7jlMOmse29woBUx7amPXUP1qkRWixpqvAJC42nG3PAYiRorIq3WNWB XyjNnqybHhgWkLnUZNzjY0N/ktMkM6gjLYAZJ4Q8fZhESiIXTaJEWfyiA9y88W3I5/sx JXjzuQAz7AEN8N3MZ9hqNwgmYl5CaWoJHqj5py+anbmvVKno+jGwjXg62RvRAiy7tv6y OZj+g9nK1gPylmyYHRwH72kP0F40XuxoDBTprArJL+i+tYeYYySB7aH54f+0Czl5m/VY T8SRbaL8IPx24XcBbxb7AaLtOY6nJ9QrSvSh3/m64I2ohjtCzvoVV9M9pnNdKblpJbdX w5VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706024135; x=1706628935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XyDmVSFodOYjD4FiRaNUUzftXSYkP1NTnuHNRCor0SU=; b=kQDKObQfuSuE3WRWIaYfq1rioGl5QKG3roPjZJcTH6aA7nP6Rj7VymuFBb9+gqjwbp 5c78mgPi/0MgW3B4RDaDai8R+o5lwoc12teJt16FbDOEBtrI6EJO+xqiKW70bRKuFWiK hqgafUQ7fG6fTSt80DB13DRuH2cnSCQHdG6TSQgxz4RKrurPRlRNuogDJqT9SjkKX6dF rzIpZy7sLPHrKzHKM7cJnTXV2c+Db0wqwwCc4KNMEvZNgzw3E2zpnMs/idRMSU2PHocr Tspnno7N+A68nWhxUuqa13kqjxL7kWFn+pQVhX2c6HJmdKEHfbBFjY5IHZ+wgVVxhTgc Mqsw== X-Gm-Message-State: AOJu0YwCIgXe8MiViMgfOvoBxkumBC161HN7nBr3Ed0NmoEOhhv7DxCH xJDEdZFiVCw+1X0/8ED4tGvTosfEreuBWDf42fBE/BmTXhDsnJ5P1EgYqA7mgnvZb5g6IYbgtQr vRHA= X-Google-Smtp-Source: AGHT+IHC7ijLeFSdFJmKLFx91WgyjZEoJBG8XtPwyBX57dmNybtyc4js6ymQgY0++9kzWUQDGxdn4w== X-Received: by 2002:aa7:d9c4:0:b0:55a:60ca:fe35 with SMTP id v4-20020aa7d9c4000000b0055a60cafe35mr953263eds.56.1706024135520; Tue, 23 Jan 2024 07:35:35 -0800 (PST) From: Manos Pitsidianakis To: qemu-devel@nongnu.org, qemu-block@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH v2 1/2] hw/core/qdev.c: add qdev_get_human_name() Date: Tue, 23 Jan 2024 17:35:30 +0200 Message-Id: <5fb58797083e7786fd3556d2c247609565b8637d.1706023972.git.manos.pitsidianakis@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=manos.pitsidianakis@linaro.org; helo=mail-ed1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1706024182210100003 Add a simple method to return some kind of human readable identifier for use in error messages. Signed-off-by: Manos Pitsidianakis Reviewed-by: Stefan Hajnoczi --- hw/core/qdev.c | 8 ++++++++ include/hw/qdev-core.h | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 43d863b0c5..c68d0f7c51 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -879,6 +879,14 @@ Object *qdev_get_machine(void) return dev; } =20 +char *qdev_get_human_name(DeviceState *dev) +{ + g_assert(dev !=3D NULL); + + return dev->id ? + g_strdup(dev->id) : object_get_canonical_path(OBJECT(dev)); +} + static MachineInitPhase machine_phase; =20 bool phase_check(MachineInitPhase phase) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 151d968238..66338f479f 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -993,6 +993,20 @@ const char *qdev_fw_name(DeviceState *dev); void qdev_assert_realized_properly(void); Object *qdev_get_machine(void); =20 +/** + * qdev_get_human_name() - Return a human-readable name for a device + * @dev: The device. Must be a valid and non-NULL pointer. + * + * .. note:: + * This function is intended for user friendly error messages. + * + * Returns: A newly allocated string containing the device id if not null, + * else the object canonical path. + * + * Use g_free() to free it. + */ +char *qdev_get_human_name(DeviceState *dev); + /* FIXME: make this a link<> */ bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp); =20 --=20 =CE=B3=CE=B1=E1=BF=96=CE=B1 =CF=80=CF=85=CF=81=CE=AF =CE=BC=CE=B9=CF=87=CE= =B8=CE=AE=CF=84=CF=89