From: Dave Chinner <david@fromorbit.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: sandeen@sandeen.net, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 1/3] xfs_scrub: refactor queueing of subdir scan work item
Date: Wed, 4 Sep 2019 18:12:52 +1000 [thread overview]
Message-ID: <20190904081252.GC1119@dread.disaster.area> (raw)
In-Reply-To: <156685447885.2840069.3132139174368034407.stgit@magnolia>
On Mon, Aug 26, 2019 at 02:21:18PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Replace the open-coded process of queueing a subdirectory for scanning
> with a single helper function.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> scrub/vfs.c | 94 +++++++++++++++++++++++++++++++++--------------------------
> 1 file changed, 52 insertions(+), 42 deletions(-)
>
>
> diff --git a/scrub/vfs.c b/scrub/vfs.c
> index 7b0b5bcd..ea2866d9 100644
> --- a/scrub/vfs.c
> +++ b/scrub/vfs.c
> @@ -43,6 +43,49 @@ 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"));
> + free(new_sftd);
> + return false;
> + }
> +
> + 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) {
> + str_info(ctx, ctx->mntpoint,
> +_("Could not queue subdirectory scan work."));
> + return false;
Need to drop sft->nr_dirs here, probably free the memory, too.
> @@ -177,41 +203,25 @@ 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;
> - }
sft is a stack varable that is stuffed into the structure passed to
work run on the workqueue. Is that safe to do here?
> pthread_mutex_lock(&sft.lock);
> pthread_cond_wait(&sft.wakeup, &sft.lock);
maybe it is because of this, but it's not immediately obvious what
condition actually triggers and that all the work is done...
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
next prev parent reply other threads:[~2019-09-04 8:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-26 21:21 [PATCH 0/3] xfs_scrub: fix bugs in vfs tree walk code Darrick J. Wong
2019-08-26 21:21 ` [PATCH 1/3] xfs_scrub: refactor queueing of subdir scan work item Darrick J. Wong
2019-09-04 8:12 ` Dave Chinner [this message]
2019-09-04 16:37 ` Darrick J. Wong
2019-08-26 21:21 ` [PATCH 2/3] xfs_scrub: fix nr_dirs accounting problems Darrick J. Wong
2019-09-04 8:15 ` Dave Chinner
2019-08-26 21:21 ` [PATCH 3/3] xfs_scrub: remove unnecessary wakeup wait in scan_fs_tree Darrick J. Wong
2019-09-04 8:20 ` Dave Chinner
-- strict thread matches above, loose matches on Subject: below --
2019-09-06 3:33 [PATCH 0/3] xfs_scrub: fix bugs in vfs tree walk code Darrick J. Wong
2019-09-06 3:34 ` [PATCH 1/3] xfs_scrub: refactor queueing of subdir scan work item Darrick J. Wong
2019-09-10 1:04 ` Dave Chinner
2019-09-25 21:31 [PATCH 0/3] xfs_scrub: fix bugs in vfs tree walk code Darrick J. Wong
2019-09-25 21:31 ` [PATCH 1/3] xfs_scrub: refactor queueing of subdir scan work item Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190904081252.GC1119@dread.disaster.area \
--to=david@fromorbit.com \
--cc=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox