11da177e4SLinus Torvalds /* 27b718769SNathan Scott * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc. 37b718769SNathan Scott * All Rights Reserved. 41da177e4SLinus Torvalds * 57b718769SNathan Scott * This program is free software; you can redistribute it and/or 67b718769SNathan Scott * modify it under the terms of the GNU General Public License as 71da177e4SLinus Torvalds * published by the Free Software Foundation. 81da177e4SLinus Torvalds * 97b718769SNathan Scott * This program is distributed in the hope that it would be useful, 107b718769SNathan Scott * but WITHOUT ANY WARRANTY; without even the implied warranty of 117b718769SNathan Scott * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 127b718769SNathan Scott * GNU General Public License for more details. 131da177e4SLinus Torvalds * 147b718769SNathan Scott * You should have received a copy of the GNU General Public License 157b718769SNathan Scott * along with this program; if not, write the Free Software Foundation, 167b718769SNathan Scott * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 171da177e4SLinus Torvalds */ 181da177e4SLinus Torvalds #ifndef __XFS_RTALLOC_H__ 191da177e4SLinus Torvalds #define __XFS_RTALLOC_H__ 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds struct xfs_mount; 221da177e4SLinus Torvalds struct xfs_trans; 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds /* Min and max rt extent sizes, specified in bytes */ 251da177e4SLinus Torvalds #define XFS_MAX_RTEXTSIZE (1024 * 1024 * 1024) /* 1GB */ 269da096fdSMalcolm Parsons #define XFS_DFL_RTEXTSIZE (64 * 1024) /* 64kB */ 279da096fdSMalcolm Parsons #define XFS_MIN_RTEXTSIZE (4 * 1024) /* 4kB */ 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds /* 301da177e4SLinus Torvalds * Constants for bit manipulations. 311da177e4SLinus Torvalds */ 321da177e4SLinus Torvalds #define XFS_NBBYLOG 3 /* log2(NBBY) */ 331da177e4SLinus Torvalds #define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */ 341da177e4SLinus Torvalds #define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG) 351da177e4SLinus Torvalds #define XFS_NBWORD (1 << XFS_NBWORDLOG) 361da177e4SLinus Torvalds #define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1) 371da177e4SLinus Torvalds 381da177e4SLinus Torvalds #define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize) 391da177e4SLinus Torvalds #define XFS_BLOCKMASK(mp) ((mp)->m_blockmask) 401da177e4SLinus Torvalds #define XFS_BLOCKWSIZE(mp) ((mp)->m_blockwsize) 411da177e4SLinus Torvalds #define XFS_BLOCKWMASK(mp) ((mp)->m_blockwmask) 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds /* 441da177e4SLinus Torvalds * Summary and bit manipulation macros. 451da177e4SLinus Torvalds */ 461da177e4SLinus Torvalds #define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb))) 471da177e4SLinus Torvalds #define XFS_SUMOFFSTOBLOCK(mp,s) \ 481da177e4SLinus Torvalds (((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog) 491da177e4SLinus Torvalds #define XFS_SUMPTR(mp,bp,so) \ 501da177e4SLinus Torvalds ((xfs_suminfo_t *)((char *)XFS_BUF_PTR(bp) + \ 511da177e4SLinus Torvalds (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp)))) 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds #define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log) 541da177e4SLinus Torvalds #define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log) 551da177e4SLinus Torvalds #define XFS_BITTOWORD(mp,bi) \ 561da177e4SLinus Torvalds ((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp))) 571da177e4SLinus Torvalds 581da177e4SLinus Torvalds #define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b)) 591da177e4SLinus Torvalds #define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b)) 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds #define XFS_RTLOBIT(w) xfs_lowbit32(w) 621da177e4SLinus Torvalds #define XFS_RTHIBIT(w) xfs_highbit32(w) 631da177e4SLinus Torvalds 641da177e4SLinus Torvalds #if XFS_BIG_BLKNOS 651da177e4SLinus Torvalds #define XFS_RTBLOCKLOG(b) xfs_highbit64(b) 661da177e4SLinus Torvalds #else 671da177e4SLinus Torvalds #define XFS_RTBLOCKLOG(b) xfs_highbit32(b) 681da177e4SLinus Torvalds #endif 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds #ifdef __KERNEL__ 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds #ifdef CONFIG_XFS_RT 741da177e4SLinus Torvalds /* 751da177e4SLinus Torvalds * Function prototypes for exported functions. 761da177e4SLinus Torvalds */ 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* 791da177e4SLinus Torvalds * Allocate an extent in the realtime subvolume, with the usual allocation 801da177e4SLinus Torvalds * parameters. The length units are all in realtime extents, as is the 811da177e4SLinus Torvalds * result block number. 821da177e4SLinus Torvalds */ 831da177e4SLinus Torvalds int /* error */ 841da177e4SLinus Torvalds xfs_rtallocate_extent( 851da177e4SLinus Torvalds struct xfs_trans *tp, /* transaction pointer */ 861da177e4SLinus Torvalds xfs_rtblock_t bno, /* starting block number to allocate */ 871da177e4SLinus Torvalds xfs_extlen_t minlen, /* minimum length to allocate */ 881da177e4SLinus Torvalds xfs_extlen_t maxlen, /* maximum length to allocate */ 891da177e4SLinus Torvalds xfs_extlen_t *len, /* out: actual length allocated */ 901da177e4SLinus Torvalds xfs_alloctype_t type, /* allocation type XFS_ALLOCTYPE... */ 911da177e4SLinus Torvalds int wasdel, /* was a delayed allocation extent */ 921da177e4SLinus Torvalds xfs_extlen_t prod, /* extent product factor */ 931da177e4SLinus Torvalds xfs_rtblock_t *rtblock); /* out: start block allocated */ 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds /* 961da177e4SLinus Torvalds * Free an extent in the realtime subvolume. Length is expressed in 971da177e4SLinus Torvalds * realtime extents, as is the block number. 981da177e4SLinus Torvalds */ 991da177e4SLinus Torvalds int /* error */ 1001da177e4SLinus Torvalds xfs_rtfree_extent( 1011da177e4SLinus Torvalds struct xfs_trans *tp, /* transaction pointer */ 1021da177e4SLinus Torvalds xfs_rtblock_t bno, /* starting block number to free */ 1031da177e4SLinus Torvalds xfs_extlen_t len); /* length of extent freed */ 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* 1061da177e4SLinus Torvalds * Initialize realtime fields in the mount structure. 1071da177e4SLinus Torvalds */ 1081da177e4SLinus Torvalds int /* error */ 1091da177e4SLinus Torvalds xfs_rtmount_init( 1101da177e4SLinus Torvalds struct xfs_mount *mp); /* file system mount structure */ 111b93b6e43SChristoph Hellwig void 112b93b6e43SChristoph Hellwig xfs_rtunmount_inodes( 113b93b6e43SChristoph Hellwig struct xfs_mount *mp); 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* 1161da177e4SLinus Torvalds * Get the bitmap and summary inodes into the mount structure 1171da177e4SLinus Torvalds * at mount time. 1181da177e4SLinus Torvalds */ 1191da177e4SLinus Torvalds int /* error */ 1201da177e4SLinus Torvalds xfs_rtmount_inodes( 1211da177e4SLinus Torvalds struct xfs_mount *mp); /* file system mount structure */ 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds /* 1241da177e4SLinus Torvalds * Pick an extent for allocation at the start of a new realtime file. 1251da177e4SLinus Torvalds * Use the sequence number stored in the atime field of the bitmap inode. 1261da177e4SLinus Torvalds * Translate this to a fraction of the rtextents, and return the product 1271da177e4SLinus Torvalds * of rtextents and the fraction. 1281da177e4SLinus Torvalds * The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ... 1291da177e4SLinus Torvalds */ 1301da177e4SLinus Torvalds int /* error */ 1311da177e4SLinus Torvalds xfs_rtpick_extent( 1321da177e4SLinus Torvalds struct xfs_mount *mp, /* file system mount point */ 1331da177e4SLinus Torvalds struct xfs_trans *tp, /* transaction pointer */ 1341da177e4SLinus Torvalds xfs_extlen_t len, /* allocation length (rtextents) */ 1351da177e4SLinus Torvalds xfs_rtblock_t *pick); /* result rt extent */ 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds /* 1381da177e4SLinus Torvalds * Grow the realtime area of the filesystem. 1391da177e4SLinus Torvalds */ 1401da177e4SLinus Torvalds int 1411da177e4SLinus Torvalds xfs_growfs_rt( 1421da177e4SLinus Torvalds struct xfs_mount *mp, /* file system mount structure */ 1431da177e4SLinus Torvalds xfs_growfs_rt_t *in); /* user supplied growfs struct */ 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds #else 1461da177e4SLinus Torvalds # define xfs_rtallocate_extent(t,b,min,max,l,a,f,p,rb) (ENOSYS) 1471da177e4SLinus Torvalds # define xfs_rtfree_extent(t,b,l) (ENOSYS) 1481da177e4SLinus Torvalds # define xfs_rtpick_extent(m,t,l,rb) (ENOSYS) 1491da177e4SLinus Torvalds # define xfs_growfs_rt(mp,in) (ENOSYS) 150*32891b29SEric Sandeen static inline int /* error */ 151*32891b29SEric Sandeen xfs_rtmount_init( 152*32891b29SEric Sandeen xfs_mount_t *mp) /* file system mount structure */ 153*32891b29SEric Sandeen { 154*32891b29SEric Sandeen if (mp->m_sb.sb_rblocks == 0) 155*32891b29SEric Sandeen return 0; 156*32891b29SEric Sandeen 157*32891b29SEric Sandeen cmn_err(CE_WARN, "XFS: Not built with CONFIG_XFS_RT"); 158*32891b29SEric Sandeen return ENOSYS; 159*32891b29SEric Sandeen } 1601da177e4SLinus Torvalds # define xfs_rtmount_inodes(m) (((mp)->m_sb.sb_rblocks == 0)? 0 : (ENOSYS)) 161b93b6e43SChristoph Hellwig # define xfs_rtunmount_inodes(m) 1621da177e4SLinus Torvalds #endif /* CONFIG_XFS_RT */ 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds #endif /* __KERNEL__ */ 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds #endif /* __XFS_RTALLOC_H__ */ 167