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/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#pragma once
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#include <unistd.h>
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "virpolkit.h"
|
|
|
|
#include "vsh.h"
|
|
|
|
#include "virsh-completer.h"
|
2019-12-05 15:00:22 +00:00
|
|
|
#include "virenum.h"
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_PROMPT_RW "virsh # "
|
|
|
|
#define VIRSH_PROMPT_RO "virsh > "
|
2012-08-18 03:16:04 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
2012-08-18 03:16:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Command group types
|
|
|
|
*/
|
2019-03-13 21:04:51 +00:00
|
|
|
#define VIRSH_CMD_GRP_CHECKPOINT "Checkpoint"
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management"
|
|
|
|
#define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring"
|
2022-02-21 13:02:19 +00:00
|
|
|
#define VIRSH_CMD_GRP_DOM_EVENTS "Domain Events"
|
2019-06-18 16:13:15 +00: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 01:42:45 +00:00
|
|
|
#define VIRSH_CMD_GRP_BACKUP "Backup"
|
2019-06-18 16:13:15 +00:00
|
|
|
#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
|
|
|
|
*/
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_POOL(_helpstr, cflags) \
|
2017-11-03 12:09:47 +00:00
|
|
|
{.name = "pool", \
|
2024-03-05 15:07:36 +00:00
|
|
|
.type = VSH_OT_STRING, \
|
2024-03-05 14:07:47 +00:00
|
|
|
.positional = true, \
|
|
|
|
.required = true, \
|
2018-01-12 13:01:33 +00:00
|
|
|
.help = _helpstr, \
|
|
|
|
.completer = virshStoragePoolNameCompleter, \
|
|
|
|
.completer_flags = cflags, \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2016-01-09 13:36:23 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_DOMAIN(_helpstr, cflags) \
|
2017-11-03 12:09:47 +00:00
|
|
|
{.name = "domain", \
|
2024-03-05 15:07:36 +00:00
|
|
|
.type = VSH_OT_STRING, \
|
2024-03-05 14:07:47 +00:00
|
|
|
.positional = true, \
|
|
|
|
.required = true, \
|
2017-10-31 08:24:21 +00:00
|
|
|
.help = _helpstr, \
|
|
|
|
.completer = virshDomainNameCompleter, \
|
|
|
|
.completer_flags = cflags, \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2016-01-09 13:36:24 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_DOMAIN_FULL(cflags) \
|
2018-05-08 14:20:29 +00:00
|
|
|
VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid"), cflags)
|
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_CONFIG(_helpstr) \
|
2017-11-03 12:09:47 +00:00
|
|
|
{.name = "config", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.help = _helpstr \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2016-01-09 13:36:26 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_LIVE(_helpstr) \
|
2017-11-03 12:09:47 +00:00
|
|
|
{.name = "live", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.help = _helpstr \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2016-01-09 13:36:27 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_CURRENT(_helpstr) \
|
2017-11-03 12:09:47 +00:00
|
|
|
{.name = "current", \
|
|
|
|
.type = VSH_OT_BOOL, \
|
|
|
|
.help = _helpstr \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2016-01-09 13:36:28 +00:00
|
|
|
|
2021-09-16 11:03:02 +00:00
|
|
|
/* Use this only for files which are existing and used locally by virsh */
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_FILE(_helpstr) \
|
2022-10-06 14:29:32 +00:00
|
|
|
VIRSH_COMMON_OPT_FILE_FULL(_helpstr, true)
|
|
|
|
|
2024-03-05 14:07:47 +00:00
|
|
|
#define VIRSH_COMMON_OPT_FILE_FULL(_helpstr, required_) \
|
2017-11-03 12:09:47 +00:00
|
|
|
{.name = "file", \
|
2024-03-05 15:07:36 +00:00
|
|
|
.type = VSH_OT_STRING, \
|
2024-03-05 14:07:47 +00:00
|
|
|
.required = required_, \
|
|
|
|
.positional = required_, \
|
2021-09-15 15:08:37 +00:00
|
|
|
.completer = virshCompletePathLocalExisting, \
|
2017-11-03 12:09:47 +00:00
|
|
|
.help = _helpstr \
|
2017-10-31 10:47:36 +00:00
|
|
|
}
|
2016-01-09 13:36:29 +00:00
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_DOMAIN_OT_STRING(_helpstr, oflags, cflags) \
|
2018-05-08 14:20:32 +00:00
|
|
|
{.name = "domain", \
|
|
|
|
.type = VSH_OT_STRING, \
|
2018-09-26 07:59:08 +00:00
|
|
|
.flags = oflags, \
|
2018-05-08 14:20:32 +00:00
|
|
|
.help = _helpstr, \
|
|
|
|
.completer = virshDomainNameCompleter, \
|
|
|
|
.completer_flags = cflags, \
|
|
|
|
}
|
|
|
|
|
2019-06-18 16:13:15 +00:00
|
|
|
#define VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(oflags, cflags) \
|
2018-09-26 07:59:08 +00:00
|
|
|
VIRSH_COMMON_OPT_DOMAIN_OT_STRING(N_("domain name, id or uuid"), \
|
|
|
|
oflags, cflags)
|
2018-05-08 14:20:32 +00:00
|
|
|
|
2015-06-15 16:53:58 +00:00
|
|
|
typedef struct _virshControl virshControl;
|
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;
|
2020-02-05 14:16:16 +00: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 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);
|