123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- #include "xfs.h"
- #include "xfs_fs.h"
- #include "xfs_format.h"
- #include "xfs_log_format.h"
- #include "xfs_trans_resv.h"
- #include "xfs_mount.h"
- #include "xfs_inode.h"
- #include "xfs_quota.h"
- #include "xfs_error.h"
- #include "xfs_trans.h"
- #include "xfs_buf_item.h"
- #include "xfs_trans_priv.h"
- #include "xfs_qm.h"
- #include "xfs_log.h"
- static inline struct xfs_dq_logitem *DQUOT_ITEM(struct xfs_log_item *lip)
- {
- return container_of(lip, struct xfs_dq_logitem, qli_item);
- }
- STATIC void
- xfs_qm_dquot_logitem_size(
- struct xfs_log_item *lip,
- int *nvecs,
- int *nbytes)
- {
- *nvecs += 2;
- *nbytes += sizeof(struct xfs_dq_logformat) +
- sizeof(struct xfs_disk_dquot);
- }
- STATIC void
- xfs_qm_dquot_logitem_format(
- struct xfs_log_item *lip,
- struct xfs_log_vec *lv)
- {
- struct xfs_dq_logitem *qlip = DQUOT_ITEM(lip);
- struct xfs_log_iovec *vecp = NULL;
- struct xfs_dq_logformat *qlf;
- qlf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_QFORMAT);
- qlf->qlf_type = XFS_LI_DQUOT;
- qlf->qlf_size = 2;
- qlf->qlf_id = be32_to_cpu(qlip->qli_dquot->q_core.d_id);
- qlf->qlf_blkno = qlip->qli_dquot->q_blkno;
- qlf->qlf_len = 1;
- qlf->qlf_boffset = qlip->qli_dquot->q_bufoffset;
- xlog_finish_iovec(lv, vecp, sizeof(struct xfs_dq_logformat));
- xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_DQUOT,
- &qlip->qli_dquot->q_core,
- sizeof(struct xfs_disk_dquot));
- }
- STATIC void
- xfs_qm_dquot_logitem_pin(
- struct xfs_log_item *lip)
- {
- struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
- ASSERT(XFS_DQ_IS_LOCKED(dqp));
- atomic_inc(&dqp->q_pincount);
- }
- STATIC void
- xfs_qm_dquot_logitem_unpin(
- struct xfs_log_item *lip,
- int remove)
- {
- struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
- ASSERT(atomic_read(&dqp->q_pincount) > 0);
- if (atomic_dec_and_test(&dqp->q_pincount))
- wake_up(&dqp->q_pinwait);
- }
- STATIC xfs_lsn_t
- xfs_qm_dquot_logitem_committed(
- struct xfs_log_item *lip,
- xfs_lsn_t lsn)
- {
-
- return lsn;
- }
- void
- xfs_qm_dqunpin_wait(
- struct xfs_dquot *dqp)
- {
- ASSERT(XFS_DQ_IS_LOCKED(dqp));
- if (atomic_read(&dqp->q_pincount) == 0)
- return;
-
- xfs_log_force(dqp->q_mount, 0);
- wait_event(dqp->q_pinwait, (atomic_read(&dqp->q_pincount) == 0));
- }
- STATIC void
- xfs_dquot_item_error(
- struct xfs_log_item *lip,
- struct xfs_buf *bp)
- {
- struct xfs_dquot *dqp;
- dqp = DQUOT_ITEM(lip)->qli_dquot;
- ASSERT(!completion_done(&dqp->q_flush));
- xfs_set_li_failed(lip, bp);
- }
- STATIC uint
- xfs_qm_dquot_logitem_push(
- struct xfs_log_item *lip,
- struct list_head *buffer_list) __releases(&lip->li_ailp->xa_lock)
- __acquires(&lip->li_ailp->xa_lock)
- {
- struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
- struct xfs_buf *bp = lip->li_buf;
- uint rval = XFS_ITEM_SUCCESS;
- int error;
- if (atomic_read(&dqp->q_pincount) > 0)
- return XFS_ITEM_PINNED;
-
- if (lip->li_flags & XFS_LI_FAILED) {
- if (!xfs_buf_trylock(bp))
- return XFS_ITEM_LOCKED;
- if (!xfs_buf_resubmit_failed_buffers(bp, lip, buffer_list))
- rval = XFS_ITEM_FLUSHING;
- xfs_buf_unlock(bp);
- return rval;
- }
- if (!xfs_dqlock_nowait(dqp))
- return XFS_ITEM_LOCKED;
-
- if (atomic_read(&dqp->q_pincount) > 0) {
- rval = XFS_ITEM_PINNED;
- goto out_unlock;
- }
-
- if (!xfs_dqflock_nowait(dqp)) {
- rval = XFS_ITEM_FLUSHING;
- goto out_unlock;
- }
- spin_unlock(&lip->li_ailp->xa_lock);
- error = xfs_qm_dqflush(dqp, &bp);
- if (error) {
- xfs_warn(dqp->q_mount, "%s: push error %d on dqp %p",
- __func__, error, dqp);
- } else {
- if (!xfs_buf_delwri_queue(bp, buffer_list))
- rval = XFS_ITEM_FLUSHING;
- xfs_buf_relse(bp);
- }
- spin_lock(&lip->li_ailp->xa_lock);
- out_unlock:
- xfs_dqunlock(dqp);
- return rval;
- }
- STATIC void
- xfs_qm_dquot_logitem_unlock(
- struct xfs_log_item *lip)
- {
- struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot;
- ASSERT(XFS_DQ_IS_LOCKED(dqp));
-
- dqp->q_transp = NULL;
-
- xfs_dqunlock(dqp);
- }
- STATIC void
- xfs_qm_dquot_logitem_committing(
- struct xfs_log_item *lip,
- xfs_lsn_t lsn)
- {
- }
- static const struct xfs_item_ops xfs_dquot_item_ops = {
- .iop_size = xfs_qm_dquot_logitem_size,
- .iop_format = xfs_qm_dquot_logitem_format,
- .iop_pin = xfs_qm_dquot_logitem_pin,
- .iop_unpin = xfs_qm_dquot_logitem_unpin,
- .iop_unlock = xfs_qm_dquot_logitem_unlock,
- .iop_committed = xfs_qm_dquot_logitem_committed,
- .iop_push = xfs_qm_dquot_logitem_push,
- .iop_committing = xfs_qm_dquot_logitem_committing,
- .iop_error = xfs_dquot_item_error
- };
- void
- xfs_qm_dquot_logitem_init(
- struct xfs_dquot *dqp)
- {
- struct xfs_dq_logitem *lp = &dqp->q_logitem;
- xfs_log_item_init(dqp->q_mount, &lp->qli_item, XFS_LI_DQUOT,
- &xfs_dquot_item_ops);
- lp->qli_dquot = dqp;
- }
- static inline struct xfs_qoff_logitem *QOFF_ITEM(struct xfs_log_item *lip)
- {
- return container_of(lip, struct xfs_qoff_logitem, qql_item);
- }
- STATIC void
- xfs_qm_qoff_logitem_size(
- struct xfs_log_item *lip,
- int *nvecs,
- int *nbytes)
- {
- *nvecs += 1;
- *nbytes += sizeof(struct xfs_qoff_logitem);
- }
- STATIC void
- xfs_qm_qoff_logitem_format(
- struct xfs_log_item *lip,
- struct xfs_log_vec *lv)
- {
- struct xfs_qoff_logitem *qflip = QOFF_ITEM(lip);
- struct xfs_log_iovec *vecp = NULL;
- struct xfs_qoff_logformat *qlf;
- qlf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_QUOTAOFF);
- qlf->qf_type = XFS_LI_QUOTAOFF;
- qlf->qf_size = 1;
- qlf->qf_flags = qflip->qql_flags;
- xlog_finish_iovec(lv, vecp, sizeof(struct xfs_qoff_logitem));
- }
- STATIC void
- xfs_qm_qoff_logitem_pin(
- struct xfs_log_item *lip)
- {
- }
- STATIC void
- xfs_qm_qoff_logitem_unpin(
- struct xfs_log_item *lip,
- int remove)
- {
- }
- STATIC uint
- xfs_qm_qoff_logitem_push(
- struct xfs_log_item *lip,
- struct list_head *buffer_list)
- {
- return XFS_ITEM_LOCKED;
- }
- STATIC void
- xfs_qm_qoff_logitem_unlock(
- struct xfs_log_item *lip)
- {
- }
- STATIC xfs_lsn_t
- xfs_qm_qoff_logitem_committed(
- struct xfs_log_item *lip,
- xfs_lsn_t lsn)
- {
- return lsn;
- }
- STATIC xfs_lsn_t
- xfs_qm_qoffend_logitem_committed(
- struct xfs_log_item *lip,
- xfs_lsn_t lsn)
- {
- struct xfs_qoff_logitem *qfe = QOFF_ITEM(lip);
- struct xfs_qoff_logitem *qfs = qfe->qql_start_lip;
- struct xfs_ail *ailp = qfs->qql_item.li_ailp;
-
- spin_lock(&ailp->xa_lock);
- xfs_trans_ail_delete(ailp, &qfs->qql_item, SHUTDOWN_LOG_IO_ERROR);
- kmem_free(qfs->qql_item.li_lv_shadow);
- kmem_free(lip->li_lv_shadow);
- kmem_free(qfs);
- kmem_free(qfe);
- return (xfs_lsn_t)-1;
- }
- STATIC void
- xfs_qm_qoff_logitem_committing(
- struct xfs_log_item *lip,
- xfs_lsn_t commit_lsn)
- {
- }
- static const struct xfs_item_ops xfs_qm_qoffend_logitem_ops = {
- .iop_size = xfs_qm_qoff_logitem_size,
- .iop_format = xfs_qm_qoff_logitem_format,
- .iop_pin = xfs_qm_qoff_logitem_pin,
- .iop_unpin = xfs_qm_qoff_logitem_unpin,
- .iop_unlock = xfs_qm_qoff_logitem_unlock,
- .iop_committed = xfs_qm_qoffend_logitem_committed,
- .iop_push = xfs_qm_qoff_logitem_push,
- .iop_committing = xfs_qm_qoff_logitem_committing
- };
- static const struct xfs_item_ops xfs_qm_qoff_logitem_ops = {
- .iop_size = xfs_qm_qoff_logitem_size,
- .iop_format = xfs_qm_qoff_logitem_format,
- .iop_pin = xfs_qm_qoff_logitem_pin,
- .iop_unpin = xfs_qm_qoff_logitem_unpin,
- .iop_unlock = xfs_qm_qoff_logitem_unlock,
- .iop_committed = xfs_qm_qoff_logitem_committed,
- .iop_push = xfs_qm_qoff_logitem_push,
- .iop_committing = xfs_qm_qoff_logitem_committing
- };
- struct xfs_qoff_logitem *
- xfs_qm_qoff_logitem_init(
- struct xfs_mount *mp,
- struct xfs_qoff_logitem *start,
- uint flags)
- {
- struct xfs_qoff_logitem *qf;
- qf = kmem_zalloc(sizeof(struct xfs_qoff_logitem), KM_SLEEP);
- xfs_log_item_init(mp, &qf->qql_item, XFS_LI_QUOTAOFF, start ?
- &xfs_qm_qoffend_logitem_ops : &xfs_qm_qoff_logitem_ops);
- qf->qql_item.li_mountp = mp;
- qf->qql_start_lip = start;
- qf->qql_flags = flags;
- return qf;
- }
|