From patchwork Tue Jul 3 06:34:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 938407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KZDy63fSz9s29 for ; Tue, 3 Jul 2018 16:37:54 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Vw4NV5NF"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41KZDy4PmTzF1PF for ; Tue, 3 Jul 2018 16:37:54 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Vw4NV5NF"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41KZDG3XDgzF1LQ for ; Tue, 3 Jul 2018 16:37:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="Vw4NV5NF"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 41KZDG1b6Lz9s3C; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1530599838; bh=FrxRQgdcy8AHAiZwEdyagAYnQBOE4YJ+VS4k4em+8GE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vw4NV5NF2BHA9eViedetFJImMUID7vP9ym8nyl8cgw8wfic15nGUjMRbxKvQ8L/o4 G3eYf3LHa1TtEUVpV5jaN7L655eR8vK2oFOvVOYxBKb9/N4qe72gS9FRYBzwSYN7aE UnyEGeQQoxBfdPOmS7PgVLFYfNGtJBKBZhIJMIzbLqw8UXwoLkI4qRBlxeQfg8fs2e 1zdRwtOZvGCKLAwST7/9MhiIslqfSfBI+eoISvYlcO/tfYpqR0h36esOFV1l0/Lx0J NUEpMimYOSBBvennC05vZ8r+vFL/tOtOv4bPyYFJR3e7SjUhwBzrvR2O/Inr30qc3o WKuLypoVcWiKQ== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 1/5] protocol: Add definition and serialisation for temporary autoboot Date: Tue, 3 Jul 2018 16:34:43 +1000 Message-Id: <20180703063447.8338-2-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703063447.8338-1-jk@ozlabs.org> References: <20180703063447.8338-1-jk@ozlabs.org> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yewei@inspur.com MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add a new message format for a temporarily-applied autoboot setting. Signed-off-by: Jeremy Kerr --- lib/pb-protocol/pb-protocol.c | 70 +++++++++++++++++++++++++++++++++++++++++++ lib/pb-protocol/pb-protocol.h | 6 ++++ 2 files changed, 76 insertions(+) diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index dbbda40..8e37348 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -363,6 +363,21 @@ int pb_protocol_plugin_option_len(const struct plugin_option *opt) return len; } +int pb_protocol_temp_autoboot_len(const struct autoboot_option *opt) +{ + unsigned int len = 0; + + /* boot_type */ + len += 4; + + if (opt->boot_type == BOOT_DEVICE_TYPE) + len += 4; + else + len += optional_strlen(opt->uuid); + + return len; +} + int pb_protocol_serialise_device(const struct device *dev, char *buf, int buf_len) { @@ -663,6 +678,26 @@ int pb_protocol_serialise_plugin_option(const struct plugin_option *opt, return 0; } +int pb_protocol_serialise_temp_autoboot(const struct autoboot_option *opt, + char *buf, int buf_len) +{ + char *pos = buf; + + *(uint32_t *)pos = __cpu_to_be32(opt->boot_type); + pos += 4; + + if (opt->boot_type == BOOT_DEVICE_TYPE) { + *(uint32_t *)pos = __cpu_to_be32(opt->type); + pos += 4; + } else { + pos += pb_protocol_serialise_string(pos, opt->uuid); + } + + (void)buf_len; + + return 0; +} + int pb_protocol_write_message(int fd, struct pb_protocol_message *message) { int total_len, rc; @@ -1265,3 +1300,38 @@ int pb_protocol_deserialise_plugin_option(struct plugin_option *opt, out: return rc; } + +int pb_protocol_deserialise_temp_autoboot(struct autoboot_option *opt, + const struct pb_protocol_message *message) +{ + unsigned int len, tmp; + const char *pos; + int rc = -1; + char *str; + + len = message->payload_len; + pos = message->payload; + + if (read_u32(&pos, &len, &tmp)) + goto out; + + opt->boot_type = tmp; + if (opt->boot_type == BOOT_DEVICE_TYPE) { + if (read_u32(&pos, &len, &tmp)) + goto out; + opt->type = tmp; + + } else if (opt->boot_type == BOOT_DEVICE_UUID) { + if (read_string(opt, &pos, &len, &str)) + goto out; + opt->uuid = str; + + } else { + return -1; + } + + rc = 0; + +out: + return rc; +} diff --git a/lib/pb-protocol/pb-protocol.h b/lib/pb-protocol/pb-protocol.h index 250c2d1..14fd8a2 100644 --- a/lib/pb-protocol/pb-protocol.h +++ b/lib/pb-protocol/pb-protocol.h @@ -26,6 +26,7 @@ enum pb_protocol_action { PB_PROTOCOL_ACTION_PLUGIN_OPTION_ADD = 0xc, PB_PROTOCOL_ACTION_PLUGINS_REMOVE = 0xd, PB_PROTOCOL_ACTION_PLUGIN_INSTALL = 0xe, + PB_PROTOCOL_ACTION_TEMP_AUTOBOOT = 0xf, }; struct pb_protocol_message { @@ -44,6 +45,7 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo); int pb_protocol_config_len(const struct config *config); int pb_protocol_url_len(const char *url); int pb_protocol_plugin_option_len(const struct plugin_option *opt); +int pb_protocol_temp_autoboot_len(const struct autoboot_option *opt); int pb_protocol_device_cmp(const struct device *a, const struct device *b); int pb_protocol_boot_option_cmp(const struct boot_option *a, @@ -68,6 +70,8 @@ int pb_protocol_serialise_config(const struct config *config, int pb_protocol_serialise_url(const char *url, char *buf, int buf_len); int pb_protocol_serialise_plugin_option(const struct plugin_option *opt, char *buf, int buf_len); +int pb_protocol_serialise_temp_autoboot(const struct autoboot_option *opt, + char *buf, int buf_len); int pb_protocol_write_message(int fd, struct pb_protocol_message *message); @@ -96,4 +100,6 @@ int pb_protocol_deserialise_config(struct config *config, int pb_protocol_deserialise_plugin_option(struct plugin_option *opt, const struct pb_protocol_message *message); +int pb_protocol_deserialise_temp_autoboot(struct autoboot_option *opt, + const struct pb_protocol_message *message); #endif /* _PB_PROTOCOL_H */ From patchwork Tue Jul 3 06:34:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 938405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KZDh0SLPz9s29 for ; Tue, 3 Jul 2018 16:37:40 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="mo3lW2u5"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41KZDg5yHSzF1PM for ; Tue, 3 Jul 2018 16:37:39 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="mo3lW2u5"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41KZDG1V3wzF1LM for ; Tue, 3 Jul 2018 16:37:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="mo3lW2u5"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 41KZDF6BqSz9s3R; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1530599837; bh=dsPmK2POGGsCxSEFo4R29R5j7GNlkXpXnovUkAqpDy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mo3lW2u5BMwqyT2L8aCZHACC9NW4geetn3F9lXEikIWGPrl7RTbfsBLEvU0tCT5Bb 58wIXgZpUwiRLQlV55AgqHVZHTT5xrN7PgAoXKoKb2ozc2P0M5yTWuzRrrkp1FYTBC FmHeQlsNmIgkGZEIKFJbbNk4qwYkQ2qaxE5kXrVfPutLXLSlgZVK2E/EYOsVPW0Pzq Exsa7m0sfMpBltiHWtX2zGBh+b+DeAYblLEI/AoVsk8Xm08oOvDnWUgqXzlJVN/hyq 9uYQEHGLr9SVYWJdhg8Yvm3sHN5xYJXFxzat3i9/Id7uodo4RuKsMtlt4XNgxD8MSA T3jgxTmz8+j3w== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 2/5] discover/handler: Split autoboot matching into a new function Date: Tue, 3 Jul 2018 16:34:44 +1000 Message-Id: <20180703063447.8338-3-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703063447.8338-1-jk@ozlabs.org> References: <20180703063447.8338-1-jk@ozlabs.org> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yewei@inspur.com MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" A future change will want to match autoboot option settings, so abstract this into its own function. Signed-off-by: Jeremy Kerr --- discover/device-handler.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/discover/device-handler.c b/discover/device-handler.c index aa61bd2..7d8b53c 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -779,24 +779,31 @@ static bool ipmi_device_type_matches(enum ipmi_bootdev ipmi_type, return false; } +static bool autoboot_option_matches(struct autoboot_option *opt, + struct discover_device *dev) +{ + if (opt->boot_type == BOOT_DEVICE_UUID) + if (!strcmp(opt->uuid, dev->uuid)) + return true; + + if (opt->boot_type == BOOT_DEVICE_TYPE) + if (opt->type == dev->device->type || + opt->type == DEVICE_TYPE_ANY) + return true; + + return false; +} + static int autoboot_option_priority(const struct config *config, struct discover_boot_option *opt) { - enum device_type type = opt->device->device->type; - const char *uuid = opt->device->uuid; struct autoboot_option *auto_opt; unsigned int i; for (i = 0; i < config->n_autoboot_opts; i++) { auto_opt = &config->autoboot_opts[i]; - if (auto_opt->boot_type == BOOT_DEVICE_UUID) - if (!strcmp(auto_opt->uuid, uuid)) - return DEFAULT_PRIORITY_LOCAL_FIRST + i; - - if (auto_opt->boot_type == BOOT_DEVICE_TYPE) - if (auto_opt->type == type || - auto_opt->type == DEVICE_TYPE_ANY) - return DEFAULT_PRIORITY_LOCAL_FIRST + i; + if (autoboot_option_matches(auto_opt, opt->device)) + return DEFAULT_PRIORITY_LOCAL_FIRST + i; } return -1; From patchwork Tue Jul 3 06:34:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 938404 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KZDX6ryGz9s3q for ; Tue, 3 Jul 2018 16:37:32 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="dFpQplj1"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41KZDX5LfgzF1LP for ; Tue, 3 Jul 2018 16:37:32 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="dFpQplj1"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41KZDG29bVzF1LP for ; Tue, 3 Jul 2018 16:37:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="dFpQplj1"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 41KZDG0Gbfz9s3Z; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1530599838; bh=oNOm7LwqtfrR9ulLtCm8en333BIP4v9KaWVz7bpBfcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dFpQplj12FjNJb8r279LXCTi2/466piK+lf6NKIl3CSVhCNSQuq3QI7hdYREsFVa/ kaf6GpKzYWo/39EDKzNx77/D5byxZZ/7nNvuc9uTh15VNzkWhvTm1PO/8GHcr2jajE lSNFusqPX+u9s5LL8QAjYO0XT0Cr13L3YvpJ6J6NWjklZcOc4ztZLraPeQR86tOcf/ rr/kV3RVWZZiDd13ij6htaiaAcm06vZ0F9HvyXR9e/Ermxr4fZKcYCaEuStAmTuNmz jeOankFA8OUv3bqH0hW+H6J3A+IUZhcP0oNrun5pwOi8CU1Sw+ynol84DaTJUe12Z/ D8zW0oSVzxWuQ== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 3/5] discover/handler: Implement temporary autoboot messages Date: Tue, 3 Jul 2018 16:34:45 +1000 Message-Id: <20180703063447.8338-4-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703063447.8338-1-jk@ozlabs.org> References: <20180703063447.8338-1-jk@ozlabs.org> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yewei@inspur.com MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Handle incoming requests for temporary autoboot settings. Signed-off-by: Jeremy Kerr --- discover/device-handler.c | 70 +++++++++++++++++++++++++++++++++++++++------- discover/device-handler.h | 2 ++ discover/discover-server.c | 16 +++++++++++ 3 files changed, 78 insertions(+), 10 deletions(-) diff --git a/discover/device-handler.c b/discover/device-handler.c index 7d8b53c..3d75e57 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -43,8 +43,9 @@ #include "ipmi.h" enum default_priority { - DEFAULT_PRIORITY_REMOTE = 1, - DEFAULT_PRIORITY_LOCAL_FIRST = 2, + DEFAULT_PRIORITY_TEMP_USER = 1, + DEFAULT_PRIORITY_REMOTE = 2, + DEFAULT_PRIORITY_LOCAL_FIRST = 3, DEFAULT_PRIORITY_LOCAL_LAST = 0xfe, DEFAULT_PRIORITY_DISABLED = 0xff, }; @@ -75,6 +76,7 @@ struct device_handler { struct waiter *timeout_waiter; bool autoboot_enabled; unsigned int sec_to_boot; + struct autoboot_option *temp_autoboot; struct discover_boot_option *default_boot_option; int default_boot_option_priority; @@ -815,19 +817,30 @@ static int autoboot_option_priority(const struct config *config, * for these options. */ static enum default_priority default_option_priority( + struct device_handler *handler, struct discover_boot_option *opt) { const struct config *config; + /* Temporary user-provided autoboot options have highest priority */ + if (handler->temp_autoboot) { + if (autoboot_option_matches(handler->temp_autoboot, + opt->device)) + return DEFAULT_PRIORITY_TEMP_USER; + + pb_debug("handler: disabled default priority due to " + "temporary user override\n"); + return DEFAULT_PRIORITY_DISABLED; + } + config = config_get(); - /* We give highest priority to IPMI-configured boot options. If - * we have an IPMI bootdev configuration set, then we don't allow - * any other defaults */ - if (config->ipmi_bootdev) { - bool ipmi_match = ipmi_device_type_matches(config->ipmi_bootdev, - opt->device->device->type); - if (ipmi_match) + /* Next highest priority to IPMI-configured boot options. If we have an + * IPMI bootdev configuration set, then we don't allow any other + * defaults */ + if (config->ipmi_bootdev) { bool ipmi_match = + ipmi_device_type_matches(config->ipmi_bootdev, + opt->device->device->type); if (ipmi_match) return DEFAULT_PRIORITY_REMOTE; pb_debug("handler: disabled default priority due to " @@ -863,7 +876,7 @@ static void set_default(struct device_handler *handler, pb_debug("handler: new default option: %s\n", opt->option->id); - new_prio = default_option_priority(opt); + new_prio = default_option_priority(handler, opt); /* Anything outside our range prevents a default boot */ if (new_prio >= DEFAULT_PRIORITY_DISABLED) @@ -903,6 +916,43 @@ static void set_default(struct device_handler *handler, default_timeout(handler); } +void device_handler_apply_temp_autoboot(struct device_handler *handler, + struct autoboot_option *opt) +{ + unsigned int i; + + handler->temp_autoboot = talloc_steal(handler, opt); + + if (!handler->autoboot_enabled) + return; + + if (!handler->default_boot_option) + return; + + if (autoboot_option_matches(opt, handler->default_boot_option->device)) + return; + + /* cancel the default, and rescan available options */ + device_handler_cancel_default(handler); + + handler->autoboot_enabled = true; + + for (i = 0; i < handler->n_devices; i++) { + struct discover_device *dev = handler->devices[i]; + struct discover_boot_option *boot_opt; + + if (!autoboot_option_matches(opt, dev)) + continue; + + list_for_each_entry(&dev->boot_options, boot_opt, list) { + if (boot_opt->option->is_default) { + set_default(handler, boot_opt); + break; + } + } + } +} + static bool resource_is_resolved(struct resource *res) { return !res || res->resolved; diff --git a/discover/device-handler.h b/discover/device-handler.h index 771cd06..b215663 100644 --- a/discover/device-handler.h +++ b/discover/device-handler.h @@ -163,6 +163,8 @@ void device_handler_process_url(struct device_handler *handler, void device_handler_install_plugin(struct device_handler *handler, const char *plugin_file); void device_handler_reinit(struct device_handler *handler); +void device_handler_apply_temp_autoboot(struct device_handler *handler, + struct autoboot_option *opt); int device_request_write(struct discover_device *dev, bool *release); void device_release_write(struct discover_device *dev, bool release); diff --git a/discover/discover-server.c b/discover/discover-server.c index 814053d..3377fa6 100644 --- a/discover/discover-server.c +++ b/discover/discover-server.c @@ -247,6 +247,7 @@ static int write_config_message(struct discover_server *server, static int discover_server_process_message(void *arg) { + struct autoboot_option *autoboot_opt; struct pb_protocol_message *message; struct boot_command *boot_command; struct client *client = arg; @@ -311,6 +312,21 @@ static int discover_server_process_message(void *arg) device_handler_install_plugin(client->server->device_handler, url); break; + + case PB_PROTOCOL_ACTION_TEMP_AUTOBOOT: + autoboot_opt = talloc_zero(client, struct autoboot_option); + rc = pb_protocol_deserialise_temp_autoboot(autoboot_opt, + message); + if (rc) { + pb_log("can't parse temporary autoboot message\n"); + return 0; + } + + device_handler_apply_temp_autoboot( + client->server->device_handler, + autoboot_opt); + break; + default: pb_log("%s: invalid action %d\n", __func__, message->action); return 0; From patchwork Tue Jul 3 06:34:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 938403 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KZDP5hnGz9s2R for ; Tue, 3 Jul 2018 16:37:25 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="fD9zDlJr"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41KZDP1ztrzF1PD for ; Tue, 3 Jul 2018 16:37:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="fD9zDlJr"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41KZDG4SGlzF1LS for ; Tue, 3 Jul 2018 16:37:18 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="fD9zDlJr"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 41KZDG2xt5z9s47; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1530599838; bh=h3MvKlaApuirAo3b6YdowqnilU10850yaZRdfjF7YG4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fD9zDlJr9eggbAxeYir10M7jr8gkc62I04uHHkIIjwap3lxSLFLyWqzDK4AyWmTgX WdoGH+mrr6oSawSTZVVTlslNQQw5kCp4qN9DiFULc6NWJRqMlQ/BkvVv6f1imfOZN5 4avJIsGVcTS4bZcsUO+3BqaoV88NQb85Oe5Oe3nzKa8jQBDdjQIQKmdxWeMaWOIJo5 mu1bTZ3m+c7mH/FIIkqtrqyIAa57WM5xp81mgDuX5m3w62ZthU4fOg5VuO0x35Hzt/ 8Kjq+2AFzcYp3an/K5JzKq44NTQ6YnkLWzL5R71jLiBMVXXThtEItXTI4IvMo04oOX F1QLPLG0cr+fg== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 4/5] ui/ncurses: Implement non-boot-cancelling keys Date: Tue, 3 Jul 2018 16:34:46 +1000 Message-Id: <20180703063447.8338-5-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703063447.8338-1-jk@ozlabs.org> References: <20180703063447.8338-1-jk@ozlabs.org> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yewei@inspur.com MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Allow some keys to not cancel the default-boot process. For the moment, this is just the screen refresh (ctrl+L). Signed-off-by: Jeremy Kerr --- ui/ncurses/nc-cui.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 8a3f97d..87540ca 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -527,6 +527,14 @@ struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr) return old; } +static bool key_cancels_boot(int key) +{ + if (key == 0xc) + return false; + + return true; +} + static bool process_global_keys(struct cui *cui, int key) { switch (key) { @@ -582,7 +590,7 @@ static int cui_process_key(void *arg) } } - if (!cui->has_input) { + if (!cui->has_input && key_cancels_boot(c)) { cui->has_input = true; if (cui->client) { pb_log("UI input received (key = %d), aborting " From patchwork Tue Jul 3 06:34:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 938406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KZDq2QSGz9s29 for ; Tue, 3 Jul 2018 16:37:47 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="DG8vynoe"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41KZDq0vlyzF1Nr for ; Tue, 3 Jul 2018 16:37:47 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="DG8vynoe"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41KZDF6v1czF1LK for ; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="DG8vynoe"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 41KZDF5Xs7z9s29; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1530599837; bh=9MmWW3eAAPP5Gjmb5kmHCBvT8joBoyWre9GkndCs5I4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DG8vynoep9uERxibFwaF46hYUmq4i+3j947fHBbUAhC8au21Tq3JiZijS23H58VFk bX+bLemYj6r8y0nY8ldMkOSAh1qBHjYTcV7z4T96D4QWmUIIXq8MwG5PeGXNZrsis0 0oZz/lqNbRPSzyYD3JAMgLEXzXnA/8a/ldI5SxHWnEPqrVY7shJrZBIdHgGzndaFWN yiYIqpdmQ/LHEqJYlMdquvsEFBikVIlJ/sO/ftzqQ6nk6Za+BVQx9bNpGjzwNqtkKP UFBKCPAIC7HbkK6mbVoQP78e/nIvDEnRRlboIvKdruBJw6mDyS+Qf0F02L/C/gS9Wi iWU8nFdqHc+lQ== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 5/5] ui/ncurses: Implement F10-F12 for autoboot device control Date: Tue, 3 Jul 2018 16:34:47 +1000 Message-Id: <20180703063447.8338-6-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703063447.8338-1-jk@ozlabs.org> References: <20180703063447.8338-1-jk@ozlabs.org> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yewei@inspur.com MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add a few mappings to specify temporary autoboot settings: F10: Only autoboot from disk F11: Only autoboot from USB devices F12: Only autoboot from network These use the new code to prevent cancelling autoboot. Signed-off-by: Jeremy Kerr --- discover/device-handler.c | 25 +++++++++++++++++++++ ui/common/discover-client.c | 18 +++++++++++++++ ui/common/discover-client.h | 4 ++++ ui/ncurses/nc-cui-help.c | 9 ++++++++ ui/ncurses/nc-cui.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ ui/ncurses/nc-cui.h | 1 + 6 files changed, 112 insertions(+) diff --git a/discover/device-handler.c b/discover/device-handler.c index 3d75e57..0a93a06 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -916,13 +916,38 @@ static void set_default(struct device_handler *handler, default_timeout(handler); } +static char *autoboot_option_desc(void *ctx, const struct autoboot_option *opt) +{ + const char *type, *val; + + if (opt->boot_type == BOOT_DEVICE_TYPE) { + type = _("device type"); + val = device_type_display_name(opt->type); + } else if (opt->boot_type == BOOT_DEVICE_UUID) { + type = _("device UUID"); + val = opt->uuid; + } else { + type = _("unknown specifier"); + val = NULL; + } + + return talloc_asprintf(ctx, "%s = %s", type, val); +} + void device_handler_apply_temp_autoboot(struct device_handler *handler, struct autoboot_option *opt) { unsigned int i; + char *desc; handler->temp_autoboot = talloc_steal(handler, opt); + desc = autoboot_option_desc(handler, opt); + device_handler_status_info(handler, + _("Applying temporary autoboot override: %s"), + desc); + talloc_free(desc); + if (!handler->autoboot_enabled) return; diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c index 784154e..88d0b4e 100644 --- a/ui/common/discover-client.c +++ b/ui/common/discover-client.c @@ -453,3 +453,21 @@ int discover_client_send_plugin_install(struct discover_client *client, return pb_protocol_write_message(client->fd, message); } + +int discover_client_send_temp_autoboot(struct discover_client *client, + const struct autoboot_option *opt) +{ + struct pb_protocol_message *message; + int len; + + len = pb_protocol_temp_autoboot_len(opt); + + message = pb_protocol_create_message(client, + PB_PROTOCOL_ACTION_TEMP_AUTOBOOT, len); + if (!message) + return -1; + + pb_protocol_serialise_temp_autoboot(opt, message->payload, len); + + return pb_protocol_write_message(client->fd, message); +} diff --git a/ui/common/discover-client.h b/ui/common/discover-client.h index 7224691..2a2ea28 100644 --- a/ui/common/discover-client.h +++ b/ui/common/discover-client.h @@ -102,4 +102,8 @@ int discover_client_send_url(struct discover_client *client, char *url); int discover_client_send_plugin_install(struct discover_client *client, char *file); +/* send a temporary autoboot override */ +int discover_client_send_temp_autoboot(struct discover_client *client, + const struct autoboot_option *opt); + #endif diff --git a/ui/ncurses/nc-cui-help.c b/ui/ncurses/nc-cui-help.c index 7d97ba5..0e57b77 100644 --- a/ui/ncurses/nc-cui-help.c +++ b/ui/ncurses/nc-cui-help.c @@ -26,5 +26,14 @@ option.\n\ To retreive new boot options from a remote configuration file, select \ the 'Retrieve config from URL' option.\n\ \n\ +To restrict petitboot to only autobooting from a specific device type, the \ +following keys are available:\n\ +\n\ + F10: Only autoboot from disk\n\ + F11: Only autoboot from USB devices\n\ + F12: Only autoboot from network\n\ +\n\ +Unlike other keys, these do not cancel automatic boot.\n\ +\n\ To close the Petitboot interface, type X (exit).\n" ); diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 87540ca..87d2503 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -59,6 +59,27 @@ static struct pmenu *plugin_menu_init(struct cui *cui); static void cui_cancel_autoboot_on_exit(struct cui *cui); +static struct { + int key; + struct autoboot_option opt; +} autoboot_override_keys[] = { + { KEY_F(10), { + .boot_type = BOOT_DEVICE_TYPE, + .type = DEVICE_TYPE_DISK, + }, + }, + { KEY_F(11), { + .boot_type = BOOT_DEVICE_TYPE, + .type = DEVICE_TYPE_USB, + }, + }, + { KEY_F(12), { + .boot_type = BOOT_DEVICE_TYPE, + .type = DEVICE_TYPE_NETWORK, + }, + }, +}; + static bool lockdown_active(void) { #if defined(SIGNED_BOOT) && defined(HARD_LOCKDOWN) @@ -527,22 +548,50 @@ struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr) return old; } +static bool set_temp_autoboot_opt(struct cui *cui, struct autoboot_option *opt) +{ + cui->autoboot_opt = opt; + if (cui->client) + discover_client_send_temp_autoboot(cui->client, opt); + + return true; +} + static bool key_cancels_boot(int key) { + unsigned int i; + if (key == 0xc) return false; + for (i = 0; i < ARRAY_SIZE(autoboot_override_keys); i++) + if (key == autoboot_override_keys[i].key) + return false; + return true; } static bool process_global_keys(struct cui *cui, int key) { + unsigned int i; + switch (key) { case 0xc: if (cui->current && cui->current->main_ncw) wrefresh(curscr); return true; } + + /* check for autoboot override keys */ + for (i = 0; i < ARRAY_SIZE(autoboot_override_keys); i++) { + if (key != autoboot_override_keys[i].key) + continue; + + pb_log("Sending temporary autoboot override\n"); + set_temp_autoboot_opt(cui, &autoboot_override_keys[i].opt); + return true; + } + return false; } @@ -1428,6 +1477,12 @@ static int cui_server_wait(void *arg) pb_log("Aborting default boot on pb-discover connect\n"); discover_client_cancel_default(cui->client); } + + if (cui->autoboot_opt) { + pb_log("Sending autoboot override on pb-discover connect\n"); + discover_client_send_temp_autoboot(cui->client, + cui->autoboot_opt); + } } return 0; diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h index b310f4a..4997f4b 100644 --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -52,6 +52,7 @@ struct cui_opt_data { struct cui { enum pb_nc_sig c_sig; bool has_input; + struct autoboot_option *autoboot_opt; sig_atomic_t abort; sig_atomic_t resize; struct nc_scr *current;