linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	Miklos Szeredi <miklos@szeredi.hu>,
	David Howells <dhowells@redhat.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] fs: create kiocb_{start,end}_write() helpers
Date: Tue, 15 Aug 2023 15:16:15 -0600	[thread overview]
Message-ID: <264fbb0a-5fd1-447d-a373-389f74a12bcf@kernel.dk> (raw)
In-Reply-To: <CAOQ4uxh4YYs2=mqqZMi-L=a19gmcgi7M+2F7iy2WDUf=iqZtxQ@mail.gmail.com>

On 8/15/23 12:48 PM, Amir Goldstein wrote:
> On Tue, Aug 15, 2023 at 8:06?PM Jens Axboe <axboe@kernel.dk> wrote:
>>
>> On 8/15/23 11:02 AM, Jens Axboe wrote:
>>> On 8/15/23 10:57 AM, Amir Goldstein wrote:
>>>> +/**
>>>> + * kiocb_start_write - get write access to a superblock for async file io
>>>> + * @iocb: the io context we want to submit the write with
>>>> + *
>>>> + * This is a variant of file_start_write() for async io submission.
>>>> + * Should be matched with a call to kiocb_end_write().
>>>> + */
>>>> +static inline void kiocb_start_write(struct kiocb *iocb)
>>>> +{
>>>> +    struct inode *inode = file_inode(iocb->ki_filp);
>>>> +
>>>> +    iocb->ki_flags |= IOCB_WRITE;
>>>> +    if (WARN_ON_ONCE(iocb->ki_flags & IOCB_WRITE_STARTED))
>>>> +            return;
>>>> +    if (!S_ISREG(inode->i_mode))
>>>> +            return;
>>>> +    sb_start_write(inode->i_sb);
>>>> +    /*
>>>> +     * Fool lockdep by telling it the lock got released so that it
>>>> +     * doesn't complain about the held lock when we return to userspace.
>>>> +     */
>>>> +    __sb_writers_release(inode->i_sb, SB_FREEZE_WRITE);
>>>> +    iocb->ki_flags |= IOCB_WRITE_STARTED;
>>>> +}
>>>> +
>>>> +/**
>>>> + * kiocb_end_write - drop write access to a superblock after async file io
>>>> + * @iocb: the io context we sumbitted the write with
>>>> + *
>>>> + * Should be matched with a call to kiocb_start_write().
>>>> + */
>>>> +static inline void kiocb_end_write(struct kiocb *iocb)
>>>> +{
>>>> +    struct inode *inode = file_inode(iocb->ki_filp);
>>>> +
>>>> +    if (!(iocb->ki_flags & IOCB_WRITE_STARTED))
>>>> +            return;
>>>> +    if (!S_ISREG(inode->i_mode))
>>>> +            return;
>>
>> And how would IOCB_WRITE_STARTED ever be set, if S_ISREG() isn't true?
> 
> Good point.
> I will pass is_reg argument from callers of kiocb_start_write() and
> will only check IOCB_WRITE_STARTED in kiocb_end_write().

Please don't pass in an argument that just makes the function do
nothing. Just gate calling the function on it instead.

-- 
Jens Axboe


  reply	other threads:[~2023-08-15 21:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-15 16:57 [PATCH] fs: create kiocb_{start,end}_write() helpers Amir Goldstein
2023-08-15 17:02 ` Jens Axboe
2023-08-15 17:06   ` Jens Axboe
2023-08-15 18:48     ` Amir Goldstein
2023-08-15 21:16       ` Jens Axboe [this message]
2023-08-16  8:51         ` Christian Brauner
2023-08-16 14:04           ` Jens Axboe

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=264fbb0a-5fd1-447d-a373-389f74a12bcf@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@zeniv.linux.org.uk \
    /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).