From patchwork Thu Jun 18 00:09:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 6632131 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 69547C0020 for ; Thu, 18 Jun 2015 00:12:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9B46F206A1 for ; Thu, 18 Jun 2015 00:12:21 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id A9A1920696 for ; Thu, 18 Jun 2015 00:12:20 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9F1971828E8; Wed, 17 Jun 2015 17:12:20 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by ml01.01.org (Postfix) with ESMTP id 628451828C6 for ; Wed, 17 Jun 2015 17:12:19 -0700 (PDT) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 17 Jun 2015 17:12:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,636,1427785200"; d="scan'208";a="712952983" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.23.232.36]) by orsmga001.jf.intel.com with ESMTP; 17 Jun 2015 17:12:19 -0700 Subject: [ndctl PATCH 5/6] ndctl: improve module binding debug From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 17 Jun 2015 20:09:38 -0400 Message-ID: <20150618000938.13255.85898.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <20150618000139.13255.82894.stgit@dwillia2-desk3.amr.corp.intel.com> References: <20150618000139.13255.82894.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.17.1-8-g92dd MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Given that we need to try every driver on an nvdimm bus the default error message reporting from sysfs_write_attr() is not very meaningful. Instead we really care about the case where the bind attempt failed completely. Suppress debug messages from sysfs_write_attr() when called by ndctl_bind(). Signed-off-by: Dan Williams --- lib/libndctl.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/libndctl.c b/lib/libndctl.c index 680adeac3fd2..b45fd56a0e7b 100644 --- a/lib/libndctl.c +++ b/lib/libndctl.c @@ -662,7 +662,8 @@ static int sysfs_read_attr(struct ndctl_ctx *ctx, const char *path, char *buf) return 0; } -static int sysfs_write_attr(struct ndctl_ctx *ctx, const char *path, const char *buf) +static int __sysfs_write_attr(struct ndctl_ctx *ctx, const char *path, + const char *buf, int quiet) { int fd = open(path, O_WRONLY|O_CLOEXEC); int n, len = strlen(buf) + 1; @@ -674,13 +675,26 @@ static int sysfs_write_attr(struct ndctl_ctx *ctx, const char *path, const char n = write(fd, buf, len); close(fd); if (n < len) { - dbg(ctx, "failed to write %s to %s: %s\n", buf, path, - strerror(errno)); + if (!quiet) + dbg(ctx, "failed to write %s to %s: %s\n", buf, path, + strerror(errno)); return -1; } return 0; } +static int sysfs_write_attr(struct ndctl_ctx *ctx, const char *path, + const char *buf) +{ + return __sysfs_write_attr(ctx, path, buf, 0); +} + +static int sysfs_write_attr_quiet(struct ndctl_ctx *ctx, const char *path, + const char *buf) +{ + return __sysfs_write_attr(ctx, path, buf, 1); +} + static char *__dev_path(char *type, int major, int minor, int parent) { char *path, *dev_path; @@ -2745,7 +2759,7 @@ static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module, continue; } - rc = sysfs_write_attr(ctx, drv_path, devname); + rc = sysfs_write_attr_quiet(ctx, drv_path, devname); free(drv_path); if (rc == 0) break;