Linux Audio

Check our new training course

Loading...
v4.17
 
  1/*
  2 * Copyright (c) 2008-2010, 2013 Dave Chinner
  3 * All Rights Reserved.
  4 *
  5 * This program is free software; you can redistribute it and/or
  6 * modify it under the terms of the GNU General Public License as
  7 * published by the Free Software Foundation.
  8 *
  9 * This program is distributed in the hope that it would be useful,
 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 * GNU General Public License for more details.
 13 *
 14 * You should have received a copy of the GNU General Public License
 15 * along with this program; if not, write the Free Software Foundation,
 16 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 17 */
 18#include "xfs.h"
 19#include "xfs_fs.h"
 20#include "xfs_shared.h"
 21#include "xfs_format.h"
 22#include "xfs_log_format.h"
 23#include "xfs_trans_resv.h"
 24#include "xfs_bit.h"
 25#include "xfs_mount.h"
 
 26#include "xfs_trans.h"
 27#include "xfs_trans_priv.h"
 28#include "xfs_error.h"
 29#include "xfs_icreate_item.h"
 30#include "xfs_log.h"
 
 
 
 
 31
 32kmem_zone_t	*xfs_icreate_zone;		/* inode create item zone */
 33
 34static inline struct xfs_icreate_item *ICR_ITEM(struct xfs_log_item *lip)
 35{
 36	return container_of(lip, struct xfs_icreate_item, ic_item);
 37}
 38
 39/*
 40 * This returns the number of iovecs needed to log the given inode item.
 41 *
 42 * We only need one iovec for the icreate log structure.
 43 */
 44STATIC void
 45xfs_icreate_item_size(
 46	struct xfs_log_item	*lip,
 47	int			*nvecs,
 48	int			*nbytes)
 49{
 50	*nvecs += 1;
 51	*nbytes += sizeof(struct xfs_icreate_log);
 52}
 53
 54/*
 55 * This is called to fill in the vector of log iovecs for the
 56 * given inode create log item.
 57 */
 58STATIC void
 59xfs_icreate_item_format(
 60	struct xfs_log_item	*lip,
 61	struct xfs_log_vec	*lv)
 62{
 63	struct xfs_icreate_item	*icp = ICR_ITEM(lip);
 64	struct xfs_log_iovec	*vecp = NULL;
 65
 66	xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ICREATE,
 67			&icp->ic_format,
 68			sizeof(struct xfs_icreate_log));
 69}
 70
 71
 72/* Pinning has no meaning for the create item, so just return. */
 73STATIC void
 74xfs_icreate_item_pin(
 75	struct xfs_log_item	*lip)
 76{
 
 
 77}
 78
 79
 80/* pinning has no meaning for the create item, so just return. */
 81STATIC void
 82xfs_icreate_item_unpin(
 83	struct xfs_log_item	*lip,
 84	int			remove)
 85{
 86}
 87
 88STATIC void
 89xfs_icreate_item_unlock(
 90	struct xfs_log_item	*lip)
 91{
 92	struct xfs_icreate_item	*icp = ICR_ITEM(lip);
 93
 94	if (icp->ic_item.li_flags & XFS_LI_ABORTED)
 95		kmem_zone_free(xfs_icreate_zone, icp);
 96	return;
 97}
 98
 99/*
100 * Because we have ordered buffers being tracked in the AIL for the inode
101 * creation, we don't need the create item after this. Hence we can free
102 * the log item and return -1 to tell the caller we're done with the item.
103 */
104STATIC xfs_lsn_t
105xfs_icreate_item_committed(
106	struct xfs_log_item	*lip,
107	xfs_lsn_t		lsn)
108{
109	struct xfs_icreate_item	*icp = ICR_ITEM(lip);
110
111	kmem_zone_free(xfs_icreate_zone, icp);
112	return (xfs_lsn_t)-1;
113}
114
115/* item can never get into the AIL */
116STATIC uint
117xfs_icreate_item_push(
118	struct xfs_log_item	*lip,
119	struct list_head	*buffer_list)
120{
121	ASSERT(0);
122	return XFS_ITEM_SUCCESS;
123}
124
125/* Ordered buffers do the dependency tracking here, so this does nothing. */
126STATIC void
127xfs_icreate_item_committing(
128	struct xfs_log_item	*lip,
129	xfs_lsn_t		lsn)
130{
131}
132
133/*
134 * This is the ops vector shared by all buf log items.
135 */
136static const struct xfs_item_ops xfs_icreate_item_ops = {
 
137	.iop_size	= xfs_icreate_item_size,
138	.iop_format	= xfs_icreate_item_format,
139	.iop_pin	= xfs_icreate_item_pin,
140	.iop_unpin	= xfs_icreate_item_unpin,
141	.iop_push	= xfs_icreate_item_push,
142	.iop_unlock	= xfs_icreate_item_unlock,
143	.iop_committed	= xfs_icreate_item_committed,
144	.iop_committing = xfs_icreate_item_committing,
145};
146
147
148/*
149 * Initialize the inode log item for a newly allocated (in-core) inode.
150 *
151 * Inode extents can only reside within an AG. Hence specify the starting
152 * block for the inode chunk by offset within an AG as well as the
153 * length of the allocated extent.
154 *
155 * This joins the item to the transaction and marks it dirty so
156 * that we don't need a separate call to do this, nor does the
157 * caller need to know anything about the icreate item.
158 */
159void
160xfs_icreate_log(
161	struct xfs_trans	*tp,
162	xfs_agnumber_t		agno,
163	xfs_agblock_t		agbno,
164	unsigned int		count,
165	unsigned int		inode_size,
166	xfs_agblock_t		length,
167	unsigned int		generation)
168{
169	struct xfs_icreate_item	*icp;
170
171	icp = kmem_zone_zalloc(xfs_icreate_zone, KM_SLEEP);
172
173	xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE,
174			  &xfs_icreate_item_ops);
175
176	icp->ic_format.icl_type = XFS_LI_ICREATE;
177	icp->ic_format.icl_size = 1;	/* single vector */
178	icp->ic_format.icl_ag = cpu_to_be32(agno);
179	icp->ic_format.icl_agbno = cpu_to_be32(agbno);
180	icp->ic_format.icl_count = cpu_to_be32(count);
181	icp->ic_format.icl_isize = cpu_to_be32(inode_size);
182	icp->ic_format.icl_length = cpu_to_be32(length);
183	icp->ic_format.icl_gen = cpu_to_be32(generation);
184
185	xfs_trans_add_item(tp, &icp->ic_item);
186	tp->t_flags |= XFS_TRANS_DIRTY;
187	icp->ic_item.li_desc->lid_flags |= XFS_LID_DIRTY;
 
 
 
 
 
 
 
 
 
 
 
 
 
188}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 * Copyright (c) 2008-2010, 2013 Dave Chinner
  4 * All Rights Reserved.
 
 
 
 
 
 
 
 
 
 
 
 
 
  5 */
  6#include "xfs.h"
  7#include "xfs_fs.h"
  8#include "xfs_shared.h"
  9#include "xfs_format.h"
 10#include "xfs_log_format.h"
 11#include "xfs_trans_resv.h"
 
 12#include "xfs_mount.h"
 13#include "xfs_inode.h"
 14#include "xfs_trans.h"
 15#include "xfs_trans_priv.h"
 
 16#include "xfs_icreate_item.h"
 17#include "xfs_log.h"
 18#include "xfs_log_priv.h"
 19#include "xfs_log_recover.h"
 20#include "xfs_ialloc.h"
 21#include "xfs_trace.h"
 22
 23struct kmem_cache	*xfs_icreate_cache;		/* inode create item */
 24
 25static inline struct xfs_icreate_item *ICR_ITEM(struct xfs_log_item *lip)
 26{
 27	return container_of(lip, struct xfs_icreate_item, ic_item);
 28}
 29
 30/*
 31 * This returns the number of iovecs needed to log the given inode item.
 32 *
 33 * We only need one iovec for the icreate log structure.
 34 */
 35STATIC void
 36xfs_icreate_item_size(
 37	struct xfs_log_item	*lip,
 38	int			*nvecs,
 39	int			*nbytes)
 40{
 41	*nvecs += 1;
 42	*nbytes += sizeof(struct xfs_icreate_log);
 43}
 44
 45/*
 46 * This is called to fill in the vector of log iovecs for the
 47 * given inode create log item.
 48 */
 49STATIC void
 50xfs_icreate_item_format(
 51	struct xfs_log_item	*lip,
 52	struct xfs_log_vec	*lv)
 53{
 54	struct xfs_icreate_item	*icp = ICR_ITEM(lip);
 55	struct xfs_log_iovec	*vecp = NULL;
 56
 57	xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ICREATE,
 58			&icp->ic_format,
 59			sizeof(struct xfs_icreate_log));
 60}
 61
 
 
 62STATIC void
 63xfs_icreate_item_release(
 64	struct xfs_log_item	*lip)
 65{
 66	kvfree(ICR_ITEM(lip)->ic_item.li_lv_shadow);
 67	kmem_cache_free(xfs_icreate_cache, ICR_ITEM(lip));
 68}
 69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 70static const struct xfs_item_ops xfs_icreate_item_ops = {
 71	.flags		= XFS_ITEM_RELEASE_WHEN_COMMITTED,
 72	.iop_size	= xfs_icreate_item_size,
 73	.iop_format	= xfs_icreate_item_format,
 74	.iop_release	= xfs_icreate_item_release,
 
 
 
 
 
 75};
 76
 77
 78/*
 79 * Initialize the inode log item for a newly allocated (in-core) inode.
 80 *
 81 * Inode extents can only reside within an AG. Hence specify the starting
 82 * block for the inode chunk by offset within an AG as well as the
 83 * length of the allocated extent.
 84 *
 85 * This joins the item to the transaction and marks it dirty so
 86 * that we don't need a separate call to do this, nor does the
 87 * caller need to know anything about the icreate item.
 88 */
 89void
 90xfs_icreate_log(
 91	struct xfs_trans	*tp,
 92	xfs_agnumber_t		agno,
 93	xfs_agblock_t		agbno,
 94	unsigned int		count,
 95	unsigned int		inode_size,
 96	xfs_agblock_t		length,
 97	unsigned int		generation)
 98{
 99	struct xfs_icreate_item	*icp;
100
101	icp = kmem_cache_zalloc(xfs_icreate_cache, GFP_KERNEL | __GFP_NOFAIL);
102
103	xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE,
104			  &xfs_icreate_item_ops);
105
106	icp->ic_format.icl_type = XFS_LI_ICREATE;
107	icp->ic_format.icl_size = 1;	/* single vector */
108	icp->ic_format.icl_ag = cpu_to_be32(agno);
109	icp->ic_format.icl_agbno = cpu_to_be32(agbno);
110	icp->ic_format.icl_count = cpu_to_be32(count);
111	icp->ic_format.icl_isize = cpu_to_be32(inode_size);
112	icp->ic_format.icl_length = cpu_to_be32(length);
113	icp->ic_format.icl_gen = cpu_to_be32(generation);
114
115	xfs_trans_add_item(tp, &icp->ic_item);
116	tp->t_flags |= XFS_TRANS_DIRTY;
117	set_bit(XFS_LI_DIRTY, &icp->ic_item.li_flags);
118}
119
120static enum xlog_recover_reorder
121xlog_recover_icreate_reorder(
122		struct xlog_recover_item *item)
123{
124	/*
125	 * Inode allocation buffers must be replayed before subsequent inode
126	 * items try to modify those buffers.  ICREATE items are the logical
127	 * equivalent of logging a newly initialized inode buffer, so recover
128	 * these at the same time that we recover logged buffers.
129	 */
130	return XLOG_REORDER_BUFFER_LIST;
131}
132
133/*
134 * This routine is called when an inode create format structure is found in a
135 * committed transaction in the log.  It's purpose is to initialise the inodes
136 * being allocated on disk. This requires us to get inode cluster buffers that
137 * match the range to be initialised, stamped with inode templates and written
138 * by delayed write so that subsequent modifications will hit the cached buffer
139 * and only need writing out at the end of recovery.
140 */
141STATIC int
142xlog_recover_icreate_commit_pass2(
143	struct xlog			*log,
144	struct list_head		*buffer_list,
145	struct xlog_recover_item	*item,
146	xfs_lsn_t			lsn)
147{
148	struct xfs_mount		*mp = log->l_mp;
149	struct xfs_icreate_log		*icl;
150	struct xfs_ino_geometry		*igeo = M_IGEO(mp);
151	xfs_agnumber_t			agno;
152	xfs_agblock_t			agbno;
153	unsigned int			count;
154	unsigned int			isize;
155	xfs_agblock_t			length;
156	int				bb_per_cluster;
157	int				cancel_count;
158	int				nbufs;
159	int				i;
160
161	icl = (struct xfs_icreate_log *)item->ri_buf[0].i_addr;
162	if (icl->icl_type != XFS_LI_ICREATE) {
163		xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad type");
164		return -EINVAL;
165	}
166
167	if (icl->icl_size != 1) {
168		xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad icl size");
169		return -EINVAL;
170	}
171
172	agno = be32_to_cpu(icl->icl_ag);
173	if (agno >= mp->m_sb.sb_agcount) {
174		xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad agno");
175		return -EINVAL;
176	}
177	agbno = be32_to_cpu(icl->icl_agbno);
178	if (!agbno || agbno == NULLAGBLOCK || agbno >= mp->m_sb.sb_agblocks) {
179		xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad agbno");
180		return -EINVAL;
181	}
182	isize = be32_to_cpu(icl->icl_isize);
183	if (isize != mp->m_sb.sb_inodesize) {
184		xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad isize");
185		return -EINVAL;
186	}
187	count = be32_to_cpu(icl->icl_count);
188	if (!count) {
189		xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad count");
190		return -EINVAL;
191	}
192	length = be32_to_cpu(icl->icl_length);
193	if (!length || length >= mp->m_sb.sb_agblocks) {
194		xfs_warn(log->l_mp, "xlog_recover_do_icreate_trans: bad length");
195		return -EINVAL;
196	}
197
198	/*
199	 * The inode chunk is either full or sparse and we only support
200	 * m_ino_geo.ialloc_min_blks sized sparse allocations at this time.
201	 */
202	if (length != igeo->ialloc_blks &&
203	    length != igeo->ialloc_min_blks) {
204		xfs_warn(log->l_mp,
205			 "%s: unsupported chunk length", __func__);
206		return -EINVAL;
207	}
208
209	/* verify inode count is consistent with extent length */
210	if ((count >> mp->m_sb.sb_inopblog) != length) {
211		xfs_warn(log->l_mp,
212			 "%s: inconsistent inode count and chunk length",
213			 __func__);
214		return -EINVAL;
215	}
216
217	/*
218	 * The icreate transaction can cover multiple cluster buffers and these
219	 * buffers could have been freed and reused. Check the individual
220	 * buffers for cancellation so we don't overwrite anything written after
221	 * a cancellation.
222	 */
223	bb_per_cluster = XFS_FSB_TO_BB(mp, igeo->blocks_per_cluster);
224	nbufs = length / igeo->blocks_per_cluster;
225	for (i = 0, cancel_count = 0; i < nbufs; i++) {
226		xfs_daddr_t	daddr;
227
228		daddr = XFS_AGB_TO_DADDR(mp, agno,
229				agbno + i * igeo->blocks_per_cluster);
230		if (xlog_is_buffer_cancelled(log, daddr, bb_per_cluster))
231			cancel_count++;
232	}
233
234	/*
235	 * We currently only use icreate for a single allocation at a time. This
236	 * means we should expect either all or none of the buffers to be
237	 * cancelled. Be conservative and skip replay if at least one buffer is
238	 * cancelled, but warn the user that something is awry if the buffers
239	 * are not consistent.
240	 *
241	 * XXX: This must be refined to only skip cancelled clusters once we use
242	 * icreate for multiple chunk allocations.
243	 */
244	ASSERT(!cancel_count || cancel_count == nbufs);
245	if (cancel_count) {
246		if (cancel_count != nbufs)
247			xfs_warn(mp,
248	"WARNING: partial inode chunk cancellation, skipped icreate.");
249		trace_xfs_log_recover_icreate_cancel(log, icl);
250		return 0;
251	}
252
253	trace_xfs_log_recover_icreate_recover(log, icl);
254	return xfs_ialloc_inode_init(mp, NULL, buffer_list, count, agno, agbno,
255				     length, be32_to_cpu(icl->icl_gen));
256}
257
258const struct xlog_recover_item_ops xlog_icreate_item_ops = {
259	.item_type		= XFS_LI_ICREATE,
260	.reorder		= xlog_recover_icreate_reorder,
261	.commit_pass2		= xlog_recover_icreate_commit_pass2,
262};