From patchwork Tue Nov 14 07:47:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: QI Fuli X-Patchwork-Id: 10057101 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 623F1602A7 for ; Tue, 14 Nov 2017 07:47:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4144728F97 for ; Tue, 14 Nov 2017 07:47:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 362CF28FD0; Tue, 14 Nov 2017 07:47:27 +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 2A48328FC8 for ; Tue, 14 Nov 2017 07:47:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5587E220D4BEE; 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 88B45220D4BEA for ; Mon, 13 Nov 2017 23:43:15 -0800 (PST) Received: from kw-mxauth.gw.nic.fujitsu.com (unknown [192.168.231.132]) by mgwkm01.jp.fujitsu.com with smtp id 4980_c3ed_2b96fd42_4f90_4b8e_b854_97504c88b23f; 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-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id 78920AC011F 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 5653F191; Tue, 14 Nov 2017 16:47:13 +0900 (JST) From: QI Fuli To: linux-nvdimm@lists.01.org Subject: [RFC PATCH v2 4/7] ndctl: nvdimmd: add body file of nvdimm daemon Date: Tue, 14 Nov 2017 16:47:01 +0900 Message-Id: <20171114074704.3446-5-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 adds the body file of nvdimm daemon and compiles nvdimmd with automake. Signed-off-by: QI Fuli --- Makefile.am | 2 +- configure.ac | 1 + nvdimmd/Makefile.am | 19 +++++++++ nvdimmd/nvdimmd.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 nvdimmd/Makefile.am create mode 100644 nvdimmd/nvdimmd.c diff --git a/Makefile.am b/Makefile.am index b538b1f..ff91439 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ include Makefile.am.in ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} -SUBDIRS = . daxctl/lib ndctl/lib ndctl daxctl +SUBDIRS = . daxctl/lib ndctl/lib ndctl daxctl nvdimmd if ENABLE_DOCS SUBDIRS += Documentation/ndctl Documentation/daxctl endif diff --git a/configure.ac b/configure.ac index 5b10381..3ce71e3 100644 --- a/configure.ac +++ b/configure.ac @@ -274,6 +274,7 @@ AC_CONFIG_FILES([ daxctl/lib/Makefile ndctl/lib/Makefile ndctl/Makefile + nvdimmd/Makefile daxctl/Makefile test/Makefile Documentation/ndctl/Makefile diff --git a/nvdimmd/Makefile.am b/nvdimmd/Makefile.am new file mode 100644 index 0000000..9883edd --- /dev/null +++ b/nvdimmd/Makefile.am @@ -0,0 +1,19 @@ +include $(top_srcdir)/Makefile.am.in + +bin_PROGRAMS = nvdimmd + +nvdimmd_SOURCES =\ + nvdimmd.c \ + libnvdimmd.c \ + util.c \ + ../util/log.c \ + ../util/json.c \ + ../ndctl/util/json-smart.c + +nvdimmd_LDADD = ../ndctl/lib/libndctl.la \ + ../daxctl/lib/libdaxctl.la \ + ../libutil.a \ + $(KMOD_LIBS) \ + $(JSON_LIBS) \ + $(UUID_LIBS) \ + $(UDEV_LIBS) diff --git a/nvdimmd/nvdimmd.c b/nvdimmd/nvdimmd.c new file mode 100644 index 0000000..f451751 --- /dev/null +++ b/nvdimmd/nvdimmd.c @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2017, FUJITSU LIMITED. All rights 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. + */ + +/* + * Nvdimm daemon is used to monitor the features of over threshold events. + * It automatically searches and monitors all of the dimms which support smart + * threshold. When an over threshold event fires, it will write a notification + * into the system log. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "libnvdimmd.h" + +static int wait_threshold_notify(struct ndctl_ctx *ctx) +{ + int rc, maxfd, cnt_dimm; + struct threshold_dimm *t_dimm; + + t_dimm = calloc(NUM_MAX_DIMM, sizeof(struct threshold_dimm)); + if (!t_dimm) { + err(ctx, "t_dimm memory not allocated"); + goto out; + } + + fd_set fds; + FD_ZERO(&fds); + + cnt_dimm = get_threshold_dimm(ctx, t_dimm, &fds, &maxfd); + if (cnt_dimm == 0) { + err(ctx, "no dimm supports over threshold notification\n"); + goto out; + } + + rc = select(maxfd + 1, NULL, NULL, &fds, NULL); + if (rc < 1) { + if (rc == 0) + err(ctx, "select unexpected timeout\n"); + else + err(ctx, "select %s\n", strerror(errno)); + goto out; + } + + log_notify(ctx, t_dimm, cnt_dimm, fds, rc); + + free(t_dimm); + return 0; + +out: + return 1; +} + +static void nvdimmd_log_init(struct ndctl_ctx *ctx, int priority, + const char *owner, const char *log_env) +{ + log_init(&ctx->ctx, owner, log_env); + ndctl_set_log_priority(ctx, priority); + if (strcmp(nvdimmd_cf->logfile, "syslog") == 0) + ndctl_set_log_fn(ctx, log_syslog); + else + ndctl_set_log_fn(ctx, log_file); +} + +int main(void) +{ + if (daemon(0, 0) != 0) { + syslog(LOG_ERR, "nvdimmd error: daemon start failed\n"); + exit(EXIT_FAILURE); + } + struct ndctl_ctx *ctx; + int rc, ret = 0; + const char *conf_path = "/etc/nvdimmd/nvdimmd.conf"; + + syslog(LOG_INFO, "nvdimmd: started\n"); + + if (get_nvdimmd_conf(conf_path) != 0) { + syslog(LOG_ERR, "nvdimmd.conf error \n"); + goto out; + } + + while (ret == 0) { + rc = ndctl_new(&ctx); + if (rc) + goto out; + + nvdimmd_log_init(ctx, LOG_NOTICE, "nvdimmd", "NVDIMMD_LOG"); + ret = wait_threshold_notify(ctx); + ndctl_unref(ctx); + } + + syslog(LOG_INFO, "nvdimmd: ended\n"); + return 0; + +out: + return 1; +}