From nobody Fri Mar 29 05:09:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1565733760; cv=none; d=zoho.com; s=zohoarc; b=H0hLCqCagX1E2Vs3nS9kNviNZ0Va2FnEWnvJik6+BAx+h3J33UJ9ry3KXOczUGFJyXluDanfxVjyMyL9h60P4EKHHWivsw7HghBYs/aD00NjhOd4Yy+HtJefrPiC2TetB3kxY6WTuVea+2XZIZjzvmFecWG+FwTlXaNdSx2zLxw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565733760; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=JXvCr+NARjYgtA+M4UEbIiGWKqDxpeCbKDu9ysC7DUM=; b=HdaaZbyUSJ8yjH1jUwCp5DzhS8E721UiP6oM55KPgX9udI1uiEJ+ddwL4ZcjGAIVrR6W1uZdtbCeJ1n2NY/lQYk9ksYhWJsikRKOxIX0MdWwVqKx9OW6eA8KJRt6LVN5S4yLlBQvcDz4Qm57DWcgUPeCnDYcaSV/JELUNHbmebk= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 156573376027425.951827133988218; Tue, 13 Aug 2019 15:02:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C74B155E0; Tue, 13 Aug 2019 22:02:36 +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 3F5EA80483; Tue, 13 Aug 2019 22:02:35 +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 6D7DC4A486; Tue, 13 Aug 2019 22:02:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7DM2W3H023366 for ; Tue, 13 Aug 2019 18:02:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6C6137EB96; Tue, 13 Aug 2019 22:02:32 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-118-64.phx2.redhat.com [10.3.118.64]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38B7E805E1 for ; Tue, 13 Aug 2019 22:02:29 +0000 (UTC) From: Jonathon Jongsma To: libvir-list@redhat.com Date: Tue, 13 Aug 2019 17:02:25 -0500 Message-Id: <20190813220225.26437-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: mdev: support persistent devices with mdevctl 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 13 Aug 2019 22:02:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When a host is rebooted, mediated devices disappear from sysfs. mdevctl (https://github.com/mdevctl/mdevctl) is a utility for managing and persisting these devices. It maintains a registry of mediated devices and can start and stop them by UUID. when libvirt attempts to create a new mediated device object, we currently fail if the path does not exist in sysfs. This patch tries a little bit harder by using mdevctl to attempt to activate the device. The approach is fairly naive -- it just calls 'mdevctl start -u $UUID' without checking whether this UUID is registered with mdevctl or not. See https://bugzilla.redhat.com/show_bug.cgi?id=3D1699274 Signed-off-by: Jonathon Jongsma --- NOTES: - an argument could be made that we should simply do nothing here. mdevctl = does have support for automatically activating the mediated device when the pa= rent device becomes available (via udev). So if the administrator set up the m= dev to start automatically, this patch should not even be necessary. That sai= d, I think this patch could still be useful. - As I said above, the approach is pretty naive. I could have checked wheth= er the device was defined in mdevctl's registry and given a different error message ("try registering this device with mdevctl") in that scenario. But I chose to keep it simple. src/util/virmdev.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 3d5488cdae..7a2f0adedc 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -25,6 +25,7 @@ #include "virfile.h" #include "virstring.h" #include "viralloc.h" +#include "vircommand.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 @@ -148,9 +149,24 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedD= eviceModelType model) return NULL; =20 if (!virFileExists(sysfspath)) { - virReportError(VIR_ERR_DEVICE_MISSING, - _("mediated device '%s' not found"), uuidstr); - return NULL; + bool activated =3D false; + /* if the mdev device path doesn't exist, we may still be able to = start + * the device using mdevctl + */ + char *mdevctl =3D virFindFileInPath("mdevctl"); + if (mdevctl) { + const char *runargs[] =3D { mdevctl, "start", "-u", uuidstr, N= ULL }; + if (virRun(runargs, NULL) =3D=3D 0) { + /* check to see if it the device exists now */ + activated =3D virFileExists(sysfspath); + } + } + + if (!activated) { + virReportError(VIR_ERR_DEVICE_MISSING, + _("mediated device '%s' not found"), uuidstr); + return NULL; + } } =20 if (VIR_ALLOC(dev) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list