From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 6NbNE6DfM2B+bgAA0tVLHw (envelope-from ) for ; Mon, 22 Feb 2021 16:45:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id MKuXD6DfM2CQQQAA1q6Kng (envelope-from ) for ; Mon, 22 Feb 2021 16:45:20 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6D2C32A693 for ; Mon, 22 Feb 2021 17:45:19 +0100 (CET) Received: from localhost ([::1]:59084 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lEEKk-00062z-MR for larch@yhetil.org; Mon, 22 Feb 2021 11:45:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lEEKV-0005qo-8k for bug-guix@gnu.org; Mon, 22 Feb 2021 11:45:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:45836) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lEEKU-0007VO-UF for bug-guix@gnu.org; Mon, 22 Feb 2021 11:45:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lEEKU-0002KD-SO for bug-guix@gnu.org; Mon, 22 Feb 2021 11:45:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#46292: [PATCH 3/3] file-systems: 'mount-file-system' preserves source flags for bind mounts. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Mon, 22 Feb 2021 16:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46292 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 46292@debbugs.gnu.org Received: via spool by 46292-submit@debbugs.gnu.org id=B46292.16140122788876 (code B ref 46292); Mon, 22 Feb 2021 16:45:02 +0000 Received: (at 46292) by debbugs.gnu.org; 22 Feb 2021 16:44:38 +0000 Received: from localhost ([127.0.0.1]:57380 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lEEK1-0002Ix-TW for submit@debbugs.gnu.org; Mon, 22 Feb 2021 11:44:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44590) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lEEJz-0002IP-3j for 46292@debbugs.gnu.org; Mon, 22 Feb 2021 11:44:32 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:57978) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lEEJs-0007K8-UJ; Mon, 22 Feb 2021 11:44:24 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=39738 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1lEEJs-0000oc-0P; Mon, 22 Feb 2021 11:44:24 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Mon, 22 Feb 2021 17:44:13 +0100 Message-Id: <20210222164413.30996-3-ludo@gnu.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210222164413.30996-1-ludo@gnu.org> References: <8735xob3ua.fsf@gnu.org> <20210222164413.30996-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.87 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: 6D2C32A693 X-Spam-Score: -1.87 X-Migadu-Scanner: scn0.migadu.com X-TUID: 15fwK9iz17nV From: Ludovic Courtès Fixes . * gnu/build/file-systems.scm (mount-file-system): If FS is a bind mount, add its original mount flags to FLAGS. --- gnu/build/file-systems.scm | 45 +++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index ddf6117b67..aca4aad848 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2020 Ludovic Courtès +;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2020, 2021 Ludovic Courtès ;;; Copyright © 2016, 2017 David Craven ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2019 Guillaume Le Vaillant @@ -909,12 +909,27 @@ corresponds to the symbols listed in FLAGS." (if options (string-append "," options) ""))))) - (let ((type (file-system-type fs)) - (options (file-system-options fs)) - (source (canonicalize-device-spec (file-system-device fs))) - (mount-point (string-append root "/" - (file-system-mount-point fs))) - (flags (mount-flags->bit-mask (file-system-flags fs)))) + (let* ((type (file-system-type fs)) + (source (canonicalize-device-spec (file-system-device fs))) + (target (string-append root "/" + (file-system-mount-point fs))) + (flags (logior (mount-flags->bit-mask (file-system-flags fs)) + + ;; For bind mounts, preserve the original flags such + ;; as MS_NOSUID, etc. Failing to do that, the + ;; MS_REMOUNT call below fails with EPERM. + ;; See + (if (memq 'bind-mount (file-system-flags fs)) + (or (and=> (find (let ((devno (stat:dev + (lstat source)))) + (lambda (mount) + (= (mount-device-number mount) + devno))) + (mounts)) + mount-flags) + 0) + 0))) + (options (file-system-options fs))) (when (file-system-check? fs) (check-file-system source type)) @@ -925,24 +940,24 @@ corresponds to the symbols listed in FLAGS." ;; needed. (if (and (= MS_BIND (logand flags MS_BIND)) (not (file-is-directory? source))) - (unless (file-exists? mount-point) - (mkdir-p (dirname mount-point)) - (call-with-output-file mount-point (const #t))) - (mkdir-p mount-point)) + (unless (file-exists? target) + (mkdir-p (dirname target)) + (call-with-output-file target (const #t))) + (mkdir-p target)) (cond ((string-prefix? "nfs" type) - (mount-nfs source mount-point type flags options)) + (mount-nfs source target type flags options)) (else - (mount source mount-point type flags options))) + (mount source target type flags options))) ;; For read-only bind mounts, an extra remount is needed, as per ;; , which still applies to Linux ;; 4.0. (when (and (= MS_BIND (logand flags MS_BIND)) (= MS_RDONLY (logand flags MS_RDONLY))) - (let ((flags (logior MS_BIND MS_REMOUNT MS_RDONLY))) - (mount source mount-point type flags #f)))) + (let ((flags (logior MS_REMOUNT flags))) + (mount source target type flags options)))) (lambda args (or (file-system-mount-may-fail? fs) (apply throw args)))))) -- 2.30.0