2005-04-16 16:20:36 -06:00
|
|
|
/*
|
2005-11-01 20:58:39 -07:00
|
|
|
* Copyright (c) 2000,2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2005-11-01 20:58:39 -07:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
2005-04-16 16:20:36 -06:00
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2005-11-01 20:58:39 -07:00
|
|
|
* This program is distributed in the hope that it would be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
2005-11-01 20:58:39 -07:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_IALLOC_H__
|
|
|
|
#define __XFS_IALLOC_H__
|
|
|
|
|
|
|
|
struct xfs_buf;
|
|
|
|
struct xfs_dinode;
|
2008-11-27 20:23:41 -07:00
|
|
|
struct xfs_imap;
|
2005-04-16 16:20:36 -06:00
|
|
|
struct xfs_mount;
|
|
|
|
struct xfs_trans;
|
2013-10-22 17:51:50 -06:00
|
|
|
struct xfs_btree_cur;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2013-12-12 21:51:48 -07:00
|
|
|
/* Move inodes in clusters of this size */
|
2005-04-16 16:20:36 -06:00
|
|
|
#define XFS_INODE_BIG_CLUSTER_SIZE 8192
|
|
|
|
|
2015-05-28 17:26:03 -06:00
|
|
|
struct xfs_icluster {
|
|
|
|
bool deleted; /* record is deleted */
|
|
|
|
xfs_ino_t first_ino; /* first inode number */
|
|
|
|
uint64_t alloc; /* inode phys. allocation bitmap for
|
|
|
|
* sparse chunks */
|
|
|
|
};
|
|
|
|
|
2013-12-12 21:51:48 -07:00
|
|
|
/* Calculate and return the number of filesystem blocks per inode cluster */
|
|
|
|
static inline int
|
|
|
|
xfs_icluster_size_fsb(
|
|
|
|
struct xfs_mount *mp)
|
|
|
|
{
|
|
|
|
if (mp->m_sb.sb_blocksize >= mp->m_inode_cluster_size)
|
|
|
|
return 1;
|
|
|
|
return mp->m_inode_cluster_size >> mp->m_sb.sb_blocklog;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Make an inode pointer out of the buffer/offset.
|
|
|
|
*/
|
2005-11-01 20:38:42 -07:00
|
|
|
static inline struct xfs_dinode *
|
|
|
|
xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
|
|
|
|
{
|
2015-06-21 17:44:29 -06:00
|
|
|
return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog);
|
2005-11-01 20:38:42 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an inode on disk.
|
|
|
|
* Mode is used to tell whether the new inode will need space, and whether
|
|
|
|
* it is a directory.
|
|
|
|
*
|
|
|
|
* To work within the constraint of one allocation per transaction,
|
|
|
|
* xfs_dialloc() is designed to be called twice if it has to do an
|
|
|
|
* allocation to make more free inodes. If an inode is
|
|
|
|
* available without an allocation, agbp would be set to the current
|
|
|
|
* agbp and alloc_done set to false.
|
|
|
|
* If an allocation needed to be done, agbp would be set to the
|
|
|
|
* inode header of the allocation group and alloc_done set to true.
|
|
|
|
* The caller should then commit the current transaction and allocate a new
|
|
|
|
* transaction. xfs_dialloc() should then be called again with
|
|
|
|
* the agbp value returned from the previous call.
|
|
|
|
*
|
|
|
|
* Once we successfully pick an inode its number is returned and the
|
|
|
|
* on-disk data structures are updated. The inode itself is not read
|
|
|
|
* in, since doing so would break ordering constraints with xfs_reclaim.
|
|
|
|
*
|
|
|
|
* *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
|
|
|
|
*/
|
|
|
|
int /* error */
|
|
|
|
xfs_dialloc(
|
|
|
|
struct xfs_trans *tp, /* transaction pointer */
|
|
|
|
xfs_ino_t parent, /* parent inode (directory) */
|
2011-07-26 00:50:15 -06:00
|
|
|
umode_t mode, /* mode bits for new inode */
|
2005-04-16 16:20:36 -06:00
|
|
|
int okalloc, /* ok to allocate more space */
|
|
|
|
struct xfs_buf **agbp, /* buf for a.g. inode header */
|
|
|
|
xfs_ino_t *inop); /* inode number allocated */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free disk inode. Carefully avoids touching the incore inode, all
|
|
|
|
* manipulations incore are the caller's responsibility.
|
|
|
|
* The on-disk inode is not changed by this operation, only the
|
|
|
|
* btree (free inode mask) is changed.
|
|
|
|
*/
|
|
|
|
int /* error */
|
|
|
|
xfs_difree(
|
|
|
|
struct xfs_trans *tp, /* transaction pointer */
|
|
|
|
xfs_ino_t inode, /* inode to be freed */
|
2016-08-02 19:19:29 -06:00
|
|
|
struct xfs_defer_ops *dfops, /* extents to free */
|
2015-05-28 17:26:03 -06:00
|
|
|
struct xfs_icluster *ifree); /* cluster info if deleted */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
2008-11-27 20:23:41 -07:00
|
|
|
* Return the location of the inode in imap, for mapping it into a buffer.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
int
|
2008-11-27 20:23:41 -07:00
|
|
|
xfs_imap(
|
2005-04-16 16:20:36 -06:00
|
|
|
struct xfs_mount *mp, /* file system mount structure */
|
|
|
|
struct xfs_trans *tp, /* transaction pointer */
|
|
|
|
xfs_ino_t ino, /* inode to locate */
|
2008-11-27 20:23:41 -07:00
|
|
|
struct xfs_imap *imap, /* location map structure */
|
2005-04-16 16:20:36 -06:00
|
|
|
uint flags); /* flags for inode btree lookup */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute and fill in value of m_in_maxlevels.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_ialloc_compute_maxlevels(
|
|
|
|
struct xfs_mount *mp); /* file system mount structure */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Log specified fields for the ag hdr (inode section)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_ialloc_log_agi(
|
|
|
|
struct xfs_trans *tp, /* transaction pointer */
|
|
|
|
struct xfs_buf *bp, /* allocation group header buffer */
|
|
|
|
int fields); /* bitmask of fields to log */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read in the allocation group header (inode allocation section)
|
|
|
|
*/
|
|
|
|
int /* error */
|
|
|
|
xfs_ialloc_read_agi(
|
|
|
|
struct xfs_mount *mp, /* file system mount structure */
|
|
|
|
struct xfs_trans *tp, /* transaction pointer */
|
|
|
|
xfs_agnumber_t agno, /* allocation group number */
|
|
|
|
struct xfs_buf **bpp); /* allocation group hdr buf */
|
|
|
|
|
[XFS] Lazy Superblock Counters
When we have a couple of hundred transactions on the fly at once, they all
typically modify the on disk superblock in some way.
create/unclink/mkdir/rmdir modify inode counts, allocation/freeing modify
free block counts.
When these counts are modified in a transaction, they must eventually lock
the superblock buffer and apply the mods. The buffer then remains locked
until the transaction is committed into the incore log buffer. The result
of this is that with enough transactions on the fly the incore superblock
buffer becomes a bottleneck.
The result of contention on the incore superblock buffer is that
transaction rates fall - the more pressure that is put on the superblock
buffer, the slower things go.
The key to removing the contention is to not require the superblock fields
in question to be locked. We do that by not marking the superblock dirty
in the transaction. IOWs, we modify the incore superblock but do not
modify the cached superblock buffer. In short, we do not log superblock
modifications to critical fields in the superblock on every transaction.
In fact we only do it just before we write the superblock to disk every
sync period or just before unmount.
This creates an interesting problem - if we don't log or write out the
fields in every transaction, then how do the values get recovered after a
crash? the answer is simple - we keep enough duplicate, logged information
in other structures that we can reconstruct the correct count after log
recovery has been performed.
It is the AGF and AGI structures that contain the duplicate information;
after recovery, we walk every AGI and AGF and sum their individual
counters to get the correct value, and we do a transaction into the log to
correct them. An optimisation of this is that if we have a clean unmount
record, we know the value in the superblock is correct, so we can avoid
the summation walk under normal conditions and so mount/recovery times do
not change under normal operation.
One wrinkle that was discovered during development was that the blocks
used in the freespace btrees are never accounted for in the AGF counters.
This was once a valid optimisation to make; when the filesystem is full,
the free space btrees are empty and consume no space. Hence when it
matters, the "accounting" is correct. But that means the when we do the
AGF summations, we would not have a correct count and xfs_check would
complain. Hence a new counter was added to track the number of blocks used
by the free space btrees. This is an *on-disk format change*.
As a result of this, lazy superblock counters are a mkfs option and at the
moment on linux there is no way to convert an old filesystem. This is
possible - xfs_db can be used to twiddle the right bits and then
xfs_repair will do the format conversion for you. Similarly, you can
convert backwards as well. At some point we'll add functionality to
xfs_admin to do the bit twiddling easily....
SGI-PV: 964999
SGI-Modid: xfs-linux-melb:xfs-kern:28652a
Signed-off-by: David Chinner <dgc@sgi.com>
Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Tim Shimmin <tes@sgi.com>
2007-05-23 23:26:31 -06:00
|
|
|
/*
|
|
|
|
* Read in the allocation group header to initialise the per-ag data
|
|
|
|
* in the mount structure
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xfs_ialloc_pagi_init(
|
|
|
|
struct xfs_mount *mp, /* file system mount structure */
|
|
|
|
struct xfs_trans *tp, /* transaction pointer */
|
|
|
|
xfs_agnumber_t agno); /* allocation group number */
|
|
|
|
|
2008-10-29 23:56:09 -06:00
|
|
|
/*
|
2009-08-31 17:58:21 -06:00
|
|
|
* Lookup a record by ino in the btree given by cur.
|
2008-10-29 23:56:09 -06:00
|
|
|
*/
|
2009-08-31 17:58:21 -06:00
|
|
|
int xfs_inobt_lookup(struct xfs_btree_cur *cur, xfs_agino_t ino,
|
|
|
|
xfs_lookup_t dir, int *stat);
|
2008-10-29 23:56:09 -06:00
|
|
|
|
2008-10-29 23:58:11 -06:00
|
|
|
/*
|
|
|
|
* Get the data from the pointed-to record.
|
|
|
|
*/
|
2012-11-13 23:53:49 -07:00
|
|
|
int xfs_inobt_get_rec(struct xfs_btree_cur *cur,
|
2009-08-31 17:56:58 -06:00
|
|
|
xfs_inobt_rec_incore_t *rec, int *stat);
|
2008-10-29 23:56:09 -06:00
|
|
|
|
2013-06-27 00:04:55 -06:00
|
|
|
/*
|
|
|
|
* Inode chunk initialisation routine
|
|
|
|
*/
|
|
|
|
int xfs_ialloc_inode_init(struct xfs_mount *mp, struct xfs_trans *tp,
|
2015-05-28 17:05:49 -06:00
|
|
|
struct list_head *buffer_list, int icount,
|
2013-06-27 00:04:55 -06:00
|
|
|
xfs_agnumber_t agno, xfs_agblock_t agbno,
|
|
|
|
xfs_agblock_t length, unsigned int gen);
|
|
|
|
|
2014-11-27 20:25:04 -07:00
|
|
|
int xfs_read_agi(struct xfs_mount *mp, struct xfs_trans *tp,
|
|
|
|
xfs_agnumber_t agno, struct xfs_buf **bpp);
|
|
|
|
|
2017-06-16 12:00:08 -06:00
|
|
|
union xfs_btree_rec;
|
|
|
|
void xfs_inobt_btrec_to_irec(struct xfs_mount *mp, union xfs_btree_rec *rec,
|
|
|
|
struct xfs_inobt_rec_incore *irec);
|
|
|
|
|
|
|
|
int xfs_ialloc_cluster_alignment(struct xfs_mount *mp);
|
2017-10-17 22:37:34 -06:00
|
|
|
void xfs_ialloc_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno,
|
|
|
|
xfs_agino_t *first, xfs_agino_t *last);
|
|
|
|
bool xfs_verify_agino(struct xfs_mount *mp, xfs_agnumber_t agno,
|
|
|
|
xfs_agino_t agino);
|
|
|
|
bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
|
|
|
|
bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
|
|
|
|
bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
|
2014-11-27 20:25:04 -07:00
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#endif /* __XFS_IALLOC_H__ */
|