Skip to content

Commit

Permalink
common: update sds detection to ndctl v63
Browse files Browse the repository at this point in the history
  • Loading branch information
lplewa committed Feb 6, 2019
1 parent e622c4a commit 6ca086e
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 43 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ env:
- TEST_BUILD=nondebug
- PMDK_CC=clang PMDK_CXX=clang++ TEST_BUILD=debug
- PMDK_CC=clang PMDK_CXX=clang++ TEST_BUILD=nondebug
- OS=ubuntu_ndctl_v60 TEST_BUILD=debug
- OS=ubuntu_ndctl_v60 PUSH_IMAGE=1 TEST_BUILD=nondebug
- OS=fedora OS_VER=28 PMDK_CC=clang PMDK_CXX=clang++ TEST_BUILD=debug
- OS=fedora OS_VER=28 PMDK_CC=clang PMDK_CXX=clang++ TEST_BUILD=nondebug
- MAKE_PKG=1 EXPERIMENTAL=y REMOTE_TESTS=0 VALGRIND=0 NDCTL_ENABLE=n PUSH_IMAGE=1
- MAKE_PKG=1 EXPERIMENTAL=y REMOTE_TESTS=0 VALGRIND=0 NDCTL_ENABLE=y PUSH_IMAGE=1 OS=fedora OS_VER=28
- MAKE_PKG=1 EXPERIMENTAL=y REMOTE_TESTS=0 VALGRIND=0 PUSH_IMAGE=1 OS=fedora OS_VER=28
- MAKE_PKG=1 EXPERIMENTAL=y REMOTE_TESTS=0 VALGRIND=0 NDCTL_ENABLE=n PMDK_CC=clang PMDK_CXX=clang++
- COVERITY=1

Expand Down
1 change: 1 addition & 0 deletions src/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ CFLAGS += -DSRCVERSION=\"$(SRCVERSION)\"

ifeq ($(OS_DIMM),ndctl)
CFLAGS += -DSDS_ENABLED
CFLAGS += $(OS_DIMM_CFLAG)
endif

ifeq ($(COVERAGE),1)
Expand Down
37 changes: 24 additions & 13 deletions src/common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ see src/librpmem/README for details
endif
endif

# unsafe shutdown count and badblock access without root (depends on kernel 4.20)
NDCTL_MIN_VERSION_FIXED := 63

NDCTL_MIN_VERSION := 60.1

sparse-c = $(shell for c in *.c; do sparse -Wsparse-all -Wno-declaration-after-statement $(CFLAGS) $(INCS) $$c || true; done)
Expand Down Expand Up @@ -370,21 +373,29 @@ NDCTL_ENABLE ?= y

# Detect libndctl if not disabled.
ifeq ($(NDCTL_ENABLE),y)
ifeq ($(LIBNDCTL),)
HAS_NDCTL := $(call check_package, libndctl --atleast-version $(NDCTL_MIN_VERSION))
HAS_DAXCTL := $(call check_package, libdaxctl --atleast-version $(NDCTL_MIN_VERSION))
ifeq ($(HAS_NDCTL),n)
$(error libndctl(version >= $(NDCTL_MIN_VERSION)) is missing -- see README)
endif
ifeq ($(HAS_DAXCTL),n)
$(error libdaxctl(version >= $(NDCTL_MIN_VERSION)) is missing -- see README)
endif
LIBNDCTL := $(shell $(PKG_CONFIG) --libs libndctl libdaxctl)
endif
export OS_DIMM := ndctl
ifeq ($(LIBNDCTL),)
HAS_NDCTL := $(call check_package, libndctl --atleast-version $(NDCTL_MIN_VERSION_FIXED))
ifeq ($(HAS_NDCTL),y)
OS_DIMM_CFLAG=-DNDCTL_GE_63
else
HAS_NDCTL := $(call check_package, libndctl --atleast-version $(NDCTL_MIN_VERSION))
ifeq ($(HAS_NDCTL),n)
$(error libndctl(version >= $(NDCTL_MIN_VERSION)) is missing -- see README)
endif
$(info WARNING: LIBNDCTL without permission fixes, some RAS features will be disabled)
endif
HAS_DAXCTL := $(call check_package, libdaxctl --atleast-version $(NDCTL_MIN_VERSION))
ifeq ($(HAS_DAXCTL),n)
$(error libdaxctl(version >= $(NDCTL_MIN_VERSION)) is missing -- see README)
endif
LIBNDCTL := $(shell $(PKG_CONFIG) --libs libndctl libdaxctl)
endif
OS_DIMM := ndctl
else
export OS_DIMM := none
OS_DIMM := none
endif
export OS_DIMM
export LIBNDCTL
export OS_DIMM_CFLAG

endif
69 changes: 45 additions & 24 deletions src/common/os_dimm_ndctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@
#include "badblock.h"
#include "vec.h"

/*
* http://pmem.io/documents/NVDIMM_DSM_Interface-V1.6.pdf
* Table 3-2 SMART amd Health Data - Validity flags
* Bit[5] – If set to 1, indicates that Unsafe Shutdown Count
* field is valid
*/
#define USC_VALID_FLAG (1 << 5)

#define FOREACH_BUS_REGION_NAMESPACE(ctx, bus, region, ndns) \
ndctl_bus_foreach(ctx, bus) \
ndctl_region_foreach(bus, region) \
Expand Down Expand Up @@ -260,6 +252,48 @@ os_dimm_uid(const char *path, char *uid, size_t *buff_len)
return ret;
}

#ifdef NDCTL_GE_63
static long long
os_dimm_usc_dimm(struct ndctl_dimm *dimm)
{
long long ret = ndctl_dimm_get_dirty_shutdown(dimm);
if (ret < 0)
ERR("!ndctl_dimm_get_dirty_shutdown");
return ret;
}
#else
/*
* http://pmem.io/documents/NVDIMM_DSM_Interface-V1.6.pdf
* Table 3-2 SMART amd Health Data - Validity flags
* Bit[5] – If set to 1, indicates that Unsafe Shutdown Count
* field is valid
*/
#define USC_VALID_FLAG (1 << 5)

static long long
os_dimm_usc_dimm(struct ndctl_dimm *dimm)
{
struct ndctl_cmd *cmd = ndctl_dimm_cmd_new_smart(dimm);

if (cmd == NULL) {
ERR("!ndctl_dimm_cmd_new_smart");
return -1;
}

if (ndctl_cmd_submit(cmd)) {
ERR("!ndctl_cmd_submit");
return -1;
}

if (!(ndctl_cmd_smart_get_flags(cmd) & USC_VALID_FLAG)) {
/* dimm doesn't support unsafe shutdown count */
return 0;
}

return ndctl_cmd_smart_get_shutdown_count(cmd);
}
#undef USC_VALID_FLAG
#endif
/*
* os_dimm_usc -- returns unsafe shutdown count
*/
Expand Down Expand Up @@ -292,23 +326,10 @@ os_dimm_usc(const char *path, uint64_t *usc)
struct ndctl_dimm *dimm;

ndctl_dimm_foreach_in_interleave_set(iset, dimm) {
struct ndctl_cmd *cmd = ndctl_dimm_cmd_new_smart(dimm);

if (cmd == NULL) {
ERR("!ndctl_dimm_cmd_new_smart");
goto err;
}

if (ndctl_cmd_submit(cmd)) {
ERR("!ndctl_cmd_submit");
long long dimm_usc = os_dimm_usc_dimm(dimm);
if (dimm_usc < 0)
goto err;
}

if (!(ndctl_cmd_smart_get_flags(cmd) & USC_VALID_FLAG)) {
/* dimm doesn't support unsafe shutdown count */
continue;
}
*usc += ndctl_cmd_smart_get_shutdown_count(cmd);
*usc += (unsigned long long)dimm_usc;
}
out:
ret = 0;
Expand Down
1 change: 1 addition & 0 deletions src/test/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ CFLAGS += $(EXTRA_CFLAGS)
LDFLAGS = -Wl,--warn-common -Wl,--fatal-warnings $(EXTRA_LDFLAGS)

ifeq ($(OS_DIMM),ndctl)
CFLAGS += $(OS_DIMM_CFLAG)
CFLAGS += -DSDS_ENABLED
endif

Expand Down
4 changes: 3 additions & 1 deletion utils/docker/images/Dockerfile.fedora-28
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ MAINTAINER marcin.slusarz@intel.com
RUN dnf update -y \
&& dnf install -y \
asciidoc \
asciidoctor \
autoconf \
automake \
bash-completion \
Expand All @@ -58,6 +59,7 @@ RUN dnf update -y \
glib2-devel \
hub \
json-c-devel \
keyutils-libs-devel \
kmod-devel \
lbzip2 \
libtool \
Expand Down Expand Up @@ -85,7 +87,7 @@ RUN dnf update -y \

# Install libndctl
COPY install-libndctl.sh install-libndctl.sh
RUN ./install-libndctl.sh fedora
RUN ./install-libndctl.sh tags/v64.1 fedora

# Install valgrind
COPY install-valgrind.sh install-valgrind.sh
Expand Down
5 changes: 4 additions & 1 deletion utils/docker/images/Dockerfile.ubuntu-18.04
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ MAINTAINER marcin.slusarz@intel.com
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common \
asciidoc \
asciidoctor \
autoconf \
bash-completion \
bc \
clang \
cmake \
Expand All @@ -55,6 +57,7 @@ RUN apt-get update \
libfuse-dev \
libglib2.0-dev \
libjson-c-dev \
libkeyutils-dev \
libkmod-dev \
libncurses5-dev \
libtool \
Expand All @@ -80,7 +83,7 @@ RUN ./install-libfabric.sh

# Install libndctl
COPY install-libndctl.sh install-libndctl.sh
RUN ./install-libndctl.sh
RUN ./install-libndctl.sh tags/v64.1

# Add user
ENV USER pmdkuser
Expand Down
96 changes: 96 additions & 0 deletions utils/docker/images/Dockerfile.ubuntu_ndctl_v60-18.04
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#
# Copyright 2016-2017, 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.

#
# Dockerfile - a 'recipe' for Docker to build an image of ubuntu-based
# environment for building the PMDK project.
#

# Pull base image
FROM ubuntu:18.04
MAINTAINER marcin.slusarz@intel.com
# Update the Apt cache and install basic tools
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common \
asciidoc \
autoconf \
bc \
clang \
cmake \
debhelper \
devscripts \
flake8 \
gcc \
gdb \
git \
libc6-dbg \
libfuse-dev \
libglib2.0-dev \
libjson-c-dev \
libkmod-dev \
libncurses5-dev \
libtool \
libudev-dev \
libunwind8-dev \
libuv1-dev \
pandoc \
pkg-config \
ruby \
ssh \
sudo \
uuid-dev \
whois \
&& rm -rf /var/lib/apt/lists/*

# Install valgrind
COPY install-valgrind.sh install-valgrind.sh
RUN ./install-valgrind.sh

# Install libfabric
COPY install-libfabric.sh install-libfabric.sh
RUN ./install-libfabric.sh

# Install libndctl
COPY install-libndctl.sh install-libndctl.sh
RUN ./install-libndctl.sh tags/v60.1

# Add user
ENV USER pmdkuser
ENV USERPASS pmdkpass
RUN useradd -m $USER -g sudo -p `mkpasswd $USERPASS`
USER $USER

# Set required environment variables
ENV OS ubuntu
ENV OS_VER 18.04
ENV START_SSH_COMMAND service ssh start
ENV PACKAGE_MANAGER dpkg
ENV NOTTY 1
6 changes: 3 additions & 3 deletions utils/docker/images/install-libndctl.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Copyright 2017-2018, Intel Corporation
# Copyright 2017-2019, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -36,12 +36,12 @@

set -e

OS=$1
OS=$2

echo "==== clone ndctl repo ===="
git clone https://github.com/pmem/ndctl.git
cd ndctl
git checkout tags/v60.1
git checkout $1

if [ "$OS" = "fedora" ]; then

Expand Down

0 comments on commit 6ca086e

Please sign in to comment.