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. * disallow mount attempts with (IRIX) project quota enabled
  339. */
  340. if (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) &&
  341. (mp->m_sb.sb_qflags & XFS_PQUOTA_ACCT)) {
  342. cmn_err(CE_WARN,
  343. "XFS: cannot mount a filesystem with IRIX project quota enabled");
  344. return XFS_ERROR(ENOSYS);
  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 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. /*
  405. * Open real time and log devices - order is important.
  406. */
  407. if (args->logname[0]) {
  408. error = xfs_blkdev_get(mp, args->logname, &logdev);
  409. if (error)
  410. return error;
  411. }
  412. if (args->rtname[0]) {
  413. error = xfs_blkdev_get(mp, args->rtname, &rtdev);
  414. if (error) {
  415. xfs_blkdev_put(logdev);
  416. return error;
  417. }
  418. if (rtdev == ddev || rtdev == logdev) {
  419. cmn_err(CE_WARN,
  420. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  421. xfs_blkdev_put(logdev);
  422. xfs_blkdev_put(rtdev);
  423. return EINVAL;
  424. }
  425. }
  426. /*
  427. * Setup xfs_mount buffer target pointers
  428. */
  429. error = ENOMEM;
  430. mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
  431. if (!mp->m_ddev_targp) {
  432. xfs_blkdev_put(logdev);
  433. xfs_blkdev_put(rtdev);
  434. return error;
  435. }
  436. if (rtdev) {
  437. mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
  438. if (!mp->m_rtdev_targp)
  439. goto error0;
  440. }
  441. mp->m_logdev_targp = (logdev && logdev != ddev) ?
  442. xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
  443. if (!mp->m_logdev_targp)
  444. goto error0;
  445. /*
  446. * Setup flags based on mount(2) options and then the superblock
  447. */
  448. error = xfs_start_flags(vfsp, args, mp);
  449. if (error)
  450. goto error1;
  451. error = xfs_readsb(mp);
  452. if (error)
  453. goto error1;
  454. error = xfs_finish_flags(vfsp, args, mp);
  455. if (error)
  456. goto error2;
  457. /*
  458. * Setup xfs_mount buffer target pointers based on superblock
  459. */
  460. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  461. mp->m_sb.sb_sectsize);
  462. if (!error && logdev && logdev != ddev) {
  463. unsigned int log_sector_size = BBSIZE;
  464. if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
  465. log_sector_size = mp->m_sb.sb_logsectsize;
  466. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  467. mp->m_sb.sb_blocksize,
  468. log_sector_size);
  469. }
  470. if (!error && rtdev)
  471. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  472. mp->m_sb.sb_blocksize,
  473. mp->m_sb.sb_sectsize);
  474. if (error)
  475. goto error2;
  476. error = XFS_IOINIT(vfsp, args, flags);
  477. if (!error)
  478. return 0;
  479. error2:
  480. if (mp->m_sb_bp)
  481. xfs_freesb(mp);
  482. error1:
  483. xfs_binval(mp->m_ddev_targp);
  484. if (logdev && logdev != ddev)
  485. xfs_binval(mp->m_logdev_targp);
  486. if (rtdev)
  487. xfs_binval(mp->m_rtdev_targp);
  488. error0:
  489. xfs_unmountfs_close(mp, credp);
  490. return error;
  491. }
  492. STATIC int
  493. xfs_unmount(
  494. bhv_desc_t *bdp,
  495. int flags,
  496. cred_t *credp)
  497. {
  498. struct vfs *vfsp = bhvtovfs(bdp);
  499. xfs_mount_t *mp = XFS_BHVTOM(bdp);
  500. xfs_inode_t *rip;
  501. vnode_t *rvp;
  502. int unmount_event_wanted = 0;
  503. int unmount_event_flags = 0;
  504. int xfs_unmountfs_needed = 0;
  505. int error;
  506. rip = mp->m_rootip;
  507. rvp = XFS_ITOV(rip);
  508. if (vfsp->vfs_flag & VFS_DMI) {
  509. error = XFS_SEND_PREUNMOUNT(mp, vfsp,
  510. rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
  511. NULL, NULL, 0, 0,
  512. (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
  513. 0:DM_FLAGS_UNWANTED);
  514. if (error)
  515. return XFS_ERROR(error);
  516. unmount_event_wanted = 1;
  517. unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
  518. 0 : DM_FLAGS_UNWANTED;
  519. }
  520. /*
  521. * First blow any referenced inode from this file system
  522. * out of the reference cache, and delete the timer.
  523. */
  524. xfs_refcache_purge_mp(mp);
  525. XFS_bflush(mp->m_ddev_targp);
  526. error = xfs_unmount_flush(mp, 0);
  527. if (error)
  528. goto out;
  529. ASSERT(vn_count(rvp) == 1);
  530. /*
  531. * Drop the reference count
  532. */
  533. VN_RELE(rvp);
  534. /*
  535. * If we're forcing a shutdown, typically because of a media error,
  536. * we want to make sure we invalidate dirty pages that belong to
  537. * referenced vnodes as well.
  538. */
  539. if (XFS_FORCED_SHUTDOWN(mp)) {
  540. error = xfs_sync(&mp->m_bhv,
  541. (SYNC_WAIT | SYNC_CLOSE), credp);
  542. ASSERT(error != EFSCORRUPTED);
  543. }
  544. xfs_unmountfs_needed = 1;
  545. out:
  546. /* Send DMAPI event, if required.
  547. * Then do xfs_unmountfs() if needed.
  548. * Then return error (or zero).
  549. */
  550. if (unmount_event_wanted) {
  551. /* Note: mp structure must still exist for
  552. * XFS_SEND_UNMOUNT() call.
  553. */
  554. XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
  555. DM_RIGHT_NULL, 0, error, unmount_event_flags);
  556. }
  557. if (xfs_unmountfs_needed) {
  558. /*
  559. * Call common unmount function to flush to disk
  560. * and free the super block buffer & mount structures.
  561. */
  562. xfs_unmountfs(mp, credp);
  563. }
  564. return XFS_ERROR(error);
  565. }
  566. #define REMOUNT_READONLY_FLAGS (SYNC_REMOUNT|SYNC_ATTR|SYNC_WAIT)
  567. STATIC int
  568. xfs_mntupdate(
  569. bhv_desc_t *bdp,
  570. int *flags,
  571. struct xfs_mount_args *args)
  572. {
  573. struct vfs *vfsp = bhvtovfs(bdp);
  574. xfs_mount_t *mp = XFS_BHVTOM(bdp);
  575. int pincount, error;
  576. int count = 0;
  577. if (args->flags & XFSMNT_NOATIME)
  578. mp->m_flags |= XFS_MOUNT_NOATIME;
  579. else
  580. mp->m_flags &= ~XFS_MOUNT_NOATIME;
  581. if (!(vfsp->vfs_flag & VFS_RDONLY)) {
  582. VFS_SYNC(vfsp, SYNC_FSDATA|SYNC_BDFLUSH|SYNC_ATTR, NULL, error);
  583. }
  584. if (*flags & MS_RDONLY) {
  585. xfs_refcache_purge_mp(mp);
  586. xfs_flush_buftarg(mp->m_ddev_targp, 0);
  587. xfs_finish_reclaim_all(mp, 0);
  588. /* This loop must run at least twice.
  589. * The first instance of the loop will flush
  590. * most meta data but that will generate more
  591. * meta data (typically directory updates).
  592. * Which then must be flushed and logged before
  593. * we can write the unmount record.
  594. */
  595. do {
  596. VFS_SYNC(vfsp, REMOUNT_READONLY_FLAGS, NULL, error);
  597. pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
  598. if (!pincount) {
  599. delay(50);
  600. count++;
  601. }
  602. } while (count < 2);
  603. /* Ok now write out an unmount record */
  604. xfs_log_unmount_write(mp);
  605. xfs_unmountfs_writesb(mp);
  606. vfsp->vfs_flag |= VFS_RDONLY;
  607. } else {
  608. vfsp->vfs_flag &= ~VFS_RDONLY;
  609. }
  610. return 0;
  611. }
  612. /*
  613. * xfs_unmount_flush implements a set of flush operation on special
  614. * inodes, which are needed as a separate set of operations so that
  615. * they can be called as part of relocation process.
  616. */
  617. int
  618. xfs_unmount_flush(
  619. xfs_mount_t *mp, /* Mount structure we are getting
  620. rid of. */
  621. int relocation) /* Called from vfs relocation. */
  622. {
  623. xfs_inode_t *rip = mp->m_rootip;
  624. xfs_inode_t *rbmip;
  625. xfs_inode_t *rsumip = NULL;
  626. vnode_t *rvp = XFS_ITOV(rip);
  627. int error;
  628. xfs_ilock(rip, XFS_ILOCK_EXCL);
  629. xfs_iflock(rip);
  630. /*
  631. * Flush out the real time inodes.
  632. */
  633. if ((rbmip = mp->m_rbmip) != NULL) {
  634. xfs_ilock(rbmip, XFS_ILOCK_EXCL);
  635. xfs_iflock(rbmip);
  636. error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
  637. xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
  638. if (error == EFSCORRUPTED)
  639. goto fscorrupt_out;
  640. ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
  641. rsumip = mp->m_rsumip;
  642. xfs_ilock(rsumip, XFS_ILOCK_EXCL);
  643. xfs_iflock(rsumip);
  644. error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
  645. xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
  646. if (error == EFSCORRUPTED)
  647. goto fscorrupt_out;
  648. ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
  649. }
  650. /*
  651. * Synchronously flush root inode to disk
  652. */
  653. error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
  654. if (error == EFSCORRUPTED)
  655. goto fscorrupt_out2;
  656. if (vn_count(rvp) != 1 && !relocation) {
  657. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  658. return XFS_ERROR(EBUSY);
  659. }
  660. /*
  661. * Release dquot that rootinode, rbmino and rsumino might be holding,
  662. * flush and purge the quota inodes.
  663. */
  664. error = XFS_QM_UNMOUNT(mp);
  665. if (error == EFSCORRUPTED)
  666. goto fscorrupt_out2;
  667. if (rbmip) {
  668. VN_RELE(XFS_ITOV(rbmip));
  669. VN_RELE(XFS_ITOV(rsumip));
  670. }
  671. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  672. return 0;
  673. fscorrupt_out:
  674. xfs_ifunlock(rip);
  675. fscorrupt_out2:
  676. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  677. return XFS_ERROR(EFSCORRUPTED);
  678. }
  679. /*
  680. * xfs_root extracts the root vnode from a vfs.
  681. *
  682. * vfsp -- the vfs struct for the desired file system
  683. * vpp -- address of the caller's vnode pointer which should be
  684. * set to the desired fs root vnode
  685. */
  686. STATIC int
  687. xfs_root(
  688. bhv_desc_t *bdp,
  689. vnode_t **vpp)
  690. {
  691. vnode_t *vp;
  692. vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
  693. VN_HOLD(vp);
  694. *vpp = vp;
  695. return 0;
  696. }
  697. /*
  698. * xfs_statvfs
  699. *
  700. * Fill in the statvfs structure for the given file system. We use
  701. * the superblock lock in the mount structure to ensure a consistent
  702. * snapshot of the counters returned.
  703. */
  704. STATIC int
  705. xfs_statvfs(
  706. bhv_desc_t *bdp,
  707. xfs_statfs_t *statp,
  708. vnode_t *vp)
  709. {
  710. __uint64_t fakeinos;
  711. xfs_extlen_t lsize;
  712. xfs_mount_t *mp;
  713. xfs_sb_t *sbp;
  714. unsigned long s;
  715. u64 id;
  716. mp = XFS_BHVTOM(bdp);
  717. sbp = &(mp->m_sb);
  718. statp->f_type = XFS_SB_MAGIC;
  719. s = XFS_SB_LOCK(mp);
  720. statp->f_bsize = sbp->sb_blocksize;
  721. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  722. statp->f_blocks = sbp->sb_dblocks - lsize;
  723. statp->f_bfree = statp->f_bavail = sbp->sb_fdblocks;
  724. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  725. #if XFS_BIG_INUMS
  726. fakeinos += mp->m_inoadd;
  727. #endif
  728. statp->f_files =
  729. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  730. if (mp->m_maxicount)
  731. #if XFS_BIG_INUMS
  732. if (!mp->m_inoadd)
  733. #endif
  734. statp->f_files = min_t(typeof(statp->f_files),
  735. statp->f_files,
  736. mp->m_maxicount);
  737. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  738. XFS_SB_UNLOCK(mp, s);
  739. id = huge_encode_dev(mp->m_dev);
  740. statp->f_fsid.val[0] = (u32)id;
  741. statp->f_fsid.val[1] = (u32)(id >> 32);
  742. statp->f_namelen = MAXNAMELEN - 1;
  743. return 0;
  744. }
  745. /*
  746. * xfs_sync flushes any pending I/O to file system vfsp.
  747. *
  748. * This routine is called by vfs_sync() to make sure that things make it
  749. * out to disk eventually, on sync() system calls to flush out everything,
  750. * and when the file system is unmounted. For the vfs_sync() case, all
  751. * we really need to do is sync out the log to make all of our meta-data
  752. * updates permanent (except for timestamps). For calls from pflushd(),
  753. * dirty pages are kept moving by calling pdflush() on the inodes
  754. * containing them. We also flush the inodes that we can lock without
  755. * sleeping and the superblock if we can lock it without sleeping from
  756. * vfs_sync() so that items at the tail of the log are always moving out.
  757. *
  758. * Flags:
  759. * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
  760. * to sleep if we can help it. All we really need
  761. * to do is ensure that the log is synced at least
  762. * periodically. We also push the inodes and
  763. * superblock if we can lock them without sleeping
  764. * and they are not pinned.
  765. * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
  766. * set, then we really want to lock each inode and flush
  767. * it.
  768. * SYNC_WAIT - All the flushes that take place in this call should
  769. * be synchronous.
  770. * SYNC_DELWRI - This tells us to push dirty pages associated with
  771. * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
  772. * determine if they should be flushed sync, async, or
  773. * delwri.
  774. * SYNC_CLOSE - This flag is passed when the system is being
  775. * unmounted. We should sync and invalidate everthing.
  776. * SYNC_FSDATA - This indicates that the caller would like to make
  777. * sure the superblock is safe on disk. We can ensure
  778. * this by simply makeing sure the log gets flushed
  779. * if SYNC_BDFLUSH is set, and by actually writing it
  780. * out otherwise.
  781. *
  782. */
  783. /*ARGSUSED*/
  784. STATIC int
  785. xfs_sync(
  786. bhv_desc_t *bdp,
  787. int flags,
  788. cred_t *credp)
  789. {
  790. xfs_mount_t *mp;
  791. mp = XFS_BHVTOM(bdp);
  792. return (xfs_syncsub(mp, flags, 0, NULL));
  793. }
  794. /*
  795. * xfs sync routine for internal use
  796. *
  797. * This routine supports all of the flags defined for the generic VFS_SYNC
  798. * interface as explained above under xfs_sync. In the interests of not
  799. * changing interfaces within the 6.5 family, additional internallly-
  800. * required functions are specified within a separate xflags parameter,
  801. * only available by calling this routine.
  802. *
  803. */
  804. STATIC int
  805. xfs_sync_inodes(
  806. xfs_mount_t *mp,
  807. int flags,
  808. int xflags,
  809. int *bypassed)
  810. {
  811. xfs_inode_t *ip = NULL;
  812. xfs_inode_t *ip_next;
  813. xfs_buf_t *bp;
  814. vnode_t *vp = NULL;
  815. vmap_t vmap;
  816. int error;
  817. int last_error;
  818. uint64_t fflag;
  819. uint lock_flags;
  820. uint base_lock_flags;
  821. boolean_t mount_locked;
  822. boolean_t vnode_refed;
  823. int preempt;
  824. xfs_dinode_t *dip;
  825. xfs_iptr_t *ipointer;
  826. #ifdef DEBUG
  827. boolean_t ipointer_in = B_FALSE;
  828. #define IPOINTER_SET ipointer_in = B_TRUE
  829. #define IPOINTER_CLR ipointer_in = B_FALSE
  830. #else
  831. #define IPOINTER_SET
  832. #define IPOINTER_CLR
  833. #endif
  834. /* Insert a marker record into the inode list after inode ip. The list
  835. * must be locked when this is called. After the call the list will no
  836. * longer be locked.
  837. */
  838. #define IPOINTER_INSERT(ip, mp) { \
  839. ASSERT(ipointer_in == B_FALSE); \
  840. ipointer->ip_mnext = ip->i_mnext; \
  841. ipointer->ip_mprev = ip; \
  842. ip->i_mnext = (xfs_inode_t *)ipointer; \
  843. ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
  844. preempt = 0; \
  845. XFS_MOUNT_IUNLOCK(mp); \
  846. mount_locked = B_FALSE; \
  847. IPOINTER_SET; \
  848. }
  849. /* Remove the marker from the inode list. If the marker was the only item
  850. * in the list then there are no remaining inodes and we should zero out
  851. * the whole list. If we are the current head of the list then move the head
  852. * past us.
  853. */
  854. #define IPOINTER_REMOVE(ip, mp) { \
  855. ASSERT(ipointer_in == B_TRUE); \
  856. if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
  857. ip = ipointer->ip_mnext; \
  858. ip->i_mprev = ipointer->ip_mprev; \
  859. ipointer->ip_mprev->i_mnext = ip; \
  860. if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
  861. mp->m_inodes = ip; \
  862. } \
  863. } else { \
  864. ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
  865. mp->m_inodes = NULL; \
  866. ip = NULL; \
  867. } \
  868. IPOINTER_CLR; \
  869. }
  870. #define XFS_PREEMPT_MASK 0x7f
  871. if (bypassed)
  872. *bypassed = 0;
  873. if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
  874. return 0;
  875. error = 0;
  876. last_error = 0;
  877. preempt = 0;
  878. /* Allocate a reference marker */
  879. ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
  880. fflag = XFS_B_ASYNC; /* default is don't wait */
  881. if (flags & SYNC_BDFLUSH)
  882. fflag = XFS_B_DELWRI;
  883. if (flags & SYNC_WAIT)
  884. fflag = 0; /* synchronous overrides all */
  885. base_lock_flags = XFS_ILOCK_SHARED;
  886. if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
  887. /*
  888. * We need the I/O lock if we're going to call any of
  889. * the flush/inval routines.
  890. */
  891. base_lock_flags |= XFS_IOLOCK_SHARED;
  892. }
  893. XFS_MOUNT_ILOCK(mp);
  894. ip = mp->m_inodes;
  895. mount_locked = B_TRUE;
  896. vnode_refed = B_FALSE;
  897. IPOINTER_CLR;
  898. do {
  899. ASSERT(ipointer_in == B_FALSE);
  900. ASSERT(vnode_refed == B_FALSE);
  901. lock_flags = base_lock_flags;
  902. /*
  903. * There were no inodes in the list, just break out
  904. * of the loop.
  905. */
  906. if (ip == NULL) {
  907. break;
  908. }
  909. /*
  910. * We found another sync thread marker - skip it
  911. */
  912. if (ip->i_mount == NULL) {
  913. ip = ip->i_mnext;
  914. continue;
  915. }
  916. vp = XFS_ITOV_NULL(ip);
  917. /*
  918. * If the vnode is gone then this is being torn down,
  919. * call reclaim if it is flushed, else let regular flush
  920. * code deal with it later in the loop.
  921. */
  922. if (vp == NULL) {
  923. /* Skip ones already in reclaim */
  924. if (ip->i_flags & XFS_IRECLAIM) {
  925. ip = ip->i_mnext;
  926. continue;
  927. }
  928. if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
  929. ip = ip->i_mnext;
  930. } else if ((xfs_ipincount(ip) == 0) &&
  931. xfs_iflock_nowait(ip)) {
  932. IPOINTER_INSERT(ip, mp);
  933. xfs_finish_reclaim(ip, 1,
  934. XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  935. XFS_MOUNT_ILOCK(mp);
  936. mount_locked = B_TRUE;
  937. IPOINTER_REMOVE(ip, mp);
  938. } else {
  939. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  940. ip = ip->i_mnext;
  941. }
  942. continue;
  943. }
  944. if (VN_BAD(vp)) {
  945. ip = ip->i_mnext;
  946. continue;
  947. }
  948. if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
  949. XFS_MOUNT_IUNLOCK(mp);
  950. kmem_free(ipointer, sizeof(xfs_iptr_t));
  951. return 0;
  952. }
  953. /*
  954. * If this is just vfs_sync() or pflushd() calling
  955. * then we can skip inodes for which it looks like
  956. * there is nothing to do. Since we don't have the
  957. * inode locked this is racey, but these are periodic
  958. * calls so it doesn't matter. For the others we want
  959. * to know for sure, so we at least try to lock them.
  960. */
  961. if (flags & SYNC_BDFLUSH) {
  962. if (((ip->i_itemp == NULL) ||
  963. !(ip->i_itemp->ili_format.ilf_fields &
  964. XFS_ILOG_ALL)) &&
  965. (ip->i_update_core == 0)) {
  966. ip = ip->i_mnext;
  967. continue;
  968. }
  969. }
  970. /*
  971. * Try to lock without sleeping. We're out of order with
  972. * the inode list lock here, so if we fail we need to drop
  973. * the mount lock and try again. If we're called from
  974. * bdflush() here, then don't bother.
  975. *
  976. * The inode lock here actually coordinates with the
  977. * almost spurious inode lock in xfs_ireclaim() to prevent
  978. * the vnode we handle here without a reference from
  979. * being freed while we reference it. If we lock the inode
  980. * while it's on the mount list here, then the spurious inode
  981. * lock in xfs_ireclaim() after the inode is pulled from
  982. * the mount list will sleep until we release it here.
  983. * This keeps the vnode from being freed while we reference
  984. * it. It is also cheaper and simpler than actually doing
  985. * a vn_get() for every inode we touch here.
  986. */
  987. if (xfs_ilock_nowait(ip, lock_flags) == 0) {
  988. if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
  989. ip = ip->i_mnext;
  990. continue;
  991. }
  992. /*
  993. * We need to unlock the inode list lock in order
  994. * to lock the inode. Insert a marker record into
  995. * the inode list to remember our position, dropping
  996. * the lock is now done inside the IPOINTER_INSERT
  997. * macro.
  998. *
  999. * We also use the inode list lock to protect us
  1000. * in taking a snapshot of the vnode version number
  1001. * for use in calling vn_get().
  1002. */
  1003. VMAP(vp, vmap);
  1004. IPOINTER_INSERT(ip, mp);
  1005. vp = vn_get(vp, &vmap);
  1006. if (vp == NULL) {
  1007. /*
  1008. * The vnode was reclaimed once we let go
  1009. * of the inode list lock. Skip to the
  1010. * next list entry. Remove the marker.
  1011. */
  1012. XFS_MOUNT_ILOCK(mp);
  1013. mount_locked = B_TRUE;
  1014. vnode_refed = B_FALSE;
  1015. IPOINTER_REMOVE(ip, mp);
  1016. continue;
  1017. }
  1018. xfs_ilock(ip, lock_flags);
  1019. ASSERT(vp == XFS_ITOV(ip));
  1020. ASSERT(ip->i_mount == mp);
  1021. vnode_refed = B_TRUE;
  1022. }
  1023. /* From here on in the loop we may have a marker record
  1024. * in the inode list.
  1025. */
  1026. if ((flags & SYNC_CLOSE) && (vp != NULL)) {
  1027. /*
  1028. * This is the shutdown case. We just need to
  1029. * flush and invalidate all the pages associated
  1030. * with the inode. Drop the inode lock since
  1031. * we can't hold it across calls to the buffer
  1032. * cache.
  1033. *
  1034. * We don't set the VREMAPPING bit in the vnode
  1035. * here, because we don't hold the vnode lock
  1036. * exclusively. It doesn't really matter, though,
  1037. * because we only come here when we're shutting
  1038. * down anyway.
  1039. */
  1040. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1041. if (XFS_FORCED_SHUTDOWN(mp)) {
  1042. VOP_TOSS_PAGES(vp, 0, -1, FI_REMAPF);
  1043. } else {
  1044. VOP_FLUSHINVAL_PAGES(vp, 0, -1, FI_REMAPF);
  1045. }
  1046. xfs_ilock(ip, XFS_ILOCK_SHARED);
  1047. } else if ((flags & SYNC_DELWRI) && (vp != NULL)) {
  1048. if (VN_DIRTY(vp)) {
  1049. /* We need to have dropped the lock here,
  1050. * so insert a marker if we have not already
  1051. * done so.
  1052. */
  1053. if (mount_locked) {
  1054. IPOINTER_INSERT(ip, mp);
  1055. }
  1056. /*
  1057. * Drop the inode lock since we can't hold it
  1058. * across calls to the buffer cache.
  1059. */
  1060. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1061. VOP_FLUSH_PAGES(vp, (xfs_off_t)0, -1,
  1062. fflag, FI_NONE, error);
  1063. xfs_ilock(ip, XFS_ILOCK_SHARED);
  1064. }
  1065. }
  1066. if (flags & SYNC_BDFLUSH) {
  1067. if ((flags & SYNC_ATTR) &&
  1068. ((ip->i_update_core) ||
  1069. ((ip->i_itemp != NULL) &&
  1070. (ip->i_itemp->ili_format.ilf_fields != 0)))) {
  1071. /* Insert marker and drop lock if not already
  1072. * done.
  1073. */
  1074. if (mount_locked) {
  1075. IPOINTER_INSERT(ip, mp);
  1076. }
  1077. /*
  1078. * We don't want the periodic flushing of the
  1079. * inodes by vfs_sync() to interfere with
  1080. * I/O to the file, especially read I/O
  1081. * where it is only the access time stamp
  1082. * that is being flushed out. To prevent
  1083. * long periods where we have both inode
  1084. * locks held shared here while reading the
  1085. * inode's buffer in from disk, we drop the
  1086. * inode lock while reading in the inode
  1087. * buffer. We have to release the buffer
  1088. * and reacquire the inode lock so that they
  1089. * are acquired in the proper order (inode
  1090. * locks first). The buffer will go at the
  1091. * end of the lru chain, though, so we can
  1092. * expect it to still be there when we go
  1093. * for it again in xfs_iflush().
  1094. */
  1095. if ((xfs_ipincount(ip) == 0) &&
  1096. xfs_iflock_nowait(ip)) {
  1097. xfs_ifunlock(ip);
  1098. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1099. error = xfs_itobp(mp, NULL, ip,
  1100. &dip, &bp, 0);
  1101. if (!error) {
  1102. xfs_buf_relse(bp);
  1103. } else {
  1104. /* Bailing out, remove the
  1105. * marker and free it.
  1106. */
  1107. XFS_MOUNT_ILOCK(mp);
  1108. IPOINTER_REMOVE(ip, mp);
  1109. XFS_MOUNT_IUNLOCK(mp);
  1110. ASSERT(!(lock_flags &
  1111. XFS_IOLOCK_SHARED));
  1112. kmem_free(ipointer,
  1113. sizeof(xfs_iptr_t));
  1114. return (0);
  1115. }
  1116. /*
  1117. * Since we dropped the inode lock,
  1118. * the inode may have been reclaimed.
  1119. * Therefore, we reacquire the mount
  1120. * lock and check to see if we were the
  1121. * inode reclaimed. If this happened
  1122. * then the ipointer marker will no
  1123. * longer point back at us. In this
  1124. * case, move ip along to the inode
  1125. * after the marker, remove the marker
  1126. * and continue.
  1127. */
  1128. XFS_MOUNT_ILOCK(mp);
  1129. mount_locked = B_TRUE;
  1130. if (ip != ipointer->ip_mprev) {
  1131. IPOINTER_REMOVE(ip, mp);
  1132. ASSERT(!vnode_refed);
  1133. ASSERT(!(lock_flags &
  1134. XFS_IOLOCK_SHARED));
  1135. continue;
  1136. }
  1137. ASSERT(ip->i_mount == mp);
  1138. if (xfs_ilock_nowait(ip,
  1139. XFS_ILOCK_SHARED) == 0) {
  1140. ASSERT(ip->i_mount == mp);
  1141. /*
  1142. * We failed to reacquire
  1143. * the inode lock without
  1144. * sleeping, so just skip
  1145. * the inode for now. We
  1146. * clear the ILOCK bit from
  1147. * the lock_flags so that we
  1148. * won't try to drop a lock
  1149. * we don't hold below.
  1150. */
  1151. lock_flags &= ~XFS_ILOCK_SHARED;
  1152. IPOINTER_REMOVE(ip_next, mp);
  1153. } else if ((xfs_ipincount(ip) == 0) &&
  1154. xfs_iflock_nowait(ip)) {
  1155. ASSERT(ip->i_mount == mp);
  1156. /*
  1157. * Since this is vfs_sync()
  1158. * calling we only flush the
  1159. * inode out if we can lock
  1160. * it without sleeping and
  1161. * it is not pinned. Drop
  1162. * the mount lock here so
  1163. * that we don't hold it for
  1164. * too long. We already have
  1165. * a marker in the list here.
  1166. */
  1167. XFS_MOUNT_IUNLOCK(mp);
  1168. mount_locked = B_FALSE;
  1169. error = xfs_iflush(ip,
  1170. XFS_IFLUSH_DELWRI);
  1171. } else {
  1172. ASSERT(ip->i_mount == mp);
  1173. IPOINTER_REMOVE(ip_next, mp);
  1174. }
  1175. }
  1176. }
  1177. } else {
  1178. if ((flags & SYNC_ATTR) &&
  1179. ((ip->i_update_core) ||
  1180. ((ip->i_itemp != NULL) &&
  1181. (ip->i_itemp->ili_format.ilf_fields != 0)))) {
  1182. if (mount_locked) {
  1183. IPOINTER_INSERT(ip, mp);
  1184. }
  1185. if (flags & SYNC_WAIT) {
  1186. xfs_iflock(ip);
  1187. error = xfs_iflush(ip,
  1188. XFS_IFLUSH_SYNC);
  1189. } else {
  1190. /*
  1191. * If we can't acquire the flush
  1192. * lock, then the inode is already
  1193. * being flushed so don't bother
  1194. * waiting. If we can lock it then
  1195. * do a delwri flush so we can
  1196. * combine multiple inode flushes
  1197. * in each disk write.
  1198. */
  1199. if (xfs_iflock_nowait(ip)) {
  1200. error = xfs_iflush(ip,
  1201. XFS_IFLUSH_DELWRI);
  1202. }
  1203. else if (bypassed)
  1204. (*bypassed)++;
  1205. }
  1206. }
  1207. }
  1208. if (lock_flags != 0) {
  1209. xfs_iunlock(ip, lock_flags);
  1210. }
  1211. if (vnode_refed) {
  1212. /*
  1213. * If we had to take a reference on the vnode
  1214. * above, then wait until after we've unlocked
  1215. * the inode to release the reference. This is
  1216. * because we can be already holding the inode
  1217. * lock when VN_RELE() calls xfs_inactive().
  1218. *
  1219. * Make sure to drop the mount lock before calling
  1220. * VN_RELE() so that we don't trip over ourselves if
  1221. * we have to go for the mount lock again in the
  1222. * inactive code.
  1223. */
  1224. if (mount_locked) {
  1225. IPOINTER_INSERT(ip, mp);
  1226. }
  1227. VN_RELE(vp);
  1228. vnode_refed = B_FALSE;
  1229. }
  1230. if (error) {
  1231. last_error = error;
  1232. }
  1233. /*
  1234. * bail out if the filesystem is corrupted.
  1235. */
  1236. if (error == EFSCORRUPTED) {
  1237. if (!mount_locked) {
  1238. XFS_MOUNT_ILOCK(mp);
  1239. IPOINTER_REMOVE(ip, mp);
  1240. }
  1241. XFS_MOUNT_IUNLOCK(mp);
  1242. ASSERT(ipointer_in == B_FALSE);
  1243. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1244. return XFS_ERROR(error);
  1245. }
  1246. /* Let other threads have a chance at the mount lock
  1247. * if we have looped many times without dropping the
  1248. * lock.
  1249. */
  1250. if ((++preempt & XFS_PREEMPT_MASK) == 0) {
  1251. if (mount_locked) {
  1252. IPOINTER_INSERT(ip, mp);
  1253. }
  1254. }
  1255. if (mount_locked == B_FALSE) {
  1256. XFS_MOUNT_ILOCK(mp);
  1257. mount_locked = B_TRUE;
  1258. IPOINTER_REMOVE(ip, mp);
  1259. continue;
  1260. }
  1261. ASSERT(ipointer_in == B_FALSE);
  1262. ip = ip->i_mnext;
  1263. } while (ip != mp->m_inodes);
  1264. XFS_MOUNT_IUNLOCK(mp);
  1265. ASSERT(ipointer_in == B_FALSE);
  1266. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1267. return XFS_ERROR(last_error);
  1268. }
  1269. /*
  1270. * xfs sync routine for internal use
  1271. *
  1272. * This routine supports all of the flags defined for the generic VFS_SYNC
  1273. * interface as explained above under xfs_sync. In the interests of not
  1274. * changing interfaces within the 6.5 family, additional internallly-
  1275. * required functions are specified within a separate xflags parameter,
  1276. * only available by calling this routine.
  1277. *
  1278. */
  1279. int
  1280. xfs_syncsub(
  1281. xfs_mount_t *mp,
  1282. int flags,
  1283. int xflags,
  1284. int *bypassed)
  1285. {
  1286. int error = 0;
  1287. int last_error = 0;
  1288. uint log_flags = XFS_LOG_FORCE;
  1289. xfs_buf_t *bp;
  1290. xfs_buf_log_item_t *bip;
  1291. /*
  1292. * Sync out the log. This ensures that the log is periodically
  1293. * flushed even if there is not enough activity to fill it up.
  1294. */
  1295. if (flags & SYNC_WAIT)
  1296. log_flags |= XFS_LOG_SYNC;
  1297. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1298. if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
  1299. if (flags & SYNC_BDFLUSH)
  1300. xfs_finish_reclaim_all(mp, 1);
  1301. else
  1302. error = xfs_sync_inodes(mp, flags, xflags, bypassed);
  1303. }
  1304. /*
  1305. * Flushing out dirty data above probably generated more
  1306. * log activity, so if this isn't vfs_sync() then flush
  1307. * the log again.
  1308. */
  1309. if (flags & SYNC_DELWRI) {
  1310. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1311. }
  1312. if (flags & SYNC_FSDATA) {
  1313. /*
  1314. * If this is vfs_sync() then only sync the superblock
  1315. * if we can lock it without sleeping and it is not pinned.
  1316. */
  1317. if (flags & SYNC_BDFLUSH) {
  1318. bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
  1319. if (bp != NULL) {
  1320. bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
  1321. if ((bip != NULL) &&
  1322. xfs_buf_item_dirty(bip)) {
  1323. if (!(XFS_BUF_ISPINNED(bp))) {
  1324. XFS_BUF_ASYNC(bp);
  1325. error = xfs_bwrite(mp, bp);
  1326. } else {
  1327. xfs_buf_relse(bp);
  1328. }
  1329. } else {
  1330. xfs_buf_relse(bp);
  1331. }
  1332. }
  1333. } else {
  1334. bp = xfs_getsb(mp, 0);
  1335. /*
  1336. * If the buffer is pinned then push on the log so
  1337. * we won't get stuck waiting in the write for
  1338. * someone, maybe ourselves, to flush the log.
  1339. * Even though we just pushed the log above, we
  1340. * did not have the superblock buffer locked at
  1341. * that point so it can become pinned in between
  1342. * there and here.
  1343. */
  1344. if (XFS_BUF_ISPINNED(bp))
  1345. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  1346. if (flags & SYNC_WAIT)
  1347. XFS_BUF_UNASYNC(bp);
  1348. else
  1349. XFS_BUF_ASYNC(bp);
  1350. error = xfs_bwrite(mp, bp);
  1351. }
  1352. if (error) {
  1353. last_error = error;
  1354. }
  1355. }
  1356. /*
  1357. * If this is the periodic sync, then kick some entries out of
  1358. * the reference cache. This ensures that idle entries are
  1359. * eventually kicked out of the cache.
  1360. */
  1361. if (flags & SYNC_REFCACHE) {
  1362. xfs_refcache_purge_some(mp);
  1363. }
  1364. /*
  1365. * Now check to see if the log needs a "dummy" transaction.
  1366. */
  1367. if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
  1368. xfs_trans_t *tp;
  1369. xfs_inode_t *ip;
  1370. /*
  1371. * Put a dummy transaction in the log to tell
  1372. * recovery that all others are OK.
  1373. */
  1374. tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
  1375. if ((error = xfs_trans_reserve(tp, 0,
  1376. XFS_ICHANGE_LOG_RES(mp),
  1377. 0, 0, 0))) {
  1378. xfs_trans_cancel(tp, 0);
  1379. return error;
  1380. }
  1381. ip = mp->m_rootip;
  1382. xfs_ilock(ip, XFS_ILOCK_EXCL);
  1383. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  1384. xfs_trans_ihold(tp, ip);
  1385. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  1386. error = xfs_trans_commit(tp, 0, NULL);
  1387. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1388. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1389. }
  1390. /*
  1391. * When shutting down, we need to insure that the AIL is pushed
  1392. * to disk or the filesystem can appear corrupt from the PROM.
  1393. */
  1394. if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
  1395. XFS_bflush(mp->m_ddev_targp);
  1396. if (mp->m_rtdev_targp) {
  1397. XFS_bflush(mp->m_rtdev_targp);
  1398. }
  1399. }
  1400. return XFS_ERROR(last_error);
  1401. }
  1402. /*
  1403. * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
  1404. */
  1405. STATIC int
  1406. xfs_vget(
  1407. bhv_desc_t *bdp,
  1408. vnode_t **vpp,
  1409. fid_t *fidp)
  1410. {
  1411. xfs_mount_t *mp = XFS_BHVTOM(bdp);
  1412. xfs_fid_t *xfid = (struct xfs_fid *)fidp;
  1413. xfs_inode_t *ip;
  1414. int error;
  1415. xfs_ino_t ino;
  1416. unsigned int igen;
  1417. /*
  1418. * Invalid. Since handles can be created in user space and passed in
  1419. * via gethandle(), this is not cause for a panic.
  1420. */
  1421. if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
  1422. return XFS_ERROR(EINVAL);
  1423. ino = xfid->xfs_fid_ino;
  1424. igen = xfid->xfs_fid_gen;
  1425. /*
  1426. * NFS can sometimes send requests for ino 0. Fail them gracefully.
  1427. */
  1428. if (ino == 0)
  1429. return XFS_ERROR(ESTALE);
  1430. error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
  1431. if (error) {
  1432. *vpp = NULL;
  1433. return error;
  1434. }
  1435. if (ip == NULL) {
  1436. *vpp = NULL;
  1437. return XFS_ERROR(EIO);
  1438. }
  1439. if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
  1440. xfs_iput_new(ip, XFS_ILOCK_SHARED);
  1441. *vpp = NULL;
  1442. return XFS_ERROR(ENOENT);
  1443. }
  1444. *vpp = XFS_ITOV(ip);
  1445. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1446. return 0;
  1447. }
  1448. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  1449. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  1450. #define MNTOPT_LOGDEV "logdev" /* log device */
  1451. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  1452. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  1453. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  1454. #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
  1455. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  1456. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  1457. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  1458. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  1459. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  1460. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  1461. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  1462. #define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
  1463. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  1464. #define MNTOPT_NOLOGFLUSH "nologflush" /* don't hard flush on log writes */
  1465. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  1466. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  1467. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  1468. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  1469. STATIC unsigned long
  1470. suffix_strtoul(const char *cp, char **endp, unsigned int base)
  1471. {
  1472. int last, shift_left_factor = 0;
  1473. char *value = (char *)cp;
  1474. last = strlen(value) - 1;
  1475. if (value[last] == 'K' || value[last] == 'k') {
  1476. shift_left_factor = 10;
  1477. value[last] = '\0';
  1478. }
  1479. if (value[last] == 'M' || value[last] == 'm') {
  1480. shift_left_factor = 20;
  1481. value[last] = '\0';
  1482. }
  1483. if (value[last] == 'G' || value[last] == 'g') {
  1484. shift_left_factor = 30;
  1485. value[last] = '\0';
  1486. }
  1487. return simple_strtoul(cp, endp, base) << shift_left_factor;
  1488. }
  1489. int
  1490. xfs_parseargs(
  1491. struct bhv_desc *bhv,
  1492. char *options,
  1493. struct xfs_mount_args *args,
  1494. int update)
  1495. {
  1496. struct vfs *vfsp = bhvtovfs(bhv);
  1497. char *this_char, *value, *eov;
  1498. int dsunit, dswidth, vol_dsunit, vol_dswidth;
  1499. int iosize;
  1500. #if 0 /* XXX: off by default, until some remaining issues ironed out */
  1501. args->flags |= XFSMNT_IDELETE; /* default to on */
  1502. #endif
  1503. if (!options)
  1504. return 0;
  1505. iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
  1506. while ((this_char = strsep(&options, ",")) != NULL) {
  1507. if (!*this_char)
  1508. continue;
  1509. if ((value = strchr(this_char, '=')) != NULL)
  1510. *value++ = 0;
  1511. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  1512. if (!value || !*value) {
  1513. printk("XFS: %s option requires an argument\n",
  1514. this_char);
  1515. return EINVAL;
  1516. }
  1517. args->logbufs = simple_strtoul(value, &eov, 10);
  1518. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  1519. if (!value || !*value) {
  1520. printk("XFS: %s option requires an argument\n",
  1521. this_char);
  1522. return EINVAL;
  1523. }
  1524. args->logbufsize = suffix_strtoul(value, &eov, 10);
  1525. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  1526. if (!value || !*value) {
  1527. printk("XFS: %s option requires an argument\n",
  1528. this_char);
  1529. return EINVAL;
  1530. }
  1531. strncpy(args->logname, value, MAXNAMELEN);
  1532. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  1533. if (!value || !*value) {
  1534. printk("XFS: %s option requires an argument\n",
  1535. this_char);
  1536. return EINVAL;
  1537. }
  1538. strncpy(args->mtpt, value, MAXNAMELEN);
  1539. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  1540. if (!value || !*value) {
  1541. printk("XFS: %s option requires an argument\n",
  1542. this_char);
  1543. return EINVAL;
  1544. }
  1545. strncpy(args->rtname, value, MAXNAMELEN);
  1546. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  1547. if (!value || !*value) {
  1548. printk("XFS: %s option requires an argument\n",
  1549. this_char);
  1550. return EINVAL;
  1551. }
  1552. iosize = simple_strtoul(value, &eov, 10);
  1553. args->flags |= XFSMNT_IOSIZE;
  1554. args->iosizelog = (uint8_t) iosize;
  1555. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  1556. if (!value || !*value) {
  1557. printk("XFS: %s option requires an argument\n",
  1558. this_char);
  1559. return EINVAL;
  1560. }
  1561. iosize = suffix_strtoul(value, &eov, 10);
  1562. args->flags |= XFSMNT_IOSIZE;
  1563. args->iosizelog = ffs(iosize) - 1;
  1564. } else if (!strcmp(this_char, MNTOPT_IHASHSIZE)) {
  1565. if (!value || !*value) {
  1566. printk("XFS: %s option requires an argument\n",
  1567. this_char);
  1568. return EINVAL;
  1569. }
  1570. args->flags |= XFSMNT_IHASHSIZE;
  1571. args->ihashsize = simple_strtoul(value, &eov, 10);
  1572. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  1573. args->flags |= XFSMNT_WSYNC;
  1574. } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
  1575. args->flags |= XFSMNT_OSYNCISOSYNC;
  1576. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  1577. args->flags |= XFSMNT_NORECOVERY;
  1578. } else if (!strcmp(this_char, MNTOPT_INO64)) {
  1579. args->flags |= XFSMNT_INO64;
  1580. #if !XFS_BIG_INUMS
  1581. printk("XFS: %s option not allowed on this system\n",
  1582. this_char);
  1583. return EINVAL;
  1584. #endif
  1585. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  1586. args->flags |= XFSMNT_NOALIGN;
  1587. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  1588. args->flags |= XFSMNT_SWALLOC;
  1589. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  1590. if (!value || !*value) {
  1591. printk("XFS: %s option requires an argument\n",
  1592. this_char);
  1593. return EINVAL;
  1594. }
  1595. dsunit = simple_strtoul(value, &eov, 10);
  1596. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  1597. if (!value || !*value) {
  1598. printk("XFS: %s option requires an argument\n",
  1599. this_char);
  1600. return EINVAL;
  1601. }
  1602. dswidth = simple_strtoul(value, &eov, 10);
  1603. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  1604. args->flags &= ~XFSMNT_32BITINODES;
  1605. #if !XFS_BIG_INUMS
  1606. printk("XFS: %s option not allowed on this system\n",
  1607. this_char);
  1608. return EINVAL;
  1609. #endif
  1610. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  1611. args->flags |= XFSMNT_NOUUID;
  1612. } else if (!strcmp(this_char, MNTOPT_NOLOGFLUSH)) {
  1613. args->flags |= XFSMNT_NOLOGFLUSH;
  1614. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  1615. args->flags &= ~XFSMNT_IDELETE;
  1616. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  1617. args->flags |= XFSMNT_IDELETE;
  1618. } else if (!strcmp(this_char, "osyncisdsync")) {
  1619. /* no-op, this is now the default */
  1620. printk("XFS: osyncisdsync is now the default, option is deprecated.\n");
  1621. } else if (!strcmp(this_char, "irixsgid")) {
  1622. printk("XFS: irixsgid is now a sysctl(2) variable, option is deprecated.\n");
  1623. } else {
  1624. printk("XFS: unknown mount option [%s].\n", this_char);
  1625. return EINVAL;
  1626. }
  1627. }
  1628. if (args->flags & XFSMNT_NORECOVERY) {
  1629. if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
  1630. printk("XFS: no-recovery mounts must be read-only.\n");
  1631. return EINVAL;
  1632. }
  1633. }
  1634. if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
  1635. printk(
  1636. "XFS: sunit and swidth options incompatible with the noalign option\n");
  1637. return EINVAL;
  1638. }
  1639. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  1640. printk("XFS: sunit and swidth must be specified together\n");
  1641. return EINVAL;
  1642. }
  1643. if (dsunit && (dswidth % dsunit != 0)) {
  1644. printk(
  1645. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)\n",
  1646. dswidth, dsunit);
  1647. return EINVAL;
  1648. }
  1649. if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  1650. if (dsunit) {
  1651. args->sunit = dsunit;
  1652. args->flags |= XFSMNT_RETERR;
  1653. } else {
  1654. args->sunit = vol_dsunit;
  1655. }
  1656. dswidth ? (args->swidth = dswidth) :
  1657. (args->swidth = vol_dswidth);
  1658. } else {
  1659. args->sunit = args->swidth = 0;
  1660. }
  1661. return 0;
  1662. }
  1663. int
  1664. xfs_showargs(
  1665. struct bhv_desc *bhv,
  1666. struct seq_file *m)
  1667. {
  1668. static struct proc_xfs_info {
  1669. int flag;
  1670. char *str;
  1671. } xfs_info[] = {
  1672. /* the few simple ones we can get from the mount struct */
  1673. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  1674. { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
  1675. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  1676. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  1677. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  1678. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  1679. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  1680. { XFS_MOUNT_NOLOGFLUSH, "," MNTOPT_NOLOGFLUSH },
  1681. { XFS_MOUNT_IDELETE, "," MNTOPT_NOIKEEP },
  1682. { 0, NULL }
  1683. };
  1684. struct proc_xfs_info *xfs_infop;
  1685. struct xfs_mount *mp = XFS_BHVTOM(bhv);
  1686. for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
  1687. if (mp->m_flags & xfs_infop->flag)
  1688. seq_puts(m, xfs_infop->str);
  1689. }
  1690. if (mp->m_flags & XFS_MOUNT_IHASHSIZE)
  1691. seq_printf(m, "," MNTOPT_IHASHSIZE "=%d", mp->m_ihsize);
  1692. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  1693. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%d", 1<<mp->m_writeio_log);
  1694. if (mp->m_logbufs > 0)
  1695. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  1696. if (mp->m_logbsize > 0)
  1697. seq_printf(m, "," MNTOPT_LOGBSIZE "=%d", mp->m_logbsize);
  1698. if (mp->m_ddev_targp != mp->m_logdev_targp)
  1699. seq_printf(m, "," MNTOPT_LOGDEV "=%s",
  1700. XFS_BUFTARG_NAME(mp->m_logdev_targp));
  1701. if (mp->m_rtdev_targp && mp->m_ddev_targp != mp->m_rtdev_targp)
  1702. seq_printf(m, "," MNTOPT_RTDEV "=%s",
  1703. XFS_BUFTARG_NAME(mp->m_rtdev_targp));
  1704. if (mp->m_dalign > 0)
  1705. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  1706. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  1707. if (mp->m_swidth > 0)
  1708. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  1709. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  1710. if (!(mp->m_flags & XFS_MOUNT_32BITINOOPT))
  1711. seq_printf(m, "," MNTOPT_64BITINODE);
  1712. return 0;
  1713. }
  1714. STATIC void
  1715. xfs_freeze(
  1716. bhv_desc_t *bdp)
  1717. {
  1718. xfs_mount_t *mp = XFS_BHVTOM(bdp);
  1719. while (atomic_read(&mp->m_active_trans) > 0)
  1720. delay(100);
  1721. /* Push the superblock and write an unmount record */
  1722. xfs_log_unmount_write(mp);
  1723. xfs_unmountfs_writesb(mp);
  1724. }
  1725. vfsops_t xfs_vfsops = {
  1726. BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
  1727. .vfs_parseargs = xfs_parseargs,
  1728. .vfs_showargs = xfs_showargs,
  1729. .vfs_mount = xfs_mount,
  1730. .vfs_unmount = xfs_unmount,
  1731. .vfs_mntupdate = xfs_mntupdate,
  1732. .vfs_root = xfs_root,
  1733. .vfs_statvfs = xfs_statvfs,
  1734. .vfs_sync = xfs_sync,
  1735. .vfs_vget = xfs_vget,
  1736. .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
  1737. .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
  1738. .vfs_init_vnode = xfs_initialize_vnode,
  1739. .vfs_force_shutdown = xfs_do_force_shutdown,
  1740. .vfs_freeze = xfs_freeze,
  1741. };