2020-09-16 00:35:12 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
|
2020-10-24 22:15:02 +01:00
|
|
|
SPDX-FileCopyrightText: 2016-2020 Andrius Štikonas <andrius@stikonas.eu>
|
2020-09-16 00:35:12 +01:00
|
|
|
SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
|
|
|
|
SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2016-07-09 01:12:31 +01:00
|
|
|
|
2016-09-04 12:25:43 +01:00
|
|
|
#include "gui/resizevolumegroupdialog.h"
|
|
|
|
#include "gui/volumegroupwidget.h"
|
2016-07-09 01:12:31 +01:00
|
|
|
|
|
|
|
#include <core/lvmdevice.h>
|
2016-08-08 00:47:05 +01:00
|
|
|
#include <core/volumemanagerdevice.h>
|
|
|
|
#include <core/partitiontable.h>
|
2016-07-09 01:12:31 +01:00
|
|
|
#include <fs/lvm2_pv.h>
|
|
|
|
|
2018-07-16 00:20:00 +01:00
|
|
|
#include <ops/deleteoperation.h>
|
|
|
|
|
2016-07-09 01:12:31 +01:00
|
|
|
#include <util/capacity.h>
|
|
|
|
#include <util/helpers.h>
|
|
|
|
|
2020-10-24 22:15:02 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2016-08-23 16:40:16 +01:00
|
|
|
#include <KConfigGroup>
|
2016-07-09 01:12:31 +01:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KSharedConfig>
|
|
|
|
|
2016-09-04 12:25:43 +01:00
|
|
|
/** Creates a new ResizeVolumeGroupDialog
|
2016-07-09 01:12:31 +01:00
|
|
|
@param parent pointer to the parent widget
|
2016-09-08 01:42:13 +01:00
|
|
|
@param d the Device to show properties for
|
2016-07-09 01:12:31 +01:00
|
|
|
*/
|
2018-07-16 00:20:00 +01:00
|
|
|
ResizeVolumeGroupDialog::ResizeVolumeGroupDialog(QWidget* parent, VolumeManagerDevice* d, QVector<const Partition*>& partList, QList<Device*> devices, QList<Operation*> pendingOps)
|
2016-09-24 21:09:16 +01:00
|
|
|
: VolumeGroupDialog(parent, d->name(), partList)
|
2018-07-16 00:20:00 +01:00
|
|
|
, m_Devices(devices)
|
2016-09-10 22:10:11 +01:00
|
|
|
, m_Device(d)
|
2018-07-16 00:20:00 +01:00
|
|
|
, m_PendingOps(pendingOps)
|
2016-07-09 01:12:31 +01:00
|
|
|
{
|
|
|
|
setWindowTitle(xi18nc("@title:window", "Resize Volume Group"));
|
|
|
|
|
|
|
|
setupDialog();
|
|
|
|
setupConstraints();
|
|
|
|
|
|
|
|
KConfigGroup kcg(KSharedConfig::openConfig(), "resizeVolumeDialog");
|
|
|
|
restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray()));
|
|
|
|
}
|
|
|
|
|
2016-09-04 12:25:43 +01:00
|
|
|
void ResizeVolumeGroupDialog::setupDialog()
|
2016-07-09 01:12:31 +01:00
|
|
|
{
|
2016-08-08 00:47:05 +01:00
|
|
|
if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) {
|
2020-10-24 22:15:02 +01:00
|
|
|
for (const auto &p : std::as_const(LVM::pvList::list())) {
|
2018-07-16 00:20:00 +01:00
|
|
|
bool toBeDeleted = false;
|
|
|
|
|
|
|
|
// Ignore partitions that are going to be deleted
|
2020-10-24 22:15:02 +01:00
|
|
|
for (const auto &o : std::as_const(m_PendingOps)) {
|
2018-07-16 00:20:00 +01:00
|
|
|
if (dynamic_cast<DeleteOperation *>(o) && o->targets(*p.partition())) {
|
|
|
|
toBeDeleted = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (toBeDeleted)
|
|
|
|
continue;
|
|
|
|
|
2016-11-03 14:22:11 +00:00
|
|
|
if (p.isLuks())
|
|
|
|
continue;
|
2016-11-02 23:07:01 +00:00
|
|
|
if (p.vgName() == device()->name())
|
|
|
|
dialogWidget().listPV().addPartition(*p.partition(), true);
|
2019-12-09 16:33:04 +00:00
|
|
|
else if (p.vgName().isEmpty() && !LvmDevice::s_DirtyPVs.contains(p.partition())) // TODO: Remove LVM PVs in current VG
|
2016-11-02 23:07:01 +00:00
|
|
|
dialogWidget().listPV().addPartition(*p.partition(), false);
|
2016-08-08 08:04:55 +01:00
|
|
|
}
|
2018-07-16 00:20:00 +01:00
|
|
|
|
2020-10-24 22:15:02 +01:00
|
|
|
for (const Device *d : std::as_const(m_Devices)) {
|
2018-07-23 17:38:30 +01:00
|
|
|
if (d->partitionTable() != nullptr) {
|
2020-10-24 22:15:02 +01:00
|
|
|
for (const Partition *p : std::as_const(d->partitionTable()->children())) {
|
2018-07-23 17:38:30 +01:00
|
|
|
// Looking if there is another VG creation that contains this partition
|
|
|
|
if (LvmDevice::s_DirtyPVs.contains(p))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Including new LVM PVs (that are currently in OperationStack and that aren't at other VG creation)
|
|
|
|
if (p->state() == Partition::State::New) {
|
|
|
|
if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV)
|
|
|
|
dialogWidget().listPV().addPartition(*p, false);
|
|
|
|
else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) {
|
|
|
|
FileSystem *fs = static_cast<const FS::luks *>(&p->fileSystem())->innerFS();
|
|
|
|
|
|
|
|
if (fs->type() == FileSystem::Type::Lvm2_PV)
|
|
|
|
dialogWidget().listPV().addPartition(*p, false);
|
|
|
|
}
|
|
|
|
}
|
2018-07-16 00:20:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-23 17:38:30 +01:00
|
|
|
|
2020-10-24 22:15:02 +01:00
|
|
|
for (const Partition *p : std::as_const(LvmDevice::s_OrphanPVs))
|
2018-07-23 17:38:30 +01:00
|
|
|
if (!LvmDevice::s_DirtyPVs.contains(p))
|
|
|
|
dialogWidget().listPV().addPartition(*p, false);
|
2016-08-08 00:47:05 +01:00
|
|
|
}
|
2016-09-24 21:09:16 +01:00
|
|
|
|
|
|
|
//update used size and LV infos
|
|
|
|
qint32 totalLV = 0;
|
|
|
|
LvmDevice *lvmDevice = dynamic_cast<LvmDevice *>(device());
|
|
|
|
if (lvmDevice != nullptr) {
|
|
|
|
m_TotalUsedSize = lvmDevice->allocatedPE() * lvmDevice->peSize();
|
|
|
|
totalLV = lvmDevice->partitionTable()->children().count();
|
|
|
|
}
|
|
|
|
|
|
|
|
dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(m_TotalUsedSize));
|
|
|
|
dialogWidget().totalLV().setText(QString::number(totalLV));
|
2016-07-09 01:12:31 +01:00
|
|
|
}
|
|
|
|
|
2016-09-04 12:25:43 +01:00
|
|
|
void ResizeVolumeGroupDialog::setupConstraints()
|
2016-07-09 01:12:31 +01:00
|
|
|
{
|
|
|
|
dialogWidget().vgName().setEnabled(false);
|
|
|
|
dialogWidget().spinPESize().setEnabled(false);
|
|
|
|
dialogWidget().volumeType().setEnabled(false);
|
2016-09-04 12:25:43 +01:00
|
|
|
VolumeGroupDialog::setupConstraints();
|
2016-07-09 01:12:31 +01:00
|
|
|
}
|
|
|
|
|
2016-09-04 12:25:43 +01:00
|
|
|
void ResizeVolumeGroupDialog::accept()
|
2016-07-09 01:12:31 +01:00
|
|
|
{
|
2017-08-31 10:34:58 +01:00
|
|
|
targetPVList().append(dialogWidget().listPV().checkedItems());
|
2016-07-09 01:12:31 +01:00
|
|
|
QDialog::accept();
|
|
|
|
}
|