jfs_logmgr.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) International Business Machines Corp., 2000-2004
  4. * Portions Copyright (C) Christoph Hellwig, 2001-2002
  5. */
  6. #ifndef _H_JFS_LOGMGR
  7. #define _H_JFS_LOGMGR
  8. #include <linux/uuid.h>
  9. #include "jfs_filsys.h"
  10. #include "jfs_lock.h"
  11. /*
  12. * log manager configuration parameters
  13. */
  14. /* log page size */
  15. #define LOGPSIZE 4096
  16. #define L2LOGPSIZE 12
  17. #define LOGPAGES 16 /* Log pages per mounted file system */
  18. /*
  19. * log logical volume
  20. *
  21. * a log is used to make the commit operation on journalled
  22. * files within the same logical volume group atomic.
  23. * a log is implemented with a logical volume.
  24. * there is one log per logical volume group.
  25. *
  26. * block 0 of the log logical volume is not used (ipl etc).
  27. * block 1 contains a log "superblock" and is used by logFormat(),
  28. * lmLogInit(), lmLogShutdown(), and logRedo() to record status
  29. * of the log but is not otherwise used during normal processing.
  30. * blocks 2 - (N-1) are used to contain log records.
  31. *
  32. * when a volume group is varied-on-line, logRedo() must have
  33. * been executed before the file systems (logical volumes) in
  34. * the volume group can be mounted.
  35. */
  36. /*
  37. * log superblock (block 1 of logical volume)
  38. */
  39. #define LOGSUPER_B 1
  40. #define LOGSTART_B 2
  41. #define LOGMAGIC 0x87654321
  42. #define LOGVERSION 1
  43. #define MAX_ACTIVE 128 /* Max active file systems sharing log */
  44. struct logsuper {
  45. __le32 magic; /* 4: log lv identifier */
  46. __le32 version; /* 4: version number */
  47. __le32 serial; /* 4: log open/mount counter */
  48. __le32 size; /* 4: size in number of LOGPSIZE blocks */
  49. __le32 bsize; /* 4: logical block size in byte */
  50. __le32 l2bsize; /* 4: log2 of bsize */
  51. __le32 flag; /* 4: option */
  52. __le32 state; /* 4: state - see below */
  53. __le32 end; /* 4: addr of last log record set by logredo */
  54. uuid_t uuid; /* 16: 128-bit journal uuid */
  55. char label[16]; /* 16: journal label */
  56. struct {
  57. uuid_t uuid;
  58. } active[MAX_ACTIVE]; /* 2048: active file systems list */
  59. };
  60. /* log flag: commit option (see jfs_filsys.h) */
  61. /* log state */
  62. #define LOGMOUNT 0 /* log mounted by lmLogInit() */
  63. #define LOGREDONE 1 /* log shutdown by lmLogShutdown().
  64. * log redo completed by logredo().
  65. */
  66. #define LOGWRAP 2 /* log wrapped */
  67. #define LOGREADERR 3 /* log read error detected in logredo() */
  68. /*
  69. * log logical page
  70. *
  71. * (this comment should be rewritten !)
  72. * the header and trailer structures (h,t) will normally have
  73. * the same page and eor value.
  74. * An exception to this occurs when a complete page write is not
  75. * accomplished on a power failure. Since the hardware may "split write"
  76. * sectors in the page, any out of order sequence may occur during powerfail
  77. * and needs to be recognized during log replay. The xor value is
  78. * an "exclusive or" of all log words in the page up to eor. This
  79. * 32 bit eor is stored with the top 16 bits in the header and the
  80. * bottom 16 bits in the trailer. logredo can easily recognize pages
  81. * that were not completed by reconstructing this eor and checking
  82. * the log page.
  83. *
  84. * Previous versions of the operating system did not allow split
  85. * writes and detected partially written records in logredo by
  86. * ordering the updates to the header, trailer, and the move of data
  87. * into the logdata area. The order: (1) data is moved (2) header
  88. * is updated (3) trailer is updated. In logredo, when the header
  89. * differed from the trailer, the header and trailer were reconciled
  90. * as follows: if h.page != t.page they were set to the smaller of
  91. * the two and h.eor and t.eor set to 8 (i.e. empty page). if (only)
  92. * h.eor != t.eor they were set to the smaller of their two values.
  93. */
  94. struct logpage {
  95. struct { /* header */
  96. __le32 page; /* 4: log sequence page number */
  97. __le16 rsrvd; /* 2: */
  98. __le16 eor; /* 2: end-of-log offset of lasrt record write */
  99. } h;
  100. __le32 data[LOGPSIZE / 4 - 4]; /* log record area */
  101. struct { /* trailer */
  102. __le32 page; /* 4: normally the same as h.page */
  103. __le16 rsrvd; /* 2: */
  104. __le16 eor; /* 2: normally the same as h.eor */
  105. } t;
  106. };
  107. #define LOGPHDRSIZE 8 /* log page header size */
  108. #define LOGPTLRSIZE 8 /* log page trailer size */
  109. /*
  110. * log record
  111. *
  112. * (this comment should be rewritten !)
  113. * jfs uses only "after" log records (only a single writer is allowed
  114. * in a page, pages are written to temporary paging space if
  115. * if they must be written to disk before commit, and i/o is
  116. * scheduled for modified pages to their home location after
  117. * the log records containing the after values and the commit
  118. * record is written to the log on disk, undo discards the copy
  119. * in main-memory.)
  120. *
  121. * a log record consists of a data area of variable length followed by
  122. * a descriptor of fixed size LOGRDSIZE bytes.
  123. * the data area is rounded up to an integral number of 4-bytes and
  124. * must be no longer than LOGPSIZE.
  125. * the descriptor is of size of multiple of 4-bytes and aligned on a
  126. * 4-byte boundary.
  127. * records are packed one after the other in the data area of log pages.
  128. * (sometimes a DUMMY record is inserted so that at least one record ends
  129. * on every page or the longest record is placed on at most two pages).
  130. * the field eor in page header/trailer points to the byte following
  131. * the last record on a page.
  132. */
  133. /* log record types */
  134. #define LOG_COMMIT 0x8000
  135. #define LOG_SYNCPT 0x4000
  136. #define LOG_MOUNT 0x2000
  137. #define LOG_REDOPAGE 0x0800
  138. #define LOG_NOREDOPAGE 0x0080
  139. #define LOG_NOREDOINOEXT 0x0040
  140. #define LOG_UPDATEMAP 0x0008
  141. #define LOG_NOREDOFILE 0x0001
  142. /* REDOPAGE/NOREDOPAGE log record data type */
  143. #define LOG_INODE 0x0001
  144. #define LOG_XTREE 0x0002
  145. #define LOG_DTREE 0x0004
  146. #define LOG_BTROOT 0x0010
  147. #define LOG_EA 0x0020
  148. #define LOG_ACL 0x0040
  149. #define LOG_DATA 0x0080
  150. #define LOG_NEW 0x0100
  151. #define LOG_EXTEND 0x0200
  152. #define LOG_RELOCATE 0x0400
  153. #define LOG_DIR_XTREE 0x0800 /* Xtree is in directory inode */
  154. /* UPDATEMAP log record descriptor type */
  155. #define LOG_ALLOCXADLIST 0x0080
  156. #define LOG_ALLOCPXDLIST 0x0040
  157. #define LOG_ALLOCXAD 0x0020
  158. #define LOG_ALLOCPXD 0x0010
  159. #define LOG_FREEXADLIST 0x0008
  160. #define LOG_FREEPXDLIST 0x0004
  161. #define LOG_FREEXAD 0x0002
  162. #define LOG_FREEPXD 0x0001
  163. struct lrd {
  164. /*
  165. * type independent area
  166. */
  167. __le32 logtid; /* 4: log transaction identifier */
  168. __le32 backchain; /* 4: ptr to prev record of same transaction */
  169. __le16 type; /* 2: record type */
  170. __le16 length; /* 2: length of data in record (in byte) */
  171. __le32 aggregate; /* 4: file system lv/aggregate */
  172. /* (16) */
  173. /*
  174. * type dependent area (20)
  175. */
  176. union {
  177. /*
  178. * COMMIT: commit
  179. *
  180. * transaction commit: no type-dependent information;
  181. */
  182. /*
  183. * REDOPAGE: after-image
  184. *
  185. * apply after-image;
  186. *
  187. * N.B. REDOPAGE, NOREDOPAGE, and UPDATEMAP must be same format;
  188. */
  189. struct {
  190. __le32 fileset; /* 4: fileset number */
  191. __le32 inode; /* 4: inode number */
  192. __le16 type; /* 2: REDOPAGE record type */
  193. __le16 l2linesize; /* 2: log2 of line size */
  194. pxd_t pxd; /* 8: on-disk page pxd */
  195. } redopage; /* (20) */
  196. /*
  197. * NOREDOPAGE: the page is freed
  198. *
  199. * do not apply after-image records which precede this record
  200. * in the log with the same page block number to this page.
  201. *
  202. * N.B. REDOPAGE, NOREDOPAGE, and UPDATEMAP must be same format;
  203. */
  204. struct {
  205. __le32 fileset; /* 4: fileset number */
  206. __le32 inode; /* 4: inode number */
  207. __le16 type; /* 2: NOREDOPAGE record type */
  208. __le16 rsrvd; /* 2: reserved */
  209. pxd_t pxd; /* 8: on-disk page pxd */
  210. } noredopage; /* (20) */
  211. /*
  212. * UPDATEMAP: update block allocation map
  213. *
  214. * either in-line PXD,
  215. * or out-of-line XADLIST;
  216. *
  217. * N.B. REDOPAGE, NOREDOPAGE, and UPDATEMAP must be same format;
  218. */
  219. struct {
  220. __le32 fileset; /* 4: fileset number */
  221. __le32 inode; /* 4: inode number */
  222. __le16 type; /* 2: UPDATEMAP record type */
  223. __le16 nxd; /* 2: number of extents */
  224. pxd_t pxd; /* 8: pxd */
  225. } updatemap; /* (20) */
  226. /*
  227. * NOREDOINOEXT: the inode extent is freed
  228. *
  229. * do not apply after-image records which precede this
  230. * record in the log with the any of the 4 page block
  231. * numbers in this inode extent.
  232. *
  233. * NOTE: The fileset and pxd fields MUST remain in
  234. * the same fields in the REDOPAGE record format.
  235. *
  236. */
  237. struct {
  238. __le32 fileset; /* 4: fileset number */
  239. __le32 iagnum; /* 4: IAG number */
  240. __le32 inoext_idx; /* 4: inode extent index */
  241. pxd_t pxd; /* 8: on-disk page pxd */
  242. } noredoinoext; /* (20) */
  243. /*
  244. * SYNCPT: log sync point
  245. *
  246. * replay log up to syncpt address specified;
  247. */
  248. struct {
  249. __le32 sync; /* 4: syncpt address (0 = here) */
  250. } syncpt;
  251. /*
  252. * MOUNT: file system mount
  253. *
  254. * file system mount: no type-dependent information;
  255. */
  256. /*
  257. * ? FREEXTENT: free specified extent(s)
  258. *
  259. * free specified extent(s) from block allocation map
  260. * N.B.: nextents should be length of data/sizeof(xad_t)
  261. */
  262. struct {
  263. __le32 type; /* 4: FREEXTENT record type */
  264. __le32 nextent; /* 4: number of extents */
  265. /* data: PXD or XAD list */
  266. } freextent;
  267. /*
  268. * ? NOREDOFILE: this file is freed
  269. *
  270. * do not apply records which precede this record in the log
  271. * with the same inode number.
  272. *
  273. * NOREDOFILE must be the first to be written at commit
  274. * (last to be read in logredo()) - it prevents
  275. * replay of preceding updates of all preceding generations
  276. * of the inumber esp. the on-disk inode itself.
  277. */
  278. struct {
  279. __le32 fileset; /* 4: fileset number */
  280. __le32 inode; /* 4: inode number */
  281. } noredofile;
  282. /*
  283. * ? NEWPAGE:
  284. *
  285. * metadata type dependent
  286. */
  287. struct {
  288. __le32 fileset; /* 4: fileset number */
  289. __le32 inode; /* 4: inode number */
  290. __le32 type; /* 4: NEWPAGE record type */
  291. pxd_t pxd; /* 8: on-disk page pxd */
  292. } newpage;
  293. /*
  294. * ? DUMMY: filler
  295. *
  296. * no type-dependent information
  297. */
  298. } log;
  299. }; /* (36) */
  300. #define LOGRDSIZE (sizeof(struct lrd))
  301. /*
  302. * line vector descriptor
  303. */
  304. struct lvd {
  305. __le16 offset;
  306. __le16 length;
  307. };
  308. /*
  309. * log logical volume
  310. */
  311. struct jfs_log {
  312. struct list_head sb_list;/* This is used to sync metadata
  313. * before writing syncpt.
  314. */
  315. struct list_head journal_list; /* Global list */
  316. struct block_device *bdev; /* 4: log lv pointer */
  317. int serial; /* 4: log mount serial number */
  318. s64 base; /* @8: log extent address (inline log ) */
  319. int size; /* 4: log size in log page (in page) */
  320. int l2bsize; /* 4: log2 of bsize */
  321. unsigned long flag; /* 4: flag */
  322. struct lbuf *lbuf_free; /* 4: free lbufs */
  323. wait_queue_head_t free_wait; /* 4: */
  324. /* log write */
  325. int logtid; /* 4: log tid */
  326. int page; /* 4: page number of eol page */
  327. int eor; /* 4: eor of last record in eol page */
  328. struct lbuf *bp; /* 4: current log page buffer */
  329. struct mutex loglock; /* 4: log write serialization lock */
  330. /* syncpt */
  331. int nextsync; /* 4: bytes to write before next syncpt */
  332. int active; /* 4: */
  333. wait_queue_head_t syncwait; /* 4: */
  334. /* commit */
  335. uint cflag; /* 4: */
  336. struct list_head cqueue; /* FIFO commit queue */
  337. struct tblock *flush_tblk; /* tblk we're waiting on for flush */
  338. int gcrtc; /* 4: GC_READY transaction count */
  339. struct tblock *gclrt; /* 4: latest GC_READY transaction */
  340. spinlock_t gclock; /* 4: group commit lock */
  341. int logsize; /* 4: log data area size in byte */
  342. int lsn; /* 4: end-of-log */
  343. int clsn; /* 4: clsn */
  344. int syncpt; /* 4: addr of last syncpt record */
  345. int sync; /* 4: addr from last logsync() */
  346. struct list_head synclist; /* 8: logsynclist anchor */
  347. spinlock_t synclock; /* 4: synclist lock */
  348. struct lbuf *wqueue; /* 4: log pageout queue */
  349. int count; /* 4: count */
  350. uuid_t uuid; /* 16: 128-bit uuid of log device */
  351. int no_integrity; /* 3: flag to disable journaling to disk */
  352. };
  353. /*
  354. * Log flag
  355. */
  356. #define log_INLINELOG 1
  357. #define log_SYNCBARRIER 2
  358. #define log_QUIESCE 3
  359. #define log_FLUSH 4
  360. /*
  361. * group commit flag
  362. */
  363. /* jfs_log */
  364. #define logGC_PAGEOUT 0x00000001
  365. /* tblock/lbuf */
  366. #define tblkGC_QUEUE 0x0001
  367. #define tblkGC_READY 0x0002
  368. #define tblkGC_COMMIT 0x0004
  369. #define tblkGC_COMMITTED 0x0008
  370. #define tblkGC_EOP 0x0010
  371. #define tblkGC_FREE 0x0020
  372. #define tblkGC_LEADER 0x0040
  373. #define tblkGC_ERROR 0x0080
  374. #define tblkGC_LAZY 0x0100 // D230860
  375. #define tblkGC_UNLOCKED 0x0200 // D230860
  376. /*
  377. * log cache buffer header
  378. */
  379. struct lbuf {
  380. struct jfs_log *l_log; /* 4: log associated with buffer */
  381. /*
  382. * data buffer base area
  383. */
  384. uint l_flag; /* 4: pageout control flags */
  385. struct lbuf *l_wqnext; /* 4: write queue link */
  386. struct lbuf *l_freelist; /* 4: freelistlink */
  387. int l_pn; /* 4: log page number */
  388. int l_eor; /* 4: log record eor */
  389. int l_ceor; /* 4: committed log record eor */
  390. s64 l_blkno; /* 8: log page block number */
  391. caddr_t l_ldata; /* 4: data page */
  392. struct page *l_page; /* The page itself */
  393. uint l_offset; /* Offset of l_ldata within the page */
  394. wait_queue_head_t l_ioevent; /* 4: i/o done event */
  395. };
  396. /* Reuse l_freelist for redrive list */
  397. #define l_redrive_next l_freelist
  398. /*
  399. * logsynclist block
  400. *
  401. * common logsyncblk prefix for jbuf_t and tblock
  402. */
  403. struct logsyncblk {
  404. u16 xflag; /* flags */
  405. u16 flag; /* only meaninful in tblock */
  406. lid_t lid; /* lock id */
  407. s32 lsn; /* log sequence number */
  408. struct list_head synclist; /* log sync list link */
  409. };
  410. /*
  411. * logsynclist serialization (per log)
  412. */
  413. #define LOGSYNC_LOCK_INIT(log) spin_lock_init(&(log)->synclock)
  414. #define LOGSYNC_LOCK(log, flags) spin_lock_irqsave(&(log)->synclock, flags)
  415. #define LOGSYNC_UNLOCK(log, flags) \
  416. spin_unlock_irqrestore(&(log)->synclock, flags)
  417. /* compute the difference in bytes of lsn from sync point */
  418. #define logdiff(diff, lsn, log)\
  419. {\
  420. diff = (lsn) - (log)->syncpt;\
  421. if (diff < 0)\
  422. diff += (log)->logsize;\
  423. }
  424. extern int lmLogOpen(struct super_block *sb);
  425. extern int lmLogClose(struct super_block *sb);
  426. extern int lmLogShutdown(struct jfs_log * log);
  427. extern int lmLogInit(struct jfs_log * log);
  428. extern int lmLogFormat(struct jfs_log *log, s64 logAddress, int logSize);
  429. extern int lmGroupCommit(struct jfs_log *, struct tblock *);
  430. extern int jfsIOWait(void *);
  431. extern void jfs_flush_journal(struct jfs_log * log, int wait);
  432. extern void jfs_syncpt(struct jfs_log *log, int hard_sync);
  433. #endif /* _H_JFS_LOGMGR */