@@ -3000,7 +3000,7 @@ int open_ctree(struct super_block *sb,
* write-ahead log, the fsync'd data will never ends
* up with being replayed by raid56 log.
*/
- btrfs_r5l_load_log(fs_info, cp);
+ btrfs_r5l_load_log(fs_info, NULL, cp);
}
ret = btrfs_recover_balance(fs_info);
@@ -1943,14 +1943,28 @@ static int btrfs_r5l_recover_log(struct btrfs_r5l_log *log)
}
/* return 0 if success, otherwise return errors */
-int btrfs_r5l_load_log(struct btrfs_fs_info *fs_info, u64 cp)
+int btrfs_r5l_load_log(struct btrfs_fs_info *fs_info, struct btrfs_r5l_log *r5log, u64 cp)
{
- struct btrfs_r5l_log *log = fs_info->r5log;
+ struct btrfs_r5l_log *log;
struct page *page;
struct btrfs_r5l_meta_block *mb;
bool create_new = false;
int ret;
+ if (r5log)
+ ASSERT(fs_info->r5log == NULL);
+ if (fs_info->r5log)
+ ASSERT(r5log == NULL);
+
+ if (fs_info->r5log)
+ log = fs_info->r5log;
+ else
+ /*
+ * this only happens when adding the raid56 log for
+ * the first time.
+ */
+ log = r5log;
+
ASSERT(log);
page = alloc_page(GFP_NOFS | __GFP_HIGHMEM);
@@ -140,5 +140,6 @@ struct btrfs_r5l_log * btrfs_r5l_init_log_prepare(struct btrfs_fs_info *fs_info,
void btrfs_r5l_init_log_post(struct btrfs_fs_info *fs_info,
struct btrfs_r5l_log *log);
int btrfs_set_r5log(struct btrfs_fs_info *fs_info, struct btrfs_device *device);
-int btrfs_r5l_load_log(struct btrfs_fs_info *fs_info, u64 cp);
+int btrfs_r5l_load_log(struct btrfs_fs_info *fs_info,
+ struct btrfs_r5l_log *r5log, u64 cp);
#endif
@@ -2521,6 +2521,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
}
if (is_r5log) {
+ /* initialize r5log with cp == 0. */
+ btrfs_r5l_load_log(fs_info, r5log, 0);
btrfs_r5l_init_log_post(fs_info, r5log);
}
We need to initialize the raid5/6 log after adding it, but we don't want to race with concurrent writes. So we initialize it before assigning the log pointer in %fs_info. Signed-off-by: Liu Bo <bo.li.liu@oracle.com> --- fs/btrfs/disk-io.c | 2 +- fs/btrfs/raid56.c | 18 ++++++++++++++++-- fs/btrfs/raid56.h | 3 ++- fs/btrfs/volumes.c | 2 ++ 4 files changed, 21 insertions(+), 4 deletions(-)