← Back to team overview

openstack team mailing list archive

Re: File injection support

 

On Tue, Jun 12, 2012 at 8:20 AM, Pádraig Brady <P@xxxxxxxxxxxxxx> wrote:
> On 06/12/2012 04:07 PM, Fredric Morenius wrote:
>> From: Scott Moser [mailto:ssmoser2@xxxxxxxxx] On Behalf Of Scott Moser
>> Sent: den 11 juni 2012 23:16
>>
>>> ...Without digging around on older versions of OS's and their included kernel/udev/kpartx.... i'd have to say that from your message above, and my testing that running 'kpartx' is no longer necessary.  That can reasonably be expected to be created by >the kernel or some other plumbing bits automatically...
>>
>> I just now tested to remove the kpartx invocation from /nova/virt/disk/mount.py, like this:
>>
>> diff --git a/nova/virt/disk/mount.py b/nova/virt/disk/mount.py
>> index 11959b2..4d9527b 100644
>> --- a/nova/virt/disk/mount.py
>> +++ b/nova/virt/disk/mount.py
>> @@ -61,25 +61,9 @@ class Mount(object):
>>          if self.partition == -1:
>>              self.error = _('partition search unsupported with %s') % self.mode
>>          elif self.partition:
>> -            map_path = '/dev/mapper/%sp%s' % (os.path.basename(self.device),
>> -                                              self.partition)
>> -            assert(not os.path.exists(map_path))
>> -
>> -            # Note kpartx can output warnings to stderr and succeed
>> -            # Also it can output failures to stderr and "succeed"
>> -            # So we just go on the existence of the mapped device
>> -            _out, err = utils.trycmd('kpartx', '-a', self.device,
>> -                                     run_as_root=True, discard_warnings=True)
>> -
>> -            # Note kpartx does nothing when presented with a raw image,
>> -            # so given we only use it when we expect a partitioned image, fail
>> -            if not os.path.exists(map_path):
>> -                if not err:
>> -                    err = _('partition %s not found') % self.partition
>> -                self.error = _('Failed to map partitions: %s') % err
>> -            else:
>> -                self.mapped_device = map_path
>> -                self.mapped = True
>> +            #qemu-nbd already has mapped the partition for mounting
>> +            self.mapped_device = '%sp%s' % (self.device, self.partition)
>> +            self.mapped = True
>
> Looks good. That should also support raw through the /dev/loop%s devices.
>
> It might be safer to fallback to kpartx if not exists ...
>   '%sp%s' % (self.device, self.partition)
> That would support kernels before 3.2
> I'd also add a comment in the code, that nbd must be mounted with param
> max_part=16 or whatever.


Might be totally unrelated to the above issues but I figured I'd throw
it out there. I was messing with file injection today and was getting
odd errors.

Some were due to hitting errors on a previous boot and partitions not
getting cleaned up (e.g. kpartx -d never ran and the /dev/mapper/nbd*
entries were still there, or qemu-nbd was still running). Some of
those were likely a result of my own circumstances.

More interesting though, and what might be of use to other people, the
"kpartx -a" calls get run and then the code in nova/virt/disk/mount.py
immediately checks for whether or not the newly created
/dev/mapper/nbdXXpX partitions exist. They'd actually get created but
the os.exists call would fail. Apparently the os.exists call was
getting run too soon. I added a time.sleep() after both the 'kpartx
-a' and 'kpartx -d' calls, to give things time to catch up before the
os.exists calls and things worked much better.


Follow ups

References