From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net, darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 05/13] libfrog: fix per-thread variable error communication problems
Date: Mon, 26 Aug 2019 14:28:49 -0700 [thread overview]
Message-ID: <156685492930.2841546.18320009091314757671.stgit@magnolia> (raw)
In-Reply-To: <156685489821.2841546.10616502094098044568.stgit@magnolia>
From: Darrick J. Wong <darrick.wong@oracle.com>
Convert all the per-thread variable functions away from the libc-style
indirect errno return to return error values directly to callers.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
include/ptvar.h | 8 ++++----
libfrog/ptvar.c | 26 +++++++++++++++-----------
scrub/counter.c | 13 ++++++++-----
scrub/phase7.c | 24 ++++++++++++++++--------
scrub/read_verify.c | 16 +++++++++++-----
5 files changed, 54 insertions(+), 33 deletions(-)
diff --git a/include/ptvar.h b/include/ptvar.h
index 90823da9..0af3f35e 100644
--- a/include/ptvar.h
+++ b/include/ptvar.h
@@ -8,11 +8,11 @@
struct ptvar;
-typedef bool (*ptvar_iter_fn)(struct ptvar *ptv, void *data, void *foreach_arg);
+typedef int (*ptvar_iter_fn)(struct ptvar *ptv, void *data, void *foreach_arg);
-struct ptvar *ptvar_init(size_t nr, size_t size);
+int ptvar_alloc(size_t nr, size_t size, struct ptvar **pptv);
void ptvar_free(struct ptvar *ptv);
-void *ptvar_get(struct ptvar *ptv);
-bool ptvar_foreach(struct ptvar *ptv, ptvar_iter_fn fn, void *foreach_arg);
+void *ptvar_get(struct ptvar *ptv, int *ret);
+int ptvar_foreach(struct ptvar *ptv, ptvar_iter_fn fn, void *foreach_arg);
#endif /* LIBFROG_PERCPU_H_ */
diff --git a/libfrog/ptvar.c b/libfrog/ptvar.c
index c9296835..6cb58208 100644
--- a/libfrog/ptvar.c
+++ b/libfrog/ptvar.c
@@ -33,11 +33,12 @@ struct ptvar {
};
#define PTVAR_SIZE(nr, sz) (sizeof(struct ptvar) + ((nr) * (size)))
-/* Initialize per-thread counter. */
-struct ptvar *
-ptvar_init(
+/* Allocate a new per-thread counter. */
+int
+ptvar_alloc(
size_t nr,
- size_t size)
+ size_t size,
+ struct ptvar **pptv)
{
struct ptvar *ptv;
int ret;
@@ -49,7 +50,7 @@ ptvar_init(
ptv = malloc(PTVAR_SIZE(nr, size));
if (!ptv)
- return NULL;
+ return errno;
ptv->data_size = size;
ptv->nr_counters = nr;
ptv->nr_used = 0;
@@ -60,13 +61,14 @@ ptvar_init(
ret = pthread_key_create(&ptv->key, NULL);
if (ret)
goto out_mutex;
- return ptv;
+ *pptv = ptv;
+ return 0;
out_mutex:
pthread_mutex_destroy(&ptv->lock);
out:
free(ptv);
- return NULL;
+ return ret;
}
/* Free per-thread counter. */
@@ -82,7 +84,8 @@ ptvar_free(
/* Get a reference to this thread's variable. */
void *
ptvar_get(
- struct ptvar *ptv)
+ struct ptvar *ptv,
+ int *retp)
{
void *p;
@@ -94,23 +97,24 @@ ptvar_get(
pthread_setspecific(ptv->key, p);
pthread_mutex_unlock(&ptv->lock);
}
+ *retp = 0;
return p;
}
/* Iterate all of the per-thread variables. */
-bool
+int
ptvar_foreach(
struct ptvar *ptv,
ptvar_iter_fn fn,
void *foreach_arg)
{
size_t i;
- bool ret = true;
+ int ret;
pthread_mutex_lock(&ptv->lock);
for (i = 0; i < ptv->nr_used; i++) {
ret = fn(ptv, &ptv->data[i * ptv->data_size], foreach_arg);
- if (!ret)
+ if (ret)
break;
}
pthread_mutex_unlock(&ptv->lock);
diff --git a/scrub/counter.c b/scrub/counter.c
index 4800e751..76a40532 100644
--- a/scrub/counter.c
+++ b/scrub/counter.c
@@ -32,12 +32,13 @@ ptcounter_init(
size_t nr)
{
struct ptcounter *p;
+ int ret;
p = malloc(sizeof(struct ptcounter));
if (!p)
return NULL;
- p->var = ptvar_init(nr, sizeof(uint64_t));
- if (!p->var) {
+ ret = ptvar_alloc(nr, sizeof(uint64_t), &p->var);
+ if (ret) {
free(p);
return NULL;
}
@@ -60,12 +61,14 @@ ptcounter_add(
int64_t nr)
{
uint64_t *p;
+ int ret;
- p = ptvar_get(ptc->var);
+ p = ptvar_get(ptc->var, &ret);
+ assert(ret == 0);
*p += nr;
}
-static bool
+static int
ptcounter_val_helper(
struct ptvar *ptv,
void *data,
@@ -75,7 +78,7 @@ ptcounter_val_helper(
uint64_t *count = data;
*sum += *count;
- return true;
+ return 0;
}
/* Return the approximate value of this counter. */
diff --git a/scrub/phase7.c b/scrub/phase7.c
index b3156fdf..cf88e30f 100644
--- a/scrub/phase7.c
+++ b/scrub/phase7.c
@@ -36,8 +36,13 @@ xfs_record_block_summary(
{
struct summary_counts *counts;
unsigned long long len;
+ int ret;
- counts = ptvar_get((struct ptvar *)arg);
+ counts = ptvar_get((struct ptvar *)arg, &ret);
+ if (ret) {
+ str_liberror(ctx, ret, _("retrieving summary counts"));
+ return false;
+ }
if (fsmap->fmr_device == ctx->fsinfo.fs_logdev)
return true;
if ((fsmap->fmr_flags & FMR_OF_SPECIAL_OWNER) &&
@@ -68,7 +73,7 @@ xfs_record_block_summary(
}
/* Add all the summaries in the per-thread counter */
-static bool
+static int
xfs_add_summaries(
struct ptvar *ptv,
void *data,
@@ -80,7 +85,7 @@ xfs_add_summaries(
total->dbytes += item->dbytes;
total->rbytes += item->rbytes;
total->agbytes += item->agbytes;
- return true;
+ return 0;
}
/*
@@ -131,9 +136,10 @@ xfs_scan_summary(
return false;
}
- ptvar = ptvar_init(scrub_nproc(ctx), sizeof(struct summary_counts));
- if (!ptvar) {
- str_errno(ctx, ctx->mntpoint);
+ error = ptvar_alloc(scrub_nproc(ctx), sizeof(struct summary_counts),
+ &ptvar);
+ if (error) {
+ str_liberror(ctx, error, _("setting up block counter"));
return false;
}
@@ -141,9 +147,11 @@ xfs_scan_summary(
moveon = xfs_scan_all_spacemaps(ctx, xfs_record_block_summary, ptvar);
if (!moveon)
goto out_free;
- moveon = ptvar_foreach(ptvar, xfs_add_summaries, &totalcount);
- if (!moveon)
+ error = ptvar_foreach(ptvar, xfs_add_summaries, &totalcount);
+ if (error) {
+ str_liberror(ctx, error, _("counting blocks"));
goto out_free;
+ }
ptvar_free(ptvar);
/* Scan the whole fs. */
diff --git a/scrub/read_verify.c b/scrub/read_verify.c
index 1e38a1a7..2cd4edfa 100644
--- a/scrub/read_verify.c
+++ b/scrub/read_verify.c
@@ -91,9 +91,9 @@ read_verify_pool_init(
rvp->ctx = ctx;
rvp->disk = disk;
rvp->ioerr_fn = ioerr_fn;
- rvp->rvstate = ptvar_init(submitter_threads,
- sizeof(struct read_verify));
- if (rvp->rvstate == NULL)
+ error = ptvar_alloc(submitter_threads, sizeof(struct read_verify),
+ &rvp->rvstate);
+ if (error)
goto out_counter;
/* Run in the main thread if we only want one thread. */
if (nproc == 1)
@@ -220,9 +220,12 @@ read_verify_schedule_io(
struct read_verify *rv;
uint64_t req_end;
uint64_t rv_end;
+ int ret;
assert(rvp->readbuf);
- rv = ptvar_get(rvp->rvstate);
+ rv = ptvar_get(rvp->rvstate, &ret);
+ if (ret)
+ return false;
req_end = start + length;
rv_end = rv->io_start + rv->io_length;
@@ -259,9 +262,12 @@ read_verify_force_io(
{
struct read_verify *rv;
bool moveon;
+ int ret;
assert(rvp->readbuf);
- rv = ptvar_get(rvp->rvstate);
+ rv = ptvar_get(rvp->rvstate, &ret);
+ if (ret)
+ return false;
if (rv->io_length == 0)
return true;
next prev parent reply other threads:[~2019-08-26 21:28 UTC|newest]
Thread overview: 17+ 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 ` Darrick J. Wong [this message]
2019-08-26 21:28 ` [PATCH 06/13] libfrog: add missing per-thread variable error handling Darrick J. Wong
2019-08-26 21:29 ` [PATCH 07/13] libfrog: fix bitmap error communication problems 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 05/13] libfrog: fix per-thread variable error communication problems Darrick J. Wong
2019-09-25 21:33 [PATCH 00/13] libfrog/xfs_scrub: fix error handling Darrick J. Wong
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
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=156685492930.2841546.18320009091314757671.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.