From: Roel Janssen <roel@gnu.org>
To: guix-devel <guix-devel@gnu.org>
Subject: [PATCH] guix-daemon: Add option to disable garbage collection.
Date: Tue, 03 Apr 2018 12:12:42 +0200 [thread overview]
Message-ID: <87a7uklht1.fsf@gnu.org> (raw)
[-- 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
next reply other threads:[~2018-04-03 10:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-03 10:12 Roel Janssen [this message]
2018-04-03 13:40 ` [PATCH] guix-daemon: Add option to disable garbage collection 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
-- strict thread matches above, loose matches on Subject: below --
2018-04-03 12:41 Adam Van Ymeren
2018-04-03 13:03 ` Roel Janssen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a7uklht1.fsf@gnu.org \
--to=roel@gnu.org \
--cc=guix-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).