* [OSSTEST PATCH 1/2] Executive: Break out task_spec_desc (no functional change)
@ 2016-10-06 16:35 Ian Jackson
2016-10-06 16:35 ` [OSSTEST PATCH 2/2] mg-allocate: Provide command line way to list allocated resources Ian Jackson
0 siblings, 1 reply; 2+ messages in thread
From: Ian Jackson @ 2016-10-06 16:35 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
Osstest/Executive.pm | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/Osstest/Executive.pm b/Osstest/Executive.pm
index 137eb44..14f75b3 100644
--- a/Osstest/Executive.pm
+++ b/Osstest/Executive.pm
@@ -45,7 +45,7 @@ BEGIN {
$VERSION = 1.00;
@ISA = qw(Exporter);
@EXPORT = qw(grabrepolock_reexec
- findtask findtask_spec @all_lock_tables
+ task_spec_desc findtask findtask_spec @all_lock_tables
restrictflight_arg restrictflight_cond
report_run_getinfo report_altcolour
report_altchangecolour
@@ -524,6 +524,20 @@ END
our $taskid;
+sub task_spec_desc ($) {
+ my ($row) = @_; # NB row maybe modifed, to fill in username and comment
+ # => ($newspec, $desc);
+
+ foreach my $k (qw(username comment)) {
+ next if defined $row->{$k};
+ $row->{$k}= "[no $k]";
+ }
+
+ my $newspec = "$row->{taskid} $row->{type} $row->{refkey}";
+ my $desc = "$row->{username} $row->{comment}";
+ return ($newspec,$desc);
+}
+
sub findtask_spec ($$) {
my ($spec, $why) = @_;
@@ -556,13 +570,8 @@ END
die "task $what dead" unless $row->{live};
$q->finish();
- foreach my $k (qw(username comment)) {
- next if defined $row->{$k};
- $row->{$k}= "[no $k]";
- }
-
- my $newspec= "$row->{taskid} $row->{type} $row->{refkey}";
- logm("${why}task $newspec: $row->{username} $row->{comment}");
+ my ($newspec, $desc) = task_spec_desc($row);
+ logm("${why}task $newspec: $desc");
$taskid= $row->{taskid};
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [OSSTEST PATCH 2/2] mg-allocate: Provide command line way to list allocated resources
2016-10-06 16:35 [OSSTEST PATCH 1/2] Executive: Break out task_spec_desc (no functional change) Ian Jackson
@ 2016-10-06 16:35 ` Ian Jackson
0 siblings, 0 replies; 2+ messages in thread
From: Ian Jackson @ 2016-10-06 16:35 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson
Freely shareable resources don't appear in the plan, and the plan is
not always immediately updated, and is generally not always a
convenient interface. Provide a command line way to list allocated
resources.
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
mg-allocate | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 92 insertions(+)
diff --git a/mg-allocate b/mg-allocate
index ef57bb8..3b3fa72 100755
--- a/mg-allocate
+++ b/mg-allocate
@@ -2,6 +2,7 @@
#
# usage:
# ./mg-allocate [<options>] <resource-spec>...
+# ./mg-allocate [-l] [-l] [-l]
#
# <resource-spec> syntax:
# [!][<type>/]<name>[/<share>] type defaults to 'host'
@@ -45,6 +46,15 @@
# as if they were free. This allows us to steal
# resources from other tasks. May be repeated.
#
+# -l | --list Instead of allocating (or deallocating), simply list
+# allocated resources.
+#
+# -l: resources owned by this task (this user).
+# -ll: resources owned by all tasks
+# -lll: include "administrative" resources
+#
+# Not compatible with other options.
+#
# <task-spec> must exist (and be in a format valid for OSSTEST_TASK).
# This is part of "osstest", an automated testing framework for Xen.
@@ -77,6 +87,7 @@ $|=1;
our $tid;
our %magictask;
+our $list_only;
our $donate_spec;
our $donate_taskid;
our @steal_specs;
@@ -491,6 +502,9 @@ while (@ARGV && $ARGV[0] =~ m/^[-0-9]/) {
1);
} elsif (s/^\-U/-/) {
$ENV{OSSTEST_RESOURCE_PRIORITY} //= -1000000;
+ } elsif (s/^\-l/-/ || s/^--list$/--/) {
+ $list_only++;
+ die "-l may be repeated only thrice\n" if $list_only > 3;
} elsif (s/^--as$/-/) {
die "--as needs task\n" unless @ARGV;
$ENV{OSSTEST_TASK} = shift @ARGV;
@@ -506,6 +520,84 @@ while (@ARGV && $ARGV[0] =~ m/^[-0-9]/) {
}
}
+$list_only = 1 if !@ARGV;
+
+if ($list_only) {
+ die "-l (--list) specified (or implied) with other options or arguments\n"
+ if $donate_spec || @steal_specs || @ARGV || $duration;
+
+ db_retry($dbh_tests, [], sub {
+ my $resbasetypeqtxt = <<END;
+ ( CASE WHEN restype LIKE 'share-%'
+ THEN SUBSTRING(restype FROM 7)
+ ELSE restype
+ END ) AS resbasetype
+END
+ my $orderqtxt = "restype, resname, shareix";
+ my $tid;
+ my $lq;
+ if ($list_only==1) {
+ $tid = findtask();
+ $lq = $dbh_tests->prepare(<<END);
+ SELECT *,
+$resbasetypeqtxt
+ FROM resources
+ WHERE owntaskid=?
+ ORDER BY resbasetype, $orderqtxt
+END
+ $lq->execute($tid);
+ } else {
+ $tid = '';
+ my @hidemagic = qw(allocatable);
+ if ($list_only<3) {
+ push @hidemagic, qw(preparing shared);
+ }
+ my $hiderefkey = join ' OR ',
+ map { "tasks.refkey='$_'" }
+ @hidemagic;
+ $lq = $dbh_tests->prepare(<<END);
+ SELECT *,
+$resbasetypeqtxt
+ FROM resources
+ JOIN tasks
+ ON owntaskid=taskid
+ WHERE tasks.live
+ AND NOT (tasks.type='magic' AND $hiderefkey)
+ ORDER BY resbasetype,
+ tasks.type, tasks.refkey,
+ $orderqtxt
+END
+ $lq->execute();
+ }
+ my $resbasetype = '';
+ while (my $c = $lq->fetchrow_hashref()) {
+ if ($c->{resbasetype} ne $resbasetype) {
+ printf "===== %s =====\n", $c->{resbasetype};
+ $resbasetype = $c->{resbasetype};
+ }
+ if ($c->{owntaskid} ne $tid) {
+ my ($spec,$desc) = task_spec_desc($c);
+ printf "------ %s -- %s ------\n", $spec, $desc;
+ $tid = $c->{owntaskid};
+ }
+ printf " %-40s ", (join "/", map { $c->{$_} }
+ qw(restype resname shareix));
+ my $restype = $c->{restype};
+ my $resname = $c->{resname};
+ if ($restype eq 'share-host') {
+ print "S/$resname";
+ } elsif ($restype eq 'host') {
+ print "$resname";
+ } elsif ($restype eq 'share-flight') {
+ print "F/$resname";
+ }
+ print "\n";
+ }
+ db_retry_abort();
+ });
+ exit 0;
+}
+
if (defined $donate_spec) {
die "--donate specified with deallocations, too confusing\n"
if grep { m/^!/ } @ARGV;
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-06 16:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-06 16:35 [OSSTEST PATCH 1/2] Executive: Break out task_spec_desc (no functional change) Ian Jackson
2016-10-06 16:35 ` [OSSTEST PATCH 2/2] mg-allocate: Provide command line way to list allocated resources Ian Jackson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).