+static struct snapshot *find_orphaned_snapshot(struct snapshot_list *sl)
+{
+ struct snapshot *s;
+ int i;
+
+ DSS_DEBUG_LOG("looking for orphaned snapshots\n");
+ FOR_EACH_SNAPSHOT(s, i, sl) {
+ if (snapshot_is_being_created(s))
+ continue;
+ /*
+ * We know that no rm is currently running, so if s is marked
+ * as being deleted, a previously started rm must have failed.
+ */
+ if (s->flags & SS_BEING_DELETED)
+ return s;
+
+ if (s->flags & SS_COMPLETE) /* good snapshot */
+ continue;
+ /*
+ * This snapshot is incomplete and it is not the snapshot
+ * currently being created. However, we must not remove it if
+ * rsync is about to be restarted. As only the newest snapshot
+ * can be restarted, this snapshot is orphaned if it is not the
+ * newest snapshot or if we are not about to restart rsync.
+ */
+ if (get_newest_snapshot(sl) != s)
+ return s;
+ if (snapshot_creation_status != HS_NEEDS_RESTART)
+ return s;
+ }
+ /* no orphaned snapshots */
+ return NULL;
+}
+
+static int is_reference_snapshot(struct snapshot *s)
+{
+ if (!name_of_reference_snapshot)
+ return 0;
+ return strcmp(s->name, name_of_reference_snapshot)? 0 : 1;
+}
+