[Libvir] [PATCH] typo
by Atsushi SAKAI
Hi,
I finally succeed for building libvirt on windows(MinGW/MSYS).
Thank you for coopration.
During that work I found several typo in libvirt document.
Thanks
Atsushi SAKAI
16 years, 11 months
[Libvir] tiny patch, FYI: Let "make syntax-check" pass.
by Jim Meyering
FYI I've just checked this in:
Let "make syntax-check" pass.
* .x-sc_avoid_if_before_free: Exempt ChangeLog.
* tests/statstest.c: Include <config.h>, not "config.h".
diff --git a/.x-sc_avoid_if_before_free b/.x-sc_avoid_if_before_free
index 627dcdf..f83ae7b 100644
--- a/.x-sc_avoid_if_before_free
+++ b/.x-sc_avoid_if_before_free
@@ -2,3 +2,4 @@
^gnulib/lib/printf-parse\.c$
^gnulib/lib/vasnprintf\.c$
^build-aux/find-unnecessary-if-before-free$
+^ChangeLog$
diff --git a/tests/statstest.c b/tests/statstest.c
index 7fa6f46..4c19833 100644
--- a/tests/statstest.c
+++ b/tests/statstest.c
@@ -1,4 +1,4 @@
-#include "config.h"
+#include <config.h>
#include <stdio.h>
#include <stdlib.h>
16 years, 11 months
[Libvir] VIR_DOMAIN_NOSTATE
by Russ Blaine
On Solaris-based xen 3.1.2 I am seeing virDomainGetInfo() often returning
VIR_DOMAIN_NOSTATE in dominfo.state for domUs that are powered on and
running. What exactly does VIR_DOMAIN_NOSTATE mean? Why does it exist? I
suspect it is a catch-all in the API for hosts that don't entirely have
their act together, that do not always return a valid guest state. Is that
the case?
Is anyone else seeing this on Xen?
--
-----------------------------------------------------
Russ Blaine | Solaris Kernel | russell.blaine(a)sun.com
16 years, 11 months
[Libvir] PATCH: Fix block device numbers for virDomainBlockStats
by Daniel P. Berrange
As mentioned in this thread:
http://www.redhat.com/archives/libvir-list/2008-January/msg00475.html
The code for calculating block devices numbers has a number of flaws.
This patch fixes the flaws and adds a comprehensive test program to
validate it. The test program also validates invalid cases.
NB, this code is actually now more perfect than Xen, since Xen doesn't
handle SCSI disks > sdp, even though you can go all the way to sdhv.
The rules are:
* hdNM: N=a-t, M=1-63, major={IDE0_MAJOR -> IDE9_MAJOR}
* sdNM: N=a-z,aa-hw, M=1-15, major={SCSI_DISK0_MAJOR -> SCSI_DISK15_MAJOR}
* xvdNM: N=a-p, M=1-15, major=XENVBD_MAJOR
Which translates to the formulas
xvdNM: (XENVBD_MAJOR * 256) + (disk * 16) + part;
sdNM: (majors[disk/16] * 256) + ((disk%16) * 16) + part
hdNM: (majors[disk/2] * 256) + ((disk % 2) * 63) + part;
The SCSI/IDE formulas lookup the major number in a table since
they are allocated non-contigously.
The test case validates these:
$ ./statstest
xvda == 51712 OK
xvda1 == 51713 OK
xvda15 == 51727 OK
xvdp == 51952 OK
xvdp1 == 51953 OK
xvdp15 == 51967 OK
xvdq == -1 OK
xvd1 == -1 OK
xvda16 == -1 OK
xvda0 == -1 OK
hda == 768 OK
hda1 == 769 OK
hda63 == 831 OK
hdd == 5695 OK
hdd1 == 5696 OK
hdd63 == 5758 OK
hdt == 23359 OK
hdt1 == 23360 OK
hdt63 == 23422 OK
hdu == -1 OK
hd1 == -1 OK
hda64 == -1 OK
hda0 == -1 OK
sda == 2048 OK
sda1 == 2049 OK
sda15 == 2063 OK
sdp == 2288 OK
sdp1 == 2289 OK
sdp15 == 2303 OK
sdq == 16640 OK
sdq1 == 16641 OK
sdq15 == 16655 OK
sdz == 16784 OK
sdz1 == 16785 OK
sdz15 == 16799 OK
sdaa == 16800 OK
sdaa1 == 16801 OK
sdaa15 == 16815 OK
sdab == 16816 OK
sdab1 == 16817 OK
sdab15 == 16831 OK
sdba == 17216 OK
sdba1 == 17217 OK
sdba15 == 17231 OK
sdiv == 34800 OK
sdiv1 == 34801 OK
sdiv15 == 34815 OK
sdix == -1 OK
sd1 == -1 OK
sda16 == -1 OK
sda0 == -1 OK
/dev == -1 OK
/dev/ == -1 OK
/dev/xvd == -1 OK
/dev/xvda == 51712 OK
/dev/xvda1 == 51713 OK
/dev/xvda15 == 51727 OK
The patch also fixes a couple of error codes to be INTERNAL_ERROR rather
than NO_SUPPORT, because the latter is for APIs which are not supported,
where as the conditions here are simply errors that shouldn't happen.
Dan.
Index: src/stats_linux.c
===================================================================
RCS file: /data/cvs/libvirt/src/stats_linux.c,v
retrieving revision 1.6
diff -u -p -r1.6 stats_linux.c
--- src/stats_linux.c 20 Nov 2007 10:58:21 -0000 1.6
+++ src/stats_linux.c 27 Jan 2008 20:08:27 -0000
@@ -179,7 +179,7 @@ read_bd_stats (virConnectPtr conn, xenUn
if (stats->rd_req == -1 && stats->rd_bytes == -1 &&
stats->wr_req == -1 && stats->wr_bytes == -1 &&
stats->errs == -1) {
- statsErrorFunc (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__,
+ statsErrorFunc (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
"Failed to read any block statistics", domid);
return -1;
}
@@ -192,7 +192,7 @@ read_bd_stats (virConnectPtr conn, xenUn
stats->wr_req == 0 && stats->wr_bytes == 0 &&
stats->errs == 0 &&
!check_bd_connected (priv, device, domid)) {
- statsErrorFunc (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__,
+ statsErrorFunc (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
"Frontend block device not connected", domid);
return -1;
}
@@ -202,7 +202,7 @@ read_bd_stats (virConnectPtr conn, xenUn
*/
if (stats->rd_bytes > 0) {
if (stats->rd_bytes >= ((unsigned long long)1)<<(63-9)) {
- statsErrorFunc (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__,
+ statsErrorFunc (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
"stats->rd_bytes would overflow 64 bit counter",
domid);
return -1;
@@ -211,7 +211,7 @@ read_bd_stats (virConnectPtr conn, xenUn
}
if (stats->wr_bytes > 0) {
if (stats->wr_bytes >= ((unsigned long long)1)<<(63-9)) {
- statsErrorFunc (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__,
+ statsErrorFunc (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
"stats->wr_bytes would overflow 64 bit counter",
domid);
return -1;
@@ -223,61 +223,149 @@ read_bd_stats (virConnectPtr conn, xenUn
}
int
-xenLinuxDomainBlockStats (xenUnifiedPrivatePtr priv,
- virDomainPtr dom,
- const char *path,
- struct _virDomainBlockStats *stats)
+xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *path)
{
- int minor, device;
+ int disk, part = 0;
- /* Paravirt domains:
- * Paths have the form "xvd[a-]" and map to paths
- * /sys/devices/xen-backend/(vbd|tap)-domid-major:minor/
- * statistics/(rd|wr|oo)_req.
- * The major:minor is in this case fixed as 202*256 + minor*16
- * where minor is 0 for xvda, 1 for xvdb and so on.
+ /* Strip leading path if any */
+ if (strlen(path) > 5 &&
+ STREQLEN(path, "/dev/", 5))
+ path += 5;
+
+ /*
+ * Possible block device majors & partition ranges. This
+ * matches the ranges supported in Xend xen/util/blkif.py
+ *
+ * hdNM: N=a-t, M=1-63, major={IDE0_MAJOR -> IDE9_MAJOR}
+ * sdNM: N=a-z,aa-hw, M=1-15, major={SCSI_DISK0_MAJOR -> SCSI_DISK15_MAJOR}
+ * xvdNM: N=a-p, M=1-15, major=XENVBD_MAJOR
*
- * XXX Not clear what happens to device numbers for devices
- * >= xdvo (minor >= 16), which would otherwise overflow the
- * 256 minor numbers assigned to this major number. So we
- * currently limit you to the first 16 block devices per domain.
+ * NB, the SCSI major isn't technically correct, as there can be
+ * many SCSI major numbers as per IDE majors. XenD only knows about
+ * major=8 so we follow same limitation (for now).
+ *
+ * The path for statistics will be
+ *
+ * /sys/devices/xen-backend/(vbd|tap)-{domid}-{devid}/statistics/{...}
*/
- if (strlen (path) == 4 &&
+
+ if (strlen (path) >= 4 &&
STREQLEN (path, "xvd", 3)) {
- if ((minor = path[3] - 'a') < 0 || minor >= 16) {
- statsErrorFunc (dom->conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
- "invalid path, should be xvda, xvdb, etc.",
- dom->id);
+ /* Xen paravirt device handling */
+ disk = (path[3] - 'a');
+ if (disk < 0 || disk > 15) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, device names must be in range xvda - xvdp",
+ domid);
return -1;
}
- device = XENVBD_MAJOR * 256 + minor * 16;
- return read_bd_stats (dom->conn, priv, device, dom->id, stats);
- }
- /* Fullvirt domains:
- * hda, hdb etc map to major = HD_MAJOR*256 + minor*16.
- *
- * See comment above about devices >= hdo.
- */
- else if (strlen (path) == 3 &&
- STREQLEN (path, "hd", 2)) {
- if ((minor = path[2] - 'a') < 0 || minor >= 16) {
- statsErrorFunc (dom->conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
- "invalid path, should be hda, hdb, etc.",
- dom->id);
+ if (path[4] != '\0') {
+ if (xstrtol_i(path+4, NULL, 10, &part) < 0 ||
+ part < 1 || part > 15) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, partition numbers for xvdN must be in range 1 - 15",
+ domid);
+ return -1;
+ }
+ }
+
+ return (XENVBD_MAJOR * 256) + (disk * 16) + part;
+ } else if (strlen (path) >= 3 &&
+ STREQLEN (path, "sd", 2)) {
+ /* SCSI device handling */
+ int majors[] = { SCSI_DISK0_MAJOR, SCSI_DISK1_MAJOR, SCSI_DISK2_MAJOR,
+ SCSI_DISK3_MAJOR, SCSI_DISK4_MAJOR, SCSI_DISK5_MAJOR,
+ SCSI_DISK6_MAJOR, SCSI_DISK7_MAJOR, SCSI_DISK8_MAJOR,
+ SCSI_DISK9_MAJOR, SCSI_DISK10_MAJOR, SCSI_DISK11_MAJOR,
+ SCSI_DISK12_MAJOR, SCSI_DISK13_MAJOR, SCSI_DISK14_MAJOR,
+ SCSI_DISK15_MAJOR };
+
+ disk = (path[2] - 'a');
+ if (disk < 0 || disk > 25) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, device names must be in range sda - sdiw",
+ domid);
return -1;
}
- device = HD_MAJOR * 256 + minor * 16;
+ if (path[3] != '\0') {
+ if (path[3] >= 'a' && path[3] <= 'z') {
+ disk = ((disk + 1) * 26) + (path[3] - 'a');
+ if (disk < 0 || disk > 255) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, device names must be in range sda - sdiw",
+ domid);
+ return -1;
+ }
+
+ if (path[4] != '\0') {
+ if (xstrtol_i(path+4, NULL, 10, &part) < 0 ||
+ part < 1 || part > 15) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, partition numbers for sdN must be in range 1 - 15",
+ domid);
+ return -1;
+ }
+ }
+ } else {
+ if (xstrtol_i(path+3, NULL, 10, &part) < 0 ||
+ part < 1 || part > 15) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, partition numbers for sdN must be in range 1 - 15",
+ domid);
+ return -1;
+ }
+ }
+ }
- return read_bd_stats (dom->conn, priv, device, dom->id, stats);
+ return (majors[disk/16] * 256) + ((disk%16) * 16) + part;
+ } else if (strlen (path) >= 3 &&
+ STREQLEN (path, "hd", 2)) {
+ /* IDE device handling */
+ int majors[] = { IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR,
+ IDE4_MAJOR, IDE5_MAJOR, IDE6_MAJOR, IDE7_MAJOR,
+ IDE8_MAJOR, IDE9_MAJOR };
+ disk = (path[2] - 'a');
+ if (disk < 0 || disk > 19) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, device names must be in range sda - sdp",
+ domid);
+ return -1;
+ }
+
+ if (path[3] != '\0') {
+ if (xstrtol_i(path+3, NULL, 10, &part) < 0 ||
+ part < 1 || part > 63) {
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "invalid path, partition numbers for sdN must be in range 1 - 15",
+ domid);
+ return -1;
+ }
+ }
+
+ return (majors[disk/2] * 256) + ((disk % 2) * 63) + part;
}
/* Otherwise, unsupported device name. */
- statsErrorFunc (dom->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__,
- "unsupported path (use xvda, hda, etc.)", dom->id);
+ statsErrorFunc (conn, VIR_ERR_INVALID_ARG, __FUNCTION__,
+ "unsupported path, use xvdN, hdN, or sdN", domid);
return -1;
}
+int
+xenLinuxDomainBlockStats (xenUnifiedPrivatePtr priv,
+ virDomainPtr dom,
+ const char *path,
+ struct _virDomainBlockStats *stats)
+{
+ int device = xenLinuxDomainDeviceID(dom->conn, dom->id, path);
+
+ if (device < 0)
+ return -1;
+
+ return read_bd_stats (dom->conn, priv, device, dom->id, stats);
+}
+
#endif /* WITH_XEN */
/*-------------------- interface stats --------------------*/
@@ -296,7 +384,7 @@ linuxDomainInterfaceStats (virConnectPtr
fp = fopen ("/proc/net/dev", "r");
if (!fp) {
- statsErrorFunc (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__,
+ statsErrorFunc (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
"/proc/net/dev", errno);
return -1;
}
@@ -352,7 +440,7 @@ linuxDomainInterfaceStats (virConnectPtr
}
fclose (fp);
- statsErrorFunc (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__,
+ statsErrorFunc (conn, VIR_ERR_INTERNAL_ERROR, __FUNCTION__,
"/proc/net/dev: Interface not found", 0);
return -1;
}
Index: src/stats_linux.h
===================================================================
RCS file: /data/cvs/libvirt/src/stats_linux.h,v
retrieving revision 1.1
diff -u -p -r1.1 stats_linux.h
--- src/stats_linux.h 14 Nov 2007 11:58:36 -0000 1.1
+++ src/stats_linux.h 27 Jan 2008 20:08:27 -0000
@@ -21,6 +21,8 @@ extern int xenLinuxDomainBlockStats (xen
extern int linuxDomainInterfaceStats (virConnectPtr conn, const char *path,
struct _virDomainInterfaceStats *stats);
+extern int xenLinuxDomainDeviceID(virConnectPtr conn, int domid, const char *dev);
+
#endif /* __linux__ */
#endif /* __STATS_LINUX_H__ */
Index: tests/.cvsignore
===================================================================
RCS file: /data/cvs/libvirt/tests/.cvsignore,v
retrieving revision 1.10
diff -u -p -r1.10 .cvsignore
--- tests/.cvsignore 25 Jul 2007 23:16:30 -0000 1.10
+++ tests/.cvsignore 27 Jan 2008 20:08:27 -0000
@@ -13,6 +13,7 @@ xencapstest
qemuxml2xmltest
qemuxml2argvtest
nodeinfotest
+statstest
*.gcda
*.gcno
Index: tests/Makefile.am
===================================================================
RCS file: /data/cvs/libvirt/tests/Makefile.am,v
retrieving revision 1.34
diff -u -p -r1.34 Makefile.am
--- tests/Makefile.am 12 Dec 2007 07:21:37 -0000 1.34
+++ tests/Makefile.am 27 Jan 2008 20:08:27 -0000
@@ -44,7 +44,7 @@ EXTRA_DIST = \
noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \
reconnect xmconfigtest xencapstest qemuxml2argvtest qemuxml2xmltest \
- nodeinfotest
+ nodeinfotest statstest
test_scripts = \
daemon-conf \
@@ -122,6 +122,10 @@ nodeinfotest_SOURCES = \
nodeinfotest.c testutils.h testutils.c
nodeinfotest_LDADD = $(LDADDS)
+statstest_SOURCES = \
+ statstest.c testutils.h testutils.c
+statstest_LDADD = $(LDADDS)
+
reconnect_SOURCES = \
reconnect.c
reconnect_LDADD = $(LDADDS)
Index: tests/statstest.c
===================================================================
RCS file: tests/statstest.c
diff -N tests/statstest.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/statstest.c 27 Jan 2008 20:08:27 -0000
@@ -0,0 +1,218 @@
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "stats_linux.h"
+#include "internal.h"
+
+static void testQuietError(void *userData ATTRIBUTE_UNUSED, virErrorPtr error ATTRIBUTE_UNUSED)
+{
+ /* nada */
+}
+
+#ifdef __linux__
+static int testDevice(const char *path, int expect)
+{
+ int actual = xenLinuxDomainDeviceID(NULL, 1, path);
+
+ if (actual == expect) {
+ fprintf(stderr, "%-14s == %-6d OK\n", path, expect);
+ return 0;
+ } else {
+ fprintf(stderr, "%-14s == %-6d (%-6d) FAILED\n", path, expect, actual);
+ return -1;
+ }
+}
+#endif
+
+int
+main(void)
+{
+ int ret = 0;
+#ifdef __linux__
+ /* Some of our tests delibrately test failure cases, so
+ * register a handler to stop error messages cluttering
+ * up display
+ */
+ if (!getenv("DEBUG_TESTS"))
+ virSetErrorFunc(NULL, testQuietError);
+
+ /********************************
+ * Xen paravirt disks
+ ********************************/
+
+ /* first valid disk */
+ if (testDevice("xvda", 51712) < 0)
+ ret = -1;
+ if (testDevice("xvda1", 51713) < 0)
+ ret = -1;
+ if (testDevice("xvda15", 51727) < 0)
+ ret = -1;
+ /* Last valid disk */
+ if (testDevice("xvdp", 51952) < 0)
+ ret = -1;
+ if (testDevice("xvdp1", 51953) < 0)
+ ret = -1;
+ if (testDevice("xvdp15", 51967) < 0)
+ ret = -1;
+
+ /* Disk letter to large */
+ if (testDevice("xvdq", -1) < 0)
+ ret = -1;
+ /* missing disk letter */
+ if (testDevice("xvd1", -1) < 0)
+ ret = -1;
+ /* partition to large */
+ if (testDevice("xvda16", -1) < 0)
+ ret = -1;
+ /* partition to small */
+ if (testDevice("xvda0", -1) < 0)
+ ret = -1;
+
+
+ /********************************
+ * IDE disks
+ ********************************/
+
+ /* odd numbered disk */
+ if (testDevice("hda", 768) < 0)
+ ret = -1;
+ if (testDevice("hda1", 769) < 0)
+ ret = -1;
+ if (testDevice("hda63", 831) < 0)
+ ret = -1;
+ /* even number disk */
+ if (testDevice("hdd", 5695) < 0)
+ ret = -1;
+ if (testDevice("hdd1", 5696) < 0)
+ ret = -1;
+ if (testDevice("hdd63", 5758) < 0)
+ ret = -1;
+ /* last valid disk */
+ if (testDevice("hdt", 23359) < 0)
+ ret = -1;
+ if (testDevice("hdt1", 23360) < 0)
+ ret = -1;
+ if (testDevice("hdt63", 23422) < 0)
+ ret = -1;
+
+ /* Disk letter to large */
+ if (testDevice("hdu", -1) < 0)
+ ret = -1;
+ /* missing disk letter */
+ if (testDevice("hd1", -1) < 0)
+ ret = -1;
+ /* partition to large */
+ if (testDevice("hda64", -1) < 0)
+ ret = -1;
+ /* partition to small */
+ if (testDevice("hda0", -1) < 0)
+ ret = -1;
+
+
+
+ /********************************
+ * SCSI disks
+ ********************************/
+
+ /* first valid disk */
+ if (testDevice("sda", 2048) < 0)
+ ret = -1;
+ if (testDevice("sda1", 2049) < 0)
+ ret = -1;
+ if (testDevice("sda15", 2063) < 0)
+ ret = -1;
+ /* last valid disk of first SCSI major number */
+ if (testDevice("sdp", 2288) < 0)
+ ret = -1;
+ if (testDevice("sdp1", 2289) < 0)
+ ret = -1;
+ if (testDevice("sdp15", 2303) < 0)
+ ret = -1;
+ /* first valid disk of second SCSI major number */
+ if (testDevice("sdq", 16640) < 0)
+ ret = -1;
+ if (testDevice("sdq1", 16641) < 0)
+ ret = -1;
+ if (testDevice("sdq15", 16655) < 0)
+ ret = -1;
+ /* last valid single letter disk */
+ if (testDevice("sdz", 16784) < 0)
+ ret = -1;
+ if (testDevice("sdz1", 16785) < 0)
+ ret = -1;
+ if (testDevice("sdz15", 16799) < 0)
+ ret = -1;
+ /* first valid dual letter disk */
+ if (testDevice("sdaa", 16800) < 0)
+ ret = -1;
+ if (testDevice("sdaa1", 16801) < 0)
+ ret = -1;
+ if (testDevice("sdaa15", 16815) < 0)
+ ret = -1;
+ /* first valid dual letter disk */
+ if (testDevice("sdab", 16816) < 0)
+ ret = -1;
+ if (testDevice("sdab1", 16817) < 0)
+ ret = -1;
+ if (testDevice("sdab15", 16831) < 0)
+ ret = -1;
+ /* second sequence of dual letter disk */
+ if (testDevice("sdba", 17216) < 0)
+ ret = -1;
+ if (testDevice("sdba1", 17217) < 0)
+ ret = -1;
+ if (testDevice("sdba15", 17231) < 0)
+ ret = -1;
+ /* last valid dual letter disk */
+ if (testDevice("sdiv", 34800) < 0)
+ ret = -1;
+ if (testDevice("sdiv1", 34801) < 0)
+ ret = -1;
+ if (testDevice("sdiv15", 34815) < 0)
+ ret = -1;
+
+ /* Disk letter to large */
+ if (testDevice("sdix", -1) < 0)
+ ret = -1;
+ /* missing disk letter */
+ if (testDevice("sd1", -1) < 0)
+ ret = -1;
+ /* partition to large */
+ if (testDevice("sda16", -1) < 0)
+ ret = -1;
+ /* partition to small */
+ if (testDevice("sda0", -1) < 0)
+ ret = -1;
+
+
+ /* Path stripping */
+
+ /* first valid disk */
+ if (testDevice("/dev", -1) < 0)
+ ret = -1;
+ if (testDevice("/dev/", -1) < 0)
+ ret = -1;
+ if (testDevice("/dev/xvd", -1) < 0)
+ ret = -1;
+ if (testDevice("/dev/xvda", 51712) < 0)
+ ret = -1;
+ if (testDevice("/dev/xvda1", 51713) < 0)
+ ret = -1;
+ if (testDevice("/dev/xvda15", 51727) < 0)
+ ret = -1;
+
+#endif
+ exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE);
+}
+
+/*
+ * Local variables:
+ * indent-tabs-mode: nil
+ * c-indent-level: 4
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
16 years, 11 months
[Libvir] update after changing XML
by Maxwell Bottiger
Hi,
I changed some of the XML for a qemu virtual machine. The original
file was generated by virt-manager, but I wanted to use bridged
networking as described in the documentation on the libvirt website. Is
there something I need to for my xml changes to show up in the virtual
machine? Right now my VM will not start because it's looking for it's
old network configuration.
-Max
This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail.
16 years, 11 months
[Libvir] [PATCH] virtinst: don't expect non-root users to have block device access
by Guido Guenther
Hi,
attached patch drops the assumption that a non-root user has read access
to the guest OSes partition - he doesn't need to since all interaction
is handled via libvirt and giving the user read access for a simple MBR
block read test seems like overkill. Please apply if appropriate, patch
is against current hg.
Cheers,
-- Guido
# HG changeset patch
# User agx(a)sigxcpu.org
# Date 1201618288 -3600
# Node ID 96a103cd78dc7616a2e1e54f2e100fe156bebafd
# Parent 5109856f3bedf3b8eff7f78ce881b39bf8d30029
Don't fail if a non root user can't read from the block device due to insufficient permissions
diff -r 5109856f3bed -r 96a103cd78dc virtinst/DistroManager.py
--- a/virtinst/DistroManager.py Thu Jan 10 20:34:27 2008 -0500
+++ b/virtinst/DistroManager.py Tue Jan 29 15:51:28 2008 +0100
@@ -22,6 +22,7 @@
import logging
import os
+import errno
import gzip
import re
import struct
@@ -239,7 +240,14 @@ class DistroInstaller(Guest.Installer):
def post_install_check(self, guest):
# Check for the 0xaa55 signature at the end of the MBR
- fd = os.open(guest._install_disks[0].path, os.O_RDONLY)
+ try:
+ fd = os.open(guest._install_disks[0].path, os.O_RDONLY)
+ except OSError, (err, msg):
+ logging.debug("Failed to open guest disk: %s" % msg)
+ if err == errno.EACCES and os.geteuid() != 0:
+ return True # non root might not have access to block devices
+ else:
+ raise
buf = os.read(fd, 512)
os.close(fd)
return len(buf) == 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,)
@@ -284,7 +292,14 @@ class PXEInstaller(Guest.Installer):
def post_install_check(self, guest):
# Check for the 0xaa55 signature at the end of the MBR
- fd = os.open(guest._install_disks[0].path, os.O_RDONLY)
+ try:
+ fd = os.open(guest._install_disks[0].path, os.O_RDONLY)
+ except OSError, (err, msg):
+ logging.debug("Failed to open guest disk: %s" % msg)
+ if err == errno.EACCES and os.geteuid() != 0:
+ return True # non root might not have access to block devices
+ else:
+ raise
buf = os.read(fd, 512)
os.close(fd)
return len(buf) == 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaa55,)
16 years, 11 months
[Libvir] [PATCH] Avoid link errors with "configure --disable-shared".
by Jim Meyering
I tried to build static binaries in the usual libtool way,
via "configure --disable-shared" and got some link errors
due to the tests linking only with shared-lib-related files.
Here's the fix:
Avoid link errors with "configure --disable-shared".
* tests/Makefile.am (LDADDS): Add ../src/libvirt.la, so that
"configure --disable-shared" no longer provokes link errors.
---
tests/Makefile.am | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dfd9e34..1b5f287 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -33,6 +33,7 @@ LDADDS = \
$(SASL_LIBS) \
$(WARN_CFLAGS) \
$(LIBVIRT) \
+ ../src/libvirt.la \
../gnulib/lib/libgnu.la \
$(COVERAGE_LDFLAGS)
--
1.5.4.rc5.1.g0fa73
16 years, 11 months
[Libvir] 2/8 Add framework for code style- and syntax-checking rules.
by Jim Meyering
Add framework for code style- and syntax-checking rules.
Almost all tests are initially disabled via the list in Makefile.cfg.
* Makefile.am (EXTRA_DIST): Add .x-sc_avoid_if_before_free.
Omit names of files that automake includes automatically.
* .x-sc_avoid_if_before_free: New file.
* build-aux/vc-list-files: Likewise.
* build-aux/find-unnecessary-if-before-free: Likewise.
* GNUmakefile, Makefile.cfg, Makefile.maint: New files.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
.x-sc_avoid_if_before_free | 4 +
GNUmakefile | 58 ++++
Makefile.am | 8 +-
Makefile.cfg | 62 ++++
Makefile.maint | 510 +++++++++++++++++++++++++++++
build-aux/find-unnecessary-if-before-free | 41 +++
build-aux/vc-list-files | 50 +++
7 files changed, 730 insertions(+), 3 deletions(-)
create mode 100644 .x-sc_avoid_if_before_free
create mode 100644 GNUmakefile
create mode 100644 Makefile.cfg
create mode 100644 Makefile.maint
create mode 100755 build-aux/find-unnecessary-if-before-free
create mode 100755 build-aux/vc-list-files
diff --git a/.x-sc_avoid_if_before_free b/.x-sc_avoid_if_before_free
new file mode 100644
index 0000000..627dcdf
--- /dev/null
+++ b/.x-sc_avoid_if_before_free
@@ -0,0 +1,4 @@
+^gnulib/lib/getaddrinfo\.c$
+^gnulib/lib/printf-parse\.c$
+^gnulib/lib/vasnprintf\.c$
+^build-aux/find-unnecessary-if-before-free$
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644
index 0000000..9eefe40
--- /dev/null
+++ b/GNUmakefile
@@ -0,0 +1,58 @@
+# Having a separate GNUmakefile lets me `include' the dynamically
+# generated rules created via Makefile.maint as well as Makefile.maint itself.
+# This makefile is used only if you run GNU Make.
+# It is necessary if you want to build targets usually of interest
+# only to the maintainer.
+
+# Copyright (C) 2001, 2003, 2006-2007 Free Software Foundation, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Systems where /bin/sh is not the default shell need this. The $(shell)
+# command below won't work with e.g. stock DOS/Windows shells.
+ifeq ($(wildcard /bin/s[h]),/bin/sh)
+SHELL = /bin/sh
+else
+# will be used only with the next shell-test line, then overwritten
+# by a configured-in value
+SHELL = sh
+endif
+
+have-Makefile := $(shell test -f Makefile && echo yes)
+
+# If the user runs GNU make but has not yet run ./configure,
+# give them a diagnostic.
+ifeq ($(have-Makefile),yes)
+
+# Make tar archive easier to reproduce.
+export TAR_OPTIONS = --owner=0 --group=0 --numeric-owner
+
+include Makefile
+
+include $(srcdir)/Makefile.cfg
+include $(srcdir)/Makefile.maint
+
+else
+
+all:
+ @echo There seems to be no Makefile in this directory. 1>&2
+ @echo "You must run ./configure before running \`make'." 1>&2
+ @exit 1
+
+endif
+
+# Tell version 3.79 and up of GNU make to not build goals in this
+# directory in parallel. This is necessary in case someone tries to
+# build multiple targets on one command line.
+.NOTPARALLEL:
diff --git a/Makefile.am b/Makefile.am
index 34a1eb5..5154203 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,9 +5,11 @@ SUBDIRS = gnulib/lib include src qemud proxy docs gnulib/tests \
ACLOCAL_AMFLAGS = -I m4 -I gnulib/m4
-EXTRA_DIST = libvirt.spec.in libvirt.spec COPYING.LIB \
- libvirt.pc.in libvirt.pc TODO AUTHORS ChangeLog \
- NEWS README $(man_MANS) autobuild.sh
+EXTRA_DIST = \
+ libvirt.spec libvirt.spec.in \
+ libvirt.pc libvirt.pc.in \
+ $(man_MANS) autobuild.sh \
+ .x-sc_avoid_if_before_free
man_MANS = virsh.1
diff --git a/Makefile.cfg b/Makefile.cfg
new file mode 100644
index 0000000..f1194d1
--- /dev/null
+++ b/Makefile.cfg
@@ -0,0 +1,62 @@
+# Customize Makefile.maint. -*- makefile -*-
+# Copyright (C) 2003-2007 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Use alpha.gnu.org for alpha and beta releases.
+# Use ftp.gnu.org for major releases.
+gnu_ftp_host-alpha = alpha.gnu.org
+gnu_ftp_host-beta = alpha.gnu.org
+gnu_ftp_host-major = ftp.gnu.org
+gnu_rel_host = $(gnu_ftp_host-$(RELEASE_TYPE))
+
+url_dir_list = \
+ ftp://$(gnu_rel_host)/gnu/coreutils
+
+# Tests not to run as part of "make distcheck".
+local-checks-to-skip = \
+ po-check \
+ makefile_path_separator_check \
+ makefile-check \
+ sc_no_have_config_h \
+ sc_unmarked_diagnostics \
+ sc_tight_scope \
+ sc_trailing_blank \
+ sc_GPL_version \
+ sc_always_defined_macros \
+ sc_cast_of_alloca_return_value \
+ sc_cast_of_argument_to_free \
+ sc_cast_of_x_alloc_return_value \
+ sc_changelog \
+ sc_dd_max_sym_length \
+ sc_error_exit_success \
+ sc_file_system \
+ sc_obsolete_symbols \
+ sc_prohibit_assert_without_use \
+ sc_prohibit_atoi_atof \
+ sc_prohibit_jm_in_m4 \
+ sc_prohibit_quote_without_use \
+ sc_prohibit_quotearg_without_use \
+ sc_prohibit_strcmp \
+ sc_require_config_h \
+ sc_root_tests \
+ sc_space_tab \
+ sc_sun_os_names \
+ sc_system_h_headers \
+ sc_the_the \
+ sc_two_space_separator_in_usage \
+ sc_useless_cpp_parens \
+ patch-check \
+ check-AUTHORS \
+ changelog-check
diff --git a/Makefile.maint b/Makefile.maint
new file mode 100644
index 0000000..0336f13
--- /dev/null
+++ b/Makefile.maint
@@ -0,0 +1,510 @@
+# This is reported not to work with make-3.79.1
+# ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
+ME := Makefile.maint
+
+# Do not save the original name or timestamp in the .tar.gz file.
+# Use --rsyncable if available.
+gzip_rsyncable := \
+ $(shell gzip --help 2>/dev/null|grep rsyncable >/dev/null && echo --rsyncable)
+GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
+
+CVS_LIST = build-aux/vc-list-files
+
+CVS_LIST_EXCEPT = \
+$(CVS_LIST) | if test -f .x-$@; then grep -vEf .x-$@; else grep -v ChangeLog; fi
+
+# Prevent programs like 'sort' from considering distinct strings to be equal.
+# Doing it here saves us from having to set LC_ALL elsewhere in this file.
+export LC_ALL = C
+
+# Collect the names of rules starting with `sc_'.
+syntax-check-rules := $(shell sed -n 's/^\(sc_[a-zA-Z0-9_-]*\):.*/\1/p' $(ME))
+.PHONY: $(syntax-check-rules)
+
+# Checks that don't require cvs.
+# Run `changelog-check' last, as previous test may reveal problems requiring
+# new ChangeLog entries.
+local-checks-available = \
+ po-check copyright-check m4-check author_mark_check \
+ changelog-check patch-check strftime-check $(syntax-check-rules) \
+ makefile_path_separator_check \
+ makefile-check check-AUTHORS
+.PHONY: $(local-checks-available)
+
+local-check := $(filter-out $(local-checks-to-skip), $(local-checks-available))
+
+syntax-check: $(local-check)
+
+## --------------- ##
+## Sanity checks. ##
+## --------------- ##
+
+sc_avoid_if_before_free:
+ @$(srcdir)/build-aux/find-unnecessary-if-before-free \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found useless "if" before "free" above' 1>&2; \
+ exit 1; } || :
+
+sc_cast_of_argument_to_free:
+ @grep -nE '\<free \(\(' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): don'\''t cast free argument' 1>&2; \
+ exit 1; } || :
+
+sc_cast_of_x_alloc_return_value:
+ @grep -nE '\*\) *x(m|c|re)alloc\>' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): don'\''t cast x*alloc return value' 1>&2; \
+ exit 1; } || :
+
+sc_cast_of_alloca_return_value:
+ @grep -nE '\*\) *alloca\>' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): don'\''t cast alloca return value' 1>&2; \
+ exit 1; } || :
+
+sc_space_tab:
+ @grep -n '[ ] ' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found SPACE-TAB sequence; remove the SPACE' \
+ 1>&2; exit 1; } || :
+
+# Don't use *scanf or the old ato* functions in `real' code.
+# They provide no error checking mechanism.
+# Instead, use strto* functions.
+sc_prohibit_atoi_atof:
+ @grep -nE '\<([fs]?scanf|ato([filq]|ll))\>' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): do not use *scan''f, ato''f, ato''i, ato''l, ato''ll, ato''q, or ss''canf' \
+ 1>&2; exit 1; } || :
+
+# Use STREQ rather than comparing strcmp == 0, or != 0.
+sc_prohibit_strcmp:
+ @grep -nE '! *str''cmp \(|\<str''cmp \([^)]+\) *==' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): use STREQ in place of the above uses of str''cmp' \
+ 1>&2; exit 1; } || :
+
+# Using EXIT_SUCCESS as the first argument to error is misleading,
+# since when that parameter is 0, error does not exit. Use `0' instead.
+sc_error_exit_success:
+ @grep -nF 'error (EXIT_SUCCESS,' \
+ $$(find -type f -name '*.[chly]') && \
+ { echo '$(ME): found error (EXIT_SUCCESS' 1>&2; \
+ exit 1; } || :
+
+sc_file_system:
+ @grep -ni 'file''system' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found use of "file''system";' \
+ 'rewrite to use "file system"' 1>&2; \
+ exit 1; } || :
+
+sc_no_have_config_h:
+ @grep -n 'HAVE''_CONFIG_H' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found use of HAVE''_CONFIG_H; remove' \
+ 1>&2; exit 1; } || :
+
+# Nearly all .c files must include <config.h>.
+sc_require_config_h:
+ @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
+ grep -L '^# *include <config\.h>' \
+ $$($(CVS_LIST_EXCEPT) | grep '\.c$$') \
+ | grep . && \
+ { echo '$(ME): the above files do not include <config.h>' \
+ 1>&2; exit 1; } || :; \
+ else :; \
+ fi
+
+# Prohibit the inclusion of assert.h without an actual use of assert.
+sc_prohibit_assert_without_use:
+ @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
+ files=$$(grep -l '# *include <assert\.h>' \
+ $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
+ grep -L '\<assert (' $$files \
+ | grep . && \
+ { echo "$(ME): the above files include <assert.h> but don't use it" \
+ 1>&2; exit 1; } || :; \
+ else :; \
+ fi
+
+# Don't include quotearg.h unless you use one of its functions.
+sc_prohibit_quotearg_without_use:
+ @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
+ files=$$(grep -l '# *include "quotearg\.h"' \
+ $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
+ grep -LE '\<quotearg(_[^ ]+)? \(' $$files \
+ | grep . && \
+ { echo "$(ME): the above files include "quotearg.h" but don't use it" \
+ 1>&2; exit 1; } || :; \
+ else :; \
+ fi
+
+# Don't include quote.h unless you use one of its functions.
+sc_prohibit_quote_without_use:
+ @if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \
+ files=$$(grep -l '# *include "quote\.h"' \
+ $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) && \
+ grep -LE '\<quote(_n)? \(' $$files \
+ | grep . && \
+ { echo "$(ME): the above files include "quote.h" but don't use it" \
+ 1>&2; exit 1; } || :; \
+ else :; \
+ fi
+
+sc_obsolete_symbols:
+ @grep -nE '\<(HAVE''_FCNTL_H|O''_NDELAY)\>' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): do not use HAVE''_FCNTL_H or O''_NDELAY' \
+ 1>&2; exit 1; } || :
+
+# FIXME: warn about definitions of EXIT_FAILURE, EXIT_SUCCESS, STREQ
+
+# Each nonempty line must start with a year number, or a TAB.
+sc_changelog:
+ @grep -n '^[^12 ]' $$(find . -maxdepth 2 -name ChangeLog) && \
+ { echo '$(ME): found unexpected prefix in a ChangeLog' 1>&2; \
+ exit 1; } || :
+
+# Ensure that dd's definition of LONGEST_SYMBOL stays in sync
+# with the strings from the two affected variables.
+dd_c = $(srcdir)/src/dd.c
+sc_dd_max_sym_length:
+ifneq ($(wildcard $(dd_c)),)
+ @len=$$( (sed -n '/conversions\[\] =$$/,/^};/p' $(dd_c);\
+ sed -n '/flags\[\] =$$/,/^};/p' $(dd_c) ) \
+ |sed -n '/"/s/^[^"]*"\([^"]*\)".*/\1/p' \
+ | wc --max-line-length); \
+ max=$$(sed -n '/^#define LONGEST_SYMBOL /s///p' $(dd_c) \
+ |tr -d '"' | wc --max-line-length); \
+ if test "$$len" = "$$max"; then :; else \
+ echo 'dd.c: LONGEST_SYMBOL is not longest' 1>&2; \
+ exit 1; \
+ fi
+endif
+
+# Many m4 macros names once began with `jm_'.
+# On 2004-04-13, they were all changed to start with gl_ instead.
+# Make sure that none are inadvertently reintroduced.
+sc_prohibit_jm_in_m4:
+ @grep -nE 'jm_[A-Z]' \
+ $$($(CVS_LIST) m4 |grep '\.m4$$'; echo /dev/null) && \
+ { echo '$(ME): do not use jm_ in m4 macro names' \
+ 1>&2; exit 1; } || :
+
+sc_root_tests:
+ @if test -d tests \
+ && grep check-root tests/Makefile.am>/dev/null 2>&1; then \
+ t1=sc-root.expected; t2=sc-root.actual; \
+ grep -nl '^PRIV_CHECK_ARG=require-root' \
+ $$($(CVS_LIST) tests) |sed s,tests,., |sort > $$t1; \
+ sed -n 's, cd \([^ ]*\) .*MAKE..check TESTS=\(.*\),./\1/\2,p' \
+ $(srcdir)/tests/Makefile.am |sort > $$t2; \
+ diff -u $$t1 $$t2 || diff=1; \
+ rm -f $$t1 $$t2; \
+ test "$$diff" \
+ && { echo 'tests/Makefile.am: missing check-root action'>&2; \
+ exit 1; } || :; \
+ fi
+
+headers_with_interesting_macro_defs = \
+ exit.h \
+ fcntl_.h \
+ fnmatch_.h \
+ intprops.h \
+ inttypes_.h \
+ lchown.h \
+ openat.h \
+ stat-macros.h \
+ stdint_.h
+
+# Create a list of regular expressions matching the names
+# of macros that are guaranteed by parts of gnulib to be defined.
+.re-defmac:
+ @(cd $(srcdir)/lib; \
+ for f in $(headers_with_interesting_macro_defs); do \
+ test -f $$f && \
+ sed -n '/^# *define \([^_ (][^ (]*\)[ (].*/s//\1/p' $$f; \
+ done; \
+ ) | sort -u \
+ | grep -Ev 'ATTRIBUTE_NORETURN|SIZE_MAX' \
+ | sed 's/^/^# *define /' \
+ > $@-t
+ @mv $@-t $@
+
+# Don't define macros that we already get from gnulib header files.
+sc_always_defined_macros: .re-defmac
+ @if test -f $(srcdir)/src/system.h; then \
+ trap 'rc=$$?; rm -f .re-defmac; exit $$rc' 0 1 2 3 15; \
+ grep -f .re-defmac $$($(CVS_LIST)) \
+ && { echo '$(ME): define the above via some gnulib .h file' \
+ 1>&2; exit 1; } || :; \
+ fi
+
+# Create a list of regular expressions matching the names
+# of files included from system.h. Exclude a couple.
+.re-list:
+ @sed -n '/^# *include /s///p' $(srcdir)/src/system.h \
+ | grep -Ev 'sys/(param|file)\.h' \
+ | sed 's/ .*//;;s/^["<]/^# *include [<"]/;s/\.h[">]$$/\\.h[">]/' \
+ > $@-t
+ @mv $@-t $@
+
+# Files in src/ should not include directly any of
+# the headers already included via system.h.
+sc_system_h_headers: .re-list
+ @if test -f $(srcdir)/src/system.h; then \
+ trap 'rc=$$?; rm -f .re-list; exit $$rc' 0 1 2 3 15; \
+ grep -nE -f .re-list \
+ $$($(CVS_LIST) src | \
+ grep -Ev '((copy|system)\.h|parse-gram\.c)$$') \
+ && { echo '$(ME): the above are already included via system.h'\
+ 1>&2; exit 1; } || :; \
+ fi
+
+sc_sun_os_names:
+ @grep -nEi \
+ 'solaris[^[:alnum:]]*2\.(7|8|9|[1-9][0-9])|sunos[^[:alnum:]][6-9]' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found misuse of Sun OS version numbers' 1>&2; \
+ exit 1; } || :
+
+sc_the_the:
+ @grep -ni '\<the ''the\>' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found use of "the ''the";' 1>&2; \
+ exit 1; } || :
+
+sc_tight_scope:
+ $(MAKE) -C src $@
+
+sc_trailing_blank:
+ @grep -n '[ ]$$' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found trailing blank(s)' \
+ 1>&2; exit 1; } || :
+
+# Match lines like the following, but where there is only one space
+# between the options and the description:
+# -D, --all-repeated[=delimit-method] print all duplicate lines\n
+longopt_re = --[a-z][0-9A-Za-z-]*(\[?=[0-9A-Za-z-]*\]?)?
+sc_two_space_separator_in_usage:
+ @grep -nE '^ *(-[A-Za-z],)? $(longopt_re) [^ ].*\\$$' \
+ $$($(CVS_LIST_EXCEPT)) && \
+ { echo "$(ME): help2man requires at least two spaces between"; \
+ echo "$(ME): an option and its description"; \
+ 1>&2; exit 1; } || :
+
+# Look for diagnostics that aren't marked for translation.
+# This won't find any for which error's format string is on a separate line.
+sc_unmarked_diagnostics:
+ @grep -nE \
+ '\<error \([^"]*"[^"]*[a-z]{3}' $$($(CVS_LIST_EXCEPT)) \
+ | grep -v '_''(' && \
+ { echo '$(ME): found unmarked diagnostic(s)' 1>&2; \
+ exit 1; } || :
+
+# Avoid useless parentheses like those in this example:
+# #if defined (SYMBOL) || defined (SYM2)
+sc_useless_cpp_parens:
+ @grep -n '^# *if .*defined *(' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): found useless parentheses in cpp directive' \
+ 1>&2; exit 1; } || :
+
+# Require the latest GPL.
+sc_GPL_version:
+ @grep -n 'either ''version [^3]' $$($(CVS_LIST_EXCEPT)) && \
+ { echo '$(ME): GPL vN, N!=3' 1>&2; exit 1; } || :
+
+# Ensure that the c99-to-c89 patch applies cleanly.
+patch-check:
+ rm -rf src-c89 $@.1 $@.2
+ cp -a src src-c89
+ (cd src-c89; patch -p1 -V never --fuzz=0) < src/c99-to-c89.diff \
+ > $@.1 2>&1
+ if test "$$REGEN_PATCH" = yes; then \
+ diff -upr src src-c89 | sed 's,src-c89/,src/,' \
+ | grep -v '^Only in' > new-diff || : ; fi
+ grep -v '^patching file ' $@.1 > $@.2 || :
+ msg=ok; test -s $@.2 && msg='fuzzy patch' || : ; \
+ rm -f src-c89/*.o || msg='rm failed'; \
+ $(MAKE) -C src-c89 CFLAGS='-Wdeclaration-after-statement -Werror' \
+ || msg='compile failure with extra options'; \
+ test "$$msg" = ok && rm -rf src-c89 $@.1 $@.2 || echo "$$msg" 1>&2; \
+ test "$$msg" = ok
+
+# Ensure that date's --help output stays in sync with the info
+# documentation for GNU strftime. The only exception is %N,
+# which date accepts but GNU strftime does not.
+extract_char = sed 's/^[^%][^%]*%\(.\).*/\1/'
+strftime-check:
+ if test -f $(srcdir)/src/date.c; then \
+ grep '^ %. ' $(srcdir)/src/date.c | sort \
+ | $(extract_char) > $@-src; \
+ { echo N; \
+ info libc date calendar format | grep '^ `%.'\' \
+ | $(extract_char); } | sort > $@-info; \
+ diff -u $@-src $@-info || exit 1; \
+ rm -f $@-src $@-info; \
+ fi
+
+check-AUTHORS:
+ $(MAKE) -C src $@
+
+# Ensure that we use only the standard $(VAR) notation,
+# not @...@ in Makefile.am, now that we can rely on automake
+# to emit a definition for each substituted variable.
+makefile-check:
+ grep -nE '@[A-Z_0-9]+@' `find . -name Makefile.am` \
+ && { echo 'Makefile.maint: use $$(...), not @...@' 1>&2; exit 1; } || :
+
+news-date-check: NEWS
+ today=`date +%Y-%m-%d`; \
+ if head NEWS | grep '^\*.* $(VERSION_REGEXP) ('$$today')' \
+ >/dev/null; then \
+ :; \
+ else \
+ echo "version or today's date is not in NEWS" 1>&2; \
+ exit 1; \
+ fi
+
+changelog-check:
+ if head ChangeLog | grep 'Version $(VERSION_REGEXP)\.$$' \
+ >/dev/null; then \
+ :; \
+ else \
+ echo "$(VERSION) not in ChangeLog" 1>&2; \
+ exit 1; \
+ fi
+
+m4-check:
+ @grep -n 'AC_DEFUN([^[]' m4/*.m4 \
+ && { echo 'Makefile.maint: quote the first arg to AC_DEFUN' 1>&2; \
+ exit 1; } || :
+
+# Verify that all source files using _() are listed in po/POTFILES.in.
+# FIXME: don't hard-code file names below; use a more general mechanism.
+po-check:
+ if test -f po/POTFILES.in; then \
+ grep -E -v '^(#|$$)' po/POTFILES.in \
+ | grep -v '^src/false\.c$$' | sort > $@-1; \
+ files=; \
+ for file in $$($(CVS_LIST_EXCEPT)); do \
+ case $$file in \
+ *.[ch]) \
+ base=`expr " $$file" : ' \(.*\)\..'`; \
+ { test -f $$base.l || test -f $$base.y; } && continue;; \
+ *) continue;; \
+ esac; \
+ files="$$files $$file"; \
+ done; \
+ grep -E -l '\b(N?_|gettext *)\([^)"]*("|$$)' $$files \
+ | sort -u > $@-2; \
+ diff -u $@-1 $@-2 || exit 1; \
+ rm -f $@-1 $@-2; \
+ fi
+
+# In a definition of #define AUTHORS "... and ..." where the RHS contains
+# the English word `and', the string must be marked with `N_ (...)' so that
+# gettext recognizes it as a string requiring translation.
+author_mark_check:
+ @grep -n '^# *define AUTHORS "[^"]* and ' src/*.c |grep -v ' N_ (' && \
+ { echo 'Makefile.maint: enclose the above strings in N_ (...)' 1>&2; \
+ exit 1; } || :
+
+# Sometimes it is useful to change the PATH environment variable
+# in Makefiles. When doing so, it's better not to use the Unix-centric
+# path separator of `:', but rather the automake-provided `@PATH_SEPARATOR@'.
+# It'd be better to use `find -print0 ...|xargs -0 ...', but less portable,
+# and there probably aren't many projects with so many Makefile.am files
+# that we'd have to worry about limits on command line length.
+msg = 'Makefile.maint: Do not use `:'\'' above; use @PATH_SEPARATOR@ instead'
+makefile_path_separator_check:
+ @grep -n 'PATH=.*:' `find $(srcdir) -name Makefile.am` \
+ && { echo $(msg) 1>&2; exit 1; } || :
+
+# Check that `make alpha' will not fail at the end of the process.
+writable-files:
+ if test -d $(release_archive_dir); then :; else \
+ mkdir $(release_archive_dir); \
+ fi
+ for file in $(distdir).tar.gz $(xd-delta) \
+ $(release_archive_dir)/$(distdir).tar.gz \
+ $(release_archive_dir)/$(xd-delta); do \
+ test -e $$file || continue; \
+ test -w $$file \
+ || { echo ERROR: $$file is not writable; fail=1; }; \
+ done; \
+ test "$$fail" && exit 1 || :
+
+v_etc_file = lib/version-etc.c
+sample-test = tests/sample-test
+texi = doc/$(PACKAGE).texi
+# Make sure that the copyright date in $(v_etc_file) is up to date.
+# Do the same for the $(sample-test) and the main doc/.texi file.
+copyright-check:
+ @if test -f $(v_etc_file); then \
+ grep 'enum { COPYRIGHT_YEAR = '$$(date +%Y)' };' $(v_etc_file) \
+ >/dev/null \
+ || { echo 'out of date copyright in $(v_etc_file); update it' 1>&2; \
+ exit 1; }; \
+ fi
+ @if test -f $(sample-test); then \
+ grep '# Copyright (C) '$$(date +%Y)' Free' $(sample-test) \
+ >/dev/null \
+ || { echo 'out of date copyright in $(sample-test); update it' 1>&2; \
+ exit 1; }; \
+ fi
+ @if test -f $(texi); then \
+ grep 'Copyright @copyright{} .*'$$(date +%Y)' Free' $(texi) \
+ >/dev/null \
+ || { echo 'out of date copyright in $(texi); update it' 1>&2; \
+ exit 1; }; \
+ fi
+
+vc-diff-check:
+ $(VC) diff > vc-diffs || :
+ if test -s vc-diffs; then \
+ cat vc-diffs; \
+ echo "Some files are locally modified:" 1>&2; \
+ exit 1; \
+ else \
+ rm vc-diffs; \
+ fi
+
+cvs-check: vc-diff-check
+
+maintainer-distcheck:
+ $(MAKE) distcheck
+ $(MAKE) my-distcheck
+
+# Use -Wformat -Werror to detect format-string/arg-list mismatches.
+# Also, check for shadowing problems with -Wshadow, and for pointer
+# arithmetic problems with -Wpointer-arith.
+# These CFLAGS are pretty strict. If you build this target, you probably
+# have to have a recent version of gcc and glibc headers.
+# The for-loop below ensures that there is a bin/ directory full of all
+# of the programs under test (except the few that are required for basic
+# Makefile rules), all symlinked to the just-built "false" program.
+# This is to ensure that if ever a test neglects to make PATH include
+# the build srcdir, these always-failing programs will run.
+# Otherwise, it is too easy to test the wrong programs.
+# Note that "false" itself is a symlink to true, so it too will malfunction.
+TMPDIR ?= /tmp
+t=$(TMPDIR)/$(PACKAGE)/test
+my-distcheck: $(local-check) check
+ -rm -rf $(t)
+ mkdir -p $(t)
+ GZIP=$(GZIP_ENV) $(AMTAR) -C $(t) -zxf $(distdir).tar.gz
+ cd $(t)/$(distdir) \
+ && ./configure --disable-nls \
+ && $(MAKE) CFLAGS='$(warn_cflags)' \
+ AM_MAKEFLAGS='$(null_AM_MAKEFLAGS)' \
+ && $(MAKE) dvi \
+ && $(MAKE) distclean
+ (cd $(t) && mv $(distdir) $(distdir).old \
+ && $(AMTAR) -zxf - ) < $(distdir).tar.gz
+ diff -ur $(t)/$(distdir).old $(t)/$(distdir)
+ if test -f $(srcdir)/src/c99-to-c89.diff; then \
+ cd $(t)/$(distdir) \
+ && (cd src && patch -V never --fuzz=0 <c99-to-c89.diff) \
+ && ./configure --disable-largefile \
+ CFLAGS='-Werror -ansi -Wno-long-long' \
+ && $(MAKE); \
+ fi
+ -rm -rf $(t)
+ @echo "========================"; \
+ echo "$(distdir).tar.gz is ready for distribution"; \
+ echo "========================"
diff --git a/build-aux/find-unnecessary-if-before-free b/build-aux/find-unnecessary-if-before-free
new file mode 100755
index 0000000..2b415f9
--- /dev/null
+++ b/build-aux/find-unnecessary-if-before-free
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+# Detect instances of "if (p) free (p);".
+# Likewise for "if (p != NULL) free (p);".
+# Exit status is like grep: 0 for no match. 1 for any number.
+
+# Note: giving line numbers isn't practical, since I've reset the
+# input record separator.
+use strict;
+use warnings;
+(my $ME = $0) =~ s|.*/||;
+
+{
+ # Use ';' as the input record separator.
+ $/ = ';';
+
+ my $found_match = 0;
+ foreach my $file (@ARGV)
+ {
+ open FH, '<', $file
+ or die "$ME: can't open `$file' for reading: $!\n";
+ while (defined (my $line = <FH>))
+ {
+ if ($line =~
+ /\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)
+ \s+(?:sexpr_)?free\s*\(\s*\2\s*\))/sx)
+ {
+ print "$file: $1\n";
+ $found_match = 1;
+ }
+ }
+ close FH;
+ }
+ exit !$found_match;
+}
+
+my $foo = <<'EOF';
+# The above is to *find* them.
+# This adjusts them, removing the unnecessary "if (p)" part.
+
+perl -0x3b -pi -e 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+((?:sexpr_)?free\s*\(\s*\1\s*\))/$2/s' $(git ls-files|grep -v '^gnulib')
+EOF
diff --git a/build-aux/vc-list-files b/build-aux/vc-list-files
new file mode 100755
index 0000000..72a6f54
--- /dev/null
+++ b/build-aux/vc-list-files
@@ -0,0 +1,50 @@
+#!/bin/sh
+# List the specified version-controlled files.
+
+# Copyright (C) 2006, 2007 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+# List the specified version-controlled files.
+# With no argument, list them all.
+# This script must be run solely from the top of a $srcdir build directory.
+
+# If there's an argument, it must be a single, "."-relative directory name.
+# cvsu is part of the cvsutils package: http://www.red-bean.com/cvsutils/
+
+dir=
+case $# in
+ 0) ;;
+ 1) dir=$1 ;;
+ *) echo "$0: too many arguments" 1>&2; exit 1 ;;
+esac
+
+test "x$dir" = x && dir=.
+
+if test -d CVS; then
+ if test -x build-aux/cvsu; then
+ build-aux/cvsu --find --types=AFGM "$dir"
+ else
+ awk -F/ '{ \
+ if (!$1 && $3 !~ /^-/) { \
+ f=FILENAME; \
+ sub(/CVS\/Entries/, "", f); \
+ print f $2; \
+ }}' \
+ $(find ${*-*} -name Entries -print) /dev/null;
+ fi
+else
+ git-ls-files "$dir"
+fi
--
1.5.4.rc4.15.g215c5
16 years, 11 months
[Libvir] [PATCH] Plug test-related leaks
by Jim Meyering
Once I had a static "virsh" binary, I ran this:
cd src && valgrind --leak-check=full ./virsh --connect \
test://$PWD/../docs/testnode.xml list
which exposed some leaks.
I fixed them like this:
Plug test-related leaks.
* src/test.c (testLoadNetwork): Free forwardDev.
(testLoadDomain): Free ctxt.
(testLoadNetwork): Likewise.
(testOpenFromFile): Likewise.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
src/test.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/src/test.c b/src/test.c
index d228b31..c46a045 100644
--- a/src/test.c
+++ b/src/test.c
@@ -351,9 +351,11 @@ static int testLoadDomain(virConnectPtr conn,
privconn->domains[handle].onPoweroff = onPoweroff;
privconn->domains[handle].onCrash = onCrash;
+ xmlXPathFreeContext(ctxt);
return (handle);
error:
+ xmlXPathFreeContext(ctxt);
if (name)
free(name);
return (-1);
@@ -508,6 +510,7 @@ static int testLoadNetwork(virConnectPtr conn,
if (forwardDev) {
strncpy(privconn->networks[handle].forwardDev, forwardDev, sizeof(privconn->networks[handle].forwardDev)-1);
privconn->networks[handle].forwardDev[sizeof(privconn->networks[handle].forwardDev)-1] = '\0';
+ free(forwardDev);
}
strncpy(privconn->networks[handle].ipAddress, ipaddress, sizeof(privconn->networks[handle].ipAddress)-1);
@@ -522,9 +525,12 @@ static int testLoadNetwork(virConnectPtr conn,
strncpy(privconn->networks[handle].dhcpEnd, dhcpend, sizeof(privconn->networks[handle].dhcpEnd)-1);
privconn->networks[handle].dhcpEnd[sizeof(privconn->networks[handle].dhcpEnd)-1] = '\0';
free(dhcpend);
+ xmlXPathFreeContext(ctxt);
return (handle);
error:
+ xmlXPathFreeContext(ctxt);
+ free (forwardDev);
if (ipaddress)
free(ipaddress);
if (ipnetmask)
@@ -833,11 +839,13 @@ static int testOpenFromFile(virConnectPtr conn,
}
}
+ xmlXPathFreeContext(ctxt);
xmlFreeDoc(xml);
return (0);
error:
+ xmlXPathFreeContext(ctxt);
if (domains != NULL)
free(domains);
if (networks != NULL)
--
1.5.4.rc5.1.g0fa73
16 years, 11 months