Make error reporting threadsafe by avoiding strerror
This commit is contained in:
parent
25415eb104
commit
437ac354fc
@ -1,4 +1,5 @@
|
|||||||
^src/util\.c$
|
^src/util\.c$
|
||||||
^src/xend_internal\.c$
|
^src/xend_internal\.c$
|
||||||
^src/util-lib\.c$
|
^src/util-lib\.c$
|
||||||
|
^qemud/qemud.c$
|
||||||
^gnulib/
|
^gnulib/
|
||||||
|
21
ChangeLog
21
ChangeLog
@ -1,3 +1,24 @@
|
|||||||
|
Tue Jan 20 16:59:53 GMT 2009 Daniel P. Berrange <berrange@redhat.com>
|
||||||
|
|
||||||
|
Make error reporting threadsafe by avoiding strerror()
|
||||||
|
* autobuild.sh: Set mingw compile warnings to fail compile
|
||||||
|
* configure.in: Check for strerror_r
|
||||||
|
* po/POTFILES.in: Add src/xen_unified.c
|
||||||
|
* src/virterror.c, src/virterror_internal.h,
|
||||||
|
src/libvirt_private.syms: Add virReportSystemErrorFull and
|
||||||
|
virReportOOMErrorFull convenience functions
|
||||||
|
* src/domain_conf.c, src/lxc_container.c, src/lxc_controller.c,
|
||||||
|
src/lxc_driver.c, src/network_conf.c, src/network_driver.c,
|
||||||
|
src/nodeinfo.c, src/qemu_driver.c, src/remote_internal.c,
|
||||||
|
src/storage_backend.c, src/storage_backend_disk.c,
|
||||||
|
src/storage_backend_fs.c, src/storage_backend_iscsi.c,
|
||||||
|
src/storage_backend_logical.c, src/storage_conf.c,
|
||||||
|
src/storage_driver.c, src/test.c, src/uml_driver.c,
|
||||||
|
src/util.c, src/xen_inotify.c, src/xen_internal.c,
|
||||||
|
src/xen_unified.c, src/xend_internal.c, src/xm_internal.c:
|
||||||
|
Remove use of strerror when reporting errors, in favour
|
||||||
|
of virReportSystemError() and virReportOOMError()
|
||||||
|
|
||||||
Tue Jan 20 17:17:11 CET 2009 Daniel Veillard <veillard@redhat.com>
|
Tue Jan 20 17:17:11 CET 2009 Daniel Veillard <veillard@redhat.com>
|
||||||
|
|
||||||
* src/qemu_driver.c: remove a warning when printing a file offset
|
* src/qemu_driver.c: remove a warning when printing a file offset
|
||||||
|
@ -65,6 +65,7 @@ if [ -x /usr/bin/i686-pc-mingw32-gcc ]; then
|
|||||||
--build=$(uname -m)-pc-linux \
|
--build=$(uname -m)-pc-linux \
|
||||||
--host=i686-pc-mingw32 \
|
--host=i686-pc-mingw32 \
|
||||||
--prefix="$AUTOBUILD_INSTALL_ROOT/i686-pc-mingw32/sys-root/mingw" \
|
--prefix="$AUTOBUILD_INSTALL_ROOT/i686-pc-mingw32/sys-root/mingw" \
|
||||||
|
--enable-compile-warnings=error \
|
||||||
--without-sasl \
|
--without-sasl \
|
||||||
--without-avahi \
|
--without-avahi \
|
||||||
--without-polkit \
|
--without-polkit \
|
||||||
|
@ -74,6 +74,9 @@ AC_SYS_LARGEFILE
|
|||||||
dnl Availability of various common functions (non-fatal if missing).
|
dnl Availability of various common functions (non-fatal if missing).
|
||||||
AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid])
|
AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid])
|
||||||
|
|
||||||
|
dnl Availability of various not common threadsafe functions
|
||||||
|
AC_CHECK_FUNCS([strerror_r])
|
||||||
|
|
||||||
dnl Availability of various common headers (non-fatal if missing).
|
dnl Availability of various common headers (non-fatal if missing).
|
||||||
AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/utsname.h sys/wait.h winsock2.h sched.h termios.h sys/poll.h syslog.h])
|
AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h sys/utsname.h sys/wait.h winsock2.h sched.h termios.h sys/poll.h syslog.h])
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ src/network_conf.c
|
|||||||
src/network_driver.c
|
src/network_driver.c
|
||||||
src/node_device.c
|
src/node_device.c
|
||||||
src/node_device_conf.c
|
src/node_device_conf.c
|
||||||
|
src/nodeinfo.c
|
||||||
src/openvz_conf.c
|
src/openvz_conf.c
|
||||||
src/openvz_driver.c
|
src/openvz_driver.c
|
||||||
src/proxy_internal.c
|
src/proxy_internal.c
|
||||||
@ -38,6 +39,7 @@ src/virsh.c
|
|||||||
src/virterror.c
|
src/virterror.c
|
||||||
src/xen_inotify.c
|
src/xen_inotify.c
|
||||||
src/xen_internal.c
|
src/xen_internal.c
|
||||||
|
src/xen_unified.c
|
||||||
src/xend_internal.c
|
src/xend_internal.c
|
||||||
src/xm_internal.c
|
src/xm_internal.c
|
||||||
src/xml.c
|
src/xml.c
|
||||||
|
@ -40,6 +40,8 @@
|
|||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
#include "c-ctype.h"
|
#include "c-ctype.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
||||||
|
|
||||||
VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
|
VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
|
||||||
"qemu",
|
"qemu",
|
||||||
"kqemu",
|
"kqemu",
|
||||||
@ -1913,8 +1915,7 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
|
|||||||
int err;
|
int err;
|
||||||
if ((err = virUUIDGenerate(def->uuid))) {
|
if ((err = virUUIDGenerate(def->uuid))) {
|
||||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to generate UUID: %s"),
|
"%s", _("Failed to generate UUID"));
|
||||||
strerror(err));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -3404,33 +3405,33 @@ int virDomainSaveXML(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((err = virFileMakePath(configDir))) {
|
if ((err = virFileMakePath(configDir))) {
|
||||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create config directory %s: %s"),
|
_("cannot create config directory '%s'"),
|
||||||
configDir, strerror(err));
|
configDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(configFile,
|
if ((fd = open(configFile,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC,
|
O_WRONLY | O_CREAT | O_TRUNC,
|
||||||
S_IRUSR | S_IWUSR )) < 0) {
|
S_IRUSR | S_IWUSR )) < 0) {
|
||||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create config file %s: %s"),
|
_("cannot create config file '%s'"),
|
||||||
configFile, strerror(errno));
|
configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
towrite = strlen(xml);
|
towrite = strlen(xml);
|
||||||
if (safewrite(fd, xml, towrite) < 0) {
|
if (safewrite(fd, xml, towrite) < 0) {
|
||||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot write config file %s: %s"),
|
_("cannot write config file '%s'"),
|
||||||
configFile, strerror(errno));
|
configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot save config file %s: %s"),
|
_("cannot save config file '%s'"),
|
||||||
configFile, strerror(errno));
|
configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3529,9 +3530,9 @@ int virDomainLoadAllConfigs(virConnectPtr conn,
|
|||||||
if (!(dir = opendir(configDir))) {
|
if (!(dir = opendir(configDir))) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return 0;
|
return 0;
|
||||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failed to open dir '%s': %s"),
|
_("Failed to open dir '%s'"),
|
||||||
configDir, strerror(errno));
|
configDir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3583,9 +3584,9 @@ int virDomainDeleteConfig(virConnectPtr conn,
|
|||||||
|
|
||||||
if (unlink(configFile) < 0 &&
|
if (unlink(configFile) < 0 &&
|
||||||
errno != ENOENT) {
|
errno != ENOENT) {
|
||||||
virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot remove config for %s: %s"),
|
_("cannot remove config %s"),
|
||||||
dom->def->name, strerror(errno));
|
configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,6 +321,8 @@ virUUIDParse;
|
|||||||
virReportErrorHelper;
|
virReportErrorHelper;
|
||||||
virErrorMsg;
|
virErrorMsg;
|
||||||
virRaiseError;
|
virRaiseError;
|
||||||
|
virReportSystemErrorFull;
|
||||||
|
virReportOOMErrorFull;
|
||||||
|
|
||||||
|
|
||||||
# xml.h
|
# xml.h
|
||||||
|
@ -48,6 +48,8 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "veth.h"
|
#include "veth.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GLibc headers are behind the kernel, so we define these
|
* GLibc headers are behind the kernel, so we define these
|
||||||
* constants if they're not present already.
|
* constants if they're not present already.
|
||||||
@ -118,14 +120,14 @@ static int lxcContainerSetStdio(int control, int ttyfd)
|
|||||||
int open_max, i;
|
int open_max, i;
|
||||||
|
|
||||||
if (setsid() < 0) {
|
if (setsid() < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("setsid failed: %s"), strerror(errno));
|
_("setsid failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(ttyfd, TIOCSCTTY, NULL) < 0) {
|
if (ioctl(ttyfd, TIOCSCTTY, NULL) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("ioctl(TIOCSTTY) failed: %s"), strerror(errno));
|
_("ioctl(TIOCSTTY) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,20 +139,20 @@ static int lxcContainerSetStdio(int control, int ttyfd)
|
|||||||
close(i);
|
close(i);
|
||||||
|
|
||||||
if (dup2(ttyfd, 0) < 0) {
|
if (dup2(ttyfd, 0) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("dup2(stdin) failed: %s"), strerror(errno));
|
_("dup2(stdin) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dup2(ttyfd, 1) < 0) {
|
if (dup2(ttyfd, 1) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("dup2(stdout) failed: %s"), strerror(errno));
|
_("dup2(stdout) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dup2(ttyfd, 2) < 0) {
|
if (dup2(ttyfd, 2) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("dup2(stderr) failed: %s"), strerror(errno));
|
_("dup2(stderr) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,9 +179,8 @@ int lxcContainerSendContinue(int control)
|
|||||||
|
|
||||||
writeCount = safewrite(control, &msg, sizeof(msg));
|
writeCount = safewrite(control, &msg, sizeof(msg));
|
||||||
if (writeCount != sizeof(msg)) {
|
if (writeCount != sizeof(msg)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("unable to send container continue message: %s"),
|
_("unable to send container continue message"));
|
||||||
strerror(errno));
|
|
||||||
goto error_out;
|
goto error_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,9 +208,8 @@ static int lxcContainerWaitForContinue(int control)
|
|||||||
readLen = saferead(control, &msg, sizeof(msg));
|
readLen = saferead(control, &msg, sizeof(msg));
|
||||||
if (readLen != sizeof(msg) ||
|
if (readLen != sizeof(msg) ||
|
||||||
msg != LXC_CONTINUE_MSG) {
|
msg != LXC_CONTINUE_MSG) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("Failed to read the container continue message: %s"),
|
_("Failed to read the container continue message"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
close(control);
|
close(control);
|
||||||
@ -266,27 +266,28 @@ static int lxcContainerChildMountSort(const void *a, const void *b)
|
|||||||
|
|
||||||
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
||||||
{
|
{
|
||||||
|
int rc;
|
||||||
char *oldroot;
|
char *oldroot;
|
||||||
|
|
||||||
/* First step is to ensure the new root itself is
|
/* First step is to ensure the new root itself is
|
||||||
a mount point */
|
a mount point */
|
||||||
if (mount(root->src, root->src, NULL, MS_BIND, NULL) < 0) {
|
if (mount(root->src, root->src, NULL, MS_BIND, NULL) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to bind new root %s: %s"),
|
_("failed to bind new root %s"),
|
||||||
root->src, strerror(errno));
|
root->src);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) {
|
if (virAsprintf(&oldroot, "%s/.oldroot", root->src) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(oldroot) < 0) {
|
if ((rc = virFileMakePath(oldroot)) < 0) {
|
||||||
VIR_FREE(oldroot);
|
VIR_FREE(oldroot);
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, rc,
|
||||||
_("failed to create %s: %s"),
|
_("failed to create %s"),
|
||||||
oldroot, strerror(errno));
|
oldroot);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,9 +295,9 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
* this and will soon be unmounted completely */
|
* this and will soon be unmounted completely */
|
||||||
if (pivot_root(root->src, oldroot) < 0) {
|
if (pivot_root(root->src, oldroot) < 0) {
|
||||||
VIR_FREE(oldroot);
|
VIR_FREE(oldroot);
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to pivot root %s to %s: %s"),
|
_("failed to pivot root %s to %s"),
|
||||||
oldroot, root->src, strerror(errno));
|
oldroot, root->src);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_FREE(oldroot);
|
VIR_FREE(oldroot);
|
||||||
@ -312,6 +313,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
static int lxcContainerPopulateDevices(void)
|
static int lxcContainerPopulateDevices(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int rc;
|
||||||
const struct {
|
const struct {
|
||||||
int maj;
|
int maj;
|
||||||
int min;
|
int min;
|
||||||
@ -326,11 +328,14 @@ static int lxcContainerPopulateDevices(void)
|
|||||||
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_URANDOM, 0666, "/dev/urandom" },
|
{ LXC_DEV_MAJ_MEMORY, LXC_DEV_MIN_URANDOM, 0666, "/dev/urandom" },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (virFileMakePath("/dev") < 0 ||
|
if ((rc = virFileMakePath("/dev")) < 0) {
|
||||||
mount("none", "/dev", "tmpfs", 0, NULL) < 0) {
|
virReportSystemError(NULL, rc, "%s",
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
_("cannot create /dev/"));
|
||||||
_("failed to mount /dev tmpfs for container: %s"),
|
return -1;
|
||||||
strerror(errno));
|
}
|
||||||
|
if (mount("none", "/dev", "tmpfs", 0, NULL) < 0) {
|
||||||
|
virReportSystemError(NULL, errno, "%s",
|
||||||
|
_("failed to mount /dev tmpfs"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Move old devpts into container, since we have to
|
/* Move old devpts into container, since we have to
|
||||||
@ -339,12 +344,15 @@ static int lxcContainerPopulateDevices(void)
|
|||||||
XXX This sucks, we need to figure out how to get our
|
XXX This sucks, we need to figure out how to get our
|
||||||
own private devpts for isolation
|
own private devpts for isolation
|
||||||
*/
|
*/
|
||||||
if (virFileMakePath("/dev/pts") < 0 ||
|
if ((rc = virFileMakePath("/dev/pts") < 0)) {
|
||||||
mount("/.oldroot/dev/pts", "/dev/pts", NULL,
|
virReportSystemError(NULL, rc, "%s",
|
||||||
|
_("cannot create /dev/pts"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (mount("/.oldroot/dev/pts", "/dev/pts", NULL,
|
||||||
MS_MOVE, NULL) < 0) {
|
MS_MOVE, NULL) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("failed to move /dev/pts into container: %s"),
|
_("failed to move /dev/pts into container"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,9 +361,9 @@ static int lxcContainerPopulateDevices(void)
|
|||||||
dev_t dev = makedev(devs[i].maj, devs[i].min);
|
dev_t dev = makedev(devs[i].maj, devs[i].min);
|
||||||
if (mknod(devs[i].path, 0, dev) < 0 ||
|
if (mknod(devs[i].path, 0, dev) < 0 ||
|
||||||
chmod(devs[i].path, devs[i].mode)) {
|
chmod(devs[i].path, devs[i].mode)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to make device %s: %s"),
|
_("failed to make device %s"),
|
||||||
devs[i].path, strerror(errno));
|
devs[i].path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -382,12 +390,19 @@ static int lxcContainerMountNewFS(virDomainDefPtr vmDef)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(vmDef->fss[i]->dst) < 0 ||
|
if (virFileMakePath(vmDef->fss[i]->dst) < 0) {
|
||||||
mount(src, vmDef->fss[i]->dst, NULL, MS_BIND, NULL) < 0) {
|
virReportSystemError(NULL, errno,
|
||||||
|
_("failed to create %s"),
|
||||||
|
vmDef->fss[i]->dst);
|
||||||
VIR_FREE(src);
|
VIR_FREE(src);
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
return -1;
|
||||||
_("failed to mount %s at %s for container: %s"),
|
}
|
||||||
vmDef->fss[i]->src, vmDef->fss[i]->dst, strerror(errno));
|
if (mount(src, vmDef->fss[i]->dst, NULL, MS_BIND, NULL) < 0) {
|
||||||
|
VIR_FREE(src);
|
||||||
|
virReportSystemError(NULL, errno,
|
||||||
|
_("failed to mount %s at %s"),
|
||||||
|
vmDef->fss[i]->src,
|
||||||
|
vmDef->fss[i]->dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_FREE(src);
|
VIR_FREE(src);
|
||||||
@ -406,9 +421,8 @@ static int lxcContainerUnmountOldFS(void)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!(procmnt = setmntent("/proc/mounts", "r"))) {
|
if (!(procmnt = setmntent("/proc/mounts", "r"))) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("failed to read /proc/mounts: %s"),
|
_("failed to read /proc/mounts"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while ((mntent = getmntent(procmnt)) != NULL) {
|
while ((mntent = getmntent(procmnt)) != NULL) {
|
||||||
@ -433,9 +447,9 @@ static int lxcContainerUnmountOldFS(void)
|
|||||||
|
|
||||||
for (i = 0 ; i < nmounts ; i++) {
|
for (i = 0 ; i < nmounts ; i++) {
|
||||||
if (umount(mounts[i]) < 0) {
|
if (umount(mounts[i]) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to unmount %s: %s"),
|
_("failed to unmount '%s'"),
|
||||||
mounts[i], strerror(errno));
|
mounts[i]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_FREE(mounts[i]);
|
VIR_FREE(mounts[i]);
|
||||||
@ -458,9 +472,8 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
|
|||||||
|
|
||||||
if (virFileMakePath("/proc") < 0 ||
|
if (virFileMakePath("/proc") < 0 ||
|
||||||
mount("none", "/proc", "proc", 0, NULL) < 0) {
|
mount("none", "/proc", "proc", 0, NULL) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("failed to mount /proc for container: %s"),
|
_("failed to mount /proc"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,18 +505,18 @@ static int lxcContainerSetupExtraMounts(virDomainDefPtr vmDef)
|
|||||||
NULL,
|
NULL,
|
||||||
MS_BIND,
|
MS_BIND,
|
||||||
NULL) < 0) {
|
NULL) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to mount %s at %s for container: %s"),
|
_("failed to mount %s at %s"),
|
||||||
vmDef->fss[i]->src, vmDef->fss[i]->dst, strerror(errno));
|
vmDef->fss[i]->src,
|
||||||
|
vmDef->fss[i]->dst);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mount /proc */
|
/* mount /proc */
|
||||||
if (mount("lxcproc", "/proc", "proc", 0, NULL) < 0) {
|
if (mount("lxcproc", "/proc", "proc", 0, NULL) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("failed to mount /proc for container: %s"),
|
_("failed to mount /proc"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,8 +570,9 @@ static int lxcContainerChild( void *data )
|
|||||||
|
|
||||||
ttyfd = open(argv->ttyPath, O_RDWR|O_NOCTTY);
|
ttyfd = open(argv->ttyPath, O_RDWR|O_NOCTTY);
|
||||||
if (ttyfd < 0) {
|
if (ttyfd < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("open(%s) failed: %s"), argv->ttyPath, strerror(errno));
|
_("failed to open %s"),
|
||||||
|
argv->ttyPath);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,8 +632,8 @@ int lxcContainerStart(virDomainDefPtr def,
|
|||||||
DEBUG("clone() returned, %d", pid);
|
DEBUG("clone() returned, %d", pid);
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("clone() failed, %s"), strerror(errno));
|
_("failed to run clone container"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "cgroup.h"
|
#include "cgroup.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
struct cgroup_device_policy {
|
struct cgroup_device_policy {
|
||||||
char type;
|
char type;
|
||||||
int major;
|
int major;
|
||||||
@ -109,8 +111,8 @@ static int lxcSetContainerResources(virDomainDefPtr def)
|
|||||||
rc = virCgroupAddTask(cgroup, getpid());
|
rc = virCgroupAddTask(cgroup, getpid());
|
||||||
out:
|
out:
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, -rc, "%s",
|
||||||
_("Failed to set lxc resources: %s\n"), strerror(-rc));
|
_("Failed to set lxc resources"));
|
||||||
virCgroupRemove(cgroup);
|
virCgroupRemove(cgroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,9 +137,9 @@ static int lxcMonitorServer(const char *sockpath)
|
|||||||
struct sockaddr_un addr;
|
struct sockaddr_un addr;
|
||||||
|
|
||||||
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to create server socket %s: %s"),
|
_("failed to create server socket '%s'"),
|
||||||
sockpath, strerror(errno));
|
sockpath);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,15 +149,15 @@ static int lxcMonitorServer(const char *sockpath)
|
|||||||
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
|
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
|
||||||
|
|
||||||
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to bind server socket %s: %s"),
|
_("failed to bind server socket '%s'"),
|
||||||
sockpath, strerror(errno));
|
sockpath);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (listen(fd, 30 /* backlog */ ) < 0) {
|
if (listen(fd, 30 /* backlog */ ) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("failed to listen server socket %s: %s"),
|
_("failed to listen server socket %s"),
|
||||||
sockpath, strerror(errno));
|
sockpath);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,14 +189,16 @@ static int lxcFdForward(int readFd, int writeFd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("read of fd %d failed: %s"), readFd, strerror(errno));
|
_("read of fd %d failed"),
|
||||||
|
readFd);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 != (safewrite(writeFd, buf, 1))) {
|
if (1 != (safewrite(writeFd, buf, 1))) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("write to fd %d failed: %s"), writeFd, strerror(errno));
|
_("write to fd %d failed"),
|
||||||
|
writeFd);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,8 +248,8 @@ static int lxcControllerMain(int monitor,
|
|||||||
/* create the epoll fild descriptor */
|
/* create the epoll fild descriptor */
|
||||||
epollFd = epoll_create(2);
|
epollFd = epoll_create(2);
|
||||||
if (0 > epollFd) {
|
if (0 > epollFd) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_create(2) failed: %s"), strerror(errno));
|
_("epoll_create(2) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,30 +258,30 @@ static int lxcControllerMain(int monitor,
|
|||||||
epollEvent.events = EPOLLIN|EPOLLET; /* edge triggered */
|
epollEvent.events = EPOLLIN|EPOLLET; /* edge triggered */
|
||||||
epollEvent.data.fd = appPty;
|
epollEvent.data.fd = appPty;
|
||||||
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, appPty, &epollEvent)) {
|
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, appPty, &epollEvent)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_ctl(appPty) failed: %s"), strerror(errno));
|
_("epoll_ctl(appPty) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
epollEvent.data.fd = contPty;
|
epollEvent.data.fd = contPty;
|
||||||
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, contPty, &epollEvent)) {
|
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, contPty, &epollEvent)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
|
_("epoll_ctl(contPty) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
epollEvent.events = EPOLLIN;
|
epollEvent.events = EPOLLIN;
|
||||||
epollEvent.data.fd = monitor;
|
epollEvent.data.fd = monitor;
|
||||||
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, monitor, &epollEvent)) {
|
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, monitor, &epollEvent)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
|
_("epoll_ctl(contPty) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
epollEvent.events = EPOLLHUP;
|
epollEvent.events = EPOLLHUP;
|
||||||
epollEvent.data.fd = client;
|
epollEvent.data.fd = client;
|
||||||
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
|
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
|
_("epoll_ctl(contPty) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,14 +300,14 @@ static int lxcControllerMain(int monitor,
|
|||||||
epollEvent.events = EPOLLHUP;
|
epollEvent.events = EPOLLHUP;
|
||||||
epollEvent.data.fd = client;
|
epollEvent.data.fd = client;
|
||||||
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
|
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
|
_("epoll_ctl(contPty) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else if (client != -1 && epollEvent.data.fd == client) {
|
} else if (client != -1 && epollEvent.data.fd == client) {
|
||||||
if (0 > epoll_ctl(epollFd, EPOLL_CTL_DEL, client, &epollEvent)) {
|
if (0 > epoll_ctl(epollFd, EPOLL_CTL_DEL, client, &epollEvent)) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_ctl(contPty) failed: %s"), strerror(errno));
|
_("epoll_ctl(contPty) failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
close(client);
|
close(client);
|
||||||
@ -340,8 +344,8 @@ static int lxcControllerMain(int monitor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* error */
|
/* error */
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("epoll_wait() failed: %s"), strerror(errno));
|
_("epoll_wait() failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -438,16 +442,16 @@ lxcControllerRun(virDomainDefPtr def,
|
|||||||
pid_t container = -1;
|
pid_t container = -1;
|
||||||
|
|
||||||
if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
|
if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("sockpair failed: %s"), strerror(errno));
|
_("sockpair failed"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileOpenTty(&containerPty,
|
if (virFileOpenTty(&containerPty,
|
||||||
&containerPtyPath,
|
&containerPtyPath,
|
||||||
0) < 0) {
|
0) < 0) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno, "%s",
|
||||||
_("failed to allocate tty: %s"), strerror(errno));
|
_("failed to allocate tty"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,18 +532,18 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
case 'n':
|
case 'n':
|
||||||
if ((name = strdup(optarg)) == NULL) {
|
if ((name = strdup(optarg)) == NULL) {
|
||||||
fprintf(stderr, "%s", strerror(errno));
|
virReportOOMError(NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'v':
|
case 'v':
|
||||||
if (VIR_REALLOC_N(veths, nveths+1) < 0) {
|
if (VIR_REALLOC_N(veths, nveths+1) < 0) {
|
||||||
fprintf(stderr, "cannot allocate veths %s", strerror(errno));
|
virReportOOMError(NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((veths[nveths++] = strdup(optarg)) == NULL) {
|
if ((veths[nveths++] = strdup(optarg)) == NULL) {
|
||||||
fprintf(stderr, "cannot allocate veth name %s", strerror(errno));
|
virReportOOMError(NULL);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -614,8 +618,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (pid > 0) {
|
if (pid > 0) {
|
||||||
if ((rc = virFileWritePid(LXC_STATE_DIR, name, pid)) != 0) {
|
if ((rc = virFileWritePid(LXC_STATE_DIR, name, pid)) != 0) {
|
||||||
fprintf(stderr, _("Unable to write pid file: %s\n"),
|
virReportSystemError(NULL, rc,
|
||||||
strerror(rc));
|
_("Unable to write pid file '%s/%s.pid'"),
|
||||||
|
LXC_STATE_DIR, name);
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -627,22 +632,22 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Don't hold onto any cwd we inherit from libvirtd either */
|
/* Don't hold onto any cwd we inherit from libvirtd either */
|
||||||
if (chdir("/") < 0) {
|
if (chdir("/") < 0) {
|
||||||
fprintf(stderr, _("Unable to change to root dir: %s\n"),
|
virReportSystemError(NULL, errno, "%s",
|
||||||
strerror(errno));
|
_("Unable to change to root dir"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsid() < 0) {
|
if (setsid() < 0) {
|
||||||
fprintf(stderr, _("Unable to become session leader: %s\n"),
|
virReportSystemError(NULL, errno, "%s",
|
||||||
strerror(errno));
|
_("Unable to become session leader"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Accept initial client which is the libvirtd daemon */
|
/* Accept initial client which is the libvirtd daemon */
|
||||||
if ((client = accept(monitor, NULL, 0)) < 0) {
|
if ((client = accept(monitor, NULL, 0)) < 0) {
|
||||||
fprintf(stderr, _("Failed connection from LXC driver: %s\n"),
|
virReportSystemError(NULL, errno, "%s",
|
||||||
strerror(errno));
|
_("Failed connection from LXC driver"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@
|
|||||||
#include "cgroup.h"
|
#include "cgroup.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_LXC
|
||||||
|
|
||||||
static int lxcStartup(void);
|
static int lxcStartup(void);
|
||||||
static int lxcShutdown(void);
|
static int lxcShutdown(void);
|
||||||
static lxc_driver_t *lxc_driver = NULL;
|
static lxc_driver_t *lxc_driver = NULL;
|
||||||
@ -467,9 +469,9 @@ static int lxcVMCleanup(virConnectPtr conn,
|
|||||||
; /* empty */
|
; /* empty */
|
||||||
|
|
||||||
if ((waitRc != vm->pid) && (errno != ECHILD)) {
|
if ((waitRc != vm->pid) && (errno != ECHILD)) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("waitpid failed to wait for container %d: %d %s"),
|
_("waitpid failed to wait for container %d: %d"),
|
||||||
vm->pid, waitRc, strerror(errno));
|
vm->pid, waitRc);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = 0;
|
rc = 0;
|
||||||
@ -579,17 +581,15 @@ static int lxcSetupInterfaces(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (0 != (rc = brAddInterface(brctl, bridge, parentVeth))) {
|
if (0 != (rc = brAddInterface(brctl, bridge, parentVeth))) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, rc,
|
||||||
_("failed to add %s device to %s: %s"),
|
_("failed to add %s device to %s"),
|
||||||
parentVeth,
|
parentVeth, bridge);
|
||||||
bridge,
|
|
||||||
strerror(rc));
|
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != (rc = vethInterfaceUpOrDown(parentVeth, 1))) {
|
if (0 != (rc = vethInterfaceUpOrDown(parentVeth, 1))) {
|
||||||
lxcError(NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, rc, "%s",
|
||||||
_("failed to enable parent ns veth device: %d"), rc);
|
_("failed to enable parent ns veth device"));
|
||||||
goto error_exit;
|
goto error_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,9 +618,8 @@ static int lxcMonitorClient(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("failed to create client socket: %s"),
|
_("failed to create client socket"));
|
||||||
strerror(errno));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,9 +628,8 @@ static int lxcMonitorClient(virConnectPtr conn,
|
|||||||
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
|
strncpy(addr.sun_path, sockpath, sizeof(addr.sun_path));
|
||||||
|
|
||||||
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("failed to connect to client socket: %s"),
|
_("failed to connect to client socket"));
|
||||||
strerror(errno));
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -662,9 +660,9 @@ static int lxcVmTerminate(virConnectPtr conn,
|
|||||||
|
|
||||||
if (kill(vm->pid, signum) < 0) {
|
if (kill(vm->pid, signum) < 0) {
|
||||||
if (errno != ESRCH) {
|
if (errno != ESRCH) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to kill pid %d: %s"),
|
_("failed to kill pid %d"),
|
||||||
vm->pid, strerror(errno));
|
vm->pid);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -792,9 +790,9 @@ static int lxcControllerStart(virConnectPtr conn,
|
|||||||
*/
|
*/
|
||||||
while ((rc = waitpid(child, &status, 0) == -1) && errno == EINTR);
|
while ((rc = waitpid(child, &status, 0) == -1) && errno == EINTR);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot wait for '%s': %s"),
|
_("cannot wait for '%s'"),
|
||||||
largv[0], strerror(errno));
|
largv[0]);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -846,10 +844,10 @@ static int lxcVmStart(virConnectPtr conn,
|
|||||||
unsigned int nveths = 0;
|
unsigned int nveths = 0;
|
||||||
char **veths = NULL;
|
char **veths = NULL;
|
||||||
|
|
||||||
if (virFileMakePath(driver->logDir) < 0) {
|
if ((rc = virFileMakePath(driver->logDir)) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, rc,
|
||||||
_("cannot create log directory %s: %s"),
|
_("cannot create log directory '%s'"),
|
||||||
driver->logDir, strerror(rc));
|
driver->logDir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -861,9 +859,8 @@ static int lxcVmStart(virConnectPtr conn,
|
|||||||
|
|
||||||
/* open parent tty */
|
/* open parent tty */
|
||||||
if (virFileOpenTty(&parentTty, &parentTtyPath, 1) < 0) {
|
if (virFileOpenTty(&parentTty, &parentTtyPath, 1) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("failed to allocate tty: %s"),
|
_("failed to allocate tty"));
|
||||||
strerror(errno));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (vm->def->console &&
|
if (vm->def->console &&
|
||||||
@ -885,9 +882,9 @@ static int lxcVmStart(virConnectPtr conn,
|
|||||||
|
|
||||||
if ((logfd = open(logfile, O_WRONLY | O_TRUNC | O_CREAT,
|
if ((logfd = open(logfile, O_WRONLY | O_TRUNC | O_CREAT,
|
||||||
S_IRUSR|S_IWUSR)) < 0) {
|
S_IRUSR|S_IWUSR)) < 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to open %s: %s"), logfile,
|
_("failed to open '%s'"),
|
||||||
strerror(errno));
|
logfile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,9 +902,9 @@ static int lxcVmStart(virConnectPtr conn,
|
|||||||
|
|
||||||
/* And get its pid */
|
/* And get its pid */
|
||||||
if ((rc = virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) != 0) {
|
if ((rc = virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) != 0) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, rc,
|
||||||
_("Failed to read pid file %s/%s.pid: %s"),
|
_("Failed to read pid file %s/%s.pid"),
|
||||||
driver->stateDir, vm->def->name, strerror(rc));
|
driver->stateDir, vm->def->name);
|
||||||
rc = -1;
|
rc = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1270,11 +1267,7 @@ static int lxcVersion(virConnectPtr conn, unsigned long *version)
|
|||||||
int min;
|
int min;
|
||||||
int rev;
|
int rev;
|
||||||
|
|
||||||
if (uname(&ver) != 0) {
|
uname(&ver);
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("uname(): %s"), strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sscanf(ver.release, "%i.%i.%i", &maj, &min, &rev) != 3) {
|
if (sscanf(ver.release, "%i.%i.%i", &maj, &min, &rev) != 3) {
|
||||||
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
#include "buf.h"
|
#include "buf.h"
|
||||||
#include "c-ctype.h"
|
#include "c-ctype.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_NETWORK
|
||||||
|
|
||||||
VIR_ENUM_DECL(virNetworkForward)
|
VIR_ENUM_DECL(virNetworkForward)
|
||||||
|
|
||||||
VIR_ENUM_IMPL(virNetworkForward,
|
VIR_ENUM_IMPL(virNetworkForward,
|
||||||
@ -332,7 +334,7 @@ virNetworkDefParseXML(virConnectPtr conn,
|
|||||||
int err;
|
int err;
|
||||||
if ((err = virUUIDGenerate(def->uuid))) {
|
if ((err = virUUIDGenerate(def->uuid))) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to generate UUID: %s"), strerror(err));
|
"%s", _("Failed to generate UUID"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -667,40 +669,40 @@ int virNetworkSaveConfig(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if ((err = virFileMakePath(configDir))) {
|
if ((err = virFileMakePath(configDir))) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("cannot create config directory %s: %s"),
|
_("cannot create config directory '%s'"),
|
||||||
configDir, strerror(err));
|
configDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = virFileMakePath(autostartDir))) {
|
if ((err = virFileMakePath(autostartDir))) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("cannot create autostart directory %s: %s"),
|
_("cannot create autostart directory '%s'"),
|
||||||
autostartDir, strerror(err));
|
autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(net->configFile,
|
if ((fd = open(net->configFile,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC,
|
O_WRONLY | O_CREAT | O_TRUNC,
|
||||||
S_IRUSR | S_IWUSR )) < 0) {
|
S_IRUSR | S_IWUSR )) < 0) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create config file %s: %s"),
|
_("cannot create config file '%s'"),
|
||||||
net->configFile, strerror(errno));
|
net->configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
towrite = strlen(xml);
|
towrite = strlen(xml);
|
||||||
if (safewrite(fd, xml, towrite) < 0) {
|
if (safewrite(fd, xml, towrite) < 0) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot write config file %s: %s"),
|
_("cannot write config file '%s'"),
|
||||||
net->configFile, strerror(errno));
|
net->configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot save config file %s: %s"),
|
_("cannot save config file '%s'"),
|
||||||
net->configFile, strerror(errno));
|
net->configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,9 +779,9 @@ int virNetworkLoadAllConfigs(virConnectPtr conn,
|
|||||||
if (!(dir = opendir(configDir))) {
|
if (!(dir = opendir(configDir))) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return 0;
|
return 0;
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failed to open dir '%s': %s"),
|
_("Failed to open dir '%s'"),
|
||||||
configDir, strerror(errno));
|
configDir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,9 +823,9 @@ int virNetworkDeleteConfig(virConnectPtr conn,
|
|||||||
unlink(net->autostartLink);
|
unlink(net->autostartLink);
|
||||||
|
|
||||||
if (unlink(net->configFile) < 0) {
|
if (unlink(net->configFile) < 0) {
|
||||||
virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot remove config for %s: %s"),
|
_("cannot remove config file '%s'"),
|
||||||
net->def->name, strerror(errno));
|
net->configFile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,9 @@
|
|||||||
#include "iptables.h"
|
#include "iptables.h"
|
||||||
#include "bridge.h"
|
#include "bridge.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_NETWORK
|
||||||
|
|
||||||
/* Main driver state */
|
/* Main driver state */
|
||||||
struct network_driver {
|
struct network_driver {
|
||||||
virMutex lock;
|
virMutex lock;
|
||||||
@ -460,9 +463,9 @@ networkAddMasqueradingIptablesRules(virConnectPtr conn,
|
|||||||
network->def->network,
|
network->def->network,
|
||||||
network->def->bridge,
|
network->def->bridge,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow forwarding from '%s' : %s\n"),
|
_("failed to add iptables rule to allow forwarding from '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto masqerr1;
|
goto masqerr1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -471,9 +474,9 @@ networkAddMasqueradingIptablesRules(virConnectPtr conn,
|
|||||||
network->def->network,
|
network->def->network,
|
||||||
network->def->bridge,
|
network->def->bridge,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow forwarding to '%s' : %s\n"),
|
_("failed to add iptables rule to allow forwarding to '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto masqerr2;
|
goto masqerr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,9 +484,9 @@ networkAddMasqueradingIptablesRules(virConnectPtr conn,
|
|||||||
if ((err = iptablesAddForwardMasquerade(driver->iptables,
|
if ((err = iptablesAddForwardMasquerade(driver->iptables,
|
||||||
network->def->network,
|
network->def->network,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to enable masquerading : %s\n"),
|
_("failed to add iptables rule to enable masquerading to '%s'\n"),
|
||||||
strerror(err));
|
network->def->forwardDev ? network->def->forwardDev : NULL);
|
||||||
goto masqerr3;
|
goto masqerr3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -513,9 +516,9 @@ networkAddRoutingIptablesRules(virConnectPtr conn,
|
|||||||
network->def->network,
|
network->def->network,
|
||||||
network->def->bridge,
|
network->def->bridge,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow routing from '%s' : %s\n"),
|
_("failed to add iptables rule to allow routing from '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto routeerr1;
|
goto routeerr1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,9 +527,9 @@ networkAddRoutingIptablesRules(virConnectPtr conn,
|
|||||||
network->def->network,
|
network->def->network,
|
||||||
network->def->bridge,
|
network->def->bridge,
|
||||||
network->def->forwardDev))) {
|
network->def->forwardDev))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow routing to '%s' : %s\n"),
|
_("failed to add iptables rule to allow routing to '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto routeerr2;
|
goto routeerr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,31 +560,31 @@ networkAddIptablesRules(virConnectPtr conn,
|
|||||||
|
|
||||||
/* allow DHCP requests through to dnsmasq */
|
/* allow DHCP requests through to dnsmasq */
|
||||||
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 67))) {
|
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 67))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow DHCP requests from '%s' : %s"),
|
_("failed to add iptables rule to allow DHCP requests from '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 67))) {
|
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 67))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow DHCP requests from '%s' : %s"),
|
_("failed to add iptables rule to allow DHCP requests from '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err2;
|
goto err2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allow DNS requests through to dnsmasq */
|
/* allow DNS requests through to dnsmasq */
|
||||||
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 53))) {
|
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 53))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow DNS requests from '%s' : %s"),
|
_("failed to add iptables rule to allow DNS requests from '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err3;
|
goto err3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 53))) {
|
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 53))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow DNS requests from '%s' : %s"),
|
_("failed to add iptables rule to allow DNS requests from '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err4;
|
goto err4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,24 +592,24 @@ networkAddIptablesRules(virConnectPtr conn,
|
|||||||
/* Catch all rules to block forwarding to/from bridges */
|
/* Catch all rules to block forwarding to/from bridges */
|
||||||
|
|
||||||
if ((err = iptablesAddForwardRejectOut(driver->iptables, network->def->bridge))) {
|
if ((err = iptablesAddForwardRejectOut(driver->iptables, network->def->bridge))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to block outbound traffic from '%s' : %s"),
|
_("failed to add iptables rule to block outbound traffic from '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err5;
|
goto err5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = iptablesAddForwardRejectIn(driver->iptables, network->def->bridge))) {
|
if ((err = iptablesAddForwardRejectIn(driver->iptables, network->def->bridge))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to block inbound traffic to '%s' : %s"),
|
_("failed to add iptables rule to block inbound traffic to '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err6;
|
goto err6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allow traffic between guests on the same bridge */
|
/* Allow traffic between guests on the same bridge */
|
||||||
if ((err = iptablesAddForwardAllowCross(driver->iptables, network->def->bridge))) {
|
if ((err = iptablesAddForwardAllowCross(driver->iptables, network->def->bridge))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to add iptables rule to allow cross bridge traffic on '%s' : %s"),
|
_("failed to add iptables rule to allow cross bridge traffic on '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err7;
|
goto err7;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,15 +714,15 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
if (!driver->brctl && (err = brInit(&driver->brctl))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err, "%s",
|
||||||
_("cannot initialize bridge support: %s"), strerror(err));
|
_("cannot initialize bridge support"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = brAddBridge(driver->brctl, &network->def->bridge))) {
|
if ((err = brAddBridge(driver->brctl, &network->def->bridge))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("cannot create bridge '%s' : %s"),
|
_("cannot create bridge '%s'"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -732,25 +735,25 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
|
|||||||
|
|
||||||
if (network->def->ipAddress &&
|
if (network->def->ipAddress &&
|
||||||
(err = brSetInetAddress(driver->brctl, network->def->bridge, network->def->ipAddress))) {
|
(err = brSetInetAddress(driver->brctl, network->def->bridge, network->def->ipAddress))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("cannot set IP address on bridge '%s' to '%s' : %s"),
|
_("cannot set IP address on bridge '%s' to '%s'"),
|
||||||
network->def->bridge, network->def->ipAddress, strerror(err));
|
network->def->bridge, network->def->ipAddress);
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network->def->netmask &&
|
if (network->def->netmask &&
|
||||||
(err = brSetInetNetmask(driver->brctl, network->def->bridge, network->def->netmask))) {
|
(err = brSetInetNetmask(driver->brctl, network->def->bridge, network->def->netmask))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("cannot set netmask on bridge '%s' to '%s' : %s"),
|
_("cannot set netmask on bridge '%s' to '%s'"),
|
||||||
network->def->bridge, network->def->netmask, strerror(err));
|
network->def->bridge, network->def->netmask);
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (network->def->ipAddress &&
|
if (network->def->ipAddress &&
|
||||||
(err = brSetInterfaceUp(driver->brctl, network->def->bridge, 1))) {
|
(err = brSetInterfaceUp(driver->brctl, network->def->bridge, 1))) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, err,
|
||||||
_("failed to bring the bridge '%s' up : %s"),
|
_("failed to bring the bridge '%s' up"),
|
||||||
network->def->bridge, strerror(err));
|
network->def->bridge);
|
||||||
goto err_delbr;
|
goto err_delbr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,8 +762,8 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
|
|||||||
|
|
||||||
if (network->def->forwardType != VIR_NETWORK_FORWARD_NONE &&
|
if (network->def->forwardType != VIR_NETWORK_FORWARD_NONE &&
|
||||||
!networkEnableIpForwarding()) {
|
!networkEnableIpForwarding()) {
|
||||||
networkReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("failed to enable IP forwarding : %s"), strerror(err));
|
_("failed to enable IP forwarding"));
|
||||||
goto err_delbr2;
|
goto err_delbr2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1249,23 +1252,23 @@ static int networkSetAutostart(virNetworkPtr net,
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = virFileMakePath(driver->networkAutostartDir))) {
|
if ((err = virFileMakePath(driver->networkAutostartDir))) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(net->conn, errno,
|
||||||
_("cannot create autostart directory %s: %s"),
|
_("cannot create autostart directory '%s'"),
|
||||||
driver->networkAutostartDir, strerror(err));
|
driver->networkAutostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symlink(network->configFile, network->autostartLink) < 0) {
|
if (symlink(network->configFile, network->autostartLink) < 0) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(net->conn, errno,
|
||||||
_("Failed to create symlink '%s' to '%s': %s"),
|
_("Failed to create symlink '%s' to '%s'"),
|
||||||
network->autostartLink, network->configFile, strerror(errno));
|
network->autostartLink, network->configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
||||||
networkReportError(net->conn, NULL, net, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(net->conn, errno,
|
||||||
_("Failed to delete symlink '%s': %s"),
|
_("Failed to delete symlink '%s'"),
|
||||||
network->autostartLink, strerror(errno));
|
network->autostartLink);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,9 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "virterror_internal.h"
|
#include "virterror_internal.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define CPUINFO_PATH "/proc/cpuinfo"
|
#define CPUINFO_PATH "/proc/cpuinfo"
|
||||||
|
|
||||||
@ -135,12 +138,8 @@ int virNodeInfoPopulate(virConnectPtr conn,
|
|||||||
#ifdef HAVE_UNAME
|
#ifdef HAVE_UNAME
|
||||||
struct utsname info;
|
struct utsname info;
|
||||||
|
|
||||||
if (uname(&info) < 0) {
|
uname(&info);
|
||||||
virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
|
||||||
"cannot extract machine type %s", strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
strncpy(nodeinfo->model, info.machine, sizeof(nodeinfo->model)-1);
|
strncpy(nodeinfo->model, info.machine, sizeof(nodeinfo->model)-1);
|
||||||
nodeinfo->model[sizeof(nodeinfo->model)-1] = '\0';
|
nodeinfo->model[sizeof(nodeinfo->model)-1] = '\0';
|
||||||
|
|
||||||
@ -155,9 +154,8 @@ int virNodeInfoPopulate(virConnectPtr conn,
|
|||||||
int ret;
|
int ret;
|
||||||
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
|
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
|
||||||
if (!cpuinfo) {
|
if (!cpuinfo) {
|
||||||
virRaiseError(conn, NULL, NULL, 0, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
_("cannot open %s"), CPUINFO_PATH);
|
||||||
"cannot open %s %s", CPUINFO_PATH, strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = linuxNodeInfoCPUPopulate(conn, cpuinfo, nodeinfo);
|
ret = linuxNodeInfoCPUPopulate(conn, cpuinfo, nodeinfo);
|
||||||
|
@ -69,6 +69,8 @@
|
|||||||
#include "uuid.h"
|
#include "uuid.h"
|
||||||
#include "domain_conf.h"
|
#include "domain_conf.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_QEMU
|
||||||
|
|
||||||
/* For storing short-lived temporary files. */
|
/* For storing short-lived temporary files. */
|
||||||
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
|
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
|
||||||
|
|
||||||
@ -153,9 +155,7 @@ qemudLogFD(virConnectPtr conn, const char* logDir, const char* name)
|
|||||||
|
|
||||||
if ((ret = snprintf(logfile, sizeof(logfile), "%s/%s.log", logDir, name))
|
if ((ret = snprintf(logfile, sizeof(logfile), "%s/%s.log", logDir, name))
|
||||||
< 0 || ret >= sizeof(logfile)) {
|
< 0 || ret >= sizeof(logfile)) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportOOMError(conn);
|
||||||
_("failed to build logfile name %s/%s.log"),
|
|
||||||
logDir, name);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,15 +165,14 @@ qemudLogFD(virConnectPtr conn, const char* logDir, const char* name)
|
|||||||
else
|
else
|
||||||
logmode |= O_APPEND;
|
logmode |= O_APPEND;
|
||||||
if ((fd = open(logfile, logmode, S_IRUSR | S_IWUSR)) < 0) {
|
if ((fd = open(logfile, logmode, S_IRUSR | S_IWUSR)) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to create logfile %s: %s"),
|
_("failed to create logfile %s"),
|
||||||
logfile, strerror(errno));
|
logfile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (qemudSetCloseExec(fd) < 0) {
|
if (qemudSetCloseExec(fd) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("Unable to set VM logfile close-on-exec flag %s"),
|
_("Unable to set VM logfile close-on-exec flag"));
|
||||||
strerror(errno));
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -631,9 +630,9 @@ qemudReadMonitorOutput(virConnectPtr conn,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (errno != EAGAIN) {
|
if (errno != EAGAIN) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failure while reading %s startup output: %s"),
|
_("Failure while reading %s startup output"),
|
||||||
what, strerror(errno));
|
what);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,9 +643,9 @@ qemudReadMonitorOutput(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
} else if (ret == -1) {
|
} else if (ret == -1) {
|
||||||
if (errno != EINTR) {
|
if (errno != EINTR) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failure while reading %s startup output: %s"),
|
_("Failure while reading %s startup output"),
|
||||||
what, strerror(errno));
|
what);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -990,9 +989,8 @@ qemudInitCpus(virConnectPtr conn,
|
|||||||
for (i = 0 ; i < vm->nvcpupids ; i++) {
|
for (i = 0 ; i < vm->nvcpupids ; i++) {
|
||||||
if (sched_setaffinity(vm->vcpupids[i],
|
if (sched_setaffinity(vm->vcpupids[i],
|
||||||
sizeof(mask), &mask) < 0) {
|
sizeof(mask), &mask) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("failed to set CPU affinity %s"),
|
_("failed to set CPU affinity"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1088,9 +1086,9 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(driver->logDir) < 0) {
|
if (virFileMakePath(driver->logDir) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create log directory %s: %s"),
|
_("cannot create log directory %s"),
|
||||||
driver->logDir, strerror(errno));
|
driver->logDir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1108,10 +1106,9 @@ static int qemudStartVMDaemon(virConnectPtr conn,
|
|||||||
* in a sub-process so its hard to feed back a useful error
|
* in a sub-process so its hard to feed back a useful error
|
||||||
*/
|
*/
|
||||||
if (stat(emulator, &sb) < 0) {
|
if (stat(emulator, &sb) < 0) {
|
||||||
qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Cannot find QEMU binary %s: %s"),
|
_("Cannot find QEMU binary %s"),
|
||||||
emulator,
|
emulator);
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2330,9 +2327,9 @@ static int qemudDomainSave(virDomainPtr dom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("unable to save file %s %s"),
|
_("unable to save file %s"),
|
||||||
path, strerror(errno));
|
path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
fd = -1;
|
fd = -1;
|
||||||
@ -2493,8 +2490,8 @@ qemudDomainPinVcpu(virDomainPtr dom,
|
|||||||
|
|
||||||
if (vm->vcpupids != NULL) {
|
if (vm->vcpupids != NULL) {
|
||||||
if (sched_setaffinity(vm->vcpupids[vcpu], sizeof(mask), &mask) < 0) {
|
if (sched_setaffinity(vm->vcpupids[vcpu], sizeof(mask), &mask) < 0) {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
|
virReportSystemError(dom->conn, errno, "%s",
|
||||||
_("cannot set affinity: %s"), strerror(errno));
|
_("cannot set affinity"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -2562,8 +2559,8 @@ qemudDomainGetVcpus(virDomainPtr dom,
|
|||||||
CPU_ZERO(&mask);
|
CPU_ZERO(&mask);
|
||||||
|
|
||||||
if (sched_getaffinity(vm->vcpupids[v], sizeof(mask), &mask) < 0) {
|
if (sched_getaffinity(vm->vcpupids[v], sizeof(mask), &mask) < 0) {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_ARG,
|
virReportSystemError(dom->conn, errno, "%s",
|
||||||
_("cannot get affinity: %s"), strerror(errno));
|
_("cannot get affinity"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3546,23 +3543,23 @@ static int qemudDomainSetAutostart(virDomainPtr dom,
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
if ((err = virFileMakePath(driver->autostartDir))) {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, err,
|
||||||
_("cannot create autostart directory %s: %s"),
|
_("cannot create autostart directory %s"),
|
||||||
driver->autostartDir, strerror(err));
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symlink(configFile, autostartLink) < 0) {
|
if (symlink(configFile, autostartLink) < 0) {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("Failed to create symlink '%s to '%s': %s"),
|
_("Failed to create symlink '%s to '%s'"),
|
||||||
autostartLink, configFile, strerror(errno));
|
autostartLink, configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
||||||
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("Failed to delete symlink '%s': %s"),
|
_("Failed to delete symlink '%s'"),
|
||||||
autostartLink, strerror(errno));
|
autostartLink);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_REMOTE
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define pipe(fds) _pipe(fds,4096, _O_BINARY)
|
#define pipe(fds) _pipe(fds,4096, _O_BINARY)
|
||||||
#endif
|
#endif
|
||||||
@ -586,9 +588,9 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo (res);
|
freeaddrinfo (res);
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, saved_errno,
|
||||||
_("unable to connect to '%s': %s"),
|
_("unable to connect to '%s'"),
|
||||||
priv->hostname, strerror (saved_errno));
|
priv->hostname);
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
tcp_connected:
|
tcp_connected:
|
||||||
@ -607,9 +609,9 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
uid_t uid = getuid();
|
uid_t uid = getuid();
|
||||||
|
|
||||||
if (!(pw = getpwuid(uid))) {
|
if (!(pw = getpwuid(uid))) {
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("unable to lookup user '%d': %s"),
|
_("unable to lookup user '%d'"),
|
||||||
uid, strerror (errno));
|
uid);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,9 +643,8 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
autostart_retry:
|
autostart_retry:
|
||||||
priv->sock = socket (AF_UNIX, SOCK_STREAM, 0);
|
priv->sock = socket (AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (priv->sock == -1) {
|
if (priv->sock == -1) {
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("unable to create socket %s"),
|
_("unable to create socket"));
|
||||||
strerror (errno));
|
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
if (connect (priv->sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
|
if (connect (priv->sock, (struct sockaddr *) &addr, sizeof addr) == -1) {
|
||||||
@ -665,9 +666,9 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
goto autostart_retry;
|
goto autostart_retry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("unable to connect to '%s': %s"),
|
_("unable to connect to '%s'"),
|
||||||
sockname, strerror (errno));
|
sockname);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -725,9 +726,8 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
* to faff around with two file descriptors (a la 'pipe(2)').
|
* to faff around with two file descriptors (a la 'pipe(2)').
|
||||||
*/
|
*/
|
||||||
if (socketpair (PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
|
if (socketpair (PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("unable to create socket pair %s"),
|
_("unable to create socket pair"));
|
||||||
strerror (errno));
|
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -754,16 +754,14 @@ doRemoteOpen (virConnectPtr conn,
|
|||||||
} /* switch (transport) */
|
} /* switch (transport) */
|
||||||
|
|
||||||
if (virSetNonBlock(priv->sock) < 0) {
|
if (virSetNonBlock(priv->sock) < 0) {
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("unable to make socket non-blocking %s"),
|
_("unable to make socket non-blocking"));
|
||||||
strerror(errno));
|
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pipe(wakeupFD) < 0) {
|
if (pipe(wakeupFD) < 0) {
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("unable to make pipe %s"),
|
_("unable to make pipe"));
|
||||||
strerror(errno));
|
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
priv->wakeupReadFD = wakeupFD[0];
|
priv->wakeupReadFD = wakeupFD[0];
|
||||||
@ -1004,9 +1002,9 @@ check_cert_file (virConnectPtr conn, const char *type, const char *file)
|
|||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (stat(file, &sb) < 0) {
|
if (stat(file, &sb) < 0) {
|
||||||
errorf(conn, VIR_ERR_RPC,
|
virReportSystemError(conn, errno,
|
||||||
_("Cannot access %s '%s': %s (%d)"),
|
_("Cannot access %s '%s'"),
|
||||||
type, file, strerror(errno), errno);
|
type, file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -1193,9 +1191,8 @@ verify_certificate (virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((now = time(NULL)) == ((time_t)-1)) {
|
if ((now = time(NULL)) == ((time_t)-1)) {
|
||||||
errorf (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno, "%s",
|
||||||
_("cannot get current time: %s"),
|
_("cannot get current time"));
|
||||||
strerror (errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5180,10 +5177,8 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
/* Get local address in form IPADDR:PORT */
|
/* Get local address in form IPADDR:PORT */
|
||||||
salen = sizeof(sa);
|
salen = sizeof(sa);
|
||||||
if (getsockname(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
|
if (getsockname(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
|
||||||
virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
|
virReportSystemError(in_open ? NULL : conn, errno, "%s",
|
||||||
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
_("failed to get sock address"));
|
||||||
_("failed to get sock address %d (%s)"),
|
|
||||||
errno, strerror(errno));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((localAddr = addrToString(&sa, salen)) == NULL)
|
if ((localAddr = addrToString(&sa, salen)) == NULL)
|
||||||
@ -5192,10 +5187,8 @@ remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in_open,
|
|||||||
/* Get remote address in form IPADDR:PORT */
|
/* Get remote address in form IPADDR:PORT */
|
||||||
salen = sizeof(sa);
|
salen = sizeof(sa);
|
||||||
if (getpeername(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
|
if (getpeername(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
|
||||||
virRaiseError (in_open ? NULL : conn, NULL, NULL, VIR_FROM_REMOTE,
|
virReportSystemError(in_open ? NULL : conn, errno, "%s",
|
||||||
VIR_ERR_AUTH_FAILED, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0,
|
_("failed to get peer address"));
|
||||||
_("failed to get peer address %d (%s)"),
|
|
||||||
errno, strerror(errno));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if ((remoteAddr = addrToString(&sa, salen)) == NULL)
|
if ((remoteAddr = addrToString(&sa, salen)) == NULL)
|
||||||
@ -5721,8 +5714,8 @@ processCallWrite(virConnectPtr conn,
|
|||||||
if (errno == EWOULDBLOCK)
|
if (errno == EWOULDBLOCK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error (in_open ? NULL : conn,
|
virReportSystemError(in_open ? NULL : conn, errno,
|
||||||
VIR_ERR_SYSTEM_ERROR, strerror (errno));
|
"%s", _("cannot send data"));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -5771,10 +5764,8 @@ processCallRead(virConnectPtr conn,
|
|||||||
if (errno == EWOULDBLOCK)
|
if (errno == EWOULDBLOCK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
errorf (in_open ? NULL : conn,
|
virReportSystemError(in_open ? NULL : conn, errno,
|
||||||
VIR_ERR_SYSTEM_ERROR,
|
"%s", _("cannot recv data"));
|
||||||
_("failed to read from socket %s"),
|
|
||||||
strerror (errno));
|
|
||||||
} else {
|
} else {
|
||||||
errorf (in_open ? NULL : conn,
|
errorf (in_open ? NULL : conn,
|
||||||
VIR_ERR_SYSTEM_ERROR,
|
VIR_ERR_SYSTEM_ERROR,
|
||||||
|
@ -62,6 +62,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
static virStorageBackendPtr backends[] = {
|
static virStorageBackendPtr backends[] = {
|
||||||
#if WITH_STORAGE_DIR
|
#if WITH_STORAGE_DIR
|
||||||
&virStorageBackendDirectory,
|
&virStorageBackendDirectory,
|
||||||
@ -104,9 +106,9 @@ virStorageBackendUpdateVolInfo(virConnectPtr conn,
|
|||||||
int ret, fd;
|
int ret, fd;
|
||||||
|
|
||||||
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot open volume '%s': %s"),
|
_("cannot open volume '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,9 +165,9 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fstat(fd, &sb) < 0) {
|
if (fstat(fd, &sb) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot stat file '%s': %s"),
|
_("cannot stat file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,9 +197,9 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
|
|||||||
*/
|
*/
|
||||||
end = lseek(fd, 0, SEEK_END);
|
end = lseek(fd, 0, SEEK_END);
|
||||||
if (end == (off_t)-1) {
|
if (end == (off_t)-1) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot seek to end of file '%s':%s"),
|
_("cannot seek to end of file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vol->allocation = end;
|
vol->allocation = end;
|
||||||
@ -215,16 +217,16 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
|
|||||||
|
|
||||||
start = lseek(fd, 0, SEEK_SET);
|
start = lseek(fd, 0, SEEK_SET);
|
||||||
if (start < 0) {
|
if (start < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot seek to beginning of file '%s':%s"),
|
_("cannot seek to beginning of file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
bytes = saferead(fd, buffer, sizeof(buffer));
|
bytes = saferead(fd, buffer, sizeof(buffer));
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read beginning of file '%s':%s"),
|
_("cannot read beginning of file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,9 +250,9 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
|
|||||||
#if HAVE_SELINUX
|
#if HAVE_SELINUX
|
||||||
if (fgetfilecon(fd, &filecon) == -1) {
|
if (fgetfilecon(fd, &filecon) == -1) {
|
||||||
if (errno != ENODATA && errno != ENOTSUP) {
|
if (errno != ENODATA && errno != ENOTSUP) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot get file context of %s: %s"),
|
_("cannot get file context of '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
vol->target.perms.label = NULL;
|
vol->target.perms.label = NULL;
|
||||||
@ -258,7 +260,7 @@ virStorageBackendUpdateVolInfoFD(virConnectPtr conn,
|
|||||||
} else {
|
} else {
|
||||||
vol->target.perms.label = strdup(filecon);
|
vol->target.perms.label = strdup(filecon);
|
||||||
if (vol->target.perms.label == NULL) {
|
if (vol->target.perms.label == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("context"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
freecon(filecon);
|
freecon(filecon);
|
||||||
@ -341,10 +343,9 @@ virStorageBackendStablePath(virConnectPtr conn,
|
|||||||
usleep(100 * 1000);
|
usleep(100 * 1000);
|
||||||
goto reopen;
|
goto reopen;
|
||||||
}
|
}
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read dir %s: %s"),
|
_("cannot read dir '%s'"),
|
||||||
pool->def->target.path,
|
pool->def->target.path);
|
||||||
strerror(errno));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +360,7 @@ virStorageBackendStablePath(virConnectPtr conn,
|
|||||||
|
|
||||||
if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) +
|
if (VIR_ALLOC_N(stablepath, strlen(pool->def->target.path) +
|
||||||
1 + strlen(dent->d_name) + 1) < 0) {
|
1 + strlen(dent->d_name) + 1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
|
virReportOOMError(conn);
|
||||||
closedir(dh);
|
closedir(dh);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -386,7 +387,7 @@ virStorageBackendStablePath(virConnectPtr conn,
|
|||||||
stablepath = strdup(devpath);
|
stablepath = strdup(devpath);
|
||||||
|
|
||||||
if (stablepath == NULL)
|
if (stablepath == NULL)
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("dup path"));
|
virReportOOMError(conn);
|
||||||
|
|
||||||
return stablepath;
|
return stablepath;
|
||||||
}
|
}
|
||||||
@ -423,7 +424,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Compile all regular expressions */
|
/* Compile all regular expressions */
|
||||||
if (VIR_ALLOC_N(reg, nregex) < 0) {
|
if (VIR_ALLOC_N(reg, nregex) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("regex"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,13 +449,11 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Storage for matched variables */
|
/* Storage for matched variables */
|
||||||
if (VIR_ALLOC_N(groups, totgroups) < 0) {
|
if (VIR_ALLOC_N(groups, totgroups) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("regex groups"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (VIR_ALLOC_N(vars, maxvars+1) < 0) {
|
if (VIR_ALLOC_N(vars, maxvars+1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("regex groups"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -490,8 +489,7 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
line[vars[j+1].rm_eo] = '\0';
|
line[vars[j+1].rm_eo] = '\0';
|
||||||
if ((groups[ngroup++] =
|
if ((groups[ngroup++] =
|
||||||
strdup(line + vars[j+1].rm_so)) == NULL) {
|
strdup(line + vars[j+1].rm_so)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("regex groups"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -538,9 +536,9 @@ virStorageBackendRunProgRegex(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (err == -1) {
|
if (err == -1) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to wait for command: %s"),
|
_("failed to wait for command '%s'"),
|
||||||
strerror(errno));
|
prog[0]);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
if (WIFEXITED(exitstatus)) {
|
if (WIFEXITED(exitstatus)) {
|
||||||
@ -588,8 +586,7 @@ virStorageBackendRunProgNul(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(v, n_columns) < 0) {
|
if (VIR_ALLOC_N(v, n_columns) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("n_columns too large"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for (i = 0; i < n_columns; i++)
|
for (i = 0; i < n_columns; i++)
|
||||||
@ -636,8 +633,8 @@ virStorageBackendRunProgNul(virConnectPtr conn,
|
|||||||
if (feof (fp))
|
if (feof (fp))
|
||||||
err = 0;
|
err = 0;
|
||||||
else
|
else
|
||||||
virStorageReportError (conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("read error: %s"), strerror (errno));
|
_("read error on pipe to '%s'"), prog[0]);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for (i = 0; i < n_columns; i++)
|
for (i = 0; i < n_columns; i++)
|
||||||
@ -657,9 +654,9 @@ virStorageBackendRunProgNul(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (w_err == -1) {
|
if (w_err == -1) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to wait for command: %s"),
|
_("failed to wait for command '%s'"),
|
||||||
strerror(errno));
|
prog[0]);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
if (WIFEXITED(exitstatus)) {
|
if (WIFEXITED(exitstatus)) {
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
#define PARTHELPER BINDIR "/libvirt_parthelper"
|
#define PARTHELPER BINDIR "/libvirt_parthelper"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -44,13 +46,13 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
|
|||||||
|
|
||||||
if (vol == NULL) {
|
if (vol == NULL) {
|
||||||
if (VIR_ALLOC(vol) < 0) {
|
if (VIR_ALLOC(vol) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(pool->volumes.objs,
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
||||||
pool->volumes.count+1) < 0) {
|
pool->volumes.count+1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virReportOOMError(conn);
|
||||||
virStorageVolDefFree(vol);
|
virStorageVolDefFree(vol);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -61,14 +63,14 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
|
|||||||
*/
|
*/
|
||||||
tmp = strrchr(groups[0], '/');
|
tmp = strrchr(groups[0], '/');
|
||||||
if ((vol->name = strdup(tmp ? tmp + 1 : groups[0])) == NULL) {
|
if ((vol->name = strdup(tmp ? tmp + 1 : groups[0])) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vol->target.path == NULL) {
|
if (vol->target.path == NULL) {
|
||||||
if ((devpath = strdup(groups[0])) == NULL) {
|
if ((devpath = strdup(groups[0])) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,15 +91,14 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
|
|||||||
if (vol->key == NULL) {
|
if (vol->key == NULL) {
|
||||||
/* XXX base off a unique key of the underlying disk */
|
/* XXX base off a unique key of the underlying disk */
|
||||||
if ((vol->key = strdup(vol->target.path)) == NULL) {
|
if ((vol->key = strdup(vol->target.path)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("volume"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vol->source.extents == NULL) {
|
if (vol->source.extents == NULL) {
|
||||||
if (VIR_ALLOC(vol->source.extents) < 0) {
|
if (VIR_ALLOC(vol->source.extents) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("volume extents"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vol->source.nextent = 1;
|
vol->source.nextent = 1;
|
||||||
@ -118,7 +119,7 @@ virStorageBackendDiskMakeDataVol(virConnectPtr conn,
|
|||||||
|
|
||||||
if ((vol->source.extents[0].path =
|
if ((vol->source.extents[0].path =
|
||||||
strdup(pool->def->source.devices[0].path)) == NULL) {
|
strdup(pool->def->source.devices[0].path)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("extents"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -367,9 +368,9 @@ virStorageBackendDiskDeleteVol(virConnectPtr conn,
|
|||||||
|
|
||||||
if ((n = readlink(vol->target.path, devpath, sizeof(devpath))) < 0 &&
|
if ((n = readlink(vol->target.path, devpath, sizeof(devpath))) < 0 &&
|
||||||
errno != EINVAL) {
|
errno != EINVAL) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Couldn't read volume target path '%s'. %s"),
|
_("Couldn't read volume target path '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
} else if (n <= 0) {
|
} else if (n <= 0) {
|
||||||
strncpy(devpath, vol->target.path, PATH_MAX);
|
strncpy(devpath, vol->target.path, PATH_MAX);
|
||||||
|
@ -122,6 +122,7 @@ const struct FileTypeInfo const fileTypeInfo[] = {
|
|||||||
*/
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -136,9 +137,9 @@ static int virStorageBackendProbeFile(virConnectPtr conn,
|
|||||||
int len, i, ret;
|
int len, i, ret;
|
||||||
|
|
||||||
if ((fd = open(def->target.path, O_RDONLY)) < 0) {
|
if ((fd = open(def->target.path, O_RDONLY)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot open volume '%s': %s"),
|
_("cannot open volume '%s'"),
|
||||||
def->target.path, strerror(errno));
|
def->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,9 +149,9 @@ static int virStorageBackendProbeFile(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((len = read(fd, head, sizeof(head))) < 0) {
|
if ((len = read(fd, head, sizeof(head))) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read header '%s': %s"),
|
_("cannot read header '%s'"),
|
||||||
def->target.path, strerror(errno));
|
def->target.path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -277,7 +278,7 @@ virStorageBackendFileSystemNetFindPoolSourcesFunc(virConnectPtr conn ATTRIBUTE_U
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(state->list.sources, state->list.nsources+1) < 0) {
|
if (VIR_REALLOC_N(state->list.sources, state->list.nsources+1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(state->list.sources + state->list.nsources, 0, sizeof(*state->list.sources));
|
memset(state->list.sources + state->list.nsources, 0, sizeof(*state->list.sources));
|
||||||
@ -335,7 +336,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn,
|
|||||||
|
|
||||||
xpath_ctxt = xmlXPathNewContext(doc);
|
xpath_ctxt = xmlXPathNewContext(doc);
|
||||||
if (xpath_ctxt == NULL) {
|
if (xpath_ctxt == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("xpath_ctxt"));
|
virReportOOMError(conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +355,7 @@ virStorageBackendFileSystemNetFindPoolSources(virConnectPtr conn,
|
|||||||
|
|
||||||
retval = virStoragePoolSourceListFormat(conn, &state.list);
|
retval = virStoragePoolSourceListFormat(conn, &state.list);
|
||||||
if (retval == NULL) {
|
if (retval == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("retval"));
|
virReportOOMError(conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,9 +388,9 @@ virStorageBackendFileSystemIsMounted(virConnectPtr conn,
|
|||||||
struct mntent *ent;
|
struct mntent *ent;
|
||||||
|
|
||||||
if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
|
if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read %s: %s"),
|
_("cannot read mount list '%s'"),
|
||||||
_PATH_MOUNTED, strerror(errno));
|
_PATH_MOUNTED);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +486,7 @@ virStorageBackendFileSystemMount(virConnectPtr conn,
|
|||||||
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
|
||||||
if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) +
|
if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) +
|
||||||
1 + strlen(pool->def->source.dir) + 1) < 0) {
|
1 + strlen(pool->def->source.dir) + 1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strcpy(src, pool->def->source.host.name);
|
strcpy(src, pool->def->source.host.name);
|
||||||
@ -493,7 +494,7 @@ virStorageBackendFileSystemMount(virConnectPtr conn,
|
|||||||
strcat(src, pool->def->source.dir);
|
strcat(src, pool->def->source.dir);
|
||||||
} else {
|
} else {
|
||||||
if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
|
if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -600,10 +601,11 @@ virStorageBackendFileSystemBuild(virConnectPtr conn,
|
|||||||
virStoragePoolObjPtr pool,
|
virStoragePoolObjPtr pool,
|
||||||
unsigned int flags ATTRIBUTE_UNUSED)
|
unsigned int flags ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
if (virFileMakePath(pool->def->target.path) < 0) {
|
int err;
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
if ((err = virFileMakePath(pool->def->target.path)) < 0) {
|
||||||
_("cannot create path '%s': %s"),
|
virReportSystemError(conn, err,
|
||||||
pool->def->target.path, strerror(errno));
|
_("cannot create path '%s'"),
|
||||||
|
pool->def->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,9 +627,9 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
|
|||||||
virStorageVolDefPtr vol = NULL;
|
virStorageVolDefPtr vol = NULL;
|
||||||
|
|
||||||
if (!(dir = opendir(pool->def->target.path))) {
|
if (!(dir = opendir(pool->def->target.path))) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot open path '%s': %s"),
|
_("cannot open path '%s'"),
|
||||||
pool->def->target.path, strerror(errno));
|
pool->def->target.path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,9 +676,9 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
if (statvfs(pool->def->target.path, &sb) < 0) {
|
if (statvfs(pool->def->target.path, &sb) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot statvfs path '%s': %s"),
|
_("cannot statvfs path '%s'"),
|
||||||
pool->def->target.path, strerror(errno));
|
pool->def->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pool->def->capacity = ((unsigned long long)sb.f_frsize *
|
pool->def->capacity = ((unsigned long long)sb.f_frsize *
|
||||||
@ -688,7 +690,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -740,9 +742,9 @@ virStorageBackendFileSystemDelete(virConnectPtr conn,
|
|||||||
/* XXX delete all vols first ? */
|
/* XXX delete all vols first ? */
|
||||||
|
|
||||||
if (unlink(pool->def->target.path) < 0) {
|
if (unlink(pool->def->target.path) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot unlink path '%s': %s"),
|
_("cannot unlink path '%s'"),
|
||||||
pool->def->target.path, strerror(errno));
|
pool->def->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -764,7 +766,7 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
|
|
||||||
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
|
||||||
1 + strlen(vol->name) + 1) < 0) {
|
1 + strlen(vol->name) + 1) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
vol->type = VIR_STORAGE_VOL_FILE;
|
vol->type = VIR_STORAGE_VOL_FILE;
|
||||||
@ -773,17 +775,16 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
strcat(vol->target.path, vol->name);
|
strcat(vol->target.path, vol->name);
|
||||||
vol->key = strdup(vol->target.path);
|
vol->key = strdup(vol->target.path);
|
||||||
if (vol->key == NULL) {
|
if (vol->key == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportOOMError(conn);
|
||||||
"%s", _("storage vol key"));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vol->target.format == VIR_STORAGE_VOL_FILE_RAW) {
|
if (vol->target.format == VIR_STORAGE_VOL_FILE_RAW) {
|
||||||
if ((fd = open(vol->target.path, O_RDWR | O_CREAT | O_EXCL,
|
if ((fd = open(vol->target.path, O_RDWR | O_CREAT | O_EXCL,
|
||||||
vol->target.perms.mode)) < 0) {
|
vol->target.perms.mode)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create path '%s': %s"),
|
_("cannot create path '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -798,9 +799,9 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
if (bytes > remain)
|
if (bytes > remain)
|
||||||
bytes = remain;
|
bytes = remain;
|
||||||
if ((bytes = safewrite(fd, zeros, bytes)) < 0) {
|
if ((bytes = safewrite(fd, zeros, bytes)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot fill file '%s': %s"),
|
_("cannot fill file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
unlink(vol->target.path);
|
unlink(vol->target.path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
@ -811,25 +812,25 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Now seek to final size, possibly making the file sparse */
|
/* Now seek to final size, possibly making the file sparse */
|
||||||
if (ftruncate(fd, vol->capacity) < 0) {
|
if (ftruncate(fd, vol->capacity) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot extend file '%s': %s"),
|
_("cannot extend file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
unlink(vol->target.path);
|
unlink(vol->target.path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (vol->target.format == VIR_STORAGE_VOL_FILE_DIR) {
|
} else if (vol->target.format == VIR_STORAGE_VOL_FILE_DIR) {
|
||||||
if (mkdir(vol->target.path, vol->target.perms.mode) < 0) {
|
if (mkdir(vol->target.path, vol->target.perms.mode) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create path '%s': %s"),
|
_("cannot create path '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(vol->target.path, O_RDWR)) < 0) {
|
if ((fd = open(vol->target.path, O_RDWR)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read path '%s': %s"),
|
_("cannot read path '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -862,9 +863,9 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read path '%s': %s"),
|
_("cannot read path '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
unlink(vol->target.path);
|
unlink(vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -897,9 +898,9 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read path '%s': %s"),
|
_("cannot read path '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
unlink(vol->target.path);
|
unlink(vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -914,18 +915,18 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
/* We can only chown/grp if root */
|
/* We can only chown/grp if root */
|
||||||
if (getuid() == 0) {
|
if (getuid() == 0) {
|
||||||
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
|
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot set file owner '%s': %s"),
|
_("cannot set file owner '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
unlink(vol->target.path);
|
unlink(vol->target.path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fchmod(fd, vol->target.perms.mode) < 0) {
|
if (fchmod(fd, vol->target.perms.mode) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot set file mode '%s': %s"),
|
_("cannot set file mode '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
unlink(vol->target.path);
|
unlink(vol->target.path);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
@ -939,9 +940,9 @@ virStorageBackendFileSystemVolCreate(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot close file '%s': %s"),
|
_("cannot close file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
unlink(vol->target.path);
|
unlink(vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -962,9 +963,9 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn,
|
|||||||
if (unlink(vol->target.path) < 0) {
|
if (unlink(vol->target.path) < 0) {
|
||||||
/* Silently ignore failures where the vol has already gone away */
|
/* Silently ignore failures where the vol has already gone away */
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot unlink file '%s': %s"),
|
_("cannot unlink file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virStorageBackendISCSITargetIP(virConnectPtr conn,
|
virStorageBackendISCSITargetIP(virConnectPtr conn,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
@ -204,9 +207,9 @@ virStorageBackendISCSINewLun(virConnectPtr conn, virStoragePoolObjPtr pool,
|
|||||||
usleep(100 * 1000);
|
usleep(100 * 1000);
|
||||||
goto reopen;
|
goto reopen;
|
||||||
}
|
}
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot open %s: %s"),
|
_("cannot open '%s'"),
|
||||||
devpath, strerror(errno));
|
devpath);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,9 +325,9 @@ virStorageBackendISCSIFindLUNs(virConnectPtr conn,
|
|||||||
|
|
||||||
sysdir = opendir(sysfs_path);
|
sysdir = opendir(sysfs_path);
|
||||||
if (sysdir == NULL) {
|
if (sysdir == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failed to opendir sysfs path %s: %s"),
|
_("Failed to opendir sysfs path '%s'"),
|
||||||
sysfs_path, strerror(errno));
|
sysfs_path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while ((sys_dirent = readdir(sysdir))) {
|
while ((sys_dirent = readdir(sysdir))) {
|
||||||
@ -354,10 +357,9 @@ virStorageBackendISCSIFindLUNs(virConnectPtr conn,
|
|||||||
n = scandir(sysfs_path, &namelist, notdotdir, versionsort);
|
n = scandir(sysfs_path, &namelist, notdotdir, versionsort);
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
/* we didn't find any reasonable entries; return failure */
|
/* we didn't find any reasonable entries; return failure */
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failed to find any LUNs for session %s: %s"),
|
_("Failed to find any LUNs for session '%s'"),
|
||||||
session, strerror(errno));
|
session);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,9 +409,9 @@ virStorageBackendISCSIFindLUNs(virConnectPtr conn,
|
|||||||
|
|
||||||
sysdir = opendir(sysfs_path);
|
sysdir = opendir(sysfs_path);
|
||||||
if (sysdir == NULL) {
|
if (sysdir == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failed to opendir sysfs path %s: %s"),
|
_("Failed to opendir sysfs path '%s'"),
|
||||||
sysfs_path, strerror(errno));
|
sysfs_path);
|
||||||
retval = -1;
|
retval = -1;
|
||||||
goto namelist_cleanup;
|
goto namelist_cleanup;
|
||||||
}
|
}
|
||||||
@ -443,9 +445,9 @@ virStorageBackendISCSIFindLUNs(virConnectPtr conn,
|
|||||||
host, bus, target, lun);
|
host, bus, target, lun);
|
||||||
sysdir = opendir(sysfs_path);
|
sysdir = opendir(sysfs_path);
|
||||||
if (sysdir == NULL) {
|
if (sysdir == NULL) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failed to opendir sysfs path %s: %s"),
|
_("Failed to opendir sysfs path '%s'"),
|
||||||
sysfs_path, strerror(errno));
|
sysfs_path);
|
||||||
retval = -1;
|
retval = -1;
|
||||||
goto namelist_cleanup;
|
goto namelist_cleanup;
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
#define PV_BLANK_SECTOR_SIZE 512
|
#define PV_BLANK_SECTOR_SIZE 512
|
||||||
|
|
||||||
|
|
||||||
@ -400,22 +402,22 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn,
|
|||||||
* rather than trying to figure out if we're a disk or partition
|
* rather than trying to figure out if we're a disk or partition
|
||||||
*/
|
*/
|
||||||
if ((fd = open(pool->def->source.devices[i].path, O_WRONLY)) < 0) {
|
if ((fd = open(pool->def->source.devices[i].path, O_WRONLY)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot open device %s"),
|
_("cannot open device '%s'"),
|
||||||
strerror(errno));
|
pool->def->source.devices[i].path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
|
if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot clear device header %s"),
|
_("cannot clear device header of '%s'"),
|
||||||
strerror(errno));
|
pool->def->source.devices[i].path);
|
||||||
close(fd);
|
close(fd);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot close device %s"),
|
_("cannot close device '%s'"),
|
||||||
strerror(errno));
|
pool->def->source.devices[i].path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -538,10 +540,9 @@ virStorageBackendLogicalDeletePool(virConnectPtr conn,
|
|||||||
pvargv[1] = pool->def->source.devices[i].path;
|
pvargv[1] = pool->def->source.devices[i].path;
|
||||||
if (virRun(conn, pvargv, NULL) < 0) {
|
if (virRun(conn, pvargv, NULL) < 0) {
|
||||||
error = -1;
|
error = -1;
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot remove PV device %s: %s"),
|
_("cannot remove PV device '%s'"),
|
||||||
pool->def->source.devices[i].path,
|
pool->def->source.devices[i].path);
|
||||||
strerror(errno));
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -591,41 +592,41 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read path '%s': %s"),
|
_("cannot read path '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We can only chown/grp if root */
|
/* We can only chown/grp if root */
|
||||||
if (getuid() == 0) {
|
if (getuid() == 0) {
|
||||||
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
|
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot set file owner '%s': %s"),
|
_("cannot set file owner '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fchmod(fd, vol->target.perms.mode) < 0) {
|
if (fchmod(fd, vol->target.perms.mode) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot set file mode '%s': %s"),
|
_("cannot set file mode '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot close file '%s': %s"),
|
_("cannot close file '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
fd = -1;
|
fd = -1;
|
||||||
|
|
||||||
/* Fill in data about this new vol */
|
/* Fill in data about this new vol */
|
||||||
if (virStorageBackendLogicalFindLVs(conn, pool, vol) < 0) {
|
if (virStorageBackendLogicalFindLVs(conn, pool, vol) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot find newly created volume '%s': %s"),
|
_("cannot find newly created volume '%s'"),
|
||||||
vol->target.path, strerror(errno));
|
vol->target.path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
/* Work around broken limits.h on debian etch */
|
/* Work around broken limits.h on debian etch */
|
||||||
#if defined __GNUC__ && defined _GCC_LIMITS_H_ && ! defined ULLONG_MAX
|
#if defined __GNUC__ && defined _GCC_LIMITS_H_ && ! defined ULLONG_MAX
|
||||||
# define ULLONG_MAX ULONG_LONG_MAX
|
# define ULLONG_MAX ULONG_LONG_MAX
|
||||||
@ -1405,9 +1407,9 @@ virStoragePoolObjSaveDef(virConnectPtr conn,
|
|||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
|
||||||
if ((err = virFileMakePath(driver->configDir))) {
|
if ((err = virFileMakePath(driver->configDir))) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virStorageReportError(conn, err,
|
||||||
_("cannot create config directory %s: %s"),
|
_("cannot create config directory %s"),
|
||||||
driver->configDir, strerror(err));
|
driver->configDir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1448,24 +1450,24 @@ virStoragePoolObjSaveDef(virConnectPtr conn,
|
|||||||
if ((fd = open(pool->configFile,
|
if ((fd = open(pool->configFile,
|
||||||
O_WRONLY | O_CREAT | O_TRUNC,
|
O_WRONLY | O_CREAT | O_TRUNC,
|
||||||
S_IRUSR | S_IWUSR )) < 0) {
|
S_IRUSR | S_IWUSR )) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create config file %s: %s"),
|
_("cannot create config file %s"),
|
||||||
pool->configFile, strerror(errno));
|
pool->configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
towrite = strlen(xml);
|
towrite = strlen(xml);
|
||||||
if (safewrite(fd, xml, towrite) != towrite) {
|
if (safewrite(fd, xml, towrite) != towrite) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot write config file %s: %s"),
|
_("cannot write config file %s"),
|
||||||
pool->configFile, strerror(errno));
|
pool->configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot save config file %s: %s"),
|
_("cannot save config file %s"),
|
||||||
pool->configFile, strerror(errno));
|
pool->configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "storage_backend.h"
|
#include "storage_backend.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
#define storageLog(msg...) fprintf(stderr, msg)
|
#define storageLog(msg...) fprintf(stderr, msg)
|
||||||
|
|
||||||
static virStorageDriverStatePtr driverState;
|
static virStorageDriverStatePtr driverState;
|
||||||
@ -379,8 +381,7 @@ storageListPools(virConnectPtr conn,
|
|||||||
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
if (virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
||||||
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
|
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
|
||||||
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("names"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
got++;
|
got++;
|
||||||
@ -428,8 +429,7 @@ storageListDefinedPools(virConnectPtr conn,
|
|||||||
if (!virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
if (!virStoragePoolObjIsActive(driver->pools.objs[i])) {
|
||||||
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
|
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
|
||||||
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
virStoragePoolObjUnlock(driver->pools.objs[i]);
|
||||||
virStorageReportError(conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("names"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
got++;
|
got++;
|
||||||
@ -952,25 +952,24 @@ storagePoolSetAutostart(virStoragePoolPtr obj,
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
if ((err = virFileMakePath(driver->autostartDir))) {
|
||||||
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(obj->conn, err,
|
||||||
_("cannot create autostart directory %s: %s"),
|
_("cannot create autostart directory %s"),
|
||||||
driver->autostartDir, strerror(err));
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symlink(pool->configFile, pool->autostartLink) < 0) {
|
if (symlink(pool->configFile, pool->autostartLink) < 0) {
|
||||||
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(obj->conn, errno,
|
||||||
_("Failed to create symlink '%s' to '%s': %s"),
|
_("Failed to create symlink '%s' to '%s'"),
|
||||||
pool->autostartLink, pool->configFile,
|
pool->autostartLink, pool->configFile);
|
||||||
strerror(errno));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (unlink(pool->autostartLink) < 0 &&
|
if (unlink(pool->autostartLink) < 0 &&
|
||||||
errno != ENOENT && errno != ENOTDIR) {
|
errno != ENOENT && errno != ENOTDIR) {
|
||||||
virStorageReportError(obj->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(obj->conn, errno,
|
||||||
_("Failed to delete symlink '%s': %s"),
|
_("Failed to delete symlink '%s'"),
|
||||||
pool->autostartLink, strerror(errno));
|
pool->autostartLink);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1042,8 +1041,7 @@ storagePoolListVolumes(virStoragePoolPtr obj,
|
|||||||
|
|
||||||
for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) {
|
for (i = 0 ; i < pool->volumes.count && n < maxnames ; i++) {
|
||||||
if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) {
|
if ((names[n++] = strdup(pool->volumes.objs[i]->name)) == NULL) {
|
||||||
virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY,
|
virReportOOMError(obj->conn);
|
||||||
"%s", _("name"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1224,7 +1222,7 @@ storageVolumeCreateXML(virStoragePoolPtr obj,
|
|||||||
|
|
||||||
if (VIR_REALLOC_N(pool->volumes.objs,
|
if (VIR_REALLOC_N(pool->volumes.objs,
|
||||||
pool->volumes.count+1) < 0) {
|
pool->volumes.count+1) < 0) {
|
||||||
virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(obj->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1453,7 +1451,7 @@ storageVolumeGetPath(virStorageVolPtr obj) {
|
|||||||
|
|
||||||
ret = strdup(vol->target.path);
|
ret = strdup(vol->target.path);
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
virStorageReportError(obj->conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
|
virReportOOMError(obj->conn);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (pool)
|
if (pool)
|
||||||
|
146
src/test.c
146
src/test.c
@ -46,6 +46,8 @@
|
|||||||
#include "xml.h"
|
#include "xml.h"
|
||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_TEST
|
||||||
|
|
||||||
#define MAX_CPUS 128
|
#define MAX_CPUS 128
|
||||||
|
|
||||||
struct _testCell {
|
struct _testCell {
|
||||||
@ -154,7 +156,7 @@ testBuildCapabilities(virConnectPtr conn) {
|
|||||||
return caps;
|
return caps;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
virCapabilitiesFree(caps);
|
virCapabilitiesFree(caps);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -195,7 +197,7 @@ static const char *defaultPoolXML =
|
|||||||
static const unsigned long long defaultPoolCap = (100 * 1024 * 1024 * 1024ull);
|
static const unsigned long long defaultPoolCap = (100 * 1024 * 1024 * 1024ull);
|
||||||
static const unsigned long long defaultPoolAlloc = 0;
|
static const unsigned long long defaultPoolAlloc = 0;
|
||||||
|
|
||||||
static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool);
|
static int testStoragePoolObjSetDefaults(virConnectPtr conn, virStoragePoolObjPtr pool);
|
||||||
|
|
||||||
static int testOpenDefault(virConnectPtr conn) {
|
static int testOpenDefault(virConnectPtr conn) {
|
||||||
int u;
|
int u;
|
||||||
@ -209,7 +211,7 @@ static int testOpenDefault(virConnectPtr conn) {
|
|||||||
virStoragePoolObjPtr poolobj = NULL;
|
virStoragePoolObjPtr poolobj = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(privconn) < 0) {
|
if (VIR_ALLOC(privconn) < 0) {
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, "testConn");
|
virReportOOMError(conn);
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
if (virMutexInit(&privconn->lock) < 0) {
|
if (virMutexInit(&privconn->lock) < 0) {
|
||||||
@ -223,7 +225,8 @@ static int testOpenDefault(virConnectPtr conn) {
|
|||||||
conn->privateData = privconn;
|
conn->privateData = privconn;
|
||||||
|
|
||||||
if (gettimeofday(&tv, NULL) < 0) {
|
if (gettimeofday(&tv, NULL) < 0) {
|
||||||
testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("getting time of day"));
|
virReportSystemError(conn, errno,
|
||||||
|
"%s", _("getting time of day"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +279,7 @@ static int testOpenDefault(virConnectPtr conn) {
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (testStoragePoolObjSetDefaults(poolobj) == -1) {
|
if (testStoragePoolObjSetDefaults(conn, poolobj) == -1) {
|
||||||
virStoragePoolObjUnlock(poolobj);
|
virStoragePoolObjUnlock(poolobj);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -336,7 +339,7 @@ static int testOpenFromFile(virConnectPtr conn,
|
|||||||
virDomainObjPtr dom;
|
virDomainObjPtr dom;
|
||||||
testConnPtr privconn;
|
testConnPtr privconn;
|
||||||
if (VIR_ALLOC(privconn) < 0) {
|
if (VIR_ALLOC(privconn) < 0) {
|
||||||
testError(NULL, VIR_ERR_NO_MEMORY, "testConn");
|
virReportOOMError(conn);
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
if (virMutexInit(&privconn->lock) < 0) {
|
if (virMutexInit(&privconn->lock) < 0) {
|
||||||
@ -353,9 +356,9 @@ static int testOpenFromFile(virConnectPtr conn,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if ((fd = open(file, O_RDONLY)) < 0) {
|
if ((fd = open(file, O_RDONLY)) < 0) {
|
||||||
testError(NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
_("loading host definition file '%s': %s"),
|
_("loading host definition file '%s'"),
|
||||||
file, strerror(errno));
|
file);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,7 +576,7 @@ static int testOpenFromFile(virConnectPtr conn,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (testStoragePoolObjSetDefaults(pool) == -1) {
|
if (testStoragePoolObjSetDefaults(conn, pool) == -1) {
|
||||||
virStoragePoolObjUnlock(pool);
|
virStoragePoolObjUnlock(pool);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -673,8 +676,8 @@ static char *testGetHostname (virConnectPtr conn)
|
|||||||
|
|
||||||
result = virGetHostname();
|
result = virGetHostname();
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
testError (conn, VIR_ERR_SYSTEM_ERROR, "%s",
|
virReportSystemError(conn, errno,
|
||||||
strerror (errno));
|
"%s", _("cannot lookup hostname"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Caller frees this string. */
|
/* Caller frees this string. */
|
||||||
@ -703,7 +706,7 @@ static char *testGetCapabilities (virConnectPtr conn)
|
|||||||
char *xml;
|
char *xml;
|
||||||
testDriverLock(privconn);
|
testDriverLock(privconn);
|
||||||
if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL)
|
if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL)
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
return xml;
|
return xml;
|
||||||
}
|
}
|
||||||
@ -1111,42 +1114,42 @@ static int testDomainSave(virDomainPtr domain,
|
|||||||
|
|
||||||
xml = testDomainDumpXML(domain, 0);
|
xml = testDomainDumpXML(domain, 0);
|
||||||
if (xml == NULL) {
|
if (xml == NULL) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("saving domain '%s' failed to allocate space for metadata: %s"),
|
_("saving domain '%s' failed to allocate space for metadata"),
|
||||||
domain->name, strerror(errno));
|
domain->name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
|
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("saving domain '%s' to '%s': open failed: %s"),
|
_("saving domain '%s' to '%s': open failed"),
|
||||||
domain->name, path, strerror(errno));
|
domain->name, path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
len = strlen(xml);
|
len = strlen(xml);
|
||||||
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
|
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("saving domain '%s' to '%s': write failed: %s"),
|
_("saving domain '%s' to '%s': write failed"),
|
||||||
domain->name, path, strerror(errno));
|
domain->name, path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
|
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("saving domain '%s' to '%s': write failed: %s"),
|
_("saving domain '%s' to '%s': write failed"),
|
||||||
domain->name, path, strerror(errno));
|
domain->name, path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (safewrite(fd, xml, len) < 0) {
|
if (safewrite(fd, xml, len) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("saving domain '%s' to '%s': write failed: %s"),
|
_("saving domain '%s' to '%s': write failed"),
|
||||||
domain->name, path, strerror(errno));
|
domain->name, path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("saving domain '%s' to '%s': write failed: %s"),
|
_("saving domain '%s' to '%s': write failed"),
|
||||||
domain->name, path, strerror(errno));
|
domain->name, path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
fd = -1;
|
fd = -1;
|
||||||
@ -1189,13 +1192,15 @@ static int testDomainRestore(virConnectPtr conn,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if ((fd = open(path, O_RDONLY)) < 0) {
|
if ((fd = open(path, O_RDONLY)) < 0) {
|
||||||
testError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("cannot read domain image"));
|
_("cannot read domain image '%s'"),
|
||||||
|
path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
|
if (saferead(fd, magic, sizeof(magic)) != sizeof(magic)) {
|
||||||
testError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("incomplete save header"));
|
_("incomplete save header in '%s'"),
|
||||||
|
path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) {
|
if (memcmp(magic, TEST_SAVE_MAGIC, sizeof(magic))) {
|
||||||
@ -1203,9 +1208,10 @@ static int testDomainRestore(virConnectPtr conn,
|
|||||||
"%s", _("mismatched header magic"));
|
"%s", _("mismatched header magic"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (read(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
|
if (saferead(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
|
||||||
testError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("failed to read metadata length"));
|
_("failed to read metadata length in '%s'"),
|
||||||
|
path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (len < 1 || len > 8192) {
|
if (len < 1 || len > 8192) {
|
||||||
@ -1214,12 +1220,12 @@ static int testDomainRestore(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (VIR_ALLOC_N(xml, len+1) < 0) {
|
if (VIR_ALLOC_N(xml, len+1) < 0) {
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, "xml");
|
virReportOOMError(conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (read(fd, xml, len) != len) {
|
if (saferead(fd, xml, len) != len) {
|
||||||
testError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("incomplete metdata"));
|
_("incomplete metdata in '%s'"), path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
xml[len] = '\0';
|
xml[len] = '\0';
|
||||||
@ -1269,21 +1275,21 @@ static int testDomainCoreDump(virDomainPtr domain,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
|
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("domain '%s' coredump: failed to open %s: %s"),
|
_("domain '%s' coredump: failed to open %s"),
|
||||||
domain->name, to, strerror (errno));
|
domain->name, to);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
|
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("domain '%s' coredump: failed to write header to %s: %s"),
|
_("domain '%s' coredump: failed to write header to %s"),
|
||||||
domain->name, to, strerror (errno));
|
domain->name, to);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (close(fd) < 0) {
|
if (close(fd) < 0) {
|
||||||
testError(domain->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("domain '%s' coredump: write failed: %s: %s"),
|
_("domain '%s' coredump: write failed: %s"),
|
||||||
domain->name, to, strerror (errno));
|
domain->name, to);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
privdom->state = VIR_DOMAIN_SHUTOFF;
|
privdom->state = VIR_DOMAIN_SHUTOFF;
|
||||||
@ -1306,7 +1312,7 @@ cleanup:
|
|||||||
static char *testGetOSType(virDomainPtr dom) {
|
static char *testGetOSType(virDomainPtr dom) {
|
||||||
char *ret = strdup("linux");
|
char *ret = strdup("linux");
|
||||||
if (!ret)
|
if (!ret)
|
||||||
testError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(dom->conn);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1491,7 +1497,7 @@ static int testListDefinedDomains(virConnectPtr conn,
|
|||||||
return n;
|
return n;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
for (n = 0 ; n < maxnames ; n++)
|
for (n = 0 ; n < maxnames ; n++)
|
||||||
VIR_FREE(names[n]);
|
VIR_FREE(names[n]);
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
@ -1682,7 +1688,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain,
|
|||||||
*nparams = 1;
|
*nparams = 1;
|
||||||
type = strdup("fair");
|
type = strdup("fair");
|
||||||
if (!type)
|
if (!type)
|
||||||
testError(domain->conn, VIR_ERR_NO_MEMORY, "schedular");
|
virReportOOMError(domain->conn);
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -1864,7 +1870,7 @@ static int testListNetworks(virConnectPtr conn, char **const names, int nnames)
|
|||||||
return n;
|
return n;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
for (n = 0 ; n < nnames ; n++)
|
for (n = 0 ; n < nnames ; n++)
|
||||||
VIR_FREE(names[n]);
|
VIR_FREE(names[n]);
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
@ -1907,7 +1913,7 @@ static int testListDefinedNetworks(virConnectPtr conn, char **const names, int n
|
|||||||
return n;
|
return n;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
for (n = 0 ; n < nnames ; n++)
|
for (n = 0 ; n < nnames ; n++)
|
||||||
VIR_FREE(names[n]);
|
VIR_FREE(names[n]);
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
@ -2099,7 +2105,7 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) {
|
|||||||
|
|
||||||
if (privnet->def->bridge &&
|
if (privnet->def->bridge &&
|
||||||
!(bridge = strdup(privnet->def->bridge))) {
|
!(bridge = strdup(privnet->def->bridge))) {
|
||||||
testError(network->conn, VIR_ERR_NO_MEMORY, "network");
|
virReportOOMError(network->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2164,7 +2170,8 @@ cleanup:
|
|||||||
* Storage Driver routines
|
* Storage Driver routines
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) {
|
static int testStoragePoolObjSetDefaults(virConnectPtr conn,
|
||||||
|
virStoragePoolObjPtr pool) {
|
||||||
|
|
||||||
pool->def->capacity = defaultPoolCap;
|
pool->def->capacity = defaultPoolCap;
|
||||||
pool->def->allocation = defaultPoolAlloc;
|
pool->def->allocation = defaultPoolAlloc;
|
||||||
@ -2172,7 +2179,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) {
|
|||||||
|
|
||||||
pool->configFile = strdup("\0");
|
pool->configFile = strdup("\0");
|
||||||
if (!pool->configFile) {
|
if (!pool->configFile) {
|
||||||
testError(NULL, VIR_ERR_NO_MEMORY, "configFile");
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2284,7 +2291,7 @@ testStorageListPools(virConnectPtr conn,
|
|||||||
return n;
|
return n;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
for (n = 0 ; n < nnames ; n++)
|
for (n = 0 ; n < nnames ; n++)
|
||||||
VIR_FREE(names[n]);
|
VIR_FREE(names[n]);
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
@ -2331,7 +2338,7 @@ testStorageListDefinedPools(virConnectPtr conn,
|
|||||||
return n;
|
return n;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
testError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
for (n = 0 ; n < nnames ; n++)
|
for (n = 0 ; n < nnames ; n++)
|
||||||
VIR_FREE(names[n]);
|
VIR_FREE(names[n]);
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
@ -2408,7 +2415,7 @@ testStoragePoolCreate(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
|
||||||
if (testStoragePoolObjSetDefaults(pool) == -1) {
|
if (testStoragePoolObjSetDefaults(conn, pool) == -1) {
|
||||||
virStoragePoolObjRemove(&privconn->pools, pool);
|
virStoragePoolObjRemove(&privconn->pools, pool);
|
||||||
pool = NULL;
|
pool = NULL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2447,7 +2454,7 @@ testStoragePoolDefine(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
|
||||||
if (testStoragePoolObjSetDefaults(pool) == -1) {
|
if (testStoragePoolObjSetDefaults(conn, pool) == -1) {
|
||||||
virStoragePoolObjRemove(&privconn->pools, pool);
|
virStoragePoolObjRemove(&privconn->pools, pool);
|
||||||
pool = NULL;
|
pool = NULL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -2806,7 +2813,7 @@ testStoragePoolListVolumes(virStoragePoolPtr pool,
|
|||||||
|
|
||||||
for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) {
|
for (i = 0 ; i < privpool->volumes.count && n < maxnames ; i++) {
|
||||||
if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) {
|
if ((names[n++] = strdup(privpool->volumes.objs[i]->name)) == NULL) {
|
||||||
testError(pool->conn, VIR_ERR_NO_MEMORY, "%s", _("name"));
|
virReportOOMError(pool->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2986,14 +2993,14 @@ testStorageVolumeCreateXML(virStoragePoolPtr pool,
|
|||||||
|
|
||||||
if (VIR_REALLOC_N(privpool->volumes.objs,
|
if (VIR_REALLOC_N(privpool->volumes.objs,
|
||||||
privpool->volumes.count+1) < 0) {
|
privpool->volumes.count+1) < 0) {
|
||||||
testError(pool->conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(pool->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(privvol->target.path,
|
if (VIR_ALLOC_N(privvol->target.path,
|
||||||
strlen(privpool->def->target.path) +
|
strlen(privpool->def->target.path) +
|
||||||
1 + strlen(privvol->name) + 1) < 0) {
|
1 + strlen(privvol->name) + 1) < 0) {
|
||||||
testError(pool->conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
|
virReportOOMError(pool->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3002,8 +3009,7 @@ testStorageVolumeCreateXML(virStoragePoolPtr pool,
|
|||||||
strcat(privvol->target.path, privvol->name);
|
strcat(privvol->target.path, privvol->name);
|
||||||
privvol->key = strdup(privvol->target.path);
|
privvol->key = strdup(privvol->target.path);
|
||||||
if (privvol->key == NULL) {
|
if (privvol->key == NULL) {
|
||||||
testError(pool->conn, VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportOOMError(pool->conn);
|
||||||
_("storage vol key"));
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3224,7 +3230,7 @@ testStorageVolumeGetPath(virStorageVolPtr vol) {
|
|||||||
|
|
||||||
ret = strdup(privvol->target.path);
|
ret = strdup(privvol->target.path);
|
||||||
if (ret == NULL)
|
if (ret == NULL)
|
||||||
testError(vol->conn, VIR_ERR_NO_MEMORY, "%s", _("path"));
|
virReportOOMError(vol->conn);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (privpool)
|
if (privpool)
|
||||||
|
107
src/uml_driver.c
107
src/uml_driver.c
@ -64,6 +64,8 @@
|
|||||||
#include "datatypes.h"
|
#include "datatypes.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_UML
|
||||||
|
|
||||||
/* For storing short-lived temporary files. */
|
/* For storing short-lived temporary files. */
|
||||||
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
|
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
|
||||||
|
|
||||||
@ -159,7 +161,7 @@ umlIdentifyOneChrPTY(virConnectPtr conn,
|
|||||||
char *res = NULL;
|
char *res = NULL;
|
||||||
int retries = 0;
|
int retries = 0;
|
||||||
if (virAsprintf(&cmd, "config %s%d", dev, def->dstPort) < 0) {
|
if (virAsprintf(&cmd, "config %s%d", dev, def->dstPort) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
requery:
|
requery:
|
||||||
@ -168,7 +170,7 @@ requery:
|
|||||||
if (STRPREFIX(res, "pts:")) {
|
if (STRPREFIX(res, "pts:")) {
|
||||||
VIR_FREE(def->data.file.path);
|
VIR_FREE(def->data.file.path);
|
||||||
if ((def->data.file.path = strdup(res + 4)) == NULL) {
|
if ((def->data.file.path = strdup(res + 4)) == NULL) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
VIR_FREE(res);
|
VIR_FREE(res);
|
||||||
VIR_FREE(cmd);
|
VIR_FREE(cmd);
|
||||||
return -1;
|
return -1;
|
||||||
@ -523,7 +525,7 @@ static int umlReadPidFile(virConnectPtr conn,
|
|||||||
vm->pid = -1;
|
vm->pid = -1;
|
||||||
if (virAsprintf(&pidfile, "%s/%s/pid",
|
if (virAsprintf(&pidfile, "%s/%s/pid",
|
||||||
driver->monitorDir, vm->def->name) < 0) {
|
driver->monitorDir, vm->def->name) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,9 +551,9 @@ reopen:
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to read pid: %s: %s"),
|
_("failed to read pid: %s"),
|
||||||
pidfile, strerror(errno));
|
pidfile);
|
||||||
VIR_FREE(pidfile);
|
VIR_FREE(pidfile);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -564,7 +566,7 @@ static int umlMonitorAddress(virConnectPtr conn,
|
|||||||
|
|
||||||
if (virAsprintf(&sockname, "%s/%s/mconsole",
|
if (virAsprintf(&sockname, "%s/%s/mconsole",
|
||||||
driver->monitorDir, vm->def->name) < 0) {
|
driver->monitorDir, vm->def->name) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -597,16 +599,16 @@ restat:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((vm->monitor = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
if ((vm->monitor = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot open socket %s"), strerror(errno));
|
"%s", _("cannot open socket"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(addr.sun_path, 0, sizeof addr.sun_path);
|
memset(addr.sun_path, 0, sizeof addr.sun_path);
|
||||||
sprintf(addr.sun_path + 1, "%u", getpid());
|
sprintf(addr.sun_path + 1, "%u", getpid());
|
||||||
if (bind(vm->monitor, (struct sockaddr *)&addr, sizeof addr) < 0) {
|
if (bind(vm->monitor, (struct sockaddr *)&addr, sizeof addr) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot bind socket %s"), strerror(errno));
|
"%s", _("cannot bind socket"));
|
||||||
close(vm->monitor);
|
close(vm->monitor);
|
||||||
vm->monitor = -1;
|
vm->monitor = -1;
|
||||||
return -1;
|
return -1;
|
||||||
@ -658,9 +660,9 @@ static int umlMonitorCommand(virConnectPtr conn,
|
|||||||
req.version = MONITOR_VERSION;
|
req.version = MONITOR_VERSION;
|
||||||
req.length = strlen(cmd);
|
req.length = strlen(cmd);
|
||||||
if (req.length > (MONITOR_BUFLEN-1)) {
|
if (req.length > (MONITOR_BUFLEN-1)) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, EINVAL,
|
||||||
_("cannot send too long command %s: %s"),
|
_("cannot send too long command %s (%d bytes)"),
|
||||||
cmd, strerror(EINVAL));
|
cmd, req.length);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strncpy(req.data, cmd, req.length);
|
strncpy(req.data, cmd, req.length);
|
||||||
@ -668,9 +670,9 @@ static int umlMonitorCommand(virConnectPtr conn,
|
|||||||
|
|
||||||
if (sendto(vm->monitor, &req, sizeof req, 0,
|
if (sendto(vm->monitor, &req, sizeof req, 0,
|
||||||
(struct sockaddr *)&addr, sizeof addr) != (sizeof req)) {
|
(struct sockaddr *)&addr, sizeof addr) != (sizeof req)) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot send command %s: %s"),
|
_("cannot send command %s"),
|
||||||
cmd, strerror(errno));
|
cmd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,15 +680,14 @@ static int umlMonitorCommand(virConnectPtr conn,
|
|||||||
addrlen = sizeof(addr);
|
addrlen = sizeof(addr);
|
||||||
if (recvfrom(vm->monitor, &res, sizeof res, 0,
|
if (recvfrom(vm->monitor, &res, sizeof res, 0,
|
||||||
(struct sockaddr *)&addr, &addrlen) < 0) {
|
(struct sockaddr *)&addr, &addrlen) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot read reply %s: %s"),
|
_("cannot read reply %s"),
|
||||||
cmd, strerror(errno));
|
cmd);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(retdata, retlen + res.length) < 0) {
|
if (VIR_REALLOC_N(retdata, retlen + res.length) < 0) {
|
||||||
umlReportError(conn, NULL, NULL,
|
virReportOOMError(conn);
|
||||||
VIR_ERR_NO_MEMORY, NULL);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
memcpy(retdata + retlen, res.data, res.length);
|
memcpy(retdata + retlen, res.data, res.length);
|
||||||
@ -740,14 +741,14 @@ static int umlStartVMDaemon(virConnectPtr conn,
|
|||||||
* in a sub-process so its hard to feed back a useful error
|
* in a sub-process so its hard to feed back a useful error
|
||||||
*/
|
*/
|
||||||
if (stat(vm->def->os.kernel, &sb) < 0) {
|
if (stat(vm->def->os.kernel, &sb) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Cannot find UML kernel %s: %s"),
|
_("Cannot find UML kernel %s"),
|
||||||
vm->def->os.kernel, strerror(errno));
|
vm->def->os.kernel);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virFileMakePath(driver->logDir) < 0) {
|
if (virFileMakePath(driver->logDir) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create log directory %s"),
|
_("cannot create log directory %s"),
|
||||||
driver->logDir);
|
driver->logDir);
|
||||||
return -1;
|
return -1;
|
||||||
@ -755,24 +756,23 @@ static int umlStartVMDaemon(virConnectPtr conn,
|
|||||||
|
|
||||||
if (virAsprintf(&logfile, "%s/%s.log",
|
if (virAsprintf(&logfile, "%s/%s.log",
|
||||||
driver->logDir, vm->def->name) < 0) {
|
driver->logDir, vm->def->name) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((logfd = open(logfile, O_CREAT | O_TRUNC | O_WRONLY,
|
if ((logfd = open(logfile, O_CREAT | O_TRUNC | O_WRONLY,
|
||||||
S_IRUSR | S_IWUSR)) < 0) {
|
S_IRUSR | S_IWUSR)) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to create logfile %s: %s"),
|
_("failed to create logfile %s"),
|
||||||
logfile, strerror(errno));
|
logfile);
|
||||||
VIR_FREE(logfile);
|
VIR_FREE(logfile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_FREE(logfile);
|
VIR_FREE(logfile);
|
||||||
|
|
||||||
if (umlSetCloseExec(logfd) < 0) {
|
if (umlSetCloseExec(logfd) < 0) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Unable to set VM logfile close-on-exec flag %s"),
|
"%s", _("Unable to set VM logfile close-on-exec flag"));
|
||||||
strerror(errno));
|
|
||||||
close(logfd);
|
close(logfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -908,7 +908,7 @@ static virDrvOpenStatus umlOpen(virConnectPtr conn,
|
|||||||
} else {
|
} else {
|
||||||
conn->uri = xmlParseURI(uid ? "uml:///session" : "uml:///system");
|
conn->uri = xmlParseURI(uid ? "uml:///session" : "uml:///system");
|
||||||
if (!conn->uri) {
|
if (!conn->uri) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,NULL);
|
virReportOOMError(conn);
|
||||||
return VIR_DRV_OPEN_ERROR;
|
return VIR_DRV_OPEN_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -945,8 +945,7 @@ static char *umlGetCapabilities(virConnectPtr conn) {
|
|||||||
|
|
||||||
umlDriverLock(driver);
|
umlDriverLock(driver);
|
||||||
if ((xml = virCapabilitiesFormatXML(driver->caps)) == NULL)
|
if ((xml = virCapabilitiesFormatXML(driver->caps)) == NULL)
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("failed to allocate space for capabilities support"));
|
|
||||||
umlDriverUnlock(driver);
|
umlDriverUnlock(driver);
|
||||||
|
|
||||||
return xml;
|
return xml;
|
||||||
@ -1156,8 +1155,8 @@ umlGetHostname (virConnectPtr conn)
|
|||||||
|
|
||||||
result = virGetHostname();
|
result = virGetHostname();
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
umlReportError (conn, NULL, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", strerror (errno));
|
"%s", _("cannot lookup hostname"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Caller frees this string. */
|
/* Caller frees this string. */
|
||||||
@ -1325,8 +1324,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(type = strdup(vm->def->os.type)))
|
if (!(type = strdup(vm->def->os.type)))
|
||||||
umlReportError(dom->conn, dom, NULL, VIR_ERR_NO_MEMORY,
|
virReportOOMError(dom->conn);
|
||||||
"%s", _("failed to allocate space for ostype"));
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (vm)
|
if (vm)
|
||||||
@ -1510,8 +1508,7 @@ static int umlListDefinedDomains(virConnectPtr conn,
|
|||||||
virDomainObjLock(driver->domains.objs[i]);
|
virDomainObjLock(driver->domains.objs[i]);
|
||||||
if (!virDomainIsActive(driver->domains.objs[i])) {
|
if (!virDomainIsActive(driver->domains.objs[i])) {
|
||||||
if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) {
|
if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) {
|
||||||
umlReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY,
|
virReportOOMError(conn);
|
||||||
"%s", _("failed to allocate space for VM name string"));
|
|
||||||
virDomainObjUnlock(driver->domains.objs[i]);
|
virDomainObjUnlock(driver->domains.objs[i]);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -1710,23 +1707,23 @@ static int umlDomainSetAutostart(virDomainPtr dom,
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
if ((err = virFileMakePath(driver->autostartDir))) {
|
if ((err = virFileMakePath(driver->autostartDir))) {
|
||||||
umlReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, err,
|
||||||
_("cannot create autostart directory %s: %s"),
|
_("cannot create autostart directory %s"),
|
||||||
driver->autostartDir, strerror(err));
|
driver->autostartDir);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (symlink(configFile, autostartLink) < 0) {
|
if (symlink(configFile, autostartLink) < 0) {
|
||||||
umlReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("Failed to create symlink '%s to '%s': %s"),
|
_("Failed to create symlink '%s to '%s'"),
|
||||||
autostartLink, configFile, strerror(errno));
|
autostartLink, configFile);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
|
||||||
umlReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("Failed to delete symlink '%s': %s"),
|
_("Failed to delete symlink '%s'"),
|
||||||
autostartLink, strerror(errno));
|
autostartLink);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1785,8 +1782,8 @@ umlDomainBlockPeek (virDomainPtr dom,
|
|||||||
/* The path is correct, now try to open it and get its size. */
|
/* The path is correct, now try to open it and get its size. */
|
||||||
fd = open (path, O_RDONLY);
|
fd = open (path, O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
umlReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
"%s", strerror (errno));
|
_("cannot open %s"), path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1796,8 +1793,8 @@ umlDomainBlockPeek (virDomainPtr dom,
|
|||||||
*/
|
*/
|
||||||
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
|
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
|
||||||
saferead (fd, buffer, size) == (ssize_t) -1) {
|
saferead (fd, buffer, size) == (ssize_t) -1) {
|
||||||
umlReportError (dom->conn, dom, NULL, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
"%s", strerror (errno));
|
_("cannot read %s"), path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
86
src/util.c
86
src/util.c
@ -67,6 +67,7 @@
|
|||||||
|
|
||||||
#define virLog(msg...) fprintf(stderr, msg)
|
#define virLog(msg...) fprintf(stderr, msg)
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
#define ReportError(conn, code, fmt...) \
|
#define ReportError(conn, code, fmt...) \
|
||||||
virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \
|
virReportErrorHelper(conn, VIR_FROM_NONE, code, __FILE__, \
|
||||||
@ -212,36 +213,35 @@ __virExec(virConnectPtr conn,
|
|||||||
*/
|
*/
|
||||||
sigfillset(&newmask);
|
sigfillset(&newmask);
|
||||||
if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
|
if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot block signals: %s"),
|
"%s", _("cannot block signals"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((null = open("/dev/null", O_RDONLY)) < 0) {
|
if ((null = open("/dev/null", O_RDONLY)) < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot open %s: %s"),
|
_("cannot open %s"),
|
||||||
"/dev/null", strerror(errno));
|
"/dev/null");
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outfd != NULL) {
|
if (outfd != NULL) {
|
||||||
if (*outfd == -1) {
|
if (*outfd == -1) {
|
||||||
if (pipe(pipeout) < 0) {
|
if (pipe(pipeout) < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot create pipe: %s"), strerror(errno));
|
"%s", _("cannot create pipe"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & VIR_EXEC_NONBLOCK) &&
|
if ((flags & VIR_EXEC_NONBLOCK) &&
|
||||||
virSetNonBlock(pipeout[0]) == -1) {
|
virSetNonBlock(pipeout[0]) == -1) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("Failed to set non-blocking file descriptor flag"));
|
"%s", _("Failed to set non-blocking file descriptor flag"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSetCloseExec(pipeout[0]) == -1) {
|
if (virSetCloseExec(pipeout[0]) == -1) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("Failed to set close-on-exec file descriptor flag"));
|
"%s", _("Failed to set close-on-exec file descriptor flag"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -259,20 +259,20 @@ __virExec(virConnectPtr conn,
|
|||||||
if (errfd != NULL) {
|
if (errfd != NULL) {
|
||||||
if (*errfd == -1) {
|
if (*errfd == -1) {
|
||||||
if (pipe(pipeerr) < 0) {
|
if (pipe(pipeerr) < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("Failed to create pipe: %s"), strerror(errno));
|
"%s", _("Failed to create pipe"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & VIR_EXEC_NONBLOCK) &&
|
if ((flags & VIR_EXEC_NONBLOCK) &&
|
||||||
virSetNonBlock(pipeerr[0]) == -1) {
|
virSetNonBlock(pipeerr[0]) == -1) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("Failed to set non-blocking file descriptor flag"));
|
"%s", _("Failed to set non-blocking file descriptor flag"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSetCloseExec(pipeerr[0]) == -1) {
|
if (virSetCloseExec(pipeerr[0]) == -1) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"%s", _("Failed to set close-on-exec file descriptor flag"));
|
"%s", _("Failed to set close-on-exec file descriptor flag"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -288,8 +288,8 @@ __virExec(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((pid = fork()) < 0) {
|
if ((pid = fork()) < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot fork child process: %s"), strerror(errno));
|
"%s", _("cannot fork child process"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,9 +307,8 @@ __virExec(virConnectPtr conn,
|
|||||||
/* Restore our original signal mask now child is safely
|
/* Restore our original signal mask now child is safely
|
||||||
running */
|
running */
|
||||||
if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
|
if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot unblock signals: %s"),
|
"%s", _("cannot unblock signals"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,9 +344,8 @@ __virExec(virConnectPtr conn,
|
|||||||
and don't want to propagate that to children */
|
and don't want to propagate that to children */
|
||||||
sigemptyset(&newmask);
|
sigemptyset(&newmask);
|
||||||
if (pthread_sigmask(SIG_SETMASK, &newmask, NULL) != 0) {
|
if (pthread_sigmask(SIG_SETMASK, &newmask, NULL) != 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot unblock signals: %s"),
|
"%s", _("cannot unblock signals"));
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,24 +361,21 @@ __virExec(virConnectPtr conn,
|
|||||||
|
|
||||||
if (flags & VIR_EXEC_DAEMON) {
|
if (flags & VIR_EXEC_DAEMON) {
|
||||||
if (setsid() < 0) {
|
if (setsid() < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot become session leader: %s"),
|
"%s", _("cannot become session leader"));
|
||||||
strerror(errno));
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chdir("/") < 0) {
|
if (chdir("/") < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot change to root directory: %s"),
|
"%s", _("cannot change to root directory: %s"));
|
||||||
strerror(errno));
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot fork child process: %s"),
|
"%s", _("cannot fork child process"));
|
||||||
strerror(errno));
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,20 +385,20 @@ __virExec(virConnectPtr conn,
|
|||||||
|
|
||||||
|
|
||||||
if (dup2(infd >= 0 ? infd : null, STDIN_FILENO) < 0) {
|
if (dup2(infd >= 0 ? infd : null, STDIN_FILENO) < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to setup stdin file handle: %s"), strerror(errno));
|
"%s", _("failed to setup stdin file handle"));
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
if (childout > 0 &&
|
if (childout > 0 &&
|
||||||
dup2(childout, STDOUT_FILENO) < 0) {
|
dup2(childout, STDOUT_FILENO) < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to setup stdout file handle: %s"), strerror(errno));
|
"%s", _("failed to setup stdout file handle"));
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
if (childerr > 0 &&
|
if (childerr > 0 &&
|
||||||
dup2(childerr, STDERR_FILENO) < 0) {
|
dup2(childerr, STDERR_FILENO) < 0) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("failed to setup stderr file handle: %s"), strerror(errno));
|
"%s", _("failed to setup stderr file handle"));
|
||||||
_exit(1);
|
_exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -419,9 +414,9 @@ __virExec(virConnectPtr conn,
|
|||||||
else
|
else
|
||||||
execvp(argv[0], (char **) argv);
|
execvp(argv[0], (char **) argv);
|
||||||
|
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot execute binary '%s': %s"),
|
_("cannot execute binary %s"),
|
||||||
argv[0], strerror(errno));
|
argv[0]);
|
||||||
|
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
|
||||||
@ -535,8 +530,8 @@ virPipeReadUntilEOF(virConnectPtr conn, int outfd, int errfd,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
pollerr:
|
pollerr:
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("poll error: %s"), strerror(errno));
|
"%s", _("poll error"));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,16 +594,15 @@ virRun(virConnectPtr conn,
|
|||||||
while ((waitret = waitpid(childpid, &exitstatus, 0) == -1) &&
|
while ((waitret = waitpid(childpid, &exitstatus, 0) == -1) &&
|
||||||
errno == EINTR);
|
errno == EINTR);
|
||||||
if (waitret == -1) {
|
if (waitret == -1) {
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot wait for '%s': %s"),
|
_("cannot wait for '%s'"),
|
||||||
argv[0], strerror(errno));
|
argv[0]);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == NULL) {
|
if (status == NULL) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
if (WIFEXITED(exitstatus) && WEXITSTATUS(exitstatus) != 0) {
|
if (WIFEXITED(exitstatus) && WEXITSTATUS(exitstatus) != 0) {
|
||||||
|
|
||||||
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
ReportError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("'%s' exited with non-zero status %d and "
|
_("'%s' exited with non-zero status %d and "
|
||||||
"signal %d: %s"), argv_str,
|
"signal %d: %s"), argv_str,
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "threads.h"
|
#include "threads.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
virThreadLocal virLastErr;
|
virThreadLocal virLastErr;
|
||||||
|
|
||||||
@ -983,7 +984,7 @@ virErrorMsg(virErrorNumber error, const char *info)
|
|||||||
void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
|
void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
|
||||||
const char *filename ATTRIBUTE_UNUSED,
|
const char *filename ATTRIBUTE_UNUSED,
|
||||||
const char *funcname ATTRIBUTE_UNUSED,
|
const char *funcname ATTRIBUTE_UNUSED,
|
||||||
long long linenr ATTRIBUTE_UNUSED,
|
size_t linenr ATTRIBUTE_UNUSED,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
@ -1003,3 +1004,67 @@ void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
|
|||||||
virerr, errorMessage, NULL, -1, -1, virerr, errorMessage);
|
virerr, errorMessage, NULL, -1, -1, virerr, errorMessage);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void virReportSystemErrorFull(virConnectPtr conn,
|
||||||
|
int domcode,
|
||||||
|
int theerrno,
|
||||||
|
const char *filename ATTRIBUTE_UNUSED,
|
||||||
|
const char *funcname ATTRIBUTE_UNUSED,
|
||||||
|
size_t linenr ATTRIBUTE_UNUSED,
|
||||||
|
const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
char errorMessage[1024];
|
||||||
|
char systemError[1024];
|
||||||
|
char *theerrnostr;
|
||||||
|
const char *virerr;
|
||||||
|
char *combined = NULL;
|
||||||
|
|
||||||
|
#ifdef HAVE_STRERROR_R
|
||||||
|
#ifdef __USE_GNU
|
||||||
|
/* Annoying linux specific API contract */
|
||||||
|
theerrnostr = strerror_r(theerrno, systemError, sizeof(systemError));
|
||||||
|
#else
|
||||||
|
strerror_r(theerrno, systemError, sizeof(systemError));
|
||||||
|
theerrnostr = systemError;
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
/* Mingw lacks strerror_r() and its strerror() is definitely not
|
||||||
|
* threadsafe, so safest option is to just print the raw errno
|
||||||
|
* value - we can at least reliably & safely look it up in the
|
||||||
|
* header files for debug purposes
|
||||||
|
*/
|
||||||
|
snprintf(systemError, sizeof(systemError), "errno=%d", theerrno);
|
||||||
|
theerrnostr = systemError;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (fmt) {
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(errorMessage, sizeof(errorMessage)-1, fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
} else {
|
||||||
|
errorMessage[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virAsprintf(&combined, "%s: %s", errorMessage, theerrnostr) < 0)
|
||||||
|
combined = theerrnostr; /* OOM, so lets just pass the strerror info as best effort */
|
||||||
|
|
||||||
|
virerr = virErrorMsg(VIR_ERR_SYSTEM_ERROR, (errorMessage[0] ? errorMessage : NULL));
|
||||||
|
virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR,
|
||||||
|
virerr, errorMessage, NULL, -1, -1, virerr, errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void virReportOOMErrorFull(virConnectPtr conn,
|
||||||
|
int domcode,
|
||||||
|
const char *filename ATTRIBUTE_UNUSED,
|
||||||
|
const char *funcname ATTRIBUTE_UNUSED,
|
||||||
|
size_t linenr ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
|
const char *virerr;
|
||||||
|
|
||||||
|
virerr = virErrorMsg(VIR_ERR_NO_MEMORY, NULL);
|
||||||
|
virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR,
|
||||||
|
virerr, NULL, NULL, -1, -1, virerr, NULL);
|
||||||
|
}
|
||||||
|
@ -48,10 +48,36 @@ const char *virErrorMsg(virErrorNumber error, const char *info);
|
|||||||
void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
|
void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode,
|
||||||
const char *filename ATTRIBUTE_UNUSED,
|
const char *filename ATTRIBUTE_UNUSED,
|
||||||
const char *funcname ATTRIBUTE_UNUSED,
|
const char *funcname ATTRIBUTE_UNUSED,
|
||||||
long long linenr ATTRIBUTE_UNUSED,
|
size_t linenr ATTRIBUTE_UNUSED,
|
||||||
const char *fmt, ...)
|
const char *fmt, ...)
|
||||||
ATTRIBUTE_FORMAT(printf, 7, 8);
|
ATTRIBUTE_FORMAT(printf, 7, 8);
|
||||||
|
|
||||||
|
void virReportSystemErrorFull(virConnectPtr conn,
|
||||||
|
int domcode,
|
||||||
|
int theerrno,
|
||||||
|
const char *filename,
|
||||||
|
const char *funcname,
|
||||||
|
size_t linenr,
|
||||||
|
const char *fmt, ...)
|
||||||
|
ATTRIBUTE_FORMAT(printf, 7, 8);
|
||||||
|
|
||||||
|
#define virReportSystemError(conn, theerrno, fmt,...) \
|
||||||
|
virReportSystemErrorFull((conn), \
|
||||||
|
VIR_FROM_THIS, \
|
||||||
|
(theerrno), \
|
||||||
|
__FILE__, __FUNCTION__, __LINE__, \
|
||||||
|
(fmt), __VA_ARGS__)
|
||||||
|
|
||||||
|
void virReportOOMErrorFull(virConnectPtr conn,
|
||||||
|
int domcode,
|
||||||
|
const char *filename,
|
||||||
|
const char *funcname,
|
||||||
|
size_t linenr);
|
||||||
|
|
||||||
|
#define virReportOOMError(conn) \
|
||||||
|
virReportOOMErrorFull((conn), VIR_FROM_THIS, \
|
||||||
|
__FILE__, __FUNCTION__, __LINE__)
|
||||||
|
|
||||||
|
|
||||||
void virSetGlobalError(void);
|
void virSetGlobalError(void);
|
||||||
void virSetConnError(virConnectPtr conn);
|
void virSetConnError(virConnectPtr conn);
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
|
|
||||||
#include "xm_internal.h" /* for xenXMDomainConfigParse */
|
#include "xm_internal.h" /* for xenXMDomainConfigParse */
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_XEN_INOTIFY
|
||||||
|
|
||||||
#define virXenInotifyError(conn, code, fmt...) \
|
#define virXenInotifyError(conn, code, fmt...) \
|
||||||
virReportErrorHelper(NULL, VIR_FROM_XEN_INOTIFY, code, __FILE__, \
|
virReportErrorHelper(NULL, VIR_FROM_XEN_INOTIFY, code, __FILE__, \
|
||||||
__FUNCTION__, __LINE__, fmt)
|
__FUNCTION__, __LINE__, fmt)
|
||||||
@ -391,8 +393,9 @@ xenInotifyOpen(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
/* populate initial list */
|
/* populate initial list */
|
||||||
if (!(dh = opendir(configDir))) {
|
if (!(dh = opendir(configDir))) {
|
||||||
virXenInotifyError (NULL, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(NULL, errno,
|
||||||
"%s", strerror(errno));
|
_("cannot open directory: %s"),
|
||||||
|
configDir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while ((ent = readdir(dh))) {
|
while ((ent = readdir(dh))) {
|
||||||
|
@ -58,6 +58,8 @@
|
|||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_XEN
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* so far there is 2 versions of the structures usable for doing
|
* so far there is 2 versions of the structures usable for doing
|
||||||
* hypervisor calls.
|
* hypervisor calls.
|
||||||
@ -2532,8 +2534,9 @@ xenHypervisorMakeCapabilities(virConnectPtr conn)
|
|||||||
cpuinfo = fopen ("/proc/cpuinfo", "r");
|
cpuinfo = fopen ("/proc/cpuinfo", "r");
|
||||||
if (cpuinfo == NULL) {
|
if (cpuinfo == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
virXenError (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"/proc/cpuinfo: %s", strerror(errno));
|
_("cannot read file %s"),
|
||||||
|
"/proc/cpuinfo");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2542,9 +2545,9 @@ xenHypervisorMakeCapabilities(virConnectPtr conn)
|
|||||||
if (capabilities == NULL) {
|
if (capabilities == NULL) {
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
fclose(cpuinfo);
|
fclose(cpuinfo);
|
||||||
virXenError (conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
"/sys/hypervisor/properties/capabilities: %s",
|
_("cannot read file %s"),
|
||||||
strerror(errno));
|
"/sys/hypervisor/properties/capabilities");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,8 @@
|
|||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_XEN
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info);
|
xenUnifiedNodeGetInfo (virConnectPtr conn, virNodeInfoPtr info);
|
||||||
static int
|
static int
|
||||||
@ -451,7 +453,8 @@ xenUnifiedGetHostname (virConnectPtr conn)
|
|||||||
|
|
||||||
result = virGetHostname();
|
result = virGetHostname();
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
xenUnifiedError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
|
virReportSystemError(conn, errno,
|
||||||
|
"%s", _("cannot lookup hostname"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
/* Caller frees this string. */
|
/* Caller frees this string. */
|
||||||
|
@ -49,6 +49,8 @@
|
|||||||
/* required for cpumap_t */
|
/* required for cpumap_t */
|
||||||
#include <xen/dom0_ops.h>
|
#include <xen/dom0_ops.h>
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_XEND
|
||||||
|
|
||||||
#ifndef PROXY
|
#ifndef PROXY
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4101,14 +4103,13 @@ xenDaemonDomainMigratePrepare (virConnectPtr dconn,
|
|||||||
if (uri_in == NULL) {
|
if (uri_in == NULL) {
|
||||||
r = gethostname (hostname, HOST_NAME_MAX+1);
|
r = gethostname (hostname, HOST_NAME_MAX+1);
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(dconn, errno,
|
||||||
_("gethostname failed: %s"), strerror (errno));
|
_("unable to resolve name %s"), hostname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*uri_out = strdup (hostname);
|
*uri_out = strdup (hostname);
|
||||||
if (*uri_out == NULL) {
|
if (*uri_out == NULL) {
|
||||||
virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
|
virReportOOMError(dconn);
|
||||||
_("failed to strdup hostname: %s"), strerror (errno));
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4742,9 +4743,9 @@ xenDaemonDomainBlockPeek (virDomainPtr domain, const char *path,
|
|||||||
/* The path is correct, now try to open it and get its size. */
|
/* The path is correct, now try to open it and get its size. */
|
||||||
fd = open (path, O_RDONLY);
|
fd = open (path, O_RDONLY);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("failed to open for reading: %s: %s"),
|
_("failed to open for reading: %s"),
|
||||||
path, strerror (errno));
|
path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4754,9 +4755,9 @@ xenDaemonDomainBlockPeek (virDomainPtr domain, const char *path,
|
|||||||
*/
|
*/
|
||||||
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
|
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
|
||||||
saferead (fd, buffer, size) == (ssize_t) -1) {
|
saferead (fd, buffer, size) == (ssize_t) -1) {
|
||||||
virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
|
virReportSystemError(domain->conn, errno,
|
||||||
_("failed to lseek or read from file: %s: %s"),
|
_("failed to lseek or read from file: %s"),
|
||||||
path, strerror (errno));
|
path);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_XENXM
|
||||||
|
|
||||||
#ifdef WITH_RHEL5_API
|
#ifdef WITH_RHEL5_API
|
||||||
#define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU 0
|
#define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU 0
|
||||||
@ -284,7 +285,7 @@ static int xenXMConfigCopyStringInternal(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(*value = strdup(val->str))) {
|
if (!(*value = strdup(val->str))) {
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,8 +414,9 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
|
|||||||
|
|
||||||
/* Get modified time */
|
/* Get modified time */
|
||||||
if ((stat(filename, &st) < 0)) {
|
if ((stat(filename, &st) < 0)) {
|
||||||
xenXMError (conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(conn, errno,
|
||||||
_("cannot stat %s: %s"), filename, strerror(errno));
|
_("cannot stat: %s"),
|
||||||
|
filename);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -449,7 +451,7 @@ xenXMConfigCacheAddFile(virConnectPtr conn, const char *filename)
|
|||||||
} else { /* Completely new entry */
|
} else { /* Completely new entry */
|
||||||
newborn = 1;
|
newborn = 1;
|
||||||
if (VIR_ALLOC(entry) < 0) {
|
if (VIR_ALLOC(entry) < 0) {
|
||||||
xenXMError (conn, VIR_ERR_NO_MEMORY, "%s", strerror(errno));
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memcpy(entry->filename, filename, PATH_MAX);
|
memcpy(entry->filename, filename, PATH_MAX);
|
||||||
@ -503,7 +505,8 @@ int xenXMConfigCacheRefresh (virConnectPtr conn) {
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (now == ((time_t)-1)) {
|
if (now == ((time_t)-1)) {
|
||||||
xenXMError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
|
virReportSystemError(conn, errno,
|
||||||
|
"%s", _("cannot get time of day"));
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +518,9 @@ int xenXMConfigCacheRefresh (virConnectPtr conn) {
|
|||||||
|
|
||||||
/* Process the files in the config dir */
|
/* Process the files in the config dir */
|
||||||
if (!(dh = opendir(configDir))) {
|
if (!(dh = opendir(configDir))) {
|
||||||
xenXMError (conn, VIR_ERR_SYSTEM_ERROR, "%s", strerror(errno));
|
virReportSystemError(conn, errno,
|
||||||
|
_("cannot read directory %s"),
|
||||||
|
configDir);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1297,7 +1302,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
|
|||||||
return def;
|
return def;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainGraphicsDefFree(graphics);
|
virDomainGraphicsDefFree(graphics);
|
||||||
@ -1531,14 +1536,14 @@ int xenXMDomainPinVcpu(virDomainPtr domain,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (virBufferError(&mapbuf)) {
|
if (virBufferError(&mapbuf)) {
|
||||||
xenXMError(domain->conn, VIR_ERR_NO_MEMORY, "%s", _("allocate buffer"));
|
virReportOOMError(domain->conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapstr = virBufferContentAndReset(&mapbuf);
|
mapstr = virBufferContentAndReset(&mapbuf);
|
||||||
|
|
||||||
if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
|
if (VIR_ALLOC_N(cpuset, maxcpu) < 0) {
|
||||||
xenXMError(domain->conn, VIR_ERR_NO_MEMORY, "%s", _("allocate buffer"));
|
virReportOOMError(domain->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (virDomainCpuSetParse(domain->conn,
|
if (virDomainCpuSetParse(domain->conn,
|
||||||
@ -1781,12 +1786,12 @@ static int xenXMDomainConfigFormatDisk(virConnectPtr conn,
|
|||||||
virBufferAddLit(&buf, ",w");
|
virBufferAddLit(&buf, ",w");
|
||||||
|
|
||||||
if (virBufferError(&buf)) {
|
if (virBufferError(&buf)) {
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC(val) < 0) {
|
if (VIR_ALLOC(val) < 0) {
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1853,7 +1858,7 @@ static int xenXMDomainConfigFormatNet(virConnectPtr conn,
|
|||||||
net->model);
|
net->model);
|
||||||
|
|
||||||
if (VIR_ALLOC(val) < 0) {
|
if (VIR_ALLOC(val) < 0) {
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2254,7 +2259,7 @@ virConfPtr xenXMDomainConfigFormat(virConnectPtr conn,
|
|||||||
return conf;
|
return conf;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(conn);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virConfFreeValue(diskVal);
|
virConfFreeValue(diskVal);
|
||||||
@ -2348,7 +2353,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_ALLOC(entry) < 0) {
|
if (VIR_ALLOC(entry) < 0) {
|
||||||
xenXMError(conn, VIR_ERR_NO_MEMORY, "%s", _("config"));
|
virReportOOMError(conn);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2544,7 +2549,7 @@ xenXMDomainAttachDevice(virDomainPtr domain, const char *xml) {
|
|||||||
case VIR_DOMAIN_DEVICE_DISK:
|
case VIR_DOMAIN_DEVICE_DISK:
|
||||||
{
|
{
|
||||||
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
|
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
|
||||||
xenXMError(domain->conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(domain->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
def->disks[def->ndisks++] = dev->data.disk;
|
def->disks[def->ndisks++] = dev->data.disk;
|
||||||
@ -2557,7 +2562,7 @@ xenXMDomainAttachDevice(virDomainPtr domain, const char *xml) {
|
|||||||
case VIR_DOMAIN_DEVICE_NET:
|
case VIR_DOMAIN_DEVICE_NET:
|
||||||
{
|
{
|
||||||
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) {
|
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) {
|
||||||
xenXMError(domain->conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(domain->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
def->nets[def->nnets++] = dev->data.net;
|
def->nets[def->nnets++] = dev->data.net;
|
||||||
@ -2715,15 +2720,15 @@ int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!linkname || !config) {
|
if (!linkname || !config) {
|
||||||
xenXMError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(dom->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
*autostart = virFileLinkPointsTo(linkname, config);
|
*autostart = virFileLinkPointsTo(linkname, config);
|
||||||
if (*autostart < 0) {
|
if (*autostart < 0) {
|
||||||
xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("failed to check autostart link %s: %s"),
|
_("cannot check link %s points to config %s"),
|
||||||
linkname, strerror(errno));
|
linkname, config);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2743,24 +2748,24 @@ int xenXMDomainSetAutostart(virDomainPtr dom, int autostart)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!linkname || !config) {
|
if (!linkname || !config) {
|
||||||
xenXMError(dom->conn, VIR_ERR_NO_MEMORY, NULL);
|
virReportOOMError(dom->conn);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autostart) {
|
if (autostart) {
|
||||||
if (symlink(config, linkname) < 0 &&
|
if (symlink(config, linkname) < 0 &&
|
||||||
errno != EEXIST) {
|
errno != EEXIST) {
|
||||||
xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("failed to create link %s: %s"),
|
_("failed to create link %s to %s"),
|
||||||
linkname, strerror(errno));
|
config, linkname);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (unlink(linkname) < 0 &&
|
if (unlink(linkname) < 0 &&
|
||||||
errno != ENOENT) {
|
errno != ENOENT) {
|
||||||
xenXMError(dom->conn, VIR_ERR_INTERNAL_ERROR,
|
virReportSystemError(dom->conn, errno,
|
||||||
_("failed to remove link %s: %s"),
|
_("failed to remove link %s"),
|
||||||
linkname, strerror(errno));
|
linkname);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user