From nobody Mon Feb 9 17:58:22 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=1622751150; cv=none; d=zohomail.com; s=zohoarc; b=GIfZjn99IN4d30dPcAjwg/2+3OjNBTxU9DC8nL9Hj9lP8NqBGwyb7LS+WFm9DMVCQJ4+9D0ipGeAOB0woiJX+MelzlnqUPK7AntGetF1yRABbTRvkqEo8N+7QfMuwiBjEn541TQynFnBpN9MuZDGQCzopJKjinPZzm9OI726zPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622751150; 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=HLAIJ611Qmt/XxsHm+2I19pGRW3QSBK7buC5QCMbxF8=; b=nu1EByp/HZClWNObvcTWWpcYRKtG78pH+kwhYtVXxgiW4OE/Hapr8P+LbNPyyK8Vs8jXqaBQd5CI8T7NsfSX1EJud5vIvhlgXmybOHFgWyedTdOSWtVIDouumS9/X+i0PqvXPylwwsK3xS535+3ua6G8JrLTjCGPZCuBBbAopYQ= 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 16227511509585.428352551805915; Thu, 3 Jun 2021 13:12:30 -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-351-qa9dteHjNVmUaOqIsfcu8g-1; Thu, 03 Jun 2021 16:12:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7268800D62; Thu, 3 Jun 2021 20:12:20 +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 92A951B428; Thu, 3 Jun 2021 20:12:20 +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 5903E180B7B6; Thu, 3 Jun 2021 20:12:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 153KC1x9000733 for ; Thu, 3 Jun 2021 16:12:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2260E19D7D; Thu, 3 Jun 2021 20:12:01 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-235.phx2.redhat.com [10.3.114.235]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D879F19C44 for ; Thu, 3 Jun 2021 20:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622751149; 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=HLAIJ611Qmt/XxsHm+2I19pGRW3QSBK7buC5QCMbxF8=; b=JLunJdVGsf+aNF8Cw9UkQdPcZv2TJuePK7bSqXzku58SMhk3eAsiwA7re7Olp5OIDT2IUN VUoHIJBofCGj2VCFJbB4kIQTixsFMBpCPlCs4xWQXmm7OYUC2qs+ozKbUkiJVYeJqgsXcw 9mmPW+a788NllLePd7pojFrGxBSE0Fc= X-MC-Unique: qa9dteHjNVmUaOqIsfcu8g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 2/7] nodedev: implement virNodeDevice(Get|Set)Autostart() Date: Thu, 3 Jun 2021 15:11:51 -0500 Message-Id: <20210603201156.3571972-3-jjongsma@redhat.com> In-Reply-To: <20210603201156.3571972-1-jjongsma@redhat.com> References: <20210603201156.3571972-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.14 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" Implement autostart functionality for mediated devices. Signed-off-by: Jonathon Jongsma --- src/conf/virnodedeviceobj.c | 16 ++++ src/conf/virnodedeviceobj.h | 6 ++ src/libvirt_private.syms | 2 + src/node_device/node_device_driver.c | 116 +++++++++++++++++++++++++++ src/node_device/node_device_driver.h | 13 +++ src/node_device/node_device_udev.c | 19 ++++- 6 files changed, 171 insertions(+), 1 deletion(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index b213592b56..deee796440 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -41,6 +41,7 @@ struct _virNodeDeviceObj { used by testdriver */ bool active; bool persistent; + bool autostart; }; =20 struct _virNodeDeviceObjList { @@ -1026,6 +1027,21 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, } =20 =20 +bool +virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj) +{ + return obj->autostart; +} + + +void +virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj, + bool autostart) +{ + obj->autostart =3D autostart; +} + + struct virNodeDeviceObjListRemoveHelperData { virNodeDeviceObjListRemoveIterator callback; diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 7353e4619b..78188be2a2 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -135,6 +135,12 @@ virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj); void virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, bool persistent); +bool +virNodeDeviceObjIsAutostart(virNodeDeviceObj *obj); + +void +virNodeDeviceObjSetAutostart(virNodeDeviceObj *obj, + bool autostart); =20 typedef bool (*virNodeDeviceObjListRemoveIterator)(virNodeDeviceObj *obj, const void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0ced2a7990..dd46fe8750 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1278,6 +1278,7 @@ virNetworkPortDefSaveStatus; virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; virNodeDeviceObjIsActive; +virNodeDeviceObjIsAutostart; virNodeDeviceObjIsPersistent; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; @@ -1294,6 +1295,7 @@ virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; virNodeDeviceObjListRemoveLocked; virNodeDeviceObjSetActive; +virNodeDeviceObjSetAutostart; virNodeDeviceObjSetPersistent; =20 =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 8a0a2c3847..9ebe609aa4 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -962,6 +962,46 @@ virMdevctlStart(virNodeDeviceDef *def, char **errmsg) } =20 =20 +/* gets a virCommand object that executes a mdevctl command to set the + * 'autostart' property of the device to the specified value + */ +virCommand* +nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def, + bool autostart, + char **errmsg) +{ + virCommand *cmd =3D virCommandNewArgList(MDEVCTL, + "modify", + "--uuid", + def->caps->data.mdev.uuid, + NULL); + + if (autostart) + virCommandAddArg(cmd, "--auto"); + else + virCommandAddArg(cmd, "--manual"); + + virCommandSetErrorBuffer(cmd, errmsg); + + return cmd; +} + + +static int +virMdevctlSetAutostart(virNodeDeviceDef *def, bool autostart, char **errms= g) +{ + int status; + g_autoptr(virCommand) cmd =3D NULL; + + cmd =3D nodeDeviceGetMdevctlSetAutostartCommand(def, autostart, errmsg= ); + + if (virCommandRun(cmd, &status) < 0 || status !=3D 0) + return -1; + + return 0; +} + + virCommand* nodeDeviceGetMdevctlListCommand(bool defined, char **output, @@ -1688,3 +1728,79 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, =20 return ret; } + + +int +nodeDeviceSetAutostart(virNodeDevice *device, + int autostart) +{ + int ret =3D -1; + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def =3D NULL; + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceSetAutostartEnsureACL(device->conn, def) < 0) + goto cleanup; + + if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) { + if (!virNodeDeviceObjIsPersistent(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cannot set autostart for transient dev= ice")); + goto cleanup; + } + + if (autostart !=3D virNodeDeviceObjIsAutostart(obj)) { + g_autofree char *errmsg =3D NULL; + + if (virMdevctlSetAutostart(def, autostart, &errmsg) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to set autostart on '%s': %s"), + def->name, + errmsg && errmsg[0] !=3D '\0' ? errmsg : _(= "Unknown Error")); + goto cleanup; + } + virNodeDeviceObjSetAutostart(obj, autostart); + } + ret =3D 0; + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("Unsupported device type")); + } + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} + + +int +nodeDeviceGetAutostart(virNodeDevice *device, + int *autostart) +{ + virNodeDeviceObj *obj =3D NULL; + virNodeDeviceDef *def =3D NULL; + int ret =3D -1; + + if (nodeDeviceInitWait() < 0) + return -1; + + if (!(obj =3D nodeDeviceObjFindByName(device->name))) + return -1; + def =3D virNodeDeviceObjGetDef(obj); + + if (virNodeDeviceGetAutostartEnsureACL(device->conn, def) < 0) + goto cleanup; + + *autostart =3D virNodeDeviceObjIsAutostart(obj); + ret =3D 0; + + cleanup: + virNodeDeviceObjEndAPI(&obj); + return ret; +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index edd763f0e4..d178a18180 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -171,3 +171,16 @@ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *ds= t, int nodeDeviceCreate(virNodeDevice *dev, unsigned int flags); + +int +nodeDeviceSetAutostart(virNodeDevice *dev, + int autostart); + +int +nodeDeviceGetAutostart(virNodeDevice *dev, + int *autostart); + +virCommand* +nodeDeviceGetMdevctlSetAutostartCommand(virNodeDeviceDef *def, + bool autostart, + char **errmsg); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index f99578414d..21273083a6 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1488,6 +1488,8 @@ udevAddOneDevice(struct udev_device *device) bool new_device =3D true; int ret =3D -1; bool was_persistent =3D false; + bool autostart =3D true; + bool is_mdev; =20 def =3D g_new0(virNodeDeviceDef, 1); =20 @@ -1509,17 +1511,28 @@ udevAddOneDevice(struct udev_device *device) if (udevSetParent(device, def) !=3D 0) goto cleanup; =20 + is_mdev =3D def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV; + if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, def->name)))= { objdef =3D virNodeDeviceObjGetDef(obj); =20 - if (def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) + if (is_mdev) nodeDeviceDefCopyFromMdevctl(def, objdef); was_persistent =3D virNodeDeviceObjIsPersistent(obj); + autostart =3D virNodeDeviceObjIsAutostart(obj); + /* If the device was defined by mdevctl and was never instantiated= , it * won't have a sysfs path. We need to emit a CREATED event... */ new_device =3D (objdef->sysfs_path =3D=3D NULL); =20 virNodeDeviceObjEndAPI(&obj); + } else { + /* All non-mdev devices report themselves as autostart since they + * should still be present and active after a reboot unless the de= vice + * is removed from the host. Mediated devices can only be persiste= nt if + * they are in already in the device list from parsing the mdevctl + * output. */ + autostart =3D !is_mdev; } =20 /* If this is a device change, the old definition will be freed @@ -1527,6 +1540,7 @@ udevAddOneDevice(struct udev_device *device) if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; virNodeDeviceObjSetPersistent(obj, was_persistent); + virNodeDeviceObjSetAutostart(obj, autostart); objdef =3D virNodeDeviceObjGetDef(obj); =20 if (new_device) @@ -1930,6 +1944,7 @@ udevSetupSystemDev(void) goto cleanup; =20 virNodeDeviceObjSetActive(obj, true); + virNodeDeviceObjSetAutostart(obj, true); =20 virNodeDeviceObjEndAPI(&obj); =20 @@ -2331,6 +2346,8 @@ static virNodeDeviceDriver udevNodeDeviceDriver =3D { .nodeDeviceDefineXML =3D nodeDeviceDefineXML, /* 7.3.0 */ .nodeDeviceUndefine =3D nodeDeviceUndefine, /* 7.3.0 */ .nodeDeviceCreate =3D nodeDeviceCreate, /* 7.3.0 */ + .nodeDeviceSetAutostart =3D nodeDeviceSetAutostart, /* 7.5.0 */ + .nodeDeviceGetAutostart =3D nodeDeviceGetAutostart, /* 7.5.0 */ }; =20 =20 --=20 2.31.1