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; 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()
345 rel_inode = (ino & (INOSPERPAGE - 1)); in diRead()
346 pageno = blkno >> sbi->l2nbperpage; in diRead()
348 if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) { in diRead()
353 (sbi->nbperpage - block_offset) << sbi->l2niperblk; in diRead()
356 rel_inode += block_offset << sbi->l2niperblk; in diRead()
359 rel_inode -= inodes_left; in diRead()
364 mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1); in diRead()
367 return -EIO; in diRead()
371 dp = (struct dinode *) mp->data; in diRead()
374 if (ip->i_ino != le32_to_cpu(dp->di_number)) { in diRead()
375 jfs_error(ip->i_sb, "i_ino != di_number\n"); in diRead()
376 rc = -EIO; in diRead()
377 } else if (le32_to_cpu(dp->di_nlink) == 0) in diRead()
378 rc = -ESTALE; in diRead()
380 /* copy the disk inode to the in-memory inode */ in diRead()
386 JFS_IP(ip)->agstart = agstart; in diRead()
387 JFS_IP(ip)->active_ag = -1; in diRead()
407 * sb - filesystem superblock
408 * inum - aggregate inode number
409 * secondary - 1 if secondary aggregate inode table
412 * new inode - success
413 * NULL - i/o error.
415 struct inode *diReadSpecial(struct super_block *sb, ino_t inum, int secondary) in diReadSpecial()
430 address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage; in diReadSpecial()
431 JFS_IP(ip)->ipimap = sbi->ipaimap2; in diReadSpecial()
434 JFS_IP(ip)->ipimap = sbi->ipaimap; in diReadSpecial()
439 ip->i_ino = inum; in diReadSpecial()
444 mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1); in diReadSpecial()
452 dp = (struct dinode *) (mp->data); in diReadSpecial()
455 /* copy on-disk inode to in-memory inode */ in diReadSpecial()
466 ip->i_mapping->a_ops = &jfs_metapage_aops; in diReadSpecial()
467 mapping_set_gfp_mask(ip->i_mapping, GFP_NOFS); in diReadSpecial()
470 ip->i_flags |= S_NOQUOTA; in diReadSpecial()
472 if ((inum == FILESYSTEM_I) && (JFS_IP(ip)->ipimap == sbi->ipaimap)) { in diReadSpecial()
473 sbi->gengen = le32_to_cpu(dp->di_gengen); in diReadSpecial()
474 sbi->inostamp = le32_to_cpu(dp->di_inostamp); in diReadSpecial()
491 * ip - special inode
492 * secondary - 1 if secondary aggregate inode table
497 void diWriteSpecial(struct inode *ip, int secondary) in diWriteSpecial()
499 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diWriteSpecial()
502 ino_t inum = ip->i_ino; in diWriteSpecial()
506 address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage; in diWriteSpecial()
515 mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1); in diWriteSpecial()
522 dp = (struct dinode *) (mp->data); in diWriteSpecial()
525 /* copy on-disk inode to in-memory inode */ in diWriteSpecial()
527 memcpy(&dp->di_xtroot, &JFS_IP(ip)->i_xtroot, 288); in diWriteSpecial()
530 dp->di_gengen = cpu_to_le32(sbi->gengen); in diWriteSpecial()
547 filemap_write_and_wait(ip->i_mapping); in diFreeSpecial()
548 truncate_inode_pages(ip->i_mapping, 0); in diFreeSpecial()
557 * FUNCTION: write the on-disk inode portion of the in-memory inode
558 * to its corresponding on-disk inode.
571 * tid - transacation id
572 * ip - pointer to incore inode to be written to the inode extent.
575 * 0 - success
576 * -EIO - i/o error.
578 int diWrite(tid_t tid, struct inode *ip) in diWrite()
580 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diWrite()
582 int rc = 0; in diWrite()
586 int block_offset; in diWrite()
587 int inodes_left; in diWrite()
590 int rel_inode; in diWrite()
591 int dioffset; in diWrite()
598 int n; in diWrite()
600 ipimap = jfs_ip->ipimap; in diWrite()
602 ino = ip->i_ino & (INOSPERIAG - 1); in diWrite()
604 if (!addressPXD(&(jfs_ip->ixpxd)) || in diWrite()
605 (lengthPXD(&(jfs_ip->ixpxd)) != in diWrite()
606 JFS_IP(ipimap)->i_imap->im_nbperiext)) { in diWrite()
607 jfs_error(ip->i_sb, "ixpxd invalid\n"); in diWrite()
608 return -EIO; in diWrite()
615 blkno = INOPBLK(&(jfs_ip->ixpxd), ino, sbi->l2nbperpage); in diWrite()
617 rel_inode = (ino & (INOSPERPAGE - 1)); in diWrite()
618 pageno = blkno >> sbi->l2nbperpage; in diWrite()
620 if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) { in diWrite()
625 (sbi->nbperpage - block_offset) << sbi->l2niperblk; in diWrite()
628 rel_inode += block_offset << sbi->l2niperblk; in diWrite()
631 rel_inode -= inodes_left; in diWrite()
636 mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1); in diWrite()
638 return -EIO; in diWrite()
641 dp = (struct dinode *) mp->data; in diWrite()
644 dioffset = (ino & (INOSPERPAGE - 1)) << L2DISIZE; in diWrite()
647 * acquire transaction lock on the on-disk inode; in diWrite()
653 dilinelock = (struct linelock *) & ditlck->lock; in diWrite()
656 * copy btree root from in-memory inode to on-disk inode in diWrite()
658 * (tlock is taken from inline B+-tree root in in-memory in diWrite()
659 * inode when the B+-tree root is updated, which is pointed in diWrite()
660 * by jfs_ip->blid as well as being on tx tlock list) in diWrite()
663 * in in-memory inode, where txLog() will log from, and, in diWrite()
668 if (S_ISDIR(ip->i_mode) && (lid = jfs_ip->xtlid)) { in diWrite()
676 jfs_ip->xtlid = 0; in diWrite()
678 assert(tlck->type & tlckXTREE); in diWrite()
679 tlck->type |= tlckBTROOT; in diWrite()
680 tlck->mp = mp; in diWrite()
681 ilinelock = (struct linelock *) & tlck->lock; in diWrite()
686 p = &jfs_ip->i_xtroot; in diWrite()
687 xp = (xtpage_t *) &dp->di_dirtable; in diWrite()
688 lv = ilinelock->lv; in diWrite()
689 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
690 memcpy(&xp->xad[lv->offset], &p->xad[lv->offset], in diWrite()
691 lv->length << L2XTSLOTSIZE); in diWrite()
694 /* reset on-disk (metadata page) xtree XAD_NEW bit */ in diWrite()
695 xad = &xp->xad[XTENTRYSTART]; in diWrite()
697 n < le16_to_cpu(xp->header.nextindex); n++, xad++) in diWrite()
698 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) in diWrite()
699 xad->flag &= ~(XAD_NEW | XAD_EXTENDED); in diWrite()
702 if ((lid = jfs_ip->blid) == 0) in diWrite()
704 jfs_ip->blid = 0; in diWrite()
707 type = tlck->type; in diWrite()
708 tlck->type |= tlckBTROOT; in diWrite()
709 tlck->mp = mp; in diWrite()
710 ilinelock = (struct linelock *) & tlck->lock; in diWrite()
722 p = &jfs_ip->i_xtroot; in diWrite()
723 xp = &dp->di_xtroot; in diWrite()
724 lv = ilinelock->lv; in diWrite()
725 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
726 memcpy(&xp->xad[lv->offset], &p->xad[lv->offset], in diWrite()
727 lv->length << L2XTSLOTSIZE); in diWrite()
730 /* reset on-disk (metadata page) xtree XAD_NEW bit */ in diWrite()
731 xad = &xp->xad[XTENTRYSTART]; in diWrite()
733 n < le16_to_cpu(xp->header.nextindex); n++, xad++) in diWrite()
734 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) in diWrite()
735 xad->flag &= ~(XAD_NEW | XAD_EXTENDED); in diWrite()
746 p = (dtpage_t *) &jfs_ip->i_dtroot; in diWrite()
747 xp = (dtpage_t *) & dp->di_dtroot; in diWrite()
748 lv = ilinelock->lv; in diWrite()
749 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
750 memcpy(&xp->slot[lv->offset], &p->slot[lv->offset], in diWrite()
751 lv->length << L2DTSLOTSIZE); in diWrite()
759 * copy inline symlink from in-memory inode to on-disk inode in diWrite()
761 if (S_ISLNK(ip->i_mode) && ip->i_size < IDATASIZE) { in diWrite()
762 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
763 lv->offset = (dioffset + 2 * 128) >> L2INODESLOTSIZE; in diWrite()
764 lv->length = 2; in diWrite()
765 memcpy(&dp->di_inline_all, jfs_ip->i_inline_all, IDATASIZE); in diWrite()
766 dilinelock->index++; in diWrite()
769 * copy inline data from in-memory inode to on-disk inode: in diWrite()
773 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
774 lv->offset = (dioffset + 3 * 128) >> L2INODESLOTSIZE; in diWrite()
775 lv->length = 1; in diWrite()
776 memcpy(&dp->di_inlineea, jfs_ip->i_inline_ea, INODESLOTSIZE); in diWrite()
777 dilinelock->index++; in diWrite()
785 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
786 lv->offset = dioffset >> L2INODESLOTSIZE; in diWrite()
789 lv->length = 2; in diWrite()
790 memcpy(&dp->di_dirtable, &jfs_ip->i_dirtable, 96); in diWrite()
792 lv->length = 1; in diWrite()
793 dilinelock->index++; in diWrite()
795 /* release the buffer holding the updated on-disk inode. in diWrite()
836 * ip - inode to be freed.
839 * 0 - success
840 * -EIO - i/o error.
842 int diFree(struct inode *ip) in diFree()
844 int rc; in diFree()
845 ino_t inum = ip->i_ino; in diFree()
848 int iagno, ino, extno, bitno, sword, agno; in diFree()
849 int back, fwd; in diFree() local
850 u32 bitmap, mask; in diFree() local
851 struct inode *ipimap = JFS_SBI(ip->i_sb)->ipimap; in diFree()
852 struct inomap *imap = JFS_IP(ipimap)->i_imap; in diFree()
872 if (iagno >= imap->im_nextiag) { in diFree()
875 jfs_error(ip->i_sb, "inum = %d, iagno = %d, nextiag = %d\n", in diFree()
876 (uint) inum, iagno, imap->im_nextiag); in diFree()
877 return -EIO; in diFree()
882 agno = BLKTOAG(JFS_IP(ip)->agstart, JFS_SBI(ip->i_sb)); in diFree()
900 iagp = (struct iag *) mp->data; in diFree()
905 ino = inum & (INOSPERIAG - 1); in diFree()
907 bitno = ino & (INOSPEREXT - 1); in diFree()
908 mask = HIGHORDER >> bitno; in diFree()
910 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diFree()
911 jfs_error(ip->i_sb, "wmap shows inode already free\n"); in diFree()
914 if (!addressPXD(&iagp->inoext[extno])) { in diFree()
918 jfs_error(ip->i_sb, "invalid inoext\n"); in diFree()
919 return -EIO; in diFree()
924 bitmap = le32_to_cpu(iagp->wmap[extno]) & ~mask; in diFree()
926 if (imap->im_agctl[agno].numfree > imap->im_agctl[agno].numinos) { in diFree()
930 jfs_error(ip->i_sb, "numfree > numinos\n"); in diFree()
931 return -EIO; in diFree()
938 imap->im_agctl[agno].numfree < 96 || in diFree()
939 (imap->im_agctl[agno].numfree < 288 && in diFree()
940 (((imap->im_agctl[agno].numfree * 100) / in diFree()
941 imap->im_agctl[agno].numinos) <= 25))) { in diFree()
946 if (iagp->nfreeinos == 0) { in diFree()
952 if ((fwd = imap->im_agctl[agno].inofree) >= 0) { in diFree()
956 if ((rc = diIAGRead(imap, fwd, &))) { in diFree()
962 aiagp = (struct iag *) amp->data; in diFree()
966 aiagp->inofreeback = cpu_to_le32(iagno); in diFree()
974 iagp->inofreefwd = in diFree()
975 cpu_to_le32(imap->im_agctl[agno].inofree); in diFree()
976 iagp->inofreeback = cpu_to_le32(-1); in diFree()
977 imap->im_agctl[agno].inofree = iagno; in diFree()
986 if (iagp->wmap[extno] == cpu_to_le32(ONES)) { in diFree()
988 bitno = extno & (EXTSPERSUM - 1); in diFree()
989 iagp->inosmap[sword] &= in diFree()
995 iagp->wmap[extno] = cpu_to_le32(bitmap); in diFree()
1000 le32_add_cpu(&iagp->nfreeinos, 1); in diFree()
1001 imap->im_agctl[agno].numfree += 1; in diFree()
1002 atomic_inc(&imap->im_numfree); in diFree()
1024 fwd = back = -1; in diFree()
1029 if (iagp->nfreeexts == 0) { in diFree()
1036 if ((fwd = imap->im_agctl[agno].extfree) >= 0) { in diFree()
1037 if ((rc = diIAGRead(imap, fwd, &))) in diFree()
1039 aiagp = (struct iag *) amp->data; in diFree()
1047 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) { in diFree()
1053 if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) { in diFree()
1054 if ((rc = diIAGRead(imap, fwd, &))) in diFree()
1056 aiagp = (struct iag *) amp->data; in diFree()
1059 if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) { in diFree()
1062 biagp = (struct iag *) bmp->data; in diFree()
1070 if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) { in diFree()
1071 int inofreeback = le32_to_cpu(iagp->inofreeback); in diFree()
1072 int inofreefwd = le32_to_cpu(iagp->inofreefwd); in diFree()
1079 * from up above, since re-reading an iag (buffer) in diFree()
1084 if (inofreefwd == fwd) in diFree()
1085 ciagp = (struct iag *) amp->data; in diFree()
1087 ciagp = (struct iag *) bmp->data; in diFree()
1092 ciagp = (struct iag *) cmp->data; in diFree()
1098 if (inofreeback == fwd) in diFree()
1099 diagp = (struct iag *) amp->data; in diFree()
1101 diagp = (struct iag *) bmp->data; in diFree()
1106 diagp = (struct iag *) dmp->data; in diFree()
1117 freepxd = iagp->inoext[extno]; in diFree()
1126 if (iagp->nfreeexts == 0) { in diFree()
1127 if (fwd >= 0) in diFree()
1128 aiagp->extfreeback = cpu_to_le32(iagno); in diFree()
1130 iagp->extfreefwd = in diFree()
1131 cpu_to_le32(imap->im_agctl[agno].extfree); in diFree()
1132 iagp->extfreeback = cpu_to_le32(-1); in diFree()
1133 imap->im_agctl[agno].extfree = iagno; in diFree()
1138 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) { in diFree()
1139 if (fwd >= 0) in diFree()
1140 aiagp->extfreeback = iagp->extfreeback; in diFree()
1143 biagp->extfreefwd = iagp->extfreefwd; in diFree()
1145 imap->im_agctl[agno].extfree = in diFree()
1146 le32_to_cpu(iagp->extfreefwd); in diFree()
1148 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diFree()
1151 iagp->iagfree = cpu_to_le32(imap->im_freeiag); in diFree()
1152 imap->im_freeiag = iagno; in diFree()
1160 if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) { in diFree()
1161 if ((int) le32_to_cpu(iagp->inofreefwd) >= 0) in diFree()
1162 ciagp->inofreeback = iagp->inofreeback; in diFree()
1164 if ((int) le32_to_cpu(iagp->inofreeback) >= 0) in diFree()
1165 diagp->inofreefwd = iagp->inofreefwd; in diFree()
1167 imap->im_agctl[agno].inofree = in diFree()
1168 le32_to_cpu(iagp->inofreefwd); in diFree()
1170 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diFree()
1178 if (iagp->pmap[extno] != 0) { in diFree()
1179 jfs_error(ip->i_sb, "the pmap does not show inode free\n"); in diFree()
1181 iagp->wmap[extno] = 0; in diFree()
1182 PXDlength(&iagp->inoext[extno], 0); in diFree()
1183 PXDaddress(&iagp->inoext[extno], 0); in diFree()
1191 bitno = extno & (EXTSPERSUM - 1); in diFree()
1192 mask = HIGHORDER >> bitno; in diFree()
1193 iagp->inosmap[sword] |= cpu_to_le32(mask); in diFree()
1194 iagp->extsmap[sword] &= cpu_to_le32(~mask); in diFree()
1199 le32_add_cpu(&iagp->nfreeinos, -(INOSPEREXT - 1)); in diFree()
1200 le32_add_cpu(&iagp->nfreeexts, 1); in diFree()
1205 imap->im_agctl[agno].numfree -= (INOSPEREXT - 1); in diFree()
1206 imap->im_agctl[agno].numinos -= INOSPEREXT; in diFree()
1207 atomic_sub(INOSPEREXT - 1, &imap->im_numfree); in diFree()
1208 atomic_sub(INOSPEREXT, &imap->im_numinos); in diFree()
1228 tid = txBegin(ipimap->i_sb, COMMIT_FORCE); in diFree()
1229 mutex_lock(&JFS_IP(ipimap)->commit_mutex); in diFree()
1239 pxdlock = (struct pxd_lock *) & tlck->lock; in diFree()
1240 pxdlock->flag = mlckFREEPXD; in diFree()
1241 pxdlock->pxd = freepxd; in diFree()
1242 pxdlock->index = 1; in diFree()
1262 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diFree()
1293 diInitInode(struct inode *ip, int iagno, int ino, int extno, struct iag * iagp) in diInitInode()
1297 ip->i_ino = (iagno << L2INOSPERIAG) + ino; in diInitInode()
1298 jfs_ip->ixpxd = iagp->inoext[extno]; in diInitInode()
1299 jfs_ip->agstart = le64_to_cpu(iagp->agstart); in diInitInode()
1300 jfs_ip->active_ag = -1; in diInitInode()
1311 * pip - pointer to incore inode for the parent inode.
1312 * dir - 'true' if the new disk inode is for a directory.
1313 * ip - pointer to a new inode
1316 * 0 - success.
1317 * -ENOSPC - insufficient disk resources.
1318 * -EIO - i/o error.
1320 int diAlloc(struct inode *pip, bool dir, struct inode *ip) in diAlloc()
1322 int rc, ino, iagno, addext, extno, bitno, sword; in diAlloc()
1323 int nwords, rem, i, agno; in diAlloc()
1324 u32 mask, inosmap, extsmap; in diAlloc() local
1334 ipimap = JFS_SBI(pip->i_sb)->ipimap; in diAlloc()
1335 imap = JFS_IP(ipimap)->i_imap; in diAlloc()
1336 JFS_IP(ip)->ipimap = ipimap; in diAlloc()
1337 JFS_IP(ip)->fileset = FILESYSTEM_I; in diAlloc()
1343 agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap); in diAlloc()
1352 * hint. (we use a left-to-right policy to attempt to avoid in diAlloc()
1358 agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb)); in diAlloc()
1360 if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) { in diAlloc()
1366 agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap); in diAlloc()
1371 inum = pip->i_ino + 1; in diAlloc()
1372 ino = inum & (INOSPERIAG - 1); in diAlloc()
1376 inum = pip->i_ino; in diAlloc()
1391 iagp = (struct iag *) mp->data; in diAlloc()
1397 addext = (imap->im_agctl[agno].numfree < 32 && iagp->nfreeexts); in diAlloc()
1405 if (iagp->nfreeinos || addext) { in diAlloc()
1413 if (addressPXD(&iagp->inoext[extno])) { in diAlloc()
1414 bitno = ino & (INOSPEREXT - 1); in diAlloc()
1416 diFindFree(le32_to_cpu(iagp->wmap[extno]), in diAlloc()
1427 assert(rc == -EIO); in diAlloc()
1447 EXTSPERIAG - 1) ? 0 : extno + 1; in diAlloc()
1466 bitno = extno & (EXTSPERSUM - 1); in diAlloc()
1470 /* mask any prior bits for the starting words of the in diAlloc()
1473 mask = (bitno == 0) ? 0 : (ONES << (EXTSPERSUM - bitno)); in diAlloc()
1474 inosmap = le32_to_cpu(iagp->inosmap[sword]) | mask; in diAlloc()
1475 extsmap = le32_to_cpu(iagp->extsmap[sword]) | mask; in diAlloc()
1491 rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), in diAlloc()
1497 jfs_error(ip->i_sb, in diAlloc()
1499 return -EIO; in diAlloc()
1510 assert(rc == -EIO); in diAlloc()
1546 if (rc == -ENOSPC) in diAlloc()
1549 assert(rc == -EIO); in diAlloc()
1569 sword = (sword == SMAPSZ - 1) ? 0 : sword + 1; in diAlloc()
1570 inosmap = le32_to_cpu(iagp->inosmap[sword]); in diAlloc()
1571 extsmap = le32_to_cpu(iagp->extsmap[sword]); in diAlloc()
1588 if (rc != -ENOSPC) in diAlloc()
1615 * imap - pointer to inode map control structure.
1616 * agno - allocation group to allocate from.
1617 * dir - 'true' if the new disk inode is for a directory.
1618 * ip - pointer to the new inode to be filled in on successful return
1623 * 0 - success.
1624 * -ENOSPC - insufficient disk resources.
1625 * -EIO - i/o error.
1627 static int
1628 diAllocAG(struct inomap * imap, int agno, bool dir, struct inode *ip) in diAllocAG()
1630 int rc, addext, numfree, numinos; in diAllocAG()
1635 numfree = imap->im_agctl[agno].numfree; in diAllocAG()
1636 numinos = imap->im_agctl[agno].numinos; in diAllocAG()
1639 jfs_error(ip->i_sb, "numfree > numinos\n"); in diAllocAG()
1640 return -EIO; in diAllocAG()
1663 if ((rc = diAllocExt(imap, agno, ip)) != -ENOSPC) in diAllocAG()
1685 * imap - pointer to inode map control structure.
1686 * agno - primary allocation group (to avoid).
1687 * dir - 'true' if the new disk inode is for a directory.
1688 * ip - pointer to a new inode to be filled in on successful return
1693 * 0 - success.
1694 * -ENOSPC - insufficient disk resources.
1695 * -EIO - i/o error.
1697 static int
1698 diAllocAny(struct inomap * imap, int agno, bool dir, struct inode *ip) in diAllocAny()
1700 int ag, rc; in diAllocAny()
1701 int maxag = JFS_SBI(imap->im_ipimap->i_sb)->bmap->db_maxag; in diAllocAny()
1714 if (rc != -ENOSPC) in diAllocAny()
1727 if (rc != -ENOSPC) in diAllocAny()
1733 return -ENOSPC; in diAllocAny()
1751 * imap - pointer to inode map control structure.
1752 * agno - allocation group.
1753 * ip - pointer to new inode to be filled in on successful return
1758 * 0 - success.
1759 * -ENOSPC - insufficient disk resources.
1760 * -EIO - i/o error.
1762 static int diAllocIno(struct inomap * imap, int agno, struct inode *ip) in diAllocIno()
1764 int iagno, ino, rc, rem, extno, sword; in diAllocIno()
1770 if ((iagno = imap->im_agctl[agno].inofree) < 0) in diAllocIno()
1771 return -ENOSPC; in diAllocIno()
1774 IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP); in diAllocIno()
1779 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1782 iagp = (struct iag *) mp->data; in diAllocIno()
1787 if (!iagp->nfreeinos) { in diAllocIno()
1788 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1790 jfs_error(ip->i_sb, "nfreeinos = 0, but iag on freelist\n"); in diAllocIno()
1791 return -EIO; in diAllocIno()
1799 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1801 jfs_error(ip->i_sb, in diAllocIno()
1803 return -EIO; in diAllocIno()
1806 if (~iagp->inosmap[sword]) in diAllocIno()
1813 rem = diFindFree(le32_to_cpu(iagp->inosmap[sword]), 0); in diAllocIno()
1815 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1817 jfs_error(ip->i_sb, "no free extent found\n"); in diAllocIno()
1818 return -EIO; in diAllocIno()
1824 rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), 0); in diAllocIno()
1826 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1828 jfs_error(ip->i_sb, "free inode not found\n"); in diAllocIno()
1829 return -EIO; in diAllocIno()
1839 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1875 * imap - pointer to inode map control structure.
1876 * agno - allocation group number.
1877 * ip - pointer to new inode to be filled in on successful return
1882 * 0 - success.
1883 * -ENOSPC - insufficient disk resources.
1884 * -EIO - i/o error.
1886 static int diAllocExt(struct inomap * imap, int agno, struct inode *ip) in diAllocExt()
1888 int rem, iagno, sword, extno, rc; in diAllocExt()
1895 if ((iagno = imap->im_agctl[agno].extfree) < 0) { in diAllocExt()
1902 iagp = (struct iag *) mp->data; in diAllocExt()
1906 iagp->agstart = in diAllocExt()
1907 cpu_to_le64(AGTOBLK(agno, imap->im_ipimap)); in diAllocExt()
1911 IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP); in diAllocExt()
1913 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1914 jfs_error(ip->i_sb, "error reading iag\n"); in diAllocExt()
1917 iagp = (struct iag *) mp->data; in diAllocExt()
1925 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1926 jfs_error(ip->i_sb, "free ext summary map not found\n"); in diAllocExt()
1927 return -EIO; in diAllocExt()
1929 if (~iagp->extsmap[sword]) in diAllocExt()
1935 rem = diFindFree(le32_to_cpu(iagp->extsmap[sword]), 0); in diAllocExt()
1938 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1939 jfs_error(ip->i_sb, "free extent not found\n"); in diAllocExt()
1940 return -EIO; in diAllocExt()
1947 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1953 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diAllocExt()
1955 iagp->iagfree = cpu_to_le32(imap->im_freeiag); in diAllocExt()
1956 imap->im_freeiag = iagno; in diAllocExt()
1994 * imap - pointer to inode map control structure.
1995 * iagp - pointer to iag.
1996 * ino - inode number to be allocated within the iag.
1999 * 0 - success.
2000 * -ENOSPC - insufficient disk resources.
2001 * -EIO - i/o error.
2003 static int diAllocBit(struct inomap * imap, struct iag * iagp, int ino) in diAllocBit()
2005 int extno, bitno, agno, sword, rc; in diAllocBit()
2008 u32 mask; in diAllocBit() local
2015 if (iagp->nfreeinos == cpu_to_le32(1)) { in diAllocBit()
2016 if ((int) le32_to_cpu(iagp->inofreefwd) >= 0) { in diAllocBit()
2018 diIAGRead(imap, le32_to_cpu(iagp->inofreefwd), in diAllocBit()
2021 aiagp = (struct iag *) amp->data; in diAllocBit()
2024 if ((int) le32_to_cpu(iagp->inofreeback) >= 0) { in diAllocBit()
2027 le32_to_cpu(iagp->inofreeback), in diAllocBit()
2033 biagp = (struct iag *) bmp->data; in diAllocBit()
2040 agno = BLKTOAG(le64_to_cpu(iagp->agstart), JFS_SBI(imap->im_ipimap->i_sb)); in diAllocBit()
2042 bitno = ino & (INOSPEREXT - 1); in diAllocBit()
2044 /* compute the mask for setting the map. in diAllocBit()
2046 mask = HIGHORDER >> bitno; in diAllocBit()
2050 if (((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) || in diAllocBit()
2051 ((le32_to_cpu(iagp->wmap[extno]) & mask) != 0) || in diAllocBit()
2052 (addressPXD(&iagp->inoext[extno]) == 0)) { in diAllocBit()
2058 jfs_error(imap->im_ipimap->i_sb, "iag inconsistent\n"); in diAllocBit()
2059 return -EIO; in diAllocBit()
2064 iagp->wmap[extno] |= cpu_to_le32(mask); in diAllocBit()
2070 if (iagp->wmap[extno] == cpu_to_le32(ONES)) { in diAllocBit()
2072 bitno = extno & (EXTSPERSUM - 1); in diAllocBit()
2073 iagp->inosmap[sword] |= cpu_to_le32(HIGHORDER >> bitno); in diAllocBit()
2079 if (iagp->nfreeinos == cpu_to_le32(1)) { in diAllocBit()
2081 aiagp->inofreeback = iagp->inofreeback; in diAllocBit()
2086 biagp->inofreefwd = iagp->inofreefwd; in diAllocBit()
2089 imap->im_agctl[agno].inofree = in diAllocBit()
2090 le32_to_cpu(iagp->inofreefwd); in diAllocBit()
2092 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diAllocBit()
2098 le32_add_cpu(&iagp->nfreeinos, -1); in diAllocBit()
2099 imap->im_agctl[agno].numfree -= 1; in diAllocBit()
2100 atomic_dec(&imap->im_numfree); in diAllocBit()
2140 * imap - pointer to inode map control structure.
2141 * iagp - pointer to iag.
2142 * extno - extent number.
2145 * 0 - success.
2146 * -ENOSPC - insufficient disk resources.
2147 * -EIO - i/o error.
2149 static int diNewExt(struct inomap * imap, struct iag * iagp, int extno) in diNewExt()
2151 int agno, iagno, fwd, back, freei = 0, sword, rc; in diNewExt() local
2156 int i, j; in diNewExt()
2157 u32 mask; in diNewExt() local
2164 if (!iagp->nfreeexts) { in diNewExt()
2165 jfs_error(imap->im_ipimap->i_sb, "no free extents\n"); in diNewExt()
2166 return -EIO; in diNewExt()
2171 ipimap = imap->im_ipimap; in diNewExt()
2172 sbi = JFS_SBI(ipimap->i_sb); in diNewExt()
2178 agno = BLKTOAG(le64_to_cpu(iagp->agstart), sbi); in diNewExt()
2179 iagno = le32_to_cpu(iagp->iagnum); in diNewExt()
2186 if (iagp->nfreeexts == cpu_to_le32(1)) { in diNewExt()
2187 if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) { in diNewExt()
2188 if ((rc = diIAGRead(imap, fwd, &))) in diNewExt()
2190 aiagp = (struct iag *) amp->data; in diNewExt()
2193 if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) { in diNewExt()
2196 biagp = (struct iag *) bmp->data; in diNewExt()
2205 fwd = back = -1; in diNewExt()
2206 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diNewExt()
2207 if ((fwd = imap->im_agctl[agno].extfree) >= 0) { in diNewExt()
2208 if ((rc = diIAGRead(imap, fwd, &))) in diNewExt()
2210 aiagp = (struct iag *) amp->data; in diNewExt()
2222 if (iagp->nfreeinos == 0) { in diNewExt()
2223 freei = imap->im_agctl[agno].inofree; in diNewExt()
2226 if (freei == fwd) { in diNewExt()
2233 ciagp = (struct iag *) cmp->data; in diNewExt()
2236 jfs_error(imap->im_ipimap->i_sb, in diNewExt()
2238 rc = -EIO; in diNewExt()
2246 if ((extno == 0) || (addressPXD(&iagp->inoext[extno - 1]) == 0)) in diNewExt()
2247 hint = ((s64) agno << sbi->bmap->db_agl2size) - 1; in diNewExt()
2249 hint = addressPXD(&iagp->inoext[extno - 1]) + in diNewExt()
2250 lengthPXD(&iagp->inoext[extno - 1]) - 1; in diNewExt()
2252 if ((rc = dbAlloc(ipimap, hint, (s64) imap->im_nbperiext, &blkno))) in diNewExt()
2263 for (i = 0; i < imap->im_nbperiext; i += sbi->nbperpage) { in diNewExt()
2268 rc = -EIO; in diNewExt()
2271 dp = (struct dinode *) dmp->data; in diNewExt()
2277 dp->di_inostamp = cpu_to_le32(sbi->inostamp); in diNewExt()
2278 dp->di_number = cpu_to_le32(ino); in diNewExt()
2279 dp->di_fileset = cpu_to_le32(FILESYSTEM_I); in diNewExt()
2280 dp->di_mode = 0; in diNewExt()
2281 dp->di_nlink = 0; in diNewExt()
2282 PXDaddress(&(dp->di_ixpxd), blkno); in diNewExt()
2283 PXDlength(&(dp->di_ixpxd), imap->im_nbperiext); in diNewExt()
2291 if (iagp->nfreeexts == cpu_to_le32(1)) { in diNewExt()
2292 if (fwd >= 0) in diNewExt()
2293 aiagp->extfreeback = iagp->extfreeback; in diNewExt()
2296 biagp->extfreefwd = iagp->extfreefwd; in diNewExt()
2298 imap->im_agctl[agno].extfree = in diNewExt()
2299 le32_to_cpu(iagp->extfreefwd); in diNewExt()
2301 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diNewExt()
2306 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diNewExt()
2307 if (fwd >= 0) in diNewExt()
2308 aiagp->extfreeback = cpu_to_le32(iagno); in diNewExt()
2310 iagp->extfreefwd = cpu_to_le32(fwd); in diNewExt()
2311 iagp->extfreeback = cpu_to_le32(-1); in diNewExt()
2312 imap->im_agctl[agno].extfree = iagno; in diNewExt()
2319 if (iagp->nfreeinos == 0) { in diNewExt()
2321 ciagp->inofreeback = cpu_to_le32(iagno); in diNewExt()
2323 iagp->inofreefwd = in diNewExt()
2324 cpu_to_le32(imap->im_agctl[agno].inofree); in diNewExt()
2325 iagp->inofreeback = cpu_to_le32(-1); in diNewExt()
2326 imap->im_agctl[agno].inofree = iagno; in diNewExt()
2330 PXDlength(&iagp->inoext[extno], imap->im_nbperiext); in diNewExt()
2331 PXDaddress(&iagp->inoext[extno], blkno); in diNewExt()
2337 iagp->wmap[extno] = cpu_to_le32(HIGHORDER); in diNewExt()
2338 iagp->pmap[extno] = 0; in diNewExt()
2345 mask = HIGHORDER >> (extno & (EXTSPERSUM - 1)); in diNewExt()
2346 iagp->extsmap[sword] |= cpu_to_le32(mask); in diNewExt()
2347 iagp->inosmap[sword] &= cpu_to_le32(~mask); in diNewExt()
2352 le32_add_cpu(&iagp->nfreeinos, (INOSPEREXT - 1)); in diNewExt()
2353 le32_add_cpu(&iagp->nfreeexts, -1); in diNewExt()
2357 imap->im_agctl[agno].numfree += (INOSPEREXT - 1); in diNewExt()
2358 imap->im_agctl[agno].numinos += INOSPEREXT; in diNewExt()
2362 atomic_add(INOSPEREXT - 1, &imap->im_numfree); in diNewExt()
2363 atomic_add(INOSPEREXT, &imap->im_numinos); in diNewExt()
2405 * imap - pointer to inode map control structure.
2406 * iagnop - pointer to an iag number set with the number of the
2408 * agno - allocation group number.
2409 * bpp - Buffer pointer to be filled in with new IAG's buffer
2412 * 0 - success.
2413 * -ENOSPC - insufficient disk resources.
2414 * -EIO - i/o error.
2426 * . at start of logredo(): init in-memory imap with one additional iag page;
2427 * . at end of logredo(): re-read imap inode to determine
2430 static int
2431 diNewIAG(struct inomap * imap, int *iagnop, int agno, struct metapage ** mpp) in diNewIAG()
2433 int rc; in diNewIAG()
2434 int iagno, i, xlen; in diNewIAG()
2446 ipimap = imap->im_ipimap; in diNewIAG()
2447 sb = ipimap->i_sb; in diNewIAG()
2456 if (imap->im_freeiag >= 0) { in diNewIAG()
2458 iagno = imap->im_freeiag; in diNewIAG()
2461 blkno = IAGTOLBLK(iagno, sbi->l2nbperpage); in diNewIAG()
2470 if (ipimap->i_size >> L2PSIZE != imap->im_nextiag + 1) { in diNewIAG()
2473 jfs_error(imap->im_ipimap->i_sb, in diNewIAG()
2474 "ipimap->i_size is wrong\n"); in diNewIAG()
2475 return -EIO; in diNewIAG()
2480 iagno = imap->im_nextiag; in diNewIAG()
2485 if (iagno > (MAXIAGS - 1)) { in diNewIAG()
2489 rc = -ENOSPC; in diNewIAG()
2497 blkno = IAGTOLBLK(iagno, sbi->l2nbperpage); in diNewIAG()
2500 xlen = sbi->nbperpage; in diNewIAG()
2513 mutex_lock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2519 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2532 ipimap->i_size += PSIZE; in diNewIAG()
2542 xtTruncate(tid, ipimap, ipimap->i_size - PSIZE, in diNewIAG()
2547 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2552 rc = -EIO; in diNewIAG()
2555 iagp = (struct iag *) mp->data; in diNewIAG()
2559 iagp->iagnum = cpu_to_le32(iagno); in diNewIAG()
2560 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diNewIAG()
2561 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diNewIAG()
2562 iagp->iagfree = cpu_to_le32(-1); in diNewIAG()
2563 iagp->nfreeinos = 0; in diNewIAG()
2564 iagp->nfreeexts = cpu_to_le32(EXTSPERIAG); in diNewIAG()
2570 iagp->inosmap[i] = cpu_to_le32(ONES); in diNewIAG()
2586 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2591 imap->im_nextiag += 1; in diNewIAG()
2596 imap->im_freeiag = iagno; in diNewIAG()
2613 rc = -EIO; in diNewIAG()
2616 iagp = (struct iag *) mp->data; in diNewIAG()
2619 imap->im_freeiag = le32_to_cpu(iagp->iagfree); in diNewIAG()
2620 iagp->iagfree = cpu_to_le32(-1); in diNewIAG()
2640 * imap - pointer to inode map control structure.
2641 * iagno - iag number.
2642 * bpp - point to buffer pointer to be filled in on successful
2651 * 0 - success.
2652 * -EIO - i/o error.
2654 static int diIAGRead(struct inomap * imap, int iagno, struct metapage ** mpp) in diIAGRead()
2656 struct inode *ipimap = imap->im_ipimap; in diIAGRead()
2660 blkno = IAGTOLBLK(iagno, JFS_SBI(ipimap->i_sb)->l2nbperpage); in diIAGRead()
2665 return -EIO; in diIAGRead()
2678 * word - word to be examined.
2679 * start - starting bit position.
2685 static int diFindFree(u32 word, int start) in diFindFree()
2687 int bitno; in diFindFree()
2707 * ipimap - Incore inode map inode
2708 * inum - Number of inode to mark in permanent map
2709 * is_free - If 'true' indicates inode should be marked freed, otherwise
2715 int
2719 int rc; in diUpdatePMap()
2722 int iagno, ino, extno, bitno; in diUpdatePMap()
2724 u32 mask; in diUpdatePMap() local
2726 int lsn, difft, diffp; in diUpdatePMap()
2729 imap = JFS_IP(ipimap)->i_imap; in diUpdatePMap()
2733 if (iagno >= imap->im_nextiag) { in diUpdatePMap()
2734 jfs_error(ipimap->i_sb, "the iag is outside the map\n"); in diUpdatePMap()
2735 return -EIO; in diUpdatePMap()
2744 iagp = (struct iag *) mp->data; in diUpdatePMap()
2748 ino = inum & (INOSPERIAG - 1); in diUpdatePMap()
2750 bitno = ino & (INOSPEREXT - 1); in diUpdatePMap()
2751 mask = HIGHORDER >> bitno; in diUpdatePMap()
2761 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diUpdatePMap()
2762 jfs_error(ipimap->i_sb, in diUpdatePMap()
2766 if (!(le32_to_cpu(iagp->pmap[extno]) & mask)) { in diUpdatePMap()
2767 jfs_error(ipimap->i_sb, in diUpdatePMap()
2772 iagp->pmap[extno] &= cpu_to_le32(~mask); in diUpdatePMap()
2781 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diUpdatePMap()
2783 jfs_error(ipimap->i_sb, in diUpdatePMap()
2785 return -EIO; in diUpdatePMap()
2787 if ((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) { in diUpdatePMap()
2789 jfs_error(ipimap->i_sb, in diUpdatePMap()
2791 return -EIO; in diUpdatePMap()
2794 iagp->pmap[extno] |= cpu_to_le32(mask); in diUpdatePMap()
2799 lsn = tblk->lsn; in diUpdatePMap()
2800 log = JFS_SBI(tblk->sb)->log; in diUpdatePMap()
2802 if (mp->lsn != 0) { in diUpdatePMap()
2805 logdiff(diffp, mp->lsn, log); in diUpdatePMap()
2807 mp->lsn = lsn; in diUpdatePMap()
2809 list_move(&mp->synclist, &tblk->synclist); in diUpdatePMap()
2812 assert(mp->clsn); in diUpdatePMap()
2813 logdiff(difft, tblk->clsn, log); in diUpdatePMap()
2814 logdiff(diffp, mp->clsn, log); in diUpdatePMap()
2816 mp->clsn = tblk->clsn; in diUpdatePMap()
2818 mp->log = log; in diUpdatePMap()
2819 mp->lsn = lsn; in diUpdatePMap()
2821 log->count++; in diUpdatePMap()
2822 list_add(&mp->synclist, &tblk->synclist); in diUpdatePMap()
2823 mp->clsn = tblk->clsn; in diUpdatePMap()
2838 int diExtendFS(struct inode *ipimap, struct inode *ipbmap) in diExtendFS()
2840 int rc, rcx = 0; in diExtendFS()
2841 struct inomap *imap = JFS_IP(ipimap)->i_imap; in diExtendFS()
2843 struct bmap *mp = JFS_SBI(ipbmap->i_sb)->bmap; in diExtendFS()
2845 int i, n, head; in diExtendFS()
2846 int numinos, xnuminos = 0, xnumfree = 0; in diExtendFS()
2850 imap->im_nextiag, atomic_read(&imap->im_numinos), in diExtendFS()
2851 atomic_read(&imap->im_numfree)); in diExtendFS()
2857 * i.e., (AGi, ..., AGj) where i = k*n and j = k*(n+1) - 1 to AGn; in diExtendFS()
2863 imap->im_agctl[i].inofree = -1; in diExtendFS()
2864 imap->im_agctl[i].extfree = -1; in diExtendFS()
2865 imap->im_agctl[i].numinos = 0; /* number of backed inodes */ in diExtendFS()
2866 imap->im_agctl[i].numfree = 0; /* number of free backed inodes */ in diExtendFS()
2874 for (i = 0; i < imap->im_nextiag; i++) { in diExtendFS()
2879 iagp = (struct iag *) bp->data; in diExtendFS()
2880 if (le32_to_cpu(iagp->iagnum) != i) { in diExtendFS()
2882 jfs_error(ipimap->i_sb, "unexpected value of iagnum\n"); in diExtendFS()
2883 return -EIO; in diExtendFS()
2887 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diExtendFS()
2892 agstart = le64_to_cpu(iagp->agstart); in diExtendFS()
2893 n = agstart >> mp->db_agl2size; in diExtendFS()
2894 iagp->agstart = cpu_to_le64((s64)n << mp->db_agl2size); in diExtendFS()
2897 numinos = (EXTSPERIAG - le32_to_cpu(iagp->nfreeexts)) in diExtendFS()
2901 imap->im_agctl[n].numinos += numinos; in diExtendFS()
2906 if ((int) le32_to_cpu(iagp->nfreeinos) > 0) { in diExtendFS()
2907 if ((head = imap->im_agctl[n].inofree) == -1) { in diExtendFS()
2908 iagp->inofreefwd = cpu_to_le32(-1); in diExtendFS()
2909 iagp->inofreeback = cpu_to_le32(-1); in diExtendFS()
2915 hiagp = (struct iag *) hbp->data; in diExtendFS()
2916 hiagp->inofreeback = iagp->iagnum; in diExtendFS()
2917 iagp->inofreefwd = cpu_to_le32(head); in diExtendFS()
2918 iagp->inofreeback = cpu_to_le32(-1); in diExtendFS()
2922 imap->im_agctl[n].inofree = in diExtendFS()
2923 le32_to_cpu(iagp->iagnum); in diExtendFS()
2926 imap->im_agctl[n].numfree += in diExtendFS()
2927 le32_to_cpu(iagp->nfreeinos); in diExtendFS()
2928 xnumfree += le32_to_cpu(iagp->nfreeinos); in diExtendFS()
2932 if (le32_to_cpu(iagp->nfreeexts) > 0) { in diExtendFS()
2933 if ((head = imap->im_agctl[n].extfree) == -1) { in diExtendFS()
2934 iagp->extfreefwd = cpu_to_le32(-1); in diExtendFS()
2935 iagp->extfreeback = cpu_to_le32(-1); in diExtendFS()
2941 hiagp = (struct iag *) hbp->data; in diExtendFS()
2942 hiagp->extfreeback = iagp->iagnum; in diExtendFS()
2943 iagp->extfreefwd = cpu_to_le32(head); in diExtendFS()
2944 iagp->extfreeback = cpu_to_le32(-1); in diExtendFS()
2948 imap->im_agctl[n].extfree = in diExtendFS()
2949 le32_to_cpu(iagp->iagnum); in diExtendFS()
2956 if (xnuminos != atomic_read(&imap->im_numinos) || in diExtendFS()
2957 xnumfree != atomic_read(&imap->im_numfree)) { in diExtendFS()
2958 jfs_error(ipimap->i_sb, "numinos or numfree incorrect\n"); in diExtendFS()
2959 return -EIO; in diExtendFS()
2974 int xlen, s64 *xaddr) in duplicateIXtree()
2982 if (JFS_SBI(sb)->mntflag & JFS_BAD_SAIT) /* s_flag */ in duplicateIXtree()
2986 JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT; in duplicateIXtree()
2989 j_sb = (struct jfs_superblock *)bh->b_data; in duplicateIXtree()
2990 j_sb->s_flag |= cpu_to_le32(JFS_BAD_SAIT); in duplicateIXtree()
3002 JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT; in duplicateIXtree()
3008 ip->i_size += PSIZE; in duplicateIXtree()
3019 * FUNCTION: Copies inode info from disk inode to in-memory inode
3022 * 0 - success
3023 * -ENOMEM - insufficient memory
3025 static int copy_from_dinode(struct dinode * dip, struct inode *ip) in copy_from_dinode()
3028 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in copy_from_dinode()
3030 jfs_ip->fileset = le32_to_cpu(dip->di_fileset); in copy_from_dinode()
3031 jfs_ip->mode2 = le32_to_cpu(dip->di_mode); in copy_from_dinode()
3034 ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff; in copy_from_dinode()
3035 if (sbi->umask != -1) { in copy_from_dinode()
3036 ip->i_mode = (ip->i_mode & ~0777) | (0777 & ~sbi->umask); in copy_from_dinode()
3038 if (S_ISDIR(ip->i_mode)) { in copy_from_dinode()
3039 if (ip->i_mode & 0400) in copy_from_dinode()
3040 ip->i_mode |= 0100; in copy_from_dinode()
3041 if (ip->i_mode & 0040) in copy_from_dinode()
3042 ip->i_mode |= 0010; in copy_from_dinode()
3043 if (ip->i_mode & 0004) in copy_from_dinode()
3044 ip->i_mode |= 0001; in copy_from_dinode()
3047 set_nlink(ip, le32_to_cpu(dip->di_nlink)); in copy_from_dinode()
3049 jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid)); in copy_from_dinode()
3050 if (!uid_valid(sbi->uid)) in copy_from_dinode()
3051 ip->i_uid = jfs_ip->saved_uid; in copy_from_dinode()
3053 ip->i_uid = sbi->uid; in copy_from_dinode()
3056 jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid)); in copy_from_dinode()
3057 if (!gid_valid(sbi->gid)) in copy_from_dinode()
3058 ip->i_gid = jfs_ip->saved_gid; in copy_from_dinode()
3060 ip->i_gid = sbi->gid; in copy_from_dinode()
3063 ip->i_size = le64_to_cpu(dip->di_size); in copy_from_dinode()
3064 ip->i_atime.tv_sec = le32_to_cpu(dip->di_atime.tv_sec); in copy_from_dinode()
3065 ip->i_atime.tv_nsec = le32_to_cpu(dip->di_atime.tv_nsec); in copy_from_dinode()
3066 ip->i_mtime.tv_sec = le32_to_cpu(dip->di_mtime.tv_sec); in copy_from_dinode()
3067 ip->i_mtime.tv_nsec = le32_to_cpu(dip->di_mtime.tv_nsec); in copy_from_dinode()
3068 inode_set_ctime(ip, le32_to_cpu(dip->di_ctime.tv_sec), in copy_from_dinode()
3069 le32_to_cpu(dip->di_ctime.tv_nsec)); in copy_from_dinode()
3070 ip->i_blocks = LBLK2PBLK(ip->i_sb, le64_to_cpu(dip->di_nblocks)); in copy_from_dinode()
3071 ip->i_generation = le32_to_cpu(dip->di_gen); in copy_from_dinode()
3073 jfs_ip->ixpxd = dip->di_ixpxd; /* in-memory pxd's are little-endian */ in copy_from_dinode()
3074 jfs_ip->acl = dip->di_acl; /* as are dxd's */ in copy_from_dinode()
3075 jfs_ip->ea = dip->di_ea; in copy_from_dinode()
3076 jfs_ip->next_index = le32_to_cpu(dip->di_next_index); in copy_from_dinode()
3077 jfs_ip->otime = le32_to_cpu(dip->di_otime.tv_sec); in copy_from_dinode()
3078 jfs_ip->acltype = le32_to_cpu(dip->di_acltype); in copy_from_dinode()
3080 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) { in copy_from_dinode()
3081 jfs_ip->dev = le32_to_cpu(dip->di_rdev); in copy_from_dinode()
3082 ip->i_rdev = new_decode_dev(jfs_ip->dev); in copy_from_dinode()
3085 if (S_ISDIR(ip->i_mode)) { in copy_from_dinode()
3086 memcpy(&jfs_ip->u.dir, &dip->u._dir, 384); in copy_from_dinode()
3087 } else if (S_ISREG(ip->i_mode) || S_ISLNK(ip->i_mode)) { in copy_from_dinode()
3088 memcpy(&jfs_ip->i_xtroot, &dip->di_xtroot, 288); in copy_from_dinode()
3090 memcpy(&jfs_ip->i_inline_ea, &dip->di_inlineea, 128); in copy_from_dinode()
3092 /* Zero the in-memory-only stuff */ in copy_from_dinode()
3093 jfs_ip->cflag = 0; in copy_from_dinode()
3094 jfs_ip->btindex = 0; in copy_from_dinode()
3095 jfs_ip->btorder = 0; in copy_from_dinode()
3096 jfs_ip->bxflag = 0; in copy_from_dinode()
3097 jfs_ip->blid = 0; in copy_from_dinode()
3098 jfs_ip->atlhead = 0; in copy_from_dinode()
3099 jfs_ip->atltail = 0; in copy_from_dinode()
3100 jfs_ip->xtlid = 0; in copy_from_dinode()
3107 * FUNCTION: Copies inode info from in-memory inode to disk inode
3112 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in copy_to_dinode()
3114 dip->di_fileset = cpu_to_le32(jfs_ip->fileset); in copy_to_dinode()
3115 dip->di_inostamp = cpu_to_le32(sbi->inostamp); in copy_to_dinode()
3116 dip->di_number = cpu_to_le32(ip->i_ino); in copy_to_dinode()
3117 dip->di_gen = cpu_to_le32(ip->i_generation); in copy_to_dinode()
3118 dip->di_size = cpu_to_le64(ip->i_size); in copy_to_dinode()
3119 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks)); in copy_to_dinode()
3120 dip->di_nlink = cpu_to_le32(ip->i_nlink); in copy_to_dinode()
3121 if (!uid_valid(sbi->uid)) in copy_to_dinode()
3122 dip->di_uid = cpu_to_le32(i_uid_read(ip)); in copy_to_dinode()
3124 dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns, in copy_to_dinode()
3125 jfs_ip->saved_uid)); in copy_to_dinode()
3126 if (!gid_valid(sbi->gid)) in copy_to_dinode()
3127 dip->di_gid = cpu_to_le32(i_gid_read(ip)); in copy_to_dinode()
3129 dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns, in copy_to_dinode()
3130 jfs_ip->saved_gid)); in copy_to_dinode()
3135 if (sbi->umask == -1) in copy_to_dinode()
3136 dip->di_mode = cpu_to_le32((jfs_ip->mode2 & 0xffff0000) | in copy_to_dinode()
3137 ip->i_mode); in copy_to_dinode()
3139 dip->di_mode = cpu_to_le32(jfs_ip->mode2); in copy_to_dinode()
3141 dip->di_atime.tv_sec = cpu_to_le32(ip->i_atime.tv_sec); in copy_to_dinode()
3142 dip->di_atime.tv_nsec = cpu_to_le32(ip->i_atime.tv_nsec); in copy_to_dinode()
3143 dip->di_ctime.tv_sec = cpu_to_le32(inode_get_ctime(ip).tv_sec); in copy_to_dinode()
3144 dip->di_ctime.tv_nsec = cpu_to_le32(inode_get_ctime(ip).tv_nsec); in copy_to_dinode()
3145 dip->di_mtime.tv_sec = cpu_to_le32(ip->i_mtime.tv_sec); in copy_to_dinode()
3146 dip->di_mtime.tv_nsec = cpu_to_le32(ip->i_mtime.tv_nsec); in copy_to_dinode()
3147 dip->di_ixpxd = jfs_ip->ixpxd; /* in-memory pxd's are little-endian */ in copy_to_dinode()
3148 dip->di_acl = jfs_ip->acl; /* as are dxd's */ in copy_to_dinode()
3149 dip->di_ea = jfs_ip->ea; in copy_to_dinode()
3150 dip->di_next_index = cpu_to_le32(jfs_ip->next_index); in copy_to_dinode()
3151 dip->di_otime.tv_sec = cpu_to_le32(jfs_ip->otime); in copy_to_dinode()
3152 dip->di_otime.tv_nsec = 0; in copy_to_dinode()
3153 dip->di_acltype = cpu_to_le32(jfs_ip->acltype); in copy_to_dinode()
3154 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) in copy_to_dinode()
3155 dip->di_rdev = cpu_to_le32(jfs_ip->dev); in copy_to_dinode()