2012-08-18 07:16:04 +04:00
/*
* virsh . h : a shell to exercise the libvirt API
*
2016-01-09 16:36:23 +03:00
* Copyright ( C ) 2005 , 2007 - 2016 Red Hat , Inc .
2012-08-18 07:16:04 +04: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-21 02:30:55 +04:00
* License along with this library . If not , see
2012-08-18 07:16:04 +04:00
* < http : //www.gnu.org/licenses/>.
*/
2019-06-18 19:13:15 +03:00
# pragma once
2012-08-18 07:16:04 +04:00
2019-06-18 19:13:15 +03:00
# include <unistd.h>
2012-08-18 07:16:04 +04:00
2019-06-18 19:13:15 +03:00
# include "internal.h"
# include "virpolkit.h"
# include "vsh.h"
# include "virsh-completer.h"
2019-12-05 18:00:22 +03:00
# include "virenum.h"
2012-08-18 07:16:04 +04:00
2019-06-18 19:13:15 +03:00
# define VIRSH_PROMPT_RW "virsh # "
# define VIRSH_PROMPT_RO "virsh > "
2012-08-18 07:16:04 +04:00
2019-06-18 19:13:15 +03:00
# define VIR_FROM_THIS VIR_FROM_NONE
2012-08-18 07:16:04 +04:00
/*
* Command group types
*/
2019-03-14 00:04:51 +03:00
# define VIRSH_CMD_GRP_CHECKPOINT "Checkpoint"
2019-06-18 19:13:15 +03:00
# define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management"
# define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring"
2022-02-21 16:02:19 +03:00
# define VIRSH_CMD_GRP_DOM_EVENTS "Domain Events"
2019-06-18 19:13:15 +03:00
# 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"
2019-08-22 04:42:45 +03:00
# define VIRSH_CMD_GRP_BACKUP "Backup"
2019-06-18 19:13:15 +03:00
# define VIRSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor"
# define VIRSH_CMD_GRP_VIRSH "Virsh itself"
2012-08-18 07:16:04 +04:00
2016-01-09 16:36:23 +03:00
/*
* Common command options
*/
2019-06-18 19:13:15 +03:00
# define VIRSH_COMMON_OPT_POOL(_helpstr, cflags) \
2017-11-03 15:09:47 +03:00
{ . name = " pool " , \
2024-03-05 18:07:36 +03:00
. type = VSH_OT_STRING , \
2024-03-05 17:07:47 +03:00
. positional = true , \
. required = true , \
2018-01-12 16:01:33 +03:00
. help = _helpstr , \
. completer = virshStoragePoolNameCompleter , \
. completer_flags = cflags , \
2017-10-31 13:47:36 +03:00
}
2016-01-09 16:36:23 +03:00
2019-06-18 19:13:15 +03:00
# define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \
2017-11-03 15:09:47 +03:00
{ . name = " domain " , \
2024-03-05 18:07:36 +03:00
. type = VSH_OT_STRING , \
2024-03-05 17:07:47 +03:00
. positional = true , \
. required = true , \
2017-10-31 11:24:21 +03:00
. help = _helpstr , \
. completer = virshDomainNameCompleter , \
. completer_flags = cflags , \
2017-10-31 13:47:36 +03:00
}
2016-01-09 16:36:24 +03:00
2019-06-18 19:13:15 +03:00
# define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \
2018-05-08 17:20:29 +03:00
VIRSH_COMMON_OPT_DOMAIN ( N_ ( " domain name, id or uuid " ) , cflags )
2019-06-18 19:13:15 +03:00
# define VIRSH_COMMON_OPT_CONFIG(_helpstr) \
2017-11-03 15:09:47 +03:00
{ . name = " config " , \
. type = VSH_OT_BOOL , \
. help = _helpstr \
2017-10-31 13:47:36 +03:00
}
2016-01-09 16:36:26 +03:00
2019-06-18 19:13:15 +03:00
# define VIRSH_COMMON_OPT_LIVE(_helpstr) \
2017-11-03 15:09:47 +03:00
{ . name = " live " , \
. type = VSH_OT_BOOL , \
. help = _helpstr \
2017-10-31 13:47:36 +03:00
}
2016-01-09 16:36:27 +03:00
2019-06-18 19:13:15 +03:00
# define VIRSH_COMMON_OPT_CURRENT(_helpstr) \
2017-11-03 15:09:47 +03:00
{ . name = " current " , \
. type = VSH_OT_BOOL , \
. help = _helpstr \
2017-10-31 13:47:36 +03:00
}
2016-01-09 16:36:28 +03:00
2021-09-16 14:03:02 +03:00
/* Use this only for files which are existing and used locally by virsh */
2019-06-18 19:13:15 +03:00
# define VIRSH_COMMON_OPT_FILE(_helpstr) \
2017-11-03 15:09:47 +03:00
{ . name = " file " , \
2024-03-05 18:07:36 +03:00
. type = VSH_OT_STRING , \
2024-03-15 00:14:31 +03:00
. required = true , \
. positional = true , \
2021-09-15 18:08:37 +03:00
. completer = virshCompletePathLocalExisting , \
2017-11-03 15:09:47 +03:00
. help = _helpstr \
2017-10-31 13:47:36 +03:00
}
2016-01-09 16:36:29 +03:00
2015-06-15 19:53:58 +03:00
typedef struct _virshControl virshControl ;
2012-08-18 07:16:04 +04:00
2015-06-15 19:53:58 +03:00
typedef struct _virshCtrlData virshCtrlData ;
2012-08-18 07:16:04 +04:00
/*
* vshControl
*/
2015-06-15 19:53:58 +03:00
struct _virshControl {
2012-08-18 07:16:04 +04: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-29 03:39:25 +04:00
bool blockJobNoBytes ; /* true if _BANDWIDTH_BYTE blockjob flags
are missing */
2012-08-18 07:16:04 +04:00
const char * escapeChar ; /* String representation of
console escape character */
2012-08-18 08:35:13 +04:00
} ;
2012-08-18 07:16:04 +04:00
/* Typedefs, function prototypes for job progress reporting.
* There are used by some long lingering commands like
* migrate , dump , save , managedsave .
*/
2015-06-15 19:53:58 +03:00
struct _virshCtrlData {
2012-08-18 07:16:04 +04:00
vshControl * ctl ;
const vshCmd * cmd ;
2020-02-05 17:16:16 +03:00
GMainLoop * eventLoop ;
int ret ;
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 12:44:36 +04:00
virConnectPtr dconn ;
2012-08-18 08:35:13 +04:00
} ;
2012-08-18 07:16:04 +04:00
2015-06-15 19:53:58 +03: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 13:01:35 +03:00
2015-06-15 19:53:58 +03:00
virConnectPtr virshConnect ( vshControl * ctl , const char * uri , bool readonly ) ;