Amador Pahim has uploaded a new change for review.
Change subject: hook: diskunmap: To include UNMAP support for disk and lun devices
......................................................................
hook: diskunmap: To include UNMAP support for disk and lun devices
This hook goes through VM definitions xml file and manipulate its
disk device if it "disk" or "lun" and if the bus is "scsi"
or "ide",
adding "discard=unmap" option to "-drive" qemu command line
patameter.
UNMAP support was added to qemu 1.5 and it's intendded to return the
unused/freed blocks back to the storage, optimizing the utilizationi,
specially useful for thin provisioned LUNs.
Result example:
<disk device="disk" snapshot="no" type="block">
...
<target bus="ide" dev="hda"/>
...
<driver cache="none" discard="unmap" ... />
</disk>
<disk device="lun" sgio="filtered" snapshot="no"
type="block">
...
<target bus="scsi" dev="sda"/>
...
<driver cache="none" discard="unmap" ... />
</disk>
Change-Id: I36385f1af24043755b3d4b6594bbe598b0d9518d
Signed-off-by: Amador Pahim <apahim(a)redhat.com>
---
M configure.ac
M vdsm.spec.in
M vdsm_hooks/Makefile.am
A vdsm_hooks/diskunmap/Makefile.am
A vdsm_hooks/diskunmap/README
A vdsm_hooks/diskunmap/before_vm_start.py
6 files changed, 178 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/70/29770/1
diff --git a/configure.ac b/configure.ac
index d741c1b..ce9d800 100644
--- a/configure.ac
+++ b/configure.ac
@@ -285,6 +285,7 @@
vdsm_hooks/Makefile
vdsm_hooks/checkimages/Makefile
vdsm_hooks/directlun/Makefile
+ vdsm_hooks/diskunmap/Makefile
vdsm_hooks/ethtool_options/Makefile
vdsm_hooks/extnet/Makefile
vdsm_hooks/fakevmstats/Makefile
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 2b67962..2c48e3e 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -366,6 +366,14 @@
VDSM hook used to perform consistency check on a qcow2 format disk image
using the QEMU disk image utility.
+%package hook-diskunmap
+Summary: Activate UNMAP for disk/lun devices
+BuildArch: noarch
+Requires: qemu-kvm >= 1.5
+
+%description hook-diskunmap
+VDSM hooks which allow to activate disk UNMAP.
+
%package hook-ethtool-options
Summary: Allow setting custom ethtool options for vdsm controlled nics
BuildArch: noarch
@@ -1282,6 +1290,10 @@
%{_libexecdir}/%{vdsm_name}/hooks/after_vm_destroy/50_directlun
%{_libexecdir}/%{vdsm_name}/hooks/before_vm_migrate_destination/50_directlun
+%files hook-diskunmap
+%defattr(-, root, root, -)
+%{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/50_diskunmap
+
%files hook-fakevmstats
%defattr(-, root, root, -)
%{_libexecdir}/%{vdsm_name}/hooks/after_get_all_vm_stats/10_fakevmstats
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index 5e4d731..20578db 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -27,6 +27,7 @@
SUBDIRS += \
checkimages \
directlun \
+ diskunmap \
extnet \
fileinject \
fakevmstats \
diff --git a/vdsm_hooks/diskunmap/Makefile.am b/vdsm_hooks/diskunmap/Makefile.am
new file mode 100644
index 0000000..f2b9a85
--- /dev/null
+++ b/vdsm_hooks/diskunmap/Makefile.am
@@ -0,0 +1,31 @@
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+#
+EXTRA_DIST = \
+ before_vm_start.py
+
+install-data-local:
+ $(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start
+ $(INSTALL_SCRIPT) $(srcdir)/before_vm_start.py \
+ $(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_diskunmap
+
+uninstall-local:
+ $(RM) $(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_diskunmap
+
diff --git a/vdsm_hooks/diskunmap/README b/vdsm_hooks/diskunmap/README
new file mode 100644
index 0000000..35751d6
--- /dev/null
+++ b/vdsm_hooks/diskunmap/README
@@ -0,0 +1,40 @@
+diskunmap vdsm hook:
+==================
+This hook goes through all of the VM's disks and manipulate its XML
+file acccording to the input. This can be used to enable UNMAP feature
+to discard unused blocks for better use of thin provisioned storage
+devices.
+
+Syntax:
+ diskunmap=(off|on)
+
+Where:
+ 'on' is unmap enabled and off (default) is unmap disabled.
+
+Example:
+ diskunmap=on
+
+Installation:
+ - Use the engine-config to append the proper custom property:
+ $ sudo engine-config -s UserDefinedVMProperties='diskunmap=^(off|on)$'
+ - Verify that the macbind custom property was properly added:
+ $ sudo engine-config -g UserDefinedVMProperties
+
+Usage:
+ In the VM configuration window, open the custom properites tab, select
+ diskmap and select 'on', activating disk UNMAP for all disks and LUNs.
+ Only devices using IDE or VirtIO-SCSI interface will be affected. UNMAP is
+ not available for VirtIO interface.
+
+Expected Result:
+ For every DISK or LUN device, this configuration will include
+ "discard=unmap" to disk driver xml:
+
+ <disk device="disk" snapshot="no" type="block">
+ ...
+ <driver cache="none" discard="unmap" ... />
+ </disk>
+
+ This option will be tranlated to qemu as bellow:
+
+ ... -drive file=<file>,discard=unmap,...
diff --git a/vdsm_hooks/diskunmap/before_vm_start.py
b/vdsm_hooks/diskunmap/before_vm_start.py
new file mode 100644
index 0000000..2fc0b81
--- /dev/null
+++ b/vdsm_hooks/diskunmap/before_vm_start.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python2
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+
+'''
+Hook to enable disk UNMAP for disk devices.
+
+Syntax:
+ diskunmap=(off|on)
+
+Example:
+ diskunmap=on
+'''
+
+import os
+import sys
+import traceback
+from xml.dom import minidom
+
+import hooking
+
+
+def addDiscardUnmap(domxml):
+ for disk in domxml.getElementsByTagName('disk'):
+ device = disk.getAttribute('device')
+ target = disk.getElementsByTagName('target')[0]
+ bus = target.getAttribute('bus')
+ if ((device == 'disk' or device == 'lun')
+ and (bus == 'scsi' or bus == 'ide')):
+ driver = disk.getElementsByTagName('driver')[0]
+ driver.setAttribute('discard', 'unmap')
+
+
+def main():
+ if 'diskunmap' in os.environ:
+ unmapConfig = os.environ['diskunmap']
+ domxml = hooking.read_domxml()
+ if unmapConfig == 'on':
+ addDiscardUnmap(domxml)
+ hooking.write_domxml(domxml)
+
+
+def test():
+ text = '''<disk device="disk" snapshot="no"
type="block">
+<address bus="0" controller="0" target="0"
type="drive" unit="0"/>
+<source dev="/rhev/data-center/mnt/blockSD/
+b4cf7d74-6a07-4138-9d4f-80b14c3acefd/images/
+1580607a-b240-4199-99ac-3d2162934ba6/e5ba276f-dcba-4582-b13f-c165afa2f575"/>
+<target bus="ide" dev="hda"/>
+<serial>1580607a-b240-4199-99ac-3d2162934ba6</serial>
+<driver cache="none" error_policy="stop" io="native"
+name="qemu" type="raw"/>
+</disk>'''
+
+ xmldom = minidom.parseString(text)
+
+ disk = xmldom.getElementsByTagName('disk')[0]
+ print "\nDisk device definition before execution: \n%s"\
+ % disk.toxml(encoding='UTF-8')
+
+ addDiscardUnmap(xmldom)
+
+ print "\nDisk device after setting discard attribute: \n%s"\
+ % disk.toxml(encoding='UTF-8')
+
+
+if __name__ == '__main__':
+ try:
+ if '--test' in sys.argv:
+ test()
+ else:
+ main()
+ except:
+ hooking.exit_hook(' diskunmap hook: [unexpected error]: %s\n' %
+ traceback.format_exc())
--
To view, visit
http://gerrit.ovirt.org/29770
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I36385f1af24043755b3d4b6594bbe598b0d9518d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Amador Pahim <apahim(a)redhat.com>