Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * NILFS Segment buffer prototypes and definitions
0004  *
0005  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
0006  *
0007  * Written by Ryusuke Konishi.
0008  *
0009  */
0010 #ifndef _NILFS_SEGBUF_H
0011 #define _NILFS_SEGBUF_H
0012 
0013 #include <linux/fs.h>
0014 #include <linux/buffer_head.h>
0015 #include <linux/bio.h>
0016 #include <linux/completion.h>
0017 
0018 /**
0019  * struct nilfs_segsum_info - On-memory segment summary
0020  * @flags: Flags
0021  * @nfinfo: Number of file information structures
0022  * @nblocks: Number of blocks included in the partial segment
0023  * @nsumblk: Number of summary blocks
0024  * @sumbytes: Byte count of segment summary
0025  * @nfileblk: Total number of file blocks
0026  * @seg_seq: Segment sequence number
0027  * @cno: Checkpoint number
0028  * @ctime: Creation time
0029  * @next: Block number of the next full segment
0030  */
0031 struct nilfs_segsum_info {
0032     unsigned int        flags;
0033     unsigned long       nfinfo;
0034     unsigned long       nblocks;
0035     unsigned long       nsumblk;
0036     unsigned long       sumbytes;
0037     unsigned long       nfileblk;
0038     u64         seg_seq;
0039     __u64           cno;
0040     time64_t        ctime;
0041     sector_t        next;
0042 };
0043 
0044 /**
0045  * struct nilfs_segment_buffer - Segment buffer
0046  * @sb_super: back pointer to a superblock struct
0047  * @sb_list: List head to chain this structure
0048  * @sb_sum: On-memory segment summary
0049  * @sb_segnum: Index number of the full segment
0050  * @sb_nextnum: Index number of the next full segment
0051  * @sb_fseg_start: Start block number of the full segment
0052  * @sb_fseg_end: End block number of the full segment
0053  * @sb_pseg_start: Disk block number of partial segment
0054  * @sb_rest_blocks: Number of residual blocks in the current segment
0055  * @sb_segsum_buffers: List of buffers for segment summaries
0056  * @sb_payload_buffers: List of buffers for segment payload
0057  * @sb_super_root: Pointer to buffer storing a super root block (if exists)
0058  * @sb_nbio: Number of flying bio requests
0059  * @sb_err: I/O error status
0060  * @sb_bio_event: Completion event of log writing
0061  */
0062 struct nilfs_segment_buffer {
0063     struct super_block     *sb_super;
0064     struct list_head    sb_list;
0065 
0066     /* Segment information */
0067     struct nilfs_segsum_info sb_sum;
0068     __u64           sb_segnum;
0069     __u64           sb_nextnum;
0070     sector_t        sb_fseg_start, sb_fseg_end;
0071     sector_t        sb_pseg_start;
0072     unsigned int        sb_rest_blocks;
0073 
0074     /* Buffers */
0075     struct list_head    sb_segsum_buffers;
0076     struct list_head    sb_payload_buffers; /* including super root */
0077     struct buffer_head     *sb_super_root;
0078 
0079     /* io status */
0080     int         sb_nbio;
0081     atomic_t        sb_err;
0082     struct completion   sb_bio_event;
0083 };
0084 
0085 #define NILFS_LIST_SEGBUF(head)  \
0086     list_entry((head), struct nilfs_segment_buffer, sb_list)
0087 #define NILFS_NEXT_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
0088 #define NILFS_PREV_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
0089 #define NILFS_LAST_SEGBUF(head)    NILFS_LIST_SEGBUF((head)->prev)
0090 #define NILFS_FIRST_SEGBUF(head)   NILFS_LIST_SEGBUF((head)->next)
0091 #define NILFS_SEGBUF_IS_LAST(segbuf, head)  ((segbuf)->sb_list.next == (head))
0092 
0093 #define nilfs_for_each_segbuf_before(s, t, h) \
0094     for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
0095          (s) = NILFS_NEXT_SEGBUF(s))
0096 
0097 #define NILFS_SEGBUF_FIRST_BH(head)  \
0098     (list_entry((head)->next, struct buffer_head, b_assoc_buffers))
0099 #define NILFS_SEGBUF_NEXT_BH(bh)  \
0100     (list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
0101             b_assoc_buffers))
0102 #define NILFS_SEGBUF_BH_IS_LAST(bh, head)  ((bh)->b_assoc_buffers.next == head)
0103 
0104 extern struct kmem_cache *nilfs_segbuf_cachep;
0105 
0106 struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
0107 void nilfs_segbuf_free(struct nilfs_segment_buffer *);
0108 void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
0109               struct the_nilfs *);
0110 void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
0111                struct nilfs_segment_buffer *prev);
0112 void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
0113                   struct the_nilfs *);
0114 int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time64_t,
0115                __u64);
0116 int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
0117 int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
0118                 struct buffer_head **);
0119 void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
0120 
0121 static inline int nilfs_segbuf_simplex(struct nilfs_segment_buffer *segbuf)
0122 {
0123     unsigned int flags = segbuf->sb_sum.flags;
0124 
0125     return (flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) ==
0126         (NILFS_SS_LOGBGN | NILFS_SS_LOGEND);
0127 }
0128 
0129 static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf)
0130 {
0131     return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk;
0132 }
0133 
0134 static inline void
0135 nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
0136                    struct buffer_head *bh)
0137 {
0138     list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
0139     segbuf->sb_sum.nblocks++;
0140     segbuf->sb_sum.nsumblk++;
0141 }
0142 
0143 static inline void
0144 nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
0145                 struct buffer_head *bh)
0146 {
0147     list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
0148     segbuf->sb_sum.nblocks++;
0149 }
0150 
0151 static inline void
0152 nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
0153                  struct buffer_head *bh)
0154 {
0155     get_bh(bh);
0156     nilfs_segbuf_add_payload_buffer(segbuf, bh);
0157     segbuf->sb_sum.nfileblk++;
0158 }
0159 
0160 void nilfs_clear_logs(struct list_head *logs);
0161 void nilfs_truncate_logs(struct list_head *logs,
0162              struct nilfs_segment_buffer *last);
0163 int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
0164 int nilfs_wait_on_logs(struct list_head *logs);
0165 void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
0166 
0167 static inline void nilfs_destroy_logs(struct list_head *logs)
0168 {
0169     nilfs_truncate_logs(logs, NULL);
0170 }
0171 
0172 #endif /* _NILFS_SEGBUF_H */