2
* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
2
* Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
4
4
* This program is free software; you can redistribute it and/or modify it
5
5
* under the terms of version 2 of the GNU General Public License as
6
6
* published by the Free Software Foundation.
8
8
* This program is distributed in the hope that it would be useful, but
9
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
12
* Further, this software is distributed without any warranty that it is
13
13
* free of the rightful claim of any third person regarding infringement
14
14
* or the like. Any license provided herein, whether implied or
15
15
* otherwise, applies only to this software file. Patent licenses, if
16
16
* any, provided herein do not apply to combinations of this program with
17
17
* other software, or any other product whatsoever.
19
19
* You should have received a copy of the GNU General Public License along
20
20
* with this program; if not, write the Free Software Foundation, Inc., 59
21
21
* Temple Place - Suite 330, Boston MA 02111-1307, USA.
23
23
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
24
* Mountain View, CA 94043, or:
28
* For further information regarding this notice, see:
28
* For further information regarding this notice, see:
30
30
* http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
199
198
args.fsbno = XFS_AGB_TO_FSB(args.mp,
200
199
INT_GET(agi->agi_seqno, ARCH_CONVERT), args.agbno);
201
200
if (XFS_SB_VERSION_HASALIGN(&args.mp->m_sb) &&
202
args.mp->m_sb.sb_inoalignmt >=
203
XFS_B_TO_FSBT(args.mp, XFS_INODE_CLUSTER_SIZE(args.mp)))
201
args.mp->m_sb.sb_inoalignmt >=
202
XFS_B_TO_FSBT(args.mp, XFS_INODE_CLUSTER_SIZE(args.mp)))
204
203
args.alignment = args.mp->m_sb.sb_inoalignmt;
206
205
args.alignment = 1;
207
206
if ((error = xfs_alloc_vextent(&args)))
211
210
if (args.fsbno == NULLFSBLOCK) {
253
257
args.mp->m_bsize * blks_per_cluster,
256
ASSERT(!XFS_BUF_GETERROR(fbuf));
260
ASSERT(!XFS_BUF_GETERROR(fbuf));
258
262
* Loop over the inodes in this buffer.
260
INT_SET(dic.di_magic, ARCH_CONVERT, XFS_DINODE_MAGIC);
261
INT_ZERO(dic.di_mode, ARCH_CONVERT);
262
INT_SET(dic.di_version, ARCH_CONVERT, version);
263
INT_ZERO(dic.di_format, ARCH_CONVERT);
264
INT_ZERO(dic.di_onlink, ARCH_CONVERT);
265
INT_ZERO(dic.di_uid, ARCH_CONVERT);
266
INT_ZERO(dic.di_gid, ARCH_CONVERT);
267
INT_ZERO(dic.di_nlink, ARCH_CONVERT);
268
INT_ZERO(dic.di_projid, ARCH_CONVERT);
269
bzero(&(dic.di_pad[0]),sizeof(dic.di_pad));
270
INT_SET(dic.di_atime.t_sec, ARCH_CONVERT, ztime.t_sec);
271
INT_SET(dic.di_atime.t_nsec, ARCH_CONVERT, ztime.t_nsec);
273
INT_SET(dic.di_mtime.t_sec, ARCH_CONVERT, ztime.t_sec);
274
INT_SET(dic.di_mtime.t_nsec, ARCH_CONVERT, ztime.t_nsec);
276
INT_SET(dic.di_ctime.t_sec, ARCH_CONVERT, ztime.t_sec);
277
INT_SET(dic.di_ctime.t_nsec, ARCH_CONVERT, ztime.t_nsec);
279
INT_ZERO(dic.di_size, ARCH_CONVERT);
280
INT_ZERO(dic.di_nblocks, ARCH_CONVERT);
281
INT_ZERO(dic.di_extsize, ARCH_CONVERT);
282
INT_ZERO(dic.di_nextents, ARCH_CONVERT);
283
INT_ZERO(dic.di_anextents, ARCH_CONVERT);
284
INT_ZERO(dic.di_forkoff, ARCH_CONVERT);
285
INT_ZERO(dic.di_aformat, ARCH_CONVERT);
286
INT_ZERO(dic.di_dmevmask, ARCH_CONVERT);
287
INT_ZERO(dic.di_dmstate, ARCH_CONVERT);
288
INT_ZERO(dic.di_flags, ARCH_CONVERT);
289
INT_ZERO(dic.di_gen, ARCH_CONVERT);
291
265
for (i = 0; i < ninodes; i++) {
292
266
free = XFS_MAKE_IPTR(args.mp, fbuf, i);
293
bcopy (&dic, &(free->di_core), sizeof(xfs_dinode_core_t));
294
INT_SET(free->di_next_unlinked, ARCH_CONVERT, NULLAGINO);
267
memcpy(&(free->di_core), &dic, sizeof(xfs_dinode_core_t));
268
INT_SET(free->di_next_unlinked, ARCH_CONVERT, NULLAGINO);
295
269
xfs_ialloc_log_di(tp, fbuf, i,
296
270
XFS_DI_CORE_BITS | XFS_DI_NEXT_UNLINKED);
300
274
INT_MOD(agi->agi_count, ARCH_CONVERT, newlen);
301
275
INT_MOD(agi->agi_freecount, ARCH_CONVERT, newlen);
302
mraccess(&args.mp->m_peraglock);
276
down_read(&args.mp->m_peraglock);
303
277
args.mp->m_perag[INT_GET(agi->agi_seqno, ARCH_CONVERT)].pagi_freecount += newlen;
304
mraccunlock(&args.mp->m_peraglock);
278
up_read(&args.mp->m_peraglock);
305
279
INT_SET(agi->agi_newino, ARCH_CONVERT, newino);
307
281
* Insert records describing the new inode chunk into the btree.
369
358
mp = tp->t_mountp;
370
359
agcount = mp->m_maxagi;
371
360
if (S_ISDIR(mode))
372
pagno = atomicIncWithWrap((int *)&mp->m_agirotor, agcount);
361
pagno = xfs_ialloc_next_ag(mp);
374
363
pagno = XFS_INO_TO_AGNO(mp, parent);
364
if (pagno >= agcount)
375
367
ASSERT(pagno < agcount);
377
369
* Loop through allocation groups, looking for one with a little
378
370
* free space in it. Note we don't look for free inodes, exactly.
379
371
* Instead, we include whether there is a need to allocate inodes
380
* to mean that blocks must be allocated for them,
372
* to mean that blocks must be allocated for them,
381
373
* if none are currently free.
384
376
flags = XFS_ALLOC_FLAG_TRYLOCK;
377
down_read(&mp->m_peraglock);
386
mraccess(&mp->m_peraglock);
387
379
pag = &mp->m_perag[agno];
388
380
if (!pag->pagi_init) {
389
381
if (xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
391
mraccunlock(&mp->m_peraglock);
397
388
if (!pag->pagi_inodeok) {
398
atomicIncWithWrap((int *)&mp->m_agirotor, agcount);
389
xfs_ialloc_next_ag(mp);
399
390
goto unlock_nextag;
423
413
if (agbp == NULL &&
424
414
xfs_ialloc_read_agi(mp, tp, agno, &agbp)) {
426
mraccunlock(&mp->m_peraglock);
429
mraccunlock(&mp->m_peraglock);
418
up_read(&mp->m_peraglock);
434
mraccunlock(&mp->m_peraglock);
436
424
xfs_trans_brelse(tp, agbp);
439
427
* No point in iterating over the rest, if we're shutting
442
if (XFS_FORCED_SHUTDOWN(mp))
430
if (XFS_FORCED_SHUTDOWN(mp)) {
431
up_read(&mp->m_peraglock);
443
432
return (xfs_buf_t *)0;
447
437
if (agno == pagno) {
439
up_read(&mp->m_peraglock);
449
440
return (xfs_buf_t *)0;
456
448
* Visible inode allocation functions.
467
459
* allocation to make more free inodes. On the first call,
468
460
* IO_agbp should be set to NULL. If an inode is available,
469
461
* i.e., xfs_dialloc() did not need to do an allocation, an inode
470
* number is returned. In this case, IO_agbp would be set to the
462
* number is returned. In this case, IO_agbp would be set to the
471
463
* current ag_buf and alloc_done set to false.
472
464
* If an allocation needed to be done, xfs_dialloc would return
473
465
* the current ag_buf in IO_agbp and set alloc_done to true.
611
603
*inop = NULLFSINO;
612
604
return noroom ? ENOSPC : 0;
614
mraccess(&mp->m_peraglock);
606
down_read(&mp->m_peraglock);
615
607
if (mp->m_perag[tagno].pagi_inodeok == 0) {
616
mraccunlock(&mp->m_peraglock);
608
up_read(&mp->m_peraglock);
619
611
error = xfs_ialloc_read_agi(mp, tp, tagno, &agbp);
620
mraccunlock(&mp->m_peraglock);
612
up_read(&mp->m_peraglock);
623
615
agi = XFS_BUF_TO_AGI(agbp);
866
858
INT_MOD(agi->agi_freecount, ARCH_CONVERT, -1);
867
859
xfs_ialloc_log_agi(tp, agbp, XFS_AGI_FREECOUNT);
868
mraccess(&mp->m_peraglock);
860
down_read(&mp->m_peraglock);
869
861
mp->m_perag[tagno].pagi_freecount--;
870
mraccunlock(&mp->m_peraglock);
862
up_read(&mp->m_peraglock);
872
864
if (cur->bc_nlevels == 1) {
873
865
int freecount = 0;
939
931
if (agno >= mp->m_sb.sb_agcount || agbno >= mp->m_sb.sb_agblocks ||
940
932
ino != XFS_AGINO_TO_INO(mp, agno, agino)) {
942
if (agno >= mp->m_sb.sb_agcount) {
934
if (agno >= mp->m_sb.sb_agcount) {
943
935
xfs_fs_cmn_err(CE_ALERT, mp,
944
936
"xfs_dilocate: agno (%d) >= "
945
937
"mp->m_sb.sb_agcount (%d)",
985
977
offset_agbno = agbno & mp->m_inoalign_mask;
986
978
chunk_agbno = agbno - offset_agbno;
988
mraccess(&mp->m_peraglock);
980
down_read(&mp->m_peraglock);
989
981
error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
990
mraccunlock(&mp->m_peraglock);
982
up_read(&mp->m_peraglock);
993
985
xfs_fs_cmn_err(CE_ALERT, mp, "xfs_dilocate: "
1122
1113
xfs_agi_t *agi; /* allocation group header */
1123
1114
int agi_ok; /* agi is consistent */
1124
1115
xfs_buf_t *bp; /* allocation group hdr buf */
1125
xfs_daddr_t d; /* disk block address */
1116
xfs_perag_t *pag; /* per allocation group data */
1130
xfs_perag_t *pag; /* per allocation group data */
1133
1119
ASSERT(agno != NULLAGNUMBER);
1134
d = XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR);
1135
if ((error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp, d, 1, 0, &bp)))
1120
error = xfs_trans_read_buf(
1121
mp, tp, mp->m_ddev_targp,
1122
XFS_AG_DADDR(mp, agno, XFS_AGI_DADDR(mp)),
1123
XFS_FSS_TO_BB(mp, 1), 0, &bp);
1137
1126
ASSERT(bp && !XFS_BUF_GETERROR(bp));
1139
1129
* Validate the magic number of the agi block.
1141
1131
agi = XFS_BUF_TO_AGI(bp);
1143
1133
INT_GET(agi->agi_magicnum, ARCH_CONVERT) == XFS_AGI_MAGIC &&
1144
XFS_AGI_GOOD_VERSION(INT_GET(agi->agi_versionnum, ARCH_CONVERT));
1145
if (XFS_TEST_ERROR(!agi_ok, mp, XFS_ERRTAG_IALLOC_READ_AGI,
1146
XFS_RANDOM_IALLOC_READ_AGI)) {
1134
XFS_AGI_GOOD_VERSION(
1135
INT_GET(agi->agi_versionnum, ARCH_CONVERT));
1136
if (unlikely(XFS_TEST_ERROR(!agi_ok, mp, XFS_ERRTAG_IALLOC_READ_AGI,
1137
XFS_RANDOM_IALLOC_READ_AGI))) {
1138
XFS_CORRUPTION_ERROR("xfs_ialloc_read_agi", XFS_ERRLEVEL_LOW,
1147
1140
xfs_trans_brelse(tp, bp);
1148
#ifdef __KERNEL__ /* additional, temporary, debugging code */
1150
"EFSCORRUPTED returned from file %s line %d",
1151
__FILE__, __LINE__);
1153
1141
return XFS_ERROR(EFSCORRUPTED);
1155
1143
pag = &mp->m_perag[agno];
1161
1149
* It's possible for these to be out of sync if
1162
1150
* we are in the middle of a forced shutdown.
1164
ASSERT(pag->pagi_freecount == INT_GET(agi->agi_freecount, ARCH_CONVERT)
1152
ASSERT(pag->pagi_freecount ==
1153
INT_GET(agi->agi_freecount, ARCH_CONVERT)
1165
1154
|| XFS_FORCED_SHUTDOWN(mp));
1168
for (i = 0; i < XFS_AGI_UNLINKED_BUCKETS; i++)
1169
ASSERT(INT_GET(agi->agi_unlinked[i], ARCH_CONVERT) != 0);
1161
for (i = 0; i < XFS_AGI_UNLINKED_BUCKETS; i++)
1162
ASSERT(!INT_ISZERO(agi->agi_unlinked[i], ARCH_CONVERT));
1171
1166
XFS_BUF_SET_VTYPE_REF(bp, B_FS_AGI, XFS_AGI_REF);