[OSSTEST,v4,2/3] examine: detect IOMMU availability and add it as a hostflag
diff mbox series

Message ID 20200311160021.6075-2-roger.pau@citrix.com
State New
Headers show
Series
  • [OSSTEST,v4,1/3] host: introduce helpers to modify hostflags
Related show

Commit Message

Roger Pau Monné March 11, 2020, 4 p.m. UTC
Introduce a new test to check for iommu availability and add it as a
hostflag if found.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Changes since v3:
 - Fail if `xl info` command fails.

Changes since v2:
 - Allow flags to be removed.
 - Fix set_flag addition to HostBD/Static.pm.
---
 sg-run-job                |  1 +
 ts-examine-hostprops-save | 28 +++++++++++++++++++---------
 ts-examine-iommu          | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 9 deletions(-)
 create mode 100755 ts-examine-iommu

Patch
diff mbox series

diff --git a/sg-run-job b/sg-run-job
index 7c58d4ba..f6bfdfd5 100755
--- a/sg-run-job
+++ b/sg-run-job
@@ -679,6 +679,7 @@  proc examine-host-examine {install} {
     if {$ok} {
 	run-ts -.  =           ts-examine-serial-post + host
 	run-ts .   =           ts-examine-logs-save   + host
+	run-ts .   =           ts-examine-iommu       + host
 	run-ts .   =           ts-examine-hostprops-save
     }
 }
diff --git a/ts-examine-hostprops-save b/ts-examine-hostprops-save
index 55d23392..b1c8de6d 100755
--- a/ts-examine-hostprops-save
+++ b/ts-examine-hostprops-save
@@ -27,20 +27,30 @@  tsreadconfig();
 
 our $blessing = intended_blessing();
 
-logm("setting host properties");
+logm("setting host properties and flags");
 
 # NB: in order to aid debug only attempt to save the host props on flights
 # with intended real blessing, for the rest just do a dry run.
 our $dry_run = $blessing ne "real";
-logm("not saving host props with intended blessing $blessing != real")
+logm("not saving host props/flags with intended blessing $blessing != real")
     if $dry_run;
 
 foreach my $k (sort keys %r) {
-    next unless $k =~ m/^hostprop\/([^\/]*)\/([^\/]*)$/;
-    my $ho = selecthost($1);
-    my $prop = $2;
-
-    logm("recording for $ho->{Name} $prop=$r{$k}");
-
-    set_host_property($ho, $prop, $r{$k}) if !$dry_run;
+    next unless $k =~ m/^host(prop|flag)\/([^\/]*)\/([^\/]*)$/;
+    my $type = $1;
+    my $ho = selecthost($2);
+    my $prop = $3;
+
+    if ($type eq "flag") {
+        if ($r{$k} && !$dry_run) {
+            logm("recording flag $prop for $ho->{Name}");
+            set_host_flag($ho, $prop);
+        } elsif (!$dry_run) {
+            logm("removing flag $prop for $ho->{Name}");
+            remove_host_flag($ho, $prop);
+        }
+    } else {
+        logm("recording prop for $ho->{Name} $prop=$r{$k}");
+        set_host_property($ho, $prop, $r{$k}) if !$dry_run;
+    }
 }
diff --git a/ts-examine-iommu b/ts-examine-iommu
new file mode 100755
index 00000000..099d4be5
--- /dev/null
+++ b/ts-examine-iommu
@@ -0,0 +1,32 @@ 
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2020 Citrix Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+use strict qw(vars);
+BEGIN { unshift @INC, qw(.); }
+use Osstest;
+use Osstest::TestSupport;
+
+tsreadconfig();
+
+our ($whhost) = @ARGV;
+$whhost ||= 'host';
+our $ho= selecthost($whhost);
+our $info = target_cmd_output_root($ho, 'xl info', 10);
+our $has_iommu = $info =~ /directio/;
+
+logm("$ho->{Ident} iommu: $has_iommu");
+hostflag_putative_record($ho, "iommu", $has_iommu);