1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

pv_header_extension: add supporting infrastructure for PV header extension (flags & Embedding Area)

PV header extension comes just beyond the existing PV header base:

PV header base (existing):
 - uuid
 - device size
 - null-terminated list of Data Areas
 - null-terminater list of MetaData Areas

PV header extension:
 - extension version
 - flags
 - null-terminated list of Embedding Areas

This patch also adds "eas" (Embedding Areas) list to lvmcache (lvmcache_info)
and it also adds support for common operations on the list (just like for
already existing "das" - Data Areas list):
 - lvmcache_add_ea
 - lvmcache_update_eas
 - lvmcache_foreach_ea
 - lvmcache_del_eas

Also, add ea_start and ea_size to struct physical_volume for processing
PV Embedding Area location throughout the code (currently only one
Embedding Area is supported, though the definition on disk allows for
more if needed in the future...).

Also, define FMT_EAS format flag to mark that the format actually
supports Embedding Areas (currently format-text only).
This commit is contained in:
Peter Rajnoha 2013-02-14 15:35:57 +01:00
parent 6d8de3638c
commit 60c5d4c42f
8 changed files with 83 additions and 1 deletions

44
lib/cache/lvmcache.c vendored
View File

@ -38,6 +38,7 @@ struct lvmcache_info {
struct dm_list list; /* Join VG members together */ struct dm_list list; /* Join VG members together */
struct dm_list mdas; /* list head for metadata areas */ struct dm_list mdas; /* list head for metadata areas */
struct dm_list das; /* list head for data areas */ struct dm_list das; /* list head for data areas */
struct dm_list eas; /* list head for embedding areas */
struct lvmcache_vginfo *vginfo; /* NULL == unknown */ struct lvmcache_vginfo *vginfo; /* NULL == unknown */
struct label *label; struct label *label;
const struct format_type *fmt; const struct format_type *fmt;
@ -1752,6 +1753,13 @@ void lvmcache_del_das(struct lvmcache_info *info)
dm_list_init(&info->das); dm_list_init(&info->das);
} }
void lvmcache_del_eas(struct lvmcache_info *info)
{
if (info->eas.n)
del_eas(&info->eas);
dm_list_init(&info->eas);
}
int lvmcache_add_mda(struct lvmcache_info *info, struct device *dev, int lvmcache_add_mda(struct lvmcache_info *info, struct device *dev,
uint64_t start, uint64_t size, unsigned ignored) uint64_t start, uint64_t size, unsigned ignored)
{ {
@ -1763,6 +1771,10 @@ int lvmcache_add_da(struct lvmcache_info *info, uint64_t start, uint64_t size)
return add_da(NULL, &info->das, start, size); return add_da(NULL, &info->das, start, size);
} }
int lvmcache_add_ea(struct lvmcache_info *info, uint64_t start, uint64_t size)
{
return add_ea(NULL, &info->eas, start, size);
}
void lvmcache_update_pv(struct lvmcache_info *info, struct physical_volume *pv, void lvmcache_update_pv(struct lvmcache_info *info, struct physical_volume *pv,
const struct format_type *fmt) const struct format_type *fmt)
@ -1788,6 +1800,25 @@ int lvmcache_update_das(struct lvmcache_info *info, struct physical_volume *pv)
return 1; return 1;
} }
int lvmcache_update_eas(struct lvmcache_info *info, struct physical_volume *pv)
{
struct data_area_list *ea;
if (info->eas.n) {
if (!pv->ea_start && !pv->ea_size)
dm_list_iterate_items(ea, &info->eas) {
pv->ea_start = ea->disk_locn.offset >> SECTOR_SHIFT;
pv->ea_size = ea->disk_locn.size >> SECTOR_SHIFT;
}
del_das(&info->eas);
} else
dm_list_init(&info->eas);
if (!add_ea(NULL, &info->eas, pv->ea_start << SECTOR_SHIFT, pv->ea_size << SECTOR_SHIFT))
return_0;
return 1;
}
int lvmcache_foreach_pv(struct lvmcache_vginfo *vginfo, int lvmcache_foreach_pv(struct lvmcache_vginfo *vginfo,
int (*fun)(struct lvmcache_info *, void *), int (*fun)(struct lvmcache_info *, void *),
void *baton) void *baton)
@ -1832,6 +1863,19 @@ int lvmcache_foreach_da(struct lvmcache_info *info,
return 1; return 1;
} }
int lvmcache_foreach_ea(struct lvmcache_info *info,
int (*fun)(struct disk_locn *, void *),
void *baton)
{
struct data_area_list *ea;
dm_list_iterate_items(ea, &info->eas) {
if (!fun(&ea->disk_locn, baton))
return_0;
}
return 1;
}
/* /*
* The lifetime of the label returned is tied to the lifetime of the * The lifetime of the label returned is tied to the lifetime of the
* lvmcache_info which is the same as lvmcache itself. * lvmcache_info which is the same as lvmcache itself.

View File

@ -118,9 +118,11 @@ int lvmcache_populate_pv_fields(struct lvmcache_info *info,
int lvmcache_check_format(struct lvmcache_info *info, const struct format_type *fmt); int lvmcache_check_format(struct lvmcache_info *info, const struct format_type *fmt);
void lvmcache_del_mdas(struct lvmcache_info *info); void lvmcache_del_mdas(struct lvmcache_info *info);
void lvmcache_del_das(struct lvmcache_info *info); void lvmcache_del_das(struct lvmcache_info *info);
void lvmcache_del_eas(struct lvmcache_info *info);
int lvmcache_add_mda(struct lvmcache_info *info, struct device *dev, int lvmcache_add_mda(struct lvmcache_info *info, struct device *dev,
uint64_t start, uint64_t size, unsigned ignored); uint64_t start, uint64_t size, unsigned ignored);
int lvmcache_add_da(struct lvmcache_info *info, uint64_t start, uint64_t size); int lvmcache_add_da(struct lvmcache_info *info, uint64_t start, uint64_t size);
int lvmcache_add_ea(struct lvmcache_info *info, uint64_t start, uint64_t size);
const struct format_type *lvmcache_fmt(struct lvmcache_info *info); const struct format_type *lvmcache_fmt(struct lvmcache_info *info);
struct label *lvmcache_get_label(struct lvmcache_info *info); struct label *lvmcache_get_label(struct lvmcache_info *info);
@ -128,6 +130,7 @@ struct label *lvmcache_get_label(struct lvmcache_info *info);
void lvmcache_update_pv(struct lvmcache_info *info, struct physical_volume *pv, void lvmcache_update_pv(struct lvmcache_info *info, struct physical_volume *pv,
const struct format_type *fmt); const struct format_type *fmt);
int lvmcache_update_das(struct lvmcache_info *info, struct physical_volume *pv); int lvmcache_update_das(struct lvmcache_info *info, struct physical_volume *pv);
int lvmcache_update_eas(struct lvmcache_info *info, struct physical_volume *pv);
int lvmcache_foreach_mda(struct lvmcache_info *info, int lvmcache_foreach_mda(struct lvmcache_info *info,
int (*fun)(struct metadata_area *, void *), int (*fun)(struct metadata_area *, void *),
void *baton); void *baton);
@ -136,6 +139,10 @@ int lvmcache_foreach_da(struct lvmcache_info *info,
int (*fun)(struct disk_locn *, void *), int (*fun)(struct disk_locn *, void *),
void *baton); void *baton);
int lvmcache_foreach_ea(struct lvmcache_info *info,
int (*fun)(struct disk_locn *, void *),
void *baton);
int lvmcache_foreach_pv(struct lvmcache_vginfo *vg, int lvmcache_foreach_pv(struct lvmcache_vginfo *vg,
int (*fun)(struct lvmcache_info *, void *), void * baton); int (*fun)(struct lvmcache_info *, void *), void * baton);

View File

@ -2349,7 +2349,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
fmt->orphan_vg_name = ORPHAN_VG_NAME(FMT_TEXT_NAME); fmt->orphan_vg_name = ORPHAN_VG_NAME(FMT_TEXT_NAME);
fmt->features = FMT_SEGMENTS | FMT_MDAS | FMT_TAGS | FMT_PRECOMMIT | fmt->features = FMT_SEGMENTS | FMT_MDAS | FMT_TAGS | FMT_PRECOMMIT |
FMT_UNLIMITED_VOLS | FMT_RESIZE_PV | FMT_UNLIMITED_VOLS | FMT_RESIZE_PV |
FMT_UNLIMITED_STRIPESIZE; FMT_UNLIMITED_STRIPESIZE | FMT_EAS;
if (!(mda_lists = dm_malloc(sizeof(struct mda_lists)))) { if (!(mda_lists = dm_malloc(sizeof(struct mda_lists)))) {
log_error("Failed to allocate dir_list"); log_error("Failed to allocate dir_list");

View File

@ -58,6 +58,9 @@ int pvhdr_read(struct device *dev, char *buf);
int add_da(struct dm_pool *mem, struct dm_list *das, int add_da(struct dm_pool *mem, struct dm_list *das,
uint64_t start, uint64_t size); uint64_t start, uint64_t size);
void del_das(struct dm_list *das); void del_das(struct dm_list *das);
int add_ea(struct dm_pool *mem, struct dm_list *eas,
uint64_t start, uint64_t size);
void del_eas(struct dm_list *eas);
int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *mdas, int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *mdas,
struct device *dev, uint64_t start, uint64_t size, unsigned ignored); struct device *dev, uint64_t start, uint64_t size, unsigned ignored);
void del_mdas(struct dm_list *mdas); void del_mdas(struct dm_list *mdas);

View File

@ -23,6 +23,15 @@
/* disk_locn and data_area_list are defined in format-text.h */ /* disk_locn and data_area_list are defined in format-text.h */
#define PV_HEADER_EXTENSION_VSN 1
struct pv_header_extension {
uint32_t version;
uint32_t flags;
/* NULL-terminated list of embedding areas */
struct disk_locn embedding_area_xl[0];
} __attribute__ ((packed));
/* Fields with the suffix _xl should be xlate'd wherever they appear */ /* Fields with the suffix _xl should be xlate'd wherever they appear */
/* On disk */ /* On disk */
struct pv_header { struct pv_header {
@ -34,6 +43,9 @@ struct pv_header {
/* NULL-terminated list of data areas followed by */ /* NULL-terminated list of data areas followed by */
/* NULL-terminated list of metadata area headers */ /* NULL-terminated list of metadata area headers */
struct disk_locn disk_areas_xl[0]; /* Two lists */ struct disk_locn disk_areas_xl[0]; /* Two lists */
/* PV header extension */
struct pv_header_extension ext;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* /*

View File

@ -196,6 +196,17 @@ void del_das(struct dm_list *das)
} }
} }
int add_ea(struct dm_pool *mem, struct dm_list *eas,
uint64_t start, uint64_t size)
{
return add_da(mem, eas, start, size);
}
void del_eas(struct dm_list *eas)
{
del_das(eas);
}
/* FIXME: refactor this function with other mda constructor code */ /* FIXME: refactor this function with other mda constructor code */
int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *mdas, int add_mda(const struct format_type *fmt, struct dm_pool *mem, struct dm_list *mdas,
struct device *dev, uint64_t start, uint64_t size, unsigned ignored) struct device *dev, uint64_t start, uint64_t size, unsigned ignored)

View File

@ -107,6 +107,7 @@
#define FMT_RESIZE_PV 0x00000080U /* Supports pvresize? */ #define FMT_RESIZE_PV 0x00000080U /* Supports pvresize? */
#define FMT_UNLIMITED_STRIPESIZE 0x00000100U /* Unlimited stripe size? */ #define FMT_UNLIMITED_STRIPESIZE 0x00000100U /* Unlimited stripe size? */
#define FMT_RESTRICTED_READAHEAD 0x00000200U /* Readahead restricted to 2-120? */ #define FMT_RESTRICTED_READAHEAD 0x00000200U /* Readahead restricted to 2-120? */
#define FMT_EAS 0x000000400U /* Supports embedding areas? */
/* Mirror conversion type flags */ /* Mirror conversion type flags */
#define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */ #define MIRROR_BY_SEG 0x00000001U /* segment-by-segment mirror */

View File

@ -43,6 +43,10 @@ struct physical_volume {
uint64_t status; uint64_t status;
uint64_t size; uint64_t size;
/* embedding area */
uint64_t ea_start;
uint64_t ea_size;
/* physical extents */ /* physical extents */
uint32_t pe_size; uint32_t pe_size;
uint64_t pe_start; uint64_t pe_start;