From nobody Tue Nov 26 08:32:44 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=ixsystems.com ARC-Seal: i=1; a=rsa-sha256; t=1582353647; cv=none; d=zohomail.com; s=zohoarc; b=ANT17pZLbBrcQCZ9iFzBxK76Q59ZfAhZ6A9hF7BjOyFJFh0FBP62j2aaSjyP4p9twuWo/w88d+XoBFCpjimX5Tsyl9sj4L/Lhz5hYfVypQqY72LPmq/zRFZSZR0Myo/pTvHLYybmzheTWoCL80gIajhVqnqNj40qctpgRJmUczQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582353647; 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=JGt5jyCDU5Vy/QsIGHO7FJ7Sdgy7s+MlIhWEOjhAz4U=; b=KxJBHCI0gwUj89dD30+unkQqjoKrjlAsdqmO7Qx/+326bJrp/xDIsbuCQA6PsUgSyu6MzV9/590G4R6YaPhYHQTorWMjEtRkLjIfmOEqTzzi3OwMu0LynT0wSLiSOVG3qDgXMaBHv7G5sDJJrVjKBnzIQQC45ouANqOoLV741FA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1582353647591875.1948549762478; Fri, 21 Feb 2020 22:40:47 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-454-cbHCMmxNOH2bpouZsWqLVA-1; Sat, 22 Feb 2020 01:40:44 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5812B801E5C; Sat, 22 Feb 2020 06:40:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F74060BE0; Sat, 22 Feb 2020 06:40:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E11F7860D6; Sat, 22 Feb 2020 06:40:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01M6dsst021793 for ; Sat, 22 Feb 2020 01:39:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0D2C913BB85; Sat, 22 Feb 2020 06:39:54 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0907713AF75 for ; Sat, 22 Feb 2020 06:39:54 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E4697101A55A for ; Sat, 22 Feb 2020 06:39:53 +0000 (UTC) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-2uPdBgI4OICG9zRsCvThVg-1; Sat, 22 Feb 2020 01:39:51 -0500 Received: by mail-yw1-f67.google.com with SMTP id b186so2649071ywc.1 for ; Fri, 21 Feb 2020 22:39:51 -0800 (PST) Received: from xeon-freebsd.freqlabs.com. (69-228-200-148.lightspeed.knvltn.sbcglobal.net. [69.228.200.148]) by smtp.gmail.com with ESMTPSA id c84sm2482131ywa.1.2020.02.21.22.39.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Feb 2020 22:39:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582353646; 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=JGt5jyCDU5Vy/QsIGHO7FJ7Sdgy7s+MlIhWEOjhAz4U=; b=JCFEcqH5+OKF+2aw4xhb0mYddxgaXmGpJIcqJB4DsqWF9HnXyreNXw3KsrIt2oiNmCxn3z aYDXpTm9J75x73F7Tr+f7mtuvadYgIKqv8CG6h7pokvkMgIp4VFxNrwfBbaf0lseWKAnc5 R4NGPMiZDvOIghI3S1VT6tI5Lk+rrfg= X-MC-Unique: cbHCMmxNOH2bpouZsWqLVA-1 X-MC-Unique: 2uPdBgI4OICG9zRsCvThVg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=x+gFL3xwJNy1ZwzVJUmNJUNXuD8EUPkdnIKqRgeEvAE=; b=l2v0vxaYZ5pIuKOCAaHQtTRIQdaAnGl4BtVZ++fMqnCIXXhQc9Oi9Bm/XOiaEzHegZ TTjKol0Fm/Czi39ivk9HDNJInwZPKLzAXOZQ+0llvUFbe3JdZCU4rMib+am8ggnRhy/U /9T1YhV6Lk0mpB6vkCkDN/kNyvKDY3kXDmQ2QTHSL4IUAnryQKF5u0pZ5+UwK+Y9eJ+0 wcVwlbFyZXPeclyOCmiMaSmjVkzRZssjBvRNT3/OBUgoSOgWtB9g5L/IUeSgq18xazkL XxxNL0zMVa4tPCkrUFgB6doaAWrNunpmNElXPTXi60XOkXrANTQ8juyLWuTbrIOMbG4t z7xg== X-Gm-Message-State: APjAAAVKBq1eVVR5vLM4RLTROeo8uZk8sVtlDYpAqIKzicd6vNn5p/OA ynTGQ4cdN77ngnv08VU+ulNddWcpm//a2RPSDAexBLbY/FbGV+hjU6uoBb6oH92u2FMnpS01pee QRolK+3kh8S34Eg3KiiO+U+jgJ3kHSny9NJc54LsgUVvQa2Wmnw5fCvVUBkCk5dk1pYw= X-Google-Smtp-Source: APXvYqxnF2oOX4g/dpUNpVITHs/yRNJ7F7Wyd7Ccjyf2wEiuHD/T9ZZKpBueW+GGYF7//bKWkgGJdw== X-Received: by 2002:a81:1289:: with SMTP id 131mr34294553yws.74.1582353590985; Fri, 21 Feb 2020 22:39:50 -0800 (PST) From: Ryan Moeller X-Google-Original-From: Ryan Moeller To: libvir-list@redhat.com Subject: [PATCH 12/16] Refactor virBhyveProcessBuildBhyveCmd a bit Date: Sat, 22 Feb 2020 01:38:51 -0500 Message-Id: <20200222063855.89637-13-ryan@iXsystems.com> In-Reply-To: <20200222063855.89637-1-ryan@iXsystems.com> References: <20200222063855.89637-1-ryan@iXsystems.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 01M6dsst021793 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Reduces the complexity by isolating loop bodies in separate functions. Signed-off-by: Ryan Moeller --- src/bhyve/bhyve_command.c | 115 ++++++++++++++++++++++---------------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 7e420165aa..bf1cfef3ab 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -44,9 +44,9 @@ VIR_LOG_INIT("bhyve.bhyve_command"); =20 static int -bhyveBuildNetArgStr(bhyveConnPtr driver, - const virDomainDef *def, +bhyveBuildNetArgStr(const virDomainDef *def, virDomainNetDefPtr net, + bhyveConnPtr driver, virCommandPtr cmd, bool dryRun) { @@ -311,6 +311,61 @@ bhyveBuildVirtIODiskArgStr(const virDomainDef *def G_G= NUC_UNUSED, return 0; } =20 +static int +bhyveBuildDiskArgStr(const virDomainDef *def, + virDomainDiskDefPtr disk, + virCommandPtr cmd) +{ + switch (disk->bus) { + case VIR_DOMAIN_DISK_BUS_SATA: + /* Handled by bhyveBuildAHCIControllerArgStr() */ + break; + case VIR_DOMAIN_DISK_BUS_VIRTIO: + if (bhyveBuildVirtIODiskArgStr(def, disk, cmd) < 0) + return -1; + break; + default: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unsupported disk device")); + return -1; + } + return 0; +} + +static int +bhyveBuildControllerArgStr(const virDomainDef *def, + virDomainControllerDefPtr controller, + bhyveConnPtr driver, + virCommandPtr cmd, + unsigned *nusbcontrollers) +{ + switch (controller->type) { + case VIR_DOMAIN_CONTROLLER_TYPE_PCI: + if (controller->model !=3D VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unsupported PCI controller model: " + "only PCI root supported")); + return -1; + } + break; + case VIR_DOMAIN_CONTROLLER_TYPE_SATA: + if (bhyveBuildAHCIControllerArgStr(def, controller, driver, cmd) <= 0) + return -1; + break; + case VIR_DOMAIN_CONTROLLER_TYPE_USB: + if (++*nusbcontrollers > 1) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only single USB controller is supported")); + return -1; + } + + if (bhyveBuildUSBControllerArgStr(def, controller, cmd) < 0) + return -1; + break; + } + return 0; +} + static int bhyveBuildLPCArgStr(const virDomainDef *def G_GNUC_UNUSED, virCommandPtr cmd) @@ -432,8 +487,8 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def, } =20 virCommandPtr -virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, - virDomainDefPtr def, bool dryRun) +virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def, + bool dryRun) { /* * /usr/sbin/bhyve -c 2 -m 256 -AI -H -P \ @@ -443,11 +498,10 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, * -S 31,uart,stdio \ * vm0 */ - size_t i; - int nusbcontrollers =3D 0; - unsigned int nvcpus =3D virDomainDefGetVcpus(def); - virCommandPtr cmd =3D virCommandNew(BHYVE); + size_t i; + unsigned nusbcontrollers =3D 0; + unsigned nvcpus =3D virDomainDefGetVcpus(def); =20 /* CPUs */ virCommandAddArg(cmd, "-c"); @@ -551,52 +605,17 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, =20 /* Devices */ for (i =3D 0; i < def->ncontrollers; i++) { - virDomainControllerDefPtr controller =3D def->controllers[i]; - switch (controller->type) { - case VIR_DOMAIN_CONTROLLER_TYPE_PCI: - if (controller->model !=3D VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROO= T) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("unsupported PCI controller model: = only PCI root supported")); - goto error; - } - break; - case VIR_DOMAIN_CONTROLLER_TYPE_SATA: - if (bhyveBuildAHCIControllerArgStr(def, controller, driver, cm= d) < 0) - goto error; - break; - case VIR_DOMAIN_CONTROLLER_TYPE_USB: - if (++nusbcontrollers > 1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - "%s", _("only single USB controller is supp= orted")); - goto error; - } - - if (bhyveBuildUSBControllerArgStr(def, controller, cmd) < 0) - goto error; - break; - } + if (bhyveBuildControllerArgStr(def, def->controllers[i], driver, c= md, + &nusbcontrollers) < 0) + goto error; } for (i =3D 0; i < def->nnets; i++) { - virDomainNetDefPtr net =3D def->nets[i]; - if (bhyveBuildNetArgStr(driver, def, net, cmd, dryRun) < 0) + if (bhyveBuildNetArgStr(def, def->nets[i], driver, cmd, dryRun) < = 0) goto error; } for (i =3D 0; i < def->ndisks; i++) { - virDomainDiskDefPtr disk =3D def->disks[i]; - - switch (disk->bus) { - case VIR_DOMAIN_DISK_BUS_SATA: - /* Handled by bhyveBuildAHCIControllerArgStr() */ - break; - case VIR_DOMAIN_DISK_BUS_VIRTIO: - if (bhyveBuildVirtIODiskArgStr(def, disk, cmd) < 0) - goto error; - break; - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unsupported disk device")); + if (bhyveBuildDiskArgStr(def, def->disks[i], cmd) < 0) goto error; - } } =20 if (def->ngraphics && def->nvideos) { --=20 2.24.1