[lxc-devel] [lxd/master] Disk usage for snapshots

monstermunchkin on Github lxc-bot at linuxcontainers.org
Mon Mar 23 07:45:58 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200323/c6ba0e36/attachment-0001.bin>
-------------- next part --------------
From c470adcf15d0710340fb0a5a0415f965f02047ac Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 23 Mar 2020 08:43:55 +0100
Subject: [PATCH 1/4] shared/version/api: Add snapshot_disk_usage API extension

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/version/api.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/shared/version/api.go b/shared/version/api.go
index e06f0d8a7e..ba5f2f00ee 100644
--- a/shared/version/api.go
+++ b/shared/version/api.go
@@ -197,6 +197,7 @@ var APIExtensions = []string{
 	"custom_volume_snapshot_expiry",
 	"volume_snapshot_scheduling",
 	"trust_ca_certificates",
+	"snapshot_disk_usage",
 }
 
 // APIExtensionsCount returns the number of available API extensions.

From dc34726c6df3c0b9290a68ab69c1810defe4ac6a Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 23 Mar 2020 08:43:37 +0100
Subject: [PATCH 2/4] doc: Add snapshot_disk_usage

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 doc/api-extensions.md | 3 +++
 doc/rest-api.md       | 1 +
 2 files changed, 4 insertions(+)

diff --git a/doc/api-extensions.md b/doc/api-extensions.md
index 6dbd0a8b9c..3340012872 100644
--- a/doc/api-extensions.md
+++ b/doc/api-extensions.md
@@ -969,3 +969,6 @@ It can be enabled by setting `core.trust_ca_certificates` to true.
 If enabled, it will perform the check, and bypass the trusted password if true.
 An exception will be made if the connecting client certificate is in the provided CRL (`ca.crl`).
 In this case, it will ask for the password.
+
+## snapshot\_disk\_usage
+This adds a new `size` field to the output of `/1.0/instances/<name>/snapshots/<snapshot>` which represents the disk usage of the snapshot.
diff --git a/doc/rest-api.md b/doc/rest-api.md
index 2629fa5834..c50327d45f 100644
--- a/doc/rest-api.md
+++ b/doc/rest-api.md
@@ -1182,6 +1182,7 @@ Return:
     "profiles": [
         "default"
     ],
+    "size": 738476032,
     "stateful": false
 }
 ```

From 3d54577c8898ab7bd8ba8bf58d1f2a57ad66659d Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Fri, 20 Mar 2020 21:31:52 +0100
Subject: [PATCH 3/4] shared/api: Add size to {Container,Instance}Snapshot

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/api/container_snapshot.go | 3 +++
 shared/api/instance_snapshot.go  | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/shared/api/container_snapshot.go b/shared/api/container_snapshot.go
index e68a0fb8cc..400177521b 100644
--- a/shared/api/container_snapshot.go
+++ b/shared/api/container_snapshot.go
@@ -44,6 +44,9 @@ type ContainerSnapshot struct {
 	LastUsedAt      time.Time                    `json:"last_used_at" yaml:"last_used_at"`
 	Name            string                       `json:"name" yaml:"name"`
 	Stateful        bool                         `json:"stateful" yaml:"stateful"`
+
+	// API extension: snapshot_disk_usage
+	Size int64 `json:"size" yaml:"size"`
 }
 
 // Writable converts a full ContainerSnapshot struct into a ContainerSnapshotPut struct
diff --git a/shared/api/instance_snapshot.go b/shared/api/instance_snapshot.go
index bdd93544b2..1d7888e330 100644
--- a/shared/api/instance_snapshot.go
+++ b/shared/api/instance_snapshot.go
@@ -49,6 +49,9 @@ type InstanceSnapshot struct {
 	LastUsedAt      time.Time                    `json:"last_used_at" yaml:"last_used_at"`
 	Name            string                       `json:"name" yaml:"name"`
 	Stateful        bool                         `json:"stateful" yaml:"stateful"`
+
+	// API extension: snapshot_disk_usage
+	Size int64 `json:"size" yaml:"size"`
 }
 
 // Writable converts a full InstanceSnapshot struct into a InstanceSnapshotPut struct

From 3285a193e3818c117d61f0d294308e4d860d52fa Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 23 Mar 2020 08:34:46 +0100
Subject: [PATCH 4/4] lxd/instance/drivers: Get snapshot usage

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 lxd/instance/drivers/driver_lxc.go | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 1d08e49f82..e1dbf32119 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -3033,6 +3033,14 @@ func (c *lxc) Render() (interface{}, interface{}, error) {
 		ct.Profiles = c.profiles
 		ct.ExpiresAt = c.expiryDate
 
+		pool, err := storagePools.GetPoolByInstance(c.state, c)
+		if err == nil {
+			pool.MountInstanceSnapshot(c, nil)
+			defer pool.UnmountInstanceSnapshot(c, nil)
+
+			ct.Size, _ = pool.GetInstanceUsage(c)
+		}
+
 		return &ct, etag, nil
 	}
 


More information about the lxc-devel mailing list