Add in new targets to handle bmc resets while host running

The point of this new target is to support getting
the systemd targets which boot the host into the
running state (without actually running the associated
services) when the BMC is rebooted and the host is
up and running.  This will ensure that systemd
and its targets match with the state of the system
without affecting the running host.

This commit will run the new target but nothing will
happen yet due to the discovery service being a noop.

Once the application is in for the service to call,
it will be added to the service which will enable this
new host running with bmc reset support.

Change-Id: Ia29e53de58ea7530941341b0e515e4d8fa49be6c
Signed-off-by: Andrew Geissler <andrewg@us.ibm.com>
diff --git a/common/recipes-core/systemd/obmc-targets.bb b/common/recipes-core/systemd/obmc-targets.bb
index 6f83a9e..1cca366 100644
--- a/common/recipes-core/systemd/obmc-targets.bb
+++ b/common/recipes-core/systemd/obmc-targets.bb
@@ -34,19 +34,25 @@
 # - start:                 Services to run to do the host boot
 # - started:               Services to run once the host is booted
 # - stop-pre,stop,stopped: Same as above but applied to shutting down the host
-HOST_SYNCH_TARGETS = "start-pre start started stop-pre stop stopped"
+# - reset-running:         Services to check if host is running after bmc reset
+HOST_SYNCH_TARGETS = "start-pre start started stop-pre stop stopped reset-running"
 
 # Track all host action targets
 # - stop:    Services to run to shutdown the host
 # - quiesce: Target to enter on host boot failure
 HOST_ACTION_TARGETS = "stop quiesce"
 
+# TODO: openbmc/openbmc#1205 - Move this to standard host action targets
+# - reset:   Check host state and update host "start" target if host running
+HOST_ACTION_TARGETS_2 = "reset"
+
 CHASSIS_FMT = "obmc-chassis-{0}@.target"
 SYNCH_POWER_FMT = "obmc-power-{0}@.target"
 CHASSIS_POWER_FMT = "obmc-power-chassis-{0}@.target"
 CHASSIS_POWER_FMT_2 = "obmc-chassis-{0}@.target"
 HOST_SYNCH_FMT = "obmc-host-{0}@.target"
 HOST_ACTION_FMT = "obmc-{0}-host@.target"
+HOST_ACTION_FMT_2 = "obmc-host-{0}@.target"
 
 CHASSIS_LINK_FMT = "${CHASSIS_FMT}:obmc-chassis-{0}@{1}.target"
 SYNCH_POWER_LINK_FMT = "${SYNCH_POWER_FMT}:obmc-power-{0}@{1}.target"
@@ -54,6 +60,7 @@
 CHASSIS_POWER_LINK_FMT_2 = "${CHASSIS_POWER_FMT_2}:obmc-chassis-{0}@{1}.target"
 HOST_LINK_SYNCH_FMT = "${HOST_SYNCH_FMT}:obmc-host-{0}@{1}.target"
 HOST_LINK_ACTION_FMT = "${HOST_ACTION_FMT}:obmc-{0}-host@{1}.target"
+HOST_LINK_ACTION_FMT_2 = "${HOST_ACTION_FMT_2}:obmc-host-{0}@{1}.target"
 
 SYSTEMD_SERVICE_${PN} += " \
         obmc-mapper.target \
@@ -69,6 +76,7 @@
 SYSTEMD_SERVICE_${PN} += "${@compose_list(d, 'CHASSIS_POWER_FMT_2', 'CHASSIS_POWER_TARGETS_2')}"
 SYSTEMD_SERVICE_${PN} += "${@compose_list(d, 'HOST_SYNCH_FMT', 'HOST_SYNCH_TARGETS')}"
 SYSTEMD_SERVICE_${PN} += "${@compose_list(d, 'HOST_ACTION_FMT', 'HOST_ACTION_TARGETS')}"
+SYSTEMD_SERVICE_${PN} += "${@compose_list(d, 'HOST_ACTION_FMT_2', 'HOST_ACTION_TARGETS_2')}"
 
 SYSTEMD_LINK_${PN} += "${@compose_list(d, 'CHASSIS_LINK_FMT', 'CHASSIS_TARGETS', 'OBMC_CHASSIS_INSTANCES')}"
 SYSTEMD_LINK_${PN} += "${@compose_list(d, 'SYNCH_POWER_LINK_FMT', 'SYNCH_POWER_TARGETS', 'OBMC_POWER_INSTANCES')}"
@@ -76,3 +84,4 @@
 SYSTEMD_LINK_${PN} += "${@compose_list(d, 'CHASSIS_POWER_LINK_FMT_2', 'CHASSIS_POWER_TARGETS_2', 'OBMC_CHASSIS_INSTANCES')}"
 SYSTEMD_LINK_${PN} += "${@compose_list(d, 'HOST_LINK_SYNCH_FMT', 'HOST_SYNCH_TARGETS', 'OBMC_HOST_INSTANCES')}"
 SYSTEMD_LINK_${PN} += "${@compose_list(d, 'HOST_LINK_ACTION_FMT', 'HOST_ACTION_TARGETS', 'OBMC_HOST_INSTANCES')}"
+SYSTEMD_LINK_${PN} += "${@compose_list(d, 'HOST_LINK_ACTION_FMT_2', 'HOST_ACTION_TARGETS_2', 'OBMC_HOST_INSTANCES')}"
diff --git a/common/recipes-core/systemd/obmc-targets/obmc-host-reset-running@.target b/common/recipes-core/systemd/obmc-targets/obmc-host-reset-running@.target
new file mode 100644
index 0000000..9edb844
--- /dev/null
+++ b/common/recipes-core/systemd/obmc-targets/obmc-host-reset-running@.target
@@ -0,0 +1,5 @@
+[Unit]
+Description=Host%i running after reset
+Conflicts=obmc-stop-host@%i.target
+RefuseManualStart=yes
+RefuseManualStop=yes
diff --git a/common/recipes-core/systemd/obmc-targets/obmc-host-reset@.target b/common/recipes-core/systemd/obmc-targets/obmc-host-reset@.target
new file mode 100644
index 0000000..3699407
--- /dev/null
+++ b/common/recipes-core/systemd/obmc-targets/obmc-host-reset@.target
@@ -0,0 +1,7 @@
+[Unit]
+Description=Host%i (Reset Check)
+Conflicts=obmc-stop-host%i.target
+RefuseManualStop=yes
+
+[Install]
+WantedBy={SYSTEMD_DEFAULT_TARGET}
diff --git a/common/recipes-phosphor/host/obmc-op-control-host.bb b/common/recipes-phosphor/host/obmc-op-control-host.bb
index fba82d8..fa5a006 100644
--- a/common/recipes-phosphor/host/obmc-op-control-host.bb
+++ b/common/recipes-phosphor/host/obmc-op-control-host.bb
@@ -12,11 +12,34 @@
 
 FMT = "org.openbmc.control.Host@{0}.service"
 DBUS_SERVICE_${PN} += "${@compose_list(d, 'FMT', 'OBMC_HOST_INSTANCES')}"
-SYSTEMD_SERVICE_${PN} = "op-start-host@.service"
+SYSTEMD_SERVICE_${PN} = " \
+        op-start-host@.service \
+        op-reset-host-check@.service \
+        op-reset-host-running@.service \
+        "
 
 START_TMPL = "op-start-host@.service"
 START_TGTFMT = "obmc-chassis-start@{1}.target"
 START_INSTFMT = "obmc-start-host@{0}.service"
 START_FMT = "../${START_TMPL}:${START_TGTFMT}.requires/${START_INSTFMT}"
 
+RESET_CHECK_TMPL = "op-reset-host-check@.service"
+RESET_CHECK_TGTFMT = "obmc-host-reset@{1}.target"
+RESET_CHECK_INSTFMT = "op-reset-host-check@{0}.service"
+RESET_CHECK_FMT = "../${RESET_CHECK_TMPL}:${RESET_CHECK_TGTFMT}.requires/${RESET_CHECK_INSTFMT}"
+
+RESET_RUNNING_TMPL = "op-reset-host-running@.service"
+RESET_RUNNING_TGTFMT = "obmc-host-reset@{1}.target"
+RESET_RUNNING_INSTFMT = "op-reset-host-running@{0}.service"
+RESET_RUNNING_FMT = "../${RESET_RUNNING_TMPL}:${RESET_RUNNING_TGTFMT}.requires/${RESET_RUNNING_INSTFMT}"
+
 SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'START_FMT', 'OBMC_HOST_INSTANCES', 'OBMC_CHASSIS_INSTANCES')}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'RESET_CHECK_FMT', 'OBMC_HOST_INSTANCES', 'OBMC_HOST_INSTANCES')}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'RESET_RUNNING_FMT', 'OBMC_HOST_INSTANCES', 'OBMC_HOST_INSTANCES')}"
+
+# Force the standby target to run the host reset check target
+RESET_TMPL_CTRL = "obmc-host-reset@.target"
+SYSD_TGT = "${SYSTEMD_DEFAULT_TARGET}"
+RESET_INSTFMT_CTRL = "obmc-host-reset@{0}.target"
+RESET_FMT_CTRL = "../${RESET_TMPL_CTRL}:${SYSD_TGT}.wants/${RESET_INSTFMT_CTRL}"
+SYSTEMD_LINK_${PN} += "${@compose_list_zip(d, 'RESET_FMT_CTRL', 'OBMC_HOST_INSTANCES')}"
diff --git a/common/recipes-phosphor/host/obmc-op-control-host/op-reset-host-check@.service b/common/recipes-phosphor/host/obmc-op-control-host/op-reset-host-check@.service
new file mode 100644
index 0000000..e3fcb04
--- /dev/null
+++ b/common/recipes-phosphor/host/obmc-op-control-host/op-reset-host-check@.service
@@ -0,0 +1,19 @@
+[Unit]
+Description=Check Host%i status on BMC reset
+Wants=mapper-wait@-xyz-openbmc_project-control-host%i.service
+After=mapper-wait@-xyz-openbmc_project-control-host%i.service
+Wants=obmc-host-reset-running@%i.target
+Before=obmc-host-reset-running@%i.target
+Wants=op-reset-chassis-on@%i.service
+After=op-reset-chassis-on@%i.service
+Conflicts=obmc-stop-host@%i.target
+ConditionPathExists=/run/openbmc/chassis@%i-on
+
+[Service]
+RemainAfterExit=yes
+Type=oneshot
+ExecStart=/bin/sh -c "echo TODO - Check Host Status on BMC Reset"
+
+
+[Install]
+WantedBy=obmc-host-reset@%i.target
diff --git a/common/recipes-phosphor/host/obmc-op-control-host/op-reset-host-running@.service b/common/recipes-phosphor/host/obmc-op-control-host/op-reset-host-running@.service
new file mode 100644
index 0000000..7f3871e
--- /dev/null
+++ b/common/recipes-phosphor/host/obmc-op-control-host/op-reset-host-running@.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Start host%i running after BMC reset
+After=obmc-host-reset-running@%i.target
+Requires=obmc-host-reset-running@%i.target
+ConditionPathExists=/run/openbmc/host@%i-on
+
+[Service]
+RemainAfterExit=no
+# TODO: openbmc/openbmc#1205 - target name refactor
+ExecStart=/bin/systemctl start obmc-chassis-start@%i.target
+
+
+[Install]
+WantedBy=obmc-host-reset@%i.target