Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | a805bad | 2006-06-19 08:40:27 +1000 | [diff] [blame] | 2 | * Copyright (c) 2000-2006 Silicon Graphics, Inc. |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 19 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_log.h" |
| 21 | #include "xfs_clnt.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 22 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include "xfs_trans.h" |
| 24 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 25 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include "xfs_bmap_btree.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 32 | #include "xfs_alloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "xfs_ialloc_btree.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include "xfs_dir2_sf.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 35 | #include "xfs_attr_sf.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include "xfs_dinode.h" |
| 37 | #include "xfs_inode.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 38 | #include "xfs_btree.h" |
| 39 | #include "xfs_ialloc.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include "xfs_bmap.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include "xfs_rtalloc.h" |
| 42 | #include "xfs_error.h" |
| 43 | #include "xfs_itable.h" |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 44 | #include "xfs_fsops.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include "xfs_rw.h" |
| 46 | #include "xfs_acl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include "xfs_attr.h" |
| 48 | #include "xfs_buf_item.h" |
| 49 | #include "xfs_utils.h" |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 50 | #include "xfs_vnodeops.h" |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 51 | #include "xfs_vfsops.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include "xfs_version.h" |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 53 | #include "xfs_log_priv.h" |
David Chinner | 249a8c1 | 2008-02-05 12:13:32 +1100 | [diff] [blame] | 54 | #include "xfs_trans_priv.h" |
Christoph Hellwig | 48b62a1 | 2008-05-20 11:30:39 +1000 | [diff] [blame] | 55 | #include "xfs_filestream.h" |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 56 | #include "xfs_da_btree.h" |
| 57 | #include "xfs_dir2_trace.h" |
| 58 | #include "xfs_extfree_item.h" |
| 59 | #include "xfs_mru_cache.h" |
| 60 | #include "xfs_inode_item.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | #include <linux/namei.h> |
| 63 | #include <linux/init.h> |
| 64 | #include <linux/mount.h> |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 65 | #include <linux/mempool.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #include <linux/writeback.h> |
Christoph Hellwig | 4df08c5 | 2005-09-05 08:34:18 +1000 | [diff] [blame] | 67 | #include <linux/kthread.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 68 | #include <linux/freezer.h> |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 69 | #include <linux/parser.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 71 | static struct quotactl_ops xfs_quotactl_operations; |
| 72 | static struct super_operations xfs_super_operations; |
| 73 | static kmem_zone_t *xfs_vnode_zone; |
| 74 | static kmem_zone_t *xfs_ioend_zone; |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 75 | mempool_t *xfs_ioend_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | STATIC struct xfs_mount_args * |
| 78 | xfs_args_allocate( |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 79 | struct super_block *sb, |
| 80 | int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | struct xfs_mount_args *args; |
| 83 | |
Christoph Hellwig | bdd907b | 2008-05-20 15:10:44 +1000 | [diff] [blame] | 84 | args = kzalloc(sizeof(struct xfs_mount_args), GFP_KERNEL); |
| 85 | if (!args) |
| 86 | return NULL; |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | args->logbufs = args->logbufsize = -1; |
| 89 | strncpy(args->fsname, sb->s_id, MAXNAMELEN); |
| 90 | |
| 91 | /* Copy the already-parsed mount(2) flags we're interested in */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (sb->s_flags & MS_DIRSYNC) |
| 93 | args->flags |= XFSMNT_DIRSYNC; |
| 94 | if (sb->s_flags & MS_SYNCHRONOUS) |
| 95 | args->flags |= XFSMNT_WSYNC; |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 96 | if (silent) |
| 97 | args->flags |= XFSMNT_QUIET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | args->flags |= XFSMNT_32BITINODES; |
| 99 | |
| 100 | return args; |
| 101 | } |
| 102 | |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 103 | #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */ |
| 104 | #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */ |
| 105 | #define MNTOPT_LOGDEV "logdev" /* log device */ |
| 106 | #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */ |
| 107 | #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */ |
| 108 | #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */ |
| 109 | #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */ |
| 110 | #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */ |
| 111 | #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */ |
| 112 | #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */ |
| 113 | #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */ |
| 114 | #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */ |
| 115 | #define MNTOPT_MTPT "mtpt" /* filesystem mount point */ |
| 116 | #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */ |
| 117 | #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */ |
| 118 | #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */ |
| 119 | #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */ |
| 120 | #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */ |
| 121 | #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */ |
| 122 | #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and |
| 123 | * unwritten extent conversion */ |
| 124 | #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */ |
| 125 | #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */ |
| 126 | #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */ |
| 127 | #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */ |
| 128 | #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */ |
| 129 | #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */ |
| 130 | #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes |
| 131 | * in stat(). */ |
| 132 | #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */ |
| 133 | #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */ |
| 134 | #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */ |
| 135 | #define MNTOPT_QUOTA "quota" /* disk quotas (user) */ |
| 136 | #define MNTOPT_NOQUOTA "noquota" /* no quotas */ |
| 137 | #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */ |
| 138 | #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */ |
| 139 | #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */ |
| 140 | #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */ |
| 141 | #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */ |
| 142 | #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */ |
| 143 | #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */ |
| 144 | #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */ |
| 145 | #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */ |
| 146 | #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */ |
| 147 | #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */ |
| 148 | #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */ |
| 149 | #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */ |
| 150 | |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 151 | /* |
| 152 | * Table driven mount option parser. |
| 153 | * |
| 154 | * Currently only used for remount, but it will be used for mount |
| 155 | * in the future, too. |
| 156 | */ |
| 157 | enum { |
| 158 | Opt_barrier, Opt_nobarrier, Opt_err |
| 159 | }; |
| 160 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 161 | static const match_table_t tokens = { |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 162 | {Opt_barrier, "barrier"}, |
| 163 | {Opt_nobarrier, "nobarrier"}, |
| 164 | {Opt_err, NULL} |
| 165 | }; |
| 166 | |
| 167 | |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 168 | STATIC unsigned long |
| 169 | suffix_strtoul(char *s, char **endp, unsigned int base) |
| 170 | { |
| 171 | int last, shift_left_factor = 0; |
| 172 | char *value = s; |
| 173 | |
| 174 | last = strlen(value) - 1; |
| 175 | if (value[last] == 'K' || value[last] == 'k') { |
| 176 | shift_left_factor = 10; |
| 177 | value[last] = '\0'; |
| 178 | } |
| 179 | if (value[last] == 'M' || value[last] == 'm') { |
| 180 | shift_left_factor = 20; |
| 181 | value[last] = '\0'; |
| 182 | } |
| 183 | if (value[last] == 'G' || value[last] == 'g') { |
| 184 | shift_left_factor = 30; |
| 185 | value[last] = '\0'; |
| 186 | } |
| 187 | |
| 188 | return simple_strtoul((const char *)s, endp, base) << shift_left_factor; |
| 189 | } |
| 190 | |
| 191 | STATIC int |
| 192 | xfs_parseargs( |
| 193 | struct xfs_mount *mp, |
| 194 | char *options, |
| 195 | struct xfs_mount_args *args, |
| 196 | int update) |
| 197 | { |
| 198 | char *this_char, *value, *eov; |
| 199 | int dsunit, dswidth, vol_dsunit, vol_dswidth; |
| 200 | int iosize; |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame] | 201 | int dmapi_implies_ikeep = 1; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 202 | |
| 203 | args->flags |= XFSMNT_BARRIER; |
| 204 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; |
| 205 | |
| 206 | if (!options) |
| 207 | goto done; |
| 208 | |
| 209 | iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0; |
| 210 | |
| 211 | while ((this_char = strsep(&options, ",")) != NULL) { |
| 212 | if (!*this_char) |
| 213 | continue; |
| 214 | if ((value = strchr(this_char, '=')) != NULL) |
| 215 | *value++ = 0; |
| 216 | |
| 217 | if (!strcmp(this_char, MNTOPT_LOGBUFS)) { |
| 218 | if (!value || !*value) { |
| 219 | cmn_err(CE_WARN, |
| 220 | "XFS: %s option requires an argument", |
| 221 | this_char); |
| 222 | return EINVAL; |
| 223 | } |
| 224 | args->logbufs = simple_strtoul(value, &eov, 10); |
| 225 | } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) { |
| 226 | if (!value || !*value) { |
| 227 | cmn_err(CE_WARN, |
| 228 | "XFS: %s option requires an argument", |
| 229 | this_char); |
| 230 | return EINVAL; |
| 231 | } |
| 232 | args->logbufsize = suffix_strtoul(value, &eov, 10); |
| 233 | } else if (!strcmp(this_char, MNTOPT_LOGDEV)) { |
| 234 | if (!value || !*value) { |
| 235 | cmn_err(CE_WARN, |
| 236 | "XFS: %s option requires an argument", |
| 237 | this_char); |
| 238 | return EINVAL; |
| 239 | } |
| 240 | strncpy(args->logname, value, MAXNAMELEN); |
| 241 | } else if (!strcmp(this_char, MNTOPT_MTPT)) { |
| 242 | if (!value || !*value) { |
| 243 | cmn_err(CE_WARN, |
| 244 | "XFS: %s option requires an argument", |
| 245 | this_char); |
| 246 | return EINVAL; |
| 247 | } |
| 248 | strncpy(args->mtpt, value, MAXNAMELEN); |
| 249 | } else if (!strcmp(this_char, MNTOPT_RTDEV)) { |
| 250 | if (!value || !*value) { |
| 251 | cmn_err(CE_WARN, |
| 252 | "XFS: %s option requires an argument", |
| 253 | this_char); |
| 254 | return EINVAL; |
| 255 | } |
| 256 | strncpy(args->rtname, value, MAXNAMELEN); |
| 257 | } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) { |
| 258 | if (!value || !*value) { |
| 259 | cmn_err(CE_WARN, |
| 260 | "XFS: %s option requires an argument", |
| 261 | this_char); |
| 262 | return EINVAL; |
| 263 | } |
| 264 | iosize = simple_strtoul(value, &eov, 10); |
| 265 | args->flags |= XFSMNT_IOSIZE; |
| 266 | args->iosizelog = (uint8_t) iosize; |
| 267 | } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) { |
| 268 | if (!value || !*value) { |
| 269 | cmn_err(CE_WARN, |
| 270 | "XFS: %s option requires an argument", |
| 271 | this_char); |
| 272 | return EINVAL; |
| 273 | } |
| 274 | iosize = suffix_strtoul(value, &eov, 10); |
| 275 | args->flags |= XFSMNT_IOSIZE; |
| 276 | args->iosizelog = ffs(iosize) - 1; |
| 277 | } else if (!strcmp(this_char, MNTOPT_GRPID) || |
| 278 | !strcmp(this_char, MNTOPT_BSDGROUPS)) { |
| 279 | mp->m_flags |= XFS_MOUNT_GRPID; |
| 280 | } else if (!strcmp(this_char, MNTOPT_NOGRPID) || |
| 281 | !strcmp(this_char, MNTOPT_SYSVGROUPS)) { |
| 282 | mp->m_flags &= ~XFS_MOUNT_GRPID; |
| 283 | } else if (!strcmp(this_char, MNTOPT_WSYNC)) { |
| 284 | args->flags |= XFSMNT_WSYNC; |
| 285 | } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) { |
| 286 | args->flags |= XFSMNT_OSYNCISOSYNC; |
| 287 | } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) { |
| 288 | args->flags |= XFSMNT_NORECOVERY; |
| 289 | } else if (!strcmp(this_char, MNTOPT_INO64)) { |
| 290 | args->flags |= XFSMNT_INO64; |
| 291 | #if !XFS_BIG_INUMS |
| 292 | cmn_err(CE_WARN, |
| 293 | "XFS: %s option not allowed on this system", |
| 294 | this_char); |
| 295 | return EINVAL; |
| 296 | #endif |
| 297 | } else if (!strcmp(this_char, MNTOPT_NOALIGN)) { |
| 298 | args->flags |= XFSMNT_NOALIGN; |
| 299 | } else if (!strcmp(this_char, MNTOPT_SWALLOC)) { |
| 300 | args->flags |= XFSMNT_SWALLOC; |
| 301 | } else if (!strcmp(this_char, MNTOPT_SUNIT)) { |
| 302 | if (!value || !*value) { |
| 303 | cmn_err(CE_WARN, |
| 304 | "XFS: %s option requires an argument", |
| 305 | this_char); |
| 306 | return EINVAL; |
| 307 | } |
| 308 | dsunit = simple_strtoul(value, &eov, 10); |
| 309 | } else if (!strcmp(this_char, MNTOPT_SWIDTH)) { |
| 310 | if (!value || !*value) { |
| 311 | cmn_err(CE_WARN, |
| 312 | "XFS: %s option requires an argument", |
| 313 | this_char); |
| 314 | return EINVAL; |
| 315 | } |
| 316 | dswidth = simple_strtoul(value, &eov, 10); |
| 317 | } else if (!strcmp(this_char, MNTOPT_64BITINODE)) { |
| 318 | args->flags &= ~XFSMNT_32BITINODES; |
| 319 | #if !XFS_BIG_INUMS |
| 320 | cmn_err(CE_WARN, |
| 321 | "XFS: %s option not allowed on this system", |
| 322 | this_char); |
| 323 | return EINVAL; |
| 324 | #endif |
| 325 | } else if (!strcmp(this_char, MNTOPT_NOUUID)) { |
| 326 | args->flags |= XFSMNT_NOUUID; |
| 327 | } else if (!strcmp(this_char, MNTOPT_BARRIER)) { |
| 328 | args->flags |= XFSMNT_BARRIER; |
| 329 | } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) { |
| 330 | args->flags &= ~XFSMNT_BARRIER; |
| 331 | } else if (!strcmp(this_char, MNTOPT_IKEEP)) { |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame] | 332 | args->flags |= XFSMNT_IKEEP; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 333 | } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) { |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame] | 334 | dmapi_implies_ikeep = 0; |
| 335 | args->flags &= ~XFSMNT_IKEEP; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 336 | } else if (!strcmp(this_char, MNTOPT_LARGEIO)) { |
| 337 | args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE; |
| 338 | } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) { |
| 339 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; |
| 340 | } else if (!strcmp(this_char, MNTOPT_ATTR2)) { |
| 341 | args->flags |= XFSMNT_ATTR2; |
| 342 | } else if (!strcmp(this_char, MNTOPT_NOATTR2)) { |
| 343 | args->flags &= ~XFSMNT_ATTR2; |
Tim Shimmin | 7c12f29 | 2008-04-30 18:15:28 +1000 | [diff] [blame] | 344 | args->flags |= XFSMNT_NOATTR2; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 345 | } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) { |
| 346 | args->flags2 |= XFSMNT2_FILESTREAMS; |
| 347 | } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) { |
| 348 | args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA); |
| 349 | args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA); |
| 350 | } else if (!strcmp(this_char, MNTOPT_QUOTA) || |
| 351 | !strcmp(this_char, MNTOPT_UQUOTA) || |
| 352 | !strcmp(this_char, MNTOPT_USRQUOTA)) { |
| 353 | args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF; |
| 354 | } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) || |
| 355 | !strcmp(this_char, MNTOPT_UQUOTANOENF)) { |
| 356 | args->flags |= XFSMNT_UQUOTA; |
| 357 | args->flags &= ~XFSMNT_UQUOTAENF; |
| 358 | } else if (!strcmp(this_char, MNTOPT_PQUOTA) || |
| 359 | !strcmp(this_char, MNTOPT_PRJQUOTA)) { |
| 360 | args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF; |
| 361 | } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) { |
| 362 | args->flags |= XFSMNT_PQUOTA; |
| 363 | args->flags &= ~XFSMNT_PQUOTAENF; |
| 364 | } else if (!strcmp(this_char, MNTOPT_GQUOTA) || |
| 365 | !strcmp(this_char, MNTOPT_GRPQUOTA)) { |
| 366 | args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF; |
| 367 | } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) { |
| 368 | args->flags |= XFSMNT_GQUOTA; |
| 369 | args->flags &= ~XFSMNT_GQUOTAENF; |
| 370 | } else if (!strcmp(this_char, MNTOPT_DMAPI)) { |
| 371 | args->flags |= XFSMNT_DMAPI; |
| 372 | } else if (!strcmp(this_char, MNTOPT_XDSM)) { |
| 373 | args->flags |= XFSMNT_DMAPI; |
| 374 | } else if (!strcmp(this_char, MNTOPT_DMI)) { |
| 375 | args->flags |= XFSMNT_DMAPI; |
| 376 | } else if (!strcmp(this_char, "ihashsize")) { |
| 377 | cmn_err(CE_WARN, |
| 378 | "XFS: ihashsize no longer used, option is deprecated."); |
| 379 | } else if (!strcmp(this_char, "osyncisdsync")) { |
| 380 | /* no-op, this is now the default */ |
| 381 | cmn_err(CE_WARN, |
| 382 | "XFS: osyncisdsync is now the default, option is deprecated."); |
| 383 | } else if (!strcmp(this_char, "irixsgid")) { |
| 384 | cmn_err(CE_WARN, |
| 385 | "XFS: irixsgid is now a sysctl(2) variable, option is deprecated."); |
| 386 | } else { |
| 387 | cmn_err(CE_WARN, |
| 388 | "XFS: unknown mount option [%s].", this_char); |
| 389 | return EINVAL; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | if (args->flags & XFSMNT_NORECOVERY) { |
| 394 | if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) { |
| 395 | cmn_err(CE_WARN, |
| 396 | "XFS: no-recovery mounts must be read-only."); |
| 397 | return EINVAL; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) { |
| 402 | cmn_err(CE_WARN, |
| 403 | "XFS: sunit and swidth options incompatible with the noalign option"); |
| 404 | return EINVAL; |
| 405 | } |
| 406 | |
| 407 | if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) { |
| 408 | cmn_err(CE_WARN, |
| 409 | "XFS: cannot mount with both project and group quota"); |
| 410 | return EINVAL; |
| 411 | } |
| 412 | |
| 413 | if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') { |
| 414 | printk("XFS: %s option needs the mount point option as well\n", |
| 415 | MNTOPT_DMAPI); |
| 416 | return EINVAL; |
| 417 | } |
| 418 | |
| 419 | if ((dsunit && !dswidth) || (!dsunit && dswidth)) { |
| 420 | cmn_err(CE_WARN, |
| 421 | "XFS: sunit and swidth must be specified together"); |
| 422 | return EINVAL; |
| 423 | } |
| 424 | |
| 425 | if (dsunit && (dswidth % dsunit != 0)) { |
| 426 | cmn_err(CE_WARN, |
| 427 | "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)", |
| 428 | dswidth, dsunit); |
| 429 | return EINVAL; |
| 430 | } |
| 431 | |
| 432 | /* |
| 433 | * Applications using DMI filesystems often expect the |
| 434 | * inode generation number to be monotonically increasing. |
| 435 | * If we delete inode chunks we break this assumption, so |
| 436 | * keep unused inode chunks on disk for DMI filesystems |
| 437 | * until we come up with a better solution. |
| 438 | * Note that if "ikeep" or "noikeep" mount options are |
| 439 | * supplied, then they are honored. |
| 440 | */ |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame] | 441 | if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep) |
| 442 | args->flags |= XFSMNT_IKEEP; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 443 | |
| 444 | if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { |
| 445 | if (dsunit) { |
| 446 | args->sunit = dsunit; |
| 447 | args->flags |= XFSMNT_RETERR; |
| 448 | } else { |
| 449 | args->sunit = vol_dsunit; |
| 450 | } |
| 451 | dswidth ? (args->swidth = dswidth) : |
| 452 | (args->swidth = vol_dswidth); |
| 453 | } else { |
| 454 | args->sunit = args->swidth = 0; |
| 455 | } |
| 456 | |
| 457 | done: |
| 458 | if (args->flags & XFSMNT_32BITINODES) |
| 459 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
| 460 | if (args->flags2) |
| 461 | args->flags |= XFSMNT_FLAGS2; |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | struct proc_xfs_info { |
| 466 | int flag; |
| 467 | char *str; |
| 468 | }; |
| 469 | |
| 470 | STATIC int |
| 471 | xfs_showargs( |
| 472 | struct xfs_mount *mp, |
| 473 | struct seq_file *m) |
| 474 | { |
| 475 | static struct proc_xfs_info xfs_info_set[] = { |
| 476 | /* the few simple ones we can get from the mount struct */ |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame] | 477 | { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP }, |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 478 | { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC }, |
| 479 | { XFS_MOUNT_INO64, "," MNTOPT_INO64 }, |
| 480 | { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN }, |
| 481 | { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC }, |
| 482 | { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID }, |
| 483 | { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY }, |
| 484 | { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC }, |
| 485 | { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 }, |
| 486 | { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM }, |
| 487 | { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI }, |
| 488 | { XFS_MOUNT_GRPID, "," MNTOPT_GRPID }, |
| 489 | { 0, NULL } |
| 490 | }; |
| 491 | static struct proc_xfs_info xfs_info_unset[] = { |
| 492 | /* the few simple ones we can get from the mount struct */ |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 493 | { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO }, |
| 494 | { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER }, |
| 495 | { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE }, |
| 496 | { 0, NULL } |
| 497 | }; |
| 498 | struct proc_xfs_info *xfs_infop; |
| 499 | |
| 500 | for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) { |
| 501 | if (mp->m_flags & xfs_infop->flag) |
| 502 | seq_puts(m, xfs_infop->str); |
| 503 | } |
| 504 | for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) { |
| 505 | if (!(mp->m_flags & xfs_infop->flag)) |
| 506 | seq_puts(m, xfs_infop->str); |
| 507 | } |
| 508 | |
| 509 | if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) |
| 510 | seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk", |
| 511 | (int)(1 << mp->m_writeio_log) >> 10); |
| 512 | |
| 513 | if (mp->m_logbufs > 0) |
| 514 | seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs); |
| 515 | if (mp->m_logbsize > 0) |
| 516 | seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10); |
| 517 | |
| 518 | if (mp->m_logname) |
| 519 | seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname); |
| 520 | if (mp->m_rtname) |
| 521 | seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname); |
| 522 | |
| 523 | if (mp->m_dalign > 0) |
| 524 | seq_printf(m, "," MNTOPT_SUNIT "=%d", |
| 525 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); |
| 526 | if (mp->m_swidth > 0) |
| 527 | seq_printf(m, "," MNTOPT_SWIDTH "=%d", |
| 528 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); |
| 529 | |
| 530 | if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD)) |
| 531 | seq_puts(m, "," MNTOPT_USRQUOTA); |
| 532 | else if (mp->m_qflags & XFS_UQUOTA_ACCT) |
| 533 | seq_puts(m, "," MNTOPT_UQUOTANOENF); |
| 534 | |
| 535 | if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD)) |
| 536 | seq_puts(m, "," MNTOPT_PRJQUOTA); |
| 537 | else if (mp->m_qflags & XFS_PQUOTA_ACCT) |
| 538 | seq_puts(m, "," MNTOPT_PQUOTANOENF); |
| 539 | |
| 540 | if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD)) |
| 541 | seq_puts(m, "," MNTOPT_GRPQUOTA); |
| 542 | else if (mp->m_qflags & XFS_GQUOTA_ACCT) |
| 543 | seq_puts(m, "," MNTOPT_GQUOTANOENF); |
| 544 | |
| 545 | if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT)) |
| 546 | seq_puts(m, "," MNTOPT_NOQUOTA); |
| 547 | |
| 548 | return 0; |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | __uint64_t |
| 551 | xfs_max_file_offset( |
| 552 | unsigned int blockshift) |
| 553 | { |
| 554 | unsigned int pagefactor = 1; |
| 555 | unsigned int bitshift = BITS_PER_LONG - 1; |
| 556 | |
| 557 | /* Figure out maximum filesize, on Linux this can depend on |
| 558 | * the filesystem blocksize (on 32 bit platforms). |
| 559 | * __block_prepare_write does this in an [unsigned] long... |
| 560 | * page->index << (PAGE_CACHE_SHIFT - bbits) |
| 561 | * So, for page sized blocks (4K on 32 bit platforms), |
| 562 | * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is |
| 563 | * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) |
| 564 | * but for smaller blocksizes it is less (bbits = log2 bsize). |
| 565 | * Note1: get_block_t takes a long (implicit cast from above) |
| 566 | * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch |
| 567 | * can optionally convert the [unsigned] long from above into |
| 568 | * an [unsigned] long long. |
| 569 | */ |
| 570 | |
| 571 | #if BITS_PER_LONG == 32 |
| 572 | # if defined(CONFIG_LBD) |
| 573 | ASSERT(sizeof(sector_t) == 8); |
| 574 | pagefactor = PAGE_CACHE_SIZE; |
| 575 | bitshift = BITS_PER_LONG; |
| 576 | # else |
| 577 | pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift); |
| 578 | # endif |
| 579 | #endif |
| 580 | |
| 581 | return (((__uint64_t)pagefactor) << bitshift) - 1; |
| 582 | } |
| 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | int |
| 585 | xfs_blkdev_get( |
| 586 | xfs_mount_t *mp, |
| 587 | const char *name, |
| 588 | struct block_device **bdevp) |
| 589 | { |
| 590 | int error = 0; |
| 591 | |
Al Viro | 30c40d2 | 2008-02-22 19:50:45 -0500 | [diff] [blame] | 592 | *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | if (IS_ERR(*bdevp)) { |
| 594 | error = PTR_ERR(*bdevp); |
| 595 | printk("XFS: Invalid device [%s], error=%d\n", name, error); |
| 596 | } |
| 597 | |
| 598 | return -error; |
| 599 | } |
| 600 | |
| 601 | void |
| 602 | xfs_blkdev_put( |
| 603 | struct block_device *bdev) |
| 604 | { |
| 605 | if (bdev) |
Al Viro | 30c40d2 | 2008-02-22 19:50:45 -0500 | [diff] [blame] | 606 | close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 609 | /* |
| 610 | * Try to write out the superblock using barriers. |
| 611 | */ |
| 612 | STATIC int |
| 613 | xfs_barrier_test( |
| 614 | xfs_mount_t *mp) |
| 615 | { |
| 616 | xfs_buf_t *sbp = xfs_getsb(mp, 0); |
| 617 | int error; |
| 618 | |
| 619 | XFS_BUF_UNDONE(sbp); |
| 620 | XFS_BUF_UNREAD(sbp); |
| 621 | XFS_BUF_UNDELAYWRITE(sbp); |
| 622 | XFS_BUF_WRITE(sbp); |
| 623 | XFS_BUF_UNASYNC(sbp); |
| 624 | XFS_BUF_ORDERED(sbp); |
| 625 | |
| 626 | xfsbdstrat(mp, sbp); |
| 627 | error = xfs_iowait(sbp); |
| 628 | |
| 629 | /* |
| 630 | * Clear all the flags we set and possible error state in the |
| 631 | * buffer. We only did the write to try out whether barriers |
| 632 | * worked and shouldn't leave any traces in the superblock |
| 633 | * buffer. |
| 634 | */ |
| 635 | XFS_BUF_DONE(sbp); |
| 636 | XFS_BUF_ERROR(sbp, 0); |
| 637 | XFS_BUF_UNORDERED(sbp); |
| 638 | |
| 639 | xfs_buf_relse(sbp); |
| 640 | return error; |
| 641 | } |
| 642 | |
| 643 | void |
| 644 | xfs_mountfs_check_barriers(xfs_mount_t *mp) |
| 645 | { |
| 646 | int error; |
| 647 | |
| 648 | if (mp->m_logdev_targp != mp->m_ddev_targp) { |
| 649 | xfs_fs_cmn_err(CE_NOTE, mp, |
| 650 | "Disabling barriers, not supported with external log device"); |
| 651 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 652 | return; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 653 | } |
| 654 | |
Nathan Scott | b2ea401 | 2006-07-28 17:05:13 +1000 | [diff] [blame] | 655 | if (xfs_readonly_buftarg(mp->m_ddev_targp)) { |
| 656 | xfs_fs_cmn_err(CE_NOTE, mp, |
| 657 | "Disabling barriers, underlying device is readonly"); |
| 658 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
| 659 | return; |
| 660 | } |
| 661 | |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 662 | error = xfs_barrier_test(mp); |
| 663 | if (error) { |
| 664 | xfs_fs_cmn_err(CE_NOTE, mp, |
| 665 | "Disabling barriers, trial barrier write failed"); |
| 666 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 667 | return; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
| 671 | void |
| 672 | xfs_blkdev_issue_flush( |
| 673 | xfs_buftarg_t *buftarg) |
| 674 | { |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 675 | blkdev_issue_flush(buftarg->bt_bdev, NULL); |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 676 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 678 | STATIC void |
| 679 | xfs_close_devices( |
| 680 | struct xfs_mount *mp) |
| 681 | { |
| 682 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 683 | struct block_device *logdev = mp->m_logdev_targp->bt_bdev; |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 684 | xfs_free_buftarg(mp->m_logdev_targp); |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 685 | xfs_blkdev_put(logdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 686 | } |
| 687 | if (mp->m_rtdev_targp) { |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 688 | struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev; |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 689 | xfs_free_buftarg(mp->m_rtdev_targp); |
Lachlan McIlroy | c032bfc | 2008-07-18 17:13:12 +1000 | [diff] [blame] | 690 | xfs_blkdev_put(rtdev); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 691 | } |
| 692 | xfs_free_buftarg(mp->m_ddev_targp); |
| 693 | } |
| 694 | |
| 695 | /* |
| 696 | * The file system configurations are: |
| 697 | * (1) device (partition) with data and internal log |
| 698 | * (2) logical volume with data and log subvolumes. |
| 699 | * (3) logical volume with data, log, and realtime subvolumes. |
| 700 | * |
| 701 | * We only have to handle opening the log and realtime volumes here if |
| 702 | * they are present. The data subvolume has already been opened by |
| 703 | * get_sb_bdev() and is stored in sb->s_bdev. |
| 704 | */ |
| 705 | STATIC int |
| 706 | xfs_open_devices( |
| 707 | struct xfs_mount *mp, |
| 708 | struct xfs_mount_args *args) |
| 709 | { |
| 710 | struct block_device *ddev = mp->m_super->s_bdev; |
| 711 | struct block_device *logdev = NULL, *rtdev = NULL; |
| 712 | int error; |
| 713 | |
| 714 | /* |
| 715 | * Open real time and log devices - order is important. |
| 716 | */ |
| 717 | if (args->logname[0]) { |
| 718 | error = xfs_blkdev_get(mp, args->logname, &logdev); |
| 719 | if (error) |
| 720 | goto out; |
| 721 | } |
| 722 | |
| 723 | if (args->rtname[0]) { |
| 724 | error = xfs_blkdev_get(mp, args->rtname, &rtdev); |
| 725 | if (error) |
| 726 | goto out_close_logdev; |
| 727 | |
| 728 | if (rtdev == ddev || rtdev == logdev) { |
| 729 | cmn_err(CE_WARN, |
| 730 | "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev."); |
| 731 | error = EINVAL; |
| 732 | goto out_close_rtdev; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | /* |
| 737 | * Setup xfs_mount buffer target pointers |
| 738 | */ |
| 739 | error = ENOMEM; |
| 740 | mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0); |
| 741 | if (!mp->m_ddev_targp) |
| 742 | goto out_close_rtdev; |
| 743 | |
| 744 | if (rtdev) { |
| 745 | mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1); |
| 746 | if (!mp->m_rtdev_targp) |
| 747 | goto out_free_ddev_targ; |
| 748 | } |
| 749 | |
| 750 | if (logdev && logdev != ddev) { |
| 751 | mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1); |
| 752 | if (!mp->m_logdev_targp) |
| 753 | goto out_free_rtdev_targ; |
| 754 | } else { |
| 755 | mp->m_logdev_targp = mp->m_ddev_targp; |
| 756 | } |
| 757 | |
| 758 | return 0; |
| 759 | |
| 760 | out_free_rtdev_targ: |
| 761 | if (mp->m_rtdev_targp) |
| 762 | xfs_free_buftarg(mp->m_rtdev_targp); |
| 763 | out_free_ddev_targ: |
| 764 | xfs_free_buftarg(mp->m_ddev_targp); |
| 765 | out_close_rtdev: |
| 766 | if (rtdev) |
| 767 | xfs_blkdev_put(rtdev); |
| 768 | out_close_logdev: |
| 769 | if (logdev && logdev != ddev) |
| 770 | xfs_blkdev_put(logdev); |
| 771 | out: |
| 772 | return error; |
| 773 | } |
| 774 | |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 775 | /* |
| 776 | * Setup xfs_mount buffer target pointers based on superblock |
| 777 | */ |
| 778 | STATIC int |
| 779 | xfs_setup_devices( |
| 780 | struct xfs_mount *mp) |
| 781 | { |
| 782 | int error; |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 783 | |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 784 | error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize, |
| 785 | mp->m_sb.sb_sectsize); |
| 786 | if (error) |
| 787 | return error; |
| 788 | |
| 789 | if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) { |
| 790 | unsigned int log_sector_size = BBSIZE; |
| 791 | |
| 792 | if (xfs_sb_version_hassector(&mp->m_sb)) |
| 793 | log_sector_size = mp->m_sb.sb_logsectsize; |
| 794 | error = xfs_setsize_buftarg(mp->m_logdev_targp, |
| 795 | mp->m_sb.sb_blocksize, |
| 796 | log_sector_size); |
| 797 | if (error) |
| 798 | return error; |
| 799 | } |
| 800 | if (mp->m_rtdev_targp) { |
| 801 | error = xfs_setsize_buftarg(mp->m_rtdev_targp, |
| 802 | mp->m_sb.sb_blocksize, |
| 803 | mp->m_sb.sb_sectsize); |
| 804 | if (error) |
| 805 | return error; |
| 806 | } |
| 807 | |
| 808 | return 0; |
| 809 | } |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 810 | |
David Chinner | 249a8c1 | 2008-02-05 12:13:32 +1100 | [diff] [blame] | 811 | /* |
| 812 | * XFS AIL push thread support |
| 813 | */ |
| 814 | void |
| 815 | xfsaild_wakeup( |
| 816 | xfs_mount_t *mp, |
| 817 | xfs_lsn_t threshold_lsn) |
| 818 | { |
| 819 | mp->m_ail.xa_target = threshold_lsn; |
| 820 | wake_up_process(mp->m_ail.xa_task); |
| 821 | } |
| 822 | |
| 823 | int |
| 824 | xfsaild( |
| 825 | void *data) |
| 826 | { |
| 827 | xfs_mount_t *mp = (xfs_mount_t *)data; |
| 828 | xfs_lsn_t last_pushed_lsn = 0; |
| 829 | long tout = 0; |
| 830 | |
| 831 | while (!kthread_should_stop()) { |
| 832 | if (tout) |
| 833 | schedule_timeout_interruptible(msecs_to_jiffies(tout)); |
| 834 | tout = 1000; |
| 835 | |
| 836 | /* swsusp */ |
| 837 | try_to_freeze(); |
| 838 | |
| 839 | ASSERT(mp->m_log); |
| 840 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 841 | continue; |
| 842 | |
| 843 | tout = xfsaild_push(mp, &last_pushed_lsn); |
| 844 | } |
| 845 | |
| 846 | return 0; |
| 847 | } /* xfsaild */ |
| 848 | |
| 849 | int |
| 850 | xfsaild_start( |
| 851 | xfs_mount_t *mp) |
| 852 | { |
| 853 | mp->m_ail.xa_target = 0; |
| 854 | mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild"); |
| 855 | if (IS_ERR(mp->m_ail.xa_task)) |
| 856 | return -PTR_ERR(mp->m_ail.xa_task); |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | void |
| 861 | xfsaild_stop( |
| 862 | xfs_mount_t *mp) |
| 863 | { |
| 864 | kthread_stop(mp->m_ail.xa_task); |
| 865 | } |
| 866 | |
| 867 | |
| 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | STATIC struct inode * |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 870 | xfs_fs_alloc_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | struct super_block *sb) |
| 872 | { |
Christoph Hellwig | df80c93 | 2008-08-13 16:22:09 +1000 | [diff] [blame] | 873 | return kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 877 | xfs_fs_destroy_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | struct inode *inode) |
| 879 | { |
Christoph Hellwig | a19d033 | 2008-08-13 16:11:26 +1000 | [diff] [blame] | 880 | kmem_zone_free(xfs_vnode_zone, inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 884 | xfs_fs_inode_init_once( |
Christoph Lameter | 4ba9b9d | 2007-10-16 23:25:51 -0700 | [diff] [blame] | 885 | void *vnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | { |
Christoph Hellwig | 863890c | 2008-08-13 16:12:05 +1000 | [diff] [blame] | 887 | inode_init_once((struct inode *)vnode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame^] | 890 | |
| 891 | /* |
| 892 | * Slab object creation initialisation for the XFS inode. |
| 893 | * This covers only the idempotent fields in the XFS inode; |
| 894 | * all other fields need to be initialised on allocation |
| 895 | * from the slab. This avoids the need to repeatedly intialise |
| 896 | * fields in the xfs inode that left in the initialise state |
| 897 | * when freeing the inode. |
| 898 | */ |
| 899 | void |
| 900 | xfs_inode_init_once( |
| 901 | kmem_zone_t *zone, |
| 902 | void *inode) |
| 903 | { |
| 904 | struct xfs_inode *ip = inode; |
| 905 | |
| 906 | memset(ip, 0, sizeof(struct xfs_inode)); |
| 907 | atomic_set(&ip->i_iocount, 0); |
| 908 | atomic_set(&ip->i_pincount, 0); |
| 909 | spin_lock_init(&ip->i_flags_lock); |
| 910 | INIT_LIST_HEAD(&ip->i_reclaim); |
| 911 | init_waitqueue_head(&ip->i_ipin_wait); |
| 912 | /* |
| 913 | * Because we want to use a counting completion, complete |
| 914 | * the flush completion once to allow a single access to |
| 915 | * the flush completion without blocking. |
| 916 | */ |
| 917 | init_completion(&ip->i_flush); |
| 918 | complete(&ip->i_flush); |
| 919 | |
| 920 | mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER, |
| 921 | "xfsino", ip->i_ino); |
| 922 | mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino); |
| 923 | } |
| 924 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | /* |
| 926 | * Attempt to flush the inode, this will actually fail |
| 927 | * if the inode is pinned, but we dirty the inode again |
| 928 | * at the point when it is unpinned after a log write, |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 929 | * since this is when the inode itself becomes flushable. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | */ |
| 931 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 932 | xfs_fs_write_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | struct inode *inode, |
| 934 | int sync) |
| 935 | { |
David Chinner | a3f74ff | 2008-03-06 13:43:42 +1100 | [diff] [blame] | 936 | int error = 0; |
| 937 | int flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 939 | xfs_itrace_entry(XFS_I(inode)); |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 940 | if (sync) { |
| 941 | filemap_fdatawait(inode->i_mapping); |
| 942 | flags |= FLUSH_SYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | } |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 944 | error = xfs_inode_flush(XFS_I(inode), flags); |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 945 | /* |
| 946 | * if we failed to write out the inode then mark |
| 947 | * it dirty again so we'll try again later. |
| 948 | */ |
| 949 | if (error) |
| 950 | mark_inode_dirty_sync(inode); |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | return -error; |
| 953 | } |
| 954 | |
| 955 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 956 | xfs_fs_clear_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | struct inode *inode) |
| 958 | { |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 959 | xfs_inode_t *ip = XFS_I(inode); |
Christoph Hellwig | 56d433e | 2005-09-05 08:23:54 +1000 | [diff] [blame] | 960 | |
Christoph Hellwig | 02ba71d | 2005-09-05 08:28:02 +1000 | [diff] [blame] | 961 | /* |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 962 | * ip can be null when xfs_iget_core calls xfs_idestroy if we |
Christoph Hellwig | 02ba71d | 2005-09-05 08:28:02 +1000 | [diff] [blame] | 963 | * find an inode with di_mode == 0 but without IGET_CREATE set. |
| 964 | */ |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 965 | if (ip) { |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 966 | xfs_itrace_entry(ip); |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 967 | XFS_STATS_INC(vn_rele); |
| 968 | XFS_STATS_INC(vn_remove); |
| 969 | XFS_STATS_INC(vn_reclaim); |
| 970 | XFS_STATS_DEC(vn_active); |
Christoph Hellwig | 56d433e | 2005-09-05 08:23:54 +1000 | [diff] [blame] | 971 | |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 972 | xfs_inactive(ip); |
| 973 | xfs_iflags_clear(ip, XFS_IMODIFIED); |
| 974 | if (xfs_reclaim(ip)) |
Harvey Harrison | 34a622b | 2008-04-10 12:19:21 +1000 | [diff] [blame] | 975 | panic("%s: cannot reclaim 0x%p\n", __func__, inode); |
Christoph Hellwig | b3aea4e | 2007-08-29 11:44:37 +1000 | [diff] [blame] | 976 | } |
Christoph Hellwig | 56d433e | 2005-09-05 08:23:54 +1000 | [diff] [blame] | 977 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 978 | ASSERT(XFS_I(inode) == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | /* |
| 982 | * Enqueue a work item to be picked up by the vfs xfssyncd thread. |
| 983 | * Doing this has two advantages: |
| 984 | * - It saves on stack space, which is tight in certain situations |
| 985 | * - It can be used (with care) as a mechanism to avoid deadlocks. |
| 986 | * Flushing while allocating in a full filesystem requires both. |
| 987 | */ |
| 988 | STATIC void |
| 989 | xfs_syncd_queue_work( |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 990 | struct xfs_mount *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | void *data, |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 992 | void (*syncer)(struct xfs_mount *, void *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 994 | struct bhv_vfs_sync_work *work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 996 | work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | INIT_LIST_HEAD(&work->w_list); |
| 998 | work->w_syncer = syncer; |
| 999 | work->w_data = data; |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1000 | work->w_mount = mp; |
| 1001 | spin_lock(&mp->m_sync_lock); |
| 1002 | list_add_tail(&work->w_list, &mp->m_sync_list); |
| 1003 | spin_unlock(&mp->m_sync_lock); |
| 1004 | wake_up_process(mp->m_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | /* |
| 1008 | * Flush delayed allocate data, attempting to free up reserved space |
| 1009 | * from existing allocations. At this point a new allocation attempt |
| 1010 | * has failed with ENOSPC and we are in the process of scratching our |
| 1011 | * heads, looking about for more room... |
| 1012 | */ |
| 1013 | STATIC void |
| 1014 | xfs_flush_inode_work( |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1015 | struct xfs_mount *mp, |
| 1016 | void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1018 | struct inode *inode = arg; |
| 1019 | filemap_flush(inode->i_mapping); |
| 1020 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | void |
| 1024 | xfs_flush_inode( |
| 1025 | xfs_inode_t *ip) |
| 1026 | { |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 1027 | struct inode *inode = VFS_I(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
| 1029 | igrab(inode); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1030 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work); |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1031 | delay(msecs_to_jiffies(500)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /* |
| 1035 | * This is the "bigger hammer" version of xfs_flush_inode_work... |
| 1036 | * (IOW, "If at first you don't succeed, use a Bigger Hammer"). |
| 1037 | */ |
| 1038 | STATIC void |
| 1039 | xfs_flush_device_work( |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1040 | struct xfs_mount *mp, |
| 1041 | void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1043 | struct inode *inode = arg; |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 1044 | sync_blockdev(mp->m_super->s_bdev); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1045 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | void |
| 1049 | xfs_flush_device( |
| 1050 | xfs_inode_t *ip) |
| 1051 | { |
David Chinner | e4f7529 | 2008-08-13 16:00:45 +1000 | [diff] [blame] | 1052 | struct inode *inode = VFS_I(ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
| 1054 | igrab(inode); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1055 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work); |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1056 | delay(msecs_to_jiffies(500)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); |
| 1058 | } |
| 1059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | STATIC void |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1061 | xfs_sync_worker( |
| 1062 | struct xfs_mount *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | void *unused) |
| 1064 | { |
| 1065 | int error; |
| 1066 | |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1067 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) |
David Chinner | 7e20694 | 2008-04-17 16:49:55 +1000 | [diff] [blame] | 1068 | error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1069 | mp->m_sync_seq++; |
| 1070 | wake_up(&mp->m_wait_single_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | STATIC int |
| 1074 | xfssyncd( |
| 1075 | void *arg) |
| 1076 | { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1077 | struct xfs_mount *mp = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | long timeleft; |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1079 | bhv_vfs_sync_work_t *work, *n; |
Christoph Hellwig | 4df08c5 | 2005-09-05 08:34:18 +1000 | [diff] [blame] | 1080 | LIST_HEAD (tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 1082 | set_freezable(); |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1083 | timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | for (;;) { |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1085 | timeleft = schedule_timeout_interruptible(timeleft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | /* swsusp */ |
Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 1087 | try_to_freeze(); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1088 | if (kthread_should_stop() && list_empty(&mp->m_sync_list)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | break; |
| 1090 | |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1091 | spin_lock(&mp->m_sync_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | /* |
| 1093 | * We can get woken by laptop mode, to do a sync - |
| 1094 | * that's the (only!) case where the list would be |
| 1095 | * empty with time remaining. |
| 1096 | */ |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1097 | if (!timeleft || list_empty(&mp->m_sync_list)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | if (!timeleft) |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1099 | timeleft = xfs_syncd_centisecs * |
| 1100 | msecs_to_jiffies(10); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1101 | INIT_LIST_HEAD(&mp->m_sync_work.w_list); |
| 1102 | list_add_tail(&mp->m_sync_work.w_list, |
| 1103 | &mp->m_sync_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | } |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1105 | list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | list_move(&work->w_list, &tmp); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1107 | spin_unlock(&mp->m_sync_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | |
| 1109 | list_for_each_entry_safe(work, n, &tmp, w_list) { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1110 | (*work->w_syncer)(mp, work->w_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | list_del(&work->w_list); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1112 | if (work == &mp->m_sync_work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | continue; |
Denys Vlasenko | f0e2d93 | 2008-05-19 16:31:57 +1000 | [diff] [blame] | 1114 | kmem_free(work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | return 0; |
| 1119 | } |
| 1120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | STATIC void |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1122 | xfs_free_fsname( |
| 1123 | struct xfs_mount *mp) |
| 1124 | { |
| 1125 | kfree(mp->m_fsname); |
| 1126 | kfree(mp->m_rtname); |
| 1127 | kfree(mp->m_logname); |
| 1128 | } |
| 1129 | |
| 1130 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1131 | xfs_fs_put_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | struct super_block *sb) |
| 1133 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1134 | struct xfs_mount *mp = XFS_M(sb); |
Christoph Hellwig | e48ad31 | 2008-05-20 11:30:52 +1000 | [diff] [blame] | 1135 | struct xfs_inode *rip = mp->m_rootip; |
| 1136 | int unmount_event_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | int error; |
| 1138 | |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1139 | kthread_stop(mp->m_sync_task); |
| 1140 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1141 | xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI); |
Christoph Hellwig | e48ad31 | 2008-05-20 11:30:52 +1000 | [diff] [blame] | 1142 | |
| 1143 | #ifdef HAVE_DMAPI |
| 1144 | if (mp->m_flags & XFS_MOUNT_DMAPI) { |
| 1145 | unmount_event_flags = |
| 1146 | (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ? |
| 1147 | 0 : DM_FLAGS_UNWANTED; |
| 1148 | /* |
| 1149 | * Ignore error from dmapi here, first unmount is not allowed |
| 1150 | * to fail anyway, and second we wouldn't want to fail a |
| 1151 | * unmount because of dmapi. |
| 1152 | */ |
| 1153 | XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL, |
| 1154 | NULL, NULL, 0, 0, unmount_event_flags); |
| 1155 | } |
| 1156 | #endif |
| 1157 | |
| 1158 | /* |
| 1159 | * Blow away any referenced inode in the filestreams cache. |
| 1160 | * This can and will cause log traffic as inodes go inactive |
| 1161 | * here. |
| 1162 | */ |
| 1163 | xfs_filestream_unmount(mp); |
| 1164 | |
| 1165 | XFS_bflush(mp->m_ddev_targp); |
| 1166 | error = xfs_unmount_flush(mp, 0); |
| 1167 | WARN_ON(error); |
| 1168 | |
Christoph Hellwig | e48ad31 | 2008-05-20 11:30:52 +1000 | [diff] [blame] | 1169 | /* |
| 1170 | * If we're forcing a shutdown, typically because of a media error, |
| 1171 | * we want to make sure we invalidate dirty pages that belong to |
| 1172 | * referenced vnodes as well. |
| 1173 | */ |
| 1174 | if (XFS_FORCED_SHUTDOWN(mp)) { |
| 1175 | error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE); |
| 1176 | ASSERT(error != EFSCORRUPTED); |
| 1177 | } |
| 1178 | |
| 1179 | if (mp->m_flags & XFS_MOUNT_DMAPI) { |
| 1180 | XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0, |
| 1181 | unmount_event_flags); |
| 1182 | } |
| 1183 | |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1184 | xfs_unmountfs(mp); |
Christoph Hellwig | 6203300 | 2008-08-13 16:50:21 +1000 | [diff] [blame] | 1185 | xfs_freesb(mp); |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1186 | xfs_icsb_destroy_counters(mp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1187 | xfs_close_devices(mp); |
Christoph Hellwig | e48ad31 | 2008-05-20 11:30:52 +1000 | [diff] [blame] | 1188 | xfs_qmops_put(mp); |
| 1189 | xfs_dmops_put(mp); |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1190 | xfs_free_fsname(mp); |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1191 | kfree(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1195 | xfs_fs_write_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | struct super_block *sb) |
| 1197 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1198 | if (!(sb->s_flags & MS_RDONLY)) |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1199 | xfs_sync(XFS_M(sb), SYNC_FSDATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | sb->s_dirt = 0; |
| 1201 | } |
| 1202 | |
| 1203 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1204 | xfs_fs_sync_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | struct super_block *sb, |
| 1206 | int wait) |
| 1207 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1208 | struct xfs_mount *mp = XFS_M(sb); |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1209 | int error; |
| 1210 | int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 1212 | /* |
| 1213 | * Treat a sync operation like a freeze. This is to work |
| 1214 | * around a race in sync_inodes() which works in two phases |
| 1215 | * - an asynchronous flush, which can write out an inode |
| 1216 | * without waiting for file size updates to complete, and a |
| 1217 | * synchronous flush, which wont do anything because the |
| 1218 | * async flush removed the inode's dirty flag. Also |
| 1219 | * sync_inodes() will not see any files that just have |
| 1220 | * outstanding transactions to be flushed because we don't |
| 1221 | * dirty the Linux inode until after the transaction I/O |
| 1222 | * completes. |
| 1223 | */ |
| 1224 | if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) { |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 1225 | /* |
| 1226 | * First stage of freeze - no more writers will make progress |
| 1227 | * now we are here, so we flush delwri and delalloc buffers |
| 1228 | * here, then wait for all I/O to complete. Data is frozen at |
| 1229 | * that point. Metadata is not frozen, transactions can still |
| 1230 | * occur here so don't bother flushing the buftarg (i.e |
| 1231 | * SYNC_QUIESCE) because it'll just get dirty again. |
| 1232 | */ |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 1233 | flags = SYNC_DATA_QUIESCE; |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 1234 | } else |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 1235 | flags = SYNC_FSDATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1237 | error = xfs_sync(mp, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | sb->s_dirt = 0; |
| 1239 | |
| 1240 | if (unlikely(laptop_mode)) { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1241 | int prev_sync_seq = mp->m_sync_seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
| 1243 | /* |
| 1244 | * The disk must be active because we're syncing. |
| 1245 | * We schedule xfssyncd now (now that the disk is |
| 1246 | * active) instead of later (when it might not be). |
| 1247 | */ |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1248 | wake_up_process(mp->m_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | /* |
| 1250 | * We have to wait for the sync iteration to complete. |
| 1251 | * If we don't, the disk activity caused by the sync |
| 1252 | * will come after the sync is completed, and that |
| 1253 | * triggers another sync from laptop mode. |
| 1254 | */ |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1255 | wait_event(mp->m_wait_single_sync_task, |
| 1256 | mp->m_sync_seq != prev_sync_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | return -error; |
| 1260 | } |
| 1261 | |
| 1262 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1263 | xfs_fs_statfs( |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1264 | struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | struct kstatfs *statp) |
| 1266 | { |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 1267 | struct xfs_mount *mp = XFS_M(dentry->d_sb); |
| 1268 | xfs_sb_t *sbp = &mp->m_sb; |
| 1269 | __uint64_t fakeinos, id; |
| 1270 | xfs_extlen_t lsize; |
| 1271 | |
| 1272 | statp->f_type = XFS_SB_MAGIC; |
| 1273 | statp->f_namelen = MAXNAMELEN - 1; |
| 1274 | |
| 1275 | id = huge_encode_dev(mp->m_ddev_targp->bt_dev); |
| 1276 | statp->f_fsid.val[0] = (u32)id; |
| 1277 | statp->f_fsid.val[1] = (u32)(id >> 32); |
| 1278 | |
Christoph Hellwig | d4d90b5 | 2008-04-22 17:34:37 +1000 | [diff] [blame] | 1279 | xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT); |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 1280 | |
| 1281 | spin_lock(&mp->m_sb_lock); |
| 1282 | statp->f_bsize = sbp->sb_blocksize; |
| 1283 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; |
| 1284 | statp->f_blocks = sbp->sb_dblocks - lsize; |
| 1285 | statp->f_bfree = statp->f_bavail = |
| 1286 | sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); |
| 1287 | fakeinos = statp->f_bfree << sbp->sb_inopblog; |
| 1288 | #if XFS_BIG_INUMS |
| 1289 | fakeinos += mp->m_inoadd; |
| 1290 | #endif |
| 1291 | statp->f_files = |
| 1292 | MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER); |
| 1293 | if (mp->m_maxicount) |
| 1294 | #if XFS_BIG_INUMS |
| 1295 | if (!mp->m_inoadd) |
| 1296 | #endif |
| 1297 | statp->f_files = min_t(typeof(statp->f_files), |
| 1298 | statp->f_files, |
| 1299 | mp->m_maxicount); |
| 1300 | statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree); |
| 1301 | spin_unlock(&mp->m_sb_lock); |
| 1302 | |
| 1303 | XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp); |
| 1304 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1308 | xfs_fs_remount( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | struct super_block *sb, |
| 1310 | int *flags, |
| 1311 | char *options) |
| 1312 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1313 | struct xfs_mount *mp = XFS_M(sb); |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1314 | substring_t args[MAX_OPT_ARGS]; |
| 1315 | char *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1317 | while ((p = strsep(&options, ",")) != NULL) { |
| 1318 | int token; |
Christoph Hellwig | bdd907b | 2008-05-20 15:10:44 +1000 | [diff] [blame] | 1319 | |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1320 | if (!*p) |
| 1321 | continue; |
Christoph Hellwig | 48b62a1 | 2008-05-20 11:30:39 +1000 | [diff] [blame] | 1322 | |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1323 | token = match_token(p, tokens, args); |
| 1324 | switch (token) { |
| 1325 | case Opt_barrier: |
Christoph Hellwig | 48b62a1 | 2008-05-20 11:30:39 +1000 | [diff] [blame] | 1326 | mp->m_flags |= XFS_MOUNT_BARRIER; |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1327 | |
| 1328 | /* |
| 1329 | * Test if barriers are actually working if we can, |
| 1330 | * else delay this check until the filesystem is |
| 1331 | * marked writeable. |
| 1332 | */ |
| 1333 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) |
| 1334 | xfs_mountfs_check_barriers(mp); |
| 1335 | break; |
| 1336 | case Opt_nobarrier: |
Christoph Hellwig | 48b62a1 | 2008-05-20 11:30:39 +1000 | [diff] [blame] | 1337 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1338 | break; |
| 1339 | default: |
Christoph Hellwig | 6efdf28 | 2008-09-17 16:49:33 +1000 | [diff] [blame] | 1340 | /* |
| 1341 | * Logically we would return an error here to prevent |
| 1342 | * users from believing they might have changed |
| 1343 | * mount options using remount which can't be changed. |
| 1344 | * |
| 1345 | * But unfortunately mount(8) adds all options from |
| 1346 | * mtab and fstab to the mount arguments in some cases |
| 1347 | * so we can't blindly reject options, but have to |
| 1348 | * check for each specified option if it actually |
| 1349 | * differs from the currently set option and only |
| 1350 | * reject it if that's the case. |
| 1351 | * |
| 1352 | * Until that is implemented we return success for |
| 1353 | * every remount request, and silently ignore all |
| 1354 | * options that we can't actually change. |
| 1355 | */ |
| 1356 | #if 0 |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1357 | printk(KERN_INFO |
| 1358 | "XFS: mount option \"%s\" not supported for remount\n", p); |
| 1359 | return -EINVAL; |
Christoph Hellwig | 6efdf28 | 2008-09-17 16:49:33 +1000 | [diff] [blame] | 1360 | #else |
Christoph Hellwig | 6c5e51d | 2008-10-12 14:30:44 +0200 | [diff] [blame] | 1361 | break; |
Christoph Hellwig | 6efdf28 | 2008-09-17 16:49:33 +1000 | [diff] [blame] | 1362 | #endif |
Christoph Hellwig | 48b62a1 | 2008-05-20 11:30:39 +1000 | [diff] [blame] | 1363 | } |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | /* rw/ro -> rw */ |
| 1367 | if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) { |
| 1368 | mp->m_flags &= ~XFS_MOUNT_RDONLY; |
| 1369 | if (mp->m_flags & XFS_MOUNT_BARRIER) |
| 1370 | xfs_mountfs_check_barriers(mp); |
| 1371 | } |
| 1372 | |
| 1373 | /* rw -> ro */ |
| 1374 | if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) { |
Christoph Hellwig | 48b62a1 | 2008-05-20 11:30:39 +1000 | [diff] [blame] | 1375 | xfs_filestream_flush(mp); |
| 1376 | xfs_sync(mp, SYNC_DATA_QUIESCE); |
| 1377 | xfs_attr_quiesce(mp); |
| 1378 | mp->m_flags |= XFS_MOUNT_RDONLY; |
| 1379 | } |
| 1380 | |
Christoph Hellwig | 62a877e | 2008-07-18 17:12:36 +1000 | [diff] [blame] | 1381 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 1384 | /* |
| 1385 | * Second stage of a freeze. The data is already frozen so we only |
| 1386 | * need to take care of themetadata. Once that's done write a dummy |
| 1387 | * record to dirty the log in case of a crash while frozen. |
| 1388 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1390 | xfs_fs_lockfs( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | struct super_block *sb) |
| 1392 | { |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 1393 | struct xfs_mount *mp = XFS_M(sb); |
| 1394 | |
| 1395 | xfs_attr_quiesce(mp); |
| 1396 | xfs_fs_log_dummy(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1400 | xfs_fs_show_options( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | struct seq_file *m, |
| 1402 | struct vfsmount *mnt) |
| 1403 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1404 | return -xfs_showargs(XFS_M(mnt->mnt_sb), m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1408 | xfs_fs_quotasync( |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 1409 | struct super_block *sb, |
| 1410 | int type) |
| 1411 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1412 | return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL); |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1416 | xfs_fs_getxstate( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | struct super_block *sb, |
| 1418 | struct fs_quota_stat *fqs) |
| 1419 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1420 | return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1424 | xfs_fs_setxstate( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | struct super_block *sb, |
| 1426 | unsigned int flags, |
| 1427 | int op) |
| 1428 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1429 | return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1433 | xfs_fs_getxquota( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | struct super_block *sb, |
| 1435 | int type, |
| 1436 | qid_t id, |
| 1437 | struct fs_disk_quota *fdq) |
| 1438 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1439 | return -XFS_QM_QUOTACTL(XFS_M(sb), |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1440 | (type == USRQUOTA) ? Q_XGETQUOTA : |
| 1441 | ((type == GRPQUOTA) ? Q_XGETGQUOTA : |
| 1442 | Q_XGETPQUOTA), id, (caddr_t)fdq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1446 | xfs_fs_setxquota( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | struct super_block *sb, |
| 1448 | int type, |
| 1449 | qid_t id, |
| 1450 | struct fs_disk_quota *fdq) |
| 1451 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1452 | return -XFS_QM_QUOTACTL(XFS_M(sb), |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1453 | (type == USRQUOTA) ? Q_XSETQLIM : |
| 1454 | ((type == GRPQUOTA) ? Q_XSETGQLIM : |
| 1455 | Q_XSETPQLIM), id, (caddr_t)fdq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1458 | /* |
| 1459 | * This function fills in xfs_mount_t fields based on mount args. |
| 1460 | * Note: the superblock has _not_ yet been read in. |
| 1461 | */ |
| 1462 | STATIC int |
| 1463 | xfs_start_flags( |
| 1464 | struct xfs_mount_args *ap, |
| 1465 | struct xfs_mount *mp) |
| 1466 | { |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1467 | int error; |
| 1468 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1469 | /* Values are in BBs */ |
| 1470 | if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { |
| 1471 | /* |
| 1472 | * At this point the superblock has not been read |
| 1473 | * in, therefore we do not know the block size. |
| 1474 | * Before the mount call ends we will convert |
| 1475 | * these to FSBs. |
| 1476 | */ |
| 1477 | mp->m_dalign = ap->sunit; |
| 1478 | mp->m_swidth = ap->swidth; |
| 1479 | } |
| 1480 | |
| 1481 | if (ap->logbufs != -1 && |
| 1482 | ap->logbufs != 0 && |
| 1483 | (ap->logbufs < XLOG_MIN_ICLOGS || |
| 1484 | ap->logbufs > XLOG_MAX_ICLOGS)) { |
| 1485 | cmn_err(CE_WARN, |
| 1486 | "XFS: invalid logbufs value: %d [not %d-%d]", |
| 1487 | ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS); |
| 1488 | return XFS_ERROR(EINVAL); |
| 1489 | } |
| 1490 | mp->m_logbufs = ap->logbufs; |
| 1491 | if (ap->logbufsize != -1 && |
| 1492 | ap->logbufsize != 0 && |
| 1493 | (ap->logbufsize < XLOG_MIN_RECORD_BSIZE || |
| 1494 | ap->logbufsize > XLOG_MAX_RECORD_BSIZE || |
| 1495 | !is_power_of_2(ap->logbufsize))) { |
| 1496 | cmn_err(CE_WARN, |
| 1497 | "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]", |
| 1498 | ap->logbufsize); |
| 1499 | return XFS_ERROR(EINVAL); |
| 1500 | } |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1501 | |
| 1502 | error = ENOMEM; |
| 1503 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1504 | mp->m_logbsize = ap->logbufsize; |
| 1505 | mp->m_fsname_len = strlen(ap->fsname) + 1; |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1506 | |
| 1507 | mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL); |
| 1508 | if (!mp->m_fsname) |
| 1509 | goto out; |
| 1510 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1511 | if (ap->rtname[0]) { |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1512 | mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL); |
| 1513 | if (!mp->m_rtname) |
| 1514 | goto out_free_fsname; |
| 1515 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1516 | } |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1517 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1518 | if (ap->logname[0]) { |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1519 | mp->m_logname = kstrdup(ap->logname, GFP_KERNEL); |
| 1520 | if (!mp->m_logname) |
| 1521 | goto out_free_rtname; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | if (ap->flags & XFSMNT_WSYNC) |
| 1525 | mp->m_flags |= XFS_MOUNT_WSYNC; |
| 1526 | #if XFS_BIG_INUMS |
| 1527 | if (ap->flags & XFSMNT_INO64) { |
| 1528 | mp->m_flags |= XFS_MOUNT_INO64; |
| 1529 | mp->m_inoadd = XFS_INO64_OFFSET; |
| 1530 | } |
| 1531 | #endif |
| 1532 | if (ap->flags & XFSMNT_RETERR) |
| 1533 | mp->m_flags |= XFS_MOUNT_RETERR; |
| 1534 | if (ap->flags & XFSMNT_NOALIGN) |
| 1535 | mp->m_flags |= XFS_MOUNT_NOALIGN; |
| 1536 | if (ap->flags & XFSMNT_SWALLOC) |
| 1537 | mp->m_flags |= XFS_MOUNT_SWALLOC; |
| 1538 | if (ap->flags & XFSMNT_OSYNCISOSYNC) |
| 1539 | mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC; |
| 1540 | if (ap->flags & XFSMNT_32BITINODES) |
| 1541 | mp->m_flags |= XFS_MOUNT_32BITINODES; |
| 1542 | |
| 1543 | if (ap->flags & XFSMNT_IOSIZE) { |
| 1544 | if (ap->iosizelog > XFS_MAX_IO_LOG || |
| 1545 | ap->iosizelog < XFS_MIN_IO_LOG) { |
| 1546 | cmn_err(CE_WARN, |
| 1547 | "XFS: invalid log iosize: %d [not %d-%d]", |
| 1548 | ap->iosizelog, XFS_MIN_IO_LOG, |
| 1549 | XFS_MAX_IO_LOG); |
| 1550 | return XFS_ERROR(EINVAL); |
| 1551 | } |
| 1552 | |
| 1553 | mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE; |
| 1554 | mp->m_readio_log = mp->m_writeio_log = ap->iosizelog; |
| 1555 | } |
| 1556 | |
| 1557 | if (ap->flags & XFSMNT_IKEEP) |
| 1558 | mp->m_flags |= XFS_MOUNT_IKEEP; |
| 1559 | if (ap->flags & XFSMNT_DIRSYNC) |
| 1560 | mp->m_flags |= XFS_MOUNT_DIRSYNC; |
| 1561 | if (ap->flags & XFSMNT_ATTR2) |
| 1562 | mp->m_flags |= XFS_MOUNT_ATTR2; |
| 1563 | if (ap->flags & XFSMNT_NOATTR2) |
| 1564 | mp->m_flags |= XFS_MOUNT_NOATTR2; |
| 1565 | |
| 1566 | if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE) |
| 1567 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; |
| 1568 | |
| 1569 | /* |
| 1570 | * no recovery flag requires a read-only mount |
| 1571 | */ |
| 1572 | if (ap->flags & XFSMNT_NORECOVERY) { |
| 1573 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { |
| 1574 | cmn_err(CE_WARN, |
| 1575 | "XFS: tried to mount a FS read-write without recovery!"); |
| 1576 | return XFS_ERROR(EINVAL); |
| 1577 | } |
| 1578 | mp->m_flags |= XFS_MOUNT_NORECOVERY; |
| 1579 | } |
| 1580 | |
| 1581 | if (ap->flags & XFSMNT_NOUUID) |
| 1582 | mp->m_flags |= XFS_MOUNT_NOUUID; |
| 1583 | if (ap->flags & XFSMNT_BARRIER) |
| 1584 | mp->m_flags |= XFS_MOUNT_BARRIER; |
| 1585 | else |
| 1586 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
| 1587 | |
| 1588 | if (ap->flags2 & XFSMNT2_FILESTREAMS) |
| 1589 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; |
| 1590 | |
| 1591 | if (ap->flags & XFSMNT_DMAPI) |
| 1592 | mp->m_flags |= XFS_MOUNT_DMAPI; |
| 1593 | return 0; |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1594 | |
| 1595 | |
| 1596 | out_free_rtname: |
| 1597 | kfree(mp->m_rtname); |
| 1598 | out_free_fsname: |
| 1599 | kfree(mp->m_fsname); |
| 1600 | out: |
| 1601 | return error; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1602 | } |
| 1603 | |
| 1604 | /* |
| 1605 | * This function fills in xfs_mount_t fields based on mount args. |
| 1606 | * Note: the superblock _has_ now been read in. |
| 1607 | */ |
| 1608 | STATIC int |
| 1609 | xfs_finish_flags( |
| 1610 | struct xfs_mount_args *ap, |
| 1611 | struct xfs_mount *mp) |
| 1612 | { |
| 1613 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); |
| 1614 | |
| 1615 | /* Fail a mount where the logbuf is smaller then the log stripe */ |
| 1616 | if (xfs_sb_version_haslogv2(&mp->m_sb)) { |
| 1617 | if ((ap->logbufsize <= 0) && |
| 1618 | (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) { |
| 1619 | mp->m_logbsize = mp->m_sb.sb_logsunit; |
| 1620 | } else if (ap->logbufsize > 0 && |
| 1621 | ap->logbufsize < mp->m_sb.sb_logsunit) { |
| 1622 | cmn_err(CE_WARN, |
| 1623 | "XFS: logbuf size must be greater than or equal to log stripe size"); |
| 1624 | return XFS_ERROR(EINVAL); |
| 1625 | } |
| 1626 | } else { |
| 1627 | /* Fail a mount if the logbuf is larger than 32K */ |
| 1628 | if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) { |
| 1629 | cmn_err(CE_WARN, |
| 1630 | "XFS: logbuf size for version 1 logs must be 16K or 32K"); |
| 1631 | return XFS_ERROR(EINVAL); |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | /* |
| 1636 | * mkfs'ed attr2 will turn on attr2 mount unless explicitly |
| 1637 | * told by noattr2 to turn it off |
| 1638 | */ |
| 1639 | if (xfs_sb_version_hasattr2(&mp->m_sb) && |
| 1640 | !(ap->flags & XFSMNT_NOATTR2)) |
| 1641 | mp->m_flags |= XFS_MOUNT_ATTR2; |
| 1642 | |
| 1643 | /* |
| 1644 | * prohibit r/w mounts of read-only filesystems |
| 1645 | */ |
| 1646 | if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) { |
| 1647 | cmn_err(CE_WARN, |
| 1648 | "XFS: cannot mount a read-only filesystem as read-write"); |
| 1649 | return XFS_ERROR(EROFS); |
| 1650 | } |
| 1651 | |
| 1652 | /* |
| 1653 | * check for shared mount. |
| 1654 | */ |
| 1655 | if (ap->flags & XFSMNT_SHARED) { |
| 1656 | if (!xfs_sb_version_hasshared(&mp->m_sb)) |
| 1657 | return XFS_ERROR(EINVAL); |
| 1658 | |
| 1659 | /* |
| 1660 | * For IRIX 6.5, shared mounts must have the shared |
| 1661 | * version bit set, have the persistent readonly |
| 1662 | * field set, must be version 0 and can only be mounted |
| 1663 | * read-only. |
| 1664 | */ |
| 1665 | if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) || |
| 1666 | (mp->m_sb.sb_shared_vn != 0)) |
| 1667 | return XFS_ERROR(EINVAL); |
| 1668 | |
| 1669 | mp->m_flags |= XFS_MOUNT_SHARED; |
| 1670 | |
| 1671 | /* |
| 1672 | * Shared XFS V0 can't deal with DMI. Return EINVAL. |
| 1673 | */ |
| 1674 | if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI)) |
| 1675 | return XFS_ERROR(EINVAL); |
| 1676 | } |
| 1677 | |
| 1678 | if (ap->flags & XFSMNT_UQUOTA) { |
| 1679 | mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE); |
| 1680 | if (ap->flags & XFSMNT_UQUOTAENF) |
| 1681 | mp->m_qflags |= XFS_UQUOTA_ENFD; |
| 1682 | } |
| 1683 | |
| 1684 | if (ap->flags & XFSMNT_GQUOTA) { |
| 1685 | mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE); |
| 1686 | if (ap->flags & XFSMNT_GQUOTAENF) |
| 1687 | mp->m_qflags |= XFS_OQUOTA_ENFD; |
| 1688 | } else if (ap->flags & XFSMNT_PQUOTA) { |
| 1689 | mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE); |
| 1690 | if (ap->flags & XFSMNT_PQUOTAENF) |
| 1691 | mp->m_qflags |= XFS_OQUOTA_ENFD; |
| 1692 | } |
| 1693 | |
| 1694 | return 0; |
| 1695 | } |
| 1696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1698 | xfs_fs_fill_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | struct super_block *sb, |
| 1700 | void *data, |
| 1701 | int silent) |
| 1702 | { |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1703 | struct inode *root; |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1704 | struct xfs_mount *mp = NULL; |
Christoph Hellwig | bdd907b | 2008-05-20 15:10:44 +1000 | [diff] [blame] | 1705 | struct xfs_mount_args *args; |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1706 | int flags = 0, error = ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | |
Christoph Hellwig | bdd907b | 2008-05-20 15:10:44 +1000 | [diff] [blame] | 1708 | args = xfs_args_allocate(sb, silent); |
| 1709 | if (!args) |
| 1710 | return -ENOMEM; |
| 1711 | |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1712 | mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL); |
| 1713 | if (!mp) |
| 1714 | goto out_free_args; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1716 | spin_lock_init(&mp->m_sb_lock); |
| 1717 | mutex_init(&mp->m_ilock); |
| 1718 | mutex_init(&mp->m_growlock); |
| 1719 | atomic_set(&mp->m_active_trans, 0); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1720 | INIT_LIST_HEAD(&mp->m_sync_list); |
| 1721 | spin_lock_init(&mp->m_sync_lock); |
| 1722 | init_waitqueue_head(&mp->m_wait_single_sync_task); |
| 1723 | |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 1724 | mp->m_super = sb; |
| 1725 | sb->s_fs_info = mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 1727 | if (sb->s_flags & MS_RDONLY) |
| 1728 | mp->m_flags |= XFS_MOUNT_RDONLY; |
| 1729 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1730 | error = xfs_parseargs(mp, (char *)data, args, 0); |
| 1731 | if (error) |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1732 | goto out_free_mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | |
| 1734 | sb_min_blocksize(sb, BBSIZE); |
Lachlan McIlroy | 0ec5851 | 2008-06-23 13:23:01 +1000 | [diff] [blame] | 1735 | sb->s_xattr = xfs_xattr_handlers; |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1736 | sb->s_export_op = &xfs_export_operations; |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1737 | sb->s_qcop = &xfs_quotactl_operations; |
| 1738 | sb->s_op = &xfs_super_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1740 | error = xfs_dmops_get(mp, args); |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1741 | if (error) |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1742 | goto out_free_mp; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1743 | error = xfs_qmops_get(mp, args); |
| 1744 | if (error) |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1745 | goto out_put_dmops; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1746 | |
| 1747 | if (args->flags & XFSMNT_QUIET) |
| 1748 | flags |= XFS_MFSI_QUIET; |
| 1749 | |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1750 | error = xfs_open_devices(mp, args); |
| 1751 | if (error) |
| 1752 | goto out_put_qmops; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1753 | |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1754 | if (xfs_icsb_init_counters(mp)) |
| 1755 | mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB; |
| 1756 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1757 | /* |
| 1758 | * Setup flags based on mount(2) options and then the superblock |
| 1759 | */ |
| 1760 | error = xfs_start_flags(args, mp); |
| 1761 | if (error) |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1762 | goto out_free_fsname; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1763 | error = xfs_readsb(mp, flags); |
| 1764 | if (error) |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1765 | goto out_free_fsname; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1766 | error = xfs_finish_flags(args, mp); |
| 1767 | if (error) |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1768 | goto out_free_sb; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1769 | |
Christoph Hellwig | e34b562 | 2008-05-20 15:10:36 +1000 | [diff] [blame] | 1770 | error = xfs_setup_devices(mp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1771 | if (error) |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1772 | goto out_free_sb; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1773 | |
| 1774 | if (mp->m_flags & XFS_MOUNT_BARRIER) |
| 1775 | xfs_mountfs_check_barriers(mp); |
| 1776 | |
| 1777 | error = xfs_filestream_mount(mp); |
| 1778 | if (error) |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1779 | goto out_free_sb; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1780 | |
Christoph Hellwig | 4249023 | 2008-08-13 16:49:32 +1000 | [diff] [blame] | 1781 | error = xfs_mountfs(mp); |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1782 | if (error) |
Christoph Hellwig | 120226c | 2008-05-20 15:11:11 +1000 | [diff] [blame] | 1783 | goto out_filestream_unmount; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1784 | |
| 1785 | XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | sb->s_dirt = 1; |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 1788 | sb->s_magic = XFS_SB_MAGIC; |
| 1789 | sb->s_blocksize = mp->m_sb.sb_blocksize; |
| 1790 | sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits); |
| 1792 | sb->s_time_gran = 1; |
| 1793 | set_posix_acl_flag(sb); |
| 1794 | |
David Chinner | 0165164 | 2008-08-13 15:45:15 +1000 | [diff] [blame] | 1795 | root = igrab(VFS_I(mp->m_rootip)); |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1796 | if (!root) { |
Christoph Hellwig | cbc89dc | 2008-02-05 12:14:01 +1100 | [diff] [blame] | 1797 | error = ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | goto fail_unmount; |
Christoph Hellwig | cbc89dc | 2008-02-05 12:14:01 +1100 | [diff] [blame] | 1799 | } |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1800 | if (is_bad_inode(root)) { |
| 1801 | error = EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | goto fail_vnrele; |
| 1803 | } |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1804 | sb->s_root = d_alloc_root(root); |
| 1805 | if (!sb->s_root) { |
| 1806 | error = ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | goto fail_vnrele; |
| 1808 | } |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1809 | |
| 1810 | mp->m_sync_work.w_syncer = xfs_sync_worker; |
| 1811 | mp->m_sync_work.w_mount = mp; |
| 1812 | mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd"); |
| 1813 | if (IS_ERR(mp->m_sync_task)) { |
| 1814 | error = -PTR_ERR(mp->m_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | goto fail_vnrele; |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1816 | } |
| 1817 | |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 1818 | xfs_itrace_exit(XFS_I(sb->s_root->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | |
Christoph Hellwig | bdd907b | 2008-05-20 15:10:44 +1000 | [diff] [blame] | 1820 | kfree(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | return 0; |
| 1822 | |
Christoph Hellwig | 120226c | 2008-05-20 15:11:11 +1000 | [diff] [blame] | 1823 | out_filestream_unmount: |
| 1824 | xfs_filestream_unmount(mp); |
Christoph Hellwig | effa2ed | 2008-05-20 15:11:05 +1000 | [diff] [blame] | 1825 | out_free_sb: |
| 1826 | xfs_freesb(mp); |
Christoph Hellwig | a738159 | 2008-08-13 16:04:05 +1000 | [diff] [blame] | 1827 | out_free_fsname: |
| 1828 | xfs_free_fsname(mp); |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1829 | xfs_icsb_destroy_counters(mp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1830 | xfs_close_devices(mp); |
| 1831 | out_put_qmops: |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1832 | xfs_qmops_put(mp); |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1833 | out_put_dmops: |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1834 | xfs_dmops_put(mp); |
Christoph Hellwig | c962fb7 | 2008-05-20 15:10:52 +1000 | [diff] [blame] | 1835 | out_free_mp: |
| 1836 | kfree(mp); |
| 1837 | out_free_args: |
| 1838 | kfree(args); |
| 1839 | return -error; |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1840 | |
| 1841 | fail_vnrele: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | if (sb->s_root) { |
| 1843 | dput(sb->s_root); |
| 1844 | sb->s_root = NULL; |
| 1845 | } else { |
Christoph Hellwig | f3dcc13 | 2008-03-27 18:00:54 +1100 | [diff] [blame] | 1846 | iput(root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
Christoph Hellwig | f8f15e4 | 2008-05-20 11:30:59 +1000 | [diff] [blame] | 1849 | fail_unmount: |
Christoph Hellwig | e48ad31 | 2008-05-20 11:30:52 +1000 | [diff] [blame] | 1850 | /* |
| 1851 | * Blow away any referenced inode in the filestreams cache. |
| 1852 | * This can and will cause log traffic as inodes go inactive |
| 1853 | * here. |
| 1854 | */ |
| 1855 | xfs_filestream_unmount(mp); |
| 1856 | |
| 1857 | XFS_bflush(mp->m_ddev_targp); |
| 1858 | error = xfs_unmount_flush(mp, 0); |
| 1859 | WARN_ON(error); |
| 1860 | |
Christoph Hellwig | 19f354d | 2008-05-20 11:31:13 +1000 | [diff] [blame] | 1861 | xfs_unmountfs(mp); |
Christoph Hellwig | 6203300 | 2008-08-13 16:50:21 +1000 | [diff] [blame] | 1862 | goto out_free_sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1865 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1866 | xfs_fs_get_sb( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | struct file_system_type *fs_type, |
| 1868 | int flags, |
| 1869 | const char *dev_name, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1870 | void *data, |
| 1871 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1873 | return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super, |
| 1874 | mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 1877 | static struct super_operations xfs_super_operations = { |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1878 | .alloc_inode = xfs_fs_alloc_inode, |
| 1879 | .destroy_inode = xfs_fs_destroy_inode, |
| 1880 | .write_inode = xfs_fs_write_inode, |
| 1881 | .clear_inode = xfs_fs_clear_inode, |
| 1882 | .put_super = xfs_fs_put_super, |
| 1883 | .write_super = xfs_fs_write_super, |
| 1884 | .sync_fs = xfs_fs_sync_super, |
| 1885 | .write_super_lockfs = xfs_fs_lockfs, |
| 1886 | .statfs = xfs_fs_statfs, |
| 1887 | .remount_fs = xfs_fs_remount, |
| 1888 | .show_options = xfs_fs_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | }; |
| 1890 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 1891 | static struct quotactl_ops xfs_quotactl_operations = { |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1892 | .quota_sync = xfs_fs_quotasync, |
| 1893 | .get_xstate = xfs_fs_getxstate, |
| 1894 | .set_xstate = xfs_fs_setxstate, |
| 1895 | .get_xquota = xfs_fs_getxquota, |
| 1896 | .set_xquota = xfs_fs_setxquota, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | }; |
| 1898 | |
Andrew Morton | 5085b60 | 2007-02-20 13:57:47 -0800 | [diff] [blame] | 1899 | static struct file_system_type xfs_fs_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | .owner = THIS_MODULE, |
| 1901 | .name = "xfs", |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1902 | .get_sb = xfs_fs_get_sb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | .kill_sb = kill_block_super, |
| 1904 | .fs_flags = FS_REQUIRES_DEV, |
| 1905 | }; |
| 1906 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1907 | STATIC int __init |
| 1908 | xfs_alloc_trace_bufs(void) |
| 1909 | { |
| 1910 | #ifdef XFS_ALLOC_TRACE |
| 1911 | xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL); |
| 1912 | if (!xfs_alloc_trace_buf) |
| 1913 | goto out; |
| 1914 | #endif |
| 1915 | #ifdef XFS_BMAP_TRACE |
| 1916 | xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL); |
| 1917 | if (!xfs_bmap_trace_buf) |
| 1918 | goto out_free_alloc_trace; |
| 1919 | #endif |
| 1920 | #ifdef XFS_BMBT_TRACE |
| 1921 | xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL); |
| 1922 | if (!xfs_bmbt_trace_buf) |
| 1923 | goto out_free_bmap_trace; |
| 1924 | #endif |
| 1925 | #ifdef XFS_ATTR_TRACE |
| 1926 | xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL); |
| 1927 | if (!xfs_attr_trace_buf) |
| 1928 | goto out_free_bmbt_trace; |
| 1929 | #endif |
| 1930 | #ifdef XFS_DIR2_TRACE |
| 1931 | xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL); |
| 1932 | if (!xfs_dir2_trace_buf) |
| 1933 | goto out_free_attr_trace; |
| 1934 | #endif |
| 1935 | |
| 1936 | return 0; |
| 1937 | |
| 1938 | #ifdef XFS_DIR2_TRACE |
| 1939 | out_free_attr_trace: |
| 1940 | #endif |
| 1941 | #ifdef XFS_ATTR_TRACE |
| 1942 | ktrace_free(xfs_attr_trace_buf); |
| 1943 | out_free_bmbt_trace: |
| 1944 | #endif |
| 1945 | #ifdef XFS_BMBT_TRACE |
| 1946 | ktrace_free(xfs_bmbt_trace_buf); |
| 1947 | out_free_bmap_trace: |
| 1948 | #endif |
| 1949 | #ifdef XFS_BMAP_TRACE |
| 1950 | ktrace_free(xfs_bmap_trace_buf); |
| 1951 | out_free_alloc_trace: |
| 1952 | #endif |
| 1953 | #ifdef XFS_ALLOC_TRACE |
| 1954 | ktrace_free(xfs_alloc_trace_buf); |
| 1955 | out: |
| 1956 | #endif |
| 1957 | return -ENOMEM; |
| 1958 | } |
| 1959 | |
| 1960 | STATIC void |
| 1961 | xfs_free_trace_bufs(void) |
| 1962 | { |
| 1963 | #ifdef XFS_DIR2_TRACE |
| 1964 | ktrace_free(xfs_dir2_trace_buf); |
| 1965 | #endif |
| 1966 | #ifdef XFS_ATTR_TRACE |
| 1967 | ktrace_free(xfs_attr_trace_buf); |
| 1968 | #endif |
| 1969 | #ifdef XFS_BMBT_TRACE |
| 1970 | ktrace_free(xfs_bmbt_trace_buf); |
| 1971 | #endif |
| 1972 | #ifdef XFS_BMAP_TRACE |
| 1973 | ktrace_free(xfs_bmap_trace_buf); |
| 1974 | #endif |
| 1975 | #ifdef XFS_ALLOC_TRACE |
| 1976 | ktrace_free(xfs_alloc_trace_buf); |
| 1977 | #endif |
| 1978 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | |
| 1980 | STATIC int __init |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1981 | xfs_init_zones(void) |
| 1982 | { |
Christoph Hellwig | 5ec7f8c | 2008-08-13 16:22:40 +1000 | [diff] [blame] | 1983 | xfs_vnode_zone = kmem_zone_init_flags(sizeof(struct inode), "xfs_vnode", |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 1984 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | |
| 1985 | KM_ZONE_SPREAD, |
| 1986 | xfs_fs_inode_init_once); |
| 1987 | if (!xfs_vnode_zone) |
| 1988 | goto out; |
| 1989 | |
| 1990 | xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend"); |
| 1991 | if (!xfs_ioend_zone) |
| 1992 | goto out_destroy_vnode_zone; |
| 1993 | |
| 1994 | xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE, |
| 1995 | xfs_ioend_zone); |
| 1996 | if (!xfs_ioend_pool) |
| 1997 | goto out_destroy_ioend_zone; |
| 1998 | |
| 1999 | xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t), |
| 2000 | "xfs_log_ticket"); |
| 2001 | if (!xfs_log_ticket_zone) |
| 2002 | goto out_destroy_ioend_pool; |
| 2003 | |
| 2004 | xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t), |
| 2005 | "xfs_bmap_free_item"); |
| 2006 | if (!xfs_bmap_free_item_zone) |
| 2007 | goto out_destroy_log_ticket_zone; |
| 2008 | xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t), |
| 2009 | "xfs_btree_cur"); |
| 2010 | if (!xfs_btree_cur_zone) |
| 2011 | goto out_destroy_bmap_free_item_zone; |
| 2012 | |
| 2013 | xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t), |
| 2014 | "xfs_da_state"); |
| 2015 | if (!xfs_da_state_zone) |
| 2016 | goto out_destroy_btree_cur_zone; |
| 2017 | |
| 2018 | xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf"); |
| 2019 | if (!xfs_dabuf_zone) |
| 2020 | goto out_destroy_da_state_zone; |
| 2021 | |
| 2022 | xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork"); |
| 2023 | if (!xfs_ifork_zone) |
| 2024 | goto out_destroy_dabuf_zone; |
| 2025 | |
| 2026 | xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans"); |
| 2027 | if (!xfs_trans_zone) |
| 2028 | goto out_destroy_ifork_zone; |
| 2029 | |
| 2030 | /* |
| 2031 | * The size of the zone allocated buf log item is the maximum |
| 2032 | * size possible under XFS. This wastes a little bit of memory, |
| 2033 | * but it is much faster. |
| 2034 | */ |
| 2035 | xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) + |
| 2036 | (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) / |
| 2037 | NBWORD) * sizeof(int))), "xfs_buf_item"); |
| 2038 | if (!xfs_buf_item_zone) |
| 2039 | goto out_destroy_trans_zone; |
| 2040 | |
| 2041 | xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) + |
| 2042 | ((XFS_EFD_MAX_FAST_EXTENTS - 1) * |
| 2043 | sizeof(xfs_extent_t))), "xfs_efd_item"); |
| 2044 | if (!xfs_efd_zone) |
| 2045 | goto out_destroy_buf_item_zone; |
| 2046 | |
| 2047 | xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) + |
| 2048 | ((XFS_EFI_MAX_FAST_EXTENTS - 1) * |
| 2049 | sizeof(xfs_extent_t))), "xfs_efi_item"); |
| 2050 | if (!xfs_efi_zone) |
| 2051 | goto out_destroy_efd_zone; |
| 2052 | |
| 2053 | xfs_inode_zone = |
| 2054 | kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode", |
| 2055 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | |
David Chinner | 07c8f67 | 2008-10-30 16:11:59 +1100 | [diff] [blame^] | 2056 | KM_ZONE_SPREAD, xfs_inode_init_once); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2057 | if (!xfs_inode_zone) |
| 2058 | goto out_destroy_efi_zone; |
| 2059 | |
| 2060 | xfs_ili_zone = |
| 2061 | kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili", |
| 2062 | KM_ZONE_SPREAD, NULL); |
| 2063 | if (!xfs_ili_zone) |
| 2064 | goto out_destroy_inode_zone; |
| 2065 | |
| 2066 | #ifdef CONFIG_XFS_POSIX_ACL |
| 2067 | xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl"); |
| 2068 | if (!xfs_acl_zone) |
| 2069 | goto out_destroy_ili_zone; |
| 2070 | #endif |
| 2071 | |
| 2072 | return 0; |
| 2073 | |
| 2074 | #ifdef CONFIG_XFS_POSIX_ACL |
| 2075 | out_destroy_ili_zone: |
| 2076 | #endif |
| 2077 | kmem_zone_destroy(xfs_ili_zone); |
| 2078 | out_destroy_inode_zone: |
| 2079 | kmem_zone_destroy(xfs_inode_zone); |
| 2080 | out_destroy_efi_zone: |
| 2081 | kmem_zone_destroy(xfs_efi_zone); |
| 2082 | out_destroy_efd_zone: |
| 2083 | kmem_zone_destroy(xfs_efd_zone); |
| 2084 | out_destroy_buf_item_zone: |
| 2085 | kmem_zone_destroy(xfs_buf_item_zone); |
| 2086 | out_destroy_trans_zone: |
| 2087 | kmem_zone_destroy(xfs_trans_zone); |
| 2088 | out_destroy_ifork_zone: |
| 2089 | kmem_zone_destroy(xfs_ifork_zone); |
| 2090 | out_destroy_dabuf_zone: |
| 2091 | kmem_zone_destroy(xfs_dabuf_zone); |
| 2092 | out_destroy_da_state_zone: |
| 2093 | kmem_zone_destroy(xfs_da_state_zone); |
| 2094 | out_destroy_btree_cur_zone: |
| 2095 | kmem_zone_destroy(xfs_btree_cur_zone); |
| 2096 | out_destroy_bmap_free_item_zone: |
| 2097 | kmem_zone_destroy(xfs_bmap_free_item_zone); |
| 2098 | out_destroy_log_ticket_zone: |
| 2099 | kmem_zone_destroy(xfs_log_ticket_zone); |
| 2100 | out_destroy_ioend_pool: |
| 2101 | mempool_destroy(xfs_ioend_pool); |
| 2102 | out_destroy_ioend_zone: |
| 2103 | kmem_zone_destroy(xfs_ioend_zone); |
| 2104 | out_destroy_vnode_zone: |
| 2105 | kmem_zone_destroy(xfs_vnode_zone); |
| 2106 | out: |
| 2107 | return -ENOMEM; |
| 2108 | } |
| 2109 | |
| 2110 | STATIC void |
| 2111 | xfs_destroy_zones(void) |
| 2112 | { |
| 2113 | #ifdef CONFIG_XFS_POSIX_ACL |
| 2114 | kmem_zone_destroy(xfs_acl_zone); |
| 2115 | #endif |
| 2116 | kmem_zone_destroy(xfs_ili_zone); |
| 2117 | kmem_zone_destroy(xfs_inode_zone); |
| 2118 | kmem_zone_destroy(xfs_efi_zone); |
| 2119 | kmem_zone_destroy(xfs_efd_zone); |
| 2120 | kmem_zone_destroy(xfs_buf_item_zone); |
| 2121 | kmem_zone_destroy(xfs_trans_zone); |
| 2122 | kmem_zone_destroy(xfs_ifork_zone); |
| 2123 | kmem_zone_destroy(xfs_dabuf_zone); |
| 2124 | kmem_zone_destroy(xfs_da_state_zone); |
| 2125 | kmem_zone_destroy(xfs_btree_cur_zone); |
| 2126 | kmem_zone_destroy(xfs_bmap_free_item_zone); |
| 2127 | kmem_zone_destroy(xfs_log_ticket_zone); |
| 2128 | mempool_destroy(xfs_ioend_pool); |
| 2129 | kmem_zone_destroy(xfs_ioend_zone); |
| 2130 | kmem_zone_destroy(xfs_vnode_zone); |
| 2131 | |
| 2132 | } |
| 2133 | |
| 2134 | STATIC int __init |
| 2135 | init_xfs_fs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | { |
| 2137 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | static char message[] __initdata = KERN_INFO \ |
| 2139 | XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n"; |
| 2140 | |
| 2141 | printk(message); |
| 2142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | ktrace_init(64); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2144 | vn_init(); |
| 2145 | xfs_dir_startup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 2147 | error = xfs_init_zones(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2148 | if (error) |
| 2149 | goto out; |
| 2150 | |
| 2151 | error = xfs_alloc_trace_bufs(); |
| 2152 | if (error) |
| 2153 | goto out_destroy_zones; |
| 2154 | |
| 2155 | error = xfs_mru_cache_init(); |
| 2156 | if (error) |
| 2157 | goto out_free_trace_buffers; |
| 2158 | |
| 2159 | error = xfs_filestream_init(); |
| 2160 | if (error) |
| 2161 | goto out_mru_cache_uninit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 2163 | error = xfs_buf_init(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2164 | if (error) |
| 2165 | goto out_filestream_uninit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2167 | error = xfs_init_procfs(); |
| 2168 | if (error) |
| 2169 | goto out_buf_terminate; |
| 2170 | |
| 2171 | error = xfs_sysctl_register(); |
| 2172 | if (error) |
| 2173 | goto out_cleanup_procfs; |
| 2174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | vfs_initquota(); |
| 2176 | |
| 2177 | error = register_filesystem(&xfs_fs_type); |
| 2178 | if (error) |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2179 | goto out_sysctl_unregister; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | return 0; |
| 2181 | |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2182 | out_sysctl_unregister: |
| 2183 | xfs_sysctl_unregister(); |
| 2184 | out_cleanup_procfs: |
| 2185 | xfs_cleanup_procfs(); |
| 2186 | out_buf_terminate: |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 2187 | xfs_buf_terminate(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2188 | out_filestream_uninit: |
| 2189 | xfs_filestream_uninit(); |
| 2190 | out_mru_cache_uninit: |
| 2191 | xfs_mru_cache_uninit(); |
| 2192 | out_free_trace_buffers: |
| 2193 | xfs_free_trace_bufs(); |
| 2194 | out_destroy_zones: |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 2195 | xfs_destroy_zones(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2196 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | return error; |
| 2198 | } |
| 2199 | |
| 2200 | STATIC void __exit |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2201 | exit_xfs_fs(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | { |
| 2203 | vfs_exitquota(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2204 | unregister_filesystem(&xfs_fs_type); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2205 | xfs_sysctl_unregister(); |
| 2206 | xfs_cleanup_procfs(); |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 2207 | xfs_buf_terminate(); |
Christoph Hellwig | 9f8868f | 2008-07-18 17:11:46 +1000 | [diff] [blame] | 2208 | xfs_filestream_uninit(); |
| 2209 | xfs_mru_cache_uninit(); |
| 2210 | xfs_free_trace_bufs(); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 2211 | xfs_destroy_zones(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | ktrace_uninit(); |
| 2213 | } |
| 2214 | |
| 2215 | module_init(init_xfs_fs); |
| 2216 | module_exit(exit_xfs_fs); |
| 2217 | |
| 2218 | MODULE_AUTHOR("Silicon Graphics, Inc."); |
| 2219 | MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled"); |
| 2220 | MODULE_LICENSE("GPL"); |