All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: josef@toxicpanda.com
Cc: linux-btrfs@vger.kernel.org
Subject: [bug report] btrfs: clean up our handling of refs == 0 in snapshot delete
Date: Sun, 28 Apr 2024 15:54:15 +0300	[thread overview]
Message-ID: <96789032-42fb-41c0-b16c-561ac00ca7c3@moroto.mountain> (raw)

Hello Josef Bacik,

Commit a07155f4e6b8 ("btrfs: clean up our handling of refs == 0 in
snapshot delete") from Apr 19, 2024 (linux-next), leads to the
following Smatch static checker warning:

	fs/btrfs/extent-tree.c:5875 walk_up_proc()
	warn: inconsistent returns '&eb->lock'.

fs/btrfs/extent-tree.c
    5766 static noinline int walk_up_proc(struct btrfs_trans_handle *trans,
    5767                                  struct btrfs_root *root,
    5768                                  struct btrfs_path *path,
    5769                                  struct walk_control *wc)
    5770 {
    5771         struct btrfs_fs_info *fs_info = root->fs_info;
    5772         int ret;
    5773         int level = wc->level;
    5774         struct extent_buffer *eb = path->nodes[level];
    5775         u64 parent = 0;
    5776 
    5777         if (wc->stage == UPDATE_BACKREF) {
    5778                 ASSERT(wc->shared_level >= level);
    5779                 if (level < wc->shared_level)
    5780                         goto out;
    5781 
    5782                 ret = find_next_key(path, level + 1, &wc->update_progress);
    5783                 if (ret > 0)
    5784                         wc->update_ref = 0;
    5785 
    5786                 wc->stage = DROP_REFERENCE;
    5787                 wc->shared_level = -1;
    5788                 path->slots[level] = 0;
    5789 
    5790                 /*
    5791                  * check reference count again if the block isn't locked.
    5792                  * we should start walking down the tree again if reference
    5793                  * count is one.
    5794                  */
    5795                 if (!path->locks[level]) {
    5796                         ASSERT(level > 0);
    5797                         btrfs_tree_lock(eb);
                                 ^^^^^^^^^^^^^^^^^^^^
Takes the lock

    5798                         path->locks[level] = BTRFS_WRITE_LOCK;
    5799 
    5800                         ret = btrfs_lookup_extent_info(trans, fs_info,
    5801                                                        eb->start, level, 1,
    5802                                                        &wc->refs[level],
    5803                                                        &wc->flags[level],
    5804                                                        NULL);
    5805                         if (ret < 0) {
    5806                                 btrfs_tree_unlock_rw(eb, path->locks[level]);

These paths drop the lock

    5807                                 path->locks[level] = 0;
    5808                                 return ret;
    5809                         }
    5810                         if (unlikely(wc->refs[level] == 0)) {
    5811                                 btrfs_err(fs_info, "Missing refs.");
    5812                                 return -EUCLEAN;

But this new return doesn't.

    5813                         }
    5814                         if (wc->refs[level] == 1) {
    5815                                 btrfs_tree_unlock_rw(eb, path->locks[level]);
    5816                                 path->locks[level] = 0;
    5817                                 return 1;
    5818                         }
    5819                 }
    5820         }
    5821 
    5822         /* wc->stage == DROP_REFERENCE */

regards,
dan carpenter

                 reply	other threads:[~2024-04-28 12:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=96789032-42fb-41c0-b16c-561ac00ca7c3@moroto.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.