[gnome-boxes] add --checks option to troubleshot for vt/kvm



commit ba236c46e4120c7c177339846ef74c999a658666
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date:   Thu Mar 8 19:25:03 2012 +0100

    add --checks option to troubleshot for vt/kvm
    
    Add a simple argument --check to do some basic capability checking.
    Although we are in freeze time, it can be helpful to help people who
    expect boxes to work on their machine explain why it doesn't.
    
    In a future version of boxes, we should have a translatable and
    friendlier version of this warning, with a documentation explaining
    how to enable VT in the bios and to load KVM.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671673

 src/app.vala  |    3 +++
 src/main.vala |   22 ++++++++++++++++++++++
 src/util.vala |   45 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 9d6aec2..743c341 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -127,6 +127,9 @@ private class Boxes.App: Boxes.UI {
                 var first_time = setup_sources.end (result);
                 ready (first_time);
             });
+
+            check_cpu_vt_capability ();
+            check_module_kvm_loaded ();
         });
 
         application.activate.connect_after ((app) => {
diff --git a/src/main.vala b/src/main.vala
index 8fc4590..e940c15 100644
--- a/src/main.vala
+++ b/src/main.vala
@@ -3,10 +3,13 @@ using Config;
 using Posix;
 
 private static bool version;
+private static bool checks;
 private static string[] uris;
 
 private const OptionEntry[] options = {
     { "version", 0, 0, OptionArg.NONE, ref version, N_("Display version number"), null },
+    // FIXME: make it translatable after string freeze
+    { "checks", 0, 0, OptionArg.NONE, ref checks, "Check virtualization capabilities", null },
     // A 'broker' is a virtual-machine manager (could be local or remote). Currently libvirt is the only one supported.
     { "", 0, 0, OptionArg.STRING_ARRAY, ref uris, N_("URI to display, broker or installer media"), null },
     { null }
@@ -37,6 +40,25 @@ private static void parse_args (ref unowned string[] args) {
         GLib.stdout.printf ("%s\n", Config.BUILD_VERSION);
         exit (0);
     }
+
+    if (checks) {
+        var loop = new GLib.MainLoop ();
+        run_checks.begin ((obj, res) => {
+            run_checks.end (res);
+            loop.quit ();
+        });
+        loop.run ();
+        exit (0);
+    }
+}
+
+private async void run_checks () {
+    var cpu = yield Boxes.check_cpu_vt_capability ();
+    var kvm = yield Boxes.check_module_kvm_loaded ();
+
+    // FIXME: make it translatable after string freeze, and add proper UI & docs
+    GLib.stdout.printf ("The CPU is capable of virtualization: %s\n".printf (Boxes.yes_no (cpu)));
+    GLib.stdout.printf ("The KVM module is loaded: %s\n".printf (Boxes.yes_no (kvm)));
 }
 
 public int main (string[] args) {
diff --git a/src/util.vala b/src/util.vala
index dd9e436..9a78842 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -394,4 +394,49 @@ namespace Boxes {
         public abstract string UserName { owned get; }
         public abstract string XSession { owned get; }
     }
+
+    public string yes_no (bool value) {
+        // FIXME: make it translatable after string freeze
+        return value ? "yes" : "no";
+    }
+
+    public async bool check_cpu_vt_capability () {
+        var result = false;
+        var file = File.new_for_path ("/proc/cpuinfo");
+
+        try {
+            var stream = new DataInputStream (file.read ());
+            string line = null;
+            while ((line = yield stream.read_line_async (Priority.DEFAULT)) != null) {
+                result = /^flags.*(vmx|svm)/.match (line);
+                if (result)
+                    break;
+            }
+        } catch (GLib.Error error) {
+            GLib.error (error.message);
+        }
+
+        debug ("check_cpu_vt_capability: " + yes_no (result));
+        return result;
+    }
+
+    public async bool check_module_kvm_loaded () {
+        var result = false;
+        var file = File.new_for_path ("/proc/modules");
+
+        try {
+            var stream = new DataInputStream (file.read ());
+            string line = null;
+            while ((line = yield stream.read_line_async (Priority.DEFAULT)) != null) {
+                result = /^(kvm_intel|kvm_amd)/.match (line);
+                if (result)
+                    break;
+            }
+        } catch (GLib.Error error) {
+            GLib.error (error.message);
+        }
+
+        debug ("check_module_kvm_loaded: " + yes_no (result));
+        return result;
+    }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]