]> sourceware.org Git - lvm2.git/commitdiff
Read PV metadata information from cache if pv_setup called with pv->fid == vg->fid.
authorPeter Rajnoha <prajnoha@redhat.com>
Fri, 25 Feb 2011 13:59:47 +0000 (13:59 +0000)
committerPeter Rajnoha <prajnoha@redhat.com>
Fri, 25 Feb 2011 13:59:47 +0000 (13:59 +0000)
If the PV is already part of the VG (so the pv->fid == vg->fid), it makes no
sense to attach the mdas information from PV to a VG. Instead, we read new
PV metadata information from cache and attach it to the VG fid.

lib/format_text/archiver.c
lib/format_text/format-text.c
lib/metadata/metadata.c

index 71b312cad01179011df2dedc7c85f7b9e2118d8e..8c926f02d5bdc9b1b56b414c09d36eef77080f00 100644 (file)
@@ -294,8 +294,6 @@ struct volume_group *backup_read_vg(struct cmd_context *cmd,
 int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
 {
        struct pv_list *pvl;
-       struct physical_volume *pv;
-       struct lvmcache_info *info;
        struct format_instance *fid;
        struct format_instance_ctx fic;
 
@@ -305,7 +303,7 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
         */
 
        /* Attempt to write out using currently active format */
-       fic.type = FMT_INSTANCE_VG | FMT_INSTANCE_MDAS | FMT_INSTANCE_AUX_MDAS;
+       fic.type = FMT_INSTANCE_VG | FMT_INSTANCE_AUX_MDAS;
        fic.context.vg_ref.vg_name = vg->name;
        fic.context.vg_ref.vg_id = NULL;
        if (!(fid = cmd->fmt->ops->create_instance(cmd->fmt, &fic))) {
@@ -322,20 +320,9 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg)
 
        /* Add any metadata areas on the PVs */
        dm_list_iterate_items(pvl, &vg->pvs) {
-               pv = pvl->pv;
-               if (!(info = info_from_pvid(pv->dev->pvid, 0))) {
-                       log_error("PV %s missing from cache",
-                                 pv_dev_name(pv));
-                       return 0;
-               }
-               if (cmd->fmt != info->fmt) {
-                       log_error("PV %s is a different format (seqno %s)",
-                                 pv_dev_name(pv), info->fmt->name);
-                       return 0;
-               }
-               if (!vg->fid->fmt->ops->pv_setup(vg->fid->fmt, pv, vg)) {
+               if (!vg->fid->fmt->ops->pv_setup(vg->fid->fmt, pvl->pv, vg)) {
                        log_error("Format-specific setup for %s failed",
-                                 pv_dev_name(pv));
+                                 pv_dev_name(pvl->pv));
                        return 0;
                }
        }
index 44d1fda359a41a85074ed939162017ccb70a7340..78f9ff9f9beed72fbe4a021b7af3f9ad4897df27 100644 (file)
@@ -1645,20 +1645,42 @@ static int _text_pv_setup(const struct format_type *fmt,
 {
        struct format_instance *fid = pv->fid;
        const char *pvid = (const char *) (*pv->old_id.uuid ? &pv->old_id : &pv->id);
+       struct lvmcache_info *info;
        unsigned mda_index;
        struct metadata_area *pv_mda;
        struct mda_context *pv_mdac;
        uint64_t pe_count;
        uint64_t size_reduction = 0;
 
-       /* Add any further mdas on this PV to VG's format instance. */
-       for (mda_index = 0; mda_index < FMT_TEXT_MAX_MDAS_PER_PV; mda_index++) {
-               if (!(pv_mda = fid_get_mda_indexed(fid, pvid, ID_LEN, mda_index)))
-                       continue;
+       /* If PV has its own format instance, add mdas from pv->fid to vg->fid. */
+       if (pv->fid != vg->fid) {
+               for (mda_index = 0; mda_index < FMT_TEXT_MAX_MDAS_PER_PV; mda_index++) {
+                       if (!(pv_mda = fid_get_mda_indexed(fid, pvid, ID_LEN, mda_index)))
+                               continue;
 
-               /* Be sure it's not already in VG's format instance! */
-               if (!fid_get_mda_indexed(vg->fid, pvid, ID_LEN, mda_index))
-                       fid_add_mda(vg->fid, pv_mda, pvid, ID_LEN, mda_index);
+                       /* Be sure it's not already in VG's format instance! */
+                       if (!fid_get_mda_indexed(vg->fid, pvid, ID_LEN, mda_index))
+                               fid_add_mda(vg->fid, pv_mda, pvid, ID_LEN, mda_index);
+               }
+       }
+       /*
+        * Otherwise, if the PV is already a part of the VG (pv->fid == vg->fid),
+        * reread PV mda information from the cache and add it to vg->fid.
+        */
+       else {
+               if (!(info = info_from_pvid(pv->dev->pvid, 0))) {
+                       log_error("PV %s missing from cache", pv_dev_name(pv));
+                       return 0;
+               }
+
+               if (fmt != info->fmt) {
+                       log_error("PV %s is a different format (seqno %s)",
+                                 pv_dev_name(pv), info->fmt->name);
+                       return 0;
+               }
+
+               if (!fid_add_mdas(vg->fid, &info->mdas, pvid, ID_LEN))
+                       return_0;
        }
 
        /* If there's the 2nd mda, we need to reduce
index 6a29d24bf7a94f18d04c04f127f38dfafbc2e11c..d1930fc074460d040d70df21485edda5d618d40f 100644 (file)
@@ -4105,7 +4105,7 @@ int fid_add_mdas(struct format_instance *fid, struct dm_list *mdas,
                mda_new = mda_copy(fid->fmt->cmd->mem, mda);
                if (!mda_new)
                        return_0;
-
+               fid_remove_mda(fid, NULL, key, key_len, mda_index);
                fid_add_mda(fid, mda_new, key, key_len, mda_index);
                mda_index++;
        }
This page took 0.085985 seconds and 5 git commands to generate.