]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/nilfs2/segbuf.h
25f2a5faa483aa350b035bc4b06af16314160bf6
[linux-2.6-omap-h63xx.git] / fs / nilfs2 / segbuf.h
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>
30 #include <linux/backing-dev.h>
31
32 /**
33  * struct nilfs_segsum_info - On-memory segment summary
34  * @flags: Flags
35  * @nfinfo: Number of file information structures
36  * @nblocks: Number of blocks included in the partial segment
37  * @nsumblk: Number of summary blocks
38  * @sumbytes: Byte count of segment summary
39  * @nfileblk: Total number of file blocks
40  * @seg_seq: Segment sequence number
41  * @ctime: Creation time
42  * @next: Block number of the next full segment
43  */
44 struct 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;
52         time_t                  ctime;
53         sector_t                next;
54 };
55
56 /* macro for the flags */
57 #define NILFS_SEG_HAS_SR(sum)    ((sum)->flags & NILFS_SS_SR)
58 #define NILFS_SEG_LOGBGN(sum)    ((sum)->flags & NILFS_SS_LOGBGN)
59 #define NILFS_SEG_LOGEND(sum)    ((sum)->flags & NILFS_SS_LOGEND)
60 #define NILFS_SEG_DSYNC(sum)     ((sum)->flags & NILFS_SS_SYNDT)
61 #define NILFS_SEG_SIMPLEX(sum) \
62         (((sum)->flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) == \
63          (NILFS_SS_LOGBGN | NILFS_SS_LOGEND))
64
65 #define NILFS_SEG_EMPTY(sum)    ((sum)->nblocks == (sum)->nsumblk)
66
67 /**
68  * struct nilfs_segment_buffer - Segment buffer
69  * @sb_super: back pointer to a superblock struct
70  * @sb_list: List head to chain this structure
71  * @sb_segent: Pointer for attaching a segment entry
72  * @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
81  * @sb_io_error: I/O error status
82  */
83 struct nilfs_segment_buffer {
84         struct super_block     *sb_super;
85         struct list_head        sb_list;
86         struct nilfs_segment_entry *sb_segent;
87
88         /* Segment information */
89         struct nilfs_segsum_info sb_sum;
90         __u64                   sb_segnum;
91         __u64                   sb_nextnum;
92         sector_t                sb_fseg_start, sb_fseg_end;
93         sector_t                sb_pseg_start;
94         unsigned                sb_rest_blocks;
95
96         /* Buffers */
97         struct list_head        sb_segsum_buffers;
98         struct list_head        sb_payload_buffers; /* including super root */
99
100         /* io status */
101         int                     sb_io_error;
102 };
103
104 #define NILFS_LIST_SEGBUF(head)  \
105         list_entry((head), struct nilfs_segment_buffer, sb_list)
106 #define NILFS_NEXT_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
107 #define NILFS_PREV_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
108 #define NILFS_LAST_SEGBUF(head)    NILFS_LIST_SEGBUF((head)->prev)
109 #define NILFS_FIRST_SEGBUF(head)   NILFS_LIST_SEGBUF((head)->next)
110 #define NILFS_SEGBUF_IS_LAST(segbuf, head)  ((segbuf)->sb_list.next == (head))
111
112 #define nilfs_for_each_segbuf_before(s, t, h) \
113         for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
114              (s) = NILFS_NEXT_SEGBUF(s))
115
116 #define NILFS_SEGBUF_FIRST_BH(head)  \
117         (list_entry((head)->next, struct buffer_head, b_assoc_buffers))
118 #define NILFS_SEGBUF_NEXT_BH(bh)  \
119         (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
120                     b_assoc_buffers))
121 #define NILFS_SEGBUF_BH_IS_LAST(bh, head)  ((bh)->b_assoc_buffers.next == head)
122
123
124 int __init nilfs_init_segbuf_cache(void);
125 void nilfs_destroy_segbuf_cache(void);
126 struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
127 void nilfs_segbuf_free(struct nilfs_segment_buffer *);
128 int nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
129                      struct the_nilfs *);
130 void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
131                                   struct the_nilfs *);
132 int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t);
133 int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
134 int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
135                                 struct buffer_head **);
136 void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
137 void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *, u32);
138 void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *, u32);
139
140 static inline void
141 nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
142                                struct buffer_head *bh)
143 {
144         list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
145         segbuf->sb_sum.nblocks++;
146         segbuf->sb_sum.nsumblk++;
147 }
148
149 static inline void
150 nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
151                                 struct buffer_head *bh)
152 {
153         list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
154         segbuf->sb_sum.nblocks++;
155 }
156
157 static inline void
158 nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
159                              struct buffer_head *bh)
160 {
161         get_bh(bh);
162         nilfs_segbuf_add_payload_buffer(segbuf, bh);
163         segbuf->sb_sum.nfileblk++;
164 }
165
166 void nilfs_release_buffers(struct list_head *);
167
168 static inline void nilfs_segbuf_clear(struct nilfs_segment_buffer *segbuf)
169 {
170         nilfs_release_buffers(&segbuf->sb_segsum_buffers);
171         nilfs_release_buffers(&segbuf->sb_payload_buffers);
172 }
173
174 struct nilfs_write_info {
175         struct bio             *bio;
176         int                     start, end; /* The region to be submitted */
177         int                     rest_blocks;
178         int                     max_pages;
179         int                     nr_vecs;
180         sector_t                blocknr;
181
182         int                     nbio;
183         atomic_t                err;
184         struct completion       bio_event;
185                                 /* completion event of segment write */
186
187         /*
188          * The following fields must be set explicitly
189          */
190         struct super_block     *sb;
191         struct backing_dev_info *bdi; /* backing dev info */
192         struct buffer_head     *bh_sr;
193 };
194
195
196 void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *,
197                                 struct nilfs_write_info *);
198 int nilfs_segbuf_write(struct nilfs_segment_buffer *,
199                        struct nilfs_write_info *);
200 int nilfs_segbuf_wait(struct nilfs_segment_buffer *,
201                       struct nilfs_write_info *);
202
203 #endif /* _NILFS_SEGBUF_H */