151 lines
4.7 KiB
Diff
151 lines
4.7 KiB
Diff
From 7f99bba84646a5efe0f25f83e6c45e70537798bd Mon Sep 17 00:00:00 2001
|
||
From: liqiang <liqiang64@huawei.com>
|
||
Date: Fri, 8 Dec 2023 17:18:42 +0800
|
||
Subject: [PATCH 2/3] fix virsh console problem
|
||
|
||
Signed-off-by: liqiang <liqiang64@huawei.com>
|
||
---
|
||
qtfs/qtfs/fifo.c | 6 +++---
|
||
qtfs/qtfs/qtfs-mod.h | 1 +
|
||
qtfs/qtfs/sb.c | 1 +
|
||
qtfs/qtfs_server/server_fifo.c | 21 ++++++++++++++++-----
|
||
4 files changed, 21 insertions(+), 8 deletions(-)
|
||
|
||
diff --git a/qtfs/qtfs/fifo.c b/qtfs/qtfs/fifo.c
|
||
index 55292de..829ce66 100644
|
||
--- a/qtfs/qtfs/fifo.c
|
||
+++ b/qtfs/qtfs/fifo.c
|
||
@@ -199,8 +199,8 @@ int qtfs_fifo_release(struct inode *inode, struct file *file)
|
||
return 0;
|
||
}
|
||
|
||
-static __poll_t
|
||
-qtfs_fifo_poll(struct file *filp, poll_table *wait)
|
||
+__poll_t
|
||
+qtfs_poll(struct file *filp, poll_table *wait)
|
||
{
|
||
struct qtfs_inode_priv *priv = filp->f_inode->i_private;
|
||
__poll_t mask = 0;
|
||
@@ -248,5 +248,5 @@ struct file_operations qtfsfifo_ops = {
|
||
.open = qtfs_fifo_open,
|
||
.release = qtfs_fifo_release,
|
||
.llseek = no_llseek,
|
||
- .poll = qtfs_fifo_poll,
|
||
+ .poll = qtfs_poll,
|
||
};
|
||
diff --git a/qtfs/qtfs/qtfs-mod.h b/qtfs/qtfs/qtfs-mod.h
|
||
index cecce11..21d2f2d 100644
|
||
--- a/qtfs/qtfs/qtfs-mod.h
|
||
+++ b/qtfs/qtfs/qtfs-mod.h
|
||
@@ -192,6 +192,7 @@ int qtfs_utils_register(void);
|
||
void qtfs_utils_destroy(void);
|
||
void qtfs_whitelist_clearall(void);
|
||
void qtfs_whitelist_initset(void);
|
||
+__poll_t qtfs_poll(struct file *filp, poll_table *wait);
|
||
|
||
#endif
|
||
|
||
diff --git a/qtfs/qtfs/sb.c b/qtfs/qtfs/sb.c
|
||
index 79f1f89..a0d0964 100644
|
||
--- a/qtfs/qtfs/sb.c
|
||
+++ b/qtfs/qtfs/sb.c
|
||
@@ -747,6 +747,7 @@ static struct file_operations qtfs_file_ops = {
|
||
.llseek = qtfs_llseek,
|
||
.fsync = qtfs_fsync,
|
||
.unlocked_ioctl = qtfs_ioctl,
|
||
+ .poll = qtfs_poll,
|
||
};
|
||
|
||
static int qtfs_readpage(struct file *file, struct page *page)
|
||
diff --git a/qtfs/qtfs_server/server_fifo.c b/qtfs/qtfs_server/server_fifo.c
|
||
index fc4c67c..0eaadea 100644
|
||
--- a/qtfs/qtfs_server/server_fifo.c
|
||
+++ b/qtfs/qtfs_server/server_fifo.c
|
||
@@ -190,15 +190,20 @@ void fifo_suspend_event(struct fifo_event_t *evt)
|
||
|
||
static int fifo_peer_index;
|
||
static struct fifo_event_t *fifo_peer_evt[EPOLL_MAX_EVENT_NUMS];
|
||
-static int fifo_del_peer(int flag, struct fifo_event_t *peer)
|
||
+static int fifo_del_peer(int flag, struct fifo_event_t *me)
|
||
{
|
||
+ // 自己已经先被peer加过了就不必加peer了,peer此时已释放
|
||
+ for (int i = 0; i < fifo_peer_index; i++) {
|
||
+ if (fifo_peer_evt[i] == me)
|
||
+ return 0;
|
||
+ }
|
||
switch (flag) {
|
||
case FIFO_PEER_PRE:
|
||
fifo_peer_index = 0;
|
||
memset(fifo_peer_evt, 0, sizeof(struct fifo_event_t *) * EPOLL_MAX_EVENT_NUMS);
|
||
break;
|
||
case FIFO_PEER_ADD:
|
||
- fifo_peer_evt[fifo_peer_index] = peer;
|
||
+ fifo_peer_evt[fifo_peer_index] = me->peerevt;
|
||
break;
|
||
case FIFO_PEER_POST:
|
||
for (int i = 0; i < fifo_peer_index; i++) {
|
||
@@ -288,6 +293,7 @@ int fifo_proc_readable(struct fifo_event_t *evt)
|
||
char *msg;
|
||
struct qtrsp_fifo_read *rsp;
|
||
int readlen = evt->len;
|
||
+ int error_ret = FIFO_RET_SUSPEND;
|
||
if (readlen > QTFS_REQ_MAX_LEN) {
|
||
log_err("Read rsp len:%d too large!", readlen);
|
||
ret = EINVAL;
|
||
@@ -307,6 +313,8 @@ int fifo_proc_readable(struct fifo_event_t *evt)
|
||
log_err("read from fifo:%d failed, readlen:%d, errno:%d", evt->fd, readlen, errno);
|
||
ret = errno;
|
||
free(msg);
|
||
+ if (errno == EPIPE)
|
||
+ error_ret = FIFO_RET_DEL_BOTH;
|
||
goto err_ack;
|
||
}
|
||
rsp->err = 0;
|
||
@@ -327,7 +335,7 @@ err_ack:
|
||
fifo_proc_ack(evt, QTFS_REQ_READITER, evt->peerevt->fd, (char *)&errrsp, sizeof(errrsp));
|
||
} while (0);
|
||
evt->peerevt->peerevt = NULL;
|
||
- return FIFO_RET_SUSPEND;
|
||
+ return error_ret;
|
||
}
|
||
|
||
int fifo_proc_writeable(struct fifo_event_t *evt)
|
||
@@ -337,6 +345,7 @@ int fifo_proc_writeable(struct fifo_event_t *evt)
|
||
char *msg;
|
||
struct qtrsp_fifo_write rsp;
|
||
int writelen = evt->len;
|
||
+ int error_ret = FIFO_RET_SUSPEND;
|
||
if (writelen > QTFS_REQ_MAX_LEN) {
|
||
log_err("Read rsp len:%d too large!", writelen);
|
||
ret = EINVAL;
|
||
@@ -361,6 +370,8 @@ int fifo_proc_writeable(struct fifo_event_t *evt)
|
||
log_err("write to fifo failed, ret:%d errno:%d", ret, errno);
|
||
ret = errno;
|
||
free(msg);
|
||
+ if (errno == EPIPE)
|
||
+ error_ret = FIFO_RET_DEL_BOTH;
|
||
goto err_ack;
|
||
}
|
||
rsp.err = 0;
|
||
@@ -379,7 +390,7 @@ err_ack:
|
||
errrsp.len = 0;
|
||
fifo_proc_ack(evt, QTFS_REQ_WRITE, evt->peerevt->fd, (char *)&errrsp, sizeof(errrsp));
|
||
} while (0);
|
||
- return FIFO_RET_SUSPEND;
|
||
+ return error_ret;
|
||
}
|
||
|
||
// 处理读请求,读可能阻塞,因为打开时已经确定是否阻塞型,
|
||
@@ -700,7 +711,7 @@ void *fifo_server_main_thread(void *arg)
|
||
} else if (ret == FIFO_RET_DEL) {
|
||
fifo_del_event(event);
|
||
} else if (ret == FIFO_RET_DEL_BOTH) {
|
||
- fifo_del_peer(FIFO_PEER_ADD, event->peerevt);
|
||
+ fifo_del_peer(FIFO_PEER_ADD, event);
|
||
fifo_del_event(event);
|
||
}
|
||
}
|
||
--
|
||
2.37.1 (Apple Git-137.1)
|
||
|