run: Rearrangement and add comments.

No functional change.
(cherry picked from commit 2d56e5af900662ea0a13e9e8ea4a802609214ecc)
ruby: Remove useless AC_SUBST in configure file.
(cherry picked from commit b9f858e5eefa0d2abae5ff0a61a39b0d34334bc1)
ruby: Changing spacing in configure file.

No functional change.
(cherry picked from commit b07d0968823d008776345a1c724713d2320e1571)
ruby: Fix detection of library (thanks Hilko Bengen).

On Debian, the Ruby C extensions library isn't '-lruby', it's
something like '-lruby1.8' or '-lruby-1.9.1' and these can even be
parallel-installed.

Fix detection so we use Ruby's own rbconfig.rb file to find the right
library to use.
(cherry picked from commit cba49169094f04dead9b165b6b5991afa92132ff)
New API: device-index.

This returns the index of the device, eg. /dev/sdb => 1.
Or you can think of it as the order that the device was
added, or the index of the device in guestfs_list_devices.

(cherry picked from commit a9d7d044f552855a7ef78d953c0c2672e35bfc80)
New API: guestfs_nr_devices

This returns the number of whole block devices added.  It is usually
simpler to call this than to list the devices and count them, which
is what we do in some places in the current codebase.
(cherry picked from commit 152b179a19e43fcb0baec65ea65d394ee1dba891)
inspect: Refactor resolve_fstab_device code into multiple functions.

This is mostly code motion, although it also fixes a memory leak in an
extremely rare failure case, and it generally tidies up the existing
code.
(cherry picked from commit 47b8225b05a7e35411f954f61f3eb3115c5a9f45)
inspect: Guess device name from /dev/disk/by-id/*-partN path (RHBZ#627675).

See https://bugzilla.redhat.com/show_bug.cgi?id=836573#c3
for an explanation.

Useful function 'is_partition' shows how to tell if a device name
represents a partition.
(cherry picked from commit 7eaa99994ebd354f4b078d4068695984989a907f)
inspect: Check partition exists when doing fstab mapping.

If the partition name we're about to return doesn't really exist,
then don't perform the mapping.
(cherry picked from commit ea8421c5d297698856a87c2cfe4a6b42796175a8)
tests: Use qemu-img to create an overlay for testing, instead of copying.

Replace:

  cp tests/guests/fedora.img test.img

with the longer but possibly more space-efficient equivalent:

  qemu-img create -F raw -b tests/guests/fedora.img -f qcow2 test.qcow2
(cherry picked from commit 339f3647f889424af2a2256c4fcad0b44982c275)
tests: Add a test of /dev/disk/by-id paths (RHBZ#627675).
(cherry picked from commit 5489304c8d2836713ec58051c24514eba22b8c94)
appliance: Update comment to note that systemd package now contains udevd.
(cherry picked from commit 100271c7bc00a1f9baacd8c56b43e156b736fc12)
appliance: Update paths to udevd.

systemd is playing a WTF game with udevd, moving it around and
renaming it unnecessarily in each release.  Chase all known locations.
(cherry picked from commit 906f8e3ae24a084d9a70d33d84c0ce29bdafa79c)
Rename qemu option cache=off to cache=none.

Note that qemu treats these identically, so this change has
no functional effect.
(cherry picked from commit 1608ca182b094a1dbe22094f39a5e86f18f728b7)

Conflicts:
	src/launch.c
Add notes about how qemu cache=none works internally.

This is just a comment and has no functional effect.
(cherry picked from commit 0437a7905619b8370e25fbae1a3e6388c5277be9)
daemon: Code tidy up in devsparts.

No functional change.

(cherry picked from commit cb24ceedd8a8ef7da71cfcce6db10669de47685c)
daemon: Run fsync on block devices after sync (RHBZ#836710).

On Linux, sync(2) does not actually issue a write barrier, thus it
doesn't force a flush of the underlying hardware write cache (or
qemu's disk cache in the virtual case).

This can be a problem, because libguestfs relies on running sync in
the appliance, followed by killing qemu (using SIGTERM).

In most cases, this is fine, because killing qemu with SIGTERM should
cause it to flush out the disk cache before it exits.  However we have
found various bugs in qemu which cause qemu to crash while doing the
flush, leaving the data unwritten (see RHBZ#836913).

The solution is to issue fsync(2) to the block devices.  This has a
write barrier, so it ensures that qemu writes out its cache long
before we get around to killing qemu.
(cherry picked from commit c0a3c9ce70b98171e737e49e6dccc4457963f2ec)
examples: In create_disk example, don't call set_autosync.

This is now set by default in all supported versions of libguestfs.
It's just confusing if the examples refer to it.
(cherry picked from commit 917550a117904ec1a06b77a7870a147014d71adb)
perl, python, ruby: Fix comments on call to close method.

Make the comments consistent.

Also make the Perl example call $g->close explicitly so it is
consistent with the other examples.
(cherry picked from commit 27ebf517fae972eee49ae5911a03fabe5f4b6e54)
close: Rearrange the order in which the handle is closed and freed.

The order is now:

 - remove the handle from the list of handles
 - send close trace message
 - sync and shutdown qemu
 - run user close callback
 - free temporary directory
 - free memory

This commit ought to be no functional change.

(cherry picked from commit fc3c6fff4b0a6ffeb75aa78b1d73241a14a03cd1)