linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: dsterba@suse.cz, Marcos Paulo de Souza <mpdesouza@suse.com>,
	linux-btrfs@vger.kernel.org, dsterba@suse.com
Subject: Re: [PATCH 5/8] btrfs: inode: use btrfs_for_each_slot in btrfs_read_readdir
Date: Tue, 31 Aug 2021 14:27:07 +0300	[thread overview]
Message-ID: <b61685b1-db19-872f-8c9e-74dfe6c80ca7@suse.com> (raw)
In-Reply-To: <20210831111051.GH3379@twin.jikos.cz>



On 31.08.21 г. 14:10, David Sterba wrote:
> On Mon, Aug 30, 2021 at 04:05:28PM +0300, Nikolay Borisov wrote:
>>> @@ -6137,35 +6136,19 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
>>>  	key.offset = ctx->pos;
>>>  	key.objectid = btrfs_ino(BTRFS_I(inode));
>>>  
>>> -	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
>>> -	if (ret < 0)
>>> -		goto err;
>>> -
>>> -	while (1) {
>>> +	btrfs_for_each_slot(root, &key, &found_key, path, iter_ret) {
>>
>> I don't think it's necessary to use iter_ret, instead you can use ret
>> directly. Because if either btrfs_search_slot return an error or
>> btrfs_valid_slot then ret would be set to the respective return value
>> and the body of the loop won't be executed at all, no?
> 
> Yeah thre's no reason to add another variable in this case. As long as
> the loop body does not use ret internally, then reusing ret is fine.
> 
> The point of having an explicit return value for the iterator is to be
> able to read the reason of failure after the iterator scope ends, so it
> can't be defined inside. We'd need to be careful to make sure that the
> iterator 'ret' is never used inside the body so that could be also
> useful to put to the documentation. I think a coccinelle script can be
> also useful to catch such things.
> 

Actually even if 'ret' is used inside the loop body it's still fine.
That's because as soon as we call the btrfs_valid_item (aka iter) and it
returns an error we break from the loop.

  reply	other threads:[~2021-08-31 11:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-26 16:40 [PATCHv2 0/8] btrfs: Create macro to iterate slots Marcos Paulo de Souza
2021-08-26 16:40 ` [PATCH 1/8] fs: btrfs: Introduce btrfs_for_each_slot Marcos Paulo de Souza
2021-08-30 12:37   ` Nikolay Borisov
2021-08-31 11:03     ` David Sterba
2021-08-31 11:06   ` David Sterba
2021-08-26 16:40 ` [PATCH 2/8] btrfs: block-group: use btrfs_for_each_slot in find_first_block_group Marcos Paulo de Souza
2021-08-26 16:40 ` [PATCH 3/8] btrfs: dev-replace: Use btrfs_for_each_slot in mark_block_group_to_copy Marcos Paulo de Souza
2021-08-26 16:40 ` [PATCH 4/8] btrfs: dir-item: use btrfs_for_each_slot in btrfs_search_dir_index_item Marcos Paulo de Souza
2021-08-26 16:40 ` [PATCH 5/8] btrfs: inode: use btrfs_for_each_slot in btrfs_read_readdir Marcos Paulo de Souza
2021-08-30 13:05   ` Nikolay Borisov
2021-08-31 11:10     ` David Sterba
2021-08-31 11:27       ` Nikolay Borisov [this message]
2021-08-26 16:40 ` [PATCH 6/8] btrfs: send: Use btrfs_for_each_slot macro Marcos Paulo de Souza
2021-08-30 13:53   ` Nikolay Borisov
2021-08-26 16:40 ` [PATCH 7/8] btrfs: volumes: use btrfs_for_each_slot in btrfs_read_chunk_tree Marcos Paulo de Souza
2021-08-26 16:40 ` [PATCH 8/8] btrfs: xattr: Use btrfs_for_each_slot macro in btrfs_listxattr Marcos Paulo de Souza
2021-08-26 18:06 ` [PATCHv2 0/8] btrfs: Create macro to iterate slots Marcos Paulo de Souza
2021-08-31 11:17 ` David Sterba

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=b61685b1-db19-872f-8c9e-74dfe6c80ca7@suse.com \
    --to=nborisov@suse.com \
    --cc=dsterba@suse.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=mpdesouza@suse.com \
    /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).