From nobody Sat May 4 08:19:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1583110517; cv=none; d=zohomail.com; s=zohoarc; b=T9tkj01Iq1R3b8dkUPShmWrxMpJlTbpEXZnB19MGlFzsP221PozWpNIZ8pkorS/A5OM+8iiZgnhqYx5pGqhrlE0bUj+hMLPgNEsYrcyxUAvG/ktQRjorsHOm7LS2vR+wHSSc9WqWafZrN0p8IFdb1xu74Dp+gDC+toJzCahndYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583110517; 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=Uw7bvfIVgCFGdEEnz2uvVPfWTpUcf5AVWd5dHDRrB70=; b=VYm35amxLqrayLLohbcYM+9yzcIZlRcDJ3v5h/yNQjEqGP9CdGWOpK3AxY2ZI8nh/sSwl6xhG3jouumGh4YJZT7KWMemv9DSDTnTmYsBnfoud24oFQBJTIPtz7GFxY9dcikS9GIZRdyZCZlq21OcSQZJdEe3KOTN4MpheD2jGaY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1583110517162571.5501713195112; Sun, 1 Mar 2020 16:55:17 -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-153-wI6gvbdYN7CJrO_xZIQV1Q-1; Sun, 01 Mar 2020 19:55:14 -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 532628018A4; Mon, 2 Mar 2020 00:55:08 +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 ED1CE60BF7; Mon, 2 Mar 2020 00:55:07 +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 7E6D786A04; Mon, 2 Mar 2020 00:55:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0220sZB9020382 for ; Sun, 1 Mar 2020 19:54:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 726DB10F1CD8; Mon, 2 Mar 2020 00:54:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6DF2910F1CD7 for ; Mon, 2 Mar 2020 00:54:32 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 BAA128007A4 for ; Mon, 2 Mar 2020 00:54:32 +0000 (UTC) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-148-CtgKdCFgPkqllxDG3t1n5A-1; Sun, 01 Mar 2020 19:54:30 -0500 Received: by mail-qv1-f67.google.com with SMTP id ff2so4121601qvb.3 for ; Sun, 01 Mar 2020 16:54:30 -0800 (PST) Received: from localhost.localdomain ([2804:431:c7cb:f65:3196:5ed7:3478:df97]) by smtp.gmail.com with ESMTPSA id g5sm2808982qkm.4.2020.03.01.16.54.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 16:54:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583110516; 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=Uw7bvfIVgCFGdEEnz2uvVPfWTpUcf5AVWd5dHDRrB70=; b=B9Bz2Jl6Ylg5IVuXRgAfvHuhKbtTnCIy7eyFo/zWmkVylOTILLlv5gMXT/DNxsRfkrcP7v Hv3ZYWFmKHhbReakplmKl7nbaS6XXiHvtculvUmV482JDjvd6LR2676QS9lJVymey89rhP KPz4wQ7y1ZMwnR1kBxLyzQSneKcP+iU= X-MC-Unique: wI6gvbdYN7CJrO_xZIQV1Q-1 X-MC-Unique: CtgKdCFgPkqllxDG3t1n5A-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=K4vcmriOsNt5IFgtSTuuMdlyRHEXcxThMHmNlBevBOg=; b=Zjh7rjRHBxaX3dlg7cKS6BPFevFhm/NmYxnufZtZRpunwwkzb+Vb6MhMVqm7XSucMM d/kKj9eN4Kw6eCt7wsiVB0cEUYT9+Nw5h2ZdFGF88es94Ex3xU+WADkwZqeJbTTUuO8P PcSMEis+CdUAdQaCdBDSFEUQz6XKtmu4AQ94lg/SsKHYYzKBpTfjZr9weAh00CVOY2h5 sPxK1kQp97Q7kVZ6RHQF9DegpTJx0ZlkFgdcgYmxMc7yfhY2yQwiiqz2X9ku7PKWSASx cQmipltS2SqDGhm9Xua3YpkCCSJER6UkulGCcK/iW6zPZQmvvewAzfGdKFepexcrpajS uURA== X-Gm-Message-State: APjAAAUtnKO0kCQePT7T+Mc304VNL4x4aPit/6LJFiRGFgZuvCxqw2/K A5+f+MwKHLKUxMcDnL8Zdd2DXqeK X-Google-Smtp-Source: APXvYqxpw3Cf5/5vBFgsWt4MCgXFq0suj69x9uZp8IZkBZUeVnbcHAj35X+1217ZF6X3jjONhTAHig== X-Received: by 2002:a05:6214:1408:: with SMTP id n8mr10338006qvx.189.1583110469725; Sun, 01 Mar 2020 16:54:29 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v5 1/2] lxc: Add Real Time Clock device into allowed devices Date: Sun, 1 Mar 2020 21:54:12 -0300 Message-Id: <20200302005413.10715-2-jcfaracco@gmail.com> In-Reply-To: <20200302005413.10715-1-jcfaracco@gmail.com> References: <20200302005413.10715-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 0220sZB9020382 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" This commit share host Real Time Clock device (rtc) into LXC containers to support hardware clock. This should be available setting up a `rtc` timer under clock section. Since this option is not emulated, it should be available only for `localtime` clock. This option should be readonly due to security reasons. Before: root# hwclock --verbose hwclock from util-linux 2.32.1 System Time: 1581877557.598365 Trying to open: /dev/rtc0 Trying to open: /dev/rtc Trying to open: /dev/misc/rtc No usable clock interface found. hwclock: Cannot access the Hardware Clock via any known method. Now: root# hwclock 2020-02-16 18:23:55.374134+00:00 root# hwclock -w hwclock: ioctl(RTC_SET_TIME) to /dev/rtc to set the time failed: Permission denied Signed-off-by: Julio Faracco Reviewed-by: Michal Privoznik --- docs/formatdomain.html.in | 2 +- src/lxc/lxc_cgroup.c | 33 ++++++++++++++++++++ src/lxc/lxc_controller.c | 66 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 28770188dd..96d06e9c3e 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2465,7 +2465,7 @@ being modified, and can be one of "platform" (currently unsupported), "hpet" (libxl, xen, qemu), "kvmclock" (qemu), - "pit" (qemu), "rtc" (qemu), "tsc" (libxl, qemu - + "pit" (qemu), "rtc" (qemu, lxc), "tsc" (libxl, qemu - since 3.2.0), "hypervclock" (qemu - since 1.2.2) or "armvtimer" (qemu - since 6.1.0). diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 952d021418..065996b3a4 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -333,6 +333,39 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr = def, VIR_CGROUP_DEVICE_RWM) < 0) return -1; =20 + VIR_DEBUG("Allowing timers char devices"); + + /* Sync'ed with Host clock */ + for (i =3D 0; i < def->clock.ntimers; i++) { + virDomainTimerDefPtr timer =3D def->clock.timers[i]; + + /* Check if "present" is set to "no" otherwise enable it. */ + if (!timer->present) + continue; + + switch ((virDomainTimerNameType)timer->name) { + case VIR_DOMAIN_TIMER_NAME_PLATFORM: + case VIR_DOMAIN_TIMER_NAME_TSC: + case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: + case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: + case VIR_DOMAIN_TIMER_NAME_PIT: + case VIR_DOMAIN_TIMER_NAME_HPET: + case VIR_DOMAIN_TIMER_NAME_ARMVTIMER: + case VIR_DOMAIN_TIMER_NAME_LAST: + break; + case VIR_DOMAIN_TIMER_NAME_RTC: + if (virFileExists("/dev/rtc")) { + if (virCgroupAllowDevicePath(cgroup, "/dev/rtc", + VIR_CGROUP_DEVICE_READ, + false) < 0) + return -1; + } else { + VIR_DEBUG("Ignoring non-existent device /dev/rtc"); + } + break; + } + } + VIR_DEBUG("Device whitelist complete"); =20 return 0; diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index fa7b9dd0e7..d97c4ad1b5 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1530,6 +1530,69 @@ static int virLXCControllerPopulateDevices(virLXCCon= trollerPtr ctrl) } =20 =20 +static int +virLXCControllerSetupTimers(virLXCControllerPtr ctrl) +{ + g_autofree char *path =3D NULL; + size_t i; + struct stat sb; + virDomainDefPtr def =3D ctrl->def; + const char *rtc_dev =3D "/dev/rtc"; + + /* Not sync'ed with Host clock */ + if (def->clock.offset !=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME) + return 0; + + for (i =3D 0; i < def->clock.ntimers; i++) { + dev_t dev; + virDomainTimerDefPtr timer =3D def->clock.timers[i]; + + /* Check if "present" is set to "no" otherwise enable it. */ + if (!timer->present) + continue; + + switch ((virDomainTimerNameType)timer->name) { + case VIR_DOMAIN_TIMER_NAME_PLATFORM: + case VIR_DOMAIN_TIMER_NAME_TSC: + case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: + case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: + case VIR_DOMAIN_TIMER_NAME_PIT: + case VIR_DOMAIN_TIMER_NAME_HPET: + case VIR_DOMAIN_TIMER_NAME_ARMVTIMER: + case VIR_DOMAIN_TIMER_NAME_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported timer type (name) '%s'"), + virDomainTimerNameTypeToString(timer->name)); + return -1; + case VIR_DOMAIN_TIMER_NAME_RTC: + if (stat(rtc_dev, &sb) < 0) { + virReportSystemError(errno, _("Unable to access %s"), + rtc_dev); + return -1; + } + + path =3D g_strdup_printf("/%s/%s.dev/%s", LXC_STATE_DIR, + ctrl->def->name, "/rtc"); + + dev =3D makedev(major(sb.st_rdev), minor(sb.st_rdev)); + if (mknod(path, S_IFCHR, dev) < 0 || + chmod(path, sb.st_mode)) { + virReportSystemError(errno, + _("Failed to make device %s"), + path); + return -1; + } + + if (lxcContainerChown(ctrl->def, path) < 0) + return -1; + break; + } + } + + return 0; +} + + static int virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef, virDomainHostdevDefPtr def, @@ -2321,6 +2384,9 @@ virLXCControllerRun(virLXCControllerPtr ctrl) if (virLXCControllerPopulateDevices(ctrl) < 0) goto cleanup; =20 + if (virLXCControllerSetupTimers(ctrl) < 0) + goto cleanup; + if (virLXCControllerSetupAllDisks(ctrl) < 0) goto cleanup; =20 --=20 2.24.1 From nobody Sat May 4 08:19:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.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 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1583110524; cv=none; d=zohomail.com; s=zohoarc; b=eFYm/kIy3EzG4jhUBjassKOXhlordY5aG08hEdALbOi3avgS2QVyxUIKs5DM2sD8/34cMEPW1pa+mNMh7b2DYX+kHC8yFjktdlISmkiab5kaKL7jVb+/VOhPn4UjO04KZwliWEeBK1oWexBoKwoy/a/khOJ5cFwFku9OUkuca+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583110524; 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=3qLXN7xSGI02zngdhx6c/gp0bFKpHi8Tz149yqMNmmo=; b=Y910dYgWto2dU7w5CbXkH96yjqe0ncZ/5TpbTyK08hZE+YT4Kc+Jdt5y4Dyy5g3fdZnwZXYCz5PutFWlaTTSprclwKE1l2ROTSRL8t33NMn0tAY4qfFQMClIJYuxb2a9LSrjmvam4HtHI8C6zdDjXg807UciaWh+AGIKTI/aofY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.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 [207.211.31.120]) by mx.zohomail.com with SMTPS id 1583110524593699.5608728450746; Sun, 1 Mar 2020 16:55:24 -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-309-T34t3UD-P_ST8KRIvrHQsw-1; Sun, 01 Mar 2020 19:55:21 -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 4C4178017CC; Mon, 2 Mar 2020 00:54: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 D44A460BF7; Mon, 2 Mar 2020 00:54:43 +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 6451618095FF; Mon, 2 Mar 2020 00:54:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0220sY9P020372 for ; Sun, 1 Mar 2020 19:54:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id A92D72166B2D; Mon, 2 Mar 2020 00:54:34 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A531A2166B2B for ; Mon, 2 Mar 2020 00:54:34 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.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 8A5BC800FC4 for ; Mon, 2 Mar 2020 00:54:34 +0000 (UTC) Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-37-mJ3bLQD5M8GqWesH1H9LXw-1; Sun, 01 Mar 2020 19:54:32 -0500 Received: by mail-qk1-f195.google.com with SMTP id f3so8581715qkh.3 for ; Sun, 01 Mar 2020 16:54:32 -0800 (PST) Received: from localhost.localdomain ([2804:431:c7cb:f65:3196:5ed7:3478:df97]) by smtp.gmail.com with ESMTPSA id g5sm2808982qkm.4.2020.03.01.16.54.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 16:54:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583110523; 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=3qLXN7xSGI02zngdhx6c/gp0bFKpHi8Tz149yqMNmmo=; b=NBx36VHu3kQCr1av29maM7rB+nioPCZk8y33mXXOHnzMGJlJeKOBIyODUmJGEAd7oLJYDC yCE5oljnSA1uUCy7U0fEcJMUnVVoK9KP0bjiBHYX3l9SSoDyYYS6DKvFEaHjcaBpY0dEjp OPZq5ah6jJe1eRv84F8aiDrYTG/ojfY= X-MC-Unique: T34t3UD-P_ST8KRIvrHQsw-1 X-MC-Unique: mJ3bLQD5M8GqWesH1H9LXw-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=U6a57mvFeVc1dlL47ELRE10M9ZbGwh7LrYLTsJpbSX8=; b=M/TCdyGPQpaB38WwIscaX9ZnoTxEyORWK4d33oSw0+Z5IYZa78HkOUFHGvh5YgNXV9 N8DlYq2QCVBxxHolyosH54G+qc7xG2EIZoH9LfilJuAqEhKgipsH4e2dQTdMh1gfkhzD bkLxfTx5JoHySI15eOKEh/HHhoOpDENWzDVfOs5mkTDtI9bljRVakwWLKar3Aw0hJICC xmNtV2BdpeJ0ianbOzSVrVO47YwvH8MtsjmcFLMbGXB3sKUDrRIziQhTDbtXwDBpThXh 6kwJ7jfc0T83Si/Txb3sqNN8rfcX2J3XmAaISJTMpjR+VMJ+vm7Ohm2GHSdtZAQw2VpX UVqA== X-Gm-Message-State: APjAAAW21A5XfOsdP3JKHK3rK+Wx0lrHepxJIRakiLzQxoSW0zyLmtNB ym9EPuS3On+SniNkq2kUb85StpIw X-Google-Smtp-Source: APXvYqwmRwt+wYmiVOvpKkIuSHtXO7qj3MlYFJoLLjmF8xX3P5mIAqSZa4yw013fPkjIDONWf4rbZQ== X-Received: by 2002:a37:7a04:: with SMTP id v4mr14607174qkc.246.1583110471538; Sun, 01 Mar 2020 16:54:31 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Subject: [PATCH v5 2/2] lxc: Add HPET device into allowed devices Date: Sun, 1 Mar 2020 21:54:13 -0300 Message-Id: <20200302005413.10715-3-jcfaracco@gmail.com> In-Reply-To: <20200302005413.10715-1-jcfaracco@gmail.com> References: <20200302005413.10715-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id 0220sY9P020372 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" This commit is related to RTC timer device too. HPET is being shared from host device through `localtime` clock. This timer is available creating a new timer using `hpet` name. Signed-off-by: Julio Faracco Reviewed-by: Michal Privoznik --- docs/formatdomain.html.in | 2 +- src/lxc/lxc_cgroup.c | 11 ++++++++++- src/lxc/lxc_controller.c | 24 +++++++++++++++++++++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 96d06e9c3e..d1d2955e51 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -2464,7 +2464,7 @@ The name attribute selects which timer is being modified, and can be one of "platform" (currently unsupported), - "hpet" (libxl, xen, qemu), "kvmclock" (qemu), + "hpet" (libxl, xen, qemu, lxc), "kvmclock" (qemu), "pit" (qemu), "rtc" (qemu, lxc), "tsc" (libxl, qemu - since 3.2.0), "hypervclock" (qemu - since 1.2.2) or diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 065996b3a4..cb5d0da980 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -349,7 +349,6 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr d= ef, case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: case VIR_DOMAIN_TIMER_NAME_PIT: - case VIR_DOMAIN_TIMER_NAME_HPET: case VIR_DOMAIN_TIMER_NAME_ARMVTIMER: case VIR_DOMAIN_TIMER_NAME_LAST: break; @@ -363,6 +362,16 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr = def, VIR_DEBUG("Ignoring non-existent device /dev/rtc"); } break; + case VIR_DOMAIN_TIMER_NAME_HPET: + if (virFileExists("/dev/hpet")) { + if (virCgroupAllowDevicePath(cgroup, "/dev/hpet", + VIR_CGROUP_DEVICE_READ, + false) < 0) + return -1; + } else { + VIR_DEBUG("Ignoring non-existent device /dev/hpet"); + } + break; } } =20 diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index d97c4ad1b5..8dcfd4c97e 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1538,6 +1538,7 @@ virLXCControllerSetupTimers(virLXCControllerPtr ctrl) struct stat sb; virDomainDefPtr def =3D ctrl->def; const char *rtc_dev =3D "/dev/rtc"; + const char *hpet_dev =3D "/dev/hpet"; =20 /* Not sync'ed with Host clock */ if (def->clock.offset !=3D VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME) @@ -1557,7 +1558,6 @@ virLXCControllerSetupTimers(virLXCControllerPtr ctrl) case VIR_DOMAIN_TIMER_NAME_KVMCLOCK: case VIR_DOMAIN_TIMER_NAME_HYPERVCLOCK: case VIR_DOMAIN_TIMER_NAME_PIT: - case VIR_DOMAIN_TIMER_NAME_HPET: case VIR_DOMAIN_TIMER_NAME_ARMVTIMER: case VIR_DOMAIN_TIMER_NAME_LAST: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -1583,6 +1583,28 @@ virLXCControllerSetupTimers(virLXCControllerPtr ctrl) return -1; } =20 + if (lxcContainerChown(ctrl->def, path) < 0) + return -1; + break; + case VIR_DOMAIN_TIMER_NAME_HPET: + if (stat(hpet_dev, &sb) < 0) { + virReportSystemError(errno, _("Unable to access %s"), + hpet_dev); + return -1; + } + + path =3D g_strdup_printf("/%s/%s.dev/%s", LXC_STATE_DIR, + ctrl->def->name, "/hpet"); + + dev =3D makedev(major(sb.st_rdev), minor(sb.st_rdev)); + if (mknod(path, S_IFCHR, dev) < 0 || + chmod(path, sb.st_mode)) { + virReportSystemError(errno, + _("Failed to make device %s"), + path); + return -1; + } + if (lxcContainerChown(ctrl->def, path) < 0) return -1; break; --=20 2.24.1