xfs_vfsops.c 52 KB

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