blob: 09e1f4f35e971c0e1edf326cfeca9d21f67a6953 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_RTALLOC_H__
19#define __XFS_RTALLOC_H__
20
21struct xfs_mount;
22struct xfs_trans;
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/* Min and max rt extent sizes, specified in bytes */
25#define XFS_MAX_RTEXTSIZE (1024 * 1024 * 1024) /* 1GB */
Malcolm Parsons9da096f2009-03-29 09:55:42 +020026#define XFS_DFL_RTEXTSIZE (64 * 1024) /* 64kB */
27#define XFS_MIN_RTEXTSIZE (4 * 1024) /* 4kB */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29/*
30 * Constants for bit manipulations.
31 */
32#define XFS_NBBYLOG 3 /* log2(NBBY) */
33#define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */
34#define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG)
35#define XFS_NBWORD (1 << XFS_NBWORDLOG)
36#define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1)
37
38#define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize)
39#define XFS_BLOCKMASK(mp) ((mp)->m_blockmask)
40#define XFS_BLOCKWSIZE(mp) ((mp)->m_blockwsize)
41#define XFS_BLOCKWMASK(mp) ((mp)->m_blockwmask)
42
43/*
44 * Summary and bit manipulation macros.
45 */
46#define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
47#define XFS_SUMOFFSTOBLOCK(mp,s) \
48 (((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
49#define XFS_SUMPTR(mp,bp,so) \
50 ((xfs_suminfo_t *)((char *)XFS_BUF_PTR(bp) + \
51 (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
52
53#define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log)
54#define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log)
55#define XFS_BITTOWORD(mp,bi) \
56 ((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
57
58#define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
59#define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b))
60
61#define XFS_RTLOBIT(w) xfs_lowbit32(w)
62#define XFS_RTHIBIT(w) xfs_highbit32(w)
63
64#if XFS_BIG_BLKNOS
65#define XFS_RTBLOCKLOG(b) xfs_highbit64(b)
66#else
67#define XFS_RTBLOCKLOG(b) xfs_highbit32(b)
68#endif
69
70
71#ifdef __KERNEL__
72
73#ifdef CONFIG_XFS_RT
74/*
75 * Function prototypes for exported functions.
76 */
77
78/*
79 * Allocate an extent in the realtime subvolume, with the usual allocation
80 * parameters. The length units are all in realtime extents, as is the
81 * result block number.
82 */
83int /* error */
84xfs_rtallocate_extent(
85 struct xfs_trans *tp, /* transaction pointer */
86 xfs_rtblock_t bno, /* starting block number to allocate */
87 xfs_extlen_t minlen, /* minimum length to allocate */
88 xfs_extlen_t maxlen, /* maximum length to allocate */
89 xfs_extlen_t *len, /* out: actual length allocated */
90 xfs_alloctype_t type, /* allocation type XFS_ALLOCTYPE... */
91 int wasdel, /* was a delayed allocation extent */
92 xfs_extlen_t prod, /* extent product factor */
93 xfs_rtblock_t *rtblock); /* out: start block allocated */
94
95/*
96 * Free an extent in the realtime subvolume. Length is expressed in
97 * realtime extents, as is the block number.
98 */
99int /* error */
100xfs_rtfree_extent(
101 struct xfs_trans *tp, /* transaction pointer */
102 xfs_rtblock_t bno, /* starting block number to free */
103 xfs_extlen_t len); /* length of extent freed */
104
105/*
106 * Initialize realtime fields in the mount structure.
107 */
108int /* error */
109xfs_rtmount_init(
110 struct xfs_mount *mp); /* file system mount structure */
Christoph Hellwigb93b6e42009-02-04 09:33:58 +0100111void
112xfs_rtunmount_inodes(
113 struct xfs_mount *mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/*
116 * Get the bitmap and summary inodes into the mount structure
117 * at mount time.
118 */
119int /* error */
120xfs_rtmount_inodes(
121 struct xfs_mount *mp); /* file system mount structure */
122
123/*
124 * Pick an extent for allocation at the start of a new realtime file.
125 * Use the sequence number stored in the atime field of the bitmap inode.
126 * Translate this to a fraction of the rtextents, and return the product
127 * of rtextents and the fraction.
128 * The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ...
129 */
130int /* error */
131xfs_rtpick_extent(
132 struct xfs_mount *mp, /* file system mount point */
133 struct xfs_trans *tp, /* transaction pointer */
134 xfs_extlen_t len, /* allocation length (rtextents) */
135 xfs_rtblock_t *pick); /* result rt extent */
136
137/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 * Grow the realtime area of the filesystem.
139 */
140int
141xfs_growfs_rt(
142 struct xfs_mount *mp, /* file system mount structure */
143 xfs_growfs_rt_t *in); /* user supplied growfs struct */
144
145#else
146# define xfs_rtallocate_extent(t,b,min,max,l,a,f,p,rb) (ENOSYS)
147# define xfs_rtfree_extent(t,b,l) (ENOSYS)
148# define xfs_rtpick_extent(m,t,l,rb) (ENOSYS)
149# define xfs_growfs_rt(mp,in) (ENOSYS)
Eric Sandeen32891b22010-04-30 16:43:48 +0000150static inline int /* error */
151xfs_rtmount_init(
152 xfs_mount_t *mp) /* file system mount structure */
153{
154 if (mp->m_sb.sb_rblocks == 0)
155 return 0;
156
Dave Chinner0b932cc2011-03-07 10:08:35 +1100157 xfs_warn(mp, "Not built with CONFIG_XFS_RT");
Eric Sandeen32891b22010-04-30 16:43:48 +0000158 return ENOSYS;
159}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160# define xfs_rtmount_inodes(m) (((mp)->m_sb.sb_rblocks == 0)? 0 : (ENOSYS))
Christoph Hellwigb93b6e42009-02-04 09:33:58 +0100161# define xfs_rtunmount_inodes(m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#endif /* CONFIG_XFS_RT */
163
164#endif /* __KERNEL__ */
165
166#endif /* __XFS_RTALLOC_H__ */