From patchwork Fri Feb 22 18:05:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10826797 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 7EC591575 for ; Fri, 22 Feb 2019 18:06:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 700DA32A79 for ; Fri, 22 Feb 2019 18:06:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6422532A7C; Fri, 22 Feb 2019 18:06:03 +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 DFEB232A79 for ; Fri, 22 Feb 2019 18:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726869AbfBVSGC (ORCPT ); Fri, 22 Feb 2019 13:06:02 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34947 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727499AbfBVSGC (ORCPT ); Fri, 22 Feb 2019 13:06:02 -0500 Received: by mail-wm1-f66.google.com with SMTP id y15so2791818wma.0 for ; Fri, 22 Feb 2019 10:06:00 -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=w+oOW9EvJCRiLD+1FCQtWkt6YnXx0urXezNZ7R4dfuE=; b=dkT3yk4LuyoHI4mtl98KA9L7P39PGETzwYULrlH9IkafPI9oNlosXqzx+zMGLSC+Rl Rm9zA/lf7OYDfjS5fejqLm/ZfwNq8YAJ51dAOAgPPcOyrAi0m4JCTOK9vr9kufkmgQJ7 sfxlagBrKSdCpPAQU8up1k/msWUl5bOgoGxCXN8oj2Z1S+7eGDv27cA54HxXAG1hpmEL v/kL9ReKH5iYEZ5A0Y3ih711TLUz12a4ouAcebMzbeJ3p8nclq9Bn35EATwEv9R3qtBh QVcB330vr8OF0eidcHffXY6+Q9m/jm3kVBVZw9IOOl9TExQlHVeJVx4UuKACCGQflDUO /EUA== X-Gm-Message-State: AHQUAubXOJvuFuRv9qXkZlZr8Rsa7pASA4jGxlNwYIQP3gDguZYmBEUQ EI0OT45A1qu6u2v2FFtEeXBARFY= X-Google-Smtp-Source: AHgI3IarlKslVz84xO/1gcmIztFmEz52uZhM9QGDIC6akGsCPE3C6EZlZwXE7JyYsEgNzWY+rscsKg== X-Received: by 2002:a1c:228b:: with SMTP id i133mr3435842wmi.105.1550858759312; Fri, 22 Feb 2019 10:05:59 -0800 (PST) Received: from localhost.localdomain ([146.247.46.6]) by smtp.gmail.com with ESMTPSA id c18sm1320678wre.32.2019.02.22.10.05.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 10:05:58 -0800 (PST) From: Slavomir Kaslev To: linux-trace-devel@vger.kernel.org Cc: rostedt@goodmis.org, slavomir.kaslev@gmail.com Subject: [RFC PATCH v8 11/13] trace-cmd: Add setup-guest flag for attaching FIFOs to the guest VM config Date: Fri, 22 Feb 2019 20:05:37 +0200 Message-Id: <20190222180539.27439-12-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190222180539.27439-1-kaslevs@vmware.com> References: <20190222180539.27439-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 This patch adds a flag for attaching the newly created FIFOs for guest tracing as virtio serial devices to libvirt managed guests. Signed-off-by: Slavomir Kaslev --- tracecmd/trace-setup-guest.c | 54 ++++++++++++++++++++++++++++++++++-- tracecmd/trace-usage.c | 3 +- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/tracecmd/trace-setup-guest.c b/tracecmd/trace-setup-guest.c index 15ec637..6ef9053 100644 --- a/tracecmd/trace-setup-guest.c +++ b/tracecmd/trace-setup-guest.c @@ -111,7 +111,45 @@ static int get_guest_cpu_count(const char *guest) return nr_cpus; } -static void do_setup_guest(const char *guest, int nr_cpus, mode_t mode, gid_t gid) +static int attach_guest_fifos(const char *guest, int nr_cpus) +{ + const char *cmd_fmt = + "virsh attach-device --config '%s' '%s' >/dev/null 2>/dev/null"; + const char *xml_fmt = + "\n" + " \n" + " \n" + ""; + char tmp_path[PATH_MAX], path[PATH_MAX]; + char cmd[PATH_MAX], xml[PATH_MAX]; + int i, fd, ret = 0; + + strcpy(tmp_path, "/tmp/pipexmlXXXXXX"); + fd = mkstemp(tmp_path); + if (fd < 0) + return fd; + + for (i = 0; i < nr_cpus; i++) { + snprintf(path, sizeof(path), GUEST_FIFO_FMT, guest, i); + snprintf(xml, sizeof(xml), xml_fmt, path, GUEST_PIPE_NAME, i); + pwrite(fd, xml, strlen(xml), 0); + + snprintf(cmd, sizeof(cmd), cmd_fmt, guest, tmp_path); + errno = 0; + if (system(cmd) != 0) { + ret = -errno; + break; + } + } + + close(fd); + unlink(tmp_path); + + return ret; +} + +static void do_setup_guest(const char *guest, int nr_cpus, + mode_t mode, gid_t gid, bool attach) { gid_t save_egid; int ret; @@ -131,6 +169,12 @@ static void do_setup_guest(const char *guest, int nr_cpus, mode_t mode, gid_t gi if (ret < 0) pdie("failed to create FIFOs for %s", guest); + if (attach) { + ret = attach_guest_fifos(guest, nr_cpus); + if (ret < 0) + pdie("failed to attach FIFOs to %s", guest); + } + if (gid != -1) { ret = setegid(save_egid); if (ret < 0) @@ -140,6 +184,7 @@ static void do_setup_guest(const char *guest, int nr_cpus, mode_t mode, gid_t gi void trace_setup_guest(int argc, char **argv) { + bool attach = false; struct group *group; mode_t mode = 0660; int nr_cpus = -1; @@ -159,7 +204,7 @@ void trace_setup_guest(int argc, char **argv) {NULL, 0, NULL, 0} }; - c = getopt_long(argc-1, argv+1, "+hc:p:g:", + c = getopt_long(argc-1, argv+1, "+hc:p:g:a", long_options, &option_index); if (c == -1) break; @@ -179,6 +224,9 @@ void trace_setup_guest(int argc, char **argv) pdie("group %s does not exist", optarg); gid = group->gr_gid; break; + case 'a': + attach = true; + break; default: usage(argv); } @@ -195,5 +243,5 @@ void trace_setup_guest(int argc, char **argv) if (nr_cpus <= 0) pdie("invalid number of cpus for guest %s", guest); - do_setup_guest(guest, nr_cpus, mode, gid); + do_setup_guest(guest, nr_cpus, mode, gid, attach); } diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 9a13d93..bcfd3dc 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -249,10 +249,11 @@ 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][-a] guest\n" " -c number of guest virtual CPUs\n" " -p FIFOs permissions (default: 0660)\n" " -g FIFOs group owner\n" + " -a Attach FIFOs to guest VM config\n" }, #endif {