xfs_super.c 38 KB

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