提交 47010f35 编写于 作者: D Daniel Veillard

* src/openvz_conf.c src/openvz_conf.h src/openvz_driver.c: new

  patch from Evgeniy Sokolov adding OpenVZ autostart get and set support
Daniel
上级 a626719f
Thu Jul 10 09:50:39 CEST 2008 Daniel Veillard <veillard@redhat.com>
* src/openvz_conf.c src/openvz_conf.h src/openvz_driver.c: new
patch from Evgeniy Sokolov adding OpenVZ autostart get and set support
Wed Jul 9 13:53:25 CEST 2008 Daniel Veillard <veillard@redhat.com> Wed Jul 9 13:53:25 CEST 2008 Daniel Veillard <veillard@redhat.com>
* src/openvz_conf.c src/openvz_conf.h src/openvz_driver.c: applied * src/openvz_conf.c src/openvz_conf.h src/openvz_driver.c: applied
......
...@@ -603,6 +603,63 @@ error: ...@@ -603,6 +603,63 @@ error:
return NULL; return NULL;
} }
/*
* Read parameter from container config
* sample: 133, "OSTEMPLATE", value, 1024
* return: -1 - error
* 0 - don't found
* 1 - OK
*/
int
openvzReadConfigParam(int vpsid ,const char * param, char *value, int maxlen)
{
char conf_file[PATH_MAX] ;
char line[PATH_MAX] ;
int ret, found = 0;
char * conf_dir;
int fd ;
char * sf, * token;
char *saveptr = NULL;
conf_dir = openvzLocateConfDir();
if (conf_dir == NULL)
return -1;
if (snprintf(conf_file, PATH_MAX,"%s/%d.conf",conf_dir,vpsid) >= PATH_MAX)
return -1;
VIR_FREE(conf_dir);
value[0] = 0;
fd = open(conf_file, O_RDONLY);
if (fd == -1)
return -1;
while(1) {
ret = openvz_readline(fd, line, sizeof(line));
if(ret <= 0)
break;
saveptr = NULL;
if (STREQLEN(line, param, strlen(param))) {
sf = line;
sf += strlen(param);
if (sf[0] == '=' && (token = strtok_r(sf,"\"\t=\n", &saveptr)) != NULL) {
strncpy(value, token, maxlen) ;
value[maxlen-1] = '\0';
found = 1;
}
}
}
close(fd);
if (ret == 0 && found)
ret = 1;
return ret ;
}
static char static char
*openvzLocateConfDir(void) *openvzLocateConfDir(void)
{ {
...@@ -680,6 +737,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr) ...@@ -680,6 +737,8 @@ openvzGetVPSUUID(int vpsid, char *uuidstr)
break; break;
} }
} }
close(fd);
return 0; return 0;
} }
......
...@@ -112,6 +112,7 @@ openvzIsActiveVM(struct openvz_vm *vm) ...@@ -112,6 +112,7 @@ openvzIsActiveVM(struct openvz_vm *vm)
void error (virConnectPtr conn, virErrorNumber code, const char *fmt, ...); void error (virConnectPtr conn, virErrorNumber code, const char *fmt, ...);
int openvz_readline(int fd, char *ptr, int maxlen); int openvz_readline(int fd, char *ptr, int maxlen);
int openvzReadConfigParam(int vpsid ,const char * param, char *value, int maxlen);
struct openvz_vm *openvzFindVMByID(const struct openvz_driver *driver, int id); struct openvz_vm *openvzFindVMByID(const struct openvz_driver *driver, int id);
struct openvz_vm *openvzFindVMByUUID(const struct openvz_driver *driver, struct openvz_vm *openvzFindVMByUUID(const struct openvz_driver *driver,
const unsigned char *uuid); const unsigned char *uuid);
......
...@@ -547,6 +547,54 @@ bail_out5: ...@@ -547,6 +547,54 @@ bail_out5:
return ret; return ret;
} }
static int
openvzDomainSetAutostart(virDomainPtr dom, int autostart)
{
virConnectPtr conn= dom->conn;
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
struct openvz_vm *vm = openvzFindVMByUUID(driver, dom->uuid);
const char *prog[] = { VZCTL, "set", vm->vmdef->name,
"--onboot", autostart ? "yes" : "no",
"--save", NULL };
if (!vm) {
error(conn, VIR_ERR_INVALID_DOMAIN, _("no domain with matching uuid"));
return -1;
}
if (virRun(conn, (char **)prog, NULL) < 0) {
error(conn, VIR_ERR_INTERNAL_ERROR, _("Could not exec %s"), VZCTL);
return -1;
}
return 0;
}
static int
openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
{
virConnectPtr conn= dom->conn;
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
struct openvz_vm *vm = openvzFindVMByUUID(driver, dom->uuid);
char value[1024];
if (!vm) {
error(conn, VIR_ERR_INVALID_DOMAIN, _("no domain with matching uuid"));
return -1;
}
if (openvzReadConfigParam(vm->vpsid , "ONBOOT", value, sizeof(value)) < 0) {
error(conn, VIR_ERR_INTERNAL_ERROR, _("Cound not read container config"));
return -1;
}
*autostart = 0;
if (STREQ(value,"yes"))
*autostart = 1;
return 0;
}
static const char *openvzProbe(void) static const char *openvzProbe(void)
{ {
#ifdef __linux__ #ifdef __linux__
...@@ -748,8 +796,8 @@ static virDriver openvzDriver = { ...@@ -748,8 +796,8 @@ static virDriver openvzDriver = {
openvzDomainUndefine, /* domainUndefine */ openvzDomainUndefine, /* domainUndefine */
NULL, /* domainAttachDevice */ NULL, /* domainAttachDevice */
NULL, /* domainDetachDevice */ NULL, /* domainDetachDevice */
NULL, /* domainGetAutostart */ openvzDomainGetAutostart, /* domainGetAutostart */
NULL, /* domainSetAutostart */ openvzDomainSetAutostart, /* domainSetAutostart */
NULL, /* domainGetSchedulerType */ NULL, /* domainGetSchedulerType */
NULL, /* domainGetSchedulerParameters */ NULL, /* domainGetSchedulerParameters */
NULL, /* domainSetSchedulerParameters */ NULL, /* domainSetSchedulerParameters */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册