xfs_vfsops.c 52 KB

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