Skip to content

Commit 152e212

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: move xfs_bmap_rtalloc to xfs_rtalloc.c
xfs_bmap_rtalloc is currently in xfs_bmap_util.c, which is a somewhat odd spot for it, given that is only called from xfs_bmap.c and calls into xfs_rtalloc.c to do the actual work. Move xfs_bmap_rtalloc to xfs_rtalloc.c and mark xfs_rtpick_extent xfs_rtallocate_extent and xfs_rtallocate_extent static now that they aren't called from outside of xfs_rtalloc.c. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: "Darrick J. Wong" <[email protected]> Signed-off-by: Chandan Babu R <[email protected]>
1 parent 5864346 commit 152e212

File tree

3 files changed

+133
-170
lines changed

3 files changed

+133
-170
lines changed

fs/xfs/xfs_bmap_util.c

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -69,137 +69,6 @@ xfs_zero_extent(
6969
GFP_NOFS, 0);
7070
}
7171

72-
#ifdef CONFIG_XFS_RT
73-
int
74-
xfs_bmap_rtalloc(
75-
struct xfs_bmalloca *ap)
76-
{
77-
struct xfs_mount *mp = ap->ip->i_mount;
78-
xfs_fileoff_t orig_offset = ap->offset;
79-
xfs_rtxnum_t rtx;
80-
xfs_rtxlen_t prod = 0; /* product factor for allocators */
81-
xfs_extlen_t mod = 0; /* product factor for allocators */
82-
xfs_rtxlen_t ralen = 0; /* realtime allocation length */
83-
xfs_extlen_t align; /* minimum allocation alignment */
84-
xfs_extlen_t orig_length = ap->length;
85-
xfs_extlen_t minlen = mp->m_sb.sb_rextsize;
86-
xfs_rtxlen_t raminlen;
87-
bool rtlocked = false;
88-
bool ignore_locality = false;
89-
int error;
90-
91-
align = xfs_get_extsz_hint(ap->ip);
92-
retry:
93-
prod = xfs_extlen_to_rtxlen(mp, align);
94-
error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev,
95-
align, 1, ap->eof, 0,
96-
ap->conv, &ap->offset, &ap->length);
97-
if (error)
98-
return error;
99-
ASSERT(ap->length);
100-
ASSERT(xfs_extlen_to_rtxmod(mp, ap->length) == 0);
101-
102-
/*
103-
* If we shifted the file offset downward to satisfy an extent size
104-
* hint, increase minlen by that amount so that the allocator won't
105-
* give us an allocation that's too short to cover at least one of the
106-
* blocks that the caller asked for.
107-
*/
108-
if (ap->offset != orig_offset)
109-
minlen += orig_offset - ap->offset;
110-
111-
/*
112-
* If the offset & length are not perfectly aligned
113-
* then kill prod, it will just get us in trouble.
114-
*/
115-
div_u64_rem(ap->offset, align, &mod);
116-
if (mod || ap->length % align)
117-
prod = 1;
118-
/*
119-
* Set ralen to be the actual requested length in rtextents.
120-
*
121-
* If the old value was close enough to XFS_BMBT_MAX_EXTLEN that
122-
* we rounded up to it, cut it back so it's valid again.
123-
* Note that if it's a really large request (bigger than
124-
* XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't
125-
* adjust the starting point to match it.
126-
*/
127-
ralen = xfs_extlen_to_rtxlen(mp, min(ap->length, XFS_MAX_BMBT_EXTLEN));
128-
129-
/*
130-
* Lock out modifications to both the RT bitmap and summary inodes
131-
*/
132-
if (!rtlocked) {
133-
xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP);
134-
xfs_trans_ijoin(ap->tp, mp->m_rbmip, XFS_ILOCK_EXCL);
135-
xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM);
136-
xfs_trans_ijoin(ap->tp, mp->m_rsumip, XFS_ILOCK_EXCL);
137-
rtlocked = true;
138-
}
139-
140-
/*
141-
* If it's an allocation to an empty file at offset 0,
142-
* pick an extent that will space things out in the rt area.
143-
*/
144-
if (ap->eof && ap->offset == 0) {
145-
error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx);
146-
if (error)
147-
return error;
148-
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
149-
} else {
150-
ap->blkno = 0;
151-
}
152-
153-
xfs_bmap_adjacent(ap);
154-
155-
/*
156-
* Realtime allocation, done through xfs_rtallocate_extent.
157-
*/
158-
if (ignore_locality)
159-
rtx = 0;
160-
else
161-
rtx = xfs_rtb_to_rtx(mp, ap->blkno);
162-
raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
163-
error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
164-
ap->wasdel, prod, &rtx);
165-
if (error)
166-
return error;
167-
168-
if (rtx != NULLRTEXTNO) {
169-
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
170-
ap->length = xfs_rtxlen_to_extlen(mp, ralen);
171-
xfs_bmap_alloc_account(ap);
172-
return 0;
173-
}
174-
175-
if (align > mp->m_sb.sb_rextsize) {
176-
/*
177-
* We previously enlarged the request length to try to satisfy
178-
* an extent size hint. The allocator didn't return anything,
179-
* so reset the parameters to the original values and try again
180-
* without alignment criteria.
181-
*/
182-
ap->offset = orig_offset;
183-
ap->length = orig_length;
184-
minlen = align = mp->m_sb.sb_rextsize;
185-
goto retry;
186-
}
187-
188-
if (!ignore_locality && ap->blkno != 0) {
189-
/*
190-
* If we can't allocate near a specific rt extent, try again
191-
* without locality criteria.
192-
*/
193-
ignore_locality = true;
194-
goto retry;
195-
}
196-
197-
ap->blkno = NULLFSBLOCK;
198-
ap->length = 0;
199-
return 0;
200-
}
201-
#endif /* CONFIG_XFS_RT */
202-
20372
/*
20473
* Extent tree block counting routines.
20574
*/

fs/xfs/xfs_rtalloc.c

Lines changed: 133 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
#include "xfs_inode.h"
1515
#include "xfs_bmap.h"
1616
#include "xfs_bmap_btree.h"
17+
#include "xfs_bmap_util.h"
1718
#include "xfs_trans.h"
1819
#include "xfs_trans_space.h"
1920
#include "xfs_icache.h"
2021
#include "xfs_rtalloc.h"
2122
#include "xfs_sb.h"
2223
#include "xfs_rtbitmap.h"
24+
#include "xfs_quota.h"
2325

2426
/*
2527
* Read and return the summary information for a given extent size,
@@ -1171,7 +1173,7 @@ xfs_growfs_rt(
11711173
* parameters. The length units are all in realtime extents, as is the
11721174
* result block number.
11731175
*/
1174-
int
1176+
static int
11751177
xfs_rtallocate_extent(
11761178
struct xfs_trans *tp,
11771179
xfs_rtxnum_t start, /* starting rtext number to allocate */
@@ -1419,7 +1421,7 @@ xfs_rtunmount_inodes(
14191421
* of rtextents and the fraction.
14201422
* The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ...
14211423
*/
1422-
int /* error */
1424+
static int
14231425
xfs_rtpick_extent(
14241426
xfs_mount_t *mp, /* file system mount point */
14251427
xfs_trans_t *tp, /* transaction pointer */
@@ -1458,3 +1460,132 @@ xfs_rtpick_extent(
14581460
*pick = b;
14591461
return 0;
14601462
}
1463+
1464+
int
1465+
xfs_bmap_rtalloc(
1466+
struct xfs_bmalloca *ap)
1467+
{
1468+
struct xfs_mount *mp = ap->ip->i_mount;
1469+
xfs_fileoff_t orig_offset = ap->offset;
1470+
xfs_rtxnum_t rtx;
1471+
xfs_rtxlen_t prod = 0; /* product factor for allocators */
1472+
xfs_extlen_t mod = 0; /* product factor for allocators */
1473+
xfs_rtxlen_t ralen = 0; /* realtime allocation length */
1474+
xfs_extlen_t align; /* minimum allocation alignment */
1475+
xfs_extlen_t orig_length = ap->length;
1476+
xfs_extlen_t minlen = mp->m_sb.sb_rextsize;
1477+
xfs_rtxlen_t raminlen;
1478+
bool rtlocked = false;
1479+
bool ignore_locality = false;
1480+
int error;
1481+
1482+
align = xfs_get_extsz_hint(ap->ip);
1483+
retry:
1484+
prod = xfs_extlen_to_rtxlen(mp, align);
1485+
error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev,
1486+
align, 1, ap->eof, 0,
1487+
ap->conv, &ap->offset, &ap->length);
1488+
if (error)
1489+
return error;
1490+
ASSERT(ap->length);
1491+
ASSERT(xfs_extlen_to_rtxmod(mp, ap->length) == 0);
1492+
1493+
/*
1494+
* If we shifted the file offset downward to satisfy an extent size
1495+
* hint, increase minlen by that amount so that the allocator won't
1496+
* give us an allocation that's too short to cover at least one of the
1497+
* blocks that the caller asked for.
1498+
*/
1499+
if (ap->offset != orig_offset)
1500+
minlen += orig_offset - ap->offset;
1501+
1502+
/*
1503+
* If the offset & length are not perfectly aligned
1504+
* then kill prod, it will just get us in trouble.
1505+
*/
1506+
div_u64_rem(ap->offset, align, &mod);
1507+
if (mod || ap->length % align)
1508+
prod = 1;
1509+
/*
1510+
* Set ralen to be the actual requested length in rtextents.
1511+
*
1512+
* If the old value was close enough to XFS_BMBT_MAX_EXTLEN that
1513+
* we rounded up to it, cut it back so it's valid again.
1514+
* Note that if it's a really large request (bigger than
1515+
* XFS_BMBT_MAX_EXTLEN), we don't hear about that number, and can't
1516+
* adjust the starting point to match it.
1517+
*/
1518+
ralen = xfs_extlen_to_rtxlen(mp, min(ap->length, XFS_MAX_BMBT_EXTLEN));
1519+
1520+
/*
1521+
* Lock out modifications to both the RT bitmap and summary inodes
1522+
*/
1523+
if (!rtlocked) {
1524+
xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP);
1525+
xfs_trans_ijoin(ap->tp, mp->m_rbmip, XFS_ILOCK_EXCL);
1526+
xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM);
1527+
xfs_trans_ijoin(ap->tp, mp->m_rsumip, XFS_ILOCK_EXCL);
1528+
rtlocked = true;
1529+
}
1530+
1531+
/*
1532+
* If it's an allocation to an empty file at offset 0,
1533+
* pick an extent that will space things out in the rt area.
1534+
*/
1535+
if (ap->eof && ap->offset == 0) {
1536+
error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx);
1537+
if (error)
1538+
return error;
1539+
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
1540+
} else {
1541+
ap->blkno = 0;
1542+
}
1543+
1544+
xfs_bmap_adjacent(ap);
1545+
1546+
/*
1547+
* Realtime allocation, done through xfs_rtallocate_extent.
1548+
*/
1549+
if (ignore_locality)
1550+
rtx = 0;
1551+
else
1552+
rtx = xfs_rtb_to_rtx(mp, ap->blkno);
1553+
raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
1554+
error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
1555+
ap->wasdel, prod, &rtx);
1556+
if (error)
1557+
return error;
1558+
1559+
if (rtx != NULLRTEXTNO) {
1560+
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
1561+
ap->length = xfs_rtxlen_to_extlen(mp, ralen);
1562+
xfs_bmap_alloc_account(ap);
1563+
return 0;
1564+
}
1565+
1566+
if (align > mp->m_sb.sb_rextsize) {
1567+
/*
1568+
* We previously enlarged the request length to try to satisfy
1569+
* an extent size hint. The allocator didn't return anything,
1570+
* so reset the parameters to the original values and try again
1571+
* without alignment criteria.
1572+
*/
1573+
ap->offset = orig_offset;
1574+
ap->length = orig_length;
1575+
minlen = align = mp->m_sb.sb_rextsize;
1576+
goto retry;
1577+
}
1578+
1579+
if (!ignore_locality && ap->blkno != 0) {
1580+
/*
1581+
* If we can't allocate near a specific rt extent, try again
1582+
* without locality criteria.
1583+
*/
1584+
ignore_locality = true;
1585+
goto retry;
1586+
}
1587+
1588+
ap->blkno = NULLFSBLOCK;
1589+
ap->length = 0;
1590+
return 0;
1591+
}

fs/xfs/xfs_rtalloc.h

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,6 @@ struct xfs_mount;
1212
struct xfs_trans;
1313

1414
#ifdef CONFIG_XFS_RT
15-
/*
16-
* Function prototypes for exported functions.
17-
*/
18-
19-
/*
20-
* Allocate an extent in the realtime subvolume, with the usual allocation
21-
* parameters. The length units are all in realtime extents, as is the
22-
* result block number.
23-
*/
24-
int /* error */
25-
xfs_rtallocate_extent(
26-
struct xfs_trans *tp, /* transaction pointer */
27-
xfs_rtxnum_t start, /* starting rtext number to allocate */
28-
xfs_rtxlen_t minlen, /* minimum length to allocate */
29-
xfs_rtxlen_t maxlen, /* maximum length to allocate */
30-
xfs_rtxlen_t *len, /* out: actual length allocated */
31-
int wasdel, /* was a delayed allocation extent */
32-
xfs_rtxlen_t prod, /* extent product factor */
33-
xfs_rtxnum_t *rtblock); /* out: start rtext allocated */
34-
35-
3615
/*
3716
* Initialize realtime fields in the mount structure.
3817
*/
@@ -51,20 +30,6 @@ int /* error */
5130
xfs_rtmount_inodes(
5231
struct xfs_mount *mp); /* file system mount structure */
5332

54-
/*
55-
* Pick an extent for allocation at the start of a new realtime file.
56-
* Use the sequence number stored in the atime field of the bitmap inode.
57-
* Translate this to a fraction of the rtextents, and return the product
58-
* of rtextents and the fraction.
59-
* The fraction sequence is 0, 1/2, 1/4, 3/4, 1/8, ..., 7/8, 1/16, ...
60-
*/
61-
int /* error */
62-
xfs_rtpick_extent(
63-
struct xfs_mount *mp, /* file system mount point */
64-
struct xfs_trans *tp, /* transaction pointer */
65-
xfs_rtxlen_t len, /* allocation length (rtextents) */
66-
xfs_rtxnum_t *pick); /* result rt extent */
67-
6833
/*
6934
* Grow the realtime area of the filesystem.
7035
*/
@@ -75,8 +40,6 @@ xfs_growfs_rt(
7540

7641
int xfs_rtalloc_reinit_frextents(struct xfs_mount *mp);
7742
#else
78-
# define xfs_rtallocate_extent(t,b,min,max,l,f,p,rb) (-ENOSYS)
79-
# define xfs_rtpick_extent(m,t,l,rb) (-ENOSYS)
8043
# define xfs_growfs_rt(mp,in) (-ENOSYS)
8144
# define xfs_rtalloc_reinit_frextents(m) (0)
8245
static inline int /* error */

0 commit comments

Comments
 (0)