2012-08-18 03:16:04 +00:00
|
|
|
/*
|
|
|
|
* virsh.h: a shell to exercise the libvirt API
|
|
|
|
*
|
2016-01-09 13:36:23 +00:00
|
|
|
* Copyright (C) 2005, 2007-2016 Red Hat, Inc.
|
2012-08-18 03:16:04 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-08-18 03:16:04 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Daniel Veillard <veillard@redhat.com>
|
|
|
|
* Karel Zak <kzak@redhat.com>
|
|
|
|
* Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef VIRSH_H
|
2012-08-20 10:17:26 +00:00
|
|
|
# define VIRSH_H
|
2012-08-18 03:16:04 +00:00
|
|
|
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <string.h>
|
|
|
|
# include <stdarg.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/stat.h>
|
2013-08-29 08:36:00 +00:00
|
|
|
# include <termios.h>
|
2012-08-18 03:16:04 +00:00
|
|
|
|
|
|
|
# include "internal.h"
|
2012-12-13 18:21:53 +00:00
|
|
|
# include "virerror.h"
|
2012-12-13 15:49:48 +00:00
|
|
|
# include "virthread.h"
|
2016-02-09 19:08:42 +00:00
|
|
|
# include "virpolkit.h"
|
2015-06-15 16:53:58 +00:00
|
|
|
# include "vsh.h"
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
# define VIRSH_PROMPT_RW "virsh # "
|
|
|
|
# define VIRSH_PROMPT_RO "virsh > "
|
2012-08-18 03:16:04 +00:00
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_NONE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Command group types
|
|
|
|
*/
|
2015-06-15 16:53:58 +00:00
|
|
|
# define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management"
|
|
|
|
# define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring"
|
|
|
|
# define VIRSH_CMD_GRP_STORAGE_POOL "Storage Pool"
|
|
|
|
# define VIRSH_CMD_GRP_STORAGE_VOL "Storage Volume"
|
|
|
|
# define VIRSH_CMD_GRP_NETWORK "Networking"
|
|
|
|
# define VIRSH_CMD_GRP_NODEDEV "Node Device"
|
|
|
|
# define VIRSH_CMD_GRP_IFACE "Interface"
|
|
|
|
# define VIRSH_CMD_GRP_NWFILTER "Network Filter"
|
|
|
|
# define VIRSH_CMD_GRP_SECRET "Secret"
|
|
|
|
# define VIRSH_CMD_GRP_SNAPSHOT "Snapshot"
|
|
|
|
# define VIRSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor"
|
|
|
|
# define VIRSH_CMD_GRP_VIRSH "Virsh itself"
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2016-01-09 13:36:23 +00:00
|
|
|
/*
|
|
|
|
* Common command options
|
|
|
|
*/
|
|
|
|
# define VIRSH_COMMON_OPT_POOL(_helpstr) \
|
|
|
|
{.name = "pool", \
|
|
|
|
.type = VSH_OT_DATA, \
|
|
|
|
.flags = VSH_OFLAG_REQ, \
|
|
|
|
.help = _helpstr \
|
|
|
|
} \
|
|
|
|
|
2016-01-09 13:36:24 +00:00
|
|
|
# define VIRSH_COMMON_OPT_DOMAIN(_helpstr) \
|
|
|
|
{.name = "domain", \
|
|
|
|
.type = VSH_OT_DATA, \
|
|
|
|
.flags = VSH_OFLAG_REQ, \
|
|
|
|
.help = _helpstr \
|
|
|
|
} \
|
|
|
|
|
2016-01-09 13:36:26 +00:00
|
|
|
# define VIRSH_COMMON_OPT_CONFIG(_helpstr) \
|
|
|
|
{.name = "config", \
|
2016-01-12 08:09:36 +00:00
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.help = _helpstr \
|
2016-01-09 13:36:26 +00:00
|
|
|
} \
|
|
|
|
|
2016-01-09 13:36:27 +00:00
|
|
|
# define VIRSH_COMMON_OPT_LIVE(_helpstr) \
|
|
|
|
{.name = "live", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.help = _helpstr \
|
|
|
|
} \
|
|
|
|
|
2016-01-09 13:36:28 +00:00
|
|
|
# define VIRSH_COMMON_OPT_CURRENT(_helpstr) \
|
|
|
|
{.name = "current", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.help = _helpstr \
|
|
|
|
} \
|
|
|
|
|
2016-01-09 13:36:29 +00:00
|
|
|
# define VIRSH_COMMON_OPT_FILE(_helpstr) \
|
|
|
|
{.name = "file", \
|
|
|
|
.type = VSH_OT_DATA, \
|
|
|
|
.flags = VSH_OFLAG_REQ, \
|
|
|
|
.help = _helpstr \
|
|
|
|
} \
|
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
typedef struct _virshControl virshControl;
|
|
|
|
typedef virshControl *virshControlPtr;
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
typedef struct _virshCtrlData virshCtrlData;
|
2012-08-18 03:16:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* vshControl
|
|
|
|
*/
|
2015-06-15 16:53:58 +00:00
|
|
|
struct _virshControl {
|
2012-08-18 03:16:04 +00:00
|
|
|
virConnectPtr conn; /* connection to hypervisor (MAY BE NULL) */
|
|
|
|
bool readonly; /* connect readonly (first time only, not
|
|
|
|
* during explicit connect command)
|
|
|
|
*/
|
|
|
|
bool useGetInfo; /* must use virDomainGetInfo, since
|
|
|
|
virDomainGetState is not supported */
|
|
|
|
bool useSnapshotOld; /* cannot use virDomainSnapshotGetParent or
|
|
|
|
virDomainSnapshotNumChildren */
|
2014-08-28 23:39:25 +00:00
|
|
|
bool blockJobNoBytes; /* true if _BANDWIDTH_BYTE blockjob flags
|
|
|
|
are missing */
|
2012-08-18 03:16:04 +00:00
|
|
|
const char *escapeChar; /* String representation of
|
|
|
|
console escape character */
|
2012-08-18 04:35:13 +00:00
|
|
|
};
|
2012-08-18 03:16:04 +00:00
|
|
|
|
|
|
|
/* Typedefs, function prototypes for job progress reporting.
|
|
|
|
* There are used by some long lingering commands like
|
|
|
|
* migrate, dump, save, managedsave.
|
|
|
|
*/
|
2015-06-15 16:53:58 +00:00
|
|
|
struct _virshCtrlData {
|
2012-08-18 03:16:04 +00:00
|
|
|
vshControl *ctl;
|
|
|
|
const vshCmd *cmd;
|
|
|
|
int writefd;
|
cmdMigrate: move vshConnect before vshWatchJob
A possible fix to issue:
http://www.redhat.com/archives/libvir-list/2014-August/thread.html#00227
While doing migration on KVM host, found problem sometimes:
VM is already running on the target host and disappears from source
host, but 'virsh migrate' command line hangs, cannot exit normally.
If pressing "ENTER" key, it will exit.
The code hangs at tools/virsh-domain.c: cmdMigrate
->vshWatchJob->poll():
poll() is trying to select pipe_fd, which is used to receive message
from doMigrate thread. In debugging, found that doMigrate finishes
and at the end it does call safewrite() to write the retval ('0' or
'1') to pipe_fd, and the write is completed. But cmdMigrate poll()
cannot get the event. If pressing "ENTER" key, poll() can get the
event and select pipe_fd, then command line can exit.
In current code, authentication thread which is called by vshConnect
will use stdin, and at the same time, in cmdMigrate main process,
poll() is listening to stdin, that probably affect poll() to get
pipe_fd event. Better to move authentication before vshWatchJob. With
this change, above problem does not exist.
Signed-off-by: Chunyan Liu <cyliu@suse.com>
2014-08-08 08:44:36 +00:00
|
|
|
virConnectPtr dconn;
|
2012-08-18 04:35:13 +00:00
|
|
|
};
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
/* Filter flags for various vshCommandOpt*By() functions */
|
|
|
|
typedef enum {
|
|
|
|
VIRSH_BYID = (1 << 1),
|
|
|
|
VIRSH_BYUUID = (1 << 2),
|
|
|
|
VIRSH_BYNAME = (1 << 3),
|
|
|
|
VIRSH_BYMAC = (1 << 4),
|
|
|
|
} virshLookupByFlags;
|
2015-03-26 10:01:35 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly);
|
|
|
|
int virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
|
2015-03-26 10:01:35 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
int virshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
|
|
|
|
void *opaque);
|
2015-03-26 10:01:35 +00:00
|
|
|
|
2012-08-18 03:16:04 +00:00
|
|
|
#endif /* VIRSH_H */
|