From ac3da3a2b2b3aecfccf62bc70ea8d0e82b9e3960 Mon Sep 17 00:00:00 2001 From: "Lucas A. M. Magalhaes" <lamm@linux.ibm.com> Date: Mon, 6 Jul 2020 16:13:23 -0300 Subject: [PATCH] common: Add runtime SDS check and disable Some devices have no support for SDS and will not be able to create a pool unless build without SDS_ENABLE or forcing disable SDS during creation. This commit checks if the device has SDS support on ndctl before durint poolset creation and disables it if don't. Signed-off-by: Lucas A. M. Magalhaes <lamm@linux.ibm.com> --- src/common/set.c | 8 ++++++++ src/common/shutdown_state.c | 27 ++++++++++++++++++++++++--- src/common/shutdown_state.h | 1 + src/libpmempool/check_pool_hdr.c | 5 +++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index e3f8b6f63..60cf16e77 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -71,6 +71,7 @@ #include "fs.h" #include "os_deep.h" #include "set_badblocks.h" +#include "shutdown_state.h" #define LIBRARY_REMOTE "librpmem.so.1" #define SIZE_AUTODETECT_STR "AUTO" @@ -2253,6 +2254,13 @@ util_header_create(struct pool_set *set, unsigned repidx, unsigned partidx, if (set->options & OPTION_SINGLEHDR) hdrp->features.incompat |= POOL_FEAT_SINGLEHDR; + /* Update SDS feature if the device don't supports it */ + if (!shutdown_state_is_supported(rep->part[partidx].fd)) { + hdrp->features.incompat &= ~POOL_FEAT_SDS; + set->ignore_sds |= IGNORE_SDS(HDR(rep, 0)); + LOG(3, "SDS disabled at runtime"); + } + memcpy(hdrp->poolset_uuid, set->uuid, POOL_HDR_UUID_LEN); memcpy(hdrp->uuid, PART(rep, partidx)->uuid, POOL_HDR_UUID_LEN); diff --git a/src/common/shutdown_state.c b/src/common/shutdown_state.c index 3a2bb11fa..d6d719002 100644 --- a/src/common/shutdown_state.c +++ b/src/common/shutdown_state.c @@ -20,6 +20,29 @@ #define FLUSH_SDS(sds, rep) \ if ((rep) != NULL) os_part_deep_common(rep, 0, sds, sizeof(*(sds)), 1) +/* + * shutdown_state_is_supported -- (internal) check if device supports SDS + * + * Returns 1 if supports and 0 if not. + */ +int +shutdown_state_is_supported(int fd) +{ + uint64_t usc; + struct pmem2_source *src; + + if (pmem2_source_from_fd(&src, fd)) + return 0; + + if (pmem2_source_device_usc(src, &usc) == PMEM2_E_NOSUPP) { + pmem2_source_delete(&src); + return 0; + } + + pmem2_source_delete(&src); + return 1; +} + /* * shutdown_state_checksum -- (internal) counts SDS checksum and flush it */ @@ -71,9 +94,7 @@ shutdown_state_add_part(struct shutdown_state *sds, int fd, int ret = pmem2_source_device_usc(src, &usc); - if (ret == PMEM2_E_NOSUPP) { - usc = 0; - } else if (ret != 0) { + if (ret != 0) { if (ret == -EPERM) { /* overwrite error message */ ERR( diff --git a/src/common/shutdown_state.h b/src/common/shutdown_state.h index 60031bb5c..147cd1f40 100644 --- a/src/common/shutdown_state.h +++ b/src/common/shutdown_state.h @@ -33,6 +33,7 @@ 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); +int shutdown_state_is_supported(int fd); #ifdef __cplusplus } diff --git a/src/libpmempool/check_pool_hdr.c b/src/libpmempool/check_pool_hdr.c index 9d24855b0..e9cf7173d 100644 --- a/src/libpmempool/check_pool_hdr.c +++ b/src/libpmempool/check_pool_hdr.c @@ -234,6 +234,11 @@ pool_hdr_default_fix(PMEMpoolcheck *ppc, location *loc, uint32_t question, loc->hdr.features.compat = def_hdr.features.compat; break; case Q_DEFAULT_INCOMPAT_FEATURES: + /* Check if SDS is supported */ + if (!shutdown_state_is_supported( + PART(REP(ppc->pool->set_file->poolset, 0), 0)->fd)) { + def_hdr.features.incompat &= ~POOL_FEAT_SDS; + } CHECK_INFO(ppc, "%ssetting pool_hdr.features.incompat to 0x%x", loc->prefix, def_hdr.features.incompat); loc->hdr.features.incompat = def_hdr.features.incompat; -- GitLab