blob: 613370f9a4bd8037fd5250b5504e65c1e816c0f9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scotta805bad2006-06-19 08:40:27 +10002 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
Nathan Scott7b718762005-11-02 14:58:39 +11003 * 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_log.h"
21#include "xfs_clnt.h"
Nathan Scotta844f452005-11-02 14:38:42 +110022#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "xfs_trans.h"
24#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110025#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_dir2.h"
27#include "xfs_alloc.h"
28#include "xfs_dmapi.h"
29#include "xfs_quota.h"
30#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110032#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "xfs_ialloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
Nathan Scotta844f452005-11-02 14:38:42 +110035#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "xfs_dinode.h"
37#include "xfs_inode.h"
Nathan Scotta844f452005-11-02 14:38:42 +110038#include "xfs_btree.h"
39#include "xfs_ialloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include "xfs_rtalloc.h"
42#include "xfs_error.h"
43#include "xfs_itable.h"
Christoph Hellwig9909c4a2007-10-11 18:11:14 +100044#include "xfs_fsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include "xfs_rw.h"
46#include "xfs_acl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include "xfs_attr.h"
48#include "xfs_buf_item.h"
49#include "xfs_utils.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100050#include "xfs_vnodeops.h"
Christoph Hellwig745f6912007-08-30 17:20:39 +100051#include "xfs_vfsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include "xfs_version.h"
David Chinnera67d7c52007-11-23 16:29:32 +110053#include "xfs_log_priv.h"
David Chinner249a8c12008-02-05 12:13:32 +110054#include "xfs_trans_priv.h"
Christoph Hellwig48b62a12008-05-20 11:30:39 +100055#include "xfs_filestream.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <linux/namei.h>
58#include <linux/init.h>
59#include <linux/mount.h>
Christoph Hellwig0829c362005-09-02 16:58:49 +100060#include <linux/mempool.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#include <linux/writeback.h>
Christoph Hellwig4df08c52005-09-05 08:34:18 +100062#include <linux/kthread.h>
Nigel Cunningham7dfb7102006-12-06 20:34:23 -080063#include <linux/freezer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
David Chinner7989cb82007-02-10 18:34:56 +110065static struct quotactl_ops xfs_quotactl_operations;
66static struct super_operations xfs_super_operations;
67static kmem_zone_t *xfs_vnode_zone;
68static kmem_zone_t *xfs_ioend_zone;
Christoph Hellwig0829c362005-09-02 16:58:49 +100069mempool_t *xfs_ioend_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71STATIC struct xfs_mount_args *
72xfs_args_allocate(
Nathan Scott764d1f82006-03-31 13:04:17 +100073 struct super_block *sb,
74 int silent)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
76 struct xfs_mount_args *args;
77
78 args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
79 args->logbufs = args->logbufsize = -1;
80 strncpy(args->fsname, sb->s_id, MAXNAMELEN);
81
82 /* Copy the already-parsed mount(2) flags we're interested in */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (sb->s_flags & MS_DIRSYNC)
84 args->flags |= XFSMNT_DIRSYNC;
85 if (sb->s_flags & MS_SYNCHRONOUS)
86 args->flags |= XFSMNT_WSYNC;
Nathan Scott764d1f82006-03-31 13:04:17 +100087 if (silent)
88 args->flags |= XFSMNT_QUIET;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 args->flags |= XFSMNT_32BITINODES;
90
91 return args;
92}
93
David Chinnera67d7c52007-11-23 16:29:32 +110094#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
95#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
96#define MNTOPT_LOGDEV "logdev" /* log device */
97#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
98#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
99#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
100#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
101#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
102#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
103#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
104#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
105#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
106#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
107#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
108#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
109#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
110#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
111#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
112#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
113#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
114 * unwritten extent conversion */
115#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
116#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
117#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
118#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
119#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
120#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
121#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
122 * in stat(). */
123#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
124#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
125#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
126#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
127#define MNTOPT_NOQUOTA "noquota" /* no quotas */
128#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
129#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
130#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
131#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
132#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
133#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
134#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
135#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
136#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
137#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
138#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
139#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
140#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
141
142STATIC unsigned long
143suffix_strtoul(char *s, char **endp, unsigned int base)
144{
145 int last, shift_left_factor = 0;
146 char *value = s;
147
148 last = strlen(value) - 1;
149 if (value[last] == 'K' || value[last] == 'k') {
150 shift_left_factor = 10;
151 value[last] = '\0';
152 }
153 if (value[last] == 'M' || value[last] == 'm') {
154 shift_left_factor = 20;
155 value[last] = '\0';
156 }
157 if (value[last] == 'G' || value[last] == 'g') {
158 shift_left_factor = 30;
159 value[last] = '\0';
160 }
161
162 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
163}
164
165STATIC int
166xfs_parseargs(
167 struct xfs_mount *mp,
168 char *options,
169 struct xfs_mount_args *args,
170 int update)
171{
172 char *this_char, *value, *eov;
173 int dsunit, dswidth, vol_dsunit, vol_dswidth;
174 int iosize;
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100175 int dmapi_implies_ikeep = 1;
David Chinnera67d7c52007-11-23 16:29:32 +1100176
177 args->flags |= XFSMNT_BARRIER;
178 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
179
180 if (!options)
181 goto done;
182
183 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
184
185 while ((this_char = strsep(&options, ",")) != NULL) {
186 if (!*this_char)
187 continue;
188 if ((value = strchr(this_char, '=')) != NULL)
189 *value++ = 0;
190
191 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
192 if (!value || !*value) {
193 cmn_err(CE_WARN,
194 "XFS: %s option requires an argument",
195 this_char);
196 return EINVAL;
197 }
198 args->logbufs = simple_strtoul(value, &eov, 10);
199 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
200 if (!value || !*value) {
201 cmn_err(CE_WARN,
202 "XFS: %s option requires an argument",
203 this_char);
204 return EINVAL;
205 }
206 args->logbufsize = suffix_strtoul(value, &eov, 10);
207 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
208 if (!value || !*value) {
209 cmn_err(CE_WARN,
210 "XFS: %s option requires an argument",
211 this_char);
212 return EINVAL;
213 }
214 strncpy(args->logname, value, MAXNAMELEN);
215 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
216 if (!value || !*value) {
217 cmn_err(CE_WARN,
218 "XFS: %s option requires an argument",
219 this_char);
220 return EINVAL;
221 }
222 strncpy(args->mtpt, value, MAXNAMELEN);
223 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
224 if (!value || !*value) {
225 cmn_err(CE_WARN,
226 "XFS: %s option requires an argument",
227 this_char);
228 return EINVAL;
229 }
230 strncpy(args->rtname, value, MAXNAMELEN);
231 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
232 if (!value || !*value) {
233 cmn_err(CE_WARN,
234 "XFS: %s option requires an argument",
235 this_char);
236 return EINVAL;
237 }
238 iosize = simple_strtoul(value, &eov, 10);
239 args->flags |= XFSMNT_IOSIZE;
240 args->iosizelog = (uint8_t) iosize;
241 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
242 if (!value || !*value) {
243 cmn_err(CE_WARN,
244 "XFS: %s option requires an argument",
245 this_char);
246 return EINVAL;
247 }
248 iosize = suffix_strtoul(value, &eov, 10);
249 args->flags |= XFSMNT_IOSIZE;
250 args->iosizelog = ffs(iosize) - 1;
251 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
252 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
253 mp->m_flags |= XFS_MOUNT_GRPID;
254 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
255 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
256 mp->m_flags &= ~XFS_MOUNT_GRPID;
257 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
258 args->flags |= XFSMNT_WSYNC;
259 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
260 args->flags |= XFSMNT_OSYNCISOSYNC;
261 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
262 args->flags |= XFSMNT_NORECOVERY;
263 } else if (!strcmp(this_char, MNTOPT_INO64)) {
264 args->flags |= XFSMNT_INO64;
265#if !XFS_BIG_INUMS
266 cmn_err(CE_WARN,
267 "XFS: %s option not allowed on this system",
268 this_char);
269 return EINVAL;
270#endif
271 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
272 args->flags |= XFSMNT_NOALIGN;
273 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
274 args->flags |= XFSMNT_SWALLOC;
275 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
276 if (!value || !*value) {
277 cmn_err(CE_WARN,
278 "XFS: %s option requires an argument",
279 this_char);
280 return EINVAL;
281 }
282 dsunit = simple_strtoul(value, &eov, 10);
283 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
284 if (!value || !*value) {
285 cmn_err(CE_WARN,
286 "XFS: %s option requires an argument",
287 this_char);
288 return EINVAL;
289 }
290 dswidth = simple_strtoul(value, &eov, 10);
291 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
292 args->flags &= ~XFSMNT_32BITINODES;
293#if !XFS_BIG_INUMS
294 cmn_err(CE_WARN,
295 "XFS: %s option not allowed on this system",
296 this_char);
297 return EINVAL;
298#endif
299 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
300 args->flags |= XFSMNT_NOUUID;
301 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
302 args->flags |= XFSMNT_BARRIER;
303 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
304 args->flags &= ~XFSMNT_BARRIER;
305 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100306 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100307 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100308 dmapi_implies_ikeep = 0;
309 args->flags &= ~XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100310 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
311 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
312 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
313 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
314 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
315 args->flags |= XFSMNT_ATTR2;
316 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
317 args->flags &= ~XFSMNT_ATTR2;
Tim Shimmin7c12f292008-04-30 18:15:28 +1000318 args->flags |= XFSMNT_NOATTR2;
David Chinnera67d7c52007-11-23 16:29:32 +1100319 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
320 args->flags2 |= XFSMNT2_FILESTREAMS;
321 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
322 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
323 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
324 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
325 !strcmp(this_char, MNTOPT_UQUOTA) ||
326 !strcmp(this_char, MNTOPT_USRQUOTA)) {
327 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
328 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
329 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
330 args->flags |= XFSMNT_UQUOTA;
331 args->flags &= ~XFSMNT_UQUOTAENF;
332 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
333 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
334 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
335 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
336 args->flags |= XFSMNT_PQUOTA;
337 args->flags &= ~XFSMNT_PQUOTAENF;
338 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
339 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
340 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
341 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
342 args->flags |= XFSMNT_GQUOTA;
343 args->flags &= ~XFSMNT_GQUOTAENF;
344 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
345 args->flags |= XFSMNT_DMAPI;
346 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
347 args->flags |= XFSMNT_DMAPI;
348 } else if (!strcmp(this_char, MNTOPT_DMI)) {
349 args->flags |= XFSMNT_DMAPI;
350 } else if (!strcmp(this_char, "ihashsize")) {
351 cmn_err(CE_WARN,
352 "XFS: ihashsize no longer used, option is deprecated.");
353 } else if (!strcmp(this_char, "osyncisdsync")) {
354 /* no-op, this is now the default */
355 cmn_err(CE_WARN,
356 "XFS: osyncisdsync is now the default, option is deprecated.");
357 } else if (!strcmp(this_char, "irixsgid")) {
358 cmn_err(CE_WARN,
359 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
360 } else {
361 cmn_err(CE_WARN,
362 "XFS: unknown mount option [%s].", this_char);
363 return EINVAL;
364 }
365 }
366
367 if (args->flags & XFSMNT_NORECOVERY) {
368 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
369 cmn_err(CE_WARN,
370 "XFS: no-recovery mounts must be read-only.");
371 return EINVAL;
372 }
373 }
374
375 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
376 cmn_err(CE_WARN,
377 "XFS: sunit and swidth options incompatible with the noalign option");
378 return EINVAL;
379 }
380
381 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
382 cmn_err(CE_WARN,
383 "XFS: cannot mount with both project and group quota");
384 return EINVAL;
385 }
386
387 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
388 printk("XFS: %s option needs the mount point option as well\n",
389 MNTOPT_DMAPI);
390 return EINVAL;
391 }
392
393 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
394 cmn_err(CE_WARN,
395 "XFS: sunit and swidth must be specified together");
396 return EINVAL;
397 }
398
399 if (dsunit && (dswidth % dsunit != 0)) {
400 cmn_err(CE_WARN,
401 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
402 dswidth, dsunit);
403 return EINVAL;
404 }
405
406 /*
407 * Applications using DMI filesystems often expect the
408 * inode generation number to be monotonically increasing.
409 * If we delete inode chunks we break this assumption, so
410 * keep unused inode chunks on disk for DMI filesystems
411 * until we come up with a better solution.
412 * Note that if "ikeep" or "noikeep" mount options are
413 * supplied, then they are honored.
414 */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100415 if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep)
416 args->flags |= XFSMNT_IKEEP;
David Chinnera67d7c52007-11-23 16:29:32 +1100417
418 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
419 if (dsunit) {
420 args->sunit = dsunit;
421 args->flags |= XFSMNT_RETERR;
422 } else {
423 args->sunit = vol_dsunit;
424 }
425 dswidth ? (args->swidth = dswidth) :
426 (args->swidth = vol_dswidth);
427 } else {
428 args->sunit = args->swidth = 0;
429 }
430
431done:
432 if (args->flags & XFSMNT_32BITINODES)
433 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
434 if (args->flags2)
435 args->flags |= XFSMNT_FLAGS2;
436 return 0;
437}
438
439struct proc_xfs_info {
440 int flag;
441 char *str;
442};
443
444STATIC int
445xfs_showargs(
446 struct xfs_mount *mp,
447 struct seq_file *m)
448{
449 static struct proc_xfs_info xfs_info_set[] = {
450 /* the few simple ones we can get from the mount struct */
Josef Jeff Sipek1bd960e2008-02-29 13:58:40 +1100451 { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
David Chinnera67d7c52007-11-23 16:29:32 +1100452 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
453 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
454 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
455 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
456 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
457 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
458 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
459 { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
460 { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
461 { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
462 { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
463 { 0, NULL }
464 };
465 static struct proc_xfs_info xfs_info_unset[] = {
466 /* the few simple ones we can get from the mount struct */
David Chinnera67d7c52007-11-23 16:29:32 +1100467 { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
468 { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
469 { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
470 { 0, NULL }
471 };
472 struct proc_xfs_info *xfs_infop;
473
474 for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
475 if (mp->m_flags & xfs_infop->flag)
476 seq_puts(m, xfs_infop->str);
477 }
478 for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
479 if (!(mp->m_flags & xfs_infop->flag))
480 seq_puts(m, xfs_infop->str);
481 }
482
483 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
484 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
485 (int)(1 << mp->m_writeio_log) >> 10);
486
487 if (mp->m_logbufs > 0)
488 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
489 if (mp->m_logbsize > 0)
490 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
491
492 if (mp->m_logname)
493 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
494 if (mp->m_rtname)
495 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
496
497 if (mp->m_dalign > 0)
498 seq_printf(m, "," MNTOPT_SUNIT "=%d",
499 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
500 if (mp->m_swidth > 0)
501 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
502 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
503
504 if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
505 seq_puts(m, "," MNTOPT_USRQUOTA);
506 else if (mp->m_qflags & XFS_UQUOTA_ACCT)
507 seq_puts(m, "," MNTOPT_UQUOTANOENF);
508
509 if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
510 seq_puts(m, "," MNTOPT_PRJQUOTA);
511 else if (mp->m_qflags & XFS_PQUOTA_ACCT)
512 seq_puts(m, "," MNTOPT_PQUOTANOENF);
513
514 if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
515 seq_puts(m, "," MNTOPT_GRPQUOTA);
516 else if (mp->m_qflags & XFS_GQUOTA_ACCT)
517 seq_puts(m, "," MNTOPT_GQUOTANOENF);
518
519 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
520 seq_puts(m, "," MNTOPT_NOQUOTA);
521
522 return 0;
523}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524__uint64_t
525xfs_max_file_offset(
526 unsigned int blockshift)
527{
528 unsigned int pagefactor = 1;
529 unsigned int bitshift = BITS_PER_LONG - 1;
530
531 /* Figure out maximum filesize, on Linux this can depend on
532 * the filesystem blocksize (on 32 bit platforms).
533 * __block_prepare_write does this in an [unsigned] long...
534 * page->index << (PAGE_CACHE_SHIFT - bbits)
535 * So, for page sized blocks (4K on 32 bit platforms),
536 * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
537 * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
538 * but for smaller blocksizes it is less (bbits = log2 bsize).
539 * Note1: get_block_t takes a long (implicit cast from above)
540 * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
541 * can optionally convert the [unsigned] long from above into
542 * an [unsigned] long long.
543 */
544
545#if BITS_PER_LONG == 32
546# if defined(CONFIG_LBD)
547 ASSERT(sizeof(sector_t) == 8);
548 pagefactor = PAGE_CACHE_SIZE;
549 bitshift = BITS_PER_LONG;
550# else
551 pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
552# endif
553#endif
554
555 return (((__uint64_t)pagefactor) << bitshift) - 1;
556}
557
David Chinner7989cb82007-02-10 18:34:56 +1100558STATIC_INLINE void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559xfs_set_inodeops(
560 struct inode *inode)
561{
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000562 switch (inode->i_mode & S_IFMT) {
563 case S_IFREG:
Nathan Scott416c6d52006-03-14 14:00:51 +1100564 inode->i_op = &xfs_inode_operations;
Nathan Scott3562fd42006-03-14 14:00:35 +1100565 inode->i_fop = &xfs_file_operations;
Nathan Scotte4c573b2006-03-14 13:54:26 +1100566 inode->i_mapping->a_ops = &xfs_address_space_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000567 break;
568 case S_IFDIR:
Nathan Scott416c6d52006-03-14 14:00:51 +1100569 inode->i_op = &xfs_dir_inode_operations;
Nathan Scott3562fd42006-03-14 14:00:35 +1100570 inode->i_fop = &xfs_dir_file_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000571 break;
572 case S_IFLNK:
Nathan Scott416c6d52006-03-14 14:00:51 +1100573 inode->i_op = &xfs_symlink_inode_operations;
Christoph Hellwig222096a2008-02-05 12:13:46 +1100574 if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
Nathan Scotte4c573b2006-03-14 13:54:26 +1100575 inode->i_mapping->a_ops = &xfs_address_space_operations;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000576 break;
577 default:
Nathan Scott416c6d52006-03-14 14:00:51 +1100578 inode->i_op = &xfs_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 init_special_inode(inode, inode->i_mode, inode->i_rdev);
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000580 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582}
583
David Chinner7989cb82007-02-10 18:34:56 +1100584STATIC_INLINE void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585xfs_revalidate_inode(
586 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000587 bhv_vnode_t *vp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 xfs_inode_t *ip)
589{
Nathan Scottec86dc02006-03-17 17:25:36 +1100590 struct inode *inode = vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000592 inode->i_mode = ip->i_d.di_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 inode->i_nlink = ip->i_d.di_nlink;
594 inode->i_uid = ip->i_d.di_uid;
595 inode->i_gid = ip->i_d.di_gid;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000596
597 switch (inode->i_mode & S_IFMT) {
598 case S_IFBLK:
599 case S_IFCHR:
600 inode->i_rdev =
601 MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
602 sysv_minor(ip->i_df.if_u2.if_rdev));
603 break;
604 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 inode->i_rdev = 0;
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000606 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
Christoph Hellwig0432dab2005-09-02 16:46:51 +1000608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 inode->i_generation = ip->i_d.di_gen;
610 i_size_write(inode, ip->i_d.di_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
612 inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
613 inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
614 inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
615 inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
616 inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
617 if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
618 inode->i_flags |= S_IMMUTABLE;
619 else
620 inode->i_flags &= ~S_IMMUTABLE;
621 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
622 inode->i_flags |= S_APPEND;
623 else
624 inode->i_flags &= ~S_APPEND;
625 if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
626 inode->i_flags |= S_SYNC;
627 else
628 inode->i_flags &= ~S_SYNC;
629 if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
630 inode->i_flags |= S_NOATIME;
631 else
632 inode->i_flags &= ~S_NOATIME;
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +1000633 xfs_iflags_clear(ip, XFS_IMODIFIED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634}
635
636void
637xfs_initialize_vnode(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000638 struct xfs_mount *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000639 bhv_vnode_t *vp,
Christoph Hellwig745f6912007-08-30 17:20:39 +1000640 struct xfs_inode *ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641{
Nathan Scottec86dc02006-03-17 17:25:36 +1100642 struct inode *inode = vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000644 if (!ip->i_vnode) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +1000645 ip->i_vnode = vp;
646 inode->i_private = ip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
649 /*
650 * We need to set the ops vectors, and unlock the inode, but if
651 * we have been called during the new inode create process, it is
652 * too early to fill in the Linux inode. We will get called a
653 * second time once the inode is properly set up, and then we can
654 * finish our work.
655 */
Christoph Hellwig745f6912007-08-30 17:20:39 +1000656 if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000657 xfs_revalidate_inode(mp, vp, ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 xfs_set_inodeops(inode);
Nathan Scottec86dc02006-03-17 17:25:36 +1100659
David Chinner7a18c382006-11-11 18:04:54 +1100660 xfs_iflags_clear(ip, XFS_INEW);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 barrier();
662
663 unlock_new_inode(inode);
664 }
665}
666
667int
668xfs_blkdev_get(
669 xfs_mount_t *mp,
670 const char *name,
671 struct block_device **bdevp)
672{
673 int error = 0;
674
675 *bdevp = open_bdev_excl(name, 0, mp);
676 if (IS_ERR(*bdevp)) {
677 error = PTR_ERR(*bdevp);
678 printk("XFS: Invalid device [%s], error=%d\n", name, error);
679 }
680
681 return -error;
682}
683
684void
685xfs_blkdev_put(
686 struct block_device *bdev)
687{
688 if (bdev)
689 close_bdev_excl(bdev);
690}
691
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100692/*
693 * Try to write out the superblock using barriers.
694 */
695STATIC int
696xfs_barrier_test(
697 xfs_mount_t *mp)
698{
699 xfs_buf_t *sbp = xfs_getsb(mp, 0);
700 int error;
701
702 XFS_BUF_UNDONE(sbp);
703 XFS_BUF_UNREAD(sbp);
704 XFS_BUF_UNDELAYWRITE(sbp);
705 XFS_BUF_WRITE(sbp);
706 XFS_BUF_UNASYNC(sbp);
707 XFS_BUF_ORDERED(sbp);
708
709 xfsbdstrat(mp, sbp);
710 error = xfs_iowait(sbp);
711
712 /*
713 * Clear all the flags we set and possible error state in the
714 * buffer. We only did the write to try out whether barriers
715 * worked and shouldn't leave any traces in the superblock
716 * buffer.
717 */
718 XFS_BUF_DONE(sbp);
719 XFS_BUF_ERROR(sbp, 0);
720 XFS_BUF_UNORDERED(sbp);
721
722 xfs_buf_relse(sbp);
723 return error;
724}
725
726void
727xfs_mountfs_check_barriers(xfs_mount_t *mp)
728{
729 int error;
730
731 if (mp->m_logdev_targp != mp->m_ddev_targp) {
732 xfs_fs_cmn_err(CE_NOTE, mp,
733 "Disabling barriers, not supported with external log device");
734 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100735 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100736 }
737
Nathan Scottce8e9222006-01-11 15:39:08 +1100738 if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100739 QUEUE_ORDERED_NONE) {
740 xfs_fs_cmn_err(CE_NOTE, mp,
741 "Disabling barriers, not supported by the underlying device");
742 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100743 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100744 }
745
Nathan Scottb2ea4012006-07-28 17:05:13 +1000746 if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
747 xfs_fs_cmn_err(CE_NOTE, mp,
748 "Disabling barriers, underlying device is readonly");
749 mp->m_flags &= ~XFS_MOUNT_BARRIER;
750 return;
751 }
752
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100753 error = xfs_barrier_test(mp);
754 if (error) {
755 xfs_fs_cmn_err(CE_NOTE, mp,
756 "Disabling barriers, trial barrier write failed");
757 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100758 return;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100759 }
760}
761
762void
763xfs_blkdev_issue_flush(
764 xfs_buftarg_t *buftarg)
765{
Nathan Scottce8e9222006-01-11 15:39:08 +1100766 blkdev_issue_flush(buftarg->bt_bdev, NULL);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100767}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000769STATIC void
770xfs_close_devices(
771 struct xfs_mount *mp)
772{
773 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
774 xfs_free_buftarg(mp->m_logdev_targp);
775 xfs_blkdev_put(mp->m_logdev_targp->bt_bdev);
776 }
777 if (mp->m_rtdev_targp) {
778 xfs_free_buftarg(mp->m_rtdev_targp);
779 xfs_blkdev_put(mp->m_rtdev_targp->bt_bdev);
780 }
781 xfs_free_buftarg(mp->m_ddev_targp);
782}
783
784/*
785 * The file system configurations are:
786 * (1) device (partition) with data and internal log
787 * (2) logical volume with data and log subvolumes.
788 * (3) logical volume with data, log, and realtime subvolumes.
789 *
790 * We only have to handle opening the log and realtime volumes here if
791 * they are present. The data subvolume has already been opened by
792 * get_sb_bdev() and is stored in sb->s_bdev.
793 */
794STATIC int
795xfs_open_devices(
796 struct xfs_mount *mp,
797 struct xfs_mount_args *args)
798{
799 struct block_device *ddev = mp->m_super->s_bdev;
800 struct block_device *logdev = NULL, *rtdev = NULL;
801 int error;
802
803 /*
804 * Open real time and log devices - order is important.
805 */
806 if (args->logname[0]) {
807 error = xfs_blkdev_get(mp, args->logname, &logdev);
808 if (error)
809 goto out;
810 }
811
812 if (args->rtname[0]) {
813 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
814 if (error)
815 goto out_close_logdev;
816
817 if (rtdev == ddev || rtdev == logdev) {
818 cmn_err(CE_WARN,
819 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
820 error = EINVAL;
821 goto out_close_rtdev;
822 }
823 }
824
825 /*
826 * Setup xfs_mount buffer target pointers
827 */
828 error = ENOMEM;
829 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
830 if (!mp->m_ddev_targp)
831 goto out_close_rtdev;
832
833 if (rtdev) {
834 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
835 if (!mp->m_rtdev_targp)
836 goto out_free_ddev_targ;
837 }
838
839 if (logdev && logdev != ddev) {
840 mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
841 if (!mp->m_logdev_targp)
842 goto out_free_rtdev_targ;
843 } else {
844 mp->m_logdev_targp = mp->m_ddev_targp;
845 }
846
847 return 0;
848
849 out_free_rtdev_targ:
850 if (mp->m_rtdev_targp)
851 xfs_free_buftarg(mp->m_rtdev_targp);
852 out_free_ddev_targ:
853 xfs_free_buftarg(mp->m_ddev_targp);
854 out_close_rtdev:
855 if (rtdev)
856 xfs_blkdev_put(rtdev);
857 out_close_logdev:
858 if (logdev && logdev != ddev)
859 xfs_blkdev_put(logdev);
860 out:
861 return error;
862}
863
Christoph Hellwige34b5622008-05-20 15:10:36 +1000864/*
865 * Setup xfs_mount buffer target pointers based on superblock
866 */
867STATIC int
868xfs_setup_devices(
869 struct xfs_mount *mp)
870{
871 int error;
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000872
Christoph Hellwige34b5622008-05-20 15:10:36 +1000873 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
874 mp->m_sb.sb_sectsize);
875 if (error)
876 return error;
877
878 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
879 unsigned int log_sector_size = BBSIZE;
880
881 if (xfs_sb_version_hassector(&mp->m_sb))
882 log_sector_size = mp->m_sb.sb_logsectsize;
883 error = xfs_setsize_buftarg(mp->m_logdev_targp,
884 mp->m_sb.sb_blocksize,
885 log_sector_size);
886 if (error)
887 return error;
888 }
889 if (mp->m_rtdev_targp) {
890 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
891 mp->m_sb.sb_blocksize,
892 mp->m_sb.sb_sectsize);
893 if (error)
894 return error;
895 }
896
897 return 0;
898}
Christoph Hellwig19f354d2008-05-20 11:31:13 +1000899
David Chinner249a8c12008-02-05 12:13:32 +1100900/*
901 * XFS AIL push thread support
902 */
903void
904xfsaild_wakeup(
905 xfs_mount_t *mp,
906 xfs_lsn_t threshold_lsn)
907{
908 mp->m_ail.xa_target = threshold_lsn;
909 wake_up_process(mp->m_ail.xa_task);
910}
911
912int
913xfsaild(
914 void *data)
915{
916 xfs_mount_t *mp = (xfs_mount_t *)data;
917 xfs_lsn_t last_pushed_lsn = 0;
918 long tout = 0;
919
920 while (!kthread_should_stop()) {
921 if (tout)
922 schedule_timeout_interruptible(msecs_to_jiffies(tout));
923 tout = 1000;
924
925 /* swsusp */
926 try_to_freeze();
927
928 ASSERT(mp->m_log);
929 if (XFS_FORCED_SHUTDOWN(mp))
930 continue;
931
932 tout = xfsaild_push(mp, &last_pushed_lsn);
933 }
934
935 return 0;
936} /* xfsaild */
937
938int
939xfsaild_start(
940 xfs_mount_t *mp)
941{
942 mp->m_ail.xa_target = 0;
943 mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
944 if (IS_ERR(mp->m_ail.xa_task))
945 return -PTR_ERR(mp->m_ail.xa_task);
946 return 0;
947}
948
949void
950xfsaild_stop(
951 xfs_mount_t *mp)
952{
953 kthread_stop(mp->m_ail.xa_task);
954}
955
956
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958STATIC struct inode *
Nathan Scotta50cd262006-03-14 14:06:18 +1100959xfs_fs_alloc_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 struct super_block *sb)
961{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000962 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Nathan Scott87582802006-03-14 13:18:19 +1100964 vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
965 if (unlikely(!vp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 return NULL;
Nathan Scottec86dc02006-03-17 17:25:36 +1100967 return vn_to_inode(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
970STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100971xfs_fs_destroy_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 struct inode *inode)
973{
Nathan Scottec86dc02006-03-17 17:25:36 +1100974 kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975}
976
977STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +1100978xfs_fs_inode_init_once(
Christoph Lameter4ba9b9d2007-10-16 23:25:51 -0700979 void *vnode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980{
Christoph Lametera35afb82007-05-16 22:10:57 -0700981 inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982}
983
Lachlan McIlroyde2eeea2008-02-06 13:37:56 +1100984STATIC int __init
Nathan Scott87582802006-03-14 13:18:19 +1100985xfs_init_zones(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000987 xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
Nathan Scotte0cc2322006-03-14 13:19:55 +1100988 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
989 KM_ZONE_SPREAD,
Nathan Scotta50cd262006-03-14 14:06:18 +1100990 xfs_fs_inode_init_once);
Christoph Hellwig0829c362005-09-02 16:58:49 +1000991 if (!xfs_vnode_zone)
992 goto out;
993
994 xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
995 if (!xfs_ioend_zone)
996 goto out_destroy_vnode_zone;
997
Matthew Dobson93d23412006-03-26 01:37:50 -0800998 xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
999 xfs_ioend_zone);
Christoph Hellwig0829c362005-09-02 16:58:49 +10001000 if (!xfs_ioend_pool)
1001 goto out_free_ioend_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 return 0;
Christoph Hellwig0829c362005-09-02 16:58:49 +10001003
Christoph Hellwig0829c362005-09-02 16:58:49 +10001004 out_free_ioend_zone:
1005 kmem_zone_destroy(xfs_ioend_zone);
1006 out_destroy_vnode_zone:
1007 kmem_zone_destroy(xfs_vnode_zone);
1008 out:
1009 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}
1011
1012STATIC void
Nathan Scott87582802006-03-14 13:18:19 +11001013xfs_destroy_zones(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Christoph Hellwig0829c362005-09-02 16:58:49 +10001015 mempool_destroy(xfs_ioend_pool);
1016 kmem_zone_destroy(xfs_vnode_zone);
1017 kmem_zone_destroy(xfs_ioend_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
1020/*
1021 * Attempt to flush the inode, this will actually fail
1022 * if the inode is pinned, but we dirty the inode again
1023 * at the point when it is unpinned after a log write,
Nathan Scott87582802006-03-14 13:18:19 +11001024 * since this is when the inode itself becomes flushable.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 */
1026STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001027xfs_fs_write_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 struct inode *inode,
1029 int sync)
1030{
David Chinnera3f74ff2008-03-06 13:43:42 +11001031 int error = 0;
1032 int flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001034 xfs_itrace_entry(XFS_I(inode));
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001035 if (sync) {
1036 filemap_fdatawait(inode->i_mapping);
1037 flags |= FLUSH_SYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 }
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001039 error = xfs_inode_flush(XFS_I(inode), flags);
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001040 /*
1041 * if we failed to write out the inode then mark
1042 * it dirty again so we'll try again later.
1043 */
1044 if (error)
1045 mark_inode_dirty_sync(inode);
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 return -error;
1048}
1049
1050STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001051xfs_fs_clear_inode(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 struct inode *inode)
1053{
Christoph Hellwig1543d792007-08-29 11:46:47 +10001054 xfs_inode_t *ip = XFS_I(inode);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001055
Christoph Hellwig02ba71d2005-09-05 08:28:02 +10001056 /*
Christoph Hellwig1543d792007-08-29 11:46:47 +10001057 * ip can be null when xfs_iget_core calls xfs_idestroy if we
Christoph Hellwig02ba71d2005-09-05 08:28:02 +10001058 * find an inode with di_mode == 0 but without IGET_CREATE set.
1059 */
Christoph Hellwig1543d792007-08-29 11:46:47 +10001060 if (ip) {
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001061 xfs_itrace_entry(ip);
Christoph Hellwig1543d792007-08-29 11:46:47 +10001062 XFS_STATS_INC(vn_rele);
1063 XFS_STATS_INC(vn_remove);
1064 XFS_STATS_INC(vn_reclaim);
1065 XFS_STATS_DEC(vn_active);
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001066
Christoph Hellwig1543d792007-08-29 11:46:47 +10001067 xfs_inactive(ip);
1068 xfs_iflags_clear(ip, XFS_IMODIFIED);
1069 if (xfs_reclaim(ip))
Harvey Harrison34a622b2008-04-10 12:19:21 +10001070 panic("%s: cannot reclaim 0x%p\n", __func__, inode);
Christoph Hellwigb3aea4e2007-08-29 11:44:37 +10001071 }
Christoph Hellwig56d433e2005-09-05 08:23:54 +10001072
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001073 ASSERT(XFS_I(inode) == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074}
1075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076/*
1077 * Enqueue a work item to be picked up by the vfs xfssyncd thread.
1078 * Doing this has two advantages:
1079 * - It saves on stack space, which is tight in certain situations
1080 * - It can be used (with care) as a mechanism to avoid deadlocks.
1081 * Flushing while allocating in a full filesystem requires both.
1082 */
1083STATIC void
1084xfs_syncd_queue_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001085 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 void *data,
Christoph Hellwig74394492007-08-30 17:21:22 +10001087 void (*syncer)(struct xfs_mount *, void *))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088{
Nathan Scottb83bd132006-06-09 16:48:30 +10001089 struct bhv_vfs_sync_work *work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
Nathan Scottb83bd132006-06-09 16:48:30 +10001091 work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 INIT_LIST_HEAD(&work->w_list);
1093 work->w_syncer = syncer;
1094 work->w_data = data;
Christoph Hellwig74394492007-08-30 17:21:22 +10001095 work->w_mount = mp;
1096 spin_lock(&mp->m_sync_lock);
1097 list_add_tail(&work->w_list, &mp->m_sync_list);
1098 spin_unlock(&mp->m_sync_lock);
1099 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
1102/*
1103 * Flush delayed allocate data, attempting to free up reserved space
1104 * from existing allocations. At this point a new allocation attempt
1105 * has failed with ENOSPC and we are in the process of scratching our
1106 * heads, looking about for more room...
1107 */
1108STATIC void
1109xfs_flush_inode_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001110 struct xfs_mount *mp,
1111 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112{
Christoph Hellwig74394492007-08-30 17:21:22 +10001113 struct inode *inode = arg;
1114 filemap_flush(inode->i_mapping);
1115 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116}
1117
1118void
1119xfs_flush_inode(
1120 xfs_inode_t *ip)
1121{
Christoph Hellwig74394492007-08-30 17:21:22 +10001122 struct inode *inode = ip->i_vnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001125 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001126 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
1129/*
1130 * This is the "bigger hammer" version of xfs_flush_inode_work...
1131 * (IOW, "If at first you don't succeed, use a Bigger Hammer").
1132 */
1133STATIC void
1134xfs_flush_device_work(
Christoph Hellwig74394492007-08-30 17:21:22 +10001135 struct xfs_mount *mp,
1136 void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137{
Christoph Hellwig74394492007-08-30 17:21:22 +10001138 struct inode *inode = arg;
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001139 sync_blockdev(mp->m_super->s_bdev);
Christoph Hellwig74394492007-08-30 17:21:22 +10001140 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
1143void
1144xfs_flush_device(
1145 xfs_inode_t *ip)
1146{
Nathan Scottec86dc02006-03-17 17:25:36 +11001147 struct inode *inode = vn_to_inode(XFS_ITOV(ip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 igrab(inode);
Christoph Hellwig74394492007-08-30 17:21:22 +10001150 xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001151 delay(msecs_to_jiffies(500));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
1153}
1154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155STATIC void
Christoph Hellwig74394492007-08-30 17:21:22 +10001156xfs_sync_worker(
1157 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 void *unused)
1159{
1160 int error;
1161
Christoph Hellwig74394492007-08-30 17:21:22 +10001162 if (!(mp->m_flags & XFS_MOUNT_RDONLY))
David Chinner7e206942008-04-17 16:49:55 +10001163 error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
Christoph Hellwig74394492007-08-30 17:21:22 +10001164 mp->m_sync_seq++;
1165 wake_up(&mp->m_wait_single_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166}
1167
1168STATIC int
1169xfssyncd(
1170 void *arg)
1171{
Christoph Hellwig74394492007-08-30 17:21:22 +10001172 struct xfs_mount *mp = arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 long timeleft;
Nathan Scottb83bd132006-06-09 16:48:30 +10001174 bhv_vfs_sync_work_t *work, *n;
Christoph Hellwig4df08c52005-09-05 08:34:18 +10001175 LIST_HEAD (tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Rafael J. Wysocki83144182007-07-17 04:03:35 -07001177 set_freezable();
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001178 timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 for (;;) {
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001180 timeleft = schedule_timeout_interruptible(timeleft);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 /* swsusp */
Christoph Lameter3e1d1d22005-06-24 23:13:50 -07001182 try_to_freeze();
Christoph Hellwig74394492007-08-30 17:21:22 +10001183 if (kthread_should_stop() && list_empty(&mp->m_sync_list))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 break;
1185
Christoph Hellwig74394492007-08-30 17:21:22 +10001186 spin_lock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 /*
1188 * We can get woken by laptop mode, to do a sync -
1189 * that's the (only!) case where the list would be
1190 * empty with time remaining.
1191 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001192 if (!timeleft || list_empty(&mp->m_sync_list)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (!timeleft)
Nishanth Aravamudan041e0e32005-09-10 00:27:23 -07001194 timeleft = xfs_syncd_centisecs *
1195 msecs_to_jiffies(10);
Christoph Hellwig74394492007-08-30 17:21:22 +10001196 INIT_LIST_HEAD(&mp->m_sync_work.w_list);
1197 list_add_tail(&mp->m_sync_work.w_list,
1198 &mp->m_sync_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001200 list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 list_move(&work->w_list, &tmp);
Christoph Hellwig74394492007-08-30 17:21:22 +10001202 spin_unlock(&mp->m_sync_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 list_for_each_entry_safe(work, n, &tmp, w_list) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001205 (*work->w_syncer)(mp, work->w_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 list_del(&work->w_list);
Christoph Hellwig74394492007-08-30 17:21:22 +10001207 if (work == &mp->m_sync_work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 continue;
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001209 kmem_free(work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 }
1211 }
1212
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 return 0;
1214}
1215
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001217xfs_fs_put_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 struct super_block *sb)
1219{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001220 struct xfs_mount *mp = XFS_M(sb);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001221 struct xfs_inode *rip = mp->m_rootip;
1222 int unmount_event_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 int error;
1224
Christoph Hellwig74394492007-08-30 17:21:22 +10001225 kthread_stop(mp->m_sync_task);
1226
Christoph Hellwig745f6912007-08-30 17:20:39 +10001227 xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001228
1229#ifdef HAVE_DMAPI
1230 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1231 unmount_event_flags =
1232 (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
1233 0 : DM_FLAGS_UNWANTED;
1234 /*
1235 * Ignore error from dmapi here, first unmount is not allowed
1236 * to fail anyway, and second we wouldn't want to fail a
1237 * unmount because of dmapi.
1238 */
1239 XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
1240 NULL, NULL, 0, 0, unmount_event_flags);
1241 }
1242#endif
1243
1244 /*
1245 * Blow away any referenced inode in the filestreams cache.
1246 * This can and will cause log traffic as inodes go inactive
1247 * here.
1248 */
1249 xfs_filestream_unmount(mp);
1250
1251 XFS_bflush(mp->m_ddev_targp);
1252 error = xfs_unmount_flush(mp, 0);
1253 WARN_ON(error);
1254
1255 IRELE(rip);
1256
1257 /*
1258 * If we're forcing a shutdown, typically because of a media error,
1259 * we want to make sure we invalidate dirty pages that belong to
1260 * referenced vnodes as well.
1261 */
1262 if (XFS_FORCED_SHUTDOWN(mp)) {
1263 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
1264 ASSERT(error != EFSCORRUPTED);
1265 }
1266
1267 if (mp->m_flags & XFS_MOUNT_DMAPI) {
1268 XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
1269 unmount_event_flags);
1270 }
1271
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001272 xfs_unmountfs(mp);
1273 xfs_close_devices(mp);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001274 xfs_qmops_put(mp);
1275 xfs_dmops_put(mp);
1276 kmem_free(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
1279STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001280xfs_fs_write_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 struct super_block *sb)
1282{
Nathan Scottb83bd132006-06-09 16:48:30 +10001283 if (!(sb->s_flags & MS_RDONLY))
Christoph Hellwig745f6912007-08-30 17:20:39 +10001284 xfs_sync(XFS_M(sb), SYNC_FSDATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 sb->s_dirt = 0;
1286}
1287
1288STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001289xfs_fs_sync_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 struct super_block *sb,
1291 int wait)
1292{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001293 struct xfs_mount *mp = XFS_M(sb);
Nathan Scottb83bd132006-06-09 16:48:30 +10001294 int error;
1295 int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001297 /*
1298 * Treat a sync operation like a freeze. This is to work
1299 * around a race in sync_inodes() which works in two phases
1300 * - an asynchronous flush, which can write out an inode
1301 * without waiting for file size updates to complete, and a
1302 * synchronous flush, which wont do anything because the
1303 * async flush removed the inode's dirty flag. Also
1304 * sync_inodes() will not see any files that just have
1305 * outstanding transactions to be flushed because we don't
1306 * dirty the Linux inode until after the transaction I/O
1307 * completes.
1308 */
1309 if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
David Chinner28239452007-02-10 18:36:40 +11001310 /*
1311 * First stage of freeze - no more writers will make progress
1312 * now we are here, so we flush delwri and delalloc buffers
1313 * here, then wait for all I/O to complete. Data is frozen at
1314 * that point. Metadata is not frozen, transactions can still
1315 * occur here so don't bother flushing the buftarg (i.e
1316 * SYNC_QUIESCE) because it'll just get dirty again.
1317 */
David Chinner516b2e72007-06-18 16:50:48 +10001318 flags = SYNC_DATA_QUIESCE;
David Chinner28239452007-02-10 18:36:40 +11001319 } else
Lachlan McIlroye893bff2007-10-12 11:13:35 +10001320 flags = SYNC_FSDATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Christoph Hellwig745f6912007-08-30 17:20:39 +10001322 error = xfs_sync(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 sb->s_dirt = 0;
1324
1325 if (unlikely(laptop_mode)) {
Christoph Hellwig74394492007-08-30 17:21:22 +10001326 int prev_sync_seq = mp->m_sync_seq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 /*
1329 * The disk must be active because we're syncing.
1330 * We schedule xfssyncd now (now that the disk is
1331 * active) instead of later (when it might not be).
1332 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001333 wake_up_process(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /*
1335 * We have to wait for the sync iteration to complete.
1336 * If we don't, the disk activity caused by the sync
1337 * will come after the sync is completed, and that
1338 * triggers another sync from laptop mode.
1339 */
Christoph Hellwig74394492007-08-30 17:21:22 +10001340 wait_event(mp->m_wait_single_sync_task,
1341 mp->m_sync_seq != prev_sync_seq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 }
1343
1344 return -error;
1345}
1346
1347STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001348xfs_fs_statfs(
David Howells726c3342006-06-23 02:02:58 -07001349 struct dentry *dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 struct kstatfs *statp)
1351{
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001352 struct xfs_mount *mp = XFS_M(dentry->d_sb);
1353 xfs_sb_t *sbp = &mp->m_sb;
1354 __uint64_t fakeinos, id;
1355 xfs_extlen_t lsize;
1356
1357 statp->f_type = XFS_SB_MAGIC;
1358 statp->f_namelen = MAXNAMELEN - 1;
1359
1360 id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
1361 statp->f_fsid.val[0] = (u32)id;
1362 statp->f_fsid.val[1] = (u32)(id >> 32);
1363
Christoph Hellwigd4d90b52008-04-22 17:34:37 +10001364 xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001365
1366 spin_lock(&mp->m_sb_lock);
1367 statp->f_bsize = sbp->sb_blocksize;
1368 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
1369 statp->f_blocks = sbp->sb_dblocks - lsize;
1370 statp->f_bfree = statp->f_bavail =
1371 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
1372 fakeinos = statp->f_bfree << sbp->sb_inopblog;
1373#if XFS_BIG_INUMS
1374 fakeinos += mp->m_inoadd;
1375#endif
1376 statp->f_files =
1377 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
1378 if (mp->m_maxicount)
1379#if XFS_BIG_INUMS
1380 if (!mp->m_inoadd)
1381#endif
1382 statp->f_files = min_t(typeof(statp->f_files),
1383 statp->f_files,
1384 mp->m_maxicount);
1385 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
1386 spin_unlock(&mp->m_sb_lock);
1387
1388 XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
1389 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390}
1391
1392STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001393xfs_fs_remount(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 struct super_block *sb,
1395 int *flags,
1396 char *options)
1397{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001398 struct xfs_mount *mp = XFS_M(sb);
Nathan Scott764d1f82006-03-31 13:04:17 +10001399 struct xfs_mount_args *args = xfs_args_allocate(sb, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 int error;
1401
Christoph Hellwig745f6912007-08-30 17:20:39 +10001402 error = xfs_parseargs(mp, options, args, 1);
Christoph Hellwig48b62a12008-05-20 11:30:39 +10001403 if (error)
1404 goto out_free_args;
1405
1406 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
1407 if (mp->m_flags & XFS_MOUNT_RDONLY)
1408 mp->m_flags &= ~XFS_MOUNT_RDONLY;
1409 if (args->flags & XFSMNT_BARRIER) {
1410 mp->m_flags |= XFS_MOUNT_BARRIER;
1411 xfs_mountfs_check_barriers(mp);
1412 } else {
1413 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1414 }
1415 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
1416 xfs_filestream_flush(mp);
1417 xfs_sync(mp, SYNC_DATA_QUIESCE);
1418 xfs_attr_quiesce(mp);
1419 mp->m_flags |= XFS_MOUNT_RDONLY;
1420 }
1421
1422 out_free_args:
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001423 kmem_free(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 return -error;
1425}
1426
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001427/*
1428 * Second stage of a freeze. The data is already frozen so we only
1429 * need to take care of themetadata. Once that's done write a dummy
1430 * record to dirty the log in case of a crash while frozen.
1431 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432STATIC void
Nathan Scotta50cd262006-03-14 14:06:18 +11001433xfs_fs_lockfs(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 struct super_block *sb)
1435{
Christoph Hellwig9909c4a2007-10-11 18:11:14 +10001436 struct xfs_mount *mp = XFS_M(sb);
1437
1438 xfs_attr_quiesce(mp);
1439 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440}
1441
1442STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001443xfs_fs_show_options(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 struct seq_file *m,
1445 struct vfsmount *mnt)
1446{
Christoph Hellwig745f6912007-08-30 17:20:39 +10001447 return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448}
1449
1450STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001451xfs_fs_quotasync(
Nathan Scottee348072005-11-02 10:32:38 +11001452 struct super_block *sb,
1453 int type)
1454{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001455 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
Nathan Scottee348072005-11-02 10:32:38 +11001456}
1457
1458STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001459xfs_fs_getxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 struct super_block *sb,
1461 struct fs_quota_stat *fqs)
1462{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001463 return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464}
1465
1466STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001467xfs_fs_setxstate(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 struct super_block *sb,
1469 unsigned int flags,
1470 int op)
1471{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001472 return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473}
1474
1475STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001476xfs_fs_getxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 struct super_block *sb,
1478 int type,
1479 qid_t id,
1480 struct fs_disk_quota *fdq)
1481{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001482 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001483 (type == USRQUOTA) ? Q_XGETQUOTA :
1484 ((type == GRPQUOTA) ? Q_XGETGQUOTA :
1485 Q_XGETPQUOTA), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486}
1487
1488STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001489xfs_fs_setxquota(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 struct super_block *sb,
1491 int type,
1492 qid_t id,
1493 struct fs_disk_quota *fdq)
1494{
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001495 return -XFS_QM_QUOTACTL(XFS_M(sb),
Nathan Scottb83bd132006-06-09 16:48:30 +10001496 (type == USRQUOTA) ? Q_XSETQLIM :
1497 ((type == GRPQUOTA) ? Q_XSETGQLIM :
1498 Q_XSETPQLIM), id, (caddr_t)fdq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499}
1500
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001501/*
1502 * This function fills in xfs_mount_t fields based on mount args.
1503 * Note: the superblock has _not_ yet been read in.
1504 */
1505STATIC int
1506xfs_start_flags(
1507 struct xfs_mount_args *ap,
1508 struct xfs_mount *mp)
1509{
1510 /* Values are in BBs */
1511 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1512 /*
1513 * At this point the superblock has not been read
1514 * in, therefore we do not know the block size.
1515 * Before the mount call ends we will convert
1516 * these to FSBs.
1517 */
1518 mp->m_dalign = ap->sunit;
1519 mp->m_swidth = ap->swidth;
1520 }
1521
1522 if (ap->logbufs != -1 &&
1523 ap->logbufs != 0 &&
1524 (ap->logbufs < XLOG_MIN_ICLOGS ||
1525 ap->logbufs > XLOG_MAX_ICLOGS)) {
1526 cmn_err(CE_WARN,
1527 "XFS: invalid logbufs value: %d [not %d-%d]",
1528 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
1529 return XFS_ERROR(EINVAL);
1530 }
1531 mp->m_logbufs = ap->logbufs;
1532 if (ap->logbufsize != -1 &&
1533 ap->logbufsize != 0 &&
1534 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
1535 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
1536 !is_power_of_2(ap->logbufsize))) {
1537 cmn_err(CE_WARN,
1538 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
1539 ap->logbufsize);
1540 return XFS_ERROR(EINVAL);
1541 }
1542 mp->m_logbsize = ap->logbufsize;
1543 mp->m_fsname_len = strlen(ap->fsname) + 1;
1544 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
1545 strcpy(mp->m_fsname, ap->fsname);
1546 if (ap->rtname[0]) {
1547 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
1548 strcpy(mp->m_rtname, ap->rtname);
1549 }
1550 if (ap->logname[0]) {
1551 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
1552 strcpy(mp->m_logname, ap->logname);
1553 }
1554
1555 if (ap->flags & XFSMNT_WSYNC)
1556 mp->m_flags |= XFS_MOUNT_WSYNC;
1557#if XFS_BIG_INUMS
1558 if (ap->flags & XFSMNT_INO64) {
1559 mp->m_flags |= XFS_MOUNT_INO64;
1560 mp->m_inoadd = XFS_INO64_OFFSET;
1561 }
1562#endif
1563 if (ap->flags & XFSMNT_RETERR)
1564 mp->m_flags |= XFS_MOUNT_RETERR;
1565 if (ap->flags & XFSMNT_NOALIGN)
1566 mp->m_flags |= XFS_MOUNT_NOALIGN;
1567 if (ap->flags & XFSMNT_SWALLOC)
1568 mp->m_flags |= XFS_MOUNT_SWALLOC;
1569 if (ap->flags & XFSMNT_OSYNCISOSYNC)
1570 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
1571 if (ap->flags & XFSMNT_32BITINODES)
1572 mp->m_flags |= XFS_MOUNT_32BITINODES;
1573
1574 if (ap->flags & XFSMNT_IOSIZE) {
1575 if (ap->iosizelog > XFS_MAX_IO_LOG ||
1576 ap->iosizelog < XFS_MIN_IO_LOG) {
1577 cmn_err(CE_WARN,
1578 "XFS: invalid log iosize: %d [not %d-%d]",
1579 ap->iosizelog, XFS_MIN_IO_LOG,
1580 XFS_MAX_IO_LOG);
1581 return XFS_ERROR(EINVAL);
1582 }
1583
1584 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
1585 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
1586 }
1587
1588 if (ap->flags & XFSMNT_IKEEP)
1589 mp->m_flags |= XFS_MOUNT_IKEEP;
1590 if (ap->flags & XFSMNT_DIRSYNC)
1591 mp->m_flags |= XFS_MOUNT_DIRSYNC;
1592 if (ap->flags & XFSMNT_ATTR2)
1593 mp->m_flags |= XFS_MOUNT_ATTR2;
1594 if (ap->flags & XFSMNT_NOATTR2)
1595 mp->m_flags |= XFS_MOUNT_NOATTR2;
1596
1597 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
1598 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
1599
1600 /*
1601 * no recovery flag requires a read-only mount
1602 */
1603 if (ap->flags & XFSMNT_NORECOVERY) {
1604 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
1605 cmn_err(CE_WARN,
1606 "XFS: tried to mount a FS read-write without recovery!");
1607 return XFS_ERROR(EINVAL);
1608 }
1609 mp->m_flags |= XFS_MOUNT_NORECOVERY;
1610 }
1611
1612 if (ap->flags & XFSMNT_NOUUID)
1613 mp->m_flags |= XFS_MOUNT_NOUUID;
1614 if (ap->flags & XFSMNT_BARRIER)
1615 mp->m_flags |= XFS_MOUNT_BARRIER;
1616 else
1617 mp->m_flags &= ~XFS_MOUNT_BARRIER;
1618
1619 if (ap->flags2 & XFSMNT2_FILESTREAMS)
1620 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
1621
1622 if (ap->flags & XFSMNT_DMAPI)
1623 mp->m_flags |= XFS_MOUNT_DMAPI;
1624 return 0;
1625}
1626
1627/*
1628 * This function fills in xfs_mount_t fields based on mount args.
1629 * Note: the superblock _has_ now been read in.
1630 */
1631STATIC int
1632xfs_finish_flags(
1633 struct xfs_mount_args *ap,
1634 struct xfs_mount *mp)
1635{
1636 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
1637
1638 /* Fail a mount where the logbuf is smaller then the log stripe */
1639 if (xfs_sb_version_haslogv2(&mp->m_sb)) {
1640 if ((ap->logbufsize <= 0) &&
1641 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
1642 mp->m_logbsize = mp->m_sb.sb_logsunit;
1643 } else if (ap->logbufsize > 0 &&
1644 ap->logbufsize < mp->m_sb.sb_logsunit) {
1645 cmn_err(CE_WARN,
1646 "XFS: logbuf size must be greater than or equal to log stripe size");
1647 return XFS_ERROR(EINVAL);
1648 }
1649 } else {
1650 /* Fail a mount if the logbuf is larger than 32K */
1651 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
1652 cmn_err(CE_WARN,
1653 "XFS: logbuf size for version 1 logs must be 16K or 32K");
1654 return XFS_ERROR(EINVAL);
1655 }
1656 }
1657
1658 /*
1659 * mkfs'ed attr2 will turn on attr2 mount unless explicitly
1660 * told by noattr2 to turn it off
1661 */
1662 if (xfs_sb_version_hasattr2(&mp->m_sb) &&
1663 !(ap->flags & XFSMNT_NOATTR2))
1664 mp->m_flags |= XFS_MOUNT_ATTR2;
1665
1666 /*
1667 * prohibit r/w mounts of read-only filesystems
1668 */
1669 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
1670 cmn_err(CE_WARN,
1671 "XFS: cannot mount a read-only filesystem as read-write");
1672 return XFS_ERROR(EROFS);
1673 }
1674
1675 /*
1676 * check for shared mount.
1677 */
1678 if (ap->flags & XFSMNT_SHARED) {
1679 if (!xfs_sb_version_hasshared(&mp->m_sb))
1680 return XFS_ERROR(EINVAL);
1681
1682 /*
1683 * For IRIX 6.5, shared mounts must have the shared
1684 * version bit set, have the persistent readonly
1685 * field set, must be version 0 and can only be mounted
1686 * read-only.
1687 */
1688 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
1689 (mp->m_sb.sb_shared_vn != 0))
1690 return XFS_ERROR(EINVAL);
1691
1692 mp->m_flags |= XFS_MOUNT_SHARED;
1693
1694 /*
1695 * Shared XFS V0 can't deal with DMI. Return EINVAL.
1696 */
1697 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
1698 return XFS_ERROR(EINVAL);
1699 }
1700
1701 if (ap->flags & XFSMNT_UQUOTA) {
1702 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
1703 if (ap->flags & XFSMNT_UQUOTAENF)
1704 mp->m_qflags |= XFS_UQUOTA_ENFD;
1705 }
1706
1707 if (ap->flags & XFSMNT_GQUOTA) {
1708 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
1709 if (ap->flags & XFSMNT_GQUOTAENF)
1710 mp->m_qflags |= XFS_OQUOTA_ENFD;
1711 } else if (ap->flags & XFSMNT_PQUOTA) {
1712 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
1713 if (ap->flags & XFSMNT_PQUOTAENF)
1714 mp->m_qflags |= XFS_OQUOTA_ENFD;
1715 }
1716
1717 return 0;
1718}
1719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001721xfs_fs_fill_super(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 struct super_block *sb,
1723 void *data,
1724 int silent)
1725{
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001726 struct inode *root;
Christoph Hellwig745f6912007-08-30 17:20:39 +10001727 struct xfs_mount *mp = NULL;
Nathan Scott764d1f82006-03-31 13:04:17 +10001728 struct xfs_mount_args *args = xfs_args_allocate(sb, silent);
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001729 int flags = 0, error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Christoph Hellwig745f6912007-08-30 17:20:39 +10001731 mp = xfs_mount_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
Christoph Hellwig74394492007-08-30 17:21:22 +10001733 INIT_LIST_HEAD(&mp->m_sync_list);
1734 spin_lock_init(&mp->m_sync_lock);
1735 init_waitqueue_head(&mp->m_wait_single_sync_task);
1736
Christoph Hellwigb267ce92007-08-30 17:21:30 +10001737 mp->m_super = sb;
1738 sb->s_fs_info = mp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001740 if (sb->s_flags & MS_RDONLY)
1741 mp->m_flags |= XFS_MOUNT_RDONLY;
1742
Christoph Hellwig745f6912007-08-30 17:20:39 +10001743 error = xfs_parseargs(mp, (char *)data, args, 0);
1744 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 goto fail_vfsop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746
1747 sb_min_blocksize(sb, BBSIZE);
Nathan Scotta50cd262006-03-14 14:06:18 +11001748 sb->s_export_op = &xfs_export_operations;
Nathan Scotta50cd262006-03-14 14:06:18 +11001749 sb->s_qcop = &xfs_quotactl_operations;
1750 sb->s_op = &xfs_super_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001752 error = xfs_dmops_get(mp, args);
Christoph Hellwig745f6912007-08-30 17:20:39 +10001753 if (error)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 goto fail_vfsop;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001755 error = xfs_qmops_get(mp, args);
1756 if (error)
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001757 goto out_put_dmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001758
1759 if (args->flags & XFSMNT_QUIET)
1760 flags |= XFS_MFSI_QUIET;
1761
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001762 error = xfs_open_devices(mp, args);
1763 if (error)
1764 goto out_put_qmops;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001765
1766 /*
1767 * Setup flags based on mount(2) options and then the superblock
1768 */
1769 error = xfs_start_flags(args, mp);
1770 if (error)
1771 goto error1;
1772 error = xfs_readsb(mp, flags);
1773 if (error)
1774 goto error1;
1775 error = xfs_finish_flags(args, mp);
1776 if (error)
1777 goto error2;
1778
Christoph Hellwige34b5622008-05-20 15:10:36 +10001779 error = xfs_setup_devices(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001780 if (error)
1781 goto error2;
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001782
1783 if (mp->m_flags & XFS_MOUNT_BARRIER)
1784 xfs_mountfs_check_barriers(mp);
1785
1786 error = xfs_filestream_mount(mp);
1787 if (error)
1788 goto error2;
1789
1790 error = xfs_mountfs(mp, flags);
1791 if (error)
1792 goto error2;
1793
1794 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 sb->s_dirt = 1;
Christoph Hellwig4ca488e2007-10-11 18:09:40 +10001797 sb->s_magic = XFS_SB_MAGIC;
1798 sb->s_blocksize = mp->m_sb.sb_blocksize;
1799 sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
1801 sb->s_time_gran = 1;
1802 set_posix_acl_flag(sb);
1803
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001804 root = igrab(mp->m_rootip->i_vnode);
1805 if (!root) {
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001806 error = ENOENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 goto fail_unmount;
Christoph Hellwigcbc89dc2008-02-05 12:14:01 +11001808 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001809 if (is_bad_inode(root)) {
1810 error = EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 goto fail_vnrele;
1812 }
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001813 sb->s_root = d_alloc_root(root);
1814 if (!sb->s_root) {
1815 error = ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 goto fail_vnrele;
1817 }
Christoph Hellwig74394492007-08-30 17:21:22 +10001818
1819 mp->m_sync_work.w_syncer = xfs_sync_worker;
1820 mp->m_sync_work.w_mount = mp;
1821 mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
1822 if (IS_ERR(mp->m_sync_task)) {
1823 error = -PTR_ERR(mp->m_sync_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 goto fail_vnrele;
Christoph Hellwig74394492007-08-30 17:21:22 +10001825 }
1826
Lachlan McIlroycf441ee2008-02-07 16:42:19 +11001827 xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001829 kmem_free(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 return 0;
1831
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001832 error2:
1833 if (mp->m_sb_bp)
1834 xfs_freesb(mp);
1835 error1:
1836 xfs_binval(mp->m_ddev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001837 if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001838 xfs_binval(mp->m_logdev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001839 if (mp->m_rtdev_targp)
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001840 xfs_binval(mp->m_rtdev_targp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001841 xfs_close_devices(mp);
1842 out_put_qmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001843 xfs_qmops_put(mp);
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001844 out_put_dmops:
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001845 xfs_dmops_put(mp);
1846 goto fail_vfsop;
1847
1848 fail_vnrele:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 if (sb->s_root) {
1850 dput(sb->s_root);
1851 sb->s_root = NULL;
1852 } else {
Christoph Hellwigf3dcc132008-03-27 18:00:54 +11001853 iput(root);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 }
1855
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001856 fail_unmount:
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001857 /*
1858 * Blow away any referenced inode in the filestreams cache.
1859 * This can and will cause log traffic as inodes go inactive
1860 * here.
1861 */
1862 xfs_filestream_unmount(mp);
1863
1864 XFS_bflush(mp->m_ddev_targp);
1865 error = xfs_unmount_flush(mp, 0);
1866 WARN_ON(error);
1867
1868 IRELE(mp->m_rootip);
1869
Christoph Hellwig19f354d2008-05-20 11:31:13 +10001870 xfs_unmountfs(mp);
1871 xfs_close_devices(mp);
Christoph Hellwige48ad3162008-05-20 11:30:52 +10001872 xfs_qmops_put(mp);
1873 xfs_dmops_put(mp);
1874 kmem_free(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
Christoph Hellwigf8f15e42008-05-20 11:30:59 +10001876 fail_vfsop:
Denys Vlasenkof0e2d932008-05-19 16:31:57 +10001877 kmem_free(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 return -error;
1879}
1880
David Howells454e2392006-06-23 02:02:57 -07001881STATIC int
Nathan Scotta50cd262006-03-14 14:06:18 +11001882xfs_fs_get_sb(
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 struct file_system_type *fs_type,
1884 int flags,
1885 const char *dev_name,
David Howells454e2392006-06-23 02:02:57 -07001886 void *data,
1887 struct vfsmount *mnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888{
David Howells454e2392006-06-23 02:02:57 -07001889 return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
1890 mnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891}
1892
David Chinner7989cb82007-02-10 18:34:56 +11001893static struct super_operations xfs_super_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001894 .alloc_inode = xfs_fs_alloc_inode,
1895 .destroy_inode = xfs_fs_destroy_inode,
1896 .write_inode = xfs_fs_write_inode,
1897 .clear_inode = xfs_fs_clear_inode,
1898 .put_super = xfs_fs_put_super,
1899 .write_super = xfs_fs_write_super,
1900 .sync_fs = xfs_fs_sync_super,
1901 .write_super_lockfs = xfs_fs_lockfs,
1902 .statfs = xfs_fs_statfs,
1903 .remount_fs = xfs_fs_remount,
1904 .show_options = xfs_fs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905};
1906
David Chinner7989cb82007-02-10 18:34:56 +11001907static struct quotactl_ops xfs_quotactl_operations = {
Nathan Scotta50cd262006-03-14 14:06:18 +11001908 .quota_sync = xfs_fs_quotasync,
1909 .get_xstate = xfs_fs_getxstate,
1910 .set_xstate = xfs_fs_setxstate,
1911 .get_xquota = xfs_fs_getxquota,
1912 .set_xquota = xfs_fs_setxquota,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913};
1914
Andrew Morton5085b602007-02-20 13:57:47 -08001915static struct file_system_type xfs_fs_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 .owner = THIS_MODULE,
1917 .name = "xfs",
Nathan Scotta50cd262006-03-14 14:06:18 +11001918 .get_sb = xfs_fs_get_sb,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 .kill_sb = kill_block_super,
1920 .fs_flags = FS_REQUIRES_DEV,
1921};
1922
1923
1924STATIC int __init
1925init_xfs_fs( void )
1926{
1927 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 static char message[] __initdata = KERN_INFO \
1929 XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
1930
1931 printk(message);
1932
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 ktrace_init(64);
1934
Nathan Scott87582802006-03-14 13:18:19 +11001935 error = xfs_init_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 if (error < 0)
Christoph Hellwig0829c362005-09-02 16:58:49 +10001937 goto undo_zones;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
Nathan Scottce8e9222006-01-11 15:39:08 +11001939 error = xfs_buf_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 if (error < 0)
Nathan Scottce8e9222006-01-11 15:39:08 +11001941 goto undo_buffers;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 vn_init();
1944 xfs_init();
1945 uuid_init();
1946 vfs_initquota();
1947
1948 error = register_filesystem(&xfs_fs_type);
1949 if (error)
1950 goto undo_register;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 return 0;
1952
1953undo_register:
Nathan Scottce8e9222006-01-11 15:39:08 +11001954 xfs_buf_terminate();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Nathan Scottce8e9222006-01-11 15:39:08 +11001956undo_buffers:
Nathan Scott87582802006-03-14 13:18:19 +11001957 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
Christoph Hellwig0829c362005-09-02 16:58:49 +10001959undo_zones:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 return error;
1961}
1962
1963STATIC void __exit
1964exit_xfs_fs( void )
1965{
1966 vfs_exitquota();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 unregister_filesystem(&xfs_fs_type);
1968 xfs_cleanup();
Nathan Scottce8e9222006-01-11 15:39:08 +11001969 xfs_buf_terminate();
Nathan Scott87582802006-03-14 13:18:19 +11001970 xfs_destroy_zones();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 ktrace_uninit();
1972}
1973
1974module_init(init_xfs_fs);
1975module_exit(exit_xfs_fs);
1976
1977MODULE_AUTHOR("Silicon Graphics, Inc.");
1978MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
1979MODULE_LICENSE("GPL");