From 50e1f161fb15cd469732210857eb88f5ba4fd151 Mon Sep 17 00:00:00 2001
From: Cao ShuFeng <caosf.fnst@cn.fujitsu.com>
Date: Sat, 4 Jun 2016 07:57:49 -0400
Subject: [PATCH] Fix size exceed of dd action when clearing a volume

This patch closes a bug that may result in "No space left" error
of dd command.

If user set the config item volume_clear_size to larger value than
a size of a volume, the "dd" command will get "No space left"
error when deleting the volume.
This change rejects volume_clear_size settings that are larger
than 1GiB, because there isn't really a reason to set that.
That would be safer all-around.

DocImpact

Closes-Bug: #1588310
Change-Id: I690d62bc728c85c9795a87f84b52f1a14474933d
---
 cinder/volume/driver.py                                       | 4 +++-
 ...ar_size-settings-larger-than-1024MiB-30b38811da048948.yaml | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)
 create mode 100644 releasenotes/notes/reject-volume_clear_size-settings-larger-than-1024MiB-30b38811da048948.yaml

diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py
index 95fbced5e12..91886fff93d 100644
--- a/cinder/volume/driver.py
+++ b/cinder/volume/driver.py
@@ -83,7 +83,9 @@ volume_opts = [
                help='Method used to wipe old volumes'),
     cfg.IntOpt('volume_clear_size',
                default=0,
-               help='Size in MiB to wipe at start of old volumes. 0 => all'),
+               max=1024,
+               help='Size in MiB to wipe at start of old volumes. 1024 MiB'
+                    'at max. 0 => all'),
     cfg.StrOpt('volume_clear_ionice',
                help='The flag to pass to ionice to alter the i/o priority '
                     'of the process used to zero a volume after deletion, '
diff --git a/releasenotes/notes/reject-volume_clear_size-settings-larger-than-1024MiB-30b38811da048948.yaml b/releasenotes/notes/reject-volume_clear_size-settings-larger-than-1024MiB-30b38811da048948.yaml
new file mode 100644
index 00000000000..9ad9eac8651
--- /dev/null
+++ b/releasenotes/notes/reject-volume_clear_size-settings-larger-than-1024MiB-30b38811da048948.yaml
@@ -0,0 +1,4 @@
+---
+fixes:
+  - Fix 'No Space left' of dd command when users set the config item
+    volume_clear_size to larger value than a size of a volume.