This is an automated email from the ASF dual-hosted git repository.

jvanderzee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new a0ee91fd88 Do not retry to open cache store on ENOMEM (#11526)
a0ee91fd88 is described below

commit a0ee91fd88bcb8636fc0626baaf4c2bbcd6c0036
Author: JosiahWI <[email protected]>
AuthorDate: Wed Jul 10 14:22:06 2024 -0500

    Do not retry to open cache store on ENOMEM (#11526)
    
    * Add `safe_open` function to tscore
    
    This is intended to replace `SocketManager::open`. The important difference
    is that we only retry the `open` call if it is interrupted by a signal. The
    `SocketManager::open` call will also retry it if there is insufficient 
memory,
    but that is not likely to be a transient condition.
    
    For consistency, we use a similar implementation style to the other safe_
    utilities in tscore (see `ink_sock.cc`).
    
    * Do not retry to open cache store on ENOMEM
    
    The `SocketManager::open` function will indefinitely retry to open the file
    if there is insufficient memory. We are unlikely to suddenly have enough
    memory, so it doesn't make sense to keep retrying. If we don't have enough
    memory to open the file, we now fail.
    
    * Remove `SocketManager::open`
    
    This function is no longer used in the codebase, and has nothing to do with
    sockets. The `open` POSIX call that this function wraps is used to open 
files
    and pipes.
    
    * Implement changes requested by Walt Keras
    
     * Remove the redundant anonymous namespace.
---
 include/iocore/eventsystem/SocketManager.h   |  5 -----
 include/tscore/ink_file.h                    |  6 +++++-
 src/iocore/cache/Store.cc                    |  2 +-
 src/iocore/eventsystem/P_UnixSocketManager.h | 14 --------------
 src/tscore/ink_file.cc                       | 15 +++++++++++++++
 5 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/include/iocore/eventsystem/SocketManager.h 
b/include/iocore/eventsystem/SocketManager.h
index b74e445305..369e354edc 100644
--- a/include/iocore/eventsystem/SocketManager.h
+++ b/include/iocore/eventsystem/SocketManager.h
@@ -62,11 +62,6 @@ bool fastopen_supported();
 // result is the socket or -errno
 SOCKET socket(int domain = AF_INET, int type = SOCK_STREAM, int protocol = 0);
 
-const mode_t DEFAULT_OPEN_MODE{0644};
-
-// result is the fd or -errno
-int open(const char *path, int oflag = O_RDWR | O_NDELAY | O_CREAT, mode_t 
mode = DEFAULT_OPEN_MODE);
-
 // result is the number of bytes or -errno
 int64_t read(int fd, void *buf, int len, void *pOLP = nullptr);
 
diff --git a/include/tscore/ink_file.h b/include/tscore/ink_file.h
index d2e354df38..32da7b663f 100644
--- a/include/tscore/ink_file.h
+++ b/include/tscore/ink_file.h
@@ -31,7 +31,7 @@
 
 #pragma once
 
-#include "tscore/ink_config.h"
+#include "tscore/ink_platform.h"
 
 #include <cstdio>
 #include <sys/types.h>
@@ -80,6 +80,10 @@
 //
 #define INK_FILEPATH_TRUENAME 0x20
 
+inline constexpr mode_t DEFAULT_OPEN_MODE{0644};
+
+int safe_open(char const *path, int oflag = O_RDWR | O_NDELAY | O_CREAT, 
mode_t mode = DEFAULT_OPEN_MODE);
+
 int ink_fputln(FILE *stream, const char *s);
 int ink_file_fd_readline(int fd, int bufsize, char *buf);
 int ink_file_fd_writestring(int fd, const char *buf);
diff --git a/src/iocore/cache/Store.cc b/src/iocore/cache/Store.cc
index 606f12e8e2..e24803fad9 100644
--- a/src/iocore/cache/Store.cc
+++ b/src/iocore/cache/Store.cc
@@ -367,7 +367,7 @@ Span::init(const char *path, int64_t size)
   span_error_t        serr;
   ink_device_geometry geometry;
 
-  ats_scoped_fd fd(SocketManager::open(path, O_RDONLY));
+  ats_scoped_fd fd(safe_open(path, O_RDONLY));
   if (fd < 0) {
     serr = make_span_error(errno);
     Warning("unable to open '%s': %s", path, strerror(errno));
diff --git a/src/iocore/eventsystem/P_UnixSocketManager.h 
b/src/iocore/eventsystem/P_UnixSocketManager.h
index 5c65f73ad8..f75ba8252b 100644
--- a/src/iocore/eventsystem/P_UnixSocketManager.h
+++ b/src/iocore/eventsystem/P_UnixSocketManager.h
@@ -43,20 +43,6 @@
 // 1024 - stdin, stderr, stdout
 #define EPOLL_MAX_DESCRIPTOR_SIZE 32768
 
-TS_INLINE int
-SocketManager::open(const char *path, int oflag, mode_t mode)
-{
-  int s;
-  do {
-    s = ::open(path, oflag, mode);
-    if (likely(s >= 0)) {
-      break;
-    }
-    s = -errno;
-  } while (transient_error());
-  return s;
-}
-
 TS_INLINE int64_t
 SocketManager::read(int fd, void *buf, int size, void * /* pOLP ATS_UNUSED */)
 {
diff --git a/src/tscore/ink_file.cc b/src/tscore/ink_file.cc
index 69fe4b6c25..285ae3df0e 100644
--- a/src/tscore/ink_file.cc
+++ b/src/tscore/ink_file.cc
@@ -42,6 +42,21 @@ using ioctl_arg_t = union {
   off_t    off;
 };
 
+/** Open and possibly create a file.
+ *
+ * This is a wrapper for the POSIX open() call that will retry the call if a
+ * transient error occurs.
+ */
+int
+safe_open(char const *path, int oflag, mode_t mode)
+{
+  int r{-1};
+  do {
+    r = open(path, oflag, mode);
+  } while ((r < 0) && (errno == EINTR));
+  return r;
+}
+
 int
 ink_fputln(FILE *stream, const char *s)
 {

Reply via email to