Re: [libvirt] Re: OpenVZ : The restriction of domain name should be addressed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Daniel

Fixed patch according to your comments in openvzDomainDefineCmd func.

--- a/src/openvz_driver.c
+++ b/src/openvz_driver.c
@@ -101,6 +101,9 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
                                 virDomainDefPtr vmdef)
{
    int narg;
+    int veid;
+    int max_veid;
+    FILE *fp;

    for (narg = 0; narg < maxarg; narg++)
        args[narg] = NULL;
@@ -130,6 +133,38 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
    ADD_ARG_LIT(VZCTL);
    ADD_ARG_LIT("--quiet");
    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++;
+    }
+
+    char str_id[10];
+    sprintf( str_id, "%d", max_veid++ );
+    ADD_ARG_LIT(str_id);
+
+    ADD_ARG_LIT("--name");
    ADD_ARG_LIT(vmdef->name);

    if (vmdef->nfss == 1 &&
@@ -151,6 +186,11 @@ static int openvzDomainDefineCmd(virConnectPtr conn,
    openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                _("Could not put argument to %s"), VZCTL);
    return -1;
+
+  cleanup:
+    fclose(fp);
+    return -1;
+
#undef ADD_ARG
#undef ADD_ARG_LIT
}



-----
Yuji Nishida
nishidy@xxxxxxxxxx

On 2009/09/15, at 18:59, Daniel P. Berrange wrote:

On Tue, Sep 15, 2009 at 03:40:09PM +0900, Yuji NISHIDA wrote:
Hi Daniel,

I didn't realize that I even did not follow the manner of XML.
I have worked with this problem and got a small patch to handle "ID"
in OpenVZ functionality.
I found it is working well with the XML script included "ID" in domain
tag.

I am concerned that I had to edit the common file domain_conf.c.
I still believe I should keep it away from this problem for
compatibility with the others.
How do you think can I avoid this?

The 'id' value is not intended to be settable by the end user,
which is why the domain_conf.c parser does not parse it by
default.

So for your usage in OpenVZ, you'll need to auto-assign an 'id'
value when creating a new guest. eg, get a list of existing
OpenVZ guest 'id' values and then pick the first one which is
not used.

diff --git a/src/openvz_driver.c b/src/openvz_driver.c
index a8c24ba..c0c1e0f 100644
--- a/src/openvz_driver.c
+++ b/src/openvz_driver.c
@@ -130,6 +131,11 @@ static int openvzDomainDefineCmd(virConnectPtr
conn,
   ADD_ARG_LIT(VZCTL);
   ADD_ARG_LIT("--quiet");
   ADD_ARG_LIT("create");
+
+    sprintf( str_id, "%d", vmdef->id );
+    ADD_ARG_LIT(str_id);
+
+    ADD_ARG_LIT("--name");
   ADD_ARG_LIT(vmdef->name);

This is where you need to pull in an auto-assigned ID value
instead of using vmdef->id.


Regards,
Daniel
--
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]