From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1VumhU-0005Pb-2G for mharc-grub-devel@gnu.org; Sun, 22 Dec 2013 12:20:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51197) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VumhR-0005Lt-AX for grub-devel@gnu.org; Sun, 22 Dec 2013 12:20:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VumhQ-0005DZ-26 for grub-devel@gnu.org; Sun, 22 Dec 2013 12:20:21 -0500 Received: from mail-pb0-x22a.google.com ([2607:f8b0:400e:c01::22a]:63903) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VumhP-0005DM-NS for grub-devel@gnu.org; Sun, 22 Dec 2013 12:20:19 -0500 Received: by mail-pb0-f42.google.com with SMTP id uo5so4535786pbc.1 for ; Sun, 22 Dec 2013 09:20:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=3Knfmqzbh/CFUBRPk9UvnIGEM0j+UOnmkd05kUTulVk=; b=S5xcjMILqQFuuYZhTTLq0uS/Eowk/rdeDn0v7pB6XprWgrb1etCQLq8WAlByfGoZ+l IFZ8h4SGXCbw8nflMnP7bAjBAOvQqIIStaOqI0RLqXSxg6otdswj9ox/JyUHgnGuY5lG jChcqfvlRJdVWRXIYnYVMaeKIj47axguO0Z0EKV2D6B1d4NxSuvfTgbeLqIxPPHWglm0 scx/BZ0no1m4ugnY79khMewedb7jvDULBPBPVBzi38H0CnUZRJtKGOLicuZV8afP9vQI Ravm1wKsnN4/1rsYzWbC72JtRSrQ1kmN8z7l+sXPIW5W5dGjvUvllUKzSv5H3Tm6XfVa 9DlQ== MIME-Version: 1.0 X-Received: by 10.68.194.71 with SMTP id hu7mr21231177pbc.68.1387732818370; Sun, 22 Dec 2013 09:20:18 -0800 (PST) Received: by 10.68.129.8 with HTTP; Sun, 22 Dec 2013 09:20:18 -0800 (PST) In-Reply-To: <52AAFD39.6000501@gmail.com> References: <20131212153643.GA1431@riva.ucam.org> <20131212153706.GB1431@riva.ucam.org> <52AAFD39.6000501@gmail.com> Date: Sun, 22 Dec 2013 11:20:18 -0600 Message-ID: Subject: Re: [Xen-devel] [PATCH 1/4] Add an option to exclude devices from search results. From: Jordan Uggla To: The development of GNU GRUB Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c01::22a Cc: Colin Watson X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Dec 2013 17:20:22 -0000 On Dec 13, 2013 6:28 AM, "Vladimir '=CF=86-coder/phcoder' Serbinenko" wrote: > > 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. > > --- > > =C2=A0ChangeLog =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0| 16 ++++++++++++++++ > > =C2=A0docs/grub.texi =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 | =C2=A07 ++++++- > > =C2=A0grub-core/commands/search.c =C2=A0 =C2=A0 =C2=A0| 15 ++++++++++++= +-- > > =C2=A0grub-core/commands/search_wrap.c | 27 ++++++++++++++++++++++----- > > =C2=A0include/grub/search.h =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| = =C2=A09 ++++++--- > > =C2=A05 files changed, insertions(+), 11 deletions(-) > > > > diff --git a/ChangeLog b/ChangeLog > > index 9cec63f..766fe4b 100644 > > --- a/ChangeLog > > +++ b/ChangeLog > > @@ -1,3 +1,19 @@ > > +2013-12-12 =C2=A0Colin Watson =C2=A0 > > + > > + =C2=A0 =C2=A0 Add an option to exclude devices from search results. > > + > > + =C2=A0 =C2=A0 * grub-core/commands/search.c (struct search_ctx): Add = excludes and > > + =C2=A0 =C2=A0 nexcludes. > > + =C2=A0 =C2=A0 (iterate_device): Ignore devices listed in ctx->exclude= s. > > + =C2=A0 =C2=A0 (FUNC_NAME): Accept excludes and nexcludes parameters. > > + =C2=A0 =C2=A0 (grub_cmd_do_search): Pass empty excludes. > > + =C2=A0 =C2=A0 * grub-core/commands/search_wrap.c (options): Add --exc= lude option. > > + =C2=A0 =C2=A0 (grub_cmd_search): Handle --exclude. > > + =C2=A0 =C2=A0 * include/grub/search.h (grub_search_fs_file): Update p= rototype. > > + =C2=A0 =C2=A0 (grub_search_fs_uuid): Likewise. > > + =C2=A0 =C2=A0 (grub_search_label): Likewise. > > + =C2=A0 =C2=A0 * docs/grub.texi (search): Document --exclude. > > + > > =C2=A02013-12-11 =C2=A0Vladimir Serbinenko =C2=A0 > > > > =C2=A0 =C2=A0 =C2=A0 * grub-core/normal/charset.c: Fix premature line w= rap 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. > > > > =C2=A0@deffn Command search @ > > =C2=A0 [@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 > > =C2=A0Search devices by file (@option{-f}, @option{--file}), filesystem= label > > =C2=A0(@option{-l}, @option{--label}), or filesystem UUID (@option{-u}, > > =C2=A0@option{--fs-uuid}). > > @@ -4743,6 +4744,10 @@ value of environment variable @var{var}. =C2=A0T= he default variable is > > =C2=A0The @option{--no-floppy} option prevents searching floppy devices= , which can > > =C2=A0be slow. > > > > +The @option{--exclude} option excludes any matches of the given GRUB d= evice > > +name. =C2=A0For example, this may be used to search for any file named > > +@file{/boot/grub/grub.cfg} other than the one in a memdisk. > > + > > =C2=A0The @samp{search.file}, @samp{search.fs_label}, and @samp{search.= fs_uuid} > > =C2=A0commands are aliases for @samp{search --file}, @samp{search --lab= el}, and > > =C2=A0@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 > > =C2=A0 =C2=A0int no_floppy; > > =C2=A0 =C2=A0char **hints; > > =C2=A0 =C2=A0unsigned nhints; > > + =C2=A0char **excludes; > > + =C2=A0unsigned nexcludes; > > =C2=A0 =C2=A0int count; > > =C2=A0 =C2=A0int is_cache; > > =C2=A0}; > > @@ -59,8 +61,15 @@ static int > > =C2=A0iterate_device (const char *name, void *data) > > =C2=A0{ > > =C2=A0 =C2=A0struct search_ctx *ctx =3D data; > > + =C2=A0unsigned i; > > =C2=A0 =C2=A0int found =3D 0; > > > > + =C2=A0for (i =3D 0; i < ctx->nexcludes; i++) > > + =C2=A0 =C2=A0{ > > + =C2=A0 =C2=A0 =C2=A0if (grub_strcmp (name, ctx->excludes[i]) =3D=3D 0= ) > > + =C2=A0 =C2=A0 return 0; > > + =C2=A0 =C2=A0} > > + > 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=3Dhd0,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. How about excluding by uuid (or uuid-file)? For example, the following (untested) grub.cfg provides what I expect would be a nice interface for Xen users, using existing grub features only: # Search all devices for grub.cfg files to use, presenting a menu to chose among them if # more than=C2=A0 one is found. timeout=3D5 probe --set=3Dthis_uuid --fs-uuid "(${root})" insmod regexp found_a_cfg=3Dfalse found_multiple_cfgs=3Dfalse for cfg in (*)/boot/grub/grub.cfg (*)/grub/grub.cfg (*)/boot/grub2/grub.cfg= \ =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (*)/grub2/grub= .cfg; do =C2=A0 regexp --set=3D1:cfg_device '^\((.*)\)/' "$cfg" =C2=A0 probe --set=3Dcfg_device_uuid --fs-uuid "(${cfg_device})" =C2=A0 if [ "$this_uuid" !=3D "$cfg_device_uuid" ]; then =C2=A0=C2=A0=C2=A0 if [ "$found_a_cfg" =3D true ]; then found_multiple_cfgs= =3Dtrue; fi =C2=A0=C2=A0=C2=A0 found_a_cfg=3Dtrue =C2=A0=C2=A0=C2=A0 menuentry "$cfg" "$cfg_device" "$cfg" { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cfg_device=3D"$2" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cfg=3D"$3" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 root=3D"$cfg_device" =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 configfile "$cfg" =C2=A0=C2=A0=C2=A0 } =C2=A0 fi done if [ "$cfg_found" !=3D true ]; then =C2=A0 echo $"Error: Could not find any grub.cfg files." else if [ "$multiple_cfg_found" !=3D true ]; then # We found exactly one gr= ub.cfg =C2=A0 timeout=3D0 # Don't bother showing the menu, just use the grub.cfg w= e found. fi One obvious downside of the above is that all devices (including possibly slow ones) are searched rather than stopping at the first grub.cfg found. To fix that properly would require a way to exclude devices with certain UUIDs (or UUID-files) from being searched by the search command. --=20 Jordan Uggla (Jordan_U on irc.freenode.net)