Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-16 Thread Richard W.M. Jones
I think it's even possible to modify that shell script to pipe into
nbdkit and from there to ‘qemu-img convert’.  I'm too lazy to actually
do that right now, but the basic idea is here:

  https://rwmj.wordpress.com/2014/10/14/streaming-nbd-server/

You'll probably have to add ‘-m 1’ to the qemu-img convert command line.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org



Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-16 Thread Tomáš Golembiovský
On Thu, 16 Nov 2017 13:56:16 +0100
Tomáš Golembiovský  wrote:

> On Wed, 15 Nov 2017 21:41:20 +0100
> Gandalf Corvotempesta  wrote:
> 
> > 2017-11-15 21:29 GMT+01:00 Richard W.M. Jones :  
> > > Gandalf, is there an XVA file publically available (pref. not
> > > too big) that we can look at?  
> > 
> > I can try to provide one, but it's simple:
> > 
> > # tar tvf 20160630_124823_aa72_.xva.gz | head -n 50
> > -- 0/0   42353 1970-01-01 01:00 ova.xml
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/
> > -- 0/0  40 1970-01-01 01:00 Ref:175/.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0001
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0001.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0003
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0003.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0004
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0004.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0005
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0005.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0006
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0006.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0007
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0007.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0009
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0009.checksum
> > -- 0/0 1048576 1970-01-01 01:00 Ref:175/0010
> > -- 0/0  40 1970-01-01 01:00 Ref:175/0010.checksum
> > 
> > 
> > You can ignore the ova.xml and just use the "Ref:175" directory.
> > Inside the XVA you'll fine one "Ref" directory for each virtual disk
> > (ref number is different for each disk)
> > Inside each Ref directory, you'll get tons of 1MB file, corrisponding
> > to the RAW image.
> > You have to merge these files in a single raw file with just an
> > exception: numbers are not sequential.
> > as you can see above, we have: , 0001, 0003
> > 
> > The 0002 is missing, because it's totally blank. XenServer doesn't
> > export any empty block, thus it will skip the corrisponding 1MB file.
> > When building the raw image, you have to replace empty blocks with 1MB
> > full of zeros.
> > 
> > This is (in addition to the tar extract) the most time-consuming part.
> > Currently I'm rebuilding a 250GB image, with tons of files to be
> > merge.
> > If qemu-img can be patched to automatically convert this kind of
> > format, I can save about 3 hours (30 minutes for extracting the
> > tarball, and about 2 hours to merge 250-300GB image)
> >   
> 
> Hi,
> 
> I like what Richard and Max came up with. Pretty nifty solutions.
> While there's nothing wrong with them I decided to take my own shot at
> it. Since the blocks in tar file are pieces of raw image there is no
> conversion happening. All in all it's just moving bytes from one place
> to another. That means there shouldn't be a need for any heavy
> machinery, right? :)
> 
> Attached is a shell script that uses dd to do the byte-shuffling.
> I'm pretty sure this could even be safely parallelized by running
> multiple instances of dd at the same time (e.g. with xargs). But I did
> not try that.

Oh yes, and one more thing: as with the other solutions I didn't bother
reading the XML for the target size. So resize may be necessary
afterwards.

Tomas

-- 
Tomáš Golembiovský 



Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-16 Thread Tomáš Golembiovský
On Wed, 15 Nov 2017 21:41:20 +0100
Gandalf Corvotempesta  wrote:

> 2017-11-15 21:29 GMT+01:00 Richard W.M. Jones :
> > Gandalf, is there an XVA file publically available (pref. not
> > too big) that we can look at?
> 
> I can try to provide one, but it's simple:
> 
> # tar tvf 20160630_124823_aa72_.xva.gz | head -n 50
> -- 0/0   42353 1970-01-01 01:00 ova.xml
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/
> -- 0/0  40 1970-01-01 01:00 Ref:175/.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0001
> -- 0/0  40 1970-01-01 01:00 Ref:175/0001.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0003
> -- 0/0  40 1970-01-01 01:00 Ref:175/0003.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0004
> -- 0/0  40 1970-01-01 01:00 Ref:175/0004.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0005
> -- 0/0  40 1970-01-01 01:00 Ref:175/0005.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0006
> -- 0/0  40 1970-01-01 01:00 Ref:175/0006.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0007
> -- 0/0  40 1970-01-01 01:00 Ref:175/0007.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0009
> -- 0/0  40 1970-01-01 01:00 Ref:175/0009.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0010
> -- 0/0  40 1970-01-01 01:00 Ref:175/0010.checksum
> 
> 
> You can ignore the ova.xml and just use the "Ref:175" directory.
> Inside the XVA you'll fine one "Ref" directory for each virtual disk
> (ref number is different for each disk)
> Inside each Ref directory, you'll get tons of 1MB file, corrisponding
> to the RAW image.
> You have to merge these files in a single raw file with just an
> exception: numbers are not sequential.
> as you can see above, we have: , 0001, 0003
> 
> The 0002 is missing, because it's totally blank. XenServer doesn't
> export any empty block, thus it will skip the corrisponding 1MB file.
> When building the raw image, you have to replace empty blocks with 1MB
> full of zeros.
> 
> This is (in addition to the tar extract) the most time-consuming part.
> Currently I'm rebuilding a 250GB image, with tons of files to be
> merge.
> If qemu-img can be patched to automatically convert this kind of
> format, I can save about 3 hours (30 minutes for extracting the
> tarball, and about 2 hours to merge 250-300GB image)
> 

Hi,

I like what Richard and Max came up with. Pretty nifty solutions.
While there's nothing wrong with them I decided to take my own shot at
it. Since the blocks in tar file are pieces of raw image there is no
conversion happening. All in all it's just moving bytes from one place
to another. That means there shouldn't be a need for any heavy
machinery, right? :)

Attached is a shell script that uses dd to do the byte-shuffling.
I'm pretty sure this could even be safely parallelized by running
multiple instances of dd at the same time (e.g. with xargs). But I did
not try that.


Tomas

-- 
Tomáš Golembiovský 


xva2raw.sh
Description: application/shellscript


Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-16 Thread Richard W.M. Jones
On Thu, Nov 16, 2017 at 11:07:10AM +0100, Gandalf Corvotempesta wrote:
> 2017-11-16 11:01 GMT+01:00 Richard W.M. Jones :
> > As mentioned before you can use this to do a qemu-img convert using
> > captive nbdkit:
> >
> >   $ nbdkit -U - \
> >   perl script=./xva-reader.pl file=./debian8cloud.xva size=4294967296 \
> >   --run 'qemu-img convert -f raw $nbd -O qcow2 /var/tmp/output.qcow2 -p'
> 
> 
> What if XVA is hosting 2 or more partitions ? Which partition are you
> converting with this command ?

See "XXX" comments in the code, left as an exercise to the reader :-)

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/



Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-16 Thread Gandalf Corvotempesta
2017-11-16 11:01 GMT+01:00 Richard W.M. Jones :
> As mentioned before you can use this to do a qemu-img convert using
> captive nbdkit:
>
>   $ nbdkit -U - \
>   perl script=./xva-reader.pl file=./debian8cloud.xva size=4294967296 \
>   --run 'qemu-img convert -f raw $nbd -O qcow2 /var/tmp/output.qcow2 -p'


What if XVA is hosting 2 or more partitions ? Which partition are you
converting with this command ?



Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-16 Thread Richard W.M. Jones
Here's my solution, as a nbdkit plugin written in Perl.

As with Max's solution I don't bother to parse the virtual size out of
the XML file, so you need to specify that on the command line
otherwise the disk will be truncated to the largest extent stored in
the file.  Also the ‘.xva’ file must not be compressed.

  $ nbdkit perl script=./xva-reader.pl file=./debian8cloud.xva size=4294967296

  $ guestfish --ro --format=raw -a nbd://localhost -i
  
  Welcome to guestfish, the guest filesystem shell for
  editing virtual machine filesystems and disk images.
  
  Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
  
  Operating system: 8.2
  /dev/sda1 mounted on /
  
  > ll /
  total 100
  drwxr-xr-x 22 root root  4096 Jan  8  2016 .
  drwxr-xr-x 19 root root  4096 Nov 16 09:50 ..
  drwxrwxr-x  2 root root  4096 Jan  8  2016 bin
  drwxr-xr-x  3 root root  4096 Jan  8  2016 boot
  drwxr-xr-x  4 root root  4096 Jan  8  2016 dev
  drwxr-xr-x 87 root root  4096 Jan  8  2016 etc
  drwxr-xr-x  3 root root  4096 Jan  8  2016 home
  lrwxrwxrwx  1 root root31 Jan  8  2016 initrd.img -> 
/boot/initrd.img-3.16.0-4-amd64
  drwxr-xr-x 14 root root  4096 Jan  8  2016 lib
  drwxr-xr-x  2 root root  4096 Jan  8  2016 lib64
  drwx--  2 root root 16384 Jan  8  2016 lost+found
  drwxr-xr-x  3 root root  4096 Jan  8  2016 media
  drwxr-xr-x  2 root root  4096 Jan  8  2016 mnt
  drwxr-xr-x  2 root root  4096 Jan  8  2016 opt
  drwxr-xr-x  2 root root  4096 May  4  2015 proc
  drwx--  2 root root  4096 Jan  8  2016 root
  drwxr-xr-x  2 root root  4096 Jan  8  2016 run
  drwxr-xr-x  2 root root  4096 Jan  8  2016 sbin
  drwxr-xr-x  2 root root  4096 Jan  8  2016 srv
  drwxr-xr-x  2 root root  4096 Apr  6  2015 sys
  drwxrwxrwt  7 root root  4096 Jan  8  2016 tmp
  drwxr-xr-x 10 root root  4096 Jan  8  2016 usr
  drwxr-xr-x 11 root root  4096 Jan  8  2016 var
  lrwxrwxrwx  1 root root27 Jan  8  2016 vmlinuz -> 
boot/vmlinuz-3.16.0-4-amd64

I even managed to boot the Debian 8 guest from the sample .xva file:

  $ qemu-system-x86_64 -cpu host -machine accel=kvm:tcg -m 2048 -drive 
file=nbd:localhost:10809,format=raw,if=virtio,snapshot=on

although it was pretty slow ...

As mentioned before you can use this to do a qemu-img convert using
captive nbdkit:

  $ nbdkit -U - \
  perl script=./xva-reader.pl file=./debian8cloud.xva size=4294967296 \
  --run 'qemu-img convert -f raw $nbd -O qcow2 /var/tmp/output.qcow2 -p'

HTH,

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html


xva-reader.pl
Description: Perl program


Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-15 Thread Richard W.M. Jones
On Wed, Nov 15, 2017 at 09:05:00PM +, Richard W.M. Jones wrote:
> This will give you one offset/size/filename tuple for each file.  The
> plugin will then simply need to calculate which file to access to
> resolve each virtual file range (or substitute zeroes for missing
> files).

By which I mean, of course, that it accesses the offset/size directly
by opening the tar file.  The file doesn't have to be extracted.

I'm still interested if you have a small XVA example you can share.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW



Re: [Qemu-block] [Qemu-devel] [Libguestfs] [qemu-img] support for XVA

2017-11-15 Thread Richard W.M. Jones
On Wed, Nov 15, 2017 at 09:41:20PM +0100, Gandalf Corvotempesta wrote:
> 2017-11-15 21:29 GMT+01:00 Richard W.M. Jones :
> > Gandalf, is there an XVA file publically available (pref. not
> > too big) that we can look at?
> 
> I can try to provide one, but it's simple:
> 
> # tar tvf 20160630_124823_aa72_.xva.gz | head -n 50
> -- 0/0   42353 1970-01-01 01:00 ova.xml
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/
> -- 0/0  40 1970-01-01 01:00 Ref:175/.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0001
> -- 0/0  40 1970-01-01 01:00 Ref:175/0001.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0003
> -- 0/0  40 1970-01-01 01:00 Ref:175/0003.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0004
> -- 0/0  40 1970-01-01 01:00 Ref:175/0004.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0005
> -- 0/0  40 1970-01-01 01:00 Ref:175/0005.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0006
> -- 0/0  40 1970-01-01 01:00 Ref:175/0006.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0007
> -- 0/0  40 1970-01-01 01:00 Ref:175/0007.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0009
> -- 0/0  40 1970-01-01 01:00 Ref:175/0009.checksum
> -- 0/0 1048576 1970-01-01 01:00 Ref:175/0010
> -- 0/0  40 1970-01-01 01:00 Ref:175/0010.checksum
> 
> 
> You can ignore the ova.xml and just use the "Ref:175" directory.
> Inside the XVA you'll fine one "Ref" directory for each virtual disk
> (ref number is different for each disk)
> Inside each Ref directory, you'll get tons of 1MB file, corrisponding
> to the RAW image.
> You have to merge these files in a single raw file with just an
> exception: numbers are not sequential.
> as you can see above, we have: , 0001, 0003
> 
> The 0002 is missing, because it's totally blank. XenServer doesn't
> export any empty block, thus it will skip the corrisponding 1MB file.
> When building the raw image, you have to replace empty blocks with 1MB
> full of zeros.
> 
> This is (in addition to the tar extract) the most time-consuming part.
> Currently I'm rebuilding a 250GB image, with tons of files to be
> merge.
> If qemu-img can be patched to automatically convert this kind of
> format, I can save about 3 hours (30 minutes for extracting the
> tarball, and about 2 hours to merge 250-300GB image)

I guess the nbdkit approach would be better given the multiple and
missing files within the tar file.

You'll have to use ‘tar tRvf file.xva’ to extract the offset and size
of each file.  (See the function ‘find_file_in_tar’ in virt-v2v source
for exactly how).

This will give you one offset/size/filename tuple for each file.  The
plugin will then simply need to calculate which file to access to
resolve each virtual file range (or substitute zeroes for missing
files).

Note that nbdkit lets you write plugins in high-level languages like
Perl or Python which would be ideally suited to this kind of task.

You can then use "captive nbdkit" (see the manual) like this:

  nbdkit -U - \
  perl script=/path/to/xva-parser.pl file=/path/to/file.xva \
  --run 'qemu-img convert $nbd -O qcow2 output.qcow2'

At no point does the tar file need to be fully unpacked and it should
all be reasonably efficient.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html