Implemented functions domainSetAutostart and domainGetAutostart. other: fixed closing file descriptor during reading uuid from config.
Index: src/openvz_conf.c =================================================================== RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.25 diff -u -p -r1.25 openvz_conf.c --- src/openvz_conf.c 12 Jun 2008 13:48:29 -0000 1.25 +++ src/openvz_conf.c 8 Jul 2008 13:49:25 -0000 @@ -595,6 +595,61 @@ error: 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; + + sprintf(conf_file,"%s/%d.conf",conf_dir,vpsid); + VIR_FREE(conf_dir); + + value[0] = 0; + + fd = open(conf_file, O_RDWR); + 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) ; + found = 1; + } + } + } + close(fd); + + if (ret == 0 && found) + ret = 1; + + return ret ; +} + + static char *openvzLocateConfDir(void) { @@ -672,6 +727,8 @@ openvzGetVPSUUID(int vpsid, char *uuidst break; } } + close(fd); + return 0; } Index: src/openvz_conf.h =================================================================== RCS file: /data/cvs/libvirt/src/openvz_conf.h,v retrieving revision 1.6 diff -u -p -r1.6 openvz_conf.h --- src/openvz_conf.h 5 Feb 2008 19:27:37 -0000 1.6 +++ src/openvz_conf.h 8 Jul 2008 13:49:25 -0000 @@ -111,6 +111,7 @@ openvzIsActiveVM(struct openvz_vm *vm) } 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 *openvzFindVMByUUID(const struct openvz_driver *driver, const unsigned char *uuid); Index: src/openvz_driver.c =================================================================== RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.23 diff -u -p -r1.23 openvz_driver.c --- src/openvz_driver.c 7 Jul 2008 11:48:40 -0000 1.23 +++ src/openvz_driver.c 8 Jul 2008 13:49:26 -0000 @@ -552,6 +552,67 @@ bail_out5: return ret; } +static int +openvzDomainSetAutostart(virDomainPtr dom, int autostart) +{ + char cmdbuf[CMDBUF_LEN], *cmdExec[OPENVZ_MAX_ARG]; + int ret, pid, outfd, errfd; + virConnectPtr conn= dom->conn; + struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; + struct openvz_vm *vm = openvzFindVMByUUID(driver, dom->uuid); + + if (!vm) { + error(conn, VIR_ERR_INVALID_DOMAIN, _("no domain with matching uuid")); + return -1; + } + + snprintf(cmdbuf, CMDBUF_LEN - 1, VZCTL " set %s --onboot %s --save", vm->vmdef->name, + autostart ? "yes" : "no"); + + if((ret = convCmdbufExec(cmdbuf, cmdExec)) == -1) + { + openvzLog(OPENVZ_ERR, "%s", _("Error in parsing Options to OPENVZ")); + goto bail_out5; + } + ret = virExec(conn, (char **)cmdExec, &pid, -1, &outfd, &errfd); + if(ret == -1) { + error(conn, VIR_ERR_INTERNAL_ERROR, "Could not exec " VZCTL); + return -1; + } + + waitpid(pid, NULL, 0); +bail_out5: + cmdExecFree(cmdExec); + return ret; +} + +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) { + openvzLog(OPENVZ_ERR, "%s", _("Cound not read container config")); + return -1; + } + + *autostart = 0; + if (STREQ(value,"yes")) + *autostart = 1; + + return 0; +} + + + static const char *openvzProbe(void) { #ifdef __linux__ @@ -751,8 +812,8 @@ static virDriver openvzDriver = { openvzDomainUndefine, /* domainUndefine */ NULL, /* domainAttachDevice */ NULL, /* domainDetachDevice */ - NULL, /* domainGetAutostart */ - NULL, /* domainSetAutostart */ + openvzDomainGetAutostart, /* domainGetAutostart */ + openvzDomainSetAutostart, /* domainSetAutostart */ NULL, /* domainGetSchedulerType */ NULL, /* domainGetSchedulerParameters */ NULL, /* domainSetSchedulerParameters */
-- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list