[Libguestfs] [PATCH] Fix device name mapping for libata guests

Matthew Booth mbooth at redhat.com
Tue Oct 12 13:22:42 UTC 2010


On 12/10/10 14:08, Daniel P. Berrange wrote:
> On Tue, Oct 12, 2010 at 02:05:25PM +0100, Matthew Booth wrote:
>> remap_block_devices was modifying the global device list while remapping device
>> names for libata guests (which includes RHEL 6). This caused a failure later
>> when the renamed devices were not present in the original XML.
>>
>> Fixes RHBZ#641869
>> ---
>>   lib/Sys/VirtV2V/GuestOS/RedHat.pm |   14 +++++++++++++-
>>   1 files changed, 13 insertions(+), 1 deletions(-)
>>
>> diff --git a/lib/Sys/VirtV2V/GuestOS/RedHat.pm b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
>> index a322a5d..cc95fd8 100644
>> --- a/lib/Sys/VirtV2V/GuestOS/RedHat.pm
>> +++ b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
>> @@ -1567,7 +1567,19 @@ sub remap_block_devices
>>                   $letter++;
>>               }
>>
>> -            map { $_ = $map{$_} } @$devices;
>> +            # N.B. Don't use map() here because we mustn't modify the original
>> +            # devices list
>
> The problem isn't that you used map(), it is that your map code block
> has side effects. You should be able to avoid the side effect thus:
>
>        my @newdevices = map { $map{$_} } @$devices;
>

Thanks, Dan.

As it turns out I'm going to leave the loop as is because it contains an 
additional sanity check which spoils the conciseness of map(). With the 
extra test, I think this form is cleaner. I have, however, updated the 
comment to not blame map :)

Matt
-- 
Matthew Booth, RHCA, RHCSS
Red Hat Engineering, Virtualisation Team

GPG ID:  D33C3490
GPG FPR: 3733 612D 2D05 5458 8A8A 1600 3441 EA19 D33C 3490




More information about the Libguestfs mailing list