From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 06/13] libfrog: add missing per-thread variable error handling
Date: Mon, 26 Aug 2019 14:28:55 -0700 [thread overview]
Message-ID: <156685493551.2841546.4155863321510387304.stgit@magnolia> (raw)
In-Reply-To: <156685489821.2841546.10616502094098044568.stgit@magnolia>
From: Darrick J. Wong <darrick.wong@oracle.com>
Add missing return value checks for everything that the per-thread
variable code calls.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
libfrog/ptvar.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/libfrog/ptvar.c b/libfrog/ptvar.c
index 6cb58208..ecbbea61 100644
--- a/libfrog/ptvar.c
+++ b/libfrog/ptvar.c
@@ -44,8 +44,12 @@ ptvar_alloc(
int ret;
#ifdef _SC_LEVEL1_DCACHE_LINESIZE
+ long l1_dcache;
+
/* Try to prevent cache pingpong by aligning to cacheline size. */
- size = max(size, sysconf(_SC_LEVEL1_DCACHE_LINESIZE));
+ l1_dcache = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ if (l1_dcache > 0)
+ size = roundup(size, l1_dcache);
#endif
ptv = malloc(PTVAR_SIZE(nr, size));
@@ -88,17 +92,30 @@ ptvar_get(
int *retp)
{
void *p;
+ int ret;
p = pthread_getspecific(ptv->key);
if (!p) {
- pthread_mutex_lock(&ptv->lock);
+ ret = pthread_mutex_lock(&ptv->lock);
+ if (ret) {
+ *retp = ret;
+ return NULL;
+ }
assert(ptv->nr_used < ptv->nr_counters);
p = &ptv->data[(ptv->nr_used++) * ptv->data_size];
- pthread_setspecific(ptv->key, p);
+ ret = pthread_setspecific(ptv->key, p);
+ if (ret)
+ goto out_unlock;
pthread_mutex_unlock(&ptv->lock);
}
*retp = 0;
return p;
+
+out_unlock:
+ ptv->nr_used--;
+ pthread_mutex_unlock(&ptv->lock);
+ *retp = ret;
+ return NULL;
}
/* Iterate all of the per-thread variables. */
@@ -111,7 +128,10 @@ ptvar_foreach(
size_t i;
int ret;
- pthread_mutex_lock(&ptv->lock);
+ ret = pthread_mutex_lock(&ptv->lock);
+ if (ret)
+ return ret;
+
for (i = 0; i < ptv->nr_used; i++) {
ret = fn(ptv, &ptv->data[i * ptv->data_size], foreach_arg);
if (ret)
next prev parent reply other threads:[~2019-08-26 21:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-26 21:28 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
2019-08-26 21:28 ` [PATCH 01/13] libfrog: fix workqueue error communication problems Darrick J. Wong
2019-08-26 21:28 ` [PATCH 02/13] libfrog: fix missing error checking in workqueue code Darrick J. Wong
2019-08-26 21:28 ` [PATCH 03/13] libfrog: split workqueue destroy functions Darrick J. Wong
2019-08-26 21:28 ` [PATCH 04/13] xfs_scrub: redistribute read verify pool flush and destroy responsibilities Darrick J. Wong
2019-08-26 21:28 ` [PATCH 05/13] libfrog: fix per-thread variable error communication problems Darrick J. Wong
2019-08-26 21:28 ` Darrick J. Wong [this message]
2019-08-26 21:29 ` [PATCH 07/13] libfrog: fix bitmap " Darrick J. Wong
2019-08-26 21:29 ` [PATCH 08/13] libfrog: fix missing error checking in bitmap code Darrick J. Wong
2019-08-26 21:29 ` [PATCH 09/13] xfs_scrub: fix per-thread counter error communication problems Darrick J. Wong
2019-08-26 21:29 ` [PATCH 10/13] xfs_scrub: report all progressbar creation failures Darrick J. Wong
2019-08-26 21:29 ` [PATCH 11/13] xfs_scrub: check progress bar timedwait failures Darrick J. Wong
2019-08-26 21:29 ` [PATCH 12/13] xfs_scrub: move all the queue_subdir error reporting to callers Darrick J. Wong
2019-08-26 21:29 ` [PATCH 13/13] xfs_scrub: fix error handling problems in vfs.c Darrick J. Wong
2019-09-06 3:36 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
2019-09-06 3:36 ` [PATCH 06/13] libfrog: add missing per-thread variable " Darrick J. Wong
2019-09-25 21:33 [PATCH 00/13] libfrog/xfs_scrub: fix " Darrick J. Wong
2019-09-25 21:33 ` [PATCH 06/13] libfrog: add missing per-thread variable " Darrick J. Wong
2019-10-09 21:16 ` Eric Sandeen
2019-10-09 21:40 ` Eric Sandeen
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=156685493551.2841546.4155863321510387304.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).