From 5571ffa04e4a3bf0bb2d68dd27be4a5838d45d39 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Beginning of virt-dmesg command, not quite working because I can't work out how the kernel buffer is arranged. --- MANIFEST | 1 + dmesg/.depend | 4 ++++ dmesg/Makefile.in | 25 +++++++++++++---------- dmesg/virt_dmesg.ml | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 11 deletions(-) create mode 100644 dmesg/virt_dmesg.ml diff --git a/MANIFEST b/MANIFEST index 1e19d14..5006cbd 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,6 +3,7 @@ configure.ac COPYING dmesg/.depend dmesg/Makefile.in +dmesg/virt_dmesg.ml .hgignore install-sh lib/.depend diff --git a/dmesg/.depend b/dmesg/.depend index e69de29..6c94cb9 100644 --- a/dmesg/.depend +++ b/dmesg/.depend @@ -0,0 +1,4 @@ +virt_dmesg.cmo: ../lib/virt_mem_utils.cmo ../lib/virt_mem_mmap.cmi \ + ../lib/virt_mem_gettext.cmo ../lib/virt_mem.cmi +virt_dmesg.cmx: ../lib/virt_mem_utils.cmx ../lib/virt_mem_mmap.cmx \ + ../lib/virt_mem_gettext.cmx ../lib/virt_mem.cmx diff --git a/dmesg/Makefile.in b/dmesg/Makefile.in index 1740e00..388b1a8 100644 --- a/dmesg/Makefile.in +++ b/dmesg/Makefile.in @@ -24,33 +24,36 @@ INSTALL = @INSTALL@ SYNTAX = -pp "camlp4o -I`ocamlc -where`/bitmatch bitmatch.cma pa_bitmatch.cmo" #OCAMLCPACKAGES = -package unix,bigarray,extlib,bitmatch -OCAMLCPACKAGES = -package unix,bigarray,extlib -I +bitmatch +OCAMLCPACKAGES = -package unix,bigarray,extlib -I +bitmatch -I ../lib ifneq ($(pkg_gettext),no) OCAMLCPACKAGES += -package gettext-stub endif OCAMLCFLAGS = @OCAMLCFLAGS@ $(SYNTAX) -OCAMLCLIBS = -linkpkg bitmatch.cma +OCAMLCLIBS = -linkpkg bitmatch.cma ../lib/virt_mem.cma OCAMLOPTFLAGS = @OCAMLOPTFLAGS@ $(SYNTAX) OCAMLOPTPACKAGES = $(OCAMLCPACKAGES) -OCAMLOPTLIBS = -linkpkg bitmatch.cmxa +OCAMLOPTLIBS = -linkpkg bitmatch.cmxa ../lib/virt_mem.cmxa OCAMLDOCFLAGS = -html -sort $(OCAMLCPACKAGES) $(SYNTAX) OCAMLDEPFLAGS = $(SYNTAX) -TARGETS = +TARGETS = virt-dmesg virt-dmesg.opt + +OBJS = virt_dmesg.cmo +XOBJS = virt_dmesg.cmx all: $(TARGETS) -#virt-mem: $(OBJS) -# ocamlfind ocamlc \ -# $(OCAMLCFLAGS) $(OCAMLCPACKAGES) $(OCAMLCLIBS) $^ -o $@ -# -#virt-mem.opt: $(XOBJS) -# ocamlfind ocamlopt \ -# $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) $(OCAMLOPTLIBS) $^ -o $@ +virt-dmesg: $(OBJS) ../lib/virt_mem.cma + ocamlfind ocamlc \ + $(OCAMLCFLAGS) $(OCAMLCPACKAGES) $(OCAMLCLIBS) $(OBJS) -o $@ + +virt-dmesg.opt: $(XOBJS) ../lib/virt_mem.cmxa + ocamlfind ocamlopt \ + $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) $(OCAMLOPTLIBS) $(XOBJS) -o $@ include ../Make.rules \ No newline at end of file diff --git a/dmesg/virt_dmesg.ml b/dmesg/virt_dmesg.ml new file mode 100644 index 0000000..2435bbc --- /dev/null +++ b/dmesg/virt_dmesg.ml @@ -0,0 +1,59 @@ +(* Memory info for virtual domains. + (C) Copyright 2008 Richard W.M. Jones, Red Hat Inc. + http://libvirt.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *) + +open Printf + +open Virt_mem_gettext.Gettext +open Virt_mem_utils +open Virt_mem_mmap + +let usage = s_"NAME + virt-dmesg - dmesg command for virtual machines + +SUMMARY + virt-dmesg [-options] [domains] + +DESCRIPTION + virt-dmesg prints the kernel messages for virtual machines running + under libvirt. The output is similar to the ordinary dmesg command + run inside the virtual machine." + +let verbose, images = Virt_mem.start usage + +let () = + List.iter ( + fun (name, arch, mem, lookup_ksym) -> + try + (* I don't know why but this symbol doesn't exist in 2.6.9 + * even in kallsyms. Hence this won't work with that kernel. + * It's possible we can fall back to memory scanning. XXX + *) + let log_buf = lookup_ksym "log_buf" in + let log_buf_len = lookup_ksym "log_buf_len" in + let log_start = lookup_ksym "log_start" in + let log_end = lookup_ksym "log_end" in + let con_start = lookup_ksym "con_start" in + + () + + with + Not_found -> + eprintf (f_"%s: could not find kernel log buffer in kernel image\n") + name + ) images -- 1.8.3.1