From: Richard W.M. Jones <"Richard W.M. Jones "> Date: Mon, 11 Aug 2008 09:27:25 +0000 (+0100) Subject: Add --list-kernels option and add a warning to the generated files. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=98e6a54c9568aaa833c151ac3f39c3234efee126;p=virt-mem.git Add --list-kernels option and add a warning to the generated files. --- diff --git a/MANIFEST b/MANIFEST index 3b4557c..379fff3 100644 --- a/MANIFEST +++ b/MANIFEST @@ -24,6 +24,7 @@ lib/test_mmap.ml lib/virt_mem_capture.ml lib/virt_mem_kallsyms.ml lib/virt_mem_kallsyms.mli +lib/virt_mem_kernels.ml lib/virt_mem_ksyms.ml lib/virt_mem_ksyms.mli lib/virt_mem.ml diff --git a/extract/codegen/kerneldb_to_parser.ml b/extract/codegen/kerneldb_to_parser.ml index e1056c5..a3bb9a1 100644 --- a/extract/codegen/kerneldb_to_parser.ml +++ b/extract/codegen/kerneldb_to_parser.ml @@ -146,6 +146,8 @@ Example (from toplevel of virt-mem source tree): (basename, version, arch) ) infos in + let nr_kernels = List.length infos in + (* For quick access to the opener strings, build a hash. *) let openers = Hashtbl.create 13 in List.iter ( @@ -154,8 +156,10 @@ Example (from toplevel of virt-mem source tree): ) what; (* Now read the data files and parse out the structures of interest. *) - let datas = List.map ( - fun (basename, version, arch) -> + let kernels = List.mapi ( + fun i (basename, version, arch) -> + printf "Loading kernel data file %d/%d\r%!" (i+1) nr_kernels; + let file_exists name = try Unix.access name [Unix.F_OK]; true with Unix.Unix_error _ -> false @@ -342,7 +346,7 @@ Example (from toplevel of virt-mem source tree): in - let datas = List.map ( + let kernels = List.map ( fun (basename, version, arch, bodies) -> let structures = List.filter_map ( fun (struct_name, (_, _, _, wanted_fields)) -> @@ -385,7 +389,7 @@ Example (from toplevel of virt-mem source tree): ) what in (basename, version, arch, structures) - ) datas in + ) kernels in if debug then List.iter ( @@ -408,10 +412,36 @@ Example (from toplevel of virt-mem source tree): ) fields; printf " } /* %d bytes */\n\n" total_size; ) structures; - ) datas; + ) kernels; + + (* First output file is a simple list of kernels, to support the + * 'virt-mem --list-kernels' option. + *) + let () = + let _loc = Loc.ghost in + + let versions = List.map (fun (_, version, _, _) -> version) kernels in + + (* Sort them in reverse because we are going to generate the + * final list in reverse. + *) + let cmp a b = compare b a in + let versions = List.sort ~cmp versions in + + let xs = + List.fold_left (fun xs version -> <:expr< $str:version$ :: $xs$ >>) + <:expr< [] >> versions in + + let code = <:str_item< + let kernels = $xs$ + >> in + + let output_file = outputdir // "virt_mem_kernels.ml" in + printf "Writing list of kernels to %s ...\n%!" output_file; + Printers.OCaml.print_implem ~output_file code in (* We'll generate a code file for each structure type (eg. task_struct - * across all kernel versions), so rearrange 'datas' for that purpose. + * across all kernel versions), so rearrange 'kernels' for that purpose. * * XXX This loop is O(n^3), luckily n is small! *) @@ -423,7 +453,7 @@ Example (from toplevel of virt-mem source tree): fun (basename, version, arch, structures) -> try Some (basename, version, arch, List.assoc name structures) with Not_found -> None - ) datas in + ) kernels in (* Sort the kernels, which makes the generated output more stable * and makes patches more useful. @@ -433,7 +463,7 @@ Example (from toplevel of virt-mem source tree): name, kernels ) what in - let datas = () in ignore datas; (* garbage collect *) + let kernels = () in ignore kernels; (* garbage collect *) (* Get just the field types. It's plausible that a field with the * same name has a different type between kernel versions, so we must @@ -644,7 +674,6 @@ Example (from toplevel of virt-mem source tree): (* Code (.ml file). *) let code = <:str_item< - let warning = "This code is automatically generated from the kernel database by kerneldb-to-parser program. Any edits you make will be lost." let zero = 0 let struct_name = $str:struct_name$ let match_err = "failed to match kernel structure" @@ -707,6 +736,18 @@ Example (from toplevel of virt-mem source tree): let ichan = open_in new_output_file in let ochan = open_out output_file in + output_string ochan "\ +(* WARNING: This file and the corresponding mli (interface) are + * automatically generated by the extract/codegen/kerneldb_to_parser.ml + * program. + * + * Any edits you make to this file will be lost. + * + * To update this file from the latest kernel database, it is recommended + * that you do 'make update-kernel-structs'. + *) +"; + let rec loop () = let line = input_line ichan in let line = diff --git a/lib/.depend b/lib/.depend index e6a321a..99f71ba 100644 --- a/lib/.depend +++ b/lib/.depend @@ -27,12 +27,12 @@ virt_mem_ksyms.cmx: virt_mem_utils.cmx virt_mem_types.cmx virt_mem_mmap.cmx \ virt_mem_gettext.cmx virt_mem_ksyms.cmi virt_mem.cmo: virt_mem_version.cmo virt_mem_utsname.cmi virt_mem_utils.cmo \ virt_mem_types.cmi virt_mem_tasks.cmi virt_mem_mmap.cmi \ - virt_mem_ksyms.cmi virt_mem_kallsyms.cmi virt_mem_gettext.cmo \ - virt_mem.cmi + virt_mem_ksyms.cmi virt_mem_kernels.cmo virt_mem_kallsyms.cmi \ + virt_mem_gettext.cmo virt_mem.cmi virt_mem.cmx: virt_mem_version.cmx virt_mem_utsname.cmx virt_mem_utils.cmx \ virt_mem_types.cmx virt_mem_tasks.cmx virt_mem_mmap.cmx \ - virt_mem_ksyms.cmx virt_mem_kallsyms.cmx virt_mem_gettext.cmx \ - virt_mem.cmi + virt_mem_ksyms.cmx virt_mem_kernels.cmx virt_mem_kallsyms.cmx \ + virt_mem_gettext.cmx virt_mem.cmi virt_mem_mmap.cmo: virt_mem_utils.cmo virt_mem_mmap.cmi virt_mem_mmap.cmx: virt_mem_utils.cmx virt_mem_mmap.cmi virt_mem_tasks.cmo: virt_mem_utils.cmo virt_mem_types.cmi virt_mem_mmap.cmi \ diff --git a/lib/Makefile.in b/lib/Makefile.in index 35f4bf2..40ef195 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -49,6 +49,7 @@ TARGETS = virt_mem.cma virt_mem.cmxa OBJS = virt_mem_gettext.cmo \ virt_mem_version.cmo \ + virt_mem_kernels.cmo \ virt_mem_utils.cmo \ virt_mem_mmap_c.o \ virt_mem_mmap.cmo \ diff --git a/lib/kernel_net_device.ml b/lib/kernel_net_device.ml index 152df9c..df704d2 100644 --- a/lib/kernel_net_device.ml +++ b/lib/kernel_net_device.ml @@ -1,5 +1,12 @@ -let warning = - "This code is automatically generated from the kernel database by kerneldb-to-parser program. Any edits you make will be lost.";; +(* WARNING: This file and the corresponding mli (interface) are + * automatically generated by the extract/codegen/kerneldb_to_parser.ml + * program. + * + * Any edits you make to this file will be lost. + * + * To update this file from the latest kernel database, it is recommended + * that you do 'make update-kernel-structs'. + *) let zero = 0;; let struct_name = "net_device";; let match_err = "failed to match kernel structure";; diff --git a/lib/kernel_task_struct.ml b/lib/kernel_task_struct.ml index edef203..91a87f9 100644 --- a/lib/kernel_task_struct.ml +++ b/lib/kernel_task_struct.ml @@ -1,5 +1,12 @@ -let warning = - "This code is automatically generated from the kernel database by kerneldb-to-parser program. Any edits you make will be lost.";; +(* WARNING: This file and the corresponding mli (interface) are + * automatically generated by the extract/codegen/kerneldb_to_parser.ml + * program. + * + * Any edits you make to this file will be lost. + * + * To update this file from the latest kernel database, it is recommended + * that you do 'make update-kernel-structs'. + *) let zero = 0;; let struct_name = "task_struct";; let match_err = "failed to match kernel structure";; diff --git a/lib/virt_mem.ml b/lib/virt_mem.ml index 22cbbc5..ca89e32 100644 --- a/lib/virt_mem.ml +++ b/lib/virt_mem.ml @@ -239,6 +239,12 @@ Options:") cmd summary description in exit 0 in + (* Handle --list-kernels option. *) + let list_kernels () = + List.iter print_endline Virt_mem_kernels.kernels; + exit 0 + in + (* Function to collect up any anonymous args (domain names/IDs). *) let anon_arg str = anon_args := str :: !anon_args in @@ -264,6 +270,8 @@ Options:") cmd summary description in "uri " ^ s_ "Connect to URI"; "--debug", Arg.Set debug, " " ^ s_"Debug mode (default: false)"; + "--list-kernels", Arg.Unit list_kernels, + " " ^ s_"List known kernels"; "-t", Arg.String memory_image, "image " ^ s_"Use saved kernel memory image"; "--version", Arg.Unit version, diff --git a/lib/virt_mem_kernels.ml b/lib/virt_mem_kernels.ml new file mode 100644 index 0000000..14ce07a --- /dev/null +++ b/lib/virt_mem_kernels.ml @@ -0,0 +1,112 @@ +let kernels = + [ "2.6.18-1.2798.fc6.i586"; "2.6.18-1.2798.fc6.i686"; + "2.6.18-1.2798.fc6.i686"; "2.6.18-1.2798.fc6.i686"; + "2.6.18-1.2798.fc6.ppc"; "2.6.18-1.2798.fc6.ppc"; + "2.6.18-1.2798.fc6.ppc64"; "2.6.18-1.2798.fc6.ppc64"; + "2.6.18-1.2798.fc6.ppc64iseries"; "2.6.18-1.2798.fc6.ppc64iseries"; + "2.6.18-1.2798.fc6.x86_64"; "2.6.18-1.2798.fc6.x86_64"; + "2.6.18-1.2798.fc6.x86_64"; "2.6.20-1.2933.fc6.i586"; + "2.6.20-1.2933.fc6.i686"; "2.6.20-1.2933.fc6.i686"; + "2.6.20-1.2933.fc6.i686"; "2.6.20-1.2933.fc6.i686"; + "2.6.20-1.2933.fc6.i686"; "2.6.20-1.2933.fc6.i686"; + "2.6.20-1.2933.fc6.ppc"; "2.6.20-1.2933.fc6.ppc"; + "2.6.20-1.2933.fc6.ppc64"; "2.6.20-1.2933.fc6.ppc64"; + "2.6.20-1.2933.fc6.x86_64"; "2.6.20-1.2933.fc6.x86_64"; + "2.6.20-1.2933.fc6.x86_64"; "2.6.20-1.2933.fc6.x86_64"; + "2.6.21-1.3128.fc7.i586"; "2.6.21-1.3128.fc7.i686"; + "2.6.21-1.3128.fc7.i686"; "2.6.21-1.3128.fc7.ppc"; + "2.6.21-1.3128.fc7.ppc"; "2.6.21-1.3128.fc7.ppc64"; + "2.6.21-1.3128.fc7.ppc64"; "2.6.21-1.3128.fc7.x86_64"; + "2.6.21-1.3128.fc7.x86_64"; "2.6.21-1.3132.fc7.i586"; + "2.6.21-1.3132.fc7.i686"; "2.6.21-1.3132.fc7.i686"; + "2.6.21-1.3132.fc7.ppc"; "2.6.21-1.3132.fc7.ppc"; + "2.6.21-1.3132.fc7.ppc64"; "2.6.21-1.3132.fc7.ppc64"; + "2.6.21-1.3132.fc7.x86_64"; "2.6.21-1.3132.fc7.x86_64"; + "2.6.21-1.3141.fc7.i586"; "2.6.21-1.3141.fc7.i686"; + "2.6.21-1.3141.fc7.i686"; "2.6.21-1.3141.fc7.ppc"; + "2.6.21-1.3141.fc7.ppc"; "2.6.21-1.3141.fc7.ppc64"; + "2.6.21-1.3141.fc7.ppc64"; "2.6.21-1.3141.fc7.x86_64"; + "2.6.21-1.3141.fc7.x86_64"; "2.6.21-1.3144.fc7.i586"; + "2.6.21-1.3144.fc7.i686"; "2.6.21-1.3144.fc7.i686"; + "2.6.21-1.3144.fc7.ppc"; "2.6.21-1.3144.fc7.ppc"; + "2.6.21-1.3144.fc7.ppc64"; "2.6.21-1.3144.fc7.ppc64"; + "2.6.21-1.3144.fc7.x86_64"; "2.6.21-1.3144.fc7.x86_64"; + "2.6.21-1.3145.fc7.i586"; "2.6.21-1.3145.fc7.i686"; + "2.6.21-1.3145.fc7.i686"; "2.6.21-1.3145.fc7.i686"; + "2.6.21-1.3145.fc7.i686"; "2.6.21-1.3145.fc7.ppc"; + "2.6.21-1.3145.fc7.ppc"; "2.6.21-1.3145.fc7.ppc64"; + "2.6.21-1.3145.fc7.ppc64"; "2.6.21-1.3145.fc7.x86_64"; + "2.6.21-1.3145.fc7.x86_64"; "2.6.21-1.3145.fc7.x86_64"; + "2.6.21-1.3190.fc7.i586"; "2.6.21-1.3190.fc7.i686"; + "2.6.21-1.3190.fc7.i686"; "2.6.21-1.3190.fc7.i686"; + "2.6.21-1.3190.fc7.i686"; "2.6.21-1.3190.fc7.ppc"; + "2.6.21-1.3190.fc7.ppc"; "2.6.21-1.3190.fc7.ppc64"; + "2.6.21-1.3190.fc7.ppc64"; "2.6.21-1.3190.fc7.x86_64"; + "2.6.21-1.3190.fc7.x86_64"; "2.6.21-1.3190.fc7.x86_64"; + "2.6.21-1.3209.fc8.i586"; "2.6.21-1.3209.fc8.i686"; + "2.6.21-1.3209.fc8.i686"; "2.6.21-1.3209.fc8.ppc"; + "2.6.21-1.3209.fc8.ppc"; "2.6.21-1.3209.fc8.ppc64"; + "2.6.21-1.3209.fc8.ppc64"; "2.6.21-1.3209.fc8.x86_64"; + "2.6.21-1.3218.fc8.i586"; "2.6.21-1.3218.fc8.i686"; + "2.6.21-1.3218.fc8.i686"; "2.6.21-1.3218.fc8.ppc"; + "2.6.21-1.3218.fc8.ppc"; "2.6.21-1.3218.fc8.ppc64"; + "2.6.21-1.3218.fc8.ppc64"; "2.6.21-1.3218.fc8.x86_64"; + "2.6.21-1.3221.fc8.i586"; "2.6.21-1.3221.fc8.i686"; + "2.6.21-1.3221.fc8.i686"; "2.6.21-1.3221.fc8.ppc"; + "2.6.21-1.3221.fc8.ppc"; "2.6.21-1.3221.fc8.ppc64"; + "2.6.21-1.3221.fc8.ppc64"; "2.6.21-1.3221.fc8.x86_64"; + "2.6.21-1.3228.fc7.i586"; "2.6.21-1.3228.fc7.i686"; + "2.6.21-1.3228.fc7.i686"; "2.6.21-1.3228.fc7.i686"; + "2.6.21-1.3228.fc7.i686"; "2.6.21-1.3228.fc7.ppc"; + "2.6.21-1.3228.fc7.ppc"; "2.6.21-1.3228.fc7.ppc64"; + "2.6.21-1.3228.fc7.ppc64"; "2.6.21-1.3228.fc7.x86_64"; + "2.6.21-1.3228.fc7.x86_64"; "2.6.21-1.3228.fc7.x86_64"; + "2.6.21-1.3234.fc8.i686"; "2.6.21-1.3234.fc8.i686"; + "2.6.21-1.3234.fc8.ppc"; "2.6.21-1.3234.fc8.ppc"; + "2.6.21-1.3234.fc8.ppc64"; "2.6.21-1.3234.fc8.ppc64"; + "2.6.21-1.3234.fc8.x86_64"; "2.6.21-1.3236.fc8.i686"; + "2.6.21-1.3236.fc8.i686"; "2.6.21-1.3236.fc8.ppc"; + "2.6.21-1.3236.fc8.ppc"; "2.6.21-1.3236.fc8.ppc64"; + "2.6.21-1.3236.fc8.ppc64"; "2.6.21-1.3236.fc8.x86_64"; + "2.6.21-1.3238.fc8.i686"; "2.6.21-1.3238.fc8.i686"; + "2.6.21-1.3238.fc8.ppc"; "2.6.21-1.3238.fc8.ppc"; + "2.6.21-1.3238.fc8.ppc64"; "2.6.21-1.3238.fc8.ppc64"; + "2.6.21-1.3238.fc8.x86_64"; "2.6.21-1.3242.fc8.i686"; + "2.6.21-1.3242.fc8.i686"; "2.6.21-1.3242.fc8.ppc"; + "2.6.21-1.3242.fc8.ppc"; "2.6.21-1.3242.fc8.ppc64"; + "2.6.21-1.3242.fc8.ppc64"; "2.6.21-1.3242.fc8.x86_64"; + "2.6.22-0.23.rc7.git6.fc8.i686"; "2.6.22-0.23.rc7.git6.fc8.i686"; + "2.6.22-0.23.rc7.git6.fc8.ppc"; "2.6.22-0.23.rc7.git6.fc8.ppc"; + "2.6.22-0.23.rc7.git6.fc8.ppc64"; "2.6.22-0.23.rc7.git6.fc8.ppc64"; + "2.6.22-0.23.rc7.git6.fc8.x86_64"; "2.6.22-0.rc7.2.fc8.i686"; + "2.6.22-0.rc7.2.fc8.i686"; "2.6.22-0.rc7.2.fc8.ppc"; + "2.6.22-0.rc7.2.fc8.ppc"; "2.6.22-0.rc7.2.fc8.ppc64"; + "2.6.22-0.rc7.2.fc8.ppc64"; "2.6.22-0.rc7.2.fc8.x86_64"; + "2.6.23.14-135.fc8.i586"; "2.6.23.14-135.fc8.i686"; + "2.6.23.14-135.fc8.i686"; "2.6.23.14-135.fc8.i686"; + "2.6.23.14-135.fc8.i686"; "2.6.23.14-135.fc8.ppc"; + "2.6.23.14-135.fc8.ppc"; "2.6.23.14-135.fc8.ppc64"; + "2.6.23.14-135.fc8.ppc64"; "2.6.23.14-135.fc8.x86_64"; + "2.6.23.14-135.fc8.x86_64"; "2.6.23.14-78.fc7.i586"; + "2.6.23.14-78.fc7.i686"; "2.6.23.14-78.fc7.i686"; + "2.6.23.14-78.fc7.i686"; "2.6.23.14-78.fc7.ppc"; "2.6.23.14-78.fc7.ppc"; + "2.6.23.14-78.fc7.ppc64"; "2.6.23.14-78.fc7.ppc64"; + "2.6.23.14-78.fc7.x86_64"; "2.6.23.14-78.fc7.x86_64"; + "2.6.24-0.167.rc8.git4.fc9.i586"; "2.6.24-0.167.rc8.git4.fc9.i686"; + "2.6.24-0.167.rc8.git4.fc9.i686"; "2.6.24-0.167.rc8.git4.fc9.ppc"; + "2.6.24-0.167.rc8.git4.fc9.ppc"; "2.6.24-0.167.rc8.git4.fc9.ppc64"; + "2.6.24-0.167.rc8.git4.fc9.ppc64"; "2.6.24-0.167.rc8.git4.fc9.x86_64"; + "2.6.24-7.fc9.i586"; "2.6.24-7.fc9.i686"; "2.6.24-7.fc9.i686"; + "2.6.24-7.fc9.ppc"; "2.6.24-7.fc9.ppc"; "2.6.24-7.fc9.ppc64"; + "2.6.24-7.fc9.ppc64"; "2.6.24-7.fc9.x86_64"; "2.6.24-9.fc9.i586"; + "2.6.24-9.fc9.i686"; "2.6.24-9.fc9.i686"; "2.6.24-9.fc9.ppc"; + "2.6.24-9.fc9.ppc"; "2.6.24-9.fc9.ppc64"; "2.6.24-9.fc9.ppc64"; + "2.6.24-9.fc9.x86_64"; "2.6.25.11-97.fc9.i686"; + "2.6.25.11-97.fc9.x86_64"; "2.6.26.2-2.fc8.i586"; "2.6.26.2-2.fc8.i686"; + "2.6.26.2-2.fc8.i686"; "2.6.26.2-2.fc8.i686"; "2.6.26.2-2.fc8.i686"; + "2.6.26.2-2.fc8.ppc"; "2.6.26.2-2.fc8.ppc"; "2.6.26.2-2.fc8.ppc64"; + "2.6.26.2-2.fc8.ppc64"; "2.6.26.2-2.fc8.x86_64"; "2.6.26.2-2.fc8.x86_64"; + "2.6.27-0.244.rc2.git1.fc10.i586"; "2.6.27-0.244.rc2.git1.fc10.i686"; + "2.6.27-0.244.rc2.git1.fc10.i686"; "2.6.27-0.244.rc2.git1.fc10.ppc"; + "2.6.27-0.244.rc2.git1.fc10.ppc"; "2.6.27-0.244.rc2.git1.fc10.ppc64"; + "2.6.27-0.244.rc2.git1.fc10.ppc64"; "2.6.27-0.244.rc2.git1.fc10.x86_64" ];; diff --git a/virt-mem.1 b/virt-mem.1 index 0aa0cf1..33a3d24 100644 --- a/virt-mem.1 +++ b/virt-mem.1 @@ -132,7 +132,7 @@ .\" ======================================================================== .\" .IX Title "VIRT-MEM 1" -.TH VIRT-MEM 1 "2008-08-07" "virt-mem-0.2.9" "Virtualization Support" +.TH VIRT-MEM 1 "2008-08-11" "virt-mem-0.2.9" "Virtualization Support" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -214,6 +214,9 @@ report a bug. .IP "\fB\-\-help\fR" 4 .IX Item "--help" Display usage summary. +.IP "\fB\-\-list\-kernels\fR" 4 +.IX Item "--list-kernels" +List which guest kernel versions are known/supported, then exit. .IP "\fB\-t memoryimage\fR" 4 .IX Item "-t memoryimage" Post-mortem analysis mode. diff --git a/virt-mem.pod b/virt-mem.pod index 2b36d0e..1eec316 100644 --- a/virt-mem.pod +++ b/virt-mem.pod @@ -86,6 +86,10 @@ report a bug. Display usage summary. +=item B<--list-kernels> + +List which guest kernel versions are known/supported, then exit. + =item B<-t memoryimage> Post-mortem analysis mode. diff --git a/virt-mem.txt b/virt-mem.txt index a835d19..4300f9d 100644 --- a/virt-mem.txt +++ b/virt-mem.txt @@ -77,6 +77,9 @@ COMMON OPTIONS --help Display usage summary. + --list-kernels + List which guest kernel versions are known/supported, then exit. + -t memoryimage Post-mortem analysis mode.