File indexing completed on 2024-05-05 05:48:51

0001 /*
0002     SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com>
0003     SPDX-FileCopyrightText: 2016-2017 Andrius Štikonas <andrius@stikonas.eu>
0004     SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com>
0005 
0006     SPDX-License-Identifier: GPL-3.0-or-later
0007 */
0008 
0009 #include "ops/createvolumegroupoperation.h"
0010 
0011 #include "core/lvmdevice.h"
0012 #include "fs/lvm2_pv.h"
0013 
0014 #include "jobs/createvolumegroupjob.h"
0015 
0016 #include <QString>
0017 
0018 #include <KLocalizedString>
0019 
0020 /** Creates a new CreateVolumeGroupOperation.
0021  * @param vgName LVM Volume Group name
0022  * @param pvList List of LVM Physical Volumes used to create Volume Group
0023  * @param peSize LVM Physical Extent size in MiB
0024 */
0025 CreateVolumeGroupOperation::CreateVolumeGroupOperation(const QString& vgName, const QVector<const Partition*>& pvList, const qint32 peSize) :
0026     Operation(),
0027     m_CreateVolumeGroupJob(new CreateVolumeGroupJob(vgName, pvList, peSize)),
0028     m_PVList(pvList),
0029     m_vgName(vgName)
0030 {
0031     addJob(createVolumeGroupJob());
0032 }
0033 
0034 QString CreateVolumeGroupOperation::description() const
0035 {
0036     return xi18nc("@info/plain", "Create a new LVM volume group named \'%1\'.", m_vgName);
0037 }
0038 
0039 bool CreateVolumeGroupOperation::targets(const Partition& partition) const
0040 {
0041     for (const auto &p : m_PVList) {
0042         if (partition == *p)
0043             return true;
0044     }
0045     return false;
0046 }
0047 
0048 void CreateVolumeGroupOperation::preview()
0049 {
0050     LvmDevice::s_DirtyPVs << PVList();
0051 }
0052 
0053 void CreateVolumeGroupOperation::undo()
0054 {
0055     for (const auto &pvPath : PVList()) {
0056         if (LvmDevice::s_DirtyPVs.contains(pvPath)) {
0057             LvmDevice::s_DirtyPVs.removeAll(pvPath);
0058         }
0059     }
0060 }
0061 
0062 bool CreateVolumeGroupOperation::canCreate()
0063 {
0064     return true;
0065 }