Re: [libvirt] [PATCH] LXC: create a bind mount for sysfs when enable userns but disable netns

2014-07-18 Thread chenhanx...@cn.fujitsu.com
ping

 -Original Message-
 From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
 On Behalf Of Chen Hanxiao
 Sent: Monday, July 14, 2014 6:02 PM
 To: libvir-list@redhat.com
 Subject: [libvirt] [PATCH] LXC: create a bind mount for sysfs when enable 
 userns
 but disable netns
 
 kernel commit 7dc5dbc879bd0779924b5132a48b731a0bc04a1e
 forbid us doing a fresh mount for sysfs
 when enable userns but disable netns.
 This patch will create a bind mount in this senario.
 
 Signed-off-by: Chen Hanxiao chenhanx...@cn.fujitsu.com
 ---
  src/lxc/lxc_container.c | 44 +---
  1 file changed, 33 insertions(+), 11 deletions(-)
 
 diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
 index 4d89677..8a27215 100644
 --- a/src/lxc/lxc_container.c
 +++ b/src/lxc/lxc_container.c
 @@ -815,10 +815,13 @@ static int lxcContainerSetReadOnly(void)
  }
 
 
 -static int lxcContainerMountBasicFS(bool userns_enabled)
 +static int lxcContainerMountBasicFS(bool userns_enabled,
 +bool netns_disabled)
  {
  size_t i;
  int rc = -1;
 +char* mnt_src = NULL;
 +int mnt_mflags;
 
  VIR_DEBUG(Mounting basic filesystems);
 
 @@ -826,8 +829,25 @@ static int lxcContainerMountBasicFS(bool userns_enabled)
  bool bindOverReadonly;
  virLXCBasicMountInfo const *mnt = lxcBasicMounts[i];
 
 +/* When enable userns but disable netns, kernel will
 + * forbid us doing a new fresh mount for sysfs.
 + * So we had to do a bind mount for sysfs instead.
 + */
 +if (userns_enabled  netns_disabled 
 +STREQ(mnt-src, sysfs)) {
 +if (VIR_STRDUP(mnt_src, /sys)  0) {
 +goto cleanup;
 +}
 +mnt_mflags = MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_RDONLY|MS_BIND;
 +} else {
 +if (VIR_STRDUP(mnt_src, mnt-src)  0) {
 +goto cleanup;
 +}
 +mnt_mflags = mnt-mflags;
 +}
 +
  VIR_DEBUG(Processing %s - %s,
 -  mnt-src, mnt-dst);
 +  mnt_src, mnt-dst);
 
  if (mnt-skipUnmounted) {
  char *hostdir;
 @@ -856,7 +876,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled)
  if (virFileMakePath(mnt-dst)  0) {
  virReportSystemError(errno,
   _(Failed to mkdir %s),
 - mnt-src);
 + mnt_src);
  goto cleanup;
  }
 
 @@ -867,24 +887,24 @@ static int lxcContainerMountBasicFS(bool userns_enabled)
   * we mount the filesystem in read-write mode initially, and then do 
 a
   * separate read-only bind mount on top of that.
   */
 -bindOverReadonly = !!(mnt-mflags  MS_RDONLY);
 +bindOverReadonly = !!(mnt_mflags  MS_RDONLY);
 
  VIR_DEBUG(Mount %s on %s type=%s flags=%x,
 -  mnt-src, mnt-dst, mnt-type, mnt-mflags  ~MS_RDONLY);
 -if (mount(mnt-src, mnt-dst, mnt-type, mnt-mflags  ~MS_RDONLY, 
 NULL)
  0) {
 +  mnt_src, mnt-dst, mnt-type, mnt_mflags  ~MS_RDONLY);
 +if (mount(mnt_src, mnt-dst, mnt-type, mnt_mflags  ~MS_RDONLY, 
 NULL)
  0) {
  virReportSystemError(errno,
   _(Failed to mount %s on %s type %s 
 flags=%x),
 - mnt-src, mnt-dst, NULLSTR(mnt-type),
 - mnt-mflags  ~MS_RDONLY);
 + mnt_src, mnt-dst, NULLSTR(mnt-type),
 + mnt_mflags  ~MS_RDONLY);
  goto cleanup;
  }
 
  if (bindOverReadonly 
 -mount(mnt-src, mnt-dst, NULL,
 +mount(mnt_src, mnt-dst, NULL,
MS_BIND|MS_REMOUNT|MS_RDONLY, NULL)  0) {
  virReportSystemError(errno,
   _(Failed to re-mount %s on %s flags=%x),
 - mnt-src, mnt-dst,
 + mnt_src, mnt-dst,
   MS_BIND|MS_REMOUNT|MS_RDONLY);
  goto cleanup;
  }
 @@ -893,6 +913,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled)
  rc = 0;
 
   cleanup:
 +VIR_FREE(mnt_src);
  VIR_DEBUG(rc=%d, rc);
  return rc;
  }
 @@ -1643,7 +1664,8 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr
 vmDef,
  goto cleanup;
 
  /* Mounts the core /proc, /sys, etc filesystems */
 -if (lxcContainerMountBasicFS(vmDef-idmap.nuidmap)  0)
 +if (lxcContainerMountBasicFS(vmDef-idmap.nuidmap,
 + !vmDef-nnets)  0)
  goto cleanup;
 
  /* Ensure entire root filesystem (except /.oldroot) is readonly */
 --
 1.9.0
 
 --
 libvir-list mailing list
 libvir-list@redhat.com
 https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list 

[libvirt] [PATCH 00/29] vbox: Rewrite several APIs.

2014-07-18 Thread Taowei
Put exactly one API into one patch.
Add a test case to test with vboxUniformedAPI.

Taowei (29):
  vbox: Begin to rewrite, vboxConnectOpen
  vbox: Add test case for vboxUniformedAPI
  vbox: Rewrite vboxConnectClose
  vbox: Rewrite vboxDomainSave
  vbox: Rewrite vboxConnectGetVersion
  vbox: Rewrite vboxConnectGetHostname
  vbox: Rewrite vboxConnectIsSecure
  vbox: Rewrite vboxConnectIsEncrypted
  vbox: Rewrite vboxConnectIsAlive
  vbox: Rewrite vboxConnectGetMaxVcpus
  vbox: Rewrite vboxConnectGetCapabilities
  vbox: Rewrite vboxConnectListDomains
  vbox: Rewrite vboxConnectNumOfDomains
  vbox: Rewrite vboxDomainLookupById
  vbox: Rewrite vboxDomainLookupByUUId
  vbox: Rewrite vboxDomainUndefineFlags
  vbox: Rewrite vboxDomainDefineXML
  vbox: Rewrite vboxDomainCreateWithFlags
  vbox: Rewrite vboxDomainCreate
  vbox: Rewrite vboxDomainCreateXML
  vbox: Rewrite vboxDomainLookupByName
  vbox: Rewrite vboxDomainIsActive
  vbox: Rewrite vboxDomainIsPersistent
  vbox: Rewrite vboxDomainIsUpdated
  vbox: Rewrite vboxDomainSuspend
  vbox: Rewrite vboxDomainResume
  vbox: Rewrite vboxDomainShutdownFlags
  vbox: Rewrite vboxDomainShutdown
  vbox: Rewrite vboxDomainReboot

 po/POTFILES.in|1 +
 src/Makefile.am   |4 +-
 src/vbox/vbox_common.c| 2547 ++
 src/vbox/vbox_common.h|  261 +++
 src/vbox/vbox_driver.c|   23 +-
 src/vbox/vbox_tmpl.c  | 4041 -
 src/vbox/vbox_uniformed_api.h |  461 +
 tests/Makefile.am |9 +-
 tests/vboxuniformedapitest.c  |   98 +
 9 files changed, 4933 insertions(+), 2512 deletions(-)
 create mode 100644 src/vbox/vbox_common.c
 create mode 100644 src/vbox/vbox_common.h
 create mode 100644 src/vbox/vbox_uniformed_api.h
 create mode 100644 tests/vboxuniformedapitest.c

-- 
1.7.9.5

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


[libvirt] [PATCH 20/29] vbox: Rewrite vboxDomainCreateXML

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   28 
 src/vbox/vbox_tmpl.c  |   28 
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 4861d52..a278a37 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2152,3 +2152,31 @@ int vboxDomainCreate(virDomainPtr dom)
 {
 return vboxDomainCreateWithFlags(dom, 0);
 }
+
+virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
+ unsigned int flags)
+{
+/* VirtualBox currently doesn't have support for running
+ * virtual machines without actually defining them and thus
+ * for time being just define new machine and start it.
+ *
+ * TODO: After the appropriate API's are added in VirtualBox
+ * change this behaviour to the expected one.
+ */
+
+virDomainPtr dom;
+
+virCheckFlags(0, NULL);
+
+dom = vboxDomainDefineXML(conn, xml);
+if (dom == NULL)
+return NULL;
+
+if (vboxDomainCreate(dom)  0) {
+vboxDomainUndefineFlags(dom, 0);
+virObjectUnref(dom);
+return NULL;
+}
+
+return dom;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 2c3097b..c4232aa 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,34 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
-unsigned int flags)
-{
-/* VirtualBox currently doesn't have support for running
- * virtual machines without actually defining them and thus
- * for time being just define new machine and start it.
- *
- * TODO: After the appropriate API's are added in VirtualBox
- * change this behaviour to the expected one.
- */
-
-virDomainPtr dom;
-
-virCheckFlags(0, NULL);
-
-dom = vboxDomainDefineXML(conn, xml);
-if (dom == NULL)
-return NULL;
-
-if (vboxDomainCreate(dom)  0) {
-vboxDomainUndefineFlags(dom, 0);
-virObjectUnref(dom);
-return NULL;
-}
-
-return dom;
-}
-
 static virDomainPtr
 vboxDomainLookupByName(virConnectPtr conn, const char *name)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 7e04845..55f2eec 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -424,6 +424,8 @@ virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const 
char *xml);
 int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainCreate(virDomainPtr dom);
+virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
+ unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 01/29] vbox: Begin to rewrite, vboxConnectOpen

2014-07-18 Thread Taowei
Introduce vbox_uniformed_api to deal with
version conflicts.

vboxConnectOpen has been rewritten.
---
 po/POTFILES.in|1 +
 src/Makefile.am   |4 +-
 src/vbox/vbox_common.c|  289 
 src/vbox/vbox_common.h|  132 +++
 src/vbox/vbox_driver.c|   23 ++-
 src/vbox/vbox_tmpl.c  |  364 ++---
 src/vbox/vbox_uniformed_api.h |  152 +
 7 files changed, 717 insertions(+), 248 deletions(-)
 create mode 100644 src/vbox/vbox_common.c
 create mode 100644 src/vbox/vbox_common.h
 create mode 100644 src/vbox/vbox_uniformed_api.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 64a987e..93b7e2b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -215,6 +215,7 @@ src/util/virxml.c
 src/vbox/vbox_MSCOMGlue.c
 src/vbox/vbox_XPCOMCGlue.c
 src/vbox/vbox_driver.c
+src/vbox/vbox_common.c
 src/vbox/vbox_snapshot_conf.c
 src/vbox/vbox_tmpl.c
 src/vmware/vmware_conf.c
diff --git a/src/Makefile.am b/src/Makefile.am
index e2f76a7..1d66492 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -674,7 +674,9 @@ VBOX_DRIVER_SOURCES =   
\
vbox/vbox_V4_2.c vbox/vbox_CAPI_v4_2.h  \
vbox/vbox_V4_2_20.c vbox/vbox_CAPI_v4_2_20.h\
vbox/vbox_V4_3.c vbox/vbox_CAPI_v4_3.h  \
-   vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h
+   vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h  \
+   vbox/vbox_common.c vbox/vbox_common.h   \
+   vbox/vbox_uniformed_api.h
 
 VBOX_DRIVER_EXTRA_DIST =   \
vbox/vbox_tmpl.c vbox/README\
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
new file mode 100644
index 000..8fb4494
--- /dev/null
+++ b/src/vbox/vbox_common.c
@@ -0,0 +1,289 @@
+/*
+ * Copyright 2014, Taowei Luo (uaeda...@gmail.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * http://www.gnu.org/licenses/.
+ */
+
+#include config.h
+
+#include unistd.h
+
+#include internal.h
+#include datatypes.h
+#include domain_conf.h
+#include domain_event.h
+#include virlog.h
+#include viralloc.h
+#include nodeinfo.h
+
+#include vbox_common.h
+#include vbox_uniformed_api.h
+
+/* Common codes for vbox driver. With the definitions in vbox_common.h,
+ * it treats vbox structs as a void*. Though vboxUniformedAPI
+ * it call vbox functions. This file is a high level implement about
+ * the vbox driver.
+ */
+
+#define VIR_FROM_THIS VIR_FROM_VBOX
+
+VIR_LOG_INIT(vbox.vbox_common);
+
+#define VBOX_UTF16_FREE(arg)\
+do {\
+if (arg) {  \
+gVBoxAPI.UPFN.Utf16Free(data-pFuncs, arg); \
+(arg) = NULL;   \
+}   \
+} while (0)
+
+#define VBOX_UTF8_FREE(arg) \
+do {\
+if (arg) {  \
+gVBoxAPI.UPFN.Utf8Free(data-pFuncs, arg);  \
+(arg) = NULL;   \
+}   \
+} while (0)
+
+#define VBOX_COM_UNALLOC_MEM(arg)   \
+do {\
+if (arg) {  \
+gVBoxAPI.UPFN.ComUnallocMem(data-pFuncs, arg); \
+(arg) = NULL;   \
+}   \
+} while (0)
+
+#define VBOX_UTF16_TO_UTF8(arg1, arg2)  
gVBoxAPI.UPFN.Utf16ToUtf8(data-pFuncs, arg1, arg2)
+#define VBOX_UTF8_TO_UTF16(arg1, arg2)  
gVBoxAPI.UPFN.Utf8ToUtf16(data-pFuncs, arg1, arg2)
+
+/* global vbox API, used for all common codes. */
+static vboxUniformedAPI gVBoxAPI;
+
+void vboxRegisterUniformedAPI(uint32_t uVersion)
+{
+

[libvirt] [PATCH 26/29] vbox: Rewrite vboxDomainResume

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   47 +
 src/vbox/vbox_tmpl.c  |   66 -
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 63 insertions(+), 53 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 62ab43b..e9a9f36 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2401,3 +2401,50 @@ int vboxDomainSuspend(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainResume(virDomainPtr dom)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRUint32 state;
+PRBool isAccessible = PR_FALSE;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Paused(state)) {
+/* resume the machine here */
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.Resume(console);
+VBOX_RELEASE(console);
+ret = 0;
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(error while resuming the domain));
+goto cleanup;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine not paused, so can't resume it));
+goto cleanup;
+}
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index f8d4b8f..c6df403 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,59 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainResume(virDomainPtr dom)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRUint32 state   = MachineState_Null;
-nsresult rc;
-
-PRBool isAccessible = PR_FALSE;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Paused) {
-/* resume the machine here */
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-Resume(console);
-VBOX_RELEASE(console);
-ret = 0;
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(error while resuming the domain));
-goto cleanup;
-}
-VBOX_SESSION_CLOSE();
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine not paused, so can't resume it));
-goto cleanup;
-}
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainShutdownFlags(virDomainPtr dom,
unsigned int flags)
 {
@@ -9980,6 +9927,12 @@ _consolePause(IConsole *console)
 }
 
 static nsresult
+_consoleResume(IConsole *console)
+{
+return console-vtbl-Resume(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10420,6 +10373,11 @@ static bool _machineStateRunning(PRUint32 state)
 return state == MachineState_Running;
 }
 
+static bool _machineStatePaused(PRUint32 state)
+{
+return state == MachineState_Paused;
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -10497,6 +10455,7 @@ static vboxUniformedISession _UISession = {
 static vboxUniformedIConsole _UIConsole = {
 .SaveState = _consoleSaveState,
 .Pause = _consolePause,
+.Resume = _consoleResume,
 };
 
 static vboxUniformedIProgress _UIProgress = {
@@ -10587,6 +10546,7 @@ static uniformedMachineStateChecker 
_machineStateChecker = {
 .Online = _machineStateOnline,
 .NotStart = _machineStateNotStart,
 .Running = _machineStateRunning,
+

[libvirt] [PATCH 12/29] vbox: Rewrite vboxConnectListDomains

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   42 ++
 src/vbox/vbox_tmpl.c  |   80 +
 src/vbox/vbox_uniformed_api.h |   22 
 3 files changed, 105 insertions(+), 39 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index ed6597c..8eedd4d 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -96,6 +96,10 @@ if (!data-vboxObj) {\
 
 #define VBOX_IID_INITIALIZE(iid)
gVBoxAPI.UIID.vboxIIDInitialize(iid)
 
+#define ARRAY_GET_MACHINES \
+(gVBoxAPI.UArray.handleGetMachines(data-vboxObj))
+
+
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
@@ -472,3 +476,41 @@ char *vboxConnectGetCapabilities(virConnectPtr conn)
 
 return ret;
 }
+
+int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+PRUint32 state;
+nsresult rc;
+size_t i, j;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of Domains, rc=%08x),
+   (unsigned)rc);
+goto cleanup;
+}
+
+ret = 0;
+for (i = 0, j = 0; (i  machines.count)  (j  nids); ++i) {
+IMachine *machine = machines.items[i];
+
+if (machine) {
+PRBool isAccessible = PR_FALSE;
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (isAccessible) {
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (gVBoxAPI.machineStateChecker.Online(state)) {
+ret++;
+ids[j++] = i + 1;
+}
+}
+}
+}
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 569ae29..1138566 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -917,45 +917,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
-{
-VBOX_OBJECT_CHECK(conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-PRUint32 state;
-nsresult rc;
-size_t i, j;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of Domains, rc=%08x),
-   (unsigned)rc);
-goto cleanup;
-}
-
-ret = 0;
-for (i = 0, j = 0; (i  machines.count)  (j  nids); ++i) {
-IMachine *machine = machines.items[i];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline)) {
-ret++;
-ids[j++] = i + 1;
-}
-}
-}
-}
-
- cleanup:
-vboxArrayRelease(machines);
-return ret;
-}
-
 static int vboxConnectNumOfDomains(virConnectPtr conn)
 {
 VBOX_OBJECT_CHECK(conn, int, -1);
@@ -11288,6 +11249,11 @@ static void _DEBUGIID(const char *msg, vboxIIDUnion 
*iidu)
 
 #endif /* VBOX_API_VERSION != 2002000 */
 
+static void* _handleGetMachines(IVirtualBox *vboxObj)
+{
+return vboxObj-vtbl-GetMachines;
+}
+
 static nsresult
 _virtualboxGetVersion(IVirtualBox *vboxObj, PRUnichar **versionUtf16)
 {
@@ -11318,6 +11284,18 @@ _virtualboxGetSystemProperties(IVirtualBox *vboxObj, 
ISystemProperties **systemP
 return vboxObj-vtbl-GetSystemProperties(vboxObj, systemProperties);
 }
 
+static nsresult
+_machineGetAccessible(IMachine *machine, PRBool *isAccessible)
+{
+return machine-vtbl-GetAccessible(machine, isAccessible);
+}
+
+static nsresult
+_machineGetState(IMachine *machine, PRUint32 *state)
+{
+return machine-vtbl-GetState(machine, state);
+}
+
 #if VBOX_API_VERSION  400
 
 static nsresult
@@ -11390,6 +11368,12 @@ static nsresult _nsisupportsRelease(void *Ihandle)
 return nsi-vtbl-Release(nsi);
 }
 
+static bool _machineStateOnline(PRUint32 state)
+{
+return ((state = MachineState_FirstOnline) 
+(state = MachineState_LastOnline));
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -11410,12 +11394,23 @@ static vboxUniformedIID _UIID = {
 .DEBUGIID = _DEBUGIID,
 };
 
+static vboxUniformedArray _UArray = {
+.vboxArrayGet = vboxArrayGet,
+.vboxArrayRelease = vboxArrayRelease,
+.handleGetMachines = _handleGetMachines,
+};
+
 static vboxUniformedIVirtualBox 

[libvirt] [PATCH 29/29] vbox: Rewrite vboxDomainReboot

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   44 
 src/vbox/vbox_tmpl.c  |   56 ++---
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 53 insertions(+), 49 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 98d7c8a..2551393 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2501,3 +2501,47 @@ int vboxDomainShutdown(virDomainPtr dom)
 {
 return vboxDomainShutdownFlags(dom, 0);
 }
+
+int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRUint32 state;
+PRBool isAccessible  = PR_FALSE;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Running(state)) {
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.Reset(console);
+VBOX_RELEASE(console);
+ret = 0;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine not running, so can't reboot it));
+goto cleanup;
+}
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 28bf9be..a960f56 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,55 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRUint32 state   = MachineState_Null;
-PRBool isAccessible  = PR_FALSE;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Running) {
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-Reset(console);
-VBOX_RELEASE(console);
-ret = 0;
-}
-VBOX_SESSION_CLOSE();
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine not running, so can't reboot it));
-goto cleanup;
-}
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int
 vboxDomainDestroyFlags(virDomainPtr dom,
unsigned int flags)
@@ -9879,6 +9830,12 @@ _consolePowerButton(IConsole *console)
 }
 
 static nsresult
+_consoleReset(IConsole *console)
+{
+return console-vtbl-Reset(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10408,6 +10365,7 @@ static vboxUniformedIConsole _UIConsole = {
 .Pause = _consolePause,
 .Resume = _consoleResume,
 .PowerButton = _consolePowerButton,
+.Reset = _consoleReset,
 };
 
 static vboxUniformedIProgress _UIProgress = {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 5926a2a..d4a590f 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -252,6 +252,7 @@ typedef struct {
 nsresult (*Pause)(IConsole *console);
 nsresult (*Resume)(IConsole *console);
 nsresult (*PowerButton)(IConsole *console);
+nsresult (*Reset)(IConsole *console);
 } vboxUniformedIConsole;
 
 /* Functions for IProgress */
@@ -441,6 +442,7 @@ int vboxDomainSuspend(virDomainPtr dom);
 int vboxDomainResume(virDomainPtr dom);
 int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainShutdown(virDomainPtr dom);
+int vboxDomainReboot(virDomainPtr dom, unsigned int flags);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing 

[libvirt] [PATCH 25/29] vbox: Rewrite vboxDomainSuspend

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   47 +
 src/vbox/vbox_tmpl.c  |   65 +
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 63 insertions(+), 52 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index cc25633..62ab43b 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2354,3 +2354,50 @@ int vboxDomainIsUpdated(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainSuspend(virDomainPtr dom)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRBool isAccessible  = PR_FALSE;
+PRUint32 state;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Running(state)) {
+/* set state pause */
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.Pause(console);
+VBOX_RELEASE(console);
+ret = 0;
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(error while suspending the domain));
+goto cleanup;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+} else {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine not in running state to suspend it));
+goto cleanup;
+}
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 96df49c..f8d4b8f 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,58 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainSuspend(virDomainPtr dom)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRBool isAccessible  = PR_FALSE;
-PRUint32 state;
-nsresult rc;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Running) {
-/* set state pause */
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-Pause(console);
-VBOX_RELEASE(console);
-ret = 0;
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(error while suspending the domain));
-goto cleanup;
-}
-VBOX_SESSION_CLOSE();
-} else {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine not in running state to suspend it));
-goto cleanup;
-}
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainResume(virDomainPtr dom)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
@@ -10026,6 +9974,12 @@ _consoleSaveState(IConsole *console, IProgress 
**progress)
 }
 
 static nsresult
+_consolePause(IConsole *console)
+{
+return console-vtbl-Pause(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10461,6 +10415,11 @@ static bool _machineStateNotStart(PRUint32 state)
 (state == MachineState_Aborted));
 }
 
+static bool _machineStateRunning(PRUint32 state)
+{
+return state == MachineState_Running;
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -10537,6 +10496,7 @@ static vboxUniformedISession _UISession = {
 
 static vboxUniformedIConsole _UIConsole = {
 .SaveState = _consoleSaveState,
+.Pause = _consolePause,
 };
 
 static vboxUniformedIProgress _UIProgress = {
@@ -10626,6 +10586,7 @@ static vboxUniformedIMedium _UIMedium = {
 static uniformedMachineStateChecker _machineStateChecker = {
 .Online = _machineStateOnline,
 .NotStart = _machineStateNotStart,
+.Running = _machineStateRunning,
 };
 
 void 

[libvirt] [PATCH 06/29] vbox: Rewrite vboxConnectGetHostname

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 3edadce..2588379 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -415,3 +415,8 @@ int vboxConnectGetVersion(virConnectPtr conn, unsigned long 
*version)
 
 return 0;
 }
+
+char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+return virGetHostname();
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 34ac5fc..12da7d2 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -911,12 +911,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-return virGetHostname();
-}
-
-
 static int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 /* Driver is using local, non-network based transport */
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 94afe16..8c44f01 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -218,6 +218,7 @@ virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
 int vboxConnectClose(virConnectPtr conn);
 int vboxDomainSave(virDomainPtr dom, const char *path);
 int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
+char *vboxConnectGetHostname(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 09/29] vbox: Rewrite vboxConnectIsAlive

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |5 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 188b878..f380c78 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -432,3 +432,8 @@ int vboxConnectIsEncrypted(virConnectPtr conn 
ATTRIBUTE_UNUSED)
 /* No encryption is needed, or used on the local transport*/
 return 0;
 }
+
+int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+return 1;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index a1d3918..e08d7cc 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -911,11 +911,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-return 1;
-}
-
 static int
 vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 0d46a7a..e586c3c 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -221,6 +221,7 @@ int vboxConnectGetVersion(virConnectPtr conn, unsigned long 
*version);
 char *vboxConnectGetHostname(virConnectPtr conn);
 int vboxConnectIsSecure(virConnectPtr conn);
 int vboxConnectIsEncrypted(virConnectPtr conn);
+int vboxConnectIsAlive(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 04/29] vbox: Rewrite vboxDomainSave

2014-07-18 Thread Taowei
vboxIIDUnion is introduced in this patch to fixup
vboxIID conflictions.
---
 src/vbox/vbox_common.c|   95 +++
 src/vbox/vbox_common.h|   40 +
 src/vbox/vbox_tmpl.c  |  346 +++--
 src/vbox/vbox_uniformed_api.h |   82 ++
 4 files changed, 478 insertions(+), 85 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 2e23d62..a74a1de 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -41,6 +41,9 @@
 
 VIR_LOG_INIT(vbox.vbox_common);
 
+#define RC_SUCCEEDED(rc) NS_SUCCEEDED(rc.resultCode)
+#define RC_FAILED(rc) NS_FAILED(rc.resultCode)
+
 #define VBOX_UTF16_FREE(arg)\
 do {\
 if (arg) {  \
@@ -68,6 +71,31 @@ VIR_LOG_INIT(vbox.vbox_common);
 #define VBOX_UTF16_TO_UTF8(arg1, arg2)  
gVBoxAPI.UPFN.Utf16ToUtf8(data-pFuncs, arg1, arg2)
 #define VBOX_UTF8_TO_UTF16(arg1, arg2)  
gVBoxAPI.UPFN.Utf8ToUtf16(data-pFuncs, arg1, arg2)
 
+#define VBOX_RELEASE(arg) \
+do {  \
+if (arg) {\
+gVBoxAPI.nsUISupports.Release((void *)arg);
\
+(arg) = NULL; \
+} \
+} while (0)
+
+#define VBOX_OBJECT_CHECK(conn, type, value) \
+vboxGlobalData *data = conn-privateData;\
+type ret = value;\
+if (!data-vboxObj) {\
+return ret;\
+}
+
+#define vboxIIDUnalloc(iid) 
gVBoxAPI.UIID.vboxIIDUnalloc(data, iid)
+#define vboxIIDToUUID(iid, uuid)
gVBoxAPI.UIID.vboxIIDToUUID(data, iid, uuid)
+#define vboxIIDFromUUID(iid, uuid)  
gVBoxAPI.UIID.vboxIIDFromUUID(data, iid, uuid)
+#define vboxIIDIsEqual(iid1, iid2)  
gVBoxAPI.UIID.vboxIIDIsEqual(data, iid1, iid2)
+#define DEBUGIID(msg, iid)  gVBoxAPI.UIID.DEBUGIID(msg, 
iid)
+#define vboxIIDFromArrayItem(iid, array, idx) \
+gVBoxAPI.UUID.vboxIIDFromArrayItem(data, iid, array, idx)
+
+#define VBOX_IID_INITIALIZE(iid)
gVBoxAPI.UIID.vboxIIDInitialize(iid)
+
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
@@ -101,6 +129,22 @@ void vboxRegisterUniformedAPI(uint32_t uVersion)
 }
 }
 
+static int openSessionForMachine(vboxGlobalData *data, const unsigned char 
*dom_uuid, vboxIIDUnion *iid,
+ IMachine **machine, bool checkflag)
+{
+VBOX_IID_INITIALIZE(iid);
+vboxIIDFromUUID(iid, dom_uuid);
+if (!checkflag || gVBoxAPI.getMachineForSession) {
+/* Get machine for the call to VBOX_SESSION_OPEN_EXISTING */
+if (NS_FAILED(gVBoxAPI.UIVirtualBox.GetMachine(data, iid, machine))) {
+virReportError(VIR_ERR_NO_DOMAIN, %s,
+   _(no domain with matching uuid));
+return -1;
+}
+}
+return 0;
+}
+
 static virDomainDefParserConfig vboxDomainDefParserConfig = {
 .macPrefix = { 0x08, 0x00, 0x27 },
 };
@@ -298,3 +342,54 @@ int vboxConnectClose(virConnectPtr conn)
 
 return 0;
 }
+
+int
+vboxDomainSave(virDomainPtr dom, const char *path ATTRIBUTE_UNUSED)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IConsole *console= NULL;
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+IProgress *progress = NULL;
+resultCodeUnion resultCode;
+nsresult rc;
+
+/* VirtualBox currently doesn't support saving to a file
+ * at a location other then the machine folder and thus
+ * setting path to ATTRIBUTE_UNUSED for now, will change
+ * this behaviour once get the VirtualBox API in right
+ * shape to do this
+ */
+
+/* Open a Session for the machine */
+if (openSessionForMachine(data, dom-uuid, iid, machine, true)  0)
+goto cleanup;
+
+rc = gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+if (NS_FAILED(rc))
+goto cleanup;
+
+rc = gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (NS_FAILED(rc) || !console)
+goto freeSession;
+
+rc = gVBoxAPI.UIConsole.SaveState(console, progress);
+if (!progress)
+goto freeSession;
+
+gVBoxAPI.UIProgress.WaitForCompletion(progress, -1);
+gVBoxAPI.UIProgress.GetResultCode(progress, resultCode);
+if (RC_SUCCEEDED(resultCode))
+ret = 0;
+
+ freeSession:
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+ cleanup:
+DEBUGIID(UUID of machine being saved:, iid);
+VBOX_RELEASE(machine);
+VBOX_RELEASE(console);
+VBOX_RELEASE(progress);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_common.h 

[libvirt] [PATCH 08/29] vbox: Rewrite vboxConnectIsEncrypted

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|6 ++
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index cdc3664..188b878 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -426,3 +426,9 @@ int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
 /* Driver is using local, non-network based transport */
 return 1;
 }
+
+int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+/* No encryption is needed, or used on the local transport*/
+return 0;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 745e1d0..a1d3918 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -911,12 +911,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-/* No encryption is needed, or used on the local transport*/
-return 0;
-}
-
 static int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return 1;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index f09eda4..0d46a7a 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -220,6 +220,7 @@ int vboxDomainSave(virDomainPtr dom, const char *path);
 int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
 char *vboxConnectGetHostname(virConnectPtr conn);
 int vboxConnectIsSecure(virConnectPtr conn);
+int vboxConnectIsEncrypted(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 23/29] vbox: Rewrite vboxDomainIsPersistent

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   19 +++
 src/vbox/vbox_tmpl.c  |   26 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 602a468..3aca1b8 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2316,3 +2316,22 @@ int vboxDomainIsActive(virDomainPtr dom)
 
 return ret;
 }
+
+int vboxDomainIsPersistent(virDomainPtr dom)
+{
+/* All domains are persistent.  However, we do want to check for
+ * existence. */
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+ret = 1;
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 6441cf4..dfa9dcf 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,32 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainIsPersistent(virDomainPtr dom ATTRIBUTE_UNUSED)
-{
-/* All domains are persistent.  However, we do want to check for
- * existence. */
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-nsresult rc;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-ret = 1;
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
-
 static int vboxDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED)
 {
 /* VBox domains never have a persistent state that differs from
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index ec5e674..1df6e76 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -429,6 +429,7 @@ int vboxDomainCreate(virDomainPtr dom);
 virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
  unsigned int flags);
 int vboxDomainIsActive(virDomainPtr dom);
+int vboxDomainIsPersistent(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 14/29] vbox: Rewrite vboxDomainLookupById

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   73 
 src/vbox/vbox_tmpl.c  |   82 +++--
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 90 insertions(+), 68 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 4acf0c8..51e07eb 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -549,3 +549,76 @@ int vboxConnectNumOfDomains(virConnectPtr conn)
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+virDomainPtr vboxDomainLookupByID(virConnectPtr conn, int id)
+{
+VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+IMachine *machine;
+PRBool isAccessible = PR_FALSE;
+PRUnichar *machineNameUtf16 = NULL;
+char *machineNameUtf8  = NULL;
+vboxIIDUnion iid;
+unsigned char uuid[VIR_UUID_BUFLEN];
+PRUint32 state;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+/* Internal vbox IDs start from 0, the public libvirt ID
+ * starts from 1, so refuse id == 0, and adjust the rest*/
+if (id == 0) {
+virReportError(VIR_ERR_NO_DOMAIN,
+   _(no domain with matching id %d), id);
+return NULL;
+}
+id = id - 1;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return NULL;
+}
+
+if (id = machines.count)
+goto cleanup;
+
+machine = machines.items[id];
+
+if (!machine)
+goto cleanup;
+
+isAccessible = PR_FALSE;
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (!gVBoxAPI.machineStateChecker.Online(state))
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+gVBoxAPI.UIMachine.GetId(machine, iid);
+vboxIIDToUUID(iid, uuid);
+vboxIIDUnalloc(iid);
+
+/* get a new domain pointer from virGetDomain, if it fails
+ * then no need to assign the id, else assign the id, cause
+ * it is -1 by default. rest is taken care by virGetDomain
+ * itself, so need not worry.
+ */
+
+ret = virGetDomain(conn, machineNameUtf8, uuid);
+if (ret)
+ret-id = id + 1;
+
+/* Cleanup all the XPCOM allocated stuff here */
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_UTF16_FREE(machineNameUtf16);
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index ffd523f..6c3e070 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -945,74 +945,6 @@ static virDomainPtr vboxDomainCreateXML(virConnectPtr 
conn, const char *xml,
 return dom;
 }
 
-static virDomainPtr vboxDomainLookupByID(virConnectPtr conn, int id)
-{
-VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-unsigned char uuid[VIR_UUID_BUFLEN];
-PRUint32 state;
-nsresult rc;
-
-/* Internal vbox IDs start from 0, the public libvirt ID
- * starts from 1, so refuse id == 0, and adjust the rest*/
-if (id == 0) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), id);
-return NULL;
-}
-id = id - 1;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return NULL;
-}
-
-if (id  machines.count) {
-IMachine *machine = machines.items[id];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline)) {
-PRUnichar *machineNameUtf16 = NULL;
-char  *machineNameUtf8  = NULL;
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-machine-vtbl-GetId(machine, iid.value);
-vboxIIDToUUID(iid, uuid);
-vboxIIDUnalloc(iid);
-
-/* get a new domain pointer from virGetDomain, if it fails
- * then no need to assign the id, else assign the id, cause
- * it is -1 by default. rest is taken care by virGetDomain
- * itself, so need not worry.
-   

[libvirt] [PATCH 02/29] vbox: Add test case for vboxUniformedAPI

2014-07-18 Thread Taowei
The test case will make sure each API will filled
with something. So we will not to define an API,
use it, yet forgot to implement.
---
 tests/Makefile.am|9 +++-
 tests/vboxuniformedapitest.c |   98 ++
 2 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 tests/vboxuniformedapitest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index bc1040a..f73d25d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -241,7 +241,7 @@ test_programs += esxutilstest
 endif WITH_ESX
 
 if WITH_VBOX
-test_programs += vboxsnapshotxmltest
+test_programs += vboxsnapshotxmltest vboxuniformedapitest
 endif WITH_VBOX
 
 if WITH_VMX
@@ -638,8 +638,13 @@ vboxsnapshotxmltest_SOURCES = \
testutils.c testutils.h
 vbox_LDADDS = ../src/libvirt_driver_vbox_impl.la
 vboxsnapshotxmltest_LDADD = $(LDADDS) $(vbox_LDADDS)
+
+vboxuniformedapitest_SOURCES = \
+   vboxuniformedapitest.c \
+   testutils.c testutils.h
+vboxuniformedapitest_LDADD = $(vbox_LDADDS) $(LDADDS)
 else ! WITH_VBOX
-EXTRA_DIST += vboxsnapshotxmltest.c
+EXTRA_DIST += vboxsnapshotxmltest.c vboxuniformedapitest.c
 endif ! WITH_VBOX
 
 if WITH_VMX
diff --git a/tests/vboxuniformedapitest.c b/tests/vboxuniformedapitest.c
new file mode 100644
index 000..933cdb7
--- /dev/null
+++ b/tests/vboxuniformedapitest.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2014, Taowei Luo (uaeda...@gmail.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * http://www.gnu.org/licenses/.
+ */
+
+#include config.h
+
+#include testutils.h
+
+#ifdef WITH_VBOX
+
+# include datatypes.h
+# include domain_event.h
+# include vbox/vbox_common.h
+# include vbox/vbox_uniformed_api.h
+
+# define VIR_FROM_THIS VIR_FROM_NONE
+
+static vboxUniformedAPI vboxAPI;
+typedef void (*installAPI_f)(vboxUniformedAPI *pVBoxAPI);
+
+/* This test make sure all APIs in vboxUniformedAPI is
+ * filled with something (say not null). It helps to
+ * make sure you will not leave an API defined (and used
+ * probably) but not implemented yet.
+ */
+
+static int testUniformedAPI(const void *args)
+{
+installAPI_f installAPI = (installAPI_f)args;
+void **iter;
+
+memset(vboxAPI, 0, sizeof(vboxUniformedAPI));
+installAPI(vboxAPI);
+
+/* Assuming that the vboxUniformedAPI is in the range
+ * of [initializeFWatch, fWatchNeedInitialize).
+ */
+for (iter = (void **)vboxAPI.initializeFWatch;
+ iter  (void **)vboxAPI.fWatchNeedInitialize;
+ iter ++)
+{
+if ((void *)(*iter) == NULL)
+return -1;
+}
+return 0;
+}
+
+static int
+mymain(void)
+{
+int ret = 0;
+
+# define TEST(version)  \
+do  {   \
+if (virtTestRun(Test uniformedAPI  # version, \
+testUniformedAPI,   \
+vbox##version##InstallUniformedAPI)  0)\
+ret = -1;   \
+} while (0)
+
+TEST(22);
+TEST(30);
+TEST(31);
+TEST(32);
+TEST(40);
+TEST(41);
+TEST(42);
+TEST(42_20);
+TEST(43);
+TEST(43_4);
+
+return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
+
+#else
+
+int main(void)
+{
+return EXIT_AM_SKIP;
+}
+
+#endif /*WITH_VBOX*/
-- 
1.7.9.5

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


[libvirt] [PATCH 07/29] vbox: Rewrite vboxConnectIsSecure

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|6 ++
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 2588379..cdc3664 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -420,3 +420,9 @@ char *vboxConnectGetHostname(virConnectPtr conn 
ATTRIBUTE_UNUSED)
 {
 return virGetHostname();
 }
+
+int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+/* Driver is using local, non-network based transport */
+return 1;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 12da7d2..745e1d0 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -911,12 +911,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectIsSecure(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-/* Driver is using local, non-network based transport */
-return 1;
-}
-
 static int vboxConnectIsEncrypted(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 /* No encryption is needed, or used on the local transport*/
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 8c44f01..f09eda4 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -219,6 +219,7 @@ int vboxConnectClose(virConnectPtr conn);
 int vboxDomainSave(virDomainPtr dom, const char *path);
 int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
 char *vboxConnectGetHostname(virConnectPtr conn);
+int vboxConnectIsSecure(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 05/29] vbox: Rewrite vboxConnectGetVersion

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   22 ++
 src/vbox/vbox_tmpl.c  |   13 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index a74a1de..3edadce 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -393,3 +393,25 @@ vboxDomainSave(virDomainPtr dom, const char *path 
ATTRIBUTE_UNUSED)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+static void vboxDriverLock(vboxGlobalData *data)
+{
+virMutexLock(data-lock);
+}
+
+static void vboxDriverUnlock(vboxGlobalData *data)
+{
+virMutexUnlock(data-lock);
+}
+
+int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
+{
+vboxGlobalData *data = conn-privateData;
+VIR_DEBUG(%s: in vboxGetVersion, conn-driver-name);
+
+vboxDriverLock(data);
+*version = data-version;
+vboxDriverUnlock(data);
+
+return 0;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 54a84bb..34ac5fc 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -911,19 +911,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
-{
-vboxGlobalData *data = conn-privateData;
-VIR_DEBUG(%s: in vboxGetVersion, conn-driver-name);
-
-vboxDriverLock(data);
-*version = data-version;
-vboxDriverUnlock(data);
-
-return 0;
-}
-
-
 static char *vboxConnectGetHostname(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return virGetHostname();
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 44bb3bc..94afe16 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -217,6 +217,7 @@ virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
  unsigned int flags);
 int vboxConnectClose(virConnectPtr conn);
 int vboxDomainSave(virDomainPtr dom, const char *path);
+int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 03/29] vbox: Rewrite vboxConnectClose

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   11 +++
 src/vbox/vbox_tmpl.c  |   29 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 12 insertions(+), 29 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 8fb4494..2e23d62 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -287,3 +287,14 @@ virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
 
 return VIR_DRV_OPEN_SUCCESS;
 }
+
+int vboxConnectClose(virConnectPtr conn)
+{
+vboxGlobalData *data = conn-privateData;
+VIR_DEBUG(%s: in vboxClose, conn-driver-name);
+
+vboxUninitialize(data);
+conn-privateData = NULL;
+
+return 0;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index cc1733b..f6890d2 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -831,35 +831,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static void vboxUninitialize(vboxGlobalData *data)
-{
-if (!data)
-return;
-
-if (data-pFuncs)
-data-pFuncs-pfnComUninitialize();
-
-virObjectUnref(data-caps);
-virObjectUnref(data-xmlopt);
-#if VBOX_API_VERSION == 2002000
-/* No domainEventCallbacks in 2.2.* version */
-#else  /* !(VBOX_API_VERSION == 2002000) */
-virObjectEventStateFree(data-domainEvents);
-#endif /* !(VBOX_API_VERSION == 2002000) */
-VIR_FREE(data);
-}
-
-static int vboxConnectClose(virConnectPtr conn)
-{
-vboxGlobalData *data = conn-privateData;
-VIR_DEBUG(%s: in vboxClose, conn-driver-name);
-
-vboxUninitialize(data);
-conn-privateData = NULL;
-
-return 0;
-}
-
 static int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version)
 {
 vboxGlobalData *data = conn-privateData;
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index fa753d4..2eda247 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -134,6 +134,7 @@ typedef struct {
 virDrvOpenStatus vboxConnectOpen(virConnectPtr conn,
  virConnectAuthPtr auth,
  unsigned int flags);
+int vboxConnectClose(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 11/29] vbox: Rewrite vboxConnectGetCapabilities

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   11 +++
 src/vbox/vbox_tmpl.c  |   16 ++--
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 1c67eea..ed6597c 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -461,3 +461,14 @@ vboxConnectGetMaxVcpus(virConnectPtr conn, const char 
*type ATTRIBUTE_UNUSED)
 VBOX_RELEASE(systemProperties);
 return ret;
 }
+
+char *vboxConnectGetCapabilities(virConnectPtr conn)
+{
+VBOX_OBJECT_CHECK(conn, char *, NULL);
+
+vboxDriverLock(data);
+ret = virCapabilitiesFormatXML(data-caps);
+vboxDriverUnlock(data);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e17b06f..569ae29 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -253,6 +253,10 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr 
conn, const char *xml);
 static int vboxDomainCreate(virDomainPtr dom);
 static int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 
+#if VBOX_API_VERSION  2002000  VBOX_API_VERSION  400
+/* Since vboxConnectGetCapabilities has been rewriten,
+ * vboxDiverLock and Unlock only be used in 3.* */
+
 static void vboxDriverLock(vboxGlobalData *data)
 {
 virMutexLock(data-lock);
@@ -263,6 +267,8 @@ static void vboxDriverUnlock(vboxGlobalData *data)
 virMutexUnlock(data-lock);
 }
 
+#endif
+
 #if VBOX_API_VERSION == 2002000
 
 static void nsIDtoChar(unsigned char *uuid, const nsID *iid)
@@ -911,16 +917,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static char *vboxConnectGetCapabilities(virConnectPtr conn) {
-VBOX_OBJECT_CHECK(conn, char *, NULL);
-
-vboxDriverLock(data);
-ret = virCapabilitiesFormatXML(data-caps);
-vboxDriverUnlock(data);
-
-return ret;
-}
-
 static int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids)
 {
 VBOX_OBJECT_CHECK(conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 4bd0cf7..18f6870 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -230,6 +230,7 @@ int vboxConnectIsSecure(virConnectPtr conn);
 int vboxConnectIsEncrypted(virConnectPtr conn);
 int vboxConnectIsAlive(virConnectPtr conn);
 int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
+char *vboxConnectGetCapabilities(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 21/29] vbox: Rewrite vboxDomainLookupByName

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   70 
 src/vbox/vbox_tmpl.c  |   71 -
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 72 insertions(+), 71 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index a278a37..b1f0df3 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -822,6 +822,76 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
 return ret;
 }
 
+virDomainPtr
+vboxDomainLookupByName(virConnectPtr conn, const char *name)
+{
+VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+vboxIIDUnion iid;
+char  *machineNameUtf8  = NULL;
+PRUnichar *machineNameUtf16 = NULL;
+unsigned char uuid[VIR_UUID_BUFLEN];
+size_t i;
+int matched = 0;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return NULL;
+}
+
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+PRBool isAccessible = PR_FALSE;
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+if (STREQ(name, machineNameUtf8)) {
+
+PRUint32 state;
+
+matched = 1;
+
+gVBoxAPI.UIMachine.GetId(machine, iid);
+vboxIIDToUUID(iid, uuid);
+vboxIIDUnalloc(iid);
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+/* get a new domain pointer from virGetDomain, if it fails
+ * then no need to assign the id, else assign the id, cause
+ * it is -1 by default. rest is taken care by virGetDomain
+ * itself, so need not worry.
+ */
+
+ret = virGetDomain(conn, machineNameUtf8, uuid);
+if (ret 
+gVBoxAPI.machineStateChecker.Online(state))
+ret-id = i + 1;
+}
+
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+if (matched == 1)
+break;
+}
+
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+
+return ret;
+}
+
 static void
 vboxSetBootDeviceOrder(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c4232aa..9ace580 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,77 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static virDomainPtr
-vboxDomainLookupByName(virConnectPtr conn, const char *name)
-{
-VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-char  *machineNameUtf8  = NULL;
-PRUnichar *machineNameUtf16 = NULL;
-unsigned char uuid[VIR_UUID_BUFLEN];
-size_t i;
-int matched = 0;
-nsresult rc;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return NULL;
-}
-
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-PRBool isAccessible = PR_FALSE;
-
-if (!machine)
-continue;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-if (STREQ(name, machineNameUtf8)) {
-
-PRUint32 state;
-
-matched = 1;
-
-machine-vtbl-GetId(machine, iid.value);
-vboxIIDToUUID(iid, uuid);
-vboxIIDUnalloc(iid);
-
-machine-vtbl-GetState(machine, state);
-
-/* get a new domain pointer from virGetDomain, if it fails
- * then no need to assign the id, else assign the id, cause
- * it is -1 by default. rest is taken care by virGetDomain
- * itself, so need not worry.
- */
-
-ret = virGetDomain(conn, machineNameUtf8, uuid);
-if (ret 
-(state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline))
-ret-id = i + 1;
-}
-
-VBOX_UTF8_FREE(machineNameUtf8);
-  

[libvirt] [PATCH 24/29] vbox: Rewrite vboxDomainIsUpdated

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   19 +++
 src/vbox/vbox_tmpl.c  |   25 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 20 insertions(+), 25 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 3aca1b8..cc25633 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2335,3 +2335,22 @@ int vboxDomainIsPersistent(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainIsUpdated(virDomainPtr dom)
+{
+/* VBox domains never have a persistent state that differs from
+ * current state.  However, we do want to check for existence.  */
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxIIDUnion iid;
+IMachine *machine = NULL;
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index dfa9dcf..96df49c 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,31 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainIsUpdated(virDomainPtr dom ATTRIBUTE_UNUSED)
-{
-/* VBox domains never have a persistent state that differs from
- * current state.  However, we do want to check for existence.  */
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxIID iid = VBOX_IID_INITIALIZER;
-IMachine *machine = NULL;
-nsresult rc;
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN, %s,
-   _(no domain with matching UUID));
-goto cleanup;
-}
-
-ret = 0;
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainSuspend(virDomainPtr dom)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 1df6e76..8397d1b 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -430,6 +430,7 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const 
char *xml,
  unsigned int flags);
 int vboxDomainIsActive(virDomainPtr dom);
 int vboxDomainIsPersistent(virDomainPtr dom);
+int vboxDomainIsUpdated(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 27/29] vbox: Rewrite vboxDomainShutdownFlags

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   48 +
 src/vbox/vbox_tmpl.c  |   67 -
 src/vbox/vbox_uniformed_api.h |3 ++
 3 files changed, 64 insertions(+), 54 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index e9a9f36..cc4328e 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2448,3 +2448,51 @@ int vboxDomainResume(virDomainPtr dom)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+IConsole *console= NULL;
+PRUint32 state;
+PRBool isAccessible  = PR_FALSE;
+
+virCheckFlags(0, -1);
+
+if (openSessionForMachine(data, dom-uuid, iid, machine, false)  0)
+goto cleanup;
+
+if (!machine)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+goto cleanup;
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Paused(state)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine paused, so can't power it down));
+goto cleanup;
+} else if (gVBoxAPI.machineStateChecker.PoweredOff(state)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(machine already powered down));
+goto cleanup;
+}
+
+gVBoxAPI.UISession.OpenExisting(data, iid, machine);
+gVBoxAPI.UISession.GetConsole(data-vboxSession, console);
+if (console) {
+gVBoxAPI.UIConsole.PowerButton(console);
+VBOX_RELEASE(console);
+ret = 0;
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+
+ cleanup:
+VBOX_RELEASE(machine);
+vboxIIDUnalloc(iid);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c6df403..1ec0a3b 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,60 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainShutdownFlags(virDomainPtr dom,
-   unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-IConsole *console= NULL;
-PRUint32 state   = MachineState_Null;
-PRBool isAccessible  = PR_FALSE;
-nsresult rc;
-
-virCheckFlags(0, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-rc = VBOX_OBJECT_GET_MACHINE(iid.value, machine);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_NO_DOMAIN,
-   _(no domain with matching id %d), dom-id);
-goto cleanup;
-}
-
-if (!machine)
-goto cleanup;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-
-if (state == MachineState_Paused) {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine paused, so can't power it down));
-goto cleanup;
-} else if (state == MachineState_PoweredOff) {
-virReportError(VIR_ERR_OPERATION_FAILED, %s,
-   _(machine already powered down));
-goto cleanup;
-}
-
-VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
-data-vboxSession-vtbl-GetConsole(data-vboxSession, console);
-if (console) {
-console-vtbl-PowerButton(console);
-VBOX_RELEASE(console);
-ret = 0;
-}
-VBOX_SESSION_CLOSE();
-}
-
- cleanup:
-VBOX_RELEASE(machine);
-vboxIIDUnalloc(iid);
-return ret;
-}
-
 static int vboxDomainShutdown(virDomainPtr dom)
 {
 return vboxDomainShutdownFlags(dom, 0);
@@ -9933,6 +9879,12 @@ _consoleResume(IConsole *console)
 }
 
 static nsresult
+_consolePowerButton(IConsole *console)
+{
+return console-vtbl-PowerButton(console);
+}
+
+static nsresult
 _progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
 {
 return progress-vtbl-WaitForCompletion(progress, timeout);
@@ -10378,6 +10330,11 @@ static bool _machineStatePaused(PRUint32 state)
 return state == MachineState_Paused;
 }
 
+static bool _machineStatePoweredOff(PRUint32 state)
+{
+return state == MachineState_PoweredOff;
+}
+
 static vboxUniformedPFN _UPFN = {
 .Initialize = _pfnInitialize,
 .Uninitialize = _pfnUninitialize,
@@ -10456,6 +10413,7 @@ static vboxUniformedIConsole _UIConsole = {
 .SaveState = _consoleSaveState,
 .Pause = _consolePause,
 .Resume = _consoleResume,
+.PowerButton = _consolePowerButton,
 };
 
 static vboxUniformedIProgress _UIProgress = {
@@ -10547,6 +10505,7 @@ static uniformedMachineStateChecker 
_machineStateChecker = {
 .NotStart = _machineStateNotStart,
 .Running = _machineStateRunning,
 .Paused = 

[libvirt] [PATCH 13/29] vbox: Rewrite vboxConnectNumOfDomains

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   35 +++
 src/vbox/vbox_tmpl.c  |   36 
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 8eedd4d..4acf0c8 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -514,3 +514,38 @@ int vboxConnectListDomains(virConnectPtr conn, int *ids, 
int nids)
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+int vboxConnectNumOfDomains(virConnectPtr conn)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+PRUint32 state;
+nsresult rc;
+size_t i;
+
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get number of Domains, rc=%08x), 
(unsigned)rc);
+goto cleanup;
+}
+
+ret = 0;
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+
+if (machine) {
+PRBool isAccessible = PR_FALSE;
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (isAccessible) {
+gVBoxAPI.UIMachine.GetState(machine, state);
+if (gVBoxAPI.machineStateChecker.Online(state))
+ret++;
+}
+}
+}
+
+ cleanup:
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 1138566..ffd523f 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -917,42 +917,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxConnectNumOfDomains(virConnectPtr conn)
-{
-VBOX_OBJECT_CHECK(conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-PRUint32 state;
-nsresult rc;
-size_t i;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get number of Domains, rc=%08x), 
(unsigned)rc);
-goto cleanup;
-}
-
-ret = 0;
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-
-if (machine) {
-PRBool isAccessible = PR_FALSE;
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-machine-vtbl-GetState(machine, state);
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline))
-ret++;
-}
-}
-}
-
- cleanup:
-vboxArrayRelease(machines);
-return ret;
-}
-
 static virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
 unsigned int flags)
 {
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 1035ce8..78dd1e7 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -253,6 +253,7 @@ int vboxConnectIsAlive(virConnectPtr conn);
 int vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type);
 char *vboxConnectGetCapabilities(virConnectPtr conn);
 int vboxConnectListDomains(virConnectPtr conn, int *ids, int nids);
+int vboxConnectNumOfDomains(virConnectPtr conn);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 10/29] vbox: Rewrite vboxConnectGetMaxVcpus

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   24 +++
 src/vbox/vbox_common.h|1 +
 src/vbox/vbox_tmpl.c  |   42 ++---
 src/vbox/vbox_uniformed_api.h |8 
 4 files changed, 51 insertions(+), 24 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index f380c78..1c67eea 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -437,3 +437,27 @@ int vboxConnectIsAlive(virConnectPtr conn ATTRIBUTE_UNUSED)
 {
 return 1;
 }
+
+int
+vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
+{
+VBOX_OBJECT_CHECK(conn, int, -1);
+PRUint32 maxCPUCount = 0;
+
+/* VirtualBox Supports only hvm and thus the type passed to it
+ * has no meaning, setting it to ATTRIBUTE_UNUSED
+ */
+ISystemProperties *systemProperties = NULL;
+
+gVBoxAPI.UIVirtualBox.GetSystemProperties(data-vboxObj, 
systemProperties);
+if (!systemProperties)
+goto cleanup;
+gVBoxAPI.UISystemProperties.GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
+
+if (maxCPUCount  0)
+ret = maxCPUCount;
+
+ cleanup:
+VBOX_RELEASE(systemProperties);
+return ret;
+}
diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index aa6be11..e01fa51 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -166,6 +166,7 @@ typedef void ISession;
 typedef void IConsole;
 typedef void IProgress;
 typedef void IMachine;
+typedef void ISystemProperties;
 typedef void IVirtualBoxCallback;
 typedef void nsIEventQueue;
 
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e08d7cc..e17b06f 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -911,30 +911,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int
-vboxConnectGetMaxVcpus(virConnectPtr conn, const char *type ATTRIBUTE_UNUSED)
-{
-VBOX_OBJECT_CHECK(conn, int, -1);
-PRUint32 maxCPUCount = 0;
-
-/* VirtualBox Supports only hvm and thus the type passed to it
- * has no meaning, setting it to ATTRIBUTE_UNUSED
- */
-ISystemProperties *systemProperties = NULL;
-
-data-vboxObj-vtbl-GetSystemProperties(data-vboxObj, systemProperties);
-if (systemProperties) {
-systemProperties-vtbl-GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
-VBOX_RELEASE(systemProperties);
-}
-
-if (maxCPUCount  0)
-ret = maxCPUCount;
-
-return ret;
-}
-
-
 static char *vboxConnectGetCapabilities(virConnectPtr conn) {
 VBOX_OBJECT_CHECK(conn, char *, NULL);
 
@@ -11340,6 +11316,12 @@ _virtualboxGetMachine(vboxGlobalData *data, 
vboxIIDUnion *iidu, IMachine **machi
 
 #endif /* VBOX_API_VERSION = 400 */
 
+static nsresult
+_virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties 
**systemProperties)
+{
+return vboxObj-vtbl-GetSystemProperties(vboxObj, systemProperties);
+}
+
 #if VBOX_API_VERSION  400
 
 static nsresult
@@ -11398,6 +11380,12 @@ _progressGetResultCode(IProgress *progress, 
resultCodeUnion *resultCode)
 #endif /* VBOX_API_VERSION != 2002000 */
 }
 
+static nsresult
+_systemPropertiesGetMaxGuestCPUCount(ISystemProperties *systemProperties, 
PRUint32 *maxCPUCount)
+{
+return systemProperties-vtbl-GetMaxGuestCPUCount(systemProperties, 
maxCPUCount);
+}
+
 static nsresult _nsisupportsRelease(void *Ihandle)
 {
 /* It is safety to convert a pointer from IVirtual(or structs
@@ -11429,6 +11417,7 @@ static vboxUniformedIID _UIID = {
 static vboxUniformedIVirtualBox _UIVirtualBox = {
 .GetVersion = _virtualboxGetVersion,
 .GetMachine = _virtualboxGetMachine,
+.GetSystemProperties = _virtualboxGetSystemProperties,
 };
 
 static vboxUniformedISession _UISession = {
@@ -11446,6 +11435,10 @@ static vboxUniformedIProgress _UIProgress = {
 .GetResultCode = _progressGetResultCode,
 };
 
+static vboxUniformedISystemProperties _UISystemProperties = {
+.GetMaxGuestCPUCount = _systemPropertiesGetMaxGuestCPUCount,
+};
+
 static vboxUniformednsISupports _nsUISupports = {
 .Release = _nsisupportsRelease,
 };
@@ -11462,6 +11455,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI 
*pVBoxAPI)
 pVBoxAPI-UISession = _UISession;
 pVBoxAPI-UIConsole = _UIConsole;
 pVBoxAPI-UIProgress = _UIProgress;
+pVBoxAPI-UISystemProperties = _UISystemProperties;
 pVBoxAPI-nsUISupports = _nsUISupports;
 
 #if (VBOX_XPCOMC_VERSION == 0x0001U) || (VBOX_API_VERSION == 2002000)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index e586c3c..4bd0cf7 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -163,6 +163,7 @@ typedef struct {
 typedef struct {
 nsresult (*GetVersion)(IVirtualBox *vboxObj, PRUnichar **versionUtf16);
 nsresult (*GetMachine)(vboxGlobalData *data, vboxIIDUnion *iidu, IMachine 
**machine);
+nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, 

[libvirt] [PATCH 28/29] vbox: Rewrite vboxDomainShutdown

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |6 --
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index cc4328e..98d7c8a 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2496,3 +2496,8 @@ int vboxDomainShutdownFlags(virDomainPtr dom, unsigned 
int flags)
 vboxIIDUnalloc(iid);
 return ret;
 }
+
+int vboxDomainShutdown(virDomainPtr dom)
+{
+return vboxDomainShutdownFlags(dom, 0);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 1ec0a3b..28bf9be 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,12 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainShutdown(virDomainPtr dom)
-{
-return vboxDomainShutdownFlags(dom, 0);
-}
-
-
 static int vboxDomainReboot(virDomainPtr dom, unsigned int flags)
 {
 VBOX_OBJECT_CHECK(dom-conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 52a8cee..5926a2a 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -440,6 +440,7 @@ int vboxDomainIsUpdated(virDomainPtr dom);
 int vboxDomainSuspend(virDomainPtr dom);
 int vboxDomainResume(virDomainPtr dom);
 int vboxDomainShutdownFlags(virDomainPtr dom, unsigned int flags);
+int vboxDomainShutdown(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 22/29] vbox: Rewrite vboxDomainIsActive

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   66 
 src/vbox/vbox_tmpl.c  |   67 -
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 67 insertions(+), 67 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index b1f0df3..602a468 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2250,3 +2250,69 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, 
const char *xml,
 
 return dom;
 }
+
+int vboxDomainIsActive(virDomainPtr dom)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+vboxIIDUnion iid;
+char  *machineNameUtf8  = NULL;
+PRUnichar *machineNameUtf16 = NULL;
+unsigned char uuid[VIR_UUID_BUFLEN];
+size_t i;
+int matched = 0;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return ret;
+}
+
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+PRBool isAccessible = PR_FALSE;
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+gVBoxAPI.UIMachine.GetId(machine, iid);
+if (NS_FAILED(rc))
+continue;
+vboxIIDToUUID(iid, uuid);
+vboxIIDUnalloc(iid);
+
+if (memcmp(dom-uuid, uuid, VIR_UUID_BUFLEN) == 0) {
+
+PRUint32 state;
+
+matched = 1;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+if (gVBoxAPI.machineStateChecker.Online(state))
+ret = 1;
+else
+ret = 0;
+}
+
+if (matched == 1)
+break;
+}
+
+/* Do the cleanup and take care you dont leak any memory */
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 9ace580..6441cf4 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,73 +916,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const 
PRUnichar *utf16,
 return result;
 }
 
-static int vboxDomainIsActive(virDomainPtr dom)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-char  *machineNameUtf8  = NULL;
-PRUnichar *machineNameUtf16 = NULL;
-unsigned char uuid[VIR_UUID_BUFLEN];
-size_t i;
-int matched = 0;
-nsresult rc;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return ret;
-}
-
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-PRBool isAccessible = PR_FALSE;
-
-if (!machine)
-continue;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-
-rc = machine-vtbl-GetId(machine, iid.value);
-if (NS_FAILED(rc))
-continue;
-vboxIIDToUUID(iid, uuid);
-vboxIIDUnalloc(iid);
-
-if (memcmp(dom-uuid, uuid, VIR_UUID_BUFLEN) == 0) {
-
-PRUint32 state;
-
-matched = 1;
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-machine-vtbl-GetState(machine, state);
-
-if ((state = MachineState_FirstOnline) 
-(state = MachineState_LastOnline))
-ret = 1;
-else
-ret = 0;
-}
-
-if (matched == 1)
-break;
-}
-}
-
-/* Do the cleanup and take care you dont leak any memory */
-VBOX_UTF8_FREE(machineNameUtf8);
-VBOX_COM_UNALLOC_MEM(machineNameUtf16);
-vboxArrayRelease(machines);
-
-return ret;
-}
-
-
 static int vboxDomainIsPersistent(virDomainPtr dom ATTRIBUTE_UNUSED)
 {
 /* All domains are persistent.  However, we do want to check for
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 8b84b1f..ec5e674 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -428,6 +428,7 @@ int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned 
int flags);
 int 

[libvirt] [PATCH 16/29] vbox: Rewrite vboxDomainUndefineFlags

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   67 
 src/vbox/vbox_tmpl.c  |  356 +
 src/vbox/vbox_uniformed_api.h |8 +
 3 files changed, 255 insertions(+), 176 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 8993519..436b6b0 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -27,6 +27,7 @@
 #include virlog.h
 #include viralloc.h
 #include nodeinfo.h
+#include virstring.h
 
 #include vbox_common.h
 #include vbox_uniformed_api.h
@@ -695,3 +696,69 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
 
 return ret;
 }
+
+static void
+detachDevices_common(vboxGlobalData *data, vboxIIDUnion *iidu)
+{
+/* Block for checking if HDD's are attched to VM.
+ * considering just IDE bus for now. Also skipped
+ * chanel=1 and device=0 (Secondary Master) as currenlty
+ * it is allocated to CD/DVD Drive by default.
+ *
+ * Only do this for VirtualBox 3.x and before. Since
+ * VirtualBox 4.0 the Unregister method can do this for use.
+ */
+IMachine *machine = NULL;
+PRUnichar *hddcnameUtf16 = NULL;
+nsresult rc;
+
+char *hddcname;
+ignore_value(VIR_STRDUP(hddcname, IDE));
+VBOX_UTF8_TO_UTF16(hddcname, hddcnameUtf16);
+VIR_FREE(hddcname);
+
+/* Open a Session for the machine */
+rc = gVBoxAPI.UISession.Open(data, iidu, machine);
+if (NS_SUCCEEDED(rc)) {
+rc = gVBoxAPI.UISession.GetMachine(data-vboxSession, machine);
+if (NS_SUCCEEDED(rc)  machine) {
+gVBoxAPI.detachDevices(data, machine, hddcnameUtf16);
+gVBoxAPI.UIMachine.SaveSettings(machine);
+}
+gVBoxAPI.UISession.Close(data-vboxSession);
+}
+VBOX_UTF16_FREE(hddcnameUtf16);
+}
+
+int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+IMachine *machine= NULL;
+vboxIIDUnion iid;
+nsresult rc;
+
+gVBoxAPI.UIID.vboxIIDInitialize(iid);
+/* No managed save, so we explicitly reject
+ * VIR_DOMAIN_UNDEFINE_MANAGED_SAVE.  No snapshot metadata for
+ * VBox, so we can trivially ignore that flag.  */
+virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
+vboxIIDFromUUID(iid, dom-uuid);
+if (gVBoxAPI.detachDevicesExplicitly)
+detachDevices_common(data, iid);
+rc = gVBoxAPI.unregisterMachine(data, iid, machine);
+
+DEBUGIID(UUID of machine being undefined, iid);
+
+if (NS_SUCCEEDED(rc)) {
+gVBoxAPI.deleteConfig(machine);
+ret = 0;
+} else {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(could not delete the domain, rc=%08x), 
(unsigned)rc);
+}
+
+vboxIIDUnalloc(iid);
+VBOX_RELEASE(machine);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 219e44a..315feba 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -251,7 +251,6 @@ static vboxGlobalData *g_pVBoxGlobalData = NULL;
 
 static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml);
 static int vboxDomainCreate(virDomainPtr dom);
-static int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 
 #if VBOX_API_VERSION  2002000  VBOX_API_VERSION  400
 /* Since vboxConnectGetCapabilities has been rewriten,
@@ -4781,181 +4780,6 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr 
conn, const char *xml)
 }
 
 static int
-vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags)
-{
-VBOX_OBJECT_CHECK(dom-conn, int, -1);
-IMachine *machine= NULL;
-vboxIID iid = VBOX_IID_INITIALIZER;
-nsresult rc;
-#if VBOX_API_VERSION = 400
-vboxArray media = VBOX_ARRAY_INITIALIZER;
-#endif
-/* No managed save, so we explicitly reject
- * VIR_DOMAIN_UNDEFINE_MANAGED_SAVE.  No snapshot metadata for
- * VBox, so we can trivially ignore that flag.  */
-virCheckFlags(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA, -1);
-
-vboxIIDFromUUID(iid, dom-uuid);
-
-#if VBOX_API_VERSION  400
-/* Block for checking if HDD's are attched to VM.
- * considering just IDE bus for now. Also skipped
- * chanel=1 and device=0 (Secondary Master) as currenlty
- * it is allocated to CD/DVD Drive by default.
- *
- * Only do this for VirtualBox 3.x and before. Since
- * VirtualBox 4.0 the Unregister method can do this for use.
- */
-{
-PRUnichar *hddcnameUtf16 = NULL;
-
-char *hddcname;
-ignore_value(VIR_STRDUP(hddcname, IDE));
-VBOX_UTF8_TO_UTF16(hddcname, hddcnameUtf16);
-VIR_FREE(hddcname);
-
-/* Open a Session for the machine */
-rc = VBOX_SESSION_OPEN(iid.value, machine);
-if (NS_SUCCEEDED(rc)) {
-rc = data-vboxSession-vtbl-GetMachine(data-vboxSession, 
machine);
-if (NS_SUCCEEDED(rc)  machine) {
-
-# if VBOX_API_VERSION  3001000
-/* Disconnect all the drives if present */
-

[libvirt] [PATCH 18/29] vbox: Rewrite vboxDomainCreateWithFlags

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|  219 
 src/vbox/vbox_tmpl.c  |  274 +++--
 src/vbox/vbox_uniformed_api.h |8 ++
 3 files changed, 269 insertions(+), 232 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 0d57b2c..c5b6c4e 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1928,3 +1928,222 @@ int vboxDomainUndefineFlags(virDomainPtr dom, unsigned 
int flags)
 
 return ret;
 }
+
+static int
+vboxStartMachine(virDomainPtr dom, int maxDomID, IMachine *machine, 
vboxIIDUnion *iid)
+{
+VBOX_OBJECT_CHECK(dom-conn, int, -1);
+int vrdpPresent  = 0;
+int sdlPresent   = 0;
+int guiPresent   = 0;
+char *guiDisplay = NULL;
+char *sdlDisplay = NULL;
+PRUnichar *keyTypeUtf16  = NULL;
+PRUnichar *valueTypeUtf16= NULL;
+char  *valueTypeUtf8 = NULL;
+PRUnichar *keyDislpayUtf16   = NULL;
+PRUnichar *valueDisplayUtf16 = NULL;
+char  *valueDisplayUtf8  = NULL;
+IProgress *progress  = NULL;
+PRUnichar *env   = NULL;
+PRUnichar *sessionType   = NULL;
+nsresult rc;
+
+VBOX_UTF8_TO_UTF16(FRONTEND/Type, keyTypeUtf16);
+gVBoxAPI.UIMachine.GetExtraData(machine, keyTypeUtf16, valueTypeUtf16);
+VBOX_UTF16_FREE(keyTypeUtf16);
+
+if (valueTypeUtf16) {
+VBOX_UTF16_TO_UTF8(valueTypeUtf16, valueTypeUtf8);
+VBOX_UTF16_FREE(valueTypeUtf16);
+
+if (STREQ(valueTypeUtf8, sdl) || STREQ(valueTypeUtf8, gui)) {
+
+VBOX_UTF8_TO_UTF16(FRONTEND/Display, keyDislpayUtf16);
+gVBoxAPI.UIMachine.GetExtraData(machine, keyDislpayUtf16,
+valueDisplayUtf16);
+VBOX_UTF16_FREE(keyDislpayUtf16);
+
+if (valueDisplayUtf16) {
+VBOX_UTF16_TO_UTF8(valueDisplayUtf16, valueDisplayUtf8);
+VBOX_UTF16_FREE(valueDisplayUtf16);
+
+if (strlen(valueDisplayUtf8) = 0)
+VBOX_UTF8_FREE(valueDisplayUtf8);
+}
+
+if (STREQ(valueTypeUtf8, sdl)) {
+sdlPresent = 1;
+if (VIR_STRDUP(sdlDisplay, valueDisplayUtf8)  0) {
+/* just don't go to cleanup yet as it is ok to have
+ * sdlDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
+}
+}
+
+if (STREQ(valueTypeUtf8, gui)) {
+guiPresent = 1;
+if (VIR_STRDUP(guiDisplay, valueDisplayUtf8)  0) {
+/* just don't go to cleanup yet as it is ok to have
+ * guiDisplay as NULL and we check it below if it
+ * exist and then only use it there
+ */
+}
+}
+}
+
+if (STREQ(valueTypeUtf8, vrdp)) {
+vrdpPresent = 1;
+}
+
+if (!vrdpPresent  !sdlPresent  !guiPresent) {
+/* if nothing is selected it means either the machine xml
+ * file is really old or some values are missing so fallback
+ */
+guiPresent = 1;
+}
+
+VBOX_UTF8_FREE(valueTypeUtf8);
+
+} else {
+guiPresent = 1;
+}
+VBOX_UTF8_FREE(valueDisplayUtf8);
+
+if (guiPresent) {
+if (guiDisplay) {
+char *displayutf8;
+if (virAsprintf(displayutf8, DISPLAY=%s, guiDisplay) = 0) {
+VBOX_UTF8_TO_UTF16(displayutf8, env);
+VIR_FREE(displayutf8);
+}
+VIR_FREE(guiDisplay);
+}
+
+VBOX_UTF8_TO_UTF16(gui, sessionType);
+}
+
+if (sdlPresent) {
+if (sdlDisplay) {
+char *displayutf8;
+if (virAsprintf(displayutf8, DISPLAY=%s, sdlDisplay) = 0) {
+VBOX_UTF8_TO_UTF16(displayutf8, env);
+VIR_FREE(displayutf8);
+}
+VIR_FREE(sdlDisplay);
+}
+
+VBOX_UTF8_TO_UTF16(sdl, sessionType);
+}
+
+if (vrdpPresent) {
+VBOX_UTF8_TO_UTF16(vrdp, sessionType);
+}
+
+rc = gVBoxAPI.UIMachine.LaunchVMProcess(data, machine, iid,
+sessionType, env,
+progress);
+
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_OPERATION_FAILED, %s,
+   _(OpenRemoteSession/LaunchVMProcess failed, domain 
can't be started));
+ret = -1;
+} else {
+PRBool completed = 0;
+resultCodeUnion resultCode;
+
+gVBoxAPI.UIProgress.WaitForCompletion(progress, -1);
+rc = gVBoxAPI.UIProgress.GetCompleted(progress, completed);
+if (NS_FAILED(rc)) {
+/* error */
+ret = -1;
+}
+

[libvirt] [PATCH 19/29] vbox: Rewrite vboxDomainCreate

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|5 +
 src/vbox/vbox_tmpl.c  |7 ---
 src/vbox/vbox_uniformed_api.h |1 +
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index c5b6c4e..4861d52 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2147,3 +2147,8 @@ int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned 
int flags)
  cleanup:
 return ret;
 }
+
+int vboxDomainCreate(virDomainPtr dom)
+{
+return vboxDomainCreateWithFlags(dom, 0);
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c13d1a9..2c3097b 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -249,8 +249,6 @@ static vboxGlobalData *g_pVBoxGlobalData = NULL;
 
 #endif /* VBOX_API_VERSION = 400 */
 
-static int vboxDomainCreate(virDomainPtr dom);
-
 #if VBOX_API_VERSION  2002000  VBOX_API_VERSION  400
 /* Since vboxConnectGetCapabilities has been rewriten,
  * vboxDiverLock and Unlock only be used in 3.* */
@@ -3064,11 +3062,6 @@ static int vboxConnectNumOfDefinedDomains(virConnectPtr 
conn)
 return ret;
 }
 
-static int vboxDomainCreate(virDomainPtr dom)
-{
-return vboxDomainCreateWithFlags(dom, 0);
-}
-
 #if VBOX_API_VERSION  3001000
 
 static void
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 5c406c9..7e04845 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -423,6 +423,7 @@ virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
 virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml);
 int vboxDomainUndefineFlags(virDomainPtr dom, unsigned int flags);
 int vboxDomainCreateWithFlags(virDomainPtr dom, unsigned int flags);
+int vboxDomainCreate(virDomainPtr dom);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

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


[libvirt] [PATCH 15/29] vbox: Rewrite vboxDomainLookupByUUId

2014-07-18 Thread Taowei
---
 src/vbox/vbox_common.c|   73 +
 src/vbox/vbox_tmpl.c  |   73 -
 src/vbox/vbox_uniformed_api.h |2 ++
 3 files changed, 75 insertions(+), 73 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 51e07eb..8993519 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -622,3 +622,76 @@ virDomainPtr vboxDomainLookupByID(virConnectPtr conn, int 
id)
 gVBoxAPI.UArray.vboxArrayRelease(machines);
 return ret;
 }
+
+virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
+const unsigned char *uuid)
+{
+VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
+vboxArray machines = VBOX_ARRAY_INITIALIZER;
+vboxIIDUnion iid;
+char  *machineNameUtf8  = NULL;
+PRUnichar *machineNameUtf16 = NULL;
+unsigned char iid_as_uuid[VIR_UUID_BUFLEN];
+size_t i;
+int matched = 0;
+nsresult rc;
+
+VBOX_IID_INITIALIZE(iid);
+rc = gVBoxAPI.UArray.vboxArrayGet(machines, data-vboxObj, 
ARRAY_GET_MACHINES);
+if (NS_FAILED(rc)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
+return NULL;
+}
+
+for (i = 0; i  machines.count; ++i) {
+IMachine *machine = machines.items[i];
+PRBool isAccessible = PR_FALSE;
+
+if (!machine)
+continue;
+
+gVBoxAPI.UIMachine.GetAccessible(machine, isAccessible);
+if (!isAccessible)
+continue;
+
+rc = gVBoxAPI.UIMachine.GetId(machine, iid);
+if (NS_FAILED(rc))
+continue;
+vboxIIDToUUID(iid, iid_as_uuid);
+vboxIIDUnalloc(iid);
+
+if (memcmp(uuid, iid_as_uuid, VIR_UUID_BUFLEN) == 0) {
+
+PRUint32 state;
+
+matched = 1;
+
+gVBoxAPI.UIMachine.GetName(machine, machineNameUtf16);
+VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
+
+gVBoxAPI.UIMachine.GetState(machine, state);
+
+/* get a new domain pointer from virGetDomain, if it fails
+ * then no need to assign the id, else assign the id, cause
+ * it is -1 by default. rest is taken care by virGetDomain
+ * itself, so need not worry.
+ */
+
+ret = virGetDomain(conn, machineNameUtf8, iid_as_uuid);
+if (ret 
+gVBoxAPI.machineStateChecker.Online(state))
+ret-id = i + 1;
+ }
+
+ if (matched == 1)
+ break;
+}
+
+/* Do the cleanup and take care you dont leak any memory */
+VBOX_UTF8_FREE(machineNameUtf8);
+VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+gVBoxAPI.UArray.vboxArrayRelease(machines);
+
+return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 6c3e070..219e44a 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -946,79 +946,6 @@ static virDomainPtr vboxDomainCreateXML(virConnectPtr 
conn, const char *xml,
 }
 
 static virDomainPtr
-vboxDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
-{
-VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
-vboxArray machines = VBOX_ARRAY_INITIALIZER;
-vboxIID iid = VBOX_IID_INITIALIZER;
-char  *machineNameUtf8  = NULL;
-PRUnichar *machineNameUtf16 = NULL;
-unsigned char iid_as_uuid[VIR_UUID_BUFLEN];
-size_t i;
-int matched = 0;
-nsresult rc;
-
-rc = vboxArrayGet(machines, data-vboxObj, 
data-vboxObj-vtbl-GetMachines);
-if (NS_FAILED(rc)) {
-virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(Could not get list of machines, rc=%08x), 
(unsigned)rc);
-return NULL;
-}
-
-for (i = 0; i  machines.count; ++i) {
-IMachine *machine = machines.items[i];
-PRBool isAccessible = PR_FALSE;
-
-if (!machine)
-continue;
-
-machine-vtbl-GetAccessible(machine, isAccessible);
-if (isAccessible) {
-
-rc = machine-vtbl-GetId(machine, iid.value);
-if (NS_FAILED(rc))
-continue;
-vboxIIDToUUID(iid, iid_as_uuid);
-vboxIIDUnalloc(iid);
-
-if (memcmp(uuid, iid_as_uuid, VIR_UUID_BUFLEN) == 0) {
-
-PRUint32 state;
-
-matched = 1;
-
-machine-vtbl-GetName(machine, machineNameUtf16);
-VBOX_UTF16_TO_UTF8(machineNameUtf16, machineNameUtf8);
-
-machine-vtbl-GetState(machine, state);
-
-/* get a new domain pointer from virGetDomain, if it fails
- * then no need to assign the id, else assign the id, cause
- * it is -1 by default. rest is taken care by virGetDomain
- * itself, so need not worry.
- */
-
-ret = virGetDomain(conn, machineNameUtf8, iid_as_uuid);
-if 

[libvirt] [PATCH] doc: add domain to address of hostdev pci

2014-07-18 Thread Hu Tao
libvirt supports pci domain already, so update the documentation.
Otherwise users who lookup the documentation for how to use hostdev may
miss the domain and encounter error when pass-through a pci device in a
domain other than 0.

Signed-off-by: Hu Tao hu...@cn.fujitsu.com
---
 docs/formatdomain.html.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 3c85fc5..4572feb 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2777,7 +2777,7 @@
   lt;devicesgt;
 lt;hostdev mode='subsystem' type='pci' managed='yes'gt;
   lt;sourcegt;
-lt;address bus='0x06' slot='0x02' function='0x0'/gt;
+lt;address domain='0x' bus='0x06' slot='0x02' function='0x0'/gt;
   lt;/sourcegt;
   lt;boot order='1'/gt;
   lt;rom bar='on' file='/etc/fake/boot.bin'/gt;
@@ -2891,7 +2891,7 @@
   USB bus and device number the device appears at on the host.
   The values of these attributes can be given in decimal, hexadecimal
   (starting with 0x) or octal (starting with 0) form.
-  For PCI devices the element carries 3 attributes allowing to designate
+  For PCI devices the element carries 4 attributes allowing to designate
   the device as can be found with the codelspci/code or
   with codevirsh
   nodedev-list/code. a href=#elementsAddressSee above/a for
-- 
1.9.3

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


[libvirt] [PATCHv4 2/2] lxc domain from xml: convert lxc.cap.drop

2014-07-18 Thread Cédric Bosdonnat
---
 src/lxc/lxc_native.c   | 25 ++
 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml|  2 ++
 tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml   |  2 ++
 tests/lxcconf2xmldata/lxcconf2xml-cputune.xml  |  2 ++
 tests/lxcconf2xmldata/lxcconf2xml-idmap.xml|  2 ++
 .../lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml |  4 
 tests/lxcconf2xmldata/lxcconf2xml-memtune.xml  |  2 ++
 tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml  |  4 
 tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml|  2 ++
 tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml  |  4 
 tests/lxcconf2xmldata/lxcconf2xml-simple.xml   |  8 +++
 tests/lxcconf2xmldata/lxcconf2xml-vlannetwork.xml  |  4 
 12 files changed, 61 insertions(+)

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index bb15a36..3ffcd47 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -843,6 +843,28 @@ lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties)
 return 0;
 }
 
+static void
+lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties)
+{
+virConfValuePtr value;
+char **toDrop = NULL;
+const char *capString;
+size_t i;
+
+if ((value = virConfGetValue(properties, lxc.cap.drop))  value-str)
+toDrop = virStringSplit(value-str,  , 0);
+
+for (i = 0; i  VIR_DOMAIN_CAPS_FEATURE_LAST; i++) {
+capString = virDomainCapsFeatureTypeToString(i);
+if (toDrop != NULL  virStringArrayHasString(toDrop, capString))
+def-caps_features[i] = VIR_DOMAIN_FEATURE_STATE_OFF;
+}
+
+def-features[VIR_DOMAIN_FEATURE_CAPABILITIES] = 
VIR_DOMAIN_CAPABILITIES_POLICY_ALLOW;
+
+virStringFreeList(toDrop);
+}
+
 virDomainDefPtr
 lxcParseConfigString(const char *config)
 {
@@ -940,6 +962,9 @@ lxcParseConfigString(const char *config)
 if (lxcSetBlkioTune(vmdef, properties)  0)
 goto error;
 
+/* lxc.cap.drop */
+lxcSetCapDrop(vmdef, properties);
+
 goto cleanup;
 
  error:
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml 
b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
index 36b8e52..c9c0469 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml
@@ -25,6 +25,8 @@
   /os
   features
 privnet/
+capabilities policy='allow'
+/capabilities
   /features
   clock offset='utc'/
   on_poweroffdestroy/on_poweroff
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml 
b/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml
index 932ab61..e7863fa 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml
@@ -13,6 +13,8 @@
   /os
   features
 privnet/
+capabilities policy='allow'
+/capabilities
   /features
   clock offset='utc'/
   on_poweroffdestroy/on_poweroff
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml 
b/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml
index 1bab1c6..50c5358 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-cputune.xml
@@ -15,6 +15,8 @@
   /os
   features
 privnet/
+capabilities policy='allow'
+/capabilities
   /features
   clock offset='utc'/
   on_poweroffdestroy/on_poweroff
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-idmap.xml 
b/tests/lxcconf2xmldata/lxcconf2xml-idmap.xml
index 050ccd6..80a83ff 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-idmap.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-idmap.xml
@@ -14,6 +14,8 @@
   /idmap
   features
 privnet/
+capabilities policy='allow'
+/capabilities
   /features
   clock offset='utc'/
   on_poweroffdestroy/on_poweroff
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml 
b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
index 996c0f7..3105b8c 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml
@@ -8,6 +8,10 @@
 typeexe/type
 init/sbin/init/init
   /os
+  features
+capabilities policy='allow'
+/capabilities
+  /features
   clock offset='utc'/
   on_poweroffdestroy/on_poweroff
   on_rebootrestart/on_reboot
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml 
b/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml
index b7c919e..7df1ef0 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-memtune.xml
@@ -15,6 +15,8 @@
   /os
   features
 privnet/
+capabilities policy='allow'
+/capabilities
   /features
   clock offset='utc'/
   on_poweroffdestroy/on_poweroff
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml 
b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
index 6d9e16d..e002b99 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml
@@ -8,6 +8,10 @@
 typeexe/type
 init/sbin/init/init
   /os
+  features
+capabilities policy='allow'
+

[libvirt] [PATCHv4 0/2] lxc keep/drop capabilities

2014-07-18 Thread Cédric Bosdonnat
Hi all,

Even though the v3 has been ACKed (but not pushed), I rebased it on top of
master before pushing it and did a few changes that are worth checking before.

 * Path 1 (feature) and 3 (doc) of the previous version merge merged together as
   suggested for another similar series.

 * virCgroupAllowDevice() has been changed to use negative major / minor device
   values to output '*'. I never saw any of them negative, but I don't have a
   good knowledge of that.

--
Cedric


Cédric Bosdonnat (2):
  lxc: allow to keep or drop capabilities
  lxc domain from xml: convert lxc.cap.drop

 docs/drvlxc.html.in|  47 
 docs/schemas/domaincommon.rng  | 207 ++
 src/conf/domain_conf.c | 126 ++-
 src/conf/domain_conf.h |  56 +
 src/libvirt_private.syms   |   3 +
 src/lxc/lxc_cgroup.c   |   8 +
 src/lxc/lxc_container.c| 241 +++--
 src/lxc/lxc_native.c   |  25 +++
 src/util/vircgroup.c   |  57 -
 src/util/vircgroup.h   |   2 +
 tests/domainschemadata/domain-caps-features.xml|  28 +++
 tests/lxcconf2xmldata/lxcconf2xml-blkiotune.xml|   2 +
 tests/lxcconf2xmldata/lxcconf2xml-cpusettune.xml   |   2 +
 tests/lxcconf2xmldata/lxcconf2xml-cputune.xml  |   2 +
 tests/lxcconf2xmldata/lxcconf2xml-idmap.xml|   2 +
 .../lxcconf2xmldata/lxcconf2xml-macvlannetwork.xml |   4 +
 tests/lxcconf2xmldata/lxcconf2xml-memtune.xml  |   2 +
 tests/lxcconf2xmldata/lxcconf2xml-nonenetwork.xml  |   4 +
 tests/lxcconf2xmldata/lxcconf2xml-nonetwork.xml|   2 +
 tests/lxcconf2xmldata/lxcconf2xml-physnetwork.xml  |   4 +
 tests/lxcconf2xmldata/lxcconf2xml-simple.xml   |   8 +
 tests/lxcconf2xmldata/lxcconf2xml-vlannetwork.xml  |   4 +
 22 files changed, 816 insertions(+), 20 deletions(-)
 create mode 100644 tests/domainschemadata/domain-caps-features.xml

-- 
1.8.4.5

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

[libvirt] [PATCHv4 1/2] lxc: allow to keep or drop capabilities

2014-07-18 Thread Cédric Bosdonnat
Added capabilities in the features section of LXC domains
configuration. This section can contain elements named after the
capabilities like:

  mknod state=on/, keep CAP_MKNOD capability
  sys_chroot state=off/ drop CAP_SYS_CHROOT capability

Users can restrict or give more capabilities than the default using
this mechanism.
---
 docs/drvlxc.html.in |  47 +
 docs/schemas/domaincommon.rng   | 207 
 src/conf/domain_conf.c  | 126 -
 src/conf/domain_conf.h  |  56 ++
 src/libvirt_private.syms|   3 +
 src/lxc/lxc_cgroup.c|   8 +
 src/lxc/lxc_container.c | 241 ++--
 src/util/vircgroup.c|  57 +-
 src/util/vircgroup.h|   2 +
 tests/domainschemadata/domain-caps-features.xml |  28 +++
 10 files changed, 755 insertions(+), 20 deletions(-)
 create mode 100644 tests/domainschemadata/domain-caps-features.xml

diff --git a/docs/drvlxc.html.in b/docs/drvlxc.html.in
index fc4bc20..403ce24 100644
--- a/docs/drvlxc.html.in
+++ b/docs/drvlxc.html.in
@@ -540,6 +540,53 @@ debootstrap, whatever) under /opt/vm-1-root:
 lt;/domaingt;
 /pre
 
+h2a name=capabilitiesAltering the available capabilities/a/h2
+
+p
+By default the libvirt LXC driver drops some capabilities among which 
CAP_MKNOD.
+However span class=sincesince 1.2.6/span libvirt can be told to keep or
+drop some capabilities using a domain configuration like the following:
+/p
+pre
+...
+lt;featuresgt;
+  lt;capabilities policy='default'gt;
+lt;mknod state='on'/gt;
+lt;sys_chroot state='off'/gt;
+  lt;/capabilitiesgt;
+lt;/featuresgt;
+...
+/pre
+p
+The capabilities children elements are named after the capabilities as defined 
in
+codeman 7 capabilities/code. An codeoff/code state tells libvirt to 
drop the
+capability, while an codeon/code state will force to keep the capability 
even though
+this one is dropped by default.
+/p
+p
+The codepolicy/code attribute can be one of codedefault/code, 
codeallow/code
+or codedeny/code. It defines the default rules for capabilities: either 
keep the
+default behavior that is dropping a few selected capabilities, or keep all 
capabilities
+or drop all capabilities. The interest of codeallow/code and 
codedeny/code is that
+they guarantee that all capabilities will be kept (or removed) even if new 
ones are added
+later.
+/p
+p
+The following example, drops all capabilities but CAP_MKNOD:
+/p
+pre
+...
+lt;featuresgt;
+  lt;capabilities policy='deny'gt;
+lt;mknod state='on'/gt;
+  lt;/capabilitiesgt;
+lt;/featuresgt;
+...
+/pre
+p
+Note that allowing capabilities that are normally dropped by default can 
seriously
+affect the security of the container and the host.
+/p
 
 h2a name=usageContainer usage / management/a/h2
 
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 2caeef9..cf0a66d 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3798,6 +3798,9 @@
   empty/
 /element
   /optional
+  optional
+ref name=capabilities/
+  /optional
 /interleave
   /element
 /optional
@@ -4370,6 +4373,200 @@
 /element
   /define
 
+  !-- Optional capabilities features --
+  define name=capabilities
+element name=capabilities
+  ref name=capabilitiespolicy/
+  interleave
+optional
+  element name=audit_control
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=audit_write
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=block_suspend
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=chown
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=dac_override
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=dac_read_search
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=fowner
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=fsetid
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=ipc_lock
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=ipc_owner
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=kill
+ref name=featurestate/
+  /element
+/optional
+optional
+  element name=lease
+

Re: [libvirt] [PATCH] spec: Consolidate with_qemu* definitions

2014-07-18 Thread Jiri Denemark
On Thu, Jul 17, 2014 at 09:12:31 -0600, Eric Blake wrote:
 On 07/17/2014 08:22 AM, Jiri Denemark wrote:
  Decisions whether qemu driver and libvirt-daemon-{qemu,kvm} packages
  should be built on various OS/arch combinations were scattered around
  the spec file. Let's make it easier to see where qemu driver is going to
  be built.
  
  Signed-off-by: Jiri Denemark jdene...@redhat.com
  ---
   libvirt.spec.in | 52 +---
   1 file changed, 25 insertions(+), 27 deletions(-)
  
  diff --git a/libvirt.spec.in b/libvirt.spec.in
  index 9c7b241..472fa4b 100644
  --- a/libvirt.spec.in
  +++ b/libvirt.spec.in
  @@ -54,15 +54,27 @@
   %define with_vbox  0%{!?_without_vbox:%{server_drivers}}
   
   %define with_qemu_tcg  %{with_qemu}
  -# Change if we ever provide qemu-kvm binaries on non-x86 hosts
  -%if 0%{?fedora} = 18
  +
  +%define qemu_kvm_arches %{ix86} x86_64
  +
  +%if 0%{?fedora}
  +%if 0%{?fedora}  16
  +# Fedora doesn't have any QEMU on ppc64 until FC16 - only ppc
  +%ifarch ppc64
  +%define with_qemu_tcg 0
  +%endif
  +%endif
 
 This may be removed if we come to a conclusion in the other thread about
 how much we want to support older Fedora.  But we can clean it up later,
 this patch is just moving it.
 
 ACK.

Pushed, thanks.

Jirka

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


Re: [libvirt] [PATCHv4 1/2] lxc: allow to keep or drop capabilities

2014-07-18 Thread chenhanx...@cn.fujitsu.com


 -Original Message-
 From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
 On Behalf Of Cédric Bosdonnat
 Sent: Friday, July 18, 2014 4:02 PM
 To: libvir-list@redhat.com
 Cc: Cédric Bosdonnat
 Subject: [libvirt] [PATCHv4 1/2] lxc: allow to keep or drop capabilities
 
 Added capabilities in the features section of LXC domains
 configuration. This section can contain elements named after the
 capabilities like:
 
   mknod state=on/, keep CAP_MKNOD capability
   sys_chroot state=off/ drop CAP_SYS_CHROOT capability
 
 Users can restrict or give more capabilities than the default using
 this mechanism.
 ---

Reviewed-by: Chen Hanxiao chenhanx...@cn.fujitsu.com

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

[libvirt] [PATCH v2] examples: Introduce domtop

2014-07-18 Thread Michal Privoznik
There's this question on the list that is asked over and over again.
How do I get {cpu, memory, ...} usage in percentage? Or its modified
version: How do I plot nice graphs like virt-manager does?

It would be nice if we have an example to inspire people. And that's
what domtop should do. Yes, it could be written in different ways, but
I've chosen this one as I think it show explicitly what users need to
implement in order to imitate virt-manager's graphing.

Note: The usage is displayed from host perspective. That is, how much
host CPUs the domain is using. But it should be fairly simple to
switch do just guest CPU usage if needed.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 .gitignore  |   1 +
 Makefile.am |   2 +-
 cfg.mk  |   2 +-
 configure.ac|   1 +
 examples/domtop/Makefile.am |  27 +++
 examples/domtop/domtop.c| 400 
 libvirt.spec.in |   2 +-
 7 files changed, 432 insertions(+), 3 deletions(-)
 create mode 100644 examples/domtop/Makefile.am
 create mode 100644 examples/domtop/domtop.c

diff --git a/.gitignore b/.gitignore
index 2d4d401..90fee91 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,6 +75,7 @@
 /examples/dominfo/info1
 /examples/domsuspend/suspend
 /examples/dommigrate/dommigrate
+/examples/domtop/domtop
 /examples/hellolibvirt/hellolibvirt
 /examples/openauth/openauth
 /gnulib/lib/*
diff --git a/Makefile.am b/Makefile.am
index a374e1a..4aafe94 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,7 +24,7 @@ SUBDIRS = . gnulib/lib include src daemon tools docs 
gnulib/tests \
   examples/dominfo examples/domsuspend examples/apparmor \
   examples/xml/nwfilter examples/openauth examples/systemtap \
   tools/wireshark examples/dommigrate \
-  examples/lxcconvert
+  examples/lxcconvert examples/domtop
 
 ACLOCAL_AMFLAGS = -I m4
 
diff --git a/cfg.mk b/cfg.mk
index c3d89a0..0559edd 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1078,7 +1078,7 @@ exclude_file_name_regexp--sc_prohibit_sprintf = \
 exclude_file_name_regexp--sc_prohibit_strncpy = ^src/util/virstring\.c$$
 
 exclude_file_name_regexp--sc_prohibit_strtol = \
-  ^(src/util/.*|examples/domsuspend/suspend)\.c$$
+  ^(src/util/.*|examples/dom.*/.*)\.c$$
 
 exclude_file_name_regexp--sc_prohibit_xmlGetProp = ^src/util/virxml\.c$$
 
diff --git a/configure.ac b/configure.ac
index 8001e24..f37c716 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2755,6 +2755,7 @@ AC_CONFIG_FILES([\
 examples/domsuspend/Makefile \
 examples/dominfo/Makefile \
 examples/dommigrate/Makefile \
+examples/domtop/Makefile \
 examples/openauth/Makefile \
 examples/hellolibvirt/Makefile \
 examples/systemtap/Makefile \
diff --git a/examples/domtop/Makefile.am b/examples/domtop/Makefile.am
new file mode 100644
index 000..c5cb6c7
--- /dev/null
+++ b/examples/domtop/Makefile.am
@@ -0,0 +1,27 @@
+## Process this file with automake to produce Makefile.in
+
+## Copyright (C) 2014 Red Hat, Inc.
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library.  If not, see
+## http://www.gnu.org/licenses/.
+
+INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include
+LDADDS = $(STATIC_BINARIES) $(WARN_CFLAGS) $(top_builddir)/src/libvirt.la \
+   $(COVERAGE_LDFLAGS)
+
+noinst_PROGRAMS=domtop
+
+domtop_SOURCES=domtop.c
+domtop_LDFLAGS=
+domtop_LDADD= $(LDADDS)
diff --git a/examples/domtop/domtop.c b/examples/domtop/domtop.c
new file mode 100644
index 000..6fb6cbe
--- /dev/null
+++ b/examples/domtop/domtop.c
@@ -0,0 +1,400 @@
+/*
+ * domtop.c: Demo program showing how to calculate CPU usage
+ *
+ * Copyright (C) 2014 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * http://www.gnu.org/licenses/.
+ *
+ * Author: 

[libvirt] [PATCH 2/2] qemu: snapshot: Forbid snapshots of iSCSI passthrough devices

2014-07-18 Thread Peter Krempa
As with the local SCSI passthrough devicesm qemu can't support snapshots
on those as the block ops are handled by the device. This is also true
for iSCSI backing of the disk. Remove the check for the local block
device and just forbid snapshot when the disk is of type 'lun'.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1073368
---
 src/qemu/qemu_driver.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 33541d3..3096688 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12434,10 +12434,7 @@ 
qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk)
 static int
 qemuDomainSnapshotPrepareDiskExternalBackingActive(virDomainDiskDefPtr disk)
 {
-int actualType = virStorageSourceGetActualType(disk-src);
-
-if (actualType == VIR_STORAGE_TYPE_BLOCK 
-disk-device == VIR_DOMAIN_DISK_DEVICE_LUN) {
+if (disk-device == VIR_DOMAIN_DISK_DEVICE_LUN) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
_(external active snapshots are not supported on scsi 
  passthrough devices));
-- 
2.0.0

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


[libvirt] [PATCH 0/2] Fix docs and handling of snapshots on SCSI passthrough devices

2014-07-18 Thread Peter Krempa
Libvirt didn't catch an attempt to do a snapshot of a SCSI passthrough disk
when backed by iSCSI and the docs didn't state that disk type 'lun' works also
with iSCSI.

Peter Krempa (2):
  doc: domain: Clarify that disk type 'lun' works with iSCSI too
  qemu: snapshot: Forbid snapshots of iSCSI passthrough devices

 docs/formatdomain.html.in | 3 ++-
 src/qemu/qemu_driver.c| 5 +
 2 files changed, 3 insertions(+), 5 deletions(-)

-- 
2.0.0

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


[libvirt] [PATCH 1/2] doc: domain: Clarify that disk type 'lun' works with iSCSI too

2014-07-18 Thread Peter Krempa
Disk type 'lun' enables SCSI command passthrough for a disk. We stated
that it works only with block disks. Qemu supports it also when using
the iSCSI protocol.
---
 docs/formatdomain.html.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 3c85fc5..e74606d 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -1683,7 +1683,8 @@
 defaulting to disk.
 p
 Using lun (span class=sincesince 0.9.10/span) is only
-valid when type is block, and behaves identically to disk,
+valid when type is block or network using the iSCSI protocol,
+and behaves identically to disk,
 except that generic SCSI commands from the guest are accepted
 and passed through to the physical device. Also note that
 device='lun' will only be recognized for actual raw devices,
-- 
2.0.0

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


Re: [libvirt] [PATCHv4 2/2] lxc domain from xml: convert lxc.cap.drop

2014-07-18 Thread chenhanx...@cn.fujitsu.com


 -Original Message-
 From: libvir-list-boun...@redhat.com [mailto:libvir-list-boun...@redhat.com]
 On Behalf Of Cédric Bosdonnat
 Sent: Friday, July 18, 2014 4:03 PM
 To: libvir-list@redhat.com
 Cc: Cédric Bosdonnat
 Subject: [libvirt] [PATCHv4 2/2] lxc domain from xml: convert lxc.cap.drop
 
 ---

Reviewed-by: Chen Hanxiao chenhanx...@cn.fujitsu.com

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

Re: [libvirt] [PATCH] qemuConnectGetDomainCapabilities: Use wiser defaults

2014-07-18 Thread Michal Privoznik
On 17.07.2014 11:28, Daniel P. Berrange wrote:
 On Thu, Jul 17, 2014 at 11:12:05AM +0200, Michal Privoznik wrote:
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index 33541d3..7d99435 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -16849,17 +16849,17 @@ qemuConnectGetDomainCapabilities(virConnectPtr 
 conn,
   char *ret = NULL;
   virQEMUDriverPtr driver = conn-privateData;
   virQEMUCapsPtr qemuCaps = NULL;
 -int virttype; /* virDomainVirtType */
 +int virttype = VIR_DOMAIN_VIRT_KVM; /* virDomainVirtType */
 
 Isn't this going to always fail when we run inside a guest which does not
 have nested virt? When we know the QEMU binary, we probe to see whether
 it can do KVM or not, so could we postpone this decision about virt type
 until after we've checked if KVM was available ?

I don't think we can. I mean, in order to construct virDomainCaps object we 
need to know the virttype. The KVM is checked later in the process when the 
object exits already. What we can do, however, is check for KVM twice. How 
about this squashed in?

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7d99435..33d6e47 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -16849,7 +16849,7 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
 char *ret = NULL;
 virQEMUDriverPtr driver = conn-privateData;
 virQEMUCapsPtr qemuCaps = NULL;
-int virttype = VIR_DOMAIN_VIRT_KVM; /* virDomainVirtType */
+int virttype; /* virDomainVirtType */
 virDomainCapsPtr domCaps = NULL;
 int arch = virArchFromHost(); /* virArch */
 
@@ -16858,6 +16858,11 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,
 if (virConnectGetDomainCapabilitiesEnsureACL(conn)  0)
 return ret;
 
+if (qemuHostdevHostSupportsPassthroughLegacy())
+virttype = VIR_DOMAIN_VIRT_KVM;
+else
+virttype = VIR_DOMAIN_VIRT_QEMU;
+
 if (virttype_str 
 (virttype = virDomainVirtTypeFromString(virttype_str))  0) {
 virReportError(VIR_ERR_INVALID_ARG,

Michal

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


[libvirt] [PATCH] support vhost-scsi controller

2014-07-18 Thread Zhang Min
 libvirt support vhost-scsi controller. The way to config
 the vhost-scsi controller is edit the xml file, Format is
 as follows:

controller type='scsi' index='0' model='vhost-scsi'
source wwpn='naa.6001405f5e3acbba' event_idx='on'/
/controller

the tag of wwpn is necessary, the 'model' must be 'vhost-scsi'
'event_idx' is optional.

Signed-off-by: Zhang Min rudy.zhang...@huawei.com
---
 src/conf/domain_conf.c   |   64 +++--
 src/conf/domain_conf.h   |   10 ++
 src/qemu/qemu_capabilities.c |2 +
 src/qemu/qemu_capabilities.h |1 +
 src/qemu/qemu_command.c  |   21 -
 src/vmx/vmx.c|3 +-
 6 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 54925ba..e42ede7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -306,7 +306,8 @@ VIR_ENUM_IMPL(virDomainControllerModelSCSI, 
VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAS
   vmpvscsi,
   ibmvscsi,
   virtio-scsi,
-  lsisas1078);
+  lsisas1078,
+  vhost-scsi);
 
 VIR_ENUM_IMPL(virDomainControllerModelUSB, 
VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
   piix3-uhci,
@@ -1290,6 +1291,10 @@ void 
virDomainControllerDefFree(virDomainControllerDefPtr def)
 if (!def)
 return;
 
+if (def-vhostscsi.wwpn)
+VIR_FREE(def-vhostscsi.wwpn);
+memset(def-vhostscsi, 0, sizeof(def-vhostscsi));
+
 virDomainDeviceInfoClear(def-info);
 
 VIR_FREE(def);
@@ -6051,6 +6056,9 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 char *max_sectors = NULL;
 xmlNodePtr saved = ctxt-node;
 int rc;
+char *wwpn = NULL;
+char *event_idx = NULL;
+int event_idx_num = 0;
 
 ctxt-node = node;
 
@@ -6087,13 +6095,42 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 def-model = -1;
 }
 
+def-vhostscsi.wwpn = NULL;
 cur = node-children;
 while (cur != NULL) {
 if (cur-type == XML_ELEMENT_NODE) {
 if (xmlStrEqual(cur-name, BAD_CAST driver))
 queues = virXMLPropString(cur, queues);
-cmd_per_lun = virXMLPropString(cur, cmd_per_lun);
-max_sectors = virXMLPropString(cur, max_sectors);
+else if(xmlStrEqual(cur-name, BAD_CAST source)) {
+switch (def-model) {
+case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VHOST_SCSI:
+wwpn = virXMLPropString(cur, wwpn);
+if (wwpn  !STREQ(wwpn,)) {
+def-vhostscsi.wwpn = wwpn;
+wwpn = NULL;
+} else {
+virReportError(VIR_ERR_XML_ERROR,
+_(vhost-scsi:wwpn can't be null));
+goto error;
+}
+
+event_idx = virXMLPropString(cur, event_idx);
+if (event_idx) {
+if ((event_idx_num = 
virDomainVirtioEventIdxTypeFromString(event_idx)) = 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unknown vhost-scsi event_idx 
mode '%s'),
+   event_idx);
+goto error;
+}
+def-vhostscsi.event_idx = event_idx_num;
+}
+break;
+default:
+break;
+}
+}
+cmd_per_lun = virXMLPropString(cur, cmd_per_lun);
+max_sectors = virXMLPropString(cur, max_sectors);
 }
 cur = cur-next;
 }
@@ -6216,6 +6253,12 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 goto error;
 }
 
+if (def-model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VHOST_SCSI 
+def-vhostscsi.wwpn == NULL) {
+virReportError(VIR_ERR_XML_ERROR,_(vhost-scsi:wwpn can't be null));
+goto error;
+}
+
  cleanup:
 ctxt-node = saved;
 VIR_FREE(type);
@@ -6224,6 +6267,8 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 VIR_FREE(queues);
 VIR_FREE(cmd_per_lun);
 VIR_FREE(max_sectors);
+VIR_FREE(wwpn);
+VIR_FREE(event_idx);
 
 return def;
 
@@ -15300,10 +15345,21 @@ virDomainControllerDefFormat(virBufferPtr buf,
 break;
 }
 
-if (def-queues || def-cmd_per_lun || def-max_sectors ||
+if (def-queues || def-cmd_per_lun || def-max_sectors || 
def-vhostscsi.wwpn
 virDomainDeviceInfoIsSet(def-info, flags) || pcihole64) {
 virBufferAddLit(buf, \n);
 virBufferAdjustIndent(buf, 2);
+
+if (def-vhostscsi.wwpn) {
+virBufferAsprintf(buf,   source wwpn='%s', 
def-vhostscsi.wwpn);
+
+   if 

Re: [libvirt] [PATCH v3 07/16] numatune: Encapsulate numatune configuration in order to unify results

2014-07-18 Thread Martin Kletzander

On Thu, Jul 17, 2014 at 10:02:45PM +0400, Roman Bogorodskiy wrote:

 Eric Blake wrote:


On 07/17/2014 10:57 AM, Roman Bogorodskiy wrote:
   Roman Bogorodskiy wrote:


 Looks like this breaks build with clang:

 gmake[3]: Entering directory `/usr/home/novel/code/libvirt/src'
   CC   util/libvirt_util_la-virclosecallbacks.lo
 In file included from util/virclosecallbacks.c:28:
 In file included from ../src/util/virclosecallbacks.h:28:
 ../src/conf/domain_conf.h:70:35: error: redefinition of typedef 
'virDomainNumatune' is a C11 feature [-Werror,-Wtypedef-redefinition]
 typedef struct _virDomainNumatune virDomainNumatune;
   ^
 ../src/conf/numatune_conf.h:43:35: note: previous definition is here
 typedef struct _virDomainNumatune virDomainNumatune;
   ^


 I got it fixed by the following diff:

 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
 index 4c9b7e8..e4d7988 100644
 --- a/src/conf/domain_conf.h
 +++ b/src/conf/domain_conf.h
 @@ -67,9 +67,6 @@ typedef virDomainFSDef *virDomainFSDefPtr;
  typedef struct _virDomainNetDef virDomainNetDef;
  typedef virDomainNetDef *virDomainNetDefPtr;

 -typedef struct _virDomainNumatune virDomainNumatune;
 -typedef virDomainNumatune *virDomainNumatunePtr;
 -
  typedef struct _virDomainInputDef virDomainInputDef;
  typedef virDomainInputDef *virDomainInputDefPtr;

ACK to this hunk.


 @@ -1854,8 +1851,6 @@ struct _virDomainResourceDef {
   * NB: if adding to this struct, virDomainDefCheckABIStability
   * may well need an update
   */
 -typedef struct _virDomainDef virDomainDef;
 -typedef virDomainDef *virDomainDefPtr;
  struct _virDomainDef {

But this hunk feels fishy.  Why does numatune_conf.h need virDomainDef?
 It's a leaky abstraction - virDomainNumatuneNodeParseXML is accessing
def-cpu directly instead of limiting itself to just def-numatune.
Also, virDomainNumatuneParseXML is accessing def-placement_mode, which
argues that placement_mode should be part of def-numatune rather than
an independent variable.



I tried abstracting as much as possible, and the numatune parsing code
was really a mess.  Now that it's abstracted a bit, I could rework it
so that it doesn't require virDomainDef at all.  It also needs to
change something in the virDomainDef, but that could be some kind of
output of the function.


Yes, this hunk solves the compiler fix, but it means that we are just
cementing that we didn't abstract things into a single object.  That is,
my ideal setup would be that numatune has access to all the pieces that
it reads/modifies as parameters, but not access the entire virDomainDef,
and then we don't have a circular referencing situation and don't need
numatune_conf.h to be the source of our typedef declaration of virDomainDef.

 I didn't check it beyond build and check/syntax-check though. Anyway, it
 doesn't look quite clean to have typedefs in numatune_conf.h for the
 struct declared in domain_conf.h.



It wasn't problem with newer gcc since the pre-definition is the same
as the actual typedef.  And because all the gcc versions me and Michal
compiled this on were newer, we didn't hit the bug and therefore I
thought circular dependencies can be solved like this, so I haven't
try that hard to abstract the whole numatune all the way :).


I'd be fine with your patch going in as a stop-gap compilation fix, even
if I still think that we could restructure the code better to make
numatune_conf.h self-contained and move the typedef for virDomainDef
back to domain_conf.h.


Good, so I pushed the patch.



And I'm reworking it so it looks and works as we want.

Martin


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [libvirt-glib] gobject: Fix GEnum generation through glib-mkenums

2014-07-18 Thread Zeeshan Ali (Khattak)
On Tue, Jun 3, 2014 at 10:16 AM, Christophe Fergeau cferg...@redhat.com wrote:
 We were only passing libvirt-gobject-domain.h and
 libvirt-gobject-connection.h through glib-mkenums, which causes it to
 only generate GEnum information for enums found in these headers.
 We want to do that for all enums defined in installed headers, so
 passing all headers listed in libvirt_gobject_1_0_la_HEADERS is more
 appropriate.

ACK if your patch doesn't introduce any warnings/errors.

 ---
  libvirt-gobject/Makefile.am | 4 ++--
  libvirt-gobject/libvirt-gobject.sym | 5 +
  2 files changed, 7 insertions(+), 2 deletions(-)

 diff --git a/libvirt-gobject/Makefile.am b/libvirt-gobject/Makefile.am
 index 516c10f..7163c7d 100644
 --- a/libvirt-gobject/Makefile.am
 +++ b/libvirt-gobject/Makefile.am
 @@ -93,7 +93,7 @@ libvirt_gobject_1_0_la_LDFLAGS = \
 -Wl,--version-script=$(srcdir)/libvirt-gobject.sym \
 -version-info $(LIBVIRT_GLIB_VERSION_INFO)

 -libvirt-gobject-enums.c: libvirt-gobject-domain.h 
 libvirt-gobject-connection.h
 +libvirt-gobject-enums.c: $(libvirt_gobject_1_0_la_HEADERS)
 $(AM_V_GEN)glib-mkenums \
  --fhead #include 
 \libvirt-gobject/libvirt-gobject.h\\n\n \
  --vhead static const G@Type@Value 
 _@enum_name@_values[] = { \
 @@ -106,7 +106,7 @@ libvirt-gobject-enums.c: libvirt-gobject-domain.h 
 libvirt-gobject-connection.h
  --vtail   return type;\n}\n\n \
  $^ | sed -e 's/g_vir/gvir/g'  $@

 -libvirt-gobject-enums.h: libvirt-gobject-domain.h 
 libvirt-gobject-connection.h
 +libvirt-gobject-enums.h: $(libvirt_gobject_1_0_la_HEADERS)
 $(AM_V_GEN)glib-mkenums--fhead #ifndef 
 __LIBVIRT_GOBJECT_ENUMS_H__\n \
  --fhead #define __LIBVIRT_GOBJECT_ENUMS_H__\n\n \
  --fhead G_BEGIN_DECLS\n\n \
 diff --git a/libvirt-gobject/libvirt-gobject.sym 
 b/libvirt-gobject/libvirt-gobject.sym
 index b781cc6..4e856e7 100644
 --- a/libvirt-gobject/libvirt-gobject.sym
 +++ b/libvirt-gobject/libvirt-gobject.sym
 @@ -237,6 +237,11 @@ LIBVIRT_GOBJECT_0.1.5 {
  LIBVIRT_GOBJECT_0.1.9 {
global:
 gvir_domain_snapshot_delete;
 +   gvir_domain_snapshot_delete_flags_get_type;
 +   gvir_storage_pool_state_get_type;
 +   gvir_storage_vol_resize_flags_get_type;
 +   gvir_storage_vol_type_get_type;
 +   gvir_stream_io_condition_get_type;

Are these related? Shouldn't this change be split?

Regards,

Zeeshan Ali (Khattak)

Befriend GNOME: http://www.gnome.org/friends/

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


Re: [libvirt] OVMF exposure in libvirt

2014-07-18 Thread Michal Privoznik

On 14.07.2014 16:12, Paolo Bonzini wrote:

Il 14/07/2014 11:27, Daniel P. Berrange ha scritto:

  -drive file=img_1,if=pflash,format=raw,readonly \
  -drive file=img_2,if=pflash,format=raw


It's safer to add ,unit=0 and ,unit=1 too.


We already use loader/ for specifying alternative BIOS blobs for
the QEMU -bios arg. Since you say this obsoletes the -bios arg, I
think it makes sense to use loader/ for the read-only firmware
image.


It obsoletes the -bios argument, but it is not the same thing:

1) on some machines you can use -drive if=pflash for the nvram, but
not for the firmware


And how should the FW cmd line look like then?



2) on some older versions of QEMU, -drive if=pflash will work only on
TCG or will not work at all so you cannot blindly replace it.


Whoa. How to detect this? I mean, how do detect both?



What about:

loader readonly='on|off' type='rom|flash'.../loader
nvram.../nvram

where the mapping from nvram to -drive if=flash is partly
machine-dependent.  On x86, for example, nvram adds the ,unit=1
sub-option and fails if the loader element is absent; it also fails if
loader has type='rom'.



Makes sense.


For the variable storage, I'd probably suggest nvram/ as the
element name, since IIUC that's a fairly commonly used term for
this concept.


I like this.


Additionally it would be great if we'd be able to
generate an empty nvram for a guest if the user doesn't specify it.


I'm not big fan of this. Pre-creating storage is something that should 
be done by mgmt applications (migration with non-shared storage is 
something different).




Laszlo has OVMF patches to auto-format an all-zero nvram file.


Great. Do they work automagically or does libvirt need to enable the 
formatting somehow (e.g. monitor command, cmd line argument, ...)?




Paolo


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


Re: [libvirt] OVMF exposure in libvirt

2014-07-18 Thread Paolo Bonzini
Il 18/07/2014 15:01, Michal Privoznik ha scritto:
 On 14.07.2014 16:12, Paolo Bonzini wrote:
 Il 14/07/2014 11:27, Daniel P. Berrange ha scritto:
   -drive file=img_1,if=pflash,format=raw,readonly \
   -drive file=img_2,if=pflash,format=raw

 It's safer to add ,unit=0 and ,unit=1 too.

 We already use loader/ for specifying alternative BIOS blobs for
 the QEMU -bios arg. Since you say this obsoletes the -bios arg, I
 think it makes sense to use loader/ for the read-only firmware
 image.

 It obsoletes the -bios argument, but it is not the same thing:

 1) on some machines you can use -drive if=pflash for the nvram, but
 not for the firmware
 
 And how should the FW cmd line look like then?

You use -bios for the firmware, and -drive (without unit=1) for the nvram.


 2) on some older versions of QEMU, -drive if=pflash will work only on
 TCG or will not work at all so you cannot blindly replace it.
 
 Whoa. How to detect this? I mean, how do detect both?

Do not bother.  Just assume that people know what they're doing.

Paolo


 What about:

 loader readonly='on|off' type='rom|flash'.../loader
 nvram.../nvram

 where the mapping from nvram to -drive if=flash is partly
 machine-dependent.  On x86, for example, nvram adds the ,unit=1
 sub-option and fails if the loader element is absent; it also fails if
 loader has type='rom'.

 
 Makes sense.
 
 For the variable storage, I'd probably suggest nvram/ as the
 element name, since IIUC that's a fairly commonly used term for
 this concept.

 I like this.

 Additionally it would be great if we'd be able to
 generate an empty nvram for a guest if the user doesn't specify it.
 
 I'm not big fan of this. Pre-creating storage is something that should
 be done by mgmt applications (migration with non-shared storage is
 something different).
 

 Laszlo has OVMF patches to auto-format an all-zero nvram file.
 
 Great. Do they work automagically or does libvirt need to enable the
 formatting somehow (e.g. monitor command, cmd line argument, ...)?
 

 Paolo
 

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


Re: [libvirt] [PATCH 1/2] doc: domain: Clarify that disk type 'lun' works with iSCSI too

2014-07-18 Thread Eric Blake
On 07/18/2014 03:22 AM, Peter Krempa wrote:
 Disk type 'lun' enables SCSI command passthrough for a disk. We stated
 that it works only with block disks. Qemu supports it also when using
 the iSCSI protocol.
 ---
  docs/formatdomain.html.in | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

ACK.

 
 diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
 index 3c85fc5..e74606d 100644
 --- a/docs/formatdomain.html.in
 +++ b/docs/formatdomain.html.in
 @@ -1683,7 +1683,8 @@
  defaulting to disk.
  p
  Using lun (span class=sincesince 0.9.10/span) is only
 -valid when type is block, and behaves identically to disk,
 +valid when type is block or network using the iSCSI protocol,
 +and behaves identically to disk,
  except that generic SCSI commands from the guest are accepted
  and passed through to the physical device. Also note that
  device='lun' will only be recognized for actual raw devices,
 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/2] qemu: snapshot: Forbid snapshots of iSCSI passthrough devices

2014-07-18 Thread Eric Blake
On 07/18/2014 03:22 AM, Peter Krempa wrote:
 As with the local SCSI passthrough devicesm qemu can't support snapshots
 on those as the block ops are handled by the device. This is also true
 for iSCSI backing of the disk. Remove the check for the local block
 device and just forbid snapshot when the disk is of type 'lun'.
 
 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1073368
 ---
  src/qemu/qemu_driver.c | 5 +
  1 file changed, 1 insertion(+), 4 deletions(-)

ACK

 
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index 33541d3..3096688 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -12434,10 +12434,7 @@ 
 qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk)
  static int
  qemuDomainSnapshotPrepareDiskExternalBackingActive(virDomainDiskDefPtr disk)
  {
 -int actualType = virStorageSourceGetActualType(disk-src);
 -
 -if (actualType == VIR_STORAGE_TYPE_BLOCK 
 -disk-device == VIR_DOMAIN_DISK_DEVICE_LUN) {
 +if (disk-device == VIR_DOMAIN_DISK_DEVICE_LUN) {
  virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
 _(external active snapshots are not supported on 
 scsi 
   passthrough devices));
 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] doc: add domain to address of hostdev pci

2014-07-18 Thread Eric Blake
On 07/18/2014 01:59 AM, Hu Tao wrote:
 libvirt supports pci domain already, so update the documentation.
 Otherwise users who lookup the documentation for how to use hostdev may
 miss the domain and encounter error when pass-through a pci device in a
 domain other than 0.
 
 Signed-off-by: Hu Tao hu...@cn.fujitsu.com
 ---
  docs/formatdomain.html.in | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

ACK; will push shortly.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/2] Refactor virMutexInit virRWLockInit and virCondInit

2014-07-18 Thread Eric Blake
On 07/17/2014 10:49 PM, Jincheng Miao wrote:
 Implement InitInternal functions for Mutex, RWLock and Cond, these functions
 contain error report using virReportSystemErrorFull, it is controlled by
 an argument 'quite'.

s/quite/quiet/

 The related macros are Init and InitQuite, they call InitInternal function

s/InitQuite/InitQuiet/ - looks like you need to respin, as it's rather
pervasive.

 by passing 'false' or 'true' to quite argument.
 
 Signed-off-by: Jincheng Miao jm...@redhat.com
 ---
  src/libvirt_private.syms |  7 ++--
  src/util/virthread.c | 95 
 
  src/util/virthread.h | 57 ++---
  3 files changed, 94 insertions(+), 65 deletions(-)
 

  
 -void virMutexDestroy(virMutexPtr m)
 +void virMutexDestroy(virMutexPtr mutex)
  {
 -pthread_mutex_destroy(m-lock);
 +pthread_mutex_destroy(mutex-lock);
  }

Please separate trivial renamings into its own patch, so that this patch
can focus on the meat of new additions rather than having to hunt for
the real changes amidst the noise.



-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/2] Refactor virMutexInit virRWLockInit and virCondInit

2014-07-18 Thread Eric Blake
On 07/17/2014 10:49 PM, Jincheng Miao wrote:
 Implement InitInternal functions for Mutex, RWLock and Cond, these functions
 contain error report using virReportSystemErrorFull, it is controlled by
 an argument 'quite'.
 The related macros are Init and InitQuite, they call InitInternal function
 by passing 'false' or 'true' to quite argument.

After your patch 2, do we really have any callers that use the quiet
version? This seems like the sort of patch where ALL callers should be
noisy (especially since the failure is so rare, but also means we are
quite hosed if it happens).  What are the callers that you intend to be
quiet, and what is the justification for them being quiet?


-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v2] examples: Introduce domtop

2014-07-18 Thread Eric Blake
On 07/18/2014 03:08 AM, Michal Privoznik wrote:
 There's this question on the list that is asked over and over again.
 How do I get {cpu, memory, ...} usage in percentage? Or its modified
 version: How do I plot nice graphs like virt-manager does?
 
 It would be nice if we have an example to inspire people. And that's
 what domtop should do. Yes, it could be written in different ways, but
 I've chosen this one as I think it show explicitly what users need to
 implement in order to imitate virt-manager's graphing.
 
 Note: The usage is displayed from host perspective. That is, how much
 host CPUs the domain is using. But it should be fairly simple to
 switch do just guest CPU usage if needed.
 
 Signed-off-by: Michal Privoznik mpriv...@redhat.com
 ---

 +++ b/examples/domtop/domtop.c

 +
 +#define STREQ(a,b) (strcmp(a,b) == 0)

Space after comma, twice.

 +
 +static void
 +print_usage(const char *progname)
 +{
 +const char *unified_progname;
 +
 +if (!(unified_progname = strrchr(progname, '/')))
 +unified_progname = progname;
 +else
 +unified_progname++;
 +
 +printf(\n%s [options] [domain name]\n\n
 + options:\n
 +   -d | --debugenable debug messages\n
 +   -h | --help print this help\n
 +   -c | --connect=URI  hypervisor connection URI\n
 +   -D | --delay=X  delay between updates in milliseconds\n

Maybe mention the default, if -D is not specified.

 +   \n
 +   Print the cumulative usage of each host CPU. \n
 +   Without any domain name specified the list of \n

Two instances of trailing whitespace in the output. s/ \n/\n/


 +case 'D':
 +/* strtoul man page suggest clearing errno prior to call */

s/suggest/suggests/

 +errno = 0;
 +val = strtoul(optarg, p, 10);
 +if (errno || *p || p == optarg) {
 +ERROR(Invalid number: '%s', optarg);
 +goto cleanup;
 +}
 +*milliseconds = val;
 +if (*milliseconds != val) {
 +ERROR(Integer overflow: %ld, val);
 +goto cleanup;

Looks odd to have 'goto cleanup' here...

 +}
 +break;
 +case ':':
 +ERROR(option '-%c' requires an argument, optopt);
 +exit(EXIT_FAILURE);
 +case '?':
 +if (optopt)
 +ERROR(unsupported option '-%c'. See --help., optopt);
 +else
 +ERROR(unsupported option '%s'. See --help., argv[optind - 
 1]);
 +exit(EXIT_FAILURE);

...but direct exit here...

 +default:
 +ERROR(unknown option);
 +exit(EXIT_FAILURE);
 +}
 +}
 +
 +if (argc  optind)
 +*dom_name = argv[optind];
 +
 +ret = 0;
 + cleanup:
 +return ret;

...especially since there is nothing cleaned up, and the main() function
eventually just exits anyway.  I don't care whether you keep the cleanup
label and consistently use it, or whether you just use direct exit()
everywhere in this function, but at least be consistent :)


 +static void
 +print_cpu_usage(const char *dom_name,
 +size_t cpu,
 +size_t ncpus,
 +unsigned long long then,
 +virTypedParameterPtr then_params,
 +size_t then_nparams,
 +unsigned long long now,
 +virTypedParameterPtr now_params,
 +size_t now_nparams)
 +{
 +size_t i, j, k;
 +size_t nparams = now_nparams;
 +bool delim = false;
 +

 +for (i = 0; i  ncpus; i++) {

 +
 +if (delim)
 +printf(\t);
 +printf(CPU%zu: %.2lf, cpu + i, usage);
 +delim = true;
 +}
 +
 +if (delim)
 +printf(\n);

This 'if' is dead (it can only be false if ncpus is 0 - but all hosts
have at least one), so you can unconditionally print the \n.

ACK with nits fixed.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [REPOST 4/8] scsi_backend: Use existing LINUX_SYSFS_SCSI_HOST_PREFIX definition

2014-07-18 Thread Michal Privoznik

On 08.07.2014 13:54, John Ferlan wrote:

Rather than supplying the path again in the formatting of the sysfs
scsi_host directory.

Signed-off-by: John Ferlan jfer...@redhat.com
---
  src/storage/storage_backend_scsi.c | 6 --
  1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/storage/storage_backend_scsi.c 
b/src/storage/storage_backend_scsi.c
index b5dbe51..e42778f 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -475,7 +475,8 @@ virStorageBackendSCSITriggerRescan(uint32_t host)

  VIR_DEBUG(Triggering rescan of host %d, host);

-if (virAsprintf(path, /sys/class/scsi_host/host%u/scan, host)  0) {
+if (virAsprintf(path, %s/host%u/scan,
+LINUX_SYSFS_SCSI_HOST_PREFIX, host)  0) {
  retval = -1;
  goto out;
  }
@@ -663,7 +664,8 @@ virStorageBackendSCSICheckPool(virConnectPtr conn 
ATTRIBUTE_UNUSED,
  if (getHostNumber(name, host)  0)
  goto cleanup;

-if (virAsprintf(path, /sys/class/scsi_host/host%d, host)  0)
+if (virAsprintf(path, %s/host%d,
+LINUX_SYSFS_SCSI_HOST_PREFIX, host)  0)
  goto cleanup;

  *isActive = virFileExists(path);



Huh, it's been defined, but not used anywhere till now. :)

Michal

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


Re: [libvirt] [REPOST 0/8] storage_scsi: Stable SCSI host addressing

2014-07-18 Thread Michal Privoznik

On 08.07.2014 13:54, John Ferlan wrote:

Reposting of a series from last month changing only the span version
in the docs from 1.2.6 to 1.2.7. Previous posting here:

   http://www.redhat.com/archives/libvir-list/2014-June/msg00448.html

The concept still remains the same - rather than rely on the hostNN
numbers for the scsi_host to remain stable and unique across host reboots
and/or kernel rebuilds, allow use a combination of the scsi_host's PCI
address and the value from the hostNN's 'unique_id' file.


John Ferlan (6):
   getAdapterName: check for SCSI_HOST
   scsi_backend: Use existing LINUX_SYSFS_SCSI_HOST_PREFIX definition
   virutil: Introduce virReadSCSIUniqueId
   Add unique_id to nodedev output
   scsi_host: Introduce virFindSCSIHostByPCI
   getAdapterName: Lookup stable scsi_host

Osier Yang (2):
   virStoragePoolSourceAdapter: Refine the SCSI_HOST adapter name
   storage: Introduce parentaddr into virStoragePoolSourceAdapter

  docs/formatnode.html.in|  11 +
  docs/formatstorage.html.in | 143 --
  docs/schemas/basictypes.rng|  24 +-
  docs/schemas/nodedev.rng   |   6 +
  src/conf/node_device_conf.c|  23 +-
  src/conf/node_device_conf.h|   1 +
  src/conf/storage_conf.c| 111 +++-
  src/conf/storage_conf.h|   8 +-
  src/libvirt_private.syms   |   2 +
  src/node_device/node_device_linux_sysfs.c  |   6 +
  src/phyp/phyp_driver.c |   8 +-
  src/storage/storage_backend_scsi.c |  53 +++-
  src/test/test_driver.c |   5 +-
  src/util/virutil.c | 154 +++
  src/util/virutil.h |   8 +
  tests/Makefile.am  |   7 +
  .../pci_8086_27c5_scsi_host_0_unique_id.xml|   8 +
  tests/nodedevxml2xmltest.c |   1 +
  tests/scsihosttest.c   | 308 +
  .../pool-scsi-type-scsi-host-stable.xml|  19 ++
  .../pool-scsi-type-scsi-host-stable.xml|  22 ++
  tests/storagepoolxml2xmltest.c |   1 +
  22 files changed, 868 insertions(+), 61 deletions(-)
  create mode 100644 
tests/nodedevschemadata/pci_8086_27c5_scsi_host_0_unique_id.xml
  create mode 100644 tests/scsihosttest.c
  create mode 100644 
tests/storagepoolxml2xmlin/pool-scsi-type-scsi-host-stable.xml
  create mode 100644 
tests/storagepoolxml2xmlout/pool-scsi-type-scsi-host-stable.xml



ACK series, but please see my inline comments.

Michal

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


Re: [libvirt] [REPOST 5/8] virutil: Introduce virReadSCSIUniqueId

2014-07-18 Thread Michal Privoznik

On 08.07.2014 13:54, John Ferlan wrote:

Introduce a new function to read the current scsi_host entry and return
the value found in the 'unique_id' file.

Add a 'scsihosttest' test (similar to the fchosttest, but incorporating some
of the concepts of the mocked pci test library) in order to read the
unique_id file like would be found in the /sys/class/scsi_host tree.

Signed-off-by: John Ferlan jfer...@redhat.com
---
  src/libvirt_private.syms |   1 +
  src/util/virutil.c   |  53 ++
  src/util/virutil.h   |   4 +
  tests/Makefile.am|   7 ++
  tests/scsihosttest.c | 254 +++
  5 files changed, 319 insertions(+)
  create mode 100644 tests/scsihosttest.c

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6d7bf41..bf365ac 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2119,6 +2119,7 @@ virParseOwnershipIds;
  virParseVersionString;
  virPipeReadUntilEOF;
  virReadFCHost;
+virReadSCSIUniqueId;
  virScaleInteger;
  virSetBlocking;
  virSetCloseExec;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 95d1ff9..c73ce06 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -1681,6 +1681,50 @@ virGetDeviceUnprivSGIO(const char *path,
  # define SYSFS_FC_HOST_PATH /sys/class/fc_host/
  # define SYSFS_SCSI_HOST_PATH /sys/class/scsi_host/

+/* virReadSCSIUniqueId:
+ * @sysfs_prefix: scsi_host sysfs path, defaults to SYSFS_SCSI_HOST_PATH
+ * @host: Host number, E.g. 5 of scsi_host/host5
+ * @result: Return the entry value as an unsigned int
+ *
+ * Read the value of the scsi_host unique_id file.
+ *
+ * Returns 0 on success, and @result is filled with the unique_id value
+ * Otherwise returns -1
+ */
+int
+virReadSCSIUniqueId(const char *sysfs_prefix,
+int host,
+int *result)
+{
+char *sysfs_path = NULL;
+char *p = NULL;
+int ret = -1;
+char *buf = NULL;
+int unique_id;
+
+if (virAsprintf(sysfs_path, %s/host%d/unique_id,
+sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH,
+host)  0)
+goto cleanup;


This prints a message on error.


+
+if (virFileReadAll(sysfs_path, 1024, buf)  0)
+goto cleanup;


And so does this.


+
+if ((p = strchr(buf, '\n')))
+*p = '\0';
+
+if (virStrToLong_i(buf, NULL, 10, unique_id)  0)
+goto cleanup;


This, however does not. If the unique_id file didn't contain a number, 
the caller gets -1 returned but have no clue why. I think:


virReportError(VIR_ERR_INTERNAL_ERROR,
   _(unable to parse unique_id: %s), buf);

will do. (yes, we are misusing the VIR_ERR_INTERNAL_ERROR code soo much).


+
+*result = unique_id;
+ret = 0;
+
+ cleanup:
+VIR_FREE(sysfs_path);
+VIR_FREE(buf);
+return ret;
+}
+
  /* virReadFCHost:
   * @sysfs_prefix: fc_host sysfs path, defaults to SYSFS_FC_HOST_PATH
   * @host: Host number, E.g. 5 of fc_host/host5
@@ -2034,6 +2078,15 @@ virFindFCHostCapableVport(const char *sysfs_prefix)
  }
  #else
  int
+virReadSCSIUniqueId(const char *sysfs_prefix ATTRIBUTE_UNUSED,
+int host ATTRIBUTE_UNUSED,
+unsigned int *result ATTRIBUTE_UNUSED)
+{
+virReportSystemError(ENOSYS, %s, _(Not supported on this platform));
+return -1;
+}
+
+int
  virReadFCHost(const char *sysfs_prefix ATTRIBUTE_UNUSED,
int host ATTRIBUTE_UNUSED,
const char *entry ATTRIBUTE_UNUSED,
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 2bb74e2..1407dfd 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -164,6 +164,10 @@ int virGetDeviceUnprivSGIO(const char *path,
 int *unpriv_sgio);
  char *virGetUnprivSGIOSysfsPath(const char *path,
  const char *sysfs_dir);
+int virReadSCSIUniqueId(const char *sysfs_prefix,
+int host,
+int *result)
+ATTRIBUTE_NONNULL(3);
  int virReadFCHost(const char *sysfs_prefix,
int host,
const char *entry,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bc1040a..ecb2f34 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -83,6 +83,7 @@ EXTRA_DIST =  \
domainsnapshotxml2xmlin \
domainsnapshotxml2xmlout \
fchostdata \
+   scsihostdata \
interfaceschemadata \
lxcconf2xmldata \
lxcxml2xmldata \
@@ -188,6 +189,7 @@ endif WITH_REMOTE

  if WITH_LINUX
  test_programs += fchosttest
+test_programs += scsihosttest
  endif WITH_LINUX

  if WITH_LIBVIRTD
@@ -1146,8 +1148,13 @@ fchosttest_SOURCES = \
 fchosttest.c testutils.h testutils.c
  fchosttest_LDADD = $(LDADDS)

+scsihosttest_SOURCES = \
+   scsihosttest.c testutils.h testutils.c
+scsihosttest_LDADD = $(LDADDS)
+
  else ! WITH_LINUX
  EXTRA_DIST += fchosttest.c
+EXTRA_DIST += scsihosttest.c
  endif  ! WITH_LINUX


Re: [libvirt] [REPOST 1/8] getAdapterName: check for SCSI_HOST

2014-07-18 Thread Michal Privoznik

On 08.07.2014 13:54, John Ferlan wrote:

Rather than assume that NOT FC_HOST is SCSI_HOST, let's call them out
specifically. Makes it easier to find SCSI_HOST code/structs and ensures
something isn't missed in the future

Signed-off-by: John Ferlan jfer...@redhat.com
---
  src/storage/storage_backend_scsi.c | 21 ++---
  1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/storage/storage_backend_scsi.c 
b/src/storage/storage_backend_scsi.c
index f6f3ca2..21c13e5 100644
--- a/src/storage/storage_backend_scsi.c
+++ b/src/storage/storage_backend_scsi.c
@@ -547,18 +547,17 @@ getAdapterName(virStoragePoolSourceAdapter adapter)
  {
  char *name = NULL;

-if (adapter.type != VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
+if (adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST) {
  ignore_value(VIR_STRDUP(name, adapter.data.name));
-return name;
-}
-
-if (!(name = virGetFCHostNameByWWN(NULL,
-   adapter.data.fchost.wwnn,
-   adapter.data.fchost.wwpn))) {
-virReportError(VIR_ERR_XML_ERROR,
-   _(Failed to find SCSI host with wwnn='%s', 
- wwpn='%s'), adapter.data.fchost.wwnn,
-   adapter.data.fchost.wwpn);
+} else if (adapter.type == VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) {
+if (!(name = virGetFCHostNameByWWN(NULL,
+   adapter.data.fchost.wwnn,
+   adapter.data.fchost.wwpn))) {
+virReportError(VIR_ERR_XML_ERROR,
+   _(Failed to find SCSI host with wwnn='%s', 
+ wwpn='%s'), adapter.data.fchost.wwnn,
+   adapter.data.fchost.wwpn);
+}
  }

  return name;



Or even better use switch((virStoragePoolSourceAdapterType) 
adapter.type) {}. But I can live with this version too.


Michal

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


Re: [libvirt] [PATCH v2] examples: Introduce domtop

2014-07-18 Thread Michal Privoznik

On 18.07.2014 15:48, Eric Blake wrote:

On 07/18/2014 03:08 AM, Michal Privoznik wrote:

There's this question on the list that is asked over and over again.
How do I get {cpu, memory, ...} usage in percentage? Or its modified
version: How do I plot nice graphs like virt-manager does?

It would be nice if we have an example to inspire people. And that's
what domtop should do. Yes, it could be written in different ways, but
I've chosen this one as I think it show explicitly what users need to
implement in order to imitate virt-manager's graphing.

Note: The usage is displayed from host perspective. That is, how much
host CPUs the domain is using. But it should be fairly simple to
switch do just guest CPU usage if needed.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---





ACK with nits fixed.



Fixed and pushed. Thanks!

Michal

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


Re: [libvirt] [PATCH 2/2] qemu: snapshot: Forbid snapshots of iSCSI passthrough devices

2014-07-18 Thread Peter Krempa
On 07/18/14 15:24, Eric Blake wrote:
 On 07/18/2014 03:22 AM, Peter Krempa wrote:
 As with the local SCSI passthrough devicesm qemu can't support snapshots
 on those as the block ops are handled by the device. This is also true
 for iSCSI backing of the disk. Remove the check for the local block
 device and just forbid snapshot when the disk is of type 'lun'.

 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1073368
 ---
  src/qemu/qemu_driver.c | 5 +
  1 file changed, 1 insertion(+), 4 deletions(-)
 
 ACK
 

Thanks; Series pushed.

Peter




signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 3/7] qemu: snapshot: Convert if-else switch to switch statement

2014-07-18 Thread Peter Krempa
Convert the target snapshot state selector to a switch statement
enumerating all possible values. This points out a few mistakes in the
original selector.

The logic of the code is preserved until later patches.
---
 src/qemu/qemu_driver.c | 22 --
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3096688..7ab0f81 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13922,6 +13922,8 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 virDomainDefPtr config = NULL;
 virQEMUDriverConfigPtr cfg = NULL;
 virCapsPtr caps = NULL;
+bool was_running = false;
+bool was_stopped = false;

 virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
   VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED |
@@ -14022,12 +14024,10 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY)  0)
 goto cleanup;

-if (snap-def-state == VIR_DOMAIN_RUNNING
-|| snap-def-state == VIR_DOMAIN_PAUSED) {
+switch ((virDomainState) snap-def-state) {
+case VIR_DOMAIN_RUNNING:
+case VIR_DOMAIN_PAUSED:
 /* Transitions 2, 3, 5, 6, 8, 9 */
-bool was_running = false;
-bool was_stopped = false;
-
 /* When using the loadvm monitor command, qemu does not know
  * whether to pause or run the reverted domain, and just stays
  * in the same state as before the monitor command, whether
@@ -14153,7 +14153,16 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
  detail);
 }
 }
-} else {
+break;
+
+case VIR_DOMAIN_SHUTDOWN:
+case VIR_DOMAIN_SHUTOFF:
+case VIR_DOMAIN_CRASHED:
+case VIR_DOMAIN_NOSTATE:
+case VIR_DOMAIN_BLOCKED:
+/* XXX: The following one is clearly wrong! */
+case VIR_DOMAIN_PMSUSPENDED:
+case VIR_DOMAIN_LAST:
 /* Transitions 1, 4, 7 */
 /* Newer qemu -loadvm refuses to revert to the state of a snapshot
  * created by qemu-img snapshot -c.  If the domain is running, we
@@ -14217,6 +14226,7 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
   detail);
 }
 }
+break;
 }

 ret = 0;
-- 
2.0.0

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


[libvirt] [PATCH 0/7] Fix domain state handling when reverting snapshots in PMSUSPENDED state

2014-07-18 Thread Peter Krempa
Unfortunately qemu behaves strangely so it probably can't be fully verified :/

Peter Krempa (7):
  event: Add transition reason for PMSUSPENDED state from snapshot ops
  lib: Add reason for a domain reaching the PMSUSPENDED state
  qemu: snapshot: Convert if-else switch to switch statement
  qemu: snapshot: Reject revertion from clearly bad states
  qemu: snapshot: Add helper to generate lifecycle events
  qemu: snapshot: Refactor event creation when reverting snapshots
  qemu: snapshot: Correctly revert snapshots in PMSUSPENDED state

 examples/object-events/event-test.c |   3 +
 include/libvirt/libvirt.h.in|   6 +
 src/conf/domain_conf.c  |   3 +-
 src/qemu/qemu_driver.c  | 301 +---
 tools/virsh-domain-monitor.c|   3 +-
 tools/virsh-domain.c|   3 +-
 6 files changed, 228 insertions(+), 91 deletions(-)

-- 
2.0.0

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


[libvirt] [PATCH 4/7] qemu: snapshot: Reject revertion from clearly bad states

2014-07-18 Thread Peter Krempa
Report errors on some states snapshots done by qemu should never reach
---
 src/qemu/qemu_driver.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7ab0f81..2d58b53 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14158,11 +14158,8 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 case VIR_DOMAIN_SHUTDOWN:
 case VIR_DOMAIN_SHUTOFF:
 case VIR_DOMAIN_CRASHED:
-case VIR_DOMAIN_NOSTATE:
-case VIR_DOMAIN_BLOCKED:
 /* XXX: The following one is clearly wrong! */
 case VIR_DOMAIN_PMSUSPENDED:
-case VIR_DOMAIN_LAST:
 /* Transitions 1, 4, 7 */
 /* Newer qemu -loadvm refuses to revert to the state of a snapshot
  * created by qemu-img snapshot -c.  If the domain is running, we
@@ -14227,6 +14224,15 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 }
 }
 break;
+
+case VIR_DOMAIN_NOSTATE:
+case VIR_DOMAIN_BLOCKED:
+case VIR_DOMAIN_LAST:
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Invalid target domain state '%s'. Refusing 
+ snapshot revertion ),
+   virDomainStateTypeToString(snap-def-state));
+goto cleanup;
 }

 ret = 0;
-- 
2.0.0

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


[libvirt] [PATCH 2/7] lib: Add reason for a domain reaching the PMSUSPENDED state

2014-07-18 Thread Peter Krempa
When libvirt reverts a snapshot in the PMSUSPENDED state we need to
record how it entered this state. Add the from snapshot reason.
---
 include/libvirt/libvirt.h.in | 3 +++
 src/conf/domain_conf.c   | 3 ++-
 tools/virsh-domain-monitor.c | 3 ++-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index af339f2..5c13c28 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -223,6 +223,9 @@ typedef enum {

 typedef enum {
 VIR_DOMAIN_PMSUSPENDED_UNKNOWN = 0,
+VIR_DOMAIN_PMSUSPENDED_FROM_SNAPSHOT = 1, /* restored from a snapshot which
+ was taken while the domain was
+ pmsuspended */

 #ifdef VIR_ENUM_SENTINELS
 VIR_DOMAIN_PMSUSPENDED_LAST
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1e27165..78a365f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -682,7 +682,8 @@ VIR_ENUM_IMPL(virDomainCrashedReason, 
VIR_DOMAIN_CRASHED_LAST,
   panicked)

 VIR_ENUM_IMPL(virDomainPMSuspendedReason, VIR_DOMAIN_PMSUSPENDED_LAST,
-  unknown)
+  unknown,
+  from snapshot)

 VIR_ENUM_IMPL(virDomainSeclabel, VIR_DOMAIN_SECLABEL_LAST,
   default,
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 8bd58ad..3a598e9 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -213,7 +213,8 @@ VIR_ENUM_IMPL(vshDomainCrashedReason,
 VIR_ENUM_DECL(vshDomainPMSuspendedReason)
 VIR_ENUM_IMPL(vshDomainPMSuspendedReason,
   VIR_DOMAIN_PMSUSPENDED_LAST,
-  N_(unknown))
+  N_(unknown),
+  N_(from snapshot))

 static const char *
 vshDomainStateReasonToString(int state, int reason)
-- 
2.0.0

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


[libvirt] [PATCH 6/7] qemu: snapshot: Refactor event creation when reverting snapshots

2014-07-18 Thread Peter Krempa
The internal snapshot revert code used a very unintuitive approach to
create lifecycle events while doing the revert. Refactor the code to use
the new automagic function to do the revertion.
---
 src/qemu/qemu_driver.c | 76 +-
 1 file changed, 13 insertions(+), 63 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e794e02..1f98f4a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14047,16 +14047,12 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 virDomainObjPtr vm = NULL;
 int ret = -1;
 virDomainSnapshotObjPtr snap = NULL;
-virObjectEventPtr event = NULL;
-virObjectEventPtr event2 = NULL;
-int detail;
 qemuDomainObjPrivatePtr priv;
 int rc;
 virDomainDefPtr config = NULL;
 virQEMUDriverConfigPtr cfg = NULL;
 virCapsPtr caps = NULL;
-bool was_running = false;
-bool was_stopped = false;
+int oldState = vm-state.state;

 virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
   VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED |
@@ -14187,24 +14183,18 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 qemuDomainSnapshotEmitLifecycleEvent(driver, vm,
  vm-state.state,
  VIR_DOMAIN_SHUTOFF);
+oldState = VIR_DOMAIN_SHUTOFF;
 goto load;
 }

 priv = vm-privateData;
 if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
 /* Transitions 5, 6 */
-was_running = true;
 if (qemuProcessStopCPUs(driver, vm,
 VIR_DOMAIN_PAUSED_FROM_SNAPSHOT,
 QEMU_ASYNC_JOB_NONE)  0)
 goto endjob;
-/* Create an event now in case the restore fails, so
- * that user will be alerted that they are now paused.
- * If restore later succeeds, we might replace this. */
-detail = VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT;
-event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_SUSPENDED,
- detail);
+
 if (!virDomainObjIsActive(vm)) {
 virReportError(VIR_ERR_INTERNAL_ERROR, %s,
_(guest unexpectedly quit));
@@ -14224,7 +14214,6 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 } else {
 /* Transitions 2, 3 */
 load:
-was_stopped = true;
 if (config)
 virDomainObjAssignDef(vm, config, false, NULL);

@@ -14233,10 +14222,7 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
   VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
   VIR_QEMU_PROCESS_START_PAUSED);
 virDomainAuditStart(vm, from-snapshot, rc = 0);
-detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
-event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_STARTED,
- detail);
+
 if (rc  0)
 goto endjob;
 }
@@ -14248,13 +14234,6 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 /* Transitions 3, 6, 9 */
 virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
  VIR_DOMAIN_PAUSED_FROM_SNAPSHOT);
-if (was_stopped) {
-/* Transition 3, use event as-is and add event2 */
-detail = VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT;
-event2 = virDomainEventLifecycleNewFromObj(vm,
-  VIR_DOMAIN_EVENT_SUSPENDED,
-  detail);
-} /* else transition 6 and 9 use event as-is */
 } else {
 /* Transitions 2, 5, 8 */
 if (!virDomainObjIsActive(vm)) {
@@ -14267,21 +14246,6 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
   QEMU_ASYNC_JOB_NONE);
 if (rc  0)
 goto endjob;
-virObjectUnref(event);
-event = NULL;
-if (was_stopped) {
-/* Transition 2 */
-detail = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
-event = virDomainEventLifecycleNewFromObj(vm,
- VIR_DOMAIN_EVENT_STARTED,
- detail);
-} else if (was_running) {
-/* Transition 8 */
-detail = 

[libvirt] [PATCH 5/7] qemu: snapshot: Add helper to generate lifecycle events

2014-07-18 Thread Peter Krempa
Add helper that will generate domain lifecycle events regarding to
snapshot revert operations and use it in a demonstration case in the
code.

The helper will be later used in internal snaphsot revert refactor more
widely.
---
 src/qemu/qemu_driver.c | 142 ++---
 1 file changed, 136 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2d58b53..e794e02 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13907,6 +13907,139 @@ qemuDomainSnapshotRevertInactive(virQEMUDriverPtr 
driver,
 return ret  0 ? -1 : ret;
 }

+
+static int
+qemuDomainSnapshotEmitLifecycleEvent(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainState oldState,
+ virDomainState newState)
+{
+int reason = 0;
+int type = -1;
+virObjectEventPtr event = NULL;
+
+switch (newState) {
+case VIR_DOMAIN_RUNNING:
+switch (oldState) {
+case VIR_DOMAIN_NOSTATE:
+case VIR_DOMAIN_SHUTOFF:
+case VIR_DOMAIN_CRASHED:
+case VIR_DOMAIN_SHUTDOWN:
+type = VIR_DOMAIN_EVENT_STARTED;
+reason = VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT;
+break;
+
+case VIR_DOMAIN_PMSUSPENDED:
+case VIR_DOMAIN_PAUSED:
+type = VIR_DOMAIN_EVENT_RESUMED;
+reason = VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT;
+break;
+
+case VIR_DOMAIN_LAST:
+case VIR_DOMAIN_RUNNING:
+case VIR_DOMAIN_BLOCKED:
+/* no event */
+break;
+}
+break;
+
+case VIR_DOMAIN_PAUSED:
+switch (oldState) {
+case VIR_DOMAIN_NOSTATE:
+case VIR_DOMAIN_SHUTOFF:
+case VIR_DOMAIN_CRASHED:
+/* the machine was started here, so we need an additional event */
+event = virDomainEventLifecycleNewFromObj(vm,
+  VIR_DOMAIN_EVENT_STARTED,
+  
VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT);
+if (!event)
+goto cleanup;
+qemuDomainEventQueue(driver, event);
+/* fallthrough! */
+case VIR_DOMAIN_PMSUSPENDED:
+case VIR_DOMAIN_RUNNING:
+case VIR_DOMAIN_SHUTDOWN:
+type = VIR_DOMAIN_EVENT_SUSPENDED;
+reason = VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT;
+break;
+
+case VIR_DOMAIN_PAUSED:
+case VIR_DOMAIN_LAST:
+case VIR_DOMAIN_BLOCKED:
+/* no event */
+break;
+}
+break;
+
+case VIR_DOMAIN_SHUTOFF:
+switch (oldState) {
+case VIR_DOMAIN_NOSTATE:
+case VIR_DOMAIN_BLOCKED:
+case VIR_DOMAIN_SHUTDOWN:
+case VIR_DOMAIN_PAUSED:
+case VIR_DOMAIN_RUNNING:
+case VIR_DOMAIN_PMSUSPENDED:
+type = VIR_DOMAIN_EVENT_STOPPED;
+reason = VIR_DOMAIN_EVENT_STOPPED_FROM_SNAPSHOT;
+break;
+
+case VIR_DOMAIN_SHUTOFF:
+case VIR_DOMAIN_CRASHED:
+case VIR_DOMAIN_LAST:
+/* no event */
+break;
+}
+break;
+
+case VIR_DOMAIN_PMSUSPENDED:
+switch (oldState) {
+case VIR_DOMAIN_NOSTATE:
+case VIR_DOMAIN_SHUTOFF:
+case VIR_DOMAIN_CRASHED:
+/* the machine was started here, so we need an additional event */
+event = virDomainEventLifecycleNewFromObj(vm,
+  VIR_DOMAIN_EVENT_STARTED,
+  
VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT);
+if (!event)
+goto cleanup;
+qemuDomainEventQueue(driver, event);
+/* fallthrough! */
+case VIR_DOMAIN_RUNNING:
+case VIR_DOMAIN_SHUTDOWN:
+case VIR_DOMAIN_PAUSED:
+type = VIR_DOMAIN_EVENT_PMSUSPENDED;
+reason = VIR_DOMAIN_EVENT_PMSUSPENDED_FROM_SNAPSHOT;
+break;
+
+case VIR_DOMAIN_LAST:
+case VIR_DOMAIN_BLOCKED:
+case VIR_DOMAIN_PMSUSPENDED:
+/* no event */
+break;
+}
+break;
+
+case VIR_DOMAIN_NOSTATE:
+case VIR_DOMAIN_BLOCKED:
+case VIR_DOMAIN_SHUTDOWN:
+case VIR_DOMAIN_CRASHED:
+case VIR_DOMAIN_LAST:
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _(Suspicious domain state '%d' after snapshot),
+   newState);
+return -1;
+}
+
+   if (!(event = virDomainEventLifecycleNewFromObj(vm, type, reason)))
+   goto cleanup;
+
+qemuDomainEventQueue(driver, event);
+return 0;
+
+ cleanup:
+return -1;
+}
+
 static int qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
   unsigned int flags)
 {
@@ 

[libvirt] [PATCH 1/7] event: Add transition reason for PMSUSPENDED state from snapshot ops

2014-07-18 Thread Peter Krempa
Add event reason to support transitions to PM suspended state from
snapshot revert operations.
---
 examples/object-events/event-test.c | 3 +++
 include/libvirt/libvirt.h.in| 3 +++
 tools/virsh-domain.c| 3 ++-
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/examples/object-events/event-test.c 
b/examples/object-events/event-test.c
index 2a5a83b..84c878e 100644
--- a/examples/object-events/event-test.c
+++ b/examples/object-events/event-test.c
@@ -210,6 +210,9 @@ static const char *eventDetailToString(int event, int 
detail) {
 case VIR_DOMAIN_EVENT_PMSUSPENDED_DISK:
 ret = Disk;
 break;
+case VIR_DOMAIN_EVENT_PMSUSPENDED_FROM_SNAPSHOT:
+ret = Snapshot;
+break;
 }
 break;
 case VIR_DOMAIN_EVENT_CRASHED:
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index ad6785f..af339f2 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3693,6 +3693,9 @@ typedef enum {
 typedef enum {
 VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY = 0, /* Guest was PM suspended to 
memory */
 VIR_DOMAIN_EVENT_PMSUSPENDED_DISK = 1, /* Guest was PM suspended to disk */
+VIR_DOMAIN_EVENT_PMSUSPENDED_FROM_SNAPSHOT = 2, /* Guest changed state to
+   PM suspended due to
+   snapshot operation */

 #ifdef VIR_ENUM_SENTINELS
 VIR_DOMAIN_EVENT_PMSUSPENDED_LAST
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ba47258..cade830 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10686,7 +10686,8 @@ VIR_ENUM_DECL(vshDomainEventPMSuspended)
 VIR_ENUM_IMPL(vshDomainEventPMSuspended,
   VIR_DOMAIN_EVENT_PMSUSPENDED_LAST,
   N_(Memory),
-  N_(Disk))
+  N_(Disk),
+  N_(Snapshot))

 VIR_ENUM_DECL(vshDomainEventCrashed)
 VIR_ENUM_IMPL(vshDomainEventCrashed,
-- 
2.0.0

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


[libvirt] [PATCH 7/7] qemu: snapshot: Correctly revert snapshots in PMSUSPENDED state

2014-07-18 Thread Peter Krempa
PMSUSPENDED state implies the qemu process running, so we should treat
it that way. This increases the possible state space of transitions that
may happen during the snapshot revert so this patch documents them as
well.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1079162
---
 src/qemu/qemu_driver.c | 67 --
 1 file changed, 48 insertions(+), 19 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1f98f4a..f93e0fd 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14052,22 +14052,29 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 virDomainDefPtr config = NULL;
 virQEMUDriverConfigPtr cfg = NULL;
 virCapsPtr caps = NULL;
-int oldState = vm-state.state;
+int oldState;

 virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
   VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED |
   VIR_DOMAIN_SNAPSHOT_REVERT_FORCE, -1);

 /* We have the following transitions, which create the following events:
- * 1. inactive - inactive: none
- * 2. inactive - running:  EVENT_STARTED
- * 3. inactive - paused:   EVENT_STARTED, EVENT_PAUSED
- * 4. running  - inactive: EVENT_STOPPED
- * 5. running  - running:  none
- * 6. running  - paused:   EVENT_PAUSED
- * 7. paused   - inactive: EVENT_STOPPED
- * 8. paused   - running:  EVENT_RESUMED
- * 9. paused   - paused:   none
+ * 1.  inactive- inactive:none
+ * 2.  inactive- running: EVENT_STARTED
+ * 3.  inactive- paused:  EVENT_STARTED, EVENT_PAUSED
+ * 4.  running - inactive:EVENT_STOPPED
+ * 5.  running - running: none
+ * 6.  running - paused:  EVENT_PAUSED
+ * 7.  paused  - inactive:EVENT_STOPPED
+ * 8.  paused  - running: EVENT_RESUMED
+ * 9.  paused  - paused:  none
+ * 10. pmsuspended - pmsuspended: none
+ * 11. pmsuspended - inactive:EVENT_STOPPED
+ * 12. pmsuspended - running: EVENT_RESUMED
+ * 13. pmsuspended - paused:  EVENT_PAUSED
+ * 14. inactive- pmsuspended: EVENT_STARTED, EVENT_PMSUSPENDED
+ * 15. paused  - pmsuspended: EVENT_PMSUSPENDED
+ * 16. running - pmsuspended: EVENT_PMSUSPENDED
  * Also, several transitions occur even if we fail partway through,
  * and use of FORCE can cause multiple transitions.
  */
@@ -14075,6 +14082,8 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 if (!(vm = qemuDomObjFromSnapshot(snapshot)))
 return -1;

+oldState = vm-state.state;
+
 cfg = virQEMUDriverGetConfig(driver);

 if (virDomainRevertToSnapshotEnsureACL(snapshot-domain-conn, vm-def)  
0)
@@ -14127,6 +14136,14 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 }
 }

+if (snap-def-state == VIR_DOMAIN_PMSUSPENDED 
+(flags  VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING ||
+ flags  VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
+virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s,
+   _(snapshot of a VM in PMSUSPENDED state cannot be 
+ reverted to a running or paused state));
+goto cleanup;
+}

 if (vm-current_snapshot) {
 vm-current_snapshot-def-current = false;
@@ -14156,14 +14173,17 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
 switch ((virDomainState) snap-def-state) {
 case VIR_DOMAIN_RUNNING:
 case VIR_DOMAIN_PAUSED:
-/* Transitions 2, 3, 5, 6, 8, 9 */
+case VIR_DOMAIN_PMSUSPENDED:
+/* New state of the domain requires a running qemu process */
+/* Transitions 2, 3, 5, 6, 8, 9, 10, 12, 13, 14, 15, 16 */
+
 /* When using the loadvm monitor command, qemu does not know
  * whether to pause or run the reverted domain, and just stays
  * in the same state as before the monitor command, whether
  * that is paused or running.  We always pause before loadvm,
  * to have finer control.  */
 if (virDomainObjIsActive(vm)) {
-/* Transitions 5, 6, 8, 9 */
+/* Transitions 5, 6, 8, 9, 10, 12, 13, 15, 16 */
 /* Check for ABI compatibility. We need to do this check against
  * the migratable XML or it will always fail otherwise */
 if (config  !qemuDomainDefCheckABIStability(driver, vm-def, 
config)) {
@@ -14189,7 +14209,7 @@ static int 
qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,

 priv = vm-privateData;
 if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
-/* Transitions 5, 6 */
+/* Transitions 5, 6, 16*/
 if (qemuProcessStopCPUs(driver, vm,
 VIR_DOMAIN_PAUSED_FROM_SNAPSHOT,
 QEMU_ASYNC_JOB_NONE)  0)
@@ -14212,7 +14232,7 

Re: [libvirt] [PATCH libvirt-tck] bhyve: reconnect to domains after libvirtd restart

2014-07-18 Thread Roman Bogorodskiy
  Ján Tomko wrote:

 On 06/29/2014 06:06 PM, Roman Bogorodskiy wrote:
  Try to reconnect to the running domains after libvirtd restart. To
  achieve that, do:

...

  @@ -1207,9 +1218,16 @@ bhyveStateInitialize(bool priveleged 
  ATTRIBUTE_UNUSED,
  NULL, NULL)  0)
   goto cleanup;
   
  +conn = virConnectOpen(bhyve:///system);
 
 The connection does not seem to be used anywhere.
 
 QEMU driver uses it for:
 qemuTranslateDiskSourcePool
 qemuProcessFiltersInstantiate
 qemuProcessRecoverJob
 
 Neither of which is done in the bhyve driver.
 
 ACK with the conn removed.

Removed 'conn' and pushed; thanks!

Roman Bogorodskiy


pgp4UOyNPkM2u.pgp
Description: PGP signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH 1/2] spec: Use power64 macro

2014-07-18 Thread Cole Robinson
From: Peter Robinson pbrobin...@fedoraproject.org

Covers the whole ppc64 family. Example bug for binutils:

https://bugzilla.redhat.com/show_bug.cgi?id=834651
---
 libvirt.spec.in | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index 76e57aa..cac7d99 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -60,15 +60,16 @@
 %if 0%{?fedora}
 %if 0%{?fedora}  16
 # Fedora doesn't have any QEMU on ppc64 until FC16 - only ppc
+# I think F17 is the first release with the power64 macro
 %ifarch ppc64
 %define with_qemu_tcg 0
 %endif
 %endif
 %if 0%{?fedora} = 18
-%define qemu_kvm_arches %{ix86} x86_64 ppc64 s390x
+%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x
 %endif
 %if 0%{?fedora} = 20
-%define qemu_kvm_arches %{ix86} x86_64 ppc64 s390x %{arm}
+%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm}
 %endif
 %endif
 
-- 
1.9.3

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


[libvirt] [PATCH 2/2] spec: aarch64 has kvm support with F21+

2014-07-18 Thread Cole Robinson
From: Peter Robinson pbrobin...@fedoraproject.org

---
 libvirt.spec.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libvirt.spec.in b/libvirt.spec.in
index cac7d99..424b6e2 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -69,7 +69,7 @@
 %define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x
 %endif
 %if 0%{?fedora} = 20
-%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm}
+%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} aarch64
 %endif
 %endif
 
-- 
1.9.3

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


Re: [libvirt] Enable kvm on aarch64, Cleanup F-16/18 conditionals

2014-07-18 Thread Cole Robinson
FWIW I sent patches to libvir-list for the power64 macro change and the
aarch64 change.

On 07/15/2014 07:29 PM, Eric Blake wrote:
 On 07/15/2014 04:29 PM, Peter Robinson wrote:
 Doing an out-of-the-box build on RHEL 5 is the oldest configuration
 still actively (if marginally) supported, ideally for as long as RHEL 5
 remains a live platform (several more years to go).  We have build-bots
 that ensure that we can build on RHEL 5, although I'm not sure if those
 buildbots are exercising 'make rpm' to test the older parts of the spec
 file.  Historically, RHEL 5.10 is based off of libvirt-0.8.2, and that
 was the release in use during Fedora 13.  So it's _definitely_ worth
 culling any conditionals older than F13; but stuff between F13 and F18
 might be shared with RHEL 5, and therefore more effort to cull the
 Fedora side while still leaving the RHEL side intact.

 Yes, and you'll note in my change that I didn't change anything that
 affected EL based releases. In terms of F-13 style tags you should be
 capturing that in appropriate and equivalent EL tags to ensure you get
 right and consistent conditionals for the appropriate release as
 opposed to relying on a translation as you have EL conditionals there
 already why mix the two.
 
 Not sure I follow you here; a patch may be worth more than words (and
 I'm planning on posting a tentative patch soon).
 
 Anyone else on the libvirt list have an opinion on how far back we can
 clean without annoying people that are slow on the upgrade to modern Fedora?

 You have known users that are actively upgrading to the latest libvirt
 and no other components on old versions of Fedora?
 
 I don't honestly know - which is why I'm asking the list if anyone
 reading here would care if we pruned F18 code.
 

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


[libvirt] [PATCH] maint: simplify some syntax check exemptions

2014-07-18 Thread Eric Blake
Commit 5028160 accidentally weakened the strtol prohibitions to
skip ALL files under src/util instead of the former situation of
just protecting util/virsexpr.c; even though NONE of the files
in that directory need any protection.

Shorten some long lines while at it.

* cfg.mk (exclude_file_name_regexp--sc_prohibit_strtol): No need
to exclude all of util.
(exclude_file_name_regexp--sc_prohibit_sprintf): Reduce long line.
(exclude_file_name_regexp--sc_prohibit_raw_allocation): Likewise.

Signed-off-by: Eric Blake ebl...@redhat.com
---
 cfg.mk | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index 0559edd..10dd79b 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1065,7 +1065,7 @@ exclude_file_name_regexp--sc_prohibit_nonreentrant = \
   
^((po|tests)/|docs/.*(py|html\.in)|run.in$$|tools/wireshark/util/genxdrstub\.pl$$)

 exclude_file_name_regexp--sc_prohibit_raw_allocation = \
-  
^(docs/hacking\.html\.in)|(src/util/viralloc\.[ch]|examples/.*|tests/securityselinuxhelper\.c|tests/vircgroupmock\.c|tools/wireshark/src/packet-libvirt.c)$$
+  
^(docs/hacking\.html\.in|src/util/viralloc\.[ch]|examples/.*|tests/(securityselinuxhelper|vircgroupmock)\.c|tools/wireshark/src/packet-libvirt\.c)$$

 exclude_file_name_regexp--sc_prohibit_readlink = \
   ^src/(util/virutil|lxc/lxc_container)\.c$$
@@ -1073,12 +1073,11 @@ exclude_file_name_regexp--sc_prohibit_readlink = \
 exclude_file_name_regexp--sc_prohibit_setuid = ^src/util/virutil\.c$$

 exclude_file_name_regexp--sc_prohibit_sprintf = \
-  
^(docs/hacking\.html\.in)|(examples/systemtap/.*stp)|(src/dtrace2systemtap\.pl)|(src/rpc/gensystemtap\.pl)|(tools/wireshark/util/genxdrstub\.pl)$$
+  ^(docs/hacking\.html\.in|.*stp|.pl)$$

 exclude_file_name_regexp--sc_prohibit_strncpy = ^src/util/virstring\.c$$

-exclude_file_name_regexp--sc_prohibit_strtol = \
-  ^(src/util/.*|examples/dom.*/.*)\.c$$
+exclude_file_name_regexp--sc_prohibit_strtol = ^examples/dom.*/.*\.c$$

 exclude_file_name_regexp--sc_prohibit_xmlGetProp = ^src/util/virxml\.c$$

-- 
1.9.3

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


Re: [libvirt] [PATCH 1/2] spec: Use power64 macro

2014-07-18 Thread Eric Blake
On 07/18/2014 11:28 AM, Cole Robinson wrote:
 From: Peter Robinson pbrobin...@fedoraproject.org
 
 Covers the whole ppc64 family. Example bug for binutils:
 
 https://bugzilla.redhat.com/show_bug.cgi?id=834651
 ---
  libvirt.spec.in | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)

 
 diff --git a/libvirt.spec.in b/libvirt.spec.in
 index 76e57aa..cac7d99 100644
 --- a/libvirt.spec.in
 +++ b/libvirt.spec.in
 @@ -60,15 +60,16 @@
  %if 0%{?fedora}
  %if 0%{?fedora}  16
  # Fedora doesn't have any QEMU on ppc64 until FC16 - only ppc
 +# I think F17 is the first release with the power64 macro
  %ifarch ppc64
  %define with_qemu_tcg 0
  %endif

Of course, we may delete this hunk in a later patch, but it works for
now. I did not try to fire up my F16 VM to run 'make dist' - we may have
bit-rotted for that build in the meantime, but it doesn't stop my from
saying:

ACK.


-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/2] spec: aarch64 has kvm support with F21+

2014-07-18 Thread Eric Blake
On 07/18/2014 11:28 AM, Cole Robinson wrote:
 From: Peter Robinson pbrobin...@fedoraproject.org
 
 ---
  libvirt.spec.in | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

ACK.

 
 diff --git a/libvirt.spec.in b/libvirt.spec.in
 index cac7d99..424b6e2 100644
 --- a/libvirt.spec.in
 +++ b/libvirt.spec.in
 @@ -69,7 +69,7 @@
  %define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x
  %endif
  %if 0%{?fedora} = 20
 -%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm}
 +%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} 
 aarch64
  %endif
  %endif
  
 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/2] spec: aarch64 has kvm support with F21+

2014-07-18 Thread Eric Blake
On 07/18/2014 04:05 PM, Eric Blake wrote:
 On 07/18/2014 11:28 AM, Cole Robinson wrote:
 From: Peter Robinson pbrobin...@fedoraproject.org

 ---
  libvirt.spec.in | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 ACK.

Spoke too soon:

 

 diff --git a/libvirt.spec.in b/libvirt.spec.in
 index cac7d99..424b6e2 100644
 --- a/libvirt.spec.in
 +++ b/libvirt.spec.in
 @@ -69,7 +69,7 @@
  %define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x
  %endif
  %if 0%{?fedora} = 20

This says F20, but your subject line says F21.  One of the two is wrong.
 Please fix before committing.

 -%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm}
 +%define qemu_kvm_arches %{ix86} x86_64 %{power64} s390x %{arm} 
 aarch64
  %endif
  %endif
  

 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 1/7] event: Add transition reason for PMSUSPENDED state from snapshot ops

2014-07-18 Thread Eric Blake
On 07/18/2014 10:11 AM, Peter Krempa wrote:
 Add event reason to support transitions to PM suspended state from
 snapshot revert operations.
 ---
  examples/object-events/event-test.c | 3 +++
  include/libvirt/libvirt.h.in| 3 +++
  tools/virsh-domain.c| 3 ++-
  3 files changed, 8 insertions(+), 1 deletion(-)
 

 +++ b/include/libvirt/libvirt.h.in
 @@ -3693,6 +3693,9 @@ typedef enum {
  typedef enum {
  VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY = 0, /* Guest was PM suspended to 
 memory */
  VIR_DOMAIN_EVENT_PMSUSPENDED_DISK = 1, /* Guest was PM suspended to disk 
 */
 +VIR_DOMAIN_EVENT_PMSUSPENDED_FROM_SNAPSHOT = 2, /* Guest changed state to
 +   PM suspended due to
 +   snapshot operation */

Umm, is this even possible with qemu? My understanding is that qemu is
unable to migrate S3 status, and therefore, the moment you migrate to
another machine or to a file, the receiving end of the migration will
act as if the guest had a PM wakeup event and is no longer in S3.  If
you are proposing immediately re-suspending the guest into S3 after
resuming it, that's wrong - we should only support states that can be
entered immediately, and not states that require an unknown amount of
guest CPU cycles.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 2/7] lib: Add reason for a domain reaching the PMSUSPENDED state

2014-07-18 Thread Eric Blake
On 07/18/2014 10:11 AM, Peter Krempa wrote:
 When libvirt reverts a snapshot in the PMSUSPENDED state we need to
 record how it entered this state. Add the from snapshot reason.
 ---
  include/libvirt/libvirt.h.in | 3 +++
  src/conf/domain_conf.c   | 3 ++-
  tools/virsh-domain-monitor.c | 3 ++-
  3 files changed, 7 insertions(+), 2 deletions(-)

Again, I'm not sure this is possible with current qemu.  Rather, what
really needs to happen is whatever we do when migrating an S3 guest or
doing a 'virsh restore file' on a file created by 'virsh save' on an S3
guest.  Basically, waking the file is forced to have the guest back in
pm wakeup state (or at best paused).

Yes, if future qemu is ever patched to support S3 migration, then we can
revisit this.  But that won't be qemu 2.1, so I don't think we need this
patch.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 3/7] qemu: snapshot: Convert if-else switch to switch statement

2014-07-18 Thread Eric Blake
On 07/18/2014 10:11 AM, Peter Krempa wrote:
 Convert the target snapshot state selector to a switch statement
 enumerating all possible values. This points out a few mistakes in the
 original selector.
 
 The logic of the code is preserved until later patches.
 ---
  src/qemu/qemu_driver.c | 22 --
  1 file changed, 16 insertions(+), 6 deletions(-)
 

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 4/7] qemu: snapshot: Reject revertion from clearly bad states

2014-07-18 Thread Eric Blake
On 07/18/2014 10:11 AM, Peter Krempa wrote:
 Report errors on some states snapshots done by qemu should never reach
 ---
  src/qemu/qemu_driver.c | 12 +---
  1 file changed, 9 insertions(+), 3 deletions(-)
 

 +
 +case VIR_DOMAIN_NOSTATE:
 +case VIR_DOMAIN_BLOCKED:
 +case VIR_DOMAIN_LAST:
 +virReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(Invalid target domain state '%s'. Refusing 
 + snapshot revertion ),

s/revertion /reversion/

(typo and trailing space)

 +   virDomainStateTypeToString(snap-def-state));
 +goto cleanup;
  }

ACK with that fixed.  It might also be nice to patch
qemuDomainSnapshotCreateXML with the _REDEFINE flag to likewise reject
modifying an existing snapshot into one of these states.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH 7/7] qemu: snapshot: Correctly revert snapshots in PMSUSPENDED state

2014-07-18 Thread Eric Blake
On 07/18/2014 10:11 AM, Peter Krempa wrote:
 PMSUSPENDED state implies the qemu process running, so we should treat
 it that way. This increases the possible state space of transitions that
 may happen during the snapshot revert so this patch documents them as
 well.
 
 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1079162
 ---
  src/qemu/qemu_driver.c | 67 
 --
  1 file changed, 48 insertions(+), 19 deletions(-)

I think this needs some rework - current qemu treats it as reverting to
a pm wakeup event, and the guest will start running again (unless the
user requested to revert as paused).

 
 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
 index 1f98f4a..f93e0fd 100644
 --- a/src/qemu/qemu_driver.c
 +++ b/src/qemu/qemu_driver.c
 @@ -14052,22 +14052,29 @@ static int 
 qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
  virDomainDefPtr config = NULL;
  virQEMUDriverConfigPtr cfg = NULL;
  virCapsPtr caps = NULL;
 -int oldState = vm-state.state;
 +int oldState;
 
  virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING |
VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED |
VIR_DOMAIN_SNAPSHOT_REVERT_FORCE, -1);
 
  /* We have the following transitions, which create the following events:
 - * 1. inactive - inactive: none
 - * 2. inactive - running:  EVENT_STARTED
 - * 3. inactive - paused:   EVENT_STARTED, EVENT_PAUSED
 - * 4. running  - inactive: EVENT_STOPPED
 - * 5. running  - running:  none
 - * 6. running  - paused:   EVENT_PAUSED
 - * 7. paused   - inactive: EVENT_STOPPED
 - * 8. paused   - running:  EVENT_RESUMED
 - * 9. paused   - paused:   none
 + * 1.  inactive- inactive:none
 + * 2.  inactive- running: EVENT_STARTED
 + * 3.  inactive- paused:  EVENT_STARTED, EVENT_PAUSED
 + * 4.  running - inactive:EVENT_STOPPED
 + * 5.  running - running: none
 + * 6.  running - paused:  EVENT_PAUSED
 + * 7.  paused  - inactive:EVENT_STOPPED
 + * 8.  paused  - running: EVENT_RESUMED
 + * 9.  paused  - paused:  none
 + * 10. pmsuspended - pmsuspended: none

this state is not possible with current qemu

 + * 11. pmsuspended - inactive:EVENT_STOPPED
 + * 12. pmsuspended - running: EVENT_RESUMED
 + * 13. pmsuspended - paused:  EVENT_PAUSED
 + * 14. inactive- pmsuspended: EVENT_STARTED, EVENT_PMSUSPENDED
 + * 15. paused  - pmsuspended: EVENT_PMSUSPENDED
 + * 16. running - pmsuspended: EVENT_PMSUSPENDED

and these three states are not possible

   * Also, several transitions occur even if we fail partway through,
   * and use of FORCE can cause multiple transitions.
   */
 @@ -14075,6 +14082,8 @@ static int 
 qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
  if (!(vm = qemuDomObjFromSnapshot(snapshot)))
  return -1;
 
 +oldState = vm-state.state;
 +
  cfg = virQEMUDriverGetConfig(driver);
 
  if (virDomainRevertToSnapshotEnsureACL(snapshot-domain-conn, vm-def) 
  0)
 @@ -14127,6 +14136,14 @@ static int 
 qemuDomainRevertToSnapshot(virDomainSnapshotPtr snapshot,
  }
  }
 
 +if (snap-def-state == VIR_DOMAIN_PMSUSPENDED 
 +(flags  VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING ||
 + flags  VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED)) {
 +virReportError(VIR_ERR_OPERATION_UNSUPPORTED, %s,
 +   _(snapshot of a VM in PMSUSPENDED state cannot be 
 + reverted to a running or paused state));

actually, I think that we need to tackle it differently - we can't
CREATE a snapshot in the pmsuspended state (just as we can't migrate in
that state - the mere act of migration is a wakeup event).  So, if you
eliminate all snapshots in the pmsuspended state as invalid, the set of
state transitions is smaller.


-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH] support vhost-scsi controller

2014-07-18 Thread Zhang Min
 libvirt support vhost-scsi controller. The way to config
 the vhost-scsi controller is edit the xml file, Format is
 as follows:

controller type='scsi' index='0' model='vhost-scsi'
source wwpn='naa.6001405f5e3acbba' event_idx='on'/
/controller

the tag of wwpn is necessary, the 'model' must be 'vhost-scsi'
'event_idx' is optional.

Signed-off-by: Zhang Min rudy.zhang...@huawei.com
---
 src/conf/domain_conf.c   |   64 +++--
 src/conf/domain_conf.h   |   10 ++
 src/qemu/qemu_capabilities.c |2 +
 src/qemu/qemu_capabilities.h |1 +
 src/qemu/qemu_command.c  |   21 -
 src/vmx/vmx.c|3 +-
 6 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 54925ba..e42ede7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -306,7 +306,8 @@ VIR_ENUM_IMPL(virDomainControllerModelSCSI, 
VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAS
   vmpvscsi,
   ibmvscsi,
   virtio-scsi,
-  lsisas1078);
+  lsisas1078,
+  vhost-scsi);
 
 VIR_ENUM_IMPL(virDomainControllerModelUSB, 
VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST,
   piix3-uhci,
@@ -1290,6 +1291,10 @@ void 
virDomainControllerDefFree(virDomainControllerDefPtr def)
 if (!def)
 return;
 
+if (def-vhostscsi.wwpn)
+VIR_FREE(def-vhostscsi.wwpn);
+memset(def-vhostscsi, 0, sizeof(def-vhostscsi));
+
 virDomainDeviceInfoClear(def-info);
 
 VIR_FREE(def);
@@ -6051,6 +6056,9 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 char *max_sectors = NULL;
 xmlNodePtr saved = ctxt-node;
 int rc;
+char *wwpn = NULL;
+char *event_idx = NULL;
+int event_idx_num = 0;
 
 ctxt-node = node;
 
@@ -6087,13 +6095,42 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 def-model = -1;
 }
 
+def-vhostscsi.wwpn = NULL;
 cur = node-children;
 while (cur != NULL) {
 if (cur-type == XML_ELEMENT_NODE) {
 if (xmlStrEqual(cur-name, BAD_CAST driver))
 queues = virXMLPropString(cur, queues);
-cmd_per_lun = virXMLPropString(cur, cmd_per_lun);
-max_sectors = virXMLPropString(cur, max_sectors);
+else if(xmlStrEqual(cur-name, BAD_CAST source)) {
+switch (def-model) {
+case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VHOST_SCSI:
+wwpn = virXMLPropString(cur, wwpn);
+if (wwpn  !STREQ(wwpn,)) {
+def-vhostscsi.wwpn = wwpn;
+wwpn = NULL;
+} else {
+virReportError(VIR_ERR_XML_ERROR,
+_(vhost-scsi:wwpn can't be null));
+goto error;
+}
+
+event_idx = virXMLPropString(cur, event_idx);
+if (event_idx) {
+if ((event_idx_num = 
virDomainVirtioEventIdxTypeFromString(event_idx)) = 0) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _(unknown vhost-scsi event_idx 
mode '%s'),
+   event_idx);
+goto error;
+}
+def-vhostscsi.event_idx = event_idx_num;
+}
+break;
+default:
+break;
+}
+}
+cmd_per_lun = virXMLPropString(cur, cmd_per_lun);
+max_sectors = virXMLPropString(cur, max_sectors);
 }
 cur = cur-next;
 }
@@ -6216,6 +6253,12 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 goto error;
 }
 
+if (def-model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VHOST_SCSI 
+def-vhostscsi.wwpn == NULL) {
+virReportError(VIR_ERR_XML_ERROR,_(vhost-scsi:wwpn can't be null));
+goto error;
+}
+
  cleanup:
 ctxt-node = saved;
 VIR_FREE(type);
@@ -6224,6 +6267,8 @@ virDomainControllerDefParseXML(xmlNodePtr node,
 VIR_FREE(queues);
 VIR_FREE(cmd_per_lun);
 VIR_FREE(max_sectors);
+VIR_FREE(wwpn);
+VIR_FREE(event_idx);
 
 return def;
 
@@ -15300,10 +15345,21 @@ virDomainControllerDefFormat(virBufferPtr buf,
 break;
 }
 
-if (def-queues || def-cmd_per_lun || def-max_sectors ||
+if (def-queues || def-cmd_per_lun || def-max_sectors || 
def-vhostscsi.wwpn
 virDomainDeviceInfoIsSet(def-info, flags) || pcihole64) {
 virBufferAddLit(buf, \n);
 virBufferAdjustIndent(buf, 2);
+
+if (def-vhostscsi.wwpn) {
+virBufferAsprintf(buf,   source wwpn='%s', 
def-vhostscsi.wwpn);
+
+   if