Skip to content

Commit

Permalink
issue: 3958757 Change error message to warning when reading FS files
Browse files Browse the repository at this point in the history
Adjust XLIO behavior to generate warnings instead of error messages
when it is unable to access FS files. This may occur in containerized
environments. Since default values are provided, the severity of the
issue is less critical.
Change the default log severity in read_file_to_int() from VLOG_ERROR
to VLOG_WARNING,and rephrase print message for better clarity.

Signed-off-by: Bashar Abdelgafer  <babdelgafer@nvidia.com>
  • Loading branch information
BasharRadya authored and galnoam committed Jun 27, 2024
1 parent 154d051 commit 5faae56
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/core/util/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,27 +547,28 @@ int priv_read_file(const char *path, char *buf, size_t size,
int fd = SYSCALL(open, path, O_RDONLY);
BULLSEYE_EXCLUDE_BLOCK_START
if (fd < 0) {
VLOG_PRINTF(log_level, "ERROR while opening file %s (errno %d %m)", path, errno);
VLOG_PRINTF(log_level, "Couldn't open file %s (errno %d %m)", path, errno);
return -1;
}
BULLSEYE_EXCLUDE_BLOCK_END
len = SYSCALL(read, fd, buf, size);
BULLSEYE_EXCLUDE_BLOCK_START
if (len < 0) {
VLOG_PRINTF(log_level, "ERROR while reading from file %s (errno %d %m)", path, errno);
VLOG_PRINTF(log_level, "Couldn't read file %s (errno %d %m)", path, errno);
}
BULLSEYE_EXCLUDE_BLOCK_END
SYSCALL(close, fd);
return len;
}

int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level)
int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level /*VLOG_WARNING*/)
{
int value = -1;
std::ifstream file_stream(path);
if (!file_stream || !(file_stream >> value)) {
VLOG_PRINTF(log_level, "ERROR while getting int from from file %s, we'll use default %d",
path, default_value);
VLOG_PRINTF(log_level,
"Couldn't read an integer from file %s (errno %d %m), we'll use default %d",
path, errno, default_value);
return default_value;
}
return value;
Expand Down
4 changes: 2 additions & 2 deletions src/core/util/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ inline int priv_safe_try_read_file(const char *path, char *buf, size_t size)

/**
* Read content of file detailed in 'path' (usually a sysfs file)
* upon failure print error
* upon failure print warning
* @return int value (atoi) of the file content, or 'default_value' upon failure
*/
int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level = VLOG_ERROR);
int read_file_to_int(const char *path, int default_value, vlog_levels_t log_level = VLOG_WARNING);

/**
* Get port number from interface name
Expand Down

0 comments on commit 5faae56

Please sign in to comment.