xfs_vfsops.c 53 KB

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