+ fd = open(operation_path, O_WRONLY);
+
+ if (fd < 0) {
-+ virReportSystemError(conn, errno,
++ virReportSystemError(errno,
+ _("Could not open '%s' for vport operation"),
+ operation_path);
+ retval = -1;
+ towrite = strlen(vport_name);
+ written = safewrite(fd, vport_name, towrite);
+ if (written != towrite) {
-+ virReportSystemError(conn, errno,
++ virReportSystemError(errno,
+ _("Write of '%s' to '%s' during "
+ "vport create/delete failed "
+ "(towrite: %lu written: %d)"),
goto cleanup;
if (virFileMakePath(configDir)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot create config directory '%s'"),
configDir);
goto cleanup;
if ((fd = open(configFile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR )) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot create config file '%s'"),
configFile);
goto cleanup;
towrite = strlen(xml);
if (safewrite(fd, xml, towrite) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot write config file '%s'"),
configFile);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
goto cleanup;
if (!(dir = opendir(configDir))) {
if (errno == ENOENT)
return 0;
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to open dir '%s'"),
configDir);
return -1;
if (unlink(configFile) < 0 &&
errno != ENOENT) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot remove config %s"),
configFile);
goto cleanup;
goto cleanup;
if ((err = virFileMakePath(configDir))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot create config directory '%s'"),
configDir);
goto cleanup;
if ((fd = open(configFile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR )) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot create config file '%s'"),
configFile);
goto cleanup;
towrite = strlen(xml);
if (safewrite(fd, xml, towrite) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot write config file '%s'"),
configFile);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot save config file '%s'"),
configFile);
goto cleanup;
if (!(dir = opendir(configDir))) {
if (errno == ENOENT)
return 0;
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to open dir '%s'"),
configDir);
return -1;
unlink(autostartLink);
if (unlink(configFile) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot remove config file '%s'"),
configFile);
goto error;
if (!(dir = opendir(configDir))) {
if (errno == ENOENT)
return 0;
- virReportSystemError(conn, errno, _("Failed to open dir '%s'"),
+ virReportSystemError(errno, _("Failed to open dir '%s'"),
configDir);
return -1;
}
char path[PATH_MAX];
if ((err = virFileMakePath(driver->configDir))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot create config directory %s"),
driver->configDir);
return -1;
if ((fd = open(pool->configFile,
O_WRONLY | O_CREAT | O_TRUNC,
S_IRUSR | S_IWUSR )) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot create config file %s"),
pool->configFile);
goto cleanup;
towrite = strlen(xml);
if (safewrite(fd, xml, towrite) != towrite) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot write config file %s"),
pool->configFile);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot save config file %s"),
pool->configFile);
goto cleanup;
int open_max, i;
if (setsid() < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("setsid failed"));
goto cleanup;
}
if (ioctl(ttyfd, TIOCSCTTY, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("ioctl(TIOCSTTY) failed"));
goto cleanup;
}
close(i);
if (dup2(ttyfd, 0) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("dup2(stdin) failed"));
goto cleanup;
}
if (dup2(ttyfd, 1) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("dup2(stdout) failed"));
goto cleanup;
}
if (dup2(ttyfd, 2) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("dup2(stderr) failed"));
goto cleanup;
}
writeCount = safewrite(control, &msg, sizeof(msg));
if (writeCount != sizeof(msg)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to send container continue message"));
goto error_out;
}
readLen = saferead(control, &msg, sizeof(msg));
if (readLen != sizeof(msg) ||
msg != LXC_CONTINUE_MSG) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to read the container continue message"));
return -1;
}
/* root->parent must be private, so make / private. */
if (mount("", "/", NULL, MS_PRIVATE|MS_REC, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to make root private"));
goto err;
}
}
if ((rc = virFileMakePath(oldroot)) != 0) {
- virReportSystemError(NULL, rc,
+ virReportSystemError(rc,
_("Failed to create %s"),
oldroot);
goto err;
/* Create a tmpfs root since old and new roots must be
* on separate filesystems */
if (mount("tmprootfs", oldroot, "tmpfs", 0, NULL) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to mount empty tmpfs at %s"),
oldroot);
goto err;
}
if ((rc = virFileMakePath(newroot)) != 0) {
- virReportSystemError(NULL, rc,
+ virReportSystemError(rc,
_("Failed to create %s"),
newroot);
goto err;
/* ... and mount our root onto it */
if (mount(root->src, newroot, NULL, MS_BIND|MS_REC, NULL) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to bind new root %s into tmpfs"),
root->src);
goto err;
/* Now we chroot into the tmpfs, then pivot into the
* root->src bind-mounted onto '/new' */
if (chdir(newroot) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to chroot into %s"), newroot);
goto err;
}
/* The old root directory will live at /.oldroot after
* this and will soon be unmounted completely */
if (pivot_root(".", ".oldroot") < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to pivot root"));
goto err;
}
for (i = 0 ; i < ARRAY_CARDINALITY(mnts) ; i++) {
if (virFileMakePath(mnts[i].dst) != 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to mkdir %s"),
mnts[i].src);
goto cleanup;
}
if (mount(mnts[i].src, mnts[i].dst, mnts[i].type, 0, NULL) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to mount %s on %s"),
mnts[i].type, mnts[i].type);
goto cleanup;
}
if ((rc = virFileMakePath("/dev/pts") != 0)) {
- virReportSystemError(NULL, rc, "%s",
+ virReportSystemError(rc, "%s",
_("Cannot create /dev/pts"));
goto cleanup;
}
VIR_DEBUG("Trying to move %s to %s", devpts, "/dev/pts");
if ((rc = mount(devpts, "/dev/pts", NULL, MS_MOVE, NULL)) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to mount /dev/pts in container"));
goto cleanup;
}
dev_t dev = makedev(devs[i].maj, devs[i].min);
if (mknod(devs[i].path, S_IFCHR, dev) < 0 ||
chmod(devs[i].path, devs[i].mode)) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to make device %s"),
devs[i].path);
return -1;
if (access("/dev/pts/ptmx", W_OK) == 0) {
if (symlink("/dev/pts/ptmx", "/dev/ptmx") < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to create symlink /dev/ptmx to /dev/pts/ptmx"));
return -1;
}
dev_t dev = makedev(LXC_DEV_MAJ_TTY, LXC_DEV_MIN_PTMX);
if (mknod("/dev/ptmx", S_IFCHR, dev) < 0 ||
chmod("/dev/ptmx", 0666)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to make device /dev/ptmx"));
return -1;
}
}
if (virFileMakePath(vmDef->fss[i]->dst) != 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to create %s"),
vmDef->fss[i]->dst);
VIR_FREE(src);
return -1;
}
if (mount(src, vmDef->fss[i]->dst, NULL, MS_BIND, NULL) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to mount %s at %s"),
src, vmDef->fss[i]->dst);
VIR_FREE(src);
char mntbuf[1024];
if (!(procmnt = setmntent("/proc/mounts", "r"))) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to read /proc/mounts"));
return -1;
}
for (i = 0 ; i < nmounts ; i++) {
VIR_DEBUG("Umount %s", mounts[i]);
if (umount(mounts[i]) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to unmount '%s'"),
mounts[i]);
return -1;
int i;
if (mount("", "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to make / slave"));
return -1;
}
NULL,
MS_BIND,
NULL) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to mount %s at %s"),
vmDef->fss[i]->src,
vmDef->fss[i]->dst);
/* mount /proc */
if (mount("lxcproc", "/proc", "proc", 0, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to mount /proc"));
return -1;
}
ttyfd = open(ttyPath, O_RDWR|O_NOCTTY);
if (ttyfd < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to open tty %s"),
ttyPath);
VIR_FREE(ttyPath);
DEBUG("clone() returned, %d", pid);
if (pid < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to run clone container"));
return -1;
}
if (rc == -ENXIO || rc == -ENOENT)
return 0;
- virReportSystemError(NULL, -rc, "%s",
+ virReportSystemError(-rc, "%s",
_("Unable to get cgroup for driver"));
return rc;
}
rc = virCgroupForDomain(driver, def->name, &cgroup, 1);
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("Unable to create cgroup for domain %s"),
def->name);
goto cleanup;
rc = virCgroupSetMemory(cgroup, def->maxmem);
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("Unable to set memory limit for domain %s"),
def->name);
goto cleanup;
rc = virCgroupDenyAllDevices(cgroup);
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("Unable to deny devices for domain %s"),
def->name);
goto cleanup;
dev->major,
dev->minor);
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("Unable to allow device %c:%d:%d for domain %s"),
dev->type, dev->major, dev->minor, def->name);
goto cleanup;
rc = virCgroupAllowDeviceMajor(cgroup, 'c', LXC_DEV_MAJ_PTY);
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("Unable to allow PYT devices for domain %s"),
def->name);
goto cleanup;
rc = virCgroupAddTask(cgroup, getpid());
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("Unable to add task %d to cgroup for domain %s"),
getpid(), def->name);
}
struct sockaddr_un addr;
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("failed to create server socket '%s'"),
sockpath);
goto error;
}
if (bind(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("failed to bind server socket '%s'"),
sockpath);
goto error;
}
if (listen(fd, 30 /* backlog */ ) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("failed to listen server socket %s"),
sockpath);
goto error;
goto cleanup;
}
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("read of fd %d failed"),
readFd);
goto cleanup;
}
if (1 != (safewrite(writeFd, buf, 1))) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("write to fd %d failed"),
writeFd);
goto cleanup;
/* create the epoll fild descriptor */
epollFd = epoll_create(2);
if (0 > epollFd) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_create(2) failed"));
goto cleanup;
}
epollEvent.events = EPOLLIN|EPOLLET; /* edge triggered */
epollEvent.data.fd = appPty;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, appPty, &epollEvent)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_ctl(appPty) failed"));
goto cleanup;
}
epollEvent.data.fd = contPty;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, contPty, &epollEvent)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_ctl(contPty) failed"));
goto cleanup;
}
epollEvent.events = EPOLLIN;
epollEvent.data.fd = monitor;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, monitor, &epollEvent)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_ctl(monitor) failed"));
goto cleanup;
}
epollEvent.events = EPOLLHUP;
epollEvent.data.fd = client;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_ctl(client) failed"));
goto cleanup;
}
epollEvent.events = EPOLLHUP;
epollEvent.data.fd = client;
if (0 > epoll_ctl(epollFd, EPOLL_CTL_ADD, client, &epollEvent)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_ctl(client) failed"));
goto cleanup;
}
} else if (client != -1 && epollEvent.data.fd == client) {
if (0 > epoll_ctl(epollFd, EPOLL_CTL_DEL, client, &epollEvent)) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_ctl(client) failed"));
goto cleanup;
}
}
/* error */
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("epoll_wait() failed"));
goto cleanup;
char *devptmx = NULL;
if (socketpair(PF_UNIX, SOCK_STREAM, 0, control) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("sockpair failed"));
goto cleanup;
}
if (root) {
VIR_DEBUG0("Setting up private /dev/pts");
if (unshare(CLONE_NEWNS) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Cannot unshare mount namespace"));
goto cleanup;
}
if (mount("", "/", NULL, MS_SLAVE|MS_REC, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to switch root mount into slave mode"));
goto cleanup;
}
}
if (virFileMakePath(devpts) != 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to make path %s"),
devpts);
goto cleanup;
VIR_DEBUG("Mouting 'devpts' on %s", devpts);
if (mount("devpts", devpts, "devpts", 0, "newinstance,ptmxmode=0666") < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to mount devpts on %s"),
devpts);
goto cleanup;
&containerPty,
&containerPtyPath,
0) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to allocate tty"));
goto cleanup;
}
if (virFileOpenTty(&containerPty,
&containerPtyPath,
0) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to allocate tty"));
goto cleanup;
}
if (pid > 0) {
if ((rc = virFileWritePid(LXC_STATE_DIR, name, pid)) != 0) {
- virReportSystemError(NULL, rc,
+ virReportSystemError(rc,
_("Unable to write pid file '%s/%s.pid'"),
LXC_STATE_DIR, name);
_exit(1);
/* Don't hold onto any cwd we inherit from libvirtd either */
if (chdir("/") < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to change to root dir"));
goto cleanup;
}
if (setsid() < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to become session leader"));
goto cleanup;
}
/* Accept initial client which is the libvirtd daemon */
if ((client = accept(monitor, NULL, 0)) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to accept a connection from driver"));
goto cleanup;
}
; /* empty */
if ((waitRc != vm->pid) && (errno != ECHILD)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("waitpid failed to wait for container %d: %d"),
vm->pid, waitRc);
}
char macaddr[VIR_MAC_STRING_BUFLEN];
virFormatMacAddr(def->nets[i]->mac, macaddr);
if (0 != (rc = setMacAddr(containerVeth, macaddr))) {
- virReportSystemError(conn, rc,
+ virReportSystemError(rc,
_("Failed to set %s to %s"),
macaddr, containerVeth);
goto error_exit;
}
if (0 != (rc = brAddInterface(brctl, bridge, parentVeth))) {
- virReportSystemError(conn, rc,
+ virReportSystemError(rc,
_("Failed to add %s device to %s"),
parentVeth, bridge);
goto error_exit;
}
if (0 != (rc = vethInterfaceUpOrDown(parentVeth, 1))) {
- virReportSystemError(conn, rc,
+ virReportSystemError(rc,
_("Failed to enable %s device"),
parentVeth);
goto error_exit;
}
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to create client socket"));
goto error;
}
}
if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to connect to client socket"));
goto error;
}
if (kill(vm->pid, signum) < 0) {
if (errno != ESRCH) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to kill pid %d"),
vm->pid);
return -1;
*/
while ((rc = waitpid(child, &status, 0) == -1) && errno == EINTR);
if (rc == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Cannot wait for '%s'"),
largv[0]);
goto cleanup;
lxcDomainObjPrivatePtr priv = vm->privateData;
if ((r = virFileMakePath(driver->logDir)) != 0) {
- virReportSystemError(conn, r,
+ virReportSystemError(r,
_("Cannot create log directory '%s'"),
driver->logDir);
return -1;
/* open parent tty */
if (virFileOpenTty(&parentTty, &parentTtyPath, 1) < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Failed to allocate tty"));
goto cleanup;
}
if ((logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT,
S_IRUSR|S_IWUSR)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to open '%s'"),
logfile);
goto cleanup;
/* And get its pid */
if ((r = virFileReadPid(driver->stateDir, vm->def->name, &vm->pid)) != 0) {
- virReportSystemError(conn, r,
+ virReportSystemError(r,
_("Failed to read pid file %s/%s.pid"),
driver->stateDir, vm->def->name);
goto cleanup;
int err;
if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(dom->conn, err,
+ virReportSystemError(err,
_("Cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
}
if (symlink(configFile, autostartLink) < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Failed to create symlink '%s to '%s'"),
autostartLink, configFile);
goto cleanup;
}
} else {
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Failed to delete symlink '%s'"),
autostartLink);
goto cleanup;
VIR_FREE(base);
if ((err = brInit(&driverState->brctl))) {
- virReportSystemError(NULL, err, "%s",
+ virReportSystemError(err, "%s",
_("cannot initialize bridge support"));
goto error;
}
}
if ((err = virFileMakePath(NETWORK_PID_DIR)) != 0) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot create directory %s"),
NETWORK_PID_DIR);
return -1;
}
if ((err = virFileMakePath(NETWORK_STATE_DIR)) != 0) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot create directory %s"),
NETWORK_STATE_DIR);
return -1;
}
static int
-networkAddMasqueradingIptablesRules(virConnectPtr conn,
- struct network_driver *driver,
- virNetworkObjPtr network) {
+networkAddMasqueradingIptablesRules(struct network_driver *driver,
+ virNetworkObjPtr network) {
int err;
/* allow forwarding packets from the bridge interface */
if ((err = iptablesAddForwardAllowOut(driver->iptables,
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow forwarding from '%s'"),
network->def->bridge);
goto masqerr1;
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow forwarding to '%s'"),
network->def->bridge);
goto masqerr2;
if ((err = iptablesAddForwardMasquerade(driver->iptables,
network->def->network,
network->def->forwardDev))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to enable masquerading to '%s'\n"),
network->def->forwardDev ? network->def->forwardDev : NULL);
goto masqerr3;
}
static int
-networkAddRoutingIptablesRules(virConnectPtr conn,
- struct network_driver *driver,
- virNetworkObjPtr network) {
+networkAddRoutingIptablesRules(struct network_driver *driver,
+ virNetworkObjPtr network) {
int err;
/* allow routing packets from the bridge interface */
if ((err = iptablesAddForwardAllowOut(driver->iptables,
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow routing from '%s'"),
network->def->bridge);
goto routeerr1;
network->def->network,
network->def->bridge,
network->def->forwardDev))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow routing to '%s'"),
network->def->bridge);
goto routeerr2;
}
static int
-networkAddIptablesRules(virConnectPtr conn,
- struct network_driver *driver,
- virNetworkObjPtr network) {
+networkAddIptablesRules(struct network_driver *driver,
+ virNetworkObjPtr network) {
int err;
/* allow DHCP requests through to dnsmasq */
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 67))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow DHCP requests from '%s'"),
network->def->bridge);
goto err1;
}
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 67))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow DHCP requests from '%s'"),
network->def->bridge);
goto err2;
/* allow DNS requests through to dnsmasq */
if ((err = iptablesAddTcpInput(driver->iptables, network->def->bridge, 53))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow DNS requests from '%s'"),
network->def->bridge);
goto err3;
}
if ((err = iptablesAddUdpInput(driver->iptables, network->def->bridge, 53))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow DNS requests from '%s'"),
network->def->bridge);
goto err4;
/* Catch all rules to block forwarding to/from bridges */
if ((err = iptablesAddForwardRejectOut(driver->iptables, network->def->bridge))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to block outbound traffic from '%s'"),
network->def->bridge);
goto err5;
}
if ((err = iptablesAddForwardRejectIn(driver->iptables, network->def->bridge))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to block inbound traffic to '%s'"),
network->def->bridge);
goto err6;
/* Allow traffic between guests on the same bridge */
if ((err = iptablesAddForwardAllowCross(driver->iptables, network->def->bridge))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add iptables rule to allow cross bridge traffic on '%s'"),
network->def->bridge);
goto err7;
/* If masquerading is enabled, set up the rules*/
if (network->def->forwardType == VIR_NETWORK_FORWARD_NAT &&
- !networkAddMasqueradingIptablesRules(conn, driver, network))
+ !networkAddMasqueradingIptablesRules(driver, network))
goto err8;
/* else if routing is enabled, set up the rules*/
else if (network->def->forwardType == VIR_NETWORK_FORWARD_ROUTE &&
- !networkAddRoutingIptablesRules(conn, driver, network))
+ !networkAddRoutingIptablesRules(driver, network))
goto err8;
return 1;
if (virNetworkObjIsActive(driver->networks.objs[i])) {
networkRemoveIptablesRules(driver, driver->networks.objs[i]);
- if (!networkAddIptablesRules(NULL, driver, driver->networks.objs[i])) {
+ if (!networkAddIptablesRules(driver, driver->networks.objs[i])) {
/* failed to add but already logged */
}
}
#define SYSCTL_PATH "/proc/sys"
-static int networkDisableIPV6(virConnectPtr conn,
- virNetworkObjPtr network)
+static int networkDisableIPV6(virNetworkObjPtr network)
{
char *field = NULL;
int ret = -1;
}
if (virFileWriteStr(field, "1") < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot enable %s"), field);
goto cleanup;
}
}
if (virFileWriteStr(field, "0") < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot disable %s"), field);
goto cleanup;
}
}
if (virFileWriteStr(field, "1") < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot enable %s"), field);
goto cleanup;
}
}
if ((err = brAddBridge(driver->brctl, network->def->bridge))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot create bridge '%s'"),
network->def->bridge);
return -1;
}
- if (networkDisableIPV6(conn, network) < 0)
+ if (networkDisableIPV6(network) < 0)
goto err_delbr;
if (brSetForwardDelay(driver->brctl, network->def->bridge, network->def->delay) < 0)
if (network->def->ipAddress &&
(err = brSetInetAddress(driver->brctl, network->def->bridge, network->def->ipAddress))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot set IP address on bridge '%s' to '%s'"),
network->def->bridge, network->def->ipAddress);
goto err_delbr;
if (network->def->netmask &&
(err = brSetInetNetmask(driver->brctl, network->def->bridge, network->def->netmask))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot set netmask on bridge '%s' to '%s'"),
network->def->bridge, network->def->netmask);
goto err_delbr;
}
if ((err = brSetInterfaceUp(driver->brctl, network->def->bridge, 1))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to bring the bridge '%s' up"),
network->def->bridge);
goto err_delbr;
}
- if (!networkAddIptablesRules(conn, driver, network))
+ if (!networkAddIptablesRules(driver, network))
goto err_delbr1;
if (network->def->forwardType != VIR_NETWORK_FORWARD_NONE &&
networkEnableIpForwarding() < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("failed to enable IP forwarding"));
goto err_delbr2;
}
if (autostart) {
if (virFileMakePath(driver->networkAutostartDir)) {
- virReportSystemError(net->conn, errno,
+ virReportSystemError(errno,
_("cannot create autostart directory '%s'"),
driver->networkAutostartDir);
goto cleanup;
}
if (symlink(configFile, autostartLink) < 0) {
- virReportSystemError(net->conn, errno,
+ virReportSystemError(errno,
_("Failed to create symlink '%s' to '%s'"),
autostartLink, configFile);
goto cleanup;
}
} else {
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
- virReportSystemError(net->conn, errno,
+ virReportSystemError(errno,
_("Failed to delete symlink '%s'"),
autostartLink);
goto cleanup;
/* Under libudev changes to the driver name should be picked up as
* "change" events, so we don't call update driver name unless we're
* using the HAL backend. */
-static int update_driver_name(virConnectPtr conn,
- virNodeDeviceObjPtr dev)
+static int update_driver_name(virNodeDeviceObjPtr dev)
{
char *driver_link = NULL;
char *devpath = NULL;
}
if (virFileResolveLink(driver_link, &devpath) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot resolve driver link %s"), driver_link);
goto cleanup;
}
}
#else
/* XXX: Implement me for non-linux */
-static int update_driver_name(virConnectPtr conn ATTRIBUTE_UNUSED,
- virNodeDeviceObjPtr dev ATTRIBUTE_UNUSED)
+static int update_driver_name(virNodeDeviceObjPtr dev ATTRIBUTE_UNUSED)
{
return 0;
}
goto cleanup;
}
- update_driver_name(dev->conn, obj);
+ update_driver_name(obj);
update_caps(obj);
ret = virNodeDeviceDefFormat(dev->conn, obj->def);
}
if (virFileWriteStr(operation_path, vport_name) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Write of '%s' to '%s' during "
"vport create/delete failed"),
vport_name, operation_path);
int ret;
FILE *cpuinfo = fopen(CPUINFO_PATH, "r");
if (!cpuinfo) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open %s"), CPUINFO_PATH);
return -1;
}
/* Set forward policy to DROP */
if ((err = ebtablesAddForwardPolicyReject(driver->ebtables))) {
- virReportSystemError(NULL, err,
+ virReportSystemError(err,
_("failed to add ebtables rule to set default policy to drop on '%s'"),
__FILE__);
return err;
/* add default rules */
if ((err = networkAddEbtablesRules(driver))) {
- virReportSystemError(NULL, err,
+ virReportSystemError(err,
_("cannot filter mac addresses on bridge '%s'"),
__FILE__);
return err;
}
int
-networkAllowMacOnPort(virConnectPtr conn,
- struct qemud_driver *driver,
+networkAllowMacOnPort(struct qemud_driver *driver,
const char * ifname,
const unsigned char * mac) {
if ((err = ebtablesAddForwardAllowIn(ebtablescontext,
ifname,
mac))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add ebtables rule to allow routing to '%s'"),
ifname);
}
int
-networkDisallowMacOnPort(virConnectPtr conn,
- struct qemud_driver *driver,
+networkDisallowMacOnPort(struct qemud_driver *driver,
const char * ifname,
const unsigned char * mac) {
if ((err = ebtablesRemoveForwardAllowIn(ebtablescontext,
ifname,
mac))) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("failed to add ebtables rule to allow routing to '%s'"),
ifname);
}
#define __QEMUD_BRIDGE_FILTER_H__
-int networkAllowMacOnPort(virConnectPtr conn,
- struct qemud_driver *driver,
- const char * ifname,
- const unsigned char * mac);
-int networkDisallowMacOnPort(virConnectPtr conn,
- struct qemud_driver *driver,
+int networkAllowMacOnPort(struct qemud_driver *driver,
+ const char * ifname,
+ const unsigned char * mac);
+int networkDisallowMacOnPort(struct qemud_driver *driver,
const char * ifname,
const unsigned char * mac);
int networkDisableAllFrames(struct qemud_driver *driver);
if (driver->privileged &&
!(driver->hugetlbfs_mount = virFileFindMountPoint("hugetlbfs"))) {
if (errno != ENOENT) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("unable to find hugetlbfs mountpoint"));
return -1;
}
driver->macFilter = p->l;
if (!(driver->ebtables = ebtablesContextNew("qemu"))) {
driver->macFilter = 0;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("failed to enable mac filter in in '%s'"),
__FILE__);
}
if ((errno = networkDisableAllFrames(driver))) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("failed to add rule to drop all frames in '%s'"),
__FILE__);
}
len = virFileReadLimFD(newstdout, MAX_MACHINES_OUTPUT_SIZE, &output);
if (len < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to read 'qemu -M ?' output"));
goto cleanup;
}
len = virFileReadLimFD(newstdout, MAX_MACHINES_OUTPUT_SIZE, &output);
if (len < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to read QEMU supported CPU models"));
goto cleanup;
}
enum { MAX_HELP_OUTPUT_SIZE = 1024*64 };
int len = virFileReadLimFD(newstdout, MAX_HELP_OUTPUT_SIZE, &help);
if (len < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to read QEMU help output"));
goto cleanup2;
}
ut->machine[1] = '6';
}
-int qemudExtractVersion(virConnectPtr conn,
- struct qemud_driver *driver) {
+int qemudExtractVersion(struct qemud_driver *driver) {
const char *binary;
struct stat sb;
struct utsname ut;
return -1;
if (stat(binary, &sb) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Cannot find QEMU binary %s"), binary);
return -1;
}
}
if (!driver->brctl && (err = brInit(&driver->brctl))) {
- virReportSystemError(conn, err, "%s",
+ virReportSystemError(err, "%s",
_("cannot initialize bridge support"));
goto cleanup;
}
_("Failed to add tap interface to bridge. "
"%s is not a bridge device"), brname);
} else if (template_ifname) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("Failed to add tap interface to bridge '%s'"),
brname);
} else {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("Failed to add tap interface '%s' to bridge '%s'"),
net->ifname, brname);
}
}
if (driver->macFilter) {
- if ((err = networkAllowMacOnPort(conn, driver, net->ifname, net->mac))) {
- virReportSystemError(conn, err,
+ if ((err = networkAllowMacOnPort(driver, net->ifname, net->mac))) {
+ virReportSystemError(err,
_("failed to add ebtables rule to allow MAC address on '%s'"),
net->ifname);
}
virCapsPtr qemudCapsInit (virCapsPtr old_caps);
-int qemudExtractVersion (virConnectPtr conn,
- struct qemud_driver *driver);
+int qemudExtractVersion (struct qemud_driver *driver);
int qemudExtractVersionInfo (const char *qemu,
unsigned int *version,
unsigned int *flags);
unsigned long long then;
if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("cannot get time of day"));
return -1;
}
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_TIMEOUT,
"%s", _("cannot acquire state change lock"));
else
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
"%s", _("cannot acquire job mutex"));
return -1;
}
unsigned long long then;
if (gettimeofday(&now, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("cannot get time of day"));
return -1;
}
qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_TIMEOUT,
"%s", _("cannot acquire state change lock"));
else
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
"%s", _("cannot acquire job mutex"));
qemuDriverLock(driver);
return -1;
}
static int
-qemudLogFD(virConnectPtr conn, struct qemud_driver *driver, const char* name)
+qemudLogFD(struct qemud_driver *driver, const char* name)
{
char logfile[PATH_MAX];
mode_t logmode;
logmode |= O_TRUNC;
if ((fd = open(logfile, logmode, S_IRUSR | S_IWUSR)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to create logfile %s"),
logfile);
return -1;
}
if (virSetCloseExec(fd) < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
close(fd);
return -1;
if ((fd = open(logfile, logmode)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to create logfile %s"),
logfile);
return -1;
}
if (virSetCloseExec(fd) < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("Unable to set VM logfile close-on-exec flag"));
close(fd);
return -1;
}
if (pos < 0 || lseek(fd, pos, SEEK_SET) < 0) {
- virReportSystemError(conn, pos < 0 ? 0 : errno,
+ virReportSystemError(pos < 0 ? 0 : errno,
_("Unable to seek to %lld in %s"),
(long long) pos, logfile);
close(fd);
if (privileged) {
if (chown(qemu_driver->libDir, qemu_driver->user, qemu_driver->group) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("unable to set ownership of '%s' to user %d:%d"),
qemu_driver->libDir, qemu_driver->user, qemu_driver->group);
goto error;
}
if (chown(qemu_driver->cacheDir, qemu_driver->user, qemu_driver->group) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("unable to set ownership of '%s' to %d:%d"),
qemu_driver->cacheDir, qemu_driver->user, qemu_driver->group);
goto error;
goto out_of_memory;
if ((rc = virFileMakePath(mempath)) != 0) {
- virReportSystemError(NULL, rc,
+ virReportSystemError(rc,
_("unable to create hugepage path %s"), mempath);
VIR_FREE(mempath);
goto error;
}
if (qemu_driver->privileged &&
chown(mempath, qemu_driver->user, qemu_driver->group) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("unable to set ownership on %s to %d:%d"),
mempath, qemu_driver->user, qemu_driver->group);
VIR_FREE(mempath);
* always have something useful to report on failure. */
ret = saferead(fd, buf+got, buflen-got-1);
if (ret < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failure while reading %s log output"),
what);
return -1;
#define DEVICE_PTY_MAJOR 136
#define DEVICE_SND_MAJOR 116
-static int qemuSetupCgroup(virConnectPtr conn,
- struct qemud_driver *driver,
+static int qemuSetupCgroup(struct qemud_driver *driver,
virDomainObjPtr vm)
{
virCgroupPtr cgroup = NULL;
rc = virCgroupForDomain(driver->cgroup, vm->def->name, &cgroup, 1);
if (rc != 0) {
- virReportSystemError(conn, -rc,
+ virReportSystemError(-rc,
_("Unable to create cgroup for %s"),
vm->def->name);
goto cleanup;
goto done;
}
- virReportSystemError(conn, -rc,
+ virReportSystemError(-rc,
_("Unable to deny all devices for %s"), vm->def->name);
goto cleanup;
}
rc = virCgroupAllowDevicePath(cgroup,
vm->def->disks[i]->src);
if (rc != 0) {
- virReportSystemError(conn, -rc,
+ virReportSystemError(-rc,
_("Unable to allow device %s for %s"),
vm->def->disks[i]->src, vm->def->name);
goto cleanup;
rc = virCgroupAllowDeviceMajor(cgroup, 'c', DEVICE_PTY_MAJOR);
if (rc != 0) {
- virReportSystemError(conn, -rc, "%s",
+ virReportSystemError(-rc, "%s",
_("unable to allow /dev/pts/ devices"));
goto cleanup;
}
if (vm->def->nsounds) {
rc = virCgroupAllowDeviceMajor(cgroup, 'c', DEVICE_SND_MAJOR);
if (rc != 0) {
- virReportSystemError(conn, -rc, "%s",
+ virReportSystemError(-rc, "%s",
_("unable to allow /dev/snd/ devices"));
goto cleanup;
}
deviceACL[i]);
if (rc < 0 &&
rc != -ENOENT) {
- virReportSystemError(conn, -rc,
+ virReportSystemError(-rc,
_("unable to allow device %s"),
deviceACL[i]);
goto cleanup;
rc = virCgroupForDomain(driver->cgroup, def->name, &cgroup, 0);
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("unable to find cgroup for domain %s"),
def->name);
goto cleanup;
rc = virCgroupAddTask(cgroup, getpid());
if (rc != 0) {
- virReportSystemError(NULL, -rc,
+ virReportSystemError(-rc,
_("unable to add domain %s task %d to cgroup"),
def->name, getpid());
goto cleanup;
}
if (virFileMakePath(driver->logDir) != 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot create log directory %s"),
driver->logDir);
goto cleanup;
}
- if ((logfile = qemudLogFD(conn, driver, vm->def->name)) < 0)
+ if ((logfile = qemudLogFD(driver, vm->def->name)) < 0)
goto cleanup;
emulator = vm->def->emulator;
* in a sub-process so its hard to feed back a useful error
*/
if (stat(emulator, &sb) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Cannot find QEMU binary %s"),
emulator);
goto cleanup;
&qemuCmdFlags) < 0)
goto cleanup;
- if (qemuSetupCgroup(conn, driver, vm) < 0)
+ if (qemuSetupCgroup(driver, vm) < 0)
goto cleanup;
if (qemuPrepareHostDevices(conn, driver, vm->def) < 0)
priv->monJSON = 0;
if ((ret = virFileDeletePid(driver->stateDir, vm->def->name)) != 0) {
- virReportSystemError(conn, ret,
+ virReportSystemError(ret,
_("Cannot remove stale PID file for %s"),
vm->def->name);
goto cleanup;
}
if (!(pidfile = virFilePid(driver->stateDir, vm->def->name))) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("Failed to build pidfile path."));
goto cleanup;
}
virDomainNetDefPtr net = def->nets[i];
if (net->ifname == NULL)
continue;
- if ((errno = networkDisallowMacOnPort(conn, driver, net->ifname,
+ if ((errno = networkDisallowMacOnPort(driver, net->ifname,
net->mac))) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to remove ebtables rule to allow MAC address on '%s'"),
net->ifname);
}
if (virKillProcess(vm->pid, 0) == 0 &&
virKillProcess(vm->pid, SIGTERM) < 0)
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to send SIGTERM to %s (%d)"),
vm->def->name, vm->pid);
fd = open(KVM_DEVICE, O_RDONLY);
if (fd < 0) {
- virReportSystemError(NULL, errno, _("Unable to open %s"), KVM_DEVICE);
+ virReportSystemError(errno, _("Unable to open %s"), KVM_DEVICE);
return -1;
}
int ret = -1;
qemuDriverLock(driver);
- if (qemudExtractVersion(conn, driver) < 0)
+ if (qemudExtractVersion(driver) < 0)
goto cleanup;
*version = qemu_driver->qemuVersion;
}
if (close(fd) < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("unable to save file %s"),
path);
goto endjob;
}
if (close(fd) < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("unable to save file %s"),
path);
goto endjob;
&(info[i].cpu),
vm->pid,
priv->vcpupids[i]) < 0) {
- virReportSystemError(dom->conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("cannot get vCPU placement & pCPU time"));
goto cleanup;
}
* in a sub-process so its hard to feed back a useful error
*/
if (stat(emulator, &sb) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Cannot find QEMU binary %s"),
emulator);
goto cleanup;
qemuDomainObjExitMonitorWithDriver(driver, vm);
if ((driver->macFilter) && (detach->ifname != NULL)) {
- if ((errno = networkDisallowMacOnPort(conn,
- driver,
+ if ((errno = networkDisallowMacOnPort(driver,
detach->ifname,
detach->mac))) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to remove ebtables rule on '%s'"),
detach->ifname);
}
int err;
if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(dom->conn, err,
+ virReportSystemError(err,
_("cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
}
if (symlink(configFile, autostartLink) < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Failed to create symlink '%s to '%s'"),
autostartLink, configFile);
goto cleanup;
}
} else {
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Failed to delete symlink '%s'"),
autostartLink);
goto cleanup;
rc = virCgroupSetCpuShares(group, params[i].value.ul);
if (rc != 0) {
- virReportSystemError(dom->conn, -rc, "%s",
+ virReportSystemError(-rc, "%s",
_("unable to set cpu shares tunable"));
goto cleanup;
}
rc = virCgroupGetCpuShares(group, &val);
if (rc != 0) {
- virReportSystemError(dom->conn, -rc, "%s",
+ virReportSystemError(-rc, "%s",
_("unable to get cpu shares tunable"));
goto cleanup;
}
/* The path is correct, now try to open it and get its size. */
fd = open (path, O_RDONLY);
if (fd == -1) {
- virReportSystemError (dom->conn, errno,
- _("%s: failed to open"), path);
+ virReportSystemError(errno,
+ _("%s: failed to open"), path);
goto cleanup;
}
*/
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
saferead (fd, buffer, size) == (ssize_t) -1) {
- virReportSystemError (dom->conn, errno,
- _("%s: failed to seek or read"), path);
+ virReportSystemError(errno,
+ _("%s: failed to seek or read"), path);
goto cleanup;
}
/* Create a temporary filename. */
if ((fd = mkstemp (tmp)) == -1) {
- virReportSystemError (dom->conn, errno,
- _("mkstemp(\"%s\") failed"), tmp);
+ virReportSystemError(errno,
+ _("mkstemp(\"%s\") failed"), tmp);
goto endjob;
}
/* Read the memory file into buffer. */
if (saferead (fd, buffer, size) == (ssize_t) -1) {
- virReportSystemError (dom->conn, errno,
- _("failed to read temporary file "
- "created with template %s"), tmp);
+ virReportSystemError(errno,
+ _("failed to read temporary file "
+ "created with template %s"), tmp);
goto endjob;
}
goto retry;
} else {
ret = -1;
- virReportSystemError(st->conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("cannot write to stream"));
}
}
virDomainRemoveInactive(&driver->domains, vm);
vm = NULL;
}
- virReportSystemError(dconn, errno,
+ virReportSystemError(errno,
_("cannot open unix socket '%s' for tunnelled migration"),
unixfile);
goto endjob;
nbytes = saferead(sock, buffer, nbytes);
if (nbytes < 0) {
virStreamAbort(st);
- virReportSystemError(dom->conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("tunnelled migration failed to read from qemu"));
return -1;
}
qemu_sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (qemu_sock < 0) {
- virReportSystemError(dom->conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("cannot open tunnelled migration socket"));
goto cleanup;
}
}
unlink(unixfile);
if (bind(qemu_sock, (struct sockaddr *)&sa_qemu, sizeof(sa_qemu)) < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Cannot bind to unix socket '%s' for tunnelled migration"),
unixfile);
goto cleanup;
}
if (listen(qemu_sock, 1) < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Cannot listen on unix socket '%s' for tunnelled migration"),
unixfile);
goto cleanup;
while ((client_sock = accept(qemu_sock, (struct sockaddr *)&sa_client, &addrlen)) < 0) {
if (errno == EAGAIN || errno == EINTR)
continue;
- virReportSystemError(dom->conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("tunnelled migration failed to accept from qemu"));
goto cancel;
}
int ret, i = 0;
if ((monfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
"%s", _("failed to create socket"));
return -1;
}
continue;
}
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("failed to connect to monitor socket"));
goto error;
} while ((++i <= timeout*5) && (usleep(.2 * 1000000) <= 0));
if (ret != 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("monitor socket did not show up."));
goto error;
}
}
if (ret < 0)
- virReportSystemError(NULL, msg.lastErrno,
+ virReportSystemError(msg.lastErrno,
_("cannot send monitor command '%s'"), cmdstr);
cleanup:
virJSONValuePtr timestamp = NULL;
if (gettimeofday(&tv, NULL) < 0) {
- virReportSystemError(NULL, errno, "%s",
+ virReportSystemError(errno, "%s",
_("cannot query time of day"));
return -1;
}
}
if (ret < 0) {
- virReportSystemError(NULL, msg.lastErrno,
+ virReportSystemError(msg.lastErrno,
_("cannot send monitor command '%s'"), cmd);
VIR_FREE(*reply);
}
static int
-qemuSecurityDACSetOwnership(virConnectPtr conn, const char *path, int uid, int gid)
+qemuSecurityDACSetOwnership(const char *path, int uid, int gid)
{
VIR_INFO("Setting DAC context on '%s' to '%d:%d'", path, uid, gid);
VIR_INFO("Setting security context '%d:%d' on '%s' not possible on readonly filesystem",
uid, gid, path);
} else {
- virReportSystemError(conn, chown_errno,
+ virReportSystemError(chown_errno,
_("unable to set security context '%d:%d' on '%s'"),
uid, gid, path);
return -1;
}
static int
-qemuSecurityDACRestoreSecurityFileLabel(virConnectPtr conn,
- const char *path)
+qemuSecurityDACRestoreSecurityFileLabel(const char *path)
{
struct stat buf;
int rc = -1;
VIR_INFO("Restoring DAC context on '%s'", path);
if ((err = virFileResolveLink(path, &newpath)) < 0) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot resolve symlink %s"), path);
goto err;
}
goto err;
/* XXX record previous ownership */
- rc = qemuSecurityDACSetOwnership(conn, newpath, 0, 0);
+ rc = qemuSecurityDACSetOwnership(newpath, 0, 0);
err:
VIR_FREE(newpath);
return -1;
if (meta.backingStore != NULL &&
- qemuSecurityDACSetOwnership(conn, meta.backingStore,
- driver->user, driver->group) < 0) {
+ qemuSecurityDACSetOwnership(meta.backingStore,
+ driver->user, driver->group) < 0) {
VIR_FREE(meta.backingStore);
return -1;
}
path = meta.backingStore;
} while (path != NULL);
- return qemuSecurityDACSetOwnership(conn, disk->src, driver->user, driver->group);
+ return qemuSecurityDACSetOwnership(disk->src, driver->user, driver->group);
}
static int
-qemuSecurityDACRestoreSecurityImageLabel(virConnectPtr conn,
+qemuSecurityDACRestoreSecurityImageLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainObjPtr vm ATTRIBUTE_UNUSED,
virDomainDiskDefPtr disk)
{
if (!disk->src)
return 0;
- return qemuSecurityDACRestoreSecurityFileLabel(conn, disk->src);
+ return qemuSecurityDACRestoreSecurityFileLabel(disk->src);
}
static int
-qemuSecurityDACSetSecurityPCILabel(virConnectPtr conn,
+qemuSecurityDACSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED,
pciDevice *dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
- return qemuSecurityDACSetOwnership(conn, file, driver->user, driver->group);
+ return qemuSecurityDACSetOwnership(file, driver->user, driver->group);
}
static int
-qemuSecurityDACSetSecurityUSBLabel(virConnectPtr conn,
+qemuSecurityDACSetSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
usbDevice *dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
- return qemuSecurityDACSetOwnership(conn, file, driver->user, driver->group);
+ return qemuSecurityDACSetOwnership(file, driver->user, driver->group);
}
static int
-qemuSecurityDACRestoreSecurityPCILabel(virConnectPtr conn,
+qemuSecurityDACRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED,
pciDevice *dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
- return qemuSecurityDACRestoreSecurityFileLabel(conn, file);
+ return qemuSecurityDACRestoreSecurityFileLabel(file);
}
static int
-qemuSecurityDACRestoreSecurityUSBLabel(virConnectPtr conn,
+qemuSecurityDACRestoreSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
usbDevice *dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
- return qemuSecurityDACRestoreSecurityFileLabel(conn, file);
+ return qemuSecurityDACRestoreSecurityFileLabel(file);
}
static int
-qemuSecurityDACSetSavedStateLabel(virConnectPtr conn,
+qemuSecurityDACSetSavedStateLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainObjPtr vm ATTRIBUTE_UNUSED,
const char *savefile)
{
if (!driver->privileged || !driver->dynamicOwnership)
return 0;
- return qemuSecurityDACSetOwnership(conn, savefile, driver->user, driver->group);
+ return qemuSecurityDACSetOwnership(savefile, driver->user, driver->group);
}
static int
-qemuSecurityDACRestoreSavedStateLabel(virConnectPtr conn,
+qemuSecurityDACRestoreSavedStateLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainObjPtr vm ATTRIBUTE_UNUSED,
const char *savefile)
{
if (!driver->privileged || !driver->dynamicOwnership)
return 0;
- return qemuSecurityDACRestoreSecurityFileLabel(conn, savefile);
+ return qemuSecurityDACRestoreSecurityFileLabel(savefile);
}
if (driver->group) {
if (setregid(driver->group, driver->group) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot change to '%d' group"),
driver->group);
return -1;
}
if (driver->user) {
if (setreuid(driver->user, driver->user) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot change to '%d' user"),
driver->user);
return -1;
}
freeaddrinfo (res);
- virReportSystemError(conn, saved_errno,
+ virReportSystemError(saved_errno,
_("unable to connect to libvirtd at '%s'"),
priv->hostname);
goto failed;
priv->is_secure = 1;
priv->sock = socket (AF_UNIX, SOCK_STREAM, 0);
if (priv->sock == -1) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("unable to create socket"));
goto failed;
}
goto autostart_retry;
}
}
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("unable to connect to '%s'"),
sockname);
goto failed;
* to faff around with two file descriptors (a la 'pipe(2)').
*/
if (socketpair (PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("unable to create socket pair"));
goto failed;
}
} /* switch (transport) */
if (virSetNonBlock(priv->sock) < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("unable to make socket non-blocking"));
goto failed;
}
if (pipe(wakeupFD) < 0) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("unable to make pipe"));
goto failed;
}
static int
-check_cert_file (virConnectPtr conn, const char *type, const char *file)
+check_cert_file(const char *type, const char *file)
{
struct stat sb;
if (stat(file, &sb) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Cannot access %s '%s'"),
type, file);
return -1;
}
- if (check_cert_file(conn, "CA certificate", LIBVIRT_CACERT) < 0)
+ if (check_cert_file("CA certificate", LIBVIRT_CACERT) < 0)
return -1;
- if (check_cert_file(conn, "client key", LIBVIRT_CLIENTKEY) < 0)
+ if (check_cert_file("client key", LIBVIRT_CLIENTKEY) < 0)
return -1;
- if (check_cert_file(conn, "client certificate", LIBVIRT_CLIENTCERT) < 0)
+ if (check_cert_file("client certificate", LIBVIRT_CLIENTCERT) < 0)
return -1;
/* Set the trusted CA cert. */
}
if ((now = time(NULL)) == ((time_t)-1)) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("cannot get current time"));
return -1;
}
/* Get local address in form IPADDR:PORT */
salen = sizeof(sa);
if (getsockname(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
- virReportSystemError(in_open ? NULL : conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("failed to get sock address"));
goto cleanup;
}
/* Get remote address in form IPADDR:PORT */
salen = sizeof(sa);
if (getpeername(priv->sock, (struct sockaddr*)&sa, &salen) < 0) {
- virReportSystemError(in_open ? NULL : conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("failed to get peer address"));
goto cleanup;
}
if (errno == EWOULDBLOCK)
return 0;
- virReportSystemError(in_open ? NULL : conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot send data"));
return -1;
if (errno == EWOULDBLOCK)
return 0;
- virReportSystemError(in_open ? NULL : conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot recv data"));
} else {
errorf (in_open ? NULL : conn,
if (ret < 0) {
if (errno == EWOULDBLOCK)
continue;
- virReportSystemError(in_open ? NULL : conn, errno,
+ virReportSystemError(errno,
"%s", _("poll on socket failed"));
goto error;
}
"$basename.base64". "$basename" is in both cases the base64-encoded UUID. */
static int
-replaceFile(virConnectPtr conn, const char *filename, void *data, size_t size)
+replaceFile(const char *filename, void *data, size_t size)
{
char *tmp_path = NULL;
int fd = -1, ret = -1;
}
fd = mkstemp (tmp_path);
if (fd == -1) {
- virReportSystemError(conn, errno, _("mkstemp('%s') failed"), tmp_path);
+ virReportSystemError(errno, _("mkstemp('%s') failed"), tmp_path);
goto cleanup;
}
if (fchmod(fd, S_IRUSR | S_IWUSR) != 0) {
- virReportSystemError(conn, errno, _("fchmod('%s') failed"), tmp_path);
+ virReportSystemError(errno, _("fchmod('%s') failed"), tmp_path);
goto cleanup;
}
ret = safewrite(fd, data, size);
if (ret < 0) {
- virReportSystemError(conn, errno, _("error writing to '%s'"),
+ virReportSystemError(errno, _("error writing to '%s'"),
tmp_path);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno, _("error closing '%s'"), tmp_path);
+ virReportSystemError(errno, _("error closing '%s'"), tmp_path);
goto cleanup;
}
fd = -1;
if (rename(tmp_path, filename) < 0) {
- virReportSystemError(conn, errno, _("rename(%s, %s) failed"), tmp_path,
+ virReportSystemError(errno, _("rename(%s, %s) failed"), tmp_path,
filename);
goto cleanup;
}
}
static int
-secretEnsureDirectory(virConnectPtr conn, virSecretDriverStatePtr driver)
+secretEnsureDirectory(virSecretDriverStatePtr driver)
{
if (mkdir(driver->directory, S_IRWXU) < 0 && errno != EEXIST) {
- virReportSystemError(conn, errno, _("cannot create '%s'"),
+ virReportSystemError(errno, _("cannot create '%s'"),
driver->directory);
return -1;
}
char *filename = NULL, *xml = NULL;
int ret = -1;
- if (secretEnsureDirectory(conn, driver) < 0)
+ if (secretEnsureDirectory(driver) < 0)
goto cleanup;
filename = secretXMLPath(conn, driver, secret);
if (xml == NULL)
goto cleanup;
- if (replaceFile(conn, filename, xml, strlen(xml)) < 0)
+ if (replaceFile(filename, xml, strlen(xml)) < 0)
goto cleanup;
ret = 0;
if (secret->value == NULL)
return 0;
- if (secretEnsureDirectory(conn, driver) < 0)
+ if (secretEnsureDirectory(driver) < 0)
goto cleanup;
filename = secretBase64Path(conn, driver, secret);
goto cleanup;
}
- if (replaceFile(conn, filename, base64, strlen(base64)) < 0)
+ if (replaceFile(filename, base64, strlen(base64)) < 0)
goto cleanup;
ret = 0;
ret = 0;
goto cleanup;
}
- virReportSystemError (conn, errno, _("cannot open '%s'"), filename);
+ virReportSystemError(errno, _("cannot open '%s'"), filename);
goto cleanup;
}
if (fstat(fd, &st) < 0) {
- virReportSystemError (conn, errno, _("cannot stat '%s'"), filename);
+ virReportSystemError(errno, _("cannot stat '%s'"), filename);
goto cleanup;
}
if ((size_t)st.st_size != st.st_size) {
goto cleanup;
}
if (saferead(fd, contents, st.st_size) != st.st_size) {
- virReportSystemError (conn, errno, _("cannot read '%s'"), filename);
+ virReportSystemError(errno, _("cannot read '%s'"), filename);
goto cleanup;
}
close(fd);
if (dir == NULL) {
if (errno == ENOENT)
return 0;
- virReportSystemError(conn, errno, _("cannot open '%s'"),
+ virReportSystemError(errno, _("cannot open '%s'"),
driver->directory);
goto cleanup;
}
}
if (virFileReadAll(APPARMOR_PROFILES_PATH, MAX_FILE_LEN, &content) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to read AppArmor profiles list "
"\'%s\'"), APPARMOR_PROFILES_PATH);
goto clean;
goto failed;
if ((len = virFileReadAll(profile, MAX_FILE_LEN, &content)) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Failed to read \'%s\'"), profile);
goto failed;
}
pid_t child;
if (pipe(pipefd) < -1) {
- virReportSystemError(conn, errno, "%s", _("unable to create pipe"));
+ virReportSystemError(errno, "%s", _("unable to create pipe"));
return rc;
}
/* parent continues here */
if (safewrite(pipefd[1], xml, strlen(xml)) < 0) {
- virReportSystemError(conn, errno, "%s", _("unable to write to pipe"));
+ virReportSystemError(errno, "%s", _("unable to write to pipe"));
goto clean;
}
close(pipefd[1]);
}
static int
-SELinuxInitialize(virConnectPtr conn)
+SELinuxInitialize(void)
{
char *ptr = NULL;
int fd = 0;
fd = open(selinux_virtual_domain_context_path(), O_RDONLY);
if (fd < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open SELinux virtual domain context file '%s'"),
selinux_virtual_domain_context_path());
return -1;
}
if (saferead(fd, default_domain_context, sizeof(default_domain_context)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read SELinux virtual domain context file %s"),
selinux_virtual_domain_context_path());
close(fd);
*ptr = '\0';
if ((fd = open(selinux_virtual_image_context_path(), O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open SELinux virtual image context file %s"),
selinux_virtual_image_context_path());
return -1;
}
if (saferead(fd, default_image_context, sizeof(default_image_context)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read SELinux virtual image context file %s"),
selinux_virtual_image_context_path());
close(fd);
}
static int
-SELinuxReserveSecurityLabel(virConnectPtr conn,
+SELinuxReserveSecurityLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainObjPtr vm)
{
security_context_t pctx;
return 0;
if (getpidcon(vm->pid, &pctx) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("unable to get PID %d security context"), vm->pid);
return -1;
}
* configuration? For the moment, we'll just set it to "0".
*/
virSecurityDriverSetDOI(conn, drv, SECURITY_SELINUX_VOID_DOI);
- return SELinuxInitialize(conn);
+ return SELinuxInitialize();
}
static int
security_context_t ctx;
if (getpidcon(vm->pid, &ctx) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("unable to get PID %d security context"),
vm->pid);
return -1;
sec->enforcing = security_getenforce();
if (sec->enforcing == -1) {
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("error calling security_getenforce()"));
return -1;
}
}
static int
-SELinuxSetFilecon(virConnectPtr conn, const char *path, char *tcon)
+SELinuxSetFilecon(const char *path, char *tcon)
{
security_context_t econ;
* virt_use_{nfs,usb,pci} boolean tunables to allow it...
*/
if (setfilecon_errno != EOPNOTSUPP) {
- virReportSystemError(conn, setfilecon_errno,
+ virReportSystemError(setfilecon_errno,
_("unable to set security context '%s' on '%s'"),
tcon, path);
if (security_getenforce() == 1)
}
static int
-SELinuxRestoreSecurityFileLabel(virConnectPtr conn,
- const char *path)
+SELinuxRestoreSecurityFileLabel(const char *path)
{
struct stat buf;
security_context_t fcon = NULL;
VIR_INFO("Restoring SELinux context on '%s'", path);
if ((err = virFileResolveLink(path, &newpath)) < 0) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("cannot resolve symlink %s"), path);
goto err;
}
goto err;
if (matchpathcon(newpath, buf.st_mode, &fcon) == 0) {
- rc = SELinuxSetFilecon(conn, newpath, fcon);
+ rc = SELinuxSetFilecon(newpath, fcon);
}
err:
VIR_FREE(fcon);
}
static int
-SELinuxRestoreSecurityImageLabel(virConnectPtr conn,
+SELinuxRestoreSecurityImageLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainObjPtr vm,
virDomainDiskDefPtr disk)
{
if (!disk->src)
return 0;
- return SELinuxRestoreSecurityFileLabel(conn, disk->src);
+ return SELinuxRestoreSecurityFileLabel(disk->src);
}
static int
return -1;
if (meta.backingStore != NULL &&
- SELinuxSetFilecon(conn, meta.backingStore,
+ SELinuxSetFilecon(meta.backingStore,
default_content_context) < 0) {
VIR_FREE(meta.backingStore);
return -1;
} while (path != NULL);
if (disk->shared) {
- return SELinuxSetFilecon(conn, disk->src, default_image_context);
+ return SELinuxSetFilecon(disk->src, default_image_context);
} else if (disk->readonly) {
- return SELinuxSetFilecon(conn, disk->src, default_content_context);
+ return SELinuxSetFilecon(disk->src, default_content_context);
} else if (secdef->imagelabel) {
- return SELinuxSetFilecon(conn, disk->src, secdef->imagelabel);
+ return SELinuxSetFilecon(disk->src, secdef->imagelabel);
}
return 0;
static int
-SELinuxSetSecurityPCILabel(virConnectPtr conn,
+SELinuxSetSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED,
pciDevice *dev ATTRIBUTE_UNUSED,
const char *file, void *opaque)
{
virDomainObjPtr vm = opaque;
const virSecurityLabelDefPtr secdef = &vm->def->seclabel;
- return SELinuxSetFilecon(conn, file, secdef->imagelabel);
+ return SELinuxSetFilecon(file, secdef->imagelabel);
}
static int
-SELinuxSetSecurityUSBLabel(virConnectPtr conn,
+SELinuxSetSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
usbDevice *dev ATTRIBUTE_UNUSED,
const char *file, void *opaque)
{
virDomainObjPtr vm = opaque;
const virSecurityLabelDefPtr secdef = &vm->def->seclabel;
- return SELinuxSetFilecon(conn, file, secdef->imagelabel);
+ return SELinuxSetFilecon(file, secdef->imagelabel);
}
static int
static int
-SELinuxRestoreSecurityPCILabel(virConnectPtr conn,
+SELinuxRestoreSecurityPCILabel(virConnectPtr conn ATTRIBUTE_UNUSED,
pciDevice *dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
- return SELinuxRestoreSecurityFileLabel(conn, file);
+ return SELinuxRestoreSecurityFileLabel(file);
}
static int
-SELinuxRestoreSecurityUSBLabel(virConnectPtr conn,
+SELinuxRestoreSecurityUSBLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
usbDevice *dev ATTRIBUTE_UNUSED,
const char *file,
void *opaque ATTRIBUTE_UNUSED)
{
- return SELinuxRestoreSecurityFileLabel(conn, file);
+ return SELinuxRestoreSecurityFileLabel(file);
}
static int
static int
-SELinuxSetSavedStateLabel(virConnectPtr conn,
+SELinuxSetSavedStateLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainObjPtr vm,
const char *savefile)
{
if (secdef->type == VIR_DOMAIN_SECLABEL_STATIC)
return 0;
- return SELinuxSetFilecon(conn, savefile, secdef->imagelabel);
+ return SELinuxSetFilecon(savefile, secdef->imagelabel);
}
static int
-SELinuxRestoreSavedStateLabel(virConnectPtr conn,
+SELinuxRestoreSavedStateLabel(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainObjPtr vm,
const char *savefile)
{
if (secdef->type == VIR_DOMAIN_SECLABEL_STATIC)
return 0;
- return SELinuxRestoreSecurityFileLabel(conn, savefile);
+ return SELinuxRestoreSecurityFileLabel(savefile);
}
}
if (setexeccon(secdef->label) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("unable to set security context '%s'"),
secdef->label);
if (security_getenforce() == 1)
TOOL_QCOW_CREATE,
};
-static int ATTRIBUTE_NONNULL (3)
-virStorageBackendCopyToFD(virConnectPtr conn,
- virStorageVolDefPtr vol,
+static int ATTRIBUTE_NONNULL (2)
+virStorageBackendCopyToFD(virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
int fd,
unsigned long long *total,
char *buf = NULL;
if ((inputfd = open(inputvol->target.path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("could not open input path '%s'"),
inputvol->target.path);
goto cleanup;
bytes = remain;
if ((amtread = saferead(inputfd, buf, bytes)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed reading from file '%s'"),
inputvol->target.path);
goto cleanup;
if (is_dest_file && memcmp(buf+offset, zerobuf, interval) == 0) {
if (lseek(fd, interval, SEEK_CUR) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot extend file '%s'"),
vol->target.path);
goto cleanup;
}
} else if (safewrite(fd, buf+offset, interval) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed writing to file '%s'"),
vol->target.path);
goto cleanup;
}
if (inputfd != -1 && close(inputfd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot close file '%s'"),
inputvol->target.path);
goto cleanup;
}
static int
-virStorageBackendCreateBlockFrom(virConnectPtr conn,
+virStorageBackendCreateBlockFrom(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
virStorageVolDefPtr vol,
virStorageVolDefPtr inputvol,
uid_t uid;
if ((fd = open(vol->target.path, O_RDWR)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot create path '%s'"),
vol->target.path);
goto cleanup;
remain = vol->allocation;
if (inputvol) {
- int res = virStorageBackendCopyToFD(conn, vol, inputvol,
+ int res = virStorageBackendCopyToFD(vol, inputvol,
fd, &remain, 0);
if (res < 0)
goto cleanup;
if (fstat(fd, &st) == -1) {
ret = errno;
- virReportSystemError(conn, errno, _("stat of '%s' failed"),
+ virReportSystemError(errno, _("stat of '%s' failed"),
vol->target.path);
goto cleanup;
}
gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : -1;
if (((uid != -1) || (gid != -1))
&& (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot chown '%s' to (%u, %u)"),
vol->target.path, vol->target.perms.uid,
vol->target.perms.gid);
goto cleanup;
}
if (fchmod(fd, vol->target.perms.mode) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot set mode of '%s' to %04o"),
vol->target.path, vol->target.perms.mode);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
goto cleanup;
vol->target.perms.uid, vol->target.perms.gid,
(pool->def->type == VIR_STORAGE_POOL_NETFS
? VIR_FILE_CREATE_AS_UID : 0))) < 0) {
- virReportSystemError(conn, createstat,
+ virReportSystemError(createstat,
_("cannot create path '%s'"),
vol->target.path);
goto cleanup;
}
if ((fd = open(vol->target.path, O_RDWR | O_EXCL)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open new path '%s'"),
vol->target.path);
goto cleanup;
/* Seek to the final size, so the capacity is available upfront
* for progress reporting */
if (ftruncate(fd, vol->capacity) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot extend file '%s'"),
vol->target.path);
goto cleanup;
remain = vol->allocation;
if (inputvol) {
- int res = virStorageBackendCopyToFD(conn, vol, inputvol,
+ int res = virStorageBackendCopyToFD(vol, inputvol,
fd, &remain, 1);
if (res < 0)
goto cleanup;
bytes = remain;
if ((r = safezero(fd, 0, vol->allocation - remain,
bytes)) != 0) {
- virReportSystemError(conn, r,
+ virReportSystemError(r,
_("cannot fill file '%s'"),
vol->target.path);
goto cleanup;
int r;
if ((r = safezero(fd, 0, 0, remain)) != 0) {
- virReportSystemError(conn, r,
+ virReportSystemError(r,
_("cannot fill file '%s'"),
vol->target.path);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
goto cleanup;
if ((vol->target.perms.gid != 0)
&& (setgid(vol->target.perms.gid) != 0)) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Cannot set gid to %u before creating %s"),
vol->target.perms.gid, vol->target.path);
return -1;
}
if ((vol->target.perms.uid != 0)
&& (setuid(vol->target.perms.uid) != 0)) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("Cannot set uid to %u before creating %s"),
vol->target.perms.uid, vol->target.path);
return -1;
}
if (!filecreated) {
if (virRun(conn, cmdargv, NULL) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Cannot run %s to create %s"),
cmdargv[0], vol->target.path);
return -1;
}
if (stat(vol->target.path, &st) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("%s failed to create %s"),
cmdargv[0], vol->target.path);
return -1;
gid = (vol->target.perms.gid != st.st_gid) ? vol->target.perms.gid : -1;
if (((uid != -1) || (gid != -1))
&& (chown(vol->target.path, uid, gid) < 0)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot chown %s to (%u, %u)"),
vol->target.path, vol->target.perms.uid,
vol->target.perms.gid);
return -1;
}
if (chmod(vol->target.path, vol->target.perms.mode) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot set mode of '%s' to %04o"),
vol->target.path, vol->target.perms.mode);
return -1;
return -1;
}
if (access(vol->backingStore.path, R_OK) != 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("inaccessible backing store volume %s"),
vol->backingStore.path);
return -1;
int
-virStorageBackendUpdateVolTargetInfo(virConnectPtr conn,
- virStorageVolTargetPtr target,
+virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
unsigned long long *allocation,
unsigned long long *capacity)
{
int ret, fd;
if ((fd = open(target->path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open volume '%s'"),
target->path);
return -1;
}
- ret = virStorageBackendUpdateVolTargetInfoFD(conn,
- target,
+ ret = virStorageBackendUpdateVolTargetInfoFD(target,
fd,
allocation,
capacity);
}
int
-virStorageBackendUpdateVolInfo(virConnectPtr conn,
- virStorageVolDefPtr vol,
+virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
int withCapacity)
{
int ret;
- if ((ret = virStorageBackendUpdateVolTargetInfo(conn,
- &vol->target,
+ if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target,
&vol->allocation,
withCapacity ? &vol->capacity : NULL)) < 0)
return ret;
if (vol->backingStore.path &&
- (ret = virStorageBackendUpdateVolTargetInfo(conn,
- &vol->backingStore,
+ (ret = virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
NULL, NULL)) < 0)
return ret;
* -2 if passed FD isn't a regular, char, or block file.
*/
int
-virStorageBackendUpdateVolTargetInfoFD(virConnectPtr conn,
- virStorageVolTargetPtr target,
+virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
int fd,
unsigned long long *allocation,
unsigned long long *capacity)
#endif
if (fstat(fd, &sb) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot stat file '%s'"),
target->path);
return -1;
*/
end = lseek(fd, 0, SEEK_END);
if (end == (off_t)-1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot seek to end of file '%s'"),
target->path);
return -1;
/* XXX: make this a security driver call */
if (fgetfilecon(fd, &filecon) == -1) {
if (errno != ENODATA && errno != ENOTSUP) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot get file context of '%s'"),
target->path);
return -1;
int
-virStorageBackendUpdateVolTargetFormatFD(virConnectPtr conn,
- virStorageVolTargetPtr target,
+virStorageBackendUpdateVolTargetFormatFD(virStorageVolTargetPtr target,
int fd)
{
int i;
start = lseek(fd, 0, SEEK_SET);
if (start < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot seek to beginning of file '%s'"),
target->path);
return -1;
}
bytes = saferead(fd, buffer, sizeof(buffer));
if (bytes < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read beginning of file '%s'"),
target->path);
return -1;
* with stable paths.
*/
char *
-virStorageBackendStablePath(virConnectPtr conn,
- virStoragePoolObjPtr pool,
+virStorageBackendStablePath(virStoragePoolObjPtr pool,
const char *devpath)
{
DIR *dh;
usleep(100 * 1000);
goto reopen;
}
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read dir '%s'"),
pool->def->target.path);
return NULL;
return -1;
if (err == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to wait for command '%s'"),
prog[0]);
return -1;
if (feof (fp))
err = 0;
else
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("read error on pipe to '%s'"), prog[0]);
cleanup:
return -1;
if (w_err == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to wait for command '%s'"),
prog[0]);
return -1;
virStorageBackendPtr virStorageBackendForType(int type);
-int virStorageBackendUpdateVolInfo(virConnectPtr conn,
- virStorageVolDefPtr vol,
+int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
int withCapacity);
-int virStorageBackendUpdateVolTargetInfo(virConnectPtr conn,
- virStorageVolTargetPtr target,
+int virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
unsigned long long *allocation,
unsigned long long *capacity);
-int virStorageBackendUpdateVolTargetInfoFD(virConnectPtr conn,
- virStorageVolTargetPtr target,
+int virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
int fd,
unsigned long long *allocation,
unsigned long long *capacity);
int
-virStorageBackendUpdateVolTargetFormatFD(virConnectPtr conn,
- virStorageVolTargetPtr target,
+virStorageBackendUpdateVolTargetFormatFD(virStorageVolTargetPtr target,
int fd);
-char *virStorageBackendStablePath(virConnectPtr conn,
- virStoragePoolObjPtr pool,
+char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
const char *devpath);
typedef int (*virStorageBackendListVolRegexFunc)(virConnectPtr conn,
* dir every time its run. Should figure out a more efficient
* way of doing this...
*/
- vol->target.path = virStorageBackendStablePath(conn, pool, devpath);
+ vol->target.path = virStorageBackendStablePath(pool, devpath);
VIR_FREE(devpath);
if (vol->target.path == NULL)
return -1;
}
/* Refresh allocation/capacity/perms */
- if (virStorageBackendUpdateVolInfo(conn, vol, 1) < 0)
+ if (virStorageBackendUpdateVolInfo(vol, 1) < 0)
return -1;
/* set partition type */
int rc = -1;
if ((err = virFileResolveLink(vol->target.path, &devpath)) < 0) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("Couldn't read volume target path '%s'"),
vol->target.path);
goto cleanup;
*encryption = NULL;
if ((fd = open(target->path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open volume '%s'"),
target->path);
return -1;
}
- if ((ret = virStorageBackendUpdateVolTargetInfoFD(conn, target, fd,
+ if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd,
allocation,
capacity)) < 0) {
close(fd);
* Return 0 if not mounted, 1 if mounted, -1 on error
*/
static int
-virStorageBackendFileSystemIsMounted(virConnectPtr conn,
- virStoragePoolObjPtr pool) {
+virStorageBackendFileSystemIsMounted(virStoragePoolObjPtr pool) {
FILE *mtab;
struct mntent ent;
char buf[1024];
if ((mtab = fopen(_PATH_MOUNTED, "r")) == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read mount list '%s'"),
_PATH_MOUNTED);
return -1;
}
/* Short-circuit if already mounted */
- if ((ret = virStorageBackendFileSystemIsMounted(conn, pool)) != 0) {
+ if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 0) {
if (ret < 0)
return -1;
else
}
/* Short-circuit if already unmounted */
- if ((ret = virStorageBackendFileSystemIsMounted(conn, pool)) != 1) {
+ if ((ret = virStorageBackendFileSystemIsMounted(pool)) != 1) {
if (ret < 0)
return -1;
else
* exist, with default uid/gid/mode. */
*p = '\0';
if ((err = virFileMakePath(parent)) != 0) {
- virReportSystemError(conn, err, _("cannot create path '%s'"),
+ virReportSystemError(err, _("cannot create path '%s'"),
parent);
goto error;
}
VIR_FILE_CREATE_ALLOW_EXIST |
(pool->def->type == VIR_STORAGE_POOL_NETFS
? VIR_FILE_CREATE_AS_UID : 0)) != 0)) {
- virReportSystemError(conn, err, _("cannot create path '%s'"),
+ virReportSystemError(err, _("cannot create path '%s'"),
pool->def->target.path);
goto error;
}
virStorageVolDefPtr vol = NULL;
if (!(dir = opendir(pool->def->target.path))) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open path '%s'"),
pool->def->target.path);
goto cleanup;
memmove(backingStore, path, strlen(path) + 1);
vol->backingStore.path = backingStore;
- if (virStorageBackendUpdateVolTargetInfo(conn,
- &vol->backingStore,
+ if (virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
NULL,
NULL) < 0)
VIR_FREE(vol->backingStore);
if (statvfs(pool->def->target.path, &sb) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot statvfs path '%s'"),
pool->def->target.path);
return -1;
* Returns 0 on success, -1 on error
*/
static int
-virStorageBackendFileSystemDelete(virConnectPtr conn,
+virStorageBackendFileSystemDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool,
unsigned int flags ATTRIBUTE_UNUSED)
{
/* XXX delete all vols first ? */
if (rmdir(pool->def->target.path) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to remove pool '%s'"),
pool->def->target.path);
return -1;
vol->target.perms.uid, vol->target.perms.gid,
(pool->def->type == VIR_STORAGE_POOL_NETFS
? VIR_FILE_CREATE_AS_UID : 0))) != 0) {
- virReportSystemError(conn, err, _("cannot create path '%s'"),
+ virReportSystemError(err, _("cannot create path '%s'"),
vol->target.path);
return -1;
}
* Remove a volume - just unlinks for now
*/
static int
-virStorageBackendFileSystemVolDelete(virConnectPtr conn,
+virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
virStorageVolDefPtr vol,
unsigned int flags ATTRIBUTE_UNUSED)
if (unlink(vol->target.path) < 0) {
/* Silently ignore failures where the vol has already gone away */
if (errno != ENOENT) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot unlink file '%s'"),
vol->target.path);
return -1;
int ret;
/* Refresh allocation / permissions info in case its changed */
- ret = virStorageBackendUpdateVolInfo(conn, vol, 0);
+ ret = virStorageBackendUpdateVolInfo(vol, 0);
if (ret < 0)
return ret;
"/sys/class/iscsi_session/session%s/device", session);
if (virStorageBackendSCSIGetHostNumber(conn, sysfs_path, &host) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to get host number for iSCSI session "
"with path '%s'"),
sysfs_path);
}
if (virStorageBackendSCSIFindLUs(conn, pool, host) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to find LUs on host %u"), host);
retval = -1;
}
return -1;
}
- if (virStorageBackendUpdateVolInfo(conn, vol, 1) < 0)
+ if (virStorageBackendUpdateVolInfo(vol, 1) < 0)
return -1;
* 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) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open device '%s'"),
pool->def->source.devices[i].path);
goto cleanup;
}
if (safewrite(fd, zeros, sizeof(zeros)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot clear device header of '%s'"),
pool->def->source.devices[i].path);
close(fd);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot close device '%s'"),
pool->def->source.devices[i].path);
goto cleanup;
pvargv[1] = pool->def->source.devices[i].path;
if (virRun(conn, pvargv, NULL) < 0) {
error = -1;
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot remove PV device '%s'"),
pool->def->source.devices[i].path);
break;
return -1;
if ((fd = open(vol->target.path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read path '%s'"),
vol->target.path);
goto cleanup;
/* We can only chown/grp if root */
if (getuid() == 0) {
if (fchown(fd, vol->target.perms.uid, vol->target.perms.gid) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot set file owner '%s'"),
vol->target.path);
goto cleanup;
}
}
if (fchmod(fd, vol->target.perms.mode) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot set file mode '%s'"),
vol->target.path);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot close file '%s'"),
vol->target.path);
goto cleanup;
/* Fill in data about this new vol */
if (virStorageBackendLogicalFindLVs(conn, pool, vol) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot find newly created volume '%s'"),
vol->target.path);
goto cleanup;
int fd = -1;
if ((fd = open(target->path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open volume '%s'"),
target->path);
ret = -1;
goto out;
}
- if (virStorageBackendUpdateVolTargetInfoFD(conn,
- target,
+ if (virStorageBackendUpdateVolTargetInfoFD(target,
fd,
allocation,
capacity) < 0) {
goto out;
}
- if (virStorageBackendUpdateVolTargetFormatFD(conn,
- target,
- fd) < 0) {
+ if (virStorageBackendUpdateVolTargetFormatFD(target, fd) < 0) {
virStorageReportError(conn, VIR_ERR_INTERNAL_ERROR,
_("Failed to update volume target format for '%s'"),
target->path);
typefile = fopen(type_path, "r");
if (typefile == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Could not find typefile '%s'"),
type_path);
/* there was no type file; that doesn't seem right */
fclose(typefile);
if (gottype == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Could not read typefile '%s'"),
type_path);
/* we couldn't read the type file; have to give up */
};
static int
-virStorageBackendSCSIUpdateVolTargetInfo(virConnectPtr conn,
- virStorageVolTargetPtr target,
+virStorageBackendSCSIUpdateVolTargetInfo(virStorageVolTargetPtr target,
unsigned long long *allocation,
unsigned long long *capacity)
{
ssize_t bytes;
if ((fd = open(target->path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open volume '%s'"),
target->path);
return -1;
}
- if (virStorageBackendUpdateVolTargetInfoFD(conn,
- target,
+ if (virStorageBackendUpdateVolTargetInfoFD(target,
fd,
allocation,
capacity) < 0)
start = lseek(fd, 0, SEEK_SET);
if (start < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot seek to beginning of file '%s'"),
target->path);
goto cleanup;
}
bytes = saferead(fd, buffer, sizeof(buffer));
if (bytes < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read beginning of file '%s'"),
target->path);
goto cleanup;
* dir every time its run. Should figure out a more efficient
* way of doing this...
*/
- if ((vol->target.path = virStorageBackendStablePath(conn,
- pool,
+ if ((vol->target.path = virStorageBackendStablePath(pool,
devpath)) == NULL) {
retval = -1;
goto free_vol;
goto free_vol;
}
- if (virStorageBackendSCSIUpdateVolTargetInfo(conn,
- &vol->target,
+ if (virStorageBackendSCSIUpdateVolTargetInfo(&vol->target,
&vol->allocation,
&vol->capacity) < 0) {
static int
-getNewStyleBlockDevice(virConnectPtr conn,
+getNewStyleBlockDevice(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
const char *lun_path,
const char *block_name ATTRIBUTE_UNUSED,
char **block_device)
block_dir = opendir(block_path);
if (block_dir == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to opendir sysfs path '%s'"),
block_path);
retval = -1;
lun_dir = opendir(lun_path);
if (lun_dir == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to opendir sysfs path '%s'"),
lun_path);
retval = -1;
devicedir = opendir(device_path);
if (devicedir == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to opendir path '%s'"), device_path);
retval = -1;
goto out;
sysdir = opendir(sysfs_path);
if (sysdir == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to opendir path '%s'"), sysfs_path);
retval = -1;
goto out;
static int
-virStorageBackendSCSITriggerRescan(virConnectPtr conn,
- uint32_t host)
+virStorageBackendSCSITriggerRescan(uint32_t host)
{
int fd = -1;
int retval = 0;
fd = open(path, O_WRONLY);
if (fd < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Could not open '%s' to trigger host scan"),
path);
retval = -1;
LINUX_SYSFS_SCSI_HOST_SCAN_STRING,
sizeof(LINUX_SYSFS_SCSI_HOST_SCAN_STRING)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Write to '%s' to trigger host scan failed"),
path);
retval = -1;
VIR_DEBUG(_("Scanning host%u"), host);
- if (virStorageBackendSCSITriggerRescan(conn, host) < 0) {
+ if (virStorageBackendSCSITriggerRescan(host) < 0) {
retval = -1;
goto out;
}
int err;
if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(obj->conn, err,
+ virReportSystemError(err,
_("cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
}
if (symlink(pool->configFile, pool->autostartLink) < 0) {
- virReportSystemError(obj->conn, errno,
+ virReportSystemError(errno,
_("Failed to create symlink '%s' to '%s'"),
pool->autostartLink, pool->configFile);
goto cleanup;
} else {
if (unlink(pool->autostartLink) < 0 &&
errno != ENOENT && errno != ENOTDIR) {
- virReportSystemError(obj->conn, errno,
+ virReportSystemError(errno,
_("Failed to delete symlink '%s'"),
pool->autostartLink);
goto cleanup;
virStorageVolDefPtr vol;
const char *stable_path;
- stable_path = virStorageBackendStablePath(conn,
- driver->pools.objs[i],
+ stable_path = virStorageBackendStablePath(driver->pools.objs[i],
path);
/*
* virStorageBackendStablePath already does
conn->privateData = privconn;
if (gettimeofday(&tv, NULL) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("getting time of day"));
goto error;
}
goto error;
if ((fd = open(file, O_RDONLY)) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("loading host definition file '%s'"),
file);
goto error;
VIR_DOMAIN_XML_SECURE);
if (xml == NULL) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("saving domain '%s' failed to allocate space for metadata"),
domain->name);
goto cleanup;
}
if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("saving domain '%s' to '%s': open failed"),
domain->name, path);
goto cleanup;
}
len = strlen(xml);
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("saving domain '%s' to '%s': write failed"),
domain->name, path);
goto cleanup;
}
if (safewrite(fd, (char*)&len, sizeof(len)) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("saving domain '%s' to '%s': write failed"),
domain->name, path);
goto cleanup;
}
if (safewrite(fd, xml, len) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("saving domain '%s' to '%s': write failed"),
domain->name, path);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("saving domain '%s' to '%s': write failed"),
domain->name, path);
goto cleanup;
int ret = -1;
if ((fd = open(path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read domain image '%s'"),
path);
goto cleanup;
}
if (saferead(fd, magic, sizeof(magic)) != sizeof(magic)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("incomplete save header in '%s'"),
path);
goto cleanup;
goto cleanup;
}
if (saferead(fd, (char*)&len, sizeof(len)) != sizeof(len)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to read metadata length in '%s'"),
path);
goto cleanup;
goto cleanup;
}
if (saferead(fd, xml, len) != len) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("incomplete metdata in '%s'"), path);
goto cleanup;
}
}
if ((fd = open(to, O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR)) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("domain '%s' coredump: failed to open %s"),
domain->name, to);
goto cleanup;
}
if (safewrite(fd, TEST_SAVE_MAGIC, sizeof(TEST_SAVE_MAGIC)) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("domain '%s' coredump: failed to write header to %s"),
domain->name, to);
goto cleanup;
}
if (close(fd) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("domain '%s' coredump: write failed: %s"),
domain->name, to);
goto cleanup;
privdomdata = privdom->privateData;
if (gettimeofday(&tv, NULL) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
"%s", _("getting time of day"));
goto cleanup;
}
}
if (gettimeofday(&tv, NULL) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
"%s", _("getting time of day"));
goto error;
}
}
if (gettimeofday(&tv, NULL) < 0) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
"%s", _("getting time of day"));
goto error;
}
int err;
if ((err = brInit(&brctl))) {
- virReportSystemError(conn, err, "%s",
+ virReportSystemError(err, "%s",
_("cannot initialize bridge support"));
goto error;
}
_("Failed to add tap interface to bridge. "
"%s is not a bridge device"), bridge);
} else if (template_ifname) {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("Failed to add tap interface to bridge '%s'"),
bridge);
} else {
- virReportSystemError(conn, err,
+ virReportSystemError(err,
_("Failed to add tap interface '%s' to bridge '%s'"),
net->ifname, bridge);
}
static int umlOpenMonitor(virConnectPtr conn,
struct uml_driver *driver,
virDomainObjPtr vm);
-static int umlReadPidFile(virConnectPtr conn,
- struct uml_driver *driver,
+static int umlReadPidFile(struct uml_driver *driver,
virDomainObjPtr vm);
static int umlSetCloseExec(int fd) {
continue;
}
- if (umlReadPidFile(NULL, driver, dom) < 0) {
+ if (umlReadPidFile(driver, dom) < 0) {
virDomainObjUnlock(dom);
continue;
}
}
-static int umlReadPidFile(virConnectPtr conn,
- struct uml_driver *driver,
+static int umlReadPidFile(struct uml_driver *driver,
virDomainObjPtr vm)
{
int rc = -1;
cleanup:
if (rc != 0)
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to read pid: %s"),
pidfile);
VIR_FREE(pidfile);
}
if ((priv->monitor = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot open socket"));
return -1;
}
sprintf(addr.sun_path + 1, "libvirt-uml-%u", vm->pid);
VIR_DEBUG("Reply address for monitor is '%s'", addr.sun_path+1);
if (bind(priv->monitor, (struct sockaddr *)&addr, sizeof addr) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot bind socket"));
close(priv->monitor);
priv->monitor = -1;
req.version = MONITOR_VERSION;
req.length = strlen(cmd);
if (req.length > (MONITOR_BUFLEN-1)) {
- virReportSystemError(conn, EINVAL,
+ virReportSystemError(EINVAL,
_("cannot send too long command %s (%d bytes)"),
cmd, req.length);
return -1;
if (sendto(priv->monitor, &req, sizeof req, 0,
(struct sockaddr *)&addr, sizeof addr) != (sizeof req)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot send command %s"),
cmd);
return -1;
addrlen = sizeof(addr);
if (recvfrom(priv->monitor, &res, sizeof res, 0,
(struct sockaddr *)&addr, &addrlen) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read reply %s"),
cmd);
goto error;
* in a sub-process so its hard to feed back a useful error
*/
if (stat(vm->def->os.kernel, &sb) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Cannot find UML kernel %s"),
vm->def->os.kernel);
return -1;
}
if (virFileMakePath(driver->logDir) != 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot create log directory %s"),
driver->logDir);
return -1;
if ((logfd = open(logfile, O_CREAT | O_TRUNC | O_WRONLY,
S_IRUSR | S_IWUSR)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("failed to create logfile %s"),
logfile);
VIR_FREE(logfile);
VIR_FREE(logfile);
if (umlSetCloseExec(logfd) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("Unable to set VM logfile close-on-exec flag"));
close(logfd);
return -1;
int err;
if ((err = virFileMakePath(driver->autostartDir))) {
- virReportSystemError(dom->conn, err,
+ virReportSystemError(err,
_("cannot create autostart directory %s"),
driver->autostartDir);
goto cleanup;
}
if (symlink(configFile, autostartLink) < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Failed to create symlink '%s to '%s'"),
autostartLink, configFile);
goto cleanup;
}
} else {
if (unlink(autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("Failed to delete symlink '%s'"),
autostartLink);
goto cleanup;
/* The path is correct, now try to open it and get its size. */
fd = open (path, O_RDONLY);
if (fd == -1) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("cannot open %s"), path);
goto cleanup;
}
*/
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
saferead (fd, buffer, size) == (ssize_t) -1) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("cannot read %s"), path);
goto cleanup;
}
dir = opendir(USB_SYSFS "/devices");
if (!dir) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Could not open directory %s"),
USB_SYSFS "/devices");
goto cleanup;
}
static int
-pciInitDevice(virConnectPtr conn, pciDevice *dev)
+pciInitDevice(pciDevice *dev)
{
if (pciOpenConfig(dev) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to open config space file '%s'"),
dev->path);
return -1;
return -1;
}
- if (!dev->initted && pciInitDevice(conn, dev) < 0)
+ if (!dev->initted && pciInitDevice(dev) < 0)
return -1;
/* KVM will perform FLR when starting and stopping
static int
-pciBindDeviceToStub(virConnectPtr conn, pciDevice *dev, const char *driver)
+pciBindDeviceToStub(pciDevice *dev, const char *driver)
{
char drvdir[PATH_MAX];
char path[PATH_MAX];
*/
pciDriverFile(path, sizeof(path), driver, "new_id");
if (virFileWriteStr(path, dev->id) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to add PCI device ID '%s' to %s"),
dev->id, driver);
return -1;
*/
pciDeviceFile(path, sizeof(path), dev->name, "driver/unbind");
if (virFileExists(path) && virFileWriteStr(path, dev->name) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to unbind PCI device '%s'"), dev->name);
return -1;
}
/* Xen's pciback.ko wants you to use new_slot first */
pciDriverFile(path, sizeof(path), driver, "new_slot");
if (virFileExists(path) && virFileWriteStr(path, dev->name) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to add slot for PCI device '%s' to %s"),
dev->name, driver);
return -1;
pciDriverFile(path, sizeof(path), driver, "bind");
if (virFileWriteStr(path, dev->name) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to bind PCI device '%s' to %s"),
dev->name, driver);
return -1;
*/
pciDriverFile(path, sizeof(path), driver, "remove_id");
if (virFileExists(path) && virFileWriteStr(path, dev->id) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to remove PCI ID '%s' from %s"),
dev->id, driver);
return -1;
return -1;
}
- return pciBindDeviceToStub(conn, dev, driver);
+ return pciBindDeviceToStub(dev, driver);
}
static int
-pciUnBindDeviceFromStub(virConnectPtr conn, pciDevice *dev, const char *driver)
+pciUnBindDeviceFromStub(pciDevice *dev, const char *driver)
{
char drvdir[PATH_MAX];
char path[PATH_MAX];
if (virFileExists(drvdir) && virFileLinkPointsTo(path, drvdir)) {
pciDriverFile(path, sizeof(path), driver, "unbind");
if (virFileWriteStr(path, dev->name) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to bind PCI device '%s' to %s"),
dev->name, driver);
return -1;
/* Xen's pciback.ko wants you to use remove_slot on the specific device */
pciDriverFile(path, sizeof(path), driver, "remove_slot");
if (virFileExists(path) && virFileWriteStr(path, dev->name) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to remove slot for PCI device '%s' to %s"),
dev->name, driver);
return -1;
pciDriverFile(path, sizeof(path), driver, "remove_id");
if (!virFileExists(drvdir) || virFileExists(path)) {
if (virFileWriteStr(PCI_SYSFS "drivers_probe", dev->name) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to trigger a re-probe for PCI device '%s'"),
dev->name);
return -1;
return -1;
}
- return pciUnBindDeviceFromStub(conn, dev, driver);
+ return pciUnBindDeviceFromStub(dev, driver);
}
/* Certain hypervisors (like qemu/kvm) map the PCI bar(s) on
}
if (!(dir = opendir(pcidir))) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open %s"), pcidir);
goto cleanup;
}
}
static int
-pciDeviceDownstreamLacksACS(virConnectPtr conn,
- pciDevice *dev)
+pciDeviceDownstreamLacksACS(pciDevice *dev)
{
uint16_t flags;
uint16_t ctrl;
unsigned int pos;
- if (!dev->initted && pciInitDevice(conn, dev) < 0)
+ if (!dev->initted && pciInitDevice(dev) < 0)
return -1;
pos = dev->pcie_cap_pos;
pciDevice *tmp;
int acs;
- acs = pciDeviceDownstreamLacksACS(conn, parent);
+ acs = pciDeviceDownstreamLacksACS(parent);
if (acs) {
pciFreeDevice(conn, parent);
numcpus = numcpus << 2;
goto realloc;
}
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set CPU affinity on process %d"), pid);
return -1;
}
}
if (sched_setaffinity(pid, sizeof(mask), &mask) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set CPU affinity on process %d"), pid);
return -1;
}
numcpus = numcpus << 2;
goto realloc;
}
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set CPU affinity on process %d"), pid);
return -1;
}
CPU_ZERO(&mask);
if (sched_getaffinity(pid, sizeof(mask), &mask) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set CPU affinity on process %d"), pid);
return -1;
}
size_t maplen ATTRIBUTE_UNUSED,
int maxcpu ATTRIBUTE_UNUSED)
{
- virReportSystemError(NULL, ENOSYS, "%s",
+ virReportSystemError(ENOSYS, "%s",
_("Process CPU affinity is not supported on this platform"));
return -1;
}
size_t maplen ATTRIBUTE_UNUSED,
int maxcpu ATTRIBUTE_UNUSED)
{
- virReportSystemError(NULL, ENOSYS, "%s",
+ virReportSystemError(ENOSYS, "%s",
_("Process CPU affinity is not supported on this platform"));
return -1;
}
meta->format = VIR_STORAGE_FILE_RAW;
if ((len = read(fd, head, sizeof(head))) < 0) {
- virReportSystemError(conn, errno, _("cannot read header '%s'"), path);
+ virReportSystemError(errno, _("cannot read header '%s'"), path);
return -1;
}
int fd, ret;
if ((fd = open(path, O_RDONLY)) < 0) {
- virReportSystemError(conn, errno, _("cannot open file '%s'"), path);
+ virReportSystemError(errno, _("cannot open file '%s'"), path);
return -1;
}
*/
sigfillset(&newmask);
if (pthread_sigmask(SIG_SETMASK, &newmask, &oldmask) != 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot block signals"));
return -1;
}
if ((null = open("/dev/null", O_RDONLY)) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot open %s"),
"/dev/null");
goto cleanup;
if (outfd != NULL) {
if (*outfd == -1) {
if (pipe(pipeout) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot create pipe"));
goto cleanup;
}
if ((flags & VIR_EXEC_NONBLOCK) &&
virSetNonBlock(pipeout[0]) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("Failed to set non-blocking file descriptor flag"));
goto cleanup;
}
if (virSetCloseExec(pipeout[0]) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("Failed to set close-on-exec file descriptor flag"));
goto cleanup;
}
if (errfd != NULL) {
if (*errfd == -1) {
if (pipe(pipeerr) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("Failed to create pipe"));
goto cleanup;
}
if ((flags & VIR_EXEC_NONBLOCK) &&
virSetNonBlock(pipeerr[0]) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("Failed to set non-blocking file descriptor flag"));
goto cleanup;
}
if (virSetCloseExec(pipeerr[0]) == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("Failed to set close-on-exec file descriptor flag"));
goto cleanup;
}
virLogUnlock();
if (pid < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot fork child process"));
goto cleanup;
}
/* Restore our original signal mask now child is safely
running */
if (pthread_sigmask(SIG_SETMASK, &oldmask, NULL) != 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot unblock signals"));
return -1;
}
and don't want to propagate that to children */
sigemptyset(&newmask);
if (pthread_sigmask(SIG_SETMASK, &newmask, NULL) != 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot unblock signals"));
_exit(1);
}
close(i);
if (dup2(infd >= 0 ? infd : null, STDIN_FILENO) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("failed to setup stdin file handle"));
_exit(1);
}
if (childout > 0 &&
dup2(childout, STDOUT_FILENO) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("failed to setup stdout file handle"));
_exit(1);
}
if (childerr > 0 &&
dup2(childerr, STDERR_FILENO) < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("failed to setup stderr file handle"));
_exit(1);
}
* the above errors with wait* */
if (flags & VIR_EXEC_DAEMON) {
if (setsid() < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot become session leader"));
_exit(1);
}
if (chdir("/") < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot change to root directory: %s"));
_exit(1);
}
pid = fork();
if (pid < 0) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot fork child process"));
_exit(1);
}
kill(pid, SIGTERM);
usleep(500*1000);
kill(pid, SIGTERM);
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("could not write pidfile %s for %d"),
pidfile, pid);
_exit(1);
else
execvp(argv[0], (char **) argv);
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot execute binary %s"),
argv[0]);
continue;
pollerr:
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("poll error"));
goto error;
}
while ((waitret = waitpid(childpid, &exitstatus, 0) == -1) &&
errno == EINTR);
if (waitret == -1) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot wait for '%s'"),
argv[0]);
goto error;
{
int fd = open(path, O_RDONLY);
if (fd < 0) {
- virReportSystemError(NULL, errno, _("Failed to open file '%s'"), path);
+ virReportSystemError(errno, _("Failed to open file '%s'"), path);
return -1;
}
int len = virFileReadLimFD(fd, maxlen, buf);
close(fd);
if (len < 0) {
- virReportSystemError(NULL, errno, _("Failed to read file '%s'"), path);
+ virReportSystemError(errno, _("Failed to read file '%s'"), path);
return -1;
}
if ((fd = open(path, open_flags, mode)) < 0) {
ret = errno;
- virReportSystemError(NULL, errno, _("failed to create file '%s'"),
+ virReportSystemError(errno, _("failed to create file '%s'"),
path);
goto error;
}
if (fstat(fd, &st) == -1) {
ret = errno;
- virReportSystemError(NULL, errno, _("stat of '%s' failed"), path);
+ virReportSystemError(errno, _("stat of '%s' failed"), path);
goto error;
}
if (((st.st_uid != uid) || (st.st_gid != gid))
&& (fchown(fd, uid, gid) < 0)) {
ret = errno;
- virReportSystemError(NULL, errno, _("cannot chown '%s' to (%u, %u)"),
+ virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"),
path, uid, gid);
goto error;
}
if (fchmod(fd, mode) < 0) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set mode of '%s' to %04o"),
path, mode);
goto error;
}
if (close(fd) < 0) {
ret = errno;
- virReportSystemError(NULL, errno, _("failed to close new file '%s'"),
+ virReportSystemError(errno, _("failed to close new file '%s'"),
path);
fd = -1;
goto error;
&& !((errno == EEXIST) && (flags & VIR_FILE_CREATE_ALLOW_EXIST)))
{
ret = errno;
- virReportSystemError(NULL, errno, _("failed to create directory '%s'"),
+ virReportSystemError(errno, _("failed to create directory '%s'"),
path);
goto error;
}
if (stat(path, &st) == -1) {
ret = errno;
- virReportSystemError(NULL, errno, _("stat of '%s' failed"), path);
+ virReportSystemError(errno, _("stat of '%s' failed"), path);
goto error;
}
if (((st.st_uid != uid) || (st.st_gid != gid))
&& (chown(path, uid, gid) < 0)) {
ret = errno;
- virReportSystemError(NULL, errno, _("cannot chown '%s' to (%u, %u)"),
+ virReportSystemError(errno, _("cannot chown '%s' to (%u, %u)"),
path, uid, gid);
goto error;
}
if (chmod(path, mode) < 0) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set mode of '%s' to %04o"),
path, mode);
goto error;
if (pid < 0) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot fork o create file '%s'"), path);
return ret;
}
&& (errno == EINTR));
if (waitret == -1) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("failed to wait for child creating '%s'"),
path);
goto parenterror;
* setgid. If not, try doing it with chown */
if (stat(path, &st) == -1) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("stat of '%s' failed"),
path);
goto parenterror;
}
if ((st.st_gid != gid) && (chown(path, -1, gid) < 0)) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot chown '%s' to group %u"),
path, gid);
goto parenterror;
}
if (chmod(path, mode) < 0) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set mode of '%s' to %04o"),
path, mode);
goto parenterror;
if ((gid != 0) && (setgid(gid) != 0)) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set gid %u creating '%s'"),
gid, path);
goto childerror;
}
if ((uid != 0) && (setuid(uid) != 0)) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set uid %u creating '%s'"),
uid, path);
goto childerror;
ret = errno;
if (ret != EACCES) {
/* in case of EACCES, the parent will retry */
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("child failed to create file '%s'"),
path);
}
}
if (close(fd) < 0) {
ret = errno;
- virReportSystemError(NULL, errno, _("child failed to close new file '%s'"),
+ virReportSystemError(errno, _("child failed to close new file '%s'"),
path);
goto childerror;
}
if (pid < 0) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot fork to create directory '%s'"),
path);
return ret;
while ((waitret = waitpid(pid, &status, 0) == -1) && (errno == EINTR));
if (waitret == -1) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("failed to wait for child creating '%s'"),
path);
goto parenterror;
* setgid. If not, try doing it with chown */
if (stat(path, &st) == -1) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("stat of '%s' failed"),
path);
goto parenterror;
}
if ((st.st_gid != gid) && (chown(path, -1, gid) < 0)) {
ret = errno;
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot chown '%s' to group %u"),
path, gid);
goto parenterror;
}
if (chmod(path, mode) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot set mode of '%s' to %04o"),
path, mode);
goto parenterror;
if ((gid != 0) && (setgid(gid) != 0)) {
ret = errno;
- virReportSystemError(NULL, errno, _("cannot set gid %u creating '%s'"),
+ virReportSystemError(errno, _("cannot set gid %u creating '%s'"),
gid, path);
goto childerror;
}
if ((uid != 0) && (setuid(uid) != 0)) {
ret = errno;
- virReportSystemError(NULL, errno, _("cannot set uid %u creating '%s'"),
+ virReportSystemError(errno, _("cannot set uid %u creating '%s'"),
uid, path);
goto childerror;
}
ret = errno;
if (ret != EACCES) {
/* in case of EACCES, the parent will retry */
- virReportSystemError(NULL, errno, _("child failed to create directory '%s'"),
+ virReportSystemError(errno, _("child failed to create directory '%s'"),
path);
}
goto childerror;
r = gethostname (hostname, sizeof(hostname));
if (r == -1) {
- virReportSystemError (conn, errno,
- "%s", _("failed to determine host name"));
+ virReportSystemError(errno,
+ "%s", _("failed to determine host name"));
return NULL;
}
NUL_TERMINATE(hostname);
VIR_USER_ENT_NAME,
};
-static char *virGetUserEnt(virConnectPtr conn,
- uid_t uid,
+static char *virGetUserEnt(uid_t uid,
int field)
{
char *strbuf;
size_t strbuflen = val;
if (val < 0) {
- virReportSystemError(conn, errno, "%s", _("sysconf failed"));
+ virReportSystemError(errno, "%s", _("sysconf failed"));
return NULL;
}
* The given name or uid was not found.
*/
if (getpwuid_r(uid, &pwbuf, strbuf, strbuflen, &pw) != 0 || pw == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to find user record for uid '%d'"),
uid);
VIR_FREE(strbuf);
return ret;
}
-char *virGetUserDirectory(virConnectPtr conn,
+char *virGetUserDirectory(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
uid_t uid)
{
- return virGetUserEnt(conn, uid, VIR_USER_ENT_DIRECTORY);
+ return virGetUserEnt(uid, VIR_USER_ENT_DIRECTORY);
}
-char *virGetUserName(virConnectPtr conn,
+char *virGetUserName(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
uid_t uid)
{
- return virGetUserEnt(conn, uid, VIR_USER_ENT_NAME);
+ return virGetUserEnt(uid, VIR_USER_ENT_NAME);
}
-int virGetUserID(virConnectPtr conn,
+int virGetUserID(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
const char *name,
uid_t *uid)
{
size_t strbuflen = val;
if (val < 0) {
- virReportSystemError(conn, errno, "%s", _("sysconf failed"));
+ virReportSystemError(errno, "%s", _("sysconf failed"));
return -1;
}
* The given name or uid was not found.
*/
if (getpwnam_r(name, &pwbuf, strbuf, strbuflen, &pw) != 0 || pw == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to find user record for name '%s'"),
name);
VIR_FREE(strbuf);
}
-int virGetGroupID(virConnectPtr conn,
+int virGetGroupID(virConnectPtr conn ATTRIBUTE_UNUSED /*TEMPORARY*/,
const char *name,
gid_t *gid)
{
size_t strbuflen = val;
if (val < 0) {
- virReportSystemError(conn, errno, "%s", _("sysconf failed"));
+ virReportSystemError(errno, "%s", _("sysconf failed"));
return -1;
}
* The given name or uid was not found.
*/
if (getgrnam_r(name, &grbuf, strbuf, strbuflen, &gr) != 0 || gr == NULL) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("Failed to find group record for name '%s'"),
name);
VIR_FREE(strbuf);
/**
* virReportSystemErrorFull:
- * @conn: the hyperisor connection
* @domcode: the virErrorDomain indicating where it's coming from
* @theerrno: an errno number
* @filename: filename where error was raised
*
* Convenience internal routine called when a system error is detected.
*/
-void virReportSystemErrorFull(virConnectPtr conn,
- int domcode,
+void virReportSystemErrorFull(int domcode,
int theerrno,
const char *filename,
const char *funcname,
if (!msgDetail)
msgDetail = errnoDetail;
- virRaiseErrorFull(conn, filename, funcname, linenr,
+ virRaiseErrorFull(NULL, filename, funcname, linenr,
domcode, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR,
msg, msgDetail, NULL, -1, -1, msg, msgDetail);
}
const char *fmt, ...)
ATTRIBUTE_FMT_PRINTF(7, 8);
-void virReportSystemErrorFull(virConnectPtr conn,
- int domcode,
+void virReportSystemErrorFull(int domcode,
int theerrno,
const char *filename,
const char *funcname,
size_t linenr,
const char *fmt, ...)
- ATTRIBUTE_FMT_PRINTF(7, 8);
+ ATTRIBUTE_FMT_PRINTF(6, 7);
-#define virReportSystemError(conn, theerrno, fmt,...) \
- virReportSystemErrorFull((conn), \
- VIR_FROM_THIS, \
+#define virReportSystemError(theerrno, fmt,...) \
+ virReportSystemErrorFull(VIR_FROM_THIS, \
(theerrno), \
__FILE__, __FUNCTION__, __LINE__, \
(fmt), __VA_ARGS__)
request->len);
if (ret < 0) {
if (!quiet)
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("failed to write proxy request"));
goto error;
}
sizeof(virProxyPacket));
if (ret < 0) {
if (!quiet)
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("failed to read proxy reply"));
goto error;
}
sizeof(virProxyPacket));
if (ret < 0) {
if (!quiet)
- virReportSystemError(conn, errno, "%s",
+ virReportSystemError(errno, "%s",
_("failed to read proxy reply"));
goto error;
}
if ((fd = open("/dev/cpu/self/cpuid", O_RDONLY)) == -1 ||
pread(fd, ®s, sizeof(regs), 0) != sizeof(regs)) {
- virReportSystemError(conn, errno, "%s", _("could not read CPU flags"));
+ virReportSystemError(errno, "%s", _("could not read CPU flags"));
goto out;
}
cpuinfo = fopen ("/proc/cpuinfo", "r");
if (cpuinfo == NULL) {
if (errno != ENOENT) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read file %s"),
"/proc/cpuinfo");
return NULL;
if (capabilities == NULL) {
if (errno != ENOENT) {
fclose(cpuinfo);
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read file %s"),
"/sys/hypervisor/properties/capabilities");
return NULL;
/* populate initial list */
if (!(dh = opendir(priv->configDir))) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("cannot open directory: %s"),
priv->configDir);
return -1;
}
if ((priv->inotifyFD = inotify_init()) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
"%s", _("initializing inotify"));
return -1;
}
IN_CREATE |
IN_CLOSE_WRITE | IN_DELETE |
IN_MOVED_TO | IN_MOVED_FROM) < 0) {
- virReportSystemError(NULL, errno,
+ virReportSystemError(errno,
_("adding watch on %s"),
priv->configDir);
return -1;
if (!priv->addrlen) {
/* Don't raise error when unprivileged, since proxy takes over */
if (xenHavePrivilege())
- virReportSystemError(conn, saved_errno,
+ virReportSystemError(saved_errno,
_("unable to connect to '%s:%s'"),
host, port);
return -1;
/* The path is correct, now try to open it and get its size. */
fd = open (path, O_RDONLY);
if (fd == -1) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("failed to open for reading: %s"),
path);
goto cleanup;
*/
if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
saferead (fd, buffer, size) == (ssize_t) -1) {
- virReportSystemError(domain->conn, errno,
+ virReportSystemError(errno,
_("failed to lseek or read from file: %s"),
path);
goto cleanup;
/* Get modified time */
if ((stat(filename, &st) < 0)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot stat: %s"),
filename);
return -1;
struct xenXMConfigReaperData args;
if (now == ((time_t)-1)) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
"%s", _("cannot get time of day"));
return (-1);
}
/* Process the files in the config dir */
if (!(dh = opendir(priv->configDir))) {
- virReportSystemError(conn, errno,
+ virReportSystemError(errno,
_("cannot read directory %s"),
priv->configDir);
return (-1);
*autostart = virFileLinkPointsTo(linkname, config);
if (*autostart < 0) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("cannot check link %s points to config %s"),
linkname, config);
goto cleanup;
if (autostart) {
if (symlink(config, linkname) < 0 &&
errno != EEXIST) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("failed to create link %s to %s"),
config, linkname);
goto cleanup;
} else {
if (unlink(linkname) < 0 &&
errno != ENOENT) {
- virReportSystemError(dom->conn, errno,
+ virReportSystemError(errno,
_("failed to remove link %s"),
linkname);
goto cleanup;