From 784a71e2bfb15f20675c11f06f834b1374335fe9 Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Tue, 17 Jun 2014 12:07:52 -0700 Subject: [PATCH] fix(configdrive): Use mount units, give virtfs a new mount point. Currently systemd cannot track dependencies on configdrive very well because it is mounted via a service instead of a mount unit. Also since the interaction between path and mount units can lead to unexpected behavior if something goes wrong the cloudinit service is now triggered explicitly by the mount again. The configdrive path unit remains only as a fall back for containers where the mount unit doesn't kick in. Better to have two mechanisms that trigger the cloudinit service than none. :) Since mounting a virtfs based configdrive requires different mount options and two different mount units cannot refer to the same path the virtfs version now mounts to /media/configvirtfs. There are also two new kernel options: - `coreos.configdrive=1`: enable config drive on physical hardware. - `coreos.configdrive=0`: disable config drive on virtual machines. --- units/90-configdrive.rules | 4 ++-- units/configdrive-block.service | 11 ----------- units/configdrive-virtfs.service | 14 -------------- units/media-configdrive.mount | 13 +++++++++++++ units/media-configvirtfs.mount | 18 ++++++++++++++++++ units/user-configdrive.path | 5 +++++ units/user-configvirtfs.service | 11 +++++++++++ 7 files changed, 49 insertions(+), 27 deletions(-) delete mode 100644 units/configdrive-block.service delete mode 100644 units/configdrive-virtfs.service create mode 100644 units/media-configdrive.mount create mode 100644 units/media-configvirtfs.mount create mode 100644 units/user-configvirtfs.service diff --git a/units/90-configdrive.rules b/units/90-configdrive.rules index 3bfea06..4005a3e 100644 --- a/units/90-configdrive.rules +++ b/units/90-configdrive.rules @@ -3,9 +3,9 @@ ACTION!="add|change", GOTO="coreos_configdrive_end" # A normal config drive. Block device formatted with iso9660 or fat -SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="iso9660|vfat", ENV{ID_FS_LABEL}=="config-2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="configdrive-block.service" +SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="iso9660|vfat", ENV{ID_FS_LABEL}=="config-2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="media-configdrive.mount" # Addtionally support virtfs from QEMU -SUBSYSTEM=="virtio", DRIVER=="9pnet_virtio", ATTR{mount_tag}=="config-2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="configdrive-virtfs.service" +SUBSYSTEM=="virtio", DRIVER=="9pnet_virtio", ATTR{mount_tag}=="config-2", TAG+="systemd", ENV{SYSTEMD_WANTS}+="media-configvirtfs.mount" LABEL="coreos_configdrive_end" diff --git a/units/configdrive-block.service b/units/configdrive-block.service deleted file mode 100644 index 873fd73..0000000 --- a/units/configdrive-block.service +++ /dev/null @@ -1,11 +0,0 @@ -[Unit] -Description=Mount config drive -Conflicts=configdrive-virtfs.service umount.target -ConditionPathIsMountPoint=!/media/configdrive -# Only mount config drive block devices automatically in virtual machines -ConditionVirtualization=vm - -[Service] -Type=oneshot -RemainAfterExit=no -ExecStart=/bin/mount -t auto -o ro,x-mount.mkdir LABEL=config-2 /media/configdrive diff --git a/units/configdrive-virtfs.service b/units/configdrive-virtfs.service deleted file mode 100644 index bc29612..0000000 --- a/units/configdrive-virtfs.service +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Mount config drive from virtfs -Conflicts=configdrive-block.service umount.target -ConditionPathIsMountPoint=!/media/configdrive -ConditionVirtualization=vm - -# Support old style setup for now -Wants=addon-run@media-configdrive.service addon-config@media-configdrive.service -Before=addon-run@media-configdrive.service addon-config@media-configdrive.service - -[Service] -Type=oneshot -RemainAfterExit=no -ExecStart=/bin/mount -t 9p -o trans=virtio,version=9p2000.L,x-mount.mkdir config-2 /media/configdrive diff --git a/units/media-configdrive.mount b/units/media-configdrive.mount new file mode 100644 index 0000000..ee76654 --- /dev/null +++ b/units/media-configdrive.mount @@ -0,0 +1,13 @@ +[Unit] +Wants=user-configdrive.service +Before=user-configdrive.service +# Only mount config drive block devices automatically in virtual machines +# or any host that has it explicitly enabled and not explicitly disabled. +ConditionVirtualization=|vm +ConditionKernelCommandLine=|coreos.configdrive=1 +ConditionKernelCommandLine=!coreos.configdrive=0 + +[Mount] +What=LABEL=config-2 +Where=/media/configdrive +Options=ro diff --git a/units/media-configvirtfs.mount b/units/media-configvirtfs.mount new file mode 100644 index 0000000..669154c --- /dev/null +++ b/units/media-configvirtfs.mount @@ -0,0 +1,18 @@ +[Unit] +Wants=user-configvirtfs.service +Before=user-configvirtfs.service +# Only mount config drive block devices automatically in virtual machines +# or any host that has it explicitly enabled and not explicitly disabled. +ConditionVirtualization=|vm +ConditionKernelCommandLine=|coreos.configdrive=1 +ConditionKernelCommandLine=!coreos.configdrive=0 + +# Support old style setup for now +Wants=addon-run@media-configvirtfs.service addon-config@media-configvirtfs.service +Before=addon-run@media-configvirtfs.service addon-config@media-configvirtfs.service + +[Mount] +What=config-2 +Where=/media/configvirtfs +Options=ro,trans=virtio,version=9p2000.L +Type=9p diff --git a/units/user-configdrive.path b/units/user-configdrive.path index 77a615a..fea642e 100644 --- a/units/user-configdrive.path +++ b/units/user-configdrive.path @@ -1,5 +1,10 @@ [Unit] Description=Watch for a cloud-config at /media/configdrive +# Note: This unit is essentially just here as a fall-back mechanism to +# trigger cloudinit if it isn't triggered explicitly by other means +# such as by a Wants= in the mount unit. This ensures we handle the +# case where /media/configdrive is provided to a CoreOS container. + [Path] DirectoryNotEmpty=/media/configdrive diff --git a/units/user-configvirtfs.service b/units/user-configvirtfs.service new file mode 100644 index 0000000..c9839ad --- /dev/null +++ b/units/user-configvirtfs.service @@ -0,0 +1,11 @@ +[Unit] +Description=Load cloud-config from /media/configvirtfs +Requires=coreos-setup-environment.service +After=coreos-setup-environment.service +Before=user-config.target + +[Service] +Type=oneshot +RemainAfterExit=yes +EnvironmentFile=-/etc/environment +ExecStart=/usr/bin/coreos-cloudinit --from-configdrive=/media/configvirtfs