Dima Kuznetsov has uploaded a new change for review. Change subject: utils: Remove duplicate set non-blocking functions ......................................................................
utils: Remove duplicate set non-blocking functions Current code had 2 implementations of functions that turned on the O_NONBLOCK flag on file descriptors, none of which were in lib, to avoid creating yet another implementation for lib code to use, one of existing implementations was moved to utils. Change-Id: I1fd242e8b437e485e45127d083c35957ccecf577 Signed-off-by: Dima Kuznetsov <[email protected]> --- M lib/vdsm/utils.py M vdsm/protocoldetector.py M vdsm/storage/misc.py M vdsm/storage/remoteFileHandler.py 4 files changed, 12 insertions(+), 19 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/13/29413/1 diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index 2ba5762..7d0b659 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -1141,3 +1141,11 @@ def prependDefer(self, func, *args, **kwargs): self._finally.insert(0, (func, args, kwargs)) + + +def setNonBlocking(fd): + if hasattr(fd, "fileno"): + fd = fd.fileno() + + fl = fcntl.fcntl(fd, fcntl.F_GETFL) + fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK) diff --git a/vdsm/protocoldetector.py b/vdsm/protocoldetector.py index d36f8d5..f258deb 100644 --- a/vdsm/protocoldetector.py +++ b/vdsm/protocoldetector.py @@ -19,7 +19,6 @@ # import errno -import fcntl import logging import os import select @@ -69,9 +68,9 @@ self._port = port self._read_fd, self._write_fd = os.pipe() - self._set_non_blocking(self._read_fd) + utils.setNonBlocking(self._read_fd) utils.closeOnExec(self._read_fd) - self._set_non_blocking(self._write_fd) + utils.setNonBlocking(self._write_fd) utils.closeOnExec(self._write_fd) self._socket = self._create_socket(host, port) @@ -83,11 +82,6 @@ self._next_cleanup = 0 self._required_size = None self._is_running = False - - def _set_non_blocking(self, fd): - flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) - flags = flags | os.O_NONBLOCK - fcntl.fcntl(fd, fcntl.F_SETFL, flags) @traceback(on=log.name) def serve_forever(self): diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py index d0869ee..ab2b4fd 100644 --- a/vdsm/storage/misc.py +++ b/vdsm/storage/misc.py @@ -46,7 +46,6 @@ import threading import types import weakref -import fcntl import inspect from vdsm import constants @@ -1072,11 +1071,3 @@ def deprecated(f): """Used to mark exported methods as deprecated""" return f - - -def setNonBlocking(fd): - if hasattr(fd, "fileno"): - fd = fd.fileno() - - fl = fcntl.fcntl(fd, fcntl.F_GETFL) - fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK) diff --git a/vdsm/storage/remoteFileHandler.py b/vdsm/storage/remoteFileHandler.py index ae3e54a..9bb57d3 100644 --- a/vdsm/storage/remoteFileHandler.py +++ b/vdsm/storage/remoteFileHandler.py @@ -126,8 +126,8 @@ def __init__(self, myRead, myWrite): self._myWrite = myWrite self._myRead = myRead - misc.setNonBlocking(self._myWrite) - misc.setNonBlocking(self._myRead) + utils.setNonBlocking(self._myWrite) + utils.setNonBlocking(self._myRead) self._poller = select.poll() @contextmanager -- To view, visit http://gerrit.ovirt.org/29413 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1fd242e8b437e485e45127d083c35957ccecf577 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Dima Kuznetsov <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
