@@ -27,18 +27,29 @@ struct tree_mod_elem {
27
27
/* This is used for BTRFS_MOD_LOG_KEY* and BTRFS_MOD_LOG_ROOT_REPLACE. */
28
28
u64 generation ;
29
29
30
- /* Those are used for op == BTRFS_MOD_LOG_KEY_{REPLACE,REMOVE}. */
31
- struct btrfs_disk_key key ;
32
- u64 blockptr ;
33
-
34
- /* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */
35
- struct {
36
- int dst_slot ;
37
- int nr_items ;
38
- } move ;
39
-
40
- /* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */
41
- struct tree_mod_root old_root ;
30
+ union {
31
+ /*
32
+ * This is used for the following op types:
33
+ *
34
+ * BTRFS_MOD_LOG_KEY_REMOVE_WHILE_FREEING
35
+ * BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING
36
+ * BTRFS_MOD_LOG_KEY_REMOVE
37
+ * BTRFS_MOD_LOG_KEY_REPLACE
38
+ */
39
+ struct {
40
+ struct btrfs_disk_key key ;
41
+ u64 blockptr ;
42
+ } slot_change ;
43
+
44
+ /* This is used for op == BTRFS_MOD_LOG_MOVE_KEYS. */
45
+ struct {
46
+ int dst_slot ;
47
+ int nr_items ;
48
+ } move ;
49
+
50
+ /* This is used for op == BTRFS_MOD_LOG_ROOT_REPLACE. */
51
+ struct tree_mod_root old_root ;
52
+ };
42
53
};
43
54
44
55
/*
@@ -228,15 +239,17 @@ static struct tree_mod_elem *alloc_tree_mod_elem(const struct extent_buffer *eb,
228
239
{
229
240
struct tree_mod_elem * tm ;
230
241
242
+ /* Can't be one of these types, due to union in struct tree_mod_elem. */
243
+ ASSERT (op != BTRFS_MOD_LOG_MOVE_KEYS );
244
+ ASSERT (op != BTRFS_MOD_LOG_ROOT_REPLACE );
245
+
231
246
tm = kzalloc (sizeof (* tm ), GFP_NOFS );
232
247
if (!tm )
233
248
return NULL ;
234
249
235
250
tm -> logical = eb -> start ;
236
- if (op != BTRFS_MOD_LOG_KEY_ADD ) {
237
- btrfs_node_key (eb , & tm -> key , slot );
238
- tm -> blockptr = btrfs_node_blockptr (eb , slot );
239
- }
251
+ btrfs_node_key (eb , & tm -> slot_change .key , slot );
252
+ tm -> slot_change .blockptr = btrfs_node_blockptr (eb , slot );
240
253
tm -> op = op ;
241
254
tm -> slot = slot ;
242
255
tm -> generation = btrfs_node_ptr_generation (eb , slot );
@@ -854,8 +867,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
854
867
fallthrough ;
855
868
case BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING :
856
869
case BTRFS_MOD_LOG_KEY_REMOVE :
857
- btrfs_set_node_key (eb , & tm -> key , tm -> slot );
858
- btrfs_set_node_blockptr (eb , tm -> slot , tm -> blockptr );
870
+ btrfs_set_node_key (eb , & tm -> slot_change . key , tm -> slot );
871
+ btrfs_set_node_blockptr (eb , tm -> slot , tm -> slot_change . blockptr );
859
872
btrfs_set_node_ptr_generation (eb , tm -> slot ,
860
873
tm -> generation );
861
874
n ++ ;
@@ -864,8 +877,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
864
877
break ;
865
878
case BTRFS_MOD_LOG_KEY_REPLACE :
866
879
BUG_ON (tm -> slot >= n );
867
- btrfs_set_node_key (eb , & tm -> key , tm -> slot );
868
- btrfs_set_node_blockptr (eb , tm -> slot , tm -> blockptr );
880
+ btrfs_set_node_key (eb , & tm -> slot_change . key , tm -> slot );
881
+ btrfs_set_node_blockptr (eb , tm -> slot , tm -> slot_change . blockptr );
869
882
btrfs_set_node_ptr_generation (eb , tm -> slot ,
870
883
tm -> generation );
871
884
break ;
0 commit comments