[PATCH] inspector: Canonicalize device names (fix RHBZ#526717).
This seems to be the completed fix for: https://bugzilla.redhat.com/show_bug.cgi?id=526717 -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 75 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
Richard W.M. Jones wrote:
This seems to be the completed fix for: https://bugzilla.redhat.com/show_bug.cgi?id=526717 ... Subject: [PATCH] inspector: Canonicalize device names (fix RHBZ#526717).
Make filesystem device names canonical, so they are /dev/sd* instead of /dev/vd*. --- perl/lib/Sys/Guestfs/Lib.pm | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm index a9868e2..068cde5 100644 --- a/perl/lib/Sys/Guestfs/Lib.pm +++ b/perl/lib/Sys/Guestfs/Lib.pm @@ -575,7 +575,19 @@ sub inspect_all_partitions my $g = shift; my $parts = shift; my @parts = @$parts; - return map { $_ => inspect_partition ($g, $_, @_) } @parts; + return map { _canonical_dev ($_) => inspect_partition ($g, $_, @_) } @parts; +} + +# Turn /dev/vd* and /dev/hd* into canonical device names +# (see BLOCK DEVICE NAMING in guestfs(3)). + +sub _canonical_dev +{ + local $_ = shift; + + return "/dev/sd$1" if m{^/dev/hd(\w+)}; + return "/dev/sd$1" if m{^/dev/vd(\w+)}; + return $_; }
=head2 inspect_partition
Hi Rich, I prefer to define such functions before their first use, and using the prototype notation, so that perl can check the number of arguments in any use: sub _canonical_dev ($) { my ($dev) = @_; $dev =~ m{^/dev/[vh]d(\w+)} and $dev = "/dev/sd$1"; return $dev; } Also, I find that not using $_ (even when declared local) improves maintainability. Finally, you can combine those two matches into one.
On Thu, Oct 01, 2009 at 05:26:10PM +0200, Jim Meyering wrote:
sub _canonical_dev ($) { my ($dev) = @_; $dev =~ m{^/dev/[vh]d(\w+)} and $dev = "/dev/sd$1"; return $dev; }
Also, I find that not using $_ (even when declared local) improves maintainability.
Finally, you can combine those two matches into one.
Thanks. This is what I will commit: +sub _canonical_dev ($) +{ + my ($dev) = @_; + return "/dev/sd$1" if $dev =~ m{^/dev/[vh]d(\w+)}; + return $dev; +} Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
participants (2)
-
Jim Meyering -
Richard W.M. Jones