From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 02/13] libfrog: fix missing error checking in workqueue code
Date: Thu, 05 Sep 2019 20:36:27 -0700 [thread overview]
Message-ID: <156774098739.2644719.3779575154856756310.stgit@magnolia> (raw)
In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia>
From: Darrick J. Wong <darrick.wong@oracle.com>
Fix all the places in the workqueue code where we fail to check return
values and blindly keep going when we shouldn't.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
libfrog/workqueue.c | 32 ++++++++++++++++++++++++++++----
1 file changed, 28 insertions(+), 4 deletions(-)
diff --git a/libfrog/workqueue.c b/libfrog/workqueue.c
index a806da3e..48038363 100644
--- a/libfrog/workqueue.c
+++ b/libfrog/workqueue.c
@@ -67,12 +67,20 @@ workqueue_create(
int err = 0;
memset(wq, 0, sizeof(*wq));
- pthread_cond_init(&wq->wakeup, NULL);
- pthread_mutex_init(&wq->lock, NULL);
+ err = pthread_cond_init(&wq->wakeup, NULL);
+ if (err)
+ return err;
+ err = pthread_mutex_init(&wq->lock, NULL);
+ if (err)
+ goto out_cond;
wq->wq_ctx = wq_ctx;
wq->thread_count = nr_workers;
wq->threads = malloc(nr_workers * sizeof(pthread_t));
+ if (!wq->threads) {
+ err = errno;
+ goto out_mutex;
+ }
wq->terminate = false;
for (i = 0; i < nr_workers; i++) {
@@ -82,9 +90,19 @@ workqueue_create(
break;
}
+ /*
+ * If we encounter errors here, we have to signal and then wait for all
+ * the threads that may have been started running before we can destroy
+ * the workqueue.
+ */
if (err)
workqueue_destroy(wq);
return err;
+out_mutex:
+ pthread_mutex_destroy(&wq->lock);
+out_cond:
+ pthread_cond_destroy(&wq->wakeup);
+ return err;
}
/*
@@ -99,6 +117,7 @@ workqueue_add(
void *arg)
{
struct workqueue_item *wi;
+ int ret;
if (wq->thread_count == 0) {
func(wq, index, arg);
@@ -118,9 +137,11 @@ workqueue_add(
/* Now queue the new work structure to the work queue. */
pthread_mutex_lock(&wq->lock);
if (wq->next_item == NULL) {
- wq->next_item = wi;
assert(wq->item_count == 0);
- pthread_cond_signal(&wq->wakeup);
+ ret = pthread_cond_signal(&wq->wakeup);
+ if (ret)
+ goto out_item;
+ wq->next_item = wi;
} else {
wq->last_item->next = wi;
}
@@ -129,6 +150,9 @@ workqueue_add(
pthread_mutex_unlock(&wq->lock);
return 0;
+out_item:
+ free(wi);
+ return ret;
}
/*
next prev parent reply other threads:[~2019-09-06 3:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-06 3:36 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
2019-09-06 3:36 ` [PATCH 01/13] libfrog: fix workqueue error communication problems Darrick J. Wong
2019-09-06 3:36 ` Darrick J. Wong [this message]
2019-09-06 3:36 ` [PATCH 03/13] libfrog: split workqueue destroy functions Darrick J. Wong
2019-09-06 3:36 ` [PATCH 04/13] xfs_scrub: redistribute read verify pool flush and destroy responsibilities Darrick J. Wong
2019-09-06 3:36 ` [PATCH 05/13] libfrog: fix per-thread variable error communication problems Darrick J. Wong
2019-09-06 3:36 ` [PATCH 06/13] libfrog: add missing per-thread variable error handling Darrick J. Wong
2019-09-06 3:36 ` [PATCH 07/13] libfrog: fix bitmap error communication problems Darrick J. Wong
2019-09-06 3:37 ` [PATCH 08/13] libfrog: fix missing error checking in bitmap code Darrick J. Wong
2019-09-06 3:37 ` [PATCH 09/13] xfs_scrub: fix per-thread counter error communication problems Darrick J. Wong
2019-09-06 3:37 ` [PATCH 10/13] xfs_scrub: report all progressbar creation failures Darrick J. Wong
2019-09-06 3:37 ` [PATCH 11/13] xfs_scrub: check progress bar timedwait failures Darrick J. Wong
2019-09-06 3:37 ` [PATCH 12/13] xfs_scrub: move all the queue_subdir error reporting to callers Darrick J. Wong
2019-09-06 3:37 ` [PATCH 13/13] xfs_scrub: fix error handling problems in vfs.c Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2019-09-25 21:33 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
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-08-26 21:28 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
2019-08-26 21:28 ` [PATCH 02/13] libfrog: fix missing error checking in workqueue code 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=156774098739.2644719.3779575154856756310.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).