All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: shr@fb.com
Cc: linux-btrfs@vger.kernel.org
Subject: [bug report] btrfs: enable nowait async buffered writes
Date: Fri, 23 Sep 2022 17:53:04 +0300	[thread overview]
Message-ID: <Yy3IUPYheKipaIei@kili> (raw)

Hello Stefan Roesch,

The patch 8bf465b1c880: "btrfs: enable nowait async buffered writes"
from Sep 12, 2022, leads to the following Smatch static checker
warning:

	fs/btrfs/file.c:2113 btrfs_do_write_iter()
	warn: refcount leak 'inode->sync_writers.counter': lines='2113'

fs/btrfs/file.c
    2092 ssize_t btrfs_do_write_iter(struct kiocb *iocb, struct iov_iter *from,
    2093                             const struct btrfs_ioctl_encoded_io_args *encoded)
    2094 {
    2095         struct file *file = iocb->ki_filp;
    2096         struct btrfs_inode *inode = BTRFS_I(file_inode(file));
    2097         ssize_t num_written, num_sync;
    2098         const bool sync = iocb_is_dsync(iocb);
    2099 
    2100         /*
    2101          * If the fs flips readonly due to some impossible error, although we
    2102          * have opened a file as writable, we have to stop this write operation
    2103          * to ensure consistency.
    2104          */
    2105         if (BTRFS_FS_ERROR(inode->root->fs_info))
    2106                 return -EROFS;
    2107 
    2108         if (sync)
    2109                 atomic_inc(&inode->sync_writers);
    2110 
    2111         if (encoded) {
    2112                 if (iocb->ki_flags & IOCB_NOWAIT)
--> 2113                         return -EOPNOTSUPP;

This check used to happen before the atomic_inc(&inode->sync_writers);

    2114 
    2115                 num_written = btrfs_encoded_write(iocb, from, encoded);
    2116                 num_sync = encoded->len;
    2117         } else if (iocb->ki_flags & IOCB_DIRECT) {
    2118                 num_written = btrfs_direct_write(iocb, from);
    2119                 num_sync = num_written;
    2120         } else {
    2121                 num_written = btrfs_buffered_write(iocb, from);
    2122                 num_sync = num_written;
    2123         }
    2124 
    2125         btrfs_set_inode_last_sub_trans(inode);
    2126 
    2127         if (num_sync > 0) {
    2128                 num_sync = generic_write_sync(iocb, num_sync);
    2129                 if (num_sync < 0)
    2130                         num_written = num_sync;
    2131         }
    2132 
    2133         if (sync)
    2134                 atomic_dec(&inode->sync_writers);
    2135 
    2136         current->backing_dev_info = NULL;
    2137         return num_written;
    2138 }

regards,
dan carpenter

             reply	other threads:[~2022-09-23 14:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 14:53 Dan Carpenter [this message]
2022-09-26 17:21 ` [bug report] btrfs: enable nowait async buffered writes Stefan Roesch

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=Yy3IUPYheKipaIei@kili \
    --to=dan.carpenter@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=shr@fb.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 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.