diff --git a/src/openvz_conf.c b/src/openvz_conf.c index ff3d607..9381410 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -634,6 +634,32 @@ static char return NULL; } +/* Return 0 if we can access and read file /etc/vz/conf/ve-$name.conf-sample + * Return -1 on error */ +int +openvzAccessDefaultProfile(const char *ostemplate) +{ + char *profile; + int ret = -1; + char *confdir = openvzLocateConfDir(); + virBuffer buf = VIR_BUFFER_INITIALIZER; + + if (confdir == NULL) + return ret; + + virBufferVSprintf(&buf, "%s/ve-%s.conf-sample", confdir, ostemplate); + if (virBufferError(&buf)) + return ret; + + profile = virBufferContentAndReset(&buf); + if (profile != NULL) { + ret = access(profile, F_OK); + VIR_FREE(profile); + } + + return ret; +} + /* Richard Steven's classic readline() function */ int openvz_readline(int fd, char *ptr, int maxlen) diff --git a/src/openvz_conf.h b/src/openvz_conf.h index 8e02056..8919d4b 100644 --- a/src/openvz_conf.h +++ b/src/openvz_conf.h @@ -64,5 +64,6 @@ void openvzFreeDriver(struct openvz_driver *driver); int strtoI(const char *str); int openvzSetDefinedUUID(int vpsid, unsigned char *uuid); unsigned int openvzGetNodeCPUs(void); +int openvzAccessDefaultProfile(const char *ostemplate); #endif /* OPENVZ_CONF_H */ diff --git a/src/openvz_driver.c b/src/openvz_driver.c index d6c4362..7ab9309 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -133,6 +133,8 @@ static int openvzDomainDefineCmd(virConnectPtr conn, ADD_ARG_LIT(vmdef->name); if (vmdef->nfss) { + char *ostemplate; + if (vmdef->fss[0]->type != VIR_DOMAIN_FS_TYPE_TEMPLATE) { openvzError(conn, VIR_ERR_INTERNAL_ERROR, "%s", _("only filesystem templates are supported")); @@ -145,15 +147,15 @@ static int openvzDomainDefineCmd(virConnectPtr conn, return -1; } + ostemplate = vmdef->fss[0]->src; ADD_ARG_LIT("--ostemplate"); - ADD_ARG_LIT(vmdef->fss[0]->src); - } -#if 0 - if ((vmdef->profile && *(vmdef->profile))) { - ADD_ARG_LIT("--config"); - ADD_ARG_LIT(vmdef->profile); + ADD_ARG_LIT(ostemplate); + + if (openvzAccessDefaultProfile(ostemplate) != -1) { + ADD_ARG_LIT("--config"); + ADD_ARG_LIT(ostemplate); + } } -#endif ADD_ARG(NULL); return 0;