Fix misc syntax problems with open nebula driver

This commit is contained in:
Daniel P. Berrange 2009-05-28 13:11:22 +00:00
parent dcd9865385
commit ee8553e156
7 changed files with 215 additions and 201 deletions

View File

@ -1,3 +1,14 @@
Thu May 28 14:11:30 BST 2009 Daniel P. Berrange <berrange@redhat.com>
Fix misc syntax check failures with OpenNebula driver
* src/opennebula/one_conf.c, src/opennebula/one_conf.h,
src/opennebula/one_driver.c, src/opennebula/one_driver.h: Kill
trailing whitespace, automatic re-indent of all code, added
missing translation marking
* Makefile.maint: Add oneError() as a function with translatable
strings.
* po/POTFILES.in: Add one_conf.c, one_driver.c
Thu May 28 13:27:30 BST 2009 Daniel P. Berrange <berrange@redhat.com> Thu May 28 13:27:30 BST 2009 Daniel P. Berrange <berrange@redhat.com>
* src/logging.c: Include function name & line number in all * src/logging.c: Include function name & line number in all

View File

@ -332,6 +332,7 @@ msg_gen_function += errorf
msg_gen_function += lxcError msg_gen_function += lxcError
msg_gen_function += networkLog msg_gen_function += networkLog
msg_gen_function += networkReportError msg_gen_function += networkReportError
msg_gen_function += oneError
msg_gen_function += openvzError msg_gen_function += openvzError
msg_gen_function += openvzLog msg_gen_function += openvzLog
msg_gen_function += qemudDispatchClientFailure msg_gen_function += qemudDispatchClientFailure

View File

@ -16,6 +16,8 @@ src/network_driver.c
src/node_device.c src/node_device.c
src/node_device_conf.c src/node_device_conf.c
src/nodeinfo.c src/nodeinfo.c
src/opennebula/one_conf.c
src/opennebula/one_driver.c
src/openvz_conf.c src/openvz_conf.c
src/openvz_driver.c src/openvz_driver.c
src/pci.c src/pci.c

View File

@ -1,7 +1,7 @@
/*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad /* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad
* Complutense de Madrid (dsa-research.org) * Complutense de Madrid (dsa-research.org)
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
#include <config.h> #include <config.h>
@ -73,7 +73,7 @@ virCapsPtr oneCapsInit(void)
} }
if ((guest = virCapabilitiesAddGuest(caps, if ((guest = virCapabilitiesAddGuest(caps,
"hvm", "hvm",
"x86_64", "x86_64",
64, 64,
@ -114,22 +114,22 @@ no_memory:
* @param vm the virtual machine pointer * @param vm the virtual machine pointer
* @return the OpenNebula ID for the new VM or -1 in case of error * @return the OpenNebula ID for the new VM or -1 in case of error
*/ */
int oneSubmitVM(virConnectPtr conn, int oneSubmitVM(virConnectPtr conn,
one_driver_t* driver ATTRIBUTE_UNUSED, one_driver_t* driver ATTRIBUTE_UNUSED,
virDomainObjPtr vm) virDomainObjPtr vm)
{ {
char* templ; char* templ;
int oneid; int oneid;
if((templ=xmlOneTemplate(conn,vm->def))==NULL )
return -1;
if( (oneid=c_oneAllocateTemplate(templ))<0 ){ if ((templ = xmlOneTemplate(conn,vm->def)) == NULL)
return -1;
if ((oneid = c_oneAllocateTemplate(templ)) < 0) {
oneError(conn, NULL, VIR_ERR_OPERATION_FAILED, oneError(conn, NULL, VIR_ERR_OPERATION_FAILED,
"Error submitting virtual machine to OpenNebula"); _("Error submitting virtual machine to OpenNebula"));
VIR_FREE(templ); VIR_FREE(templ);
return -1; return -1;
} }
VIR_FREE(templ); VIR_FREE(templ);
@ -147,113 +147,113 @@ int oneSubmitVM(virConnectPtr conn,
*/ */
char* xmlOneTemplate(virConnectPtr conn,virDomainDefPtr def) char* xmlOneTemplate(virConnectPtr conn,virDomainDefPtr def)
{ {
int i; int i;
virBuffer buf= VIR_BUFFER_INITIALIZER; virBuffer buf= VIR_BUFFER_INITIALIZER;
virBufferVSprintf(&buf,"#OpenNebula Template automatically generated by libvirt\nNAME = %s\nCPU = %ld\nMEMORY = %ld\n", virBufferVSprintf(&buf,"#OpenNebula Template automatically generated by libvirt\nNAME = %s\nCPU = %ld\nMEMORY = %ld\n",
def->name, def->name,
def->vcpus, def->vcpus,
(def->maxmem)/1024); (def->maxmem)/1024);
/*Optional Booting OpenNebula Information:*/ /*Optional Booting OpenNebula Information:*/
if( def->os.kernel ){ if (def->os.kernel) {
virBufferVSprintf(&buf,"OS=[ kernel = \"%s\"",def->os.kernel); virBufferVSprintf(&buf,"OS=[ kernel = \"%s\"",def->os.kernel);
if(def->os.initrd) if (def->os.initrd)
virBufferVSprintf(&buf,",\n initrd = \"%s\"",def->os.initrd); virBufferVSprintf(&buf,",\n initrd = \"%s\"",def->os.initrd);
if(def->os.cmdline) if (def->os.cmdline)
virBufferVSprintf(&buf,",\n kernel_cmd = \"%s\"",def->os.cmdline); virBufferVSprintf(&buf,",\n kernel_cmd = \"%s\"",def->os.cmdline);
if(def->os.root) if (def->os.root)
virBufferVSprintf(&buf,",\n root = \"%s\"",def->os.root); virBufferVSprintf(&buf,",\n root = \"%s\"",def->os.root);
virBufferAddLit(&buf," ]\n"); virBufferAddLit(&buf," ]\n");
} }
/* set Disks & NICS */ /* set Disks & NICS */
for(i=0 ; i<def->ndisks ; i++){ for (i=0 ; i < def->ndisks ; i++) {
// missing source is only allowed at cdrom and floppy // missing source is only allowed at cdrom and floppy
if(def->disks[i]->device==VIR_DOMAIN_DISK_DEVICE_DISK){ if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
virBufferVSprintf(&buf, "DISK=[ type = disk,\n" virBufferVSprintf(&buf, "DISK=[ type = disk,\n"
" source = \"%s\",\n", " source = \"%s\",\n",
def->disks[i]->src); def->disks[i]->src);
} }
else if(def->disks[i]->device==VIR_DOMAIN_DISK_DEVICE_CDROM){ else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
virBufferAddLit(&buf, "DISK=[ type = cdrom,\n"); virBufferAddLit(&buf, "DISK=[ type = cdrom,\n");
if(def->disks[i]->src) virBufferVSprintf(&buf, " source = \"%s\",\n",def->disks[i]->src); if (def->disks[i]->src) virBufferVSprintf(&buf, " source = \"%s\",\n",def->disks[i]->src);
} }
else if(def->disks[i]->device==VIR_DOMAIN_DISK_DEVICE_FLOPPY){ else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
virBufferAddLit(&buf, "DISK=[ type = floppy,\n"); virBufferAddLit(&buf, "DISK=[ type = floppy,\n");
if(def->disks[i]->src) virBufferVSprintf(&buf, " source = \"%s\",\n",def->disks[i]->src); if (def->disks[i]->src) virBufferVSprintf(&buf, " source = \"%s\",\n",def->disks[i]->src);
} }
virBufferVSprintf(&buf, " target = \"%s\",\n" virBufferVSprintf(&buf, " target = \"%s\",\n"
" readonly =", " readonly =",
def->disks[i]->dst); def->disks[i]->dst);
if(def->disks[i]->readonly) if (def->disks[i]->readonly)
virBufferAddLit(&buf,"\"yes\"]\n"); virBufferAddLit(&buf,"\"yes\"]\n");
else else
virBufferAddLit(&buf,"\"no\"]\n"); virBufferAddLit(&buf,"\"no\"]\n");
} }
for(i=0 ; i< def->nnets ; i++) for (i=0 ; i< def->nnets ; i++)
{ {
if ( !def->nets[i] ) { if (!def->nets[i]) {
continue; continue;
} }
switch(def->nets[i]->type) switch(def->nets[i]->type)
{ {
case VIR_DOMAIN_NET_TYPE_BRIDGE: case VIR_DOMAIN_NET_TYPE_BRIDGE:
virBufferVSprintf(&buf,"NIC=[ bridge =\"%s\",\n",def->nets[i]->data.bridge.brname); virBufferVSprintf(&buf,"NIC=[ bridge =\"%s\",\n",def->nets[i]->data.bridge.brname);
if(def->nets[i]->ifname)
virBufferVSprintf(&buf," target =\"%s\",\n",def->nets[i]->ifname);
virBufferVSprintf(&buf," mac =\"%02x:%02x:%02x:%02x:%02x:%02x\" ]\n",
def->nets[i]->mac[0],def->nets[i]->mac[1],
def->nets[i]->mac[2],def->nets[i]->mac[3],
def->nets[i]->mac[4],def->nets[i]->mac[5]);
break;
case VIR_DOMAIN_NET_TYPE_NETWORK: if (def->nets[i]->ifname)
virBufferVSprintf(&buf,"NIC=[ network=\"%s\"",def->nets[i]->data.network.name); virBufferVSprintf(&buf," target =\"%s\",\n",def->nets[i]->ifname);
if(def->nets[i]->ifname)
virBufferVSprintf(&buf,",\n target =\"%s\"",def->nets[i]->ifname); virBufferVSprintf(&buf," mac =\"%02x:%02x:%02x:%02x:%02x:%02x\" ]\n",
virBufferAddLit(&buf," ]\n"); def->nets[i]->mac[0],def->nets[i]->mac[1],
break; def->nets[i]->mac[2],def->nets[i]->mac[3],
def->nets[i]->mac[4],def->nets[i]->mac[5]);
break;
case VIR_DOMAIN_NET_TYPE_NETWORK:
virBufferVSprintf(&buf,"NIC=[ network=\"%s\"",def->nets[i]->data.network.name);
if (def->nets[i]->ifname)
virBufferVSprintf(&buf,",\n target =\"%s\"",def->nets[i]->ifname);
virBufferAddLit(&buf," ]\n");
break;
default: break;
}
}
if (def->graphics != NULL) {
if (def->graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
virBufferAddLit(&buf,"GRAPHICS = [\n type = \"vnc\"");
if (def->graphics->data.vnc.listenAddr != NULL)
virBufferVSprintf(&buf,",\n listen = \"%s\"",def->graphics->data.vnc.listenAddr);
if (def->graphics->data.vnc.autoport == 0)
virBufferVSprintf(&buf,",\n port = \"%d\"",def->graphics->data.vnc.port);
if (def->graphics->data.vnc.passwd != NULL)
virBufferVSprintf(&buf,",\n passwd = \"%s\"",def->graphics->data.vnc.passwd);
virBufferAddLit(&buf," ]\n");
}
else //graphics.type==VIR_DOMAIN_GRAPHICS_TYPE_SDL
virBufferAddLit(&buf,"GRAPHICS = [\n type = \"sdl\" ]\n");
default: break;
}
} }
if(def->graphics!=NULL){
if(def->graphics->type==VIR_DOMAIN_GRAPHICS_TYPE_VNC){
virBufferAddLit(&buf,"GRAPHICS = [\n type = \"vnc\"");
if(def->graphics->data.vnc.listenAddr!=NULL)
virBufferVSprintf(&buf,",\n listen = \"%s\"",def->graphics->data.vnc.listenAddr);
if(def->graphics->data.vnc.autoport==0)
virBufferVSprintf(&buf,",\n port = \"%d\"",def->graphics->data.vnc.port);
if(def->graphics->data.vnc.passwd!=NULL)
virBufferVSprintf(&buf,",\n passwd = \"%s\"",def->graphics->data.vnc.passwd);
virBufferAddLit(&buf," ]\n");
}
else //graphics.type==VIR_DOMAIN_GRAPHICS_TYPE_SDL
virBufferAddLit(&buf,"GRAPHICS = [\n type = \"sdl\" ]\n");
}
if (virBufferError(&buf)) if (virBufferError(&buf))
goto no_memory; goto no_memory;
return virBufferContentAndReset(&buf); return virBufferContentAndReset(&buf);
no_memory: no_memory:
virReportOOMError(conn); virReportOOMError(conn);
char* tmp = virBufferContentAndReset(&buf); char* tmp = virBufferContentAndReset(&buf);
VIR_FREE(tmp); VIR_FREE(tmp);
return NULL; return NULL;
}; };

View File

@ -1,7 +1,7 @@
/*----------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------*/
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad /* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad
* Complutense de Madrid (dsa-research.org) * Complutense de Madrid (dsa-research.org)
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
#ifndef ONE_CONF_H #ifndef ONE_CONF_H
@ -34,7 +34,7 @@ struct one_driver{
virCapsPtr caps; virCapsPtr caps;
virDomainObjList domains; virDomainObjList domains;
int nextid; int nextid;
}; };
typedef struct one_driver one_driver_t; typedef struct one_driver one_driver_t;
@ -44,9 +44,9 @@ int oneSubmitVM(virConnectPtr conn ,one_driver_t* driver, virDomainObjPtr vm);
char* xmlOneTemplate(virConnectPtr conn,virDomainDefPtr def); char* xmlOneTemplate(virConnectPtr conn,virDomainDefPtr def);
#define oneError(conn, dom, code, fmt...) \ #define oneError(conn, dom, code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_ONE, code, __FILE__, \ virReportErrorHelper(conn, VIR_FROM_ONE, code, __FILE__, \
__FUNCTION__, __LINE__, fmt) __FUNCTION__, __LINE__, fmt)
#endif /* ONE_CONF_H */ #endif /* ONE_CONF_H */

View File

@ -1,7 +1,7 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad /* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad
* Complutense de Madrid (dsa-research.org) * Complutense de Madrid (dsa-research.org)
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
#include <config.h> #include <config.h>
@ -66,7 +66,7 @@ static virDrvOpenStatus oneOpen(virConnectPtr conn,
virConnectAuthPtr auth ATTRIBUTE_UNUSED, virConnectAuthPtr auth ATTRIBUTE_UNUSED,
int flags ATTRIBUTE_UNUSED) int flags ATTRIBUTE_UNUSED)
{ {
/* Verify uri was specified */ /* Verify uri was specified */
if (conn->uri == NULL) { if (conn->uri == NULL) {
conn->uri = xmlParseURI("one:///"); conn->uri = xmlParseURI("one:///");
if (!conn->uri) { if (!conn->uri) {
@ -78,7 +78,7 @@ static virDrvOpenStatus oneOpen(virConnectPtr conn,
goto declineConnection; goto declineConnection;
} }
conn->privateData = one_driver; conn->privateData = one_driver;
return VIR_DRV_OPEN_SUCCESS; return VIR_DRV_OPEN_SUCCESS;
declineConnection: declineConnection:
@ -86,7 +86,7 @@ declineConnection:
} }
static int oneClose(virConnectPtr conn) static int oneClose(virConnectPtr conn)
{ {
conn->privateData = NULL; conn->privateData = NULL;
return 0; return 0;
} }
@ -116,7 +116,7 @@ return_point:
if(vm) { if(vm) {
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
} }
return dom; return dom;
} }
@ -144,7 +144,7 @@ return_point:
if(vm) { if(vm) {
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
} }
return dom; return dom;
} }
@ -172,7 +172,7 @@ return_point:
if(vm) { if(vm) {
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
} }
return dom; return dom;
} }
@ -204,7 +204,7 @@ static int oneNumDomains(virConnectPtr conn)
if (virDomainIsActive(driver->domains.objs[i])) if (virDomainIsActive(driver->domains.objs[i]))
n++; n++;
virDomainObjUnlock(driver->domains.objs[i]); virDomainObjUnlock(driver->domains.objs[i]);
} }
oneDriverUnlock(driver); oneDriverUnlock(driver);
return n; return n;
@ -217,25 +217,25 @@ static int oneListDefinedDomains(virConnectPtr conn,
oneDriverLock(driver); oneDriverLock(driver);
for (i = 0 ; i < driver->domains.count && got < nnames ; i++) { for (i = 0 ; i < driver->domains.count && got < nnames ; i++) {
virDomainObjLock(driver->domains.objs[i]); virDomainObjLock(driver->domains.objs[i]);
if (!virDomainIsActive(driver->domains.objs[i])) { if (!virDomainIsActive(driver->domains.objs[i])) {
if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) {
virReportOOMError(conn); virReportOOMError(conn);
virDomainObjUnlock(driver->domains.objs[i]); virDomainObjUnlock(driver->domains.objs[i]);
goto cleanup; goto cleanup;
} }
} }
virDomainObjUnlock(driver->domains.objs[i]); virDomainObjUnlock(driver->domains.objs[i]);
} }
oneDriverUnlock(driver); oneDriverUnlock(driver);
return got; return got;
cleanup: cleanup:
for (i = 0 ; i < got ; i++) for (i = 0 ; i < got ; i++)
VIR_FREE(names[i]); VIR_FREE(names[i]);
oneDriverUnlock(driver); oneDriverUnlock(driver);
return -1; return -1;
} }
@ -250,7 +250,7 @@ static int oneNumDefinedDomains(virConnectPtr conn)
if (!virDomainIsActive(driver->domains.objs[i])) if (!virDomainIsActive(driver->domains.objs[i]))
n++; n++;
virDomainObjUnlock(driver->domains.objs[i]); virDomainObjUnlock(driver->domains.objs[i]);
} }
oneDriverUnlock(driver); oneDriverUnlock(driver);
return n; return n;
@ -264,7 +264,7 @@ static virDomainPtr oneDomainDefine(virConnectPtr conn, const char *xml)
virDomainPtr dom=NULL; virDomainPtr dom=NULL;
oneDriverLock(driver); oneDriverLock(driver);
if (!(def = virDomainDefParseString(conn, driver->caps, xml, if (!(def = virDomainDefParseString(conn, driver->caps, xml,
VIR_DOMAIN_XML_INACTIVE))) VIR_DOMAIN_XML_INACTIVE)))
goto return_point; goto return_point;
@ -292,18 +292,18 @@ static int oneDomainUndefine(virDomainPtr dom)
one_driver_t *driver = (one_driver_t *)dom->conn->privateData; one_driver_t *driver = (one_driver_t *)dom->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
int ret=-1; int ret=-1;
oneDriverLock(driver); oneDriverLock(driver);
vm =virDomainFindByUUID(&driver->domains, dom->uuid); vm =virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) { if (!vm) {
oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
"no domain with matching uuid"); _("no domain with matching uuid"));
goto return_point; goto return_point;
} }
if (!vm->persistent) { if (!vm->persistent) {
oneError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR, oneError(dom->conn, dom, VIR_ERR_INTERNAL_ERROR,
"cannot undefine transient domain"); _("cannot undefine transient domain"));
goto return_point; goto return_point;
} }
virDomainRemoveInactive(&driver->domains, vm); virDomainRemoveInactive(&driver->domains, vm);
@ -332,7 +332,7 @@ static int oneDomainGetInfo(virDomainPtr dom,
if(gettimeofday(&tv,NULL)<0) { if(gettimeofday(&tv,NULL)<0) {
oneError(dom->conn,dom, VIR_ERR_INTERNAL_ERROR, oneError(dom->conn,dom, VIR_ERR_INTERNAL_ERROR,
"%s",_("getting time of day")); "%s",_("getting time of day"));
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
return -1; return -1;
} }
@ -347,24 +347,24 @@ static int oneDomainGetInfo(virDomainPtr dom,
cptr = index(cptr, ':'); cptr = index(cptr, ':');
cptr++; cptr++;
int one_state=atoi(cptr); int one_state=atoi(cptr);
switch(one_state) { switch(one_state) {
case 3: /** running */ case 3: /** running */
if (vm->state!=VIR_DOMAIN_SHUTDOWN) if (vm->state!=VIR_DOMAIN_SHUTDOWN)
vm->state=VIR_DOMAIN_RUNNING; vm->state=VIR_DOMAIN_RUNNING;
break; break;
case 5: /** pause */ case 5: /** pause */
vm->state=VIR_DOMAIN_PAUSED; vm->state=VIR_DOMAIN_PAUSED;
break; break;
case 6: /** done */ case 6: /** done */
vm->state=VIR_DOMAIN_SHUTOFF; vm->state=VIR_DOMAIN_SHUTOFF;
vm->def->id=-1; vm->def->id=-1;
break; break;
case 7: /** error */ case 7: /** error */
vm->state=VIR_DOMAIN_CRASHED; vm->state=VIR_DOMAIN_CRASHED;
break; break;
default: default:
break; break;
}; };
//Memory: //Memory:
cptr=strstr(vm_info,"MEMORY"); cptr=strstr(vm_info,"MEMORY");
@ -380,7 +380,7 @@ static int oneDomainGetInfo(virDomainPtr dom,
info->cpuTime = (tv.tv_sec - starttime) *1000ll *1000ll *1000ll; info->cpuTime = (tv.tv_sec - starttime) *1000ll *1000ll *1000ll;
} }
info->state = vm->state; info->state = vm->state;
info->maxMem = vm->def->maxmem; info->maxMem = vm->def->maxmem;
info->memory = vm->def->memory; info->memory = vm->def->memory;
@ -416,13 +416,13 @@ static int oneDomainStart(virDomainPtr dom)
virDomainObjPtr vm; virDomainObjPtr vm;
int ret = -1; int ret = -1;
int oneid; int oneid;
oneDriverLock(driver); oneDriverLock(driver);
vm = virDomainFindByName(&driver->domains, dom->name); vm = virDomainFindByName(&driver->domains, dom->name);
if (!vm) { if (!vm) {
oneError(conn, dom, VIR_ERR_INVALID_DOMAIN, oneError(conn, dom, VIR_ERR_INVALID_DOMAIN,
"no domain named %s", dom->name); _("no domain named %s"), dom->name);
goto return_point; goto return_point;
} }
if((oneid = oneSubmitVM(dom->conn,driver,vm)) < 0) { if((oneid = oneSubmitVM(dom->conn,driver,vm)) < 0) {
@ -437,7 +437,7 @@ return_point:
if(vm) if(vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
oneDriverUnlock(driver); oneDriverUnlock(driver);
return ret; return ret;
} }
@ -449,21 +449,21 @@ oneDomainCreateAndStart(virConnectPtr conn,
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
virDomainDefPtr def; virDomainDefPtr def;
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
int oneid; int oneid;
oneDriverLock(driver); oneDriverLock(driver);
if (!(def = virDomainDefParseString(conn, driver->caps, xml, if (!(def = virDomainDefParseString(conn, driver->caps, xml,
VIR_DOMAIN_XML_INACTIVE))) VIR_DOMAIN_XML_INACTIVE)))
goto return_point; goto return_point;
vm = virDomainFindByName(&driver->domains, def->name); vm = virDomainFindByName(&driver->domains, def->name);
if (vm) { if (vm) {
oneError(conn,NULL, VIR_ERR_OPERATION_FAILED, oneError(conn,NULL, VIR_ERR_OPERATION_FAILED,
_("Already an OpenNebula VM active with the name: \"%s\" id: %d "), _("Already an OpenNebula VM active with the name: '%s' id: %d "),
def->name,def->id); def->name,def->id);
goto return_point; goto return_point;
} }
if (!(vm = virDomainAssignDef(conn, &driver->domains, def))) { if (!(vm = virDomainAssignDef(conn, &driver->domains, def))) {
virDomainDefFree(def); virDomainDefFree(def);
goto return_point; goto return_point;
@ -473,7 +473,7 @@ oneDomainCreateAndStart(virConnectPtr conn,
vm=NULL; vm=NULL;
goto return_point; goto return_point;
} }
vm->def->id=driver->nextid++; vm->def->id=driver->nextid++;
vm->persistent=0; vm->persistent=0;
vm->pid=oneid; vm->pid=oneid;
@ -483,12 +483,12 @@ oneDomainCreateAndStart(virConnectPtr conn,
if (dom) { if (dom) {
dom->id = vm->def->id; dom->id = vm->def->id;
} }
return_point: return_point:
if(vm) if(vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
oneDriverUnlock(driver); oneDriverUnlock(driver);
return dom; return dom;
} }
@ -506,22 +506,22 @@ static int oneDomainShutdown(virDomainPtr dom)
goto return_point; goto return_point;
} }
oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED,
"Wrong state to perform action"); _("Wrong state to perform action"));
goto return_point; goto return_point;
} }
oneError(dom->conn,dom, VIR_ERR_INVALID_DOMAIN, oneError(dom->conn,dom, VIR_ERR_INVALID_DOMAIN,
_("no domain with id %d"), dom->id); _("no domain with id %d"), dom->id);
goto return_point; goto return_point;
if (!vm->persistent) { if (!vm->persistent) {
virDomainRemoveInactive(&driver->domains, vm); virDomainRemoveInactive(&driver->domains, vm);
vm = NULL; vm = NULL;
} }
return_point: return_point:
if(vm) if(vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
oneDriverUnlock(driver); oneDriverUnlock(driver);
return ret; return ret;
} }
@ -535,15 +535,15 @@ static int oneDomainDestroy(virDomainPtr dom)
vm= virDomainFindByID(&driver->domains, dom->id); vm= virDomainFindByID(&driver->domains, dom->id);
if (!vm) { if (!vm) {
oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
"no domain with id %d", dom->id); _("no domain with id %d"), dom->id);
goto return_point; goto return_point;
} }
if(c_oneCancel(vm->pid)) { if(c_oneCancel(vm->pid)) {
/* VM not running, delete the instance at ONE DB */ /* VM not running, delete the instance at ONE DB */
if(c_oneFinalize(vm->pid)){ if(c_oneFinalize(vm->pid)){
oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED,
"Wrong state to perform action"); _("Wrong state to perform action"));
goto return_point; goto return_point;
} }
} }
if(!vm->persistent) { if(!vm->persistent) {
@ -557,7 +557,7 @@ return_point:
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
oneDriverUnlock(driver); oneDriverUnlock(driver);
return ret; return ret;
} }
@ -566,32 +566,32 @@ static int oneDomainSuspend(virDomainPtr dom)
one_driver_t* driver=dom->conn->privateData; one_driver_t* driver=dom->conn->privateData;
virDomainObjPtr vm; virDomainObjPtr vm;
int ret=-1; int ret=-1;
oneDriverLock(driver); oneDriverLock(driver);
if ((vm=virDomainFindByID(&driver->domains,dom->id))){ if ((vm=virDomainFindByID(&driver->domains,dom->id))){
if (vm->state == VIR_DOMAIN_RUNNING) { if (vm->state == VIR_DOMAIN_RUNNING) {
if( !(c_oneSuspend(vm->pid)) ) { if( !(c_oneSuspend(vm->pid)) ) {
vm->state=VIR_DOMAIN_PAUSED; vm->state=VIR_DOMAIN_PAUSED;
ret=0; ret=0;
goto return_point;
}
oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED,
_("Wrong state to perform action"));
goto return_point; goto return_point;
} }
oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, oneError(dom->conn,dom,VIR_ERR_OPERATION_FAILED,
"Wrong state to perform action"); _("domain is not running"));
goto return_point;
}
oneError(dom->conn,dom,VIR_ERR_OPERATION_FAILED,
"domain is not running");
} else { } else {
oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
"no domain with matching id %d", dom->id); _("no domain with matching id %d"), dom->id);
} }
return_point: return_point:
if(vm) if(vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
oneDriverUnlock(driver); oneDriverUnlock(driver);
return ret; return ret;
}; };
@ -608,23 +608,23 @@ static int oneDomainResume(virDomainPtr dom)
vm->state=VIR_DOMAIN_RUNNING; vm->state=VIR_DOMAIN_RUNNING;
ret=0; ret=0;
goto return_point; goto return_point;
} }
oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED, oneError(dom->conn, dom, VIR_ERR_OPERATION_FAILED,
"Wrong state to perform action"); _("Wrong state to perform action"));
goto return_point; goto return_point;
} }
oneError(dom->conn,dom,VIR_ERR_OPERATION_FAILED, oneError(dom->conn,dom,VIR_ERR_OPERATION_FAILED,
"domain is not paused "); _("domain is not paused "));
} else { } else {
oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, oneError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
"no domain with matching id %d", dom->id); _("no domain with matching id %d"), dom->id);
} }
return_point: return_point:
if(vm) if(vm)
virDomainObjUnlock(vm); virDomainObjUnlock(vm);
oneDriverUnlock(driver); oneDriverUnlock(driver);
return ret; return ret;
}; };
@ -638,7 +638,7 @@ static int oneStartup(void){
VIR_FREE(one_driver); VIR_FREE(one_driver);
return -1; return -1;
} }
c_oneStart(); c_oneStart();
oneDriverLock(one_driver); oneDriverLock(one_driver);
one_driver->nextid=1; one_driver->nextid=1;
@ -647,8 +647,8 @@ static int oneStartup(void){
VIR_FREE(one_driver); VIR_FREE(one_driver);
return -1; return -1;
} }
oneDriverUnlock(one_driver); oneDriverUnlock(one_driver);
return 0; return 0;
} }
@ -670,7 +670,7 @@ static int oneShutdown(void){
static int oneActive(void){ static int oneActive(void){
unsigned int i; unsigned int i;
int active = 0; int active = 0;
if (one_driver == NULL) if (one_driver == NULL)
return(0); return(0);
@ -679,9 +679,9 @@ static int oneActive(void){
for (i = 0 ; i < one_driver->domains.count ; i++) { for (i = 0 ; i < one_driver->domains.count ; i++) {
virDomainObjLock(one_driver->domains.objs[i]); virDomainObjLock(one_driver->domains.objs[i]);
if (virDomainIsActive(one_driver->domains.objs[i])) if (virDomainIsActive(one_driver->domains.objs[i]))
active = 1; active = 1;
virDomainObjUnlock(one_driver->domains.objs[i]); virDomainObjUnlock(one_driver->domains.objs[i]);
} }
oneDriverUnlock(one_driver); oneDriverUnlock(one_driver);
return active; return active;
@ -697,12 +697,12 @@ static int oneVersion(virConnectPtr conn ATTRIBUTE_UNUSED, unsigned long *hvVer)
static int oneGetAutostart(virDomainPtr domain ATTRIBUTE_UNUSED, int *autostart) static int oneGetAutostart(virDomainPtr domain ATTRIBUTE_UNUSED, int *autostart)
{ {
autostart=0; autostart=0;
return 0; return 0;
} }
static char* oneGetCapabilities(virConnectPtr conn){ static char* oneGetCapabilities(virConnectPtr conn){
one_driver_t* privconn=conn->privateData; one_driver_t* privconn=conn->privateData;
char *xml; char *xml;
oneDriverLock(privconn); oneDriverLock(privconn);
if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL) if ((xml = virCapabilitiesFormatXML(privconn->caps)) == NULL)
@ -778,7 +778,7 @@ static virDriver oneDriver = {
NULL, /* nodeDeviceReAttach; */ NULL, /* nodeDeviceReAttach; */
NULL, /* nodeDeviceReset; */ NULL, /* nodeDeviceReset; */
}; };
static virStateDriver oneStateDriver = { static virStateDriver oneStateDriver = {
.initialize = oneStartup, .initialize = oneStartup,
.cleanup = oneShutdown, .cleanup = oneShutdown,

View File

@ -1,7 +1,7 @@
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad /* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad
* Complutense de Madrid (dsa-research.org) * Complutense de Madrid (dsa-research.org)
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either * License as published by the Free Software Foundation; either
@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/