The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/2888

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Christian Brauner <[email protected]>
From 46036a4e1f866a280153f8ffff99bf1167f0af33 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Wed, 15 Feb 2017 11:44:28 +0100
Subject: [PATCH] storage volumes: refuse removal if volume is used

Signed-off-by: Christian Brauner <[email protected]>
---
 lxd/storage_volumes.go       | 9 +++++++++
 lxd/storage_volumes_utils.go | 3 +--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index f2f5f8b..56fdd76 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -435,6 +435,15 @@ func storagePoolVolumeTypeDelete(d *Daemon, r 
*http.Request) Response {
                return BadRequest(fmt.Errorf("Invalid storage volume type %s.", 
volumeTypeName))
        }
 
+       volumeUsedBy, err := storagePoolVolumeUsedByGet(d, volumeName)
+       if err != nil {
+               return InternalError(err)
+       }
+
+       if len(volumeUsedBy) > 0 {
+               return BadRequest(fmt.Errorf("The storage volume is in use by 
containers."))
+       }
+
        s, err := storagePoolVolumeInit(d, poolName, volumeName, volumeType)
        if err != nil {
                return NotFound
diff --git a/lxd/storage_volumes_utils.go b/lxd/storage_volumes_utils.go
index bf8f365..10ffa77 100644
--- a/lxd/storage_volumes_utils.go
+++ b/lxd/storage_volumes_utils.go
@@ -184,10 +184,9 @@ func storagePoolVolumeUsedByGet(d *Daemon, volumeName 
string) ([]string, error)
 
        volumeUsedBy := []string{}
        for _, ct := range cts {
-               // We're not accessing any storage here.
                c, err := containerLoadByName(d, ct)
                if err != nil {
-                       return []string{}, err
+                       continue
                }
 
                for _, d := range c.LocalDevices() {
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to