From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: dsterba@suse.cz, m_btrfs@ml1.co.uk
Subject: [PATCH 7/8] Btrfs: fix btrfs_scratch_superblock() with fixes from device delete
Date: Mon, 27 Apr 2015 15:34:14 +0800 [thread overview]
Message-ID: <1430120055-10381-8-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1430120055-10381-1-git-send-email-anand.jain@oracle.com>
This patch updates the btrfs_scratch_superblock(), (which is used
by the replace device thread), with those fixes from the
scratch superblock code section of btrfs_rm_device(). The fixes are:
Scratch all copies of superblock
Notify kobject that superblock has been changed
Update time on the device
so that btrfs_rm_device() can use the function btrfs_scratch_superblock()
instead of its own scratch code. And further replace deivce code which
similarly releases device back to the system, will have the fixes from
the btrfs device delete.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
fs/btrfs/volumes.c | 40 ++++++++++++++++++++++++++++------------
fs/btrfs/volumes.h | 2 +-
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index e57dd60..4fd7010 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1891,7 +1891,8 @@ void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_fs_info *fs_info,
if (srcdev->writeable) {
fs_devices->rw_devices--;
/* zero out the old super if it is writable */
- btrfs_scratch_superblock(srcdev);
+ btrfs_scratch_superblock(srcdev->bdev,
+ rcu_str_deref(srcdev->name));
}
if (srcdev->bdev)
@@ -1941,7 +1942,8 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
btrfs_sysfs_rm_device_link(fs_info->fs_devices, tgtdev, 0);
if (tgtdev->bdev) {
- btrfs_scratch_superblock(tgtdev);
+ btrfs_scratch_superblock(tgtdev->bdev,
+ rcu_str_deref(tgtdev->name));
fs_info->fs_devices->open_devices--;
}
fs_info->fs_devices->num_devices--;
@@ -6779,22 +6781,36 @@ int btrfs_get_dev_stats(struct btrfs_root *root,
return 0;
}
-int btrfs_scratch_superblock(struct btrfs_device *device)
+void btrfs_scratch_superblock(struct block_device *bdev, char *device_path)
{
struct buffer_head *bh;
struct btrfs_super_block *disk_super;
+ int copy_num;
- bh = btrfs_read_dev_super(device->bdev);
- if (IS_ERR(bh))
- return PTR_ERR(bh);
- disk_super = (struct btrfs_super_block *)bh->b_data;
+ if (!bdev)
+ return;
- memset(&disk_super->magic, 0, sizeof(disk_super->magic));
- set_buffer_dirty(bh);
- sync_dirty_buffer(bh);
- brelse(bh);
+ for (copy_num = 0; copy_num < BTRFS_SUPER_MIRROR_MAX;
+ copy_num++) {
- return 0;
+ if (btrfs_read_dev_one_super(bdev, copy_num, &bh))
+ continue;
+
+ disk_super = (struct btrfs_super_block *)bh->b_data;
+
+ memset(&disk_super->magic, 0, sizeof(disk_super->magic));
+ set_buffer_dirty(bh);
+ sync_dirty_buffer(bh);
+ brelse(bh);
+ }
+
+ /* Notify udev that device has changed */
+ btrfs_kobject_uevent(bdev, KOBJ_CHANGE);
+
+ /* Update ctime/mtime for device path for libblkid */
+ update_dev_time(device_path);
+
+ return;
}
/*
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 027d454..a9e4459 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -487,7 +487,7 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
struct btrfs_device *tgtdev);
void btrfs_init_dev_replace_tgtdev_for_resume(struct btrfs_fs_info *fs_info,
struct btrfs_device *tgtdev);
-int btrfs_scratch_superblock(struct btrfs_device *device);
+void btrfs_scratch_superblock(struct block_device *bdev, char *device_path);
int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
u64 logical, u64 len, int mirror_num);
unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
--
2.0.0.153.g79dcccc
next prev parent reply other threads:[~2015-04-27 7:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-20 10:29 [PATCH] device delete by devid Anand Jain
2015-04-20 10:29 ` [PATCH] Btrfs: " Anand Jain
2015-04-27 7:34 ` [PATCH 0/8 v2] " Anand Jain
2015-04-27 7:34 ` [PATCH V2 1/8] Btrfs: " Anand Jain
2015-04-27 7:34 ` [PATCH 2/8] Btrfs: move check for min number of devices to a function Anand Jain
2015-04-27 7:34 ` [PATCH 3/8] Btrfs: rename btrfs_dev_replace_find_srcdev() Anand Jain
2015-04-27 7:34 ` [PATCH 4/8] Btrfs: use BTRFS_ERROR_DEV_MISSING_NOT_FOUND when missing device is not found Anand Jain
2015-04-27 7:34 ` [PATCH 5/8] Btrfs: use btrfs_find_device_by_user_input() Anand Jain
2015-04-27 7:34 ` [PATCH 6/8] Btrfs: add btrfs_read_dev_one_super() to read one specific SB Anand Jain
2015-04-27 7:34 ` Anand Jain [this message]
2015-04-27 7:34 ` [PATCH 8/8] Btrfs: use btrfs_scratch_superblock() in btrfs_rm_device() Anand Jain
2015-04-20 10:29 ` [PATCH 1/2] btrfs-progs: move is_numerical to utils-lib.h and make it non static Anand Jain
2015-04-20 10:29 ` [PATCH 2/2] btrfs-progs: device delete to accept devid Anand Jain
2015-07-13 2:28 ` [PATCH 2/2 v2] " 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=1430120055-10381-8-git-send-email-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=m_btrfs@ml1.co.uk \
/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).