Re: [libvirt] [PATCH] Openvz: how to use a nondefault config
2009/4/2 Daniel P. Berrange berra...@redhat.com mailto:berra...@redhat.com On Thu, Apr 02, 2009 at 06:36:15PM +0400, Evgeniy Sokolov wrote: Config /etc/vz/conf/ve-XXX.conf-sample define there are many parameters like memory, CPU etc. This parameters are not properties of filesystem. Daniel, usage of pre-defined configs in really usefull. Can we create additional tag inside domain/domain? The trouble with this is that given the XML config of a guest, you can no longer determine what its configuration is, because a large amount of configuration is hidden in this opaque 'template'. And in kvm/qemu case there is a lot of hidden information too :) In OpenVZ case we don't loose any info (see below). If we're to support templates, I think we need to make them first class objects, so you can query what templates exist, and see their associated config settings. eg, expose a simple API virDomainTemplatePtr; int virConnectListDomainTemplates(virConnectPtr conn, const char **names); virDomainTemplatePtr virDomainTemplateLookupbyName(virConnectPtr con, const char *name) char *virDomainTemplateGetXMLDesc(virDomainTemplatePtr tmpl); virDomainTemplatePtr virDomainTemplateDefineXML(virConnectPtr conn, const char *xml) int virDomainTemplateUndefine(virDomainTemplatePtr tmpl); int virDomainTemplateFree(virDomainTemplatePtr tmpl); Then, we could either include a template$NAME/template parameter in the XML for a guest. Or have an alternate API for creating guests virDomainCreateXMLWithTemplate(virConnectPtr conn, const char *xmlDesc, const char *template) It depends whether we'd want to track the template - guest association forever, or just use it once to fill-in the guest XML and then forget about the template after that. Template - guest association don't need. Information is used only once. So, we will extend libvirt API by virDomainCreateXMLWithTemplate() and will include template$NAME/template to domain/domain. Daniel, is it correct? It doesn't matter in OpenVZ case: template (or, config, in openvz terminology) is used only once, when container is creating. But then per-container copy is created, and it is already used by libvirt to keep information about container. Per-container OpenVZ config keeps the name of the original config (in ORIGIN_SAMPLE variable). ORIGIN_SAMPLE is not used by OpenVZ, and don't need. It is saved to config for using external tools. Is there need for Template API in case of other hypervisors? -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Openvz: how to use a nondefault config
Hi Anton, I'm sorry for delay. I was on vacation. Hi all. When libvirt creates an OpenVZ machine, it does smth like # vzctl create $ctid --ostemplate `ostemplate` And we can't specify an --config `config` argument. In this case vzctl chooses a default config file (a value of CONFIG variable from /etc/vz/vz.conf). But there are cases when we want to specify a config file directly, as in # vzctl create $ctid --ostemplate `ostemplate` --config `config` I think, that we can try to use the same `ostemplate` name as --config value, if corresponding template exists, i.e., if there is a file /etc/vz/conf/ve-`ostemplate`.conf-sample, libvirt will run a command # vzctl create $ctid --ostemplate `ostemplate` --config `ostemplate` Otherwise, it will run it's default command # vzctl create $ctid --ostemplate `ostemplate` (the same arguments.) Config /etc/vz/conf/ve-XXX.conf-sample define there are many parameters like memory, CPU etc. This parameters are not properties of filesystem. Daniel, usage of pre-defined configs in really usefull. Can we create additional tag inside domain/domain? --- Example of creating a machine with nondefault config: 1. Create /etc/vz/conf/ve-altlinux-test.conf-sample 2. Create /var/lib/vz/template/cache/altlinux-test.tar 3. Use libvirt with (hypothetical) XML: domain type=openvz name100/name memory1/memory ostypeexe/type/os devices filesystem type=template source name=altlinux-test/ target dir=// /filesystem /devices /domain --- Example of creating a machine with default config: 1. Ensure there is no /etc/vz/conf/ve-altlinux-test.conf-sample 2. Create /var/lib/vz/template/cache/altlinux-test.tar 3. Use libvirt with (the same as above) XML file --- -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Adding filesystem mount support for openVZ
Hi Evgeniy, really, default config is specified in /etc/sysconfig/vz # grep -R CONFIGFILE /etc/sysconfig/vz CONFIGFILE=vps.basic config file is calculating by snprintf(path, sizeof(path), VPS_CONF_DIR ve-%s.conf-sample, config); Actually, vz.conf is in /etc/vz/ on my machine (Ubuntu Hardy). Isn't /etc/vz/ standard ? If not, do you have any idea on how I could locate vz.conf reliably (or get the value of CONFIGFILE reliably) ? Yes, /etc/vz/vz.conf is standard config. Better to use /etc/vz. I am accustomed to use old path /etc/sysconfig/vz, it is symlink to /etc/vz/vz.conf now. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Adding filesystem mount support for openVZ
Hi Florian, Hi everyone, This patch is to allow using the mount type in the filesystem tag for OpenVZ domains. Example: ... filesystem type='mount' source dir='/path/to/filesystem/directory/' / target dir='/path/to/pivot/root/' / /filesystem ... This is my first patch to an external project, so don't spare me if I got things wrong :) Also, I'm curious for suggestions as to how I could allow for the target not to be specified in the XML. Because in this case OpenVZ just makes a temporary pivot root in /var/lib/vz/root/ and that is probably sufficient for most people, who might not want to have to explicitly create a pivot root somewhere, just for mounting the filesystem while it's running. I was thinking either allow for the target tag not to be specified, or add an auto attribute to target. Which one sounds better ? Thanks, Florian diff --git a/src/openvz_conf.c b/src/openvz_conf.c index ff3d607..33fb259 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -314,6 +314,41 @@ error: } +/* utility function to replace 'from' by 'to' in 'str' */ +static char* +openvz_replace(const char* str, + const char* from, + int to) { +char tmp[4096]; +char* offset = tmp; +int len = strlen(str); +int fromLen = strlen(from); +int r,i,maxcmp,left = sizeof(tmp); + +if(!from) +return NULL; + +for(i = 0; i len left; ++i) { + /* compare first caracters to limit useless full comparisons */ +if(*from == str[i]) { +maxcmp = (fromLen len-i) ? len-i : fromLen; +if(strncmp(from, str+i, maxcmp) == 0) { +r = snprintf(offset, left, %d, to); +offset += r; +i += fromLen - 1; +continue; +} +} +*offset++ = str[i]; +left = sizeof(tmp) - (offset-tmp); +} search can be simplified by strstr(str, from) + +tmp[sizeof(tmp)-left] = '\0'; + +return strdup(tmp); +} + + diff --git a/src/openvz_conf.h b/src/openvz_conf.h index 8e02056..da9bfb4 100644 --- a/src/openvz_conf.h +++ b/src/openvz_conf.h @@ -42,6 +42,7 @@ enum { OPENVZ_WARN, OPENVZ_ERR }; /* OpenVZ commands - Replace with wrapper scripts later? */ #define VZLIST /usr/sbin/vzlist #define VZCTL /usr/sbin/vzctl +#define VZ_DEFAULT_CONF_FILE ve-vps.basic.conf-sample really, default config is specified in /etc/sysconfig/vz # grep -R CONFIGFILE /etc/sysconfig/vz CONFIGFILE=vps.basic config file is calculating by snprintf(path, sizeof(path), VPS_CONF_DIR ve-%s.conf-sample, config); #define VZCTL_BRIDGE_MIN_VERSION ((3 * 1000 * 1000) + (0 * 1000) + 22 + 1) -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [OpenVZ]
Hi, attached patch fix problem. Guys, is it really an issue to fix also mac generation for OpenVZ? Vzctl generates different macs for host's and domain's eth devices. Libvirt creates them with equal macs. In this case there is a bridge support for OpenVZ in libvirt but it doesn't work ... :-( And it has to implement additional steps for changing macs after container creation. This message (including attachments) is private and confidential. If you have received this message in error, please notify us and remove it from your system. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list Index: openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.65 diff -u -p -r1.65 openvz_driver.c --- openvz_driver.c 17 Dec 2008 21:13:19 - 1.65 +++ openvz_driver.c 18 Dec 2008 13:42:28 - @@ -473,6 +473,8 @@ openvzDomainSetNetwork(virConnectPtr con int rc = 0, narg; const char *prog[OPENVZ_MAX_ARG]; char macaddr[VIR_MAC_STRING_BUFLEN]; +unsigned char host_mac[VIR_MAC_BUFLEN]; +char host_macaddr[VIR_MAC_STRING_BUFLEN]; struct openvz_driver *driver = conn-privateData; char *opt = NULL; @@ -507,6 +509,8 @@ openvzDomainSetNetwork(virConnectPtr con } virFormatMacAddr(net-mac, macaddr); +virCapabilitiesGenerateMac(driver-caps, host_mac); +virFormatMacAddr(host_mac, host_macaddr); if (net-type == VIR_DOMAIN_NET_TYPE_BRIDGE) { virBuffer buf = VIR_BUFFER_INITIALIZER; @@ -541,7 +545,7 @@ openvzDomainSetNetwork(virConnectPtr con virBufferAdd(buf, dev_name_ve, -1); /* Guest dev */ virBufferVSprintf(buf, ,%s, macaddr); /* Guest dev mac */ virBufferVSprintf(buf, ,%s, net-ifname); /* Host dev */ -virBufferVSprintf(buf, ,%s, macaddr); /* Host dev mac */ +virBufferVSprintf(buf, ,%s, host_macaddr); /* Host dev mac */ if (driver-version = VZCTL_BRIDGE_MIN_VERSION) { virBufferVSprintf(buf, ,%s, net-data.bridge.brname); /* Host bridge */ @@ -549,7 +553,7 @@ openvzDomainSetNetwork(virConnectPtr con virBufferVSprintf(configBuf, ifname=%s, dev_name_ve); virBufferVSprintf(configBuf, ,mac=%s, macaddr); /* Guest dev mac */ virBufferVSprintf(configBuf, ,host_ifname=%s, net-ifname); /* Host dev */ -virBufferVSprintf(configBuf, ,host_mac=%s, macaddr); /* Host dev mac */ +virBufferVSprintf(configBuf, ,host_mac=%s, host_macaddr); /* Host dev mac */ virBufferVSprintf(configBuf, ,bridge=%s, net-data.bridge.brname); /* Host bridge */ } -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] PATCH: allow to set nvcpus = 0
On Mon, Nov 17, 2008 at 06:44:07PM +0300, Evgeniy Sokolov wrote: OpenVZ uses all CPUs available in system - by default (number of CPUs did not set) - number of CPUs = 0 Currenty, libvirt don't allow to set nvcpus = 0 Attached patch removes limitation in libvirt set nvcpu = 0, but add it to each driver which allow to set number of virtual CPU. For OpenVZ set default number of CPUs = 0. This is the wrong way to handle this. If OpenVZ allows the container to use all the host CPUs, then the vCPUs number should reflect the number of pCPUs, not 0. So when loading the openvz config, if there is no CPUS= setting in the config file, the driver should fill in the number of host pCPUs. Likewise, when setting the openvz config, if the vCPUs in the XML is = pCPUs, then it should just leave out the CPUS= setting, so OpenVZ uses all CPUs. It is not like in OpenVZ, but good way. Attached patch implement it. Index: openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.50 diff -u -r1.50 openvz_conf.c --- openvz_conf.c 17 Nov 2008 09:55:59 - 1.50 +++ openvz_conf.c 19 Nov 2008 16:16:39 - @@ -49,6 +49,7 @@ #include buf.h #include memory.h #include util.h +#include nodeinfo.h static char *openvzLocateConfDir(void); static int openvzGetVPSUUID(int vpsid, char *uuidstr); @@ -427,10 +428,11 @@ goto cleanup; } else if (ret 0) { dom-def-vcpus = strtoI(temp); -} else { -dom-def-vcpus = 1; } +if (ret == 0 || dom-def-vcpus == 0) +dom-def-vcpus = openvzGetNodeCPUs(); + /* XXX load rest of VM config data */ openvzReadNetworkConf(NULL, dom-def, veid); @@ -457,6 +459,19 @@ return -1; } +unsigned int +openvzGetNodeCPUs(void) +{ +virNodeInfo nodeinfo; + +if (virNodeInfoPopulate(NULL, nodeinfo) 0) { +openvzError(NULL, VIR_ERR_INTERNAL_ERROR, + _(Cound not read nodeinfo)); +return 0; +} + +return nodeinfo.cpus; +} int openvzWriteConfigParam(int vpsid, const char *param, const char *value) Index: openvz_conf.h === RCS file: /data/cvs/libvirt/src/openvz_conf.h,v retrieving revision 1.17 diff -u -r1.17 openvz_conf.h --- openvz_conf.h 12 Nov 2008 16:35:47 - 1.17 +++ openvz_conf.h 19 Nov 2008 16:16:39 - @@ -68,5 +68,6 @@ void openvzFreeDriver(struct openvz_driver *driver); int strtoI(const char *str); int openvzSetDefinedUUID(int vpsid, unsigned char *uuid); +unsigned int openvzGetNodeCPUs(void); #endif /* OPENVZ_CONF_H */ Index: openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.60 diff -u -r1.60 openvz_driver.c --- openvz_driver.c 17 Nov 2008 11:44:51 - 1.60 +++ openvz_driver.c 19 Nov 2008 16:16:39 - @@ -834,7 +834,7 @@ char str_vcpus[32]; const char *prog[] = { VZCTL, --quiet, set, vm ? vm-def-name : NULL, --cpus, str_vcpus, --save, NULL }; - +unsigned int pcpus; if (!vm) { openvzError(conn, VIR_ERR_INVALID_DOMAIN, @@ -848,6 +848,10 @@ return -1; } +pcpus = openvzGetNodeCPUs(); +if (pcpus 0 pcpus nvcpus) +nvcpus = pcpus; + snprintf(str_vcpus, 31, %d, nvcpus); str_vcpus[31] = '\0'; -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] PATCH: allow to set nvcpus = 0
OpenVZ uses all CPUs available in system - by default (number of CPUs did not set) - number of CPUs = 0 Currenty, libvirt don't allow to set nvcpus = 0. Attached patch removes limitation in libvirt set nvcpu = 0, but add it to each driver which allow to set number of virtual CPU. For OpenVZ set default number of CPUs = 0. Index: libvirt.c === RCS file: /data/cvs/libvirt/src/libvirt.c,v retrieving revision 1.174 diff -u -p -r1.174 libvirt.c --- libvirt.c 17 Nov 2008 12:18:18 - 1.174 +++ libvirt.c 17 Nov 2008 15:11:12 - @@ -3124,10 +3124,6 @@ virDomainSetVcpus(virDomainPtr domain, u return (-1); } -if (nvcpus 1) { -virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__); -return (-1); -} conn = domain-conn; if (conn-driver-domainSetVcpus) Index: openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.50 diff -u -p -r1.50 openvz_conf.c --- openvz_conf.c 17 Nov 2008 09:55:59 - 1.50 +++ openvz_conf.c 17 Nov 2008 15:11:12 - @@ -428,7 +428,7 @@ int openvzLoadDomains(struct openvz_driv } else if (ret 0) { dom-def-vcpus = strtoI(temp); } else { -dom-def-vcpus = 1; +dom-def-vcpus = 0; } /* XXX load rest of VM config data */ Index: openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.60 diff -u -p -r1.60 openvz_driver.c --- openvz_driver.c 17 Nov 2008 11:44:51 - 1.60 +++ openvz_driver.c 17 Nov 2008 15:11:12 - @@ -842,12 +842,6 @@ static int openvzDomainSetVcpus(virDomai return -1; } -if (nvcpus = 0) { -openvzError(conn, VIR_ERR_INTERNAL_ERROR, -%s, _(VCPUs should be = 1)); -return -1; -} - snprintf(str_vcpus, 31, %d, nvcpus); str_vcpus[31] = '\0'; Index: qemu_driver.c === RCS file: /data/cvs/libvirt/src/qemu_driver.c,v retrieving revision 1.153 diff -u -p -r1.153 qemu_driver.c --- qemu_driver.c 17 Nov 2008 11:44:51 - 1.153 +++ qemu_driver.c 17 Nov 2008 15:11:12 - @@ -1969,6 +1969,12 @@ static int qemudDomainSetVcpus(virDomain return -1; } +if (nvcpus 1) { +qemudReportError(dom-conn, dom, NULL, VIR_ERR_INVALID_ARG, + _(nvcpus '%u'), nvcpus); +return -1; +} + if (virDomainIsActive(vm)) { qemudReportError(dom-conn, dom, NULL, VIR_ERR_NO_SUPPORT, %s, _(cannot change vcpu count of an active domain)); Index: test.c === RCS file: /data/cvs/libvirt/src/test.c,v retrieving revision 1.96 diff -u -p -r1.96 test.c --- test.c 17 Nov 2008 11:44:51 - 1.96 +++ test.c 17 Nov 2008 15:11:13 - @@ -1180,7 +1180,7 @@ static int testSetVcpus(virDomainPtr dom GET_DOMAIN(domain, -1); /* We allow more cpus in guest than host */ -if (nrCpus 32) { +if (nrCpus 32 || nrCpus 1) { testError(domain-conn, VIR_ERR_INVALID_ARG, __FUNCTION__); return (-1); } Index: virsh.c === RCS file: /data/cvs/libvirt/src/virsh.c,v retrieving revision 1.172 diff -u -p -r1.172 virsh.c --- virsh.c 17 Nov 2008 11:03:25 - 1.172 +++ virsh.c 17 Nov 2008 15:11:13 - @@ -1897,7 +1897,7 @@ cmdSetvcpus(vshControl *ctl, const vshCm return FALSE; count = vshCommandOptInt(cmd, count, count); -if (count = 0) { +if (count 0) { vshError(ctl, FALSE, %s, _(Invalid number of virtual CPUs.)); virDomainFree(dom); return FALSE; Index: xen_unified.c === RCS file: /data/cvs/libvirt/src/xen_unified.c,v retrieving revision 1.61 diff -u -p -r1.61 xen_unified.c --- xen_unified.c 17 Nov 2008 11:44:51 - 1.61 +++ xen_unified.c 17 Nov 2008 15:11:13 - @@ -884,6 +884,11 @@ xenUnifiedDomainSetVcpus (virDomainPtr d GET_PRIVATE(dom-conn); int i; +if (nvcpus 1) { +xenUnifiedError (dom-conn, VIR_ERR_INVALID_ARG, __FUNCTION__); +return -1; +} + /* Try non-hypervisor methods first, then hypervisor direct method * as a last resort. */ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] PATCH: OpenVZ bridge support
Sorry for delay. Big thanks for docs! This is an update of the patch http://www.redhat.com/archives/libvir-list/2008-October/msg00326.html To enable bridge support in the OpenVZ driver. As well as the fixes suggested last time, it includes an initial bit of HTML doc for the openvz driver, covering example XML, and the bridge configuration requirements Daniel + +while(1) { +if (openvz_readline(fd, line, sizeof(line)) = 0) +break; + +if (!STRPREFIX(line, param) +line[strlen(param)] == '=') { +if (safewrite(temp_fd, line, strlen(line)) != +strlen(line)) +goto error; +} +} + this condition make container config completely broken. as the patch is already commited, here is fix. diff -u -r1.49 openvz_conf.c --- openvz_conf.c 12 Nov 2008 16:35:47 - 1.49 +++ openvz_conf.c 14 Nov 2008 16:14:24 - @@ -484,8 +484,7 @@ if (openvz_readline(fd, line, sizeof(line)) = 0) break; -if (!STRPREFIX(line, param) -line[strlen(param)] == '=') { +if (!(STRPREFIX(line, param) line[strlen(param)] == '=')) { if (safewrite(temp_fd, line, strlen(line)) != strlen(line)) goto error; -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] PATCH 3/4: SUpport bridge config for openvz
This implements support for bridge configs in openvz following the rules set out in http://wiki.openvz.org/Virtual_Ethernet_device#Making_a_bridged_veth-device_persistent This simply requires that the admin has created /etc/vz/vznetctl.conf containing #!/bin/bash EXTERNAL_SCRIPT=/usr/sbin/vznetaddbr For openvz = 3.0.22, we have to manually re-write the NETIF line to add the bridge config parameter. It is alternative, but more flexible way. It require simple modification of vznetaddbr. Common scenario is to add VZHOSTBR=bridge if to config. For newer openvz we can simply pass the bridge name on the commnand line to --netif_add. Older openvz also requires that the admin install /usr/sbin/vznetaddbr since it is not available out of the box Daniel + +while(1) { +if (openvz_readline(fd, line, sizeof(line)) = 0) +break; + +if (!STRPREFIX(line, param)) { need to check for '='. Currently, if you will search for 'NETIF', you can find any string with such prefix. example 'NETIFOTHERPARAM' +if (safewrite(temp_fd, line, strlen(line)) != +strlen(line)) +goto error; +} +} + /* + +if (!(opt = virBufferContentAndReset(buf))) +goto no_memory; + ADD_ARG_LIT(opt) ; Need to free opt -}else if (net-type == VIR_DOMAIN_NET_TYPE_ETHERNET +} else if (net-type == VIR_DOMAIN_NET_TYPE_ETHERNET net-data.ethernet.ipaddr != NULL) { +static int +openvzDomainSetNetworkConfig(virConnectPtr conn, + virDomainDefPtr def) +{ +unsigned int i; +virBuffer buf = VIR_BUFFER_INITIALIZER; +char *param; +struct openvz_driver *driver = (struct openvz_driver *) conn-privateData; + +for (i = 0 ; i def-nnets ; i++) { +if (driver-version VZCTL_BRIDGE_MIN_VERSION i 0) +virBufferAddLit(buf, ;); Need to check that network is bridge. In other case we will have NETIF='some params' + +if (openvzDomainSetNetwork(conn, def-name, def-nets[i], buf) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, +%s, _(Could not configure network)); +goto exit; +} +} + -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] openvz: swap source bridge=... with target dev=...
I done the following: - Add function openvzAppendConfigParam(veid, param, value) This function simply appends a string `param=value` to config file. - Rewrite functions openvz{Get,Set}DefinedBridge to use that function Patch looks good now. I think, we need to rewrite {Get,Set}UUID functions in the same manner. Yes, good idea. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] openvz: swap source bridge=... with target dev=...
Hi. I rewrite functions taken from vzctl in the new patch, so this: Here is the patch, that implements the following behaviour * interface name inside container is automatically generated and equals ethN, where N is the number of that interface within current domain * mac address of that interface inside container is generated automatically by function openvzGenerateMac * if target dev= is specified, use it; otherwise, use the default openvz name, i.e., vethN.M for interface ethM in container with veid N * if mac address='...' specified, use it; otherwise, vzctl will generate it automatically * target dev and mac address are (re)stored (from)to $veid.conf is true, while that: the functions openvzGenerateMac and openvzGenerateVethName are taken from vzctl sources and slightly changed then is not true anymore. +static char * +openvzGenerateMac(void) +{ +char mac[6] = { +0x52, +0x54, +0x00, How did you get 0x52, 0x54, 0x00? +if (net-type == VIR_DOMAIN_NET_TYPE_BRIDGE) { +static int vnetNo = 0; Libvirt may be use as library in applications. If some will call create 2 containers, then first container will have eth0...ethN second will have ethN+1... Other looks good. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] openvz: swap source bridge=... with target dev=...
P.S. Now I am working on that: P.S. Are someone going to implement interface type='bridge' ... source bridge=... ... /interface part of openvz driver? :) I plan to implement it in a month. It will be fine if you are ready to develop the feature. I'm using $veid.conf to store information about bridge device in the following manner: for interface ifname, therhe will be a line #BRIGDE(ifname): bridge name for example, #BRIDGE(veth101.0): virbr1 Do you agree with that behaviour? I think we can simplify format to simplify parsing. #BRIDGE=virbr1:veth101.0,veth101.1,veth101.2 In this case we may use openvzReadConfigParam(101, #BRIDGE, value, 1024) -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] openvz: swap source bridge=... with target dev=...
2008/9/29 Evgeniy V. Sokolov [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] This behaviour contradicts with description found in docs (in which source tag specify interface in host, not in container). I think, the previous bridge must be specified as interface type='bridge' mac address='00:16:3e:34:21:9e'/ - source bridge='eth10'/ + target dev='eth10'/ /interface You are right. It is bug. Well, here is the patch, that fixes that behaviour. Your patch is half of fix. It require to fix openvzReadNetworkConf() in openvz_conf.c. Here is a new one. Check it, please. Patch looks good. But currently it will work strange because of all drivers (except OpenVZ) in libvirt require specified source bridge=/ - it is generic. With patch you need to specify both source bridge='eth10'/ - to satisfy common requirements target dev='eth10'/ - to create network -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] openvz support in libvirt
Hi, Evgeniy interface type='bridge' source bridge='eth10'/ /interface interface type='ethernet' mac address='00:16:3e:34:21:9e'/ ip address=192.168.122.3 / /interface First, this should be interface type='bridge' mac address='00:16:3e:34:21:9e'/ source bridge='eth10'/ /interface interface type='ethernet' ip address=192.168.122.3 / /interface instead. mac address is optional field. mac is useless for ethernet type. For bridge mac is taken into account. Second. If I understood it right, the following description interface type='bridge' mac address='00:16:3e:34:21:9e'/ source bridge='eth10'/ /interface will result in the (approximataly) following: # vzctl --netiff_add eth10,00:16:3e:34:21:9e yes. This behaviour contradicts with description found in docs (in which source tag specify interface in host, not in container). I think, the previous bridge must be specified as interface type='bridge' mac address='00:16:3e:34:21:9e'/ - source bridge='eth10'/ + target dev='eth10'/ /interface You are right. It is bug. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] openvz support in libvirt
2008/9/19 Evgeniy Sokolov [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] Hello. To start with, I have the following questions: Does libvirt support the xml format for openvz driver described in the next thread? http://www.redhat.com/archives/libvir-list/2008-July/msg00312.html (I think, that it does not. But will it support it in future? :)) What libvirt functionality does openvz driver support? (Openvz does not mentioned in http://libvirt.org/hvsupport.html) Hi Anton, OpenVZ uses generic xml format. It is common for all libvirt drivers. one difference is filesystem: filesystem type=template source name=name of template / target dir=// /filesystem example: domain type='openvz' name210/name Does the 'name ' tag specify domain veid or veid is generated automatically? You need to specify veid. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] read network config in OpenVZ driver
On Wed, Sep 17, 2008 at 08:28:56PM +0400, Evgeniy Sokolov wrote: I attached patch without hunk which was commited by Daniel. Please commit if you are agree with it. A few comments inline.. So you're not artifically restricting the max length of the network name. It is limit in OpenVZ kernel. I did not remove check for max length. Thanks for review. Corrected patch is attached. Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.39 diff -u -p -r1.39 openvz_conf.c --- src/openvz_conf.c 8 Sep 2008 12:45:29 - 1.39 +++ src/openvz_conf.c 18 Sep 2008 11:30:06 - @@ -151,6 +151,146 @@ char *openvzMacToString(const unsigned c return strdup(str); } +/*parse MAC from view: 00:18:51:8F:D9:F3 + return -1 - error + 0 - OK +*/ +static int openvzParseMac(const char *macaddr, unsigned char *mac) +{ +int ret; +ret = sscanf((const char *)macaddr, %02X:%02X:%02X:%02X:%02X:%02X, + (unsigned int*)mac[0], + (unsigned int*)mac[1], + (unsigned int*)mac[2], + (unsigned int*)mac[3], + (unsigned int*)mac[4], + (unsigned int*)mac[5]) ; +if (ret == 6) +return 0; + +return -1; +} + +static virDomainNetDefPtr +openvzReadNetworkConf(virConnectPtr conn, int veid) { +int ret; +virDomainNetDefPtr net = NULL; +virDomainNetDefPtr new_net; +char temp[4096]; +char *token, *saveptr = NULL; + +/*parse routing network configuration* + * Sample from config: + * IP_ADDRESS=1.1.1.1 1.1.1.2 + * splited IPs by space + */ +ret = openvzReadConfigParam(veid, IP_ADDRESS, temp, sizeof(temp)); +if (ret 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Cound not read 'IP_ADDRESS' from config for container %d), + veid); +goto error; +} else if (ret 0) { +token = strtok_r(temp, , saveptr); +while (token != NULL) { +new_net = NULL; +if (VIR_ALLOC(new_net) 0) +goto no_memory; +new_net-next = net; +net = new_net; + +net-type = VIR_DOMAIN_NET_TYPE_ETHERNET; +net-data.ethernet.ipaddr = strdup(token); + +if (net-data.ethernet.ipaddr == NULL) +goto no_memory; + +token = strtok_r(NULL, , saveptr); +} +} + +/*parse bridge devices*/ +/*Sample from config: + *NETIF=ifname=eth10,mac=00:18:51:C1:05:EE,host_ifname=veth105.10,host_mac=00:18:51:8F:D9:F3 + *devices splited by ';' + */ +ret = openvzReadConfigParam(veid, NETIF, temp, sizeof(temp)); +if (ret 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Cound not read 'NETIF' from config for container %d), + veid); +goto error; +} else if (ret 0) { +token = strtok_r(temp, ;, saveptr); +while (token != NULL) { +/*add new device to list*/ +new_net = NULL; +if (VIR_ALLOC(new_net) 0) +goto no_memory; +new_net-next = net; +net = new_net; + +net-type = VIR_DOMAIN_NET_TYPE_BRIDGE; + +char *p = token, *next = token; +char cpy_temp[32]; +int len; + +/*parse string*/ +do { +while (*next != '\0' *next != ',') next++; +if (STRPREFIX(p, ifname=)) { +p += 7; +len = next - p; +if (len 16) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, +_(Too long network device name)); +goto error; +} + +if (VIR_ALLOC_N(net-data.bridge.brname, len+1) 0) +goto no_memory; + +strncpy(net-data.bridge.brname, p, len); +net-data.bridge.brname[len] = '\0'; +} else if (STRPREFIX(p, host_ifname=)) { +p += 12; +//skip in libvirt +} else if (STRPREFIX(p, mac=)) { +p += 4; +len = next - p; +if (len != 17) { //should be 17 +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Wrong length MAC address)); +goto error; +} +strncpy(cpy_temp, p, len); +cpy_temp[len] = '\0'; +if (openvzParseMac(cpy_temp, net-mac)0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Wrong MAC address)); +goto error; +} +} else if (STRPREFIX(p, host_mac
Re: [libvirt] [PATCH] segfailt in openvz driver
On Thu, Sep 11, 2008 at 04:50:53PM +0400, Evgeniy Sokolov wrote: There was segmentation failt in openvz driver during 'create' command if domain with same id exist. Segfault was because of using structure (print warning with name of container) which is free. Hi Evgeniy, I notice that this patch hasn't been applied to CVS. Do you have commit permission or would you like me to apply it? Hi Rich, I have no commit permission. Please, apply and commit the patch. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] read network config in OpenVZ driver
On Mon, Sep 08, 2008 at 03:59:55PM +0400, Evgeniy Sokolov wrote: This patch add possibility to load network configuration for container in OpenVZ driver. It support routing network and bridge devices. This types is currently supported in create/define command. Also, patch contain fix to small bug in openvzReadConfigParam method. Same question as previously - do you have a patch that can be applied? I attached patch without hunk which was commited by Daniel. Please commit if you are agree with it. Index: openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.38 diff -u -p -r1.38 openvz_conf.c --- openvz_conf.c 5 Sep 2008 15:00:14 - 1.38 +++ openvz_conf.c 8 Sep 2008 11:38:48 - @@ -151,6 +151,148 @@ char *openvzMacToString(const unsigned c return strdup(str); } +/*parse MAC from view: 00:18:51:8F:D9:F3 + return -1 - error + 0 - OK +*/ +int openvzParseMac(const char *macaddr, unsigned char *mac) +{ +int ret; +ret = sscanf((const char *)macaddr, %02X:%02X:%02X:%02X:%02X:%02X, + (unsigned int*)mac[0], + (unsigned int*)mac[1], + (unsigned int*)mac[2], + (unsigned int*)mac[3], + (unsigned int*)mac[4], + (unsigned int*)mac[5]) ; +if (ret == 6) +return 0; + +return -1; +} + +virDomainNetDefPtr +openvzReadNetworkConf(virConnectPtr conn, int veid) { +int ret; +virDomainNetDefPtr net = NULL; +virDomainNetDefPtr new_net; +char temp[4096]; +char *token, *saveptr = NULL; + +/*parse routing network configuration* + * Sample from config: + * IP_ADDRESS=1.1.1.1 1.1.1.2 + * splited IPs by space + */ +ret = openvzReadConfigParam(veid, IP_ADDRESS, temp, sizeof(temp)); +if (ret 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Cound not read 'IP_ADDRESS' from config for container %d), + veid); +goto error; +} else if (ret 0) { +token = strtok_r(temp, , saveptr); +while (token != NULL) { +new_net = NULL; +if (VIR_ALLOC(new_net) 0) { +openvzError(conn, VIR_ERR_NO_MEMORY, _(virDomainNetDefPtr)); +goto error; +} +new_net-next = net; +net = new_net; + +net-type = VIR_DOMAIN_NET_TYPE_ETHERNET; +net-data.ethernet.ipaddr = strdup(token); + +token = strtok_r(NULL, , saveptr); +} +} + +/*parse bridge devices*/ +/*Sample from config: + *NETIF=ifname=eth10,mac=00:18:51:C1:05:EE,host_ifname=veth105.10,host_mac=00:18:51:8F:D9:F3 + *devices splited by ';' + */ +ret = openvzReadConfigParam(veid, NETIF, temp, sizeof(temp)); +if (ret 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Cound not read 'NETIF' from config for container %d), + veid); +goto error; +} else if (ret 0) { +token = strtok_r(temp, ;, saveptr); +while (token != NULL) { +/*add new device to list*/ +new_net = NULL; +if (VIR_ALLOC(new_net) 0) { +openvzError(conn, VIR_ERR_NO_MEMORY, _(virDomainNetDefPtr)); +goto error; +} +new_net-next = net; +net = new_net; + +net-type = VIR_DOMAIN_NET_TYPE_BRIDGE; + +char *p = token, *next = token; +char cpy_temp[32]; +int len; + +/*parse string*/ +do { +while (*next != '\0' *next != ',') next++; +if (STREQLEN(ifname=, p, 7)) { +p += 7; +len = next - p; +if (len 16) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, +_(Too long network device name)); +goto error; +} +strncpy(cpy_temp, p, len); +cpy_temp[len] = '\0'; +net-data.bridge.brname = strdup(cpy_temp); + +if (net-data.bridge.brname == NULL) { +openvzError(conn, VIR_ERR_NO_MEMORY, _(Can't strdup)); +goto error; +} + +} else if (STREQLEN(host_ifname=, p, 12)) { +p += 12; +//skip in libvirt +} else if (STREQLEN(mac=, p, 4)) { +p += 4; +len = next - p; +if (len != 17) { //should be 17 +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Wrong length MAC address)); +goto error; +} +strncpy(cpy_temp, p, len); +cpy_temp[len
Re: [libvirt] [PATCH] read network config in OpenVZ driver
On Mon, Sep 08, 2008 at 03:59:55PM +0400, Evgeniy Sokolov wrote: This patch add possibility to load network configuration for container in OpenVZ driver. It support routing network and bridge devices. This types is currently supported in create/define command. Also, patch contain fix to small bug in openvzReadConfigParam method. It was too late to add this to 0.4.5 but ... @@ -298,10 +442,13 @@ openvzReadConfigParam(int vpsid ,const c 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) ; -value[maxlen-1] = '\0'; -found = 1; +if (sf[0] == '=' sf[1] != '\0' ) { +sf ++; +if ((token = strtok_r(sf,\\t\n, saveptr)) != NULL) { +strncpy(value, token, maxlen) ; +value[maxlen-1] = '\0'; +found = 1; +} } } } I commited that bug fix before the release though, Ok. Bug arise only during loading network configuration. Previous method works good without networking. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] PATCH: Fix NULL checks in openvz driver
On Fri, Sep 05, 2008 at 05:40:16PM +0200, Jim Meyering wrote: Daniel P. Berrange [EMAIL PROTECTED] wrote: Jim pointed out some places where the openvz driver could deference some NULs, so this patch fixes them ... Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.46 diff -u -p -r1.46 openvz_driver.c --- src/openvz_driver.c 5 Sep 2008 15:00:14 - 1.46 +++ src/openvz_driver.c 5 Sep 2008 15:11:34 - @@ -276,7 +276,7 @@ static char *openvzDomainDumpXML(virDoma static int openvzDomainShutdown(virDomainPtr dom) { struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; virDomainObjPtr vm = virDomainFindByUUID(driver-domains, dom-uuid); -const char *prog[] = {VZCTL, --quiet, stop, vm-def-name, NULL}; +const char *prog[] = {VZCTL, --quiet, stop, NULL /* name */, NULL}; ... +prog[3] = vm-def-name; if (virRun(dom-conn, prog, NULL) 0) return -1; ... All looks correct. However, I'm a little nervous about hard-coding those '[3]'s. What if someone inserts a new --foo option somewhere before the NULL place-holder, or otherwise rearranges the options? Then we'll have to remember to update that 3 below to e.g., 4. Easy to miss that... I just realized there is a much simpler way todo this... Daniel Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.46 diff -u -p -r1.46 openvz_driver.c --- src/openvz_driver.c 5 Sep 2008 15:00:14 - 1.46 +++ src/openvz_driver.c 8 Sep 2008 09:44:53 - @@ -276,7 +276,7 @@ static char *openvzDomainDumpXML(virDoma static int openvzDomainShutdown(virDomainPtr dom) { struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; virDomainObjPtr vm = virDomainFindByUUID(driver-domains, dom-uuid); -const char *prog[] = {VZCTL, --quiet, stop, vm-def-name, NULL}; +const char *prog[] = {VZCTL, --quiet, stop, vm ? vm-def-name : NULL, NULL}; if (!vm) { openvzError(dom-conn, VIR_ERR_INVALID_DOMAIN, @@ -303,7 +303,7 @@ static int openvzDomainReboot(virDomainP unsigned int flags ATTRIBUTE_UNUSED) { struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; virDomainObjPtr vm = virDomainFindByUUID(driver-domains, dom-uuid); -const char *prog[] = {VZCTL, --quiet, restart, vm-def-name, NULL}; +const char *prog[] = {VZCTL, --quiet, restart, vm ? vm-def-name : NULL, NULL}; if (!vm) { openvzError(dom-conn, VIR_ERR_INVALID_DOMAIN, @@ -581,7 +581,7 @@ openvzDomainCreate(virDomainPtr dom) { struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; virDomainObjPtr vm = virDomainFindByName(driver-domains, dom-name); -const char *prog[] = {VZCTL, --quiet, start, vm-def-name, NULL }; +const char *prog[] = {VZCTL, --quiet, start, vm ? vm-def-name : NULL, NULL }; if (!vm) { openvzError(dom-conn, VIR_ERR_INVALID_DOMAIN, @@ -614,7 +614,7 @@ openvzDomainUndefine(virDomainPtr dom) virConnectPtr conn= dom-conn; struct openvz_driver *driver = (struct openvz_driver *) conn-privateData; virDomainObjPtr vm = virDomainFindByUUID(driver-domains, dom-uuid); -const char *prog[] = { VZCTL, --quiet, destroy, vm-def-name, NULL }; +const char *prog[] = { VZCTL, --quiet, destroy, vm ? vm-def-name : NULL, NULL }; if (!vm) { openvzError(conn, VIR_ERR_INVALID_DOMAIN, _(no domain with matching uuid)); @@ -643,7 +643,7 @@ openvzDomainSetAutostart(virDomainPtr do virConnectPtr conn= dom-conn; struct openvz_driver *driver = (struct openvz_driver *) conn-privateData; virDomainObjPtr vm = virDomainFindByUUID(driver-domains, dom-uuid); -const char *prog[] = { VZCTL, --quiet, set, vm-def-name, +const char *prog[] = { VZCTL, --quiet, set, vm ? vm-def-name : NULL, --onboot, autostart ? yes : no, --save, NULL }; @@ -704,16 +704,9 @@ static int openvzDomainSetVcpus(virDomai struct openvz_driver *driver = (struct openvz_driver *) conn-privateData; virDomainObjPtr vm = virDomainFindByUUID(driver-domains, dom-uuid); char str_vcpus[32]; -const char *prog[] = { VZCTL, --quiet, set, vm-def-name, +const char *prog[] = { VZCTL, --quiet, set, vm ? vm-def-name : NULL, --cpus, str_vcpus, --save, NULL }; -snprintf(str_vcpus, 31, %d, nvcpus); -str_vcpus[31] = '\0'; -if (nvcpus = 0) { -openvzError(conn, VIR_ERR_INTERNAL_ERROR, -_(VCPUs should be = 1)); -return -1; -} if (!vm) { openvzError(conn, VIR_ERR_INVALID_DOMAIN, @@ -721,6 +714,15 @@ static int openvzDomainSetVcpus(virDomai return -1; }
Re: [libvirt] [PATCH] get memory in openvz driver
On Thu, Aug 14, 2008 at 06:08:31PM +0400, Evgeniy Sokolov wrote: On Wed, Aug 13, 2008 at 12:50:33PM +0400, Evgeniy Sokolov wrote: OpenVZ has several parameters for memory management. All of them can be configured independetly. Summing all the different memory limits together is wrong - this will make it impossible to implement a 'setMemory' operation because you've now no way of deciding which parameter to set. It is correct calcuation of total memory. Because of non-obvious implenetation of 'setMemory', I have asked 'how to manage memory' in begining. I propouse to set some portion of 'memory' to each limit. I don't think that will be lead to good behaviour - ultimtely I think we'll need to expose more (all?) of these memory settings directly as tunable resources. Good idea! 5 setting for low memory + application THus for the 'memory' setting we which pick the value which provides the primary memory size as available to apps within the container. In my testing the total memory inside a OpenVZ container seems to correspond to the 'lockedpages' parameter, so we should just return that value. How did you get total memory? Most big part of memory is oomguarpages (by default). Lockedpages is about %1. I've just found read these descriptions... http://wiki.openvz.org/Oomguarpages#oomguarpages http://wiki.openvz.org/Oomguarpages#privvmpages http://wiki.openvz.org/Vmguarpages#vmguarpages To summarize Oomguarpages parameter accounts the total amount of memory and swap space used by the processes of a particular container. Privvmpages parameter accounts allocated (but, possibly, not used yet) memory. The accounted value is an estimation how much memory will be really consumed when the container's applications start to use the allocated memory. Consumed memory is accounted into oomguarpages parameter vmguarpages parameter controls how much memory is available to the Virtual Environment (i.e. how much memory its applications can allocate by malloc(3) or other standard Linux memory allocation mechanisms The memory allocation guarantee (vmguarpages) is a primary tool for controlling the memory available to containers, because it allows administrators to provide Service Level Agreements So from those I'd think that 'vmguarpages' maps best into libvirt's concept of 'memory'. Though perhaps 'oomguardpages' could be set for 'memory' and 'vmguarpages' used for 'max memory' Oomguarpages Privvmpages vmguarpages are settings for apps memory. We may 1 set 'memory' to 'privvmpages' - then free will show correct value. 2 set 'memory' to 'vmguarpages' or 'oomguardpages' and 'maxmemory' to 'privvmpages'. What do 'MaxMemory' mean for other libvirt drivers? Bad point of it, for example: We can set many of Oomguarpages Privvmpages vmguarpages but application can not start because of 'kmemsize' is over. Daniel -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] get memory in openvz driver
OpenVZ has several parameters for memory management. All of them can be configured independetly. Patch allow to get configuration of memory from container config and then calculate total usage of memory. It is open question how to manage memory? Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.33 diff -u -p -r1.33 openvz_conf.c --- src/openvz_conf.c 5 Aug 2008 10:53:05 - 1.33 +++ src/openvz_conf.c 13 Aug 2008 08:32:57 - @@ -138,6 +138,35 @@ strtoI(const char *str) return val; } +/* openvz memory parameters have pattern +456633:2345565 - barrier limit +function split to 2 separate value +*/ +int +splitValues(const char *value, unsigned long *barrier, unsigned long *limit) +{ +if (value == NULL) +return -1; + +if (sscanf(value, %lu:%lu , barrier, limit) != 2) +return -1; + +return 0; +} + +/* function return memory page size +*/ +static long +get_pagesize(void) +{ +long pagesize; +if ((pagesize = sysconf(_SC_PAGESIZE)) == -1) { +/*Unable to get page size*/ + pagesize = 4096; //set default +} +return pagesize; +} + /* function checks MAC address is empty return 0 - empty 1 - not @@ -814,4 +843,310 @@ int openvzAssignUUIDs(void) return 0; } +const char *ubc_names[] = { +KMEMSIZE, +LOCKEDPAGES, +PRIVVMPAGES, +SHMPAGES, +NUMPROC, +PHYSPAGES, +VMGUARPAGES, +OOMGUARPAGES, +NUMTCPSOCK, +NUMFLOCK, +NUMPTY, +NUMSIGINFO, +TCPSNDBUF, +TCPRCVBUF, +OTHERSOCKBUF, +DGRAMRCVBUF, +NUMOTHERSOCK, +NUMFILE, +DCACHESIZE, +NUMIPTENT, +AVNUMPROC, +NULL +}; + +/* function return list of parameters based on +* parameter names +* return pointer to openvz_param or NULL +*/ +static struct openvz_param* +openvzGetEmptyParams(const char *list_names[]) { +int i = 0, count; +struct openvz_param *params; + +/*get count*/ +while(list_names[i] != NULL) +i++; + +if (i == 0) +return NULL; + +count = i + 1; + +if (VIR_ALLOC_N(params, count) 0) /*could not allocate memory*/ +return NULL; + +i = 0; +while(list_names[i] != NULL) { +params[i].name = strdup(list_names[i]); +if (params[i].name == NULL) /*could not allocate memory*/ +break; + +params[i].value = NULL; +i++; +} + +params[i].name = NULL; +params[i].value = NULL; + +return params; +} + +static void +openvzFreeParams(struct openvz_param * params) { +int i = 0; + +if (params == NULL) +return; + +while(params[i].name != NULL) { +VIR_FREE(params[i].name); + +if (params[i].value != NULL) { + VIR_FREE(params[i].value); +} +i++; +} + +VIR_FREE(params); +} + +void +openvzFreeUbParam(struct openvz_ub_param *ub) +{ +if (ub == NULL) +return; +#define FREE_P(x) if (ub-x != NULL) VIR_FREE(ub-x); + +FREE_P(kmemsize) +FREE_P(lockedpages) +FREE_P(privvmpages) +FREE_P(shmpages) +FREE_P(numproc) +FREE_P(physpages) +FREE_P(vmguarpages) +FREE_P(oomguarpages) +FREE_P(numtcpsock) +FREE_P(numflock) +FREE_P(numpty) +FREE_P(numsiginfo) +FREE_P(tcpsndbuf) +FREE_P(tcprcvbuf) +FREE_P(othersockbuf) +FREE_P(dgramrcvbuf) +FREE_P(numothersock) +FREE_P(numfile) +FREE_P(dcachesize) +FREE_P(numiptent) +FREE_P(avnumproc) + +#undef FREE_P +VIR_FREE(ub); +} + +/* +* Read several parameters from container config +* return: -1 - error +* 0 - OK +* TODO: rewrite function to don't read config several times +*/ +static int +openvzReadMultiConfigParams(int vpsid, struct openvz_param *params) +{ +int i = 0; +char value[1024]; +int ret = 0; + +while(params[i].name != NULL) { + ret = openvzReadConfigParam(vpsid, params[i].name, value, 1024); + if (ret 0) + return -1; + if (ret 0) + params[i].value = strdup(value); + /*do nothing if parameter don't found*/ + + i++; +} + +return 0; +} + +/* search parameter in list and return it value +* return pointer to value or NULL +*/ +static char * +openvzGetParamValue(struct openvz_param *params, const char *name) +{ +int j; +for (j = 0; params[j].name != NULL; j++) { +if (STREQ(params[j].name, name)) { +return params[j].value; +} +} +return NULL; +} + +static int +openvzConvertParams2UbParams(struct openvz_param *params, + struct openvz_ub_param *ub) +{ +char *value; +if (ub == NULL || params == NULL) +return -1; + +#define PARAM2UB(param_name, ub_param_name) \ +if ((value = openvzGetParamValue(params, param_name)) != NULL) { \ + if (VIR_ALLOC(ub-ub_param_name) 0) \ + goto error; \ +
[libvirt] [PATCH] manage number of virtual CPUs
OpenVZ containers use all CPUs available in system by default. Limitations may be caused only by Linux kernel limitation. There is way to artificially limit number of CPUs. patch add cpu management functionality to OpenVZ driver. Index: openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.33 diff -u -p -r1.33 openvz_conf.c --- openvz_conf.c 5 Aug 2008 10:53:05 - 1.33 +++ openvz_conf.c 13 Aug 2008 12:49:58 - @@ -513,6 +513,7 @@ openvzGetVPSInfo(virConnectPtr conn) { struct openvz_vm **pnext; struct openvz_driver *driver; struct openvz_vm_def *vmdef; +char temp[124]; vm = NULL; driver = conn-privateData; @@ -569,6 +570,17 @@ openvzGetVPSInfo(virConnectPtr conn) { goto error; } +/*get VCPU*/ +ret = openvzReadConfigParam(veid, CPUS, temp, sizeof(temp)); +if (ret 0) { + openvzError(conn, VIR_ERR_INTERNAL_ERROR, +_(Cound not read config for container %d), veid); + goto error; +} else if (ret 0) { + vmdef-vcpus = strtoI(temp); +} + + (*pnext)-vmdef = vmdef; pnext = (*pnext)-next; } Index: openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.37 diff -u -p -r1.37 openvz_driver.c --- openvz_driver.c 5 Aug 2008 10:53:05 - 1.37 +++ openvz_driver.c 13 Aug 2008 12:49:58 - @@ -94,6 +94,9 @@ static int openvzDomainUndefine(virDomai static void cmdExecFree(char *cmdExec[]); static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid); +static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type); +static int openvzDomainGetMaxVcpus(virDomainPtr dom); +static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus); struct openvz_driver ovz_driver; @@ -266,7 +269,7 @@ static int openvzDomainGetInfo(virDomain //info-cpuTime = //info-maxMem = vm-def-maxmem; //info-memory = vm-def-memory; -//info-nrVirtCpu = vm-def-vcpus; +info-nrVirtCpu = vm-vmdef-vcpus; return 0; } @@ -450,7 +453,6 @@ openvzDomainDefineXML(virConnectPtr conn goto exit; } -//TODO: set number virtual CPUs //TODO: set quota if (virRun(conn, (char **)prog, NULL) 0) { @@ -475,6 +477,14 @@ openvzDomainDefineXML(virConnectPtr conn goto exit; } +if (vmdef-vcpus 0) { +if (openvzDomainSetVcpus(dom, vmdef-vcpus) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not set number of virtual cpu)); + goto exit; +} +} + exit: cmdExecFree(prog); return dom; @@ -548,6 +558,15 @@ openvzDomainCreateLinux(virConnectPtr co dom = virGetDomain(conn, vm-vmdef-name, vm-vmdef-uuid); if (dom) dom-id = vm-vpsid; + +if (vmdef-vcpus 0) { +if (openvzDomainSetVcpus(dom, vmdef-vcpus) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not set number of virtual cpu)); + goto exit; +} +} + exit: cmdExecFree(progcreate); return dom; @@ -662,6 +681,52 @@ openvzDomainGetAutostart(virDomainPtr do return 0; } +static int openvzGetMaxVCPUs(virConnectPtr conn, const char *type) { +if (STRCASEEQ(type, openvz)) +return 4096; //OpenVZ has no limitation + +openvzError(conn, VIR_ERR_INVALID_ARG, + _(unknown type '%s'), type); +return -1; +} + + +static int openvzDomainGetMaxVcpus(virDomainPtr dom) { +return openvzGetMaxVCPUs(dom-conn, openvz); +} + +static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { +virConnectPtr conn= dom-conn; +struct openvz_driver *driver = (struct openvz_driver *) conn-privateData; +struct openvz_vm *vm = openvzFindVMByUUID(driver, dom-uuid); +char str_vcpus[32]; +const char *prog[] = { VZCTL, --quiet, set, vm-vmdef-name, + --cpus, str_vcpus, --save, NULL }; +snprintf(str_vcpus, 31, %d, nvcpus); +str_vcpus[31] = '\0'; + +if (nvcpus = 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(VCPUs should be = 1)); +return -1; +} + +if (!vm) { +openvzError(conn, VIR_ERR_INVALID_DOMAIN, + _(no domain with matching uuid)); +return -1; +} + +if (virRun(conn, (char **)prog, NULL) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not exec %s), VZCTL); +return -1; +} + +vm-vmdef-vcpus = nvcpus; +return 0; +} + static const char *openvzProbe(void) { #ifdef __linux__ @@ -884,7 +949,7 @@ static virDriver openvzDriver = { NULL, /* version */ NULL, /* hostname */ NULL, /* uri */ -NULL,
[libvirt] [PATCH] Save uuid when define/create domain
Hi, There was bug. UUID defined in XML or generated during define/create was not saved to config. Then it was regenerated in virDrvStateInitialize. Attached patch fix bug. Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.32 diff -u -p -r1.32 openvz_conf.c --- src/openvz_conf.c 29 Jul 2008 08:42:56 - 1.32 +++ src/openvz_conf.c 5 Aug 2008 09:51:49 - @@ -736,13 +736,14 @@ openvzGetVPSUUID(int vpsid, char *uuidst /* Do actual checking for UUID presence in conf file, * assign if not present. */ - -static int -openvzSetUUID(int vpsid) +int +openvzSetDefinedUUID(int vpsid, unsigned char *uuid) { char conf_file[PATH_MAX]; char uuidstr[VIR_UUID_STRING_BUFLEN]; -unsigned char uuid[VIR_UUID_BUFLEN]; + +if (uuid == NULL) +return -1; if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)0) return -1; @@ -755,7 +756,6 @@ openvzSetUUID(int vpsid) if (fp == NULL) return -1; -virUUIDGenerate(uuid); virUUIDFormat(uuid, uuidstr); /* Record failure if fprintf or fclose fails, @@ -768,6 +768,15 @@ openvzSetUUID(int vpsid) return 0; } +static int +openvzSetUUID(int vpsid){ +unsigned char uuid[VIR_UUID_BUFLEN]; + +virUUIDGenerate(uuid); + +return openvzSetDefinedUUID(vpsid, uuid); +} + /* * Scan VPS config files and see if they have a UUID. * If not, assign one. Just append one to the config Index: src/openvz_conf.h === RCS file: /data/cvs/libvirt/src/openvz_conf.h,v retrieving revision 1.10 diff -u -p -r1.10 openvz_conf.h --- src/openvz_conf.h 28 Jul 2008 14:06:54 - 1.10 +++ src/openvz_conf.h 5 Aug 2008 09:51:49 - @@ -119,5 +119,6 @@ void openvzFreeVMDef(struct openvz_vm_de int strtoI(const char *str); int openvzCheckEmptyMac(const unsigned char *mac); char *openvzMacToString(const unsigned char *mac); +int openvzSetDefinedUUID(int vpsid, unsigned char *uuid); #endif /* OPENVZ_CONF_H */ Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.36 diff -u -p -r1.36 openvz_driver.c --- src/openvz_driver.c 28 Jul 2008 14:06:54 - 1.36 +++ src/openvz_driver.c 5 Aug 2008 09:51:49 - @@ -459,6 +459,12 @@ openvzDomainDefineXML(virConnectPtr conn goto exit; } +if (openvzSetDefinedUUID(strtoI(vmdef-name), vmdef-uuid) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not set UUID)); +goto exit; +} + dom = virGetDomain(conn, vm-vmdef-name, vm-vmdef-uuid); if (dom) dom-id = vm-vpsid; @@ -514,6 +520,12 @@ openvzDomainCreateLinux(virConnectPtr co goto exit; } +if (openvzSetDefinedUUID(strtoI(vmdef-name), vmdef-uuid) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not set UUID)); +goto exit; +} + if (openvzDomainSetNetwork(conn, vmdef-name, vmdef-net) 0) { openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(Could not configure network)); -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] PATCH: 0/7: Re-factor LXC driver
On Tue, Aug 05, 2008 at 09:04:34PM +0400, Evgeniy V. Sokolov wrote: This is a long overdue followup to my previous set of patches to make the LXC driver use the new domain XML apis. Getting this merged is a blocker for the new libvirt release, now we've turned on LXC by default. Likewise we need to get OpenVZ fully ported to new XML before release too. Daniel, do you plan to finish port of OpenVZ ? or I will do it. I'm happy todo the work to at least port the code, but I don't have a OpenVZ enabled machine, so would neeed someone else to actually test if its works :-) Ideally I think we should aim todo a release next week, so I'll look at whatever the state of the OpenVZ code is this coming weekend, and work from that. Ok. I will be glad to help you with testing and other questions. Regards, Daniel -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] PATCH: Support container XML enhancements
Daniel P. Berrange пишет: eg to use a template called 'fedora9web' as the root filesystem for a container filesystem type='template' source name='fedora9web'/ target dir='/'/ /filesystem Daniel, OpenVZ also require quota tags quota type=size max=1/ quota type=inodes max=20/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] OpenVZ xml refactoring
On Fri, Jul 25, 2008 at 04:44:09PM +0400, Evgeniy Sokolov wrote: Patch switch OpenVZ XML format to generic. main changes: - I used generic virDomainNetDef to define network in container. And wrote function to apply virDomainNetDef for container. Method virDomainNetDefParseXML is public now. - tag container is changed to devices - changed format of tag filesystem - added processing vcpu tag. Generally looks fine to me, just a few remarks +/* Parse filesystem section +Sample: +filesystem type=template + source name=fedora-core-5-i386/ + quota type=size max=1/ + quota type=inodes max=100/ +/filesystem +*/ +static int openvzParseDomainFS(virConnectPtr conn, + struct openvz_fs_def *fs, + xmlXPathContextPtr ctxt) +{ +xmlNodePtr cur, obj; +char *type; + +obj = virXPathNode(/domain/devices/filesystem[1], ctxt); +if (obj == NULL) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(missing filesystem tag)); +return -1; +} hum, maybe use virXPathNodeSet and checking you won't get more than one ? good idea! done /* Extract domain uuid */ -obj = xmlXPathEval(BAD_CAST string(/domain/uuid[1]), ctxt); -if ((obj == NULL) || (obj-type != XPATH_STRING) || -(obj-stringval == NULL) || (obj-stringval[0] == 0)) { +prop = virXPathString(string(./uuid[1]), ctxt); +if (!prop) { int err; Hum, if you start using relative XPath queries like that it's a good idea to make sure ctxt-node is set to the node you're starting the lookup from I don't see that in the patch, maybe I missed it... Yes, you found bug. Fixed now. Thanks! +} else { +if (virUUIDParse(prop, def-uuid) 0) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, +_(malformed uuid element)); +goto bail_out; +} +VIR_FREE(prop); [...] +//TODO: processing NAT and phisical device typo physical :-) In general that looks way cleaner to me, I will give it a few nmore days and apply, unless you suggest another version, fixed patch is attached. Index: src/domain_conf.c === RCS file: /data/cvs/libvirt/src/domain_conf.c,v retrieving revision 1.5 diff -u -p -r1.5 domain_conf.c --- src/domain_conf.c 19 Jul 2008 07:42:34 - 1.5 +++ src/domain_conf.c 28 Jul 2008 13:20:10 - @@ -633,7 +633,7 @@ static void virDomainNetRandomMAC(virDom * @param node XML nodeset to parse for net definition * @return 0 on success, -1 on failure */ -static virDomainNetDefPtr +virDomainNetDefPtr virDomainNetDefParseXML(virConnectPtr conn, xmlNodePtr node) { virDomainNetDefPtr def; Index: src/domain_conf.h === RCS file: /data/cvs/libvirt/src/domain_conf.h,v retrieving revision 1.1 diff -u -p -r1.1 domain_conf.h --- src/domain_conf.h 11 Jul 2008 16:23:36 - 1.1 +++ src/domain_conf.h 28 Jul 2008 13:20:10 - @@ -472,6 +472,9 @@ int virDomainLoadAllConfigs(virConnectPt int virDomainDeleteConfig(virConnectPtr conn, virDomainObjPtr dom); +virDomainNetDefPtr virDomainNetDefParseXML(virConnectPtr conn, +xmlNodePtr node); + VIR_ENUM_DECL(virDomainVirt) VIR_ENUM_DECL(virDomainBoot) VIR_ENUM_DECL(virDomainFeature) Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.30 diff -u -p -r1.30 openvz_conf.c --- src/openvz_conf.c 21 Jul 2008 13:34:19 - 1.30 +++ src/openvz_conf.c 28 Jul 2008 13:20:12 - @@ -56,6 +56,8 @@ #include buf.h #include memory.h #include util.h +#include xml.h +#include domain_conf.h static char *openvzLocateConfDir(void); static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml); @@ -136,6 +138,34 @@ strtoI(const char *str) return val; } +/* function checks MAC address is empty + return 0 - empty + 1 - not +*/ +int openvzCheckEmptyMac(const unsigned char *mac) +{ +int i; +for (i = 0; i VIR_DOMAIN_NET_MAC_SIZE; i++) +if (mac[i] != 0x00) +return 1; + +return 0; +} + +/* convert mac address to string + return pointer to string or NULL +*/ +char *openvzMacToString(const unsigned char *mac) +{ +char str[20]; +if (snprintf(str, 18, %02X:%02X:%02X:%02X:%02X:%02X, + mac[0], mac[1], mac[2], + mac[3], mac[4], mac[5]) = 18) +return NULL; + +return strdup(str); +} + void openvzRemoveInactiveVM(struct openvz_driver *driver, struct openvz_vm *vm) { @@ -148,30 +178,7 @@ void openvzFreeVMDef(struct openvz_vm_def *def) { if (def) { -struct ovz_quota *quota = def-fs.quota; -struct ovz_ip *ip = def-net.ips
[libvirt] [PATCH] OpenVZ xml refactoring
Patch switch OpenVZ XML format to generic. main changes: - I used generic virDomainNetDef to define network in container. And wrote function to apply virDomainNetDef for container. Method virDomainNetDefParseXML is public now. - tag container is changed to devices - changed format of tag filesystem - added processing vcpu tag. Index: src/domain_conf.c === RCS file: /data/cvs/libvirt/src/domain_conf.c,v retrieving revision 1.5 diff -u -p -r1.5 domain_conf.c --- src/domain_conf.c 19 Jul 2008 07:42:34 - 1.5 +++ src/domain_conf.c 25 Jul 2008 12:40:17 - @@ -633,7 +633,7 @@ static void virDomainNetRandomMAC(virDom * @param node XML nodeset to parse for net definition * @return 0 on success, -1 on failure */ -static virDomainNetDefPtr +virDomainNetDefPtr virDomainNetDefParseXML(virConnectPtr conn, xmlNodePtr node) { virDomainNetDefPtr def; Index: src/domain_conf.h === RCS file: /data/cvs/libvirt/src/domain_conf.h,v retrieving revision 1.1 diff -u -p -r1.1 domain_conf.h --- src/domain_conf.h 11 Jul 2008 16:23:36 - 1.1 +++ src/domain_conf.h 25 Jul 2008 12:40:17 - @@ -472,6 +472,9 @@ int virDomainLoadAllConfigs(virConnectPt int virDomainDeleteConfig(virConnectPtr conn, virDomainObjPtr dom); +virDomainNetDefPtr virDomainNetDefParseXML(virConnectPtr conn, +xmlNodePtr node); + VIR_ENUM_DECL(virDomainVirt) VIR_ENUM_DECL(virDomainBoot) VIR_ENUM_DECL(virDomainFeature) Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.30 diff -u -p -r1.30 openvz_conf.c --- src/openvz_conf.c 21 Jul 2008 13:34:19 - 1.30 +++ src/openvz_conf.c 25 Jul 2008 12:40:17 - @@ -56,6 +56,8 @@ #include buf.h #include memory.h #include util.h +#include xml.h +#include domain_conf.h static char *openvzLocateConfDir(void); static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml); @@ -136,6 +138,34 @@ strtoI(const char *str) return val; } +/* function checks MAC address is empty + return 0 - empty + 1 - not +*/ +int openvzCheckEmptyMac(const unsigned char *mac) +{ +int i; +for (i = 0; i VIR_DOMAIN_NET_MAC_SIZE; i++) +if (mac[i] != 0x00) +return 1; + +return 0; +} + +/* convert mac address to string + return pointer to string or NULL +*/ +char *openvzMacToString(const unsigned char *mac) +{ +char str[20]; +if (snprintf(str, 18, %02X:%02X:%02X:%02X:%02X:%02X, + mac[0], mac[1], mac[2], + mac[3], mac[4], mac[5]) = 18) +return NULL; + +return strdup(str); +} + void openvzRemoveInactiveVM(struct openvz_driver *driver, struct openvz_vm *vm) { @@ -148,30 +178,7 @@ void openvzFreeVMDef(struct openvz_vm_def *def) { if (def) { -struct ovz_quota *quota = def-fs.quota; -struct ovz_ip *ip = def-net.ips; -struct ovz_ns *ns = def-net.ns; - -while (quota) { -struct ovz_quota *prev = quota; - -quota = quota-next; -VIR_FREE(prev); -} -while (ip) { -struct ovz_ip *prev = ip; - -ip = ip-next; -VIR_FREE(prev); -} -while (ns) { -struct ovz_ns *prev = ns; - -ns = ns-next; -VIR_FREE(prev); -} - -VIR_FREE(def); +virDomainNetDefFree(def-net); } } @@ -285,6 +292,74 @@ struct openvz_vm_def return def; } +/* Parse filesystem section +Sample: +filesystem type=template + source name=fedora-core-5-i386/ + quota type=size max=1/ + quota type=inodes max=100/ +/filesystem +*/ +static int openvzParseDomainFS(virConnectPtr conn, + struct openvz_fs_def *fs, + xmlXPathContextPtr ctxt) +{ +xmlNodePtr cur, obj; +char *type; + +obj = virXPathNode(/domain/devices/filesystem[1], ctxt); +if (obj == NULL) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(missing filesystem tag)); +return -1; +} + +/*check template type*/ +type = virXMLPropString(obj, type); +if (!type) { + openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(missing type attribute)); + return -1; +} + +if (STRNEQ(type, template)) { + openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Unknown type attribute %s), type); + return -1; +} +VIR_FREE(type); + +cur = obj-children; +while(cur != NULL) +{ +if (cur-type == XML_ELEMENT_NODE) { +if (xmlStrEqual(cur-name, BAD_CAST source)) { + char * name = virXMLPropString(cur,
Re: [libvirt] xml format for openvz driver
On Tue, Jul 22, 2008 at 08:41:36PM +0400, Evgeniy Sokolov wrote: For tag domain/os: need to add ostemplate desirable config Can you explain exactly what the semantics of the two desired attributes are used for ? config is name of sample config for container. It contains many parameters http://wiki.openvz.org/UBC_parameters_table It is desirable because of many customers like to use config. The problem including a 'config' parameter is that this data becomes totally opaque to the management app. Given a piece of XML describing a domain, including a config=' parameter, there's no way for the app to find out what the underlying resources settings are. Can we add to XML some parameters that is in config file? It is because of OpenVZ has no one parameter memory. It consist of many different parameters which can be configured separately: kernel memory, application memory, etc I suppose it will be not generic. How can we desing XML to tune more memory limits? For the filesystem stuff, for LXC we've got a section under devices whcih looks like filesystem type=mount source dir='/some/path'/ target dir='/'/ /filessytem Which says 'make /some/path be the root filesystem, using a bind mount'. I could imagine representing the idea of a template with a slight variation like filesystem type=template source name=template name/ target dir='/'/ /filesystem Yes, we can. But template name is not property of file system. Well, actually I'd argue that it is. The source element refers to the resource in the host OS that forms the source of the filesystem. So for a root filesystem instantiated from a template, I think template name is the most applicable. Sounds good from such point of view. Tag target is useless for OpenVZ. For tag domain/devices/interface: How to describe, if want to add ip addresses for routing network? We'll probably want todo something based on interface type='ethernet' which is a generic catch all config. Does OpenVZ support bridging, or NAT for containers ? bridging is supported. NAT can be configured via iptables. If it supports bridging that is sufficient. The libvirt networking APIs, allow us to implement NAT for any VM in terms of the generic bridge support. Basically libvirt creates a bridge device 'virbr0' and sets up NAT rules for that device. A guest VM simply needs to be connected to virbr0, and then NAT automagically works for it. Do I correctly undertand? For NAT we shoud use tag interface with type bridge and target dev=virbr0 / -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] xml format for openvz driver
Hello! I made review of domain XML format for driver in libvirt. And I have several questions and additions. For tag domain: need to add vmid or id - currenly tag name is used for ID. OpenVZ has mandatory parameter ID, but it also support optional parameter name, which is not implemented for openvz driver now. I plan to support of name in future. For tag domain/os: need to add ostemplate desirable config For tag domain/devices/disk: need to add diskspace desirable diskinodes - it is optional because of disknodes are over very rarely. For tag domain/devices/interface: How to describe, if want to add ip addresses for routing network? Also, OpenVZ may move network adapter to VM (for example, eth1), adapter becomes inaccessible on harware node. How to describe it? Is it ethernet type? Thanks! Evgeniy -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] xml format for openvz driver
On Tue, Jul 22, 2008 at 05:21:41PM +0400, Evgeniy Sokolov wrote: Hello! Hi Evgeniy I made review of domain XML format for driver in libvirt. And I have several questions and additions. For tag domain: need to add vmid or id - currenly tag name is used for ID. OpenVZ has mandatory parameter ID, but it also support optional parameter name, which is not implemented for openvz driver now. I plan to support of name in future. Hum ... the id is usually added as @id in the domain - assuming it is running. The decision to go for the numerical id for the name value was that it was supposed to be permanent and no extra high level naming scheme would appear. IIRC the 'id' name was the one of the subdirectory for the OpenVZ container. How is the new name support added on top of that ? Unless the directory names can now be allocated as name I don't see how the mapping is done. If the new external name is as good as the old id then just replace the id with the external name in name otherwise i wonder what the value of this new naming scheme is and would ignore it For tag domain/os: need to add ostemplate desirable config For tag domain/devices/disk: need to add diskspace desirable diskinodes - it is optional because of disknodes are over very rarely. Hum, could you describe those new fields a bit more ? It is disk quota for container. OpenVZ mount /vz/root/ID into VM as /. It can be changed on running container (increase/decrease). diskinodes is quota for inodes. Inside VM: [EMAIL PROTECTED] /]# df Filesystem 1K-blocks Used Available Use% Mounted on simfs 1048576 96424952152 10% / [EMAIL PROTECTED] /]# df -i FilesystemInodes IUsed IFree IUse% Mounted on simfs 206813 1931874% / For tag domain/devices/interface: How to describe, if want to add ip addresses for routing network? http://libvirt.org/formatdomain.html#elementsNICS and http://libvirt.org/formatnetwork.html#examplesRoute in general in libvirt the networking capabilities are not described per domain but as a separate set of networks with their own definitions. Maybe the OpenVZ driver would have to dynamically add/remove them as domain are instanciated. It would be good to see how the LXC containers plans things too, if we need to extend the model, they should be kept as compatible as possible. Also, OpenVZ may move network adapter to VM (for example, eth1), adapter becomes inaccessible on harware node. How to describe it? Is it ethernet type? Hum, i don't know how i would express that in libvirt Daniel -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] parse container id in separate function
On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote: On Fri, Jul 18, 2008 at 06:02:00PM +0400, Evgeniy Sokolov wrote: There were several places with parsing container id from code. Separate function is used now. Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.29 diff -u -p -r1.29 openvz_conf.c --- src/openvz_conf.c 11 Jul 2008 08:56:16 - 1.29 +++ src/openvz_conf.c 18 Jul 2008 13:21:07 - @@ -134,9 +134,7 @@ strtoI(const char *str) val = (int) strtol(str, endptr, base); /* Check for various possible errors */ -if ((endptr == str) /* No digits were found */ -||((*endptr != '\0') - (*endptr != ' ')) /*Name contain characters other than integers */ ) +if (endptr == str) /* No digits were found */ return 0; return val; } I'd not noticed this function before, but it looks like you could probably just call virStrToLong_i() from the util.h file. Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function. I did not know about virStrToLong_i(). Thanks. Also, I think it would be convenient to create simple function int virStrToLongSimple_i(const char *str, int *result) { char *endptr; return virStrToLong_i(str, endptr, 10, result); } -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] parse container id in separate function
On Mon, Jul 21, 2008 at 01:41:27PM +0400, Evgeniy Sokolov wrote: On Fri, Jul 18, 2008 at 07:16:25PM +0100, Daniel P. Berrange wrote: Right, let's reuse it, but I notice we are using strtol() in a lot of places ...openvz driver is not the worse here especially since it has already an encapsulating function. I did not know about virStrToLong_i(). Thanks. Also, I think it would be convenient to create simple function int virStrToLongSimple_i(const char *str, int *result) { char *endptr; return virStrToLong_i(str, endptr, 10, result); } If you don't want to deal wit the endptr return value, you can simply pass in NULL for that param. from notes: When END_PTR is NULL, the byte after the final valid digit must be NUL. I don't want to deal the endptr. But I want to parse strings like 123 abc. Regards, Daniel -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] cpu usage in OpenVZ
On Thu, Jul 17, 2008 at 03:04:46PM +0400, Evgeniy Sokolov wrote: OpenVZ calculate statistics and allow to get them . Added function for getting cpu usage of container. Modular some minor comments, ACK for this patch. +if (!openvzIsActiveVM(vm)) { +info-cpuTime = 0; +} else { +if (openvzGetProcessInfo((info-cpuTime), dom-id) 0) { +openvzError(dom-conn, VIR_ERR_OPERATION_FAILED, (cannot read cputime for domain)); Need to have a leading '_' in front of the string to be mark for translation. +return -1; +} +} + /* TODO These need to be calculated differently for OpenVZ */ //info-cpuTime = //info-maxMem = vm-def-maxmem; @@ -689,6 +700,48 @@ static int openvzListDefinedDomains(virC return got; } +static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid) { +int fd; +char line[PATH_MAX] ; Best to use something else as the size here - we're not reading a path we should try to eliminate uses of PATH_MAX in libvirt, since POSIX allows for it to be undefine, or stupidly huge. I reckon 1024 would do the job for line length in this case. +if (readvps != vpsid) /*not found*/ +return -1; + +/* convert jiffies to nanoseconds */ +*cpuTime = 1000ull * 1000ull * 1000ull * (usertime + nicetime + systime) / (unsigned long long)sysconf(_SC_CLK_TCK); Can we break this expression across multiple lines to avoid going soo far over 80 chars. Daniel Thanks! I completely forgot basic rules. fixed patch is attached. Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.31 diff -u -p -r1.31 openvz_driver.c --- src/openvz_driver.c 16 Jul 2008 20:42:38 - 1.31 +++ src/openvz_driver.c 18 Jul 2008 09:38:44 - @@ -94,6 +94,8 @@ static int openvzDomainUndefine(virDomai static int convCmdbufExec(char cmdbuf[], char *cmdExec[]); static void cmdExecFree(char *cmdExec[]); +static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid); + struct openvz_driver ovz_driver; static int convCmdbufExec(char cmdbuf[], char *cmdExec[]) @@ -279,6 +281,16 @@ static int openvzDomainGetInfo(virDomain info-state = vm-status; +if (!openvzIsActiveVM(vm)) { +info-cpuTime = 0; +} else { +if (openvzGetProcessInfo((info-cpuTime), dom-id) 0) { +openvzError(dom-conn, VIR_ERR_OPERATION_FAILED, +_(cannot read cputime for domain %d), dom-id); +return -1; +} +} + /* TODO These need to be calculated differently for OpenVZ */ //info-cpuTime = //info-maxMem = vm-def-maxmem; @@ -689,6 +701,51 @@ static int openvzListDefinedDomains(virC return got; } +static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid) { +int fd; +char line[1024] ; +unsigned long long usertime, systime, nicetime; +int readvps = 0, ret; + +/* read statistic from /proc/vz/vestat. +sample: +Version: 2.2 + VEID user nice system uptime idle other.. +33 78 0 1330 59454597 142650441835148 other.. +55 178 0 5340 59424597 542650441835148 other.. +*/ + +if ((fd = open(/proc/vz/vestat, O_RDONLY)) == -1) +return -1; + +/*search line with VEID=vpsid*/ +while(1) { +ret = openvz_readline(fd, line, sizeof(line)); +if(ret = 0) +break; + +if (sscanf(line, %d %llu %llu %llu, + readvps, usertime, nicetime, systime) != 4) +continue; + +if (readvps == vpsid) +break; /*found vpsid*/ +} + +close(fd); +if (ret 0) +return -1; + +if (readvps != vpsid) /*not found*/ +return -1; + +/* convert jiffies to nanoseconds */ +*cpuTime = 1000ull * 1000ull * 1000ull * (usertime + nicetime + systime) + / (unsigned long long)sysconf(_SC_CLK_TCK); + +return 0; +} + static int openvzNumDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED) { return ovz_driver.num_inactive; } -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] parse container id in separate function
There were several places with parsing container id from code. Separate function is used now. Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.29 diff -u -p -r1.29 openvz_conf.c --- src/openvz_conf.c 11 Jul 2008 08:56:16 - 1.29 +++ src/openvz_conf.c 18 Jul 2008 13:21:07 - @@ -134,9 +134,7 @@ strtoI(const char *str) val = (int) strtol(str, endptr, base); /* Check for various possible errors */ -if ((endptr == str) /* No digits were found */ -||((*endptr != '\0') - (*endptr != ' ')) /*Name contain characters other than integers */ ) +if (endptr == str) /* No digits were found */ return 0; return val; } Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.31 diff -u -p -r1.31 openvz_driver.c --- src/openvz_driver.c 16 Jul 2008 20:42:38 - 1.31 +++ src/openvz_driver.c 18 Jul 2008 13:21:07 - @@ -437,7 +437,7 @@ openvzDomainCreateLinux(virConnectPtr co goto exit; } -sscanf(vmdef-name, %d, vm-vpsid); +vm-vpsid = strtoI(vmdef-name); vm-status = VIR_DOMAIN_RUNNING; ovz_driver.num_inactive--; ovz_driver.num_active++; @@ -475,7 +475,7 @@ openvzDomainCreate(virDomainPtr dom) return -1; } -sscanf(vm-vmdef-name, %d, vm-vpsid); +vm-vpsid = strtoI(vm-vmdef-name); vm-status = VIR_DOMAIN_RUNNING; ovz_driver.num_inactive --; ovz_driver.num_active ++; @@ -648,7 +648,7 @@ static int openvzListDomains(virConnectP while(got nids){ ret = openvz_readline(outfd, buf, 32); if(!ret) break; -sscanf(buf, %d, veid); +veid = strtoI(buf); ids[got] = veid; got ++; } @@ -680,7 +680,7 @@ static int openvzListDefinedDomains(virC while(got nnames){ ret = openvz_readline(outfd, buf, 32); if(!ret) break; -sscanf(buf, %d\n, veid); +veid = strtoI(buf); sprintf(vpsname, %d, veid); names[got] = strdup(vpsname); got ++; -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] fix lookup
I am often catching error related with that stoped VM has ID = -1. 1. If I create/define VM with existing ID of stoped VM. Creation failed, but error message is wrong. Detection is fixed. 2. Dominfo command may show info about some another VM. And report error that can't get autostart state. Current patch shoud fix problems. Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.31 diff -u -p -r1.31 openvz_driver.c --- src/openvz_driver.c 16 Jul 2008 20:42:38 - 1.31 +++ src/openvz_driver.c 18 Jul 2008 14:41:44 - @@ -289,7 +289,7 @@ static int openvzDomainGetInfo(virDomain static int openvzDomainShutdown(virDomainPtr dom) { struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; -struct openvz_vm *vm = openvzFindVMByID(driver, dom-id); +struct openvz_vm *vm = openvzFindVMByUUID(driver, dom-uuid); const char *prog[] = {VZCTL, --quiet, stop, vm-vmdef-name, NULL}; if (!vm) { @@ -321,7 +321,7 @@ static int openvzDomainShutdown(virDomai static int openvzDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) { struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; -struct openvz_vm *vm = openvzFindVMByID(driver, dom-id); +struct openvz_vm *vm = openvzFindVMByUUID(driver, dom-uuid); const char *prog[] = {VZCTL, --quiet, restart, vm-vmdef-name, NULL}; if (!vm) { @@ -358,7 +358,7 @@ openvzDomainDefineXML(virConnectPtr conn if ((vmdef = openvzParseVMDef(conn, xml, NULL)) == NULL) return NULL; -vm = openvzFindVMByID(driver, strtoI(vmdef-name)); +vm = openvzFindVMByName(driver, vmdef-name); if (vm) { openvzLog(OPENVZ_ERR, _(Already an OPENVZ VM active with the id '%s'), vmdef-name); @@ -404,7 +404,7 @@ openvzDomainCreateLinux(virConnectPtr co if (!(vmdef = openvzParseVMDef(conn, xml, NULL))) return NULL; -vm = openvzFindVMByID(driver, strtoI(vmdef-name)); +vm = openvzFindVMByName(driver, vmdef-name); if (vm) { openvzFreeVMDef(vmdef); openvzLog(OPENVZ_ERR, @@ -547,7 +547,7 @@ openvzDomainGetAutostart(virDomainPtr do return -1; } -if (openvzReadConfigParam(vm-vpsid , ONBOOT, value, sizeof(value)) 0) { +if (openvzReadConfigParam(strtoI(vm-vmdef-name), ONBOOT, value, sizeof(value)) 0) { openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(Cound not read container config)); return -1; } -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] repeat lookup by name in LookupByID
Daniel Veillard пишет: On Wed, Jul 16, 2008 at 08:10:21PM +0100, Daniel P. Berrange wrote: Yes, the documentation is wrong - all inactive VMs have an ID of -1, and thus lookup-by-ID is nonsensical for inactive VMs. If any application did make use of this change which falls back to lookup-by-name, then it would only ever work with OpenVZ and not any of the other libvirt drivers, which isn't useful behaviour. [...] Then the virLookupById description must be updated, I'm not against it, but we need to be coherent. Indeed, the docs need to be clarified. okay, what about * Try to find a domain based on the hypervisor ID number * Note that this won't work for inactive domains which have an ID of -1, * in that case a lookup based on the Name or UUId need to be done instead. Ok. In that case we may disable lookup-by-id in undefine subcommand. and then revert that specific part of the patch, as attached. Also I would make a 'make rebuild' in the doc directory and push the doc update Daniel Index: virsh.c === RCS file: /data/cvs/libvirt/src/virsh.c,v retrieving revision 1.155 diff -u -p -r1.155 virsh.c --- virsh.c 29 May 2008 14:56:12 - 1.155 +++ virsh.c 17 Jul 2008 09:04:17 - @@ -978,7 +978,8 @@ cmdUndefine(vshControl * ctl, vshCmd * c if (!vshConnectionUsability(ctl, ctl-conn, TRUE)) return FALSE; -if (!(dom = vshCommandOptDomain(ctl, cmd, domain, name))) +if (!(dom = vshCommandOptDomainBy(ctl, cmd, domain, name, + VSH_BYNAME|VSH_BYUUID))) return FALSE; if (virDomainUndefine(dom) == 0) { -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] cpu usage in OpenVZ
OpenVZ calculate statistics and allow to get them . Added function for getting cpu usage of container. Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.31 diff -u -p -r1.31 openvz_driver.c --- src/openvz_driver.c 16 Jul 2008 20:42:38 - 1.31 +++ src/openvz_driver.c 17 Jul 2008 10:50:15 - @@ -94,6 +94,8 @@ static int openvzDomainUndefine(virDomai static int convCmdbufExec(char cmdbuf[], char *cmdExec[]); static void cmdExecFree(char *cmdExec[]); +static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid); + struct openvz_driver ovz_driver; static int convCmdbufExec(char cmdbuf[], char *cmdExec[]) @@ -279,6 +281,15 @@ static int openvzDomainGetInfo(virDomain info-state = vm-status; +if (!openvzIsActiveVM(vm)) { +info-cpuTime = 0; +} else { +if (openvzGetProcessInfo((info-cpuTime), dom-id) 0) { +openvzError(dom-conn, VIR_ERR_OPERATION_FAILED, (cannot read cputime for domain)); +return -1; +} +} + /* TODO These need to be calculated differently for OpenVZ */ //info-cpuTime = //info-maxMem = vm-def-maxmem; @@ -689,6 +700,48 @@ static int openvzListDefinedDomains(virC return got; } +static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid) { +int fd; +char line[PATH_MAX] ; +unsigned long long usertime, systime, nicetime; +int readvps = 0, ret; + +/* read statistic from /proc/vz/vestat. +sample: +Version: 2.2 + VEID user nice system uptime idle other +33 78 0 1330 59454597 142650441835148 other +*/ + +fd = open(/proc/vz/vestat, O_RDONLY); +if (fd == -1) +return -1; + +while(1) { +ret = openvz_readline(fd, line, sizeof(line)); +if(ret = 0) +break; + +if (sscanf(line, %d %llu %llu %llu, readvps, usertime, nicetime, systime) != 4) +continue; + +if (readvps == vpsid) +break; +} + +close(fd); +if (ret 0) +return -1; + +if (readvps != vpsid) /*not found*/ +return -1; + +/* convert jiffies to nanoseconds */ +*cpuTime = 1000ull * 1000ull * 1000ull * (usertime + nicetime + systime) / (unsigned long long)sysconf(_SC_CLK_TCK); + +return 0; +} + static int openvzNumDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED) { return ovz_driver.num_inactive; } -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] repeat lookup by name in LookupByID
There was error every time when I undefine stoped container no domain with matching id. Bug arrise due to stoped container has ID = -1. In such case container will be searched by name. other: use VIR_ERR_NO_DOMAIN when domain is not found Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.28 diff -u -p -r1.28 openvz_driver.c --- src/openvz_driver.c 11 Jul 2008 11:09:44 - 1.28 +++ src/openvz_driver.c 16 Jul 2008 07:51:19 - @@ -128,11 +128,22 @@ static void cmdExecFree(char *cmdExec[]) static virDomainPtr openvzDomainLookupByID(virConnectPtr conn, int id) { struct openvz_driver *driver = (struct openvz_driver *)conn-privateData; -struct openvz_vm *vm = openvzFindVMByID(driver, id); +struct openvz_vm *vm; virDomainPtr dom; +vm = openvzFindVMByID(driver, id); + +if (!vm) { /*try to find by name*/ +char name[OPENVZ_NAME_MAX]; +if (snprintf(name, OPENVZ_NAME_MAX, %d,id) = OPENVZ_NAME_MAX) { +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(Too long domain name)); +return NULL; +} +vm = openvzFindVMByName(driver, name); +} + if (!vm) { -openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(no domain with matching id)); +openvzError(conn, VIR_ERR_NO_DOMAIN, NULL); return NULL; } @@ -160,7 +171,7 @@ static virDomainPtr openvzDomainLookupBy virDomainPtr dom; if (!vm) { -openvzError(conn, VIR_ERR_INVALID_DOMAIN, _(no domain with matching uuid)); +openvzError(conn, VIR_ERR_NO_DOMAIN, NULL); return NULL; } @@ -181,7 +192,7 @@ static virDomainPtr openvzDomainLookupBy virDomainPtr dom; if (!vm) { -openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(no domain with matching name)); +openvzError(conn, VIR_ERR_NO_DOMAIN, NULL); return NULL; } -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] cleanup functions which exec OpenVZ tools
Patch improve code which execute external OpenVZ tools. +/* generate arguments to create OpenVZ container + return -1 - error + 0 - OK +*/ +static int openvzDomainDefineCmd(const char *args[], int maxarg, struct openvz_vm_def *vmdef) Rather than passing in the pre-allocated args array of a fixed length, grab the 'ADD_ARG' and 'ADD_ARG_LIT' macros from the qemu_conf.c file in the qemudBuildCommandLine() method. They let you easily dynamically grow the argv as required, without complicating the code significantly. I thought about it, but I planned to add in one of next patches. Thanks for review! fixed patch is attached. Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.28 diff -u -p -r1.28 openvz_driver.c --- src/openvz_driver.c 11 Jul 2008 11:09:44 - 1.28 +++ src/openvz_driver.c 14 Jul 2008 12:01:46 - @@ -56,6 +56,7 @@ #include util.h #include openvz_conf.h #include nodeinfo.h +#include memory.h #define OPENVZ_MAX_ARG 28 #define CMDBUF_LEN 1488 @@ -120,11 +121,79 @@ static void cmdExecFree(char *cmdExec[]) int i=-1; while(cmdExec[++i]) { -free(cmdExec[i]); -cmdExec[i] = NULL; +VIR_FREE(cmdExec[i]); } } +/* generate arguments to create OpenVZ container + return -1 - error + 0 - OK +*/ +static int openvzDomainDefineCmd(virConnectPtr conn, + char *args[], + int maxarg, + struct openvz_vm_def *vmdef) +{ +int narg; + +for (narg = 0; narg maxarg; narg++) +args[narg] = NULL; + +if (vmdef == NULL){ +openvzError(conn, VIR_ERR_INTERNAL_ERROR, + _(Container is not defined)); +return -1; +} + +#define ADD_ARG(thisarg)\ +do {\ +if (narg = maxarg) \ + goto no_memory;\ +args[narg++] = thisarg; \ +} while (0) + +#define ADD_ARG_LIT(thisarg)\ +do {\ +if (narg = maxarg) \ + goto no_memory;\ +if ((args[narg++] = strdup(thisarg)) == NULL) \ +goto no_memory; \ +} while (0) + +narg = 0; +ADD_ARG_LIT(VZCTL); +ADD_ARG_LIT(--quiet); +ADD_ARG_LIT(create); +ADD_ARG_LIT(vmdef-name); + +if ((vmdef-fs.tmpl *(vmdef-fs.tmpl))) { +ADD_ARG_LIT(--ostemplate); +ADD_ARG_LIT(vmdef-fs.tmpl); +} +if ((vmdef-profile *(vmdef-profile))) { +ADD_ARG_LIT(--config); +ADD_ARG_LIT(vmdef-profile); +} +if ((vmdef-net.ips-ip *(vmdef-net.ips-ip))) { +ADD_ARG_LIT(--ipadd); +ADD_ARG_LIT(vmdef-net.ips-ip); +} +if ((vmdef-net.hostname *(vmdef-net.hostname))) { +ADD_ARG_LIT(--hostname); +ADD_ARG_LIT(vmdef-net.hostname); +} + +ADD_ARG(NULL); +return 0; + no_memory: +openvzError(conn, VIR_ERR_INTERNAL_ERROR, +_(Could not put argument to %s), VZCTL); +return -1; +#undef ADD_ARG +#undef ADD_ARG_LIT +} + + static virDomainPtr openvzDomainLookupByID(virConnectPtr conn, int id) { struct openvz_driver *driver = (struct openvz_driver *)conn-privateData; @@ -217,12 +286,9 @@ static int openvzDomainGetInfo(virDomain } static int openvzDomainShutdown(virDomainPtr dom) { -char cmdbuf[CMDBUF_LEN]; -int ret; -char *cmdExec[OPENVZ_MAX_ARG]; -int pid, outfd, errfd; struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; struct openvz_vm *vm = openvzFindVMByID(driver, dom-id); +const char *prog[] = {VZCTL, --quiet, stop, vm-vmdef-name, NULL}; if (!vm) { openvzError(dom-conn, VIR_ERR_INVALID_DOMAIN, @@ -235,16 +301,8 @@ static int openvzDomainShutdown(virDomai _(domain is not in running state)); return -1; } -snprintf(cmdbuf, CMDBUF_LEN - 1, VZCTL stop %d , dom-id); -if((ret = convCmdbufExec(cmdbuf, cmdExec)) == -1) -{ -openvzLog(OPENVZ_ERR, %s, _(Error in parsing Options to OPENVZ)); -goto bail_out; -} - -ret = virExec(dom-conn, (char **)cmdExec, pid, -1, outfd, errfd); -if(ret == -1) { +if (virRun(dom-conn, (char **)prog, NULL) 0) { openvzError(dom-conn, VIR_ERR_INTERNAL_ERROR, _(Could not exec %s), VZCTL); return -1; @@ -255,20 +313,14 @@ static int
[libvirt] [PATCH] default URI in probe
I specified default URI in probe(). To use libvirt with OpenVZ: # ./configure --with-openvz # make # ./src/virsh list Id Name State -- 33 33 running 105 105 running 108 108 running Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.27 diff -u -r1.27 openvz_driver.c --- src/openvz_driver.c 10 Jul 2008 12:21:09 - 1.27 +++ src/openvz_driver.c 11 Jul 2008 10:28:59 - @@ -599,7 +599,7 @@ { #ifdef __linux__ if ((getuid() == 0) (virFileExists(/proc/vz))) -return(openvz:///); +return(openvz:///system); #endif return(NULL); } -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] cleanup functions which exec OpenVZ tools
Patch improve code which execute external OpenVZ tools. ? src/test.xml Index: src/openvz_driver.c === RCS file: /data/cvs/libvirt/src/openvz_driver.c,v retrieving revision 1.28 diff -u -p -r1.28 openvz_driver.c --- src/openvz_driver.c 11 Jul 2008 11:09:44 - 1.28 +++ src/openvz_driver.c 11 Jul 2008 15:50:22 - @@ -125,6 +125,61 @@ static void cmdExecFree(char *cmdExec[]) } } +/* generate arguments to create OpenVZ container + return -1 - error + 0 - OK +*/ +static int openvzDomainDefineCmd(const char *args[], int maxarg, struct openvz_vm_def *vmdef) +{ +int narg; + +if (vmdef == NULL) +return -1; + +for (narg = 0; narg maxarg; narg++) +args[narg] = NULL; + +narg = 0; +if (narg + 4 maxarg) { +args[narg++] = VZCTL; +args[narg++] = --quiet; +args[narg++] = create; +args[narg++] = vmdef-name; +} else +return -1; + +if ((vmdef-fs.tmpl *(vmdef-fs.tmpl))) { +if (narg + 2 = maxarg) +return -1; +args[narg++] = --ostemplate; +args[narg++] = vmdef-fs.tmpl; +} +if ((vmdef-profile *(vmdef-profile))) { +if (narg + 2 = maxarg) +return -1; +args[narg++] = --config; +args[narg++] = vmdef-profile; +} +if ((vmdef-net.ips-ip *(vmdef-net.ips-ip))) { + if (narg + 2 = maxarg) +return -1; +args[narg++] = --ipadd; +args[narg++] = vmdef-net.ips-ip; +} +if ((vmdef-net.hostname *(vmdef-net.hostname))) { +if (narg + 2 = maxarg) +return -1; +args[narg++] = --hostname; +args[narg++] = vmdef-net.hostname; +} + +if (args[maxarg-1] != NULL) //for sure +return -1; + +return 0; +} + + static virDomainPtr openvzDomainLookupByID(virConnectPtr conn, int id) { struct openvz_driver *driver = (struct openvz_driver *)conn-privateData; @@ -217,12 +272,9 @@ static int openvzDomainGetInfo(virDomain } static int openvzDomainShutdown(virDomainPtr dom) { -char cmdbuf[CMDBUF_LEN]; -int ret; -char *cmdExec[OPENVZ_MAX_ARG]; -int pid, outfd, errfd; struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; struct openvz_vm *vm = openvzFindVMByID(driver, dom-id); +const char *prog[] = {VZCTL, --quiet, stop, vm-vmdef-name, NULL}; if (!vm) { openvzError(dom-conn, VIR_ERR_INVALID_DOMAIN, @@ -235,16 +287,8 @@ static int openvzDomainShutdown(virDomai _(domain is not in running state)); return -1; } -snprintf(cmdbuf, CMDBUF_LEN - 1, VZCTL stop %d , dom-id); -if((ret = convCmdbufExec(cmdbuf, cmdExec)) == -1) -{ -openvzLog(OPENVZ_ERR, %s, _(Error in parsing Options to OPENVZ)); -goto bail_out; -} - -ret = virExec(dom-conn, (char **)cmdExec, pid, -1, outfd, errfd); -if(ret == -1) { +if (virRun(dom-conn, (char **)prog, NULL) 0) { openvzError(dom-conn, VIR_ERR_INTERNAL_ERROR, _(Could not exec %s), VZCTL); return -1; @@ -255,20 +299,14 @@ static int openvzDomainShutdown(virDomai ovz_driver.num_inactive ++; ovz_driver.num_active --; -bail_out: -cmdExecFree(cmdExec); - -return ret; +return 0; } static int openvzDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) { -char cmdbuf[CMDBUF_LEN]; -int ret; -char *cmdExec[OPENVZ_MAX_ARG]; -int pid, outfd, errfd; struct openvz_driver *driver = (struct openvz_driver *)dom-conn-privateData; struct openvz_vm *vm = openvzFindVMByID(driver, dom-id); +const char *prog[] = {VZCTL, --quiet, restart, vm-vmdef-name, NULL}; if (!vm) { openvzError(dom-conn, VIR_ERR_INVALID_DOMAIN, @@ -281,24 +319,14 @@ static int openvzDomainReboot(virDomainP _(domain is not in running state)); return -1; } -snprintf(cmdbuf, CMDBUF_LEN - 1, VZCTL restart %d , dom-id); -if((ret = convCmdbufExec(cmdbuf, cmdExec)) == -1) -{ -openvzLog(OPENVZ_ERR, %s, _(Error in parsing Options to OPENVZ)); -goto bail_out1; -} -ret = virExec(dom-conn, (char **)cmdExec, pid, -1, outfd, errfd); -if(ret == -1) { +if (virRun(dom-conn, (char **)prog, NULL) 0) { openvzError(dom-conn, VIR_ERR_INTERNAL_ERROR, _(Could not exec %s), VZCTL); return -1; } -bail_out1: -cmdExecFree(cmdExec); - -return ret; +return 0; } static virDomainPtr @@ -308,63 +336,39 @@ openvzDomainDefineXML(virConnectPtr conn struct openvz_vm_def *vmdef = NULL; struct openvz_vm *vm = NULL; virDomainPtr dom; -char cmdbuf[CMDBUF_LEN], cmdOption[CMDOP_LEN], *cmdExec[OPENVZ_MAX_ARG]; -int ret, pid, outfd, errfd; +const char *prog[OPENVZ_MAX_ARG]; -if (!(vmdef =
[libvirt] [PATCH] renaming error - openvzError
function error() was renamed to openvzError() to don't conflict with other functions with the same name. other - openvzError() is added to msg_gen_function - fixed to pass make syntax-check Thanks to Jim Meyering for review. Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.27 diff -u -p -r1.27 openvz_conf.c --- src/openvz_conf.c 10 Jul 2008 07:52:14 - 1.27 +++ src/openvz_conf.c 10 Jul 2008 11:21:56 - @@ -62,7 +62,7 @@ static int openvzGetVPSUUID(int vpsid, c static int openvzSetUUID(int vpsid); void -error (virConnectPtr conn, virErrorNumber code, const char *fmt, ...) +openvzError (virConnectPtr conn, virErrorNumber code, const char *fmt, ...) { va_list args; char errorMessage[OPENVZ_MAX_ERROR_LEN]; @@ -254,7 +254,7 @@ openvzAssignVMDef(virConnectPtr conn, if (VIR_ALLOC(vm) 0) { openvzFreeVMDef(def); -error(conn, VIR_ERR_NO_MEMORY, vm); +openvzError(conn, VIR_ERR_NO_MEMORY, _(vm)); return NULL; } @@ -279,7 +279,7 @@ struct openvz_vm_def xml = xmlReadDoc(BAD_CAST xmlStr, displayName ? displayName : domain.xml, NULL, XML_PARSE_NOENT | XML_PARSE_NONET | XML_PARSE_NOERROR | XML_PARSE_NOWARNING); if (!xml) { -error(conn, VIR_ERR_XML_ERROR, NULL); +openvzError(conn, VIR_ERR_XML_ERROR, NULL); return NULL; } @@ -305,7 +305,7 @@ static struct openvz_vm_def struct ovz_ns *ovzNs; if (VIR_ALLOC(def) 0) { -error(conn, VIR_ERR_NO_MEMORY, xmlXPathContext); +openvzError(conn, VIR_ERR_NO_MEMORY, _(xmlXPathContext)); return NULL; } @@ -313,24 +313,24 @@ static struct openvz_vm_def root = xmlDocGetRootElement(xml); if ((root == NULL) || (!xmlStrEqual(root-name, BAD_CAST domain))) { -error(conn, VIR_ERR_INTERNAL_ERROR, _(incorrect root element)); +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(incorrect root element)); goto bail_out; } ctxt = xmlXPathNewContext(xml); if (ctxt == NULL) { -error(conn, VIR_ERR_NO_MEMORY, xmlXPathContext); +openvzError(conn, VIR_ERR_NO_MEMORY, _(xmlXPathContext)); goto bail_out; } /* Find out what type of OPENVZ virtualization to use */ if (!(prop = xmlGetProp(root, BAD_CAST type))) { -error(conn, VIR_ERR_INTERNAL_ERROR, _(missing domain type attribute)); +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(missing domain type attribute)); goto bail_out; } if (STRNEQ((char *)prop, openvz)){ -error(conn, VIR_ERR_INTERNAL_ERROR, _(invalid domain type attribute)); +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(invalid domain type attribute)); goto bail_out; } VIR_FREE(prop); @@ -339,13 +339,13 @@ static struct openvz_vm_def obj = xmlXPathEval(BAD_CAST string(/domain/name[1]), ctxt); if ((obj == NULL) || (obj-type != XPATH_STRING) || (obj-stringval == NULL) || (obj-stringval[0] == 0)) { -error(conn, VIR_ERR_INTERNAL_ERROR, _(invalid domain name)); +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(invalid domain name)); goto bail_out; } /* rejecting VPS ID = OPENVZ_RSRV_VM_LIMIT for they are reserved */ if (strtoI((const char *) obj-stringval) = OPENVZ_RSRV_VM_LIMIT) { -error(conn, VIR_ERR_INTERNAL_ERROR, +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(VPS ID Error (must be an integer greater than 100)); goto bail_out; } @@ -359,11 +359,11 @@ static struct openvz_vm_def int err; if ((err = virUUIDGenerate(def-uuid))) { -error(conn, VIR_ERR_INTERNAL_ERROR, _(Failed to generate UUID)); +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(Failed to generate UUID)); goto bail_out; } } else if (virUUIDParse((const char *)obj-stringval, def-uuid) 0) { -error(conn, VIR_ERR_INTERNAL_ERROR, _(malformed uuid element)); +openvzError(conn, VIR_ERR_INTERNAL_ERROR, _(malformed uuid element)); goto bail_out; } xmlXPathFreeObject(obj); @@ -372,7 +372,7 @@ static struct openvz_vm_def obj = xmlXPathEval(BAD_CAST string(/domain/container/filesystem/template[1]), ctxt); if ((obj == NULL) || (obj-type != XPATH_STRING) || (obj-stringval == NULL) || (obj-stringval[0] == 0)) { -error(conn, VIR_ERR_OS_TYPE, NULL); +openvzError(conn, VIR_ERR_OS_TYPE, NULL); goto bail_out; } strncpy(def-fs.tmpl, (const char *) obj-stringval, OPENVZ_TMPL_MAX); @@ -393,11 +393,8 @@ static struct openvz_vm_def xml-name); } if (xmlStrlen(obj-stringval) = (OPENVZ_IP_MAX)) { -char errorMessage[OPENVZ_MAX_ERROR_LEN]; - -snprintf(errorMessage, OPENVZ_MAX_ERROR_LEN - 1, %s, - _(ipaddress length too
[libvirt] bug in libvirt.c?
for (i = 0; i virNetworkDriverTabCount; i++) { if ((virDriverTab[i]-probe != NULL) ((latest = virDriverTab[i]-probe()) != NULL)) { probes++; . } } We use array virDriverTab, but cicle is to virNetworkDriverTabCount which count number of virNetworkDriverTab drivers. I think virDriverTabCount should be used. Index: libvirt.c === RCS file: /data/cvs/libvirt/src/libvirt.c,v retrieving revision 1.147 diff -u -p -r1.147 libvirt.c --- libvirt.c 26 Jun 2008 09:37:51 - 1.147 +++ libvirt.c 10 Jul 2008 14:48:44 - @@ -699,7 +699,7 @@ do_open (const char *name, const char *use = NULL; const char *latest; int probes = 0; -for (i = 0; i virNetworkDriverTabCount; i++) { +for (i = 0; i virDriverTabCount; i++) { if ((virDriverTab[i]-probe != NULL) ((latest = virDriverTab[i]-probe()) != NULL)) { probes++; -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] using one function to locate OpenVZ config files
There were 3 places with the same code. I moved it to separate function. other: use O_RDONLY to read config file Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.28 diff -u -a -r1.28 openvz_conf.c --- src/openvz_conf.c 10 Jul 2008 12:21:09 - 1.28 +++ src/openvz_conf.c 10 Jul 2008 16:43:06 - @@ -60,6 +60,7 @@ static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml); static int openvzGetVPSUUID(int vpsid, char *uuidstr); static int openvzSetUUID(int vpsid); +static int openvzLocateConfFile(int vpsid, char *conffile, int maxlen); void openvzError (virConnectPtr conn, virErrorNumber code, const char *fmt, ...) @@ -595,20 +596,13 @@ 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; - -if (snprintf(conf_file, PATH_MAX, %s/%d.conf, conf_dir,vpsid) = PATH_MAX) +if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)0) return -1; -VIR_FREE(conf_dir); - value[0] = 0; fd = open(conf_file, O_RDONLY); @@ -638,6 +632,27 @@ return ret ; } +/* Locate config file of container +* return -1 - error +* 0 - OK +*/ +static int +openvzLocateConfFile(int vpsid, char *conffile, int maxlen) +{ +char * confdir; +int ret = 0; + +confdir = openvzLocateConfDir(); +if (confdir == NULL) +return -1; + +if (snprintf(conffile, maxlen, %s/%d.conf, confdir, vpsid) = maxlen) +ret = -1; + +VIR_FREE(confdir); +return ret; +} + static char *openvzLocateConfDir(void) { @@ -686,16 +701,12 @@ char line[1024]; char uuidbuf[1024]; char iden[1024]; -char *conf_dir; int fd, ret; -conf_dir = openvzLocateConfDir(); -if (conf_dir == NULL) -return -1; -sprintf(conf_file, %s/%d.conf, conf_dir, vpsid); -VIR_FREE(conf_dir); + if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)0) + return -1; -fd = open(conf_file, O_RDWR); +fd = open(conf_file, O_RDONLY); if(fd == -1) return -1; @@ -730,13 +741,9 @@ char conf_file[PATH_MAX]; char uuidstr[VIR_UUID_STRING_BUFLEN]; unsigned char uuid[VIR_UUID_BUFLEN]; -char *conf_dir; -conf_dir = openvzLocateConfDir(); -if (conf_dir == NULL) -return -1; -sprintf(conf_file, %s/%d.conf, conf_dir, vpsid); -VIR_FREE(conf_dir); + if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)0) + return -1; if (openvzGetVPSUUID(vpsid, uuidstr)) return -1; -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] fix diagnostic when execute openvz commands
This really needs to be changed to pass through gettext, eg error(dom-conn, VIR_ERR_INTERNAL_ERROR, _(Could not exec %s), VZCTL); NB, we have to use a %s format string when going via gettext rather than just allowing the preprocessor to do string concatenation for us. Ok, it need. Thanks! fixed patch is attached. Index: 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 --- openvz_conf.c 12 Jun 2008 13:48:29 - 1.25 +++ openvz_conf.c 9 Jul 2008 10:08:49 - @@ -57,21 +57,29 @@ #include memory.h static char *openvzLocateConfDir(void); -static void error (virConnectPtr conn, virErrorNumber code, const char *info); static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml); static int openvzGetVPSUUID(int vpsid, char *uuidstr); static int openvzSetUUID(int vpsid); -/* For errors internal to this library. */ -static void -error (virConnectPtr conn, virErrorNumber code, const char *info) +void +error (virConnectPtr conn, virErrorNumber code, const char *fmt, ...) { +va_list args; +char errorMessage[OPENVZ_MAX_ERROR_LEN]; const char *errmsg; -errmsg = __virErrorMsg (code, info); +if (fmt) { +va_start(args, fmt); +vsnprintf(errorMessage, OPENVZ_MAX_ERROR_LEN-1, fmt, args); +va_end(args); +} else { +errorMessage[0] = '\0'; +} + +errmsg = __virErrorMsg(code, (errorMessage[0] ? errorMessage : NULL)); __virRaiseError (conn, NULL, NULL, VIR_FROM_OPENVZ, - code, VIR_ERR_ERROR, errmsg, info, NULL, 0, 0, - errmsg, info); + code, VIR_ERR_ERROR, errmsg, errorMessage, NULL, 0, 0, + errmsg, errorMessage); } struct openvz_vm Index: 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 --- openvz_conf.h 5 Feb 2008 19:27:37 - 1.6 +++ openvz_conf.h 9 Jul 2008 10:08:49 - @@ -110,6 +110,7 @@ openvzIsActiveVM(struct openvz_vm *vm) return vm-vpsid != -1; } +void error (virConnectPtr conn, virErrorNumber code, const char *fmt, ...); int openvz_readline(int fd, char *ptr, int maxlen); struct openvz_vm *openvzFindVMByID(const struct openvz_driver *driver, int id); struct openvz_vm *openvzFindVMByUUID(const struct openvz_driver *driver, Index: 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 --- openvz_driver.c 7 Jul 2008 11:48:40 - 1.23 +++ openvz_driver.c 9 Jul 2008 10:08:49 - @@ -125,18 +125,6 @@ static void cmdExecFree(char *cmdExec[]) } } -/* For errors internal to this library. */ -static void -error (virConnectPtr conn, virErrorNumber code, const char *info) -{ -const char *errmsg; - -errmsg = __virErrorMsg (code, info); -__virRaiseError (conn, NULL, NULL, VIR_FROM_OPENVZ, - code, VIR_ERR_ERROR, errmsg, info, NULL, 0, 0, - errmsg, info); -} - static virDomainPtr openvzDomainLookupByID(virConnectPtr conn, int id) { struct openvz_driver *driver = (struct openvz_driver *)conn-privateData; @@ -257,7 +245,8 @@ static int openvzDomainShutdown(virDomai ret = virExec(dom-conn, (char **)cmdExec, pid, -1, outfd, errfd); if(ret == -1) { -error(dom-conn, VIR_ERR_INTERNAL_ERROR, Could not exec VZLIST); +error(dom-conn, VIR_ERR_INTERNAL_ERROR, + _(Could not exec %s), VZCTL); return -1; } @@ -301,7 +290,8 @@ static int openvzDomainReboot(virDomainP } ret = virExec(dom-conn, (char **)cmdExec, pid, -1, outfd, errfd); if(ret == -1) { -error(dom-conn, VIR_ERR_INTERNAL_ERROR, Could not exec VZLIST); +error(dom-conn, VIR_ERR_INTERNAL_ERROR, + _(Could not exec %s), VZCTL); return -1; } @@ -360,7 +350,8 @@ openvzDomainDefineXML(virConnectPtr conn } ret = virExec(conn, (char **)cmdExec, pid, -1, outfd, errfd); if(ret == -1) { -error(conn, VIR_ERR_INTERNAL_ERROR, Could not exec VZLIST); +error(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not exec %s), VZCTL); goto bail_out2; } @@ -428,7 +419,8 @@ openvzDomainCreateLinux(virConnectPtr co } ret = virExec(conn, (char **)cmdExec, pid, -1, outfd, errfd); if(ret == -1) { -error(conn, VIR_ERR_INTERNAL_ERROR, Could not exec VZLIST); +error(conn, VIR_ERR_INTERNAL_ERROR, + _(Could not exec %s), VZCTL); return NULL; } @@ -444,7 +436,8 @@ openvzDomainCreateLinux(virConnectPtr co } ret = virExec(conn, (char **)cmdExec, pid, -1,
Re: [libvirt] [PATCH] SetAutostart and GetAutostart in openvz driver
I realize you are just following the existing pattern used in OpenVZ driver, but this piece of code is horrible. sprintf'ing into a string, then parsing that string and turning it back into a list of argv[] strings, with no escaping of special characters, or quoting. eg if the vm name had a space in it it'll mis-parse it. In fact, names of VMs are always numbers in OpenVZ. Just declare the command argv straight into a char*[], eg const char *prog[] = { VZCTL, set, vm-vmdef-name, --onboot, autostart ? yes : no, --save } ret = virExec(conn, prog, pid, -1, outfd, errfd) See the storage_backend_logical.c file for examples of this kind of approach We should put other uses of convCmdbufExec() on the TODO list for removal in the future. Ok. Moreover, many code is needed to rewrite. Daniel, thanks for review! fixed patch is attached. Index: src/openvz_conf.c === RCS file: /data/cvs/libvirt/src/openvz_conf.c,v retrieving revision 1.26 diff -u -p -r1.26 openvz_conf.c --- src/openvz_conf.c 9 Jul 2008 11:55:27 - 1.26 +++ src/openvz_conf.c 9 Jul 2008 14:23:18 - @@ -603,6 +603,63 @@ 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; + +if (snprintf(conf_file, PATH_MAX,%s/%d.conf,conf_dir,vpsid) = PATH_MAX) +return -1; + +VIR_FREE(conf_dir); + +value[0] = 0; + +fd = open(conf_file, O_RDONLY); +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) ; +value[maxlen-1] = '\0'; +found = 1; +} + } +} +close(fd); + +if (ret == 0 found) +ret = 1; + +return ret ; +} + static char *openvzLocateConfDir(void) { @@ -680,6 +737,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.7 diff -u -p -r1.7 openvz_conf.h --- src/openvz_conf.h 9 Jul 2008 11:55:27 - 1.7 +++ src/openvz_conf.h 9 Jul 2008 14:23:18 - @@ -112,6 +112,7 @@ openvzIsActiveVM(struct openvz_vm *vm) void error (virConnectPtr conn, virErrorNumber code, const char *fmt, ...); 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.24 diff -u -p -r1.24 openvz_driver.c --- src/openvz_driver.c 9 Jul 2008 11:55:27 - 1.24 +++ src/openvz_driver.c 9 Jul 2008 14:23:18 - @@ -547,6 +547,54 @@ bail_out5: return ret; } +static int +openvzDomainSetAutostart(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); +const char *prog[] = { VZCTL, set, vm-vmdef-name, + --onboot, autostart ? yes : no, + --save, NULL }; + +if (!vm) { +error(conn, VIR_ERR_INVALID_DOMAIN, _(no domain with matching uuid)); +return -1; +} + +if (virRun(conn, (char **)prog, NULL) 0) { +error(conn, VIR_ERR_INTERNAL_ERROR, _(Could not exec %s), VZCTL); +return -1; +} + +return 0; +} + +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; +} +