Re: [libvirt] [PATCH] audit: Fix some comments

2014-08-08 Thread Ján Tomko
On 08/08/2014 04:29 AM, Wang Rui wrote:
 On 2014/8/7 17:07, Ján Tomko wrote:
 On 08/07/2014 10:12 AM, Wang Rui wrote:
 Fix a comment in virDomainAuditNetDevice.
 Fix a typo in comment of qemuPhysIfaceConnect which is
 the caller of virDomainAuditNetDevice.

 Signed-off-by: Wang Rui moon.wang...@huawei.com
 ---
  src/conf/domain_audit.c | 4 ++--
  src/qemu/qemu_command.c | 2 +-
  2 files changed, 3 insertions(+), 3 deletions(-)


 ACK and pushed.
 
 Thanks.
 I have a question about comment style.
 I see there are two comment styles in our libvirt code.
 
 One is
 /*  
  *  
  */
 
 The other is
 /* 
  *  */
 
 Are both of them fine ?
 Or which one is recommended ?
 (I'm not sure about my comments when coding.)

We don't have a written rule.

To me, the second one only looks good with one to three line comments inside
functions.

For comments above function definitions, the first style seems to be preferred.

Jan



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

Re: [libvirt] [Qemu-devel] [PATCH v2 0/2] Add machine type pc-1.0-qemu-kvm for live migrate compatibility with qemu-kvm

2014-08-08 Thread Alex Bligh

On 7 Aug 2014, at 20:26, Serge E. Hallyn se...@hallyn.com wrote:

 A-ha, acpi wasn't a problem.  I actually had a general migration
 problem even when coming from other utopic hosts.  With that fixed,
 I've got successful migration from qemu-kvm 1.0 in precise to
 a utopic host.

That's good news. You might try the 2 patches here:

https://github.com/abligh/qemu/tree/livemigrate-qemu-kvm-to-qemu-2.0.0-test-2

and see if you can get Precise to Trusty migration working (as well
as Precise to Utopic)

-- 
Alex Bligh




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


Re: [libvirt] [PATCH 2/2] blockjob: fix use-after-free in blockcopy

2014-08-08 Thread Peter Krempa
On 08/07/14 18:36, Eric Blake wrote:
 On 08/07/2014 01:58 AM, Peter Krempa wrote:
 On 08/06/14 23:12, Eric Blake wrote:
 Commit febf84c2 tried to delay in-memory modification of the actual
 domain disk structure until after the qemu event was received.
 However, I missed that the code for block pivot had been temporarily
 setting disk-src = disk-mirror prior to the qemu command, in order
 to label the backing chain of a reused external blockcopy disk;
 and calls into qemu while still in that state before finally undoing
 things at the cleanup label.  Since the qemu event handler then does:
  virStorageSourceFree(disk-src);
  disk-src = disk-mirror;
 we have the sad race that a fast enough qemu event can cause a leak of
 the original disk-src, as well as a use-after-free of the disk-mirror
 contents, bad enough to crash libvirtd in some of my test runs, even
 though the common case of the qemu event being much later won't trip
 the race.

 

 -if (qemuDomainDetermineDiskChain(driver, vm, disk, false)  0)
 -goto cleanup;
 +if (qemuDomainDetermineDiskChain(driver, vm, disk, false)  0)
 +goto cleanup;

 
 If we go to cleanup here...
 
 -if (disk-mirror-format  disk-mirror-format != 
 VIR_STORAGE_FILE_RAW 
 -(virDomainLockDiskAttach(driver-lockManager, cfg-uri, vm, disk) 
  0 ||
 - qemuSetupDiskCgroup(vm, disk)  0 ||
 - virSecurityManagerSetDiskLabel(driver-securityManager, vm-def, 
 disk)  0))
 -goto cleanup;
 +if (disk-mirror-format 
 +disk-mirror-format != VIR_STORAGE_FILE_RAW 
 +(virDomainLockDiskAttach(driver-lockManager, cfg-uri, vm,
 + disk)  0 ||
 + qemuSetupDiskCgroup(vm, disk)  0 ||
 + virSecurityManagerSetDiskLabel(driver-securityManager, 
 vm-def,
 +disk)  0))
 +goto cleanup;
 +
 +disk-src = oldsrc;
 +oldsrc = NULL;
 
 ...then we miss the restore of disk-src here...
 
 +}

  /* Attempt the pivot.  Record the attempt now, to prevent duplicate
   * attempts; but the actual disk change will be made when emitting


 In the cleanup section there's the original place where oldsrc was
 returned back to disk-src. That would now be dead code.
 
 ...so the cleanup label is not dead code.
 

 ACK with that part removed.
 
 Is the patch okay as-is, with my explanation?
 

Ah right :)

Peter



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

Re: [libvirt] [PATCHv3] conf: Add USB sound card support and implement it for qemu

2014-08-08 Thread Ján Tomko
On 08/04/2014 11:46 AM, Peter Krempa wrote:
 ---
 
 Notes:
 Version 3:
 - rebased after recent additions
 Version 2:
 - added docs
 
  docs/formatdomain.html.in |  5 +++--
  src/conf/domain_conf.c|  3 ++-
  src/conf/domain_conf.h|  1 +
  src/qemu/qemu_capabilities.c  |  2 ++
  src/qemu/qemu_capabilities.h  |  1 +
  src/qemu/qemu_command.c   | 14 --
  tests/qemucapabilitiesdata/caps_1.2.2-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.3.1-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.4.2-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.5.3-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.6.0-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.6.50-1.caps |  1 +
  tests/qemuhelptest.c  |  9 ++---
  13 files changed, 33 insertions(+), 8 deletions(-)
 

 diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
 index e5b1adb..409a76e 100644
 --- a/docs/formatdomain.html.in
 +++ b/docs/formatdomain.html.in
 @@ -4981,9 +4981,10 @@ qemu-kvm -net nic,model=? /dev/null
  The codesound/code element has one mandatory attribute,
  codemodel/code, which specifies what real sound device is 
 emulated.
  Valid values are specific to the underlying hypervisor, though 
 typical
 -choices are 'es1370', 'sb16', 'ac97', and 'ich6'
 +choices are 'es1370', 'sb16', 'ac97', 'ich6' and 'usb'.
  (span class=since
 - 'ac97' only since 0.6.0, 'ich6' only since 0.8.8/span)
 + 'ac97' only since 0.6.0, 'ich6' only since 0.8.8,
 + 'usb' only since 1.2.7/span)

1.2.8

ACK with a xml-argv test added.

Jan



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

Re: [libvirt] virsh migrate: sometimes command line cannot exit until manually press ENTER key

2014-08-08 Thread Chun Yan Liu


 On 8/8/2014 at 12:18 AM, in message
CAAfHSJvP1P20kBFD9ZgYy=0JVvG5oiS0eVCfGZc+k39=eha...@mail.gmail.com,
Shivaprasad bhat shivaprasadb...@gmail.com wrote: 
 On Thu, Aug 7, 2014 at 11:02 AM, Chun Yan Liu cy...@suse.com wrote: 
  Hi, List, 
  
  Do you meet the same problem? Host is kvm, doing: (e.g.) 
  #virsh migrate sles11 qemu+ssh://147.2.207.55/system --live --unsafe 
  password: 
  Sometimes, VM is already running on the target host and disappears 
  from source host, but the command line still hangs there, if pressing 
  ENTER, it will exit. 
  
  I debugged the code, but found the result is weird. The code hangs at 
  tools/virsh-domain.c - cmdMigrate -vshWatchJob-poll(): 
  poll() is trying to select pipe_fd, which is used to receive message from 
  doMigrate thread. In debugging, found that doMigrate finishes and at 
  the end it  does call safewrite() to write the retval ('0' or '1') to  
 pipe_fd, 
  and the write is completed. But cmdMigrate poll() cannot get the event. 
  Then after pressing ENTER key, poll() can get the event and select 
  pipe_fd, then command line can exit. 
  
  Any ideas about the possible reason? 
  
 It is because, the authentication thread is independently waiting for the 
 password on virsh. I see that the virWatchJob interferes with authentication 
 thread and the password is never taken successfully. The virWatchJob 
 probably needs to wait till the authentication thread completes taking the 
 password after which it should start watching the job.

Agree. Although in my testing password can be taken successfully, and I
don't know how to explain why pressing ENTER then poll() can get
the pipe_fd event, I do think both authentication thread and main process
uses stdin might have some bad affect.

I'd like to adjust the code a little to move the authentication before poll(). 

Thanks!
 Moreover, I see 
 that --p2p 
 migration doesnt work at all when auto login is not configured. 
  
  
  Thanks, 
  Chunyan 
  
  
  -- 
  libvir-list mailing list 
  libvir-list@redhat.com 
  https://www.redhat.com/mailman/listinfo/libvir-list 
  
 Thanks, 
 Shiva 
  
  



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


[libvirt] [PATCH] cmdMigrate: move vshConnect before vshWatchJob

2014-08-08 Thread Chunyan Liu
A possible fix to issue:
http://www.redhat.com/archives/libvir-list/2014-August/thread.html#00227

While doing migration on KVM host, found problem sometimes:
VM is already running on the target host and disappears from source
host, but 'virsh migrate' command line hangs, cannot exit normally.
If pressing ENTER key, it will exit.

The code hangs at tools/virsh-domain.c: cmdMigrate
-vshWatchJob-poll():
poll() is trying to select pipe_fd, which is used to receive message
from doMigrate thread. In debugging, found that doMigrate finishes
and at the end it does call safewrite() to write the retval ('0' or
'1') to pipe_fd, and the write is completed. But cmdMigrate poll()
cannot get the event. If pressing ENTER key, poll() can get the
event and select pipe_fd, then command line can exit.

In current code, authentication thread which is called by vshConnect
will use stdin, and at the same time, in cmdMigrate main process,
poll() is listening to stdin, that probably affect poll() to get
pipe_fd event. Better to move authentication before vshWatchJob. With
this change, above problem does not exist.

Signed-off-by: Chunyan Liu cy...@suse.com
---
 tools/virsh-domain.c | 26 --
 tools/virsh.h|  1 +
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f7193cb..2562326 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -8965,6 +8965,7 @@ doMigrate(void *opaque)
 virTypedParameterPtr params = NULL;
 int nparams = 0;
 int maxparams = 0;
+virConnectPtr dconn = data-dconn;
 
 sigemptyset(sigmask);
 sigaddset(sigmask, SIGINT);
@@ -9079,18 +9080,12 @@ doMigrate(void *opaque)
 ret = '0';
 } else {
 /* For traditional live migration, connect to the destination host 
directly. */
-virConnectPtr dconn = NULL;
 virDomainPtr ddom = NULL;
 
-dconn = vshConnect(ctl, desturi, false);
-if (!dconn)
-goto out;
-
 if ((ddom = virDomainMigrate3(dom, dconn, params, nparams, flags))) {
 virDomainFree(ddom);
 ret = '0';
 }
-virConnectClose(dconn);
 }
 
  out:
@@ -9152,6 +9147,23 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
 data.cmd = cmd;
 data.writefd = p[1];
 
+if (vshCommandOptBool(cmd, p2p) || vshCommandOptBool(cmd, direct)) {
+data.dconn = NULL;
+} else {
+/* For traditional live migration, connect to the destination host. */
+virConnectPtr dconn = NULL;
+const char *desturi = NULL;
+
+if (vshCommandOptStringReq(ctl, cmd, desturi, desturi)  0)
+goto cleanup;
+
+dconn = vshConnect(ctl, desturi, false);
+if (!dconn)
+goto cleanup;
+
+data.dconn = dconn;
+}
+
 if (virThreadCreate(workerThread,
 true,
 doMigrate,
@@ -9163,6 +9175,8 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
 virThreadJoin(workerThread);
 
  cleanup:
+if (data.dconn)
+virConnectClose(data.dconn);
 virDomainFree(dom);
 VIR_FORCE_CLOSE(p[0]);
 VIR_FORCE_CLOSE(p[1]);
diff --git a/tools/virsh.h b/tools/virsh.h
index 7656407..b4df24b 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -371,6 +371,7 @@ struct _vshCtrlData {
 vshControl *ctl;
 const vshCmd *cmd;
 int writefd;
+virConnectPtr dconn;
 };
 
 /* error handling */
-- 
1.8.4.5

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


Re: [libvirt] [RFC PATCH 1/5] doc: schema: Add basic documentation for the ivshmem support

2014-08-08 Thread Martin Kletzander

On Thu, Aug 07, 2014 at 05:34:35PM +0200, Maxime Leroy wrote:

On Thu, Aug 7, 2014 at 12:33 PM, Martin Kletzander mklet...@redhat.com wrote:

On Tue, Aug 05, 2014 at 06:48:01PM +0200, Maxime Leroy wrote:


This patch documents XML elements used for support of ivshmem
devices.



At first, I'd like to thank you for the proposal.  There were numerous
requests for this, but since ivshmem is not known much, it's not easy
to get it in.  I'll get to the details later.



You welcome. ;) Thanks for the review.

[...]

At first, we should be more generic about the name if we want other
hypervisors to benefit from it.  The idea is that ivshmem is not
something new that nobody else than qemu can do.  It's just a shared
memory, every other hypervisor out there can come up with something
similar to this, so we don't want this to be called ivshmem.  One more
reason for that is that it doesn't just share memory between VMs, but
between host - guest too.  Something like a 'shmem' should be fine,
I guess.



I agree with you, shmem is a better name for ivshmem.

In such a case, should ivshmem be renamed in QEMU ?

This would break compatibility with older versions of QEMU.

If we change ivshmem name in QEMU, we need to manage this case in libvirt.

So, I am not sure about this point.



No need to change anything in QEMU.  That name is because libvirt
supports more than just QEMU.  For example if we add support for that
in lxc/xen/bhyve/whatever, it might not be called ivshmem and we
should be generic.


I prolonged the paragraph to stress out this is not qemu-only feature
(or might not be in the future) and we should be prepared for that.
Because of that, we should be more generic about more things than just
the name.

Another thing that bothers me (and bothered me with earlier
ivshmem-related proposals as well) is that role='(master|peer)' thing.
That thing does not mean squat for qemu and should be removed
completely.  Looking at the code the only thing that role=peer
(non-default, by the way) does is that it disables migration...
That's it.  That's another sign of the ivshmem code maturity inside
QEMU that we should keep in mind when designing the XML schema.




Ok. I added this role to be coherent with the initial proposals.

I agree with you, we should wait that live migration is properly
supported in ivshmem QEMU before adding any options related to that in
libvirt.



It is supported in a sense that it will migrate.  But that doesn't
mean it will work.  The data on destination host might not be there
and there might even be different data.  The guest must count with
that, but that's another issue.


So I will remove this role to avoid adding confusions.





Note: the ivshmem server needs to be launched before
  creating the VM. It's not done by libvirt.



This is a good temporary workaround, but keep in mind that libvirt
works remotely as well and for remote machines libvirt should be able
to do everything for you to be able to run the machine if necessary.
So even if it might not start the server now, it should in the future.
That should be at least differentiable by some parameter (maybe you do
it somewhere in the code somehow, I haven't got into that).



The new version of ivshmem server has not been accepted yet in QEMU.
I think it's too early to have an option to launch an ivshmem server or not.

I will prefer to focus on integrating these patches in libvirt first,
before adding a new feature to launch an ivhsmem server.

Are you ok with that ?



There was a suggestion of implementing the non-server variant first
and expand it to the variant with server afterwards.  That might be
the best solution because we'll have bit more time to see the
re-factoring differences in QEMU as well.  And we can concentrate on
other details.


- For ivshmem device not using an ivshmem server:

ivshmem use_server='no' role='peer'/
  source file='ivshmem1'/
  size unit='M'32/size
/ivshmem

Note: the ivshmem shm needs to be created before
  creating the VM. It's not done by libvirt.



Isn't it done by qemu automatically?  If it's not, the same as for the
ivshmem server applies.


Just checked the QEMU code, QEMU creates the file if it doesn't exist yet.
So my mistake ;)


I had one idea to deal with most of the problems (but adding a lot of
code); let me outline that.  From the global POV, we want something
that will fully work remotely, we want to be able to start it, stop
it, assign it to domains, etc.  We might even migrate it in the
future, but that's another storyline.  It must be generic enough, as
it can change a lot in the future.  And so on.  One way out of this
mess is to have yet another driver, let's call it shmem driver.  That
driver would have APIs to define, undefine, ..., start and stop shared
memory regions.  Those would have their own XML, and domain XML would
only have a device shmem name='asdf_mem'/ or shmem uuid='...'/
that would mean the domain will be started with a shared memory
region 

Re: [libvirt] [PATCH v2] storage: ZFS support

2014-08-08 Thread Ján Tomko
On 07/26/2014 06:13 PM, Roman Bogorodskiy wrote:
 Implement ZFS storage backend driver. Currently supported
 only on FreeBSD because of ZFS limitations on Linux.
 
 Features supported:
 
  - pool-start, pool-stop
  - pool-info
  - vol-list
  - vol-create / vol-delete
 
 Pool definition looks like that:
 
  pool type='zfs'
   namemyzfspool/name
   source
 nameactualpoolname/name
   /source
  /pool
 
 The 'actualpoolname' value is a name of the pool on the system,
 such as shown by 'zpool list' command. Target makes no sense
 here because volumes path is always /dev/zvol/$poolname/$volname.
 
 Users has to create a pool on his own, this driver doesn't

s/Users/User/

 support pool creation currently.
 
 A volume could be used with Qemu by adding an entry like this:
 
 disk type='volume' device='disk'
   driver name='qemu' type='raw'/
   source pool='myzfspool' volume='vol5'/
   target dev='hdc' bus='ide'/
 /disk
 ---
  configure.ac  |  43 +
  docs/schemas/storagepool.rng  |  20 +++
  docs/storage.html.in  |  34 
  include/libvirt/libvirt.h.in  |   1 +
  po/POTFILES.in|   1 +
  src/Makefile.am   |   8 +
  src/conf/storage_conf.c   |  15 +-
  src/conf/storage_conf.h   |   4 +-
  src/qemu/qemu_conf.c  |   1 +
  src/storage/storage_backend.c |   6 +
  src/storage/storage_backend_zfs.c | 329 
 ++
  src/storage/storage_backend_zfs.h |  29 
  src/storage/storage_driver.c  |   1 +
  tools/virsh-pool.c|   3 +
  14 files changed, 492 insertions(+), 3 deletions(-)
  create mode 100644 src/storage/storage_backend_zfs.c
  create mode 100644 src/storage/storage_backend_zfs.h

ACK

Jan



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

[libvirt] [PATCH] build: Fix build warning on libvirt-python

2014-08-08 Thread Wang Rui
From: Mo Yuxiang moyuxi...@huawei.com

On compiling libvirt-python, we get such a warning:

libvirt-qemu-override.c: In function 
‘libvirt_qemu_virConnectDomainQemuMonitorEventRegister’:
libvirt-qemu-override.c:304: warning: suggest explicit braces to avoid 
ambiguous ‘else’

Py_DECREF is a macro. The solution is to add brackets.

Signed-off-by: Mo Yuxiang moyuxi...@huawei.com
---
 libvirt-qemu-override.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c
index 05ead30..8be3755 100644
--- a/libvirt-qemu-override.c
+++ b/libvirt-qemu-override.c
@@ -301,8 +301,9 @@ 
libvirt_qemu_virConnectDomainQemuMonitorEventRegister(PyObject *self ATTRIBUTE_U
flags);
 LIBVIRT_END_ALLOW_THREADS;
 
-if (ret  0)
+if (ret  0) {
 Py_DECREF(pyobj_cbData);
+}
 
 py_retval = libvirt_intWrap(ret);
 return py_retval;
-- 
1.7.12.4


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

[libvirt] [PATCH v1 0/3] OVMF exposure

2014-08-08 Thread Michal Privoznik
Not so long ago, QEMU introduced support for UEFI instead of
standard BIOS. Our domain XML needs to be adjusted, however.
Users are expected to use mainly OVMF which works in two modes:

1) UEFI code and UEFI variables are mixed in one file

2) The code and variables are split in two separate files

For the case number one we are almost ready. The second case,
however, needs more changes on our side. Especially if you
consider fact, that the UEFI code can be shared among multiple
domains while the variables store can't.

Michal Privoznik (3):
  conf: Extend loader/ and introduce nvram/
  qemu: Implement extended loader and nvram
  qemu: Automatically create NVRAM store

 configure.ac   |  27 +
 docs/formatdomain.html.in  |  19 +++-
 docs/schemas/domaincommon.rng  |  21 
 libvirt.spec.in|   2 +
 src/Makefile.am|   1 +
 src/conf/domain_conf.c |  87 +-
 src/conf/domain_conf.h |  22 +++-
 src/libvirt_private.syms   |   3 +
 src/qemu/libvirtd_qemu.aug |   3 +
 src/qemu/qemu.conf |   9 ++
 src/qemu/qemu_command.c|  87 +-
 src/qemu/qemu_conf.c   |   8 ++
 src/qemu/qemu_conf.h   |   3 +
 src/qemu/qemu_process.c| 125 +
 src/qemu/test_libvirtd_qemu.aug.in |   1 +
 src/security/security_dac.c|   8 ++
 src/security/security_selinux.c|   8 ++
 src/security/virt-aa-helper.c  |   4 +-
 src/vbox/vbox_tmpl.c   |   7 +-
 src/xenapi/xenapi_driver.c |   3 +-
 src/xenxs/xen_sxpr.c   |  16 +--
 src/xenxs/xen_xm.c |   8 +-
 .../qemuxml2argvdata/qemuxml2argv-bios-nvram.args  |  10 ++
 tests/qemuxml2argvdata/qemuxml2argv-bios-nvram.xml |  40 +++
 tests/qemuxml2argvtest.c   |   2 +
 .../qemuxml2xmlout-pci-bridge-many-disks.xml   |   2 +-
 tests/qemuxml2xmltest.c|   2 +
 tests/sexpr2xmldata/sexpr2xml-fv-autoport.xml  |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.xml  |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.xml|   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-force-nohpet.xml  |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-kernel.xml|   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-legacy-vfb.xml|   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-net-ioemu.xml |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-net-netfront.xml  |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-parallel-tcp.xml  |   2 +-
 .../sexpr2xml-fv-serial-dev-2-ports.xml|   2 +-
 .../sexpr2xml-fv-serial-dev-2nd-port.xml   |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-file.xml   |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-null.xml   |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-pipe.xml   |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-pty.xml|   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-stdio.xml  |   2 +-
 .../sexpr2xml-fv-serial-tcp-telnet.xml |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp.xml|   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-udp.xml|   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-unix.xml   |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-sound-all.xml |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-sound.xml |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-usbmouse.xml  |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-usbtablet.xml |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-utc.xml   |   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-v2.xml|   2 +-
 tests/sexpr2xmldata/sexpr2xml-fv.xml   |   2 +-
 tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml  |   2 +-
 tests/xmconfigdata/test-escape-paths.xml   |   2 +-
 tests/xmconfigdata/test-fullvirt-force-hpet.xml|   2 +-
 tests/xmconfigdata/test-fullvirt-force-nohpet.xml  |   2 +-
 tests/xmconfigdata/test-fullvirt-localtime.xml |   2 +-
 tests/xmconfigdata/test-fullvirt-net-ioemu.xml |   2 +-
 tests/xmconfigdata/test-fullvirt-net-netfront.xml  |   2 +-
 tests/xmconfigdata/test-fullvirt-new-cdrom.xml |   2 +-
 tests/xmconfigdata/test-fullvirt-old-cdrom.xml |   2 +-
 tests/xmconfigdata/test-fullvirt-parallel-tcp.xml  |   2 +-
 .../test-fullvirt-serial-dev-2-ports.xml   |   2 +-
 .../test-fullvirt-serial-dev-2nd-port.xml  |   2 +-
 tests/xmconfigdata/test-fullvirt-serial-file.xml   |   2 +-
 tests/xmconfigdata/test-fullvirt-serial-null.xml   |   2 +-
 tests/xmconfigdata/test-fullvirt-serial-pipe.xml   |   2 +-

[libvirt] [PATCH v1 1/3] conf: Extend loader/ and introduce nvram/

2014-08-08 Thread Michal Privoznik
Up to now, users can configure BIOS via the loader/ element. With
the upcoming implementation of UEFI this is not enough as BIOS and
UEFI are conceptually different. For instance, while BIOS is ROM, UEFI
is programmable flash (although all writes to code section are
denied). Therefore we need new attribute @type which will
differentiate the two. Then, new attribute @readonly is introduced to
reflect the fact that some images are RO.

Moreover, the OVMF (which is going to be used mostly), works in two
modes:
1) Code and UEFI variable store is mixed in one file.
2) Code and UEFI variable store is separated in two files

The latter has advantage of updating the UEFI code without losing the
configuration. However, in order to represent the latter case we need
yet another XML element: nvram/. Currently, it has no additional
attributes, it's just a bare element containing path to the variable
store file.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 docs/formatdomain.html.in  | 19 -
 docs/schemas/domaincommon.rng  | 21 ++
 src/conf/domain_conf.c | 87 +-
 src/conf/domain_conf.h | 22 +-
 src/libvirt_private.syms   |  3 +
 src/qemu/qemu_command.c|  5 +-
 src/security/virt-aa-helper.c  |  4 +-
 src/vbox/vbox_tmpl.c   |  7 +-
 src/xenapi/xenapi_driver.c |  3 +-
 src/xenxs/xen_sxpr.c   | 16 ++--
 src/xenxs/xen_xm.c |  8 +-
 tests/qemuxml2argvdata/qemuxml2argv-bios-nvram.xml | 40 ++
 .../qemuxml2xmlout-pci-bridge-many-disks.xml   |  2 +-
 tests/qemuxml2xmltest.c|  2 +
 tests/sexpr2xmldata/sexpr2xml-fv-autoport.xml  |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-empty-kernel.xml  |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-force-hpet.xml|  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-force-nohpet.xml  |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-kernel.xml|  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-legacy-vfb.xml|  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-localtime.xml |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-net-ioemu.xml |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-net-netfront.xml  |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-parallel-tcp.xml  |  2 +-
 .../sexpr2xml-fv-serial-dev-2-ports.xml|  2 +-
 .../sexpr2xml-fv-serial-dev-2nd-port.xml   |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-file.xml   |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-null.xml   |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-pipe.xml   |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-pty.xml|  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-stdio.xml  |  2 +-
 .../sexpr2xml-fv-serial-tcp-telnet.xml |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-tcp.xml|  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-udp.xml|  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-serial-unix.xml   |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-sound-all.xml |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-sound.xml |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-usbmouse.xml  |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-usbtablet.xml |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-utc.xml   |  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv-v2.xml|  2 +-
 tests/sexpr2xmldata/sexpr2xml-fv.xml   |  2 +-
 tests/sexpr2xmldata/sexpr2xml-no-source-cdrom.xml  |  2 +-
 tests/xmconfigdata/test-escape-paths.xml   |  2 +-
 tests/xmconfigdata/test-fullvirt-force-hpet.xml|  2 +-
 tests/xmconfigdata/test-fullvirt-force-nohpet.xml  |  2 +-
 tests/xmconfigdata/test-fullvirt-localtime.xml |  2 +-
 tests/xmconfigdata/test-fullvirt-net-ioemu.xml |  2 +-
 tests/xmconfigdata/test-fullvirt-net-netfront.xml  |  2 +-
 tests/xmconfigdata/test-fullvirt-new-cdrom.xml |  2 +-
 tests/xmconfigdata/test-fullvirt-old-cdrom.xml |  2 +-
 tests/xmconfigdata/test-fullvirt-parallel-tcp.xml  |  2 +-
 .../test-fullvirt-serial-dev-2-ports.xml   |  2 +-
 .../test-fullvirt-serial-dev-2nd-port.xml  |  2 +-
 tests/xmconfigdata/test-fullvirt-serial-file.xml   |  2 +-
 tests/xmconfigdata/test-fullvirt-serial-null.xml   |  2 +-
 tests/xmconfigdata/test-fullvirt-serial-pipe.xml   |  2 +-
 tests/xmconfigdata/test-fullvirt-serial-pty.xml|  2 +-
 tests/xmconfigdata/test-fullvirt-serial-stdio.xml  |  2 +-
 .../test-fullvirt-serial-tcp-telnet.xml|  2 +-
 tests/xmconfigdata/test-fullvirt-serial-tcp.xml|  2 +-
 tests/xmconfigdata/test-fullvirt-serial-udp.xml|  2 +-
 tests/xmconfigdata/test-fullvirt-serial-unix.xml   |  2 +-
 tests/xmconfigdata/test-fullvirt-sound.xml |  2 +-
 tests/xmconfigdata/test-fullvirt-usbmouse.xml  |  2 +-
 tests/xmconfigdata/test-fullvirt-usbtablet.xml |  2 +-
 

[libvirt] [PATCH v1 2/3] qemu: Implement extended loader and nvram

2014-08-08 Thread Michal Privoznik
QEMU now supports UEFI with the following command line:

  -drive 
file=/usr/share/OVMF/OVMF_CODE.fd,if=pflash,format=raw,unit=0,readonly=on \
  -drive file=/usr/share/OVMF/OVMF_VARS.fd,if=pflash,format=raw,unit=1 \

where the first line reflects loader and the second one nvram.
Moreover, these two lines obsoletes the -bios argument.

Note that UEFI is unusable without ACPI. This is handled properly now.
Among with this extension, the variable file is expected to be
writable and hence we need security drivers to label it.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 src/qemu/qemu_command.c| 84 --
 src/security/security_dac.c|  8 +++
 src/security/security_selinux.c|  8 +++
 .../qemuxml2argvdata/qemuxml2argv-bios-nvram.args  | 10 +++
 tests/qemuxml2argvtest.c   |  2 +
 5 files changed, 108 insertions(+), 4 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-bios-nvram.args

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a3c048f..982dd7b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7284,6 +7284,84 @@ qemuBuildChrDeviceCommandLine(virCommandPtr cmd,
 return 0;
 }
 
+static int
+qemuBuilDomainLoaderCommandLine(virCommandPtr cmd,
+virDomainDefPtr def,
+virQEMUCapsPtr qemuCaps)
+{
+int ret = -1;
+virDomainLoaderDefPtr loader = def-os.loader;
+virBuffer buf = VIR_BUFFER_INITIALIZER;
+
+if (!loader)
+return 0;
+
+switch ((virDomainLoader) loader-type) {
+case VIR_DOMAIN_LOADER_TYPE_ROM:
+virCommandAddArg(cmd, -bios);
+virCommandAddArg(cmd, loader-path);
+break;
+
+case VIR_DOMAIN_LOADER_TYPE_PFLASH:
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
+   _(this qemu doesn't support -drive));
+goto cleanup;
+}
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_FORMAT)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
+   _(this qemu doesn't support passing 
+ drive format));
+goto cleanup;
+}
+if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NO_ACPI) 
+def-features[VIR_DOMAIN_FEATURE_ACPI] != VIR_TRISTATE_SWITCH_ON) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
+   _(ACPI must be enabled in order to use UEFI));
+goto cleanup;
+}
+
+virBufferAsprintf(buf,
+  file=%s,if=pflash,format=raw,unit=0,
+  loader-path);
+
+if (loader-readonly) {
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_READONLY)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
+   _(this qemu doesn't support passing 
+ readonly attribute));
+goto cleanup;
+}
+
+virBufferAsprintf(buf, ,readonly=%s,
+  virTristateSwitchTypeToString(loader-readonly));
+}
+
+virCommandAddArg(cmd, -drive);
+virCommandAddArgBuffer(cmd, buf);
+
+if (loader-nvram) {
+virBufferFreeAndReset(buf);
+virBufferAsprintf(buf,
+  file=%s,if=pflash,format=raw,unit=1,
+  loader-nvram);
+
+virCommandAddArg(cmd, -drive);
+virCommandAddArgBuffer(cmd, buf);
+}
+break;
+
+case VIR_DOMAIN_LOADER_TYPE_LAST:
+/* nada */
+break;
+}
+
+ret = 0;
+ cleanup:
+virBufferFreeAndReset(buf);
+return ret;
+}
+
 qemuBuildCommandLineCallbacks buildCommandLineCallbacks = {
 .qemuGetSCSIDeviceSgName = virSCSIDeviceGetSgName,
 };
@@ -7439,10 +7517,8 @@ qemuBuildCommandLine(virConnectPtr conn,
 virCommandAddArg(cmd, -enable-nesting);
 }
 
-if (def-os.loader) {
-virCommandAddArg(cmd, -bios);
-virCommandAddArg(cmd, def-os.loader-path);
-}
+if (qemuBuilDomainLoaderCommandLine(cmd, def, qemuCaps)  0)
+goto error;
 
 /* Set '-m MB' based on maxmem, because the lower 'memory' limit
  * is set post-startup using the balloon driver. If balloon driver
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index e62828e..e398d2c 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -960,6 +960,10 @@ 
virSecurityDACRestoreSecurityAllLabel(virSecurityManagerPtr mgr,
 rc = -1;
 }
 
+if (def-os.loader  def-os.loader-nvram 
+virSecurityDACRestoreSecurityFileLabel(def-os.loader-nvram)  0)
+rc = -1;
+
 if (def-os.kernel 
 virSecurityDACRestoreSecurityFileLabel(def-os.kernel)  0)
 rc = -1;

[libvirt] [PATCH v1 3/3] qemu: Automatically create NVRAM store

2014-08-08 Thread Michal Privoznik
When using split UEFI image, it may come handy if libvirt manages per
domain _VARS file automatically. While the _CODE file is RO and can be
shared among multiple domains, you certainly don't want to do that on
the _VARS file. This latter one needs to be per domain. So at the
domain startup process, if it's determined that domain needs _VARS
file it's copied from this master _VARS file. The location of the
master file is configurable in qemu.conf and the default path can be
compiled in via --with-qemu-nvram-file configure option.

Signed-off-by: Michal Privoznik mpriv...@redhat.com
---
 configure.ac   |  27 
 libvirt.spec.in|   2 +
 src/Makefile.am|   1 +
 src/qemu/libvirtd_qemu.aug |   3 +
 src/qemu/qemu.conf |   9 +++
 src/qemu/qemu_conf.c   |   8 +++
 src/qemu/qemu_conf.h   |   3 +
 src/qemu/qemu_process.c| 125 +
 src/qemu/test_libvirtd_qemu.aug.in |   1 +
 9 files changed, 179 insertions(+)

diff --git a/configure.ac b/configure.ac
index 9dd07d2..16ca266 100644
--- a/configure.ac
+++ b/configure.ac
@@ -569,6 +569,11 @@ AC_ARG_WITH([chrdev-lock-files],
 [location for UUCP style lock files for character devices
  (use auto for default paths on some platforms) @:@default=auto@:@])])
 m4_divert_text([DEFAULTS], [with_chrdev_lock_files=auto])
+AC_ARG_WITH([qemu-nvram-file],
+  [AS_HELP_STRING([--with-qemu-nvram-file],
+[location of OVMF_VARS.fd file
+ (use auto for default path on some platforms) @:@default=auto@:@])])
+m4_divert_text([DEFAULTS], [with_qemu_nvram_file=auto])
 AC_ARG_WITH([pm-utils],
   [AS_HELP_STRING([--with-pm-utils],
 [use pm-utils for power management @:@default=yes@:@])])
@@ -1418,6 +1423,27 @@ platform])
 fi
 AM_CONDITIONAL([VIR_CHRDEV_LOCK_FILE_PATH], [test $with_chrdev_lock_files != 
no])
 
+dnl OVMF_VARS.fd file
+if test $with_qemu_nvram_file != no; then
+  case $with_qemu_nvram_file in
+  yes | auto)
+dnl Default locations for platforms, or disable if unknown
+if test $with_linux = yes; then
+  with_qemu_nvram_file=/usr/share/OVMF/OVMF_VARS.fd
+elif test $with_chrdev_lock_files = auto; then
+  with_qemu_nvram_file=no
+fi ;;
+  esac
+  if test $with_qemu_nvram_file = yes; then
+AC_MSG_ERROR([You must specify path for the lock files on this
+platform])
+  fi
+  if test $with_qemu_nvram_file != no; then
+AC_DEFINE_UNQUOTED([VIR_QEMU_NVRAM_FILE_PATH], $with_qemu_nvram_file,
+   [default path to OVMF_VARS.fd file])
+  fi
+fi
+AM_CONDITIONAL([VIR_QEMU_NVRAM_FILE_PATH], [test $with_qemu_nvram_file != 
no])
 
 AC_ARG_WITH([secdriver-selinux],
   [AS_HELP_STRING([--with-secdriver-selinux],
@@ -2925,6 +2951,7 @@ AC_MSG_NOTICE([numad: $with_numad])
 AC_MSG_NOTICE([  XML Catalog: $XML_CATALOG_FILE])
 AC_MSG_NOTICE([  Init script: $with_init_script])
 AC_MSG_NOTICE([Char device locks: $with_chrdev_lock_files])
+AC_MSG_NOTICE([ OVMF_VARS.fd loc: $with_qemu_nvram_file])
 AC_MSG_NOTICE([])
 AC_MSG_NOTICE([Developer Tools])
 AC_MSG_NOTICE([])
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 29da071..486fc66 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1947,6 +1947,7 @@ exit 0
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/channel/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/channel/target/
+%dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/nvram/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/cache/libvirt/qemu/
 %{_datadir}/augeas/lenses/libvirtd_qemu.aug
 %{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
@@ -2049,6 +2050,7 @@ exit 0
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/channel/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/channel/target/
+%dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/lib/libvirt/qemu/nvram/
 %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
%{_localstatedir}/cache/libvirt/qemu/
 %{_datadir}/augeas/lenses/libvirtd_qemu.aug
 %{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
diff --git a/src/Makefile.am b/src/Makefile.am
index 982f63d..9bd38f5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2632,6 +2632,7 @@ endif WITH_SANLOCK
 if WITH_QEMU
$(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/libvirt/qemu
$(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/channel/target
+   $(MKDIR_P) $(DESTDIR)$(localstatedir)/lib/libvirt/qemu/nvram
$(MKDIR_P) $(DESTDIR)$(localstatedir)/run/libvirt/qemu
$(MKDIR_P) $(DESTDIR)$(localstatedir)/cache/libvirt/qemu
$(MKDIR_P) 

Re: [libvirt] [PATCH 3/4] vol-info: Check for NFS FS type

2014-08-08 Thread Ján Tomko
On 08/05/2014 04:38 PM, John Ferlan wrote:
 https://bugzilla.redhat.com/show_bug.cgi?id=1077068
 
 Check for the NFS FS type being true for a local stat of the file
 to force usage of the 'st_size' value rather than calculating the size
 using the 'st_blocks' and 'st_blksize'.  As described in the stat(2)
 man page:
 
 Use of the st_blocks and st_blksize fields may be less portable.
 
 experimentation shows a 10M file could get the following output from stat:
 
   st_size=10485760 st_blocks=88 st_blksize=1048576
 
 resulting in a 44 KiB value being displayed as the allocation value.
 While this value does match the du -s value of the same file, the
 du -b value shows the st_size field. Similarly a long listing of the
 file shows the 10M size.

Capacity should be the apparent size (what du -b shows, or st_size), while
allocation should track the on-disk usage (du, st_blocks * 512).

It looks to me that the values are correct, it's just that posix_fallocate
does neither work nor fail on NFS.

Jan



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/4] virfile: Introduce virFileIsNFSFSType

2014-08-08 Thread Ján Tomko
On 08/05/2014 04:38 PM, John Ferlan wrote:
 Use the virFileGetFSFtype() in order to compare the returned
 f_type for the NFS super magic number
 
 Signed-off-by: John Ferlan jfer...@redhat.com
 ---
  src/libvirt_private.syms |  1 +
  src/util/virfile.c   | 19 +++
  src/util/virfile.h   |  1 +
  3 files changed, 21 insertions(+)
 
 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
 index 08111d4..121e578 100644
 --- a/src/libvirt_private.syms
 +++ b/src/libvirt_private.syms
 @@ -1291,6 +1291,7 @@ virFileIsDir;
  virFileIsExecutable;
  virFileIsLink;
  virFileIsMountPoint;
 +virFileIsNFSFSType;
  virFileIsSharedFS;
  virFileIsSharedFSType;
  virFileLinkPointsTo;
 diff --git a/src/util/virfile.c b/src/util/virfile.c
 index 7612007..e6c767d 100644
 --- a/src/util/virfile.c
 +++ b/src/util/virfile.c
 @@ -2927,6 +2927,18 @@ virFileIsSharedFSType(const char *path,
  return 0;
  }
  
 +bool
 +virFileIsNFSFSType(const char *path)
 +{
 +long long int f_type;
 +
 +if ((virFileGetFSFtype(path, f_type) == 0) 
 +(f_type == NFS_SUPER_MAGIC))
 +return true;
 +
 +return false;
 +}
 +
  int
  virFileGetHugepageSize(const char *path,
 unsigned long long *size)
 @@ -3060,6 +3072,13 @@ int virFileIsSharedFSType(const char *path 
 ATTRIBUTE_UNUSED,
  }
  
  int
 +virFileIsNFSFSType(const char *path ATTRIBUTE_UNUSED)

This doesn't match the prototype in virfile.h.

Also, I wonder if virFileIsNFSFSType(path) is that much more readable than
virFileIsSharedFSType(path, VIR_FILE_SHFS_NFS) == 1.

 +{
 +/* XXX implement me :-) */
 +return false;
 +}
 +
 +int
  virFileGetHugepageSize(const char *path ATTRIBUTE_UNUSED,
 unsigned long long *size ATTRIBUTE_UNUSED)
  {
 diff --git a/src/util/virfile.h b/src/util/virfile.h
 index 403d0ba..cc07c53 100644
 --- a/src/util/virfile.h
 +++ b/src/util/virfile.h
 @@ -191,6 +191,7 @@ enum {
  };
  
  int virFileIsSharedFSType(const char *path, int fstypes) 
 ATTRIBUTE_NONNULL(1);
 +bool virFileIsNFSFSType(const char *path);

ATTRIBUTE_NONNULL(1);

  int virFileIsSharedFS(const char *path) ATTRIBUTE_NONNULL(1);
  int virFileIsMountPoint(const char *file) ATTRIBUTE_NONNULL(1);
  
 

ACK



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/4] virfile: Introduce virFileIsNFSFSType

2014-08-08 Thread John Ferlan


On 08/08/2014 07:07 AM, Ján Tomko wrote:
 On 08/05/2014 04:38 PM, John Ferlan wrote:
 Use the virFileGetFSFtype() in order to compare the returned
 f_type for the NFS super magic number

 Signed-off-by: John Ferlan jfer...@redhat.com
 ---
  src/libvirt_private.syms |  1 +
  src/util/virfile.c   | 19 +++
  src/util/virfile.h   |  1 +
  3 files changed, 21 insertions(+)

 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
 index 08111d4..121e578 100644
 --- a/src/libvirt_private.syms
 +++ b/src/libvirt_private.syms
 @@ -1291,6 +1291,7 @@ virFileIsDir;
  virFileIsExecutable;
  virFileIsLink;
  virFileIsMountPoint;
 +virFileIsNFSFSType;
  virFileIsSharedFS;
  virFileIsSharedFSType;
  virFileLinkPointsTo;
 diff --git a/src/util/virfile.c b/src/util/virfile.c
 index 7612007..e6c767d 100644
 --- a/src/util/virfile.c
 +++ b/src/util/virfile.c
 @@ -2927,6 +2927,18 @@ virFileIsSharedFSType(const char *path,
  return 0;
  }
  
 +bool
 +virFileIsNFSFSType(const char *path)
 +{
 +long long int f_type;
 +
 +if ((virFileGetFSFtype(path, f_type) == 0) 
 +(f_type == NFS_SUPER_MAGIC))
 +return true;
 +
 +return false;
 +}
 +
  int
  virFileGetHugepageSize(const char *path,
 unsigned long long *size)
 @@ -3060,6 +3072,13 @@ int virFileIsSharedFSType(const char *path 
 ATTRIBUTE_UNUSED,
  }
  
  int
 +virFileIsNFSFSType(const char *path ATTRIBUTE_UNUSED)
 
 This doesn't match the prototype in virfile.h.
 

Drat - boy I hate making the same mistake twice - changed the function
late, but forgot to change the #else...

 Also, I wonder if virFileIsNFSFSType(path) is that much more readable than
 virFileIsSharedFSType(path, VIR_FILE_SHFS_NFS) == 1.
 

hmm... guess that makes patch 1  2 unnecessary. Guess I was more
hyperfocused on how to get at NFS_SUPER_MAGIC that I missed the SHFS enum

I'll rework...


John


 +{
 +/* XXX implement me :-) */ 
 +return false;
 +}
 +
 +int
  virFileGetHugepageSize(const char *path ATTRIBUTE_UNUSED,
 unsigned long long *size ATTRIBUTE_UNUSED)
  {
 diff --git a/src/util/virfile.h b/src/util/virfile.h
 index 403d0ba..cc07c53 100644
 --- a/src/util/virfile.h
 +++ b/src/util/virfile.h
 @@ -191,6 +191,7 @@ enum {
  };
  
  int virFileIsSharedFSType(const char *path, int fstypes) 
 ATTRIBUTE_NONNULL(1);
 +bool virFileIsNFSFSType(const char *path);
 
 ATTRIBUTE_NONNULL(1);
 
  int virFileIsSharedFS(const char *path) ATTRIBUTE_NONNULL(1);
  int virFileIsMountPoint(const char *file) ATTRIBUTE_NONNULL(1);
  

 
 ACK
 

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


Re: [libvirt] [PATCH 3/4] vol-info: Check for NFS FS type

2014-08-08 Thread John Ferlan


On 08/08/2014 07:07 AM, Ján Tomko wrote:
 On 08/05/2014 04:38 PM, John Ferlan wrote:
 https://bugzilla.redhat.com/show_bug.cgi?id=1077068

 Check for the NFS FS type being true for a local stat of the file
 to force usage of the 'st_size' value rather than calculating the size
 using the 'st_blocks' and 'st_blksize'.  As described in the stat(2)
 man page:

 Use of the st_blocks and st_blksize fields may be less portable.

 experimentation shows a 10M file could get the following output from stat:

   st_size=10485760 st_blocks=88 st_blksize=1048576

 resulting in a 44 KiB value being displayed as the allocation value.
 While this value does match the du -s value of the same file, the
 du -b value shows the st_size field. Similarly a long listing of the
 file shows the 10M size.
 
 Capacity should be the apparent size (what du -b shows, or st_size), while
 allocation should track the on-disk usage (du, st_blocks * 512).
 
 It looks to me that the values are correct, it's just that posix_fallocate
 does neither work nor fail on NFS.
 

Ah yes - this is exactly where I went back and forth on... Digging
through 'old' google results on posix_fallocate() and wondering whether
it was incorrectly returning success or whether stat() was as pointed
out in its man page not getting a reliable st_blocks value.

However, if posix_fallocate() isn't working as specified for NFS and not
producing any error message, then how does one really determine that?

I also had some code that reworked the two callers/users in order to
force the allocation paths to go through the slower lseek/safewrite
calls.  Is it worth resurrecting that and going with it?

John

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


Re: [libvirt] [PATCH v1 3/3] qemu: Automatically create NVRAM store

2014-08-08 Thread Paolo Bonzini
Il 08/08/2014 12:17, Michal Privoznik ha scritto:
 When using split UEFI image, it may come handy if libvirt manages per
 domain _VARS file automatically. While the _CODE file is RO and can be
 shared among multiple domains, you certainly don't want to do that on
 the _VARS file. This latter one needs to be per domain. So at the
 domain startup process, if it's determined that domain needs _VARS
 file it's copied from this master _VARS file. The location of the
 master file is configurable in qemu.conf and the default path can be
 compiled in via --with-qemu-nvram-file configure option.

The only problem I see with this series is in this patch.

The master _VARS file can be different for different machine types, for
different architectures, and even for different _CODE files.

Perhaps you could introduce a format='...' attribute in nvram and use
that to pick the right master file (e.g. a format value could be
uefi128k)?  I don't like it, but I cannot think of anything else.

Or just leave out this patch for now...

Paolo

 Signed-off-by: Michal Privoznik mpriv...@redhat.com
 ---
  configure.ac   |  27 
  libvirt.spec.in|   2 +
  src/Makefile.am|   1 +
  src/qemu/libvirtd_qemu.aug |   3 +
  src/qemu/qemu.conf |   9 +++
  src/qemu/qemu_conf.c   |   8 +++
  src/qemu/qemu_conf.h   |   3 +
  src/qemu/qemu_process.c| 125 
 +
  src/qemu/test_libvirtd_qemu.aug.in |   1 +
  9 files changed, 179 insertions(+)
 
 diff --git a/configure.ac b/configure.ac
 index 9dd07d2..16ca266 100644
 --- a/configure.ac
 +++ b/configure.ac
 @@ -569,6 +569,11 @@ AC_ARG_WITH([chrdev-lock-files],
  [location for UUCP style lock files for character devices
   (use auto for default paths on some platforms) @:@default=auto@:@])])
  m4_divert_text([DEFAULTS], [with_chrdev_lock_files=auto])
 +AC_ARG_WITH([qemu-nvram-file],
 +  [AS_HELP_STRING([--with-qemu-nvram-file],
 +[location of OVMF_VARS.fd file
 + (use auto for default path on some platforms) @:@default=auto@:@])])
 +m4_divert_text([DEFAULTS], [with_qemu_nvram_file=auto])
  AC_ARG_WITH([pm-utils],
[AS_HELP_STRING([--with-pm-utils],
  [use pm-utils for power management @:@default=yes@:@])])
 @@ -1418,6 +1423,27 @@ platform])
  fi
  AM_CONDITIONAL([VIR_CHRDEV_LOCK_FILE_PATH], [test $with_chrdev_lock_files 
 != no])
  
 +dnl OVMF_VARS.fd file
 +if test $with_qemu_nvram_file != no; then
 +  case $with_qemu_nvram_file in
 +  yes | auto)
 +dnl Default locations for platforms, or disable if unknown
 +if test $with_linux = yes; then
 +  with_qemu_nvram_file=/usr/share/OVMF/OVMF_VARS.fd
 +elif test $with_chrdev_lock_files = auto; then
 +  with_qemu_nvram_file=no
 +fi ;;
 +  esac
 +  if test $with_qemu_nvram_file = yes; then
 +AC_MSG_ERROR([You must specify path for the lock files on this
 +platform])
 +  fi
 +  if test $with_qemu_nvram_file != no; then
 +AC_DEFINE_UNQUOTED([VIR_QEMU_NVRAM_FILE_PATH], $with_qemu_nvram_file,
 +   [default path to OVMF_VARS.fd file])
 +  fi
 +fi
 +AM_CONDITIONAL([VIR_QEMU_NVRAM_FILE_PATH], [test $with_qemu_nvram_file != 
 no])
  
  AC_ARG_WITH([secdriver-selinux],
[AS_HELP_STRING([--with-secdriver-selinux],
 @@ -2925,6 +2951,7 @@ AC_MSG_NOTICE([numad: $with_numad])
  AC_MSG_NOTICE([  XML Catalog: $XML_CATALOG_FILE])
  AC_MSG_NOTICE([  Init script: $with_init_script])
  AC_MSG_NOTICE([Char device locks: $with_chrdev_lock_files])
 +AC_MSG_NOTICE([ OVMF_VARS.fd loc: $with_qemu_nvram_file])
  AC_MSG_NOTICE([])
  AC_MSG_NOTICE([Developer Tools])
  AC_MSG_NOTICE([])
 diff --git a/libvirt.spec.in b/libvirt.spec.in
 index 29da071..486fc66 100644
 --- a/libvirt.spec.in
 +++ b/libvirt.spec.in
 @@ -1947,6 +1947,7 @@ exit 0
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/channel/
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/channel/target/
 +%dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/nvram/
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/cache/libvirt/qemu/
  %{_datadir}/augeas/lenses/libvirtd_qemu.aug
  %{_datadir}/augeas/lenses/tests/test_libvirtd_qemu.aug
 @@ -2049,6 +2050,7 @@ exit 0
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/channel/
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/channel/target/
 +%dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/lib/libvirt/qemu/nvram/
  %dir %attr(0750, %{qemu_user}, %{qemu_group}) 
 %{_localstatedir}/cache/libvirt/qemu/
  %{_datadir}/augeas/lenses/libvirtd_qemu.aug
  

Re: [libvirt] [PATCH v1 2/3] qemu: Implement extended loader and nvram

2014-08-08 Thread Paolo Bonzini
Il 08/08/2014 12:17, Michal Privoznik ha scritto:
 +if (loader-nvram) {
 +virBufferFreeAndReset(buf);
 +virBufferAsprintf(buf,
 +  file=%s,if=pflash,format=raw,unit=1,
 +  loader-nvram);
 +
 +virCommandAddArg(cmd, -drive);
 +virCommandAddArgBuffer(cmd, buf);
 +}

Note that other machines may not need unit=1, for example pseries
doesn't need it (it uses -bios for the firmware, not -drive if=pflash).
 It would be nice to make this easily configurable.

Alternatively you could use unit=1 if there is a loader type='pflash'
element, and unit=0 otherwise.  We can then patch QEMU to reject unit=1
on machines that use -bios + -drive if=pflash,unit=0.

Laszlo, what happens on x86 with -bios + -drive if=pflash,unit=0?

Paolo

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


Re: [libvirt] [RFC PATCH 1/5] doc: schema: Add basic documentation for the ivshmem support

2014-08-08 Thread Maxime Leroy
On Fri, Aug 8, 2014 at 11:21 AM, Martin Kletzander mklet...@redhat.com wrote:
 On Thu, Aug 07, 2014 at 05:34:35PM +0200, Maxime Leroy wrote:

 On Thu, Aug 7, 2014 at 12:33 PM, Martin Kletzander mklet...@redhat.com
 wrote:

 On Tue, Aug 05, 2014 at 06:48:01PM +0200, Maxime Leroy wrote:

[...]

 Note: the ivshmem server needs to be launched before
   creating the VM. It's not done by libvirt.


 This is a good temporary workaround, but keep in mind that libvirt
 works remotely as well and for remote machines libvirt should be able
 to do everything for you to be able to run the machine if necessary.
 So even if it might not start the server now, it should in the future.
 That should be at least differentiable by some parameter (maybe you do
 it somewhere in the code somehow, I haven't got into that).


 The new version of ivshmem server has not been accepted yet in QEMU.
 I think it's too early to have an option to launch an ivshmem server or
 not.

 I will prefer to focus on integrating these patches in libvirt first,
 before adding a new feature to launch an ivhsmem server.

 Are you ok with that ?


 There was a suggestion of implementing the non-server variant first
 and expand it to the variant with server afterwards.  That might be
 the best solution because we'll have bit more time to see the
 re-factoring differences in QEMU as well.  And we can concentrate on
 other details.


I would prefer to have ivshmen server and non-server mode supported in
libvirt with these patches; because the XML format need to be designed
with both at the same time.

The new XML format supporting a start or not of ivshmem server could be:

shmem type='ivshmem'
  shm file='ivshmem0'
  server socket='/tmp/socket-ivshmem0'  start='yes'
  size unit='M'32/size
  msi vectors='32' ioeventfd='on'/
/shmem

Note: This new XML format can support different types of shmem.

After my holiday, I am going to check how to implement this feature.
What do you think about this XML format?

Any hints to develop this feature (i.e. starting ivshmen server in
libvirt) is welcomed.

I assume I need to add a new file: src/util/virivshmemserver.c to add
a new function virIvshmemServerRun() and to use it in qemu_command.c.

How can I check whether an ivshmem-server application is installed or
not on the host ? Are there other equivalent behaviors into libvirt?

Maxime

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


Re: [libvirt] [PATCH v1 2/3] qemu: Implement extended loader and nvram

2014-08-08 Thread Michal Privoznik

On 08.08.2014 14:08, Paolo Bonzini wrote:

Il 08/08/2014 12:17, Michal Privoznik ha scritto:

+if (loader-nvram) {
+virBufferFreeAndReset(buf);
+virBufferAsprintf(buf,
+  file=%s,if=pflash,format=raw,unit=1,
+  loader-nvram);
+
+virCommandAddArg(cmd, -drive);
+virCommandAddArgBuffer(cmd, buf);
+}


Note that other machines may not need unit=1, for example pseries
doesn't need it (it uses -bios for the firmware, not -drive if=pflash).
  It would be nice to make this easily configurable.


Is there a table anywhere where I can see what machine types support 
this? Or does it makes sense to enable this only for 
qemu-system-{x86_64,i386} -M pc and error out for all other combinations?




Alternatively you could use unit=1 if there is a loader type='pflash'
element, and unit=0 otherwise.  We can then patch QEMU to reject unit=1
on machines that use -bios + -drive if=pflash,unit=0.

Laszlo, what happens on x86 with -bios + -drive if=pflash,unit=0?

Paolo



Michal

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


Re: [libvirt] [PATCH v1 2/3] qemu: Implement extended loader and nvram

2014-08-08 Thread Laszlo Ersek
On 08/08/14 14:08, Paolo Bonzini wrote:
 Il 08/08/2014 12:17, Michal Privoznik ha scritto:
 +if (loader-nvram) {
 +virBufferFreeAndReset(buf);
 +virBufferAsprintf(buf,
 +  file=%s,if=pflash,format=raw,unit=1,
 +  loader-nvram);
 +
 +virCommandAddArg(cmd, -drive);
 +virCommandAddArgBuffer(cmd, buf);
 +}
 
 Note that other machines may not need unit=1, for example pseries
 doesn't need it (it uses -bios for the firmware, not -drive if=pflash).
  It would be nice to make this easily configurable.
 
 Alternatively you could use unit=1 if there is a loader type='pflash'
 element, and unit=0 otherwise.  We can then patch QEMU to reject unit=1
 on machines that use -bios + -drive if=pflash,unit=0.
 
 Laszlo, what happens on x86 with -bios + -drive if=pflash,unit=0?

I checked that earlier (independently of unit=... in the pflash drive).
With -bios, you only change the bios filename:

case QEMU_OPTION_bios:
qemu_opts_set(qemu_find_opts(machine), 0, firmware,
optarg);

[...]

bios_name = qemu_opt_get(machine_opts, firmware);

Code using bios_name is not reached when a pflash drive is present: that
would be old_pc_system_rom_init() in hw/i386/pc_sysfw.c, but its only
caller, pc_system_firmware_init(), doesn't call it if there's at least
one pflash drive (and you're not running an ISA PC).

... I did find the firmware machine property too, but it seems to be
used only on s390x.

So, in total, as long as you run a PCI-enabled PC (esp. i440fx) machine
type, -bios is simply ignored when a pflash drive is present.

Thanks
Laszlo



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


Re: [libvirt] [PATCHv3] conf: Add USB sound card support and implement it for qemu

2014-08-08 Thread Peter Krempa
On 08/08/14 10:23, Ján Tomko wrote:
 On 08/04/2014 11:46 AM, Peter Krempa wrote:
 ---

 Notes:
 Version 3:
 - rebased after recent additions
 Version 2:
 - added docs

  docs/formatdomain.html.in |  5 +++--
  src/conf/domain_conf.c|  3 ++-
  src/conf/domain_conf.h|  1 +
  src/qemu/qemu_capabilities.c  |  2 ++
  src/qemu/qemu_capabilities.h  |  1 +
  src/qemu/qemu_command.c   | 14 --
  tests/qemucapabilitiesdata/caps_1.2.2-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.3.1-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.4.2-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.5.3-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.6.0-1.caps  |  1 +
  tests/qemucapabilitiesdata/caps_1.6.50-1.caps |  1 +
  tests/qemuhelptest.c  |  9 ++---
  13 files changed, 33 insertions(+), 8 deletions(-)

 
 diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
 index e5b1adb..409a76e 100644
 --- a/docs/formatdomain.html.in
 +++ b/docs/formatdomain.html.in
 @@ -4981,9 +4981,10 @@ qemu-kvm -net nic,model=? /dev/null
  The codesound/code element has one mandatory attribute,
  codemodel/code, which specifies what real sound device is 
 emulated.
  Valid values are specific to the underlying hypervisor, though 
 typical
 -choices are 'es1370', 'sb16', 'ac97', and 'ich6'
 +choices are 'es1370', 'sb16', 'ac97', 'ich6' and 'usb'.
  (span class=since
 - 'ac97' only since 0.6.0, 'ich6' only since 0.8.8/span)
 + 'ac97' only since 0.6.0, 'ich6' only since 0.8.8,
 + 'usb' only since 1.2.7/span)
 
 1.2.8
 
 ACK with a xml-argv test added.
 

I've added the model to one of the existing sound card model tests and
pushed the patch.

Thanks for the review.

Peter





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

Re: [libvirt] [RFC PATCH 1/5] doc: schema: Add basic documentation for the ivshmem support

2014-08-08 Thread Martin Kletzander

On Fri, Aug 08, 2014 at 02:07:56PM +0200, Maxime Leroy wrote:

On Fri, Aug 8, 2014 at 11:21 AM, Martin Kletzander mklet...@redhat.com wrote:

On Thu, Aug 07, 2014 at 05:34:35PM +0200, Maxime Leroy wrote:


On Thu, Aug 7, 2014 at 12:33 PM, Martin Kletzander mklet...@redhat.com
wrote:


On Tue, Aug 05, 2014 at 06:48:01PM +0200, Maxime Leroy wrote:



[...]



Note: the ivshmem server needs to be launched before
  creating the VM. It's not done by libvirt.



This is a good temporary workaround, but keep in mind that libvirt
works remotely as well and for remote machines libvirt should be able
to do everything for you to be able to run the machine if necessary.
So even if it might not start the server now, it should in the future.
That should be at least differentiable by some parameter (maybe you do
it somewhere in the code somehow, I haven't got into that).



The new version of ivshmem server has not been accepted yet in QEMU.
I think it's too early to have an option to launch an ivshmem server or
not.

I will prefer to focus on integrating these patches in libvirt first,
before adding a new feature to launch an ivhsmem server.

Are you ok with that ?



There was a suggestion of implementing the non-server variant first
and expand it to the variant with server afterwards.  That might be
the best solution because we'll have bit more time to see the
re-factoring differences in QEMU as well.  And we can concentrate on
other details.



I would prefer to have ivshmen server and non-server mode supported in
libvirt with these patches; because the XML format need to be designed
with both at the same time.

The new XML format supporting a start or not of ivshmem server could be:

shmem type='ivshmem'
 shm file='ivshmem0'
 server socket='/tmp/socket-ivshmem0'  start='yes'
 size unit='M'32/size
 msi vectors='32' ioeventfd='on'/
/shmem

Note: This new XML format can support different types of shmem.

After my holiday, I am going to check how to implement this feature.
What do you think about this XML format?



It's better, but I would like this:

shmem name='my_ivshmem_001'
 server socket='/tmp/ivsh-server' start='yes'/
 ...
/shmem

That could be simplified into (in case of no server):

shmem name='my_ivshmem_001'/

Of course this will have a PCI address afterwards.

This design is generic enough that it doesn't mention ivshmem (so it
can be implemented differently in any hypervisor).

What's your opinion on that?


Any hints to develop this feature (i.e. starting ivshmen server in
libvirt) is welcomed.



With starting the server in libvirt we'll have to wait until it's in
qemu *and* we have to deal with how and when to stop the server (if we
are running it).


I assume I need to add a new file: src/util/virivshmemserver.c to add
a new function virIvshmemServerRun() and to use it in qemu_command.c.

How can I check whether an ivshmem-server application is installed or
not on the host ? Are there other equivalent behaviors into libvirt?



That should be checked by virFileIsExecutable() on a
IVSHMEM_SERVER_PATH that would be set by configure.ac (take a look at
EBTABLES_PATH in src/util/virfirewall.c for example).

I'll also see if I'll be able to get any info from the QEMU side about
what can we expect to happen with ivshmem in near future.

Martin


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

[libvirt] [BUG] Two different connections to the same host through different transport

2014-08-08 Thread Емил Гелев
Hi. I am using libvirt for some time and I have found the following problem.
When I try opening two connections with the same credentials to the same
host but using different transport(TCP and TLS) I get the following error
when trying to free the TLS one:
*** Error in `./test': double free or corruption (!prev):
0x014a7a60 ***
Aborted (core dumped)

Example code:
#include stdio.h
#include stdlib.h
#include string.h
#include libvirt/libvirt.h


struct CredentialsPack {
const char* username;
const char* password;
};

struct CredentialsPack* newCredentialsPack(const char* username,
const char* password) {
struct CredentialsPack* ptr = malloc(sizeof(struct CredentialsPack));
ptr-username = username;
ptr-password = password;
return ptr;
}

static int authCredTypes[] = { VIR_CRED_AUTHNAME, VIR_CRED_PASSPHRASE, };

static int authCb(virConnectCredentialPtr cred, unsigned int ncred,
void* cbdata) {
struct CredentialsPack* inputCreds = (struct CredentialsPack*) cbdata;
int i;
for (i = 0; i  ncred; ++i) {
if (cred[i].type == VIR_CRED_AUTHNAME) {
cred[i].result = strdup(inputCreds-username);
if (cred[i].result == NULL) {
return -1;
}
cred[i].resultlen = strlen(cred[i].result);
} else if (cred[i].type == VIR_CRED_PASSPHRASE) {
cred[i].result = strdup(inputCreds-password);
if (cred[i].result == NULL) {
return -1;
}
cred[i].resultlen = strlen(cred[i].result);
}
}
return 0;
}

int main(){
struct CredentialsPack* credentials = newCredentialsPack(user,
pass);
virConnectAuth auth;
auth.credtype = authCredTypes;
auth.ncredtype = sizeof(authCredTypes) / sizeof(int);
auth.cb = authCb;
auth.cbdata = credentials;

virConnectPtr conn;
conn = virConnectOpenAuth(qemu+tcp://host1/system, auth, 0);


struct CredentialsPack* credentials2 = newCredentialsPack(user,
pass);
virConnectAuth auth2;
auth2.credtype = authCredTypes;
auth2.ncredtype = sizeof(authCredTypes) / sizeof(int);
auth2.cb = authCb;
auth2.cbdata = credentials2;

virConnectPtr conn2;
conn2 = virConnectOpenAuth(qemu://host1/system, auth2, 0);

//virConnectClose(conn); // this does not change the behaviour
virConnectClose(conn2); // here the error occurs
}

If I try to close conn then everything works until I try to close
conn2. I can even invoke virConnectListAllDomains using conn2 and use
the domain pointers when conn is closed. The problem is when I try to
close conn2.

The platform running this code is Ubuntu 14.04. The version of libvirt is
1.2.2 (default configuration). The certificate of the CA which signed the
server certificate is under /etc/pki/CA/cacert.pem

The target machine is RHEL 6.5. The version of libvirt is 0.10.2. It is
configured this way:
listen_tls = 1
listen_tcp = 1
auth_tcp = sasl
auth_tls = sasl
tls_no_verify_certificate = 1
Everything else is set to default.
The certificate of the CA which signed the server certificate is under
/etc/pki/CA/cacert.pem
The user user is added to the DB( using $ saslpasswd2 -a libvirt user). I
can successfully execute the following on the command line using the
user/pass credentials:
virsh -c qemu://host1/system list
virsh -c qemu+tcp://host1/system list

I hope this will be useful.
Thank you.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH v1 2/3] qemu: Implement extended loader and nvram

2014-08-08 Thread Paolo Bonzini
Il 08/08/2014 14:26, Michal Privoznik ha scritto:

 Note that other machines may not need unit=1, for example pseries
 doesn't need it (it uses -bios for the firmware, not -drive if=pflash).
   It would be nice to make this easily configurable.
 
 Is there a table anywhere where I can see what machine types support
 this? Or does it makes sense to enable this only for
 qemu-system-{x86_64,i386} -M pc and error out for all other combinations?

Only on x86_64 is a good match for now.  I don't know what ARM does or
will do, but it's possible it supports or will support 2 pflash devices too.

Paolo

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


[libvirt] [PATCH 14/14] qemu: hotplug: Reject media change when XML contains disk ABI change

2014-08-08 Thread Peter Krempa
Changing the media doesn't change other (especially ABI based) aspects
of the disk. Add verification and reject disk change if ABI would be
changed.
---
 src/conf/domain_conf.c   | 2 +-
 src/conf/domain_conf.h   | 3 +++
 src/libvirt_private.syms | 1 +
 src/qemu/qemu_driver.c   | 4 
 src/qemu/qemu_hotplug.c  | 4 
 5 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 34c1a8c..126a489 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13667,7 +13667,7 @@ 
virDomainDeviceInfoCheckABIStability(virDomainDeviceInfoPtr src,
 }


-static bool
+bool
 virDomainDiskDefCheckABIStability(virDomainDiskDefPtr src,
   virDomainDiskDefPtr dst)
 {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 21cfba2..c59ad19 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2304,6 +2304,9 @@ virDomainDefPtr virDomainDefParseNode(xmlDocPtr doc,
 bool virDomainDefCheckABIStability(virDomainDefPtr src,
virDomainDefPtr dst);

+bool virDomainDiskDefCheckABIStability(virDomainDiskDefPtr src,
+   virDomainDiskDefPtr dst);
+
 int virDomainDefAddImplicitControllers(virDomainDefPtr def);

 char *virDomainDefFormat(virDomainDefPtr def,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 08111d4..e85467e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -219,6 +219,7 @@ virDomainDiskBusTypeToString;
 virDomainDiskCacheTypeFromString;
 virDomainDiskCacheTypeToString;
 virDomainDiskDefAssignAddress;
+virDomainDiskDefCheckABIStability;
 virDomainDiskDefForeachPath;
 virDomainDiskDefFree;
 virDomainDiskDefNew;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4b1c69f..ad7cb84 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6642,6 +6642,10 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 goto end;
 }

+/* when changing media, rest of the disk ABI cannot change */
+if (!virDomainDiskDefCheckABIStability(orig_disk, disk))
+goto end;
+
 if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
 goto end;

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 4c69c5e..d937d44 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -795,6 +795,10 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
 goto end;
 }

+/* when changing media, rest of the disk ABI cannot change */
+if (!virDomainDiskDefCheckABIStability(orig_disk, disk))
+goto end;
+
 if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
 goto end;

-- 
2.0.2

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


[libvirt] [PATCH 00/14] qemu: Cdrom media change fixes and support for networked storage

2014-08-08 Thread Peter Krempa
Peter Krempa (14):
  qemu: Explicitly state that hotplugging cdroms and floppies doesn't
work
  conf: Pass virStorageSource into virDomainDiskSourceIsBlockType
  qemu: hotplug: Untangle cleanup paths in
qemuDomainChangeEjectableMedia
  qemu: hotplug: Add helper to initialize/teardown new disks for VMs
  qemu: hotplug: Change arguments for qemuDomainChangeEjectableMedia
  qemu: hotplug: Format proper source string for cdrom media change
  qemu: shared: Split out insertion code to the shared device list
  qemu: shared: Split out shared device list remove code
  qemu: conf: rename qemuCheckSharedDevice to qemuCheckSharedDisk
  qemu: conf: Split up qemuAddSharedDevice into per-device-type
functions
  qemu: conf: Split up qemuRemoveSharedDevice into per-device-type
functions
  qemu: conf: Split out code to retrieve hostdev key and reuse it
  qemu: hotplug: Sanitize shared device removal on media change
  qemu: hotplug: Reject media change when XML contains disk ABI change

 src/conf/domain_conf.c   |  21 +--
 src/conf/domain_conf.h   |   5 +-
 src/libvirt_private.syms |   1 +
 src/lxc/lxc_cgroup.c |   2 +-
 src/lxc/lxc_driver.c |   2 +-
 src/qemu/qemu_command.c  |   2 +-
 src/qemu/qemu_conf.c | 445 ---
 src/qemu/qemu_conf.h |   5 +
 src/qemu/qemu_driver.c   |  43 ++---
 src/qemu/qemu_hotplug.c  | 269 +++-
 src/qemu/qemu_hotplug.h  |   3 +-
 11 files changed, 414 insertions(+), 384 deletions(-)

-- 
2.0.2

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


[libvirt] [PATCH 02/14] conf: Pass virStorageSource into virDomainDiskSourceIsBlockType

2014-08-08 Thread Peter Krempa
All checks are based on the storage source, thus there's no need to pass
the complete disk def.
---
 src/conf/domain_conf.c  | 19 ---
 src/conf/domain_conf.h  |  2 +-
 src/lxc/lxc_cgroup.c|  2 +-
 src/lxc/lxc_driver.c|  2 +-
 src/qemu/qemu_command.c |  2 +-
 src/qemu/qemu_conf.c|  6 +++---
 6 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c7016f3..34c1a8c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -20011,29 +20011,26 @@ virDomainDefFindDevice(virDomainDefPtr def,
  * Return true if its source is block type, or false otherwise.
  */
 bool
-virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
+virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
 {
-/* No reason to think the disk source is block type if
- * the source is empty
- */
-if (!virDomainDiskGetSource(def))
+if (!src-path)
 return false;

-if (virDomainDiskGetType(def) == VIR_STORAGE_TYPE_BLOCK)
+if (src-type == VIR_STORAGE_TYPE_BLOCK)
 return true;

 /* For volume types, check the srcpool.
  * If it's a block type source pool, then it's possible
  */
-if (virDomainDiskGetType(def) == VIR_STORAGE_TYPE_VOLUME 
-def-src-srcpool 
-def-src-srcpool-voltype == VIR_STORAGE_VOL_BLOCK) {
+if (src-type == VIR_STORAGE_TYPE_VOLUME 
+src-srcpool 
+src-srcpool-voltype == VIR_STORAGE_VOL_BLOCK) {
 /* We don't think the volume accessed by remote URI is
  * block type source, since we can't/shouldn't manage it
  * (e.g. set sgio=filtered|unfiltered for it) in libvirt.
  */
- if (def-src-srcpool-pooltype == VIR_STORAGE_POOL_ISCSI 
- def-src-srcpool-mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT)
+ if (src-srcpool-pooltype == VIR_STORAGE_POOL_ISCSI 
+ src-srcpool-mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT)
  return false;

 return true;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ff7d640..21cfba2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2713,7 +2713,7 @@ int virDomainDefFindDevice(virDomainDefPtr def,
virDomainDeviceDefPtr dev,
bool reportError);

-bool virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def)
+bool virDomainDiskSourceIsBlockType(virStorageSourcePtr src)
 ATTRIBUTE_NONNULL(1);

 void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index ff88e4f..f9af31c 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -373,7 +373,7 @@ static int virLXCCgroupSetupDeviceACL(virDomainDefPtr def,

 VIR_DEBUG(Allowing any disk block devs);
 for (i = 0; i  def-ndisks; i++) {
-if (!virDomainDiskSourceIsBlockType(def-disks[i]))
+if (!virDomainDiskSourceIsBlockType(def-disks[i]-src))
 continue;

 if (virCgroupAllowDevicePath(cgroup,
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 9e12ecc..6eff8b3 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -4047,7 +4047,7 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
 goto cleanup;
 }

-if (!virDomainDiskSourceIsBlockType(def)) {
+if (!virDomainDiskSourceIsBlockType(def-src)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
_(Can't setup disk for non-block device));
 goto cleanup;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8a69976..b8af9e0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3660,7 +3660,7 @@ qemuBuildDriveDevStr(virDomainDefPtr def,

virStorageNetProtocolTypeToString(disk-src-protocol));
 goto error;
 }
-} else if (!virDomainDiskSourceIsBlockType(disk)) {
+} else if (!virDomainDiskSourceIsBlockType(disk-src)) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, %s,
_(disk device='lun' is only valid for block type 
disk source));
 goto error;
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 6bfa48e..ec665d6 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -979,7 +979,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
 disk = dev-data.disk;

-if (!disk-src-shared || !virDomainDiskSourceIsBlockType(disk))
+if (!disk-src-shared || !virDomainDiskSourceIsBlockType(disk-src))
 return 0;
 } else if (dev-type == VIR_DOMAIN_DEVICE_HOSTDEV) {
 hostdev = dev-data.hostdev;
@@ -1088,7 +1088,7 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
 if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
 disk = dev-data.disk;

-if (!disk-src-shared || !virDomainDiskSourceIsBlockType(disk))
+if 

[libvirt] [PATCH 13/14] qemu: hotplug: Sanitize shared device removal on media change

2014-08-08 Thread Peter Krempa
Instead of tediously copying of the disk source to remove it later
ensure that the media change function removes the old device after it
succeeds.
---
 src/qemu/qemu_conf.c|  2 +-
 src/qemu/qemu_conf.h|  5 
 src/qemu/qemu_driver.c  | 38 +++---
 src/qemu/qemu_hotplug.c | 62 +++--
 4 files changed, 43 insertions(+), 64 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 00405cc..6b4a497 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1097,7 +1097,7 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 }


-static int
+int
 qemuRemoveSharedDisk(virQEMUDriverPtr driver,
  virDomainDiskDefPtr disk,
  const char *name)
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 90aebef..2f60b6a 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -302,6 +302,11 @@ int qemuRemoveSharedDevice(virQEMUDriverPtr driver,
const char *name)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

+int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
+ virDomainDiskDefPtr disk,
+ const char *name)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
 int qemuSetUnprivSGIO(virDomainDeviceDefPtr dev);

 int qemuDriverAllocateID(virQEMUDriverPtr driver);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7088f19..4b1c69f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6621,9 +6621,6 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 {
 virDomainDiskDefPtr disk = dev-data.disk;
 virDomainDiskDefPtr orig_disk = NULL;
-virDomainDiskDefPtr tmp = NULL;
-virDomainDeviceDefPtr dev_copy = NULL;
-virStorageSourcePtr newsrc;
 virCapsPtr caps = NULL;
 int ret = -1;

@@ -6648,38 +6645,20 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
 goto end;

-tmp = dev-data.disk;
-dev-data.disk = orig_disk;
-
-if (!(dev_copy = virDomainDeviceDefCopy(dev, vm-def,
-caps, driver-xmlopt))) {
-dev-data.disk = tmp;
-goto end;
-}
-dev-data.disk = tmp;
-
 /* Add the new disk src into shared disk hash table */
 if (qemuAddSharedDevice(driver, dev, vm-def-name)  0)
 goto end;

-newsrc = disk-src;
-disk-src = NULL;
-
-ret = qemuDomainChangeEjectableMedia(driver, conn, vm,
- orig_disk, newsrc, force);
-/* 'disk' must not be accessed now - it has been freed.
- * 'orig_disk' now points to the new disk, while 'dev_copy'
- * now points to the old disk */
-
-/* Need to remove the shared disk entry for the original
- * disk src if the operation is either ejecting or updating.
- */
-if (ret == 0) {
-dev-data.disk = NULL;
-ignore_value(qemuRemoveSharedDevice(driver, dev_copy,
-vm-def-name));
+if (qemuDomainChangeEjectableMedia(driver, conn, vm,
+   orig_disk, dev-data.disk-src, 
force)  0) {
+ignore_value(qemuRemoveSharedDisk(driver, dev-data.disk, 
vm-def-name));
+goto end;
 }
+
+dev-data.disk-src = NULL;
+ret = 0;
 break;
+
 default:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_(disk bus '%s' cannot be updated.),
@@ -6689,7 +6668,6 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,

  end:
 virObjectUnref(caps);
-virDomainDeviceDefFree(dev_copy);
 return ret;
 }

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 39907ab..4c69c5e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -137,12 +137,29 @@ qemuDomainPrepareDisk(virQEMUDriverPtr driver,
 }


-int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
-   virConnectPtr conn,
-   virDomainObjPtr vm,
-   virDomainDiskDefPtr disk,
-   virStorageSourcePtr newsrc,
-   bool force)
+/**
+ * qemuDomainChangeEjectableMedia:
+ * @driver: qemu driver structure
+ * @conn: connection structure
+ * @vm: domain definition
+ * @disk: disk definition to change the source of
+ * @newsrc: new disk source to change to
+ * @force: force the change of media
+ *
+ * Change the media in an ejectable device to the one described by
+ * @newsrc. This function also removes the old source from the
+ * shared device table if appropriate. Note that newsrc is consumed
+ * on success and the old source is freed on success.
+ *
+ * Returns 0 on 

[libvirt] [PATCH 05/14] qemu: hotplug: Change arguments for qemuDomainChangeEjectableMedia

2014-08-08 Thread Peter Krempa
Pass the source of the changed media instead of a complete disk
definition.

Note that the @disk argument now contains what @olddisk would contain.
The new source is passed as a virStorageSource struct.
---
 src/qemu/qemu_driver.c  |  6 -
 src/qemu/qemu_hotplug.c | 71 ++---
 src/qemu/qemu_hotplug.h |  2 +-
 3 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 03fe96f..fc345d5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6623,6 +6623,7 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 virDomainDiskDefPtr orig_disk = NULL;
 virDomainDiskDefPtr tmp = NULL;
 virDomainDeviceDefPtr dev_copy = NULL;
+virStorageSourcePtr newsrc;
 virCapsPtr caps = NULL;
 int ret = -1;

@@ -6661,7 +6662,10 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 if (qemuAddSharedDevice(driver, dev, vm-def-name)  0)
 goto end;

-ret = qemuDomainChangeEjectableMedia(driver, vm, disk, orig_disk, 
force);
+newsrc = disk-src;
+disk-src = NULL;
+
+ret = qemuDomainChangeEjectableMedia(driver, vm, orig_disk, newsrc, 
force);
 /* 'disk' must not be accessed now - it has been freed.
  * 'orig_disk' now points to the new disk, while 'dev_copy'
  * now points to the old disk */
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 5894f43..9ad06be 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -140,34 +140,33 @@ qemuDomainPrepareDisk(virQEMUDriverPtr driver,
 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
-   virDomainDiskDefPtr origdisk,
+   virStorageSourcePtr newsrc,
bool force)
 {
 int ret = -1;
 char *driveAlias = NULL;
 qemuDomainObjPrivatePtr priv = vm-privateData;
 int retries = CHANGE_MEDIA_RETRIES;
-virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
-const char *src = NULL;
+const char *format = NULL;

-if (!origdisk-info.alias) {
+if (!disk-info.alias) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(missing disk device alias name for %s), 
origdisk-dst);
+   _(missing disk device alias name for %s), disk-dst);
 goto cleanup;
 }

-if (origdisk-device != VIR_DOMAIN_DISK_DEVICE_FLOPPY 
-origdisk-device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
+if (disk-device != VIR_DOMAIN_DISK_DEVICE_FLOPPY 
+disk-device != VIR_DOMAIN_DISK_DEVICE_CDROM) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
_(Removable media not supported for %s device),
virDomainDiskDeviceTypeToString(disk-device));
 goto cleanup;
 }

-if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false)  0)
+if (qemuDomainPrepareDisk(driver, vm, disk, newsrc, false)  0)
 goto cleanup;

-if (!(driveAlias = qemuDeviceDriveHostAlias(origdisk, priv-qemuCaps)))
+if (!(driveAlias = qemuDeviceDriveHostAlias(disk, priv-qemuCaps)))
 goto error;

 qemuDomainObjEnterMonitor(driver, vm);
@@ -180,7 +179,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 virObjectRef(vm);
 /* we don't want to report errors from media tray_open polling */
 while (retries) {
-if (origdisk-tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)
+if (disk-tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)
 break;

 retries--;
@@ -198,53 +197,42 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr 
driver,
 goto error;
 }

-src = virDomainDiskGetSource(disk);
-if (src) {
-/* deliberately don't depend on 'ret' as 'eject' may have failed the
- * first time and we are going to check the drive state anyway */
-const char *format = NULL;
-int type = virDomainDiskGetType(disk);
-int diskFormat = virDomainDiskGetFormat(disk);
-
-if (type != VIR_STORAGE_TYPE_DIR) {
-if (diskFormat  0) {
-format = virStorageFileFormatTypeToString(diskFormat);
+if (newsrc-path) {
+if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
+if (newsrc-format  0) {
+format = virStorageFileFormatTypeToString(newsrc-format);
 } else {
-diskFormat = virDomainDiskGetFormat(origdisk);
-if (diskFormat  0)
-format = virStorageFileFormatTypeToString(diskFormat);
+if (disk-src-format  0)
+format = 
virStorageFileFormatTypeToString(disk-src-format);
 }
 }
 qemuDomainObjEnterMonitor(driver, vm);
 ret = 

[libvirt] [PATCH 07/14] qemu: shared: Split out insertion code to the shared device list

2014-08-08 Thread Peter Krempa
To allow reuse split the code into a separate function and refactor it.
To update an existing entry there's no need to copy it first, just
update it inplace.
---
 src/qemu/qemu_conf.c | 81 
 1 file changed, 44 insertions(+), 37 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index ec665d6..ef5d0a5 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -949,6 +949,47 @@ qemuSharedDeviceEntryCopy(const qemuSharedDeviceEntry 
*entry)
 return NULL;
 }

+
+static int
+qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver,
+const char *key,
+const char *name)
+{
+qemuSharedDeviceEntry *entry = NULL;
+int ret = -1;
+
+if ((entry = virHashLookup(driver-sharedDevices, key))) {
+/* Nothing to do if the shared scsi host device is already
+ * recorded in the table.
+ */
+if (qemuSharedDeviceEntryDomainExists(entry, name, NULL)) {
+ret = 0;
+goto cleanup;
+}
+
+if (VIR_EXPAND_N(entry-domains, entry-ref, 1)  0 ||
+VIR_STRDUP(entry-domains[entry-ref - 1], name)  0)
+goto cleanup;
+} else {
+if (VIR_ALLOC(entry)  0 ||
+VIR_ALLOC_N(entry-domains, 1)  0 ||
+VIR_STRDUP(entry-domains[0], name)  0)
+goto cleanup;
+
+entry-ref = 1;
+
+if (virHashAddEntry(driver-sharedDevices, key, entry))
+goto cleanup;
+}
+
+ret = 0;
+
+ cleanup:
+qemuSharedDeviceEntryFree(entry, NULL);
+
+return ret;
+}
+
 /* qemuAddSharedDevice:
  * @driver: Pointer to qemu driver struct
  * @dev: The device def
@@ -963,8 +1004,6 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 virDomainDeviceDefPtr dev,
 const char *name)
 {
-qemuSharedDeviceEntry *entry = NULL;
-qemuSharedDeviceEntry *new_entry = NULL;
 virDomainDiskDefPtr disk = NULL;
 virDomainHostdevDefPtr hostdev = NULL;
 char *dev_name = NULL;
@@ -1016,43 +1055,11 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 goto cleanup;
 }

-if ((entry = virHashLookup(driver-sharedDevices, key))) {
-/* Nothing to do if the shared scsi host device is already
- * recorded in the table.
- */
-if (qemuSharedDeviceEntryDomainExists(entry, name, NULL)) {
-ret = 0;
-goto cleanup;
-}
-
-if (!(new_entry = qemuSharedDeviceEntryCopy(entry)))
-goto cleanup;
-
-if (VIR_EXPAND_N(new_entry-domains, new_entry-ref, 1)  0 ||
-VIR_STRDUP(new_entry-domains[new_entry-ref - 1], name)  0) {
-qemuSharedDeviceEntryFree(new_entry, NULL);
-goto cleanup;
-}
-
-if (virHashUpdateEntry(driver-sharedDevices, key, new_entry)  0) {
-qemuSharedDeviceEntryFree(new_entry, NULL);
-goto cleanup;
-}
-} else {
-if (VIR_ALLOC(entry)  0 ||
-VIR_ALLOC_N(entry-domains, 1)  0 ||
-VIR_STRDUP(entry-domains[0], name)  0) {
-qemuSharedDeviceEntryFree(entry, NULL);
-goto cleanup;
-}
-
-entry-ref = 1;
-
-if (virHashAddEntry(driver-sharedDevices, key, entry))
-goto cleanup;
-}
+if (qemuSharedDeviceEntryInsert(driver, key, name)  0)
+goto cleanup;

 ret = 0;
+
  cleanup:
 qemuDriverUnlock(driver);
 VIR_FREE(dev_name);
-- 
2.0.2

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


[libvirt] [PATCH 10/14] qemu: conf: Split up qemuAddSharedDevice into per-device-type functions

2014-08-08 Thread Peter Krempa
Adding a shared device needs special steps for disks and hostdevs.
Instead of having one function dealing this split the code into two
separate functions that can be used with better granularity.
---
 src/qemu/qemu_conf.c | 125 ---
 1 file changed, 79 insertions(+), 46 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 5efabfb..7af3c5c 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -951,71 +951,78 @@ qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver,
 return ret;
 }

-/* qemuAddSharedDevice:
+
+/* qemuAddSharedDisk:
  * @driver: Pointer to qemu driver struct
- * @dev: The device def
+ * @src: disk source
  * @name: The domain name
  *
  * Increase ref count and add the domain name into the list which
  * records all the domains that use the shared device if the entry
  * already exists, otherwise add a new entry.
  */
-int
-qemuAddSharedDevice(virQEMUDriverPtr driver,
-virDomainDeviceDefPtr dev,
-const char *name)
+static int
+qemuAddSharedDisk(virQEMUDriverPtr driver,
+  virDomainDiskDefPtr disk,
+  const char *name)
 {
-virDomainDiskDefPtr disk = NULL;
-virDomainHostdevDefPtr hostdev = NULL;
-char *dev_name = NULL;
-char *dev_path = NULL;
 char *key = NULL;
 int ret = -1;

-/* Currently the only conflicts we have to care about for
- * the shared disk and shared host device is sgio setting,
- * which is only valid for block disk and scsi host device.
- */
-if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
-disk = dev-data.disk;
+if (!disk-src-shared || !virDomainDiskSourceIsBlockType(disk-src))
+return 0;

-if (!disk-src-shared || !virDomainDiskSourceIsBlockType(disk-src))
-return 0;
-} else if (dev-type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-hostdev = dev-data.hostdev;
+qemuDriverLock(driver);

-if (!hostdev-shareable ||
-!(hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
-  hostdev-source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
-return 0;
-} else {
+if (qemuCheckSharedDisk(driver-sharedDevices, disk)  0)
+goto cleanup;
+
+if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk
+goto cleanup;
+
+if (qemuSharedDeviceEntryInsert(driver, key, name)  0)
+goto cleanup;
+
+ret = 0;
+
+ cleanup:
+qemuDriverUnlock(driver);
+VIR_FREE(key);
+return ret;
+}
+
+
+static int
+qemuAddSharedHostdev(virQEMUDriverPtr driver,
+ virDomainHostdevDefPtr hostdev,
+ const char *name)
+{
+virDomainHostdevSubsysSCSIPtr scsisrc = hostdev-source.subsys.u.scsi;
+virDomainHostdevSubsysSCSIHostPtr scsihostsrc = scsisrc-u.host;
+char *dev_name = NULL;
+char *dev_path = NULL;
+char *key = NULL;
+int ret = -1;
+
+if (!hostdev-shareable ||
+!(hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
+  hostdev-source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
 return 0;
-}

 qemuDriverLock(driver);

-if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
-if (qemuCheckSharedDisk(driver-sharedDevices, disk)  0)
-goto cleanup;
-
-if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk
-goto cleanup;
-} else {
-virDomainHostdevSubsysSCSIPtr scsisrc = hostdev-source.subsys.u.scsi;
-virDomainHostdevSubsysSCSIHostPtr scsihostsrc = scsisrc-u.host;
-if (!(dev_name = virSCSIDeviceGetDevName(NULL,
- scsihostsrc-adapter,
- scsihostsrc-bus,
- scsihostsrc-target,
- scsihostsrc-unit)))
-goto cleanup;
+if (!(dev_name = virSCSIDeviceGetDevName(NULL,
+ scsihostsrc-adapter,
+ scsihostsrc-bus,
+ scsihostsrc-target,
+ scsihostsrc-unit)))
+goto cleanup;

-if (virAsprintf(dev_path, /dev/%s, dev_name)  0)
-goto cleanup;
+if (virAsprintf(dev_path, /dev/%s, dev_name)  0)
+goto cleanup;

-if (!(key = qemuGetSharedDeviceKey(dev_path)))
-goto cleanup;
-}
+if (!(key = qemuGetSharedDeviceKey(dev_path)))
+goto cleanup;

 if (qemuSharedDeviceEntryInsert(driver, key, name)  0)
 goto cleanup;
@@ -1055,6 +1062,32 @@ qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
 }


+/* qemuAddSharedDevice:
+ * @driver: Pointer to qemu driver struct
+ * @dev: The device def
+ * @name: The domain name
+ *
+ * Increase ref count and add the domain name into the list which
+ * 

[libvirt] [PATCH 08/14] qemu: shared: Split out shared device list remove code

2014-08-08 Thread Peter Krempa
Split it out into a separate function and simplify the code. There's no
need to copy the entry to update it as the hash returns pointer to the
existing item.

Also remove the now unused qemuSharedDeviceEntryCopy function.
---
 src/qemu/qemu_conf.c | 77 ++--
 1 file changed, 26 insertions(+), 51 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index ef5d0a5..79f8df8 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -924,31 +924,6 @@ qemuSharedDeviceEntryFree(void *payload, const void *name 
ATTRIBUTE_UNUSED)
 VIR_FREE(entry);
 }

-static qemuSharedDeviceEntryPtr
-qemuSharedDeviceEntryCopy(const qemuSharedDeviceEntry *entry)
-{
-qemuSharedDeviceEntryPtr ret = NULL;
-size_t i;
-
-if (VIR_ALLOC(ret)  0)
-return NULL;
-
-if (VIR_ALLOC_N(ret-domains, entry-ref)  0)
-goto cleanup;
-
-for (i = 0; i  entry-ref; i++) {
-if (VIR_STRDUP(ret-domains[i], entry-domains[i])  0)
-goto cleanup;
-ret-ref++;
-}
-
-return ret;
-
- cleanup:
-qemuSharedDeviceEntryFree(ret, NULL);
-return NULL;
-}
-

 static int
 qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver,
@@ -1068,6 +1043,31 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 return ret;
 }

+
+static int
+qemuSharedDeviceEntryRemove(virQEMUDriverPtr driver,
+const char *key,
+const char *name)
+{
+qemuSharedDeviceEntryPtr entry = NULL;
+int idx;
+
+if (!(entry = virHashLookup(driver-sharedDevices, key)))
+return -1;
+
+/* Nothing to do if the shared disk is not recored in the table. */
+if (!qemuSharedDeviceEntryDomainExists(entry, name, idx))
+return 0;
+
+if (entry-ref != 1)
+VIR_DELETE_ELEMENT(entry-domains, idx, entry-ref);
+else
+ignore_value(virHashRemoveEntry(driver-sharedDevices, key));
+
+return 0;
+}
+
+
 /* qemuRemoveSharedDevice:
  * @driver: Pointer to qemu driver struct
  * @device: The device def
@@ -1082,15 +1082,12 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
virDomainDeviceDefPtr dev,
const char *name)
 {
-qemuSharedDeviceEntryPtr entry = NULL;
-qemuSharedDeviceEntryPtr new_entry = NULL;
 virDomainDiskDefPtr disk = NULL;
 virDomainHostdevDefPtr hostdev = NULL;
 char *key = NULL;
 char *dev_name = NULL;
 char *dev_path = NULL;
 int ret = -1;
-int idx;

 if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
 disk = dev-data.disk;
@@ -1130,31 +1127,9 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
 goto cleanup;
 }

-if (!(entry = virHashLookup(driver-sharedDevices, key)))
+if (qemuSharedDeviceEntryRemove(driver, key, name)  0)
 goto cleanup;

-/* Nothing to do if the shared disk is not recored in
- * the table.
- */
-if (!qemuSharedDeviceEntryDomainExists(entry, name, idx)) {
-ret = 0;
-goto cleanup;
-}
-
-if (entry-ref != 1) {
-if (!(new_entry = qemuSharedDeviceEntryCopy(entry)))
-goto cleanup;
-
-VIR_DELETE_ELEMENT(new_entry-domains, idx, new_entry-ref);
-if (virHashUpdateEntry(driver-sharedDevices, key, new_entry)  0){
-qemuSharedDeviceEntryFree(new_entry, NULL);
-goto cleanup;
-}
-} else {
-if (virHashRemoveEntry(driver-sharedDevices, key)  0)
-goto cleanup;
-}
-
 ret = 0;
  cleanup:
 qemuDriverUnlock(driver);
-- 
2.0.2

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


[libvirt] [PATCH 03/14] qemu: hotplug: Untangle cleanup paths in qemuDomainChangeEjectableMedia

2014-08-08 Thread Peter Krempa
Avoid the audit label to simplify control flow.
---
 src/qemu/qemu_hotplug.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f6e98b4..0ad467e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -107,7 +107,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 qemuDomainObjExitMonitor(driver, vm);

 if (ret  0)
-goto audit;
+goto error;

 virObjectRef(vm);
 /* we don't want to report errors from media tray_open polling */
@@ -127,7 +127,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 virReportError(VIR_ERR_OPERATION_FAILED, %s,
_(Unable to eject media));
 ret = -1;
-goto audit;
+goto error;
 }

 src = virDomainDiskGetSource(disk);
@@ -153,7 +153,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
  src, format);
 qemuDomainObjExitMonitor(driver, vm);
 }
- audit:
+
 virDomainAuditDisk(vm, origdisk-src, disk-src, update, ret = 0);

 if (ret  0)
@@ -180,6 +180,8 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 return ret;

  error:
+virDomainAuditDisk(vm, origdisk-src, disk-src, update, false);
+
 if (virSecurityManagerRestoreDiskLabel(driver-securityManager,
vm-def, disk)  0)
 VIR_WARN(Unable to restore security label on new media %s, src);
-- 
2.0.2

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


[libvirt] [PATCH 12/14] qemu: conf: Split out code to retrieve hostdev key and reuse it

2014-08-08 Thread Peter Krempa
Both addition and removal of a shared hostdev share the code to generate
the hostdev key. Split it out into a separate function and refactor
them.
---
 src/qemu/qemu_conf.c | 76 ++--
 1 file changed, 32 insertions(+), 44 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index f6a3b8d..00405cc 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -992,24 +992,14 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
 }


-static int
-qemuAddSharedHostdev(virQEMUDriverPtr driver,
- virDomainHostdevDefPtr hostdev,
- const char *name)
+static char *
+qemuGetSharedHostdevKey(virDomainHostdevDefPtr hostdev)
 {
 virDomainHostdevSubsysSCSIPtr scsisrc = hostdev-source.subsys.u.scsi;
 virDomainHostdevSubsysSCSIHostPtr scsihostsrc = scsisrc-u.host;
 char *dev_name = NULL;
 char *dev_path = NULL;
 char *key = NULL;
-int ret = -1;
-
-if (!hostdev-shareable ||
-!(hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
-  hostdev-source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
-return 0;
-
-qemuDriverLock(driver);

 if (!(dev_name = virSCSIDeviceGetDevName(NULL,
  scsihostsrc-adapter,
@@ -1024,15 +1014,33 @@ qemuAddSharedHostdev(virQEMUDriverPtr driver,
 if (!(key = qemuGetSharedDeviceKey(dev_path)))
 goto cleanup;

-if (qemuSharedDeviceEntryInsert(driver, key, name)  0)
-goto cleanup;
-
-ret = 0;
-
  cleanup:
-qemuDriverUnlock(driver);
 VIR_FREE(dev_name);
 VIR_FREE(dev_path);
+
+return key;
+}
+
+static int
+qemuAddSharedHostdev(virQEMUDriverPtr driver,
+ virDomainHostdevDefPtr hostdev,
+ const char *name)
+{
+char *key = NULL;
+int ret = -1;
+
+if (!hostdev-shareable ||
+!(hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
+  hostdev-source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
+return 0;
+
+if (!(key = qemuGetSharedHostdevKey(hostdev)))
+return -1;
+
+qemuDriverLock(driver);
+ret = qemuSharedDeviceEntryInsert(driver, key, name);
+qemuDriverUnlock(driver);
+
 VIR_FREE(key);
 return ret;
 }
@@ -1121,41 +1129,21 @@ qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
 virDomainHostdevDefPtr hostdev,
 const char *name)
 {
-virDomainHostdevSubsysSCSIPtr scsisrc = hostdev-source.subsys.u.scsi;
-virDomainHostdevSubsysSCSIHostPtr scsihostsrc = scsisrc-u.host;
 char *key = NULL;
-char *dev_name = NULL;
-char *dev_path = NULL;
-int ret = -1;
+int ret;

 if (!hostdev-shareable ||
 !(hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
   hostdev-source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
 return 0;

-qemuDriverLock(driver);
-
-if (!(dev_name = virSCSIDeviceGetDevName(NULL,
- scsihostsrc-adapter,
- scsihostsrc-bus,
- scsihostsrc-target,
- scsihostsrc-unit)))
-goto cleanup;
-
-if (virAsprintf(dev_path, /dev/%s, dev_name)  0)
-goto cleanup;
-
-if (!(key = qemuGetSharedDeviceKey(dev_path)))
-goto cleanup;
-
-if (qemuSharedDeviceEntryRemove(driver, key, name)  0)
-goto cleanup;
+if (!(key = qemuGetSharedHostdevKey(hostdev)))
+return -1;

-ret = 0;
- cleanup:
+qemuDriverLock(driver);
+ret = qemuSharedDeviceEntryRemove(driver, key, name);
 qemuDriverUnlock(driver);
-VIR_FREE(dev_name);
-VIR_FREE(dev_path);
+
 VIR_FREE(key);
 return ret;
 }
-- 
2.0.2

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


[libvirt] [PATCH 11/14] qemu: conf: Split up qemuRemoveSharedDevice into per-device-type functions

2014-08-08 Thread Peter Krempa
Removing a shared device needs special steps for disks and hostdevs.
Instead of having one function dealing this split the code into two
separate functions that can be used with better granularity.
---
 src/qemu/qemu_conf.c | 117 +++
 1 file changed, 71 insertions(+), 46 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 7af3c5c..f6a3b8d 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1088,64 +1088,65 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 return 0;
 }

-/* qemuRemoveSharedDevice:
- * @driver: Pointer to qemu driver struct
- * @device: The device def
- * @name: The domain name
- *
- * Decrease ref count and remove the domain name from the list which
- * records all the domains that use the shared device if ref is not
- * 1, otherwise remove the entry.
- */
-int
-qemuRemoveSharedDevice(virQEMUDriverPtr driver,
-   virDomainDeviceDefPtr dev,
-   const char *name)
+
+static int
+qemuRemoveSharedDisk(virQEMUDriverPtr driver,
+ virDomainDiskDefPtr disk,
+ const char *name)
 {
-virDomainDiskDefPtr disk = NULL;
-virDomainHostdevDefPtr hostdev = NULL;
 char *key = NULL;
-char *dev_name = NULL;
-char *dev_path = NULL;
 int ret = -1;

-if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
-disk = dev-data.disk;
+if (!disk-src-shared || !virDomainDiskSourceIsBlockType(disk-src))
+return 0;

-if (!disk-src-shared || !virDomainDiskSourceIsBlockType(disk-src))
-return 0;
-} else if (dev-type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-hostdev = dev-data.hostdev;
+qemuDriverLock(driver);

-if (!hostdev-shareable ||
-!(hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
-  hostdev-source.subsys.type == 
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
-return 0;
-} else {
+if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk
+goto cleanup;
+
+if (qemuSharedDeviceEntryRemove(driver, key, name)  0)
+goto cleanup;
+
+ret = 0;
+ cleanup:
+qemuDriverUnlock(driver);
+VIR_FREE(key);
+return ret;
+}
+
+
+static int
+qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
+virDomainHostdevDefPtr hostdev,
+const char *name)
+{
+virDomainHostdevSubsysSCSIPtr scsisrc = hostdev-source.subsys.u.scsi;
+virDomainHostdevSubsysSCSIHostPtr scsihostsrc = scsisrc-u.host;
+char *key = NULL;
+char *dev_name = NULL;
+char *dev_path = NULL;
+int ret = -1;
+
+if (!hostdev-shareable ||
+!(hostdev-mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS 
+  hostdev-source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
 return 0;
-}

 qemuDriverLock(driver);

-if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
-if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk
-goto cleanup;
-} else {
-virDomainHostdevSubsysSCSIPtr scsisrc = hostdev-source.subsys.u.scsi;
-virDomainHostdevSubsysSCSIHostPtr scsihostsrc = scsisrc-u.host;
-if (!(dev_name = virSCSIDeviceGetDevName(NULL,
- scsihostsrc-adapter,
- scsihostsrc-bus,
- scsihostsrc-target,
- scsihostsrc-unit)))
-goto cleanup;
+if (!(dev_name = virSCSIDeviceGetDevName(NULL,
+ scsihostsrc-adapter,
+ scsihostsrc-bus,
+ scsihostsrc-target,
+ scsihostsrc-unit)))
+goto cleanup;

-if (virAsprintf(dev_path, /dev/%s, dev_name)  0)
-goto cleanup;
+if (virAsprintf(dev_path, /dev/%s, dev_name)  0)
+goto cleanup;

-if (!(key = qemuGetSharedDeviceKey(dev_path)))
-goto cleanup;
-}
+if (!(key = qemuGetSharedDeviceKey(dev_path)))
+goto cleanup;

 if (qemuSharedDeviceEntryRemove(driver, key, name)  0)
 goto cleanup;
@@ -1159,6 +1160,30 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
 return ret;
 }

+
+/* qemuRemoveSharedDevice:
+ * @driver: Pointer to qemu driver struct
+ * @device: The device def
+ * @name: The domain name
+ *
+ * Decrease ref count and remove the domain name from the list which
+ * records all the domains that use the shared device if ref is not
+ * 1, otherwise remove the entry.
+ */
+int
+qemuRemoveSharedDevice(virQEMUDriverPtr driver,
+   virDomainDeviceDefPtr dev,
+   const char *name)
+{
+if (dev-type == VIR_DOMAIN_DEVICE_DISK)
+return qemuRemoveSharedDisk(driver, dev-data.disk, name);
+else if 

[libvirt] [PATCH 06/14] qemu: hotplug: Format proper source string for cdrom media change

2014-08-08 Thread Peter Krempa
Use the qemu source string formatter to format the source string
correctly for remote and other storage instead of passing source-path
blindly.
---
 src/qemu/qemu_driver.c  |  3 ++-
 src/qemu/qemu_hotplug.c | 12 +---
 src/qemu/qemu_hotplug.h |  1 +
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index fc345d5..7088f19 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6665,7 +6665,8 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 newsrc = disk-src;
 disk-src = NULL;

-ret = qemuDomainChangeEjectableMedia(driver, vm, orig_disk, newsrc, 
force);
+ret = qemuDomainChangeEjectableMedia(driver, conn, vm,
+ orig_disk, newsrc, force);
 /* 'disk' must not be accessed now - it has been freed.
  * 'orig_disk' now points to the new disk, while 'dev_copy'
  * now points to the old disk */
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 9ad06be..39907ab 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -138,6 +138,7 @@ qemuDomainPrepareDisk(virQEMUDriverPtr driver,


 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
+   virConnectPtr conn,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
virStorageSourcePtr newsrc,
@@ -148,6 +149,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 qemuDomainObjPrivatePtr priv = vm-privateData;
 int retries = CHANGE_MEDIA_RETRIES;
 const char *format = NULL;
+char *sourcestr = NULL;

 if (!disk-info.alias) {
 virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -197,7 +199,10 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 goto error;
 }

-if (newsrc-path) {
+if (!virStorageSourceIsLocalStorage(newsrc) || newsrc-path) {
+if (qemuGetDriveSourceString(newsrc, conn, sourcestr)  0)
+goto error;
+
 if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR) {
 if (newsrc-format  0) {
 format = virStorageFileFormatTypeToString(newsrc-format);
@@ -209,7 +214,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 qemuDomainObjEnterMonitor(driver, vm);
 ret = qemuMonitorChangeMedia(priv-mon,
  driveAlias,
- newsrc-path,
+ sourcestr,
  format);
 qemuDomainObjExitMonitor(driver, vm);
 }
@@ -228,6 +233,7 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
  cleanup:
 virStorageSourceFree(newsrc);
 VIR_FREE(driveAlias);
+VIR_FREE(sourcestr);
 return ret;

  error:
@@ -791,7 +797,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
 newsrc = disk-src;
 disk-src = NULL;

-ret = qemuDomainChangeEjectableMedia(driver, vm, orig_disk, newsrc, 
false);
+ret = qemuDomainChangeEjectableMedia(driver, conn, vm, orig_disk, 
newsrc, false);
 /* 'newsrc' must not be accessed now - it has been free'd.
  * 'orig_disk' now points to the new disk, while 'dev_copy'
  * now points to the old disk */
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 5ce8f0a..1200e44 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -29,6 +29,7 @@
 # include domain_conf.h

 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
+   virConnectPtr conn,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
virStorageSourcePtr newsrc,
-- 
2.0.2

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


[libvirt] [PATCH 09/14] qemu: conf: rename qemuCheckSharedDevice to qemuCheckSharedDisk

2014-08-08 Thread Peter Krempa
The qemuCheckSharedDevice function is operating only on disk devices.
Rename it and change the arguments to reflect that and refactor some
logic for more readability.
---
 src/qemu/qemu_conf.c | 89 ++--
 1 file changed, 38 insertions(+), 51 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 79f8df8..5efabfb 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -814,82 +814,68 @@ qemuGetSharedDeviceKey(const char *device_path)
  * Returns 0 if no conflicts, otherwise returns -1.
  */
 static int
-qemuCheckSharedDevice(virHashTablePtr sharedDevices,
-  virDomainDeviceDefPtr dev)
+qemuCheckSharedDisk(virHashTablePtr sharedDevices,
+virDomainDiskDefPtr disk)
 {
-virDomainDiskDefPtr disk = NULL;
 char *sysfs_path = NULL;
 char *key = NULL;
 int val;
-int ret = 0;
-const char *src;
-
-if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
-disk = dev-data.disk;
+int ret = -1;

-/* The only conflicts between shared disk we care about now
- * is sgio setting, which is only valid for device='lun'.
- */
-if (disk-device != VIR_DOMAIN_DISK_DEVICE_LUN)
-return 0;
-} else {
+if (disk-device != VIR_DOMAIN_DISK_DEVICE_LUN)
 return 0;
-}
-
-src = virDomainDiskGetSource(disk);
-if (!(sysfs_path = virGetUnprivSGIOSysfsPath(src, NULL))) {
-ret = -1;
-goto cleanup;
-}

-/* It can't be conflict if unpriv_sgio is not supported
- * by kernel.
- */
-if (!virFileExists(sysfs_path))
+if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk-src-path, NULL)))
 goto cleanup;

-if (!(key = qemuGetSharedDeviceKey(src))) {
-ret = -1;
+/* It can't be conflict if unpriv_sgio is not supported by kernel. */
+if (!virFileExists(sysfs_path)) {
+ret = 0;
 goto cleanup;
 }

-/* It can't be conflict if no other domain is
- * is sharing it.
- */
-if (!(virHashLookup(sharedDevices, key)))
+if (!(key = qemuGetSharedDeviceKey(disk-src-path)))
 goto cleanup;

-if (virGetDeviceUnprivSGIO(src, NULL, val)  0) {
-ret = -1;
+/* It can't be conflict if no other domain is sharing it. */
+if (!(virHashLookup(sharedDevices, key))) {
+ret = 0;
 goto cleanup;
 }

-if ((val == 0 
- (disk-sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
-  disk-sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
-(val == 1 
- disk-sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))
+if (virGetDeviceUnprivSGIO(disk-src-path, NULL, val)  0)
 goto cleanup;

-if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
-virReportError(VIR_ERR_OPERATION_INVALID,
-   _(sgio of shared disk 'pool=%s' 'volume=%s' conflicts 
- with other active domains),
-   disk-src-srcpool-pool,
-   disk-src-srcpool-volume);
-} else {
-virReportError(VIR_ERR_OPERATION_INVALID,
-   _(sgio of shared disk '%s' conflicts with other 
- active domains), src);
+if (!((val == 0 
+   (disk-sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
+disk-sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
+  (val == 1 
+   disk-sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
+
+if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _(sgio of shared disk 'pool=%s' 'volume=%s' 
conflicts 
+ with other active domains),
+   disk-src-srcpool-pool,
+   disk-src-srcpool-volume);
+} else {
+virReportError(VIR_ERR_OPERATION_INVALID,
+   _(sgio of shared disk '%s' conflicts with other 
+ active domains), disk-src-path);
+}
+
+goto cleanup;
 }

-ret = -1;
+ret = 0;
+
  cleanup:
 VIR_FREE(sysfs_path);
 VIR_FREE(key);
 return ret;
 }

+
 bool
 qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
   const char *name,
@@ -1007,10 +993,11 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
 }

 qemuDriverLock(driver);
-if (qemuCheckSharedDevice(driver-sharedDevices, dev)  0)
-goto cleanup;

 if (dev-type == VIR_DOMAIN_DEVICE_DISK) {
+if (qemuCheckSharedDisk(driver-sharedDevices, disk)  0)
+goto cleanup;
+
 if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk
 goto cleanup;
 } else {
-- 
2.0.2

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


[libvirt] new libvirt-python release for pypi needed (1.2.7)

2014-08-08 Thread Thomas Bechtold
Hi,

I'm using libvirt 1.2.7 and when I try to install libvirt-python via
pypi, I get an error [1]. Please release a new version (1.2.7) on pypi.

TIA,

Tom

[1] http://paste.openstack.org/show/91904/

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


[libvirt] [PATCH 01/14] qemu: Explicitly state that hotplugging cdroms and floppies doesn't work

2014-08-08 Thread Peter Krempa
---
 src/qemu/qemu_hotplug.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 004b6a4..f6e98b4 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -743,7 +743,9 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
 if (!(orig_disk = virDomainDiskFindByBusAndDst(vm-def,
disk-bus, disk-dst))) 
{
 virReportError(VIR_ERR_INTERNAL_ERROR,
-   _(No device with bus '%s' and target '%s'),
+   _(No device with bus '%s' and target '%s'. 
+ cdrom and floppy device hotplug isn't supported 
+ by libvirt),
virDomainDiskBusTypeToString(disk-bus),
disk-dst);
 goto end;
-- 
2.0.2

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


[libvirt] [PATCH 04/14] qemu: hotplug: Add helper to initialize/teardown new disks for VMs

2014-08-08 Thread Peter Krempa
When we are changing media (or doing other hotplug operations) we need
to setup cgroups, locking and seclabels on the new disk. This is a
multi-step process where every piece can fail. To simplify dealing with
this introduce qemuDomainPrepareDisk that similarly to
qemuDomainPrepareDiskChainElement initializes/tears down  a whole new
disk to be used with the domain.

Additionally the function supports passing a different source struct for
media changes of cdroms that will be refactored later.
---
 src/qemu/qemu_driver.c  |   8 ---
 src/qemu/qemu_hotplug.c | 144 
 2 files changed, 85 insertions(+), 67 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 82a82aa..03fe96f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6632,9 +6632,6 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 if (qemuDomainDetermineDiskChain(driver, vm, disk, false)  0)
 goto end;

-if (qemuSetupDiskCgroup(vm, disk)  0)
-goto end;
-
 switch (disk-device) {
 case VIR_DOMAIN_DISK_DEVICE_CDROM:
 case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
@@ -6685,11 +6682,6 @@ qemuDomainChangeDiskMediaLive(virConnectPtr conn,
 break;
 }

-if (ret != 0 
-qemuTeardownDiskCgroup(vm, disk)  0)
-VIR_WARN(Failed to teardown cgroup for disk path %s,
- NULLSTR(virDomainDiskGetSource(disk)));
-
  end:
 virObjectUnref(caps);
 virDomainDeviceDefFree(dev_copy);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0ad467e..5894f43 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -60,6 +60,83 @@ VIR_LOG_INIT(qemu.qemu_hotplug);
 unsigned long long qemuDomainRemoveDeviceWaitTime = 1000ull * 5;


+/**
+ * qemuDomainPrepareDisk:
+ * @driver: qemu driver struct
+ * @vm: domain object
+ * @disk: disk to prepare
+ * @overridesrc: Source different than @disk-src when necessary
+ * @teardown: Teardown the disk instead of adding it to a vm
+ *
+ * Setup the locks, cgroups and security permissions on a disk of a VM.
+ * If @overridesrc is specified the source struct is used instead of the
+ * one present in @disk. If @teardown is true, then the labels and cgroups
+ * are removed instead.
+ *
+ * Returns 0 on success and -1 on error. Reports libvirt error.
+ */
+static int
+qemuDomainPrepareDisk(virQEMUDriverPtr driver,
+  virDomainObjPtr vm,
+  virDomainDiskDefPtr disk,
+  virStorageSourcePtr overridesrc,
+  bool teardown)
+{
+virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+int ret = -1;
+virStorageSourcePtr origsrc = NULL;
+
+if (overridesrc) {
+origsrc = disk-src;
+disk-src = overridesrc;
+}
+
+/* just tear down the disk access */
+if (teardown) {
+ret = 0;
+goto rollback_cgroup;
+}
+
+if (virDomainLockDiskAttach(driver-lockManager, cfg-uri,
+vm, disk)  0)
+goto cleanup;
+
+if (virSecurityManagerSetDiskLabel(driver-securityManager,
+   vm-def, disk)  0)
+goto rollback_lock;
+
+if (qemuSetupDiskCgroup(vm, disk)  0)
+goto rollback_label;
+
+ret = 0;
+goto cleanup;
+
+ rollback_cgroup:
+if (qemuTeardownDiskCgroup(vm, disk)  0)
+VIR_WARN(Unable to tear down cgroup access on %s,
+ virDomainDiskGetSource(disk));
+
+ rollback_label:
+if (virSecurityManagerRestoreDiskLabel(driver-securityManager,
+   vm-def, disk)  0)
+VIR_WARN(Unable to restore security label on %s,
+ virDomainDiskGetSource(disk));
+
+ rollback_lock:
+if (virDomainLockDiskDetach(driver-lockManager, vm, disk)  0)
+VIR_WARN(Unable to release lock on %s,
+ virDomainDiskGetSource(disk));
+
+ cleanup:
+if (origsrc)
+disk-src = origsrc;
+
+virObjectUnref(cfg);
+
+return ret;
+}
+
+
 int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainDiskDefPtr disk,
@@ -87,17 +164,8 @@ int qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
 goto cleanup;
 }

-if (virDomainLockDiskAttach(driver-lockManager, cfg-uri,
-vm, disk)  0)
-goto cleanup;
-
-if (virSecurityManagerSetDiskLabel(driver-securityManager,
-   vm-def, disk)  0) {
-if (virDomainLockDiskDetach(driver-lockManager, vm, disk)  0)
-VIR_WARN(Unable to release lock on %s,
- virDomainDiskGetSource(disk));
+if (qemuDomainPrepareDisk(driver, vm, disk, NULL, false)  0)
 goto cleanup;
-}

 if (!(driveAlias = qemuDeviceDriveHostAlias(origdisk, priv-qemuCaps)))
 goto error;
@@ -159,14 

[libvirt] [PATCH 4/4] GVirDomain: Add _get_has_current_snapshot

2014-08-08 Thread Timm Bäder
... which uses virDomainHasCurrentSnapshot to determine if the given
domain has a current snapshot or not.
---
 libvirt-gobject/libvirt-gobject-domain.c | 34 
 libvirt-gobject/libvirt-gobject-domain.h |  4 
 libvirt-gobject/libvirt-gobject.sym  |  1 +
 3 files changed, 39 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
b/libvirt-gobject/libvirt-gobject-domain.c
index 5399892..feac6f0 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -1686,3 +1686,37 @@ gboolean gvir_domain_fetch_snapshots_finish(GVirDomain 
*dom,
 
 return g_task_propagate_boolean(G_TASK(res), error);
 }
+
+
+/**
+ * gvir_domain_get_has_current_snapshot:
+ * @dom: a #GVirDomain
+ * @flags: Unused, pass 0
+ * @has_current_snapshot: (out): Will be set to %TRUE if the given domain
+ * has a current snapshot and to %FALSE otherwise.
+ * @error: (allow-none): Place-holder for error or %NULL
+ *
+ * Returns: %TRUE on success, %FALSE otherwise.
+ */
+gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom,
+  guint flags,
+  gboolean *has_current_snapshot,
+  GError **error) {
+int status;
+g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
+
+status = virDomainHasCurrentSnapshot(dom-priv-handle,
+ flags);
+
+if (status == -1) {
+gvir_set_error(error, GVIR_DOMAIN_ERROR, 0,
+   Unable to check if domain `%s' has a current snapshot,
+   gvir_domain_get_name(dom));
+return FALSE;
+}
+
+*has_current_snapshot = status;
+
+return TRUE;
+}
diff --git a/libvirt-gobject/libvirt-gobject-domain.h 
b/libvirt-gobject/libvirt-gobject-domain.h
index 9846375..56c80b8 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -380,6 +380,10 @@ gboolean gvir_domain_fetch_snapshots_finish(GVirDomain 
*dom,
 GAsyncResult *res,
 GError **error);
 
+gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom,
+  guint flags,
+  gboolean *has_current_snapshot,
+  GError **error);
 
 G_END_DECLS
 
diff --git a/libvirt-gobject/libvirt-gobject.sym 
b/libvirt-gobject/libvirt-gobject.sym
index bd12239..68e9b58 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -240,6 +240,7 @@ LIBVIRT_GOBJECT_0.1.9 {
gvir_domain_fetch_snapshots_async;
gvir_domain_fetch_snapshots_finish;
gvir_domain_get_snapshots;
+   gvir_domain_get_has_current_snapshot;
gvir_domain_snapshot_delete;
gvir_domain_snapshot_delete_flags_get_type;
gvir_domain_snapshot_get_is_current;
-- 
2.0.4

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


Re: [libvirt] [PATCH 3/4] vol-info: Check for NFS FS type

2014-08-08 Thread John Ferlan


On 08/08/2014 07:07 AM, Ján Tomko wrote:
 On 08/05/2014 04:38 PM, John Ferlan wrote:
 https://bugzilla.redhat.com/show_bug.cgi?id=1077068

 Check for the NFS FS type being true for a local stat of the file
 to force usage of the 'st_size' value rather than calculating the size
 using the 'st_blocks' and 'st_blksize'.  As described in the stat(2)
 man page:

 Use of the st_blocks and st_blksize fields may be less portable.

 experimentation shows a 10M file could get the following output from stat:

   st_size=10485760 st_blocks=88 st_blksize=1048576

 resulting in a 44 KiB value being displayed as the allocation value.
 While this value does match the du -s value of the same file, the
 du -b value shows the st_size field. Similarly a long listing of the
 file shows the 10M size.
 
 Capacity should be the apparent size (what du -b shows, or st_size), while
 allocation should track the on-disk usage (du, st_blocks * 512).
 
 It looks to me that the values are correct, it's just that posix_fallocate
 does neither work nor fail on NFS.
 
 Jan
 

Testing seems to indicate that posix_fallocate() either doesn't work as
expected on the target or using the target.path is incorrect...

Before posix_fallocate
stat st_blocks=0 st_blksize=1048576 st_size=10485760
lseek end=10485760

posix_fallocate of 10485760 bytes on /home/nfs_pool/target/test-vol1

After posix_fallocate
stat st_blocks=88 st_blksize=1048576 st_size=10485760
lseek end=10485760


Hmm... would going at the target be correct in this instance?  Same test
but use the source path:

Before posix_fallocate
stat st_blocks=0 st_blksize=4096 st_size=10485760
lseek end=10485760

posix_fallocate of 10485760 bytes on /home/nfs_pool/nfs-export/test-vol1

After posix_fallocate
stat st_blocks=20480 st_blksize=4096 st_size=10485760
lseek end=10485760

...

hmm 20480 * 512 = 10485760

# df
...
localhost:/home/nfs_pool/nfs-export 140979200 35521536  98273280  27%
/home/nfs_pool/target
#


John


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


Re: [libvirt] [PATCH 4/4] GVirDomain: Add _get_has_current_snapshot

2014-08-08 Thread Christophe Fergeau
On Fri, Aug 08, 2014 at 05:07:32PM +0200, Timm Bäder wrote:
 ... which uses virDomainHasCurrentSnapshot to determine if the given
 domain has a current snapshot or not.
 ---
  libvirt-gobject/libvirt-gobject-domain.c | 34 
 
  libvirt-gobject/libvirt-gobject-domain.h |  4 
  libvirt-gobject/libvirt-gobject.sym  |  1 +
  3 files changed, 39 insertions(+)
 
 diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
 b/libvirt-gobject/libvirt-gobject-domain.c
 index 5399892..feac6f0 100644
 --- a/libvirt-gobject/libvirt-gobject-domain.c
 +++ b/libvirt-gobject/libvirt-gobject-domain.c
 @@ -1686,3 +1686,37 @@ gboolean gvir_domain_fetch_snapshots_finish(GVirDomain 
 *dom,
  
  return g_task_propagate_boolean(G_TASK(res), error);
  }
 +
 +
 +/**
 + * gvir_domain_get_has_current_snapshot:
 + * @dom: a #GVirDomain
 + * @flags: Unused, pass 0
 + * @has_current_snapshot: (out): Will be set to %TRUE if the given domain
 + * has a current snapshot and to %FALSE otherwise.
 + * @error: (allow-none): Place-holder for error or %NULL
 + *
 + * Returns: %TRUE on success, %FALSE otherwise.
 + */
 +gboolean gvir_domain_get_has_current_snapshot(GVirDomain *dom,
 +  guint flags,
 +  gboolean *has_current_snapshot,
 +  GError **error) {
 +int status;
 +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
 +g_return_val_if_fail(error == NULL || *error == NULL, FALSE);


We could also have a g_return_if_fail(has_current_snapshot != NULL);

ACK!

Christophe


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

Re: [libvirt] Lifecycle events during reboot for KVM and Xen

2014-08-08 Thread Jim Fehlig
Thomas Bechtold wrote:
 Hi,

 during debugging a problem[1] of Openstack Nova I recognized the following:

 Doing a reboot (from inside of the VM with reboot command) on a kvm VM
 doesn't send any lifecycle events (events debugged with [2]).
 Doing the same thing with a xen VM leads to 2 events: First a
 VIR_DOMAIN_EVENT_STOPPED and then a VIR_DOMAIN_EVENT_STARTED event.
   

Yep. Same can be said for new libxl Xen driver too.

 The problem here is that for the xen case it doesn't seem to be possible
 to recognize that a reboot is ongoing.

Right. There is no VIR_DOMAIN_EVENT_REBOOTED event type.

  For that reason the OpenStack
 Nova component just forces the domain to stop after receiving the
 VIR_DOMAIN_EVENT_STOPPED event.
   

Yikes!

 Is it expected that the 2 drivers send different events for the same
 action or a bug in qemu/xen/libvirt?
   

You mentioned above that the qemu driver doesn't send *any* events when
a reboot occurs within the VM. Looking at the code seems to confirm
that. We could certainly change the Xen drivers to behave similarly, but
I'd like to hear opinions from other libvirt devs. Options for resolving
this include

1. Remove emitting the events from Xen drivers
2. Add the events to qemu driver and fix nova
3. Add VIR_DOMAIN_EVENT_REBOOTED, adapt drivers to use it, and fix nova

Regards,
Jim

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


Re: [libvirt] Lifecycle events during reboot for KVM and Xen

2014-08-08 Thread Thomas Bechtold

On 08/08/2014 06:54 PM, Jim Fehlig wrote:

1. Remove emitting the events from Xen drivers
2. Add the events to qemu driver and fix nova


Just for the record: I already proposed a patch[1] for Nova to get some 
comments from Nova folks. The patch basically delays the Nova stop API 
call a couple of seconds. If a VIR_DOMAIN_EVENT_STARTED is received 
during the wait period, the stop API call is canceled and the VM can 
start. But I think solution 3) would be better.



3. Add VIR_DOMAIN_EVENT_REBOOTED, adapt drivers to use it, and fix nova


As mentioned, I think that would be nice to have.


Best

Tom


[1] https://review.openstack.org/#/c/112946/

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


[libvirt] [PATCH] qemu: use guest-fsfreeze-freeze-list command if mountpoints to freeze specified

2014-08-08 Thread Tomoki Sekiyama
A command to freeze a part of mounted file systems is implemented in
upstream QEMU-guest-agent with a name of 'guest-fsfreeze-freeze-list'.
This fixes the name of the command used to partial fsfreeze in qemu driver
when 'mountpoints' option is specified to virDomainFSFreeze API.

Signed-off-by: Tomoki Sekiyama tomoki.sekiy...@hds.com
---
 src/qemu/qemu_agent.c |2 +-
 tests/qemuagenttest.c |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 0421733..a10954a 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1336,7 +1336,7 @@ int qemuAgentFSFreeze(qemuAgentPtr mon, const char 
**mountpoints,
 if (!arg)
 return -1;
 
-cmd = qemuAgentMakeCommand(guest-fsfreeze-freeze,
+cmd = qemuAgentMakeCommand(guest-fsfreeze-freeze-list,
a:mountpoints, arg, NULL);
 } else {
 cmd = qemuAgentMakeCommand(guest-fsfreeze-freeze, NULL);
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index be207e8..bc649b4 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -45,7 +45,7 @@ testQemuAgentFSFreeze(const void *data)
 if (qemuMonitorTestAddAgentSyncResponse(test)  0)
 goto cleanup;
 
-if (qemuMonitorTestAddItem(test, guest-fsfreeze-freeze,
+if (qemuMonitorTestAddItem(test, guest-fsfreeze-freeze-list,
{ \return\ : 5 })  0)
 goto cleanup;
 

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


Re: [libvirt] [Qemu-devel] [PATCH v2 0/2] Add machine type pc-1.0-qemu-kvm for live migrate compatibility with qemu-kvm

2014-08-08 Thread Serge E. Hallyn
Quoting Alex Bligh (a...@alex.org.uk):
 
 On 7 Aug 2014, at 20:26, Serge E. Hallyn se...@hallyn.com wrote:
 
  A-ha, acpi wasn't a problem.  I actually had a general migration
  problem even when coming from other utopic hosts.  With that fixed,
  I've got successful migration from qemu-kvm 1.0 in precise to
  a utopic host.
 
 That's good news. You might try the 2 patches here:
 
 https://github.com/abligh/qemu/tree/livemigrate-qemu-kvm-to-qemu-2.0.0-test-2
 
 and see if you can get Precise to Trusty migration working (as well
 as Precise to Utopic)

These have built at 
https://launchpad.net/~serge-hallyn/+archive/ubuntu/qemu-p-migration

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


Re: [libvirt] [PATCH 01/24] src/xenxs: Refactor code parsing memory config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
   xenParseXMMem(virConfPtr conf,.);
 which parses memory config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
   

Extra SOB in the patches.  I'll remove the first one before pushing any
patch.

 ---
  src/xenxs/xen_xm.c | 83 
 +-
  1 file changed, 45 insertions(+), 38 deletions(-)

 diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
 index 4461654..443e6da 100644
 --- a/src/xenxs/xen_xm.c
 +++ b/src/xenxs/xen_xm.c
 @@ -40,11 +40,9 @@
  #include virstoragefile.h
  #include virstring.h
  
 -/* Convenience method to grab a long int from the config file object */
 -static int xenXMConfigGetBool(virConfPtr conf,
 -  const char *name,
 -  int *value,
 -  int def)
 +/* Convenience method to grab a int from the config file object */
 +static int
 +xenXMConfigGetBool(virConfPtr conf, const char *name, int *value, int def)
   

You forgot to remove this and the other whitespace changes that have
nothing to do with Refactor code parsing memory config.  ACK to the
patch otherwise.  I'll remove these unrelated changes before pushing.

Regards,
Jim

  {
  virConfValuePtr val;
  
 @@ -67,11 +65,10 @@ static int xenXMConfigGetBool(virConfPtr conf,
  }
  
  
 -/* Convenience method to grab a int from the config file object */
 -static int xenXMConfigGetULong(virConfPtr conf,
 -   const char *name,
 -   unsigned long *value,
 -   unsigned long def)
 +/* Convenience method to grab a long int from the config file object */
 +static int
 +xenXMConfigGetULong(virConfPtr conf, const char *name, unsigned long *value,
 +unsigned long def)
  {
  virConfValuePtr val;
  
 @@ -99,10 +96,9 @@ static int xenXMConfigGetULong(virConfPtr conf,
  
  
  /* Convenience method to grab a int from the config file object */
 -static int xenXMConfigGetULongLong(virConfPtr conf,
 -   const char *name,
 -   unsigned long long *value,
 -   unsigned long long def)
 +static int
 +xenXMConfigGetULongLong(virConfPtr conf, const char *name,
 +unsigned long long *value, unsigned long long def)
  {
  virConfValuePtr val;
  
 @@ -130,10 +126,9 @@ static int xenXMConfigGetULongLong(virConfPtr conf,
  
  
  /* Convenience method to grab a string from the config file object */
 -static int xenXMConfigGetString(virConfPtr conf,
 -const char *name,
 -const char **value,
 -const char *def)
 +static int
 +xenXMConfigGetString(virConfPtr conf, const char *name, const char **value,
 + const char *def)
  {
  virConfValuePtr val;
  
 @@ -155,10 +150,10 @@ static int xenXMConfigGetString(virConfPtr conf,
  return 0;
  }
  
 -static int xenXMConfigCopyStringInternal(virConfPtr conf,
 - const char *name,
 - char **value,
 - int allowMissing)
 +
 +static int
 +xenXMConfigCopyStringInternal(virConfPtr conf, const char *name, char 
 **value,
 +  int allowMissing)
  {
  virConfValuePtr val;
  
 @@ -188,15 +183,16 @@ static int xenXMConfigCopyStringInternal(virConfPtr 
 conf,
  }
  
  
 -static int xenXMConfigCopyString(virConfPtr conf,
 - const char *name,
 - char **value) {
 +static int
 +xenXMConfigCopyString(virConfPtr conf, const char *name, char **value)
 +{
  return xenXMConfigCopyStringInternal(conf, name, value, 0);
  }
  
 -static int xenXMConfigCopyStringOpt(virConfPtr conf,
 -const char *name,
 -char **value) {
 +
 +static int
 +xenXMConfigCopyStringOpt(virConfPtr conf, const char *name, char **value)
 +{
  return xenXMConfigCopyStringInternal(conf, name, value, 1);
  }
  
 @@ -244,6 +240,25 @@ xenXMConfigGetUUID(virConfPtr conf, const char *name, 
 unsigned char *uuid)
  return 0;
  }
  
 +
 +static int
 +xenParseXMMem(virConfPtr conf, virDomainDefPtr def)
 +{
 +if (xenXMConfigGetULongLong(conf, memory, def-mem.cur_balloon,
 +MIN_XEN_GUEST_SIZE * 2)  0)
 +return -1;
 +
 +if (xenXMConfigGetULongLong(conf, maxmem, def-mem.max_balloon,
 +def-mem.cur_balloon)  0)
 +return -1;
 +
 +def-mem.cur_balloon *= 1024;
 +def-mem.max_balloon *= 1024;
 +
 +return 0;
 +}
 +
 +
  #define MAX_VFB 1024
  /*
   * Turn a config record into a lump of XML describing the
 @@ -251,7 

Re: [libvirt] [PATCH 02/24] src/xenxs: Refactor code parsing virtual time config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
 xenParseXMTimeOffset(virConfPtr conf,...);
 which parses time offset config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 71 
 +-
  1 file changed, 43 insertions(+), 28 deletions(-)
   

ACK.  Will push shortly after removing the first SOB.

Regards,
Jim

 diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
 index 443e6da..0e0cf90 100644
 --- a/src/xenxs/xen_xm.c
 +++ b/src/xenxs/xen_xm.c
 @@ -259,7 +259,48 @@ xenParseXMMem(virConfPtr conf, virDomainDefPtr def)
  }
  
  
 +static int
 +xenParseXMTimeOffset(virConfPtr conf, virDomainDefPtr def,
 + int xendConfigVersion)
 +{
 +int vmlocaltime;
 +
 +if (xenXMConfigGetBool(conf, localtime, vmlocaltime, 0)  0)
 +return -1;
 +
 +if (STREQ(def-os.type, hvm)) {
 +/* only managed HVM domains since 3.1.0 have persistent 
 rtc_timeoffset */
 +if (xendConfigVersion  XEND_CONFIG_VERSION_3_1_0) {
 +if (vmlocaltime)
 +def-clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
 +else
 +def-clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
 +def-clock.data.utc_reset = true;
 +} else {
 +unsigned long rtc_timeoffset;
 +def-clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE;
 +if (xenXMConfigGetULong(conf, rtc_timeoffset, rtc_timeoffset, 
 0)  0)
 +return -1;
 +
 +def-clock.data.variable.adjustment = (int)rtc_timeoffset;
 +def-clock.data.variable.basis = vmlocaltime ?
 +VIR_DOMAIN_CLOCK_BASIS_LOCALTIME :
 +VIR_DOMAIN_CLOCK_BASIS_UTC;
 +}
 +} else {
 +/* PV domains do not have an emulated RTC and the offset is fixed. */
 +def-clock.offset = vmlocaltime ?
 +VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME :
 +VIR_DOMAIN_CLOCK_OFFSET_UTC;
 +def-clock.data.utc_reset = true;
 +} /* !hvm */
 +
 +return 0;
 +}
 +
 +
  #define MAX_VFB 1024
 +
  /*
   * Turn a config record into a lump of XML describing the
   * domain, suitable for later feeding for virDomainCreateXML
 @@ -279,7 +320,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
  virDomainHostdevDefPtr hostdev = NULL;
  size_t i;
  const char *defaultMachine;
 -int vmlocaltime = 0;
  unsigned long count;
  char *script = NULL;
  char *listenAddr = NULL;
 @@ -456,34 +496,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
  def-clock.timers[0] = timer;
  }
  }
 -if (xenXMConfigGetBool(conf, localtime, vmlocaltime, 0)  0)
 -goto cleanup;
  
 -if (hvm) {
 -/* only managed HVM domains since 3.1.0 have persistent 
 rtc_timeoffset */
 -if (xendConfigVersion  XEND_CONFIG_VERSION_3_1_0) {
 -if (vmlocaltime)
 -def-clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
 -else
 -def-clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
 -def-clock.data.utc_reset = true;
 -} else {
 -unsigned long rtc_timeoffset;
 -def-clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE;
 -if (xenXMConfigGetULong(conf, rtc_timeoffset, rtc_timeoffset, 
 0)  0)
 -goto cleanup;
 -def-clock.data.variable.adjustment = (int)rtc_timeoffset;
 -def-clock.data.variable.basis = vmlocaltime ?
 -VIR_DOMAIN_CLOCK_BASIS_LOCALTIME :
 -VIR_DOMAIN_CLOCK_BASIS_UTC;
 -}
 -} else {
 -/* PV domains do not have an emulated RTC and the offset is fixed. */
 -def-clock.offset = vmlocaltime ?
 -VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME :
 -VIR_DOMAIN_CLOCK_OFFSET_UTC;
 -def-clock.data.utc_reset = true;
 -} /* !hvm */
 +if (xenParseXMTimeOffset(conf, def, xendConfigVersion)  0)
 +goto cleanup;
  
  if (xenXMConfigCopyStringOpt(conf, device_model, def-emulator)  0)
  goto cleanup;
   

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


Re: [libvirt] [PATCH 03/24] src/xenxs: Refactor code parsing event actions

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
   xenParseXMEventActions(virConfPtr conf,)
 which parses events leading to certain actions

 signed-off-by: Kiarie Kahurani davidkia...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 61 
 +-
  1 file changed, 37 insertions(+), 24 deletions(-)
   

ACK.  Will push after removing the first SOB.

Regards,
Jim

 diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
 index 0e0cf90..ecc8f52 100644
 --- a/src/xenxs/xen_xm.c
 +++ b/src/xenxs/xen_xm.c
 @@ -299,6 +299,42 @@ xenParseXMTimeOffset(virConfPtr conf, virDomainDefPtr 
 def,
  }
  
  
 +static int
 +xenParseXMEventsActions(virConfPtr conf, virDomainDefPtr def)
 +{
 +const char *str = NULL;
 +
 +if (xenXMConfigGetString(conf, on_poweroff, str, destroy)  0)
 +return -1;
 +
 +if ((def-onPoweroff = virDomainLifecycleTypeFromString(str))  0) {
 +virReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(unexpected value %s for on_poweroff), str);
 +return -1;
 +}
 +
 +if (xenXMConfigGetString(conf, on_reboot, str, restart)  0)
 +return -1;
 +
 +if ((def-onReboot = virDomainLifecycleTypeFromString(str))  0) {
 +virReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(unexpected value %s for on_reboot), str);
 +return -1;
 +}
 +
 +if (xenXMConfigGetString(conf, on_crash, str, restart)  0)
 +return -1;
 +
 +if ((def-onCrash = virDomainLifecycleCrashTypeFromString(str))  0) {
 +virReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(unexpected value %s for on_crash), str);
 +return -1;
 +}
 +
 +return 0;
 +}
 +
 +
  #define MAX_VFB 1024
  
  /*
 @@ -431,31 +467,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
  if (str  (virBitmapParse(str, 0, def-cpumask, 4096)  0))
  goto cleanup;
  
 -if (xenXMConfigGetString(conf, on_poweroff, str, destroy)  0)
 +if (xenParseXMEventsActions(conf, def)  0)
  goto cleanup;
 -if ((def-onPoweroff = virDomainLifecycleTypeFromString(str))  0) {
 -virReportError(VIR_ERR_INTERNAL_ERROR,
 -   _(unexpected value %s for on_poweroff), str);
 -goto cleanup;
 -}
 -
 -if (xenXMConfigGetString(conf, on_reboot, str, restart)  0)
 -goto cleanup;
 -if ((def-onReboot = virDomainLifecycleTypeFromString(str))  0) {
 -virReportError(VIR_ERR_INTERNAL_ERROR,
 -   _(unexpected value %s for on_reboot), str);
 -goto cleanup;
 -}
 -
 -if (xenXMConfigGetString(conf, on_crash, str, restart)  0)
 -goto cleanup;
 -if ((def-onCrash = virDomainLifecycleCrashTypeFromString(str))  0) {
 -virReportError(VIR_ERR_INTERNAL_ERROR,
 -   _(unexpected value %s for on_crash), str);
 -goto cleanup;
 -}
 -
 -
  
  if (hvm) {
  if (xenXMConfigGetBool(conf, pae, val, 0)  0)
   

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


Re: [libvirt] [PATCH 04/24] src/xenxs: Refactor code parsing PCI config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
xenParseXMPCI(virConfPtr conf, );
 which parses PCI config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 185 
 +++--
  1 file changed, 95 insertions(+), 90 deletions(-)
   

Looks good, ACK.  Will push after removing the first SOB.

Regards,
Jim

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


Re: [libvirt] [PATCH 05/24] src/xenxs: Refactor code parsing CPU features

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
   xenParseXMCPUFeatures(virConfPtr conf,.);
 which parses CPU features instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 127 
 +++--
  1 file changed, 74 insertions(+), 53 deletions(-)
   

ACK.  Will push shortly after cleaning up the extra SOB.

Regards,
Jim

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


Re: [libvirt] [PATCH 01/24] src/xenxs: Refactor code parsing memory config

2014-08-08 Thread Eric Blake
On 08/08/2014 02:58 PM, Jim Fehlig wrote:
 Kiarie Kahurani wrote:
 introduce function
   xenParseXMMem(virConfPtr conf,.);
 which parses memory config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
   
 
 Extra SOB in the patches.  I'll remove the first one before pushing any
 patch.

Also, you forgot a cover letter this time around.  When sending a
series, it's helpful to have the 0/24 cover letter. :)

-- 
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 06/24] src/xenxs: Refactor code parsing xm disk config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
   xenParseXMDisk(virConfPtr conf, );
 which parses xm disk config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 322 
 -
  1 file changed, 168 insertions(+), 154 deletions(-)

 diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
 index e75842f..f4bb37d 100644
 --- a/src/xenxs/xen_xm.c
 +++ b/src/xenxs/xen_xm.c
 @@ -500,136 +500,15 @@ xenParseXMCPUFeatures(virConfPtr conf, virDomainDefPtr 
 def)
  }
  
  
 -#define MAX_VFB 1024
 -
 -/*
 - * Turn a config record into a lump of XML describing the
 - * domain, suitable for later feeding for virDomainCreateXML
 - */
 -virDomainDefPtr
 -xenParseXM(virConfPtr conf, int xendConfigVersion,
 -   virCapsPtr caps)
 +static int
 +xenParseXMDisk(virConfPtr conf, virDomainDefPtr def,
 +   int xendConfigVersion)
   

Whitespace off a bit.

  {
 -const char *str;
 -int hvm = 0;
 -int val;
 -virConfValuePtr list;
 -virDomainDefPtr def = NULL;
 +const char *str = NULL;
  virDomainDiskDefPtr disk = NULL;
 -virDomainNetDefPtr net = NULL;
 -virDomainGraphicsDefPtr graphics = NULL;
 -size_t i;
 -const char *defaultMachine;
 -char *script = NULL;
 -char *listenAddr = NULL;
 -
 -if (VIR_ALLOC(def)  0)
 -return NULL;
 -
 -def-virtType = VIR_DOMAIN_VIRT_XEN;
 -def-id = -1;
 -
 -if (xenXMConfigCopyString(conf, name, def-name)  0)
 -goto cleanup;
 -if (xenXMConfigGetUUID(conf, uuid, def-uuid)  0)
 -goto cleanup;
 -
 -
 -if ((xenXMConfigGetString(conf, builder, str, linux) == 0) 
 -STREQ(str, hvm))
 -hvm = 1;
 -
 -if (VIR_STRDUP(def-os.type, hvm ? hvm : xen)  0)
 -goto cleanup;
 -
 -def-os.arch =
 -virCapabilitiesDefaultGuestArch(caps,
 -def-os.type,
 -
 virDomainVirtTypeToString(def-virtType));
 -if (!def-os.arch) {
 -virReportError(VIR_ERR_INTERNAL_ERROR,
 -   _(no supported architecture for os type '%s'),
 -   def-os.type);
 -goto cleanup;
 -}
 -
 -defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
 -def-os.type,
 -def-os.arch,
 -
 virDomainVirtTypeToString(def-virtType));
 -if (defaultMachine != NULL) {
 -if (VIR_STRDUP(def-os.machine, defaultMachine)  0)
 -goto cleanup;
 -}
 -
 -if (hvm) {
 -const char *boot;
 -if (xenXMConfigCopyString(conf, kernel, def-os.loader)  0)
 -goto cleanup;
 -
 -if (xenXMConfigGetString(conf, boot, boot, c)  0)
 -goto cleanup;
 -
 -for (i = 0; i  VIR_DOMAIN_BOOT_LAST  boot[i]; i++) {
 -switch (*boot) {
 -case 'a':
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
 -break;
 -case 'd':
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_CDROM;
 -break;
 -case 'n':
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_NET;
 -break;
 -case 'c':
 -default:
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_DISK;
 -break;
 -}
 -def-os.nBootDevs++;
 -}
 -} else {
 -const char *extra, *root;
 -
 -if (xenXMConfigCopyStringOpt(conf, bootloader, 
 def-os.bootloader)  0)
 -goto cleanup;
 -if (xenXMConfigCopyStringOpt(conf, bootargs, 
 def-os.bootloaderArgs)  0)
 -goto cleanup;
 -
 -if (xenXMConfigCopyStringOpt(conf, kernel, def-os.kernel)  0)
 -goto cleanup;
 -if (xenXMConfigCopyStringOpt(conf, ramdisk, def-os.initrd)  0)
 -goto cleanup;
 -if (xenXMConfigGetString(conf, extra, extra, NULL)  0)
 -goto cleanup;
 -if (xenXMConfigGetString(conf, root, root, NULL)  0)
 -goto cleanup;
 -
 -if (root) {
 -if (virAsprintf(def-os.cmdline, root=%s %s, root, extra)  0)
 -goto cleanup;
 -} else {
 -if (VIR_STRDUP(def-os.cmdline, extra)  0)
 -goto cleanup;
 -}
 -}
 -
 -if (xenParseXMMem(conf, def)  0)
 -goto cleanup;
 +int hvm = STREQ(def-os.type, hvm);
 +virConfValuePtr list = virConfGetValue(conf, disk);
  
 -if (xenParseXMEventsActions(conf, def)  0)
 -goto cleanup;
 -
 -if (xenParseXMCPUFeatures(conf, def)  0)
 -goto cleanup;
 -
 -if (xenParseXMTimeOffset(conf, def, xendConfigVersion)  0)
 -goto cleanup;
 -
 -if (xenXMConfigCopyStringOpt(conf, 

Re: [libvirt] [PATCH 07/24] src/xenxs: Refactor code parsing Vfb config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
  xenParseXMVfb(virConfPtr conf,..);
 which parses Vfb config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 301 
 +++--
  1 file changed, 155 insertions(+), 146 deletions(-)

 diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
 index f4bb37d..228e0a2 100644
 --- a/src/xenxs/xen_xm.c
 +++ b/src/xenxs/xen_xm.c
 @@ -40,6 +40,7 @@
  #include virstoragefile.h
  #include virstring.h
  
 +#define MAX_VFB 1024
  /* Convenience method to grab a int from the config file object */
  static int
  xenXMConfigGetBool(virConfPtr conf, const char *name, int *value, int def)
 @@ -689,7 +690,158 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def,
  
  return 0;
  }
 -#define MAX_VFB 1024
 +
 +
 +static int
 +xenParseXMVfb(virConfPtr conf, virDomainDefPtr def,
 +  int xendConfigVersion)
 +{
 +int val;
 +char *listenAddr = NULL;
 +int hvm = STREQ(def-os.type, hvm);
 +virConfValuePtr list;
 +virDomainGraphicsDefPtr graphics = NULL;
 +
 +if (hvm || xendConfigVersion  XEND_CONFIG_VERSION_3_0_4) {
 +if (xenXMConfigGetBool(conf, vnc, val, 0)  0)
 +goto cleanup;
 +if (val) {
 +if (VIR_ALLOC(graphics)  0)
 +goto cleanup;
 +graphics-type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
 +if (xenXMConfigGetBool(conf, vncunused, val, 1)  0)
 +goto cleanup;
 +graphics-data.vnc.autoport = val ? 1 : 0;
 +if (!graphics-data.vnc.autoport) {
 +unsigned long vncdisplay;
 +if (xenXMConfigGetULong(conf, vncdisplay, vncdisplay, 0) 
  0)
 +goto cleanup;
 +graphics-data.vnc.port = (int)vncdisplay + 5900;
 +}
 +
 +if (xenXMConfigCopyStringOpt(conf, vnclisten, listenAddr)  0)
 +goto cleanup;
 +if (listenAddr 
 +virDomainGraphicsListenSetAddress(graphics, 0, listenAddr,
 +  -1, true)  0) {
 +   goto cleanup;
 +}
 +
 +VIR_FREE(listenAddr);
 +if (xenXMConfigCopyStringOpt(conf, vncpasswd, 
 graphics-data.vnc.auth.passwd)  0)
 +goto cleanup;
 +if (xenXMConfigCopyStringOpt(conf, keymap, 
 graphics-data.vnc.keymap)  0)
 +goto cleanup;
 +if (VIR_ALLOC_N(def-graphics, 1)  0)
 +goto cleanup;
 +def-graphics[0] = graphics;
 +def-ngraphics = 1;
 +graphics = NULL;
 +} else {
 +if (xenXMConfigGetBool(conf, sdl, val, 0)  0)
 +goto cleanup;
 +if (val) {
 +if (VIR_ALLOC(graphics)  0)
 +goto cleanup;
 +graphics-type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
 +if (xenXMConfigCopyStringOpt(conf, display, 
 graphics-data.sdl.display)  0)
 +goto cleanup;
 +if (xenXMConfigCopyStringOpt(conf, xauthority, 
 graphics-data.sdl.xauth)  0)
 +goto cleanup;
 +if (VIR_ALLOC_N(def-graphics, 1)  0)
 +goto cleanup;
 +def-graphics[0] = graphics;
 +def-ngraphics = 1;
 +graphics = NULL;
 +}
 +}
 +}
 +
 +if (!hvm  def-graphics == NULL) { /* New PV guests use this format */
 +list = virConfGetValue(conf, vfb);
 +if (list  list-type == VIR_CONF_LIST 
 +list-list  list-list-type == VIR_CONF_STRING 
 +list-list-str) {
 +char vfb[MAX_VFB];
 +char *key = vfb;
 +
 +if (virStrcpyStatic(vfb, list-list-str) == NULL) {
 +virReportError(VIR_ERR_INTERNAL_ERROR,
 +   _(VFB %s too big for destination),
 +   list-list-str);
 +goto cleanup;
 +}
 +
 +if (VIR_ALLOC(graphics)  0)
 +goto cleanup;
 +if (strstr(key, type=sdl))
 +graphics-type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
 +else
 +graphics-type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
 +while (key) {
 +char *nextkey = strchr(key, ',');
 +char *end = nextkey;
 +if (nextkey) {
 +*end = '\0';
 +nextkey++;
 +}
 +
 +if (!strchr(key, '='))
 +break;
 +if (graphics-type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
 +if (STRPREFIX(key, vncunused=)) {
 +if (STREQ(key + 10, 1))
 +graphics-data.vnc.autoport = true;
 +} else if 

Re: [libvirt] [PATCH 08/24] src/xenxs: Refactor code parsing Char devices config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
   xenParseXMCharDev(virConfPtr conf,.);
 which parses Char devices config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 174 
 -
  1 file changed, 93 insertions(+), 81 deletions(-)
   

ACK.  Will push after removing the extra SOB.

Regards,
Jim

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


Re: [libvirt] [PATCH 09/24] src/xenxs: Refactor code parsing Vif config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
   xenParseXMVif(virConfPtr conf,);
 which parses Vfb config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 283 
 +++--
  1 file changed, 143 insertions(+), 140 deletions(-)

 diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
 index 628cef6..73efa5f 100644
 --- a/src/xenxs/xen_xm.c
 +++ b/src/xenxs/xen_xm.c
 @@ -934,134 +934,13 @@ xenParseXMCharDev(virConfPtr conf, virDomainDefPtr def)
  }
  
  
 -/*
 - * Turn a config record into a lump of XML describing the
 - * domain, suitable for later feeding for virDomainCreateXML
 - */
 -virDomainDefPtr
 -xenParseXM(virConfPtr conf, int xendConfigVersion,
 -   virCapsPtr caps)
 +static int
 +xenParseXMVif(virConfPtr conf, virDomainDefPtr def)
  {
 -const char *str;
 -int hvm = 0;
 -virConfValuePtr list;
 -virDomainDefPtr def = NULL;
 -virDomainDiskDefPtr disk = NULL;
 -virDomainNetDefPtr net = NULL;
 -size_t i;
 -const char *defaultMachine;
  char *script = NULL;
 +virDomainNetDefPtr net = NULL;
 +virConfValuePtr list = virConfGetValue(conf, vif);
  
 -if (VIR_ALLOC(def)  0)
 -return NULL;
 -
 -def-virtType = VIR_DOMAIN_VIRT_XEN;
 -def-id = -1;
 -
 -if (xenXMConfigCopyString(conf, name, def-name)  0)
 -goto cleanup;
 -if (xenXMConfigGetUUID(conf, uuid, def-uuid)  0)
 -goto cleanup;
 -
 -
 -if ((xenXMConfigGetString(conf, builder, str, linux) == 0) 
 -STREQ(str, hvm))
 -hvm = 1;
 -
 -if (VIR_STRDUP(def-os.type, hvm ? hvm : xen)  0)
 -goto cleanup;
 -
 -def-os.arch =
 -virCapabilitiesDefaultGuestArch(caps,
 -def-os.type,
 -
 virDomainVirtTypeToString(def-virtType));
 -if (!def-os.arch) {
 -virReportError(VIR_ERR_INTERNAL_ERROR,
 -   _(no supported architecture for os type '%s'),
 -   def-os.type);
 -goto cleanup;
 -}
 -
 -defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
 -def-os.type,
 -def-os.arch,
 -
 virDomainVirtTypeToString(def-virtType));
 -if (defaultMachine != NULL) {
 -if (VIR_STRDUP(def-os.machine, defaultMachine)  0)
 -goto cleanup;
 -}
 -
 -if (hvm) {
 -const char *boot;
 -if (xenXMConfigCopyString(conf, kernel, def-os.loader)  0)
 -goto cleanup;
 -
 -if (xenXMConfigGetString(conf, boot, boot, c)  0)
 -goto cleanup;
 -
 -for (i = 0; i  VIR_DOMAIN_BOOT_LAST  boot[i]; i++) {
 -switch (*boot) {
 -case 'a':
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
 -break;
 -case 'd':
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_CDROM;
 -break;
 -case 'n':
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_NET;
 -break;
 -case 'c':
 -default:
 -def-os.bootDevs[i] = VIR_DOMAIN_BOOT_DISK;
 -break;
 -}
 -def-os.nBootDevs++;
 -}
 -} else {
 -const char *extra, *root;
 -
 -if (xenXMConfigCopyStringOpt(conf, bootloader, 
 def-os.bootloader)  0)
 -goto cleanup;
 -if (xenXMConfigCopyStringOpt(conf, bootargs, 
 def-os.bootloaderArgs)  0)
 -goto cleanup;
 -
 -if (xenXMConfigCopyStringOpt(conf, kernel, def-os.kernel)  0)
 -goto cleanup;
 -if (xenXMConfigCopyStringOpt(conf, ramdisk, def-os.initrd)  0)
 -goto cleanup;
 -if (xenXMConfigGetString(conf, extra, extra, NULL)  0)
 -goto cleanup;
 -if (xenXMConfigGetString(conf, root, root, NULL)  0)
 -goto cleanup;
 -
 -if (root) {
 -if (virAsprintf(def-os.cmdline, root=%s %s, root, extra)  0)
 -goto cleanup;
 -} else {
 -if (VIR_STRDUP(def-os.cmdline, extra)  0)
 -goto cleanup;
 -}
 -}
 -
 -if (xenParseXMMem(conf, def)  0)
 -goto cleanup;
 -
 -if (xenParseXMEventsActions(conf, def)  0)
 -goto cleanup;
 -
 -if (xenParseXMCPUFeatures(conf, def)  0)
 -goto cleanup;
 -
 -if (xenParseXMTimeOffset(conf, def, xendConfigVersion)  0)
 -goto cleanup;
 -
 -if (xenParseXMDisk(conf, def, xendConfigVersion)  0)
 -goto cleanup;
 -
 -if (xenXMConfigCopyStringOpt(conf, device_model, def-emulator)  0)
 -goto cleanup;
 -
 -list = virConfGetValue(conf, vif);
  if (list  list-type == VIR_CONF_LIST) {
  list = 

Re: [libvirt] [PATCH 10/24] src/xenxs: Refactor code parsing emulated hardware config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
xenParseXMEmulatedHardware(virConfPtr conf,.);
 which parses emulated devices config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 82 
 --
  1 file changed, 48 insertions(+), 34 deletions(-)
   

Looks good, ACK.  I'll push after removing the extra SOB.

Regards,
Jim

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


Re: [libvirt] [PATCH 11/24] src/xenxs: Refactor code parsing general config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
xenParseXMGeneralMeta(virConfPtr conf, ...);
 which parses general metadata instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 58 
 --
  1 file changed, 35 insertions(+), 23 deletions(-)
   

ACK.  Will push shortly.

Regards,
Jim

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


Re: [libvirt] [PATCH 12/24] src/xenxs: Refactor code parsing OS config

2014-08-08 Thread Jim Fehlig
Kiarie Kahurani wrote:
 introduce function
   xenParseXMOS(virConfPtr conf,...);
 which parses the OS config instead

 signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 Signed-off-by: Kiarie Kahurani davidkiar...@gmail.com
 ---
  src/xenxs/xen_xm.c | 80 
 ++
  1 file changed, 50 insertions(+), 30 deletions(-)

 diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
 index 32c6d8c..b21d794 100644
 --- a/src/xenxs/xen_xm.c
 +++ b/src/xenxs/xen_xm.c
 @@ -1176,33 +1176,26 @@ xenParseXMGeneralMeta(virConfPtr conf, 
 virDomainDefPtr def,
  
  return 0;
  }
 -/*
 - * Turn a config record into a lump of XML describing the
 - * domain, suitable for later feeding for virDomainCreateXML
 - */
 -virDomainDefPtr
 -xenParseXM(virConfPtr conf, int xendConfigVersion,
 -   virCapsPtr caps)
 -{
 -virDomainDefPtr def = NULL;
 -size_t i;
  
 -if (VIR_ALLOC(def)  0)
 -return NULL;
 -
 -def-virtType = VIR_DOMAIN_VIRT_XEN;
 -def-id = -1;
  
 -if (xenParseXMGeneralMeta(conf, def, caps)  0)
 -goto cleanup;
 +static int
 +xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
 +{
 +size_t i;
  
  if (STREQ(def-os.type, hvm)) {
  const char *boot;
 +if (xenXMConfigCopyStringOpt(conf, device_model, def-emulator)  
 0)
 +return -1;
 +
 +if (xenXMConfigCopyStringOpt(conf, device_model, def-emulator)  
 0)
 +return -1;
   

Opps, copy and paste one time too many.  This should also be outside the
'if (hvm)', as it was originally.

ACK otherwise.  I've fixed this up and pushed 1-12.  The rest will have
to wait until next week.  Thanks!

Regards,
Jim

 +
  if (xenXMConfigCopyString(conf, kernel, def-os.loader)  0)
 -goto cleanup;
 +return -1;
  
  if (xenXMConfigGetString(conf, boot, boot, c)  0)
 -goto cleanup;
 +return -1;
  
  for (i = 0; i  VIR_DOMAIN_BOOT_LAST  boot[i]; i++) {
  switch (*boot) {
 @@ -1226,28 +1219,58 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
  const char *extra, *root;
  
  if (xenXMConfigCopyStringOpt(conf, bootloader, 
 def-os.bootloader)  0)
 -goto cleanup;
 +return -1;
 +
  if (xenXMConfigCopyStringOpt(conf, bootargs, 
 def-os.bootloaderArgs)  0)
 -goto cleanup;
 +return -1;
  
  if (xenXMConfigCopyStringOpt(conf, kernel, def-os.kernel)  0)
 -goto cleanup;
 +return -1;
 +
  if (xenXMConfigCopyStringOpt(conf, ramdisk, def-os.initrd)  0)
 -goto cleanup;
 +return -1;
 +
  if (xenXMConfigGetString(conf, extra, extra, NULL)  0)
 -goto cleanup;
 +return -1;
 +
  if (xenXMConfigGetString(conf, root, root, NULL)  0)
 -goto cleanup;
 +return -1;
  
  if (root) {
  if (virAsprintf(def-os.cmdline, root=%s %s, root, extra)  0)
 -goto cleanup;
 +return -1;
 +
  } else {
  if (VIR_STRDUP(def-os.cmdline, extra)  0)
 -goto cleanup;
 +return -1;
 +
  }
  }
  
 +return 0;
 +}
 +/*
 + * Turn a config record into a lump of XML describing the
 + * domain, suitable for later feeding for virDomainCreateXML
 + */
 +virDomainDefPtr
 +xenParseXM(virConfPtr conf, int xendConfigVersion,
 +   virCapsPtr caps)
 +{
 +virDomainDefPtr def = NULL;
 +
 +if (VIR_ALLOC(def)  0)
 +return NULL;
 +
 +def-virtType = VIR_DOMAIN_VIRT_XEN;
 +def-id = -1;
 +
 +if (xenParseXMGeneralMeta(conf, def, caps)  0)
 +goto cleanup;
 +
 +if (xenParseXMOS(conf, def)  0)
 +goto cleanup;
 +
  if (xenParseXMMem(conf, def)  0)
  goto cleanup;
  
 @@ -1263,9 +1286,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
  if (xenParseXMDisk(conf, def, xendConfigVersion)  0)
  goto cleanup;
  
 -if (xenXMConfigCopyStringOpt(conf, device_model, def-emulator)  0)
 -goto cleanup;
 -
  if (xenParseXMVif(conf, def)  0)
  goto cleanup;
  
   

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


Re: [libvirt] [PATCH 3/4] vol-info: Check for NFS FS type

2014-08-08 Thread John Ferlan


On 08/08/2014 11:26 AM, John Ferlan wrote:
 
 
 On 08/08/2014 07:07 AM, Ján Tomko wrote:
 On 08/05/2014 04:38 PM, John Ferlan wrote:
 https://bugzilla.redhat.com/show_bug.cgi?id=1077068

 Check for the NFS FS type being true for a local stat of the file
 to force usage of the 'st_size' value rather than calculating the size
 using the 'st_blocks' and 'st_blksize'.  As described in the stat(2)
 man page:

 Use of the st_blocks and st_blksize fields may be less portable.

 experimentation shows a 10M file could get the following output from stat:

   st_size=10485760 st_blocks=88 st_blksize=1048576

 resulting in a 44 KiB value being displayed as the allocation value.
 While this value does match the du -s value of the same file, the
 du -b value shows the st_size field. Similarly a long listing of the
 file shows the 10M size.

 Capacity should be the apparent size (what du -b shows, or st_size), while
 allocation should track the on-disk usage (du, st_blocks * 512).

 It looks to me that the values are correct, it's just that posix_fallocate
 does neither work nor fail on NFS.

 Jan

 
 Testing seems to indicate that posix_fallocate() either doesn't work as
 expected on the target or using the target.path is incorrect...
 
 Before posix_fallocate
 stat st_blocks=0 st_blksize=1048576 st_size=10485760
 lseek end=10485760
 
 posix_fallocate of 10485760 bytes on /home/nfs_pool/target/test-vol1
 
 After posix_fallocate
 stat st_blocks=88 st_blksize=1048576 st_size=10485760
 lseek end=10485760
 
 
 Hmm... would going at the target be correct in this instance?  Same test
 but use the source path:
 
 Before posix_fallocate
 stat st_blocks=0 st_blksize=4096 st_size=10485760
 lseek end=10485760
 
 posix_fallocate of 10485760 bytes on /home/nfs_pool/nfs-export/test-vol1
 
 After posix_fallocate
 stat st_blocks=20480 st_blksize=4096 st_size=10485760
 lseek end=10485760
 
 ...
 
 hmm 20480 * 512 = 10485760
 
 # df
 ...
 localhost:/home/nfs_pool/nfs-export 140979200 35521536  98273280  27%
 /home/nfs_pool/target
 #
 

Well it's a tangled web that's being weaved...  The blksize of the
target volume comes from the 'wsize' value in the mount:

localhost:/home/nfs_pool/nfs-export on /home/nfs_pool/target type nfs4
(rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,...)

Further testing shows if I change the wsize to 4096, then I get what I
expect; however, starting at 8192 I'll get decreasingly smaller
allocations. So this is a math problem.

So going back to writing via posix_fallocate() to the
/home/nfs_pool/target/test-vol the issue is the blksize of the
source (nfs-export) is 4096 while the blksize of the target (target)
is 1048576 (as a result of the nfs mount settings).  What seems to
happen is the posix_fallocate() makes 11 writes - I assume because
blksize*10  desired_size (10485760) (instead of =...).

Thus 11 * 4096 = 45056 (bytes) / 1024 = 44 KiB which was displayed.

Why all this happens I'm not sure.  Bug in posix_fallocate()? Bug in
configuration?  I have to assume that when this code was first added NFS
probably was still using smaller block sizes.  Whether anyone has
noticed or not beyond the virt-test which discovered the issue - I'm not
sure.  In any case, does anyone have feedback/thoughts for next steps?
I can put together something that avoids posix_fallocate() for the
create-as and resize paths.


John


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