Skip to content

Commit

Permalink
Merge pull request #5988 from grom72/core-log-warning
Browse files Browse the repository at this point in the history
Core log warning
  • Loading branch information
janekmi authored Feb 5, 2024
2 parents e67b654 + 506a7ff commit 155f1df
Show file tree
Hide file tree
Showing 52 changed files with 233 additions and 163 deletions.
40 changes: 22 additions & 18 deletions src/common/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ util_file_map_whole(const char *path)

ssize_t size = util_fd_get_size(fd);
if (size < 0) {
LOG(2, "cannot determine file length \"%s\"", path);
CORE_LOG_ERROR("cannot determine file length \"%s\"", path);
goto out;
}

addr = util_map(fd, 0, (size_t)size, MAP_SHARED, 0, 0, NULL);
if (addr == NULL) {
LOG(2, "failed to map entire file \"%s\"", path);
CORE_LOG_ERROR("failed to map entire file \"%s\"", path);
goto out;
}

Expand Down Expand Up @@ -247,27 +247,29 @@ util_file_zero(const char *path, os_off_t off, size_t len)

ssize_t size = util_fd_get_size(fd);
if (size < 0) {
LOG(2, "cannot determine file length \"%s\"", path);
CORE_LOG_ERROR("cannot determine file length \"%s\"", path);
ret = -1;
goto out;
}

if (off > size) {
LOG(2, "offset beyond file length, %ju > %ju", off, size);
CORE_LOG_ERROR("offset beyond file length, %ju > %ju", off,
size);
ret = -1;
goto out;
}

if ((size_t)off + len > (size_t)size) {
LOG(2, "requested size of write goes beyond the file length, "
"%zu > %zu", (size_t)off + len, size);
CORE_LOG_WARNING(
"requested size of write goes beyond the file length, %zu > %zu",
(size_t)off + len, size);
LOG(4, "adjusting len to %zu", size - off);
len = (size_t)(size - off);
}

void *addr = util_map(fd, 0, (size_t)size, MAP_SHARED, 0, 0, NULL);
if (addr == NULL) {
LOG(2, "failed to map entire file \"%s\"", path);
CORE_LOG_ERROR("failed to map entire file \"%s\"", path);
ret = -1;
goto out;
}
Expand Down Expand Up @@ -302,7 +304,7 @@ util_file_pwrite(const char *path, const void *buffer, size_t size,
if (type == TYPE_NORMAL) {
int fd = util_file_open(path, NULL, 0, O_RDWR);
if (fd < 0) {
LOG(2, "failed to open file \"%s\"", path);
CORE_LOG_ERROR("failed to open file \"%s\"", path);
return -1;
}

Expand All @@ -315,21 +317,22 @@ util_file_pwrite(const char *path, const void *buffer, size_t size,

ssize_t file_size = util_file_get_size(path);
if (file_size < 0) {
LOG(2, "cannot determine file length \"%s\"", path);
CORE_LOG_ERROR("cannot determine file length \"%s\"", path);
return -1;
}

size_t max_size = (size_t)(file_size - offset);
if (size > max_size) {
LOG(2, "requested size of write goes beyond the file length, "
"%zu > %zu", size, max_size);
CORE_LOG_WARNING(
"requested size of write goes beyond the file length, %zu > %zu",
size, max_size);
LOG(4, "adjusting size to %zu", max_size);
size = max_size;
}

void *addr = util_file_map_whole(path);
if (addr == NULL) {
LOG(2, "failed to map entire file \"%s\"", path);
CORE_LOG_ERROR("failed to map entire file \"%s\"", path);
return -1;
}

Expand All @@ -355,7 +358,7 @@ util_file_pread(const char *path, void *buffer, size_t size,
if (type == TYPE_NORMAL) {
int fd = util_file_open(path, NULL, 0, O_RDONLY);
if (fd < 0) {
LOG(2, "failed to open file \"%s\"", path);
CORE_LOG_ERROR("failed to open file \"%s\"", path);
return -1;
}

Expand All @@ -368,21 +371,22 @@ util_file_pread(const char *path, void *buffer, size_t size,

ssize_t file_size = util_file_get_size(path);
if (file_size < 0) {
LOG(2, "cannot determine file length \"%s\"", path);
CORE_LOG_ERROR("cannot determine file length \"%s\"", path);
return -1;
}

size_t max_size = (size_t)(file_size - offset);
if (size > max_size) {
LOG(2, "requested size of read goes beyond the file length, "
"%zu > %zu", size, max_size);
CORE_LOG_WARNING(
"requested size of read goes beyond the file length, %zu > %zu",
size, max_size);
LOG(4, "adjusting size to %zu", max_size);
size = max_size;
}

void *addr = util_file_map_whole(path);
if (addr == NULL) {
LOG(2, "failed to map entire file \"%s\"", path);
CORE_LOG_ERROR("failed to map entire file \"%s\"", path);
return -1;
}

Expand Down Expand Up @@ -540,7 +544,7 @@ util_unlink_flock(const char *path)

int fd = util_file_open(path, NULL, 0, O_RDONLY);
if (fd < 0) {
LOG(2, "failed to open file \"%s\"", path);
CORE_LOG_ERROR("failed to open file \"%s\"", path);
return -1;
}

Expand Down
4 changes: 2 additions & 2 deletions src/common/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ util_mmap_init(void)
unsigned long long val = strtoull(e, &endp, 16);

if (errno || endp == e) {
LOG(2, "Invalid PMEM_MMAP_HINT");
CORE_LOG_WARNING("Invalid PMEM_MMAP_HINT");
} else if (os_access(OS_MAPFILE, R_OK)) {
LOG(2, "No /proc, PMEM_MMAP_HINT ignored");
CORE_LOG_WARNING("No /proc, PMEM_MMAP_HINT ignored");
} else {
Mmap_hint = (void *)val;
Mmap_no_random = 1;
Expand Down
5 changes: 3 additions & 2 deletions src/common/os_deep_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ os_deep_type(const struct map_tracker *mt, void *addr, size_t len)
"deep_flush not supported");
} else {
errno = pmem2_err_to_errno(ret);
LOG(2, "cannot write to deep_flush"
"in region %u", mt->region_id);
CORE_LOG_ERROR(
"cannot write to deep_flush in region %u",
mt->region_id);
}
return -1;
}
Expand Down
70 changes: 41 additions & 29 deletions src/common/set.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ util_poolset_open(struct pool_set *set)
{
for (unsigned r = 0; r < set->nreplicas; ++r) {
if (util_replica_open(set, r, MAP_SHARED)) {
LOG(2, "replica open failed: replica %u", r);
CORE_LOG_ERROR("replica open failed: replica %u", r);
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -1050,9 +1050,9 @@ util_poolset_directory_load(struct pool_replica **repp, const char *directory)

ssize_t size = util_file_get_size(entry->path);
if (size < 0) {
LOG(2,
"cannot read size of file (%s) in a poolset directory",
entry->path);
CORE_LOG_ERROR(
"cannot read size of file (%s) in a poolset directory",
entry->path);
goto err;
}

Expand Down Expand Up @@ -1481,7 +1481,8 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part)
part->fd = util_file_create(part->path, part->filesize,
minsize);
if (part->fd == -1) {
LOG(2, "failed to create file: %s", part->path);
CORE_LOG_ERROR("failed to create file: %s",
part->path);
return -1;
}
part->created = 1;
Expand All @@ -1490,7 +1491,7 @@ util_part_open(struct pool_set_part *part, size_t minsize, int create_part)
int flags = O_RDWR;
part->fd = util_file_open(part->path, &size, minsize, flags);
if (part->fd == -1) {
LOG(2, "failed to open file: %s", part->path);
CORE_LOG_ERROR("failed to open file: %s", part->path);
return -1;
}

Expand Down Expand Up @@ -1968,7 +1969,8 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags)
/* map the first part and reserve space for remaining parts */
if (util_map_part(&rep->part[0], addr, rep->resvsize, 0,
flags, 0) != 0) {
LOG(2, "pool mapping failed - replica #%u part #0",
CORE_LOG_ERROR(
"pool mapping failed - replica #%u part #0",
repidx);
return -1;
}
Expand Down Expand Up @@ -1997,8 +1999,9 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags)
*/
if ((errno == EINVAL) &&
(remaining_retries > 0)) {
LOG(2, "usable space mapping failed - "
"part #%d - retrying", p);
CORE_LOG_WARNING(
"usable space mapping failed - part #%d - retrying",
p);
retry_for_contiguous_addr = 1;
remaining_retries--;

Expand All @@ -2010,7 +2013,8 @@ util_replica_map_local(struct pool_set *set, unsigned repidx, int flags)
munmap(addr, rep->resvsize - mapsize);
break;
}
LOG(2, "usable space mapping failed - part #%d",
CORE_LOG_ERROR(
"usable space mapping failed - part #%d",
p);
goto err;
}
Expand Down Expand Up @@ -2078,15 +2082,16 @@ util_replica_init_headers_local(struct pool_set *set, unsigned repidx,
/* map all headers - don't care about the address */
for (unsigned p = 0; p < rep->nhdrs; p++) {
if (util_map_hdr(&rep->part[p], flags, 0) != 0) {
LOG(2, "header mapping failed - part #%d", p);
CORE_LOG_ERROR("header mapping failed - part #%d", p);
goto err;
}
}

/* create headers, set UUID's */
for (unsigned p = 0; p < rep->nhdrs; p++) {
if (util_header_create(set, repidx, p, attr, 0) != 0) {
LOG(2, "header creation failed - part #%d", p);
CORE_LOG_ERROR("header creation failed - part #%d",
p);
goto err;
}
}
Expand Down Expand Up @@ -2122,7 +2127,7 @@ util_replica_create_local(struct pool_set *set, unsigned repidx, int flags,
*/
if (PART(REP(set, repidx), 0)->addr == NULL) {
if (util_replica_map_local(set, repidx, flags) != 0) {
LOG(2, "replica #%u map failed", repidx);
CORE_LOG_ERROR("replica #%u map failed", repidx);
return -1;
}
}
Expand All @@ -2131,7 +2136,8 @@ util_replica_create_local(struct pool_set *set, unsigned repidx, int flags,
return 0;

if (util_replica_init_headers_local(set, repidx, flags, attr) != 0) {
LOG(2, "replica #%u headers initialization failed", repidx);
CORE_LOG_ERROR("replica #%u headers initialization failed",
repidx);
return -1;
}
return 0;
Expand Down Expand Up @@ -2389,7 +2395,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path,
int ret = util_poolset_create_set(setp, path, poolsize, minsize,
IGNORE_SDS(attr));
if (ret < 0) {
LOG(2, "cannot create pool set -- '%s'", path);
CORE_LOG_ERROR("cannot create pool set -- '%s'", path);
return -1;
}

Expand Down Expand Up @@ -2476,7 +2482,8 @@ util_pool_create_uuids(struct pool_set **setp, const char *path,
/* generate pool set UUID */
ret = util_uuid_generate(set->uuid);
if (ret < 0) {
LOG(2, "cannot generate pool set UUID");
CORE_LOG_ERROR(
"cannot generate pool set UUID");
goto err_poolset;
}
}
Expand All @@ -2487,8 +2494,8 @@ util_pool_create_uuids(struct pool_set **setp, const char *path,
for (unsigned i = 0; i < rep->nhdrs; i++) {
ret = util_uuid_generate(rep->part[i].uuid);
if (ret < 0) {
LOG(2,
"cannot generate pool set part UUID");
CORE_LOG_ERROR(
"cannot generate pool set part UUID");
goto err_poolset;
}
}
Expand All @@ -2514,7 +2521,7 @@ util_pool_create_uuids(struct pool_set **setp, const char *path,
for (unsigned r = 0; r < set->nreplicas; r++) {
if (util_replica_create_local(set, r, flags, attr) !=
0) {
LOG(2, "replica #%u creation failed", r);
CORE_LOG_ERROR("replica #%u creation failed", r);
goto err_create;
}
}
Expand Down Expand Up @@ -2591,7 +2598,8 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags)
/* map the first part and reserve space for remaining parts */
if (util_map_part(&rep->part[0], addr, rep->resvsize, 0,
flags, 0) != 0) {
LOG(2, "pool mapping failed - replica #%u part #0",
CORE_LOG_ERROR(
"pool mapping failed - replica #%u part #0",
repidx);
return -1;
}
Expand All @@ -2604,7 +2612,8 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags)
/* map all headers - don't care about the address */
for (unsigned p = 0; p < rep->nhdrs; p++) {
if (util_map_hdr(&rep->part[p], flags, 0) != 0) {
LOG(2, "header mapping failed - part #%d", p);
CORE_LOG_ERROR(
"header mapping failed - part #%d", p);
goto err;
}
}
Expand Down Expand Up @@ -2637,8 +2646,9 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags)
*/
if ((errno == EINVAL) &&
(remaining_retries > 0)) {
LOG(2, "usable space mapping failed - "
"part #%d - retrying", p);
CORE_LOG_WARNING(
"usable space mapping failed - part #%d - retrying",
p);
retry_for_contiguous_addr = 1;
remaining_retries--;

Expand All @@ -2649,7 +2659,8 @@ util_replica_open_local(struct pool_set *set, unsigned repidx, int flags)
rep->resvsize);
break;
}
LOG(2, "usable space mapping failed - part #%d",
CORE_LOG_ERROR(
"usable space mapping failed - part #%d",
p);
goto err;
}
Expand Down Expand Up @@ -2779,7 +2790,8 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr)
struct pool_replica *rep = set->replica[r];
for (unsigned p = 0; p < rep->nhdrs; p++) {
if (util_header_check(set, r, p, attr) != 0) {
LOG(2, "header check failed - part #%d", p);
CORE_LOG_ERROR(
"header check failed - part #%d", p);
return -1;
}
set->rdonly |= rep->part[p].rdonly;
Expand Down Expand Up @@ -2808,7 +2820,7 @@ util_replica_check(struct pool_set *set, const struct pool_attr *attr)
ASSERTne(rep->nparts, 0);
if (shutdown_state_check(&sds, &HDR(rep, 0)->sds,
rep)) {
LOG(2, "ADR failure detected");
CORE_LOG_ERROR("ADR failure detected");
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -2901,7 +2913,7 @@ util_pool_open_nocheck(struct pool_set *set, unsigned flags)

for (unsigned r = 0; r < set->nreplicas; r++) {
if (util_replica_open(set, r, mmap_flags) != 0) {
LOG(2, "replica #%u open failed", r);
CORE_LOG_ERROR("replica #%u open failed", r);
goto err_replica;
}
}
Expand Down Expand Up @@ -2992,7 +3004,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize,
int ret = util_poolset_create_set(setp, path, 0, 0,
flags & POOL_OPEN_IGNORE_SDS);
if (ret < 0) {
LOG(2, "cannot open pool set -- '%s'", path);
CORE_LOG_ERROR("cannot open pool set -- '%s'", path);
return -1;
}

Expand Down Expand Up @@ -3064,7 +3076,7 @@ util_pool_open(struct pool_set **setp, const char *path, size_t minpartsize,

for (unsigned r = 0; r < set->nreplicas; r++) {
if (util_replica_open(set, r, mmap_flags) != 0) {
LOG(2, "replica #%u open failed", r);
CORE_LOG_ERROR("replica #%u open failed", r);
goto err_replica;
}
}
Expand Down
Loading

0 comments on commit 155f1df

Please sign in to comment.