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" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | #include <linux/namei.h> |
| 57 | #include <linux/init.h> |
| 58 | #include <linux/mount.h> |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 59 | #include <linux/mempool.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #include <linux/writeback.h> |
Christoph Hellwig | 4df08c5 | 2005-09-05 08:34:18 +1000 | [diff] [blame] | 61 | #include <linux/kthread.h> |
Nigel Cunningham | 7dfb710 | 2006-12-06 20:34:23 -0800 | [diff] [blame] | 62 | #include <linux/freezer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 64 | static struct quotactl_ops xfs_quotactl_operations; |
| 65 | static struct super_operations xfs_super_operations; |
| 66 | static kmem_zone_t *xfs_vnode_zone; |
| 67 | static kmem_zone_t *xfs_ioend_zone; |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 68 | mempool_t *xfs_ioend_pool; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | STATIC struct xfs_mount_args * |
| 71 | xfs_args_allocate( |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 72 | struct super_block *sb, |
| 73 | int silent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | struct xfs_mount_args *args; |
| 76 | |
| 77 | args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP); |
| 78 | args->logbufs = args->logbufsize = -1; |
| 79 | strncpy(args->fsname, sb->s_id, MAXNAMELEN); |
| 80 | |
| 81 | /* Copy the already-parsed mount(2) flags we're interested in */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | if (sb->s_flags & MS_DIRSYNC) |
| 83 | args->flags |= XFSMNT_DIRSYNC; |
| 84 | if (sb->s_flags & MS_SYNCHRONOUS) |
| 85 | args->flags |= XFSMNT_WSYNC; |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 86 | if (silent) |
| 87 | args->flags |= XFSMNT_QUIET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | args->flags |= XFSMNT_32BITINODES; |
| 89 | |
| 90 | return args; |
| 91 | } |
| 92 | |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 93 | #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */ |
| 94 | #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */ |
| 95 | #define MNTOPT_LOGDEV "logdev" /* log device */ |
| 96 | #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */ |
| 97 | #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */ |
| 98 | #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */ |
| 99 | #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */ |
| 100 | #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */ |
| 101 | #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */ |
| 102 | #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */ |
| 103 | #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */ |
| 104 | #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */ |
| 105 | #define MNTOPT_MTPT "mtpt" /* filesystem mount point */ |
| 106 | #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */ |
| 107 | #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */ |
| 108 | #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */ |
| 109 | #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */ |
| 110 | #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */ |
| 111 | #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */ |
| 112 | #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and |
| 113 | * unwritten extent conversion */ |
| 114 | #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */ |
| 115 | #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */ |
| 116 | #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */ |
| 117 | #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */ |
| 118 | #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */ |
| 119 | #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */ |
| 120 | #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes |
| 121 | * in stat(). */ |
| 122 | #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */ |
| 123 | #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */ |
| 124 | #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */ |
| 125 | #define MNTOPT_QUOTA "quota" /* disk quotas (user) */ |
| 126 | #define MNTOPT_NOQUOTA "noquota" /* no quotas */ |
| 127 | #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */ |
| 128 | #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */ |
| 129 | #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */ |
| 130 | #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */ |
| 131 | #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */ |
| 132 | #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */ |
| 133 | #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */ |
| 134 | #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */ |
| 135 | #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */ |
| 136 | #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */ |
| 137 | #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */ |
| 138 | #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */ |
| 139 | #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */ |
| 140 | |
| 141 | STATIC unsigned long |
| 142 | suffix_strtoul(char *s, char **endp, unsigned int base) |
| 143 | { |
| 144 | int last, shift_left_factor = 0; |
| 145 | char *value = s; |
| 146 | |
| 147 | last = strlen(value) - 1; |
| 148 | if (value[last] == 'K' || value[last] == 'k') { |
| 149 | shift_left_factor = 10; |
| 150 | value[last] = '\0'; |
| 151 | } |
| 152 | if (value[last] == 'M' || value[last] == 'm') { |
| 153 | shift_left_factor = 20; |
| 154 | value[last] = '\0'; |
| 155 | } |
| 156 | if (value[last] == 'G' || value[last] == 'g') { |
| 157 | shift_left_factor = 30; |
| 158 | value[last] = '\0'; |
| 159 | } |
| 160 | |
| 161 | return simple_strtoul((const char *)s, endp, base) << shift_left_factor; |
| 162 | } |
| 163 | |
| 164 | STATIC int |
| 165 | xfs_parseargs( |
| 166 | struct xfs_mount *mp, |
| 167 | char *options, |
| 168 | struct xfs_mount_args *args, |
| 169 | int update) |
| 170 | { |
| 171 | char *this_char, *value, *eov; |
| 172 | int dsunit, dswidth, vol_dsunit, vol_dswidth; |
| 173 | int iosize; |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame^] | 174 | int dmapi_implies_ikeep = 1; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 175 | |
| 176 | args->flags |= XFSMNT_BARRIER; |
| 177 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; |
| 178 | |
| 179 | if (!options) |
| 180 | goto done; |
| 181 | |
| 182 | iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0; |
| 183 | |
| 184 | while ((this_char = strsep(&options, ",")) != NULL) { |
| 185 | if (!*this_char) |
| 186 | continue; |
| 187 | if ((value = strchr(this_char, '=')) != NULL) |
| 188 | *value++ = 0; |
| 189 | |
| 190 | if (!strcmp(this_char, MNTOPT_LOGBUFS)) { |
| 191 | if (!value || !*value) { |
| 192 | cmn_err(CE_WARN, |
| 193 | "XFS: %s option requires an argument", |
| 194 | this_char); |
| 195 | return EINVAL; |
| 196 | } |
| 197 | args->logbufs = simple_strtoul(value, &eov, 10); |
| 198 | } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) { |
| 199 | if (!value || !*value) { |
| 200 | cmn_err(CE_WARN, |
| 201 | "XFS: %s option requires an argument", |
| 202 | this_char); |
| 203 | return EINVAL; |
| 204 | } |
| 205 | args->logbufsize = suffix_strtoul(value, &eov, 10); |
| 206 | } else if (!strcmp(this_char, MNTOPT_LOGDEV)) { |
| 207 | if (!value || !*value) { |
| 208 | cmn_err(CE_WARN, |
| 209 | "XFS: %s option requires an argument", |
| 210 | this_char); |
| 211 | return EINVAL; |
| 212 | } |
| 213 | strncpy(args->logname, value, MAXNAMELEN); |
| 214 | } else if (!strcmp(this_char, MNTOPT_MTPT)) { |
| 215 | if (!value || !*value) { |
| 216 | cmn_err(CE_WARN, |
| 217 | "XFS: %s option requires an argument", |
| 218 | this_char); |
| 219 | return EINVAL; |
| 220 | } |
| 221 | strncpy(args->mtpt, value, MAXNAMELEN); |
| 222 | } else if (!strcmp(this_char, MNTOPT_RTDEV)) { |
| 223 | if (!value || !*value) { |
| 224 | cmn_err(CE_WARN, |
| 225 | "XFS: %s option requires an argument", |
| 226 | this_char); |
| 227 | return EINVAL; |
| 228 | } |
| 229 | strncpy(args->rtname, value, MAXNAMELEN); |
| 230 | } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) { |
| 231 | if (!value || !*value) { |
| 232 | cmn_err(CE_WARN, |
| 233 | "XFS: %s option requires an argument", |
| 234 | this_char); |
| 235 | return EINVAL; |
| 236 | } |
| 237 | iosize = simple_strtoul(value, &eov, 10); |
| 238 | args->flags |= XFSMNT_IOSIZE; |
| 239 | args->iosizelog = (uint8_t) iosize; |
| 240 | } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) { |
| 241 | if (!value || !*value) { |
| 242 | cmn_err(CE_WARN, |
| 243 | "XFS: %s option requires an argument", |
| 244 | this_char); |
| 245 | return EINVAL; |
| 246 | } |
| 247 | iosize = suffix_strtoul(value, &eov, 10); |
| 248 | args->flags |= XFSMNT_IOSIZE; |
| 249 | args->iosizelog = ffs(iosize) - 1; |
| 250 | } else if (!strcmp(this_char, MNTOPT_GRPID) || |
| 251 | !strcmp(this_char, MNTOPT_BSDGROUPS)) { |
| 252 | mp->m_flags |= XFS_MOUNT_GRPID; |
| 253 | } else if (!strcmp(this_char, MNTOPT_NOGRPID) || |
| 254 | !strcmp(this_char, MNTOPT_SYSVGROUPS)) { |
| 255 | mp->m_flags &= ~XFS_MOUNT_GRPID; |
| 256 | } else if (!strcmp(this_char, MNTOPT_WSYNC)) { |
| 257 | args->flags |= XFSMNT_WSYNC; |
| 258 | } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) { |
| 259 | args->flags |= XFSMNT_OSYNCISOSYNC; |
| 260 | } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) { |
| 261 | args->flags |= XFSMNT_NORECOVERY; |
| 262 | } else if (!strcmp(this_char, MNTOPT_INO64)) { |
| 263 | args->flags |= XFSMNT_INO64; |
| 264 | #if !XFS_BIG_INUMS |
| 265 | cmn_err(CE_WARN, |
| 266 | "XFS: %s option not allowed on this system", |
| 267 | this_char); |
| 268 | return EINVAL; |
| 269 | #endif |
| 270 | } else if (!strcmp(this_char, MNTOPT_NOALIGN)) { |
| 271 | args->flags |= XFSMNT_NOALIGN; |
| 272 | } else if (!strcmp(this_char, MNTOPT_SWALLOC)) { |
| 273 | args->flags |= XFSMNT_SWALLOC; |
| 274 | } else if (!strcmp(this_char, MNTOPT_SUNIT)) { |
| 275 | if (!value || !*value) { |
| 276 | cmn_err(CE_WARN, |
| 277 | "XFS: %s option requires an argument", |
| 278 | this_char); |
| 279 | return EINVAL; |
| 280 | } |
| 281 | dsunit = simple_strtoul(value, &eov, 10); |
| 282 | } else if (!strcmp(this_char, MNTOPT_SWIDTH)) { |
| 283 | if (!value || !*value) { |
| 284 | cmn_err(CE_WARN, |
| 285 | "XFS: %s option requires an argument", |
| 286 | this_char); |
| 287 | return EINVAL; |
| 288 | } |
| 289 | dswidth = simple_strtoul(value, &eov, 10); |
| 290 | } else if (!strcmp(this_char, MNTOPT_64BITINODE)) { |
| 291 | args->flags &= ~XFSMNT_32BITINODES; |
| 292 | #if !XFS_BIG_INUMS |
| 293 | cmn_err(CE_WARN, |
| 294 | "XFS: %s option not allowed on this system", |
| 295 | this_char); |
| 296 | return EINVAL; |
| 297 | #endif |
| 298 | } else if (!strcmp(this_char, MNTOPT_NOUUID)) { |
| 299 | args->flags |= XFSMNT_NOUUID; |
| 300 | } else if (!strcmp(this_char, MNTOPT_BARRIER)) { |
| 301 | args->flags |= XFSMNT_BARRIER; |
| 302 | } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) { |
| 303 | args->flags &= ~XFSMNT_BARRIER; |
| 304 | } else if (!strcmp(this_char, MNTOPT_IKEEP)) { |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame^] | 305 | args->flags |= XFSMNT_IKEEP; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 306 | } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) { |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame^] | 307 | dmapi_implies_ikeep = 0; |
| 308 | args->flags &= ~XFSMNT_IKEEP; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 309 | } else if (!strcmp(this_char, MNTOPT_LARGEIO)) { |
| 310 | args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE; |
| 311 | } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) { |
| 312 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; |
| 313 | } else if (!strcmp(this_char, MNTOPT_ATTR2)) { |
| 314 | args->flags |= XFSMNT_ATTR2; |
| 315 | } else if (!strcmp(this_char, MNTOPT_NOATTR2)) { |
| 316 | args->flags &= ~XFSMNT_ATTR2; |
| 317 | } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) { |
| 318 | args->flags2 |= XFSMNT2_FILESTREAMS; |
| 319 | } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) { |
| 320 | args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA); |
| 321 | args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA); |
| 322 | } else if (!strcmp(this_char, MNTOPT_QUOTA) || |
| 323 | !strcmp(this_char, MNTOPT_UQUOTA) || |
| 324 | !strcmp(this_char, MNTOPT_USRQUOTA)) { |
| 325 | args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF; |
| 326 | } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) || |
| 327 | !strcmp(this_char, MNTOPT_UQUOTANOENF)) { |
| 328 | args->flags |= XFSMNT_UQUOTA; |
| 329 | args->flags &= ~XFSMNT_UQUOTAENF; |
| 330 | } else if (!strcmp(this_char, MNTOPT_PQUOTA) || |
| 331 | !strcmp(this_char, MNTOPT_PRJQUOTA)) { |
| 332 | args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF; |
| 333 | } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) { |
| 334 | args->flags |= XFSMNT_PQUOTA; |
| 335 | args->flags &= ~XFSMNT_PQUOTAENF; |
| 336 | } else if (!strcmp(this_char, MNTOPT_GQUOTA) || |
| 337 | !strcmp(this_char, MNTOPT_GRPQUOTA)) { |
| 338 | args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF; |
| 339 | } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) { |
| 340 | args->flags |= XFSMNT_GQUOTA; |
| 341 | args->flags &= ~XFSMNT_GQUOTAENF; |
| 342 | } else if (!strcmp(this_char, MNTOPT_DMAPI)) { |
| 343 | args->flags |= XFSMNT_DMAPI; |
| 344 | } else if (!strcmp(this_char, MNTOPT_XDSM)) { |
| 345 | args->flags |= XFSMNT_DMAPI; |
| 346 | } else if (!strcmp(this_char, MNTOPT_DMI)) { |
| 347 | args->flags |= XFSMNT_DMAPI; |
| 348 | } else if (!strcmp(this_char, "ihashsize")) { |
| 349 | cmn_err(CE_WARN, |
| 350 | "XFS: ihashsize no longer used, option is deprecated."); |
| 351 | } else if (!strcmp(this_char, "osyncisdsync")) { |
| 352 | /* no-op, this is now the default */ |
| 353 | cmn_err(CE_WARN, |
| 354 | "XFS: osyncisdsync is now the default, option is deprecated."); |
| 355 | } else if (!strcmp(this_char, "irixsgid")) { |
| 356 | cmn_err(CE_WARN, |
| 357 | "XFS: irixsgid is now a sysctl(2) variable, option is deprecated."); |
| 358 | } else { |
| 359 | cmn_err(CE_WARN, |
| 360 | "XFS: unknown mount option [%s].", this_char); |
| 361 | return EINVAL; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | if (args->flags & XFSMNT_NORECOVERY) { |
| 366 | if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) { |
| 367 | cmn_err(CE_WARN, |
| 368 | "XFS: no-recovery mounts must be read-only."); |
| 369 | return EINVAL; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) { |
| 374 | cmn_err(CE_WARN, |
| 375 | "XFS: sunit and swidth options incompatible with the noalign option"); |
| 376 | return EINVAL; |
| 377 | } |
| 378 | |
| 379 | if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) { |
| 380 | cmn_err(CE_WARN, |
| 381 | "XFS: cannot mount with both project and group quota"); |
| 382 | return EINVAL; |
| 383 | } |
| 384 | |
| 385 | if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') { |
| 386 | printk("XFS: %s option needs the mount point option as well\n", |
| 387 | MNTOPT_DMAPI); |
| 388 | return EINVAL; |
| 389 | } |
| 390 | |
| 391 | if ((dsunit && !dswidth) || (!dsunit && dswidth)) { |
| 392 | cmn_err(CE_WARN, |
| 393 | "XFS: sunit and swidth must be specified together"); |
| 394 | return EINVAL; |
| 395 | } |
| 396 | |
| 397 | if (dsunit && (dswidth % dsunit != 0)) { |
| 398 | cmn_err(CE_WARN, |
| 399 | "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)", |
| 400 | dswidth, dsunit); |
| 401 | return EINVAL; |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * Applications using DMI filesystems often expect the |
| 406 | * inode generation number to be monotonically increasing. |
| 407 | * If we delete inode chunks we break this assumption, so |
| 408 | * keep unused inode chunks on disk for DMI filesystems |
| 409 | * until we come up with a better solution. |
| 410 | * Note that if "ikeep" or "noikeep" mount options are |
| 411 | * supplied, then they are honored. |
| 412 | */ |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame^] | 413 | if ((args->flags & XFSMNT_DMAPI) && dmapi_implies_ikeep) |
| 414 | args->flags |= XFSMNT_IKEEP; |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 415 | |
| 416 | if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { |
| 417 | if (dsunit) { |
| 418 | args->sunit = dsunit; |
| 419 | args->flags |= XFSMNT_RETERR; |
| 420 | } else { |
| 421 | args->sunit = vol_dsunit; |
| 422 | } |
| 423 | dswidth ? (args->swidth = dswidth) : |
| 424 | (args->swidth = vol_dswidth); |
| 425 | } else { |
| 426 | args->sunit = args->swidth = 0; |
| 427 | } |
| 428 | |
| 429 | done: |
| 430 | if (args->flags & XFSMNT_32BITINODES) |
| 431 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
| 432 | if (args->flags2) |
| 433 | args->flags |= XFSMNT_FLAGS2; |
| 434 | return 0; |
| 435 | } |
| 436 | |
| 437 | struct proc_xfs_info { |
| 438 | int flag; |
| 439 | char *str; |
| 440 | }; |
| 441 | |
| 442 | STATIC int |
| 443 | xfs_showargs( |
| 444 | struct xfs_mount *mp, |
| 445 | struct seq_file *m) |
| 446 | { |
| 447 | static struct proc_xfs_info xfs_info_set[] = { |
| 448 | /* the few simple ones we can get from the mount struct */ |
Josef Jeff Sipek | 1bd960e | 2008-02-29 13:58:40 +1100 | [diff] [blame^] | 449 | { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP }, |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 450 | { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC }, |
| 451 | { XFS_MOUNT_INO64, "," MNTOPT_INO64 }, |
| 452 | { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN }, |
| 453 | { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC }, |
| 454 | { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID }, |
| 455 | { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY }, |
| 456 | { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC }, |
| 457 | { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 }, |
| 458 | { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM }, |
| 459 | { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI }, |
| 460 | { XFS_MOUNT_GRPID, "," MNTOPT_GRPID }, |
| 461 | { 0, NULL } |
| 462 | }; |
| 463 | static struct proc_xfs_info xfs_info_unset[] = { |
| 464 | /* the few simple ones we can get from the mount struct */ |
David Chinner | a67d7c5 | 2007-11-23 16:29:32 +1100 | [diff] [blame] | 465 | { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO }, |
| 466 | { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER }, |
| 467 | { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE }, |
| 468 | { 0, NULL } |
| 469 | }; |
| 470 | struct proc_xfs_info *xfs_infop; |
| 471 | |
| 472 | for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) { |
| 473 | if (mp->m_flags & xfs_infop->flag) |
| 474 | seq_puts(m, xfs_infop->str); |
| 475 | } |
| 476 | for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) { |
| 477 | if (!(mp->m_flags & xfs_infop->flag)) |
| 478 | seq_puts(m, xfs_infop->str); |
| 479 | } |
| 480 | |
| 481 | if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) |
| 482 | seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk", |
| 483 | (int)(1 << mp->m_writeio_log) >> 10); |
| 484 | |
| 485 | if (mp->m_logbufs > 0) |
| 486 | seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs); |
| 487 | if (mp->m_logbsize > 0) |
| 488 | seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10); |
| 489 | |
| 490 | if (mp->m_logname) |
| 491 | seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname); |
| 492 | if (mp->m_rtname) |
| 493 | seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname); |
| 494 | |
| 495 | if (mp->m_dalign > 0) |
| 496 | seq_printf(m, "," MNTOPT_SUNIT "=%d", |
| 497 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); |
| 498 | if (mp->m_swidth > 0) |
| 499 | seq_printf(m, "," MNTOPT_SWIDTH "=%d", |
| 500 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); |
| 501 | |
| 502 | if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD)) |
| 503 | seq_puts(m, "," MNTOPT_USRQUOTA); |
| 504 | else if (mp->m_qflags & XFS_UQUOTA_ACCT) |
| 505 | seq_puts(m, "," MNTOPT_UQUOTANOENF); |
| 506 | |
| 507 | if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD)) |
| 508 | seq_puts(m, "," MNTOPT_PRJQUOTA); |
| 509 | else if (mp->m_qflags & XFS_PQUOTA_ACCT) |
| 510 | seq_puts(m, "," MNTOPT_PQUOTANOENF); |
| 511 | |
| 512 | if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD)) |
| 513 | seq_puts(m, "," MNTOPT_GRPQUOTA); |
| 514 | else if (mp->m_qflags & XFS_GQUOTA_ACCT) |
| 515 | seq_puts(m, "," MNTOPT_GQUOTANOENF); |
| 516 | |
| 517 | if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT)) |
| 518 | seq_puts(m, "," MNTOPT_NOQUOTA); |
| 519 | |
| 520 | return 0; |
| 521 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | __uint64_t |
| 523 | xfs_max_file_offset( |
| 524 | unsigned int blockshift) |
| 525 | { |
| 526 | unsigned int pagefactor = 1; |
| 527 | unsigned int bitshift = BITS_PER_LONG - 1; |
| 528 | |
| 529 | /* Figure out maximum filesize, on Linux this can depend on |
| 530 | * the filesystem blocksize (on 32 bit platforms). |
| 531 | * __block_prepare_write does this in an [unsigned] long... |
| 532 | * page->index << (PAGE_CACHE_SHIFT - bbits) |
| 533 | * So, for page sized blocks (4K on 32 bit platforms), |
| 534 | * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is |
| 535 | * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) |
| 536 | * but for smaller blocksizes it is less (bbits = log2 bsize). |
| 537 | * Note1: get_block_t takes a long (implicit cast from above) |
| 538 | * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch |
| 539 | * can optionally convert the [unsigned] long from above into |
| 540 | * an [unsigned] long long. |
| 541 | */ |
| 542 | |
| 543 | #if BITS_PER_LONG == 32 |
| 544 | # if defined(CONFIG_LBD) |
| 545 | ASSERT(sizeof(sector_t) == 8); |
| 546 | pagefactor = PAGE_CACHE_SIZE; |
| 547 | bitshift = BITS_PER_LONG; |
| 548 | # else |
| 549 | pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift); |
| 550 | # endif |
| 551 | #endif |
| 552 | |
| 553 | return (((__uint64_t)pagefactor) << bitshift) - 1; |
| 554 | } |
| 555 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 556 | STATIC_INLINE void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | xfs_set_inodeops( |
| 558 | struct inode *inode) |
| 559 | { |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 560 | switch (inode->i_mode & S_IFMT) { |
| 561 | case S_IFREG: |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 562 | inode->i_op = &xfs_inode_operations; |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 563 | inode->i_fop = &xfs_file_operations; |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 564 | inode->i_mapping->a_ops = &xfs_address_space_operations; |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 565 | break; |
| 566 | case S_IFDIR: |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 567 | inode->i_op = &xfs_dir_inode_operations; |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 568 | inode->i_fop = &xfs_dir_file_operations; |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 569 | break; |
| 570 | case S_IFLNK: |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 571 | inode->i_op = &xfs_symlink_inode_operations; |
Christoph Hellwig | 222096a | 2008-02-05 12:13:46 +1100 | [diff] [blame] | 572 | if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE)) |
Nathan Scott | e4c573b | 2006-03-14 13:54:26 +1100 | [diff] [blame] | 573 | inode->i_mapping->a_ops = &xfs_address_space_operations; |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 574 | break; |
| 575 | default: |
Nathan Scott | 416c6d5 | 2006-03-14 14:00:51 +1100 | [diff] [blame] | 576 | inode->i_op = &xfs_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 578 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 582 | STATIC_INLINE void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | xfs_revalidate_inode( |
| 584 | xfs_mount_t *mp, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 585 | bhv_vnode_t *vp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | xfs_inode_t *ip) |
| 587 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 588 | struct inode *inode = vn_to_inode(vp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 590 | inode->i_mode = ip->i_d.di_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | inode->i_nlink = ip->i_d.di_nlink; |
| 592 | inode->i_uid = ip->i_d.di_uid; |
| 593 | inode->i_gid = ip->i_d.di_gid; |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 594 | |
| 595 | switch (inode->i_mode & S_IFMT) { |
| 596 | case S_IFBLK: |
| 597 | case S_IFCHR: |
| 598 | inode->i_rdev = |
| 599 | MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff, |
| 600 | sysv_minor(ip->i_df.if_u2.if_rdev)); |
| 601 | break; |
| 602 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | inode->i_rdev = 0; |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 604 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | } |
Christoph Hellwig | 0432dab | 2005-09-02 16:46:51 +1000 | [diff] [blame] | 606 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | inode->i_generation = ip->i_d.di_gen; |
| 608 | i_size_write(inode, ip->i_d.di_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec; |
| 610 | inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec; |
| 611 | inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec; |
| 612 | inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec; |
| 613 | inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec; |
| 614 | inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec; |
| 615 | if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE) |
| 616 | inode->i_flags |= S_IMMUTABLE; |
| 617 | else |
| 618 | inode->i_flags &= ~S_IMMUTABLE; |
| 619 | if (ip->i_d.di_flags & XFS_DIFLAG_APPEND) |
| 620 | inode->i_flags |= S_APPEND; |
| 621 | else |
| 622 | inode->i_flags &= ~S_APPEND; |
| 623 | if (ip->i_d.di_flags & XFS_DIFLAG_SYNC) |
| 624 | inode->i_flags |= S_SYNC; |
| 625 | else |
| 626 | inode->i_flags &= ~S_SYNC; |
| 627 | if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME) |
| 628 | inode->i_flags |= S_NOATIME; |
| 629 | else |
| 630 | inode->i_flags &= ~S_NOATIME; |
Christoph Hellwig | b3aea4e | 2007-08-29 11:44:37 +1000 | [diff] [blame] | 631 | xfs_iflags_clear(ip, XFS_IMODIFIED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | void |
| 635 | xfs_initialize_vnode( |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 636 | struct xfs_mount *mp, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 637 | bhv_vnode_t *vp, |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 638 | struct xfs_inode *ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 640 | struct inode *inode = vn_to_inode(vp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 642 | if (!ip->i_vnode) { |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 643 | ip->i_vnode = vp; |
| 644 | inode->i_private = ip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | /* |
| 648 | * We need to set the ops vectors, and unlock the inode, but if |
| 649 | * we have been called during the new inode create process, it is |
| 650 | * too early to fill in the Linux inode. We will get called a |
| 651 | * second time once the inode is properly set up, and then we can |
| 652 | * finish our work. |
| 653 | */ |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 654 | if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) { |
Christoph Hellwig | 48c872a9f | 2007-08-30 17:20:31 +1000 | [diff] [blame] | 655 | xfs_revalidate_inode(mp, vp, ip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | xfs_set_inodeops(inode); |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 657 | |
David Chinner | 7a18c38 | 2006-11-11 18:04:54 +1100 | [diff] [blame] | 658 | xfs_iflags_clear(ip, XFS_INEW); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | barrier(); |
| 660 | |
| 661 | unlock_new_inode(inode); |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | int |
| 666 | xfs_blkdev_get( |
| 667 | xfs_mount_t *mp, |
| 668 | const char *name, |
| 669 | struct block_device **bdevp) |
| 670 | { |
| 671 | int error = 0; |
| 672 | |
| 673 | *bdevp = open_bdev_excl(name, 0, mp); |
| 674 | if (IS_ERR(*bdevp)) { |
| 675 | error = PTR_ERR(*bdevp); |
| 676 | printk("XFS: Invalid device [%s], error=%d\n", name, error); |
| 677 | } |
| 678 | |
| 679 | return -error; |
| 680 | } |
| 681 | |
| 682 | void |
| 683 | xfs_blkdev_put( |
| 684 | struct block_device *bdev) |
| 685 | { |
| 686 | if (bdev) |
| 687 | close_bdev_excl(bdev); |
| 688 | } |
| 689 | |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 690 | /* |
| 691 | * Try to write out the superblock using barriers. |
| 692 | */ |
| 693 | STATIC int |
| 694 | xfs_barrier_test( |
| 695 | xfs_mount_t *mp) |
| 696 | { |
| 697 | xfs_buf_t *sbp = xfs_getsb(mp, 0); |
| 698 | int error; |
| 699 | |
| 700 | XFS_BUF_UNDONE(sbp); |
| 701 | XFS_BUF_UNREAD(sbp); |
| 702 | XFS_BUF_UNDELAYWRITE(sbp); |
| 703 | XFS_BUF_WRITE(sbp); |
| 704 | XFS_BUF_UNASYNC(sbp); |
| 705 | XFS_BUF_ORDERED(sbp); |
| 706 | |
| 707 | xfsbdstrat(mp, sbp); |
| 708 | error = xfs_iowait(sbp); |
| 709 | |
| 710 | /* |
| 711 | * Clear all the flags we set and possible error state in the |
| 712 | * buffer. We only did the write to try out whether barriers |
| 713 | * worked and shouldn't leave any traces in the superblock |
| 714 | * buffer. |
| 715 | */ |
| 716 | XFS_BUF_DONE(sbp); |
| 717 | XFS_BUF_ERROR(sbp, 0); |
| 718 | XFS_BUF_UNORDERED(sbp); |
| 719 | |
| 720 | xfs_buf_relse(sbp); |
| 721 | return error; |
| 722 | } |
| 723 | |
| 724 | void |
| 725 | xfs_mountfs_check_barriers(xfs_mount_t *mp) |
| 726 | { |
| 727 | int error; |
| 728 | |
| 729 | if (mp->m_logdev_targp != mp->m_ddev_targp) { |
| 730 | xfs_fs_cmn_err(CE_NOTE, mp, |
| 731 | "Disabling barriers, not supported with external log device"); |
| 732 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 733 | return; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 734 | } |
| 735 | |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 736 | if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered == |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 737 | QUEUE_ORDERED_NONE) { |
| 738 | xfs_fs_cmn_err(CE_NOTE, mp, |
| 739 | "Disabling barriers, not supported by the underlying device"); |
| 740 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 741 | return; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 742 | } |
| 743 | |
Nathan Scott | b2ea401 | 2006-07-28 17:05:13 +1000 | [diff] [blame] | 744 | if (xfs_readonly_buftarg(mp->m_ddev_targp)) { |
| 745 | xfs_fs_cmn_err(CE_NOTE, mp, |
| 746 | "Disabling barriers, underlying device is readonly"); |
| 747 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
| 748 | return; |
| 749 | } |
| 750 | |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 751 | error = xfs_barrier_test(mp); |
| 752 | if (error) { |
| 753 | xfs_fs_cmn_err(CE_NOTE, mp, |
| 754 | "Disabling barriers, trial barrier write failed"); |
| 755 | mp->m_flags &= ~XFS_MOUNT_BARRIER; |
Christoph Hellwig | 4ef19dd | 2006-01-11 15:27:18 +1100 | [diff] [blame] | 756 | return; |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | void |
| 761 | xfs_blkdev_issue_flush( |
| 762 | xfs_buftarg_t *buftarg) |
| 763 | { |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 764 | blkdev_issue_flush(buftarg->bt_bdev, NULL); |
Christoph Hellwig | f538d4d | 2005-11-02 10:26:59 +1100 | [diff] [blame] | 765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
David Chinner | 249a8c1 | 2008-02-05 12:13:32 +1100 | [diff] [blame] | 767 | /* |
| 768 | * XFS AIL push thread support |
| 769 | */ |
| 770 | void |
| 771 | xfsaild_wakeup( |
| 772 | xfs_mount_t *mp, |
| 773 | xfs_lsn_t threshold_lsn) |
| 774 | { |
| 775 | mp->m_ail.xa_target = threshold_lsn; |
| 776 | wake_up_process(mp->m_ail.xa_task); |
| 777 | } |
| 778 | |
| 779 | int |
| 780 | xfsaild( |
| 781 | void *data) |
| 782 | { |
| 783 | xfs_mount_t *mp = (xfs_mount_t *)data; |
| 784 | xfs_lsn_t last_pushed_lsn = 0; |
| 785 | long tout = 0; |
| 786 | |
| 787 | while (!kthread_should_stop()) { |
| 788 | if (tout) |
| 789 | schedule_timeout_interruptible(msecs_to_jiffies(tout)); |
| 790 | tout = 1000; |
| 791 | |
| 792 | /* swsusp */ |
| 793 | try_to_freeze(); |
| 794 | |
| 795 | ASSERT(mp->m_log); |
| 796 | if (XFS_FORCED_SHUTDOWN(mp)) |
| 797 | continue; |
| 798 | |
| 799 | tout = xfsaild_push(mp, &last_pushed_lsn); |
| 800 | } |
| 801 | |
| 802 | return 0; |
| 803 | } /* xfsaild */ |
| 804 | |
| 805 | int |
| 806 | xfsaild_start( |
| 807 | xfs_mount_t *mp) |
| 808 | { |
| 809 | mp->m_ail.xa_target = 0; |
| 810 | mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild"); |
| 811 | if (IS_ERR(mp->m_ail.xa_task)) |
| 812 | return -PTR_ERR(mp->m_ail.xa_task); |
| 813 | return 0; |
| 814 | } |
| 815 | |
| 816 | void |
| 817 | xfsaild_stop( |
| 818 | xfs_mount_t *mp) |
| 819 | { |
| 820 | kthread_stop(mp->m_ail.xa_task); |
| 821 | } |
| 822 | |
| 823 | |
| 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | STATIC struct inode * |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 826 | xfs_fs_alloc_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | struct super_block *sb) |
| 828 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 829 | bhv_vnode_t *vp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 831 | vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP); |
| 832 | if (unlikely(!vp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | return NULL; |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 834 | return vn_to_inode(vp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 838 | xfs_fs_destroy_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | struct inode *inode) |
| 840 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 841 | kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 845 | xfs_fs_inode_init_once( |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 846 | kmem_zone_t *zonep, |
Christoph Lameter | 4ba9b9d | 2007-10-16 23:25:51 -0700 | [diff] [blame] | 847 | void *vnode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | { |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 849 | inode_init_once(vn_to_inode((bhv_vnode_t *)vnode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Lachlan McIlroy | de2eeea | 2008-02-06 13:37:56 +1100 | [diff] [blame] | 852 | STATIC int __init |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 853 | xfs_init_zones(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 855 | 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] | 856 | KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | |
| 857 | KM_ZONE_SPREAD, |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 858 | xfs_fs_inode_init_once); |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 859 | if (!xfs_vnode_zone) |
| 860 | goto out; |
| 861 | |
| 862 | xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend"); |
| 863 | if (!xfs_ioend_zone) |
| 864 | goto out_destroy_vnode_zone; |
| 865 | |
Matthew Dobson | 93d2341 | 2006-03-26 01:37:50 -0800 | [diff] [blame] | 866 | xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE, |
| 867 | xfs_ioend_zone); |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 868 | if (!xfs_ioend_pool) |
| 869 | goto out_free_ioend_zone; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | return 0; |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 871 | |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 872 | out_free_ioend_zone: |
| 873 | kmem_zone_destroy(xfs_ioend_zone); |
| 874 | out_destroy_vnode_zone: |
| 875 | kmem_zone_destroy(xfs_vnode_zone); |
| 876 | out: |
| 877 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | STATIC void |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 881 | xfs_destroy_zones(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | { |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 883 | mempool_destroy(xfs_ioend_pool); |
| 884 | kmem_zone_destroy(xfs_vnode_zone); |
| 885 | kmem_zone_destroy(xfs_ioend_zone); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | /* |
| 889 | * Attempt to flush the inode, this will actually fail |
| 890 | * if the inode is pinned, but we dirty the inode again |
| 891 | * at the point when it is unpinned after a log write, |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 892 | * since this is when the inode itself becomes flushable. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | */ |
| 894 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 895 | xfs_fs_write_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | struct inode *inode, |
| 897 | int sync) |
| 898 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | int error = 0, flags = FLUSH_INODE; |
| 900 | |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 901 | xfs_itrace_entry(XFS_I(inode)); |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 902 | if (sync) { |
| 903 | filemap_fdatawait(inode->i_mapping); |
| 904 | flags |= FLUSH_SYNC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | } |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 906 | error = xfs_inode_flush(XFS_I(inode), flags); |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 907 | /* |
| 908 | * if we failed to write out the inode then mark |
| 909 | * it dirty again so we'll try again later. |
| 910 | */ |
| 911 | if (error) |
| 912 | mark_inode_dirty_sync(inode); |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 913 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | return -error; |
| 915 | } |
| 916 | |
| 917 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 918 | xfs_fs_clear_inode( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | struct inode *inode) |
| 920 | { |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 921 | xfs_inode_t *ip = XFS_I(inode); |
Christoph Hellwig | 56d433e | 2005-09-05 08:23:54 +1000 | [diff] [blame] | 922 | |
Christoph Hellwig | 02ba71d | 2005-09-05 08:28:02 +1000 | [diff] [blame] | 923 | /* |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 924 | * 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] | 925 | * find an inode with di_mode == 0 but without IGET_CREATE set. |
| 926 | */ |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 927 | if (ip) { |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 928 | xfs_itrace_entry(ip); |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 929 | XFS_STATS_INC(vn_rele); |
| 930 | XFS_STATS_INC(vn_remove); |
| 931 | XFS_STATS_INC(vn_reclaim); |
| 932 | XFS_STATS_DEC(vn_active); |
Christoph Hellwig | 56d433e | 2005-09-05 08:23:54 +1000 | [diff] [blame] | 933 | |
Christoph Hellwig | 1543d79 | 2007-08-29 11:46:47 +1000 | [diff] [blame] | 934 | xfs_inactive(ip); |
| 935 | xfs_iflags_clear(ip, XFS_IMODIFIED); |
| 936 | if (xfs_reclaim(ip)) |
| 937 | panic("%s: cannot reclaim 0x%p\n", __FUNCTION__, inode); |
Christoph Hellwig | b3aea4e | 2007-08-29 11:44:37 +1000 | [diff] [blame] | 938 | } |
Christoph Hellwig | 56d433e | 2005-09-05 08:23:54 +1000 | [diff] [blame] | 939 | |
Christoph Hellwig | 739bfb2 | 2007-08-29 10:58:01 +1000 | [diff] [blame] | 940 | ASSERT(XFS_I(inode) == NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | /* |
| 944 | * Enqueue a work item to be picked up by the vfs xfssyncd thread. |
| 945 | * Doing this has two advantages: |
| 946 | * - It saves on stack space, which is tight in certain situations |
| 947 | * - It can be used (with care) as a mechanism to avoid deadlocks. |
| 948 | * Flushing while allocating in a full filesystem requires both. |
| 949 | */ |
| 950 | STATIC void |
| 951 | xfs_syncd_queue_work( |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 952 | struct xfs_mount *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | void *data, |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 954 | void (*syncer)(struct xfs_mount *, void *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 956 | struct bhv_vfs_sync_work *work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 958 | work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | INIT_LIST_HEAD(&work->w_list); |
| 960 | work->w_syncer = syncer; |
| 961 | work->w_data = data; |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 962 | work->w_mount = mp; |
| 963 | spin_lock(&mp->m_sync_lock); |
| 964 | list_add_tail(&work->w_list, &mp->m_sync_list); |
| 965 | spin_unlock(&mp->m_sync_lock); |
| 966 | wake_up_process(mp->m_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | /* |
| 970 | * Flush delayed allocate data, attempting to free up reserved space |
| 971 | * from existing allocations. At this point a new allocation attempt |
| 972 | * has failed with ENOSPC and we are in the process of scratching our |
| 973 | * heads, looking about for more room... |
| 974 | */ |
| 975 | STATIC void |
| 976 | xfs_flush_inode_work( |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 977 | struct xfs_mount *mp, |
| 978 | void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 980 | struct inode *inode = arg; |
| 981 | filemap_flush(inode->i_mapping); |
| 982 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | void |
| 986 | xfs_flush_inode( |
| 987 | xfs_inode_t *ip) |
| 988 | { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 989 | struct inode *inode = ip->i_vnode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
| 991 | igrab(inode); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 992 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work); |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 993 | delay(msecs_to_jiffies(500)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | /* |
| 997 | * This is the "bigger hammer" version of xfs_flush_inode_work... |
| 998 | * (IOW, "If at first you don't succeed, use a Bigger Hammer"). |
| 999 | */ |
| 1000 | STATIC void |
| 1001 | xfs_flush_device_work( |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1002 | struct xfs_mount *mp, |
| 1003 | void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1005 | struct inode *inode = arg; |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 1006 | sync_blockdev(mp->m_super->s_bdev); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1007 | iput(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | void |
| 1011 | xfs_flush_device( |
| 1012 | xfs_inode_t *ip) |
| 1013 | { |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 1014 | struct inode *inode = vn_to_inode(XFS_ITOV(ip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | |
| 1016 | igrab(inode); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1017 | xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work); |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1018 | delay(msecs_to_jiffies(500)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC); |
| 1020 | } |
| 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | STATIC void |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1023 | xfs_sync_worker( |
| 1024 | struct xfs_mount *mp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | void *unused) |
| 1026 | { |
| 1027 | int error; |
| 1028 | |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1029 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) |
| 1030 | error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR | |
| 1031 | SYNC_REFCACHE | SYNC_SUPER); |
| 1032 | mp->m_sync_seq++; |
| 1033 | wake_up(&mp->m_wait_single_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | STATIC int |
| 1037 | xfssyncd( |
| 1038 | void *arg) |
| 1039 | { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1040 | struct xfs_mount *mp = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | long timeleft; |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1042 | bhv_vfs_sync_work_t *work, *n; |
Christoph Hellwig | 4df08c5 | 2005-09-05 08:34:18 +1000 | [diff] [blame] | 1043 | LIST_HEAD (tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 1045 | set_freezable(); |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1046 | timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | for (;;) { |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1048 | timeleft = schedule_timeout_interruptible(timeleft); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | /* swsusp */ |
Christoph Lameter | 3e1d1d2 | 2005-06-24 23:13:50 -0700 | [diff] [blame] | 1050 | try_to_freeze(); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1051 | if (kthread_should_stop() && list_empty(&mp->m_sync_list)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | break; |
| 1053 | |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1054 | spin_lock(&mp->m_sync_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | /* |
| 1056 | * We can get woken by laptop mode, to do a sync - |
| 1057 | * that's the (only!) case where the list would be |
| 1058 | * empty with time remaining. |
| 1059 | */ |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1060 | if (!timeleft || list_empty(&mp->m_sync_list)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | if (!timeleft) |
Nishanth Aravamudan | 041e0e3 | 2005-09-10 00:27:23 -0700 | [diff] [blame] | 1062 | timeleft = xfs_syncd_centisecs * |
| 1063 | msecs_to_jiffies(10); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1064 | INIT_LIST_HEAD(&mp->m_sync_work.w_list); |
| 1065 | list_add_tail(&mp->m_sync_work.w_list, |
| 1066 | &mp->m_sync_list); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1068 | 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] | 1069 | list_move(&work->w_list, &tmp); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1070 | spin_unlock(&mp->m_sync_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
| 1072 | list_for_each_entry_safe(work, n, &tmp, w_list) { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1073 | (*work->w_syncer)(mp, work->w_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | list_del(&work->w_list); |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1075 | if (work == &mp->m_sync_work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | continue; |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1077 | kmem_free(work, sizeof(struct bhv_vfs_sync_work)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | return 0; |
| 1082 | } |
| 1083 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1085 | xfs_fs_put_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | struct super_block *sb) |
| 1087 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1088 | struct xfs_mount *mp = XFS_M(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | int error; |
| 1090 | |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1091 | kthread_stop(mp->m_sync_task); |
| 1092 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1093 | xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI); |
| 1094 | error = xfs_unmount(mp, 0, NULL); |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 1095 | if (error) |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1096 | printk("XFS: unmount got error=%d\n", error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1100 | xfs_fs_write_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | struct super_block *sb) |
| 1102 | { |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1103 | if (!(sb->s_flags & MS_RDONLY)) |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1104 | xfs_sync(XFS_M(sb), SYNC_FSDATA); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | sb->s_dirt = 0; |
| 1106 | } |
| 1107 | |
| 1108 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1109 | xfs_fs_sync_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | struct super_block *sb, |
| 1111 | int wait) |
| 1112 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1113 | struct xfs_mount *mp = XFS_M(sb); |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1114 | int error; |
| 1115 | int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 1117 | /* |
| 1118 | * Treat a sync operation like a freeze. This is to work |
| 1119 | * around a race in sync_inodes() which works in two phases |
| 1120 | * - an asynchronous flush, which can write out an inode |
| 1121 | * without waiting for file size updates to complete, and a |
| 1122 | * synchronous flush, which wont do anything because the |
| 1123 | * async flush removed the inode's dirty flag. Also |
| 1124 | * sync_inodes() will not see any files that just have |
| 1125 | * outstanding transactions to be flushed because we don't |
| 1126 | * dirty the Linux inode until after the transaction I/O |
| 1127 | * completes. |
| 1128 | */ |
| 1129 | if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) { |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 1130 | /* |
| 1131 | * First stage of freeze - no more writers will make progress |
| 1132 | * now we are here, so we flush delwri and delalloc buffers |
| 1133 | * here, then wait for all I/O to complete. Data is frozen at |
| 1134 | * that point. Metadata is not frozen, transactions can still |
| 1135 | * occur here so don't bother flushing the buftarg (i.e |
| 1136 | * SYNC_QUIESCE) because it'll just get dirty again. |
| 1137 | */ |
David Chinner | 516b2e7 | 2007-06-18 16:50:48 +1000 | [diff] [blame] | 1138 | flags = SYNC_DATA_QUIESCE; |
David Chinner | 2823945 | 2007-02-10 18:36:40 +1100 | [diff] [blame] | 1139 | } else |
Lachlan McIlroy | e893bff | 2007-10-12 11:13:35 +1000 | [diff] [blame] | 1140 | flags = SYNC_FSDATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1142 | error = xfs_sync(mp, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | sb->s_dirt = 0; |
| 1144 | |
| 1145 | if (unlikely(laptop_mode)) { |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1146 | int prev_sync_seq = mp->m_sync_seq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | |
| 1148 | /* |
| 1149 | * The disk must be active because we're syncing. |
| 1150 | * We schedule xfssyncd now (now that the disk is |
| 1151 | * active) instead of later (when it might not be). |
| 1152 | */ |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1153 | wake_up_process(mp->m_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | /* |
| 1155 | * We have to wait for the sync iteration to complete. |
| 1156 | * If we don't, the disk activity caused by the sync |
| 1157 | * will come after the sync is completed, and that |
| 1158 | * triggers another sync from laptop mode. |
| 1159 | */ |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1160 | wait_event(mp->m_wait_single_sync_task, |
| 1161 | mp->m_sync_seq != prev_sync_seq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | return -error; |
| 1165 | } |
| 1166 | |
| 1167 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1168 | xfs_fs_statfs( |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 1169 | struct dentry *dentry, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | struct kstatfs *statp) |
| 1171 | { |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 1172 | struct xfs_mount *mp = XFS_M(dentry->d_sb); |
| 1173 | xfs_sb_t *sbp = &mp->m_sb; |
| 1174 | __uint64_t fakeinos, id; |
| 1175 | xfs_extlen_t lsize; |
| 1176 | |
| 1177 | statp->f_type = XFS_SB_MAGIC; |
| 1178 | statp->f_namelen = MAXNAMELEN - 1; |
| 1179 | |
| 1180 | id = huge_encode_dev(mp->m_ddev_targp->bt_dev); |
| 1181 | statp->f_fsid.val[0] = (u32)id; |
| 1182 | statp->f_fsid.val[1] = (u32)(id >> 32); |
| 1183 | |
| 1184 | xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT); |
| 1185 | |
| 1186 | spin_lock(&mp->m_sb_lock); |
| 1187 | statp->f_bsize = sbp->sb_blocksize; |
| 1188 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; |
| 1189 | statp->f_blocks = sbp->sb_dblocks - lsize; |
| 1190 | statp->f_bfree = statp->f_bavail = |
| 1191 | sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); |
| 1192 | fakeinos = statp->f_bfree << sbp->sb_inopblog; |
| 1193 | #if XFS_BIG_INUMS |
| 1194 | fakeinos += mp->m_inoadd; |
| 1195 | #endif |
| 1196 | statp->f_files = |
| 1197 | MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER); |
| 1198 | if (mp->m_maxicount) |
| 1199 | #if XFS_BIG_INUMS |
| 1200 | if (!mp->m_inoadd) |
| 1201 | #endif |
| 1202 | statp->f_files = min_t(typeof(statp->f_files), |
| 1203 | statp->f_files, |
| 1204 | mp->m_maxicount); |
| 1205 | statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree); |
| 1206 | spin_unlock(&mp->m_sb_lock); |
| 1207 | |
| 1208 | XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp); |
| 1209 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1213 | xfs_fs_remount( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | struct super_block *sb, |
| 1215 | int *flags, |
| 1216 | char *options) |
| 1217 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1218 | struct xfs_mount *mp = XFS_M(sb); |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 1219 | struct xfs_mount_args *args = xfs_args_allocate(sb, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | int error; |
| 1221 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1222 | error = xfs_parseargs(mp, options, args, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | if (!error) |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1224 | error = xfs_mntupdate(mp, flags, args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | kmem_free(args, sizeof(*args)); |
| 1226 | return -error; |
| 1227 | } |
| 1228 | |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 1229 | /* |
| 1230 | * Second stage of a freeze. The data is already frozen so we only |
| 1231 | * need to take care of themetadata. Once that's done write a dummy |
| 1232 | * record to dirty the log in case of a crash while frozen. |
| 1233 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | STATIC void |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1235 | xfs_fs_lockfs( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | struct super_block *sb) |
| 1237 | { |
Christoph Hellwig | 9909c4a | 2007-10-11 18:11:14 +1000 | [diff] [blame] | 1238 | struct xfs_mount *mp = XFS_M(sb); |
| 1239 | |
| 1240 | xfs_attr_quiesce(mp); |
| 1241 | xfs_fs_log_dummy(mp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1245 | xfs_fs_show_options( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | struct seq_file *m, |
| 1247 | struct vfsmount *mnt) |
| 1248 | { |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1249 | return -xfs_showargs(XFS_M(mnt->mnt_sb), m); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1253 | xfs_fs_quotasync( |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 1254 | struct super_block *sb, |
| 1255 | int type) |
| 1256 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1257 | return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL); |
Nathan Scott | ee34807 | 2005-11-02 10:32:38 +1100 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1261 | xfs_fs_getxstate( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | struct super_block *sb, |
| 1263 | struct fs_quota_stat *fqs) |
| 1264 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1265 | 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] | 1266 | } |
| 1267 | |
| 1268 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1269 | xfs_fs_setxstate( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | struct super_block *sb, |
| 1271 | unsigned int flags, |
| 1272 | int op) |
| 1273 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1274 | return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1278 | xfs_fs_getxquota( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | struct super_block *sb, |
| 1280 | int type, |
| 1281 | qid_t id, |
| 1282 | struct fs_disk_quota *fdq) |
| 1283 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1284 | return -XFS_QM_QUOTACTL(XFS_M(sb), |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1285 | (type == USRQUOTA) ? Q_XGETQUOTA : |
| 1286 | ((type == GRPQUOTA) ? Q_XGETGQUOTA : |
| 1287 | Q_XGETPQUOTA), id, (caddr_t)fdq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1291 | xfs_fs_setxquota( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | struct super_block *sb, |
| 1293 | int type, |
| 1294 | qid_t id, |
| 1295 | struct fs_disk_quota *fdq) |
| 1296 | { |
Christoph Hellwig | b09cc77 | 2007-08-30 17:19:57 +1000 | [diff] [blame] | 1297 | return -XFS_QM_QUOTACTL(XFS_M(sb), |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1298 | (type == USRQUOTA) ? Q_XSETQLIM : |
| 1299 | ((type == GRPQUOTA) ? Q_XSETGQLIM : |
| 1300 | Q_XSETPQLIM), id, (caddr_t)fdq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1304 | xfs_fs_fill_super( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | struct super_block *sb, |
| 1306 | void *data, |
| 1307 | int silent) |
| 1308 | { |
Christoph Hellwig | 0a74cd1 | 2007-08-29 11:53:12 +1000 | [diff] [blame] | 1309 | struct inode *rootvp; |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1310 | struct xfs_mount *mp = NULL; |
Nathan Scott | 764d1f8 | 2006-03-31 13:04:17 +1000 | [diff] [blame] | 1311 | struct xfs_mount_args *args = xfs_args_allocate(sb, silent); |
Nathan Scott | b83bd13 | 2006-06-09 16:48:30 +1000 | [diff] [blame] | 1312 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1314 | mp = xfs_mount_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1316 | INIT_LIST_HEAD(&mp->m_sync_list); |
| 1317 | spin_lock_init(&mp->m_sync_lock); |
| 1318 | init_waitqueue_head(&mp->m_wait_single_sync_task); |
| 1319 | |
Christoph Hellwig | b267ce9 | 2007-08-30 17:21:30 +1000 | [diff] [blame] | 1320 | mp->m_super = sb; |
| 1321 | sb->s_fs_info = mp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
Christoph Hellwig | bd186aa | 2007-08-30 17:21:12 +1000 | [diff] [blame] | 1323 | if (sb->s_flags & MS_RDONLY) |
| 1324 | mp->m_flags |= XFS_MOUNT_RDONLY; |
| 1325 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1326 | error = xfs_parseargs(mp, (char *)data, args, 0); |
| 1327 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | goto fail_vfsop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | |
| 1330 | sb_min_blocksize(sb, BBSIZE); |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1331 | sb->s_export_op = &xfs_export_operations; |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1332 | sb->s_qcop = &xfs_quotactl_operations; |
| 1333 | sb->s_op = &xfs_super_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1335 | error = xfs_mount(mp, args, NULL); |
| 1336 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | goto fail_vfsop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | sb->s_dirt = 1; |
Christoph Hellwig | 4ca488e | 2007-10-11 18:09:40 +1000 | [diff] [blame] | 1340 | sb->s_magic = XFS_SB_MAGIC; |
| 1341 | sb->s_blocksize = mp->m_sb.sb_blocksize; |
| 1342 | sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits); |
| 1344 | sb->s_time_gran = 1; |
| 1345 | set_posix_acl_flag(sb); |
| 1346 | |
Christoph Hellwig | cbc89dc | 2008-02-05 12:14:01 +1100 | [diff] [blame] | 1347 | rootvp = igrab(mp->m_rootip->i_vnode); |
| 1348 | if (!rootvp) { |
| 1349 | error = ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | goto fail_unmount; |
Christoph Hellwig | cbc89dc | 2008-02-05 12:14:01 +1100 | [diff] [blame] | 1351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
Nathan Scott | ec86dc0 | 2006-03-17 17:25:36 +1100 | [diff] [blame] | 1353 | sb->s_root = d_alloc_root(vn_to_inode(rootvp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | if (!sb->s_root) { |
| 1355 | error = ENOMEM; |
| 1356 | goto fail_vnrele; |
| 1357 | } |
| 1358 | if (is_bad_inode(sb->s_root->d_inode)) { |
| 1359 | error = EINVAL; |
| 1360 | goto fail_vnrele; |
| 1361 | } |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1362 | |
| 1363 | mp->m_sync_work.w_syncer = xfs_sync_worker; |
| 1364 | mp->m_sync_work.w_mount = mp; |
| 1365 | mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd"); |
| 1366 | if (IS_ERR(mp->m_sync_task)) { |
| 1367 | error = -PTR_ERR(mp->m_sync_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | goto fail_vnrele; |
Christoph Hellwig | 7439449 | 2007-08-30 17:21:22 +1000 | [diff] [blame] | 1369 | } |
| 1370 | |
Lachlan McIlroy | cf441ee | 2008-02-07 16:42:19 +1100 | [diff] [blame] | 1371 | xfs_itrace_exit(XFS_I(sb->s_root->d_inode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | |
| 1373 | kmem_free(args, sizeof(*args)); |
| 1374 | return 0; |
| 1375 | |
| 1376 | fail_vnrele: |
| 1377 | if (sb->s_root) { |
| 1378 | dput(sb->s_root); |
| 1379 | sb->s_root = NULL; |
| 1380 | } else { |
| 1381 | VN_RELE(rootvp); |
| 1382 | } |
| 1383 | |
| 1384 | fail_unmount: |
Christoph Hellwig | 745f691 | 2007-08-30 17:20:39 +1000 | [diff] [blame] | 1385 | xfs_unmount(mp, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
| 1387 | fail_vfsop: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | kmem_free(args, sizeof(*args)); |
| 1389 | return -error; |
| 1390 | } |
| 1391 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1392 | STATIC int |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1393 | xfs_fs_get_sb( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | struct file_system_type *fs_type, |
| 1395 | int flags, |
| 1396 | const char *dev_name, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1397 | void *data, |
| 1398 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | { |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 1400 | return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super, |
| 1401 | mnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 1404 | static struct super_operations xfs_super_operations = { |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1405 | .alloc_inode = xfs_fs_alloc_inode, |
| 1406 | .destroy_inode = xfs_fs_destroy_inode, |
| 1407 | .write_inode = xfs_fs_write_inode, |
| 1408 | .clear_inode = xfs_fs_clear_inode, |
| 1409 | .put_super = xfs_fs_put_super, |
| 1410 | .write_super = xfs_fs_write_super, |
| 1411 | .sync_fs = xfs_fs_sync_super, |
| 1412 | .write_super_lockfs = xfs_fs_lockfs, |
| 1413 | .statfs = xfs_fs_statfs, |
| 1414 | .remount_fs = xfs_fs_remount, |
| 1415 | .show_options = xfs_fs_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | }; |
| 1417 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 1418 | static struct quotactl_ops xfs_quotactl_operations = { |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1419 | .quota_sync = xfs_fs_quotasync, |
| 1420 | .get_xstate = xfs_fs_getxstate, |
| 1421 | .set_xstate = xfs_fs_setxstate, |
| 1422 | .get_xquota = xfs_fs_getxquota, |
| 1423 | .set_xquota = xfs_fs_setxquota, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1424 | }; |
| 1425 | |
Andrew Morton | 5085b60 | 2007-02-20 13:57:47 -0800 | [diff] [blame] | 1426 | static struct file_system_type xfs_fs_type = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | .owner = THIS_MODULE, |
| 1428 | .name = "xfs", |
Nathan Scott | a50cd26 | 2006-03-14 14:06:18 +1100 | [diff] [blame] | 1429 | .get_sb = xfs_fs_get_sb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | .kill_sb = kill_block_super, |
| 1431 | .fs_flags = FS_REQUIRES_DEV, |
| 1432 | }; |
| 1433 | |
| 1434 | |
| 1435 | STATIC int __init |
| 1436 | init_xfs_fs( void ) |
| 1437 | { |
| 1438 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | static char message[] __initdata = KERN_INFO \ |
| 1440 | XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n"; |
| 1441 | |
| 1442 | printk(message); |
| 1443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | ktrace_init(64); |
| 1445 | |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 1446 | error = xfs_init_zones(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | if (error < 0) |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 1448 | goto undo_zones; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 1450 | error = xfs_buf_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | if (error < 0) |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 1452 | goto undo_buffers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
| 1454 | vn_init(); |
| 1455 | xfs_init(); |
| 1456 | uuid_init(); |
| 1457 | vfs_initquota(); |
| 1458 | |
| 1459 | error = register_filesystem(&xfs_fs_type); |
| 1460 | if (error) |
| 1461 | goto undo_register; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1462 | return 0; |
| 1463 | |
| 1464 | undo_register: |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 1465 | xfs_buf_terminate(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 1467 | undo_buffers: |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 1468 | xfs_destroy_zones(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
Christoph Hellwig | 0829c36 | 2005-09-02 16:58:49 +1000 | [diff] [blame] | 1470 | undo_zones: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | return error; |
| 1472 | } |
| 1473 | |
| 1474 | STATIC void __exit |
| 1475 | exit_xfs_fs( void ) |
| 1476 | { |
| 1477 | vfs_exitquota(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | unregister_filesystem(&xfs_fs_type); |
| 1479 | xfs_cleanup(); |
Nathan Scott | ce8e922 | 2006-01-11 15:39:08 +1100 | [diff] [blame] | 1480 | xfs_buf_terminate(); |
Nathan Scott | 8758280 | 2006-03-14 13:18:19 +1100 | [diff] [blame] | 1481 | xfs_destroy_zones(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | ktrace_uninit(); |
| 1483 | } |
| 1484 | |
| 1485 | module_init(init_xfs_fs); |
| 1486 | module_exit(exit_xfs_fs); |
| 1487 | |
| 1488 | MODULE_AUTHOR("Silicon Graphics, Inc."); |
| 1489 | MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled"); |
| 1490 | MODULE_LICENSE("GPL"); |