]> sourceware.org Git - lvm2.git/commitdiff
pvcreate: Fix cache state with filters/sig wiping.
authorAlasdair G Kergon <agk@redhat.com>
Thu, 14 Aug 2014 00:30:01 +0000 (01:30 +0100)
committerAlasdair G Kergon <agk@redhat.com>
Thu, 14 Aug 2014 00:30:01 +0000 (01:30 +0100)
_pvcreate_check() has two missing requirements:
  After refreshing filters there must be a rescan.
    (Otherwise the persistent filter may remain empty.)
  After wiping a signature, the filters must be refreshed.
    (A device that was previously excluded by the filter due to
     its signature might now need to be included.)

If several devices are added at once, the repeated scanning isn't
strictly needed, but we can address that later as part of the command
processing restructuring (by grouping the devices).

Replace the new pvcreate code added by commit
54685c20fc9dfb155a2e5bc9d8cf5f0aad944305 "filters: fix regression caused
by commit e80884cd080cad7e10be4588e3493b9000649426"
with this change to _pvcreate_check().

The filter refresh problem dates back to commit
acb4b5e4de3c49d36fe756f6fb9997ec179b89c2 "Fix pvcreate device check."

WHATS_NEW
lib/metadata/metadata.c
tools/pvcreate.c

index 28f7e363295d5f99bd4369bd64e4fe2ed12541f7..0ca048596c2f5ae609338bd3f698ef5d155764ba 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.110 -
 ==================================
+  Fix pvcreate_check() to update cache correctly after signature wiping.
   Fix primary device lookup failure for partition when processing mpath filter.
   If LV inactive and non-clustered, do not issue "Cannot deactivate" on -aln.
   Remove spurious "Skipping mirror LV" message on pvmove of clustered mirror.
index 6f88fd846409deab51d6261762700878affa20df..d4832253665f386201191da043829ab00ad3a48f 100644 (file)
@@ -1329,11 +1329,14 @@ int vg_split_mdas(struct cmd_context *cmd __attribute__((unused)),
  * See if we may pvcreate on this device.
  * 0 indicates we may not.
  */
-static int pvcreate_check(struct cmd_context *cmd, const char *name,
-                         struct pvcreate_params *pp)
+static int _pvcreate_check(struct cmd_context *cmd, const char *name,
+                          struct pvcreate_params *pp)
 {
        struct physical_volume *pv;
        struct device *dev;
+       int r = 0;
+       int scan_needed = 0;
+       int filter_refresh_needed = 0;
 
        /* FIXME Check partition type is LVM unless --force is given */
 
@@ -1345,7 +1348,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
        if (pv && !is_orphan(pv) && pp->force != DONT_PROMPT_OVERRIDE) {
                log_error("Can't initialize physical volume \"%s\" of "
                          "volume group \"%s\" without -ff", name, pv_vg_name(pv));
-               goto bad;
+               goto out;
        }
 
        /* prompt */
@@ -1353,28 +1356,29 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
            yes_no_prompt("Really INITIALIZE physical volume \"%s\" of volume group \"%s\" [y/n]? ",
                          name, pv_vg_name(pv)) == 'n') {
                log_error("%s: physical volume not initialized", name);
-               goto bad;
+               goto out;
        }
 
        if (sigint_caught())
-               goto_bad;
+               goto_out;
 
        dev = dev_cache_get(name, cmd->filter);
 
        /* Is there an md superblock here? */
-       /* FIXME: still possible issues here - rescan cache? */
        if (!dev && md_filtering()) {
                if (!refresh_filters(cmd))
-                       goto_bad;
+                       goto_out;
 
                init_md_filtering(0);
                dev = dev_cache_get(name, cmd->filter);
                init_md_filtering(1);
+
+               scan_needed = 1;
        }
 
        if (!dev) {
                log_error("Device %s not found (or ignored by filtering).", name);
-               goto bad;
+               goto out;
        }
 
        /*
@@ -1384,33 +1388,39 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
                /* FIXME Detect whether device-mapper itself is still using it */
                log_error("Can't open %s exclusively.  Mounted filesystem?",
                          name);
-               goto bad;
+               goto out;
        }
 
        if (!wipe_known_signatures(cmd, dev, name,
                                   TYPE_LVM1_MEMBER | TYPE_LVM2_MEMBER,
                                   0, pp->yes, pp->force)) {
                log_error("Aborting pvcreate on %s.", name);
-               goto bad;
-       }
+               goto out;
+       } else
+               filter_refresh_needed = scan_needed = 1;
+       
 
        if (sigint_caught())
-               goto_bad;
+               goto_out;
 
-       if (pv && !is_orphan(pv) && pp->force) {
+       if (pv && !is_orphan(pv) && pp->force)
                log_warn("WARNING: Forcing physical volume creation on "
                          "%s%s%s%s", name,
                          !is_orphan(pv) ? " of volume group \"" : "",
                          pv_vg_name(pv),
                          !is_orphan(pv) ? "\"" : "");
-       }
 
-       free_pv_fid(pv);
-       return 1;
+       r = 1;
+
+out:
+       if (filter_refresh_needed)
+               refresh_filters(cmd);
+
+       if (scan_needed)
+               lvmcache_label_scan(cmd, 2);
 
-bad:
        free_pv_fid(pv);
-       return 0;
+       return r;
 }
 
 void pvcreate_params_set_defaults(struct pvcreate_params *pp)
@@ -1542,7 +1552,7 @@ struct physical_volume *pvcreate_vol(struct cmd_context *cmd, const char *pv_nam
                }
        }
 
-       if (!pvcreate_check(cmd, pv_name, pp))
+       if (!_pvcreate_check(cmd, pv_name, pp))
                goto_bad;
 
        if (sigint_caught())
index 67ecd41c99aae0014bb3871f27c6eb2ffb445ab6..958e353b5a6deb0a1e8247eea6a6092702888635 100644 (file)
@@ -105,15 +105,6 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv)
                return EINVALID_CMD_LINE;
        }
 
-       /*
-        * Make sure we don't overwrite any existing signature
-        * that may have been created after last time we did filtering.
-        */
-       if (!(refresh_filters(cmd))) {
-               log_error("Failed to refresh filters before pvcreate.");
-               return ECMD_FAILED;
-       }
-
        for (i = 0; i < argc; i++) {
                if (sigint_caught())
                        return_ECMD_FAILED;
This page took 0.057265 seconds and 5 git commands to generate.