xfs_vfsops.c 53 KB

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