From: Dan Williams <dan.j.williams@intel.com>
To: linux-nvdimm@lists.01.org
Subject: [ndctl PATCH 1/5] ndctl, scrub: fix ndctl_bus_wait_for_scrub_completion()
Date: Wed, 04 Apr 2018 14:12:01 -0700 [thread overview]
Message-ID: <152287632145.29230.18008700588119765698.stgit@dwillia2-desk3.amr.corp.intel.com> (raw)
In-Reply-To: <152287631592.29230.11531789298631204393.stgit@dwillia2-desk3.amr.corp.intel.com>
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 <dan.j.williams@intel.com>
---
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,
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
next prev parent reply other threads:[~2018-04-04 21:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-04 21:11 [ndctl PATCH 0/5] Address Range Scrub (ARS) Utilities Dan Williams
2018-04-04 21:12 ` Dan Williams [this message]
2018-04-04 21:12 ` [ndctl PATCH 2/5] ndctl, scrub: report the bus scrub state in 'ndctl list' Dan Williams
2018-04-04 21:12 ` [ndctl PATCH 3/5] ndctl, scrub: add ndctl_bus_start_scrub() Dan Williams
2018-04-04 21:12 ` [ndctl PATCH 4/5] ndctl: add new START and WAIT actions Dan Williams
2018-04-04 21:12 ` [ndctl PATCH 5/5] ndctl, scrub: add {wait, start}-scrub helper utilities Dan Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=152287632145.29230.18008700588119765698.stgit@dwillia2-desk3.amr.corp.intel.com \
--to=dan.j.williams@intel.com \
--cc=linux-nvdimm@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).