aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2019-11-06 17:32:33 -0500
committerEric Sandeen <sandeen@sandeen.net>2019-11-06 17:32:33 -0500
commitbaed134d7c25d0ea247046ad61cff16f19de541f (patch)
treedbc7c3eb014ea5f46ed61ae9086f6e308445059f
parentde5d20ece73f57942a68693c89edfc15969ea5ab (diff)
downloadxfsprogs-dev-baed134d7c25d0ea247046ad61cff16f19de541f.tar.gz
libfrog: convert workqueue.c functions to negative error codes
Convert libfrog functions to return negative error codes like libxfs does. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
-rw-r--r--libfrog/workqueue.c25
-rw-r--r--repair/threads.c6
-rw-r--r--scrub/fscounters.c6
-rw-r--r--scrub/inodes.c6
-rw-r--r--scrub/phase2.c8
-rw-r--r--scrub/phase4.c6
-rw-r--r--scrub/read_verify.c6
-rw-r--r--scrub/spacemap.c10
-rw-r--r--scrub/vfs.c6
9 files changed, 40 insertions, 39 deletions
diff --git a/libfrog/workqueue.c b/libfrog/workqueue.c
index a93bba3d30..fe3de42893 100644
--- a/libfrog/workqueue.c
+++ b/libfrog/workqueue.c
@@ -56,7 +56,7 @@ workqueue_thread(void *arg)
return NULL;
}
-/* Allocate a work queue and threads. */
+/* Allocate a work queue and threads. Returns zero or negative error code. */
int
workqueue_create(
struct workqueue *wq,
@@ -67,10 +67,10 @@ workqueue_create(
int err = 0;
memset(wq, 0, sizeof(*wq));
- err = pthread_cond_init(&wq->wakeup, NULL);
+ err = -pthread_cond_init(&wq->wakeup, NULL);
if (err)
return err;
- err = pthread_mutex_init(&wq->lock, NULL);
+ err = -pthread_mutex_init(&wq->lock, NULL);
if (err)
goto out_cond;
@@ -78,14 +78,14 @@ workqueue_create(
wq->thread_count = nr_workers;
wq->threads = malloc(nr_workers * sizeof(pthread_t));
if (!wq->threads) {
- err = errno;
+ err = -errno;
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,
+ err = -pthread_create(&wq->threads[i], NULL, workqueue_thread,
wq);
if (err)
break;
@@ -107,8 +107,9 @@ out_cond:
}
/*
- * Create a work item consisting of a function and some arguments and
- * schedule the work item to be run via the thread pool.
+ * Create a work item consisting of a function and some arguments and schedule
+ * the work item to be run via the thread pool. Returns zero or a negative
+ * error code.
*/
int
workqueue_add(
@@ -129,7 +130,7 @@ workqueue_add(
wi = malloc(sizeof(struct workqueue_item));
if (!wi)
- return errno;
+ return -errno;
wi->function = func;
wi->index = index;
@@ -141,7 +142,7 @@ workqueue_add(
pthread_mutex_lock(&wq->lock);
if (wq->next_item == NULL) {
assert(wq->item_count == 0);
- ret = pthread_cond_signal(&wq->wakeup);
+ ret = -pthread_cond_signal(&wq->wakeup);
if (ret) {
pthread_mutex_unlock(&wq->lock);
free(wi);
@@ -160,7 +161,7 @@ workqueue_add(
/*
* Wait for all pending work items to be processed and tear down the
- * workqueue thread pool.
+ * workqueue thread pool. Returns zero or a negative error code.
*/
int
workqueue_terminate(
@@ -173,12 +174,12 @@ workqueue_terminate(
wq->terminate = true;
pthread_mutex_unlock(&wq->lock);
- ret = pthread_cond_broadcast(&wq->wakeup);
+ 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);
+ ret = -pthread_join(wq->threads[i], NULL);
if (ret)
return ret;
}
diff --git a/repair/threads.c b/repair/threads.c
index 9b7241e3d1..45ca2dd58a 100644
--- a/repair/threads.c
+++ b/repair/threads.c
@@ -31,7 +31,7 @@ create_work_queue(
{
int err;
- err = workqueue_create(wq, mp, nworkers);
+ err = -workqueue_create(wq, mp, nworkers);
if (err)
do_error(_("cannot create worker threads, error = [%d] %s\n"),
err, strerror(err));
@@ -46,7 +46,7 @@ queue_work(
{
int err;
- err = workqueue_add(wq, func, agno, arg);
+ err = -workqueue_add(wq, func, agno, arg);
if (err)
do_error(_("cannot allocate worker item, error = [%d] %s\n"),
err, strerror(err));
@@ -58,7 +58,7 @@ destroy_work_queue(
{
int err;
- err = workqueue_terminate(wq);
+ err = -workqueue_terminate(wq);
if (err)
do_error(_("cannot terminate worker item, error = [%d] %s\n"),
err, strerror(err));
diff --git a/scrub/fscounters.c b/scrub/fscounters.c
index a6b62f34ec..f9d64f8c00 100644
--- a/scrub/fscounters.c
+++ b/scrub/fscounters.c
@@ -86,18 +86,18 @@ scrub_count_all_inodes(
if (!ci)
return errno;
- ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
+ ret = -workqueue_create(&wq, (struct xfs_mount *)ctx,
scrub_nproc_workqueue(ctx));
if (ret)
goto out_free;
for (agno = 0; agno < ctx->mnt.fsgeom.agcount && !ci->error; agno++) {
- ret = workqueue_add(&wq, count_ag_inodes, agno, ci);
+ ret = -workqueue_add(&wq, count_ag_inodes, agno, ci);
if (ret)
break;
}
- ret2 = workqueue_terminate(&wq);
+ ret2 = -workqueue_terminate(&wq);
if (!ret && ret2)
ret = ret2;
workqueue_destroy(&wq);
diff --git a/scrub/inodes.c b/scrub/inodes.c
index e1fafc9fc0..099489d837 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -232,7 +232,7 @@ scrub_scan_all_inodes(
struct workqueue wq;
int ret;
- ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
+ ret = -workqueue_create(&wq, (struct xfs_mount *)ctx,
scrub_nproc_workqueue(ctx));
if (ret) {
str_liberror(ctx, ret, _("creating bulkstat workqueue"));
@@ -240,7 +240,7 @@ scrub_scan_all_inodes(
}
for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) {
- ret = workqueue_add(&wq, scan_ag_inodes, agno, &si);
+ ret = -workqueue_add(&wq, scan_ag_inodes, agno, &si);
if (ret) {
si.aborted = true;
str_liberror(ctx, ret, _("queueing bulkstat work"));
@@ -248,7 +248,7 @@ scrub_scan_all_inodes(
}
}
- ret = workqueue_terminate(&wq);
+ ret = -workqueue_terminate(&wq);
if (ret) {
si.aborted = true;
str_liberror(ctx, ret, _("finishing bulkstat work"));
diff --git a/scrub/phase2.c b/scrub/phase2.c
index 45e0d7121a..c40d9d3b17 100644
--- a/scrub/phase2.c
+++ b/scrub/phase2.c
@@ -128,7 +128,7 @@ phase2_func(
bool aborted = false;
int ret, ret2;
- ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
+ ret = -workqueue_create(&wq, (struct xfs_mount *)ctx,
scrub_nproc_workqueue(ctx));
if (ret) {
str_liberror(ctx, ret, _("creating scrub workqueue"));
@@ -149,7 +149,7 @@ phase2_func(
goto out;
for (agno = 0; !aborted && agno < ctx->mnt.fsgeom.agcount; agno++) {
- ret = workqueue_add(&wq, scan_ag_metadata, agno, &aborted);
+ ret = -workqueue_add(&wq, scan_ag_metadata, agno, &aborted);
if (ret) {
str_liberror(ctx, ret, _("queueing per-AG scrub work"));
goto out;
@@ -159,14 +159,14 @@ phase2_func(
if (aborted)
goto out;
- ret = workqueue_add(&wq, scan_fs_metadata, 0, &aborted);
+ ret = -workqueue_add(&wq, scan_fs_metadata, 0, &aborted);
if (ret) {
str_liberror(ctx, ret, _("queueing per-FS scrub work"));
goto out;
}
out:
- ret2 = workqueue_terminate(&wq);
+ ret2 = -workqueue_terminate(&wq);
if (ret2) {
str_liberror(ctx, ret2, _("finishing scrub work"));
if (!ret && ret2)
diff --git a/scrub/phase4.c b/scrub/phase4.c
index 1c1de906c1..af9b493ea9 100644
--- a/scrub/phase4.c
+++ b/scrub/phase4.c
@@ -70,7 +70,7 @@ repair_everything(
bool aborted = false;
int ret;
- ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
+ ret = -workqueue_create(&wq, (struct xfs_mount *)ctx,
scrub_nproc_workqueue(ctx));
if (ret) {
str_liberror(ctx, ret, _("creating repair workqueue"));
@@ -80,14 +80,14 @@ repair_everything(
if (action_list_length(&ctx->action_lists[agno]) == 0)
continue;
- ret = workqueue_add(&wq, repair_ag, agno, &aborted);
+ ret = -workqueue_add(&wq, repair_ag, agno, &aborted);
if (ret) {
str_liberror(ctx, ret, _("queueing repair work"));
break;
}
}
- ret = workqueue_terminate(&wq);
+ ret = -workqueue_terminate(&wq);
if (ret)
str_liberror(ctx, ret, _("finishing repair work"));
workqueue_destroy(&wq);
diff --git a/scrub/read_verify.c b/scrub/read_verify.c
index bfee3a6613..be30f2688f 100644
--- a/scrub/read_verify.c
+++ b/scrub/read_verify.c
@@ -123,7 +123,7 @@ read_verify_pool_alloc(
&rvp->rvstate);
if (ret)
goto out_counter;
- ret = workqueue_create(&rvp->wq, (struct xfs_mount *)rvp,
+ ret = -workqueue_create(&rvp->wq, (struct xfs_mount *)rvp,
verifier_threads == 1 ? 0 : verifier_threads);
if (ret)
goto out_rvstate;
@@ -156,7 +156,7 @@ int
read_verify_pool_flush(
struct read_verify_pool *rvp)
{
- return workqueue_terminate(&rvp->wq);
+ return -workqueue_terminate(&rvp->wq);
}
/* Finish up any read verification work and tear it down. */
@@ -303,7 +303,7 @@ read_verify_queue(
memcpy(tmp, rv, sizeof(*tmp));
- ret = workqueue_add(&rvp->wq, read_verify, 0, tmp);
+ ret = -workqueue_add(&rvp->wq, read_verify, 0, tmp);
if (ret) {
free(tmp);
rvp->runtime_error = ret;
diff --git a/scrub/spacemap.c b/scrub/spacemap.c
index e56f090d5e..d427049fe7 100644
--- a/scrub/spacemap.c
+++ b/scrub/spacemap.c
@@ -203,14 +203,14 @@ scrub_scan_all_spacemaps(
xfs_agnumber_t agno;
int ret;
- ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
+ ret = -workqueue_create(&wq, (struct xfs_mount *)ctx,
scrub_nproc_workqueue(ctx));
if (ret) {
str_liberror(ctx, ret, _("creating fsmap workqueue"));
return ret;
}
if (ctx->fsinfo.fs_rt) {
- ret = workqueue_add(&wq, scan_rt_rmaps,
+ ret = -workqueue_add(&wq, scan_rt_rmaps,
ctx->mnt.fsgeom.agcount + 1, &sbx);
if (ret) {
sbx.aborted = true;
@@ -219,7 +219,7 @@ scrub_scan_all_spacemaps(
}
}
if (ctx->fsinfo.fs_log) {
- ret = workqueue_add(&wq, scan_log_rmaps,
+ ret = -workqueue_add(&wq, scan_log_rmaps,
ctx->mnt.fsgeom.agcount + 2, &sbx);
if (ret) {
sbx.aborted = true;
@@ -228,7 +228,7 @@ scrub_scan_all_spacemaps(
}
}
for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) {
- ret = workqueue_add(&wq, scan_ag_rmaps, agno, &sbx);
+ ret = -workqueue_add(&wq, scan_ag_rmaps, agno, &sbx);
if (ret) {
sbx.aborted = true;
str_liberror(ctx, ret, _("queueing per-AG fsmap work"));
@@ -236,7 +236,7 @@ scrub_scan_all_spacemaps(
}
}
out:
- ret = workqueue_terminate(&wq);
+ ret = -workqueue_terminate(&wq);
if (ret) {
sbx.aborted = true;
str_liberror(ctx, ret, _("finishing fsmap work"));
diff --git a/scrub/vfs.c b/scrub/vfs.c
index c807c9b921..7692092313 100644
--- a/scrub/vfs.c
+++ b/scrub/vfs.c
@@ -97,7 +97,7 @@ queue_subdir(
new_sftd->rootdir = is_rootdir;
inc_nr_dirs(sft);
- error = workqueue_add(wq, scan_fs_dir, 0, new_sftd);
+ error = -workqueue_add(wq, scan_fs_dir, 0, new_sftd);
if (error) {
dec_nr_dirs(sft);
str_liberror(ctx, error, _("queueing directory scan work"));
@@ -242,7 +242,7 @@ scan_fs_tree(
goto out_mutex;
}
- ret = workqueue_create(&wq, (struct xfs_mount *)ctx,
+ ret = -workqueue_create(&wq, (struct xfs_mount *)ctx,
scrub_nproc_workqueue(ctx));
if (ret) {
str_liberror(ctx, ret, _("creating directory scan workqueue"));
@@ -268,7 +268,7 @@ scan_fs_tree(
assert(sft.nr_dirs == 0);
pthread_mutex_unlock(&sft.lock);
- ret = workqueue_terminate(&wq);
+ ret = -workqueue_terminate(&wq);
if (ret) {
str_liberror(ctx, ret, _("finishing directory scan work"));
goto out_wq;