xfs_vfsops.c 51 KB

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