9 #include <linux/slab.h>
50 static void reserve_sb_and_journal(
struct super_block *sb)
56 err = btree_insert32(head, seg_no(sb, super->
s_sb_ofs[0]), (
void *)1,
60 err = btree_insert32(head, seg_no(sb, super->
s_sb_ofs[1]), (
void *)1,
67 err = btree_insert32(head, super->
s_journal_seg[i], (
void *)1,
105 static void read_erasecount(
struct super_block *sb,
135 return logfs_buf_recover(area, ofs, a + 1, super->
s_writesize);
137 return logfs_buf_recover(area, ofs,
NULL, 0);
140 static void *unpack(
void *
from,
void *to)
169 err =
wbuf_read(sb, ofs,
sizeof(*jh), jh);
179 if (datalen > bufsize)
191 err =
wbuf_read(sb, ofs +
sizeof(*jh), len, jh + 1);
194 if (jh->
h_crc != logfs_crc32(jh, len +
sizeof(*jh), 4)) {
200 if (jh->
h_crc == logfs_crc32(jh, len, 4))
216 err = __read_je_header(sb, ofs, jh);
219 return __read_je_payload(sb, ofs, jh);
230 err = __read_je(sb, ofs, jh);
238 read_dynsb(sb, unpack(jh, scratch));
241 read_anchor(sb, unpack(jh, scratch));
244 read_erasecount(sb, unpack(jh, scratch));
247 err = read_area(sb, unpack(jh, scratch));
264 u64 ofs, seg_ofs = dev_ofs(sb, segno, 0);
265 u32 h_ofs, last_ofs = 0;
270 for (h_ofs = 0; h_ofs < super->
s_segsize; h_ofs +=
sizeof(*jh)) {
271 ofs = seg_ofs + h_ofs;
272 err = __read_je_header(sb, ofs, jh);
277 err = __read_je_payload(sb, ofs, jh);
283 (datalen %
sizeof(
__be64)))
287 h_ofs +=
ALIGN(len,
sizeof(*jh)) -
sizeof(*jh);
292 ofs = seg_ofs + last_ofs;
294 err = __read_je(sb, ofs, jh);
302 for (i = 0; i < super->
s_no_je; i++) {
319 err =
wbuf_read(sb, dev_ofs(sb, segno, 0),
sizeof(sh), &sh);
322 crc = logfs_crc32(&sh,
sizeof(sh), 4);
331 static int logfs_read_journal(
struct super_block *sb)
358 static void journal_get_free_segment(
struct logfs_area *area)
382 static void journal_get_erase_count(
struct logfs_area *area)
388 static int journal_erase_segment(
struct logfs_area *area)
409 u.sh.crc = logfs_crc32(&
u.sh,
sizeof(
u.sh), 4);
414 ofs = dev_ofs(sb, area->
a_segno, 0);
416 logfs_buf_write(area, ofs, &
u,
sizeof(
u));
420 static size_t __logfs_write_header(
struct logfs_super *super,
433 jh->
h_crc = logfs_crc32(jh, len +
sizeof(*jh), 4);
434 return ALIGN(len, 16) +
sizeof(*jh);
437 static size_t logfs_write_header(
struct logfs_super *super,
442 return __logfs_write_header(super, jh, len, datalen, type,
COMPR_NONE);
445 static inline size_t logfs_journal_erasecount_size(
struct logfs_super *super)
450 static void *logfs_write_erasecount(
struct super_block *sb,
void *_ec,
451 u16 *type,
size_t *len)
460 *len = logfs_journal_erasecount_size(super);
464 static
void account_shadow(
void *_shadow,
unsigned long _sb,
u64 ignore,
484 log_journal(
"account_shadow(%llx, %llx, %x) %llx->%llx %x->%x\n",
491 static void account_shadows(
struct super_block *sb)
498 btree_grim_visitor64(&tree->
new, (
unsigned long)sb, account_shadow);
499 btree_grim_visitor64(&tree->
old, (
unsigned long)sb, account_shadow);
515 static void *__logfs_write_anchor(
struct super_block *sb,
void *_da,
516 u16 *type,
size_t *len)
535 static void *logfs_write_dynsb(
struct super_block *sb,
void *_dynsb,
536 u16 *type,
size_t *len)
549 *len =
sizeof(*dynsb);
563 ofs = dev_ofs(sb, area->
a_segno,
574 static void *logfs_write_area(
struct super_block *sb,
void *_a,
575 u16 *type,
size_t *len)
586 write_wbuf(sb, area, a + 1);
593 static void *logfs_write_commit(
struct super_block *sb,
void *
h,
594 u16 *type,
size_t *len)
613 return logfs_write_header(super, header, 0, type);
616 if (compr_len < 0 || type ==
JE_ANCHOR) {
622 pad_len =
ALIGN(compr_len, 16);
623 memset(data + compr_len, 0, pad_len - compr_len);
625 return __logfs_write_header(super, header, compr_len, len, type, compr);
650 static int logfs_write_je_buf(
struct super_block *sb,
void *buf,
u16 type,
660 len = __logfs_write_je(sb, buf, type, buf_len);
664 ofs = logfs_get_free_bytes(area, &len, must_pad);
675 u16 *type,
size_t *len))
682 return logfs_write_je_buf(sb, buf, type, len);
692 log_aliases(
"logfs_write_obj_aliases #%x(%llx, %llx, %x, %x) %llx\n",
709 static int logfs_write_obj_aliases(
struct super_block *sb)
714 log_journal(
"logfs_write_obj_aliases: %d aliases to write\n",
754 if (!super->
s_area[i]->a_is_open)
757 err = logfs_write_je(sb, logfs_write_area);
761 err = logfs_write_obj_aliases(sb);
764 err = logfs_write_je(sb, logfs_write_erasecount);
767 err = logfs_write_je(sb, __logfs_write_anchor);
770 err = logfs_write_je(sb, logfs_write_dynsb);
792 err = logfs_write_je(sb, logfs_write_commit);
830 err = btree_insert32(head, segno, (
void *)1,
GFP_NOFS);
848 .get_free_segment = journal_get_free_segment,
849 .get_erase_count = journal_get_erase_count,
850 .erase_segment = journal_erase_segment,
875 ret = logfs_read_journal(sb);
879 reserve_sb_and_journal(sb);