]> sourceware.org Git - lvm2.git/commitdiff
format: format_text: add pv_needs_rewrite to format_handler and implemention for...
authorPeter Rajnoha <prajnoha@redhat.com>
Fri, 12 Feb 2016 12:53:06 +0000 (13:53 +0100)
committerPeter Rajnoha <prajnoha@redhat.com>
Mon, 15 Feb 2016 11:44:46 +0000 (12:44 +0100)
lib/format_text/format-text.c
lib/metadata/metadata.h

index 72026581bdd3bd64d904c8614ed4ec1739c24680..666357c952ddc340b6d6795759764ca23deca685 100644 (file)
@@ -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,
index 3f5f5aeaef8dd24677d5c88d33d32176f5f0fc52..f2b62e4772cf00d1265c7a30f1ad5ff660109a25 100644 (file)
@@ -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.
This page took 0.11867 seconds and 5 git commands to generate.