From patchwork Wed Apr 4 21:12:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10323415 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 54E2C60390 for ; Wed, 4 Apr 2018 21:21:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4442629021 for ; Wed, 4 Apr 2018 21:21:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 390B929024; Wed, 4 Apr 2018 21:21:59 +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 D99A229021 for ; Wed, 4 Apr 2018 21:21:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BC24C2252649E; Wed, 4 Apr 2018 14:21:58 -0700 (PDT) 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=192.55.52.43; helo=mga05.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 D126E22526491 for ; Wed, 4 Apr 2018 14:21:57 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Apr 2018 14:21:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,408,1517904000"; d="scan'208";a="43501247" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004.fm.intel.com with ESMTP; 04 Apr 2018 14:21:57 -0700 Subject: [ndctl PATCH 1/5] ndctl, scrub: fix ndctl_bus_wait_for_scrub_completion() From: Dan Williams To: linux-nvdimm@lists.01.org Date: Wed, 04 Apr 2018 14:12:01 -0700 Message-ID: <152287632145.29230.18008700588119765698.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152287631592.29230.11531789298631204393.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152287631592.29230.11531789298631204393.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.26 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-Virus-Scanned: ClamAV using ClamSMTP Given that we trust the kernel to increment the scrub count when transitioning from in-progress to idle it is safe to wait forever. Previously this routine was mistakenly waiting 120ms when it thought it was waiting 120 seconds, was not verifying the in-progress was cleared after a wakeup, and was not checking for the POLLMSG events that sysfs files emit. Signed-off-by: Dan Williams --- ndctl/lib/libndctl.c | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 580a450e837c..743863b5c7e7 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -1154,55 +1154,50 @@ NDCTL_EXPORT unsigned int ndctl_bus_get_scrub_count(struct ndctl_bus *bus) NDCTL_EXPORT int ndctl_bus_wait_for_scrub_completion(struct ndctl_bus *bus) { struct ndctl_ctx *ctx = ndctl_bus_get_ctx(bus); - unsigned int tmo = 120, scrub_count; + unsigned int scrub_count; char buf[SYSFS_ATTR_SIZE]; - char in_progress = '\0'; struct pollfd fds; + char in_progress; int fd = 0, rc; fd = open(bus->scrub_path, O_RDONLY|O_CLOEXEC); + memset(&fds, 0, sizeof(fds)); fds.fd = fd; - fds.events = POLLPRI | POLLIN; - do { + for (;;) { rc = sysfs_read_attr(ctx, bus->scrub_path, buf); - if (rc < 0) + if (rc < 0) { + rc = -EOPNOTSUPP; break; + } rc = sscanf(buf, "%u%c", &scrub_count, &in_progress); - if (rc < 0) + if (rc < 0) { + rc = -EOPNOTSUPP; break; - else if (rc <= 1) { + } + + if (rc == 1) { /* scrub complete, break successfully */ rc = 0; break; } else if (rc == 2 && in_progress == '+') { /* scrub in progress, wait */ - rc = poll(&fds, 1, tmo); + rc = poll(&fds, 1, -1); if (rc < 0) { - dbg(ctx, "poll error: %d\n", errno); - break; - } else if (rc == 0) { - dbg(ctx, "poll timeout after: %d seconds", tmo); - rc = -ENXIO; + rc = -errno; + dbg(ctx, "poll error: %s\n", strerror(errno)); break; } - if (fds.revents & (POLLERR | POLLHUP | POLLNVAL)) { - dbg(ctx, "poll error, revents: %d\n", - fds.revents); - rc = -ENXIO; - break; - } - } else { - /* unknown condition */ - rc = -ENXIO; - break; + dbg(ctx, "poll wake: revents: %d\n", fds.revents); + pread(fd, buf, 1, 0); + fds.revents = 0; } - } while (in_progress); + } dbg(ctx, "bus%d: scrub complete\n", ndctl_bus_get_id(bus)); if (fd) close (fd); - return rc < 0 ? -ENXIO : 0; + return rc; } static int ndctl_bind(struct ndctl_ctx *ctx, struct kmod_module *module,