blob: 73a64bf32f6f4a9214bebf2080d4a556ea634d1e [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_LOG_H__
7#define __XFS_LOG_H__
8
Dave Chinnerfc06c6d2013-08-12 20:49:22 +10009struct xfs_log_vec {
10 struct xfs_log_vec *lv_next; /* next lv in build list */
11 int lv_niovecs; /* number of iovecs in lv */
12 struct xfs_log_iovec *lv_iovecp; /* iovec array */
13 struct xfs_log_item *lv_item; /* owner */
14 char *lv_buf; /* formatted buffer */
Dave Chinner110dc242014-05-20 08:18:09 +100015 int lv_bytes; /* accounted space in buffer */
16 int lv_buf_len; /* aligned size of buffer */
Dave Chinner7492c5b2013-08-12 20:50:05 +100017 int lv_size; /* size of allocated lv */
Dave Chinnerfc06c6d2013-08-12 20:49:22 +100018};
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Dave Chinnerfc06c6d2013-08-12 20:49:22 +100020#define XFS_LOG_VEC_ORDERED (-1)
21
Christoph Hellwig12343512013-12-13 11:00:43 +110022static inline void *
Christoph Hellwigbde7cff2013-12-13 11:34:02 +110023xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
24 uint type)
Christoph Hellwig12343512013-12-13 11:00:43 +110025{
26 struct xfs_log_iovec *vec = *vecp;
27
Christoph Hellwigbde7cff2013-12-13 11:34:02 +110028 if (vec) {
29 ASSERT(vec - lv->lv_iovecp < lv->lv_niovecs);
30 vec++;
31 } else {
32 vec = &lv->lv_iovecp[0];
33 }
Christoph Hellwig12343512013-12-13 11:00:43 +110034
Christoph Hellwigbde7cff2013-12-13 11:34:02 +110035 vec->i_type = type;
36 vec->i_addr = lv->lv_buf + lv->lv_buf_len;
37
38 ASSERT(IS_ALIGNED((unsigned long)vec->i_addr, sizeof(uint64_t)));
39
40 *vecp = vec;
Christoph Hellwig12343512013-12-13 11:00:43 +110041 return vec->i_addr;
42}
43
Dave Chinner110dc242014-05-20 08:18:09 +100044/*
45 * We need to make sure the next buffer is naturally aligned for the biggest
46 * basic data type we put into it. We already accounted for this padding when
47 * sizing the buffer.
48 *
49 * However, this padding does not get written into the log, and hence we have to
50 * track the space used by the log vectors separately to prevent log space hangs
51 * due to inaccurate accounting (i.e. a leak) of the used log space through the
52 * CIL context ticket.
53 */
Christoph Hellwigbde7cff2013-12-13 11:34:02 +110054static inline void
55xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, int len)
56{
Christoph Hellwigbde7cff2013-12-13 11:34:02 +110057 lv->lv_buf_len += round_up(len, sizeof(uint64_t));
Dave Chinner110dc242014-05-20 08:18:09 +100058 lv->lv_bytes += len;
Christoph Hellwigbde7cff2013-12-13 11:34:02 +110059 vec->i_len = len;
60}
61
62static inline void *
63xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
64 uint type, void *data, int len)
65{
66 void *buf;
67
68 buf = xlog_prepare_iovec(lv, vecp, type);
69 memcpy(buf, data, len);
70 xlog_finish_iovec(lv, *vecp, len);
71 return buf;
72}
73
Dave Chinnerfc06c6d2013-08-12 20:49:22 +100074/*
75 * Structure used to pass callback function and the function's argument
76 * to the log manager.
77 */
78typedef struct xfs_log_callback {
79 struct xfs_log_callback *cb_next;
80 void (*cb_func)(void *, int);
81 void *cb_arg;
82} xfs_log_callback_t;
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
Nathan Scottc41564b2006-03-29 08:55:14 +100085 * By comparing each component, we don't have to worry about extra
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 * endian issues in treating two 32 bit numbers as one 64 bit number
87 */
Andrew Mortona1365642006-01-08 01:04:09 -080088static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
90 if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
91 return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
92
93 if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
94 return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
95
96 return 0;
97}
98
99#define XFS_LSN_CMP(x,y) _lsn_cmp(x,y)
100
101/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 * Flags to xfs_log_force()
103 *
104 * XFS_LOG_SYNC: Synchronous force in-core log to disk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 */
106#define XFS_LOG_SYNC 0x1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108/* Log manager interfaces */
109struct xfs_mount;
Christoph Hellwig35a8a722010-02-15 23:34:54 +0000110struct xlog_in_core;
Dave Chinnercc09c0d2008-11-17 17:37:10 +1100111struct xlog_ticket;
Dave Chinner43f5efc2010-03-23 10:10:00 +1100112struct xfs_log_item;
113struct xfs_item_ops;
Dave Chinner955833c2010-05-14 21:41:46 +1000114struct xfs_trans;
Christoph Hellwig35a8a722010-02-15 23:34:54 +0000115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116xfs_lsn_t xfs_log_done(struct xfs_mount *mp,
Christoph Hellwig35a8a722010-02-15 23:34:54 +0000117 struct xlog_ticket *ticket,
118 struct xlog_in_core **iclog,
Christoph Hellwigf78c3902015-06-04 13:48:20 +1000119 bool regrant);
Christoph Hellwig60e5bb72018-03-13 23:15:28 -0700120int xfs_log_force(struct xfs_mount *mp, uint flags);
Christoph Hellwig656de4f2018-03-13 23:15:28 -0700121int xfs_log_force_lsn(struct xfs_mount *mp, xfs_lsn_t lsn, uint flags,
122 int *log_forced);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123int xfs_log_mount(struct xfs_mount *mp,
124 struct xfs_buftarg *log_target,
125 xfs_daddr_t start_block,
126 int num_bblocks);
Christoph Hellwig42490232008-08-13 16:49:32 +1000127int xfs_log_mount_finish(struct xfs_mount *mp);
Brian Fosterf0b2efa2015-08-19 09:58:36 +1000128int xfs_log_mount_cancel(struct xfs_mount *);
Christoph Hellwig09a423a2012-02-20 02:31:20 +0000129xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
Christoph Hellwig1c304622012-04-23 15:58:33 +1000130xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
Christoph Hellwigcfb7cdc2012-02-20 02:31:23 +0000131void xfs_log_space_wake(struct xfs_mount *mp);
Eric Sandeena1f69412018-04-06 10:09:42 -0700132int xfs_log_notify(struct xlog_in_core *iclog,
Dave Chinner239880e2013-10-23 10:50:10 +1100133 struct xfs_log_callback *callback_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134int xfs_log_release_iclog(struct xfs_mount *mp,
Christoph Hellwig35a8a722010-02-15 23:34:54 +0000135 struct xlog_in_core *iclog);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136int xfs_log_reserve(struct xfs_mount *mp,
137 int length,
138 int count,
Christoph Hellwig35a8a722010-02-15 23:34:54 +0000139 struct xlog_ticket **ticket,
Darrick J. Wongc8ce5402017-06-16 11:00:05 -0700140 uint8_t clientid,
Christoph Hellwig710b1e22016-04-06 09:20:36 +1000141 bool permanent);
Christoph Hellwig9006fb92012-02-20 02:31:31 +0000142int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
Christoph Hellwig21b699c2009-03-16 08:19:29 +0100143void xfs_log_unmount(struct xfs_mount *mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144int xfs_log_force_umount(struct xfs_mount *mp, int logerror);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Dave Chinner71e330b2010-05-21 14:37:18 +1000146struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
Dave Chinnercc09c0d2008-11-17 17:37:10 +1100147void xfs_log_ticket_put(struct xlog_ticket *ticket);
148
Jie Liuc6f97262014-02-07 15:26:07 +1100149void xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
Christoph Hellwig70393312015-06-04 13:48:08 +1000150 xfs_lsn_t *commit_lsn, bool regrant);
Dave Chinnerccf7c232010-05-20 23:19:42 +1000151bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
Dave Chinner71e330b2010-05-21 14:37:18 +1000152
Dave Chinnerf661f1e2012-10-08 21:56:02 +1100153void xfs_log_work_queue(struct xfs_mount *mp);
Dave Chinnerc75921a2012-10-08 21:56:08 +1100154void xfs_log_quiesce(struct xfs_mount *mp);
Brian Fostera45086e2015-10-12 15:59:25 +1100155bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
Darrick J. Wong0c60d3a2018-08-01 07:40:48 -0700156bool xfs_log_in_recovery(struct xfs_mount *);
Dave Chinnerf661f1e2012-10-08 21:56:02 +1100157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158#endif /* __XFS_LOG_H__ */