mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-02 08:34:20 +08:00
[XFS] turn xlog helper macros into real functions
SGI-PV: 946205 SGI-Modid: xfs-linux-melb:xfs-kern:203360a Signed-off-by: Christoph Hellwig <hch@sgi.com> Signed-off-by: Nathan Scott <nathans@sgi.com>
This commit is contained in:
parent
24ee80882d
commit
dd954c69d1
113
fs/xfs/xfs_log.c
113
fs/xfs/xfs_log.c
@ -178,6 +178,83 @@ xlog_trace_iclog(xlog_in_core_t *iclog, uint state)
|
||||
#define xlog_trace_iclog(iclog,state)
|
||||
#endif /* XFS_LOG_TRACE */
|
||||
|
||||
|
||||
static void
|
||||
xlog_ins_ticketq(struct xlog_ticket **qp, struct xlog_ticket *tic)
|
||||
{
|
||||
if (*qp) {
|
||||
tic->t_next = (*qp);
|
||||
tic->t_prev = (*qp)->t_prev;
|
||||
(*qp)->t_prev->t_next = tic;
|
||||
(*qp)->t_prev = tic;
|
||||
} else {
|
||||
tic->t_prev = tic->t_next = tic;
|
||||
*qp = tic;
|
||||
}
|
||||
|
||||
tic->t_flags |= XLOG_TIC_IN_Q;
|
||||
}
|
||||
|
||||
static void
|
||||
xlog_del_ticketq(struct xlog_ticket **qp, struct xlog_ticket *tic)
|
||||
{
|
||||
if (tic == tic->t_next) {
|
||||
*qp = NULL;
|
||||
} else {
|
||||
*qp = tic->t_next;
|
||||
tic->t_next->t_prev = tic->t_prev;
|
||||
tic->t_prev->t_next = tic->t_next;
|
||||
}
|
||||
|
||||
tic->t_next = tic->t_prev = NULL;
|
||||
tic->t_flags &= ~XLOG_TIC_IN_Q;
|
||||
}
|
||||
|
||||
static void
|
||||
xlog_grant_sub_space(struct log *log, int bytes)
|
||||
{
|
||||
log->l_grant_write_bytes -= bytes;
|
||||
if (log->l_grant_write_bytes < 0) {
|
||||
log->l_grant_write_bytes += log->l_logsize;
|
||||
log->l_grant_write_cycle--;
|
||||
}
|
||||
|
||||
log->l_grant_reserve_bytes -= bytes;
|
||||
if ((log)->l_grant_reserve_bytes < 0) {
|
||||
log->l_grant_reserve_bytes += log->l_logsize;
|
||||
log->l_grant_reserve_cycle--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
xlog_grant_add_space_write(struct log *log, int bytes)
|
||||
{
|
||||
log->l_grant_write_bytes += bytes;
|
||||
if (log->l_grant_write_bytes > log->l_logsize) {
|
||||
log->l_grant_write_bytes -= log->l_logsize;
|
||||
log->l_grant_write_cycle++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xlog_grant_add_space_reserve(struct log *log, int bytes)
|
||||
{
|
||||
log->l_grant_reserve_bytes += bytes;
|
||||
if (log->l_grant_reserve_bytes > log->l_logsize) {
|
||||
log->l_grant_reserve_bytes -= log->l_logsize;
|
||||
log->l_grant_reserve_cycle++;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
xlog_grant_add_space(struct log *log, int bytes)
|
||||
{
|
||||
xlog_grant_add_space_write(log, bytes);
|
||||
xlog_grant_add_space_reserve(log, bytes);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* NOTES:
|
||||
*
|
||||
@ -1320,8 +1397,7 @@ xlog_sync(xlog_t *log,
|
||||
|
||||
/* move grant heads by roundoff in sync */
|
||||
s = GRANT_LOCK(log);
|
||||
XLOG_GRANT_ADD_SPACE(log, roundoff, 'w');
|
||||
XLOG_GRANT_ADD_SPACE(log, roundoff, 'r');
|
||||
xlog_grant_add_space(log, roundoff);
|
||||
GRANT_UNLOCK(log, s);
|
||||
|
||||
/* put cycle number in every block */
|
||||
@ -2389,7 +2465,7 @@ xlog_grant_log_space(xlog_t *log,
|
||||
|
||||
/* something is already sleeping; insert new transaction at end */
|
||||
if (log->l_reserve_headq) {
|
||||
XLOG_INS_TICKETQ(log->l_reserve_headq, tic);
|
||||
xlog_ins_ticketq(&log->l_reserve_headq, tic);
|
||||
xlog_trace_loggrant(log, tic,
|
||||
"xlog_grant_log_space: sleep 1");
|
||||
/*
|
||||
@ -2422,7 +2498,7 @@ redo:
|
||||
log->l_grant_reserve_bytes);
|
||||
if (free_bytes < need_bytes) {
|
||||
if ((tic->t_flags & XLOG_TIC_IN_Q) == 0)
|
||||
XLOG_INS_TICKETQ(log->l_reserve_headq, tic);
|
||||
xlog_ins_ticketq(&log->l_reserve_headq, tic);
|
||||
xlog_trace_loggrant(log, tic,
|
||||
"xlog_grant_log_space: sleep 2");
|
||||
XFS_STATS_INC(xs_sleep_logspace);
|
||||
@ -2439,11 +2515,10 @@ redo:
|
||||
s = GRANT_LOCK(log);
|
||||
goto redo;
|
||||
} else if (tic->t_flags & XLOG_TIC_IN_Q)
|
||||
XLOG_DEL_TICKETQ(log->l_reserve_headq, tic);
|
||||
xlog_del_ticketq(&log->l_reserve_headq, tic);
|
||||
|
||||
/* we've got enough space */
|
||||
XLOG_GRANT_ADD_SPACE(log, need_bytes, 'w');
|
||||
XLOG_GRANT_ADD_SPACE(log, need_bytes, 'r');
|
||||
xlog_grant_add_space(log, need_bytes);
|
||||
#ifdef DEBUG
|
||||
tail_lsn = log->l_tail_lsn;
|
||||
/*
|
||||
@ -2464,7 +2539,7 @@ redo:
|
||||
|
||||
error_return:
|
||||
if (tic->t_flags & XLOG_TIC_IN_Q)
|
||||
XLOG_DEL_TICKETQ(log->l_reserve_headq, tic);
|
||||
xlog_del_ticketq(&log->l_reserve_headq, tic);
|
||||
xlog_trace_loggrant(log, tic, "xlog_grant_log_space: err_ret");
|
||||
/*
|
||||
* If we are failing, make sure the ticket doesn't have any
|
||||
@ -2533,7 +2608,7 @@ xlog_regrant_write_log_space(xlog_t *log,
|
||||
|
||||
if (ntic != log->l_write_headq) {
|
||||
if ((tic->t_flags & XLOG_TIC_IN_Q) == 0)
|
||||
XLOG_INS_TICKETQ(log->l_write_headq, tic);
|
||||
xlog_ins_ticketq(&log->l_write_headq, tic);
|
||||
|
||||
xlog_trace_loggrant(log, tic,
|
||||
"xlog_regrant_write_log_space: sleep 1");
|
||||
@ -2565,7 +2640,7 @@ redo:
|
||||
log->l_grant_write_bytes);
|
||||
if (free_bytes < need_bytes) {
|
||||
if ((tic->t_flags & XLOG_TIC_IN_Q) == 0)
|
||||
XLOG_INS_TICKETQ(log->l_write_headq, tic);
|
||||
xlog_ins_ticketq(&log->l_write_headq, tic);
|
||||
XFS_STATS_INC(xs_sleep_logspace);
|
||||
sv_wait(&tic->t_sema, PINOD|PLTWAIT, &log->l_grant_lock, s);
|
||||
|
||||
@ -2581,9 +2656,10 @@ redo:
|
||||
s = GRANT_LOCK(log);
|
||||
goto redo;
|
||||
} else if (tic->t_flags & XLOG_TIC_IN_Q)
|
||||
XLOG_DEL_TICKETQ(log->l_write_headq, tic);
|
||||
xlog_del_ticketq(&log->l_write_headq, tic);
|
||||
|
||||
XLOG_GRANT_ADD_SPACE(log, need_bytes, 'w'); /* we've got enough space */
|
||||
/* we've got enough space */
|
||||
xlog_grant_add_space_write(log, need_bytes);
|
||||
#ifdef DEBUG
|
||||
tail_lsn = log->l_tail_lsn;
|
||||
if (CYCLE_LSN(tail_lsn) != log->l_grant_write_cycle) {
|
||||
@ -2600,7 +2676,7 @@ redo:
|
||||
|
||||
error_return:
|
||||
if (tic->t_flags & XLOG_TIC_IN_Q)
|
||||
XLOG_DEL_TICKETQ(log->l_reserve_headq, tic);
|
||||
xlog_del_ticketq(&log->l_reserve_headq, tic);
|
||||
xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: err_ret");
|
||||
/*
|
||||
* If we are failing, make sure the ticket doesn't have any
|
||||
@ -2633,8 +2709,7 @@ xlog_regrant_reserve_log_space(xlog_t *log,
|
||||
ticket->t_cnt--;
|
||||
|
||||
s = GRANT_LOCK(log);
|
||||
XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'w');
|
||||
XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'r');
|
||||
xlog_grant_sub_space(log, ticket->t_curr_res);
|
||||
ticket->t_curr_res = ticket->t_unit_res;
|
||||
XLOG_TIC_RESET_RES(ticket);
|
||||
xlog_trace_loggrant(log, ticket,
|
||||
@ -2647,7 +2722,7 @@ xlog_regrant_reserve_log_space(xlog_t *log,
|
||||
return;
|
||||
}
|
||||
|
||||
XLOG_GRANT_ADD_SPACE(log, ticket->t_unit_res, 'r');
|
||||
xlog_grant_add_space_reserve(log, ticket->t_unit_res);
|
||||
xlog_trace_loggrant(log, ticket,
|
||||
"xlog_regrant_reserve_log_space: exit");
|
||||
xlog_verify_grant_head(log, 0);
|
||||
@ -2683,8 +2758,7 @@ xlog_ungrant_log_space(xlog_t *log,
|
||||
s = GRANT_LOCK(log);
|
||||
xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: enter");
|
||||
|
||||
XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'w');
|
||||
XLOG_GRANT_SUB_SPACE(log, ticket->t_curr_res, 'r');
|
||||
xlog_grant_sub_space(log, ticket->t_curr_res);
|
||||
|
||||
xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: sub current");
|
||||
|
||||
@ -2693,8 +2767,7 @@ xlog_ungrant_log_space(xlog_t *log,
|
||||
*/
|
||||
if (ticket->t_cnt > 0) {
|
||||
ASSERT(ticket->t_flags & XLOG_TIC_PERM_RESERV);
|
||||
XLOG_GRANT_SUB_SPACE(log, ticket->t_unit_res*ticket->t_cnt,'w');
|
||||
XLOG_GRANT_SUB_SPACE(log, ticket->t_unit_res*ticket->t_cnt,'r');
|
||||
xlog_grant_sub_space(log, ticket->t_unit_res*ticket->t_cnt);
|
||||
}
|
||||
|
||||
xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: exit");
|
||||
|
@ -494,63 +494,6 @@ typedef struct log {
|
||||
|
||||
#define XLOG_FORCED_SHUTDOWN(log) ((log)->l_flags & XLOG_IO_ERROR)
|
||||
|
||||
#define XLOG_GRANT_SUB_SPACE(log,bytes,type) \
|
||||
{ \
|
||||
if (type == 'w') { \
|
||||
(log)->l_grant_write_bytes -= (bytes); \
|
||||
if ((log)->l_grant_write_bytes < 0) { \
|
||||
(log)->l_grant_write_bytes += (log)->l_logsize; \
|
||||
(log)->l_grant_write_cycle--; \
|
||||
} \
|
||||
} else { \
|
||||
(log)->l_grant_reserve_bytes -= (bytes); \
|
||||
if ((log)->l_grant_reserve_bytes < 0) { \
|
||||
(log)->l_grant_reserve_bytes += (log)->l_logsize;\
|
||||
(log)->l_grant_reserve_cycle--; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define XLOG_GRANT_ADD_SPACE(log,bytes,type) \
|
||||
{ \
|
||||
if (type == 'w') { \
|
||||
(log)->l_grant_write_bytes += (bytes); \
|
||||
if ((log)->l_grant_write_bytes > (log)->l_logsize) { \
|
||||
(log)->l_grant_write_bytes -= (log)->l_logsize; \
|
||||
(log)->l_grant_write_cycle++; \
|
||||
} \
|
||||
} else { \
|
||||
(log)->l_grant_reserve_bytes += (bytes); \
|
||||
if ((log)->l_grant_reserve_bytes > (log)->l_logsize) { \
|
||||
(log)->l_grant_reserve_bytes -= (log)->l_logsize;\
|
||||
(log)->l_grant_reserve_cycle++; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define XLOG_INS_TICKETQ(q, tic) \
|
||||
{ \
|
||||
if (q) { \
|
||||
(tic)->t_next = (q); \
|
||||
(tic)->t_prev = (q)->t_prev; \
|
||||
(q)->t_prev->t_next = (tic); \
|
||||
(q)->t_prev = (tic); \
|
||||
} else { \
|
||||
(tic)->t_prev = (tic)->t_next = (tic); \
|
||||
(q) = (tic); \
|
||||
} \
|
||||
(tic)->t_flags |= XLOG_TIC_IN_Q; \
|
||||
}
|
||||
#define XLOG_DEL_TICKETQ(q, tic) \
|
||||
{ \
|
||||
if ((tic) == (tic)->t_next) { \
|
||||
(q) = NULL; \
|
||||
} else { \
|
||||
(q) = (tic)->t_next; \
|
||||
(tic)->t_next->t_prev = (tic)->t_prev; \
|
||||
(tic)->t_prev->t_next = (tic)->t_next; \
|
||||
} \
|
||||
(tic)->t_next = (tic)->t_prev = NULL; \
|
||||
(tic)->t_flags &= ~XLOG_TIC_IN_Q; \
|
||||
}
|
||||
|
||||
/* common routines */
|
||||
extern xfs_lsn_t xlog_assign_tail_lsn(struct xfs_mount *mp);
|
||||
|
Loading…
Reference in New Issue
Block a user