From patchwork Tue Sep 17 13:15:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 11148873 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E40EE1708 for ; Tue, 17 Sep 2019 13:15:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC365214AF for ; Tue, 17 Sep 2019 13:15:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726131AbfIQNP6 (ORCPT ); Tue, 17 Sep 2019 09:15:58 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53028 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727711AbfIQNP6 (ORCPT ); Tue, 17 Sep 2019 09:15:58 -0400 Received: by mail-wm1-f66.google.com with SMTP id x2so3390194wmj.2 for ; Tue, 17 Sep 2019 06:15:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JCNgQ67sbTc5rsl3eJYEuZk9Li9O5zUsndsWEkzhvh0=; b=Ydr+WEgzT+xhyYNGCvjNZYEFCTEn4FQOzy+UMjknwS8IVf1HUoUWyFDx8cknv4mojr nMJkdI2xXOWw9bq4eu1IqVeS461cJN5jnRNVzJHO2GQlmCbwhJ1J7JoI8w4mWsSW411D dMG6pni8QbG1P/ayjPO4DWN5T9jjuzj+RfttGLrhM4gz8f+AC1VfabGQ2b9YtKlHQJJo FEhGWFcIaxSMRDxAarnZ7rEJ4hu9GYG8JUYfi19aGUgJlSTXF7S9qv/AaUHJ4pZF5VWw UxUXbjHUUaFK4o/Te6NAN4U1Mzi1YyjGg9m8p+5BxEVdvvUS6wyQo8QcJiq+tOT/RhCs t86g== X-Gm-Message-State: APjAAAW+uV530spdztz74CaVQu6tMqDZPhQY3hO0SiRoYp5RfKgoUDzJ AIfTzur6C6/5nb4F7z+cG3ZiNpU6bA== X-Google-Smtp-Source: APXvYqxDam4a5XQ266DaQ9goa7jvl3Ne7Bg3yrtSEnqKRlal3gTTH9zjTp0TNBNikddA+UJk7r2d3Q== X-Received: by 2002:a05:600c:291c:: with SMTP id i28mr716861wmd.98.1568726156437; Tue, 17 Sep 2019 06:15:56 -0700 (PDT) Received: from box.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id d22sm1667265wmb.44.2019.09.17.06.15.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2019 06:15:55 -0700 (PDT) From: Slavomir Kaslev To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v14 10/13] trace-cmd: Try to autodetect number of guest CPUs in setup-guest if not specified Date: Tue, 17 Sep 2019 16:15:35 +0300 Message-Id: <20190917131538.31926-11-kaslevs@vmware.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190917131538.31926-1-kaslevs@vmware.com> References: <20190917131538.31926-1-kaslevs@vmware.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org 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 --- tracecmd/trace-setup-guest.c | 21 +++++++++++++++++++++ tracecmd/trace-usage.c | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tracecmd/trace-setup-guest.c b/tracecmd/trace-setup-guest.c index a6f58dc..a55a37d 100644 --- a/tracecmd/trace-setup-guest.c +++ b/tracecmd/trace-setup-guest.c @@ -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); diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 2caff0e..6c8dc10 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -251,7 +251,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"