2013-04-23 11:39:56 +02:00
|
|
|
From: Frederic Crozat <fcrozat@suse.com>
|
|
|
|
Date: Mon, 7 Nov 2011 18:04:20 +0100
|
|
|
|
Subject: force lvm restart after cryptsetup target is reached
|
|
|
|
|
|
|
|
---
|
|
|
|
src/cryptsetup/cryptsetup-generator.c | 57 ++++++++++++++++++++++++++++++++++-
|
|
|
|
1 file changed, 56 insertions(+), 1 deletion(-)
|
|
|
|
|
2013-08-02 07:26:48 +02:00
|
|
|
--- systemd-206.orig/src/cryptsetup/cryptsetup-generator.c
|
|
|
|
+++ systemd-206/src/cryptsetup/cryptsetup-generator.c
|
2013-04-23 11:39:56 +02:00
|
|
|
@@ -22,6 +22,7 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
2013-08-02 07:26:48 +02:00
|
|
|
@@ -64,6 +65,54 @@ static bool has_option(const char *hayst
|
2013-04-23 11:39:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static int create_storage_after_cryptsetup (void) {
|
|
|
|
+ _cleanup_free_ char *to = NULL, *p = NULL;
|
|
|
|
+ _cleanup_fclose_ FILE *f = NULL;
|
|
|
|
+
|
|
|
|
+ if (asprintf(&p, "%s/storage-after-cryptsetup.service", arg_dest) < 0)
|
|
|
|
+ return log_oom();
|
|
|
|
+
|
|
|
|
+ if (!(f = fopen(p, "wxe"))) {
|
|
|
|
+ log_error("Failed to create unit file: %m");
|
|
|
|
+ return -errno;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fprintf(f,
|
|
|
|
+ "[Unit]\n"
|
|
|
|
+ "Description=Restart storage after cryptsetup\n"
|
|
|
|
+ "DefaultDependencies=no\n"
|
|
|
|
+ "After=cryptsetup.target\n"
|
|
|
|
+ "Wants=cryptsetup.target\n"
|
|
|
|
+ "Before=local-fs.target\n"
|
|
|
|
+ "Before=shutdown.target\n");
|
|
|
|
+
|
|
|
|
+ fprintf(f,
|
|
|
|
+ "\n[Service]\n"
|
|
|
|
+ "RemainAfterExit=true\n"
|
|
|
|
+ "Type=oneshot\n"
|
|
|
|
+ "TimeoutSec=0\n"
|
|
|
|
+ "ExecStart=/usr/bin/systemctl restart lvm.service\n");
|
|
|
|
+
|
|
|
|
+ fflush(f);
|
|
|
|
+
|
|
|
|
+ if (ferror(f)) {
|
|
|
|
+ log_error("Failed to write file: %m");
|
|
|
|
+ return -errno;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (asprintf(&to, "%s/local-fs.target.wants/storage-after-cryptsetup.service", arg_dest) < 0)
|
|
|
|
+ return log_oom();
|
|
|
|
+
|
|
|
|
+ mkdir_parents(to, 0755);
|
|
|
|
+
|
|
|
|
+ if (symlink("../storage-after-cryptsetup.service", to) < 0) {
|
|
|
|
+ log_error("Failed to create symlink ../storage-after-cryptsetup.service to '%s': %m", to);
|
|
|
|
+ return -errno;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static int create_disk(
|
|
|
|
const char *name,
|
|
|
|
const char *device,
|
2013-06-05 13:16:22 +02:00
|
|
|
@@ -334,6 +383,7 @@ int main(int argc, char *argv[]) {
|
2013-04-23 11:39:56 +02:00
|
|
|
_cleanup_fclose_ FILE *f = NULL;
|
|
|
|
unsigned n = 0;
|
|
|
|
int r = EXIT_SUCCESS;
|
|
|
|
+ bool no_crypttab = false;
|
|
|
|
char **i;
|
|
|
|
|
2013-06-05 13:16:22 +02:00
|
|
|
if (argc > 1 && argc != 4) {
|
|
|
|
@@ -361,8 +411,10 @@ int main(int argc, char *argv[]) {
|
|
|
|
|
|
|
|
f = fopen("/etc/crypttab", "re");
|
2013-04-23 11:39:56 +02:00
|
|
|
if (!f) {
|
|
|
|
- if (errno == ENOENT)
|
|
|
|
+ if (errno == ENOENT) {
|
|
|
|
+ no_crypttab = true;
|
|
|
|
r = EXIT_SUCCESS;
|
|
|
|
+ }
|
|
|
|
else {
|
|
|
|
r = EXIT_FAILURE;
|
|
|
|
log_error("Failed to open /etc/crypttab: %m");
|
2013-06-05 13:16:22 +02:00
|
|
|
@@ -464,5 +516,8 @@ next:
|
2013-04-23 11:39:56 +02:00
|
|
|
r = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if ((r == EXIT_SUCCESS && !no_crypttab) && (create_storage_after_cryptsetup () < 0))
|
|
|
|
+ r = EXIT_FAILURE;
|
|
|
|
+
|
|
|
|
return r;
|
|
|
|
}
|