xfs_super.c 38 KB

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