xfs_mount.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_shared.h"
  21. #include "xfs_format.h"
  22. #include "xfs_log_format.h"
  23. #include "xfs_trans_resv.h"
  24. #include "xfs_bit.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_da_format.h"
  28. #include "xfs_da_btree.h"
  29. #include "xfs_inode.h"
  30. #include "xfs_dir2.h"
  31. #include "xfs_ialloc.h"
  32. #include "xfs_alloc.h"
  33. #include "xfs_rtalloc.h"
  34. #include "xfs_bmap.h"
  35. #include "xfs_trans.h"
  36. #include "xfs_trans_priv.h"
  37. #include "xfs_log.h"
  38. #include "xfs_error.h"
  39. #include "xfs_quota.h"
  40. #include "xfs_fsops.h"
  41. #include "xfs_trace.h"
  42. #include "xfs_icache.h"
  43. #include "xfs_sysfs.h"
  44. static DEFINE_MUTEX(xfs_uuid_table_mutex);
  45. static int xfs_uuid_table_size;
  46. static uuid_t *xfs_uuid_table;
  47. /*
  48. * See if the UUID is unique among mounted XFS filesystems.
  49. * Mount fails if UUID is nil or a FS with the same UUID is already mounted.
  50. */
  51. STATIC int
  52. xfs_uuid_mount(
  53. struct xfs_mount *mp)
  54. {
  55. uuid_t *uuid = &mp->m_sb.sb_uuid;
  56. int hole, i;
  57. if (mp->m_flags & XFS_MOUNT_NOUUID)
  58. return 0;
  59. if (uuid_is_nil(uuid)) {
  60. xfs_warn(mp, "Filesystem has nil UUID - can't mount");
  61. return -EINVAL;
  62. }
  63. mutex_lock(&xfs_uuid_table_mutex);
  64. for (i = 0, hole = -1; i < xfs_uuid_table_size; i++) {
  65. if (uuid_is_nil(&xfs_uuid_table[i])) {
  66. hole = i;
  67. continue;
  68. }
  69. if (uuid_equal(uuid, &xfs_uuid_table[i]))
  70. goto out_duplicate;
  71. }
  72. if (hole < 0) {
  73. xfs_uuid_table = kmem_realloc(xfs_uuid_table,
  74. (xfs_uuid_table_size + 1) * sizeof(*xfs_uuid_table),
  75. xfs_uuid_table_size * sizeof(*xfs_uuid_table),
  76. KM_SLEEP);
  77. hole = xfs_uuid_table_size++;
  78. }
  79. xfs_uuid_table[hole] = *uuid;
  80. mutex_unlock(&xfs_uuid_table_mutex);
  81. return 0;
  82. out_duplicate:
  83. mutex_unlock(&xfs_uuid_table_mutex);
  84. xfs_warn(mp, "Filesystem has duplicate UUID %pU - can't mount", uuid);
  85. return -EINVAL;
  86. }
  87. STATIC void
  88. xfs_uuid_unmount(
  89. struct xfs_mount *mp)
  90. {
  91. uuid_t *uuid = &mp->m_sb.sb_uuid;
  92. int i;
  93. if (mp->m_flags & XFS_MOUNT_NOUUID)
  94. return;
  95. mutex_lock(&xfs_uuid_table_mutex);
  96. for (i = 0; i < xfs_uuid_table_size; i++) {
  97. if (uuid_is_nil(&xfs_uuid_table[i]))
  98. continue;
  99. if (!uuid_equal(uuid, &xfs_uuid_table[i]))
  100. continue;
  101. memset(&xfs_uuid_table[i], 0, sizeof(uuid_t));
  102. break;
  103. }
  104. ASSERT(i < xfs_uuid_table_size);
  105. mutex_unlock(&xfs_uuid_table_mutex);
  106. }
  107. STATIC void
  108. __xfs_free_perag(
  109. struct rcu_head *head)
  110. {
  111. struct xfs_perag *pag = container_of(head, struct xfs_perag, rcu_head);
  112. ASSERT(atomic_read(&pag->pag_ref) == 0);
  113. kmem_free(pag);
  114. }
  115. /*
  116. * Free up the per-ag resources associated with the mount structure.
  117. */
  118. STATIC void
  119. xfs_free_perag(
  120. xfs_mount_t *mp)
  121. {
  122. xfs_agnumber_t agno;
  123. struct xfs_perag *pag;
  124. for (agno = 0; agno < mp->m_sb.sb_agcount; agno++) {
  125. spin_lock(&mp->m_perag_lock);
  126. pag = radix_tree_delete(&mp->m_perag_tree, agno);
  127. spin_unlock(&mp->m_perag_lock);
  128. ASSERT(pag);
  129. ASSERT(atomic_read(&pag->pag_ref) == 0);
  130. call_rcu(&pag->rcu_head, __xfs_free_perag);
  131. }
  132. }
  133. /*
  134. * Check size of device based on the (data/realtime) block count.
  135. * Note: this check is used by the growfs code as well as mount.
  136. */
  137. int
  138. xfs_sb_validate_fsb_count(
  139. xfs_sb_t *sbp,
  140. __uint64_t nblocks)
  141. {
  142. ASSERT(PAGE_SHIFT >= sbp->sb_blocklog);
  143. ASSERT(sbp->sb_blocklog >= BBSHIFT);
  144. /* Limited by ULONG_MAX of page cache index */
  145. if (nblocks >> (PAGE_CACHE_SHIFT - sbp->sb_blocklog) > ULONG_MAX)
  146. return -EFBIG;
  147. return 0;
  148. }
  149. int
  150. xfs_initialize_perag(
  151. xfs_mount_t *mp,
  152. xfs_agnumber_t agcount,
  153. xfs_agnumber_t *maxagi)
  154. {
  155. xfs_agnumber_t index;
  156. xfs_agnumber_t first_initialised = 0;
  157. xfs_perag_t *pag;
  158. xfs_agino_t agino;
  159. xfs_ino_t ino;
  160. xfs_sb_t *sbp = &mp->m_sb;
  161. int error = -ENOMEM;
  162. /*
  163. * Walk the current per-ag tree so we don't try to initialise AGs
  164. * that already exist (growfs case). Allocate and insert all the
  165. * AGs we don't find ready for initialisation.
  166. */
  167. for (index = 0; index < agcount; index++) {
  168. pag = xfs_perag_get(mp, index);
  169. if (pag) {
  170. xfs_perag_put(pag);
  171. continue;
  172. }
  173. if (!first_initialised)
  174. first_initialised = index;
  175. pag = kmem_zalloc(sizeof(*pag), KM_MAYFAIL);
  176. if (!pag)
  177. goto out_unwind;
  178. pag->pag_agno = index;
  179. pag->pag_mount = mp;
  180. spin_lock_init(&pag->pag_ici_lock);
  181. mutex_init(&pag->pag_ici_reclaim_lock);
  182. INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC);
  183. spin_lock_init(&pag->pag_buf_lock);
  184. pag->pag_buf_tree = RB_ROOT;
  185. if (radix_tree_preload(GFP_NOFS))
  186. goto out_unwind;
  187. spin_lock(&mp->m_perag_lock);
  188. if (radix_tree_insert(&mp->m_perag_tree, index, pag)) {
  189. BUG();
  190. spin_unlock(&mp->m_perag_lock);
  191. radix_tree_preload_end();
  192. error = -EEXIST;
  193. goto out_unwind;
  194. }
  195. spin_unlock(&mp->m_perag_lock);
  196. radix_tree_preload_end();
  197. }
  198. /*
  199. * If we mount with the inode64 option, or no inode overflows
  200. * the legacy 32-bit address space clear the inode32 option.
  201. */
  202. agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0);
  203. ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
  204. if ((mp->m_flags & XFS_MOUNT_SMALL_INUMS) && ino > XFS_MAXINUMBER_32)
  205. mp->m_flags |= XFS_MOUNT_32BITINODES;
  206. else
  207. mp->m_flags &= ~XFS_MOUNT_32BITINODES;
  208. if (mp->m_flags & XFS_MOUNT_32BITINODES)
  209. index = xfs_set_inode32(mp, agcount);
  210. else
  211. index = xfs_set_inode64(mp, agcount);
  212. if (maxagi)
  213. *maxagi = index;
  214. return 0;
  215. out_unwind:
  216. kmem_free(pag);
  217. for (; index > first_initialised; index--) {
  218. pag = radix_tree_delete(&mp->m_perag_tree, index);
  219. kmem_free(pag);
  220. }
  221. return error;
  222. }
  223. /*
  224. * xfs_readsb
  225. *
  226. * Does the initial read of the superblock.
  227. */
  228. int
  229. xfs_readsb(
  230. struct xfs_mount *mp,
  231. int flags)
  232. {
  233. unsigned int sector_size;
  234. struct xfs_buf *bp;
  235. struct xfs_sb *sbp = &mp->m_sb;
  236. int error;
  237. int loud = !(flags & XFS_MFSI_QUIET);
  238. const struct xfs_buf_ops *buf_ops;
  239. ASSERT(mp->m_sb_bp == NULL);
  240. ASSERT(mp->m_ddev_targp != NULL);
  241. /*
  242. * For the initial read, we must guess at the sector
  243. * size based on the block device. It's enough to
  244. * get the sb_sectsize out of the superblock and
  245. * then reread with the proper length.
  246. * We don't verify it yet, because it may not be complete.
  247. */
  248. sector_size = xfs_getsize_buftarg(mp->m_ddev_targp);
  249. buf_ops = NULL;
  250. /*
  251. * Allocate a (locked) buffer to hold the superblock.
  252. * This will be kept around at all times to optimize
  253. * access to the superblock.
  254. */
  255. reread:
  256. error = xfs_buf_read_uncached(mp->m_ddev_targp, XFS_SB_DADDR,
  257. BTOBB(sector_size), 0, &bp, buf_ops);
  258. if (error) {
  259. if (loud)
  260. xfs_warn(mp, "SB validate failed with error %d.", error);
  261. /* bad CRC means corrupted metadata */
  262. if (error == -EFSBADCRC)
  263. error = -EFSCORRUPTED;
  264. return error;
  265. }
  266. /*
  267. * Initialize the mount structure from the superblock.
  268. */
  269. xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp));
  270. /*
  271. * If we haven't validated the superblock, do so now before we try
  272. * to check the sector size and reread the superblock appropriately.
  273. */
  274. if (sbp->sb_magicnum != XFS_SB_MAGIC) {
  275. if (loud)
  276. xfs_warn(mp, "Invalid superblock magic number");
  277. error = -EINVAL;
  278. goto release_buf;
  279. }
  280. /*
  281. * We must be able to do sector-sized and sector-aligned IO.
  282. */
  283. if (sector_size > sbp->sb_sectsize) {
  284. if (loud)
  285. xfs_warn(mp, "device supports %u byte sectors (not %u)",
  286. sector_size, sbp->sb_sectsize);
  287. error = -ENOSYS;
  288. goto release_buf;
  289. }
  290. if (buf_ops == NULL) {
  291. /*
  292. * Re-read the superblock so the buffer is correctly sized,
  293. * and properly verified.
  294. */
  295. xfs_buf_relse(bp);
  296. sector_size = sbp->sb_sectsize;
  297. buf_ops = loud ? &xfs_sb_buf_ops : &xfs_sb_quiet_buf_ops;
  298. goto reread;
  299. }
  300. xfs_reinit_percpu_counters(mp);
  301. /* no need to be quiet anymore, so reset the buf ops */
  302. bp->b_ops = &xfs_sb_buf_ops;
  303. mp->m_sb_bp = bp;
  304. xfs_buf_unlock(bp);
  305. return 0;
  306. release_buf:
  307. xfs_buf_relse(bp);
  308. return error;
  309. }
  310. /*
  311. * Update alignment values based on mount options and sb values
  312. */
  313. STATIC int
  314. xfs_update_alignment(xfs_mount_t *mp)
  315. {
  316. xfs_sb_t *sbp = &(mp->m_sb);
  317. if (mp->m_dalign) {
  318. /*
  319. * If stripe unit and stripe width are not multiples
  320. * of the fs blocksize turn off alignment.
  321. */
  322. if ((BBTOB(mp->m_dalign) & mp->m_blockmask) ||
  323. (BBTOB(mp->m_swidth) & mp->m_blockmask)) {
  324. xfs_warn(mp,
  325. "alignment check failed: sunit/swidth vs. blocksize(%d)",
  326. sbp->sb_blocksize);
  327. return -EINVAL;
  328. } else {
  329. /*
  330. * Convert the stripe unit and width to FSBs.
  331. */
  332. mp->m_dalign = XFS_BB_TO_FSBT(mp, mp->m_dalign);
  333. if (mp->m_dalign && (sbp->sb_agblocks % mp->m_dalign)) {
  334. xfs_warn(mp,
  335. "alignment check failed: sunit/swidth vs. agsize(%d)",
  336. sbp->sb_agblocks);
  337. return -EINVAL;
  338. } else if (mp->m_dalign) {
  339. mp->m_swidth = XFS_BB_TO_FSBT(mp, mp->m_swidth);
  340. } else {
  341. xfs_warn(mp,
  342. "alignment check failed: sunit(%d) less than bsize(%d)",
  343. mp->m_dalign, sbp->sb_blocksize);
  344. return -EINVAL;
  345. }
  346. }
  347. /*
  348. * Update superblock with new values
  349. * and log changes
  350. */
  351. if (xfs_sb_version_hasdalign(sbp)) {
  352. if (sbp->sb_unit != mp->m_dalign) {
  353. sbp->sb_unit = mp->m_dalign;
  354. mp->m_update_sb = true;
  355. }
  356. if (sbp->sb_width != mp->m_swidth) {
  357. sbp->sb_width = mp->m_swidth;
  358. mp->m_update_sb = true;
  359. }
  360. } else {
  361. xfs_warn(mp,
  362. "cannot change alignment: superblock does not support data alignment");
  363. return -EINVAL;
  364. }
  365. } else if ((mp->m_flags & XFS_MOUNT_NOALIGN) != XFS_MOUNT_NOALIGN &&
  366. xfs_sb_version_hasdalign(&mp->m_sb)) {
  367. mp->m_dalign = sbp->sb_unit;
  368. mp->m_swidth = sbp->sb_width;
  369. }
  370. return 0;
  371. }
  372. /*
  373. * Set the maximum inode count for this filesystem
  374. */
  375. STATIC void
  376. xfs_set_maxicount(xfs_mount_t *mp)
  377. {
  378. xfs_sb_t *sbp = &(mp->m_sb);
  379. __uint64_t icount;
  380. if (sbp->sb_imax_pct) {
  381. /*
  382. * Make sure the maximum inode count is a multiple
  383. * of the units we allocate inodes in.
  384. */
  385. icount = sbp->sb_dblocks * sbp->sb_imax_pct;
  386. do_div(icount, 100);
  387. do_div(icount, mp->m_ialloc_blks);
  388. mp->m_maxicount = (icount * mp->m_ialloc_blks) <<
  389. sbp->sb_inopblog;
  390. } else {
  391. mp->m_maxicount = 0;
  392. }
  393. }
  394. /*
  395. * Set the default minimum read and write sizes unless
  396. * already specified in a mount option.
  397. * We use smaller I/O sizes when the file system
  398. * is being used for NFS service (wsync mount option).
  399. */
  400. STATIC void
  401. xfs_set_rw_sizes(xfs_mount_t *mp)
  402. {
  403. xfs_sb_t *sbp = &(mp->m_sb);
  404. int readio_log, writeio_log;
  405. if (!(mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)) {
  406. if (mp->m_flags & XFS_MOUNT_WSYNC) {
  407. readio_log = XFS_WSYNC_READIO_LOG;
  408. writeio_log = XFS_WSYNC_WRITEIO_LOG;
  409. } else {
  410. readio_log = XFS_READIO_LOG_LARGE;
  411. writeio_log = XFS_WRITEIO_LOG_LARGE;
  412. }
  413. } else {
  414. readio_log = mp->m_readio_log;
  415. writeio_log = mp->m_writeio_log;
  416. }
  417. if (sbp->sb_blocklog > readio_log) {
  418. mp->m_readio_log = sbp->sb_blocklog;
  419. } else {
  420. mp->m_readio_log = readio_log;
  421. }
  422. mp->m_readio_blocks = 1 << (mp->m_readio_log - sbp->sb_blocklog);
  423. if (sbp->sb_blocklog > writeio_log) {
  424. mp->m_writeio_log = sbp->sb_blocklog;
  425. } else {
  426. mp->m_writeio_log = writeio_log;
  427. }
  428. mp->m_writeio_blocks = 1 << (mp->m_writeio_log - sbp->sb_blocklog);
  429. }
  430. /*
  431. * precalculate the low space thresholds for dynamic speculative preallocation.
  432. */
  433. void
  434. xfs_set_low_space_thresholds(
  435. struct xfs_mount *mp)
  436. {
  437. int i;
  438. for (i = 0; i < XFS_LOWSP_MAX; i++) {
  439. __uint64_t space = mp->m_sb.sb_dblocks;
  440. do_div(space, 100);
  441. mp->m_low_space[i] = space * (i + 1);
  442. }
  443. }
  444. /*
  445. * Set whether we're using inode alignment.
  446. */
  447. STATIC void
  448. xfs_set_inoalignment(xfs_mount_t *mp)
  449. {
  450. if (xfs_sb_version_hasalign(&mp->m_sb) &&
  451. mp->m_sb.sb_inoalignmt >=
  452. XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size))
  453. mp->m_inoalign_mask = mp->m_sb.sb_inoalignmt - 1;
  454. else
  455. mp->m_inoalign_mask = 0;
  456. /*
  457. * If we are using stripe alignment, check whether
  458. * the stripe unit is a multiple of the inode alignment
  459. */
  460. if (mp->m_dalign && mp->m_inoalign_mask &&
  461. !(mp->m_dalign & mp->m_inoalign_mask))
  462. mp->m_sinoalign = mp->m_dalign;
  463. else
  464. mp->m_sinoalign = 0;
  465. }
  466. /*
  467. * Check that the data (and log if separate) is an ok size.
  468. */
  469. STATIC int
  470. xfs_check_sizes(
  471. struct xfs_mount *mp)
  472. {
  473. struct xfs_buf *bp;
  474. xfs_daddr_t d;
  475. int error;
  476. d = (xfs_daddr_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks);
  477. if (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_dblocks) {
  478. xfs_warn(mp, "filesystem size mismatch detected");
  479. return -EFBIG;
  480. }
  481. error = xfs_buf_read_uncached(mp->m_ddev_targp,
  482. d - XFS_FSS_TO_BB(mp, 1),
  483. XFS_FSS_TO_BB(mp, 1), 0, &bp, NULL);
  484. if (error) {
  485. xfs_warn(mp, "last sector read failed");
  486. return error;
  487. }
  488. xfs_buf_relse(bp);
  489. if (mp->m_logdev_targp == mp->m_ddev_targp)
  490. return 0;
  491. d = (xfs_daddr_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
  492. if (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_logblocks) {
  493. xfs_warn(mp, "log size mismatch detected");
  494. return -EFBIG;
  495. }
  496. error = xfs_buf_read_uncached(mp->m_logdev_targp,
  497. d - XFS_FSB_TO_BB(mp, 1),
  498. XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL);
  499. if (error) {
  500. xfs_warn(mp, "log device read failed");
  501. return error;
  502. }
  503. xfs_buf_relse(bp);
  504. return 0;
  505. }
  506. /*
  507. * Clear the quotaflags in memory and in the superblock.
  508. */
  509. int
  510. xfs_mount_reset_sbqflags(
  511. struct xfs_mount *mp)
  512. {
  513. mp->m_qflags = 0;
  514. /* It is OK to look at sb_qflags in the mount path without m_sb_lock. */
  515. if (mp->m_sb.sb_qflags == 0)
  516. return 0;
  517. spin_lock(&mp->m_sb_lock);
  518. mp->m_sb.sb_qflags = 0;
  519. spin_unlock(&mp->m_sb_lock);
  520. if (!xfs_fs_writable(mp, SB_FREEZE_WRITE))
  521. return 0;
  522. return xfs_sync_sb(mp, false);
  523. }
  524. __uint64_t
  525. xfs_default_resblks(xfs_mount_t *mp)
  526. {
  527. __uint64_t resblks;
  528. /*
  529. * We default to 5% or 8192 fsbs of space reserved, whichever is
  530. * smaller. This is intended to cover concurrent allocation
  531. * transactions when we initially hit enospc. These each require a 4
  532. * block reservation. Hence by default we cover roughly 2000 concurrent
  533. * allocation reservations.
  534. */
  535. resblks = mp->m_sb.sb_dblocks;
  536. do_div(resblks, 20);
  537. resblks = min_t(__uint64_t, resblks, 8192);
  538. return resblks;
  539. }
  540. /*
  541. * This function does the following on an initial mount of a file system:
  542. * - reads the superblock from disk and init the mount struct
  543. * - if we're a 32-bit kernel, do a size check on the superblock
  544. * so we don't mount terabyte filesystems
  545. * - init mount struct realtime fields
  546. * - allocate inode hash table for fs
  547. * - init directory manager
  548. * - perform recovery and init the log manager
  549. */
  550. int
  551. xfs_mountfs(
  552. xfs_mount_t *mp)
  553. {
  554. xfs_sb_t *sbp = &(mp->m_sb);
  555. xfs_inode_t *rip;
  556. __uint64_t resblks;
  557. uint quotamount = 0;
  558. uint quotaflags = 0;
  559. int error = 0;
  560. xfs_sb_mount_common(mp, sbp);
  561. /*
  562. * Check for a mismatched features2 values. Older kernels read & wrote
  563. * into the wrong sb offset for sb_features2 on some platforms due to
  564. * xfs_sb_t not being 64bit size aligned when sb_features2 was added,
  565. * which made older superblock reading/writing routines swap it as a
  566. * 64-bit value.
  567. *
  568. * For backwards compatibility, we make both slots equal.
  569. *
  570. * If we detect a mismatched field, we OR the set bits into the existing
  571. * features2 field in case it has already been modified; we don't want
  572. * to lose any features. We then update the bad location with the ORed
  573. * value so that older kernels will see any features2 flags. The
  574. * superblock writeback code ensures the new sb_features2 is copied to
  575. * sb_bad_features2 before it is logged or written to disk.
  576. */
  577. if (xfs_sb_has_mismatched_features2(sbp)) {
  578. xfs_warn(mp, "correcting sb_features alignment problem");
  579. sbp->sb_features2 |= sbp->sb_bad_features2;
  580. mp->m_update_sb = true;
  581. /*
  582. * Re-check for ATTR2 in case it was found in bad_features2
  583. * slot.
  584. */
  585. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  586. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  587. mp->m_flags |= XFS_MOUNT_ATTR2;
  588. }
  589. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  590. (mp->m_flags & XFS_MOUNT_NOATTR2)) {
  591. xfs_sb_version_removeattr2(&mp->m_sb);
  592. mp->m_update_sb = true;
  593. /* update sb_versionnum for the clearing of the morebits */
  594. if (!sbp->sb_features2)
  595. mp->m_update_sb = true;
  596. }
  597. /* always use v2 inodes by default now */
  598. if (!(mp->m_sb.sb_versionnum & XFS_SB_VERSION_NLINKBIT)) {
  599. mp->m_sb.sb_versionnum |= XFS_SB_VERSION_NLINKBIT;
  600. mp->m_update_sb = true;
  601. }
  602. /*
  603. * Check if sb_agblocks is aligned at stripe boundary
  604. * If sb_agblocks is NOT aligned turn off m_dalign since
  605. * allocator alignment is within an ag, therefore ag has
  606. * to be aligned at stripe boundary.
  607. */
  608. error = xfs_update_alignment(mp);
  609. if (error)
  610. goto out;
  611. xfs_alloc_compute_maxlevels(mp);
  612. xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK);
  613. xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK);
  614. xfs_ialloc_compute_maxlevels(mp);
  615. xfs_set_maxicount(mp);
  616. error = xfs_sysfs_init(&mp->m_kobj, &xfs_mp_ktype, NULL, mp->m_fsname);
  617. if (error)
  618. goto out;
  619. error = xfs_uuid_mount(mp);
  620. if (error)
  621. goto out_remove_sysfs;
  622. /*
  623. * Set the minimum read and write sizes
  624. */
  625. xfs_set_rw_sizes(mp);
  626. /* set the low space thresholds for dynamic preallocation */
  627. xfs_set_low_space_thresholds(mp);
  628. /*
  629. * Set the inode cluster size.
  630. * This may still be overridden by the file system
  631. * block size if it is larger than the chosen cluster size.
  632. *
  633. * For v5 filesystems, scale the cluster size with the inode size to
  634. * keep a constant ratio of inode per cluster buffer, but only if mkfs
  635. * has set the inode alignment value appropriately for larger cluster
  636. * sizes.
  637. */
  638. mp->m_inode_cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
  639. if (xfs_sb_version_hascrc(&mp->m_sb)) {
  640. int new_size = mp->m_inode_cluster_size;
  641. new_size *= mp->m_sb.sb_inodesize / XFS_DINODE_MIN_SIZE;
  642. if (mp->m_sb.sb_inoalignmt >= XFS_B_TO_FSBT(mp, new_size))
  643. mp->m_inode_cluster_size = new_size;
  644. }
  645. /*
  646. * Set inode alignment fields
  647. */
  648. xfs_set_inoalignment(mp);
  649. /*
  650. * Check that the data (and log if separate) is an ok size.
  651. */
  652. error = xfs_check_sizes(mp);
  653. if (error)
  654. goto out_remove_uuid;
  655. /*
  656. * Initialize realtime fields in the mount structure
  657. */
  658. error = xfs_rtmount_init(mp);
  659. if (error) {
  660. xfs_warn(mp, "RT mount failed");
  661. goto out_remove_uuid;
  662. }
  663. /*
  664. * Copies the low order bits of the timestamp and the randomly
  665. * set "sequence" number out of a UUID.
  666. */
  667. uuid_getnodeuniq(&sbp->sb_uuid, mp->m_fixedfsid);
  668. mp->m_dmevmask = 0; /* not persistent; set after each mount */
  669. error = xfs_da_mount(mp);
  670. if (error) {
  671. xfs_warn(mp, "Failed dir/attr init: %d", error);
  672. goto out_remove_uuid;
  673. }
  674. /*
  675. * Initialize the precomputed transaction reservations values.
  676. */
  677. xfs_trans_init(mp);
  678. /*
  679. * Allocate and initialize the per-ag data.
  680. */
  681. spin_lock_init(&mp->m_perag_lock);
  682. INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
  683. error = xfs_initialize_perag(mp, sbp->sb_agcount, &mp->m_maxagi);
  684. if (error) {
  685. xfs_warn(mp, "Failed per-ag init: %d", error);
  686. goto out_free_dir;
  687. }
  688. if (!sbp->sb_logblocks) {
  689. xfs_warn(mp, "no log defined");
  690. XFS_ERROR_REPORT("xfs_mountfs", XFS_ERRLEVEL_LOW, mp);
  691. error = -EFSCORRUPTED;
  692. goto out_free_perag;
  693. }
  694. /*
  695. * log's mount-time initialization. Perform 1st part recovery if needed
  696. */
  697. error = xfs_log_mount(mp, mp->m_logdev_targp,
  698. XFS_FSB_TO_DADDR(mp, sbp->sb_logstart),
  699. XFS_FSB_TO_BB(mp, sbp->sb_logblocks));
  700. if (error) {
  701. xfs_warn(mp, "log mount failed");
  702. goto out_fail_wait;
  703. }
  704. /*
  705. * Now the log is mounted, we know if it was an unclean shutdown or
  706. * not. If it was, with the first phase of recovery has completed, we
  707. * have consistent AG blocks on disk. We have not recovered EFIs yet,
  708. * but they are recovered transactionally in the second recovery phase
  709. * later.
  710. *
  711. * Hence we can safely re-initialise incore superblock counters from
  712. * the per-ag data. These may not be correct if the filesystem was not
  713. * cleanly unmounted, so we need to wait for recovery to finish before
  714. * doing this.
  715. *
  716. * If the filesystem was cleanly unmounted, then we can trust the
  717. * values in the superblock to be correct and we don't need to do
  718. * anything here.
  719. *
  720. * If we are currently making the filesystem, the initialisation will
  721. * fail as the perag data is in an undefined state.
  722. */
  723. if (xfs_sb_version_haslazysbcount(&mp->m_sb) &&
  724. !XFS_LAST_UNMOUNT_WAS_CLEAN(mp) &&
  725. !mp->m_sb.sb_inprogress) {
  726. error = xfs_initialize_perag_data(mp, sbp->sb_agcount);
  727. if (error)
  728. goto out_log_dealloc;
  729. }
  730. /*
  731. * Get and sanity-check the root inode.
  732. * Save the pointer to it in the mount structure.
  733. */
  734. error = xfs_iget(mp, NULL, sbp->sb_rootino, 0, XFS_ILOCK_EXCL, &rip);
  735. if (error) {
  736. xfs_warn(mp, "failed to read root inode");
  737. goto out_log_dealloc;
  738. }
  739. ASSERT(rip != NULL);
  740. if (unlikely(!S_ISDIR(rip->i_d.di_mode))) {
  741. xfs_warn(mp, "corrupted root inode %llu: not a directory",
  742. (unsigned long long)rip->i_ino);
  743. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  744. XFS_ERROR_REPORT("xfs_mountfs_int(2)", XFS_ERRLEVEL_LOW,
  745. mp);
  746. error = -EFSCORRUPTED;
  747. goto out_rele_rip;
  748. }
  749. mp->m_rootip = rip; /* save it */
  750. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  751. /*
  752. * Initialize realtime inode pointers in the mount structure
  753. */
  754. error = xfs_rtmount_inodes(mp);
  755. if (error) {
  756. /*
  757. * Free up the root inode.
  758. */
  759. xfs_warn(mp, "failed to read RT inodes");
  760. goto out_rele_rip;
  761. }
  762. /*
  763. * If this is a read-only mount defer the superblock updates until
  764. * the next remount into writeable mode. Otherwise we would never
  765. * perform the update e.g. for the root filesystem.
  766. */
  767. if (mp->m_update_sb && !(mp->m_flags & XFS_MOUNT_RDONLY)) {
  768. error = xfs_sync_sb(mp, false);
  769. if (error) {
  770. xfs_warn(mp, "failed to write sb changes");
  771. goto out_rtunmount;
  772. }
  773. }
  774. /*
  775. * Initialise the XFS quota management subsystem for this mount
  776. */
  777. if (XFS_IS_QUOTA_RUNNING(mp)) {
  778. error = xfs_qm_newmount(mp, &quotamount, &quotaflags);
  779. if (error)
  780. goto out_rtunmount;
  781. } else {
  782. ASSERT(!XFS_IS_QUOTA_ON(mp));
  783. /*
  784. * If a file system had quotas running earlier, but decided to
  785. * mount without -o uquota/pquota/gquota options, revoke the
  786. * quotachecked license.
  787. */
  788. if (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT) {
  789. xfs_notice(mp, "resetting quota flags");
  790. error = xfs_mount_reset_sbqflags(mp);
  791. if (error)
  792. goto out_rtunmount;
  793. }
  794. }
  795. /*
  796. * Finish recovering the file system. This part needed to be
  797. * delayed until after the root and real-time bitmap inodes
  798. * were consistently read in.
  799. */
  800. error = xfs_log_mount_finish(mp);
  801. if (error) {
  802. xfs_warn(mp, "log mount finish failed");
  803. goto out_rtunmount;
  804. }
  805. /*
  806. * Complete the quota initialisation, post-log-replay component.
  807. */
  808. if (quotamount) {
  809. ASSERT(mp->m_qflags == 0);
  810. mp->m_qflags = quotaflags;
  811. xfs_qm_mount_quotas(mp);
  812. }
  813. /*
  814. * Now we are mounted, reserve a small amount of unused space for
  815. * privileged transactions. This is needed so that transaction
  816. * space required for critical operations can dip into this pool
  817. * when at ENOSPC. This is needed for operations like create with
  818. * attr, unwritten extent conversion at ENOSPC, etc. Data allocations
  819. * are not allowed to use this reserved space.
  820. *
  821. * This may drive us straight to ENOSPC on mount, but that implies
  822. * we were already there on the last unmount. Warn if this occurs.
  823. */
  824. if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
  825. resblks = xfs_default_resblks(mp);
  826. error = xfs_reserve_blocks(mp, &resblks, NULL);
  827. if (error)
  828. xfs_warn(mp,
  829. "Unable to allocate reserve blocks. Continuing without reserve pool.");
  830. }
  831. return 0;
  832. out_rtunmount:
  833. xfs_rtunmount_inodes(mp);
  834. out_rele_rip:
  835. IRELE(rip);
  836. out_log_dealloc:
  837. xfs_log_unmount(mp);
  838. out_fail_wait:
  839. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp)
  840. xfs_wait_buftarg(mp->m_logdev_targp);
  841. xfs_wait_buftarg(mp->m_ddev_targp);
  842. out_free_perag:
  843. xfs_free_perag(mp);
  844. out_free_dir:
  845. xfs_da_unmount(mp);
  846. out_remove_uuid:
  847. xfs_uuid_unmount(mp);
  848. out_remove_sysfs:
  849. xfs_sysfs_del(&mp->m_kobj);
  850. out:
  851. return error;
  852. }
  853. /*
  854. * This flushes out the inodes,dquots and the superblock, unmounts the
  855. * log and makes sure that incore structures are freed.
  856. */
  857. void
  858. xfs_unmountfs(
  859. struct xfs_mount *mp)
  860. {
  861. __uint64_t resblks;
  862. int error;
  863. cancel_delayed_work_sync(&mp->m_eofblocks_work);
  864. xfs_qm_unmount_quotas(mp);
  865. xfs_rtunmount_inodes(mp);
  866. IRELE(mp->m_rootip);
  867. /*
  868. * We can potentially deadlock here if we have an inode cluster
  869. * that has been freed has its buffer still pinned in memory because
  870. * the transaction is still sitting in a iclog. The stale inodes
  871. * on that buffer will have their flush locks held until the
  872. * transaction hits the disk and the callbacks run. the inode
  873. * flush takes the flush lock unconditionally and with nothing to
  874. * push out the iclog we will never get that unlocked. hence we
  875. * need to force the log first.
  876. */
  877. xfs_log_force(mp, XFS_LOG_SYNC);
  878. /*
  879. * Flush all pending changes from the AIL.
  880. */
  881. xfs_ail_push_all_sync(mp->m_ail);
  882. /*
  883. * And reclaim all inodes. At this point there should be no dirty
  884. * inodes and none should be pinned or locked, but use synchronous
  885. * reclaim just to be sure. We can stop background inode reclaim
  886. * here as well if it is still running.
  887. */
  888. cancel_delayed_work_sync(&mp->m_reclaim_work);
  889. xfs_reclaim_inodes(mp, SYNC_WAIT);
  890. xfs_qm_unmount(mp);
  891. /*
  892. * Unreserve any blocks we have so that when we unmount we don't account
  893. * the reserved free space as used. This is really only necessary for
  894. * lazy superblock counting because it trusts the incore superblock
  895. * counters to be absolutely correct on clean unmount.
  896. *
  897. * We don't bother correcting this elsewhere for lazy superblock
  898. * counting because on mount of an unclean filesystem we reconstruct the
  899. * correct counter value and this is irrelevant.
  900. *
  901. * For non-lazy counter filesystems, this doesn't matter at all because
  902. * we only every apply deltas to the superblock and hence the incore
  903. * value does not matter....
  904. */
  905. resblks = 0;
  906. error = xfs_reserve_blocks(mp, &resblks, NULL);
  907. if (error)
  908. xfs_warn(mp, "Unable to free reserved block pool. "
  909. "Freespace may not be correct on next mount.");
  910. error = xfs_log_sbcount(mp);
  911. if (error)
  912. xfs_warn(mp, "Unable to update superblock counters. "
  913. "Freespace may not be correct on next mount.");
  914. xfs_log_unmount(mp);
  915. xfs_da_unmount(mp);
  916. xfs_uuid_unmount(mp);
  917. #if defined(DEBUG)
  918. xfs_errortag_clearall(mp, 0);
  919. #endif
  920. xfs_free_perag(mp);
  921. xfs_sysfs_del(&mp->m_kobj);
  922. }
  923. /*
  924. * Determine whether modifications can proceed. The caller specifies the minimum
  925. * freeze level for which modifications should not be allowed. This allows
  926. * certain operations to proceed while the freeze sequence is in progress, if
  927. * necessary.
  928. */
  929. bool
  930. xfs_fs_writable(
  931. struct xfs_mount *mp,
  932. int level)
  933. {
  934. ASSERT(level > SB_UNFROZEN);
  935. if ((mp->m_super->s_writers.frozen >= level) ||
  936. XFS_FORCED_SHUTDOWN(mp) || (mp->m_flags & XFS_MOUNT_RDONLY))
  937. return false;
  938. return true;
  939. }
  940. /*
  941. * xfs_log_sbcount
  942. *
  943. * Sync the superblock counters to disk.
  944. *
  945. * Note this code can be called during the process of freezing, so we use the
  946. * transaction allocator that does not block when the transaction subsystem is
  947. * in its frozen state.
  948. */
  949. int
  950. xfs_log_sbcount(xfs_mount_t *mp)
  951. {
  952. /* allow this to proceed during the freeze sequence... */
  953. if (!xfs_fs_writable(mp, SB_FREEZE_COMPLETE))
  954. return 0;
  955. /*
  956. * we don't need to do this if we are updating the superblock
  957. * counters on every modification.
  958. */
  959. if (!xfs_sb_version_haslazysbcount(&mp->m_sb))
  960. return 0;
  961. return xfs_sync_sb(mp, true);
  962. }
  963. /*
  964. * Deltas for the inode count are +/-64, hence we use a large batch size
  965. * of 128 so we don't need to take the counter lock on every update.
  966. */
  967. #define XFS_ICOUNT_BATCH 128
  968. int
  969. xfs_mod_icount(
  970. struct xfs_mount *mp,
  971. int64_t delta)
  972. {
  973. __percpu_counter_add(&mp->m_icount, delta, XFS_ICOUNT_BATCH);
  974. if (__percpu_counter_compare(&mp->m_icount, 0, XFS_ICOUNT_BATCH) < 0) {
  975. ASSERT(0);
  976. percpu_counter_add(&mp->m_icount, -delta);
  977. return -EINVAL;
  978. }
  979. return 0;
  980. }
  981. int
  982. xfs_mod_ifree(
  983. struct xfs_mount *mp,
  984. int64_t delta)
  985. {
  986. percpu_counter_add(&mp->m_ifree, delta);
  987. if (percpu_counter_compare(&mp->m_ifree, 0) < 0) {
  988. ASSERT(0);
  989. percpu_counter_add(&mp->m_ifree, -delta);
  990. return -EINVAL;
  991. }
  992. return 0;
  993. }
  994. /*
  995. * Deltas for the block count can vary from 1 to very large, but lock contention
  996. * only occurs on frequent small block count updates such as in the delayed
  997. * allocation path for buffered writes (page a time updates). Hence we set
  998. * a large batch count (1024) to minimise global counter updates except when
  999. * we get near to ENOSPC and we have to be very accurate with our updates.
  1000. */
  1001. #define XFS_FDBLOCKS_BATCH 1024
  1002. int
  1003. xfs_mod_fdblocks(
  1004. struct xfs_mount *mp,
  1005. int64_t delta,
  1006. bool rsvd)
  1007. {
  1008. int64_t lcounter;
  1009. long long res_used;
  1010. s32 batch;
  1011. if (delta > 0) {
  1012. /*
  1013. * If the reserve pool is depleted, put blocks back into it
  1014. * first. Most of the time the pool is full.
  1015. */
  1016. if (likely(mp->m_resblks == mp->m_resblks_avail)) {
  1017. percpu_counter_add(&mp->m_fdblocks, delta);
  1018. return 0;
  1019. }
  1020. spin_lock(&mp->m_sb_lock);
  1021. res_used = (long long)(mp->m_resblks - mp->m_resblks_avail);
  1022. if (res_used > delta) {
  1023. mp->m_resblks_avail += delta;
  1024. } else {
  1025. delta -= res_used;
  1026. mp->m_resblks_avail = mp->m_resblks;
  1027. percpu_counter_add(&mp->m_fdblocks, delta);
  1028. }
  1029. spin_unlock(&mp->m_sb_lock);
  1030. return 0;
  1031. }
  1032. /*
  1033. * Taking blocks away, need to be more accurate the closer we
  1034. * are to zero.
  1035. *
  1036. * If the counter has a value of less than 2 * max batch size,
  1037. * then make everything serialise as we are real close to
  1038. * ENOSPC.
  1039. */
  1040. if (__percpu_counter_compare(&mp->m_fdblocks, 2 * XFS_FDBLOCKS_BATCH,
  1041. XFS_FDBLOCKS_BATCH) < 0)
  1042. batch = 1;
  1043. else
  1044. batch = XFS_FDBLOCKS_BATCH;
  1045. __percpu_counter_add(&mp->m_fdblocks, delta, batch);
  1046. if (__percpu_counter_compare(&mp->m_fdblocks, XFS_ALLOC_SET_ASIDE(mp),
  1047. XFS_FDBLOCKS_BATCH) >= 0) {
  1048. /* we had space! */
  1049. return 0;
  1050. }
  1051. /*
  1052. * lock up the sb for dipping into reserves before releasing the space
  1053. * that took us to ENOSPC.
  1054. */
  1055. spin_lock(&mp->m_sb_lock);
  1056. percpu_counter_add(&mp->m_fdblocks, -delta);
  1057. if (!rsvd)
  1058. goto fdblocks_enospc;
  1059. lcounter = (long long)mp->m_resblks_avail + delta;
  1060. if (lcounter >= 0) {
  1061. mp->m_resblks_avail = lcounter;
  1062. spin_unlock(&mp->m_sb_lock);
  1063. return 0;
  1064. }
  1065. printk_once(KERN_WARNING
  1066. "Filesystem \"%s\": reserve blocks depleted! "
  1067. "Consider increasing reserve pool size.",
  1068. mp->m_fsname);
  1069. fdblocks_enospc:
  1070. spin_unlock(&mp->m_sb_lock);
  1071. return -ENOSPC;
  1072. }
  1073. int
  1074. xfs_mod_frextents(
  1075. struct xfs_mount *mp,
  1076. int64_t delta)
  1077. {
  1078. int64_t lcounter;
  1079. int ret = 0;
  1080. spin_lock(&mp->m_sb_lock);
  1081. lcounter = mp->m_sb.sb_frextents + delta;
  1082. if (lcounter < 0)
  1083. ret = -ENOSPC;
  1084. else
  1085. mp->m_sb.sb_frextents = lcounter;
  1086. spin_unlock(&mp->m_sb_lock);
  1087. return ret;
  1088. }
  1089. /*
  1090. * xfs_getsb() is called to obtain the buffer for the superblock.
  1091. * The buffer is returned locked and read in from disk.
  1092. * The buffer should be released with a call to xfs_brelse().
  1093. *
  1094. * If the flags parameter is BUF_TRYLOCK, then we'll only return
  1095. * the superblock buffer if it can be locked without sleeping.
  1096. * If it can't then we'll return NULL.
  1097. */
  1098. struct xfs_buf *
  1099. xfs_getsb(
  1100. struct xfs_mount *mp,
  1101. int flags)
  1102. {
  1103. struct xfs_buf *bp = mp->m_sb_bp;
  1104. if (!xfs_buf_trylock(bp)) {
  1105. if (flags & XBF_TRYLOCK)
  1106. return NULL;
  1107. xfs_buf_lock(bp);
  1108. }
  1109. xfs_buf_hold(bp);
  1110. ASSERT(XFS_BUF_ISDONE(bp));
  1111. return bp;
  1112. }
  1113. /*
  1114. * Used to free the superblock along various error paths.
  1115. */
  1116. void
  1117. xfs_freesb(
  1118. struct xfs_mount *mp)
  1119. {
  1120. struct xfs_buf *bp = mp->m_sb_bp;
  1121. xfs_buf_lock(bp);
  1122. mp->m_sb_bp = NULL;
  1123. xfs_buf_relse(bp);
  1124. }
  1125. /*
  1126. * If the underlying (data/log/rt) device is readonly, there are some
  1127. * operations that cannot proceed.
  1128. */
  1129. int
  1130. xfs_dev_is_read_only(
  1131. struct xfs_mount *mp,
  1132. char *message)
  1133. {
  1134. if (xfs_readonly_buftarg(mp->m_ddev_targp) ||
  1135. xfs_readonly_buftarg(mp->m_logdev_targp) ||
  1136. (mp->m_rtdev_targp && xfs_readonly_buftarg(mp->m_rtdev_targp))) {
  1137. xfs_notice(mp, "%s required on read-only device.", message);
  1138. xfs_notice(mp, "write access unavailable, cannot proceed.");
  1139. return -EROFS;
  1140. }
  1141. return 0;
  1142. }