2016-06-08 16:50:40 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* 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
|
|
|
|
|
2016-09-08 01:42:04 +01:00
|
|
|
#include "core/device.h"
|
2016-06-08 16:50:40 +01:00
|
|
|
#include "core/volumemanagerdevice.h"
|
|
|
|
#include "util/libpartitionmanagerexport.h"
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QtGlobal>
|
2016-08-07 21:30:47 +01:00
|
|
|
#include <QStringList>
|
2016-06-08 16:50:40 +01:00
|
|
|
|
|
|
|
class PartitionTable;
|
2016-08-11 22:27:58 +01:00
|
|
|
class Report;
|
|
|
|
class Partition;
|
2016-06-08 16:50:40 +01:00
|
|
|
class SmartStatus;
|
|
|
|
|
2016-08-15 07:18:40 +01:00
|
|
|
/** Representation of LVM Volume Group(VG).
|
2016-06-08 16:50:40 +01:00
|
|
|
|
|
|
|
Devices are the outermost entity; they contain a PartitionTable that itself contains Partitions.
|
|
|
|
|
2016-08-15 07:18:40 +01:00
|
|
|
@see Device, VolumeManagerDevice, PartitionTable, Partition
|
2016-06-08 16:50:40 +01:00
|
|
|
*/
|
|
|
|
class LIBKPMCORE_EXPORT LvmDevice : public VolumeManagerDevice
|
|
|
|
{
|
|
|
|
Q_DISABLE_COPY(LvmDevice)
|
|
|
|
|
|
|
|
public:
|
2016-09-08 01:42:04 +01:00
|
|
|
LvmDevice(const QString& name, const QList<Device *>& devices, const QString& iconName = QString());
|
2016-08-07 21:30:47 +01:00
|
|
|
~LvmDevice();
|
2016-06-10 18:00:19 +01:00
|
|
|
|
|
|
|
public:
|
2016-08-10 03:13:53 +01:00
|
|
|
const QStringList deviceNodes() const override;
|
|
|
|
const QStringList partitionNodes() const override;
|
|
|
|
qint64 partitionSize(QString& partitionPath) const override;
|
|
|
|
|
2016-08-08 08:03:58 +01:00
|
|
|
static QStringList s_DirtyPVs;
|
2016-06-10 18:00:19 +01:00
|
|
|
|
2016-08-07 21:30:47 +01:00
|
|
|
public:
|
2016-09-08 01:42:04 +01:00
|
|
|
static QList<LvmDevice*> scanSystemLVM(const QList<Device*>& devices);
|
2016-07-28 14:21:31 +01:00
|
|
|
|
2016-08-10 03:13:53 +01:00
|
|
|
static const QStringList getVGs();
|
2016-08-12 01:57:34 +01:00
|
|
|
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 getTotalLE(const QString& lvPath);
|
|
|
|
|
|
|
|
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);
|
2016-08-14 18:13:13 +01:00
|
|
|
static bool activateLV(const QString& deviceNode);
|
2016-08-12 01:57:34 +01:00
|
|
|
|
|
|
|
static bool removePV(Report& report, LvmDevice& d, const QString& pvPath);
|
|
|
|
static bool insertPV(Report& report, LvmDevice& d, const QString& pvPath);
|
2016-08-11 15:51:52 +01:00
|
|
|
static bool movePV(Report& report, const QString& pvPath, const QStringList& destinations = QStringList());
|
2016-06-18 21:58:40 +01:00
|
|
|
|
2016-08-12 01:57:34 +01:00
|
|
|
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);
|
2016-06-29 16:08:32 +01:00
|
|
|
|
2016-06-10 18:00:19 +01:00
|
|
|
protected:
|
2016-08-11 22:27:58 +01:00
|
|
|
|
2016-08-08 18:37:21 +01:00
|
|
|
void initPartitions() override;
|
2016-08-10 03:13:53 +01:00
|
|
|
const QList<Partition*> scanPartitions(PartitionTable* pTable) const;
|
2016-08-11 22:27:58 +01:00
|
|
|
Partition* scanPartition(const QString& lvPath, PartitionTable* pTable) const;
|
2016-08-12 01:57:34 +01:00
|
|
|
qint64 mappedSector(const QString& lvPath, qint64 sector) const override;
|
2016-06-18 20:54:52 +01:00
|
|
|
|
2016-06-08 16:50:40 +01:00
|
|
|
public:
|
2016-07-15 21:54:38 +01:00
|
|
|
qint64 peSize() const {
|
2016-06-08 16:50:40 +01:00
|
|
|
return m_peSize;
|
|
|
|
}
|
2016-06-26 11:54:47 +01:00
|
|
|
qint64 totalPE() const {
|
2016-06-08 16:50:40 +01:00
|
|
|
return m_totalPE;
|
|
|
|
}
|
2016-07-15 21:54:38 +01:00
|
|
|
qint64 allocatedPE() const {
|
2016-06-08 16:50:40 +01:00
|
|
|
return m_allocPE;
|
|
|
|
}
|
2016-07-15 21:54:38 +01:00
|
|
|
qint64 freePE() const {
|
2016-06-08 16:50:40 +01:00
|
|
|
return m_freePE;
|
|
|
|
}
|
2016-06-10 18:00:19 +01:00
|
|
|
QString UUID() const {
|
|
|
|
return m_UUID;
|
|
|
|
}
|
2016-06-08 16:50:40 +01:00
|
|
|
|
2016-08-10 03:13:53 +01:00
|
|
|
QStringList* LVPathList() const {
|
2016-08-07 21:30:47 +01:00
|
|
|
return m_LVPathList;
|
|
|
|
}
|
|
|
|
|
2016-09-08 01:42:04 +01:00
|
|
|
const QList <const Partition*> physicalVolumes() const {
|
|
|
|
return m_PVs;
|
2016-08-07 21:30:47 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 01:42:04 +01:00
|
|
|
protected:
|
2016-08-07 21:30:47 +01:00
|
|
|
QMap<QString, qint64>* LVSizeMap() const {
|
|
|
|
return m_LVSizeMap;
|
|
|
|
}
|
|
|
|
|
2016-06-08 16:50:40 +01:00
|
|
|
private:
|
2016-07-15 21:54:38 +01:00
|
|
|
qint64 m_peSize;
|
2016-06-26 11:54:47 +01:00
|
|
|
qint64 m_totalPE;
|
2016-07-15 21:54:38 +01:00
|
|
|
qint64 m_allocPE;
|
|
|
|
qint64 m_freePE;
|
2016-06-10 15:03:17 +01:00
|
|
|
QString m_UUID;
|
2016-06-18 20:54:52 +01:00
|
|
|
|
2016-08-07 21:30:47 +01:00
|
|
|
mutable QStringList* m_LVPathList;
|
2016-09-08 01:42:04 +01:00
|
|
|
mutable QList <const Partition*> m_PVs;
|
2016-08-07 21:30:47 +01:00
|
|
|
mutable QMap<QString, qint64>* m_LVSizeMap;
|
2016-06-08 16:50:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|