xfs_vfsops.c 53 KB

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