From patchwork Mon Feb 4 06:58:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10795003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DFC156C2 for ; Mon, 4 Feb 2019 06:59:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC74E2B03C for ; Mon, 4 Feb 2019 06:59:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF7D52B042; Mon, 4 Feb 2019 06:59:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CBF32B03C for ; Mon, 4 Feb 2019 06:59:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726348AbfBDG7I (ORCPT ); Mon, 4 Feb 2019 01:59:08 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:34619 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbfBDG7I (ORCPT ); Mon, 4 Feb 2019 01:59:08 -0500 Received: by mail-wm1-f67.google.com with SMTP id y185so9296664wmd.1 for ; Sun, 03 Feb 2019 22:59:07 -0800 (PST) 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=oO5do8q1U5Vv4Twz8iY4p0exxjg6NdsA2d3EcWpAL5s=; b=M00OPCjymDZNmLKI0ceI+MI4b3k3byaRXk6CVCk4PfPfW5GvxG9Y3i0XB5LuHmteZn xjMn2o7efA215zEHEcSI0yiPxKbMkKlSH+ekj2jftdLa/4pMn6Q5PmltdAGSm+Ba3LCE weBFc+yY2/SMBUJmB4kFsC2wv6smSA4VWyDVXb0Sp1zFg0e+yIKk3Lzt3ENEkOwc1hQX PSDXHHrF26rTdE5HAIrUmkgOw3BBeruOrSyQJc9Did8KFJzAkLjlt7HaARwfdQvOhFcQ ruIRmwur5pn+k6MtJfSP36FV+h4Gh+NzztG9W08xyQv+wFEgkbP5JbTE8L4ufYDMhJvf 5q0A== X-Gm-Message-State: AHQUAubebNzLmg/9/tGQi1nkgq3sAmQbzrS4eEqpJUsZzkZUQsOy73wZ P30gSPlBpPZcmImc7VHRbRpSMbF4Yg== X-Google-Smtp-Source: AHgI3Ia2MdyNkNTNIcX05ufz1SUwLAytlYVBluTGCVlFvXy3I6ugTvC45stNlCZsSlRrRZlI+/iMWw== X-Received: by 2002:a1c:5a42:: with SMTP id o63mr11875915wmb.88.1549263546379; Sun, 03 Feb 2019 22:59:06 -0800 (PST) Received: from localhost.localdomain ([213.145.108.55]) by smtp.gmail.com with ESMTPSA id q12sm12596809wrx.31.2019.02.03.22.59.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Feb 2019 22:59:05 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com, tstoyanov@vmware.com, ykaradzhov@vmware.com Subject: [RFC PATCH v5 08/11] trace-cmd: Try to autodetect number of guest CPUs in setup-guest if not specified Date: Mon, 4 Feb 2019 08:58:45 +0200 Message-Id: <20190204065848.8248-9-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190204065848.8248-1-kaslevs@vmware.com> References: <20190204065848.8248-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 X-Virus-Scanned: ClamAV using ClamSMTP 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 1a2c8d4..bcd8f40 100644 --- a/tracecmd/trace-setup-guest.c +++ b/tracecmd/trace-setup-guest.c @@ -100,6 +100,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 -1; + + 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; @@ -174,6 +192,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 7a8002f..9a13d93 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -249,7 +249,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"