Update logs

This commit is contained in:
Kamil Trzcinski
2022-04-11 13:52:46 +02:00
parent 1d6298d248
commit ae12963c6e
23 changed files with 157 additions and 167 deletions

View File

@ -84,26 +84,21 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv)
return get_time_us(CLOCK_MONOTONIC, ts, tv, 0);
}
int xioctl(const char *name, int fd, int request, void *arg)
int ioctl_retried(const char *name, int fd, int request, void *arg)
{
int retries = XIOCTL_RETRIES;
int retval = -1;
#define MAX_RETRIES 4
do {
retval = ioctl(fd, request, arg);
} while (
retval
&& retries--
&& (
errno == EINTR
|| errno == EAGAIN
|| errno == ETIMEDOUT
)
);
int retries = 4;
int ret = -1;
// cppcheck-suppress knownConditionTrueFalse
if (retval && retries <= 0) {
E_LOG_PERROR(NULL, "%s: ioctl(%08x) retried %u times; giving up", name, request, XIOCTL_RETRIES);
while (retries-- > 0) {
ret = ioctl(fd, request, arg);
if (errno != EINTR && errno != EAGAIN && errno != ETIMEDOUT)
break;
}
return retval;
if (ret && retries <= 0) {
LOG_PERROR(NULL, "%s: ioctl(%08x) retried %u times; giving up", name, request, MAX_RETRIES);
}
return ret;
}

View File

@ -38,11 +38,11 @@ bool filter_log(const char *filename);
// assumes that name is first item
#define dev_name(dev) (dev ? *(const char**)dev : "?")
#define E_LOG_ERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); goto error; } while(0)
#define E_LOG_PERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); exit(-1); } while(0)
#define E_LOG_INFO(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } while(0)
#define E_LOG_VERBOSE(dev, _msg, ...) do { if (log_options.debug || log_options.verbose || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0)
#define E_LOG_DEBUG(dev, _msg, ...) do { if (log_options.debug || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0)
#define LOG_ERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); goto error; } while(0)
#define LOG_PERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); exit(-1); } while(0)
#define LOG_INFO(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } while(0)
#define LOG_VERBOSE(dev, _msg, ...) do { if (log_options.debug || log_options.verbose || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0)
#define LOG_DEBUG(dev, _msg, ...) do { if (log_options.debug || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0)
#define CLOCK_FROM_PARAMS -1
@ -50,16 +50,11 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv);
uint64_t get_time_us(clockid_t clock, struct timespec *ts, struct timeval *tv, int64_t delays_us);
int shrink_to_block(int size, int block);
#ifndef CFG_XIOCTL_RETRIES
# define CFG_XIOCTL_RETRIES 4
#endif
#define XIOCTL_RETRIES ((unsigned)(CFG_XIOCTL_RETRIES))
int ioctl_retried(const char *name, int fd, int request, void *arg);
int xioctl(const char *name, int fd, int request, void *arg);
#define E_XIOCTL(dev, _fd, _request, _value, _msg, ...) do { \
#define ERR_IOCTL(dev, _fd, _request, _value, _msg, ...) do { \
int ret; \
if ((ret = xioctl(dev_name(dev), _fd, _request, _value)) < 0) { \
E_LOG_ERROR(dev, "xioctl(ret=%d): " _msg, ret, ##__VA_ARGS__); \
if ((ret = ioctl_retried(dev_name(dev), _fd, _request, _value)) < 0) { \
LOG_ERROR(dev, "ioctl(ret=%d): " _msg, ret, ##__VA_ARGS__); \
} \
} while(0)

View File

@ -70,7 +70,7 @@ static int parse_opt(option_t *options, const char *key)
}
}
E_LOG_DEBUG(NULL, "Parsing '%s'. Got value='%s', and option='%s'", key, value, option ? option->name : NULL);
LOG_DEBUG(NULL, "Parsing '%s'. Got value='%s', and option='%s'", key, value, option ? option->name : NULL);
if (!option || !value) {
return -EINVAL;
@ -115,7 +115,7 @@ int parse_opts(option_t *options, int argc, char *argv[])
if (key[0] == '-')
key++;
} else {
E_LOG_ERROR(NULL, "The '%s' is not option (should start with - or --).", key);
LOG_ERROR(NULL, "The '%s' is not option (should start with - or --).", key);
}
if (!strcmp(key, "help")) {
@ -125,7 +125,7 @@ int parse_opts(option_t *options, int argc, char *argv[])
int ret = parse_opt(options, key);
if (ret <= 0) {
E_LOG_ERROR(NULL, "Parsing '%s' returned '%d'.", argv[arg], ret);
LOG_ERROR(NULL, "Parsing '%s' returned '%d'.", argv[arg], ret);
}
}