From patchwork Fri Sep 6 03:34:03 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: 11134293 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 5E15F924 for ; Fri, 6 Sep 2019 03:34:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44B5420820 for ; Fri, 6 Sep 2019 03:34:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="XIK4eVI2" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392118AbfIFDeI (ORCPT ); Thu, 5 Sep 2019 23:34:08 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:47718 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392128AbfIFDeI (ORCPT ); Thu, 5 Sep 2019 23:34:08 -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 x863Y1v7109808; Fri, 6 Sep 2019 03:34:05 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=bWhWLK7qg/BuhufbP+WJDZ+OfiQbQL1c9m5+c5+2r9k=; b=XIK4eVI2Vky4clfF3d5x36tbRR2JX6dgeIotF3FzUxRaI2CtGyKmUqh4mxqLpHBtDVLR SFgrWlV210oG/rs+q/svrqJ2CTXq9g/Sa1E+Upus2VLPjlYQNtKheDEfBCbJ/zz0lqu8 IFWBDxe1WxPPIKrp79Resxep2fljzGL2XaXIk62wyyxQGKLLeqnu411jcNYE9AGuJYXI SDNooeuXQLNj8dc4PfvyuS46oae4NegZ3kRjP4M1En/zuPn+TYH/6CVNiUXJdWsIqW3p 1yBdcrW7/4Z3OZ3CCaFCF55YX8IXi90zoVystto10y4purn0YKWu99dcEOYfIhqYcPAc mA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2uuf4n033y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:34:05 +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 x863XbVg069127; Fri, 6 Sep 2019 03:34:05 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3020.oracle.com with ESMTP id 2utvr4js6d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:34:05 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863Y4wk003594; Fri, 6 Sep 2019 03:34:04 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:34:03 -0700 Subject: [PATCH 1/3] xfs_scrub: refactor queueing of subdir scan work item From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Thu, 05 Sep 2019 20:34:03 -0700 Message-ID: <156774084332.2643257.12234848325153797756.stgit@magnolia> In-Reply-To: <156774083707.2643257.15738851266613887341.stgit@magnolia> References: <156774083707.2643257.15738851266613887341.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 Replace the open-coded process of queueing a subdirectory for scanning with a single helper function. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- scrub/vfs.c | 109 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 42 deletions(-) diff --git a/scrub/vfs.c b/scrub/vfs.c index b5d54837..add4e815 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -43,6 +43,57 @@ struct scan_fs_tree_dir { bool rootdir; }; +static void scan_fs_dir(struct workqueue *wq, xfs_agnumber_t agno, void *arg); + +/* Queue a directory for scanning. */ +static bool +queue_subdir( + struct scrub_ctx *ctx, + struct scan_fs_tree *sft, + struct workqueue *wq, + const char *path, + bool is_rootdir) +{ + struct scan_fs_tree_dir *new_sftd; + int error; + + new_sftd = malloc(sizeof(struct scan_fs_tree_dir)); + if (!new_sftd) { + str_errno(ctx, _("creating directory scan context")); + return false; + } + + new_sftd->path = strdup(path); + if (!new_sftd->path) { + str_errno(ctx, _("creating directory scan path")); + goto out_sftd; + } + + new_sftd->sft = sft; + new_sftd->rootdir = is_rootdir; + + pthread_mutex_lock(&sft->lock); + sft->nr_dirs++; + pthread_mutex_unlock(&sft->lock); + error = workqueue_add(wq, scan_fs_dir, 0, new_sftd); + if (error) { + /* + * XXX: need to decrement nr_dirs here; will do that in the + * next patch. + */ + str_info(ctx, ctx->mntpoint, +_("Could not queue subdirectory scan work.")); + goto out_path; + } + + return true; +out_path: + free(new_sftd->path); +out_sftd: + free(new_sftd); + return false; +} + /* Scan a directory sub tree. */ static void scan_fs_dir( @@ -56,7 +107,6 @@ scan_fs_dir( DIR *dir; struct dirent *dirent; char newpath[PATH_MAX]; - struct scan_fs_tree_dir *new_sftd; struct stat sb; int dir_fd; int error; @@ -117,25 +167,10 @@ scan_fs_dir( /* If directory, call ourselves recursively. */ if (S_ISDIR(sb.st_mode) && strcmp(".", dirent->d_name) && strcmp("..", dirent->d_name)) { - new_sftd = malloc(sizeof(struct scan_fs_tree_dir)); - if (!new_sftd) { - str_errno(ctx, newpath); - sft->moveon = false; - break; - } - new_sftd->path = strdup(newpath); - new_sftd->sft = sft; - new_sftd->rootdir = false; - pthread_mutex_lock(&sft->lock); - sft->nr_dirs++; - pthread_mutex_unlock(&sft->lock); - error = workqueue_add(wq, scan_fs_dir, 0, new_sftd); - if (error) { - str_info(ctx, ctx->mntpoint, -_("Could not queue subdirectory scan work.")); - sft->moveon = false; + sft->moveon = queue_subdir(ctx, sft, wq, newpath, + false); + if (!sft->moveon) break; - } } } @@ -165,11 +200,10 @@ scan_fs_tree( { struct workqueue wq; struct scan_fs_tree sft; - struct scan_fs_tree_dir *sftd; int ret; sft.moveon = true; - sft.nr_dirs = 1; + sft.nr_dirs = 0; sft.root_sb = ctx->mnt_sb; sft.dir_fn = dir_fn; sft.dirent_fn = dirent_fn; @@ -177,41 +211,32 @@ scan_fs_tree( pthread_mutex_init(&sft.lock, NULL); pthread_cond_init(&sft.wakeup, NULL); - sftd = malloc(sizeof(struct scan_fs_tree_dir)); - if (!sftd) { - str_errno(ctx, ctx->mntpoint); - return false; - } - sftd->path = strdup(ctx->mntpoint); - sftd->sft = &sft; - sftd->rootdir = true; - ret = workqueue_create(&wq, (struct xfs_mount *)ctx, scrub_nproc_workqueue(ctx)); if (ret) { str_info(ctx, ctx->mntpoint, _("Could not create workqueue.")); - goto out_free; + return false; } - ret = workqueue_add(&wq, scan_fs_dir, 0, sftd); - if (ret) { - str_info(ctx, ctx->mntpoint, -_("Could not queue directory scan work.")); + + sft.moveon = queue_subdir(ctx, &sft, &wq, ctx->mntpoint, true); + if (!sft.moveon) goto out_wq; - } + /* + * Wait for the wakeup to trigger, which should only happen when the + * last worker thread decrements nr_dirs to zero. Once the worker + * triggers the wakeup and unlocks the sft lock, it's no longer safe + * for any worker thread to access sft, as we now own the lock and are + * about to tear everything down. + */ pthread_mutex_lock(&sft.lock); pthread_cond_wait(&sft.wakeup, &sft.lock); assert(sft.nr_dirs == 0); pthread_mutex_unlock(&sft.lock); - workqueue_destroy(&wq); - return sft.moveon; out_wq: workqueue_destroy(&wq); -out_free: - free(sftd->path); - free(sftd); - return false; + return sft.moveon; } #ifndef FITRIM From patchwork Fri Sep 6 03:34:09 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: 11134307 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 4B2FC13BD for ; Fri, 6 Sep 2019 03:34:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30250206B8 for ; Fri, 6 Sep 2019 03:34:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="HOvBb8Bs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730914AbfIFDes (ORCPT ); Thu, 5 Sep 2019 23:34:48 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:48344 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404422AbfIFDer (ORCPT ); Thu, 5 Sep 2019 23:34:47 -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 x863YROH110101; Fri, 6 Sep 2019 03:34: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=PLGCz0g+q3R0fzk//ee5GCzfpWRIQI0a75gt/FydX4k=; b=HOvBb8BsPoAMRHkof3LSp2sHPQRwzFkLkG5YXfMfeumUdnvx4icuIA9XF6IVQrrS9o7t p37uPAQZL7rivNDgBhtjgO3uZ+UtxeaehnraX3vi+d5rhXAl11p5me+raaURNFgsLy9Q FZYalIt4HH9lNGho/REICehZ9y6n0QI33a5uqJ3H17pUYItGlfYJmSAp7YedlbTxbpTL Y7r1vkWf/Mk18cnHaHuBuXVLinNkBB26k923eYNMsPdwGVv+XbrnWJkDgldTlhgXej5L RdEhU0V4DR1JSBQjWveYuK/yjaRxx/P2XNHpopivYIQ4zBxEUoBhT89UQradB8X+s60l GA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2uuf4n0350-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:34:35 +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 x863YVx3103620; Fri, 6 Sep 2019 03:34:35 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 2uud7p2pmv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:34:31 +0000 Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x863YA1U018732; Fri, 6 Sep 2019 03:34:10 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:34:10 -0700 Subject: [PATCH 2/3] xfs_scrub: fix nr_dirs accounting problems From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Dave Chinner Date: Thu, 05 Sep 2019 20:34:09 -0700 Message-ID: <156774084974.2643257.15403943146639779829.stgit@magnolia> In-Reply-To: <156774083707.2643257.15738851266613887341.stgit@magnolia> References: <156774083707.2643257.15738851266613887341.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 When we're scanning the directory tree, we bump nr_dirs every time we think we're going to queue a new directory to process, and we decrement it every time we're finished doing something with a directory (successful or not). We forgot to undo a counter increment when workqueue_add fails, so refactor the code into helpers and call them as necessary for correct operation. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- scrub/vfs.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/scrub/vfs.c b/scrub/vfs.c index add4e815..f8bc98c0 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -45,6 +45,32 @@ struct scan_fs_tree_dir { static void scan_fs_dir(struct workqueue *wq, xfs_agnumber_t agno, void *arg); +/* Increment the number of directories that are queued for processing. */ +static void +inc_nr_dirs( + struct scan_fs_tree *sft) +{ + pthread_mutex_lock(&sft->lock); + sft->nr_dirs++; + pthread_mutex_unlock(&sft->lock); +} + +/* + * Decrement the number of directories that are queued for processing and if + * we ran out of dirs to process, wake up anyone who was waiting for processing + * to finish. + */ +static void +dec_nr_dirs( + struct scan_fs_tree *sft) +{ + pthread_mutex_lock(&sft->lock); + sft->nr_dirs--; + if (sft->nr_dirs == 0) + pthread_cond_signal(&sft->wakeup); + pthread_mutex_unlock(&sft->lock); +} + /* Queue a directory for scanning. */ static bool queue_subdir( @@ -72,15 +98,10 @@ queue_subdir( new_sftd->sft = sft; new_sftd->rootdir = is_rootdir; - pthread_mutex_lock(&sft->lock); - sft->nr_dirs++; - pthread_mutex_unlock(&sft->lock); + inc_nr_dirs(sft); error = workqueue_add(wq, scan_fs_dir, 0, new_sftd); if (error) { - /* - * XXX: need to decrement nr_dirs here; will do that in the - * next patch. - */ + dec_nr_dirs(sft); str_info(ctx, ctx->mntpoint, _("Could not queue subdirectory scan work.")); goto out_path; @@ -180,12 +201,7 @@ scan_fs_dir( str_errno(ctx, sftd->path); out: - pthread_mutex_lock(&sft->lock); - sft->nr_dirs--; - if (sft->nr_dirs == 0) - pthread_cond_signal(&sft->wakeup); - pthread_mutex_unlock(&sft->lock); - + dec_nr_dirs(sft); free(sftd->path); free(sftd); } From patchwork Fri Sep 6 03:34:16 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: 11134297 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 6F38813BD for ; Fri, 6 Sep 2019 03:34:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5EA552082C for ; Fri, 6 Sep 2019 03:34:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="dnXA19EF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392132AbfIFDea (ORCPT ); Thu, 5 Sep 2019 23:34:30 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:33304 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392128AbfIFDea (ORCPT ); Thu, 5 Sep 2019 23:34:30 -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 x863XvJm105018; Fri, 6 Sep 2019 03:34:19 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=/jdZlyEQ50y2ae2IghUP3PSW9UoCx3jwJH+IxpSHBGI=; b=dnXA19EFac15FHRqZjLuajDUhhmXhAwZyo+KtCYY2FAhI2V16BHp/GOTQQWAlpICU/uL jKiddyfH2hCdM18mST0UGKhQFJnMmzu49OTkFyAvCZczu7R+U1pvYTM1QCdPO7z0pf/C GL0qioPWSn9RGCilt8SoDRFXB2Atm9F1jxDngpPv06JK8KIiwe2e7LV8zqltlsbfBEij Pj5kevCfeg5xOlMkekV5BtX/vJwoa3aEzn3JbjR8B/RagTbFNmLbwZWPc11g+3o4l/s2 1J2tyrsI4fY3qYW32/GePN7xgOWyt4Ke3bUM9tcKEzxWW4syQGNcrybgRRpJZAx5JXvr rw== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2uuf5f82ug-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:34:19 +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 x863XTDB188675; Fri, 6 Sep 2019 03:34:18 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 2utpmc73xx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 06 Sep 2019 03:34:18 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x863YHw5003626; Fri, 6 Sep 2019 03:34:17 GMT Received: from localhost (/10.159.148.70) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 05 Sep 2019 20:34:17 -0700 Subject: [PATCH 3/3] xfs_scrub: remove unnecessary wakeup wait in scan_fs_tree From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, Dave Chinner Date: Thu, 05 Sep 2019 20:34:16 -0700 Message-ID: <156774085609.2643257.18220893434559330906.stgit@magnolia> In-Reply-To: <156774083707.2643257.15738851266613887341.stgit@magnolia> References: <156774083707.2643257.15738851266613887341.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 We don't need to wait on the condition variable if directory tree scanning has already finished by the time we've finished queueing all the directory work items. This is easy to trigger when the workqueue is single-threaded, but in theory it could happen any time. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner --- scrub/vfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scrub/vfs.c b/scrub/vfs.c index f8bc98c0..1a1482dd 100644 --- a/scrub/vfs.c +++ b/scrub/vfs.c @@ -246,7 +246,8 @@ scan_fs_tree( * about to tear everything down. */ pthread_mutex_lock(&sft.lock); - pthread_cond_wait(&sft.wakeup, &sft.lock); + if (sft.nr_dirs) + pthread_cond_wait(&sft.wakeup, &sft.lock); assert(sft.nr_dirs == 0); pthread_mutex_unlock(&sft.lock);