1153323Srodrigc/* 2159451Srodrigc * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. 3159451Srodrigc * All Rights Reserved. 4153323Srodrigc * 5159451Srodrigc * This program is free software; you can redistribute it and/or 6159451Srodrigc * modify it under the terms of the GNU General Public License as 7153323Srodrigc * published by the Free Software Foundation. 8153323Srodrigc * 9159451Srodrigc * This program is distributed in the hope that it would be useful, 10159451Srodrigc * but WITHOUT ANY WARRANTY; without even the implied warranty of 11159451Srodrigc * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12159451Srodrigc * GNU General Public License for more details. 13153323Srodrigc * 14159451Srodrigc * You should have received a copy of the GNU General Public License 15159451Srodrigc * along with this program; if not, write the Free Software Foundation, 16159451Srodrigc * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17153323Srodrigc */ 18153323Srodrigc#ifndef __XFS_ALLOC_H__ 19153323Srodrigc#define __XFS_ALLOC_H__ 20153323Srodrigc 21153323Srodrigcstruct xfs_buf; 22153323Srodrigcstruct xfs_mount; 23153323Srodrigcstruct xfs_perag; 24153323Srodrigcstruct xfs_trans; 25153323Srodrigc 26153323Srodrigc/* 27153323Srodrigc * Freespace allocation types. Argument to xfs_alloc_[v]extent. 28153323Srodrigc */ 29153323Srodrigctypedef enum xfs_alloctype 30153323Srodrigc{ 31153323Srodrigc XFS_ALLOCTYPE_ANY_AG, /* allocate anywhere, use rotor */ 32153323Srodrigc XFS_ALLOCTYPE_FIRST_AG, /* ... start at ag 0 */ 33153323Srodrigc XFS_ALLOCTYPE_START_AG, /* anywhere, start in this a.g. */ 34153323Srodrigc XFS_ALLOCTYPE_THIS_AG, /* anywhere in this a.g. */ 35153323Srodrigc XFS_ALLOCTYPE_START_BNO, /* near this block else anywhere */ 36153323Srodrigc XFS_ALLOCTYPE_NEAR_BNO, /* in this a.g. and near this block */ 37153323Srodrigc XFS_ALLOCTYPE_THIS_BNO /* at exactly this block */ 38153323Srodrigc} xfs_alloctype_t; 39153323Srodrigc 40153323Srodrigc/* 41153323Srodrigc * Flags for xfs_alloc_fix_freelist. 42153323Srodrigc */ 43153323Srodrigc#define XFS_ALLOC_FLAG_TRYLOCK 0x00000001 /* use trylock for buffer locking */ 44153323Srodrigc 45153323Srodrigc/* 46153323Srodrigc * Argument structure for xfs_alloc routines. 47153323Srodrigc * This is turned into a structure to avoid having 20 arguments passed 48153323Srodrigc * down several levels of the stack. 49153323Srodrigc */ 50153323Srodrigctypedef struct xfs_alloc_arg { 51153323Srodrigc struct xfs_trans *tp; /* transaction pointer */ 52153323Srodrigc struct xfs_mount *mp; /* file system mount point */ 53153323Srodrigc struct xfs_buf *agbp; /* buffer for a.g. freelist header */ 54153323Srodrigc struct xfs_perag *pag; /* per-ag struct for this agno */ 55153323Srodrigc xfs_fsblock_t fsbno; /* file system block number */ 56153323Srodrigc xfs_agnumber_t agno; /* allocation group number */ 57153323Srodrigc xfs_agblock_t agbno; /* allocation group-relative block # */ 58153323Srodrigc xfs_extlen_t minlen; /* minimum size of extent */ 59153323Srodrigc xfs_extlen_t maxlen; /* maximum size of extent */ 60153323Srodrigc xfs_extlen_t mod; /* mod value for extent size */ 61153323Srodrigc xfs_extlen_t prod; /* prod value for extent size */ 62153323Srodrigc xfs_extlen_t minleft; /* min blocks must be left after us */ 63153323Srodrigc xfs_extlen_t total; /* total blocks needed in xaction */ 64153323Srodrigc xfs_extlen_t alignment; /* align answer to multiple of this */ 65153323Srodrigc xfs_extlen_t minalignslop; /* slop for minlen+alignment calcs */ 66153323Srodrigc xfs_extlen_t len; /* output: actual size of extent */ 67153323Srodrigc xfs_alloctype_t type; /* allocation type XFS_ALLOCTYPE_... */ 68153323Srodrigc xfs_alloctype_t otype; /* original allocation type */ 69153323Srodrigc char wasdel; /* set if allocation was prev delayed */ 70153323Srodrigc char wasfromfl; /* set if allocation is from freelist */ 71159451Srodrigc char isfl; /* set if is freelist blocks - !acctg */ 72153323Srodrigc char userdata; /* set if this is user data */ 73153323Srodrigc} xfs_alloc_arg_t; 74153323Srodrigc 75153323Srodrigc/* 76153323Srodrigc * Defines for userdata 77153323Srodrigc */ 78153323Srodrigc#define XFS_ALLOC_USERDATA 1 /* allocation is for user data*/ 79153323Srodrigc#define XFS_ALLOC_INITIAL_USER_DATA 2 /* special case start of file */ 80153323Srodrigc 81153323Srodrigc 82153323Srodrigc#ifdef __KERNEL__ 83153323Srodrigc 84153323Srodrigc#if defined(XFS_ALLOC_TRACE) 85153323Srodrigc/* 86153323Srodrigc * Allocation tracing buffer size. 87153323Srodrigc */ 88153323Srodrigc#define XFS_ALLOC_TRACE_SIZE 4096 89153323Srodrigcextern ktrace_t *xfs_alloc_trace_buf; 90153323Srodrigc 91153323Srodrigc/* 92153323Srodrigc * Types for alloc tracing. 93153323Srodrigc */ 94153323Srodrigc#define XFS_ALLOC_KTRACE_ALLOC 1 95153323Srodrigc#define XFS_ALLOC_KTRACE_FREE 2 96153323Srodrigc#define XFS_ALLOC_KTRACE_MODAGF 3 97153323Srodrigc#define XFS_ALLOC_KTRACE_BUSY 4 98153323Srodrigc#define XFS_ALLOC_KTRACE_UNBUSY 5 99153323Srodrigc#define XFS_ALLOC_KTRACE_BUSYSEARCH 6 100153323Srodrigc#endif 101153323Srodrigc 102153323Srodrigc/* 103153323Srodrigc * Compute and fill in value of m_ag_maxlevels. 104153323Srodrigc */ 105153323Srodrigcvoid 106153323Srodrigcxfs_alloc_compute_maxlevels( 107153323Srodrigc struct xfs_mount *mp); /* file system mount structure */ 108153323Srodrigc 109153323Srodrigc/* 110153323Srodrigc * Get a block from the freelist. 111153323Srodrigc * Returns with the buffer for the block gotten. 112153323Srodrigc */ 113153323Srodrigcint /* error */ 114153323Srodrigcxfs_alloc_get_freelist( 115153323Srodrigc struct xfs_trans *tp, /* transaction pointer */ 116153323Srodrigc struct xfs_buf *agbp, /* buffer containing the agf structure */ 117153323Srodrigc xfs_agblock_t *bnop); /* block address retrieved from freelist */ 118153323Srodrigc 119153323Srodrigc/* 120153323Srodrigc * Log the given fields from the agf structure. 121153323Srodrigc */ 122153323Srodrigcvoid 123153323Srodrigcxfs_alloc_log_agf( 124153323Srodrigc struct xfs_trans *tp, /* transaction pointer */ 125153323Srodrigc struct xfs_buf *bp, /* buffer for a.g. freelist header */ 126153323Srodrigc int fields);/* mask of fields to be logged (XFS_AGF_...) */ 127153323Srodrigc 128153323Srodrigc/* 129153323Srodrigc * Interface for inode allocation to force the pag data to be initialized. 130153323Srodrigc */ 131153323Srodrigcint /* error */ 132153323Srodrigcxfs_alloc_pagf_init( 133153323Srodrigc struct xfs_mount *mp, /* file system mount structure */ 134153323Srodrigc struct xfs_trans *tp, /* transaction pointer */ 135153323Srodrigc xfs_agnumber_t agno, /* allocation group number */ 136153323Srodrigc int flags); /* XFS_ALLOC_FLAGS_... */ 137153323Srodrigc 138153323Srodrigc/* 139153323Srodrigc * Put the block on the freelist for the allocation group. 140153323Srodrigc */ 141153323Srodrigcint /* error */ 142153323Srodrigcxfs_alloc_put_freelist( 143153323Srodrigc struct xfs_trans *tp, /* transaction pointer */ 144153323Srodrigc struct xfs_buf *agbp, /* buffer for a.g. freelist header */ 145153323Srodrigc struct xfs_buf *agflbp,/* buffer for a.g. free block array */ 146153323Srodrigc xfs_agblock_t bno); /* block being freed */ 147153323Srodrigc 148153323Srodrigc/* 149153323Srodrigc * Read in the allocation group header (free/alloc section). 150153323Srodrigc */ 151153323Srodrigcint /* error */ 152153323Srodrigcxfs_alloc_read_agf( 153153323Srodrigc struct xfs_mount *mp, /* mount point structure */ 154153323Srodrigc struct xfs_trans *tp, /* transaction pointer */ 155153323Srodrigc xfs_agnumber_t agno, /* allocation group number */ 156153323Srodrigc int flags, /* XFS_ALLOC_FLAG_... */ 157153323Srodrigc struct xfs_buf **bpp); /* buffer for the ag freelist header */ 158153323Srodrigc 159153323Srodrigc/* 160153323Srodrigc * Allocate an extent (variable-size). 161153323Srodrigc */ 162153323Srodrigcint /* error */ 163153323Srodrigcxfs_alloc_vextent( 164153323Srodrigc xfs_alloc_arg_t *args); /* allocation argument structure */ 165153323Srodrigc 166153323Srodrigc/* 167153323Srodrigc * Free an extent. 168153323Srodrigc */ 169153323Srodrigcint /* error */ 170153323Srodrigcxfs_free_extent( 171153323Srodrigc struct xfs_trans *tp, /* transaction pointer */ 172153323Srodrigc xfs_fsblock_t bno, /* starting block number of extent */ 173153323Srodrigc xfs_extlen_t len); /* length of extent */ 174153323Srodrigc 175153323Srodrigcvoid 176153323Srodrigcxfs_alloc_mark_busy(xfs_trans_t *tp, 177153323Srodrigc xfs_agnumber_t agno, 178153323Srodrigc xfs_agblock_t bno, 179153323Srodrigc xfs_extlen_t len); 180153323Srodrigc 181153323Srodrigcvoid 182153323Srodrigcxfs_alloc_clear_busy(xfs_trans_t *tp, 183153323Srodrigc xfs_agnumber_t ag, 184153323Srodrigc int idx); 185153323Srodrigc 186153323Srodrigc 187153323Srodrigc#endif /* __KERNEL__ */ 188153323Srodrigc 189153323Srodrigc#endif /* __XFS_ALLOC_H__ */ 190