From 5e9f317250b2ef38658cc7c43080cf22978eacbc Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Mon, 30 Sep 2013 09:48:05 +0200 Subject: [PATCH] - remove unused code and lvs output parameters --- snapper/Lvm.cc | 63 +++++++------------------ snapper/Lvm.h | 6 +-- snapper/LvmCache.cc | 110 ++++---------------------------------------- snapper/LvmCache.h | 13 +----- 4 files changed, 30 insertions(+), 162 deletions(-) diff --git a/snapper/Lvm.cc b/snapper/Lvm.cc index ca49fcc8..3a0af36d 100644 --- a/snapper/Lvm.cc +++ b/snapper/Lvm.cc @@ -250,7 +250,7 @@ namespace snapper try { - activateSnapshot(vg_name, snapshotLvName(num), true); + activateSnapshot(vg_name, snapshotLvName(num)); } catch (const LvmActivationException& e) { @@ -278,7 +278,7 @@ namespace snapper try { - deactivateSnapshot(vg_name, snapshotLvName(num), true); + deactivateSnapshot(vg_name, snapshotLvName(num)); } catch (const LvmDeactivatationException& e) { @@ -290,7 +290,7 @@ namespace snapper bool Lvm::checkSnapshot(unsigned int num) const { - return detectInactiveSnapshot(vg_name, snapshotLvName(num), true); + return detectInactiveSnapshot(vg_name, snapshotLvName(num)); } @@ -329,68 +329,39 @@ namespace snapper void - Lvm::activateSnapshot(const string& vg_name, const string& lv_name, bool use_cache) const + Lvm::activateSnapshot(const string& vg_name, const string& lv_name) const { - if (use_cache) + try { - try - { - cache->activate(vg_name, lv_name); - } - catch(const LvmCacheException& e) - { - y2deb(cache); - throw LvmActivationException(); - } + cache->activate(vg_name, lv_name); } - else + catch(const LvmCacheException& e) { - SystemCmd cmd(LVCHANGEBIN + caps->get_ignoreactivationskip() + " -ay " + quote(vg_name + "/" + lv_name)); - if (cmd.retcode() != 0) - { - y2err("Couldn't activate snapshot " << vg_name << "/" << lv_name); - throw LvmActivationException(); - } + y2deb(cache); + throw LvmActivationException(); } } void - Lvm::deactivateSnapshot(const string& vg_name, const string& lv_name, bool use_cache) const + Lvm::deactivateSnapshot(const string& vg_name, const string& lv_name) const { - if (use_cache) + try { - try - { - cache->deactivate(vg_name, lv_name); - } - catch(const LvmCacheException& e) - { - y2deb(cache); - throw LvmDeactivatationException(); - } + cache->deactivate(vg_name, lv_name); } - else + catch(const LvmCacheException& e) { - SystemCmd cmd(LVCHANGEBIN " -an " + quote(vg_name + "/" + lv_name)); - if (cmd.retcode()) - throw LvmDeactivatationException(); + y2deb(cache); + throw LvmDeactivatationException(); } } bool - Lvm::detectInactiveSnapshot(const string& vg_name, const string& lv_name, bool use_cache) const + Lvm::detectInactiveSnapshot(const string& vg_name, const string& lv_name) const { - if (use_cache) - { - return cache->contains(vg_name, lv_name); - } - else - { - SystemCmd cmd(LVSBIN " " + quote(vg_name + "/" + lv_name)); - return cmd.retcode() == 0; - } + return cache->contains(vg_name, lv_name); } diff --git a/snapper/Lvm.h b/snapper/Lvm.h index 2e0936c1..fbca2f5e 100644 --- a/snapper/Lvm.h +++ b/snapper/Lvm.h @@ -109,9 +109,9 @@ namespace snapper LvmCache* cache; bool detectThinVolumeNames(const MtabData& mtab_data); - void activateSnapshot(const string& vg_name, const string& lv_name, bool use_cache) const; - void deactivateSnapshot(const string& vg_name, const string& lv_name, bool use_cache) const; - bool detectInactiveSnapshot(const string& vg_name, const string& lv_name, bool use_cache) const; + void activateSnapshot(const string& vg_name, const string& lv_name) const; + void deactivateSnapshot(const string& vg_name, const string& lv_name) const; + bool detectInactiveSnapshot(const string& vg_name, const string& lv_name) const; string getDevice(unsigned int num) const; diff --git a/snapper/LvmCache.cc b/snapper/LvmCache.cc index 0201e1e2..9bcabb9c 100644 --- a/snapper/LvmCache.cc +++ b/snapper/LvmCache.cc @@ -40,31 +40,22 @@ namespace snapper } - bool - LvAttrs::extract_readonly(const string& raw) - { - return (raw.size() > 1 && raw[1] == 'r'); - } - - LvAttrs::LvAttrs(const vector& raw) : active(raw.size() > 0 && extract_active(raw.front())), - readonly(raw.size() > 0 && extract_readonly(raw.front())), - thin(raw.size() > 1 && raw[1] == "thin"), - pool(raw.size() > 2 ? raw[2] : "") + thin(raw.size() > 1 && raw[1] == "thin") { } - LvAttrs::LvAttrs(bool active, bool readonly, bool thin, string pool) - : active(active), readonly(readonly), thin(thin), pool(pool) + LvAttrs::LvAttrs(bool active, bool thin) + : active(active), thin(thin) { } LogicalVolume::LogicalVolume(const VolumeGroup* vg, const string& lv_name) : vg(vg), lv_name(lv_name), caps(LvmCapabilities::get_lvm_capabilities()), - attrs(caps->get_ignoreactivationskip().empty(), true, true, "") + attrs(caps->get_ignoreactivationskip().empty(), true) { } @@ -150,7 +141,7 @@ namespace snapper { boost::unique_lock unique_lock(lv_mutex); - SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype,pool_lv " + quote(vg->get_vg_name() + "/" + lv_name)); + SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype " + quote(vg->get_vg_name() + "/" + lv_name)); if (cmd.retcode() != 0 || cmd.numLines() < 1) { @@ -170,15 +161,6 @@ namespace snapper } - bool - LogicalVolume::readonly() - { - boost::shared_lock shared_lock(lv_mutex); - - return attrs.readonly; - } - - bool LogicalVolume::thin() { @@ -263,17 +245,6 @@ namespace snapper } - bool - VolumeGroup::constains_read_only(const string& lv_name) const - { - boost::shared_lock shared_lock(vg_mutex); - - const_iterator cit = lv_info_map.find(lv_name); - - return cit != lv_info_map.end() && cit->second->readonly(); - } - - void VolumeGroup::create_snapshot(const string& lv_origin_name, const string& lv_snapshot_name) { @@ -310,7 +281,7 @@ namespace snapper } else { - SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype,pool_lv " + quote(vg_name + "/" + lv_name)); + SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype " + quote(vg_name + "/" + lv_name)); if (cmd.retcode() != 0 || cmd.numLines() < 1) { y2err("lvm cache: failed to get info about " << vg_name << "/" << lv_name); @@ -356,41 +327,6 @@ namespace snapper } - void - VolumeGroup::rename(const string& old_name, const string& new_name) - { - boost::upgrade_lock upg_lock(vg_mutex); - - const_iterator cit = lv_info_map.find(old_name); - - if (cit == lv_info_map.end() || lv_info_map.find(new_name) != lv_info_map.end()) - { - y2err("lvm cache: " << vg_name << "/" << old_name << - " is missing or " << vg_name << "/" << new_name << - " already in cache!"); - throw LvmCacheException(); - } - - // wait for all invidual lv cache operations under shared vg lock to finish - boost::upgrade_to_unique_lock unique_lock(upg_lock); - - SystemCmd cmd(LVRENAMEBIN " " + quote(vg_name) + " " + quote(old_name) + - " " + quote(new_name)); - - if (cmd.retcode() != 0) - { - y2err("lvm cache: " << vg_name << "/" << old_name << " -> " << - vg_name << "/" << new_name << " rename command failed!"); - throw LvmCacheException(); - } - - lv_info_map.insert(make_pair(new_name, new LogicalVolume(this, new_name, cit->second->attrs))); - - delete cit->second; - lv_info_map.erase(cit); - } - - void VolumeGroup::debug(std::ostream& out) const { @@ -447,15 +383,6 @@ namespace snapper } - bool - LvmCache::contains_read_only(const string& vg_name, const string& lv_name) const - { - const_iterator cit = vgroups.find(vg_name); - - return cit != vgroups.end() && cit->second->constains_read_only(lv_name); - } - - bool LvmCache::contains(const string& vg_name, const string& lv_name) const { @@ -510,7 +437,7 @@ namespace snapper void LvmCache::add_vg(const string& vg_name, const string& include_lv_name) { - SystemCmd cmd(LVSBIN " --noheadings -o lv_name,lv_attr,segtype,pool_lv " + quote(vg_name)); + SystemCmd cmd(LVSBIN " --noheadings -o lv_name,lv_attr,segtype " + quote(vg_name)); if (cmd.retcode() != 0) { y2err("lvm cache: failed to get info about VG " << vg_name); @@ -554,23 +481,6 @@ namespace snapper } - void - LvmCache::rename(const string& vg_name, const string& old_name, const string& new_name) const - { - const_iterator cit = vgroups.find(vg_name); - - if (cit == vgroups.end()) - { - y2err("lvm cache: VG " << vg_name << " is not in cache!"); - throw LvmCacheException(); - } - - cit->second->rename(old_name, new_name); - - y2deb("lvm cache: " << vg_name << "/" << old_name << " renamed to " << vg_name << "/" << new_name); - } - - std::ostream& operator<<(std::ostream& out, const LvmCache* cache) { @@ -603,10 +513,8 @@ namespace snapper 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; + out << "active='" << (a.active ? "true" : "false") << "',thin='" + << (a.thin ? "true" : "false") << "'" << std::endl; return out; } diff --git a/snapper/LvmCache.h b/snapper/LvmCache.h index 6cdcc990..5d5e3e3b 100644 --- a/snapper/LvmCache.h +++ b/snapper/LvmCache.h @@ -55,13 +55,10 @@ namespace snapper static bool extract_readonly(const string& raw); LvAttrs(const vector& raw); - LvAttrs(bool active, bool readonly, bool thin, string pool); - //LvAttrs() : active(false), readonly(false), thin(false), pool() {} + LvAttrs(bool active, bool thin); bool active; - bool readonly; bool thin; - string pool; }; @@ -79,7 +76,6 @@ namespace snapper void update(); // shared, unique_lock - bool readonly(); // shared bool thin(); // shared friend std::ostream& operator<<(std::ostream& out, const LogicalVolume* cache); @@ -117,13 +113,10 @@ namespace snapper bool contains(const string& lv_name) const; // shared lock bool contains_thin(const string& lv_name) const; // shared lock - bool constains_read_only(const string& lv_name) const; // shared lock - void create_snapshot(const string& lv_origin_name, const string& lv_snapshot_name); // upg lock -> excl void add_or_update(const string& lv_name); // upg lock -> excl void remove_lv(const string& lv_name); // upg lock -> excl - void rename(const string& old_name, const string& new_name); // upg lock -> excl friend std::ostream& operator<<(std::ostream& out, const VolumeGroup* vg); @@ -154,7 +147,6 @@ namespace snapper bool contains(const string& vg_name, const string& lv_name) const; bool contains_thin(const string& vg_name, const string& lv_name) const; - bool contains_read_only(const string& vg_name, const string& lv_name) const; // create snapper owned snapshot void create_snapshot(const string& vg_name, const string&lv_origin_name, const string& lv_snapshot_name); @@ -164,9 +156,6 @@ namespace snapper // remove snapshot owned by snapper void delete_snapshot(const string& vg_name, const string& lv_name) const; - // 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() {} -- 2.47.3