From: David Sterba <dsterba@suse.cz>
To: Miao Xie <miaox@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 06/10] Btrfs: Fix the problem that the dirty flag of dev stats is cleared
Date: Thu, 24 Jul 2014 15:45:49 +0200 [thread overview]
Message-ID: <20140724134549.GD1553@twin.jikos.cz> (raw)
In-Reply-To: <1406173035-29478-6-git-send-email-miaox@cn.fujitsu.com>
On Thu, Jul 24, 2014 at 11:37:11AM +0800, Miao Xie wrote:
> The io error might happen during writing out the device stats, and the
> device stats information and dirty flag would be update at that time,
> but the current code didn't consider this case, just clear the dirty
> flag, it would cause that we forgot to write out the new device stats
> information. Fix it.
>
> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
> ---
> fs/btrfs/volumes.c | 7 +++++--
> fs/btrfs/volumes.h | 19 +++++++++++++++----
> 2 files changed, 20 insertions(+), 6 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 19188df..0d37746 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -159,6 +159,7 @@ static struct btrfs_device *__alloc_device(void)
>
> spin_lock_init(&dev->reada_lock);
> atomic_set(&dev->reada_in_flight, 0);
> + atomic_set(&dev->dev_stats_ccnt, 0);
> INIT_RADIX_TREE(&dev->reada_zones, GFP_NOFS & ~__GFP_WAIT);
> INIT_RADIX_TREE(&dev->reada_extents, GFP_NOFS & ~__GFP_WAIT);
>
> @@ -6398,16 +6399,18 @@ int btrfs_run_dev_stats(struct btrfs_trans_handle *trans,
> struct btrfs_root *dev_root = fs_info->dev_root;
> struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
> struct btrfs_device *device;
> + int stats_cnt;
> int ret = 0;
>
> mutex_lock(&fs_devices->device_list_mutex);
> list_for_each_entry(device, &fs_devices->devices, dev_list) {
> - if (!device->dev_stats_valid || !device->dev_stats_dirty)
> + if (!device->dev_stats_valid || !btrfs_dev_stats_dirty(device))
The helper btrfs_dev_stats_dirty is used only once and IMHO not
necessary.
> continue;
>
> + stats_cnt = atomic_read(&device->dev_stats_ccnt);
Here it is opencoded anyway.
> ret = update_dev_stat_item(trans, dev_root, device);
> if (!ret)
> - device->dev_stats_dirty = 0;
> + atomic_sub(stats_cnt, &device->dev_stats_ccnt);
> }
> mutex_unlock(&fs_devices->device_list_mutex);
>
> diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
> index 6fcc8ea..0defd23 100644
> --- a/fs/btrfs/volumes.h
> +++ b/fs/btrfs/volumes.h
> @@ -110,7 +110,9 @@ struct btrfs_device {
> /* disk I/O failure stats. For detailed description refer to
> * enum btrfs_dev_stat_values in ioctl.h */
> int dev_stats_valid;
> - int dev_stats_dirty; /* counters need to be written to disk */
> +
> + /* Counter to record the change of device stats */
> + atomic_t dev_stats_ccnt;
dev_stats_dirty is more descriptive, please keep it. The counter
semantics can be documented here.
> atomic_t dev_stat_values[BTRFS_DEV_STAT_VALUES_MAX];
> };
>
> @@ -359,11 +361,18 @@ unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
> int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
> struct btrfs_root *extent_root,
> u64 chunk_offset, u64 chunk_size);
> +
> +static inline int btrfs_dev_stats_dirty(struct btrfs_device *dev)
> +{
> + return atomic_read(&dev->dev_stats_ccnt);
IMHO too trivial, not necessary.
> +}
> +
> static inline void btrfs_dev_stat_inc(struct btrfs_device *dev,
> int index)
> {
> atomic_inc(dev->dev_stat_values + index);
> - dev->dev_stats_dirty = 1;
> + smp_mb__before_atomic();
> + atomic_inc(&dev->dev_stats_ccnt);
Please put the two lines into a wrapper, 3 times repeating the same is
worth it.
> @@ -378,7 +387,8 @@ static inline int btrfs_dev_stat_read_and_reset(struct btrfs_device *dev,
> int ret;
>
> ret = atomic_xchg(dev->dev_stat_values + index, 0);
> - dev->dev_stats_dirty = 1;
> + smp_mb__before_atomic();
> + atomic_inc(&dev->dev_stats_ccnt);
> @@ -386,7 +396,8 @@ static inline void btrfs_dev_stat_set(struct btrfs_device *dev,
> int index, unsigned long val)
> {
> atomic_set(dev->dev_stat_values + index, val);
> - dev->dev_stats_dirty = 1;
> + smp_mb__before_atomic();
> + atomic_inc(&dev->dev_stats_ccnt);
next prev parent reply other threads:[~2014-07-24 13:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-24 3:37 [PATCH 01/10] Btrfs: Fix the problem that the replace destroys the seed filesystem Miao Xie
2014-07-24 3:37 ` [PATCH 02/10] Btrfs: don't write any data into a readonly device when scrub Miao Xie
2014-07-24 13:19 ` David Sterba
2014-07-25 9:39 ` Anand Jain
2014-07-24 3:37 ` [PATCH 03/10] Btrfs: fix wrong fsid check of scrub Miao Xie
2014-07-24 13:24 ` David Sterba
2014-09-03 6:58 ` [PATCH v2 " Miao Xie
2014-07-24 3:37 ` [PATCH 04/10] Btrfs: fix wrong generation check of super block on a seed device Miao Xie
2014-07-24 13:25 ` David Sterba
2014-07-24 3:37 ` [PATCH 05/10] Btrfs: make the device lock and its protected data in the same cacheline Miao Xie
2014-07-24 3:37 ` [PATCH 06/10] Btrfs: Fix the problem that the dirty flag of dev stats is cleared Miao Xie
2014-07-24 13:45 ` David Sterba [this message]
2014-09-03 6:59 ` [PATCH v2 " Miao Xie
2014-07-24 3:37 ` [PATCH 07/10] Btrfs: update the comment of total_bytes and disk_total_bytes of btrfs_devie Miao Xie
2014-07-24 3:37 ` [PATCH 08/10] Btrfs: Fix wrong device size when we are resizing the device Miao Xie
2014-07-24 3:37 ` [PATCH 09/10] Btrfs: don't consider the missing device when allocating new chunks Miao Xie
2014-07-24 3:37 ` [PATCH 10/10] Btrfs: cleanup unused latest_devid and latest_trans in fs_devices Miao Xie
2014-07-24 13:13 ` [PATCH 01/10] Btrfs: Fix the problem that the replace destroys the seed filesystem David Sterba
2014-07-25 7:56 ` Anand Jain
2014-07-25 12:33 ` [PATCH] btrfs: replace seed device followed by unmount causes kernel WARNING Anand Jain
2014-07-30 7:42 ` Miao Xie
2014-07-31 8:45 ` Anand Jain
2014-08-11 9:46 ` Anand Jain
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=20140724134549.GD1553@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=miaox@cn.fujitsu.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).