Handle ENOSPC on os.close() operation

It is quite possible that errors on a previous write()
operation are first reported at the final close().

For fruther info, refer to: http://review.gluster.org/#/c/6269/

Change-Id: If0fbe2f5109d28c82cb493f2526fd5057f86b556
Signed-off-by: Prashanth Pai <ppai@redhat.com>
Reviewed-on: http://review.gluster.org/6608
Reviewed-by: Luis Pabon <lpabon@redhat.com>
Tested-by: Luis Pabon <lpabon@redhat.com>
This commit is contained in:
Prashanth Pai 2013-12-27 14:36:06 +05:30 committed by Luis Pabon
parent e280f91ff1
commit d1c7b1cc4b
2 changed files with 17 additions and 2 deletions

View File

@ -226,8 +226,14 @@ def do_close(fd):
try:
os.close(fd)
except OSError as err:
raise GlusterFileSystemOSError(
err.errno, '%s, os.close(%s)' % (err.strerror, fd))
if err.errno in (errno.ENOSPC, errno.EDQUOT):
filename = get_filename_from_fd(fd)
do_log_rl("do_close(%d) failed: %s : %s",
fd, err, filename)
raise DiskFileNoSpace()
else:
raise GlusterFileSystemOSError(
err.errno, '%s, os.close(%s)' % (err.strerror, fd))
def do_unlink(path, log=True):

View File

@ -517,6 +517,15 @@ class TestFsUtils(unittest.TestCase):
finally:
os.remove(tmpfile)
def test_do_close_err_ENOSPC(self):
def _mock_os_close_enospc(fd):
raise OSError(errno.ENOSPC, os.strerror(errno.ENOSPC))
fd, tmpfile = mkstemp()
with patch('os.close', _mock_os_close_enospc):
self.assertRaises(DiskFileNoSpace, fs.do_close, fd)
def test_do_unlink(self):
fd, tmpfile = mkstemp()
try: