From: Roland Hieber <rhi@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: oss-tools@pengutronix.de
Subject: Re: [OSS-Tools] [PATCH v2] barebox-state: have the --set option to avoid writes if possible
Date: Tue, 16 Mar 2021 15:24:37 +0100 [thread overview]
Message-ID: <20210316142437.v6kfydi43d2gnix3@pengutronix.de> (raw)
In-Reply-To: <20201113190856.3197-1-a.fatoum@pengutronix.de>
On Fri, Nov 13, 2020 at 08:08:56PM +0100, Ahmad Fatoum wrote:
> barebox-state --set always dirties the state when successful. Users
> seeking to conserve write cycles thus have to --get the variable in
> question first to check whether to write it. Make life of such users
> easier by having barebox-state support this out-of-the-box.
>
> This allows users to fire and forget execute barebox-state.
>
> This arguably should have been the behavior from the beginning,
> the state implementation shared by barebox and dt-utils already
> marks the state dirty if buckets appear corrupted on probe, so
> there is no extra benefit in always executing the write.
>
> The comparison to determine whether the state should be dirtied
> does an extra allocation in interest of clarity.
> This overhead is deemed negligible compared to I/O and it makes
> the code easier to follow.
>
> Suggested-by: Jan Lübbe <jlu@pengutronix.de>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> v1 -> v2:
> - incorporate Jan's (off-list) suggestion to just change --set
> behavior. state implementation already dirties state if a
> bucket is corrupt, so there is really no valid use case for
> not conserving writes by default.
> ---
> src/barebox-state.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
Thanks, applied.
- Roland
>
> diff --git a/src/barebox-state.c b/src/barebox-state.c
> index cd56ce7192c3..7b5c0dae00dd 100644
> --- a/src/barebox-state.c
> +++ b/src/barebox-state.c
> @@ -283,6 +283,7 @@ static int state_set_var(struct state *state, const char *var, const char *val)
> {
> struct state_variable *sv;
> struct variable_str_type *vtype;
> + char *oldval;
> int ret;
>
> sv = state_find_var(state, var);
> @@ -296,6 +297,14 @@ static int state_set_var(struct state *state, const char *var, const char *val)
> if (!vtype->set)
> return -EPERM;
>
> + oldval = vtype->get(sv);
> + if (!IS_ERR(oldval)) {
> + bool equal = strcmp(oldval, val) == 0;
> + free(oldval);
> + if (equal)
> + return 0;
> + }
> +
> ret = vtype->set(sv, val);
> if (ret)
> return ret;
> --
> 2.28.0
>
>
> _______________________________________________
> OSS-Tools mailing list
> OSS-Tools@pengutronix.de
--
Roland Hieber, Pengutronix e.K. | r.hieber@pengutronix.de |
Steuerwalder Str. 21 | https://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
OSS-Tools mailing list
OSS-Tools@pengutronix.de
prev parent reply other threads:[~2021-03-16 14:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-13 19:08 Ahmad Fatoum
2021-03-16 14:24 ` Roland Hieber [this message]
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=20210316142437.v6kfydi43d2gnix3@pengutronix.de \
--to=rhi@pengutronix.de \
--cc=a.fatoum@pengutronix.de \
--cc=oss-tools@pengutronix.de \
/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