OSDN Git Service

partitionmanager: implement used capacity for ZFS
authorIvailo Monev <xakepa10@gmail.com>
Tue, 16 Nov 2021 18:46:12 +0000 (20:46 +0200)
committerIvailo Monev <xakepa10@gmail.com>
Tue, 16 Nov 2021 18:46:12 +0000 (20:46 +0200)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
partitionmanager/src/fs/zfs.cpp
partitionmanager/src/fs/zfs.h

index 75adaaa..b7b48e1 100644 (file)
@@ -49,6 +49,7 @@ namespace FS
        {
                m_SetLabel = findExternal("zpool", QStringList(), 2) ? cmdSupportFileSystem : cmdSupportNone;
 
+               m_GetUsed = findExternal("zfs", QStringList(), 2) ? cmdSupportFileSystem : cmdSupportNone;
                m_GetLabel = cmdSupportCore;
                m_Backup = cmdSupportCore;
                m_GetUUID = cmdSupportCore;
@@ -57,7 +58,7 @@ namespace FS
        bool zfs::supportToolFound() const
        {
                return
-//                     m_GetUsed != cmdSupportNone &&
+                       m_GetUsed != cmdSupportNone &&
                        m_GetLabel != cmdSupportNone &&
                        m_SetLabel != cmdSupportNone &&
 //                     m_Create != cmdSupportNone &&
@@ -86,6 +87,28 @@ namespace FS
                 return Capacity::unitFactor(Capacity::Byte, Capacity::EiB);
        }
 
+       qint64 zfs::maxLabelLength() const
+       {
+               // for reference:
+               // https://www.freebsd.org/cgi/man.cgi?query=zfs
+               return (256 * 50);
+       }
+
+       qint64 zfs::readUsedCapacity(const QString& deviceNode) const
+       {
+               Q_UNUSED(deviceNode)
+               qint64 result = -1;
+               ExternalCommand cmd("zfs", QStringList() << "list" << "-H" << "-p" << "-o" << "used" << this->label());
+               if (cmd.start() && cmd.waitFor()) {
+                       bool ok = false;
+                       result = cmd.output().toLongLong(&ok);
+                       if (!ok) {
+                               result = -1;
+                       }
+               }
+               return result;
+       }
+
        bool zfs::remove(Report& report, const QString& deviceNode) const
        {
                Q_UNUSED(deviceNode)
index 6b8236a..7b0a9ee 100644 (file)
@@ -44,6 +44,7 @@ namespace FS
                public:
                        static void init();
 
+                       virtual qint64 readUsedCapacity(const QString& deviceNode) const;
                        virtual bool remove(Report& report, const QString& deviceNode) const;
                        virtual bool writeLabel(Report& report, const QString& deviceNode, const QString& newLabel);
 
@@ -62,6 +63,7 @@ namespace FS
 
                        virtual qint64 minCapacity() const;
                        virtual qint64 maxCapacity() const;
+                       virtual qint64 maxLabelLength() const;
                        virtual SupportTool supportToolName() const;
                        virtual bool supportToolFound() const;