From: Ondrej Kozina Date: Mon, 26 Aug 2013 15:57:59 +0000 (+0200) Subject: - add ostream operators for LvmCache X-Git-Tag: v0.1.7~8^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dce582efe1e2db85319bdacd01f0ab4c1f7c06a8;p=thirdparty%2Fsnapper.git - add ostream operators for LvmCache --- diff --git a/snapper/Lvm.cc b/snapper/Lvm.cc index f7e6a582..d285ad6f 100644 --- a/snapper/Lvm.cc +++ b/snapper/Lvm.cc @@ -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(); } } diff --git a/snapper/LvmCache.cc b/snapper/LvmCache.cc index ea8a8693..2f21bdc2 100644 --- a/snapper/LvmCache.cc +++ b/snapper/LvmCache.cc @@ -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 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; } } diff --git a/snapper/LvmCache.h b/snapper/LvmCache.h index 29d25759..65dafd06 100644 --- a/snapper/LvmCache.h +++ b/snapper/LvmCache.h @@ -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 vgroups; }; + + std::ostream& operator<<(std::ostream& out, const LvAttrs& a); } #endif // SNAPPER_LVM_CACHE_H