xfs_vfsops.c 52 KB

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