xfs_vfsops.c 52 KB

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