From 88a1bd75a515e348c6cd5f08e98ec9e39b7f66e8 Mon Sep 17 00:00:00 2001 From: Prashanth Pai Date: Mon, 23 May 2016 14:47:38 +0530 Subject: Don't attempt unlink on a non-existing object Problem: getxattr() and unlink() were being called on an object path which was already determined to be non-existent. This resulted in both these syscalls always failing with ENOENT when client issues DELETE request on an object that does not exist. A request to DELETE an object will incur the following DiskFile API calls in sequence: disk_file.read_metadata() disk_file.delete() The above mentioned problem manifests because Swift code invokes disk_file.delete() even when disk_file.read_metadata() has raised DiskFileNotExist. Fix: During disk_file.read_metadata(), make a note that the file does not exist. When disk_file.delete() is called, do not proceed with object deletion. Change-Id: Iaf6915197a8fced7564db8fab80e696dea080c25 Signed-off-by: Prashanth Pai Reviewed-on: http://review.gluster.org/14501 Reviewed-by: Thiago da Silva Tested-by: Thiago da Silva --- test/unit/obj/test_diskfile.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/unit') diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index eab8ebf..72db849 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -1142,3 +1142,31 @@ class TestDiskFile(unittest.TestCase): self.assertFalse(_m_do_fchown.called) assert os.path.exists(gdf._data_file) assert not os.path.exists(tmppath) + + def test_unlink_not_called_on_non_existent_object(self): + # Create container dir + cpath = os.path.join(self.td, "vol0", "container") + os.makedirs(cpath) + self.assertTrue(os.path.exists(cpath)) + + # This file does not exist + obj_path = os.path.join(cpath, "object") + self.assertFalse(os.path.exists(obj_path)) + + # Create diskfile instance and check attribute initialization + gdf = self._get_diskfile("vol0", "p57", "ufo47", "container", "object") + assert gdf._obj == "object" + assert gdf._data_file == obj_path + self.assertFalse(gdf._disk_file_does_not_exist) + + # Simulate disk file call sequence issued during DELETE request. + # And confirm that read_metadata() and unlink() is not called. + self.assertRaises(DiskFileNotExist, gdf.read_metadata) + self.assertTrue(gdf._disk_file_does_not_exist) + _m_rmd = Mock() + _m_do_unlink = Mock() + with patch("gluster.swift.obj.diskfile.read_metadata", _m_rmd): + with patch("gluster.swift.obj.diskfile.do_unlink", _m_do_unlink): + gdf.delete(0) + self.assertFalse(_m_rmd.called) + self.assertFalse(_m_do_unlink.called) -- cgit