unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Re: [PATCH] guix-daemon: Add option to disable garbage collection.
@ 2018-04-03 12:41 Adam Van Ymeren
  2018-04-03 13:03 ` Roel Janssen
  0 siblings, 1 reply; 15+ messages in thread
From: Adam Van Ymeren @ 2018-04-03 12:41 UTC (permalink / raw)
  To: Roel Janssen; +Cc: guix-devel

Just out of curiosity, what is your situation where the daemon can't see all GC roots?  Are you sharing the store over NFS or something?On 3 Apr 2018 6:12 a.m., Roel Janssen <roel@gnu.org> wrote:
>
> Dear Guix, 
>
> I have an interesting situation where the guix-daemon cannot see all 
> directories that (may) contain Guix profiles, and therefore is not able 
> to judge whether a GC root is gone and can be collected, or whether it's 
> just inaccessible. 
>
> To be on the safe side, I'd like to disable garbage collection on this 
> system.  To achieve this, I wrote the attached patch.  Even though “it 
> works for me”, I don't think it's good to be added as-is.  At least I 
> need to figure out how to make the error message “Garbage collection is 
> disabled.” translatable. 
>
> The patch adds a “disableGarbageCollection” boolean variable to the 
> guix-daemon settings, and on each occasion where a store item may be 
> deleted, it checks this option. 
>
> This option can be set using “--disable-gc”. 
>
> It would be great if someone could review this and discuss whether 
> this is the right way to implement such a feature.  And to point out 
> what else would be needed to include this option in guix-daemon. 
>
> Thank you for your time. 
>
> Kind regards, 
> Roel Janssen 
>

^ permalink raw reply	[flat|nested] 15+ messages in thread
* [PATCH] guix-daemon: Add option to disable garbage collection.
@ 2018-04-03 10:12 Roel Janssen
  2018-04-03 13:40 ` Ludovic Courtès
  0 siblings, 1 reply; 15+ messages in thread
From: Roel Janssen @ 2018-04-03 10:12 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1044 bytes --]

Dear Guix,

I have an interesting situation where the guix-daemon cannot see all
directories that (may) contain Guix profiles, and therefore is not able
to judge whether a GC root is gone and can be collected, or whether it's
just inaccessible.

To be on the safe side, I'd like to disable garbage collection on this
system.  To achieve this, I wrote the attached patch.  Even though “it
works for me”, I don't think it's good to be added as-is.  At least I
need to figure out how to make the error message “Garbage collection is
disabled.” translatable.

The patch adds a “disableGarbageCollection” boolean variable to the
guix-daemon settings, and on each occasion where a store item may be
deleted, it checks this option.

This option can be set using “--disable-gc”.

It would be great if someone could review this and discuss whether
this is the right way to implement such a feature.  And to point out
what else would be needed to include this option in guix-daemon.

Thank you for your time.

Kind regards,
Roel Janssen


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-guix-daemon-Add-option-to-disable-garbage-collection.patch --]
[-- Type: text/x-patch, Size: 4797 bytes --]

From d842f320f0ee911d7d219bba7baa45240edcbe6d Mon Sep 17 00:00:00 2001
From: Roel Janssen <roel@gnu.org>
Date: Tue, 3 Apr 2018 11:22:16 +0200
Subject: [PATCH] guix-daemon: Add option to disable garbage collection.

* nix/libstore/gc.cc: Return early on deleterious functions.
* nix/libstore/globals.hh (disableGarbageCollection): New settings variable.
* nix/nix-daemon/guix-daemon.cc: Implement new settings variable.
* nix/nix-daemon/nix-daemon.cc: Show appropriate message.
---
 nix/libstore/gc.cc            | 20 ++++++++++++++++++++
 nix/libstore/globals.hh       |  3 +++
 nix/nix-daemon/guix-daemon.cc |  6 ++++++
 nix/nix-daemon/nix-daemon.cc  |  5 +++++
 4 files changed, 34 insertions(+)

diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index 72eff5242..b811cacd1 100644
--- a/nix/libstore/gc.cc
+++ b/nix/libstore/gc.cc
@@ -393,6 +393,10 @@ bool LocalStore::isActiveTempFile(const GCState & state,
 
 void LocalStore::deleteGarbage(GCState & state, const Path & path)
 {
+    if (settings.disableGarbageCollection) {
+        return;
+    }
+
     unsigned long long bytesFreed;
     deletePath(path, bytesFreed);
     state.results.bytesFreed += bytesFreed;
@@ -401,6 +405,10 @@ void LocalStore::deleteGarbage(GCState & state, const Path & path)
 
 void LocalStore::deletePathRecursive(GCState & state, const Path & path)
 {
+    if (settings.disableGarbageCollection) {
+        return;
+    }
+
     checkInterrupt();
 
     unsigned long long size = 0;
@@ -513,6 +521,10 @@ bool LocalStore::canReachRoot(GCState & state, PathSet & visited, const Path & p
 
 void LocalStore::tryToDelete(GCState & state, const Path & path)
 {
+    if (settings.disableGarbageCollection) {
+        return;
+    }
+
     checkInterrupt();
 
     if (path == linksDir || path == state.trashDir) return;
@@ -552,6 +564,10 @@ void LocalStore::tryToDelete(GCState & state, const Path & path)
    the link count. */
 void LocalStore::removeUnusedLinks(const GCState & state)
 {
+    if (settings.disableGarbageCollection) {
+        return;
+    }
+
     AutoCloseDir dir = opendir(linksDir.c_str());
     if (!dir) throw SysError(format("opening directory `%1%'") % linksDir);
 
@@ -595,6 +611,10 @@ void LocalStore::removeUnusedLinks(const GCState & state)
 
 void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
 {
+    if (settings.disableGarbageCollection) {
+        return;
+    }
+
     GCState state(results);
     state.options = options;
     state.trashDir = settings.nixStore + "/trash";
diff --git a/nix/libstore/globals.hh b/nix/libstore/globals.hh
index 1293625e1..54e04f218 100644
--- a/nix/libstore/globals.hh
+++ b/nix/libstore/globals.hh
@@ -218,6 +218,9 @@ struct Settings {
     /* Whether the importNative primop should be enabled */
     bool enableImportNative;
 
+    /* Whether the disable garbage collection. */
+    bool disableGarbageCollection;
+
 private:
     SettingsMap settings, overrides;
 
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index b71b100f6..13811cd99 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -89,6 +89,7 @@ builds derivations on behalf of its clients.");
 #define GUIX_OPT_TIMEOUT 18
 #define GUIX_OPT_MAX_SILENT_TIME 19
 #define GUIX_OPT_LOG_COMPRESSION 20
+#define GUIX_OPT_DISABLE_GC 21
 
 static const struct argp_option options[] =
   {
@@ -133,6 +134,8 @@ static const struct argp_option options[] =
       n_("disable automatic file \"deduplication\" in the store") },
     { "disable-store-optimization", GUIX_OPT_DISABLE_DEDUPLICATION, 0,
       OPTION_ALIAS | OPTION_HIDDEN, NULL },
+    { "disable-gc", GUIX_OPT_DISABLE_GC, 0, 0,
+      n_("disable garbage collection.") },
 
     { "impersonate-linux-2.6", GUIX_OPT_IMPERSONATE_LINUX_26, 0,
 #ifdef HAVE_SYS_PERSONALITY_H
@@ -225,6 +228,9 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case GUIX_OPT_DISABLE_DEDUPLICATION:
       settings.autoOptimiseStore = false;
       break;
+    case GUIX_OPT_DISABLE_GC:
+      settings.disableGarbageCollection = true;
+      break;
     case GUIX_OPT_CACHE_FAILURES:
       settings.cacheFailure = true;
       break;
diff --git a/nix/nix-daemon/nix-daemon.cc b/nix/nix-daemon/nix-daemon.cc
index deb7003d7..5af8ec796 100644
--- a/nix/nix-daemon/nix-daemon.cc
+++ b/nix/nix-daemon/nix-daemon.cc
@@ -529,6 +529,11 @@ static void performOp(bool trusted, unsigned int clientVersion,
     }
 
     case wopCollectGarbage: {
+        if (settings.disableGarbageCollection) {
+            throw Error("Garbage collection is disabled.");
+            break;
+        }
+
         GCOptions options;
         options.action = (GCOptions::GCAction) readInt(from);
         options.pathsToDelete = readStorePaths<PathSet>(from);
-- 
2.16.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-04-19 17:07 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-03 12:41 [PATCH] guix-daemon: Add option to disable garbage collection Adam Van Ymeren
2018-04-03 13:03 ` Roel Janssen
  -- strict thread matches above, loose matches on Subject: below --
2018-04-03 10:12 Roel Janssen
2018-04-03 13:40 ` Ludovic Courtès
2018-04-03 14:02   ` Roel Janssen
2018-04-11  7:57     ` Roel Janssen
2018-04-17 21:00       ` Roel Janssen
2018-04-18 21:12         ` Ludovic Courtès
2018-04-19  9:06       ` Ludovic Courtès
2018-04-19 12:12         ` Roel Janssen
2018-04-19 14:47           ` Ludovic Courtès
2018-04-19 15:15             ` Roel Janssen
2018-04-19 15:26               ` Ludovic Courtès
2018-04-19 17:07                 ` Roel Janssen
2018-04-19 15:25           ` Marius Bakke

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).