Hierarchical local mount
Hello everyone! I have to implement the functionality of mounting all VM disks/partitions. E.g. if a VM has 2 disks of 2 partitions each (I get it from virt-filesystems), I want to get the following structure on host node after mount: mnt/ ------hdd0/ -------------volume1/ -------------volume2/ ------hdd1/ -------------volume1/ -------------volume2/ I'd like to use guestmount due to syntax simplicity, but I found out that it's impossible to call e.g. guestmount -a disk.qcow2 -m /dev/sda1:/hdd0/volume1 -m /dev/sda2:/hdd0/volume2 mnt/ So I came to only two possible options: 1) mkdir -p mnt/hdd0/volume1 guestmount -a disk.qcow2 -m /dev/sda1 mnt/hdd0/volume1 .... (Is it safe to use the same disk from multiple guestmounts?) 2) guestfish -a disk.qcow2 " run : mkmountpoint /hdd0 : mkmountpoint /hdd0/volume1 : ... : mount /dev/sda1 /hdd0/volume1 : ... : mount-local mnt/ : mount-local-run" kill -TERM `pidof guestfish` guestunmount mnt/ Is any of these options safe enough/preferred? Or, maybe, other options? I'd like to avoid guestfs API, threading and so on, and confine myself to command-line. Thanks in advance! -- Your sincerely, Maxim Perevedentsev
On Fri, Nov 06, 2015 at 04:16:21PM +0300, Maxim Perevedentsev wrote:
Hello everyone!
I have to implement the functionality of mounting all VM disks/partitions.
E.g. if a VM has 2 disks of 2 partitions each (I get it from virt-filesystems), I want to get the following structure on host node after mount: mnt/ ------hdd0/ -------------volume1/ -------------volume2/ ------hdd1/ -------------volume1/ -------------volume2/
I'd like to use guestmount due to syntax simplicity, but I found out that it's impossible to call e.g. guestmount -a disk.qcow2 -m /dev/sda1:/hdd0/volume1 -m /dev/sda2:/hdd0/volume2 mnt/
So I came to only two possible options: 1) mkdir -p mnt/hdd0/volume1 guestmount -a disk.qcow2 -m /dev/sda1 mnt/hdd0/volume1 .... (Is it safe to use the same disk from multiple guestmounts?)
2) guestfish -a disk.qcow2 " run : mkmountpoint /hdd0 : mkmountpoint /hdd0/volume1 : ... : mount /dev/sda1 /hdd0/volume1 : ... : mount-local mnt/ : mount-local-run"
kill -TERM `pidof guestfish` guestunmount mnt/
Is any of these options safe enough/preferred? Or, maybe, other options? I'd like to avoid guestfs API, threading and so on, and confine myself to command-line.
The mount-local APIs don't require threads, although they can use them. A Perl script should be fairly simple, and is a lot easier to automate that guestfish and much more flexible than guestmount. Have a look at the attached file. In case it's not clear, you have to do 'guestunmount <MOUNTPOINT>' to exit the main program. 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
On 11/06/2015 05:08 PM, Richard W.M. Jones wrote:
Hello everyone!
I have to implement the functionality of mounting all VM disks/partitions.
E.g. if a VM has 2 disks of 2 partitions each (I get it from virt-filesystems), I want to get the following structure on host node after mount: mnt/ ------hdd0/ -------------volume1/ -------------volume2/ ------hdd1/ -------------volume1/ -------------volume2/
I'd like to use guestmount due to syntax simplicity, but I found out that it's impossible to call e.g. guestmount -a disk.qcow2 -m /dev/sda1:/hdd0/volume1 -m /dev/sda2:/hdd0/volume2 mnt/
So I came to only two possible options: 1) mkdir -p mnt/hdd0/volume1 guestmount -a disk.qcow2 -m /dev/sda1 mnt/hdd0/volume1 .... (Is it safe to use the same disk from multiple guestmounts?)
2) guestfish -a disk.qcow2 " run : mkmountpoint /hdd0 : mkmountpoint /hdd0/volume1 : ... : mount /dev/sda1 /hdd0/volume1 : ... : mount-local mnt/ : mount-local-run"
kill -TERM `pidof guestfish` guestunmount mnt/
Is any of these options safe enough/preferred? Or, maybe, other options? I'd like to avoid guestfs API, threading and so on, and confine myself to command-line. The mount-local APIs don't require threads, although they can use
On Fri, Nov 06, 2015 at 04:16:21PM +0300, Maxim Perevedentsev wrote: them.
A Perl script should be fairly simple, and is a lot easier to automate that guestfish and much more flexible than guestmount.
Have a look at the attached file. In case it's not clear, you have to do 'guestunmount <MOUNTPOINT>' to exit the main program.
Rich.
Thank you very much! I've rewritten this script in C, and it works just as expected. The only problem is that for unmount, we cannot reuse the same handle, and have to call guestunmount. There's a dim place: what is the difference between guestunmount and guestfs_umount_local? As I understood, guestunmount does need guestfs handle, launch etc. Does umount_local need it? If yes, how should this command be used (assumed that the handle is already used in mount_local_run)? These questions confuse me a little :-s -- Your sincerely, Maxim Perevedentsev
On Tue, Nov 10, 2015 at 02:06:30PM +0300, Maxim Perevedentsev wrote:
I've rewritten this script in C, and it works just as expected. The only problem is that for unmount, we cannot reuse the same handle, and have to call guestunmount.
There's a dim place: what is the difference between guestunmount and guestfs_umount_local? As I understood, guestunmount does [not] need guestfs handle, launch etc. Does umount_local need it? If yes, how should this command be used (assumed that the handle is already used in mount_local_run)?
These questions confuse me a little :-s
guestfs_umount_local just calls guestunmount, so they're the same thing: https://github.com/libguestfs/libguestfs/blob/master/src/fuse.c#L1103 Also as you can see from the implementation, guestfs_umount_local doesn't really use the guestfs_h *g handle -- it only uses it to find the mountpoint (so it can run guestunmount /mountpoint) and for a bit of bookkeeping: creating the 'cmd' object and error messages. We have an example program: https://github.com/libguestfs/libguestfs/blob/master/examples/mount-local.c Also an example of using mount-local with threads (which I don't recommend - I see lots of deadlocks under load which I don't think have anything to do with libguestfs): https://github.com/libguestfs/libguestfs/blob/master/tests/mount-local/test-... I found that pthreads + FUSE is a minefield. It's easy to end up with a forgotten file descriptor which makes the mountpoint busy and unmountable, or get deadlocks. Better to use fork()-parallelism instead. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
participants (2)
-
Maxim Perevedentsev -
Richard W.M. Jones