Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

bcachefs: jset_entry_datetime

This gives us a way to record the date and time every journal entry was
written - useful for debugging.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

+67 -17
+7 -1
fs/bcachefs/bcachefs_format.h
··· 1275 1275 x(dev_usage, 8) \ 1276 1276 x(log, 9) \ 1277 1277 x(overwrite, 10) \ 1278 - x(write_buffer_keys, 11) 1278 + x(write_buffer_keys, 11) \ 1279 + x(datetime, 12) 1279 1280 1280 1281 enum { 1281 1282 #define x(f, nr) BCH_JSET_ENTRY_##f = nr, ··· 1375 1374 struct jset_entry_log { 1376 1375 struct jset_entry entry; 1377 1376 u8 d[]; 1377 + } __packed __aligned(8); 1378 + 1379 + struct jset_entry_datetime { 1380 + struct jset_entry entry; 1381 + __le64 seconds; 1378 1382 } __packed __aligned(8); 1379 1383 1380 1384 /*
+44
fs/bcachefs/journal_io.c
··· 39 39 prt_printf(out, "seq %llu ", le64_to_cpu(j->j.seq)); 40 40 41 41 bch2_journal_ptrs_to_text(out, c, j); 42 + 43 + struct jset_entry *entry; 44 + for_each_jset_entry_type(entry, &j->j, BCH_JSET_ENTRY_datetime) { 45 + struct jset_entry_datetime *datetime = 46 + container_of(entry, struct jset_entry_datetime, entry); 47 + bch2_prt_datetime(out, le64_to_cpu(datetime->seconds)); 48 + break; 49 + } 42 50 } 43 51 44 52 static struct nonce journal_nonce(const struct jset *jset) ··· 760 752 struct jset_entry *entry) 761 753 { 762 754 journal_entry_btree_keys_to_text(out, c, entry); 755 + } 756 + 757 + static int journal_entry_datetime_validate(struct bch_fs *c, 758 + struct jset *jset, 759 + struct jset_entry *entry, 760 + unsigned version, int big_endian, 761 + enum bkey_invalid_flags flags) 762 + { 763 + unsigned bytes = vstruct_bytes(entry); 764 + unsigned expected = 16; 765 + int ret = 0; 766 + 767 + if (journal_entry_err_on(vstruct_bytes(entry) < expected, 768 + c, version, jset, entry, 769 + journal_entry_dev_usage_bad_size, 770 + "bad size (%u < %u)", 771 + bytes, expected)) { 772 + journal_entry_null_range(entry, vstruct_next(entry)); 773 + return ret; 774 + } 775 + fsck_err: 776 + return ret; 777 + } 778 + 779 + static void journal_entry_datetime_to_text(struct printbuf *out, struct bch_fs *c, 780 + struct jset_entry *entry) 781 + { 782 + struct jset_entry_datetime *datetime = 783 + container_of(entry, struct jset_entry_datetime, entry); 784 + 785 + bch2_prt_datetime(out, le64_to_cpu(datetime->seconds)); 763 786 } 764 787 765 788 struct jset_entry_ops { ··· 1832 1793 start = end = vstruct_last(jset); 1833 1794 1834 1795 end = bch2_btree_roots_to_journal_entries(c, end, btree_roots_have); 1796 + 1797 + struct jset_entry_datetime *d = 1798 + container_of(jset_entry_init(&end, sizeof(*d)), struct jset_entry_datetime, entry); 1799 + d->entry.type = BCH_JSET_ENTRY_datetime; 1800 + d->seconds = cpu_to_le64(ktime_get_real_seconds()); 1835 1801 1836 1802 bch2_journal_super_entries_add_common(c, &end, seq); 1837 1803 u64s = (u64 *) end - (u64 *) start;
+16
fs/bcachefs/journal_io.h
··· 65 65 66 66 CLOSURE_CALLBACK(bch2_journal_write); 67 67 68 + static inline struct jset_entry *jset_entry_init(struct jset_entry **end, size_t size) 69 + { 70 + struct jset_entry *entry = *end; 71 + unsigned u64s = DIV_ROUND_UP(size, sizeof(u64)); 72 + 73 + memset(entry, 0, u64s * sizeof(u64)); 74 + /* 75 + * The u64s field counts from the start of data, ignoring the shared 76 + * fields. 77 + */ 78 + entry->u64s = cpu_to_le16(u64s - 1); 79 + 80 + *end = vstruct_next(*end); 81 + return entry; 82 + } 83 + 68 84 #endif /* _BCACHEFS_JOURNAL_IO_H */
-16
fs/bcachefs/sb-clean.c
··· 171 171 return ERR_PTR(ret); 172 172 } 173 173 174 - static struct jset_entry *jset_entry_init(struct jset_entry **end, size_t size) 175 - { 176 - struct jset_entry *entry = *end; 177 - unsigned u64s = DIV_ROUND_UP(size, sizeof(u64)); 178 - 179 - memset(entry, 0, u64s * sizeof(u64)); 180 - /* 181 - * The u64s field counts from the start of data, ignoring the shared 182 - * fields. 183 - */ 184 - entry->u64s = cpu_to_le16(u64s - 1); 185 - 186 - *end = vstruct_next(*end); 187 - return entry; 188 - } 189 - 190 174 void bch2_journal_super_entries_add_common(struct bch_fs *c, 191 175 struct jset_entry **end, 192 176 u64 journal_seq)