From patchwork Sat May 26 06:06:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 920934 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 40tCLn3qytz9s16 for ; Sat, 26 May 2018 16:06:57 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40tCLn2R70zDqnw for ; Sat, 26 May 2018 16:06:57 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=thuth@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40tCL81k88zDr3M for ; Sat, 26 May 2018 16:06:24 +1000 (AEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDF3411DB0A; Sat, 26 May 2018 06:06:21 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id E172B210C6C0; Sat, 26 May 2018 06:06:20 +0000 (UTC) From: Thomas Huth To: slof@lists.ozlabs.org Date: Sat, 26 May 2018 08:06:08 +0200 Message-Id: <1527314768-4797-9-git-send-email-thuth@redhat.com> In-Reply-To: <1527314768-4797-1-git-send-email-thuth@redhat.com> References: <1527314768-4797-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 26 May 2018 06:06:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Sat, 26 May 2018 06:06:21 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Subject: [SLOF] [PATCH v3 8/8] libnet: Support UUID-based pxelinux.cfg file names X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" Retrieve the UUID from the device tree and pass it to the pxelinux.cfg function, so that we can look there for UUID-based file names, too. Signed-off-by: Thomas Huth --- lib/libnet/netload.c | 18 +++++++++++++++++- lib/libnet/pxelinux.c | 16 +++++++++++++--- lib/libnet/pxelinux.h | 2 +- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/lib/libnet/netload.c b/lib/libnet/netload.c index 4c7ac37..4b95eab 100644 --- a/lib/libnet/netload.c +++ b/lib/libnet/netload.c @@ -427,6 +427,21 @@ static int tftp_load(filename_ip_t *fnip, void *buffer, int len, return rc; } +static const char *get_uuid(void) +{ + char *addr; + int len; + + if (SLOF_get_property("/", "system-id", &addr, &len)) + return NULL; + if (len < 37) { /* This should never happen... */ + puts("Warning: UUID property is too short."); + return NULL; + } + + return addr; +} + #define CFG_BUF_SIZE 2048 #define MAX_PL_CFG_ENTRIES 16 static int net_pxelinux_load(filename_ip_t *fnip, char *loadbase, @@ -442,7 +457,8 @@ static int net_pxelinux_load(filename_ip_t *fnip, char *loadbase, return -1; } - rc = pxelinux_load_parse_cfg(fnip, mac, retries, cfgbuf, CFG_BUF_SIZE, + rc = pxelinux_load_parse_cfg(fnip, mac, get_uuid(), retries, + cfgbuf, CFG_BUF_SIZE, entries, MAX_PL_CFG_ENTRIES, &def); if (rc < 0) goto out_free; diff --git a/lib/libnet/pxelinux.c b/lib/libnet/pxelinux.c index 91b3c13..718ceca 100644 --- a/lib/libnet/pxelinux.c +++ b/lib/libnet/pxelinux.c @@ -51,7 +51,7 @@ static int pxelinux_tftp_load(filename_ip_t *fnip, void *buffer, int len, * Try to load a pxelinux.cfg file by probing the possible file names. * Note that this function will overwrite filename_ip_t->filename. */ -static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, +static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid, int retries, char *cfgbuf, int cfgbufsize) { int rc, idx; @@ -101,6 +101,15 @@ static int pxelinux_load_cfg(filename_ip_t *fn_ip, uint8_t *mac, } } + /* Try to load config file with name based on the VM UUID */ + if (uuid) { + strcpy(baseptr, uuid); + rc = pxelinux_tftp_load(fn_ip, cfgbuf, cfgbufsize - 1, retries); + if (rc > 0) { + return rc; + } + } + /* Look for config file with MAC address in its name */ sprintf(baseptr, "01-%02x-%02x-%02x-%02x-%02x-%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -215,6 +224,7 @@ nextline: * Try to load and parse a pxelinux-style configuration file. * @param fn_ip must contain server and client IP information * @param mac MAC address which should be used for probing + * @param uuid UUID which should be used for probing (can be NULL) * @param retries Amount of TFTP retries before giving up * @param cfgbuf Pointer to the buffer where config file should be loaded * @param cfgsize Size of the cfgbuf buffer @@ -223,14 +233,14 @@ nextline: * @param def_ent Used to return the index of the default entry * @return Number of valid entries */ -int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac, +int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid, int retries, char *cfgbuf, int cfgsize, struct pl_cfg_entry *entries, int max_entries, int *def_ent) { int rc; - rc = pxelinux_load_cfg(fn_ip, mac, retries, cfgbuf, cfgsize); + rc = pxelinux_load_cfg(fn_ip, mac, uuid, retries, cfgbuf, cfgsize); if (rc < 0) return rc; diff --git a/lib/libnet/pxelinux.h b/lib/libnet/pxelinux.h index 98b3925..0514d0d 100644 --- a/lib/libnet/pxelinux.h +++ b/lib/libnet/pxelinux.h @@ -25,7 +25,7 @@ struct pl_cfg_entry { int pxelinux_parse_cfg(char *cfg, int cfgsize, struct pl_cfg_entry *entries, int max_entries, int *def_ent); -int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac, +int pxelinux_load_parse_cfg(filename_ip_t *fn_ip, uint8_t *mac, const char *uuid, int retries, char *cfgbuf, int cfgsize, struct pl_cfg_entry *entries, int max_entries, int *def_ent);