From nobody Tue Feb 10 12:40:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618004036; cv=none; d=zohomail.com; s=zohoarc; b=Ya4Iid8CVJGS/hKaZ1DmcfJd7DJsfk5qmUVWjCHVVHOCAbROaondq9PjUl5YvUjhjUhuTYLFq7MDKimuTf1RotYw2jEq3uYtPXMa+V+6jmfZ+LoiSnhU27Ei7BY7eYjhIRA9xLLPdHpqOUwJdT6JdEe7kUYwnT00bRHXcR6WPfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618004036; h=Content-Type:Content-Transfer-Encoding:Cc: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=d+pXcocvh5+4oVBLxRQr2CVqZ/utsyzBaE+Kc2Wg4yg=; b=L004Yu6GBbjqDDRbVrtgxlO/HScFsuU8cRmraCWptGeaYEydephU7pDqPCG2drlurRHjEF7qL2qvrbhRlNidYMjXr0INJbGB00lwH2gVFuIf2e7hwAHSaEWLQav3zCSql5h5BiAF/zHQhZ7gqHcwQDvRylFLpDFKZEjpMPet9kE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618004036712376.0280115273674; Fri, 9 Apr 2021 14:33:56 -0700 (PDT) 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-195-Ja0b9NC4O0ynHEsdSvvD0g-1; Fri, 09 Apr 2021 17:33:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BF15C8190BE; Fri, 9 Apr 2021 21:33:45 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E2F95D6D3; Fri, 9 Apr 2021 21:33:45 +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 65FDE1806D20; Fri, 9 Apr 2021 21:33:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 139LXERQ032641 for ; Fri, 9 Apr 2021 17:33:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 14A695D6AD; Fri, 9 Apr 2021 21:33:14 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-25.phx2.redhat.com [10.3.113.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCC795D6A1; Fri, 9 Apr 2021 21:33:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618004034; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=d+pXcocvh5+4oVBLxRQr2CVqZ/utsyzBaE+Kc2Wg4yg=; b=BCZVPTsPmnJe3NLNlvlOk4zoufv+/Pg9/MrWilfitUe43g8iWF5LEwO1uFFzbuEQ0x5bnM R28odiMUj/W+aFnjkPXIu2HHmbx9wVKsq83Yh7+7pKe8KY9K24XaPeZtxnJmX/yLcCyXNZ /vKdPfRJpgR6EGeh0QdJL+OUKuJOB5g= X-MC-Unique: Ja0b9NC4O0ynHEsdSvvD0g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 07/11] nodedev: driver: Create a generic mdevctl command translator Date: Fri, 9 Apr 2021 16:33:02 -0500 Message-Id: <20210409213306.3971286-8-jjongsma@redhat.com> In-Reply-To: <20210409213306.3971286-1-jjongsma@redhat.com> References: <20210409213306.3971286-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Erik Skultety 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.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" From: Erik Skultety Currently there are dedicated wrappers to construct mdevctl command. These are mostly fine except for the one that translates both "start" and "define" commands, only because mdevctl takes the same set of arguments. Instead, keep the wrappers, but let them call a single global translator that handles all the mdevctl command differences and commonalities. Signed-off-by: Erik Skultety Signed-off-by: Jonathon Jongsma --- src/node_device/node_device_driver.c | 125 ++++++++++++++++----------- src/node_device/node_device_driver.h | 6 +- tests/nodedevmdevctltest.c | 4 +- 3 files changed, 79 insertions(+), 56 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index c25558cf05..0fddfdde86 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -702,42 +702,75 @@ nodeDeviceFindAddressByName(const char *name) } =20 =20 -/* the mdevctl 'start' and 'define' commands accept almost the exact same - * arguments, so provide a common implementation that can be wrapped by a = more - * specific function */ -static virCommand* -nodeDeviceGetMdevctlDefineCreateCommand(virNodeDeviceDef *def, - const char *subcommand, - char **uuid_out, - char **errmsg) +static virCommand * +nodeDeviceGetMdevctlCommand(virNodeDeviceDefPtr def, + virMdevctlCommand cmd_type, + char **outbuf, + char **errbuf) { - virCommandPtr cmd; - g_autofree char *json =3D NULL; - g_autofree char *parent_addr =3D nodeDeviceFindAddressByName(def->pare= nt); - - if (!parent_addr) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unable to find parent device '%s'"), def->parent= ); - return NULL; + g_autofree char *parent_addr =3D NULL; + virCommand *cmd =3D NULL; + const char *subcommand =3D virMdevctlCommandTypeToString(cmd_type); + g_autofree char *inbuf =3D NULL; + + switch (cmd_type) { + case MDEVCTL_CMD_CREATE: + /* now is the time to make sure "create" is replaced with "start" = on + * mdevctl cmdline */ + cmd =3D virCommandNewArgList(MDEVCTL, "start", NULL); + break; + case MDEVCTL_CMD_STOP: + case MDEVCTL_CMD_START: + case MDEVCTL_CMD_DEFINE: + case MDEVCTL_CMD_UNDEFINE: + cmd =3D virCommandNewArgList(MDEVCTL, subcommand, NULL); + break; + case MDEVCTL_CMD_LAST: + default: + /* SHOULD NEVER HAPPEN */ + break; } =20 - if (nodeDeviceDefToMdevctlConfig(def, &json) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("couldn't convert node device def to mdevctl JSON= ")); - return NULL; - } + switch (cmd_type) { + case MDEVCTL_CMD_CREATE: + case MDEVCTL_CMD_DEFINE: + parent_addr =3D nodeDeviceFindAddressByName(def->parent); =20 - cmd =3D virCommandNewArgList(MDEVCTL, subcommand, NULL); - virCommandAddArgPair(cmd, "--parent", parent_addr); - virCommandAddArgPair(cmd, "--jsonfile", "/dev/stdin"); + if (!parent_addr) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to find parent device '%s'"), def->pa= rent); + return NULL; + } + + if (nodeDeviceDefToMdevctlConfig(def, &inbuf) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("couldn't convert node device def to mdevctl = JSON")); + return NULL; + } =20 - virCommandSetInputBuffer(cmd, json); + virCommandAddArgPair(cmd, "--parent", parent_addr); + virCommandAddArgPair(cmd, "--jsonfile", "/dev/stdin"); + + virCommandSetInputBuffer(cmd, inbuf); + virCommandSetOutputBuffer(cmd, outbuf); + break; + + case MDEVCTL_CMD_UNDEFINE: + case MDEVCTL_CMD_STOP: + case MDEVCTL_CMD_START: + /* No special handling here, we only need to pass UUID with these = */ + break; + case MDEVCTL_CMD_LAST: + default: + /* SHOULD NEVER HAPPEN */ + break; + } =20 + /* Fill in UUID for commands that need it */ if (def->caps->data.mdev.uuid) virCommandAddArgPair(cmd, "--uuid", def->caps->data.mdev.uuid); =20 - virCommandSetOutputBuffer(cmd, uuid_out); - virCommandSetErrorBuffer(cmd, errmsg); + virCommandSetErrorBuffer(cmd, errbuf); =20 return cmd; } @@ -747,8 +780,7 @@ nodeDeviceGetMdevctlCreateCommand(virNodeDeviceDef *def, char **uuid_out, char **errmsg) { - return nodeDeviceGetMdevctlDefineCreateCommand(def, "start", uuid_out, - errmsg); + return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_CREATE, uuid_out, = errmsg); } =20 virCommand* @@ -756,8 +788,7 @@ nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *def, char **uuid_out, char **errmsg) { - return nodeDeviceGetMdevctlDefineCreateCommand(def, "define", uuid_out, - errmsg); + return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_DEFINE, uuid_out, = errmsg); } =20 =20 @@ -891,31 +922,24 @@ nodeDeviceCreateXML(virConnectPtr conn, =20 =20 virCommandPtr -nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg) +nodeDeviceGetMdevctlStopCommand(virNodeDeviceDefPtr def, + char **errmsg) { - virCommandPtr cmd =3D virCommandNewArgList(MDEVCTL, "stop", NULL); - virCommandAddArgPair(cmd, "--uuid", uuid); - virCommandSetErrorBuffer(cmd, errmsg); - return cmd; - + return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_STOP, NULL, errmsg= ); } =20 virCommand * -nodeDeviceGetMdevctlUndefineCommand(const char *uuid, char **errmsg) +nodeDeviceGetMdevctlUndefineCommand(virNodeDeviceDefPtr def, + char **errmsg) { - virCommand *cmd =3D virCommandNewArgList(MDEVCTL, "undefine", NULL); - virCommandAddArgPair(cmd, "--uuid", uuid); - virCommandSetErrorBuffer(cmd, errmsg); - return cmd; + return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_UNDEFINE, NULL, er= rmsg); } =20 virCommand* -nodeDeviceGetMdevctlStartCommand(const char *uuid, char **errmsg) +nodeDeviceGetMdevctlStartCommand(virNodeDeviceDef *def, + char **errmsg) { - virCommand *cmd =3D virCommandNewArgList(MDEVCTL, "start", NULL); - virCommandAddArgPair(cmd, "--uuid", uuid); - virCommandSetErrorBuffer(cmd, errmsg); - return cmd; + return nodeDeviceGetMdevctlCommand(def, MDEVCTL_CMD_START, NULL, errms= g); } =20 static int @@ -924,7 +948,7 @@ virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg) int status; g_autoptr(virCommand) cmd =3D NULL; =20 - cmd =3D nodeDeviceGetMdevctlStopCommand(def->caps->data.mdev.uuid, err= msg); + cmd =3D nodeDeviceGetMdevctlStopCommand(def, errmsg); =20 if (virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; @@ -939,8 +963,7 @@ virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg) int status; g_autoptr(virCommand) cmd =3D NULL; =20 - cmd =3D nodeDeviceGetMdevctlUndefineCommand(def->caps->data.mdev.uuid, - errmsg); + cmd =3D nodeDeviceGetMdevctlUndefineCommand(def, errmsg); =20 if (virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; @@ -955,7 +978,7 @@ virMdevctlStart(virNodeDeviceDef *def, char **errmsg) int status; g_autoptr(virCommand) cmd =3D NULL; =20 - cmd =3D nodeDeviceGetMdevctlStartCommand(def->caps->data.mdev.uuid, er= rmsg); + cmd =3D nodeDeviceGetMdevctlStartCommand(def, errmsg); =20 if (virCommandRun(cmd, &status) < 0 || status !=3D 0) return -1; diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index aaeed588e8..0fea75a118 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -152,11 +152,11 @@ nodeDeviceGetMdevctlDefineCommand(virNodeDeviceDef *d= ef, char **errmsg); =20 virCommandPtr -nodeDeviceGetMdevctlStopCommand(const char *uuid, +nodeDeviceGetMdevctlStopCommand(virNodeDeviceDefPtr def, char **errmsg); =20 virCommand * -nodeDeviceGetMdevctlUndefineCommand(const char *uuid, +nodeDeviceGetMdevctlUndefineCommand(virNodeDeviceDefPtr def, char **errmsg); =20 virCommandPtr @@ -181,7 +181,7 @@ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, virNodeDeviceDef *src); =20 virCommand* -nodeDeviceGetMdevctlStartCommand(const char *uuid, +nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr def, char **errmsg); =20 int diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 8a37dd2e80..e766ae8f34 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -130,7 +130,7 @@ testMdevctlCreateOrDefineHelper(const void *data) mdevxml, cmdlinefile, jsonfile); } =20 -typedef virCommand* (*GetStopUndefineCmdFunc)(const char *uuid, char **err= buf); +typedef virCommand* (*GetStopUndefineCmdFunc)(virNodeDeviceDef *def, char = **errbuf); struct UuidCommandTestInfo { const char *filename; virMdevctlCommand command; @@ -150,7 +150,7 @@ testMdevctlUuidCommand(GetStopUndefineCmdFunc func, if (!(def =3D virNodeDeviceDefParseFile(mdevxml, EXISTING_DEVICE, "QEM= U"))) goto cleanup; =20 - cmd =3D func(def->caps->data.mdev.uuid, &errmsg); + cmd =3D func(def, &errmsg); =20 if (!cmd) goto cleanup; --=20 2.26.3