11// SPDX-License-Identifier: BSD-3-Clause
22/* Copyright 2017-2024, Intel Corporation */
3+ /* Copyright 2025, Hewlett Packard Enterprise Development LP */
34
45/*
56 * shutdown_state.c -- unsafe shudown detection
1718#include "bad_blocks.h"
1819#include "../libpmem2/pmem2_utils.h"
1920
20- #define FLUSH_SDS (sds , rep ) \
21- if ((rep) != NULL) os_part_deep_common(rep, 0, sds, sizeof(*(sds)), 1)
22-
2321/*
24- * shutdown_state_checksum -- (internal) counts SDS checksum and flush it
22+ * shutdown_state_checksum -- counts SDS checksum and flush it
2523 */
26- static void
24+ void
2725shutdown_state_checksum (struct shutdown_state * sds , struct pool_replica * rep )
2826{
2927 LOG (3 , "sds %p" , sds );
@@ -159,24 +157,6 @@ shutdown_state_clear_dirty(struct shutdown_state *sds, struct pool_replica *rep)
159157 shutdown_state_checksum (sds , rep );
160158}
161159
162- /*
163- * shutdown_state_reinit -- (internal) reinitializes shutdown_state struct
164- */
165- static void
166- shutdown_state_reinit (struct shutdown_state * curr_sds ,
167- struct shutdown_state * pool_sds , struct pool_replica * rep )
168- {
169- LOG (3 , "curr_sds %p, pool_sds %p" , curr_sds , pool_sds );
170- shutdown_state_init (pool_sds , rep );
171- pool_sds -> uuid = htole64 (curr_sds -> uuid );
172- pool_sds -> usc = htole64 (curr_sds -> usc );
173- pool_sds -> dirty = 0 ;
174-
175- FLUSH_SDS (pool_sds , rep );
176-
177- shutdown_state_checksum (pool_sds , rep );
178- }
179-
180160/*
181161 * shutdown_state_check -- compares and fixes shutdown state
182162 */
@@ -186,15 +166,26 @@ shutdown_state_check(struct shutdown_state *curr_sds,
186166{
187167 LOG (3 , "curr_sds %p, pool_sds %p" , curr_sds , pool_sds );
188168
169+ /*
170+ * This is likely to occur only when the pool is being opened for
171+ * the first time after the SHUTDOWN_STATE feature has been enabled on
172+ * the pool, for example, via (lib)pmempool.
173+ * Please do not confuse this with establishing SDS during creation.
174+ */
189175 if (util_is_zeroed (pool_sds , sizeof (* pool_sds )) &&
190176 !util_is_zeroed (curr_sds , sizeof (* curr_sds ))) {
177+ CORE_LOG_WARNING (
178+ "Enabling ADR failure detection, assuming pool consistency up to this point." );
191179 shutdown_state_reinit (curr_sds , pool_sds , rep );
192180 return 0 ;
193181 }
194182
183+ bool is_uuid_correct =
184+ le64toh (pool_sds -> uuid ) == le64toh (curr_sds -> uuid );
185+
195186 bool is_uuid_usc_correct =
196187 le64toh (pool_sds -> usc ) == le64toh (curr_sds -> usc ) &&
197- le64toh ( pool_sds -> uuid ) == le64toh ( curr_sds -> uuid ) ;
188+ is_uuid_correct ;
198189
199190 bool is_checksum_correct = util_checksum (pool_sds ,
200191 sizeof (* pool_sds ), & pool_sds -> checksum , 0 , 0 );
@@ -204,7 +195,7 @@ shutdown_state_check(struct shutdown_state *curr_sds,
204195 if (!is_checksum_correct ) {
205196 /* the program was killed during opening or closing the pool */
206197 CORE_LOG_WARNING (
207- "incorrect checksum - SDS will be reinitialized " );
198+ "The pool was not opened/closed properly - reinitializing ADR failure detection. " );
208199 shutdown_state_reinit (curr_sds , pool_sds , rep );
209200 return 0 ;
210201 }
@@ -217,19 +208,23 @@ shutdown_state_check(struct shutdown_state *curr_sds,
217208 * but there wasn't an ADR failure
218209 */
219210 CORE_LOG_WARNING (
220- "the pool was not closed - SDS will be reinitialized " );
211+ "The ADR failure was detected but the pool was closed properly - reinitializing ADR failure detection. " );
221212 shutdown_state_reinit (curr_sds , pool_sds , rep );
222213 return 0 ;
223214 }
224215 if (dirty == 0 ) {
225- /* an ADR failure but the pool was closed */
226- CORE_LOG_WARNING (
227- "an ADR failure was detected but the pool was closed - SDS will be reinitialized" );
216+ if (is_uuid_correct )
217+ CORE_LOG_WARNING (
218+ "The ADR failure was detected but the pool was closed properly - reinitializing ADR failure detection." );
219+ else
220+ CORE_LOG_HARK (
221+ "The pool has moved to a new location but it was closed properly - reinitializing ADR failure detection." );
228222 shutdown_state_reinit (curr_sds , pool_sds , rep );
229223 return 0 ;
230224 }
231- /* an ADR failure - the pool might be corrupted */
232- ERR_WO_ERRNO (
233- "an ADR failure was detected, the pool might be corrupted" );
225+
226+ ERR_WO_ERRNO ("%s, the pool might be corrupted." , is_uuid_correct ?
227+ "The ADR failure was detected" :
228+ "The pool has moved to a new location while it was not closed properly" );
234229 return 1 ;
235230}
0 commit comments