try
{
- activateSnapshot(vg_name, snapshotLvName(num), true);
+ activateSnapshot(vg_name, snapshotLvName(num));
}
catch (const LvmActivationException& e)
{
try
{
- deactivateSnapshot(vg_name, snapshotLvName(num), true);
+ deactivateSnapshot(vg_name, snapshotLvName(num));
}
catch (const LvmDeactivatationException& e)
{
bool
Lvm::checkSnapshot(unsigned int num) const
{
- return detectInactiveSnapshot(vg_name, snapshotLvName(num), true);
+ return detectInactiveSnapshot(vg_name, snapshotLvName(num));
}
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);
}
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;
}
- bool
- LvAttrs::extract_readonly(const string& raw)
- {
- return (raw.size() > 1 && raw[1] == 'r');
- }
-
-
LvAttrs::LvAttrs(const vector<string>& 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)
{
}
{
boost::unique_lock<boost::shared_mutex> 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)
{
}
- bool
- LogicalVolume::readonly()
- {
- boost::shared_lock<boost::shared_mutex> shared_lock(lv_mutex);
-
- return attrs.readonly;
- }
-
-
bool
LogicalVolume::thin()
{
}
- bool
- VolumeGroup::constains_read_only(const string& lv_name) const
- {
- boost::shared_lock<boost::shared_mutex> 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)
{
}
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);
}
- void
- VolumeGroup::rename(const string& old_name, const string& new_name)
- {
- boost::upgrade_lock<boost::shared_mutex> 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<boost::shared_mutex> 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
{
}
- 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
{
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);
}
- 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)
{
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;
}
static bool extract_readonly(const string& raw);
LvAttrs(const vector<string>& 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;
};
void update(); // shared, unique_lock
- bool readonly(); // shared
bool thin(); // shared
friend std::ostream& operator<<(std::ostream& out, const LogicalVolume* cache);
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);
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);
// 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() {}