blob: 85fbb66455e2ed43d4004724e24c4930bf4af48f [file] [log] [blame]
Ryusuke Konishi64b5a322009-04-06 19:01:36 -07001/*
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>
Ryusuke Konishi64b5a322009-04-06 19:01:36 -070030
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
Ryusuke Konishi50614bc2010-04-10 17:59:15 +090040 * @cno: Checkpoint number
Ryusuke Konishi64b5a322009-04-06 19:01:36 -070041 * @ctime: Creation time
42 * @next: Block number of the next full segment
43 */
44struct nilfs_segsum_info {
45 unsigned int flags;
46 unsigned long nfinfo;
47 unsigned long nblocks;
48 unsigned long nsumblk;
49 unsigned long sumbytes;
50 unsigned long nfileblk;
51 u64 seg_seq;
Ryusuke Konishi50614bc2010-04-10 17:59:15 +090052 __u64 cno;
Ryusuke Konishi64b5a322009-04-06 19:01:36 -070053 time_t ctime;
54 sector_t next;
55};
56
57/* macro for the flags */
58#define NILFS_SEG_HAS_SR(sum) ((sum)->flags & NILFS_SS_SR)
59#define NILFS_SEG_LOGBGN(sum) ((sum)->flags & NILFS_SS_LOGBGN)
60#define NILFS_SEG_LOGEND(sum) ((sum)->flags & NILFS_SS_LOGEND)
61#define NILFS_SEG_DSYNC(sum) ((sum)->flags & NILFS_SS_SYNDT)
62#define NILFS_SEG_SIMPLEX(sum) \
63 (((sum)->flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) == \
64 (NILFS_SS_LOGBGN | NILFS_SS_LOGEND))
65
66#define NILFS_SEG_EMPTY(sum) ((sum)->nblocks == (sum)->nsumblk)
67
68/**
69 * struct nilfs_segment_buffer - Segment buffer
70 * @sb_super: back pointer to a superblock struct
71 * @sb_list: List head to chain this structure
Ryusuke Konishi64b5a322009-04-06 19:01:36 -070072 * @sb_sum: On-memory segment summary
73 * @sb_segnum: Index number of the full segment
74 * @sb_nextnum: Index number of the next full segment
75 * @sb_fseg_start: Start block number of the full segment
76 * @sb_fseg_end: End block number of the full segment
77 * @sb_pseg_start: Disk block number of partial segment
78 * @sb_rest_blocks: Number of residual blocks in the current segment
79 * @sb_segsum_buffers: List of buffers for segment summaries
80 * @sb_payload_buffers: List of buffers for segment payload
Ryusuke Konishi1e2b68b2010-03-23 01:15:31 +090081 * @sb_super_root: Pointer to buffer storing a super root block (if exists)
Ryusuke Konishi9284ad22009-11-25 01:04:21 +090082 * @sb_nbio: Number of flying bio requests
83 * @sb_err: I/O error status
84 * @sb_bio_event: Completion event of log writing
Ryusuke Konishi64b5a322009-04-06 19:01:36 -070085 */
86struct nilfs_segment_buffer {
87 struct super_block *sb_super;
88 struct list_head sb_list;
Ryusuke Konishi64b5a322009-04-06 19:01:36 -070089
90 /* Segment information */
91 struct nilfs_segsum_info sb_sum;
92 __u64 sb_segnum;
93 __u64 sb_nextnum;
94 sector_t sb_fseg_start, sb_fseg_end;
95 sector_t sb_pseg_start;
96 unsigned sb_rest_blocks;
97
98 /* Buffers */
99 struct list_head sb_segsum_buffers;
100 struct list_head sb_payload_buffers; /* including super root */
Ryusuke Konishi1e2b68b2010-03-23 01:15:31 +0900101 struct buffer_head *sb_super_root;
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700102
103 /* io status */
Ryusuke Konishi9284ad22009-11-25 01:04:21 +0900104 int sb_nbio;
105 atomic_t sb_err;
106 struct completion sb_bio_event;
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700107};
108
109#define NILFS_LIST_SEGBUF(head) \
110 list_entry((head), struct nilfs_segment_buffer, sb_list)
111#define NILFS_NEXT_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
112#define NILFS_PREV_SEGBUF(segbuf) NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
113#define NILFS_LAST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->prev)
114#define NILFS_FIRST_SEGBUF(head) NILFS_LIST_SEGBUF((head)->next)
115#define NILFS_SEGBUF_IS_LAST(segbuf, head) ((segbuf)->sb_list.next == (head))
116
117#define nilfs_for_each_segbuf_before(s, t, h) \
118 for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
119 (s) = NILFS_NEXT_SEGBUF(s))
120
121#define NILFS_SEGBUF_FIRST_BH(head) \
122 (list_entry((head)->next, struct buffer_head, b_assoc_buffers))
123#define NILFS_SEGBUF_NEXT_BH(bh) \
124 (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
125 b_assoc_buffers))
126#define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head)
127
Li Hong41c88bd2010-04-06 00:54:11 +0800128extern struct kmem_cache *nilfs_segbuf_cachep;
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700129
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700130struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
131void nilfs_segbuf_free(struct nilfs_segment_buffer *);
Ryusuke Konishicece5522009-04-06 19:01:58 -0700132void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
133 struct the_nilfs *);
Ryusuke Konishia694291a2009-11-29 23:03:04 +0900134void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
135 struct nilfs_segment_buffer *prev);
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700136void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
137 struct the_nilfs *);
Ryusuke Konishi50614bc2010-04-10 17:59:15 +0900138int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t, __u64);
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700139int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
140int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
141 struct buffer_head **);
142void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700143
144static inline void
145nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
146 struct buffer_head *bh)
147{
148 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
149 segbuf->sb_sum.nblocks++;
150 segbuf->sb_sum.nsumblk++;
151}
152
153static inline void
154nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
155 struct buffer_head *bh)
156{
157 list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
158 segbuf->sb_sum.nblocks++;
159}
160
161static inline void
162nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
163 struct buffer_head *bh)
164{
165 get_bh(bh);
166 nilfs_segbuf_add_payload_buffer(segbuf, bh);
167 segbuf->sb_sum.nfileblk++;
168}
169
Ryusuke Konishie29df392009-11-29 16:51:16 +0900170void nilfs_clear_logs(struct list_head *logs);
171void nilfs_truncate_logs(struct list_head *logs,
172 struct nilfs_segment_buffer *last);
Ryusuke Konishid1c6b722009-12-17 00:55:40 +0900173int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
Ryusuke Konishie29df392009-11-29 16:51:16 +0900174int nilfs_wait_on_logs(struct list_head *logs);
Ryusuke Konishiaaed1d52010-03-23 01:50:38 +0900175void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
Ryusuke Konishie29df392009-11-29 16:51:16 +0900176
177static inline void nilfs_destroy_logs(struct list_head *logs)
178{
179 nilfs_truncate_logs(logs, NULL);
180}
181
Ryusuke Konishi64b5a322009-04-06 19:01:36 -0700182#endif /* _NILFS_SEGBUF_H */