Initial work on LvmDevice
This commit is contained in:
parent
fcc8a7c992
commit
103b5343d6
|
@ -15,8 +15,10 @@ set(CORE_SRC
|
|||
core/devicescanner.cpp
|
||||
core/partitionnode.cpp
|
||||
core/partitionalignment.cpp
|
||||
core/diskdevice.cpp
|
||||
core/device.cpp
|
||||
core/diskdevice.cpp
|
||||
core/volumemanagerdevice.cpp
|
||||
core/lvmdevice.cpp
|
||||
core/operationstack.cpp
|
||||
core/partitionrole.cpp
|
||||
)
|
||||
|
@ -26,8 +28,10 @@ set(CORE_LIB_HDRS
|
|||
core/copysourcedevice.h
|
||||
core/copytarget.h
|
||||
core/copytargetdevice.h
|
||||
core/diskdevice.h
|
||||
core/device.h
|
||||
core/diskdevice.h
|
||||
core/volumemanagerdevice.h
|
||||
core/lvmdevice.h
|
||||
core/devicescanner.h
|
||||
core/mountentry.h
|
||||
core/operationrunner.h
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
|
||||
#include "core/operationstack.h"
|
||||
#include "core/device.h"
|
||||
#include "core/lvmdevice.h"
|
||||
#include "core/diskdevice.h"
|
||||
|
||||
#include "util/externalcommand.h"
|
||||
#include <QRegularExpression>
|
||||
#include <QDebug>
|
||||
|
||||
/** Constructs a DeviceScanner
|
||||
@param ostack the OperationStack where the devices will be created
|
||||
|
@ -57,10 +63,33 @@ void DeviceScanner::scan()
|
|||
clear();
|
||||
|
||||
QList<Device*> deviceList = CoreBackendManager::self()->backend()->scanDevices();
|
||||
//TODO: Scan for LVM here and add to the list.
|
||||
QList<LvmDevice*> lvmList = scanLvmDevices();
|
||||
|
||||
foreach(Device * d, deviceList)
|
||||
operationStack().addDevice(d);
|
||||
|
||||
foreach(Device * d, lvmList)
|
||||
operationStack().addDevice(d);
|
||||
|
||||
operationStack().sortDevices();
|
||||
}
|
||||
|
||||
/* Return list of VG (LvmDevice) on the system */
|
||||
QList<LvmDevice*> DeviceScanner::scanLvmDevices() const
|
||||
{
|
||||
QList<LvmDevice*> lvmList;
|
||||
|
||||
ExternalCommand scanLvm(QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgdisplay")});
|
||||
|
||||
if (scanLvm.run(-1) && scanLvm.exitCode() == 0) {
|
||||
QRegularExpression re(QStringLiteral("VG Name\\h+(\\w+)"));
|
||||
QRegularExpressionMatchIterator i = re.globalMatch(scanLvm.output());
|
||||
while(i.hasNext()) {
|
||||
QRegularExpressionMatch vgName = i.next();
|
||||
LvmDevice* temp = new LvmDevice(vgName.captured(1));
|
||||
lvmList.append(temp);
|
||||
}
|
||||
}
|
||||
return lvmList;
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QThread>
|
||||
|
||||
class OperationStack;
|
||||
class LvmDevice;
|
||||
|
||||
/** Thread to scan for all available Devices on this computer.
|
||||
|
||||
|
@ -54,6 +55,8 @@ protected:
|
|||
return m_OperationStack;
|
||||
}
|
||||
|
||||
QList<LvmDevice*> scanLvmDevices() const;
|
||||
|
||||
private:
|
||||
OperationStack& m_OperationStack;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#include "core/lvmdevice.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
#include "util/externalcommand.h"
|
||||
|
||||
#include <QRegularExpression>
|
||||
|
||||
/** Constructs a representation of LVM device with functionning LV as Partition
|
||||
@param name Volume Group name
|
||||
*/
|
||||
LvmDevice::LvmDevice(const QString& name, const QString& iconname)
|
||||
: VolumeManagerDevice(name,
|
||||
(QStringLiteral("/dev/") + name),
|
||||
getPeSize(name),
|
||||
getTotalPE(name),
|
||||
iconname,
|
||||
Device::LVM_Device)
|
||||
, m_peSize(getPeSize(name))
|
||||
, m_totalPE(getTotalPE(name))
|
||||
, m_allocPE(getAllocatedPE(name))
|
||||
, m_freePE(getFreePE(name))
|
||||
{
|
||||
//called to initialize member variables
|
||||
//refresh();
|
||||
initPartitions();
|
||||
}
|
||||
/*
|
||||
void LvmDevice::refresh() const
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
void LvmDevice::initPartitions() const
|
||||
{
|
||||
//PartitionTable* pTable = new PartitionTable(PartitionTable::TableType::vmd,0, )
|
||||
}
|
||||
|
||||
qint32 LvmDevice::getPeSize(const QString& vgname)
|
||||
{
|
||||
ExternalCommand cmd(QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgdisplay"),
|
||||
QStringLiteral("--units"),
|
||||
QStringLiteral("B"),
|
||||
vgname});
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
QRegularExpression re(QStringLiteral("PE Size\\h+(\\d+)"));
|
||||
QRegularExpressionMatch match = re.match(cmd.output());
|
||||
if (match.hasMatch()) {
|
||||
return match.captured(1).toInt();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
qint32 LvmDevice::getTotalPE(const QString& vgname)
|
||||
{
|
||||
ExternalCommand cmd(QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgdisplay"),
|
||||
QStringLiteral("--units"),
|
||||
QStringLiteral("B"),
|
||||
vgname});
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
QRegularExpression re(QStringLiteral("Total PE\\h+(\\d+)"));
|
||||
QRegularExpressionMatch match = re.match(cmd.output());
|
||||
if (match.hasMatch()) {
|
||||
return match.captured(1).toInt();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
qint32 LvmDevice::getAllocatedPE(const QString& vgname)
|
||||
{
|
||||
ExternalCommand cmd(QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgdisplay"),
|
||||
QStringLiteral("--units"),
|
||||
QStringLiteral("B"),
|
||||
vgname});
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
QRegularExpression re(QStringLiteral("Alloc PE.*\\h+(\\d+)"));
|
||||
QRegularExpressionMatch match = re.match(cmd.output());
|
||||
if (match.hasMatch()) {
|
||||
return match.captured(1).toInt();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
qint32 LvmDevice::getFreePE(const QString& vgname)
|
||||
{
|
||||
ExternalCommand cmd(QStringLiteral("lvm"),
|
||||
{ QStringLiteral("vgdisplay"),
|
||||
QStringLiteral("--units"),
|
||||
QStringLiteral("B"),
|
||||
vgname});
|
||||
if (cmd.run(-1) && cmd.exitCode() == 0) {
|
||||
QRegularExpression re(QStringLiteral("Free PE.*\\h+(\\d+)"));
|
||||
QRegularExpressionMatch match = re.match(cmd.output());
|
||||
if (match.hasMatch()) {
|
||||
return match.captured(1).toInt();
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2016 by Chantara Tith <tith.chantara@gmail.com> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(LVMDEVICE__H)
|
||||
|
||||
#define LVMDEVICE__H
|
||||
|
||||
#include "core/volumemanagerdevice.h"
|
||||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QtGlobal>
|
||||
|
||||
class PartitionTable;
|
||||
class CreatePartitionTableOperation;
|
||||
class SmartStatus;
|
||||
|
||||
/** A device.
|
||||
|
||||
Represents a device like /dev/sda.
|
||||
|
||||
Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions.
|
||||
|
||||
@see PartitionTable, Partition
|
||||
@author Volker Lanz <vl@fidra.de>
|
||||
*/
|
||||
class LIBKPMCORE_EXPORT LvmDevice : public VolumeManagerDevice
|
||||
{
|
||||
Q_DISABLE_COPY(LvmDevice)
|
||||
|
||||
public:
|
||||
LvmDevice(const QString& name, const QString& iconname = QString());
|
||||
// void refresh() const override;
|
||||
|
||||
public:
|
||||
qint32 peSize() const {
|
||||
return m_peSize;
|
||||
}
|
||||
qint32 totalPE() const {
|
||||
return m_totalPE;
|
||||
}
|
||||
qint32 allocatedPE() const {
|
||||
return m_allocPE;
|
||||
}
|
||||
qint32 freePE() const {
|
||||
return m_freePE;
|
||||
}
|
||||
|
||||
public:
|
||||
static qint32 getPeSize(const QString& name);
|
||||
static qint32 getTotalPE(const QString& name);
|
||||
static qint32 getAllocatedPE(const QString& name);
|
||||
static qint32 getFreePE(const QString& name);
|
||||
protected:
|
||||
// void init() const;
|
||||
void initPartitions() const;
|
||||
|
||||
|
||||
private:
|
||||
qint32 m_peSize;
|
||||
qint32 m_totalPE;
|
||||
qint32 m_allocPE;
|
||||
qint32 m_freePE;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#include "core/volumemanagerdevice.h"
|
||||
|
||||
#include "core/partitiontable.h"
|
||||
#include "core/smartstatus.h"
|
||||
|
||||
#include "util/capacity.h"
|
||||
|
||||
/** Constructs a Device with an empty PartitionTable.
|
||||
*/
|
||||
VolumeManagerDevice::VolumeManagerDevice(const QString& name,
|
||||
const QString& devicenode,
|
||||
const qint32 logicalSize,
|
||||
const qint64 totalLogical,
|
||||
const QString& iconname,
|
||||
Device::Type type)
|
||||
: Device(name, devicenode, logicalSize, totalLogical, iconname, type)
|
||||
{
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*************************************************************************
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 3 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
||||
*************************************************************************/
|
||||
|
||||
#if !defined(VOLUMEMANAGERDEVICE__H)
|
||||
|
||||
#define VOLUMEMANAGERDEVICE__H
|
||||
|
||||
#include "util/libpartitionmanagerexport.h"
|
||||
#include "core/device.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QtGlobal>
|
||||
|
||||
class PartitionTable;
|
||||
class CreatePartitionTableOperation;
|
||||
class CoreBackend;
|
||||
class SmartStatus;
|
||||
class Partition;
|
||||
|
||||
/** A device.
|
||||
|
||||
Represents a device like /dev/sda.
|
||||
|
||||
Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions.
|
||||
|
||||
@see PartitionTable, Partition
|
||||
@author Volker Lanz <vl@fidra.de>
|
||||
*/
|
||||
class LIBKPMCORE_EXPORT VolumeManagerDevice : public Device
|
||||
{
|
||||
Q_DISABLE_COPY(VolumeManagerDevice)
|
||||
|
||||
protected:
|
||||
VolumeManagerDevice(const QString& name, const QString& devicenode, const qint32 logicalSize, const qint64 totalLogical, const QString& iconname = QString(), Device::Type type = Device::Unknown_Device);
|
||||
|
||||
public:
|
||||
//virtual void refresh() const = 0; /* VG infos can be changed, unlike disk_device */
|
||||
//virtual Qlist<Partition*> listDevices() const = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue