mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
Tue Feb 14 14:52:12 EST 2007 Mark McLoughlin <markmc@redhat.com
* qemud/conf.c: Re-factor bits of conf.c so that: - qemudMakeConfigPath() can be re-used given another configDir - split qemudEnsureConfigDir() out of qemudSaveConfig() so that it may be re-used to create another configDir - split qemudScanConfigDir() out so that qemudScanConfigs() can scan multiple configDirs
This commit is contained in:
parent
bf46e15b2c
commit
fbc08f063c
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Tue Feb 14 14:52:12 EST 2007 Mark McLoughlin <markmc@redhat.com
|
||||||
|
|
||||||
|
* qemud/conf.c: Re-factor bits of conf.c so that:
|
||||||
|
|
||||||
|
- qemudMakeConfigPath() can be re-used given another configDir
|
||||||
|
- split qemudEnsureConfigDir() out of qemudSaveConfig() so
|
||||||
|
that it may be re-used to create another configDir
|
||||||
|
- split qemudScanConfigDir() out so that qemudScanConfigs()
|
||||||
|
can scan multiple configDirs
|
||||||
|
|
||||||
Tue Feb 14 14:50:22 EST 2007 Mark McLoughlin <markmc@redhat.com
|
Tue Feb 14 14:50:22 EST 2007 Mark McLoughlin <markmc@redhat.com
|
||||||
|
|
||||||
* qemud/conf.c: handle an unspecified MAC address,
|
* qemud/conf.c: handle an unspecified MAC address,
|
||||||
|
106
qemud/conf.c
106
qemud/conf.c
@ -93,6 +93,55 @@ static int qemudParseUUID(const char *uuid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Build up a fully qualfiied path for a config file to be
|
||||||
|
* associated with a persistent guest or network */
|
||||||
|
static int
|
||||||
|
qemudMakeConfigPath(const char *configDir,
|
||||||
|
const char *name,
|
||||||
|
const char *ext,
|
||||||
|
char *buf,
|
||||||
|
unsigned int buflen) {
|
||||||
|
if ((strlen(configDir) + 1 + strlen(name) + (ext ? strlen(ext) : 0) + 1) > buflen)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
strcpy(buf, configDir);
|
||||||
|
strcat(buf, "/");
|
||||||
|
strcat(buf, name);
|
||||||
|
if (ext)
|
||||||
|
strcat(buf, ext);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemudEnsureConfigDir(struct qemud_server *server,
|
||||||
|
const char *configDir) {
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
|
/* XXX: needs to be recursive */
|
||||||
|
|
||||||
|
if (stat(configDir, &sb) < 0) {
|
||||||
|
if (errno == ENOENT) {
|
||||||
|
if (mkdir(configDir, 0700) < 0) {
|
||||||
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"cannot create config directory %s: %s",
|
||||||
|
configDir, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"cannot stat config directory %s",
|
||||||
|
configDir, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else if (!S_ISDIR(sb.st_mode)) {
|
||||||
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"config directory %s is not a directory", configDir);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct qemu_arch_info {
|
struct qemu_arch_info {
|
||||||
const char *arch;
|
const char *arch;
|
||||||
const char **machines;
|
const char **machines;
|
||||||
@ -928,57 +977,19 @@ void qemudFreeVM(struct qemud_vm *vm) {
|
|||||||
free(vm);
|
free(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Build up a fully qualified path for a config file to be
|
|
||||||
* associated with a persistent guest */
|
|
||||||
static
|
|
||||||
int qemudMakeConfigPath(struct qemud_server *server,
|
|
||||||
const char *name,
|
|
||||||
const char *ext,
|
|
||||||
char *buf,
|
|
||||||
unsigned int buflen) {
|
|
||||||
if ((strlen(server->configDir) + 1 + strlen(name) + (ext ? strlen(ext) : 0) + 1) > buflen)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
strcpy(buf, server->configDir);
|
|
||||||
strcat(buf, "/");
|
|
||||||
strcat(buf, name);
|
|
||||||
if (ext)
|
|
||||||
strcat(buf, ext);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Save a guest's config data into a persistent file */
|
/* Save a guest's config data into a persistent file */
|
||||||
static int qemudSaveConfig(struct qemud_server *server,
|
static int qemudSaveConfig(struct qemud_server *server,
|
||||||
struct qemud_vm *vm) {
|
struct qemud_vm *vm) {
|
||||||
char *xml;
|
char *xml;
|
||||||
int fd = -1, ret = -1;
|
int fd = -1, ret = -1;
|
||||||
int towrite;
|
int towrite;
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
if (!(xml = qemudGenerateXML(server, vm))) {
|
if (!(xml = qemudGenerateXML(server, vm))) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(server->configDir, &sb) < 0) {
|
if (qemudEnsureConfigDir(server, server->configDir) < 0) {
|
||||||
if (errno == ENOENT) {
|
goto cleanup;
|
||||||
if (mkdir(server->configDir, 0700) < 0) {
|
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"cannot create config directory %s",
|
|
||||||
server->configDir);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"cannot stat config directory %s",
|
|
||||||
server->configDir);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if (!S_ISDIR(sb.st_mode)) {
|
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
|
||||||
"config directory %s is not a directory",
|
|
||||||
server->configDir);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(vm->configFile,
|
if ((fd = open(vm->configFile,
|
||||||
@ -1068,7 +1079,7 @@ struct qemud_vm *qemudLoadConfigXML(struct qemud_server *server,
|
|||||||
vm->configFile[PATH_MAX-1] = '\0';
|
vm->configFile[PATH_MAX-1] = '\0';
|
||||||
} else {
|
} else {
|
||||||
if (save) {
|
if (save) {
|
||||||
if (qemudMakeConfigPath(server, vm->def.name, ".xml", vm->configFile, PATH_MAX) < 0) {
|
if (qemudMakeConfigPath(server->configDir, vm->def.name, ".xml", vm->configFile, PATH_MAX) < 0) {
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
"cannot construct config file path");
|
"cannot construct config file path");
|
||||||
qemudFreeVM(vm);
|
qemudFreeVM(vm);
|
||||||
@ -1131,12 +1142,13 @@ static void qemudLoadConfig(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Scan for all guest config files */
|
static
|
||||||
int qemudScanConfigs(struct qemud_server *server) {
|
int qemudScanConfigDir(struct qemud_server *server,
|
||||||
|
const char *configDir) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
|
||||||
if (!(dir = opendir(server->configDir))) {
|
if (!(dir = opendir(configDir))) {
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
return 0;
|
return 0;
|
||||||
return -1;
|
return -1;
|
||||||
@ -1147,7 +1159,7 @@ int qemudScanConfigs(struct qemud_server *server) {
|
|||||||
if (entry->d_name[0] == '.')
|
if (entry->d_name[0] == '.')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (qemudMakeConfigPath(server, entry->d_name, NULL, file, PATH_MAX) < 0)
|
if (qemudMakeConfigPath(configDir, entry->d_name, NULL, file, PATH_MAX) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
qemudLoadConfig(server, file);
|
qemudLoadConfig(server, file);
|
||||||
@ -1158,6 +1170,10 @@ int qemudScanConfigs(struct qemud_server *server) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Scan for all guest and network config files */
|
||||||
|
int qemudScanConfigs(struct qemud_server *server) {
|
||||||
|
return qemudScanConfigDir(server, server->configDir);
|
||||||
|
}
|
||||||
|
|
||||||
/* Simple grow-on-demand string buffer */
|
/* Simple grow-on-demand string buffer */
|
||||||
/* XXX re-factor to shared library */
|
/* XXX re-factor to shared library */
|
||||||
|
Loading…
Reference in New Issue
Block a user