diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-07-25 14:17:42 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-07-25 14:47:15 +0100 |
commit | 2b59b5f1d2e36b0ef84b7c7c9ab2c4b602f2ad91 (patch) | |
tree | 8aefb9bc2bfb2eee1f851bfdc4655e4dada14777 /sysprep/sysprep_operation.ml | |
parent | 1fb95e65661f19c050b928694f750f2406eff2ac (diff) | |
download | libguestfs-2b59b5f1d2e36b0ef84b7c7c9ab2c4b602f2ad91.tar.gz libguestfs-2b59b5f1d2e36b0ef84b7c7c9ab2c4b602f2ad91.tar.xz libguestfs-2b59b5f1d2e36b0ef84b7c7c9ab2c4b602f2ad91.zip |
sysprep: Change perform callback to perform_on_filesystems and perform_on_devices.
Operations that need to work directly on guest block devices will fail
because the block devices are busy. Therefore add a phase with the
filesystems unmounted, and allow operations to specify that they need
to work in this phase.
Diffstat (limited to 'sysprep/sysprep_operation.ml')
-rw-r--r-- | sysprep/sysprep_operation.ml | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml index e22d3a2b..24b868c5 100644 --- a/sysprep/sysprep_operation.ml +++ b/sysprep/sysprep_operation.ml @@ -24,13 +24,16 @@ open Sysprep_gettext.Gettext type flag = [ `Created_files ] +type callback = Guestfs.guestfs -> string -> flag list + type operation = { name : string; enabled_by_default : bool; heading : string; pod_description : string option; extra_args : ((Arg.key * Arg.spec * Arg.doc) * string) list; - perform : Guestfs.guestfs -> string -> flag list; + perform_on_filesystems : callback option; + perform_on_devices : callback option; } let all_operations = ref [] @@ -189,7 +192,28 @@ let list_operations () = op.heading ) !all_operations -let perform_operations ?operations ?(quiet = false) g root = +let perform_operations_on_filesystems ?operations ?(quiet = false) g root = + assert !baked; + + let ops = + match operations with + | None -> !enabled_by_default_operations + | Some opset -> (* just the operation names listed *) + OperationSet.elements opset in + + let flags = + List.map ( + function + | { name = name; perform_on_filesystems = Some fn } -> + if not quiet then + printf "Performing %S ...\n%!" name; + fn g root + | { perform_on_filesystems = None } -> [] + ) ops in + + List.flatten flags + +let perform_operations_on_devices ?operations ?(quiet = false) g root = assert !baked; let ops = @@ -200,10 +224,12 @@ let perform_operations ?operations ?(quiet = false) g root = let flags = List.map ( - fun op -> + function + | { name = name; perform_on_devices = Some fn } -> if not quiet then - printf "Performing %S ...\n%!" op.name; - op.perform g root + printf "Performing %S ...\n%!" name; + fn g root + | { perform_on_devices = None } -> [] ) ops in List.flatten flags |