From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id RWy9AbMzNV/WTAAA0tVLHw (envelope-from ) for ; Thu, 13 Aug 2020 12:36:03 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id IFSjOLIzNV87OwAAB5/wlQ (envelope-from ) for ; Thu, 13 Aug 2020 12:36:02 +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 809389401CB for ; Thu, 13 Aug 2020 12:36:02 +0000 (UTC) Received: from localhost ([::1]:36190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6CSf-0007va-GQ for larch@yhetil.org; Thu, 13 Aug 2020 08:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k6CRi-00075P-Va for guix-patches@gnu.org; Thu, 13 Aug 2020 08:35:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:35814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k6CRi-00046H-MG for guix-patches@gnu.org; Thu, 13 Aug 2020 08:35:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1k6CRi-0000zE-Ie for guix-patches@gnu.org; Thu, 13 Aug 2020 08:35:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42849] [PATCH 1/3] install: Factorize cow-store procedure. References: <20200813122323.262805-1-othacehe@gnu.org> In-Reply-To: <20200813122323.262805-1-othacehe@gnu.org> Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 13 Aug 2020 12:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42849 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42849@debbugs.gnu.org Cc: Mathieu Othacehe Received: via spool by 42849-submit@debbugs.gnu.org id=B42849.15973220793744 (code B ref 42849); Thu, 13 Aug 2020 12:35:02 +0000 Received: (at 42849) by debbugs.gnu.org; 13 Aug 2020 12:34:39 +0000 Received: from localhost ([127.0.0.1]:47356 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k6CRL-0000y9-6L for submit@debbugs.gnu.org; Thu, 13 Aug 2020 08:34:39 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37056) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k6CRI-0000xq-1g for 42849@debbugs.gnu.org; Thu, 13 Aug 2020 08:34:38 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:53336) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k6CRC-00043t-Q9 for 42849@debbugs.gnu.org; Thu, 13 Aug 2020 08:34:30 -0400 Received: from [2a01:e0a:19b:d9a0:3107:b202:556:bd51] (port=48336 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1k6CRB-0001L2-Qt; Thu, 13 Aug 2020 08:34:30 -0400 From: Mathieu Othacehe Date: Thu, 13 Aug 2020 14:34:17 +0200 Message-Id: <20200813123419.263639-1-othacehe@gnu.org> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -3.3 (---) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 3.99 X-TUID: NhmiW9nrbffi Move the cow-store procedure from the service declaration in (gnu system install) to (gnu build install), so that it can be called from within a different context than Shepherd. * gnu/build/install.scm (mount-cow-store, umount-cow-store): New procedures. * gnu/system/install.scm (make-cow-store): Remove it, (cow-store-service-type): adapt it accordingly. --- gnu/build/install.scm | 44 ++++++++++++++++++++++++++++++++++- gnu/system/install.scm | 52 ++++++++++-------------------------------- 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/gnu/build/install.scm b/gnu/build/install.scm index 87aa5d68da..91c7225c87 100644 --- a/gnu/build/install.scm +++ b/gnu/build/install.scm @@ -18,6 +18,7 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu build install) + #:use-module (guix build syscalls) #:use-module (guix build utils) #:use-module (guix build store-copy) #:use-module (srfi srfi-26) @@ -26,7 +27,9 @@ evaluate-populate-directive populate-root-file-system install-database-and-gc-roots - populate-single-profile-directory)) + populate-single-profile-directory + mount-cow-store + umount-cow-store)) ;;; Commentary: ;;; @@ -229,4 +232,43 @@ This is used to create the self-contained tarballs with 'guix pack'." (_ #t))) +(define (mount-cow-store target backing-directory) + "Make the store copy-on-write, using TARGET as the backing store. This is +useful when TARGET is on a hard disk, whereas the current store is on a RAM +disk." + (define (set-store-permissions directory) + "Set the right perms on DIRECTORY to use it as the store." + (chown directory 0 30000) ;use the fixed 'guixbuild' GID + (chmod directory #o1775)) + + (let ((tmpdir (string-append target "/tmp"))) + (mkdir-p tmpdir) + (mount tmpdir "/tmp" "none" MS_BIND)) + + (let* ((rw-dir (string-append target backing-directory)) + (work-dir (string-append rw-dir "/../.overlayfs-workdir"))) + (mkdir-p rw-dir) + (mkdir-p work-dir) + (mkdir-p "/.rw-store") + (set-store-permissions rw-dir) + (set-store-permissions "/.rw-store") + + ;; Mount the overlay, then atomically make it the store. + (mount "none" "/.rw-store" "overlay" 0 + (string-append "lowerdir=" (%store-directory) "," + "upperdir=" rw-dir "," + "workdir=" work-dir)) + (mount "/.rw-store" (%store-directory) "" MS_MOVE) + (rmdir "/.rw-store"))) + +(define (umount-cow-store target backing-directory) + "Umount copy-on-write store." + (let ((tmp-dir "/remove")) + (mkdir-p tmp-dir) + (mount (%store-directory) tmp-dir "" MS_MOVE) + (umount tmp-dir) + (rmdir tmp-dir) + (delete-file-recursively + (string-append target backing-directory)))) + ;;; install.scm ends here diff --git a/gnu/system/install.scm b/gnu/system/install.scm index a87c2f4207..be5a678cec 100644 --- a/gnu/system/install.scm +++ b/gnu/system/install.scm @@ -175,39 +175,6 @@ manual." ;; Sub-directory used as the backing store for copy-on-write. "/tmp/guix-inst") -(define (make-cow-store target) - "Return a gexp that makes the store copy-on-write, using TARGET as the -backing store. This is useful when TARGET is on a hard disk, whereas the -current store is on a RAM disk." - - (define (set-store-permissions directory) - ;; Set the right perms on DIRECTORY to use it as the store. - #~(begin - (chown #$directory 0 30000) ;use the fixed 'guixbuild' GID - (chmod #$directory #o1775))) - - #~(begin - ;; Bind-mount TARGET's /tmp in case we need space to build things. - (let ((tmpdir (string-append #$target "/tmp"))) - (mkdir-p tmpdir) - (mount tmpdir "/tmp" "none" MS_BIND)) - - (let* ((rw-dir (string-append target #$%backing-directory)) - (work-dir (string-append rw-dir "/../.overlayfs-workdir"))) - (mkdir-p rw-dir) - (mkdir-p work-dir) - (mkdir-p "/.rw-store") - #$(set-store-permissions #~rw-dir) - #$(set-store-permissions "/.rw-store") - - ;; Mount the overlay, then atomically make it the store. - (mount "none" "/.rw-store" "overlay" 0 - (string-append "lowerdir=" #$(%store-prefix) "," - "upperdir=" rw-dir "," - "workdir=" work-dir)) - (mount "/.rw-store" #$(%store-prefix) "" MS_MOVE) - (rmdir "/.rw-store")))) - (define cow-store-service-type (shepherd-service-type 'cow-store @@ -222,13 +189,18 @@ the given target.") ;; This is meant to be explicitly started by the user. (auto-start? #f) - (start #~(case-lambda - ((target) - #$(make-cow-store #~target) - target) - (else - ;; Do nothing, and mark the service as stopped. - #f))) + (modules `((gnu build install) + ,@%default-modules)) + (start + (with-imported-modules (source-module-closure + '((gnu build install))) + #~(case-lambda + ((target) + (mount-cow-store target #$%backing-directory) + target) + (else + ;; Do nothing, and mark the service as stopped. + #f)))) (stop #~(lambda (target) ;; Delete the temporary directory, but leave everything ;; mounted as there may still be processes using it since -- 2.28.0