From c3c718615d1c33e5b937913489245d7a7d7ae728 Mon Sep 17 00:00:00 2001 From: Chantara Tith Date: Mon, 1 Aug 2016 19:20:20 +0700 Subject: [PATCH] Add LVM snapshotting functionality. --- src/core/lvmdevice.cpp | 17 +++++++++++++++++ src/core/lvmdevice.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index 8b6c8e1..72eabde 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -339,6 +339,23 @@ bool LvmDevice::createLV(Report& report, LvmDevice& dev, Partition& part, const return (cmd.run(-1) && cmd.exitCode() == 0); } +bool LvmDevice::createLVSnapshot(Report& report, LvmDevice& dev, Partition& lvpart, const QString& name, const qint64 extents) +{ + Q_UNUSED(dev); + QString numExtents = (extents > 0) ? QString::number(extents) : + QString::number(lvpart.length()); + ExternalCommand cmd(report, QStringLiteral("lvm"), + { QStringLiteral("lvcreate"), + QStringLiteral("--yes"), + QStringLiteral("--extents"), + numExtents, + QStringLiteral("--snapshot"), + QStringLiteral("--name"), + name, + lvpart.partitionPath() }); + return (cmd.run(-1) && cmd.exitCode() == 0); +} + bool LvmDevice::resizeLV(Report& report, LvmDevice& dev, Partition& part) { Q_UNUSED(dev); diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index b69f52f..a59935d 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -66,6 +66,7 @@ public: static bool removeLV(Report& report, LvmDevice& dev, Partition& part); static bool createLV(Report& report, LvmDevice& dev, Partition& part, const QString& lvname); + static bool createLVSnapshot(Report& report, LvmDevice& dev, Partition& lvpart, const QString& name, const qint64 extents = 0); static bool resizeLV(Report& report, LvmDevice& dev, Partition& part); static bool removePV(Report& report, LvmDevice& dev, const QString& pvPath);