Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /* SPDX-License-Identifier: GPL-2.0+ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * segbuf.h - NILFS Segment buffer prototypes and definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Written by Ryusuke Konishi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #ifndef _NILFS_SEGBUF_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define _NILFS_SEGBUF_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * struct nilfs_segsum_info - On-memory segment summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * @flags: Flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * @nfinfo: Number of file information structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * @nblocks: Number of blocks included in the partial segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * @nsumblk: Number of summary blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @sumbytes: Byte count of segment summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @nfileblk: Total number of file blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * @seg_seq: Segment sequence number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * @cno: Checkpoint number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * @ctime: Creation time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * @next: Block number of the next full segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct nilfs_segsum_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	unsigned int		flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned long		nfinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	unsigned long		nblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	unsigned long		nsumblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	unsigned long		sumbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	unsigned long		nfileblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	u64			seg_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	__u64			cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	time64_t		ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	sector_t		next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * struct nilfs_segment_buffer - Segment buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @sb_super: back pointer to a superblock struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * @sb_list: List head to chain this structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * @sb_sum: On-memory segment summary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * @sb_segnum: Index number of the full segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * @sb_nextnum: Index number of the next full segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * @sb_fseg_start: Start block number of the full segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * @sb_fseg_end: End block number of the full segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * @sb_pseg_start: Disk block number of partial segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * @sb_rest_blocks: Number of residual blocks in the current segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * @sb_segsum_buffers: List of buffers for segment summaries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * @sb_payload_buffers: List of buffers for segment payload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * @sb_super_root: Pointer to buffer storing a super root block (if exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * @sb_nbio: Number of flying bio requests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * @sb_err: I/O error status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * @sb_bio_event: Completion event of log writing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) struct nilfs_segment_buffer {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct super_block     *sb_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	struct list_head	sb_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/* Segment information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct nilfs_segsum_info sb_sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	__u64			sb_segnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	__u64			sb_nextnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	sector_t		sb_fseg_start, sb_fseg_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	sector_t		sb_pseg_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	unsigned int		sb_rest_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* Buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct list_head	sb_segsum_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct list_head	sb_payload_buffers; /* including super root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct buffer_head     *sb_super_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/* io status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int			sb_nbio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	atomic_t		sb_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct completion	sb_bio_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #define NILFS_LIST_SEGBUF(head)  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	list_entry((head), struct nilfs_segment_buffer, sb_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) #define NILFS_NEXT_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #define NILFS_PREV_SEGBUF(segbuf)  NILFS_LIST_SEGBUF((segbuf)->sb_list.prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) #define NILFS_LAST_SEGBUF(head)    NILFS_LIST_SEGBUF((head)->prev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) #define NILFS_FIRST_SEGBUF(head)   NILFS_LIST_SEGBUF((head)->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #define NILFS_SEGBUF_IS_LAST(segbuf, head)  ((segbuf)->sb_list.next == (head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #define nilfs_for_each_segbuf_before(s, t, h) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	for ((s) = NILFS_FIRST_SEGBUF(h); (s) != (t); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	     (s) = NILFS_NEXT_SEGBUF(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #define NILFS_SEGBUF_FIRST_BH(head)  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	(list_entry((head)->next, struct buffer_head, b_assoc_buffers))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define NILFS_SEGBUF_NEXT_BH(bh)  \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	(list_entry((bh)->b_assoc_buffers.next, struct buffer_head, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		    b_assoc_buffers))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define NILFS_SEGBUF_BH_IS_LAST(bh, head)  ((bh)->b_assoc_buffers.next == head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) extern struct kmem_cache *nilfs_segbuf_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) void nilfs_segbuf_free(struct nilfs_segment_buffer *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void nilfs_segbuf_map(struct nilfs_segment_buffer *, __u64, unsigned long,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		      struct the_nilfs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) void nilfs_segbuf_map_cont(struct nilfs_segment_buffer *segbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			   struct nilfs_segment_buffer *prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				  struct the_nilfs *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned int, time64_t,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		       __u64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				struct buffer_head **);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static inline int nilfs_segbuf_simplex(struct nilfs_segment_buffer *segbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	unsigned int flags = segbuf->sb_sum.flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	return (flags & (NILFS_SS_LOGBGN | NILFS_SS_LOGEND)) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		(NILFS_SS_LOGBGN | NILFS_SS_LOGEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static inline int nilfs_segbuf_empty(struct nilfs_segment_buffer *segbuf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return segbuf->sb_sum.nblocks == segbuf->sb_sum.nsumblk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			       struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_segsum_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	segbuf->sb_sum.nblocks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	segbuf->sb_sum.nsumblk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) nilfs_segbuf_add_payload_buffer(struct nilfs_segment_buffer *segbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	list_add_tail(&bh->b_assoc_buffers, &segbuf->sb_payload_buffers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	segbuf->sb_sum.nblocks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) nilfs_segbuf_add_file_buffer(struct nilfs_segment_buffer *segbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			     struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	get_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	nilfs_segbuf_add_payload_buffer(segbuf, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	segbuf->sb_sum.nfileblk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void nilfs_clear_logs(struct list_head *logs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) void nilfs_truncate_logs(struct list_head *logs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			 struct nilfs_segment_buffer *last);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int nilfs_wait_on_logs(struct list_head *logs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static inline void nilfs_destroy_logs(struct list_head *logs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	nilfs_truncate_logs(logs, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) #endif /* _NILFS_SEGBUF_H */