4
4
5
5
#include <linux/bug.h>
6
6
#include "bcachefs_format.h"
7
-
7
+ #include "bkey_types.h"
8
8
#include "btree_types.h"
9
9
#include "util.h"
10
10
#include "vstructs.h"
@@ -31,57 +31,6 @@ void bch2_bkey_packed_to_binary_text(struct printbuf *,
31
31
const struct bkey_format * ,
32
32
const struct bkey_packed * );
33
33
34
- /* bkey with split value, const */
35
- struct bkey_s_c {
36
- const struct bkey * k ;
37
- const struct bch_val * v ;
38
- };
39
-
40
- /* bkey with split value */
41
- struct bkey_s {
42
- union {
43
- struct {
44
- struct bkey * k ;
45
- struct bch_val * v ;
46
- };
47
- struct bkey_s_c s_c ;
48
- };
49
- };
50
-
51
- #define bkey_p_next (_k ) vstruct_next(_k)
52
-
53
- static inline struct bkey_i * bkey_next (struct bkey_i * k )
54
- {
55
- return (struct bkey_i * ) ((u64 * ) k -> _data + k -> k .u64s );
56
- }
57
-
58
- #define bkey_val_u64s (_k ) ((_k)->u64s - BKEY_U64s)
59
-
60
- static inline size_t bkey_val_bytes (const struct bkey * k )
61
- {
62
- return bkey_val_u64s (k ) * sizeof (u64 );
63
- }
64
-
65
- static inline void set_bkey_val_u64s (struct bkey * k , unsigned val_u64s )
66
- {
67
- unsigned u64s = BKEY_U64s + val_u64s ;
68
-
69
- BUG_ON (u64s > U8_MAX );
70
- k -> u64s = u64s ;
71
- }
72
-
73
- static inline void set_bkey_val_bytes (struct bkey * k , unsigned bytes )
74
- {
75
- set_bkey_val_u64s (k , DIV_ROUND_UP (bytes , sizeof (u64 )));
76
- }
77
-
78
- #define bkey_val_end (_k ) ((void *) (((u64 *) (_k).v) + bkey_val_u64s((_k).k)))
79
-
80
- #define bkey_deleted (_k ) ((_k)->type == KEY_TYPE_deleted)
81
-
82
- #define bkey_whiteout (_k ) \
83
- ((_k)->type == KEY_TYPE_deleted || (_k)->type == KEY_TYPE_whiteout)
84
-
85
34
enum bkey_lr_packed {
86
35
BKEY_PACKED_BOTH ,
87
36
BKEY_PACKED_RIGHT ,
@@ -550,155 +499,6 @@ static inline void bkey_reassemble(struct bkey_i *dst,
550
499
memcpy_u64s_small (& dst -> v , src .v , bkey_val_u64s (src .k ));
551
500
}
552
501
553
- #define bkey_s_null ((struct bkey_s) { .k = NULL })
554
- #define bkey_s_c_null ((struct bkey_s_c) { .k = NULL })
555
-
556
- #define bkey_s_err (err ) ((struct bkey_s) { .k = ERR_PTR(err) })
557
- #define bkey_s_c_err (err ) ((struct bkey_s_c) { .k = ERR_PTR(err) })
558
-
559
- static inline struct bkey_s bkey_to_s (struct bkey * k )
560
- {
561
- return (struct bkey_s ) { .k = k , .v = NULL };
562
- }
563
-
564
- static inline struct bkey_s_c bkey_to_s_c (const struct bkey * k )
565
- {
566
- return (struct bkey_s_c ) { .k = k , .v = NULL };
567
- }
568
-
569
- static inline struct bkey_s bkey_i_to_s (struct bkey_i * k )
570
- {
571
- return (struct bkey_s ) { .k = & k -> k , .v = & k -> v };
572
- }
573
-
574
- static inline struct bkey_s_c bkey_i_to_s_c (const struct bkey_i * k )
575
- {
576
- return (struct bkey_s_c ) { .k = & k -> k , .v = & k -> v };
577
- }
578
-
579
- /*
580
- * For a given type of value (e.g. struct bch_extent), generates the types for
581
- * bkey + bch_extent - inline, split, split const - and also all the conversion
582
- * functions, which also check that the value is of the correct type.
583
- *
584
- * We use anonymous unions for upcasting - e.g. converting from e.g. a
585
- * bkey_i_extent to a bkey_i - since that's always safe, instead of conversion
586
- * functions.
587
- */
588
- #define x (name , ...) \
589
- struct bkey_i_##name { \
590
- union { \
591
- struct bkey k; \
592
- struct bkey_i k_i; \
593
- }; \
594
- struct bch_##name v; \
595
- }; \
596
- \
597
- struct bkey_s_c_##name { \
598
- union { \
599
- struct { \
600
- const struct bkey *k; \
601
- const struct bch_##name *v; \
602
- }; \
603
- struct bkey_s_c s_c; \
604
- }; \
605
- }; \
606
- \
607
- struct bkey_s_##name { \
608
- union { \
609
- struct { \
610
- struct bkey *k; \
611
- struct bch_##name *v; \
612
- }; \
613
- struct bkey_s_c_##name c; \
614
- struct bkey_s s; \
615
- struct bkey_s_c s_c; \
616
- }; \
617
- }; \
618
- \
619
- static inline struct bkey_i_##name *bkey_i_to_##name(struct bkey_i *k) \
620
- { \
621
- EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name); \
622
- return container_of(&k->k, struct bkey_i_##name, k); \
623
- } \
624
- \
625
- static inline const struct bkey_i_##name * \
626
- bkey_i_to_##name##_c(const struct bkey_i *k) \
627
- { \
628
- EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name); \
629
- return container_of(&k->k, struct bkey_i_##name, k); \
630
- } \
631
- \
632
- static inline struct bkey_s_##name bkey_s_to_##name(struct bkey_s k) \
633
- { \
634
- EBUG_ON(!IS_ERR_OR_NULL(k.k) && k.k->type != KEY_TYPE_##name); \
635
- return (struct bkey_s_##name) { \
636
- .k = k.k, \
637
- .v = container_of(k.v, struct bch_##name, v), \
638
- }; \
639
- } \
640
- \
641
- static inline struct bkey_s_c_##name bkey_s_c_to_##name(struct bkey_s_c k)\
642
- { \
643
- EBUG_ON(!IS_ERR_OR_NULL(k.k) && k.k->type != KEY_TYPE_##name); \
644
- return (struct bkey_s_c_##name) { \
645
- .k = k.k, \
646
- .v = container_of(k.v, struct bch_##name, v), \
647
- }; \
648
- } \
649
- \
650
- static inline struct bkey_s_##name name##_i_to_s(struct bkey_i_##name *k)\
651
- { \
652
- return (struct bkey_s_##name) { \
653
- .k = &k->k, \
654
- .v = &k->v, \
655
- }; \
656
- } \
657
- \
658
- static inline struct bkey_s_c_##name \
659
- name##_i_to_s_c(const struct bkey_i_##name *k) \
660
- { \
661
- return (struct bkey_s_c_##name) { \
662
- .k = &k->k, \
663
- .v = &k->v, \
664
- }; \
665
- } \
666
- \
667
- static inline struct bkey_s_##name bkey_i_to_s_##name(struct bkey_i *k) \
668
- { \
669
- EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name); \
670
- return (struct bkey_s_##name) { \
671
- .k = &k->k, \
672
- .v = container_of(&k->v, struct bch_##name, v), \
673
- }; \
674
- } \
675
- \
676
- static inline struct bkey_s_c_##name \
677
- bkey_i_to_s_c_##name(const struct bkey_i *k) \
678
- { \
679
- EBUG_ON(!IS_ERR_OR_NULL(k) && k->k.type != KEY_TYPE_##name); \
680
- return (struct bkey_s_c_##name) { \
681
- .k = &k->k, \
682
- .v = container_of(&k->v, struct bch_##name, v), \
683
- }; \
684
- } \
685
- \
686
- static inline struct bkey_i_##name *bkey_##name##_init(struct bkey_i *_k)\
687
- { \
688
- struct bkey_i_##name *k = \
689
- container_of(&_k->k, struct bkey_i_##name, k); \
690
- \
691
- bkey_init(&k->k); \
692
- memset(&k->v, 0, sizeof(k->v)); \
693
- k->k.type = KEY_TYPE_##name; \
694
- set_bkey_val_bytes(&k->k, sizeof(k->v)); \
695
- \
696
- return k; \
697
- }
698
-
699
- BCH_BKEY_TYPES ();
700
- #undef x
701
-
702
502
/* byte order helpers */
703
503
704
504
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
0 commit comments