xfs_super.c 52 KB

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