35 #ifdef XFS_FILESTREAMS_TRACE
37 ktrace_t *xfs_filestreams_trace_buf;
40 xfs_filestreams_trace(
52 ktrace_enter(xfs_filestreams_trace_buf,
53 (
void *)(__psint_t)(type | (line << 16)),
57 (
void *)(__psunsigned_t)arg0,
58 (
void *)(__psunsigned_t)arg1,
59 (
void *)(__psunsigned_t)arg2,
60 (
void *)(__psunsigned_t)arg3,
61 (
void *)(__psunsigned_t)arg4,
62 (
void *)(__psunsigned_t)arg5,
66 #define TRACE0(mp,t) TRACE6(mp,t,0,0,0,0,0,0)
67 #define TRACE1(mp,t,a0) TRACE6(mp,t,a0,0,0,0,0,0)
68 #define TRACE2(mp,t,a0,a1) TRACE6(mp,t,a0,a1,0,0,0,0)
69 #define TRACE3(mp,t,a0,a1,a2) TRACE6(mp,t,a0,a1,a2,0,0,0)
70 #define TRACE4(mp,t,a0,a1,a2,a3) TRACE6(mp,t,a0,a1,a2,a3,0,0)
71 #define TRACE5(mp,t,a0,a1,a2,a3,a4) TRACE6(mp,t,a0,a1,a2,a3,a4,0)
72 #define TRACE6(mp,t,a0,a1,a2,a3,a4,a5) \
73 xfs_filestreams_trace(mp, t, __func__, __LINE__, \
74 (__psunsigned_t)a0, (__psunsigned_t)a1, \
75 (__psunsigned_t)a2, (__psunsigned_t)a3, \
76 (__psunsigned_t)a4, (__psunsigned_t)a5)
78 #define TRACE_AG_SCAN(mp, ag, ag2) \
79 TRACE2(mp, XFS_FSTRM_KTRACE_AGSCAN, ag, ag2);
80 #define TRACE_AG_PICK1(mp, max_ag, maxfree) \
81 TRACE2(mp, XFS_FSTRM_KTRACE_AGPICK1, max_ag, maxfree);
82 #define TRACE_AG_PICK2(mp, ag, ag2, cnt, free, scan, flag) \
83 TRACE6(mp, XFS_FSTRM_KTRACE_AGPICK2, ag, ag2, \
84 cnt, free, scan, flag)
85 #define TRACE_UPDATE(mp, ip, ag, cnt, ag2, cnt2) \
86 TRACE5(mp, XFS_FSTRM_KTRACE_UPDATE, ip, ag, cnt, ag2, cnt2)
87 #define TRACE_FREE(mp, ip, pip, ag, cnt) \
88 TRACE4(mp, XFS_FSTRM_KTRACE_FREE, ip, pip, ag, cnt)
89 #define TRACE_LOOKUP(mp, ip, pip, ag, cnt) \
90 TRACE4(mp, XFS_FSTRM_KTRACE_ITEM_LOOKUP, ip, pip, ag, cnt)
91 #define TRACE_ASSOCIATE(mp, ip, pip, ag, cnt) \
92 TRACE4(mp, XFS_FSTRM_KTRACE_ASSOCIATE, ip, pip, ag, cnt)
93 #define TRACE_MOVEAG(mp, ip, pip, oag, ocnt, nag, ncnt) \
94 TRACE6(mp, XFS_FSTRM_KTRACE_MOVEAG, ip, pip, oag, ocnt, nag, ncnt)
95 #define TRACE_ORPHAN(mp, ip, ag) \
96 TRACE2(mp, XFS_FSTRM_KTRACE_ORPHAN, ip, ag);
100 #define TRACE_AG_SCAN(mp, ag, ag2)
101 #define TRACE_AG_PICK1(mp, max_ag, maxfree)
102 #define TRACE_AG_PICK2(mp, ag, ag2, cnt, free, scan, flag)
103 #define TRACE_UPDATE(mp, ip, ag, cnt, ag2, cnt2)
104 #define TRACE_FREE(mp, ip, pip, ag, cnt)
105 #define TRACE_LOOKUP(mp, ip, pip, ag, cnt)
106 #define TRACE_ASSOCIATE(mp, ip, pip, ag, cnt)
107 #define TRACE_MOVEAG(mp, ip, pip, oag, ocnt, nag, ncnt)
108 #define TRACE_ORPHAN(mp, ip, ag)
164 xfs_filestream_peek_ag(
178 xfs_filestream_get_ag(
192 xfs_filestream_put_ag(
208 _xfs_filestream_pick_ag(
216 int err, trylock, nscan;
222 minfree = mp->m_sb.sb_agblocks / 50;
230 for (nscan = 0; 1; nscan++) {
236 if (err && !trylock) {
259 if (xfs_filestream_get_ag(mp, ag) > 1) {
260 xfs_filestream_put_ag(mp, ag);
265 if (((minlen && longest >= minlen) ||
268 (flags & XFS_PICK_LOWSPACE))) {
279 xfs_filestream_put_ag(mp, ag);
283 if (++ag >= mp->m_sb.sb_agcount)
297 if (!(flags & XFS_PICK_LOWSPACE)) {
298 flags |= XFS_PICK_LOWSPACE;
307 xfs_filestream_get_ag(mp, max_ag);
309 streams = max_streams;
331 _xfs_filestream_update_ag(
341 xfs_inode_t *old_pip;
349 (
S_ISDIR(ip->i_d.di_mode) && !pip)));
352 cache = mp->m_filestream;
368 xfs_filestream_put_ag(mp, old_ag);
369 xfs_filestream_get_ag(mp, ag);
376 if (pip && pip != old_pip) {
381 TRACE_UPDATE(mp, ip, old_ag, xfs_filestream_peek_ag(mp, old_ag),
382 ag, xfs_filestream_peek_ag(mp, ag));
396 kmem_zone_free(item_zone, item);
401 xfs_filestream_get_ag(mp, ag);
416 TRACE_UPDATE(mp, ip, ag, xfs_filestream_peek_ag(mp, ag),
417 ag, xfs_filestream_peek_ag(mp, ag));
429 xfs_inode_t *ip = item->
ip;
433 xfs_iflags_clear(ip, XFS_IFILESTREAM);
436 xfs_filestream_put_ag(ip->i_mount, item->
ag);
439 xfs_filestream_peek_ag(ip->i_mount, item->
ag));
459 kmem_zone_free(item_zone, item);
469 item_zone = kmem_zone_init(
sizeof(
fstrm_item_t),
"fstrm_item");
483 kmem_zone_destroy(item_zone);
496 unsigned int lifetime, grp_count;
545 cache = ip->i_mount->m_filestream;
554 ref = xfs_filestream_peek_ag(ip->i_mount, ag);
588 cache = mp->m_filestream;
615 TRACE_LOOKUP(mp, pip, pip, ag, xfs_filestream_peek_ag(mp, ag));
616 err = _xfs_filestream_update_ag(ip, pip, ag);
625 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
627 startag = (mp->m_agfrotor / rotorstep) % mp->m_sb.sb_agcount;
628 mp->m_agfrotor = (mp->m_agfrotor + 1) %
629 (mp->m_sb.sb_agcount * rotorstep);
634 err = _xfs_filestream_pick_ag(mp, startag, &ag, 0, 0);
639 err = _xfs_filestream_update_ag(pip,
NULL, ag);
644 err = _xfs_filestream_update_ag(ip, pip, ag);
657 xfs_filestream_put_ag(mp, ag);
675 xfs_inode_t *
ip, *pip =
NULL;
684 cache = mp->m_filestream;
711 if (dir->
ag != file->
ag) {
712 xfs_filestream_put_ag(mp, file->
ag);
713 xfs_filestream_get_ag(mp, dir->
ag);
714 *agp = file->
ag = dir->
ag;
737 ag, xfs_filestream_peek_ag(mp, ag),
738 *agp, xfs_filestream_peek_ag(mp, *agp));
755 xfs_ilock(pip, XFS_IOLOCK_EXCL | XFS_IOLOCK_PARENT);
762 ag = (ag ==
NULLAGNUMBER) ? 0 : (ag + 1) % mp->m_sb.sb_agcount;
763 flags = (ap->
userdata ? XFS_PICK_USERDATA : 0) |
764 (ap->
flist->xbf_low ? XFS_PICK_LOWSPACE : 0);
766 err = _xfs_filestream_pick_ag(mp, ag, agp, flags, minlen);
784 err = _xfs_filestream_update_ag(pip,
NULL, *agp);
789 err = _xfs_filestream_update_ag(ip, pip, *agp);
794 *agp, xfs_filestream_peek_ag(mp, *agp));
803 xfs_filestream_put_ag(mp, *agp);