Make variable names slightly more consistent thruoght kmpcore.
Add more doxygen comments.
This commit is contained in:
parent
69647e816e
commit
8a3c11774c
|
@ -72,24 +72,24 @@ static qint32 getPhysicalSectorSize(const QString& device_node)
|
|||
|
||||
/** Constructs a Disk Device with an empty PartitionTable.
|
||||
@param name the Device's name, usually some string defined by the manufacturer
|
||||
@param devicenode the Device's node, for example "/dev/sda"
|
||||
@param deviceNode the Device's node, for example "/dev/sda"
|
||||
@param heads the number of heads in CHS notation
|
||||
@param numSectors the number of sectors in CHS notation
|
||||
@param cylinders the number of cylinders in CHS notation
|
||||
@param sectorSize the size of a sector in bytes
|
||||
*/
|
||||
DiskDevice::DiskDevice(const QString& name,
|
||||
const QString& devicenode,
|
||||
const QString& deviceNode,
|
||||
qint32 heads,
|
||||
qint32 numSectors,
|
||||
qint32 cylinders,
|
||||
qint32 sectorSize,
|
||||
const QString& iconname)
|
||||
: Device(name, devicenode, sectorSize, (static_cast<qint64>(heads) * cylinders * numSectors), iconname, Device::Disk_Device)
|
||||
const QString& iconName)
|
||||
: Device(name, deviceNode, sectorSize, (static_cast<qint64>(heads) * cylinders * numSectors), iconName, Device::Disk_Device)
|
||||
, m_Heads(heads)
|
||||
, m_SectorsPerTrack(numSectors)
|
||||
, m_Cylinders(cylinders)
|
||||
, m_LogicalSectorSize(sectorSize)
|
||||
, m_PhysicalSectorSize(getPhysicalSectorSize(devicenode))
|
||||
, m_PhysicalSectorSize(getPhysicalSectorSize(deviceNode))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ class LIBKPMCORE_EXPORT DiskDevice : public Device
|
|||
friend class CoreBackend;
|
||||
|
||||
public:
|
||||
DiskDevice(const QString& name, const QString& devicenode, qint32 heads, qint32 numSectors, qint32 cylinders, qint32 sectorSize, const QString& iconname = QString());
|
||||
DiskDevice(const QString& name, const QString& deviceNode, qint32 heads, qint32 numSectors, qint32 cylinders, qint32 sectorSize, const QString& iconName = QString());
|
||||
|
||||
public:
|
||||
qint32 heads() const {
|
||||
|
|
|
@ -35,24 +35,24 @@
|
|||
|
||||
/** Constructs a representation of LVM device with functionning LV as Partitions
|
||||
*
|
||||
* @param name Volume Group name
|
||||
* @param iconname
|
||||
* @param vgName Volume Group name
|
||||
* @param iconName Icon representing LVM Volume group
|
||||
*/
|
||||
LvmDevice::LvmDevice(const QString& name, const QString& iconname)
|
||||
: VolumeManagerDevice(name,
|
||||
(QStringLiteral("/dev/") + name),
|
||||
getPeSize(name),
|
||||
getTotalPE(name),
|
||||
iconname,
|
||||
LvmDevice::LvmDevice(const QString& vgName, const QString& iconName)
|
||||
: VolumeManagerDevice(vgName,
|
||||
(QStringLiteral("/dev/") + vgName),
|
||||
getPeSize(vgName),
|
||||
getTotalPE(vgName),
|
||||
iconName,
|
||||
Device::LVM_Device)
|
||||
{
|
||||
m_peSize = logicalSize();
|
||||
m_totalPE = totalLogical();
|
||||
m_freePE = getFreePE(name);
|
||||
m_freePE = getFreePE(vgName);
|
||||
m_allocPE = m_totalPE - m_freePE;
|
||||
m_UUID = getUUID(name);
|
||||
m_PVPathList = new QStringList(getPVs(name));
|
||||
m_LVPathList = new QStringList(getLVs(name));
|
||||
m_UUID = getUUID(vgName);
|
||||
m_PVPathList = new QStringList(getPVs(vgName));
|
||||
m_LVPathList = new QStringList(getLVs(vgName));
|
||||
m_LVSizeMap = new QMap<QString, qint64>();
|
||||
|
||||
initPartitions();
|
||||
|
@ -96,11 +96,11 @@ const QList<Partition*> LvmDevice::scanPartitions(PartitionTable* pTable) const
|
|||
}
|
||||
|
||||
/**
|
||||
* @param lvpath
|
||||
* @param pTable
|
||||
* @param lvPath LVM Logical Volume path
|
||||
* @param pTable Abstract partition table representing partitions of LVM Volume Group
|
||||
* @return sorted Partition (LV) Array
|
||||
*/
|
||||
Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTable) const
|
||||
Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTable) const
|
||||
{
|
||||
/*
|
||||
* NOTE:
|
||||
|
@ -112,14 +112,14 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTabl
|
|||
* without too many special cases.
|
||||
*/
|
||||
|
||||
qint64 lvSize = getTotalLE(lvpath);
|
||||
qint64 startSector = mappedSector(lvpath, 0);
|
||||
qint64 lvSize = getTotalLE(lvPath);
|
||||
qint64 startSector = mappedSector(lvPath, 0);
|
||||
qint64 endSector = startSector + lvSize - 1;
|
||||
|
||||
FileSystem::Type type = FileSystem::detectFileSystem(lvpath);
|
||||
FileSystem::Type type = FileSystem::detectFileSystem(lvPath);
|
||||
FileSystem* fs = FileSystemFactory::create(type, 0, lvSize - 1);
|
||||
|
||||
bool mounted = isMounted(lvpath);
|
||||
bool mounted = isMounted(lvPath);
|
||||
QString mountPoint = QString();
|
||||
|
||||
KMountPoint::List mountPointList = KMountPoint::currentMountPoints(KMountPoint::NeedRealDeviceName);
|
||||
|
@ -130,13 +130,13 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTabl
|
|||
if (type == FileSystem::Luks) {
|
||||
r |= PartitionRole::Luks;
|
||||
FS::luks* luksFs = static_cast<FS::luks*>(fs);
|
||||
QString mapperNode = FS::luks::mapperName(lvpath);
|
||||
QString mapperNode = FS::luks::mapperName(lvPath);
|
||||
bool isCryptOpen = !mapperNode.isEmpty();
|
||||
luksFs->setCryptOpen(isCryptOpen);
|
||||
luksFs->setLogicalSectorSize(logicalSize());
|
||||
|
||||
if (isCryptOpen) {
|
||||
luksFs->loadInnerFileSystem(lvpath, mapperNode);
|
||||
luksFs->loadInnerFileSystem(lvPath, mapperNode);
|
||||
mountPoint = mountPointList.findByDevice(mapperNode) ?
|
||||
mountPointList.findByDevice(mapperNode)->mountPoint() :
|
||||
QString();
|
||||
|
@ -144,15 +144,15 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTabl
|
|||
if (mounted) {
|
||||
const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint);
|
||||
if (freeSpaceInfo.isValid() && mountPoint != QString())
|
||||
luksFs->setSectorsUsed((freeSpaceInfo.used() + luksFs->getPayloadOffset(lvpath)) / logicalSize());
|
||||
luksFs->setSectorsUsed((freeSpaceInfo.used() + luksFs->getPayloadOffset(lvPath)) / logicalSize());
|
||||
}
|
||||
} else {
|
||||
mounted = false;
|
||||
}
|
||||
luksFs->setMounted(mounted);
|
||||
} else {
|
||||
mountPoint = mountPointList.findByDevice(lvpath) ?
|
||||
mountPointList.findByDevice(lvpath)->mountPoint() :
|
||||
mountPoint = mountPointList.findByDevice(lvPath) ?
|
||||
mountPointList.findByDevice(lvPath)->mountPoint() :
|
||||
QString();
|
||||
const KDiskFreeSpaceInfo freeSpaceInfo = KDiskFreeSpaceInfo::freeSpaceInfo(mountPoint);
|
||||
|
||||
|
@ -161,16 +161,16 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTabl
|
|||
if (mounted && freeSpaceInfo.isValid() && mountPoint != QString()) {
|
||||
fs->setSectorsUsed(freeSpaceInfo.used() / logicalSize());
|
||||
} else if (fs->supportGetUsed() == FileSystem::cmdSupportFileSystem) {
|
||||
fs->setSectorsUsed(fs->readUsedCapacity(lvpath) / logicalSize());
|
||||
fs->setSectorsUsed(fs->readUsedCapacity(lvPath) / logicalSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fs->supportGetLabel() != FileSystem::cmdSupportNone) {
|
||||
fs->setLabel(fs->readLabel(lvpath));
|
||||
fs->setLabel(fs->readLabel(lvPath));
|
||||
}
|
||||
if (fs->supportGetUUID() != FileSystem::cmdSupportNone)
|
||||
fs->setUUID(fs->readUUID(lvpath));
|
||||
fs->setUUID(fs->readUUID(lvPath));
|
||||
|
||||
Partition* part = new Partition(pTable,
|
||||
*this,
|
||||
|
@ -178,7 +178,7 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTabl
|
|||
fs,
|
||||
startSector,
|
||||
endSector,
|
||||
lvpath,
|
||||
lvPath,
|
||||
PartitionTable::Flag::FlagNone,
|
||||
mountPoint,
|
||||
mounted);
|
||||
|
@ -191,17 +191,17 @@ Partition* LvmDevice::scanPartition(const QString& lvpath, PartitionTable* pTabl
|
|||
QList<LvmDevice*> LvmDevice::scanSystemLVM()
|
||||
{
|
||||
QList<LvmDevice*> lvmList;
|
||||
for (const auto &vgname : getVGs()) {
|
||||
lvmList.append(new LvmDevice(vgname));
|
||||
for (const auto &vgName : getVGs()) {
|
||||
lvmList.append(new LvmDevice(vgName));
|
||||
}
|
||||
return lvmList;
|
||||
}
|
||||
|
||||
qint64 LvmDevice::mappedSector(const QString& lvpath, qint64 sector) const
|
||||
qint64 LvmDevice::mappedSector(const QString& lvPath, qint64 sector) const
|
||||
{
|
||||
qint64 mSector = 0;
|
||||
QList<QString> lvpathList = partitionNodes();
|
||||
qint32 devIndex = lvpathList.indexOf(lvpath);
|
||||
qint32 devIndex = lvpathList.indexOf(lvPath);
|
||||
|
||||
if (devIndex) {
|
||||
for (int i = 0; i < devIndex; i++) {
|
||||
|
@ -232,18 +232,18 @@ const QStringList LvmDevice::getVGs()
|
|||
QStringList vgList;
|
||||
QString output = getField(QStringLiteral("vg_name"));
|
||||
if (!output.isEmpty()) {
|
||||
const QStringList vgnameList = output.split(QStringLiteral("\n"), QString::SkipEmptyParts);
|
||||
for (const auto &vgname : vgnameList) {
|
||||
vgList.append(vgname.trimmed());
|
||||
const QStringList vgNameList = output.split(QStringLiteral("\n"), QString::SkipEmptyParts);
|
||||
for (const auto &vgName : vgNameList) {
|
||||
vgList.append(vgName.trimmed());
|
||||
}
|
||||
}
|
||||
return vgList;
|
||||
}
|
||||
|
||||
const QStringList LvmDevice::getPVs(const QString& vgname)
|
||||
const QStringList LvmDevice::getPVs(const QString& vgName)
|
||||
{
|
||||
QStringList devPathList;
|
||||
QString cmdOutput = getField(QStringLiteral("pv_name"), vgname);
|
||||
QString cmdOutput = getField(QStringLiteral("pv_name"), vgName);
|
||||
|
||||
if (cmdOutput.size()) {
|
||||
const QStringList tempPathList = cmdOutput.split(QStringLiteral("\n"), QString::SkipEmptyParts);
|
||||
|
@ -254,10 +254,10 @@ const QStringList LvmDevice::getPVs(const QString& vgname)
|
|||
return devPathList;
|
||||
}
|
||||
|
||||
const QStringList LvmDevice::getLVs(const QString& vgname)
|
||||
const QStringList LvmDevice::getLVs(const QString& vgName)
|
||||
{
|
||||
QStringList lvPathList;
|
||||
QString cmdOutput = getField(QStringLiteral("lv_path"), vgname);
|
||||
QString cmdOutput = getField(QStringLiteral("lv_path"), vgName);
|
||||
|
||||
if (cmdOutput.size()) {
|
||||
const QStringList tempPathList = cmdOutput.split(QStringLiteral("\n"), QString::SkipEmptyParts);
|
||||
|
@ -268,32 +268,32 @@ const QStringList LvmDevice::getLVs(const QString& vgname)
|
|||
return lvPathList;
|
||||
}
|
||||
|
||||
qint64 LvmDevice::getPeSize(const QString& vgname)
|
||||
qint64 LvmDevice::getPeSize(const QString& vgName)
|
||||
{
|
||||
QString val = getField(QStringLiteral("vg_extent_size"), vgname);
|
||||
QString val = getField(QStringLiteral("vg_extent_size"), vgName);
|
||||
return val.isEmpty() ? -1 : val.toInt();
|
||||
}
|
||||
|
||||
qint64 LvmDevice::getTotalPE(const QString& vgname)
|
||||
qint64 LvmDevice::getTotalPE(const QString& vgName)
|
||||
{
|
||||
QString val = getField(QStringLiteral("vg_extent_count"), vgname);
|
||||
QString val = getField(QStringLiteral("vg_extent_count"), vgName);
|
||||
return val.isEmpty() ? -1 : val.toInt();
|
||||
}
|
||||
|
||||
qint64 LvmDevice::getAllocatedPE(const QString& vgname)
|
||||
qint64 LvmDevice::getAllocatedPE(const QString& vgName)
|
||||
{
|
||||
return getTotalPE(vgname) - getFreePE(vgname);
|
||||
return getTotalPE(vgName) - getFreePE(vgName);
|
||||
}
|
||||
|
||||
qint64 LvmDevice::getFreePE(const QString& vgname)
|
||||
qint64 LvmDevice::getFreePE(const QString& vgName)
|
||||
{
|
||||
QString val = getField(QStringLiteral("vg_free_count"), vgname);
|
||||
QString val = getField(QStringLiteral("vg_free_count"), vgName);
|
||||
return val.isEmpty() ? -1 : val.toInt();
|
||||
}
|
||||
|
||||
QString LvmDevice::getUUID(const QString& vgname)
|
||||
QString LvmDevice::getUUID(const QString& vgName)
|
||||
{
|
||||
QString val = getField(QStringLiteral("vg_uuid"), vgname);
|
||||
QString val = getField(QStringLiteral("vg_uuid"), vgName);
|
||||
return val.isEmpty() ? QStringLiteral("---") : val;
|
||||
|
||||
}
|
||||
|
@ -301,11 +301,11 @@ QString LvmDevice::getUUID(const QString& vgname)
|
|||
/** Get LVM vgs command output with field name
|
||||
*
|
||||
* @param fieldName LVM field name
|
||||
* @param vgname the name of LVM Volume Group
|
||||
* @param vgName the name of LVM Volume Group
|
||||
* @return raw output of command output, usully with many spaces within the returned string
|
||||
* */
|
||||
|
||||
QString LvmDevice::getField(const QString& fieldName, const QString& vgname)
|
||||
QString LvmDevice::getField(const QString& fieldName, const QString& vgName)
|
||||
{
|
||||
QStringList args = { QStringLiteral("vgs"),
|
||||
QStringLiteral("--foreign"),
|
||||
|
@ -316,8 +316,8 @@ QString LvmDevice::getField(const QString& fieldName, const QString& vgname)
|
|||
QStringLiteral("--nosuffix"),
|
||||
QStringLiteral("--options"),
|
||||
fieldName };
|
||||
if (!vgname.isEmpty()) {
|
||||
args << vgname;
|
||||
if (!vgName.isEmpty()) {
|
||||
args << vgName;
|
||||
}
|
||||
ExternalCommand cmd(QStringLiteral("lvm"), args);
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
|
@ -326,11 +326,11 @@ QString LvmDevice::getField(const QString& fieldName, const QString& vgname)
|
|||
return QString();
|
||||
}
|
||||
|
||||
qint64 LvmDevice::getTotalLE(const QString& lvpath)
|
||||
qint64 LvmDevice::getTotalLE(const QString& lvPath)
|
||||
{
|
||||
ExternalCommand cmd(QStringLiteral("lvm"),
|
||||
{ QStringLiteral("lvdisplay"),
|
||||
lvpath});
|
||||
lvPath});
|
||||
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
QRegularExpression re(QStringLiteral("Current LE\\h+(\\d+)"));
|
||||
|
@ -342,39 +342,39 @@ qint64 LvmDevice::getTotalLE(const QString& lvpath)
|
|||
return -1;
|
||||
}
|
||||
|
||||
bool LvmDevice::removeLV(Report& report, LvmDevice& dev, Partition& part)
|
||||
bool LvmDevice::removeLV(Report& report, LvmDevice& d, Partition& p)
|
||||
{
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("lvremove"),
|
||||
QStringLiteral("--yes"),
|
||||
part.partitionPath()});
|
||||
p.partitionPath()});
|
||||
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
//TODO: remove Partition from PartitionTable and delete from memory ??
|
||||
dev.partitionTable()->remove(&part);
|
||||
d.partitionTable()->remove(&p);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LvmDevice::createLV(Report& report, LvmDevice& dev, Partition& part, const QString& lvname)
|
||||
bool LvmDevice::createLV(Report& report, LvmDevice& d, Partition& p, const QString& lvName)
|
||||
{
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("lvcreate"),
|
||||
QStringLiteral("--yes"),
|
||||
QStringLiteral("--extents"),
|
||||
QString::number(part.length()),
|
||||
QString::number(p.length()),
|
||||
QStringLiteral("--name"),
|
||||
lvname,
|
||||
dev.name()});
|
||||
lvName,
|
||||
d.name()});
|
||||
|
||||
return (cmd.run(-1) && cmd.exitCode() == 0);
|
||||
}
|
||||
|
||||
bool LvmDevice::createLVSnapshot(Report& report, Partition& lvpart, const QString& name, const qint64 extents)
|
||||
bool LvmDevice::createLVSnapshot(Report& report, Partition& p, const QString& name, const qint64 extents)
|
||||
{
|
||||
QString numExtents = (extents > 0) ? QString::number(extents) :
|
||||
QString::number(lvpart.length());
|
||||
QString::number(p.length());
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("lvcreate"),
|
||||
QStringLiteral("--yes"),
|
||||
|
@ -383,11 +383,11 @@ bool LvmDevice::createLVSnapshot(Report& report, Partition& lvpart, const QStrin
|
|||
QStringLiteral("--snapshot"),
|
||||
QStringLiteral("--name"),
|
||||
name,
|
||||
lvpart.partitionPath() });
|
||||
p.partitionPath() });
|
||||
return (cmd.run(-1) && cmd.exitCode() == 0);
|
||||
}
|
||||
|
||||
bool LvmDevice::resizeLV(Report& report, Partition& part)
|
||||
bool LvmDevice::resizeLV(Report& report, Partition& p)
|
||||
{
|
||||
//TODO: thorough tests and add warning that it could currupt the user data.
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"),
|
||||
|
@ -395,29 +395,29 @@ bool LvmDevice::resizeLV(Report& report, Partition& part)
|
|||
QStringLiteral("--force"), // this command could corrupt user data
|
||||
QStringLiteral("--yes"),
|
||||
QStringLiteral("--extents"),
|
||||
QString::number(part.length()),
|
||||
part.partitionPath()});
|
||||
QString::number(p.length()),
|
||||
p.partitionPath()});
|
||||
|
||||
return (cmd.run(-1) && cmd.exitCode() == 0);
|
||||
}
|
||||
|
||||
bool LvmDevice::removePV(Report& report, LvmDevice& dev, const QString& pvPath)
|
||||
bool LvmDevice::removePV(Report& report, LvmDevice& d, const QString& pvPath)
|
||||
{
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgreduce"),
|
||||
//QStringLiteral("--yes"), // potentially corrupt user data
|
||||
dev.name(),
|
||||
d.name(),
|
||||
pvPath});
|
||||
|
||||
return (cmd.run(-1) && cmd.exitCode() == 0);
|
||||
}
|
||||
|
||||
bool LvmDevice::insertPV(Report& report, LvmDevice& dev, const QString& pvPath)
|
||||
bool LvmDevice::insertPV(Report& report, LvmDevice& d, const QString& pvPath)
|
||||
{
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgextend"),
|
||||
//QStringLiteral("--yes"), // potentially corrupt user data
|
||||
dev.name(),
|
||||
d.name(),
|
||||
pvPath});
|
||||
|
||||
return (cmd.run(-1) && cmd.exitCode() == 0);
|
||||
|
@ -442,60 +442,60 @@ bool LvmDevice::movePV(Report& report, const QString& pvPath, const QStringList&
|
|||
return (cmd.run(-1) && cmd.exitCode() == 0);
|
||||
}
|
||||
|
||||
bool LvmDevice::createVG(Report& report, const QString vgname, const QStringList pvlist, const qint32 peSize)
|
||||
bool LvmDevice::createVG(Report& report, const QString vgName, const QStringList pvList, const qint32 peSize)
|
||||
{
|
||||
QStringList args = QStringList();
|
||||
args << QStringLiteral("vgcreate") << QStringLiteral("--physicalextentsize") << QString::number(peSize);
|
||||
args << vgname;
|
||||
for (const auto &pvnode : pvlist) {
|
||||
args << pvnode.trimmed();
|
||||
args << vgName;
|
||||
for (const auto &pvNode : pvList) {
|
||||
args << pvNode.trimmed();
|
||||
}
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"), args);
|
||||
|
||||
return (cmd.run(-1) && cmd.exitCode() == 0);
|
||||
}
|
||||
|
||||
bool LvmDevice::removeVG(Report& report, LvmDevice& dev)
|
||||
bool LvmDevice::removeVG(Report& report, LvmDevice& d)
|
||||
{
|
||||
bool deactivated = deactivateVG(report, dev);
|
||||
bool deactivated = deactivateVG(report, d);
|
||||
ExternalCommand cmd(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgremove"),
|
||||
dev.name() });
|
||||
d.name() });
|
||||
return (deactivated && cmd.run(-1) && cmd.exitCode() == 0);
|
||||
}
|
||||
|
||||
bool LvmDevice::deactivateVG(Report& report, const LvmDevice& dev)
|
||||
bool LvmDevice::deactivateVG(Report& report, const LvmDevice& d)
|
||||
{
|
||||
ExternalCommand deactivate(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgchange"),
|
||||
QStringLiteral("--activate"), QStringLiteral("n"),
|
||||
dev.name() });
|
||||
d.name() });
|
||||
return deactivate.run(-1) && deactivate.exitCode() == 0;
|
||||
}
|
||||
|
||||
bool LvmDevice::deactivateLV(Report& report, const Partition& part)
|
||||
bool LvmDevice::deactivateLV(Report& report, const Partition& p)
|
||||
{
|
||||
ExternalCommand deactivate(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("lvchange"),
|
||||
QStringLiteral("--activate"), QStringLiteral("n"),
|
||||
part.partitionPath() });
|
||||
p.partitionPath() });
|
||||
return deactivate.run(-1) && deactivate.exitCode() == 0;
|
||||
}
|
||||
|
||||
bool LvmDevice::activateVG(Report& report, const LvmDevice& dev)
|
||||
bool LvmDevice::activateVG(Report& report, const LvmDevice& d)
|
||||
{
|
||||
ExternalCommand deactivate(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgchange"),
|
||||
QStringLiteral("--activate"), QStringLiteral("y"),
|
||||
dev.name() });
|
||||
d.name() });
|
||||
return deactivate.run(-1) && deactivate.exitCode() == 0;
|
||||
}
|
||||
|
||||
bool LvmDevice::activateLV(Report& report, Partition& part)
|
||||
bool LvmDevice::activateLV(Report& report, Partition& p)
|
||||
{
|
||||
ExternalCommand deactivate(report, QStringLiteral("lvm"),
|
||||
{ QStringLiteral("lvchange"),
|
||||
QStringLiteral("--activate"), QStringLiteral("y"),
|
||||
part.partitionPath() });
|
||||
p.partitionPath() });
|
||||
return deactivate.run(-1) && deactivate.exitCode() == 0;
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class LIBKPMCORE_EXPORT LvmDevice : public VolumeManagerDevice
|
|||
Q_DISABLE_COPY(LvmDevice)
|
||||
|
||||
public:
|
||||
LvmDevice(const QString& name, const QString& iconname = QString());
|
||||
LvmDevice(const QString& name, const QString& iconName = QString());
|
||||
~LvmDevice();
|
||||
|
||||
public:
|
||||
|
@ -62,33 +62,33 @@ public:
|
|||
static QList<LvmDevice*> scanSystemLVM();
|
||||
|
||||
static const QStringList getVGs();
|
||||
static const QStringList getPVs(const QString& vgname);
|
||||
static const QStringList getLVs(const QString& vgname);
|
||||
static const QStringList getPVs(const QString& vgName);
|
||||
static const QStringList getLVs(const QString& vgName);
|
||||
|
||||
static qint64 getPeSize(const QString& vgname);
|
||||
static qint64 getTotalPE(const QString& vgname);
|
||||
static qint64 getAllocatedPE(const QString& vgname);
|
||||
static qint64 getFreePE(const QString& vgname);
|
||||
static QString getUUID(const QString& vgname);
|
||||
static QString getField(const QString& fieldName, const QString& vgname = QString());
|
||||
static qint64 getPeSize(const QString& vgName);
|
||||
static qint64 getTotalPE(const QString& vgName);
|
||||
static qint64 getAllocatedPE(const QString& vgName);
|
||||
static qint64 getFreePE(const QString& vgName);
|
||||
static QString getUUID(const QString& vgName);
|
||||
static QString getField(const QString& fieldName, const QString& vgName = QString());
|
||||
|
||||
static qint64 getTotalLE(const QString& lvpath);
|
||||
static qint64 getTotalLE(const QString& lvPath);
|
||||
|
||||
static bool removeLV(Report& report, LvmDevice& dev, Partition& part);
|
||||
static bool createLV(Report& report, LvmDevice& dev, Partition& part, const QString& lvname);
|
||||
static bool createLVSnapshot(Report& report, Partition& lvpart, const QString& name, const qint64 extents = 0);
|
||||
static bool resizeLV(Report& report, Partition& part);
|
||||
static bool deactivateLV(Report& report, const Partition& part);
|
||||
static bool activateLV(Report& report, Partition& part);
|
||||
static bool removeLV(Report& report, LvmDevice& d, Partition& p);
|
||||
static bool createLV(Report& report, LvmDevice& d, Partition& p, const QString& lvName);
|
||||
static bool createLVSnapshot(Report& report, Partition& p, const QString& name, const qint64 extents = 0);
|
||||
static bool resizeLV(Report& report, Partition& p);
|
||||
static bool deactivateLV(Report& report, const Partition& p);
|
||||
static bool activateLV(Report& report, Partition& p);
|
||||
|
||||
static bool removePV(Report& report, LvmDevice& dev, const QString& pvPath);
|
||||
static bool insertPV(Report& report, LvmDevice& dev, const QString& pvPath);
|
||||
static bool removePV(Report& report, LvmDevice& d, const QString& pvPath);
|
||||
static bool insertPV(Report& report, LvmDevice& d, const QString& pvPath);
|
||||
static bool movePV(Report& report, const QString& pvPath, const QStringList& destinations = QStringList());
|
||||
|
||||
static bool removeVG(Report& report, LvmDevice& dev);
|
||||
static bool createVG(Report& report, const QString vgname, const QStringList pvlist, const qint32 peSize = 4); // peSize in megabytes
|
||||
static bool deactivateVG(Report& report, const LvmDevice& dev);
|
||||
static bool activateVG(Report& report, const LvmDevice& dev);
|
||||
static bool removeVG(Report& report, LvmDevice& d);
|
||||
static bool createVG(Report& report, const QString vgName, const QStringList pvList, const qint32 peSize = 4); // peSize in megabytes
|
||||
static bool deactivateVG(Report& report, const LvmDevice& d);
|
||||
static bool activateVG(Report& report, const LvmDevice& d);
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -103,7 +103,7 @@ protected:
|
|||
*
|
||||
*/
|
||||
Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const;
|
||||
qint64 mappedSector(const QString& lvpath, qint64 sector) const override;
|
||||
qint64 mappedSector(const QString& lvPath, qint64 sector) const override;
|
||||
|
||||
public:
|
||||
qint64 peSize() const {
|
||||
|
|
|
@ -39,13 +39,13 @@
|
|||
/** Creates a new PartitionTable object with type MSDOS
|
||||
@param type name of the PartitionTable type (e.g. "msdos" or "gpt")
|
||||
*/
|
||||
PartitionTable::PartitionTable(TableType type, qint64 first_usable, qint64 last_usable) :
|
||||
PartitionTable::PartitionTable(TableType type, qint64 firstUsable, qint64 lastUsable) :
|
||||
PartitionNode(),
|
||||
m_Children(),
|
||||
m_MaxPrimaries(maxPrimariesForTableType(type)),
|
||||
m_Type(type),
|
||||
m_FirstUsable(first_usable),
|
||||
m_LastUsable(last_usable)
|
||||
m_FirstUsable(firstUsable),
|
||||
m_LastUsable(lastUsable)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ public:
|
|||
Q_FLAG(Flag)
|
||||
|
||||
public:
|
||||
PartitionTable(TableType type, qint64 first_usable, qint64 last_usable);
|
||||
PartitionTable(TableType type, qint64 firstUsable, qint64 lastUsable);
|
||||
~PartitionTable();
|
||||
|
||||
public:
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
/** Constructs a Volume Manager Device with an empty PartitionTable.
|
||||
*/
|
||||
VolumeManagerDevice::VolumeManagerDevice(const QString& name,
|
||||
const QString& devicenode,
|
||||
const QString& deviceNode,
|
||||
const qint32 logicalSize,
|
||||
const qint64 totalLogical,
|
||||
const QString& iconname,
|
||||
const QString& iconName,
|
||||
Device::Type type)
|
||||
: Device(name, devicenode, logicalSize, totalLogical, iconname, type)
|
||||
: Device(name, deviceNode, logicalSize, totalLogical, iconName, type)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
/**
|
||||
*
|
||||
*/
|
||||
VolumeManagerDevice(const QString& name, const QString& devicenode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconname = QString(), Device::Type type = Device::Unknown_Device);
|
||||
VolumeManagerDevice(const QString& name, const QString& deviceNode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconName = QString(), Device::Type type = Device::Unknown_Device);
|
||||
|
||||
/**
|
||||
* @return list of physical device or partitions that makes up volumeManagerDevice.
|
||||
|
|
|
@ -24,14 +24,15 @@
|
|||
#include <KLocalizedString>
|
||||
|
||||
/** Creates a new CreateVolumeGroupJob
|
||||
@param vgname LVM Volume Group name
|
||||
@param pvlist List of LVM Physical Volumes
|
||||
* @param vgName LVM Volume Group name
|
||||
* @param pvList List of LVM Physical Volumes used to create Volume Group
|
||||
* @param peSize LVM Physical Extent size in MiB
|
||||
*/
|
||||
CreateVolumeGroupJob::CreateVolumeGroupJob(const QString& vgname, const QStringList& pvlist, const qint32 pesize) :
|
||||
CreateVolumeGroupJob::CreateVolumeGroupJob(const QString& vgName, const QStringList& pvList, const qint32 peSize) :
|
||||
Job(),
|
||||
m_vgName(vgname),
|
||||
m_pvList(pvlist),
|
||||
m_PESize(pesize)
|
||||
m_vgName(vgName),
|
||||
m_pvList(pvList),
|
||||
m_PESize(peSize)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class QString;
|
|||
class CreateVolumeGroupJob : public Job
|
||||
{
|
||||
public:
|
||||
CreateVolumeGroupJob(const QString& vgname, const QStringList& pvlist, const qint32 pesize);
|
||||
CreateVolumeGroupJob(const QString& vgName, const QStringList& pvList, const qint32 peSize);
|
||||
|
||||
public:
|
||||
bool run(Report& parent) override;
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
|
||||
/** Creates a new DeactivateLogicalVolumeJob
|
||||
*/
|
||||
DeactivateLogicalVolumeJob::DeactivateLogicalVolumeJob(const VolumeManagerDevice& dev, const QStringList lvPaths) :
|
||||
DeactivateLogicalVolumeJob::DeactivateLogicalVolumeJob(const VolumeManagerDevice& d, const QStringList lvPaths) :
|
||||
Job(),
|
||||
m_Device(dev),
|
||||
m_Device(d),
|
||||
m_LVList(lvPaths)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
|
||||
/** Deactivate LVM Volume Group
|
||||
*/
|
||||
DeactivateVolumeGroupJob::DeactivateVolumeGroupJob(VolumeManagerDevice& dev) :
|
||||
DeactivateVolumeGroupJob::DeactivateVolumeGroupJob(VolumeManagerDevice& d) :
|
||||
Job(),
|
||||
m_Device(dev)
|
||||
m_Device(d)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,12 @@
|
|||
#include <KLocalizedString>
|
||||
|
||||
/** Creates a new MovePhysicalVolumeJob
|
||||
* @param d Device representing LVM Volume Group
|
||||
*/
|
||||
MovePhysicalVolumeJob::MovePhysicalVolumeJob(LvmDevice& dev, const QStringList partlist) :
|
||||
MovePhysicalVolumeJob::MovePhysicalVolumeJob(LvmDevice& d, const QStringList partList) :
|
||||
Job(),
|
||||
m_Device(dev),
|
||||
m_PartList(partlist)
|
||||
m_Device(d),
|
||||
m_PartList(partList)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
|
||||
/** Creates a new RemoveVolumeGroupJob
|
||||
*/
|
||||
RemoveVolumeGroupJob::RemoveVolumeGroupJob(VolumeManagerDevice& dev) :
|
||||
RemoveVolumeGroupJob::RemoveVolumeGroupJob(VolumeManagerDevice& d) :
|
||||
Job(),
|
||||
m_Device(dev)
|
||||
m_Device(d)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -27,11 +27,14 @@
|
|||
#include <KLocalizedString>
|
||||
|
||||
/** Creates a new CreateVolumeGroupOperation.
|
||||
* @param vgName LVM Volume Group name
|
||||
* @param pvList List of LVM Physical Volumes used to create Volume Group
|
||||
* @param peSize LVM Physical Extent size in MiB
|
||||
*/
|
||||
CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgname, const QStringList& pvlist, const qint32 pesize) :
|
||||
CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgName, const QStringList& pvList, const qint32 peSize) :
|
||||
Operation(),
|
||||
m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgname, pvlist, pesize)),
|
||||
m_PVList(pvlist)
|
||||
m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgName, pvList, peSize)),
|
||||
m_PVList(pvList)
|
||||
{
|
||||
addJob(createVolumeGroupJob());
|
||||
}
|
||||
|
@ -41,9 +44,8 @@ QString CreateVolumeGroupOperation::description() const
|
|||
return xi18nc("@info/plain", "Create a new LVM volume group.");
|
||||
}
|
||||
|
||||
bool CreateVolumeGroupOperation::targets(const Partition& part) const
|
||||
bool CreateVolumeGroupOperation::targets(const Partition&) const
|
||||
{
|
||||
Q_UNUSED(part)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -54,9 +56,9 @@ void CreateVolumeGroupOperation::preview()
|
|||
|
||||
void CreateVolumeGroupOperation::undo()
|
||||
{
|
||||
for (const auto &pvpath : PVList()) {
|
||||
if (LvmDevice::s_DirtyPVs.contains(pvpath)) {
|
||||
LvmDevice::s_DirtyPVs.removeAll(pvpath);
|
||||
for (const auto &pvPath : PVList()) {
|
||||
if (LvmDevice::s_DirtyPVs.contains(pvPath)) {
|
||||
LvmDevice::s_DirtyPVs.removeAll(pvPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class LIBKPMCORE_EXPORT CreateVolumeGroupOperation : public Operation
|
|||
friend class OperationStack;
|
||||
|
||||
public:
|
||||
CreateVolumeGroupOperation(const QString& vgname, const QStringList& pvlist, const qint32 pesize = 4);
|
||||
CreateVolumeGroupOperation(const QString& vgName, const QStringList& pvList, const qint32 peSize = 4);
|
||||
|
||||
public:
|
||||
QString iconName() const override {
|
||||
|
|
|
@ -28,11 +28,11 @@
|
|||
|
||||
/** Creates a new RemoveVolumeGroupOperation.
|
||||
*/
|
||||
DeactivateVolumeGroupOperation::DeactivateVolumeGroupOperation(VolumeManagerDevice& dev) :
|
||||
DeactivateVolumeGroupOperation::DeactivateVolumeGroupOperation(VolumeManagerDevice& d) :
|
||||
Operation(),
|
||||
m_DeactivateVolumeGroupJob(new DeactivateVolumeGroupJob(dev)),
|
||||
m_DeactivateLogicalVolumeJob(new DeactivateLogicalVolumeJob(dev)),
|
||||
m_Device(dev)
|
||||
m_DeactivateVolumeGroupJob(new DeactivateVolumeGroupJob(d)),
|
||||
m_DeactivateLogicalVolumeJob(new DeactivateLogicalVolumeJob(d)),
|
||||
m_Device(d)
|
||||
{
|
||||
addJob(deactivateLogicalVolumeJob());
|
||||
addJob(deactivateVolumeGroupJob());
|
||||
|
|
|
@ -38,7 +38,7 @@ class LIBKPMCORE_EXPORT DeactivateVolumeGroupOperation : public Operation
|
|||
friend class OperationStack;
|
||||
|
||||
public:
|
||||
DeactivateVolumeGroupOperation(VolumeManagerDevice& dev);
|
||||
DeactivateVolumeGroupOperation(VolumeManagerDevice& d);
|
||||
|
||||
public:
|
||||
QString iconName() const override {
|
||||
|
|
|
@ -26,10 +26,10 @@
|
|||
|
||||
/** Creates a new RemoveVolumeGroupOperation.
|
||||
*/
|
||||
RemoveVolumeGroupOperation::RemoveVolumeGroupOperation(VolumeManagerDevice& dev) :
|
||||
RemoveVolumeGroupOperation::RemoveVolumeGroupOperation(VolumeManagerDevice& d) :
|
||||
Operation(),
|
||||
m_RemoveVolumeGroupJob(new RemoveVolumeGroupJob(dev)),
|
||||
m_Device(dev)
|
||||
m_RemoveVolumeGroupJob(new RemoveVolumeGroupJob(d)),
|
||||
m_Device(d)
|
||||
{
|
||||
addJob(removeVolumeGroupJob());
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ class LIBKPMCORE_EXPORT RemoveVolumeGroupOperation : public Operation
|
|||
friend class OperationStack;
|
||||
|
||||
public:
|
||||
RemoveVolumeGroupOperation(VolumeManagerDevice& dev);
|
||||
RemoveVolumeGroupOperation(VolumeManagerDevice& d);
|
||||
|
||||
public:
|
||||
QString iconName() const override {
|
||||
|
|
|
@ -30,22 +30,22 @@
|
|||
|
||||
/** Creates a new ResizeVolumeGroupOperation.
|
||||
@param d the Device to create the new PartitionTable on
|
||||
@param t the type for the new PartitionTable
|
||||
@param partlist list of LVM Physical Volumes that should be in LVM Volume Group
|
||||
*/
|
||||
ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& dev, const QStringList partlist) :
|
||||
ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& d, const QStringList partlist) :
|
||||
Operation(),
|
||||
m_Device(dev),
|
||||
m_Device(d),
|
||||
m_TargetList(partlist),
|
||||
m_CurrentList(LvmDevice::getPVs(dev.name())),
|
||||
m_CurrentList(LvmDevice::getPVs(d.name())),
|
||||
m_GrowVolumeGroupJob(nullptr),
|
||||
m_ShrinkVolumeGroupJob(nullptr),
|
||||
m_MovePhysicalVolumeJob(nullptr)
|
||||
{
|
||||
const QStringList clist = currentList();
|
||||
const QStringList curList = currentList();
|
||||
m_TargetSize = FS::lvm2_pv::getPVSize(targetList());
|
||||
m_CurrentSize = FS::lvm2_pv::getPVSize(currentList());
|
||||
|
||||
QStringList toRemoveList = clist;
|
||||
QStringList toRemoveList = curList;
|
||||
for (QString path : partlist) {
|
||||
if (toRemoveList.contains(path)) {
|
||||
toRemoveList.removeAll(path);
|
||||
|
@ -53,28 +53,28 @@ ResizeVolumeGroupOperation::ResizeVolumeGroupOperation(LvmDevice& dev, const QSt
|
|||
}
|
||||
|
||||
QStringList toInsertList = partlist;
|
||||
for (QString path : clist) {
|
||||
for (QString path : curList) {
|
||||
if (toInsertList.contains(path)) {
|
||||
toInsertList.removeAll(path);
|
||||
}
|
||||
}
|
||||
|
||||
qint64 freePE = FS::lvm2_pv::getFreePE(clist) - FS::lvm2_pv::getFreePE(toRemoveList);
|
||||
qint64 freePE = FS::lvm2_pv::getFreePE(curList) - FS::lvm2_pv::getFreePE(toRemoveList);
|
||||
qint64 movePE = FS::lvm2_pv::getAllocatedPE(toRemoveList);
|
||||
qint64 growPE = FS::lvm2_pv::getPVSize(toInsertList) / LvmDevice::getPeSize(dev.name());
|
||||
qint64 growPE = FS::lvm2_pv::getPVSize(toInsertList) / LvmDevice::getPeSize(d.name());
|
||||
|
||||
if ( movePE > (freePE + growPE)) {
|
||||
// *ABORT* can't move
|
||||
} else if (partlist == clist) {
|
||||
} else if (partlist == curList) {
|
||||
// *DO NOTHING*
|
||||
} else {
|
||||
if (!toInsertList.isEmpty()) {
|
||||
m_GrowVolumeGroupJob = new ResizeVolumeGroupJob(dev, toInsertList, ResizeVolumeGroupJob::Grow);
|
||||
m_GrowVolumeGroupJob = new ResizeVolumeGroupJob(d, toInsertList, ResizeVolumeGroupJob::Grow);
|
||||
addJob(growVolumeGroupJob());
|
||||
}
|
||||
if (!toRemoveList.isEmpty()) {
|
||||
m_MovePhysicalVolumeJob = new MovePhysicalVolumeJob(dev, toRemoveList);
|
||||
m_ShrinkVolumeGroupJob = new ResizeVolumeGroupJob(dev, toRemoveList, ResizeVolumeGroupJob::Shrink);
|
||||
m_MovePhysicalVolumeJob = new MovePhysicalVolumeJob(d, toRemoveList);
|
||||
m_ShrinkVolumeGroupJob = new ResizeVolumeGroupJob(d, toRemoveList, ResizeVolumeGroupJob::Shrink);
|
||||
addJob(movePhysicalVolumeJob());
|
||||
addJob(shrinkvolumegroupjob());
|
||||
}
|
||||
|
@ -94,10 +94,10 @@ bool ResizeVolumeGroupOperation::targets(const Device& d) const
|
|||
return d == device();
|
||||
}
|
||||
|
||||
bool ResizeVolumeGroupOperation::targets(const Partition& part) const
|
||||
bool ResizeVolumeGroupOperation::targets(const Partition& p) const
|
||||
{
|
||||
for (QString partPath : targetList()) {
|
||||
if (partPath == part.partitionPath()) {
|
||||
if (partPath == p.partitionPath()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue