xfs_super.c 56 KB

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