mirror of https://gitee.com/openkylin/libvirt.git
OpenVZ Fix a restriction about domain names
* src/openvz/openvz_driver.c: try to autogenerate a non-conflicting id for the domain and use the name field as the name not as id.
This commit is contained in:
parent
24e0171b86
commit
0c85095e46
|
@ -95,12 +95,16 @@ static void cmdExecFree(const char *cmdExec[])
|
||||||
return -1 - error
|
return -1 - error
|
||||||
0 - OK
|
0 - OK
|
||||||
*/
|
*/
|
||||||
static int openvzDomainDefineCmd(virConnectPtr conn,
|
static int
|
||||||
|
openvzDomainDefineCmd(virConnectPtr conn,
|
||||||
const char *args[],
|
const char *args[],
|
||||||
int maxarg,
|
int maxarg, virDomainDefPtr vmdef)
|
||||||
virDomainDefPtr vmdef)
|
|
||||||
{
|
{
|
||||||
int narg;
|
int narg;
|
||||||
|
int veid;
|
||||||
|
int max_veid;
|
||||||
|
char str_id[10];
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
for (narg = 0; narg < maxarg; narg++)
|
for (narg = 0; narg < maxarg; narg++)
|
||||||
args[narg] = NULL;
|
args[narg] = NULL;
|
||||||
|
@ -110,7 +114,6 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
|
||||||
"%s", _("Container is not defined"));
|
"%s", _("Container is not defined"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADD_ARG(thisarg) \
|
#define ADD_ARG(thisarg) \
|
||||||
do { \
|
do { \
|
||||||
if (narg >= maxarg) \
|
if (narg >= maxarg) \
|
||||||
|
@ -130,11 +133,42 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
|
||||||
ADD_ARG_LIT(VZCTL);
|
ADD_ARG_LIT(VZCTL);
|
||||||
ADD_ARG_LIT("--quiet");
|
ADD_ARG_LIT("--quiet");
|
||||||
ADD_ARG_LIT("create");
|
ADD_ARG_LIT("create");
|
||||||
|
|
||||||
|
if ((fp = popen(VZLIST " -a -ovpsid -H 2>/dev/null", "r")) == NULL) {
|
||||||
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
|
_("popen failed"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
max_veid = 0;
|
||||||
|
while (!feof(fp)) {
|
||||||
|
if (fscanf(fp, "%d\n", &veid) != 1) {
|
||||||
|
if (feof(fp))
|
||||||
|
break;
|
||||||
|
|
||||||
|
openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"%s", _("Failed to parse vzlist output"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
if (veid > max_veid) {
|
||||||
|
max_veid = veid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
if (max_veid == 0) {
|
||||||
|
max_veid = 100;
|
||||||
|
} else {
|
||||||
|
max_veid++;
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(str_id, "%d", max_veid++);
|
||||||
|
ADD_ARG_LIT(str_id);
|
||||||
|
|
||||||
|
ADD_ARG_LIT("--name");
|
||||||
ADD_ARG_LIT(vmdef->name);
|
ADD_ARG_LIT(vmdef->name);
|
||||||
|
|
||||||
if (vmdef->nfss == 1 &&
|
if (vmdef->nfss == 1 &&
|
||||||
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE)
|
vmdef->fss[0]->type == VIR_DOMAIN_FS_TYPE_TEMPLATE) {
|
||||||
{
|
|
||||||
ADD_ARG_LIT("--ostemplate");
|
ADD_ARG_LIT("--ostemplate");
|
||||||
ADD_ARG_LIT(vmdef->fss[0]->src);
|
ADD_ARG_LIT(vmdef->fss[0]->src);
|
||||||
}
|
}
|
||||||
|
@ -147,10 +181,16 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
|
||||||
|
|
||||||
ADD_ARG(NULL);
|
ADD_ARG(NULL);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
openvzError(conn, VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Could not put argument to %s"), VZCTL);
|
_("Could not put argument to %s"), VZCTL);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
fclose(fp);
|
||||||
|
return -1;
|
||||||
|
|
||||||
#undef ADD_ARG
|
#undef ADD_ARG
|
||||||
#undef ADD_ARG_LIT
|
#undef ADD_ARG_LIT
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue