2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2006-06-09 11:48:12 +07:00
|
|
|
* Copyright (c) 2000-2006 Silicon Graphics, Inc.
|
2005-11-02 10:58:39 +07:00
|
|
|
* All Rights Reserved.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2005-11-02 10: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-17 05:20:36 +07:00
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2005-11-02 10: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-17 05:20:36 +07:00
|
|
|
*
|
2005-11-02 10: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-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_BMAP_H__
|
|
|
|
#define __XFS_BMAP_H__
|
|
|
|
|
|
|
|
struct getbmap;
|
|
|
|
struct xfs_bmbt_irec;
|
2006-03-14 09:29:52 +07:00
|
|
|
struct xfs_ifork;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct xfs_inode;
|
|
|
|
struct xfs_mount;
|
|
|
|
struct xfs_trans;
|
|
|
|
|
2007-11-23 12:28:09 +07:00
|
|
|
extern kmem_zone_t *xfs_bmap_free_item_zone;
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* List of extents to be free "later".
|
|
|
|
* The list is kept sorted on xbf_startblock.
|
|
|
|
*/
|
|
|
|
typedef struct xfs_bmap_free_item
|
|
|
|
{
|
|
|
|
xfs_fsblock_t xbfi_startblock;/* starting fs block number */
|
|
|
|
xfs_extlen_t xbfi_blockcount;/* number of blocks in extent */
|
|
|
|
struct xfs_bmap_free_item *xbfi_next; /* link to next entry */
|
|
|
|
} xfs_bmap_free_item_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Header for free extent list.
|
2008-06-27 10:33:03 +07:00
|
|
|
*
|
|
|
|
* xbf_low is used by the allocator to activate the lowspace algorithm -
|
|
|
|
* when free space is running low the extent allocator may choose to
|
|
|
|
* allocate an extent from an AG without leaving sufficient space for
|
|
|
|
* a btree split when inserting the new extent. In this case the allocator
|
|
|
|
* will enable the lowspace algorithm which is supposed to allow further
|
|
|
|
* allocations (such as btree splits and newroots) to allocate from
|
|
|
|
* sequential AGs. In order to avoid locking AGs out of order the lowspace
|
|
|
|
* algorithm will start searching for free space from AG 0. If the correct
|
|
|
|
* transaction reservations have been made then this algorithm will eventually
|
|
|
|
* find all the space it needs.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
typedef struct xfs_bmap_free
|
|
|
|
{
|
|
|
|
xfs_bmap_free_item_t *xbf_first; /* list of to-be-free extents */
|
|
|
|
int xbf_count; /* count of items on list */
|
2008-06-27 10:33:03 +07:00
|
|
|
int xbf_low; /* alloc in low mode */
|
2005-04-17 05:20:36 +07:00
|
|
|
} xfs_bmap_free_t;
|
|
|
|
|
|
|
|
#define XFS_BMAP_MAX_NMAP 4
|
|
|
|
|
|
|
|
/*
|
2011-09-19 03:40:52 +07:00
|
|
|
* Flags for xfs_bmapi_*
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2011-09-19 03:40:52 +07:00
|
|
|
#define XFS_BMAPI_ENTIRE 0x001 /* return entire extent, not trimmed */
|
|
|
|
#define XFS_BMAPI_METADATA 0x002 /* mapping metadata not user data */
|
|
|
|
#define XFS_BMAPI_ATTRFORK 0x004 /* use attribute fork not data */
|
|
|
|
#define XFS_BMAPI_PREALLOC 0x008 /* preallocation op: unwritten space */
|
|
|
|
#define XFS_BMAPI_IGSTATE 0x010 /* Ignore state - */
|
2005-04-17 05:20:36 +07:00
|
|
|
/* combine contig. space */
|
2011-09-19 03:40:52 +07:00
|
|
|
#define XFS_BMAPI_CONTIG 0x020 /* must allocate only one extent */
|
2010-08-24 09:02:11 +07:00
|
|
|
/*
|
|
|
|
* unwritten extent conversion - this needs write cache flushing and no additional
|
|
|
|
* allocation alignments. When specified with XFS_BMAPI_PREALLOC it converts
|
|
|
|
* from written to unwritten, otherwise convert from unwritten to written.
|
|
|
|
*/
|
2011-09-19 03:40:52 +07:00
|
|
|
#define XFS_BMAPI_CONVERT 0x040
|
2012-10-05 08:06:58 +07:00
|
|
|
#define XFS_BMAPI_STACK_SWITCH 0x080
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-12-15 06:14:59 +07:00
|
|
|
#define XFS_BMAPI_FLAGS \
|
|
|
|
{ XFS_BMAPI_ENTIRE, "ENTIRE" }, \
|
|
|
|
{ XFS_BMAPI_METADATA, "METADATA" }, \
|
|
|
|
{ XFS_BMAPI_ATTRFORK, "ATTRFORK" }, \
|
|
|
|
{ XFS_BMAPI_PREALLOC, "PREALLOC" }, \
|
|
|
|
{ XFS_BMAPI_IGSTATE, "IGSTATE" }, \
|
|
|
|
{ XFS_BMAPI_CONTIG, "CONTIG" }, \
|
2012-10-05 08:06:58 +07:00
|
|
|
{ XFS_BMAPI_CONVERT, "CONVERT" }, \
|
|
|
|
{ XFS_BMAPI_STACK_SWITCH, "STACK_SWITCH" }
|
2009-12-15 06:14:59 +07:00
|
|
|
|
|
|
|
|
2005-11-02 10:38:42 +07:00
|
|
|
static inline int xfs_bmapi_aflag(int w)
|
|
|
|
{
|
|
|
|
return (w == XFS_ATTR_FORK ? XFS_BMAPI_ATTRFORK : 0);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Special values for xfs_bmbt_irec_t br_startblock field.
|
|
|
|
*/
|
|
|
|
#define DELAYSTARTBLOCK ((xfs_fsblock_t)-1LL)
|
|
|
|
#define HOLESTARTBLOCK ((xfs_fsblock_t)-2LL)
|
|
|
|
|
2005-11-02 10:38:42 +07:00
|
|
|
static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp)
|
|
|
|
{
|
2005-04-17 05:20:36 +07:00
|
|
|
((flp)->xbf_first = NULL, (flp)->xbf_count = 0, \
|
2005-11-02 10:38:42 +07:00
|
|
|
(flp)->xbf_low = 0, *(fbp) = NULLFSBLOCK);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Argument structure for xfs_bmap_alloc.
|
|
|
|
*/
|
|
|
|
typedef struct xfs_bmalloca {
|
2011-09-19 03:40:57 +07:00
|
|
|
xfs_fsblock_t *firstblock; /* i/o first block allocated */
|
|
|
|
struct xfs_bmap_free *flist; /* bmap freelist */
|
2005-04-17 05:20:36 +07:00
|
|
|
struct xfs_trans *tp; /* transaction pointer */
|
|
|
|
struct xfs_inode *ip; /* incore inode pointer */
|
2011-09-19 03:40:56 +07:00
|
|
|
struct xfs_bmbt_irec prev; /* extent before the new one */
|
|
|
|
struct xfs_bmbt_irec got; /* extent after, or delayed */
|
2011-09-19 03:40:58 +07:00
|
|
|
|
|
|
|
xfs_fileoff_t offset; /* offset in file filling in */
|
|
|
|
xfs_extlen_t length; /* i/o length asked/allocated */
|
|
|
|
xfs_fsblock_t blkno; /* starting block of new extent */
|
|
|
|
|
2011-09-19 03:41:00 +07:00
|
|
|
struct xfs_btree_cur *cur; /* btree cursor */
|
2011-09-19 03:41:01 +07:00
|
|
|
xfs_extnum_t idx; /* current extent index */
|
|
|
|
int nallocs;/* number of extents alloc'd */
|
2011-09-19 03:41:02 +07:00
|
|
|
int logflags;/* flags for transaction logging */
|
2011-09-19 03:41:00 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_extlen_t total; /* total blocks needed for xaction */
|
2009-03-29 14:55:42 +07:00
|
|
|
xfs_extlen_t minlen; /* minimum allocation size (blocks) */
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_extlen_t minleft; /* amount must be left after alloc */
|
|
|
|
char eof; /* set if allocating past last extent */
|
|
|
|
char wasdel; /* replacing a delayed allocation */
|
|
|
|
char userdata;/* set if is user data */
|
2006-01-11 11:28:28 +07:00
|
|
|
char aeof; /* allocated space at eof */
|
|
|
|
char conv; /* overwriting unwritten extents */
|
2012-10-05 08:06:58 +07:00
|
|
|
char stack_switch;
|
2012-10-05 08:06:59 +07:00
|
|
|
int flags;
|
|
|
|
struct completion *done;
|
|
|
|
struct work_struct work;
|
|
|
|
int result;
|
2005-04-17 05:20:36 +07:00
|
|
|
} xfs_bmalloca_t;
|
|
|
|
|
2009-11-25 07:00:19 +07:00
|
|
|
/*
|
|
|
|
* Flags for xfs_bmap_add_extent*.
|
|
|
|
*/
|
|
|
|
#define BMAP_LEFT_CONTIG (1 << 0)
|
|
|
|
#define BMAP_RIGHT_CONTIG (1 << 1)
|
|
|
|
#define BMAP_LEFT_FILLING (1 << 2)
|
|
|
|
#define BMAP_RIGHT_FILLING (1 << 3)
|
|
|
|
#define BMAP_LEFT_DELAY (1 << 4)
|
|
|
|
#define BMAP_RIGHT_DELAY (1 << 5)
|
|
|
|
#define BMAP_LEFT_VALID (1 << 6)
|
|
|
|
#define BMAP_RIGHT_VALID (1 << 7)
|
2009-11-25 07:00:21 +07:00
|
|
|
#define BMAP_ATTRFORK (1 << 8)
|
2009-11-25 07:00:19 +07:00
|
|
|
|
2009-12-15 06:14:59 +07:00
|
|
|
#define XFS_BMAP_EXT_FLAGS \
|
|
|
|
{ BMAP_LEFT_CONTIG, "LC" }, \
|
|
|
|
{ BMAP_RIGHT_CONTIG, "RC" }, \
|
|
|
|
{ BMAP_LEFT_FILLING, "LF" }, \
|
|
|
|
{ BMAP_RIGHT_FILLING, "RF" }, \
|
|
|
|
{ BMAP_ATTRFORK, "ATTR" }
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-12-15 06:14:59 +07:00
|
|
|
#if defined(__KERNEL) && defined(DEBUG)
|
2011-09-19 03:41:07 +07:00
|
|
|
void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt,
|
|
|
|
int whichfork, unsigned long caller_ip);
|
2007-07-11 08:09:47 +07:00
|
|
|
#define XFS_BMAP_TRACE_EXLIST(ip,c,w) \
|
2009-12-15 06:14:59 +07:00
|
|
|
xfs_bmap_trace_exlist(ip,c,w, _THIS_IP_)
|
|
|
|
#else
|
2007-07-11 08:09:47 +07:00
|
|
|
#define XFS_BMAP_TRACE_EXLIST(ip,c,w)
|
2009-12-15 06:14:59 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-09-19 03:41:07 +07:00
|
|
|
int xfs_bmap_add_attrfork(struct xfs_inode *ip, int size, int rsvd);
|
|
|
|
void xfs_bmap_add_free(xfs_fsblock_t bno, xfs_filblks_t len,
|
|
|
|
struct xfs_bmap_free *flist, struct xfs_mount *mp);
|
|
|
|
void xfs_bmap_cancel(struct xfs_bmap_free *flist);
|
|
|
|
void xfs_bmap_compute_maxlevels(struct xfs_mount *mp, int whichfork);
|
|
|
|
int xfs_bmap_first_unused(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
xfs_extlen_t len, xfs_fileoff_t *unused, int whichfork);
|
|
|
|
int xfs_bmap_last_before(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
xfs_fileoff_t *last_block, int whichfork);
|
|
|
|
int xfs_bmap_last_offset(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
xfs_fileoff_t *unused, int whichfork);
|
|
|
|
int xfs_bmap_one_block(struct xfs_inode *ip, int whichfork);
|
|
|
|
int xfs_bmap_read_extents(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
int whichfork);
|
2011-09-19 03:40:45 +07:00
|
|
|
int xfs_bmapi_read(struct xfs_inode *ip, xfs_fileoff_t bno,
|
|
|
|
xfs_filblks_t len, struct xfs_bmbt_irec *mval,
|
|
|
|
int *nmap, int flags);
|
2011-09-19 03:40:48 +07:00
|
|
|
int xfs_bmapi_delay(struct xfs_inode *ip, xfs_fileoff_t bno,
|
|
|
|
xfs_filblks_t len, struct xfs_bmbt_irec *mval,
|
|
|
|
int *nmap, int flags);
|
2011-09-19 03:40:52 +07:00
|
|
|
int xfs_bmapi_write(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
xfs_fileoff_t bno, xfs_filblks_t len, int flags,
|
|
|
|
xfs_fsblock_t *firstblock, xfs_extlen_t total,
|
|
|
|
struct xfs_bmbt_irec *mval, int *nmap,
|
|
|
|
struct xfs_bmap_free *flist);
|
2011-09-19 03:41:07 +07:00
|
|
|
int xfs_bunmapi(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
xfs_fileoff_t bno, xfs_filblks_t len, int flags,
|
|
|
|
xfs_extnum_t nexts, xfs_fsblock_t *firstblock,
|
|
|
|
struct xfs_bmap_free *flist, int *done);
|
|
|
|
int xfs_check_nostate_extents(struct xfs_ifork *ifp, xfs_extnum_t idx,
|
|
|
|
xfs_extnum_t num);
|
|
|
|
uint xfs_default_attroffset(struct xfs_inode *ip);
|
2009-03-30 00:26:46 +07:00
|
|
|
|
2008-10-30 13:05:38 +07:00
|
|
|
#ifdef __KERNEL__
|
2008-11-28 10:23:35 +07:00
|
|
|
/* bmap to userspace formatter - copy to user & advance pointer */
|
|
|
|
typedef int (*xfs_bmap_format_t)(void **, struct getbmapx *, int *);
|
|
|
|
|
2011-09-19 03:41:07 +07:00
|
|
|
int xfs_bmap_finish(struct xfs_trans **tp, struct xfs_bmap_free *flist,
|
|
|
|
int *committed);
|
|
|
|
int xfs_getbmap(struct xfs_inode *ip, struct getbmapx *bmv,
|
|
|
|
xfs_bmap_format_t formatter, void *arg);
|
|
|
|
int xfs_bmap_eof(struct xfs_inode *ip, xfs_fileoff_t endoff,
|
|
|
|
int whichfork, int *eof);
|
|
|
|
int xfs_bmap_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip,
|
|
|
|
int whichfork, int *count);
|
|
|
|
int xfs_bmap_punch_delalloc_range(struct xfs_inode *ip,
|
|
|
|
xfs_fileoff_t start_fsb, xfs_fileoff_t length);
|
2012-04-23 12:59:01 +07:00
|
|
|
|
|
|
|
xfs_daddr_t xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* __XFS_BMAP_H__ */
|