xfs_vfsops.c 53 KB

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