]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- add ostream operators for LvmCache
authorOndrej Kozina <okozina@redhat.com>
Mon, 26 Aug 2013 15:57:59 +0000 (17:57 +0200)
committerOndrej Kozina <okozina@redhat.com>
Mon, 26 Aug 2013 15:57:59 +0000 (17:57 +0200)
snapper/Lvm.cc
snapper/LvmCache.cc
snapper/LvmCache.h

index f7e6a58263174c4536081ea32702d1af59b8b791..d285ad6fe404b47feaa449a5742a8e9917dc948f 100644 (file)
@@ -208,6 +208,7 @@ namespace snapper
        catch (const LvmCacheException& e)
        {
            y2war("lvm cache failed");
+           y2deb(cache);
        }
     }
 
@@ -226,6 +227,7 @@ namespace snapper
        catch (const LvmCacheException& e)
        {
            y2war("lvm cache failed");
+           y2deb(cache);
        }
 
        SDir info_dir = openInfoDir(num);
@@ -321,6 +323,7 @@ namespace snapper
        catch(const LvmCacheException& e)
        {
            y2err("Lvm cache failure");
+           y2deb(cache);
            return false;
        }
 
@@ -347,6 +350,7 @@ namespace snapper
            catch(const LvmCacheException& e)
            {
                y2err("Couldn't activate snapshot " << vg_name << "/" << lv_name);
+               y2deb(cache);
                throw LvmActivationException();
            }
        }
@@ -374,6 +378,7 @@ namespace snapper
            catch(const LvmCacheException& e)
            {
                y2war("lvm cache failure");
+               y2deb(cache);
                throw LvmDeactivatationException();
            }
        }
index ea8a8693ac435ff87e29d234d655ee380262e46b..2f21bdc2533e4b3f88dbbc2481388228478c680d 100644 (file)
@@ -185,6 +185,13 @@ namespace snapper
     }
 
 
+    void
+    LogicalVolume::debug(std::ostream& out) const
+    {
+       out << attrs;
+    }
+
+
     VolumeGroup::VolumeGroup(vg_content_raw& input, const string& vg_name, const string& add_lv_name)
        : vg_name(vg_name)
     {
@@ -345,6 +352,17 @@ namespace snapper
     }
 
 
+    void
+    VolumeGroup::debug(std::ostream& out) const
+    {
+       // do not allow any modifications in a whole VG
+       boost::unique_lock<boost::upgrade_mutex> unique_lock(vg_mutex);
+
+       for (const_iterator cit = lv_info_map.begin(); cit != lv_info_map.end(); cit++)
+           out << "\tLV:'" << cit->first << "':" << std::endl << "\t\t" << cit->second;
+    }
+
+
     LvmCache*
     LvmCache::get_lvm_cache()
     {
@@ -422,10 +440,14 @@ namespace snapper
     {
        const_iterator cit = vgroups.find(vg_name);
        if (cit == vgroups.end())
+       {
            add_vg(vg_name, lv_name);
+           y2deb("lvm cache: added new vg: " << vg_name << ", including lv: " << lv_name);
+       }
        else
        {
            cit->second->add_or_update(lv_name);
+           y2deb("lvm cache: updated lv details for " << lv_name);
        }
     }
 
@@ -449,6 +471,8 @@ namespace snapper
            y2err(vg_name << "/" << lv_name << " already in cache!");
            throw;
        }
+
+       y2deb("lvm cache: added new lv: " << lv_name << " in vg: " << vg_name);
     }
 
 
@@ -489,6 +513,8 @@ namespace snapper
 
        if (cit != vgroups.end())
            cit->second->remove(lv_name);
+
+       y2deb("lvm cache: removed lv " << lv_name << " from vg " << vg_name);
     }
 
 
@@ -512,5 +538,48 @@ namespace snapper
            y2err("lvm cache failed to rename " << vg_name << "/" << old_name << " ->  " << vg_name << "/" << new_name);
            throw;
        }
+
+       y2deb("lvm cache: in vg " << vg_name << " " << old_name << " was renamed to " << new_name);
+    }
+
+
+    std::ostream&
+    operator<<(std::ostream& out, const LvmCache* cache)
+    {
+       out << "LvmCache:" << std::endl;
+       for (LvmCache::const_iterator cit = cache->vgroups.begin(); cit != cache->vgroups.end(); cit++)
+           out << "Volume Group:'" << cit->first << "':" << std::endl << cit->second;
+
+       return out;
+    }
+
+
+    std::ostream&
+    operator<<(std::ostream& out, const VolumeGroup* vg)
+    {
+       vg->debug(out);
+
+       return out;
+    }
+
+
+    std::ostream&
+    operator<<(std::ostream& out, const LogicalVolume* lv)
+    {
+       lv->debug(out);
+
+       return out;
+    }
+
+
+    std::ostream&
+    operator<<(std::ostream& out, const LvAttrs& a)
+    {
+       out << "active='" << (a.active ? "true" : "false") << "',readonly='"
+           << (a.readonly ? "true" : "false") << "',thin='"
+           << (a.thin ? "true" : "false") << ",pool='" << a.pool << "'"
+           << std::endl;
+
+       return out;
     }
 }
index 29d257598cd6a508f5c8ea8da62351e4f6a40a52..65dafd0684839dd0808efe06989d5f800f9d8648 100644 (file)
@@ -82,7 +82,11 @@ namespace snapper
        bool readonly(); // shared
        bool thin(); // shared
 
+       friend std::ostream& operator<<(std::ostream& out, const LogicalVolume* cache);
+
     private:
+       void debug(std::ostream& out) const;
+
        const VolumeGroup* vg;
        const string lv_name;
        const LvmCapabilities* caps;
@@ -121,7 +125,11 @@ namespace snapper
        void remove(const string& lv_name); // excl lock
        void rename(const string& old_name, const string& new_name); // upg lock -> excl
 
+       friend std::ostream& operator<<(std::ostream& out, const VolumeGroup* vg);
+
     private:
+       void debug(std::ostream& out) const;
+
        const string vg_name;
 
        mutable boost::upgrade_mutex vg_mutex;
@@ -159,6 +167,7 @@ namespace snapper
        // rename snapshots (used during import)
        void rename(const string& vg_name, const string& old_name, const string& new_name) const;
 
+       friend std::ostream& operator<<(std::ostream& out, const LvmCache* cache);
     private:
        LvmCache() {}
 
@@ -167,5 +176,7 @@ namespace snapper
 
        map<string, VolumeGroup*> vgroups;
     };
+
+    std::ostream& operator<<(std::ostream& out, const LvAttrs& a);
 }
 #endif // SNAPPER_LVM_CACHE_H