xfs_super.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  1. /*
  2. * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_bit.h"
  20. #include "xfs_log.h"
  21. #include "xfs_clnt.h"
  22. #include "xfs_inum.h"
  23. #include "xfs_trans.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_dir2.h"
  27. #include "xfs_alloc.h"
  28. #include "xfs_dmapi.h"
  29. #include "xfs_quota.h"
  30. #include "xfs_mount.h"
  31. #include "xfs_bmap_btree.h"
  32. #include "xfs_alloc_btree.h"
  33. #include "xfs_ialloc_btree.h"
  34. #include "xfs_dir2_sf.h"
  35. #include "xfs_attr_sf.h"
  36. #include "xfs_dinode.h"
  37. #include "xfs_inode.h"
  38. #include "xfs_btree.h"
  39. #include "xfs_ialloc.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_rtalloc.h"
  42. #include "xfs_error.h"
  43. #include "xfs_itable.h"
  44. #include "xfs_fsops.h"
  45. #include "xfs_rw.h"
  46. #include "xfs_acl.h"
  47. #include "xfs_attr.h"
  48. #include "xfs_buf_item.h"
  49. #include "xfs_utils.h"
  50. #include "xfs_vnodeops.h"
  51. #include "xfs_vfsops.h"
  52. #include "xfs_version.h"
  53. #include "xfs_log_priv.h"
  54. #include <linux/namei.h>
  55. #include <linux/init.h>
  56. #include <linux/mount.h>
  57. #include <linux/mempool.h>
  58. #include <linux/writeback.h>
  59. #include <linux/kthread.h>
  60. #include <linux/freezer.h>
  61. static struct quotactl_ops xfs_quotactl_operations;
  62. static struct super_operations xfs_super_operations;
  63. static kmem_zone_t *xfs_vnode_zone;
  64. static kmem_zone_t *xfs_ioend_zone;
  65. mempool_t *xfs_ioend_pool;
  66. STATIC struct xfs_mount_args *
  67. xfs_args_allocate(
  68. struct super_block *sb,
  69. int silent)
  70. {
  71. struct xfs_mount_args *args;
  72. args = kmem_zalloc(sizeof(struct xfs_mount_args), KM_SLEEP);
  73. args->logbufs = args->logbufsize = -1;
  74. strncpy(args->fsname, sb->s_id, MAXNAMELEN);
  75. /* Copy the already-parsed mount(2) flags we're interested in */
  76. if (sb->s_flags & MS_DIRSYNC)
  77. args->flags |= XFSMNT_DIRSYNC;
  78. if (sb->s_flags & MS_SYNCHRONOUS)
  79. args->flags |= XFSMNT_WSYNC;
  80. if (silent)
  81. args->flags |= XFSMNT_QUIET;
  82. args->flags |= XFSMNT_32BITINODES;
  83. return args;
  84. }
  85. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  86. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  87. #define MNTOPT_LOGDEV "logdev" /* log device */
  88. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  89. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  90. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  91. #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
  92. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  93. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  94. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  95. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  96. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  97. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  98. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  99. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  100. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  101. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  102. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  103. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  104. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  105. * unwritten extent conversion */
  106. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  107. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  108. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  109. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  110. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  111. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  112. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  113. * in stat(). */
  114. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  115. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  116. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  117. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  118. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  119. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  120. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  121. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  122. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  123. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  124. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  125. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  126. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  127. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  128. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  129. #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
  130. #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
  131. #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
  132. STATIC unsigned long
  133. suffix_strtoul(char *s, char **endp, unsigned int base)
  134. {
  135. int last, shift_left_factor = 0;
  136. char *value = s;
  137. last = strlen(value) - 1;
  138. if (value[last] == 'K' || value[last] == 'k') {
  139. shift_left_factor = 10;
  140. value[last] = '\0';
  141. }
  142. if (value[last] == 'M' || value[last] == 'm') {
  143. shift_left_factor = 20;
  144. value[last] = '\0';
  145. }
  146. if (value[last] == 'G' || value[last] == 'g') {
  147. shift_left_factor = 30;
  148. value[last] = '\0';
  149. }
  150. return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
  151. }
  152. STATIC int
  153. xfs_parseargs(
  154. struct xfs_mount *mp,
  155. char *options,
  156. struct xfs_mount_args *args,
  157. int update)
  158. {
  159. char *this_char, *value, *eov;
  160. int dsunit, dswidth, vol_dsunit, vol_dswidth;
  161. int iosize;
  162. int ikeep = 0;
  163. args->flags |= XFSMNT_BARRIER;
  164. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  165. if (!options)
  166. goto done;
  167. iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
  168. while ((this_char = strsep(&options, ",")) != NULL) {
  169. if (!*this_char)
  170. continue;
  171. if ((value = strchr(this_char, '=')) != NULL)
  172. *value++ = 0;
  173. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  174. if (!value || !*value) {
  175. cmn_err(CE_WARN,
  176. "XFS: %s option requires an argument",
  177. this_char);
  178. return EINVAL;
  179. }
  180. args->logbufs = simple_strtoul(value, &eov, 10);
  181. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  182. if (!value || !*value) {
  183. cmn_err(CE_WARN,
  184. "XFS: %s option requires an argument",
  185. this_char);
  186. return EINVAL;
  187. }
  188. args->logbufsize = suffix_strtoul(value, &eov, 10);
  189. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  190. if (!value || !*value) {
  191. cmn_err(CE_WARN,
  192. "XFS: %s option requires an argument",
  193. this_char);
  194. return EINVAL;
  195. }
  196. strncpy(args->logname, value, MAXNAMELEN);
  197. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  198. if (!value || !*value) {
  199. cmn_err(CE_WARN,
  200. "XFS: %s option requires an argument",
  201. this_char);
  202. return EINVAL;
  203. }
  204. strncpy(args->mtpt, value, MAXNAMELEN);
  205. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  206. if (!value || !*value) {
  207. cmn_err(CE_WARN,
  208. "XFS: %s option requires an argument",
  209. this_char);
  210. return EINVAL;
  211. }
  212. strncpy(args->rtname, value, MAXNAMELEN);
  213. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  214. if (!value || !*value) {
  215. cmn_err(CE_WARN,
  216. "XFS: %s option requires an argument",
  217. this_char);
  218. return EINVAL;
  219. }
  220. iosize = simple_strtoul(value, &eov, 10);
  221. args->flags |= XFSMNT_IOSIZE;
  222. args->iosizelog = (uint8_t) iosize;
  223. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  224. if (!value || !*value) {
  225. cmn_err(CE_WARN,
  226. "XFS: %s option requires an argument",
  227. this_char);
  228. return EINVAL;
  229. }
  230. iosize = suffix_strtoul(value, &eov, 10);
  231. args->flags |= XFSMNT_IOSIZE;
  232. args->iosizelog = ffs(iosize) - 1;
  233. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  234. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  235. mp->m_flags |= XFS_MOUNT_GRPID;
  236. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  237. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  238. mp->m_flags &= ~XFS_MOUNT_GRPID;
  239. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  240. args->flags |= XFSMNT_WSYNC;
  241. } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
  242. args->flags |= XFSMNT_OSYNCISOSYNC;
  243. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  244. args->flags |= XFSMNT_NORECOVERY;
  245. } else if (!strcmp(this_char, MNTOPT_INO64)) {
  246. args->flags |= XFSMNT_INO64;
  247. #if !XFS_BIG_INUMS
  248. cmn_err(CE_WARN,
  249. "XFS: %s option not allowed on this system",
  250. this_char);
  251. return EINVAL;
  252. #endif
  253. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  254. args->flags |= XFSMNT_NOALIGN;
  255. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  256. args->flags |= XFSMNT_SWALLOC;
  257. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  258. if (!value || !*value) {
  259. cmn_err(CE_WARN,
  260. "XFS: %s option requires an argument",
  261. this_char);
  262. return EINVAL;
  263. }
  264. dsunit = simple_strtoul(value, &eov, 10);
  265. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  266. if (!value || !*value) {
  267. cmn_err(CE_WARN,
  268. "XFS: %s option requires an argument",
  269. this_char);
  270. return EINVAL;
  271. }
  272. dswidth = simple_strtoul(value, &eov, 10);
  273. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  274. args->flags &= ~XFSMNT_32BITINODES;
  275. #if !XFS_BIG_INUMS
  276. cmn_err(CE_WARN,
  277. "XFS: %s option not allowed on this system",
  278. this_char);
  279. return EINVAL;
  280. #endif
  281. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  282. args->flags |= XFSMNT_NOUUID;
  283. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  284. args->flags |= XFSMNT_BARRIER;
  285. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  286. args->flags &= ~XFSMNT_BARRIER;
  287. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  288. ikeep = 1;
  289. args->flags &= ~XFSMNT_IDELETE;
  290. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  291. args->flags |= XFSMNT_IDELETE;
  292. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  293. args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
  294. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  295. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  296. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  297. args->flags |= XFSMNT_ATTR2;
  298. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  299. args->flags &= ~XFSMNT_ATTR2;
  300. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  301. args->flags2 |= XFSMNT2_FILESTREAMS;
  302. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  303. args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
  304. args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
  305. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  306. !strcmp(this_char, MNTOPT_UQUOTA) ||
  307. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  308. args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
  309. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  310. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  311. args->flags |= XFSMNT_UQUOTA;
  312. args->flags &= ~XFSMNT_UQUOTAENF;
  313. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  314. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  315. args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
  316. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  317. args->flags |= XFSMNT_PQUOTA;
  318. args->flags &= ~XFSMNT_PQUOTAENF;
  319. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  320. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  321. args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
  322. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  323. args->flags |= XFSMNT_GQUOTA;
  324. args->flags &= ~XFSMNT_GQUOTAENF;
  325. } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
  326. args->flags |= XFSMNT_DMAPI;
  327. } else if (!strcmp(this_char, MNTOPT_XDSM)) {
  328. args->flags |= XFSMNT_DMAPI;
  329. } else if (!strcmp(this_char, MNTOPT_DMI)) {
  330. args->flags |= XFSMNT_DMAPI;
  331. } else if (!strcmp(this_char, "ihashsize")) {
  332. cmn_err(CE_WARN,
  333. "XFS: ihashsize no longer used, option is deprecated.");
  334. } else if (!strcmp(this_char, "osyncisdsync")) {
  335. /* no-op, this is now the default */
  336. cmn_err(CE_WARN,
  337. "XFS: osyncisdsync is now the default, option is deprecated.");
  338. } else if (!strcmp(this_char, "irixsgid")) {
  339. cmn_err(CE_WARN,
  340. "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
  341. } else {
  342. cmn_err(CE_WARN,
  343. "XFS: unknown mount option [%s].", this_char);
  344. return EINVAL;
  345. }
  346. }
  347. if (args->flags & XFSMNT_NORECOVERY) {
  348. if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
  349. cmn_err(CE_WARN,
  350. "XFS: no-recovery mounts must be read-only.");
  351. return EINVAL;
  352. }
  353. }
  354. if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
  355. cmn_err(CE_WARN,
  356. "XFS: sunit and swidth options incompatible with the noalign option");
  357. return EINVAL;
  358. }
  359. if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
  360. cmn_err(CE_WARN,
  361. "XFS: cannot mount with both project and group quota");
  362. return EINVAL;
  363. }
  364. if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
  365. printk("XFS: %s option needs the mount point option as well\n",
  366. MNTOPT_DMAPI);
  367. return EINVAL;
  368. }
  369. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  370. cmn_err(CE_WARN,
  371. "XFS: sunit and swidth must be specified together");
  372. return EINVAL;
  373. }
  374. if (dsunit && (dswidth % dsunit != 0)) {
  375. cmn_err(CE_WARN,
  376. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  377. dswidth, dsunit);
  378. return EINVAL;
  379. }
  380. /*
  381. * Applications using DMI filesystems often expect the
  382. * inode generation number to be monotonically increasing.
  383. * If we delete inode chunks we break this assumption, so
  384. * keep unused inode chunks on disk for DMI filesystems
  385. * until we come up with a better solution.
  386. * Note that if "ikeep" or "noikeep" mount options are
  387. * supplied, then they are honored.
  388. */
  389. if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
  390. args->flags |= XFSMNT_IDELETE;
  391. if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  392. if (dsunit) {
  393. args->sunit = dsunit;
  394. args->flags |= XFSMNT_RETERR;
  395. } else {
  396. args->sunit = vol_dsunit;
  397. }
  398. dswidth ? (args->swidth = dswidth) :
  399. (args->swidth = vol_dswidth);
  400. } else {
  401. args->sunit = args->swidth = 0;
  402. }
  403. done:
  404. if (args->flags & XFSMNT_32BITINODES)
  405. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  406. if (args->flags2)
  407. args->flags |= XFSMNT_FLAGS2;
  408. return 0;
  409. }
  410. struct proc_xfs_info {
  411. int flag;
  412. char *str;
  413. };
  414. STATIC int
  415. xfs_showargs(
  416. struct xfs_mount *mp,
  417. struct seq_file *m)
  418. {
  419. static struct proc_xfs_info xfs_info_set[] = {
  420. /* the few simple ones we can get from the mount struct */
  421. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  422. { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
  423. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  424. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  425. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  426. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  427. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  428. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  429. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  430. { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
  431. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  432. { 0, NULL }
  433. };
  434. static struct proc_xfs_info xfs_info_unset[] = {
  435. /* the few simple ones we can get from the mount struct */
  436. { XFS_MOUNT_IDELETE, "," MNTOPT_IKEEP },
  437. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  438. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  439. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  440. { 0, NULL }
  441. };
  442. struct proc_xfs_info *xfs_infop;
  443. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  444. if (mp->m_flags & xfs_infop->flag)
  445. seq_puts(m, xfs_infop->str);
  446. }
  447. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  448. if (!(mp->m_flags & xfs_infop->flag))
  449. seq_puts(m, xfs_infop->str);
  450. }
  451. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  452. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  453. (int)(1 << mp->m_writeio_log) >> 10);
  454. if (mp->m_logbufs > 0)
  455. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  456. if (mp->m_logbsize > 0)
  457. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  458. if (mp->m_logname)
  459. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  460. if (mp->m_rtname)
  461. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  462. if (mp->m_dalign > 0)
  463. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  464. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  465. if (mp->m_swidth > 0)
  466. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  467. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  468. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  469. seq_puts(m, "," MNTOPT_USRQUOTA);
  470. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  471. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  472. if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
  473. seq_puts(m, "," MNTOPT_PRJQUOTA);
  474. else if (mp->m_qflags & XFS_PQUOTA_ACCT)
  475. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  476. if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
  477. seq_puts(m, "," MNTOPT_GRPQUOTA);
  478. else if (mp->m_qflags & XFS_GQUOTA_ACCT)
  479. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  480. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  481. seq_puts(m, "," MNTOPT_NOQUOTA);
  482. return 0;
  483. }
  484. __uint64_t
  485. xfs_max_file_offset(
  486. unsigned int blockshift)
  487. {
  488. unsigned int pagefactor = 1;
  489. unsigned int bitshift = BITS_PER_LONG - 1;
  490. /* Figure out maximum filesize, on Linux this can depend on
  491. * the filesystem blocksize (on 32 bit platforms).
  492. * __block_prepare_write does this in an [unsigned] long...
  493. * page->index << (PAGE_CACHE_SHIFT - bbits)
  494. * So, for page sized blocks (4K on 32 bit platforms),
  495. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  496. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  497. * but for smaller blocksizes it is less (bbits = log2 bsize).
  498. * Note1: get_block_t takes a long (implicit cast from above)
  499. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  500. * can optionally convert the [unsigned] long from above into
  501. * an [unsigned] long long.
  502. */
  503. #if BITS_PER_LONG == 32
  504. # if defined(CONFIG_LBD)
  505. ASSERT(sizeof(sector_t) == 8);
  506. pagefactor = PAGE_CACHE_SIZE;
  507. bitshift = BITS_PER_LONG;
  508. # else
  509. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  510. # endif
  511. #endif
  512. return (((__uint64_t)pagefactor) << bitshift) - 1;
  513. }
  514. STATIC_INLINE void
  515. xfs_set_inodeops(
  516. struct inode *inode)
  517. {
  518. switch (inode->i_mode & S_IFMT) {
  519. case S_IFREG:
  520. inode->i_op = &xfs_inode_operations;
  521. inode->i_fop = &xfs_file_operations;
  522. inode->i_mapping->a_ops = &xfs_address_space_operations;
  523. break;
  524. case S_IFDIR:
  525. inode->i_op = &xfs_dir_inode_operations;
  526. inode->i_fop = &xfs_dir_file_operations;
  527. break;
  528. case S_IFLNK:
  529. inode->i_op = &xfs_symlink_inode_operations;
  530. if (inode->i_blocks)
  531. inode->i_mapping->a_ops = &xfs_address_space_operations;
  532. break;
  533. default:
  534. inode->i_op = &xfs_inode_operations;
  535. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  536. break;
  537. }
  538. }
  539. STATIC_INLINE void
  540. xfs_revalidate_inode(
  541. xfs_mount_t *mp,
  542. bhv_vnode_t *vp,
  543. xfs_inode_t *ip)
  544. {
  545. struct inode *inode = vn_to_inode(vp);
  546. inode->i_mode = ip->i_d.di_mode;
  547. inode->i_nlink = ip->i_d.di_nlink;
  548. inode->i_uid = ip->i_d.di_uid;
  549. inode->i_gid = ip->i_d.di_gid;
  550. switch (inode->i_mode & S_IFMT) {
  551. case S_IFBLK:
  552. case S_IFCHR:
  553. inode->i_rdev =
  554. MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  555. sysv_minor(ip->i_df.if_u2.if_rdev));
  556. break;
  557. default:
  558. inode->i_rdev = 0;
  559. break;
  560. }
  561. inode->i_generation = ip->i_d.di_gen;
  562. i_size_write(inode, ip->i_d.di_size);
  563. inode->i_blocks =
  564. XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
  565. inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
  566. inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
  567. inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
  568. inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
  569. inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
  570. inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
  571. if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
  572. inode->i_flags |= S_IMMUTABLE;
  573. else
  574. inode->i_flags &= ~S_IMMUTABLE;
  575. if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
  576. inode->i_flags |= S_APPEND;
  577. else
  578. inode->i_flags &= ~S_APPEND;
  579. if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
  580. inode->i_flags |= S_SYNC;
  581. else
  582. inode->i_flags &= ~S_SYNC;
  583. if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
  584. inode->i_flags |= S_NOATIME;
  585. else
  586. inode->i_flags &= ~S_NOATIME;
  587. xfs_iflags_clear(ip, XFS_IMODIFIED);
  588. }
  589. void
  590. xfs_initialize_vnode(
  591. struct xfs_mount *mp,
  592. bhv_vnode_t *vp,
  593. struct xfs_inode *ip)
  594. {
  595. struct inode *inode = vn_to_inode(vp);
  596. if (!ip->i_vnode) {
  597. ip->i_vnode = vp;
  598. inode->i_private = ip;
  599. }
  600. /*
  601. * We need to set the ops vectors, and unlock the inode, but if
  602. * we have been called during the new inode create process, it is
  603. * too early to fill in the Linux inode. We will get called a
  604. * second time once the inode is properly set up, and then we can
  605. * finish our work.
  606. */
  607. if (ip->i_d.di_mode != 0 && (inode->i_state & I_NEW)) {
  608. xfs_revalidate_inode(mp, vp, ip);
  609. xfs_set_inodeops(inode);
  610. xfs_iflags_clear(ip, XFS_INEW);
  611. barrier();
  612. unlock_new_inode(inode);
  613. }
  614. }
  615. int
  616. xfs_blkdev_get(
  617. xfs_mount_t *mp,
  618. const char *name,
  619. struct block_device **bdevp)
  620. {
  621. int error = 0;
  622. *bdevp = open_bdev_excl(name, 0, mp);
  623. if (IS_ERR(*bdevp)) {
  624. error = PTR_ERR(*bdevp);
  625. printk("XFS: Invalid device [%s], error=%d\n", name, error);
  626. }
  627. return -error;
  628. }
  629. void
  630. xfs_blkdev_put(
  631. struct block_device *bdev)
  632. {
  633. if (bdev)
  634. close_bdev_excl(bdev);
  635. }
  636. /*
  637. * Try to write out the superblock using barriers.
  638. */
  639. STATIC int
  640. xfs_barrier_test(
  641. xfs_mount_t *mp)
  642. {
  643. xfs_buf_t *sbp = xfs_getsb(mp, 0);
  644. int error;
  645. XFS_BUF_UNDONE(sbp);
  646. XFS_BUF_UNREAD(sbp);
  647. XFS_BUF_UNDELAYWRITE(sbp);
  648. XFS_BUF_WRITE(sbp);
  649. XFS_BUF_UNASYNC(sbp);
  650. XFS_BUF_ORDERED(sbp);
  651. xfsbdstrat(mp, sbp);
  652. error = xfs_iowait(sbp);
  653. /*
  654. * Clear all the flags we set and possible error state in the
  655. * buffer. We only did the write to try out whether barriers
  656. * worked and shouldn't leave any traces in the superblock
  657. * buffer.
  658. */
  659. XFS_BUF_DONE(sbp);
  660. XFS_BUF_ERROR(sbp, 0);
  661. XFS_BUF_UNORDERED(sbp);
  662. xfs_buf_relse(sbp);
  663. return error;
  664. }
  665. void
  666. xfs_mountfs_check_barriers(xfs_mount_t *mp)
  667. {
  668. int error;
  669. if (mp->m_logdev_targp != mp->m_ddev_targp) {
  670. xfs_fs_cmn_err(CE_NOTE, mp,
  671. "Disabling barriers, not supported with external log device");
  672. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  673. return;
  674. }
  675. if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
  676. QUEUE_ORDERED_NONE) {
  677. xfs_fs_cmn_err(CE_NOTE, mp,
  678. "Disabling barriers, not supported by the underlying device");
  679. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  680. return;
  681. }
  682. if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
  683. xfs_fs_cmn_err(CE_NOTE, mp,
  684. "Disabling barriers, underlying device is readonly");
  685. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  686. return;
  687. }
  688. error = xfs_barrier_test(mp);
  689. if (error) {
  690. xfs_fs_cmn_err(CE_NOTE, mp,
  691. "Disabling barriers, trial barrier write failed");
  692. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  693. return;
  694. }
  695. }
  696. void
  697. xfs_blkdev_issue_flush(
  698. xfs_buftarg_t *buftarg)
  699. {
  700. blkdev_issue_flush(buftarg->bt_bdev, NULL);
  701. }
  702. STATIC struct inode *
  703. xfs_fs_alloc_inode(
  704. struct super_block *sb)
  705. {
  706. bhv_vnode_t *vp;
  707. vp = kmem_zone_alloc(xfs_vnode_zone, KM_SLEEP);
  708. if (unlikely(!vp))
  709. return NULL;
  710. return vn_to_inode(vp);
  711. }
  712. STATIC void
  713. xfs_fs_destroy_inode(
  714. struct inode *inode)
  715. {
  716. kmem_zone_free(xfs_vnode_zone, vn_from_inode(inode));
  717. }
  718. STATIC void
  719. xfs_fs_inode_init_once(
  720. kmem_zone_t *zonep,
  721. void *vnode)
  722. {
  723. inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
  724. }
  725. STATIC int
  726. xfs_init_zones(void)
  727. {
  728. xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
  729. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
  730. KM_ZONE_SPREAD,
  731. xfs_fs_inode_init_once);
  732. if (!xfs_vnode_zone)
  733. goto out;
  734. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  735. if (!xfs_ioend_zone)
  736. goto out_destroy_vnode_zone;
  737. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  738. xfs_ioend_zone);
  739. if (!xfs_ioend_pool)
  740. goto out_free_ioend_zone;
  741. return 0;
  742. out_free_ioend_zone:
  743. kmem_zone_destroy(xfs_ioend_zone);
  744. out_destroy_vnode_zone:
  745. kmem_zone_destroy(xfs_vnode_zone);
  746. out:
  747. return -ENOMEM;
  748. }
  749. STATIC void
  750. xfs_destroy_zones(void)
  751. {
  752. mempool_destroy(xfs_ioend_pool);
  753. kmem_zone_destroy(xfs_vnode_zone);
  754. kmem_zone_destroy(xfs_ioend_zone);
  755. }
  756. /*
  757. * Attempt to flush the inode, this will actually fail
  758. * if the inode is pinned, but we dirty the inode again
  759. * at the point when it is unpinned after a log write,
  760. * since this is when the inode itself becomes flushable.
  761. */
  762. STATIC int
  763. xfs_fs_write_inode(
  764. struct inode *inode,
  765. int sync)
  766. {
  767. int error = 0, flags = FLUSH_INODE;
  768. xfs_itrace_entry(XFS_I(inode));
  769. if (sync) {
  770. filemap_fdatawait(inode->i_mapping);
  771. flags |= FLUSH_SYNC;
  772. }
  773. error = xfs_inode_flush(XFS_I(inode), flags);
  774. /*
  775. * if we failed to write out the inode then mark
  776. * it dirty again so we'll try again later.
  777. */
  778. if (error)
  779. mark_inode_dirty_sync(inode);
  780. return -error;
  781. }
  782. STATIC void
  783. xfs_fs_clear_inode(
  784. struct inode *inode)
  785. {
  786. xfs_inode_t *ip = XFS_I(inode);
  787. /*
  788. * ip can be null when xfs_iget_core calls xfs_idestroy if we
  789. * find an inode with di_mode == 0 but without IGET_CREATE set.
  790. */
  791. if (ip) {
  792. xfs_itrace_entry(ip);
  793. XFS_STATS_INC(vn_rele);
  794. XFS_STATS_INC(vn_remove);
  795. XFS_STATS_INC(vn_reclaim);
  796. XFS_STATS_DEC(vn_active);
  797. xfs_inactive(ip);
  798. xfs_iflags_clear(ip, XFS_IMODIFIED);
  799. if (xfs_reclaim(ip))
  800. panic("%s: cannot reclaim 0x%p\n", __FUNCTION__, inode);
  801. }
  802. ASSERT(XFS_I(inode) == NULL);
  803. }
  804. /*
  805. * Enqueue a work item to be picked up by the vfs xfssyncd thread.
  806. * Doing this has two advantages:
  807. * - It saves on stack space, which is tight in certain situations
  808. * - It can be used (with care) as a mechanism to avoid deadlocks.
  809. * Flushing while allocating in a full filesystem requires both.
  810. */
  811. STATIC void
  812. xfs_syncd_queue_work(
  813. struct xfs_mount *mp,
  814. void *data,
  815. void (*syncer)(struct xfs_mount *, void *))
  816. {
  817. struct bhv_vfs_sync_work *work;
  818. work = kmem_alloc(sizeof(struct bhv_vfs_sync_work), KM_SLEEP);
  819. INIT_LIST_HEAD(&work->w_list);
  820. work->w_syncer = syncer;
  821. work->w_data = data;
  822. work->w_mount = mp;
  823. spin_lock(&mp->m_sync_lock);
  824. list_add_tail(&work->w_list, &mp->m_sync_list);
  825. spin_unlock(&mp->m_sync_lock);
  826. wake_up_process(mp->m_sync_task);
  827. }
  828. /*
  829. * Flush delayed allocate data, attempting to free up reserved space
  830. * from existing allocations. At this point a new allocation attempt
  831. * has failed with ENOSPC and we are in the process of scratching our
  832. * heads, looking about for more room...
  833. */
  834. STATIC void
  835. xfs_flush_inode_work(
  836. struct xfs_mount *mp,
  837. void *arg)
  838. {
  839. struct inode *inode = arg;
  840. filemap_flush(inode->i_mapping);
  841. iput(inode);
  842. }
  843. void
  844. xfs_flush_inode(
  845. xfs_inode_t *ip)
  846. {
  847. struct inode *inode = ip->i_vnode;
  848. igrab(inode);
  849. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
  850. delay(msecs_to_jiffies(500));
  851. }
  852. /*
  853. * This is the "bigger hammer" version of xfs_flush_inode_work...
  854. * (IOW, "If at first you don't succeed, use a Bigger Hammer").
  855. */
  856. STATIC void
  857. xfs_flush_device_work(
  858. struct xfs_mount *mp,
  859. void *arg)
  860. {
  861. struct inode *inode = arg;
  862. sync_blockdev(mp->m_super->s_bdev);
  863. iput(inode);
  864. }
  865. void
  866. xfs_flush_device(
  867. xfs_inode_t *ip)
  868. {
  869. struct inode *inode = vn_to_inode(XFS_ITOV(ip));
  870. igrab(inode);
  871. xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
  872. delay(msecs_to_jiffies(500));
  873. xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
  874. }
  875. STATIC void
  876. xfs_sync_worker(
  877. struct xfs_mount *mp,
  878. void *unused)
  879. {
  880. int error;
  881. if (!(mp->m_flags & XFS_MOUNT_RDONLY))
  882. error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR |
  883. SYNC_REFCACHE | SYNC_SUPER);
  884. mp->m_sync_seq++;
  885. wake_up(&mp->m_wait_single_sync_task);
  886. }
  887. STATIC int
  888. xfssyncd(
  889. void *arg)
  890. {
  891. struct xfs_mount *mp = arg;
  892. long timeleft;
  893. bhv_vfs_sync_work_t *work, *n;
  894. LIST_HEAD (tmp);
  895. set_freezable();
  896. timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10);
  897. for (;;) {
  898. timeleft = schedule_timeout_interruptible(timeleft);
  899. /* swsusp */
  900. try_to_freeze();
  901. if (kthread_should_stop() && list_empty(&mp->m_sync_list))
  902. break;
  903. spin_lock(&mp->m_sync_lock);
  904. /*
  905. * We can get woken by laptop mode, to do a sync -
  906. * that's the (only!) case where the list would be
  907. * empty with time remaining.
  908. */
  909. if (!timeleft || list_empty(&mp->m_sync_list)) {
  910. if (!timeleft)
  911. timeleft = xfs_syncd_centisecs *
  912. msecs_to_jiffies(10);
  913. INIT_LIST_HEAD(&mp->m_sync_work.w_list);
  914. list_add_tail(&mp->m_sync_work.w_list,
  915. &mp->m_sync_list);
  916. }
  917. list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
  918. list_move(&work->w_list, &tmp);
  919. spin_unlock(&mp->m_sync_lock);
  920. list_for_each_entry_safe(work, n, &tmp, w_list) {
  921. (*work->w_syncer)(mp, work->w_data);
  922. list_del(&work->w_list);
  923. if (work == &mp->m_sync_work)
  924. continue;
  925. kmem_free(work, sizeof(struct bhv_vfs_sync_work));
  926. }
  927. }
  928. return 0;
  929. }
  930. STATIC void
  931. xfs_fs_put_super(
  932. struct super_block *sb)
  933. {
  934. struct xfs_mount *mp = XFS_M(sb);
  935. int error;
  936. kthread_stop(mp->m_sync_task);
  937. xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
  938. error = xfs_unmount(mp, 0, NULL);
  939. if (error)
  940. printk("XFS: unmount got error=%d\n", error);
  941. }
  942. STATIC void
  943. xfs_fs_write_super(
  944. struct super_block *sb)
  945. {
  946. if (!(sb->s_flags & MS_RDONLY))
  947. xfs_sync(XFS_M(sb), SYNC_FSDATA);
  948. sb->s_dirt = 0;
  949. }
  950. STATIC int
  951. xfs_fs_sync_super(
  952. struct super_block *sb,
  953. int wait)
  954. {
  955. struct xfs_mount *mp = XFS_M(sb);
  956. int error;
  957. int flags;
  958. /*
  959. * Treat a sync operation like a freeze. This is to work
  960. * around a race in sync_inodes() which works in two phases
  961. * - an asynchronous flush, which can write out an inode
  962. * without waiting for file size updates to complete, and a
  963. * synchronous flush, which wont do anything because the
  964. * async flush removed the inode's dirty flag. Also
  965. * sync_inodes() will not see any files that just have
  966. * outstanding transactions to be flushed because we don't
  967. * dirty the Linux inode until after the transaction I/O
  968. * completes.
  969. */
  970. if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
  971. /*
  972. * First stage of freeze - no more writers will make progress
  973. * now we are here, so we flush delwri and delalloc buffers
  974. * here, then wait for all I/O to complete. Data is frozen at
  975. * that point. Metadata is not frozen, transactions can still
  976. * occur here so don't bother flushing the buftarg (i.e
  977. * SYNC_QUIESCE) because it'll just get dirty again.
  978. */
  979. flags = SYNC_DATA_QUIESCE;
  980. } else
  981. flags = SYNC_FSDATA;
  982. error = xfs_sync(mp, flags);
  983. sb->s_dirt = 0;
  984. if (unlikely(laptop_mode)) {
  985. int prev_sync_seq = mp->m_sync_seq;
  986. /*
  987. * The disk must be active because we're syncing.
  988. * We schedule xfssyncd now (now that the disk is
  989. * active) instead of later (when it might not be).
  990. */
  991. wake_up_process(mp->m_sync_task);
  992. /*
  993. * We have to wait for the sync iteration to complete.
  994. * If we don't, the disk activity caused by the sync
  995. * will come after the sync is completed, and that
  996. * triggers another sync from laptop mode.
  997. */
  998. wait_event(mp->m_wait_single_sync_task,
  999. mp->m_sync_seq != prev_sync_seq);
  1000. }
  1001. return -error;
  1002. }
  1003. STATIC int
  1004. xfs_fs_statfs(
  1005. struct dentry *dentry,
  1006. struct kstatfs *statp)
  1007. {
  1008. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  1009. xfs_sb_t *sbp = &mp->m_sb;
  1010. __uint64_t fakeinos, id;
  1011. xfs_extlen_t lsize;
  1012. statp->f_type = XFS_SB_MAGIC;
  1013. statp->f_namelen = MAXNAMELEN - 1;
  1014. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  1015. statp->f_fsid.val[0] = (u32)id;
  1016. statp->f_fsid.val[1] = (u32)(id >> 32);
  1017. xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
  1018. spin_lock(&mp->m_sb_lock);
  1019. statp->f_bsize = sbp->sb_blocksize;
  1020. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  1021. statp->f_blocks = sbp->sb_dblocks - lsize;
  1022. statp->f_bfree = statp->f_bavail =
  1023. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  1024. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  1025. #if XFS_BIG_INUMS
  1026. fakeinos += mp->m_inoadd;
  1027. #endif
  1028. statp->f_files =
  1029. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  1030. if (mp->m_maxicount)
  1031. #if XFS_BIG_INUMS
  1032. if (!mp->m_inoadd)
  1033. #endif
  1034. statp->f_files = min_t(typeof(statp->f_files),
  1035. statp->f_files,
  1036. mp->m_maxicount);
  1037. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  1038. spin_unlock(&mp->m_sb_lock);
  1039. XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
  1040. return 0;
  1041. }
  1042. STATIC int
  1043. xfs_fs_remount(
  1044. struct super_block *sb,
  1045. int *flags,
  1046. char *options)
  1047. {
  1048. struct xfs_mount *mp = XFS_M(sb);
  1049. struct xfs_mount_args *args = xfs_args_allocate(sb, 0);
  1050. int error;
  1051. error = xfs_parseargs(mp, options, args, 1);
  1052. if (!error)
  1053. error = xfs_mntupdate(mp, flags, args);
  1054. kmem_free(args, sizeof(*args));
  1055. return -error;
  1056. }
  1057. /*
  1058. * Second stage of a freeze. The data is already frozen so we only
  1059. * need to take care of themetadata. Once that's done write a dummy
  1060. * record to dirty the log in case of a crash while frozen.
  1061. */
  1062. STATIC void
  1063. xfs_fs_lockfs(
  1064. struct super_block *sb)
  1065. {
  1066. struct xfs_mount *mp = XFS_M(sb);
  1067. xfs_attr_quiesce(mp);
  1068. xfs_fs_log_dummy(mp);
  1069. }
  1070. STATIC int
  1071. xfs_fs_show_options(
  1072. struct seq_file *m,
  1073. struct vfsmount *mnt)
  1074. {
  1075. return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
  1076. }
  1077. STATIC int
  1078. xfs_fs_quotasync(
  1079. struct super_block *sb,
  1080. int type)
  1081. {
  1082. return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
  1083. }
  1084. STATIC int
  1085. xfs_fs_getxstate(
  1086. struct super_block *sb,
  1087. struct fs_quota_stat *fqs)
  1088. {
  1089. return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
  1090. }
  1091. STATIC int
  1092. xfs_fs_setxstate(
  1093. struct super_block *sb,
  1094. unsigned int flags,
  1095. int op)
  1096. {
  1097. return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
  1098. }
  1099. STATIC int
  1100. xfs_fs_getxquota(
  1101. struct super_block *sb,
  1102. int type,
  1103. qid_t id,
  1104. struct fs_disk_quota *fdq)
  1105. {
  1106. return -XFS_QM_QUOTACTL(XFS_M(sb),
  1107. (type == USRQUOTA) ? Q_XGETQUOTA :
  1108. ((type == GRPQUOTA) ? Q_XGETGQUOTA :
  1109. Q_XGETPQUOTA), id, (caddr_t)fdq);
  1110. }
  1111. STATIC int
  1112. xfs_fs_setxquota(
  1113. struct super_block *sb,
  1114. int type,
  1115. qid_t id,
  1116. struct fs_disk_quota *fdq)
  1117. {
  1118. return -XFS_QM_QUOTACTL(XFS_M(sb),
  1119. (type == USRQUOTA) ? Q_XSETQLIM :
  1120. ((type == GRPQUOTA) ? Q_XSETGQLIM :
  1121. Q_XSETPQLIM), id, (caddr_t)fdq);
  1122. }
  1123. STATIC int
  1124. xfs_fs_fill_super(
  1125. struct super_block *sb,
  1126. void *data,
  1127. int silent)
  1128. {
  1129. struct inode *rootvp;
  1130. struct xfs_mount *mp = NULL;
  1131. struct xfs_mount_args *args = xfs_args_allocate(sb, silent);
  1132. int error;
  1133. mp = xfs_mount_init();
  1134. INIT_LIST_HEAD(&mp->m_sync_list);
  1135. spin_lock_init(&mp->m_sync_lock);
  1136. init_waitqueue_head(&mp->m_wait_single_sync_task);
  1137. mp->m_super = sb;
  1138. sb->s_fs_info = mp;
  1139. if (sb->s_flags & MS_RDONLY)
  1140. mp->m_flags |= XFS_MOUNT_RDONLY;
  1141. error = xfs_parseargs(mp, (char *)data, args, 0);
  1142. if (error)
  1143. goto fail_vfsop;
  1144. sb_min_blocksize(sb, BBSIZE);
  1145. sb->s_export_op = &xfs_export_operations;
  1146. sb->s_qcop = &xfs_quotactl_operations;
  1147. sb->s_op = &xfs_super_operations;
  1148. error = xfs_mount(mp, args, NULL);
  1149. if (error)
  1150. goto fail_vfsop;
  1151. sb->s_dirt = 1;
  1152. sb->s_magic = XFS_SB_MAGIC;
  1153. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1154. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1155. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1156. sb->s_time_gran = 1;
  1157. set_posix_acl_flag(sb);
  1158. error = xfs_root(mp, &rootvp);
  1159. if (error)
  1160. goto fail_unmount;
  1161. sb->s_root = d_alloc_root(vn_to_inode(rootvp));
  1162. if (!sb->s_root) {
  1163. error = ENOMEM;
  1164. goto fail_vnrele;
  1165. }
  1166. if (is_bad_inode(sb->s_root->d_inode)) {
  1167. error = EINVAL;
  1168. goto fail_vnrele;
  1169. }
  1170. mp->m_sync_work.w_syncer = xfs_sync_worker;
  1171. mp->m_sync_work.w_mount = mp;
  1172. mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
  1173. if (IS_ERR(mp->m_sync_task)) {
  1174. error = -PTR_ERR(mp->m_sync_task);
  1175. goto fail_vnrele;
  1176. }
  1177. xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
  1178. kmem_free(args, sizeof(*args));
  1179. return 0;
  1180. fail_vnrele:
  1181. if (sb->s_root) {
  1182. dput(sb->s_root);
  1183. sb->s_root = NULL;
  1184. } else {
  1185. VN_RELE(rootvp);
  1186. }
  1187. fail_unmount:
  1188. xfs_unmount(mp, 0, NULL);
  1189. fail_vfsop:
  1190. kmem_free(args, sizeof(*args));
  1191. return -error;
  1192. }
  1193. STATIC int
  1194. xfs_fs_get_sb(
  1195. struct file_system_type *fs_type,
  1196. int flags,
  1197. const char *dev_name,
  1198. void *data,
  1199. struct vfsmount *mnt)
  1200. {
  1201. return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
  1202. mnt);
  1203. }
  1204. static struct super_operations xfs_super_operations = {
  1205. .alloc_inode = xfs_fs_alloc_inode,
  1206. .destroy_inode = xfs_fs_destroy_inode,
  1207. .write_inode = xfs_fs_write_inode,
  1208. .clear_inode = xfs_fs_clear_inode,
  1209. .put_super = xfs_fs_put_super,
  1210. .write_super = xfs_fs_write_super,
  1211. .sync_fs = xfs_fs_sync_super,
  1212. .write_super_lockfs = xfs_fs_lockfs,
  1213. .statfs = xfs_fs_statfs,
  1214. .remount_fs = xfs_fs_remount,
  1215. .show_options = xfs_fs_show_options,
  1216. };
  1217. static struct quotactl_ops xfs_quotactl_operations = {
  1218. .quota_sync = xfs_fs_quotasync,
  1219. .get_xstate = xfs_fs_getxstate,
  1220. .set_xstate = xfs_fs_setxstate,
  1221. .get_xquota = xfs_fs_getxquota,
  1222. .set_xquota = xfs_fs_setxquota,
  1223. };
  1224. static struct file_system_type xfs_fs_type = {
  1225. .owner = THIS_MODULE,
  1226. .name = "xfs",
  1227. .get_sb = xfs_fs_get_sb,
  1228. .kill_sb = kill_block_super,
  1229. .fs_flags = FS_REQUIRES_DEV,
  1230. };
  1231. STATIC int __init
  1232. init_xfs_fs( void )
  1233. {
  1234. int error;
  1235. static char message[] __initdata = KERN_INFO \
  1236. XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled\n";
  1237. printk(message);
  1238. ktrace_init(64);
  1239. error = xfs_init_zones();
  1240. if (error < 0)
  1241. goto undo_zones;
  1242. error = xfs_buf_init();
  1243. if (error < 0)
  1244. goto undo_buffers;
  1245. vn_init();
  1246. xfs_init();
  1247. uuid_init();
  1248. vfs_initquota();
  1249. error = register_filesystem(&xfs_fs_type);
  1250. if (error)
  1251. goto undo_register;
  1252. return 0;
  1253. undo_register:
  1254. xfs_buf_terminate();
  1255. undo_buffers:
  1256. xfs_destroy_zones();
  1257. undo_zones:
  1258. return error;
  1259. }
  1260. STATIC void __exit
  1261. exit_xfs_fs( void )
  1262. {
  1263. vfs_exitquota();
  1264. unregister_filesystem(&xfs_fs_type);
  1265. xfs_cleanup();
  1266. xfs_buf_terminate();
  1267. xfs_destroy_zones();
  1268. ktrace_uninit();
  1269. }
  1270. module_init(init_xfs_fs);
  1271. module_exit(exit_xfs_fs);
  1272. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1273. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1274. MODULE_LICENSE("GPL");