blob: ff6f90215c8aa37eff45d2a26faa8b5738869d75 [file] [log] [blame]
David Chinner2a82b8b2007-07-11 11:09:12 +10001/*
2 * Copyright (c) 2006-2007 Silicon Graphics, Inc.
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +10003 * Copyright (c) 2014 Christoph Hellwig.
David Chinner2a82b8b2007-07-11 11:09:12 +10004 * All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19#include "xfs.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110020#include "xfs_format.h"
Dave Chinner239880e2013-10-23 10:50:10 +110021#include "xfs_log_format.h"
22#include "xfs_trans_resv.h"
23#include "xfs_ag.h"
24#include "xfs_sb.h"
25#include "xfs_mount.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100026#include "xfs_inum.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100027#include "xfs_inode.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100028#include "xfs_bmap.h"
Dave Chinner68988112013-08-12 20:49:42 +100029#include "xfs_bmap_util.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100030#include "xfs_alloc.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100031#include "xfs_mru_cache.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +110032#include "xfs_dinode.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100033#include "xfs_filestream.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000034#include "xfs_trace.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100035
David Chinner2a82b8b2007-07-11 11:09:12 +100036#define TRACE_AG_SCAN(mp, ag, ag2)
37#define TRACE_AG_PICK1(mp, max_ag, maxfree)
38#define TRACE_AG_PICK2(mp, ag, ag2, cnt, free, scan, flag)
David Chinner2a82b8b2007-07-11 11:09:12 +100039#define TRACE_FREE(mp, ip, pip, ag, cnt)
40#define TRACE_LOOKUP(mp, ip, pip, ag, cnt)
David Chinner2a82b8b2007-07-11 11:09:12 +100041
42static kmem_zone_t *item_zone;
43
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +100044struct xfs_fstrm_item {
45 struct xfs_mru_cache_elem mru;
46 struct xfs_inode *ip;
47 xfs_agnumber_t ag; /* AG in use for this directory */
48};
49
50enum xfs_fstrm_alloc {
51 XFS_PICK_USERDATA = 1,
52 XFS_PICK_LOWSPACE = 2,
53};
David Chinner2a82b8b2007-07-11 11:09:12 +100054
Christoph Hellwig0664ce82010-07-20 17:31:01 +100055/*
56 * Allocation group filestream associations are tracked with per-ag atomic
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +100057 * counters. These counters allow xfs_filestream_pick_ag() to tell whether a
Christoph Hellwig0664ce82010-07-20 17:31:01 +100058 * particular AG already has active filestreams associated with it. The mount
59 * point's m_peraglock is used to protect these counters from per-ag array
60 * re-allocation during a growfs operation. When xfs_growfs_data_private() is
61 * about to reallocate the array, it calls xfs_filestream_flush() with the
62 * m_peraglock held in write mode.
63 *
64 * Since xfs_mru_cache_flush() guarantees that all the free functions for all
65 * the cache elements have finished executing before it returns, it's safe for
66 * the free functions to use the atomic counters without m_peraglock protection.
67 * This allows the implementation of xfs_fstrm_free_func() to be agnostic about
68 * whether it was called with the m_peraglock held in read mode, write mode or
69 * not held at all. The race condition this addresses is the following:
70 *
71 * - The work queue scheduler fires and pulls a filestream directory cache
72 * element off the LRU end of the cache for deletion, then gets pre-empted.
73 * - A growfs operation grabs the m_peraglock in write mode, flushes all the
74 * remaining items from the cache and reallocates the mount point's per-ag
75 * array, resetting all the counters to zero.
76 * - The work queue thread resumes and calls the free function for the element
77 * it started cleaning up earlier. In the process it decrements the
78 * filestreams counter for an AG that now has no references.
79 *
80 * With a shrinkfs feature, the above scenario could panic the system.
81 *
82 * All other uses of the following macros should be protected by either the
83 * m_peraglock held in read mode, or the cache's internal locking exposed by the
84 * interval between a call to xfs_mru_cache_lookup() and a call to
85 * xfs_mru_cache_done(). In addition, the m_peraglock must be held in read mode
86 * when new elements are added to the cache.
87 *
88 * Combined, these locking rules ensure that no associations will ever exist in
89 * the cache that reference per-ag array elements that have since been
90 * reallocated.
91 */
92static int
93xfs_filestream_peek_ag(
94 xfs_mount_t *mp,
95 xfs_agnumber_t agno)
96{
97 struct xfs_perag *pag;
98 int ret;
99
100 pag = xfs_perag_get(mp, agno);
101 ret = atomic_read(&pag->pagf_fstrms);
102 xfs_perag_put(pag);
103 return ret;
104}
105
106static int
107xfs_filestream_get_ag(
108 xfs_mount_t *mp,
109 xfs_agnumber_t agno)
110{
111 struct xfs_perag *pag;
112 int ret;
113
114 pag = xfs_perag_get(mp, agno);
115 ret = atomic_inc_return(&pag->pagf_fstrms);
116 xfs_perag_put(pag);
117 return ret;
118}
119
120static void
121xfs_filestream_put_ag(
122 xfs_mount_t *mp,
123 xfs_agnumber_t agno)
124{
125 struct xfs_perag *pag;
126
127 pag = xfs_perag_get(mp, agno);
128 atomic_dec(&pag->pagf_fstrms);
129 xfs_perag_put(pag);
130}
David Chinner2a82b8b2007-07-11 11:09:12 +1000131
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000132static void
133xfs_fstrm_free_func(
134 struct xfs_mru_cache_elem *mru)
135{
136 struct xfs_fstrm_item *item =
137 container_of(mru, struct xfs_fstrm_item, mru);
138
139 xfs_filestream_put_ag(item->ip->i_mount, item->ag);
140
141 TRACE_FREE(mp, ip, NULL, item->ag,
142 xfs_filestream_peek_ag(mp, item->ag));
143
144 kmem_zone_free(item_zone, item);
145}
146
David Chinner2a82b8b2007-07-11 11:09:12 +1000147/*
148 * Scan the AGs starting at startag looking for an AG that isn't in use and has
149 * at least minlen blocks free.
150 */
151static int
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000152xfs_filestream_pick_ag(
153 struct xfs_inode *ip,
154 xfs_agnumber_t startag,
155 xfs_agnumber_t *agp,
156 int flags,
157 xfs_extlen_t minlen)
David Chinner2a82b8b2007-07-11 11:09:12 +1000158{
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000159 struct xfs_mount *mp = ip->i_mount;
160 struct xfs_fstrm_item *item;
161 struct xfs_perag *pag;
162 xfs_extlen_t longest, free, minfree, maxfree = 0;
163 xfs_agnumber_t ag, max_ag = NULLAGNUMBER;
164 int streams, max_streams;
165 int err, trylock, nscan;
166
167 ASSERT(S_ISDIR(ip->i_d.di_mode));
David Chinner2a82b8b2007-07-11 11:09:12 +1000168
169 /* 2% of an AG's blocks must be free for it to be chosen. */
170 minfree = mp->m_sb.sb_agblocks / 50;
171
172 ag = startag;
173 *agp = NULLAGNUMBER;
174
175 /* For the first pass, don't sleep trying to init the per-AG. */
176 trylock = XFS_ALLOC_FLAG_TRYLOCK;
177
178 for (nscan = 0; 1; nscan++) {
Dave Chinner4196ac02010-01-11 11:47:42 +0000179 pag = xfs_perag_get(mp, ag);
180 TRACE_AG_SCAN(mp, ag, atomic_read(&pag->pagf_fstrms));
David Chinner2a82b8b2007-07-11 11:09:12 +1000181
182 if (!pag->pagf_init) {
183 err = xfs_alloc_pagf_init(mp, NULL, ag, trylock);
Dave Chinner4196ac02010-01-11 11:47:42 +0000184 if (err && !trylock) {
185 xfs_perag_put(pag);
David Chinner2a82b8b2007-07-11 11:09:12 +1000186 return err;
Dave Chinner4196ac02010-01-11 11:47:42 +0000187 }
David Chinner2a82b8b2007-07-11 11:09:12 +1000188 }
189
190 /* Might fail sometimes during the 1st pass with trylock set. */
191 if (!pag->pagf_init)
192 goto next_ag;
193
194 /* Keep track of the AG with the most free blocks. */
195 if (pag->pagf_freeblks > maxfree) {
196 maxfree = pag->pagf_freeblks;
Dave Chinner4196ac02010-01-11 11:47:42 +0000197 max_streams = atomic_read(&pag->pagf_fstrms);
David Chinner2a82b8b2007-07-11 11:09:12 +1000198 max_ag = ag;
199 }
200
201 /*
202 * The AG reference count does two things: it enforces mutual
203 * exclusion when examining the suitability of an AG in this
204 * loop, and it guards against two filestreams being established
205 * in the same AG as each other.
206 */
207 if (xfs_filestream_get_ag(mp, ag) > 1) {
208 xfs_filestream_put_ag(mp, ag);
209 goto next_ag;
210 }
211
Dave Chinner6cc87642009-03-16 08:29:46 +0100212 longest = xfs_alloc_longest_free_extent(mp, pag);
David Chinner2a82b8b2007-07-11 11:09:12 +1000213 if (((minlen && longest >= minlen) ||
214 (!minlen && pag->pagf_freeblks >= minfree)) &&
215 (!pag->pagf_metadata || !(flags & XFS_PICK_USERDATA) ||
216 (flags & XFS_PICK_LOWSPACE))) {
217
218 /* Break out, retaining the reference on the AG. */
219 free = pag->pagf_freeblks;
Dave Chinner4196ac02010-01-11 11:47:42 +0000220 streams = atomic_read(&pag->pagf_fstrms);
221 xfs_perag_put(pag);
David Chinner2a82b8b2007-07-11 11:09:12 +1000222 *agp = ag;
223 break;
224 }
225
226 /* Drop the reference on this AG, it's not usable. */
227 xfs_filestream_put_ag(mp, ag);
228next_ag:
Dave Chinner4196ac02010-01-11 11:47:42 +0000229 xfs_perag_put(pag);
David Chinner2a82b8b2007-07-11 11:09:12 +1000230 /* Move to the next AG, wrapping to AG 0 if necessary. */
231 if (++ag >= mp->m_sb.sb_agcount)
232 ag = 0;
233
234 /* If a full pass of the AGs hasn't been done yet, continue. */
235 if (ag != startag)
236 continue;
237
238 /* Allow sleeping in xfs_alloc_pagf_init() on the 2nd pass. */
239 if (trylock != 0) {
240 trylock = 0;
241 continue;
242 }
243
244 /* Finally, if lowspace wasn't set, set it for the 3rd pass. */
245 if (!(flags & XFS_PICK_LOWSPACE)) {
246 flags |= XFS_PICK_LOWSPACE;
247 continue;
248 }
249
250 /*
251 * Take the AG with the most free space, regardless of whether
252 * it's already in use by another filestream.
253 */
254 if (max_ag != NULLAGNUMBER) {
255 xfs_filestream_get_ag(mp, max_ag);
256 TRACE_AG_PICK1(mp, max_ag, maxfree);
Dave Chinner4196ac02010-01-11 11:47:42 +0000257 streams = max_streams;
David Chinner2a82b8b2007-07-11 11:09:12 +1000258 free = maxfree;
259 *agp = max_ag;
260 break;
261 }
262
263 /* take AG 0 if none matched */
264 TRACE_AG_PICK1(mp, max_ag, maxfree);
265 *agp = 0;
266 return 0;
267 }
268
Dave Chinner4196ac02010-01-11 11:47:42 +0000269 TRACE_AG_PICK2(mp, startag, *agp, streams, free, nscan, flags);
David Chinner2a82b8b2007-07-11 11:09:12 +1000270
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000271 if (*agp == NULLAGNUMBER)
David Chinner2a82b8b2007-07-11 11:09:12 +1000272 return 0;
David Chinner2a82b8b2007-07-11 11:09:12 +1000273
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000274 err = ENOMEM;
David Chinner2a82b8b2007-07-11 11:09:12 +1000275 item = kmem_zone_zalloc(item_zone, KM_MAYFAIL);
276 if (!item)
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000277 goto out_put_ag;
David Chinner2a82b8b2007-07-11 11:09:12 +1000278
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000279 item->ag = *agp;
David Chinner2a82b8b2007-07-11 11:09:12 +1000280 item->ip = ip;
David Chinner2a82b8b2007-07-11 11:09:12 +1000281
Christoph Hellwig22328d72014-04-23 07:11:51 +1000282 err = xfs_mru_cache_insert(mp->m_filestream, ip->i_ino, &item->mru);
David Chinner2a82b8b2007-07-11 11:09:12 +1000283 if (err) {
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000284 if (err == EEXIST)
285 err = 0;
286 goto out_free_item;
David Chinner2a82b8b2007-07-11 11:09:12 +1000287 }
288
David Chinner2a82b8b2007-07-11 11:09:12 +1000289 return 0;
David Chinner2a82b8b2007-07-11 11:09:12 +1000290
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000291out_free_item:
David Chinner2a82b8b2007-07-11 11:09:12 +1000292 kmem_zone_free(item_zone, item);
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000293out_put_ag:
294 xfs_filestream_put_ag(mp, *agp);
David Chinner2a82b8b2007-07-11 11:09:12 +1000295 return err;
296}
297
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000298static struct xfs_inode *
299xfs_filestream_get_parent(
300 struct xfs_inode *ip)
David Chinner2a82b8b2007-07-11 11:09:12 +1000301{
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000302 struct inode *inode = VFS_I(ip), *dir = NULL;
303 struct dentry *dentry, *parent;
304
305 dentry = d_find_alias(inode);
306 if (!dentry)
307 goto out;
308
309 parent = dget_parent(dentry);
310 if (!parent)
311 goto out_dput;
312
313 dir = igrab(parent->d_inode);
314 dput(parent);
315
316out_dput:
317 dput(dentry);
318out:
319 return dir ? XFS_I(dir) : NULL;
David Chinner2a82b8b2007-07-11 11:09:12 +1000320}
321
322/*
David Chinner2a82b8b2007-07-11 11:09:12 +1000323 * Return the AG of the filestream the file or directory belongs to, or
324 * NULLAGNUMBER otherwise.
325 */
326xfs_agnumber_t
327xfs_filestream_lookup_ag(
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000328 struct xfs_inode *ip)
David Chinner2a82b8b2007-07-11 11:09:12 +1000329{
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000330 struct xfs_mount *mp = ip->i_mount;
331 struct xfs_fstrm_item *item;
332 struct xfs_inode *pip = NULL;
333 xfs_agnumber_t ag = NULLAGNUMBER;
334 int ref = 0;
Christoph Hellwig22328d72014-04-23 07:11:51 +1000335 struct xfs_mru_cache_elem *mru;
David Chinner2a82b8b2007-07-11 11:09:12 +1000336
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000337 ASSERT(S_ISREG(ip->i_d.di_mode));
David Chinner2a82b8b2007-07-11 11:09:12 +1000338
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000339 pip = xfs_filestream_get_parent(ip);
340 if (!pip)
341 goto out;
David Chinner2a82b8b2007-07-11 11:09:12 +1000342
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000343 mru = xfs_mru_cache_lookup(mp->m_filestream, pip->i_ino);
344 if (!mru)
345 goto out;
346
347 item = container_of(mru, struct xfs_fstrm_item, mru);
348
David Chinner2a82b8b2007-07-11 11:09:12 +1000349 ag = item->ag;
Christoph Hellwig22328d72014-04-23 07:11:51 +1000350 xfs_mru_cache_done(mp->m_filestream);
David Chinner2a82b8b2007-07-11 11:09:12 +1000351
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000352 ref = xfs_filestream_peek_ag(ip->i_mount, ag);
353out:
354 TRACE_LOOKUP(mp, ip, pip, ag, ref);
355 IRELE(pip);
David Chinner2a82b8b2007-07-11 11:09:12 +1000356 return ag;
357}
358
359/*
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000360 * Make sure a directory has a filestream associated with it.
David Chinner2a82b8b2007-07-11 11:09:12 +1000361 *
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000362 * This is called when creating regular files in an directory that has
363 * filestreams enabled, so that a stream is ready by the time we need it
364 * in the allocator for the files inside the directory.
David Chinner2a82b8b2007-07-11 11:09:12 +1000365 */
366int
367xfs_filestream_associate(
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000368 struct xfs_inode *pip)
David Chinner2a82b8b2007-07-11 11:09:12 +1000369{
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000370 struct xfs_mount *mp = pip->i_mount;
Christoph Hellwig22328d72014-04-23 07:11:51 +1000371 struct xfs_mru_cache_elem *mru;
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000372 xfs_agnumber_t startag, ag;
David Chinner2a82b8b2007-07-11 11:09:12 +1000373
Al Viro03209372011-07-25 20:54:24 -0400374 ASSERT(S_ISDIR(pip->i_d.di_mode));
David Chinner2a82b8b2007-07-11 11:09:12 +1000375
376 /*
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000377 * If the directory already has a file stream associated we're done.
David Chinner2a82b8b2007-07-11 11:09:12 +1000378 */
Christoph Hellwig22328d72014-04-23 07:11:51 +1000379 mru = xfs_mru_cache_lookup(mp->m_filestream, pip->i_ino);
380 if (mru) {
Christoph Hellwig22328d72014-04-23 07:11:51 +1000381 xfs_mru_cache_done(mp->m_filestream);
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000382 return 0;
David Chinner2a82b8b2007-07-11 11:09:12 +1000383 }
384
385 /*
386 * Set the starting AG using the rotor for inode32, otherwise
387 * use the directory inode's AG.
388 */
389 if (mp->m_flags & XFS_MOUNT_32BITINODES) {
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000390 xfs_agnumber_t rotorstep = xfs_rotorstep;
David Chinner2a82b8b2007-07-11 11:09:12 +1000391 startag = (mp->m_agfrotor / rotorstep) % mp->m_sb.sb_agcount;
392 mp->m_agfrotor = (mp->m_agfrotor + 1) %
393 (mp->m_sb.sb_agcount * rotorstep);
394 } else
395 startag = XFS_INO_TO_AGNO(mp, pip->i_ino);
396
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000397 return xfs_filestream_pick_ag(pip, startag, &ag, 0, 0);
David Chinner2a82b8b2007-07-11 11:09:12 +1000398}
399
400/*
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000401 * Pick a new allocation group for the current file and its file stream.
402 *
403 * This is called when the allocator can't find a suitable extent in the
404 * current AG, and we have to move the stream into a new AG with more space.
David Chinner2a82b8b2007-07-11 11:09:12 +1000405 */
406int
407xfs_filestream_new_ag(
Dave Chinner68988112013-08-12 20:49:42 +1000408 struct xfs_bmalloca *ap,
409 xfs_agnumber_t *agp)
David Chinner2a82b8b2007-07-11 11:09:12 +1000410{
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000411 struct xfs_inode *ip = ap->ip, *pip;
412 struct xfs_mount *mp = ip->i_mount;
413 xfs_extlen_t minlen = ap->length;
414 xfs_agnumber_t startag = 0;
415 int flags, err = 0;
416 struct xfs_mru_cache_elem *mru;
David Chinner2a82b8b2007-07-11 11:09:12 +1000417
David Chinner2a82b8b2007-07-11 11:09:12 +1000418 *agp = NULLAGNUMBER;
419
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000420 pip = xfs_filestream_get_parent(ip);
421 if (!pip)
422 goto exit;
423
424 mru = xfs_mru_cache_remove(mp->m_filestream, pip->i_ino);
Christoph Hellwig22328d72014-04-23 07:11:51 +1000425 if (mru) {
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000426 struct xfs_fstrm_item *item =
427 container_of(mru, struct xfs_fstrm_item, mru);
428 startag = (item->ag + 1) % mp->m_sb.sb_agcount;
David Chinner2a82b8b2007-07-11 11:09:12 +1000429 }
430
David Chinner2a82b8b2007-07-11 11:09:12 +1000431 flags = (ap->userdata ? XFS_PICK_USERDATA : 0) |
Dave Chinner0937e0f2011-09-18 20:40:57 +0000432 (ap->flist->xbf_low ? XFS_PICK_LOWSPACE : 0);
David Chinner2a82b8b2007-07-11 11:09:12 +1000433
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000434 err = xfs_filestream_pick_ag(pip, startag, agp, flags, minlen);
David Chinner2a82b8b2007-07-11 11:09:12 +1000435
436 /*
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000437 * Only free the item here so we skip over the old AG earlier.
David Chinner2a82b8b2007-07-11 11:09:12 +1000438 */
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000439 if (mru)
440 xfs_fstrm_free_func(mru);
David Chinner2a82b8b2007-07-11 11:09:12 +1000441
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000442 IRELE(pip);
David Chinner2a82b8b2007-07-11 11:09:12 +1000443exit:
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000444 if (*agp == NULLAGNUMBER)
David Chinner2a82b8b2007-07-11 11:09:12 +1000445 *agp = 0;
David Chinner2a82b8b2007-07-11 11:09:12 +1000446 return err;
447}
448
David Chinner2a82b8b2007-07-11 11:09:12 +1000449void
450xfs_filestream_deassociate(
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000451 struct xfs_inode *ip)
David Chinner2a82b8b2007-07-11 11:09:12 +1000452{
Christoph Hellwig22328d72014-04-23 07:11:51 +1000453 xfs_mru_cache_delete(ip->i_mount->m_filestream, ip->i_ino);
David Chinner2a82b8b2007-07-11 11:09:12 +1000454}
Christoph Hellwig2cd2ef62014-04-23 07:11:51 +1000455
456int
457xfs_filestream_mount(
458 xfs_mount_t *mp)
459{
460 /*
461 * The filestream timer tunable is currently fixed within the range of
462 * one second to four minutes, with five seconds being the default. The
463 * group count is somewhat arbitrary, but it'd be nice to adhere to the
464 * timer tunable to within about 10 percent. This requires at least 10
465 * groups.
466 */
467 return xfs_mru_cache_create(&mp->m_filestream, xfs_fstrm_centisecs * 10,
468 10, xfs_fstrm_free_func);
469}
470
471void
472xfs_filestream_unmount(
473 xfs_mount_t *mp)
474{
475 xfs_mru_cache_destroy(mp->m_filestream);
476}
477
478
479/* needs to return a positive errno for the init path */
480int
481xfs_filestream_init(void)
482{
483 item_zone = kmem_zone_init(sizeof(struct xfs_fstrm_item), "fstrm_item");
484 if (!item_zone)
485 return -ENOMEM;
486 return 0;
487}
488
489void
490xfs_filestream_uninit(void)
491{
492 kmem_zone_destroy(item_zone);
493}