From 71a7811fa9206cd94703f8f6554bba129699b66229c4a3cc1ee15d28a881065e Mon Sep 17 00:00:00 2001 From: Larry Dewey Date: Tue, 21 Jan 2020 18:57:34 +0000 Subject: [PATCH 1/3] Accepting request 766138 from home:ldewey:branches:Virtualization - Added patches to configure sparsify to ignore readonly images. (bsc#1161169, rhbz#1064041) OBS-URL: https://build.opensuse.org/request/show/766138 OBS-URL: https://build.opensuse.org/package/show/Virtualization/libguestfs?expand=0&rev=448 --- ...44-sparsify-ignore-read-only-devices.patch | 44 ++++++++++++ ...-readonly-btrfs-snapshots-RHBZ-10796.patch | 68 +++++++++++++++++++ libguestfs.changes | 6 ++ libguestfs.spec | 9 ++- 4 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 4bb3c44-sparsify-ignore-read-only-devices.patch create mode 100644 864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch diff --git a/4bb3c44-sparsify-ignore-read-only-devices.patch b/4bb3c44-sparsify-ignore-read-only-devices.patch new file mode 100644 index 0000000..fa409c2 --- /dev/null +++ b/4bb3c44-sparsify-ignore-read-only-devices.patch @@ -0,0 +1,44 @@ +From 4bb3c44a286beb0dd8cdf337d64d8ce71e361dd6 Mon Sep 17 00:00:00 2001 +From: Pino Toscano +Date: Mon, 2 Feb 2015 15:02:31 +0100 +Subject: [PATCH] sparsify: ignore read-only devices + +In copy mode, make sure to not zero-free-space devices mounted as +read-only, as we cannot write to them. + +Related to RHBZ#1079625. +--- + sparsify/copying.ml | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/sparsify/copying.ml b/sparsify/copying.ml +index 43f108bdc..9f788b94c 100644 +--- a/sparsify/copying.ml ++++ b/sparsify/copying.ml +@@ -235,6 +235,13 @@ You can ignore this warning or change it to a hard failure using the + with Not_found -> false + in + ++ let is_readonly_device mp = ++ let statvfs = g#statvfs mp in ++ let flags = statvfs.G.flag in ++ (* 0x01 is ST_RDONLY in Linux' GNU libc. *) ++ flags <> -1_L && (flags &^ 0x1_L) <> 0_L ++ in ++ + List.iter ( + fun fs -> + if not (is_ignored fs) && not (is_read_only_lv fs) then ( +@@ -252,6 +259,9 @@ You can ignore this warning or change it to a hard failure using the + if is_readonly_btrfs_snapshot fs "/" then ( + if not quiet then + printf (f_"Skipping %s, as it is a read-only btrfs snapshot.\n%!") fs; ++ ) else if is_readonly_device "/" then ( ++ if not quiet then ++ printf (f_"Skipping %s, as it is a read-only device.\n%!") fs; + ) else ( + if not quiet then + printf (f_"Fill free space in %s with zero ...\n%!") fs; +-- +2.24.1 + diff --git a/864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch b/864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch new file mode 100644 index 0000000..a9d0c1f --- /dev/null +++ b/864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch @@ -0,0 +1,68 @@ +From 864c2ee371f65388b18e737136663986cfc9eb08 Mon Sep 17 00:00:00 2001 +From: Pino Toscano +Date: Mon, 2 Feb 2015 14:50:52 +0100 +Subject: [PATCH] sparsify: ignore read-only btrfs snapshots (RHBZ#1079625) + +In copy mode, make sure to not zero-free-space read-only btrfs +snapshots, as we cannot write to them. +--- + sparsify/copying.ml | 28 +++++++++++++++++++++++++--- + 1 file changed, 25 insertions(+), 3 deletions(-) + +diff --git a/sparsify/copying.ml b/sparsify/copying.ml +index 165dd6e93..43f108bdc 100644 +--- a/sparsify/copying.ml ++++ b/sparsify/copying.ml +@@ -208,6 +208,11 @@ You can ignore this warning or change it to a hard failure using the + * and selected swap partitions. + *) + let filesystems = g#list_filesystems () in ++ let btrfs_filesystems = List.filter ( ++ fun (fs, fstype) -> ++ fstype = "btrfs" ++ ) filesystems in ++ let btrfs_filesystems = List.map fst btrfs_filesystems in + let filesystems = List.map fst filesystems in + let filesystems = List.sort compare filesystems in + +@@ -218,6 +223,18 @@ You can ignore this warning or change it to a hard failure using the + + let is_read_only_lv = is_read_only_lv g in + ++ let is_readonly_btrfs_snapshot fs mp = ++ try ++ let is_btrfs = List.mem fs btrfs_filesystems in ++ if is_btrfs then ( ++ try ++ let vol_info = g#btrfs_subvolume_show mp in ++ string_find (List.assoc "Flags" vol_info) "readonly" <> -1 ++ with G.Error _ -> false ++ ) else false ++ with Not_found -> false ++ in ++ + List.iter ( + fun fs -> + if not (is_ignored fs) && not (is_read_only_lv fs) then ( +@@ -232,10 +249,15 @@ You can ignore this warning or change it to a hard failure using the + with _ -> false in + + if mounted then ( +- if not quiet then +- printf (f_"Fill free space in %s with zero ...\n%!") fs; ++ if is_readonly_btrfs_snapshot fs "/" then ( ++ if not quiet then ++ printf (f_"Skipping %s, as it is a read-only btrfs snapshot.\n%!") fs; ++ ) else ( ++ if not quiet then ++ printf (f_"Fill free space in %s with zero ...\n%!") fs; + +- g#zero_free_space "/" ++ g#zero_free_space "/" ++ ) + ) else ( + let is_linux_x86_swap = + (* Look for the signature for Linux swap on i386. +-- +2.24.1 + diff --git a/libguestfs.changes b/libguestfs.changes index 5fffafe..3b534e8 100644 --- a/libguestfs.changes +++ b/libguestfs.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Tue Jan 21 18:54:11 UTC 2020 - Larry Dewey + +- Added patches to configure sparsify to ignore readonly images. + (bsc#1161169, rhbz#1064041) + ------------------------------------------------------------------- Tue Sep 10 09:59:19 UTC 2019 - Christophe Giboudeaux diff --git a/libguestfs.spec b/libguestfs.spec index 03753de..f64f32e 100644 --- a/libguestfs.spec +++ b/libguestfs.spec @@ -1,7 +1,7 @@ # # spec file for package libguestfs # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # Copyright (c) 2011 Michal Hrusecky # # All modifications and additions to the file contributed by third parties @@ -136,7 +136,7 @@ BuildRequires: hivex-devel BuildRequires: gtk2-devel %endif # -Url: http://libguestfs.org/ +URL: http://libguestfs.org/ BuildRoot: %{_tmppath}/%{name}-%{version}-build Summary: Compatibility package for guestfs-tools # Upstream patches @@ -147,6 +147,9 @@ Patch1: 0a55098f-builder-repository-fix-compute_short_id-for-sles-X.0.pa Patch2: fd43730e-error-with-uninstall-option-on-SUSE.patch Patch3: 70407cd622-inspection-Parse-os-release-opensuse-leap-as-opensus.patch Patch4: 28bd06227b-inspect-handle-os-release-opensuse-tumbleweed-as-ope.patch +Patch5: 864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch +Patch6: 4bb3c44-sparsify-ignore-read-only-devices.patch + # Pending upstram review Patch50: 0001-Introduce-a-wrapper-around-xmlParseURI.patch Patch51: 0002-common-extract-UTF-8-conversion-function.patch @@ -566,6 +569,8 @@ It can import a variety of guest operating systems from libvirt-managed hosts. %patch2 -p1 %patch3 -p1 %patch4 -p1 +%patch5 -p1 +%patch6 -p1 %patch50 -p1 %patch51 -p1 %patch52 -p1 From 7ea970047b634645ff63fd4158ef20abfd01fb4d93f08bf62fb62064d961b2bd Mon Sep 17 00:00:00 2001 From: Larry Dewey Date: Tue, 21 Jan 2020 19:38:19 +0000 Subject: [PATCH 2/3] Accepting request 766144 from home:ldewey:branches:Virtualization Removing previous commit. OBS-URL: https://build.opensuse.org/request/show/766144 OBS-URL: https://build.opensuse.org/package/show/Virtualization/libguestfs?expand=0&rev=449 --- ...44-sparsify-ignore-read-only-devices.patch | 44 ------------ ...-readonly-btrfs-snapshots-RHBZ-10796.patch | 68 ------------------- libguestfs.spec | 4 -- 3 files changed, 116 deletions(-) delete mode 100644 4bb3c44-sparsify-ignore-read-only-devices.patch delete mode 100644 864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch diff --git a/4bb3c44-sparsify-ignore-read-only-devices.patch b/4bb3c44-sparsify-ignore-read-only-devices.patch deleted file mode 100644 index fa409c2..0000000 --- a/4bb3c44-sparsify-ignore-read-only-devices.patch +++ /dev/null @@ -1,44 +0,0 @@ -From 4bb3c44a286beb0dd8cdf337d64d8ce71e361dd6 Mon Sep 17 00:00:00 2001 -From: Pino Toscano -Date: Mon, 2 Feb 2015 15:02:31 +0100 -Subject: [PATCH] sparsify: ignore read-only devices - -In copy mode, make sure to not zero-free-space devices mounted as -read-only, as we cannot write to them. - -Related to RHBZ#1079625. ---- - sparsify/copying.ml | 10 ++++++++++ - 1 file changed, 10 insertions(+) - -diff --git a/sparsify/copying.ml b/sparsify/copying.ml -index 43f108bdc..9f788b94c 100644 ---- a/sparsify/copying.ml -+++ b/sparsify/copying.ml -@@ -235,6 +235,13 @@ You can ignore this warning or change it to a hard failure using the - with Not_found -> false - in - -+ let is_readonly_device mp = -+ let statvfs = g#statvfs mp in -+ let flags = statvfs.G.flag in -+ (* 0x01 is ST_RDONLY in Linux' GNU libc. *) -+ flags <> -1_L && (flags &^ 0x1_L) <> 0_L -+ in -+ - List.iter ( - fun fs -> - if not (is_ignored fs) && not (is_read_only_lv fs) then ( -@@ -252,6 +259,9 @@ You can ignore this warning or change it to a hard failure using the - if is_readonly_btrfs_snapshot fs "/" then ( - if not quiet then - printf (f_"Skipping %s, as it is a read-only btrfs snapshot.\n%!") fs; -+ ) else if is_readonly_device "/" then ( -+ if not quiet then -+ printf (f_"Skipping %s, as it is a read-only device.\n%!") fs; - ) else ( - if not quiet then - printf (f_"Fill free space in %s with zero ...\n%!") fs; --- -2.24.1 - diff --git a/864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch b/864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch deleted file mode 100644 index a9d0c1f..0000000 --- a/864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch +++ /dev/null @@ -1,68 +0,0 @@ -From 864c2ee371f65388b18e737136663986cfc9eb08 Mon Sep 17 00:00:00 2001 -From: Pino Toscano -Date: Mon, 2 Feb 2015 14:50:52 +0100 -Subject: [PATCH] sparsify: ignore read-only btrfs snapshots (RHBZ#1079625) - -In copy mode, make sure to not zero-free-space read-only btrfs -snapshots, as we cannot write to them. ---- - sparsify/copying.ml | 28 +++++++++++++++++++++++++--- - 1 file changed, 25 insertions(+), 3 deletions(-) - -diff --git a/sparsify/copying.ml b/sparsify/copying.ml -index 165dd6e93..43f108bdc 100644 ---- a/sparsify/copying.ml -+++ b/sparsify/copying.ml -@@ -208,6 +208,11 @@ You can ignore this warning or change it to a hard failure using the - * and selected swap partitions. - *) - let filesystems = g#list_filesystems () in -+ let btrfs_filesystems = List.filter ( -+ fun (fs, fstype) -> -+ fstype = "btrfs" -+ ) filesystems in -+ let btrfs_filesystems = List.map fst btrfs_filesystems in - let filesystems = List.map fst filesystems in - let filesystems = List.sort compare filesystems in - -@@ -218,6 +223,18 @@ You can ignore this warning or change it to a hard failure using the - - let is_read_only_lv = is_read_only_lv g in - -+ let is_readonly_btrfs_snapshot fs mp = -+ try -+ let is_btrfs = List.mem fs btrfs_filesystems in -+ if is_btrfs then ( -+ try -+ let vol_info = g#btrfs_subvolume_show mp in -+ string_find (List.assoc "Flags" vol_info) "readonly" <> -1 -+ with G.Error _ -> false -+ ) else false -+ with Not_found -> false -+ in -+ - List.iter ( - fun fs -> - if not (is_ignored fs) && not (is_read_only_lv fs) then ( -@@ -232,10 +249,15 @@ You can ignore this warning or change it to a hard failure using the - with _ -> false in - - if mounted then ( -- if not quiet then -- printf (f_"Fill free space in %s with zero ...\n%!") fs; -+ if is_readonly_btrfs_snapshot fs "/" then ( -+ if not quiet then -+ printf (f_"Skipping %s, as it is a read-only btrfs snapshot.\n%!") fs; -+ ) else ( -+ if not quiet then -+ printf (f_"Fill free space in %s with zero ...\n%!") fs; - -- g#zero_free_space "/" -+ g#zero_free_space "/" -+ ) - ) else ( - let is_linux_x86_swap = - (* Look for the signature for Linux swap on i386. --- -2.24.1 - diff --git a/libguestfs.spec b/libguestfs.spec index f64f32e..1693294 100644 --- a/libguestfs.spec +++ b/libguestfs.spec @@ -147,8 +147,6 @@ Patch1: 0a55098f-builder-repository-fix-compute_short_id-for-sles-X.0.pa Patch2: fd43730e-error-with-uninstall-option-on-SUSE.patch Patch3: 70407cd622-inspection-Parse-os-release-opensuse-leap-as-opensus.patch Patch4: 28bd06227b-inspect-handle-os-release-opensuse-tumbleweed-as-ope.patch -Patch5: 864c2ee-sparsify-ignore-readonly-btrfs-snapshots-RHBZ-10796.patch -Patch6: 4bb3c44-sparsify-ignore-read-only-devices.patch # Pending upstram review Patch50: 0001-Introduce-a-wrapper-around-xmlParseURI.patch @@ -569,8 +567,6 @@ It can import a variety of guest operating systems from libvirt-managed hosts. %patch2 -p1 %patch3 -p1 %patch4 -p1 -%patch5 -p1 -%patch6 -p1 %patch50 -p1 %patch51 -p1 %patch52 -p1 From e746a46e6f7b453b0affabeb4b478b3c3b64482fa864e7189ca88a88d6271062 Mon Sep 17 00:00:00 2001 From: Charles Arnold Date: Thu, 19 Mar 2020 16:28:31 +0000 Subject: [PATCH 3/3] - bsc#1167131 - virt-v2v fails importing ubuntu 18.04 LTS ova 500acb15-v2v-linux-fix-kernel-detection-when-split-in-different-packages.patch OBS-URL: https://build.opensuse.org/package/show/Virtualization/libguestfs?expand=0&rev=450 --- ...ion-when-split-in-different-packages.patch | 101 ++++++++++++++++++ libguestfs.changes | 6 ++ libguestfs.spec | 8 +- 3 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 500acb15-v2v-linux-fix-kernel-detection-when-split-in-different-packages.patch diff --git a/500acb15-v2v-linux-fix-kernel-detection-when-split-in-different-packages.patch b/500acb15-v2v-linux-fix-kernel-detection-when-split-in-different-packages.patch new file mode 100644 index 0000000..26fd1cf --- /dev/null +++ b/500acb15-v2v-linux-fix-kernel-detection-when-split-in-different-packages.patch @@ -0,0 +1,101 @@ +Subject: v2v: linux: fix kernel detection when split in different packages +From: Pino Toscano ptoscano@redhat.com Tue May 22 10:46:21 2018 +0200 +Date: Tue May 22 10:46:21 2018 +0200: +Git: 500acb15f8f777e9fe99a60c4216daf84a92aae3 + +The current detection code for Linux kernels assumes that a kernel +package contains everything in it, i.e. the kernel itself, its modules, +and its configuration. However, since recent Ubuntu versions (e.g. +starting from 18.04) modules & config (with few more files) are split in +an own package, thus not detecting the modpath from installed vmlinuz +files. + +To overcome this situation, rework this detection a bit: +1) find the vmlinuz file as before, but then immediately make sure it + exists by stat'ing it +2) find the modules path from the package as before: +2a) if found, extract the version in the same step +2b) if not found, get the kernel version from the vmlinuz filename, + and use it to detect the modules path +3) check that the modules path exists + +The detection done in (2b) is based on the current packaging scheme +found in the most important Linux distributions (Fedora, RHEL, CentOS, +Debian, Ubuntu, openSUSE, AltLinux, and possibly more). The notable +exception is Arch Linux. + +As additional change, do not assume the config file is in the same +package as vmlinuz, but directly look into the filesystem using the +version we already have. + +diff --git a/v2v/linux_kernels.ml b/v2v/linux_kernels.ml +index c047d6deb..24f61429d 100644 +--- a/v2v/linux_kernels.ml ++++ b/v2v/linux_kernels.ml +@@ -103,27 +103,42 @@ let detect_kernels (g : G.guestfs) inspect family bootloader = + None + ) + else ( +- (* Which of these is the kernel itself? *) ++ (* Which of these is the kernel itself? Also, make sure to check ++ * it exists by stat'ing it. ++ *) + let vmlinuz = List.find ( + fun filename -> String.is_prefix filename "/boot/vmlinuz-" + ) files in +- (* Which of these is the modpath? *) +- let modpath = List.find ( +- fun filename -> +- String.length filename >= 14 && +- String.is_prefix filename "/lib/modules/" +- ) files in +- +- (* Check vmlinuz & modpath exist. *) +- if not (g#is_dir ~followsymlinks:true modpath) then +- raise Not_found; + let vmlinuz_stat = + try g#statns vmlinuz with G.Error _ -> raise Not_found in + +- (* Get/construct the version. XXX Read this from kernel file. *) +- let version = +- let prefix_len = String.length "/lib/modules/" in +- String.sub modpath prefix_len (String.length modpath - prefix_len) in ++ (* Determine the modpath from the package, falling back to the ++ * version in the vmlinuz file name. ++ *) ++ let modpath, version = ++ let prefix = "/lib/modules/" in ++ try ++ let prefix_len = String.length prefix in ++ List.find_map ( ++ fun filename -> ++ let filename_len = String.length filename in ++ if filename_len > prefix_len && ++ String.is_prefix filename prefix then ( ++ let version = String.sub filename prefix_len ++ (filename_len - prefix_len) in ++ Some (filename, version) ++ ) else ++ None ++ ) files ++ with Not_found -> ++ let version = ++ String.sub vmlinuz 14 (String.length vmlinuz - 14) in ++ let modpath = prefix ^ version in ++ modpath, version in ++ ++ (* Check that the modpath exists. *) ++ if not (g#is_dir ~followsymlinks:true modpath) then ++ raise Not_found; + + (* Find the initramfs which corresponds to the kernel. + * Since the initramfs is built at runtime, and doesn't have +@@ -188,7 +203,7 @@ let detect_kernels (g : G.guestfs) inspect family bootloader = + + let config_file = + let cfg = "/boot/config-" ^ version in +- if List.mem cfg files then Some cfg ++ if g#is_file ~followsymlinks:true cfg then Some cfg + else None in + + let kernel_supports what kconf = diff --git a/libguestfs.changes b/libguestfs.changes index 3b534e8..1436199 100644 --- a/libguestfs.changes +++ b/libguestfs.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Mar 19 10:25:01 MDT 2020 - carnold@suse.com + +- bsc#1167131 - virt-v2v fails importing ubuntu 18.04 LTS ova + 500acb15-v2v-linux-fix-kernel-detection-when-split-in-different-packages.patch + ------------------------------------------------------------------- Tue Jan 21 18:54:11 UTC 2020 - Larry Dewey diff --git a/libguestfs.spec b/libguestfs.spec index 1693294..2ff8a6e 100644 --- a/libguestfs.spec +++ b/libguestfs.spec @@ -1,7 +1,7 @@ # # spec file for package libguestfs # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany. # Copyright (c) 2011 Michal Hrusecky # # All modifications and additions to the file contributed by third parties @@ -13,7 +13,7 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# Please submit bugfixes or comments via http://bugs.opensuse.org/ # # needsbinariesforbuild @@ -136,7 +136,7 @@ BuildRequires: hivex-devel BuildRequires: gtk2-devel %endif # -URL: http://libguestfs.org/ +Url: http://libguestfs.org/ BuildRoot: %{_tmppath}/%{name}-%{version}-build Summary: Compatibility package for guestfs-tools # Upstream patches @@ -147,6 +147,7 @@ Patch1: 0a55098f-builder-repository-fix-compute_short_id-for-sles-X.0.pa Patch2: fd43730e-error-with-uninstall-option-on-SUSE.patch Patch3: 70407cd622-inspection-Parse-os-release-opensuse-leap-as-opensus.patch Patch4: 28bd06227b-inspect-handle-os-release-opensuse-tumbleweed-as-ope.patch +Patch5: 500acb15-v2v-linux-fix-kernel-detection-when-split-in-different-packages.patch # Pending upstram review Patch50: 0001-Introduce-a-wrapper-around-xmlParseURI.patch @@ -567,6 +568,7 @@ It can import a variety of guest operating systems from libvirt-managed hosts. %patch2 -p1 %patch3 -p1 %patch4 -p1 +%patch5 -p1 %patch50 -p1 %patch51 -p1 %patch52 -p1