xfs_vfsops.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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. #include "xfs_vfsops.h"
  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 spinlock_t xfs_dabuf_global_lock;
  69. spin_lock_init(&xfs_dabuf_global_lock);
  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 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_logbsize = ap->logbufsize;
  235. mp->m_fsname_len = strlen(ap->fsname) + 1;
  236. mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
  237. strcpy(mp->m_fsname, ap->fsname);
  238. if (ap->rtname[0]) {
  239. mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
  240. strcpy(mp->m_rtname, ap->rtname);
  241. }
  242. if (ap->logname[0]) {
  243. mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
  244. strcpy(mp->m_logname, ap->logname);
  245. }
  246. if (ap->flags & XFSMNT_WSYNC)
  247. mp->m_flags |= XFS_MOUNT_WSYNC;
  248. #if XFS_BIG_INUMS
  249. if (ap->flags & XFSMNT_INO64) {
  250. mp->m_flags |= XFS_MOUNT_INO64;
  251. mp->m_inoadd = XFS_INO64_OFFSET;
  252. }
  253. #endif
  254. if (ap->flags & XFSMNT_RETERR)
  255. mp->m_flags |= XFS_MOUNT_RETERR;
  256. if (ap->flags & XFSMNT_NOALIGN)
  257. mp->m_flags |= XFS_MOUNT_NOALIGN;
  258. if (ap->flags & XFSMNT_SWALLOC)
  259. mp->m_flags |= XFS_MOUNT_SWALLOC;
  260. if (ap->flags & XFSMNT_OSYNCISOSYNC)
  261. mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
  262. if (ap->flags & XFSMNT_32BITINODES)
  263. mp->m_flags |= XFS_MOUNT_32BITINODES;
  264. if (ap->flags & XFSMNT_IOSIZE) {
  265. if (ap->iosizelog > XFS_MAX_IO_LOG ||
  266. ap->iosizelog < XFS_MIN_IO_LOG) {
  267. cmn_err(CE_WARN,
  268. "XFS: invalid log iosize: %d [not %d-%d]",
  269. ap->iosizelog, XFS_MIN_IO_LOG,
  270. XFS_MAX_IO_LOG);
  271. return XFS_ERROR(EINVAL);
  272. }
  273. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  274. mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
  275. }
  276. if (ap->flags & XFSMNT_IDELETE)
  277. mp->m_flags |= XFS_MOUNT_IDELETE;
  278. if (ap->flags & XFSMNT_DIRSYNC)
  279. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  280. if (ap->flags & XFSMNT_ATTR2)
  281. mp->m_flags |= XFS_MOUNT_ATTR2;
  282. if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
  283. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  284. /*
  285. * no recovery flag requires a read-only mount
  286. */
  287. if (ap->flags & XFSMNT_NORECOVERY) {
  288. if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
  289. cmn_err(CE_WARN,
  290. "XFS: tried to mount a FS read-write without recovery!");
  291. return XFS_ERROR(EINVAL);
  292. }
  293. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  294. }
  295. if (ap->flags & XFSMNT_NOUUID)
  296. mp->m_flags |= XFS_MOUNT_NOUUID;
  297. if (ap->flags & XFSMNT_BARRIER)
  298. mp->m_flags |= XFS_MOUNT_BARRIER;
  299. else
  300. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  301. if (ap->flags2 & XFSMNT2_FILESTREAMS)
  302. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  303. if (ap->flags & XFSMNT_DMAPI)
  304. mp->m_flags |= XFS_MOUNT_DMAPI;
  305. return 0;
  306. }
  307. /*
  308. * This function fills in xfs_mount_t fields based on mount args.
  309. * Note: the superblock _has_ now been read in.
  310. */
  311. STATIC int
  312. xfs_finish_flags(
  313. struct xfs_mount_args *ap,
  314. struct xfs_mount *mp)
  315. {
  316. int ronly = (mp->m_flags & XFS_MOUNT_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. if (ap->flags & XFSMNT_UQUOTA) {
  370. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  371. if (ap->flags & XFSMNT_UQUOTAENF)
  372. mp->m_qflags |= XFS_UQUOTA_ENFD;
  373. }
  374. if (ap->flags & XFSMNT_GQUOTA) {
  375. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  376. if (ap->flags & XFSMNT_GQUOTAENF)
  377. mp->m_qflags |= XFS_OQUOTA_ENFD;
  378. } else if (ap->flags & XFSMNT_PQUOTA) {
  379. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  380. if (ap->flags & XFSMNT_PQUOTAENF)
  381. mp->m_qflags |= XFS_OQUOTA_ENFD;
  382. }
  383. return 0;
  384. }
  385. /*
  386. * xfs_mount
  387. *
  388. * The file system configurations are:
  389. * (1) device (partition) with data and internal log
  390. * (2) logical volume with data and log subvolumes.
  391. * (3) logical volume with data, log, and realtime subvolumes.
  392. *
  393. * We only have to handle opening the log and realtime volumes here if
  394. * they are present. The data subvolume has already been opened by
  395. * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
  396. */
  397. int
  398. xfs_mount(
  399. struct xfs_mount *mp,
  400. struct xfs_mount_args *args,
  401. cred_t *credp)
  402. {
  403. struct block_device *ddev, *logdev, *rtdev;
  404. int flags = 0, error;
  405. ddev = mp->m_super->s_bdev;
  406. logdev = rtdev = NULL;
  407. error = xfs_dmops_get(mp, args);
  408. if (error)
  409. return error;
  410. error = xfs_qmops_get(mp, args);
  411. if (error)
  412. return error;
  413. if (args->flags & XFSMNT_QUIET)
  414. flags |= XFS_MFSI_QUIET;
  415. /*
  416. * Open real time and log devices - order is important.
  417. */
  418. if (args->logname[0]) {
  419. error = xfs_blkdev_get(mp, args->logname, &logdev);
  420. if (error)
  421. return error;
  422. }
  423. if (args->rtname[0]) {
  424. error = xfs_blkdev_get(mp, args->rtname, &rtdev);
  425. if (error) {
  426. xfs_blkdev_put(logdev);
  427. return error;
  428. }
  429. if (rtdev == ddev || rtdev == logdev) {
  430. cmn_err(CE_WARN,
  431. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  432. xfs_blkdev_put(logdev);
  433. xfs_blkdev_put(rtdev);
  434. return EINVAL;
  435. }
  436. }
  437. /*
  438. * Setup xfs_mount buffer target pointers
  439. */
  440. error = ENOMEM;
  441. mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
  442. if (!mp->m_ddev_targp) {
  443. xfs_blkdev_put(logdev);
  444. xfs_blkdev_put(rtdev);
  445. return error;
  446. }
  447. if (rtdev) {
  448. mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
  449. if (!mp->m_rtdev_targp) {
  450. xfs_blkdev_put(logdev);
  451. xfs_blkdev_put(rtdev);
  452. goto error0;
  453. }
  454. }
  455. mp->m_logdev_targp = (logdev && logdev != ddev) ?
  456. xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
  457. if (!mp->m_logdev_targp) {
  458. xfs_blkdev_put(logdev);
  459. xfs_blkdev_put(rtdev);
  460. goto error0;
  461. }
  462. /*
  463. * Setup flags based on mount(2) options and then the superblock
  464. */
  465. error = xfs_start_flags(args, mp);
  466. if (error)
  467. goto error1;
  468. error = xfs_readsb(mp, flags);
  469. if (error)
  470. goto error1;
  471. error = xfs_finish_flags(args, mp);
  472. if (error)
  473. goto error2;
  474. /*
  475. * Setup xfs_mount buffer target pointers based on superblock
  476. */
  477. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  478. mp->m_sb.sb_sectsize);
  479. if (!error && logdev && logdev != ddev) {
  480. unsigned int log_sector_size = BBSIZE;
  481. if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
  482. log_sector_size = mp->m_sb.sb_logsectsize;
  483. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  484. mp->m_sb.sb_blocksize,
  485. log_sector_size);
  486. }
  487. if (!error && rtdev)
  488. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  489. mp->m_sb.sb_blocksize,
  490. mp->m_sb.sb_sectsize);
  491. if (error)
  492. goto error2;
  493. if (mp->m_flags & XFS_MOUNT_BARRIER)
  494. xfs_mountfs_check_barriers(mp);
  495. if ((error = xfs_filestream_mount(mp)))
  496. goto error2;
  497. error = xfs_mountfs(mp, flags);
  498. if (error)
  499. goto error2;
  500. XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
  501. return 0;
  502. error2:
  503. if (mp->m_sb_bp)
  504. xfs_freesb(mp);
  505. error1:
  506. xfs_binval(mp->m_ddev_targp);
  507. if (logdev && logdev != ddev)
  508. xfs_binval(mp->m_logdev_targp);
  509. if (rtdev)
  510. xfs_binval(mp->m_rtdev_targp);
  511. error0:
  512. xfs_unmountfs_close(mp, credp);
  513. xfs_qmops_put(mp);
  514. xfs_dmops_put(mp);
  515. return error;
  516. }
  517. int
  518. xfs_unmount(
  519. xfs_mount_t *mp,
  520. int flags,
  521. cred_t *credp)
  522. {
  523. xfs_inode_t *rip;
  524. bhv_vnode_t *rvp;
  525. int unmount_event_wanted = 0;
  526. int unmount_event_flags = 0;
  527. int xfs_unmountfs_needed = 0;
  528. int error;
  529. rip = mp->m_rootip;
  530. rvp = XFS_ITOV(rip);
  531. #ifdef HAVE_DMAPI
  532. if (mp->m_flags & XFS_MOUNT_DMAPI) {
  533. error = XFS_SEND_PREUNMOUNT(mp,
  534. rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
  535. NULL, NULL, 0, 0,
  536. (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
  537. 0:DM_FLAGS_UNWANTED);
  538. if (error)
  539. return XFS_ERROR(error);
  540. unmount_event_wanted = 1;
  541. unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
  542. 0 : DM_FLAGS_UNWANTED;
  543. }
  544. #endif
  545. /*
  546. * First blow any referenced inode from this file system
  547. * out of the reference cache, and delete the timer.
  548. */
  549. xfs_refcache_purge_mp(mp);
  550. /*
  551. * Blow away any referenced inode in the filestreams cache.
  552. * This can and will cause log traffic as inodes go inactive
  553. * here.
  554. */
  555. xfs_filestream_unmount(mp);
  556. XFS_bflush(mp->m_ddev_targp);
  557. error = xfs_unmount_flush(mp, 0);
  558. if (error)
  559. goto out;
  560. ASSERT(vn_count(rvp) == 1);
  561. /*
  562. * Drop the reference count
  563. */
  564. VN_RELE(rvp);
  565. /*
  566. * If we're forcing a shutdown, typically because of a media error,
  567. * we want to make sure we invalidate dirty pages that belong to
  568. * referenced vnodes as well.
  569. */
  570. if (XFS_FORCED_SHUTDOWN(mp)) {
  571. error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
  572. ASSERT(error != EFSCORRUPTED);
  573. }
  574. xfs_unmountfs_needed = 1;
  575. out:
  576. /* Send DMAPI event, if required.
  577. * Then do xfs_unmountfs() if needed.
  578. * Then return error (or zero).
  579. */
  580. if (unmount_event_wanted) {
  581. /* Note: mp structure must still exist for
  582. * XFS_SEND_UNMOUNT() call.
  583. */
  584. XFS_SEND_UNMOUNT(mp, error == 0 ? rvp : NULL,
  585. DM_RIGHT_NULL, 0, error, unmount_event_flags);
  586. }
  587. if (xfs_unmountfs_needed) {
  588. /*
  589. * Call common unmount function to flush to disk
  590. * and free the super block buffer & mount structures.
  591. */
  592. xfs_unmountfs(mp, credp);
  593. xfs_qmops_put(mp);
  594. xfs_dmops_put(mp);
  595. kmem_free(mp, sizeof(xfs_mount_t));
  596. }
  597. return XFS_ERROR(error);
  598. }
  599. STATIC int
  600. xfs_quiesce_fs(
  601. xfs_mount_t *mp)
  602. {
  603. int count = 0, pincount;
  604. xfs_refcache_purge_mp(mp);
  605. xfs_flush_buftarg(mp->m_ddev_targp, 0);
  606. xfs_finish_reclaim_all(mp, 0);
  607. /* This loop must run at least twice.
  608. * The first instance of the loop will flush
  609. * most meta data but that will generate more
  610. * meta data (typically directory updates).
  611. * Which then must be flushed and logged before
  612. * we can write the unmount record.
  613. */
  614. do {
  615. xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
  616. pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
  617. if (!pincount) {
  618. delay(50);
  619. count++;
  620. }
  621. } while (count < 2);
  622. return 0;
  623. }
  624. /*
  625. * Second stage of a quiesce. The data is already synced, now we have to take
  626. * care of the metadata. New transactions are already blocked, so we need to
  627. * wait for any remaining transactions to drain out before proceding.
  628. */
  629. STATIC void
  630. xfs_attr_quiesce(
  631. xfs_mount_t *mp)
  632. {
  633. /* wait for all modifications to complete */
  634. while (atomic_read(&mp->m_active_trans) > 0)
  635. delay(100);
  636. /* flush inodes and push all remaining buffers out to disk */
  637. xfs_quiesce_fs(mp);
  638. ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
  639. /* Push the superblock and write an unmount record */
  640. xfs_log_sbcount(mp, 1);
  641. xfs_log_unmount_write(mp);
  642. xfs_unmountfs_writesb(mp);
  643. }
  644. int
  645. xfs_mntupdate(
  646. struct xfs_mount *mp,
  647. int *flags,
  648. struct xfs_mount_args *args)
  649. {
  650. if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
  651. if (mp->m_flags & XFS_MOUNT_RDONLY)
  652. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  653. if (args->flags & XFSMNT_BARRIER) {
  654. mp->m_flags |= XFS_MOUNT_BARRIER;
  655. xfs_mountfs_check_barriers(mp);
  656. } else {
  657. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  658. }
  659. } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
  660. xfs_filestream_flush(mp);
  661. xfs_sync(mp, SYNC_DATA_QUIESCE);
  662. xfs_attr_quiesce(mp);
  663. mp->m_flags |= XFS_MOUNT_RDONLY;
  664. }
  665. return 0;
  666. }
  667. /*
  668. * xfs_unmount_flush implements a set of flush operation on special
  669. * inodes, which are needed as a separate set of operations so that
  670. * they can be called as part of relocation process.
  671. */
  672. int
  673. xfs_unmount_flush(
  674. xfs_mount_t *mp, /* Mount structure we are getting
  675. rid of. */
  676. int relocation) /* Called from vfs relocation. */
  677. {
  678. xfs_inode_t *rip = mp->m_rootip;
  679. xfs_inode_t *rbmip;
  680. xfs_inode_t *rsumip = NULL;
  681. bhv_vnode_t *rvp = XFS_ITOV(rip);
  682. int error;
  683. xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
  684. xfs_iflock(rip);
  685. /*
  686. * Flush out the real time inodes.
  687. */
  688. if ((rbmip = mp->m_rbmip) != NULL) {
  689. xfs_ilock(rbmip, XFS_ILOCK_EXCL);
  690. xfs_iflock(rbmip);
  691. error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
  692. xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
  693. if (error == EFSCORRUPTED)
  694. goto fscorrupt_out;
  695. ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
  696. rsumip = mp->m_rsumip;
  697. xfs_ilock(rsumip, XFS_ILOCK_EXCL);
  698. xfs_iflock(rsumip);
  699. error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
  700. xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
  701. if (error == EFSCORRUPTED)
  702. goto fscorrupt_out;
  703. ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
  704. }
  705. /*
  706. * Synchronously flush root inode to disk
  707. */
  708. error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
  709. if (error == EFSCORRUPTED)
  710. goto fscorrupt_out2;
  711. if (vn_count(rvp) != 1 && !relocation) {
  712. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  713. return XFS_ERROR(EBUSY);
  714. }
  715. /*
  716. * Release dquot that rootinode, rbmino and rsumino might be holding,
  717. * flush and purge the quota inodes.
  718. */
  719. error = XFS_QM_UNMOUNT(mp);
  720. if (error == EFSCORRUPTED)
  721. goto fscorrupt_out2;
  722. if (rbmip) {
  723. VN_RELE(XFS_ITOV(rbmip));
  724. VN_RELE(XFS_ITOV(rsumip));
  725. }
  726. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  727. return 0;
  728. fscorrupt_out:
  729. xfs_ifunlock(rip);
  730. fscorrupt_out2:
  731. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  732. return XFS_ERROR(EFSCORRUPTED);
  733. }
  734. /*
  735. * xfs_root extracts the root vnode from a vfs.
  736. *
  737. * vfsp -- the vfs struct for the desired file system
  738. * vpp -- address of the caller's vnode pointer which should be
  739. * set to the desired fs root vnode
  740. */
  741. int
  742. xfs_root(
  743. xfs_mount_t *mp,
  744. bhv_vnode_t **vpp)
  745. {
  746. bhv_vnode_t *vp;
  747. vp = XFS_ITOV(mp->m_rootip);
  748. VN_HOLD(vp);
  749. *vpp = vp;
  750. return 0;
  751. }
  752. /*
  753. * xfs_sync flushes any pending I/O to file system vfsp.
  754. *
  755. * This routine is called by vfs_sync() to make sure that things make it
  756. * out to disk eventually, on sync() system calls to flush out everything,
  757. * and when the file system is unmounted. For the vfs_sync() case, all
  758. * we really need to do is sync out the log to make all of our meta-data
  759. * updates permanent (except for timestamps). For calls from pflushd(),
  760. * dirty pages are kept moving by calling pdflush() on the inodes
  761. * containing them. We also flush the inodes that we can lock without
  762. * sleeping and the superblock if we can lock it without sleeping from
  763. * vfs_sync() so that items at the tail of the log are always moving out.
  764. *
  765. * Flags:
  766. * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
  767. * to sleep if we can help it. All we really need
  768. * to do is ensure that the log is synced at least
  769. * periodically. We also push the inodes and
  770. * superblock if we can lock them without sleeping
  771. * and they are not pinned.
  772. * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
  773. * set, then we really want to lock each inode and flush
  774. * it.
  775. * SYNC_WAIT - All the flushes that take place in this call should
  776. * be synchronous.
  777. * SYNC_DELWRI - This tells us to push dirty pages associated with
  778. * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
  779. * determine if they should be flushed sync, async, or
  780. * delwri.
  781. * SYNC_CLOSE - This flag is passed when the system is being
  782. * unmounted. We should sync and invalidate everything.
  783. * SYNC_FSDATA - This indicates that the caller would like to make
  784. * sure the superblock is safe on disk. We can ensure
  785. * this by simply making sure the log gets flushed
  786. * if SYNC_BDFLUSH is set, and by actually writing it
  787. * out otherwise.
  788. * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
  789. * before we return (including direct I/O). Forms the drain
  790. * side of the write barrier needed to safely quiesce the
  791. * filesystem.
  792. *
  793. */
  794. int
  795. xfs_sync(
  796. xfs_mount_t *mp,
  797. int flags)
  798. {
  799. int error;
  800. /*
  801. * Get the Quota Manager to flush the dquots.
  802. *
  803. * If XFS quota support is not enabled or this filesystem
  804. * instance does not use quotas XFS_QM_DQSYNC will always
  805. * return zero.
  806. */
  807. error = XFS_QM_DQSYNC(mp, flags);
  808. if (error) {
  809. /*
  810. * If we got an IO error, we will be shutting down.
  811. * So, there's nothing more for us to do here.
  812. */
  813. ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
  814. if (XFS_FORCED_SHUTDOWN(mp))
  815. return XFS_ERROR(error);
  816. }
  817. if (flags & SYNC_IOWAIT)
  818. xfs_filestream_flush(mp);
  819. return xfs_syncsub(mp, flags, NULL);
  820. }
  821. /*
  822. * xfs sync routine for internal use
  823. *
  824. * This routine supports all of the flags defined for the generic vfs_sync
  825. * interface as explained above under xfs_sync.
  826. *
  827. */
  828. int
  829. xfs_sync_inodes(
  830. xfs_mount_t *mp,
  831. int flags,
  832. int *bypassed)
  833. {
  834. xfs_inode_t *ip = NULL;
  835. bhv_vnode_t *vp = NULL;
  836. int error;
  837. int last_error;
  838. uint64_t fflag;
  839. uint lock_flags;
  840. uint base_lock_flags;
  841. boolean_t mount_locked;
  842. boolean_t vnode_refed;
  843. int preempt;
  844. xfs_iptr_t *ipointer;
  845. #ifdef DEBUG
  846. boolean_t ipointer_in = B_FALSE;
  847. #define IPOINTER_SET ipointer_in = B_TRUE
  848. #define IPOINTER_CLR ipointer_in = B_FALSE
  849. #else
  850. #define IPOINTER_SET
  851. #define IPOINTER_CLR
  852. #endif
  853. /* Insert a marker record into the inode list after inode ip. The list
  854. * must be locked when this is called. After the call the list will no
  855. * longer be locked.
  856. */
  857. #define IPOINTER_INSERT(ip, mp) { \
  858. ASSERT(ipointer_in == B_FALSE); \
  859. ipointer->ip_mnext = ip->i_mnext; \
  860. ipointer->ip_mprev = ip; \
  861. ip->i_mnext = (xfs_inode_t *)ipointer; \
  862. ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
  863. preempt = 0; \
  864. XFS_MOUNT_IUNLOCK(mp); \
  865. mount_locked = B_FALSE; \
  866. IPOINTER_SET; \
  867. }
  868. /* Remove the marker from the inode list. If the marker was the only item
  869. * in the list then there are no remaining inodes and we should zero out
  870. * the whole list. If we are the current head of the list then move the head
  871. * past us.
  872. */
  873. #define IPOINTER_REMOVE(ip, mp) { \
  874. ASSERT(ipointer_in == B_TRUE); \
  875. if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
  876. ip = ipointer->ip_mnext; \
  877. ip->i_mprev = ipointer->ip_mprev; \
  878. ipointer->ip_mprev->i_mnext = ip; \
  879. if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
  880. mp->m_inodes = ip; \
  881. } \
  882. } else { \
  883. ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
  884. mp->m_inodes = NULL; \
  885. ip = NULL; \
  886. } \
  887. IPOINTER_CLR; \
  888. }
  889. #define XFS_PREEMPT_MASK 0x7f
  890. ASSERT(!(flags & SYNC_BDFLUSH));
  891. if (bypassed)
  892. *bypassed = 0;
  893. if (mp->m_flags & XFS_MOUNT_RDONLY)
  894. return 0;
  895. error = 0;
  896. last_error = 0;
  897. preempt = 0;
  898. /* Allocate a reference marker */
  899. ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
  900. fflag = XFS_B_ASYNC; /* default is don't wait */
  901. if (flags & SYNC_DELWRI)
  902. fflag = XFS_B_DELWRI;
  903. if (flags & SYNC_WAIT)
  904. fflag = 0; /* synchronous overrides all */
  905. base_lock_flags = XFS_ILOCK_SHARED;
  906. if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
  907. /*
  908. * We need the I/O lock if we're going to call any of
  909. * the flush/inval routines.
  910. */
  911. base_lock_flags |= XFS_IOLOCK_SHARED;
  912. }
  913. XFS_MOUNT_ILOCK(mp);
  914. ip = mp->m_inodes;
  915. mount_locked = B_TRUE;
  916. vnode_refed = B_FALSE;
  917. IPOINTER_CLR;
  918. do {
  919. ASSERT(ipointer_in == B_FALSE);
  920. ASSERT(vnode_refed == B_FALSE);
  921. lock_flags = base_lock_flags;
  922. /*
  923. * There were no inodes in the list, just break out
  924. * of the loop.
  925. */
  926. if (ip == NULL) {
  927. break;
  928. }
  929. /*
  930. * We found another sync thread marker - skip it
  931. */
  932. if (ip->i_mount == NULL) {
  933. ip = ip->i_mnext;
  934. continue;
  935. }
  936. vp = XFS_ITOV_NULL(ip);
  937. /*
  938. * If the vnode is gone then this is being torn down,
  939. * call reclaim if it is flushed, else let regular flush
  940. * code deal with it later in the loop.
  941. */
  942. if (vp == NULL) {
  943. /* Skip ones already in reclaim */
  944. if (ip->i_flags & XFS_IRECLAIM) {
  945. ip = ip->i_mnext;
  946. continue;
  947. }
  948. if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
  949. ip = ip->i_mnext;
  950. } else if ((xfs_ipincount(ip) == 0) &&
  951. xfs_iflock_nowait(ip)) {
  952. IPOINTER_INSERT(ip, mp);
  953. xfs_finish_reclaim(ip, 1,
  954. XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  955. XFS_MOUNT_ILOCK(mp);
  956. mount_locked = B_TRUE;
  957. IPOINTER_REMOVE(ip, mp);
  958. } else {
  959. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  960. ip = ip->i_mnext;
  961. }
  962. continue;
  963. }
  964. if (VN_BAD(vp)) {
  965. ip = ip->i_mnext;
  966. continue;
  967. }
  968. if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
  969. XFS_MOUNT_IUNLOCK(mp);
  970. kmem_free(ipointer, sizeof(xfs_iptr_t));
  971. return 0;
  972. }
  973. /*
  974. * Try to lock without sleeping. We're out of order with
  975. * the inode list lock here, so if we fail we need to drop
  976. * the mount lock and try again. If we're called from
  977. * bdflush() here, then don't bother.
  978. *
  979. * The inode lock here actually coordinates with the
  980. * almost spurious inode lock in xfs_ireclaim() to prevent
  981. * the vnode we handle here without a reference from
  982. * being freed while we reference it. If we lock the inode
  983. * while it's on the mount list here, then the spurious inode
  984. * lock in xfs_ireclaim() after the inode is pulled from
  985. * the mount list will sleep until we release it here.
  986. * This keeps the vnode from being freed while we reference
  987. * it.
  988. */
  989. if (xfs_ilock_nowait(ip, lock_flags) == 0) {
  990. if (vp == NULL) {
  991. ip = ip->i_mnext;
  992. continue;
  993. }
  994. vp = vn_grab(vp);
  995. if (vp == NULL) {
  996. ip = ip->i_mnext;
  997. continue;
  998. }
  999. IPOINTER_INSERT(ip, mp);
  1000. xfs_ilock(ip, lock_flags);
  1001. ASSERT(vp == XFS_ITOV(ip));
  1002. ASSERT(ip->i_mount == mp);
  1003. vnode_refed = B_TRUE;
  1004. }
  1005. /* From here on in the loop we may have a marker record
  1006. * in the inode list.
  1007. */
  1008. /*
  1009. * If we have to flush data or wait for I/O completion
  1010. * we need to drop the ilock that we currently hold.
  1011. * If we need to drop the lock, insert a marker if we
  1012. * have not already done so.
  1013. */
  1014. if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
  1015. ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
  1016. if (mount_locked) {
  1017. IPOINTER_INSERT(ip, mp);
  1018. }
  1019. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1020. if (flags & SYNC_CLOSE) {
  1021. /* Shutdown case. Flush and invalidate. */
  1022. if (XFS_FORCED_SHUTDOWN(mp))
  1023. xfs_tosspages(ip, 0, -1,
  1024. FI_REMAPF);
  1025. else
  1026. error = xfs_flushinval_pages(ip,
  1027. 0, -1, FI_REMAPF);
  1028. } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
  1029. error = xfs_flush_pages(ip, 0,
  1030. -1, fflag, FI_NONE);
  1031. }
  1032. /*
  1033. * When freezing, we need to wait ensure all I/O (including direct
  1034. * I/O) is complete to ensure no further data modification can take
  1035. * place after this point
  1036. */
  1037. if (flags & SYNC_IOWAIT)
  1038. vn_iowait(ip);
  1039. xfs_ilock(ip, XFS_ILOCK_SHARED);
  1040. }
  1041. if ((flags & SYNC_ATTR) &&
  1042. (ip->i_update_core ||
  1043. (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) {
  1044. if (mount_locked)
  1045. IPOINTER_INSERT(ip, mp);
  1046. if (flags & SYNC_WAIT) {
  1047. xfs_iflock(ip);
  1048. error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
  1049. /*
  1050. * If we can't acquire the flush lock, then the inode
  1051. * is already being flushed so don't bother waiting.
  1052. *
  1053. * If we can lock it then do a delwri flush so we can
  1054. * combine multiple inode flushes in each disk write.
  1055. */
  1056. } else if (xfs_iflock_nowait(ip)) {
  1057. error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
  1058. } else if (bypassed) {
  1059. (*bypassed)++;
  1060. }
  1061. }
  1062. if (lock_flags != 0) {
  1063. xfs_iunlock(ip, lock_flags);
  1064. }
  1065. if (vnode_refed) {
  1066. /*
  1067. * If we had to take a reference on the vnode
  1068. * above, then wait until after we've unlocked
  1069. * the inode to release the reference. This is
  1070. * because we can be already holding the inode
  1071. * lock when VN_RELE() calls xfs_inactive().
  1072. *
  1073. * Make sure to drop the mount lock before calling
  1074. * VN_RELE() so that we don't trip over ourselves if
  1075. * we have to go for the mount lock again in the
  1076. * inactive code.
  1077. */
  1078. if (mount_locked) {
  1079. IPOINTER_INSERT(ip, mp);
  1080. }
  1081. VN_RELE(vp);
  1082. vnode_refed = B_FALSE;
  1083. }
  1084. if (error) {
  1085. last_error = error;
  1086. }
  1087. /*
  1088. * bail out if the filesystem is corrupted.
  1089. */
  1090. if (error == EFSCORRUPTED) {
  1091. if (!mount_locked) {
  1092. XFS_MOUNT_ILOCK(mp);
  1093. IPOINTER_REMOVE(ip, mp);
  1094. }
  1095. XFS_MOUNT_IUNLOCK(mp);
  1096. ASSERT(ipointer_in == B_FALSE);
  1097. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1098. return XFS_ERROR(error);
  1099. }
  1100. /* Let other threads have a chance at the mount lock
  1101. * if we have looped many times without dropping the
  1102. * lock.
  1103. */
  1104. if ((++preempt & XFS_PREEMPT_MASK) == 0) {
  1105. if (mount_locked) {
  1106. IPOINTER_INSERT(ip, mp);
  1107. }
  1108. }
  1109. if (mount_locked == B_FALSE) {
  1110. XFS_MOUNT_ILOCK(mp);
  1111. mount_locked = B_TRUE;
  1112. IPOINTER_REMOVE(ip, mp);
  1113. continue;
  1114. }
  1115. ASSERT(ipointer_in == B_FALSE);
  1116. ip = ip->i_mnext;
  1117. } while (ip != mp->m_inodes);
  1118. XFS_MOUNT_IUNLOCK(mp);
  1119. ASSERT(ipointer_in == B_FALSE);
  1120. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1121. return XFS_ERROR(last_error);
  1122. }
  1123. /*
  1124. * xfs sync routine for internal use
  1125. *
  1126. * This routine supports all of the flags defined for the generic vfs_sync
  1127. * interface as explained above under xfs_sync.
  1128. *
  1129. */
  1130. int
  1131. xfs_syncsub(
  1132. xfs_mount_t *mp,
  1133. int flags,
  1134. int *bypassed)
  1135. {
  1136. int error = 0;
  1137. int last_error = 0;
  1138. uint log_flags = XFS_LOG_FORCE;
  1139. xfs_buf_t *bp;
  1140. xfs_buf_log_item_t *bip;
  1141. /*
  1142. * Sync out the log. This ensures that the log is periodically
  1143. * flushed even if there is not enough activity to fill it up.
  1144. */
  1145. if (flags & SYNC_WAIT)
  1146. log_flags |= XFS_LOG_SYNC;
  1147. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1148. if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
  1149. if (flags & SYNC_BDFLUSH)
  1150. xfs_finish_reclaim_all(mp, 1);
  1151. else
  1152. error = xfs_sync_inodes(mp, flags, bypassed);
  1153. }
  1154. /*
  1155. * Flushing out dirty data above probably generated more
  1156. * log activity, so if this isn't vfs_sync() then flush
  1157. * the log again.
  1158. */
  1159. if (flags & SYNC_DELWRI) {
  1160. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1161. }
  1162. if (flags & SYNC_FSDATA) {
  1163. /*
  1164. * If this is vfs_sync() then only sync the superblock
  1165. * if we can lock it without sleeping and it is not pinned.
  1166. */
  1167. if (flags & SYNC_BDFLUSH) {
  1168. bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
  1169. if (bp != NULL) {
  1170. bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
  1171. if ((bip != NULL) &&
  1172. xfs_buf_item_dirty(bip)) {
  1173. if (!(XFS_BUF_ISPINNED(bp))) {
  1174. XFS_BUF_ASYNC(bp);
  1175. error = xfs_bwrite(mp, bp);
  1176. } else {
  1177. xfs_buf_relse(bp);
  1178. }
  1179. } else {
  1180. xfs_buf_relse(bp);
  1181. }
  1182. }
  1183. } else {
  1184. bp = xfs_getsb(mp, 0);
  1185. /*
  1186. * If the buffer is pinned then push on the log so
  1187. * we won't get stuck waiting in the write for
  1188. * someone, maybe ourselves, to flush the log.
  1189. * Even though we just pushed the log above, we
  1190. * did not have the superblock buffer locked at
  1191. * that point so it can become pinned in between
  1192. * there and here.
  1193. */
  1194. if (XFS_BUF_ISPINNED(bp))
  1195. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  1196. if (flags & SYNC_WAIT)
  1197. XFS_BUF_UNASYNC(bp);
  1198. else
  1199. XFS_BUF_ASYNC(bp);
  1200. error = xfs_bwrite(mp, bp);
  1201. }
  1202. if (error) {
  1203. last_error = error;
  1204. }
  1205. }
  1206. /*
  1207. * If this is the periodic sync, then kick some entries out of
  1208. * the reference cache. This ensures that idle entries are
  1209. * eventually kicked out of the cache.
  1210. */
  1211. if (flags & SYNC_REFCACHE) {
  1212. if (flags & SYNC_WAIT)
  1213. xfs_refcache_purge_mp(mp);
  1214. else
  1215. xfs_refcache_purge_some(mp);
  1216. }
  1217. /*
  1218. * If asked, update the disk superblock with incore counter values if we
  1219. * are using non-persistent counters so that they don't get too far out
  1220. * of sync if we crash or get a forced shutdown. We don't want to force
  1221. * this to disk, just get a transaction into the iclogs....
  1222. */
  1223. if (flags & SYNC_SUPER)
  1224. xfs_log_sbcount(mp, 0);
  1225. /*
  1226. * Now check to see if the log needs a "dummy" transaction.
  1227. */
  1228. if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
  1229. xfs_trans_t *tp;
  1230. xfs_inode_t *ip;
  1231. /*
  1232. * Put a dummy transaction in the log to tell
  1233. * recovery that all others are OK.
  1234. */
  1235. tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
  1236. if ((error = xfs_trans_reserve(tp, 0,
  1237. XFS_ICHANGE_LOG_RES(mp),
  1238. 0, 0, 0))) {
  1239. xfs_trans_cancel(tp, 0);
  1240. return error;
  1241. }
  1242. ip = mp->m_rootip;
  1243. xfs_ilock(ip, XFS_ILOCK_EXCL);
  1244. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  1245. xfs_trans_ihold(tp, ip);
  1246. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  1247. error = xfs_trans_commit(tp, 0);
  1248. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1249. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1250. }
  1251. /*
  1252. * When shutting down, we need to insure that the AIL is pushed
  1253. * to disk or the filesystem can appear corrupt from the PROM.
  1254. */
  1255. if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
  1256. XFS_bflush(mp->m_ddev_targp);
  1257. if (mp->m_rtdev_targp) {
  1258. XFS_bflush(mp->m_rtdev_targp);
  1259. }
  1260. }
  1261. return XFS_ERROR(last_error);
  1262. }
  1263. /*
  1264. * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
  1265. */
  1266. int
  1267. xfs_vget(
  1268. xfs_mount_t *mp,
  1269. bhv_vnode_t **vpp,
  1270. xfs_fid_t *xfid)
  1271. {
  1272. xfs_inode_t *ip;
  1273. int error;
  1274. xfs_ino_t ino;
  1275. unsigned int igen;
  1276. /*
  1277. * Invalid. Since handles can be created in user space and passed in
  1278. * via gethandle(), this is not cause for a panic.
  1279. */
  1280. if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len))
  1281. return XFS_ERROR(EINVAL);
  1282. ino = xfid->fid_ino;
  1283. igen = xfid->fid_gen;
  1284. /*
  1285. * NFS can sometimes send requests for ino 0. Fail them gracefully.
  1286. */
  1287. if (ino == 0)
  1288. return XFS_ERROR(ESTALE);
  1289. error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
  1290. if (error) {
  1291. *vpp = NULL;
  1292. return error;
  1293. }
  1294. if (ip == NULL) {
  1295. *vpp = NULL;
  1296. return XFS_ERROR(EIO);
  1297. }
  1298. if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
  1299. xfs_iput_new(ip, XFS_ILOCK_SHARED);
  1300. *vpp = NULL;
  1301. return XFS_ERROR(ENOENT);
  1302. }
  1303. *vpp = XFS_ITOV(ip);
  1304. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1305. return 0;
  1306. }
  1307. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  1308. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  1309. #define MNTOPT_LOGDEV "logdev" /* log device */
  1310. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  1311. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  1312. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  1313. #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
  1314. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  1315. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  1316. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  1317. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  1318. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  1319. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  1320. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  1321. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  1322. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  1323. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  1324. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  1325. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  1326. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  1327. * unwritten extent conversion */
  1328. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  1329. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  1330. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  1331. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  1332. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  1333. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  1334. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  1335. * in stat(). */
  1336. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  1337. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  1338. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  1339. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  1340. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  1341. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  1342. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  1343. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  1344. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  1345. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  1346. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  1347. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  1348. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  1349. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  1350. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  1351. #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
  1352. #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
  1353. #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
  1354. STATIC unsigned long
  1355. suffix_strtoul(char *s, char **endp, unsigned int base)
  1356. {
  1357. int last, shift_left_factor = 0;
  1358. char *value = s;
  1359. last = strlen(value) - 1;
  1360. if (value[last] == 'K' || value[last] == 'k') {
  1361. shift_left_factor = 10;
  1362. value[last] = '\0';
  1363. }
  1364. if (value[last] == 'M' || value[last] == 'm') {
  1365. shift_left_factor = 20;
  1366. value[last] = '\0';
  1367. }
  1368. if (value[last] == 'G' || value[last] == 'g') {
  1369. shift_left_factor = 30;
  1370. value[last] = '\0';
  1371. }
  1372. return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
  1373. }
  1374. int
  1375. xfs_parseargs(
  1376. struct xfs_mount *mp,
  1377. char *options,
  1378. struct xfs_mount_args *args,
  1379. int update)
  1380. {
  1381. char *this_char, *value, *eov;
  1382. int dsunit, dswidth, vol_dsunit, vol_dswidth;
  1383. int iosize;
  1384. int ikeep = 0;
  1385. args->flags |= XFSMNT_BARRIER;
  1386. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1387. if (!options)
  1388. goto done;
  1389. iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
  1390. while ((this_char = strsep(&options, ",")) != NULL) {
  1391. if (!*this_char)
  1392. continue;
  1393. if ((value = strchr(this_char, '=')) != NULL)
  1394. *value++ = 0;
  1395. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  1396. if (!value || !*value) {
  1397. cmn_err(CE_WARN,
  1398. "XFS: %s option requires an argument",
  1399. this_char);
  1400. return EINVAL;
  1401. }
  1402. args->logbufs = simple_strtoul(value, &eov, 10);
  1403. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  1404. if (!value || !*value) {
  1405. cmn_err(CE_WARN,
  1406. "XFS: %s option requires an argument",
  1407. this_char);
  1408. return EINVAL;
  1409. }
  1410. args->logbufsize = suffix_strtoul(value, &eov, 10);
  1411. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  1412. if (!value || !*value) {
  1413. cmn_err(CE_WARN,
  1414. "XFS: %s option requires an argument",
  1415. this_char);
  1416. return EINVAL;
  1417. }
  1418. strncpy(args->logname, value, MAXNAMELEN);
  1419. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  1420. if (!value || !*value) {
  1421. cmn_err(CE_WARN,
  1422. "XFS: %s option requires an argument",
  1423. this_char);
  1424. return EINVAL;
  1425. }
  1426. strncpy(args->mtpt, value, MAXNAMELEN);
  1427. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  1428. if (!value || !*value) {
  1429. cmn_err(CE_WARN,
  1430. "XFS: %s option requires an argument",
  1431. this_char);
  1432. return EINVAL;
  1433. }
  1434. strncpy(args->rtname, value, MAXNAMELEN);
  1435. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  1436. if (!value || !*value) {
  1437. cmn_err(CE_WARN,
  1438. "XFS: %s option requires an argument",
  1439. this_char);
  1440. return EINVAL;
  1441. }
  1442. iosize = simple_strtoul(value, &eov, 10);
  1443. args->flags |= XFSMNT_IOSIZE;
  1444. args->iosizelog = (uint8_t) iosize;
  1445. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  1446. if (!value || !*value) {
  1447. cmn_err(CE_WARN,
  1448. "XFS: %s option requires an argument",
  1449. this_char);
  1450. return EINVAL;
  1451. }
  1452. iosize = suffix_strtoul(value, &eov, 10);
  1453. args->flags |= XFSMNT_IOSIZE;
  1454. args->iosizelog = ffs(iosize) - 1;
  1455. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  1456. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  1457. mp->m_flags |= XFS_MOUNT_GRPID;
  1458. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  1459. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  1460. mp->m_flags &= ~XFS_MOUNT_GRPID;
  1461. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  1462. args->flags |= XFSMNT_WSYNC;
  1463. } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
  1464. args->flags |= XFSMNT_OSYNCISOSYNC;
  1465. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  1466. args->flags |= XFSMNT_NORECOVERY;
  1467. } else if (!strcmp(this_char, MNTOPT_INO64)) {
  1468. args->flags |= XFSMNT_INO64;
  1469. #if !XFS_BIG_INUMS
  1470. cmn_err(CE_WARN,
  1471. "XFS: %s option not allowed on this system",
  1472. this_char);
  1473. return EINVAL;
  1474. #endif
  1475. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  1476. args->flags |= XFSMNT_NOALIGN;
  1477. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  1478. args->flags |= XFSMNT_SWALLOC;
  1479. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  1480. if (!value || !*value) {
  1481. cmn_err(CE_WARN,
  1482. "XFS: %s option requires an argument",
  1483. this_char);
  1484. return EINVAL;
  1485. }
  1486. dsunit = simple_strtoul(value, &eov, 10);
  1487. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  1488. if (!value || !*value) {
  1489. cmn_err(CE_WARN,
  1490. "XFS: %s option requires an argument",
  1491. this_char);
  1492. return EINVAL;
  1493. }
  1494. dswidth = simple_strtoul(value, &eov, 10);
  1495. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  1496. args->flags &= ~XFSMNT_32BITINODES;
  1497. #if !XFS_BIG_INUMS
  1498. cmn_err(CE_WARN,
  1499. "XFS: %s option not allowed on this system",
  1500. this_char);
  1501. return EINVAL;
  1502. #endif
  1503. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  1504. args->flags |= XFSMNT_NOUUID;
  1505. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  1506. args->flags |= XFSMNT_BARRIER;
  1507. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  1508. args->flags &= ~XFSMNT_BARRIER;
  1509. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  1510. ikeep = 1;
  1511. args->flags &= ~XFSMNT_IDELETE;
  1512. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  1513. args->flags |= XFSMNT_IDELETE;
  1514. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  1515. args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
  1516. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  1517. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1518. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  1519. args->flags |= XFSMNT_ATTR2;
  1520. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  1521. args->flags &= ~XFSMNT_ATTR2;
  1522. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  1523. args->flags2 |= XFSMNT2_FILESTREAMS;
  1524. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  1525. args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
  1526. args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
  1527. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  1528. !strcmp(this_char, MNTOPT_UQUOTA) ||
  1529. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  1530. args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
  1531. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  1532. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  1533. args->flags |= XFSMNT_UQUOTA;
  1534. args->flags &= ~XFSMNT_UQUOTAENF;
  1535. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  1536. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  1537. args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
  1538. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  1539. args->flags |= XFSMNT_PQUOTA;
  1540. args->flags &= ~XFSMNT_PQUOTAENF;
  1541. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  1542. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  1543. args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
  1544. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  1545. args->flags |= XFSMNT_GQUOTA;
  1546. args->flags &= ~XFSMNT_GQUOTAENF;
  1547. } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
  1548. args->flags |= XFSMNT_DMAPI;
  1549. } else if (!strcmp(this_char, MNTOPT_XDSM)) {
  1550. args->flags |= XFSMNT_DMAPI;
  1551. } else if (!strcmp(this_char, MNTOPT_DMI)) {
  1552. args->flags |= XFSMNT_DMAPI;
  1553. } else if (!strcmp(this_char, "ihashsize")) {
  1554. cmn_err(CE_WARN,
  1555. "XFS: ihashsize no longer used, option is deprecated.");
  1556. } else if (!strcmp(this_char, "osyncisdsync")) {
  1557. /* no-op, this is now the default */
  1558. cmn_err(CE_WARN,
  1559. "XFS: osyncisdsync is now the default, option is deprecated.");
  1560. } else if (!strcmp(this_char, "irixsgid")) {
  1561. cmn_err(CE_WARN,
  1562. "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
  1563. } else {
  1564. cmn_err(CE_WARN,
  1565. "XFS: unknown mount option [%s].", this_char);
  1566. return EINVAL;
  1567. }
  1568. }
  1569. if (args->flags & XFSMNT_NORECOVERY) {
  1570. if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
  1571. cmn_err(CE_WARN,
  1572. "XFS: no-recovery mounts must be read-only.");
  1573. return EINVAL;
  1574. }
  1575. }
  1576. if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
  1577. cmn_err(CE_WARN,
  1578. "XFS: sunit and swidth options incompatible with the noalign option");
  1579. return EINVAL;
  1580. }
  1581. if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
  1582. cmn_err(CE_WARN,
  1583. "XFS: cannot mount with both project and group quota");
  1584. return EINVAL;
  1585. }
  1586. if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
  1587. printk("XFS: %s option needs the mount point option as well\n",
  1588. MNTOPT_DMAPI);
  1589. return EINVAL;
  1590. }
  1591. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  1592. cmn_err(CE_WARN,
  1593. "XFS: sunit and swidth must be specified together");
  1594. return EINVAL;
  1595. }
  1596. if (dsunit && (dswidth % dsunit != 0)) {
  1597. cmn_err(CE_WARN,
  1598. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  1599. dswidth, dsunit);
  1600. return EINVAL;
  1601. }
  1602. /*
  1603. * Applications using DMI filesystems often expect the
  1604. * inode generation number to be monotonically increasing.
  1605. * If we delete inode chunks we break this assumption, so
  1606. * keep unused inode chunks on disk for DMI filesystems
  1607. * until we come up with a better solution.
  1608. * Note that if "ikeep" or "noikeep" mount options are
  1609. * supplied, then they are honored.
  1610. */
  1611. if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
  1612. args->flags |= XFSMNT_IDELETE;
  1613. if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  1614. if (dsunit) {
  1615. args->sunit = dsunit;
  1616. args->flags |= XFSMNT_RETERR;
  1617. } else {
  1618. args->sunit = vol_dsunit;
  1619. }
  1620. dswidth ? (args->swidth = dswidth) :
  1621. (args->swidth = vol_dswidth);
  1622. } else {
  1623. args->sunit = args->swidth = 0;
  1624. }
  1625. done:
  1626. if (args->flags & XFSMNT_32BITINODES)
  1627. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  1628. if (args->flags2)
  1629. args->flags |= XFSMNT_FLAGS2;
  1630. return 0;
  1631. }
  1632. int
  1633. xfs_showargs(
  1634. struct xfs_mount *mp,
  1635. struct seq_file *m)
  1636. {
  1637. static struct proc_xfs_info {
  1638. int flag;
  1639. char *str;
  1640. } xfs_info[] = {
  1641. /* the few simple ones we can get from the mount struct */
  1642. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  1643. { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
  1644. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  1645. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  1646. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  1647. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  1648. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  1649. { 0, NULL }
  1650. };
  1651. struct proc_xfs_info *xfs_infop;
  1652. for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
  1653. if (mp->m_flags & xfs_infop->flag)
  1654. seq_puts(m, xfs_infop->str);
  1655. }
  1656. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  1657. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  1658. (int)(1 << mp->m_writeio_log) >> 10);
  1659. if (mp->m_logbufs > 0)
  1660. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  1661. if (mp->m_logbsize > 0)
  1662. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  1663. if (mp->m_logname)
  1664. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  1665. if (mp->m_rtname)
  1666. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  1667. if (mp->m_dalign > 0)
  1668. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  1669. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  1670. if (mp->m_swidth > 0)
  1671. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  1672. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  1673. if (!(mp->m_flags & XFS_MOUNT_IDELETE))
  1674. seq_printf(m, "," MNTOPT_IKEEP);
  1675. if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
  1676. seq_printf(m, "," MNTOPT_LARGEIO);
  1677. if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS))
  1678. seq_printf(m, "," MNTOPT_64BITINODE);
  1679. if (mp->m_flags & XFS_MOUNT_GRPID)
  1680. seq_printf(m, "," MNTOPT_GRPID);
  1681. if (mp->m_qflags & XFS_UQUOTA_ACCT) {
  1682. if (mp->m_qflags & XFS_UQUOTA_ENFD)
  1683. seq_puts(m, "," MNTOPT_USRQUOTA);
  1684. else
  1685. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  1686. }
  1687. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  1688. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1689. seq_puts(m, "," MNTOPT_PRJQUOTA);
  1690. else
  1691. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  1692. }
  1693. if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  1694. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1695. seq_puts(m, "," MNTOPT_GRPQUOTA);
  1696. else
  1697. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  1698. }
  1699. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  1700. seq_puts(m, "," MNTOPT_NOQUOTA);
  1701. if (mp->m_flags & XFS_MOUNT_DMAPI)
  1702. seq_puts(m, "," MNTOPT_DMAPI);
  1703. return 0;
  1704. }
  1705. /*
  1706. * Second stage of a freeze. The data is already frozen so we only
  1707. * need to take care of themetadata. Once that's done write a dummy
  1708. * record to dirty the log in case of a crash while frozen.
  1709. */
  1710. void
  1711. xfs_freeze(
  1712. xfs_mount_t *mp)
  1713. {
  1714. xfs_attr_quiesce(mp);
  1715. xfs_fs_log_dummy(mp);
  1716. }