[PATCH V4 4/5] trace-cmd/virt-server: Add --dom option which makes a domain directory to virt-server

2014-07-10 Thread Yoshihiro YUNOMAE
Add --dom option which makes a domain directory to virt-server. When a user
already knows domain name of a guest before running virt-server, trace-cmd
should automatically set up I/Fs of the guest. By adding --dom option,
trace-cmd creates a domain directory with 0710 and qemu group.

This patch adds additional options for --dom as follows:

-m 
   This option changes the permission of domain directory. If you don't use
   this option, the default permission is 0710.

-g 
   This option changes group of domain directory. If you don't use this option,
   the default group is qemu.

-c 
   This option creates trace data I/Fs(trace-path-cpu*.{in,out}) for each CPU
   of 'domain'. If you don't use this option, those files are not created.

Here, an example you use this option is written as follows:

- trace-cmd creates a guest1 directory with trace data I/Fs of 2 CPUs.
   # trace-cmd virt-server --dom guest1 -c 2

- trace-cmd creates guest2 and guest3 directories
   # trace-cmd virt-server --dom guest2 -c 3 --dom guest3 -c 1

Changes in V4: Introduce parse_args_virt()
   Add usage of virt-server in trace-usage.c

Signed-off-by: Yoshihiro YUNOMAE 
---
 Documentation/trace-cmd-virt-server.1.txt |   56 ---
 trace-listen.c|  151 ++---
 trace-usage.c |5 +
 3 files changed, 178 insertions(+), 34 deletions(-)

diff --git a/Documentation/trace-cmd-virt-server.1.txt 
b/Documentation/trace-cmd-virt-server.1.txt
index 4168a04..fbd0ad6 100644
--- a/Documentation/trace-cmd-virt-server.1.txt
+++ b/Documentation/trace-cmd-virt-server.1.txt
@@ -34,40 +34,64 @@ OPTIONS
 *-l* 'filename'::
 This option writes the output messages to a log file instead of standard 
output.
 
+*--dom* 'domain'::
+This option makes a directory for the 'domain'. You can use additional 
options
+*-m*, *-g*, *-c* after this option for the 'domain'. If you don't use these
+additional options, the directory is made as 0710 and qemu group and
+trace data I/Fs(trace-path-cpu*.{in,out}) are not created.
+
+*-m* 'permission'::
+This option changes the permission of 'domain' directory. If you don't use
+this option, the default permission is 0710.
+
+*-g* 'group'::
+This option changes group of 'domain' directory. If you don't use this 
option,
+the default group is qemu.
+
+*-c* 'cpu'::
+This option creates trace data I/Fs(trace-path-cpu*.{in,out}) for each CPU
+of 'domain'. If you don't use this option, those files are not created.
+
 SET UP
 --
 Here, an example is written as follows:
 
 1. Run virt-server on a host
-   # trace-cmd virt-server
-
-2. Make guest domain directory
-   # mkdir -p /tmp/trace-cmd/virt/
-   # chmod 710 /tmp/trace-cmd/virt/
-   # chgrp qemu /tmp/trace-cmd/virt/
-
-3. Make FIFO on the host
-   # mkfifo /tmp/trace-cmd/virt//trace-path-cpu{0,1,...,X}.{in,out}
+   # trace-cmd virt-server --dom guest1 -c 2
 
-4. Set up of virtio-serial pipe of a guest on the host
+2. Set up of virtio-serial pipe of guest1 on the host
Add the following tags to domain XML files.
-   # virsh edit 
+   # virsh edit guest1

   
   


-  
+  
   

-   ... (cpu1, cpu2, ...)
+   
+  
+  
+   
 
-5. Boot the guest
-   # virsh start 
+3. Boot the guest
+   # virsh start guest1
 
-6. Run the guest's client(see trace-cmd-record(1) with the *--virt* option)
+4. Run the guest1's client(see trace-cmd-record(1) with the *--virt* option)
# trace-cmd record -e sched* --virt
 
+If you want to boot another guest sends trace-data via virtio-serial,
+you will manually make the guest domain directory and trace data I/Fs.
+
+- Make guest domain directory on the host
+   # mkdir -p /tmp/trace-cmd/virt/
+   # chmod 710 /tmp/trace-cmd/virt/
+   # chgrp qemu /tmp/trace-cmd/virt/
+
+- Make FIFO on the host
+   # mkfifo /tmp/trace-cmd/virt//trace-path-cpu{0,1,...,X}.{in,out}
+
 SEE ALSO
 
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
diff --git a/trace-listen.c b/trace-listen.c
index 01b7ebf..e424c2a 100644
--- a/trace-listen.c
+++ b/trace-listen.c
@@ -54,11 +54,21 @@ static int backlog = 5;
 
 static int proto_ver;
 
+struct domain_dir {
+   struct domain_dir *next;
+   char *name;
+   char *group;
+   mode_t perms;
+   int cpu;
+};
+
 enum {
NET = 1,
VIRT= 2,
 };
 
+struct domain_dir *dom_dir_list;
+
 #define  TEMP_FILE_STR_NET "%s.%s:%s.cpu%d", output_file, host, port, cpu
 #define  TEMP_FILE_STR_VIRT "%s.%s:%d.cpu%d", output_file, domain, virtpid, cpu
 static char *get_temp_file(const char *host, const char *port,
@@ -382,7 +392,9 @@ static int open_udp(const char *node, const char *port, int 
*pid,
 #define TRACE_CMD_DIR  "/tmp/trace-cmd/"
 #define VIRT_DIR   TRACE_CMD_DIR "virt/"
 #define VIRT_TRACE_CTL_SOCKVIRT_DIR "agent-ctl-path"
-#define TRACE_PATH_DOMAIN_CPU  

[PATCH V4 4/5] trace-cmd/virt-server: Add --dom option which makes a domain directory to virt-server

2014-07-10 Thread Yoshihiro YUNOMAE
Add --dom option which makes a domain directory to virt-server. When a user
already knows domain name of a guest before running virt-server, trace-cmd
should automatically set up I/Fs of the guest. By adding --dom option,
trace-cmd creates a domain directory with 0710 and qemu group.

This patch adds additional options for --dom as follows:

-m permission
   This option changes the permission of domain directory. If you don't use
   this option, the default permission is 0710.

-g group
   This option changes group of domain directory. If you don't use this option,
   the default group is qemu.

-c cpu
   This option creates trace data I/Fs(trace-path-cpu*.{in,out}) for each CPU
   of 'domain'. If you don't use this option, those files are not created.

Here, an example you use this option is written as follows:

- trace-cmd creates a guest1 directory with trace data I/Fs of 2 CPUs.
   # trace-cmd virt-server --dom guest1 -c 2

- trace-cmd creates guest2 and guest3 directories
   # trace-cmd virt-server --dom guest2 -c 3 --dom guest3 -c 1

Changes in V4: Introduce parse_args_virt()
   Add usage of virt-server in trace-usage.c

Signed-off-by: Yoshihiro YUNOMAE yoshihiro.yunomae...@hitachi.com
---
 Documentation/trace-cmd-virt-server.1.txt |   56 ---
 trace-listen.c|  151 ++---
 trace-usage.c |5 +
 3 files changed, 178 insertions(+), 34 deletions(-)

diff --git a/Documentation/trace-cmd-virt-server.1.txt 
b/Documentation/trace-cmd-virt-server.1.txt
index 4168a04..fbd0ad6 100644
--- a/Documentation/trace-cmd-virt-server.1.txt
+++ b/Documentation/trace-cmd-virt-server.1.txt
@@ -34,40 +34,64 @@ OPTIONS
 *-l* 'filename'::
 This option writes the output messages to a log file instead of standard 
output.
 
+*--dom* 'domain'::
+This option makes a directory for the 'domain'. You can use additional 
options
+*-m*, *-g*, *-c* after this option for the 'domain'. If you don't use these
+additional options, the directory is made as 0710 and qemu group and
+trace data I/Fs(trace-path-cpu*.{in,out}) are not created.
+
+*-m* 'permission'::
+This option changes the permission of 'domain' directory. If you don't use
+this option, the default permission is 0710.
+
+*-g* 'group'::
+This option changes group of 'domain' directory. If you don't use this 
option,
+the default group is qemu.
+
+*-c* 'cpu'::
+This option creates trace data I/Fs(trace-path-cpu*.{in,out}) for each CPU
+of 'domain'. If you don't use this option, those files are not created.
+
 SET UP
 --
 Here, an example is written as follows:
 
 1. Run virt-server on a host
-   # trace-cmd virt-server
-
-2. Make guest domain directory
-   # mkdir -p /tmp/trace-cmd/virt/DOMAIN
-   # chmod 710 /tmp/trace-cmd/virt/DOMAIN
-   # chgrp qemu /tmp/trace-cmd/virt/DOMAIN
-
-3. Make FIFO on the host
-   # mkfifo /tmp/trace-cmd/virt/DOMAIN/trace-path-cpu{0,1,...,X}.{in,out}
+   # trace-cmd virt-server --dom guest1 -c 2
 
-4. Set up of virtio-serial pipe of a guest on the host
+2. Set up of virtio-serial pipe of guest1 on the host
Add the following tags to domain XML files.
-   # virsh edit guest domain
+   # virsh edit guest1
channel type='unix'
   source mode='connect' path='/tmp/trace-cmd/virt/agent-ctl-path'/
   target type='virtio' name='agent-ctl-path'/
/channel
channel type='pipe'
-  source path='/tmp/trace-cmd/virt/DOMAIN/trace-path-cpu0'/
+  source path='/tmp/trace-cmd/virt/guest1/trace-path-cpu0'/
   target type='virtio' name='trace-path-cpu0'/
/channel
-   ... (cpu1, cpu2, ...)
+   channel type='pipe'
+  source path='/tmp/trace-cmd/virt/guest1/trace-path-cpu1'/
+  target type='virtio' name='trace-path-cpu1'/
+   /channel
 
-5. Boot the guest
-   # virsh start DOMAIN
+3. Boot the guest
+   # virsh start guest1
 
-6. Run the guest's client(see trace-cmd-record(1) with the *--virt* option)
+4. Run the guest1's client(see trace-cmd-record(1) with the *--virt* option)
# trace-cmd record -e sched* --virt
 
+If you want to boot another guest sends trace-data via virtio-serial,
+you will manually make the guest domain directory and trace data I/Fs.
+
+- Make guest domain directory on the host
+   # mkdir -p /tmp/trace-cmd/virt/DOMAIN
+   # chmod 710 /tmp/trace-cmd/virt/DOMAIN
+   # chgrp qemu /tmp/trace-cmd/virt/DOMAIN
+
+- Make FIFO on the host
+   # mkfifo /tmp/trace-cmd/virt/DOMAIN/trace-path-cpu{0,1,...,X}.{in,out}
+
 SEE ALSO
 
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-start(1),
diff --git a/trace-listen.c b/trace-listen.c
index 01b7ebf..e424c2a 100644
--- a/trace-listen.c
+++ b/trace-listen.c
@@ -54,11 +54,21 @@ static int backlog = 5;
 
 static int proto_ver;
 
+struct domain_dir {
+   struct domain_dir *next;
+   char *name;
+   char *group;
+   mode_t perms;
+   int cpu;
+};
+
 enum {
NET = 1,