From patchwork Tue Nov 14 07:47:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10057099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6658D602A7 for ; Tue, 14 Nov 2017 07:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4621828F97 for ; Tue, 14 Nov 2017 07:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B32028FEA; Tue, 14 Nov 2017 07:47:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6E49428F97 for ; Tue, 14 Nov 2017 07:47:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3C7DA220D4BEC; Mon, 13 Nov 2017 23:43:17 -0800 (PST) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=202.219.69.168; helo=mgwkm01.jp.fujitsu.com; envelope-from=qi.fuli@jp.fujitsu.com; receiver=linux-nvdimm@lists.01.org Received: from mgwkm01.jp.fujitsu.com (mgwkm01.jp.fujitsu.com [202.219.69.168]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 85EBE220D4BE9 for ; Mon, 13 Nov 2017 23:43:15 -0800 (PST) Received: from kw-mxoi1.gw.nic.fujitsu.com (unknown [192.168.231.131]) by mgwkm01.jp.fujitsu.com with smtp id 4980_c40f_71999a8e_1fff_403a_b0ee_94a35c088a7b; Tue, 14 Nov 2017 16:47:14 +0900 Received: from m3051.s.css.fujitsu.com (m3051.s.css.fujitsu.com [10.134.21.209]) by kw-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id D39A0AC00D4 for ; Tue, 14 Nov 2017 16:47:13 +0900 (JST) Received: from qi-fedora.fujitsu.com (unknown [10.124.196.110]) by m3051.s.css.fujitsu.com (Postfix) with ESMTP id B31761C4; Tue, 14 Nov 2017 16:47:13 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [RFC PATCH v2 7/7] ndctl: nvdimmd: add a temporary test for nvdimm daemon Date: Tue, 14 Nov 2017 16:47:04 +0900 Message-Id: <20171114074704.3446-8-qi.fuli@jp.fujitsu.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171114074704.3446-1-qi.fuli@jp.fujitsu.com> References: <20171114074704.3446-1-qi.fuli@jp.fujitsu.com> X-TM-AS-MML: disable X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP This patch is used to test nvdimmd service temporarily. I will make it an ndctl command or an option of ndctl inject-error in next step. Currently, You can test nvdimm daemon with the following command. nvdimmd_test [nmemX] [all] Signed-off-by: QI Fuli --- nvdimmd/Makefile.am | 14 ++++- nvdimmd/nvdimmd_test.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 nvdimmd/nvdimmd_test.c diff --git a/nvdimmd/Makefile.am b/nvdimmd/Makefile.am index bca0bc8..cca1980 100644 --- a/nvdimmd/Makefile.am +++ b/nvdimmd/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/Makefile.am.in -bin_PROGRAMS = nvdimmd +bin_PROGRAMS = nvdimmd nvdimmd_test nvdimmd_SOURCES =\ nvdimmd.c \ @@ -18,6 +18,18 @@ nvdimmd_LDADD = ../ndctl/lib/libndctl.la \ $(UUID_LIBS) \ $(UDEV_LIBS) +nvdimmd_test_SOURCES =\ + nvdimmd_test.c \ + ../util/log.c + +nvdimmd_test_LDADD =\ + ../ndctl/lib/libndctl.la \ + ../daxctl/lib/libdaxctl.la \ + ../libutil.a \ + $(KMOD_LIBS) \ + $(UUID_LIBS) \ + $(UDEV_LIBS) + unitfiles = nvdimmd.service unitdir = /usr/lib/systemd/system/ diff --git a/nvdimmd/nvdimmd_test.c b/nvdimmd/nvdimmd_test.c new file mode 100644 index 0000000..8d16243 --- /dev/null +++ b/nvdimmd/nvdimmd_test.c @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2017, FUJITSU LIMITED. All rirhts reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU Lesser General Public License, + * version 2.1, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for + * more details. + */ + +/* + * This program is used to call the emulation of event of over threshold. + * You can test nvdimmd daemon with the following command. + * nvdimmd_test [nmemX] [all] + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#define NUM_MAX_DIMM 1024 +#include + +struct threshold_dimm { + struct ndctl_dimm *dimm; + const char *devname; + int health_eventfd; +}; + +const char *test_help_info = "nvdimmd_test [nmemX] [all]"; + +static int get_threshold(struct ndctl_ctx *ctx, struct threshold_dimm *t_dimm) +{ + struct ndctl_bus *bus; + struct ndctl_dimm *dimm; + int cnt_dimm = 0; + + ndctl_bus_foreach(ctx, bus) { + ndctl_dimm_foreach(bus, dimm) { + if (!ndctl_dimm_is_cmd_supported(dimm, ND_CMD_SMART_THRESHOLD)) + continue; + t_dimm[cnt_dimm].dimm = dimm; + t_dimm[cnt_dimm].devname = ndctl_dimm_get_devname(dimm); + cnt_dimm++; + } + } + return cnt_dimm; +} + +static int test_submit_cmd(struct threshold_dimm *t_dimm) +{ + struct ndctl_cmd *cmd; + const char *msg = "command to call over threshold event notification: "; + + cmd = ndctl_dimm_cmd_new_smart_threshold(t_dimm->dimm); + if (!cmd) { + fprintf(stderr, "failed to prepare %s[%s]\n", + msg, t_dimm->devname); + return -1; + } + if(ndctl_cmd_submit(cmd)) { + fprintf(stderr, "failed to submit %s[%s]\n", + msg, t_dimm->devname); + return -1; + } + ndctl_cmd_unref(cmd); + return 0; +} + +static int +test_submit(struct threshold_dimm *t_dimm, int count_dimm, char *test_devname) +{ + int count_test = 0; + + for (int i= 0; i < count_dimm; i++) { + if (!strcmp(test_devname, "all")) { + if (!test_submit_cmd(&t_dimm[i])) + count_test++; + continue; + } + if (!strcmp(test_devname, t_dimm[i].devname)) { + if (!test_submit_cmd(&t_dimm[i])) + count_test++; + else + count_test--; + break; + } + } + return count_test; +} + +int main(int argc, char *argv[]) +{ + struct ndctl_ctx *ctx; + int rc, count_dimm; + char *test_devname; + struct threshold_dimm *t_dimm; + + if (argc < 1) { + fprintf(stderr, "usage: %s\n", test_help_info); + goto out; + } + + test_devname = argv[1]; + if (!test_devname || !strcmp(test_devname, "--help")){ + fprintf(stderr, "usage: %s\n", test_help_info); + goto out; + } + rc = ndctl_new(&ctx); + if (rc) + goto out; + + t_dimm = calloc(NUM_MAX_DIMM, sizeof(struct threshold_dimm)); + if (!t_dimm) { + fprintf(stderr, "nvdimmd test error: memory not allocate\n"); + goto out; + } + + count_dimm = get_threshold(ctx, t_dimm); + if (count_dimm == 0) { + fprintf(stderr, "nvdimmd test error: no dimm support over threshold\n"); + goto out; + } + + rc = test_submit(t_dimm, count_dimm, test_devname); + + if (!rc && strcmp(test_devname, "all")) + fprintf(stderr, "UNKNOWM DIMM_NAME\n"); + else if (rc >= 0) + printf("%d nvdimmd test submit: [%s]\n", rc, test_devname); + + ndctl_unref(ctx); +out: + return 1; +}