From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 03/13] libfrog: split workqueue destroy functions
Date: Wed, 25 Sep 2019 14:33:41 -0700 [thread overview]
Message-ID: <156944722163.297677.13367863143814852108.stgit@magnolia> (raw)
In-Reply-To: <156944720314.297677.12837037497727069563.stgit@magnolia>
From: Darrick J. Wong <darrick.wong@oracle.com>
Split the workqueue destroy function into two parts -- one to signal all
the threads to exit and wait for them, and a second one that actually
destroys all the memory associated with the workqueue. This mean we can
report latent workqueue errors independent of the freeing function.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
libfrog/workqueue.c | 37 ++++++++++++++++++++++++++++++-------
libfrog/workqueue.h | 2 ++
repair/threads.c | 6 ++++++
scrub/fscounters.c | 11 ++++++++++-
scrub/inodes.c | 5 +++++
scrub/phase2.c | 5 +++++
scrub/phase4.c | 6 ++++++
scrub/read_verify.c | 1 +
scrub/spacemap.c | 5 +++++
scrub/vfs.c | 5 +++++
10 files changed, 75 insertions(+), 8 deletions(-)
diff --git a/libfrog/workqueue.c b/libfrog/workqueue.c
index 48038363..07f11a7b 100644
--- a/libfrog/workqueue.c
+++ b/libfrog/workqueue.c
@@ -82,6 +82,7 @@ workqueue_create(
goto out_mutex;
}
wq->terminate = false;
+ wq->terminated = false;
for (i = 0; i < nr_workers; i++) {
err = pthread_create(&wq->threads[i], NULL, workqueue_thread,
@@ -119,6 +120,8 @@ workqueue_add(
struct workqueue_item *wi;
int ret;
+ assert(!wq->terminated);
+
if (wq->thread_count == 0) {
func(wq, index, arg);
return 0;
@@ -157,22 +160,42 @@ workqueue_add(
/*
* Wait for all pending work items to be processed and tear down the
- * workqueue.
+ * workqueue thread pool.
*/
-void
-workqueue_destroy(
+int
+workqueue_terminate(
struct workqueue *wq)
{
unsigned int i;
+ int ret;
+
+ pthread_mutex_lock(&wq->lock);
+ wq->terminate = true;
+ pthread_mutex_unlock(&wq->lock);
+
+ ret = pthread_cond_broadcast(&wq->wakeup);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < wq->thread_count; i++) {
+ ret = pthread_join(wq->threads[i], NULL);
+ if (ret)
+ return ret;
+ }
pthread_mutex_lock(&wq->lock);
- wq->terminate = 1;
+ wq->terminated = true;
pthread_mutex_unlock(&wq->lock);
- pthread_cond_broadcast(&wq->wakeup);
+ return 0;
+}
- for (i = 0; i < wq->thread_count; i++)
- pthread_join(wq->threads[i], NULL);
+/* Tear down the workqueue. */
+void
+workqueue_destroy(
+ struct workqueue *wq)
+{
+ assert(wq->terminated);
free(wq->threads);
pthread_mutex_destroy(&wq->lock);
diff --git a/libfrog/workqueue.h b/libfrog/workqueue.h
index a1f3a57c..a56d1cf1 100644
--- a/libfrog/workqueue.h
+++ b/libfrog/workqueue.h
@@ -30,12 +30,14 @@ struct workqueue {
unsigned int item_count;
unsigned int thread_count;
bool terminate;
+ bool terminated;
};
int workqueue_create(struct workqueue *wq, void *wq_ctx,
unsigned int nr_workers);
int workqueue_add(struct workqueue *wq, workqueue_func_t fn,
uint32_t index, void *arg);
+int workqueue_terminate(struct workqueue *wq);
void workqueue_destroy(struct workqueue *wq);
#endif /* __LIBFROG_WORKQUEUE_H__ */
diff --git a/repair/threads.c b/repair/threads.c
index d2190920..9b7241e3 100644
--- a/repair/threads.c
+++ b/repair/threads.c
@@ -56,5 +56,11 @@ void
destroy_work_queue(
struct workqueue *wq)
{
+ int err;
+
+ err = workqueue_terminate(wq);
+ if (err)
+ do_error(_("cannot terminate worker item, error = [%d] %s\n"),
+ err, strerror(err));
workqueue_destroy(wq);
}
diff --git a/scrub/fscounters.c b/scrub/fscounters.c
index 669c5ab0..98aa3826 100644
--- a/scrub/fscounters.c
+++ b/scrub/fscounters.c
@@ -102,7 +102,7 @@ xfs_count_all_inodes(
struct xfs_count_inodes *ci;
xfs_agnumber_t agno;
struct workqueue wq;
- bool moveon;
+ bool moveon = true;
int ret;
ci = calloc(1, sizeof(struct xfs_count_inodes) +
@@ -126,8 +126,17 @@ xfs_count_all_inodes(
break;
}
}
+
+ ret = workqueue_terminate(&wq);
+ if (ret) {
+ moveon = false;
+ str_liberror(ctx, ret, _("finishing icount work"));
+ }
workqueue_destroy(&wq);
+ if (!moveon)
+ goto out_free;
+
for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++)
*count += ci->counters[agno];
moveon = ci->moveon;
diff --git a/scrub/inodes.c b/scrub/inodes.c
index 644a6372..c459a3b4 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -256,6 +256,11 @@ xfs_scan_all_inodes(
}
}
+ ret = workqueue_terminate(&wq);
+ if (ret) {
+ si.moveon = false;
+ str_liberror(ctx, ret, _("finishing bulkstat work"));
+ }
workqueue_destroy(&wq);
return si.moveon;
diff --git a/scrub/phase2.c b/scrub/phase2.c
index 1d2244a4..d92b7e29 100644
--- a/scrub/phase2.c
+++ b/scrub/phase2.c
@@ -161,6 +161,11 @@ xfs_scan_metadata(
}
out:
+ ret = workqueue_terminate(&wq);
+ if (ret) {
+ moveon = false;
+ str_liberror(ctx, ret, _("finishing scrub work"));
+ }
workqueue_destroy(&wq);
return moveon;
}
diff --git a/scrub/phase4.c b/scrub/phase4.c
index 903da6d2..eb30c189 100644
--- a/scrub/phase4.c
+++ b/scrub/phase4.c
@@ -90,6 +90,12 @@ xfs_process_action_items(
if (!moveon)
break;
}
+
+ ret = workqueue_terminate(&wq);
+ if (ret) {
+ moveon = false;
+ str_liberror(ctx, ret, _("finishing repair work"));
+ }
workqueue_destroy(&wq);
pthread_mutex_lock(&ctx->lock);
diff --git a/scrub/read_verify.c b/scrub/read_verify.c
index ff4d3572..bb8f09a8 100644
--- a/scrub/read_verify.c
+++ b/scrub/read_verify.c
@@ -120,6 +120,7 @@ void
read_verify_pool_flush(
struct read_verify_pool *rvp)
{
+ workqueue_terminate(&rvp->wq);
workqueue_destroy(&rvp->wq);
}
diff --git a/scrub/spacemap.c b/scrub/spacemap.c
index 4258e318..91e8badb 100644
--- a/scrub/spacemap.c
+++ b/scrub/spacemap.c
@@ -230,6 +230,11 @@ xfs_scan_all_spacemaps(
}
}
out:
+ ret = workqueue_terminate(&wq);
+ if (ret) {
+ sbx.moveon = false;
+ str_liberror(ctx, ret, _("finishing fsmap work"));
+ }
workqueue_destroy(&wq);
return sbx.moveon;
diff --git a/scrub/vfs.c b/scrub/vfs.c
index 0cff2e3f..49d689af 100644
--- a/scrub/vfs.c
+++ b/scrub/vfs.c
@@ -250,6 +250,11 @@ scan_fs_tree(
assert(sft.nr_dirs == 0);
pthread_mutex_unlock(&sft.lock);
+ ret = workqueue_terminate(&wq);
+ if (ret) {
+ sft.moveon = false;
+ str_liberror(ctx, ret, _("finishing directory scan work"));
+ }
out_wq:
workqueue_destroy(&wq);
return sft.moveon;
next prev parent reply other threads:[~2019-09-25 21:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-25 21:33 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
2019-09-25 21:33 ` [PATCH 01/13] libfrog: fix workqueue error communication problems Darrick J. Wong
2019-09-30 19:23 ` Eric Sandeen
2019-09-30 19:29 ` Darrick J. Wong
2019-09-30 19:35 ` Eric Sandeen
2019-09-30 20:32 ` Eric Sandeen
2019-09-25 21:33 ` [PATCH 02/13] libfrog: fix missing error checking in workqueue code Darrick J. Wong
2019-09-30 20:37 ` Eric Sandeen
2019-09-25 21:33 ` Darrick J. Wong [this message]
2019-09-30 22:33 ` [PATCH 03/13] libfrog: split workqueue destroy functions Eric Sandeen
2019-09-25 21:33 ` [PATCH 04/13] xfs_scrub: redistribute read verify pool flush and destroy responsibilities Darrick J. Wong
2019-10-07 20:04 ` Eric Sandeen
2019-09-25 21:33 ` [PATCH 05/13] libfrog: fix per-thread variable error communication problems Darrick J. Wong
2019-10-07 20:37 ` Eric Sandeen
2019-09-25 21:33 ` [PATCH 06/13] libfrog: add missing per-thread variable error handling Darrick J. Wong
2019-10-09 21:16 ` Eric Sandeen
2019-10-09 21:40 ` Eric Sandeen
2019-09-25 21:34 ` [PATCH 07/13] libfrog: fix bitmap error communication problems Darrick J. Wong
2019-10-09 21:27 ` Eric Sandeen
2019-09-25 21:34 ` [PATCH 08/13] libfrog: fix missing error checking in bitmap code Darrick J. Wong
2019-10-09 21:30 ` Eric Sandeen
2019-09-25 21:34 ` [PATCH 09/13] xfs_scrub: fix per-thread counter error communication problems Darrick J. Wong
2019-10-09 21:46 ` Eric Sandeen
2019-10-10 3:05 ` Darrick J. Wong
2019-10-15 16:57 ` Eric Sandeen
2019-09-25 21:34 ` [PATCH 10/13] xfs_scrub: report all progressbar creation failures Darrick J. Wong
2019-10-09 21:47 ` Eric Sandeen
2019-09-25 21:34 ` [PATCH 11/13] xfs_scrub: check progress bar timedwait failures Darrick J. Wong
2019-10-09 21:49 ` Eric Sandeen
2019-09-25 21:34 ` [PATCH 12/13] xfs_scrub: move all the queue_subdir error reporting to callers Darrick J. Wong
2019-10-09 21:54 ` Eric Sandeen
2019-09-25 21:34 ` [PATCH 13/13] xfs_scrub: fix error handling problems in vfs.c Darrick J. Wong
2019-10-09 21:57 ` Eric Sandeen
-- strict thread matches above, loose matches on Subject: below --
2019-09-06 3:36 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
2019-09-06 3:36 ` [PATCH 03/13] libfrog: split workqueue destroy functions Darrick J. Wong
2019-08-26 21:28 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
2019-08-26 21:28 ` [PATCH 03/13] libfrog: split workqueue destroy functions Darrick J. Wong
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=156944722163.297677.13367863143814852108.stgit@magnolia \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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).