linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org, linux-fscrypt@vger.kernel.org
Subject: Re: [PATCH 1/6] block: Add blk_completion
Date: Tue, 27 Oct 2020 18:30:39 +0000	[thread overview]
Message-ID: <20201027183039.GA7983@infradead.org> (raw)
In-Reply-To: <20201022212228.15703-2-willy@infradead.org>

On Thu, Oct 22, 2020 at 10:22:23PM +0100, Matthew Wilcox (Oracle) wrote:
> This new data structure allows a task to wait for N things to complete.
> Usually the submitting task will handle cleanup, but if it is killed,
> the last completer will take care of it.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
>  block/blk-core.c    | 61 +++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/bio.h | 11 ++++++++
>  2 files changed, 72 insertions(+)
> 
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 10c08ac50697..2892246f2176 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -1900,6 +1900,67 @@ void blk_io_schedule(void)
>  }
>  EXPORT_SYMBOL_GPL(blk_io_schedule);
>  
> +void blk_completion_init(struct blk_completion *cmpl, int n)
> +{
> +	spin_lock_init(&cmpl->cmpl_lock);
> +	cmpl->cmpl_count = n;
> +	cmpl->cmpl_task = current;
> +	cmpl->cmpl_status = BLK_STS_OK;
> +}
> +
> +int blk_completion_sub(struct blk_completion *cmpl, blk_status_t status, int n)

This needs documentation.  e.g. to explain what 'n' is.

> +int blk_completion_wait_killable(struct blk_completion *cmpl)
> +{
> +	int err = 0;
> +
> +	for (;;) {
> +		set_current_state(TASK_KILLABLE);
> +		spin_lock_bh(&cmpl->cmpl_lock);
> +		if (cmpl->cmpl_count == 0)
> +			break;
> +		spin_unlock_bh(&cmpl->cmpl_lock);
> +		blk_io_schedule();
> +		if (fatal_signal_pending(current)) {
> +			spin_lock_bh(&cmpl->cmpl_lock);
> +			cmpl->cmpl_task = NULL;
> +			if (cmpl->cmpl_count != 0) {
> +				spin_unlock_bh(&cmpl->cmpl_lock);
> +				cmpl = NULL;
> +			}
> +			err = -ERESTARTSYS;
> +			break;
> +		}
> +	}
> +	set_current_state(TASK_RUNNING);
> +	if (cmpl) {
> +		spin_unlock_bh(&cmpl->cmpl_lock);
> +		err = blk_status_to_errno(cmpl->cmpl_status);
> +		kfree(cmpl);
> +	}
> +
> +	return err;
> +}

What are the life time rules for cmpl?  Who frees it in the case
of a fatal signal?

  reply	other threads:[~2020-10-27 18:30 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-22 21:22 [PATCH 0/6] Make block_read_full_page synchronous Matthew Wilcox (Oracle)
2020-10-22 21:22 ` [PATCH 1/6] block: Add blk_completion Matthew Wilcox (Oracle)
2020-10-27 18:30   ` Christoph Hellwig [this message]
2020-10-22 21:22 ` [PATCH 2/6] fs: Return error from block_read_full_page Matthew Wilcox (Oracle)
2020-10-22 21:22 ` [PATCH 3/6] fs: Convert block_read_full_page to be synchronous Matthew Wilcox (Oracle)
2020-10-22 23:35   ` Eric Biggers
2020-10-22 23:40   ` Eric Biggers
2020-10-23 13:21     ` Matthew Wilcox
2020-10-23 16:13       ` Eric Biggers
2020-10-23 20:42         ` Matthew Wilcox
2020-10-22 21:22 ` [PATCH 4/6] fs: Hoist fscrypt decryption to bio completion handler Matthew Wilcox (Oracle)
2020-10-22 21:22 ` [PATCH 5/6] fs: Turn decrypt_bh into decrypt_bio Matthew Wilcox (Oracle)
2020-10-22 21:22 ` [PATCH 6/6] fs: Convert block_read_full_page to be synchronous with fscrypt enabled Matthew Wilcox (Oracle)

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=20201027183039.GA7983@infradead.org \
    --to=hch@infradead.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=willy@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).