if (!attrs.active)
{
- boost::upgrade_to_unique_lock<boost::upgrade_mutex> unique_lock(upg_lock);
-
- SystemCmd cmd(LVCHANGEBIN + caps->get_ignoreactivationskip() + " -ay " + quote(vg->get_vg_name() + "/" + lv_name));
- if (cmd.retcode() != 0)
{
- y2err("Couldn't activate snapshot " << vg->get_vg_name() << "/" << lv_name);
- throw LvmActivationException();
+ boost::upgrade_to_unique_lock<boost::upgrade_mutex> unique_lock(upg_lock);
+
+ SystemCmd cmd(LVCHANGEBIN + caps->get_ignoreactivationskip() + " -ay " + quote(vg->get_vg_name() + "/" + lv_name));
+ if (cmd.retcode() != 0)
+ {
+ y2err("lvm cache: " << vg->get_vg_name() << "/" << lv_name << " activation failed!");
+ throw LvmCacheException();
+ }
+
+ attrs.active = true;
}
- attrs.active = true;
+ y2deb("lvm cache: " << vg->get_vg_name() << "/" << lv_name << " activated");
}
}
if (attrs.active)
{
- boost::upgrade_to_unique_lock<boost::upgrade_mutex> unique_lock(upg_lock);
-
- SystemCmd cmd(LVCHANGEBIN " -an " + quote(vg->get_vg_name() + "/" + lv_name));
- if (cmd.retcode() != 0)
{
- y2err("Couldn't activate snapshot " << vg->get_vg_name() << "/" << lv_name);
- throw LvmDeactivatationException();
+ boost::upgrade_to_unique_lock<boost::upgrade_mutex> unique_lock(upg_lock);
+
+ SystemCmd cmd(LVCHANGEBIN " -an " + quote(vg->get_vg_name() + "/" + lv_name));
+ if (cmd.retcode() != 0)
+ {
+ y2err("lvm cache: " << vg->get_vg_name() << "/" << lv_name << " deactivation failed!");
+ throw LvmCacheException();
+ }
+
+ attrs.active = false;
}
- attrs.active = false;
+ y2deb("lvm cache: " << vg->get_vg_name() << "/" << lv_name << " deactivated");
}
}
if (cmd.retcode() != 0 || cmd.numLines() < 1)
{
- y2err("lvm cache failed to get info about " << vg->get_vg_name() << "/" << lv_name);
+ y2err("lvm cache: failed to get info about " << vg->get_vg_name() << "/" << lv_name);
throw LvmCacheException();
}
iterator it = lv_info_map.find(lv_name);
if (it == lv_info_map.end())
{
- y2err(vg_name << "/" << lv_name << " is not in cache!");
+ y2err("lvm cache: " << vg_name << "/" << lv_name << " is not in cache!");
throw LvmCacheException();
}
iterator it = lv_info_map.find(lv_name);
if (it == lv_info_map.end())
{
- y2err(vg_name << "/" << lv_name << " is not in cache!");
+ y2err("lvm cache: " << vg_name << "/" << lv_name << " is not in cache!");
throw LvmCacheException();
}
void
- VolumeGroup::add(const string& lv_name)
+ VolumeGroup::create_snapshot(const string& lv_origin_name, const string& lv_snapshot_name)
{
- boost::unique_lock<boost::upgrade_mutex> lock(vg_mutex);
+ boost::upgrade_lock<boost::upgrade_mutex> upg_lock(vg_mutex);
+
+ if (lv_info_map.find(lv_snapshot_name) != lv_info_map.end())
+ {
+ y2err("lvm cache: " << vg_name << "/" << lv_snapshot_name << " already in cache!");
+ throw LvmCacheException();
+ }
- if (!lv_info_map.insert(make_pair(lv_name, new LogicalVolume(this, lv_name))).second)
+ boost::upgrade_to_unique_lock<boost::upgrade_mutex> unique_lock(upg_lock);
+
+ SystemCmd cmd(LVCREATEBIN " --permission r --snapshot --name " +
+ quote(lv_snapshot_name) + " " + quote(vg_name + "/" + lv_origin_name));
+
+ if (cmd.retcode() != 0)
throw LvmCacheException();
+
+ lv_info_map.insert(make_pair(lv_snapshot_name, new LogicalVolume(this, lv_snapshot_name)));
}
SystemCmd cmd(LVSBIN " --noheadings -o lv_attr,segtype,pool_lv " + quote(vg_name + "/" + lv_name));
if (cmd.retcode() != 0 || cmd.numLines() < 1)
{
- y2err("lvm cache failed to get info about " << vg_name << "/" << lv_name);
+ y2err("lvm cache: failed to get info about " << vg_name << "/" << lv_name);
throw LvmCacheException();
}
void
- VolumeGroup::remove(const string& lv_name)
+ VolumeGroup::remove_lv(const string& lv_name)
{
- boost::unique_lock<boost::upgrade_mutex> unique_lock(vg_mutex);
+ boost::upgrade_lock<boost::upgrade_mutex> upg_lock(vg_mutex);
const_iterator cit = lv_info_map.find(lv_name);
if (cit == lv_info_map.end())
+ {
+ y2err("lvm cache: " << vg_name << "/" << lv_name << " is not in cache!");
+ throw LvmCacheException();
+ }
+
+ // wait for all invidual lv cache operations under shared vg lock to finish
+ boost::upgrade_to_unique_lock<boost::upgrade_mutex> unique_lock(upg_lock);
+
+ SystemCmd cmd(LVREMOVEBIN " --force " + quote(vg_name + "/" + lv_name));
+ if (cmd.retcode() != 0)
throw LvmCacheException();
delete cit->second;
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::upgrade_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;
if (cit == vgroups.end())
{
- y2err("VG " << vg_name << " is not in cache!");
+ y2err("lvm cache: VG " << vg_name << " is not in cache!");
throw LvmCacheException();
}
if (cit == vgroups.end())
{
- y2err("VG " << vg_name << " is not in cache!");
+ y2err("lvm cache: VG " << vg_name << " is not in cache!");
throw LvmCacheException();
}
void
- LvmCache::add(const string& vg_name, const string& lv_name) const
+ LvmCache::create_snapshot(const string& vg_name, const string& lv_origin_name, const string& lv_snapshot_name)
{
const_iterator cit = vgroups.find(vg_name);
if (cit == vgroups.end())
throw LvmCacheException();
}
- try
- {
- cit->second->add(lv_name);
- }
- catch(const LvmCacheException& e)
- {
- y2err(vg_name << "/" << lv_name << " already in cache!");
- throw;
- }
+ cit->second->create_snapshot(lv_origin_name, lv_snapshot_name);
- y2deb("lvm cache: added new lv: " << lv_name << " in vg: " << vg_name);
+ y2deb("lvm cache: created new snapshot: " << lv_snapshot_name << " in vg: " << vg_name);
}
SystemCmd cmd(LVSBIN " --noheadings -o lv_name,lv_attr,segtype,pool_lv " + quote(vg_name));
if (cmd.retcode() != 0)
{
- y2err("lvm cache failed to get info about VG: " << vg_name);
+ y2err("lvm cache: failed to get info about VG " << vg_name);
throw LvmCacheException();
}
void
- LvmCache::remove(const string& vg_name, const string& lv_name) const
+ LvmCache::delete_snapshot(const string& vg_name, const string& lv_name) const
{
const_iterator cit = vgroups.find(vg_name);
- if (cit != vgroups.end())
- cit->second->remove(lv_name);
+ if (cit == vgroups.end())
+ {
+ y2err("lvm cache: VG " << vg_name << " not in cache!");
+ throw LvmCacheException();
+ }
+
+ cit->second->remove_lv(lv_name);
- y2deb("lvm cache: removed lv " << lv_name << " from vg " << vg_name);
+ y2deb("lvm cache: removed " << vg_name << "/" << lv_name);
}
if (cit == vgroups.end())
{
- y2err("VG " << vg_name << " is not in cache!");
+ y2err("lvm cache: VG " << vg_name << " is not in cache!");
throw LvmCacheException();
}
- try
- {
- cit->second->rename(old_name, new_name);
- }
- catch (const LvmCacheException& e)
- {
- y2err("lvm cache failed to rename " << vg_name << "/" << old_name << " -> " << vg_name << "/" << new_name);
- throw;
- }
+ cit->second->rename(old_name, new_name);
- y2deb("lvm cache: in vg " << vg_name << " " << old_name << " was renamed to " << new_name);
+ y2deb("lvm cache: " << vg_name << "/" << old_name << " renamed to " << vg_name << "/" << new_name);
}
bool read_only(const string& lv_name) const; // shared lock
- void add(const string& lv_name); // excl 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(const string& lv_name); // excl lock
+ 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_thin(const string& vg_name, const string& lv_name) const;
bool read_only(const string& vg_name, const string& lv_name) const;
- // add snapshot owned by snapper
- void add(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);
// used to actualise info about origin volume
void add_or_update(const string& vg_name, const string& lv_name);
// remove snapshot owned by snapper
- void remove(const string& vg_name, const string& lv_name) const;
+ 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;