[PATCH v2] filesystems: don't try to get the size of btrfs subvolume
by Cédric Bosdonnat
virt-filesystem -l tries to get the size of btrfs subvolumes, which
results in an error. Teach it to skip the subvolumes.
---
cat/filesystems.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/cat/filesystems.c b/cat/filesystems.c
index f1c2852..cfdac86 100644
--- a/cat/filesystems.c
+++ b/cat/filesystems.c
@@ -476,9 +476,28 @@ do_output_filesystems (void)
}
}
if ((columns & COLUMN_SIZE)) {
- size = guestfs_blockdev_getsize64 (g, fses[i]);
- if (size == -1)
+ CLEANUP_FREE char *device = guestfs_mountable_device (g, fses[i]);
+ CLEANUP_FREE char *subvolume = NULL;
+
+ guestfs_push_error_handler (g, NULL, NULL);
+
+ subvolume = guestfs_mountable_subvolume (g, fses[i]);
+ if (subvolume == NULL && guestfs_last_errno (g) != EINVAL) {
+ fprintf (stderr,
+ _("%s: cannot determine the subvolume for %s: %s: %s\n"),
+ guestfs_int_program_name, fses[i],
+ guestfs_last_error (g),
+ strerror (guestfs_last_errno (g)));
exit (EXIT_FAILURE);
+ }
+
+ guestfs_pop_error_handler (g);
+
+ if (!device || !subvolume) {
+ size = guestfs_blockdev_getsize64 (g, fses[i]);
+ if (size == -1)
+ exit (EXIT_FAILURE);
+ }
}
if (is_md (fses[i]))
--
2.6.6
8 years, 6 months
[PATCH 2/3] Convert source so it can be compiled with OCaml '-safe-string' option.
by Richard W.M. Jones
OCaml 4.02 introduced the 'bytes' type, a mutable string intended to
replace the existing 'string' type for those cases where the byte
array can be mutated. In future the 'string' type will become
immutable. This is not the default now, but it can be forced using
the '-safe-string' compile option.
I tested this on Fedora 24 (OCaml 4.02) & RHEL 7 (OCaml 4.01).
Rich.
8 years, 6 months
[PATCH] mllib: Use Unix.F_OK instead of plain F_OK.
by Richard W.M. Jones
Removes this warning:
File "common_utils.ml", line 826, characters 24-28:
Warning 40: F_OK was selected from type Unix.access_permission.
It is not visible in the current scope, and will not
be selected if the type becomes unknown.
---
mllib/common_utils.ml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 8e9f943..64bf3d3 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -823,7 +823,7 @@ let is_partition dev =
let major = Dev_t.major rdev in
let minor = Dev_t.minor rdev in
let path = sprintf "/sys/dev/block/%d:%d/partition" major minor in
- Unix.access path [F_OK];
+ Unix.access path [Unix.F_OK];
true
)
with Unix.Unix_error _ -> false
--
2.7.4
8 years, 6 months
[PATCH] generator: Remove unnecessary 'chars' function.
by Richard W.M. Jones
String.make can be used instead, and that function has been around
since at least RHEL 6 era OCaml.
---
generator/utils.ml | 9 +--------
generator/utils.mli | 3 ---
2 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/generator/utils.ml b/generator/utils.ml
index 34edf9d..6fb04dc 100644
--- a/generator/utils.ml
+++ b/generator/utils.ml
@@ -356,14 +356,7 @@ let pod2text ?width ?(trim = true) ?(discard = true) name longdesc =
(* Compare two actions (for sorting). *)
let action_compare { name = n1 } { name = n2 } = compare n1 n2
-let chars c n =
- let str = String.create n in
- for i = 0 to n-1 do
- String.unsafe_set str i c
- done;
- str
-
-let spaces n = chars ' ' n
+let spaces n = String.make n ' '
let args_of_optargs optargs =
List.map (
diff --git a/generator/utils.mli b/generator/utils.mli
index aec1f71..41dd47d 100644
--- a/generator/utils.mli
+++ b/generator/utils.mli
@@ -123,9 +123,6 @@ val pod2text : ?width:int -> ?trim:bool -> ?discard:bool -> string -> string ->
val action_compare : Types.action -> Types.action -> int
(** Compare the names of two actions, for sorting. *)
-val chars : char -> int -> string
-(** [chars c n] creates a string containing character c repeated n times. *)
-
val spaces : int -> string
(** [spaces n] creates a string of n spaces. *)
--
2.7.4
8 years, 6 months
[PATCH supermin] init: Delete initramfs files before chrooting into the appliance.
by Richard W.M. Jones
After supermin has finished running, the initramfs files sit around
occupying swappable memory but serving no further purpose.
This saves a little memory, at the cost of about 1ms of extra boot
time.
---
init/init.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 48 insertions(+), 2 deletions(-)
diff --git a/init/init.c b/init/init.c
index 733d66e..5ac53e9 100644
--- a/init/init.c
+++ b/init/init.c
@@ -1,5 +1,5 @@
/* supermin-helper reimplementation in C.
- * Copyright (C) 2009-2014 Red Hat Inc.
+ * Copyright (C) 2009-2016 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -80,6 +80,7 @@ static void mount_proc (void);
static void print_uptime (void);
static void read_cmdline (void);
static void insmod (const char *filename);
+static void delete_initramfs_files (void);
static void show_directory (const char *dir);
static char cmdline[1024];
@@ -264,9 +265,12 @@ main ()
exit (EXIT_FAILURE);
}
+ if (!quiet)
+ fprintf (stderr, "supermin: deleting initramfs files\n");
+ delete_initramfs_files ();
+
/* Note that pivot_root won't work. See the note in
* Documentation/filesystems/ramfs-rootfs-initramfs.txt
- * We could remove the old initramfs files, but let's not bother.
*/
if (!quiet)
fprintf (stderr, "supermin: chroot\n");
@@ -396,6 +400,48 @@ read_cmdline (void)
cmdline[len-1] = '\0';
}
+/* By deleting the files in the initramfs before we chroot, we save a
+ * little bit of memory (or quite a lot of memory if the user is using
+ * unstripped kmods).
+ *
+ * We only delete files in the root directory. We don't delete
+ * directories because they only take a tiny amount of space and
+ * because we must not delete any mountpoints, especially not /root
+ * where we are about to chroot.
+ *
+ * We don't recursively look for files because that would be too
+ * complex and risky, and the normal supermin initramfs doesn't have
+ * any files except in the root directory.
+ */
+static void
+delete_initramfs_files (void)
+{
+ DIR *dir;
+ struct dirent *d;
+ struct stat statbuf;
+
+ if (chdir ("/") == -1) {
+ perror ("chdir: /");
+ return;
+ }
+
+ dir = opendir (".");
+ if (!dir) {
+ perror ("opendir: /");
+ return;
+ }
+
+ while ((d = readdir (dir)) != NULL) {
+ /* "." and ".." are directories, so the S_ISREG test ignores them. */
+ if (lstat (d->d_name, &statbuf) >= 0 && S_ISREG (statbuf.st_mode)) {
+ if (unlink (d->d_name) == -1)
+ perror (d->d_name);
+ }
+ }
+
+ closedir (dir);
+}
+
/* Display a directory on stderr. This is used for debugging only. */
static char
dirtype (int dt)
--
2.7.4
8 years, 6 months
[PATCH] v2v: OVF: Add new <Origin/> values for virt-p2v and HyperV.
by Richard W.M. Jones
See proposed change to oVirt: https://gerrit.ovirt.org/#/c/59147/
and RHBZ#1342398.
Thanks: Shahar Havivi
---
v2v/OVF.ml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/v2v/OVF.ml b/v2v/OVF.ml
index 6d24d97..95e4e9f 100644
--- a/v2v/OVF.ml
+++ b/v2v/OVF.ml
@@ -186,11 +186,15 @@ and get_ostype = function
(* Set the <Origin/> element based on the source hypervisor.
* https://bugzilla.redhat.com/show_bug.cgi?id=1342398#c6
+ * https://gerrit.ovirt.org/#/c/59147/
+ * ovirt-engine.git: backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/OriginType.java
*)
let origin_of_source_hypervisor = function
| VMware -> Some 1
| Xen -> Some 2
| QEmu | KVM -> Some 7
+ | Physical -> Some 8
+ | HyperV -> Some 9
(* Anything else is mapped to None, which causes the <Origin/>
* element to be omitted from the OVF output, which causes oVirt
--
2.7.4
8 years, 6 months
[PATCH v2 0/2] Reset the graphics mode in UEFI BCD
by Pavel Butsykin
Guest tools for Windows in Parallels / Virtuozzo Server 6 contain a
paravirtualized video driver, which wants to take full control of the video
mode. To avoid excessive video mode switches in UEFI VMs it executes
"bcdedit /set {current} graphicsmodedisabled true".
When such a VM is imported into a QEMU/KVM-based hypervisor, the standard video
drivers in Windows do not set the video mode as they expect it to have already
been configured by the bootloader. As a result, the VM runs with black screen.
To solve this issue, we need to try to lead the BCD to the default state.
Changes from v1:
- replaced i_uefi bool to a new i_firmware (1)
Pavel Butsykin (2):
v2v: fill the list of the EFI system partitions
v2v: remove the 'graphicsmodedisabled' entry in ESP BCD
v2v/convert_linux.ml | 7 +++----
v2v/convert_windows.ml | 41 +++++++++++++++++++++++++++++++++++++++++
v2v/inspect_source.ml | 34 +++++++++++++++++++++-------------
v2v/types.ml | 12 +++++++++---
v2v/types.mli | 8 +++++++-
v2v/v2v.ml | 5 ++++-
v2v/v2v_unit_tests.ml | 2 +-
7 files changed, 86 insertions(+), 23 deletions(-)
--
2.8.3
8 years, 6 months
[PATCH 0/2] Uninstall Parallels Tools for Linux
by Pavel Butsykin
Pavel Butsykin (2):
increase the default memory size to 768 MB
v2v: linux: uninstall Parallels tools
src/guestfs-internal.h | 2 +-
v2v/convert_linux.ml | 15 +++++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
--
2.8.3
8 years, 6 months
[PATCH v2] sysprep: Add --network to enable the network (RHBZ#1345813).
by Richard W.M. Jones
In commit ae6f726ecc3bc1b67fd76e51a7b1e1a33d4dcfc0 we started to use
the virt-customize code to replace various virt-sysprep operations.
This had the effect of adding many more possible operations to
virt-sysprep, but some of them (specifically --install) did not work
unless the appliance network is enabled. It was not enabled in
virt-sysprep, so these operations never worked.
This change does NOT enable the network by default. However it adds a
--network flag which may be used in conjunction with --install etc to
make those commands work.
In addition we now emit a warning for certain customize operations if
they fail and if the network is not enabled. It will print:
[ 4.5] Installing packages: tcpdump
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock error was
virt-sysprep: warning: the command may have failed because the network is
disabled. Try either removing '--no-network' or adding '--network' on the
command line.
virt-sysprep: error: yum -y install 'tcpdump': command exited with an error
(If the network is already enabled, or if the command is successful,
then the warning is not printed.)
Thanks: Xianghua Chen
---
customize/customize_run.ml | 22 ++++++++++++++--------
sysprep/main.ml | 5 +++++
sysprep/virt-sysprep.pod | 13 +++++++++++++
3 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index d4950a2..b96e40c 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -50,7 +50,7 @@ let run (g : Guestfs.guestfs) root (ops : ops) =
warning (f_"log file %s: %s (ignored)") logfile (Printexc.to_string exn) in
(* Useful wrapper for scripts. *)
- let do_run ~display cmd =
+ let do_run ~display ?(warn_failed_no_network = false) cmd =
if not guest_arch_compatible then
error (f_"host cpu (%s) and guest arch (%s) are not compatible, so you cannot use command line options that involve running commands in the guest. Use --firstboot scripts instead.")
Guestfs_config.host_cpu guest_arch;
@@ -90,6 +90,11 @@ exec >>%s 2>&1
with
Guestfs.Error msg ->
debug_logfile ();
+ if warn_failed_no_network && not (g#get_network ()) then (
+ prerr_newline ();
+ warning (f_"the command may have failed because the network is disabled. Try either removing '--no-network' or adding '--network' on the command line.");
+ prerr_newline ()
+ );
error (f_"%s: command exited with an error") display
in
@@ -263,7 +268,7 @@ exec >>%s 2>&1
| `InstallPackages pkgs ->
message (f_"Installing packages: %s") (String.concat " " pkgs);
let cmd = guest_install_command pkgs in
- do_run ~display:cmd cmd
+ do_run ~display:cmd ~warn_failed_no_network:true cmd
| `Link (target, links) ->
List.iter (
@@ -300,11 +305,11 @@ exec >>%s 2>&1
| Subscription_manager.PoolAuto ->
message (f_"Attaching to compatible subscriptions");
let cmd = "subscription-manager attach --auto" in
- do_run ~display:cmd cmd
+ do_run ~display:cmd ~warn_failed_no_network:true cmd
| Subscription_manager.PoolId id ->
message (f_"Attaching to the pool %s") id;
let cmd = sprintf "subscription-manager attach --pool=%s" (quote id) in
- do_run ~display:cmd cmd
+ do_run ~display:cmd ~warn_failed_no_network:true cmd
)
| `SMRegister ->
@@ -317,17 +322,18 @@ exec >>%s 2>&1
let cmd = sprintf "subscription-manager register --username=%s --password=%s"
(quote creds.Subscription_manager.sm_username)
(quote creds.Subscription_manager.sm_password) in
- do_run ~display:"subscription-manager register" cmd
+ do_run ~display:"subscription-manager register"
+ ~warn_failed_no_network:true cmd
| `SMRemove ->
message (f_"Removing all the subscriptions");
let cmd = "subscription-manager remove --all" in
- do_run ~display:cmd cmd
+ do_run ~display:cmd ~warn_failed_no_network:true cmd
| `SMUnregister ->
message (f_"Unregistering with subscription-manager");
let cmd = "subscription-manager unregister" in
- do_run ~display:cmd cmd
+ do_run ~display:cmd ~warn_failed_no_network:true cmd
| `SSHInject (user, selector) ->
(match g#inspect_get_type root with
@@ -362,7 +368,7 @@ exec >>%s 2>&1
| `Update ->
message (f_"Updating packages");
let cmd = guest_update_command () in
- do_run ~display:cmd cmd
+ do_run ~display:cmd ~warn_failed_no_network:true cmd
| `Upload (path, dest) ->
message (f_"Uploading: %s to %s") path dest;
diff --git a/sysprep/main.ml b/sysprep/main.ml
index 6f331b5..35a259c 100644
--- a/sysprep/main.ml
+++ b/sysprep/main.ml
@@ -40,6 +40,7 @@ let main () =
let files = ref [] in
let libvirturi = ref "" in
let mount_opts = ref "" in
+ let network = ref false in
let operations = ref None in
let format = ref "auto" in
@@ -131,6 +132,8 @@ let main () =
"--format", Arg.String set_format, s_"format" ^ " " ^ s_"Set format (default: auto)";
"--list-operations", Arg.Unit list_operations, " " ^ s_"List supported operations";
"--mount-options", Arg.Set_string mount_opts, s_"opts" ^ " " ^ s_"Set mount options (eg /:noatime;/var:rw,noatime)";
+ "--network", Arg.Set network, " " ^ s_"Enable appliance network";
+ "--no-network", Arg.Clear network, " " ^ s_"Disable appliance network (default)";
"--no-selinux-relabel", Arg.Unit (fun () -> ()),
" " ^ s_"Compatibility option, does nothing";
"--operation", Arg.String set_operations, " " ^ s_"Enable/disable specific operations";
@@ -192,6 +195,7 @@ read the man page virt-sysprep(1).
(* Dereference the rest of the args. *)
let dryrun = !dryrun in
+ let network = !network in
let operations = !operations in
(* At this point we know which operations are enabled. So call the
@@ -212,6 +216,7 @@ read the man page virt-sysprep(1).
(* Connect to libguestfs. *)
let g = open_guestfs () in
+ g#set_network network;
add g dryrun;
g#launch ();
diff --git a/sysprep/virt-sysprep.pod b/sysprep/virt-sysprep.pod
index d86b1e4..0c1c7c6 100644
--- a/sysprep/virt-sysprep.pod
+++ b/sysprep/virt-sysprep.pod
@@ -219,6 +219,19 @@ Don't print log messages.
To enable detailed logging of individual file operations, use I<-x>.
+=item B<--network>
+
+=item B<--no-network>
+
+Enable or disable network access from the guest during the installation.
+
+In virt-sysprep, the network is I<disabled> by default. You must use
+I<--network> to enable it, in order that options such as I<--install>
+or I<--update> will work.
+
+L<virt-builder(1)> has more information about the security advantages
+of disabling the network.
+
=item B<-v>
=item B<--verbose>
--
2.7.4
8 years, 6 months
[PATCH v7 0/5] New API: filesystem_walk
by Matteo Cafasso
v7:
- iterate over output file instead of reading it into memory
Instead of reading the whole output file in memory and iterating over
the resulting buffer, use XDR primitives to directly iterate over
the file itself.
This should reduce the API memory consumption.
Patch ready for review. Code available at:
https://github.com/noxdafox/libguestfs/tree/filesystem_walk
Matteo Cafasso (5):
generator: Added tsk_dirent struct
New API: internal_filesystem_walk
configure: Added libtsk compile-time check
New API: filesystem_walk
lib: Added filesystem_walk command tests
daemon/Makefile.am | 4 +-
daemon/tsk.c | 249 ++++++++++++++++++++++++++++++++++++++
docs/guestfs-building.pod | 4 +
generator/actions.ml | 117 ++++++++++++++++++
generator/structs.ml | 13 ++
m4/guestfs_daemon.m4 | 8 ++
src/MAX_PROC_NR | 2 +-
src/Makefile.am | 1 +
src/tsk.c | 129 ++++++++++++++++++++
tests/tsk/Makefile.am | 3 +-
tests/tsk/test-filesystem-walk.sh | 64 ++++++++++
11 files changed, 591 insertions(+), 3 deletions(-)
create mode 100644 daemon/tsk.c
create mode 100644 src/tsk.c
create mode 100755 tests/tsk/test-filesystem-walk.sh
--
2.8.1
8 years, 6 months