xfs_fsops.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #include "xfs.h"
  33. #include "xfs_macros.h"
  34. #include "xfs_types.h"
  35. #include "xfs_inum.h"
  36. #include "xfs_log.h"
  37. #include "xfs_trans.h"
  38. #include "xfs_sb.h"
  39. #include "xfs_dir.h"
  40. #include "xfs_dmapi.h"
  41. #include "xfs_mount.h"
  42. #include "xfs_ag.h"
  43. #include "xfs_alloc_btree.h"
  44. #include "xfs_bmap_btree.h"
  45. #include "xfs_ialloc_btree.h"
  46. #include "xfs_btree.h"
  47. #include "xfs_error.h"
  48. #include "xfs_alloc.h"
  49. #include "xfs_ialloc.h"
  50. #include "xfs_fsops.h"
  51. #include "xfs_itable.h"
  52. #include "xfs_rw.h"
  53. #include "xfs_refcache.h"
  54. #include "xfs_trans_space.h"
  55. #include "xfs_rtalloc.h"
  56. #include "xfs_dir2.h"
  57. #include "xfs_attr_sf.h"
  58. #include "xfs_dir_sf.h"
  59. #include "xfs_dir2_sf.h"
  60. #include "xfs_dinode.h"
  61. #include "xfs_inode.h"
  62. #include "xfs_inode_item.h"
  63. /*
  64. * File system operations
  65. */
  66. int
  67. xfs_fs_geometry(
  68. xfs_mount_t *mp,
  69. xfs_fsop_geom_t *geo,
  70. int new_version)
  71. {
  72. geo->blocksize = mp->m_sb.sb_blocksize;
  73. geo->rtextsize = mp->m_sb.sb_rextsize;
  74. geo->agblocks = mp->m_sb.sb_agblocks;
  75. geo->agcount = mp->m_sb.sb_agcount;
  76. geo->logblocks = mp->m_sb.sb_logblocks;
  77. geo->sectsize = mp->m_sb.sb_sectsize;
  78. geo->inodesize = mp->m_sb.sb_inodesize;
  79. geo->imaxpct = mp->m_sb.sb_imax_pct;
  80. geo->datablocks = mp->m_sb.sb_dblocks;
  81. geo->rtblocks = mp->m_sb.sb_rblocks;
  82. geo->rtextents = mp->m_sb.sb_rextents;
  83. geo->logstart = mp->m_sb.sb_logstart;
  84. ASSERT(sizeof(geo->uuid)==sizeof(mp->m_sb.sb_uuid));
  85. memcpy(geo->uuid, &mp->m_sb.sb_uuid, sizeof(mp->m_sb.sb_uuid));
  86. if (new_version >= 2) {
  87. geo->sunit = mp->m_sb.sb_unit;
  88. geo->swidth = mp->m_sb.sb_width;
  89. }
  90. if (new_version >= 3) {
  91. geo->version = XFS_FSOP_GEOM_VERSION;
  92. geo->flags =
  93. (XFS_SB_VERSION_HASATTR(&mp->m_sb) ?
  94. XFS_FSOP_GEOM_FLAGS_ATTR : 0) |
  95. (XFS_SB_VERSION_HASNLINK(&mp->m_sb) ?
  96. XFS_FSOP_GEOM_FLAGS_NLINK : 0) |
  97. (XFS_SB_VERSION_HASQUOTA(&mp->m_sb) ?
  98. XFS_FSOP_GEOM_FLAGS_QUOTA : 0) |
  99. (XFS_SB_VERSION_HASALIGN(&mp->m_sb) ?
  100. XFS_FSOP_GEOM_FLAGS_IALIGN : 0) |
  101. (XFS_SB_VERSION_HASDALIGN(&mp->m_sb) ?
  102. XFS_FSOP_GEOM_FLAGS_DALIGN : 0) |
  103. (XFS_SB_VERSION_HASSHARED(&mp->m_sb) ?
  104. XFS_FSOP_GEOM_FLAGS_SHARED : 0) |
  105. (XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb) ?
  106. XFS_FSOP_GEOM_FLAGS_EXTFLG : 0) |
  107. (XFS_SB_VERSION_HASDIRV2(&mp->m_sb) ?
  108. XFS_FSOP_GEOM_FLAGS_DIRV2 : 0) |
  109. (XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ?
  110. XFS_FSOP_GEOM_FLAGS_SECTOR : 0) |
  111. (XFS_SB_VERSION_HASATTR2(&mp->m_sb) ?
  112. XFS_FSOP_GEOM_FLAGS_ATTR2 : 0);
  113. geo->logsectsize = XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ?
  114. mp->m_sb.sb_logsectsize : BBSIZE;
  115. geo->rtsectsize = mp->m_sb.sb_blocksize;
  116. geo->dirblocksize = mp->m_dirblksize;
  117. }
  118. if (new_version >= 4) {
  119. geo->flags |=
  120. (XFS_SB_VERSION_HASLOGV2(&mp->m_sb) ?
  121. XFS_FSOP_GEOM_FLAGS_LOGV2 : 0);
  122. geo->logsunit = mp->m_sb.sb_logsunit;
  123. }
  124. return 0;
  125. }
  126. static int
  127. xfs_growfs_data_private(
  128. xfs_mount_t *mp, /* mount point for filesystem */
  129. xfs_growfs_data_t *in) /* growfs data input struct */
  130. {
  131. xfs_agf_t *agf;
  132. xfs_agi_t *agi;
  133. xfs_agnumber_t agno;
  134. xfs_extlen_t agsize;
  135. xfs_extlen_t tmpsize;
  136. xfs_alloc_rec_t *arec;
  137. xfs_btree_sblock_t *block;
  138. xfs_buf_t *bp;
  139. int bucket;
  140. int dpct;
  141. int error;
  142. xfs_agnumber_t nagcount;
  143. xfs_agnumber_t nagimax = 0;
  144. xfs_rfsblock_t nb, nb_mod;
  145. xfs_rfsblock_t new;
  146. xfs_rfsblock_t nfree;
  147. xfs_agnumber_t oagcount;
  148. int pct;
  149. xfs_sb_t *sbp;
  150. xfs_trans_t *tp;
  151. nb = in->newblocks;
  152. pct = in->imaxpct;
  153. if (nb < mp->m_sb.sb_dblocks || pct < 0 || pct > 100)
  154. return XFS_ERROR(EINVAL);
  155. dpct = pct - mp->m_sb.sb_imax_pct;
  156. error = xfs_read_buf(mp, mp->m_ddev_targp,
  157. XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1),
  158. XFS_FSS_TO_BB(mp, 1), 0, &bp);
  159. if (error)
  160. return error;
  161. ASSERT(bp);
  162. xfs_buf_relse(bp);
  163. new = nb; /* use new as a temporary here */
  164. nb_mod = do_div(new, mp->m_sb.sb_agblocks);
  165. nagcount = new + (nb_mod != 0);
  166. if (nb_mod && nb_mod < XFS_MIN_AG_BLOCKS) {
  167. nagcount--;
  168. nb = nagcount * mp->m_sb.sb_agblocks;
  169. if (nb < mp->m_sb.sb_dblocks)
  170. return XFS_ERROR(EINVAL);
  171. }
  172. new = nb - mp->m_sb.sb_dblocks;
  173. oagcount = mp->m_sb.sb_agcount;
  174. if (nagcount > oagcount) {
  175. down_write(&mp->m_peraglock);
  176. mp->m_perag = kmem_realloc(mp->m_perag,
  177. sizeof(xfs_perag_t) * nagcount,
  178. sizeof(xfs_perag_t) * oagcount,
  179. KM_SLEEP);
  180. memset(&mp->m_perag[oagcount], 0,
  181. (nagcount - oagcount) * sizeof(xfs_perag_t));
  182. mp->m_flags |= XFS_MOUNT_32BITINODES;
  183. nagimax = xfs_initialize_perag(mp, nagcount);
  184. up_write(&mp->m_peraglock);
  185. }
  186. tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFS);
  187. if ((error = xfs_trans_reserve(tp, XFS_GROWFS_SPACE_RES(mp),
  188. XFS_GROWDATA_LOG_RES(mp), 0, 0, 0))) {
  189. xfs_trans_cancel(tp, 0);
  190. return error;
  191. }
  192. nfree = 0;
  193. for (agno = nagcount - 1; agno >= oagcount; agno--, new -= agsize) {
  194. /*
  195. * AG freelist header block
  196. */
  197. bp = xfs_buf_get(mp->m_ddev_targp,
  198. XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
  199. XFS_FSS_TO_BB(mp, 1), 0);
  200. agf = XFS_BUF_TO_AGF(bp);
  201. memset(agf, 0, mp->m_sb.sb_sectsize);
  202. INT_SET(agf->agf_magicnum, ARCH_CONVERT, XFS_AGF_MAGIC);
  203. INT_SET(agf->agf_versionnum, ARCH_CONVERT, XFS_AGF_VERSION);
  204. INT_SET(agf->agf_seqno, ARCH_CONVERT, agno);
  205. if (agno == nagcount - 1)
  206. agsize =
  207. nb -
  208. (agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks);
  209. else
  210. agsize = mp->m_sb.sb_agblocks;
  211. INT_SET(agf->agf_length, ARCH_CONVERT, agsize);
  212. INT_SET(agf->agf_roots[XFS_BTNUM_BNOi], ARCH_CONVERT,
  213. XFS_BNO_BLOCK(mp));
  214. INT_SET(agf->agf_roots[XFS_BTNUM_CNTi], ARCH_CONVERT,
  215. XFS_CNT_BLOCK(mp));
  216. INT_SET(agf->agf_levels[XFS_BTNUM_BNOi], ARCH_CONVERT, 1);
  217. INT_SET(agf->agf_levels[XFS_BTNUM_CNTi], ARCH_CONVERT, 1);
  218. agf->agf_flfirst = 0;
  219. INT_SET(agf->agf_fllast, ARCH_CONVERT, XFS_AGFL_SIZE(mp) - 1);
  220. agf->agf_flcount = 0;
  221. tmpsize = agsize - XFS_PREALLOC_BLOCKS(mp);
  222. INT_SET(agf->agf_freeblks, ARCH_CONVERT, tmpsize);
  223. INT_SET(agf->agf_longest, ARCH_CONVERT, tmpsize);
  224. error = xfs_bwrite(mp, bp);
  225. if (error) {
  226. goto error0;
  227. }
  228. /*
  229. * AG inode header block
  230. */
  231. bp = xfs_buf_get(mp->m_ddev_targp,
  232. XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
  233. XFS_FSS_TO_BB(mp, 1), 0);
  234. agi = XFS_BUF_TO_AGI(bp);
  235. memset(agi, 0, mp->m_sb.sb_sectsize);
  236. INT_SET(agi->agi_magicnum, ARCH_CONVERT, XFS_AGI_MAGIC);
  237. INT_SET(agi->agi_versionnum, ARCH_CONVERT, XFS_AGI_VERSION);
  238. INT_SET(agi->agi_seqno, ARCH_CONVERT, agno);
  239. INT_SET(agi->agi_length, ARCH_CONVERT, agsize);
  240. agi->agi_count = 0;
  241. INT_SET(agi->agi_root, ARCH_CONVERT, XFS_IBT_BLOCK(mp));
  242. INT_SET(agi->agi_level, ARCH_CONVERT, 1);
  243. agi->agi_freecount = 0;
  244. INT_SET(agi->agi_newino, ARCH_CONVERT, NULLAGINO);
  245. INT_SET(agi->agi_dirino, ARCH_CONVERT, NULLAGINO);
  246. for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++)
  247. INT_SET(agi->agi_unlinked[bucket], ARCH_CONVERT,
  248. NULLAGINO);
  249. error = xfs_bwrite(mp, bp);
  250. if (error) {
  251. goto error0;
  252. }
  253. /*
  254. * BNO btree root block
  255. */
  256. bp = xfs_buf_get(mp->m_ddev_targp,
  257. XFS_AGB_TO_DADDR(mp, agno, XFS_BNO_BLOCK(mp)),
  258. BTOBB(mp->m_sb.sb_blocksize), 0);
  259. block = XFS_BUF_TO_SBLOCK(bp);
  260. memset(block, 0, mp->m_sb.sb_blocksize);
  261. INT_SET(block->bb_magic, ARCH_CONVERT, XFS_ABTB_MAGIC);
  262. block->bb_level = 0;
  263. INT_SET(block->bb_numrecs, ARCH_CONVERT, 1);
  264. INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK);
  265. INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK);
  266. arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc,
  267. block, 1, mp->m_alloc_mxr[0]);
  268. INT_SET(arec->ar_startblock, ARCH_CONVERT,
  269. XFS_PREALLOC_BLOCKS(mp));
  270. INT_SET(arec->ar_blockcount, ARCH_CONVERT,
  271. agsize - INT_GET(arec->ar_startblock, ARCH_CONVERT));
  272. error = xfs_bwrite(mp, bp);
  273. if (error) {
  274. goto error0;
  275. }
  276. /*
  277. * CNT btree root block
  278. */
  279. bp = xfs_buf_get(mp->m_ddev_targp,
  280. XFS_AGB_TO_DADDR(mp, agno, XFS_CNT_BLOCK(mp)),
  281. BTOBB(mp->m_sb.sb_blocksize), 0);
  282. block = XFS_BUF_TO_SBLOCK(bp);
  283. memset(block, 0, mp->m_sb.sb_blocksize);
  284. INT_SET(block->bb_magic, ARCH_CONVERT, XFS_ABTC_MAGIC);
  285. block->bb_level = 0;
  286. INT_SET(block->bb_numrecs, ARCH_CONVERT, 1);
  287. INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK);
  288. INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK);
  289. arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc,
  290. block, 1, mp->m_alloc_mxr[0]);
  291. INT_SET(arec->ar_startblock, ARCH_CONVERT,
  292. XFS_PREALLOC_BLOCKS(mp));
  293. INT_SET(arec->ar_blockcount, ARCH_CONVERT,
  294. agsize - INT_GET(arec->ar_startblock, ARCH_CONVERT));
  295. nfree += INT_GET(arec->ar_blockcount, ARCH_CONVERT);
  296. error = xfs_bwrite(mp, bp);
  297. if (error) {
  298. goto error0;
  299. }
  300. /*
  301. * INO btree root block
  302. */
  303. bp = xfs_buf_get(mp->m_ddev_targp,
  304. XFS_AGB_TO_DADDR(mp, agno, XFS_IBT_BLOCK(mp)),
  305. BTOBB(mp->m_sb.sb_blocksize), 0);
  306. block = XFS_BUF_TO_SBLOCK(bp);
  307. memset(block, 0, mp->m_sb.sb_blocksize);
  308. INT_SET(block->bb_magic, ARCH_CONVERT, XFS_IBT_MAGIC);
  309. block->bb_level = 0;
  310. block->bb_numrecs = 0;
  311. INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK);
  312. INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK);
  313. error = xfs_bwrite(mp, bp);
  314. if (error) {
  315. goto error0;
  316. }
  317. }
  318. xfs_trans_agblocks_delta(tp, nfree);
  319. /*
  320. * There are new blocks in the old last a.g.
  321. */
  322. if (new) {
  323. /*
  324. * Change the agi length.
  325. */
  326. error = xfs_ialloc_read_agi(mp, tp, agno, &bp);
  327. if (error) {
  328. goto error0;
  329. }
  330. ASSERT(bp);
  331. agi = XFS_BUF_TO_AGI(bp);
  332. INT_MOD(agi->agi_length, ARCH_CONVERT, new);
  333. ASSERT(nagcount == oagcount ||
  334. INT_GET(agi->agi_length, ARCH_CONVERT) ==
  335. mp->m_sb.sb_agblocks);
  336. xfs_ialloc_log_agi(tp, bp, XFS_AGI_LENGTH);
  337. /*
  338. * Change agf length.
  339. */
  340. error = xfs_alloc_read_agf(mp, tp, agno, 0, &bp);
  341. if (error) {
  342. goto error0;
  343. }
  344. ASSERT(bp);
  345. agf = XFS_BUF_TO_AGF(bp);
  346. INT_MOD(agf->agf_length, ARCH_CONVERT, new);
  347. ASSERT(INT_GET(agf->agf_length, ARCH_CONVERT) ==
  348. INT_GET(agi->agi_length, ARCH_CONVERT));
  349. /*
  350. * Free the new space.
  351. */
  352. error = xfs_free_extent(tp, XFS_AGB_TO_FSB(mp, agno,
  353. INT_GET(agf->agf_length, ARCH_CONVERT) - new), new);
  354. if (error) {
  355. goto error0;
  356. }
  357. }
  358. if (nagcount > oagcount)
  359. xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount);
  360. if (nb > mp->m_sb.sb_dblocks)
  361. xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS,
  362. nb - mp->m_sb.sb_dblocks);
  363. if (nfree)
  364. xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, nfree);
  365. if (dpct)
  366. xfs_trans_mod_sb(tp, XFS_TRANS_SB_IMAXPCT, dpct);
  367. error = xfs_trans_commit(tp, 0, NULL);
  368. if (error) {
  369. return error;
  370. }
  371. /* New allocation groups fully initialized, so update mount struct */
  372. if (nagimax)
  373. mp->m_maxagi = nagimax;
  374. if (mp->m_sb.sb_imax_pct) {
  375. __uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
  376. do_div(icount, 100);
  377. mp->m_maxicount = icount << mp->m_sb.sb_inopblog;
  378. } else
  379. mp->m_maxicount = 0;
  380. for (agno = 1; agno < nagcount; agno++) {
  381. error = xfs_read_buf(mp, mp->m_ddev_targp,
  382. XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
  383. XFS_FSS_TO_BB(mp, 1), 0, &bp);
  384. if (error) {
  385. xfs_fs_cmn_err(CE_WARN, mp,
  386. "error %d reading secondary superblock for ag %d",
  387. error, agno);
  388. break;
  389. }
  390. sbp = XFS_BUF_TO_SBP(bp);
  391. xfs_xlatesb(sbp, &mp->m_sb, -1, XFS_SB_ALL_BITS);
  392. /*
  393. * If we get an error writing out the alternate superblocks,
  394. * just issue a warning and continue. The real work is
  395. * already done and committed.
  396. */
  397. if (!(error = xfs_bwrite(mp, bp))) {
  398. continue;
  399. } else {
  400. xfs_fs_cmn_err(CE_WARN, mp,
  401. "write error %d updating secondary superblock for ag %d",
  402. error, agno);
  403. break; /* no point in continuing */
  404. }
  405. }
  406. return 0;
  407. error0:
  408. xfs_trans_cancel(tp, XFS_TRANS_ABORT);
  409. return error;
  410. }
  411. static int
  412. xfs_growfs_log_private(
  413. xfs_mount_t *mp, /* mount point for filesystem */
  414. xfs_growfs_log_t *in) /* growfs log input struct */
  415. {
  416. xfs_extlen_t nb;
  417. nb = in->newblocks;
  418. if (nb < XFS_MIN_LOG_BLOCKS || nb < XFS_B_TO_FSB(mp, XFS_MIN_LOG_BYTES))
  419. return XFS_ERROR(EINVAL);
  420. if (nb == mp->m_sb.sb_logblocks &&
  421. in->isint == (mp->m_sb.sb_logstart != 0))
  422. return XFS_ERROR(EINVAL);
  423. /*
  424. * Moving the log is hard, need new interfaces to sync
  425. * the log first, hold off all activity while moving it.
  426. * Can have shorter or longer log in the same space,
  427. * or transform internal to external log or vice versa.
  428. */
  429. return XFS_ERROR(ENOSYS);
  430. }
  431. /*
  432. * protected versions of growfs function acquire and release locks on the mount
  433. * point - exported through ioctls: XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG,
  434. * XFS_IOC_FSGROWFSRT
  435. */
  436. int
  437. xfs_growfs_data(
  438. xfs_mount_t *mp,
  439. xfs_growfs_data_t *in)
  440. {
  441. int error;
  442. if (!cpsema(&mp->m_growlock))
  443. return XFS_ERROR(EWOULDBLOCK);
  444. error = xfs_growfs_data_private(mp, in);
  445. vsema(&mp->m_growlock);
  446. return error;
  447. }
  448. int
  449. xfs_growfs_log(
  450. xfs_mount_t *mp,
  451. xfs_growfs_log_t *in)
  452. {
  453. int error;
  454. if (!cpsema(&mp->m_growlock))
  455. return XFS_ERROR(EWOULDBLOCK);
  456. error = xfs_growfs_log_private(mp, in);
  457. vsema(&mp->m_growlock);
  458. return error;
  459. }
  460. /*
  461. * exported through ioctl XFS_IOC_FSCOUNTS
  462. */
  463. int
  464. xfs_fs_counts(
  465. xfs_mount_t *mp,
  466. xfs_fsop_counts_t *cnt)
  467. {
  468. unsigned long s;
  469. s = XFS_SB_LOCK(mp);
  470. cnt->freedata = mp->m_sb.sb_fdblocks;
  471. cnt->freertx = mp->m_sb.sb_frextents;
  472. cnt->freeino = mp->m_sb.sb_ifree;
  473. cnt->allocino = mp->m_sb.sb_icount;
  474. XFS_SB_UNLOCK(mp, s);
  475. return 0;
  476. }
  477. /*
  478. * exported through ioctl XFS_IOC_SET_RESBLKS & XFS_IOC_GET_RESBLKS
  479. *
  480. * xfs_reserve_blocks is called to set m_resblks
  481. * in the in-core mount table. The number of unused reserved blocks
  482. * is kept in m_resbls_avail.
  483. *
  484. * Reserve the requested number of blocks if available. Otherwise return
  485. * as many as possible to satisfy the request. The actual number
  486. * reserved are returned in outval
  487. *
  488. * A null inval pointer indicates that only the current reserved blocks
  489. * available should be returned no settings are changed.
  490. */
  491. int
  492. xfs_reserve_blocks(
  493. xfs_mount_t *mp,
  494. __uint64_t *inval,
  495. xfs_fsop_resblks_t *outval)
  496. {
  497. __int64_t lcounter, delta;
  498. __uint64_t request;
  499. unsigned long s;
  500. /* If inval is null, report current values and return */
  501. if (inval == (__uint64_t *)NULL) {
  502. outval->resblks = mp->m_resblks;
  503. outval->resblks_avail = mp->m_resblks_avail;
  504. return(0);
  505. }
  506. request = *inval;
  507. s = XFS_SB_LOCK(mp);
  508. /*
  509. * If our previous reservation was larger than the current value,
  510. * then move any unused blocks back to the free pool.
  511. */
  512. if (mp->m_resblks > request) {
  513. lcounter = mp->m_resblks_avail - request;
  514. if (lcounter > 0) { /* release unused blocks */
  515. mp->m_sb.sb_fdblocks += lcounter;
  516. mp->m_resblks_avail -= lcounter;
  517. }
  518. mp->m_resblks = request;
  519. } else {
  520. delta = request - mp->m_resblks;
  521. lcounter = mp->m_sb.sb_fdblocks - delta;
  522. if (lcounter < 0) {
  523. /* We can't satisfy the request, just get what we can */
  524. mp->m_resblks += mp->m_sb.sb_fdblocks;
  525. mp->m_resblks_avail += mp->m_sb.sb_fdblocks;
  526. mp->m_sb.sb_fdblocks = 0;
  527. } else {
  528. mp->m_sb.sb_fdblocks = lcounter;
  529. mp->m_resblks = request;
  530. mp->m_resblks_avail += delta;
  531. }
  532. }
  533. outval->resblks = mp->m_resblks;
  534. outval->resblks_avail = mp->m_resblks_avail;
  535. XFS_SB_UNLOCK(mp, s);
  536. return(0);
  537. }
  538. int
  539. xfs_fs_goingdown(
  540. xfs_mount_t *mp,
  541. __uint32_t inflags)
  542. {
  543. switch (inflags) {
  544. case XFS_FSOP_GOING_FLAGS_DEFAULT: {
  545. struct vfs *vfsp = XFS_MTOVFS(mp);
  546. struct super_block *sb = freeze_bdev(vfsp->vfs_super->s_bdev);
  547. if (sb) {
  548. xfs_force_shutdown(mp, XFS_FORCE_UMOUNT);
  549. thaw_bdev(sb->s_bdev, sb);
  550. }
  551. break;
  552. }
  553. case XFS_FSOP_GOING_FLAGS_LOGFLUSH:
  554. xfs_force_shutdown(mp, XFS_FORCE_UMOUNT);
  555. break;
  556. case XFS_FSOP_GOING_FLAGS_NOLOGFLUSH:
  557. xfs_force_shutdown(mp, XFS_FORCE_UMOUNT|XFS_LOG_IO_ERROR);
  558. break;
  559. default:
  560. return XFS_ERROR(EINVAL);
  561. }
  562. return 0;
  563. }