File indexing completed on 2024-04-28 05:46:35
0001 /* 0002 SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com> 0003 SPDX-FileCopyrightText: 2016-2020 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com> 0005 SPDX-FileCopyrightText: 2019 Yuri Chornoivan <yurchor@ukr.net> 0006 0007 SPDX-License-Identifier: GPL-3.0-or-later 0008 */ 0009 0010 #include "gui/resizevolumegroupdialog.h" 0011 #include "gui/volumegroupwidget.h" 0012 0013 #include <core/lvmdevice.h> 0014 #include <core/volumemanagerdevice.h> 0015 #include <core/partitiontable.h> 0016 #include <fs/lvm2_pv.h> 0017 0018 #include <ops/deleteoperation.h> 0019 0020 #include <util/capacity.h> 0021 #include <util/helpers.h> 0022 0023 #include <utility> 0024 0025 #include <KConfigGroup> 0026 #include <KLocalizedString> 0027 #include <KSharedConfig> 0028 0029 /** Creates a new ResizeVolumeGroupDialog 0030 @param parent pointer to the parent widget 0031 @param d the Device to show properties for 0032 */ 0033 ResizeVolumeGroupDialog::ResizeVolumeGroupDialog(QWidget* parent, VolumeManagerDevice* d, QVector<const Partition*>& partList, QList<Device*> devices, QList<Operation*> pendingOps) 0034 : VolumeGroupDialog(parent, d->name(), partList) 0035 , m_Devices(devices) 0036 , m_Device(d) 0037 , m_PendingOps(pendingOps) 0038 { 0039 setWindowTitle(xi18nc("@title:window", "Resize Volume Group")); 0040 0041 setupDialog(); 0042 setupConstraints(); 0043 0044 KConfigGroup kcg(KSharedConfig::openConfig(), QStringLiteral("resizeVolumeDialog")); 0045 restoreGeometry(kcg.readEntry<QByteArray>("Geometry", QByteArray())); 0046 } 0047 0048 void ResizeVolumeGroupDialog::setupDialog() 0049 { 0050 if (dialogWidget().volumeType().currentText() == QStringLiteral("LVM")) { 0051 for (const auto &p : std::as_const(LVM::pvList::list())) { 0052 bool toBeDeleted = false; 0053 0054 // Ignore partitions that are going to be deleted 0055 for (const auto &o : std::as_const(m_PendingOps)) { 0056 if (dynamic_cast<DeleteOperation *>(o) && o->targets(*p.partition())) { 0057 toBeDeleted = true; 0058 break; 0059 } 0060 } 0061 0062 if (toBeDeleted) 0063 continue; 0064 0065 if (p.isLuks()) 0066 continue; 0067 if (p.vgName() == device()->name()) 0068 dialogWidget().listPV().addPartition(*p.partition(), true); 0069 else if (p.vgName().isEmpty() && !LvmDevice::s_DirtyPVs.contains(p.partition())) // TODO: Remove LVM PVs in current VG 0070 dialogWidget().listPV().addPartition(*p.partition(), false); 0071 } 0072 0073 for (const Device *d : std::as_const(m_Devices)) { 0074 if (d->partitionTable() != nullptr) { 0075 for (const Partition *p : std::as_const(d->partitionTable()->children())) { 0076 // Looking if there is another VG creation that contains this partition 0077 if (LvmDevice::s_DirtyPVs.contains(p)) 0078 continue; 0079 0080 // Including new LVM PVs (that are currently in OperationStack and that aren't at other VG creation) 0081 if (p->state() == Partition::State::New) { 0082 if (p->fileSystem().type() == FileSystem::Type::Lvm2_PV) 0083 dialogWidget().listPV().addPartition(*p, false); 0084 else if (p->fileSystem().type() == FileSystem::Type::Luks || p->fileSystem().type() == FileSystem::Type::Luks2) { 0085 FileSystem *fs = static_cast<const FS::luks *>(&p->fileSystem())->innerFS(); 0086 0087 if (fs->type() == FileSystem::Type::Lvm2_PV) 0088 dialogWidget().listPV().addPartition(*p, false); 0089 } 0090 } 0091 } 0092 } 0093 } 0094 0095 for (const Partition *p : std::as_const(LvmDevice::s_OrphanPVs)) 0096 if (!LvmDevice::s_DirtyPVs.contains(p)) 0097 dialogWidget().listPV().addPartition(*p, false); 0098 } 0099 0100 //update used size and LV infos 0101 qint32 totalLV = 0; 0102 LvmDevice *lvmDevice = dynamic_cast<LvmDevice *>(device()); 0103 if (lvmDevice != nullptr) { 0104 m_TotalUsedSize = lvmDevice->allocatedPE() * lvmDevice->peSize(); 0105 totalLV = lvmDevice->partitionTable()->children().count(); 0106 } 0107 0108 dialogWidget().totalUsedSize().setText(Capacity::formatByteSize(m_TotalUsedSize)); 0109 dialogWidget().totalLV().setText(QString::number(totalLV)); 0110 } 0111 0112 void ResizeVolumeGroupDialog::setupConstraints() 0113 { 0114 dialogWidget().vgName().setEnabled(false); 0115 dialogWidget().spinPESize().setEnabled(false); 0116 dialogWidget().volumeType().setEnabled(false); 0117 VolumeGroupDialog::setupConstraints(); 0118 } 0119 0120 void ResizeVolumeGroupDialog::accept() 0121 { 0122 targetPVList().append(dialogWidget().listPV().checkedItems()); 0123 QDialog::accept(); 0124 }