xfs_vfsops.c 53 KB

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