grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 5/9] util/grub-editenv: wire unset_variables to optional fs_envblk
  2025-09-15  9:08 [PATCH v2 0/9] Add support for external environment block on Btrfs Michael Chang via Grub-devel
@ 2025-09-15  9:08 ` Michael Chang via Grub-devel
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Chang via Grub-devel @ 2025-09-15  9:08 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Michael Chang, Neal Gompa, Marta Lewandowska

This patch updates unset_variables so that removals are also applied to
the external environment block when it is present. The code opens the
external block, deletes the same named keys there, and then writes the
external block back using fs_envblk_write. The file based envblk is
still updated and written as before.

Signed-off-by: Michael Chang <mchang@suse.com>
---
 util/grub-editenv.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/util/grub-editenv.c b/util/grub-editenv.c
index d47adeb5e..5fe240c42 100644
--- a/util/grub-editenv.c
+++ b/util/grub-editenv.c
@@ -476,18 +476,32 @@ static void
 unset_variables (const char *name, int argc, char *argv[])
 {
   grub_envblk_t envblk;
+  grub_envblk_t envblk_fs = NULL;
 
   envblk = open_envblk_file (name);
+
+  if (fs_envblk != NULL)
+    envblk_fs = fs_envblk->ops->open (envblk);
+
   while (argc)
     {
       grub_envblk_delete (envblk, argv[0]);
 
+      if (envblk_fs != NULL)
+	grub_envblk_delete (envblk_fs, argv[0]);
+
       argc--;
       argv++;
     }
 
   write_envblk (name, envblk);
   grub_envblk_close (envblk);
+
+  if (envblk_fs != NULL)
+    {
+      fs_envblk->ops->write (envblk_fs);
+      grub_envblk_close (envblk_fs);
+    }
 }
 
 static bool
-- 
2.51.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 4/9] util/grub-editenv: wire set_variables to optional fs_envblk
       [not found] <mailman.4164.1757927381.1199.grub-devel@gnu.org>
@ 2025-09-17 17:08 ` Avnish Chouhan
  2025-09-24  2:29   ` Michael Chang via Grub-devel
  2025-09-17 17:23 ` [PATCH v2 5/9] util/grub-editenv: wire unset_variables " Avnish Chouhan
  2025-09-17 17:27 ` [PATCH v2 6/9] util/grub-editenv: wire list_variables " Avnish Chouhan
  2 siblings, 1 reply; 5+ messages in thread
From: Avnish Chouhan @ 2025-09-17 17:08 UTC (permalink / raw)
  To: mchang; +Cc: grub-devel, ngompa13, mlewando, Daniel Kiper

On 2025-09-15 14:39, grub-devel-request@gnu.org wrote:
> Message: 1
> Date: Mon, 15 Sep 2025 17:08:43 +0800
> From: Michael Chang <mchang@suse.com>
> To: The development of GNU GRUB <grub-devel@gnu.org>
> Cc: Neal Gompa <ngompa13@gmail.com>,	Marta Lewandowska
> 	<mlewando@redhat.com>
> Subject: [PATCH v2 4/9] util/grub-editenv: wire set_variables to
> 	optional fs_envblk
> Message-ID: <20250915090848.131937-5-mchang@suse.com>
> 
> This patch changes set_variables so that it can use an external
> environment block when one is present. The variable next_entry is
> written into the external block, env_block is treated as read only, and
> all other variables are written into the normal file based envblk.
> 
> A cleanup step is added to handle cases where GRUB at runtime writes
> variables into the external block because file based updates are not
> safe on a copy on write filesystem such as Btrfs. For example, the
> savedefault command can update saved_entry, and on Btrfs GRUB will 
> place
> that update in the external block instead of the file envblk. If an
> older copy remains in the external block, it would override the newer
> value from the file envblk when GRUB first loads the file and then
> applies the external block on top of it. To avoid this, whenever a
> variable is updated in the file envblk, any same named key in the
> external block is deleted.
> 
> Signed-off-by: Michael Chang <mchang@suse.com>
> ---
>  util/grub-editenv.c | 55 +++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 53 insertions(+), 2 deletions(-)
> 
> diff --git a/util/grub-editenv.c b/util/grub-editenv.c
> index 26a81d2d0..d47adeb5e 100644
> --- a/util/grub-editenv.c
> +++ b/util/grub-editenv.c
> @@ -394,12 +394,33 @@ fs_envblk_write (grub_envblk_t envblk)
>    fclose (fp);
>  }
> 
> +struct var_lookup_ctx {
> +  const char *varname;
> +  bool found;
> +};
> +
> +static int
> +var_lookup_iter (const char *varname, const char *value __attribute__
> ((unused)), void *hook_data)
> +{
> +  struct var_lookup_ctx *ctx = (struct var_lookup_ctx *)hook_data;

Hi Michael,

Missing a space before "hook_data;"

Thank you!

Regards,
Avnish Chouhan

****

Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 5/9] util/grub-editenv: wire unset_variables to optional fs_envblk
       [not found] <mailman.4164.1757927381.1199.grub-devel@gnu.org>
  2025-09-17 17:08 ` [PATCH v2 4/9] util/grub-editenv: wire set_variables to optional fs_envblk Avnish Chouhan
@ 2025-09-17 17:23 ` Avnish Chouhan
  2025-09-17 17:27 ` [PATCH v2 6/9] util/grub-editenv: wire list_variables " Avnish Chouhan
  2 siblings, 0 replies; 5+ messages in thread
From: Avnish Chouhan @ 2025-09-17 17:23 UTC (permalink / raw)
  To: mchang; +Cc: grub-devel, Daniel Kiper, ngompa13, mlewando

On 2025-09-15 14:39, grub-devel-request@gnu.org wrote:
> Message: 3
> Date: Mon, 15 Sep 2025 17:08:44 +0800
> From: Michael Chang <mchang@suse.com>
> To: The development of GNU GRUB <grub-devel@gnu.org>
> Cc: Neal Gompa <ngompa13@gmail.com>,	Marta Lewandowska
> 	<mlewando@redhat.com>
> Subject: [PATCH v2 5/9] util/grub-editenv: wire unset_variables to
> 	optional fs_envblk
> Message-ID: <20250915090848.131937-6-mchang@suse.com>
> 
> This patch updates unset_variables so that removals are also applied to
> the external environment block when it is present. The code opens the
> external block, deletes the same named keys there, and then writes the
> external block back using fs_envblk_write. The file based envblk is
> still updated and written as before.
> 
> Signed-off-by: Michael Chang <mchang@suse.com>

Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 6/9] util/grub-editenv: wire list_variables to optional fs_envblk
       [not found] <mailman.4164.1757927381.1199.grub-devel@gnu.org>
  2025-09-17 17:08 ` [PATCH v2 4/9] util/grub-editenv: wire set_variables to optional fs_envblk Avnish Chouhan
  2025-09-17 17:23 ` [PATCH v2 5/9] util/grub-editenv: wire unset_variables " Avnish Chouhan
@ 2025-09-17 17:27 ` Avnish Chouhan
  2 siblings, 0 replies; 5+ messages in thread
From: Avnish Chouhan @ 2025-09-17 17:27 UTC (permalink / raw)
  To: mchang; +Cc: grub-devel, Daniel Kiper, ngompa13, mlewando

On 2025-09-15 14:39, grub-devel-request@gnu.org wrote:
> Message: 2
> Date: Mon, 15 Sep 2025 17:08:45 +0800
> From: Michael Chang <mchang@suse.com>
> To: The development of GNU GRUB <grub-devel@gnu.org>
> Cc: Neal Gompa <ngompa13@gmail.com>,	Marta Lewandowska
> 	<mlewando@redhat.com>
> Subject: [PATCH v2 6/9] util/grub-editenv: wire list_variables to
> 	optional fs_envblk
> Message-ID: <20250915090848.131937-7-mchang@suse.com>
> 
> This patch updates list_variables so that it also prints entries from
> the external environment block when one is present. The function first
> lists all variables from the file based envblk, then iterates over the
> external envblk and prints those as well.
> 
> The output format remains the same as before. The change makes it
> possible to inspect variables regardless of whether they are stored in
> the file envblk or in the reserved block.
> 
> Signed-off-by: Michael Chang <mchang@suse.com>

Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 4/9] util/grub-editenv: wire set_variables to optional fs_envblk
  2025-09-17 17:08 ` [PATCH v2 4/9] util/grub-editenv: wire set_variables to optional fs_envblk Avnish Chouhan
@ 2025-09-24  2:29   ` Michael Chang via Grub-devel
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Chang via Grub-devel @ 2025-09-24  2:29 UTC (permalink / raw)
  To: Avnish Chouhan
  Cc: Michael Chang, grub-devel, ngompa13, mlewando, Daniel Kiper

On Wed, Sep 17, 2025 at 10:38:17PM +0530, Avnish Chouhan wrote:
> On 2025-09-15 14:39, grub-devel-request@gnu.org wrote:
> > Message: 1
> > Date: Mon, 15 Sep 2025 17:08:43 +0800
> > From: Michael Chang <mchang@suse.com>
> > To: The development of GNU GRUB <grub-devel@gnu.org>
> > Cc: Neal Gompa <ngompa13@gmail.com>,	Marta Lewandowska
> > 	<mlewando@redhat.com>
> > Subject: [PATCH v2 4/9] util/grub-editenv: wire set_variables to
> > 	optional fs_envblk
> > Message-ID: <20250915090848.131937-5-mchang@suse.com>
> > 
> > This patch changes set_variables so that it can use an external
> > environment block when one is present. The variable next_entry is
> > written into the external block, env_block is treated as read only, and
> > all other variables are written into the normal file based envblk.
> > 
> > A cleanup step is added to handle cases where GRUB at runtime writes
> > variables into the external block because file based updates are not
> > safe on a copy on write filesystem such as Btrfs. For example, the
> > savedefault command can update saved_entry, and on Btrfs GRUB will place
> > that update in the external block instead of the file envblk. If an
> > older copy remains in the external block, it would override the newer
> > value from the file envblk when GRUB first loads the file and then
> > applies the external block on top of it. To avoid this, whenever a
> > variable is updated in the file envblk, any same named key in the
> > external block is deleted.
> > 
> > Signed-off-by: Michael Chang <mchang@suse.com>
> > ---
> >  util/grub-editenv.c | 55 +++++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 53 insertions(+), 2 deletions(-)
> > 
> > diff --git a/util/grub-editenv.c b/util/grub-editenv.c
> > index 26a81d2d0..d47adeb5e 100644
> > --- a/util/grub-editenv.c
> > +++ b/util/grub-editenv.c
> > @@ -394,12 +394,33 @@ fs_envblk_write (grub_envblk_t envblk)
> >    fclose (fp);
> >  }
> > 
> > +struct var_lookup_ctx {
> > +  const char *varname;
> > +  bool found;
> > +};
> > +
> > +static int
> > +var_lookup_iter (const char *varname, const char *value __attribute__
> > ((unused)), void *hook_data)
> > +{
> > +  struct var_lookup_ctx *ctx = (struct var_lookup_ctx *)hook_data;
> 
> Hi Michael,
> 
> Missing a space before "hook_data;"

OK. I'll put a space the cast operator.

Thanks,
Michael

> 
> Thank you!
> 
> Regards,
> Avnish Chouhan
> 
> ****
> 
> Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
> 

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-24  2:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.4164.1757927381.1199.grub-devel@gnu.org>
2025-09-17 17:08 ` [PATCH v2 4/9] util/grub-editenv: wire set_variables to optional fs_envblk Avnish Chouhan
2025-09-24  2:29   ` Michael Chang via Grub-devel
2025-09-17 17:23 ` [PATCH v2 5/9] util/grub-editenv: wire unset_variables " Avnish Chouhan
2025-09-17 17:27 ` [PATCH v2 6/9] util/grub-editenv: wire list_variables " Avnish Chouhan
2025-09-15  9:08 [PATCH v2 0/9] Add support for external environment block on Btrfs Michael Chang via Grub-devel
2025-09-15  9:08 ` [PATCH v2 5/9] util/grub-editenv: wire unset_variables to optional fs_envblk Michael Chang via Grub-devel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).