From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1OLjOK-0005vV-1w for mharc-grub-devel@gnu.org; Mon, 07 Jun 2010 16:57:52 -0400 Received: from [140.186.70.92] (port=38743 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLjOA-0005sG-8x for grub-devel@gnu.org; Mon, 07 Jun 2010 16:57:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLjO2-0007fB-2D for grub-devel@gnu.org; Mon, 07 Jun 2010 16:57:36 -0400 Received: from mail-ew0-f214.google.com ([209.85.219.214]:57354) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLjO1-0007f3-KC for grub-devel@gnu.org; Mon, 07 Jun 2010 16:57:34 -0400 Received: by ewy6 with SMTP id 6so2494152ewy.32 for ; Mon, 07 Jun 2010 13:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :x-enigmail-version:content-type; bh=PapCvPfKtpaXBbV/VVcIP4rA5FQkbga9gojFjHYvo38=; b=NfKldK+qjRvto15A8j4CJ7SpO1Zwrdj/Yfxw+wrcTxm6YDfRc93pbwsTHyiGomsiwq S8XSTPw7FJuhYavRpiUBhBN4XpC7obLV2v4n/qHDNQjAA+iewJnkEaNf0UE+0avtFwO0 oluL5A8TWA65jmgmlf8/Sw9Tm9PErxIYcCfkU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; b=t1Sy3kiDFo1OsYa4Rj5SQ5dnbHPEroVX6AEKlPNFIArXsR7Q82x8fq/FNbP97P6roc M8CcCXjVguoQ0wAJDrJFnK+DFeSPiinSTJ9c7QSU31NFovLIoL9DqgbHJfulCUitTENu 1D16XGVfUM3Np0yLBXeseW2yDSENP46NFNEys= Received: by 10.213.31.133 with SMTP id y5mr3703735ebc.68.1275944252067; Mon, 07 Jun 2010 13:57:32 -0700 (PDT) Received: from debian.bg45.phnet (gprs27.swisscom-mobile.ch [193.247.250.27]) by mx.google.com with ESMTPS id 13sm2875265ewy.9.2010.06.07.13.57.29 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 07 Jun 2010 13:57:31 -0700 (PDT) Message-ID: <4C0D5D37.8090508@gmail.com> Date: Mon, 07 Jun 2010 22:57:27 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100515 Icedove/3.0.4 MIME-Version: 1.0 To: grub-devel@gnu.org References: <20100603162354.GX21862@riva.ucam.org> In-Reply-To: <20100603162354.GX21862@riva.ucam.org> X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigB12FF1CAB4B24238138E79DA" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: [PATCH] Fix verbose error output when device-mapper not supported by kernel X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 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: Mon, 07 Jun 2010 20:57:50 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigB12FF1CAB4B24238138E79DA Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/03/2010 06:23 PM, Colin Watson wrote: > Following the merge of my dmraid-probe branch, several people have > reported extremely verbose error output in the event that the kernel > doesn't have device-mapper support (perhaps because the module isn't > loaded; it's modular in the stock Debian kernel). See e.g. > http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=3D584196. The attache= d > patch fixes this. OK for trunk? > > =20 Go ahead. > (The long patch to util/deviceiter.c is almost entirely due to the extr= a > 'if' causing an indentation change.) > =20 For such cases please send a patch with --diff-options=3D-bpB > 2010-06-03 Colin Watson > > * kern/emu/misc.c (device_mapper_null_log): New function. > (grub_device_mapper_supported): New function. > * include/grub/emu/misc.h (grub_device_mapper_supported): Add > prototype. > * kern/emu/hostdisk.c (find_partition_start): Check whether > device-mapper is supported before trying to use it. > * util/deviceiter.c (grub_util_iterate_devices): Likewise. > > =3D=3D=3D modified file 'include/grub/emu/misc.h' > --- include/grub/emu/misc.h 2010-05-28 13:48:45 +0000 > +++ include/grub/emu/misc.h 2010-06-03 16:00:06 +0000 > @@ -48,4 +48,8 @@ int EXPORT_FUNC(asprintf) (char **buf, c > char * EXPORT_FUNC(xasprintf) (const char *fmt, ...); > extern char * canonicalize_file_name (const char *path); > =20 > +#ifdef HAVE_DEVICE_MAPPER > +int grub_device_mapper_supported (void); > +#endif > + > #endif /* GRUB_EMU_MISC_H */ > > =3D=3D=3D modified file 'kern/emu/hostdisk.c' > --- kern/emu/hostdisk.c 2010-06-02 22:47:22 +0000 > +++ kern/emu/hostdisk.c 2010-06-03 16:00:06 +0000 > @@ -342,7 +342,7 @@ find_partition_start (const char *dev) > # endif /* !defined(__NetBSD__) */ > =20 > # ifdef HAVE_DEVICE_MAPPER > - if (device_is_mapped (dev)) { > + if (grub_device_mapper_supported () && device_is_mapped (dev)) { > struct dm_task *task =3D NULL; > grub_uint64_t start, length; > char *target_type, *params, *space; > > =3D=3D=3D modified file 'kern/emu/misc.c' > --- kern/emu/misc.c 2010-05-27 14:45:41 +0000 > +++ kern/emu/misc.c 2010-06-03 16:00:06 +0000 > @@ -22,6 +22,10 @@ > #include > #include > =20 > +#ifdef HAVE_DEVICE_MAPPER > +# include > +#endif > + > int verbosity; > =20 > void > @@ -311,3 +315,38 @@ grub_make_system_path_relative_to_its_ro > =20 > return buf3; > } > + > +#ifdef HAVE_DEVICE_MAPPER > +static void device_mapper_null_log (int level __attribute__ ((unused))= , > + const char *file __attribute__ ((unused)), > + int line __attribute__ ((unused)), > + int dm_errno __attribute__ ((unused)), > + const char *f __attribute__ ((unused)), > + ...) > +{ > +} > + > +int > +grub_device_mapper_supported (void) > +{ > + static int supported =3D -1; > + > + if (supported =3D=3D -1) > + { > + struct dm_task *dmt; > + > + /* Suppress annoying log messages. */ > + dm_log_with_errno_init (&device_mapper_null_log); > + > + dmt =3D dm_task_create (DM_DEVICE_VERSION); > + supported =3D (dmt !=3D NULL); > + if (dmt) > + dm_task_destroy (dmt); > + > + /* Restore the original logger. */ > + dm_log_with_errno_init (NULL); > + } > + > + return supported; > +} > +#endif /* HAVE_DEVICE_MAPPER */ > > =3D=3D=3D modified file 'util/deviceiter.c' > --- util/deviceiter.c 2010-01-26 14:26:16 +0000 > +++ util/deviceiter.c 2010-06-03 16:00:06 +0000 > @@ -33,6 +33,7 @@ > #include > #include > #include > +#include > =20 > #ifdef __linux__ > # if !defined(__GLIBC__) || \ > @@ -676,112 +677,113 @@ grub_util_iterate_devices (int NESTED_FU > } > =20 > /* DM-RAID. */ > - { > - struct dm_tree *tree =3D NULL; > - struct dm_task *task =3D NULL; > - struct dm_names *names =3D NULL; > - unsigned int next =3D 0; > - void *top_handle, *second_handle; > - struct dm_tree_node *root, *top, *second; > - struct dmraid_seen *seen =3D NULL; > - > - /* Build DM tree for all devices. */ > - tree =3D dm_tree_create (); > - dmraid_check (tree, "dm_tree_create failed\n"); > - task =3D dm_task_create (DM_DEVICE_LIST); > - dmraid_check (task, "dm_task_create failed\n"); > - dmraid_check (dm_task_run (task), "dm_task_run failed\n"); > - names =3D dm_task_get_names (task); > - dmraid_check (names, "dm_task_get_names failed\n"); > - dmraid_check (names->dev, "No DM devices found\n"); > - do > - { > - names =3D (void *) names + next; > - dmraid_check (dm_tree_add_dev (tree, MAJOR (names->dev), > - MINOR (names->dev)), > - "dm_tree_add_dev (%s) failed\n", names->name); > - next =3D names->next; > - } > - while (next); > - > - /* Walk the second-level children of the inverted tree; that is, d= evices > - which are directly composed of non-DM devices such as hard disk= s. > - This class includes all DM-RAID disks and excludes all DM-RAID > - partitions. */ > - root =3D dm_tree_find_node (tree, 0, 0); > - top_handle =3D NULL; > - top =3D dm_tree_next_child (&top_handle, root, 1); > - while (top) > - { > - second_handle =3D NULL; > - second =3D dm_tree_next_child (&second_handle, top, 1); > - while (second) > - { > - const char *node_name, *node_uuid; > - char *name; > - struct dmraid_seen *seen_elt; > - > - node_name =3D dm_tree_node_get_name (second); > - dmraid_check (node_name, "dm_tree_node_get_name failed\n"); > - node_uuid =3D dm_tree_node_get_uuid (second); > - dmraid_check (node_uuid, "dm_tree_node_get_uuid failed\n"); > - if (strncmp (node_uuid, "DMRAID-", 7) !=3D 0) > - { > - grub_dprintf ("deviceiter", "%s is not DM-RAID\n", node_name); > - goto dmraid_next_child; > - } > - > - /* Have we already seen this node? There are typically very few > - DM-RAID disks, so a list should be fast enough. */ > - if (grub_named_list_find (GRUB_AS_NAMED_LIST (seen), node_name)) > - { > - grub_dprintf ("deviceiter", "Already seen DM device %s\n", > - node_name); > - goto dmraid_next_child; > - } > - > - name =3D xasprintf ("/dev/mapper/%s", node_name); > - if (check_device (name)) > - { > - if (hook (name, 0)) > - { > - free (name); > - while (seen) > - { > - struct dmraid_seen *seen_elt =3D > - grub_list_pop (GRUB_AS_LIST_P (&seen)); > - free (seen_elt); > - } > - if (task) > - dm_task_destroy (task); > - if (tree) > - dm_tree_free (tree); > - return; > - } > - } > - free (name); > + if (grub_device_mapper_supported ()) > + { > + struct dm_tree *tree =3D NULL; > + struct dm_task *task =3D NULL; > + struct dm_names *names =3D NULL; > + unsigned int next =3D 0; > + void *top_handle, *second_handle; > + struct dm_tree_node *root, *top, *second; > + struct dmraid_seen *seen =3D NULL; > + > + /* Build DM tree for all devices. */ > + tree =3D dm_tree_create (); > + dmraid_check (tree, "dm_tree_create failed\n"); > + task =3D dm_task_create (DM_DEVICE_LIST); > + dmraid_check (task, "dm_task_create failed\n"); > + dmraid_check (dm_task_run (task), "dm_task_run failed\n"); > + names =3D dm_task_get_names (task); > + dmraid_check (names, "dm_task_get_names failed\n"); > + dmraid_check (names->dev, "No DM devices found\n"); > + do > + { > + names =3D (void *) names + next; > + dmraid_check (dm_tree_add_dev (tree, MAJOR (names->dev), > + MINOR (names->dev)), > + "dm_tree_add_dev (%s) failed\n", names->name); > + next =3D names->next; > + } > + while (next); > =20 > - seen_elt =3D xmalloc (sizeof *seen_elt); > - seen_elt->name =3D node_name; > - grub_list_push (GRUB_AS_LIST_P (&seen), GRUB_AS_LIST (seen_elt));= > + /* Walk the second-level children of the inverted tree; that is,= devices > + which are directly composed of non-DM devices such as hard disks. > + This class includes all DM-RAID disks and excludes all DM-RAID > + partitions. */ > + root =3D dm_tree_find_node (tree, 0, 0); > + top_handle =3D NULL; > + top =3D dm_tree_next_child (&top_handle, root, 1); > + while (top) > + { > + second_handle =3D NULL; > + second =3D dm_tree_next_child (&second_handle, top, 1); > + while (second) > + { > + const char *node_name, *node_uuid; > + char *name; > + struct dmraid_seen *seen_elt; > + > + node_name =3D dm_tree_node_get_name (second); > + dmraid_check (node_name, "dm_tree_node_get_name failed\n"); > + node_uuid =3D dm_tree_node_get_uuid (second); > + dmraid_check (node_uuid, "dm_tree_node_get_uuid failed\n"); > + if (strncmp (node_uuid, "DMRAID-", 7) !=3D 0) > + { > + grub_dprintf ("deviceiter", "%s is not DM-RAID\n", node_name); > + goto dmraid_next_child; > + } > + > + /* Have we already seen this node? There are typically very fe= w > + DM-RAID disks, so a list should be fast enough. */ > + if (grub_named_list_find (GRUB_AS_NAMED_LIST (seen), node_name)= ) > + { > + grub_dprintf ("deviceiter", "Already seen DM device %s\n", > + node_name); > + goto dmraid_next_child; > + } > + > + name =3D xasprintf ("/dev/mapper/%s", node_name); > + if (check_device (name)) > + { > + if (hook (name, 0)) > + { > + free (name); > + while (seen) > + { > + struct dmraid_seen *seen_elt =3D > + grub_list_pop (GRUB_AS_LIST_P (&seen)); > + free (seen_elt); > + } > + if (task) > + dm_task_destroy (task); > + if (tree) > + dm_tree_free (tree); > + return; > + } > + } > + free (name); > + > + seen_elt =3D xmalloc (sizeof *seen_elt); > + seen_elt->name =3D node_name; > + grub_list_push (GRUB_AS_LIST_P (&seen), GRUB_AS_LIST (seen_elt)= ); > =20 > dmraid_next_child: > - second =3D dm_tree_next_child (&second_handle, top, 1); > - } > - top =3D dm_tree_next_child (&top_handle, root, 1); > - } > + second =3D dm_tree_next_child (&second_handle, top, 1); > + } > + top =3D dm_tree_next_child (&top_handle, root, 1); > + } > =20 > dmraid_end: > - while (seen) > - { > - struct dmraid_seen *seen_elt =3D grub_list_pop (GRUB_AS_LIST_P (&seen= )); > - free (seen_elt); > - } > - if (task) > - dm_task_destroy (task); > - if (tree) > - dm_tree_free (tree); > - } > + while (seen) > + { > + struct dmraid_seen *seen_elt =3D grub_list_pop (GRUB_AS_LIST_P (&se= en)); > + free (seen_elt); > + } > + if (task) > + dm_task_destroy (task); > + if (tree) > + dm_tree_free (tree); > + } > # endif /* HAVE_DEVICE_MAPPER */ > #endif /* __linux__ */ > } > > Thanks, > > =20 --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enigB12FF1CAB4B24238138E79DA Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAkwNXTcACgkQNak7dOguQgnKHwD/UgluJHEMMNkXEaJL4CvHhvZM 3+Ujtewk4IKlDKwvPQoBAIWJ2SE4bn8345tT16FMCN0MGb6MCqXhrNxTjNRRdC/9 =nSbZ -----END PGP SIGNATURE----- --------------enigB12FF1CAB4B24238138E79DA--