Skip to content
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
2 changes: 2 additions & 0 deletions src/common/pmemcommon.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2017-2023, Intel Corporation
# Copyright 2025, Hewlett Packard Enterprise Development LP
#
# src/pmemcommon.inc -- common SOURCE definitions for PMDK libraries
#
Expand All @@ -21,6 +22,7 @@ SOURCE +=\
$(COMMON)/rand.c\
$(COMMON)/set.c\
$(COMMON)/shutdown_state.c\
$(COMMON)/shutdown_state_helper.c\
$(COMMON)/uuid.c\
$(COMMON)/uuid_linux.c\
$(PMEM2)/pmem2_utils.c\
Expand Down
59 changes: 27 additions & 32 deletions src/common/shutdown_state.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2017-2024, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* shutdown_state.c -- unsafe shudown detection
Expand All @@ -17,13 +18,10 @@
#include "bad_blocks.h"
#include "../libpmem2/pmem2_utils.h"

#define FLUSH_SDS(sds, rep) \
if ((rep) != NULL) os_part_deep_common(rep, 0, sds, sizeof(*(sds)), 1)

/*
* shutdown_state_checksum -- (internal) counts SDS checksum and flush it
* shutdown_state_checksum -- counts SDS checksum and flush it
*/
static void
void
shutdown_state_checksum(struct shutdown_state *sds, struct pool_replica *rep)
{
LOG(3, "sds %p", sds);
Expand Down Expand Up @@ -159,24 +157,6 @@ shutdown_state_clear_dirty(struct shutdown_state *sds, struct pool_replica *rep)
shutdown_state_checksum(sds, rep);
}

/*
* shutdown_state_reinit -- (internal) reinitializes shutdown_state struct
*/
static void
shutdown_state_reinit(struct shutdown_state *curr_sds,
struct shutdown_state *pool_sds, struct pool_replica *rep)
{
LOG(3, "curr_sds %p, pool_sds %p", curr_sds, pool_sds);
shutdown_state_init(pool_sds, rep);
pool_sds->uuid = htole64(curr_sds->uuid);
pool_sds->usc = htole64(curr_sds->usc);
pool_sds->dirty = 0;

FLUSH_SDS(pool_sds, rep);

shutdown_state_checksum(pool_sds, rep);
}

/*
* shutdown_state_check -- compares and fixes shutdown state
*/
Expand All @@ -186,15 +166,26 @@ shutdown_state_check(struct shutdown_state *curr_sds,
{
LOG(3, "curr_sds %p, pool_sds %p", curr_sds, pool_sds);

/*
* This is likely to occur only when the pool is being opened for
* the first time after the SHUTDOWN_STATE feature has been enabled on
* the pool, for example, via (lib)pmempool.
* Please do not confuse this with establishing SDS during creation.
*/
if (util_is_zeroed(pool_sds, sizeof(*pool_sds)) &&
!util_is_zeroed(curr_sds, sizeof(*curr_sds))) {
CORE_LOG_WARNING(
"Enabling ADR failure detection, assuming pool consistency up to this point.");
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}

bool is_uuid_correct =
le64toh(pool_sds->uuid) == le64toh(curr_sds->uuid);

bool is_uuid_usc_correct =
le64toh(pool_sds->usc) == le64toh(curr_sds->usc) &&
le64toh(pool_sds->uuid) == le64toh(curr_sds->uuid);
is_uuid_correct;

bool is_checksum_correct = util_checksum(pool_sds,
sizeof(*pool_sds), &pool_sds->checksum, 0, 0);
Expand All @@ -204,7 +195,7 @@ shutdown_state_check(struct shutdown_state *curr_sds,
if (!is_checksum_correct) {
/* the program was killed during opening or closing the pool */
CORE_LOG_WARNING(
"incorrect checksum - SDS will be reinitialized");
"The pool was not opened/closed properly - reinitializing ADR failure detection.");
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}
Expand All @@ -217,19 +208,23 @@ shutdown_state_check(struct shutdown_state *curr_sds,
* but there wasn't an ADR failure
*/
CORE_LOG_WARNING(
"the pool was not closed - SDS will be reinitialized");
"The ADR failure was detected but the pool was closed properly - reinitializing ADR failure detection.");
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}
if (dirty == 0) {
/* an ADR failure but the pool was closed */
CORE_LOG_WARNING(
"an ADR failure was detected but the pool was closed - SDS will be reinitialized");
if (is_uuid_correct)
CORE_LOG_WARNING(
"The ADR failure was detected but the pool was closed properly - reinitializing ADR failure detection.");
else
CORE_LOG_HARK(
"The pool has moved to a new location but it was closed properly - reinitializing ADR failure detection.");
shutdown_state_reinit(curr_sds, pool_sds, rep);
return 0;
}
/* an ADR failure - the pool might be corrupted */
ERR_WO_ERRNO(
"an ADR failure was detected, the pool might be corrupted");

ERR_WO_ERRNO("%s, the pool might be corrupted.", is_uuid_correct ?
"The ADR failure was detected" :
"The pool has moved to a new location while it was not closed properly");
return 1;
}
10 changes: 10 additions & 0 deletions src/common/shutdown_state.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* Copyright 2017-2020, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* shutdown_state.h -- unsafe shudown detection
Expand All @@ -23,6 +24,9 @@ struct shutdown_state {
uint64_t checksum;
};

#define FLUSH_SDS(sds, rep) \
if ((rep) != NULL) os_part_deep_common(rep, 0, sds, sizeof(*(sds)), 1)

int shutdown_state_init(struct shutdown_state *sds, struct pool_replica *rep);
int shutdown_state_add_part(struct shutdown_state *sds, int fd,
struct pool_replica *rep);
Expand All @@ -34,6 +38,12 @@ void shutdown_state_clear_dirty(struct shutdown_state *sds,
int shutdown_state_check(struct shutdown_state *curr_sds,
struct shutdown_state *pool_sds, struct pool_replica *rep);

void shutdown_state_reinit(struct shutdown_state *curr_sds,
struct shutdown_state *pool_sds, struct pool_replica *rep);

void shutdown_state_checksum(struct shutdown_state *sds,
struct pool_replica *rep);

#ifdef __cplusplus
}
#endif
Expand Down
28 changes: 28 additions & 0 deletions src/common/shutdown_state_helper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* shutdown_state_helper.c -- implementation of shutdown_state_reinit
*/

#include "out.h"
#include "os_deep.h"
#include "set.h"

/*
* shutdown_state_reinit -- reinitializes shutdown_state struct
*/
void
shutdown_state_reinit(struct shutdown_state *curr_sds,
struct shutdown_state *pool_sds, struct pool_replica *rep)
{
LOG(3, "curr_sds %p, pool_sds %p", curr_sds, pool_sds);
shutdown_state_init(pool_sds, rep);
pool_sds->uuid = htole64(curr_sds->uuid);
pool_sds->usc = htole64(curr_sds->usc);
pool_sds->dirty = 0;

FLUSH_SDS(pool_sds, rep);

shutdown_state_checksum(pool_sds, rep);
}
1 change: 1 addition & 0 deletions src/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ OTHER_TESTS = \
util_poolset_size\
util_ravl\
util_sds\
util_sds_check\
util_uuid_generate\
util_vec\
util_vecq\
Expand Down
2 changes: 2 additions & 0 deletions src/test/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ OBJS +=\
$(TOP)/src/nondebug/common/pool_hdr.o\
$(TOP)/src/nondebug/common/set.o\
$(TOP)/src/nondebug/common/shutdown_state.o\
$(TOP)/src/nondebug/common/shutdown_state_helper.o\
$(TOP)/src/nondebug/common/util.o\
$(TOP)/src/nondebug/common/util_posix.o\
$(TOP)/src/nondebug/common/uuid.o\
Expand Down Expand Up @@ -287,6 +288,7 @@ OBJS +=\
$(TOP)/src/debug/common/pool_hdr.o\
$(TOP)/src/debug/common/set.o\
$(TOP)/src/debug/common/shutdown_state.o\
$(TOP)/src/debug/common/shutdown_state_helper.o\
$(TOP)/src/debug/common/uuid.o\
$(TOP)/src/debug/common/uuid_linux.o\
$(TOP)/src/debug/libpmem2/pmem2_utils.o\
Expand Down
14 changes: 8 additions & 6 deletions src/test/core_log_max/call_all.c.generated
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ call_all_ERR_WO_ERRNO(void)
// src/common/set_badblocks.c
ERR_WO_ERRNO("part file contains bad blocks -- '%s'", _s);
// src/common/shutdown_state.c
ERR_WO_ERRNO("cannot read uuid of %d", _d);
// src/common/shutdown_state.c
ERR_WO_ERRNO("an ADR failure was detected, the pool might be corrupted");
ERR_WO_ERRNO("%s, the pool might be corrupted.", _s);
// src/common/shutdown_state.c
ERR_WO_ERRNO("Cannot read unsafe shutdown count. For more information please check https://github.com/pmem/pmdk/issues/4207");
// src/common/shutdown_state.c
ERR_WO_ERRNO("cannot read uuid of %d", _d);
// src/common/shutdown_state.c
ERR_WO_ERRNO("cannot read uuid of %d", _d);
// src/libpmem/libpmem.c
ERR_WO_ERRNO("libpmem major version mismatch (need %u, found %u)", _u, _u);
// src/libpmem/libpmem.c
Expand Down Expand Up @@ -462,11 +462,13 @@ call_all_CORE_LOG_WARNING(void)
// src/common/set.c
CORE_LOG_WARNING("file permissions changed during pool initialization, file: %s (%o)", _s, _u);
// src/common/shutdown_state.c
CORE_LOG_WARNING("incorrect checksum - SDS will be reinitialized");
CORE_LOG_WARNING("Enabling ADR failure detection, assuming pool consistency up to this point.");
// src/common/shutdown_state.c
CORE_LOG_WARNING("The pool was not opened/closed properly - reinitializing ADR failure detection.");
// src/common/shutdown_state.c
CORE_LOG_WARNING("the pool was not closed - SDS will be reinitialized");
CORE_LOG_WARNING("The ADR failure was detected but the pool was closed properly - reinitializing ADR failure detection.");
// src/common/shutdown_state.c
CORE_LOG_WARNING("an ADR failure was detected but the pool was closed - SDS will be reinitialized");
CORE_LOG_WARNING("The ADR failure was detected but the pool was closed properly - reinitializing ADR failure detection.");
// src/libpmemobj/heap.c
CORE_LOG_WARNING("failed to allocate memory block runtime tracking info");
// src/libpmemobj/heap.c
Expand Down
3 changes: 2 additions & 1 deletion src/test/core_log_max/core_log_max.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: BSD-3-Clause
/* Copyright 2024, Intel Corporation */
/* Copyright 2025, Hewlett Packard Enterprise Development LP */

/*
* core_log_max.c -- unit test to verify max size of log buffers
Expand Down Expand Up @@ -119,7 +120,7 @@ test_ERR_W_ERRNO(const struct test_case *tc, int argc, char *argv[])
return NO_ARGS_CONSUMED;
}

#define TOTAL_MESSAGE_NUM_EXPECTED 213
#define TOTAL_MESSAGE_NUM_EXPECTED 214
static int Max_message_len = 0;
static int Total_message_num = 0;
static char The_longest_message[BIG_BUF_SIZE];
Expand Down
2 changes: 2 additions & 0 deletions src/test/util_sds/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2015-2020, Intel Corporation
# Copyright 2025, Hewlett Packard Enterprise Development LP

#
# src/test/util_sds/Makefile -- shutdown_tests unit test
Expand All @@ -11,6 +12,7 @@ vpath %.c $(TOP)/src/common/
TARGET = util_sds
OBJS = util_sds.o\
shutdown_state.o\
shutdown_state_helper.o\
ut_pmem2_config.o\
ut_pmem2_source.o\
ut_pmem2_utils.o
Expand Down
1 change: 1 addition & 0 deletions src/test/util_sds/grep1.log.match
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<libpmem2>: <2> [shutdown_state.c:$(N) shutdown_state_check] Enabling ADR failure detection, assuming pool consistency up to this point.
1 change: 1 addition & 0 deletions src/test/util_sds/grep2.log.match
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<libpmem2>: <2> [shutdown_state.c:$(N) shutdown_state_check] Enabling ADR failure detection, assuming pool consistency up to this point.
2 changes: 1 addition & 1 deletion src/test/util_sds/grep3.log.match
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<libpmem2>: <2> [shutdown_state.c:$(N) shutdown_state_check] an ADR failure was detected but the pool was closed - SDS will be reinitialized
<libpmem2>: <1> [shutdown_state.c:$(N) shutdown_state_check] The pool has moved to a new location but it was closed properly - reinitializing ADR failure detection.
2 changes: 1 addition & 1 deletion src/test/util_sds/grep5.log.match
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<libpmem2>: <2> [shutdown_state.c:$(N) shutdown_state_check] the pool was not closed - SDS will be reinitialized
<libpmem2>: <2> [shutdown_state.c:$(N) shutdown_state_check] The ADR failure was detected but the pool was closed properly - reinitializing ADR failure detection.
2 changes: 1 addition & 1 deletion src/test/util_sds/grep6.log.match
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<libpmem2>: <1> [shutdown_state.c:$(N) shutdown_state_check] an ADR failure was detected, the pool might be corrupted
<libpmem2>: <1> [shutdown_state.c:$(N) shutdown_state_check] The pool has moved to a new location while it was not closed properly, the pool might be corrupted.
2 changes: 1 addition & 1 deletion src/test/util_sds/grep7.log.match
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<libpmem2>: <1> [shutdown_state.c:$(N) shutdown_state_check] an ADR failure was detected, the pool might be corrupted
<libpmem2>: <1> [shutdown_state.c:$(N) shutdown_state_check] The ADR failure was detected, the pool might be corrupted.
1 change: 1 addition & 0 deletions src/test/util_sds_check/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
util_sds_check
18 changes: 18 additions & 0 deletions src/test/util_sds_check/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2025, Hewlett Packard Enterprise Development LP

#
# src/test/util_sds_check/Makefile -- shutdown_state_check unit test
#
BUILD_STATIC_DEBUG=n
BUILD_STATIC_NONDEBUG=n

TARGET = util_sds_check
OBJS = util_sds_check.o

LIBPMEM=y
LIBPMEMCOMMON=internal-debug

include ../Makefile.inc

LDFLAGS += $(call extract_funcs, util_sds_check.c)
23 changes: 23 additions & 0 deletions src/test/util_sds_check/TEST0
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2025, Hewlett Packard Enterprise Development LP

#
# src/test/util_sds_check/TEST0 -- unittest for shutdown_state_check
#

. ../unittest/unittest.sh

require_test_type short

require_fs_type none

require_build_type debug

setup

expect_normal_exit ./util_sds_check test_dirty_clear

check

pass
23 changes: 23 additions & 0 deletions src/test/util_sds_check/TEST1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2025, Hewlett Packard Enterprise Development LP

#
# src/test/util_sds_check/TEST1 -- unittest for shutdown_state_check
#

. ../unittest/unittest.sh

require_test_type short

require_fs_type none

require_build_type debug

setup

expect_normal_exit ./util_sds_check test_invalid_checksum

check

pass
23 changes: 23 additions & 0 deletions src/test/util_sds_check/TEST2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2025, Hewlett Packard Enterprise Development LP

#
# src/test/util_sds_check/TEST2 -- unittest for shutdown_state_check
#

. ../unittest/unittest.sh

require_test_type short

require_fs_type none

require_build_type debug

setup

expect_normal_exit ./util_sds_check test_dirty_set

check

pass
Loading
Loading