xfs_vfsops.c 51 KB

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