Re: [libvirt] Unable to make libvirt-0.9.13

2012-07-11 Thread B Veera-B37207
Hi Eric,

I am compiling on "Power PC" Architecture Board.

As you said I compiled with 'make V=1' , Output file is attached with this mail.



Regards,
Veera.

-Original Message-
From: Eric Blake [mailto:ebl...@redhat.com] 
Sent: Wednesday, July 11, 2012 8:00 PM
To: B Veera-B37207
Cc: libvir-list@redhat.com
Subject: Re: [libvirt] Unable to make libvirt

On 07/11/2012 06:52 AM, B Veera-B37207 wrote:
> Hi,
> 
> I am unable to compile libvirt -0.9.13
> 
> 
> 1.   ./configure (Executed successfully without any errors)
> 
> 2.   While executing make I am getting following Error
> 
> /bin/sed: can't read =/usr/lib/libnl-route.la: No such file or 
> directory

That's an odd file name.  Something went wrong to botch libtool up that badly.  
What platform are you compiling on?  Can you show the error is you repeat 
things with 'make V=1' to get a more complete command line that was being 
attempted prior to the error?

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



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

[libvirt] [glib PATCH V4] Add bindings for virDomainSave*()

2012-07-11 Thread Jovanka Gulicoska
---
 libvirt-gobject/libvirt-gobject-domain.c |  152 ++
 libvirt-gobject/libvirt-gobject-domain.h |   18 
 libvirt-gobject/libvirt-gobject.sym  |3 +
 3 files changed, 173 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
b/libvirt-gobject/libvirt-gobject-domain.c
index 088cd33..d803829 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -557,6 +557,158 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
 }
 
 /**
+ * gvir_domain_save_to_file:
+ * @dom: the domain
+ * @filename: path to the output file
+ * @custom_conf: configuration for domain or NULL
+ * @flags: the flags
+ *
+ * Returns: TRUE on success, FALSE otherwise
+ */
+gboolean gvir_domain_save_to_file(GVirDomain *dom,
+  gchar *filename,
+  GVirConfigDomain *custom_conf,
+  guint flags,
+  GError **err)
+{
+GVirDomainPrivate *priv;
+gchar *custom_xml = NULL;
+int ret;
+
+g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+priv = dom->priv;
+
+if (flags || custom_conf != NULL) {
+if (custom_conf != NULL)
+custom_xml = 
gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(custom_conf));
+
+ret = virDomainSaveFlags(priv->handle, filename, custom_xml, flags);
+g_free(custom_xml);
+}
+else {
+ret = virDomainSave(priv->handle, filename);
+}
+
+if (ret < 0) {
+gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+   0,
+   "Unable to save domain to file");
+return FALSE;
+}
+
+return TRUE;
+}
+
+typedef struct {
+gchar *filename;
+gchar *custom_xml;
+guint flags;
+} DomainSaveToFileData;
+
+static void domain_save_to_file_data_free(DomainSaveToFileData *data)
+{
+g_free(data->filename);
+g_free(data->custom_xml);
+g_slice_free(DomainSaveToFileData, data);
+}
+
+static void
+gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
+GObject *object,
+GCancellable *cancellable G_GNUC_UNUSED)
+{
+GVirDomain *dom = GVIR_DOMAIN(object);
+DomainSaveToFileData *data;
+GVirConfigDomain *conf;
+GError *err = NULL;
+
+data = g_simple_async_result_get_op_res_gpointer(res);
+conf = gvir_domain_get_config(dom, data->flags, &err);
+
+if (!gvir_domain_save_to_file(dom, data->filename, conf, data->flags, 
&err))
+g_simple_async_result_take_error(res, err);
+}
+
+/**
+ * gvir_domain_save_to_file_async:
+ * @dom: the domain
+ * @filename: path to output file
+ * @custom_conf: (allow-none): configuration for domain or NULL
+ * @flags: the flags
+ * @cancellable: (allow-none) (transfer none): cancallation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_domain_save_to_file
+ */
+void gvir_domain_save_to_file_async(GVirDomain *dom,
+gchar *filename,
+GVirConfigDomain *custom_conf,
+guint flags,
+GCancellable *cancellable,
+GAsyncReadyCallback callback,
+gpointer user_data)
+{
+GSimpleAsyncResult *res;
+DomainSaveToFileData *data;
+gchar *xml = NULL;
+
+g_return_if_fail(GVIR_IS_DOMAIN(dom));
+g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+if (custom_xml != NULL)
+xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(custom_conf));
+
+data = g_slice_new0(DomainSaveToFileData);
+data->filename = g_strdup(filename);
+data->custom_xml = g_strdup(xml);
+data->flags = flags;
+
+res = g_simple_async_result_new(G_OBJECT(dom),
+callback,
+user_data,
+gvir_domain_save_to_file_async);
+g_simple_async_result_set_op_res_gpointer(res, data, (GDestroyNotify)
+  domain_save_to_file_data_free);
+
+g_simple_async_result_run_in_thread(res,
+gvir_domain_save_to_file_helper,
+G_PRIORITY_DEFAULT,
+cancellable);
+
+g_object_unref(res);
+}
+
+/**
+ * gvir_domain_save_to_file_finish:
+ * @dom: the domain to save
+ * @result: (transfer none): async method result
+ * @err: Place-holder for possible errors
+ *
+ * Finishes the operation started by #gvir_domain_save_to_file_async.
+ *
+ * Returns: TRUE if domain was saved successfully, FALSE otherwise.
+ */
+gboolean gvir_domai

Re: [libvirt] Libvirt iSCSI APIs

2012-07-11 Thread Osier Yang

On 2012年07月12日 08:28, Ata Bohra wrote:

Hi All,

I am interested in extending libvirt APIs to support iSCSI operations
such as: add/remove targets, list targets, list remote LUNs, rescan luns
etc.


Nice.

The intention is to provide an interface that external programs can

hook to manage iSCSI storage devices on a given hypervisor(I would be
adding interfaces for ESX first). Looking at the libvirt.c interface for
storage driver I'm unable find routines that can be overridden for
specific hypervisor. Googling lead to a nice blog presentation that
provisions VMs on remote LUN(s) for KVM but uses virish.
(http://berrange.com/tags/iscsi/).


The storage APIs are independant, not associated with domain APIs.
AFAIK, the storage management is just common, not tied with specific
hypervisor (I may be wrong, perhaps there is specific stuffs I
don't known yet).

The blog post presents using virsh/virt-manager/virt-install, but
if you have the APIs, you can use the APIs (of both domain and storage)
to provision the guests with whatever external programs you want.

So if I understand you correctly, what you need to do is add the
implementations for those APIs in iscsi backend.



My question is; is this as per design not to expose iSCSI related APIs?


No, we'd like to see new useful APIs.


Will an extention to libvirt.c (_virStorageDriver) so that every
hypervisor can implement it is acceptable?


Again, either you or me is wrong, my understanding is the storage
management is not specific for different hypervisors, and it should
keep independant.

Regards,
Osier

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

Re: [libvirt] [RFC] [PATCH 2/5] add fuse support for libvirt lxc

2012-07-11 Thread Gao feng
于 2012年07月11日 17:30, Daniel P. Berrange 写道:
> On Wed, Jul 11, 2012 at 03:58:20PM +0800, Gao feng wrote:
>> this patch addes fuse support for libvirt lxc.
>> we can use fuse filesystem to generate sysinfo dynamically,
>> So we can isolate /proc/meminfo,cpuinfo and so on through
>> fuse filesystem.
>>
>> we mount fuse filesystem for every container.the mount name
>> is Lxc-lxcname-fuse.
>>
>> Signed-off-by: Gao feng 
>> ---
>>  src/Makefile.am  |9 ++-
>>  src/lxc/lxc_controller.c |   15 +
>>  src/lxc/lxc_driver.c |2 +
>>  src/lxc/lxc_fuse.c   |  155 
>> ++
>>  src/lxc/lxc_fuse.h   |   38 +++
>>  5 files changed, 217 insertions(+), 2 deletions(-)
>>  create mode 100644 src/lxc/lxc_fuse.c
>>  create mode 100644 src/lxc/lxc_fuse.h
>>
>> diff --git a/src/Makefile.am b/src/Makefile.am
>> index 6c3eaa7..b01b2df 100644
>> --- a/src/Makefile.am
>> +++ b/src/Makefile.am
>> @@ -349,11 +349,13 @@ endif
>>  
>>  LXC_DRIVER_SOURCES =\
>>  lxc/lxc_conf.c lxc/lxc_conf.h   \
>> +lxc/lxc_fuse.c lxc/lxc_fuse.h   \
>>  lxc/lxc_container.c lxc/lxc_container.h \
>>  lxc/lxc_driver.c lxc/lxc_driver.h
>>  
>>  LXC_CONTROLLER_SOURCES =\
>>  lxc/lxc_conf.c lxc/lxc_conf.h   \
>> +lxc/lxc_fuse.c lxc/lxc_fuse.h   \
>>  lxc/lxc_container.c lxc/lxc_container.h \
>>  lxc/lxc_controller.c
>>  
>> @@ -819,8 +821,9 @@ endif
>>  
>>  libvirt_driver_lxc_impl_la_CFLAGS = \
>>  $(LIBNL_CFLAGS) \
>> +$(FUSE_CFLAGS) \
>>  -I$(top_srcdir)/src/conf $(AM_CFLAGS)
>> -libvirt_driver_lxc_impl_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS)
>> +libvirt_driver_lxc_impl_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) $(FUSE_LIBS)
>>  if HAVE_LIBBLKID
>>  libvirt_driver_lxc_impl_la_CFLAGS += $(BLKID_CFLAGS)
>>  libvirt_driver_lxc_impl_la_LIBADD += $(BLKID_LIBS)
>> @@ -1523,6 +1526,7 @@ libvirt_lxc_SOURCES =  
>> \
>>  libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS)
>>  libvirt_lxc_LDADD = \
>>  $(NUMACTL_LIBS) \
>> +$(FUSE_LIBS) \
>>  libvirt-net-rpc-server.la \
>>  libvirt-net-rpc.la \
>>  libvirt_driver_security.la \
>> @@ -1540,7 +1544,8 @@ libvirt_lxc_LDADD += $(APPARMOR_LIBS)
>>  endif
>>  libvirt_lxc_CFLAGS =\
>>  -I$(top_srcdir)/src/conf\
>> -$(AM_CFLAGS)
>> +$(AM_CFLAGS)\
>> +$(FUSE_CFLAGS)
>>  if HAVE_LIBBLKID
>>  libvirt_lxc_CFLAGS += $(BLKID_CFLAGS)
>>  libvirt_lxc_LDADD += $(BLKID_LIBS)
>> diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
>> index a4874ea..44ba07c 100644
>> --- a/src/lxc/lxc_controller.c
>> +++ b/src/lxc/lxc_controller.c
>> @@ -58,6 +58,7 @@
>>  
>>  #include "lxc_conf.h"
>>  #include "lxc_container.h"
>> +#include "lxc_fuse.h"
>>  #include "virnetdev.h"
>>  #include "virnetdevveth.h"
>>  #include "memory.h"
>> @@ -1741,6 +1742,20 @@ int main(int argc, char *argv[])
>>  }
>>  }
>>  
>> +if ((pid = fork()) < 0)
>> +goto cleanup;
>> +
>> +if (pid == 0) {
>> +if ((pid = fork()) < 0)
>> +_exit(-1);
>> +
>> +if (pid > 0)
>> +   _exit(0);
>> +
>> +lxcRegisterFuse(ctrl->def);
>> +_exit(0);
>> +}
> 
> 
> This is double forking to daemonize, but you never execve()
> anywhere. Thus according to POSIX you are mandated to only
> use async signal safe functions. This is clearly impossible
> given the functionality you need to use with FUSE.
> 
> So either you need to make this a separate binary that can
> be exec()'d, or instead of fork()ing, run this in a thread
> of the libvirt_lxc process.  I think you can probably make
> do with just using a thread.
> 

Get it,thanks for explaining this to me.

>> +#if HAVE_FUSE
>> +
>> +static int lxcProcGetattr(const char *path, struct stat *stbuf)
>> +{
>> +int res = 0;
>> +
>> +memset(stbuf, 0, sizeof(struct stat));
>> +if (strcmp(path, "/") == 0) {
> 
> strcmp() == 0, is not allowed - use STREQ instead - if you
> run 'make syntax-check' it should warn you about this.
> 
>> +stbuf->st_mode = S_IFDIR | 0755;
>> +stbuf->st_nlink = 2;
>> +} else
>> +res = -ENOENT;
> 
> You need {} around the else clause, if you use {}
> around the if clause (see HACKING)
> 

Yes,will read it,thanks

>> +
>> +return res;
>> +}
>> +
>> +static int lxcProcReaddir(const char *path, void *buf,
>> +  fuse_fill_dir_t filler,
>> +  off_t offset ATTRIBUTE_UNUSED,
>> +  struct fuse_file_info *fi ATTRIBUTE_UNUSED)
>> +{
>> +if (strcmp(p

Re: [libvirt] [PATCHv2] fix failure when building with --disable-debug

2012-07-11 Thread Hu Tao
On Wed, Jul 11, 2012 at 08:36:10AM -0600, Eric Blake wrote:
> On 07/11/2012 04:40 AM, Hu Tao wrote:
> > When building with --disable-debug, VIR_DEBUG expands to a nop.
> > But parameters to VIR_DEBUG can be variables that are passed only
> > to VIR_DEBUG. In the case the building system complains about unused
> > variables.
> > ---
> >  cfg.mk |2 ++
> >  src/util/logging.h |8 +++-
> >  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> >  # else
> > +/**
> > + * virLogEatParam:
> > + *
> > + * Do nothing but eat parameters.
> > + */
> > +static inline void virLogEatParam(void *unused ATTRIBUTE_UNUSED, ...) {}
> 
> Can't we do:
> 
> static inline void virLogEatParam(void *dummy, ...) { dummy = dummy; }
> 
> to avoid even needing the ATTRIBUTE_UNUSED, and the syntax check exemption?

Good.

> 
> >  #  define VIR_DEBUG_INT(category, f, l, ...)\
> > -do { } while (0)
> > +virLogEatParam((void*)category, f, l, __VA_ARGS__)
> 
> Any reason we have to use a cast, instead of just creating our eat
> function with the correct type parameter in the first place?

I just wanted to make the function more generic.


-- 
Thanks,
Hu Tao

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


Re: [libvirt] [RFC] [PATCH 1/5] add configure option --with-fuse for libvirt

2012-07-11 Thread Gao feng
于 2012年07月11日 17:24, Daniel P. Berrange 写道:
> On Wed, Jul 11, 2012 at 03:58:19PM +0800, Gao feng wrote:
>> add a configure option --with-fuse to prepare introduction
>> of fuse support for libvirt lxc.
>>
>> Signed-off-by: Gao feng 
>> ---
>>  configure.ac|   45 +
>>  libvirt.spec.in |9 +
>>  2 files changed, 54 insertions(+), 0 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index d45f4f1..d5cf45f 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -1694,7 +1694,47 @@ AM_CONDITIONAL([HAVE_CAPNG], [test "$with_capng" != 
>> "no"])
>>  AC_SUBST([CAPNG_CFLAGS])
>>  AC_SUBST([CAPNG_LIBS])
>>  
>> +dnl libfuse
>> +AC_ARG_WITH([fuse],
>> +AC_HELP_STRING([--with-fuse], [use libfuse to proivde fuse filesystem 
>> support for libvirt lxc]),
>> +[],
>> +[with_fuse=check])
>>  
>> +dnl
>> +dnl This check looks for 'fuse'
>> +dnl
>> +FUSE_CFLAGS=
>> +FUSE_LIBS=
>> +if test "$with_fuse" != "no"; then
>> +old_cflags="$CFLAGS"
>> +old_libs="$LIBS"
>> +old_cppflags="$CPPFLAGS"
>> +CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
>> +if test "$with_fuse" = "check"; then
>> +AC_CHECK_HEADER([fuse.h], [], [with_fuse=no])
>> +AC_CHECK_LIB([fuse], [fuse_main], [], [with_fuse=no])
>> +if test "$with_fuse" != "no"; then
>> +with_fuse="yes"
>> +fi
>> +else
>> +fail=0
>> +AC_CHECK_HEADER([fuse.h], [], [fail=1])
>> +AC_CHECK_LIB([fuse], [fuse_main], [], [fail=1])
>> +test $fail = 1 &&
>> + AC_MSG_ERROR([You must install the fuse >= 2.9.0 development 
>> package in order to compile and run libvirt])
>> +fi
>> +CFLAGS="$old_cflags"
>> +LIBS="$old_libs"
>> +CPPFLAGS="$old_cppflags"
>> +fi
>> +if test "$with_fuse" = "yes"; then
>> +FUSE_LIBS="-lfuse"
>> +FUSE_CFLAGS="-D_FILE_OFFSET_BITS=64"
>> +AC_DEFINE_UNQUOTED([HAVE_FUSE], 1, [Whether fuse is available for 
>> privilege reduction])
>> +fi
>> +AM_CONDITIONAL([HAVE_FUSE], [test "$with_fuse" != "no"])
>> +AC_SUBST([FUSE_CFLAGS])
>> +AC_SUBST([FUSE_LIBS])
> 
> FUSE includes a pkg-config file, so you can remove almost all of this
> code here and just use PKG_CONFIG_CHECK
> 

I see,I will change this in next version.

Thanks!


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

Re: [libvirt] [glib PATCH V3] Add bindings for virDomainSave*()

2012-07-11 Thread Zeeshan Ali (Khattak)
Hi,
  Its getting into a mergable state soon. Some comments/issues still:

Firstly there seems to be trailing whitespaces in this patch. Please
remove those. Haven't yet checked the other patches but please make
sure they don't have those either. More comments inlined:

On Wed, Jul 11, 2012 at 11:42 PM, Jovanka Gulicoska
 wrote:
> ---
>  libvirt-gobject/libvirt-gobject-domain.c |  145 
> ++
>  libvirt-gobject/libvirt-gobject-domain.h |   18 
>  libvirt-gobject/libvirt-gobject.sym  |3 +
>  3 files changed, 166 insertions(+)
>
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
> b/libvirt-gobject/libvirt-gobject-domain.c
> index 088cd33..d9688f7 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -557,6 +557,151 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
>  }
>
>  /**
> + * gvir_domain_save_to_file:
> + * @dom: the domain
> + * @filename: path to the output file
> + * @custom_conf: configuration for domain or NULL
> + * @flags: the flags
> + *
> + * Returns: TRUE on success, FALSE otherwise
> + */
> +gboolean gvir_domain_save_to_file(GVirDomain *dom,
> +  gchar *filename,
> +  GVirConfigDomain *custom_conf,
> +  guint flags,
> +  GError **err)
> +{
> +GVirDomainPrivate *priv;
> +gchar *custom_xml;
> +int ret;
> +
> +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> +g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> +
> +priv = dom->priv;
> +
> +if (flags || (custom_conf != NULL)) {

* No need for '()' around the NULL check.
* You need to do this check again before trying to get xml out of the
object as this condition could be TRUE just because flag was non-zero.
Something like:

char *custom_xml = NULL;

if (custom_conf != NULL)
custom_xml == ..

> +custom_xml = 
> gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(custom_conf));
> +ret = virDomainSaveFlags(priv->handle, filename, custom_xml, flags);
> +g_free (custom_xml);
> +}
> +else
> +ret = virDomainSave(priv->handle, filename);

Quoting directly from HACKING file:

 - If a brace needs to be used for one clause in an if/else statement,
   it should be used for both clauses, even if the other clauses are
   only single statements. eg

  if (foo) {
 bar;
 wizz;
  } else {
 eek;
  }

   Not

  if (foo) {
 bar;
 wizz;
  } else
 eek;

> +if (ret < 0) {
> +gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
> +   0,
> +   "Unable to save domain to file");
> +return FALSE;
> +}
> +
> +return TRUE;
> +}
> +
> +typedef struct {
> +gchar *filename;
> +gchar *custom_xml;
> +guint flags;
> +} DomainSaveToFileData;
> +
> +static void domain_save_to_file_data_free(DomainSaveToFileData *data)
> +{
> +g_free(data->filename);
> +g_free(data->custom_xml);
> +g_slice_free(DomainSaveToFileData, data);
> +}
> +
> +static void
> +gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
> +GObject *object,
> +GCancellable *cancellable G_GNUC_UNUSED)
> +{
> +GVirDomain *dom = GVIR_DOMAIN(object);
> +DomainSaveToFileData *data;
> +GVirConfigDomain *conf;
> +GError *err = NULL;
> +
> +data = g_simple_async_result_get_op_res_gpointer(res);
> +conf = gvir_domain_get_config(dom, data->flags, &err);
> +
> +if (!gvir_domain_save_to_file(dom, data->filename, conf, data->flags, 
> &err))
> +g_simple_async_result_take_error(res, err);
> +}
> +
> +/**
> + * gvir_domain_save_to_file_async:
> + * @dom: the domain
> + * @filename: path to output file
> + * @custom_conf: configuration for domain

You want to declare this and cancellable as nullable for GIR using
'allow-none' annotation. Check gvir_domain_start_async's doc comment
to see how. Same goes for any nullable parameters in this and other
patches of yours.

> + * @flags: the flags
> + * @cancellable: cancallation object
> + * @callback: (scope async): completion callback
> + * @user_data: (closure): opaque data for callback
> + *
> + * Asynchronous variant of #gvir_domain_save_to_file
> + */
> +void gvir_domain_save_to_file_async(GVirDomain *dom,
> +gchar *filename,
> +GVirConfigDomain *custom_conf,
> +guint flags,
> +GCancellable *cancellable,
> +GAsyncReadyCallback callback,
> +gpointer user_data)
> +{
> +GSimpleAsyncResult *res;
> +DomainSaveToFileData *data;
> +gchar *xml;
> +
> +g_return_if_fail(GVIR_IS_DOMAIN(dom)

[libvirt] Libvirt iSCSI APIs

2012-07-11 Thread Ata Bohra




Hi All, 
 
I am interested in extending libvirt APIs to support iSCSI operations such as: 
add/remove targets, list targets, list remote LUNs, rescan luns etc. The 
intention is to provide an interface that external programs can hook to manage 
iSCSI storage devices on a given hypervisor(I would be adding interfaces for 
ESX first). Looking at the libvirt.c interface for storage driver I'm  unable 
find routines that can be overridden for specific hypervisor. Googling lead to 
a nice blog presentation that provisions VMs on remote LUN(s) for KVM but uses 
virish. (http://berrange.com/tags/iscsi/). 
 
My question is; is this as per design not to expose iSCSI related APIs? Will an 
extention to libvirt.c (_virStorageDriver) so that every hypervisor can 
implement it is acceptable? Please correct me if I am missing something serious 
here. 
 
Thanks!
Ata


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

[libvirt] ESX: Add routines to interface driver

2012-07-11 Thread Ata Bohra
From: Ata E Husain Bohra 

Add following routines to esx_interface_driver:
esxNumOfInterfaces,
esxNumOfDefinedInterfaces,
esxListInterfaces,
esxListDefinedInterfaces,
esxInterfaceLookupByMACString,
esxInterfaceGetXMLDesc,
esxInterfaceUndefine,
esxInterfaceCreate,
esxInterfaceDestroy

Signed-off-by: Ata E Husain Bohra 
---
 src/esx/esx_interface_driver.c |  506 +++-
 src/esx/esx_vi.c   |  126 ++
 src/esx/esx_vi.h   |   10 +
 src/esx/esx_vi_generator.input |  227 ++
 src/esx/esx_vi_generator.py|   31 ++-
 src/esx/esx_vi_types.c |   18 +-
 6 files changed, 913 insertions(+), 5 deletions(-)

diff --git a/src/esx/esx_interface_driver.c b/src/esx/esx_interface_driver.c
index 5713137..b1ba5e2 100644
--- a/src/esx/esx_interface_driver.c
+++ b/src/esx/esx_interface_driver.c
@@ -23,6 +23,9 @@
  */

 #include 
+#include 
+#include 
+#include 

 #include "internal.h"
 #include "util.h"
@@ -34,6 +37,7 @@
 #include "esx_vi.h"
 #include "esx_vi_methods.h"
 #include "esx_util.h"
+#include "interface_conf.h"

 #define VIR_FROM_THIS VIR_FROM_ESX

@@ -67,10 +71,508 @@ esxInterfaceClose(virConnectPtr conn)



+static int
+esxNumOfInterfaces(virConnectPtr conn)
+{
+esxPrivate *priv = conn->interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+int count = 0;
+
+if (esxVI_EnsureSession(priv->primary) < 0 ||
+esxVI_LookupVirtualNicList(priv->primary, &virtualNicList) < 0) {
+goto cleanup;
+}
+
+if (virtualNicList == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+_("Could not retrieve vNic List"));
+
+goto cleanup;
+}
+
+for (virtualNic = virtualNicList;
+ virtualNic != NULL;
+ virtualNic = virtualNic->_next) {
+count++;
+}
+
+cleanup:
+
+esxVI_HostVirtualNic_Free(&virtualNicList);
+
+return count;
+}
+
+
+
+static int
+esxNumOfDefinedInterfaces(virConnectPtr conn)
+{
+conn->interfacePrivateData = NULL;
+
+// ESX interfaces are always active
+return 0;
+}
+
+
+
+static int
+esxListInterfaces(virConnectPtr conn, char **names, int maxnames)
+{
+esxPrivate *priv = conn->interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+int result = -1;
+int i = 0;
+
+if (esxVI_EnsureSession(priv->primary) < 0 ||
+esxVI_LookupVirtualNicList(priv->primary,
+   &virtualNicList) < 0) {
+goto cleanup;
+}
+
+if (virtualNicList == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+_("Could not retrieve vNIC List"));
+goto cleanup;
+}
+
+for (i= 0, virtualNic = virtualNicList;
+ virtualNic != NULL && i < maxnames;
+ ++i, virtualNic = virtualNic->_next) {
+names[i] = strdup(virtualNic->device);
+
+if (names[i] == NULL) {
+for(;i >=0;--i) {
+VIR_FREE(names[i]);
+}
+virReportOOMError();
+goto cleanup;
+}
+}
+
+result = i;
+ cleanup:
+esxVI_HostVirtualNic_Free(&virtualNicList);
+
+return result;
+}
+
+
+
+static int
+esxListDefinedInterfaces(virConnectPtr conn, char **names, int maxnames)
+{
+conn->interfacePrivateData = conn->privateData;
+*names = NULL;
+
+/* keeps compiler happy */
+VIR_DEBUG("max interfaces: %d", maxnames);
+
+// ESX interfaces are always active
+return 0;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByName(virConnectPtr conn, const char *name)
+{
+esxPrivate *priv = conn->interfacePrivateData;
+esxVI_HostVirtualNic *virtualNicList = NULL;
+const esxVI_HostVirtualNic *virtualNic = NULL;
+virInterfacePtr ret = NULL;
+
+if (esxVI_EnsureSession(priv->primary) < 0 ||
+esxVI_LookupVirtualNicList(priv->primary,
+   &virtualNicList) < 0) {
+goto cleanup;
+}
+
+if (virtualNicList == 0) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+_("Could not retrieve vNIC List"));
+goto cleanup;
+}
+
+
+for(virtualNic = virtualNicList;
+virtualNic != NULL;
+virtualNic = virtualNic->_next) {
+if (STREQ(virtualNic->device, name)) {
+if (virtualNic->spec == NULL ||
+virtualNic->spec->mac == NULL) {
+ESX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
+  _("Malformed HostVirtualNicSpec"));
+goto cleanup;
+}
+
+ret = virGetInterface(conn, virtualNic->device, 
virtualNic->spec->mac);
+break;
+}
+}
+
+ cleanup:
+esxVI_HostVirtualNic_Free(&virtualNicList);
+
+return ret;
+}
+
+
+
+static virInterfacePtr
+esxInterfaceLookupByMACString(virConn

Re: [libvirt] [PATCH] virsh: remove extra space between function name and opening brace

2012-07-11 Thread Guido Günther
On Wed, Jul 11, 2012 at 11:11:46AM +0200, Peter Krempa wrote:
> On 07/11/12 10:39, Guido Günther wrote:
> >to match our CodingStyle.
> >---
> >This avoids c'n'p problems as seen in my recent domhostname patch.
> >Cheers,
> >  -- Guido
> >
> >  tools/virsh.c |  186 
> > -
> >  1 file changed, 93 insertions(+), 93 deletions(-)
> >
> 
> I couldn't apply this patch to current head, but it looks OK to me
> and it's a nice cleanup.

I rebased on top of current master and pushed this. Thanks,
 -- Guido

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


[libvirt] [glib PATCH V3] Add bindings for virDomainSave*()

2012-07-11 Thread Jovanka Gulicoska
---
 libvirt-gobject/libvirt-gobject-domain.c |  145 ++
 libvirt-gobject/libvirt-gobject-domain.h |   18 
 libvirt-gobject/libvirt-gobject.sym  |3 +
 3 files changed, 166 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
b/libvirt-gobject/libvirt-gobject-domain.c
index 088cd33..d9688f7 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -557,6 +557,151 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
 }
 
 /**
+ * gvir_domain_save_to_file:
+ * @dom: the domain
+ * @filename: path to the output file
+ * @custom_conf: configuration for domain or NULL
+ * @flags: the flags
+ *
+ * Returns: TRUE on success, FALSE otherwise 
+ */
+gboolean gvir_domain_save_to_file(GVirDomain *dom,
+  gchar *filename,
+  GVirConfigDomain *custom_conf,
+  guint flags,
+  GError **err)
+{
+GVirDomainPrivate *priv;
+gchar *custom_xml;
+int ret;
+
+g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE); 
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+priv = dom->priv;
+
+if (flags || (custom_conf != NULL)) {
+custom_xml = 
gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(custom_conf));
+ret = virDomainSaveFlags(priv->handle, filename, custom_xml, flags);
+g_free (custom_xml);
+}
+else 
+ret = virDomainSave(priv->handle, filename);
+
+if (ret < 0) {
+gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+   0,
+   "Unable to save domain to file");
+return FALSE;
+}
+
+return TRUE;
+}
+
+typedef struct {
+gchar *filename;
+gchar *custom_xml;
+guint flags;
+} DomainSaveToFileData;
+
+static void domain_save_to_file_data_free(DomainSaveToFileData *data)
+{
+g_free(data->filename);
+g_free(data->custom_xml);
+g_slice_free(DomainSaveToFileData, data);
+}
+
+static void
+gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
+GObject *object,
+GCancellable *cancellable G_GNUC_UNUSED)
+{
+GVirDomain *dom = GVIR_DOMAIN(object);
+DomainSaveToFileData *data;
+GVirConfigDomain *conf;
+GError *err = NULL;
+
+data = g_simple_async_result_get_op_res_gpointer(res);
+conf = gvir_domain_get_config(dom, data->flags, &err);
+
+if (!gvir_domain_save_to_file(dom, data->filename, conf, data->flags, 
&err))
+g_simple_async_result_take_error(res, err);
+}
+
+/**
+ * gvir_domain_save_to_file_async:
+ * @dom: the domain
+ * @filename: path to output file
+ * @custom_conf: configuration for domain
+ * @flags: the flags
+ * @cancellable: cancallation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_domain_save_to_file
+ */
+void gvir_domain_save_to_file_async(GVirDomain *dom,
+gchar *filename,
+GVirConfigDomain *custom_conf,
+guint flags,
+GCancellable *cancellable,
+GAsyncReadyCallback callback,
+gpointer user_data)
+{
+GSimpleAsyncResult *res;
+DomainSaveToFileData *data;
+gchar *xml;
+
+g_return_if_fail(GVIR_IS_DOMAIN(dom));
+g_return_if_fail(GVIR_CONFIG_IS_DOMAIN (custom_conf));
+g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(custom_conf));
+
+data = g_slice_new0(DomainSaveToFileData);
+data->filename = g_strdup(filename);
+data->custom_xml = g_strdup(xml);
+data->flags = flags;
+
+res = g_simple_async_result_new(G_OBJECT(dom),
+callback,
+user_data,
+gvir_domain_save_to_file_async);
+g_simple_async_result_set_op_res_gpointer(res, data, 
(GDestroyNotify)domain_save_to_file_data_free);
+
+g_simple_async_result_run_in_thread(res,
+gvir_domain_save_to_file_helper,
+G_PRIORITY_DEFAULT,
+cancellable);
+
+g_object_unref(res);
+}
+
+/**
+ * gvir_domain_save_to_file_finish:
+ * @dom: the domain to save
+ * @result: (transfer none): async method result
+ * @err: Place-holder for possible errors
+ *
+ * Finishes the operation started by #gvir_domain_save_to_file_async.
+ *
+ * Returns: TRUE if domain was saved successfully, FALSE otherwise.
+ */
+gboolean gvir_domain_save_to_file_finish(GVirDomain *dom,
+ GAsyncResult *result,
+ 

Re: [libvirt] CPU tuning in containers

2012-07-11 Thread Eric Blake
On 07/11/2012 12:29 PM, Sukadev Bhattiprolu wrote:
> 
> Following section indicates that CPU tuning with  and 
> tags are only supported for QEMU
> 
>   http://libvirt.org/formatdomain.html#elementsCPUTuning
> 
> I see this commit in libvirt.git:
> 
> commit d9724a81b3c53a40f45bf76067a976cce73ed278
> Author: Daniel P. Berrange 
> Date:   Thu Nov 10 12:16:26 2011 +
> 
> Add support for CPU quota/period to LXC driver
> 
> and the code seems to be included in libvirt-0.9.10-21.el6.

Good catch - that patch forgot a doc update.

> 
> I have not had a chance to try on latest libvirt yet, but is it just
> that the CPUTuning section on the above wiki needs an update ? 

That page is actually not a wiki, but maintained from a file in
libvirt.git: see docs/formatdomain.html.in.  Would you like to try your
hand at submitting a patch?

-- 
Eric Blake   ebl...@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] [Qemu-devel] [PATCH v4 2/7] qapi: Convert getfd and closefd

2012-07-11 Thread Luiz Capitulino
On Fri, 22 Jun 2012 14:36:09 -0400
Corey Bryant  wrote:

> Signed-off-by: Corey Bryant 

I've cherry-picked this one into the qmp tree.

> ---
> v2:
>  -Convert getfd and closefd to QAPI (lcapitul...@redhat.com)
>  -Remove changes that returned fd from getfd (lcapitul...@redhat.com)
>  -Wrap hmp_* functions around qmp_* functions (kw...@redhat.com)
>  -Move hmp_* functions to hmp.c (lcapitul...@redhat.com)
>  -Drop .user_print lines (lcapitul...@redhat.com)
>  -Use 'cmd' instead of 'cmd_new' for HMP (lcapitul...@redhat.com)
>  -Change QMP command existance back to 0.14 (lcapitul...@redhat.com)
> 
> v3:
>  -Remove unnecessary return statements from qmp_* functions
>   (lcapitul...@redhat.com)
>  -Add notes to QMP command describing behavior in more detail
>   (lcapitul...@redhat.com, ebl...@redhat.com)
> 
> v4:
>  -No changes
> 
>  hmp-commands.hx  |6 ++
>  hmp.c|   18 ++
>  hmp.h|2 ++
>  monitor.c|   32 ++--
>  qapi-schema.json |   35 +++
>  qmp-commands.hx  |   14 ++
>  6 files changed, 81 insertions(+), 26 deletions(-)
> 
> diff --git a/hmp-commands.hx b/hmp-commands.hx
> index f5d9d91..eea8b32 100644
> --- a/hmp-commands.hx
> +++ b/hmp-commands.hx
> @@ -1236,8 +1236,7 @@ ETEXI
>  .args_type  = "fdname:s",
>  .params = "getfd name",
>  .help   = "receive a file descriptor via SCM rights and assign 
> it a name",
> -.user_print = monitor_user_noop,
> -.mhandler.cmd_new = do_getfd,
> +.mhandler.cmd = hmp_getfd,
>  },
>  
>  STEXI
> @@ -1253,8 +1252,7 @@ ETEXI
>  .args_type  = "fdname:s",
>  .params = "closefd name",
>  .help   = "close a file descriptor previously passed via SCM 
> rights",
> -.user_print = monitor_user_noop,
> -.mhandler.cmd_new = do_closefd,
> +.mhandler.cmd = hmp_closefd,
>  },
>  
>  STEXI
> diff --git a/hmp.c b/hmp.c
> index 2ce8cb9..6241856 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -999,3 +999,21 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
>  qmp_netdev_del(id, &err);
>  hmp_handle_error(mon, &err);
>  }
> +
> +void hmp_getfd(Monitor *mon, const QDict *qdict)
> +{
> +const char *fdname = qdict_get_str(qdict, "fdname");
> +Error *errp = NULL;
> +
> +qmp_getfd(fdname, &errp);
> +hmp_handle_error(mon, &errp);
> +}
> +
> +void hmp_closefd(Monitor *mon, const QDict *qdict)
> +{
> +const char *fdname = qdict_get_str(qdict, "fdname");
> +Error *errp = NULL;
> +
> +qmp_closefd(fdname, &errp);
> +hmp_handle_error(mon, &errp);
> +}
> diff --git a/hmp.h b/hmp.h
> index 79d138d..8d2b0d7 100644
> --- a/hmp.h
> +++ b/hmp.h
> @@ -64,5 +64,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict);
>  void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict);
>  void hmp_netdev_add(Monitor *mon, const QDict *qdict);
>  void hmp_netdev_del(Monitor *mon, const QDict *qdict);
> +void hmp_getfd(Monitor *mon, const QDict *qdict);
> +void hmp_closefd(Monitor *mon, const QDict *qdict);
>  
>  #endif
> diff --git a/monitor.c b/monitor.c
> index a3bc2c7..1a7f7e7 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2182,48 +2182,45 @@ static void do_inject_mce(Monitor *mon, const QDict 
> *qdict)
>  }
>  #endif
>  
> -static int do_getfd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_getfd(const char *fdname, Error **errp)
>  {
> -const char *fdname = qdict_get_str(qdict, "fdname");
>  mon_fd_t *monfd;
>  int fd;
>  
> -fd = qemu_chr_fe_get_msgfd(mon->chr);
> +fd = qemu_chr_fe_get_msgfd(cur_mon->chr);
>  if (fd == -1) {
> -qerror_report(QERR_FD_NOT_SUPPLIED);
> -return -1;
> +error_set(errp, QERR_FD_NOT_SUPPLIED);
> +return;
>  }
>  
>  if (qemu_isdigit(fdname[0])) {
> -qerror_report(QERR_INVALID_PARAMETER_VALUE, "fdname",
> -  "a name not starting with a digit");
> -return -1;
> +error_set(errp, QERR_INVALID_PARAMETER_VALUE, "fdname",
> +  "a name not starting with a digit");
> +return;
>  }
>  
> -QLIST_FOREACH(monfd, &mon->fds, next) {
> +QLIST_FOREACH(monfd, &cur_mon->fds, next) {
>  if (strcmp(monfd->name, fdname) != 0) {
>  continue;
>  }
>  
>  close(monfd->fd);
>  monfd->fd = fd;
> -return 0;
> +return;
>  }
>  
>  monfd = g_malloc0(sizeof(mon_fd_t));
>  monfd->name = g_strdup(fdname);
>  monfd->fd = fd;
>  
> -QLIST_INSERT_HEAD(&mon->fds, monfd, next);
> -return 0;
> +QLIST_INSERT_HEAD(&cur_mon->fds, monfd, next);
>  }
>  
> -static int do_closefd(Monitor *mon, const QDict *qdict, QObject **ret_data)
> +void qmp_closefd(const char *fdname, Error **errp)
>  {
> -const char *fdname = qdict_get_str(qdict, "fdname");
>  mon_fd_t *monfd;
>  
> -QLIST_

[libvirt] CPU tuning in containers

2012-07-11 Thread Sukadev Bhattiprolu

Following section indicates that CPU tuning with  and 
tags are only supported for QEMU

http://libvirt.org/formatdomain.html#elementsCPUTuning

I see this commit in libvirt.git:

commit d9724a81b3c53a40f45bf76067a976cce73ed278
Author: Daniel P. Berrange 
Date:   Thu Nov 10 12:16:26 2011 +

Add support for CPU quota/period to LXC driver

and the code seems to be included in libvirt-0.9.10-21.el6.

I have not had a chance to try on latest libvirt yet, but is it just
that the CPUTuning section on the above wiki needs an update ? 

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


Re: [libvirt] [glib PATCH] Add gvir_connection_domain_restore() and gvir_connection_domain_restore_async()

2012-07-11 Thread Jovanka Gulicoska
I've sent version 2 of this PATCH. I've changed this one since I saw your
comments on gvir_save_to_file_domain.


On Wed, Jul 11, 2012 at 6:18 PM, Zeeshan Ali (Khattak)
wrote:

> Hi,
>Forgot review this one. Mostly its the same things I noticed here
> as the last one.
>
> On Wed, Jul 11, 2012 at 8:28 AM, Jovanka Gulicoska
>  wrote:
> > ---
> >  libvirt-gobject/libvirt-gobject-connection.c |  136
> ++
> >  libvirt-gobject/libvirt-gobject-connection.h |   19 
> >  libvirt-gobject/libvirt-gobject.sym  |3 +
> >  3 files changed, 158 insertions(+)
> >
> > diff --git a/libvirt-gobject/libvirt-gobject-connection.c
> b/libvirt-gobject/libvirt-gobject-connection.c
> > index 3a99034..2302328 100644
> > --- a/libvirt-gobject/libvirt-gobject-connection.c
> > +++ b/libvirt-gobject/libvirt-gobject-connection.c
> > @@ -57,6 +57,7 @@ enum {
> >  VIR_CONNECTION_CLOSED,
> >  VIR_DOMAIN_ADDED,
> >  VIR_DOMAIN_REMOVED,
> > +VIR_DOMAIN_RESTORED,
>
> Same as in previous patch: no additional signal needed.
>
> >  LAST_SIGNAL
> >  };
> >
> > @@ -228,6 +229,15 @@ static void
> gvir_connection_class_init(GVirConnectionClass *klass)
> >   1,
> >   GVIR_TYPE_DOMAIN);
> >
> > +signals[VIR_DOMAIN_RESTORED] = g_signal_new("domain-restored",
> > +
>  G_OBJECT_CLASS_TYPE(object_class),
> > +G_SIGNAL_RUN_FIRST,
> > +
>  G_STRUCT_OFFSET(GVirConnectionClass, domain_restored),
> > +NULL, NULL,
> > +
>  g_cclosure_marshal_VOID__OBJECT,
> > +G_TYPE_NONE,
> > +0);
> > +
> >  g_type_class_add_private(klass, sizeof(GVirConnectionPrivate));
> >  }
> >
> > @@ -1605,3 +1615,129 @@
> gvir_connection_get_capabilities_finish(GVirConnection *conn,
> >
> >  return g_object_ref(caps);
> >  }
> > +
> > +/*
> > + * gvir_connection_domain_restore
> > + */
> > +gboolean gvir_connection_domain_restore(GVirConnection *conn,
> > +gchar *filename,
> > +GVirConfigDomain *conf,
>
> Now that I think of it, I think 'custom_conf' would be a better name
> for this parameter. Same for the previous patch.
>
> > +guint flags,
> > +GError **err)
> > +{
> > +GVirConnectionPrivate *priv;
> > +gchar *custom_xml;
> > +int ret;
> > +
> > +g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
> > +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
> > +g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
> > +
> > +priv = conn->priv;
> > +custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
> > +
> > +g_return_val_if_fail(custom_xml != NULL, FALSE);
> > +
> > +if(flags || custom_xml) {
>
> Same here:
>
>  if(flags || custom_xml != NULL)
>
> Oh and now I realize that you are checking for the string extracted
> from the parameter for being NULL. You want to check 'conf' itself to
> be NULL here and then extract the XML string before using it. You'll
> wan to remove one of the g_return_val_if_fail above to allow user to
> pass NULL as conf.
>
> Same goes for the previous patch too.
>
> > +   ret = virDomainRestoreFlags(priv->conn, filename, custom_xml,
> flags);
> > +   g_free (custom_xml);
> > +}
> > +else {
> > +   ret = virDomainRestore(priv->conn, filename);
> > +   g_free (custom_xml);
> > +}
> > +
> > +if(ret < 0) {
> > +   gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
> > +  0,
> > +  "Unable to restore domain");
> > +
> > +   return FALSE;
> > +}
> > +
> > +return TRUE;
> > +}
> > +
> > +typedef struct {
> > +gchar *filename;
> > +gchar *custom_xml;
> > +guint flags;
> > +} DomainRestoreFromFileData;
>
> Since we are using essentially the same data as for
> gvir_connection_domain_save, I think we can simply re-use that:
>
> #define DomainRestoreFromFileData DomainSaveFromFileData
>
> > +static void
> domain_restore_from_file_data_free(DomainRestoreFromFileData *data)
> > +{
>
> Same goes for this function.
>
> > +g_slice_free(DomainRestoreFromFileData, data);
> > +}
> > +
> > +static void
> > +gvir_connection_domain_restore_helper(GSimpleAsyncResult *res,
> > +  GObject *object,
> > +  GCancellable *cancellable
> G_GNUC_UNUSED)
> > +{
> > +GVirConnection *conn = GVIR_CONNECTION(object);
> > +DomainRestoreFromFileData *data;
> > +GVirConfigDomain *conf;
> > +GError *err = NULL;
> > +
> > +data = g_simple_async_result_get_op_res_gpointer(res);
> > +conf =  gvir_config_domain_new_from_xml(data->custom_xml, &err);
> > +
> > +if(!gvir_con

Re: [libvirt] [PATCH] Support creation of sparse LVM volumes

2012-07-11 Thread Eric Blake
On 07/11/2012 10:30 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> When calling 'lvcreate' if specifying both the '-L' and
> '--virtualsize' options, the latter will be treated as
> the capacity and the former as the allocation. This can
> be used to support sparse volume creation. In addition,
> when listing volumes it is neccessary to include the 'size'

s/neccessary/necessary/

> field in lvs output, so that we can detect sparse volume
> allocation correctly.
> ---
>  src/storage/storage_backend_logical.c |   27 ++-
>  1 files changed, 18 insertions(+), 9 deletions(-)
> 

ACK.

-- 
Eric Blake   ebl...@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] Remove all use of virRun in storage code

2012-07-11 Thread Eric Blake
On 07/11/2012 10:30 AM, Daniel P. Berrange wrote:
> From: "Daniel P. Berrange" 
> 
> To make it easier to dynamically change the command line ARGV,
> switch all storage code over to use virCommandPtr APIs for
> running programs
> 
> Signed-off-by: Daniel P. Berrange 
> ---

> @@ -1623,8 +1617,8 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
>  }
>  
>  if (feof (fp) < 0) {
> -virReportSystemError(errno,
> - _("read error on pipe to '%s'"), prog[0]);
> +virReportSystemError(errno, "%s",
> + _("read error on pipe"));

Is it worth s/feof /feof/ while touching this hunk?

Other than that, ACK.

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



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

[libvirt] [PATCH] Support creation of sparse LVM volumes

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

When calling 'lvcreate' if specifying both the '-L' and
'--virtualsize' options, the latter will be treated as
the capacity and the former as the allocation. This can
be used to support sparse volume creation. In addition,
when listing volumes it is neccessary to include the 'size'
field in lvs output, so that we can detect sparse volume
allocation correctly.
---
 src/storage/storage_backend_logical.c |   27 ++-
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/storage/storage_backend_logical.c 
b/src/storage/storage_backend_logical.c
index 9fe769b..c6e09e6 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -171,6 +171,11 @@ virStorageBackendLogicalMakeVol(virStoragePoolObjPtr pool,
   "%s", _("malformed volume extent size value"));
 goto cleanup;
 }
+if (virStrToLong_ull(groups[8], NULL, 10, &vol->allocation) < 0) {
+virStorageReportError(VIR_ERR_INTERNAL_ERROR,
+  "%s", _("malformed volume allocation value"));
+goto cleanup;
+}
 
 /* Now parse the "devices" field separately */
 regex = strdup(regex_unit);
@@ -271,12 +276,12 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
 virStorageVolDefPtr vol)
 {
 /*
- *  # lvs --separator , --noheadings --units b --unbuffered --nosuffix 
--options "lv_name,origin,uuid,devices,seg_size,vg_extent_size" VGNAME
- *  
RootLV,,06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky,/dev/hda2(0),5234491392,33554432
- *  
SwapLV,,oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M,/dev/hda2(156),1040187392,33554432
- *  
Test2,,3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR,/dev/hda2(219),1073741824,33554432
- *  
Test3,,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(251),2181038080,33554432
- *  
Test3,Test2,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(187),1040187392,33554432
+ *  # lvs --separator , --noheadings --units b --unbuffered --nosuffix 
--options "lv_name,origin,uuid,devices,seg_size,vg_extent_size,size" VGNAME
+ *  
RootLV,,06UgP5-2rhb-w3Bo-3mdR-WeoL-pytO-SAa2ky,/dev/hda2(0),5234491392,33554432,5234491392
+ *  
SwapLV,,oHviCK-8Ik0-paqS-V20c-nkhY-Bm1e-zgzU0M,/dev/hda2(156),1040187392,33554432,1040187392
+ *  
Test2,,3pg3he-mQsA-5Sui-h0i6-HNmc-Cz7W-QSndcR,/dev/hda2(219),1073741824,33554432,1073741824
+ *  
Test3,,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(251),2181038080,33554432,2181038080
+ *  
Test3,Test2,UB5hFw-kmlm-LSoX-EI1t-ioVd-h7GL-M0W8Ht,/dev/hda2(187),1040187392,33554432,1040187392
  *
  * Pull out name, origin, & uuid, device, device extent start #, segment 
size, extent size.
  *
@@ -290,10 +295,10 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
  *striped, so "," is not a suitable separator either (rhbz 727474).
  */
 const char *regexes[] = {
-   
"^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#?\\s*$"
+   
"^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#([0-9]+)#?\\s*$"
 };
 int vars[] = {
-8
+9
 };
 int ret = -1;
 virCommandPtr cmd;
@@ -304,7 +309,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
"--units", "b",
"--unbuffered",
"--nosuffix",
-   "--options", 
"lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size",
+   "--options", 
"lv_name,origin,uuid,devices,segtype,stripes,seg_size,vg_extent_size,size",
pool->def->source.name,
NULL);
 if (virStorageBackendRunProgRegex(pool,
@@ -718,6 +723,10 @@ virStorageBackendLogicalCreateVol(virConnectPtr conn,
"--name", vol->name,
NULL);
 virCommandAddArg(cmd, "-L");
+if (vol->capacity != vol->allocation) {
+virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->allocation, 
1024));
+virCommandAddArg(cmd, "--virtualsize");
+}
 virCommandAddArgFormat(cmd, "%lluK", VIR_DIV_UP(vol->capacity, 1024));
 if (vol->backingStore.path)
 virCommandAddArgPair(cmd, "-s", vol->backingStore.path);
-- 
1.7.7.6

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


[libvirt] [PATCH] Remove all use of virRun in storage code

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

To make it easier to dynamically change the command line ARGV,
switch all storage code over to use virCommandPtr APIs for
running programs

Signed-off-by: Daniel P. Berrange 
---
 src/storage/storage_backend.c |   15 +--
 src/storage/storage_backend.h |5 +-
 src/storage/storage_backend_disk.c|   93 +++
 src/storage/storage_backend_fs.c  |  134 +---
 src/storage/storage_backend_iscsi.c   |  107 +---
 src/storage/storage_backend_logical.c |  225 ++---
 6 files changed, 294 insertions(+), 285 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index e2e9b51..e0ff717 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -57,7 +57,6 @@
 #include "storage_backend.h"
 #include "logging.h"
 #include "virfile.h"
-#include "command.h"
 
 #if WITH_STORAGE_LVM
 # include "storage_backend_logical.h"
@@ -1418,7 +1417,7 @@ virStorageBackendStablePath(virStoragePoolObjPtr pool,
  */
 int
 virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
-  const char *const*prog,
+  virCommandPtr cmd,
   int nregex,
   const char **regex,
   int *nvars,
@@ -1433,7 +1432,6 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
 int maxReg = 0, i, j;
 int totgroups = 0, ngroup = 0, maxvars = 0;
 char **groups;
-virCommandPtr cmd = NULL;
 
 /* Compile all regular expressions */
 if (VIR_ALLOC_N(reg, nregex) < 0) {
@@ -1470,7 +1468,6 @@ virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
 goto cleanup;
 }
 
-cmd = virCommandNewArgs(prog);
 virCommandSetOutputFD(cmd, &fd);
 if (virCommandRunAsync(cmd, NULL) < 0) {
 goto cleanup;
@@ -1541,7 +1538,6 @@ cleanup:
 regfree(®[i]);
 
 VIR_FREE(reg);
-virCommandFree(cmd);
 
 VIR_FORCE_FCLOSE(list);
 VIR_FORCE_CLOSE(fd);
@@ -1562,7 +1558,7 @@ cleanup:
  */
 int
 virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
-const char **prog,
+virCommandPtr cmd,
 size_t n_columns,
 virStorageBackendListVolNulFunc func,
 void *data)
@@ -1573,7 +1569,6 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
 char **v;
 int ret = -1;
 int i;
-virCommandPtr cmd = NULL;
 
 if (n_columns == 0)
 return -1;
@@ -1585,7 +1580,6 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
 for (i = 0; i < n_columns; i++)
 v[i] = NULL;
 
-cmd = virCommandNewArgs(prog);
 virCommandSetOutputFD(cmd, &fd);
 if (virCommandRunAsync(cmd, NULL) < 0) {
 goto cleanup;
@@ -1623,8 +1617,8 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
 }
 
 if (feof (fp) < 0) {
-virReportSystemError(errno,
- _("read error on pipe to '%s'"), prog[0]);
+virReportSystemError(errno, "%s",
+ _("read error on pipe"));
 goto cleanup;
 }
 
@@ -1633,7 +1627,6 @@ virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
 for (i = 0; i < n_columns; i++)
 VIR_FREE(v[i]);
 VIR_FREE(v);
-virCommandFree(cmd);
 
 VIR_FORCE_FCLOSE(fp);
 VIR_FORCE_CLOSE(fd);
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index a37bf7c..4c371fb 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -27,6 +27,7 @@
 # include 
 # include "internal.h"
 # include "storage_conf.h"
+# include "command.h"
 
 typedef char * (*virStorageBackendFindPoolSources)(virConnectPtr conn, const 
char *srcSpec, unsigned int flags);
 typedef int (*virStorageBackendCheckPool)(virConnectPtr conn, 
virStoragePoolObjPtr pool, bool *active);
@@ -141,7 +142,7 @@ typedef int 
(*virStorageBackendListVolNulFunc)(virStoragePoolObjPtr pool,
void *data);
 
 int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
-  const char *const*prog,
+  virCommandPtr cmd,
   int nregex,
   const char **regex,
   int *nvars,
@@ -149,7 +150,7 @@ int virStorageBackendRunProgRegex(virStoragePoolObjPtr pool,
   void *data, const char *cmd_to_ignore);
 
 int virStorageBackendRunProgNul(virStoragePoolObjPtr pool,
-const char **prog,
+virCommandPtr cmd,
 size_t n_columns,
 virStorageBackendListVolNulFunc func,
 void *data);
diff --git a/src/sto

Re: [libvirt] [glib PATCH] Add gvir_connection_domain_restore() and gvir_connection_domain_restore_async()

2012-07-11 Thread Zeeshan Ali (Khattak)
Hi,
   Forgot review this one. Mostly its the same things I noticed here
as the last one.

On Wed, Jul 11, 2012 at 8:28 AM, Jovanka Gulicoska
 wrote:
> ---
>  libvirt-gobject/libvirt-gobject-connection.c |  136 
> ++
>  libvirt-gobject/libvirt-gobject-connection.h |   19 
>  libvirt-gobject/libvirt-gobject.sym  |3 +
>  3 files changed, 158 insertions(+)
>
> diff --git a/libvirt-gobject/libvirt-gobject-connection.c 
> b/libvirt-gobject/libvirt-gobject-connection.c
> index 3a99034..2302328 100644
> --- a/libvirt-gobject/libvirt-gobject-connection.c
> +++ b/libvirt-gobject/libvirt-gobject-connection.c
> @@ -57,6 +57,7 @@ enum {
>  VIR_CONNECTION_CLOSED,
>  VIR_DOMAIN_ADDED,
>  VIR_DOMAIN_REMOVED,
> +VIR_DOMAIN_RESTORED,

Same as in previous patch: no additional signal needed.

>  LAST_SIGNAL
>  };
>
> @@ -228,6 +229,15 @@ static void 
> gvir_connection_class_init(GVirConnectionClass *klass)
>   1,
>   GVIR_TYPE_DOMAIN);
>
> +signals[VIR_DOMAIN_RESTORED] = g_signal_new("domain-restored",
> +
> G_OBJECT_CLASS_TYPE(object_class),
> +G_SIGNAL_RUN_FIRST,
> +
> G_STRUCT_OFFSET(GVirConnectionClass, domain_restored),
> +NULL, NULL,
> +
> g_cclosure_marshal_VOID__OBJECT,
> +G_TYPE_NONE,
> +0);
> +
>  g_type_class_add_private(klass, sizeof(GVirConnectionPrivate));
>  }
>
> @@ -1605,3 +1615,129 @@ 
> gvir_connection_get_capabilities_finish(GVirConnection *conn,
>
>  return g_object_ref(caps);
>  }
> +
> +/*
> + * gvir_connection_domain_restore
> + */
> +gboolean gvir_connection_domain_restore(GVirConnection *conn,
> +gchar *filename,
> +GVirConfigDomain *conf,

Now that I think of it, I think 'custom_conf' would be a better name
for this parameter. Same for the previous patch.

> +guint flags,
> +GError **err)
> +{
> +GVirConnectionPrivate *priv;
> +gchar *custom_xml;
> +int ret;
> +
> +g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
> +g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
> +
> +priv = conn->priv;
> +custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
> +
> +g_return_val_if_fail(custom_xml != NULL, FALSE);
> +
> +if(flags || custom_xml) {

Same here:

 if(flags || custom_xml != NULL)

Oh and now I realize that you are checking for the string extracted
from the parameter for being NULL. You want to check 'conf' itself to
be NULL here and then extract the XML string before using it. You'll
wan to remove one of the g_return_val_if_fail above to allow user to
pass NULL as conf.

Same goes for the previous patch too.

> +   ret = virDomainRestoreFlags(priv->conn, filename, custom_xml, flags);
> +   g_free (custom_xml);
> +}
> +else {
> +   ret = virDomainRestore(priv->conn, filename);
> +   g_free (custom_xml);
> +}
> +
> +if(ret < 0) {
> +   gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
> +  0,
> +  "Unable to restore domain");
> +
> +   return FALSE;
> +}
> +
> +return TRUE;
> +}
> +
> +typedef struct {
> +gchar *filename;
> +gchar *custom_xml;
> +guint flags;
> +} DomainRestoreFromFileData;

Since we are using essentially the same data as for
gvir_connection_domain_save, I think we can simply re-use that:

#define DomainRestoreFromFileData DomainSaveFromFileData

> +static void domain_restore_from_file_data_free(DomainRestoreFromFileData 
> *data)
> +{

Same goes for this function.

> +g_slice_free(DomainRestoreFromFileData, data);
> +}
> +
> +static void
> +gvir_connection_domain_restore_helper(GSimpleAsyncResult *res,
> +  GObject *object,
> +  GCancellable *cancellable 
> G_GNUC_UNUSED)
> +{
> +GVirConnection *conn = GVIR_CONNECTION(object);
> +DomainRestoreFromFileData *data;
> +GVirConfigDomain *conf;
> +GError *err = NULL;
> +
> +data = g_simple_async_result_get_op_res_gpointer(res);
> +conf =  gvir_config_domain_new_from_xml(data->custom_xml, &err);
> +
> +if(!gvir_connection_domain_restore(conn, data->filename, conf, 
> data->flags, &err))
> +   g_simple_async_result_take_error(res, err);
> +}
> +
> +/*
> + * Async function of gvir_connection_domain_restore
> + */
> +void gvir_connection_domain_restore_async(GVirConnection *conn,
> +  

Re: [libvirt] [glib PATCH V2] Add bindings for virStorageVolDownload() and virStorageVolUpload()

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 03:50:29PM +0200, Jovanka Gulicoska wrote:
> ---
>  libvirt-gobject/libvirt-gobject-storage-vol.c |   75 
> +
>  libvirt-gobject/libvirt-gobject-storage-vol.h |   14 +
>  libvirt-gobject/libvirt-gobject.h |1 +
>  libvirt-gobject/libvirt-gobject.sym   |2 +
>  4 files changed, 92 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c 
> b/libvirt-gobject/libvirt-gobject-storage-vol.c
> index 6f60fcd..7f9aeb7 100644
> --- a/libvirt-gobject/libvirt-gobject-storage-vol.c
> +++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
> @@ -349,3 +349,78 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
>  
>  return TRUE;
>  }
> +
> +/**
> + * gvir_storage_vol_download:
> + * @vol: the storage volume to download from
> + * @stream: stream to use as output
> + * @offset: position in @vol to start reading from
> + * @length: limit on amount of data to download
> + * @flags: extra flags, not used yet, pass 0
> + *
> + * Returns: #TRUE of success, #FALSE otherwise
> + */
> +gboolean gvir_storage_vol_download(GVirStorageVol *vol,
> +   GVirStream *stream,
> +   unsigned long long offset,
> +   unsigned long long length,
> +   guint flags,
> +   GError **err)
> +{
> +virStreamPtr st = NULL;
> +
> +g_object_get(stream, "handle", &st, NULL);

IIRC, g_object_get() will acquire a reference on the objects it
returns, so I think you might need a virStreamFree() call at
the end when you're done.

> +
> +g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
> +g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
> +g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> +
> +if(virStorageVolDownload(vol->priv->handle, st, offset, length, 0) < 0) {

s/if(foo)/if (foo)/

> +   gvir_set_error_literal(err,
> +  GVIR_STORAGE_VOL_ERROR,
> +  0,
> +  "Unable to downlaod volume storage");
> +
> +   return FALSE;
> +}
> +
> +return TRUE;
> +}
> +
> +/**
> + * gvir_storage_vol_upload:
> + * @vol: the storage volume to upload
> + * @stream: stream to use as input
> + * @offset: position in @vol to start to write to
> + * @length: limit on amount of data to upload
> + * @flags: the flags, not set yet, pass 0
> + *
> + * Returns: #TRUE of success, #FALSE otherwise
> + */
> +gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
> + GVirStream *stream,
> + unsigned long long offset,
> + unsigned long long length,
> + guint flags,
> + GError **err)
> +{
> +virStreamPtr st = NULL;
> +
> +g_object_get(stream, "handle", &st, NULL);
> +
> +g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
> +g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
> +g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> +
> +if(virStorageVolUpload(vol->priv->handle, st, offset, length, 0) < 0) {
> +   gvir_set_error_literal(err,
> +  GVIR_STORAGE_VOL_ERROR,
> +  0,
> +  "Unable to upload to stream");
> +
> +   return FALSE;
> +}

Same comments as above.


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [glib PATCH] Add bindings for virDomainSnapshotCreateXML()

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 05:40:43PM +0200, Jovanka Gulicoska wrote:
> ---
>  libvirt-gobject/libvirt-gobject-domain.c |   39 
> ++
>  libvirt-gobject/libvirt-gobject-domain.h |4 +++
>  2 files changed, 43 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
> b/libvirt-gobject/libvirt-gobject-domain.c
> index eda2427..ea621ff 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -1270,3 +1270,42 @@ GList *gvir_domain_get_devices(GVirDomain *domain,
>  
>  return g_list_reverse (ret);
>  }
> +
> +/**
> + * gvir_domain_snapshot_create_xml:
> + * @dom: the domain
> + * @conf: configuration of domain
> + * @flags: the flags
> + * @err: (allow-none):Place-holder for error or NULL
> + *
> + * Returns: snapshot of existing domain
> + */
> +GVirConfigDomainSnapshot *gvir_domain_snapshot_create_xml(GVirDomain *dom,
> +  GVirConfigDomain 
> *conf,

This parameter actually needs to be GVirConfigDomainSnapshot, since the
method below needs the domain-snapshot XML format, not the domain XML
format

> +  guint flags,
> +  GError **err)
> +{
> +GVirDomainPrivate *priv;
> +virDomainSnapshot *snapshot;
> +gchar *xml_desc;
> +
> +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
> +g_return_val_if_fail(err == NULL || *err == NULL, NULL);
> +
> +priv = dom->priv;
> +xml_desc = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
> +
> +if(!(snapshot = virDomainSnapshotCreateXML(priv->handle, xml_desc, 
> flags))) {
> +   gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
> +  0,
> + "Unable to create snapshot of domain");
> +return NULL;
> +
> +}
> +
> +GVirConfigDomainSnapshot *conf_snapshot = 
> gvir_config_domain_snapshot_new_from_xml(xml_desc, err);
> +
> +g_free(xml_desc);
> +return conf_snapshot;
> +}

There seems to be some trailing whitespace on some of these lines - you
can use 'make syntax-check' to validate code style

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [glib PATCH V2] Add bindings for virDomainRestore*()

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 03:38:58PM +0200, Jovanka Gulicoska wrote:
> ---
>  libvirt-gobject/libvirt-gobject-connection.c |  153 
> ++
>  libvirt-gobject/libvirt-gobject-connection.h |   19 
>  libvirt-gobject/libvirt-gobject.sym  |3 +
>  3 files changed, 175 insertions(+)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-connection.c 
> b/libvirt-gobject/libvirt-gobject-connection.c
> index 3a99034..6fbf86b 100644
> --- a/libvirt-gobject/libvirt-gobject-connection.c
> +++ b/libvirt-gobject/libvirt-gobject-connection.c
> @@ -1605,3 +1605,156 @@ 
> gvir_connection_get_capabilities_finish(GVirConnection *conn,
>  
>  return g_object_ref(caps);
>  }
> +
> +/**
> + * gvir_connection_domain_restore:
> + * @conn: a #GVirConnection
> + * @filename: path to input file
> + * @conf: configuration for domain

As with the save method, we should expect @conf to be NULL most
of the time

> + * @flags: the flags
> + *
> + * Returns: TRUE on success, FALSe otherwise
> + */
> +gboolean gvir_connection_domain_restore(GVirConnection *conn,
> +gchar *filename,
> +GVirConfigDomain *conf,
> +guint flags,
> +GError **err)
> +{
> +GVirConnectionPrivate *priv;
> +gchar *custom_xml;
> +int ret;
> +
> +g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
> +g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
> +
> +priv = conn->priv;
> +custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));

So this can be pushed inside the if()

> +
> +g_return_val_if_fail(custom_xml != NULL, FALSE);
> +
> +if(flags || (custom_xml != NULL)) {
> +   ret = virDomainRestoreFlags(priv->conn, filename, custom_xml, flags);
> +   g_free (custom_xml);
> +}
> +else {
> +   ret = virDomainRestore(priv->conn, filename);
> +   g_free (custom_xml);
> +}
> +
> +if(ret < 0) {

Can you make sure to  have a single ' ' between 'if' and the
'(...)'. egif (foo),   not  if(foo)

Conversely, do not put a space after function names, in function
calls.  eg use   g_free(foo), not g_free (foo). This was also an
issue in the first patch.

Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [glib PATCH V2] Add bindings for virDomainSave*()

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 03:33:42PM +0200, Jovanka Gulicoska wrote:
> ---
>  libvirt-gobject/libvirt-gobject-domain.c |  149 
> +-
>  libvirt-gobject/libvirt-gobject-domain.h |   20 +++-
>  libvirt-gobject/libvirt-gobject.sym  |3 +
>  3 files changed, 170 insertions(+), 2 deletions(-)
> 
> diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
> b/libvirt-gobject/libvirt-gobject-domain.c
> index 088cd33..eda2427 100644
> --- a/libvirt-gobject/libvirt-gobject-domain.c
> +++ b/libvirt-gobject/libvirt-gobject-domain.c
> @@ -557,6 +557,153 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
>  }
>  
>  /**
> + * gvir_domain_save_to_file:
> + * @dom: the domain
> + * @filename: path to the output file
> + * @conf: configuration for domain

In most use cases, people won't care about passing a 'conf'
instance, so we need to accept NULL for this.

> + * @flags: the flags
> + *
> + * Returns: TRUE on success, FALSE otherwise 
> + */
> +gboolean gvir_domain_save_to_file(GVirDomain *dom,
> +  gchar *filename,
> +  GVirConfigDomain *conf,
> +  guint flags,
> +  GError **err)
> +{
> +GVirDomainPrivate *priv;
> +gchar *custom_xml;
> +int ret;
> +
> +g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
> +g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);

Need to allow for NULL conf here.

> +g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
> +
> +priv = dom->priv;
> +custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));

So this should be pushed inside the if()

> +   
> +if (flags || (custom_xml != NULL)) {

changing this second clause to  '(conf != NULL)'

> +ret = virDomainSaveFlags(priv->handle, filename, custom_xml, flags);
> +g_free (custom_xml);
> +}
> +else {
> +ret = virDomainSave(priv->handle, filename);
> +g_free (custom_xml);
> +}
> +if (ret < 0) {
> +gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
> + 0,
> + "Unable to save domain to file");
> +return FALSE;
> +}
> +
> +return TRUE;
> +}
> +


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [PATCH] Fix directory removal in virStorageBackendFileSystemVolDelete

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 03:21:27PM +0200, Sascha Peilicke wrote:
> ---
>  src/storage/storage_backend_fs.c |   28 +++-
>  1 file changed, 23 insertions(+), 5 deletions(-)
> 
> diff --git a/src/storage/storage_backend_fs.c 
> b/src/storage/storage_backend_fs.c
> index 4894994..df0aaf8 100644
> --- a/src/storage/storage_backend_fs.c
> +++ b/src/storage/storage_backend_fs.c
> @@ -1127,7 +1127,7 @@ virStorageBackendFileSystemVolBuildFrom(virConnectPtr 
> conn,
>  }
>  
>  /**
> - * Remove a volume - just unlinks for now
> + * Remove a volume - no support for BLOCK and NETWORK yet
>   */
>  static int
>  virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
> @@ -1137,14 +1137,32 @@ virStorageBackendFileSystemVolDelete(virConnectPtr 
> conn ATTRIBUTE_UNUSED,
>  {
>  virCheckFlags(0, -1);
>  
> -if (unlink(vol->target.path) < 0) {
> -/* Silently ignore failures where the vol has already gone away */
> -if (errno != ENOENT) {
> +switch (vol->type) {
> +case VIR_STORAGE_VOL_FILE:
> +if (unlink(vol->target.path) < 0) {
> +/* Silently ignore failures where the vol has already gone away 
> */
> +if (errno != ENOENT) {
> +virReportSystemError(errno,
> + _("cannot unlink file '%s'"),
> + vol->target.path);
> +return -1;
> +}
> +}
> +break;
> +case VIR_STORAGE_VOL_DIR:
> +if (rmdir(vol->target.path) < 0) {
>  virReportSystemError(errno,
> - _("cannot unlink file '%s'"),
> + _("cannot remove directory '%s'"),
>   vol->target.path);
>  return -1;
>  }
> +break;
> +case VIR_STORAGE_VOL_BLOCK:
> +case VIR_STORAGE_VOL_NETWORK:
> +default:
> +virStorageReportError(VIR_ERR_NO_SUPPORT,
> +  _("removing block or network volumes is not 
> supported: %s"),
> +  vol->target.path);

Missing 'return -1' line here.

>  }
>  return 0;
>  }

I fixed that small bug and committed this patch to GIT, adding your
name to AUTHORS.

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


[libvirt] [glib PATCH] Add bindings for virDomainSnapshotCreateXML()

2012-07-11 Thread Jovanka Gulicoska
---
 libvirt-gobject/libvirt-gobject-domain.c |   39 ++
 libvirt-gobject/libvirt-gobject-domain.h |4 +++
 2 files changed, 43 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
b/libvirt-gobject/libvirt-gobject-domain.c
index eda2427..ea621ff 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -1270,3 +1270,42 @@ GList *gvir_domain_get_devices(GVirDomain *domain,
 
 return g_list_reverse (ret);
 }
+
+/**
+ * gvir_domain_snapshot_create_xml:
+ * @dom: the domain
+ * @conf: configuration of domain
+ * @flags: the flags
+ * @err: (allow-none):Place-holder for error or NULL
+ *
+ * Returns: snapshot of existing domain
+ */
+GVirConfigDomainSnapshot *gvir_domain_snapshot_create_xml(GVirDomain *dom,
+  GVirConfigDomain 
*conf,
+  guint flags,
+  GError **err)
+{
+GVirDomainPrivate *priv;
+virDomainSnapshot *snapshot;
+gchar *xml_desc;
+
+g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+
+priv = dom->priv;
+xml_desc = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+if(!(snapshot = virDomainSnapshotCreateXML(priv->handle, xml_desc, 
flags))) {
+   gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+  0,
+ "Unable to create snapshot of domain");
+return NULL;
+
+}
+
+GVirConfigDomainSnapshot *conf_snapshot = 
gvir_config_domain_snapshot_new_from_xml(xml_desc, err);
+
+g_free(xml_desc);
+return conf_snapshot;
+}
diff --git a/libvirt-gobject/libvirt-gobject-domain.h 
b/libvirt-gobject/libvirt-gobject-domain.h
index 49516a7..6540f64 100644
--- a/libvirt-gobject/libvirt-gobject-domain.h
+++ b/libvirt-gobject/libvirt-gobject-domain.h
@@ -220,6 +220,10 @@ gboolean gvir_domain_get_saved(GVirDomain *dom);
 GList *gvir_domain_get_devices(GVirDomain *domain,
GError **err);
 
+GVirConfigDomainSnapshot *gvir_domain_snapshot_create_xml(GVirDomain *dom,
+GVirConfigDomain *conf,
+guint flags,
+GError **err);
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_DOMAIN_H__ */
-- 
1.7.10.4

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


Re: [libvirt] trying to build 0.9.13 on F17: cannot find -lcrypto

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 11:15:07AM -0400, Cole Robinson wrote:
> On 07/11/2012 10:42 AM, Daniel P. Berrange wrote:
> > On Wed, Jul 11, 2012 at 10:23:21AM -0400, Cole Robinson wrote:
> >> In trying to build libvirt 0.9.13 on F17, I'm hitting a link error:
> >>
> >>   ...
> >>   CCLD   libvirt_driver_nodedev.la
> >>   CCLD   libvirt_driver_nwfilter.la
> >> /usr/bin/ld: cannot find -lcrypto
> >>
> >> Full log here:
> >>
> >> http://kojipkgs.fedoraproject.org//work/tasks/3678/4233678/build.log
> >>
> >> I think this comes from rbd support, from configure.ac:
> >>
> >> LIBRBD_LIBS="-lrbd -lrados -lcrypto"
> >>
> >> from this commit:
> >>
> >> http://libvirt.org/git/?p=libvirt.git;a=commit;h=74951eadef85e2d100c7dc7bd9ae1093fbda722f
> >>
> >> What's missing here? RPM BuildRequires, configure change, ...?
> > 
> > If rbd is include '-lcrypto' in its pkgconfig line, then its
> > RPM is responsible for ensuring BuildRequires is set in its
> > own -devel package. So sounds like there's BR missing there.
> > 
> > 
> 
> The package here is ceph-devel. You're saying ceph-devel needs a
> BuildRequires: openssl-devel. Or should that be a plain Requires: ? Otherwise
> how would 'yum install ceph-devel' pull in openssl-devel, or is that one of
> the magic things rpm/yum figures out?

Yeah, ceph-devel should have BuildRequires: openssl-devel

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] trying to build 0.9.13 on F17: cannot find -lcrypto

2012-07-11 Thread Cole Robinson
On 07/11/2012 10:42 AM, Daniel P. Berrange wrote:
> On Wed, Jul 11, 2012 at 10:23:21AM -0400, Cole Robinson wrote:
>> In trying to build libvirt 0.9.13 on F17, I'm hitting a link error:
>>
>>   ...
>>   CCLD   libvirt_driver_nodedev.la
>>   CCLD   libvirt_driver_nwfilter.la
>> /usr/bin/ld: cannot find -lcrypto
>>
>> Full log here:
>>
>> http://kojipkgs.fedoraproject.org//work/tasks/3678/4233678/build.log
>>
>> I think this comes from rbd support, from configure.ac:
>>
>> LIBRBD_LIBS="-lrbd -lrados -lcrypto"
>>
>> from this commit:
>>
>> http://libvirt.org/git/?p=libvirt.git;a=commit;h=74951eadef85e2d100c7dc7bd9ae1093fbda722f
>>
>> What's missing here? RPM BuildRequires, configure change, ...?
> 
> If rbd is include '-lcrypto' in its pkgconfig line, then its
> RPM is responsible for ensuring BuildRequires is set in its
> own -devel package. So sounds like there's BR missing there.
> 
> 

The package here is ceph-devel. You're saying ceph-devel needs a
BuildRequires: openssl-devel. Or should that be a plain Requires: ? Otherwise
how would 'yum install ceph-devel' pull in openssl-devel, or is that one of
the magic things rpm/yum figures out?

Thanks,
Cole

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


Re: [libvirt] [PATCH]POWER Hypervisor: Fix the segment fault issue for the "list" command

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 06:05:28PM +0800, Dennis Chen wrote:
> When connect to the remote IBM HMC/IVM server, the remoteNetworkOpen() called
> after the phypOpen() in do_open function will re-assign a NULL pointer to the
> virConnectPtr conn->networkPrivateData which is allocated in phypOpen(), this
> will result in a segment fault issue when execute the following commands,
> eg, "virsh# list --all"
> 
> Signed-off-by: Dennis Chen
> ---
>  src/remote/remote_driver.c |3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
> index eac50e6..22ef129 100644
> --- a/src/remote/remote_driver.c
> +++ b/src/remote/remote_driver.c
> @@ -2504,7 +2504,8 @@ static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
>  remoteGenericOpen(virConnectPtr conn, virConnectAuthPtr auth,
>unsigned int flags, void **genericPrivateData)
>  {
> -if (inside_daemon)
> +if (inside_daemon ||
> +   STREQ (conn->driver->name, "PHYP"))
>  return VIR_DRV_OPEN_DECLINED;
> 
>  if (conn->driver&&

This needs to be fixed in the PHYP driver code actually. In its
phypRegister() method it should be registering a network driver
impl of its own.


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] trying to build 0.9.13 on F17: cannot find -lcrypto

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 10:23:21AM -0400, Cole Robinson wrote:
> In trying to build libvirt 0.9.13 on F17, I'm hitting a link error:
> 
>   ...
>   CCLD   libvirt_driver_nodedev.la
>   CCLD   libvirt_driver_nwfilter.la
> /usr/bin/ld: cannot find -lcrypto
> 
> Full log here:
> 
> http://kojipkgs.fedoraproject.org//work/tasks/3678/4233678/build.log
> 
> I think this comes from rbd support, from configure.ac:
> 
> LIBRBD_LIBS="-lrbd -lrados -lcrypto"
> 
> from this commit:
> 
> http://libvirt.org/git/?p=libvirt.git;a=commit;h=74951eadef85e2d100c7dc7bd9ae1093fbda722f
> 
> What's missing here? RPM BuildRequires, configure change, ...?

If rbd is include '-lcrypto' in its pkgconfig line, then its
RPM is responsible for ensuring BuildRequires is set in its
own -devel package. So sounds like there's BR missing there.


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


[libvirt] [PATCH]POWER Hypervisor: Fix the segment fault issue for the "list" command

2012-07-11 Thread Dennis Chen

When connect to the remote IBM HMC/IVM server, the remoteNetworkOpen() called
after the phypOpen() in do_open function will re-assign a NULL pointer to the
virConnectPtr conn->networkPrivateData which is allocated in phypOpen(), this
will result in a segment fault issue when execute the following commands,
eg, "virsh# list --all"

Signed-off-by: Dennis Chen
---
 src/remote/remote_driver.c |3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index eac50e6..22ef129 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2504,7 +2504,8 @@ static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
 remoteGenericOpen(virConnectPtr conn, virConnectAuthPtr auth,
   unsigned int flags, void **genericPrivateData)
 {
-if (inside_daemon)
+if (inside_daemon ||
+   STREQ (conn->driver->name, "PHYP"))
 return VIR_DRV_OPEN_DECLINED;

 if (conn->driver&&

BRs,
Dennis


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


Re: [libvirt] [PATCH] storage: Default pool permission mode to 0711

2012-07-11 Thread Osier Yang

On 2012年07月10日 18:01, Peter Krempa wrote:

On 06/21/12 05:49, Osier Yang wrote:

On 2012年06月19日 00:24, Eric Blake wrote:

On 06/18/2012 03:47 AM, Osier Yang wrote:

Per the typical use of libvirt is to fork the qemu process with
qemu:qemu. Setting the pool permission mode as 0700 by default
will prevent the guest start with permission reason.

Define macro for the default pool and vol permission modes
incidentally.
---
src/conf/storage_conf.c | 11 ---
1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index bf4567f..6d4987b 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -47,6 +47,8 @@

#define VIR_FROM_THIS VIR_FROM_STORAGE

+#define DEFAULT_POOL_PERM_MODE 0711
+#define DEFAULT_VOL_PERM_MODE 0600


Isn't 755 more typical than 711 for directory permissions? For that
reason, I'd like a second opinion on whether the more relaxed
permissions make sense.


The difference is 755 allows the group users and others to inspect
what the images are and their permissions in the pool. The side
effect what I can think of is:

% ls -l /var/lib/libvirt/images/

-rw-r--r--. 1 root root 1048576 6月 18 14:34 attch.img
-rw-r--r--. 1 root root 1048576 6月 14 17:38 foo2.img
-rw-r--r--. 1 root root 1048576 6月 14 17:33 foo.img
-rw-rw-rw-. 1 root root 0 6月 21 11:31 local.img

% > /var/lib/libvirt/images/local.img

I.e, if one can check the files in the pool, and the vols
have write permission for group users/others exposed, then
it can be easily damaged.

However, one can destroy the vols data anyway even with 711,
though one should known the filename of the target vol first,
e.g.


By not allowing to view the directory contents you don't really add much
security. I don't like security-by-obscurity approaches. IIUC you are
able to change the permissions on the pool if you wish to have different
from the default, so this choice should just



% ls -ld /var/lib/libvirt/images/
drwx--x--x. 2 root root 4096 Jun 18 14:34 /var/lib/libvirt/images/
% stat /var/lib/libvirt/images/local.img
File: `/var/lib/libvirt/images/local.img'
Size: 0 Blocks: 0 IO Block: 4096 regular empty
file
Device: 808h/2056d Inode: 1054167 Links: 1
Access: (0666/-rw-rw-rw-) Uid: ( 0/ root) Gid: ( 0/ root)
Context: system_u:object_r:virt_image_t:s0
Access: 2012-06-21 11:39:41.928284645 +0800
Modify: 2012-06-21 11:31:11.948457979 +0800
Change: 2012-06-21 11:38:58.948639333 +0800
Birth: -
% > /var/lib/libvirt/images/local.img
%

So from my p.o.v, 711 is better choice, at least it's not that
easy for the group users/others to get the file names in the
pool.


I vote for the more common 755 permissions. We shouldn't try to hide the
real problem if permissions are misconfigured by hiding the names.


It doesn't matter much anyway either 755 or 711, and given there
are two votes for 755. I pushed the patch with the change. Thanks
for the points!

Regards,
Osier

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

Re: [libvirt] [PATCH]POWER Hypervisor: Fix the segment fault issue for the "list" command

2012-07-11 Thread Dennis Chen

On 07/11/2012 06:05 PM, Dennis Chen wrote:

When connect to the remote IBM HMC/IVM server, the remoteNetworkOpen() called
after the phypOpen() in do_open function will re-assign a NULL pointer to the
virConnectPtr conn->networkPrivateData which is allocated in phypOpen(), this
will result in a segment fault issue when execute the following commands,
eg, "virsh# list --all"

Signed-off-by: Dennis Chen
---
   src/remote/remote_driver.c |3 ++-
   1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index eac50e6..22ef129 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2504,7 +2504,8 @@ static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
   remoteGenericOpen(virConnectPtr conn, virConnectAuthPtr auth,
 unsigned int flags, void **genericPrivateData)
   {
-if (inside_daemon)
+if (inside_daemon ||
+   STREQ (conn->driver->name, "PHYP"))
   return VIR_DRV_OPEN_DECLINED;

   if (conn->driver&&

BRs,
Dennis



Resending to CC Eduardo, the author of phyp driver...

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


Re: [libvirt] [PATCHv2] fix failure when building with --disable-debug

2012-07-11 Thread Eric Blake
On 07/11/2012 04:40 AM, Hu Tao wrote:
> When building with --disable-debug, VIR_DEBUG expands to a nop.
> But parameters to VIR_DEBUG can be variables that are passed only
> to VIR_DEBUG. In the case the building system complains about unused
> variables.
> ---
>  cfg.mk |2 ++
>  src/util/logging.h |8 +++-
>  2 files changed, 9 insertions(+), 1 deletion(-)

>  # else
> +/**
> + * virLogEatParam:
> + *
> + * Do nothing but eat parameters.
> + */
> +static inline void virLogEatParam(void *unused ATTRIBUTE_UNUSED, ...) {}

Can't we do:

static inline void virLogEatParam(void *dummy, ...) { dummy = dummy; }

to avoid even needing the ATTRIBUTE_UNUSED, and the syntax check exemption?

>  #  define VIR_DEBUG_INT(category, f, l, ...)\
> -do { } while (0)
> +virLogEatParam((void*)category, f, l, __VA_ARGS__)

Any reason we have to use a cast, instead of just creating our eat
function with the correct type parameter in the first place?

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



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

[libvirt] [PATCH 3/3] virsh: New options for the 3 pool commands to allow pool building

2012-07-11 Thread Osier Yang
New options --build, --build-overwrite, and --build-no-overwrite
are added to commands pool-create/pool-create-as/pool-start.
Perhaps it's not that necessary to allow pool building for pool-start,
but it doesn't hurt to have them.

---
The documents of pool-build is not that correct, as the flags
--overwrite and --no-overwrite are also supported by disk backend,
but it will be a follow up patch, with fixing the documents
for the new options together.
---
 tools/virsh.c   |  100 +++---
 tools/virsh.pod |   27 +--
 2 files changed, 118 insertions(+), 9 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 01e7ce0..7e4fc6f 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -10295,6 +10295,10 @@ static const vshCmdInfo info_pool_create[] = {
 static const vshCmdOptDef opts_pool_create[] = {
 {"file", VSH_OT_DATA, VSH_OFLAG_REQ,
  N_("file containing an XML pool description")},
+{"build", VSH_OT_BOOL, 0, N_("build the pool as normal")},
+{"build-overwrite", VSH_OT_BOOL, 0, N_("build the pool without overwriting 
the "
+"existed pool data")},
+{"build-no-overwrite", VSH_OT_BOOL, 0, N_("build the pool with overwriting 
anything")},
 {NULL, 0, 0, NULL}
 };
 
@@ -10305,6 +10309,10 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
 const char *from = NULL;
 bool ret = true;
 char *buffer;
+bool build;
+bool build_overwrite;
+bool build_no_overwrite;
+unsigned int flags = 0;
 
 if (!vshConnectionUsability(ctl, ctl->conn))
 return false;
@@ -10312,10 +10320,27 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
 if (vshCommandOptString(cmd, "file", &from) <= 0)
 return false;
 
+build = vshCommandOptBool(cmd, "build");
+build_overwrite = vshCommandOptBool(cmd, "build-overwrite");
+build_no_overwrite = vshCommandOptBool(cmd, "build-no-overwrite");
+
+if (build + build_overwrite + build_no_overwrite > 1) {
+vshError(ctl, _("build, build-overwrite, and build-no-overwrite must "
+"be sepcified exclusively"));
+return false;
+}
+
+if (build)
+flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD;
+if (build_overwrite)
+flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE;
+if (build_no_overwrite)
+flags |= VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE;
+
 if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
 return false;
 
-pool = virStoragePoolCreateXML(ctl->conn, buffer, 0);
+pool = virStoragePoolCreateXML(ctl->conn, buffer, flags);
 VIR_FREE(buffer);
 
 if (pool != NULL) {
@@ -10428,7 +10453,7 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
 /*
  * XML Building helper for pool-define-as and pool-create-as
  */
-static const vshCmdOptDef opts_pool_X_as[] = {
+static const vshCmdOptDef opts_pool_define_as[] = {
 {"name", VSH_OT_DATA, VSH_OFLAG_REQ, N_("name of the pool")},
 {"print-xml", VSH_OT_BOOL, 0, N_("print XML document, but don't 
define/create")},
 {"type", VSH_OT_DATA, VSH_OFLAG_REQ, N_("type of the pool")},
@@ -10510,6 +10535,23 @@ static const vshCmdInfo info_pool_create_as[] = {
 {NULL, NULL}
 };
 
+static const vshCmdOptDef opts_pool_create_as[] = {
+{"name", VSH_OT_DATA, VSH_OFLAG_REQ, N_("name of the pool")},
+{"print-xml", VSH_OT_BOOL, 0, N_("print XML document, but don't 
define/create")},
+{"type", VSH_OT_DATA, VSH_OFLAG_REQ, N_("type of the pool")},
+{"source-host", VSH_OT_DATA, 0, N_("source-host for underlying storage")},
+{"source-path", VSH_OT_DATA, 0, N_("source path for underlying storage")},
+{"source-dev", VSH_OT_DATA, 0, N_("source device for underlying storage")},
+{"source-name", VSH_OT_DATA, 0, N_("source name for underlying storage")},
+{"target", VSH_OT_DATA, 0, N_("target for underlying storage")},
+{"source-format", VSH_OT_STRING, 0, N_("format for underlying storage")},
+{"build", VSH_OT_BOOL, 0, N_("build the pool as normal")},
+{"build-overwrite", VSH_OT_BOOL, 0, N_("build the pool without overwriting 
"
+"the existed pool data")},
+{"build-no-overwrite", VSH_OT_BOOL, 0, N_("build the pool with overwriting 
anything")},
+{NULL, 0, 0, NULL}
+};
+
 static bool
 cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
 {
@@ -10517,6 +10559,10 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
 const char *name;
 char *xml;
 bool printXML = vshCommandOptBool(cmd, "print-xml");
+bool build;
+bool build_overwrite;
+bool build_no_overwrite;
+unsigned int flags = 0;
 
 if (!vshConnectionUsability(ctl, ctl->conn))
 return false;
@@ -10524,11 +10570,28 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
 if (!buildPoolXML(cmd, &name, &xml))
 return false;
 
+build = vshCommandOptBool(cmd, "build");
+bu

[libvirt] [PATCH 1/3] Fix the indentions of libvirt.h.in

2012-07-11 Thread Osier Yang
Substitute 2 spaces with 4 spaces instead.
---
 include/libvirt/libvirt.h.in |   96 +-
 1 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 6e8d5dd..e1c9789 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -736,11 +736,11 @@ int virDomainSetSchedulerParametersFlags 
(virDomainPtr domain,
 typedef struct _virDomainBlockStats virDomainBlockStatsStruct;
 
 struct _virDomainBlockStats {
-  long long rd_req; /* number of read requests */
-  long long rd_bytes; /* number of read bytes */
-  long long wr_req; /* number of write requests */
-  long long wr_bytes; /* number of written bytes */
-  long long errs;   /* In Xen this returns the mysterious 'oo_req'. */
+long long rd_req; /* number of read requests */
+long long rd_bytes; /* number of read bytes */
+long long wr_req; /* number of write requests */
+long long wr_bytes; /* number of written bytes */
+long long errs;   /* In Xen this returns the mysterious 'oo_req'. */
 };
 
 /**
@@ -843,14 +843,14 @@ typedef virDomainBlockStatsStruct *virDomainBlockStatsPtr;
 typedef struct _virDomainInterfaceStats virDomainInterfaceStatsStruct;
 
 struct _virDomainInterfaceStats {
-  long long rx_bytes;
-  long long rx_packets;
-  long long rx_errs;
-  long long rx_drop;
-  long long tx_bytes;
-  long long tx_packets;
-  long long tx_errs;
-  long long tx_drop;
+long long rx_bytes;
+long long rx_packets;
+long long rx_errs;
+long long rx_drop;
+long long tx_bytes;
+long long tx_packets;
+long long tx_errs;
+long long tx_drop;
 };
 
 /**
@@ -1728,8 +1728,8 @@ int virDomainMemoryStats 
(virDomainPtr dom,
 /* Memory peeking flags. */
 
 typedef enum {
-  VIR_MEMORY_VIRTUAL= 1 << 0, /* addresses are virtual addresses */
-  VIR_MEMORY_PHYSICAL   = 1 << 1, /* addresses are physical addresses 
*/
+VIR_MEMORY_VIRTUAL= 1 << 0, /* addresses are virtual addresses 
*/
+VIR_MEMORY_PHYSICAL   = 1 << 1, /* addresses are physical 
addresses */
 } virDomainMemoryFlags;
 
 int virDomainMemoryPeek (virDomainPtr dom,
@@ -2358,17 +2358,17 @@ typedef enum {
 } virStoragePoolBuildFlags;
 
 typedef enum {
-  VIR_STORAGE_POOL_DELETE_NORMAL = 0, /* Delete metadata only(fast) */
-  VIR_STORAGE_POOL_DELETE_ZEROED = 1 << 0,  /* Clear all data to zeros (slow) 
*/
+VIR_STORAGE_POOL_DELETE_NORMAL = 0, /* Delete metadata only(fast) */
+VIR_STORAGE_POOL_DELETE_ZEROED = 1 << 0,  /* Clear all data to zeros 
(slow) */
 } virStoragePoolDeleteFlags;
 
 typedef struct _virStoragePoolInfo virStoragePoolInfo;
 
 struct _virStoragePoolInfo {
-  int state; /* virStoragePoolState flags */
-  unsigned long long capacity;   /* Logical size bytes */
-  unsigned long long allocation; /* Current allocation bytes */
-  unsigned long long available;  /* Remaining free space bytes */
+int state; /* virStoragePoolState flags */
+unsigned long long capacity;   /* Logical size bytes */
+unsigned long long allocation; /* Current allocation bytes */
+unsigned long long available;  /* Remaining free space bytes */
 };
 
 typedef virStoragePoolInfo *virStoragePoolInfoPtr;
@@ -2391,10 +2391,10 @@ typedef virStorageVol *virStorageVolPtr;
 
 
 typedef enum {
-  VIR_STORAGE_VOL_FILE = 0, /* Regular file based volumes */
-  VIR_STORAGE_VOL_BLOCK = 1,/* Block based volumes */
-  VIR_STORAGE_VOL_DIR = 2,  /* Directory-passthrough based volume */
-  VIR_STORAGE_VOL_NETWORK = 3,  /* Network volumes like RBD (RADOS Block 
Device) */
+VIR_STORAGE_VOL_FILE = 0, /* Regular file based volumes */
+VIR_STORAGE_VOL_BLOCK = 1,/* Block based volumes */
+VIR_STORAGE_VOL_DIR = 2,  /* Directory-passthrough based volume */
+VIR_STORAGE_VOL_NETWORK = 3,  /* Network volumes like RBD (RADOS Block 
Device) */
 
 #ifdef VIR_ENUM_SENTINELS
 VIR_STORAGE_VOL_LAST
@@ -2402,45 +2402,45 @@ typedef enum {
 } virStorageVolType;
 
 typedef enum {
-  VIR_STORAGE_VOL_DELETE_NORMAL = 0, /* Delete metadata only(fast) */
-  VIR_STORAGE_VOL_DELETE_ZEROED = 1 << 0,  /* Clear all data to zeros (slow) */
+VIR_STORAGE_VOL_DELETE_NORMAL = 0, /* Delete metadata only(fast) */
+VIR_STORAGE_VOL_DELETE_ZEROED = 1 << 0,  /* Clear all data to zeros (slow) 
*/
 } virStorageVolDeleteFlags;
 
 typedef enum {
-  VIR_STORAGE_VOL_WIPE_ALG_ZERO = 0, /* 1-pass, all zeroes */
-  VIR_STORAGE_VOL_WIPE_ALG_NNSA = 1, /* 4-pass  NNSA Policy Letter
+VIR_STORAGE_VOL_WIPE_ALG_ZERO = 0, /* 1-pass, all zeroes */
+VIR_STORAGE_VOL_WIPE_ALG_NNSA = 1, /* 4-pass  NNSA Policy Letter
 NAP-14.1-C (XVI-8) */
-  VIR_STORAGE_VOL_WIPE_ALG_DOD = 2, /* 4-pass DoD 5220.22-M section
+VIR_STORAGE_VOL_WIPE_ALG_DOD = 2, /* 4-pass DoD 5220.22-M section
 

[libvirt] [PATCH 2/3] storage: New flags to allow building the pool while creating it

2012-07-11 Thread Osier Yang
We see the requirement for allowing to build the pool while pool-create
/pool-create-as/pool-start often in either upstream list or bugzilla,
so this patch introduces the flags virStoragePoolCreateFlags for
both virStoragePoolCreate and virStoragePoolCreateXML.

VIR_STORAGE_POOL_CREATE_WITH_BUILD allows to build the pool as
normal (for a filesystem pool, means only making the directory),
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE allows to build
the pool with overwriting the existed pool data. Oppositely,
VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE doesn't allow
to overwrite anything.
---
 include/libvirt/libvirt.h.in |   13 +
 src/libvirt.c|4 ++--
 src/storage/storage_driver.c |   38 --
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index e1c9789..3646e78 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2362,6 +2362,19 @@ typedef enum {
 VIR_STORAGE_POOL_DELETE_ZEROED = 1 << 0,  /* Clear all data to zeros 
(slow) */
 } virStoragePoolDeleteFlags;
 
+typedef enum {
+VIR_STORAGE_POOL_CREATE_NORMAL = 0,
+
+/* Create the pool with regular building */
+VIR_STORAGE_POOL_CREATE_WITH_BUILD = 1 << 0,
+
+/* Create the pool with building, overwrite the existing pool data */
+VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE = 1 << 1,
+
+/* Create the pool with building, don't overwrite the existing pool data */
+VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE = 1 << 2,
+} virStoragePoolCreateFlags;
+
 typedef struct _virStoragePoolInfo virStoragePoolInfo;
 
 struct _virStoragePoolInfo {
diff --git a/src/libvirt.c b/src/libvirt.c
index db6ba15..0cd6110 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -11595,7 +11595,7 @@ error:
  * virStoragePoolCreateXML:
  * @conn: pointer to hypervisor connection
  * @xmlDesc: XML description for new pool
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of virStoragePoolCreateFlags
  *
  * Create a new storage based on its XML description. The
  * pool is not persistent, so its definition will disappear
@@ -11779,7 +11779,7 @@ error:
 /**
  * virStoragePoolCreate:
  * @pool: pointer to storage pool
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of virStoragePoolCreateFlags
  *
  * Starts an inactive storage pool
  *
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index fbc630d..0835850 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -518,8 +518,11 @@ storagePoolCreate(virConnectPtr conn,
 virStoragePoolObjPtr pool = NULL;
 virStoragePoolPtr ret = NULL;
 virStorageBackendPtr backend;
+unsigned int build_flags = 0;
 
-virCheckFlags(0, NULL);
+virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
+  VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
+  VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE, NULL);
 
 storageDriverLock(driver);
 if (!(def = virStoragePoolDefParseString(xml)))
@@ -538,6 +541,21 @@ storagePoolCreate(virConnectPtr conn,
 goto cleanup;
 def = NULL;
 
+if (backend->buildPool) {
+if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)
+build_flags |= VIR_STORAGE_POOL_BUILD_NEW;
+if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
+build_flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
+if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)
+build_flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE;
+
+if (backend->buildPool(conn, pool, build_flags) < 0) {
+virStoragePoolObjRemove(&driver->pools, pool);
+pool = NULL;
+goto cleanup;
+}
+}
+
 if (backend->startPool &&
 backend->startPool(conn, pool) < 0) {
 virStoragePoolObjRemove(&driver->pools, pool);
@@ -670,8 +688,11 @@ storagePoolStart(virStoragePoolPtr obj,
 virStoragePoolObjPtr pool;
 virStorageBackendPtr backend;
 int ret = -1;
+unsigned int start_flags = 0;
 
-virCheckFlags(0, -1);
+virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
+  VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
+  VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE, -1);
 
 storageDriverLock(driver);
 pool = virStoragePoolObjFindByUUID(&driver->pools, obj->uuid);
@@ -691,6 +712,19 @@ storagePoolStart(virStoragePoolPtr obj,
   "%s", _("pool already active"));
 goto cleanup;
 }
+
+if (backend->buildPool) {
+if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)
+start_flags |= VIR_STORAGE_POOL_BUILD_NEW;
+if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
+start_flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
+if (flags & VIR_STORAGE_POOL_CREATE_

Re: [libvirt] Unable to make libvirt

2012-07-11 Thread Eric Blake
On 07/11/2012 06:52 AM, B Veera-B37207 wrote:
> Hi,
> 
> I am unable to compile libvirt -0.9.13
> 
> 
> 1.   ./configure (Executed successfully without any errors)
> 
> 2.   While executing make I am getting following Error
> 
> /bin/sed: can't read =/usr/lib/libnl-route.la: No such file or directory

That's an odd file name.  Something went wrong to botch libtool up that
badly.  What platform are you compiling on?  Can you show the error is
you repeat things with 'make V=1' to get a more complete command line
that was being attempted prior to the error?

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



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

[libvirt] trying to build 0.9.13 on F17: cannot find -lcrypto

2012-07-11 Thread Cole Robinson
In trying to build libvirt 0.9.13 on F17, I'm hitting a link error:

  ...
  CCLD   libvirt_driver_nodedev.la
  CCLD   libvirt_driver_nwfilter.la
/usr/bin/ld: cannot find -lcrypto

Full log here:

http://kojipkgs.fedoraproject.org//work/tasks/3678/4233678/build.log

I think this comes from rbd support, from configure.ac:

LIBRBD_LIBS="-lrbd -lrados -lcrypto"

from this commit:

http://libvirt.org/git/?p=libvirt.git;a=commit;h=74951eadef85e2d100c7dc7bd9ae1093fbda722f

What's missing here? RPM BuildRequires, configure change, ...?

Thanks,
Cole

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


[libvirt] [PATCH 0/3] Storage: Allow pool building while creating it

2012-07-11 Thread Osier Yang

Patch 1/3 is just about the indention fix.

We tries to start the pool while creating a transicient pool,
if the pool target is not existed yet, we must fail on starting,
and thus we see many users raise up the problem on either list
or bugzilla. Patch 2/3 and 3/3 are to fix the problem by introducing
flags to allow the pool building for APIs virStoragePoolCreate
and virStoragePoolCreateXML, and expose the flags to commands
pool-create/pool-create-as/pool-start.

Osier Yang (3):
  Fix the indentions of libvirt.h.in
  storage: New flags to allow building the pool while creating it
  virsh: New options for the 3 pool commands to allow pool building

 include/libvirt/libvirt.h.in |  109 +++--
 src/libvirt.c|4 +-
 src/storage/storage_driver.c |   38 ++-
 tools/virsh.c|  100 --
 tools/virsh.pod  |   27 +-
 5 files changed, 217 insertions(+), 61 deletions(-)

Regards,
Osier
-- 
1.7.7.3


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


Re: [libvirt] [PATCHv4 2/4] nodeinfo: Fix gathering of nodeinfo data structure

2012-07-11 Thread Peter Krempa

On 07/11/12 15:08, Michal Privoznik wrote:

On 11.07.2012 11:47, Peter Krempa wrote:

This patch changes the way data to fill the nodeinfo structure are
gathered. We've gathere the test data by iterating processors an sockets
separately from nodes. The reported data was based solely on information
about core id. Problems arise when eg cores in mulit-processor machines
don't have same id's on both processors or maybe one physical processor
contains more NUMA nodes.

This patch changes the approach how we detect processors and nodes. Now
we start at enumerating nodes and for each node processors, sockets and
threads are enumerated separately. This approach provides acurate data
that comply to docs about the nodeinfo structure. This also enables to
get rid of hacks: see commits 10d9038b744a69c8d4bd29c2e8c012a097481586,
ac9dd4a676f21b5e3ca6dbe0526f2a6709072beb. (Those changes in nodeinfo.c
are efectively reverted by this patch).

This patch also changes output of one of the tests, as the processor
topology is now acquired more precisely.
---
Changes to v3:
- added ATTRIBUTE_NONNULL to arguments of virNodeParseNode()
- added resetting of errno before calling readdir()
- indented comment properly
- edited comment placed before parsing info from /proc/cpuinfo to reflect 
current state better
---
  src/nodeinfo.c |  326 
  .../linux-nodeinfo-sysfs-test-3-cpu-x86-output.txt |2 +-
  2 files changed, 197 insertions(+), 131 deletions(-)


ACK


Thanks! Series pushed with along with the tests.

Peter



Michal

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




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


[libvirt] [glib PATCH V2] Add bindings for virDomainRestore*()

2012-07-11 Thread Jovanka Gulicoska
---
 libvirt-gobject/libvirt-gobject-connection.c |  153 ++
 libvirt-gobject/libvirt-gobject-connection.h |   19 
 libvirt-gobject/libvirt-gobject.sym  |3 +
 3 files changed, 175 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-connection.c 
b/libvirt-gobject/libvirt-gobject-connection.c
index 3a99034..6fbf86b 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -1605,3 +1605,156 @@ gvir_connection_get_capabilities_finish(GVirConnection 
*conn,
 
 return g_object_ref(caps);
 }
+
+/**
+ * gvir_connection_domain_restore:
+ * @conn: a #GVirConnection
+ * @filename: path to input file
+ * @conf: configuration for domain
+ * @flags: the flags
+ *
+ * Returns: TRUE on success, FALSe otherwise
+ */
+gboolean gvir_connection_domain_restore(GVirConnection *conn,
+gchar *filename,
+GVirConfigDomain *conf,
+guint flags,
+GError **err)
+{
+GVirConnectionPrivate *priv;
+gchar *custom_xml;
+int ret;
+
+g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE);
+g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
+g_return_val_if_fail((err == NULL) || (*err == NULL), FALSE);
+
+priv = conn->priv;
+custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+g_return_val_if_fail(custom_xml != NULL, FALSE);
+
+if(flags || (custom_xml != NULL)) {
+   ret = virDomainRestoreFlags(priv->conn, filename, custom_xml, flags);
+   g_free (custom_xml);
+}
+else {
+   ret = virDomainRestore(priv->conn, filename);
+   g_free (custom_xml);
+}
+
+if(ret < 0) {
+   gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
+  0,
+  "Unable to restore domain");
+
+   return FALSE;
+}
+
+return TRUE;
+}
+
+typedef struct {
+gchar *filename;
+gchar *custom_xml;
+guint flags;
+} DomainRestoreFromFileData;
+
+static void domain_restore_from_file_data_free(DomainRestoreFromFileData *data)
+{
+g_free(data->filename);
+g_free(data->custom_xml);
+g_slice_free(DomainRestoreFromFileData, data);
+}
+
+static void
+gvir_connection_domain_restore_helper(GSimpleAsyncResult *res,
+  GObject *object,
+  GCancellable *cancellable G_GNUC_UNUSED)
+{
+GVirConnection *conn = GVIR_CONNECTION(object);
+DomainRestoreFromFileData *data;
+GVirConfigDomain *conf;
+GError *err = NULL;
+
+data = g_simple_async_result_get_op_res_gpointer(res);
+conf =  gvir_config_domain_new_from_xml(data->custom_xml, &err);
+
+if(!gvir_connection_domain_restore(conn, data->filename, conf, 
data->flags, &err))
+   g_simple_async_result_take_error(res, err);
+}
+
+/**
+ * gvir_connection_domain_restore_async:
+ * @conn: a #GVirConnection
+ * @filename: path to input file
+ * @conf: configuration for domain
+ * @flags: the flags
+ * @cancellable: cancallation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_connection_domain_restore
+ */
+void gvir_connection_domain_restore_async(GVirConnection *conn,
+  gchar *filename,
+  GVirConfigDomain *conf,
+  guint flags,
+  GCancellable *cancellable,
+  GAsyncReadyCallback callback,
+  gpointer user_data)
+{
+GSimpleAsyncResult *res;
+DomainRestoreFromFileData *data;
+gchar *custom_xml;
+
+g_return_if_fail(GVIR_IS_CONNECTION(conn));
+g_return_if_fail(GVIR_CONFIG_IS_DOMAIN (conf));
+g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+data = g_slice_new0(DomainRestoreFromFileData);
+data->filename = g_strdup(filename);
+data->custom_xml = g_strdup(custom_xml);
+data->flags = flags;
+
+res = g_simple_async_result_new(G_OBJECT(conn),
+callback,
+user_data,
+gvir_connection_domain_restore_async);
+g_simple_async_result_set_op_res_gpointer(res, data, 
+  
(GDestroyNotify)domain_restore_from_file_data_free);
+
+g_simple_async_result_run_in_thread(res,
+gvir_connection_domain_restore_helper,
+G_PRIORITY_DEFAULT,
+cancellable);
+
+g_object_unref(res);
+}
+
+/**

[libvirt] [PATCH 08/13] Turn virNetTLSContext and virNetTLSSession into virObject instances

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Make virNetTLSContext and virNetTLSSession use the virObject
APIs for reference counting

Signed-off-by: Daniel P. Berrange 
---
 daemon/libvirtd.c |4 +-
 src/libvirt_private.syms  |2 -
 src/libvirt_probes.d  |8 +--
 src/remote/remote_driver.c|2 +-
 src/rpc/virnetclient.c|6 +--
 src/rpc/virnetserver.c|3 +-
 src/rpc/virnetserverclient.c  |   11 ++---
 src/rpc/virnetserverservice.c |   10 ++--
 src/rpc/virnetsocket.c|7 ++-
 src/rpc/virnettlscontext.c|  110 +++--
 src/rpc/virnettlscontext.h|   10 +---
 tests/virnettlscontexttest.c  |   10 ++--
 12 files changed, 66 insertions(+), 117 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 79f37ae..211a4bc 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -541,7 +541,7 @@ static int daemonSetupNetworking(virNetServerPtr srv,
 false,
 config->max_client_requests,
 ctxt))) {
-virNetTLSContextFree(ctxt);
+virObjectUnref(ctxt);
 goto error;
 }
 if (virNetServerAddService(srv, svcTLS,
@@ -549,7 +549,7 @@ static int daemonSetupNetworking(virNetServerPtr srv,
!config->listen_tcp ? "_libvirt._tcp" : 
NULL) < 0)
 goto error;
 
-virNetTLSContextFree(ctxt);
+virObjectUnref(ctxt);
 }
 }
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3551fd0..035658e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1481,11 +1481,9 @@ virNetSocketWrite;
 
 # virnettlscontext.h
 virNetTLSContextCheckCertificate;
-virNetTLSContextFree;
 virNetTLSContextNewClient;
 virNetTLSContextNewServer;
 virNetTLSContextNewServerPath;
-virNetTLSSessionFree;
 virNetTLSSessionHandshake;
 virNetTLSSessionNew;
 virNetTLSSessionSetIOCallbacks;
diff --git a/src/libvirt_probes.d b/src/libvirt_probes.d
index ceb3caa..3b138a9 100644
--- a/src/libvirt_probes.d
+++ b/src/libvirt_probes.d
@@ -61,19 +61,15 @@ provider libvirt {
 
# file: src/rpc/virnettlscontext.c
# prefix: rpc
-   probe rpc_tls_context_new(void *ctxt, int refs, const char *cacert, 
const char *cacrl,
+   probe rpc_tls_context_new(void *ctxt, const char *cacert, const char 
*cacrl,
  const char *cert, const char *key, int 
sanityCheckCert, int requireValidCert, int isServer);
-   probe rpc_tls_context_ref(void *ctxt, int refs);
-   probe rpc_tls_context_free(void *ctxt, int refs);
 
probe rpc_tls_context_session_allow(void *ctxt, void *sess, const char 
*dname);
probe rpc_tls_context_session_deny(void *ctxt, void *sess, const char 
*dname);
probe rpc_tls_context_session_fail(void *ctxt, void *sess);
 
 
-   probe rpc_tls_session_new(void *sess, void *ctxt, int refs, const char 
*hostname, int isServer);
-   probe rpc_tls_session_ref(void *sess, int refs);
-   probe rpc_tls_session_free(void *sess, int refs);
+   probe rpc_tls_session_new(void *sess, void *ctxt, const char *hostname, 
int isServer);
 
probe rpc_tls_session_handshake_pass(void *sess);
probe rpc_tls_session_handshake_fail(void *sess);
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index eac50e6..28035de 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -908,7 +908,7 @@ doRemoteClose (virConnectPtr conn, struct private_data 
*priv)
   (xdrproc_t) xdr_void, (char *) NULL) == -1)
 ret = -1;
 
-virNetTLSContextFree(priv->tls);
+virObjectUnref(priv->tls);
 priv->tls = NULL;
 virNetClientClose(priv->client);
 virNetClientFree(priv->client);
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 49d238e..2b51246 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -475,7 +475,7 @@ void virNetClientFree(virNetClientPtr client)
 if (client->sock)
 virNetSocketRemoveIOCallback(client->sock);
 virNetSocketFree(client->sock);
-virNetTLSSessionFree(client->tls);
+virObjectUnref(client->tls);
 #if HAVE_SASL
 virNetSASLSessionFree(client->sasl);
 #endif
@@ -499,7 +499,7 @@ virNetClientCloseLocked(virNetClientPtr client)
 virNetSocketRemoveIOCallback(client->sock);
 virNetSocketFree(client->sock);
 client->sock = NULL;
-virNetTLSSessionFree(client->tls);
+virObjectUnref(client->tls);
 client->tls = NULL;
 #if HAVE_SASL
 virNetSASLSessionFree(client->sasl);
@@ -661,7 +661,7 @@ int virNetClientSetTLSSession(virNetClientPtr client,
 return 0;
 
 error:
-virNetTLSSessionFree(client->tls);
+virObjectUnref(client->tls);
 client->tls = NULL;
 virNetClientUnlock(client);
 return -1;
diff --

[libvirt] [glib PATCH V2] Add bindings for virStorageVolDownload() and virStorageVolUpload()

2012-07-11 Thread Jovanka Gulicoska
---
 libvirt-gobject/libvirt-gobject-storage-vol.c |   75 +
 libvirt-gobject/libvirt-gobject-storage-vol.h |   14 +
 libvirt-gobject/libvirt-gobject.h |1 +
 libvirt-gobject/libvirt-gobject.sym   |2 +
 4 files changed, 92 insertions(+)

diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.c 
b/libvirt-gobject/libvirt-gobject-storage-vol.c
index 6f60fcd..7f9aeb7 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.c
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.c
@@ -349,3 +349,78 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
 
 return TRUE;
 }
+
+/**
+ * gvir_storage_vol_download:
+ * @vol: the storage volume to download from
+ * @stream: stream to use as output
+ * @offset: position in @vol to start reading from
+ * @length: limit on amount of data to download
+ * @flags: extra flags, not used yet, pass 0
+ *
+ * Returns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+   GVirStream *stream,
+   unsigned long long offset,
+   unsigned long long length,
+   guint flags,
+   GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, "handle", &st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolDownload(vol->priv->handle, st, offset, length, 0) < 0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  "Unable to downlaod volume storage");
+
+   return FALSE;
+}
+
+return TRUE;
+}
+
+/**
+ * gvir_storage_vol_upload:
+ * @vol: the storage volume to upload
+ * @stream: stream to use as input
+ * @offset: position in @vol to start to write to
+ * @length: limit on amount of data to upload
+ * @flags: the flags, not set yet, pass 0
+ *
+ * Returns: #TRUE of success, #FALSE otherwise
+ */
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err)
+{
+virStreamPtr st = NULL;
+
+g_object_get(stream, "handle", &st, NULL);
+
+g_return_val_if_fail(GVIR_IS_STORAGE_VOL(vol), FALSE);
+g_return_val_if_fail(GVIR_IS_STREAM(stream), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+if(virStorageVolUpload(vol->priv->handle, st, offset, length, 0) < 0) {
+   gvir_set_error_literal(err,
+  GVIR_STORAGE_VOL_ERROR,
+  0,
+  "Unable to upload to stream");
+
+   return FALSE;
+}
+
+return TRUE;
+}
+
diff --git a/libvirt-gobject/libvirt-gobject-storage-vol.h 
b/libvirt-gobject/libvirt-gobject-storage-vol.h
index b425f0a..e156792 100644
--- a/libvirt-gobject/libvirt-gobject-storage-vol.h
+++ b/libvirt-gobject/libvirt-gobject-storage-vol.h
@@ -110,6 +110,20 @@ gboolean gvir_storage_vol_resize(GVirStorageVol *vol,
  guint flags,
  GError **err);
 
+gboolean gvir_storage_vol_download(GVirStorageVol *vol,
+   GVirStream *stream,
+   unsigned long long offset,
+   unsigned long long length,
+   guint flags,
+   GError **err);
+
+gboolean gvir_storage_vol_upload(GVirStorageVol *vol,
+ GVirStream *stream,
+ unsigned long long offset,
+ unsigned long long length,
+ guint flags,
+ GError **err);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_STORAGE_VOL_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.h 
b/libvirt-gobject/libvirt-gobject.h
index f52cc00..b1158f7 100644
--- a/libvirt-gobject/libvirt-gobject.h
+++ b/libvirt-gobject/libvirt-gobject.h
@@ -44,5 +44,6 @@
 #include 
 #include 
 #include 
+#include 
 
 #endif /* __LIBVIRT_GOBJECT_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym 
b/libvirt-gobject/libvirt-gobject.sym
index db32c7f..478881b 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -143,6 +143,8 @@ LIBVIRT_GOBJECT_0.0.8 {
gvir_storage_vol_get_info;
gvir_storage_vol_delete;
gvir_storage_vol_resize;
+   gvir_storage_vol_download;
+   gvir_storage_vol_upload;
 
gvir_connection_handl

[libvirt] [PATCH 12/13] Turn virNetServer* into virObject instances

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Make all the virNetServer* objects use the virObject APIs
for reference countign

Signed-off-by: Daniel P. Berrange 
---
 daemon/libvirtd.c |   22 -
 daemon/stream.c   |   19 ++--
 src/libvirt_private.syms  |7 ---
 src/libvirt_probes.d  |4 +-
 src/lxc/lxc_controller.c  |8 +--
 src/rpc/virnetserver.c|   79 ++
 src/rpc/virnetserver.h|5 +-
 src/rpc/virnetserverclient.c  |  108 ++---
 src/rpc/virnetserverclient.h  |5 +-
 src/rpc/virnetserverprogram.c |   49 ++-
 src/rpc/virnetserverprogram.h |8 +--
 src/rpc/virnetserverservice.c |   83 +++
 src/rpc/virnetserverservice.h |5 +-
 13 files changed, 172 insertions(+), 230 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 211a4bc..bed5aa5 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -568,10 +568,10 @@ static int daemonSetupNetworking(virNetServerPtr srv,
 return 0;
 
 error:
-virNetServerServiceFree(svcTLS);
-virNetServerServiceFree(svcTCP);
-virNetServerServiceFree(svc);
-virNetServerServiceFree(svcRO);
+virObjectUnref(svcTLS);
+virObjectUnref(svcTCP);
+virObjectUnref(svc);
+virObjectUnref(svcRO);
 return -1;
 }
 
@@ -759,21 +759,21 @@ static void daemonRunStateInit(void *opaque)
 VIR_ERROR(_("Driver state initialization failed"));
 /* Ensure the main event loop quits */
 kill(getpid(), SIGTERM);
-virNetServerFree(srv);
+virObjectUnref(srv);
 return;
 }
 
 /* Only now accept clients from network */
 virNetServerUpdateServices(srv, true);
-virNetServerFree(srv);
+virObjectUnref(srv);
 }
 
 static int daemonStateInit(virNetServerPtr srv)
 {
 virThread thr;
-virNetServerRef(srv);
+virObjectRef(srv);
 if (virThreadCreate(&thr, false, daemonRunStateInit, srv) < 0) {
-virNetServerFree(srv);
+virObjectUnref(srv);
 return -1;
 }
 return 0;
@@ -1306,10 +1306,10 @@ int main(int argc, char **argv) {
 
 cleanup:
 virNetlinkEventServiceStop();
-virNetServerProgramFree(remoteProgram);
-virNetServerProgramFree(qemuProgram);
+virObjectUnref(remoteProgram);
+virObjectUnref(qemuProgram);
 virNetServerClose(srv);
-virNetServerFree(srv);
+virObjectUnref(srv);
 virNetlinkShutdown();
 if (statuswrite != -1) {
 if (ret != 0) {
diff --git a/daemon/stream.c b/daemon/stream.c
index bb66f75..024a8c9 100644
--- a/daemon/stream.c
+++ b/daemon/stream.c
@@ -108,14 +108,6 @@ daemonStreamMessageFinished(virNetMessagePtr msg 
ATTRIBUTE_UNUSED,
 }
 
 
-static void
-daemonStreamEventFreeFunc(void *opaque)
-{
-virNetServerClientPtr client = opaque;
-
-virNetServerClientFree(client);
-}
-
 /*
  * Callback that gets invoked when a stream becomes writable/readable
  */
@@ -336,14 +328,12 @@ daemonCreateClientStream(virNetServerClientPtr client,
 
 stream->refs = 1;
 stream->priv = priv;
-stream->prog = prog;
+stream->prog = virObjectRef(prog);
 stream->procedure = header->proc;
 stream->serial = header->serial;
 stream->filterID = -1;
 stream->st = st;
 
-virNetServerProgramRef(prog);
-
 return stream;
 }
 
@@ -369,7 +359,7 @@ int daemonFreeClientStream(virNetServerClientPtr client,
 VIR_DEBUG("client=%p, proc=%d, serial=%d",
   client, stream->procedure, stream->serial);
 
-virNetServerProgramFree(stream->prog);
+virObjectUnref(stream->prog);
 
 msg = stream->rx;
 while (msg) {
@@ -415,10 +405,11 @@ int daemonAddClientStream(virNetServerClientPtr client,
 
 if (virStreamEventAddCallback(stream->st, 0,
   daemonStreamEvent, client,
-  daemonStreamEventFreeFunc) < 0)
+  (virFreeCallback)virObjectUnref) < 0)
 return -1;
 
-virNetServerClientRef(client);
+virObjectRef(client);
+
 if ((stream->filterID = virNetServerClientAddFilter(client,
 daemonStreamFilter,
 stream)) < 0) {
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index ee2f581..a129cd5 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1406,14 +1406,11 @@ virNetServerAddService;
 virNetServerAddSignalHandler;
 virNetServerAutoShutdown;
 virNetServerClose;
-virNetServerFree;
 virNetServerIsPrivileged;
 virNetServerKeepAliveRequired;
 virNetServerNew;
 virNetServerQuit;
-virNetServerRef;
 virNetServerRun;
-virNetServerServiceFree;
 virNetServerServiceNewTCP;
 virNetServerServiceNewUNIX;
 virNetServerUpdateServices;
@@ -1423,7 +1420,6 @@ virNetServerUpdateServices;
 virNetServerClientAddFilter;
 virNetServerClientClose;
 virNetServerClientDelay

[libvirt] [PATCH 10/13] Turn virKeepAlive into a virObject

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Make virKeepAlive use the virObject APIs for reference counting

Signed-off-by: Daniel P. Berrange 
---
 src/libvirt_probes.d |4 +--
 src/rpc/virkeepalive.c   |   73 +-
 src/rpc/virkeepalive.h   |4 +--
 src/rpc/virnetclient.c   |4 +--
 src/rpc/virnetserverclient.c |4 +--
 5 files changed, 35 insertions(+), 54 deletions(-)

diff --git a/src/libvirt_probes.d b/src/libvirt_probes.d
index 3b138a9..807239f 100644
--- a/src/libvirt_probes.d
+++ b/src/libvirt_probes.d
@@ -77,9 +77,7 @@ provider libvirt {
 
# file: src/rpc/virkeepalive.c
# prefix: rpc
-   probe rpc_keepalive_new(void *ka, void *client, int refs);
-   probe rpc_keepalive_ref(void *ka, void *client, int refs);
-   probe rpc_keepalive_free(void *ka, void *client, int refs);
+   probe rpc_keepalive_new(void *ka, void *client);
probe rpc_keepalive_start(void *ka, void *client, int interval, int 
count);
probe rpc_keepalive_stop(void *ka, void *client);
probe rpc_keepalive_send(void *ka, void *client, int prog, int vers, 
int proc);
diff --git a/src/rpc/virkeepalive.c b/src/rpc/virkeepalive.c
index 70cf31e..f6d7242 100644
--- a/src/rpc/virkeepalive.c
+++ b/src/rpc/virkeepalive.c
@@ -38,7 +38,8 @@
  __FUNCTION__, __LINE__, __VA_ARGS__)
 
 struct _virKeepAlive {
-int refs;
+virObject object;
+
 virMutex lock;
 
 int interval;
@@ -55,6 +56,21 @@ struct _virKeepAlive {
 };
 
 
+static virClassPtr virKeepAliveClass;
+static void virKeepAliveDispose(void *obj);
+
+static int virKeepAliveOnceInit(void)
+{
+if (!(virKeepAliveClass = virClassNew("virKeepAlive",
+  sizeof(virKeepAlive),
+  virKeepAliveDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virKeepAlive)
+
 static void
 virKeepAliveLock(virKeepAlivePtr ka)
 {
@@ -168,7 +184,7 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
 if (!dead && !msg)
 goto cleanup;
 
-ka->refs++;
+virObjectRef(ka);
 virKeepAliveUnlock(ka);
 
 if (dead) {
@@ -179,20 +195,13 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void 
*opaque)
 }
 
 virKeepAliveLock(ka);
-ka->refs--;
+virObjectUnref(ka);
 
 cleanup:
 virKeepAliveUnlock(ka);
 }
 
 
-static void
-virKeepAliveTimerFree(void *opaque)
-{
-virKeepAliveFree(opaque);
-}
-
-
 virKeepAlivePtr
 virKeepAliveNew(int interval,
 unsigned int count,
@@ -205,17 +214,17 @@ virKeepAliveNew(int interval,
 
 VIR_DEBUG("client=%p, interval=%d, count=%u", client, interval, count);
 
-if (VIR_ALLOC(ka) < 0) {
-virReportOOMError();
+if (virKeepAliveInitialize() < 0)
+return NULL;
+
+if (!(ka = virObjectNew(virKeepAliveClass)))
 return NULL;
-}
 
 if (virMutexInit(&ka->lock) < 0) {
 VIR_FREE(ka);
 return NULL;
 }
 
-ka->refs = 1;
 ka->interval = interval;
 ka->count = count;
 ka->countToDeath = count;
@@ -226,44 +235,20 @@ virKeepAliveNew(int interval,
 ka->freeCB = freeCB;
 
 PROBE(RPC_KEEPALIVE_NEW,
-  "ka=%p client=%p refs=%d",
-  ka, ka->client, ka->refs);
+  "ka=%p client=%p",
+  ka, ka->client);
 
 return ka;
 }
 
 
 void
-virKeepAliveRef(virKeepAlivePtr ka)
+virKeepAliveDispose(void *obj)
 {
-virKeepAliveLock(ka);
-ka->refs++;
-PROBE(RPC_KEEPALIVE_REF,
-  "ka=%p client=%p refs=%d",
-  ka, ka->client, ka->refs);
-virKeepAliveUnlock(ka);
-}
-
-
-void
-virKeepAliveFree(virKeepAlivePtr ka)
-{
-if (!ka)
-return;
-
-virKeepAliveLock(ka);
-PROBE(RPC_KEEPALIVE_FREE,
-  "ka=%p client=%p refs=%d",
-  ka, ka->client, ka->refs);
-
-if (--ka->refs > 0) {
-virKeepAliveUnlock(ka);
-return;
-}
+virKeepAlivePtr ka = obj;
 
 virMutexDestroy(&ka->lock);
 ka->freeCB(ka->client);
-VIR_FREE(ka);
 }
 
 
@@ -314,12 +299,12 @@ virKeepAliveStart(virKeepAlivePtr ka,
 timeout = ka->interval - delay;
 ka->intervalStart = now - (ka->interval - timeout);
 ka->timer = virEventAddTimeout(timeout * 1000, virKeepAliveTimer,
-   ka, virKeepAliveTimerFree);
+   ka, (virFreeCallback)virObjectUnref);
 if (ka->timer < 0)
 goto cleanup;
 
 /* the timer now has another reference to this object */
-ka->refs++;
+virObjectRef(ka);
 ret = 0;
 
 cleanup:
diff --git a/src/rpc/virkeepalive.h b/src/rpc/virkeepalive.h
index 1e25214..c397a7e 100644
--- a/src/rpc/virkeepalive.h
+++ b/src/rpc/virkeepalive.h
@@ -24,6 +24,7 @@
 # define __VIR_KEEPALIVE_H__
 
 # include "virnetmessage.h"
+# include "virobject.h"
 
 typedef int (*virKeepAliveSendFunc)(void *client, virNetMessagePtr msg);
 typedef void (*virKeepAliveDeadFu

[libvirt] [PATCH 13/13] Turn virNetClient* into virObject instances

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Make all the virNetClient* objects use virObject APIs for
reference counting

Signed-off-by: Daniel P. Berrange 
---
 src/libvirt_probes.d  |4 +-
 src/remote/remote_driver.c|   20 -
 src/rpc/gendispatch.pl|4 +-
 src/rpc/virnetclient.c|   96 +
 src/rpc/virnetclient.h|4 +-
 src/rpc/virnetclientprogram.c |   43 +-
 src/rpc/virnetclientprogram.h |5 +--
 src/rpc/virnetclientstream.c  |   65 +---
 src/rpc/virnetclientstream.h  |5 +--
 9 files changed, 108 insertions(+), 138 deletions(-)

diff --git a/src/libvirt_probes.d b/src/libvirt_probes.d
index 27f4e9a..9343fa4 100644
--- a/src/libvirt_probes.d
+++ b/src/libvirt_probes.d
@@ -40,9 +40,7 @@ provider libvirt {
 
# file: src/rpc/virnetclient.c
# prefix: rpc
-   probe rpc_client_new(void *client, int refs, void *sock);
-   probe rpc_client_ref(void *client, int refs);
-   probe rpc_client_free(void *client, int refs);
+   probe rpc_client_new(void *client, void *sock);
 
probe rpc_client_msg_tx_queue(void *client, int len, int prog, int 
vers, int proc, int type, int status, int serial);
probe rpc_client_msg_rx(void *client, int len, int prog, int vers, int 
proc, int type, int status, int serial);
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index f2600a8..3420ff8 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -757,10 +757,10 @@ doRemoteOpen (virConnectPtr conn,
 virReportOOMError();
 
  failed:
-virNetClientProgramFree(priv->remoteProgram);
-virNetClientProgramFree(priv->qemuProgram);
+virObjectUnref(priv->remoteProgram);
+virObjectUnref(priv->qemuProgram);
 virNetClientClose(priv->client);
-virNetClientFree(priv->client);
+virObjectUnref(priv->client);
 priv->client = NULL;
 
 VIR_FREE(priv->hostname);
@@ -911,10 +911,10 @@ doRemoteClose (virConnectPtr conn, struct private_data 
*priv)
 virObjectUnref(priv->tls);
 priv->tls = NULL;
 virNetClientClose(priv->client);
-virNetClientFree(priv->client);
+virObjectUnref(priv->client);
 priv->client = NULL;
-virNetClientProgramFree(priv->remoteProgram);
-virNetClientProgramFree(priv->qemuProgram);
+virObjectUnref(priv->remoteProgram);
+virObjectUnref(priv->qemuProgram);
 priv->remoteProgram = priv->qemuProgram = NULL;
 
 /* Free hostname copy */
@@ -4115,7 +4115,7 @@ remoteStreamFinish(virStreamPtr st)
 
 cleanup:
 virNetClientRemoveStream(priv->client, privst);
-virNetClientStreamFree(privst);
+virObjectUnref(privst);
 st->privateData = NULL;
 st->driver = NULL;
 
@@ -4144,7 +4144,7 @@ remoteStreamAbort(virStreamPtr st)
 
 cleanup:
 virNetClientRemoveStream(priv->client, privst);
-virNetClientStreamFree(privst);
+virObjectUnref(privst);
 st->privateData = NULL;
 st->driver = NULL;
 
@@ -4445,7 +4445,7 @@ remoteDomainMigratePrepareTunnel3(virConnectPtr dconn,
 goto done;
 
 if (virNetClientAddStream(priv->client, netst) < 0) {
-virNetClientStreamFree(netst);
+virObjectUnref(netst);
 goto done;
 }
 
@@ -4463,7 +4463,7 @@ remoteDomainMigratePrepareTunnel3(virConnectPtr dconn,
  (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_args, (char 
*) &args,
  (xdrproc_t) xdr_remote_domain_migrate_prepare_tunnel3_ret, (char 
*) &ret) == -1) {
 virNetClientRemoveStream(priv->client, netst);
-virNetClientStreamFree(netst);
+virObjectUnref(netst);
 goto done;
 }
 
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index f161ee0..ea31ae9 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -1404,7 +1404,7 @@ elsif ($opt_k) {
 print "goto done;\n";
 print "\n";
 print "if (virNetClientAddStream(priv->client, netst) < 0) 
{\n";
-print "virNetClientStreamFree(netst);\n";
+print "virObjectUnref(netst);\n";
 print "goto done;\n";
 print "}";
 print "\n";
@@ -1480,7 +1480,7 @@ elsif ($opt_k) {
 
 if ($call->{streamflag} ne "none") {
 print "virNetClientRemoveStream(priv->client, netst);\n";
-print "virNetClientStreamFree(netst);\n";
+print "virObjectUnref(netst);\n";
 print "st->driver = NULL;\n";
 print "st->privateData = NULL;\n";
 }
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 4da5082..9be0592 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -66,7 +66,7 @@ struct _virNetClientCall {
 
 
 struct _virNetClient {
-int refs;
+virObject object;
 
 virMutex lock;
 
@@ -107,6 +107,21 @@ struct _virNetClient {
 };
 
 
+sta

[libvirt] [PATCH 07/13] Turn qemuAgentPtr and qemuMonitorPtr into virObjectPtr instances

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Make qemuAgentPtr and qemuMonitorPtr types use the virObject APIs
for reference counting

Signed-off-by: Daniel P. Berrange 
---
 src/qemu/qemu_agent.c   |   86 ++---
 src/qemu/qemu_agent.h   |3 --
 src/qemu/qemu_domain.c  |   22 +--
 src/qemu/qemu_monitor.c |   97 ---
 src/qemu/qemu_monitor.h |3 --
 5 files changed, 89 insertions(+), 122 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 7a0381c..7c3de4d 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -40,6 +40,7 @@
 #include "json.h"
 #include "virfile.h"
 #include "virtime.h"
+#include "virobject.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -80,11 +81,11 @@ struct _qemuAgentMessage {
 
 
 struct _qemuAgent {
+virObject object;
+
 virMutex lock; /* also used to protect fd */
 virCond notify;
 
-int refs;
-
 int fd;
 int watch;
 
@@ -114,6 +115,22 @@ struct _qemuAgent {
 qemuAgentEvent await_event;
 };
 
+static virClassPtr qemuAgentClass;
+static void qemuAgentDispose(void *obj);
+
+static int qemuAgentOnceInit(void)
+{
+if (!(qemuAgentClass = virClassNew("qemuAgent",
+   sizeof(qemuAgent),
+   qemuAgentDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(qemuAgent)
+
+
 #if DEBUG_RAW_IO
 # include 
 static char *
@@ -146,45 +163,15 @@ void qemuAgentUnlock(qemuAgentPtr mon)
 }
 
 
-static void qemuAgentFree(qemuAgentPtr mon)
+static void qemuAgentDispose(void *obj)
 {
+qemuAgentPtr mon = obj;
 VIR_DEBUG("mon=%p", mon);
 if (mon->cb && mon->cb->destroy)
 (mon->cb->destroy)(mon, mon->vm);
 ignore_value(virCondDestroy(&mon->notify));
 virMutexDestroy(&mon->lock);
 VIR_FREE(mon->buffer);
-VIR_FREE(mon);
-}
-
-int qemuAgentRef(qemuAgentPtr mon)
-{
-mon->refs++;
-VIR_DEBUG("%d", mon->refs);
-return mon->refs;
-}
-
-int qemuAgentUnref(qemuAgentPtr mon)
-{
-mon->refs--;
-VIR_DEBUG("%d", mon->refs);
-if (mon->refs == 0) {
-qemuAgentUnlock(mon);
-qemuAgentFree(mon);
-return 0;
-}
-
-return mon->refs;
-}
-
-static void
-qemuAgentUnwatch(void *monitor)
-{
-qemuAgentPtr mon = monitor;
-
-qemuAgentLock(mon);
-if (qemuAgentUnref(mon) > 0)
-qemuAgentUnlock(mon);
 }
 
 static int
@@ -599,9 +586,9 @@ qemuAgentIO(int watch, int fd, int events, void *opaque) {
 bool error = false;
 bool eof = false;
 
+virObjectRef(mon);
 /* lock access to the monitor and protect fd */
 qemuAgentLock(mon);
-qemuAgentRef(mon);
 #if DEBUG_IO
 VIR_DEBUG("Agent %p I/O on watch %d fd %d events %d", mon, watch, fd, 
events);
 #endif
@@ -704,8 +691,8 @@ qemuAgentIO(int watch, int fd, int events, void *opaque) {
 
 /* Make sure anyone waiting wakes up now */
 virCondSignal(&mon->notify);
-if (qemuAgentUnref(mon) > 0)
-qemuAgentUnlock(mon);
+qemuAgentUnlock(mon);
+virObjectUnref(mon);
 VIR_DEBUG("Triggering EOF callback");
 (eofNotify)(mon, vm);
 } else if (error) {
@@ -715,13 +702,13 @@ qemuAgentIO(int watch, int fd, int events, void *opaque) {
 
 /* Make sure anyone waiting wakes up now */
 virCondSignal(&mon->notify);
-if (qemuAgentUnref(mon) > 0)
-qemuAgentUnlock(mon);
+qemuAgentUnlock(mon);
+virObjectUnref(mon);
 VIR_DEBUG("Triggering error callback");
 (errorNotify)(mon, vm);
 } else {
-if (qemuAgentUnref(mon) > 0)
-qemuAgentUnlock(mon);
+qemuAgentUnlock(mon);
+virObjectUnref(mon);
 }
 }
 
@@ -739,10 +726,11 @@ qemuAgentOpen(virDomainObjPtr vm,
 return NULL;
 }
 
-if (VIR_ALLOC(mon) < 0) {
-virReportOOMError();
+if (qemuAgentInitialize() < 0)
+return NULL;
+
+if (!(mon = virObjectNew(qemuAgentClass)))
 return NULL;
-}
 
 if (virMutexInit(&mon->lock) < 0) {
 qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -758,7 +746,6 @@ qemuAgentOpen(virDomainObjPtr vm,
 return NULL;
 }
 mon->fd = -1;
-mon->refs = 1;
 mon->vm = vm;
 mon->cb = cb;
 qemuAgentLock(mon);
@@ -791,12 +778,13 @@ qemuAgentOpen(virDomainObjPtr vm,
  VIR_EVENT_HANDLE_WRITABLE :
  0),
 qemuAgentIO,
-mon, qemuAgentUnwatch)) < 0) {
+mon,
+(virFreeCallback)virObjectUnref)) < 0) 
{
 qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 _("unable to register monitor events"));
 goto cleanup;
 }
-qemuAgentRef(mon);
+virObjectRef(mon);
 
 VIR_DEBUG("New 

[libvirt] [PATCH 11/13] Turn virSocket into a virObject

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Make virSocket use the virObject APIs for reference counting

Signed-off-by: Daniel P. Berrange 
---
 src/libvirt_private.syms  |1 -
 src/libvirt_probes.d  |4 +--
 src/qemu/qemu_migration.c |4 +--
 src/rpc/virnetclient.c|4 +--
 src/rpc/virnetserverclient.c  |4 +--
 src/rpc/virnetserverservice.c |4 +--
 src/rpc/virnetsocket.c|   71 ++---
 src/rpc/virnetsocket.h|3 +-
 tests/virnetsockettest.c  |   26 +++
 9 files changed, 54 insertions(+), 67 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 035658e..ee2f581 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1459,7 +1459,6 @@ virNetServerProgramSendStreamError;
 # virnetsocket.h
 virNetSocketAccept;
 virNetSocketDupFD;
-virNetSocketFree;
 virNetSocketGetFD;
 virNetSocketHasPassFD;
 virNetSocketIsLocal;
diff --git a/src/libvirt_probes.d b/src/libvirt_probes.d
index 807239f..be1d938 100644
--- a/src/libvirt_probes.d
+++ b/src/libvirt_probes.d
@@ -25,11 +25,9 @@ provider libvirt {
 
# file: src/rpc/virnetsocket.c
# prefix: rpc
-   probe rpc_socket_new(void *sock, int refs, int fd, int errfd, pid_t 
pid, const char *localAddr, const char *remoteAddr);
+   probe rpc_socket_new(void *sock, int fd, int errfd, pid_t pid, const 
char *localAddr, const char *remoteAddr);
probe rpc_socket_send_fd(void *sock, int fd);
probe rpc_socket_recv_fd(void *sock, int fd);
-   probe rpc_socket_ref(void *sock, int refs);
-   probe rpc_socket_free(void *sock, int refs);
 
 
# file: src/rpc/virnetserverclient.c
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 61d3d68..8409bc1 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1805,7 +1805,7 @@ qemuMigrationConnect(struct qemud_driver *driver,
 goto cleanup;
 if (virNetSocketNewConnectTCP(host, port, &sock) == 0) {
 spec->dest.fd.qemu = virNetSocketDupFD(sock, true);
-virNetSocketFree(sock);
+virObjectUnref(sock);
 }
 if (virSecurityManagerClearSocketLabel(driver->securityManager, vm->def) < 
0 ||
 spec->dest.fd.qemu == -1)
@@ -2157,7 +2157,7 @@ cleanup:
 VIR_FORCE_CLOSE(spec.dest.fd.qemu);
 VIR_FORCE_CLOSE(spec.dest.fd.local);
 } else {
-virNetSocketFree(sock);
+virObjectUnref(sock);
 VIR_FREE(spec.dest.unix_socket.file);
 }
 
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 45f3309..4da5082 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -474,7 +474,7 @@ void virNetClientFree(virNetClientPtr client)
 
 if (client->sock)
 virNetSocketRemoveIOCallback(client->sock);
-virNetSocketFree(client->sock);
+virObjectUnref(client->sock);
 virObjectUnref(client->tls);
 #if HAVE_SASL
 virObjectUnref(client->sasl);
@@ -497,7 +497,7 @@ virNetClientCloseLocked(virNetClientPtr client)
 return;
 
 virNetSocketRemoveIOCallback(client->sock);
-virNetSocketFree(client->sock);
+virObjectUnref(client->sock);
 client->sock = NULL;
 virObjectUnref(client->tls);
 client->tls = NULL;
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index b2ab12f..58b56e1 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -598,7 +598,7 @@ void virNetServerClientFree(virNetServerClientPtr client)
 virEventRemoveTimeout(client->sockTimer);
 virObjectUnref(client->tls);
 virObjectUnref(client->tlsCtxt);
-virNetSocketFree(client->sock);
+virObjectUnref(client->sock);
 virNetServerClientUnlock(client);
 virMutexDestroy(&client->lock);
 VIR_FREE(client);
@@ -669,7 +669,7 @@ void virNetServerClientClose(virNetServerClientPtr client)
 }
 
 if (client->sock) {
-virNetSocketFree(client->sock);
+virObjectUnref(client->sock);
 client->sock = NULL;
 }
 
diff --git a/src/rpc/virnetserverservice.c b/src/rpc/virnetserverservice.c
index b4689b4..46cef3a 100644
--- a/src/rpc/virnetserverservice.c
+++ b/src/rpc/virnetserverservice.c
@@ -86,7 +86,7 @@ error:
 virNetServerClientClose(client);
 virNetServerClientFree(client);
 } else {
-virNetSocketFree(clientsock);
+virObjectUnref(clientsock);
 }
 }
 
@@ -258,7 +258,7 @@ void virNetServerServiceFree(virNetServerServicePtr svc)
 return;
 
 for (i = 0 ; i < svc->nsocks ; i++)
-virNetSocketFree(svc->socks[i]);
+virObjectUnref(svc->socks[i]);
 VIR_FREE(svc->socks);
 
 virObjectUnref(svc->tls);
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 1a64cc0..93ff9dd 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -54,8 +54,9 @@
 
 
 struct _virNetSocket {
+virObject object;
+
 virMutex lock;
-int refs;
 
 int 

[libvirt] [PATCH 06/13] Turn virDomainObjPtr into a virObjectPtr

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Switch virDomainObjPtr to use the virObject APIs for reference
counting. The main change is that virObjectUnref does not return
the reference count, merely a bool indicating whether the object
still has any refs left. Checking the return value is also not
mandatory.

Signed-off-by: Daniel P. Berrange 
---
 src/conf/domain_conf.c|   59 -
 src/conf/domain_conf.h|8 +++---
 src/libvirt_private.syms  |3 +--
 src/libxl/libxl_driver.c  |6 ++---
 src/openvz/openvz_conf.c  |   17 ++---
 src/qemu/qemu_domain.c|   27 +
 src/qemu/qemu_domain.h|8 +++---
 src/qemu/qemu_driver.c|2 +-
 src/qemu/qemu_migration.c |   22 -
 src/qemu/qemu_migration.h |4 +--
 src/qemu/qemu_process.c   |   50 ++
 src/vmware/vmware_conf.c  |4 +--
 12 files changed, 89 insertions(+), 121 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3fb90db..e9527b4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -661,6 +661,21 @@ VIR_ENUM_IMPL(virDomainNumatuneMemPlacementMode,
 #define VIR_DOMAIN_XML_WRITE_FLAGS  VIR_DOMAIN_XML_SECURE
 #define VIR_DOMAIN_XML_READ_FLAGS   VIR_DOMAIN_XML_INACTIVE
 
+static virClassPtr virDomainObjClass;
+static void virDomainObjDispose(void *obj);
+
+static int virDomainObjOnceInit(void)
+{
+if (!(virDomainObjClass = virClassNew("virDomainObj",
+  sizeof(virDomainObj),
+  virDomainObjDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virDomainObj)
+
 void
 virBlkioDeviceWeightArrayClear(virBlkioDeviceWeightPtr deviceWeights,
int ndevices)
@@ -726,7 +741,7 @@ virDomainObjListDataFree(void *payload, const void *name 
ATTRIBUTE_UNUSED)
 {
 virDomainObjPtr obj = payload;
 virDomainObjLock(obj);
-if (virDomainObjUnref(obj) > 0)
+if (!virObjectUnref(obj))
 virDomainObjUnlock(obj);
 }
 
@@ -1640,10 +1655,10 @@ void virDomainDefFree(virDomainDefPtr def)
 }
 
 static void virDomainSnapshotObjListDeinit(virDomainSnapshotObjListPtr 
snapshots);
-static void virDomainObjFree(virDomainObjPtr dom)
+
+static void virDomainObjDispose(void *obj)
 {
-if (!dom)
-return;
+virDomainObjPtr dom = obj;
 
 VIR_DEBUG("obj=%p", dom);
 virDomainDefFree(dom->def);
@@ -1655,37 +1670,18 @@ static void virDomainObjFree(virDomainObjPtr dom)
 virMutexDestroy(&dom->lock);
 
 virDomainSnapshotObjListDeinit(&dom->snapshots);
-
-VIR_FREE(dom);
-}
-
-void virDomainObjRef(virDomainObjPtr dom)
-{
-dom->refs++;
-VIR_DEBUG("obj=%p refs=%d", dom, dom->refs);
 }
 
 
-int virDomainObjUnref(virDomainObjPtr dom)
-{
-dom->refs--;
-VIR_DEBUG("obj=%p refs=%d", dom, dom->refs);
-if (dom->refs == 0) {
-virDomainObjUnlock(dom);
-virDomainObjFree(dom);
-return 0;
-}
-return dom->refs;
-}
-
-static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
+virDomainObjPtr virDomainObjNew(virCapsPtr caps)
 {
 virDomainObjPtr domain;
 
-if (VIR_ALLOC(domain) < 0) {
-virReportOOMError();
+if (virDomainObjInitialize() < 0)
+return NULL;
+
+if (!(domain = virObjectNew(virDomainObjClass)))
 return NULL;
-}
 
 if (caps->privateDataAllocFunc &&
 !(domain->privateData = (caps->privateDataAllocFunc)())) {
@@ -1707,7 +1703,6 @@ static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
 virDomainObjLock(domain);
 virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF,
  VIR_DOMAIN_SHUTOFF_UNKNOWN);
-domain->refs = 1;
 
 virDomainSnapshotObjListInit(&domain->snapshots);
 
@@ -9316,8 +9311,7 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr 
caps,
 return obj;
 
 error:
-/* obj was never shared, so unref should return 0 */
-ignore_value(virDomainObjUnref(obj));
+virObjectUnref(obj);
 VIR_FREE(nodes);
 return NULL;
 }
@@ -13374,9 +13368,8 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr 
caps,
 return obj;
 
 error:
-/* obj was never shared, so unref should return 0 */
 if (obj)
-ignore_value(virDomainObjUnref(obj));
+virObjectUnref(obj);
 VIR_FREE(statusFile);
 return NULL;
 }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7d5d60b..d79e4ee 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -43,6 +43,7 @@
 # include "virnetdevvportprofile.h"
 # include "virnetdevopenvswitch.h"
 # include "virnetdevbandwidth.h"
+# include "virobject.h"
 
 /* forward declarations of all device types, required by
  * virDomainDeviceDef
@@ -1806,8 +1807,9 @@ struct _virDomainStateReason {
 typedef struct _virDomainObj virDomainObj;
 typedef virDomainObj *virDomainObjPtr;
 struct _virDomainObj {
+virObject object;
+
 vi

[libvirt] [PATCH 09/13] Turn virNetSASLContext and virNetSASLSession into virObject instances

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Make virNetSASLContext and virNetSASLSession use virObject APIs
for reference counting

Signed-off-by: Daniel P. Berrange 
---
 daemon/remote.c  |8 ++--
 src/remote/remote_driver.c   |4 +-
 src/rpc/virnetclient.c   |7 ++-
 src/rpc/virnetsaslcontext.c  |  106 ++
 src/rpc/virnetsaslcontext.h  |8 +---
 src/rpc/virnetserverclient.c |7 ++-
 src/rpc/virnetsocket.c   |7 ++-
 7 files changed, 61 insertions(+), 86 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 095d854..24741d2 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2301,7 +2301,7 @@ authfail:
 PROBE(RPC_SERVER_CLIENT_AUTH_FAIL,
   "client=%p auth=%d",
   client, REMOTE_AUTH_SASL);
-virNetSASLSessionFree(sasl);
+virObjectUnref(sasl);
 virMutexUnlock(&priv->lock);
 return -1;
 }
@@ -2345,7 +2345,7 @@ remoteSASLFinish(virNetServerClientPtr client)
   "client=%p auth=%d identity=%s",
   client, REMOTE_AUTH_SASL, identity);
 
-virNetSASLSessionFree(priv->sasl);
+virObjectUnref(priv->sasl);
 priv->sasl = NULL;
 
 return 0;
@@ -2443,7 +2443,7 @@ authdeny:
 goto error;
 
 error:
-virNetSASLSessionFree(priv->sasl);
+virObjectUnref(priv->sasl);
 priv->sasl = NULL;
 virResetLastError();
 virNetError(VIR_ERR_AUTH_FAILED, "%s",
@@ -2541,7 +2541,7 @@ authdeny:
 goto error;
 
 error:
-virNetSASLSessionFree(priv->sasl);
+virObjectUnref(priv->sasl);
 priv->sasl = NULL;
 virResetLastError();
 virNetError(VIR_ERR_AUTH_FAILED, "%s",
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 28035de..f2600a8 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3374,8 +3374,8 @@ remoteAuthSASL (virConnectPtr conn, struct private_data 
*priv,
 
 remoteAuthInteractStateClear(&state, true);
 VIR_FREE(saslcb);
-virNetSASLSessionFree(sasl);
-virNetSASLContextFree(saslCtxt);
+virObjectUnref(sasl);
+virObjectUnref(saslCtxt);
 
 return ret;
 }
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 2b51246..8dd09ef 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -477,7 +477,7 @@ void virNetClientFree(virNetClientPtr client)
 virNetSocketFree(client->sock);
 virObjectUnref(client->tls);
 #if HAVE_SASL
-virNetSASLSessionFree(client->sasl);
+virObjectUnref(client->sasl);
 #endif
 virNetClientUnlock(client);
 virMutexDestroy(&client->lock);
@@ -502,7 +502,7 @@ virNetClientCloseLocked(virNetClientPtr client)
 virObjectUnref(client->tls);
 client->tls = NULL;
 #if HAVE_SASL
-virNetSASLSessionFree(client->sasl);
+virObjectUnref(client->sasl);
 client->sasl = NULL;
 #endif
 ka = client->keepalive;
@@ -556,8 +556,7 @@ void virNetClientSetSASLSession(virNetClientPtr client,
 virNetSASLSessionPtr sasl)
 {
 virNetClientLock(client);
-client->sasl = sasl;
-virNetSASLSessionRef(sasl);
+client->sasl = virObjectRef(sasl);
 virNetSocketSetSASLSession(client->sock, client->sasl);
 virNetClientUnlock(client);
 }
diff --git a/src/rpc/virnetsaslcontext.c b/src/rpc/virnetsaslcontext.c
index 8db0e15..f910d4c 100644
--- a/src/rpc/virnetsaslcontext.c
+++ b/src/rpc/virnetsaslcontext.c
@@ -37,24 +37,52 @@
 
 
 struct _virNetSASLContext {
+virObject object;
+
 virMutex lock;
 const char *const*usernameWhitelist;
-int refs;
 };
 
 struct _virNetSASLSession {
+virObject object;
+
 virMutex lock;
 sasl_conn_t *conn;
-int refs;
 size_t maxbufsize;
 };
 
 
+static virClassPtr virNetSASLContextClass;
+static virClassPtr virNetSASLSessionClass;
+static void virNetSASLContextDispose(void *obj);
+static void virNetSASLSessionDispose(void *obj);
+
+static int virNetSASLContextOnceInit(void)
+{
+if (!(virNetSASLContextClass = virClassNew("virNetSASLContext",
+   sizeof(virNetSASLContext),
+   virNetSASLContextDispose)))
+return -1;
+
+if (!(virNetSASLSessionClass = virClassNew("virNetSASLSession",
+   sizeof(virNetSASLSession),
+   virNetSASLSessionDispose)))
+return -1;
+
+return 0;
+}
+
+VIR_ONCE_GLOBAL_INIT(virNetSASLContext)
+
+
 virNetSASLContextPtr virNetSASLContextNewClient(void)
 {
 virNetSASLContextPtr ctxt;
 int err;
 
+if (virNetSASLContextInitialize() < 0)
+return NULL;
+
 err = sasl_client_init(NULL);
 if (err != SASL_OK) {
 virNetError(VIR_ERR_AUTH_FAILED,
@@ -63,10 +91,8 @@ virNetSASLContextPtr virNetSASLContextNewClient(void)
 return NULL;
 }
 
-if (VIR_ALLOC(ctxt) < 0) {
-virReportOOMError();
+if (!(ctxt = virObjectNew(virNetSASLContextClass)))
 retur

[libvirt] [PATCH 04/13] Add a generic reference counted virObject type

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

This introduces a fairly basic reference counted virObject type
and an associated virClass type, that use atomic operations for
ref counting.

In a global initializer (recommended to be invoked using the
virOnceInit API), a virClass type must be allocated for each
object type. This requires a class name, a "dispose" callback
which will be invoked to free memory associated with the object's
fields, and the size in bytes of the object struct.

eg,

   virClassPtr  connklass = virClassNew("virConnect",
sizeof(virConnect),
virConnectDispose);

The struct for the object, must include 'virObject' as its
first member

eg

  struct _virConnect {
virObject object;

virURIPtr uri;
  };

The 'dispose' callback is only responsible for freeing
fields in the object, not the object itself. eg a suitable
impl for the above struct would be

  void virConnectDispose(void *obj) {
 virConnectPtr conn = obj;
 virURIFree(conn->uri);
  }

There is no need to reset fields to 'NULL' or '0' in the
dispose callback, since the entire object will be memset
to 0, and the klass pointer & magic integer fields will
be poisoned with 0xDEADBEEF

When creating an instance of an object, one needs simply
pass the virClassPtr eg

   virConnectPtr conn = virObjectNew(connklass);
   if (!conn)
  return NULL;
   conn->uri = virURIParse("foo:///bar")

Object references can be manipulated with

   virObjectRef(conn)
   virObjectUnref(conn)

The latter returns a true value, if the object has been
freed (ie its ref count hit zero)

Signed-off-by: Daniel P. Berrange 
---
 src/Makefile.am  |1 +
 src/libvirt_private.syms |9 ++
 src/libvirt_probes.d |7 ++
 src/util/virobject.c |  203 ++
 src/util/virobject.h |   60 ++
 5 files changed, 280 insertions(+)
 create mode 100644 src/util/virobject.c
 create mode 100644 src/util/virobject.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 76d5eb7..2e596d5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -84,6 +84,7 @@ UTIL_SOURCES =
\
util/virauth.c util/virauth.h   \
util/virauthconfig.c util/virauthconfig.h   \
util/virfile.c util/virfile.h   \
+   util/virobject.c util/virobject.h   \
util/virnodesuspend.c util/virnodesuspend.h \
util/virpidfile.c util/virpidfile.h \
util/virtypedparam.c util/virtypedparam.h   \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index e22b133..1ff6735 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1492,6 +1492,15 @@ nodeSuspendForDuration;
 virNodeSuspendGetTargetMask;
 
 
+# virobject.h
+virClassNew;
+virClassName;
+virObjectNew;
+virObjectRef;
+virObjectUnref;
+virObjectIsClass;
+
+
 # virpidfile.h
 virPidFileAcquire;
 virPidFileAcquirePath;
diff --git a/src/libvirt_probes.d b/src/libvirt_probes.d
index 0dac8f3..ceb3caa 100644
--- a/src/libvirt_probes.d
+++ b/src/libvirt_probes.d
@@ -16,6 +16,13 @@ provider libvirt {
probe event_poll_run(int nfds, int timeout);
 
 
+# file: src/util/virobject.c
+# prefix: object
+probe object_new(void *obj, const char *klassname);
+probe object_ref(void *obj);
+probe object_unref(void *obj);
+probe object_dispose(void *obj);
+
# file: src/rpc/virnetsocket.c
# prefix: rpc
probe rpc_socket_new(void *sock, int refs, int fd, int errfd, pid_t 
pid, const char *localAddr, const char *remoteAddr);
diff --git a/src/util/virobject.c b/src/util/virobject.c
new file mode 100644
index 000..002196e
--- /dev/null
+++ b/src/util/virobject.c
@@ -0,0 +1,203 @@
+/*
+ * virobject.c: libvirt reference counted object
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ */
+
+#include 
+
+#include "virobject.h"
+#include "threads.h"
+#include "memory.h"
+#include "viratomic.h"
+#include "virterror_internal.h"
+#include "logging.h"
+
+#define VIR_FROM_THIS VIR

[libvirt] [PATCH 01/13] Add a simple macro for doing one-time global init using virOnce

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Using virOnce for global initialization is desirable since it
ensures that initialization will always take place when it is
needed, and guarantees it only occurs once. The problem is that
the code to setup a global initializer with proper error
propagation is tedious. This introduces VIR_ONCE_GLOBAL_INIT
macro to simplify this.

Signed-off-by: Daniel P. Berrange 
---
 src/util/threads.h |   49 +
 1 file changed, 49 insertions(+)

diff --git a/src/util/threads.h b/src/util/threads.h
index e5000ea..8f192cf 100644
--- a/src/util/threads.h
+++ b/src/util/threads.h
@@ -114,4 +114,53 @@ int virThreadLocalSet(virThreadLocalPtr l, void*) 
ATTRIBUTE_RETURN_CHECK;
 #  error "Either pthreads or Win32 threads are required"
 # endif
 
+
+/**
+ * VIR_ONCE_GLOBAL_INIT:
+ * classname: base classname
+ *
+ * This macro simplifies the setup of a one-time only
+ * global file initializer.
+ *
+ * Assuming a class called "virMyObject", and a method
+ * implemented like:
+ *
+ *  int virMyObjectOnceInit(void) {
+ *  ...do init tasks...
+ *  }
+ *
+ * Then invoking the macro:
+ *
+ *  VIR_ONCE_GLOBAL_INIT(virMyObject)
+ *
+ * Will create a method
+ *
+ *  int virMyObjectInitialize(void);
+ *
+ * Which will ensure that 'virMyObjectOnceInit' is
+ * guaranteed to be invoked exactly once.
+ */
+# define VIR_ONCE_GLOBAL_INIT(classname)\
+static virOnceControl classname ## OnceControl = 
VIR_ONCE_CONTROL_INITIALIZER; \
+static virErrorPtr classname ## OnceError = NULL;   \
+\
+static void classname ## Once(void) \
+{   \
+if (classname ## OnceInit() < 0)\
+classname ## OnceError = virSaveLastError();\
+}   \
+\
+static int classname ## Initialize(void)\
+{   \
+if (virOnce(&classname ## OnceControl, classname ## Once) < 0)  \
+return -1;  \
+\
+if (classname ## OnceError) {   \
+virSetError(classname ## OnceError);\
+return -1;  \
+}   \
+\
+return 0;   \
+}
+
 #endif
-- 
1.7.10.2

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


[libvirt] [PATCH 03/13] Rewrite virAtomic APIs using GLib's atomic ops code

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

There are a few issues with the current virAtomic APIs

 - They require use of a virAtomicInt struct instead of a plain
   int type
 - Several of the methods do not implement memory barriers
 - The methods do not implement compiler re-ordering barriers
 - There is no Win32 native impl

The GLib library has a nice LGPLv2+ licensed impl of atomic
ops that works with GCC, Win32, or pthreads.h that addresses
all these problems. The main downside to their code is that
the pthreads impl uses a single global mutex, instead of
a per-variable mutex. Given that it does have a Win32 impl
though, we don't expect anyone to seriously use the pthread.h
impl, so this downside is not significant.

* .gitignore: Ignore test case
* configure.ac: Check for which atomic ops impl to use
* src/Makefile.am: Add viratomic.c
* src/nwfilter/nwfilter_dhcpsnoop.c: Switch to new atomic
  ops APIs and plain int datatype
* src/util/viratomic.h: inline impls of all atomic ops
  for GCC, Win32 and pthreads
* src/util/viratomic.c: Global pthreads mutex for atomic
  ops
* tests/viratomictest.c: Test validate to validate safety
  of atomic ops.

Signed-off-by: Daniel P. Berrange 
---
 .gitignore|1 +
 configure.ac  |   59 +-
 src/Makefile.am   |6 +-
 src/libvirt_atomic.syms   |3 +
 src/nwfilter/nwfilter_dhcpsnoop.c |   48 ++---
 src/util/viratomic.c  |   35 +++
 src/util/viratomic.h  |  424 ++---
 src/util/virfile.c|4 +-
 tests/Makefile.am |5 +
 tests/viratomictest.c |  180 
 10 files changed, 663 insertions(+), 102 deletions(-)
 create mode 100644 src/libvirt_atomic.syms
 create mode 100644 src/util/viratomic.c
 create mode 100644 tests/viratomictest.c

diff --git a/.gitignore b/.gitignore
index e5d5db9..3fe9486 100644
--- a/.gitignore
+++ b/.gitignore
@@ -146,6 +146,7 @@
 /tests/ssh
 /tests/statstest
 /tests/utiltest
+/tests/viratomictest
 /tests/virauthconfigtest
 /tests/virbuftest
 /tests/virdrivermoduletest
diff --git a/configure.ac b/configure.ac
index d45f4f1..2ac17a4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -157,7 +157,64 @@ dnl Availability of various common headers (non-fatal if 
missing).
 AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/un.h \
   sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h \
   sys/un.h sys/syscall.h netinet/tcp.h ifaddrs.h libtasn1.h \
-  net/if.h execinfo.h])
+  net/if.h execinfo.h pthread.h])
+
+dnl We need to decide at configure time if libvirt will use real atomic
+dnl operations ("lock free") or emulated ones with a mutex.
+
+dnl Note that the atomic ops are only available with GCC on x86 when
+dnl using -march=i486 or higher.  If we detect that the atomic ops are
+dnl not available but would be available given the right flags, we want
+dnl to abort and advise the user to fix their CFLAGS.  It's better to do
+dnl that then to silently fall back on emulated atomic ops just because
+dnl the user had the wrong build environment.
+
+atomic_ops=
+
+AC_MSG_CHECKING([for atomic ops implementation])
+
+AC_TRY_COMPILE([], [__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;],[
+  atomic_ops=gcc
+],[])
+
+if test "$atomic_ops" = "" ; then
+  SAVE_CFLAGS="${CFLAGS}"
+  CFLAGS="-march=i486"
+  AC_TRY_COMPILE([],
+ [__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4;],
+ [AC_MSG_ERROR([Libvirt must be build with -march=i486 or 
later.])],
+ [])
+  CFLAGS="${SAVE_CFLAGS}"
+
+  case "$host" in
+*-*-mingw* | *-*-cygwin* | *-*-msvc* )
+  atomic_ops=win32
+  ;;
+*)
+  if test "$ac_cv_header_pthread_h" = "yes" ; then
+atomic_ops=pthread
+  else
+AC_MSG_ERROR([Libvirt must be built with GCC or have pthread.h on 
non-Win32 platforms])
+  fi
+  ;;
+  esac
+fi
+
+case "$atomic_ops" in
+   gcc)
+ AC_DEFINE([VIR_ATOMIC_OPS_GCC],[1],[Use GCC atomic ops])
+ ;;
+   win32)
+ AC_DEFINE([VIR_ATOMIC_OPS_WIN32],[1],[Use Win32 atomic ops])
+ ;;
+   pthread)
+ AC_DEFINE([VIR_ATOMIC_OPS_PTHREAD],[1],[Use pthread atomic ops emulation])
+ ;;
+esac
+AM_CONDITIONAL([WITH_ATOMIC_OPS_PTHREAD],[test "$atomic_ops" = "pthread"])
+AC_MSG_RESULT([$atomic_ops])
+
+
 
 AC_MSG_CHECKING([for struct ifreq in net/if.h])
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
diff --git a/src/Makefile.am b/src/Makefile.am
index 6c3eaa7..76d5eb7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -79,7 +79,7 @@ UTIL_SOURCES =
\
util/threadpool.c util/threadpool.h \
util/uuid.c util/uuid.h \
util/util.c util/util.h \
-   util/viratomic.h\
+   util/viratomic.h util/viratomic.c   \
util/viraudit.c util/vi

[libvirt] [PATCH 00/13] Introduce a virObject module fo reference counting

2012-07-11 Thread Daniel P. Berrange
Last year Hu Tao posted a series which introduced a virObject
type and converted the QEMU driver to use this for some of its
objects

  https://www.redhat.com/archives/libvir-list/2011-April/msg00316.html

While the idea was generally encouraged, the impl was never updated
with review feedback, although some of the atomic ops code was updated
and merged.

This series is an attempt to address the same problem. The significant
things in this series

 - Instead of storing a 'destroy' pointer in virObject itself,
   introduce a separate 'virClass' concept. As we add more
   functionality to virObject, the benefit of not duplicating
   class-level data in each object instance will be great

 - The virObject APIs take a 'void *' instead of virObjectPtr
   to avoid the need to litter the code with casts, albeit at
   a slight loss in compile time type safety checking

 - Replace our current atomic ops code with GLib's impl
   which is more complete, in particular it has Win32 support

 - Add a macro to facilitate creating one-time init functions
   usig virOnce

 - Convert all our public API objects to use this new code

 - Convert all code in src/rpc, src/conf and src/qemu to the
   new object APIs

In the future the things I plan to do are

 - Add a mutex to virObject - nearly all subclasses make use of
   a mutex, so it makes sense to provide one in the base class

 - Add generic support for callbacks. Currently each module
   deals with callbacks in a rather adhoc fashion. THis will
   create something similar in concept to GLib's 'signal'
   capabilities, though somewhat simpler.


 .gitignore|1 
 configure.ac  |   59 ++
 daemon/libvirtd.c |   27 -
 daemon/remote.c   |8 
 daemon/stream.c   |   19 
 src/Makefile.am   |7 
 src/conf/domain_conf.c|   59 --
 src/conf/domain_conf.h|8 
 src/conf/domain_event.c   |8 
 src/datatypes.c   |  999 --
 src/datatypes.h   |  264 +++---
 src/libvirt.c |  131 +---
 src/libvirt_atomic.syms   |3 
 src/libvirt_private.syms  |   42 -
 src/libvirt_probes.d  |   31 -
 src/libxl/libxl_driver.c  |6 
 src/lxc/lxc_controller.c  |8 
 src/nwfilter/nwfilter_dhcpsnoop.c |   48 -
 src/openvz/openvz_conf.c  |   17 
 src/phyp/phyp_driver.c|   14 
 src/qemu/qemu_agent.c |   86 +--
 src/qemu/qemu_agent.h |3 
 src/qemu/qemu_command.c   |2 
 src/qemu/qemu_domain.c|   49 -
 src/qemu/qemu_domain.h|8 
 src/qemu/qemu_driver.c|2 
 src/qemu/qemu_migration.c |   34 -
 src/qemu/qemu_migration.h |4 
 src/qemu/qemu_monitor.c   |   97 +--
 src/qemu/qemu_monitor.h   |3 
 src/qemu/qemu_process.c   |   52 -
 src/remote/remote_driver.c|   26 
 src/rpc/gendispatch.pl|4 
 src/rpc/virkeepalive.c|   73 +-
 src/rpc/virkeepalive.h|4 
 src/rpc/virnetclient.c|  117 +---
 src/rpc/virnetclient.h|4 
 src/rpc/virnetclientprogram.c |   43 -
 src/rpc/virnetclientprogram.h |5 
 src/rpc/virnetclientstream.c  |   65 +-
 src/rpc/virnetclientstream.h  |5 
 src/rpc/virnetsaslcontext.c   |  106 +---
 src/rpc/virnetsaslcontext.h   |8 
 src/rpc/virnetserver.c|   82 +--
 src/rpc/virnetserver.h|5 
 src/rpc/virnetserverclient.c  |  134 ++---
 src/rpc/virnetserverclient.h  |5 
 src/rpc/virnetserverprogram.c |   49 -
 src/rpc/virnetserverprogram.h |8 
 src/rpc/virnetserverservice.c |   97 +--
 src/rpc/virnetserverservice.h |5 
 src/rpc/virnetsocket.c|   85 +--
 src/rpc/virnetsocket.h|3 
 src/rpc/virnettlscontext.c|  110 +---
 src/rpc/virnettlscontext.h|   10 
 src/storage/storage_driver.c  |4 
 src/util/logging.c|   54 --
 src/util/logging.h|2 
 src/util/threads.h|   49 +
 src/util/viratomic.c  |   35 +
 src/util/viratomic.h  |  424 +---
 src/util/virfile.c|4 
 src/util/virnodesuspend.c |   25 
 src/util/virnodesuspend.h |1 
 src/util/virobject.c  |  203 +++
 src/util/virobject.h  |   60 ++
 src/vbox/vbox_tmpl.c  |2 
 src/vmware/vmware_conf.c  |4 
 src/xen/xend_internal.c   |4 
 tests/Makefile.am |5 
 tests/qemuxml2argvtest.c  |   21 
 tests/qemuxmlnstest.c |2 
 tests/sexpr2xmltest.c |2 
 tests/viratomictest.c |  180 ++
 tests/virnetsockettest.c  |   26 
 tests/virnettlscontexttest.c  

[libvirt] [PATCH 02/13] Remove manual nodesuspend & logging global initiaizers

2012-07-11 Thread Daniel P. Berrange
From: "Daniel P. Berrange" 

Remove the use of a manually run virLogStartup and
virNodeSuspendInitialize methods. Instead make sure they
are automatically run using VIR_ONCE_GLOBAL_INIT

Signed-off-by: Daniel P. Berrange 
---
 daemon/libvirtd.c |1 -
 src/libvirt.c |4 +---
 src/libvirt_private.syms  |3 ---
 src/util/logging.c|   54 +
 src/util/logging.h|2 --
 src/util/virnodesuspend.c |   25 +++--
 src/util/virnodesuspend.h |1 -
 7 files changed, 29 insertions(+), 61 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 8c434a0..79f37ae 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1331,7 +1331,6 @@ cleanup:
 VIR_FREE(run_dir);
 
 daemonConfigFree(config);
-virLogShutdown();
 
 return ret;
 }
diff --git a/src/libvirt.c b/src/libvirt.c
index db6ba15..c6640b2 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -41,7 +41,6 @@
 #include "conf.h"
 #include "rpc/virnettlscontext.h"
 #include "command.h"
-#include "virnodesuspend.h"
 #include "virrandom.h"
 #include "viruri.h"
 
@@ -395,8 +394,7 @@ virInitialize(void)
 
 if (virThreadInitialize() < 0 ||
 virErrorInitialize() < 0 ||
-virRandomInitialize(time(NULL) ^ getpid()) ||
-virNodeSuspendInit() < 0)
+virRandomInitialize(time(NULL) ^ getpid()))
 return -1;
 
 gcry_control(GCRYCTL_SET_THREAD_CBS, &virTLSThreadImpl);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6625fc6..e22b133 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -756,8 +756,6 @@ virLogReset;
 virLogSetBufferSize;
 virLogSetDefaultPriority;
 virLogSetFromEnv;
-virLogShutdown;
-virLogStartup;
 virLogUnlock;
 
 
@@ -1491,7 +1489,6 @@ virNetTLSSessionSetIOCallbacks;
 
 # virnodesuspend.h
 nodeSuspendForDuration;
-virNodeSuspendInit;
 virNodeSuspendGetTargetMask;
 
 
diff --git a/src/util/logging.c b/src/util/logging.c
index f8233cd..59b455e 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -147,25 +147,14 @@ static const char *virLogPriorityString(virLogPriority 
lvl) {
 return "unknown";
 }
 
-static int virLogInitialized = 0;
 
-/**
- * virLogStartup:
- *
- * Initialize the logging module
- *
- * Returns 0 if successful, and -1 in case or error
- */
-int virLogStartup(void) {
+static int virLogOnceInit(void)
+{
 const char *pbm = NULL;
 
-if (virLogInitialized)
-return -1;
-
 if (virMutexInit(&virLogMutex) < 0)
 return -1;
 
-virLogInitialized = 1;
 virLogLock();
 if (VIR_ALLOC_N(virLogBuffer, virLogSize + 1) < 0) {
 /*
@@ -191,6 +180,8 @@ int virLogStartup(void) {
 return 0;
 }
 
+VIR_ONCE_GLOBAL_INIT(virLog)
+
 /**
  * virLogSetBufferSize:
  * @size: size of the buffer in kilobytes or <= 0 to deactivate
@@ -211,7 +202,10 @@ virLogSetBufferSize(int size) {
 if (size < 0)
 size = 0;
 
-if ((virLogInitialized == 0) || (size * 1024 == virLogSize))
+if (virLogInitialize() < 0)
+return -1;
+
+if (size * 1024 == virLogSize)
 return ret;
 
 virLogLock();
@@ -253,8 +247,8 @@ error:
  * Returns 0 if successful, and -1 in case or error
  */
 int virLogReset(void) {
-if (!virLogInitialized)
-return virLogStartup();
+if (virLogInitialize() < 0)
+return -1;
 
 virLogLock();
 virLogResetFilters();
@@ -266,25 +260,6 @@ int virLogReset(void) {
 virLogUnlock();
 return 0;
 }
-/**
- * virLogShutdown:
- *
- * Shutdown the logging module
- */
-void virLogShutdown(void) {
-if (!virLogInitialized)
-return;
-virLogLock();
-virLogResetFilters();
-virLogResetOutputs();
-virLogLen = 0;
-virLogStart = 0;
-virLogEnd = 0;
-VIR_FREE(virLogBuffer);
-virLogUnlock();
-virMutexDestroy(&virLogMutex);
-virLogInitialized = 0;
-}
 
 /*
  * Store a string in the ring buffer
@@ -450,8 +425,9 @@ int virLogSetDefaultPriority(int priority) {
 VIR_WARN("Ignoring invalid log level setting.");
 return -1;
 }
-if (!virLogInitialized)
-virLogStartup();
+if (virLogInitialize() < 0)
+return -1;
+
 virLogDefaultPriority = priority;
 return 0;
 }
@@ -723,8 +699,8 @@ void virLogVMessage(const char *category, int priority, 
const char *funcname,
 int emit = 1;
 unsigned int filterflags = 0;
 
-if (!virLogInitialized)
-virLogStartup();
+if (virLogInitialize() < 0)
+return;
 
 if (fmt == NULL)
 goto cleanup;
diff --git a/src/util/logging.h b/src/util/logging.h
index 70318d0..d02cda7 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -125,9 +125,7 @@ extern int virLogDefineOutput(virLogOutputFunc f, 
virLogCloseFunc c, void *data,
 
 extern void virLogLock(void);
 extern void virLogUnlock(void);
-extern int virLogStartup(void);
 extern int virLogReset(void);
-extern void virLogShutdown(void);
 extern i

[libvirt] [glib PATCH V2] Add bindings for virDomainSave*()

2012-07-11 Thread Jovanka Gulicoska
---
 libvirt-gobject/libvirt-gobject-domain.c |  149 +-
 libvirt-gobject/libvirt-gobject-domain.h |   20 +++-
 libvirt-gobject/libvirt-gobject.sym  |3 +
 3 files changed, 170 insertions(+), 2 deletions(-)

diff --git a/libvirt-gobject/libvirt-gobject-domain.c 
b/libvirt-gobject/libvirt-gobject-domain.c
index 088cd33..eda2427 100644
--- a/libvirt-gobject/libvirt-gobject-domain.c
+++ b/libvirt-gobject/libvirt-gobject-domain.c
@@ -54,7 +54,7 @@ enum {
 VIR_SUSPENDED,
 VIR_RESUMED,
 VIR_STOPPED,
-VIR_UPDATED,
+VIR_UPDATED, 
 LAST_SIGNAL
 };
 
@@ -557,6 +557,153 @@ gboolean gvir_domain_reboot(GVirDomain *dom,
 }
 
 /**
+ * gvir_domain_save_to_file:
+ * @dom: the domain
+ * @filename: path to the output file
+ * @conf: configuration for domain
+ * @flags: the flags
+ *
+ * Returns: TRUE on success, FALSE otherwise 
+ */
+gboolean gvir_domain_save_to_file(GVirDomain *dom,
+  gchar *filename,
+  GVirConfigDomain *conf,
+  guint flags,
+  GError **err)
+{
+GVirDomainPrivate *priv;
+gchar *custom_xml;
+int ret;
+
+g_return_val_if_fail(GVIR_IS_DOMAIN(dom), FALSE);
+g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN (conf), FALSE);
+g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+priv = dom->priv;
+custom_xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+   
+if (flags || (custom_xml != NULL)) {
+ret = virDomainSaveFlags(priv->handle, filename, custom_xml, flags);
+g_free (custom_xml);
+}
+else {
+ret = virDomainSave(priv->handle, filename);
+g_free (custom_xml);
+}
+if (ret < 0) {
+gvir_set_error_literal(err, GVIR_DOMAIN_ERROR,
+ 0,
+ "Unable to save domain to file");
+return FALSE;
+}
+
+return TRUE;
+}
+
+typedef struct {
+gchar *filename;
+gchar *custom_xml;
+guint flags;
+} DomainSaveToFileData;
+
+static void domain_save_to_file_data_free(DomainSaveToFileData *data)
+{
+g_free(data->filename);
+g_free(data->custom_xml);
+g_slice_free(DomainSaveToFileData, data);
+}
+
+static void
+gvir_domain_save_to_file_helper(GSimpleAsyncResult *res,
+GObject *object,
+GCancellable *cancellable G_GNUC_UNUSED)
+{
+GVirDomain *dom = GVIR_DOMAIN(object);
+DomainSaveToFileData *data;
+GVirConfigDomain *conf;
+GError *err = NULL;
+  
+data = g_simple_async_result_get_op_res_gpointer(res);
+conf = gvir_domain_get_config(dom, data->flags, &err);
+  
+if (!gvir_domain_save_to_file(dom, data->filename, conf, data->flags, 
&err))
+   g_simple_async_result_take_error(res, err);
+ }
+
+/**
+ * gvir_domain_save_to_file_async:
+ * @dom: the domain
+ * @filename: path to output file
+ * @conf: configuration for domain
+ * @flags: the flags
+ * @cancellable: cancallation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ *
+ * Asynchronous variant of #gvir_domain_save_to_file
+ */
+void gvir_domain_save_to_file_async (GVirDomain *dom,
+ gchar *filename,
+ GVirConfigDomain *conf,
+ guint flags,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+GSimpleAsyncResult *res;
+DomainSaveToFileData *data;
+gchar *xml;
+ 
+g_return_if_fail(GVIR_IS_DOMAIN(dom));
+g_return_if_fail(GVIR_CONFIG_IS_DOMAIN (conf));
+g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
+
+xml = gvir_config_object_to_xml(GVIR_CONFIG_OBJECT(conf));
+
+data = g_slice_new0(DomainSaveToFileData);
+data->filename = g_strdup(filename);
+data->custom_xml = g_strdup(xml);
+data->flags = flags;
+
+res = g_simple_async_result_new(G_OBJECT(dom),
+callback,
+user_data,
+gvir_domain_save_to_file_async);
+g_simple_async_result_set_op_res_gpointer(res, data, 
(GDestroyNotify)domain_save_to_file_data_free);
+
+g_simple_async_result_run_in_thread(res,
+gvir_domain_save_to_file_helper,
+G_PRIORITY_DEFAULT,
+cancellable);
+   
+g_object_unref(res);
+}
+
+/**
+ * gvir_domain_save_to_file_finish:
+ * @dom: the domain to save
+ * @result: (transfer none): async method result
+ * @err: Place-holder for possible errors
+ *
+ * Finishes the operation started by #gvir_domain_save

[libvirt] [PATCH] Fix directory removal in virStorageBackendFileSystemVolDelete

2012-07-11 Thread Sascha Peilicke
---
 src/storage/storage_backend_fs.c |   28 +++-
 1 file changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 4894994..df0aaf8 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1127,7 +1127,7 @@ virStorageBackendFileSystemVolBuildFrom(virConnectPtr 
conn,
 }
 
 /**
- * Remove a volume - just unlinks for now
+ * Remove a volume - no support for BLOCK and NETWORK yet
  */
 static int
 virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
@@ -1137,14 +1137,32 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 {
 virCheckFlags(0, -1);
 
-if (unlink(vol->target.path) < 0) {
-/* Silently ignore failures where the vol has already gone away */
-if (errno != ENOENT) {
+switch (vol->type) {
+case VIR_STORAGE_VOL_FILE:
+if (unlink(vol->target.path) < 0) {
+/* Silently ignore failures where the vol has already gone away */
+if (errno != ENOENT) {
+virReportSystemError(errno,
+ _("cannot unlink file '%s'"),
+ vol->target.path);
+return -1;
+}
+}
+break;
+case VIR_STORAGE_VOL_DIR:
+if (rmdir(vol->target.path) < 0) {
 virReportSystemError(errno,
- _("cannot unlink file '%s'"),
+ _("cannot remove directory '%s'"),
  vol->target.path);
 return -1;
 }
+break;
+case VIR_STORAGE_VOL_BLOCK:
+case VIR_STORAGE_VOL_NETWORK:
+default:
+virStorageReportError(VIR_ERR_NO_SUPPORT,
+  _("removing block or network volumes is not 
supported: %s"),
+  vol->target.path);
 }
 return 0;
 }
-- 
1.7.10.4

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


Re: [libvirt] [PATCH] Added timestamps to storage volumes

2012-07-11 Thread Hendrik Schwartke

On 11.07.2012 15:10, Eric Blake wrote:

On 07/11/2012 07:09 AM, Eric Blake wrote:

On 07/11/2012 01:12 AM, Hendrik Schwartke wrote:


+atime->tv_sec = sb.st_atime;
+mtime->tv_sec = sb.st_mtime;
+catime->tv_sec = sb.st_ctime;
+#if _BSD_SOURCE || _SVID_SOURCE
+atime->tv_nsec = sb.st_atim.tv_nsec;

Yuck.  I've nearly got consensus to use the gnulib stat-time module, in
which case this would instead be the much simpler:

Ok, that sounds good. But what exactly does 'nearly' mean?

It means 3 of the 4 copyright holders have agreed, with less than
24-hour turnaround time; the 4th will likely respond sometime this week:
https://lists.gnu.org/archive/html/bug-gnulib/2012-07/msg00141.html


Correction - there is only one copyright holder - the FSF.  But 3 of the
4 original contributors have agreed to a relicense, and if all original
contributors agree, then we don't have to bother the FSF with a much
more formal and lengthy process of convincing the FSF to relicense.


Oh, cool. I didn't thought that this could be done in such a short term.
So I will update my patch using stat-time this week so that it is ready 
if the license has changed.

(I will also add the birth time.)

Thanks
Hendrik

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


Re: [libvirt] [PATCHv4 2/4] nodeinfo: Fix gathering of nodeinfo data structure

2012-07-11 Thread Michal Privoznik
On 11.07.2012 11:47, Peter Krempa wrote:
> This patch changes the way data to fill the nodeinfo structure are
> gathered. We've gathere the test data by iterating processors an sockets
> separately from nodes. The reported data was based solely on information
> about core id. Problems arise when eg cores in mulit-processor machines
> don't have same id's on both processors or maybe one physical processor
> contains more NUMA nodes.
> 
> This patch changes the approach how we detect processors and nodes. Now
> we start at enumerating nodes and for each node processors, sockets and
> threads are enumerated separately. This approach provides acurate data
> that comply to docs about the nodeinfo structure. This also enables to
> get rid of hacks: see commits 10d9038b744a69c8d4bd29c2e8c012a097481586,
> ac9dd4a676f21b5e3ca6dbe0526f2a6709072beb. (Those changes in nodeinfo.c
> are efectively reverted by this patch).
> 
> This patch also changes output of one of the tests, as the processor
> topology is now acquired more precisely.
> ---
> Changes to v3:
> - added ATTRIBUTE_NONNULL to arguments of virNodeParseNode()
> - added resetting of errno before calling readdir()
> - indented comment properly
> - edited comment placed before parsing info from /proc/cpuinfo to reflect 
> current state better
> ---
>  src/nodeinfo.c |  326 
> 
>  .../linux-nodeinfo-sysfs-test-3-cpu-x86-output.txt |2 +-
>  2 files changed, 197 insertions(+), 131 deletions(-)

ACK

Michal

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


Re: [libvirt] [PATCH] Added timestamps to storage volumes

2012-07-11 Thread Eric Blake
On 07/11/2012 07:09 AM, Eric Blake wrote:
> On 07/11/2012 01:12 AM, Hendrik Schwartke wrote:
> 
 +atime->tv_sec = sb.st_atime;
 +mtime->tv_sec = sb.st_mtime;
 +catime->tv_sec = sb.st_ctime;
 +#if _BSD_SOURCE || _SVID_SOURCE
 +atime->tv_nsec = sb.st_atim.tv_nsec;
>>> Yuck.  I've nearly got consensus to use the gnulib stat-time module, in
>>> which case this would instead be the much simpler:
>> Ok, that sounds good. But what exactly does 'nearly' mean?
> 
> It means 3 of the 4 copyright holders have agreed, with less than
> 24-hour turnaround time; the 4th will likely respond sometime this week:
> https://lists.gnu.org/archive/html/bug-gnulib/2012-07/msg00141.html
> 

Correction - there is only one copyright holder - the FSF.  But 3 of the
4 original contributors have agreed to a relicense, and if all original
contributors agree, then we don't have to bother the FSF with a much
more formal and lengthy process of convincing the FSF to relicense.

-- 
Eric Blake   ebl...@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] Added timestamps to storage volumes

2012-07-11 Thread Eric Blake
On 07/11/2012 01:12 AM, Hendrik Schwartke wrote:

>>> +atime->tv_sec = sb.st_atime;
>>> +mtime->tv_sec = sb.st_mtime;
>>> +catime->tv_sec = sb.st_ctime;
>>> +#if _BSD_SOURCE || _SVID_SOURCE
>>> +atime->tv_nsec = sb.st_atim.tv_nsec;
>> Yuck.  I've nearly got consensus to use the gnulib stat-time module, in
>> which case this would instead be the much simpler:
> Ok, that sounds good. But what exactly does 'nearly' mean?

It means 3 of the 4 copyright holders have agreed, with less than
24-hour turnaround time; the 4th will likely respond sometime this week:
https://lists.gnu.org/archive/html/bug-gnulib/2012-07/msg00141.html

>> But before we can use the gnulib stat-time module, we have to update
>> .gnulib and bootstrap.conf; and I'm holding off on the .gnulib update
>> until after fixed Automake is available in at least Fedora 17 (right
>> now, unless you are manually using automake 1.11.6 or newer, you are
>> injecting a security bug into every other package that uses automake).
> So any idea how long this will take?

Being a security patch that affects multiple packages, I'm sure it won't
be too long in the works.

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



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

[libvirt] Unable to make libvirt

2012-07-11 Thread B Veera-B37207
Hi,

I am unable to compile libvirt -0.9.13


1.   ./configure (Executed successfully without any errors)

2.   While executing make I am getting following Error

/bin/sed: can't read =/usr/lib/libnl-route.la: No such file or directory

libtool: link: `=/usr/lib/libnl-route.la' is not a valid libtool archive

make[3]: *** [libvirt.la] Error 1

make[3]: Leaving directory `/home/root/libvirt-0.9.13/src'

make[2]: *** [all] Error 2

make[2]: Leaving directory `/home/root/libvirt-0.9.13/src'

make[1]: *** [all-recursive] Error 1

make[1]: Leaving directory `/home/root/libvirt-0.9.13'

make: *** [all] Error 2





But "=/usr/lib/libnl-route.la" file exist





Please help me regarding this.



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

Re: [libvirt] [PATCH] docs: added description of the vendor_id attribute

2012-07-11 Thread Hendrik Schwartke

On 11.07.2012 14:03, Jiri Denemark wrote:

On Wed, Jul 11, 2012 at 09:00:05 +0200, Hendrik Schwartke wrote:

On 10.07.2012 21:57, Jiri Denemark wrote:

I know I'm late in this vendor_id stuff but it hasn't been released yet so I'm
not too late. I assume the reason for introducing it is to be able to lie to a
guest. Please, correct me, if this is not the case.

Well, the reason is to specify a vendor_id which is different to the
actual host vendor id

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 94c555f..b6e0d5d 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -779,7 +779,11 @@
   in which case an attempt to start a domain requesting an unsupported
   CPU model will fail. Supported values forfallback
   attribute are:allow   (this is the default), and
-forbid.
+forbid. The optionalvendor_id   attribute
+(Since 0.9.14)  can be used to set the
+vendor id seen by the guest. It must be exactly 12 characters long.
+If not set the vendor id of the host is used. Typical possible
+values are "AuthenticAMD" and "GenuineIntel".

 vendor
 Since 0.8.3   the content of the

This is wrong (unless your previous patch explicitly modified the code to
behave like this). If vendor_id is not set, a guest should see model's default
vendor. If a guest is configured with, e.g., SandyBridge model, its vendor
will be "GenuineIntel". If a guest uses Opteron_G3, it will see "AuthenticAMD"
vendor. All this regardless on the vendor of the host CPU as longs as the host
CPU is capable enough to support all features of a given guest CPU.

I have tested this (with the qemu driver) and that's not correct. I'm
sure you have to set the vendor attribute in the qemu command line to
set the vendor id. So "kvm -cpu core2duo -cdrom
debian-6.0.5-i386-netinst.iso" on an amd machine results in vendor id =
AuthenticAMD (just as with -cpu 486)

Oh, you are right. I tried with Opteron_G1 on Sandy Bridge host and indeed the
guest sees it as Opteron made by Intel. I think this is a QEMU bug as its CPU
configuration says:

 [cpudef]
name = "Opteron_G1"
level = "5"
vendor = "AuthenticAMD"
...



No, it's not a bug it's a feature ;). There are a few instructions that 
are implemented differently on intel and amd cpus (e.g.SYSENTER and 
SYSCALL). So in the past it was important for the guest to know the 
correct cpu vendor and therefor it wasn't possible to fake it. But since 
a while these few instructions can be emulated by qemu, so that it's 
know unproblematic to change it. (See 
http://developer.amd.com/assets/CrossVendorMigration.pdf)
I'm not sure but I'm supposing that the old behavior of qemu to set all 
cpu properties with the exception of the vendor id is still in use to 
avoid compatibility issues. If you want to specify a guest cpu 
*including* the vendor id you have to set the additional vendor attribute.



Anyway, to be honest, I'm not a big fan of the new vendor_id attribute.
Currently we have

  
Model
...
  

to force "bleblablebla" vendor ID on the guest CPU and

  
Model
Intel
...
  

to make sure the guest will be run only on a host with Intel CPU.

I think it would be much better to reuse the already existing
element. We could perhaps add new force attribute for vendor element. Thus,

These are two different things. One is the vendor_id the guest should
see and the other the vendor id the host should have to start the
domain. So if the CPUID instruction in the guest should return
"NOT-INTEL" and the host cpu should be an intel cpu a force bit is not
enough. Furthermore it would be confusing to use only one attribute to
specify the vendor of the host and the guest cpu.

Yes, I know there are two different things here. However, having
element specifying host's vendor and vendor_id attribute for model element
specifying guest's vendor feels a bit odd. Let's see what other thinks about
this matter.

Jirka


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


Re: [libvirt] [PATCH] docs: added description of the vendor_id attribute

2012-07-11 Thread Jiri Denemark
On Wed, Jul 11, 2012 at 09:00:05 +0200, Hendrik Schwartke wrote:
> On 10.07.2012 21:57, Jiri Denemark wrote:
> > I know I'm late in this vendor_id stuff but it hasn't been released yet so 
> > I'm
> > not too late. I assume the reason for introducing it is to be able to lie 
> > to a
> > guest. Please, correct me, if this is not the case.
> Well, the reason is to specify a vendor_id which is different to the 
> actual host vendor id
> >> diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
> >> index 94c555f..b6e0d5d 100644
> >> --- a/docs/formatdomain.html.in
> >> +++ b/docs/formatdomain.html.in
> >> @@ -779,7 +779,11 @@
> >>   in which case an attempt to start a domain requesting an 
> >> unsupported
> >>   CPU model will fail. Supported values forfallback
> >>   attribute are:allow  (this is the default), and
> >> -forbid.
> >> +forbid. The optionalvendor_id  attribute
> >> +(Since 0.9.14)  can be used to set the
> >> +vendor id seen by the guest. It must be exactly 12 characters 
> >> long.
> >> +If not set the vendor id of the host is used. Typical possible
> >> +values are "AuthenticAMD" and "GenuineIntel".
> >>
> >> vendor
> >> Since 0.8.3  the content of the
> >
> > This is wrong (unless your previous patch explicitly modified the code to
> > behave like this). If vendor_id is not set, a guest should see model's 
> > default
> > vendor. If a guest is configured with, e.g., SandyBridge model, its vendor
> > will be "GenuineIntel". If a guest uses Opteron_G3, it will see 
> > "AuthenticAMD"
> > vendor. All this regardless on the vendor of the host CPU as longs as the 
> > host
> > CPU is capable enough to support all features of a given guest CPU.
> I have tested this (with the qemu driver) and that's not correct. I'm 
> sure you have to set the vendor attribute in the qemu command line to 
> set the vendor id. So "kvm -cpu core2duo -cdrom 
> debian-6.0.5-i386-netinst.iso" on an amd machine results in vendor id = 
> AuthenticAMD (just as with -cpu 486)

Oh, you are right. I tried with Opteron_G1 on Sandy Bridge host and indeed the
guest sees it as Opteron made by Intel. I think this is a QEMU bug as its CPU
configuration says:

[cpudef]
   name = "Opteron_G1"
   level = "5"
   vendor = "AuthenticAMD"
   ...

> > Anyway, to be honest, I'm not a big fan of the new vendor_id attribute.
> > Currently we have
> >
> >  
> >Model
> >...
> >  
> >
> > to force "bleblablebla" vendor ID on the guest CPU and
> >
> >  
> >Model
> >Intel
> >...
> >  
> >
> > to make sure the guest will be run only on a host with Intel CPU.
> >
> > I think it would be much better to reuse the already existing
> > element. We could perhaps add new force attribute for vendor element. Thus,
> These are two different things. One is the vendor_id the guest should 
> see and the other the vendor id the host should have to start the 
> domain. So if the CPUID instruction in the guest should return 
> "NOT-INTEL" and the host cpu should be an intel cpu a force bit is not 
> enough. Furthermore it would be confusing to use only one attribute to 
> specify the vendor of the host and the guest cpu.

Yes, I know there are two different things here. However, having 
element specifying host's vendor and vendor_id attribute for model element
specifying guest's vendor feels a bit odd. Let's see what other thinks about
this matter.

Jirka

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


Re: [libvirt] [PATCH] Fix directory removal in virStorageBackendFileSystemVolDelete

2012-07-11 Thread Sascha Peilicke
On 07/11/2012 01:51 PM, Daniel P. Berrange wrote:
> On Wed, Jul 11, 2012 at 01:25:34PM +0200, Sascha Peilicke wrote:
>> ---
>>  src/storage/storage_backend_fs.c |   11 +++
>>  1 file changed, 11 insertions(+)
>>
>> diff --git a/src/storage/storage_backend_fs.c 
>> b/src/storage/storage_backend_fs.c
>> index 4894994..8e93aaa 100644
>> --- a/src/storage/storage_backend_fs.c
>> +++ b/src/storage/storage_backend_fs.c
>> @@ -1138,6 +1138,17 @@ virStorageBackendFileSystemVolDelete(virConnectPtr 
>> conn ATTRIBUTE_UNUSED,
>>  virCheckFlags(0, -1);
>>  
>>  if (unlink(vol->target.path) < 0) {
>> +if (errno == EISDIR /* linux */ ||
>> +errno == EPERM /* posix */) {
>> +if (rmdir(vol->target.path) < 0) {
>> +virReportSystemError(errno,
>> + _("cannot remove directory '%s'"),
>> + vol->target.path);
>> +return -1;
>> +} else {
>> +return 0;
>> +}
>> +}
> 
> The vol->type field should already tell us whether the volume is a FILE,
> BLOCK, NETWORK or DIR object. We should make this code switch(vol->type)
> and use unlink or rmdir as appropriate, and raise an error for BLOCK
> or NETWORK types
Sounds reasonable, I'll adjust the patch.

-- 
With kind regards,
Sascha Peilicke
SUSE Linux GmbH, Maxfeldstr. 5, D-90409 Nuernberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer HRB 16746 (AG Nürnberg)





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] Problem setting CPU topology

2012-07-11 Thread Eduardo Habkost
On Tue, Jul 10, 2012 at 09:19:37PM -0500, Doug Goldstein wrote:
> On Tue, Jul 10, 2012 at 2:02 PM, Eduardo Habkost  wrote:
> > On Tue, Jul 10, 2012 at 11:54:05AM +0200, Christophe Fergeau wrote:
> >> On Sat, Jul 07, 2012 at 07:10:53PM +0300, Zeeshan Ali (Khattak) wrote:
> >> > Hi,
> >> >I'm trying to set exact CPU topology to qemu-kvm domains to match
> >> > host's topology. In my case, host topology is: 1 socket, 2 cores and 2
> >> > threads. If I set the XML like this:
> >> >
> >> > 
> >> >   ..
> >> >   4
> >> >   
> >> > hvm
> >> > 
> >> >   
> >> >   
> >> > 
> >> > 
> >> >   
> >> > ..
> >> >
> >> > The qemu commandline launched for this domain looks like this:
> >> >
> >> > /usr/bin/qemu-kvm -name fedora17-2 -S -M pc-0.15 -cpu
> >> > core2duo,+lahf_lm,+rdtscp,+aes,+popcnt,+sse4.2,+sse4.1,+pdcm,+xtpr,+cx16,+tm2,+est,+smx,+vmx,+ds_cpl,+dtes64,+pclmuldq,+pbe,+tm,+ht,+ss,+acpi,+ds
> >> > -enable-kvm -m 1152 -smp 4,sockets=1,cores=2,threads=2 -uuid
> >> > c573342b-2876-05b8-098e-6d5314cab062 -nodefconfig -nodefaults -chardev
> >> > socket,id=charmonitor,path=/home/zeenix/.config/libvirt/qemu/lib/fedora17-2.monitor,server,nowait
> >> > -mon chardev=charmonitor,id=monitor,mode=control -rtc
> >> > base=utc,driftfix=slew -no-kvm-pit-reinjection -no-shutdown -no-acpi
> >>
> >> I debugged this together with Zeeshan, and the issue comes from this 
> >> -no-acpi flag
> >> which libvirt added because the domain XML was missing
> >> 
> >> So in the end that was a bug in Boxes, not really a libvirt/qemu issue.
> >> Unless libvirt/qemu should be taught that CPU topology won't work without 
> >> ACPI
> >> and complain about it?
> >
> > I don't think it's really impossible for any guest OS to recognize the
> > CPU topology or boot the other CPUs without ACPI. It looks like it's
> > just a limitation of (most?) guest OSes. If that's the case, libvirt or
> > QEMU can't prevent the user from running a (possibly valid)
> > configuration just because it's not very common.
> >
> > --
> > Eduardo
> >
> 
> Isn't MPS and APIC support required for a guest OS to really handle
> the topology correctly? Now days ACPI provides most of that
> information so its likely that QEMU doesn't support plain old MPS +
> APIC. Its also possible that QEMU does support this but the kernel got
> confused because I see the CPUID +acpi specified in the command line
> while -no-acpi is on the command line as you noted.
> 

QEMU + Seabios have plain old MPS working, and from my tests it looks
like:

- Seabios is able to init all VCPUs correctly.
- The MP-table contains only 1 entry for each CPU package (not for each
  core+thread). I don't understand why exactly, but I am assuming that
  this is a feature, not a bug (there's some discussion about it at
  [1]).
- The CPUID information exposed by QEMU reflect the topology correctly.

With that information, nothing really prevents the guest from trying to
init the other cores/threads in each package after parsing the MP-table.
On the other hand, I don't think there's any spec that recommends an
algorithm for that (as the MPS spec is too old to have any mention of
multi-core or hyper-threading).

[1] http://www.coreboot.org/pipermail/coreboot/2009-November/054119.html

-- 
Eduardo

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


Re: [libvirt] [PATCH] Fix directory removal in virStorageBackendFileSystemVolDelete

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 01:25:34PM +0200, Sascha Peilicke wrote:
> ---
>  src/storage/storage_backend_fs.c |   11 +++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/src/storage/storage_backend_fs.c 
> b/src/storage/storage_backend_fs.c
> index 4894994..8e93aaa 100644
> --- a/src/storage/storage_backend_fs.c
> +++ b/src/storage/storage_backend_fs.c
> @@ -1138,6 +1138,17 @@ virStorageBackendFileSystemVolDelete(virConnectPtr 
> conn ATTRIBUTE_UNUSED,
>  virCheckFlags(0, -1);
>  
>  if (unlink(vol->target.path) < 0) {
> +if (errno == EISDIR /* linux */ ||
> +errno == EPERM /* posix */) {
> +if (rmdir(vol->target.path) < 0) {
> +virReportSystemError(errno,
> + _("cannot remove directory '%s'"),
> + vol->target.path);
> +return -1;
> +} else {
> +return 0;
> +}
> +}

The vol->type field should already tell us whether the volume is a FILE,
BLOCK, NETWORK or DIR object. We should make this code switch(vol->type)
and use unlink or rmdir as appropriate, and raise an error for BLOCK
or NETWORK types


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [PATCHv3 4/5] S390: Domain Schema for s390-virtio machines.

2012-07-11 Thread Michal Privoznik
On 11.07.2012 10:42, Viktor Mihajlovski wrote:
> On 07/10/2012 05:50 PM, Michal Privoznik wrote:
>> On 09.07.2012 14:33, Viktor Mihajlovski wrote:
>>> On 07/03/2012 06:18 PM, Michal Privoznik wrote:
 On 29.06.2012 17:02, Viktor Mihajlovski wrote:
> Added s390-virtio machine type to the XML schema for domains in order
> to not fail the domain schema tests.
>
> Signed-off-by: Viktor Mihajlovski
> ---
>docs/schemas/domaincommon.rng |   20 
>1 files changed, 20 insertions(+), 0 deletions(-)
>
> diff --git a/docs/schemas/domaincommon.rng
> b/docs/schemas/domaincommon.rng
> index 912a1a2..70c7d16 100644
> --- a/docs/schemas/domaincommon.rng
> +++ b/docs/schemas/domaincommon.rng
> @@ -283,6 +283,7 @@
>  
>  
>  
> +
>
>  
>  hvm
> @@ -369,6 +370,25 @@
>  
>
>  
> +
> +
> +
> +
> +
> +s390
> +s390x
> +
> +
> +
> +
> +
> +
> +s390-virtio
>>
>> [1]^^
>>
> +
> +
> +
> +
> +
>  
>
>  
>

 Sorry cannot ACK this one until you update the documentation as well.

 Michal

>>>
>>> Hi Michal,
>>>
>>> actually I was pondering about a doc update when preparing the patches.
>>> I only wasn't clear where to put it. The only place where possible
>>> arch/machine values are mentioned seems to be in formatcaps.html.in.
>>> Would you expect me to add a sample output of the capabilities XML for
>>> s390 with some comments in there, or did you have something else in
>>> mind?
>>>
>>> Thanks.
>>>
>>
>> Actually, now I am going through docs I don't see a proper place
>> neither. Moreover, in formatdomain.html.in we state: "The Capabilities
>> XML provides details on allowed values for these" [these = @machine and
>> @type] So as long as we report them in capabilities XML I guess we don't
>> really need an doc extension.
>>
>> However, I think this [1] should be virtio-s390 instead of s390-virtio
>> since we use the former among the code.
>>
>> What do you think?
>>
>> Michal
>>
> 
> the naming is awkward and I stumble over it from time to time too.
> Unfortunately this is the terminology qemu uses.
> 
> In a nutshell:
> s390-virtio = machine type, meaning s390 machine with virtio bus
> virtio-s390 = bus type, meaning s390-specific virtio bus
> 
> The current virtio bus on s390 is a fully virtual bus not related to a
> real hardware bus like the PCI bus on the other architectures. So, while
> the names looks strange, they are technically correct.
> 

Okay. I've pushed the patch set.

Michal

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


[libvirt] [PATCH] Fix directory removal in virStorageBackendFileSystemVolDelete

2012-07-11 Thread Sascha Peilicke
---
 src/storage/storage_backend_fs.c |   11 +++
 1 file changed, 11 insertions(+)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 4894994..8e93aaa 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1138,6 +1138,17 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn 
ATTRIBUTE_UNUSED,
 virCheckFlags(0, -1);
 
 if (unlink(vol->target.path) < 0) {
+if (errno == EISDIR /* linux */ ||
+errno == EPERM /* posix */) {
+if (rmdir(vol->target.path) < 0) {
+virReportSystemError(errno,
+ _("cannot remove directory '%s'"),
+ vol->target.path);
+return -1;
+} else {
+return 0;
+}
+}
 /* Silently ignore failures where the vol has already gone away */
 if (errno != ENOENT) {
 virReportSystemError(errno,
-- 
1.7.10.4

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


[libvirt] [PATCHv2] fix failure when building with --disable-debug

2012-07-11 Thread Hu Tao
When building with --disable-debug, VIR_DEBUG expands to a nop.
But parameters to VIR_DEBUG can be variables that are passed only
to VIR_DEBUG. In the case the building system complains about unused
variables.
---
 cfg.mk |2 ++
 src/util/logging.h |8 +++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/cfg.mk b/cfg.mk
index 7664d5d..6e036fb 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -750,6 +750,8 @@ $(srcdir)/src/remote/remote_client_bodies.h: 
$(srcdir)/src/remote/remote_protoco
$(MAKE) -C src remote/remote_client_bodies.h
 
 # List all syntax-check exemptions:
+exclude_file_name_regexp--sc_avoid_attribute_unused_in_header = 
^src/util/logging\.h$$
+
 exclude_file_name_regexp--sc_avoid_strcase = ^tools/virsh\.c$$
 
 
_src1=libvirt|fdstream|qemu/qemu_monitor|util/(command|util)|xen/xend_internal|rpc/virnetsocket|lxc/lxc_controller
diff --git a/src/util/logging.h b/src/util/logging.h
index 70318d0..7cc5823 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -34,8 +34,14 @@
 #  define VIR_DEBUG_INT(category, f, l, ...)\
 virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__)
 # else
+/**
+ * virLogEatParam:
+ *
+ * Do nothing but eat parameters.
+ */
+static inline void virLogEatParam(void *unused ATTRIBUTE_UNUSED, ...) {}
 #  define VIR_DEBUG_INT(category, f, l, ...)\
-do { } while (0)
+virLogEatParam((void*)category, f, l, __VA_ARGS__)
 # endif /* !ENABLE_DEBUG */
 
 # define VIR_INFO_INT(category, f, l, ...)  \
-- 
1.7.10.2

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


[libvirt] [PATCH 1/2] vmx: handle shared folders formatting

2012-07-11 Thread Jean-Baptiste Rouault
This patch adds support for generating vmx files with
shared folders enabled.

Update test suite accordingly.
---
 src/vmx/vmx.c  |   59 +++-
 src/vmx/vmx.h  |3 ++
 tests/xml2vmxdata/xml2vmx-sharedfolder.vmx |   18 +
 tests/xml2vmxdata/xml2vmx-sharedfolder.xml |   14 +++
 tests/xml2vmxtest.c|2 +
 5 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 tests/xml2vmxdata/xml2vmx-sharedfolder.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-sharedfolder.xml

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 3de7062..8a26f8c 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -262,6 +262,29 @@ def->disks[0]...
 
 
 

+## filesystems 
#
+
+isolation.tools.hgfs.disable = "false" 
 # defaults to "true"
+
+def->nfss = 1 <=>   sharedFolder.maxNum = "1"  
 # must match the number of shared folders
+
+sharedFolder[0..n] -> 
+
+def->fss[0]...<=>   sharedFolder0.present = "true" 
 # defaults to "false"
+sharedFolder0.enabled = "true" 
 # defaults to "false"
+sharedFolder0.expiration = "never" 
 # defaults to "never"
+sharedFolder0.readAccess = "true"  
 # defaults to "false"
+->type = _FS_TYPE_MOUNT
+->fsdriver
+->accessmode
+->wrpolicy
+->src =<=>   sharedFolder0.hostPath = "" 
 # defaults to ?
+->dst =<=>   sharedFolder0.guestName = ""
+->readonly =<=>   sharedFolder0.writeAccess = ""  
 # "true" ->  = 0, "false" ->  = 1
+
+
+
+
 ## nets 

 
 ethernet[0..3] -> 
@@ -3142,7 +3165,16 @@ virVMXFormatConfig(virVMXContext *ctx, virCapsPtr caps, 
virDomainDefPtr def,
 }
 
 /* def:fss */
-/* FIXME */
+if (def->nfss > 0) {
+virBufferAddLit(&buffer, "isolation.tools.hgfs.disable = \"false\"\n");
+virBufferAsprintf(&buffer, "sharedFolder.maxNum = \"%d\"\n", 
def->nfss);
+}
+
+for (i = 0; i < def->nfss; ++i) {
+if (virVMXFormatFileSystem(def->fss[i], i, &buffer) < 0) {
+goto cleanup;
+}
+}
 
 /* def:nets */
 for (i = 0; i < def->nnets; ++i) {
@@ -3496,6 +3528,31 @@ virVMXFormatFloppy(virVMXContext *ctx, 
virDomainDiskDefPtr def,
 
 
 int
+virVMXFormatFileSystem(virDomainFSDefPtr def, int index, virBufferPtr buffer)
+{
+if (def->type != VIR_DOMAIN_FS_TYPE_MOUNT) {
+VMX_ERROR(VIR_ERR_CONFIG_UNSUPPORTED,
+  _("Only '%s' filesystem type is supported"),
+  virDomainFSTypeToString(VIR_DOMAIN_FS_TYPE_MOUNT));
+return -1;
+}
+
+virBufferAsprintf(buffer, "sharedFolder%d.present = \"true\"\n", index);
+virBufferAsprintf(buffer, "sharedFolder%d.enabled = \"true\"\n", index);
+virBufferAsprintf(buffer, "sharedFolder%d.readAccess = \"true\"\n", index);
+virBufferAsprintf(buffer, "sharedFolder%d.writeAccess = \"%s\"\n", index,
+  def->readonly ? "false" : "true");
+virBufferAsprintf(buffer, "sharedFolder%d.hostPath = \"%s\"\n", index,
+  def->src);
+virBufferAsprintf(buffer, "sharedFolder%d.guestName = \"%s\"\n", index,
+  def->dst);
+
+return 0;
+}
+
+
+
+int
 virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
  virBufferPtr buffer)
 {
diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h
index 4d54660..656aafa 100644
--- a/src/vmx/vmx.h
+++ b/src/vmx/vmx.h
@@ -120,6 +120,9 @@ int virVMXFormatCDROM(virVMXContext *ctx, 
virDomainDiskDefPtr def,
 int virVMXFormatFloppy(virVMXContext *ctx, virDomainDiskDefPtr def,
virBufferPtr buffer, bool floppy_present[2]);
 
+int virVMXFormatFileSystem(virDomainFSDefPtr def, int index,
+   virBufferPtr buffer);
+
 int virVMXFormatEthernet(virDomainNetDefPtr def, int controller,
  virBufferPtr buffer);
 
diff --git a/tests/xml2vmxdata/xml2vmx-sharedfolder.vmx 
b/tests/xml2vmxdata/xml2vmx-sharedfolder.vmx
new file mode 100644
index 000..15a322a
--- /dev/null
+++ b/tests/xml2vmxdata/xml2vmx-sharedfolder.vmx
@@ -0,0 +1,18 @@
+.encoding = "UTF-8"
+config.version = "8"
+virtualHW.version = "4"
+guestOS = "other"
+uuid.bios = "56 4d 9b ef ac d9 b4 e0-c8 f0 ae a8 b9 10 35 15"
+displayName = "sharedFolder"
+memsize = "4"
+numvcpus = "1"
+floppy0.present = "false"
+floppy1.present = "false"
+isolation.tools.hgfs.disab

[libvirt] [PATCH 2/2] vmx: handle shared folders parsing

2012-07-11 Thread Jean-Baptiste Rouault
This patch adds support for parsing vmx files with
shared folders enabled.

Update test suite accordingly.
---
 src/vmx/vmx.c  |  134 +++-
 src/vmx/vmx.h  |2 +
 tests/vmx2xmldata/vmx2xml-sharedfolder.vmx |9 ++
 tests/vmx2xmldata/vmx2xml-sharedfolder.xml |   22 +
 tests/vmx2xmltest.c|2 +
 5 files changed, 168 insertions(+), 1 deletion(-)
 create mode 100644 tests/vmx2xmldata/vmx2xml-sharedfolder.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-sharedfolder.xml

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 8a26f8c..d4f75ee 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1237,6 +1237,8 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, 
const char *vmx)
 bool present;
 int scsi_virtualDev[4] = { -1, -1, -1, -1 };
 int unit;
+bool hgfs_disabled = true;
+long long shared_folders_num = 0;
 
 if (ctx->parseFileName == NULL) {
 VMX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -1676,7 +1678,37 @@ virVMXParseConfig(virVMXContext *ctx, virCapsPtr caps, 
const char *vmx)
 }
 
 /* def:fss */
-/* FIXME */
+if (virVMXGetConfigBoolean(conf, "isolation.tools.hgfs.disable",
+   &hgfs_disabled, true, true) < 0) {
+goto cleanup;
+}
+
+if (!hgfs_disabled) {
+if (virVMXGetConfigLong(conf, "sharedFolder.maxNum", 
&shared_folders_num,
+0, true) < 0) {
+goto cleanup;
+}
+
+if (shared_folders_num) {
+if (VIR_ALLOC_N(def->fss, shared_folders_num) < 0) {
+virReportOOMError();
+goto cleanup;
+}
+
+def->nfss = 0;
+
+for (port = 0; port < shared_folders_num; ++port) {
+if (virVMXParseFileSystem(conf, port,
+  &def->fss[def->nfss]) < 0) {
+goto cleanup;
+}
+
+if (def->fss[def->nfss] != NULL) {
+++def->nfss;
+}
+}
+}
+}
 
 /* def:nets */
 if (VIR_ALLOC_N(def->nets, 4) < 0) {
@@ -2288,6 +2320,106 @@ virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, 
virConfPtr conf,
 
 
 
+int virVMXParseFileSystem(virConfPtr conf, int index, virDomainFSDefPtr *def)
+{
+int result = -1;
+char prefix[48] = "";
+
+char present_name[48] = "";
+bool present = false;
+
+char enabled_name[48] = "";
+bool enabled = false;
+
+char hostPath_name[48] = "";
+char *hostPath = NULL;
+
+char guestName_name[48] = "";
+char *guestName = NULL;
+
+char writeAccess_name[48] = "";
+bool writeAccess = false;
+
+if (def == NULL || *def != NULL) {
+VMX_ERROR(VIR_ERR_INTERNAL_ERROR, "%s", _("Invalid argument"));
+return -1;
+}
+
+if (VIR_ALLOC(*def) < 0) {
+virReportOOMError();
+return -1;
+}
+
+(*def)->type = VIR_DOMAIN_FS_TYPE_MOUNT;
+
+snprintf(prefix, sizeof(prefix), "sharedFolder%d", index);
+
+VMX_BUILD_NAME(present);
+VMX_BUILD_NAME(enabled);
+VMX_BUILD_NAME(hostPath);
+VMX_BUILD_NAME(guestName);
+VMX_BUILD_NAME(writeAccess);
+
+/* vmx:present */
+if (virVMXGetConfigBoolean(conf, present_name, &present, false, true) < 0) 
{
+goto cleanup;
+}
+
+/* vmx:enabled */
+if (virVMXGetConfigBoolean(conf, enabled_name, &enabled, false, true) < 0) 
{
+goto cleanup;
+}
+
+if (!(present && enabled)) {
+goto ignore;
+}
+
+/* vmx:hostPath */
+if (virVMXGetConfigString(conf, hostPath_name, &hostPath, false) < 0) {
+goto cleanup;
+}
+
+(*def)->src = strdup(hostPath);
+
+/* vmx:guestName */
+if (virVMXGetConfigString(conf, guestName_name, &guestName, false) < 0) {
+goto cleanup;
+}
+
+(*def)->dst = strdup(guestName);
+
+/* vmx:writeAccess */
+if (virVMXGetConfigBoolean(conf, writeAccess_name, &writeAccess, false,
+   true) < 0) {
+goto cleanup;
+}
+
+(*def)->readonly = !writeAccess;
+
+result = 0;
+
+  cleanup:
+if (result < 0) {
+virDomainFSDefFree(*def);
+*def = NULL;
+}
+
+VIR_FREE(hostPath);
+VIR_FREE(guestName);
+
+return result;
+
+  ignore:
+virDomainFSDefFree(*def);
+*def = NULL;
+
+result = 0;
+
+goto cleanup;
+}
+
+
+
 int
 virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
 {
diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h
index 656aafa..8ae0707 100644
--- a/src/vmx/vmx.h
+++ b/src/vmx/vmx.h
@@ -90,6 +90,8 @@ int virVMXParseDisk(virVMXContext *ctx, virCapsPtr caps, 
virConfPtr conf,
 int device, int busType, int controllerOrBus, int unit,
 virDomainDiskDefPtr *def);
 
+int virVMXParseFileSystem(virConfPtr conf, int index, virDomainFSDefPtr *def);
+
 in

[libvirt] [PATCH 0/2] vmx: handle shared folders

2012-07-11 Thread Jean-Baptiste Rouault
The following patches add support for shared folders
for VMware domains

Jean-Baptiste Rouault (2):
  vmx: handle shared folders formatting
  vmx: handle shared folders parsing

 src/vmx/vmx.c  |  193 +++-
 src/vmx/vmx.h  |5 +
 tests/vmx2xmldata/vmx2xml-sharedfolder.vmx |9 ++
 tests/vmx2xmldata/vmx2xml-sharedfolder.xml |   22 
 tests/vmx2xmltest.c|2 +
 tests/xml2vmxdata/xml2vmx-sharedfolder.vmx |   18 +++
 tests/xml2vmxdata/xml2vmx-sharedfolder.xml |   14 ++
 tests/xml2vmxtest.c|2 +
 8 files changed, 263 insertions(+), 2 deletions(-)
 create mode 100644 tests/vmx2xmldata/vmx2xml-sharedfolder.vmx
 create mode 100644 tests/vmx2xmldata/vmx2xml-sharedfolder.xml
 create mode 100644 tests/xml2vmxdata/xml2vmx-sharedfolder.vmx
 create mode 100644 tests/xml2vmxdata/xml2vmx-sharedfolder.xml

-- 
1.7.10.4

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


Re: [libvirt] [PATCH] fix failure when building with --disable-debug

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 05:54:51PM +0800, Hu Tao wrote:
> On Wed, Jul 11, 2012 at 10:45:17AM +0100, Daniel P. Berrange wrote:
> > On Wed, Jul 11, 2012 at 05:05:24PM +0800, Hu Tao wrote:
> > > When building with --disable-debug, VIR_DEBUG expands to a nop.
> > > But parameters to VIR_DEBUG can be variables that are passed only
> > > to VIR_DEBUG. In the case the building system complains about unused
> > > variables.
> > > ---
> > >  src/libvirt_private.syms |1 +
> > >  src/util/logging.c   |   15 +++
> > >  src/util/logging.h   |3 ++-
> > >  3 files changed, 18 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> > > index b173590..48c4df7 100644
> > > --- a/src/libvirt_private.syms
> > > +++ b/src/libvirt_private.syms
> > > @@ -739,6 +739,7 @@ virLockManagerRelease;
> > >  
> > >  
> > >  # logging.h
> > > +virEatParam;
> > >  virLogDefineFilter;
> > >  virLogDefineOutput;
> > >  virLogEmergencyDumpAll;
> > > diff --git a/src/util/logging.c b/src/util/logging.c
> > > index f8233cd..999dd01 100644
> > > --- a/src/util/logging.c
> > > +++ b/src/util/logging.c
> > > @@ -1262,3 +1262,18 @@ void virLogSetFromEnv(void) {
> > >  if (debugEnv && *debugEnv)
> > >  virLogParseOutputs(debugEnv);
> > >  }
> > > +
> > > +/**
> > > + * virEatParam:
> > > + *
> > > + * Do nothing but eat parameters. See VIR_DEBUG_INT.
> > > + *
> > > + * Currently only VIR_DEBUG_INT uses this function, which could
> > > + * have been defined right before VIR_DEBUG_INT, but it makes
> > > + * `make syntax-check' unhappy about ATTRIBUTE_UNUSED appearing
> > > + * in .h file.
> > > + */
> > > +void virEatParam(void *unused ATTRIBUTE_UNUSED, ...)
> > > +{
> > > +/* do nothing */
> > > +}
> > 
> > Could you in fact put this in logging.h and mark it 'inline' so
> > the compiler does away with it entirely, but still thinks the
> > params are used ?
> 
> but `make syntax-check' will fail.

Opps, yes, sorry I didn't read your comment. I suggest just whitelisting
the logging.h file in cfg.mk so that we don't apply that check to
this file


Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [PATCH] fix failure when building with --disable-debug

2012-07-11 Thread Hu Tao
On Wed, Jul 11, 2012 at 10:45:17AM +0100, Daniel P. Berrange wrote:
> On Wed, Jul 11, 2012 at 05:05:24PM +0800, Hu Tao wrote:
> > When building with --disable-debug, VIR_DEBUG expands to a nop.
> > But parameters to VIR_DEBUG can be variables that are passed only
> > to VIR_DEBUG. In the case the building system complains about unused
> > variables.
> > ---
> >  src/libvirt_private.syms |1 +
> >  src/util/logging.c   |   15 +++
> >  src/util/logging.h   |3 ++-
> >  3 files changed, 18 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> > index b173590..48c4df7 100644
> > --- a/src/libvirt_private.syms
> > +++ b/src/libvirt_private.syms
> > @@ -739,6 +739,7 @@ virLockManagerRelease;
> >  
> >  
> >  # logging.h
> > +virEatParam;
> >  virLogDefineFilter;
> >  virLogDefineOutput;
> >  virLogEmergencyDumpAll;
> > diff --git a/src/util/logging.c b/src/util/logging.c
> > index f8233cd..999dd01 100644
> > --- a/src/util/logging.c
> > +++ b/src/util/logging.c
> > @@ -1262,3 +1262,18 @@ void virLogSetFromEnv(void) {
> >  if (debugEnv && *debugEnv)
> >  virLogParseOutputs(debugEnv);
> >  }
> > +
> > +/**
> > + * virEatParam:
> > + *
> > + * Do nothing but eat parameters. See VIR_DEBUG_INT.
> > + *
> > + * Currently only VIR_DEBUG_INT uses this function, which could
> > + * have been defined right before VIR_DEBUG_INT, but it makes
> > + * `make syntax-check' unhappy about ATTRIBUTE_UNUSED appearing
> > + * in .h file.
> > + */
> > +void virEatParam(void *unused ATTRIBUTE_UNUSED, ...)
> > +{
> > +/* do nothing */
> > +}
> 
> Could you in fact put this in logging.h and mark it 'inline' so
> the compiler does away with it entirely, but still thinks the
> params are used ?

but `make syntax-check' will fail.

-- 
Thanks,
Hu Tao

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


[libvirt] [PATCHv4 2/4] nodeinfo: Fix gathering of nodeinfo data structure

2012-07-11 Thread Peter Krempa
This patch changes the way data to fill the nodeinfo structure are
gathered. We've gathere the test data by iterating processors an sockets
separately from nodes. The reported data was based solely on information
about core id. Problems arise when eg cores in mulit-processor machines
don't have same id's on both processors or maybe one physical processor
contains more NUMA nodes.

This patch changes the approach how we detect processors and nodes. Now
we start at enumerating nodes and for each node processors, sockets and
threads are enumerated separately. This approach provides acurate data
that comply to docs about the nodeinfo structure. This also enables to
get rid of hacks: see commits 10d9038b744a69c8d4bd29c2e8c012a097481586,
ac9dd4a676f21b5e3ca6dbe0526f2a6709072beb. (Those changes in nodeinfo.c
are efectively reverted by this patch).

This patch also changes output of one of the tests, as the processor
topology is now acquired more precisely.
---
Changes to v3:
- added ATTRIBUTE_NONNULL to arguments of virNodeParseNode()
- added resetting of errno before calling readdir()
- indented comment properly
- edited comment placed before parsing info from /proc/cpuinfo to reflect 
current state better
---
 src/nodeinfo.c |  326 
 .../linux-nodeinfo-sysfs-test-3-cpu-x86-output.txt |2 +-
 2 files changed, 197 insertions(+), 131 deletions(-)

diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 819f954..a892e7a 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -188,38 +188,139 @@ virNodeParseSocket(const char *dir, unsigned int cpu)
 return ret;
 }

+/* parses a node entry, returning number of processors in the node and
+ * filling arguments */
 static int
-virNodeParseNode(const char *sysfs_dir)
+virNodeParseNode(const char *node, int *sockets, int *cores, int *threads)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
+ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4)
 {
-char *file = NULL;
-char *possible = NULL;
-char *tmp;
 int ret = -1;
+int processors = 0;
+DIR *cpudir = NULL;
+struct dirent *cpudirent = NULL;
+int sock_max = 0;
+cpu_set_t sock_map;
+int sock;
+cpu_set_t *core_maps = NULL;
+int core;
+int i;
+int siblings;
+unsigned int cpu;
+int online;

-if (virAsprintf(&file, "%s/node/possible", sysfs_dir) < 0) {
-virReportOOMError();
+*threads = 0;
+*cores = 0;
+*sockets = 0;
+
+if (!(cpudir = opendir(node))) {
+virReportSystemError(errno, _("cannot opendir %s"), node);
 goto cleanup;
 }
-/* Assume that a missing node/possible file implies no NUMA
- * support, and hence all cpus belong to the same node.  */
-if (!virFileExists(file)) {
-ret = 1;
+
+/* enumerate sockets in the node */
+CPU_ZERO(&sock_map);
+errno = 0;
+while ((cpudirent = readdir(cpudir))) {
+if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
+continue;
+
+/* Parse socket */
+sock = virNodeParseSocket(node, cpu);
+CPU_SET(sock, &sock_map);
+
+if (sock > sock_max)
+sock_max = sock;
+
+errno = 0;
+}
+
+if (errno) {
+virReportSystemError(errno, _("problem reading %s"), node);
 goto cleanup;
 }
-if (virFileReadAll(file, 1024, &possible) < 0)
+
+sock_max++;
+
+/* allocate cpu maps for each socket */
+if (VIR_ALLOC_N(core_maps, sock_max) < 0) {
+virReportOOMError();
 goto cleanup;
-if (virStrToLong_i(possible, &tmp, 10, &ret) < 0 ||
-(*tmp == '-' && virStrToLong_i(tmp+1, &tmp, 10, &ret) < 0) ||
-*tmp != '\n') {
-nodeReportError(VIR_ERR_INTERNAL_ERROR,
-_("failed to parse possible nodes '%s'"), possible);
+}
+
+for (i = 0; i < sock_max; i++)
+CPU_ZERO(&core_maps[i]);
+
+/* iterate over all CPU's in the node */
+rewinddir(cpudir);
+errno = 0;
+while ((cpudirent = readdir(cpudir))) {
+if (sscanf(cpudirent->d_name, "cpu%u", &cpu) != 1)
+continue;
+
+if ((online = virNodeGetCpuValue(node, cpu, "online", true)) < 0)
+goto cleanup;
+
+if (!online)
+continue;
+
+processors++;
+
+/* Parse socket */
+sock = virNodeParseSocket(node, cpu);
+if (!CPU_ISSET(sock, &sock_map)) {
+nodeReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+_("CPU socket topology has changed"));
+goto cleanup;
+}
+
+/* Parse core */
+# if defined(__s390__) || \
+defined(__s390x__)
+/* logical cpu is equivalent to a core on s390 */
+core = cpu;
+# else
+core = virNodeGetCpuValue(node, cpu, "topology/core_id", false);
+# endif
+
+CPU_SET(core, &core_maps[sock]);
+
+if (!(siblings = virNodeCountThreadSiblings(node, cpu)))
+goto cleanup;
+
+if (siblings > *t

Re: [libvirt] [PATCH] fix failure when building with --disable-debug

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 05:05:24PM +0800, Hu Tao wrote:
> When building with --disable-debug, VIR_DEBUG expands to a nop.
> But parameters to VIR_DEBUG can be variables that are passed only
> to VIR_DEBUG. In the case the building system complains about unused
> variables.
> ---
>  src/libvirt_private.syms |1 +
>  src/util/logging.c   |   15 +++
>  src/util/logging.h   |3 ++-
>  3 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index b173590..48c4df7 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -739,6 +739,7 @@ virLockManagerRelease;
>  
>  
>  # logging.h
> +virEatParam;
>  virLogDefineFilter;
>  virLogDefineOutput;
>  virLogEmergencyDumpAll;
> diff --git a/src/util/logging.c b/src/util/logging.c
> index f8233cd..999dd01 100644
> --- a/src/util/logging.c
> +++ b/src/util/logging.c
> @@ -1262,3 +1262,18 @@ void virLogSetFromEnv(void) {
>  if (debugEnv && *debugEnv)
>  virLogParseOutputs(debugEnv);
>  }
> +
> +/**
> + * virEatParam:
> + *
> + * Do nothing but eat parameters. See VIR_DEBUG_INT.
> + *
> + * Currently only VIR_DEBUG_INT uses this function, which could
> + * have been defined right before VIR_DEBUG_INT, but it makes
> + * `make syntax-check' unhappy about ATTRIBUTE_UNUSED appearing
> + * in .h file.
> + */
> +void virEatParam(void *unused ATTRIBUTE_UNUSED, ...)
> +{
> +/* do nothing */
> +}

Could you in fact put this in logging.h and mark it 'inline' so
the compiler does away with it entirely, but still thinks the
params are used ?


> diff --git a/src/util/logging.h b/src/util/logging.h
> index 70318d0..b96a115 100644
> --- a/src/util/logging.h
> +++ b/src/util/logging.h
> @@ -35,7 +35,7 @@
>  virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__)
>  # else
>  #  define VIR_DEBUG_INT(category, f, l, ...)\
> -do { } while (0)
> +virEatParam((void*)category, f, l, __VA_ARGS__)
>  # endif /* !ENABLE_DEBUG */
>  
>  # define VIR_INFO_INT(category, f, l, ...)  \
> @@ -142,4 +142,5 @@ extern void virLogVMessage(const char *category, int 
> priority,
> va_list vargs) ATTRIBUTE_FMT_PRINTF(6, 0);
>  extern int virLogSetBufferSize(int size);
>  extern void virLogEmergencyDumpAll(int signum);
> +void virEatParam(void *unused, ...);

Oh and rename it to:

  s/virEatParam/virLogEatParam/


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


[libvirt] [PATCH] fix failure when building with --disable-debug

2012-07-11 Thread Hu Tao
When building with --disable-debug, VIR_DEBUG expands to a nop.
But parameters to VIR_DEBUG can be variables that are passed only
to VIR_DEBUG. In the case the building system complains about unused
variables.
---
 src/libvirt_private.syms |1 +
 src/util/logging.c   |   15 +++
 src/util/logging.h   |3 ++-
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b173590..48c4df7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -739,6 +739,7 @@ virLockManagerRelease;
 
 
 # logging.h
+virEatParam;
 virLogDefineFilter;
 virLogDefineOutput;
 virLogEmergencyDumpAll;
diff --git a/src/util/logging.c b/src/util/logging.c
index f8233cd..999dd01 100644
--- a/src/util/logging.c
+++ b/src/util/logging.c
@@ -1262,3 +1262,18 @@ void virLogSetFromEnv(void) {
 if (debugEnv && *debugEnv)
 virLogParseOutputs(debugEnv);
 }
+
+/**
+ * virEatParam:
+ *
+ * Do nothing but eat parameters. See VIR_DEBUG_INT.
+ *
+ * Currently only VIR_DEBUG_INT uses this function, which could
+ * have been defined right before VIR_DEBUG_INT, but it makes
+ * `make syntax-check' unhappy about ATTRIBUTE_UNUSED appearing
+ * in .h file.
+ */
+void virEatParam(void *unused ATTRIBUTE_UNUSED, ...)
+{
+/* do nothing */
+}
diff --git a/src/util/logging.h b/src/util/logging.h
index 70318d0..b96a115 100644
--- a/src/util/logging.h
+++ b/src/util/logging.h
@@ -35,7 +35,7 @@
 virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__)
 # else
 #  define VIR_DEBUG_INT(category, f, l, ...)\
-do { } while (0)
+virEatParam((void*)category, f, l, __VA_ARGS__)
 # endif /* !ENABLE_DEBUG */
 
 # define VIR_INFO_INT(category, f, l, ...)  \
@@ -142,4 +142,5 @@ extern void virLogVMessage(const char *category, int 
priority,
va_list vargs) ATTRIBUTE_FMT_PRINTF(6, 0);
 extern int virLogSetBufferSize(int size);
 extern void virLogEmergencyDumpAll(int signum);
+void virEatParam(void *unused, ...);
 #endif
-- 
1.7.10.2

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


Re: [libvirt] [RFC] [PATCH 2/5] add fuse support for libvirt lxc

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 03:58:20PM +0800, Gao feng wrote:
> this patch addes fuse support for libvirt lxc.
> we can use fuse filesystem to generate sysinfo dynamically,
> So we can isolate /proc/meminfo,cpuinfo and so on through
> fuse filesystem.
> 
> we mount fuse filesystem for every container.the mount name
> is Lxc-lxcname-fuse.
> 
> Signed-off-by: Gao feng 
> ---
>  src/Makefile.am  |9 ++-
>  src/lxc/lxc_controller.c |   15 +
>  src/lxc/lxc_driver.c |2 +
>  src/lxc/lxc_fuse.c   |  155 
> ++
>  src/lxc/lxc_fuse.h   |   38 +++
>  5 files changed, 217 insertions(+), 2 deletions(-)
>  create mode 100644 src/lxc/lxc_fuse.c
>  create mode 100644 src/lxc/lxc_fuse.h
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 6c3eaa7..b01b2df 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -349,11 +349,13 @@ endif
>  
>  LXC_DRIVER_SOURCES = \
>   lxc/lxc_conf.c lxc/lxc_conf.h   \
> + lxc/lxc_fuse.c lxc/lxc_fuse.h   \
>   lxc/lxc_container.c lxc/lxc_container.h \
>   lxc/lxc_driver.c lxc/lxc_driver.h
>  
>  LXC_CONTROLLER_SOURCES = \
>   lxc/lxc_conf.c lxc/lxc_conf.h   \
> + lxc/lxc_fuse.c lxc/lxc_fuse.h   \
>   lxc/lxc_container.c lxc/lxc_container.h \
>   lxc/lxc_controller.c
>  
> @@ -819,8 +821,9 @@ endif
>  
>  libvirt_driver_lxc_impl_la_CFLAGS = \
>   $(LIBNL_CFLAGS) \
> + $(FUSE_CFLAGS) \
>   -I$(top_srcdir)/src/conf $(AM_CFLAGS)
> -libvirt_driver_lxc_impl_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS)
> +libvirt_driver_lxc_impl_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) $(FUSE_LIBS)
>  if HAVE_LIBBLKID
>  libvirt_driver_lxc_impl_la_CFLAGS += $(BLKID_CFLAGS)
>  libvirt_driver_lxc_impl_la_LIBADD += $(BLKID_LIBS)
> @@ -1523,6 +1526,7 @@ libvirt_lxc_SOURCES =   
> \
>  libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS)
>  libvirt_lxc_LDADD =  \
>   $(NUMACTL_LIBS) \
> + $(FUSE_LIBS) \
>   libvirt-net-rpc-server.la \
>   libvirt-net-rpc.la \
>   libvirt_driver_security.la \
> @@ -1540,7 +1544,8 @@ libvirt_lxc_LDADD += $(APPARMOR_LIBS)
>  endif
>  libvirt_lxc_CFLAGS = \
>   -I$(top_srcdir)/src/conf\
> - $(AM_CFLAGS)
> + $(AM_CFLAGS)\
> + $(FUSE_CFLAGS)
>  if HAVE_LIBBLKID
>  libvirt_lxc_CFLAGS += $(BLKID_CFLAGS)
>  libvirt_lxc_LDADD += $(BLKID_LIBS)
> diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
> index a4874ea..44ba07c 100644
> --- a/src/lxc/lxc_controller.c
> +++ b/src/lxc/lxc_controller.c
> @@ -58,6 +58,7 @@
>  
>  #include "lxc_conf.h"
>  #include "lxc_container.h"
> +#include "lxc_fuse.h"
>  #include "virnetdev.h"
>  #include "virnetdevveth.h"
>  #include "memory.h"
> @@ -1741,6 +1742,20 @@ int main(int argc, char *argv[])
>  }
>  }
>  
> +if ((pid = fork()) < 0)
> +goto cleanup;
> +
> +if (pid == 0) {
> +if ((pid = fork()) < 0)
> +_exit(-1);
> +
> +if (pid > 0)
> +   _exit(0);
> +
> +lxcRegisterFuse(ctrl->def);
> +_exit(0);
> +}


This is double forking to daemonize, but you never execve()
anywhere. Thus according to POSIX you are mandated to only
use async signal safe functions. This is clearly impossible
given the functionality you need to use with FUSE.

So either you need to make this a separate binary that can
be exec()'d, or instead of fork()ing, run this in a thread
of the libvirt_lxc process.  I think you can probably make
do with just using a thread.

> +#if HAVE_FUSE
> +
> +static int lxcProcGetattr(const char *path, struct stat *stbuf)
> +{
> +int res = 0;
> +
> +memset(stbuf, 0, sizeof(struct stat));
> +if (strcmp(path, "/") == 0) {

strcmp() == 0, is not allowed - use STREQ instead - if you
run 'make syntax-check' it should warn you about this.

> +stbuf->st_mode = S_IFDIR | 0755;
> +stbuf->st_nlink = 2;
> +} else
> +res = -ENOENT;

You need {} around the else clause, if you use {}
around the if clause (see HACKING)

> +
> +return res;
> +}
> +
> +static int lxcProcReaddir(const char *path, void *buf,
> +  fuse_fill_dir_t filler,
> +  off_t offset ATTRIBUTE_UNUSED,
> +  struct fuse_file_info *fi ATTRIBUTE_UNUSED)
> +{
> +if (strcmp(path, "/") != 0)
> +return -ENOENT;
> +
> +filler(buf, ".", NULL, 0);
> +filler(buf, "..", NULL, 0);
> +
> +return 0;
> +}
> +
> +static int lxcProcOpen(const char *path ATTRIBUTE_UNUSED,
> +   struct fuse_file_info *fi ATT

Re: [libvirt] [RFC] [PATCH 1/5] add configure option --with-fuse for libvirt

2012-07-11 Thread Daniel P. Berrange
On Wed, Jul 11, 2012 at 03:58:19PM +0800, Gao feng wrote:
> add a configure option --with-fuse to prepare introduction
> of fuse support for libvirt lxc.
> 
> Signed-off-by: Gao feng 
> ---
>  configure.ac|   45 +
>  libvirt.spec.in |9 +
>  2 files changed, 54 insertions(+), 0 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index d45f4f1..d5cf45f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -1694,7 +1694,47 @@ AM_CONDITIONAL([HAVE_CAPNG], [test "$with_capng" != 
> "no"])
>  AC_SUBST([CAPNG_CFLAGS])
>  AC_SUBST([CAPNG_LIBS])
>  
> +dnl libfuse
> +AC_ARG_WITH([fuse],
> +AC_HELP_STRING([--with-fuse], [use libfuse to proivde fuse filesystem 
> support for libvirt lxc]),
> +[],
> +[with_fuse=check])
>  
> +dnl
> +dnl This check looks for 'fuse'
> +dnl
> +FUSE_CFLAGS=
> +FUSE_LIBS=
> +if test "$with_fuse" != "no"; then
> +old_cflags="$CFLAGS"
> +old_libs="$LIBS"
> +old_cppflags="$CPPFLAGS"
> +CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
> +if test "$with_fuse" = "check"; then
> +AC_CHECK_HEADER([fuse.h], [], [with_fuse=no])
> +AC_CHECK_LIB([fuse], [fuse_main], [], [with_fuse=no])
> +if test "$with_fuse" != "no"; then
> +with_fuse="yes"
> +fi
> +else
> +fail=0
> +AC_CHECK_HEADER([fuse.h], [], [fail=1])
> +AC_CHECK_LIB([fuse], [fuse_main], [], [fail=1])
> +test $fail = 1 &&
> + AC_MSG_ERROR([You must install the fuse >= 2.9.0 development 
> package in order to compile and run libvirt])
> +fi
> +CFLAGS="$old_cflags"
> +LIBS="$old_libs"
> +CPPFLAGS="$old_cppflags"
> +fi
> +if test "$with_fuse" = "yes"; then
> +FUSE_LIBS="-lfuse"
> +FUSE_CFLAGS="-D_FILE_OFFSET_BITS=64"
> +AC_DEFINE_UNQUOTED([HAVE_FUSE], 1, [Whether fuse is available for 
> privilege reduction])
> +fi
> +AM_CONDITIONAL([HAVE_FUSE], [test "$with_fuse" != "no"])
> +AC_SUBST([FUSE_CFLAGS])
> +AC_SUBST([FUSE_LIBS])

FUSE includes a pkg-config file, so you can remove almost all of this
code here and just use PKG_CONFIG_CHECK



Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

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


Re: [libvirt] [PATCH] virsh: remove extra space between function name and opening brace

2012-07-11 Thread Peter Krempa

On 07/11/12 10:39, Guido Günther wrote:

to match our CodingStyle.
---
This avoids c'n'p problems as seen in my recent domhostname patch.
Cheers,
  -- Guido

  tools/virsh.c |  186 -
  1 file changed, 93 insertions(+), 93 deletions(-)



I couldn't apply this patch to current head, but it looks OK to me and 
it's a nice cleanup.


Peter

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


Re: [libvirt] [PATCHv3 4/5] S390: Domain Schema for s390-virtio machines.

2012-07-11 Thread Viktor Mihajlovski

On 07/10/2012 05:50 PM, Michal Privoznik wrote:

On 09.07.2012 14:33, Viktor Mihajlovski wrote:

On 07/03/2012 06:18 PM, Michal Privoznik wrote:

On 29.06.2012 17:02, Viktor Mihajlovski wrote:

Added s390-virtio machine type to the XML schema for domains in order
to not fail the domain schema tests.

Signed-off-by: Viktor Mihajlovski
---
   docs/schemas/domaincommon.rng |   20 
   1 files changed, 20 insertions(+), 0 deletions(-)

diff --git a/docs/schemas/domaincommon.rng
b/docs/schemas/domaincommon.rng
index 912a1a2..70c7d16 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -283,6 +283,7 @@
 
 
 
+
   
 
 hvm
@@ -369,6 +370,25 @@
 
   
 
+
+
+
+
+
+s390
+s390x
+
+
+
+
+
+
+s390-virtio


[1]^^


+
+
+
+
+
 
   
 



Sorry cannot ACK this one until you update the documentation as well.

Michal



Hi Michal,

actually I was pondering about a doc update when preparing the patches.
I only wasn't clear where to put it. The only place where possible
arch/machine values are mentioned seems to be in formatcaps.html.in.
Would you expect me to add a sample output of the capabilities XML for
s390 with some comments in there, or did you have something else in mind?

Thanks.



Actually, now I am going through docs I don't see a proper place
neither. Moreover, in formatdomain.html.in we state: "The Capabilities
XML provides details on allowed values for these" [these = @machine and
@type] So as long as we report them in capabilities XML I guess we don't
really need an doc extension.

However, I think this [1] should be virtio-s390 instead of s390-virtio
since we use the former among the code.

What do you think?

Michal



the naming is awkward and I stumble over it from time to time too. 
Unfortunately this is the terminology qemu uses.


In a nutshell:
s390-virtio = machine type, meaning s390 machine with virtio bus
virtio-s390 = bus type, meaning s390-specific virtio bus

The current virtio bus on s390 is a fully virtual bus not related to a 
real hardware bus like the PCI bus on the other architectures. So, while 
the names looks strange, they are technically correct.


--

Mit freundlichen Grüßen/Kind Regards
   Viktor Mihajlovski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294

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


Re: [libvirt] [PATCHv2] openvz: Handle domain obj hash map errors

2012-07-11 Thread Guido Günther
On Tue, Jul 10, 2012 at 05:31:27PM -0600, Eric Blake wrote:
> On 07/10/2012 12:54 PM, Guido Günther wrote:
> > This makes the driver fail with a clear error message in case of UUID
> > collisions (for example if somebody copied a container configuration
> > without updating the UUID) and also raises an error on other hash map
> > failures.
> > 
> > OpenVZ itself doesn't complain about duplicate UUIDs since this
> > parameter is only used by libvirt.
> > ---
> > This version adds an extra check for hash collisions and keeps the
> > generic failure message for all other errors in virHashAddEntry.
> > Cheers,
> >  -- Guido
> 
> ACK.

Pushed. Thanks,
 -- Guido

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




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

[libvirt] [PATCH] virsh: remove extra space between function name and opening brace

2012-07-11 Thread Guido Günther
to match our CodingStyle.
---
This avoids c'n'p problems as seen in my recent domhostname patch.
Cheers,
 -- Guido

 tools/virsh.c |  186 -
 1 file changed, 93 insertions(+), 93 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index 2c0446c..2c2f9f1 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1405,7 +1405,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd 
ATTRIBUTE_UNUSED)
 
 VIR_FREE(title);
 } else if (optHostname) {
-if (!(hostname = virDomainGetHostname (dom, 0)))
+if (!(hostname = virDomainGetHostname(dom, 0)))
 goto cleanup;
 
 vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf,
@@ -1742,7 +1742,7 @@ static const struct _domblkstat_sequence 
domblkstat_output[] = {
  VALUE);
 
 static bool
-cmdDomblkstat (vshControl *ctl, const vshCmd *cmd)
+cmdDomblkstat(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainPtr dom;
 const char *name = NULL, *device = NULL;
@@ -1800,7 +1800,7 @@ cmdDomblkstat (vshControl *ctl, const vshCmd *cmd)
 } else {
 params = vshCalloc(ctl, nparams, sizeof(*params));
 
-if (virDomainBlockStatsFlags (dom, device, params, &nparams, 0) < 0) {
+if (virDomainBlockStatsFlags(dom, device, params, &nparams, 0) < 0) {
 vshError(ctl, _("Failed to get block stats %s %s"), name, device);
 goto cleanup;
 }
@@ -1875,52 +1875,52 @@ static const vshCmdOptDef opts_domifstat[] = {
 };
 
 static bool
-cmdDomIfstat (vshControl *ctl, const vshCmd *cmd)
+cmdDomIfstat(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainPtr dom;
 const char *name = NULL, *device = NULL;
 struct _virDomainInterfaceStats stats;
 
-if (!vshConnectionUsability (ctl, ctl->conn))
+if (!vshConnectionUsability(ctl, ctl->conn))
 return false;
 
-if (!(dom = vshCommandOptDomain (ctl, cmd, &name)))
+if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
 return false;
 
-if (vshCommandOptString (cmd, "interface", &device) <= 0) {
+if (vshCommandOptString(cmd, "interface", &device) <= 0) {
 virDomainFree(dom);
 return false;
 }
 
-if (virDomainInterfaceStats (dom, device, &stats, sizeof(stats)) == -1) {
+if (virDomainInterfaceStats(dom, device, &stats, sizeof(stats)) == -1) {
 vshError(ctl, _("Failed to get interface stats %s %s"), name, device);
 virDomainFree(dom);
 return false;
 }
 
 if (stats.rx_bytes >= 0)
-vshPrint (ctl, "%s rx_bytes %lld\n", device, stats.rx_bytes);
+vshPrint(ctl, "%s rx_bytes %lld\n", device, stats.rx_bytes);
 
 if (stats.rx_packets >= 0)
-vshPrint (ctl, "%s rx_packets %lld\n", device, stats.rx_packets);
+vshPrint(ctl, "%s rx_packets %lld\n", device, stats.rx_packets);
 
 if (stats.rx_errs >= 0)
-vshPrint (ctl, "%s rx_errs %lld\n", device, stats.rx_errs);
+vshPrint(ctl, "%s rx_errs %lld\n", device, stats.rx_errs);
 
 if (stats.rx_drop >= 0)
-vshPrint (ctl, "%s rx_drop %lld\n", device, stats.rx_drop);
+vshPrint(ctl, "%s rx_drop %lld\n", device, stats.rx_drop);
 
 if (stats.tx_bytes >= 0)
-vshPrint (ctl, "%s tx_bytes %lld\n", device, stats.tx_bytes);
+vshPrint(ctl, "%s tx_bytes %lld\n", device, stats.tx_bytes);
 
 if (stats.tx_packets >= 0)
-vshPrint (ctl, "%s tx_packets %lld\n", device, stats.tx_packets);
+vshPrint(ctl, "%s tx_packets %lld\n", device, stats.tx_packets);
 
 if (stats.tx_errs >= 0)
-vshPrint (ctl, "%s tx_errs %lld\n", device, stats.tx_errs);
+vshPrint(ctl, "%s tx_errs %lld\n", device, stats.tx_errs);
 
 if (stats.tx_drop >= 0)
-vshPrint (ctl, "%s tx_drop %lld\n", device, stats.tx_drop);
+vshPrint(ctl, "%s tx_drop %lld\n", device, stats.tx_drop);
 
 virDomainFree(dom);
 return true;
@@ -1944,7 +1944,7 @@ static const vshCmdOptDef opts_domif_setlink[] = {
 };
 
 static bool
-cmdDomIfSetLink (vshControl *ctl, const vshCmd *cmd)
+cmdDomIfSetLink(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainPtr dom;
 const char *iface;
@@ -2120,7 +2120,7 @@ static const vshCmdOptDef opts_domif_getlink[] = {
 };
 
 static bool
-cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
+cmdDomIfGetLink(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainPtr dom;
 const char *iface = NULL;
@@ -2138,13 +2138,13 @@ cmdDomIfGetLink (vshControl *ctl, const vshCmd *cmd)
 xmlNodePtr cur = NULL;
 xmlXPathObjectPtr obj = NULL;
 
-if (!vshConnectionUsability (ctl, ctl->conn))
+if (!vshConnectionUsability(ctl, ctl->conn))
 return false;
 
-if (!(dom = vshCommandOptDomain (ctl, cmd, NULL)))
+if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
 return false;
 
-if (vshCommandOptString (cmd, "interface", &iface) <= 0) {
+if (vshCommandOptString(cmd, "interface", &ifac

[libvirt] [RFC] [PATCH 4/5] make /proc/meminfo isolate with host through fuse

2012-07-11 Thread Gao feng
with this patch,container's meminfo will be shown based on
containers' mem cgroup.

Right now,it's impossible to virtualize all values in meminfo,
I collect some values such as MemTotal,MemFree,Cached,Active,
Inactive,Active(anon),Inactive(anon),Active(file),Inactive(anon),
Active(file),Inactive(file),Unevictable,SwapTotal,SwapFree.

if I miss something, please let me know.

Signed-off-by: Gao feng 
---
 src/lxc/lxc_fuse.c |  340 ++--
 1 files changed, 332 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c
index 5fdacab..69b4f2e 100644
--- a/src/lxc/lxc_fuse.c
+++ b/src/lxc/lxc_fuse.c
@@ -32,22 +32,52 @@
 #include "lxc_fuse.h"
 #include "util.h"
 #include "memory.h"
+#include "virfile.h"
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
 #if HAVE_FUSE
+enum {
+MEMTOTAL,
+MEMUSAGE,
+CACHED,
+ACTIVE_ANON,
+INACTIVE_ANON,
+ACTIVE_FILE,
+INACTIVE_FILE,
+UNEVICTABLE,
+SWAPTOTAL,
+SWAPUSAGE,
+MEMMAX,
+};
+
+static const char *meminfo_path = "/meminfo";
 
 static int lxcProcGetattr(const char *path, struct stat *stbuf)
 {
 int res = 0;
+char *mempath = NULL;
+struct stat sb;
+virAsprintf(&mempath, "/proc/%s",path);
 
 memset(stbuf, 0, sizeof(struct stat));
 if (strcmp(path, "/") == 0) {
 stbuf->st_mode = S_IFDIR | 0755;
 stbuf->st_nlink = 2;
+} else if (strcmp(path, meminfo_path) == 0) {
+stat(mempath, &sb);
+stbuf->st_mode = S_IFREG | 0444;
+stbuf->st_nlink = 1;
+stbuf->st_blksize = sb.st_blksize;
+stbuf->st_blocks = sb.st_blocks;
+stbuf->st_size = sb.st_size;
+stbuf->st_atime = sb.st_atime;
+stbuf->st_ctime = sb.st_ctime;
+stbuf->st_mtime = sb.st_mtime;
 } else
 res = -ENOENT;
 
+VIR_FREE(mempath);
 return res;
 }
 
@@ -61,23 +91,317 @@ static int lxcProcReaddir(const char *path, void *buf,
 
 filler(buf, ".", NULL, 0);
 filler(buf, "..", NULL, 0);
+filler(buf, meminfo_path + 1, NULL, 0);
 
 return 0;
 }
 
-static int lxcProcOpen(const char *path ATTRIBUTE_UNUSED,
-   struct fuse_file_info *fi ATTRIBUTE_UNUSED)
+static int lxcProcOpen(const char *path,
+   struct fuse_file_info *fi)
+{
+if (strcmp(path, meminfo_path) != 0)
+return -ENOENT;
+
+if ((fi->flags & 3) != O_RDONLY)
+return -EACCES;
+
+return 0;
+}
+
+static int lxcGetMemCgroupSwapUsage(virCgroupPtr cgroup, unsigned long long 
*usage)
+{
+return virCgroupGetMemSwapUsage(cgroup, usage);
+}
+
+static int lxcGetMemCgroupSwapTotal(virCgroupPtr cgroup, unsigned long long 
*total)
+{
+return virCgroupGetMemSwapHardLimit(cgroup, total);
+}
+
+static int lxcGetMemCgroupMemUsage(virCgroupPtr cgroup, unsigned long long 
*usage)
+{
+int ret;
+unsigned long memUsage;
+
+ret = virCgroupGetMemoryUsage(cgroup, &memUsage);
+*usage = (unsigned long long) memUsage;
+
+return ret;
+}
+
+static int lxcGetMemCgroupMemTotal(virCgroupPtr cgroup, unsigned long long 
*total)
 {
-return -ENOENT;
+return virCgroupGetMemoryHardLimit(cgroup, total);
 }
 
-static int lxcProcRead(const char *path ATTRIBUTE_UNUSED,
-   char *buf ATTRIBUTE_UNUSED,
-   size_t size ATTRIBUTE_UNUSED,
-   off_t offset ATTRIBUTE_UNUSED,
+static int lxcGetMemCgroupStat(virCgroupPtr cgroup, unsigned long long 
*meminfo)
+{
+int ret = 0;
+FILE *statfd = NULL;
+char *statFile = NULL;
+char line[1024];
+
+ret = virCgroupPathOfController(cgroup, VIR_CGROUP_CONTROLLER_MEMORY,
+"memory.stat", &statFile);
+if (ret < 0 ) {
+virReportSystemError(-ret, "%s",
+ _("cannot get the path of MEMORY cgroup 
controller"));
+return ret;
+}
+
+statfd = fopen(statFile, "r");
+if (statfd == NULL) {
+ret = -ENOENT;
+goto out_free;
+}
+
+while (fgets(line, sizeof(line), statfd) != NULL) {
+char *value = strchr(line, ' ');
+char *nl = value ? strchr(line, '\n') : NULL;
+unsigned long long stat_value;
+
+if (!value)
+continue;
+
+if (nl)
+*nl = '\0';
+
+*value = '\0';
+if (strcmp(line, "cache") == 0) {
+if ((ret = virStrToLong_ull(value + 1, NULL, 10, &stat_value)) < 0)
+goto out;
+meminfo[CACHED] = stat_value >> 10;
+} else if (strcmp(line, "inactive_anon") == 0) {
+if ((ret = virStrToLong_ull(value + 1, NULL, 10, &stat_value)) < 0)
+goto out;
+meminfo[INACTIVE_ANON] = stat_value >> 10;
+} else if (strcmp(line, "active_anon") == 0) {
+if ((ret = virStrToLong_ull(value + 1, NULL, 10, &stat_value)) < 0)
+goto out;
+meminfo[ACTIVE_ANON] = stat_value >> 10;
+  

[libvirt] [RFC] [PATCH 2/5] add fuse support for libvirt lxc

2012-07-11 Thread Gao feng
this patch addes fuse support for libvirt lxc.
we can use fuse filesystem to generate sysinfo dynamically,
So we can isolate /proc/meminfo,cpuinfo and so on through
fuse filesystem.

we mount fuse filesystem for every container.the mount name
is Lxc-lxcname-fuse.

Signed-off-by: Gao feng 
---
 src/Makefile.am  |9 ++-
 src/lxc/lxc_controller.c |   15 +
 src/lxc/lxc_driver.c |2 +
 src/lxc/lxc_fuse.c   |  155 ++
 src/lxc/lxc_fuse.h   |   38 +++
 5 files changed, 217 insertions(+), 2 deletions(-)
 create mode 100644 src/lxc/lxc_fuse.c
 create mode 100644 src/lxc/lxc_fuse.h

diff --git a/src/Makefile.am b/src/Makefile.am
index 6c3eaa7..b01b2df 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -349,11 +349,13 @@ endif
 
 LXC_DRIVER_SOURCES =   \
lxc/lxc_conf.c lxc/lxc_conf.h   \
+   lxc/lxc_fuse.c lxc/lxc_fuse.h   \
lxc/lxc_container.c lxc/lxc_container.h \
lxc/lxc_driver.c lxc/lxc_driver.h
 
 LXC_CONTROLLER_SOURCES =   \
lxc/lxc_conf.c lxc/lxc_conf.h   \
+   lxc/lxc_fuse.c lxc/lxc_fuse.h   \
lxc/lxc_container.c lxc/lxc_container.h \
lxc/lxc_controller.c
 
@@ -819,8 +821,9 @@ endif
 
 libvirt_driver_lxc_impl_la_CFLAGS = \
$(LIBNL_CFLAGS) \
+   $(FUSE_CFLAGS) \
-I$(top_srcdir)/src/conf $(AM_CFLAGS)
-libvirt_driver_lxc_impl_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS)
+libvirt_driver_lxc_impl_la_LIBADD = $(CAPNG_LIBS) $(LIBNL_LIBS) $(FUSE_LIBS)
 if HAVE_LIBBLKID
 libvirt_driver_lxc_impl_la_CFLAGS += $(BLKID_CFLAGS)
 libvirt_driver_lxc_impl_la_LIBADD += $(BLKID_LIBS)
@@ -1523,6 +1526,7 @@ libvirt_lxc_SOURCES = 
\
 libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(AM_LDFLAGS)
 libvirt_lxc_LDADD =\
$(NUMACTL_LIBS) \
+   $(FUSE_LIBS) \
libvirt-net-rpc-server.la \
libvirt-net-rpc.la \
libvirt_driver_security.la \
@@ -1540,7 +1544,8 @@ libvirt_lxc_LDADD += $(APPARMOR_LIBS)
 endif
 libvirt_lxc_CFLAGS =   \
-I$(top_srcdir)/src/conf\
-   $(AM_CFLAGS)
+   $(AM_CFLAGS)\
+   $(FUSE_CFLAGS)
 if HAVE_LIBBLKID
 libvirt_lxc_CFLAGS += $(BLKID_CFLAGS)
 libvirt_lxc_LDADD += $(BLKID_LIBS)
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index a4874ea..44ba07c 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -58,6 +58,7 @@
 
 #include "lxc_conf.h"
 #include "lxc_container.h"
+#include "lxc_fuse.h"
 #include "virnetdev.h"
 #include "virnetdevveth.h"
 #include "memory.h"
@@ -1741,6 +1742,20 @@ int main(int argc, char *argv[])
 }
 }
 
+if ((pid = fork()) < 0)
+goto cleanup;
+
+if (pid == 0) {
+if ((pid = fork()) < 0)
+_exit(-1);
+
+if (pid > 0)
+   _exit(0);
+
+lxcRegisterFuse(ctrl->def);
+_exit(0);
+}
+
 rc = virLXCControllerRun(ctrl);
 
 cleanup:
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index b58aeae..3f6838f 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -41,6 +41,7 @@
 #include "lxc_conf.h"
 #include "lxc_container.h"
 #include "lxc_driver.h"
+#include "lxc_fuse.h"
 #include "memory.h"
 #include "util.h"
 #include "virnetdevbridge.h"
@@ -1485,6 +1486,7 @@ static int lxcVmTerminate(lxc_driver_t *driver,
 return -1;
 }
 
+lxcUnregisterFuse(vm->def);
 virSecurityManagerRestoreAllLabel(driver->securityManager,
   vm->def, false);
 virSecurityManagerReleaseLabel(driver->securityManager, vm->def);
diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c
new file mode 100644
index 000..5fdacab
--- /dev/null
+++ b/src/lxc/lxc_fuse.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2012 Fujitsu Limited.
+ *
+ * lxc_fuse.c: fuse filesystem support for libvirt lxc
+ *
+ * Authors:
+ *  Gao feng 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,

[libvirt] [RFC] [PATCH 5/5] Mount fuse's meminfo file to container's /proc/meminfo

2012-07-11 Thread Gao feng
we already have virtualize meminfo for container in fuse filesystem,
add function lxcContainerMountProcFuse to mount this meminfo file to
the container's /proc/meminfo.

So we isolate container's /proc/meminfo now.

Signed-off-by: Gao feng 
---
 src/lxc/lxc_container.c |   29 +
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 145accb..5e0cf06 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -520,6 +520,27 @@ cleanup:
 return rc;
 }
 
+static int lxcContainerMountProcFuse(virDomainDefPtr def,
+ const char *srcprefix)
+{
+int ret;
+char *meminfo_path = NULL;
+
+if ((ret = virAsprintf(&meminfo_path,
+   "%s/%s/%s/meminfo",
+   srcprefix, LXC_STATE_DIR,
+   def->name)) < 0)
+ return ret;
+
+if ((ret = mount(meminfo_path, "/proc/meminfo",
+ NULL, MS_BIND, NULL)) < 0) {
+ virReportSystemError(errno,
+  _("Failed to mount %s on /proc/meminfo"),
+  meminfo_path);
+}
+VIR_FREE(meminfo_path);
+return ret;
+}
 
 static int lxcContainerMountFSDevPTS(virDomainFSDefPtr root)
 {
@@ -1430,6 +1451,10 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr 
vmDef,
 if (lxcContainerMountBasicFS(vmDef, true, securityDriver) < 0)
 goto cleanup;
 
+/* Mounts /proc/meminfo etc sysinfo */
+if (lxcContainerMountProcFuse(vmDef, "/.oldroot") < 0)
+goto cleanup;
+
 /* Now we can re-mount the cgroups controllers in the
  * same configuration as before */
 if (lxcContainerMountCGroups(mounts, nmounts) < 0)
@@ -1509,6 +1534,10 @@ static int lxcContainerSetupExtraMounts(virDomainDefPtr 
vmDef,
 if (lxcContainerMountBasicFS(vmDef, false, securityDriver) < 0)
 goto cleanup;
 
+/* Mounts /proc/meminfo etc sysinfo */
+if (lxcContainerMountProcFuse(vmDef, "/.oldroot") < 0)
+goto cleanup;
+
 /* Now we can re-mount the cgroups controllers in the
  * same configuration as before */
 if (lxcContainerMountCGroups(mounts, nmounts) < 0)
-- 
1.7.7.6

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


[libvirt] [RFC] [PATCH 3/5] add interface virCgroupGetMemSwapUsage

2012-07-11 Thread Gao feng
virCgroupGetMemSwapUsage is used to get container's swap usage,
with this interface,we can get swap usage in fuse filesystem.

Signed-off-by: Gao feng 
---
 src/libvirt_private.syms |1 +
 src/util/cgroup.c|   20 
 src/util/cgroup.h|1 +
 3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6625fc6..5a1f20e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -79,6 +79,7 @@ virCgroupGetCpuacctStat;
 virCgroupGetCpuacctUsage;
 virCgroupGetCpusetMems;
 virCgroupGetFreezerState;
+virCgroupGetMemSwapUsage;
 virCgroupGetMemSwapHardLimit;
 virCgroupGetMemoryHardLimit;
 virCgroupGetMemorySoftLimit;
diff --git a/src/util/cgroup.c b/src/util/cgroup.c
index 5b32881..d6fcd61 100644
--- a/src/util/cgroup.c
+++ b/src/util/cgroup.c
@@ -1188,6 +1188,26 @@ int virCgroupSetMemSwapHardLimit(virCgroupPtr group, 
unsigned long long kb)
 }
 
 /**
+ * virCgroupGetMemSwapUsage:
+ *
+ * @group: The cgroup to get mem+swap usage for
+ * @kb: The mem+swap amount in kilobytes
+ *
+ * Returns: 0 on success
+ */
+int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb)
+{
+long long unsigned int usage_in_bytes;
+int ret;
+ret = virCgroupGetValueU64(group,
+   VIR_CGROUP_CONTROLLER_MEMORY,
+   "memory.memsw.usage_in_bytes", &usage_in_bytes);
+if (ret == 0)
+*kb = usage_in_bytes >> 10;
+return ret;
+}
+
+/**
  * virCgroupGetMemSwapHardLimit:
  *
  * @group: The cgroup to get mem+swap hard limit for
diff --git a/src/util/cgroup.h b/src/util/cgroup.h
index 05325ae..caca362 100644
--- a/src/util/cgroup.h
+++ b/src/util/cgroup.h
@@ -70,6 +70,7 @@ int virCgroupSetMemorySoftLimit(virCgroupPtr group, unsigned 
long long kb);
 int virCgroupGetMemorySoftLimit(virCgroupPtr group, unsigned long long *kb);
 int virCgroupSetMemSwapHardLimit(virCgroupPtr group, unsigned long long kb);
 int virCgroupGetMemSwapHardLimit(virCgroupPtr group, unsigned long long *kb);
+int virCgroupGetMemSwapUsage(virCgroupPtr group, unsigned long long *kb);
 
 enum {
 VIR_CGROUP_DEVICE_READ  = 1,
-- 
1.7.7.6

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


[libvirt] [RFC] [PATCH 1/5] add configure option --with-fuse for libvirt

2012-07-11 Thread Gao feng
add a configure option --with-fuse to prepare introduction
of fuse support for libvirt lxc.

Signed-off-by: Gao feng 
---
 configure.ac|   45 +
 libvirt.spec.in |9 +
 2 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index d45f4f1..d5cf45f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1694,7 +1694,47 @@ AM_CONDITIONAL([HAVE_CAPNG], [test "$with_capng" != 
"no"])
 AC_SUBST([CAPNG_CFLAGS])
 AC_SUBST([CAPNG_LIBS])
 
+dnl libfuse
+AC_ARG_WITH([fuse],
+AC_HELP_STRING([--with-fuse], [use libfuse to proivde fuse filesystem 
support for libvirt lxc]),
+[],
+[with_fuse=check])
 
+dnl
+dnl This check looks for 'fuse'
+dnl
+FUSE_CFLAGS=
+FUSE_LIBS=
+if test "$with_fuse" != "no"; then
+old_cflags="$CFLAGS"
+old_libs="$LIBS"
+old_cppflags="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
+if test "$with_fuse" = "check"; then
+AC_CHECK_HEADER([fuse.h], [], [with_fuse=no])
+AC_CHECK_LIB([fuse], [fuse_main], [], [with_fuse=no])
+if test "$with_fuse" != "no"; then
+with_fuse="yes"
+fi
+else
+fail=0
+AC_CHECK_HEADER([fuse.h], [], [fail=1])
+AC_CHECK_LIB([fuse], [fuse_main], [], [fail=1])
+test $fail = 1 &&
+ AC_MSG_ERROR([You must install the fuse >= 2.9.0 development 
package in order to compile and run libvirt])
+fi
+CFLAGS="$old_cflags"
+LIBS="$old_libs"
+CPPFLAGS="$old_cppflags"
+fi
+if test "$with_fuse" = "yes"; then
+FUSE_LIBS="-lfuse"
+FUSE_CFLAGS="-D_FILE_OFFSET_BITS=64"
+AC_DEFINE_UNQUOTED([HAVE_FUSE], 1, [Whether fuse is available for 
privilege reduction])
+fi
+AM_CONDITIONAL([HAVE_FUSE], [test "$with_fuse" != "no"])
+AC_SUBST([FUSE_CFLAGS])
+AC_SUBST([FUSE_LIBS])
 
 dnl virsh libraries
 AC_CHECK_HEADERS([readline/readline.h])
@@ -2912,6 +2952,11 @@ AC_MSG_NOTICE([   capng: $CAPNG_CFLAGS $CAPNG_LIBS])
 else
 AC_MSG_NOTICE([   capng: no])
 fi
+if test "$with_fuse" = "yes" ; then
+AC_MSG_NOTICE([fuse: $FUSE_CFLAGS $FUSE_LIBS])
+else
+AC_MSG_NOTICE([fuse: no])
+fi
 if test "$with_xen" = "yes" ; then
 AC_MSG_NOTICE([ xen: $XEN_CFLAGS $XEN_LIBS])
 else
diff --git a/libvirt.spec.in b/libvirt.spec.in
index ec2b3b4..8cb2291 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -86,6 +86,7 @@
 # A few optional bits off by default, we enable later
 %define with_polkit0%{!?_without_polkit:0}
 %define with_capng 0%{!?_without_capng:0}
+%define with_fuse  0%{!?_without_fuse:0}
 %define with_netcf 0%{!?_without_netcf:0}
 %define with_udev  0%{!?_without_udev:0}
 %define with_hal   0%{!?_without_hal:0}
@@ -450,6 +451,9 @@ BuildRequires: numactl-devel
 %if %{with_capng}
 BuildRequires: libcap-ng-devel >= 0.5.0
 %endif
+%if %{with_fuse}
+BuildRequires: fuse-devel >= 2.9.0
+%endif
 %if %{with_phyp}
 BuildRequires: libssh2-devel
 %endif
@@ -1092,6 +1096,10 @@ of recent versions of Linux (and other OSes).
 %define _without_capng --without-capng
 %endif
 
+%if ! %{with_fuse}
+%define _without_fuse --without-fuse
+%endif
+
 %if ! %{with_netcf}
 %define _without_netcf --without-netcf
 %endif
@@ -1181,6 +1189,7 @@ autoreconf -if
%{?_without_numactl} \
%{?_without_numad} \
%{?_without_capng} \
+   %{?_without_fuse} \
%{?_without_netcf} \
%{?_without_selinux} \
%{?_without_hal} \
-- 
1.7.7.6

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


Re: [libvirt] [PATCH] Fix /domain/features setting in qemuParseCommandLine

2012-07-11 Thread Christophe Fergeau
On Tue, Jul 10, 2012 at 04:04:12PM +0200, Michal Privoznik wrote:
> 
> Cool, so now we don't overwrite PAE feature set just a few lines above (not 
> visible in this diff though).
> 
> ACK with this squashed in:

I have now pushed this patch with the testcase update. Before pushing I
have tested that without my patch the test fails, and after applying it the
test succeeds.

Christophe

> 
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-kvmclock.xml 
> b/tests/qemuxml2argvdata/qemuxml2argv-kvmclock.xml
> index e07c1f6..8abcb51 100644
> --- a/tests/qemuxml2argvdata/qemuxml2argv-kvmclock.xml
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-kvmclock.xml
> @@ -8,6 +8,9 @@
>  hvm
>  
>
> +  
> +
> +  
>
>  
>
> 
> 
> Michal


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

Re: [libvirt] [PATCH] Added timestamps to storage volumes

2012-07-11 Thread Hendrik Schwartke

On 10.07.2012 17:36, Eric Blake wrote:

On 07/10/2012 09:22 AM, Hendrik Schwartke wrote:

The access, modification and change times are added to storage
volumes and corresponding xml representations.
---
  docs/formatstorage.html.in|   13 +
  docs/schemas/storagevol.rng   |   23 +++
  src/conf/storage_conf.c   |   12 
  src/conf/storage_conf.h   |9 +
  src/storage/storage_backend.c |   20 
  5 files changed, 77 insertions(+)

+timestamps
+Provides timing information about the volume. The three sub elements
+atime,mtime  andctime  hold the
+access, modification and respectively the change time of the volume. 
The

Grammar:

hold the access, modification, and change times of the volume, where known.

no need to mention 'respectively'.


+++ b/src/conf/storage_conf.c
@@ -1272,6 +1272,18 @@ virStorageVolTargetDefFormat(virStorageVolOptionsPtr 
options,

  virBufferAddLit(buf,"\n");

+virBufferAddLit(buf, "\n");
+virBufferAsprintf(buf, "%llu.%lu\n",
+  (unsigned long long) def->timestamps.atime.tv_sec,
+  def->timestamps.atime.tv_nsec);

Technically, tv_nsec is a signed long, and you should be using %ld
instead of %lu.


+++ b/src/storage/storage_backend.c
@@ -1156,6 +1156,9 @@ 
virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
 unsigned long long *capacity)
  {
  struct stat sb;
+struct timespec *const atime=&target->timestamps.atime,

Space on either side of '='.



+atime->tv_sec = sb.st_atime;
+mtime->tv_sec = sb.st_mtime;
+catime->tv_sec = sb.st_ctime;
+#if _BSD_SOURCE || _SVID_SOURCE
+atime->tv_nsec = sb.st_atim.tv_nsec;

Yuck.  I've nearly got consensus to use the gnulib stat-time module, in
which case this would instead be the much simpler:

Ok, that sounds good. But what exactly does 'nearly' mean?

#include "stat-time.h"
...

atime = get_stat_atime(sb);
mtime = get_stat_mtime(sb);
ctime = get_stat_mtime(sb);

Of course, you are absolutely right. It is much cleaner to use stat-time.

But before we can use the gnulib stat-time module, we have to update
.gnulib and bootstrap.conf; and I'm holding off on the .gnulib update
until after fixed Automake is available in at least Fedora 17 (right
now, unless you are manually using automake 1.11.6 or newer, you are
injecting a security bug into every other package that uses automake).

So any idea how long this will take?

Also, with gnulib's stat-time module, my earlier suggestion to include
birthtime would be as simple as:

btime = get_state_birthtime(sb);

along with filtering the display:

if (btime->tv_nsec == -1) {
   /* birth time not available */
}



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


Re: [libvirt] [PATCH] docs: added description of the vendor_id attribute

2012-07-11 Thread Hendrik Schwartke

On 10.07.2012 21:57, Jiri Denemark wrote:

I know I'm late in this vendor_id stuff but it hasn't been released yet so I'm
not too late. I assume the reason for introducing it is to be able to lie to a
guest. Please, correct me, if this is not the case.
Well, the reason is to specify a vendor_id which is different to the 
actual host vendor id

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 94c555f..b6e0d5d 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -779,7 +779,11 @@
  in which case an attempt to start a domain requesting an unsupported
  CPU model will fail. Supported values forfallback
  attribute are:allow  (this is the default), and
-forbid.
+forbid. The optionalvendor_id  attribute
+(Since 0.9.14)  can be used to set the
+vendor id seen by the guest. It must be exactly 12 characters long.
+If not set the vendor id of the host is used. Typical possible
+values are "AuthenticAMD" and "GenuineIntel".

vendor
Since 0.8.3  the content of the


This is wrong (unless your previous patch explicitly modified the code to
behave like this). If vendor_id is not set, a guest should see model's default
vendor. If a guest is configured with, e.g., SandyBridge model, its vendor
will be "GenuineIntel". If a guest uses Opteron_G3, it will see "AuthenticAMD"
vendor. All this regardless on the vendor of the host CPU as longs as the host
CPU is capable enough to support all features of a given guest CPU.
I have tested this (with the qemu driver) and that's not correct. I'm 
sure you have to set the vendor attribute in the qemu command line to 
set the vendor id. So "kvm -cpu core2duo -cdrom 
debian-6.0.5-i386-netinst.iso" on an amd machine results in vendor id = 
AuthenticAMD (just as with -cpu 486)

Anyway, to be honest, I'm not a big fan of the new vendor_id attribute.
Currently we have

 
   Model
   ...
 

to force "bleblablebla" vendor ID on the guest CPU and

 
   Model
   Intel
   ...
 

to make sure the guest will be run only on a host with Intel CPU.

I think it would be much better to reuse the already existing
element. We could perhaps add new force attribute for vendor element. Thus,
These are two different things. One is the vendor_id the guest should 
see and the other the vendor id the host should have to start the 
domain. So if the CPUID instruction in the guest should return 
"NOT-INTEL" and the host cpu should be an intel cpu a force bit is not 
enough. Furthermore it would be confusing to use only one attribute to 
specify the vendor of the host and the guest cpu.

 
   Model
   
 

would force "bleblablebla" vendor ID,

 
   Model
   Intel
 

would just check that host CPU is made by Intel, and

 
   Model
   Intel
 

would check that host CPU is made by Intel but the guest CPU will have
"bleblablebla" vendor ID.

I was also thinking about making use of our vendor aliases (Intel for
GenuineIntel and AMD for AuthenticAMD, and we are free to add others) but
since vendor ID forcing seems to be only useful for testing, I think it's fine
if we require full vendor ID to be used. At least I don't see another reason
why anyone would want to confuse a guest OS by giving it Opteron_G4 CPU made
by VIA.
Well, there are some special cases where migrating guest from one host 
to another with different cpu vendors is a problem. Using a windows 7 or 
8 image on different cpus could for example require a (re-)activation. 
So this feature could be quite important not only for testing.

What other think about this?

One idea is to rename vendor_id to guest_vendor_id or to fake_vendor_id.

Jirka


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