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-2005 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_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "xfs_trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "xfs_error.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "xfs_alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "xfs_fsops.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "xfs_trans_space.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) #include "xfs_ag.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "xfs_ag_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * growfs operations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) xfs_growfs_data_private(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	xfs_mount_t		*mp,		/* mount point for filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	xfs_growfs_data_t	*in)		/* growfs data input struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	xfs_buf_t		*bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	xfs_agnumber_t		nagcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	xfs_agnumber_t		nagimax = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	xfs_rfsblock_t		nb, nb_mod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	xfs_rfsblock_t		new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	xfs_agnumber_t		oagcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	xfs_trans_t		*tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct aghdr_init_data	id = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	nb = in->newblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (nb < mp->m_sb.sb_dblocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	if ((error = xfs_sb_validate_fsb_count(&mp->m_sb, nb)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	error = xfs_buf_read_uncached(mp->m_ddev_targp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 				XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 				XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	xfs_buf_relse(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	new = nb;	/* use new as a temporary here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	nb_mod = do_div(new, mp->m_sb.sb_agblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	nagcount = new + (nb_mod != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (nb_mod && nb_mod < XFS_MIN_AG_BLOCKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		nagcount--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		nb = (xfs_rfsblock_t)nagcount * mp->m_sb.sb_agblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		if (nb < mp->m_sb.sb_dblocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	new = nb - mp->m_sb.sb_dblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	oagcount = mp->m_sb.sb_agcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	/* allocate the new per-ag structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	if (nagcount > oagcount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		error = xfs_initialize_perag(mp, nagcount, &nagimax);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * Write new AG headers to disk. Non-transactional, but need to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * written and completed prior to the growfs transaction being logged.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * To do this, we use a delayed write buffer list and wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * submission and IO completion of the list as a whole. This allows the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * IO subsystem to merge all the AG headers in a single AG into a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 * IO and hide most of the latency of the IO from us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 * This also means that if we get an error whilst building the buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * list to write, we can cancel the entire list without having written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 * anything.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	INIT_LIST_HEAD(&id.buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	for (id.agno = nagcount - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	     id.agno >= oagcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	     id.agno--, new -= id.agsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (id.agno == nagcount - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			id.agsize = nb -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 				(id.agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			id.agsize = mp->m_sb.sb_agblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		error = xfs_ag_init_headers(mp, &id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			xfs_buf_delwri_cancel(&id.buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			goto out_trans_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	error = xfs_buf_delwri_submit(&id.buffer_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		goto out_trans_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	xfs_trans_agblocks_delta(tp, id.nfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/* If there are new blocks in the old last AG, extend it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		error = xfs_ag_extend_space(mp, tp, &id, new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			goto out_trans_cancel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * Update changed superblock fields transactionally. These are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * seen by the rest of the world until the transaction commit applies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * them atomically to the superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (nagcount > oagcount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (nb > mp->m_sb.sb_dblocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 				 nb - mp->m_sb.sb_dblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (id.nfree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, id.nfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	xfs_trans_set_sync(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	error = xfs_trans_commit(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/* New allocation groups fully initialized, so update mount struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if (nagimax)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		mp->m_maxagi = nagimax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	xfs_set_low_space_thresholds(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	mp->m_alloc_set_aside = xfs_alloc_set_aside(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 * If we expanded the last AG, free the per-AG reservation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 * so we can reinitialize it with the new size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (new) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		struct xfs_perag	*pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		pag = xfs_perag_get(mp, id.agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		error = xfs_ag_resv_free(pag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 		xfs_perag_put(pag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 * Reserve AG metadata blocks. ENOSPC here does not mean there was a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * growfs failure, just that there still isn't space for new user data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * after the grow has been run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	error = xfs_fs_reserve_ag_blocks(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (error == -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) out_trans_cancel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	xfs_trans_cancel(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	return error;
^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 int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) xfs_growfs_log_private(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	xfs_mount_t		*mp,	/* mount point for filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	xfs_growfs_log_t	*in)	/* growfs log input struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	xfs_extlen_t		nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	nb = in->newblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (nb < XFS_MIN_LOG_BLOCKS || nb < XFS_B_TO_FSB(mp, XFS_MIN_LOG_BYTES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (nb == mp->m_sb.sb_logblocks &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	    in->isint == (mp->m_sb.sb_logstart != 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * Moving the log is hard, need new interfaces to sync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * the log first, hold off all activity while moving it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 * Can have shorter or longer log in the same space,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * or transform internal to external log or vice versa.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) xfs_growfs_imaxpct(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	__u32			imaxpct)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct xfs_trans	*tp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int			dpct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	int			error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (imaxpct > 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	error = xfs_trans_alloc(mp, &M_RES(mp)->tr_growdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			XFS_GROWFS_SPACE_RES(mp), 0, XFS_TRANS_RESERVE, &tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	dpct = imaxpct - mp->m_sb.sb_imax_pct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	xfs_trans_mod_sb(tp, XFS_TRANS_SB_IMAXPCT, dpct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	xfs_trans_set_sync(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	return xfs_trans_commit(tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  * protected versions of growfs function acquire and release locks on the mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * point - exported through ioctls: XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  * XFS_IOC_FSGROWFSRT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) xfs_growfs_data(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct xfs_growfs_data	*in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (!mutex_trylock(&mp->m_growlock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		return -EWOULDBLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/* update imaxpct separately to the physical grow of the filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	if (in->imaxpct != mp->m_sb.sb_imax_pct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		error = xfs_growfs_imaxpct(mp, in->imaxpct);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (in->newblocks != mp->m_sb.sb_dblocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		error = xfs_growfs_data_private(mp, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* Post growfs calculations needed to reflect new state in operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	if (mp->m_sb.sb_imax_pct) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		do_div(icount, 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		M_IGEO(mp)->maxicount = XFS_FSB_TO_INO(mp, icount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		M_IGEO(mp)->maxicount = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	/* Update secondary superblocks now the physical grow has completed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	error = xfs_update_secondary_sbs(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) out_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	 * Increment the generation unconditionally, the error could be from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 * updating the secondary superblocks, in which case the new size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 * is live already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	mp->m_generation++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	mutex_unlock(&mp->m_growlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) xfs_growfs_log(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	xfs_mount_t		*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	xfs_growfs_log_t	*in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (!mutex_trylock(&mp->m_growlock))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		return -EWOULDBLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	error = xfs_growfs_log_private(mp, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	mutex_unlock(&mp->m_growlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * exported through ioctl XFS_IOC_FSCOUNTS
^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) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) xfs_fs_counts(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	xfs_mount_t		*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	xfs_fsop_counts_t	*cnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	cnt->allocino = percpu_counter_read_positive(&mp->m_icount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	cnt->freeino = percpu_counter_read_positive(&mp->m_ifree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	cnt->freedata = percpu_counter_read_positive(&mp->m_fdblocks) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 						mp->m_alloc_set_aside;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	spin_lock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	cnt->freertx = mp->m_sb.sb_frextents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	spin_unlock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)  * exported through ioctl XFS_IOC_SET_RESBLKS & XFS_IOC_GET_RESBLKS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)  * xfs_reserve_blocks is called to set m_resblks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)  * in the in-core mount table. The number of unused reserved blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)  * is kept in m_resblks_avail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)  * Reserve the requested number of blocks if available. Otherwise return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)  * as many as possible to satisfy the request. The actual number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  * reserved are returned in outval
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)  * A null inval pointer indicates that only the current reserved blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)  * available  should  be returned no settings are changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) xfs_reserve_blocks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	xfs_mount_t             *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	uint64_t              *inval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	xfs_fsop_resblks_t      *outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	int64_t			lcounter, delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	int64_t			fdblks_delta = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	uint64_t		request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	int64_t			free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	int			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	/* If inval is null, report current values and return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (inval == (uint64_t *)NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		if (!outval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		outval->resblks = mp->m_resblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		outval->resblks_avail = mp->m_resblks_avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	request = *inval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	 * With per-cpu counters, this becomes an interesting problem. we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	 * to work out if we are freeing or allocation blocks first, then we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 * do the modification as necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 * We do this under the m_sb_lock so that if we are near ENOSPC, we will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	 * hold out any changes while we work out what to do. This means that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	 * the amount of free space can change while we do this, so we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	 * retry if we end up trying to reserve more space than is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	spin_lock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	 * If our previous reservation was larger than the current value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	 * then move any unused blocks back to the free pool. Modify the resblks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	 * counters directly since we shouldn't have any problems unreserving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	 * space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	if (mp->m_resblks > request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		lcounter = mp->m_resblks_avail - request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		if (lcounter  > 0) {		/* release unused blocks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			fdblks_delta = lcounter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			mp->m_resblks_avail -= lcounter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		mp->m_resblks = request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		if (fdblks_delta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			spin_unlock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 			error = xfs_mod_fdblocks(mp, fdblks_delta, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 			spin_lock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 * If the request is larger than the current reservation, reserve the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * blocks before we update the reserve counters. Sample m_fdblocks and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * perform a partial reservation if the request exceeds free space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	error = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		free = percpu_counter_sum(&mp->m_fdblocks) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 						mp->m_alloc_set_aside;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		if (free <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		delta = request - mp->m_resblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		lcounter = free - delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		if (lcounter < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			/* We can't satisfy the request, just get what we can */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 			fdblks_delta = free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 			fdblks_delta = delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		 * We'll either succeed in getting space from the free block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		 * count or we'll get an ENOSPC. If we get a ENOSPC, it means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		 * things changed while we were calculating fdblks_delta and so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		 * we should try again to see if there is anything left to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		 * reserve.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		 * Don't set the reserved flag here - we don't want to reserve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		 * the extra reserve blocks from the reserve.....
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		spin_unlock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		error = xfs_mod_fdblocks(mp, -fdblks_delta, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		spin_lock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	} while (error == -ENOSPC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	 * Update the reserve counters if blocks have been successfully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	 * allocated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (!error && fdblks_delta) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		mp->m_resblks += fdblks_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		mp->m_resblks_avail += fdblks_delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	if (outval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		outval->resblks = mp->m_resblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		outval->resblks_avail = mp->m_resblks_avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	spin_unlock(&mp->m_sb_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) xfs_fs_goingdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	xfs_mount_t	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	uint32_t	inflags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	switch (inflags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	case XFS_FSOP_GOING_FLAGS_DEFAULT: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		if (!freeze_bdev(mp->m_super->s_bdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			xfs_force_shutdown(mp, SHUTDOWN_FORCE_UMOUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			thaw_bdev(mp->m_super->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	case XFS_FSOP_GOING_FLAGS_LOGFLUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		xfs_force_shutdown(mp, SHUTDOWN_FORCE_UMOUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	case XFS_FSOP_GOING_FLAGS_NOLOGFLUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 		xfs_force_shutdown(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 				SHUTDOWN_FORCE_UMOUNT | SHUTDOWN_LOG_IO_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  * Force a shutdown of the filesystem instantly while keeping the filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)  * consistent. We don't do an unmount here; just shutdown the shop, make sure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)  * that absolutely nothing persistent happens to this filesystem after this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)  * point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) xfs_do_force_shutdown(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	int		flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	char		*fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	int		lnnum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	bool		logerror = flags & SHUTDOWN_LOG_IO_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	 * No need to duplicate efforts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	if (XFS_FORCED_SHUTDOWN(mp) && !logerror)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	 * This flags XFS_MOUNT_FS_SHUTDOWN, makes sure that we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	 * queue up anybody new on the log reservations, and wakes up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	 * everybody who's sleeping on log reservations to tell them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	 * the bad news.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	if (xfs_log_force_umount(mp, logerror))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	if (flags & SHUTDOWN_FORCE_UMOUNT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 		xfs_alert(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) "User initiated shutdown received. Shutting down filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	xfs_notice(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) "%s(0x%x) called from line %d of file %s. Return address = "PTR_FMT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		__func__, flags, lnnum, fname, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	if (flags & SHUTDOWN_CORRUPT_INCORE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_CORRUPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) "Corruption of in-memory data detected.  Shutting down filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		if (XFS_ERRLEVEL_HIGH <= xfs_error_level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			xfs_stack_trace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	} else if (logerror) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 		xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_LOGERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 			"Log I/O Error Detected. Shutting down filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		xfs_alert_tag(mp, XFS_PTAG_SHUTDOWN_IOERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			"I/O Error Detected. Shutting down filesystem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	xfs_alert(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		"Please unmount the filesystem and rectify the problem(s)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)  * Reserve free space for per-AG metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) xfs_fs_reserve_ag_blocks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	struct xfs_mount	*mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	xfs_agnumber_t		agno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	struct xfs_perag	*pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	int			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	int			err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	mp->m_finobt_nores = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		pag = xfs_perag_get(mp, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		err2 = xfs_ag_resv_init(pag, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		xfs_perag_put(pag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 		if (err2 && !error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 			error = err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	if (error && error != -ENOSPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	"Error %d reserving per-AG metadata reserve pool.", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 		xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)  * Free space reserved for per-AG metadata.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) xfs_fs_unreserve_ag_blocks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	struct xfs_mount	*mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	xfs_agnumber_t		agno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	struct xfs_perag	*pag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	int			error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	int			err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 		pag = xfs_perag_get(mp, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		err2 = xfs_ag_resv_free(pag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		xfs_perag_put(pag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		if (err2 && !error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 			error = err2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		xfs_warn(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 	"Error %d freeing per-AG metadata reserve pool.", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }