From 9b9f1ae7726c2ee0e7eda76cd519f7d4921a12d9 Mon Sep 17 00:00:00 2001 From: Peter Rajnoha Date: Fri, 12 Feb 2016 13:53:06 +0100 Subject: [PATCH] format: format_text: add pv_needs_rewrite to format_handler and implemention for format_text --- lib/format_text/format-text.c | 22 ++++++++++++++++++++++ lib/metadata/metadata.h | 9 +++++++++ 2 files changed, 31 insertions(+) diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 72026581b..666357c95 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -1439,6 +1439,27 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume return 1; } +static int _text_pv_needs_rewrite(const struct format_type *fmt, struct physical_volume *pv, + int *needs_rewrite) +{ + struct lvmcache_info *info; + uint32_t ext_vsn; + + *needs_rewrite = 0; + + if (!(info = lvmcache_info_from_pvid((const char *)&pv->id, 0))) { + log_error("Failed to find cached info for PV %s.", pv_dev_name(pv)); + return 0; + } + + ext_vsn = lvmcache_ext_version(info); + + if (ext_vsn < PV_HEADER_EXTENSION_VSN) + *needs_rewrite = 1; + + return 1; +} + static int _add_raw(struct dm_list *raw_list, struct device_area *dev_area) { struct raw_list *rl; @@ -2384,6 +2405,7 @@ static struct format_handler _text_handler = { .pv_remove_metadata_area = _text_pv_remove_metadata_area, .pv_resize = _text_pv_resize, .pv_write = _text_pv_write, + .pv_needs_rewrite = _text_pv_needs_rewrite, .vg_setup = _text_vg_setup, .lv_setup = _text_lv_setup, .create_instance = _text_create_text_instance, diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index 3f5f5aeae..f2b62e477 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -302,6 +302,15 @@ struct format_handler { int (*pv_write) (const struct format_type * fmt, struct physical_volume * pv); + /* + * Check if PV needs rewriting. This is used to check whether there are any + * format-specific changes before actually writing the PV (by calling pv_write). + * With this, we can call pv_write conditionally only if it's really needed. + */ + int (*pv_needs_rewrite) (const struct format_type *fmt, + struct physical_volume *pv, + int *needs_rewrite); + /* * Tweak an already filled out a lv eg, check there * aren't too many extents.