Blob Blame History Raw
#!/usr/bin/env bash
#
# Copyright 2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in
#       the documentation and/or other materials provided with the
#       distribution.
#
#     * Neither the name of the copyright holder nor the names of its
#       contributors may be used to endorse or promote products derived
#       from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#
# pmempool_sync_remote/TEST32 -- pmempool sync with remote replication
#                                and bad blocks in the regular file:
#                                - the pool consists of 2 parts
#                                - offset of bad block in all 2 parts: 0
#

# standard unit test setup
. ../unittest/unittest.sh

require_test_type medium
require_fs_type non-pmem
require_build_type debug nondebug
require_linked_with_ndctl $PMEMPOOL$EXESUFFIX

require_nfit_tests_enabled
require_nodes 2
require_sudo_allowed_node 0
require_kernel_module_node 0 nfit_test
require_command_node 0 ndctl

setup

require_node_libfabric 0 $RPMEM_PROVIDER
require_node_libfabric 1 $RPMEM_PROVIDER

init_rpmem_on_node 0 1

export PMEMPOOL_LOG_LEVEL=10
export PMEMOBJ_LOG_LEVEL=10
export_vars_node 0 PMEMPOOL_LOG_LEVEL
export_vars_node 0 PMEMOBJ_LOG_LEVEL

require_node_log_files 0 pmemobj$UNITTEST_NUM.log
require_node_log_files 0 pmempool$UNITTEST_NUM.log

. ../common_badblock.sh

ndctl_nfit_test_init_node 0

DEVICE=$(ndctl_nfit_test_get_block_device_node 0)
NAMESPACE=$(ndctl_nfit_test_get_namespace_of_device_node 0 $DEVICE)
FULLDEV="/dev/$DEVICE"
MOUNT_DIR="${NODE_DIR[0]}/mnt-pmem"
LAYOUT="layout"

ndctl_nfit_test_mount_pmem_node 0 $FULLDEV $MOUNT_DIR

LOG=out${UNITTEST_NUM}.log
rm -f $LOG && touch $LOG

POOLSET_LOCAL="local_pool.set"
POOLSET_REMOTE="remote_pool.set"

create_poolset $DIR/$POOLSET_LOCAL \
	8M:${MOUNT_DIR}/pool.local.part.0:x \
	8M:${MOUNT_DIR}/pool.local.part.1:x \
	M \
	${NODE_ADDR[1]}:$POOLSET_REMOTE

create_poolset $DIR/$POOLSET_REMOTE \
	16M:${NODE_DIR[1]}/pool.remote:x

copy_files_to_node 0 ${NODE_DIR[0]} $DIR/$POOLSET_LOCAL
copy_files_to_node 1 ${NODE_DIR[1]} $DIR/$POOLSET_REMOTE

expect_normal_exit run_on_node 0 ../pmempool rm -sf ${NODE_DIR[0]}$POOLSET_LOCAL
expect_normal_exit run_on_node 0 "../obj_verify ${NODE_DIR[0]}$POOLSET_LOCAL $LAYOUT c v &>> $LOG"

###############################################################################
# Enabling features in poolsets with remote replicas is not supported now,
# so we have to use the following workaround to enable
# the POOL_FEAT_CHECK_BAD_BLOCKS compat feature in such poolset.
# We create the auxiliary poolset without the remote replica
# and enable this compat feature on all nodes separately.

POOLSET_LOCAL_AUX=${POOLSET_LOCAL}_aux

create_poolset $DIR/${POOLSET_LOCAL_AUX} \
	8M:${MOUNT_DIR}/pool.local.part.0:x \
	8M:${MOUNT_DIR}/pool.local.part.1:x

copy_files_to_node 0 ${NODE_DIR[0]} $DIR/${POOLSET_LOCAL_AUX}

turn_on_checking_bad_blocks_node 0 ${NODE_DIR[0]}/${POOLSET_LOCAL_AUX}
turn_on_checking_bad_blocks_node 1 ${NODE_DIR[1]}/${POOLSET_REMOTE}

###############################################################################

# inject bad block in the part #0
FILE=${MOUNT_DIR}/pool.local.part.0
FIRST_SECTOR=$(expect_normal_exit run_on_node 0 ../extents $FILE -l 0)
expect_normal_exit run_on_node 0 "sudo ndctl inject-error --block=$FIRST_SECTOR --count=1 $NAMESPACE &>> $PREP_LOG_FILE"

# inject bad block in the part #1
FILE=${MOUNT_DIR}/pool.local.part.1
FIRST_SECTOR=$(expect_normal_exit run_on_node 0 ../extents $FILE -l 0)
expect_normal_exit run_on_node 0 "sudo ndctl inject-error --block=$FIRST_SECTOR --count=1 $NAMESPACE &>> $PREP_LOG_FILE"

expect_normal_exit run_on_node 0 "sudo ndctl start-scrub &>> $PREP_LOG_FILE"
expect_normal_exit run_on_node 0 "sudo ndctl wait-scrub &>> $PREP_LOG_FILE"

expect_bad_blocks_node 0

expect_abnormal_exit run_on_node 0 "../obj_verify ${NODE_DIR[0]}$POOLSET_LOCAL $LAYOUT v &>> $LOG"

expect_bad_blocks_node 0

expect_normal_exit run_on_node 0 "../pmempool sync -b -v ${NODE_DIR[0]}$POOLSET_LOCAL &>> $LOG"
expect_normal_exit run_on_node 0 "../obj_verify ${NODE_DIR[0]}$POOLSET_LOCAL $LAYOUT v &>> $LOG"

ndctl_nfit_test_fini_node 0 $MOUNT_DIR

pass