[virt-tools-list] find0 in (perl) Sys::Guestfs

Richard W.M. Jones rjones at redhat.com
Fri Mar 2 15:11:30 UTC 2012


On Tue, Jan 31, 2012 at 01:29:58PM -0800, dan farmer wrote:
> Is there anyway to convince find0 to put the results in memory rather than
> writing to a file?  I really don't want to have to write it to a file and
> then read it again just to process the results.  I see guestfish has an
> option to write to stdout (but the lib doesn't have a documented way) for
> some reason.

These so-called "FileIn" and "FileOut" APIs only read and write to
files.  However in Linux you can easily convert this to a file
descriptor, or even in-memory operation.  This page describes the
/dev/fd method:

http://libguestfs.org/guestfs.3.html#uploading_and_downloading_to_pipes_and_file_descriptors

Note that if you want to actively read or write from the other end of
the /dev/fd file descriptor, then there has to be another process or
thread involved.  This is because the libguestfs API is synchronous
and so the thread which makes the guestfs_* call will be doing
blocking read(2) and write(2) system calls.  This makes it rather hard
to use /dev/fd/* from guestfish, which is single-threaded, but you can
still use pipes, eg:

  find0 / - | <some other program>

> It'd be nice to point to either a scalar (or w/e var) or filename and let me
> worry if I have enough memory to hold all that.  I suppose I could write
> my own walker, try to intercept the writes of guestfish, change the
> source, try tricks with named pipes, (not going to call guestfish from
> inside perl!)Š hoping for an easier answer.

At some point you hit the limits of guestfish and it's better to use
the real perl bindings, ie. Sys::Guestfs.

[...]
> P.s.  If there's a better place to ask for such things, let me know; looking
> at 
> archives it seems more patch/dev stuff here than the charter suggests,
> but I'm fine with w/e.

Usually better to ask libguestfs questions here:

https://www.redhat.com/mailman/listinfo/libguestfs

Rich.

> P.p.s. Is there a repository for scripts or things written for libguestfs?
> I'm 
> familiar with the recipes page
> (http://libguestfs.org/guestfs-recipes.1.html)
> but haven't found much else other than rich's blog.  But unless libguestfs
> dies on me along the way I'm planning on writing various things in the next
> few months that may or may not see the light of day, but don't want to spam
> folks if there's another option or no interest.
> 
> ^..^
> 
> 

> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list


-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v




More information about the virt-tools-list mailing list