[libvirt] Strange failure of commandtest when doing F15 build
by Laine Stump
Today I added some patches to the f15 branch of Fedora libvirt, ran
"fedpkg local" to be sure it was all in order, then did a "fedpkg commit
-p" and "fedpkg build". When I came back awhile later, I found that it
had failed. Looking in the logs, I could see that the failure was due to
tests/commandtest.
Since the failure says almost nothing (and there was nothing even
remotely related in any of the changes), I decided to try and build 1)
the older libvirt and 2) with debugging turned on in the tests.
I had no idea how to do this, but nirik in #fedora-devel helped me out,
and I did the following:
1) reverted the libvirt.spec file locally (so that I'm working with
source that previously built)
2) added the following lines just prior to "make check" in the specfile:
export VIR_TEST_VERBOSE=1
export LIBVIRT_LOG_OUTPUTS=3:stderr
export LIBVIRT_LOG_FILTERS="1:command"
export VIR_TEST_DEBUG=2
3) added something identifiable to the version string in libvirt.spec:
Release: 4.test%{?dist}%{?extra_release}
4) fedpkg srpm
5) koji build --scratch dist-f15 libvirt-0.8.8-4.test.fc15.src.rpm
This build also failed. The results are here:
http://koji.fedoraproject.org/koji/taskinfo?taskID=3182099
(search for "... FAIL")
So it appears that some other package on the build machine has been
updated, and it's causing most of the tests in commandtest to fail.
Unfortunately, even when debugging is turned on the tests don't say
anything about why they failed.
Any ideas?
13 years, 4 months
[libvirt] [PATCH] Reduce code duplication in virFileMakePath(Helper)
by Matthias Bolte
Move stat and mkdir to virFileMakePathHelper.
Also use the stat result to detect whether the existing path
is a directory and set errno accordingly if it's not.
---
src/util/util.c | 44 ++++++++++++++------------------------------
1 files changed, 14 insertions(+), 30 deletions(-)
diff --git a/src/util/util.c b/src/util/util.c
index 4710fc5..d944123 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1013,11 +1013,17 @@ int virDirCreate(const char *path ATTRIBUTE_UNUSED,
static int virFileMakePathHelper(char *path)
{
struct stat st;
- char *p = NULL;
+ char *p;
- if (stat(path, &st) >= 0)
- return 0;
- else if (errno != ENOENT)
+ if (stat(path, &st) >= 0) {
+ if (S_ISDIR(st.st_mode))
+ return 0;
+
+ errno = ENOTDIR;
+ return -1;
+ }
+
+ if (errno != ENOENT)
return -1;
if ((p = strrchr(path, '/')) == NULL) {
@@ -1049,39 +1055,17 @@ static int virFileMakePathHelper(char *path)
int virFileMakePath(const char *path)
{
int ret = -1;
- struct stat st;
- char *parent = NULL;
- char *p;
-
- if (stat(path, &st) >= 0)
- return 0;
- else if (errno != ENOENT)
- goto cleanup;
+ char *tmp;
- if ((parent = strdup(path)) == NULL) {
+ if ((tmp = strdup(path)) == NULL) {
errno = ENOMEM;
goto cleanup;
}
- if ((p = strrchr(parent, '/')) == NULL) {
- errno = EINVAL;
- goto cleanup;
- }
-
- if (p != parent) {
- *p = '\0';
-
- if (virFileMakePathHelper(parent) < 0)
- goto cleanup;
- }
-
- if (mkdir(path, 0777) < 0 && errno != EEXIST)
- goto cleanup;
-
- ret = 0;
+ ret = virFileMakePathHelper(tmp);
cleanup:
- VIR_FREE(parent);
+ VIR_FREE(tmp);
return ret;
}
--
1.7.4.1
13 years, 4 months
[libvirt] [PATCH] util: close the ioctl socket at the end of if(Get|Set)MacAddress
by Laine Stump
Otherwise this will leak an fd each time one of these functions is
called.
---
src/util/interface.c | 36 ++++++++++++++++++++++++++----------
1 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/src/util/interface.c b/src/util/interface.c
index f486124..178a4dd 100644
--- a/src/util/interface.c
+++ b/src/util/interface.c
@@ -413,6 +413,7 @@ ifaceGetMacAddress(const char *ifname,
{
struct ifreq ifr;
int fd;
+ int rc = 0;
if (!ifname)
return EINVAL;
@@ -422,15 +423,21 @@ ifaceGetMacAddress(const char *ifname,
return errno;
memset(&ifr, 0, sizeof(struct ifreq));
- if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL)
- return EINVAL;
+ if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
+ rc = EINVAL;
+ goto err_exit;
+ }
- if (ioctl(fd, SIOCGIFHWADDR, (char *)&ifr) != 0)
- return errno;
+ if (ioctl(fd, SIOCGIFHWADDR, (char *)&ifr) != 0) {
+ rc = errno;
+ goto err_exit;
+ }
memcpy(macaddr, ifr.ifr_ifru.ifru_hwaddr.sa_data, VIR_MAC_BUFLEN);
- return 0;
+err_exit:
+ VIR_FORCE_CLOSE(fd);
+ return rc;
}
#else
@@ -461,6 +468,7 @@ ifaceSetMacAddress(const char *ifname,
{
struct ifreq ifr;
int fd;
+ int rc = 0;
if (!ifname)
return EINVAL;
@@ -470,16 +478,24 @@ ifaceSetMacAddress(const char *ifname,
return errno;
memset(&ifr, 0, sizeof(struct ifreq));
- if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL)
- return EINVAL;
+ if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
+ rc = EINVAL;
+ goto err_exit;
+ }
/* To fill ifr.ifr_hdaddr.sa_family field */
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0)
- return errno;
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) {
+ rc = errno;
+ goto err_exit;
+ }
memcpy(ifr.ifr_hwaddr.sa_data, macaddr, VIR_MAC_BUFLEN);
- return ioctl(fd, SIOCSIFHWADDR, &ifr) == 0 ? 0 : errno;
+ rc = ioctl(fd, SIOCSIFHWADDR, &ifr) == 0 ? 0 : errno;
+
+err_exit:
+ VIR_FORCE_CLOSE(fd);
+ return rc;
}
#else
--
1.7.3.4
13 years, 4 months
[libvirt] [PATCH] apparmor: Finish incomplete renaming of relabel to norelabel
by Matthias Bolte
Commit 693eac388f1759d was incomplete here.
---
Pushing this under the build-breaker rule.
src/security/security_apparmor.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index 76c6e3d..6dfe8c9 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -461,7 +461,7 @@ static int
AppArmorSetSecurityAllLabel(virSecurityManagerPtr mgr,
virDomainObjPtr vm, const char *stdin_path)
{
- if (!vm->def->seclabel.relabel)
+ if (vm->def->seclabel.norelabel)
return 0;
/* Reload the profile if stdin_path is specified. Note that
--
1.7.4.1
13 years, 4 months
[libvirt] [PATCH v2] qemu: Add support for SGA
by Michal Privoznik
This patch creates new attribute 'sga' for <serial> element. Serial Graphics
Adapter allows users to see BIOS messages from the very first moment
domain boots up. Therefore, users can choose boot medium, set PXE, etc.
However, to be able to use this, one need SGABIOS, which is accessible
here: http://code.google.com/p/sgabios/
---
diff to v1:
-move from <video> to <serial> as Dan suggested:
https://www.redhat.com/archives/libvir-list/2011-July/msg00134.html
docs/formatdomain.html.in | 10 ++++--
docs/schemas/domain.rng | 20 +++++++++---
src/conf/domain_conf.c | 34 ++++++++++++++++++-
src/conf/domain_conf.h | 10 ++++++
src/qemu/qemu_capabilities.c | 3 ++
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 5 +++
.../qemuxml2argv-serial-pty-chardev.args | 3 +-
.../qemuxml2argv-serial-pty-chardev.xml | 2 +-
tests/qemuxml2argvtest.c | 3 +-
10 files changed, 78 insertions(+), 13 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index fe8d74c..1e9eee5 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2040,7 +2040,7 @@ qemu-kvm -net nic,model=? /dev/null
<source path='/dev/pts/2'/>
<target port='0'/>
</parallel>
- <serial type='pty'>
+ <serial type='pty' sga='on'>
<source path='/dev/pts/3'/>
<target port='0'/>
</serial>
@@ -2105,7 +2105,7 @@ qemu-kvm -net nic,model=? /dev/null
<pre>
...
<devices>
- <serial type='pty'>
+ <serial type='pty' sga='on'>
<source path='/dev/pts/3'/>
<target port='0'/>
</serial>
@@ -2115,7 +2115,11 @@ qemu-kvm -net nic,model=? /dev/null
<p>
<code>target</code> can have a <code>port</code> attribute, which
specifies the port number. Ports are numbered starting from 0. There are
- usually 0, 1 or 2 serial ports.
+ usually 0, 1 or 2 serial ports. The <code>sga</code> attribute enables
+ or disables Serial Graphics Adapter. Accepted values are <code>on</code>
+ and <code>off</code>. To be able to use this feature, you need to install
+ <a href="http://code.google.com/p/sgabios/">SGABios</a>. SGA
+ <span class="since">Since 0.9.4</span>
</p>
<h6><a name="elementCharConsole">Console</a></h6>
diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng
index fb1497b..e9539d5 100644
--- a/docs/schemas/domain.rng
+++ b/docs/schemas/domain.rng
@@ -1618,11 +1618,21 @@
-->
<define name="qemucdev">
<ref name="qemucdevSrcType"/>
- <optional>
- <attribute name="tty">
- <ref name="absFilePath"/>
- </attribute>
- </optional>
+ <interleave>
+ <optional>
+ <attribute name="tty">
+ <ref name="absFilePath"/>
+ </attribute>
+ </optional>
+ <optional>
+ <attribute name="sga">
+ <choice>
+ <value>on</value>
+ <value>off</value>
+ </choice>
+ </attribute>
+ </optional>
+ </interleave>
<interleave>
<ref name="qemucdevSrcDef"/>
<optional>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 109a947..cb7fe23 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -258,6 +258,11 @@ VIR_ENUM_IMPL(virDomainChrSpicevmc, VIR_DOMAIN_CHR_SPICEVMC_LAST,
"vdagent",
"smartcard")
+VIR_ENUM_IMPL(virDomainChrSGA, VIR_DOMAIN_CHR_SGA_LAST,
+ "default",
+ "on",
+ "off")
+
VIR_ENUM_IMPL(virDomainSmartcard, VIR_DOMAIN_SMARTCARD_TYPE_LAST,
"host",
"host-certificates",
@@ -3488,6 +3493,10 @@ virDomainChrDefNew(void) {
* <target port="1"/>
* </serial>
*
+ * <serial type="pty" sga="on">
+ * <target port="0"/>
+ * </serial>
+ *
* <serial type="dev">
* <source path="/dev/ttyS0"/>
* <target port="1"/>
@@ -3522,6 +3531,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
int flags) {
xmlNodePtr cur;
char *type = NULL;
+ char *sga = NULL;
const char *nodeName;
virDomainChrDefPtr def;
int remaining;
@@ -3530,6 +3540,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
return NULL;
type = virXMLPropString(node, "type");
+ sga = virXMLPropString(node, "sga");
if (type == NULL) {
def->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
} else if ((def->source.type = virDomainChrTypeFromString(type)) < 0) {
@@ -3539,6 +3550,13 @@ virDomainChrDefParseXML(virCapsPtr caps,
goto error;
}
+ if (sga && (def->source.sga=virDomainChrSGATypeFromString(sga)) <= 0) {
+ virDomainReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unknown value for sga: %s"),
+ sga);
+ goto error;
+ }
+
nodeName = (const char *) node->name;
if ((def->deviceType = virDomainChrDeviceTypeFromString(nodeName)) < 0) {
virDomainReportError(VIR_ERR_XML_ERROR,
@@ -3580,6 +3598,7 @@ virDomainChrDefParseXML(virCapsPtr caps,
cleanup:
VIR_FREE(type);
+ VIR_FREE(sga);
return def;
@@ -8739,9 +8758,11 @@ static int
virDomainChrSourceDefFormat(virBufferPtr buf,
virDomainChrSourceDefPtr def,
bool tty_compat,
+ int deviceType,
int flags)
{
const char *type = virDomainChrTypeToString(def->type);
+ const char *sga = virDomainChrSGATypeToString(def->sga);
if (!type) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
@@ -8755,6 +8776,14 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
virBufferEscapeString(buf, " tty='%s'",
def->data.file.path);
}
+ if (deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && def->sga) {
+ if (!sga) {
+ virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected sga value %d"), def->sga);
+ return -1;
+ }
+ virBufferAsprintf(buf, " sga='%s'", sga);
+ }
virBufferAddLit(buf, ">\n");
switch (def->type) {
@@ -8857,7 +8886,8 @@ virDomainChrDefFormat(virBufferPtr buf,
def->source.type == VIR_DOMAIN_CHR_TYPE_PTY &&
!(flags & VIR_DOMAIN_XML_INACTIVE) &&
def->source.data.file.path);
- if (virDomainChrSourceDefFormat(buf, &def->source, tty_compat, flags) < 0)
+ if (virDomainChrSourceDefFormat(buf, &def->source, tty_compat,
+ def->deviceType, flags) < 0)
return -1;
/* Format <target> block */
@@ -8962,7 +8992,7 @@ virDomainSmartcardDefFormat(virBufferPtr buf,
case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
if (virDomainChrSourceDefFormat(buf, &def->data.passthru, false,
- flags) < 0)
+ -1, flags) < 0)
return -1;
break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 258289a..ab0632c 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -457,11 +457,20 @@ enum virDomainChrSpicevmcName {
VIR_DOMAIN_CHR_SPICEVMC_LAST,
};
+enum virDomainChrSGA {
+ VIR_DOMAIN_CHR_SGA_DEFAULT = 0,
+ VIR_DOMAIN_CHR_SGA_ON,
+ VIR_DOMAIN_CHR_SGA_OFF,
+
+ VIR_DOMAIN_CHR_SGA_LAST
+};
+
/* The host side information for a character device. */
typedef struct _virDomainChrSourceDef virDomainChrSourceDef;
typedef virDomainChrSourceDef *virDomainChrSourceDefPtr;
struct _virDomainChrSourceDef {
int type; /* virDomainChrType */
+ int sga; /* Serial Graphics Adapter */
union {
/* no <source> for null, vc, stdio */
struct {
@@ -1570,6 +1579,7 @@ VIR_ENUM_DECL(virDomainSmartcard)
VIR_ENUM_DECL(virDomainChr)
VIR_ENUM_DECL(virDomainChrTcpProtocol)
VIR_ENUM_DECL(virDomainChrSpicevmc)
+VIR_ENUM_DECL(virDomainChrSGA)
VIR_ENUM_DECL(virDomainSoundModel)
VIR_ENUM_DECL(virDomainMemballoonModel)
VIR_ENUM_DECL(virDomainSmbiosMode)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index ad62a07..2dfe375 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -122,6 +122,7 @@ VIR_ENUM_IMPL(qemuCaps, QEMU_CAPS_LAST,
"pci-multifunction", /* 60 */
"virtio-blk-pci.ioeventfd",
+ "sga",
);
struct qemu_feature_flags {
@@ -1210,6 +1211,8 @@ qemuCapsParseDeviceStr(const char *str, virBitmapPtr flags)
qemuCapsSet(flags, QEMU_CAPS_DEVICE_QXL_VGA);
if (strstr(str, "virtio-blk-pci.ioeventfd"))
qemuCapsSet(flags, QEMU_CAPS_VIRTIO_IOEVENTFD);
+ if (strstr(str, "name \"sga\""))
+ qemuCapsSet(flags, QEMU_CAPS_SGA);
return 0;
}
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 0b9c8be..d251262 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -97,6 +97,7 @@ enum qemuCapsFlags {
QEMU_CAPS_DEVICE_QXL_VGA = 59, /* Is the primary and vga campatible qxl device named qxl-vga? */
QEMU_CAPS_PCI_MULTIFUNCTION = 60, /* -device multifunction=on|off */
QEMU_CAPS_VIRTIO_IOEVENTFD = 61, /* IOeventFD feature: virtio-{net|blk}-pci.ioeventfd=on/off */
+ QEMU_CAPS_SGA = 62, /* Serial Graphics Adapter */
QEMU_CAPS_LAST, /* this must always be the last item */
};
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 6e4480e..29936a6 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3884,6 +3884,11 @@ qemuBuildCommandLine(virConnectPtr conn,
virCommandAddArg(cmd, "-device");
virCommandAddArgFormat(cmd, "isa-serial,chardev=char%s,id=%s",
serial->info.alias, serial->info.alias);
+
+ if (serial->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL &&
+ serial->source.sga == VIR_DOMAIN_CHR_SGA_ON &&
+ qemuCapsGet(qemuCaps, QEMU_CAPS_SGA))
+ virCommandAddArgList(cmd, "-device", "sga", NULL);
} else {
virCommandAddArg(cmd, "-serial");
if (!(devstr = qemuBuildChrArgStr(&serial->source, NULL)))
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.args b/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.args
index 4a6202e..369379f 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.args
+++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.args
@@ -2,5 +2,6 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \
pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev socket,\
id=charmonitor,path=/tmp/test-monitor,server,nowait -mon chardev=charmonitor,\
id=monitor,mode=readline -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -chardev \
-pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 -usb \
+pty,id=charserial0 -device isa-serial,chardev=charserial0,id=serial0 \
+-device sga -usb \
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.xml b/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.xml
index 57d1b74..31eb7d1 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-serial-pty-chardev.xml
@@ -20,7 +20,7 @@
<address type='drive' controller='0' bus='0' unit='0'/>
</disk>
<controller type='ide' index='0'/>
- <serial type='pty'>
+ <serial type='pty' sga='on'>
<target port='0'/>
</serial>
<console type='pty'>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index ec1f4b5..b4562d1 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -425,7 +425,8 @@ mymain(void)
DO_TEST("serial-vc-chardev", false,
QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
DO_TEST("serial-pty-chardev", false,
- QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
+ QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+ QEMU_CAPS_SGA);
DO_TEST("serial-dev-chardev", false,
QEMU_CAPS_CHARDEV, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG);
DO_TEST("serial-file-chardev", false,
--
1.7.5.rc3
13 years, 4 months
[libvirt] [PATCH] Fix return value semantic of virFileMakePath
by Matthias Bolte
Some callers expected virFileMakePath to set errno, some expected
it to return an errno value. Unify this to return 0 on success and
-1 on error. Set errno to report detailed error information.
Also Make virFileMakePath report an error when stat fails with an
errno different from ENOENT.
---
src/conf/domain_conf.c | 2 +-
src/conf/network_conf.c | 5 +--
src/conf/nwfilter_conf.c | 11 +++-----
src/conf/storage_conf.c | 6 +---
src/libxl/libxl_driver.c | 14 ++++-----
src/lxc/lxc_container.c | 18 ++++++------
src/lxc/lxc_controller.c | 2 +-
src/lxc/lxc_driver.c | 10 +++----
src/network/bridge_driver.c | 25 ++++++++---------
src/qemu/qemu_driver.c | 28 ++++++++-----------
src/qemu/qemu_process.c | 2 +-
src/storage/storage_backend_fs.c | 4 +-
src/storage/storage_driver.c | 6 +---
src/uml/uml_driver.c | 10 +++----
src/util/dnsmasq.c | 5 +--
src/util/util.c | 56 ++++++++++++++++++++++++-------------
16 files changed, 100 insertions(+), 104 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 109a947..64c5636 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9986,7 +9986,7 @@ int virDomainSaveXML(const char *configDir,
if ((configFile = virDomainConfigFile(configDir, def->name)) == NULL)
goto cleanup;
- if (virFileMakePath(configDir)) {
+ if (virFileMakePath(configDir) < 0) {
virReportSystemError(errno,
_("cannot create config directory '%s'"),
configDir);
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 45ddee2..ae479bf 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1114,13 +1114,12 @@ int virNetworkSaveXML(const char *configDir,
char *configFile = NULL;
int fd = -1, ret = -1;
size_t towrite;
- int err;
if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
goto cleanup;
- if ((err = virFileMakePath(configDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(configDir) < 0) {
+ virReportSystemError(errno,
_("cannot create config directory '%s'"),
configDir);
goto cleanup;
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 127d4be..036c61a 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2184,13 +2184,12 @@ int virNWFilterSaveXML(const char *configDir,
char *configFile = NULL;
int fd = -1, ret = -1;
size_t towrite;
- int err;
if ((configFile = virNWFilterConfigFile(configDir, def->name)) == NULL)
goto cleanup;
- if ((err = virFileMakePath(configDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(configDir) < 0) {
+ virReportSystemError(errno,
_("cannot create config directory '%s'"),
configDir);
goto cleanup;
@@ -2574,10 +2573,8 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
ssize_t towrite;
if (!nwfilter->configFile) {
- int err;
-
- if ((err = virFileMakePath(driver->configDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(driver->configDir) < 0) {
+ virReportSystemError(errno,
_("cannot create config directory %s"),
driver->configDir);
return -1;
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index ca86f19..f6f8be1 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1512,10 +1512,8 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
ssize_t towrite;
if (!pool->configFile) {
- int err;
-
- if ((err = virFileMakePath(driver->configDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(driver->configDir) < 0) {
+ virReportSystemError(errno,
_("cannot create config directory %s"),
driver->configDir);
return -1;
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 7fd257d..ade69d8 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -914,25 +914,25 @@ libxlStartup(int privileged) {
"%s", LIBXL_SAVE_DIR) == -1)
goto out_of_memory;
- if (virFileMakePath(libxl_driver->logDir) != 0) {
+ if (virFileMakePath(libxl_driver->logDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create log dir '%s': %s"),
libxl_driver->logDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(libxl_driver->stateDir) != 0) {
+ if (virFileMakePath(libxl_driver->stateDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create state dir '%s': %s"),
libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(libxl_driver->libDir) != 0) {
+ if (virFileMakePath(libxl_driver->libDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
libxl_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(libxl_driver->saveDir) != 0) {
+ if (virFileMakePath(libxl_driver->saveDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create save dir '%s': %s"),
libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
@@ -3389,10 +3389,8 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
goto cleanup;
if (autostart) {
- int err;
-
- if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(driver->autostartDir) < 0) {
+ virReportSystemError(errno,
_("cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 7924858..ef8469c 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -308,7 +308,7 @@ static int lxcContainerChildMountSort(const void *a, const void *b)
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
{
- int rc, ret;
+ int ret;
char *oldroot = NULL, *newroot = NULL;
ret = -1;
@@ -325,8 +325,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
goto err;
}
- if ((rc = virFileMakePath(oldroot)) != 0) {
- virReportSystemError(rc,
+ if (virFileMakePath(oldroot) < 0) {
+ virReportSystemError(errno,
_("Failed to create %s"),
oldroot);
goto err;
@@ -347,8 +347,8 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
goto err;
}
- if ((rc = virFileMakePath(newroot)) != 0) {
- virReportSystemError(rc,
+ if (virFileMakePath(newroot) < 0) {
+ virReportSystemError(errno,
_("Failed to create %s"),
newroot);
goto err;
@@ -415,7 +415,7 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
}
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
- if (virFileMakePath(mnts[i].dst) != 0) {
+ if (virFileMakePath(mnts[i].dst) < 0) {
virReportSystemError(errno,
_("Failed to mkdir %s"),
mnts[i].src);
@@ -429,8 +429,8 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
}
}
- if ((rc = virFileMakePath("/dev/pts") != 0)) {
- virReportSystemError(rc, "%s",
+ if (virFileMakePath("/dev/pts") < 0) {
+ virReportSystemError(errno, "%s",
_("Cannot create /dev/pts"));
goto cleanup;
}
@@ -531,7 +531,7 @@ static int lxcContainerMountNewFS(virDomainDefPtr vmDef)
return -1;
}
- if (virFileMakePath(vmDef->fss[i]->dst) != 0) {
+ if (virFileMakePath(vmDef->fss[i]->dst) < 0) {
virReportSystemError(errno,
_("Failed to create %s"),
vmDef->fss[i]->dst);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 7d60090..31c7d4f 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -690,7 +690,7 @@ lxcControllerRun(virDomainDefPtr def,
goto cleanup;
}
- if (virFileMakePath(devpts) != 0) {
+ if (virFileMakePath(devpts) < 0) {
virReportSystemError(errno,
_("Failed to make path %s"),
devpts);
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 7220a9b..ffcfe4d 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1502,8 +1502,8 @@ static int lxcVmStart(virConnectPtr conn,
return -1;
}
- if ((r = virFileMakePath(driver->logDir)) != 0) {
- virReportSystemError(r,
+ if (virFileMakePath(driver->logDir) < 0) {
+ virReportSystemError(errno,
_("Cannot create log directory '%s'"),
driver->logDir);
return -1;
@@ -2539,10 +2539,8 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
goto cleanup;
if (autostart) {
- int err;
-
- if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(driver->autostartDir) < 0) {
+ virReportSystemError(errno,
_("Cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 660dd65..170bf98 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -692,17 +692,16 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
virCommandPtr cmd = NULL;
char *pidfile = NULL;
int ret = -1;
- int err;
dnsmasqContext *dctx = NULL;
- if ((err = virFileMakePath(NETWORK_PID_DIR)) != 0) {
- virReportSystemError(err,
+ if (virFileMakePath(NETWORK_PID_DIR) < 0) {
+ virReportSystemError(errno,
_("cannot create directory %s"),
NETWORK_PID_DIR);
goto cleanup;
}
- if ((err = virFileMakePath(NETWORK_STATE_DIR)) != 0) {
- virReportSystemError(err,
+ if (virFileMakePath(NETWORK_STATE_DIR) < 0) {
+ virReportSystemError(errno,
_("cannot create directory %s"),
NETWORK_STATE_DIR);
goto cleanup;
@@ -713,8 +712,8 @@ networkStartDhcpDaemon(virNetworkObjPtr network)
goto cleanup;
}
- if ((err = virFileMakePath(DNSMASQ_STATE_DIR)) != 0) {
- virReportSystemError(err,
+ if (virFileMakePath(DNSMASQ_STATE_DIR) < 0) {
+ virReportSystemError(errno,
_("cannot create directory %s"),
DNSMASQ_STATE_DIR);
goto cleanup;
@@ -777,14 +776,14 @@ networkStartRadvd(virNetworkObjPtr network)
goto cleanup;
}
- if ((err = virFileMakePath(NETWORK_PID_DIR)) != 0) {
- virReportSystemError(err,
+ if (virFileMakePath(NETWORK_PID_DIR) < 0) {
+ virReportSystemError(errno,
_("cannot create directory %s"),
NETWORK_PID_DIR);
goto cleanup;
}
- if ((err = virFileMakePath(RADVD_STATE_DIR)) != 0) {
- virReportSystemError(err,
+ if (virFileMakePath(RADVD_STATE_DIR) < 0) {
+ virReportSystemError(errno,
_("cannot create directory %s"),
RADVD_STATE_DIR);
goto cleanup;
@@ -2500,7 +2499,7 @@ static int networkSetAutostart(virNetworkPtr net,
struct network_driver *driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
char *configFile = NULL, *autostartLink = NULL;
- int ret = -1;
+ int ret = -1, err;
networkDriverLock(driver);
network = virNetworkFindByUUID(&driver->networks, net->uuid);
@@ -2526,7 +2525,7 @@ static int networkSetAutostart(virNetworkPtr net,
goto cleanup;
if (autostart) {
- if (virFileMakePath(driver->networkAutostartDir)) {
+ if (virFileMakePath(driver->networkAutostartDir) < 0) {
virReportSystemError(errno,
_("cannot create autostart directory '%s'"),
driver->networkAutostartDir);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index aab3ab9..0f645fa 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -469,37 +469,37 @@ qemudStartup(int privileged) {
goto out_of_memory;
}
- if (virFileMakePath(qemu_driver->stateDir) != 0) {
+ if (virFileMakePath(qemu_driver->stateDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create state dir '%s': %s"),
qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->libDir) != 0) {
+ if (virFileMakePath(qemu_driver->libDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
qemu_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->cacheDir) != 0) {
+ if (virFileMakePath(qemu_driver->cacheDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create cache dir '%s': %s"),
qemu_driver->cacheDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->saveDir) != 0) {
+ if (virFileMakePath(qemu_driver->saveDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create save dir '%s': %s"),
qemu_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->snapshotDir) != 0) {
+ if (virFileMakePath(qemu_driver->snapshotDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create save dir '%s': %s"),
qemu_driver->snapshotDir, virStrerror(errno, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->autoDumpPath) != 0) {
+ if (virFileMakePath(qemu_driver->autoDumpPath) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create dump dir '%s': %s"),
qemu_driver->autoDumpPath, virStrerror(errno, ebuf, sizeof ebuf));
@@ -586,8 +586,8 @@ qemudStartup(int privileged) {
if (virAsprintf(&mempath, "%s/libvirt/qemu", qemu_driver->hugetlbfs_mount) < 0)
goto out_of_memory;
- if ((rc = virFileMakePath(mempath)) != 0) {
- virReportSystemError(rc,
+ if (virFileMakePath(mempath) < 0) {
+ virReportSystemError(errno,
_("unable to create hugepage path %s"), mempath);
VIR_FREE(mempath);
goto error;
@@ -5017,10 +5017,8 @@ static int qemudDomainSetAutostart(virDomainPtr dom,
goto cleanup;
if (autostart) {
- int err;
-
- if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(driver->autostartDir) < 0) {
+ virReportSystemError(errno,
_("cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
@@ -7483,7 +7481,6 @@ static int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
int ret = -1;
char *snapDir = NULL;
char *snapFile = NULL;
- int err;
char uuidstr[VIR_UUID_STRING_BUFLEN];
virUUIDFormat(vm->def->uuid, uuidstr);
@@ -7497,9 +7494,8 @@ static int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
virReportOOMError();
goto cleanup;
}
- err = virFileMakePath(snapDir);
- if (err != 0) {
- virReportSystemError(err, _("cannot create snapshot directory '%s'"),
+ if (virFileMakePath(snapDir) < 0) {
+ virReportSystemError(errno, _("cannot create snapshot directory '%s'"),
snapDir);
goto cleanup;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f2c439b..c9145cb 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2448,7 +2448,7 @@ int qemuProcessStart(virConnectPtr conn,
}
}
- if (virFileMakePath(driver->logDir) != 0) {
+ if (virFileMakePath(driver->logDir) < 0) {
virReportSystemError(errno,
_("cannot create log directory %s"),
driver->logDir);
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index f2912f0..d87401f 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -559,8 +559,8 @@ virStorageBackendFileSystemBuild(virConnectPtr conn ATTRIBUTE_UNUSED,
/* assure all directories in the path prior to the final dir
* exist, with default uid/gid/mode. */
*p = '\0';
- if ((err = virFileMakePath(parent)) != 0) {
- virReportSystemError(err, _("cannot create path '%s'"),
+ if (virFileMakePath(parent) < 0) {
+ virReportSystemError(errno, _("cannot create path '%s'"),
parent);
goto error;
}
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index f9652f8..a990118 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1019,10 +1019,8 @@ storagePoolSetAutostart(virStoragePoolPtr obj,
if (pool->autostart != autostart) {
if (autostart) {
- int err;
-
- if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(driver->autostartDir) < 0) {
+ virReportSystemError(errno,
_("cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index a71ea21..f0f053b 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -420,7 +420,7 @@ umlStartup(int privileged)
goto error;
}
- if (virFileMakePath(uml_driver->monitorDir) != 0) {
+ if (virFileMakePath(uml_driver->monitorDir) < 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create monitor directory %s: %s"),
uml_driver->monitorDir, virStrerror(errno, ebuf, sizeof ebuf));
@@ -839,7 +839,7 @@ static int umlStartVMDaemon(virConnectPtr conn,
return -1;
}
- if (virFileMakePath(driver->logDir) != 0) {
+ if (virFileMakePath(driver->logDir) < 0) {
virReportSystemError(errno,
_("cannot create log directory %s"),
driver->logDir);
@@ -2004,10 +2004,8 @@ static int umlDomainSetAutostart(virDomainPtr dom,
goto cleanup;
if (autostart) {
- int err;
-
- if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(err,
+ if (virFileMakePath(driver->autostartDir) < 0) {
+ virReportSystemError(errno,
_("cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
diff --git a/src/util/dnsmasq.c b/src/util/dnsmasq.c
index aadca10..55db96b 100644
--- a/src/util/dnsmasq.c
+++ b/src/util/dnsmasq.c
@@ -523,11 +523,10 @@ dnsmasqAddHost(dnsmasqContext *ctx,
int
dnsmasqSave(const dnsmasqContext *ctx)
{
- int err;
int ret = 0;
- if ((err = virFileMakePath(ctx->config_dir))) {
- virReportSystemError(err, _("cannot create config directory '%s'"),
+ if (virFileMakePath(ctx->config_dir) < 0) {
+ virReportSystemError(errno, _("cannot create config directory '%s'"),
ctx->config_dir);
return -1;
}
diff --git a/src/util/util.c b/src/util/util.c
index 13973c3..482ca6b 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1010,66 +1010,80 @@ int virDirCreate(const char *path ATTRIBUTE_UNUSED,
}
#endif /* WIN32 */
-static int virFileMakePathHelper(char *path) {
+static int virFileMakePathHelper(char *path)
+{
struct stat st;
char *p = NULL;
- int err;
if (stat(path, &st) >= 0)
return 0;
+ else if (errno != ENOENT)
+ return -1;
- if ((p = strrchr(path, '/')) == NULL)
- return EINVAL;
+ if ((p = strrchr(path, '/')) == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
if (p != path) {
*p = '\0';
- err = virFileMakePathHelper(path);
+
+ if (virFileMakePathHelper(path) < 0)
+ return -1;
+
*p = '/';
- if (err != 0)
- return err;
}
- if (mkdir(path, 0777) < 0 && errno != EEXIST) {
- return errno;
- }
+ if (mkdir(path, 0777) < 0 && errno != EEXIST)
+ return -1;
+
return 0;
}
+/**
+ * Creates the given path with mode 0777 if it's not already existing
+ * completely.
+ *
+ * Returns 0 on success, or -1 if an error occurred (in which case, errno
+ * is set appropriately).
+ */
int virFileMakePath(const char *path)
{
+ int ret = -1;
struct stat st;
char *parent = NULL;
char *p;
- int err = 0;
if (stat(path, &st) >= 0)
+ return 0;
+ else if (errno != ENOENT)
goto cleanup;
if ((parent = strdup(path)) == NULL) {
- err = ENOMEM;
+ errno = ENOMEM;
goto cleanup;
}
if ((p = strrchr(parent, '/')) == NULL) {
- err = EINVAL;
+ errno = EINVAL;
goto cleanup;
}
if (p != parent) {
*p = '\0';
- if ((err = virFileMakePathHelper(parent)) != 0) {
+
+ if (virFileMakePathHelper(parent) < 0)
goto cleanup;
- }
}
- if (mkdir(path, 0777) < 0 && errno != EEXIST) {
- err = errno;
+ if (mkdir(path, 0777) < 0 && errno != EEXIST)
goto cleanup;
- }
+
+ ret = 0;
cleanup:
VIR_FREE(parent);
- return err;
+ return ret;
}
/* Build up a fully qualified path for a config file to be
@@ -1182,8 +1196,10 @@ int virFileWritePid(const char *dir,
goto cleanup;
}
- if ((rc = virFileMakePath(dir)))
+ if (virFileMakePath(dir) < 0) {
+ rc = errno;
goto cleanup;
+ }
if (!(pidfile = virFilePid(dir, name))) {
rc = ENOMEM;
--
1.7.4.1
13 years, 4 months
[libvirt] [PATCH] nodedev: Let check_fc_host_linux report errors to the caller
by Matthias Bolte
---
src/node_device/node_device_linux_sysfs.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
index 4f4acc7..34e4501 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -156,7 +156,7 @@ out:
VIR_FREE(d->scsi_host.wwpn);
}
VIR_FREE(sysfs_path);
- return 0;
+ return retval;
}
--
1.7.4.1
13 years, 4 months
[libvirt] [PATCH] Fix compilation error when SASL support is disabled
by Jean-Baptiste Rouault
This patch adds #if HAVE_SASL where needed in libvirtd.h
---
daemon/libvirtd.h | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h
index 6c604fc..8e1843c 100644
--- a/daemon/libvirtd.h
+++ b/daemon/libvirtd.h
@@ -38,7 +38,9 @@
# include "logging.h"
# include "threads.h"
# include "network.h"
-# include "virnetsaslcontext.h"
+# if HAVE_SASL
+# include "virnetsaslcontext.h"
+# endif
# include "virnetserverprogram.h"
# if WITH_DTRACE
@@ -70,7 +72,9 @@ struct daemonClientPrivate {
int domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LAST];
+# if HAVE_SASL
virNetSASLSessionPtr sasl;
+# endif
/* This is only valid if a remote open call has been made on this
* connection, otherwise it will be NULL. Also if remote close is
@@ -81,7 +85,9 @@ struct daemonClientPrivate {
daemonClientStreamPtr streams;
};
+# if HAVE_SASL
extern virNetSASLContextPtr saslCtxt;
+# endif
extern virNetServerProgramPtr remoteProgram;
extern virNetServerProgramPtr qemuProgram;
--
1.7.5.4
13 years, 4 months
[libvirt] [PATCH 0/4] Virsh: Extend command arguments completion
by Michal Privoznik
This patchset extends arguments completion for virsh commands. Currently only
for domain related (start, destroy, etc.) and 'help'. But if community is
satisfied with this little part I'll write follow up patches for other commands
as well.
This means that for command start not only pre-defined options will be generated
(autodestroy, console, paused) but names of inactive domains too. However, this
requires virsh to be already connected to daemon. Completers for commands can be
easily defined as they follow readline logic. Basically, completer returns on
each call one string (=possible argument/option) and it's called repeatedly
until NULL is returned. To generate only corresponding values for given prefix,
there is @text variable in function prototype. There is also @state variable
that is set to zero on the 1st call and to non-zero on any subsequent calls,
so completer can set it internal structures.
Michal Privoznik (4):
virsh: make conn global
virsh: Extend virsh commands definition with completer
virsh: Create completer for commands related to domains
virsh: Create completer for help command
tools/virsh.c | 1108 ++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 660 insertions(+), 448 deletions(-)
--
1.7.5.rc3
13 years, 4 months
[libvirt] [PATCH] Fix usage of virFileMakePath, it doesn't set errno but returns it
by Matthias Bolte
Also be explicity about the != 0 check in the few places that weren't.
---
src/conf/domain_conf.c | 6 +++---
src/conf/network_conf.c | 2 +-
src/conf/nwfilter_conf.c | 4 ++--
src/conf/storage_conf.c | 2 +-
src/libxl/libxl_driver.c | 20 ++++++++++----------
src/lxc/lxc_container.c | 16 ++++++++--------
src/lxc/lxc_controller.c | 6 +++---
src/lxc/lxc_driver.c | 2 +-
src/network/bridge_driver.c | 6 +++---
src/qemu/qemu_driver.c | 28 ++++++++++++++--------------
src/qemu/qemu_process.c | 6 +++---
src/storage/storage_driver.c | 2 +-
src/uml/uml_driver.c | 13 +++++++------
src/util/dnsmasq.c | 2 +-
src/util/util.c | 2 +-
15 files changed, 59 insertions(+), 58 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 109a947..2467fcf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9980,14 +9980,14 @@ int virDomainSaveXML(const char *configDir,
const char *xml)
{
char *configFile = NULL;
- int fd = -1, ret = -1;
+ int fd = -1, ret = -1, err;
size_t towrite;
if ((configFile = virDomainConfigFile(configDir, def->name)) == NULL)
goto cleanup;
- if (virFileMakePath(configDir)) {
- virReportSystemError(errno,
+ if ((err = virFileMakePath(configDir)) != 0) {
+ virReportSystemError(err,
_("cannot create config directory '%s'"),
configDir);
goto cleanup;
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 45ddee2..b0dbd43 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1119,7 +1119,7 @@ int virNetworkSaveXML(const char *configDir,
if ((configFile = virNetworkConfigFile(configDir, def->name)) == NULL)
goto cleanup;
- if ((err = virFileMakePath(configDir))) {
+ if ((err = virFileMakePath(configDir)) != 0) {
virReportSystemError(err,
_("cannot create config directory '%s'"),
configDir);
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 127d4be..bd03f67 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -2189,7 +2189,7 @@ int virNWFilterSaveXML(const char *configDir,
if ((configFile = virNWFilterConfigFile(configDir, def->name)) == NULL)
goto cleanup;
- if ((err = virFileMakePath(configDir))) {
+ if ((err = virFileMakePath(configDir)) != 0) {
virReportSystemError(err,
_("cannot create config directory '%s'"),
configDir);
@@ -2576,7 +2576,7 @@ virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
if (!nwfilter->configFile) {
int err;
- if ((err = virFileMakePath(driver->configDir))) {
+ if ((err = virFileMakePath(driver->configDir)) != 0) {
virReportSystemError(err,
_("cannot create config directory %s"),
driver->configDir);
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index ca86f19..8ccfc8c 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1514,7 +1514,7 @@ virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
if (!pool->configFile) {
int err;
- if ((err = virFileMakePath(driver->configDir))) {
+ if ((err = virFileMakePath(driver->configDir)) != 0) {
virReportSystemError(err,
_("cannot create config directory %s"),
driver->configDir);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 7fd257d..0a5ea07 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -854,7 +854,7 @@ libxlStartup(int privileged) {
const libxl_version_info *ver_info;
char *log_file = NULL;
virCommandPtr cmd;
- int status, ret = 0;
+ int status, ret = 0, err;
/* Disable libxl driver if non-root */
if (!privileged) {
@@ -914,28 +914,28 @@ libxlStartup(int privileged) {
"%s", LIBXL_SAVE_DIR) == -1)
goto out_of_memory;
- if (virFileMakePath(libxl_driver->logDir) != 0) {
+ if ((err = virFileMakePath(libxl_driver->logDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create log dir '%s': %s"),
- libxl_driver->logDir, virStrerror(errno, ebuf, sizeof ebuf));
+ libxl_driver->logDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(libxl_driver->stateDir) != 0) {
+ if ((err = virFileMakePath(libxl_driver->stateDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create state dir '%s': %s"),
- libxl_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
+ libxl_driver->stateDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(libxl_driver->libDir) != 0) {
+ if ((err = virFileMakePath(libxl_driver->libDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
- libxl_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
+ libxl_driver->libDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(libxl_driver->saveDir) != 0) {
+ if ((err = virFileMakePath(libxl_driver->saveDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create save dir '%s': %s"),
- libxl_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
+ libxl_driver->saveDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
@@ -3391,7 +3391,7 @@ libxlDomainSetAutostart(virDomainPtr dom, int autostart)
if (autostart) {
int err;
- if ((err = virFileMakePath(driver->autostartDir))) {
+ if ((err = virFileMakePath(driver->autostartDir)) != 0) {
virReportSystemError(err,
_("cannot create autostart directory %s"),
driver->autostartDir);
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 7924858..b4138c4 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -406,7 +406,7 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
{ "none", "/selinux", "selinuxfs" },
#endif
};
- int i, rc = -1;
+ int i, rc = -1, err;
char *devpts;
if (virAsprintf(&devpts, "/.oldroot%s/dev/pts", root->src) < 0) {
@@ -415,8 +415,8 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
}
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
- if (virFileMakePath(mnts[i].dst) != 0) {
- virReportSystemError(errno,
+ if ((err = virFileMakePath(mnts[i].dst)) != 0) {
+ virReportSystemError(err,
_("Failed to mkdir %s"),
mnts[i].src);
goto cleanup;
@@ -429,8 +429,8 @@ static int lxcContainerMountBasicFS(virDomainFSDefPtr root)
}
}
- if ((rc = virFileMakePath("/dev/pts") != 0)) {
- virReportSystemError(rc, "%s",
+ if ((err = virFileMakePath("/dev/pts") != 0)) {
+ virReportSystemError(err, "%s",
_("Cannot create /dev/pts"));
goto cleanup;
}
@@ -515,7 +515,7 @@ static int lxcContainerPopulateDevices(void)
static int lxcContainerMountNewFS(virDomainDefPtr vmDef)
{
- int i;
+ int i, err;
/* Pull in rest of container's mounts */
for (i = 0 ; i < vmDef->nfss ; i++) {
@@ -531,8 +531,8 @@ static int lxcContainerMountNewFS(virDomainDefPtr vmDef)
return -1;
}
- if (virFileMakePath(vmDef->fss[i]->dst) != 0) {
- virReportSystemError(errno,
+ if ((err = virFileMakePath(vmDef->fss[i]->dst)) != 0) {
+ virReportSystemError(err,
_("Failed to create %s"),
vmDef->fss[i]->dst);
VIR_FREE(src);
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 7d60090..db3ef21 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -615,7 +615,7 @@ lxcControllerRun(virDomainDefPtr def,
int appPty,
int handshakefd)
{
- int rc = -1;
+ int rc = -1, err;
int control[2] = { -1, -1};
int containerhandshake[2] = { -1, -1 };
int containerPty = -1;
@@ -690,8 +690,8 @@ lxcControllerRun(virDomainDefPtr def,
goto cleanup;
}
- if (virFileMakePath(devpts) != 0) {
- virReportSystemError(errno,
+ if ((err = virFileMakePath(devpts)) != 0) {
+ virReportSystemError(err,
_("Failed to make path %s"),
devpts);
goto cleanup;
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 7220a9b..2222365 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -2541,7 +2541,7 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
if (autostart) {
int err;
- if ((err = virFileMakePath(driver->autostartDir))) {
+ if ((err = virFileMakePath(driver->autostartDir)) != 0) {
virReportSystemError(err,
_("Cannot create autostart directory %s"),
driver->autostartDir);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 660dd65..517f03d 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2500,7 +2500,7 @@ static int networkSetAutostart(virNetworkPtr net,
struct network_driver *driver = net->conn->networkPrivateData;
virNetworkObjPtr network;
char *configFile = NULL, *autostartLink = NULL;
- int ret = -1;
+ int ret = -1, err;
networkDriverLock(driver);
network = virNetworkFindByUUID(&driver->networks, net->uuid);
@@ -2526,8 +2526,8 @@ static int networkSetAutostart(virNetworkPtr net,
goto cleanup;
if (autostart) {
- if (virFileMakePath(driver->networkAutostartDir)) {
- virReportSystemError(errno,
+ if ((err = virFileMakePath(driver->networkAutostartDir)) != 0) {
+ virReportSystemError(err,
_("cannot create autostart directory '%s'"),
driver->networkAutostartDir);
goto cleanup;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index aab3ab9..835e3e1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -372,7 +372,7 @@ static int
qemudStartup(int privileged) {
char *base = NULL;
char *driverConf = NULL;
- int rc;
+ int rc, err;
virConnectPtr conn = NULL;
if (VIR_ALLOC(qemu_driver) < 0)
@@ -469,40 +469,40 @@ qemudStartup(int privileged) {
goto out_of_memory;
}
- if (virFileMakePath(qemu_driver->stateDir) != 0) {
+ if ((err = virFileMakePath(qemu_driver->stateDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create state dir '%s': %s"),
- qemu_driver->stateDir, virStrerror(errno, ebuf, sizeof ebuf));
+ qemu_driver->stateDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->libDir) != 0) {
+ if ((err = virFileMakePath(qemu_driver->libDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create lib dir '%s': %s"),
- qemu_driver->libDir, virStrerror(errno, ebuf, sizeof ebuf));
+ qemu_driver->libDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->cacheDir) != 0) {
+ if ((err = virFileMakePath(qemu_driver->cacheDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create cache dir '%s': %s"),
- qemu_driver->cacheDir, virStrerror(errno, ebuf, sizeof ebuf));
+ qemu_driver->cacheDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->saveDir) != 0) {
+ if ((err = virFileMakePath(qemu_driver->saveDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create save dir '%s': %s"),
- qemu_driver->saveDir, virStrerror(errno, ebuf, sizeof ebuf));
+ qemu_driver->saveDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->snapshotDir) != 0) {
+ if ((err = virFileMakePath(qemu_driver->snapshotDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create save dir '%s': %s"),
- qemu_driver->snapshotDir, virStrerror(errno, ebuf, sizeof ebuf));
+ qemu_driver->snapshotDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
- if (virFileMakePath(qemu_driver->autoDumpPath) != 0) {
+ if ((err = virFileMakePath(qemu_driver->autoDumpPath)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create dump dir '%s': %s"),
- qemu_driver->autoDumpPath, virStrerror(errno, ebuf, sizeof ebuf));
+ qemu_driver->autoDumpPath, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
@@ -5019,7 +5019,7 @@ static int qemudDomainSetAutostart(virDomainPtr dom,
if (autostart) {
int err;
- if ((err = virFileMakePath(driver->autostartDir))) {
+ if ((err = virFileMakePath(driver->autostartDir)) != 0) {
virReportSystemError(err,
_("cannot create autostart directory %s"),
driver->autostartDir);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index f2c439b..d52b0ad 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2336,7 +2336,7 @@ int qemuProcessStart(virConnectPtr conn,
const char *stdin_path,
enum virVMOperationType vmop)
{
- int ret;
+ int ret, err;
off_t pos = -1;
char ebuf[1024];
char *pidfile = NULL;
@@ -2448,8 +2448,8 @@ int qemuProcessStart(virConnectPtr conn,
}
}
- if (virFileMakePath(driver->logDir) != 0) {
- virReportSystemError(errno,
+ if ((err = virFileMakePath(driver->logDir)) != 0) {
+ virReportSystemError(err,
_("cannot create log directory %s"),
driver->logDir);
goto cleanup;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index f9652f8..7b95340 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1021,7 +1021,7 @@ storagePoolSetAutostart(virStoragePoolPtr obj,
if (autostart) {
int err;
- if ((err = virFileMakePath(driver->autostartDir))) {
+ if ((err = virFileMakePath(driver->autostartDir)) != 0) {
virReportSystemError(err,
_("cannot create autostart directory %s"),
driver->autostartDir);
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index a71ea21..fbd8bca 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -350,6 +350,7 @@ umlStartup(int privileged)
uid_t uid = geteuid();
char *base = NULL;
char *userdir = NULL;
+ int err;
if (VIR_ALLOC(uml_driver) < 0)
return -1;
@@ -420,10 +421,10 @@ umlStartup(int privileged)
goto error;
}
- if (virFileMakePath(uml_driver->monitorDir) != 0) {
+ if ((err = virFileMakePath(uml_driver->monitorDir)) != 0) {
char ebuf[1024];
VIR_ERROR(_("Failed to create monitor directory %s: %s"),
- uml_driver->monitorDir, virStrerror(errno, ebuf, sizeof ebuf));
+ uml_driver->monitorDir, virStrerror(err, ebuf, sizeof ebuf));
goto error;
}
@@ -811,7 +812,7 @@ static int umlCleanupTapDevices(virConnectPtr conn ATTRIBUTE_UNUSED,
static int umlStartVMDaemon(virConnectPtr conn,
struct uml_driver *driver,
virDomainObjPtr vm) {
- int ret;
+ int ret, err;
char *logfile;
int logfd = -1;
umlDomainObjPrivatePtr priv = vm->privateData;
@@ -839,8 +840,8 @@ static int umlStartVMDaemon(virConnectPtr conn,
return -1;
}
- if (virFileMakePath(driver->logDir) != 0) {
- virReportSystemError(errno,
+ if ((err = virFileMakePath(driver->logDir)) != 0) {
+ virReportSystemError(err,
_("cannot create log directory %s"),
driver->logDir);
return -1;
@@ -2006,7 +2007,7 @@ static int umlDomainSetAutostart(virDomainPtr dom,
if (autostart) {
int err;
- if ((err = virFileMakePath(driver->autostartDir))) {
+ if ((err = virFileMakePath(driver->autostartDir)) != 0) {
virReportSystemError(err,
_("cannot create autostart directory %s"),
driver->autostartDir);
diff --git a/src/util/dnsmasq.c b/src/util/dnsmasq.c
index aadca10..27b1dcb 100644
--- a/src/util/dnsmasq.c
+++ b/src/util/dnsmasq.c
@@ -526,7 +526,7 @@ dnsmasqSave(const dnsmasqContext *ctx)
int err;
int ret = 0;
- if ((err = virFileMakePath(ctx->config_dir))) {
+ if ((err = virFileMakePath(ctx->config_dir)) != 0) {
virReportSystemError(err, _("cannot create config directory '%s'"),
ctx->config_dir);
return -1;
diff --git a/src/util/util.c b/src/util/util.c
index 13973c3..e0c625f 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1182,7 +1182,7 @@ int virFileWritePid(const char *dir,
goto cleanup;
}
- if ((rc = virFileMakePath(dir)))
+ if ((rc = virFileMakePath(dir)) != 0)
goto cleanup;
if (!(pidfile = virFilePid(dir, name))) {
--
1.7.4.1
13 years, 4 months