xfs_super.c 52 KB

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