xfs_super.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168
  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 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_excl(name, 0, 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_excl(bdev);
  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. * Attempt to flush the inode, this will actually fail
  804. * if the inode is pinned, but we dirty the inode again
  805. * at the point when it is unpinned after a log write,
  806. * since this is when the inode itself becomes flushable.
  807. */
  808. STATIC int
  809. xfs_fs_write_inode(
  810. struct inode *inode,
  811. int sync)
  812. {
  813. int error = 0;
  814. int flags = 0;
  815. xfs_itrace_entry(XFS_I(inode));
  816. if (sync) {
  817. filemap_fdatawait(inode->i_mapping);
  818. flags |= FLUSH_SYNC;
  819. }
  820. error = xfs_inode_flush(XFS_I(inode), flags);
  821. /*
  822. * if we failed to write out the inode then mark
  823. * it dirty again so we'll try again later.
  824. */
  825. if (error)
  826. mark_inode_dirty_sync(inode);
  827. return -error;
  828. }
  829. STATIC void
  830. xfs_fs_clear_inode(
  831. struct inode *inode)
  832. {
  833. xfs_inode_t *ip = XFS_I(inode);
  834. /*
  835. * ip can be null when xfs_iget_core calls xfs_idestroy if we
  836. * find an inode with di_mode == 0 but without IGET_CREATE set.
  837. */
  838. if (ip) {
  839. xfs_itrace_entry(ip);
  840. XFS_STATS_INC(vn_rele);
  841. XFS_STATS_INC(vn_remove);
  842. XFS_STATS_INC(vn_reclaim);
  843. XFS_STATS_DEC(vn_active);
  844. xfs_inactive(ip);
  845. xfs_iflags_clear(ip, XFS_IMODIFIED);
  846. if (xfs_reclaim(ip))
  847. panic("%s: cannot reclaim 0x%p\n", __func__, inode);
  848. }
  849. ASSERT(XFS_I(inode) == NULL);
  850. }
  851. /*
  852. * Enqueue a work item to be picked up by the vfs xfssyncd thread.
  853. * Doing this has two advantages:
  854. * - It saves on stack space, which is tight in certain situations
  855. * - It can be used (with care) as a mechanism to avoid deadlocks.
  856. * Flushing while allocating in a full filesystem requires both.
  857. */
  858. STATIC void
  859. xfs_syncd_queue_work(
  860. struct xfs_mount *mp,
  861. void *data,
  862. void (*syncer)(struct xfs_mount *, void *))
  863. {
  864. struct bhv_vfs_sync_work *work;
  865. work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
  866. INIT_LIST_HEAD(&work->w_list);
  867. work->w_syncer = syncer;
  868. work->w_data = data;
  869. work->w_mount = mp;
  870. spin_lock(&mp->m_sync_lock);
  871. list_add_tail(&work->w_list, &mp->m_sync_list);
  872. spin_unlock(&mp->m_sync_lock);
  873. wake_up_process(mp->m_sync_task);
  874. }
  875. /*
  876. * Flush delayed allocate data, attempting to free up reserved space
  877. * from existing allocations. At this point a new allocation attempt
  878. * has failed with ENOSPC and we are in the process of scratching our
  879. * heads, looking about for more room...
  880. */
  881. STATIC void
  882. xfs_flush_inode_work(
  883. struct xfs_mount *mp,
  884. void *arg)
  885. {
  886. struct inode *inode = arg;
  887. filemap_flush(inode->i_mapping);
  888. iput(inode);
  889. }
  890. void
  891. xfs_flush_inode(
  892. xfs_inode_t *ip)
  893. {
  894. struct inode *inode = VFS_I(ip);
  895. igrab(inode);
  896. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
  897. delay(msecs_to_jiffies(500));
  898. }
  899. /*
  900. * This is the "bigger hammer" version of xfs_flush_inode_work...
  901. * (IOW, "If at first you don't succeed, use a Bigger Hammer").
  902. */
  903. STATIC void
  904. xfs_flush_device_work(
  905. struct xfs_mount *mp,
  906. void *arg)
  907. {
  908. struct inode *inode = arg;
  909. sync_blockdev(mp->m_super->s_bdev);
  910. iput(inode);
  911. }
  912. void
  913. xfs_flush_device(
  914. xfs_inode_t *ip)
  915. {
  916. struct inode *inode = VFS_I(ip);
  917. igrab(inode);
  918. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
  919. delay(msecs_to_jiffies(500));
  920. xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
  921. }
  922. STATIC void
  923. xfs_sync_worker(
  924. struct xfs_mount *mp,
  925. void *unused)
  926. {
  927. int error;
  928. if (!(mp->m_flags & XFS_MOUNT_RDONLY))
  929. error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR);
  930. mp->m_sync_seq++;
  931. wake_up(&mp->m_wait_single_sync_task);
  932. }
  933. STATIC int
  934. xfssyncd(
  935. void *arg)
  936. {
  937. struct xfs_mount *mp = arg;
  938. long timeleft;
  939. bhv_vfs_sync_work_t *work, *n;
  940. LIST_HEAD (tmp);
  941. set_freezable();
  942. timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
  943. for (;;) {
  944. timeleft = schedule_timeout_interruptible(timeleft);
  945. /* swsusp */
  946. try_to_freeze();
  947. if (kthread_should_stop() && list_empty(&mp->m_sync_list))
  948. break;
  949. spin_lock(&mp->m_sync_lock);
  950. /*
  951. * We can get woken by laptop mode, to do a sync -
  952. * that's the (only!) case where the list would be
  953. * empty with time remaining.
  954. */
  955. if (!timeleft || list_empty(&mp->m_sync_list)) {
  956. if (!timeleft)
  957. timeleft = xfs_syncd_centisecs *
  958. msecs_to_jiffies(10);
  959. INIT_LIST_HEAD(&mp->m_sync_work.w_list);
  960. list_add_tail(&mp->m_sync_work.w_list,
  961. &mp->m_sync_list);
  962. }
  963. list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
  964. list_move(&work->w_list, &tmp);
  965. spin_unlock(&mp->m_sync_lock);
  966. list_for_each_entry_safe(work, n, &tmp, w_list) {
  967. (*work->w_syncer)(mp, work->w_data);
  968. list_del(&work->w_list);
  969. if (work == &mp->m_sync_work)
  970. continue;
  971. kmem_free(work);
  972. }
  973. }
  974. return 0;
  975. }
  976. STATIC void
  977. xfs_free_fsname(
  978. struct xfs_mount *mp)
  979. {
  980. kfree(mp->m_fsname);
  981. kfree(mp->m_rtname);
  982. kfree(mp->m_logname);
  983. }
  984. STATIC void
  985. xfs_fs_put_super(
  986. struct super_block *sb)
  987. {
  988. struct xfs_mount *mp = XFS_M(sb);
  989. struct xfs_inode *rip = mp->m_rootip;
  990. int unmount_event_flags = 0;
  991. int error;
  992. kthread_stop(mp->m_sync_task);
  993. xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
  994. #ifdef HAVE_DMAPI
  995. if (mp->m_flags & XFS_MOUNT_DMAPI) {
  996. unmount_event_flags =
  997. (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
  998. 0 : DM_FLAGS_UNWANTED;
  999. /*
  1000. * Ignore error from dmapi here, first unmount is not allowed
  1001. * to fail anyway, and second we wouldn't want to fail a
  1002. * unmount because of dmapi.
  1003. */
  1004. XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
  1005. NULL, NULL, 0, 0, unmount_event_flags);
  1006. }
  1007. #endif
  1008. /*
  1009. * Blow away any referenced inode in the filestreams cache.
  1010. * This can and will cause log traffic as inodes go inactive
  1011. * here.
  1012. */
  1013. xfs_filestream_unmount(mp);
  1014. XFS_bflush(mp->m_ddev_targp);
  1015. error = xfs_unmount_flush(mp, 0);
  1016. WARN_ON(error);
  1017. IRELE(rip);
  1018. /*
  1019. * If we're forcing a shutdown, typically because of a media error,
  1020. * we want to make sure we invalidate dirty pages that belong to
  1021. * referenced vnodes as well.
  1022. */
  1023. if (XFS_FORCED_SHUTDOWN(mp)) {
  1024. error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
  1025. ASSERT(error != EFSCORRUPTED);
  1026. }
  1027. if (mp->m_flags & XFS_MOUNT_DMAPI) {
  1028. XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
  1029. unmount_event_flags);
  1030. }
  1031. xfs_unmountfs(mp);
  1032. xfs_icsb_destroy_counters(mp);
  1033. xfs_close_devices(mp);
  1034. xfs_qmops_put(mp);
  1035. xfs_dmops_put(mp);
  1036. xfs_free_fsname(mp);
  1037. kfree(mp);
  1038. }
  1039. STATIC void
  1040. xfs_fs_write_super(
  1041. struct super_block *sb)
  1042. {
  1043. if (!(sb->s_flags & MS_RDONLY))
  1044. xfs_sync(XFS_M(sb), SYNC_FSDATA);
  1045. sb->s_dirt = 0;
  1046. }
  1047. STATIC int
  1048. xfs_fs_sync_super(
  1049. struct super_block *sb,
  1050. int wait)
  1051. {
  1052. struct xfs_mount *mp = XFS_M(sb);
  1053. int error;
  1054. int flags;
  1055. /*
  1056. * Treat a sync operation like a freeze. This is to work
  1057. * around a race in sync_inodes() which works in two phases
  1058. * - an asynchronous flush, which can write out an inode
  1059. * without waiting for file size updates to complete, and a
  1060. * synchronous flush, which wont do anything because the
  1061. * async flush removed the inode's dirty flag. Also
  1062. * sync_inodes() will not see any files that just have
  1063. * outstanding transactions to be flushed because we don't
  1064. * dirty the Linux inode until after the transaction I/O
  1065. * completes.
  1066. */
  1067. if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
  1068. /*
  1069. * First stage of freeze - no more writers will make progress
  1070. * now we are here, so we flush delwri and delalloc buffers
  1071. * here, then wait for all I/O to complete. Data is frozen at
  1072. * that point. Metadata is not frozen, transactions can still
  1073. * occur here so don't bother flushing the buftarg (i.e
  1074. * SYNC_QUIESCE) because it'll just get dirty again.
  1075. */
  1076. flags = SYNC_DATA_QUIESCE;
  1077. } else
  1078. flags = SYNC_FSDATA;
  1079. error = xfs_sync(mp, flags);
  1080. sb->s_dirt = 0;
  1081. if (unlikely(laptop_mode)) {
  1082. int prev_sync_seq = mp->m_sync_seq;
  1083. /*
  1084. * The disk must be active because we're syncing.
  1085. * We schedule xfssyncd now (now that the disk is
  1086. * active) instead of later (when it might not be).
  1087. */
  1088. wake_up_process(mp->m_sync_task);
  1089. /*
  1090. * We have to wait for the sync iteration to complete.
  1091. * If we don't, the disk activity caused by the sync
  1092. * will come after the sync is completed, and that
  1093. * triggers another sync from laptop mode.
  1094. */
  1095. wait_event(mp->m_wait_single_sync_task,
  1096. mp->m_sync_seq != prev_sync_seq);
  1097. }
  1098. return -error;
  1099. }
  1100. STATIC int
  1101. xfs_fs_statfs(
  1102. struct dentry *dentry,
  1103. struct kstatfs *statp)
  1104. {
  1105. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  1106. xfs_sb_t *sbp = &mp->m_sb;
  1107. __uint64_t fakeinos, id;
  1108. xfs_extlen_t lsize;
  1109. statp->f_type = XFS_SB_MAGIC;
  1110. statp->f_namelen = MAXNAMELEN - 1;
  1111. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  1112. statp->f_fsid.val[0] = (u32)id;
  1113. statp->f_fsid.val[1] = (u32)(id >> 32);
  1114. xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
  1115. spin_lock(&mp->m_sb_lock);
  1116. statp->f_bsize = sbp->sb_blocksize;
  1117. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  1118. statp->f_blocks = sbp->sb_dblocks - lsize;
  1119. statp->f_bfree = statp->f_bavail =
  1120. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  1121. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  1122. #if XFS_BIG_INUMS
  1123. fakeinos += mp->m_inoadd;
  1124. #endif
  1125. statp->f_files =
  1126. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  1127. if (mp->m_maxicount)
  1128. #if XFS_BIG_INUMS
  1129. if (!mp->m_inoadd)
  1130. #endif
  1131. statp->f_files = min_t(typeof(statp->f_files),
  1132. statp->f_files,
  1133. mp->m_maxicount);
  1134. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  1135. spin_unlock(&mp->m_sb_lock);
  1136. XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
  1137. return 0;
  1138. }
  1139. STATIC int
  1140. xfs_fs_remount(
  1141. struct super_block *sb,
  1142. int *flags,
  1143. char *options)
  1144. {
  1145. struct xfs_mount *mp = XFS_M(sb);
  1146. substring_t args[MAX_OPT_ARGS];
  1147. char *p;
  1148. while ((p = strsep(&options, ",")) != NULL) {
  1149. int token;
  1150. if (!*p)
  1151. continue;
  1152. token = match_token(p, tokens, args);
  1153. switch (token) {
  1154. case Opt_barrier:
  1155. mp->m_flags |= XFS_MOUNT_BARRIER;
  1156. /*
  1157. * Test if barriers are actually working if we can,
  1158. * else delay this check until the filesystem is
  1159. * marked writeable.
  1160. */
  1161. if (!(mp->m_flags & XFS_MOUNT_RDONLY))
  1162. xfs_mountfs_check_barriers(mp);
  1163. break;
  1164. case Opt_nobarrier:
  1165. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1166. break;
  1167. default:
  1168. printk(KERN_INFO
  1169. "XFS: mount option \"%s\" not supported for remount\n", p);
  1170. return -EINVAL;
  1171. }
  1172. }
  1173. /* rw/ro -> rw */
  1174. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1175. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1176. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1177. xfs_mountfs_check_barriers(mp);
  1178. }
  1179. /* rw -> ro */
  1180. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1181. xfs_filestream_flush(mp);
  1182. xfs_sync(mp, SYNC_DATA_QUIESCE);
  1183. xfs_attr_quiesce(mp);
  1184. mp->m_flags |= XFS_MOUNT_RDONLY;
  1185. }
  1186. return 0;
  1187. }
  1188. /*
  1189. * Second stage of a freeze. The data is already frozen so we only
  1190. * need to take care of themetadata. Once that's done write a dummy
  1191. * record to dirty the log in case of a crash while frozen.
  1192. */
  1193. STATIC void
  1194. xfs_fs_lockfs(
  1195. struct super_block *sb)
  1196. {
  1197. struct xfs_mount *mp = XFS_M(sb);
  1198. xfs_attr_quiesce(mp);
  1199. xfs_fs_log_dummy(mp);
  1200. }
  1201. STATIC int
  1202. xfs_fs_show_options(
  1203. struct seq_file *m,
  1204. struct vfsmount *mnt)
  1205. {
  1206. return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
  1207. }
  1208. STATIC int
  1209. xfs_fs_quotasync(
  1210. struct super_block *sb,
  1211. int type)
  1212. {
  1213. return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
  1214. }
  1215. STATIC int
  1216. xfs_fs_getxstate(
  1217. struct super_block *sb,
  1218. struct fs_quota_stat *fqs)
  1219. {
  1220. return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
  1221. }
  1222. STATIC int
  1223. xfs_fs_setxstate(
  1224. struct super_block *sb,
  1225. unsigned int flags,
  1226. int op)
  1227. {
  1228. return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
  1229. }
  1230. STATIC int
  1231. xfs_fs_getxquota(
  1232. struct super_block *sb,
  1233. int type,
  1234. qid_t id,
  1235. struct fs_disk_quota *fdq)
  1236. {
  1237. return -XFS_QM_QUOTACTL(XFS_M(sb),
  1238. (type == USRQUOTA) ? Q_XGETQUOTA :
  1239. ((type == GRPQUOTA) ? Q_XGETGQUOTA :
  1240. Q_XGETPQUOTA), id, (caddr_t)fdq);
  1241. }
  1242. STATIC int
  1243. xfs_fs_setxquota(
  1244. struct super_block *sb,
  1245. int type,
  1246. qid_t id,
  1247. struct fs_disk_quota *fdq)
  1248. {
  1249. return -XFS_QM_QUOTACTL(XFS_M(sb),
  1250. (type == USRQUOTA) ? Q_XSETQLIM :
  1251. ((type == GRPQUOTA) ? Q_XSETGQLIM :
  1252. Q_XSETPQLIM), id, (caddr_t)fdq);
  1253. }
  1254. /*
  1255. * This function fills in xfs_mount_t fields based on mount args.
  1256. * Note: the superblock has _not_ yet been read in.
  1257. */
  1258. STATIC int
  1259. xfs_start_flags(
  1260. struct xfs_mount_args *ap,
  1261. struct xfs_mount *mp)
  1262. {
  1263. int error;
  1264. /* Values are in BBs */
  1265. if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  1266. /*
  1267. * At this point the superblock has not been read
  1268. * in, therefore we do not know the block size.
  1269. * Before the mount call ends we will convert
  1270. * these to FSBs.
  1271. */
  1272. mp->m_dalign = ap->sunit;
  1273. mp->m_swidth = ap->swidth;
  1274. }
  1275. if (ap->logbufs != -1 &&
  1276. ap->logbufs != 0 &&
  1277. (ap->logbufs < XLOG_MIN_ICLOGS ||
  1278. ap->logbufs > XLOG_MAX_ICLOGS)) {
  1279. cmn_err(CE_WARN,
  1280. "XFS: invalid logbufs value: %d [not %d-%d]",
  1281. ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  1282. return XFS_ERROR(EINVAL);
  1283. }
  1284. mp->m_logbufs = ap->logbufs;
  1285. if (ap->logbufsize != -1 &&
  1286. ap->logbufsize != 0 &&
  1287. (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
  1288. ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
  1289. !is_power_of_2(ap->logbufsize))) {
  1290. cmn_err(CE_WARN,
  1291. "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  1292. ap->logbufsize);
  1293. return XFS_ERROR(EINVAL);
  1294. }
  1295. error = ENOMEM;
  1296. mp->m_logbsize = ap->logbufsize;
  1297. mp->m_fsname_len = strlen(ap->fsname) + 1;
  1298. mp->m_fsname = kstrdup(ap->fsname, GFP_KERNEL);
  1299. if (!mp->m_fsname)
  1300. goto out;
  1301. if (ap->rtname[0]) {
  1302. mp->m_rtname = kstrdup(ap->rtname, GFP_KERNEL);
  1303. if (!mp->m_rtname)
  1304. goto out_free_fsname;
  1305. }
  1306. if (ap->logname[0]) {
  1307. mp->m_logname = kstrdup(ap->logname, GFP_KERNEL);
  1308. if (!mp->m_logname)
  1309. goto out_free_rtname;
  1310. }
  1311. if (ap->flags & XFSMNT_WSYNC)
  1312. mp->m_flags |= XFS_MOUNT_WSYNC;
  1313. #if XFS_BIG_INUMS
  1314. if (ap->flags & XFSMNT_INO64) {
  1315. mp->m_flags |= XFS_MOUNT_INO64;
  1316. mp->m_inoadd = XFS_INO64_OFFSET;
  1317. }
  1318. #endif
  1319. if (ap->flags & XFSMNT_RETERR)
  1320. mp->m_flags |= XFS_MOUNT_RETERR;
  1321. if (ap->flags & XFSMNT_NOALIGN)
  1322. mp->m_flags |= XFS_MOUNT_NOALIGN;
  1323. if (ap->flags & XFSMNT_SWALLOC)
  1324. mp->m_flags |= XFS_MOUNT_SWALLOC;
  1325. if (ap->flags & XFSMNT_OSYNCISOSYNC)
  1326. mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
  1327. if (ap->flags & XFSMNT_32BITINODES)
  1328. mp->m_flags |= XFS_MOUNT_32BITINODES;
  1329. if (ap->flags & XFSMNT_IOSIZE) {
  1330. if (ap->iosizelog > XFS_MAX_IO_LOG ||
  1331. ap->iosizelog < XFS_MIN_IO_LOG) {
  1332. cmn_err(CE_WARN,
  1333. "XFS: invalid log iosize: %d [not %d-%d]",
  1334. ap->iosizelog, XFS_MIN_IO_LOG,
  1335. XFS_MAX_IO_LOG);
  1336. return XFS_ERROR(EINVAL);
  1337. }
  1338. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  1339. mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
  1340. }
  1341. if (ap->flags & XFSMNT_IKEEP)
  1342. mp->m_flags |= XFS_MOUNT_IKEEP;
  1343. if (ap->flags & XFSMNT_DIRSYNC)
  1344. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  1345. if (ap->flags & XFSMNT_ATTR2)
  1346. mp->m_flags |= XFS_MOUNT_ATTR2;
  1347. if (ap->flags & XFSMNT_NOATTR2)
  1348. mp->m_flags |= XFS_MOUNT_NOATTR2;
  1349. if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
  1350. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  1351. /*
  1352. * no recovery flag requires a read-only mount
  1353. */
  1354. if (ap->flags & XFSMNT_NORECOVERY) {
  1355. if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
  1356. cmn_err(CE_WARN,
  1357. "XFS: tried to mount a FS read-write without recovery!");
  1358. return XFS_ERROR(EINVAL);
  1359. }
  1360. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  1361. }
  1362. if (ap->flags & XFSMNT_NOUUID)
  1363. mp->m_flags |= XFS_MOUNT_NOUUID;
  1364. if (ap->flags & XFSMNT_BARRIER)
  1365. mp->m_flags |= XFS_MOUNT_BARRIER;
  1366. else
  1367. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1368. if (ap->flags2 & XFSMNT2_FILESTREAMS)
  1369. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  1370. if (ap->flags & XFSMNT_DMAPI)
  1371. mp->m_flags |= XFS_MOUNT_DMAPI;
  1372. return 0;
  1373. out_free_rtname:
  1374. kfree(mp->m_rtname);
  1375. out_free_fsname:
  1376. kfree(mp->m_fsname);
  1377. out:
  1378. return error;
  1379. }
  1380. /*
  1381. * This function fills in xfs_mount_t fields based on mount args.
  1382. * Note: the superblock _has_ now been read in.
  1383. */
  1384. STATIC int
  1385. xfs_finish_flags(
  1386. struct xfs_mount_args *ap,
  1387. struct xfs_mount *mp)
  1388. {
  1389. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1390. /* Fail a mount where the logbuf is smaller then the log stripe */
  1391. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1392. if ((ap->logbufsize <= 0) &&
  1393. (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
  1394. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1395. } else if (ap->logbufsize > 0 &&
  1396. ap->logbufsize < mp->m_sb.sb_logsunit) {
  1397. cmn_err(CE_WARN,
  1398. "XFS: logbuf size must be greater than or equal to log stripe size");
  1399. return XFS_ERROR(EINVAL);
  1400. }
  1401. } else {
  1402. /* Fail a mount if the logbuf is larger than 32K */
  1403. if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
  1404. cmn_err(CE_WARN,
  1405. "XFS: logbuf size for version 1 logs must be 16K or 32K");
  1406. return XFS_ERROR(EINVAL);
  1407. }
  1408. }
  1409. /*
  1410. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1411. * told by noattr2 to turn it off
  1412. */
  1413. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1414. !(ap->flags & XFSMNT_NOATTR2))
  1415. mp->m_flags |= XFS_MOUNT_ATTR2;
  1416. /*
  1417. * prohibit r/w mounts of read-only filesystems
  1418. */
  1419. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1420. cmn_err(CE_WARN,
  1421. "XFS: cannot mount a read-only filesystem as read-write");
  1422. return XFS_ERROR(EROFS);
  1423. }
  1424. /*
  1425. * check for shared mount.
  1426. */
  1427. if (ap->flags & XFSMNT_SHARED) {
  1428. if (!xfs_sb_version_hasshared(&mp->m_sb))
  1429. return XFS_ERROR(EINVAL);
  1430. /*
  1431. * For IRIX 6.5, shared mounts must have the shared
  1432. * version bit set, have the persistent readonly
  1433. * field set, must be version 0 and can only be mounted
  1434. * read-only.
  1435. */
  1436. if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
  1437. (mp->m_sb.sb_shared_vn != 0))
  1438. return XFS_ERROR(EINVAL);
  1439. mp->m_flags |= XFS_MOUNT_SHARED;
  1440. /*
  1441. * Shared XFS V0 can't deal with DMI. Return EINVAL.
  1442. */
  1443. if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
  1444. return XFS_ERROR(EINVAL);
  1445. }
  1446. if (ap->flags & XFSMNT_UQUOTA) {
  1447. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  1448. if (ap->flags & XFSMNT_UQUOTAENF)
  1449. mp->m_qflags |= XFS_UQUOTA_ENFD;
  1450. }
  1451. if (ap->flags & XFSMNT_GQUOTA) {
  1452. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  1453. if (ap->flags & XFSMNT_GQUOTAENF)
  1454. mp->m_qflags |= XFS_OQUOTA_ENFD;
  1455. } else if (ap->flags & XFSMNT_PQUOTA) {
  1456. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  1457. if (ap->flags & XFSMNT_PQUOTAENF)
  1458. mp->m_qflags |= XFS_OQUOTA_ENFD;
  1459. }
  1460. return 0;
  1461. }
  1462. STATIC int
  1463. xfs_fs_fill_super(
  1464. struct super_block *sb,
  1465. void *data,
  1466. int silent)
  1467. {
  1468. struct inode *root;
  1469. struct xfs_mount *mp = NULL;
  1470. struct xfs_mount_args *args;
  1471. int flags = 0, error = ENOMEM;
  1472. args = xfs_args_allocate(sb, silent);
  1473. if (!args)
  1474. return -ENOMEM;
  1475. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1476. if (!mp)
  1477. goto out_free_args;
  1478. spin_lock_init(&mp->m_sb_lock);
  1479. mutex_init(&mp->m_ilock);
  1480. mutex_init(&mp->m_growlock);
  1481. atomic_set(&mp->m_active_trans, 0);
  1482. INIT_LIST_HEAD(&mp->m_sync_list);
  1483. spin_lock_init(&mp->m_sync_lock);
  1484. init_waitqueue_head(&mp->m_wait_single_sync_task);
  1485. mp->m_super = sb;
  1486. sb->s_fs_info = mp;
  1487. if (sb->s_flags & MS_RDONLY)
  1488. mp->m_flags |= XFS_MOUNT_RDONLY;
  1489. error = xfs_parseargs(mp, (char *)data, args, 0);
  1490. if (error)
  1491. goto out_free_mp;
  1492. sb_min_blocksize(sb, BBSIZE);
  1493. sb->s_xattr = xfs_xattr_handlers;
  1494. sb->s_export_op = &xfs_export_operations;
  1495. sb->s_qcop = &xfs_quotactl_operations;
  1496. sb->s_op = &xfs_super_operations;
  1497. error = xfs_dmops_get(mp, args);
  1498. if (error)
  1499. goto out_free_mp;
  1500. error = xfs_qmops_get(mp, args);
  1501. if (error)
  1502. goto out_put_dmops;
  1503. if (args->flags & XFSMNT_QUIET)
  1504. flags |= XFS_MFSI_QUIET;
  1505. error = xfs_open_devices(mp, args);
  1506. if (error)
  1507. goto out_put_qmops;
  1508. if (xfs_icsb_init_counters(mp))
  1509. mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
  1510. /*
  1511. * Setup flags based on mount(2) options and then the superblock
  1512. */
  1513. error = xfs_start_flags(args, mp);
  1514. if (error)
  1515. goto out_free_fsname;
  1516. error = xfs_readsb(mp, flags);
  1517. if (error)
  1518. goto out_free_fsname;
  1519. error = xfs_finish_flags(args, mp);
  1520. if (error)
  1521. goto out_free_sb;
  1522. error = xfs_setup_devices(mp);
  1523. if (error)
  1524. goto out_free_sb;
  1525. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1526. xfs_mountfs_check_barriers(mp);
  1527. error = xfs_filestream_mount(mp);
  1528. if (error)
  1529. goto out_free_sb;
  1530. error = xfs_mountfs(mp, flags);
  1531. if (error)
  1532. goto out_filestream_unmount;
  1533. XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
  1534. sb->s_dirt = 1;
  1535. sb->s_magic = XFS_SB_MAGIC;
  1536. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1537. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1538. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1539. sb->s_time_gran = 1;
  1540. set_posix_acl_flag(sb);
  1541. root = igrab(VFS_I(mp->m_rootip));
  1542. if (!root) {
  1543. error = ENOENT;
  1544. goto fail_unmount;
  1545. }
  1546. if (is_bad_inode(root)) {
  1547. error = EINVAL;
  1548. goto fail_vnrele;
  1549. }
  1550. sb->s_root = d_alloc_root(root);
  1551. if (!sb->s_root) {
  1552. error = ENOMEM;
  1553. goto fail_vnrele;
  1554. }
  1555. mp->m_sync_work.w_syncer = xfs_sync_worker;
  1556. mp->m_sync_work.w_mount = mp;
  1557. mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
  1558. if (IS_ERR(mp->m_sync_task)) {
  1559. error = -PTR_ERR(mp->m_sync_task);
  1560. goto fail_vnrele;
  1561. }
  1562. xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
  1563. kfree(args);
  1564. return 0;
  1565. out_filestream_unmount:
  1566. xfs_filestream_unmount(mp);
  1567. out_free_sb:
  1568. xfs_freesb(mp);
  1569. out_free_fsname:
  1570. xfs_free_fsname(mp);
  1571. xfs_icsb_destroy_counters(mp);
  1572. xfs_close_devices(mp);
  1573. out_put_qmops:
  1574. xfs_qmops_put(mp);
  1575. out_put_dmops:
  1576. xfs_dmops_put(mp);
  1577. out_free_mp:
  1578. kfree(mp);
  1579. out_free_args:
  1580. kfree(args);
  1581. return -error;
  1582. fail_vnrele:
  1583. if (sb->s_root) {
  1584. dput(sb->s_root);
  1585. sb->s_root = NULL;
  1586. } else {
  1587. iput(root);
  1588. }
  1589. fail_unmount:
  1590. /*
  1591. * Blow away any referenced inode in the filestreams cache.
  1592. * This can and will cause log traffic as inodes go inactive
  1593. * here.
  1594. */
  1595. xfs_filestream_unmount(mp);
  1596. XFS_bflush(mp->m_ddev_targp);
  1597. error = xfs_unmount_flush(mp, 0);
  1598. WARN_ON(error);
  1599. IRELE(mp->m_rootip);
  1600. xfs_unmountfs(mp);
  1601. goto out_free_fsname;
  1602. }
  1603. STATIC int
  1604. xfs_fs_get_sb(
  1605. struct file_system_type *fs_type,
  1606. int flags,
  1607. const char *dev_name,
  1608. void *data,
  1609. struct vfsmount *mnt)
  1610. {
  1611. return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
  1612. mnt);
  1613. }
  1614. static struct super_operations xfs_super_operations = {
  1615. .alloc_inode = xfs_fs_alloc_inode,
  1616. .destroy_inode = xfs_fs_destroy_inode,
  1617. .write_inode = xfs_fs_write_inode,
  1618. .clear_inode = xfs_fs_clear_inode,
  1619. .put_super = xfs_fs_put_super,
  1620. .write_super = xfs_fs_write_super,
  1621. .sync_fs = xfs_fs_sync_super,
  1622. .write_super_lockfs = xfs_fs_lockfs,
  1623. .statfs = xfs_fs_statfs,
  1624. .remount_fs = xfs_fs_remount,
  1625. .show_options = xfs_fs_show_options,
  1626. };
  1627. static struct quotactl_ops xfs_quotactl_operations = {
  1628. .quota_sync = xfs_fs_quotasync,
  1629. .get_xstate = xfs_fs_getxstate,
  1630. .set_xstate = xfs_fs_setxstate,
  1631. .get_xquota = xfs_fs_getxquota,
  1632. .set_xquota = xfs_fs_setxquota,
  1633. };
  1634. static struct file_system_type xfs_fs_type = {
  1635. .owner = THIS_MODULE,
  1636. .name = "xfs",
  1637. .get_sb = xfs_fs_get_sb,
  1638. .kill_sb = kill_block_super,
  1639. .fs_flags = FS_REQUIRES_DEV,
  1640. };
  1641. STATIC int __init
  1642. xfs_alloc_trace_bufs(void)
  1643. {
  1644. #ifdef XFS_ALLOC_TRACE
  1645. xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
  1646. if (!xfs_alloc_trace_buf)
  1647. goto out;
  1648. #endif
  1649. #ifdef XFS_BMAP_TRACE
  1650. xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
  1651. if (!xfs_bmap_trace_buf)
  1652. goto out_free_alloc_trace;
  1653. #endif
  1654. #ifdef XFS_BMBT_TRACE
  1655. xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
  1656. if (!xfs_bmbt_trace_buf)
  1657. goto out_free_bmap_trace;
  1658. #endif
  1659. #ifdef XFS_ATTR_TRACE
  1660. xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
  1661. if (!xfs_attr_trace_buf)
  1662. goto out_free_bmbt_trace;
  1663. #endif
  1664. #ifdef XFS_DIR2_TRACE
  1665. xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
  1666. if (!xfs_dir2_trace_buf)
  1667. goto out_free_attr_trace;
  1668. #endif
  1669. return 0;
  1670. #ifdef XFS_DIR2_TRACE
  1671. out_free_attr_trace:
  1672. #endif
  1673. #ifdef XFS_ATTR_TRACE
  1674. ktrace_free(xfs_attr_trace_buf);
  1675. out_free_bmbt_trace:
  1676. #endif
  1677. #ifdef XFS_BMBT_TRACE
  1678. ktrace_free(xfs_bmbt_trace_buf);
  1679. out_free_bmap_trace:
  1680. #endif
  1681. #ifdef XFS_BMAP_TRACE
  1682. ktrace_free(xfs_bmap_trace_buf);
  1683. out_free_alloc_trace:
  1684. #endif
  1685. #ifdef XFS_ALLOC_TRACE
  1686. ktrace_free(xfs_alloc_trace_buf);
  1687. out:
  1688. #endif
  1689. return -ENOMEM;
  1690. }
  1691. STATIC void
  1692. xfs_free_trace_bufs(void)
  1693. {
  1694. #ifdef XFS_DIR2_TRACE
  1695. ktrace_free(xfs_dir2_trace_buf);
  1696. #endif
  1697. #ifdef XFS_ATTR_TRACE
  1698. ktrace_free(xfs_attr_trace_buf);
  1699. #endif
  1700. #ifdef XFS_BMBT_TRACE
  1701. ktrace_free(xfs_bmbt_trace_buf);
  1702. #endif
  1703. #ifdef XFS_BMAP_TRACE
  1704. ktrace_free(xfs_bmap_trace_buf);
  1705. #endif
  1706. #ifdef XFS_ALLOC_TRACE
  1707. ktrace_free(xfs_alloc_trace_buf);
  1708. #endif
  1709. }
  1710. STATIC int __init
  1711. xfs_init_zones(void)
  1712. {
  1713. xfs_vnode_zone = kmem_zone_init_flags(sizeof(struct inode), "xfs_vnode",
  1714. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
  1715. KM_ZONE_SPREAD,
  1716. xfs_fs_inode_init_once);
  1717. if (!xfs_vnode_zone)
  1718. goto out;
  1719. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1720. if (!xfs_ioend_zone)
  1721. goto out_destroy_vnode_zone;
  1722. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1723. xfs_ioend_zone);
  1724. if (!xfs_ioend_pool)
  1725. goto out_destroy_ioend_zone;
  1726. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1727. "xfs_log_ticket");
  1728. if (!xfs_log_ticket_zone)
  1729. goto out_destroy_ioend_pool;
  1730. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1731. "xfs_bmap_free_item");
  1732. if (!xfs_bmap_free_item_zone)
  1733. goto out_destroy_log_ticket_zone;
  1734. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1735. "xfs_btree_cur");
  1736. if (!xfs_btree_cur_zone)
  1737. goto out_destroy_bmap_free_item_zone;
  1738. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1739. "xfs_da_state");
  1740. if (!xfs_da_state_zone)
  1741. goto out_destroy_btree_cur_zone;
  1742. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  1743. if (!xfs_dabuf_zone)
  1744. goto out_destroy_da_state_zone;
  1745. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1746. if (!xfs_ifork_zone)
  1747. goto out_destroy_dabuf_zone;
  1748. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1749. if (!xfs_trans_zone)
  1750. goto out_destroy_ifork_zone;
  1751. /*
  1752. * The size of the zone allocated buf log item is the maximum
  1753. * size possible under XFS. This wastes a little bit of memory,
  1754. * but it is much faster.
  1755. */
  1756. xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  1757. (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
  1758. NBWORD) * sizeof(int))), "xfs_buf_item");
  1759. if (!xfs_buf_item_zone)
  1760. goto out_destroy_trans_zone;
  1761. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1762. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1763. sizeof(xfs_extent_t))), "xfs_efd_item");
  1764. if (!xfs_efd_zone)
  1765. goto out_destroy_buf_item_zone;
  1766. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1767. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1768. sizeof(xfs_extent_t))), "xfs_efi_item");
  1769. if (!xfs_efi_zone)
  1770. goto out_destroy_efd_zone;
  1771. xfs_inode_zone =
  1772. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1773. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
  1774. KM_ZONE_SPREAD, NULL);
  1775. if (!xfs_inode_zone)
  1776. goto out_destroy_efi_zone;
  1777. xfs_ili_zone =
  1778. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1779. KM_ZONE_SPREAD, NULL);
  1780. if (!xfs_ili_zone)
  1781. goto out_destroy_inode_zone;
  1782. #ifdef CONFIG_XFS_POSIX_ACL
  1783. xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
  1784. if (!xfs_acl_zone)
  1785. goto out_destroy_ili_zone;
  1786. #endif
  1787. return 0;
  1788. #ifdef CONFIG_XFS_POSIX_ACL
  1789. out_destroy_ili_zone:
  1790. #endif
  1791. kmem_zone_destroy(xfs_ili_zone);
  1792. out_destroy_inode_zone:
  1793. kmem_zone_destroy(xfs_inode_zone);
  1794. out_destroy_efi_zone:
  1795. kmem_zone_destroy(xfs_efi_zone);
  1796. out_destroy_efd_zone:
  1797. kmem_zone_destroy(xfs_efd_zone);
  1798. out_destroy_buf_item_zone:
  1799. kmem_zone_destroy(xfs_buf_item_zone);
  1800. out_destroy_trans_zone:
  1801. kmem_zone_destroy(xfs_trans_zone);
  1802. out_destroy_ifork_zone:
  1803. kmem_zone_destroy(xfs_ifork_zone);
  1804. out_destroy_dabuf_zone:
  1805. kmem_zone_destroy(xfs_dabuf_zone);
  1806. out_destroy_da_state_zone:
  1807. kmem_zone_destroy(xfs_da_state_zone);
  1808. out_destroy_btree_cur_zone:
  1809. kmem_zone_destroy(xfs_btree_cur_zone);
  1810. out_destroy_bmap_free_item_zone:
  1811. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1812. out_destroy_log_ticket_zone:
  1813. kmem_zone_destroy(xfs_log_ticket_zone);
  1814. out_destroy_ioend_pool:
  1815. mempool_destroy(xfs_ioend_pool);
  1816. out_destroy_ioend_zone:
  1817. kmem_zone_destroy(xfs_ioend_zone);
  1818. out_destroy_vnode_zone:
  1819. kmem_zone_destroy(xfs_vnode_zone);
  1820. out:
  1821. return -ENOMEM;
  1822. }
  1823. STATIC void
  1824. xfs_destroy_zones(void)
  1825. {
  1826. #ifdef CONFIG_XFS_POSIX_ACL
  1827. kmem_zone_destroy(xfs_acl_zone);
  1828. #endif
  1829. kmem_zone_destroy(xfs_ili_zone);
  1830. kmem_zone_destroy(xfs_inode_zone);
  1831. kmem_zone_destroy(xfs_efi_zone);
  1832. kmem_zone_destroy(xfs_efd_zone);
  1833. kmem_zone_destroy(xfs_buf_item_zone);
  1834. kmem_zone_destroy(xfs_trans_zone);
  1835. kmem_zone_destroy(xfs_ifork_zone);
  1836. kmem_zone_destroy(xfs_dabuf_zone);
  1837. kmem_zone_destroy(xfs_da_state_zone);
  1838. kmem_zone_destroy(xfs_btree_cur_zone);
  1839. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1840. kmem_zone_destroy(xfs_log_ticket_zone);
  1841. mempool_destroy(xfs_ioend_pool);
  1842. kmem_zone_destroy(xfs_ioend_zone);
  1843. kmem_zone_destroy(xfs_vnode_zone);
  1844. }
  1845. STATIC int __init
  1846. init_xfs_fs(void)
  1847. {
  1848. int error;
  1849. static char message[] __initdata = KERN_INFO \
  1850. XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
  1851. printk(message);
  1852. ktrace_init(64);
  1853. vn_init();
  1854. xfs_dir_startup();
  1855. error = xfs_init_zones();
  1856. if (error)
  1857. goto out;
  1858. error = xfs_alloc_trace_bufs();
  1859. if (error)
  1860. goto out_destroy_zones;
  1861. error = xfs_mru_cache_init();
  1862. if (error)
  1863. goto out_free_trace_buffers;
  1864. error = xfs_filestream_init();
  1865. if (error)
  1866. goto out_mru_cache_uninit;
  1867. error = xfs_buf_init();
  1868. if (error)
  1869. goto out_filestream_uninit;
  1870. error = xfs_init_procfs();
  1871. if (error)
  1872. goto out_buf_terminate;
  1873. error = xfs_sysctl_register();
  1874. if (error)
  1875. goto out_cleanup_procfs;
  1876. vfs_initquota();
  1877. error = register_filesystem(&xfs_fs_type);
  1878. if (error)
  1879. goto out_sysctl_unregister;
  1880. return 0;
  1881. out_sysctl_unregister:
  1882. xfs_sysctl_unregister();
  1883. out_cleanup_procfs:
  1884. xfs_cleanup_procfs();
  1885. out_buf_terminate:
  1886. xfs_buf_terminate();
  1887. out_filestream_uninit:
  1888. xfs_filestream_uninit();
  1889. out_mru_cache_uninit:
  1890. xfs_mru_cache_uninit();
  1891. out_free_trace_buffers:
  1892. xfs_free_trace_bufs();
  1893. out_destroy_zones:
  1894. xfs_destroy_zones();
  1895. out:
  1896. return error;
  1897. }
  1898. STATIC void __exit
  1899. exit_xfs_fs(void)
  1900. {
  1901. vfs_exitquota();
  1902. unregister_filesystem(&xfs_fs_type);
  1903. xfs_sysctl_unregister();
  1904. xfs_cleanup_procfs();
  1905. xfs_buf_terminate();
  1906. xfs_filestream_uninit();
  1907. xfs_mru_cache_uninit();
  1908. xfs_free_trace_bufs();
  1909. xfs_destroy_zones();
  1910. ktrace_uninit();
  1911. }
  1912. module_init(init_xfs_fs);
  1913. module_exit(exit_xfs_fs);
  1914. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1915. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1916. MODULE_LICENSE("GPL");