2018-06-05 20:42:14 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-06-27 00:04:53 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008-2010, 2013 Dave Chinner
|
|
|
|
* All Rights Reserved.
|
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
|
|
|
#include "xfs_fs.h"
|
2013-10-22 17:36:05 -06:00
|
|
|
#include "xfs_shared.h"
|
2013-10-22 17:50:10 -06:00
|
|
|
#include "xfs_log_format.h"
|
|
|
|
#include "xfs_trans.h"
|
2013-06-27 00:04:53 -06:00
|
|
|
#include "xfs_trans_priv.h"
|
|
|
|
#include "xfs_icreate_item.h"
|
2013-12-12 17:00:43 -07:00
|
|
|
#include "xfs_log.h"
|
2013-06-27 00:04:53 -06:00
|
|
|
|
|
|
|
kmem_zone_t *xfs_icreate_zone; /* inode create item zone */
|
|
|
|
|
|
|
|
static inline struct xfs_icreate_item *ICR_ITEM(struct xfs_log_item *lip)
|
|
|
|
{
|
|
|
|
return container_of(lip, struct xfs_icreate_item, ic_item);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This returns the number of iovecs needed to log the given inode item.
|
|
|
|
*
|
|
|
|
* We only need one iovec for the icreate log structure.
|
|
|
|
*/
|
2013-08-12 04:50:04 -06:00
|
|
|
STATIC void
|
2013-06-27 00:04:53 -06:00
|
|
|
xfs_icreate_item_size(
|
2013-08-12 04:50:04 -06:00
|
|
|
struct xfs_log_item *lip,
|
|
|
|
int *nvecs,
|
|
|
|
int *nbytes)
|
2013-06-27 00:04:53 -06:00
|
|
|
{
|
2013-08-12 04:50:04 -06:00
|
|
|
*nvecs += 1;
|
|
|
|
*nbytes += sizeof(struct xfs_icreate_log);
|
2013-06-27 00:04:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called to fill in the vector of log iovecs for the
|
|
|
|
* given inode create log item.
|
|
|
|
*/
|
|
|
|
STATIC void
|
|
|
|
xfs_icreate_item_format(
|
|
|
|
struct xfs_log_item *lip,
|
2013-12-12 17:34:02 -07:00
|
|
|
struct xfs_log_vec *lv)
|
2013-06-27 00:04:53 -06:00
|
|
|
{
|
|
|
|
struct xfs_icreate_item *icp = ICR_ITEM(lip);
|
2013-12-12 17:34:02 -07:00
|
|
|
struct xfs_log_iovec *vecp = NULL;
|
2013-06-27 00:04:53 -06:00
|
|
|
|
2013-12-12 17:34:02 -07:00
|
|
|
xlog_copy_iovec(lv, &vecp, XLOG_REG_TYPE_ICREATE,
|
2013-12-12 17:00:43 -07:00
|
|
|
&icp->ic_format,
|
|
|
|
sizeof(struct xfs_icreate_log));
|
2013-06-27 00:04:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
STATIC void
|
2019-06-28 20:27:32 -06:00
|
|
|
xfs_icreate_item_release(
|
2013-06-27 00:04:53 -06:00
|
|
|
struct xfs_log_item *lip)
|
|
|
|
{
|
2019-06-28 20:27:32 -06:00
|
|
|
kmem_zone_free(xfs_icreate_zone, ICR_ITEM(lip));
|
2013-06-27 00:04:53 -06:00
|
|
|
}
|
|
|
|
|
2016-11-27 20:57:42 -07:00
|
|
|
static const struct xfs_item_ops xfs_icreate_item_ops = {
|
2019-06-28 20:27:32 -06:00
|
|
|
.flags = XFS_ITEM_RELEASE_WHEN_COMMITTED,
|
2013-06-27 00:04:53 -06:00
|
|
|
.iop_size = xfs_icreate_item_size,
|
|
|
|
.iop_format = xfs_icreate_item_format,
|
2019-06-28 20:27:32 -06:00
|
|
|
.iop_release = xfs_icreate_item_release,
|
2013-06-27 00:04:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the inode log item for a newly allocated (in-core) inode.
|
|
|
|
*
|
|
|
|
* Inode extents can only reside within an AG. Hence specify the starting
|
|
|
|
* block for the inode chunk by offset within an AG as well as the
|
|
|
|
* length of the allocated extent.
|
|
|
|
*
|
|
|
|
* This joins the item to the transaction and marks it dirty so
|
|
|
|
* that we don't need a separate call to do this, nor does the
|
|
|
|
* caller need to know anything about the icreate item.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_icreate_log(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t agbno,
|
|
|
|
unsigned int count,
|
|
|
|
unsigned int inode_size,
|
|
|
|
xfs_agblock_t length,
|
|
|
|
unsigned int generation)
|
|
|
|
{
|
|
|
|
struct xfs_icreate_item *icp;
|
|
|
|
|
|
|
|
icp = kmem_zone_zalloc(xfs_icreate_zone, KM_SLEEP);
|
|
|
|
|
|
|
|
xfs_log_item_init(tp->t_mountp, &icp->ic_item, XFS_LI_ICREATE,
|
|
|
|
&xfs_icreate_item_ops);
|
|
|
|
|
|
|
|
icp->ic_format.icl_type = XFS_LI_ICREATE;
|
|
|
|
icp->ic_format.icl_size = 1; /* single vector */
|
|
|
|
icp->ic_format.icl_ag = cpu_to_be32(agno);
|
|
|
|
icp->ic_format.icl_agbno = cpu_to_be32(agbno);
|
|
|
|
icp->ic_format.icl_count = cpu_to_be32(count);
|
|
|
|
icp->ic_format.icl_isize = cpu_to_be32(inode_size);
|
|
|
|
icp->ic_format.icl_length = cpu_to_be32(length);
|
|
|
|
icp->ic_format.icl_gen = cpu_to_be32(generation);
|
|
|
|
|
|
|
|
xfs_trans_add_item(tp, &icp->ic_item);
|
|
|
|
tp->t_flags |= XFS_TRANS_DIRTY;
|
2018-05-09 08:49:37 -06:00
|
|
|
set_bit(XFS_LI_DIRTY, &icp->ic_item.li_flags);
|
2013-06-27 00:04:53 -06:00
|
|
|
}
|