xfs_super.c 50 KB

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