master - dmeventd: fifo init and close cleanup
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6dae2373034ce3...
Commit: 6dae2373034ce3fc11f226c963d81a670043191a
Parent: fc9d4dd11f2331e056f0b56274877c8a4b4b1570
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 28 12:21:06 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:43:14 2013 +0100
dmeventd: fifo init and close cleanup
Use structure initialization for easier to read code.
Close only descriptors >= 0.
---
daemons/dmeventd/dmeventd.c | 8 +++++-
daemons/dmeventd/libdevmapper-event.c | 48 ++++++++++++++++----------------
2 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 189d1b6..301c5f5 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1826,7 +1826,13 @@ static void _daemonize(void)
static void restart(void)
{
- struct dm_event_fifos fifos = { 0 };
+ struct dm_event_fifos fifos = {
+ .server = -1,
+ .client = -1,
+ /* FIXME Make these either configurable or depend directly on dmeventd_path */
+ .client_path = DM_EVENT_FIFO_CLIENT,
+ .server_path = DM_EVENT_FIFO_SERVER
+ };
struct dm_event_daemon_message msg = { 0 };
int i, count = 0;
char *message;
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 92e9c1d..9e8911e 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -468,10 +468,6 @@ int init_fifos(struct dm_event_fifos *fifos)
/* FIXME? Is fifo the most suitable method? Why not share
comms/daemon code with something else e.g. multipath? */
- /* FIXME Make these either configurable or depend directly on dmeventd_path */
- fifos->client_path = DM_EVENT_FIFO_CLIENT;
- fifos->server_path = DM_EVENT_FIFO_SERVER;
-
/* Open the fifo used to read from the daemon. */
if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) {
log_sys_error("open", fifos->server_path);
@@ -481,32 +477,27 @@ int init_fifos(struct dm_event_fifos *fifos)
/* Lock out anyone else trying to do communication with the daemon. */
if (flock(fifos->server, LOCK_EX) < 0) {
log_sys_error("flock", fifos->server_path);
- if (close(fifos->server))
- log_sys_error("close", fifos->server_path);
- return 0;
+ goto bad;
}
/* if ((fifos->client = open(fifos->client_path, O_WRONLY | O_NONBLOCK)) < 0) {*/
if ((fifos->client = open(fifos->client_path, O_RDWR | O_NONBLOCK)) < 0) {
log_sys_error("open", fifos->client_path);
- if (close(fifos->server))
- log_sys_error("close", fifos->server_path);
- return 0;
+ goto bad;
}
return 1;
+bad:
+ if (close(fifos->server))
+ log_sys_debug("close", fifos->server_path);
+ fifos->server = -1;
+
+ return 0;
}
/* Initialize client. */
static int _init_client(char *dmeventd_path, struct dm_event_fifos *fifos)
{
- /* init fifos */
- memset(fifos, 0, sizeof(*fifos));
-
- /* FIXME Make these either configurable or depend directly on dmeventd_path */
- fifos->client_path = DM_EVENT_FIFO_CLIENT;
- fifos->server_path = DM_EVENT_FIFO_SERVER;
-
if (!_start_daemon(dmeventd_path, fifos))
return_0;
@@ -515,13 +506,16 @@ static int _init_client(char *dmeventd_path, struct dm_event_fifos *fifos)
void fini_fifos(struct dm_event_fifos *fifos)
{
- if (flock(fifos->server, LOCK_UN))
- log_error("flock unlock %s", fifos->server_path);
-
- if (close(fifos->client))
+ if (fifos->client >= 0 && close(fifos->client))
log_sys_error("close", fifos->client_path);
- if (close(fifos->server))
- log_sys_error("close", fifos->server_path);
+
+ if (fifos->server >= 0) {
+ if (flock(fifos->server, LOCK_UN))
+ log_sys_error("flock unlock", fifos->server_path);
+
+ if (close(fifos->server))
+ log_sys_error("close", fifos->server_path);
+ }
}
/* Get uuid of a device */
@@ -585,7 +579,13 @@ static int _do_event(int cmd, char *dmeventd_path, struct dm_event_daemon_messag
enum dm_event_mask evmask, uint32_t timeout)
{
int ret;
- struct dm_event_fifos fifos;
+ struct dm_event_fifos fifos = {
+ .server = -1,
+ .client = -1,
+ /* FIXME Make these either configurable or depend directly on dmeventd_path */
+ .client_path = DM_EVENT_FIFO_CLIENT,
+ .server_path = DM_EVENT_FIFO_SERVER
+ };
if (!_init_client(dmeventd_path, &fifos)) {
stack;
10 years, 5 months
master - config: use int for type
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fc9d4dd11f2331...
Commit: fc9d4dd11f2331e056f0b56274877c8a4b4b1570
Parent: 79991aa7699587b40946d029787b38ae67405336
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 25 13:44:46 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:42:44 2013 +0100
config: use int for type
Since the type is used for 'or' operation of enumerated bit fields,
it doesn't not have type cfg_def_type_t - use proper int type for
bitmask.
---
lib/config/config.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/config/config.h b/lib/config/config.h
index f57757b..0769c40 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -88,7 +88,7 @@ typedef struct cfg_def_item {
int id; /* ID of this item */
int parent; /* ID of parent item */
const char *name; /* name of the item in configuration tree */
- cfg_def_type_t type; /* configuration item type */
+ int type; /* configuration item type (bits of cfg_def_type_t) */
cfg_def_value_t default_value; /* default value (only for settings) */
uint16_t flags; /* configuration item definition flags */
uint16_t since_version; /* version this item appeared in */
10 years, 5 months
master - snapshot: drop find_merging_snapshot
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=79991aa7699587...
Commit: 79991aa7699587b40946d029787b38ae67405336
Parent: 01c438a96c82bf31ccda0721707fc90afa01a07e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 28 11:39:38 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:42:43 2013 +0100
snapshot: drop find_merging_snapshot
Drop find_merging_snapshot() function. Use find_snapshot()
called after check for lv_is_merging_origin() which
is the commonly used code path - so we avoid duplicated
tests and potential risk of derefering NULL point
in unhandled error path.
---
lib/activate/dev_manager.c | 12 ++++++------
lib/metadata/metadata-exported.h | 2 --
lib/metadata/snapshot_manip.c | 11 ++---------
tools/lvconvert.c | 9 +++++----
4 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index f8027d4..e53273d 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -2047,9 +2047,9 @@ static int _add_snapshot_merge_target_to_dtree(struct dev_manager *dm,
struct logical_volume *lv)
{
const char *origin_dlid, *cow_dlid, *merge_dlid;
- struct lv_segment *merging_snap_seg;
+ struct lv_segment *merging_snap_seg = find_snapshot(lv);
- if (!(merging_snap_seg = find_merging_snapshot(lv))) {
+ if (!lv_is_merging_origin(lv)) {
log_error(INTERNAL_ERROR "LV %s is not merging snapshot.", lv->name);
return 0;
}
@@ -2374,7 +2374,8 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
/* FIXME Seek a simpler way to lay out the snapshot-merge tree. */
- if (lv_is_origin(lv) && lv_is_merging_origin(lv) && !layer) {
+ if (!layer && lv_is_merging_origin(lv)) {
+ seg = find_snapshot(lv);
/*
* Clear merge attributes if merge isn't currently possible:
* either origin or merging snapshot are open
@@ -2385,8 +2386,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
/* An activating merging origin won't have a node in the tree yet */
if (((dinfo = _cached_info(dm->mem, dtree, lv, NULL)) &&
dinfo->open_count) ||
- ((dinfo = _cached_info(dm->mem, dtree,
- find_merging_snapshot(lv)->cow, NULL)) &&
+ ((dinfo = _cached_info(dm->mem, dtree, seg->cow, NULL)) &&
dinfo->open_count)) {
/* FIXME Is there anything simpler to check for instead? */
if (!lv_has_target_type(dm->mem, lv, NULL, "snapshot-merge"))
@@ -2445,7 +2445,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
return_0;
if (!laopts->no_merging && lv_is_merging_origin(lv)) {
if (!_add_new_lv_to_dtree(dm, dtree,
- find_merging_snapshot(lv)->cow, laopts, "cow"))
+ find_snapshot(lv)->cow, laopts, "cow"))
return_0;
/*
* Must also add "real" LV for use when
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 41bd1a7..c274649 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -882,8 +882,6 @@ int lv_is_visible(const struct logical_volume *lv);
int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv);
-struct lv_segment *find_merging_snapshot(const struct logical_volume *origin);
-
/* Given a cow LV, return return the snapshot lv_segment that uses it */
struct lv_segment *find_snapshot(const struct logical_volume *lv);
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index 3e90f3e..e9a6d87 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -100,14 +100,6 @@ int lv_is_merging_origin(const struct logical_volume *origin)
return (origin->status & MERGING) ? 1 : 0;
}
-struct lv_segment *find_merging_snapshot(const struct logical_volume *origin)
-{
- if (!lv_is_merging_origin(origin))
- return NULL;
-
- return find_snapshot(origin);
-}
-
int lv_is_merging_cow(const struct logical_volume *snapshot)
{
/* checks lv_segment's status to see if cow is merging */
@@ -233,7 +225,8 @@ int vg_remove_snapshot(struct logical_volume *cow)
dm_list_del(&cow->snapshot->origin_list);
origin->origin_count--;
- if (find_merging_snapshot(origin) == find_snapshot(cow)) {
+ if (lv_is_merging_origin(origin) &&
+ (find_snapshot(origin) == find_snapshot(cow))) {
clear_snapshot_merge(origin);
/*
* preload origin IFF "snapshot-merge" target is active
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 31eb232..051463b 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -650,8 +650,9 @@ static int _finish_lvconvert_merge(struct cmd_context *cmd,
struct logical_volume *lv,
struct dm_list *lvs_changed __attribute__((unused)))
{
- struct lv_segment *snap_seg = find_merging_snapshot(lv);
- if (!snap_seg) {
+ struct lv_segment *snap_seg = find_snapshot(lv);
+
+ if (!lv_is_merging_origin(lv)) {
log_error("Logical volume %s has no merging snapshot.", lv->name);
return 0;
}
@@ -1899,8 +1900,8 @@ static int lvconvert_merge(struct cmd_context *cmd,
return 0;
}
if (lv_is_merging_origin(origin)) {
- log_error("Snapshot %s is already merging into the origin",
- find_merging_snapshot(origin)->cow->name);
+ log_error("Snapshot %s is already merging into the origin.",
+ find_snapshot(origin)->cow->name);
return 0;
}
if (lv_is_virtual_origin(origin)) {
10 years, 5 months
master - format-text: ensure aligment is not 0
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=01c438a96c82bf...
Commit: 01c438a96c82bf31ccda0721707fc90afa01a07e
Parent: 5a4137c804b0ba579c5f368fe91942c465815f66
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 24 19:00:53 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:42:39 2013 +0100
format-text: ensure aligment is not 0
Make sure this path of code is not used for alignment == 0,
to prevent division by 0.
---
WHATS_NEW | 1 +
lib/format_text/format-text.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 55b17c0..cd63144 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Check for non-zero aligment in _text_pv_add_metadata_area() to not div by 0.
Add allocation/use_blkid_wiping to lvm.conf to enable blkid wiping.
Add configure --enable-blkid_wiping to use libblkid to detect signatures.
Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 275d16f..eb5c9e9 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -2083,7 +2083,7 @@ static int _text_pv_add_metadata_area(const struct format_type *fmt,
* alignment since it would be useless.
* Check first whether we can apply that!
*/
- if (!pe_start_locked &&
+ if (!pe_start_locked && alignment &&
((limit - mda_start) > alignment * 2)) {
mda_size = limit - mda_start - alignment * 2;
10 years, 5 months
master - profile: wipe_signatures_on_new_logical_volumes_when_zeroing not yet profilable
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5a4137c804b0ba...
Commit: 5a4137c804b0ba579c5f368fe91942c465815f66
Parent: 5968f07fd5ccb2b7d4e407cd8fec86b0b1f80f3a
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 16:49:12 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 16:49:12 2013 +0100
profile: wipe_signatures_on_new_logical_volumes_when_zeroing not yet profilable
But it might be - needs more testing...
---
conf/default.profile.in | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/conf/default.profile.in b/conf/default.profile.in
index 5a481de..29049ef 100644
--- a/conf/default.profile.in
+++ b/conf/default.profile.in
@@ -9,7 +9,6 @@
# Refer to 'man lvm.conf' for further information about profiles and file layout.
allocation {
- wipe_signatures_on_new_logical_volumes_when_zeroing = 1
thin_pool_chunk_size_policy = "generic"
thin_pool_chunk_size = 64
thin_pool_discards = "passdown"
10 years, 5 months
master - man: lvcreate -W/--wipesignatures
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5968f07fd5ccb2...
Commit: 5968f07fd5ccb2b7d4e407cd8fec86b0b1f80f3a
Parent: eaa23d32732c9bc3dd4f948781b5764cf21d84ba
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 15:20:12 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:49:15 2013 +0100
man: lvcreate -W/--wipesignatures
---
man/lvcreate.8.in | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/man/lvcreate.8.in b/man/lvcreate.8.in
index 4a29720..a34c4ae 100644
--- a/man/lvcreate.8.in
+++ b/man/lvcreate.8.in
@@ -75,6 +75,7 @@ lvcreate \- create a logical volume in an existing volume group
.RB [ \-\-type
.IR SegmentType ]
.RB [ \-v | \-\-verbose ]
+.RB [ \-W | \-\-wipesignatures ]
.RB [ \-Z | \-\-zero
.RI { y | n }]
.IR VolumeGroup { Name | Path }[/ ThinPoolLogicalVolumeName ]
@@ -135,8 +136,9 @@ If autoactivation option is used (\fB\-a\fIay\fR), the logical volume is
activated only if it matches an item in the
.B activation/auto_activation_volume_list
set in \fBlvm.conf\fP(5).
-For autoactivated logical volumes, \fB\-\-zero\fP \fIn\fP is always assumed
-and it can't be overridden. If the clustered locking is enabled,
+For autoactivated logical volumes, \fB\-\-zero\fP \fIn\fP and
+\fB\-\-wipesignatures\fP \fIn\fP is always assumed and it can't
+be overridden. If the clustered locking is enabled,
\fB\-a\fIey\fR will activate exclusively on one node and
.IR \fB\-a { a | l } y
will activate only on the local node.
@@ -399,6 +401,21 @@ requested size using the zero target. A suffix of _vorigin is used for
this device. Note: using sparse snapshots is not efficient for larger
device sizes (GiB), thin provisioning should be used for this case.
.TP
+.BR \-W ", " \-\-wipesignatures " {" \fIy | \fIn }
+Controls wiping of detected signatures on newly created Logical Volume.
+If this option is not specified, then by default signature wiping is done
+each time the zeroing (\fB\-Z\fP/\fB\-\-zero\fP) is done. This default behaviour
+can be controlled by \fBallocation/wipe_signatures_on_new_logical_volumes_when_zeroing\fP
+setting found in \fBlvm.conf\fP(5).
+.br
+If blkid wiping is used (\fBallocation/use_blkid_wiping setting\fP in \fBlvm.conf\fP(5))
+and LVM2 is compiled with blkid wiping support, then \fBblkid\fP(8) library is used
+to detect the signatures (use \fBblkid -k\fP command to list the signatures that are recognized).
+Otherwise, native LVM2 code is used to detect signatures (MD RAID, swap and LUKS
+signatures are detected only in this case).
+.br
+Logical Volume is not wiped if the read only flag is set.
+.TP
.BR \-Z ", " \-\-zero " {" \fIy | \fIn }
Controls zeroing of the first KiB of data in the new logical volume.
.br
10 years, 5 months
master - wiping: add support for blkid wiping
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=eaa23d32732c9b...
Commit: eaa23d32732c9bc3dd4f948781b5764cf21d84ba
Parent: ab2f858af7a72448b6c015a5984c73f5cdaf3664
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Nov 15 14:50:02 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:49:15 2013 +0100
wiping: add support for blkid wiping
This is actually the wipefs functionailty as a matter of fact
(wipefs uses the same libblkid calls).
libblkid is more rich when it comes to detecting various
signatures, including filesystems and users can better
decide what to erase and what should be kept.
The code is shared for both pvcreate (where wiping is necessary
to complete the pvcreate operation) and lvcreate where it's up
to the user to decide.
The verbose output contains a bit more information about the
signature like LABEL and UUID.
For example:
raw/~ # lvcreate -L16m vg
WARNING: linux_raid_member signature detected on /dev/vg/lvol0 at offset 4096. Wipe it? [y/n]
or more verbose one:
raw/~ # lvcreate -L16m vg -v
...
Found existing signature on /dev/vg/lvol0 at offset 4096: LABEL="raw.virt:0" UUID="da6af139-8403-5d06-b8c4-13f6f24b73b1" TYPE="linux_raid_member" USAGE="raid"
WARNING: linux_raid_member signature detected on /dev/vg/lvol0 at offset 4096. Wipe it? [y/n]
The verbose output is the same output as found in blkid.
---
lib/device/dev-type.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++-
lib/device/dev-type.h | 2 +-
lib/metadata/lv_manip.c | 2 +-
lib/metadata/metadata.c | 2 +-
4 files changed, 115 insertions(+), 4 deletions(-)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index e42349d..04b555b 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -21,6 +21,10 @@
#include <libgen.h>
#include <ctype.h>
+#ifdef BLKID_WIPING_SUPPORT
+#include <blkid/blkid.h>
+#endif
+
#include "device-types.h"
struct dev_types *create_dev_types(const char *proc_dir,
@@ -443,6 +447,102 @@ out:
return ret;
}
+#ifdef BLKID_WIPING_SUPPORT
+
+static int _blkid_wipe(blkid_probe probe, struct device *dev,
+ const char *name, int yes, force_t force)
+{
+ const char *offset = NULL, *type = NULL, *magic = NULL,
+ *usage = NULL, *label = NULL, *uuid = NULL;
+ loff_t offset_value;
+ size_t len;
+
+ if (!blkid_probe_lookup_value(probe, "TYPE", &type, NULL)) {
+ if (!blkid_probe_lookup_value(probe, "SBMAGIC_OFFSET", &offset, NULL) &&
+ blkid_probe_lookup_value(probe, "SBMAGIC", &magic, &len))
+ return_0;
+ } else if (!blkid_probe_lookup_value(probe, "PTTYPE", &type, NULL)) {
+ if (!blkid_probe_lookup_value(probe, "PTMAGIC_OFFSET", &offset, NULL) &&
+ blkid_probe_lookup_value(probe, "PTMAGIC", &magic, &len))
+ return_0;
+ usage = "partition table";
+ } else
+ return_0;
+
+ offset_value = strtoll(offset, NULL, 10);
+
+ if (!usage)
+ blkid_probe_lookup_value(probe, "USAGE", &usage, NULL);
+ blkid_probe_lookup_value(probe, "LABEL", &label, NULL);
+ blkid_probe_lookup_value(probe, "UUID", &uuid, NULL);
+
+ log_verbose("Found existing signature on %s at offset %s: LABEL=\"%s\" "
+ "UUID=\"%s\" TYPE=\"%s\" USAGE=\"%s\"",
+ name, offset, label, uuid, type, usage);
+
+ if (!yes && (force == PROMPT) &&
+ yes_no_prompt("WARNING: %s signature detected on %s at offset %s. "
+ "Wipe it? [y/n] ", type, name, offset) != 'y')
+ return_0;
+
+ log_print_unless_silent("Wiping %s signature on %s.", type, name);
+ if (!dev_set(dev, offset_value, len, 0)) {
+ log_error("Failed to wipe %s signature on %s.", type, name);
+ return 0;
+ }
+
+ return 1;
+}
+
+static int _wipe_known_signatures_with_blkid(struct device *dev, const char *name,
+ int yes, force_t force)
+{
+ blkid_probe probe = NULL;
+ int found = 0, wiped = 0, left = 0;
+ int r = 0;
+
+ /* TODO: Should we check for valid dev - _dev_is_valid(dev)? */
+
+ if (!(probe = blkid_new_probe_from_filename(dev_name(dev)))) {
+ log_error("Failed to create a new blkid probe for device %s.", dev_name(dev));
+ goto out;
+ }
+
+ blkid_probe_enable_partitions(probe, 1);
+ blkid_probe_set_partitions_flags(probe, BLKID_PARTS_MAGIC);
+
+ blkid_probe_enable_superblocks(probe, 1);
+ blkid_probe_set_superblocks_flags(probe, BLKID_SUBLKS_LABEL |
+ BLKID_SUBLKS_UUID |
+ BLKID_SUBLKS_TYPE |
+ BLKID_SUBLKS_USAGE |
+ BLKID_SUBLKS_VERSION |
+ BLKID_SUBLKS_MAGIC |
+ BLKID_SUBLKS_BADCSUM);
+
+ while (!blkid_do_probe(probe)) {
+ found++;
+ if (_blkid_wipe(probe, dev, name, yes, force))
+ wiped++;
+ }
+
+ if (!found)
+ r = 1;
+
+ left = found - wiped;
+ if (!left)
+ r = 1;
+ else
+ log_warn("%d existing signature%s left on the device.",
+ left, left > 1 ? "s" : "");
+out:
+ if (probe)
+ blkid_free_probe(probe);
+ return r;
+}
+
+#endif /* BLKID_WIPING_SUPPORT */
+
static int _wipe_signature(struct device *dev, const char *type, const char *name,
int wipe_len, int yes, force_t force,
int (*signature_detection_fn)(struct device *dev, uint64_t *offset_found))
@@ -475,7 +575,8 @@ static int _wipe_signature(struct device *dev, const char *type, const char *nam
return 1;
}
-int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t force)
+static int _wipe_known_signatures_with_lvm(struct device *dev, const char *name,
+ int yes, force_t force)
{
if (!_wipe_signature(dev, "software RAID md superblock", name, 4, yes, force, dev_is_md) ||
!_wipe_signature(dev, "swap signature", name, 10, yes, force, dev_is_swap) ||
@@ -485,6 +586,16 @@ int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t
return 1;
}
+int wipe_known_signatures(struct cmd_context *cmd, struct device *dev,
+ const char *name, int yes, force_t force)
+{
+#ifdef BLKID_WIPING_SUPPORT
+ if (find_config_tree_bool(cmd, allocation_use_blkid_wiping_CFG, NULL))
+ return _wipe_known_signatures_with_blkid(dev, name, yes, force);
+#endif
+ return _wipe_known_signatures_with_lvm(dev, name, yes, force);
+}
+
#ifdef __linux__
static int _snprintf_attr(char *buf, size_t buf_size, const char *sysfs_dir,
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
index 895a172..39d947b 100644
--- a/lib/device/dev-type.h
+++ b/lib/device/dev-type.h
@@ -60,7 +60,7 @@ int dev_is_swap(struct device *dev, uint64_t *signature);
int dev_is_luks(struct device *dev, uint64_t *signature);
/* Signature wiping. */
-int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t force);
+int wipe_known_signatures(struct cmd_context *cmd, struct device *dev, const char *name, int yes, force_t force);
/* Type-specific device properties */
unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev);
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 521d058..2480942 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -5429,7 +5429,7 @@ int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
if (wp->do_wipe_signatures) {
log_verbose("Wiping known signatures on logical volume \"%s/%s\"",
wp->lv->vg->name, wp->lv->name);
- if (!wipe_known_sbs(dev, name, wp->yes, wp->force))
+ if (!wipe_known_signatures(cmd, dev, name, wp->yes, wp->force))
stack;
}
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index f0230f1..5c87ab6 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1330,7 +1330,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
goto bad;
}
- if (!wipe_known_signatures(dev, name, pp->yes, pp->force)) {
+ if (!wipe_known_signatures(cmd, dev, name, pp->yes, pp->force)) {
log_error("Aborting pvcreate on %s.", name);
goto bad;
}
10 years, 5 months
master - conf: add allocation/use_blkid_wiping
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ab2f858af7a724...
Commit: ab2f858af7a72448b6c015a5984c73f5cdaf3664
Parent: 9bfc0be493192958f5dbffea4eb7dda968062261
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 13:52:15 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:49:14 2013 +0100
conf: add allocation/use_blkid_wiping
Add allocation/use_blkid_wiping setting to lvm.conf to select between
LVM2 native code to detect signatures to wipe or blkid library code.
---
WHATS_NEW | 1 +
conf/example.conf.in | 15 +++++++++++++++
lib/config/config_settings.h | 1 +
3 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 9823cd1..55b17c0 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add allocation/use_blkid_wiping to lvm.conf to enable blkid wiping.
Add configure --enable-blkid_wiping to use libblkid to detect signatures.
Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
Add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing to lvm.conf.
diff --git a/conf/example.conf.in b/conf/example.conf.in
index 0ac53ef..b7ad3d1 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -272,6 +272,21 @@ allocation {
# algorithm.
maximise_cling = 1
+ # Whether to use blkid library instead of native LVM2 code to detect
+ # any existing signatures while creating new Physical Volumes and
+ # Logical Volumes. LVM2 needs to be compiled with blkid wiping support
+ # for this setting to take effect.
+ #
+ # LVM2 native detection code is currently able to recognize these signatures:
+ # - MD device signature
+ # - swap signature
+ # - LUKS signature
+ # To see the list of signatures recognized by blkid, check the output
+ # of 'blkid -k' command. The blkid can recognize more signatures than
+ # LVM2 native detection code, but due to this higher number of signatures
+ # to be recognized, it can take more time to complete the signature scan.
+ use_blkid_wiping = 1
+
# Whether do wipe any signatures found on newly created Logical Volumes
# automatically in addition to zeroing of the first KB on the LV
# (-Z/--zero y option) when running the LVM command without specifying
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 7a7e8e5..929e907 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -104,6 +104,7 @@ cfg(devices_issue_discards_CFG, "issue_discards", devices_CFG_SECTION, 0, CFG_TY
cfg_array(allocation_cling_tag_list_CFG, "cling_tag_list", allocation_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 77), NULL)
cfg(allocation_maximise_cling_CFG, "maximise_cling", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MAXIMISE_CLING, vsn(2, 2, 85), NULL)
+cfg(allocation_use_blkid_wiping_CFG, "use_blkid_wiping", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL)
cfg(allocation_wipe_signatures_on_new_logical_volumes_when_zeroing_CFG, "wipe_signatures_on_new_logical_volumes_when_zeroing", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL)
cfg(allocation_mirror_logs_require_separate_pvs_CFG, "mirror_logs_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS, vsn(2, 2, 85), NULL)
cfg(allocation_thin_pool_metadata_require_separate_pvs_CFG, "thin_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 89), NULL)
10 years, 5 months
master - configure: add --enable-blkid_wiping
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9bfc0be4931929...
Commit: 9bfc0be493192958f5dbffea4eb7dda968062261
Parent: b6dab4e0598df7b6a44a32749fdb846c03aa692d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Nov 14 14:03:24 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:48:16 2013 +0100
configure: add --enable-blkid_wiping
---
WHATS_NEW | 1 +
configure | 128 +++++++++++++++++++++++++++++++++++++++++++++++
configure.in | 22 ++++++++
lib/misc/configure.h.in | 3 +
liblvm/liblvm2app.pc.in | 2 +-
make.tmpl.in | 5 +-
tools/Makefile.in | 2 +-
7 files changed, 159 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index b4d683d..9823cd1 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add configure --enable-blkid_wiping to use libblkid to detect signatures.
Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
Add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing to lvm.conf.
Do not fail the whole autoactivation if the VG refresh done before fails.
diff --git a/configure b/configure
index 9418d53..8247ddd 100755
--- a/configure
+++ b/configure
@@ -691,6 +691,8 @@ CLDFLAGS
BUILD_LVMETAD
BUILD_DMEVENTD
BUILD_CMIRRORD
+BLKID_WIPING
+BLKID_PC
APPLIB
MODPROBE_CMD
MSGFMT
@@ -700,6 +702,8 @@ LVM2CMD_LIB
LVM2APP_LIB
UDEV_LIBS
UDEV_CFLAGS
+BLKID_LIBS
+BLKID_CFLAGS
VALGRIND_POOL
VALGRIND_LIBS
VALGRIND_CFLAGS
@@ -852,6 +856,7 @@ enable_valgrind_pool
enable_devmapper
enable_lvmetad
with_lvmetad_pidfile
+enable_blkid_wiping
enable_udev_systemd_background_jobs
enable_udev_sync
enable_udev_rules
@@ -926,6 +931,8 @@ CUNIT_CFLAGS
CUNIT_LIBS
VALGRIND_CFLAGS
VALGRIND_LIBS
+BLKID_CFLAGS
+BLKID_LIBS
UDEV_CFLAGS
UDEV_LIBS'
@@ -1556,6 +1563,7 @@ Optional Features:
--enable-valgrind-pool enable valgrind awareness of pools
--disable-devmapper disable LVM2 device-mapper interaction
--enable-lvmetad enable the LVM Metadata Daemon
+ --enable-blkid_wiping use wiping functionality provided by libblkid
--enable-udev-systemd-background-jobs
enable udev-systemd protocol to instantiate a
service for background job
@@ -1716,6 +1724,9 @@ Some influential environment variables:
C compiler flags for VALGRIND, overriding pkg-config
VALGRIND_LIBS
linker flags for VALGRIND, overriding pkg-config
+ BLKID_CFLAGS
+ C compiler flags for BLKID, overriding pkg-config
+ BLKID_LIBS linker flags for BLKID, overriding pkg-config
UDEV_CFLAGS C compiler flags for UDEV, overriding pkg-config
UDEV_LIBS linker flags for UDEV, overriding pkg-config
@@ -9174,6 +9185,120 @@ _ACEOF
fi
################################################################################
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use blkid wiping functionality" >&5
+$as_echo_n "checking whether to use blkid wiping functionality... " >&6; }
+# Check whether --enable-blkid-wiping was given.
+if test "${enable_blkid_wiping+set}" = set; then :
+ enableval=$enable_blkid_wiping; BLKID_WIPING=$enableval
+else
+ BLKID_WIPING=no
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $BLKID_WIPING" >&5
+$as_echo "$BLKID_WIPING" >&6; }
+
+
+if test x$BLKID_WIPING = xyes; then
+ if test x$PKGCONFIG_INIT != x1; then
+ pkg_config_init
+ fi
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BLKID" >&5
+$as_echo_n "checking for BLKID... " >&6; }
+
+if test -n "$BLKID_CFLAGS"; then
+ pkg_cv_BLKID_CFLAGS="$BLKID_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.22\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "blkid >= 2.22") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_BLKID_CFLAGS=`$PKG_CONFIG --cflags "blkid >= 2.22" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ else
+ pkg_failed=untried
+fi
+if test -n "$BLKID_LIBS"; then
+ pkg_cv_BLKID_LIBS="$BLKID_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.22\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "blkid >= 2.22") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_BLKID_LIBS=`$PKG_CONFIG --libs "blkid >= 2.22" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ else
+ pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+ _pkg_short_errors_supported=yes
+else
+ _pkg_short_errors_supported=no
+fi
+ if test $_pkg_short_errors_supported = yes; then
+ BLKID_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "blkid >= 2.22" 2>&1`
+ else
+ BLKID_PKG_ERRORS=`$PKG_CONFIG --print-errors "blkid >= 2.22" 2>&1`
+ fi
+ # Put the nasty error message in config.log where it belongs
+ echo "$BLKID_PKG_ERRORS" >&5
+
+ as_fn_error $? "Package requirements (blkid >= 2.22) were not met:
+
+$BLKID_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables BLKID_CFLAGS
+and BLKID_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details." "$LINENO" 5
+
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables BLKID_CFLAGS
+and BLKID_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details" "$LINENO" 5; }
+
+else
+ BLKID_CFLAGS=$pkg_cv_BLKID_CFLAGS
+ BLKID_LIBS=$pkg_cv_BLKID_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ BLKID_PC="blkid"
+fi
+
+$as_echo "#define BLKID_WIPING_SUPPORT 1" >>confdefs.h
+
+fi
+
+################################################################################
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use udev-systemd protocol for jobs in background" >&5
$as_echo_n "checking whether to use udev-systemd protocol for jobs in background... " >&6; }
# Check whether --enable-udev-systemd-background-jobs was given.
@@ -11029,6 +11154,9 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'`
+
+
+
################################################################################
ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/lvm2/Makefile daemons/dmeventd/plugins/raid/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile daemons/dmeventd/plugins/thin/Makefile daemons/lvmetad/Makefile conf/Makefile conf/example.conf conf/default.profile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/raid/Makefile lib/snapshot/Makefile lib/thin/Makefile libdaemon/Makefile libdaemon/client/Makefile libdaemon/server/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile python/Makefile python/setup.py scripts/blkdeactivate.sh scripts/blk_availability_
init_red_hat scripts/blk_availability_systemd_red_hat.service scripts/clvmd_init_red_hat scripts/cmirrord_init_red_hat scripts/lvm2_lvmetad_init_red_hat scripts/lvm2_lvmetad_systemd_red_hat.socket scripts/lvm2_lvmetad_systemd_red_hat.service scripts/lvm2_pvscan_systemd_red_hat@.service scripts/lvm2_monitoring_init_red_hat scripts/dm_event_systemd_red_hat.socket scripts/dm_event_systemd_red_hat.service scripts/lvm2_monitoring_systemd_red_hat.service scripts/lvm2_tmpfiles_red_hat.conf scripts/Makefile test/Makefile test/api/Makefile test/unit/Makefile tools/Makefile udev/Makefile unit-tests/datastruct/Makefile unit-tests/regex/Makefile unit-tests/mm/Makefile"
diff --git a/configure.in b/configure.in
index cd80274..ff9bf81 100644
--- a/configure.in
+++ b/configure.in
@@ -946,6 +946,25 @@ if test x$BUILD_LVMETAD = xyes; then
fi
################################################################################
+dnl -- Enable blkid wiping functionality
+AC_MSG_CHECKING(whether to use blkid wiping functionality)
+AC_ARG_ENABLE(blkid-wiping,
+ AC_HELP_STRING([--enable-blkid_wiping],
+ [use wiping functionality provided by libblkid]),
+ BLKID_WIPING=$enableval, BLKID_WIPING=no)
+AC_MSG_RESULT($BLKID_WIPING)
+
+
+if test x$BLKID_WIPING = xyes; then
+ dnl -- init pkgconfig if required
+ if test x$PKGCONFIG_INIT != x1; then
+ pkg_config_init
+ fi
+ PKG_CHECK_MODULES(BLKID, blkid >= 2.22, [BLKID_PC="blkid"])
+ AC_DEFINE([BLKID_WIPING_SUPPORT], 1, [Define to 1 to use wiping functionality provided by libblkid.])
+fi
+
+################################################################################
dnl -- Enable udev-systemd protocol to instantiate a service for background jobs
AC_MSG_CHECKING(whether to use udev-systemd protocol for jobs in background)
AC_ARG_ENABLE(udev-systemd-background-jobs,
@@ -1538,6 +1557,9 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[[()]]' '{print $2}'`
################################################################################
AC_SUBST(APPLIB)
AC_SUBST(AWK)
+AC_SUBST(BLKID_LIBS)
+AC_SUBST(BLKID_PC)
+AC_SUBST(BLKID_WIPING)
AC_SUBST(BUILD_CMIRRORD)
AC_SUBST(BUILD_DMEVENTD)
AC_SUBST(BUILD_LVMETAD)
diff --git a/lib/misc/configure.h.in b/lib/misc/configure.h.in
index 13ba882..51db42e 100644
--- a/lib/misc/configure.h.in
+++ b/lib/misc/configure.h.in
@@ -1,5 +1,8 @@
/* lib/misc/configure.h.in. Generated from configure.in by autoheader. */
+/* Define to 1 to use wiping functionality provided by libblkid. */
+#undef BLKID_WIPING_SUPPORT
+
/* Define to 1 if the `closedir' function returns void instead of `int'. */
#undef CLOSEDIR_VOID
diff --git a/liblvm/liblvm2app.pc.in b/liblvm/liblvm2app.pc.in
index 4c71c36..7d7fd3d 100644
--- a/liblvm/liblvm2app.pc.in
+++ b/liblvm/liblvm2app.pc.in
@@ -8,4 +8,4 @@ Description: lvm2 application library
Version: @LVM_MAJOR@.@LVM_LIBAPI@
Cflags: -I${includedir}
Libs: -L${libdir} -llvm2app
-Requires.private: devmapper
+Requires.private: devmapper @BLKID_PC@
diff --git a/make.tmpl.in b/make.tmpl.in
index 3eea85e..35a47be 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -43,7 +43,7 @@ PYTHON = @PYTHON@
LIBS = @LIBS@
# Extra libraries always linked with static binaries
-STATIC_LIBS = $(SELINUX_LIBS) $(UDEV_LIBS)
+STATIC_LIBS = $(SELINUX_LIBS) $(UDEV_LIBS) $(BLKID_LIBS)
DEFS += @DEFS@
# FIXME set this only where it's needed, not globally?
CFLAGS += @CFLAGS@ @UDEV_CFLAGS@
@@ -52,12 +52,13 @@ ELDFLAGS += @ELDFLAGS@
LDDEPS += @LDDEPS@
LDFLAGS += @LDFLAGS@
LIB_SUFFIX = @LIB_SUFFIX@
-LVMINTERNAL_LIBS = -llvm-internal $(DAEMON_LIBS) $(UDEV_LIBS) $(DL_LIBS)
+LVMINTERNAL_LIBS = -llvm-internal $(DAEMON_LIBS) $(UDEV_LIBS) $(DL_LIBS) $(BLKID_LIBS)
DL_LIBS = @DL_LIBS@
PTHREAD_LIBS = @PTHREAD_LIBS@
READLINE_LIBS = @READLINE_LIBS@
SELINUX_LIBS = @SELINUX_LIBS@
UDEV_LIBS = @UDEV_LIBS@
+BLKID_LIBS=@BLKID_LIBS@
TESTING = @TESTING@
# Setup directory variables
diff --git a/tools/Makefile.in b/tools/Makefile.in
index f90cfae..f8e4934 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -117,7 +117,7 @@ CFLOW_TARGET = lvm
include $(top_builddir)/make.tmpl
-LIBS += $(UDEV_LIBS)
+LIBS += $(UDEV_LIBS) $(BLKID_LIBS)
device-mapper: $(TARGETS_DM)
10 years, 5 months
master - lv_manip: rename set_lv -> wipe_lv and include signature wiping capability
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b6dab4e0598df7...
Commit: b6dab4e0598df7b6a44a32749fdb846c03aa692d
Parent: 169b4c15864330e3fe47efee7b0def06581b8f08
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 6 16:16:34 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:48:15 2013 +0100
lv_manip: rename set_lv -> wipe_lv and include signature wiping capability
Use common wipe_lv (former set_lv) fn to do zeroing as well as signature
wiping if needed. Provide new struct wipe_lv_params to define the
functionality.
Bind "lvcreate -W/--wipesignatures y" with proper wipe_lv call.
Also, add "yes" and "force" to lvcreate_params so it's possible
to apply them for the prompt: "WARNING: %s detected on %s. Wipe it? [y/n]".
---
lib/metadata/lv_manip.c | 98 ++++++++++++++++++++++++++------------
lib/metadata/metadata-exported.h | 18 ++++++-
lib/metadata/mirror.c | 18 +++++--
lib/metadata/raid_manip.c | 11 ++++-
lib/metadata/thin_manip.c | 12 ++++-
tools/lvchange.c | 13 +++++-
tools/lvconvert.c | 27 ++++++++++-
tools/lvcreate.c | 2 +
8 files changed, 157 insertions(+), 42 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 491accd..521d058 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2906,7 +2906,17 @@ static int _lv_extend_layered_lv(struct alloc_handle *ah,
* wipe '1' to remove the superblock of any previous
* RAID devices. It is much quicker.
*/
- if (!set_lv(meta_lv->vg->cmd, meta_lv, 1, 0)) {
+ struct wipe_lv_params wp = {
+ .lv = meta_lv,
+ .do_zero = 1,
+ .zero_sectors = 1,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(meta_lv->vg->cmd, &wp)) {
log_error("Failed to zero %s/%s",
meta_lv->vg->name, meta_lv->name);
return 0;
@@ -5372,15 +5382,19 @@ int insert_layer_for_segments_on_pv(struct cmd_context *cmd,
/*
* Initialize the LV with 'value'.
*/
-int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
- uint64_t sectors, int value)
+int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
{
struct device *dev;
char *name;
+ uint64_t zero_sectors;
- if (!lv_is_active_locally(lv)) {
+ if (!(wp->do_zero || wp->do_wipe_signatures))
+ /* nothing to do */
+ return 1;
+
+ if (!lv_is_active_locally(wp->lv)) {
log_error("Volume \"%s/%s\" is not active locally.",
- lv->vg->name, lv->name);
+ wp->lv->vg->name, wp->lv->name);
return 0;
}
@@ -5397,15 +5411,13 @@ int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
}
if (dm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
- lv->vg->name, lv->name) < 0) {
- log_error("Name too long - device not cleared (%s)", lv->name);
+ wp->lv->vg->name, wp->lv->name) < 0) {
+ log_error("Name too long - device not cleared (%s)", wp->lv->name);
return 0;
}
sync_local_dev_names(cmd); /* Wait until devices are available */
- log_verbose("Clearing start of logical volume \"%s\"", lv->name);
-
if (!(dev = dev_cache_get(name, NULL))) {
log_error("%s: not found: device not cleared", name);
return 0;
@@ -5414,21 +5426,32 @@ int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
if (!dev_open_quiet(dev))
return_0;
- if (!sectors)
- sectors = UINT64_C(4096) >> SECTOR_SHIFT;
+ if (wp->do_wipe_signatures) {
+ log_verbose("Wiping known signatures on logical volume \"%s/%s\"",
+ wp->lv->vg->name, wp->lv->name);
+ if (!wipe_known_sbs(dev, name, wp->yes, wp->force))
+ stack;
+ }
- if (sectors > lv->size)
- sectors = lv->size;
+ if (wp->do_zero) {
+ zero_sectors = wp->zero_sectors ? : UINT64_C(4096) >> SECTOR_SHIFT;
- if (!dev_set(dev, UINT64_C(0), (size_t) sectors << SECTOR_SHIFT, value))
- stack;
+ if (zero_sectors > wp->lv->size)
+ zero_sectors = wp->lv->size;
+
+ log_verbose("Clearing start of logical volume \"%s/%s\"",
+ wp->lv->vg->name, wp->lv->name);
+
+ if (!dev_set(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, wp->zero_value))
+ stack;
+ }
dev_flush(dev);
if (!dev_close_immediate(dev))
stack;
- lv->status &= ~LV_NOSCAN;
+ wp->lv->status &= ~LV_NOSCAN;
return 1;
}
@@ -5982,12 +6005,12 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
backup(vg);
if (test_mode()) {
- log_verbose("Test mode: Skipping activation and zeroing.");
+ log_verbose("Test mode: Skipping activation, zeroing and signature wiping.");
goto out;
}
- /* Do not scan this LV until properly zeroed. */
- if (lp->zero)
+ /* Do not scan this LV until properly zeroed/wiped. */
+ if (lp->zero | lp->wipe_signatures)
lv->status |= LV_NOSCAN;
if (lp->temporary)
@@ -6056,21 +6079,36 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
}
} else if (!lv_active_change(cmd, lv, lp->activate)) {
log_error("Failed to activate new LV.");
- if (lp->zero)
+ if (lp->zero || lp->wipe_signatures)
goto deactivate_and_revert_new_lv;
return NULL;
}
- if (!seg_is_thin(lp) && !lp->zero && !lp->snapshot)
- log_warn("WARNING: \"%s\" not zeroed", lv->name);
- else if ((!seg_is_thin(lp) ||
- (lv_is_thin_volume(lv) && !lp->snapshot &&
- !first_seg(first_seg(lv)->pool_lv)->zero_new_blocks)) &&
- !set_lv(cmd, lv, UINT64_C(0), 0)) {
- log_error("Aborting. Failed to wipe %s.",
- lp->snapshot ? "snapshot exception store" :
- "start of new LV");
- goto deactivate_and_revert_new_lv;
+ if (!seg_is_thin(lp) && !lp->snapshot) {
+ if (!lp->zero)
+ log_warn("WARNING: \"%s/%s\" not zeroed", lv->vg->name, lv->name);
+ if (!lp->wipe_signatures)
+ log_verbose("Signature wiping on \"%s/%s\" not requested", lv->vg->name, lv->name);
+ }
+
+ if ((!seg_is_thin(lp) ||
+ (lv_is_thin_volume(lv) && !lp->snapshot &&
+ !first_seg(first_seg(lv)->pool_lv)->zero_new_blocks))) {
+ struct wipe_lv_params wp = {
+ .lv = lv,
+ .do_zero = lp->zero,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = lp->wipe_signatures,
+ .yes = lp->yes,
+ .force = lp->force
+ };
+ if (!wipe_lv(cmd, &wp)) {
+ log_error("Aborting. Failed to wipe %s.",
+ lp->snapshot ? "snapshot exception store" :
+ "start of new LV");
+ goto deactivate_and_revert_new_lv;
+ }
}
if (lp->snapshot && !seg_is_thin(lp)) {
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 69a0e90..41bd1a7 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -622,9 +622,18 @@ struct logical_volume *lv_create_empty(const char *name,
alloc_policy_t alloc,
struct volume_group *vg);
-/* Write out LV contents */
-int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
- uint64_t sectors, int value);
+struct wipe_lv_params {
+ struct logical_volume *lv;
+ int do_zero; /* should we do zeroing of LV start? */
+ uint64_t zero_sectors; /* sector count to zero */
+ int zero_value; /* zero-out with this value */
+ int do_wipe_signatures; /* should we wipe known signatures found on LV? */
+ int yes; /* answer yes automatically to all questions */
+ force_t force; /* force mode */
+};
+
+/* Zero out LV and/or wipe signatures */
+int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *params);
int lv_change_tag(struct logical_volume *lv, const char *tag, int add_tag);
@@ -779,6 +788,9 @@ struct lvcreate_params {
alloc_policy_t alloc; /* all */
struct dm_list tags; /* all */
+
+ int yes;
+ force_t force;
};
struct logical_volume *lv_create_single(struct volume_group *vg,
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 24c9786..83ba486 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -339,10 +339,20 @@ static int _init_mirror_log(struct cmd_context *cmd,
dm_list_iterate_items(sl, tags)
str_list_del(&log_lv->tags, sl->str);
- if (activation() && !set_lv(cmd, log_lv, log_lv->size,
- in_sync ? -1 : 0)) {
- log_error("Aborting. Failed to wipe mirror log.");
- goto deactivate_and_revert_new_lv;
+ if (activation()) {
+ struct wipe_lv_params wp = {
+ .lv = log_lv,
+ .do_zero = 1,
+ .zero_sectors = log_lv->size,
+ .zero_value = in_sync ? -1 : 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+ if (!wipe_lv(cmd, &wp)) {
+ log_error("Aborting. Failed to wipe mirror log.");
+ goto deactivate_and_revert_new_lv;
+ }
}
if (activation() && !_write_log_header(cmd, log_lv)) {
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 147b478..d1bb330 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -170,6 +170,15 @@ static int _raid_remove_top_layer(struct logical_volume *lv,
static int _clear_lv(struct logical_volume *lv)
{
int was_active = lv_is_active_locally(lv);
+ struct wipe_lv_params wp = {
+ .lv = lv,
+ .do_zero = 1,
+ .zero_sectors = 1,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
if (test_mode())
return 1;
@@ -187,7 +196,7 @@ static int _clear_lv(struct logical_volume *lv)
* wipe the first sector to remove the superblock of any previous
* RAID devices. It is much quicker.
*/
- if (!set_lv(lv->vg->cmd, lv, 1, 0)) {
+ if (!wipe_lv(lv->vg->cmd, &wp)) {
log_error("Failed to zero %s", lv->name);
return 0;
}
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index bd5b117..4ee4411 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -468,10 +468,20 @@ int create_pool(struct logical_volume *pool_lv, const struct segment_type *segty
* FIXME: implement lazy clearing when activation is disabled
*/
+ struct wipe_lv_params wp = {
+ .lv = pool_lv,
+ .do_zero = 1,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
/* pool_lv is a new LV so the VG lock protects us */
if (!activate_lv_local(pool_lv->vg->cmd, pool_lv) ||
/* Clear 4KB of metadata device for new thin-pool. */
- !set_lv(pool_lv->vg->cmd, pool_lv, UINT64_C(0), 0)) {
+ !wipe_lv(pool_lv->vg->cmd, &wp)) {
log_error("Aborting. Failed to wipe pool metadata %s.",
pool_lv->name);
goto bad;
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 897ffb2..59a554c 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -478,7 +478,18 @@ static int lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)
log_very_verbose("Clearing %s device %s",
(seg_is_raid(seg)) ? "metadata" : "log",
lvl->lv->name);
- if (!set_lv(cmd, lvl->lv, lvl->lv->size, 0)) {
+
+ struct wipe_lv_params wp = {
+ .lv = lvl->lv,
+ .do_zero = 1,
+ .zero_sectors = lvl->lv->size,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(cmd, &wp)) {
log_error("Unable to reset sync status for %s",
lv->name);
if (!deactivate_lv(cmd, lvl->lv))
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index a15bd75..31eb232 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1846,10 +1846,22 @@ static int lvconvert_snapshot(struct cmd_context *cmd,
if (!lp->zero || !(lv->status & LVM_WRITE))
log_warn("WARNING: \"%s\" not zeroed", lv->name);
- else if (!set_lv(cmd, lv, UINT64_C(0), 0)) {
+ else {
+ struct wipe_lv_params wp = {
+ .lv = lv,
+ .do_zero = 1,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(cmd, &wp)) {
log_error("Aborting. Failed to wipe snapshot "
"exception store.");
return 0;
+ }
}
if (!deactivate_lv(cmd, lv)) {
@@ -2463,7 +2475,18 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
log_error("Aborting. Failed to activate thin metadata lv.");
return 0;
}
- if (!set_lv(cmd, metadata_lv, UINT64_C(0), 0)) {
+
+ struct wipe_lv_params wp = {
+ .lv = metadata_lv,
+ .do_zero = 1,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(cmd, &wp)) {
log_error("Aborting. Failed to wipe thin metadata lv.");
return 0;
}
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 83c12a7..1fe5130 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -710,6 +710,8 @@ static int _read_activation_params(struct lvcreate_params *lp, struct cmd_contex
return 0;
}
+ lp->yes = arg_count(cmd, yes_ARG);
+ lp->force = (force_t) arg_count(cmd, force_ARG);
return 1;
}
10 years, 5 months