2018-06-05 20:42:14 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2005-11-01 20:58:39 -07:00
|
|
|
* Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_LOG_H__
|
|
|
|
#define __XFS_LOG_H__
|
|
|
|
|
2013-08-12 04:49:22 -06:00
|
|
|
struct xfs_log_vec {
|
|
|
|
struct xfs_log_vec *lv_next; /* next lv in build list */
|
|
|
|
int lv_niovecs; /* number of iovecs in lv */
|
|
|
|
struct xfs_log_iovec *lv_iovecp; /* iovec array */
|
|
|
|
struct xfs_log_item *lv_item; /* owner */
|
|
|
|
char *lv_buf; /* formatted buffer */
|
2014-05-19 16:18:09 -06:00
|
|
|
int lv_bytes; /* accounted space in buffer */
|
|
|
|
int lv_buf_len; /* aligned size of buffer */
|
2013-08-12 04:50:05 -06:00
|
|
|
int lv_size; /* size of allocated lv */
|
2013-08-12 04:49:22 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#define XFS_LOG_VEC_ORDERED (-1)
|
|
|
|
|
2013-12-12 17:00:43 -07:00
|
|
|
static inline void *
|
2013-12-12 17:34:02 -07:00
|
|
|
xlog_prepare_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
|
|
|
|
uint type)
|
2013-12-12 17:00:43 -07:00
|
|
|
{
|
|
|
|
struct xfs_log_iovec *vec = *vecp;
|
|
|
|
|
2013-12-12 17:34:02 -07:00
|
|
|
if (vec) {
|
|
|
|
ASSERT(vec - lv->lv_iovecp < lv->lv_niovecs);
|
|
|
|
vec++;
|
|
|
|
} else {
|
|
|
|
vec = &lv->lv_iovecp[0];
|
|
|
|
}
|
|
|
|
|
2013-12-12 17:00:43 -07:00
|
|
|
vec->i_type = type;
|
2013-12-12 17:34:02 -07:00
|
|
|
vec->i_addr = lv->lv_buf + lv->lv_buf_len;
|
|
|
|
|
|
|
|
ASSERT(IS_ALIGNED((unsigned long)vec->i_addr, sizeof(uint64_t)));
|
2013-12-12 17:00:43 -07:00
|
|
|
|
2013-12-12 17:34:02 -07:00
|
|
|
*vecp = vec;
|
2013-12-12 17:00:43 -07:00
|
|
|
return vec->i_addr;
|
|
|
|
}
|
|
|
|
|
2014-05-19 16:18:09 -06:00
|
|
|
/*
|
|
|
|
* We need to make sure the next buffer is naturally aligned for the biggest
|
|
|
|
* basic data type we put into it. We already accounted for this padding when
|
|
|
|
* sizing the buffer.
|
|
|
|
*
|
|
|
|
* However, this padding does not get written into the log, and hence we have to
|
|
|
|
* track the space used by the log vectors separately to prevent log space hangs
|
|
|
|
* due to inaccurate accounting (i.e. a leak) of the used log space through the
|
|
|
|
* CIL context ticket.
|
|
|
|
*/
|
2013-12-12 17:34:02 -07:00
|
|
|
static inline void
|
|
|
|
xlog_finish_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec *vec, int len)
|
|
|
|
{
|
|
|
|
lv->lv_buf_len += round_up(len, sizeof(uint64_t));
|
2014-05-19 16:18:09 -06:00
|
|
|
lv->lv_bytes += len;
|
2013-12-12 17:34:02 -07:00
|
|
|
vec->i_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
xlog_copy_iovec(struct xfs_log_vec *lv, struct xfs_log_iovec **vecp,
|
|
|
|
uint type, void *data, int len)
|
|
|
|
{
|
|
|
|
void *buf;
|
|
|
|
|
|
|
|
buf = xlog_prepare_iovec(lv, vecp, type);
|
|
|
|
memcpy(buf, data, len);
|
|
|
|
xlog_finish_iovec(lv, *vecp, len);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2013-08-12 04:49:22 -06:00
|
|
|
/*
|
|
|
|
* Structure used to pass callback function and the function's argument
|
|
|
|
* to the log manager.
|
|
|
|
*/
|
|
|
|
typedef struct xfs_log_callback {
|
|
|
|
struct xfs_log_callback *cb_next;
|
|
|
|
void (*cb_func)(void *, int);
|
|
|
|
void *cb_arg;
|
|
|
|
} xfs_log_callback_t;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
2006-03-28 15:55:14 -07:00
|
|
|
* By comparing each component, we don't have to worry about extra
|
2005-04-16 16:20:36 -06:00
|
|
|
* endian issues in treating two 32 bit numbers as one 64 bit number
|
|
|
|
*/
|
2006-01-08 02:04:09 -07:00
|
|
|
static inline xfs_lsn_t _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
if (CYCLE_LSN(lsn1) != CYCLE_LSN(lsn2))
|
|
|
|
return (CYCLE_LSN(lsn1)<CYCLE_LSN(lsn2))? -999 : 999;
|
|
|
|
|
|
|
|
if (BLOCK_LSN(lsn1) != BLOCK_LSN(lsn2))
|
|
|
|
return (BLOCK_LSN(lsn1)<BLOCK_LSN(lsn2))? -999 : 999;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define XFS_LSN_CMP(x,y) _lsn_cmp(x,y)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flags to xfs_log_force()
|
|
|
|
*
|
|
|
|
* XFS_LOG_SYNC: Synchronous force in-core log to disk
|
|
|
|
*/
|
|
|
|
#define XFS_LOG_SYNC 0x1
|
|
|
|
|
|
|
|
/* Log manager interfaces */
|
|
|
|
struct xfs_mount;
|
2010-02-15 16:34:54 -07:00
|
|
|
struct xlog_in_core;
|
2008-11-16 23:37:10 -07:00
|
|
|
struct xlog_ticket;
|
2010-03-22 17:10:00 -06:00
|
|
|
struct xfs_log_item;
|
|
|
|
struct xfs_item_ops;
|
2010-05-14 05:41:46 -06:00
|
|
|
struct xfs_trans;
|
2010-02-15 16:34:54 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
xfs_lsn_t xfs_log_done(struct xfs_mount *mp,
|
2010-02-15 16:34:54 -07:00
|
|
|
struct xlog_ticket *ticket,
|
|
|
|
struct xlog_in_core **iclog,
|
2015-06-03 21:48:20 -06:00
|
|
|
bool regrant);
|
2018-03-14 00:15:28 -06:00
|
|
|
int xfs_log_force(struct xfs_mount *mp, uint flags);
|
2018-03-14 00:15:28 -06:00
|
|
|
int xfs_log_force_lsn(struct xfs_mount *mp, xfs_lsn_t lsn, uint flags,
|
|
|
|
int *log_forced);
|
2005-04-16 16:20:36 -06:00
|
|
|
int xfs_log_mount(struct xfs_mount *mp,
|
|
|
|
struct xfs_buftarg *log_target,
|
|
|
|
xfs_daddr_t start_block,
|
|
|
|
int num_bblocks);
|
2008-08-13 00:49:32 -06:00
|
|
|
int xfs_log_mount_finish(struct xfs_mount *mp);
|
2015-08-18 17:58:36 -06:00
|
|
|
int xfs_log_mount_cancel(struct xfs_mount *);
|
2012-02-19 19:31:20 -07:00
|
|
|
xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
|
2012-04-22 23:58:33 -06:00
|
|
|
xfs_lsn_t xlog_assign_tail_lsn_locked(struct xfs_mount *mp);
|
2012-02-19 19:31:23 -07:00
|
|
|
void xfs_log_space_wake(struct xfs_mount *mp);
|
2018-04-06 11:09:42 -06:00
|
|
|
int xfs_log_notify(struct xlog_in_core *iclog,
|
2013-10-22 17:50:10 -06:00
|
|
|
struct xfs_log_callback *callback_entry);
|
2005-04-16 16:20:36 -06:00
|
|
|
int xfs_log_release_iclog(struct xfs_mount *mp,
|
2010-02-15 16:34:54 -07:00
|
|
|
struct xlog_in_core *iclog);
|
2005-04-16 16:20:36 -06:00
|
|
|
int xfs_log_reserve(struct xfs_mount *mp,
|
|
|
|
int length,
|
|
|
|
int count,
|
2010-02-15 16:34:54 -07:00
|
|
|
struct xlog_ticket **ticket,
|
2017-06-16 12:00:05 -06:00
|
|
|
uint8_t clientid,
|
2016-04-05 17:20:36 -06:00
|
|
|
bool permanent);
|
2012-02-19 19:31:31 -07:00
|
|
|
int xfs_log_regrant(struct xfs_mount *mp, struct xlog_ticket *tic);
|
2009-03-16 01:19:29 -06:00
|
|
|
void xfs_log_unmount(struct xfs_mount *mp);
|
2005-04-16 16:20:36 -06:00
|
|
|
int xfs_log_force_umount(struct xfs_mount *mp, int logerror);
|
|
|
|
|
xfs: Introduce delayed logging core code
The delayed logging code only changes in-memory structures and as
such can be enabled and disabled with a mount option. Add the mount
option and emit a warning that this is an experimental feature that
should not be used in production yet.
We also need infrastructure to track committed items that have not
yet been written to the log. This is what the Committed Item List
(CIL) is for.
The log item also needs to be extended to track the current log
vector, the associated memory buffer and it's location in the Commit
Item List. Extend the log item and log vector structures to enable
this tracking.
To maintain the current log format for transactions with delayed
logging, we need to introduce a checkpoint transaction and a context
for tracking each checkpoint from initiation to transaction
completion. This includes adding a log ticket for tracking space
log required/used by the context checkpoint.
To track all the changes we need an io vector array per log item,
rather than a single array for the entire transaction. Using the new
log vector structure for this requires two passes - the first to
allocate the log vector structures and chain them together, and the
second to fill them out. This log vector chain can then be passed
to the CIL for formatting, pinning and insertion into the CIL.
Formatting of the log vector chain is relatively simple - it's just
a loop over the iovecs on each log vector, but it is made slightly
more complex because we re-write the iovec after the copy to point
back at the memory buffer we just copied into.
This code also needs to pin log items. If the log item is not
already tracked in this checkpoint context, then it needs to be
pinned. Otherwise it is already pinned and we don't need to pin it
again.
The only other complexity is calculating the amount of new log space
the formatting has consumed. This needs to be accounted to the
transaction in progress, and the accounting is made more complex
becase we need also to steal space from it for log metadata in the
checkpoint transaction. Calculate all this at insert time and update
all the tickets, counters, etc correctly.
Once we've formatted all the log items in the transaction, attach
the busy extents to the checkpoint context so the busy extents live
until checkpoint completion and can be processed at that point in
time. Transactions can then be freed at this point in time.
Now we need to issue checkpoints - we are tracking the amount of log space
used by the items in the CIL, so we can trigger background checkpoints when the
space usage gets to a certain threshold. Otherwise, checkpoints need ot be
triggered when a log synchronisation point is reached - a log force event.
Because the log write code already handles chained log vectors, writing the
transaction is trivial, too. Construct a transaction header, add it
to the head of the chain and write it into the log, then issue a
commit record write. Then we can release the checkpoint log ticket
and attach the context to the log buffer so it can be called during
Io completion to complete the checkpoint.
We also need to allow for synchronising multiple in-flight
checkpoints. This is needed for two things - the first is to ensure
that checkpoint commit records appear in the log in the correct
sequence order (so they are replayed in the correct order). The
second is so that xfs_log_force_lsn() operates correctly and only
flushes and/or waits for the specific sequence it was provided with.
To do this we need a wait variable and a list tracking the
checkpoint commits in progress. We can walk this list and wait for
the checkpoints to change state or complete easily, an this provides
the necessary synchronisation for correct operation in both cases.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
2010-05-20 22:37:18 -06:00
|
|
|
struct xlog_ticket *xfs_log_ticket_get(struct xlog_ticket *ticket);
|
2008-11-16 23:37:10 -07:00
|
|
|
void xfs_log_ticket_put(struct xlog_ticket *ticket);
|
|
|
|
|
2014-02-06 21:26:07 -07:00
|
|
|
void xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
|
2015-06-03 21:48:08 -06:00
|
|
|
xfs_lsn_t *commit_lsn, bool regrant);
|
2010-05-20 07:19:42 -06:00
|
|
|
bool xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
|
xfs: Introduce delayed logging core code
The delayed logging code only changes in-memory structures and as
such can be enabled and disabled with a mount option. Add the mount
option and emit a warning that this is an experimental feature that
should not be used in production yet.
We also need infrastructure to track committed items that have not
yet been written to the log. This is what the Committed Item List
(CIL) is for.
The log item also needs to be extended to track the current log
vector, the associated memory buffer and it's location in the Commit
Item List. Extend the log item and log vector structures to enable
this tracking.
To maintain the current log format for transactions with delayed
logging, we need to introduce a checkpoint transaction and a context
for tracking each checkpoint from initiation to transaction
completion. This includes adding a log ticket for tracking space
log required/used by the context checkpoint.
To track all the changes we need an io vector array per log item,
rather than a single array for the entire transaction. Using the new
log vector structure for this requires two passes - the first to
allocate the log vector structures and chain them together, and the
second to fill them out. This log vector chain can then be passed
to the CIL for formatting, pinning and insertion into the CIL.
Formatting of the log vector chain is relatively simple - it's just
a loop over the iovecs on each log vector, but it is made slightly
more complex because we re-write the iovec after the copy to point
back at the memory buffer we just copied into.
This code also needs to pin log items. If the log item is not
already tracked in this checkpoint context, then it needs to be
pinned. Otherwise it is already pinned and we don't need to pin it
again.
The only other complexity is calculating the amount of new log space
the formatting has consumed. This needs to be accounted to the
transaction in progress, and the accounting is made more complex
becase we need also to steal space from it for log metadata in the
checkpoint transaction. Calculate all this at insert time and update
all the tickets, counters, etc correctly.
Once we've formatted all the log items in the transaction, attach
the busy extents to the checkpoint context so the busy extents live
until checkpoint completion and can be processed at that point in
time. Transactions can then be freed at this point in time.
Now we need to issue checkpoints - we are tracking the amount of log space
used by the items in the CIL, so we can trigger background checkpoints when the
space usage gets to a certain threshold. Otherwise, checkpoints need ot be
triggered when a log synchronisation point is reached - a log force event.
Because the log write code already handles chained log vectors, writing the
transaction is trivial, too. Construct a transaction header, add it
to the head of the chain and write it into the log, then issue a
commit record write. Then we can release the checkpoint log ticket
and attach the context to the log buffer so it can be called during
Io completion to complete the checkpoint.
We also need to allow for synchronising multiple in-flight
checkpoints. This is needed for two things - the first is to ensure
that checkpoint commit records appear in the log in the correct
sequence order (so they are replayed in the correct order). The
second is so that xfs_log_force_lsn() operates correctly and only
flushes and/or waits for the specific sequence it was provided with.
To do this we need a wait variable and a list tracking the
checkpoint commits in progress. We can walk this list and wait for
the checkpoints to change state or complete easily, an this provides
the necessary synchronisation for correct operation in both cases.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
2010-05-20 22:37:18 -06:00
|
|
|
|
2012-10-08 04:56:02 -06:00
|
|
|
void xfs_log_work_queue(struct xfs_mount *mp);
|
2012-10-08 04:56:08 -06:00
|
|
|
void xfs_log_quiesce(struct xfs_mount *mp);
|
2015-10-11 22:59:25 -06:00
|
|
|
bool xfs_log_check_lsn(struct xfs_mount *, xfs_lsn_t);
|
2012-10-08 04:56:02 -06:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif /* __XFS_LOG_H__ */
|