linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Slavomir Kaslev <kaslevs@vmware.com>
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 09/11] trace-cmd: Make setup-guest auto attach FIFOs to the guest VM config
Date: Mon,  4 Feb 2019 08:58:46 +0200	[thread overview]
Message-ID: <20190204065848.8248-10-kaslevs@vmware.com> (raw)
In-Reply-To: <20190204065848.8248-1-kaslevs@vmware.com>

This patch tries to attach the newly created FIFOs for guest tracing as virtio
serial devices to libvirt managed guests.

Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
---
 tracecmd/trace-setup-guest.c | 41 ++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tracecmd/trace-setup-guest.c b/tracecmd/trace-setup-guest.c
index bcd8f40..3176b7e 100644
--- a/tracecmd/trace-setup-guest.c
+++ b/tracecmd/trace-setup-guest.c
@@ -118,6 +118,43 @@ static int get_guest_cpu_count(const char *guest)
 	return nr_cpus;
 }
 
+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 =
+		"<channel type='pipe'>\n"
+		"  <source path='%s'/>\n"
+		"  <target type='virtio' name='%s%d'/>\n"
+		"</channel>";
+	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 = -1;
+			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)
 {
 	gid_t save_egid;
@@ -136,6 +173,10 @@ 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);
 
+	ret = attach_guest_fifos(guest, nr_cpus);
+	if (ret < 0)
+		warning("failed to attach FIFOs to %s", guest);
+
 	ret = setegid(save_egid);
 	if (ret < 0)
 		pdie("failed to restore effective group ID");
-- 
2.19.1


  parent reply	other threads:[~2019-02-04  6:59 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04  6:58 [RFC PATCH v5 00/11] Add VM kernel tracing over vsockets and FIFOs Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 01/11] trace-cmd: Detect if vsockets are available Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 02/11] trace-cmd: Add tracecmd_create_recorder_virt function Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 03/11] trace-cmd: Add TRACE_REQ and TRACE_RESP messages Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 04/11] trace-cmd: Add buffer instance flags for tracing in guest and agent context Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 05/11] trace-cmd: Add VM kernel tracing over vsockets transport Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 06/11] trace-cmd: Use splice(2) for vsockets if available Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 07/11] trace-cmd: Add `trace-cmd setup-guest` command Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 08/11] trace-cmd: Try to autodetect number of guest CPUs in setup-guest if not specified Slavomir Kaslev
2019-02-04  6:58 ` Slavomir Kaslev [this message]
2019-02-04  6:58 ` [RFC PATCH v5 10/11] trace-cmd: Set both input and output to non-blocking when recording is stopped Slavomir Kaslev
2019-02-04  6:58 ` [RFC PATCH v5 11/11] trace-cmd: Add VM tracing over FIFOs transport Slavomir Kaslev
2019-02-08 21:03 ` [RFC PATCH v5 00/11] Add VM kernel tracing over vsockets and FIFOs Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190204065848.8248-10-kaslevs@vmware.com \
    --to=kaslevs@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=slavomir.kaslev@gmail.com \
    --cc=tstoyanov@vmware.com \
    --cc=ykaradzhov@vmware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).