Streaming IO solution optimization and enhancement

Signed-off-by: wujing <wujing50@huawei.com>
This commit is contained in:
wujing 2020-12-24 16:12:57 +08:00
parent 7e088a1cf6
commit a154ac0831
4 changed files with 145 additions and 1 deletions

View File

@ -0,0 +1,92 @@
From d19376d8735651b23394cdeb560cbebe374c8bb9 Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Wed, 21 Oct 2020 15:34:50 +0800
Subject: [PATCH 2/3] Streaming IO solution optimization and enhancement
Signed-off-by: wujing <wujing50@huawei.com>
---
src/lxc/file_utils.c | 27 +++++++++++++++++++++++++++
src/lxc/file_utils.h | 4 ++++
src/lxc/terminal.c | 14 ++++++++++----
3 files changed, 41 insertions(+), 4 deletions(-)
diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c
index 1689cbaa..2dbbbd3b 100644
--- a/src/lxc/file_utils.c
+++ b/src/lxc/file_utils.c
@@ -122,6 +122,33 @@ int lxc_read_from_file(const char *filename, void *buf, size_t count)
return ret;
}
+#ifdef HAVE_ISULAD
+ssize_t lxc_write_nointr_for_fifo(int fd, const void *buf, size_t count)
+{
+ ssize_t nret = 0;
+ ssize_t nwritten;
+
+ if (buf == NULL) {
+ return -1;
+ }
+
+ for (nwritten = 0; nwritten < count;) {
+ nret = write(fd, buf + nwritten, count - nwritten);
+ if (nret < 0) {
+ if (errno == EINTR || errno == EAGAIN) {
+ continue;
+ } else {
+ return nret;
+ }
+ } else {
+ nwritten += nret;
+ }
+ }
+
+ return nwritten;
+}
+#endif
+
ssize_t lxc_write_nointr(int fd, const void *buf, size_t count)
{
ssize_t ret;
diff --git a/src/lxc/file_utils.h b/src/lxc/file_utils.h
index 6d5dbf68..29162b3f 100644
--- a/src/lxc/file_utils.h
+++ b/src/lxc/file_utils.h
@@ -58,4 +58,8 @@ extern FILE *fdopen_cached(int fd, const char *mode, void **caller_freed_buffer)
extern FILE *fopen_cached(const char *path, const char *mode,
void **caller_freed_buffer);
+#ifdef HAVE_ISULAD
+extern ssize_t lxc_write_nointr_for_fifo(int fd, const void *buf, size_t count);
+#endif
+
#endif /* __LXC_FILE_UTILS_H */
diff --git a/src/lxc/terminal.c b/src/lxc/terminal.c
index 7441de79..a4c6ad0c 100644
--- a/src/lxc/terminal.c
+++ b/src/lxc/terminal.c
@@ -683,11 +683,17 @@ static void lxc_forward_data_to_fifo(struct lxc_list *list, bool is_err, const c
lxc_list_for_each_safe(it, list, next) {
elem = it->elem;
if (is_err) {
- if (elem->err_fd >= 0)
- lxc_write_nointr(elem->err_fd, buf, r);
+ if (elem->err_fd >= 0) {
+ if (lxc_write_nointr_for_fifo(elem->err_fd, buf, r) < 0) {
+ ERROR("Failed to write to fifo fd %d with error: %s", elem->err_fd, strerror(errno));
+ }
+ }
} else {
- if (elem->out_fd >= 0)
- lxc_write_nointr(elem->out_fd, buf, r);
+ if (elem->out_fd >= 0) {
+ if (lxc_write_nointr_for_fifo(elem->out_fd, buf, r) < 0) {
+ ERROR("Failed to write to fifo fd %d with error: %s", elem->out_fd, strerror(errno));
+ }
+ }
}
}
--
2.25.1

View File

@ -0,0 +1,40 @@
From 1912d374c6fbabc9ac549011cd863c28ee1a55fa Mon Sep 17 00:00:00 2001
From: wujing <wujing50@huawei.com>
Date: Thu, 24 Dec 2020 11:23:01 +0800
Subject: [PATCH 3/3] avoid using void pointers in caclulation
Signed-off-by: wujing <wujing50@huawei.com>
---
src/lxc/file_utils.c | 2 +-
src/lxc/file_utils.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c
index 2dbbbd3b..681207b2 100644
--- a/src/lxc/file_utils.c
+++ b/src/lxc/file_utils.c
@@ -123,7 +123,7 @@ int lxc_read_from_file(const char *filename, void *buf, size_t count)
}
#ifdef HAVE_ISULAD
-ssize_t lxc_write_nointr_for_fifo(int fd, const void *buf, size_t count)
+ssize_t lxc_write_nointr_for_fifo(int fd, const char *buf, size_t count)
{
ssize_t nret = 0;
ssize_t nwritten;
diff --git a/src/lxc/file_utils.h b/src/lxc/file_utils.h
index 29162b3f..cb959bfb 100644
--- a/src/lxc/file_utils.h
+++ b/src/lxc/file_utils.h
@@ -59,7 +59,7 @@ extern FILE *fopen_cached(const char *path, const char *mode,
void **caller_freed_buffer);
#ifdef HAVE_ISULAD
-extern ssize_t lxc_write_nointr_for_fifo(int fd, const void *buf, size_t count);
+extern ssize_t lxc_write_nointr_for_fifo(int fd, const char *buf, size_t count);
#endif
#endif /* __LXC_FILE_UTILS_H */
--
2.25.1

View File

@ -1,4 +1,4 @@
%global _release 2020121501
%global _release 2020122401
Name: lxc
Version: 4.0.3
@ -22,6 +22,8 @@ Patch0011: 0011-rootfs-add-make-private-for-root.path-parent.patch
Patch0012: 0012-mount-make-possible-to-bind-mount-proc-and-sys-fs.patch
Patch0013: 0013-use-path-based-unix-domain-sockets-instead-of-abstra.patch
Patch0014: 0014-api-add-get-container-metrics-api.patch
Patch0015: 0015-Streaming-IO-solution-optimization-and-enhancement.patch
Patch0016: 0016-avoid-using-void-pointers-in-caclulation.patch
BuildRequires: systemd-units git libtool graphviz docbook2X doxygen chrpath
BuildRequires: pkgconfig(libseccomp)
@ -193,6 +195,12 @@ make check
%{_mandir}/*/man7/%{name}*
%changelog
* Thu Dec 24 2020 wujing <wujing50@huawei.com> - 4.0.3-2020122401
- Type:enhancement
- ID:NA
- SUG:NA
- DESC: Streaming IO solution optimization and enhancement
* Tue Dec 15 2020 lifeng <lifeng68@huawei.com> - 4.0.3-2020121501
- Type:enhancement
- ID:NA

View File

@ -10,3 +10,7 @@
0010-cgfsng-adjust-log-level-from-error-to-warn.patch
0011-rootfs-add-make-private-for-root.path-parent.patch
0012-mount-make-possible-to-bind-mount-proc-and-sys-fs.patch
0013-use-path-based-unix-domain-sockets-instead-of-abstra.patch
0014-api-add-get-container-metrics-api.patch
0015-Streaming-IO-solution-optimization-and-enhancement.patch
0016-avoid-using-void-pointers-in-caclulation.patch