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