|
|
e76f14 |
From 97add8b77aebc8032b7d186f36e264e1d9ffa733 Mon Sep 17 00:00:00 2001
|
|
|
e76f14 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
e76f14 |
Date: Fri, 24 Jun 2016 15:28:46 +0100
|
|
|
e76f14 |
Subject: [PATCH] p2v: Display serial number of fixed disks (RHBZ#855058).
|
|
|
e76f14 |
|
|
|
e76f14 |
Use "lsblk -o serial" to get the serial number of each fixed disk, and
|
|
|
e76f14 |
if it is available display that in the GUI.
|
|
|
e76f14 |
|
|
|
e76f14 |
(cherry picked from commit 9270a27650abaf586070c51cb90b6a77ec13e0cf)
|
|
|
e76f14 |
---
|
|
|
e76f14 |
p2v/dependencies.m4 | 8 ++++----
|
|
|
e76f14 |
p2v/gui.c | 8 ++++++--
|
|
|
e76f14 |
p2v/p2v.h | 1 +
|
|
|
e76f14 |
p2v/utils.c | 34 ++++++++++++++++++++++++++++++++++
|
|
|
e76f14 |
p2v/virt-p2v.pod | 2 ++
|
|
|
e76f14 |
5 files changed, 47 insertions(+), 6 deletions(-)
|
|
|
e76f14 |
|
|
|
e76f14 |
diff --git a/p2v/dependencies.m4 b/p2v/dependencies.m4
|
|
|
e76f14 |
index 6cf2961..80d6c92 100644
|
|
|
e76f14 |
--- a/p2v/dependencies.m4
|
|
|
e76f14 |
+++ b/p2v/dependencies.m4
|
|
|
e76f14 |
@@ -30,6 +30,7 @@ ifelse(REDHAT,1,
|
|
|
e76f14 |
/usr/bin/qemu-nbd
|
|
|
e76f14 |
curl
|
|
|
e76f14 |
ethtool
|
|
|
e76f14 |
+ util-linux
|
|
|
e76f14 |
|
|
|
e76f14 |
dnl The hwdata package contains PCI IDs, used by virt-p2v to display
|
|
|
e76f14 |
dnl network vendor information (RHBZ#855059).
|
|
|
e76f14 |
@@ -39,7 +40,6 @@ ifelse(REDHAT,1,
|
|
|
e76f14 |
pciutils
|
|
|
e76f14 |
hdparm
|
|
|
e76f14 |
smartmontools
|
|
|
e76f14 |
- util-linux
|
|
|
e76f14 |
|
|
|
e76f14 |
dnl X11 environment
|
|
|
e76f14 |
xterm
|
|
|
e76f14 |
@@ -72,11 +72,11 @@ ifelse(DEBIAN,1,
|
|
|
e76f14 |
qemu-utils
|
|
|
e76f14 |
curl
|
|
|
e76f14 |
ethtool
|
|
|
e76f14 |
+ util-linux
|
|
|
e76f14 |
hwdata
|
|
|
e76f14 |
pciutils
|
|
|
e76f14 |
hdparm
|
|
|
e76f14 |
smartmontools
|
|
|
e76f14 |
- util-linux
|
|
|
e76f14 |
xorg
|
|
|
e76f14 |
xterm
|
|
|
e76f14 |
xserver-xorg-video-all
|
|
|
e76f14 |
@@ -97,11 +97,11 @@ ifelse(ARCHLINUX,1,
|
|
|
e76f14 |
qemu
|
|
|
e76f14 |
curl
|
|
|
e76f14 |
ethtool
|
|
|
e76f14 |
+ util-linux
|
|
|
e76f14 |
hwdata
|
|
|
e76f14 |
pciutils
|
|
|
e76f14 |
hdparm
|
|
|
e76f14 |
smartmontools
|
|
|
e76f14 |
- util-linux
|
|
|
e76f14 |
xterm
|
|
|
e76f14 |
xorg-xinit
|
|
|
e76f14 |
xorg-server
|
|
|
e76f14 |
@@ -123,11 +123,11 @@ ifelse(SUSE,1,
|
|
|
e76f14 |
openssh
|
|
|
e76f14 |
curl
|
|
|
e76f14 |
ethtool
|
|
|
e76f14 |
+ util-linux
|
|
|
e76f14 |
hwdata
|
|
|
e76f14 |
pciutils
|
|
|
e76f14 |
hdparm
|
|
|
e76f14 |
smartmontools
|
|
|
e76f14 |
- util-linux
|
|
|
e76f14 |
xinit
|
|
|
e76f14 |
xorg-x11-server
|
|
|
e76f14 |
xterm
|
|
|
e76f14 |
diff --git a/p2v/gui.c b/p2v/gui.c
|
|
|
e76f14 |
index 49c703d..58e9ea3 100644
|
|
|
e76f14 |
--- a/p2v/gui.c
|
|
|
e76f14 |
+++ b/p2v/gui.c
|
|
|
e76f14 |
@@ -868,6 +868,7 @@ populate_disks (GtkTreeView *disks_list)
|
|
|
e76f14 |
uint64_t size;
|
|
|
e76f14 |
CLEANUP_FREE char *size_gb = NULL;
|
|
|
e76f14 |
CLEANUP_FREE char *model = NULL;
|
|
|
e76f14 |
+ CLEANUP_FREE char *serial = NULL;
|
|
|
e76f14 |
CLEANUP_FREE char *device_descr = NULL;
|
|
|
e76f14 |
|
|
|
e76f14 |
if (all_disks[i][0] != '/') { /* not using --test-disk */
|
|
|
e76f14 |
@@ -875,15 +876,18 @@ populate_disks (GtkTreeView *disks_list)
|
|
|
e76f14 |
if (asprintf (&size_gb, "%" PRIu64 "G", size) == -1)
|
|
|
e76f14 |
error (EXIT_FAILURE, errno, "asprintf");
|
|
|
e76f14 |
model = get_blockdev_model (all_disks[i]);
|
|
|
e76f14 |
+ serial = get_blockdev_serial (all_disks[i]);
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
if (asprintf (&device_descr,
|
|
|
e76f14 |
"%s\n"
|
|
|
e76f14 |
"<small>"
|
|
|
e76f14 |
- "%s %s"
|
|
|
e76f14 |
+ "%s %s\n"
|
|
|
e76f14 |
+ "%s%s"
|
|
|
e76f14 |
"</small>\n",
|
|
|
e76f14 |
all_disks[i],
|
|
|
e76f14 |
- size_gb ? size_gb : "", model ? model : "") == -1)
|
|
|
e76f14 |
+ size_gb ? size_gb : "", model ? model : "",
|
|
|
e76f14 |
+ serial ? "s/n " : "", serial ? serial : "") == -1)
|
|
|
e76f14 |
error (EXIT_FAILURE, errno, "asprintf");
|
|
|
e76f14 |
|
|
|
e76f14 |
gtk_list_store_append (disks_store, &iter);
|
|
|
e76f14 |
diff --git a/p2v/p2v.h b/p2v/p2v.h
|
|
|
e76f14 |
index 40b05b8..3e75690 100644
|
|
|
e76f14 |
--- a/p2v/p2v.h
|
|
|
e76f14 |
+++ b/p2v/p2v.h
|
|
|
e76f14 |
@@ -133,6 +133,7 @@ extern const char *get_ssh_error (void);
|
|
|
e76f14 |
/* utils.c */
|
|
|
e76f14 |
extern uint64_t get_blockdev_size (const char *dev);
|
|
|
e76f14 |
extern char *get_blockdev_model (const char *dev);
|
|
|
e76f14 |
+extern char *get_blockdev_serial (const char *dev);
|
|
|
e76f14 |
extern char *get_if_addr (const char *if_name);
|
|
|
e76f14 |
extern char *get_if_vendor (const char *if_name, int truncate);
|
|
|
e76f14 |
extern void wait_network_online (const struct config *);
|
|
|
e76f14 |
diff --git a/p2v/utils.c b/p2v/utils.c
|
|
|
e76f14 |
index 18c2b7c..c9fbd2f 100644
|
|
|
e76f14 |
--- a/p2v/utils.c
|
|
|
e76f14 |
+++ b/p2v/utils.c
|
|
|
e76f14 |
@@ -103,6 +103,40 @@ get_blockdev_model (const char *dev)
|
|
|
e76f14 |
return model;
|
|
|
e76f14 |
}
|
|
|
e76f14 |
|
|
|
e76f14 |
+/**
|
|
|
e76f14 |
+ * Return the serial number of a block device.
|
|
|
e76f14 |
+ *
|
|
|
e76f14 |
+ * This is found using the lsblk command.
|
|
|
e76f14 |
+ *
|
|
|
e76f14 |
+ * Returns C<NULL> if we could not get the serial number. The caller
|
|
|
e76f14 |
+ * must free the returned string.
|
|
|
e76f14 |
+ */
|
|
|
e76f14 |
+char *
|
|
|
e76f14 |
+get_blockdev_serial (const char *dev)
|
|
|
e76f14 |
+{
|
|
|
e76f14 |
+ CLEANUP_PCLOSE FILE *fp = NULL;
|
|
|
e76f14 |
+ CLEANUP_FREE char *cmd = NULL;
|
|
|
e76f14 |
+ char *serial = NULL;
|
|
|
e76f14 |
+ size_t len = 0;
|
|
|
e76f14 |
+ ssize_t n;
|
|
|
e76f14 |
+
|
|
|
e76f14 |
+ if (asprintf (&cmd, "lsblk -o serial /dev/%s --nodeps --noheadings",
|
|
|
e76f14 |
+ dev) == -1)
|
|
|
e76f14 |
+ error (EXIT_FAILURE, errno, "asprintf");
|
|
|
e76f14 |
+ fp = popen (cmd, "r");
|
|
|
e76f14 |
+ if (fp == NULL) {
|
|
|
e76f14 |
+ perror (cmd);
|
|
|
e76f14 |
+ return NULL;
|
|
|
e76f14 |
+ }
|
|
|
e76f14 |
+ if ((n = getline (&serial, &len, fp)) == -1) {
|
|
|
e76f14 |
+ perror (cmd);
|
|
|
e76f14 |
+ free (serial);
|
|
|
e76f14 |
+ return NULL;
|
|
|
e76f14 |
+ }
|
|
|
e76f14 |
+ CHOMP (serial, n);
|
|
|
e76f14 |
+ return serial;
|
|
|
e76f14 |
+}
|
|
|
e76f14 |
+
|
|
|
e76f14 |
/* Return contents of /sys/class/net/<if_name>/address (if found). */
|
|
|
e76f14 |
char *
|
|
|
e76f14 |
get_if_addr (const char *if_name)
|
|
|
e76f14 |
diff --git a/p2v/virt-p2v.pod b/p2v/virt-p2v.pod
|
|
|
e76f14 |
index 032a480..421925f 100644
|
|
|
e76f14 |
--- a/p2v/virt-p2v.pod
|
|
|
e76f14 |
+++ b/p2v/virt-p2v.pod
|
|
|
e76f14 |
@@ -197,8 +197,10 @@ settings is fine.
|
|
|
e76f14 |
Convert Device │
|
|
|
e76f14 |
[✔] sda │
|
|
|
e76f14 |
1024G HITACHI │
|
|
|
e76f14 |
+ s/n 12345 │
|
|
|
e76f14 |
[✔] sdb │
|
|
|
e76f14 |
119G HITACHI │
|
|
|
e76f14 |
+ s/n 12346 │
|
|
|
e76f14 |
│
|
|
|
e76f14 |
|
|
|
e76f14 |
Normally you would want to convert all hard disks. If you want
|
|
|
e76f14 |
--
|
|
|
e76f14 |
1.8.3.1
|
|
|
e76f14 |
|