[lxc-devel] [lxd/master] Fix ZFS refcounting issues
stgraber on Github
lxc-bot at linuxcontainers.org
Wed May 11 16:07:49 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 384 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160511/610d6716/attachment.bin>
-------------- next part --------------
From b588fe35c359eca860d5230919cb9818ed4d6dac Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 11 May 2016 12:07:06 -0400
Subject: [PATCH] Fix ZFS refcounting issues
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #1916
Closes #2013
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/storage_zfs.go | 61 ++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 48 insertions(+), 13 deletions(-)
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 4d8d932..8386ed8 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -795,29 +795,64 @@ func (s *storageZfs) zfsDestroy(path string) error {
func (s *storageZfs) zfsCleanup(path string) error {
if strings.HasPrefix(path, "deleted/") {
+ // Cleanup of filesystems kept for refcount reason
removablePath, err := s.zfsSnapshotRemovable(path, "")
if err != nil {
return err
}
+ // Confirm that there are no more clones
if removablePath {
- subPath := strings.SplitN(path, "@", 2)[0]
-
- origin, err := s.zfsGet(subPath, "origin")
- if err != nil {
- return err
- }
- origin = strings.TrimPrefix(origin, fmt.Sprintf("%s/", s.zfsPool))
-
- err = s.zfsDestroy(subPath)
- if err != nil {
- return err
+ if strings.Contains(path, "@") {
+ // Cleanup snapshots
+ err = s.zfsDestroy(path)
+ if err != nil {
+ return err
+ }
+
+ // Check if the parent can now be deleted
+ subPath := strings.SplitN(path, "@", 2)[0]
+ snaps, err := s.zfsListSnapshots(subPath)
+ if err != nil {
+ return err
+ }
+
+ if len(snaps) == 0 {
+ err := s.zfsCleanup(subPath)
+ if err != nil {
+ return err
+ }
+ }
+ } else {
+ // Cleanup filesystems
+ origin, err := s.zfsGet(path, "origin")
+ if err != nil {
+ return err
+ }
+ origin = strings.TrimPrefix(origin, fmt.Sprintf("%s/", s.zfsPool))
+
+ err = s.zfsDestroy(path)
+ if err != nil {
+ return err
+ }
+
+ // Attempt to remove its parent
+ if origin != "-" {
+ err := s.zfsCleanup(origin)
+ if err != nil {
+ return err
+ }
+ }
}
- s.zfsCleanup(origin)
-
return nil
}
+ } else if strings.HasPrefix(path, "containers") {
+ // Just remove the copy- snapshot for copies of active containers
+ err := s.zfsDestroy(path)
+ if err != nil {
+ return err
+ }
}
return nil
More information about the lxc-devel
mailing list