[PATCH 1/2] canonical_device_name: Don't rewrite /dev/mdX as /dev/sdX (RHBZ#1414682).
by Richard W.M. Jones
The guestfs_canonical_device_name API was rewriting /dev/mdX as
/dev/sdX. This is wrong since (eg) /dev/sd0 is not a device name, so
if you pass the canonicalized name back to the API it will fail.
virt-v2v was one tool doing this.
---
src/canonical-name.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/canonical-name.c b/src/canonical-name.c
index ae7b468..d72768f 100644
--- a/src/canonical-name.c
+++ b/src/canonical-name.c
@@ -35,6 +35,7 @@ guestfs_impl_canonical_device_name (guestfs_h *g, const char *device)
/* /dev/hd etc. */
if (STRPREFIX (device, "/dev/") &&
strchr (device+5, '/') == NULL && /* not an LV name */
+ device[5] != 'm' && /* not /dev/md - RHBZ#1414682 */
((len = strcspn (device+5, "d")) > 0 && len <= 2)) {
ret = safe_asprintf (g, "/dev/sd%s", &device[5+len+1]);
}
--
2.9.3
7 years, 9 months
[PATCH 1/2] daemon: Fix part-to-dev when the partition name includes p<N>.
by Richard W.M. Jones
From: Pino Toscano <ptoscano(a)redhat.com>
If the device name ends with a number, Linux uses partition names of
the form <device>p<N>. Handle this case by knocking off the 'p'
character.
---
daemon/devsparts.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 5862ae2..b764f63 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -203,6 +203,9 @@ do_part_to_dev (const char *part)
return NULL;
}
+ if (part[n-1] == 'p')
+ n--;
+
char *r = strndup (part, n);
if (r == NULL) {
reply_with_perror ("strdup");
--
2.9.3
7 years, 9 months
[PATCH] lib: Use a common function to validate strings.
by Richard W.M. Jones
As discussed in the thread on validating $TERM, it would be good to
have a common function to do this. This is such a function.
The main advantage is it includes unit tests which the previous
functions did not.
Rich.
7 years, 9 months
[PATCH] aarch64: launch: direct: Use virtio-pci devices.
by Richard W.M. Jones
As discussed yesterday:
https://www.redhat.com/archives/libguestfs/2017-January/msg00040.html
qemu and the kernel now support virtio-pci on aarch64.
It turns out that no changes are required for the libvirt backend,
since with libvirt 3.0.0 the same XML will switch to using virtio-pci
over virtio-mmio. I have tested this on Fedora 25 with a
self-compiled libvirt 3.0.0 rc2.
However for the direct backend we do need a small change to stop using
virtio-mmio devices. In fact this simply makes aarch64 more like
x86_64.
I have mostly tested this by running 'make check-release' but I found
a few (unconnected) problems with that so I'm still running the checks
on this one. However it's a pretty simple and obvious change. I did
check that the max-disks test passes.
Rich.
7 years, 9 months
[PATCH] resize: support non-local output disks (RHBZ#1404182)
by Pino Toscano
Parse the output disk as URI, and use all its attributes just like
it is done for the input disk. The only change is that the fsync of the
output disk is limited now for local URIs only, since it will not work
with remote protocols.
---
resize/resize.ml | 43 +++++++++++++++++++++++++++++++------------
resize/virt-resize.pod | 6 +++---
2 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 19cd8df..7e16cb5 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -315,6 +315,13 @@ read the man page virt-resize(1).
error (f_"error parsing URI '%s'. Look for error messages printed above.")
infile in
+ (* outfile can be a URI. *)
+ let outfile =
+ try (outfile, URI.parse_uri outfile)
+ with Invalid_argument "URI.parse_uri" ->
+ error (f_"error parsing URI '%s'. Look for error messages printed above.")
+ outfile in
+
infile, outfile, align_first, alignment, copy_boot_loader,
deletes,
dryrun, expand, expand_content, extra_partition, format, ignores,
@@ -333,9 +340,12 @@ read the man page virt-resize(1).
server = server; username = username;
password = password } = infile in
g#add_drive ?format ~readonly:true ~protocol ?server ?username ?secret:password path;
+ let _, { URI.path = path; protocol = protocol;
+ server = server; username = username;
+ password = password } = outfile in
(* The output disk is being created, so use cache=unsafe here. *)
g#add_drive ?format:output_format ~readonly:false ~cachemode:"unsafe"
- outfile;
+ ~protocol ?server ?username ?secret:password path;
if not (quiet ()) then Progress.set_up_progress_bar ~machine_readable g;
g#launch ();
@@ -368,7 +378,7 @@ read the man page virt-resize(1).
let insize = g#blockdev_getsize64 "/dev/sda" in
let outsize = g#blockdev_getsize64 "/dev/sdb" in
debug "%s size %Ld bytes" (fst infile) insize;
- debug "%s size %Ld bytes" outfile outsize;
+ debug "%s size %Ld bytes" (fst outfile) outsize;
sectsize, insize, outsize in
let max_bootloader =
@@ -390,7 +400,7 @@ read the man page virt-resize(1).
(fst infile) insize;
if outsize < Int64.of_int max_bootloader then
error (f_"%s: file is too small to be a disk image (%Ld bytes)")
- outfile outsize;
+ (fst outfile) outsize;
(* Get the source partition type. *)
let parttype, parttype_string =
@@ -983,7 +993,7 @@ read the man page virt-resize(1).
(* Try hard to initialize the partition table. This might involve
* relaunching another handle.
*)
- message (f_"Setting up initial partition table on %s") outfile;
+ message (f_"Setting up initial partition table on %s") (fst outfile);
let last_error = ref "" in
let rec initialize_partition_table g attempts =
@@ -1300,9 +1310,12 @@ read the man page virt-resize(1).
g#close ();
let g = open_guestfs () in
+ let _, { URI.path = path; protocol = protocol;
+ server = server; username = username;
+ password = password } = outfile in
(* The output disk is being created, so use cache=unsafe here. *)
g#add_drive ?format:output_format ~readonly:false ~cachemode:"unsafe"
- outfile;
+ ~protocol ?server ?username ?secret:password path;
if not (quiet ()) then Progress.set_up_progress_bar ~machine_readable g;
g#launch ();
@@ -1378,13 +1391,19 @@ read the man page virt-resize(1).
g#shutdown ();
g#close ();
- (* Because we used cache=unsafe when writing the output file, the
- * file might not be committed to disk. This is a problem if qemu is
- * immediately used afterwards with cache=none (which uses O_DIRECT
- * and therefore bypasses the host cache). In general you should not
- * use cache=none.
- *)
- Fsync.file outfile;
+ (* Try to sync the destination disk only if it is a local file. *)
+ let () =
+ let _, { URI.protocol = protocol; path = path } = outfile in
+ match protocol with
+ | "" | "file" ->
+ (* Because we used cache=unsafe when writing the output file, the
+ * file might not be committed to disk. This is a problem if qemu is
+ * immediately used afterwards with cache=none (which uses O_DIRECT
+ * and therefore bypasses the host cache). In general you should not
+ * use cache=none.
+ *)
+ Fsync.file path
+ | _ -> () in
if not (quiet ()) then (
print_newline ();
diff --git a/resize/virt-resize.pod b/resize/virt-resize.pod
index 2344056..98c4b10 100644
--- a/resize/virt-resize.pod
+++ b/resize/virt-resize.pod
@@ -121,9 +121,9 @@ Or use L<virsh(1)> vol-create-as to create a libvirt storage volume:
=item 5. Resize
-virt-resize takes two mandatory parameters, the input disk
-(eg. device, file, or a URI to a remote disk) and the output disk.
-The output disk is the one created in the previous step.
+virt-resize takes two mandatory parameters, the input disk and the
+output disk (both can be e.g. a device, a file, or a URI to a remote
+disk). The output disk is the one created in the previous step.
# virt-resize indisk outdisk
--
2.7.4
7 years, 9 months
[PATCH 0/3] library: improve handling of external tools
by Pino Toscano
Hi,
the libguestfs library uses a number of external tools; for some of
them, we search for them at build time, enabling some feature only if
found, and later on assuming at runtime they are installed. However,
the situation is more complex than that:
- hardcoding the full path means that there is an incoherency in the
way some of the tools are used, as some other tools (e.g. qemu-img)
are just run as assumed to be in $PATH; also hardcoding means
libguestfs cannot use different versions of those tools
- some of the tools are actually optional, and their runtime lack can
be handled gracefully instead of throwing a "failed to execute" error
The chosen approach is to build a process-wide cache in the libguestfs
library of paths of tools searched, even in case they are not available:
this way it is easier to just skip something at runtime if a program is
not there. The patch series applies it for the libdb tools, and for
the tools used to extract icons from guests.
Thanks,
Pino Toscano (3):
lib: add internal cache for external application
lib: improve libdb tools handling at runtime (RHBZ#1409024)
inspect: make netpbm and icoutils really optional runtime tools
m4/guestfs-find-db-tool.m4 | 2 +-
m4/guestfs_progs.m4 | 24 ------
src/Makefile.am | 1 +
src/external-apps.c | 190 +++++++++++++++++++++++++++++++++++++++++++++
src/guestfs-internal.h | 3 +
src/inspect-apps.c | 14 +++-
src/inspect-icon.c | 54 +++++++------
7 files changed, 237 insertions(+), 51 deletions(-)
create mode 100644 src/external-apps.c
--
2.7.4
7 years, 9 months