defconfig: exynos9610: Re-add dropped Wi-Fi AP options lost
[GitHub/LineageOS/android_kernel_motorola_exynos9610.git] / fs / nilfs2 / segbuf.h
CommitLineData
64b5a32e
RK
1/*
2 * segbuf.h - NILFS Segment buffer prototypes and definitions
3 *
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
4b420ab4 16 * Written by Ryusuke Konishi.
64b5a32e
RK
17 *
18 */
19#ifndef _NILFS_SEGBUF_H
20#define _NILFS_SEGBUF_H
21
22#include <linux/fs.h>
23#include <linux/buffer_head.h>
24#include <linux/bio.h>
25#include <linux/completion.h>
64b5a32e
RK
26
27/**
28 * struct nilfs_segsum_info - On-memory segment summary
29 * @flags: Flags
30 * @nfinfo: Number of file information structures
31 * @nblocks: Number of blocks included in the partial segment
32 * @nsumblk: Number of summary blocks
33 * @sumbytes: Byte count of segment summary
34 * @nfileblk: Total number of file blocks
35 * @seg_seq: Segment sequence number
50614bcf 36 * @cno: Checkpoint number
64b5a32e
RK
37 * @ctime: Creation time
38 * @next: Block number of the next full segment
39 */
40struct nilfs_segsum_info {
41 unsigned int flags;
42 unsigned long nfinfo;
43 unsigned long nblocks;
44 unsigned long nsumblk;
45 unsigned long sumbytes;
46 unsigned long nfileblk;
47 u64 seg_seq;
50614bcf 48 __u64 cno;
64b5a32e
RK
49 time_t ctime;
50 sector_t next;
51};
52
64b5a32e
RK
53/**
54 * struct nilfs_segment_buffer - Segment buffer
55 * @sb_super: back pointer to a superblock struct
56 * @sb_list: List head to chain this structure
64b5a32e
RK
57 * @sb_sum: On-memory segment summary
58 * @sb_segnum: Index number of the full segment
59 * @sb_nextnum: Index number of the next full segment
60 * @sb_fseg_start: Start block number of the full segment
61 * @sb_fseg_end: End block number of the full segment
62 * @sb_pseg_start: Disk block number of partial segment
63 * @sb_rest_blocks: Number of residual blocks in the current segment
64 * @sb_segsum_buffers: List of buffers for segment summaries
65 * @sb_payload_buffers: List of buffers for segment payload
1e2b68bf 66 * @sb_super_root: Pointer to buffer storing a super root block (if exists)
9284ad2a
RK
67 * @sb_nbio: Number of flying bio requests
68 * @sb_err: I/O error status
69 * @sb_bio_event: Completion event of log writing
64b5a32e
RK
70 */
71struct nilfs_segment_buffer {
72 struct super_block *sb_super;
73 struct list_head sb_list;
64b5a32e
RK
74
75 /* Segment information */
76 struct nilfs_segsum_info sb_sum;
77 __u64 sb_segnum;
78 __u64 sb_nextnum;
79 sector_t sb_fseg_start, sb_fseg_end;
80 sector_t sb_pseg_start;
0c6c44cb 81 unsigned int sb_rest_blocks;
64b5a32e
RK
82
83 /* Buffers */
84 struct list_head sb_segsum_buffers;
85 struct list_head sb_payload_buffers; /* including super root */
1e2b68bf 86 struct buffer_head *sb_super_root;
64b5a32e
RK
87
88 /* io status */
9284ad2a
RK
89 int sb_nbio;
90 atomic_t sb_err;
91 struct completion sb_bio_event;
64b5a32e
RK
92};
93
94#define NILFS_LIST_SEGBUF(head) \
95 list_entry((head), struct nilfs_segment_buffer, sb_list)
96#define NILFS_NEXT_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
97#define NILFS_PREV_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
98#define NILFS_LAST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->prev)
99#define NILFS_FIRST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->next)
100#define NILFS_SEGBUF_IS_LAST(segbuf, head) ((segbuf)->sb_list.next == (head))
101
102#define nilfs_for_each_segbuf_before(s, t, h) \
103 for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
104 (s) = NILFS_NEXT_SEGBUF(s))
105
106#define NILFS_SEGBUF_FIRST_BH(head) \
107 (list_entry((head)->next, struct buffer_head, b_assoc_buffers))
108#define NILFS_SEGBUF_NEXT_BH(bh) \
109 (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
110 b_assoc_buffers))
111#define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head)
112
41c88bd7 113extern struct kmem_cache *nilfs_segbuf_cachep;
64b5a32e 114
64b5a32e
RK
115struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
116void nilfs_segbuf_free(struct nilfs_segment_buffer *);
cece5520
RK
117void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
118 struct the_nilfs *);
a694291a
RK
119void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
120 struct nilfs_segment_buffer *prev);
64b5a32e
RK
121void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
122 struct the_nilfs *);
0c6c44cb
RK
123int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time_t,
124 __u64);
64b5a32e
RK
125int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
126int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
127 struct buffer_head **);
128void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
64b5a32e 129
4762077c
RK
130static inline int nilfs_segbuf_simplex(struct nilfs_segment_buffer *segbuf)
131{
132 unsigned int flags = segbuf->sb_sum.flags;
133
134 return (flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) ==
135 (NILFS_SS_LOGBGN | NILFS_SS_LOGEND);
136}
137
138static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf)
139{
140 return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk;
141}
142
64b5a32e
RK
143static inline void
144nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
145 struct buffer_head *bh)
146{
147 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
148 segbuf->sb_sum.nblocks++;
149 segbuf->sb_sum.nsumblk++;
150}
151
152static inline void
153nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
154 struct buffer_head *bh)
155{
156 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
157 segbuf->sb_sum.nblocks++;
158}
159
160static inline void
161nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
162 struct buffer_head *bh)
163{
164 get_bh(bh);
165 nilfs_segbuf_add_payload_buffer(segbuf, bh);
166 segbuf->sb_sum.nfileblk++;
167}
168
e29df395
RK
169void nilfs_clear_logs(struct list_head *logs);
170void nilfs_truncate_logs(struct list_head *logs,
171 struct nilfs_segment_buffer *last);
d1c6b72a 172int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
e29df395 173int nilfs_wait_on_logs(struct list_head *logs);
aaed1d5b 174void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
e29df395
RK
175
176static inline void nilfs_destroy_logs(struct list_head *logs)
177{
178 nilfs_truncate_logs(logs, NULL);
179}
180
64b5a32e 181#endif /* _NILFS_SEGBUF_H */