Commit Graph

591 Commits

Author SHA1 Message Date
Daniel P. Berrange
3d1596b048 Introduce an LXC specific public API & library
This patch introduces support for LXC specific public APIs. In
common with what was done for QEMU, this creates a libvirt_lxc.so
library and libvirt/libvirt-lxc.h header file.

The actual APIs are

  int virDomainLxcOpenNamespace(virDomainPtr domain,
                                int **fdlist,
                                unsigned int flags);

  int virDomainLxcEnterNamespace(virDomainPtr domain,
                                 unsigned int nfdlist,
                                 int *fdlist,
                                 unsigned int *noldfdlist,
                                 int **oldfdlist,
                                 unsigned int flags);

which provide a way to use the setns() system call to move the
calling process into the container's namespace. It is not
practical to write in a generically applicable manner. The
nearest that we could get to such an API would be an API which
allows to pass a command + argv to be executed inside a
container. Even if we had such a generic API, this LXC specific
API is still useful, because it allows the caller to maintain
the current process context, in particular any I/O streams they
have open.

NB the virDomainLxcEnterNamespace() API is special in that it
runs client side, so does not involve the internal driver API.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-01-14 13:58:34 +00:00
Daniel P. Berrange
d3b05abfa9 Convert HAVE_UDEV to WITH_UDEV
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-01-14 13:26:47 +00:00
Daniel P. Berrange
f24404a324 Rename virterror.c virterror_internal.h to virerror.{c,h} 2012-12-21 11:19:50 +00:00
Daniel P. Berrange
556cf5f617 Rename xml.{c,h} to virxml.{c,h} 2012-12-21 11:19:50 +00:00
Daniel P. Berrange
44f6ae27fe Rename util.{c,h} to virutil.{c,h} 2012-12-21 11:19:49 +00:00
Daniel P. Berrange
404174cad3 Rename threads.{c,h} to virthread.{c,h} 2012-12-21 11:19:49 +00:00
Daniel P. Berrange
ab9b7ec2f6 Rename memory.{c,h} to viralloc.{c,h} 2012-12-21 11:17:14 +00:00
Daniel P. Berrange
4d6050a8eb Rename event_poll.{c,h} to vireventpoll.{c,h} 2012-12-21 11:17:13 +00:00
Daniel P. Berrange
04d9510f50 Rename command.{c,h} to vircommand.{c,h} 2012-12-21 11:17:13 +00:00
Daniel P. Berrange
2005f7b552 Rename buf.{c,h} to virbuffer.{c,h}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-12-21 11:17:12 +00:00
Daniel P. Berrange
a27e4fbb72 Rename bitmap.{c,h} to virbitmap.{c,h}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-12-21 11:17:12 +00:00
Ján Tomko
8d0e7eb4c1 virsh: use vshReconnect for non-default connections too
For non-default connections (specified by the environment variable or
the command line option) we call virConnectOpenAuth without registering
the vshCatchDisconnect callback.

This calls vshReconnect instead which takes care of it.
2012-12-13 16:39:38 +01:00
Ján Tomko
d94b501b7b virsh: don't lie about reconnection in vshReconnect
Since we (ab)use vshReconnect for the default URI connection, if it
fails it might print 'Failed to reconnect to the hypervisor' even if we
were never connected before.

This changes it to only mention reconnection on the first try after
getting disconnected.
2012-12-13 16:39:38 +01:00
Peter Krempa
989a427de8 virsh: Fix usage of header termios.h
The termios struct exported by the termios.h header is used as an
argument for vshMakeStdinRaw(). The header isn't used anywhere in
tools/virsh-domain.c.

This patch adds the header to the header declaring vshMakeStdinRaw() and
removes other places in virsh.
2012-12-07 14:21:25 +01:00
Peter Krempa
bf72095954 virsh: Report errors if arguments of the schedinfo command are incorrect
Libvirt's helper API's when called directly don't raise the error so
that virsh remembers it. Subsequent calls to libvirt API's might reset
the error.

In case of schedinfo virDomainFree() in the cleanup section resets the
error when virTypedParameterAssignFromStr() fails.

This patch adds function vshSaveLibvirtError() that can be called after
calling libvirt helper APIs to ensure the error is remembered.
2012-12-03 16:37:10 +01:00
Ján Tomko
8b235d4057 virsh: do timing even for unusable connections
Time values were uninitialized if the connection wasn't usable.
2012-11-29 10:10:08 -07:00
Eric Blake
9d91a18ebf virsh: make ,, escape parsing common
So far, none of the existing callers of vshStringToArray expected
the user to ever pass a literal comma; meanwhile, snapshot parsing
had rolled its own array parser.  Moving the comma escaping into
the common function won't affect any existing callers, and will make
this function reusable for adding memory handling to snapshot parsing.

As a bonus, the testsuite was already testing snapshot parsing, so
the fact that the test still passes means that we are now giving
testsuite exposure to vshStringToArray.

* tools/virsh-snapshot.c (vshParseSnapshotDiskspec): Move ,,
parsing...
* tools/virsh.c (vshStringToArray): ...into common function.
Also, vshStrdup can't fail.
2012-11-07 09:01:37 -07:00
Daniel P. Berrange
1c04f99970 Remove spurious whitespace between function name & open brackets
The libvirt coding standard is to use 'function(...args...)'
instead of 'function (...args...)'. A non-trivial number of
places did not follow this rule and are fixed in this patch.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-02 13:36:49 +00:00
Eric Blake
4dbd6e9654 build: prefer mkostemp for multi-thread safety
https://bugzilla.redhat.com/show_bug.cgi?id=871756

Commit cd1e8d1 assumed that systems new enough to have journald
also have mkostemp; but this is not true for uclibc.

For that matter, use of mkstemp[s] is unsafe in a multi-threaded
program.  We should prefer mkostemp[s] in the first place.

* bootstrap.conf (gnulib_modules): Add mkostemp, mkostemps; drop
mkstemp and mkstemps.
* cfg.mk (sc_prohibit_mkstemp): New syntax check.
* tools/virsh.c (vshEditWriteToTempFile): Adjust caller.
* src/qemu/qemu_driver.c (qemuDomainScreenshot)
(qemudDomainMemoryPeek): Likewise.
* src/secret/secret_driver.c (replaceFile): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainScreenshot): Likewise.
2012-10-31 10:06:10 -06:00
Doug Goldstein
5a33366f5c interface: add udev based backend for virInterface
Add a read-only udev based backend for virInterface. Useful for distros
that do not have netcf support yet. Multiple libvirt based utilities use
a HAL based fallback when virInterface is not available which is less
than ideal. This implements:
* virConnectNumOfInterfaces()
* virConnectListInterfaces()
* virConnectNumOfDefinedInterfaces()
* virConnectListDefinedInterfaces()
* virConnectListAllInterfaces()
* virConnectInterfaceLookupByName()
* virConnectInterfaceLookupByMACString()
2012-10-09 09:39:43 -06:00
Eric Blake
4ecb723b9e maint: fix up copyright notice inconsistencies
https://www.gnu.org/licenses/gpl-howto.html recommends that
the 'If not, see <url>.' phrase be a separate sentence.

* tests/securityselinuxhelper.c: Remove doubled line.
* tests/securityselinuxtest.c: Likewise.
* globally: s/;  If/.  If/
2012-09-20 16:30:55 -06:00
Doug Goldstein
6a1b0e37af virsh: Move daemon to misc since its not a network
Move the 'Daemon' entry to the Miscellaneous section since its not a
networking driver or component.
2012-09-19 14:19:45 -06:00
Doug Goldstein
b95ad92e05 build: define WITH_INTERFACE for the driver
Based exclusively on work by Eric Blake in a patch posted with the same
subject. However some modifications related to comments and my plans to
add another backend.

Added WITH_INTERFACE as the only automake variable deciding whether to
build the driver and using WITH_NETCF to identify that we're wanting to
use the netcf library as the backend.

* configure.ac: Added with_interface
* src/interface/netcf_driver.c: Renamed..
* src/interface/interface_backend_netcf.c: ..to this to match storage.
* src/interface/netcf_driver.h: Renamed..
* src/interface/interface_driver.h: ..to this.
* daemon/Makefile.am: Respect WITH_INTERFACE and WITH_NETCF.
* libvirt.spec.in: Add RPM support for --with-interface
2012-09-19 08:27:01 -06:00
Doug Goldstein
c88a4f2a46 virsh: Rename QEmu to QEMU to match upstream
Match upstream's naming of QEMU. There was a notice on the ML that said
the preferred spelling was QEMU a while back.
2012-09-19 06:59:19 -06:00
Osier Yang
f5fb059a78 virsh: Don't motify the const string
This improve helper vshStringToArray to accept const string as
argument instead. To not convert the const string when using
vshStringToArray, and thus avoid motifying it.
2012-09-17 11:29:31 +08:00
Osier Yang
f7eac4f722 list: Add helper to convert strings separated by ', ' to array
tools/virsh.c: New helper function vshStringToArray.
tools/virsh.h: Declare vshStringToArray.
tools/virsh-domain.c: use the helper in cmdUndefine.
2012-09-06 22:04:43 +08:00
Eric Blake
44342a0efe build: use re-entrant functions in virsh
Yesterday's commit 15d2c9f pointed out that virsh was still using
localtime(), which is not thread-safe, even though virsh is
definitely multi-threaded.  Even if we only ever triggered it from
one thread, it's better safe than sorry for maintenance purposes.

* cfg.mk (exclude_file_name_regexp--sc_prohibit_nonreentrant):
Tighten the rule.
* tools/virsh.c (vshOutputLogFile): Avoid localtime.
(vshEditWriteToTempFile, vshEditReadBackFile, cmdCd, cmdPwd)
(vshCloseLogFile): Avoid strerror.
* tools/console.c (vshMakeStdinRaw): Likewise.
* tools/virsh-domain.c (vshGenFileName): Fix spacing in previous
patch.
2012-09-05 11:09:04 -06:00
Paul Eggert
15d2c9fad4 Pass a correct pointer type to localtime_r(3).
On 09/04/2012 08:20 AM, Eric Blake wrote:
> tv_sec is required by POSIX to be
> of type time_t; so this is a bug in the OpenBSD header
> [for declaring it as long]

Most likely this problem arose because of the patch I pushed
in gnulib commit e07d7c40f3ca5ec410cf5aa6fa03cfe51e712039.
Previously, gnulib required timeval's tv_sec to be
the same size as time_t.  But now, it requires only that
tv_sec be big enough to hold a time_t.

This patch was needed for Emacs.  Without the patch, gnulib
replaced struct timeval on OpenBSD, and this messed up
utimens.c, and Emacs wouldn't build.

Alternatively, gnulib could substitute its own struct timeval
for the system's, wrapping every struct timeval-using function
(gettimeofday, futimesat, futimes, lutimes, etc.  That'd be
more work, though.  And it would introduce some performance
issues with gettimeofday, which is supposed to be fast.

I've been trying to get away from using struct timeval,
and to use the higher-resolution struct timespec instead,
so messing with these obsolescent interfaces has been
lower priority for me.  But if someone wants to take the
more-ambitious approach that'd be fine, I expect.

For this particular case, though, how about if we avoid
the problem entirely?  libvirt doesn't need to use struct
timeval here at all.  It makes libvirt smaller and probably
faster, and it ports to OpenBSD without messing with gnulib.
2012-09-04 17:20:08 -06:00
Peter Krempa
67f83cd497 virsh: remove unneeded usage of vshConnectionUsability()
Now that vshCommandRun() checks for the connection automaticaly, remove
all of the redundant checks in the code.

vshConnectionUsability() no longer needs to be exported and this patch
marks it static.
2012-08-31 16:22:22 +02:00
Peter Krempa
70e608918e virsh: Improve checking for connection when running commands
Almost each virsh command uses the function vshConnectionUsability
before doing anything, to check if the connection is "alive".  Commands
that don't need an conection are already conveniently marked with
VSH_CMD_FLAG_NOCONNECT. We can automaticaly check for the connection
before calling any remote command so we don't forget to do so.

This patch also upgrades the connection check to use virConnectIsAlive
along with the current approach.
2012-08-31 16:22:22 +02:00
Viktor Mihajlovski
641d406d27 virsh: fixed incorrect timing report
When executing virsh -t <command> the reported timing was off
by 3 orders of magnitude if the command took more than one
second.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
2012-08-31 20:00:20 +08:00
Eric Blake
f95f1ba4c0 virsh: split out virsh-volume.c
Last of the file splits.

* tools/virsh-volume.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-volume.c: Likewise.
(vshCommandOptVolBy): Fix flag usage.
2012-08-21 00:23:12 -06:00
Eric Blake
c0dbd5f352 virsh: split out virsh-snapshot.c
Almost done with the splits.

* tools/virsh-snapshot.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-snapshot.c: Likewise.
2012-08-21 00:19:10 -06:00
Eric Blake
9cbb0eda92 virsh: split out virsh-secret.c
One of the simpler splits.

* tools/virsh-secret.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-secret.c: Likewise.
2012-08-21 00:16:35 -06:00
Eric Blake
ef8d35830c virsh: split out virsh-pool.c
More in a series of file splits.

* tools/virsh-pool.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-pool.c: Likewise.
(virCommandOptPoolBy): Fix flag usage.
2012-08-21 00:11:29 -06:00
Eric Blake
69af4f7cb8 virsh: split out virsh-nwfilter.c
Yet another split file.

* tools/virsh-nwfilter.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-nwfilter.c: Likewise.
2012-08-21 00:07:30 -06:00
Eric Blake
ea3cf921f2 virsh: split out virsh-nodedev.c
Another worthwhile split, needed one more public function.

* tools/virsh-nodedev.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh-nodedev.c: Use new header.
* tools/virsh.c: Likewise.
(vshTreePrint): Export.
* tools/virsh.h (vshTreePrint): Declare.
2012-08-21 00:05:53 -06:00
Eric Blake
dcff981a70 virsh: split out virsh-network.c
Another relatively easy file split.

* tools/virsh-network.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-network.c: Likewise.
(vshCommandOptNetworkBy): Update signature.
2012-08-21 00:02:09 -06:00
Eric Blake
7aeb16a8c0 virsh: split out virsh-interface.c
Another relatively easy split, since helper functions were fixed
in the previous patch.

* tools/virsh-interface.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-interface.c: Likewise.
(vshCommandOptInterfaceBy): Check flags.
2012-08-20 23:59:06 -06:00
Eric Blake
4c10b3c7da virsh: declare more common functions
In preparation for splitting virsh-interface.c, I found these
functions need to be declared in virsh.h, as well as one that
belongs more properly in virsh-domain.h.  Also, since we
use the VSH_BY* flags in more than one function, I improved
how they are used.

* tools/virsh.h (vshNameSorter, vshCmdHasOption): Declare.
(VSH_BYID): Turn into enum.
(vshCommandOptDomainBy): Move...
* tools/virsh-domain.h): ...here.
* tools/virsh.c: (vshNameSorter): Export.
(cmd_has_option): Rename...
(vshCmdHasOption): ...and export.
(vshCommandOptDomainBy): Move...
* tools/virsh-domain.c (vshCommandOptDomainBy): ...here, adjust
signature, and check flags.
* tools/virsh-network.c (vshCommandOptNetworkBy): Update callers.
* tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise.
* tools/virsh-secret.c (vshCommandOptSecret): Likewise.
* tools/virsh-domain-monitor.c (includes): Likewise.
* tools/virsh-host.c (includes): Likewise.
2012-08-20 23:56:18 -06:00
Eric Blake
ae8e89fb12 virsh: split out virsh-host.c
The splits are getting easier, with fewer cleanups needed in virsh.h.

* tools/virsh-host.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh-host.c: Use new header.
* tools/virsh.c: Likewise.
2012-08-20 23:51:29 -06:00
Eric Blake
99ae57f841 virsh: split out virsh-domain-monitor.c
Another file worth compiling on its own instead of by .c inclusion.

* tools/virsh-domain-monitor.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.h (vshGetDomainDescription): Move to correct
header.
* tools/virsh-domain-monitor.c: Use new header.
* tools/virsh.c: Likewise.
* tools/virsh-domain.c: Likewise.
2012-08-20 23:39:54 -06:00
Eric Blake
521b7ab7eb virsh: drop unused headers
The previous commit now trips up 'make syntax-check' due to a useless
use of <signal.h>.

* tools/virsh.c (includes): Drop useless includes.
2012-08-20 09:57:38 -06:00
Daniel P. Berrange
6a48179803 Fix build of virsh on Win32 by moving SA_SIGINFO stub
On Win32 SA_SIGINFO is not defined, so virsh.c stub'd it out
to 0, but recent changes moved the usage out of virsh.c and
into virsh-domain.c
2012-08-20 16:00:29 +01:00
Eric Blake
e68ee5e765 virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.

* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-20 07:04:10 -06:00
Daniel P. Berrange
ee7b4e551e Make Win32 stub of vshAskReedit non-static
The main impl of vshAskReedit is non-static, so the Win32
stub must be the same
2012-08-20 13:29:14 +01:00
Eric Blake
6d96fab9cf virsh: kill some double underscores
C99 says that __foo naming is reserved for the compiler.  Besides,
we had several different styles in use; this consolidates things
to set up the typedefs up front then declare the types with
consistent naming.

* tools/virsh.h: Use consistent struct naming.
* tools/virsh.c (_vshCommandParser): Likewise.
2012-08-18 08:10:02 -06:00
Eric Blake
f4a7b87de0 virsh: split out virsh-domain.c
The virsh-domain.c file was pretty self-contained; the only
entry point was the table of command definitions.  The bulk
of this patch is making more functions in virsh.c reusable.
A later patch will clean up poor naming choices.

* tools/Makefile.am (virsh_SOURCES): Build virsh-domain.c.
* tools/virsh-domain.h: New file.
* tools/virsh.h (virshReportError, vshResetLibvirtError)
(vshAskReedit, vshStreamSink): Declare.
* tools/virsh.c: Switch from using .c to .h.
(virshReportError, vshResetLibvirtError, vshAskReedit)
(vshStreamSink, prettyCapacity): Export.
(vshCatchInt): Move...
* tools/virsh-domain.c: ...into sole user.  Use header.
2012-08-17 22:22:42 -06:00
Eric Blake
c2e494cc57 virsh: split out virsh.h
Having one .c file include another does not give any compilation
benefits; move towards modular .o files by first splitting out
reused declarations into a new virsh.h.  This patch doesn't try
very hard to see which functions are used or not, to make it
easier to review the file split.  Future patches can further trim
the header to be smaller.

* tools/Makefile.am (virsh_SOURCES): List new file, and prepare
for others.
* tools/virsh.c: Split declarations...
* tools/virsh.h: ...into new file, and make several functions
non-static.
* tools/virsh-domain-monitor.c (vshGetDomainDescription): Make
non-static.
2012-08-17 21:54:42 -06:00
Eric Blake
8e8809e131 virsh: move vshWatchJob earlier
It's easier to order things in topological order than it is to
forward declare in one file for use only by one other file.

* tools/virsh.c (vshWatchJob, parseRateStr)
(vshDomainStateToString, vshDomainStateReasonToString)
(vshDomainControlStateToString, vshDomainVcpuStateToString): Drop
useless prototypes.
* tools/virsh-domain.c (vshWatchJob): Move earlier.
2012-08-17 21:44:14 -06:00