[lxc-devel] [lxd/master] Bugfixes
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Apr 28 23:10:52 UTC 2016
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/20160428/08ce611f/attachment.bin>
-------------- next part --------------
From cb8233b7a2dd6c3256c4bacba390097824562326 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 27 Apr 2016 20:19:10 -0400
Subject: [PATCH 1/2] Use the same key check for unix-char and unix-block
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/container.go | 19 +------------------
1 file changed, 1 insertion(+), 18 deletions(-)
diff --git a/lxd/container.go b/lxd/container.go
index dd10b30..89b7ac1 100644
--- a/lxd/container.go
+++ b/lxd/container.go
@@ -112,24 +112,7 @@ func containerValidDeviceConfigKey(t, k string) bool {
}
switch t {
- case "unix-char":
- switch k {
- case "gid":
- return true
- case "major":
- return true
- case "minor":
- return true
- case "mode":
- return true
- case "path":
- return true
- case "uid":
- return true
- default:
- return false
- }
- case "unix-block":
+ case "unix-char", "unix-block":
switch k {
case "gid":
return true
From 652e49c7505db260ff989c5780c4126951e5f411 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 28 Apr 2016 18:45:36 -0400
Subject: [PATCH 2/2] Allow removing when fs object no longer exists
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This allows for the removal of container, image or snapshot that have
been manually removed from the filesystem.
Closes #1967
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/storage_btrfs.go | 18 +++++--
lxd/storage_dir.go | 4 ++
lxd/storage_zfs.go | 139 +++++++++++++++++++++++++++------------------------
3 files changed, 91 insertions(+), 70 deletions(-)
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 5093d4c..e9903c0 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -122,10 +122,12 @@ func (s *storageBtrfs) ContainerDelete(container container) error {
}
// Then the directory (if it still exists).
- err := os.RemoveAll(cPath)
- if err != nil {
- s.log.Error("ContainerDelete: failed", log.Ctx{"cPath": cPath, "err": err})
- return fmt.Errorf("Error cleaning up %s: %s", cPath, err)
+ if shared.PathExists(cPath) {
+ err := os.RemoveAll(cPath)
+ if err != nil {
+ s.log.Error("ContainerDelete: failed", log.Ctx{"cPath": cPath, "err": err})
+ return fmt.Errorf("Error cleaning up %s: %s", cPath, err)
+ }
}
return nil
@@ -423,7 +425,13 @@ func (s *storageBtrfs) ImageDelete(fingerprint string) error {
imagePath := shared.VarPath("images", fingerprint)
subvol := fmt.Sprintf("%s.btrfs", imagePath)
- return s.subvolDelete(subvol)
+ if s.isSubvolume(subvol) {
+ if err := s.subvolsDelete(subvol); err != nil {
+ return err
+ }
+ }
+
+ return nil
}
func (s *storageBtrfs) subvolCreate(subvol string) error {
diff --git a/lxd/storage_dir.go b/lxd/storage_dir.go
index 652d7eb..f0c892e 100644
--- a/lxd/storage_dir.go
+++ b/lxd/storage_dir.go
@@ -82,6 +82,10 @@ func (s *storageDir) ContainerCanRestore(container container, sourceContainer co
func (s *storageDir) ContainerDelete(container container) error {
cPath := container.Path()
+ if !shared.PathExists(cPath) {
+ return nil
+ }
+
err := os.RemoveAll(cPath)
if err != nil {
// RemovaAll fails on very long paths, so attempt an rm -Rf
diff --git a/lxd/storage_zfs.go b/lxd/storage_zfs.go
index 7b35aa9..9c73fc3 100644
--- a/lxd/storage_zfs.go
+++ b/lxd/storage_zfs.go
@@ -182,61 +182,63 @@ func (s *storageZfs) ContainerCanRestore(container container, sourceContainer co
func (s *storageZfs) ContainerDelete(container container) error {
fs := fmt.Sprintf("containers/%s", container.Name())
- removable := true
- snaps, err := s.zfsListSnapshots(fs)
- if err != nil {
- return err
- }
-
- for _, snap := range snaps {
- var err error
- removable, err = s.zfsSnapshotRemovable(fs, snap)
+ if s.zfsExists(fs) {
+ removable := true
+ snaps, err := s.zfsListSnapshots(fs)
if err != nil {
return err
}
- if !removable {
- break
- }
- }
+ for _, snap := range snaps {
+ var err error
+ removable, err = s.zfsSnapshotRemovable(fs, snap)
+ if err != nil {
+ return err
+ }
- if removable {
- origin, err := s.zfsGet(fs, "origin")
- if err != nil {
- return err
+ if !removable {
+ break
+ }
}
- origin = strings.TrimPrefix(origin, fmt.Sprintf("%s/", s.zfsPool))
- err = s.zfsDestroy(fs)
- if err != nil {
- return err
- }
+ if removable {
+ origin, err := s.zfsGet(fs, "origin")
+ if err != nil {
+ return err
+ }
+ origin = strings.TrimPrefix(origin, fmt.Sprintf("%s/", s.zfsPool))
- err = s.zfsCleanup(origin)
- if err != nil {
- return err
- }
- } else {
- err := s.zfsSet(fs, "mountpoint", "none")
- if err != nil {
- return err
- }
+ err = s.zfsDestroy(fs)
+ if err != nil {
+ return err
+ }
- err = s.zfsRename(fs, fmt.Sprintf("deleted/containers/%s", uuid.NewRandom().String()))
- if err != nil {
- return err
+ err = s.zfsCleanup(origin)
+ if err != nil {
+ return err
+ }
+ } else {
+ err := s.zfsSet(fs, "mountpoint", "none")
+ if err != nil {
+ return err
+ }
+
+ err = s.zfsRename(fs, fmt.Sprintf("deleted/containers/%s", uuid.NewRandom().String()))
+ if err != nil {
+ return err
+ }
}
}
if shared.PathExists(shared.VarPath(fs)) {
- os.Remove(shared.VarPath(fs))
+ err := os.Remove(shared.VarPath(fs))
if err != nil {
return err
}
}
if shared.PathExists(shared.VarPath(fs) + ".zfs") {
- os.Remove(shared.VarPath(fs) + ".zfs")
+ err := os.Remove(shared.VarPath(fs) + ".zfs")
if err != nil {
return err
}
@@ -470,27 +472,32 @@ func (s *storageZfs) ContainerSnapshotDelete(snapshotContainer container) error
cName := fields[0]
snapName := fmt.Sprintf("snapshot-%s", fields[1])
- removable, err := s.zfsSnapshotRemovable(fmt.Sprintf("containers/%s", cName), snapName)
- if removable {
- err = s.zfsSnapshotDestroy(fmt.Sprintf("containers/%s", cName), snapName)
- if err != nil {
- return err
+ if s.zfsExists(fmt.Sprintf("containers/%s@%s", cName, snapName)) {
+ removable, err := s.zfsSnapshotRemovable(fmt.Sprintf("containers/%s", cName), snapName)
+ if removable {
+ err = s.zfsSnapshotDestroy(fmt.Sprintf("containers/%s", cName), snapName)
+ if err != nil {
+ return err
+ }
+ } else {
+ err = s.zfsSnapshotRename(fmt.Sprintf("containers/%s", cName), snapName, fmt.Sprintf("copy-%s", uuid.NewRandom().String()))
+ if err != nil {
+ return err
+ }
}
- } else {
- err = s.zfsSnapshotRename(fmt.Sprintf("containers/%s", cName), snapName, fmt.Sprintf("copy-%s", uuid.NewRandom().String()))
+ }
+
+ snapPath := shared.VarPath(fmt.Sprintf("snapshots/%s/%s.zfs", cName, fields[1]))
+ if shared.PathExists(snapPath) {
+ err := os.Remove(snapPath)
if err != nil {
return err
}
}
- err = os.Remove(shared.VarPath(fmt.Sprintf("snapshots/%s/%s.zfs", cName, fields[1])))
- if err != nil {
- return err
- }
-
parent := shared.VarPath(fmt.Sprintf("snapshots/%s", cName))
if ok, _ := shared.PathIsEmpty(parent); ok {
- err = os.Remove(parent)
+ err := os.Remove(parent)
if err != nil {
return err
}
@@ -635,32 +642,34 @@ func (s *storageZfs) ImageCreate(fingerprint string) error {
func (s *storageZfs) ImageDelete(fingerprint string) error {
fs := fmt.Sprintf("images/%s", fingerprint)
- removable, err := s.zfsSnapshotRemovable(fs, "readonly")
-
- if err != nil {
- return err
- }
-
- if removable {
- err := s.zfsDestroy(fs)
- if err != nil {
- return err
- }
- } else {
- err := s.zfsSet(fs, "mountpoint", "none")
+ if s.zfsExists(fs) {
+ removable, err := s.zfsSnapshotRemovable(fs, "readonly")
if err != nil {
return err
}
- err = s.zfsRename(fs, fmt.Sprintf("deleted/%s", fs))
- if err != nil {
- return err
+ if removable {
+ err := s.zfsDestroy(fs)
+ if err != nil {
+ return err
+ }
+ } else {
+ err := s.zfsSet(fs, "mountpoint", "none")
+ if err != nil {
+ return err
+ }
+
+ err = s.zfsRename(fs, fmt.Sprintf("deleted/%s", fs))
+ if err != nil {
+ return err
+ }
}
}
if shared.PathExists(shared.VarPath(fs + ".zfs")) {
os.Remove(shared.VarPath(fs + ".zfs"))
}
+
return nil
}
More information about the lxc-devel
mailing list