123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- #ifndef __XFS_LOG_PRIV_H__
- #define __XFS_LOG_PRIV_H__
- struct xfs_buf;
- struct xlog;
- struct xlog_ticket;
- struct xfs_mount;
- struct xfs_log_callback;
- #define XLOG_ACTIVE_RECOVERY 0x2
- #define XLOG_RECOVERY_NEEDED 0x4
- #define XLOG_IO_ERROR 0x8
- #define XLOG_TAIL_WARN 0x10
- static inline uint xlog_get_client_id(__be32 i)
- {
- return be32_to_cpu(i) >> 24;
- }
- #define XLOG_STATE_ACTIVE 0x0001
- #define XLOG_STATE_WANT_SYNC 0x0002
- #define XLOG_STATE_SYNCING 0x0004
- #define XLOG_STATE_DONE_SYNC 0x0008
- #define XLOG_STATE_DO_CALLBACK \
- 0x0010
- #define XLOG_STATE_CALLBACK 0x0020
- #define XLOG_STATE_DIRTY 0x0040
- #define XLOG_STATE_IOERROR 0x0080
- #define XLOG_STATE_IOABORT 0x0100
- #define XLOG_STATE_ALL 0x7FFF
- #define XLOG_STATE_NOTUSED 0x8000
- #define XLOG_TIC_INITED 0x1
- #define XLOG_TIC_PERM_RESERV 0x2
- #define XLOG_TIC_FLAGS \
- { XLOG_TIC_INITED, "XLOG_TIC_INITED" }, \
- { XLOG_TIC_PERM_RESERV, "XLOG_TIC_PERM_RESERV" }
- #define XLOG_STATE_COVER_IDLE 0
- #define XLOG_STATE_COVER_NEED 1
- #define XLOG_STATE_COVER_DONE 2
- #define XLOG_STATE_COVER_NEED2 3
- #define XLOG_STATE_COVER_DONE2 4
- #define XLOG_COVER_OPS 5
-
- #define XLOG_TIC_LEN_MAX 15
- typedef struct xlog_res {
- uint r_len;
- uint r_type;
- } xlog_res_t;
- typedef struct xlog_ticket {
- struct list_head t_queue;
- struct task_struct *t_task;
- xlog_tid_t t_tid;
- atomic_t t_ref;
- int t_curr_res;
- int t_unit_res;
- char t_ocnt;
- char t_cnt;
- char t_clientid;
- char t_flags;
-
- uint t_res_num;
- uint t_res_num_ophdrs;
- uint t_res_arr_sum;
- uint t_res_o_flow;
- xlog_res_t t_res_arr[XLOG_TIC_LEN_MAX];
- } xlog_ticket_t;
- typedef struct xlog_in_core {
- wait_queue_head_t ic_force_wait;
- wait_queue_head_t ic_write_wait;
- struct xlog_in_core *ic_next;
- struct xlog_in_core *ic_prev;
- struct xfs_buf *ic_bp;
- struct xlog *ic_log;
- int ic_size;
- int ic_offset;
- int ic_bwritecnt;
- unsigned short ic_state;
- char *ic_datap;
-
- spinlock_t ic_callback_lock ____cacheline_aligned_in_smp;
- struct xfs_log_callback *ic_callback;
- struct xfs_log_callback **ic_callback_tail;
-
- atomic_t ic_refcnt ____cacheline_aligned_in_smp;
- xlog_in_core_2_t *ic_data;
- #define ic_header ic_data->hic_header
- } xlog_in_core_t;
- struct xfs_cil;
- struct xfs_cil_ctx {
- struct xfs_cil *cil;
- xfs_lsn_t sequence;
- xfs_lsn_t start_lsn;
- xfs_lsn_t commit_lsn;
- struct xlog_ticket *ticket;
- int nvecs;
- int space_used;
- struct list_head busy_extents;
- struct xfs_log_vec *lv_chain;
- struct xfs_log_callback log_cb;
- struct list_head committing;
- };
- struct xfs_cil {
- struct xlog *xc_log;
- struct list_head xc_cil;
- spinlock_t xc_cil_lock;
- struct rw_semaphore xc_ctx_lock ____cacheline_aligned_in_smp;
- struct xfs_cil_ctx *xc_ctx;
- spinlock_t xc_push_lock ____cacheline_aligned_in_smp;
- xfs_lsn_t xc_push_seq;
- struct list_head xc_committing;
- wait_queue_head_t xc_commit_wait;
- xfs_lsn_t xc_current_sequence;
- struct work_struct xc_push_work;
- } ____cacheline_aligned_in_smp;
- #define XLOG_CIL_SPACE_LIMIT(log) (log->l_logsize >> 3)
- struct xlog_grant_head {
- spinlock_t lock ____cacheline_aligned_in_smp;
- struct list_head waiters;
- atomic64_t grant;
- };
- struct xlog {
-
- struct xfs_mount *l_mp;
- struct xfs_ail *l_ailp;
- struct xfs_cil *l_cilp;
- struct xfs_buf *l_xbuf;
- struct xfs_buftarg *l_targ;
- struct delayed_work l_work;
- uint l_flags;
- uint l_quotaoffs_flag;
- struct list_head *l_buf_cancel_table;
- int l_iclog_hsize;
- int l_iclog_heads;
- uint l_sectBBsize;
- int l_iclog_size;
- int l_iclog_size_log;
- int l_iclog_bufs;
- xfs_daddr_t l_logBBstart;
- int l_logsize;
- int l_logBBsize;
-
- wait_queue_head_t l_flush_wait ____cacheline_aligned_in_smp;
-
- int l_covered_state;
- xlog_in_core_t *l_iclog;
- spinlock_t l_icloglock;
- int l_curr_cycle;
- int l_prev_cycle;
- int l_curr_block;
- int l_prev_block;
-
-
- atomic64_t l_last_sync_lsn ____cacheline_aligned_in_smp;
-
- atomic64_t l_tail_lsn ____cacheline_aligned_in_smp;
- struct xlog_grant_head l_reserve_head;
- struct xlog_grant_head l_write_head;
- struct xfs_kobj l_kobj;
-
- #ifdef DEBUG
- void *l_iclog_bak[XLOG_MAX_ICLOGS];
-
- uint32_t l_badcrc_factor;
- #endif
-
- xfs_lsn_t l_recovery_lsn;
- };
- #define XLOG_BUF_CANCEL_BUCKET(log, blkno) \
- ((log)->l_buf_cancel_table + ((__uint64_t)blkno % XLOG_BC_TABLE_SIZE))
- #define XLOG_FORCED_SHUTDOWN(log) ((log)->l_flags & XLOG_IO_ERROR)
- extern int
- xlog_recover(
- struct xlog *log);
- extern int
- xlog_recover_finish(
- struct xlog *log);
- extern int
- xlog_recover_cancel(struct xlog *);
- extern __le32 xlog_cksum(struct xlog *log, struct xlog_rec_header *rhead,
- char *dp, int size);
- extern kmem_zone_t *xfs_log_ticket_zone;
- struct xlog_ticket *
- xlog_ticket_alloc(
- struct xlog *log,
- int unit_bytes,
- int count,
- char client,
- bool permanent,
- xfs_km_flags_t alloc_flags);
- static inline void
- xlog_write_adv_cnt(void **ptr, int *len, int *off, size_t bytes)
- {
- *ptr += bytes;
- *len -= bytes;
- *off += bytes;
- }
- void xlog_print_tic_res(struct xfs_mount *mp, struct xlog_ticket *ticket);
- int
- xlog_write(
- struct xlog *log,
- struct xfs_log_vec *log_vector,
- struct xlog_ticket *tic,
- xfs_lsn_t *start_lsn,
- struct xlog_in_core **commit_iclog,
- uint flags);
- static inline void
- xlog_crack_atomic_lsn(atomic64_t *lsn, uint *cycle, uint *block)
- {
- xfs_lsn_t val = atomic64_read(lsn);
- *cycle = CYCLE_LSN(val);
- *block = BLOCK_LSN(val);
- }
- static inline void
- xlog_assign_atomic_lsn(atomic64_t *lsn, uint cycle, uint block)
- {
- atomic64_set(lsn, xlog_assign_lsn(cycle, block));
- }
- static inline void
- xlog_crack_grant_head_val(int64_t val, int *cycle, int *space)
- {
- *cycle = val >> 32;
- *space = val & 0xffffffff;
- }
- static inline void
- xlog_crack_grant_head(atomic64_t *head, int *cycle, int *space)
- {
- xlog_crack_grant_head_val(atomic64_read(head), cycle, space);
- }
- static inline int64_t
- xlog_assign_grant_head_val(int cycle, int space)
- {
- return ((int64_t)cycle << 32) | space;
- }
- static inline void
- xlog_assign_grant_head(atomic64_t *head, int cycle, int space)
- {
- atomic64_set(head, xlog_assign_grant_head_val(cycle, space));
- }
- int xlog_cil_init(struct xlog *log);
- void xlog_cil_init_post_recovery(struct xlog *log);
- void xlog_cil_destroy(struct xlog *log);
- bool xlog_cil_empty(struct xlog *log);
- xfs_lsn_t
- xlog_cil_force_lsn(
- struct xlog *log,
- xfs_lsn_t sequence);
- static inline void
- xlog_cil_force(struct xlog *log)
- {
- xlog_cil_force_lsn(log, log->l_cilp->xc_current_sequence);
- }
- #define XLOG_UNMOUNT_REC_TYPE (-1U)
- static inline void xlog_wait(wait_queue_head_t *wq, spinlock_t *lock)
- {
- DECLARE_WAITQUEUE(wait, current);
- add_wait_queue_exclusive(wq, &wait);
- __set_current_state(TASK_UNINTERRUPTIBLE);
- spin_unlock(lock);
- schedule();
- remove_wait_queue(wq, &wait);
- }
- static inline bool
- xlog_valid_lsn(
- struct xlog *log,
- xfs_lsn_t lsn)
- {
- int cur_cycle;
- int cur_block;
- bool valid = true;
-
- cur_cycle = ACCESS_ONCE(log->l_curr_cycle);
- smp_rmb();
- cur_block = ACCESS_ONCE(log->l_curr_block);
- if ((CYCLE_LSN(lsn) > cur_cycle) ||
- (CYCLE_LSN(lsn) == cur_cycle && BLOCK_LSN(lsn) > cur_block)) {
-
- spin_lock(&log->l_icloglock);
- cur_cycle = log->l_curr_cycle;
- cur_block = log->l_curr_block;
- spin_unlock(&log->l_icloglock);
- if ((CYCLE_LSN(lsn) > cur_cycle) ||
- (CYCLE_LSN(lsn) == cur_cycle && BLOCK_LSN(lsn) > cur_block))
- valid = false;
- }
- return valid;
- }
- #endif
|