Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2000-2003 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "xfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "xfs_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "xfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "xfs_quota.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "xfs_trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "xfs_buf_item.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "xfs_trans_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "xfs_qm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "xfs_log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static inline struct xfs_dq_logitem *DQUOT_ITEM(struct xfs_log_item *lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	return container_of(lip, struct xfs_dq_logitem, qli_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * returns the number of iovecs needed to log the given dquot item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) xfs_qm_dquot_logitem_size(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int			*nvecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	int			*nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	*nvecs += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	*nbytes += sizeof(struct xfs_dq_logformat) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		   sizeof(struct xfs_disk_dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * fills in the vector of log iovecs for the given dquot log item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) xfs_qm_dquot_logitem_format(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct xfs_log_vec	*lv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct xfs_disk_dquot	ddq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct xfs_dq_logitem	*qlip = DQUOT_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	struct xfs_log_iovec	*vecp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	struct xfs_dq_logformat	*qlf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	qlf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_QFORMAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	qlf->qlf_type = XFS_LI_DQUOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	qlf->qlf_size = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	qlf->qlf_id = qlip->qli_dquot->q_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	qlf->qlf_blkno = qlip->qli_dquot->q_blkno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	qlf->qlf_len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	qlf->qlf_boffset = qlip->qli_dquot->q_bufoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	xlog_finish_iovec(lv, vecp, sizeof(struct xfs_dq_logformat));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	xfs_dquot_to_disk(&ddq, qlip->qli_dquot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_DQUOT, &ddq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			sizeof(struct xfs_disk_dquot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69)  * Increment the pin count of the given dquot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) xfs_qm_dquot_logitem_pin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct xfs_log_item	*lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct xfs_dquot	*dqp = DQUOT_ITEM(lip)->qli_dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	ASSERT(XFS_DQ_IS_LOCKED(dqp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	atomic_inc(&dqp->q_pincount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82)  * Decrement the pin count of the given dquot, and wake up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * anyone in xfs_dqwait_unpin() if the count goes to 0.	 The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * dquot must have been previously pinned with a call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * xfs_qm_dquot_logitem_pin().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) xfs_qm_dquot_logitem_unpin(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	int			remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct xfs_dquot	*dqp = DQUOT_ITEM(lip)->qli_dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	ASSERT(atomic_read(&dqp->q_pincount) > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (atomic_dec_and_test(&dqp->q_pincount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		wake_up(&dqp->q_pinwait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  * This is called to wait for the given dquot to be unpinned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * Most of these pin/unpin routines are plagiarized from inode code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) xfs_qm_dqunpin_wait(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct xfs_dquot	*dqp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	ASSERT(XFS_DQ_IS_LOCKED(dqp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	if (atomic_read(&dqp->q_pincount) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	 * Give the log a push so we don't wait here too long.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	xfs_log_force(dqp->q_mount, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	wait_event(dqp->q_pinwait, (atomic_read(&dqp->q_pincount) == 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) STATIC uint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) xfs_qm_dquot_logitem_push(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct list_head	*buffer_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		__releases(&lip->li_ailp->ail_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		__acquires(&lip->li_ailp->ail_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct xfs_dquot	*dqp = DQUOT_ITEM(lip)->qli_dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct xfs_buf		*bp = lip->li_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	uint			rval = XFS_ITEM_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (atomic_read(&dqp->q_pincount) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		return XFS_ITEM_PINNED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (!xfs_dqlock_nowait(dqp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return XFS_ITEM_LOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * Re-check the pincount now that we stabilized the value by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 * taking the quota lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (atomic_read(&dqp->q_pincount) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		rval = XFS_ITEM_PINNED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * Someone else is already flushing the dquot.  Nothing we can do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * here but wait for the flush to finish and remove the item from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 * the AIL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	if (!xfs_dqflock_nowait(dqp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		rval = XFS_ITEM_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	spin_unlock(&lip->li_ailp->ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	error = xfs_qm_dqflush(dqp, &bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (!error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		if (!xfs_buf_delwri_queue(bp, buffer_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			rval = XFS_ITEM_FLUSHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		xfs_buf_relse(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	} else if (error == -EAGAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		rval = XFS_ITEM_LOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	spin_lock(&lip->li_ailp->ail_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	xfs_dqunlock(dqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return rval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) xfs_qm_dquot_logitem_release(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct xfs_log_item	*lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct xfs_dquot	*dqp = DQUOT_ITEM(lip)->qli_dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	ASSERT(XFS_DQ_IS_LOCKED(dqp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	 * dquots are never 'held' from getting unlocked at the end of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * a transaction.  Their locking and unlocking is hidden inside the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * transaction layer, within trans_commit. Hence, no LI_HOLD flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 * for the logitem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	xfs_dqunlock(dqp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) xfs_qm_dquot_logitem_committing(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	xfs_lsn_t		commit_lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	return xfs_qm_dquot_logitem_release(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static const struct xfs_item_ops xfs_dquot_item_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	.iop_size	= xfs_qm_dquot_logitem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.iop_format	= xfs_qm_dquot_logitem_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.iop_pin	= xfs_qm_dquot_logitem_pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.iop_unpin	= xfs_qm_dquot_logitem_unpin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.iop_release	= xfs_qm_dquot_logitem_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.iop_committing	= xfs_qm_dquot_logitem_committing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	.iop_push	= xfs_qm_dquot_logitem_push,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  * Initialize the dquot log item for a newly allocated dquot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)  * The dquot isn't locked at this point, but it isn't on any of the lists
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)  * either, so we don't care.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) xfs_qm_dquot_logitem_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct xfs_dquot	*dqp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct xfs_dq_logitem	*lp = &dqp->q_logitem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	xfs_log_item_init(dqp->q_mount, &lp->qli_item, XFS_LI_DQUOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 					&xfs_dquot_item_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	lp->qli_dquot = dqp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /*------------------  QUOTAOFF LOG ITEMS  -------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static inline struct xfs_qoff_logitem *QOFF_ITEM(struct xfs_log_item *lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return container_of(lip, struct xfs_qoff_logitem, qql_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  * This returns the number of iovecs needed to log the given quotaoff item.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * We only need 1 iovec for an quotaoff item.  It just logs the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  * quotaoff_log_format structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) xfs_qm_qoff_logitem_size(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	int			*nvecs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	int			*nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	*nvecs += 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	*nbytes += sizeof(struct xfs_qoff_logitem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) xfs_qm_qoff_logitem_format(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	struct xfs_log_vec	*lv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct xfs_qoff_logitem	*qflip = QOFF_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	struct xfs_log_iovec	*vecp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct xfs_qoff_logformat *qlf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	qlf = xlog_prepare_iovec(lv, &vecp, XLOG_REG_TYPE_QUOTAOFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	qlf->qf_type = XFS_LI_QUOTAOFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	qlf->qf_size = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	qlf->qf_flags = qflip->qql_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	xlog_finish_iovec(lv, vecp, sizeof(struct xfs_qoff_logitem));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * There isn't much you can do to push a quotaoff item.  It is simply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  * stuck waiting for the log to be flushed to disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) STATIC uint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) xfs_qm_qoff_logitem_push(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	struct list_head	*buffer_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	return XFS_ITEM_LOCKED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) STATIC xfs_lsn_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) xfs_qm_qoffend_logitem_committed(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct xfs_log_item	*lip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	xfs_lsn_t		lsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct xfs_qoff_logitem	*qfe = QOFF_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct xfs_qoff_logitem	*qfs = qfe->qql_start_lip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	xfs_qm_qoff_logitem_relse(qfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	kmem_free(lip->li_lv_shadow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	kmem_free(qfe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	return (xfs_lsn_t)-1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) STATIC void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) xfs_qm_qoff_logitem_release(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct xfs_log_item	*lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	struct xfs_qoff_logitem	*qoff = QOFF_ITEM(lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (test_bit(XFS_LI_ABORTED, &lip->li_flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		if (qoff->qql_start_lip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			xfs_qm_qoff_logitem_relse(qoff->qql_start_lip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		xfs_qm_qoff_logitem_relse(qoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) static const struct xfs_item_ops xfs_qm_qoffend_logitem_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	.iop_size	= xfs_qm_qoff_logitem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	.iop_format	= xfs_qm_qoff_logitem_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	.iop_committed	= xfs_qm_qoffend_logitem_committed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	.iop_push	= xfs_qm_qoff_logitem_push,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	.iop_release	= xfs_qm_qoff_logitem_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static const struct xfs_item_ops xfs_qm_qoff_logitem_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	.iop_size	= xfs_qm_qoff_logitem_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	.iop_format	= xfs_qm_qoff_logitem_format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	.iop_push	= xfs_qm_qoff_logitem_push,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	.iop_release	= xfs_qm_qoff_logitem_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * Delete the quotaoff intent from the AIL and free it. On success,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * this should only be called for the start item. It can be used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * either on shutdown or abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) xfs_qm_qoff_logitem_relse(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct xfs_qoff_logitem	*qoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	struct xfs_log_item	*lip = &qoff->qql_item;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	       test_bit(XFS_LI_ABORTED, &lip->li_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	       XFS_FORCED_SHUTDOWN(lip->li_mountp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	xfs_trans_ail_delete(lip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	kmem_free(lip->li_lv_shadow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	kmem_free(qoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * Allocate and initialize an quotaoff item of the correct quota type(s).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) struct xfs_qoff_logitem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) xfs_qm_qoff_logitem_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	struct xfs_qoff_logitem	*start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	uint			flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct xfs_qoff_logitem	*qf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	qf = kmem_zalloc(sizeof(struct xfs_qoff_logitem), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	xfs_log_item_init(mp, &qf->qql_item, XFS_LI_QUOTAOFF, start ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 			&xfs_qm_qoffend_logitem_ops : &xfs_qm_qoff_logitem_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	qf->qql_item.li_mountp = mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	qf->qql_start_lip = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	qf->qql_flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return qf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }