xfs_vfsops.c 52 KB

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