Skip to content

Commit

Permalink
common: convert LOG(2,...) into CORE_LOG_WARNING()
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Gromadzki <tomasz.gromadzki@intel.com>
  • Loading branch information
grom72 committed Jan 29, 2024
1 parent bf45066 commit a5ffeee
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 105 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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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_WARNING("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 @@ -38,8 +38,9 @@ os_deep_type(const struct map_tracker *mt, void *addr, size_t len)
CORE_LOG_ERROR("!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_WARNING(
"cannot write to deep_flush in region %u",
mt->region_id);
}
return -1;
}
Expand Down
68 changes: 40 additions & 28 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_WARNING("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_WARNING(
"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_WARNING("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_WARNING("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_WARNING(
"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_WARNING(
"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_WARNING("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_WARNING("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_WARNING("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_WARNING("replica #%u headers initialization failed",
repidx);
return -1;
}
return 0;
Expand Down Expand Up @@ -2388,7 +2394,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_WARNING("cannot create pool set -- '%s'", path);
return -1;
}

Expand Down Expand Up @@ -2475,7 +2481,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_WARNING(
"cannot generate pool set UUID");
goto err_poolset;
}
}
Expand All @@ -2486,7 +2493,7 @@ 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,
CORE_LOG_WARNING(
"cannot generate pool set part UUID");
goto err_poolset;
}
Expand All @@ -2513,7 +2520,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_WARNING("replica #%u creation failed", r);
goto err_create;
}
}
Expand Down Expand Up @@ -2590,7 +2597,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_WARNING(
"pool mapping failed - replica #%u part #0",
repidx);
return -1;
}
Expand All @@ -2603,7 +2611,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_WARNING(
"header mapping failed - part #%d", p);
goto err;
}
}
Expand Down Expand Up @@ -2636,8 +2645,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 @@ -2648,7 +2658,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_WARNING(
"usable space mapping failed - part #%d",
p);
goto err;
}
Expand Down Expand Up @@ -2778,7 +2789,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_WARNING(
"header check failed - part #%d", p);
return -1;
}
set->rdonly |= rep->part[p].rdonly;
Expand Down Expand Up @@ -2807,7 +2819,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_WARNING("ADR failure detected");
errno = EINVAL;
return -1;
}
Expand Down Expand Up @@ -2900,7 +2912,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_WARNING("replica #%u open failed", r);
goto err_replica;
}
}
Expand Down Expand Up @@ -2991,7 +3003,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_WARNING("cannot open pool set -- '%s'", path);
return -1;
}

Expand Down Expand Up @@ -3063,7 +3075,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_WARNING("replica #%u open failed", r);
goto err_replica;
}
}
Expand Down
Loading

0 comments on commit a5ffeee

Please sign in to comment.