};
#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;
ptv = malloc(PTVAR_SIZE(nr, size));
if (!ptv)
- return NULL;
+ return errno;
ptv->data_size = size;
ptv->nr_counters = nr;
ptv->nr_used = 0;
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. */
/* Get a reference to this thread's variable. */
void *
ptvar_get(
- struct ptvar *ptv)
+ struct ptvar *ptv,
+ int *retp)
{
void *p;
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 = 0;
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);
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_PTVAR_H__ */
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;
}
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,
uint64_t *count = data;
*sum += *count;
- return true;
+ return 0;
}
/* Return the approximate value of this counter. */
{
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) &&
}
/* Add all the summaries in the per-thread counter */
-static bool
+static int
xfs_add_summaries(
struct ptvar *ptv,
void *data,
total->dbytes += item->dbytes;
total->rbytes += item->rbytes;
total->agbytes += item->agbytes;
- return true;
+ return 0;
}
/*
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;
}
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. */
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)
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;
{
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;