xfs_super.c 49 KB

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