Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core log error #5987

Merged
merged 8 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/common/bad_blocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@

ret = pmem2_badblock_context_new(&bbctx, src);
if (ret) {
LOG(1, "pmem2_badblock_context_new failed -- %s", file);
CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", file);

Check warning on line 151 in src/common/bad_blocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/bad_blocks.c#L151

Added line #L151 was not covered by tests
goto exit_delete_source;
}

Expand All @@ -157,7 +157,7 @@
bb.length = bbs->bbv[b].length;
ret = pmem2_badblock_clear(bbctx, &bb);
if (ret) {
LOG(1, "pmem2_badblock_clear -- %s", file);
CORE_LOG_ERROR("pmem2_badblock_clear -- %s", file);

Check warning on line 160 in src/common/bad_blocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/bad_blocks.c#L160

Added line #L160 was not covered by tests
goto exit_delete_ctx;
}
}
Expand Down Expand Up @@ -206,14 +206,14 @@

ret = pmem2_badblock_context_new(&bbctx, src);
if (ret) {
LOG(1, "pmem2_badblock_context_new failed -- %s", file);
CORE_LOG_ERROR("pmem2_badblock_context_new failed -- %s", file);

Check warning on line 209 in src/common/bad_blocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/bad_blocks.c#L209

Added line #L209 was not covered by tests
goto exit_delete_source;
}

while ((pmem2_badblock_next(bbctx, &bb)) == 0) {
ret = pmem2_badblock_clear(bbctx, &bb);
if (ret) {
LOG(1, "pmem2_badblock_clear -- %s", file);
CORE_LOG_ERROR("pmem2_badblock_clear -- %s", file);

Check warning on line 216 in src/common/bad_blocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/bad_blocks.c#L216

Added line #L216 was not covered by tests
goto exit_delete_ctx;
}
};
Expand Down Expand Up @@ -251,12 +251,13 @@

long bbsc = badblocks_count(file);
if (bbsc < 0) {
LOG(1, "counting bad blocks failed -- '%s'", file);
CORE_LOG_ERROR("counting bad blocks failed -- '%s'", file);

Check warning on line 254 in src/common/bad_blocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/bad_blocks.c#L254

Added line #L254 was not covered by tests
return -1;
}

if (bbsc > 0) {
LOG(1, "pool file '%s' contains %li bad block(s)", file, bbsc);
CORE_LOG_ERROR("pool file '%s' contains %li bad block(s)", file,

Check warning on line 259 in src/common/bad_blocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/bad_blocks.c#L259

Added line #L259 was not covered by tests
bbsc);
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ ctl_exec_query_write(void *ctx, const struct ctl_node *n,

void *real_arg = ctl_query_get_real_args(n, arg, source);
if (real_arg == NULL) {
LOG(1, "Invalid arguments");
CORE_LOG_ERROR("Invalid arguments");
return -1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/file_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@

int fd = os_open(path, O_RDONLY);
if (fd == -1) {
LOG(1, "Cannot open file %s", path);
CORE_LOG_ERROR("Cannot open file %s", path);

Check warning on line 115 in src/common/file_posix.c

View check run for this annotation

Codecov / codecov/patch

src/common/file_posix.c#L115

Added line #L115 was not covered by tests
return size;
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
void *base;
void *addr = util_map_hint(len, req_align);
if (addr == MAP_FAILED) {
LOG(1, "cannot find a contiguous region of given size");
CORE_LOG_ERROR("cannot find a contiguous region of given size");

Check warning on line 94 in src/common/mmap.c

View check run for this annotation

Codecov / codecov/patch

src/common/mmap.c#L94

Added line #L94 was not covered by tests
return NULL;
}

Expand Down
18 changes: 10 additions & 8 deletions src/common/os_deep_linux.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017-2023, Intel Corporation */
/* Copyright 2017-2024, Intel Corporation */

/*
* os_deep_linux.c -- Linux abstraction layer
Expand Down Expand Up @@ -35,7 +35,8 @@
if (ret < 0) {
if (ret == PMEM2_E_NOSUPP) {
errno = ENOTSUP;
LOG(1, "!deep_flush not supported");
CORE_LOG_ERROR_WITH_ERRNO(

Check warning on line 38 in src/common/os_deep_linux.c

View check run for this annotation

Codecov / codecov/patch

src/common/os_deep_linux.c#L38

Added line #L38 was not covered by tests
"deep_flush not supported");
} else {
errno = pmem2_err_to_errno(ret);
LOG(2, "cannot write to deep_flush"
Expand Down Expand Up @@ -122,7 +123,7 @@
return 0;

if (pmem_msync(addr, len)) {
LOG(1, "pmem_msync(%p, %lu)", addr, len);
CORE_LOG_ERROR("pmem_msync(%p, %lu)", addr, len);

Check warning on line 126 in src/common/os_deep_linux.c

View check run for this annotation

Codecov / codecov/patch

src/common/os_deep_linux.c#L126

Added line #L126 was not covered by tests
return -1;
}
return 0;
Expand Down Expand Up @@ -151,16 +152,17 @@
if (ret < 0) {
if (errno == ENOENT) {
errno = ENOTSUP;
LOG(1, "!deep_flush not supported");
CORE_LOG_ERROR_WITH_ERRNO(

Check warning on line 155 in src/common/os_deep_linux.c

View check run for this annotation

Codecov / codecov/patch

src/common/os_deep_linux.c#L155

Added line #L155 was not covered by tests
"deep_flush not supported");
} else {
LOG(1, "invalid dax_region id %u", region_id);
CORE_LOG_ERROR("invalid dax_region id %u",

Check warning on line 158 in src/common/os_deep_linux.c

View check run for this annotation

Codecov / codecov/patch

src/common/os_deep_linux.c#L158

Added line #L158 was not covered by tests
region_id);
}
return -1;
}

if (pmem2_deep_flush_write(region_id)) {
LOG(1, "pmem2_deep_flush_write(%u)",
region_id);
CORE_LOG_ERROR("pmem2_deep_flush_write(%u)", region_id);

Check warning on line 165 in src/common/os_deep_linux.c

View check run for this annotation

Codecov / codecov/patch

src/common/os_deep_linux.c#L165

Added line #L165 was not covered by tests
return -1;
}
} else {
Expand All @@ -169,7 +171,7 @@
* call msync on one page.
*/
if (pmem_msync(addr, MIN(Pagesize, len))) {
LOG(1, "pmem_msync(%p, %lu)", addr, len);
CORE_LOG_ERROR("pmem_msync(%p, %lu)", addr, len);

Check warning on line 174 in src/common/os_deep_linux.c

View check run for this annotation

Codecov / codecov/patch

src/common/os_deep_linux.c#L174

Added line #L174 was not covered by tests
return -1;
}
}
Expand Down
42 changes: 24 additions & 18 deletions src/common/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@
/* this is required only for Device DAX & memcheck */
addr = util_map_hint(hdrsize, hdrsize);
if (addr == MAP_FAILED) {
LOG(1, "cannot find a contiguous region of given size");
CORE_LOG_ERROR(

Check warning on line 183 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L183

Added line #L183 was not covered by tests
"cannot find a contiguous region of given size");
/* there's nothing we can do */
return -1;
}
Expand Down Expand Up @@ -424,8 +425,8 @@
}

if (stbuf.st_mode & ~(unsigned)S_IFMT) {
LOG(1, "file permissions changed during pool "
"initialization, file: %s (%o)",
CORE_LOG_WARNING(

Check warning on line 428 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L428

Added line #L428 was not covered by tests
"file permissions changed during pool initialization, file: %s (%o)",
part->path,
stbuf.st_mode & ~(unsigned)S_IFMT);
}
Expand Down Expand Up @@ -1959,7 +1960,8 @@
/* determine a hint address for mmap() */
addr = util_map_hint(rep->resvsize, 0);
if (addr == MAP_FAILED) {
LOG(1, "cannot find a contiguous region of given size");
CORE_LOG_ERROR(

Check warning on line 1963 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L1963

Added line #L1963 was not covered by tests
"cannot find a contiguous region of given size");
return -1;
}

Expand Down Expand Up @@ -2434,7 +2436,7 @@
(attr->features.compat & POOL_FEAT_CHECK_BAD_BLOCKS)) {
int bbs = badblocks_check_poolset(set, 1 /* create */);
if (bbs < 0) {
LOG(1,
CORE_LOG_ERROR(

Check warning on line 2439 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L2439

Added line #L2439 was not covered by tests
"failed to check pool set for bad blocks -- '%s'",
path);
goto err_poolset_free;
Expand Down Expand Up @@ -2579,7 +2581,8 @@
if (addr == NULL)
addr = util_map_hint(rep->resvsize, 0);
if (addr == MAP_FAILED) {
LOG(1, "cannot find a contiguous region of given size");
CORE_LOG_ERROR(

Check warning on line 2584 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L2584

Added line #L2584 was not covered by tests
"cannot find a contiguous region of given size");
return -1;
}

Expand Down Expand Up @@ -2865,21 +2868,22 @@
return -1;
}
if (bfe < 0) {
LOG(1,
CORE_LOG_ERROR(

Check warning on line 2871 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L2871

Added line #L2871 was not covered by tests
"an error occurred when checking whether recovery file exists.");
return -1;
}

int bbs = badblocks_check_poolset(set, 0 /* not create */);
if (bbs < 0) {
LOG(1, "failed to check pool set for bad blocks");
CORE_LOG_ERROR(

Check warning on line 2878 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L2878

Added line #L2878 was not covered by tests
"failed to check pool set for bad blocks");
return -1;
}

if (bbs > 0) {
if (flags & POOL_OPEN_IGNORE_BAD_BLOCKS) {
LOG(1,
"WARNING: pool set contains bad blocks, ignoring");
CORE_LOG_WARNING(

Check warning on line 2885 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L2885

Added line #L2885 was not covered by tests
"pool set contains bad blocks, ignoring");
} else {
ERR_WO_ERRNO(
"pool set contains bad blocks and cannot be opened, run 'pmempool sync --bad-blocks' utility to try to recover the pool");
Expand Down Expand Up @@ -2936,14 +2940,16 @@
struct pool_set_part *part = &rep->part[p];

if (util_part_open(part, 0, 0 /* create */)) {
LOG(1, "!cannot open the part -- \"%s\"",
CORE_LOG_WARNING_W_ERRNO(
"cannot open the part -- \"%s\"",
part->path);
/* try to open the next part */
continue;
}

if (util_map_hdr(part, MAP_SHARED, 0) != 0) {
LOG(1, "header mapping failed -- \"%s\"",
CORE_LOG_ERROR(

Check warning on line 2951 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L2951

Added line #L2951 was not covered by tests
"header mapping failed -- \"%s\"",
part->path);
util_part_fdclose(part);
return -1;
Expand Down Expand Up @@ -3009,7 +3015,7 @@
uint32_t compat_features;

if (util_read_compat_features(set, &compat_features)) {
LOG(1, "reading compat features failed");
CORE_LOG_ERROR("reading compat features failed");

Check warning on line 3018 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L3018

Added line #L3018 was not covered by tests
goto err_poolset_free;
}

Expand All @@ -3024,23 +3030,23 @@
}

if (bfe < 0) {
LOG(1,
CORE_LOG_ERROR(

Check warning on line 3033 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L3033

Added line #L3033 was not covered by tests
"an error occurred when checking whether recovery file exists.");
goto err_poolset_free;
}

int bbs = badblocks_check_poolset(set, 0 /* not create */);
if (bbs < 0) {
LOG(1,
CORE_LOG_ERROR(

Check warning on line 3040 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L3040

Added line #L3040 was not covered by tests
"failed to check pool set for bad blocks -- '%s'",
path);
goto err_poolset_free;
}

if (bbs > 0) {
if (flags & POOL_OPEN_IGNORE_BAD_BLOCKS) {
LOG(1,
"WARNING: pool set contains bad blocks, ignoring -- '%s'",
CORE_LOG_WARNING(

Check warning on line 3048 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L3048

Added line #L3048 was not covered by tests
"pool set contains bad blocks, ignoring -- '%s'",
path);
} else {
ERR_WO_ERRNO(
Expand Down Expand Up @@ -3295,7 +3301,7 @@
replica_id, part, (void *)range_start, range_len);
if (os_part_deep_common(rep, p, (void *)range_start,
range_len, flush)) {
LOG(1, "os_part_deep_common(%p, %p, %lu)",
CORE_LOG_ERROR("os_part_deep_common(%p, %p, %lu)",

Check warning on line 3304 in src/common/set.c

View check run for this annotation

Codecov / codecov/patch

src/common/set.c#L3304

Added line #L3304 was not covered by tests
part, (void *)range_start, range_len);
return -1;
}
Expand Down
5 changes: 3 additions & 2 deletions src/common/set_badblocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
}

if (cfcb.n_files_bbs) {
LOG(1, "%i pool file(s) contain bad blocks", cfcb.n_files_bbs);
CORE_LOG_ERROR("%i pool file(s) contain bad blocks",

Check warning on line 86 in src/common/set_badblocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/set_badblocks.c#L86

Added line #L86 was not covered by tests
cfcb.n_files_bbs);
set->has_bad_blocks = 1;
}

Expand Down Expand Up @@ -209,7 +210,7 @@
char *rec_file =
badblocks_recovery_file_alloc(set->path, r, p);
if (rec_file == NULL) {
LOG(1,
CORE_LOG_ERROR(

Check warning on line 213 in src/common/set_badblocks.c

View check run for this annotation

Codecov / codecov/patch

src/common/set_badblocks.c#L213

Added line #L213 was not covered by tests
"allocating name of bad block recovery file failed");
return -1;
}
Expand Down
57 changes: 51 additions & 6 deletions src/core/log_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
#ifndef CORE_LOG_INTERNAL_H
#define CORE_LOG_INTERNAL_H

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif

#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>

#ifdef ATOMIC_OPERATIONS_SUPPORTED
#include <stdatomic.h>
#endif /* ATOMIC_OPERATIONS_SUPPORTED */
Expand Down Expand Up @@ -147,13 +144,26 @@ void core_log_default_function(void *context, enum core_log_level level,
} while (0)

#define CORE_LOG_MAX_ERR_MSG 128
#ifdef _GNU_SOURCE
#define CORE_LOG_FATAL_W_ERRNO(format, ...) \
do { \
char buff[CORE_LOG_MAX_ERR_MSG]; \
CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \
strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \
abort(); \
} while (0)
#else
#define CORE_LOG_FATAL_W_ERRNO(format, ...) \
do { \
char buff[CORE_LOG_MAX_ERR_MSG]; \
uint64_t ret = (uint64_t)strerror_r(errno, buff, \
CORE_LOG_MAX_ERR_MSG); \
ret = ret; \
CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \
buff); \
abort(); \
} while (0)
#endif

#define CORE_LOG_ALWAYS(format, ...) \
CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__)
Expand All @@ -163,8 +173,43 @@ void core_log_default_function(void *context, enum core_log_level level,
* 'f' stands here for 'function' or 'format' where the latter may accept
* additional arguments.
*/
#define CORE_LOG_ERROR_WITH_ERRNO(f, ...) \
CORE_LOG_ERROR(f ": %s", ##__VA_ARGS__, strerror(errno))
#ifdef _GNU_SOURCE
#define CORE_LOG_ERROR_WITH_ERRNO(format, ...) \
do { \
char buff[CORE_LOG_MAX_ERR_MSG]; \
CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \
strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \
} while (0)
#else
#define CORE_LOG_ERROR_WITH_ERRNO(format, ...) \
do { \
char buff[CORE_LOG_MAX_ERR_MSG]; \
uint64_t ret = (uint64_t)strerror_r(errno, buff, \
CORE_LOG_MAX_ERR_MSG); \
ret = ret; \
CORE_LOG(CORE_LOG_LEVEL_ERROR, format ": %s", ##__VA_ARGS__, \
buff); \
} while (0)
#endif

#ifdef _GNU_SOURCE
#define CORE_LOG_WARNING_W_ERRNO(format, ...) \
do { \
char buff[CORE_LOG_MAX_ERR_MSG]; \
CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \
strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \
} while (0)
#else
#define CORE_LOG_WARNING_W_ERRNO(format, ...) \
do { \
char buff[CORE_LOG_MAX_ERR_MSG]; \
uint64_t ret = (uint64_t)strerror_r(errno, buff, \
CORE_LOG_MAX_ERR_MSG); \
ret = ret; \
CORE_LOG(CORE_LOG_LEVEL_WARNING, format ": %s", ##__VA_ARGS__, \
buff); \
} while (0)
#endif

static inline int
core_log_error_translate(int ret)
Expand Down
Loading
Loading