xfs_fsops.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * Copyright (c) 2000-2002 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. geo->logsectsize = XFS_SB_VERSION_HASSECTOR(&mp->m_sb) ?
  112. mp->m_sb.sb_logsectsize : BBSIZE;
  113. geo->rtsectsize = mp->m_sb.sb_blocksize;
  114. geo->dirblocksize = mp->m_dirblksize;
  115. }
  116. if (new_version >= 4) {
  117. geo->flags |=
  118. (XFS_SB_VERSION_HASLOGV2(&mp->m_sb) ?
  119. XFS_FSOP_GEOM_FLAGS_LOGV2 : 0);
  120. geo->logsunit = mp->m_sb.sb_logsunit;
  121. }
  122. return 0;
  123. }
  124. static int
  125. xfs_growfs_data_private(
  126. xfs_mount_t *mp, /* mount point for filesystem */
  127. xfs_growfs_data_t *in) /* growfs data input struct */
  128. {
  129. xfs_agf_t *agf;
  130. xfs_agi_t *agi;
  131. xfs_agnumber_t agno;
  132. xfs_extlen_t agsize;
  133. xfs_extlen_t tmpsize;
  134. xfs_alloc_rec_t *arec;
  135. xfs_btree_sblock_t *block;
  136. xfs_buf_t *bp;
  137. int bucket;
  138. int dpct;
  139. int error;
  140. xfs_agnumber_t nagcount;
  141. xfs_agnumber_t nagimax = 0;
  142. xfs_rfsblock_t nb, nb_mod;
  143. xfs_rfsblock_t new;
  144. xfs_rfsblock_t nfree;
  145. xfs_agnumber_t oagcount;
  146. int pct;
  147. xfs_sb_t *sbp;
  148. xfs_trans_t *tp;
  149. nb = in->newblocks;
  150. pct = in->imaxpct;
  151. if (nb < mp->m_sb.sb_dblocks || pct < 0 || pct > 100)
  152. return XFS_ERROR(EINVAL);
  153. dpct = pct - mp->m_sb.sb_imax_pct;
  154. error = xfs_read_buf(mp, mp->m_ddev_targp,
  155. XFS_FSB_TO_BB(mp, nb) - XFS_FSS_TO_BB(mp, 1),
  156. XFS_FSS_TO_BB(mp, 1), 0, &bp);
  157. if (error)
  158. return error;
  159. ASSERT(bp);
  160. xfs_buf_relse(bp);
  161. new = nb; /* use new as a temporary here */
  162. nb_mod = do_div(new, mp->m_sb.sb_agblocks);
  163. nagcount = new + (nb_mod != 0);
  164. if (nb_mod && nb_mod < XFS_MIN_AG_BLOCKS) {
  165. nagcount--;
  166. nb = nagcount * mp->m_sb.sb_agblocks;
  167. if (nb < mp->m_sb.sb_dblocks)
  168. return XFS_ERROR(EINVAL);
  169. }
  170. new = nb - mp->m_sb.sb_dblocks;
  171. oagcount = mp->m_sb.sb_agcount;
  172. if (nagcount > oagcount) {
  173. down_write(&mp->m_peraglock);
  174. mp->m_perag = kmem_realloc(mp->m_perag,
  175. sizeof(xfs_perag_t) * nagcount,
  176. sizeof(xfs_perag_t) * oagcount,
  177. KM_SLEEP);
  178. memset(&mp->m_perag[oagcount], 0,
  179. (nagcount - oagcount) * sizeof(xfs_perag_t));
  180. mp->m_flags |= XFS_MOUNT_32BITINODES;
  181. nagimax = xfs_initialize_perag(mp, nagcount);
  182. up_write(&mp->m_peraglock);
  183. }
  184. tp = xfs_trans_alloc(mp, XFS_TRANS_GROWFS);
  185. if ((error = xfs_trans_reserve(tp, XFS_GROWFS_SPACE_RES(mp),
  186. XFS_GROWDATA_LOG_RES(mp), 0, 0, 0))) {
  187. xfs_trans_cancel(tp, 0);
  188. return error;
  189. }
  190. nfree = 0;
  191. for (agno = nagcount - 1; agno >= oagcount; agno--, new -= agsize) {
  192. /*
  193. * AG freelist header block
  194. */
  195. bp = xfs_buf_get(mp->m_ddev_targp,
  196. XFS_AG_DADDR(mp, agno, XFS_AGF_DADDR(mp)),
  197. XFS_FSS_TO_BB(mp, 1), 0);
  198. agf = XFS_BUF_TO_AGF(bp);
  199. memset(agf, 0, mp->m_sb.sb_sectsize);
  200. INT_SET(agf->agf_magicnum, ARCH_CONVERT, XFS_AGF_MAGIC);
  201. INT_SET(agf->agf_versionnum, ARCH_CONVERT, XFS_AGF_VERSION);
  202. INT_SET(agf->agf_seqno, ARCH_CONVERT, agno);
  203. if (agno == nagcount - 1)
  204. agsize =
  205. nb -
  206. (agno * (xfs_rfsblock_t)mp->m_sb.sb_agblocks);
  207. else
  208. agsize = mp->m_sb.sb_agblocks;
  209. INT_SET(agf->agf_length, ARCH_CONVERT, agsize);
  210. INT_SET(agf->agf_roots[XFS_BTNUM_BNOi], ARCH_CONVERT,
  211. XFS_BNO_BLOCK(mp));
  212. INT_SET(agf->agf_roots[XFS_BTNUM_CNTi], ARCH_CONVERT,
  213. XFS_CNT_BLOCK(mp));
  214. INT_SET(agf->agf_levels[XFS_BTNUM_BNOi], ARCH_CONVERT, 1);
  215. INT_SET(agf->agf_levels[XFS_BTNUM_CNTi], ARCH_CONVERT, 1);
  216. agf->agf_flfirst = 0;
  217. INT_SET(agf->agf_fllast, ARCH_CONVERT, XFS_AGFL_SIZE(mp) - 1);
  218. agf->agf_flcount = 0;
  219. tmpsize = agsize - XFS_PREALLOC_BLOCKS(mp);
  220. INT_SET(agf->agf_freeblks, ARCH_CONVERT, tmpsize);
  221. INT_SET(agf->agf_longest, ARCH_CONVERT, tmpsize);
  222. error = xfs_bwrite(mp, bp);
  223. if (error) {
  224. goto error0;
  225. }
  226. /*
  227. * AG inode header block
  228. */
  229. bp = xfs_buf_get(mp->m_ddev_targp,
  230. XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
  231. XFS_FSS_TO_BB(mp, 1), 0);
  232. agi = XFS_BUF_TO_AGI(bp);
  233. memset(agi, 0, mp->m_sb.sb_sectsize);
  234. INT_SET(agi->agi_magicnum, ARCH_CONVERT, XFS_AGI_MAGIC);
  235. INT_SET(agi->agi_versionnum, ARCH_CONVERT, XFS_AGI_VERSION);
  236. INT_SET(agi->agi_seqno, ARCH_CONVERT, agno);
  237. INT_SET(agi->agi_length, ARCH_CONVERT, agsize);
  238. agi->agi_count = 0;
  239. INT_SET(agi->agi_root, ARCH_CONVERT, XFS_IBT_BLOCK(mp));
  240. INT_SET(agi->agi_level, ARCH_CONVERT, 1);
  241. agi->agi_freecount = 0;
  242. INT_SET(agi->agi_newino, ARCH_CONVERT, NULLAGINO);
  243. INT_SET(agi->agi_dirino, ARCH_CONVERT, NULLAGINO);
  244. for (bucket = 0; bucket < XFS_AGI_UNLINKED_BUCKETS; bucket++)
  245. INT_SET(agi->agi_unlinked[bucket], ARCH_CONVERT,
  246. NULLAGINO);
  247. error = xfs_bwrite(mp, bp);
  248. if (error) {
  249. goto error0;
  250. }
  251. /*
  252. * BNO btree root block
  253. */
  254. bp = xfs_buf_get(mp->m_ddev_targp,
  255. XFS_AGB_TO_DADDR(mp, agno, XFS_BNO_BLOCK(mp)),
  256. BTOBB(mp->m_sb.sb_blocksize), 0);
  257. block = XFS_BUF_TO_SBLOCK(bp);
  258. memset(block, 0, mp->m_sb.sb_blocksize);
  259. INT_SET(block->bb_magic, ARCH_CONVERT, XFS_ABTB_MAGIC);
  260. block->bb_level = 0;
  261. INT_SET(block->bb_numrecs, ARCH_CONVERT, 1);
  262. INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK);
  263. INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK);
  264. arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc,
  265. block, 1, mp->m_alloc_mxr[0]);
  266. INT_SET(arec->ar_startblock, ARCH_CONVERT,
  267. XFS_PREALLOC_BLOCKS(mp));
  268. INT_SET(arec->ar_blockcount, ARCH_CONVERT,
  269. agsize - INT_GET(arec->ar_startblock, ARCH_CONVERT));
  270. error = xfs_bwrite(mp, bp);
  271. if (error) {
  272. goto error0;
  273. }
  274. /*
  275. * CNT btree root block
  276. */
  277. bp = xfs_buf_get(mp->m_ddev_targp,
  278. XFS_AGB_TO_DADDR(mp, agno, XFS_CNT_BLOCK(mp)),
  279. BTOBB(mp->m_sb.sb_blocksize), 0);
  280. block = XFS_BUF_TO_SBLOCK(bp);
  281. memset(block, 0, mp->m_sb.sb_blocksize);
  282. INT_SET(block->bb_magic, ARCH_CONVERT, XFS_ABTC_MAGIC);
  283. block->bb_level = 0;
  284. INT_SET(block->bb_numrecs, ARCH_CONVERT, 1);
  285. INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK);
  286. INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK);
  287. arec = XFS_BTREE_REC_ADDR(mp->m_sb.sb_blocksize, xfs_alloc,
  288. block, 1, mp->m_alloc_mxr[0]);
  289. INT_SET(arec->ar_startblock, ARCH_CONVERT,
  290. XFS_PREALLOC_BLOCKS(mp));
  291. INT_SET(arec->ar_blockcount, ARCH_CONVERT,
  292. agsize - INT_GET(arec->ar_startblock, ARCH_CONVERT));
  293. nfree += INT_GET(arec->ar_blockcount, ARCH_CONVERT);
  294. error = xfs_bwrite(mp, bp);
  295. if (error) {
  296. goto error0;
  297. }
  298. /*
  299. * INO btree root block
  300. */
  301. bp = xfs_buf_get(mp->m_ddev_targp,
  302. XFS_AGB_TO_DADDR(mp, agno, XFS_IBT_BLOCK(mp)),
  303. BTOBB(mp->m_sb.sb_blocksize), 0);
  304. block = XFS_BUF_TO_SBLOCK(bp);
  305. memset(block, 0, mp->m_sb.sb_blocksize);
  306. INT_SET(block->bb_magic, ARCH_CONVERT, XFS_IBT_MAGIC);
  307. block->bb_level = 0;
  308. block->bb_numrecs = 0;
  309. INT_SET(block->bb_leftsib, ARCH_CONVERT, NULLAGBLOCK);
  310. INT_SET(block->bb_rightsib, ARCH_CONVERT, NULLAGBLOCK);
  311. error = xfs_bwrite(mp, bp);
  312. if (error) {
  313. goto error0;
  314. }
  315. }
  316. xfs_trans_agblocks_delta(tp, nfree);
  317. /*
  318. * There are new blocks in the old last a.g.
  319. */
  320. if (new) {
  321. /*
  322. * Change the agi length.
  323. */
  324. error = xfs_ialloc_read_agi(mp, tp, agno, &bp);
  325. if (error) {
  326. goto error0;
  327. }
  328. ASSERT(bp);
  329. agi = XFS_BUF_TO_AGI(bp);
  330. INT_MOD(agi->agi_length, ARCH_CONVERT, new);
  331. ASSERT(nagcount == oagcount ||
  332. INT_GET(agi->agi_length, ARCH_CONVERT) ==
  333. mp->m_sb.sb_agblocks);
  334. xfs_ialloc_log_agi(tp, bp, XFS_AGI_LENGTH);
  335. /*
  336. * Change agf length.
  337. */
  338. error = xfs_alloc_read_agf(mp, tp, agno, 0, &bp);
  339. if (error) {
  340. goto error0;
  341. }
  342. ASSERT(bp);
  343. agf = XFS_BUF_TO_AGF(bp);
  344. INT_MOD(agf->agf_length, ARCH_CONVERT, new);
  345. ASSERT(INT_GET(agf->agf_length, ARCH_CONVERT) ==
  346. INT_GET(agi->agi_length, ARCH_CONVERT));
  347. /*
  348. * Free the new space.
  349. */
  350. error = xfs_free_extent(tp, XFS_AGB_TO_FSB(mp, agno,
  351. INT_GET(agf->agf_length, ARCH_CONVERT) - new), new);
  352. if (error) {
  353. goto error0;
  354. }
  355. }
  356. if (nagcount > oagcount)
  357. xfs_trans_mod_sb(tp, XFS_TRANS_SB_AGCOUNT, nagcount - oagcount);
  358. if (nb > mp->m_sb.sb_dblocks)
  359. xfs_trans_mod_sb(tp, XFS_TRANS_SB_DBLOCKS,
  360. nb - mp->m_sb.sb_dblocks);
  361. if (nfree)
  362. xfs_trans_mod_sb(tp, XFS_TRANS_SB_FDBLOCKS, nfree);
  363. if (dpct)
  364. xfs_trans_mod_sb(tp, XFS_TRANS_SB_IMAXPCT, dpct);
  365. error = xfs_trans_commit(tp, 0, NULL);
  366. if (error) {
  367. return error;
  368. }
  369. /* New allocation groups fully initialized, so update mount struct */
  370. if (nagimax)
  371. mp->m_maxagi = nagimax;
  372. if (mp->m_sb.sb_imax_pct) {
  373. __uint64_t icount = mp->m_sb.sb_dblocks * mp->m_sb.sb_imax_pct;
  374. do_div(icount, 100);
  375. mp->m_maxicount = icount << mp->m_sb.sb_inopblog;
  376. } else
  377. mp->m_maxicount = 0;
  378. for (agno = 1; agno < nagcount; agno++) {
  379. error = xfs_read_buf(mp, mp->m_ddev_targp,
  380. XFS_AGB_TO_DADDR(mp, agno, XFS_SB_BLOCK(mp)),
  381. XFS_FSS_TO_BB(mp, 1), 0, &bp);
  382. if (error) {
  383. xfs_fs_cmn_err(CE_WARN, mp,
  384. "error %d reading secondary superblock for ag %d",
  385. error, agno);
  386. break;
  387. }
  388. sbp = XFS_BUF_TO_SBP(bp);
  389. xfs_xlatesb(sbp, &mp->m_sb, -1, XFS_SB_ALL_BITS);
  390. /*
  391. * If we get an error writing out the alternate superblocks,
  392. * just issue a warning and continue. The real work is
  393. * already done and committed.
  394. */
  395. if (!(error = xfs_bwrite(mp, bp))) {
  396. continue;
  397. } else {
  398. xfs_fs_cmn_err(CE_WARN, mp,
  399. "write error %d updating secondary superblock for ag %d",
  400. error, agno);
  401. break; /* no point in continuing */
  402. }
  403. }
  404. return 0;
  405. error0:
  406. xfs_trans_cancel(tp, XFS_TRANS_ABORT);
  407. return error;
  408. }
  409. static int
  410. xfs_growfs_log_private(
  411. xfs_mount_t *mp, /* mount point for filesystem */
  412. xfs_growfs_log_t *in) /* growfs log input struct */
  413. {
  414. xfs_extlen_t nb;
  415. nb = in->newblocks;
  416. if (nb < XFS_MIN_LOG_BLOCKS || nb < XFS_B_TO_FSB(mp, XFS_MIN_LOG_BYTES))
  417. return XFS_ERROR(EINVAL);
  418. if (nb == mp->m_sb.sb_logblocks &&
  419. in->isint == (mp->m_sb.sb_logstart != 0))
  420. return XFS_ERROR(EINVAL);
  421. /*
  422. * Moving the log is hard, need new interfaces to sync
  423. * the log first, hold off all activity while moving it.
  424. * Can have shorter or longer log in the same space,
  425. * or transform internal to external log or vice versa.
  426. */
  427. return XFS_ERROR(ENOSYS);
  428. }
  429. /*
  430. * protected versions of growfs function acquire and release locks on the mount
  431. * point - exported through ioctls: XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG,
  432. * XFS_IOC_FSGROWFSRT
  433. */
  434. int
  435. xfs_growfs_data(
  436. xfs_mount_t *mp,
  437. xfs_growfs_data_t *in)
  438. {
  439. int error;
  440. if (!cpsema(&mp->m_growlock))
  441. return XFS_ERROR(EWOULDBLOCK);
  442. error = xfs_growfs_data_private(mp, in);
  443. vsema(&mp->m_growlock);
  444. return error;
  445. }
  446. int
  447. xfs_growfs_log(
  448. xfs_mount_t *mp,
  449. xfs_growfs_log_t *in)
  450. {
  451. int error;
  452. if (!cpsema(&mp->m_growlock))
  453. return XFS_ERROR(EWOULDBLOCK);
  454. error = xfs_growfs_log_private(mp, in);
  455. vsema(&mp->m_growlock);
  456. return error;
  457. }
  458. /*
  459. * exported through ioctl XFS_IOC_FSCOUNTS
  460. */
  461. int
  462. xfs_fs_counts(
  463. xfs_mount_t *mp,
  464. xfs_fsop_counts_t *cnt)
  465. {
  466. unsigned long s;
  467. s = XFS_SB_LOCK(mp);
  468. cnt->freedata = mp->m_sb.sb_fdblocks;
  469. cnt->freertx = mp->m_sb.sb_frextents;
  470. cnt->freeino = mp->m_sb.sb_ifree;
  471. cnt->allocino = mp->m_sb.sb_icount;
  472. XFS_SB_UNLOCK(mp, s);
  473. return 0;
  474. }
  475. /*
  476. * exported through ioctl XFS_IOC_SET_RESBLKS & XFS_IOC_GET_RESBLKS
  477. *
  478. * xfs_reserve_blocks is called to set m_resblks
  479. * in the in-core mount table. The number of unused reserved blocks
  480. * is kept in m_resbls_avail.
  481. *
  482. * Reserve the requested number of blocks if available. Otherwise return
  483. * as many as possible to satisfy the request. The actual number
  484. * reserved are returned in outval
  485. *
  486. * A null inval pointer indicates that only the current reserved blocks
  487. * available should be returned no settings are changed.
  488. */
  489. int
  490. xfs_reserve_blocks(
  491. xfs_mount_t *mp,
  492. __uint64_t *inval,
  493. xfs_fsop_resblks_t *outval)
  494. {
  495. __int64_t lcounter, delta;
  496. __uint64_t request;
  497. unsigned long s;
  498. /* If inval is null, report current values and return */
  499. if (inval == (__uint64_t *)NULL) {
  500. outval->resblks = mp->m_resblks;
  501. outval->resblks_avail = mp->m_resblks_avail;
  502. return(0);
  503. }
  504. request = *inval;
  505. s = XFS_SB_LOCK(mp);
  506. /*
  507. * If our previous reservation was larger than the current value,
  508. * then move any unused blocks back to the free pool.
  509. */
  510. if (mp->m_resblks > request) {
  511. lcounter = mp->m_resblks_avail - request;
  512. if (lcounter > 0) { /* release unused blocks */
  513. mp->m_sb.sb_fdblocks += lcounter;
  514. mp->m_resblks_avail -= lcounter;
  515. }
  516. mp->m_resblks = request;
  517. } else {
  518. delta = request - mp->m_resblks;
  519. lcounter = mp->m_sb.sb_fdblocks - delta;
  520. if (lcounter < 0) {
  521. /* We can't satisfy the request, just get what we can */
  522. mp->m_resblks += mp->m_sb.sb_fdblocks;
  523. mp->m_resblks_avail += mp->m_sb.sb_fdblocks;
  524. mp->m_sb.sb_fdblocks = 0;
  525. } else {
  526. mp->m_sb.sb_fdblocks = lcounter;
  527. mp->m_resblks = request;
  528. mp->m_resblks_avail += delta;
  529. }
  530. }
  531. outval->resblks = mp->m_resblks;
  532. outval->resblks_avail = mp->m_resblks_avail;
  533. XFS_SB_UNLOCK(mp, s);
  534. return(0);
  535. }
  536. int
  537. xfs_fs_goingdown(
  538. xfs_mount_t *mp,
  539. __uint32_t inflags)
  540. {
  541. switch (inflags) {
  542. case XFS_FSOP_GOING_FLAGS_DEFAULT: {
  543. struct vfs *vfsp = XFS_MTOVFS(mp);
  544. struct super_block *sb = freeze_bdev(vfsp->vfs_super->s_bdev);
  545. if (sb) {
  546. xfs_force_shutdown(mp, XFS_FORCE_UMOUNT);
  547. thaw_bdev(sb->s_bdev, sb);
  548. }
  549. break;
  550. }
  551. case XFS_FSOP_GOING_FLAGS_LOGFLUSH:
  552. xfs_force_shutdown(mp, XFS_FORCE_UMOUNT);
  553. break;
  554. case XFS_FSOP_GOING_FLAGS_NOLOGFLUSH:
  555. xfs_force_shutdown(mp, XFS_FORCE_UMOUNT|XFS_LOG_IO_ERROR);
  556. break;
  557. default:
  558. return XFS_ERROR(EINVAL);
  559. }
  560. return 0;
  561. }