Commit Graph

284 Commits

Author SHA1 Message Date
Jiri Denemark
9f181ebc14 Wire protocol format and remote driver for virDomainGetState 2011-05-16 10:04:19 +02:00
Wen Congyang
a1b962ada9 build: probes.d and libvirtd.stp should be part of tarball
Steps to reproduce this problem:
1. # ./autogen.sh --without-libvirtd
2. # make dist
3. # rpmbuild --nodeps --define "_sourcedir `pwd`" -ba libvirt.spec
   ...
   make[2]: Entering directory `/home/wency/rpmbuild/BUILD/libvirt-0.9.1/daemon'
   make[2]: *** No rule to make target `probes.d', needed by `probes.h'.  Stop.
   make[2]: Leaving directory `/home/wency/rpmbuild/BUILD/libvirt-0.9.1/daemon'
   make[1]: *** [all-recursive] Error 1
   make[1]: Leaving directory `/home/wency/rpmbuild/BUILD/libvirt-0.9.1'
   make: *** [all] Error 2
   error: Bad exit status from /var/tmp/rpm-tmp.WkAD7a (%build)
2011-05-14 13:46:00 +08:00
Michal Privoznik
2c6efac985 screenshot: Implementing the remote protocol
* src/remote/remote_protocol.x: Wire protocol definition
* daemon/remote.c: Daemon part
* src/remote/remote_driver.c: Client part
* src/remote_protocol-structs: Add structures
2011-05-13 12:44:23 +02:00
Matthias Bolte
2a5251e2c4 remote generator: Add skipgen/autogen flags to .x files
Make procedure parsing more robust, by allowing arbitrary
amounts of whitespaces.

Also make some error messages more verbose.
2011-05-12 08:44:07 +02:00
Eric Blake
88d03d4ff1 nwfilter: drop unused flag argument
The public API and RPC over-the-wire format have no flags argument,
so neither should the internal callback API.  This simplifies the
RPC generator.

* src/driver.h (virDrvNWFilterDefineXML): Drop argument that does
not match public API.
* src/nwfilter/nwfilter_driver.c (nwfilterDefine): Likewise.
* src/libvirt.c (virNWFilterDefineXML): Likewise.
* daemon/remote_generator.pl: Drop special case.
2011-05-11 19:26:59 -06:00
Eric Blake
cb84580a25 maint: omit translation for all VIR_INFO
We were 31/73 on whether to translate; since less than 50% translated
and since VIR_INFO is less than VIR_WARN which also doesn't translate,
this makes sense.

* cfg.mk (sc_prohibit_gettext_markup): Add VIR_INFO, since it
falls between WARN and DEBUG.
* daemon/libvirtd.c (qemudDispatchSignalEvent, remoteCheckAccess)
(qemudDispatchServer): Adjust offenders.
* daemon/remote.c (remoteDispatchAuthPolkit): Likewise.
* src/network/bridge_driver.c (networkReloadIptablesRules)
(networkStartNetworkDaemon, networkShutdownNetworkDaemon)
(networkCreate, networkDefine, networkUndefine): Likewise.
* src/qemu/qemu_driver.c (qemudDomainDefine)
(qemudDomainUndefine): Likewise.
* src/storage/storage_driver.c (storagePoolCreate)
(storagePoolDefine, storagePoolUndefine, storagePoolStart)
(storagePoolDestroy, storagePoolDelete, storageVolumeCreateXML)
(storageVolumeCreateXMLFrom, storageVolumeDelete): Likewise.
* src/util/bridge.c (brProbeVnetHdr): Likewise.
* po/POTFILES.in: Drop src/util/bridge.c.
2011-05-11 15:20:33 -06:00
Christophe Fergeau
29d753c8d5 fix xdr detection and use with recent glibc
glibc 2.13.90 has obsoleted its rpc implementation in favour of
the one provided by the TI-RPC library:

> * The RPC implementation in libc is obsoleted.  Old programs keep working
>   but new programs cannot be linked with the routines in libc anymore.
>   Programs in need of RPC functionality must be linked against TI-RPC.
>   The TI-RPC implemtation is IPv6 enabled and there are other benefits.
>
>   Visible changes of this change include (obviously) the inability to
>   link
>   programs using RPC functions without referencing the TI-RPC library,
>   the
>   removal of the RPC headers from the glibc headers, and the lack of
>   symbols defined in <rpc/netdb.h> when <netdb.h> is installed.
>   Implemented by Ulrich Drepper.
(from glibc NEWS)

Thus with recent glibc, we need to try linking with -ltirpc when looking
for the XDR functions. The daemon also needs to use XDR_CFLAGS to be able
to find the XDR headers stored in /usr/include/tirpc.

When using TI-RPC, there are some warnings about redundant declarations, but
the fix probably belongs in other modules:

/usr/include/tirpc/rpc/rpcent.h:68:13: warning: redundant redeclaration of
'setrpcent' [-Wredundant-decls]
/usr/include/rpc/netdb.h:53:13: note: previous declaration of 'setrpcent'
was here

/usr/include/tirpc/rpc/rpcent.h:69:13: warning: redundant redeclaration of
'endrpcent' [-Wredundant-decls]
/usr/include/rpc/netdb.h:54:13: note: previous declaration of 'endrpcent'
was here

/usr/include/tirpc/rpc/rpc.h:84:12: warning: redundant redeclaration of
'bindresvport' [-Wredundant-decls]
/usr/include/netinet/in.h:440:12: note: previous declaration of
'bindresvport' was here
2011-05-11 14:56:57 -06:00
Lai Jiangshan
b65f37a4a1 libvirt,logging: cleanup VIR_XXX0()
These VIR_XXXX0 APIs make us confused, use the non-0-suffix APIs instead.

How do these coversions works? The magic is using the gcc extension of ##.
When __VA_ARGS__ is empty, "##" will swallow the "," in "fmt," to
avoid compile error.

example: origin				after CPP
	high_level_api("%d", a_int)	low_level_api("%d", a_int)
	high_level_api("a  string")	low_level_api("a  string")

About 400 conversions.

8 special conversions:
VIR_XXXX0("") -> VIR_XXXX("msg") (avoid empty format) 2 conversions
VIR_XXXX0(string_literal_with_%) -> VIR_XXXX(%->%%) 0 conversions
VIR_XXXX0(non_string_literal) -> VIR_XXXX("%s", non_string_literal)
  (for security) 6 conversions

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2011-05-11 12:41:14 -06:00
Eric Blake
ba13a37cff build: fix VPATH build with distributed generated files
* daemon/Makefile.am (DAEMON_GENERATED, remote_dispatch_*.h)
(qemu_dispatch_*.h): Update to live in srcdir, since they are
distributed.
Detected by Daniel P. Berrange's autobuilder.
2011-05-11 09:17:19 -06:00
Matthias Bolte
8c6df9139b remote generator: Make parsing stricter
Anchor matches at the beginning of a line.

Specialize some general matches.

Add some comments to special cases.
2011-05-10 20:51:26 +02:00
Matthias Bolte
bfb188dd44 remote generator: Unify unsigned int notation in .x files
Rename u_int and unsigned to unsigned int. This gets rid of some special
case code in the generator.
2011-05-10 20:47:24 +02:00
Matthias Bolte
e4f6e1230d remote generator: Fix comment ignoring regex 2011-05-10 20:36:13 +02:00
Matthias Bolte
9817604afc Rename internal DumpXML functions to GetXMLDesc
This matches the public API and helps to get rid of some special
case code in the remote generator.

Rename driver API functions and XDR protocol structs.

No functional change included outside of the remote generator.
2011-05-10 20:32:41 +02:00
Lai Jiangshan
b8c776eb63 inject-nmi: Implementing the remote protocol 2011-05-10 11:40:51 -06:00
Daniel P. Berrange
3496b7f500 build: Remove all generated RPC files from GIT
Stop storing the generated files for the remote protocol client
and server in source control. The generated files will still be
included in the result of 'make dist' to avoid end-users needing
to generate the files

Signed-off-by: Eric Blake <eblake@redhat.com>

Unfortunately, this means that the strings marked for translation
in generated files are not picked up by gnulib's syntax-check,
I'm working on fixing that in gnulib.

* .gitignore, cfg.mk, po/POTFILES.in: Reflect deletion.
2011-05-06 16:22:33 -06:00
Daniel P. Berrange
fb1e8d9c44 build: refactor generated RPC files
Always generate the rpc files, and require rpcgen during bootstrap.

* daemon/Makefile.am: Removed generated files with
  maintainer-clean target
* src/Makefile.am: Removed generated files with
  maintainer-clean target. Always run 'rpcgen' if
  generated files are missing
2011-05-06 16:18:31 -06:00
Eric Blake
d3c5104dda build: rename generated files to .h, for automake's sake
In preparation for removing generated files, it is necessary
to tell automake that the generated files must be distributed
but not directly compiled (since they are included into the
body of a larger .c file that is compiled).  Hence, even though
these files are code and not headers in the strict sense of
the word, it is easier to rename them to .h for automake's sake.

* daemon/remote_client_bodies.c: Rename to .h.
* daemon/qemu_client_bodies.c: Likewise.
* src/remote/remote_client_bodies.c: Likewise.
* src/remote/qemu_client_bodies.c: Likewise.
* daemon/Makefile.am (remote_dispatch_bodies.c)
(qemu_dispatch_bodies.c): Rename to .h.
(remote.c, EXTRA_DIST): Reflect rename.
* daemon/remote.c: Likewise.
* daemon/remote_generator.pl: Likewise.
* src/Makefile.am (remote/remote_driver.c): Likewise.
* src/remote/remote_driver.c: Likewise.
* po/POTFILES.in: Likewise.
* cfg.mk (exclude_file_name_regexp--sc_require_config_h)
(exclude_file_name_regexp--sc_require_config_h_first)
(exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF):
Likewise.
2011-05-06 15:11:36 -06:00
Matthias Bolte
15b64ef0ed remote generator, client: Handle arguments with limited length
This adds length checks to all affected functions.
2011-05-06 20:27:29 +02:00
Matthias Bolte
b5041a49ec remote generator, client: Handle functions that return lists 2011-05-06 20:27:27 +02:00
Matthias Bolte
58b6a5c49e remote generator, client: Handle functions with optional return values 2011-05-06 20:27:24 +02:00
Matthias Bolte
abd05a07ae remote generator, client: Handle functions with multiple return values 2011-05-06 20:27:22 +02:00
Matthias Bolte
a1c891ec1e remote generator, client: Handle functions with wrapped return values 2011-05-06 20:27:20 +02:00
Matthias Bolte
9de503f957 remote generator, client: Handle functions with simple return values 2011-05-06 20:27:18 +02:00
Matthias Bolte
f68bb4edb3 remote generator, client: Handle simple remote driver functions
Rename remoteSecretListSecrets to remoteListSecrets to match the normal
naming pattern.
2011-05-06 20:26:21 +02:00
Matthias Bolte
2c4105f112 remote generator: Reorder into prepare and print section 2011-05-06 20:09:50 +02:00
Matthias Bolte
6384104bcc remote generator, daemon: Handle functions with multiple return values
Once again rename members in the XDR definitions to avoid special case
code in the generator.
2011-05-06 20:08:36 +02:00
Matthias Bolte
38982f18f2 remote generator, daemon: Combine multiple ifs in the generated code 2011-05-06 20:08:34 +02:00
Matthias Bolte
5641222eba remote generator, daemon: Handle the CPU functions
They require additional special cases.
2011-05-06 20:08:31 +02:00
Matthias Bolte
900b18f47b remote generator: Refactor duplicate code 2011-05-06 20:08:29 +02:00
Matthias Bolte
33148050e7 remote generator, daemon: Handle functions that return lists 2011-05-06 20:08:27 +02:00
Matthias Bolte
705519d8e9 remote: Rename 'nameslen' to the common 'maxnames'
Avoids special case handling in the remote generator.
2011-05-06 20:08:25 +02:00
Matthias Bolte
9a74649cd2 remote generator, daemon: Handle functions with optional arguments 2011-05-06 20:08:23 +02:00
Matthias Bolte
0411030665 remote generator, daemon: Handle more functions
This covers functions that return single wrapped objects and don't
involve complexer code in the body.
2011-05-06 20:08:21 +02:00
Matthias Bolte
0c3cea0bd6 remote generator, daemon: Handle simple-return-value functions 2011-05-06 20:07:39 +02:00
Matthias Bolte
0fb79ff4bb remote generator, daemon: Change capitalization of some words
Again this will simplify the generator, due to less special case handling.
2011-05-06 20:05:01 +02:00
Matthias Bolte
37cb0882b5 remote: Replace 'domain' with 'dom' in the XDR protocol
This simplifies the remote protocol code generator.

Also rename 'ret' to 'result' to resolve a naming conflict in the
generator.
2011-05-06 20:05:00 +02:00
Matthias Bolte
aff1db9fab remote generator, daemon: Output function bodies too
This patch just covers the simple functions without explicit return
values. There is more to be handled.

The generator collects the members of the XDR argument structs and uses
this information to generate the function bodies.

Exclude the generated files from offending syntax-checks.

Suggested by Richard W.M. Jones
2011-05-06 20:04:56 +02:00
Matthias Bolte
999f5b3ea6 remote generator: Replace tabs with spaces and rename file
No functional change included, just a whitespace change.
2011-05-06 20:04:55 +02:00
Eric Blake
85cb292681 remote: avoid null dereference on error
Clang found three instances of uninitialized use of nparams in
the cleanup path.  Unfortunately, one is a false positive: clang
couldn't see that ret->params.params_val is guaranteed to be
NULL unless allocated within a function, and that nparams is
guaranteed to be assigned prior to the allocation; hoisting the
assignment to nparams to be earlier in the function shuts up
that false positive.  But two of the reports also happened to
highlight a real bug - the error path can dereference NULL.

Regression introduced in commit 158ba873.

* daemon/remote.c (remoteDispatchDomainGetMemoryParameters)
(remoteDispatchDomainGetBlkioParameters): Don't clear fields if
array was not allocated.
(remoteDispatchDomainGetSchedulerParameters): Initialize nparams
earlier.
2011-05-04 10:55:29 -06:00
Hu Tao
3c1326385a free memory properly in cleanup patch
virsh schedinfo inactive-domain will trigger the problem.
2011-04-27 20:12:14 +08:00
Matthias Bolte
802e2df9a3 daemon: Don't try to free an unsigned int in error paths 2011-04-22 19:02:40 +02:00
Matthias Bolte
56eb2081f5 daemon: Honor error variable name change in the generator
Commit 36b652138b renamed err to rerr, do the same in the generator.
2011-04-22 19:02:35 +02:00
Daniel P. Berrange
bf4883caff Change some variable names to follow standard in daemon dispatcher
Replace some occurrances of

  virDomainPtr domain;
  virNetworkPtr network;

With

  virDomainPtr dom;
  virNetworkPtr net;

* daemon/remote.c: Fix variable naming to follow standard
2011-04-18 15:20:33 +01:00
Daniel P. Berrange
05a6283c7a Write error check conditionals in more compact form for dispatcher
Replace cases of

     type = virConnectGetType(conn);
     if (type == NULL)
         goto cleanup;

With

     if (!(type = virConnectGetType(conn)))
         goto cleanup;

* daemon/remote.c: Write error checks in compat form
2011-04-18 15:20:33 +01:00
Daniel P. Berrange
55c71a26af Remove curly braces on all single-line conditional jumps in dispatcher
Replace all occurrances of

   if (....) {
      goto cleanup;
   }

With

   if (.....)
      goto cleanup;

to save one line of code

* daemon/remote.c: Remove curly braces on single line conditionals
2011-04-18 15:20:33 +01:00
Daniel P. Berrange
c19295e5ae Fix checking of return codes in dispatcher
The libvirt APIs reserve any negative value for indicating an
error. Thus checks

    if (virXXXX() == -1)

Should instead be

    if (virXXXX() < 0)

* daemon/remote.c: s/ == -1/ < 0/
2011-04-18 15:20:33 +01:00
Daniel P. Berrange
158ba8730e Merge all returns paths from dispatcher into single path
The dispatcher functions have numerous places where they
return to the caller. This leads to duplicated cleanup
code, often resulting in memory leaks. It makes it harder
to ensure that errors are dispatched before freeing objects,
which may overwrite the original error.

The standard pattern is now

    remoteDispatchXXX(...) {
        int rv = -1;

        ....
        if (XXX < 0)
          goto cleanup;
        ...
        if (XXXX < 0)
          goto cleanup;
        ...

        rv = 0;
    cleanup:
        if (rv < 0)
           remoteDispatchError(rerr);
        ...free all other stuff..
        return rv;
    }

* daemon/remote.c: Centralize all cleanup paths
* daemon/stream.c: s/remoteDispatchConnError/remoteDispatchError/
* daemon/dispatch.c, daemon/dispatch.h: Replace
  remoteDispatchConnError with remoteDispatchError
  removing unused virConnectPtr
2011-04-18 15:20:33 +01:00
Alan Pevec
16d6b0d80a Experimental libvirtd upstart job
To install it, disable libvirtd sysv initscript:
    chkconfig libvirtd off
    service libvirtd stop

and enable libvirtd upstart job:
    cp  /usr/share/doc/libvirt-*/libvirtd.upstart \
        /etc/init/libvirtd.conf
    initctl reload-configuration
    initctl start libvirtd

Test:
    initctl status libvirtd
libvirtd start/running, process 3929
    killall -9 libvirtd
    initctl status libvirtd
libvirtd start/running, process 4047

I looked into the possibility to use the upstart script from Ubuntu or
at least getting inspiration from it but that's not possible. "expect
daemon" is a nice thing but it only works if the process is defined with
exec stanza instead of script ... no script. Unfortunately, with exec
stanza environment variables can only be set within upstart script
(i.e., configuration in /etc/sysconfig/libvirtd can't work). Hence, we
need to use script stanza, source sysconfig, and execute libvirtd
without --daemon. For similar reasons we can't use limit stanza and need
to handle DAEMON_COREFILE_LIMIT in job's script.
2011-04-18 11:38:30 +02:00
Daniel P. Berrange
d93ef4466b Replace REMOTE_DEBUG with VIR_DEBUG in daemon dispatcher
The daemon dispatcher code had an obsolete macro

  #define REMOTE_DEBUG(fmt, ...) VIR_DEBUG(fmt, __VA_ARGS__)

This can be trivially removed

* daemon/remote.c: s/REMOTE_DEBUG/VIR_DEBUG/
2011-04-13 19:01:24 +01:00
Daniel P. Berrange
aaa6d7eb39 Add missing checks for whether the connection is open in dispatcher
Many functions did not check for whether a connection was
open. Replace the macro which obscures control flow, with
explicit checks, and ensure all dispatcher code has checks.

* daemon/remote.c: Add connection checks
2011-04-13 19:01:11 +01:00