[libvirt] [PATCH] virsh: pool-info: introduce option --bytes
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)gmail.com>
By default, pool-info will convert sizes to human friendly
units.
This patch will introduce option [--bytes].
If specified, the raw sizes will be in the output.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)gmail.com>
---
tools/virsh-pool.c | 25 +++++++++++++++++++------
tools/virsh.pod | 5 +++--
2 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 8313be8..cbd7042 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -1589,6 +1589,10 @@ static const vshCmdInfo info_pool_info[] = {
static const vshCmdOptDef opts_pool_info[] = {
VIRSH_COMMON_OPT_POOL_FULL,
+ {.name = "bytes",
+ .type = VSH_OT_BOOL,
+ .help = N_("Reture pool info in bytes"),
+ },
{.name = NULL}
};
@@ -1600,11 +1604,14 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
int autostart = 0;
int persistent = 0;
bool ret = true;
+ bool bytes = false;
char uuid[VIR_UUID_STRING_BUFLEN];
if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
return false;
+ bytes = vshCommandOptBool(cmd, "bytes");
+
vshPrint(ctl, "%-15s %s\n", _("Name:"), virStoragePoolGetName(pool));
if (virStoragePoolGetUUIDString(pool, &uuid[0]) == 0)
@@ -1633,14 +1640,20 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
if (info.state == VIR_STORAGE_POOL_RUNNING ||
info.state == VIR_STORAGE_POOL_DEGRADED) {
- val = vshPrettyCapacity(info.capacity, &unit);
- vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
+ if (bytes) {
+ vshPrint(ctl, "%-15s %llu\n", _("Capacity:"), info.capacity);
+ vshPrint(ctl, "%-15s %llu\n", _("Allocation:"), info.allocation);
+ vshPrint(ctl, "%-15s %llu\n", _("Available:"), info.available);
+ } else {
+ val = vshPrettyCapacity(info.capacity, &unit);
+ vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
- val = vshPrettyCapacity(info.allocation, &unit);
- vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
+ val = vshPrettyCapacity(info.allocation, &unit);
+ vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
- val = vshPrettyCapacity(info.available, &unit);
- vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit);
+ val = vshPrettyCapacity(info.available, &unit);
+ vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit);
+ }
}
} else {
ret = false;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index ef91223..7c418a5 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3605,9 +3605,10 @@ except that it does some error checking.
The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment
variables, and defaults to C<vi>.
-=item B<pool-info> I<pool-or-uuid>
+=item B<pool-info> [I<--bytes>] I<pool-or-uuid>
-Returns basic information about the I<pool> object.
+Returns basic information about the I<pool> object. If I<--bytes> is specified the sizes
+of basic info are not converted to human friendly units.
=item B<pool-list> [I<--inactive>] [I<--all>]
[I<--persistent>] [I<--transient>]
--
2.7.4
7 years, 10 months
[libvirt] [PATCH 00/12] vbox: remove support for vbox 3.x and older.
by Dawid Zamirski
Hello,
This series removes support for legacy VirtualBox versions (3.x and
older) that did not have upstream support for a while and won't even
work on any relatively recent distro. The idea for doing this was
first mentioned here [1] and this makes the driver code cleaner as
the APIs for those old versions were quite different from v4.0+ and
required abstractions to handle the differences.
Please note that the first patch in the series is sent to ML as a
compressed attachment because it deletes VirtualBox SDK header files
for those old verions which are large and the patch would not pass ML
message size limit.
[1] https://www.redhat.com/archives/libvir-list/2016-November/msg01133.html
Regards,
Dawid
Dawid Zamirski (12):
vbox: remove SDK header files for vbox 3 and older.
vbox: remove calls to *InstallUniformedAPI macros.
vbox: remove code for old API versions.
vbox: remove _vboxAttachDrivesOld
vbox: do not use IHardDisk anymore.
vbox: remove getMachineForSession flag.
vbox: remove domain events support.
vbox: remove code dealing with oldMediumInterface
vbox: IVRDxServer to IVRDEServer.
vbox: fix _displayTakeScreenShotPNGToArray
vbox: consolidate vbox IID structures.
docs: add news entry in improvements section.
docs/news.html.in | 8 +
src/Makefile.am | 4 -
src/vbox/vbox_CAPI_v2_2.h | 4869 -----------------------------------
src/vbox/vbox_CAPI_v3_0.h | 5396 ---------------------------------------
src/vbox/vbox_CAPI_v3_1.h | 5297 --------------------------------------
src/vbox/vbox_CAPI_v3_2.h | 5625 -----------------------------------------
src/vbox/vbox_V2_2.c | 37 -
src/vbox/vbox_V3_0.c | 37 -
src/vbox/vbox_V3_1.c | 37 -
src/vbox/vbox_V3_2.c | 37 -
src/vbox/vbox_XPCOMCGlue.h | 2 +-
src/vbox/vbox_common.c | 402 +--
src/vbox/vbox_common.h | 13 +-
src/vbox/vbox_network.c | 12 +-
src/vbox/vbox_storage.c | 76 +-
src/vbox/vbox_tmpl.c | 3006 ++--------------------
src/vbox/vbox_uniformed_api.h | 171 +-
17 files changed, 438 insertions(+), 24591 deletions(-)
delete mode 100644 src/vbox/vbox_CAPI_v2_2.h
delete mode 100644 src/vbox/vbox_CAPI_v3_0.h
delete mode 100644 src/vbox/vbox_CAPI_v3_1.h
delete mode 100644 src/vbox/vbox_CAPI_v3_2.h
delete mode 100644 src/vbox/vbox_V2_2.c
delete mode 100644 src/vbox/vbox_V3_0.c
delete mode 100644 src/vbox/vbox_V3_1.c
delete mode 100644 src/vbox/vbox_V3_2.c
--
2.9.3
7 years, 10 months
[libvirt] [PATCH 1/3] rpc: libssh: allow a NULL known_hosts file
by Pino Toscano
Make sure that virNetLibsshSessionSetHostKeyVerification accepts a NULL
value for the path to the known_hosts file:
- call ssh_options_set(SSH_OPTIONS_KNOWNHOSTS) anyway, using /dev/null,
otherwise libssh will use its default path
- do not call ssh_write_knownhost when no known hosts file was set
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1406457
---
src/rpc/virnetlibsshsession.c | 37 +++++++++++++++++++++++--------------
1 file changed, 23 insertions(+), 14 deletions(-)
diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c
index 5de6629..25f93ce 100644
--- a/src/rpc/virnetlibsshsession.c
+++ b/src/rpc/virnetlibsshsession.c
@@ -382,14 +382,16 @@ virNetLibsshCheckHostKey(virNetLibsshSessionPtr sess)
VIR_FREE(askKey.result);
}
- /* write the host key file */
- if (ssh_write_knownhost(sess->session) < 0) {
- errmsg = ssh_get_error(sess->session);
- virReportError(VIR_ERR_LIBSSH,
- _("failed to write known_host file '%s': %s"),
- sess->knownHostsFile,
- errmsg);
- return -1;
+ /* write the host key file, if specified */
+ if (sess->knownHostsFile) {
+ if (ssh_write_knownhost(sess->session) < 0) {
+ errmsg = ssh_get_error(sess->session);
+ virReportError(VIR_ERR_LIBSSH,
+ _("failed to write known_host file '%s': %s"),
+ sess->knownHostsFile,
+ errmsg);
+ return -1;
+ }
}
/* key was accepted and added */
return 0;
@@ -1172,13 +1174,20 @@ virNetLibsshSessionSetHostKeyVerification(virNetLibsshSessionPtr sess,
goto error;
}
- /* set the known hosts file */
- if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, hostsfile) < 0)
- goto error;
+ /* set the known hosts file, if specified */
+ if (hostsfile) {
+ if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, hostsfile) < 0)
+ goto error;
- VIR_FREE(sess->knownHostsFile);
- if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0)
- goto error;
+ VIR_FREE(sess->knownHostsFile);
+ if (VIR_STRDUP(sess->knownHostsFile, hostsfile) < 0)
+ goto error;
+ } else {
+ /* libssh does not support trying no known_host file at all:
+ * hence use /dev/null here, without storing it as file */
+ if (ssh_options_set(sess->session, SSH_OPTIONS_KNOWNHOSTS, "/dev/null") < 0)
+ goto error;
+ }
virObjectUnlock(sess);
return 0;
--
2.7.4
7 years, 10 months
[libvirt] [PATCH] maint: update to latest gnulib
by Eric Blake
Among other recent changes, this includes a workaround to avoid
Clang compiler bug https://llvm.org/bugs/show_bug.cgi?id=16404
having spurious link failures.
* .gnulib: Update.
* bootstrap: Synchronize to upstream.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
I'm debating about re-enabling test-lock (right now, we explicitly
pass --avoid=lock-tests to gnulib-tool via our bootstrap.conf), now
that upstream is finally starting to fix the bugs in the test that
were causing extremely slow completion or outright hangs on
multi-processor setups. But that's probably something better done
right after a libvirt release, not right before a release candidate.
Pushing under the gnulib maintenance rule; contains these gnulib patches:
* .gnulib e210a3c...94386a1 (38):
> maint.mk: enforce spelling of "timestamp" (i.e., no space)
> dfa: minor simplification with emptyset
> dfa: shrink constraints from 4 bits to 3
> dfa: omit unnecessary ptrdiff_t check
> dfa: omit unnecessary allocation
> dfa: omit unused local
> maint: time stamp -> timestamp
> maint: remove stray .texi files
> getprogname: fix port to IRIX
> dfa: melt down dfastate into build_state
> dfa: simplify transition table allocation
> dfa: fix reallocation bug when matching newlines
> Avoid -Wundef warning about undefined WINDOWS_SOCKETS.
> Avoid -Wundef warning about undefined __USE_FILE_OFFSET64.
> stdioext: Port to Minix 3.2 and newer.
> getprogname: port to IRIX
> localename-tests: port to NetBSD 7
> glob, intprops, xalloc: work around Clang bug
> dfa: fix 'return' typo
> lock tests: Prefer semaphore over mutex.
> parse-datetime: fix generated paths for coverage files
> maint.mk: support parallel execution of coverage
> lock: Provide guarantee to avoid writer starvation for rwlocks.
> thread: Fix pth port.
> parse-datetime: fix debug message on lone year number
> parse-datetime: fix local timezone debug messages
> parse-datetime: add debug warning about DST changes
> parse-datetime: add debug warning about date arithmetic
> parse-datetime: fix debug message of relative part after timezone
> parse-datetime: fix incorrect debug message on lone number
> exec
> build-aux/mdate-sh
> doc: fix typo in previous change
> Revert copyright-year change to synced files
> doc: modernize for C11 etc.
> dfa: prefer functions to FETCH_WC macro
> dfa: narrow more local var scopes
> dfa: remove duplicate assignment
.gnulib | 2 +-
bootstrap | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/.gnulib b/.gnulib
index e210a3c..94386a1 160000
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit e210a3cbaec0ee82a67ff8fc427e21bdd64dba1b
+Subproject commit 94386a13667c645fd42544a7fd302cdddd39fcdf
diff --git a/bootstrap b/bootstrap
index 26066b2..932ff85 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,6 +1,6 @@
#! /bin/sh
# Print a version string.
-scriptversion=2016-11-03.18; # UTC
+scriptversion=2017-01-09.19; # UTC
# Bootstrap this package from checked-out sources.
@@ -790,7 +790,7 @@ symlink_to_dir()
# Leave any existing symlink alone, if it already points to the source,
# so that broken build tools that care about symlink times
# aren't confused into doing unnecessary builds. Conversely, if the
- # existing symlink's time stamp is older than the source, make it afresh,
+ # existing symlink's timestamp is older than the source, make it afresh,
# so that broken tools aren't confused into skipping needed builds. See
# <http://lists.gnu.org/archive/html/bug-gnulib/2011-05/msg00326.html>.
test -h "$dst" &&
--
2.9.3
7 years, 10 months
[libvirt] [PATCH v3 0/3] Improve release notes process
by Andrea Bolognani
Dan raised some concerns, but it doesn't look like they're
critical enough for him to NACK the series; moreover, it's
all stuff that we can easily address later on, so I'd like
to move forward with this before the freeze.
Details of changes can be found in the single patches.
Andrea Bolognani (3):
NEWS: Improve building pipeline
NEWS: Reformat at generation time
docs: Document the release notes process for contributors
.gitignore | 1 +
HACKING | 7 ++
Makefile.am | 26 ++++--
docs/Makefile.am | 28 +++++-
docs/hacking.html.in | 10 ++
docs/news-ascii.xsl | 68 ++++++++++++++
docs/news-html.xsl | 96 +++++++++++++++++++
docs/news.html.in | 164 --------------------------------
docs/news.xml | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++
docs/news.xsl | 50 ----------
docs/reformat-news.py | 104 +++++++++++++++++++++
11 files changed, 583 insertions(+), 223 deletions(-)
create mode 100644 docs/news-ascii.xsl
create mode 100644 docs/news-html.xsl
delete mode 100644 docs/news.html.in
create mode 100644 docs/news.xml
delete mode 100644 docs/news.xsl
create mode 100755 docs/reformat-news.py
--
2.7.4
7 years, 10 months
[libvirt] [PATCH 0/2] Couple of build fixes
by Michal Privoznik
Spotted by our CI.
Michal Privoznik (2):
qemu_domain: Move qemuDomainGetPreservedMounts
virSecuritySELinuxSetFileconHelper: Fix build with broken selinux.h
src/qemu/qemu_domain.c | 140 ++++++++++++++++++++--------------------
src/security/security_selinux.c | 2 +-
2 files changed, 71 insertions(+), 71 deletions(-)
--
2.11.0
7 years, 10 months
[libvirt] [PATCH] libxl: implement virDomainGetMaxVcpus
by Jim Fehlig
The libxl driver already supports getting maximum vcpu count via
libxlDomainGetVcpusFlags, allowing to trivially implement
virDomainGetMaxVcpus.
Signed-off-by: Jim Fehlig <jfehlig(a)suse.com>
---
docs/news.html.in | 2 ++
src/libxl/libxl_driver.c | 8 ++++++++
2 files changed, 10 insertions(+)
diff --git a/docs/news.html.in b/docs/news.html.in
index c222075..2365c39 100644
--- a/docs/news.html.in
+++ b/docs/news.html.in
@@ -39,6 +39,8 @@
_virStorageVolInfo structure. The --physical flag has been
added to the virsh vol-info command to access the data
</li>
+ <li>libxl: Implement virDomainGetMaxVcpus API
+ </li>
</ul>
</li>
<li><strong>Improvements</strong>
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 7e5d9b6..51fe3d8 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2363,6 +2363,13 @@ libxlDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
}
static int
+libxlDomainGetMaxVcpus(virDomainPtr dom)
+{
+ return libxlDomainGetVcpusFlags(dom, (VIR_DOMAIN_AFFECT_LIVE |
+ VIR_DOMAIN_VCPU_MAXIMUM));
+}
+
+static int
libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu,
unsigned char *cpumap, int maplen,
unsigned int flags)
@@ -6446,6 +6453,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
.domainSetVcpus = libxlDomainSetVcpus, /* 0.9.0 */
.domainSetVcpusFlags = libxlDomainSetVcpusFlags, /* 0.9.0 */
.domainGetVcpusFlags = libxlDomainGetVcpusFlags, /* 0.9.0 */
+ .domainGetMaxVcpus = libxlDomainGetMaxVcpus, /* 3.0.0 */
.domainPinVcpu = libxlDomainPinVcpu, /* 0.9.0 */
.domainPinVcpuFlags = libxlDomainPinVcpuFlags, /* 1.2.1 */
.domainGetVcpus = libxlDomainGetVcpus, /* 0.9.0 */
--
2.9.2
7 years, 10 months
[libvirt] [PATCH 0/2] replacement for Patches 5/8 & 6/8 of "aggregate multiple pcie-root-ports onto a single slot"
by Laine Stump
During review of the aforementioned series, Andrea expressed
misgivings about patch 6, which automatically set the multifunction=on
option transiently at the time the qemu commandline was generated. Dan
agreed. These two patches replace patches 5 and 6 of that series with
two patches that will set multi='on' in the domain's config rather
than just temporarily in the commandline. This way it will remain set
even if all the devices on the non-0 function are later removed
(unless it's explicitly changed by the user/management app, that is).
The rest of the series is ACKed and ready to push, which I'd like to
do before the freeze on Wednesday; these two patche are all that's
holding it up.
Laine Stump (2):
conf: new function virDomainPCIAddressSetAllMulti()
qemu: use virDomainPCIAddressSetAllMulti() to set multi when needed
src/conf/domain_addr.c | 75 +++++++++++++
src/conf/domain_addr.h | 4 +
src/libvirt_private.syms | 1 +
src/qemu/qemu_domain_address.c | 5 +
.../qemuxml2argv-q35-multifunction.args | 42 ++++++++
.../qemuxml2argv-q35-multifunction.xml | 51 +++++++++
tests/qemuxml2argvtest.c | 23 ++++
.../qemuxml2xmlout-q35-multifunction.xml | 120 +++++++++++++++++++++
tests/qemuxml2xmltest.c | 23 ++++
9 files changed, 344 insertions(+)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-q35-multifunction.xml
create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-q35-multifunction.xml
--
2.7.4
7 years, 10 months
[libvirt] qemu-kvm blocked for more than 120 seconds when "libvirt-guests" is enabled
by Oscar Segarra
Hi,
I just have two virtual machines in my environment, I want them to
gracefully stop when host is powered off gracefully.
Nevertheless, system hangs on shutdown:
[root@vdicnode01 ~]# virsh list
Id Name State
----------------------------------------------------
1 vdicdb01 running
2 vdicone01 running
The configuration:
/usr/libexec/libvirt-guests.sh
URIS=default
ON_BOOT=ignore
ON_SHUTDOWN=shutdown
SHUTDOWN_TIMEOUT=60
PARALLEL_SHUTDOWN=5
START_DELAY=0
BYPASS_CACHE=0
CONNECT_RETRIES=10
RETRIES_SLEEP=1
SYNC_TIME=0
[root@vdicnode01 ~]# cat /etc/libvirt/qemu.conf
user = "oneadmin"
group = "oneadmin"
dynamic_ownership = 0
spice_tls = 0
With libvirt-guests service started:
[root@vdicnode01 ~]# service libvirt-guests status
Redirecting to /bin/systemctl status libvirt-guests.service
● libvirt-guests.service - Suspend Active Libvirt Guests
Loaded: loaded (/usr/lib/systemd/system/libvirt-guests.service;
disabled; vendor preset: disabled)
Active: active (exited) since Sat 2016-12-31 17:13:34 CET; 5s ago
Docs: man:libvirtd(8)
http://libvirt.org
Process: 6619 ExecStart=/usr/libexec/libvirt-guests.sh start
(code=exited, status=0/SUCCESS)
Main PID: 6619 (code=exited, status=0/SUCCESS)
Dec 31 17:13:34 vdicnode01.vdicube.com systemd[1]: Starting Suspend Active
Libvirt Guests...
Dec 31 17:13:34 vdicnode01.vdicube.com libvirt-guests.sh[6619]:
libvirt-guests is configured not to start any guests on boot
Dec 31 17:13:34 vdicnode01.vdicube.com systemd[1]: Started Suspend Active
Libvirt Guests.
[root@vdicnode01 ~]#
If I stop locally libvirt-guests (as root) Looks work perfectly:
[root@vdicnode01 ~]# virsh list
Id Name State
----------------------------------------------------
[root@vdicnode01 ~]#
--> Now I start again the virtual machines and the libvirt-guests service
<--
[root@vdicnode01 ~]# service libvirtd restart
Redirecting to /bin/systemctl restart libvirtd.service
[root@vdicnode01 ~]# service libvirt-guests start
Redirecting to /bin/systemctl start libvirt-guests.service
[root@vdicnode01 ~]# virsh list
Id Name State
----------------------------------------------------
1 vdicone01 running
2 vdicdb01 running
[root@vdicnode01 ~]#
But If I shutdown the host it look not work properly (I attack screenshots
of the shutdown process).
Any help will be welcome.
Thanks a lot.
7 years, 10 months
[libvirt] [PATCH] storage: Fix storage_backend probing when PARTED not installed.
by John Ferlan
Commit id 'a48c674f' caused problems for systems without PARTED installed.
So move the PARTED probing code back to storage_backend_disk.c and create
a shim within storage_backend.c to call it if WITH_STORAGE_DISK is true;
otherwise, just return -1 with the error.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
Reported to me internally via Peter Krempa... Not pushing as a build
breaker - I'll let Peter review and ACK.
src/storage/storage_backend.c | 155 ++++---------------------------------
src/storage/storage_backend_disk.c | 152 ++++++++++++++++++++++++++++++++++++
src/storage/storage_backend_disk.h | 3 +
3 files changed, 169 insertions(+), 141 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 060b1c0..18433e9 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2851,157 +2851,30 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
#endif /* #if WITH_BLKID */
-typedef enum {
- VIR_STORAGE_PARTED_ERROR = -1,
- VIR_STORAGE_PARTED_MATCH, /* Valid label found and matches format */
- VIR_STORAGE_PARTED_DIFFERENT, /* Valid label found but not match format */
- VIR_STORAGE_PARTED_UNKNOWN, /* No or unrecognized label */
- VIR_STORAGE_PARTED_NOPTTYPE, /* Did not find the Partition Table type */
- VIR_STORAGE_PARTED_PTTYPE_UNK, /* Partition Table type unknown*/
-} virStorageBackendPARTEDResult;
-
-/**
- * Check for a valid disk label (partition table) on device using
- * the PARTED command
- *
- * returns virStorageBackendPARTEDResult
- */
-static virStorageBackendPARTEDResult
-virStorageBackendPARTEDFindLabel(const char *device,
- const char *format)
-{
- const char *const args[] = {
- device, "print", "--script", NULL,
- };
- virCommandPtr cmd = virCommandNew(PARTED);
- char *output = NULL;
- char *error = NULL;
- char *start, *end;
- int ret = VIR_STORAGE_PARTED_ERROR;
-
- virCommandAddArgSet(cmd, args);
- virCommandAddEnvString(cmd, "LC_ALL=C");
- virCommandSetOutputBuffer(cmd, &output);
- virCommandSetErrorBuffer(cmd, &error);
-
- /* if parted succeeds we have a valid partition table */
- ret = virCommandRun(cmd, NULL);
- if (ret < 0) {
- if ((output && strstr(output, "unrecognised disk label")) ||
- (error && strstr(error, "unrecognised disk label"))) {
- ret = VIR_STORAGE_PARTED_UNKNOWN;
- }
- goto cleanup;
- }
-
- /* Search for "Partition Table:" in the output. If not present,
- * then we cannot validate the partition table type.
- */
- if (!(start = strstr(output, "Partition Table: ")) ||
- !(end = strstr(start, "\n"))) {
- VIR_DEBUG("Unable to find tag in output: %s", output);
- ret = VIR_STORAGE_PARTED_NOPTTYPE;
- goto cleanup;
- }
- start += strlen("Partition Table: ");
- *end = '\0';
-
- /* on disk it's "msdos", but we document/use "dos" so deal with it here */
- if (STREQ(start, "msdos"))
- start += 2;
-
- /* Make sure we know about this type */
- if (virStoragePoolFormatDiskTypeFromString(start) < 0) {
- ret = VIR_STORAGE_PARTED_PTTYPE_UNK;
- goto cleanup;
- }
-
- /* Does the on disk match what the pool desired? */
- if (STREQ(start, format))
- ret = VIR_STORAGE_PARTED_MATCH;
-
- ret = VIR_STORAGE_PARTED_DIFFERENT;
-
- cleanup:
- virCommandFree(cmd);
- VIR_FREE(output);
- VIR_FREE(error);
- return ret;
-}
-
+#if WITH_STORAGE_DISK
-/**
- * Determine whether the label on the disk is valid or in a known format
- * for the purpose of rewriting the label during build or being able to
- * start a pool on a device.
- *
- * When 'writelabel' is true, if we find a valid disk label on the device,
- * then we shouldn't be attempting to write as the volume may contain
- * data. Force the usage of the overwrite flag to the build command in
- * order to be certain. When the disk label is unrecognized, then it
- * should be safe to write.
- *
- * When 'writelabel' is false, only if we find a valid disk label on the
- * device should we allow the start since for this path we won't be
- * rewriting the label.
- *
- * Return: 0 if it's OK
- * -1 if something's wrong
- */
static int
virStorageBackendPARTEDValidLabel(const char *device,
const char *format,
bool writelabel)
{
- int ret = -1;
- virStorageBackendPARTEDResult check;
-
- check = virStorageBackendPARTEDFindLabel(device, format);
- switch (check) {
- case VIR_STORAGE_PARTED_ERROR:
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("Error checking for disk label, failed to get "
- "disk partition information"));
- break;
-
- case VIR_STORAGE_PARTED_MATCH:
- if (writelabel)
- virReportError(VIR_ERR_OPERATION_INVALID,
- _("Disk label already formatted using '%s'"),
- format);
- else
- ret = 0;
- break;
-
- case VIR_STORAGE_PARTED_DIFFERENT:
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("Known, but different label format present, "
- "requires build --overwrite"));
- break;
-
- case VIR_STORAGE_PARTED_UNKNOWN:
- if (writelabel)
- ret = 0;
- else
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("Unrecognized disk label found, requires build"));
- break;
-
- case VIR_STORAGE_PARTED_NOPTTYPE:
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("Unable to determine Partition Type, "
- "requires build --overwrite"));
- break;
+ return virStorageBackendDiskValidLabel(device, format, writelabel);
+}
- case VIR_STORAGE_PARTED_PTTYPE_UNK:
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("Unknown Partition Type, requires build --overwrite"));
- break;
- }
+#else
- return ret;
+static int
+virStorageBackendPARTEDValidLabel(const char *device ATTRIBUTE_UNUSED,
+ const char *format ATTRIBUTE_UNUSED,
+ bool writelabel ATTRIBUTE_UNUSED)
+{
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("PARTED is unsupported by this build"));
+ return -1;
}
+#endif /* #if WITH_STORAGE_DISK */
+
/* virStorageBackendDeviceIsEmpty:
* @devpath: Path to the device to check
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index eae6c90..04ffc6c 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -418,6 +418,158 @@ virStorageBackendDiskRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
}
+typedef enum {
+ VIR_STORAGE_PARTED_ERROR = -1,
+ VIR_STORAGE_PARTED_MATCH, /* Valid label found and matches format */
+ VIR_STORAGE_PARTED_DIFFERENT, /* Valid label found but not match format */
+ VIR_STORAGE_PARTED_UNKNOWN, /* No or unrecognized label */
+ VIR_STORAGE_PARTED_NOPTTYPE, /* Did not find the Partition Table type */
+ VIR_STORAGE_PARTED_PTTYPE_UNK, /* Partition Table type unknown*/
+} virStorageBackendPARTEDResult;
+
+/**
+ * Check for a valid disk label (partition table) on device using
+ * the PARTED command
+ *
+ * returns virStorageBackendPARTEDResult
+ */
+static virStorageBackendPARTEDResult
+virStorageBackendPARTEDFindLabel(const char *device,
+ const char *format)
+{
+ const char *const args[] = {
+ device, "print", "--script", NULL,
+ };
+ virCommandPtr cmd = virCommandNew(PARTED);
+ char *output = NULL;
+ char *error = NULL;
+ char *start, *end;
+ int ret = VIR_STORAGE_PARTED_ERROR;
+
+ virCommandAddArgSet(cmd, args);
+ virCommandAddEnvString(cmd, "LC_ALL=C");
+ virCommandSetOutputBuffer(cmd, &output);
+ virCommandSetErrorBuffer(cmd, &error);
+
+ /* if parted succeeds we have a valid partition table */
+ ret = virCommandRun(cmd, NULL);
+ if (ret < 0) {
+ if ((output && strstr(output, "unrecognised disk label")) ||
+ (error && strstr(error, "unrecognised disk label"))) {
+ ret = VIR_STORAGE_PARTED_UNKNOWN;
+ }
+ goto cleanup;
+ }
+
+ /* Search for "Partition Table:" in the output. If not present,
+ * then we cannot validate the partition table type.
+ */
+ if (!(start = strstr(output, "Partition Table: ")) ||
+ !(end = strstr(start, "\n"))) {
+ VIR_DEBUG("Unable to find tag in output: %s", output);
+ ret = VIR_STORAGE_PARTED_NOPTTYPE;
+ goto cleanup;
+ }
+ start += strlen("Partition Table: ");
+ *end = '\0';
+
+ /* on disk it's "msdos", but we document/use "dos" so deal with it here */
+ if (STREQ(start, "msdos"))
+ start += 2;
+
+ /* Make sure we know about this type */
+ if (virStoragePoolFormatDiskTypeFromString(start) < 0) {
+ ret = VIR_STORAGE_PARTED_PTTYPE_UNK;
+ goto cleanup;
+ }
+
+ /* Does the on disk match what the pool desired? */
+ if (STREQ(start, format))
+ ret = VIR_STORAGE_PARTED_MATCH;
+
+ ret = VIR_STORAGE_PARTED_DIFFERENT;
+
+ cleanup:
+ virCommandFree(cmd);
+ VIR_FREE(output);
+ VIR_FREE(error);
+ return ret;
+}
+
+
+/**
+ * Determine whether the label on the disk is valid or in a known format
+ * for the purpose of rewriting the label during build or being able to
+ * start a pool on a device.
+ *
+ * When 'writelabel' is true, if we find a valid disk label on the device,
+ * then we shouldn't be attempting to write as the volume may contain
+ * data. Force the usage of the overwrite flag to the build command in
+ * order to be certain. When the disk label is unrecognized, then it
+ * should be safe to write.
+ *
+ * When 'writelabel' is false, only if we find a valid disk label on the
+ * device should we allow the start since for this path we won't be
+ * rewriting the label.
+ *
+ * Return: 0 if it's OK
+ * -1 if something's wrong
+ */
+int
+virStorageBackendDiskValidLabel(const char *device,
+ const char *format,
+ bool writelabel)
+{
+ int ret = -1;
+ virStorageBackendPARTEDResult check;
+
+ check = virStorageBackendPARTEDFindLabel(device, format);
+ switch (check) {
+ case VIR_STORAGE_PARTED_ERROR:
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Error checking for disk label, failed to get "
+ "disk partition information"));
+ break;
+
+ case VIR_STORAGE_PARTED_MATCH:
+ if (writelabel)
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("Disk label already formatted using '%s'"),
+ format);
+ else
+ ret = 0;
+ break;
+
+ case VIR_STORAGE_PARTED_DIFFERENT:
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Known, but different label format present, "
+ "requires build --overwrite"));
+ break;
+
+ case VIR_STORAGE_PARTED_UNKNOWN:
+ if (writelabel)
+ ret = 0;
+ else
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Unrecognized disk label found, requires build"));
+ break;
+
+ case VIR_STORAGE_PARTED_NOPTTYPE:
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Unable to determine Partition Type, "
+ "requires build --overwrite"));
+ break;
+
+ case VIR_STORAGE_PARTED_PTTYPE_UNK:
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("Unknown Partition Type, requires build --overwrite"));
+ break;
+ }
+
+ return ret;
+}
+
+
static int
virStorageBackendDiskStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
virStoragePoolObjPtr pool)
diff --git a/src/storage/storage_backend_disk.h b/src/storage/storage_backend_disk.h
index aaabe62..79c0e6b 100644
--- a/src/storage/storage_backend_disk.h
+++ b/src/storage/storage_backend_disk.h
@@ -28,4 +28,7 @@
extern virStorageBackend virStorageBackendDisk;
+int virStorageBackendDiskValidLabel(const char *device,
+ const char *format,
+ bool writelabel);
#endif /* __VIR_STORAGE_BACKEND_DISK_H__ */
--
2.7.4
7 years, 10 months