]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/nilfs2/segbuf.h
nilfs2: add iterator for segment buffers
[net-next-2.6.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 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 * Written by Ryusuke Konishi <ryusuke@osrg.net>
21 *
22 */
23#ifndef _NILFS_SEGBUF_H
24#define _NILFS_SEGBUF_H
25
26#include <linux/fs.h>
27#include <linux/buffer_head.h>
28#include <linux/bio.h>
29#include <linux/completion.h>
64b5a32e
RK
30
31/**
32 * struct nilfs_segsum_info - On-memory segment summary
33 * @flags: Flags
34 * @nfinfo: Number of file information structures
35 * @nblocks: Number of blocks included in the partial segment
36 * @nsumblk: Number of summary blocks
37 * @sumbytes: Byte count of segment summary
38 * @nfileblk: Total number of file blocks
39 * @seg_seq: Segment sequence number
40 * @ctime: Creation time
41 * @next: Block number of the next full segment
42 */
43struct nilfs_segsum_info {
44 unsigned int flags;
45 unsigned long nfinfo;
46 unsigned long nblocks;
47 unsigned long nsumblk;
48 unsigned long sumbytes;
49 unsigned long nfileblk;
50 u64 seg_seq;
51 time_t ctime;
52 sector_t next;
53};
54
55/* macro for the flags */
56#define NILFS_SEG_HAS_SR(sum) ((sum)->flags & NILFS_SS_SR)
57#define NILFS_SEG_LOGBGN(sum) ((sum)->flags & NILFS_SS_LOGBGN)
58#define NILFS_SEG_LOGEND(sum) ((sum)->flags & NILFS_SS_LOGEND)
59#define NILFS_SEG_DSYNC(sum) ((sum)->flags & NILFS_SS_SYNDT)
60#define NILFS_SEG_SIMPLEX(sum) \
61 (((sum)->flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) == \
62 (NILFS_SS_LOGBGN | NILFS_SS_LOGEND))
63
64#define NILFS_SEG_EMPTY(sum) ((sum)->nblocks == (sum)->nsumblk)
65
66/**
67 * struct nilfs_segment_buffer - Segment buffer
68 * @sb_super: back pointer to a superblock struct
69 * @sb_list: List head to chain this structure
64b5a32e
RK
70 * @sb_sum: On-memory segment summary
71 * @sb_segnum: Index number of the full segment
72 * @sb_nextnum: Index number of the next full segment
73 * @sb_fseg_start: Start block number of the full segment
74 * @sb_fseg_end: End block number of the full segment
75 * @sb_pseg_start: Disk block number of partial segment
76 * @sb_rest_blocks: Number of residual blocks in the current segment
77 * @sb_segsum_buffers: List of buffers for segment summaries
78 * @sb_payload_buffers: List of buffers for segment payload
9284ad2a
RK
79 * @sb_nbio: Number of flying bio requests
80 * @sb_err: I/O error status
81 * @sb_bio_event: Completion event of log writing
64b5a32e
RK
82 */
83struct nilfs_segment_buffer {
84 struct super_block *sb_super;
85 struct list_head sb_list;
64b5a32e
RK
86
87 /* Segment information */
88 struct nilfs_segsum_info sb_sum;
89 __u64 sb_segnum;
90 __u64 sb_nextnum;
91 sector_t sb_fseg_start, sb_fseg_end;
92 sector_t sb_pseg_start;
93 unsigned sb_rest_blocks;
94
95 /* Buffers */
96 struct list_head sb_segsum_buffers;
97 struct list_head sb_payload_buffers; /* including super root */
98
99 /* io status */
9284ad2a
RK
100 int sb_nbio;
101 atomic_t sb_err;
102 struct completion sb_bio_event;
64b5a32e
RK
103};
104
105#define NILFS_LIST_SEGBUF(head) \
106 list_entry((head), struct nilfs_segment_buffer, sb_list)
107#define NILFS_NEXT_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
108#define NILFS_PREV_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
109#define NILFS_LAST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->prev)
110#define NILFS_FIRST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->next)
111#define NILFS_SEGBUF_IS_LAST(segbuf, head) ((segbuf)->sb_list.next == (head))
112
113#define nilfs_for_each_segbuf_before(s, t, h) \
114 for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
115 (s) = NILFS_NEXT_SEGBUF(s))
116
117#define NILFS_SEGBUF_FIRST_BH(head) \
118 (list_entry((head)->next, struct buffer_head, b_assoc_buffers))
119#define NILFS_SEGBUF_NEXT_BH(bh) \
120 (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
121 b_assoc_buffers))
122#define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head)
123
124
125int __init nilfs_init_segbuf_cache(void);
126void nilfs_destroy_segbuf_cache(void);
127struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
128void nilfs_segbuf_free(struct nilfs_segment_buffer *);
cece5520
RK
129void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
130 struct the_nilfs *);
64b5a32e
RK
131void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
132 struct the_nilfs *);
133int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t);
134int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
135int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
136 struct buffer_head **);
137void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
138void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *, u32);
139void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *, u32);
140
141static inline void
142nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
143 struct buffer_head *bh)
144{
145 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
146 segbuf->sb_sum.nblocks++;
147 segbuf->sb_sum.nsumblk++;
148}
149
150static inline void
151nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
152 struct buffer_head *bh)
153{
154 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
155 segbuf->sb_sum.nblocks++;
156}
157
158static inline void
159nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
160 struct buffer_head *bh)
161{
162 get_bh(bh);
163 nilfs_segbuf_add_payload_buffer(segbuf, bh);
164 segbuf->sb_sum.nfileblk++;
165}
166
9c965bac
RK
167int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
168 struct the_nilfs *nilfs);
9284ad2a 169int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
64b5a32e 170
e29df395
RK
171void nilfs_clear_logs(struct list_head *logs);
172void nilfs_truncate_logs(struct list_head *logs,
173 struct nilfs_segment_buffer *last);
174int nilfs_wait_on_logs(struct list_head *logs);
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 */