From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
Subject: [OSSTEST PATCH 2/2] mg-allocate: Provide command line way to list allocated resources
Date: Thu, 6 Oct 2016 17:35:50 +0100 [thread overview]
Message-ID: <1475771750-12776-2-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1475771750-12776-1-git-send-email-ian.jackson@eu.citrix.com>
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
prev parent reply other threads:[~2016-10-06 16:36 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475771750-12776-2-git-send-email-ian.jackson@eu.citrix.com \
--to=ian.jackson@eu.citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).