Skip to contentSkip to conversation

xentop: add support for qdisks

PATCH In review Charles Arnold 3 participants 6 messages Mar 24, 2015 – Mar 31, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v3 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().

Libxl is modified to create a new socket dedicated for the use of libxenstat for querying the block statistics using QMP.

The current APIs remain unchanged. It works within the existing framework of libxenstat.

tools/libxl/libxl_dm.c +9 -0
index a8b08f2..d72cb1d 100644
@@ -454,6 +454,15 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
     flexarray_append(dm_args, "-mon");
     flexarray_append(dm_args, "chardev=libxl-cmd,mode=control");
 
+    flexarray_append(dm_args, "-chardev");
+    flexarray_append(dm_args,
+                     libxl__sprintf(gc, "socket,id=libxenstat-cmd,"
+                                    "path=%s/qmp-libxenstat-%d,server,nowait",
+                                    libxl__run_dir_path(), guest_domid));
+
+    flexarray_append(dm_args, "-mon");
+    flexarray_append(dm_args, "chardev=libxenstat-cmd,mode=control");
+
     for (i = 0; i < guest_config->num_channels; i++) {
         connection = guest_config->channels[i].connection;
         devid = guest_config->channels[i].devid;
tools/libxl/libxl_qmp.c +7 -0
index c7324e6..7f3731b 100644
@@ -723,6 +723,13 @@ void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid)
             LOGE(ERROR, "Failed to remove QMP socket file %s", qmp_socket);
         }
     }
+
+    qmp_socket = GCSPRINTF("%s/qmp-libxenstat-%d", libxl__run_dir_path(), domid);
+    if (unlink(qmp_socket) == -1) {
+        if (errno != ENOENT) {
+            LOGE(ERROR, "Failed to remove QMP socket file %s", qmp_socket);
+        }
+    }
 }
 
 int libxl__qmp_query_serial(libxl__qmp_handler *qmp)
tools/xenstat/libxenstat/Makefile +2 -2
index 07d39b1..7c973f8 100644
@@ -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
@@ -32,7 +32,7 @@ OBJECTS-$(CONFIG_FreeBSD) += src/xenstat_freebsd.o
 SONAME_FLAGS=-Wl,$(SONAME_LDFLAG) -Wl,libxenstat.so.$(MAJOR)
 
 CFLAGS+=-fPIC
-CFLAGS+=-Isrc $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(CFLAGS_xeninclude)
+CFLAGS+=-Isrc $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(CFLAGS_xeninclude) -include $(XEN_ROOT)/tools/config.h
 
 LDLIBS-y = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl)
 LDLIBS-$(CONFIG_SunOS) += -lkstat
tools/xenstat/libxenstat/src/xenstat.c +21 -0
index 8072a90..3ad89c4 100644
@@ -657,6 +657,27 @@ 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)
+{
+        xenstat_vbd *vbds = domain->vbds;
+
+        domain->num_vbds++;
+        domain->vbds = realloc(domain->vbds,
+                               domain->num_vbds *
+                               sizeof(xenstat_vbd));
+
+        if (domain->vbds == NULL) {
+                domain->num_vbds = 0;
+                free(vbds);
+        }
+        else {
+                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
index 7fdf70a..2cc9c7f 100644
@@ -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
index 8490e23..74e0774 100644
@@ -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
index e2665aa..5376fdc 100644
@@ -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 +450 -0

450 lines not on this page · raw message

#1 lore raw
Quoted 1 line · Charles Arnold

+/* Get up to 1024 active domains */

What I meant last time was, is this limitation a concern? What if there are 1025 domains?

If this is a concern then perhaps refactor such that the qdisk stats gathering collection can happen from the inner loop of xenstat_get_node, i.e. near the call to domain_get_tmem_stats, then you would be given the single domain of interest. Might simplify some other stuff too.

Ian.

#2 lore raw
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 1 line · Charles Arnold

+/* Get up to 1024 active domains */

What I meant last time was, is this limitation a concern? What if there are 1025 domains?

This is actually a limit I picked up from libxl. See libxl.c libxl_list_domain() which is consumed in several places. I guess I assumed this was some official limit. This version of the patch would simply ignore any VMs beyond 1024.

Quoted 5 lines

If this is a concern then perhaps refactor such that the qdisk stats gathering collection can happen from the inner loop of xenstat_get_node, i.e. near the call to domain_get_tmem_stats, then you would be given the single domain of interest. Might simplify some other stuff too.

This would certainly eliminate the 1024 limit. This may become important for running xentop in batch mode where the output can be captured. For normal screen viewing, I doubt anyone has a screen with more that 1024 lines on which to view the output :)

I'll code up another version with your suggestion.

- Charles

#3 lore raw
Quoted 11 lines · Charles Arnold
Quoted 7 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 1 line · Charles Arnold

+/* Get up to 1024 active domains */

What I meant last time was, is this limitation a concern? What if there are 1025 domains?

This is actually a limit I picked up from libxl. See libxl.c libxl_list_domain() which is consumed in several places. I guess I assumed this was some official limit. This version of the patch would simply ignore any VMs beyond 1024.

Hrm, that libxl limit is also somewhat unfortunate :-(. In theory xc_domain_getinfolist can be used a bit more flexibly to get slices of domains, although getting a consistent snapshot might be tricky. One to fix for sure though.

Quoted 9 lines
Quoted 4 lines

If this is a concern then perhaps refactor such that the qdisk stats gathering collection can happen from the inner loop of xenstat_get_node, i.e. near the call to domain_get_tmem_stats, then you would be given the single domain of interest. Might simplify some other stuff too.

This would certainly eliminate the 1024 limit. This may become important for running xentop in batch mode where the output can be captured. For normal screen viewing, I doubt anyone has a screen with more that 1024 lines on which to view the output :)

:-). I'm not sure if there is anyone out there who uses libxenstat directly for other purposes, but I suppose it isn't impossible.

Quoted 1 line

I'll code up another version with your suggestion.

Thanks, given the libxl limit I'm wondering about just taking v3 of this patch and taking what would otherwise have been v4 as an improvement.

Ian, Wei, any thoughts?

Ian.

#4 lore raw

On Tue, Mar 24, 2015 at 04:59:47PM +0000, Ian Campbell wrote:
[...]

Quoted 4 lines
Quoted 3 lines

for running xentop in batch mode where the output can be captured. For normal screen viewing, I doubt anyone has a screen with more that 1024 lines on which to view the output :)

Quoted 8 lines

:-). I'm not sure if there is anyone out there who uses libxenstat directly for other purposes, but I suppose it isn't impossible.

Quoted 1 line

I'll code up another version with your suggestion.

Thanks, given the libxl limit I'm wondering about just taking v3 of this patch and taking what would otherwise have been v4 as an improvement.

Agreed.

Wei.

#5 lore raw
Quoted 9 lines · Wei Liu

On Tue, Mar 24, 2015 at 04:59:47PM +0000, Ian Campbell wrote:
[...]

Quoted 7 lines
Quoted 3 lines

for running xentop in batch mode where the output can be captured. For normal screen viewing, I doubt anyone has a screen with more that 1024 lines on which to view the output :)

:-). I'm not sure if there is anyone out there who uses libxenstat directly for other purposes, but I suppose it isn't impossible.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I'll code up another version with your suggestion.

Thanks, given the libxl limit I'm wondering about just taking v3 of this patch and taking what would otherwise have been v4 as an improvement.

Agreed.

OK, Acked + applied.

Ian.