@@ -147,12 +147,18 @@ void bch2_stripe_to_text(struct printbuf *out, struct bch_fs *c,
147
147
bch2_prt_csum_type (out , s .csum_type );
148
148
prt_printf (out , " gran %u" , 1U << s .csum_granularity_bits );
149
149
150
+ if (s .disk_label ) {
151
+ prt_str (out , " label" );
152
+ bch2_disk_path_to_text (out , c , s .disk_label - 1 );
153
+ }
154
+
150
155
for (unsigned i = 0 ; i < s .nr_blocks ; i ++ ) {
151
156
const struct bch_extent_ptr * ptr = sp -> ptrs + i ;
152
157
153
158
if ((void * ) ptr >= bkey_val_end (k ))
154
159
break ;
155
160
161
+ prt_char (out , ' ' );
156
162
bch2_extent_ptr_to_text (out , c , ptr );
157
163
158
164
if (s .csum_type < BCH_CSUM_NR &&
@@ -358,6 +364,7 @@ static inline void stripe_to_mem(struct stripe *m, const struct bch_stripe *s)
358
364
m -> algorithm = s -> algorithm ;
359
365
m -> nr_blocks = s -> nr_blocks ;
360
366
m -> nr_redundant = s -> nr_redundant ;
367
+ m -> disk_label = s -> disk_label ;
361
368
m -> blocks_nonempty = 0 ;
362
369
363
370
for (unsigned i = 0 ; i < s -> nr_blocks ; i ++ )
@@ -1647,7 +1654,8 @@ static void ec_stripe_key_init(struct bch_fs *c,
1647
1654
struct bkey_i * k ,
1648
1655
unsigned nr_data ,
1649
1656
unsigned nr_parity ,
1650
- unsigned stripe_size )
1657
+ unsigned stripe_size ,
1658
+ unsigned disk_label )
1651
1659
{
1652
1660
struct bkey_i_stripe * s = bkey_stripe_init (k );
1653
1661
unsigned u64s ;
@@ -1658,7 +1666,7 @@ static void ec_stripe_key_init(struct bch_fs *c,
1658
1666
s -> v .nr_redundant = nr_parity ;
1659
1667
s -> v .csum_granularity_bits = ilog2 (c -> opts .encoded_extent_max >> 9 );
1660
1668
s -> v .csum_type = BCH_CSUM_crc32c ;
1661
- s -> v .pad = 0 ;
1669
+ s -> v .disk_label = disk_label ;
1662
1670
1663
1671
while ((u64s = stripe_val_u64s (& s -> v )) > BKEY_VAL_U64s_MAX ) {
1664
1672
BUG_ON (1 << s -> v .csum_granularity_bits >=
@@ -1691,14 +1699,15 @@ static int ec_new_stripe_alloc(struct bch_fs *c, struct ec_stripe_head *h)
1691
1699
s -> nr_parity = h -> redundancy ;
1692
1700
1693
1701
ec_stripe_key_init (c , & s -> new_stripe .key ,
1694
- s -> nr_data , s -> nr_parity , h -> blocksize );
1702
+ s -> nr_data , s -> nr_parity ,
1703
+ h -> blocksize , h -> disk_label );
1695
1704
1696
1705
h -> s = s ;
1697
1706
return 0 ;
1698
1707
}
1699
1708
1700
1709
static struct ec_stripe_head *
1701
- ec_new_stripe_head_alloc (struct bch_fs * c , unsigned target ,
1710
+ ec_new_stripe_head_alloc (struct bch_fs * c , unsigned disk_label ,
1702
1711
unsigned algo , unsigned redundancy ,
1703
1712
enum bch_watermark watermark )
1704
1713
{
@@ -1711,13 +1720,13 @@ ec_new_stripe_head_alloc(struct bch_fs *c, unsigned target,
1711
1720
mutex_init (& h -> lock );
1712
1721
BUG_ON (!mutex_trylock (& h -> lock ));
1713
1722
1714
- h -> target = target ;
1723
+ h -> disk_label = disk_label ;
1715
1724
h -> algo = algo ;
1716
1725
h -> redundancy = redundancy ;
1717
1726
h -> watermark = watermark ;
1718
1727
1719
1728
rcu_read_lock ();
1720
- h -> devs = target_rw_devs (c , BCH_DATA_user , target );
1729
+ h -> devs = target_rw_devs (c , BCH_DATA_user , disk_label ? group_to_target ( disk_label - 1 ) : 0 );
1721
1730
1722
1731
for_each_member_device_rcu (c , ca , & h -> devs )
1723
1732
if (!ca -> mi .durability )
@@ -1756,7 +1765,7 @@ void bch2_ec_stripe_head_put(struct bch_fs *c, struct ec_stripe_head *h)
1756
1765
1757
1766
static struct ec_stripe_head *
1758
1767
__bch2_ec_stripe_head_get (struct btree_trans * trans ,
1759
- unsigned target ,
1768
+ unsigned disk_label ,
1760
1769
unsigned algo ,
1761
1770
unsigned redundancy ,
1762
1771
enum bch_watermark watermark )
@@ -1778,7 +1787,7 @@ __bch2_ec_stripe_head_get(struct btree_trans *trans,
1778
1787
}
1779
1788
1780
1789
list_for_each_entry (h , & c -> ec_stripe_head_list , list )
1781
- if (h -> target == target &&
1790
+ if (h -> disk_label == disk_label &&
1782
1791
h -> algo == algo &&
1783
1792
h -> redundancy == redundancy &&
1784
1793
h -> watermark == watermark ) {
@@ -1788,7 +1797,7 @@ __bch2_ec_stripe_head_get(struct btree_trans *trans,
1788
1797
goto found ;
1789
1798
}
1790
1799
1791
- h = ec_new_stripe_head_alloc (c , target , algo , redundancy , watermark );
1800
+ h = ec_new_stripe_head_alloc (c , disk_label , algo , redundancy , watermark );
1792
1801
found :
1793
1802
if (!IS_ERR_OR_NULL (h ) &&
1794
1803
h -> nr_active_devs < h -> redundancy + 2 ) {
@@ -1884,7 +1893,6 @@ static int new_stripe_alloc_buckets(struct btree_trans *trans, struct ec_stripe_
1884
1893
return 0 ;
1885
1894
}
1886
1895
1887
- /* XXX: doesn't obey target: */
1888
1896
static s64 get_existing_stripe (struct bch_fs * c ,
1889
1897
struct ec_stripe_head * head )
1890
1898
{
@@ -1907,7 +1915,8 @@ static s64 get_existing_stripe(struct bch_fs *c,
1907
1915
1908
1916
m = genradix_ptr (& c -> stripes , stripe_idx );
1909
1917
1910
- if (m -> algorithm == head -> algo &&
1918
+ if (m -> disk_label == head -> disk_label &&
1919
+ m -> algorithm == head -> algo &&
1911
1920
m -> nr_redundant == head -> redundancy &&
1912
1921
m -> sectors == head -> blocksize &&
1913
1922
m -> blocks_nonempty < m -> nr_blocks - m -> nr_redundant &&
@@ -2052,9 +2061,19 @@ struct ec_stripe_head *bch2_ec_stripe_head_get(struct btree_trans *trans,
2052
2061
struct bch_fs * c = trans -> c ;
2053
2062
struct ec_stripe_head * h ;
2054
2063
bool waiting = false;
2064
+ unsigned disk_label = 0 ;
2065
+ struct target t = target_decode (target );
2055
2066
int ret ;
2056
2067
2057
- h = __bch2_ec_stripe_head_get (trans , target , algo , redundancy , watermark );
2068
+ if (t .type == TARGET_GROUP ) {
2069
+ if (t .group > U8_MAX ) {
2070
+ bch_err (c , "cannot create a stripe when disk_label > U8_MAX" );
2071
+ return NULL ;
2072
+ }
2073
+ disk_label = t .group + 1 ; /* 0 == no label */
2074
+ }
2075
+
2076
+ h = __bch2_ec_stripe_head_get (trans , disk_label , algo , redundancy , watermark );
2058
2077
if (IS_ERR_OR_NULL (h ))
2059
2078
return h ;
2060
2079
@@ -2259,8 +2278,8 @@ void bch2_new_stripes_to_text(struct printbuf *out, struct bch_fs *c)
2259
2278
2260
2279
mutex_lock (& c -> ec_stripe_head_lock );
2261
2280
list_for_each_entry (h , & c -> ec_stripe_head_list , list ) {
2262
- prt_printf (out , "target %u algo %u redundancy %u %s:\n" ,
2263
- h -> target , h -> algo , h -> redundancy ,
2281
+ prt_printf (out , "disk label %u algo %u redundancy %u %s:\n" ,
2282
+ h -> disk_label , h -> algo , h -> redundancy ,
2264
2283
bch2_watermarks [h -> watermark ]);
2265
2284
2266
2285
if (h -> s )
0 commit comments