xfs_vfsops.c 51 KB

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