xfs_vfsops.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971
  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 lock_t xfs_dabuf_global_lock;
  69. spinlock_init(&xfs_dabuf_global_lock, "xfsda");
  70. #endif
  71. /*
  72. * Initialize all of the zone allocators we use.
  73. */
  74. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  75. "xfs_bmap_free_item");
  76. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  77. "xfs_btree_cur");
  78. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  79. xfs_da_state_zone =
  80. kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
  81. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  82. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  83. xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
  84. xfs_mru_cache_init();
  85. xfs_filestream_init();
  86. /*
  87. * The size of the zone allocated buf log item is the maximum
  88. * size possible under XFS. This wastes a little bit of memory,
  89. * but it is much faster.
  90. */
  91. xfs_buf_item_zone =
  92. kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  93. (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
  94. NBWORD) * sizeof(int))),
  95. "xfs_buf_item");
  96. xfs_efd_zone =
  97. kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  98. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  99. sizeof(xfs_extent_t))),
  100. "xfs_efd_item");
  101. xfs_efi_zone =
  102. kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  103. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  104. sizeof(xfs_extent_t))),
  105. "xfs_efi_item");
  106. /*
  107. * These zones warrant special memory allocator hints
  108. */
  109. xfs_inode_zone =
  110. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  111. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
  112. KM_ZONE_SPREAD, NULL);
  113. xfs_ili_zone =
  114. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  115. KM_ZONE_SPREAD, NULL);
  116. xfs_icluster_zone =
  117. kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
  118. KM_ZONE_SPREAD, NULL);
  119. /*
  120. * Allocate global trace buffers.
  121. */
  122. #ifdef XFS_ALLOC_TRACE
  123. xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
  124. #endif
  125. #ifdef XFS_BMAP_TRACE
  126. xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
  127. #endif
  128. #ifdef XFS_BMBT_TRACE
  129. xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
  130. #endif
  131. #ifdef XFS_ATTR_TRACE
  132. xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
  133. #endif
  134. #ifdef XFS_DIR2_TRACE
  135. xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
  136. #endif
  137. xfs_dir_startup();
  138. #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
  139. xfs_error_test_init();
  140. #endif /* DEBUG || INDUCE_IO_ERROR */
  141. xfs_init_procfs();
  142. xfs_sysctl_register();
  143. return 0;
  144. }
  145. void
  146. xfs_cleanup(void)
  147. {
  148. extern kmem_zone_t *xfs_bmap_free_item_zone;
  149. extern kmem_zone_t *xfs_btree_cur_zone;
  150. extern kmem_zone_t *xfs_inode_zone;
  151. extern kmem_zone_t *xfs_trans_zone;
  152. extern kmem_zone_t *xfs_da_state_zone;
  153. extern kmem_zone_t *xfs_dabuf_zone;
  154. extern kmem_zone_t *xfs_efd_zone;
  155. extern kmem_zone_t *xfs_efi_zone;
  156. extern kmem_zone_t *xfs_buf_item_zone;
  157. extern kmem_zone_t *xfs_icluster_zone;
  158. xfs_cleanup_procfs();
  159. xfs_sysctl_unregister();
  160. xfs_refcache_destroy();
  161. xfs_filestream_uninit();
  162. xfs_mru_cache_uninit();
  163. xfs_acl_zone_destroy(xfs_acl_zone);
  164. #ifdef XFS_DIR2_TRACE
  165. ktrace_free(xfs_dir2_trace_buf);
  166. #endif
  167. #ifdef XFS_ATTR_TRACE
  168. ktrace_free(xfs_attr_trace_buf);
  169. #endif
  170. #ifdef XFS_BMBT_TRACE
  171. ktrace_free(xfs_bmbt_trace_buf);
  172. #endif
  173. #ifdef XFS_BMAP_TRACE
  174. ktrace_free(xfs_bmap_trace_buf);
  175. #endif
  176. #ifdef XFS_ALLOC_TRACE
  177. ktrace_free(xfs_alloc_trace_buf);
  178. #endif
  179. kmem_zone_destroy(xfs_bmap_free_item_zone);
  180. kmem_zone_destroy(xfs_btree_cur_zone);
  181. kmem_zone_destroy(xfs_inode_zone);
  182. kmem_zone_destroy(xfs_trans_zone);
  183. kmem_zone_destroy(xfs_da_state_zone);
  184. kmem_zone_destroy(xfs_dabuf_zone);
  185. kmem_zone_destroy(xfs_buf_item_zone);
  186. kmem_zone_destroy(xfs_efd_zone);
  187. kmem_zone_destroy(xfs_efi_zone);
  188. kmem_zone_destroy(xfs_ifork_zone);
  189. kmem_zone_destroy(xfs_ili_zone);
  190. kmem_zone_destroy(xfs_icluster_zone);
  191. }
  192. /*
  193. * xfs_start_flags
  194. *
  195. * This function fills in xfs_mount_t fields based on mount args.
  196. * Note: the superblock has _not_ yet been read in.
  197. */
  198. STATIC int
  199. xfs_start_flags(
  200. struct 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_statvfs
  754. *
  755. * Fill in the statvfs structure for the given file system. We use
  756. * the superblock lock in the mount structure to ensure a consistent
  757. * snapshot of the counters returned.
  758. */
  759. int
  760. xfs_statvfs(
  761. xfs_mount_t *mp,
  762. bhv_statvfs_t *statp,
  763. bhv_vnode_t *vp)
  764. {
  765. __uint64_t fakeinos;
  766. xfs_extlen_t lsize;
  767. xfs_sb_t *sbp;
  768. unsigned long s;
  769. sbp = &(mp->m_sb);
  770. statp->f_type = XFS_SB_MAGIC;
  771. xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
  772. s = XFS_SB_LOCK(mp);
  773. statp->f_bsize = sbp->sb_blocksize;
  774. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  775. statp->f_blocks = sbp->sb_dblocks - lsize;
  776. statp->f_bfree = statp->f_bavail =
  777. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  778. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  779. #if XFS_BIG_INUMS
  780. fakeinos += mp->m_inoadd;
  781. #endif
  782. statp->f_files =
  783. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  784. if (mp->m_maxicount)
  785. #if XFS_BIG_INUMS
  786. if (!mp->m_inoadd)
  787. #endif
  788. statp->f_files = min_t(typeof(statp->f_files),
  789. statp->f_files,
  790. mp->m_maxicount);
  791. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  792. XFS_SB_UNLOCK(mp, s);
  793. xfs_statvfs_fsid(statp, mp);
  794. statp->f_namelen = MAXNAMELEN - 1;
  795. if (vp)
  796. XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
  797. return 0;
  798. }
  799. /*
  800. * xfs_sync flushes any pending I/O to file system vfsp.
  801. *
  802. * This routine is called by vfs_sync() to make sure that things make it
  803. * out to disk eventually, on sync() system calls to flush out everything,
  804. * and when the file system is unmounted. For the vfs_sync() case, all
  805. * we really need to do is sync out the log to make all of our meta-data
  806. * updates permanent (except for timestamps). For calls from pflushd(),
  807. * dirty pages are kept moving by calling pdflush() on the inodes
  808. * containing them. We also flush the inodes that we can lock without
  809. * sleeping and the superblock if we can lock it without sleeping from
  810. * vfs_sync() so that items at the tail of the log are always moving out.
  811. *
  812. * Flags:
  813. * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
  814. * to sleep if we can help it. All we really need
  815. * to do is ensure that the log is synced at least
  816. * periodically. We also push the inodes and
  817. * superblock if we can lock them without sleeping
  818. * and they are not pinned.
  819. * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
  820. * set, then we really want to lock each inode and flush
  821. * it.
  822. * SYNC_WAIT - All the flushes that take place in this call should
  823. * be synchronous.
  824. * SYNC_DELWRI - This tells us to push dirty pages associated with
  825. * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
  826. * determine if they should be flushed sync, async, or
  827. * delwri.
  828. * SYNC_CLOSE - This flag is passed when the system is being
  829. * unmounted. We should sync and invalidate everything.
  830. * SYNC_FSDATA - This indicates that the caller would like to make
  831. * sure the superblock is safe on disk. We can ensure
  832. * this by simply making sure the log gets flushed
  833. * if SYNC_BDFLUSH is set, and by actually writing it
  834. * out otherwise.
  835. * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
  836. * before we return (including direct I/O). Forms the drain
  837. * side of the write barrier needed to safely quiesce the
  838. * filesystem.
  839. *
  840. */
  841. int
  842. xfs_sync(
  843. xfs_mount_t *mp,
  844. int flags)
  845. {
  846. int error;
  847. /*
  848. * Get the Quota Manager to flush the dquots.
  849. *
  850. * If XFS quota support is not enabled or this filesystem
  851. * instance does not use quotas XFS_QM_DQSYNC will always
  852. * return zero.
  853. */
  854. error = XFS_QM_DQSYNC(mp, flags);
  855. if (error) {
  856. /*
  857. * If we got an IO error, we will be shutting down.
  858. * So, there's nothing more for us to do here.
  859. */
  860. ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
  861. if (XFS_FORCED_SHUTDOWN(mp))
  862. return XFS_ERROR(error);
  863. }
  864. if (flags & SYNC_IOWAIT)
  865. xfs_filestream_flush(mp);
  866. return xfs_syncsub(mp, flags, NULL);
  867. }
  868. /*
  869. * xfs sync routine for internal use
  870. *
  871. * This routine supports all of the flags defined for the generic vfs_sync
  872. * interface as explained above under xfs_sync.
  873. *
  874. */
  875. int
  876. xfs_sync_inodes(
  877. xfs_mount_t *mp,
  878. int flags,
  879. int *bypassed)
  880. {
  881. xfs_inode_t *ip = NULL;
  882. bhv_vnode_t *vp = NULL;
  883. int error;
  884. int last_error;
  885. uint64_t fflag;
  886. uint lock_flags;
  887. uint base_lock_flags;
  888. boolean_t mount_locked;
  889. boolean_t vnode_refed;
  890. int preempt;
  891. xfs_iptr_t *ipointer;
  892. #ifdef DEBUG
  893. boolean_t ipointer_in = B_FALSE;
  894. #define IPOINTER_SET ipointer_in = B_TRUE
  895. #define IPOINTER_CLR ipointer_in = B_FALSE
  896. #else
  897. #define IPOINTER_SET
  898. #define IPOINTER_CLR
  899. #endif
  900. /* Insert a marker record into the inode list after inode ip. The list
  901. * must be locked when this is called. After the call the list will no
  902. * longer be locked.
  903. */
  904. #define IPOINTER_INSERT(ip, mp) { \
  905. ASSERT(ipointer_in == B_FALSE); \
  906. ipointer->ip_mnext = ip->i_mnext; \
  907. ipointer->ip_mprev = ip; \
  908. ip->i_mnext = (xfs_inode_t *)ipointer; \
  909. ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
  910. preempt = 0; \
  911. XFS_MOUNT_IUNLOCK(mp); \
  912. mount_locked = B_FALSE; \
  913. IPOINTER_SET; \
  914. }
  915. /* Remove the marker from the inode list. If the marker was the only item
  916. * in the list then there are no remaining inodes and we should zero out
  917. * the whole list. If we are the current head of the list then move the head
  918. * past us.
  919. */
  920. #define IPOINTER_REMOVE(ip, mp) { \
  921. ASSERT(ipointer_in == B_TRUE); \
  922. if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
  923. ip = ipointer->ip_mnext; \
  924. ip->i_mprev = ipointer->ip_mprev; \
  925. ipointer->ip_mprev->i_mnext = ip; \
  926. if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
  927. mp->m_inodes = ip; \
  928. } \
  929. } else { \
  930. ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
  931. mp->m_inodes = NULL; \
  932. ip = NULL; \
  933. } \
  934. IPOINTER_CLR; \
  935. }
  936. #define XFS_PREEMPT_MASK 0x7f
  937. ASSERT(!(flags & SYNC_BDFLUSH));
  938. if (bypassed)
  939. *bypassed = 0;
  940. if (mp->m_flags & XFS_MOUNT_RDONLY)
  941. return 0;
  942. error = 0;
  943. last_error = 0;
  944. preempt = 0;
  945. /* Allocate a reference marker */
  946. ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
  947. fflag = XFS_B_ASYNC; /* default is don't wait */
  948. if (flags & SYNC_DELWRI)
  949. fflag = XFS_B_DELWRI;
  950. if (flags & SYNC_WAIT)
  951. fflag = 0; /* synchronous overrides all */
  952. base_lock_flags = XFS_ILOCK_SHARED;
  953. if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
  954. /*
  955. * We need the I/O lock if we're going to call any of
  956. * the flush/inval routines.
  957. */
  958. base_lock_flags |= XFS_IOLOCK_SHARED;
  959. }
  960. XFS_MOUNT_ILOCK(mp);
  961. ip = mp->m_inodes;
  962. mount_locked = B_TRUE;
  963. vnode_refed = B_FALSE;
  964. IPOINTER_CLR;
  965. do {
  966. ASSERT(ipointer_in == B_FALSE);
  967. ASSERT(vnode_refed == B_FALSE);
  968. lock_flags = base_lock_flags;
  969. /*
  970. * There were no inodes in the list, just break out
  971. * of the loop.
  972. */
  973. if (ip == NULL) {
  974. break;
  975. }
  976. /*
  977. * We found another sync thread marker - skip it
  978. */
  979. if (ip->i_mount == NULL) {
  980. ip = ip->i_mnext;
  981. continue;
  982. }
  983. vp = XFS_ITOV_NULL(ip);
  984. /*
  985. * If the vnode is gone then this is being torn down,
  986. * call reclaim if it is flushed, else let regular flush
  987. * code deal with it later in the loop.
  988. */
  989. if (vp == NULL) {
  990. /* Skip ones already in reclaim */
  991. if (ip->i_flags & XFS_IRECLAIM) {
  992. ip = ip->i_mnext;
  993. continue;
  994. }
  995. if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
  996. ip = ip->i_mnext;
  997. } else if ((xfs_ipincount(ip) == 0) &&
  998. xfs_iflock_nowait(ip)) {
  999. IPOINTER_INSERT(ip, mp);
  1000. xfs_finish_reclaim(ip, 1,
  1001. XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  1002. XFS_MOUNT_ILOCK(mp);
  1003. mount_locked = B_TRUE;
  1004. IPOINTER_REMOVE(ip, mp);
  1005. } else {
  1006. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1007. ip = ip->i_mnext;
  1008. }
  1009. continue;
  1010. }
  1011. if (VN_BAD(vp)) {
  1012. ip = ip->i_mnext;
  1013. continue;
  1014. }
  1015. if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
  1016. XFS_MOUNT_IUNLOCK(mp);
  1017. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1018. return 0;
  1019. }
  1020. /*
  1021. * Try to lock without sleeping. We're out of order with
  1022. * the inode list lock here, so if we fail we need to drop
  1023. * the mount lock and try again. If we're called from
  1024. * bdflush() here, then don't bother.
  1025. *
  1026. * The inode lock here actually coordinates with the
  1027. * almost spurious inode lock in xfs_ireclaim() to prevent
  1028. * the vnode we handle here without a reference from
  1029. * being freed while we reference it. If we lock the inode
  1030. * while it's on the mount list here, then the spurious inode
  1031. * lock in xfs_ireclaim() after the inode is pulled from
  1032. * the mount list will sleep until we release it here.
  1033. * This keeps the vnode from being freed while we reference
  1034. * it.
  1035. */
  1036. if (xfs_ilock_nowait(ip, lock_flags) == 0) {
  1037. if (vp == NULL) {
  1038. ip = ip->i_mnext;
  1039. continue;
  1040. }
  1041. vp = vn_grab(vp);
  1042. if (vp == NULL) {
  1043. ip = ip->i_mnext;
  1044. continue;
  1045. }
  1046. IPOINTER_INSERT(ip, mp);
  1047. xfs_ilock(ip, lock_flags);
  1048. ASSERT(vp == XFS_ITOV(ip));
  1049. ASSERT(ip->i_mount == mp);
  1050. vnode_refed = B_TRUE;
  1051. }
  1052. /* From here on in the loop we may have a marker record
  1053. * in the inode list.
  1054. */
  1055. /*
  1056. * If we have to flush data or wait for I/O completion
  1057. * we need to drop the ilock that we currently hold.
  1058. * If we need to drop the lock, insert a marker if we
  1059. * have not already done so.
  1060. */
  1061. if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
  1062. ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
  1063. if (mount_locked) {
  1064. IPOINTER_INSERT(ip, mp);
  1065. }
  1066. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1067. if (flags & SYNC_CLOSE) {
  1068. /* Shutdown case. Flush and invalidate. */
  1069. if (XFS_FORCED_SHUTDOWN(mp))
  1070. xfs_tosspages(ip, 0, -1,
  1071. FI_REMAPF);
  1072. else
  1073. error = xfs_flushinval_pages(ip,
  1074. 0, -1, FI_REMAPF);
  1075. } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
  1076. error = xfs_flush_pages(ip, 0,
  1077. -1, fflag, FI_NONE);
  1078. }
  1079. /*
  1080. * When freezing, we need to wait ensure all I/O (including direct
  1081. * I/O) is complete to ensure no further data modification can take
  1082. * place after this point
  1083. */
  1084. if (flags & SYNC_IOWAIT)
  1085. vn_iowait(ip);
  1086. xfs_ilock(ip, XFS_ILOCK_SHARED);
  1087. }
  1088. if ((flags & SYNC_ATTR) &&
  1089. (ip->i_update_core ||
  1090. (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) {
  1091. if (mount_locked)
  1092. IPOINTER_INSERT(ip, mp);
  1093. if (flags & SYNC_WAIT) {
  1094. xfs_iflock(ip);
  1095. error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
  1096. /*
  1097. * If we can't acquire the flush lock, then the inode
  1098. * is already being flushed so don't bother waiting.
  1099. *
  1100. * If we can lock it then do a delwri flush so we can
  1101. * combine multiple inode flushes in each disk write.
  1102. */
  1103. } else if (xfs_iflock_nowait(ip)) {
  1104. error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
  1105. } else if (bypassed) {
  1106. (*bypassed)++;
  1107. }
  1108. }
  1109. if (lock_flags != 0) {
  1110. xfs_iunlock(ip, lock_flags);
  1111. }
  1112. if (vnode_refed) {
  1113. /*
  1114. * If we had to take a reference on the vnode
  1115. * above, then wait until after we've unlocked
  1116. * the inode to release the reference. This is
  1117. * because we can be already holding the inode
  1118. * lock when VN_RELE() calls xfs_inactive().
  1119. *
  1120. * Make sure to drop the mount lock before calling
  1121. * VN_RELE() so that we don't trip over ourselves if
  1122. * we have to go for the mount lock again in the
  1123. * inactive code.
  1124. */
  1125. if (mount_locked) {
  1126. IPOINTER_INSERT(ip, mp);
  1127. }
  1128. VN_RELE(vp);
  1129. vnode_refed = B_FALSE;
  1130. }
  1131. if (error) {
  1132. last_error = error;
  1133. }
  1134. /*
  1135. * bail out if the filesystem is corrupted.
  1136. */
  1137. if (error == EFSCORRUPTED) {
  1138. if (!mount_locked) {
  1139. XFS_MOUNT_ILOCK(mp);
  1140. IPOINTER_REMOVE(ip, mp);
  1141. }
  1142. XFS_MOUNT_IUNLOCK(mp);
  1143. ASSERT(ipointer_in == B_FALSE);
  1144. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1145. return XFS_ERROR(error);
  1146. }
  1147. /* Let other threads have a chance at the mount lock
  1148. * if we have looped many times without dropping the
  1149. * lock.
  1150. */
  1151. if ((++preempt & XFS_PREEMPT_MASK) == 0) {
  1152. if (mount_locked) {
  1153. IPOINTER_INSERT(ip, mp);
  1154. }
  1155. }
  1156. if (mount_locked == B_FALSE) {
  1157. XFS_MOUNT_ILOCK(mp);
  1158. mount_locked = B_TRUE;
  1159. IPOINTER_REMOVE(ip, mp);
  1160. continue;
  1161. }
  1162. ASSERT(ipointer_in == B_FALSE);
  1163. ip = ip->i_mnext;
  1164. } while (ip != mp->m_inodes);
  1165. XFS_MOUNT_IUNLOCK(mp);
  1166. ASSERT(ipointer_in == B_FALSE);
  1167. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1168. return XFS_ERROR(last_error);
  1169. }
  1170. /*
  1171. * xfs sync routine for internal use
  1172. *
  1173. * This routine supports all of the flags defined for the generic vfs_sync
  1174. * interface as explained above under xfs_sync.
  1175. *
  1176. */
  1177. int
  1178. xfs_syncsub(
  1179. xfs_mount_t *mp,
  1180. int flags,
  1181. int *bypassed)
  1182. {
  1183. int error = 0;
  1184. int last_error = 0;
  1185. uint log_flags = XFS_LOG_FORCE;
  1186. xfs_buf_t *bp;
  1187. xfs_buf_log_item_t *bip;
  1188. /*
  1189. * Sync out the log. This ensures that the log is periodically
  1190. * flushed even if there is not enough activity to fill it up.
  1191. */
  1192. if (flags & SYNC_WAIT)
  1193. log_flags |= XFS_LOG_SYNC;
  1194. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1195. if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
  1196. if (flags & SYNC_BDFLUSH)
  1197. xfs_finish_reclaim_all(mp, 1);
  1198. else
  1199. error = xfs_sync_inodes(mp, flags, bypassed);
  1200. }
  1201. /*
  1202. * Flushing out dirty data above probably generated more
  1203. * log activity, so if this isn't vfs_sync() then flush
  1204. * the log again.
  1205. */
  1206. if (flags & SYNC_DELWRI) {
  1207. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1208. }
  1209. if (flags & SYNC_FSDATA) {
  1210. /*
  1211. * If this is vfs_sync() then only sync the superblock
  1212. * if we can lock it without sleeping and it is not pinned.
  1213. */
  1214. if (flags & SYNC_BDFLUSH) {
  1215. bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
  1216. if (bp != NULL) {
  1217. bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
  1218. if ((bip != NULL) &&
  1219. xfs_buf_item_dirty(bip)) {
  1220. if (!(XFS_BUF_ISPINNED(bp))) {
  1221. XFS_BUF_ASYNC(bp);
  1222. error = xfs_bwrite(mp, bp);
  1223. } else {
  1224. xfs_buf_relse(bp);
  1225. }
  1226. } else {
  1227. xfs_buf_relse(bp);
  1228. }
  1229. }
  1230. } else {
  1231. bp = xfs_getsb(mp, 0);
  1232. /*
  1233. * If the buffer is pinned then push on the log so
  1234. * we won't get stuck waiting in the write for
  1235. * someone, maybe ourselves, to flush the log.
  1236. * Even though we just pushed the log above, we
  1237. * did not have the superblock buffer locked at
  1238. * that point so it can become pinned in between
  1239. * there and here.
  1240. */
  1241. if (XFS_BUF_ISPINNED(bp))
  1242. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  1243. if (flags & SYNC_WAIT)
  1244. XFS_BUF_UNASYNC(bp);
  1245. else
  1246. XFS_BUF_ASYNC(bp);
  1247. error = xfs_bwrite(mp, bp);
  1248. }
  1249. if (error) {
  1250. last_error = error;
  1251. }
  1252. }
  1253. /*
  1254. * If this is the periodic sync, then kick some entries out of
  1255. * the reference cache. This ensures that idle entries are
  1256. * eventually kicked out of the cache.
  1257. */
  1258. if (flags & SYNC_REFCACHE) {
  1259. if (flags & SYNC_WAIT)
  1260. xfs_refcache_purge_mp(mp);
  1261. else
  1262. xfs_refcache_purge_some(mp);
  1263. }
  1264. /*
  1265. * If asked, update the disk superblock with incore counter values if we
  1266. * are using non-persistent counters so that they don't get too far out
  1267. * of sync if we crash or get a forced shutdown. We don't want to force
  1268. * this to disk, just get a transaction into the iclogs....
  1269. */
  1270. if (flags & SYNC_SUPER)
  1271. xfs_log_sbcount(mp, 0);
  1272. /*
  1273. * Now check to see if the log needs a "dummy" transaction.
  1274. */
  1275. if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
  1276. xfs_trans_t *tp;
  1277. xfs_inode_t *ip;
  1278. /*
  1279. * Put a dummy transaction in the log to tell
  1280. * recovery that all others are OK.
  1281. */
  1282. tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
  1283. if ((error = xfs_trans_reserve(tp, 0,
  1284. XFS_ICHANGE_LOG_RES(mp),
  1285. 0, 0, 0))) {
  1286. xfs_trans_cancel(tp, 0);
  1287. return error;
  1288. }
  1289. ip = mp->m_rootip;
  1290. xfs_ilock(ip, XFS_ILOCK_EXCL);
  1291. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  1292. xfs_trans_ihold(tp, ip);
  1293. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  1294. error = xfs_trans_commit(tp, 0);
  1295. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1296. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1297. }
  1298. /*
  1299. * When shutting down, we need to insure that the AIL is pushed
  1300. * to disk or the filesystem can appear corrupt from the PROM.
  1301. */
  1302. if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
  1303. XFS_bflush(mp->m_ddev_targp);
  1304. if (mp->m_rtdev_targp) {
  1305. XFS_bflush(mp->m_rtdev_targp);
  1306. }
  1307. }
  1308. return XFS_ERROR(last_error);
  1309. }
  1310. /*
  1311. * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
  1312. */
  1313. int
  1314. xfs_vget(
  1315. xfs_mount_t *mp,
  1316. bhv_vnode_t **vpp,
  1317. xfs_fid_t *xfid)
  1318. {
  1319. xfs_inode_t *ip;
  1320. int error;
  1321. xfs_ino_t ino;
  1322. unsigned int igen;
  1323. /*
  1324. * Invalid. Since handles can be created in user space and passed in
  1325. * via gethandle(), this is not cause for a panic.
  1326. */
  1327. if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len))
  1328. return XFS_ERROR(EINVAL);
  1329. ino = xfid->fid_ino;
  1330. igen = xfid->fid_gen;
  1331. /*
  1332. * NFS can sometimes send requests for ino 0. Fail them gracefully.
  1333. */
  1334. if (ino == 0)
  1335. return XFS_ERROR(ESTALE);
  1336. error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
  1337. if (error) {
  1338. *vpp = NULL;
  1339. return error;
  1340. }
  1341. if (ip == NULL) {
  1342. *vpp = NULL;
  1343. return XFS_ERROR(EIO);
  1344. }
  1345. if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
  1346. xfs_iput_new(ip, XFS_ILOCK_SHARED);
  1347. *vpp = NULL;
  1348. return XFS_ERROR(ENOENT);
  1349. }
  1350. *vpp = XFS_ITOV(ip);
  1351. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1352. return 0;
  1353. }
  1354. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  1355. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  1356. #define MNTOPT_LOGDEV "logdev" /* log device */
  1357. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  1358. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  1359. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  1360. #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
  1361. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  1362. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  1363. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  1364. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  1365. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  1366. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  1367. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  1368. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  1369. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  1370. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  1371. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  1372. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  1373. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  1374. * unwritten extent conversion */
  1375. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  1376. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  1377. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  1378. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  1379. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  1380. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  1381. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  1382. * in stat(). */
  1383. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  1384. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  1385. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  1386. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  1387. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  1388. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  1389. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  1390. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  1391. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  1392. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  1393. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  1394. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  1395. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  1396. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  1397. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  1398. #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
  1399. #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
  1400. #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
  1401. STATIC unsigned long
  1402. suffix_strtoul(char *s, char **endp, unsigned int base)
  1403. {
  1404. int last, shift_left_factor = 0;
  1405. char *value = s;
  1406. last = strlen(value) - 1;
  1407. if (value[last] == 'K' || value[last] == 'k') {
  1408. shift_left_factor = 10;
  1409. value[last] = '\0';
  1410. }
  1411. if (value[last] == 'M' || value[last] == 'm') {
  1412. shift_left_factor = 20;
  1413. value[last] = '\0';
  1414. }
  1415. if (value[last] == 'G' || value[last] == 'g') {
  1416. shift_left_factor = 30;
  1417. value[last] = '\0';
  1418. }
  1419. return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
  1420. }
  1421. int
  1422. xfs_parseargs(
  1423. struct xfs_mount *mp,
  1424. char *options,
  1425. struct xfs_mount_args *args,
  1426. int update)
  1427. {
  1428. char *this_char, *value, *eov;
  1429. int dsunit, dswidth, vol_dsunit, vol_dswidth;
  1430. int iosize;
  1431. int ikeep = 0;
  1432. args->flags |= XFSMNT_BARRIER;
  1433. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1434. if (!options)
  1435. goto done;
  1436. iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
  1437. while ((this_char = strsep(&options, ",")) != NULL) {
  1438. if (!*this_char)
  1439. continue;
  1440. if ((value = strchr(this_char, '=')) != NULL)
  1441. *value++ = 0;
  1442. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  1443. if (!value || !*value) {
  1444. cmn_err(CE_WARN,
  1445. "XFS: %s option requires an argument",
  1446. this_char);
  1447. return EINVAL;
  1448. }
  1449. args->logbufs = simple_strtoul(value, &eov, 10);
  1450. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  1451. if (!value || !*value) {
  1452. cmn_err(CE_WARN,
  1453. "XFS: %s option requires an argument",
  1454. this_char);
  1455. return EINVAL;
  1456. }
  1457. args->logbufsize = suffix_strtoul(value, &eov, 10);
  1458. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  1459. if (!value || !*value) {
  1460. cmn_err(CE_WARN,
  1461. "XFS: %s option requires an argument",
  1462. this_char);
  1463. return EINVAL;
  1464. }
  1465. strncpy(args->logname, value, MAXNAMELEN);
  1466. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  1467. if (!value || !*value) {
  1468. cmn_err(CE_WARN,
  1469. "XFS: %s option requires an argument",
  1470. this_char);
  1471. return EINVAL;
  1472. }
  1473. strncpy(args->mtpt, value, MAXNAMELEN);
  1474. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  1475. if (!value || !*value) {
  1476. cmn_err(CE_WARN,
  1477. "XFS: %s option requires an argument",
  1478. this_char);
  1479. return EINVAL;
  1480. }
  1481. strncpy(args->rtname, value, MAXNAMELEN);
  1482. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  1483. if (!value || !*value) {
  1484. cmn_err(CE_WARN,
  1485. "XFS: %s option requires an argument",
  1486. this_char);
  1487. return EINVAL;
  1488. }
  1489. iosize = simple_strtoul(value, &eov, 10);
  1490. args->flags |= XFSMNT_IOSIZE;
  1491. args->iosizelog = (uint8_t) iosize;
  1492. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  1493. if (!value || !*value) {
  1494. cmn_err(CE_WARN,
  1495. "XFS: %s option requires an argument",
  1496. this_char);
  1497. return EINVAL;
  1498. }
  1499. iosize = suffix_strtoul(value, &eov, 10);
  1500. args->flags |= XFSMNT_IOSIZE;
  1501. args->iosizelog = ffs(iosize) - 1;
  1502. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  1503. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  1504. mp->m_flags |= XFS_MOUNT_GRPID;
  1505. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  1506. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  1507. mp->m_flags &= ~XFS_MOUNT_GRPID;
  1508. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  1509. args->flags |= XFSMNT_WSYNC;
  1510. } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
  1511. args->flags |= XFSMNT_OSYNCISOSYNC;
  1512. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  1513. args->flags |= XFSMNT_NORECOVERY;
  1514. } else if (!strcmp(this_char, MNTOPT_INO64)) {
  1515. args->flags |= XFSMNT_INO64;
  1516. #if !XFS_BIG_INUMS
  1517. cmn_err(CE_WARN,
  1518. "XFS: %s option not allowed on this system",
  1519. this_char);
  1520. return EINVAL;
  1521. #endif
  1522. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  1523. args->flags |= XFSMNT_NOALIGN;
  1524. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  1525. args->flags |= XFSMNT_SWALLOC;
  1526. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  1527. if (!value || !*value) {
  1528. cmn_err(CE_WARN,
  1529. "XFS: %s option requires an argument",
  1530. this_char);
  1531. return EINVAL;
  1532. }
  1533. dsunit = simple_strtoul(value, &eov, 10);
  1534. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  1535. if (!value || !*value) {
  1536. cmn_err(CE_WARN,
  1537. "XFS: %s option requires an argument",
  1538. this_char);
  1539. return EINVAL;
  1540. }
  1541. dswidth = simple_strtoul(value, &eov, 10);
  1542. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  1543. args->flags &= ~XFSMNT_32BITINODES;
  1544. #if !XFS_BIG_INUMS
  1545. cmn_err(CE_WARN,
  1546. "XFS: %s option not allowed on this system",
  1547. this_char);
  1548. return EINVAL;
  1549. #endif
  1550. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  1551. args->flags |= XFSMNT_NOUUID;
  1552. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  1553. args->flags |= XFSMNT_BARRIER;
  1554. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  1555. args->flags &= ~XFSMNT_BARRIER;
  1556. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  1557. ikeep = 1;
  1558. args->flags &= ~XFSMNT_IDELETE;
  1559. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  1560. args->flags |= XFSMNT_IDELETE;
  1561. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  1562. args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
  1563. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  1564. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1565. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  1566. args->flags |= XFSMNT_ATTR2;
  1567. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  1568. args->flags &= ~XFSMNT_ATTR2;
  1569. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  1570. args->flags2 |= XFSMNT2_FILESTREAMS;
  1571. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  1572. args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
  1573. args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
  1574. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  1575. !strcmp(this_char, MNTOPT_UQUOTA) ||
  1576. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  1577. args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
  1578. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  1579. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  1580. args->flags |= XFSMNT_UQUOTA;
  1581. args->flags &= ~XFSMNT_UQUOTAENF;
  1582. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  1583. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  1584. args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
  1585. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  1586. args->flags |= XFSMNT_PQUOTA;
  1587. args->flags &= ~XFSMNT_PQUOTAENF;
  1588. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  1589. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  1590. args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
  1591. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  1592. args->flags |= XFSMNT_GQUOTA;
  1593. args->flags &= ~XFSMNT_GQUOTAENF;
  1594. } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
  1595. args->flags |= XFSMNT_DMAPI;
  1596. } else if (!strcmp(this_char, MNTOPT_XDSM)) {
  1597. args->flags |= XFSMNT_DMAPI;
  1598. } else if (!strcmp(this_char, MNTOPT_DMI)) {
  1599. args->flags |= XFSMNT_DMAPI;
  1600. } else if (!strcmp(this_char, "ihashsize")) {
  1601. cmn_err(CE_WARN,
  1602. "XFS: ihashsize no longer used, option is deprecated.");
  1603. } else if (!strcmp(this_char, "osyncisdsync")) {
  1604. /* no-op, this is now the default */
  1605. cmn_err(CE_WARN,
  1606. "XFS: osyncisdsync is now the default, option is deprecated.");
  1607. } else if (!strcmp(this_char, "irixsgid")) {
  1608. cmn_err(CE_WARN,
  1609. "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
  1610. } else {
  1611. cmn_err(CE_WARN,
  1612. "XFS: unknown mount option [%s].", this_char);
  1613. return EINVAL;
  1614. }
  1615. }
  1616. if (args->flags & XFSMNT_NORECOVERY) {
  1617. if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
  1618. cmn_err(CE_WARN,
  1619. "XFS: no-recovery mounts must be read-only.");
  1620. return EINVAL;
  1621. }
  1622. }
  1623. if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
  1624. cmn_err(CE_WARN,
  1625. "XFS: sunit and swidth options incompatible with the noalign option");
  1626. return EINVAL;
  1627. }
  1628. if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
  1629. cmn_err(CE_WARN,
  1630. "XFS: cannot mount with both project and group quota");
  1631. return EINVAL;
  1632. }
  1633. if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
  1634. printk("XFS: %s option needs the mount point option as well\n",
  1635. MNTOPT_DMAPI);
  1636. return EINVAL;
  1637. }
  1638. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  1639. cmn_err(CE_WARN,
  1640. "XFS: sunit and swidth must be specified together");
  1641. return EINVAL;
  1642. }
  1643. if (dsunit && (dswidth % dsunit != 0)) {
  1644. cmn_err(CE_WARN,
  1645. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  1646. dswidth, dsunit);
  1647. return EINVAL;
  1648. }
  1649. /*
  1650. * Applications using DMI filesystems often expect the
  1651. * inode generation number to be monotonically increasing.
  1652. * If we delete inode chunks we break this assumption, so
  1653. * keep unused inode chunks on disk for DMI filesystems
  1654. * until we come up with a better solution.
  1655. * Note that if "ikeep" or "noikeep" mount options are
  1656. * supplied, then they are honored.
  1657. */
  1658. if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
  1659. args->flags |= XFSMNT_IDELETE;
  1660. if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  1661. if (dsunit) {
  1662. args->sunit = dsunit;
  1663. args->flags |= XFSMNT_RETERR;
  1664. } else {
  1665. args->sunit = vol_dsunit;
  1666. }
  1667. dswidth ? (args->swidth = dswidth) :
  1668. (args->swidth = vol_dswidth);
  1669. } else {
  1670. args->sunit = args->swidth = 0;
  1671. }
  1672. done:
  1673. if (args->flags & XFSMNT_32BITINODES)
  1674. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  1675. if (args->flags2)
  1676. args->flags |= XFSMNT_FLAGS2;
  1677. return 0;
  1678. }
  1679. int
  1680. xfs_showargs(
  1681. struct xfs_mount *mp,
  1682. struct seq_file *m)
  1683. {
  1684. static struct proc_xfs_info {
  1685. int flag;
  1686. char *str;
  1687. } xfs_info[] = {
  1688. /* the few simple ones we can get from the mount struct */
  1689. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  1690. { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
  1691. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  1692. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  1693. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  1694. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  1695. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  1696. { 0, NULL }
  1697. };
  1698. struct proc_xfs_info *xfs_infop;
  1699. for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
  1700. if (mp->m_flags & xfs_infop->flag)
  1701. seq_puts(m, xfs_infop->str);
  1702. }
  1703. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  1704. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  1705. (int)(1 << mp->m_writeio_log) >> 10);
  1706. if (mp->m_logbufs > 0)
  1707. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  1708. if (mp->m_logbsize > 0)
  1709. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  1710. if (mp->m_logname)
  1711. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  1712. if (mp->m_rtname)
  1713. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  1714. if (mp->m_dalign > 0)
  1715. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  1716. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  1717. if (mp->m_swidth > 0)
  1718. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  1719. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  1720. if (!(mp->m_flags & XFS_MOUNT_IDELETE))
  1721. seq_printf(m, "," MNTOPT_IKEEP);
  1722. if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
  1723. seq_printf(m, "," MNTOPT_LARGEIO);
  1724. if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS))
  1725. seq_printf(m, "," MNTOPT_64BITINODE);
  1726. if (mp->m_flags & XFS_MOUNT_GRPID)
  1727. seq_printf(m, "," MNTOPT_GRPID);
  1728. if (mp->m_qflags & XFS_UQUOTA_ACCT) {
  1729. if (mp->m_qflags & XFS_UQUOTA_ENFD)
  1730. seq_puts(m, "," MNTOPT_USRQUOTA);
  1731. else
  1732. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  1733. }
  1734. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  1735. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1736. seq_puts(m, "," MNTOPT_PRJQUOTA);
  1737. else
  1738. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  1739. }
  1740. if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  1741. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1742. seq_puts(m, "," MNTOPT_GRPQUOTA);
  1743. else
  1744. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  1745. }
  1746. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  1747. seq_puts(m, "," MNTOPT_NOQUOTA);
  1748. if (mp->m_flags & XFS_MOUNT_DMAPI)
  1749. seq_puts(m, "," MNTOPT_DMAPI);
  1750. return 0;
  1751. }
  1752. /*
  1753. * Second stage of a freeze. The data is already frozen so we only
  1754. * need to take care of themetadata. Once that's done write a dummy
  1755. * record to dirty the log in case of a crash while frozen.
  1756. */
  1757. void
  1758. xfs_freeze(
  1759. xfs_mount_t *mp)
  1760. {
  1761. xfs_attr_quiesce(mp);
  1762. xfs_fs_log_dummy(mp);
  1763. }