xfs_vfsops.c 50 KB

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