Do not allow deactivating LUKS containers containing active LVM physical volumes.

This commit is contained in:
Andrius Štikonas 2016-10-30 02:31:46 +00:00
parent 2414b69be1
commit 3272cd3f5f
5 changed files with 28 additions and 14 deletions

View File

@ -23,6 +23,7 @@
#include "fs/filesystem.h" #include "fs/filesystem.h"
#include "fs/filesystemfactory.h" #include "fs/filesystemfactory.h"
#include "fs/luks.h"
#include "util/externalcommand.h" #include "util/externalcommand.h"
#include "util/report.h" #include "util/report.h"
@ -283,7 +284,13 @@ bool Partition::canMount() const
/** @return true if this Partition can be unmounted */ /** @return true if this Partition can be unmounted */
bool Partition::canUnmount() const bool Partition::canUnmount() const
{ {
return !roles().has(PartitionRole::Extended) && isMounted(); return !roles().has(PartitionRole::Extended) && isMounted() && fileSystem().canUnmount(deviceNode());
}
void Partition::setMounted(bool b) {
m_IsMounted = b;
if (roles().has(PartitionRole::Luks))
static_cast<FS::luks*>(m_FileSystem)->setMounted(b);
} }
/** Tries to mount a Partition. /** Tries to mount a Partition.

View File

@ -100,6 +100,8 @@ class LIBKPMCORE_EXPORT Partition : public PartitionNode
friend class SetPartFlagsJob; friend class SetPartFlagsJob;
friend class RestoreFileSystemJob; friend class RestoreFileSystemJob;
friend class DeactivateVolumeGroupJob;
friend QTextStream& operator<<(QTextStream& stream, const Partition& p); friend QTextStream& operator<<(QTextStream& stream, const Partition& p);
public: public:
@ -254,9 +256,8 @@ protected:
m_SectorSize = s; m_SectorSize = s;
} }
void move(qint64 newStartSector); void move(qint64 newStartSector);
void setMounted(bool b) { void setMounted(bool b);
m_IsMounted = b;
}
void setFlag(PartitionTable::Flag f) { void setFlag(PartitionTable::Flag f) {
m_ActiveFlags |= f; m_ActiveFlags |= f;
} }

View File

@ -625,7 +625,7 @@ void luks::initLUKS(FileSystem* fs)
luksFS->setCryptOpen(isCryptOpen); luksFS->setCryptOpen(isCryptOpen);
if (isCryptOpen) { if (isCryptOpen) {
luksFS->loadInnerFileSystem(mapperNode); luksFS->loadInnerFileSystem(mapperNode);
luksFS->setMounted(::isMounted(mapperNode)); //isMounted from helpers.h luksFS->setMounted(detectMountStatus(luksFS->innerFS(), mapperNode));
} }
} }
} }

View File

@ -174,29 +174,29 @@ QString lvm2_pv::readUUID(const QString& deviceNode) const
bool lvm2_pv::mount(Report& report, const QString& deviceNode, const QString& mountPoint) bool lvm2_pv::mount(Report& report, const QString& deviceNode, const QString& mountPoint)
{ {
Q_UNUSED(report); Q_UNUSED(report)
Q_UNUSED(deviceNode); Q_UNUSED(deviceNode)
Q_UNUSED(mountPoint); Q_UNUSED(mountPoint)
return false; return false;
} }
bool lvm2_pv::unmount(Report& report, const QString& deviceNode) bool lvm2_pv::unmount(Report& report, const QString& deviceNode)
{ {
Q_UNUSED(deviceNode); Q_UNUSED(deviceNode)
Q_UNUSED(report); Q_UNUSED(report)
return false; return false;
} }
bool lvm2_pv::canMount(const QString& deviceNode, const QString& mountPoint) const bool lvm2_pv::canMount(const QString& deviceNode, const QString& mountPoint) const
{ {
Q_UNUSED(deviceNode); Q_UNUSED(deviceNode)
Q_UNUSED(mountPoint); Q_UNUSED(mountPoint)
return false; return false;
} }
bool lvm2_pv::canUnmount(const QString& deviceNode) const bool lvm2_pv::canUnmount(const QString& deviceNode) const
{ {
Q_UNUSED(deviceNode); Q_UNUSED(deviceNode)
return false; return false;
} }

View File

@ -18,6 +18,7 @@
#include "jobs/deactivatevolumegroupjob.h" #include "jobs/deactivatevolumegroupjob.h"
#include "core/lvmdevice.h" #include "core/lvmdevice.h"
#include "core/partition.h"
#include "util/report.h" #include "util/report.h"
@ -38,7 +39,12 @@ bool DeactivateVolumeGroupJob::run(Report& parent)
Report* report = jobStarted(parent); Report* report = jobStarted(parent);
if (device().type() == Device::LVM_Device) { if (device().type() == Device::LVM_Device) {
rval = LvmDevice::deactivateVG(*report, dynamic_cast<LvmDevice&>(device())); rval = LvmDevice::deactivateVG(*report, static_cast<LvmDevice&>(device()));
}
const auto lvmPVs = static_cast<LvmDevice&>(device()).physicalVolumes();
for (auto &p : lvmPVs) {
Partition *partition = const_cast<Partition *>(p);
partition->setMounted(false);
} }
jobFinished(*report, rval); jobFinished(*report, rval);