[libvirt] [ PATCH ] fix multiple veth problem for OpenVZ
Dear all This is to fix multiple veth problem. NETIF setting was overwritten after first CT because any CT could not be found by character name. --- src/openvz/openvz_conf.c | 38 ++ src/openvz/openvz_conf.h |1 + src/openvz/openvz_driver.c |2 +- 3 files changed, 40 insertions(+), 1 deletions(-) diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c index 43bbaf2..9fb9f7e 100644 --- a/src/openvz/openvz_conf.c +++ b/src/openvz/openvz_conf.c @@ -948,3 +948,41 @@ static int openvzAssignUUIDs(void) VIR_FREE(conf_dir); return 0; } + + +/* + * Return CTID from name + * + */ + +int openvzGetVEID(char *name) { + +char cmd[64]; +int veid; +FILE *fp; + +strcpy( cmd, VZLIST ); +strcat( cmd, ); +strcat( cmd, name ); +strcat( cmd, -ovpsid -H ); + +if ((fp = popen(cmd, r)) == NULL) { +openvzError(NULL, VIR_ERR_INTERNAL_ERROR, %s, _(popen failed)); +return -1; +} + +if (fscanf(fp, %d\n, veid ) != 1) { +if (feof(fp)) +return -1; + +openvzError(NULL, VIR_ERR_INTERNAL_ERROR, +%s, _(Failed to parse vzlist output)); +goto cleanup; +} + +return veid; + + cleanup: +fclose(fp); +return -1; +} diff --git a/src/openvz/openvz_conf.h b/src/openvz/openvz_conf.h index 00e18b4..518c267 100644 --- a/src/openvz/openvz_conf.h +++ b/src/openvz/openvz_conf.h @@ -66,5 +66,6 @@ void openvzFreeDriver(struct openvz_driver *driver); int strtoI(const char *str); int openvzSetDefinedUUID(int vpsid, unsigned char *uuid); unsigned int openvzGetNodeCPUs(void); +int openvzGetVEID(char *name); #endif /* OPENVZ_CONF_H */ diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 196fd8c..879b5d0 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -667,7 +667,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid, if (net-type == VIR_DOMAIN_NET_TYPE_BRIDGE) { virBuffer buf = VIR_BUFFER_INITIALIZER; char *dev_name_ve; -int veid = strtoI(vpsid); +int veid = openvzGetVEID(vpsid); //--netif_add ifname[,mac,host_ifname,host_mac] ADD_ARG_LIT(--netif_add) ; -- 1.5.2.2 - Yuji Nishida nish...@nict.go.jp -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [patch] Add openvzDomainSetMemoryInternal
Hi all, This patch is to set KMEMSIZE for OpenVZ. This function is used for initializing the parameter of KMEMSIZE to start container. openvzDomainSetMemory should be left for another purpose so I added new one. I think users should specify memory as kbyte ( or bigger ). --- src/openvz/openvz_driver.c | 32 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index f64ad1e..5c1fefa 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -69,6 +69,7 @@ static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type); static int openvzDomainGetMaxVcpus(virDomainPtr dom); static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus); static int openvzDomainSetVcpusInternal(virConnectPtr conn, virDomainObjPtr vm, unsigned int nvcpus); +static int openvzDomainSetMemoryInternal(virConnectPtr conn, virDomainObjPtr vm, unsigned long memory); static void openvzDriverLock(struct openvz_driver *driver) { @@ -803,6 +804,14 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml) } } +if (vm-def-memory 0) { +if (openvzDomainSetMemoryInternal(conn, vm, vm-def-memory) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + %s, _(Could not set memory size)); + goto cleanup; +} +} + dom = virGetDomain(conn, vm-def-name, vm-def-uuid); if (dom) dom-id = -1; @@ -1364,6 +1373,29 @@ static int openvzNumDefinedDomains (virConnectPtr conn) { return ninactive; } +static int openvzDomainSetMemoryInternal(virConnectPtr conn, virDomainObjPtr vm, + unsigned long mem) { +struct openvz_driver *driver = conn-privateData; +char str_mem[16]; +const char *prog[] = { VZCTL, --quiet, set, PROGRAM_SENTINAL, + --kmemsize, str_mem, --save, NULL }; + +/* memory has to be changed its format from kbyte to byte */ +snprintf( str_mem, sizeof(str_mem), %lu, mem * 1024 ); + +openvzSetProgramSentinal(prog, vm-def-name); +if (virRun(conn, prog, NULL) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not exec %s), VZCTL); +goto cleanup; +} + +return 0; + +cleanup: +return -1; +} + static virDriver openvzDriver = { VIR_DRV_OPENVZ, OPENVZ, -- 1.5.3.4 - Yuji Nishida nish...@nict.go.jp -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Priority of vzctl create should be lower
Hi all About OpenVZ, it uses vzctl command that produces tar/gzip commands. I think we should lower these commands for running other procedures prior to them. This is the patch to achieve it with nice/ionice commands. From ff3cf022995ef541136bd40579af2eeb20aeafdb Mon Sep 17 00:00:00 2001 From: root r...@node13.nvlab.org Date: Mon, 26 Oct 2009 02:44:43 + Subject: [PATCH] lower priority for running tar and gzip during vzctl create --- src/openvz/openvz_driver.c |8 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index f64ad1e..59d38ae 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -130,6 +130,14 @@ openvzDomainDefineCmd(virConnectPtr conn, } while (0) narg = 0; + +/* lower priority for running tar and gzip */ +ADD_ARG_LIT(nice); +ADD_ARG_LIT(-n); +ADD_ARG_LIT(19); +ADD_ARG_LIT(ionice); +ADD_ARG_LIT(-c3); + ADD_ARG_LIT(VZCTL); ADD_ARG_LIT(--quiet); ADD_ARG_LIT(create); -- 1.5.3.4 - Yuji Nishida nish...@nict.go.jp -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Priority of vzctl create should be lower
Hi Chris, I think vzctl create command invokes processes which occupy CPU and Disk I/O. It seems clearly necessary for such commands to prevent from running prior to other processes. But I almost agree with you. We should have flexibility about it for users. As you said if it requires to encode policy into libvirt, we should avoid it still now. And I want to spend more time in writing some other patches :) - Yuji Nishida nish...@nict.go.jp On 2009/10/26, at 21:15, Chris Lalancette wrote: Yuji NISHIDA wrote: Hi all About OpenVZ, it uses vzctl command that produces tar/gzip commands. I think we should lower these commands for running other procedures prior to them. This is the patch to achieve it with nice/ionice commands. I'm not sure that this is such a good idea, as it is encoding policy into libvirt. There have been other requests for being able to set the priorities of certain domains, so it might make sense to have a more generic priority concept that could be set by the user. Then the user would specify how important a particular task is, and we wouldn't be putting any policy into libvirt itself. -- Chris Lalancette -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] Re: OpenVZ : The restriction of domain name should be addressed
Thanks, Chris and Daniel I corrected the code that I posted here according to your comments. Chris, I now need to handle openvz containers by character(name) not integer(id) at all. diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 54bcaa9..3b8505d 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -156,12 +156,13 @@ openvzDomainDefineCmd(virConnectPtr conn, fclose(fp); if (max_veid == 0) { -max_veid = 100; +/* OpenVZ reserves the IDs ranging from 0 to 100 */ +max_veid = 101; } else { max_veid++; } -sprintf(str_id, %d, max_veid++); +snprintf(str_id, sizeof(str_id), %d, max_veid); ADD_ARG_LIT(str_id); ADD_ARG_LIT(--name); -- 1.5.2.2 - Yuji Nishida nish...@nict.go.jp On 2009/09/23, at 23:45, Daniel Veillard wrote: On Wed, Sep 23, 2009 at 10:22:51AM +0200, Chris Lalancette wrote: Yuji NISHIDA wrote: 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++; +} You might want to add a comment saying that vpsid's below 100 are reserved for OpenVZ internal use; otherwise, it looks like an odd place to begin numbering. good point. + +char str_id[10]; +sprintf( str_id, %d, max_veid++ ); You'll want to use snprintf here, like: snprintf(str_id, sizeof(str_id), %d, max_veid++); (bear with me on this part, since I don't know much about OpenVZ). Besides that, though, I'm not sure you necessarily want to do it like this, since you aren't really tracking the ID's properly. The problem I see is that if you do it like this, start the container, and then do virsh dumpxml openvz, you won't see the ID in the output XML, like you do for the other drivers. Is that intentional? If not, I think you'll want to store the id in the virDomainDef-id member so that the information will be properly printed to the user. I actually applied that patch on monday (after a couple of cleanups) and apparently my reply mail is part of the set that got lost :-( Author: Yuji NISHIDA nish...@nict.go.jp 2009-09-22 12:19:09 Committer: Daniel Veillard veill...@redhat.com 2009-09-22 12:19:09 0c85095e46f3aba09ac401f559b76df0b0bea998 the snprintf wasn't looking critical because I don't think a %d can generate more than 9 characters, but you're right in the absolute :-) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] Re: OpenVZ : The restriction of domain name should be addressed
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 nish...@nict.go.jp 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@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] Re: OpenVZ : The restriction of domain name should be addressed
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? diff --git a/src/domain_conf.c b/src/domain_conf.c index 5ae0775..f74961f 100644 --- a/src/domain_conf.c +++ b/src/domain_conf.c @@ -2492,7 +2492,7 @@ static virDomainDefPtr virDomainDefParseXML (virConnectPtr conn, return NULL; } -if (!(flags VIR_DOMAIN_XML_INACTIVE)) +// if (!(flags VIR_DOMAIN_XML_INACTIVE)) if((virXPathLong(conn, string(./@id), ctxt, id)) 0) id = -1; def-id = (int)id; diff --git a/src/openvz_conf.c b/src/openvz_conf.c index be94b9e..d23f173 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -425,17 +425,18 @@ int openvzLoadDomains(struct openvz_driver *driver) { char uuidstr[VIR_UUID_STRING_BUFLEN]; virDomainObjPtr dom = NULL; char temp[50]; +char name[64]; if (openvzAssignUUIDs() 0) return -1; -if ((fp = popen(VZLIST -a -ovpsid,status -H 2/dev/null, r)) == NULL) { +if ((fp = popen(VZLIST -a -ovpsid,name,status -H 2/dev/null, r)) == NULL) { openvzError(NULL, VIR_ERR_INTERNAL_ERROR, %s, _(popen failed)); return -1; } while(!feof(fp)) { -if (fscanf(fp, %d %s\n, veid, status) != 2) { +if (fscanf(fp, %d %s\n, veid, name, status) != 3) { if (feof(fp)) break; @@ -465,7 +466,7 @@ int openvzLoadDomains(struct openvz_driver *driver) { dom-pid = veid; dom-def-id = dom-state == VIR_DOMAIN_SHUTOFF ? -1 : veid; -if (virAsprintf(dom-def-name, %i, veid) 0) +if (virAsprintf(dom-def-name, %s, name) 0) goto no_memory; openvzGetVPSUUID(veid, uuidstr, sizeof(uuidstr)); 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 @@ -101,6 +101,7 @@ static int openvzDomainDefineCmd(virConnectPtr conn, virDomainDefPtr vmdef) { int narg; +char str_id[10]; for (narg = 0; narg maxarg; narg++) args[narg] = NULL; @@ -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); if (vmdef-nfss == 1 @@ -1229,7 +1235,11 @@ static int openvzListDefinedDomains (virConnectPtr conn, char vpsname[32]; char buf[32]; char *endptr; -const char *cmd[] = {VZLIST, -ovpsid, -H, -S, NULL}; +const char *cmd[] = {VZLIST, -oname, -H, -S, NULL}; +int cnt = 0; +char name_buf[32]; + + /* the -S options lists only stopped domains */ ret = virExec(conn, cmd, NULL, NULL, @@ -1241,14 +1251,14 @@ static int openvzListDefinedDomains (virConnectPtr conn, } while(got nnames){ -ret = openvz_readline(outfd, buf, 32); +ret = openvz_readline(outfd, buf, 64); if(!ret) break; -if (virStrToLong_i(buf, endptr, 10, veid) 0) { -openvzError(conn, VIR_ERR_INTERNAL_ERROR, -_(Could not parse VPS ID %s), buf); -continue; +cnt = 0; +while( buf[cnt] != ' ' ){ + name_buf[cnt] = buf[cnt]; + cnt++; } -snprintf(vpsname, sizeof(vpsname), %d, veid); +snprintf(vpsname, sizeof(vpsname), %d, name_buf); if (!(names[got] = strdup(vpsname))) goto no_memory; got ++; -- 1.5.2.2 - Yuji Nishida nish...@nict.go.jp -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] Re: OpenVZ : The restriction of domain name should be addressed
2009/7/24 Daniel P. Berrange berra...@redhat.com We should make use of this --name parameter then - I guess it didn't exist when we first wrote the driver. It is useful to users to have separate ID vs Name parameters - and in fact the current reusing of 'ID' for the name, causes a little confusion in virsh's lookup routines because it can't tell whether the parameter its given is a name or an ID, since they are identical. There is still a question of how to specify both a name and CTID in XML description. By default, CTID can be obtained as openvzGimmeFirstUnusedCTID(), but actually I think that there exists a number of persons interested in giving CTIDs manually. Well, can domain id='' be used for CTID remaining name for alphabetical domain name? I worte a small patch and tried with following XML setting. ### Patch ### --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -130,9 +130,6 @@ ADD_ARG_LIT(VZCTL); ADD_ARG_LIT(--quiet); ADD_ARG_LIT(create); -ADD_ARG_LIT(vmdef-id); - -ADD_ARG_LIT(--name); ADD_ARG_LIT(vmdef-name); ### XML ### domain id='100' nameabc/name I found the type of id was identified as number( obj-type == XPATH_NUMBER ) in virXPathLongBase, but it is clearly string before converted. I think correct path is to go in the first if context( obj-type == XPATH_STRING ) and run strtol. Then I tried with following XML. ### XML ### domain id=100 nameabc/name I got following error. AttValue: or ' expected I'm not sure from which function should return this result. Maybe this is the first step to go forward. I am doubting openvz*LookupBy* functions be also modified, right? - Yuji Nishida nish...@nict.go.jp -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] OpenVZ : The restriction of domain name should be addressed
Hi, The current libvirt OpenVZ driver has a restriction that the domain names must match the OpenVZ container VEID I really want to have domain name as character, not integer. It could help me very much if any patch against this problem would be released. Is there anyone tackling this problem now?( or going to? ) Otherwise, any hint would help me. Regards. - Yuji Nishida nish...@nict.go.jp -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] OpenVZ : cannot assign bridge to any interface
='utc'/ on_poweroffdestroy/on_poweroff on_rebootdestroy/on_reboot on_crashdestroy/on_crash devices filesystem type='template' source name='fedora-10-x86_64'/ target dir='/'/ /filesystem interface type='bridge' mac address='52:54:00:00:01:01'/ source bridge='guestnet101'/ target dev='veth101'/ /interface /devices /domain [r...@node13 test]# virsh net-dumpxml guestnet101 network nameguestnet101/name uuid5462e7a5-2048-3067-af9d-b134381a3f8a/uuid forward mode='nat'/ bridge name='br101' stp='off' forwardDelay='0' / ip address='10.0.1.1' netmask='255.255.255.240' dhcp range start='10.0.1.2' end='10.0.1.2' / /dhcp /ip /network ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Regards. - Yuji Nishida nish...@nict.go.jp -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list