* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2007-08-21 16:40 wysochanski
0 siblings, 0 replies; 13+ messages in thread
From: wysochanski @ 2007-08-21 16:40 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski at sourceware.org 2007-08-21 16:40:33
Modified files:
lib/metadata : lv_manip.c metadata-exported.h
tools : vgremove.c
Log message:
Prepare to move guts of vgremove into lvm library.
Fixup force_t.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.124&r2=1.125
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.10&r2=1.11
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgremove.c.diff?cvsroot=lvm2&r1=1.42&r2=1.43
--- LVM2/lib/metadata/lv_manip.c 2007/08/20 20:55:26 1.124
+++ LVM2/lib/metadata/lv_manip.c 2007/08/21 16:40:33 1.125
@@ -1850,7 +1850,7 @@
return 0;
}
- if (info.exists && (force == DONT_FORCE)) {
+ if (info.exists && (force == PROMPT)) {
if (yes_no_prompt("Do you really want to remove active "
"logical volume \"%s\"? [y/n]: ",
lv->name) == 'n') {
--- LVM2/lib/metadata/metadata-exported.h 2007/08/20 20:55:26 1.10
+++ LVM2/lib/metadata/metadata-exported.h 2007/08/21 16:40:33 1.11
@@ -107,9 +107,9 @@
* Whether or not to force an operation.
*/
typedef enum {
- DONT_FORCE = 0,
- FORCE_NO_CONFIRM = 1, /* skip yes/no confirmation of operation */
- FORCE_OVERRIDE = 2 /* skip confirmation and bypass a second condition */
+ PROMPT = 0, /* Issue yes/no prompt to confirm operation */
+ DONT_PROMPT = 1, /* Skip yes/no prompt */
+ DONT_PROMPT_OVERRIDE = 2 /* Skip prompt + override a second condition */
} force_t;
struct cmd_context;
--- LVM2/tools/vgremove.c 2007/08/20 20:55:30 1.42
+++ LVM2/tools/vgremove.c 2007/08/21 16:40:33 1.43
@@ -15,37 +15,37 @@
#include "tools.h"
-static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
- struct volume_group *vg, int consistent,
- void *handle __attribute((unused)))
+static int vg_remove_single(struct cmd_context *cmd, const char *vg_name,
+ struct volume_group *vg, int consistent,
+ force_t force)
{
struct physical_volume *pv;
struct pv_list *pvl;
- int ret = ECMD_PROCESSED;
+ int ret = 1;
if (!vg || !consistent || (vg_status(vg) & PARTIAL_VG)) {
log_error("Volume group \"%s\" not found or inconsistent.",
vg_name);
log_error("Consider vgreduce --removemissing if metadata "
"is inconsistent.");
- return ECMD_FAILED;
+ return 0;
}
if (!vg_check_status(vg, EXPORTED_VG))
- return ECMD_FAILED;
+ return 0;
if (vg->lv_count) {
log_error("Volume group \"%s\" still contains %d "
"logical volume(s)", vg_name, vg->lv_count);
- return ECMD_FAILED;
+ return 0;
}
if (!archive(vg))
- return ECMD_FAILED;
+ return 0;
if (!vg_remove(vg)) {
log_error("vg_remove %s failed", vg_name);
- return ECMD_FAILED;
+ return 0;
}
/* init physical volumes */
@@ -58,7 +58,7 @@
if (!dev_get_size(pv_dev(pv), &pv->size)) {
log_error("%s: Couldn't get size.", dev_name(pv_dev(pv)));
- ret = ECMD_FAILED;
+ ret = 0;
continue;
}
@@ -67,19 +67,29 @@
log_error("Failed to remove physical volume \"%s\""
" from volume group \"%s\"",
dev_name(pv_dev(pv)), vg_name);
- ret = ECMD_FAILED;
+ ret = 0;
}
}
backup_remove(cmd, vg_name);
- if (ret == ECMD_PROCESSED)
+ if (ret)
log_print("Volume group \"%s\" successfully removed", vg_name);
else
log_error("Volume group \"%s\" not properly removed", vg_name);
return ret;
}
+static int vgremove_single(struct cmd_context *cmd, const char *vg_name,
+ struct volume_group *vg, int consistent,
+ void *handle __attribute((unused)))
+{
+ if (!vg_remove_single(cmd, vg_name, vg, consistent,
+ arg_count(cmd, force_ARG)))
+ return ECMD_FAILED;
+
+ return ECMD_PROCESSED;
+}
int vgremove(struct cmd_context *cmd, int argc, char **argv)
{
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2007-09-24 21:30 wysochanski
0 siblings, 0 replies; 13+ messages in thread
From: wysochanski @ 2007-09-24 21:30 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski at sourceware.org 2007-09-24 21:30:00
Modified files:
lib/metadata : lv_manip.c metadata-exported.h pv_manip.c
tools : lvcreate.c lvresize.c
Log message:
Some const fixups for previous checkins
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.128&r2=1.129
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.15&r2=1.16
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv_manip.c.diff?cvsroot=lvm2&r1=1.13&r2=1.14
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvcreate.c.diff?cvsroot=lvm2&r1=1.148&r2=1.149
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvresize.c.diff?cvsroot=lvm2&r1=1.83&r2=1.84
--- LVM2/lib/metadata/lv_manip.c 2007/08/28 16:14:48 1.128
+++ LVM2/lib/metadata/lv_manip.c 2007/09/24 21:30:00 1.129
@@ -1803,7 +1803,7 @@
}
int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
- force_t force)
+ const force_t force)
{
struct volume_group *vg;
struct lvinfo info;
--- LVM2/lib/metadata/metadata-exported.h 2007/09/20 21:39:07 1.15
+++ LVM2/lib/metadata/metadata-exported.h 2007/09/24 21:30:00 1.16
@@ -330,7 +330,7 @@
uint64_t label_sector);
/* FIXME: move internal to library */
-uint32_t pv_list_extents_free(struct list *pvh);
+uint32_t pv_list_extents_free(const struct list *pvh);
struct volume_group *vg_create(struct cmd_context *cmd, const char *name,
uint32_t extent_size, uint32_t max_pv,
--- LVM2/lib/metadata/pv_manip.c 2007/09/20 21:39:07 1.13
+++ LVM2/lib/metadata/pv_manip.c 2007/09/24 21:30:00 1.14
@@ -218,8 +218,8 @@
* Calculate the overlap, in extents, between a struct pv_segment and
* a struct pe_range.
*/
-static uint32_t _overlap_pe(struct pv_segment *pvseg,
- struct pe_range *per)
+static uint32_t _overlap_pe(const struct pv_segment *pvseg,
+ const struct pe_range *per)
{
uint32_t start;
uint32_t end;
@@ -235,7 +235,7 @@
/*
* Returns: number of free PEs in a struct pv_list
*/
-uint32_t pv_list_extents_free(struct list *pvh)
+uint32_t pv_list_extents_free(const struct list *pvh)
{
struct pv_list *pvl;
struct pe_range *per;
@@ -443,7 +443,7 @@
int pv_resize_single(struct cmd_context *cmd,
struct volume_group *vg,
struct physical_volume *pv,
- uint64_t new_size)
+ const uint64_t new_size)
{
struct pv_list *pvl;
int consistent = 1;
--- LVM2/tools/lvcreate.c 2007/09/24 13:29:49 1.148
+++ LVM2/tools/lvcreate.c 2007/09/24 21:30:00 1.149
@@ -244,8 +244,8 @@
* Generic mirror parameter checks.
* FIXME: Should eventually be moved into lvm library.
*/
-static int _validate_mirror_params(struct cmd_context *cmd,
- struct lvcreate_params *lp)
+static int _validate_mirror_params(const struct cmd_context *cmd,
+ const struct lvcreate_params *lp)
{
int pagesize = lvm_getpagesize();
--- LVM2/tools/lvresize.c 2007/09/20 21:39:08 1.83
+++ LVM2/tools/lvresize.c 2007/09/24 21:30:00 1.84
@@ -47,7 +47,7 @@
};
static int validate_stripesize(struct cmd_context *cmd,
- struct volume_group *vg,
+ const struct volume_group *vg,
struct lvresize_params *lp)
{
if (arg_sign_value(cmd, stripesize_ARG, 0) == SIGN_MINUS) {
@@ -87,9 +87,9 @@
}
static int confirm_resizefs_reduce(struct cmd_context *cmd,
- struct volume_group *vg,
- struct logical_volume *lv,
- struct lvresize_params *lp)
+ const struct volume_group *vg,
+ const struct logical_volume *lv,
+ const struct lvresize_params *lp)
{
struct lvinfo info;
@@ -131,8 +131,9 @@
return 1;
}
-static int do_resizefs_reduce(struct cmd_context *cmd, struct volume_group *vg,
- struct lvresize_params *lp)
+static int do_resizefs_reduce(const struct cmd_context *cmd,
+ const struct volume_group *vg,
+ const struct lvresize_params *lp)
{
char lv_path[PATH_MAX];
char size_buf[SIZE_BUF];
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2007-10-11 19:20 wysochanski
0 siblings, 0 replies; 13+ messages in thread
From: wysochanski @ 2007-10-11 19:20 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski at sourceware.org 2007-10-11 19:20:38
Modified files:
lib/metadata : lv_manip.c metadata-exported.h mirror.c
snapshot_manip.c
tools : lvcreate.c pvmove.c toollib.c
Log message:
Non-functional change - refactor lv_create_empty().
Remove struct format_instance param - we can safely obtain
this from vg->fid inside the function.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.129&r2=1.130
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.17&r2=1.18
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/mirror.c.diff?cvsroot=lvm2&r1=1.42&r2=1.43
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/snapshot_manip.c.diff?cvsroot=lvm2&r1=1.26&r2=1.27
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvcreate.c.diff?cvsroot=lvm2&r1=1.151&r2=1.152
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvmove.c.diff?cvsroot=lvm2&r1=1.41&r2=1.42
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.c.diff?cvsroot=lvm2&r1=1.106&r2=1.107
--- LVM2/lib/metadata/lv_manip.c 2007/09/24 21:30:00 1.129
+++ LVM2/lib/metadata/lv_manip.c 2007/10/11 19:20:38 1.130
@@ -1656,14 +1656,14 @@
/*
* Create a new empty LV.
*/
-struct logical_volume *lv_create_empty(struct format_instance *fi,
- const char *name,
+struct logical_volume *lv_create_empty(const char *name,
union lvid *lvid,
uint32_t status,
alloc_policy_t alloc,
int import,
struct volume_group *vg)
{
+ struct format_instance *fi = vg->fid;
struct cmd_context *cmd = vg->cmd;
struct lv_list *ll = NULL;
struct logical_volume *lv;
--- LVM2/lib/metadata/metadata-exported.h 2007/10/11 18:51:21 1.17
+++ LVM2/lib/metadata/metadata-exported.h 2007/10/11 19:20:38 1.18
@@ -349,8 +349,7 @@
struct volume_group *vg_to);
/* Manipulate LVs */
-struct logical_volume *lv_create_empty(struct format_instance *fi,
- const char *name,
+struct logical_volume *lv_create_empty(const char *name,
union lvid *lvid,
uint32_t status,
alloc_policy_t alloc,
--- LVM2/lib/metadata/mirror.c 2007/08/29 20:19:11 1.42
+++ LVM2/lib/metadata/mirror.c 2007/10/11 19:20:38 1.43
@@ -439,7 +439,7 @@
}
for (m = 0; m < num_mirrors; m++) {
- if (!(img_lvs[m] = lv_create_empty(lv->vg->fid, img_name,
+ if (!(img_lvs[m] = lv_create_empty(img_name,
NULL, LVM_READ | LVM_WRITE,
ALLOC_INHERIT, 0, lv->vg))) {
log_error("Aborting. Failed to create mirror image LV. "
--- LVM2/lib/metadata/snapshot_manip.c 2007/10/11 18:51:21 1.26
+++ LVM2/lib/metadata/snapshot_manip.c 2007/10/11 19:20:38 1.27
@@ -53,7 +53,6 @@
struct logical_volume *cow, union lvid *lvid,
uint32_t extent_count, uint32_t chunk_size)
{
- struct format_instance *fid = vg->fid;
struct logical_volume *snap;
struct lv_segment *seg;
@@ -65,7 +64,7 @@
return 0;
}
- if (!(snap = lv_create_empty(fid, name ? name : "snapshot%d",
+ if (!(snap = lv_create_empty(name ? name : "snapshot%d",
lvid, LVM_READ | LVM_WRITE | VISIBLE_LV,
ALLOC_INHERIT, 1, origin->vg))) {
stack;
--- LVM2/tools/lvcreate.c 2007/10/11 18:51:21 1.151
+++ LVM2/tools/lvcreate.c 2007/10/11 19:20:38 1.152
@@ -762,7 +762,7 @@
}
}
- if (!(lv = lv_create_empty(vg->fid, lv_name ? lv_name : "lvol%d", NULL,
+ if (!(lv = lv_create_empty(lv_name ? lv_name : "lvol%d", NULL,
status, lp->alloc, 0, vg))) {
stack;
goto error;
--- LVM2/tools/pvmove.c 2007/08/20 20:55:30 1.41
+++ LVM2/tools/pvmove.c 2007/10/11 19:20:38 1.42
@@ -119,7 +119,7 @@
struct lv_list *lvl;
/* FIXME Cope with non-contiguous => splitting existing segments */
- if (!(lv_mirr = lv_create_empty(vg->fid, "pvmove%d", NULL,
+ if (!(lv_mirr = lv_create_empty("pvmove%d", NULL,
LVM_READ | LVM_WRITE,
ALLOC_CONTIGUOUS, 0, vg))) {
log_error("Creation of temporary pvmove LV failed");
--- LVM2/tools/toollib.c 2007/09/11 20:12:54 1.106
+++ LVM2/tools/toollib.c 2007/10/11 19:20:38 1.107
@@ -1347,7 +1347,7 @@
return NULL;
}
- if (!(log_lv = lv_create_empty(vg->fid, log_name, NULL,
+ if (!(log_lv = lv_create_empty(log_name, NULL,
VISIBLE_LV | LVM_READ | LVM_WRITE,
alloc, 0, vg))) {
stack;
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2007-12-20 22:37 agk
0 siblings, 0 replies; 13+ messages in thread
From: agk @ 2007-12-20 22:37 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: agk at sourceware.org 2007-12-20 22:37:42
Modified files:
lib/metadata : lv_manip.c metadata-exported.h mirror.c
tools : toollib.c toollib.h
Log message:
various cleanups in recent patches
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.138&r2=1.139
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.27&r2=1.28
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/mirror.c.diff?cvsroot=lvm2&r1=1.47&r2=1.48
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.c.diff?cvsroot=lvm2&r1=1.120&r2=1.121
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.h.diff?cvsroot=lvm2&r1=1.53&r2=1.54
--- LVM2/lib/metadata/lv_manip.c 2007/12/20 18:55:46 1.138
+++ LVM2/lib/metadata/lv_manip.c 2007/12/20 22:37:42 1.139
@@ -2280,7 +2280,7 @@
struct segment_type *segtype;
struct lv_segment *mapseg;
- if (!(segtype = get_segtype_from_string(lv_where->vg->cmd, "striped")))
+ if (!(segtype = get_segtype_from_string(cmd, "striped")))
return_NULL;
/* create an empty layer LV */
@@ -2310,7 +2310,7 @@
_move_lv_segments(layer_lv, lv_where, 0, 0);
/* allocate a new linear segment */
- if (!(mapseg = alloc_lv_segment(lv_where->vg->cmd->mem, segtype,
+ if (!(mapseg = alloc_lv_segment(cmd->mem, segtype,
lv_where, 0, layer_lv->le_count,
status, 0, NULL, 1, layer_lv->le_count,
0, 0, 0)))
@@ -2520,3 +2520,51 @@
return 1;
}
+
+/*
+ * Initialize the LV with 'value'.
+ */
+int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
+ uint64_t sectors, int value)
+{
+ struct device *dev;
+ char *name;
+
+ /*
+ * FIXME:
+ * <clausen> also, more than 4k
+ * <clausen> say, reiserfs puts it's superblock 32k in, IIRC
+ * <ejt_> k, I'll drop a fixme to that effect
+ * (I know the device is at least 4k, but not 32k)
+ */
+ if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
+ log_error("Name allocation failed - device not cleared");
+ return 0;
+ }
+
+ 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);
+ return 0;
+ }
+
+ 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;
+ }
+
+ if (!dev_open_quiet(dev))
+ return 0;
+
+ dev_set(dev, UINT64_C(0),
+ sectors ? (size_t) sectors << SECTOR_SHIFT : (size_t) 4096,
+ value);
+ dev_flush(dev);
+ dev_close_immediate(dev);
+
+ return 1;
+}
+
+
--- LVM2/lib/metadata/metadata-exported.h 2007/12/20 18:55:46 1.27
+++ LVM2/lib/metadata/metadata-exported.h 2007/12/20 22:37:42 1.28
@@ -88,6 +88,10 @@
#define CORRECT_INCONSISTENT 0x00000001U /* Correct inconsistent metadata */
#define FAIL_INCONSISTENT 0x00000002U /* Fail if metadata inconsistent */
+/* Mirror conversion type flags */
+#define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */
+#define MIRROR_BY_LV 0x00000002U /* mirror by mimage LVs */
+
/* Ordered list - see lv_manip.c */
typedef enum {
ALLOC_INVALID,
@@ -355,6 +359,10 @@
int import,
struct volume_group *vg);
+/* Write out LV contents */
+int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
+ uint64_t sectors, int value);
+
/* Reduce the size of an LV by extents */
int lv_reduce(struct logical_volume *lv, uint32_t extents);
@@ -457,9 +465,6 @@
int lv_remove_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
uint32_t mirrors, uint32_t log_count,
struct list *pvs, uint32_t status_mask);
-/* conversion flags */
-#define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */
-#define MIRROR_BY_LV 0x00000002U /* mirror by mimage LVs */
int is_temporary_mirror_layer(const struct logical_volume *lv);
uint32_t lv_mirror_count(const struct logical_volume *lv);
--- LVM2/lib/metadata/mirror.c 2007/12/20 18:55:46 1.47
+++ LVM2/lib/metadata/mirror.c 2007/12/20 22:37:42 1.48
@@ -27,6 +27,11 @@
#include "defaults.h" /* FIXME: should this be defaults.h? */
+/* These are necessary for _write_log_header() */
+#include "xlate.h"
+#define MIRROR_MAGIC 0x4D695272
+#define MIRROR_DISK_VERSION 2
+
/* These are the flags that represent the mirror failure restoration policies */
#define MIRROR_REMOVE 0
#define MIRROR_ALLOCATE 1
@@ -332,7 +337,7 @@
static int _merge_mirror_images(struct logical_volume *lv,
const struct list *mimages)
{
- int addition = list_size(mimages);
+ uint32_t addition = list_size(mimages);
struct logical_volume **img_lvs;
struct lv_list *lvl;
int i = 0;
@@ -893,60 +898,10 @@
}
/*
- * Initialize the LV with 'value'.
- */
-static int _set_lv(struct cmd_context *cmd, struct logical_volume *lv,
- uint64_t sectors, int value)
-{
- struct device *dev;
- char *name;
-
- /*
- * FIXME:
- * <clausen> also, more than 4k
- * <clausen> say, reiserfs puts it's superblock 32k in, IIRC
- * <ejt_> k, I'll drop a fixme to that effect
- * (I know the device is at least 4k, but not 32k)
- */
- if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
- log_error("Name allocation failed - device not cleared");
- return 0;
- }
-
- 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);
- return 0;
- }
-
- 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;
- }
-
- if (!dev_open_quiet(dev))
- return 0;
-
- dev_set(dev, UINT64_C(0),
- sectors ? (size_t) sectors << SECTOR_SHIFT : (size_t) 4096,
- value);
- dev_flush(dev);
- dev_close_immediate(dev);
-
- return 1;
-}
-
-/*
* This function writes a new header to the mirror log header to the lv
*
* Returns: 1 on success, 0 on failure
*/
-#include "xlate.h"
-#define MIRROR_MAGIC 0x4D695272
-#define MIRROR_DISK_VERSION 2
-
static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv)
{
struct device *dev;
@@ -1036,7 +991,7 @@
log_error("Failed to remove tag %s from mirror log.",
sl->str);
- if (activation() && !_set_lv(cmd, log_lv, log_lv->size,
+ 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;
@@ -1072,11 +1027,10 @@
return 0;
}
-static struct logical_volume *_create_mirror_log(struct cmd_context *cmd,
- struct logical_volume *lv,
- struct alloc_handle *ah,
- alloc_policy_t alloc,
- const char *lv_name)
+static struct logical_volume *_create_mirror_log(struct logical_volume *lv,
+ struct alloc_handle *ah,
+ alloc_policy_t alloc,
+ const char *lv_name)
{
struct logical_volume *log_lv;
char *log_name;
@@ -1108,7 +1062,7 @@
struct alloc_handle *ah,
struct logical_volume *lv,
uint32_t log_count,
- uint32_t region_size,
+ uint32_t region_size __attribute((unused)),
alloc_policy_t alloc,
int in_sync)
{
@@ -1116,7 +1070,12 @@
init_mirror_in_sync(in_sync);
- if (!(log_lv = _create_mirror_log(cmd, lv, ah, alloc, lv->name))) {
+ if (log_count != 1) {
+ log_error("log_count != 1 is not supported.");
+ return NULL;
+ }
+
+ if (!(log_lv = _create_mirror_log(lv, ah, alloc, lv->name))) {
log_error("Failed to create mirror log.");
return NULL;
}
@@ -1341,7 +1300,8 @@
* 'mirror' is the number of mirrors to be removed.
* 'pvs' is removable pvs.
*/
-int lv_remove_mirrors(struct cmd_context *cmd, struct logical_volume *lv,
+int lv_remove_mirrors(struct cmd_context *cmd __attribute((unused)),
+ struct logical_volume *lv,
uint32_t mirrors, uint32_t log_count, struct list *pvs,
uint32_t status_mask)
{
--- LVM2/tools/toollib.c 2007/12/20 18:55:46 1.120
+++ LVM2/tools/toollib.c 2007/12/20 22:37:42 1.121
@@ -1246,50 +1246,3 @@
return 1;
}
-
-/*
- * Initialize the LV with 'value'.
- */
-int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
- uint64_t sectors, int value)
-{
- struct device *dev;
- char *name;
-
- /*
- * FIXME:
- * <clausen> also, more than 4k
- * <clausen> say, reiserfs puts it's superblock 32k in, IIRC
- * <ejt_> k, I'll drop a fixme to that effect
- * (I know the device is at least 4k, but not 32k)
- */
- if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
- log_error("Name allocation failed - device not cleared");
- return 0;
- }
-
- 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);
- return 0;
- }
-
- 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;
- }
-
- if (!dev_open_quiet(dev))
- return 0;
-
- dev_set(dev, UINT64_C(0),
- sectors ? (size_t) sectors << SECTOR_SHIFT : (size_t) 4096,
- value);
- dev_flush(dev);
- dev_close_immediate(dev);
-
- return 1;
-}
-
--- LVM2/tools/toollib.h 2007/12/20 15:42:55 1.53
+++ LVM2/tools/toollib.h 2007/12/20 22:37:42 1.54
@@ -98,7 +98,4 @@
int validate_new_vg_name(struct cmd_context *cmd, const char *vg_name);
-int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
- uint64_t sectors, int value);
-
#endif
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2008-01-17 13:13 agk
0 siblings, 0 replies; 13+ messages in thread
From: agk @ 2008-01-17 13:13 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: agk at sourceware.org 2008-01-17 13:13:55
Modified files:
lib/metadata : lv_manip.c metadata-exported.h mirror.c
tools : vgreduce.c
Log message:
lvconvert/vgreduce fixes
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.142&r2=1.143
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.37&r2=1.38
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/mirror.c.diff?cvsroot=lvm2&r1=1.59&r2=1.60
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgreduce.c.diff?cvsroot=lvm2&r1=1.73&r2=1.74
--- LVM2/lib/metadata/lv_manip.c 2008/01/16 20:00:01 1.142
+++ LVM2/lib/metadata/lv_manip.c 2008/01/17 13:13:54 1.143
@@ -459,6 +459,24 @@
}
/*
+ * Empty an LV and add error segment.
+ */
+int lv_remap_error(struct logical_volume *lv)
+{
+ uint32_t len = lv->le_count;
+
+ if (!lv_empty(lv))
+ return_0;
+
+ if (!lv_add_virtual_segment(lv, 0, len,
+ get_segtype_from_string(lv->vg->cmd,
+ "error")))
+ return_0;
+
+ return 1;
+}
+
+/*
* Remove given number of extents from LV.
*/
int lv_reduce(struct logical_volume *lv, uint32_t extents)
--- LVM2/lib/metadata/metadata-exported.h 2008/01/16 19:54:39 1.37
+++ LVM2/lib/metadata/metadata-exported.h 2008/01/17 13:13:54 1.38
@@ -378,6 +378,9 @@
/* Empty an LV prior to deleting it */
int lv_empty(struct logical_volume *lv);
+/* Empty an LV and add error segment */
+int lv_remap_error(struct logical_volume *lv);
+
/* Entry point for all LV extent allocations */
int lv_extend(struct logical_volume *lv,
const struct segment_type *segtype,
--- LVM2/lib/metadata/mirror.c 2008/01/16 19:50:23 1.59
+++ LVM2/lib/metadata/mirror.c 2008/01/17 13:13:54 1.60
@@ -373,11 +373,34 @@
/*
* Remove num_removed images from mirrored_seg
+ *
+ * Arguments:
+ * num_removed: the requested (maximum) number of mirrors to be removed
+ * removable_pvs: if not NULL, only mirrors using PVs in this list
+ * will be removed
+ * remove_log: if non-zero, log_lv will be removed
+ * (even if it's 0, log_lv will be removed if there is no
+ * mirror remaining after the removal)
+ * collapse: if non-zero, instead of removing, remove the temporary
+ * mirror layer and merge mirrors to the original LV.
+ * removable_pvs should be NULL and num_removed should be
+ * seg->area_count - 1.
+ * removed: if non NULL, the number of removed mirror images is set
+ * as a result
+ *
+ * If collapse is non-zero, <removed> is guaranteed to be equal to num_removed.
+ *
+ * Return values:
+ * Failure (0) means something unexpected has happend and
+ * the caller should abort.
+ * Even if no mirror was removed (e.g. no LV matches to 'removable_pvs'),
+ * returns success (1).
*/
static int _remove_mirror_images(struct logical_volume *lv,
uint32_t num_removed,
struct list *removable_pvs,
- unsigned remove_log, unsigned collapse)
+ unsigned remove_log, unsigned collapse,
+ uint32_t *removed)
{
uint32_t m;
uint32_t s;
@@ -391,6 +414,9 @@
struct lv_list *lvl;
struct list tmp_orphan_lvs;
+ if (removed)
+ *removed = 0;
+
log_very_verbose("Reducing mirror set from %" PRIu32 " to %"
PRIu32 " image(s)%s.",
old_area_count, old_area_count - num_removed,
@@ -407,7 +433,8 @@
for (s = 0; s < mirrored_seg->area_count &&
old_area_count - new_area_count < num_removed; s++) {
sub_lv = seg_lv(mirrored_seg, s);
- if (_is_mirror_image_removable(sub_lv, removable_pvs)) {
+ if (!is_temporary_mirror_layer(sub_lv) &&
+ _is_mirror_image_removable(sub_lv, removable_pvs)) {
/* Swap segment to end */
new_area_count--;
area = mirrored_seg->areas[new_area_count];
@@ -415,10 +442,8 @@
mirrored_seg->areas[s] = area;
}
}
- if (num_removed && old_area_count == new_area_count) {
- log_error("No mirror images found using specified PVs.");
- return 0;
- }
+ if (num_removed && old_area_count == new_area_count)
+ return 1;
} else
new_area_count = old_area_count - num_removed;
@@ -442,7 +467,10 @@
log_lv = mirrored_seg->log_lv;
/* If no more mirrors, remove mirror layer */
- if (new_area_count == 1) {
+ /* As an exceptional case, if the lv is temporary layer,
+ * leave the LV as mirrored and let the lvconvert completion
+ * to remove the layer. */
+ if (new_area_count == 1 && !is_temporary_mirror_layer(lv)) {
lv1 = seg_lv(mirrored_seg, 0);
_remove_mirror_log(mirrored_seg);
if (!remove_layer_from_lv(lv, lv1))
@@ -454,6 +482,15 @@
log_error("Failed to add mirror images");
return 0;
}
+ } else if (new_area_count == 0) {
+ /* All mirror images are gone.
+ * It can happen for vgreduce --removemissing. */
+ _remove_mirror_log(mirrored_seg);
+ lv->status &= ~MIRRORED;
+ lv->status &= ~MIRROR_NOTSYNCED;
+ if (!lv_remap_error(lv))
+ return_0;
+ remove_log = 1;
} else if (remove_log)
_remove_mirror_log(mirrored_seg);
@@ -502,6 +539,20 @@
if (remove_log && log_lv && !_delete_lv(lv, log_lv))
return 0;
+ /* Mirror with only 1 area is 'in sync'. */
+ if (!remove_log && log_lv &&
+ new_area_count == 1 && is_temporary_mirror_layer(lv)) {
+ if (!_init_mirror_log(lv->vg->cmd, log_lv, 1, &lv->tags, 0)) {
+ /* As a result, unnecessary sync may run after
+ * collapsing. But safe.*/
+ log_error("Failed to initialize log device");
+ return_0;
+ }
+ }
+
+ if (removed)
+ *removed = old_area_count - new_area_count;
+
return 1;
}
@@ -511,24 +562,43 @@
int remove_mirror_images(struct logical_volume *lv, uint32_t num_mirrors,
struct list *removable_pvs, unsigned remove_log)
{
- uint32_t num_removed, removed_once;
+ uint32_t num_removed, removed_once, r;
uint32_t existing_mirrors = lv_mirror_count(lv);
+ struct logical_volume *next_lv = lv;
num_removed = existing_mirrors - num_mirrors;
/* num_removed can be 0 if the function is called just to remove log */
do {
- if (num_removed < first_seg(lv)->area_count)
+ if (num_removed < first_seg(next_lv)->area_count)
removed_once = num_removed;
else
- removed_once = first_seg(lv)->area_count - 1;
+ removed_once = first_seg(next_lv)->area_count - 1;
- if (!_remove_mirror_images(lv, removed_once,
- removable_pvs, remove_log, 0))
+ if (!_remove_mirror_images(next_lv, removed_once,
+ removable_pvs, remove_log, 0, &r))
return_0;
- num_removed -= removed_once;
- } while (num_removed);
+ if (r < removed_once) {
+ /* Some mirrors are removed from the temporary mirror,
+ * but the temporary layer still exists.
+ * Down the stack and retry for remainder. */
+ next_lv = find_tmp_mirror(next_lv);
+ }
+
+ num_removed -= r;
+ } while (next_lv && num_removed);
+
+ if (num_removed) {
+ if (num_removed == existing_mirrors - num_mirrors)
+ log_error("No mirror images found using specified PVs.");
+ else {
+ log_error("%u images are removed out of requested %u.",
+ existing_mirrors - lv_mirror_count(lv),
+ existing_mirrors - num_mirrors);
+ }
+ return 0;
+ }
return 1;
}
@@ -581,7 +651,7 @@
if (!_remove_mirror_images(mirror_seg->lv,
mirror_seg->area_count - 1,
- NULL, 1, 1)) {
+ NULL, 1, 1, NULL)) {
log_error("Failed to release mirror images");
return 0;
}
@@ -701,8 +771,8 @@
*/
init_mirror_in_sync(in_sync);
- r = remove_mirror_images(mirrored_seg->lv, num_mirrors,
- removable_pvs, remove_log);
+ r = _remove_mirror_images(mirrored_seg->lv, old_num_mirrors - num_mirrors,
+ removable_pvs, remove_log, 0, NULL);
if (!r)
/* Unable to remove bad devices */
return 0;
--- LVM2/tools/vgreduce.c 2008/01/16 19:00:59 1.73
+++ LVM2/tools/vgreduce.c 2008/01/17 13:13:54 1.74
@@ -255,8 +255,10 @@
}
}
+ lvs_changed_altered:
/* Remove lost mirror images from mirrors */
list_iterate_items(lvl, &vg->lvs) {
+ mirrored_seg_altered:
mirrored_seg = first_seg(lvl->lv);
if (!seg_is_mirrored(mirrored_seg))
continue;
@@ -315,6 +317,23 @@
vg_revert(vg);
return 0;
}
+
+ /* mirrored LV no longer has valid mimages.
+ * So add it to lvs_changed for removal.
+ * For this LV may be an area of other mirror,
+ * restart the loop. */
+ if (!mimages) {
+ if (!_remove_lv(cmd, lvl->lv,
+ &list_unsafe, &lvs_changed))
+ return_0;
+ goto lvs_changed_altered;
+ }
+
+ /* As a result of reconfigure_mirror_images(),
+ * first_seg(lv) may now be different seg.
+ * e.g. a temporary layer might be removed.
+ * So check the mirrored_seg again. */
+ goto mirrored_seg_altered;
}
}
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2008-01-17 13:54 agk
0 siblings, 0 replies; 13+ messages in thread
From: agk @ 2008-01-17 13:54 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: agk at sourceware.org 2008-01-17 13:54:05
Modified files:
lib/metadata : lv_manip.c metadata-exported.h mirror.c
tools : vgreduce.c
Log message:
rename lv_remap_error
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.143&r2=1.144
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.38&r2=1.39
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/mirror.c.diff?cvsroot=lvm2&r1=1.61&r2=1.62
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgreduce.c.diff?cvsroot=lvm2&r1=1.74&r2=1.75
--- LVM2/lib/metadata/lv_manip.c 2008/01/17 13:13:54 1.143
+++ LVM2/lib/metadata/lv_manip.c 2008/01/17 13:54:05 1.144
@@ -461,7 +461,7 @@
/*
* Empty an LV and add error segment.
*/
-int lv_remap_error(struct logical_volume *lv)
+int replace_lv_with_error_segment(struct logical_volume *lv)
{
uint32_t len = lv->le_count;
--- LVM2/lib/metadata/metadata-exported.h 2008/01/17 13:13:54 1.38
+++ LVM2/lib/metadata/metadata-exported.h 2008/01/17 13:54:05 1.39
@@ -379,7 +379,7 @@
int lv_empty(struct logical_volume *lv);
/* Empty an LV and add error segment */
-int lv_remap_error(struct logical_volume *lv);
+int replace_lv_with_error_segment(struct logical_volume *lv);
/* Entry point for all LV extent allocations */
int lv_extend(struct logical_volume *lv,
--- LVM2/lib/metadata/mirror.c 2008/01/17 13:37:51 1.61
+++ LVM2/lib/metadata/mirror.c 2008/01/17 13:54:05 1.62
@@ -521,7 +521,7 @@
_remove_mirror_log(mirrored_seg);
lv->status &= ~MIRRORED;
lv->status &= ~MIRROR_NOTSYNCED;
- if (!lv_remap_error(lv))
+ if (!replace_lv_with_error_segment(lv))
return_0;
remove_log = 1;
} else if (remove_log)
@@ -616,7 +616,7 @@
/* Some mirrors are removed from the temporary mirror,
* but the temporary layer still exists.
* Down the stack and retry for remainder. */
- next_lv = find_tmp_mirror(next_lv);
+ next_lv = find_temporary_mirror(next_lv);
}
num_removed -= r;
--- LVM2/tools/vgreduce.c 2008/01/17 13:13:54 1.74
+++ LVM2/tools/vgreduce.c 2008/01/17 13:54:05 1.75
@@ -54,7 +54,6 @@
struct list *snh, *snht;
struct logical_volume *cow;
struct lv_list *lvl;
- uint32_t extents;
struct lvinfo info;
int first = 1;
@@ -116,19 +115,10 @@
* the mirrored LV also should be cleaned up.
* Clean-up is currently done by caller (_make_vg_consistent()).
*/
- if ((lv_info(cmd, lv, &info, 0, 0) && info.exists)
- || find_mirror_seg(first_seg(lv))) {
- extents = lv->le_count;
- if (!lv_empty(lv)) {
- stack;
- return 0;
- }
- if (!lv_add_virtual_segment(lv, 0, extents,
- get_segtype_from_string(cmd,
- "error"))) {
- stack;
- return 0;
- }
+ if ((lv_info(cmd, lv, &info, 0, 0) && info.exists) ||
+ find_mirror_seg(first_seg(lv))) {
+ if (!replace_lv_with_error_segment(lv))
+ return_0;
if (!(lvl = dm_pool_alloc(cmd->mem, sizeof(*lvl)))) {
log_error("lv_list alloc failed");
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2008-08-05 12:05 zkabelac
0 siblings, 0 replies; 13+ messages in thread
From: zkabelac @ 2008-08-05 12:05 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: zkabelac at sourceware.org 2008-08-05 12:05:26
Modified files:
lib/metadata : lv_manip.c metadata-exported.h metadata.c
. : WHATS_NEW
Log message:
vgremove tries to remove lv snapshot first.
Added function lv_remove_with_dependencies().
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.154&r2=1.155
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.49&r2=1.50
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.184&r2=1.185
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.943&r2=1.944
--- LVM2/lib/metadata/lv_manip.c 2008/04/22 12:54:33 1.154
+++ LVM2/lib/metadata/lv_manip.c 2008/08/05 12:05:25 1.155
@@ -2049,6 +2049,27 @@
}
/*
+ * remove LVs with its dependencies - LV leaf nodes should be removed first
+ */
+int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *lv,
+ const force_t force)
+{
+ struct list *snh, *snht;
+
+ if (lv_is_origin(lv)) {
+ /* remove snapshot LVs first */
+ list_iterate_safe(snh, snht, &lv->snapshot_segs) {
+ if (!lv_remove_with_dependencies(cmd, list_struct_base(snh, struct lv_segment,
+ origin_list)->cow,
+ force))
+ return 0;
+ }
+ }
+
+ return lv_remove_single(cmd, lv, force);
+}
+
+/*
* insert_layer_for_segments_on_pv() inserts a layer segment for a segment area.
* However, layer modification could split the underlying layer segment.
* This function splits the parent area according to keep the 1:1 relationship
--- LVM2/lib/metadata/metadata-exported.h 2008/06/24 20:10:31 1.49
+++ LVM2/lib/metadata/metadata-exported.h 2008/08/05 12:05:25 1.50
@@ -416,6 +416,9 @@
int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
force_t force);
+int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *lv,
+ force_t force);
+
int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
const char *new_name);
--- LVM2/lib/metadata/metadata.c 2008/06/27 15:18:31 1.184
+++ LVM2/lib/metadata/metadata.c 2008/08/05 12:05:25 1.185
@@ -298,8 +298,8 @@
{
struct lv_list *lvl;
- list_iterate_items(lvl, &vg->lvs)
- if (!lv_remove_single(cmd, lvl->lv, force))
+ while ((lvl = list_first(&vg->lvs)))
+ if (!lv_remove_with_dependencies(cmd, lvl->lv, force))
return 0;
return 1;
--- LVM2/WHATS_NEW 2008/08/01 19:51:27 1.943
+++ LVM2/WHATS_NEW 2008/08/05 12:05:26 1.944
@@ -1,5 +1,7 @@
Version 2.02.40 -
================================
+ vgremove tries to remove lv snapshot first.
+ Added function lv_remove_with_dependencies().
Improve file descriptor leak detection to display likely culprit and filename.
Change clustered mirror kernel module name from cmirror to dm-log-clustered.
Avoid looping forever in _pv_analyze_mda_raw used by pvck.
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2009-07-26 2:33 wysochanski
0 siblings, 0 replies; 13+ messages in thread
From: wysochanski @ 2009-07-26 2:33 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: wysochanski at sourceware.org 2009-07-26 02:33:35
Modified files:
lib/metadata : lv_manip.c metadata-exported.h
tools : lvcreate.c
Log message:
Move _lvcreate into the internal library and rename to lv_create_single.
After some refactorings, we can now move the bulk of _lvcreate into the
internal library, and we can call from liblvm. In the future, we should
refactor lv_create_single further, probably by segtype, to reduce the
size of struct lvcreate_params. For now this is a reasonable refactor
and allows us to re-use the function from liblvm.
Author: Dave Wysochanski <dwysocha@redhat.com>
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.182&r2=1.183
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.99&r2=1.100
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvcreate.c.diff?cvsroot=lvm2&r1=1.205&r2=1.206
--- LVM2/lib/metadata/lv_manip.c 2009/07/15 20:02:47 1.182
+++ LVM2/lib/metadata/lv_manip.c 2009/07/26 02:33:35 1.183
@@ -25,6 +25,7 @@
#include "segtype.h"
#include "archiver.h"
#include "activate.h"
+#include "str_list.h"
struct lv_names {
const char *old;
@@ -2772,3 +2773,384 @@
return 1;
}
+
+
+static struct logical_volume *_create_virtual_origin(struct cmd_context *cmd,
+ struct volume_group *vg,
+ const char *lv_name,
+ uint32_t permission,
+ uint64_t voriginextents)
+{
+ const struct segment_type *segtype;
+ size_t len;
+ char *vorigin_name;
+ struct logical_volume *lv;
+
+ if (!(segtype = get_segtype_from_string(cmd, "zero"))) {
+ log_error("Zero segment type for virtual origin not found");
+ return NULL;
+ }
+
+ len = strlen(lv_name) + 32;
+ if (!(vorigin_name = alloca(len)) ||
+ dm_snprintf(vorigin_name, len, "%s_vorigin", lv_name) < 0) {
+ log_error("Virtual origin name allocation failed.");
+ return NULL;
+ }
+
+ if (!(lv = lv_create_empty(vorigin_name, NULL, permission,
+ ALLOC_INHERIT, vg)))
+ return_NULL;
+
+ if (!lv_extend(lv, segtype, 1, 0, 1, voriginextents, NULL, 0u, 0u,
+ NULL, ALLOC_INHERIT))
+ return_NULL;
+
+ /* store vg on disk(s) */
+ if (!vg_write(vg) || !vg_commit(vg))
+ return_NULL;
+
+ backup(vg);
+
+ return lv;
+}
+
+int lv_create_single(struct volume_group *vg,
+ struct lvcreate_params *lp)
+{
+ struct cmd_context *cmd = vg->cmd;
+ uint32_t size_rest;
+ uint32_t status = 0;
+ struct logical_volume *lv, *org = NULL;
+ int origin_active = 0;
+ char lv_name_buf[128];
+ const char *lv_name;
+ struct lvinfo info;
+
+ if (lp->lv_name && find_lv_in_vg(vg, lp->lv_name)) {
+ log_error("Logical volume \"%s\" already exists in "
+ "volume group \"%s\"", lp->lv_name, lp->vg_name);
+ return 0;
+ }
+
+ if (vg_max_lv_reached(vg)) {
+ log_error("Maximum number of logical volumes (%u) reached "
+ "in volume group %s", vg->max_lv, vg->name);
+ return 0;
+ }
+
+ if (lp->mirrors > 1 && !(vg->fid->fmt->features & FMT_SEGMENTS)) {
+ log_error("Metadata does not support mirroring.");
+ return 0;
+ }
+
+ if (lp->read_ahead != DM_READ_AHEAD_AUTO &&
+ lp->read_ahead != DM_READ_AHEAD_NONE &&
+ (vg->fid->fmt->features & FMT_RESTRICTED_READAHEAD) &&
+ (lp->read_ahead < 2 || lp->read_ahead > 120)) {
+ log_error("Metadata only supports readahead values between 2 and 120.");
+ return 0;
+ }
+
+ if (lp->stripe_size > vg->extent_size) {
+ log_error("Reducing requested stripe size %s to maximum, "
+ "physical extent size %s",
+ display_size(cmd, (uint64_t) lp->stripe_size),
+ display_size(cmd, (uint64_t) vg->extent_size));
+ lp->stripe_size = vg->extent_size;
+ }
+
+ /* Need to check the vg's format to verify this - the cmd format isn't setup properly yet */
+ if (lp->stripes > 1 &&
+ !(vg->fid->fmt->features & FMT_UNLIMITED_STRIPESIZE) &&
+ (lp->stripe_size > STRIPE_SIZE_MAX)) {
+ log_error("Stripe size may not exceed %s",
+ display_size(cmd, (uint64_t) STRIPE_SIZE_MAX));
+ return 0;
+ }
+
+ if ((size_rest = lp->extents % lp->stripes)) {
+ log_print("Rounding size (%d extents) up to stripe boundary "
+ "size (%d extents)", lp->extents,
+ lp->extents - size_rest + lp->stripes);
+ lp->extents = lp->extents - size_rest + lp->stripes;
+ }
+
+ if (lp->zero && !activation()) {
+ log_error("Can't wipe start of new LV without using "
+ "device-mapper kernel driver");
+ return 0;
+ }
+
+ status |= lp->permission | VISIBLE_LV;
+
+ if (lp->snapshot) {
+ if (!activation()) {
+ log_error("Can't create snapshot without using "
+ "device-mapper kernel driver");
+ return 0;
+ }
+ /* FIXME Allow exclusive activation. */
+ if (vg_is_clustered(vg)) {
+ log_error("Clustered snapshots are not yet supported.");
+ return 0;
+ }
+
+ /* Must zero cow */
+ status |= LVM_WRITE;
+
+ if (lp->voriginsize)
+ origin_active = 1;
+ else {
+
+ if (!(org = find_lv(vg, lp->origin))) {
+ log_error("Couldn't find origin volume '%s'.",
+ lp->origin);
+ return 0;
+ }
+ if (lv_is_virtual_origin(org)) {
+ log_error("Can't share virtual origins. "
+ "Use --virtualsize.");
+ return 0;
+ }
+ if (lv_is_cow(org)) {
+ log_error("Snapshots of snapshots are not "
+ "supported yet.");
+ return 0;
+ }
+ if (org->status & LOCKED) {
+ log_error("Snapshots of locked devices are not "
+ "supported yet");
+ return 0;
+ }
+ if (org->status & MIRROR_IMAGE ||
+ org->status & MIRROR_LOG ||
+ org->status & MIRRORED) {
+ log_error("Snapshots and mirrors may not yet "
+ "be mixed.");
+ return 0;
+ }
+
+ if (!lv_info(cmd, org, &info, 0, 0)) {
+ log_error("Check for existence of snapshot "
+ "origin '%s' failed.", org->name);
+ return 0;
+ }
+ origin_active = info.exists;
+ }
+ }
+
+ if (!lp->extents) {
+ log_error("Unable to create new logical volume with no extents");
+ return 0;
+ }
+
+ if (!seg_is_virtual(lp) &&
+ vg->free_count < lp->extents) {
+ log_error("Insufficient free extents (%u) in volume group %s: "
+ "%u required", vg->free_count, vg->name, lp->extents);
+ return 0;
+ }
+
+ if (lp->stripes > dm_list_size(lp->pvh) && lp->alloc != ALLOC_ANYWHERE) {
+ log_error("Number of stripes (%u) must not exceed "
+ "number of physical volumes (%d)", lp->stripes,
+ dm_list_size(lp->pvh));
+ return 0;
+ }
+
+ if (lp->mirrors > 1 && !activation()) {
+ log_error("Can't create mirror without using "
+ "device-mapper kernel driver.");
+ return 0;
+ }
+
+ /* The snapshot segment gets created later */
+ if (lp->snapshot &&
+ !(lp->segtype = get_segtype_from_string(cmd, "striped")))
+ return_0;
+
+ if (!archive(vg))
+ return 0;
+
+ if (lp->lv_name)
+ lv_name = lp->lv_name;
+ else {
+ if (!generate_lv_name(vg, "lvol%d", lv_name_buf, sizeof(lv_name_buf))) {
+ log_error("Failed to generate LV name.");
+ return 0;
+ }
+ lv_name = &lv_name_buf[0];
+ }
+
+ if (lp->tag) {
+ if (!(vg->fid->fmt->features & FMT_TAGS)) {
+ log_error("Volume group %s does not support tags",
+ vg->name);
+ return 0;
+ }
+ }
+
+ if (lp->mirrors > 1) {
+ init_mirror_in_sync(lp->nosync);
+
+ if (lp->nosync) {
+ log_warn("WARNING: New mirror won't be synchronised. "
+ "Don't read what you didn't write!");
+ status |= MIRROR_NOTSYNCED;
+ }
+ }
+
+ if (!(lv = lv_create_empty(lv_name ? lv_name : "lvol%d", NULL,
+ status, lp->alloc, vg)))
+ return_0;
+
+ if (lp->read_ahead) {
+ log_verbose("Setting read ahead sectors");
+ lv->read_ahead = lp->read_ahead;
+ }
+
+ if (lp->minor >= 0) {
+ lv->major = lp->major;
+ lv->minor = lp->minor;
+ lv->status |= FIXED_MINOR;
+ log_verbose("Setting device number to (%d, %d)", lv->major,
+ lv->minor);
+ }
+
+ if (lp->tag && !str_list_add(cmd->mem, &lv->tags, lp->tag)) {
+ log_error("Failed to add tag %s to %s/%s",
+ lp->tag, lv->vg->name, lv->name);
+ return 0;
+ }
+
+ if (!lv_extend(lv, lp->segtype, lp->stripes, lp->stripe_size,
+ 1, lp->extents, NULL, 0u, 0u, lp->pvh, lp->alloc))
+ return_0;
+
+ if (lp->mirrors > 1) {
+ if (!lv_add_mirrors(cmd, lv, lp->mirrors - 1, lp->stripes,
+ adjusted_mirror_region_size(
+ vg->extent_size,
+ lv->le_count,
+ lp->region_size),
+ lp->corelog ? 0U : 1U, lp->pvh, lp->alloc,
+ MIRROR_BY_LV |
+ (lp->nosync ? MIRROR_SKIP_INIT_SYNC : 0))) {
+ stack;
+ goto revert_new_lv;
+ }
+ }
+
+ /* store vg on disk(s) */
+ if (!vg_write(vg) || !vg_commit(vg))
+ return_0;
+
+ backup(vg);
+
+ if (lp->snapshot) {
+ if (!activate_lv_excl(cmd, lv)) {
+ log_error("Aborting. Failed to activate snapshot "
+ "exception store.");
+ goto revert_new_lv;
+ }
+ } else if (!activate_lv(cmd, lv)) {
+ if (lp->zero) {
+ log_error("Aborting. Failed to activate new LV to wipe "
+ "the start of it.");
+ goto deactivate_and_revert_new_lv;
+ }
+ log_error("Failed to activate new LV.");
+ return 0;
+ }
+
+ if (!lp->zero && !lp->snapshot)
+ log_error("WARNING: \"%s\" not zeroed", lv->name);
+ else if (!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 (lp->snapshot) {
+ /* Reset permission after zeroing */
+ if (!(lp->permission & LVM_WRITE))
+ lv->status &= ~LVM_WRITE;
+
+ /* COW area must be deactivated if origin is not active */
+ if (!origin_active && !deactivate_lv(cmd, lv)) {
+ log_error("Aborting. Couldn't deactivate snapshot "
+ "COW area. Manual intervention required.");
+ return 0;
+ }
+
+ /* A virtual origin must be activated explicitly. */
+ if (lp->voriginsize &&
+ (!(org = _create_virtual_origin(cmd, vg, lv->name,
+ lp->permission,
+ lp->voriginextents)) ||
+ !activate_lv(cmd, org))) {
+ log_error("Couldn't create virtual origin for LV %s",
+ lv->name);
+ if (org && !lv_remove(org))
+ stack;
+ goto deactivate_and_revert_new_lv;
+ }
+
+ /* cow LV remains active and becomes snapshot LV */
+
+ if (!vg_add_snapshot(org, lv, NULL,
+ org->le_count, lp->chunk_size)) {
+ log_error("Couldn't create snapshot.");
+ goto deactivate_and_revert_new_lv;
+ }
+
+ /* store vg on disk(s) */
+ if (!vg_write(vg))
+ return_0;
+
+ if (!suspend_lv(cmd, org)) {
+ log_error("Failed to suspend origin %s", org->name);
+ vg_revert(vg);
+ return 0;
+ }
+
+ if (!vg_commit(vg))
+ return_0;
+
+ if (!resume_lv(cmd, org)) {
+ log_error("Problem reactivating origin %s", org->name);
+ return 0;
+ }
+ }
+ /* FIXME out of sequence */
+ backup(vg);
+
+ log_print("Logical volume \"%s\" created", lv->name);
+
+ /*
+ * FIXME: as a sanity check we could try reading the
+ * last block of the device ?
+ */
+
+ return 1;
+
+deactivate_and_revert_new_lv:
+ if (!deactivate_lv(cmd, lv)) {
+ log_error("Unable to deactivate failed new LV. "
+ "Manual intervention required.");
+ return 0;
+ }
+
+revert_new_lv:
+ /* FIXME Better to revert to backup of metadata? */
+ if (!lv_remove(lv) || !vg_write(vg) || !vg_commit(vg))
+ log_error("Manual intervention may be required to remove "
+ "abandoned LV(s) before retrying.");
+ else
+ backup(vg);
+
+ return 0;
+}
+
--- LVM2/lib/metadata/metadata-exported.h 2009/07/26 02:02:22 1.99
+++ LVM2/lib/metadata/metadata-exported.h 2009/07/26 02:33:35 1.100
@@ -495,6 +495,45 @@
int lv_rename(struct cmd_context *cmd, struct logical_volume *lv,
const char *new_name);
+/* FIXME: refactor and reduce the size of this struct! */
+struct lvcreate_params {
+ /* flags */
+ int snapshot; /* snap */
+ int zero; /* all */
+ int major; /* all */
+ int minor; /* all */
+ int corelog; /* mirror */
+ int nosync; /* mirror */
+
+ char *origin; /* snap */
+ const char *vg_name; /* all */
+ const char *lv_name; /* all */
+
+ uint32_t stripes; /* striped */
+ uint32_t stripe_size; /* striped */
+ uint32_t chunk_size; /* snapshot */
+ uint32_t region_size; /* mirror */
+
+ uint32_t mirrors; /* mirror */
+
+ const struct segment_type *segtype; /* all */
+
+ /* size */
+ uint32_t extents; /* all */
+ uint32_t voriginextents; /* snapshot */
+ uint64_t voriginsize; /* snapshot */
+ struct dm_list *pvh; /* all */
+
+ uint32_t permission; /* all */
+ uint32_t read_ahead; /* all */
+ alloc_policy_t alloc; /* all */
+
+ const char *tag; /* all */
+};
+
+int lv_create_single(struct volume_group *vg,
+ struct lvcreate_params *lp);
+
/*
* Functions for layer manipulation
*/
--- LVM2/tools/lvcreate.c 2009/07/26 02:32:50 1.205
+++ LVM2/tools/lvcreate.c 2009/07/26 02:33:35 1.206
@@ -25,42 +25,6 @@
int pv_count;
};
-/* FIXME: refactor and reduce the size of this struct! */
-struct lvcreate_params {
- /* flags */
- int snapshot; /* snap */
- int zero; /* all */
- int major; /* all */
- int minor; /* all */
- int corelog; /* mirror */
- int nosync; /* mirror */
-
- char *origin; /* snap */
- const char *vg_name; /* all */
- const char *lv_name; /* all */
-
- uint32_t stripes; /* striped */
- uint32_t stripe_size; /* striped */
- uint32_t chunk_size; /* snapshot */
- uint32_t region_size; /* mirror */
-
- uint32_t mirrors; /* mirror */
-
- const struct segment_type *segtype; /* all */
-
- /* size */
- uint32_t extents; /* all */
- uint32_t voriginextents; /* snapshot */
- uint64_t voriginsize; /* snapshot */
- struct dm_list *pvh; /* all */
-
- uint32_t permission; /* all */
- uint32_t read_ahead; /* all */
- alloc_policy_t alloc; /* all */
-
- const char *tag; /* all */
-};
-
static uint64_t _extents_from_size(struct cmd_context *cmd, uint64_t size,
uint32_t extent_size);
@@ -631,385 +595,6 @@
return (uint64_t) size / extent_size;
}
-static struct logical_volume *_create_virtual_origin(struct cmd_context *cmd,
- struct volume_group *vg,
- const char *lv_name,
- uint32_t permission,
- uint64_t voriginextents)
-{
- const struct segment_type *segtype;
- size_t len;
- char *vorigin_name;
- struct logical_volume *lv;
-
- if (!(segtype = get_segtype_from_string(cmd, "zero"))) {
- log_error("Zero segment type for virtual origin not found");
- return NULL;
- }
-
- len = strlen(lv_name) + 32;
- if (!(vorigin_name = alloca(len)) ||
- dm_snprintf(vorigin_name, len, "%s_vorigin", lv_name) < 0) {
- log_error("Virtual origin name allocation failed.");
- return NULL;
- }
-
- if (!(lv = lv_create_empty(vorigin_name, NULL, permission,
- ALLOC_INHERIT, vg)))
- return_NULL;
-
- if (!lv_extend(lv, segtype, 1, 0, 1, voriginextents, NULL, 0u, 0u,
- NULL, ALLOC_INHERIT))
- return_NULL;
-
- /* store vg on disk(s) */
- if (!vg_write(vg) || !vg_commit(vg))
- return_NULL;
-
- backup(vg);
-
- return lv;
-}
-
-static int _lvcreate(struct volume_group *vg,
- struct lvcreate_params *lp)
-{
- struct cmd_context *cmd = vg->cmd;
- uint32_t size_rest;
- uint32_t status = 0;
- struct logical_volume *lv, *org = NULL;
- int origin_active = 0;
- char lv_name_buf[128];
- const char *lv_name;
- struct lvinfo info;
-
- if (lp->lv_name && find_lv_in_vg(vg, lp->lv_name)) {
- log_error("Logical volume \"%s\" already exists in "
- "volume group \"%s\"", lp->lv_name, lp->vg_name);
- return 0;
- }
-
- if (vg_max_lv_reached(vg)) {
- log_error("Maximum number of logical volumes (%u) reached "
- "in volume group %s", vg->max_lv, vg->name);
- return 0;
- }
-
- if (lp->mirrors > 1 && !(vg->fid->fmt->features & FMT_SEGMENTS)) {
- log_error("Metadata does not support mirroring.");
- return 0;
- }
-
- if (lp->read_ahead != DM_READ_AHEAD_AUTO &&
- lp->read_ahead != DM_READ_AHEAD_NONE &&
- (vg->fid->fmt->features & FMT_RESTRICTED_READAHEAD) &&
- (lp->read_ahead < 2 || lp->read_ahead > 120)) {
- log_error("Metadata only supports readahead values between 2 and 120.");
- return 0;
- }
-
- if (lp->stripe_size > vg->extent_size) {
- log_error("Reducing requested stripe size %s to maximum, "
- "physical extent size %s",
- display_size(cmd, (uint64_t) lp->stripe_size),
- display_size(cmd, (uint64_t) vg->extent_size));
- lp->stripe_size = vg->extent_size;
- }
-
- /* Need to check the vg's format to verify this - the cmd format isn't setup properly yet */
- if (lp->stripes > 1 &&
- !(vg->fid->fmt->features & FMT_UNLIMITED_STRIPESIZE) &&
- (lp->stripe_size > STRIPE_SIZE_MAX)) {
- log_error("Stripe size may not exceed %s",
- display_size(cmd, (uint64_t) STRIPE_SIZE_MAX));
- return 0;
- }
-
- if ((size_rest = lp->extents % lp->stripes)) {
- log_print("Rounding size (%d extents) up to stripe boundary "
- "size (%d extents)", lp->extents,
- lp->extents - size_rest + lp->stripes);
- lp->extents = lp->extents - size_rest + lp->stripes;
- }
-
- if (lp->zero && !activation()) {
- log_error("Can't wipe start of new LV without using "
- "device-mapper kernel driver");
- return 0;
- }
-
- status |= lp->permission | VISIBLE_LV;
-
- if (lp->snapshot) {
- if (!activation()) {
- log_error("Can't create snapshot without using "
- "device-mapper kernel driver");
- return 0;
- }
- /* FIXME Allow exclusive activation. */
- if (vg_is_clustered(vg)) {
- log_error("Clustered snapshots are not yet supported.");
- return 0;
- }
-
- /* Must zero cow */
- status |= LVM_WRITE;
-
- if (lp->voriginsize)
- origin_active = 1;
- else {
-
- if (!(org = find_lv(vg, lp->origin))) {
- log_error("Couldn't find origin volume '%s'.",
- lp->origin);
- return 0;
- }
- if (lv_is_virtual_origin(org)) {
- log_error("Can't share virtual origins. "
- "Use --virtualsize.");
- return 0;
- }
- if (lv_is_cow(org)) {
- log_error("Snapshots of snapshots are not "
- "supported yet.");
- return 0;
- }
- if (org->status & LOCKED) {
- log_error("Snapshots of locked devices are not "
- "supported yet");
- return 0;
- }
- if (org->status & MIRROR_IMAGE ||
- org->status & MIRROR_LOG ||
- org->status & MIRRORED) {
- log_error("Snapshots and mirrors may not yet "
- "be mixed.");
- return 0;
- }
-
- if (!lv_info(cmd, org, &info, 0, 0)) {
- log_error("Check for existence of snapshot "
- "origin '%s' failed.", org->name);
- return 0;
- }
- origin_active = info.exists;
- }
- }
-
- if (!lp->extents) {
- log_error("Unable to create new logical volume with no extents");
- return 0;
- }
-
- if (!seg_is_virtual(lp) &&
- vg->free_count < lp->extents) {
- log_error("Insufficient free extents (%u) in volume group %s: "
- "%u required", vg->free_count, vg->name, lp->extents);
- return 0;
- }
-
- if (lp->stripes > dm_list_size(lp->pvh) && lp->alloc != ALLOC_ANYWHERE) {
- log_error("Number of stripes (%u) must not exceed "
- "number of physical volumes (%d)", lp->stripes,
- dm_list_size(lp->pvh));
- return 0;
- }
-
- if (lp->mirrors > 1 && !activation()) {
- log_error("Can't create mirror without using "
- "device-mapper kernel driver.");
- return 0;
- }
-
- /* The snapshot segment gets created later */
- if (lp->snapshot &&
- !(lp->segtype = get_segtype_from_string(cmd, "striped")))
- return_0;
-
- if (!archive(vg))
- return 0;
-
- if (lp->lv_name)
- lv_name = lp->lv_name;
- else {
- if (!generate_lv_name(vg, "lvol%d", lv_name_buf, sizeof(lv_name_buf))) {
- log_error("Failed to generate LV name.");
- return 0;
- }
- lv_name = &lv_name_buf[0];
- }
-
- if (lp->tag) {
- if (!(vg->fid->fmt->features & FMT_TAGS)) {
- log_error("Volume group %s does not support tags",
- vg->name);
- return 0;
- }
- }
-
- if (lp->mirrors > 1) {
- init_mirror_in_sync(lp->nosync);
-
- if (lp->nosync) {
- log_warn("WARNING: New mirror won't be synchronised. "
- "Don't read what you didn't write!");
- status |= MIRROR_NOTSYNCED;
- }
- }
-
- if (!(lv = lv_create_empty(lv_name ? lv_name : "lvol%d", NULL,
- status, lp->alloc, vg)))
- return_0;
-
- if (lp->read_ahead) {
- log_verbose("Setting read ahead sectors");
- lv->read_ahead = lp->read_ahead;
- }
-
- if (lp->minor >= 0) {
- lv->major = lp->major;
- lv->minor = lp->minor;
- lv->status |= FIXED_MINOR;
- log_verbose("Setting device number to (%d, %d)", lv->major,
- lv->minor);
- }
-
- if (lp->tag && !str_list_add(cmd->mem, &lv->tags, lp->tag)) {
- log_error("Failed to add tag %s to %s/%s",
- lp->tag, lv->vg->name, lv->name);
- return 0;
- }
-
- if (!lv_extend(lv, lp->segtype, lp->stripes, lp->stripe_size,
- 1, lp->extents, NULL, 0u, 0u, lp->pvh, lp->alloc))
- return_0;
-
- if (lp->mirrors > 1) {
- if (!lv_add_mirrors(cmd, lv, lp->mirrors - 1, lp->stripes,
- adjusted_mirror_region_size(
- vg->extent_size,
- lv->le_count,
- lp->region_size),
- lp->corelog ? 0U : 1U, lp->pvh, lp->alloc,
- MIRROR_BY_LV |
- (lp->nosync ? MIRROR_SKIP_INIT_SYNC : 0))) {
- stack;
- goto revert_new_lv;
- }
- }
-
- /* store vg on disk(s) */
- if (!vg_write(vg) || !vg_commit(vg))
- return_0;
-
- backup(vg);
-
- if (lp->snapshot) {
- if (!activate_lv_excl(cmd, lv)) {
- log_error("Aborting. Failed to activate snapshot "
- "exception store.");
- goto revert_new_lv;
- }
- } else if (!activate_lv(cmd, lv)) {
- if (lp->zero) {
- log_error("Aborting. Failed to activate new LV to wipe "
- "the start of it.");
- goto deactivate_and_revert_new_lv;
- }
- log_error("Failed to activate new LV.");
- return 0;
- }
-
- if (!lp->zero && !lp->snapshot)
- log_error("WARNING: \"%s\" not zeroed", lv->name);
- else if (!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 (lp->snapshot) {
- /* Reset permission after zeroing */
- if (!(lp->permission & LVM_WRITE))
- lv->status &= ~LVM_WRITE;
-
- /* COW area must be deactivated if origin is not active */
- if (!origin_active && !deactivate_lv(cmd, lv)) {
- log_error("Aborting. Couldn't deactivate snapshot "
- "COW area. Manual intervention required.");
- return 0;
- }
-
- /* A virtual origin must be activated explicitly. */
- if (lp->voriginsize &&
- (!(org = _create_virtual_origin(cmd, vg, lv->name,
- lp->permission,
- lp->voriginextents)) ||
- !activate_lv(cmd, org))) {
- log_error("Couldn't create virtual origin for LV %s",
- lv->name);
- if (org && !lv_remove(org))
- stack;
- goto deactivate_and_revert_new_lv;
- }
-
- /* cow LV remains active and becomes snapshot LV */
-
- if (!vg_add_snapshot(org, lv, NULL,
- org->le_count, lp->chunk_size)) {
- log_error("Couldn't create snapshot.");
- goto deactivate_and_revert_new_lv;
- }
-
- /* store vg on disk(s) */
- if (!vg_write(vg))
- return_0;
-
- if (!suspend_lv(cmd, org)) {
- log_error("Failed to suspend origin %s", org->name);
- vg_revert(vg);
- return 0;
- }
-
- if (!vg_commit(vg))
- return_0;
-
- if (!resume_lv(cmd, org)) {
- log_error("Problem reactivating origin %s", org->name);
- return 0;
- }
- }
- /* FIXME out of sequence */
- backup(vg);
-
- log_print("Logical volume \"%s\" created", lv->name);
-
- /*
- * FIXME: as a sanity check we could try reading the
- * last block of the device ?
- */
-
- return 1;
-
-deactivate_and_revert_new_lv:
- if (!deactivate_lv(cmd, lv)) {
- log_error("Unable to deactivate failed new LV. "
- "Manual intervention required.");
- return 0;
- }
-
-revert_new_lv:
- /* FIXME Better to revert to backup of metadata? */
- if (!lv_remove(lv) || !vg_write(vg) || !vg_commit(vg))
- log_error("Manual intervention may be required to remove "
- "abandoned LV(s) before retrying.");
- else
- backup(vg);
-
- return 0;
-}
-
int lvcreate(struct cmd_context *cmd, int argc, char **argv)
{
int r = ECMD_PROCESSED;
@@ -1032,7 +617,7 @@
if (!_update_extents_params(vg, &lp, &lcp))
return ECMD_FAILED;
- if (!_lvcreate(vg, &lp))
+ if (!lv_create_single(vg, &lp))
r = ECMD_FAILED;
unlock_and_release_vg(cmd, vg, lp.vg_name);
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
@ 2011-04-06 21:32 jbrassow
2011-04-07 12:09 ` Zdenek Kabelac
0 siblings, 1 reply; 13+ messages in thread
From: jbrassow @ 2011-04-06 21:32 UTC (permalink / raw)
To: lvm-devel
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: jbrassow at sourceware.org 2011-04-06 21:32:21
Modified files:
lib/metadata : lv_manip.c metadata-exported.h mirror.c
tools : lvresize.c
Log message:
This patch adds the ability to extend 0 length layered LVs. This
allows us to allocate all images of a mirror (or RAID array) at one
time during create.
The current mirror implementation still requires a separate allocation
for the log, however.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.254&r2=1.255
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.188&r2=1.189
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/mirror.c.diff?cvsroot=lvm2&r1=1.146&r2=1.147
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvresize.c.diff?cvsroot=lvm2&r1=1.129&r2=1.130
--- LVM2/lib/metadata/lv_manip.c 2011/03/29 20:19:04 1.254
+++ LVM2/lib/metadata/lv_manip.c 2011/04/06 21:32:20 1.255
@@ -2106,29 +2106,87 @@
0, status, 0);
}
-static int _lv_extend_mirror(struct alloc_handle *ah,
- struct logical_volume *lv,
- uint32_t extents, uint32_t first_area,
- uint32_t stripes, uint32_t stripe_size)
+static int _lv_insert_empty_sublvs(struct logical_volume *lv,
+ const struct segment_type *segtype,
+ uint32_t region_size,
+ uint32_t devices)
+{
+ struct logical_volume *sub_lv;
+ uint32_t i;
+ uint64_t status = 0;
+ char *img_name;
+ size_t len;
+ struct lv_segment *mapseg;
+
+ if (lv->le_count || first_seg(lv)) {
+ log_error(INTERNAL_ERROR
+ "Non-empty LV passed to _lv_insert_empty_sublv");
+ return 0;
+ }
+
+ if (!segtype_is_mirrored(segtype))
+ return_0;
+ lv->status |= MIRRORED;
+
+ /*
+ * First, create our top-level segment for our top-level LV
+ */
+ if (!(mapseg = alloc_lv_segment(lv->vg->cmd->mem, segtype,
+ lv, 0, 0, lv->status, 0, NULL,
+ devices, 0, 0, region_size, 0, NULL))) {
+ log_error("Failed to create mapping segment for %s", lv->name);
+ return 0;
+ }
+
+ /*
+ * Next, create all of our sub_lv's and link them in.
+ */
+ len = strlen(lv->name) + 32;
+ if (!(img_name = dm_pool_alloc(lv->vg->cmd->mem, len)))
+ return_0;
+ if (dm_snprintf(img_name, len, "%s%s", lv->name, "_mimage_%d") < 0)
+ return_0;
+
+ for (i = 0; i < devices; i++) {
+ sub_lv = lv_create_empty(img_name, NULL,
+ MIRROR_IMAGE, lv->alloc, lv->vg);
+ if (!sub_lv)
+ return_0;
+ if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, status))
+ return_0;
+ }
+ dm_list_add(&lv->segments, &mapseg->list);
+
+ dm_pool_free(lv->vg->cmd->mem, img_name);
+ return 1;
+}
+
+static int _lv_extend_layered_lv(struct alloc_handle *ah,
+ struct logical_volume *lv,
+ uint32_t extents, uint32_t first_area,
+ uint32_t stripes, uint32_t stripe_size)
{
+ struct logical_volume *sub_lv;
struct lv_segment *seg;
uint32_t m, s;
seg = first_seg(lv);
for (m = first_area, s = 0; s < seg->area_count; s++) {
if (is_temporary_mirror_layer(seg_lv(seg, s))) {
- if (!_lv_extend_mirror(ah, seg_lv(seg, s), extents, m, stripes, stripe_size))
+ if (!_lv_extend_layered_lv(ah, seg_lv(seg, s), extents,
+ m, stripes, stripe_size))
return_0;
m += lv_mirror_count(seg_lv(seg, s));
continue;
}
- if (!lv_add_segment(ah, m, stripes, seg_lv(seg, s),
+ sub_lv = seg_lv(seg, s);
+ if (!lv_add_segment(ah, m, stripes, sub_lv,
get_segtype_from_string(lv->vg->cmd,
"striped"),
- stripe_size, 0, 0)) {
- log_error("Aborting. Failed to extend %s.",
- seg_lv(seg, s)->name);
+ stripe_size, sub_lv->status, 0)) {
+ log_error("Aborting. Failed to extend %s in %s.",
+ sub_lv->name, lv->name);
return 0;
}
m += stripes;
@@ -2147,28 +2205,35 @@
int lv_extend(struct logical_volume *lv,
const struct segment_type *segtype,
uint32_t stripes, uint32_t stripe_size,
- uint32_t mirrors, uint32_t extents,
- struct physical_volume *mirrored_pv __attribute__((unused)),
- uint32_t mirrored_pe __attribute__((unused)),
- uint64_t status, struct dm_list *allocatable_pvs,
- alloc_policy_t alloc)
+ uint32_t mirrors, uint32_t region_size,
+ uint32_t extents,
+ struct dm_list *allocatable_pvs, alloc_policy_t alloc)
{
int r = 1;
struct alloc_handle *ah;
if (segtype_is_virtual(segtype))
- return lv_add_virtual_segment(lv, status, extents, segtype);
+ return lv_add_virtual_segment(lv, 0u, extents, segtype);
if (!(ah = allocate_extents(lv->vg, lv, segtype, stripes, mirrors, 0, 0,
extents, allocatable_pvs, alloc, NULL)))
return_0;
- if (mirrors < 2)
+ if (!segtype_is_mirrored(segtype))
r = lv_add_segment(ah, 0, ah->area_count, lv, segtype,
- stripe_size, status, 0);
- else
- r = _lv_extend_mirror(ah, lv, extents, 0, stripes, stripe_size);
+ stripe_size, 0u, 0);
+ else {
+ if (!lv->le_count &&
+ !_lv_insert_empty_sublvs(lv, segtype,
+ region_size, mirrors)) {
+ log_error("Failed to insert layer for %s", lv->name);
+ alloc_destroy(ah);
+ return 0;
+ }
+ r = _lv_extend_layered_lv(ah, lv, extents, 0,
+ stripes, stripe_size);
+ }
alloc_destroy(ah);
return r;
}
@@ -3389,7 +3454,7 @@
ALLOC_INHERIT, vg)))
return_NULL;
- if (!lv_extend(lv, segtype, 1, 0, 1, voriginextents, NULL, 0u, 0u,
+ if (!lv_extend(lv, segtype, 1, 0, 1, 0, voriginextents,
NULL, ALLOC_INHERIT))
return_NULL;
@@ -3588,6 +3653,10 @@
"Don't read what you didn't write!");
status |= LV_NOTSYNCED;
}
+
+ lp->segtype = get_segtype_from_string(cmd, "mirror");
+ if (!lp->segtype)
+ return_0;
}
if (!(lv = lv_create_empty(lp->lv_name ? lp->lv_name : "lvol%d", NULL,
@@ -3611,19 +3680,17 @@
dm_list_splice(&lv->tags, &lp->tags);
if (!lv_extend(lv, lp->segtype, lp->stripes, lp->stripe_size,
- 1, lp->extents, NULL, 0u, 0u, lp->pvh, lp->alloc))
+ lp->mirrors,
+ adjusted_mirror_region_size(vg->extent_size,
+ lp->extents,
+ lp->region_size),
+ lp->extents, lp->pvh, lp->alloc))
return_0;
- if (lp->mirrors > 1) {
- if (!lv_add_mirrors(cmd, lv, lp->mirrors - 1, lp->stripes,
- lp->stripe_size,
- adjusted_mirror_region_size(
- vg->extent_size,
- lv->le_count,
- lp->region_size),
- lp->log_count, lp->pvh, lp->alloc,
- MIRROR_BY_LV |
- (lp->nosync ? MIRROR_SKIP_INIT_SYNC : 0))) {
+ if ((lp->mirrors > 1) && lp->log_count) {
+ if (!add_mirror_log(cmd, lv, lp->log_count,
+ first_seg(lv)->region_size,
+ lp->pvh, lp->alloc)) {
stack;
goto revert_new_lv;
}
--- LVM2/lib/metadata/metadata-exported.h 2011/03/29 12:51:57 1.188
+++ LVM2/lib/metadata/metadata-exported.h 2011/04/06 21:32:20 1.189
@@ -500,10 +500,9 @@
int lv_extend(struct logical_volume *lv,
const struct segment_type *segtype,
uint32_t stripes, uint32_t stripe_size,
- uint32_t mirrors, uint32_t extents,
- struct physical_volume *mirrored_pv, uint32_t mirrored_pe,
- uint64_t status, struct dm_list *allocatable_pvs,
- alloc_policy_t alloc);
+ uint32_t mirrors, uint32_t region_size,
+ uint32_t extents,
+ struct dm_list *allocatable_pvs, alloc_policy_t alloc);
/* lv must be part of lv->vg->lvs */
int lv_remove(struct logical_volume *lv);
--- LVM2/lib/metadata/mirror.c 2011/03/29 12:51:57 1.146
+++ LVM2/lib/metadata/mirror.c 2011/04/06 21:32:20 1.147
@@ -1899,8 +1899,9 @@
}
/* check sync status */
- if (lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL) &&
- (sync_percent == PERCENT_100))
+ if (mirror_in_sync() ||
+ (lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL) &&
+ (sync_percent == PERCENT_100)))
in_sync = 1;
else
in_sync = 0;
--- LVM2/tools/lvresize.c 2011/03/02 16:56:07 1.129
+++ LVM2/tools/lvresize.c 2011/04/06 21:32:21 1.130
@@ -670,10 +670,11 @@
return ECMD_FAILED;
}
} else if ((lp->extents > lv->le_count) && /* Ensure we extend */
- !lv_extend(lv, lp->segtype, lp->stripes,
- lp->stripe_size, lp->mirrors,
+ !lv_extend(lv, lp->segtype,
+ lp->stripes, lp->stripe_size,
+ lp->mirrors, first_seg(lv)->region_size,
lp->extents - lv->le_count,
- NULL, 0u, 0u, pvh, alloc)) {
+ pvh, alloc)) {
stack;
return ECMD_FAILED;
}
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
2011-04-06 21:32 jbrassow
@ 2011-04-07 12:09 ` Zdenek Kabelac
2011-04-07 15:20 ` Jonathan Brassow
0 siblings, 1 reply; 13+ messages in thread
From: Zdenek Kabelac @ 2011-04-07 12:09 UTC (permalink / raw)
To: lvm-devel
Dne 6.4.2011 23:32, jbrassow at sourceware.org napsal(a):
> CVSROOT: /cvs/lvm2
> Module name: LVM2
> Changes by: jbrassow at sourceware.org 2011-04-06 21:32:21
>
> Modified files:
> lib/metadata : lv_manip.c metadata-exported.h mirror.c
> tools : lvresize.c
>
> Log message:
> This patch adds the ability to extend 0 length layered LVs. This
> allows us to allocate all images of a mirror (or RAID array) at one
> time during create.
>
> The current mirror implementation still requires a separate allocation
> for the log, however.
>
> Patches:
> http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv_manip.c.diff?cvsroot=lvm2&r1=1.254&r2=1.255
> http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.188&r2=1.189
> http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/mirror.c.diff?cvsroot=lvm2&r1=1.146&r2=1.147
> http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvresize.c.diff?cvsroot=lvm2&r1=1.129&r2=1.130
>
> --- LVM2/lib/metadata/lv_manip.c 2011/03/29 20:19:04 1.254
> +++ LVM2/lib/metadata/lv_manip.c 2011/04/06 21:32:20 1.255
> @@ -2106,29 +2106,87 @@
> 0, status, 0);
> }
>
> -static int _lv_extend_mirror(struct alloc_handle *ah,
> - struct logical_volume *lv,
> - uint32_t extents, uint32_t first_area,
> - uint32_t stripes, uint32_t stripe_size)
> +static int _lv_insert_empty_sublvs(struct logical_volume *lv,
> + const struct segment_type *segtype,
> + uint32_t region_size,
> + uint32_t devices)
> +{
> + struct logical_volume *sub_lv;
> + uint32_t i;
> + uint64_t status = 0;
> + char *img_name;
> + size_t len;
> + struct lv_segment *mapseg;
> +
> + if (lv->le_count || first_seg(lv)) {
> + log_error(INTERNAL_ERROR
> + "Non-empty LV passed to _lv_insert_empty_sublv");
> + return 0;
> + }
> +
> + if (!segtype_is_mirrored(segtype))
> + return_0;
> + lv->status |= MIRRORED;
> +
> + /*
> + * First, create our top-level segment for our top-level LV
> + */
> + if (!(mapseg = alloc_lv_segment(lv->vg->cmd->mem, segtype,
> + lv, 0, 0, lv->status, 0, NULL,
> + devices, 0, 0, region_size, 0, NULL))) {
> + log_error("Failed to create mapping segment for %s", lv->name);
> + return 0;
> + }
> +
> + /*
> + * Next, create all of our sub_lv's and link them in.
> + */
> + len = strlen(lv->name) + 32;
> + if (!(img_name = dm_pool_alloc(lv->vg->cmd->mem, len)))
> + return_0;
> + if (dm_snprintf(img_name, len, "%s%s", lv->name, "_mimage_%d") < 0)
> + return_0;
> +
> + for (i = 0; i < devices; i++) {
> + sub_lv = lv_create_empty(img_name, NULL,
> + MIRROR_IMAGE, lv->alloc, lv->vg);
> + if (!sub_lv)
> + return_0;
> + if (!set_lv_segment_area_lv(mapseg, i, sub_lv, 0, status))
> + return_0;
> + }
> + dm_list_add(&lv->segments, &mapseg->list);
> +
> + dm_pool_free(lv->vg->cmd->mem, img_name);
Aren't you experiencing random crashes with this dm_pool_free() ?
It removes also all objects allocated past this img_name.
(Also I think there is already an internal function for building such names)
Zdenek
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
2011-04-07 12:09 ` Zdenek Kabelac
@ 2011-04-07 15:20 ` Jonathan Brassow
2011-04-07 20:35 ` Zdenek Kabelac
0 siblings, 1 reply; 13+ messages in thread
From: Jonathan Brassow @ 2011-04-07 15:20 UTC (permalink / raw)
To: lvm-devel
On Apr 7, 2011, at 7:09 AM, Zdenek Kabelac wrote:
>> +
>> + dm_pool_free(lv->vg->cmd->mem, img_name);
>
>
> Aren't you experiencing random crashes with this dm_pool_free() ?
> It removes also all objects allocated past this img_name.
> (Also I think there is already an internal function for building such names)
No crashes so far... I haven't run into that while running through the test suite or my by-hand tests. Why would I expect that kind of behavior?
Also, do you know what the name of the internal function would be to replace my 'alloc, fill with template name, create empty lv's, free' sequence?
brassow
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
2011-04-07 15:20 ` Jonathan Brassow
@ 2011-04-07 20:35 ` Zdenek Kabelac
2011-04-07 21:36 ` Jonathan Brassow
0 siblings, 1 reply; 13+ messages in thread
From: Zdenek Kabelac @ 2011-04-07 20:35 UTC (permalink / raw)
To: lvm-devel
Dne 7.4.2011 17:20, Jonathan Brassow napsal(a):
>
> On Apr 7, 2011, at 7:09 AM, Zdenek Kabelac wrote:
>
>>> +
>>> + dm_pool_free(lv->vg->cmd->mem, img_name);
>>
>>
>> Aren't you experiencing random crashes with this dm_pool_free() ?
>> It removes also all objects allocated past this img_name.
>> (Also I think there is already an internal function for building such names)
>
> No crashes so far... I haven't run into that while running through the test suite or my by-hand tests. Why would I expect that kind of behavior?
See the comment for dm_pool_free() in libdevmapper.h
As you are allocating LV after img_name - by this pool you are effectively
removing all memory allocated in VG pool after.
>
> Also, do you know what the name of the internal function would be to replace my 'alloc, fill with template name, create empty lv's, free' sequence?
>
Ok - it looks like for _mimage_ - there is not yet one - so as there are
already 3 other placed - it might be forth to create one for this purpose.
(Also note - in other case we are already using simplier ,"%s_mimage_%%d",
(see the _split_mirror_images() in mirror.c)
Zdenek
^ permalink raw reply [flat|nested] 13+ messages in thread
* LVM2 lib/metadata/lv_manip.c lib/metadata/meta ...
2011-04-07 20:35 ` Zdenek Kabelac
@ 2011-04-07 21:36 ` Jonathan Brassow
0 siblings, 0 replies; 13+ messages in thread
From: Jonathan Brassow @ 2011-04-07 21:36 UTC (permalink / raw)
To: lvm-devel
On Apr 7, 2011, at 3:35 PM, Zdenek Kabelac wrote:
> Dne 7.4.2011 17:20, Jonathan Brassow napsal(a):
>>
>> On Apr 7, 2011, at 7:09 AM, Zdenek Kabelac wrote:
>>
>>>> +
>>>> + dm_pool_free(lv->vg->cmd->mem, img_name);
>>>
>>>
>>> Aren't you experiencing random crashes with this dm_pool_free() ?
>>> It removes also all objects allocated past this img_name.
>>> (Also I think there is already an internal function for building such names)
>>
>> No crashes so far... I haven't run into that while running through the test suite or my by-hand tests. Why would I expect that kind of behavior?
>
> See the comment for dm_pool_free() in libdevmapper.h
> As you are allocating LV after img_name - by this pool you are effectively
> removing all memory allocated in VG pool after.
Thank-you for mentioning this! Gah. Alright, I'll fix that. I'm surprised too now that I haven't seen problems.
>
>>
>> Also, do you know what the name of the internal function would be to replace my 'alloc, fill with template name, create empty lv's, free' sequence?
>>
>
> Ok - it looks like for _mimage_ - there is not yet one - so as there are
> already 3 other placed - it might be forth to create one for this purpose.
>
> (Also note - in other case we are already using simplier ,"%s_mimage_%%d",
> (see the _split_mirror_images() in mirror.c)
Well, there are a couple different things going on in _split_mirror_images. In one case, the space is created at the time the variable is declared ('format' is allocated on the stack). In the other, that string ("_mimage_%d") is passed to a function.
In this case, I could easily create the space for img_name on the stack, i think.
brassow
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2011-04-07 21:36 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-21 16:40 LVM2 lib/metadata/lv_manip.c lib/metadata/meta wysochanski
-- strict thread matches above, loose matches on Subject: below --
2007-09-24 21:30 wysochanski
2007-10-11 19:20 wysochanski
2007-12-20 22:37 agk
2008-01-17 13:13 agk
2008-01-17 13:54 agk
2008-08-05 12:05 zkabelac
2009-07-26 2:33 wysochanski
2011-04-06 21:32 jbrassow
2011-04-07 12:09 ` Zdenek Kabelac
2011-04-07 15:20 ` Jonathan Brassow
2011-04-07 20:35 ` Zdenek Kabelac
2011-04-07 21:36 ` Jonathan Brassow
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.