mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-26 08:02:21 +00:00
1639cc2a51
The status display was reading the state while the task was updating it. Use a mutex to prevent the race. This race was detected using ThreadSanitizer and misc-tests/005-convert-progress-thread-crash. ================== WARNING: ThreadSanitizer: data race Write of size 8 by main thread: #0 ext2_copy_inodes btrfs-progs/convert/source-ext2.c:853 #1 copy_inodes btrfs-progs/convert/main.c:145 #2 do_convert btrfs-progs/convert/main.c:1297 #3 main btrfs-progs/convert/main.c:1924 Previous read of size 8 by thread T1: #0 print_copied_inodes btrfs-progs/convert/main.c:124 Location is stack of main thread. Thread T1 (running) created by main thread at: #0 pthread_create <null> #1 task_start btrfs-progs/task-utils.c:50 #2 do_convert btrfs-progs/convert/main.c:1295 #3 main btrfs-progs/convert/main.c:1924 SUMMARY: ThreadSanitizer: data race btrfs-progs/convert/source-ext2.c:853 in ext2_copy_inodes Signed-off-by: Adam Buchbinder <abuchbinder@google.com> Signed-off-by: David Sterba <dsterba@suse.com>
119 lines
3.3 KiB
C
119 lines
3.3 KiB
C
/*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public
|
|
* License v2 as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public
|
|
* License along with this program; if not, write to the
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
* Boston, MA 021110-1307, USA.
|
|
*/
|
|
|
|
#ifndef __BTRFS_CONVERT_SOURCE_FS_H__
|
|
#define __BTRFS_CONVERT_SOURCE_FS_H__
|
|
|
|
#include "kerncompat.h"
|
|
#include <pthread.h>
|
|
|
|
|
|
#define CONV_IMAGE_SUBVOL_OBJECTID BTRFS_FIRST_FREE_OBJECTID
|
|
|
|
/*
|
|
* Reresents a simple contiguous range.
|
|
*
|
|
* For multiple or non-contiguous ranges, use extent_cache_tree from
|
|
* extent-cache.c
|
|
*/
|
|
struct simple_range {
|
|
u64 start;
|
|
u64 len;
|
|
};
|
|
|
|
extern const struct simple_range btrfs_reserved_ranges[3];
|
|
|
|
struct task_info;
|
|
|
|
struct task_ctx {
|
|
pthread_mutex_t mutex;
|
|
u64 max_copy_inodes;
|
|
u64 cur_copy_inodes;
|
|
struct task_info *info;
|
|
};
|
|
|
|
struct btrfs_convert_context;
|
|
|
|
#define SOURCE_FS_NAME_LEN (16)
|
|
|
|
#define CONVERT_FLAG_DATACSUM (1U << 0)
|
|
#define CONVERT_FLAG_INLINE_DATA (1U << 1)
|
|
#define CONVERT_FLAG_XATTR (1U << 2)
|
|
#define CONVERT_FLAG_COPY_LABEL (1U << 3)
|
|
#define CONVERT_FLAG_SET_LABEL (1U << 4)
|
|
|
|
struct btrfs_convert_operations {
|
|
const char name[SOURCE_FS_NAME_LEN];
|
|
int (*open_fs)(struct btrfs_convert_context *cctx, const char *devname);
|
|
int (*read_used_space)(struct btrfs_convert_context *cctx);
|
|
int (*copy_inodes)(struct btrfs_convert_context *cctx,
|
|
struct btrfs_root *root, u32 covert_flags,
|
|
struct task_ctx *p);
|
|
void (*close_fs)(struct btrfs_convert_context *cctx);
|
|
int (*check_state)(struct btrfs_convert_context *cctx);
|
|
};
|
|
|
|
struct btrfs_trans_handle;
|
|
struct btrfs_root;
|
|
struct btrfs_inode_item;
|
|
|
|
struct blk_iterate_data {
|
|
struct btrfs_trans_handle *trans;
|
|
struct btrfs_root *root;
|
|
struct btrfs_root *convert_root;
|
|
struct btrfs_inode_item *inode;
|
|
u64 convert_ino;
|
|
u64 objectid;
|
|
u64 first_block;
|
|
u64 disk_block;
|
|
u64 num_blocks;
|
|
u64 boundary;
|
|
int checksum;
|
|
int errcode;
|
|
};
|
|
|
|
void init_convert_context(struct btrfs_convert_context *cctx);
|
|
void clean_convert_context(struct btrfs_convert_context *cctx);
|
|
int block_iterate_proc(u64 disk_block, u64 file_block,
|
|
struct blk_iterate_data *idata);
|
|
void init_blk_iterate_data(struct blk_iterate_data *data,
|
|
struct btrfs_trans_handle *trans,
|
|
struct btrfs_root *root,
|
|
struct btrfs_inode_item *inode,
|
|
u64 objectid, int checksum);
|
|
int convert_insert_dirent(struct btrfs_trans_handle *trans,
|
|
struct btrfs_root *root,
|
|
const char *name, size_t name_len,
|
|
u64 dir, u64 objectid,
|
|
u8 file_type, u64 index_cnt,
|
|
struct btrfs_inode_item *inode);
|
|
int read_disk_extent(struct btrfs_root *root, u64 bytenr,
|
|
u32 num_bytes, char *buffer);
|
|
int record_file_blocks(struct blk_iterate_data *data,
|
|
u64 file_block, u64 disk_block, u64 num_blocks);
|
|
|
|
/*
|
|
* Simple range functions
|
|
*
|
|
* Get range end (exclusive)
|
|
*/
|
|
static inline u64 range_end(const struct simple_range *range)
|
|
{
|
|
return (range->start + range->len);
|
|
}
|
|
|
|
#endif
|