1 (* Memory info command for virtual domains.
2 (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 Implements 'virt-mem capture' command.
25 module D = Libvirt.Domain
28 open Virt_mem_gettext.Gettext
30 (* This will contain what is passed by the user as '-o' option. *)
31 let output_filename = ref ""
33 (* Early argument check. *)
35 (* -o flag must have been specified. *)
36 let output_filename = !output_filename in
37 if output_filename = "" then (
38 prerr_endline (s_"virt-mem capture: '-o memoryimage' option is required");
42 (* Capture the image. *)
43 let rec run debug image kdata = ()
47 (s_"virt-mem capture: warning: no kernel images were captured")
49 (* Single image is saved to output_filename. *)
50 save_image image !output_filename
52 (* Multiple images are saved to output_filename.ID where ID
53 * is the domain ID (if known) or a mangled domain name.
56 fun ({ dom = dom; domname = domname } as image) ->
58 !output_filename ^ "." ^
60 | Some dom -> string_of_int (D.get_id dom)
63 | ('a'..'z'|'A'..'Z'|'0'..'9'|'_' as c) -> String.make 1 c
66 String.replace_chars f domname in
67 save_image image filename
70 and save_image { domname = domname } filename =
73 let chan = open_out filename in
77 printf (f_"virt-mem capture: wrote kernel image from %s to filename %s\n")
81 let summary = s_"capture memory image for post-mortem analysis"
82 let description = s_"Capture a memory image to a file for later post-mortem
83 analysis. Use the '-o memoryimage' option to specify the
86 Other tools can load the memory image using the '-t' option."
89 "-o", Arg.Set_string output_filename,
90 "memoryimage " ^s_"Set output filename"
95 ~needs_everything:true ~run
96 ~external_cmd:false ~extra_args ~argcheck
97 "capture" summary description