Lines Matching +full:int +full:- +full:fwd +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) International Business Machines Corp., 2000-2004
51 #define IAGFREE_LOCK_INIT(imap) mutex_init(&imap->im_freelock)
52 #define IAGFREE_LOCK(imap) mutex_lock(&imap->im_freelock)
53 #define IAGFREE_UNLOCK(imap) mutex_unlock(&imap->im_freelock)
56 #define AG_LOCK_INIT(imap,index) mutex_init(&(imap->im_aglock[index]))
57 #define AG_LOCK(imap,agno) mutex_lock(&imap->im_aglock[agno])
58 #define AG_UNLOCK(imap,agno) mutex_unlock(&imap->im_aglock[agno])
63 static int diAllocAG(struct inomap *, int, bool, struct inode *);
64 static int diAllocAny(struct inomap *, int, bool, struct inode *);
65 static int diAllocBit(struct inomap *, struct iag *, int);
66 static int diAllocExt(struct inomap *, int, struct inode *);
67 static int diAllocIno(struct inomap *, int, struct inode *);
68 static int diFindFree(u32, int);
69 static int diNewExt(struct inomap *, struct iag *, int);
70 static int diNewIAG(struct inomap *, int *, int, struct metapage **);
71 static void duplicateIXtree(struct super_block *, s64, int, s64 *);
73 static int diIAGRead(struct inomap * imap, int, struct metapage **);
74 static int copy_from_dinode(struct dinode *, struct inode *);
87 * ipimap - pointer to inode map inode for the aggregate or fileset.
90 * 0 - success
91 * -ENOMEM - insufficient free virtual memory.
92 * -EIO - i/o error.
94 int diMount(struct inode *ipimap) in diMount()
98 int index; in diMount()
102 * allocate/initialize the in-memory inode map control structure in diMount()
104 /* allocate the in-memory inode map control structure. */ in diMount()
107 return -ENOMEM; in diMount()
109 /* read the on-disk inode map control structure. */ in diMount()
112 IMAPBLKNO << JFS_SBI(ipimap->i_sb)->l2nbperpage, in diMount()
116 return -EIO; in diMount()
119 /* copy the on-disk version to the in-memory version. */ in diMount()
120 dinom_le = (struct dinomap_disk *) mp->data; in diMount()
121 imap->im_freeiag = le32_to_cpu(dinom_le->in_freeiag); in diMount()
122 imap->im_nextiag = le32_to_cpu(dinom_le->in_nextiag); in diMount()
123 atomic_set(&imap->im_numinos, le32_to_cpu(dinom_le->in_numinos)); in diMount()
124 atomic_set(&imap->im_numfree, le32_to_cpu(dinom_le->in_numfree)); in diMount()
125 imap->im_nbperiext = le32_to_cpu(dinom_le->in_nbperiext); in diMount()
126 imap->im_l2nbperiext = le32_to_cpu(dinom_le->in_l2nbperiext); in diMount()
128 imap->im_agctl[index].inofree = in diMount()
129 le32_to_cpu(dinom_le->in_agctl[index].inofree); in diMount()
130 imap->im_agctl[index].extfree = in diMount()
131 le32_to_cpu(dinom_le->in_agctl[index].extfree); in diMount()
132 imap->im_agctl[index].numinos = in diMount()
133 le32_to_cpu(dinom_le->in_agctl[index].numinos); in diMount()
134 imap->im_agctl[index].numfree = in diMount()
135 le32_to_cpu(dinom_le->in_agctl[index].numfree); in diMount()
155 imap->im_ipimap = ipimap; in diMount()
156 JFS_IP(ipimap)->i_imap = imap; in diMount()
169 * ipimap - pointer to inode map inode for the aggregate or fileset.
172 * 0 - success
173 * -ENOMEM - insufficient free virtual memory.
174 * -EIO - i/o error.
176 int diUnmount(struct inode *ipimap, int mounterror) in diUnmount()
178 struct inomap *imap = JFS_IP(ipimap)->i_imap; in diUnmount()
181 * update the on-disk inode map control structure in diUnmount()
190 truncate_inode_pages(ipimap->i_mapping, 0); in diUnmount()
193 * free in-memory control structure in diUnmount()
196 JFS_IP(ipimap)->i_imap = NULL; in diUnmount()
205 int diSync(struct inode *ipimap) in diSync()
208 struct inomap *imp = JFS_IP(ipimap)->i_imap; in diSync()
210 int index; in diSync()
215 /* read the on-disk inode map control structure */ in diSync()
217 IMAPBLKNO << JFS_SBI(ipimap->i_sb)->l2nbperpage, in diSync()
221 return -EIO; in diSync()
224 /* copy the in-memory version to the on-disk version */ in diSync()
225 dinom_le = (struct dinomap_disk *) mp->data; in diSync()
226 dinom_le->in_freeiag = cpu_to_le32(imp->im_freeiag); in diSync()
227 dinom_le->in_nextiag = cpu_to_le32(imp->im_nextiag); in diSync()
228 dinom_le->in_numinos = cpu_to_le32(atomic_read(&imp->im_numinos)); in diSync()
229 dinom_le->in_numfree = cpu_to_le32(atomic_read(&imp->im_numfree)); in diSync()
230 dinom_le->in_nbperiext = cpu_to_le32(imp->im_nbperiext); in diSync()
231 dinom_le->in_l2nbperiext = cpu_to_le32(imp->im_l2nbperiext); in diSync()
233 dinom_le->in_agctl[index].inofree = in diSync()
234 cpu_to_le32(imp->im_agctl[index].inofree); in diSync()
235 dinom_le->in_agctl[index].extfree = in diSync()
236 cpu_to_le32(imp->im_agctl[index].extfree); in diSync()
237 dinom_le->in_agctl[index].numinos = in diSync()
238 cpu_to_le32(imp->im_agctl[index].numinos); in diSync()
239 dinom_le->in_agctl[index].numfree = in diSync()
240 cpu_to_le32(imp->im_agctl[index].numfree); in diSync()
249 filemap_write_and_wait(ipimap->i_mapping); in diSync()
282 * ip - pointer to incore inode to be initialized from disk.
285 * 0 - success
286 * -EIO - i/o error.
287 * -ENOMEM - insufficient memory
290 int diRead(struct inode *ip) in diRead()
292 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diRead()
293 int iagno, ino, extno, rc, agno; in diRead()
300 int block_offset; in diRead()
301 int inodes_left; in diRead()
303 int rel_inode; in diRead()
305 jfs_info("diRead: ino = %ld", ip->i_ino); in diRead()
307 ipimap = sbi->ipimap; in diRead()
308 JFS_IP(ip)->ipimap = ipimap; in diRead()
311 iagno = INOTOIAG(ip->i_ino); in diRead()
315 imap = JFS_IP(ipimap)->i_imap; in diRead()
323 iagp = (struct iag *) mp->data; in diRead()
326 ino = ip->i_ino & (INOSPERIAG - 1); in diRead()
329 if ((lengthPXD(&iagp->inoext[extno]) != imap->im_nbperiext) || in diRead()
330 (addressPXD(&iagp->inoext[extno]) == 0)) { in diRead()
332 return -ESTALE; in diRead()
338 blkno = INOPBLK(&iagp->inoext[extno], ino, sbi->l2nbperpage); in diRead()
341 agstart = le64_to_cpu(iagp->agstart); in diRead()
342 agno = BLKTOAG(agstart, JFS_SBI(ip->i_sb)); in diRead()
346 return -EIO; in diRead()
348 rel_inode = (ino & (INOSPERPAGE - 1)); in diRead()
349 pageno = blkno >> sbi->l2nbperpage; in diRead()
351 if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) { in diRead()
356 (sbi->nbperpage - block_offset) << sbi->l2niperblk; in diRead()
359 rel_inode += block_offset << sbi->l2niperblk; in diRead()
362 rel_inode -= inodes_left; in diRead()
367 mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1); in diRead()
370 return -EIO; in diRead()
374 dp = (struct dinode *) mp->data; in diRead()
377 if (ip->i_ino != le32_to_cpu(dp->di_number)) { in diRead()
378 jfs_error(ip->i_sb, "i_ino != di_number\n"); in diRead()
379 rc = -EIO; in diRead()
380 } else if (le32_to_cpu(dp->di_nlink) == 0) in diRead()
381 rc = -ESTALE; in diRead()
383 /* copy the disk inode to the in-memory inode */ in diRead()
389 JFS_IP(ip)->agstart = agstart; in diRead()
390 JFS_IP(ip)->active_ag = -1; in diRead()
410 * sb - filesystem superblock
411 * inum - aggregate inode number
412 * secondary - 1 if secondary aggregate inode table
415 * new inode - success
416 * NULL - i/o error.
418 struct inode *diReadSpecial(struct super_block *sb, ino_t inum, int secondary) in diReadSpecial()
433 address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage; in diReadSpecial()
434 JFS_IP(ip)->ipimap = sbi->ipaimap2; in diReadSpecial()
437 JFS_IP(ip)->ipimap = sbi->ipaimap; in diReadSpecial()
442 ip->i_ino = inum; in diReadSpecial()
447 mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1); in diReadSpecial()
455 dp = (struct dinode *) (mp->data); in diReadSpecial()
458 /* copy on-disk inode to in-memory inode */ in diReadSpecial()
469 ip->i_mapping->a_ops = &jfs_metapage_aops; in diReadSpecial()
470 mapping_set_gfp_mask(ip->i_mapping, GFP_NOFS); in diReadSpecial()
473 ip->i_flags |= S_NOQUOTA; in diReadSpecial()
475 if ((inum == FILESYSTEM_I) && (JFS_IP(ip)->ipimap == sbi->ipaimap)) { in diReadSpecial()
476 sbi->gengen = le32_to_cpu(dp->di_gengen); in diReadSpecial()
477 sbi->inostamp = le32_to_cpu(dp->di_inostamp); in diReadSpecial()
494 * ip - special inode
495 * secondary - 1 if secondary aggregate inode table
500 void diWriteSpecial(struct inode *ip, int secondary) in diWriteSpecial()
502 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diWriteSpecial()
505 ino_t inum = ip->i_ino; in diWriteSpecial()
509 address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage; in diWriteSpecial()
518 mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1); in diWriteSpecial()
525 dp = (struct dinode *) (mp->data); in diWriteSpecial()
528 /* copy on-disk inode to in-memory inode */ in diWriteSpecial()
530 memcpy(&dp->di_xtroot, &JFS_IP(ip)->i_xtroot, 288); in diWriteSpecial()
533 dp->di_gengen = cpu_to_le32(sbi->gengen); in diWriteSpecial()
550 filemap_write_and_wait(ip->i_mapping); in diFreeSpecial()
551 truncate_inode_pages(ip->i_mapping, 0); in diFreeSpecial()
560 * FUNCTION: write the on-disk inode portion of the in-memory inode
561 * to its corresponding on-disk inode.
574 * tid - transacation id
575 * ip - pointer to incore inode to be written to the inode extent.
578 * 0 - success
579 * -EIO - i/o error.
581 int diWrite(tid_t tid, struct inode *ip) in diWrite()
583 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diWrite()
585 int rc = 0; in diWrite()
589 int block_offset; in diWrite()
590 int inodes_left; in diWrite()
593 int rel_inode; in diWrite()
594 int dioffset; in diWrite()
601 int n; in diWrite()
603 ipimap = jfs_ip->ipimap; in diWrite()
605 ino = ip->i_ino & (INOSPERIAG - 1); in diWrite()
607 if (!addressPXD(&(jfs_ip->ixpxd)) || in diWrite()
608 (lengthPXD(&(jfs_ip->ixpxd)) != in diWrite()
609 JFS_IP(ipimap)->i_imap->im_nbperiext)) { in diWrite()
610 jfs_error(ip->i_sb, "ixpxd invalid\n"); in diWrite()
611 return -EIO; in diWrite()
618 blkno = INOPBLK(&(jfs_ip->ixpxd), ino, sbi->l2nbperpage); in diWrite()
620 rel_inode = (ino & (INOSPERPAGE - 1)); in diWrite()
621 pageno = blkno >> sbi->l2nbperpage; in diWrite()
623 if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) { in diWrite()
628 (sbi->nbperpage - block_offset) << sbi->l2niperblk; in diWrite()
631 rel_inode += block_offset << sbi->l2niperblk; in diWrite()
634 rel_inode -= inodes_left; in diWrite()
639 mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1); in diWrite()
641 return -EIO; in diWrite()
644 dp = (struct dinode *) mp->data; in diWrite()
647 dioffset = (ino & (INOSPERPAGE - 1)) << L2DISIZE; in diWrite()
650 * acquire transaction lock on the on-disk inode; in diWrite()
656 dilinelock = (struct linelock *) & ditlck->lock; in diWrite()
659 * copy btree root from in-memory inode to on-disk inode in diWrite()
661 * (tlock is taken from inline B+-tree root in in-memory in diWrite()
662 * inode when the B+-tree root is updated, which is pointed in diWrite()
663 * by jfs_ip->blid as well as being on tx tlock list) in diWrite()
666 * in in-memory inode, where txLog() will log from, and, in diWrite()
671 if (S_ISDIR(ip->i_mode) && (lid = jfs_ip->xtlid)) { in diWrite()
679 jfs_ip->xtlid = 0; in diWrite()
681 assert(tlck->type & tlckXTREE); in diWrite()
682 tlck->type |= tlckBTROOT; in diWrite()
683 tlck->mp = mp; in diWrite()
684 ilinelock = (struct linelock *) & tlck->lock; in diWrite()
689 p = &jfs_ip->i_xtroot; in diWrite()
690 xp = (xtroot_t *) &dp->di_dirtable; in diWrite()
691 lv = ilinelock->lv; in diWrite()
692 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
693 memcpy(&xp->xad[lv->offset], &p->xad[lv->offset], in diWrite()
694 lv->length << L2XTSLOTSIZE); in diWrite()
697 /* reset on-disk (metadata page) xtree XAD_NEW bit */ in diWrite()
698 xad = &xp->xad[XTENTRYSTART]; in diWrite()
700 n < le16_to_cpu(xp->header.nextindex); n++, xad++) in diWrite()
701 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) in diWrite()
702 xad->flag &= ~(XAD_NEW | XAD_EXTENDED); in diWrite()
705 if ((lid = jfs_ip->blid) == 0) in diWrite()
707 jfs_ip->blid = 0; in diWrite()
710 type = tlck->type; in diWrite()
711 tlck->type |= tlckBTROOT; in diWrite()
712 tlck->mp = mp; in diWrite()
713 ilinelock = (struct linelock *) & tlck->lock; in diWrite()
725 p = &jfs_ip->i_xtroot; in diWrite()
726 xp = &dp->di_xtroot; in diWrite()
727 lv = ilinelock->lv; in diWrite()
728 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
729 memcpy(&xp->xad[lv->offset], &p->xad[lv->offset], in diWrite()
730 lv->length << L2XTSLOTSIZE); in diWrite()
733 /* reset on-disk (metadata page) xtree XAD_NEW bit */ in diWrite()
734 xad = &xp->xad[XTENTRYSTART]; in diWrite()
736 n < le16_to_cpu(xp->header.nextindex); n++, xad++) in diWrite()
737 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) in diWrite()
738 xad->flag &= ~(XAD_NEW | XAD_EXTENDED); in diWrite()
749 p = (dtpage_t *) &jfs_ip->i_dtroot; in diWrite()
750 xp = (dtpage_t *) & dp->di_dtroot; in diWrite()
751 lv = ilinelock->lv; in diWrite()
752 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
753 memcpy(&xp->slot[lv->offset], &p->slot[lv->offset], in diWrite()
754 lv->length << L2DTSLOTSIZE); in diWrite()
762 * copy inline symlink from in-memory inode to on-disk inode in diWrite()
764 if (S_ISLNK(ip->i_mode) && ip->i_size < IDATASIZE) { in diWrite()
765 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
766 lv->offset = (dioffset + 2 * 128) >> L2INODESLOTSIZE; in diWrite()
767 lv->length = 2; in diWrite()
768 memcpy(&dp->di_inline_all, jfs_ip->i_inline_all, IDATASIZE); in diWrite()
769 dilinelock->index++; in diWrite()
772 * copy inline data from in-memory inode to on-disk inode: in diWrite()
776 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
777 lv->offset = (dioffset + 3 * 128) >> L2INODESLOTSIZE; in diWrite()
778 lv->length = 1; in diWrite()
779 memcpy(&dp->di_inlineea, jfs_ip->i_inline_ea, INODESLOTSIZE); in diWrite()
780 dilinelock->index++; in diWrite()
788 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
789 lv->offset = dioffset >> L2INODESLOTSIZE; in diWrite()
792 lv->length = 2; in diWrite()
793 memcpy(&dp->di_dirtable, &jfs_ip->i_dirtable, 96); in diWrite()
795 lv->length = 1; in diWrite()
796 dilinelock->index++; in diWrite()
798 /* release the buffer holding the updated on-disk inode. in diWrite()
839 * ip - inode to be freed.
842 * 0 - success
843 * -EIO - i/o error.
845 int diFree(struct inode *ip) in diFree()
847 int rc; in diFree()
848 ino_t inum = ip->i_ino; in diFree()
851 int iagno, ino, extno, bitno, sword, agno; in diFree()
852 int back, fwd; in diFree() local
853 u32 bitmap, mask; in diFree() local
854 struct inode *ipimap = JFS_SBI(ip->i_sb)->ipimap; in diFree()
855 struct inomap *imap = JFS_IP(ipimap)->i_imap; in diFree()
875 if (iagno >= imap->im_nextiag) { in diFree()
878 jfs_error(ip->i_sb, "inum = %d, iagno = %d, nextiag = %d\n", in diFree()
879 (uint) inum, iagno, imap->im_nextiag); in diFree()
880 return -EIO; in diFree()
885 agno = BLKTOAG(JFS_IP(ip)->agstart, JFS_SBI(ip->i_sb)); in diFree()
903 iagp = (struct iag *) mp->data; in diFree()
908 ino = inum & (INOSPERIAG - 1); in diFree()
910 bitno = ino & (INOSPEREXT - 1); in diFree()
911 mask = HIGHORDER >> bitno; in diFree()
913 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diFree()
914 jfs_error(ip->i_sb, "wmap shows inode already free\n"); in diFree()
917 if (!addressPXD(&iagp->inoext[extno])) { in diFree()
921 jfs_error(ip->i_sb, "invalid inoext\n"); in diFree()
922 return -EIO; in diFree()
927 bitmap = le32_to_cpu(iagp->wmap[extno]) & ~mask; in diFree()
929 if (imap->im_agctl[agno].numfree > imap->im_agctl[agno].numinos) { in diFree()
933 jfs_error(ip->i_sb, "numfree > numinos\n"); in diFree()
934 return -EIO; in diFree()
941 imap->im_agctl[agno].numfree < 96 || in diFree()
942 (imap->im_agctl[agno].numfree < 288 && in diFree()
943 (((imap->im_agctl[agno].numfree * 100) / in diFree()
944 imap->im_agctl[agno].numinos) <= 25))) { in diFree()
949 if (iagp->nfreeinos == 0) { in diFree()
955 if ((fwd = imap->im_agctl[agno].inofree) >= 0) { in diFree()
959 if ((rc = diIAGRead(imap, fwd, &amp))) { in diFree()
965 aiagp = (struct iag *) amp->data; in diFree()
969 aiagp->inofreeback = cpu_to_le32(iagno); in diFree()
977 iagp->inofreefwd = in diFree()
978 cpu_to_le32(imap->im_agctl[agno].inofree); in diFree()
979 iagp->inofreeback = cpu_to_le32(-1); in diFree()
980 imap->im_agctl[agno].inofree = iagno; in diFree()
989 if (iagp->wmap[extno] == cpu_to_le32(ONES)) { in diFree()
991 bitno = extno & (EXTSPERSUM - 1); in diFree()
992 iagp->inosmap[sword] &= in diFree()
998 iagp->wmap[extno] = cpu_to_le32(bitmap); in diFree()
1003 le32_add_cpu(&iagp->nfreeinos, 1); in diFree()
1004 imap->im_agctl[agno].numfree += 1; in diFree()
1005 atomic_inc(&imap->im_numfree); in diFree()
1027 fwd = back = -1; in diFree()
1032 if (iagp->nfreeexts == 0) { in diFree()
1039 if ((fwd = imap->im_agctl[agno].extfree) >= 0) { in diFree()
1040 if ((rc = diIAGRead(imap, fwd, &amp))) in diFree()
1042 aiagp = (struct iag *) amp->data; in diFree()
1050 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) { in diFree()
1056 if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) { in diFree()
1057 if ((rc = diIAGRead(imap, fwd, &amp))) in diFree()
1059 aiagp = (struct iag *) amp->data; in diFree()
1062 if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) { in diFree()
1065 biagp = (struct iag *) bmp->data; in diFree()
1073 if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) { in diFree()
1074 int inofreeback = le32_to_cpu(iagp->inofreeback); in diFree()
1075 int inofreefwd = le32_to_cpu(iagp->inofreefwd); in diFree()
1082 * from up above, since re-reading an iag (buffer) in diFree()
1087 if (inofreefwd == fwd) in diFree()
1088 ciagp = (struct iag *) amp->data; in diFree()
1090 ciagp = (struct iag *) bmp->data; in diFree()
1095 ciagp = (struct iag *) cmp->data; in diFree()
1101 if (inofreeback == fwd) in diFree()
1102 diagp = (struct iag *) amp->data; in diFree()
1104 diagp = (struct iag *) bmp->data; in diFree()
1109 diagp = (struct iag *) dmp->data; in diFree()
1120 freepxd = iagp->inoext[extno]; in diFree()
1129 if (iagp->nfreeexts == 0) { in diFree()
1130 if (fwd >= 0) in diFree()
1131 aiagp->extfreeback = cpu_to_le32(iagno); in diFree()
1133 iagp->extfreefwd = in diFree()
1134 cpu_to_le32(imap->im_agctl[agno].extfree); in diFree()
1135 iagp->extfreeback = cpu_to_le32(-1); in diFree()
1136 imap->im_agctl[agno].extfree = iagno; in diFree()
1141 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) { in diFree()
1142 if (fwd >= 0) in diFree()
1143 aiagp->extfreeback = iagp->extfreeback; in diFree()
1146 biagp->extfreefwd = iagp->extfreefwd; in diFree()
1148 imap->im_agctl[agno].extfree = in diFree()
1149 le32_to_cpu(iagp->extfreefwd); in diFree()
1151 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diFree()
1154 iagp->iagfree = cpu_to_le32(imap->im_freeiag); in diFree()
1155 imap->im_freeiag = iagno; in diFree()
1163 if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) { in diFree()
1164 if ((int) le32_to_cpu(iagp->inofreefwd) >= 0) in diFree()
1165 ciagp->inofreeback = iagp->inofreeback; in diFree()
1167 if ((int) le32_to_cpu(iagp->inofreeback) >= 0) in diFree()
1168 diagp->inofreefwd = iagp->inofreefwd; in diFree()
1170 imap->im_agctl[agno].inofree = in diFree()
1171 le32_to_cpu(iagp->inofreefwd); in diFree()
1173 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diFree()
1181 if (iagp->pmap[extno] != 0) { in diFree()
1182 jfs_error(ip->i_sb, "the pmap does not show inode free\n"); in diFree()
1184 iagp->wmap[extno] = 0; in diFree()
1185 PXDlength(&iagp->inoext[extno], 0); in diFree()
1186 PXDaddress(&iagp->inoext[extno], 0); in diFree()
1194 bitno = extno & (EXTSPERSUM - 1); in diFree()
1195 mask = HIGHORDER >> bitno; in diFree()
1196 iagp->inosmap[sword] |= cpu_to_le32(mask); in diFree()
1197 iagp->extsmap[sword] &= cpu_to_le32(~mask); in diFree()
1202 le32_add_cpu(&iagp->nfreeinos, -(INOSPEREXT - 1)); in diFree()
1203 le32_add_cpu(&iagp->nfreeexts, 1); in diFree()
1208 imap->im_agctl[agno].numfree -= (INOSPEREXT - 1); in diFree()
1209 imap->im_agctl[agno].numinos -= INOSPEREXT; in diFree()
1210 atomic_sub(INOSPEREXT - 1, &imap->im_numfree); in diFree()
1211 atomic_sub(INOSPEREXT, &imap->im_numinos); in diFree()
1231 tid = txBegin(ipimap->i_sb, COMMIT_FORCE); in diFree()
1232 mutex_lock(&JFS_IP(ipimap)->commit_mutex); in diFree()
1242 pxdlock = (struct pxd_lock *) & tlck->lock; in diFree()
1243 pxdlock->flag = mlckFREEPXD; in diFree()
1244 pxdlock->pxd = freepxd; in diFree()
1245 pxdlock->index = 1; in diFree()
1265 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diFree()
1296 diInitInode(struct inode *ip, int iagno, int ino, int extno, struct iag * iagp) in diInitInode()
1300 ip->i_ino = (iagno << L2INOSPERIAG) + ino; in diInitInode()
1301 jfs_ip->ixpxd = iagp->inoext[extno]; in diInitInode()
1302 jfs_ip->agstart = le64_to_cpu(iagp->agstart); in diInitInode()
1303 jfs_ip->active_ag = -1; in diInitInode()
1314 * pip - pointer to incore inode for the parent inode.
1315 * dir - 'true' if the new disk inode is for a directory.
1316 * ip - pointer to a new inode
1319 * 0 - success.
1320 * -ENOSPC - insufficient disk resources.
1321 * -EIO - i/o error.
1323 int diAlloc(struct inode *pip, bool dir, struct inode *ip) in diAlloc()
1325 int rc, ino, iagno, addext, extno, bitno, sword; in diAlloc()
1326 int nwords, rem, i, agno, dn_numag; in diAlloc()
1327 u32 mask, inosmap, extsmap; in diAlloc() local
1337 ipimap = JFS_SBI(pip->i_sb)->ipimap; in diAlloc()
1338 imap = JFS_IP(ipimap)->i_imap; in diAlloc()
1339 JFS_IP(ip)->ipimap = ipimap; in diAlloc()
1340 JFS_IP(ip)->fileset = FILESYSTEM_I; in diAlloc()
1346 agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap); in diAlloc()
1355 * hint. (we use a left-to-right policy to attempt to avoid in diAlloc()
1361 agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb)); in diAlloc()
1362 dn_numag = JFS_SBI(pip->i_sb)->bmap->db_numag; in diAlloc()
1364 return -EIO; in diAlloc()
1366 if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) { in diAlloc()
1372 agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap); in diAlloc()
1377 inum = pip->i_ino + 1; in diAlloc()
1378 ino = inum & (INOSPERIAG - 1); in diAlloc()
1382 inum = pip->i_ino; in diAlloc()
1397 iagp = (struct iag *) mp->data; in diAlloc()
1403 addext = (imap->im_agctl[agno].numfree < 32 && iagp->nfreeexts); in diAlloc()
1411 if (iagp->nfreeinos || addext) { in diAlloc()
1419 if (addressPXD(&iagp->inoext[extno])) { in diAlloc()
1420 bitno = ino & (INOSPEREXT - 1); in diAlloc()
1422 diFindFree(le32_to_cpu(iagp->wmap[extno]), in diAlloc()
1433 assert(rc == -EIO); in diAlloc()
1453 EXTSPERIAG - 1) ? 0 : extno + 1; in diAlloc()
1472 bitno = extno & (EXTSPERSUM - 1); in diAlloc()
1476 /* mask any prior bits for the starting words of the in diAlloc()
1479 mask = (bitno == 0) ? 0 : (ONES << (EXTSPERSUM - bitno)); in diAlloc()
1480 inosmap = le32_to_cpu(iagp->inosmap[sword]) | mask; in diAlloc()
1481 extsmap = le32_to_cpu(iagp->extsmap[sword]) | mask; in diAlloc()
1497 rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), in diAlloc()
1503 jfs_error(ip->i_sb, in diAlloc()
1505 return -EIO; in diAlloc()
1516 assert(rc == -EIO); in diAlloc()
1552 if (rc == -ENOSPC) in diAlloc()
1555 assert(rc == -EIO); in diAlloc()
1575 sword = (sword == SMAPSZ - 1) ? 0 : sword + 1; in diAlloc()
1576 inosmap = le32_to_cpu(iagp->inosmap[sword]); in diAlloc()
1577 extsmap = le32_to_cpu(iagp->extsmap[sword]); in diAlloc()
1594 if (rc != -ENOSPC) in diAlloc()
1621 * imap - pointer to inode map control structure.
1622 * agno - allocation group to allocate from.
1623 * dir - 'true' if the new disk inode is for a directory.
1624 * ip - pointer to the new inode to be filled in on successful return
1629 * 0 - success.
1630 * -ENOSPC - insufficient disk resources.
1631 * -EIO - i/o error.
1633 static int
1634 diAllocAG(struct inomap * imap, int agno, bool dir, struct inode *ip) in diAllocAG()
1636 int rc, addext, numfree, numinos; in diAllocAG()
1641 numfree = imap->im_agctl[agno].numfree; in diAllocAG()
1642 numinos = imap->im_agctl[agno].numinos; in diAllocAG()
1645 jfs_error(ip->i_sb, "numfree > numinos\n"); in diAllocAG()
1646 return -EIO; in diAllocAG()
1669 if ((rc = diAllocExt(imap, agno, ip)) != -ENOSPC) in diAllocAG()
1691 * imap - pointer to inode map control structure.
1692 * agno - primary allocation group (to avoid).
1693 * dir - 'true' if the new disk inode is for a directory.
1694 * ip - pointer to a new inode to be filled in on successful return
1699 * 0 - success.
1700 * -ENOSPC - insufficient disk resources.
1701 * -EIO - i/o error.
1703 static int
1704 diAllocAny(struct inomap * imap, int agno, bool dir, struct inode *ip) in diAllocAny()
1706 int ag, rc; in diAllocAny()
1707 int maxag = JFS_SBI(imap->im_ipimap->i_sb)->bmap->db_maxag; in diAllocAny()
1720 if (rc != -ENOSPC) in diAllocAny()
1733 if (rc != -ENOSPC) in diAllocAny()
1739 return -ENOSPC; in diAllocAny()
1757 * imap - pointer to inode map control structure.
1758 * agno - allocation group.
1759 * ip - pointer to new inode to be filled in on successful return
1764 * 0 - success.
1765 * -ENOSPC - insufficient disk resources.
1766 * -EIO - i/o error.
1768 static int diAllocIno(struct inomap * imap, int agno, struct inode *ip) in diAllocIno()
1770 int iagno, ino, rc, rem, extno, sword; in diAllocIno()
1776 if ((iagno = imap->im_agctl[agno].inofree) < 0) in diAllocIno()
1777 return -ENOSPC; in diAllocIno()
1780 IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP); in diAllocIno()
1785 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1788 iagp = (struct iag *) mp->data; in diAllocIno()
1793 if (!iagp->nfreeinos) { in diAllocIno()
1794 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1796 jfs_error(ip->i_sb, "nfreeinos = 0, but iag on freelist\n"); in diAllocIno()
1797 return -EIO; in diAllocIno()
1805 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1807 jfs_error(ip->i_sb, in diAllocIno()
1809 return -EIO; in diAllocIno()
1812 if (~iagp->inosmap[sword]) in diAllocIno()
1819 rem = diFindFree(le32_to_cpu(iagp->inosmap[sword]), 0); in diAllocIno()
1821 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1823 jfs_error(ip->i_sb, "no free extent found\n"); in diAllocIno()
1824 return -EIO; in diAllocIno()
1830 rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), 0); in diAllocIno()
1832 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1834 jfs_error(ip->i_sb, "free inode not found\n"); in diAllocIno()
1835 return -EIO; in diAllocIno()
1845 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1881 * imap - pointer to inode map control structure.
1882 * agno - allocation group number.
1883 * ip - pointer to new inode to be filled in on successful return
1888 * 0 - success.
1889 * -ENOSPC - insufficient disk resources.
1890 * -EIO - i/o error.
1892 static int diAllocExt(struct inomap * imap, int agno, struct inode *ip) in diAllocExt()
1894 int rem, iagno, sword, extno, rc; in diAllocExt()
1901 if ((iagno = imap->im_agctl[agno].extfree) < 0) { in diAllocExt()
1908 iagp = (struct iag *) mp->data; in diAllocExt()
1912 iagp->agstart = in diAllocExt()
1913 cpu_to_le64(AGTOBLK(agno, imap->im_ipimap)); in diAllocExt()
1917 IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP); in diAllocExt()
1919 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1920 jfs_error(ip->i_sb, "error reading iag\n"); in diAllocExt()
1923 iagp = (struct iag *) mp->data; in diAllocExt()
1931 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1932 jfs_error(ip->i_sb, "free ext summary map not found\n"); in diAllocExt()
1933 return -EIO; in diAllocExt()
1935 if (~iagp->extsmap[sword]) in diAllocExt()
1941 rem = diFindFree(le32_to_cpu(iagp->extsmap[sword]), 0); in diAllocExt()
1944 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1945 jfs_error(ip->i_sb, "free extent not found\n"); in diAllocExt()
1946 return -EIO; in diAllocExt()
1953 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1959 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diAllocExt()
1961 iagp->iagfree = cpu_to_le32(imap->im_freeiag); in diAllocExt()
1962 imap->im_freeiag = iagno; in diAllocExt()
2000 * imap - pointer to inode map control structure.
2001 * iagp - pointer to iag.
2002 * ino - inode number to be allocated within the iag.
2005 * 0 - success.
2006 * -ENOSPC - insufficient disk resources.
2007 * -EIO - i/o error.
2009 static int diAllocBit(struct inomap * imap, struct iag * iagp, int ino) in diAllocBit()
2011 int extno, bitno, agno, sword, rc; in diAllocBit()
2014 u32 mask; in diAllocBit() local
2021 if (iagp->nfreeinos == cpu_to_le32(1)) { in diAllocBit()
2022 if ((int) le32_to_cpu(iagp->inofreefwd) >= 0) { in diAllocBit()
2024 diIAGRead(imap, le32_to_cpu(iagp->inofreefwd), in diAllocBit()
2027 aiagp = (struct iag *) amp->data; in diAllocBit()
2030 if ((int) le32_to_cpu(iagp->inofreeback) >= 0) { in diAllocBit()
2033 le32_to_cpu(iagp->inofreeback), in diAllocBit()
2039 biagp = (struct iag *) bmp->data; in diAllocBit()
2046 agno = BLKTOAG(le64_to_cpu(iagp->agstart), JFS_SBI(imap->im_ipimap->i_sb)); in diAllocBit()
2048 bitno = ino & (INOSPEREXT - 1); in diAllocBit()
2050 /* compute the mask for setting the map. in diAllocBit()
2052 mask = HIGHORDER >> bitno; in diAllocBit()
2056 if (((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) || in diAllocBit()
2057 ((le32_to_cpu(iagp->wmap[extno]) & mask) != 0) || in diAllocBit()
2058 (addressPXD(&iagp->inoext[extno]) == 0)) { in diAllocBit()
2064 jfs_error(imap->im_ipimap->i_sb, "iag inconsistent\n"); in diAllocBit()
2065 return -EIO; in diAllocBit()
2070 iagp->wmap[extno] |= cpu_to_le32(mask); in diAllocBit()
2076 if (iagp->wmap[extno] == cpu_to_le32(ONES)) { in diAllocBit()
2078 bitno = extno & (EXTSPERSUM - 1); in diAllocBit()
2079 iagp->inosmap[sword] |= cpu_to_le32(HIGHORDER >> bitno); in diAllocBit()
2085 if (iagp->nfreeinos == cpu_to_le32(1)) { in diAllocBit()
2087 aiagp->inofreeback = iagp->inofreeback; in diAllocBit()
2092 biagp->inofreefwd = iagp->inofreefwd; in diAllocBit()
2095 imap->im_agctl[agno].inofree = in diAllocBit()
2096 le32_to_cpu(iagp->inofreefwd); in diAllocBit()
2098 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diAllocBit()
2104 le32_add_cpu(&iagp->nfreeinos, -1); in diAllocBit()
2105 imap->im_agctl[agno].numfree -= 1; in diAllocBit()
2106 atomic_dec(&imap->im_numfree); in diAllocBit()
2146 * imap - pointer to inode map control structure.
2147 * iagp - pointer to iag.
2148 * extno - extent number.
2151 * 0 - success.
2152 * -ENOSPC - insufficient disk resources.
2153 * -EIO - i/o error.
2155 static int diNewExt(struct inomap * imap, struct iag * iagp, int extno) in diNewExt()
2157 int agno, iagno, fwd, back, freei = 0, sword, rc; in diNewExt() local
2162 int i, j; in diNewExt()
2163 u32 mask; in diNewExt() local
2170 if (!iagp->nfreeexts) { in diNewExt()
2171 jfs_error(imap->im_ipimap->i_sb, "no free extents\n"); in diNewExt()
2172 return -EIO; in diNewExt()
2177 ipimap = imap->im_ipimap; in diNewExt()
2178 sbi = JFS_SBI(ipimap->i_sb); in diNewExt()
2184 agno = BLKTOAG(le64_to_cpu(iagp->agstart), sbi); in diNewExt()
2186 return -EIO; in diNewExt()
2188 iagno = le32_to_cpu(iagp->iagnum); in diNewExt()
2195 if (iagp->nfreeexts == cpu_to_le32(1)) { in diNewExt()
2196 if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) { in diNewExt()
2197 if ((rc = diIAGRead(imap, fwd, &amp))) in diNewExt()
2199 aiagp = (struct iag *) amp->data; in diNewExt()
2202 if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) { in diNewExt()
2205 biagp = (struct iag *) bmp->data; in diNewExt()
2214 fwd = back = -1; in diNewExt()
2215 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diNewExt()
2216 if ((fwd = imap->im_agctl[agno].extfree) >= 0) { in diNewExt()
2217 if ((rc = diIAGRead(imap, fwd, &amp))) in diNewExt()
2219 aiagp = (struct iag *) amp->data; in diNewExt()
2231 if (iagp->nfreeinos == 0) { in diNewExt()
2232 freei = imap->im_agctl[agno].inofree; in diNewExt()
2235 if (freei == fwd) { in diNewExt()
2242 ciagp = (struct iag *) cmp->data; in diNewExt()
2245 jfs_error(imap->im_ipimap->i_sb, in diNewExt()
2247 rc = -EIO; in diNewExt()
2255 if ((extno == 0) || (addressPXD(&iagp->inoext[extno - 1]) == 0)) in diNewExt()
2256 hint = ((s64) agno << sbi->bmap->db_agl2size) - 1; in diNewExt()
2258 hint = addressPXD(&iagp->inoext[extno - 1]) + in diNewExt()
2259 lengthPXD(&iagp->inoext[extno - 1]) - 1; in diNewExt()
2261 if ((rc = dbAlloc(ipimap, hint, (s64) imap->im_nbperiext, &blkno))) in diNewExt()
2272 for (i = 0; i < imap->im_nbperiext; i += sbi->nbperpage) { in diNewExt()
2277 rc = -EIO; in diNewExt()
2280 dp = (struct dinode *) dmp->data; in diNewExt()
2286 dp->di_inostamp = cpu_to_le32(sbi->inostamp); in diNewExt()
2287 dp->di_number = cpu_to_le32(ino); in diNewExt()
2288 dp->di_fileset = cpu_to_le32(FILESYSTEM_I); in diNewExt()
2289 dp->di_mode = 0; in diNewExt()
2290 dp->di_nlink = 0; in diNewExt()
2291 PXDaddress(&(dp->di_ixpxd), blkno); in diNewExt()
2292 PXDlength(&(dp->di_ixpxd), imap->im_nbperiext); in diNewExt()
2300 if (iagp->nfreeexts == cpu_to_le32(1)) { in diNewExt()
2301 if (fwd >= 0) in diNewExt()
2302 aiagp->extfreeback = iagp->extfreeback; in diNewExt()
2305 biagp->extfreefwd = iagp->extfreefwd; in diNewExt()
2307 imap->im_agctl[agno].extfree = in diNewExt()
2308 le32_to_cpu(iagp->extfreefwd); in diNewExt()
2310 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diNewExt()
2315 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diNewExt()
2316 if (fwd >= 0) in diNewExt()
2317 aiagp->extfreeback = cpu_to_le32(iagno); in diNewExt()
2319 iagp->extfreefwd = cpu_to_le32(fwd); in diNewExt()
2320 iagp->extfreeback = cpu_to_le32(-1); in diNewExt()
2321 imap->im_agctl[agno].extfree = iagno; in diNewExt()
2328 if (iagp->nfreeinos == 0) { in diNewExt()
2330 ciagp->inofreeback = cpu_to_le32(iagno); in diNewExt()
2332 iagp->inofreefwd = in diNewExt()
2333 cpu_to_le32(imap->im_agctl[agno].inofree); in diNewExt()
2334 iagp->inofreeback = cpu_to_le32(-1); in diNewExt()
2335 imap->im_agctl[agno].inofree = iagno; in diNewExt()
2339 PXDlength(&iagp->inoext[extno], imap->im_nbperiext); in diNewExt()
2340 PXDaddress(&iagp->inoext[extno], blkno); in diNewExt()
2346 iagp->wmap[extno] = cpu_to_le32(HIGHORDER); in diNewExt()
2347 iagp->pmap[extno] = 0; in diNewExt()
2354 mask = HIGHORDER >> (extno & (EXTSPERSUM - 1)); in diNewExt()
2355 iagp->extsmap[sword] |= cpu_to_le32(mask); in diNewExt()
2356 iagp->inosmap[sword] &= cpu_to_le32(~mask); in diNewExt()
2361 le32_add_cpu(&iagp->nfreeinos, (INOSPEREXT - 1)); in diNewExt()
2362 le32_add_cpu(&iagp->nfreeexts, -1); in diNewExt()
2366 imap->im_agctl[agno].numfree += (INOSPEREXT - 1); in diNewExt()
2367 imap->im_agctl[agno].numinos += INOSPEREXT; in diNewExt()
2371 atomic_add(INOSPEREXT - 1, &imap->im_numfree); in diNewExt()
2372 atomic_add(INOSPEREXT, &imap->im_numinos); in diNewExt()
2414 * imap - pointer to inode map control structure.
2415 * iagnop - pointer to an iag number set with the number of the
2417 * agno - allocation group number.
2418 * bpp - Buffer pointer to be filled in with new IAG's buffer
2421 * 0 - success.
2422 * -ENOSPC - insufficient disk resources.
2423 * -EIO - i/o error.
2435 * . at start of logredo(): init in-memory imap with one additional iag page;
2436 * . at end of logredo(): re-read imap inode to determine
2439 static int
2440 diNewIAG(struct inomap * imap, int *iagnop, int agno, struct metapage ** mpp) in diNewIAG()
2442 int rc; in diNewIAG()
2443 int iagno, i, xlen; in diNewIAG()
2455 ipimap = imap->im_ipimap; in diNewIAG()
2456 sb = ipimap->i_sb; in diNewIAG()
2465 if (imap->im_freeiag >= 0) { in diNewIAG()
2467 iagno = imap->im_freeiag; in diNewIAG()
2470 blkno = IAGTOLBLK(iagno, sbi->l2nbperpage); in diNewIAG()
2479 if (ipimap->i_size >> L2PSIZE != imap->im_nextiag + 1) { in diNewIAG()
2482 jfs_error(imap->im_ipimap->i_sb, in diNewIAG()
2483 "ipimap->i_size is wrong\n"); in diNewIAG()
2484 return -EIO; in diNewIAG()
2489 iagno = imap->im_nextiag; in diNewIAG()
2494 if (iagno > (MAXIAGS - 1)) { in diNewIAG()
2498 rc = -ENOSPC; in diNewIAG()
2506 blkno = IAGTOLBLK(iagno, sbi->l2nbperpage); in diNewIAG()
2509 xlen = sbi->nbperpage; in diNewIAG()
2522 mutex_lock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2528 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2541 ipimap->i_size += PSIZE; in diNewIAG()
2551 xtTruncate(tid, ipimap, ipimap->i_size - PSIZE, in diNewIAG()
2556 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2561 rc = -EIO; in diNewIAG()
2564 iagp = (struct iag *) mp->data; in diNewIAG()
2568 iagp->iagnum = cpu_to_le32(iagno); in diNewIAG()
2569 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diNewIAG()
2570 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diNewIAG()
2571 iagp->iagfree = cpu_to_le32(-1); in diNewIAG()
2572 iagp->nfreeinos = 0; in diNewIAG()
2573 iagp->nfreeexts = cpu_to_le32(EXTSPERIAG); in diNewIAG()
2579 iagp->inosmap[i] = cpu_to_le32(ONES); in diNewIAG()
2595 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2600 imap->im_nextiag += 1; in diNewIAG()
2605 imap->im_freeiag = iagno; in diNewIAG()
2622 rc = -EIO; in diNewIAG()
2625 iagp = (struct iag *) mp->data; in diNewIAG()
2628 imap->im_freeiag = le32_to_cpu(iagp->iagfree); in diNewIAG()
2629 iagp->iagfree = cpu_to_le32(-1); in diNewIAG()
2649 * imap - pointer to inode map control structure.
2650 * iagno - iag number.
2651 * bpp - point to buffer pointer to be filled in on successful
2660 * 0 - success.
2661 * -EIO - i/o error.
2663 static int diIAGRead(struct inomap * imap, int iagno, struct metapage ** mpp) in diIAGRead()
2665 struct inode *ipimap = imap->im_ipimap; in diIAGRead()
2669 blkno = IAGTOLBLK(iagno, JFS_SBI(ipimap->i_sb)->l2nbperpage); in diIAGRead()
2674 return -EIO; in diIAGRead()
2687 * word - word to be examined.
2688 * start - starting bit position.
2694 static int diFindFree(u32 word, int start) in diFindFree()
2696 int bitno; in diFindFree()
2716 * ipimap - Incore inode map inode
2717 * inum - Number of inode to mark in permanent map
2718 * is_free - If 'true' indicates inode should be marked freed, otherwise
2724 int
2728 int rc; in diUpdatePMap()
2731 int iagno, ino, extno, bitno; in diUpdatePMap()
2733 u32 mask; in diUpdatePMap() local
2735 int lsn, difft, diffp; in diUpdatePMap()
2738 imap = JFS_IP(ipimap)->i_imap; in diUpdatePMap()
2742 if (iagno >= imap->im_nextiag) { in diUpdatePMap()
2743 jfs_error(ipimap->i_sb, "the iag is outside the map\n"); in diUpdatePMap()
2744 return -EIO; in diUpdatePMap()
2753 iagp = (struct iag *) mp->data; in diUpdatePMap()
2757 ino = inum & (INOSPERIAG - 1); in diUpdatePMap()
2759 bitno = ino & (INOSPEREXT - 1); in diUpdatePMap()
2760 mask = HIGHORDER >> bitno; in diUpdatePMap()
2770 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diUpdatePMap()
2771 jfs_error(ipimap->i_sb, in diUpdatePMap()
2775 if (!(le32_to_cpu(iagp->pmap[extno]) & mask)) { in diUpdatePMap()
2776 jfs_error(ipimap->i_sb, in diUpdatePMap()
2781 iagp->pmap[extno] &= cpu_to_le32(~mask); in diUpdatePMap()
2790 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diUpdatePMap()
2792 jfs_error(ipimap->i_sb, in diUpdatePMap()
2794 return -EIO; in diUpdatePMap()
2796 if ((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) { in diUpdatePMap()
2798 jfs_error(ipimap->i_sb, in diUpdatePMap()
2800 return -EIO; in diUpdatePMap()
2803 iagp->pmap[extno] |= cpu_to_le32(mask); in diUpdatePMap()
2808 lsn = tblk->lsn; in diUpdatePMap()
2809 log = JFS_SBI(tblk->sb)->log; in diUpdatePMap()
2811 if (mp->lsn != 0) { in diUpdatePMap()
2814 logdiff(diffp, mp->lsn, log); in diUpdatePMap()
2816 mp->lsn = lsn; in diUpdatePMap()
2818 list_move(&mp->synclist, &tblk->synclist); in diUpdatePMap()
2821 assert(mp->clsn); in diUpdatePMap()
2822 logdiff(difft, tblk->clsn, log); in diUpdatePMap()
2823 logdiff(diffp, mp->clsn, log); in diUpdatePMap()
2825 mp->clsn = tblk->clsn; in diUpdatePMap()
2827 mp->log = log; in diUpdatePMap()
2828 mp->lsn = lsn; in diUpdatePMap()
2830 log->count++; in diUpdatePMap()
2831 list_add(&mp->synclist, &tblk->synclist); in diUpdatePMap()
2832 mp->clsn = tblk->clsn; in diUpdatePMap()
2847 int diExtendFS(struct inode *ipimap, struct inode *ipbmap) in diExtendFS()
2849 int rc, rcx = 0; in diExtendFS()
2850 struct inomap *imap = JFS_IP(ipimap)->i_imap; in diExtendFS()
2852 struct bmap *mp = JFS_SBI(ipbmap->i_sb)->bmap; in diExtendFS()
2854 int i, n, head; in diExtendFS()
2855 int numinos, xnuminos = 0, xnumfree = 0; in diExtendFS()
2859 imap->im_nextiag, atomic_read(&imap->im_numinos), in diExtendFS()
2860 atomic_read(&imap->im_numfree)); in diExtendFS()
2866 * i.e., (AGi, ..., AGj) where i = k*n and j = k*(n+1) - 1 to AGn; in diExtendFS()
2872 imap->im_agctl[i].inofree = -1; in diExtendFS()
2873 imap->im_agctl[i].extfree = -1; in diExtendFS()
2874 imap->im_agctl[i].numinos = 0; /* number of backed inodes */ in diExtendFS()
2875 imap->im_agctl[i].numfree = 0; /* number of free backed inodes */ in diExtendFS()
2883 for (i = 0; i < imap->im_nextiag; i++) { in diExtendFS()
2888 iagp = (struct iag *) bp->data; in diExtendFS()
2889 if (le32_to_cpu(iagp->iagnum) != i) { in diExtendFS()
2891 jfs_error(ipimap->i_sb, "unexpected value of iagnum\n"); in diExtendFS()
2892 return -EIO; in diExtendFS()
2896 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diExtendFS()
2901 agstart = le64_to_cpu(iagp->agstart); in diExtendFS()
2902 n = agstart >> mp->db_agl2size; in diExtendFS()
2903 iagp->agstart = cpu_to_le64((s64)n << mp->db_agl2size); in diExtendFS()
2906 numinos = (EXTSPERIAG - le32_to_cpu(iagp->nfreeexts)) in diExtendFS()
2910 imap->im_agctl[n].numinos += numinos; in diExtendFS()
2915 if ((int) le32_to_cpu(iagp->nfreeinos) > 0) { in diExtendFS()
2916 if ((head = imap->im_agctl[n].inofree) == -1) { in diExtendFS()
2917 iagp->inofreefwd = cpu_to_le32(-1); in diExtendFS()
2918 iagp->inofreeback = cpu_to_le32(-1); in diExtendFS()
2924 hiagp = (struct iag *) hbp->data; in diExtendFS()
2925 hiagp->inofreeback = iagp->iagnum; in diExtendFS()
2926 iagp->inofreefwd = cpu_to_le32(head); in diExtendFS()
2927 iagp->inofreeback = cpu_to_le32(-1); in diExtendFS()
2931 imap->im_agctl[n].inofree = in diExtendFS()
2932 le32_to_cpu(iagp->iagnum); in diExtendFS()
2935 imap->im_agctl[n].numfree += in diExtendFS()
2936 le32_to_cpu(iagp->nfreeinos); in diExtendFS()
2937 xnumfree += le32_to_cpu(iagp->nfreeinos); in diExtendFS()
2941 if (le32_to_cpu(iagp->nfreeexts) > 0) { in diExtendFS()
2942 if ((head = imap->im_agctl[n].extfree) == -1) { in diExtendFS()
2943 iagp->extfreefwd = cpu_to_le32(-1); in diExtendFS()
2944 iagp->extfreeback = cpu_to_le32(-1); in diExtendFS()
2950 hiagp = (struct iag *) hbp->data; in diExtendFS()
2951 hiagp->extfreeback = iagp->iagnum; in diExtendFS()
2952 iagp->extfreefwd = cpu_to_le32(head); in diExtendFS()
2953 iagp->extfreeback = cpu_to_le32(-1); in diExtendFS()
2957 imap->im_agctl[n].extfree = in diExtendFS()
2958 le32_to_cpu(iagp->iagnum); in diExtendFS()
2965 if (xnuminos != atomic_read(&imap->im_numinos) || in diExtendFS()
2966 xnumfree != atomic_read(&imap->im_numfree)) { in diExtendFS()
2967 jfs_error(ipimap->i_sb, "numinos or numfree incorrect\n"); in diExtendFS()
2968 return -EIO; in diExtendFS()
2983 int xlen, s64 *xaddr) in duplicateIXtree()
2991 if (JFS_SBI(sb)->mntflag & JFS_BAD_SAIT) /* s_flag */ in duplicateIXtree()
2995 JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT; in duplicateIXtree()
2998 j_sb = (struct jfs_superblock *)bh->b_data; in duplicateIXtree()
2999 j_sb->s_flag |= cpu_to_le32(JFS_BAD_SAIT); in duplicateIXtree()
3011 JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT; in duplicateIXtree()
3017 ip->i_size += PSIZE; in duplicateIXtree()
3028 * FUNCTION: Copies inode info from disk inode to in-memory inode
3031 * 0 - success
3032 * -ENOMEM - insufficient memory
3034 static int copy_from_dinode(struct dinode * dip, struct inode *ip) in copy_from_dinode()
3037 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in copy_from_dinode()
3039 jfs_ip->fileset = le32_to_cpu(dip->di_fileset); in copy_from_dinode()
3040 jfs_ip->mode2 = le32_to_cpu(dip->di_mode); in copy_from_dinode()
3043 ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff; in copy_from_dinode()
3044 if (sbi->umask != -1) { in copy_from_dinode()
3045 ip->i_mode = (ip->i_mode & ~0777) | (0777 & ~sbi->umask); in copy_from_dinode()
3047 if (S_ISDIR(ip->i_mode)) { in copy_from_dinode()
3048 if (ip->i_mode & 0400) in copy_from_dinode()
3049 ip->i_mode |= 0100; in copy_from_dinode()
3050 if (ip->i_mode & 0040) in copy_from_dinode()
3051 ip->i_mode |= 0010; in copy_from_dinode()
3052 if (ip->i_mode & 0004) in copy_from_dinode()
3053 ip->i_mode |= 0001; in copy_from_dinode()
3056 set_nlink(ip, le32_to_cpu(dip->di_nlink)); in copy_from_dinode()
3058 jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid)); in copy_from_dinode()
3059 if (!uid_valid(sbi->uid)) in copy_from_dinode()
3060 ip->i_uid = jfs_ip->saved_uid; in copy_from_dinode()
3062 ip->i_uid = sbi->uid; in copy_from_dinode()
3065 jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid)); in copy_from_dinode()
3066 if (!gid_valid(sbi->gid)) in copy_from_dinode()
3067 ip->i_gid = jfs_ip->saved_gid; in copy_from_dinode()
3069 ip->i_gid = sbi->gid; in copy_from_dinode()
3072 ip->i_size = le64_to_cpu(dip->di_size); in copy_from_dinode()
3073 inode_set_atime(ip, le32_to_cpu(dip->di_atime.tv_sec), in copy_from_dinode()
3074 le32_to_cpu(dip->di_atime.tv_nsec)); in copy_from_dinode()
3075 inode_set_mtime(ip, le32_to_cpu(dip->di_mtime.tv_sec), in copy_from_dinode()
3076 le32_to_cpu(dip->di_mtime.tv_nsec)); in copy_from_dinode()
3077 inode_set_ctime(ip, le32_to_cpu(dip->di_ctime.tv_sec), in copy_from_dinode()
3078 le32_to_cpu(dip->di_ctime.tv_nsec)); in copy_from_dinode()
3079 ip->i_blocks = LBLK2PBLK(ip->i_sb, le64_to_cpu(dip->di_nblocks)); in copy_from_dinode()
3080 ip->i_generation = le32_to_cpu(dip->di_gen); in copy_from_dinode()
3082 jfs_ip->ixpxd = dip->di_ixpxd; /* in-memory pxd's are little-endian */ in copy_from_dinode()
3083 jfs_ip->acl = dip->di_acl; /* as are dxd's */ in copy_from_dinode()
3084 jfs_ip->ea = dip->di_ea; in copy_from_dinode()
3085 jfs_ip->next_index = le32_to_cpu(dip->di_next_index); in copy_from_dinode()
3086 jfs_ip->otime = le32_to_cpu(dip->di_otime.tv_sec); in copy_from_dinode()
3087 jfs_ip->acltype = le32_to_cpu(dip->di_acltype); in copy_from_dinode()
3089 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) { in copy_from_dinode()
3090 jfs_ip->dev = le32_to_cpu(dip->di_rdev); in copy_from_dinode()
3091 ip->i_rdev = new_decode_dev(jfs_ip->dev); in copy_from_dinode()
3094 if (S_ISDIR(ip->i_mode)) { in copy_from_dinode()
3095 memcpy(&jfs_ip->u.dir, &dip->u._dir, 384); in copy_from_dinode()
3096 } else if (S_ISREG(ip->i_mode) || S_ISLNK(ip->i_mode)) { in copy_from_dinode()
3097 memcpy(&jfs_ip->i_xtroot, &dip->di_xtroot, 288); in copy_from_dinode()
3099 memcpy(&jfs_ip->i_inline_ea, &dip->di_inlineea, 128); in copy_from_dinode()
3101 /* Zero the in-memory-only stuff */ in copy_from_dinode()
3102 jfs_ip->cflag = 0; in copy_from_dinode()
3103 jfs_ip->btindex = 0; in copy_from_dinode()
3104 jfs_ip->btorder = 0; in copy_from_dinode()
3105 jfs_ip->bxflag = 0; in copy_from_dinode()
3106 jfs_ip->blid = 0; in copy_from_dinode()
3107 jfs_ip->atlhead = 0; in copy_from_dinode()
3108 jfs_ip->atltail = 0; in copy_from_dinode()
3109 jfs_ip->xtlid = 0; in copy_from_dinode()
3116 * FUNCTION: Copies inode info from in-memory inode to disk inode
3121 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in copy_to_dinode()
3123 dip->di_fileset = cpu_to_le32(jfs_ip->fileset); in copy_to_dinode()
3124 dip->di_inostamp = cpu_to_le32(sbi->inostamp); in copy_to_dinode()
3125 dip->di_number = cpu_to_le32(ip->i_ino); in copy_to_dinode()
3126 dip->di_gen = cpu_to_le32(ip->i_generation); in copy_to_dinode()
3127 dip->di_size = cpu_to_le64(ip->i_size); in copy_to_dinode()
3128 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks)); in copy_to_dinode()
3129 dip->di_nlink = cpu_to_le32(ip->i_nlink); in copy_to_dinode()
3130 if (!uid_valid(sbi->uid)) in copy_to_dinode()
3131 dip->di_uid = cpu_to_le32(i_uid_read(ip)); in copy_to_dinode()
3133 dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns, in copy_to_dinode()
3134 jfs_ip->saved_uid)); in copy_to_dinode()
3135 if (!gid_valid(sbi->gid)) in copy_to_dinode()
3136 dip->di_gid = cpu_to_le32(i_gid_read(ip)); in copy_to_dinode()
3138 dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns, in copy_to_dinode()
3139 jfs_ip->saved_gid)); in copy_to_dinode()
3144 if (sbi->umask == -1) in copy_to_dinode()
3145 dip->di_mode = cpu_to_le32((jfs_ip->mode2 & 0xffff0000) | in copy_to_dinode()
3146 ip->i_mode); in copy_to_dinode()
3148 dip->di_mode = cpu_to_le32(jfs_ip->mode2); in copy_to_dinode()
3150 dip->di_atime.tv_sec = cpu_to_le32(inode_get_atime_sec(ip)); in copy_to_dinode()
3151 dip->di_atime.tv_nsec = cpu_to_le32(inode_get_atime_nsec(ip)); in copy_to_dinode()
3152 dip->di_ctime.tv_sec = cpu_to_le32(inode_get_ctime_sec(ip)); in copy_to_dinode()
3153 dip->di_ctime.tv_nsec = cpu_to_le32(inode_get_ctime_nsec(ip)); in copy_to_dinode()
3154 dip->di_mtime.tv_sec = cpu_to_le32(inode_get_mtime_sec(ip)); in copy_to_dinode()
3155 dip->di_mtime.tv_nsec = cpu_to_le32(inode_get_mtime_nsec(ip)); in copy_to_dinode()
3156 dip->di_ixpxd = jfs_ip->ixpxd; /* in-memory pxd's are little-endian */ in copy_to_dinode()
3157 dip->di_acl = jfs_ip->acl; /* as are dxd's */ in copy_to_dinode()
3158 dip->di_ea = jfs_ip->ea; in copy_to_dinode()
3159 dip->di_next_index = cpu_to_le32(jfs_ip->next_index); in copy_to_dinode()
3160 dip->di_otime.tv_sec = cpu_to_le32(jfs_ip->otime); in copy_to_dinode()
3161 dip->di_otime.tv_nsec = 0; in copy_to_dinode()
3162 dip->di_acltype = cpu_to_le32(jfs_ip->acltype); in copy_to_dinode()
3163 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) in copy_to_dinode()
3164 dip->di_rdev = cpu_to_le32(jfs_ip->dev); in copy_to_dinode()