mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
Recoded way to insert thin pool into vg
Code in _lv_insert_empty_sublvs was not able to provide proper initialization order for thin pool LV. New function extend_pool() first adds metadata segment to pool LV which is still visible. Such LV is activate and cleared. Then new meta LV is created and metadata segments are moved there. Now the preallocated pool data segment is attached to the pool LV and layer _tpool is created. Finaly segment is marked as thin_pool.
This commit is contained in:
parent
06b8248d63
commit
f4c77bd0e3
@ -69,6 +69,7 @@
|
|||||||
|
|
||||||
struct dm_config_tree;
|
struct dm_config_tree;
|
||||||
struct metadata_area;
|
struct metadata_area;
|
||||||
|
struct alloc_handle;
|
||||||
|
|
||||||
/* Per-format per-metadata area operations */
|
/* Per-format per-metadata area operations */
|
||||||
struct metadata_area_ops {
|
struct metadata_area_ops {
|
||||||
@ -461,6 +462,8 @@ int attach_pool_message(struct lv_segment *seg, dm_thin_message_t type,
|
|||||||
struct logical_volume *lv, uint32_t delete_id,
|
struct logical_volume *lv, uint32_t delete_id,
|
||||||
int read_only);
|
int read_only);
|
||||||
int detach_pool_messages(struct lv_segment *seg);
|
int detach_pool_messages(struct lv_segment *seg);
|
||||||
|
int extend_pool(struct logical_volume *lv, const struct segment_type *segtype,
|
||||||
|
struct alloc_handle *ah);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Begin skeleton for external LVM library
|
* Begin skeleton for external LVM library
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lib.h"
|
#include "lib.h"
|
||||||
|
#include "activate.h"
|
||||||
|
#include "locking.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
#include "segtype.h"
|
#include "segtype.h"
|
||||||
#include "lv_alloc.h"
|
#include "lv_alloc.h"
|
||||||
@ -216,3 +218,96 @@ uint32_t get_free_pool_device_id(struct lv_segment *thin_pool_seg)
|
|||||||
|
|
||||||
return max_id;
|
return max_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int extend_pool(struct logical_volume *pool_lv, const struct segment_type *segtype,
|
||||||
|
struct alloc_handle *ah)
|
||||||
|
{
|
||||||
|
const struct segment_type *striped;
|
||||||
|
struct logical_volume *meta_lv, *data_lv;
|
||||||
|
struct lv_segment *seg;
|
||||||
|
const size_t len = strlen(pool_lv->name) + 16;
|
||||||
|
char name[len];
|
||||||
|
|
||||||
|
if (lv_is_thin_pool(pool_lv)) {
|
||||||
|
log_error("Resize of pool %s not yet implemented.", pool_lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* LV is not yet a pool, so it's extension from lvcreate */
|
||||||
|
if (!(striped = get_segtype_from_string(pool_lv->vg->cmd, "striped")))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
if (activation() && segtype->ops->target_present &&
|
||||||
|
!segtype->ops->target_present(pool_lv->vg->cmd, NULL, NULL)) {
|
||||||
|
log_error("%s: Required device-mapper target(s) not "
|
||||||
|
"detected in your kernel.", segtype->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Metadata segment */
|
||||||
|
if (!lv_add_segment(ah, 1, 1, pool_lv, striped, 1, 0, 0))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
if (activation()) {
|
||||||
|
if (!vg_write(pool_lv->vg) || !vg_commit(pool_lv->vg))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If killed here, only the VISIBLE striped pool LV is left
|
||||||
|
* and user could easily remove it.
|
||||||
|
*
|
||||||
|
* FIXME: implement lazy clearing when activation is disabled
|
||||||
|
*/
|
||||||
|
|
||||||
|
// FIXME: activate_lv_local_excl is actually wanted here
|
||||||
|
if (!activate_lv_local(pool_lv->vg->cmd, pool_lv) ||
|
||||||
|
// FIXME: maybe -zero n should allow to recreate same thin pool
|
||||||
|
// and different option should be used for zero_new_blocks
|
||||||
|
/* Clear 4KB of metadata device for new thin-pool. */
|
||||||
|
!set_lv(pool_lv->vg->cmd, pool_lv, UINT64_C(0), 0)) {
|
||||||
|
log_error("Aborting. Failed to wipe pool metadata %s.",
|
||||||
|
pool_lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!deactivate_lv_local(pool_lv->vg->cmd, pool_lv)) {
|
||||||
|
log_error("Aborting. Could not deactivate pool metadata %s.",
|
||||||
|
pool_lv->name);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_error("Pool %s created without initilization.", pool_lv->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dm_snprintf(name, len, "%s_tmeta", pool_lv->name) < 0)
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
if (!(meta_lv = lv_create_empty(name, NULL, LVM_READ | LVM_WRITE,
|
||||||
|
ALLOC_INHERIT, pool_lv->vg)))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
if (!move_lv_segments(meta_lv, pool_lv, 0, 0))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
/* Pool data segment */
|
||||||
|
if (!lv_add_segment(ah, 0, 1, pool_lv, striped, 1, 0, 0))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
if (!(data_lv = insert_layer_for_lv(pool_lv->vg->cmd, pool_lv,
|
||||||
|
pool_lv->status, "_tpool")))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
seg = first_seg(pool_lv);
|
||||||
|
seg->segtype = segtype; /* Set as thin_pool segment */
|
||||||
|
seg->lv->status |= THIN_POOL;
|
||||||
|
|
||||||
|
if (!attach_pool_metadata_lv(seg, meta_lv))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
/* Drop reference as attach_pool_data_lv() takes it again */
|
||||||
|
remove_seg_from_segs_using_this_lv(data_lv, seg);
|
||||||
|
if (!attach_pool_data_lv(seg, data_lv))
|
||||||
|
return_0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user