mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Daniel Glöckner" <dg@emlix.com>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH v3 12/14] globalvar: Add helper for deprecated variable names
Date: Mon, 15 Jun 2020 19:20:45 +0200	[thread overview]
Message-ID: <396a023759153b4e9fd04e1ac64601356faff653.1592241105.git.dg@emlix.com> (raw)
In-Reply-To: <cover.1592241105.git.dg@emlix.com>
In-Reply-To: <cover.1592241105.git.dg@emlix.com>

From: Sascha Hauer <s.hauer@pengutronix.de>

When globalvars are renamed across releases it's not nice when variables
in the persistent environment loose their meaning. This adds a helper
function which adds an alias for the old names. When the persistent
variables still use the old names then their values are automatically
written to variables with the new names.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/globalvar.c  | 41 +++++++++++++++++++++++++++++++++++++++--
 include/globalvar.h |  5 +++++
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index c87f2c933..5e91cc815 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -293,6 +293,40 @@ int nvvar_remove(const char *name)
 	return ret;
 }
 
+struct globalvar_deprecated {
+	char *newname;
+	char *oldname;
+	struct list_head list;
+};
+
+static LIST_HEAD(globalvar_deprecated_list);
+
+void globalvar_alias_deprecated(const char *oldname, const char *newname)
+{
+	struct globalvar_deprecated *gd;
+
+	gd = xzalloc(sizeof(*gd));
+	gd->newname = xstrdup(newname);
+	gd->oldname = xstrdup(oldname);
+	list_add_tail(&gd->list, &globalvar_deprecated_list);
+}
+
+static const char *globalvar_new_name(const char *oldname)
+{
+	struct globalvar_deprecated *gd;
+
+	list_for_each_entry(gd, &globalvar_deprecated_list, list) {
+		if (!strcmp(oldname, gd->oldname)) {
+			pr_warn("nv.%s is deprecated, converting to nv.%s\n", oldname,
+				gd->newname);
+			nv_dirty = 1;
+			return gd->newname;
+		}
+	}
+
+	return oldname;
+}
+
 int nvvar_load(void)
 {
 	char *val;
@@ -308,6 +342,8 @@ int nvvar_load(void)
 		return -ENOENT;
 
 	while ((d = readdir(dir))) {
+		const char *n;
+
 		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
 			continue;
 
@@ -316,10 +352,11 @@ int nvvar_load(void)
 		pr_debug("%s: Setting \"%s\" to \"%s\"\n",
 				__func__, d->d_name, val);
 
-		ret = __nvvar_add(d->d_name, val);
+		n = globalvar_new_name(d->d_name);
+		ret = __nvvar_add(n, val);
 		if (ret)
 			pr_err("failed to create nv variable %s: %s\n",
-					d->d_name, strerror(-ret));
+					n, strerror(-ret));
 	}
 
 	closedir(dir);
diff --git a/include/globalvar.h b/include/globalvar.h
index fc85e93e1..db229e239 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -33,6 +33,7 @@ int nvvar_remove(const char *name);
 void globalvar_print(void);
 
 void dev_param_init_from_nv(struct device_d *dev, const char *name);
+void globalvar_alias_deprecated(const char *newname, const char *oldname);
 
 #else
 static inline int globalvar_add_simple(const char *name, const char *value)
@@ -114,6 +115,10 @@ static inline void dev_param_init_from_nv(struct device_d *dev, const char *name
 {
 }
 
+static inline void globalvar_alias_deprecated(const char *newname, const char *oldname)
+{
+}
+
 #endif
 
 void nv_var_set_clean(void);
-- 
2.17.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-06-15 17:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15 17:20 [PATCH v3 00/14] Slices and fastboot over UDP Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 01/14] Introduce slices Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 02/14] Introduce idle slice Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 03/14] net: Add a slice to struct eth_device Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 04/14] net: mdiobus: Add slice Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 05/14] usb: Add a slice to usb host controllers Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 06/14] usbnet: Add slice Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 07/14] net: Call net_poll() in a poller Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 08/14] net: reply to ping requests Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 09/14] usbnet: Be more friendly in the receive path Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 10/14] poller: Allow to run pollers inside of pollers Daniel Glöckner
2020-06-17  7:00   ` Sascha Hauer
2020-06-15 17:20 ` [PATCH v3 11/14] defconfigs: update renamed fastboot options Daniel Glöckner
2020-06-15 17:20 ` Daniel Glöckner [this message]
2020-06-15 17:20 ` [PATCH v3 13/14] fastboot: rename usbgadget.fastboot_* variables to fastboot.* Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 14/14] fastboot net: implement fastboot over UDP Daniel Glöckner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=396a023759153b4e9fd04e1ac64601356faff653.1592241105.git.dg@emlix.com \
    --to=dg@emlix.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox