]> git.ozlabs.org Git - petitboot/commitdiff
discover: Add safe mode
authorJeremy Kerr <jk@ozlabs.org>
Mon, 21 Jul 2014 10:18:35 +0000 (18:18 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Tue, 22 Jul 2014 01:04:59 +0000 (09:04 +0800)
Safe mode configures the discover server to not start any device
parsing; this can be used to diagnose any problems with early device
handing.

In safe mode, we don't initialise any of the device sources - udev,
network and user events are disabled.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/device-handler.c
discover/platform.c
lib/pb-config/pb-config.c
lib/pb-protocol/pb-protocol.c
lib/types/types.h

index b93cdfa1130cc5c956e6608a997c118a3786cd08..e4978faaffd13d4a0c3545d10caf54955062b5c2 100644 (file)
@@ -285,6 +285,9 @@ struct device_handler *device_handler_init(struct discover_server *server,
 
        parser_init();
 
 
        parser_init();
 
+       if (config_get()->safe_mode)
+               return handler;
+
        rc = device_handler_init_sources(handler);
        if (rc) {
                talloc_free(handler);
        rc = device_handler_init_sources(handler);
        if (rc) {
                talloc_free(handler);
@@ -842,6 +845,13 @@ static int device_handler_init_sources(struct device_handler *handler)
 
 static void device_handler_reinit_sources(struct device_handler *handler)
 {
 
 static void device_handler_reinit_sources(struct device_handler *handler)
 {
+       /* if we haven't initialised sources previously (becuase we started in
+        * safe mode), then init once here. */
+       if (!(handler->udev || handler->network || handler->user_event)) {
+               device_handler_init_sources(handler);
+               return;
+       }
+
        udev_reinit(handler->udev);
 
        network_shutdown(handler->network);
        udev_reinit(handler->udev);
 
        network_shutdown(handler->network);
index 3ab6b7b7e5eaa7199e92a1e8361e2ff49ae24d42..be60f00fb8205dd4407f0fb14ac84fab5d69b837 100644 (file)
@@ -43,6 +43,9 @@ static void dump_config(struct config *config)
        if (config->network.n_interfaces || config->network.n_dns_servers)
                pb_log(" network configuration:\n");
 
        if (config->network.n_interfaces || config->network.n_dns_servers)
                pb_log(" network configuration:\n");
 
+       if (config->safe_mode)
+               pb_log(" safe mode: active\n");
+
        for (i = 0; i < config->network.n_interfaces; i++) {
                struct interface_config *ifconf =
                        config->network.interfaces[i];
        for (i = 0; i < config->network.n_interfaces; i++) {
                struct interface_config *ifconf =
                        config->network.interfaces[i];
index 2adc7b248d8b956569ff971464cf6e2bc74092e4..d43a5abba718bd1eedab88149b4d4aeaf6063589 100644 (file)
@@ -42,6 +42,7 @@ struct config *config_copy(void *ctx, const struct config *src)
        dest = talloc(ctx, struct config);
        dest->autoboot_enabled = src->autoboot_enabled;
        dest->autoboot_timeout_sec = src->autoboot_timeout_sec;
        dest = talloc(ctx, struct config);
        dest->autoboot_enabled = src->autoboot_enabled;
        dest->autoboot_timeout_sec = src->autoboot_timeout_sec;
+       dest->safe_mode = src->safe_mode;
 
        dest->network.n_interfaces = src->network.n_interfaces;
        dest->network.interfaces = talloc_array(dest, struct interface_config *,
 
        dest->network.n_interfaces = src->network.n_interfaces;
        dest->network.interfaces = talloc_array(dest, struct interface_config *,
index 67e1f9e91a04dbf52e3ffebecc0a2371feca35a4..d39c1c490e1a782bf5a8b9c176e7250b459a5979 100644 (file)
@@ -267,7 +267,8 @@ int pb_protocol_config_len(const struct config *config)
        unsigned int i, len;
 
        len =   4 /* config->autoboot_enabled */ +
        unsigned int i, len;
 
        len =   4 /* config->autoboot_enabled */ +
-               4 /* config->autoboot_timeout_sec */;
+               4 /* config->autoboot_timeout_sec */ +
+               4 /* config->safe_mode */;
 
        len += 4;
        for (i = 0; i < config->network.n_interfaces; i++)
 
        len += 4;
        for (i = 0; i < config->network.n_interfaces; i++)
@@ -448,6 +449,9 @@ int pb_protocol_serialise_config(const struct config *config,
        *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
        pos += 4;
 
        *(uint32_t *)pos = __cpu_to_be32(config->autoboot_timeout_sec);
        pos += 4;
 
+       *(uint32_t *)pos = config->safe_mode;
+       pos += 4;
+
        *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
        pos += 4;
        for (i = 0; i < config->network.n_interfaces; i++) {
        *(uint32_t *)pos = __cpu_to_be32(config->network.n_interfaces);
        pos += 4;
        for (i = 0; i < config->network.n_interfaces; i++) {
@@ -862,6 +866,10 @@ int pb_protocol_deserialise_config(struct config *config,
        if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
                goto out;
 
        if (read_u32(&pos, &len, &config->autoboot_timeout_sec))
                goto out;
 
+       if (read_u32(&pos, &len, &tmp))
+               goto out;
+       config->safe_mode = !!tmp;
+
        if (read_u32(&pos, &len, &config->network.n_interfaces))
                goto out;
 
        if (read_u32(&pos, &len, &config->network.n_interfaces))
                goto out;
 
index 762530a36d46467d3770e3411d8f1460fabdab5c..0333a02d9aa385b4eb121574813d85e862120bfd 100644 (file)
@@ -121,6 +121,7 @@ struct boot_priority {
 struct config {
        bool                    autoboot_enabled;
        unsigned int            autoboot_timeout_sec;
 struct config {
        bool                    autoboot_enabled;
        unsigned int            autoboot_timeout_sec;
+       bool                    safe_mode;
        struct network_config   network;
        struct boot_priority    *boot_priorities;
        unsigned int            n_boot_priorities;
        struct network_config   network;
        struct boot_priority    *boot_priorities;
        unsigned int            n_boot_priorities;