Commit e3b318d1 authored by Omar Sandoval's avatar Omar Sandoval Committed by David Sterba

btrfs: convert btrfs_dio_private->pending_bios to refcount_t

This is really a reference count now, so convert it to refcount_t and
rename it to refs.
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 2390a6da
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#define BTRFS_INODE_H #define BTRFS_INODE_H
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/refcount.h>
#include "extent_map.h" #include "extent_map.h"
#include "extent_io.h" #include "extent_io.h"
#include "ordered-data.h" #include "ordered-data.h"
...@@ -302,8 +303,11 @@ struct btrfs_dio_private { ...@@ -302,8 +303,11 @@ struct btrfs_dio_private {
u64 disk_bytenr; u64 disk_bytenr;
u64 bytes; u64 bytes;
/* number of bios pending for this dio */ /*
atomic_t pending_bios; * References to this structure. There is one reference per in-flight
* bio plus one while we're still setting up.
*/
refcount_t refs;
/* IO errors */ /* IO errors */
int errors; int errors;
......
...@@ -7811,7 +7811,7 @@ static void btrfs_end_dio_bio(struct bio *bio) ...@@ -7811,7 +7811,7 @@ static void btrfs_end_dio_bio(struct bio *bio)
} }
/* if there are more bios still pending for this dio, just exit */ /* if there are more bios still pending for this dio, just exit */
if (!atomic_dec_and_test(&dip->pending_bios)) if (!refcount_dec_and_test(&dip->refs))
goto out; goto out;
if (dip->errors) { if (dip->errors) {
...@@ -7929,7 +7929,7 @@ static struct btrfs_dio_private *btrfs_create_dio_private(struct bio *dio_bio, ...@@ -7929,7 +7929,7 @@ static struct btrfs_dio_private *btrfs_create_dio_private(struct bio *dio_bio,
dip->disk_bytenr = (u64)dio_bio->bi_iter.bi_sector << 9; dip->disk_bytenr = (u64)dio_bio->bi_iter.bi_sector << 9;
dip->orig_bio = bio; dip->orig_bio = bio;
dip->dio_bio = dio_bio; dip->dio_bio = dio_bio;
atomic_set(&dip->pending_bios, 1); refcount_set(&dip->refs, 1);
if (write) { if (write) {
struct btrfs_dio_data *dio_data = current->journal_info; struct btrfs_dio_data *dio_data = current->journal_info;
...@@ -8025,13 +8025,13 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, ...@@ -8025,13 +8025,13 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode,
* count. Otherwise, the dip might get freed before we're * count. Otherwise, the dip might get freed before we're
* done setting it up. * done setting it up.
*/ */
atomic_inc(&dip->pending_bios); refcount_inc(&dip->refs);
status = btrfs_submit_dio_bio(bio, inode, file_offset, status = btrfs_submit_dio_bio(bio, inode, file_offset,
async_submit); async_submit);
if (status) { if (status) {
bio_put(bio); bio_put(bio);
atomic_dec(&dip->pending_bios); refcount_dec(&dip->refs);
goto out_err; goto out_err;
} }
...@@ -8060,7 +8060,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode, ...@@ -8060,7 +8060,7 @@ static void btrfs_submit_direct(struct bio *dio_bio, struct inode *inode,
* atomic operations with a return value are fully ordered as per * atomic operations with a return value are fully ordered as per
* atomic_t.txt * atomic_t.txt
*/ */
if (atomic_dec_and_test(&dip->pending_bios)) if (refcount_dec_and_test(&dip->refs))
bio_io_error(dip->orig_bio); bio_io_error(dip->orig_bio);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment