]> git.tuebingen.mpg.de Git - dss.git/commitdiff
Merge branch 'refs/heads/t/min-complete'
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 12 Dec 2014 13:21:53 +0000 (14:21 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 12 Dec 2014 13:21:53 +0000 (14:21 +0100)
1  2 
dss.c
dss.ggo
snap.c
snap.h

diff --combined dss.c
index 0ad7a35989a75e893fe40e30d84d1ff18f4d94ff,9f39324500ffa915af5e0c593ae7d56d40eb5062..006cd27c333e097231ae140374fffdf3b8d689f6
--- 1/dss.c
--- 2/dss.c
+++ b/dss.c
@@@ -1,5 -1,5 +1,5 @@@
  /*
 - * Copyright (C) 2008-2011 Andre Noll <maan@systemlinux.org>
 + * Copyright (C) 2008-2011 Andre Noll <maan@tuebingen.mpg.de>
   *
   * Licensed under the GPL v2. For licencing details see COPYING.
   */
@@@ -531,17 -531,25 +531,25 @@@ static struct snapshot *find_outdated_s
  
  static struct snapshot *find_oldest_removable_snapshot(struct snapshot_list *sl)
  {
-       int i;
-       struct snapshot *s;
+       int i, num_complete;
+       struct snapshot *s, *ref = NULL;
+       num_complete = num_complete_snapshots(sl);
+       if (num_complete <= conf.min_complete_arg)
+               return NULL;
        FOR_EACH_SNAPSHOT(s, i, sl) {
                if (snapshot_is_being_created(s))
                        continue;
-               if (is_reference_snapshot(s))
+               if (is_reference_snapshot(s)) { /* avoid this one */
+                       ref = s;
                        continue;
+               }
                DSS_INFO_LOG(("oldest removable snapshot: %s\n", s->name));
                return s;
        }
-       return NULL;
+       assert(ref);
+       DSS_WARNING_LOG(("removing reference snapshot %s\n", ref->name));
+       return ref;
  }
  
  static int rename_incomplete_snapshot(int64_t start)
diff --combined dss.ggo
index ac7f5b7875279914e7b71ca15b26d8d60e36faf6,d8b956e7e276fb5b9e0d4da75dab1351e9afe852..9587dd24c7b11a439b2c63335ba922361e1cf988
+++ b/dss.ggo
@@@ -1,4 -1,4 +1,4 @@@
 -# Copyright (C) 2008-2010 Andre Noll <maan@systemlinux.org>
 +# Copyright (C) 2008-2010 Andre Noll <maan@tuebingen.mpg.de>
  #
  # Licensed under the GPL v2. For licencing details see COPYING.
  
@@@ -439,3 -439,23 +439,23 @@@ details=
        becomes low. Use this flag if the file system containing the
        destination directory is used for snapshots only.
  "
+ option "min-complete" -
+ #~~~~~~~~~~~~~~~~~~~~~~
+ "Minimal number of complete snapshots to keep"
+ int typestr = "num"
+ default = "1"
+ optional
+ details = "
+       This option is only relevant if snapshots must be deleted
+       because disk space gets low.
+       dss refuses to remove old snapshots if there are fewer complete
+       snapshots left than the given number. The default value of one
+       guarantees that at least one complete snapshot is available
+       at all times.
+       If only <num> complete snapshot are left, and there is not
+       enough disk space available for another snapshot, the program
+       terminates with a \"No space left on device\" error.
+ "
diff --combined snap.c
index 4dbb4461ed43c3152460ed3b312caa6f434143fd,ec0449d941c0296b5bb2b7f282a828b3c76d1196..7c16d2e870b8e4e918a1486ab801bf31f1344c47
--- 1/snap.c
--- 2/snap.c
+++ b/snap.c
@@@ -1,5 -1,5 +1,5 @@@
  /*
 - * Copyright (C) 2008-2010 Andre Noll <maan@systemlinux.org>
 + * Copyright (C) 2008-2010 Andre Noll <maan@tuebingen.mpg.de>
   *
   * Licensed under the GPL v2. For licencing details see COPYING.
   */
@@@ -232,3 -232,13 +232,13 @@@ __malloc char *name_of_newest_complete_
        return name;
  }
  
+ int num_complete_snapshots(struct snapshot_list *sl)
+ {
+       struct snapshot *s;
+       int i, ret = 0;
+       FOR_EACH_SNAPSHOT(s, i, sl)
+               if (s->flags & SS_COMPLETE)
+                       ret++;
+       return ret;
+ }
diff --combined snap.h
index 8fee1389595840f62cffb9932d21f51c6b33943f,c817de2b5ef75cb0ab0ad791362a9575844b524c..626ecad003a52a1a465ea6f7f2e11f960a97df3c
--- 1/snap.h
--- 2/snap.h
+++ b/snap.h
@@@ -1,5 -1,5 +1,5 @@@
  /*
 - * Copyright (C) 2008-2010 Andre Noll <maan@systemlinux.org>
 + * Copyright (C) 2008-2010 Andre Noll <maan@tuebingen.mpg.de>
   *
   * Licensed under the GPL v2. For licencing details see COPYING.
   */
@@@ -88,6 -88,7 +88,7 @@@ __malloc char *incomplete_name(int64_t 
  __malloc char *being_deleted_name(struct snapshot *s);
  int complete_name(int64_t start, int64_t end, char **result);
  __malloc char *name_of_newest_complete_snapshot(struct snapshot_list *sl);
+ int num_complete_snapshots(struct snapshot_list *sl);
  
  /**
   * Get the newest snapshot in a snapshot list.