@@ -93,6 +93,24 @@ static int make_guest_fifos(const char *guest, int nr_cpus, mode_t mode)
return ret;
}
+static int get_guest_cpu_count(const char *guest)
+{
+ const char *cmd_fmt = "virsh vcpucount --maximum '%s' 2>/dev/null";
+ int nr_cpus = -1;
+ char cmd[1024];
+ FILE *f;
+
+ snprintf(cmd, sizeof(cmd), cmd_fmt, guest);
+ f = popen(cmd, "r");
+ if (!f)
+ return -errno;
+
+ fscanf(f, "%d", &nr_cpus);
+ pclose(f);
+
+ return nr_cpus;
+}
+
static void do_setup_guest(const char *guest, int nr_cpus, mode_t mode, gid_t gid)
{
gid_t save_egid;
@@ -171,6 +189,9 @@ void trace_setup_guest(int argc, char **argv)
guest = argv[optind+1];
+ if (nr_cpus <= 0)
+ nr_cpus = get_guest_cpu_count(guest);
+
if (nr_cpus <= 0)
pdie("invalid number of cpus for guest %s", guest);
@@ -250,7 +250,7 @@ static struct usage_help usage_help[] = {
{
"setup-guest",
"create FIFOs for tracing guest VMs",
- " %s setup-guest -c cpus[-p perm][-g group] guest\n"
+ " %s setup-guest [-c cpus][-p perm][-g group] guest\n"
" -c number of guest virtual CPUs\n"
" -p FIFOs permissions (default: 0660)\n"
" -g FIFOs group owner\n"
When no number of guest CPUs is provided with the -c flag to `trace-cmd setup-guest`, try to autodetect it using virsh for libvirt managed guests. Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com> --- tracecmd/trace-setup-guest.c | 21 +++++++++++++++++++++ tracecmd/trace-usage.c | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-)