grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: Colin Watson <cjwatson@ubuntu.com>,
	 The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [Xen-devel] [PATCH 1/4] Add an option to exclude devices from search results.
Date: Fri, 13 Dec 2013 13:27:37 +0100	[thread overview]
Message-ID: <52AAFD39.6000501@gmail.com> (raw)
In-Reply-To: <20131212153706.GB1431@riva.ucam.org>

[-- Attachment #1: Type: text/plain, Size: 4585 bytes --]

On 12.12.2013 16:37, Colin Watson wrote:
> * grub-core/commands/search.c (struct search_ctx): Add excludes and
> nexcludes.
> (iterate_device): Ignore devices listed in ctx->excludes.
> (FUNC_NAME): Accept excludes and nexcludes parameters.
> (grub_cmd_do_search): Pass empty excludes.
> * grub-core/commands/search_wrap.c (options): Add --exclude option.
> (grub_cmd_search): Handle --exclude.
> * include/grub/search.h (grub_search_fs_file): Update prototype.
> (grub_search_fs_uuid): Likewise.
> (grub_search_label): Likewise.
> * docs/grub.texi (search): Document --exclude.
> ---
>  ChangeLog                        | 16 ++++++++++++++++
>  docs/grub.texi                   |  7 ++++++-
>  grub-core/commands/search.c      | 15 +++++++++++++--
>  grub-core/commands/search_wrap.c | 27 ++++++++++++++++++++++-----
>  include/grub/search.h            |  9 ++++++---
>  5 files changed, 63 insertions(+), 11 deletions(-)
> 
> diff --git a/ChangeLog b/ChangeLog
> index 9cec63f..766fe4b 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,3 +1,19 @@
> +2013-12-12  Colin Watson  <cjwatson@ubuntu.com>
> +
> +	Add an option to exclude devices from search results.
> +
> +	* grub-core/commands/search.c (struct search_ctx): Add excludes and
> +	nexcludes.
> +	(iterate_device): Ignore devices listed in ctx->excludes.
> +	(FUNC_NAME): Accept excludes and nexcludes parameters.
> +	(grub_cmd_do_search): Pass empty excludes.
> +	* grub-core/commands/search_wrap.c (options): Add --exclude option.
> +	(grub_cmd_search): Handle --exclude.
> +	* include/grub/search.h (grub_search_fs_file): Update prototype.
> +	(grub_search_fs_uuid): Likewise.
> +	(grub_search_label): Likewise.
> +	* docs/grub.texi (search): Document --exclude.
> +
>  2013-12-11  Vladimir Serbinenko  <phcoder@gmail.com>
>  
>  	* grub-core/normal/charset.c: Fix premature line wrap and crash.
> diff --git a/docs/grub.texi b/docs/grub.texi
> index 91fa1de..4c53665 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -4731,7 +4731,8 @@ unbootable. @xref{Using digital signatures}, for more information.
>  
>  @deffn Command search @
>   [@option{--file}|@option{--label}|@option{--fs-uuid}] @
> - [@option{--set} [var]] [@option{--no-floppy}] name
> + [@option{--set} [var]] [@option{--no-floppy}] @
> + [@option{--exclude} @var{name} ...] name
>  Search devices by file (@option{-f}, @option{--file}), filesystem label
>  (@option{-l}, @option{--label}), or filesystem UUID (@option{-u},
>  @option{--fs-uuid}).
> @@ -4743,6 +4744,10 @@ value of environment variable @var{var}.  The default variable is
>  The @option{--no-floppy} option prevents searching floppy devices, which can
>  be slow.
>  
> +The @option{--exclude} option excludes any matches of the given GRUB device
> +name.  For example, this may be used to search for any file named
> +@file{/boot/grub/grub.cfg} other than the one in a memdisk.
> +
>  The @samp{search.file}, @samp{search.fs_label}, and @samp{search.fs_uuid}
>  commands are aliases for @samp{search --file}, @samp{search --label}, and
>  @samp{search --fs-uuid} respectively.
> diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c
> index 16143a3..03cfea1 100644
> --- a/grub-core/commands/search.c
> +++ b/grub-core/commands/search.c
> @@ -50,6 +50,8 @@ struct search_ctx
>    int no_floppy;
>    char **hints;
>    unsigned nhints;
> +  char **excludes;
> +  unsigned nexcludes;
>    int count;
>    int is_cache;
>  };
> @@ -59,8 +61,15 @@ static int
>  iterate_device (const char *name, void *data)
>  {
>    struct search_ctx *ctx = data;
> +  unsigned i;
>    int found = 0;
>  
> +  for (i = 0; i < ctx->nexcludes; i++)
> +    {
> +      if (grub_strcmp (name, ctx->excludes[i]) == 0)
> +	return 0;
> +    }
> +
This makes behaviour strongly dependent on the unstable names. In case
of memdisk it's not a problem because its name is stable but outside
this specific use it's easily misusable command. E.g.
search --exclude=hd0,1
would be heavily dependent on disk naming and won't work because this
check considers hd0,1 and hd0,msdos1 as distict. The only way to sanely
use this interface is to do sth like
search --exclude $boot
to find next configfile, a bit like include_next directive but it
creates a problem that the same disk may have several names. E.g. LVM
have names base on name and UUID.
This doesn't handle some configs like 2 autodetecting scripts including
each other.
This is complex problem and I'm unsure how to solve it.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 291 bytes --]

  reply	other threads:[~2013-12-13 12:27 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-12 15:36 [PATCH 0/4] Turn-key PV-GRUB2 installation Colin Watson
2013-12-12 15:37 ` [PATCH 1/4] Add an option to exclude devices from search results Colin Watson
2013-12-13 12:27   ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2013-12-13 13:18     ` [Xen-devel] " Colin Watson
2013-12-13 15:40       ` [PATCH] add --boot-directory option to grub-mkstandalone Andrey Borzenkov
2013-12-20 12:16         ` Colin Watson
2013-12-21 10:29           ` Andrey Borzenkov
2013-12-21 10:37             ` Andrey Borzenkov
2013-12-22 17:20     ` [Xen-devel] [PATCH 1/4] Add an option to exclude devices from search results Jordan Uggla
2013-12-12 15:37 ` [PATCH 2/4] Accept environment variables on the command line for Xen Colin Watson
2013-12-12 15:48   ` Andrey Borzenkov
2013-12-12 16:11     ` Colin Watson
2013-12-12 16:15       ` Vladimir 'phcoder' Serbinenko
2013-12-12 16:13     ` Vladimir 'phcoder' Serbinenko
2013-12-12 17:12       ` Andrey Borzenkov
2013-12-12 17:58         ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-12 19:12           ` Colin Watson
2013-12-12 19:50             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-12 15:37 ` [PATCH 3/4] Build grub.xen Colin Watson
2013-12-12 16:24   ` Vladimir 'phcoder' Serbinenko
2013-12-12 16:39     ` Colin Watson
2013-12-12 16:45       ` Vladimir 'phcoder' Serbinenko
2013-12-12 16:49         ` Fwd: " Vladimir 'phcoder' Serbinenko
2013-12-12 17:36         ` Colin Watson
2013-12-12 17:41           ` Andrey Borzenkov
2013-12-12 18:08             ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-13 11:56   ` Colin Watson
2013-12-13 12:19     ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-12-12 15:37 ` [PATCH 4/4] Improve installation on Xen Colin Watson
2013-12-12 16:23   ` [Xen-devel] " Vladimir 'phcoder' Serbinenko
2013-12-13 11:58     ` Colin Watson
2013-12-16 11:42 ` [Xen-devel] [PATCH 0/4] Turn-key PV-GRUB2 installation Ian Campbell
2013-12-16 12:05   ` Samuel Thibault

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=52AAFD39.6000501@gmail.com \
    --to=phcoder@gmail.com \
    --cc=cjwatson@ubuntu.com \
    --cc=grub-devel@gnu.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;
as well as URLs for NNTP newsgroup(s).