~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/bcachefs/journal_sb.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/bcachefs/journal_sb.c (Version linux-6.11-rc3) and /fs/bcachefs/journal_sb.c (Version linux-6.7.12)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 #include "bcachefs.h"                               3 #include "bcachefs.h"
  4 #include "journal_sb.h"                             4 #include "journal_sb.h"
  5 #include "darray.h"                                 5 #include "darray.h"
  6                                                     6 
  7 #include <linux/sort.h>                             7 #include <linux/sort.h>
  8                                                     8 
  9 /* BCH_SB_FIELD_journal: */                         9 /* BCH_SB_FIELD_journal: */
 10                                                    10 
 11 static int u64_cmp(const void *_l, const void      11 static int u64_cmp(const void *_l, const void *_r)
 12 {                                                  12 {
 13         const u64 *l = _l;                         13         const u64 *l = _l;
 14         const u64 *r = _r;                         14         const u64 *r = _r;
 15                                                    15 
 16         return cmp_int(*l, *r);                    16         return cmp_int(*l, *r);
 17 }                                                  17 }
 18                                                    18 
 19 static int bch2_sb_journal_validate(struct bch !!  19 static int bch2_sb_journal_validate(struct bch_sb *sb,
 20                                 enum bch_valid !!  20                                     struct bch_sb_field *f,
                                                   >>  21                                     struct printbuf *err)
 21 {                                                  22 {
 22         struct bch_sb_field_journal *journal =     23         struct bch_sb_field_journal *journal = field_to_type(f, journal);
 23         struct bch_member m = bch2_sb_member_g     24         struct bch_member m = bch2_sb_member_get(sb, sb->dev_idx);
 24         int ret = -BCH_ERR_invalid_sb_journal;     25         int ret = -BCH_ERR_invalid_sb_journal;
 25         unsigned nr;                               26         unsigned nr;
 26         unsigned i;                                27         unsigned i;
 27         u64 *b;                                    28         u64 *b;
 28                                                    29 
 29         nr = bch2_nr_journal_buckets(journal);     30         nr = bch2_nr_journal_buckets(journal);
 30         if (!nr)                                   31         if (!nr)
 31                 return 0;                          32                 return 0;
 32                                                    33 
 33         b = kmalloc_array(nr, sizeof(u64), GFP     34         b = kmalloc_array(nr, sizeof(u64), GFP_KERNEL);
 34         if (!b)                                    35         if (!b)
 35                 return -BCH_ERR_ENOMEM_sb_jour     36                 return -BCH_ERR_ENOMEM_sb_journal_validate;
 36                                                    37 
 37         for (i = 0; i < nr; i++)                   38         for (i = 0; i < nr; i++)
 38                 b[i] = le64_to_cpu(journal->bu     39                 b[i] = le64_to_cpu(journal->buckets[i]);
 39                                                    40 
 40         sort(b, nr, sizeof(u64), u64_cmp, NULL     41         sort(b, nr, sizeof(u64), u64_cmp, NULL);
 41                                                    42 
 42         if (!b[0]) {                               43         if (!b[0]) {
 43                 prt_printf(err, "journal bucke     44                 prt_printf(err, "journal bucket at sector 0");
 44                 goto err;                          45                 goto err;
 45         }                                          46         }
 46                                                    47 
 47         if (b[0] < le16_to_cpu(m.first_bucket)     48         if (b[0] < le16_to_cpu(m.first_bucket)) {
 48                 prt_printf(err, "journal bucke     49                 prt_printf(err, "journal bucket %llu before first bucket %u",
 49                        b[0], le16_to_cpu(m.fir     50                        b[0], le16_to_cpu(m.first_bucket));
 50                 goto err;                          51                 goto err;
 51         }                                          52         }
 52                                                    53 
 53         if (b[nr - 1] >= le64_to_cpu(m.nbucket     54         if (b[nr - 1] >= le64_to_cpu(m.nbuckets)) {
 54                 prt_printf(err, "journal bucke     55                 prt_printf(err, "journal bucket %llu past end of device (nbuckets %llu)",
 55                        b[nr - 1], le64_to_cpu(     56                        b[nr - 1], le64_to_cpu(m.nbuckets));
 56                 goto err;                          57                 goto err;
 57         }                                          58         }
 58                                                    59 
 59         for (i = 0; i + 1 < nr; i++)               60         for (i = 0; i + 1 < nr; i++)
 60                 if (b[i] == b[i + 1]) {            61                 if (b[i] == b[i + 1]) {
 61                         prt_printf(err, "dupli     62                         prt_printf(err, "duplicate journal buckets %llu", b[i]);
 62                         goto err;                  63                         goto err;
 63                 }                                  64                 }
 64                                                    65 
 65         ret = 0;                                   66         ret = 0;
 66 err:                                               67 err:
 67         kfree(b);                                  68         kfree(b);
 68         return ret;                                69         return ret;
 69 }                                                  70 }
 70                                                    71 
 71 static void bch2_sb_journal_to_text(struct pri     72 static void bch2_sb_journal_to_text(struct printbuf *out, struct bch_sb *sb,
 72                                     struct bch     73                                     struct bch_sb_field *f)
 73 {                                                  74 {
 74         struct bch_sb_field_journal *journal =     75         struct bch_sb_field_journal *journal = field_to_type(f, journal);
 75         unsigned i, nr = bch2_nr_journal_bucke     76         unsigned i, nr = bch2_nr_journal_buckets(journal);
 76                                                    77 
 77         prt_printf(out, "Buckets: ");              78         prt_printf(out, "Buckets: ");
 78         for (i = 0; i < nr; i++)                   79         for (i = 0; i < nr; i++)
 79                 prt_printf(out, " %llu", le64_     80                 prt_printf(out, " %llu", le64_to_cpu(journal->buckets[i]));
 80         prt_newline(out);                          81         prt_newline(out);
 81 }                                                  82 }
 82                                                    83 
 83 const struct bch_sb_field_ops bch_sb_field_ops     84 const struct bch_sb_field_ops bch_sb_field_ops_journal = {
 84         .validate       = bch2_sb_journal_vali     85         .validate       = bch2_sb_journal_validate,
 85         .to_text        = bch2_sb_journal_to_t     86         .to_text        = bch2_sb_journal_to_text,
 86 };                                                 87 };
 87                                                    88 
 88 struct u64_range {                                 89 struct u64_range {
 89         u64     start;                             90         u64     start;
 90         u64     end;                               91         u64     end;
 91 };                                                 92 };
 92                                                    93 
 93 static int u64_range_cmp(const void *_l, const     94 static int u64_range_cmp(const void *_l, const void *_r)
 94 {                                                  95 {
 95         const struct u64_range *l = _l;            96         const struct u64_range *l = _l;
 96         const struct u64_range *r = _r;            97         const struct u64_range *r = _r;
 97                                                    98 
 98         return cmp_int(l->start, r->start);        99         return cmp_int(l->start, r->start);
 99 }                                                 100 }
100                                                   101 
101 static int bch2_sb_journal_v2_validate(struct  !! 102 static int bch2_sb_journal_v2_validate(struct bch_sb *sb,
102                                 enum bch_valid !! 103                                     struct bch_sb_field *f,
                                                   >> 104                                     struct printbuf *err)
103 {                                                 105 {
104         struct bch_sb_field_journal_v2 *journa    106         struct bch_sb_field_journal_v2 *journal = field_to_type(f, journal_v2);
105         struct bch_member m = bch2_sb_member_g    107         struct bch_member m = bch2_sb_member_get(sb, sb->dev_idx);
106         int ret = -BCH_ERR_invalid_sb_journal;    108         int ret = -BCH_ERR_invalid_sb_journal;
107         unsigned nr;                              109         unsigned nr;
108         unsigned i;                               110         unsigned i;
109         struct u64_range *b;                      111         struct u64_range *b;
110                                                   112 
111         nr = bch2_sb_field_journal_v2_nr_entri    113         nr = bch2_sb_field_journal_v2_nr_entries(journal);
112         if (!nr)                                  114         if (!nr)
113                 return 0;                         115                 return 0;
114                                                   116 
115         b = kmalloc_array(nr, sizeof(*b), GFP_    117         b = kmalloc_array(nr, sizeof(*b), GFP_KERNEL);
116         if (!b)                                   118         if (!b)
117                 return -BCH_ERR_ENOMEM_sb_jour    119                 return -BCH_ERR_ENOMEM_sb_journal_v2_validate;
118                                                   120 
119         for (i = 0; i < nr; i++) {                121         for (i = 0; i < nr; i++) {
120                 b[i].start = le64_to_cpu(journ    122                 b[i].start = le64_to_cpu(journal->d[i].start);
121                 b[i].end = b[i].start + le64_t    123                 b[i].end = b[i].start + le64_to_cpu(journal->d[i].nr);
122         }                                         124         }
123                                                   125 
124         sort(b, nr, sizeof(*b), u64_range_cmp,    126         sort(b, nr, sizeof(*b), u64_range_cmp, NULL);
125                                                   127 
126         if (!b[0].start) {                        128         if (!b[0].start) {
127                 prt_printf(err, "journal bucke    129                 prt_printf(err, "journal bucket at sector 0");
128                 goto err;                         130                 goto err;
129         }                                         131         }
130                                                   132 
131         if (b[0].start < le16_to_cpu(m.first_b    133         if (b[0].start < le16_to_cpu(m.first_bucket)) {
132                 prt_printf(err, "journal bucke    134                 prt_printf(err, "journal bucket %llu before first bucket %u",
133                        b[0].start, le16_to_cpu    135                        b[0].start, le16_to_cpu(m.first_bucket));
134                 goto err;                         136                 goto err;
135         }                                         137         }
136                                                   138 
137         if (b[nr - 1].end > le64_to_cpu(m.nbuc    139         if (b[nr - 1].end > le64_to_cpu(m.nbuckets)) {
138                 prt_printf(err, "journal bucke    140                 prt_printf(err, "journal bucket %llu past end of device (nbuckets %llu)",
139                        b[nr - 1].end - 1, le64    141                        b[nr - 1].end - 1, le64_to_cpu(m.nbuckets));
140                 goto err;                         142                 goto err;
141         }                                         143         }
142                                                   144 
143         for (i = 0; i + 1 < nr; i++) {            145         for (i = 0; i + 1 < nr; i++) {
144                 if (b[i].end > b[i + 1].start)    146                 if (b[i].end > b[i + 1].start) {
145                         prt_printf(err, "dupli    147                         prt_printf(err, "duplicate journal buckets in ranges %llu-%llu, %llu-%llu",
146                                b[i].start, b[i    148                                b[i].start, b[i].end, b[i + 1].start, b[i + 1].end);
147                         goto err;                 149                         goto err;
148                 }                                 150                 }
149         }                                         151         }
150                                                   152 
151         ret = 0;                                  153         ret = 0;
152 err:                                              154 err:
153         kfree(b);                                 155         kfree(b);
154         return ret;                               156         return ret;
155 }                                                 157 }
156                                                   158 
157 static void bch2_sb_journal_v2_to_text(struct     159 static void bch2_sb_journal_v2_to_text(struct printbuf *out, struct bch_sb *sb,
158                                     struct bch    160                                     struct bch_sb_field *f)
159 {                                                 161 {
160         struct bch_sb_field_journal_v2 *journa    162         struct bch_sb_field_journal_v2 *journal = field_to_type(f, journal_v2);
161         unsigned i, nr = bch2_sb_field_journal    163         unsigned i, nr = bch2_sb_field_journal_v2_nr_entries(journal);
162                                                   164 
163         prt_printf(out, "Buckets: ");             165         prt_printf(out, "Buckets: ");
164         for (i = 0; i < nr; i++)                  166         for (i = 0; i < nr; i++)
165                 prt_printf(out, " %llu-%llu",     167                 prt_printf(out, " %llu-%llu",
166                        le64_to_cpu(journal->d[    168                        le64_to_cpu(journal->d[i].start),
167                        le64_to_cpu(journal->d[    169                        le64_to_cpu(journal->d[i].start) + le64_to_cpu(journal->d[i].nr));
168         prt_newline(out);                         170         prt_newline(out);
169 }                                                 171 }
170                                                   172 
171 const struct bch_sb_field_ops bch_sb_field_ops    173 const struct bch_sb_field_ops bch_sb_field_ops_journal_v2 = {
172         .validate       = bch2_sb_journal_v2_v    174         .validate       = bch2_sb_journal_v2_validate,
173         .to_text        = bch2_sb_journal_v2_t    175         .to_text        = bch2_sb_journal_v2_to_text,
174 };                                                176 };
175                                                   177 
176 int bch2_journal_buckets_to_sb(struct bch_fs *    178 int bch2_journal_buckets_to_sb(struct bch_fs *c, struct bch_dev *ca,
177                                u64 *buckets, u    179                                u64 *buckets, unsigned nr)
178 {                                                 180 {
179         struct bch_sb_field_journal_v2 *j;        181         struct bch_sb_field_journal_v2 *j;
180         unsigned i, dst = 0, nr_compacted = 1;    182         unsigned i, dst = 0, nr_compacted = 1;
181                                                   183 
182         if (c)                                    184         if (c)
183                 lockdep_assert_held(&c->sb_loc    185                 lockdep_assert_held(&c->sb_lock);
184                                                   186 
185         if (!nr) {                                187         if (!nr) {
186                 bch2_sb_field_delete(&ca->disk    188                 bch2_sb_field_delete(&ca->disk_sb, BCH_SB_FIELD_journal);
187                 bch2_sb_field_delete(&ca->disk    189                 bch2_sb_field_delete(&ca->disk_sb, BCH_SB_FIELD_journal_v2);
188                 return 0;                         190                 return 0;
189         }                                         191         }
190                                                   192 
191         for (i = 0; i + 1 < nr; i++)              193         for (i = 0; i + 1 < nr; i++)
192                 if (buckets[i] + 1 != buckets[    194                 if (buckets[i] + 1 != buckets[i + 1])
193                         nr_compacted++;           195                         nr_compacted++;
194                                                   196 
195         j = bch2_sb_field_resize(&ca->disk_sb,    197         j = bch2_sb_field_resize(&ca->disk_sb, journal_v2,
196                          (sizeof(*j) + sizeof(    198                          (sizeof(*j) + sizeof(j->d[0]) * nr_compacted) / sizeof(u64));
197         if (!j)                                   199         if (!j)
198                 return -BCH_ERR_ENOSPC_sb_jour    200                 return -BCH_ERR_ENOSPC_sb_journal;
199                                                   201 
200         bch2_sb_field_delete(&ca->disk_sb, BCH    202         bch2_sb_field_delete(&ca->disk_sb, BCH_SB_FIELD_journal);
201                                                   203 
202         j->d[dst].start = cpu_to_le64(buckets[    204         j->d[dst].start = cpu_to_le64(buckets[0]);
203         j->d[dst].nr    = cpu_to_le64(1);         205         j->d[dst].nr    = cpu_to_le64(1);
204                                                   206 
205         for (i = 1; i < nr; i++) {                207         for (i = 1; i < nr; i++) {
206                 if (buckets[i] == buckets[i -     208                 if (buckets[i] == buckets[i - 1] + 1) {
207                         le64_add_cpu(&j->d[dst    209                         le64_add_cpu(&j->d[dst].nr, 1);
208                 } else {                          210                 } else {
209                         dst++;                    211                         dst++;
210                         j->d[dst].start = cpu_    212                         j->d[dst].start = cpu_to_le64(buckets[i]);
211                         j->d[dst].nr    = cpu_    213                         j->d[dst].nr    = cpu_to_le64(1);
212                 }                                 214                 }
213         }                                         215         }
214                                                   216 
215         BUG_ON(dst + 1 != nr_compacted);          217         BUG_ON(dst + 1 != nr_compacted);
216         return 0;                                 218         return 0;
217 }                                                 219 }
218                                                   220 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php