diff options
author | Qu Wenruo <quwenruo@cn.fujitsu.com> | 2014-04-16 05:02:32 -0400 |
---|---|---|
committer | Chris Mason <clm@fb.com> | 2014-06-09 20:20:33 -0400 |
commit | 5a1972bd9fd4b2fb1bac8b7a0b636d633d8717e3 (patch) | |
tree | 93944f37e34a5669ebcf2e5fab5c05a9ad887c3a /fs/btrfs/volumes.c | |
parent | 61155aa04ebcba6a33f2a281c46f351ca150d816 (diff) |
btrfs: Add ctime/mtime update for btrfs device add/remove.
Btrfs will send uevent to udev inform the device change,
but ctime/mtime for the block device inode is not udpated, which cause
libblkid used by btrfs-progs unable to detect device change and use old
cache, causing 'btrfs dev scan; btrfs dev rmove; btrfs dev scan' give an
error message.
Reported-by: Tsutomu Itoh <t-itoh@jp.fujitsu.com>
Cc: Karel Zak <kzak@redhat.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r-- | fs/btrfs/volumes.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 3b761a456acd..ad8e342c4b78 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c | |||
@@ -1452,6 +1452,22 @@ out: | |||
1452 | return ret; | 1452 | return ret; |
1453 | } | 1453 | } |
1454 | 1454 | ||
1455 | /* | ||
1456 | * Function to update ctime/mtime for a given device path. | ||
1457 | * Mainly used for ctime/mtime based probe like libblkid. | ||
1458 | */ | ||
1459 | static void update_dev_time(char *path_name) | ||
1460 | { | ||
1461 | struct file *filp; | ||
1462 | |||
1463 | filp = filp_open(path_name, O_RDWR, 0); | ||
1464 | if (!filp) | ||
1465 | return; | ||
1466 | file_update_time(filp); | ||
1467 | filp_close(filp, NULL); | ||
1468 | return; | ||
1469 | } | ||
1470 | |||
1455 | static int btrfs_rm_dev_item(struct btrfs_root *root, | 1471 | static int btrfs_rm_dev_item(struct btrfs_root *root, |
1456 | struct btrfs_device *device) | 1472 | struct btrfs_device *device) |
1457 | { | 1473 | { |
@@ -1704,10 +1720,14 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) | |||
1704 | 1720 | ||
1705 | ret = 0; | 1721 | ret = 0; |
1706 | 1722 | ||
1707 | /* Notify udev that device has changed */ | 1723 | if (bdev) { |
1708 | if (bdev) | 1724 | /* Notify udev that device has changed */ |
1709 | btrfs_kobject_uevent(bdev, KOBJ_CHANGE); | 1725 | btrfs_kobject_uevent(bdev, KOBJ_CHANGE); |
1710 | 1726 | ||
1727 | /* Update ctime/mtime for device path for libblkid */ | ||
1728 | update_dev_time(device_path); | ||
1729 | } | ||
1730 | |||
1711 | error_brelse: | 1731 | error_brelse: |
1712 | brelse(bh); | 1732 | brelse(bh); |
1713 | if (bdev) | 1733 | if (bdev) |
@@ -2146,6 +2166,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) | |||
2146 | ret = btrfs_commit_transaction(trans, root); | 2166 | ret = btrfs_commit_transaction(trans, root); |
2147 | } | 2167 | } |
2148 | 2168 | ||
2169 | /* Update ctime/mtime for libblkid */ | ||
2170 | update_dev_time(device_path); | ||
2149 | return ret; | 2171 | return ret; |
2150 | 2172 | ||
2151 | error_trans: | 2173 | error_trans: |