xfs_vfsops.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132
  1. /*
  2. * Copyright (c) 2000-2005 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_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_bit.h"
  22. #include "xfs_log.h"
  23. #include "xfs_inum.h"
  24. #include "xfs_trans.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_ag.h"
  27. #include "xfs_dir2.h"
  28. #include "xfs_dmapi.h"
  29. #include "xfs_mount.h"
  30. #include "xfs_da_btree.h"
  31. #include "xfs_bmap_btree.h"
  32. #include "xfs_ialloc_btree.h"
  33. #include "xfs_alloc_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_inode_item.h"
  39. #include "xfs_btree.h"
  40. #include "xfs_alloc.h"
  41. #include "xfs_ialloc.h"
  42. #include "xfs_quota.h"
  43. #include "xfs_error.h"
  44. #include "xfs_bmap.h"
  45. #include "xfs_rw.h"
  46. #include "xfs_refcache.h"
  47. #include "xfs_buf_item.h"
  48. #include "xfs_log_priv.h"
  49. #include "xfs_dir2_trace.h"
  50. #include "xfs_extfree_item.h"
  51. #include "xfs_acl.h"
  52. #include "xfs_attr.h"
  53. #include "xfs_clnt.h"
  54. #include "xfs_mru_cache.h"
  55. #include "xfs_filestream.h"
  56. #include "xfs_fsops.h"
  57. #include "xfs_vnodeops.h"
  58. #include "xfs_vfsops.h"
  59. int
  60. xfs_init(void)
  61. {
  62. extern kmem_zone_t *xfs_bmap_free_item_zone;
  63. extern kmem_zone_t *xfs_btree_cur_zone;
  64. extern kmem_zone_t *xfs_trans_zone;
  65. extern kmem_zone_t *xfs_buf_item_zone;
  66. extern kmem_zone_t *xfs_dabuf_zone;
  67. #ifdef XFS_DABUF_DEBUG
  68. extern lock_t xfs_dabuf_global_lock;
  69. spinlock_init(&xfs_dabuf_global_lock, "xfsda");
  70. #endif
  71. /*
  72. * Initialize all of the zone allocators we use.
  73. */
  74. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  75. "xfs_bmap_free_item");
  76. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  77. "xfs_btree_cur");
  78. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  79. xfs_da_state_zone =
  80. kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
  81. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  82. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  83. xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
  84. xfs_mru_cache_init();
  85. xfs_filestream_init();
  86. /*
  87. * The size of the zone allocated buf log item is the maximum
  88. * size possible under XFS. This wastes a little bit of memory,
  89. * but it is much faster.
  90. */
  91. xfs_buf_item_zone =
  92. kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  93. (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
  94. NBWORD) * sizeof(int))),
  95. "xfs_buf_item");
  96. xfs_efd_zone =
  97. kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  98. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  99. sizeof(xfs_extent_t))),
  100. "xfs_efd_item");
  101. xfs_efi_zone =
  102. kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  103. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  104. sizeof(xfs_extent_t))),
  105. "xfs_efi_item");
  106. /*
  107. * These zones warrant special memory allocator hints
  108. */
  109. xfs_inode_zone =
  110. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  111. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
  112. KM_ZONE_SPREAD, NULL);
  113. xfs_ili_zone =
  114. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  115. KM_ZONE_SPREAD, NULL);
  116. xfs_icluster_zone =
  117. kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
  118. KM_ZONE_SPREAD, NULL);
  119. /*
  120. * Allocate global trace buffers.
  121. */
  122. #ifdef XFS_ALLOC_TRACE
  123. xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
  124. #endif
  125. #ifdef XFS_BMAP_TRACE
  126. xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
  127. #endif
  128. #ifdef XFS_BMBT_TRACE
  129. xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
  130. #endif
  131. #ifdef XFS_ATTR_TRACE
  132. xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
  133. #endif
  134. #ifdef XFS_DIR2_TRACE
  135. xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
  136. #endif
  137. xfs_dir_startup();
  138. #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
  139. xfs_error_test_init();
  140. #endif /* DEBUG || INDUCE_IO_ERROR */
  141. xfs_init_procfs();
  142. xfs_sysctl_register();
  143. return 0;
  144. }
  145. void
  146. xfs_cleanup(void)
  147. {
  148. extern kmem_zone_t *xfs_bmap_free_item_zone;
  149. extern kmem_zone_t *xfs_btree_cur_zone;
  150. extern kmem_zone_t *xfs_inode_zone;
  151. extern kmem_zone_t *xfs_trans_zone;
  152. extern kmem_zone_t *xfs_da_state_zone;
  153. extern kmem_zone_t *xfs_dabuf_zone;
  154. extern kmem_zone_t *xfs_efd_zone;
  155. extern kmem_zone_t *xfs_efi_zone;
  156. extern kmem_zone_t *xfs_buf_item_zone;
  157. extern kmem_zone_t *xfs_icluster_zone;
  158. xfs_cleanup_procfs();
  159. xfs_sysctl_unregister();
  160. xfs_refcache_destroy();
  161. xfs_filestream_uninit();
  162. xfs_mru_cache_uninit();
  163. xfs_acl_zone_destroy(xfs_acl_zone);
  164. #ifdef XFS_DIR2_TRACE
  165. ktrace_free(xfs_dir2_trace_buf);
  166. #endif
  167. #ifdef XFS_ATTR_TRACE
  168. ktrace_free(xfs_attr_trace_buf);
  169. #endif
  170. #ifdef XFS_BMBT_TRACE
  171. ktrace_free(xfs_bmbt_trace_buf);
  172. #endif
  173. #ifdef XFS_BMAP_TRACE
  174. ktrace_free(xfs_bmap_trace_buf);
  175. #endif
  176. #ifdef XFS_ALLOC_TRACE
  177. ktrace_free(xfs_alloc_trace_buf);
  178. #endif
  179. kmem_zone_destroy(xfs_bmap_free_item_zone);
  180. kmem_zone_destroy(xfs_btree_cur_zone);
  181. kmem_zone_destroy(xfs_inode_zone);
  182. kmem_zone_destroy(xfs_trans_zone);
  183. kmem_zone_destroy(xfs_da_state_zone);
  184. kmem_zone_destroy(xfs_dabuf_zone);
  185. kmem_zone_destroy(xfs_buf_item_zone);
  186. kmem_zone_destroy(xfs_efd_zone);
  187. kmem_zone_destroy(xfs_efi_zone);
  188. kmem_zone_destroy(xfs_ifork_zone);
  189. kmem_zone_destroy(xfs_ili_zone);
  190. kmem_zone_destroy(xfs_icluster_zone);
  191. }
  192. /*
  193. * xfs_start_flags
  194. *
  195. * This function fills in xfs_mount_t fields based on mount args.
  196. * Note: the superblock has _not_ yet been read in.
  197. */
  198. STATIC int
  199. xfs_start_flags(
  200. struct bhv_vfs *vfs,
  201. struct xfs_mount_args *ap,
  202. struct xfs_mount *mp)
  203. {
  204. /* Values are in BBs */
  205. if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  206. /*
  207. * At this point the superblock has not been read
  208. * in, therefore we do not know the block size.
  209. * Before the mount call ends we will convert
  210. * these to FSBs.
  211. */
  212. mp->m_dalign = ap->sunit;
  213. mp->m_swidth = ap->swidth;
  214. }
  215. if (ap->logbufs != -1 &&
  216. ap->logbufs != 0 &&
  217. (ap->logbufs < XLOG_MIN_ICLOGS ||
  218. ap->logbufs > XLOG_MAX_ICLOGS)) {
  219. cmn_err(CE_WARN,
  220. "XFS: invalid logbufs value: %d [not %d-%d]",
  221. ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  222. return XFS_ERROR(EINVAL);
  223. }
  224. mp->m_logbufs = ap->logbufs;
  225. if (ap->logbufsize != -1 &&
  226. ap->logbufsize != 0 &&
  227. (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
  228. ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
  229. !is_power_of_2(ap->logbufsize))) {
  230. cmn_err(CE_WARN,
  231. "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  232. ap->logbufsize);
  233. return XFS_ERROR(EINVAL);
  234. }
  235. mp->m_logbsize = ap->logbufsize;
  236. mp->m_fsname_len = strlen(ap->fsname) + 1;
  237. mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
  238. strcpy(mp->m_fsname, ap->fsname);
  239. if (ap->rtname[0]) {
  240. mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
  241. strcpy(mp->m_rtname, ap->rtname);
  242. }
  243. if (ap->logname[0]) {
  244. mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
  245. strcpy(mp->m_logname, ap->logname);
  246. }
  247. if (ap->flags & XFSMNT_WSYNC)
  248. mp->m_flags |= XFS_MOUNT_WSYNC;
  249. #if XFS_BIG_INUMS
  250. if (ap->flags & XFSMNT_INO64) {
  251. mp->m_flags |= XFS_MOUNT_INO64;
  252. mp->m_inoadd = XFS_INO64_OFFSET;
  253. }
  254. #endif
  255. if (ap->flags & XFSMNT_RETERR)
  256. mp->m_flags |= XFS_MOUNT_RETERR;
  257. if (ap->flags & XFSMNT_NOALIGN)
  258. mp->m_flags |= XFS_MOUNT_NOALIGN;
  259. if (ap->flags & XFSMNT_SWALLOC)
  260. mp->m_flags |= XFS_MOUNT_SWALLOC;
  261. if (ap->flags & XFSMNT_OSYNCISOSYNC)
  262. mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
  263. if (ap->flags & XFSMNT_32BITINODES)
  264. mp->m_flags |= XFS_MOUNT_32BITINODES;
  265. if (ap->flags & XFSMNT_IOSIZE) {
  266. if (ap->iosizelog > XFS_MAX_IO_LOG ||
  267. ap->iosizelog < XFS_MIN_IO_LOG) {
  268. cmn_err(CE_WARN,
  269. "XFS: invalid log iosize: %d [not %d-%d]",
  270. ap->iosizelog, XFS_MIN_IO_LOG,
  271. XFS_MAX_IO_LOG);
  272. return XFS_ERROR(EINVAL);
  273. }
  274. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  275. mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
  276. }
  277. if (ap->flags & XFSMNT_IDELETE)
  278. mp->m_flags |= XFS_MOUNT_IDELETE;
  279. if (ap->flags & XFSMNT_DIRSYNC)
  280. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  281. if (ap->flags & XFSMNT_ATTR2)
  282. mp->m_flags |= XFS_MOUNT_ATTR2;
  283. if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
  284. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  285. /*
  286. * no recovery flag requires a read-only mount
  287. */
  288. if (ap->flags & XFSMNT_NORECOVERY) {
  289. if (!(vfs->vfs_flag & VFS_RDONLY)) {
  290. cmn_err(CE_WARN,
  291. "XFS: tried to mount a FS read-write without recovery!");
  292. return XFS_ERROR(EINVAL);
  293. }
  294. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  295. }
  296. if (ap->flags & XFSMNT_NOUUID)
  297. mp->m_flags |= XFS_MOUNT_NOUUID;
  298. if (ap->flags & XFSMNT_BARRIER)
  299. mp->m_flags |= XFS_MOUNT_BARRIER;
  300. else
  301. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  302. if (ap->flags2 & XFSMNT2_FILESTREAMS)
  303. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  304. if (ap->flags & XFSMNT_DMAPI)
  305. vfs->vfs_flag |= VFS_DMI;
  306. return 0;
  307. }
  308. /*
  309. * This function fills in xfs_mount_t fields based on mount args.
  310. * Note: the superblock _has_ now been read in.
  311. */
  312. STATIC int
  313. xfs_finish_flags(
  314. struct bhv_vfs *vfs,
  315. struct xfs_mount_args *ap,
  316. struct xfs_mount *mp)
  317. {
  318. int ronly = (vfs->vfs_flag & VFS_RDONLY);
  319. /* Fail a mount where the logbuf is smaller then the log stripe */
  320. if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
  321. if ((ap->logbufsize <= 0) &&
  322. (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
  323. mp->m_logbsize = mp->m_sb.sb_logsunit;
  324. } else if (ap->logbufsize > 0 &&
  325. ap->logbufsize < mp->m_sb.sb_logsunit) {
  326. cmn_err(CE_WARN,
  327. "XFS: logbuf size must be greater than or equal to log stripe size");
  328. return XFS_ERROR(EINVAL);
  329. }
  330. } else {
  331. /* Fail a mount if the logbuf is larger than 32K */
  332. if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
  333. cmn_err(CE_WARN,
  334. "XFS: logbuf size for version 1 logs must be 16K or 32K");
  335. return XFS_ERROR(EINVAL);
  336. }
  337. }
  338. if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
  339. mp->m_flags |= XFS_MOUNT_ATTR2;
  340. }
  341. /*
  342. * prohibit r/w mounts of read-only filesystems
  343. */
  344. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  345. cmn_err(CE_WARN,
  346. "XFS: cannot mount a read-only filesystem as read-write");
  347. return XFS_ERROR(EROFS);
  348. }
  349. /*
  350. * check for shared mount.
  351. */
  352. if (ap->flags & XFSMNT_SHARED) {
  353. if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
  354. return XFS_ERROR(EINVAL);
  355. /*
  356. * For IRIX 6.5, shared mounts must have the shared
  357. * version bit set, have the persistent readonly
  358. * field set, must be version 0 and can only be mounted
  359. * read-only.
  360. */
  361. if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
  362. (mp->m_sb.sb_shared_vn != 0))
  363. return XFS_ERROR(EINVAL);
  364. mp->m_flags |= XFS_MOUNT_SHARED;
  365. /*
  366. * Shared XFS V0 can't deal with DMI. Return EINVAL.
  367. */
  368. if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
  369. return XFS_ERROR(EINVAL);
  370. }
  371. if (ap->flags & XFSMNT_UQUOTA) {
  372. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  373. if (ap->flags & XFSMNT_UQUOTAENF)
  374. mp->m_qflags |= XFS_UQUOTA_ENFD;
  375. }
  376. if (ap->flags & XFSMNT_GQUOTA) {
  377. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  378. if (ap->flags & XFSMNT_GQUOTAENF)
  379. mp->m_qflags |= XFS_OQUOTA_ENFD;
  380. } else if (ap->flags & XFSMNT_PQUOTA) {
  381. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  382. if (ap->flags & XFSMNT_PQUOTAENF)
  383. mp->m_qflags |= XFS_OQUOTA_ENFD;
  384. }
  385. return 0;
  386. }
  387. /*
  388. * xfs_mount
  389. *
  390. * The file system configurations are:
  391. * (1) device (partition) with data and internal log
  392. * (2) logical volume with data and log subvolumes.
  393. * (3) logical volume with data, log, and realtime subvolumes.
  394. *
  395. * We only have to handle opening the log and realtime volumes here if
  396. * they are present. The data subvolume has already been opened by
  397. * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
  398. */
  399. int
  400. xfs_mount(
  401. struct xfs_mount *mp,
  402. struct xfs_mount_args *args,
  403. cred_t *credp)
  404. {
  405. struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
  406. struct block_device *ddev, *logdev, *rtdev;
  407. int flags = 0, error;
  408. ddev = vfsp->vfs_super->s_bdev;
  409. logdev = rtdev = NULL;
  410. error = xfs_dmops_get(mp, args);
  411. if (error)
  412. return error;
  413. error = xfs_qmops_get(mp, args);
  414. if (error)
  415. return error;
  416. mp->m_io_ops = xfs_iocore_xfs;
  417. if (args->flags & XFSMNT_QUIET)
  418. flags |= XFS_MFSI_QUIET;
  419. /*
  420. * Open real time and log devices - order is important.
  421. */
  422. if (args->logname[0]) {
  423. error = xfs_blkdev_get(mp, args->logname, &logdev);
  424. if (error)
  425. return error;
  426. }
  427. if (args->rtname[0]) {
  428. error = xfs_blkdev_get(mp, args->rtname, &rtdev);
  429. if (error) {
  430. xfs_blkdev_put(logdev);
  431. return error;
  432. }
  433. if (rtdev == ddev || rtdev == logdev) {
  434. cmn_err(CE_WARN,
  435. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  436. xfs_blkdev_put(logdev);
  437. xfs_blkdev_put(rtdev);
  438. return EINVAL;
  439. }
  440. }
  441. /*
  442. * Setup xfs_mount buffer target pointers
  443. */
  444. error = ENOMEM;
  445. mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
  446. if (!mp->m_ddev_targp) {
  447. xfs_blkdev_put(logdev);
  448. xfs_blkdev_put(rtdev);
  449. return error;
  450. }
  451. if (rtdev) {
  452. mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
  453. if (!mp->m_rtdev_targp) {
  454. xfs_blkdev_put(logdev);
  455. xfs_blkdev_put(rtdev);
  456. goto error0;
  457. }
  458. }
  459. mp->m_logdev_targp = (logdev && logdev != ddev) ?
  460. xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
  461. if (!mp->m_logdev_targp) {
  462. xfs_blkdev_put(logdev);
  463. xfs_blkdev_put(rtdev);
  464. goto error0;
  465. }
  466. /*
  467. * Setup flags based on mount(2) options and then the superblock
  468. */
  469. error = xfs_start_flags(vfsp, args, mp);
  470. if (error)
  471. goto error1;
  472. error = xfs_readsb(mp, flags);
  473. if (error)
  474. goto error1;
  475. error = xfs_finish_flags(vfsp, args, mp);
  476. if (error)
  477. goto error2;
  478. /*
  479. * Setup xfs_mount buffer target pointers based on superblock
  480. */
  481. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  482. mp->m_sb.sb_sectsize);
  483. if (!error && logdev && logdev != ddev) {
  484. unsigned int log_sector_size = BBSIZE;
  485. if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
  486. log_sector_size = mp->m_sb.sb_logsectsize;
  487. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  488. mp->m_sb.sb_blocksize,
  489. log_sector_size);
  490. }
  491. if (!error && rtdev)
  492. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  493. mp->m_sb.sb_blocksize,
  494. mp->m_sb.sb_sectsize);
  495. if (error)
  496. goto error2;
  497. if (mp->m_flags & XFS_MOUNT_BARRIER)
  498. xfs_mountfs_check_barriers(mp);
  499. if ((error = xfs_filestream_mount(mp)))
  500. goto error2;
  501. error = XFS_IOINIT(vfsp, args, flags);
  502. if (error)
  503. goto error2;
  504. XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
  505. return 0;
  506. error2:
  507. if (mp->m_sb_bp)
  508. xfs_freesb(mp);
  509. error1:
  510. xfs_binval(mp->m_ddev_targp);
  511. if (logdev && logdev != ddev)
  512. xfs_binval(mp->m_logdev_targp);
  513. if (rtdev)
  514. xfs_binval(mp->m_rtdev_targp);
  515. error0:
  516. xfs_unmountfs_close(mp, credp);
  517. xfs_qmops_put(mp);
  518. xfs_dmops_put(mp);
  519. return error;
  520. }
  521. int
  522. xfs_unmount(
  523. xfs_mount_t *mp,
  524. int flags,
  525. cred_t *credp)
  526. {
  527. bhv_vfs_t *vfsp = XFS_MTOVFS(mp);
  528. xfs_inode_t *rip;
  529. bhv_vnode_t *rvp;
  530. int unmount_event_wanted = 0;
  531. int unmount_event_flags = 0;
  532. int xfs_unmountfs_needed = 0;
  533. int error;
  534. rip = mp->m_rootip;
  535. rvp = XFS_ITOV(rip);
  536. #ifdef HAVE_DMAPI
  537. if (vfsp->vfs_flag & VFS_DMI) {
  538. error = XFS_SEND_PREUNMOUNT(mp, vfsp,
  539. rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
  540. NULL, NULL, 0, 0,
  541. (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
  542. 0:DM_FLAGS_UNWANTED);
  543. if (error)
  544. return XFS_ERROR(error);
  545. unmount_event_wanted = 1;
  546. unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
  547. 0 : DM_FLAGS_UNWANTED;
  548. }
  549. #endif
  550. /*
  551. * First blow any referenced inode from this file system
  552. * out of the reference cache, and delete the timer.
  553. */
  554. xfs_refcache_purge_mp(mp);
  555. /*
  556. * Blow away any referenced inode in the filestreams cache.
  557. * This can and will cause log traffic as inodes go inactive
  558. * here.
  559. */
  560. xfs_filestream_unmount(mp);
  561. XFS_bflush(mp->m_ddev_targp);
  562. error = xfs_unmount_flush(mp, 0);
  563. if (error)
  564. goto out;
  565. ASSERT(vn_count(rvp) == 1);
  566. /*
  567. * Drop the reference count
  568. */
  569. VN_RELE(rvp);
  570. /*
  571. * If we're forcing a shutdown, typically because of a media error,
  572. * we want to make sure we invalidate dirty pages that belong to
  573. * referenced vnodes as well.
  574. */
  575. if (XFS_FORCED_SHUTDOWN(mp)) {
  576. error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
  577. ASSERT(error != EFSCORRUPTED);
  578. }
  579. xfs_unmountfs_needed = 1;
  580. out:
  581. /* Send DMAPI event, if required.
  582. * Then do xfs_unmountfs() if needed.
  583. * Then return error (or zero).
  584. */
  585. if (unmount_event_wanted) {
  586. /* Note: mp structure must still exist for
  587. * XFS_SEND_UNMOUNT() call.
  588. */
  589. XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
  590. DM_RIGHT_NULL, 0, error, unmount_event_flags);
  591. }
  592. if (xfs_unmountfs_needed) {
  593. /*
  594. * Call common unmount function to flush to disk
  595. * and free the super block buffer & mount structures.
  596. */
  597. xfs_unmountfs(mp, credp);
  598. xfs_qmops_put(mp);
  599. xfs_dmops_put(mp);
  600. kmem_free(mp, sizeof(xfs_mount_t));
  601. }
  602. return XFS_ERROR(error);
  603. }
  604. STATIC int
  605. xfs_quiesce_fs(
  606. xfs_mount_t *mp)
  607. {
  608. int count = 0, pincount;
  609. xfs_refcache_purge_mp(mp);
  610. xfs_flush_buftarg(mp->m_ddev_targp, 0);
  611. xfs_finish_reclaim_all(mp, 0);
  612. /* This loop must run at least twice.
  613. * The first instance of the loop will flush
  614. * most meta data but that will generate more
  615. * meta data (typically directory updates).
  616. * Which then must be flushed and logged before
  617. * we can write the unmount record.
  618. */
  619. do {
  620. xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
  621. pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
  622. if (!pincount) {
  623. delay(50);
  624. count++;
  625. }
  626. } while (count < 2);
  627. return 0;
  628. }
  629. /*
  630. * Second stage of a quiesce. The data is already synced, now we have to take
  631. * care of the metadata. New transactions are already blocked, so we need to
  632. * wait for any remaining transactions to drain out before proceding.
  633. */
  634. STATIC void
  635. xfs_attr_quiesce(
  636. xfs_mount_t *mp)
  637. {
  638. /* wait for all modifications to complete */
  639. while (atomic_read(&mp->m_active_trans) > 0)
  640. delay(100);
  641. /* flush inodes and push all remaining buffers out to disk */
  642. xfs_quiesce_fs(mp);
  643. ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
  644. /* Push the superblock and write an unmount record */
  645. xfs_log_sbcount(mp, 1);
  646. xfs_log_unmount_write(mp);
  647. xfs_unmountfs_writesb(mp);
  648. }
  649. int
  650. xfs_mntupdate(
  651. struct xfs_mount *mp,
  652. int *flags,
  653. struct xfs_mount_args *args)
  654. {
  655. struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
  656. if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
  657. if (vfsp->vfs_flag & VFS_RDONLY)
  658. vfsp->vfs_flag &= ~VFS_RDONLY;
  659. if (args->flags & XFSMNT_BARRIER) {
  660. mp->m_flags |= XFS_MOUNT_BARRIER;
  661. xfs_mountfs_check_barriers(mp);
  662. } else {
  663. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  664. }
  665. } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
  666. xfs_filestream_flush(mp);
  667. xfs_sync(mp, SYNC_DATA_QUIESCE);
  668. xfs_attr_quiesce(mp);
  669. vfsp->vfs_flag |= VFS_RDONLY;
  670. }
  671. return 0;
  672. }
  673. /*
  674. * xfs_unmount_flush implements a set of flush operation on special
  675. * inodes, which are needed as a separate set of operations so that
  676. * they can be called as part of relocation process.
  677. */
  678. int
  679. xfs_unmount_flush(
  680. xfs_mount_t *mp, /* Mount structure we are getting
  681. rid of. */
  682. int relocation) /* Called from vfs relocation. */
  683. {
  684. xfs_inode_t *rip = mp->m_rootip;
  685. xfs_inode_t *rbmip;
  686. xfs_inode_t *rsumip = NULL;
  687. bhv_vnode_t *rvp = XFS_ITOV(rip);
  688. int error;
  689. xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
  690. xfs_iflock(rip);
  691. /*
  692. * Flush out the real time inodes.
  693. */
  694. if ((rbmip = mp->m_rbmip) != NULL) {
  695. xfs_ilock(rbmip, XFS_ILOCK_EXCL);
  696. xfs_iflock(rbmip);
  697. error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
  698. xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
  699. if (error == EFSCORRUPTED)
  700. goto fscorrupt_out;
  701. ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
  702. rsumip = mp->m_rsumip;
  703. xfs_ilock(rsumip, XFS_ILOCK_EXCL);
  704. xfs_iflock(rsumip);
  705. error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
  706. xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
  707. if (error == EFSCORRUPTED)
  708. goto fscorrupt_out;
  709. ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
  710. }
  711. /*
  712. * Synchronously flush root inode to disk
  713. */
  714. error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
  715. if (error == EFSCORRUPTED)
  716. goto fscorrupt_out2;
  717. if (vn_count(rvp) != 1 && !relocation) {
  718. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  719. return XFS_ERROR(EBUSY);
  720. }
  721. /*
  722. * Release dquot that rootinode, rbmino and rsumino might be holding,
  723. * flush and purge the quota inodes.
  724. */
  725. error = XFS_QM_UNMOUNT(mp);
  726. if (error == EFSCORRUPTED)
  727. goto fscorrupt_out2;
  728. if (rbmip) {
  729. VN_RELE(XFS_ITOV(rbmip));
  730. VN_RELE(XFS_ITOV(rsumip));
  731. }
  732. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  733. return 0;
  734. fscorrupt_out:
  735. xfs_ifunlock(rip);
  736. fscorrupt_out2:
  737. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  738. return XFS_ERROR(EFSCORRUPTED);
  739. }
  740. /*
  741. * xfs_root extracts the root vnode from a vfs.
  742. *
  743. * vfsp -- the vfs struct for the desired file system
  744. * vpp -- address of the caller's vnode pointer which should be
  745. * set to the desired fs root vnode
  746. */
  747. int
  748. xfs_root(
  749. xfs_mount_t *mp,
  750. bhv_vnode_t **vpp)
  751. {
  752. bhv_vnode_t *vp;
  753. vp = XFS_ITOV(mp->m_rootip);
  754. VN_HOLD(vp);
  755. *vpp = vp;
  756. return 0;
  757. }
  758. /*
  759. * xfs_statvfs
  760. *
  761. * Fill in the statvfs structure for the given file system. We use
  762. * the superblock lock in the mount structure to ensure a consistent
  763. * snapshot of the counters returned.
  764. */
  765. int
  766. xfs_statvfs(
  767. xfs_mount_t *mp,
  768. bhv_statvfs_t *statp,
  769. bhv_vnode_t *vp)
  770. {
  771. __uint64_t fakeinos;
  772. xfs_extlen_t lsize;
  773. xfs_sb_t *sbp;
  774. unsigned long s;
  775. sbp = &(mp->m_sb);
  776. statp->f_type = XFS_SB_MAGIC;
  777. xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
  778. s = XFS_SB_LOCK(mp);
  779. statp->f_bsize = sbp->sb_blocksize;
  780. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  781. statp->f_blocks = sbp->sb_dblocks - lsize;
  782. statp->f_bfree = statp->f_bavail =
  783. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  784. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  785. #if XFS_BIG_INUMS
  786. fakeinos += mp->m_inoadd;
  787. #endif
  788. statp->f_files =
  789. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  790. if (mp->m_maxicount)
  791. #if XFS_BIG_INUMS
  792. if (!mp->m_inoadd)
  793. #endif
  794. statp->f_files = min_t(typeof(statp->f_files),
  795. statp->f_files,
  796. mp->m_maxicount);
  797. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  798. XFS_SB_UNLOCK(mp, s);
  799. xfs_statvfs_fsid(statp, mp);
  800. statp->f_namelen = MAXNAMELEN - 1;
  801. if (vp)
  802. XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
  803. return 0;
  804. }
  805. /*
  806. * xfs_sync flushes any pending I/O to file system vfsp.
  807. *
  808. * This routine is called by vfs_sync() to make sure that things make it
  809. * out to disk eventually, on sync() system calls to flush out everything,
  810. * and when the file system is unmounted. For the vfs_sync() case, all
  811. * we really need to do is sync out the log to make all of our meta-data
  812. * updates permanent (except for timestamps). For calls from pflushd(),
  813. * dirty pages are kept moving by calling pdflush() on the inodes
  814. * containing them. We also flush the inodes that we can lock without
  815. * sleeping and the superblock if we can lock it without sleeping from
  816. * vfs_sync() so that items at the tail of the log are always moving out.
  817. *
  818. * Flags:
  819. * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
  820. * to sleep if we can help it. All we really need
  821. * to do is ensure that the log is synced at least
  822. * periodically. We also push the inodes and
  823. * superblock if we can lock them without sleeping
  824. * and they are not pinned.
  825. * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
  826. * set, then we really want to lock each inode and flush
  827. * it.
  828. * SYNC_WAIT - All the flushes that take place in this call should
  829. * be synchronous.
  830. * SYNC_DELWRI - This tells us to push dirty pages associated with
  831. * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
  832. * determine if they should be flushed sync, async, or
  833. * delwri.
  834. * SYNC_CLOSE - This flag is passed when the system is being
  835. * unmounted. We should sync and invalidate everything.
  836. * SYNC_FSDATA - This indicates that the caller would like to make
  837. * sure the superblock is safe on disk. We can ensure
  838. * this by simply making sure the log gets flushed
  839. * if SYNC_BDFLUSH is set, and by actually writing it
  840. * out otherwise.
  841. * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
  842. * before we return (including direct I/O). Forms the drain
  843. * side of the write barrier needed to safely quiesce the
  844. * filesystem.
  845. *
  846. */
  847. int
  848. xfs_sync(
  849. xfs_mount_t *mp,
  850. int flags)
  851. {
  852. int error;
  853. /*
  854. * Get the Quota Manager to flush the dquots.
  855. *
  856. * If XFS quota support is not enabled or this filesystem
  857. * instance does not use quotas XFS_QM_DQSYNC will always
  858. * return zero.
  859. */
  860. error = XFS_QM_DQSYNC(mp, flags);
  861. if (error) {
  862. /*
  863. * If we got an IO error, we will be shutting down.
  864. * So, there's nothing more for us to do here.
  865. */
  866. ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
  867. if (XFS_FORCED_SHUTDOWN(mp))
  868. return XFS_ERROR(error);
  869. }
  870. if (flags & SYNC_IOWAIT)
  871. xfs_filestream_flush(mp);
  872. return xfs_syncsub(mp, flags, NULL);
  873. }
  874. /*
  875. * xfs sync routine for internal use
  876. *
  877. * This routine supports all of the flags defined for the generic vfs_sync
  878. * interface as explained above under xfs_sync.
  879. *
  880. */
  881. int
  882. xfs_sync_inodes(
  883. xfs_mount_t *mp,
  884. int flags,
  885. int *bypassed)
  886. {
  887. xfs_inode_t *ip = NULL;
  888. xfs_inode_t *ip_next;
  889. xfs_buf_t *bp;
  890. bhv_vnode_t *vp = NULL;
  891. int error;
  892. int last_error;
  893. uint64_t fflag;
  894. uint lock_flags;
  895. uint base_lock_flags;
  896. boolean_t mount_locked;
  897. boolean_t vnode_refed;
  898. int preempt;
  899. xfs_dinode_t *dip;
  900. xfs_iptr_t *ipointer;
  901. #ifdef DEBUG
  902. boolean_t ipointer_in = B_FALSE;
  903. #define IPOINTER_SET ipointer_in = B_TRUE
  904. #define IPOINTER_CLR ipointer_in = B_FALSE
  905. #else
  906. #define IPOINTER_SET
  907. #define IPOINTER_CLR
  908. #endif
  909. /* Insert a marker record into the inode list after inode ip. The list
  910. * must be locked when this is called. After the call the list will no
  911. * longer be locked.
  912. */
  913. #define IPOINTER_INSERT(ip, mp) { \
  914. ASSERT(ipointer_in == B_FALSE); \
  915. ipointer->ip_mnext = ip->i_mnext; \
  916. ipointer->ip_mprev = ip; \
  917. ip->i_mnext = (xfs_inode_t *)ipointer; \
  918. ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
  919. preempt = 0; \
  920. XFS_MOUNT_IUNLOCK(mp); \
  921. mount_locked = B_FALSE; \
  922. IPOINTER_SET; \
  923. }
  924. /* Remove the marker from the inode list. If the marker was the only item
  925. * in the list then there are no remaining inodes and we should zero out
  926. * the whole list. If we are the current head of the list then move the head
  927. * past us.
  928. */
  929. #define IPOINTER_REMOVE(ip, mp) { \
  930. ASSERT(ipointer_in == B_TRUE); \
  931. if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
  932. ip = ipointer->ip_mnext; \
  933. ip->i_mprev = ipointer->ip_mprev; \
  934. ipointer->ip_mprev->i_mnext = ip; \
  935. if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
  936. mp->m_inodes = ip; \
  937. } \
  938. } else { \
  939. ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
  940. mp->m_inodes = NULL; \
  941. ip = NULL; \
  942. } \
  943. IPOINTER_CLR; \
  944. }
  945. #define XFS_PREEMPT_MASK 0x7f
  946. if (bypassed)
  947. *bypassed = 0;
  948. if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
  949. return 0;
  950. error = 0;
  951. last_error = 0;
  952. preempt = 0;
  953. /* Allocate a reference marker */
  954. ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
  955. fflag = XFS_B_ASYNC; /* default is don't wait */
  956. if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
  957. fflag = XFS_B_DELWRI;
  958. if (flags & SYNC_WAIT)
  959. fflag = 0; /* synchronous overrides all */
  960. base_lock_flags = XFS_ILOCK_SHARED;
  961. if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
  962. /*
  963. * We need the I/O lock if we're going to call any of
  964. * the flush/inval routines.
  965. */
  966. base_lock_flags |= XFS_IOLOCK_SHARED;
  967. }
  968. XFS_MOUNT_ILOCK(mp);
  969. ip = mp->m_inodes;
  970. mount_locked = B_TRUE;
  971. vnode_refed = B_FALSE;
  972. IPOINTER_CLR;
  973. do {
  974. ASSERT(ipointer_in == B_FALSE);
  975. ASSERT(vnode_refed == B_FALSE);
  976. lock_flags = base_lock_flags;
  977. /*
  978. * There were no inodes in the list, just break out
  979. * of the loop.
  980. */
  981. if (ip == NULL) {
  982. break;
  983. }
  984. /*
  985. * We found another sync thread marker - skip it
  986. */
  987. if (ip->i_mount == NULL) {
  988. ip = ip->i_mnext;
  989. continue;
  990. }
  991. vp = XFS_ITOV_NULL(ip);
  992. /*
  993. * If the vnode is gone then this is being torn down,
  994. * call reclaim if it is flushed, else let regular flush
  995. * code deal with it later in the loop.
  996. */
  997. if (vp == NULL) {
  998. /* Skip ones already in reclaim */
  999. if (ip->i_flags & XFS_IRECLAIM) {
  1000. ip = ip->i_mnext;
  1001. continue;
  1002. }
  1003. if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
  1004. ip = ip->i_mnext;
  1005. } else if ((xfs_ipincount(ip) == 0) &&
  1006. xfs_iflock_nowait(ip)) {
  1007. IPOINTER_INSERT(ip, mp);
  1008. xfs_finish_reclaim(ip, 1,
  1009. XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  1010. XFS_MOUNT_ILOCK(mp);
  1011. mount_locked = B_TRUE;
  1012. IPOINTER_REMOVE(ip, mp);
  1013. } else {
  1014. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1015. ip = ip->i_mnext;
  1016. }
  1017. continue;
  1018. }
  1019. if (VN_BAD(vp)) {
  1020. ip = ip->i_mnext;
  1021. continue;
  1022. }
  1023. if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
  1024. XFS_MOUNT_IUNLOCK(mp);
  1025. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1026. return 0;
  1027. }
  1028. /*
  1029. * If this is just vfs_sync() or pflushd() calling
  1030. * then we can skip inodes for which it looks like
  1031. * there is nothing to do. Since we don't have the
  1032. * inode locked this is racy, but these are periodic
  1033. * calls so it doesn't matter. For the others we want
  1034. * to know for sure, so we at least try to lock them.
  1035. */
  1036. if (flags & SYNC_BDFLUSH) {
  1037. if (((ip->i_itemp == NULL) ||
  1038. !(ip->i_itemp->ili_format.ilf_fields &
  1039. XFS_ILOG_ALL)) &&
  1040. (ip->i_update_core == 0)) {
  1041. ip = ip->i_mnext;
  1042. continue;
  1043. }
  1044. }
  1045. /*
  1046. * Try to lock without sleeping. We're out of order with
  1047. * the inode list lock here, so if we fail we need to drop
  1048. * the mount lock and try again. If we're called from
  1049. * bdflush() here, then don't bother.
  1050. *
  1051. * The inode lock here actually coordinates with the
  1052. * almost spurious inode lock in xfs_ireclaim() to prevent
  1053. * the vnode we handle here without a reference from
  1054. * being freed while we reference it. If we lock the inode
  1055. * while it's on the mount list here, then the spurious inode
  1056. * lock in xfs_ireclaim() after the inode is pulled from
  1057. * the mount list will sleep until we release it here.
  1058. * This keeps the vnode from being freed while we reference
  1059. * it.
  1060. */
  1061. if (xfs_ilock_nowait(ip, lock_flags) == 0) {
  1062. if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
  1063. ip = ip->i_mnext;
  1064. continue;
  1065. }
  1066. vp = vn_grab(vp);
  1067. if (vp == NULL) {
  1068. ip = ip->i_mnext;
  1069. continue;
  1070. }
  1071. IPOINTER_INSERT(ip, mp);
  1072. xfs_ilock(ip, lock_flags);
  1073. ASSERT(vp == XFS_ITOV(ip));
  1074. ASSERT(ip->i_mount == mp);
  1075. vnode_refed = B_TRUE;
  1076. }
  1077. /* From here on in the loop we may have a marker record
  1078. * in the inode list.
  1079. */
  1080. /*
  1081. * If we have to flush data or wait for I/O completion
  1082. * we need to drop the ilock that we currently hold.
  1083. * If we need to drop the lock, insert a marker if we
  1084. * have not already done so.
  1085. */
  1086. if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
  1087. ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
  1088. if (mount_locked) {
  1089. IPOINTER_INSERT(ip, mp);
  1090. }
  1091. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1092. if (flags & SYNC_CLOSE) {
  1093. /* Shutdown case. Flush and invalidate. */
  1094. if (XFS_FORCED_SHUTDOWN(mp))
  1095. xfs_tosspages(ip, 0, -1,
  1096. FI_REMAPF);
  1097. else
  1098. error = xfs_flushinval_pages(ip,
  1099. 0, -1, FI_REMAPF);
  1100. } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
  1101. error = xfs_flush_pages(ip, 0,
  1102. -1, fflag, FI_NONE);
  1103. }
  1104. /*
  1105. * When freezing, we need to wait ensure all I/O (including direct
  1106. * I/O) is complete to ensure no further data modification can take
  1107. * place after this point
  1108. */
  1109. if (flags & SYNC_IOWAIT)
  1110. vn_iowait(ip);
  1111. xfs_ilock(ip, XFS_ILOCK_SHARED);
  1112. }
  1113. if (flags & SYNC_BDFLUSH) {
  1114. if ((flags & SYNC_ATTR) &&
  1115. ((ip->i_update_core) ||
  1116. ((ip->i_itemp != NULL) &&
  1117. (ip->i_itemp->ili_format.ilf_fields != 0)))) {
  1118. /* Insert marker and drop lock if not already
  1119. * done.
  1120. */
  1121. if (mount_locked) {
  1122. IPOINTER_INSERT(ip, mp);
  1123. }
  1124. /*
  1125. * We don't want the periodic flushing of the
  1126. * inodes by vfs_sync() to interfere with
  1127. * I/O to the file, especially read I/O
  1128. * where it is only the access time stamp
  1129. * that is being flushed out. To prevent
  1130. * long periods where we have both inode
  1131. * locks held shared here while reading the
  1132. * inode's buffer in from disk, we drop the
  1133. * inode lock while reading in the inode
  1134. * buffer. We have to release the buffer
  1135. * and reacquire the inode lock so that they
  1136. * are acquired in the proper order (inode
  1137. * locks first). The buffer will go at the
  1138. * end of the lru chain, though, so we can
  1139. * expect it to still be there when we go
  1140. * for it again in xfs_iflush().
  1141. */
  1142. if ((xfs_ipincount(ip) == 0) &&
  1143. xfs_iflock_nowait(ip)) {
  1144. xfs_ifunlock(ip);
  1145. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1146. error = xfs_itobp(mp, NULL, ip,
  1147. &dip, &bp, 0, 0);
  1148. if (!error) {
  1149. xfs_buf_relse(bp);
  1150. } else {
  1151. /* Bailing out, remove the
  1152. * marker and free it.
  1153. */
  1154. XFS_MOUNT_ILOCK(mp);
  1155. IPOINTER_REMOVE(ip, mp);
  1156. XFS_MOUNT_IUNLOCK(mp);
  1157. ASSERT(!(lock_flags &
  1158. XFS_IOLOCK_SHARED));
  1159. kmem_free(ipointer,
  1160. sizeof(xfs_iptr_t));
  1161. return (0);
  1162. }
  1163. /*
  1164. * Since we dropped the inode lock,
  1165. * the inode may have been reclaimed.
  1166. * Therefore, we reacquire the mount
  1167. * lock and check to see if we were the
  1168. * inode reclaimed. If this happened
  1169. * then the ipointer marker will no
  1170. * longer point back at us. In this
  1171. * case, move ip along to the inode
  1172. * after the marker, remove the marker
  1173. * and continue.
  1174. */
  1175. XFS_MOUNT_ILOCK(mp);
  1176. mount_locked = B_TRUE;
  1177. if (ip != ipointer->ip_mprev) {
  1178. IPOINTER_REMOVE(ip, mp);
  1179. ASSERT(!vnode_refed);
  1180. ASSERT(!(lock_flags &
  1181. XFS_IOLOCK_SHARED));
  1182. continue;
  1183. }
  1184. ASSERT(ip->i_mount == mp);
  1185. if (xfs_ilock_nowait(ip,
  1186. XFS_ILOCK_SHARED) == 0) {
  1187. ASSERT(ip->i_mount == mp);
  1188. /*
  1189. * We failed to reacquire
  1190. * the inode lock without
  1191. * sleeping, so just skip
  1192. * the inode for now. We
  1193. * clear the ILOCK bit from
  1194. * the lock_flags so that we
  1195. * won't try to drop a lock
  1196. * we don't hold below.
  1197. */
  1198. lock_flags &= ~XFS_ILOCK_SHARED;
  1199. IPOINTER_REMOVE(ip_next, mp);
  1200. } else if ((xfs_ipincount(ip) == 0) &&
  1201. xfs_iflock_nowait(ip)) {
  1202. ASSERT(ip->i_mount == mp);
  1203. /*
  1204. * Since this is vfs_sync()
  1205. * calling we only flush the
  1206. * inode out if we can lock
  1207. * it without sleeping and
  1208. * it is not pinned. Drop
  1209. * the mount lock here so
  1210. * that we don't hold it for
  1211. * too long. We already have
  1212. * a marker in the list here.
  1213. */
  1214. XFS_MOUNT_IUNLOCK(mp);
  1215. mount_locked = B_FALSE;
  1216. error = xfs_iflush(ip,
  1217. XFS_IFLUSH_DELWRI);
  1218. } else {
  1219. ASSERT(ip->i_mount == mp);
  1220. IPOINTER_REMOVE(ip_next, mp);
  1221. }
  1222. }
  1223. }
  1224. } else {
  1225. if ((flags & SYNC_ATTR) &&
  1226. ((ip->i_update_core) ||
  1227. ((ip->i_itemp != NULL) &&
  1228. (ip->i_itemp->ili_format.ilf_fields != 0)))) {
  1229. if (mount_locked) {
  1230. IPOINTER_INSERT(ip, mp);
  1231. }
  1232. if (flags & SYNC_WAIT) {
  1233. xfs_iflock(ip);
  1234. error = xfs_iflush(ip,
  1235. XFS_IFLUSH_SYNC);
  1236. } else {
  1237. /*
  1238. * If we can't acquire the flush
  1239. * lock, then the inode is already
  1240. * being flushed so don't bother
  1241. * waiting. If we can lock it then
  1242. * do a delwri flush so we can
  1243. * combine multiple inode flushes
  1244. * in each disk write.
  1245. */
  1246. if (xfs_iflock_nowait(ip)) {
  1247. error = xfs_iflush(ip,
  1248. XFS_IFLUSH_DELWRI);
  1249. }
  1250. else if (bypassed)
  1251. (*bypassed)++;
  1252. }
  1253. }
  1254. }
  1255. if (lock_flags != 0) {
  1256. xfs_iunlock(ip, lock_flags);
  1257. }
  1258. if (vnode_refed) {
  1259. /*
  1260. * If we had to take a reference on the vnode
  1261. * above, then wait until after we've unlocked
  1262. * the inode to release the reference. This is
  1263. * because we can be already holding the inode
  1264. * lock when VN_RELE() calls xfs_inactive().
  1265. *
  1266. * Make sure to drop the mount lock before calling
  1267. * VN_RELE() so that we don't trip over ourselves if
  1268. * we have to go for the mount lock again in the
  1269. * inactive code.
  1270. */
  1271. if (mount_locked) {
  1272. IPOINTER_INSERT(ip, mp);
  1273. }
  1274. VN_RELE(vp);
  1275. vnode_refed = B_FALSE;
  1276. }
  1277. if (error) {
  1278. last_error = error;
  1279. }
  1280. /*
  1281. * bail out if the filesystem is corrupted.
  1282. */
  1283. if (error == EFSCORRUPTED) {
  1284. if (!mount_locked) {
  1285. XFS_MOUNT_ILOCK(mp);
  1286. IPOINTER_REMOVE(ip, mp);
  1287. }
  1288. XFS_MOUNT_IUNLOCK(mp);
  1289. ASSERT(ipointer_in == B_FALSE);
  1290. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1291. return XFS_ERROR(error);
  1292. }
  1293. /* Let other threads have a chance at the mount lock
  1294. * if we have looped many times without dropping the
  1295. * lock.
  1296. */
  1297. if ((++preempt & XFS_PREEMPT_MASK) == 0) {
  1298. if (mount_locked) {
  1299. IPOINTER_INSERT(ip, mp);
  1300. }
  1301. }
  1302. if (mount_locked == B_FALSE) {
  1303. XFS_MOUNT_ILOCK(mp);
  1304. mount_locked = B_TRUE;
  1305. IPOINTER_REMOVE(ip, mp);
  1306. continue;
  1307. }
  1308. ASSERT(ipointer_in == B_FALSE);
  1309. ip = ip->i_mnext;
  1310. } while (ip != mp->m_inodes);
  1311. XFS_MOUNT_IUNLOCK(mp);
  1312. ASSERT(ipointer_in == B_FALSE);
  1313. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1314. return XFS_ERROR(last_error);
  1315. }
  1316. /*
  1317. * xfs sync routine for internal use
  1318. *
  1319. * This routine supports all of the flags defined for the generic vfs_sync
  1320. * interface as explained above under xfs_sync.
  1321. *
  1322. */
  1323. int
  1324. xfs_syncsub(
  1325. xfs_mount_t *mp,
  1326. int flags,
  1327. int *bypassed)
  1328. {
  1329. int error = 0;
  1330. int last_error = 0;
  1331. uint log_flags = XFS_LOG_FORCE;
  1332. xfs_buf_t *bp;
  1333. xfs_buf_log_item_t *bip;
  1334. /*
  1335. * Sync out the log. This ensures that the log is periodically
  1336. * flushed even if there is not enough activity to fill it up.
  1337. */
  1338. if (flags & SYNC_WAIT)
  1339. log_flags |= XFS_LOG_SYNC;
  1340. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1341. if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
  1342. if (flags & SYNC_BDFLUSH)
  1343. xfs_finish_reclaim_all(mp, 1);
  1344. else
  1345. error = xfs_sync_inodes(mp, flags, bypassed);
  1346. }
  1347. /*
  1348. * Flushing out dirty data above probably generated more
  1349. * log activity, so if this isn't vfs_sync() then flush
  1350. * the log again.
  1351. */
  1352. if (flags & SYNC_DELWRI) {
  1353. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1354. }
  1355. if (flags & SYNC_FSDATA) {
  1356. /*
  1357. * If this is vfs_sync() then only sync the superblock
  1358. * if we can lock it without sleeping and it is not pinned.
  1359. */
  1360. if (flags & SYNC_BDFLUSH) {
  1361. bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
  1362. if (bp != NULL) {
  1363. bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
  1364. if ((bip != NULL) &&
  1365. xfs_buf_item_dirty(bip)) {
  1366. if (!(XFS_BUF_ISPINNED(bp))) {
  1367. XFS_BUF_ASYNC(bp);
  1368. error = xfs_bwrite(mp, bp);
  1369. } else {
  1370. xfs_buf_relse(bp);
  1371. }
  1372. } else {
  1373. xfs_buf_relse(bp);
  1374. }
  1375. }
  1376. } else {
  1377. bp = xfs_getsb(mp, 0);
  1378. /*
  1379. * If the buffer is pinned then push on the log so
  1380. * we won't get stuck waiting in the write for
  1381. * someone, maybe ourselves, to flush the log.
  1382. * Even though we just pushed the log above, we
  1383. * did not have the superblock buffer locked at
  1384. * that point so it can become pinned in between
  1385. * there and here.
  1386. */
  1387. if (XFS_BUF_ISPINNED(bp))
  1388. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  1389. if (flags & SYNC_WAIT)
  1390. XFS_BUF_UNASYNC(bp);
  1391. else
  1392. XFS_BUF_ASYNC(bp);
  1393. error = xfs_bwrite(mp, bp);
  1394. }
  1395. if (error) {
  1396. last_error = error;
  1397. }
  1398. }
  1399. /*
  1400. * If this is the periodic sync, then kick some entries out of
  1401. * the reference cache. This ensures that idle entries are
  1402. * eventually kicked out of the cache.
  1403. */
  1404. if (flags & SYNC_REFCACHE) {
  1405. if (flags & SYNC_WAIT)
  1406. xfs_refcache_purge_mp(mp);
  1407. else
  1408. xfs_refcache_purge_some(mp);
  1409. }
  1410. /*
  1411. * If asked, update the disk superblock with incore counter values if we
  1412. * are using non-persistent counters so that they don't get too far out
  1413. * of sync if we crash or get a forced shutdown. We don't want to force
  1414. * this to disk, just get a transaction into the iclogs....
  1415. */
  1416. if (flags & SYNC_SUPER)
  1417. xfs_log_sbcount(mp, 0);
  1418. /*
  1419. * Now check to see if the log needs a "dummy" transaction.
  1420. */
  1421. if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
  1422. xfs_trans_t *tp;
  1423. xfs_inode_t *ip;
  1424. /*
  1425. * Put a dummy transaction in the log to tell
  1426. * recovery that all others are OK.
  1427. */
  1428. tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
  1429. if ((error = xfs_trans_reserve(tp, 0,
  1430. XFS_ICHANGE_LOG_RES(mp),
  1431. 0, 0, 0))) {
  1432. xfs_trans_cancel(tp, 0);
  1433. return error;
  1434. }
  1435. ip = mp->m_rootip;
  1436. xfs_ilock(ip, XFS_ILOCK_EXCL);
  1437. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  1438. xfs_trans_ihold(tp, ip);
  1439. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  1440. error = xfs_trans_commit(tp, 0);
  1441. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1442. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1443. }
  1444. /*
  1445. * When shutting down, we need to insure that the AIL is pushed
  1446. * to disk or the filesystem can appear corrupt from the PROM.
  1447. */
  1448. if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
  1449. XFS_bflush(mp->m_ddev_targp);
  1450. if (mp->m_rtdev_targp) {
  1451. XFS_bflush(mp->m_rtdev_targp);
  1452. }
  1453. }
  1454. return XFS_ERROR(last_error);
  1455. }
  1456. /*
  1457. * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
  1458. */
  1459. int
  1460. xfs_vget(
  1461. xfs_mount_t *mp,
  1462. bhv_vnode_t **vpp,
  1463. fid_t *fidp)
  1464. {
  1465. xfs_fid_t *xfid = (struct xfs_fid *)fidp;
  1466. xfs_inode_t *ip;
  1467. int error;
  1468. xfs_ino_t ino;
  1469. unsigned int igen;
  1470. /*
  1471. * Invalid. Since handles can be created in user space and passed in
  1472. * via gethandle(), this is not cause for a panic.
  1473. */
  1474. if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
  1475. return XFS_ERROR(EINVAL);
  1476. ino = xfid->xfs_fid_ino;
  1477. igen = xfid->xfs_fid_gen;
  1478. /*
  1479. * NFS can sometimes send requests for ino 0. Fail them gracefully.
  1480. */
  1481. if (ino == 0)
  1482. return XFS_ERROR(ESTALE);
  1483. error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
  1484. if (error) {
  1485. *vpp = NULL;
  1486. return error;
  1487. }
  1488. if (ip == NULL) {
  1489. *vpp = NULL;
  1490. return XFS_ERROR(EIO);
  1491. }
  1492. if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
  1493. xfs_iput_new(ip, XFS_ILOCK_SHARED);
  1494. *vpp = NULL;
  1495. return XFS_ERROR(ENOENT);
  1496. }
  1497. *vpp = XFS_ITOV(ip);
  1498. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1499. return 0;
  1500. }
  1501. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  1502. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  1503. #define MNTOPT_LOGDEV "logdev" /* log device */
  1504. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  1505. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  1506. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  1507. #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
  1508. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  1509. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  1510. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  1511. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  1512. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  1513. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  1514. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  1515. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  1516. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  1517. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  1518. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  1519. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  1520. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  1521. * unwritten extent conversion */
  1522. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  1523. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  1524. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  1525. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  1526. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  1527. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  1528. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  1529. * in stat(). */
  1530. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  1531. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  1532. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  1533. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  1534. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  1535. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  1536. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  1537. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  1538. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  1539. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  1540. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  1541. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  1542. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  1543. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  1544. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  1545. #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
  1546. #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
  1547. #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
  1548. STATIC unsigned long
  1549. suffix_strtoul(char *s, char **endp, unsigned int base)
  1550. {
  1551. int last, shift_left_factor = 0;
  1552. char *value = s;
  1553. last = strlen(value) - 1;
  1554. if (value[last] == 'K' || value[last] == 'k') {
  1555. shift_left_factor = 10;
  1556. value[last] = '\0';
  1557. }
  1558. if (value[last] == 'M' || value[last] == 'm') {
  1559. shift_left_factor = 20;
  1560. value[last] = '\0';
  1561. }
  1562. if (value[last] == 'G' || value[last] == 'g') {
  1563. shift_left_factor = 30;
  1564. value[last] = '\0';
  1565. }
  1566. return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
  1567. }
  1568. int
  1569. xfs_parseargs(
  1570. struct xfs_mount *mp,
  1571. char *options,
  1572. struct xfs_mount_args *args,
  1573. int update)
  1574. {
  1575. bhv_vfs_t *vfsp = XFS_MTOVFS(mp);
  1576. char *this_char, *value, *eov;
  1577. int dsunit, dswidth, vol_dsunit, vol_dswidth;
  1578. int iosize;
  1579. /*
  1580. * Applications using DMI filesystems often expect the
  1581. * inode generation number to be monotonically increasing.
  1582. * If we delete inode chunks we break this assumption, so
  1583. * keep unused inode chunks on disk for DMI filesystems
  1584. * until we come up with a better solution.
  1585. * Note that if "ikeep" or "noikeep" mount options are
  1586. * supplied, then they are honored.
  1587. */
  1588. if (!(args->flags & XFSMNT_DMAPI))
  1589. args->flags |= XFSMNT_IDELETE;
  1590. args->flags |= XFSMNT_BARRIER;
  1591. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1592. if (!options)
  1593. goto done;
  1594. iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
  1595. while ((this_char = strsep(&options, ",")) != NULL) {
  1596. if (!*this_char)
  1597. continue;
  1598. if ((value = strchr(this_char, '=')) != NULL)
  1599. *value++ = 0;
  1600. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  1601. if (!value || !*value) {
  1602. cmn_err(CE_WARN,
  1603. "XFS: %s option requires an argument",
  1604. this_char);
  1605. return EINVAL;
  1606. }
  1607. args->logbufs = simple_strtoul(value, &eov, 10);
  1608. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  1609. if (!value || !*value) {
  1610. cmn_err(CE_WARN,
  1611. "XFS: %s option requires an argument",
  1612. this_char);
  1613. return EINVAL;
  1614. }
  1615. args->logbufsize = suffix_strtoul(value, &eov, 10);
  1616. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  1617. if (!value || !*value) {
  1618. cmn_err(CE_WARN,
  1619. "XFS: %s option requires an argument",
  1620. this_char);
  1621. return EINVAL;
  1622. }
  1623. strncpy(args->logname, value, MAXNAMELEN);
  1624. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  1625. if (!value || !*value) {
  1626. cmn_err(CE_WARN,
  1627. "XFS: %s option requires an argument",
  1628. this_char);
  1629. return EINVAL;
  1630. }
  1631. strncpy(args->mtpt, value, MAXNAMELEN);
  1632. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  1633. if (!value || !*value) {
  1634. cmn_err(CE_WARN,
  1635. "XFS: %s option requires an argument",
  1636. this_char);
  1637. return EINVAL;
  1638. }
  1639. strncpy(args->rtname, value, MAXNAMELEN);
  1640. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  1641. if (!value || !*value) {
  1642. cmn_err(CE_WARN,
  1643. "XFS: %s option requires an argument",
  1644. this_char);
  1645. return EINVAL;
  1646. }
  1647. iosize = simple_strtoul(value, &eov, 10);
  1648. args->flags |= XFSMNT_IOSIZE;
  1649. args->iosizelog = (uint8_t) iosize;
  1650. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  1651. if (!value || !*value) {
  1652. cmn_err(CE_WARN,
  1653. "XFS: %s option requires an argument",
  1654. this_char);
  1655. return EINVAL;
  1656. }
  1657. iosize = suffix_strtoul(value, &eov, 10);
  1658. args->flags |= XFSMNT_IOSIZE;
  1659. args->iosizelog = ffs(iosize) - 1;
  1660. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  1661. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  1662. vfsp->vfs_flag |= VFS_GRPID;
  1663. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  1664. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  1665. vfsp->vfs_flag &= ~VFS_GRPID;
  1666. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  1667. args->flags |= XFSMNT_WSYNC;
  1668. } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
  1669. args->flags |= XFSMNT_OSYNCISOSYNC;
  1670. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  1671. args->flags |= XFSMNT_NORECOVERY;
  1672. } else if (!strcmp(this_char, MNTOPT_INO64)) {
  1673. args->flags |= XFSMNT_INO64;
  1674. #if !XFS_BIG_INUMS
  1675. cmn_err(CE_WARN,
  1676. "XFS: %s option not allowed on this system",
  1677. this_char);
  1678. return EINVAL;
  1679. #endif
  1680. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  1681. args->flags |= XFSMNT_NOALIGN;
  1682. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  1683. args->flags |= XFSMNT_SWALLOC;
  1684. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  1685. if (!value || !*value) {
  1686. cmn_err(CE_WARN,
  1687. "XFS: %s option requires an argument",
  1688. this_char);
  1689. return EINVAL;
  1690. }
  1691. dsunit = simple_strtoul(value, &eov, 10);
  1692. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  1693. if (!value || !*value) {
  1694. cmn_err(CE_WARN,
  1695. "XFS: %s option requires an argument",
  1696. this_char);
  1697. return EINVAL;
  1698. }
  1699. dswidth = simple_strtoul(value, &eov, 10);
  1700. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  1701. args->flags &= ~XFSMNT_32BITINODES;
  1702. #if !XFS_BIG_INUMS
  1703. cmn_err(CE_WARN,
  1704. "XFS: %s option not allowed on this system",
  1705. this_char);
  1706. return EINVAL;
  1707. #endif
  1708. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  1709. args->flags |= XFSMNT_NOUUID;
  1710. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  1711. args->flags |= XFSMNT_BARRIER;
  1712. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  1713. args->flags &= ~XFSMNT_BARRIER;
  1714. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  1715. args->flags &= ~XFSMNT_IDELETE;
  1716. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  1717. args->flags |= XFSMNT_IDELETE;
  1718. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  1719. args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
  1720. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  1721. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1722. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  1723. args->flags |= XFSMNT_ATTR2;
  1724. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  1725. args->flags &= ~XFSMNT_ATTR2;
  1726. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  1727. args->flags2 |= XFSMNT2_FILESTREAMS;
  1728. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  1729. args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
  1730. args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
  1731. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  1732. !strcmp(this_char, MNTOPT_UQUOTA) ||
  1733. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  1734. args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
  1735. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  1736. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  1737. args->flags |= XFSMNT_UQUOTA;
  1738. args->flags &= ~XFSMNT_UQUOTAENF;
  1739. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  1740. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  1741. args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
  1742. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  1743. args->flags |= XFSMNT_PQUOTA;
  1744. args->flags &= ~XFSMNT_PQUOTAENF;
  1745. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  1746. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  1747. args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
  1748. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  1749. args->flags |= XFSMNT_GQUOTA;
  1750. args->flags &= ~XFSMNT_GQUOTAENF;
  1751. } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
  1752. args->flags |= XFSMNT_DMAPI;
  1753. } else if (!strcmp(this_char, MNTOPT_XDSM)) {
  1754. args->flags |= XFSMNT_DMAPI;
  1755. } else if (!strcmp(this_char, MNTOPT_DMI)) {
  1756. args->flags |= XFSMNT_DMAPI;
  1757. } else if (!strcmp(this_char, "ihashsize")) {
  1758. cmn_err(CE_WARN,
  1759. "XFS: ihashsize no longer used, option is deprecated.");
  1760. } else if (!strcmp(this_char, "osyncisdsync")) {
  1761. /* no-op, this is now the default */
  1762. cmn_err(CE_WARN,
  1763. "XFS: osyncisdsync is now the default, option is deprecated.");
  1764. } else if (!strcmp(this_char, "irixsgid")) {
  1765. cmn_err(CE_WARN,
  1766. "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
  1767. } else {
  1768. cmn_err(CE_WARN,
  1769. "XFS: unknown mount option [%s].", this_char);
  1770. return EINVAL;
  1771. }
  1772. }
  1773. if (args->flags & XFSMNT_NORECOVERY) {
  1774. if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
  1775. cmn_err(CE_WARN,
  1776. "XFS: no-recovery mounts must be read-only.");
  1777. return EINVAL;
  1778. }
  1779. }
  1780. if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
  1781. cmn_err(CE_WARN,
  1782. "XFS: sunit and swidth options incompatible with the noalign option");
  1783. return EINVAL;
  1784. }
  1785. if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
  1786. cmn_err(CE_WARN,
  1787. "XFS: cannot mount with both project and group quota");
  1788. return EINVAL;
  1789. }
  1790. if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
  1791. printk("XFS: %s option needs the mount point option as well\n",
  1792. MNTOPT_DMAPI);
  1793. return EINVAL;
  1794. }
  1795. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  1796. cmn_err(CE_WARN,
  1797. "XFS: sunit and swidth must be specified together");
  1798. return EINVAL;
  1799. }
  1800. if (dsunit && (dswidth % dsunit != 0)) {
  1801. cmn_err(CE_WARN,
  1802. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  1803. dswidth, dsunit);
  1804. return EINVAL;
  1805. }
  1806. if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  1807. if (dsunit) {
  1808. args->sunit = dsunit;
  1809. args->flags |= XFSMNT_RETERR;
  1810. } else {
  1811. args->sunit = vol_dsunit;
  1812. }
  1813. dswidth ? (args->swidth = dswidth) :
  1814. (args->swidth = vol_dswidth);
  1815. } else {
  1816. args->sunit = args->swidth = 0;
  1817. }
  1818. done:
  1819. if (args->flags & XFSMNT_32BITINODES)
  1820. vfsp->vfs_flag |= VFS_32BITINODES;
  1821. if (args->flags2)
  1822. args->flags |= XFSMNT_FLAGS2;
  1823. return 0;
  1824. }
  1825. int
  1826. xfs_showargs(
  1827. struct xfs_mount *mp,
  1828. struct seq_file *m)
  1829. {
  1830. static struct proc_xfs_info {
  1831. int flag;
  1832. char *str;
  1833. } xfs_info[] = {
  1834. /* the few simple ones we can get from the mount struct */
  1835. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  1836. { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
  1837. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  1838. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  1839. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  1840. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  1841. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  1842. { 0, NULL }
  1843. };
  1844. struct proc_xfs_info *xfs_infop;
  1845. struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
  1846. for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
  1847. if (mp->m_flags & xfs_infop->flag)
  1848. seq_puts(m, xfs_infop->str);
  1849. }
  1850. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  1851. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  1852. (int)(1 << mp->m_writeio_log) >> 10);
  1853. if (mp->m_logbufs > 0)
  1854. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  1855. if (mp->m_logbsize > 0)
  1856. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  1857. if (mp->m_logname)
  1858. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  1859. if (mp->m_rtname)
  1860. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  1861. if (mp->m_dalign > 0)
  1862. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  1863. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  1864. if (mp->m_swidth > 0)
  1865. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  1866. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  1867. if (!(mp->m_flags & XFS_MOUNT_IDELETE))
  1868. seq_printf(m, "," MNTOPT_IKEEP);
  1869. if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
  1870. seq_printf(m, "," MNTOPT_LARGEIO);
  1871. if (!(vfsp->vfs_flag & VFS_32BITINODES))
  1872. seq_printf(m, "," MNTOPT_64BITINODE);
  1873. if (vfsp->vfs_flag & VFS_GRPID)
  1874. seq_printf(m, "," MNTOPT_GRPID);
  1875. if (mp->m_qflags & XFS_UQUOTA_ACCT) {
  1876. if (mp->m_qflags & XFS_UQUOTA_ENFD)
  1877. seq_puts(m, "," MNTOPT_USRQUOTA);
  1878. else
  1879. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  1880. }
  1881. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  1882. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1883. seq_puts(m, "," MNTOPT_PRJQUOTA);
  1884. else
  1885. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  1886. }
  1887. if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  1888. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1889. seq_puts(m, "," MNTOPT_GRPQUOTA);
  1890. else
  1891. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  1892. }
  1893. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  1894. seq_puts(m, "," MNTOPT_NOQUOTA);
  1895. if (vfsp->vfs_flag & VFS_DMI)
  1896. seq_puts(m, "," MNTOPT_DMAPI);
  1897. return 0;
  1898. }
  1899. /*
  1900. * Second stage of a freeze. The data is already frozen so we only
  1901. * need to take care of themetadata. Once that's done write a dummy
  1902. * record to dirty the log in case of a crash while frozen.
  1903. */
  1904. STATIC void
  1905. xfs_freeze(
  1906. xfs_mount_t *mp)
  1907. {
  1908. xfs_attr_quiesce(mp);
  1909. xfs_fs_log_dummy(mp);
  1910. }