Ryusuke Konishi | ae98043 | 2018-09-04 15:46:30 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 2 | /* |
Ryusuke Konishi | 94ee1d9 | 2021-11-08 18:35:01 -0800 | [diff] [blame] | 3 | * NILFS Segment buffer prototypes and definitions |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation. |
| 6 | * |
Ryusuke Konishi | 4b420ab | 2016-05-23 16:23:09 -0700 | [diff] [blame] | 7 | * Written by Ryusuke Konishi. |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 8 | * |
| 9 | */ |
| 10 | #ifndef _NILFS_SEGBUF_H |
| 11 | #define _NILFS_SEGBUF_H |
| 12 | |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/buffer_head.h> |
| 15 | #include <linux/bio.h> |
| 16 | #include <linux/completion.h> |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * struct nilfs_segsum_info - On-memory segment summary |
| 20 | * @flags: Flags |
| 21 | * @nfinfo: Number of file information structures |
| 22 | * @nblocks: Number of blocks included in the partial segment |
| 23 | * @nsumblk: Number of summary blocks |
| 24 | * @sumbytes: Byte count of segment summary |
| 25 | * @nfileblk: Total number of file blocks |
| 26 | * @seg_seq: Segment sequence number |
Ryusuke Konishi | 50614bc | 2010-04-10 17:59:15 +0900 | [diff] [blame] | 27 | * @cno: Checkpoint number |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 28 | * @ctime: Creation time |
| 29 | * @next: Block number of the next full segment |
| 30 | */ |
| 31 | struct nilfs_segsum_info { |
| 32 | unsigned int flags; |
| 33 | unsigned long nfinfo; |
| 34 | unsigned long nblocks; |
| 35 | unsigned long nsumblk; |
| 36 | unsigned long sumbytes; |
| 37 | unsigned long nfileblk; |
| 38 | u64 seg_seq; |
Ryusuke Konishi | 50614bc | 2010-04-10 17:59:15 +0900 | [diff] [blame] | 39 | __u64 cno; |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 40 | time64_t ctime; |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 41 | sector_t next; |
| 42 | }; |
| 43 | |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 44 | /** |
| 45 | * struct nilfs_segment_buffer - Segment buffer |
| 46 | * @sb_super: back pointer to a superblock struct |
| 47 | * @sb_list: List head to chain this structure |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 48 | * @sb_sum: On-memory segment summary |
| 49 | * @sb_segnum: Index number of the full segment |
| 50 | * @sb_nextnum: Index number of the next full segment |
| 51 | * @sb_fseg_start: Start block number of the full segment |
| 52 | * @sb_fseg_end: End block number of the full segment |
| 53 | * @sb_pseg_start: Disk block number of partial segment |
| 54 | * @sb_rest_blocks: Number of residual blocks in the current segment |
| 55 | * @sb_segsum_buffers: List of buffers for segment summaries |
| 56 | * @sb_payload_buffers: List of buffers for segment payload |
Ryusuke Konishi | 1e2b68b | 2010-03-23 01:15:31 +0900 | [diff] [blame] | 57 | * @sb_super_root: Pointer to buffer storing a super root block (if exists) |
Ryusuke Konishi | 9284ad2 | 2009-11-25 01:04:21 +0900 | [diff] [blame] | 58 | * @sb_nbio: Number of flying bio requests |
| 59 | * @sb_err: I/O error status |
| 60 | * @sb_bio_event: Completion event of log writing |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 61 | */ |
| 62 | struct nilfs_segment_buffer { |
| 63 | struct super_block *sb_super; |
| 64 | struct list_head sb_list; |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 65 | |
| 66 | /* Segment information */ |
| 67 | struct nilfs_segsum_info sb_sum; |
| 68 | __u64 sb_segnum; |
| 69 | __u64 sb_nextnum; |
| 70 | sector_t sb_fseg_start, sb_fseg_end; |
| 71 | sector_t sb_pseg_start; |
Ryusuke Konishi | 0c6c44c | 2016-05-23 16:23:39 -0700 | [diff] [blame] | 72 | unsigned int sb_rest_blocks; |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 73 | |
| 74 | /* Buffers */ |
| 75 | struct list_head sb_segsum_buffers; |
| 76 | struct list_head sb_payload_buffers; /* including super root */ |
Ryusuke Konishi | 1e2b68b | 2010-03-23 01:15:31 +0900 | [diff] [blame] | 77 | struct buffer_head *sb_super_root; |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* io status */ |
Ryusuke Konishi | 9284ad2 | 2009-11-25 01:04:21 +0900 | [diff] [blame] | 80 | int sb_nbio; |
| 81 | atomic_t sb_err; |
| 82 | struct completion sb_bio_event; |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | #define NILFS_LIST_SEGBUF(head) \ |
| 86 | list_entry((head), struct nilfs_segment_buffer, sb_list) |
| 87 | #define NILFS_NEXT_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.next) |
| 88 | #define NILFS_PREV_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.prev) |
| 89 | #define NILFS_LAST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->prev) |
| 90 | #define NILFS_FIRST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->next) |
| 91 | #define NILFS_SEGBUF_IS_LAST(segbuf, head) ((segbuf)->sb_list.next == (head)) |
| 92 | |
| 93 | #define nilfs_for_each_segbuf_before(s, t, h) \ |
| 94 | for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \ |
| 95 | (s) = NILFS_NEXT_SEGBUF(s)) |
| 96 | |
| 97 | #define NILFS_SEGBUF_FIRST_BH(head) \ |
| 98 | (list_entry((head)->next, struct buffer_head, b_assoc_buffers)) |
| 99 | #define NILFS_SEGBUF_NEXT_BH(bh) \ |
| 100 | (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \ |
| 101 | b_assoc_buffers)) |
| 102 | #define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head) |
| 103 | |
Li Hong | 41c88bd | 2010-04-06 00:54:11 +0800 | [diff] [blame] | 104 | extern struct kmem_cache *nilfs_segbuf_cachep; |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 105 | |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 106 | struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *); |
| 107 | void nilfs_segbuf_free(struct nilfs_segment_buffer *); |
Ryusuke Konishi | cece552 | 2009-04-06 19:01:58 -0700 | [diff] [blame] | 108 | void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long, |
| 109 | struct the_nilfs *); |
Ryusuke Konishi | a694291a | 2009-11-29 23:03:04 +0900 | [diff] [blame] | 110 | void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf, |
| 111 | struct nilfs_segment_buffer *prev); |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 112 | void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64, |
| 113 | struct the_nilfs *); |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 114 | int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time64_t, |
Ryusuke Konishi | 0c6c44c | 2016-05-23 16:23:39 -0700 | [diff] [blame] | 115 | __u64); |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 116 | int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *); |
| 117 | int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *, |
| 118 | struct buffer_head **); |
| 119 | void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *); |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 120 | |
Ryusuke Konishi | 4762077 | 2010-05-23 21:48:36 +0900 | [diff] [blame] | 121 | static inline int nilfs_segbuf_simplex(struct nilfs_segment_buffer *segbuf) |
| 122 | { |
| 123 | unsigned int flags = segbuf->sb_sum.flags; |
| 124 | |
| 125 | return (flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) == |
| 126 | (NILFS_SS_LOGBGN | NILFS_SS_LOGEND); |
| 127 | } |
| 128 | |
| 129 | static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf) |
| 130 | { |
| 131 | return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk; |
| 132 | } |
| 133 | |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 134 | static inline void |
| 135 | nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf, |
| 136 | struct buffer_head *bh) |
| 137 | { |
| 138 | list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers); |
| 139 | segbuf->sb_sum.nblocks++; |
| 140 | segbuf->sb_sum.nsumblk++; |
| 141 | } |
| 142 | |
| 143 | static inline void |
| 144 | nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf, |
| 145 | struct buffer_head *bh) |
| 146 | { |
| 147 | list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers); |
| 148 | segbuf->sb_sum.nblocks++; |
| 149 | } |
| 150 | |
| 151 | static inline void |
| 152 | nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf, |
| 153 | struct buffer_head *bh) |
| 154 | { |
| 155 | get_bh(bh); |
| 156 | nilfs_segbuf_add_payload_buffer(segbuf, bh); |
| 157 | segbuf->sb_sum.nfileblk++; |
| 158 | } |
| 159 | |
Ryusuke Konishi | e29df39 | 2009-11-29 16:51:16 +0900 | [diff] [blame] | 160 | void nilfs_clear_logs(struct list_head *logs); |
| 161 | void nilfs_truncate_logs(struct list_head *logs, |
| 162 | struct nilfs_segment_buffer *last); |
Ryusuke Konishi | d1c6b72 | 2009-12-17 00:55:40 +0900 | [diff] [blame] | 163 | int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs); |
Ryusuke Konishi | e29df39 | 2009-11-29 16:51:16 +0900 | [diff] [blame] | 164 | int nilfs_wait_on_logs(struct list_head *logs); |
Ryusuke Konishi | aaed1d5 | 2010-03-23 01:50:38 +0900 | [diff] [blame] | 165 | void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed); |
Ryusuke Konishi | e29df39 | 2009-11-29 16:51:16 +0900 | [diff] [blame] | 166 | |
| 167 | static inline void nilfs_destroy_logs(struct list_head *logs) |
| 168 | { |
| 169 | nilfs_truncate_logs(logs, NULL); |
| 170 | } |
| 171 | |
Ryusuke Konishi | 64b5a32 | 2009-04-06 19:01:36 -0700 | [diff] [blame] | 172 | #endif /* _NILFS_SEGBUF_H */ |