From nobody Sun Feb 8 03:38:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1596023025; cv=none; d=zohomail.com; s=zohoarc; b=boY0kD3RQHQIGl62nfGzz4LzAmsTkHZJrLfXyrI9WW1z8Sva2cO7KLF3O3TWcbMRg2PVkh0R9nS/e8OKwqru2CpHMm71N6orl+EXnUjz/0EpztNo1tMDf1F/QaaeSFwLsH/1NYkVSd+2G0asgo3dTACCevWZtx0F1OQsiYNdOIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596023025; 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=Lq8EHz7l+/e/R9ZzMgebRHehFiBBA/O2TS1eYfQTEKo=; b=bH3Vn8iZwtwqArWt/YNscIO+nXGtvU9hmNEziJK0K5gMuWhEFk8sZyal7Er0diioxofSGxxj22nwqRbjAHIi/E5zDCLX9nno7hIOhKuWYF6Jlan9MVZQEyOZYCFARFJYWwJSqIY7I/Mvr+kAKD6w21H0EB0PGKwbanCEls/nHHY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1596023025269976.1171903386952; Wed, 29 Jul 2020 04:43:45 -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-40-GwmdoKYBN4KxttEDMLeROw-1; Wed, 29 Jul 2020 07:43:41 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09A5F1800D4A; Wed, 29 Jul 2020 11:43:34 +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 B2CD319C71; Wed, 29 Jul 2020 11:43:33 +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 BA96E1809547; Wed, 29 Jul 2020 11:43:30 +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 06TBhTUW002538 for ; Wed, 29 Jul 2020 07:43:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id C2A1771906; Wed, 29 Jul 2020 11:43:29 +0000 (UTC) Received: from carol.localdomain (unknown [10.40.195.78]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C3CA771910; Wed, 29 Jul 2020 11:43:26 +0000 (UTC) Received: from carol.redhat.com (carol.k8r.cz [127.0.0.1]) by carol.localdomain (Postfix) with ESMTP id 53952C20024; Wed, 29 Jul 2020 13:43:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596023023; 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=Lq8EHz7l+/e/R9ZzMgebRHehFiBBA/O2TS1eYfQTEKo=; b=b063BODvC1wZwFGr/lB7r+q2t+WQzgX/PG3NLWPUDIuyewVzHTt1c7miMPVn05cSNRaAX4 MyONRDmMYJUFzNJbk5f6afllO4ZgHzar8TbWaxUtkcRlDGUcRH6OSzEJMKO0ODE0KYj6Ed +Fz7DEJcjeIINgdnkebSa9vofBEh6cs= X-MC-Unique: GwmdoKYBN4KxttEDMLeROw-1 From: Martin Kletzander To: libvir-list@redhat.com Subject: [PATCH v3 2/3] util: Get rid of virFileFlock() Date: Wed, 29 Jul 2020 13:43:13 +0200 Message-Id: <9be9c7590cf02f176ea8623bd2fddb3cf7b183a2.1596021883.git.mkletzan@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Andrea Bolognani 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.84 on 10.5.11.23 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" It was created to get rid of conditional compilation in the resctrl code and make it usable anywhere else. However this is not something that is going = to be used in other places because it is not portable and resctrl is just very specific in this regard. And there is no reason why there could not be a preprocessor conditional in the resctrl code. Also the interface of virFileFlock() was very ambiguous which lead to some issues. Signed-off-by: Martin Kletzander Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 - src/util/virfile.c | 31 +------------------------------ src/util/virfile.h | 2 -- src/util/virresctrl.c | 17 +++++++++++++++-- 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index eea31a736def..fbbe07becbcf 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2074,7 +2074,6 @@ virFileFindHugeTLBFS; virFileFindMountPoint; virFileFindResource; virFileFindResourceFull; -virFileFlock; virFileFreeACLs; virFileGetACLs; virFileGetDefaultHugepage; diff --git a/src/util/virfile.c b/src/util/virfile.c index af150421e726..b1ca3adcff04 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -463,30 +463,9 @@ int virFileUnlock(int fd, off_t start, off_t len) } =20 =20 -/** - * virFileFlock: - * @fd: file descriptor to call flock on - * @lock: true for lock, false for unlock - * @shared: true if shared, false for exclusive, ignored if `@lock =3D=3D = false` - * - * This is just a simple wrapper around flock(2) that errors out on unsupp= orted - * platforms. - * - * The lock will be released when @fd is closed or this function is called= with - * `@lock =3D=3D false`. - * - * Returns 0 on success, -1 otherwise (with errno set) - */ -int virFileFlock(int fd, bool lock, bool shared) -{ - if (lock) - return flock(fd, shared ? LOCK_SH : LOCK_EX); - - return flock(fd, LOCK_UN); -} - #else /* WIN32 */ =20 + int virFileLock(int fd G_GNUC_UNUSED, bool shared G_GNUC_UNUSED, off_t start G_GNUC_UNUSED, @@ -505,14 +484,6 @@ int virFileUnlock(int fd G_GNUC_UNUSED, } =20 =20 -int virFileFlock(int fd G_GNUC_UNUSED, - bool lock G_GNUC_UNUSED, - bool shared G_GNUC_UNUSED) -{ - errno =3D ENOSYS; - return -1; -} - #endif /* WIN32 */ =20 =20 diff --git a/src/util/virfile.h b/src/util/virfile.h index cb0e586a7d11..2eec89598f6b 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -118,8 +118,6 @@ int virFileLock(int fd, bool shared, off_t start, off_t= len, bool waitForLock) int virFileUnlock(int fd, off_t start, off_t len) G_GNUC_NO_INLINE; =20 -int virFileFlock(int fd, bool lock, bool shared); - typedef int (*virFileRewriteFunc)(int fd, const void *opaque); int virFileRewrite(const char *path, mode_t mode, diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 9b78a6cb159b..2129630a190f 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -456,6 +456,8 @@ VIR_ONCE_GLOBAL_INIT(virResctrl); static int virResctrlLockWrite(void) { +#ifndef WIN32 + int fd =3D open(SYSFS_RESCTRL_PATH, O_RDONLY | O_CLOEXEC); =20 if (fd < 0) { @@ -463,13 +465,20 @@ virResctrlLockWrite(void) return -1; } =20 - if (virFileFlock(fd, true, false) < 0) { + if (flock(fd, LOCK_EX) < 0) { virReportSystemError(errno, "%s", _("Cannot lock resctrl")); VIR_FORCE_CLOSE(fd); return -1; } =20 return fd; + +#else /* WIN32 */ + + virReportSystemError(ENOSYS, "%s", _("Cannot lock resctrl")); + return -1; + +#endif } =20 =20 @@ -484,10 +493,14 @@ virResctrlUnlock(int fd) if (VIR_CLOSE(fd) < 0) { virReportSystemError(errno, "%s", _("Cannot close resctrl")); =20 +#ifndef WIN32 + /* Trying to save the already broken */ - if (virFileFlock(fd, false, false) < 0) + if (flock(fd, LOCK_UN) < 0) virReportSystemError(errno, "%s", _("Cannot unlock resctrl")); =20 +#endif + return -1; } =20 --=20 2.28.0