xfs_vfsops.c 53 KB

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