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;