Skip to contentSkip to conversation

Fix use of xenctx

PATCH In review Ian Jackson 2 participants 19 messages Jul 2, 2015 – Jul 3, 2015

lore
Share & tools
lore
#7 lore raw

PATCH 4/4 ts-logs-capture: Run xenctx earlier

In reply to Ian Jackson

Break fetch_xenctx_guest out into its own function, and run it before serial_fetch_logs.

This is relevant because serial_fetch_logs sends the Xen debug keys, which might dislodge a stuck guest - and, if it does, we would like to have captured the stuck state with xenctx, rather than the unstuck one.

---
 ts-logs-capture |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
ts-logs-capture +13 -7
index 7127675..04cb2fd 100755
@@ -203,14 +203,9 @@ sub fetch_logs_host () {
         }
 }
 
-sub fetch_logs_guest ($) {
+sub fetch_xenctx_guest ($) {
     my ($gho) = @_;
-    my $gn = $gho->{Name};
-    logm("saving logs for $gn");
-
-    my $consolecmd= toolstack($ho)->consolecmd($gho);
-    try_cmd_output_save("sleep 1 | $consolecmd | cat",
-                        "guest-$gho->{Name}-console");
+    logm("collecting xenctx for $gho->{Name}");
 
     if (defined $gho->{Vcpus}) {
         foreach (my $vcpu=0; $vcpu < $gho->{Vcpus}; $vcpu++) {
@@ -224,6 +219,16 @@ sub fetch_logs_guest ($) {
 		);
         }
     }
+}
+
+sub fetch_logs_guest ($) {
+    my ($gho) = @_;
+    my $gn = $gho->{Name};
+    logm("saving logs for $gn");
+
+    my $consolecmd= toolstack($ho)->consolecmd($gho);
+    try_cmd_output_save("sleep 1 | $consolecmd | cat",
+                        "guest-$gho->{Name}-console");
 
     if (!eval {
         my $vnc= guest_vncsnapshot_begin($ho,$gho);
@@ -235,6 +240,7 @@ sub fetch_logs_guest ($) {
 }
 
 find_guests();
+fetch_xenctx_guest($_) foreach @guests;
 serial_fetch_logs($ho);
 fetch_logs_host();
 fetch_logs_guest($_) foreach @guests;
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/4 guest_find_domid: Set Vcpus correctly.

In reply to Ian Jackson

The regexp was wrong, resulting in the last digit of the memory being mistaken for the number of vcpus (!)

The only consumer of this is ts-logs-capture.

---
 Osstest/TestSupport.pm |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Osstest/TestSupport.pm +1 -1
index b5994a4..66dc218 100644
@@ -1918,7 +1918,7 @@ sub guest_find_domid ($$) {
     return if defined $gho->{Domid};
     my $list= target_cmd_output_root($ho,
                 common_toolstack($ho)." list $gho->{Name}");
-    $list =~ m/^(?!Name\s)(\S+)\s+(\d+)\s+(\d+)+(\d+)\s.*$/m
+    $list =~ m/^(?!Name\s)(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s.*$/m
         or die "domain list: $list";
     $1 eq $gho->{Name} or die "domain list name $1 expected $gho->{Name}";
     $gho->{MemUsed}= $3;
Signature · 1 line
1.7.10.4
#5 lore raw

PATCH 3/4 ts-logs-capture: Break out guest listing and do it earlier

In reply to Ian Jackson

Break out the function find_guests from what was fetch_logs_host_guests, and have it save its results in the @guests global.

We do this soon because in the next patch we are going to want to do something to each guest before we call serial_fetch_logs.

The loop containing fetch_logs_guest is now in the main program.

---
 ts-logs-capture |   60 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 25 deletions(-)
ts-logs-capture +35 -25
index 13795e8..7127675 100755
@@ -33,6 +33,34 @@ our ($whhost) = @ARGV;
 $whhost ||= 'host';
 our $ho= selecthost($whhost);
 
+our @guests;
+
+sub find_guests () {
+    my $sth= $dbh_tests->prepare(<<END);
+        SELECT name FROM runvars WHERE flight=? AND job=?
+            AND name LIKE '%_domname'
+            ORDER BY name
+END
+    $sth->execute($flight, $job);
+    my $row;
+    while ($row= $sth->fetchrow_hashref) {
+        my $gn= $row->{name};
+        $gn =~ s/_domname$//;
+
+	my $gho= selectguest($gn,$ho);
+	if (!eval {
+	    guest_find_domid($ho,$gho);
+	    1;
+	}) {
+	    logm("cannot find domid: $@");;
+	    next;
+	}
+
+	push @guests, $gho;
+    }
+    $sth->finish();
+}
+
 sub try_fetch_logs ($$) {
     my ($lho, $logfilepats) = @_;
     my $ok= 0;
@@ -97,7 +125,7 @@ sub try_cmd_output_save ($;$) {
     close $fh or die $!;
 }
 
-sub fetch_logs_host_guests () {
+sub fetch_logs_host () {
     my $logs= [qw(
                   /var/log/kern.log*
                   /var/log/syslog*
@@ -173,33 +201,13 @@ sub fetch_logs_host_guests () {
          ) {
             try_cmd_output_save($cmd);
         }
-
-    my $sth= $dbh_tests->prepare(<<END);
-        SELECT name FROM runvars WHERE flight=? AND job=?
-            AND name LIKE '%_domname'
-            ORDER BY name
-END
-    $sth->execute($flight, $job);
-    my $row;
-    while ($row= $sth->fetchrow_hashref) {
-        my $gn= $row->{name};
-        $gn =~ s/_domname$//;
-        fetch_logs_guest($gn);
-    }
-    $sth->finish();
 }
 
 sub fetch_logs_guest ($) {
-    my ($gn) = @_;
+    my ($gho) = @_;
+    my $gn = $gho->{Name};
     logm("saving logs for $gn");
-    my $gho= selectguest($gn,$ho);
-    if (!eval {
-        guest_find_domid($ho,$gho);
-        1;
-    }) {
-        logm("cannot find domid: $@");
-        return;
-    }
+
     my $consolecmd= toolstack($ho)->consolecmd($gho);
     try_cmd_output_save("sleep 1 | $consolecmd | cat",
                         "guest-$gho->{Name}-console");
@@ -226,6 +234,8 @@ sub fetch_logs_guest ($) {
     }
 }
 
+find_guests();
 serial_fetch_logs($ho);
-fetch_logs_host_guests();
+fetch_logs_host();
+fetch_logs_guest($_) foreach @guests;
 logm("logs captured to $stash");
Signature · 1 line
1.7.10.4
#0 lore raw

cover Fix use of xenctx

I discovered that xenctx was not being run any more. These 4 patches fix it, and also arrange to run it sooner.

Ian.

#3 lore raw

PATCH 2/4 ts-logs-capture: Find xenctx in /usr/local as well

xenctx is now in /usr/local/lib/xen/bin/xenctx.

                     ^^^^^^

Find it by setting PATH in the shell command.

---
 ts-logs-capture |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
ts-logs-capture +4 -2
index 2498416..13795e8 100755
@@ -210,8 +210,10 @@ sub fetch_logs_guest ($) {
 	    my $sysmaparg = !defined $kernpath ? '' :
 		$kernpath !~ m,/vmlinuz-, ? die "$kernpath ?" :
 		"-s $`/System.map-$'";
-	    try_cmd_output_save("/usr/lib/xen/bin/xenctx ".$sysmaparg.
-				" $gho->{Domid} $vcpu");
+	    try_cmd_output_save(
+		'PATH=/usr/local/lib/xen/bin:/usr/lib/xen/bin:$PATH; '.
+		"xenctx $sysmaparg $gho->{Domid} $vcpu"
+		);
         }
     }
 
Signature · 1 line
1.7.10.4
Acked-by on v1 1/4
#2 lore raw

Re: [OSSTEST PATCH 1/4] guest_find_domid: Set Vcpus correctly.

In reply to Ian Jackson
Quoted 6 lines · Ian Jackson

The regexp was wrong, resulting in the last digit of the memory being mistaken for the number of vcpus (!)

The only consumer of this is ts-logs-capture.

Perhaps at some point in the future once xm is off the test radar we could consider using xl list --format=json (nb, I didn't check the concrete syntax) and using that.

Quoted 17 lines
---
 Osstest/TestSupport.pm |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Osstest/TestSupport.pm +1 -1
index b5994a4..66dc218 100644
@@ -1918,7 +1918,7 @@ sub guest_find_domid ($$) {
     return if defined $gho->{Domid};
     my $list= target_cmd_output_root($ho,
                 common_toolstack($ho)." list $gho->{Name}");
-    $list =~ m/^(?!Name\s)(\S+)\s+(\d+)\s+(\d+)+(\d+)\s.*$/m
+    $list =~ m/^(?!Name\s)(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s.*$/m
         or die "domain list: $list";
     $1 eq $gho->{Name} or die "domain list name $1 expected $gho->{Name}";
     $gho->{MemUsed}= $3;
Acked-by on v1 3/4
#6 lore raw

Re: [OSSTEST PATCH 3/4] ts-logs-capture: Break out guest listing and do it earlier

In reply to Ian Jackson
Quoted 10 lines · Ian Jackson

Break out the function find_guests from what was fetch_logs_host_guests, and have it save its results in the @guests global.

We do this soon because in the next patch we are going to want to do something to each guest before we call serial_fetch_logs.

The loop containing fetch_logs_guest is now in the main program.

Acked-by on v1 4/4
#8 lore raw

Re: [OSSTEST PATCH 4/4] ts-logs-capture: Run xenctx earlier

In reply to Ian Jackson
Quoted 9 lines · Ian Jackson

Break fetch_xenctx_guest out into its own function, and run it before serial_fetch_logs.

This is relevant because serial_fetch_logs sends the Xen debug keys, which might dislodge a stuck guest - and, if it does, we would like to have captured the stuck state with xenctx, rather than the unstuck one.

At first I wondered if before and after might be useful, but I don't think the unstuck state would be useful. However two (or more) back-to-back ctxt's can often be useful, by giving a snapshot of the loop the guest is stuck.

Ian.

#9 lore raw

Re: [OSSTEST PATCH 4/4] ts-logs-capture: Run xenctx earlier

Ian Campbell writes ("Re: [OSSTEST PATCH 4/4] ts-logs-capture: Run xenctx earlier"):

Quoted 4 lines

At first I wondered if before and after might be useful, but I don't think the unstuck state would be useful. However two (or more) back-to-back ctxt's can often be useful, by giving a snapshot of the loop the guest is stuck.

Good idea. I will respin.

Ian.

#10 lore raw

PATCH 1/6 guest_find_domid: Set Vcpus correctly.

The regexp was wrong, resulting in the last digit of the memory being mistaken for the number of vcpus (!)

The only consumer of this is ts-logs-capture.

---
 Osstest/TestSupport.pm |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Osstest/TestSupport.pm +1 -1
index b5994a4..66dc218 100644
@@ -1918,7 +1918,7 @@ sub guest_find_domid ($$) {
     return if defined $gho->{Domid};
     my $list= target_cmd_output_root($ho,
                 common_toolstack($ho)." list $gho->{Name}");
-    $list =~ m/^(?!Name\s)(\S+)\s+(\d+)\s+(\d+)+(\d+)\s.*$/m
+    $list =~ m/^(?!Name\s)(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s.*$/m
         or die "domain list: $list";
     $1 eq $gho->{Name} or die "domain list name $1 expected $gho->{Name}";
     $gho->{MemUsed}= $3;
Signature · 1 line
1.7.10.4
#12 lore raw

PATCH 3/6 ts-logs-capture: Break out guest listing and do it earlier

Break out the function find_guests from what was fetch_logs_host_guests, and have it save its results in the @guests global.

We do this soon because in the next patch we are going to want to do something to each guest before we call serial_fetch_logs.

The loop containing fetch_logs_guest is now in the main program.

---
 ts-logs-capture |   60 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 25 deletions(-)
ts-logs-capture +35 -25
index 13795e8..7127675 100755
@@ -33,6 +33,34 @@ our ($whhost) = @ARGV;
 $whhost ||= 'host';
 our $ho= selecthost($whhost);
 
+our @guests;
+
+sub find_guests () {
+    my $sth= $dbh_tests->prepare(<<END);
+        SELECT name FROM runvars WHERE flight=? AND job=?
+            AND name LIKE '%_domname'
+            ORDER BY name
+END
+    $sth->execute($flight, $job);
+    my $row;
+    while ($row= $sth->fetchrow_hashref) {
+        my $gn= $row->{name};
+        $gn =~ s/_domname$//;
+
+	my $gho= selectguest($gn,$ho);
+	if (!eval {
+	    guest_find_domid($ho,$gho);
+	    1;
+	}) {
+	    logm("cannot find domid: $@");;
+	    next;
+	}
+
+	push @guests, $gho;
+    }
+    $sth->finish();
+}
+
 sub try_fetch_logs ($$) {
     my ($lho, $logfilepats) = @_;
     my $ok= 0;
@@ -97,7 +125,7 @@ sub try_cmd_output_save ($;$) {
     close $fh or die $!;
 }
 
-sub fetch_logs_host_guests () {
+sub fetch_logs_host () {
     my $logs= [qw(
                   /var/log/kern.log*
                   /var/log/syslog*
@@ -173,33 +201,13 @@ sub fetch_logs_host_guests () {
          ) {
             try_cmd_output_save($cmd);
         }
-
-    my $sth= $dbh_tests->prepare(<<END);
-        SELECT name FROM runvars WHERE flight=? AND job=?
-            AND name LIKE '%_domname'
-            ORDER BY name
-END
-    $sth->execute($flight, $job);
-    my $row;
-    while ($row= $sth->fetchrow_hashref) {
-        my $gn= $row->{name};
-        $gn =~ s/_domname$//;
-        fetch_logs_guest($gn);
-    }
-    $sth->finish();
 }
 
 sub fetch_logs_guest ($) {
-    my ($gn) = @_;
+    my ($gho) = @_;
+    my $gn = $gho->{Name};
     logm("saving logs for $gn");
-    my $gho= selectguest($gn,$ho);
-    if (!eval {
-        guest_find_domid($ho,$gho);
-        1;
-    }) {
-        logm("cannot find domid: $@");
-        return;
-    }
+
     my $consolecmd= toolstack($ho)->consolecmd($gho);
     try_cmd_output_save("sleep 1 | $consolecmd | cat",
                         "guest-$gho->{Name}-console");
@@ -226,6 +234,8 @@ sub fetch_logs_guest ($) {
     }
 }
 
+find_guests();
 serial_fetch_logs($ho);
-fetch_logs_host_guests();
+fetch_logs_host();
+fetch_logs_guest($_) foreach @guests;
 logm("logs captured to $stash");
Signature · 1 line
1.7.10.4
#11 lore raw

PATCH 2/6 ts-logs-capture: Find xenctx in /usr/local as well

In reply to Ian Jackson

xenctx is now in /usr/local/lib/xen/bin/xenctx.

                     ^^^^^^

Find it by setting PATH in the shell command.

---
 ts-logs-capture |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
ts-logs-capture +4 -2
index 2498416..13795e8 100755
@@ -210,8 +210,10 @@ sub fetch_logs_guest ($) {
 	    my $sysmaparg = !defined $kernpath ? '' :
 		$kernpath !~ m,/vmlinuz-, ? die "$kernpath ?" :
 		"-s $`/System.map-$'";
-	    try_cmd_output_save("/usr/lib/xen/bin/xenctx ".$sysmaparg.
-				" $gho->{Domid} $vcpu");
+	    try_cmd_output_save(
+		'PATH=/usr/local/lib/xen/bin:/usr/lib/xen/bin:$PATH; '.
+		"xenctx $sysmaparg $gho->{Domid} $vcpu"
+		);
         }
     }
 
Signature · 1 line
1.7.10.4
#14 lore raw

PATCH 5/6 ts-logs-capture: Run xenctx twice for each guest vcpu

In reply to Ian Jackson

Two (or more) back-to-back ctxt's can often be useful, by giving a snapshot of a loop the guest is stuck in.

---
v2: New patch in this series.

---
 ts-logs-capture |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
ts-logs-capture +6 -4
index 04cb2fd..b2caa77 100755
@@ -213,10 +213,12 @@ sub fetch_xenctx_guest ($) {
 	    my $sysmaparg = !defined $kernpath ? '' :
 		$kernpath !~ m,/vmlinuz-, ? die "$kernpath ?" :
 		"-s $`/System.map-$'";
-	    try_cmd_output_save(
-		'PATH=/usr/local/lib/xen/bin:/usr/lib/xen/bin:$PATH; '.
-		"xenctx $sysmaparg $gho->{Domid} $vcpu"
-		);
+	    foreach my $iter (0..1) {
+		try_cmd_output_save(
+		    'PATH=/usr/local/lib/xen/bin:/usr/lib/xen/bin:$PATH; '.
+		    "xenctx $sysmaparg $gho->{Domid} $vcpu"
+		    );
+	    }
         }
     }
 }
Signature · 1 line
1.7.10.4
#16 lore raw

PATCH 6/6 ts-logs-capture: Explicitly set xenctx capture filename

In reply to Ian Jackson

Now that the command contains PATH, the autogenerated filename is very ugly.

---
v2: New patch in this version of the series.

---
 ts-logs-capture |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
ts-logs-capture +3 -2
index b2caa77..0081372 100755
@@ -214,10 +214,11 @@ sub fetch_xenctx_guest ($) {
 		$kernpath !~ m,/vmlinuz-, ? die "$kernpath ?" :
 		"-s $`/System.map-$'";
 	    foreach my $iter (0..1) {
+		my $dfn = "$ho->{Name}-xenctx-$gho->{Name},vcpu$vcpu,i$iter";
 		try_cmd_output_save(
 		    'PATH=/usr/local/lib/xen/bin:/usr/lib/xen/bin:$PATH; '.
-		    "xenctx $sysmaparg $gho->{Domid} $vcpu"
-		    );
+		    "xenctx $sysmaparg $gho->{Domid} $vcpu",
+		    $dfn);
 	    }
         }
     }
Signature · 1 line
1.7.10.4
#13 lore raw

PATCH 4/6 ts-logs-capture: Run xenctx earlier

In reply to Ian Jackson

Break fetch_xenctx_guest out into its own function, and run it before serial_fetch_logs.

This is relevant because serial_fetch_logs sends the Xen debug keys, which might dislodge a stuck guest - and, if it does, we would like to have captured the stuck state with xenctx, rather than the unstuck one.

---
 ts-logs-capture |   20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)
ts-logs-capture +13 -7
index 7127675..04cb2fd 100755
@@ -203,14 +203,9 @@ sub fetch_logs_host () {
         }
 }
 
-sub fetch_logs_guest ($) {
+sub fetch_xenctx_guest ($) {
     my ($gho) = @_;
-    my $gn = $gho->{Name};
-    logm("saving logs for $gn");
-
-    my $consolecmd= toolstack($ho)->consolecmd($gho);
-    try_cmd_output_save("sleep 1 | $consolecmd | cat",
-                        "guest-$gho->{Name}-console");
+    logm("collecting xenctx for $gho->{Name}");
 
     if (defined $gho->{Vcpus}) {
         foreach (my $vcpu=0; $vcpu < $gho->{Vcpus}; $vcpu++) {
@@ -224,6 +219,16 @@ sub fetch_logs_guest ($) {
 		);
         }
     }
+}
+
+sub fetch_logs_guest ($) {
+    my ($gho) = @_;
+    my $gn = $gho->{Name};
+    logm("saving logs for $gn");
+
+    my $consolecmd= toolstack($ho)->consolecmd($gho);
+    try_cmd_output_save("sleep 1 | $consolecmd | cat",
+                        "guest-$gho->{Name}-console");
 
     if (!eval {
         my $vnc= guest_vncsnapshot_begin($ho,$gho);
@@ -235,6 +240,7 @@ sub fetch_logs_guest ($) {
 }
 
 find_guests();
+fetch_xenctx_guest($_) foreach @guests;
 serial_fetch_logs($ho);
 fetch_logs_host();
 fetch_logs_guest($_) foreach @guests;
Signature · 1 line
1.7.10.4
#18 lore raw

Re: [OSSTEST PATCH 6/6] ts-logs-capture: Explicitly set xenctx capture filename

Ian Campbell writes ("Re: [OSSTEST PATCH 6/6] ts-logs-capture: Explicitly set xenctx capture filename"):

Quoted 8 lines · Ian Jackson
Quoted 4 lines

Now that the command contains PATH, the autogenerated filename is very ugly.

I should have read this before checking the behaviour of try_cmd_output_save in the last patch!

Maybe. But it would still be important for the filename to be made unique in case (say) ts-logs-capture is run more than once.

But yes, it is made unique (even if the caller passes an explicit starting point filename) :-).

Thanks,
Ian.