From patchwork Sat Jun 17 22:22:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Bugaev X-Patchwork-Id: 1796205 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=tAHd0jfn; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qk9Xg6qKyz20WT for ; Sun, 18 Jun 2023 08:23:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BEDA73856262 for ; Sat, 17 Jun 2023 22:23:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEDA73856262 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687040609; bh=MTMvhmeuoXOzsps0QPIWu5i/LlTZGAhrWTbe/OLJCi8=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=tAHd0jfnDhnn4qTFhm93kQfmN+xfhtTlp69HQjsaSpLvy280i3tlLrhufB8INgukR OzO0QKql7R54dkvCCFRMV/nbLboLG3YUSN/gPVKLAbFlIbAubdHqF4oBcu6JDFyUYi 4QLgbhkF9LDCq+mbwuMZ+QF054rvQmF5beQ3QKyQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 92D103858D35 for ; Sat, 17 Jun 2023 22:22:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92D103858D35 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4f63006b4e3so2721647e87.1 for ; Sat, 17 Jun 2023 15:22:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687040543; x=1689632543; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MTMvhmeuoXOzsps0QPIWu5i/LlTZGAhrWTbe/OLJCi8=; b=MfzYa0S8p+AQO0zz+wfHH+ZwqWbkhMyrRNpkvon8iZ8pAbncqwy8Z6b/2ddx3qjDSJ wtLF1YlK2WjsWOAJzQ9afUwrlyoY7j3z43xddmhLfj4DxJBmofiYGyASGhq/KJ7dLFLt UnkOuBE/VFdWtlOzojWMh4Bo7WTDIoe5B9hnrcG467GYi73ufuXmNA91q+QyJT8LLwjw 8MEkNRyhrpg1s30NIW82kFStmR2ey2I7HCksYGmJ/cB+qr7PtpkiL+CCliCliMKJRnbc /6NGyO6dAwhhkrrCKuEjkZwZvo0Adw0k1yYiplUWrOlwG5k6Viy1ZrcAqFHwF6YsnQI7 GfnQ== X-Gm-Message-State: AC+VfDyFL4q6+hN6msBL0h+h9WsRg0OZjkkGmla1eBOyw7dhaqFpM9NU qdEZ1DODxJ+xFPUfOCR/rFQ+QhAw4Jg= X-Google-Smtp-Source: ACHHUZ5cdk6KyZXcYfeB4zdOBp6znXXTYWYjc6CwCsSEqzRrLjahHfR4Esd3+bXg3v8XccU7Kvmusg== X-Received: by 2002:a19:650b:0:b0:4f8:5885:61e with SMTP id z11-20020a19650b000000b004f85885061emr2732392lfb.40.1687040542450; Sat, 17 Jun 2023 15:22:22 -0700 (PDT) Received: from surface-pro-6.. ([2a00:1370:818c:173b:cc34:4e0d:9ea6:c16c]) by smtp.gmail.com with ESMTPSA id j28-20020ac253bc000000b004f76a88dbcbsm1567091lfh.176.2023.06.17.15.22.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Jun 2023 15:22:22 -0700 (PDT) To: libc-alpha@sourceware.org Cc: Adhemerval Zanella Subject: [PATCH v3 1/5] support: Add support_fcntl_support_ofd_locks () Date: Sun, 18 Jun 2023 01:22:14 +0300 Message-ID: <20230617222218.642125-2-bugaevc@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230617222218.642125-1-bugaevc@gmail.com> References: <20230617222218.642125-1-bugaevc@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sergey Bugaev via Libc-alpha From: Sergey Bugaev Reply-To: Sergey Bugaev Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Reviewed-by: Adhemerval Zanella Signed-off-by: Sergey Bugaev --- support/Makefile | 1 + support/support.h | 3 ++ support/support_fcntl_support_ofd_locks.c | 44 +++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 support/support_fcntl_support_ofd_locks.c diff --git a/support/Makefile b/support/Makefile index 8ebe68aa..4dd9335b 100644 --- a/support/Makefile +++ b/support/Makefile @@ -58,6 +58,7 @@ libsupport-routines = \ support_descriptors \ support_enter_mount_namespace \ support_enter_network_namespace \ + support_fcntl_support_ofd_locks \ support_format_address_family \ support_format_addrinfo \ support_format_dns_packet \ diff --git a/support/support.h b/support/support.h index b7f76bf0..e20d2ce7 100644 --- a/support/support.h +++ b/support/support.h @@ -178,6 +178,9 @@ static __inline bool support_itimer_support_time64 (void) #endif } +/* Return true if the kernel/file supports open file description locks. */ +extern bool support_fcntl_support_ofd_locks (int fd); + /* Return true if stat supports nanoseconds resolution. PATH is used for tests and its ctime may change. */ extern bool support_stat_nanoseconds (const char *path); diff --git a/support/support_fcntl_support_ofd_locks.c b/support/support_fcntl_support_ofd_locks.c new file mode 100644 index 00000000..fb197a70 --- /dev/null +++ b/support/support_fcntl_support_ofd_locks.c @@ -0,0 +1,44 @@ +/* Return whether the kernel/file supports OFD locks. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +bool +support_fcntl_support_ofd_locks (int fd) +{ +#ifdef F_OFD_GETLK + int res; + struct flock flock; + memset (&flock, 0, sizeof (flock)); + + flock.l_type = F_WRLCK; + flock.l_whence = SEEK_SET; + flock.l_start = 0; + flock.l_len = INT32_MAX; + flock.l_pid = 0; + + res = fcntl (fd, F_OFD_GETLK, &flock); + return res != -1 || errno != EINVAL; +#else + (void) fd; + return false; +#endif +}