|
|
0882396 |
From 5a6f9558a980c6c7d3d08379edcde85dd85b5190 Mon Sep 17 00:00:00 2001
|
|
|
0882396 |
From: Richard Jones <rjones@redhat.com>
|
|
|
0882396 |
Date: Fri, 30 Jul 2010 16:32:35 +0100
|
|
|
0882396 |
Subject: [PATCH] New API: is-lv: check if a block device is a logical volume (RHBZ#619793)
|
|
|
0882396 |
|
|
|
0882396 |
This adds a new API, guestfs_is_lv (g, device), which returns true iff
|
|
|
0882396 |
the named device is an LVM2 logical volume.
|
|
|
0882396 |
|
|
|
0882396 |
A sample guestfish session:
|
|
|
0882396 |
|
|
|
0882396 |
><fs> lvs
|
|
|
0882396 |
/dev/vg_f13x64/lv_root
|
|
|
0882396 |
/dev/vg_f13x64/lv_swap
|
|
|
0882396 |
><fs> list-devices
|
|
|
0882396 |
/dev/vda
|
|
|
0882396 |
><fs> list-partitions
|
|
|
0882396 |
/dev/vda1
|
|
|
0882396 |
/dev/vda2
|
|
|
0882396 |
><fs> is-lv /dev/vg_f13x64/lv_root
|
|
|
0882396 |
true
|
|
|
0882396 |
><fs> is-lv /dev/vg_f13x64/lv_swap
|
|
|
0882396 |
true
|
|
|
0882396 |
><fs> is-lv /dev/vda
|
|
|
0882396 |
false
|
|
|
0882396 |
><fs> is-lv /dev/vda1
|
|
|
0882396 |
false
|
|
|
0882396 |
><fs> is-lv /dev/vda2
|
|
|
0882396 |
false
|
|
|
0882396 |
(cherry picked from commit 6280ac9b987c14f89749b4b4fdfec5a647567432)
|
|
|
0882396 |
---
|
|
|
0882396 |
daemon/lvm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
0882396 |
src/MAX_PROC_NR | 2 +-
|
|
|
0882396 |
src/generator.ml | 10 ++++++++++
|
|
|
0882396 |
3 files changed, 58 insertions(+), 1 deletions(-)
|
|
|
0882396 |
|
|
|
0882396 |
diff --git a/daemon/lvm.c b/daemon/lvm.c
|
|
|
0882396 |
index 70c3c90..0df27e2 100644
|
|
|
0882396 |
--- a/daemon/lvm.c
|
|
|
0882396 |
+++ b/daemon/lvm.c
|
|
|
0882396 |
@@ -23,6 +23,7 @@
|
|
|
0882396 |
#include <inttypes.h>
|
|
|
0882396 |
#include <string.h>
|
|
|
0882396 |
#include <unistd.h>
|
|
|
0882396 |
+#include <sys/stat.h>
|
|
|
0882396 |
|
|
|
0882396 |
#include "daemon.h"
|
|
|
0882396 |
#include "c-ctype.h"
|
|
|
0882396 |
@@ -662,3 +663,49 @@ do_vgscan (void)
|
|
|
0882396 |
free (err);
|
|
|
0882396 |
return 0;
|
|
|
0882396 |
}
|
|
|
0882396 |
+
|
|
|
0882396 |
+/* Test if a device is a logical volume (RHBZ#619793).
|
|
|
0882396 |
+ *
|
|
|
0882396 |
+ * This is harder than it should be. A LV device like /dev/VG/LV is
|
|
|
0882396 |
+ * really a symlink to a device-mapper device like /dev/dm-0. However
|
|
|
0882396 |
+ * at the device-mapper (kernel) level, nothing is really known about
|
|
|
0882396 |
+ * LVM (a userspace concept). Therefore we use a convoluted method to
|
|
|
0882396 |
+ * determine this, by listing out known LVs and checking whether the
|
|
|
0882396 |
+ * rdev (major/minor) of the device we are passed matches any of them.
|
|
|
0882396 |
+ *
|
|
|
0882396 |
+ * Note use of 'stat' instead of 'lstat' so that symlinks are fully
|
|
|
0882396 |
+ * resolved.
|
|
|
0882396 |
+ */
|
|
|
0882396 |
+int
|
|
|
0882396 |
+do_is_lv (const char *device)
|
|
|
0882396 |
+{
|
|
|
0882396 |
+ struct stat stat1, stat2;
|
|
|
0882396 |
+
|
|
|
0882396 |
+ int r = stat (device, &stat1);
|
|
|
0882396 |
+ if (r == -1) {
|
|
|
0882396 |
+ reply_with_perror ("stat: %s", device);
|
|
|
0882396 |
+ return -1;
|
|
|
0882396 |
+ }
|
|
|
0882396 |
+
|
|
|
0882396 |
+ char **lvs = do_lvs ();
|
|
|
0882396 |
+ if (lvs == NULL)
|
|
|
0882396 |
+ return -1;
|
|
|
0882396 |
+
|
|
|
0882396 |
+ size_t i;
|
|
|
0882396 |
+ for (i = 0; lvs[i] != NULL; ++i) {
|
|
|
0882396 |
+ r = stat (lvs[i], &stat2);
|
|
|
0882396 |
+ if (r == -1) {
|
|
|
0882396 |
+ reply_with_perror ("stat: %s", lvs[i]);
|
|
|
0882396 |
+ free_strings (lvs);
|
|
|
0882396 |
+ return -1;
|
|
|
0882396 |
+ }
|
|
|
0882396 |
+ if (stat1.st_rdev == stat2.st_rdev) { /* found it */
|
|
|
0882396 |
+ free_strings (lvs);
|
|
|
0882396 |
+ return 1;
|
|
|
0882396 |
+ }
|
|
|
0882396 |
+ }
|
|
|
0882396 |
+
|
|
|
0882396 |
+ /* not found */
|
|
|
0882396 |
+ free_strings (lvs);
|
|
|
0882396 |
+ return 0;
|
|
|
0882396 |
+}
|
|
|
0882396 |
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
|
|
|
0882396 |
index 175b6c5..10b0c0d 100644
|
|
|
0882396 |
--- a/src/MAX_PROC_NR
|
|
|
0882396 |
+++ b/src/MAX_PROC_NR
|
|
|
0882396 |
@@ -1 +1 @@
|
|
|
0882396 |
-263
|
|
|
0882396 |
+264
|
|
|
0882396 |
diff --git a/src/generator.ml b/src/generator.ml
|
|
|
0882396 |
index 8675828..b5da6cf 100755
|
|
|
0882396 |
--- a/src/generator.ml
|
|
|
0882396 |
+++ b/src/generator.ml
|
|
|
0882396 |
@@ -4953,6 +4953,16 @@ This command deletes the key in key slot C<keyslot> from the
|
|
|
0882396 |
encrypted LUKS device C<device>. C<key> must be one of the
|
|
|
0882396 |
I<other> keys.");
|
|
|
0882396 |
|
|
|
0882396 |
+ ("is_lv", (RBool "lvflag", [Device "device"]), 264, [Optional "lvm2"],
|
|
|
0882396 |
+ [InitBasicFSonLVM, IfAvailable "lvm2", TestOutputTrue (
|
|
|
0882396 |
+ [["is_lv"; "/dev/VG/LV"]]);
|
|
|
0882396 |
+ InitBasicFSonLVM, IfAvailable "lvm2", TestOutputFalse (
|
|
|
0882396 |
+ [["is_lv"; "/dev/sda1"]])],
|
|
|
0882396 |
+ "test if device is a logical volume",
|
|
|
0882396 |
+ "\
|
|
|
0882396 |
+This command tests whether C<device> is a logical volume, and
|
|
|
0882396 |
+returns true iff this is the case.");
|
|
|
0882396 |
+
|
|
|
0882396 |
]
|
|
|
0882396 |
|
|
|
0882396 |
let all_functions = non_daemon_functions @ daemon_functions
|
|
|
0882396 |
--
|
|
|
0882396 |
1.7.1
|
|
|
0882396 |
|