2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2006-06-09 04:48:12 +00:00
|
|
|
* Copyright (c) 2000-2006 Silicon Graphics, Inc.
|
2005-11-02 03:58:39 +00:00
|
|
|
* All Rights Reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2005-11-02 03:58:39 +00: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 22:20:36 +00:00
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2005-11-02 03:58:39 +00: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 22:20:36 +00:00
|
|
|
*
|
2005-11-02 03:58:39 +00: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 22:20:36 +00:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_BMAP_H__
|
|
|
|
#define __XFS_BMAP_H__
|
|
|
|
|
|
|
|
struct getbmap;
|
|
|
|
struct xfs_bmbt_irec;
|
2006-03-14 02:29:52 +00:00
|
|
|
struct xfs_ifork;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct xfs_inode;
|
|
|
|
struct xfs_mount;
|
|
|
|
struct xfs_trans;
|
|
|
|
|
2007-11-23 05:28:09 +00:00
|
|
|
extern kmem_zone_t *xfs_bmap_free_item_zone;
|
|
|
|
|
2005-04-16 22:20:36 +00: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 03:33:03 +00: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-16 22:20:36 +00: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 03:33:03 +00:00
|
|
|
int xbf_low; /* alloc in low mode */
|
2005-04-16 22:20:36 +00:00
|
|
|
} xfs_bmap_free_t;
|
|
|
|
|
|
|
|
#define XFS_BMAP_MAX_NMAP 4
|
|
|
|
|
|
|
|
/*
|
2011-09-18 20:40:52 +00:00
|
|
|
* Flags for xfs_bmapi_*
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2011-09-18 20:40:52 +00: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-16 22:20:36 +00:00
|
|
|
/* combine contig. space */
|
2011-09-18 20:40:52 +00:00
|
|
|
#define XFS_BMAPI_CONTIG 0x020 /* must allocate only one extent */
|
2010-08-24 02:02:11 +00: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-18 20:40:52 +00:00
|
|
|
#define XFS_BMAPI_CONVERT 0x040
|
2012-10-05 01:06:58 +00:00
|
|
|
#define XFS_BMAPI_STACK_SWITCH 0x080
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-12-14 23:14:59 +00: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 01:06:58 +00:00
|
|
|
{ XFS_BMAPI_CONVERT, "CONVERT" }, \
|
|
|
|
{ XFS_BMAPI_STACK_SWITCH, "STACK_SWITCH" }
|
2009-12-14 23:14:59 +00:00
|
|
|
|
|
|
|
|
2005-11-02 03:38:42 +00:00
|
|
|
static inline int xfs_bmapi_aflag(int w)
|
|
|
|
{
|
|
|
|
return (w == XFS_ATTR_FORK ? XFS_BMAPI_ATTRFORK : 0);
|
|
|
|
}
|
2005-04-16 22:20:36 +00: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 03:38:42 +00:00
|
|
|
static inline void xfs_bmap_init(xfs_bmap_free_t *flp, xfs_fsblock_t *fbp)
|
|
|
|
{
|
2005-04-16 22:20:36 +00:00
|
|
|
((flp)->xbf_first = NULL, (flp)->xbf_count = 0, \
|
2005-11-02 03:38:42 +00:00
|
|
|
(flp)->xbf_low = 0, *(fbp) = NULLFSBLOCK);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Argument structure for xfs_bmap_alloc.
|
|
|
|
*/
|
|
|
|
typedef struct xfs_bmalloca {
|
2011-09-18 20:40:57 +00:00
|
|
|
xfs_fsblock_t *firstblock; /* i/o first block allocated */
|
|
|
|
struct xfs_bmap_free *flist; /* bmap freelist */
|
2005-04-16 22:20:36 +00:00
|
|
|
struct xfs_trans *tp; /* transaction pointer */
|
|
|
|
struct xfs_inode *ip; /* incore inode pointer */
|
2011-09-18 20:40:56 +00:00
|
|
|
struct xfs_bmbt_irec prev; /* extent before the new one */
|
|
|
|
struct xfs_bmbt_irec got; /* extent after, or delayed */
|
2011-09-18 20:40:58 +00: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-18 20:41:00 +00:00
|
|
|
struct xfs_btree_cur *cur; /* btree cursor */
|
2011-09-18 20:41:01 +00:00
|
|
|
xfs_extnum_t idx; /* current extent index */
|
|
|
|
int nallocs;/* number of extents alloc'd */
|
2011-09-18 20:41:02 +00:00
|
|
|
int logflags;/* flags for transaction logging */
|
2011-09-18 20:41:00 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
xfs_extlen_t total; /* total blocks needed for xaction */
|
2009-03-29 07:55:42 +00:00
|
|
|
xfs_extlen_t minlen; /* minimum allocation size (blocks) */
|
2005-04-16 22:20:36 +00: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 04:28:28 +00:00
|
|
|
char aeof; /* allocated space at eof */
|
|
|
|
char conv; /* overwriting unwritten extents */
|
2012-10-05 01:06:58 +00:00
|
|
|
char stack_switch;
|
2012-10-05 01:06:59 +00:00
|
|
|
int flags;
|
|
|
|
struct completion *done;
|
|
|
|
struct work_struct work;
|
|
|
|
int result;
|
2005-04-16 22:20:36 +00:00
|
|
|
} xfs_bmalloca_t;
|
|
|
|
|
2009-11-25 00:00:19 +00: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 00:00:21 +00:00
|
|
|
#define BMAP_ATTRFORK (1 << 8)
|
2009-11-25 00:00:19 +00:00
|
|
|
|
2009-12-14 23:14:59 +00: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-16 22:20:36 +00:00
|
|
|
|
2009-12-14 23:14:59 +00:00
|
|
|
#if defined(__KERNEL) && defined(DEBUG)
|
2011-09-18 20:41:07 +00:00
|
|
|
void xfs_bmap_trace_exlist(struct xfs_inode *ip, xfs_extnum_t cnt,
|
|
|
|
int whichfork, unsigned long caller_ip);
|
2007-07-11 01:09:47 +00:00
|
|
|
#define XFS_BMAP_TRACE_EXLIST(ip,c,w) \
|
2009-12-14 23:14:59 +00:00
|
|
|
xfs_bmap_trace_exlist(ip,c,w, _THIS_IP_)
|
|
|
|
#else
|
2007-07-11 01:09:47 +00:00
|
|
|
#define XFS_BMAP_TRACE_EXLIST(ip,c,w)
|
2009-12-14 23:14:59 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-09-18 20:41:07 +00: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-18 20:40:45 +00: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-18 20:40:48 +00: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-18 20:40:52 +00: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-18 20:41:07 +00: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-29 17:26:46 +00:00
|
|
|
|
2008-10-30 06:05:38 +00:00
|
|
|
#ifdef __KERNEL__
|
2008-11-28 03:23:35 +00:00
|
|
|
/* bmap to userspace formatter - copy to user & advance pointer */
|
|
|
|
typedef int (*xfs_bmap_format_t)(void **, struct getbmapx *, int *);
|
|
|
|
|
2011-09-18 20:41:07 +00: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 05:59:01 +00:00
|
|
|
|
|
|
|
xfs_daddr_t xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* __KERNEL__ */
|
|
|
|
|
|
|
|
#endif /* __XFS_BMAP_H__ */
|