From nobody Sat Nov 23 12:17:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675354529; cv=none; d=zohomail.com; s=zohoarc; b=igaI76kyrsJrWJs0ovlAhXL/JowkfVwYBxd2Gn8335cyes3vxMl4rRj3GDkJmK14BtFGmvHkg7DhbJc0fvkwtC9ojHvReXBuCbOhJQnAGe5iF6+9sOfkRgvW25EjAX9gJ2LtxfrdTy16R2U8qhcXuNYL56j/CQ6GOny4Om4/I6E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675354529; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=LMvclOZ5LYcb4bA+wj6e3wDqjxXhtofDT/22nMoGthM=; b=X/+JFXl4QuRTlqwJoW/oJGe9Mu4v/2Zh1iKUVDoWeXpOwDZven7P4NYER6wseEe13em1pYjhuafY2/d4AtRQY09SzjWhWGPVhvn/uu7eXF/0t+LcOhuR6cTk6af17kPHV8bsTTJ4WTnHF2zatXuHmUxRdjnNquyAoAalJ2NYCVE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1675354529963395.6305725543765; Thu, 2 Feb 2023 08:15:29 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-271-18kDbFHCNUWrGSJVUHeUGQ-1; Thu, 02 Feb 2023 11:15:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B9B6857A8E; Thu, 2 Feb 2023 16:15:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 370FE40398A0; Thu, 2 Feb 2023 16:15:20 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 18128194658C; Thu, 2 Feb 2023 16:15:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C0964194658F for ; Thu, 2 Feb 2023 16:15:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1FD042166B35; Thu, 2 Feb 2023 16:15:15 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 518382166B33 for ; Thu, 2 Feb 2023 16:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675354529; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=LMvclOZ5LYcb4bA+wj6e3wDqjxXhtofDT/22nMoGthM=; b=d9QL3MA7AtTYy/C4LvdILQyid0p7jH+MCJADtOtHC2w3DF1SCrNGeWFL2O2UUtv9Sf6ot1 SGqyoYFyybpZ5sjjVP1ymY9c2poaPeHHfD+8J+FyLHpwzDAySo70MstvSNdJCt3NJzXqmn 7Wmtg930infnCl7BvNqES/FXMVVQ5R8= X-MC-Unique: 18kDbFHCNUWrGSJVUHeUGQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/2] virDomainDeviceDefParse: Separate code for parsing type Date: Thu, 2 Feb 2023 17:15:10 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675354530585100003 Content-Type: text/plain; charset="utf-8" Move the code into a new function named virDomainDeviceDefParseType. The separation will make it easier to change the type of the 'type' field in side of virDomainDeviceDef. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 43 +++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6e33a4472f..2744a3370e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13730,6 +13730,32 @@ virDomainCryptoDefParseXML(virDomainXMLOption *xml= opt, } +static int +virDomainDeviceDefParseType(const char *typestr, + int *type) +{ + int tmp; + + /* Mapping of serial, parallel, console and channel to VIR_DOMAIN_DEVI= CE_CHR. */ + if (STREQ(typestr, "channel") || + STREQ(typestr, "console") || + STREQ(typestr, "parallel") || + STREQ(typestr, "serial")) { + *type =3D VIR_DOMAIN_DEVICE_CHR; + return 0; + } + + if ((tmp =3D virDomainDeviceTypeFromString(typestr)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown device type '%s'"), typestr); + return -1; + } + + *type =3D tmp; + return 0; +} + + virDomainDeviceDef * virDomainDeviceDefParse(const char *xmlStr, const virDomainDef *def, @@ -13749,21 +13775,8 @@ virDomainDeviceDefParse(const char *xmlStr, dev =3D g_new0(virDomainDeviceDef, 1); - if ((dev->type =3D virDomainDeviceTypeFromString((const char *) node->= name)) < 0) { - /* Some crazy mapping of serial, parallel, console and channel to - * VIR_DOMAIN_DEVICE_CHR. */ - if (virXMLNodeNameEqual(node, "channel") || - virXMLNodeNameEqual(node, "console") || - virXMLNodeNameEqual(node, "parallel") || - virXMLNodeNameEqual(node, "serial")) { - dev->type =3D VIR_DOMAIN_DEVICE_CHR; - } else { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown device type '%s'"), - node->name); - return NULL; - } - } + if (virDomainDeviceDefParseType((const char *)node->name, &dev->type) = < 0) + return NULL; switch ((virDomainDeviceType) dev->type) { case VIR_DOMAIN_DEVICE_DISK: --=20 2.39.1