xfs_super.c 55 KB

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