mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
v2v: fix and implify the internal Convert_linux:discover_modpath
First check for the existence of the directory /etc/modprobe.d, in case using a file under it; this also skips all the other checks, since they are not needed at all. Also /etc/modprobe.d exists on recent Linux versions, so let's give priority to the more common methods. When /etc/modprobe.d does not exist, check for the file to edit using a single list of possible files, now in order of priority, where the first find is used without checking further for the rest. Also, make sure all the returned paths are absolute: they are used in Augeas paths later on, so relative paths will not do anything useful.
This commit is contained in:
@@ -1219,28 +1219,18 @@ let rec convert ~keep_serial_console (g : G.guestfs) inspect source rcaps =
|
||||
|
||||
and discover_modpath () =
|
||||
(* Find what /etc/modprobe.conf is called today. *)
|
||||
let modpath = ref "" in
|
||||
|
||||
(* Note that we're checking in ascending order of preference so
|
||||
* that the last discovered method will be chosen.
|
||||
*)
|
||||
List.iter (
|
||||
fun file ->
|
||||
if g#is_file ~followsymlinks:true file then
|
||||
modpath := file
|
||||
) [ "/etc/conf.modules"; "/etc/modules.conf" ];
|
||||
|
||||
if g#is_file ~followsymlinks:true "/etc/modprobe.conf" then
|
||||
modpath := "modprobe.conf";
|
||||
|
||||
if g#is_dir ~followsymlinks:true "/etc/modprobe.d" then
|
||||
if g#is_dir ~followsymlinks:true "/etc/modprobe.d" then (
|
||||
(* Create a new file /etc/modprobe.d/virt-v2v-added.conf. *)
|
||||
modpath := "modprobe.d/virt-v2v-added.conf";
|
||||
"/etc/modprobe.d/virt-v2v-added.conf"
|
||||
) else (
|
||||
(* List of methods, in order of preference. *)
|
||||
let paths = [ "/etc/modprobe.conf"; "/etc/modules.conf"; "/etc/conf.modules" ] in
|
||||
|
||||
if !modpath = "" then
|
||||
error (f_"unable to find any valid modprobe configuration file such as /etc/modprobe.conf");
|
||||
|
||||
!modpath
|
||||
try
|
||||
List.find (g#is_file ~followsymlinks:true) paths
|
||||
with Not_found ->
|
||||
error (f_"unable to find any valid modprobe configuration file such as /etc/modprobe.conf");
|
||||
)
|
||||
|
||||
and remap_block_devices block_type =
|
||||
(* This function's job is to iterate over boot configuration
|
||||
|
||||
Reference in New Issue
Block a user