[vdsm] vdsm-4.12.1-4
Douglas Schilling Landgraf
dougsland at fedoraproject.org
Thu Oct 10 12:22:09 UTC 2013
commit bf7d37c535f66e4e5248820280a46bcc2e607f87
Author: Douglas Schilling Landgraf <dougsland at redhat.com>
Date: Thu Oct 10 05:21:49 2013 -0400
vdsm-4.12.1-4
- remoteFileHandler: Add create exclusive option for truncateFile (BZ#979193)
- oop: improve safety for truncateFile
...andler-Add-create-exclusive-option-for-tr.patch | 41 ++++++++
0007-oop-improve-safety-for-truncateFile.patch | 105 ++++++++++++++++++++
vdsm.spec | 11 ++-
3 files changed, 156 insertions(+), 1 deletions(-)
---
diff --git a/0006-remoteFileHandler-Add-create-exclusive-option-for-tr.patch b/0006-remoteFileHandler-Add-create-exclusive-option-for-tr.patch
new file mode 100644
index 0000000..bfb8e16
--- /dev/null
+++ b/0006-remoteFileHandler-Add-create-exclusive-option-for-tr.patch
@@ -0,0 +1,41 @@
+From e086b7a3d1de694d3335304442a3564c277acc30 Mon Sep 17 00:00:00 2001
+From: Yeela Kaplan <ykaplan at redhat.com>
+Date: Mon, 9 Sep 2013 11:04:39 +0200
+Subject: [PATCH] remoteFileHandler: Add create exclusive option for
+ truncateFile
+
+Change-Id: Idfeff348e0f6fc240954e7d304b794dd99ea098c
+Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=979193
+Signed-off-by: Yeela Kaplan <ykaplan at redhat.com>
+Reviewed-on: http://gerrit.ovirt.org/19022
+Reviewed-by: Dan Kenigsberg <danken at redhat.com>
+Reviewed-on: http://gerrit.ovirt.org/20062
+Reviewed-by: Federico Simoncelli <fsimonce at redhat.com>
+Tested-by: Federico Simoncelli <fsimonce at redhat.com>
+---
+ vdsm/storage/remoteFileHandler.py | 9 +++++++--
+ 1 file changed, 7 insertions(+), 2 deletions(-)
+
+diff --git a/vdsm/storage/remoteFileHandler.py b/vdsm/storage/remoteFileHandler.py
+index abe9915..47b237b 100644
+--- a/vdsm/storage/remoteFileHandler.py
++++ b/vdsm/storage/remoteFileHandler.py
+@@ -334,8 +334,13 @@ def directWriteLines(path, lines):
+ return f.writelines(lines)
+
+
+-def truncateFile(path, size, mode=None):
+- with open(path, "w") as f:
++def truncateFile(path, size, mode=None, creatExcl=False):
++ flags = os.O_CREAT | os.O_WRONLY
++ if creatExcl:
++ flags |= os.O_EXCL
++
++ fd = os.open(path, flags)
++ with os.fdopen(fd, 'w') as f:
+ if mode is not None:
+ os.chmod(path, mode)
+ f.truncate(size)
+--
+1.8.3.1
+
diff --git a/0007-oop-improve-safety-for-truncateFile.patch b/0007-oop-improve-safety-for-truncateFile.patch
new file mode 100644
index 0000000..b01203b
--- /dev/null
+++ b/0007-oop-improve-safety-for-truncateFile.patch
@@ -0,0 +1,105 @@
+From 22b94817d1647e2bfdce66a24d0c25ead47fdedc Mon Sep 17 00:00:00 2001
+From: Federico Simoncelli <fsimonce at redhat.com>
+Date: Wed, 9 Oct 2013 15:03:25 -0400
+Subject: [PATCH] oop: improve safety for truncateFile
+
+In order to make truncateFile safer and to avoid any confusion on its
+behavior:
+
+* a new comment has been added mentioning O_TRUNC and "w" to avoid any
+ future mistake in this area
+* a new test has been added to check the expected outcomes
+* the "w" mode has been removed from truncateFile (used in os.fdopen)
+ to prevent any future reconversion to open(path, "w")
+* the risk of a file descriptor leak (for a failing os.fdopen call)
+ has been removed using the relevant posix calls
+
+Change-Id: Ib71b53498c7bc4ea7a1ab725feb18bc5929f8c85
+Signed-off-by: Federico Simoncelli <fsimonce at redhat.com>
+Reviewed-on: http://gerrit.ovirt.org/20046
+Reviewed-by: Nir Soffer <nsoffer at redhat.com>
+Reviewed-by: Sergey Gotliv <sgotliv at redhat.com>
+Reviewed-by: Dan Kenigsberg <danken at redhat.com>
+Reviewed-on: http://gerrit.ovirt.org/20063
+---
+ tests/remoteFileHandlerTests.py | 28 ++++++++++++++++++++++++++++
+ vdsm/storage/remoteFileHandler.py | 14 +++++++++++---
+ 2 files changed, 39 insertions(+), 3 deletions(-)
+
+diff --git a/tests/remoteFileHandlerTests.py b/tests/remoteFileHandlerTests.py
+index 544ec28..a2ca574 100644
+--- a/tests/remoteFileHandlerTests.py
++++ b/tests/remoteFileHandlerTests.py
+@@ -18,6 +18,8 @@
+ # Refer to the README and COPYING files for full details of the license
+ #
+ import os
++import string
++import tempfile
+ from vdsm import utils
+
+ from testrunner import VdsmTestCase as TestCaseBase
+@@ -69,3 +71,29 @@ class PoolHandlerTests(TestCaseBase):
+ test = lambda: self.assertFalse(os.path.exists(procPath))
+
+ utils.retry(test, AssertionError, timeout=4, sleep=0.1)
++
++
++class RemoteFileHandlerFunctionTests(TestCaseBase):
++ def testTruncateFile(self):
++ fd, path = tempfile.mkstemp()
++ try:
++ os.write(fd, string.ascii_uppercase)
++ os.close(fd)
++
++ # Verifying content
++ data = string.ascii_uppercase
++ self.assertEquals(data, file(path).read())
++
++ # Testing truncate to a larger size
++ data = string.ascii_uppercase + chr(0) * 16
++
++ rhandler.truncateFile(path, len(data))
++ self.assertEquals(data, file(path).read())
++
++ # Testing truncate to a smaller size
++ data = string.ascii_uppercase
++
++ rhandler.truncateFile(path, len(data))
++ self.assertEquals(data, file(path).read())
++ finally:
++ os.unlink(path)
+diff --git a/vdsm/storage/remoteFileHandler.py b/vdsm/storage/remoteFileHandler.py
+index 47b237b..3a22bc4 100644
+--- a/vdsm/storage/remoteFileHandler.py
++++ b/vdsm/storage/remoteFileHandler.py
+@@ -335,15 +335,23 @@ def directWriteLines(path, lines):
+
+
+ def truncateFile(path, size, mode=None, creatExcl=False):
++ # NOTE: Under no circumstance you should add the O_TRUNC
++ # flag here. We rely on the fact that the file content is
++ # not deleted when truncating to a larger size.
++ # Please also note that the "w" option used in open/file
++ # contains O_TRUNC and therefore should not be used here.
+ flags = os.O_CREAT | os.O_WRONLY
++
+ if creatExcl:
+ flags |= os.O_EXCL
+
+ fd = os.open(path, flags)
+- with os.fdopen(fd, 'w') as f:
++ try:
+ if mode is not None:
+- os.chmod(path, mode)
+- f.truncate(size)
++ os.fchmod(fd, mode)
++ os.ftruncate(fd, size)
++ finally:
++ os.close(fd)
+
+
+ def readLines(path):
+--
+1.8.3.1
+
diff --git a/vdsm.spec b/vdsm.spec
index c501e8a..f494557 100644
--- a/vdsm.spec
+++ b/vdsm.spec
@@ -46,7 +46,7 @@
Name: %{vdsm_name}
Version: 4.12.1
-Release: 3%{?vdsm_relvtag}%{?dist}%{?extra_release}
+Release: 4%{?vdsm_relvtag}%{?dist}%{?extra_release}
Summary: Virtual Desktop Server Manager
Group: Applications/System
@@ -66,6 +66,8 @@ Patch2: 0002-vdsmd.init-Add-service-is-managed-in-shutdown_confli.patch
Patch3: 0003-imageSharing-return-proper-size-in-httpGetSize.patch
Patch4: 0004-Require-libvirt-that-allows-vmUpdateDevice.patch
Patch5: 0005-vm.Vm._getUnderlyingDriveInfo-extract-path-of-gluste.patch
+Patch6: 0006-remoteFileHandler-Add-create-exclusive-option-for-tr.patch
+Patch7: 0007-oop-improve-safety-for-truncateFile.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@@ -562,6 +564,9 @@ Gluster plugin enables VDSM to serve Gluster functionalities.
%patch3 -p1
%patch4 -p1
%patch5 -p1
+%patch6 -p1
+%patch7 -p1
+
%if 0%{?rhel} == 6
sed -i '/ su /d' vdsm/vdsm-logrotate.conf.in
%endif
@@ -1316,6 +1321,10 @@ exit 0
%attr(755, root, root) %{python_sitearch}/cpopen/cpopen.so*
%changelog
+* Thu Oct 10 2013 Douglas Schilling Landgraf <dougsland at redhat.com> 4.12.1-4
+- remoteFileHandler: Add create exclusive option for truncateFile (BZ#979193)
+- oop: improve safety for truncateFile
+
* Tue Oct 08 2013 Douglas Schilling Landgraf <dougsland at redhat.com> 4.12.1-3
- vm.Vm._getUnderlyingDriveInfo: extract path of gluster disks (BZ#1007980)
- Require libvirt that allows vmUpdateDevice (BZ#1001001)
More information about the scm-commits
mailing list