]> sourceware.org Git - lvm2.git/commitdiff
ability to keep track of outdated pvs in lvmcache
authorDavid Teigland <teigland@redhat.com>
Tue, 5 Feb 2019 18:55:51 +0000 (12:55 -0600)
committerDavid Teigland <teigland@redhat.com>
Fri, 7 Jun 2019 20:54:04 +0000 (15:54 -0500)
Outdated PVs hold metadata for VG from which they
have been removed.  Add the ability to keep track
of these in lvmcache.
This will be used for more advanced repair in a
subsequent commit.

lib/cache/lvmcache.c
lib/cache/lvmcache.h

index a36e14535fba10698d2a5d23fd91f64337b6d704..a8606601534b207b01fb047ef7774af1bc04a230 100644 (file)
@@ -48,6 +48,7 @@ struct lvmcache_info {
 struct lvmcache_vginfo {
        struct dm_list list;    /* Join these vginfos together */
        struct dm_list infos;   /* List head for lvmcache_infos */
+       struct dm_list outdated_infos; /* vg_read moves info from infos to outdated_infos */
        const struct format_type *fmt;
        char *vgname;           /* "" == orphan */
        uint32_t status;
@@ -1389,6 +1390,7 @@ static int _lvmcache_update_vgname(struct lvmcache_info *info,
                        return 0;
                }
                dm_list_init(&vginfo->infos);
+               dm_list_init(&vginfo->outdated_infos);
 
                /*
                 * A different VG (different uuid) can exist with the same name.
@@ -2392,3 +2394,81 @@ struct metadata_area *lvmcache_get_mda(struct cmd_context *cmd,
        return NULL;
 }
 
+void lvmcache_get_outdated_devs(struct cmd_context *cmd,
+                               const char *vgname, const char *vgid,
+                               struct dm_list *devs)
+{
+       struct lvmcache_vginfo *vginfo;
+       struct lvmcache_info *info;
+       struct device_list *devl;
+
+       if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, vgid))) {
+               log_error(INTERNAL_ERROR "lvmcache_get_outdated_devs no vginfo %s", vgname);
+               return;
+       }
+
+       dm_list_iterate_items(info, &vginfo->outdated_infos) {
+               if (!(devl = zalloc(sizeof(*devl))))
+                       return;
+               devl->dev = info->dev;
+               dm_list_add(devs, &devl->list);
+       }
+}
+
+void lvmcache_del_outdated_devs(struct cmd_context *cmd,
+                               const char *vgname, const char *vgid)
+{
+       struct lvmcache_vginfo *vginfo;
+       struct lvmcache_info *info, *info2;
+
+       if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, vgid))) {
+               log_error(INTERNAL_ERROR "lvmcache_get_outdated_devs no vginfo");
+               return;
+       }
+
+       dm_list_iterate_items_safe(info, info2, &vginfo->outdated_infos)
+               lvmcache_del(info);
+}
+
+void lvmcache_get_outdated_mdas(struct cmd_context *cmd,
+                               const char *vgname, const char *vgid,
+                               struct device *dev,
+                               struct dm_list **mdas)
+{
+       struct lvmcache_vginfo *vginfo;
+       struct lvmcache_info *info;
+
+       *mdas = NULL;
+
+       if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, vgid))) {
+               log_error(INTERNAL_ERROR "lvmcache_get_outdated_mdas no vginfo");
+               return;
+       }
+
+       dm_list_iterate_items(info, &vginfo->outdated_infos) {
+               if (info->dev != dev)
+                       continue;
+               *mdas = &info->mdas;
+               return;
+       }
+}
+
+bool lvmcache_is_outdated_dev(struct cmd_context *cmd,
+                            const char *vgname, const char *vgid,
+                            struct device *dev)
+{
+       struct lvmcache_vginfo *vginfo;
+       struct lvmcache_info *info;
+
+       if (!(vginfo = lvmcache_vginfo_from_vgname(vgname, vgid))) {
+               log_error(INTERNAL_ERROR "lvmcache_get_outdated_mdas no vginfo");
+               return false;
+       }
+
+       dm_list_iterate_items(info, &vginfo->outdated_infos) {
+               if (info->dev == dev)
+                       return true;
+       }
+
+       return false;
+}
index dd6730e3fe2a0d117235572f1ad8df8ed6daf983..0f83c80aa2a59ec4af21bb0509cb9f626e724f93 100644 (file)
@@ -222,6 +222,21 @@ int dev_in_device_list(struct device *dev, struct dm_list *head);
 
 bool lvmcache_has_bad_metadata(struct device *dev);
 
+void lvmcache_get_outdated_devs(struct cmd_context *cmd,
+                                const char *vgname, const char *vgid,
+                                struct dm_list *devs);
+void lvmcache_get_outdated_mdas(struct cmd_context *cmd,
+                                const char *vgname, const char *vgid,
+                                struct device *dev,
+                                struct dm_list **mdas);
+
+bool lvmcache_is_outdated_dev(struct cmd_context *cmd,
+                              const char *vgname, const char *vgid,
+                              struct device *dev);
+
+void lvmcache_del_outdated_devs(struct cmd_context *cmd,
+                                const char *vgname, const char *vgid);
+
 void lvmcache_save_bad_mda(struct lvmcache_info *info, struct metadata_area *mda);
 
 void lvmcache_get_bad_mdas(struct cmd_context *cmd,
This page took 0.037502 seconds and 5 git commands to generate.