From patchwork Fri Sep 6 03:36:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134373 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 481FE76 for ; Fri, 6 Sep 2019 03:38:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2B04C2082C for ; Fri, 6 Sep 2019 03:38:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="HibyE9tG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392150AbfIFDiZ (ORCPT ); Thu, 5 Sep 2019 23:38:25 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:44410 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392145AbfIFDiZ (ORCPT ); Thu, 5 Sep 2019 23:38:25 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XpYe074291; Fri, 6 Sep 2019 03:38:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=nPXZAxhR4rl0WcHd4NOr1DWMW76YiXYk4IVYdEmaOOs=; b=HibyE9tGRO6NTQ7/7Zz7mdFey/bEYLHFczLF8UaJ7foN/23Oj/JhFSBv+j7zCeE9GXF/ kUNuU8aYJ/BulGdgYvg/cMFnJ15W9wAohxnMGM4S+Xai/uneJzww+Md4lTLOPZ/YPdns h6KvUo8qwRQnVR5oJxWuAVgLAoqfpLBWGz8C81YPHXbt/50Tyusl1U4pqwwjCzY9zKsE JIzzdkX1GO48y4wt5ceXG665PUyLVCWVFzN2Zm7HwywHWGJnuImQqVC4nQ/TacBcR+2w OCK5YSEzYAkpLASwJKwMqWFQ+SLE3JIL97I405jJ0AHjFG19eCSnn7mB/BN3IEllcGVd 7Q== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2uuf51g3b5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:38:23 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XT7X188643; Fri, 6 Sep 2019 03:36:22 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3030.oracle.com with ESMTP id 2utpmc75dh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:22 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x863aLST014977; Fri, 6 Sep 2019 03:36:22 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:36:21 -0700 Subject: [PATCH 01/13] libfrog: fix workqueue error communication problems From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:36:21 -0700 Message-ID: <156774098118.2644719.14134216746447487987.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Convert all the workqueue functions to return positive error codes so that we can move away from the libc-style indirect errno handling and towards passing error codes directly back to callers. Signed-off-by: Darrick J. Wong --- libfrog/workqueue.c | 4 ++-- scrub/fscounters.c | 5 ++--- scrub/inodes.c | 5 ++--- scrub/phase2.c | 8 +++----- scrub/phase4.c | 6 +++--- scrub/read_verify.c | 3 +-- scrub/spacemap.c | 11 ++++------- scrub/vfs.c | 3 +-- 8 files changed, 18 insertions(+), 27 deletions(-) diff --git a/libfrog/workqueue.c b/libfrog/workqueue.c index 73114773..a806da3e 100644 --- a/libfrog/workqueue.c +++ b/libfrog/workqueue.c @@ -106,8 +106,8 @@ workqueue_add( } wi = malloc(sizeof(struct workqueue_item)); - if (wi == NULL) - return ENOMEM; + if (!wi) + return errno; wi->function = func; wi->index = index; diff --git a/scrub/fscounters.c b/scrub/fscounters.c index ad467e0c..669c5ab0 100644 --- a/scrub/fscounters.c +++ b/scrub/fscounters.c @@ -115,15 +115,14 @@ xfs_count_all_inodes( scrub_nproc_workqueue(ctx)); if (ret) { moveon = false; - str_info(ctx, ctx->mntpoint, _("Could not create workqueue.")); + str_liberror(ctx, ret, _("creating icount workqueue")); goto out_free; } for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) { ret = workqueue_add(&wq, xfs_count_ag_inodes, agno, ci); if (ret) { moveon = false; - str_info(ctx, ctx->mntpoint, -_("Could not queue AG %u icount work."), agno); + str_liberror(ctx, ret, _("queueing icount work")); break; } } diff --git a/scrub/inodes.c b/scrub/inodes.c index c7aadae7..06350ec6 100644 --- a/scrub/inodes.c +++ b/scrub/inodes.c @@ -243,7 +243,7 @@ xfs_scan_all_inodes( ret = workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); if (ret) { - str_info(ctx, ctx->mntpoint, _("Could not create workqueue.")); + str_liberror(ctx, ret, _("creating bulkstat workqueue")); return false; } @@ -251,8 +251,7 @@ xfs_scan_all_inodes( ret = workqueue_add(&wq, xfs_scan_ag_inodes, agno, &si); if (ret) { si.moveon = false; - str_info(ctx, ctx->mntpoint, -_("Could not queue AG %u bulkstat work."), agno); + str_liberror(ctx, ret, _("queueing bulkstat work")); break; } } diff --git a/scrub/phase2.c b/scrub/phase2.c index f064c83d..1d2244a4 100644 --- a/scrub/phase2.c +++ b/scrub/phase2.c @@ -124,7 +124,7 @@ xfs_scan_metadata( ret = workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); if (ret) { - str_info(ctx, ctx->mntpoint, _("Could not create workqueue.")); + str_liberror(ctx, ret, _("creating scrub workqueue")); return false; } @@ -145,8 +145,7 @@ xfs_scan_metadata( ret = workqueue_add(&wq, xfs_scan_ag_metadata, agno, &moveon); if (ret) { moveon = false; - str_info(ctx, ctx->mntpoint, -_("Could not queue AG %u scrub work."), agno); + str_liberror(ctx, ret, _("queueing per-AG scrub work")); goto out; } } @@ -157,8 +156,7 @@ _("Could not queue AG %u scrub work."), agno); ret = workqueue_add(&wq, xfs_scan_fs_metadata, 0, &moveon); if (ret) { moveon = false; - str_info(ctx, ctx->mntpoint, -_("Could not queue filesystem scrub work.")); + str_liberror(ctx, ret, _("queueing per-FS scrub work")); goto out; } diff --git a/scrub/phase4.c b/scrub/phase4.c index 25fedc83..903da6d2 100644 --- a/scrub/phase4.c +++ b/scrub/phase4.c @@ -74,7 +74,7 @@ xfs_process_action_items( ret = workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); if (ret) { - str_error(ctx, ctx->mntpoint, _("Could not create workqueue.")); + str_liberror(ctx, ret, _("creating repair workqueue")); return false; } for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) { @@ -82,8 +82,8 @@ xfs_process_action_items( ret = workqueue_add(&wq, xfs_repair_ag, agno, &moveon); if (ret) { moveon = false; - str_error(ctx, ctx->mntpoint, -_("Could not queue repair work.")); + str_liberror(ctx, ret, + _("queueing repair work")); break; } } diff --git a/scrub/read_verify.c b/scrub/read_verify.c index 2152d167..ff4d3572 100644 --- a/scrub/read_verify.c +++ b/scrub/read_verify.c @@ -197,8 +197,7 @@ read_verify_queue( ret = workqueue_add(&rvp->wq, read_verify, 0, tmp); if (ret) { - str_info(rvp->ctx, rvp->ctx->mntpoint, -_("Could not queue read-verify work.")); + str_liberror(rvp->ctx, ret, _("queueing read-verify work")); free(tmp); return false; } diff --git a/scrub/spacemap.c b/scrub/spacemap.c index a7876478..4258e318 100644 --- a/scrub/spacemap.c +++ b/scrub/spacemap.c @@ -200,7 +200,7 @@ xfs_scan_all_spacemaps( ret = workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); if (ret) { - str_info(ctx, ctx->mntpoint, _("Could not create workqueue.")); + str_liberror(ctx, ret, _("creating fsmap workqueue")); return false; } if (ctx->fsinfo.fs_rt) { @@ -208,8 +208,7 @@ xfs_scan_all_spacemaps( ctx->mnt.fsgeom.agcount + 1, &sbx); if (ret) { sbx.moveon = false; - str_info(ctx, ctx->mntpoint, -_("Could not queue rtdev fsmap work.")); + str_liberror(ctx, ret, _("queueing rtdev fsmap work")); goto out; } } @@ -218,8 +217,7 @@ _("Could not queue rtdev fsmap work.")); ctx->mnt.fsgeom.agcount + 2, &sbx); if (ret) { sbx.moveon = false; - str_info(ctx, ctx->mntpoint, -_("Could not queue logdev fsmap work.")); + str_liberror(ctx, ret, _("queueing logdev fsmap work")); goto out; } } @@ -227,8 +225,7 @@ _("Could not queue logdev fsmap work.")); ret = workqueue_add(&wq, xfs_scan_ag_blocks, agno, &sbx); if (ret) { sbx.moveon = false; - str_info(ctx, ctx->mntpoint, -_("Could not queue AG %u fsmap work."), agno); + str_liberror(ctx, ret, _("queueing per-AG fsmap work")); break; } } diff --git a/scrub/vfs.c b/scrub/vfs.c index 1a1482dd..0cff2e3f 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -102,8 +102,7 @@ queue_subdir( error = workqueue_add(wq, scan_fs_dir, 0, new_sftd); if (error) { dec_nr_dirs(sft); - str_info(ctx, ctx->mntpoint, -_("Could not queue subdirectory scan work.")); + str_liberror(ctx, error, _("queueing directory scan work")); goto out_path; } From patchwork Fri Sep 6 03:36:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134331 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF62476 for ; Fri, 6 Sep 2019 03:36:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB4D22082C for ; Fri, 6 Sep 2019 03:36:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="AGPORCwU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387623AbfIFDgc (ORCPT ); Thu, 5 Sep 2019 23:36:32 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:35240 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390521AbfIFDgc (ORCPT ); Thu, 5 Sep 2019 23:36:32 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863Xpo5104779; Fri, 6 Sep 2019 03:36:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=s8P9pZTcX3/SDa0za7d0YID3+cChZYOB+aOmdjhZP0c=; b=AGPORCwUn5WKRg0VPrQldlLFUKbdi3+GedMi2PbuUJy7T0/Y1hFnXcPdjJB+M2Kl9wD4 mVneq7ybf1hm0bxgU1uo7+kTkS+mFiHfb3KugUguvxaDBF/IsE53Zw/bnD5c3Zjn5rN+ T2jAx0VzIxZ9uDr0CFdiIq1zqhonP4xj02bj9pQhTGOMHIgELTA5O7BMdJpGazuuBeSy Cs8Hpkn4sZn90UMZu98jUyJdz4DhJBWZDXdeIiOghuS0eVfEvmcFsxch5Bvfp7v6S9FD 9hM0CR0xxG/ZXdEbpsPyRcn8EvwGIGtoto0v5DfYoY7tBcubT/pifyQjFMFHXH8Qn+yo sg== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2uuf5f830v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:29 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XaBW188783; Fri, 6 Sep 2019 03:36:29 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2utpmc75ep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:29 +0000 Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863aSnb004764; Fri, 6 Sep 2019 03:36:28 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:36:27 -0700 Subject: [PATCH 02/13] libfrog: fix missing error checking in workqueue code From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:36:27 -0700 Message-ID: <156774098739.2644719.3779575154856756310.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong 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 --- 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; } /* From patchwork Fri Sep 6 03:36:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134333 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C21B5924 for ; Fri, 6 Sep 2019 03:36:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A4226206B8 for ; Fri, 6 Sep 2019 03:36:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="chghSw85" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392134AbfIFDgj (ORCPT ); Thu, 5 Sep 2019 23:36:39 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:50240 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390521AbfIFDgj (ORCPT ); Thu, 5 Sep 2019 23:36:39 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863Y2qw109818; Fri, 6 Sep 2019 03:36:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=774DEcyyjw0QgCrEgJfjBDY+urg/M3hsZRx/7J9Lmr8=; b=chghSw85utukWbgUIJEX7YsnaOVGm5eWd/Mz6RLndJiDbcKWnvlb3+LpxkqkK0nI3Vva Fjs0/RAt/IKsL5p8W8lYfqSccIUyo3InUopYpFzWuLzP5g6gugmt7WtVZ3HcLmeza0g1 ZkwjWDY+YaT9T3h70NtlvvwwUMgXALp4w6+JdPMBAVh0C7zbONtc4xLAopkiYz2pSuO/ bHans/Iz48APZQmQkpIgomfHg6dWMf4+FRtNBu6Phb866v0LY2ZvIGfaMwEyxjo/8vf6 Djwpcp8fKruilkttosHmQtXigGRO+9pjZK9d+oVBZcW64wEbhFxJYS4REXcTJse7XNhO Gg== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2uuf4n039h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:36 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YP4B088617; Fri, 6 Sep 2019 03:36:35 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2uu1b99rx7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:35 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x863aYGn015223; Fri, 6 Sep 2019 03:36:34 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:36:34 -0700 Subject: [PATCH 03/13] libfrog: split workqueue destroy functions From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:36:33 -0700 Message-ID: <156774099365.2644719.16908304881126505845.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Split the workqueue destroy function into two parts -- one to signal all the threads to exit and wait for them, and a second one that actually destroys all the memory associated with the workqueue. This mean we can report latent workqueue errors independent of the freeing function. Signed-off-by: Darrick J. Wong --- libfrog/workqueue.c | 37 ++++++++++++++++++++++++++++++------- libfrog/workqueue.h | 2 ++ repair/threads.c | 6 ++++++ scrub/fscounters.c | 11 ++++++++++- scrub/inodes.c | 5 +++++ scrub/phase2.c | 5 +++++ scrub/phase4.c | 6 ++++++ scrub/read_verify.c | 1 + scrub/spacemap.c | 5 +++++ scrub/vfs.c | 5 +++++ 10 files changed, 75 insertions(+), 8 deletions(-) diff --git a/libfrog/workqueue.c b/libfrog/workqueue.c index 48038363..07f11a7b 100644 --- a/libfrog/workqueue.c +++ b/libfrog/workqueue.c @@ -82,6 +82,7 @@ workqueue_create( 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, @@ -119,6 +120,8 @@ workqueue_add( struct workqueue_item *wi; int ret; + assert(!wq->terminated); + if (wq->thread_count == 0) { func(wq, index, arg); return 0; @@ -157,22 +160,42 @@ workqueue_add( /* * Wait for all pending work items to be processed and tear down the - * workqueue. + * workqueue thread pool. */ -void -workqueue_destroy( +int +workqueue_terminate( struct workqueue *wq) { unsigned int i; + int ret; + + pthread_mutex_lock(&wq->lock); + wq->terminate = true; + pthread_mutex_unlock(&wq->lock); + + 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); + if (ret) + return ret; + } pthread_mutex_lock(&wq->lock); - wq->terminate = 1; + wq->terminated = true; pthread_mutex_unlock(&wq->lock); - pthread_cond_broadcast(&wq->wakeup); + return 0; +} - for (i = 0; i < wq->thread_count; i++) - pthread_join(wq->threads[i], NULL); +/* Tear down the workqueue. */ +void +workqueue_destroy( + struct workqueue *wq) +{ + assert(wq->terminated); free(wq->threads); pthread_mutex_destroy(&wq->lock); diff --git a/libfrog/workqueue.h b/libfrog/workqueue.h index a1f3a57c..a56d1cf1 100644 --- a/libfrog/workqueue.h +++ b/libfrog/workqueue.h @@ -30,12 +30,14 @@ struct workqueue { unsigned int item_count; unsigned int thread_count; bool terminate; + bool terminated; }; int workqueue_create(struct workqueue *wq, void *wq_ctx, unsigned int nr_workers); int workqueue_add(struct workqueue *wq, workqueue_func_t fn, uint32_t index, void *arg); +int workqueue_terminate(struct workqueue *wq); void workqueue_destroy(struct workqueue *wq); #endif /* __LIBFROG_WORKQUEUE_H__ */ diff --git a/repair/threads.c b/repair/threads.c index d2190920..9b7241e3 100644 --- a/repair/threads.c +++ b/repair/threads.c @@ -56,5 +56,11 @@ void destroy_work_queue( struct workqueue *wq) { + int err; + + err = workqueue_terminate(wq); + if (err) + do_error(_("cannot terminate worker item, error = [%d] %s\n"), + err, strerror(err)); workqueue_destroy(wq); } diff --git a/scrub/fscounters.c b/scrub/fscounters.c index 669c5ab0..98aa3826 100644 --- a/scrub/fscounters.c +++ b/scrub/fscounters.c @@ -102,7 +102,7 @@ xfs_count_all_inodes( struct xfs_count_inodes *ci; xfs_agnumber_t agno; struct workqueue wq; - bool moveon; + bool moveon = true; int ret; ci = calloc(1, sizeof(struct xfs_count_inodes) + @@ -126,8 +126,17 @@ xfs_count_all_inodes( break; } } + + ret = workqueue_terminate(&wq); + if (ret) { + moveon = false; + str_liberror(ctx, ret, _("finishing icount work")); + } workqueue_destroy(&wq); + if (!moveon) + goto out_free; + for (agno = 0; agno < ctx->mnt.fsgeom.agcount; agno++) *count += ci->counters[agno]; moveon = ci->moveon; diff --git a/scrub/inodes.c b/scrub/inodes.c index 06350ec6..37a35a3f 100644 --- a/scrub/inodes.c +++ b/scrub/inodes.c @@ -256,6 +256,11 @@ xfs_scan_all_inodes( } } + ret = workqueue_terminate(&wq); + if (ret) { + si.moveon = false; + str_liberror(ctx, ret, _("finishing bulkstat work")); + } workqueue_destroy(&wq); return si.moveon; diff --git a/scrub/phase2.c b/scrub/phase2.c index 1d2244a4..d92b7e29 100644 --- a/scrub/phase2.c +++ b/scrub/phase2.c @@ -161,6 +161,11 @@ xfs_scan_metadata( } out: + ret = workqueue_terminate(&wq); + if (ret) { + moveon = false; + str_liberror(ctx, ret, _("finishing scrub work")); + } workqueue_destroy(&wq); return moveon; } diff --git a/scrub/phase4.c b/scrub/phase4.c index 903da6d2..eb30c189 100644 --- a/scrub/phase4.c +++ b/scrub/phase4.c @@ -90,6 +90,12 @@ xfs_process_action_items( if (!moveon) break; } + + ret = workqueue_terminate(&wq); + if (ret) { + moveon = false; + str_liberror(ctx, ret, _("finishing repair work")); + } workqueue_destroy(&wq); pthread_mutex_lock(&ctx->lock); diff --git a/scrub/read_verify.c b/scrub/read_verify.c index ff4d3572..bb8f09a8 100644 --- a/scrub/read_verify.c +++ b/scrub/read_verify.c @@ -120,6 +120,7 @@ void read_verify_pool_flush( struct read_verify_pool *rvp) { + workqueue_terminate(&rvp->wq); workqueue_destroy(&rvp->wq); } diff --git a/scrub/spacemap.c b/scrub/spacemap.c index 4258e318..91e8badb 100644 --- a/scrub/spacemap.c +++ b/scrub/spacemap.c @@ -230,6 +230,11 @@ xfs_scan_all_spacemaps( } } out: + ret = workqueue_terminate(&wq); + if (ret) { + sbx.moveon = false; + str_liberror(ctx, ret, _("finishing fsmap work")); + } workqueue_destroy(&wq); return sbx.moveon; diff --git a/scrub/vfs.c b/scrub/vfs.c index 0cff2e3f..49d689af 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -250,6 +250,11 @@ scan_fs_tree( assert(sft.nr_dirs == 0); pthread_mutex_unlock(&sft.lock); + ret = workqueue_terminate(&wq); + if (ret) { + sft.moveon = false; + str_liberror(ctx, ret, _("finishing directory scan work")); + } out_wq: workqueue_destroy(&wq); return sft.moveon; From patchwork Fri Sep 6 03:36:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134335 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7128276 for ; Fri, 6 Sep 2019 03:36:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5E6812082C for ; Fri, 6 Sep 2019 03:36:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="lIV2o+6x" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390521AbfIFDgn (ORCPT ); Thu, 5 Sep 2019 23:36:43 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:50310 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388688AbfIFDgn (ORCPT ); Thu, 5 Sep 2019 23:36:43 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YJZ6109869; Fri, 6 Sep 2019 03:36:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=knduo7mmOzYKtQwIAwV8dAkAygKXoqcWiFpsWzsh43I=; b=lIV2o+6x+Imtdm3kHr7ogbYgilJaVdd3rp7d1iU3eBNaUUu1VQhjh6KCMK4rTbwm/snl 3ZbQMJY9dRmHWNgvFF6pYMxbtL6JQG2wy+7pvI3sBfsWFirDJMjC1Fu0wojpLhjorMbV vAi9r+ZzYGFdo8S5nHqtdGPggQkSzMOgvWfh95Ddl2N/351jYDig6xhTswm0PgDY2M+t YadmNeS7w0VEnBa360FG2ySm5Sg3Ui4cElrhbyDKvwprev6qkr/TsgKiJpdQZjxpcJiP jG98ta5hV+ogYi1Fe2jt+fazHiRU7RrHb5Zt7SjVkCx1ZfDHktdNsd/pFlj7v19MVpxX NQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2uuf4n039u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:41 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XdrY069349; Fri, 6 Sep 2019 03:36:41 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2utvr4jvw4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:41 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863aeTT018985; Fri, 6 Sep 2019 03:36:40 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:36:40 -0700 Subject: [PATCH 04/13] xfs_scrub: redistribute read verify pool flush and destroy responsibilities From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:36:39 -0700 Message-ID: <156774099994.2644719.15845341004106862142.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Since workqueues now have separate primitives for "wait for all queued work" and "destroy workqueue", it makes more sense for the read verify pool code to call the workqueue destructor from its own destructor function. Signed-off-by: Darrick J. Wong --- scrub/phase6.c | 9 +++++++-- scrub/read_verify.c | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scrub/phase6.c b/scrub/phase6.c index b41f90e0..aff04e76 100644 --- a/scrub/phase6.c +++ b/scrub/phase6.c @@ -511,12 +511,17 @@ _("Could not create data device media verifier.")); return moveon; out_rtpool: - if (vs.rvp_realtime) + if (vs.rvp_realtime) { + read_verify_pool_flush(vs.rvp_realtime); read_verify_pool_destroy(vs.rvp_realtime); + } out_logpool: - if (vs.rvp_log) + if (vs.rvp_log) { + read_verify_pool_flush(vs.rvp_log); read_verify_pool_destroy(vs.rvp_log); + } out_datapool: + read_verify_pool_flush(vs.rvp_data); read_verify_pool_destroy(vs.rvp_data); out_rbad: bitmap_free(&vs.r_bad); diff --git a/scrub/read_verify.c b/scrub/read_verify.c index bb8f09a8..e59d3e67 100644 --- a/scrub/read_verify.c +++ b/scrub/read_verify.c @@ -121,7 +121,6 @@ read_verify_pool_flush( struct read_verify_pool *rvp) { workqueue_terminate(&rvp->wq); - workqueue_destroy(&rvp->wq); } /* Finish up any read verification work and tear it down. */ @@ -129,6 +128,7 @@ void read_verify_pool_destroy( struct read_verify_pool *rvp) { + workqueue_destroy(&rvp->wq); ptvar_free(rvp->rvstate); ptcounter_free(rvp->verified_bytes); free(rvp->readbuf); From patchwork Fri Sep 6 03:36:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134337 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 04CE976 for ; Fri, 6 Sep 2019 03:36:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DCDCF20820 for ; Fri, 6 Sep 2019 03:36:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="qz0eAt1e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390252AbfIFDgu (ORCPT ); Thu, 5 Sep 2019 23:36:50 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:35610 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388688AbfIFDgu (ORCPT ); Thu, 5 Sep 2019 23:36:50 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863Xssk104900; Fri, 6 Sep 2019 03:36:47 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=WkbcaJHkS8rdDMhvUiKpSlk5IADFevQ33FKLAbeCXSk=; b=qz0eAt1e0OXPcLMnx/3S+weWVmMxxmB/JPMjsO7Hg1WBsXv37+MTFsqI9KT4w3lomxq7 D9LAYKgU6HR9kBwxYhnWRu7kvSOYPsViqoT7SDcCcwSwjY80XwBYqk4WFbQ4jdqcydfj HpMi2o3ArYOBN3YO7zQWqE7zTztYOGF4sYUQrrYKwzLZkG05yud3WioF2pcl4ItRebnP FSXlEku9EWjI4XFa1j/NFqGWLNt8v/YS+RLJ8Rt2U4opWAZltNWoAIHGWqgqoKHB0k+/ fLd/D5k/9LRLWC4eWaRDdeZGhbzVPF7ORtsoXBQ+Wq7IdAzXb1tcW20X6sbJE63ZIX0V gw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2uuf5f831p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:47 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XTeP188644; Fri, 6 Sep 2019 03:36:47 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2utpmc75k0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:47 +0000 Received: from abhmp0022.oracle.com (abhmp0022.oracle.com [141.146.116.28]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863akUk019000; Fri, 6 Sep 2019 03:36:46 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:36:46 -0700 Subject: [PATCH 05/13] libfrog: fix per-thread variable error communication problems From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:36:46 -0700 Message-ID: <156774100605.2644719.10169202241832439023.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong 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 --- libfrog/ptvar.c | 26 +++++++++++++++----------- libfrog/ptvar.h | 8 ++++---- scrub/counter.c | 13 ++++++++----- scrub/phase7.c | 24 ++++++++++++++++-------- scrub/read_verify.c | 16 +++++++++++----- 5 files changed, 54 insertions(+), 33 deletions(-) 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/libfrog/ptvar.h b/libfrog/ptvar.h index a8803c64..42865c0b 100644 --- a/libfrog/ptvar.h +++ b/libfrog/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_PTVAR_H__ */ diff --git a/scrub/counter.c b/scrub/counter.c index 43444927..49ffbfea 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 308b8bb3..bc959f5b 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 e59d3e67..95987a9b 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; From patchwork Fri Sep 6 03:36:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134341 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6817F76 for ; Fri, 6 Sep 2019 03:36:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54A1F20820 for ; Fri, 6 Sep 2019 03:36:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="kcr9xVDv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388688AbfIFDg4 (ORCPT ); Thu, 5 Sep 2019 23:36:56 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:42672 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387624AbfIFDg4 (ORCPT ); Thu, 5 Sep 2019 23:36:56 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YFvo074394; Fri, 6 Sep 2019 03:36:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=CVff4CSW93m4xJ2YRk+C3BNTVL2W8grW+5LXu/d/sFQ=; b=kcr9xVDvU6amMUtg/qLKoRAytwrBHQqf8mEMwasx1Ocp/4TwZkT4aj9SfOsNESBXHuin kOKSK2NsyH/wvbLXq6gocz58yfZAXHoXSfIYQCn3w+WlOv4zKiklzGSIqX1irBw22NYv FJ5F35gCLDURN6sM73qhtkmq7qeggbG6/y/txszIqgXK7/FuEGs6msVPeF+NCf+f15wV MvYrq5caQGiIb9R94QkTzVvkxb5gt3wM+oEgOFq1PerPs4elQgSgwlGOMibx+bReuNZM RnzYVw9TxcAHMS4chws94goETDYLfC9ACAcRhgCOOuaMYrYlifDBL55zByFLHDO6/bdd ng== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 2uuf51g360-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:54 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XTf8188609; Fri, 6 Sep 2019 03:36:54 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2utpmc75me-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:36:53 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863are0004887; Fri, 6 Sep 2019 03:36:53 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:36:52 -0700 Subject: [PATCH 06/13] libfrog: add missing per-thread variable error handling From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:36:52 -0700 Message-ID: <156774101226.2644719.10512779001456813045.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Add missing return value checks for everything that the per-thread variable code calls. Signed-off-by: Darrick J. Wong --- libfrog/ptvar.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libfrog/ptvar.c b/libfrog/ptvar.c index 6cb58208..55324b71 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,26 @@ ptvar_get( int *retp) { void *p; + int ret; p = pthread_getspecific(ptv->key); if (!p) { pthread_mutex_lock(&ptv->lock); 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. */ From patchwork Fri Sep 6 03:36:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134343 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C93B6924 for ; Fri, 6 Sep 2019 03:37:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B667320820 for ; Fri, 6 Sep 2019 03:37:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="ImjEUepx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392128AbfIFDhD (ORCPT ); Thu, 5 Sep 2019 23:37:03 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:50668 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387624AbfIFDhD (ORCPT ); Thu, 5 Sep 2019 23:37:03 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YUQ8110133; Fri, 6 Sep 2019 03:37:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=vTkD6KUcn379TJhBo2oB/mdzlgqlW1twLv63kEVw69Y=; b=ImjEUepx11QLAcYb/Gt1FklEGjdgXhb166/FXSJoUXjADYwm0zZEL2kdvK+mXgCugllJ lMjQnEgF8KT0e1IuEl58Dxg7dOPQgLlfYl5l/cJVPBCFDF9/EPNw3FwGOy2a66onY0qo XIoqny9sYb6SZZ43WIYga82p9j9wrap9fhPo11lnheftUn2VHylWCV/z9ibS1RGQPnOb EM6BOgX4aqX88P/hrLOxW3VTYVAPF1DbLXY2YU5UcrxGfCu/yDKKafXr9PKy66sgSVR4 hJyJwTfOu6ZA68OhK49i30bEV46pYVaFYJLsiHvGoUKMqpqdSxf0vEW85//bGqOqlr61 hQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2uuf4n03av-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:00 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863Xbpt069179; Fri, 6 Sep 2019 03:37:00 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2utvr4jw9x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:00 +0000 Received: from abhmp0022.oracle.com (abhmp0022.oracle.com [141.146.116.28]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863ax0W005048; Fri, 6 Sep 2019 03:36:59 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:36:58 -0700 Subject: [PATCH 07/13] libfrog: fix bitmap error communication problems From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:36:58 -0700 Message-ID: <156774101854.2644719.3408391175817643314.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Convert all the libfrog code and callers away from the libc-style indirect errno returns to directly returning error codes to callers. Signed-off-by: Darrick J. Wong --- libfrog/bitmap.c | 13 +++++++------ libfrog/bitmap.h | 2 +- repair/rmap.c | 4 ++-- scrub/phase6.c | 20 +++++++++++--------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/libfrog/bitmap.c b/libfrog/bitmap.c index 4dafc4c9..be95965f 100644 --- a/libfrog/bitmap.c +++ b/libfrog/bitmap.c @@ -23,7 +23,8 @@ */ #define avl_for_each_range_safe(pos, n, l, first, last) \ - for (pos = (first), n = pos->avl_nextino, l = (last)->avl_nextino; pos != (l); \ + for (pos = (first), n = pos->avl_nextino, l = (last)->avl_nextino; \ + pos != (l); \ pos = n, n = pos ? pos->avl_nextino : NULL) #define avl_for_each_safe(tree, pos, n) \ @@ -67,18 +68,18 @@ static struct avl64ops bitmap_ops = { /* Initialize a bitmap. */ int -bitmap_init( +bitmap_alloc( struct bitmap **bmapp) { struct bitmap *bmap; bmap = calloc(1, sizeof(struct bitmap)); if (!bmap) - return -ENOMEM; + return errno; bmap->bt_tree = malloc(sizeof(struct avl64tree_desc)); if (!bmap->bt_tree) { free(bmap); - return -ENOMEM; + return errno; } pthread_mutex_init(&bmap->bt_lock, NULL); @@ -139,12 +140,12 @@ __bitmap_insert( ext = bitmap_node_init(start, length); if (!ext) - return -ENOMEM; + return errno; node = avl64_insert(bmap->bt_tree, &ext->btn_node); if (node == NULL) { free(ext); - return -EEXIST; + return EEXIST; } return 0; diff --git a/libfrog/bitmap.h b/libfrog/bitmap.h index 40119b9c..759386a8 100644 --- a/libfrog/bitmap.h +++ b/libfrog/bitmap.h @@ -11,7 +11,7 @@ struct bitmap { struct avl64tree_desc *bt_tree; }; -int bitmap_init(struct bitmap **bmap); +int bitmap_alloc(struct bitmap **bmap); void bitmap_free(struct bitmap **bmap); int bitmap_set(struct bitmap *bmap, uint64_t start, uint64_t length); int bitmap_iterate(struct bitmap *bmap, int (*fn)(uint64_t, uint64_t, void *), diff --git a/repair/rmap.c b/repair/rmap.c index b907383e..c6ed25a9 100644 --- a/repair/rmap.c +++ b/repair/rmap.c @@ -490,13 +490,13 @@ rmap_store_ag_btree_rec( error = init_slab_cursor(ag_rmap->ar_raw_rmaps, rmap_compare, &rm_cur); if (error) goto err; - error = -bitmap_init(&own_ag_bitmap); + error = bitmap_alloc(&own_ag_bitmap); if (error) goto err_slab; while ((rm_rec = pop_slab_cursor(rm_cur)) != NULL) { if (rm_rec->rm_owner != XFS_RMAP_OWN_AG) continue; - error = -bitmap_set(own_ag_bitmap, rm_rec->rm_startblock, + error = bitmap_set(own_ag_bitmap, rm_rec->rm_startblock, rm_rec->rm_blockcount); if (error) { /* diff --git a/scrub/phase6.c b/scrub/phase6.c index aff04e76..d9285fee 100644 --- a/scrub/phase6.c +++ b/scrub/phase6.c @@ -341,6 +341,7 @@ xfs_check_rmap_ioerr( struct media_verify_state *vs = arg; struct bitmap *tree; dev_t dev; + int ret; dev = xfs_disk_to_dev(ctx, disk); @@ -355,9 +356,9 @@ xfs_check_rmap_ioerr( else tree = NULL; if (tree) { - errno = -bitmap_set(tree, start, length); - if (errno) - str_errno(ctx, ctx->mntpoint); + ret = bitmap_set(tree, start, length); + if (ret) + str_liberror(ctx, ret, _("setting bad block bitmap")); } snprintf(descr, DESCR_BUFSZ, _("dev %d:%d ioerr @ %"PRIu64":%"PRIu64" "), @@ -454,16 +455,17 @@ xfs_scan_blocks( { struct media_verify_state vs = { NULL }; bool moveon = false; + int ret; - errno = -bitmap_init(&vs.d_bad); - if (errno) { - str_errno(ctx, ctx->mntpoint); + ret = bitmap_alloc(&vs.d_bad); + if (ret) { + str_liberror(ctx, ret, _("creating datadev badblock bitmap")); goto out; } - errno = -bitmap_init(&vs.r_bad); - if (errno) { - str_errno(ctx, ctx->mntpoint); + ret = bitmap_alloc(&vs.r_bad); + if (ret) { + str_liberror(ctx, ret, _("creating realtime badblock bitmap")); goto out_dbad; } From patchwork Fri Sep 6 03:37:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134345 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70962924 for ; Fri, 6 Sep 2019 03:37:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CF24206B8 for ; Fri, 6 Sep 2019 03:37:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="IkwUUIx4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387624AbfIFDhJ (ORCPT ); Thu, 5 Sep 2019 23:37:09 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:50764 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732799AbfIFDhJ (ORCPT ); Thu, 5 Sep 2019 23:37:09 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YecL110274; Fri, 6 Sep 2019 03:37:07 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=57v6OlE4fKldtseXRurmX6ES/7SqMpzP00s49qCPjm8=; b=IkwUUIx4UrHBlL57GR5qxBblVTeTAlwrnn3KruBJPkhGQoYF9+M2m1/f0YxOKnu83yMw +IFwSWGmD3GQyS60c8v6LQLFWKxvfsKFIIRIwTuJ4z6xEKOYW4Lakc2tkZOdF1GyC7Mk 059tIiFSfPDOdJvGSzH9i3CMFOBC3psfyNOGo1h3oGe3TNMYMyb3H7sPg885GmuHJA35 wWF1VWUBvGzo2/4RWa23pLnJS9Kmg/rKo4Cjjh/zUJZhOsx05m1KNOsbZHc2ssfnU8Ea eYeitzbAxAOGvANVtWxBG7nxDz1gATPUnO/WYja1MW3uZhOU2hBN5e9/UIu5h+C9nTtU CA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by userp2130.oracle.com with ESMTP id 2uuf4n03b3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:07 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YPjF088664; Fri, 6 Sep 2019 03:37:06 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3030.oracle.com with ESMTP id 2uu1b99s6d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:06 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863b53M019102; Fri, 6 Sep 2019 03:37:05 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:37:05 -0700 Subject: [PATCH 08/13] libfrog: fix missing error checking in bitmap code From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:37:04 -0700 Message-ID: <156774102466.2644719.5744022638045647382.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Check library calls for error codes being returned. Signed-off-by: Darrick J. Wong --- libfrog/bitmap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libfrog/bitmap.c b/libfrog/bitmap.c index be95965f..a75d085a 100644 --- a/libfrog/bitmap.c +++ b/libfrog/bitmap.c @@ -72,21 +72,30 @@ bitmap_alloc( struct bitmap **bmapp) { struct bitmap *bmap; + int ret; bmap = calloc(1, sizeof(struct bitmap)); if (!bmap) return errno; bmap->bt_tree = malloc(sizeof(struct avl64tree_desc)); if (!bmap->bt_tree) { - free(bmap); - return errno; + ret = errno; + goto out; } - pthread_mutex_init(&bmap->bt_lock, NULL); + ret = pthread_mutex_init(&bmap->bt_lock, NULL); + if (ret) + goto out_tree; + avl64_init_tree(bmap->bt_tree, &bitmap_ops); *bmapp = bmap; return 0; +out_tree: + free(bmap->bt_tree); +out: + free(bmap); + return ret; } /* Free a bitmap. */ From patchwork Fri Sep 6 03:37:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134347 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3310E76 for ; Fri, 6 Sep 2019 03:37:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 16B7B2082C for ; Fri, 6 Sep 2019 03:37:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="pAyGL4iA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392137AbfIFDhQ (ORCPT ); Thu, 5 Sep 2019 23:37:16 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:43004 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732799AbfIFDhQ (ORCPT ); Thu, 5 Sep 2019 23:37:16 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YAOJ074363; Fri, 6 Sep 2019 03:37:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=LgpX/+bj7iIsp8Zi6TzNYtyV0DkfUNjYoyWC3uU2lPM=; b=pAyGL4iALopuss+iUiq15+QOrsA2NnogngK6HXxxncnWnyXnHGMqkRJspEujvtDaST8S 8LayuWoARh4KS7Ntj80iqX/6LiCCi2boqpbtzTPv5DNwSq4puWliVVAzPrlDTp19T4mX 62Nih4Lnkp+xpXzBVHnHuneG9Se4eizqEVoT9hm7Gc1w/sK8ujMAcvNn9E5nv5i0LRBy a2l7LDumsBh3dmuu0CU037q4cCqzE2EKn6nSmdJciMNoHS+nnlE7VhxVlDyQ8tM4j7W0 Z0Gplxq6nDNe8l3S73Ym1XJOtObGOJkR+qbppTKWm6Yt2TOnzluUBTbmY3ICoe9q6leh hA== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 2uuf51g36x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:14 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YOTx088452; Fri, 6 Sep 2019 03:37:14 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3030.oracle.com with ESMTP id 2uu1b99s7j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:13 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x863bC6T015496; Fri, 6 Sep 2019 03:37:13 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:37:12 -0700 Subject: [PATCH 09/13] xfs_scrub: fix per-thread counter error communication problems From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:37:10 -0700 Message-ID: <156774103087.2644719.15423118655626775867.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Fix all the places in the per-thread counter functions either we fail to check for runtime errors or fail to communicate them properly to callers. Then fix all the callers to report the error messages instead of hiding them. Signed-off-by: Darrick J. Wong --- scrub/counter.c | 33 ++++++++++++++++++--------------- scrub/counter.h | 6 +++--- scrub/phase3.c | 23 +++++++++++++++++------ scrub/progress.c | 12 +++++++++--- scrub/read_verify.c | 9 ++++++--- 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/scrub/counter.c b/scrub/counter.c index 49ffbfea..1bb726dc 100644 --- a/scrub/counter.c +++ b/scrub/counter.c @@ -26,23 +26,25 @@ struct ptcounter { struct ptvar *var; }; -/* Initialize per-thread counter. */ -struct ptcounter * -ptcounter_init( - size_t nr) +/* Allocate per-thread counter. */ +int +ptcounter_alloc( + size_t nr, + struct ptcounter **pp) { struct ptcounter *p; int ret; p = malloc(sizeof(struct ptcounter)); if (!p) - return NULL; + return errno; ret = ptvar_alloc(nr, sizeof(uint64_t), &p->var); if (ret) { free(p); - return NULL; + return ret; } - return p; + *pp = p; + return 0; } /* Free per-thread counter. */ @@ -55,7 +57,7 @@ ptcounter_free( } /* Add a quantity to the counter. */ -void +int ptcounter_add( struct ptcounter *ptc, int64_t nr) @@ -64,8 +66,10 @@ ptcounter_add( int ret; p = ptvar_get(ptc->var, &ret); - assert(ret == 0); + if (ret) + return ret; *p += nr; + return 0; } static int @@ -82,12 +86,11 @@ ptcounter_val_helper( } /* Return the approximate value of this counter. */ -uint64_t +int ptcounter_value( - struct ptcounter *ptc) + struct ptcounter *ptc, + uint64_t *sum) { - uint64_t sum = 0; - - ptvar_foreach(ptc->var, ptcounter_val_helper, &sum); - return sum; + *sum = 0; + return ptvar_foreach(ptc->var, ptcounter_val_helper, sum); } diff --git a/scrub/counter.h b/scrub/counter.h index 6c501b85..01b65056 100644 --- a/scrub/counter.h +++ b/scrub/counter.h @@ -7,9 +7,9 @@ #define XFS_SCRUB_COUNTER_H_ struct ptcounter; -struct ptcounter *ptcounter_init(size_t nr); +int ptcounter_alloc(size_t nr, struct ptcounter **pp); void ptcounter_free(struct ptcounter *ptc); -void ptcounter_add(struct ptcounter *ptc, int64_t nr); -uint64_t ptcounter_value(struct ptcounter *ptc); +int ptcounter_add(struct ptcounter *ptc, int64_t nr); +int ptcounter_value(struct ptcounter *ptc, uint64_t *sum); #endif /* XFS_SCRUB_COUNTER_H_ */ diff --git a/scrub/phase3.c b/scrub/phase3.c index a32d1ced..1e908c2c 100644 --- a/scrub/phase3.c +++ b/scrub/phase3.c @@ -139,7 +139,12 @@ xfs_scrub_inode( goto out; out: - ptcounter_add(icount, 1); + error = ptcounter_add(icount, 1); + if (error) { + str_liberror(ctx, error, + _("incrementing scanned inode counter")); + return false; + } progress_add(1); xfs_action_list_defer(ctx, agno, &alist); if (fd >= 0) { @@ -158,12 +163,14 @@ xfs_scan_inodes( struct scrub_ctx *ctx) { struct scrub_inode_ctx ictx; + uint64_t val; + int err; bool ret; ictx.moveon = true; - ictx.icount = ptcounter_init(scrub_nproc(ctx)); - if (!ictx.icount) { - str_info(ctx, ctx->mntpoint, _("Could not create counter.")); + err = ptcounter_alloc(scrub_nproc(ctx), &ictx.icount); + if (err) { + str_liberror(ctx, err, _("creating scanned inode counter")); return false; } @@ -173,8 +180,12 @@ xfs_scan_inodes( if (!ictx.moveon) goto free; xfs_scrub_report_preen_triggers(ctx); - ctx->inodes_checked = ptcounter_value(ictx.icount); - + err = ptcounter_value(ictx.icount, &val); + if (err) { + str_liberror(ctx, err, _("summing scanned inode counter")); + return false; + } + ctx->inodes_checked = val; free: ptcounter_free(ictx.icount); return ictx.moveon; diff --git a/scrub/progress.c b/scrub/progress.c index c9a9d286..08c7233e 100644 --- a/scrub/progress.c +++ b/scrub/progress.c @@ -119,6 +119,8 @@ progress_report_thread(void *arg) pthread_mutex_lock(&pt.lock); while (1) { + uint64_t progress_val; + /* Every half second. */ ret = clock_gettime(CLOCK_REALTIME, &abstime); if (ret) @@ -131,7 +133,9 @@ progress_report_thread(void *arg) pthread_cond_timedwait(&pt.wakeup, &pt.lock, &abstime); if (pt.terminate) break; - progress_report(ptcounter_value(pt.ptc)); + ret = ptcounter_value(pt.ptc, &progress_val); + if (!ret) + progress_report(progress_val); } pthread_mutex_unlock(&pt.lock); return NULL; @@ -187,9 +191,11 @@ progress_init_phase( pt.twiddle = 0; pt.terminate = false; - pt.ptc = ptcounter_init(nr_threads); - if (!pt.ptc) + ret = ptcounter_alloc(nr_threads, &pt.ptc); + if (ret) { + str_liberror(ctx, ret, _("allocating progress counter")); goto out_max; + } ret = pthread_create(&pt.thread, NULL, progress_report_thread, NULL); if (ret) diff --git a/scrub/read_verify.c b/scrub/read_verify.c index 95987a9b..b890c92f 100644 --- a/scrub/read_verify.c +++ b/scrub/read_verify.c @@ -84,8 +84,8 @@ read_verify_pool_init( RVP_IO_MAX_SIZE); if (error || !rvp->readbuf) goto out_free; - rvp->verified_bytes = ptcounter_init(nproc); - if (!rvp->verified_bytes) + error = ptcounter_alloc(nproc, &rvp->verified_bytes); + if (error) goto out_buf; rvp->miniosz = miniosz; rvp->ctx = ctx; @@ -282,5 +282,8 @@ uint64_t read_verify_bytes( struct read_verify_pool *rvp) { - return ptcounter_value(rvp->verified_bytes); + uint64_t ret; + + ptcounter_value(rvp->verified_bytes, &ret); + return ret; } From patchwork Fri Sep 6 03:37:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134367 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5C0B924 for ; Fri, 6 Sep 2019 03:38:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B15E92082C for ; Fri, 6 Sep 2019 03:38:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="d5qs3S7Z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392147AbfIFDiL (ORCPT ); Thu, 5 Sep 2019 23:38:11 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:44222 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392146AbfIFDiL (ORCPT ); Thu, 5 Sep 2019 23:38:11 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863Xu3u074308; Fri, 6 Sep 2019 03:38:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=wFNAEg5YtbO6E4yspEc6n6KfAiklSqUX3m/88fxOJCs=; b=d5qs3S7ZbCrRVv7dKQd1HZ31yiDm55n22CRVpz7gH1M6JpcAZsx+kJkc1oTeURGpEoiu 9oNy/qblN583m9vXDhyPP9YEYvXbI6IWY7DdAwffn2I6mEg7DS83ZBYT4cO2aFSOeYVF xhkL+kmUvJPj0OHYYKcT0VxKIOHlmQkPt5/d2/iIOUi3WyVwOP96FwXIzWEhNmEwdHF/ /xdNAlvHFpjSqiHKQUlXSQkHNiIEGjqEkU1nYJ19tMd7KPnZNqzH3GwPBgP+AJnTb5/g wozQS5HIeBjT/yEDfZWVnjG8HiXoX3UGjyVHFOyPwfKmZ3ffqmjqbgf3R0bCo1ke9ERA /g== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by aserp2120.oracle.com with ESMTP id 2uuf51g3ab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:38:09 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XbqX069130; Fri, 6 Sep 2019 03:37:19 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userp3020.oracle.com with ESMTP id 2utvr4jwpf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:19 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x863bJP2015507; Fri, 6 Sep 2019 03:37:19 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:37:18 -0700 Subject: [PATCH 10/13] xfs_scrub: report all progressbar creation failures From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:37:18 -0700 Message-ID: <156774103839.2644719.4073244978058882123.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=993 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Always report failures when creating progress bars. Signed-off-by: Darrick J. Wong --- scrub/progress.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scrub/progress.c b/scrub/progress.c index 08c7233e..5fda4ccb 100644 --- a/scrub/progress.c +++ b/scrub/progress.c @@ -198,8 +198,10 @@ progress_init_phase( } ret = pthread_create(&pt.thread, NULL, progress_report_thread, NULL); - if (ret) + if (ret) { + str_liberror(ctx, ret, _("creating progress reporting thread")); goto out_ptcounter; + } return true; From patchwork Fri Sep 6 03:37:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134351 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3C830924 for ; Fri, 6 Sep 2019 03:37:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 28C192082C for ; Fri, 6 Sep 2019 03:37:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="TkY3hE/9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392140AbfIFDh3 (ORCPT ); Thu, 5 Sep 2019 23:37:29 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:36210 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392138AbfIFDh3 (ORCPT ); Thu, 5 Sep 2019 23:37:29 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863Xw0E105085; Fri, 6 Sep 2019 03:37:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=rO1xdgdP7mc5eMTSJb07Snh24FizECXgUy//Th9QZNY=; b=TkY3hE/95gCJU36oxFtQPUEjZWVrrMJExl5l9gqGpSqAkvZy+syLocKY3yRn/3xln+Pm GZ3bcqSQ93EMsuANm9so8x5qEXVgiaUwj3w++yyuHZJjxWleEE/707knsPrBphO7PMG8 iwFoxQWvgEQcYVh22EdTQWAwvjoE4MaJk/6Vh/rf/pjmolxI/jJ/UOcTiYS44COhAtW4 qT20NDkXfJobvD37G44h6sh91Enpe2elPKf8TzC8pMjAC7jGvrY+l3e9UdEDkHol8g5S BFDAN1nEExFYewAs4Ez8wvkBvs1vu1AEcIudMW/aEODJ5/LZdOLTte7OMe23W4y+NLBM Uw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2uuf5f8335-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:27 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YVBr103636; Fri, 6 Sep 2019 03:37:26 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2uud7p2rsc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:26 +0000 Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863bPqp019259; Fri, 6 Sep 2019 03:37:25 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:37:25 -0700 Subject: [PATCH 11/13] xfs_scrub: check progress bar timedwait failures From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:37:24 -0700 Message-ID: <156774104464.2644719.15234278628058661215.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Check for failures in the timedwait for progressbar reporting. Signed-off-by: Darrick J. Wong --- scrub/progress.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scrub/progress.c b/scrub/progress.c index 5fda4ccb..e93b607f 100644 --- a/scrub/progress.c +++ b/scrub/progress.c @@ -130,7 +130,9 @@ progress_report_thread(void *arg) abstime.tv_sec++; abstime.tv_nsec -= NSEC_PER_SEC; } - pthread_cond_timedwait(&pt.wakeup, &pt.lock, &abstime); + ret = pthread_cond_timedwait(&pt.wakeup, &pt.lock, &abstime); + if (ret && ret != ETIMEDOUT) + break; if (pt.terminate) break; ret = ptcounter_value(pt.ptc, &progress_val); From patchwork Fri Sep 6 03:37:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134355 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CF23924 for ; Fri, 6 Sep 2019 03:37:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 89C4820820 for ; Fri, 6 Sep 2019 03:37:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="b88umjvu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392102AbfIFDhg (ORCPT ); Thu, 5 Sep 2019 23:37:36 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:36300 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732799AbfIFDhf (ORCPT ); Thu, 5 Sep 2019 23:37:35 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863XwBC105063; Fri, 6 Sep 2019 03:37:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=+Iesd87YkMxOI/J+X/jVDJxmXkXlWI+yBnYZU+NrZxo=; b=b88umjvuVuYRF2/B0RjwK99jpaquBqj8ZZw3eWcjZ3j9zYl/XuUbZwXptvHkBJA3wdHx VejVLzNdzrgkDPNzablN715FvGBKhxsaz9RySjKOacaCfGZqfRaCnC1/mb1n2rvtfOAr C01Nyod7+O83kTPvAYSReCvLS9fFQ39Cqh+ndm3/5z8mjs2vNY2629GQl4jeJM/RVZHK U6FhUOQpY2NWZYF/oIvxG/zfHSlDxgeQYQ/JLxyfRmAoVvd4+pIXbhnpp1XKFz06x3EO 29OolmdnCFB0IbprTznVcHDS+F50MFOiQ2QFuhUiR8Fq6i2tMRl1QgRZaFSc3uGtZ6wv qA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 2uuf5f833b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:33 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YW9V103784; Fri, 6 Sep 2019 03:37:32 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 2uud7p2rtn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:32 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x863bV6H015653; Fri, 6 Sep 2019 03:37:31 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:37:31 -0700 Subject: [PATCH 12/13] xfs_scrub: move all the queue_subdir error reporting to callers From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:37:30 -0700 Message-ID: <156774105080.2644719.10846017264580113281.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Change queue_subdir to return a positive error code to callers and move the error reporting to the callers. This continues the process of changing internal functions to return error codes. Signed-off-by: Darrick J. Wong --- scrub/vfs.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/scrub/vfs.c b/scrub/vfs.c index 49d689af..e0bc3ea4 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -72,7 +72,7 @@ dec_nr_dirs( } /* Queue a directory for scanning. */ -static bool +static int queue_subdir( struct scrub_ctx *ctx, struct scan_fs_tree *sft, @@ -84,14 +84,12 @@ queue_subdir( int error; new_sftd = malloc(sizeof(struct scan_fs_tree_dir)); - if (!new_sftd) { - str_errno(ctx, _("creating directory scan context")); - return false; - } + if (!new_sftd) + return errno; new_sftd->path = strdup(path); if (!new_sftd->path) { - str_errno(ctx, _("creating directory scan path")); + error = errno; goto out_sftd; } @@ -106,12 +104,12 @@ queue_subdir( goto out_path; } - return true; + return 0; out_path: free(new_sftd->path); out_sftd: free(new_sftd); - return false; + return error; } /* Scan a directory sub tree. */ @@ -187,10 +185,13 @@ scan_fs_dir( /* If directory, call ourselves recursively. */ if (S_ISDIR(sb.st_mode) && strcmp(".", dirent->d_name) && strcmp("..", dirent->d_name)) { - sft->moveon = queue_subdir(ctx, sft, wq, newpath, - false); - if (!sft->moveon) + error = queue_subdir(ctx, sft, wq, newpath, false); + if (error) { + str_liberror(ctx, error, +_("queueing subdirectory scan")); + sft->moveon = false; break; + } } } @@ -233,9 +234,11 @@ scan_fs_tree( return false; } - sft.moveon = queue_subdir(ctx, &sft, &wq, ctx->mntpoint, true); - if (!sft.moveon) + ret = queue_subdir(ctx, &sft, &wq, ctx->mntpoint, true); + if (ret) { + str_liberror(ctx, ret, _("queueing directory scan")); goto out_wq; + } /* * Wait for the wakeup to trigger, which should only happen when the From patchwork Fri Sep 6 03:37:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 11134357 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 105F476 for ; Fri, 6 Sep 2019 03:37:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F1C3A20820 for ; Fri, 6 Sep 2019 03:37:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iXSe2r4O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392141AbfIFDhl (ORCPT ); Thu, 5 Sep 2019 23:37:41 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:43450 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732799AbfIFDhl (ORCPT ); Thu, 5 Sep 2019 23:37:41 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863Y0Md074326; Fri, 6 Sep 2019 03:37:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=Yhsh6/l2T2NtO2IcFzcAv62SfLhsKuqqrZpAa8B0+co=; b=iXSe2r4OwylYgf4ovOUIqg1OsRiUZ6rgyjNiqRATkTSJSVQK0MLW4SuXMQ4HcvMQw7zz 4Kj1lRRPyOUNnndOc5v55csNVx1yZJ0q5jUOd1ZU7h4IuqqmGOZuDRIVNDK6hxWdw/Vu uxom4HX1FRqFfqH8BVna6BN08jupLvqVe+cgA2s0UEuU3g6ScKjFd4lRwUm1sIeeWqYV i3quHD9csWc7XOEjvjuUcXPu6iXtOcUkPaM01DdVyaqVD8m6QCE0c4ALpxjh46d2W0Ec hIqImMnOhrvn8Pxp4PfcRh0ApJIaxbR3LdT/nxMVs82mJ+AAA3I7oS+taTOGiLsga2mf Sg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 2uuf51g38c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:39 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x863YV99103717; Fri, 6 Sep 2019 03:37:38 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2uud7p2rvq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:37:38 +0000 Received: from abhmp0020.oracle.com (abhmp0020.oracle.com [141.146.116.26]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863bbep019372; Fri, 6 Sep 2019 03:37:37 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:37:37 -0700 Subject: [PATCH 13/13] xfs_scrub: fix error handling problems in vfs.c From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:37:37 -0700 Message-ID: <156774105700.2644719.16974632587680060434.stgit@magnolia> In-Reply-To: <156774097496.2644719.4441145106129821110.stgit@magnolia> References: <156774097496.2644719.4441145106129821110.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9371 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1909060039 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Fix all the places where we drop or screw up error handling in scan_fs_tree. Signed-off-by: Darrick J. Wong --- scrub/vfs.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/scrub/vfs.c b/scrub/vfs.c index e0bc3ea4..d7c40239 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -216,6 +216,7 @@ scan_fs_tree( { struct workqueue wq; struct scan_fs_tree sft; + bool moveon = false; int ret; sft.moveon = true; @@ -224,14 +225,22 @@ scan_fs_tree( sft.dir_fn = dir_fn; sft.dirent_fn = dirent_fn; sft.arg = arg; - pthread_mutex_init(&sft.lock, NULL); - pthread_cond_init(&sft.wakeup, NULL); + ret = pthread_mutex_init(&sft.lock, NULL); + if (ret) { + str_liberror(ctx, ret, _("creating directory scan lock")); + return false; + } + ret = pthread_cond_init(&sft.wakeup, NULL); + if (ret) { + str_liberror(ctx, ret, _("creating directory scan signal")); + goto out_mutex; + } ret = workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); if (ret) { - str_info(ctx, ctx->mntpoint, _("Could not create workqueue.")); - return false; + str_liberror(ctx, ret, _("creating directory scan workqueue")); + goto out_cond; } ret = queue_subdir(ctx, &sft, &wq, ctx->mntpoint, true); @@ -255,12 +264,18 @@ scan_fs_tree( ret = workqueue_terminate(&wq); if (ret) { - sft.moveon = false; str_liberror(ctx, ret, _("finishing directory scan work")); + goto out_wq; } + + moveon = sft.moveon; out_wq: workqueue_destroy(&wq); - return sft.moveon; +out_cond: + pthread_cond_destroy(&sft.wakeup); +out_mutex: + pthread_mutex_destroy(&sft.lock); + return moveon; } #ifndef FITRIM