xentop: add support for qdisks
PATCH v2 1/1 xentop: add support for qdisks
Now that Xen uses qdisks by default and qemu does not write out statistics to sysfs this patch queries the QMP for disk statistics.
This patch depends on libyajl for parsing statistics returned from QMP. The runtime requires libyajl 2.0.3 or newer for required bug fixes in yajl_tree_parse().
No interfaces have been changed. It works within the existing framework of libxenstat.
tools/xenstat/libxenstat/Makefile +1 -1
@@ -24,7 +24,7 @@ MINOR=0 LIB=src/libxenstat.a SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR) SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so -OBJECTS-y=src/xenstat.o +OBJECTS-y=src/xenstat.o src/xenstat_qmp.o OBJECTS-$(CONFIG_Linux) += src/xenstat_linux.o OBJECTS-$(CONFIG_SunOS) += src/xenstat_solaris.o OBJECTS-$(CONFIG_NetBSD) += src/xenstat_netbsd.o
tools/xenstat/libxenstat/src/xenstat.c +18 -0
@@ -657,6 +657,24 @@ static void xenstat_uninit_xen_version(xenstat_handle * handle)* VBD functions */ +/* Save VBD information */ +xenstat_vbd *xenstat_save_vbd (xenstat_domain *domain,xenstat_vbd *vbd) +{ +if (domain->vbds ==NULL ) { + domain->num_vbds =1 ; + domain->vbds =malloc (sizeof (xenstat_vbd)); + }else { + domain->num_vbds++; + domain->vbds =realloc (domain->vbds, + domain->num_vbds * +sizeof (xenstat_vbd)); + } +if (domain->vbds !=NULL ) + domain->vbds[domain->num_vbds -1 ] = *vbd; + +return domain->vbds; +} +/* Free VBD information */ static void xenstat_free_vbds (xenstat_node * node) {
tools/xenstat/libxenstat/src/xenstat_linux.c +6 -11
@@ -417,6 +417,9 @@ int xenstat_collect_vbds(xenstat_node * node) } } +/* Get qdisk statistics */ +read_attributes_qdisk (node); +rewinddir (priv->sysfsvbd); for(dp = readdir(priv->sysfsvbd); dp != NULL ;
@@ -477,18 +480,10 @@ int xenstat_collect_vbds(xenstat_node * node)continue ; } -if (domain->vbds ==NULL ) { - domain->num_vbds =1 ; - domain->vbds =malloc (sizeof (xenstat_vbd)); - }else { - domain->num_vbds++; - domain->vbds =realloc (domain->vbds, - domain->num_vbds * -sizeof (xenstat_vbd)); - } -if (domain->vbds ==NULL ) +if ((xenstat_save_vbd (domain, &vbd)) ==NULL ) { +perror ("Allocation error" );return 0 ; - domain->vbds[domain->num_vbds -1 ] = vbd; + } }return 1 ;
tools/xenstat/libxenstat/src/xenstat_priv.h +2 -0
@@ -109,5 +109,7 @@ extern int xenstat_collect_networks(xenstat_node * node);extern void xenstat_uninit_networks (xenstat_handle * handle);extern int xenstat_collect_vbds (xenstat_node * node);extern void xenstat_uninit_vbds (xenstat_handle * handle); +extern void read_attributes_qdisk (xenstat_node * node); +extern xenstat_vbd *xenstat_save_vbd (xenstat_domain * domain,xenstat_vbd * vbd);#endif /* XENSTAT_PRIV_H */
tools/xenstat/xentop/Makefile +1 -1
@@ -19,7 +19,7 @@ all install xentop: else CFLAGS += -DGCC_PRINTF -Werror $(CFLAGS_libxenstat) -LDLIBS += $(LDLIBS_libxenstat) $(CURSES_LIBS) $(SOCKET_LIBS) -lm +LDLIBS += $(LDLIBS_libxenstat) $(CURSES_LIBS) $(SOCKET_LIBS) -lm -lyajl CFLAGS += -DHOST_$(XEN_OS) # Include configure output (config.h) to headers search path
tools/xenstat/libxenstat/src/xenstat_qmp.c new file +387 -0
387 lines not on this page · raw message
Quoted 6 lines · Charles Arnold
Now that Xen uses qdisks by default and qemu does not write out statistics to sysfs this patch queries the QMP for disk statistics.
This patch depends on libyajl for parsing statistics returned from QMP. The runtime requires libyajl 2.0.3 or newer for required bug fixes in
yajl_tree_parse().
Elsewhere we currently support libyajl1 even, which means that this is all configure tests for.
You say bug fixes here, but the code comment says:
/* Use libyajl version 2.1.x or newer for the tree parser feature with bug fixes */
which suggests it perhaps didn't even exist in earlier versions. Also I note the quoted versions differ, FWIW.
Whether the interface exists (even in buggy form) or not in older versions is important because if it doesn't exist then that would be a build failure, which we would want to avoid.
Whereas a functional failure would perhaps be tolerable. However, given the existing HAVE_YAJL_YAJL_VERSION_H define I think the code could easily check if the YAJL library is good enough at compile time and stub itself out -- i.e. not report qdisk stats if the yajl doesn't do the job.
My second concern here is with the use of /var/run/xen/qmp-libxl-%i from outside of libxl. I can't remember if qemu is safe against multiple users of the socket. ISTR asking Anthony this before, but I don't recall the answer, sorry :-(
Even if it is strictly speaking ok it seems a bit warty to do it, but perhaps for an in-tree user like libxenstat it is tolerable. Alternatively we could (relatively) easily arrange for their to be a second qemp-libxenstat-%i socket, assuming the qemu overhead of a second one is sane.
Would it be possible to include somewhere, either in a code comment or in the changelog, an example of the JSON response to the QMP commands.
(I'm also consistently surprised by the lack of a qmp client library, but that's not your fault!)
Quoted 10 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-0@@ -657,6 +657,24 @@ static void xenstat_uninit_xen_version(xenstat_handle * handle)* VBD functions */ +/* Save VBD information */ +xenstat_vbd *xenstat_save_vbd (xenstat_domain *domain,xenstat_vbd *vbd)
tools/xenstat/libxenstat/src/xenstat.c static void xenstat_uninit_xen_version(xenstat_handle * handle) · line 671
Quoted 10 lines
tools/xenstat/libxenstat/src/xenstat.c +10
-0+{ +if (domain->vbds ==NULL ) { + domain->num_vbds =1 ; + domain->vbds =malloc (sizeof (xenstat_vbd)); + }else { + domain->num_vbds++; + domain->vbds =realloc (domain->vbds, + domain->num_vbds * +sizeof (xenstat_vbd)); + }
FYI realloc handles the old pointer being NULL just fine, so you don't need to special case that so long as num_vbds starts out initialised to 0.
Also, if realloc returns NULL then you need to have remembered the old value to free it, else it gets leaked.
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 488
Quoted 13 lines
tools/xenstat/libxenstat/src/xenstat.c +0
-9@@ -477,18 +480,10 @@ int xenstat_collect_vbds(xenstat_node * node)continue ; } -if (domain->vbds ==NULL ) { - domain->num_vbds =1 ; - domain->vbds =malloc (sizeof (xenstat_vbd)); - }else { - domain->num_vbds++; - domain->vbds =realloc (domain->vbds, - domain->num_vbds * -sizeof (xenstat_vbd)); - }
Oh, I see my comments above were actually on the old code you were moving.
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 484
Quoted 2 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-0+/* Use libyajl version 2.1.x or newer for the tree parser feature with bug fixes */ +if ((info =yajl_tree_parse ((char *)qmp_stats, errbuf,sizeof (errbuf))) ==NULL ) {
You don't want to log something using errbuf? If not then it may as well be as small as possible.
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 486
Quoted 2 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-0+/* Use libyajl version 2.0.3 or newer for the tree parser feature */ +if ((info =yajl_tree_parse ((char *)stats_buf, errbuf,sizeof (errbuf))) ==NULL )
Likewise.
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 487
Quoted 1 line
tools/xenstat/libxenstat/src/xenstat.c +1
-0+/* Get all the active domains */
actually only up to 1024 of them ;-)
Ian.
Quoted 12 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 6 lines · Charles Arnold
Now that Xen uses qdisks by default and qemu does not write out statistics to sysfs this patch queries the QMP for disk statistics.
This patch depends on libyajl for parsing statistics returned from QMP. The runtime requires libyajl 2.0.3 or newer for required bug fixes in
yajl_tree_parse().Elsewhere we currently support libyajl1 even, which means that this is all configure tests for.
Quoted 6 lines
You say bug fixes here, but the code comment says:
/* Use libyajl version 2.1.x or newer for the tree parser feature with bug
fixes */which suggests it perhaps didn't even exist in earlier versions. Also I note the quoted versions differ, FWIW.
I looked it up in libyajl's ChangeLog and noticed it was fixed specifically in 2.0.3 and noted that in the patch header but failed to go back and fix the code comment. I'll fix the code comment.
Quoted 4 lines
Whether the interface exists (even in buggy form) or not in older versions is important because if it doesn't exist then that would be a build failure, which we would want to avoid.
Right. The tree feature was added in version 2.0.0 (again according to the ChangeLog file). I guess you would prefer not making this a requirement in tools/configure given the statement below.
Quoted 6 lines
Whereas a functional failure would perhaps be tolerable. However, given the existing
HAVE_YAJL_YAJL_VERSION_Hdefine I think the code could easily check if the YAJL library is good enough at compile time and stub itself out -- i.e. not report qdisk stats if the yajl doesn't do the job.
Ok, I'll do it this way.
Quoted 11 lines
My second concern here is with the use of /var/run/xen/qmp-libxl-%i from outside of libxl. I can't remember if qemu is safe against multiple users of the socket. ISTR asking Anthony this before, but I don't recall the answer, sorry :-(
Even if it is strictly speaking ok it seems a bit warty to do it, but perhaps for an in-tree user like libxenstat it is tolerable. Alternatively we could (relatively) easily arrange for their to be a second qemp-libxenstat-%i socket, assuming the qemu overhead of a second one is sane.
As a test I modified libxl to create a qmp-libxenstat-%i socket and updated libxenstat to use it instead of qmp-libxl-%i. It works fine although I don't know if there is any performance penalty for having a second socket. I am ok with going with this solution if this is preferred.
Quoted 3 lines
Would it be possible to include somewhere, either in a code comment or in the changelog, an example of the JSON response to the QMP commands.
No problem.
Quoted 38 lines
(I'm also consistently surprised by the lack of a qmp client library, but that's not your fault!)
Review
Quoted 1 line
(quoted diff) +0
-0
b/tools/xenstat/libxenstat/src/xenstat.ctools/xenstat/libxenstat/src/xenstat.c static void xenstat_uninit_xen_version(xenstat_handle *
Quoted 4 lines
index 8072a90..f3847be 100644
tools/xenstat/libxenstat/src/xenstat.c +0
-0@@ -657,6 +657,24 @@ static void xenstat_uninit_xen_version(xenstat_handle *handle)
Quoted 5 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-0* VBD functions */ +/* Save VBD information */ +xenstat_vbd *xenstat_save_vbd (xenstat_domain *domain,xenstat_vbd *vbd)tools/xenstat/libxenstat/src/xenstat.c static void xenstat_uninit_xen_version(xenstat_handle * handle) · line 671
Quoted 10 lines
tools/xenstat/libxenstat/src/xenstat.c +10
-0+{ +if (domain->vbds ==NULL ) { + domain->num_vbds =1 ; + domain->vbds =malloc (sizeof (xenstat_vbd)); + }else { + domain->num_vbds++; + domain->vbds =realloc (domain->vbds, + domain->num_vbds * +sizeof (xenstat_vbd)); + }FYI realloc handles the old pointer being NULL just fine, so you don't need to special case that so long as
num_vbdsstarts out initialised to 0.Also, if realloc returns NULL then you need to have remembered the old value to free it, else it gets leaked.
Quoted 4 lines
tools/xenstat/libxenstat/src/xenstat.c +0
-0@@ -477,18 +480,10 @@ int xenstat_collect_vbds(xenstat_node * node)continue ; }
Quoted 12 lines
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 488
Quoted 9 lines
tools/xenstat/libxenstat/src/xenstat.c +0
-9-if (domain->vbds ==NULL ) { - domain->num_vbds =1 ; - domain->vbds =malloc (sizeof (xenstat_vbd)); - }else { - domain->num_vbds++; - domain->vbds =realloc (domain->vbds, - domain->num_vbds * -sizeof (xenstat_vbd)); - }Oh, I see my comments above were actually on the old code you were moving.
I'll look at fixing this up based on your realloc comments above.
Quoted 9 lines
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 483
Quoted 3 lines
tools/xenstat/libxenstat/src/xenstat.c +1
-0+/* Use libyajl version 2.1.x or newer for the tree parser feature with bug fixes */
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 484
Quoted 1 line
tools/xenstat/libxenstat/src/xenstat.c +1
-0+ if ((info = yajl_tree_parse((char *)qmp_stats, errbuf, sizeof(errbuf))) ==NULL) {
You don't want to log something using errbuf? If not then it may as well be as small as possible.
Ok.
Quoted 6 lines
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 486
Quoted 3 lines
tools/xenstat/libxenstat/src/xenstat.c +2
-0+/* Use libyajl version 2.0.3 or newer for the tree parser feature */ + if ((info = yajl_tree_parse((char *)stats_buf, errbuf, sizeof(errbuf))) ==NULL)
Likewise.
Ok.
Quoted 4 lines
tools/xenstat/libxenstat/src/xenstat.c int xenstat_collect_vbds(xenstat_node * node) · line 487
Quoted 2 lines
tools/xenstat/libxenstat/src/xenstat.c +1
-0+/* Get all the active domains */ actually only up to 1024 of them ;-)
Ok.
Thanks for the review!
- Charles
Quoted 7 lines · Charles Arnold
Quoted 3 lines
Whether the interface exists (even in buggy form) or not in older versions is important because if it doesn't exist then that would be a build failure, which we would want to avoid.
Right. The tree feature was added in version 2.0.0 (again according to the ChangeLog file). I guess you would prefer not making this a requirement in
tools/configuregiven the statement below.
Right, I think we don't want to make a global requirement for yajl >= 2.0.0 (or 2.0.3) just yet so making xenstat fallback gracefully is probably the best option.
Quoted 7 lines
Quoted 5 lines
Whereas a functional failure would perhaps be tolerable. However, given the existing
HAVE_YAJL_YAJL_VERSION_Hdefine I think the code could easily check if the YAJL library is good enough at compile time and stub itself out -- i.e. not report qdisk stats if the yajl doesn't do the job.Ok, I'll do it this way.
Thanks. FWIW if HAVE_YAJL_YAJL_VERSION_H is not set then you can assume v1 (as libxl_json.h does).
Quoted 11 lines
Quoted 10 lines
My second concern here is with the use of /var/run/xen/qmp-libxl-%i from outside of libxl. I can't remember if qemu is safe against multiple users of the socket. ISTR asking Anthony this before, but I don't recall the answer, sorry :-(
Even if it is strictly speaking ok it seems a bit warty to do it, but perhaps for an in-tree user like libxenstat it is tolerable. Alternatively we could (relatively) easily arrange for their to be a second qemp-libxenstat-%i socket, assuming the qemu overhead of a second one is sane.
Quoted 4 lines
As a test I modified libxl to create a qmp-libxenstat-%i socket and updated libxenstat to use it instead of qmp-libxl-%i. It works fine although I don't know if there is any performance penalty for having a second socket. I am ok with going with this solution if this is preferred.
I'm fine with this unless someone gives a good reason not to do it.
Quoted 4 lines
Quoted 2 lines
Oh, I see my comments above were actually on the old code you were moving.
I'll look at fixing this up based on your realloc comments above.
Thanks!
Ian.
Quoted 4 lines · Ian Campbell
My second concern here is with the use of /var/run/xen/qmp-libxl-%i from outside of libxl. I can't remember if qemu is safe against multiple users of the socket. ISTR asking Anthony this before, but I don't recall the answer, sorry :-(
Last time I checked, only one client at a time can connect to the socket. If a second user want to connect to the socket, it will be blocked until the first one disconnect.
Signature · 1 line
Anthony PERARD
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Anthony PERARD
Quoted 4 lines · Ian Campbell
My second concern here is with the use of /var/run/xen/qmp-libxl-%i from outside of libxl. I can't remember if qemu is safe against multiple users of the socket. ISTR asking Anthony this before, but I don't recall the answer, sorry :-(
Last time I checked, only one client at a time can connect to the socket. If a second user want to connect to the socket, it will be blocked until the first one disconnect.
This seems correct based on some of my testing. In rare cases (perhaps not so rare for VMs under heavy I/O load), reading the socket to get the stats times out and so xentop will report '0' for the read/write stats until the next read attempt that succeeds.
It looks as if we do need a second socket to qemu. I will include that in the next patch version.
- Charles
Quoted 11 lines · Charles Arnold
Quoted 10 lines
Quoted 1 line
Quoted 1 line · Anthony PERARD
Quoted 4 lines · Ian Campbell
My second concern here is with the use of /var/run/xen/qmp-libxl-%i from outside of libxl. I can't remember if qemu is safe against multiple users of the socket. ISTR asking Anthony this before, but I don't recall the answer, sorry :-(
Last time I checked, only one client at a time can connect to the socket. If a second user want to connect to the socket, it will be blocked until the first one disconnect.
Quoted 7 lines
This seems correct based on some of my testing. In rare cases (perhaps not so rare for VMs under heavy I/O load), reading the socket to get the stats times out and so xentop will report '0' for the read/write stats until the next read attempt that succeeds.
It looks as if we do need a second socket to qemu. I will include that in the next patch version.
Yep, it sounds like it is a requirement, thanks.
Ian.