From patchwork Wed Feb 26 15:20:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11406571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2322713A4 for ; Wed, 26 Feb 2020 15:22:21 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F139821D7E for ; Wed, 26 Feb 2020 15:22:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RHmDNteO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F139821D7E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUc-0001Au-GC; Wed, 26 Feb 2020 15:20:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUb-0001Ao-N2 for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 15:20:57 +0000 X-Inumbo-ID: 9672249c-58ab-11ea-aba8-bc764e2007e4 Received: from mail-qt1-x842.google.com (unknown [2607:f8b0:4864:20::842]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9672249c-58ab-11ea-aba8-bc764e2007e4; Wed, 26 Feb 2020 15:20:57 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id v25so2484321qto.7 for ; Wed, 26 Feb 2020 07:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lygCv0fXeRA8hLfYhPykOOLRebIgfRLYlOPXtqIcsWk=; b=RHmDNteOlXSU6OHAFYOZ/9CR346ldplcfXkIjlwa+1onSg+RiDDAujlgu/Jp60AlmQ aQBJSBRkI4lnLX0+lM6P1j0Phv5qUBNiTsKzTWcHLqTiNRdhbYnp1PMLUm3ErzG3+LBq EaOVswD7Ah/NqWnbtbegQNCz/EGbbWHTI/XABBzwls252l02Wj3N8YOF0TCOItgj9brU ZjrMOxqZHzhlXYNH3w2TbUFDD8pl7PwaV9UO6ud7KW4lNqgTY58PEzeSa95kUSCA0aek mM4vTyexUKmZpP4ZWWC9xH9aAXdgmxtVPc4uJT7UjEH/xZsR4ViDbamKVCu6s1Y2cwhE g+tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lygCv0fXeRA8hLfYhPykOOLRebIgfRLYlOPXtqIcsWk=; b=Z/THKy94ca4R0UXxhq63ljUzU5Lz6kZfwo1hXnkYoy+YWKAHDxpuEeAz8rf7LUDRFm LWWP3WHMZVgJPcbYEaqOOQkUyosnIJnqZJSxhUAhilelkThxhJUos5dxDcKSiipLSwHN /WdAwK9NJgw0tklo3/+91iCkf2VffGSdc8wsOSxMyznDJiczgpyfT/bwxVPTU5dUQtyn 5PLPz/8xyL4aYv8S4AR+CarWb1K7tTDc5n6/PTslMJINKdjb0canuMcYhYBFh+SQEbR8 UzaORNBkibXOUPT10g9yV1B6TLuUyuQu12+x9gIeyH3vDL2zByv6tP3OwQ065Rr8C9lx cWZQ== X-Gm-Message-State: APjAAAWO+C7PNNH3XOW5JyboTQhseSNeP0ciE3p6MLFEFo8KknmBfvqJ f/xbk4/L6RdHqzt9BGcTiwohIRoL X-Google-Smtp-Source: APXvYqy60CO4ZMzSohLAXfZS9PCwcJYwNKm//tr3S7l65LFbTZ9Imic4Yr+HQkHenpRIAuUfRqKuBg== X-Received: by 2002:ac8:4711:: with SMTP id f17mr5404744qtp.160.1582730456832; Wed, 26 Feb 2020 07:20:56 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id q196sm327187qke.80.2020.02.26.07.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 07:20:56 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Date: Wed, 26 Feb 2020 10:20:12 -0500 Message-Id: <20200226152013.12200-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200226152013.12200-1-jandryuk@gmail.com> References: <20200226152013.12200-1-jandryuk@gmail.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/2] tools/helpers: Introduce cmp-fd-file-inode utility X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This is a C implementation of the perl code inside of locking.sh to check that the locked file descriptor and lock file share the same inode and therefore match. One change from the perl version is replacing printing "y" on success with exit values of 0 (shell True) and 1 (shell False). Requiring perl is a large dependency for the single use, so a dedicated utility removes that dependency for systems that otherwise would not install perl. Signed-off-by: Jason Andryuk --- .gitignore | 1 + tools/helpers/Makefile | 3 +++ tools/helpers/cmp-fd-file-inode.c | 43 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tools/helpers/cmp-fd-file-inode.c diff --git a/.gitignore b/.gitignore index 4ca679ddbc..897f878eef 100644 --- a/.gitignore +++ b/.gitignore @@ -164,6 +164,7 @@ tools/fuzz/x86_instruction_emulator/x86-emulate.[ch] tools/helpers/_paths.h tools/helpers/init-xenstore-domain tools/helpers/xen-init-dom0 +tools/helpers/cmp-fd-file-inode tools/hotplug/common/hotplugpath.sh tools/hotplug/FreeBSD/rc.d/xencommons tools/hotplug/FreeBSD/rc.d/xendriverdomain diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile index f759528322..7daf5c46ca 100644 --- a/tools/helpers/Makefile +++ b/tools/helpers/Makefile @@ -8,6 +8,7 @@ include $(XEN_ROOT)/tools/Rules.mk PROGS += xen-init-dom0 ifeq ($(CONFIG_Linux),y) PROGS += init-xenstore-domain +PROGS += cmp-fd-file-inode endif XEN_INIT_DOM0_OBJS = xen-init-dom0.o init-dom-json.o @@ -40,12 +41,14 @@ install: all $(INSTALL_PROG) xen-init-dom0 $(DESTDIR)$(LIBEXEC_BIN) ifeq ($(CONFIG_Linux),y) $(INSTALL_PROG) init-xenstore-domain $(DESTDIR)$(LIBEXEC_BIN) + $(INSTALL_PROG) cmp-fd-file-inode $(DESTDIR)$(LIBEXEC_BIN) endif .PHONY: uninstall uninstall: ifeq ($(CONFIG_Linux),y) rm -f $(DESTDIR)$(LIBEXEC_BIN)/init-xenstore-domain + rm -f $(DESTDIR)$(LIBEXEC_BIN)/cmp-fd-file-inode endif rm -f $(DESTDIR)$(LIBEXEC_BIN)/xen-init-dom0 diff --git a/tools/helpers/cmp-fd-file-inode.c b/tools/helpers/cmp-fd-file-inode.c new file mode 100644 index 0000000000..886ea888ed --- /dev/null +++ b/tools/helpers/cmp-fd-file-inode.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +void usage(const char * prog) +{ + fprintf(stderr, +"%s \n" +"Checks that the open file descriptor (referenced by number) has the same\n" +"inode as the filename.\n" +"Returns 0 on match and 1 on non-match\n", prog); +} + +int main(int argc, char *argv[]) +{ + struct stat fd_statbuf, file_statbuf; + int ret; + int fd; + + if (argc < 3) { + usage(argv[0]); + return 1; + } + + fd = strtoul(argv[1], NULL, 0); + + ret = fstat(fd, &fd_statbuf); + if (ret) { + return 1; + } + + ret = stat(argv[2], &file_statbuf); + if (ret) { + return 1; + } + + if (fd_statbuf.st_ino == file_statbuf.st_ino) + return 0; + else + return 1; +} From patchwork Wed Feb 26 15:20:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11406569 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DCEC71395 for ; Wed, 26 Feb 2020 15:22:04 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B9A412467D for ; Wed, 26 Feb 2020 15:22:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qy+Lmqcn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B9A412467D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUh-0001CK-Ph; Wed, 26 Feb 2020 15:21:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUg-0001C9-MU for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 15:21:02 +0000 X-Inumbo-ID: 97d1ba78-58ab-11ea-a490-bc764e2007e4 Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 97d1ba78-58ab-11ea-a490-bc764e2007e4; Wed, 26 Feb 2020 15:20:59 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id r5so2480833qtt.9 for ; Wed, 26 Feb 2020 07:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VFOAd65lQswkmbzdAMYJGUSVTalFZ80HbsJPAnnzq2k=; b=Qy+LmqcnrO4tFK9DKfrKCg5Xis7lwdWKVieMep9iDcrcSHJ2Jpvhaz9JsSc+6qxkhv 3JWWZUBFyGe728K9iYsFiFzQ6B5kgvFoB/UVaOaP2jIxVRomPkq1y6sBVk4zyUfHTKcf 8f+j8NeauX6qJ3g2J7J46aYdnVZbE5ROYGAWY+gdHvuKLzAzcuSVF+XgCauVRpGwOk5l x3p2NYqzUzhUgtSp+7OEP/g+/yqpd1BzVrxUAXfnXi2WQQlwm1tSLd8wvtjU7wNfLn6N qAenp6eU1BfcwKbmGFPYKb1z2I1hnaLahBjMCJU+ed+oqQz/PXRKw5loICccv5uaV5VM GaAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VFOAd65lQswkmbzdAMYJGUSVTalFZ80HbsJPAnnzq2k=; b=OimENtyiGpT/VDy5nnjuyVCseCvHGac0LrB2tN/afUP9/jtJ4KUAQ1bgbuSsC3dLgw wcnnWi64DodHKbP2TRPXEe8ubgzdnbIjNHtOFFqG7UCjO2ThQRYayDY4VYSTa4Qm4OqM Vz+oFvtgjSm72dVE+GoZrW1aQ0qpxMX6Rq6m1B10jZRfts0L9M6LEXczXLmO5F7n3rBP bMDMSVk57L7vjvHueNMqBht+9jRG7NbdM0LfkBAAtUv8npXcqksa8wxl/kaxl3YQd3Yi /tljjNZ0ASC8DaICnFvUd69K9rzzyWtiCGTidfxf9nNrYSJP6ayd00yq687du7tTp12k JoiQ== X-Gm-Message-State: APjAAAVODoJ65JMxYRAKA1UlrfXYvFl8Oc2CBKGkCxeGkogA3bj4Ab+y Ko8PbdNaGwxZQdPazZV23KqvQhC6 X-Google-Smtp-Source: APXvYqxKwRrFeHXykdEtDwbAPXl/JpTWF8CC8F9DYXFbHDP37dpEi7+p/90GZQv8TsCu4GHmv/9csw== X-Received: by 2002:ac8:7101:: with SMTP id z1mr5242193qto.333.1582730459173; Wed, 26 Feb 2020 07:20:59 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id q196sm327187qke.80.2020.02.26.07.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 07:20:58 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Date: Wed, 26 Feb 2020 10:20:13 -0500 Message-Id: <20200226152013.12200-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200226152013.12200-1-jandryuk@gmail.com> References: <20200226152013.12200-1-jandryuk@gmail.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/2] Linux/locking.sh: Use cmp-fd-file-inode for lock check X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Replace perl with cmp-fd-file-inode when checking that the lock file descriptor and lockfile inodes match. Signed-off-by: Jason Andryuk --- tools/hotplug/Linux/locking.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/hotplug/Linux/locking.sh b/tools/hotplug/Linux/locking.sh index c6a7e96ff9..de468c4bb5 100644 --- a/tools/hotplug/Linux/locking.sh +++ b/tools/hotplug/Linux/locking.sh @@ -50,14 +50,8 @@ claim_lock() # actually a synthetic symlink in /proc and we aren't # guaranteed that our stat(2) won't lose the race with an # rm(1) between reading the synthetic link and traversing the - # file system to find the inum. Perl is very fast so use that. - rightfile=$( perl -e ' - open STDIN, "<&'$_lockfd'" or die $!; - my $fd_inum = (stat STDIN)[1]; die $! unless defined $fd_inum; - my $file_inum = (stat $ARGV[0])[1]; - print "y\n" if $fd_inum eq $file_inum; - ' "$_lockfile" ) - if [ x$rightfile = xy ]; then break; fi + # file system to find the inum. + if cmp-fd-file-inode $_lockfd $_lockfile ; then break; fi # Some versions of bash appear to be buggy if the same # $_lockfile is opened repeatedly. Close the current fd here. eval "exec $_lockfd<&-"