From ba2083708acd33a7a1e4f40ed8f3aacbc9457e0e Mon Sep 17 00:00:00 2001 From: Yan Burman Date: Wed, 28 Jan 2015 12:15:35 +0000 Subject: [PATCH] isert: Make the login character device more posix compliant This fixes a case where iscsi-scstd will go into busy-waiting loop on some occasions because it would not detect disconnect correctly Signed-off-by: Yan Burman git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/iser@5999 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- iscsi-scst/kernel/isert-scst/isert_login.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/iscsi-scst/kernel/isert-scst/isert_login.c b/iscsi-scst/kernel/isert-scst/isert_login.c index 8ee988801..eb764f2aa 100644 --- a/iscsi-scst/kernel/isert-scst/isert_login.c +++ b/iscsi-scst/kernel/isert-scst/isert_login.c @@ -555,6 +555,9 @@ static ssize_t isert_read(struct file *filp, char __user *buf, size_t count, struct isert_conn_dev *dev = filp->private_data; size_t to_read; + if (dev->state == CS_DISCONNECTED) + return -EPIPE; + if (will_read_block(dev)) { int ret; if (filp->f_flags & O_NONBLOCK) @@ -565,9 +568,6 @@ static ssize_t isert_read(struct file *filp, char __user *buf, size_t count, return ret; } - if (dev->state == CS_DISCONNECTED) - return -EPIPE; - to_read = min(count, dev->read_len); if (copy_to_user(buf, dev->read_buf, to_read)) return -EFAULT; @@ -769,11 +769,13 @@ static unsigned int isert_poll(struct file *filp, poll_wait(filp, &dev->waitqueue, wait); if (!dev->conn) - mask |= POLLHUP | POLLERR; - if (!will_read_block(dev)) - mask |= POLLIN | POLLRDNORM; + mask |= POLLHUP | POLLIN; + else { + if (!will_read_block(dev)) + mask |= POLLIN | POLLRDNORM; - mask |= POLLOUT | POLLWRNORM; + mask |= POLLOUT | POLLWRNORM; + } return mask; }