1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

systemd: generator: add lvm2-activation-net.service

The new lvm2-activation-net.service activates LVM volumes
after network-attached devices are set up (iSCSI and FCoE)
if lvmetad is disabled and hence the autoactivation is not
used.
This commit is contained in:
Peter Rajnoha 2013-07-17 16:21:18 +02:00
parent 73e7f6c45f
commit 8606bf316a
2 changed files with 41 additions and 20 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.99 -
===================================
Add lvm2-activation-net systemd unit to activate LVs on net-attached storage.
Release memory allocated with _cached_info().
Add whole log_lv and metadata_lv sub volumes when creating partial tree.
Properly use snapshot layer for origin which is also thin volume.

View File

@ -25,16 +25,27 @@
#define KMSG_DEV_PATH "/dev/kmsg"
#define LVM_CONF_USE_LVMETAD "global/use_lvmetad"
#define DEFAULT_UNIT_DIR "/tmp"
#define UNIT_NAME_EARLY "lvm2-activation-early.service"
#define UNIT_NAME "lvm2-activation.service"
#define UNIT_TARGET "local-fs.target"
#define DEFAULT_UNIT_DIR "/tmp"
#define UNIT_TARGET_LOCAL_FS "local-fs.target"
#define UNIT_TARGET_REMOTE_FS "remote-fs.target"
static char unit_path[PATH_MAX];
static char target_path[PATH_MAX];
static char message[PATH_MAX];
static int kmsg_fd = -1;
enum {
UNIT_EARLY,
UNIT_MAIN,
UNIT_NET
};
static const char *unit_names[] = {
[UNIT_EARLY] = "lvm2-activation-early.service",
[UNIT_MAIN] = "lvm2-activation.service",
[UNIT_NET] = "lvm2-activation-net.service"
};
__attribute__ ((format(printf, 1, 2)))
static void kmsg(const char *format, ...)
{
@ -92,16 +103,17 @@ out:
return r;
}
static int generate_unit(const char *dir, int early)
static int generate_unit(const char *dir, int unit)
{
FILE *f;
const char *unit = early ? UNIT_NAME_EARLY : UNIT_NAME;
const char *unit_name = unit_names[unit];
const char *target_name = unit == UNIT_NET ? UNIT_TARGET_REMOTE_FS : UNIT_TARGET_LOCAL_FS;
if (dm_snprintf(unit_path, PATH_MAX, "%s/%s", dir, unit) < 0)
if (dm_snprintf(unit_path, PATH_MAX, "%s/%s", dir, unit_name) < 0)
return 0;
if (!(f = fopen(unit_path, "wxe"))) {
kmsg("LVM: Failed to create unit file %s: %m.\n", unit);
kmsg("LVM: Failed to create unit file %s: %m.\n", unit_name);
return 0;
}
@ -117,25 +129,31 @@ static int generate_unit(const char *dir, int early)
"SourcePath=/etc/lvm/lvm.conf\n"
"DefaultDependencies=no\n", f);
if (early) {
fputs("After=systemd-udev-settle.service\n", f);
fputs("Before=cryptsetup.target\n", f);
} else
fputs("After=lvm2-activation-early.service cryptsetup.target\n", f);
if (unit == UNIT_NET) {
fputs("After=iscsi.service fcoe.service\n"
"Before=remote-fs.target shutdown.target\n", f);
} else {
if (unit == UNIT_EARLY) {
fputs("After=systemd-udev-settle.service\n", f);
fputs("Before=cryptsetup.target\n", f);
} else
fputs("After=lvm2-activation-early.service cryptsetup.target\n", f);
fputs("Before=local-fs.target shutdown.target\n"
"Wants=systemd-udev-settle.service\n\n"
"[Service]\n"
fputs("Before=local-fs.target shutdown.target\n"
"Wants=systemd-udev-settle.service\n\n", f);
}
fputs("[Service]\n"
"ExecStart=/usr/sbin/lvm vgchange -aay --sysinit\n"
"Type=oneshot\n", f);
if (fclose(f) < 0) {
kmsg("LVM: Failed to write unit file %s: %m.\n", unit);
kmsg("LVM: Failed to write unit file %s: %m.\n", unit_name);
return 0;
}
if (!register_unit_with_target(dir, unit, UNIT_TARGET)) {
kmsg("LVM: Failed to register unit %s with target %s.\n", unit, UNIT_TARGET);
if (!register_unit_with_target(dir, unit_name, target_name)) {
kmsg("LVM: Failed to register unit %s with target %s.\n", unit_name, target_name);
return 0;
}
@ -162,7 +180,9 @@ int main(int argc, char *argv[])
dir = argc > 1 ? argv[1] : DEFAULT_UNIT_DIR;
if (!generate_unit(dir, 1) || !generate_unit(dir, 0))
if (!generate_unit(dir, UNIT_EARLY) ||
!generate_unit(dir, UNIT_MAIN) ||
!generate_unit(dir, UNIT_NET))
r = EXIT_FAILURE;
out:
kmsg("LVM: Activation generator %s.\n", r ? "failed" : "successfully completed");