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()
204 int diSync(struct inode *ipimap) in diSync()
207 struct inomap *imp = JFS_IP(ipimap)->i_imap; in diSync()
209 int index; in diSync()
214 /* read the on-disk inode map control structure */ in diSync()
216 IMAPBLKNO << JFS_SBI(ipimap->i_sb)->l2nbperpage, in diSync()
220 return -EIO; in diSync()
223 /* copy the in-memory version to the on-disk version */ in diSync()
224 dinom_le = (struct dinomap_disk *) mp->data; in diSync()
225 dinom_le->in_freeiag = cpu_to_le32(imp->im_freeiag); in diSync()
226 dinom_le->in_nextiag = cpu_to_le32(imp->im_nextiag); in diSync()
227 dinom_le->in_numinos = cpu_to_le32(atomic_read(&imp->im_numinos)); in diSync()
228 dinom_le->in_numfree = cpu_to_le32(atomic_read(&imp->im_numfree)); in diSync()
229 dinom_le->in_nbperiext = cpu_to_le32(imp->im_nbperiext); in diSync()
230 dinom_le->in_l2nbperiext = cpu_to_le32(imp->im_l2nbperiext); in diSync()
232 dinom_le->in_agctl[index].inofree = in diSync()
233 cpu_to_le32(imp->im_agctl[index].inofree); in diSync()
234 dinom_le->in_agctl[index].extfree = in diSync()
235 cpu_to_le32(imp->im_agctl[index].extfree); in diSync()
236 dinom_le->in_agctl[index].numinos = in diSync()
237 cpu_to_le32(imp->im_agctl[index].numinos); in diSync()
238 dinom_le->in_agctl[index].numfree = in diSync()
239 cpu_to_le32(imp->im_agctl[index].numfree); in diSync()
248 filemap_write_and_wait(ipimap->i_mapping); in diSync()
281 * ip - pointer to incore inode to be initialized from disk.
284 * 0 - success
285 * -EIO - i/o error.
286 * -ENOMEM - insufficient memory
289 int diRead(struct inode *ip) in diRead()
291 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diRead()
292 int iagno, ino, extno, rc; in diRead()
299 int block_offset; in diRead()
300 int inodes_left; in diRead()
302 int rel_inode; in diRead()
304 jfs_info("diRead: ino = %ld", ip->i_ino); in diRead()
306 ipimap = sbi->ipimap; in diRead()
307 JFS_IP(ip)->ipimap = ipimap; in diRead()
310 iagno = INOTOIAG(ip->i_ino); in diRead()
313 imap = JFS_IP(ipimap)->i_imap; in diRead()
322 iagp = (struct iag *) mp->data; in diRead()
325 ino = ip->i_ino & (INOSPERIAG - 1); in diRead()
328 if ((lengthPXD(&iagp->inoext[extno]) != imap->im_nbperiext) || in diRead()
329 (addressPXD(&iagp->inoext[extno]) == 0)) { in diRead()
331 return -ESTALE; in diRead()
337 blkno = INOPBLK(&iagp->inoext[extno], ino, sbi->l2nbperpage); in diRead()
340 agstart = le64_to_cpu(iagp->agstart); in diRead()
344 rel_inode = (ino & (INOSPERPAGE - 1)); in diRead()
345 pageno = blkno >> sbi->l2nbperpage; in diRead()
347 if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) { in diRead()
352 (sbi->nbperpage - block_offset) << sbi->l2niperblk; in diRead()
355 rel_inode += block_offset << sbi->l2niperblk; in diRead()
358 rel_inode -= inodes_left; in diRead()
363 mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1); in diRead()
366 return -EIO; in diRead()
370 dp = (struct dinode *) mp->data; in diRead()
373 if (ip->i_ino != le32_to_cpu(dp->di_number)) { in diRead()
374 jfs_error(ip->i_sb, "i_ino != di_number\n"); in diRead()
375 rc = -EIO; in diRead()
376 } else if (le32_to_cpu(dp->di_nlink) == 0) in diRead()
377 rc = -ESTALE; in diRead()
379 /* copy the disk inode to the in-memory inode */ in diRead()
385 JFS_IP(ip)->agstart = agstart; in diRead()
386 JFS_IP(ip)->active_ag = -1; in diRead()
406 * sb - filesystem superblock
407 * inum - aggregate inode number
408 * secondary - 1 if secondary aggregate inode table
411 * new inode - success
412 * NULL - i/o error.
414 struct inode *diReadSpecial(struct super_block *sb, ino_t inum, int secondary) in diReadSpecial()
429 address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage; in diReadSpecial()
430 JFS_IP(ip)->ipimap = sbi->ipaimap2; in diReadSpecial()
433 JFS_IP(ip)->ipimap = sbi->ipaimap; in diReadSpecial()
438 ip->i_ino = inum; in diReadSpecial()
443 mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1); in diReadSpecial()
451 dp = (struct dinode *) (mp->data); in diReadSpecial()
454 /* copy on-disk inode to in-memory inode */ in diReadSpecial()
465 ip->i_mapping->a_ops = &jfs_metapage_aops; in diReadSpecial()
466 mapping_set_gfp_mask(ip->i_mapping, GFP_NOFS); in diReadSpecial()
469 ip->i_flags |= S_NOQUOTA; in diReadSpecial()
471 if ((inum == FILESYSTEM_I) && (JFS_IP(ip)->ipimap == sbi->ipaimap)) { in diReadSpecial()
472 sbi->gengen = le32_to_cpu(dp->di_gengen); in diReadSpecial()
473 sbi->inostamp = le32_to_cpu(dp->di_inostamp); in diReadSpecial()
490 * ip - special inode
491 * secondary - 1 if secondary aggregate inode table
496 void diWriteSpecial(struct inode *ip, int secondary) in diWriteSpecial()
498 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diWriteSpecial()
501 ino_t inum = ip->i_ino; in diWriteSpecial()
505 address = addressPXD(&sbi->ait2) >> sbi->l2nbperpage; in diWriteSpecial()
514 mp = read_metapage(ip, address << sbi->l2nbperpage, PSIZE, 1); in diWriteSpecial()
521 dp = (struct dinode *) (mp->data); in diWriteSpecial()
524 /* copy on-disk inode to in-memory inode */ in diWriteSpecial()
526 memcpy(&dp->di_xtroot, &JFS_IP(ip)->i_xtroot, 288); in diWriteSpecial()
529 dp->di_gengen = cpu_to_le32(sbi->gengen); in diWriteSpecial()
546 filemap_write_and_wait(ip->i_mapping); in diFreeSpecial()
547 truncate_inode_pages(ip->i_mapping, 0); in diFreeSpecial()
556 * FUNCTION: write the on-disk inode portion of the in-memory inode
557 * to its corresponding on-disk inode.
570 * tid - transacation id
571 * ip - pointer to incore inode to be written to the inode extent.
574 * 0 - success
575 * -EIO - i/o error.
577 int diWrite(tid_t tid, struct inode *ip) in diWrite()
579 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in diWrite()
581 int rc = 0; in diWrite()
585 int block_offset; in diWrite()
586 int inodes_left; in diWrite()
589 int rel_inode; in diWrite()
590 int dioffset; in diWrite()
597 int n; in diWrite()
599 ipimap = jfs_ip->ipimap; in diWrite()
601 ino = ip->i_ino & (INOSPERIAG - 1); in diWrite()
603 if (!addressPXD(&(jfs_ip->ixpxd)) || in diWrite()
604 (lengthPXD(&(jfs_ip->ixpxd)) != in diWrite()
605 JFS_IP(ipimap)->i_imap->im_nbperiext)) { in diWrite()
606 jfs_error(ip->i_sb, "ixpxd invalid\n"); in diWrite()
607 return -EIO; in diWrite()
614 blkno = INOPBLK(&(jfs_ip->ixpxd), ino, sbi->l2nbperpage); in diWrite()
616 rel_inode = (ino & (INOSPERPAGE - 1)); in diWrite()
617 pageno = blkno >> sbi->l2nbperpage; in diWrite()
619 if ((block_offset = ((u32) blkno & (sbi->nbperpage - 1)))) { in diWrite()
624 (sbi->nbperpage - block_offset) << sbi->l2niperblk; in diWrite()
627 rel_inode += block_offset << sbi->l2niperblk; in diWrite()
630 rel_inode -= inodes_left; in diWrite()
635 mp = read_metapage(ipimap, pageno << sbi->l2nbperpage, PSIZE, 1); in diWrite()
637 return -EIO; in diWrite()
640 dp = (struct dinode *) mp->data; in diWrite()
643 dioffset = (ino & (INOSPERPAGE - 1)) << L2DISIZE; in diWrite()
646 * acquire transaction lock on the on-disk inode; in diWrite()
652 dilinelock = (struct linelock *) & ditlck->lock; in diWrite()
655 * copy btree root from in-memory inode to on-disk inode in diWrite()
657 * (tlock is taken from inline B+-tree root in in-memory in diWrite()
658 * inode when the B+-tree root is updated, which is pointed in diWrite()
659 * by jfs_ip->blid as well as being on tx tlock list) in diWrite()
662 * in in-memory inode, where txLog() will log from, and, in diWrite()
667 if (S_ISDIR(ip->i_mode) && (lid = jfs_ip->xtlid)) { in diWrite()
675 jfs_ip->xtlid = 0; in diWrite()
677 assert(tlck->type & tlckXTREE); in diWrite()
678 tlck->type |= tlckBTROOT; in diWrite()
679 tlck->mp = mp; in diWrite()
680 ilinelock = (struct linelock *) & tlck->lock; in diWrite()
685 p = &jfs_ip->i_xtroot; in diWrite()
686 xp = (xtpage_t *) &dp->di_dirtable; in diWrite()
687 lv = ilinelock->lv; in diWrite()
688 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
689 memcpy(&xp->xad[lv->offset], &p->xad[lv->offset], in diWrite()
690 lv->length << L2XTSLOTSIZE); in diWrite()
693 /* reset on-disk (metadata page) xtree XAD_NEW bit */ in diWrite()
694 xad = &xp->xad[XTENTRYSTART]; in diWrite()
696 n < le16_to_cpu(xp->header.nextindex); n++, xad++) in diWrite()
697 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) in diWrite()
698 xad->flag &= ~(XAD_NEW | XAD_EXTENDED); in diWrite()
701 if ((lid = jfs_ip->blid) == 0) in diWrite()
703 jfs_ip->blid = 0; in diWrite()
706 type = tlck->type; in diWrite()
707 tlck->type |= tlckBTROOT; in diWrite()
708 tlck->mp = mp; in diWrite()
709 ilinelock = (struct linelock *) & tlck->lock; in diWrite()
721 p = &jfs_ip->i_xtroot; in diWrite()
722 xp = &dp->di_xtroot; in diWrite()
723 lv = ilinelock->lv; in diWrite()
724 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
725 memcpy(&xp->xad[lv->offset], &p->xad[lv->offset], in diWrite()
726 lv->length << L2XTSLOTSIZE); in diWrite()
729 /* reset on-disk (metadata page) xtree XAD_NEW bit */ in diWrite()
730 xad = &xp->xad[XTENTRYSTART]; in diWrite()
732 n < le16_to_cpu(xp->header.nextindex); n++, xad++) in diWrite()
733 if (xad->flag & (XAD_NEW | XAD_EXTENDED)) in diWrite()
734 xad->flag &= ~(XAD_NEW | XAD_EXTENDED); in diWrite()
745 p = (dtpage_t *) &jfs_ip->i_dtroot; in diWrite()
746 xp = (dtpage_t *) & dp->di_dtroot; in diWrite()
747 lv = ilinelock->lv; in diWrite()
748 for (n = 0; n < ilinelock->index; n++, lv++) { in diWrite()
749 memcpy(&xp->slot[lv->offset], &p->slot[lv->offset], in diWrite()
750 lv->length << L2DTSLOTSIZE); in diWrite()
758 * copy inline symlink from in-memory inode to on-disk inode in diWrite()
760 if (S_ISLNK(ip->i_mode) && ip->i_size < IDATASIZE) { in diWrite()
761 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
762 lv->offset = (dioffset + 2 * 128) >> L2INODESLOTSIZE; in diWrite()
763 lv->length = 2; in diWrite()
764 memcpy(&dp->di_inline_all, jfs_ip->i_inline_all, IDATASIZE); in diWrite()
765 dilinelock->index++; in diWrite()
768 * copy inline data from in-memory inode to on-disk inode: in diWrite()
772 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
773 lv->offset = (dioffset + 3 * 128) >> L2INODESLOTSIZE; in diWrite()
774 lv->length = 1; in diWrite()
775 memcpy(&dp->di_inlineea, jfs_ip->i_inline_ea, INODESLOTSIZE); in diWrite()
776 dilinelock->index++; in diWrite()
784 lv = & dilinelock->lv[dilinelock->index]; in diWrite()
785 lv->offset = dioffset >> L2INODESLOTSIZE; in diWrite()
788 lv->length = 2; in diWrite()
789 memcpy(&dp->di_dirtable, &jfs_ip->i_dirtable, 96); in diWrite()
791 lv->length = 1; in diWrite()
792 dilinelock->index++; in diWrite()
794 /* release the buffer holding the updated on-disk inode. in diWrite()
835 * ip - inode to be freed.
838 * 0 - success
839 * -EIO - i/o error.
841 int diFree(struct inode *ip) in diFree()
843 int rc; in diFree()
844 ino_t inum = ip->i_ino; in diFree()
847 int iagno, ino, extno, bitno, sword, agno; in diFree()
848 int back, fwd; in diFree() local
849 u32 bitmap, mask; in diFree() local
850 struct inode *ipimap = JFS_SBI(ip->i_sb)->ipimap; in diFree()
851 struct inomap *imap = JFS_IP(ipimap)->i_imap; in diFree()
871 if (iagno >= imap->im_nextiag) { in diFree()
874 jfs_error(ip->i_sb, "inum = %d, iagno = %d, nextiag = %d\n", in diFree()
875 (uint) inum, iagno, imap->im_nextiag); in diFree()
876 return -EIO; in diFree()
881 agno = BLKTOAG(JFS_IP(ip)->agstart, JFS_SBI(ip->i_sb)); in diFree()
899 iagp = (struct iag *) mp->data; in diFree()
904 ino = inum & (INOSPERIAG - 1); in diFree()
906 bitno = ino & (INOSPEREXT - 1); in diFree()
907 mask = HIGHORDER >> bitno; in diFree()
909 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diFree()
910 jfs_error(ip->i_sb, "wmap shows inode already free\n"); in diFree()
913 if (!addressPXD(&iagp->inoext[extno])) { in diFree()
917 jfs_error(ip->i_sb, "invalid inoext\n"); in diFree()
918 return -EIO; in diFree()
923 bitmap = le32_to_cpu(iagp->wmap[extno]) & ~mask; in diFree()
925 if (imap->im_agctl[agno].numfree > imap->im_agctl[agno].numinos) { in diFree()
929 jfs_error(ip->i_sb, "numfree > numinos\n"); in diFree()
930 return -EIO; in diFree()
937 imap->im_agctl[agno].numfree < 96 || in diFree()
938 (imap->im_agctl[agno].numfree < 288 && in diFree()
939 (((imap->im_agctl[agno].numfree * 100) / in diFree()
940 imap->im_agctl[agno].numinos) <= 25))) { in diFree()
945 if (iagp->nfreeinos == 0) { in diFree()
951 if ((fwd = imap->im_agctl[agno].inofree) >= 0) { in diFree()
955 if ((rc = diIAGRead(imap, fwd, &))) { in diFree()
961 aiagp = (struct iag *) amp->data; in diFree()
965 aiagp->inofreeback = cpu_to_le32(iagno); in diFree()
973 iagp->inofreefwd = in diFree()
974 cpu_to_le32(imap->im_agctl[agno].inofree); in diFree()
975 iagp->inofreeback = cpu_to_le32(-1); in diFree()
976 imap->im_agctl[agno].inofree = iagno; in diFree()
985 if (iagp->wmap[extno] == cpu_to_le32(ONES)) { in diFree()
987 bitno = extno & (EXTSPERSUM - 1); in diFree()
988 iagp->inosmap[sword] &= in diFree()
994 iagp->wmap[extno] = cpu_to_le32(bitmap); in diFree()
999 le32_add_cpu(&iagp->nfreeinos, 1); in diFree()
1000 imap->im_agctl[agno].numfree += 1; in diFree()
1001 atomic_inc(&imap->im_numfree); in diFree()
1023 fwd = back = -1; in diFree()
1028 if (iagp->nfreeexts == 0) { in diFree()
1035 if ((fwd = imap->im_agctl[agno].extfree) >= 0) { in diFree()
1036 if ((rc = diIAGRead(imap, fwd, &))) in diFree()
1038 aiagp = (struct iag *) amp->data; in diFree()
1046 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) { in diFree()
1052 if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) { in diFree()
1053 if ((rc = diIAGRead(imap, fwd, &))) in diFree()
1055 aiagp = (struct iag *) amp->data; in diFree()
1058 if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) { in diFree()
1061 biagp = (struct iag *) bmp->data; in diFree()
1069 if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) { in diFree()
1070 int inofreeback = le32_to_cpu(iagp->inofreeback); in diFree()
1071 int inofreefwd = le32_to_cpu(iagp->inofreefwd); in diFree()
1078 * from up above, since re-reading an iag (buffer) in diFree()
1083 if (inofreefwd == fwd) in diFree()
1084 ciagp = (struct iag *) amp->data; in diFree()
1086 ciagp = (struct iag *) bmp->data; in diFree()
1091 ciagp = (struct iag *) cmp->data; in diFree()
1097 if (inofreeback == fwd) in diFree()
1098 diagp = (struct iag *) amp->data; in diFree()
1100 diagp = (struct iag *) bmp->data; in diFree()
1105 diagp = (struct iag *) dmp->data; in diFree()
1116 freepxd = iagp->inoext[extno]; in diFree()
1125 if (iagp->nfreeexts == 0) { in diFree()
1126 if (fwd >= 0) in diFree()
1127 aiagp->extfreeback = cpu_to_le32(iagno); in diFree()
1129 iagp->extfreefwd = in diFree()
1130 cpu_to_le32(imap->im_agctl[agno].extfree); in diFree()
1131 iagp->extfreeback = cpu_to_le32(-1); in diFree()
1132 imap->im_agctl[agno].extfree = iagno; in diFree()
1137 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG - 1)) { in diFree()
1138 if (fwd >= 0) in diFree()
1139 aiagp->extfreeback = iagp->extfreeback; in diFree()
1142 biagp->extfreefwd = iagp->extfreefwd; in diFree()
1144 imap->im_agctl[agno].extfree = in diFree()
1145 le32_to_cpu(iagp->extfreefwd); in diFree()
1147 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diFree()
1150 iagp->iagfree = cpu_to_le32(imap->im_freeiag); in diFree()
1151 imap->im_freeiag = iagno; in diFree()
1159 if (iagp->nfreeinos == cpu_to_le32(INOSPEREXT - 1)) { in diFree()
1160 if ((int) le32_to_cpu(iagp->inofreefwd) >= 0) in diFree()
1161 ciagp->inofreeback = iagp->inofreeback; in diFree()
1163 if ((int) le32_to_cpu(iagp->inofreeback) >= 0) in diFree()
1164 diagp->inofreefwd = iagp->inofreefwd; in diFree()
1166 imap->im_agctl[agno].inofree = in diFree()
1167 le32_to_cpu(iagp->inofreefwd); in diFree()
1169 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diFree()
1177 if (iagp->pmap[extno] != 0) { in diFree()
1178 jfs_error(ip->i_sb, "the pmap does not show inode free\n"); in diFree()
1180 iagp->wmap[extno] = 0; in diFree()
1181 PXDlength(&iagp->inoext[extno], 0); in diFree()
1182 PXDaddress(&iagp->inoext[extno], 0); in diFree()
1190 bitno = extno & (EXTSPERSUM - 1); in diFree()
1191 mask = HIGHORDER >> bitno; in diFree()
1192 iagp->inosmap[sword] |= cpu_to_le32(mask); in diFree()
1193 iagp->extsmap[sword] &= cpu_to_le32(~mask); in diFree()
1198 le32_add_cpu(&iagp->nfreeinos, -(INOSPEREXT - 1)); in diFree()
1199 le32_add_cpu(&iagp->nfreeexts, 1); in diFree()
1204 imap->im_agctl[agno].numfree -= (INOSPEREXT - 1); in diFree()
1205 imap->im_agctl[agno].numinos -= INOSPEREXT; in diFree()
1206 atomic_sub(INOSPEREXT - 1, &imap->im_numfree); in diFree()
1207 atomic_sub(INOSPEREXT, &imap->im_numinos); in diFree()
1227 tid = txBegin(ipimap->i_sb, COMMIT_FORCE); in diFree()
1228 mutex_lock(&JFS_IP(ipimap)->commit_mutex); in diFree()
1238 pxdlock = (struct pxd_lock *) & tlck->lock; in diFree()
1239 pxdlock->flag = mlckFREEPXD; in diFree()
1240 pxdlock->pxd = freepxd; in diFree()
1241 pxdlock->index = 1; in diFree()
1261 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diFree()
1292 diInitInode(struct inode *ip, int iagno, int ino, int extno, struct iag * iagp) in diInitInode()
1296 ip->i_ino = (iagno << L2INOSPERIAG) + ino; in diInitInode()
1297 jfs_ip->ixpxd = iagp->inoext[extno]; in diInitInode()
1298 jfs_ip->agstart = le64_to_cpu(iagp->agstart); in diInitInode()
1299 jfs_ip->active_ag = -1; in diInitInode()
1310 * pip - pointer to incore inode for the parent inode.
1311 * dir - 'true' if the new disk inode is for a directory.
1312 * ip - pointer to a new inode
1315 * 0 - success.
1316 * -ENOSPC - insufficient disk resources.
1317 * -EIO - i/o error.
1319 int diAlloc(struct inode *pip, bool dir, struct inode *ip) in diAlloc()
1321 int rc, ino, iagno, addext, extno, bitno, sword; in diAlloc()
1322 int nwords, rem, i, agno; in diAlloc()
1323 u32 mask, inosmap, extsmap; in diAlloc() local
1333 ipimap = JFS_SBI(pip->i_sb)->ipimap; in diAlloc()
1334 imap = JFS_IP(ipimap)->i_imap; in diAlloc()
1335 JFS_IP(ip)->ipimap = ipimap; in diAlloc()
1336 JFS_IP(ip)->fileset = FILESYSTEM_I; in diAlloc()
1342 agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap); in diAlloc()
1351 * hint. (we use a left-to-right policy to attempt to avoid in diAlloc()
1357 agno = BLKTOAG(JFS_IP(pip)->agstart, JFS_SBI(pip->i_sb)); in diAlloc()
1359 if (atomic_read(&JFS_SBI(pip->i_sb)->bmap->db_active[agno])) { in diAlloc()
1365 agno = dbNextAG(JFS_SBI(pip->i_sb)->ipbmap); in diAlloc()
1370 inum = pip->i_ino + 1; in diAlloc()
1371 ino = inum & (INOSPERIAG - 1); in diAlloc()
1375 inum = pip->i_ino; in diAlloc()
1390 iagp = (struct iag *) mp->data; in diAlloc()
1396 addext = (imap->im_agctl[agno].numfree < 32 && iagp->nfreeexts); in diAlloc()
1404 if (iagp->nfreeinos || addext) { in diAlloc()
1412 if (addressPXD(&iagp->inoext[extno])) { in diAlloc()
1413 bitno = ino & (INOSPEREXT - 1); in diAlloc()
1415 diFindFree(le32_to_cpu(iagp->wmap[extno]), in diAlloc()
1426 assert(rc == -EIO); in diAlloc()
1446 EXTSPERIAG - 1) ? 0 : extno + 1; in diAlloc()
1465 bitno = extno & (EXTSPERSUM - 1); in diAlloc()
1469 /* mask any prior bits for the starting words of the in diAlloc()
1472 mask = (bitno == 0) ? 0 : (ONES << (EXTSPERSUM - bitno)); in diAlloc()
1473 inosmap = le32_to_cpu(iagp->inosmap[sword]) | mask; in diAlloc()
1474 extsmap = le32_to_cpu(iagp->extsmap[sword]) | mask; in diAlloc()
1490 rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), in diAlloc()
1496 jfs_error(ip->i_sb, in diAlloc()
1498 return -EIO; in diAlloc()
1509 assert(rc == -EIO); in diAlloc()
1545 if (rc == -ENOSPC) in diAlloc()
1548 assert(rc == -EIO); in diAlloc()
1568 sword = (sword == SMAPSZ - 1) ? 0 : sword + 1; in diAlloc()
1569 inosmap = le32_to_cpu(iagp->inosmap[sword]); in diAlloc()
1570 extsmap = le32_to_cpu(iagp->extsmap[sword]); in diAlloc()
1587 if (rc != -ENOSPC) in diAlloc()
1614 * imap - pointer to inode map control structure.
1615 * agno - allocation group to allocate from.
1616 * dir - 'true' if the new disk inode is for a directory.
1617 * ip - pointer to the new inode to be filled in on successful return
1622 * 0 - success.
1623 * -ENOSPC - insufficient disk resources.
1624 * -EIO - i/o error.
1626 static int
1627 diAllocAG(struct inomap * imap, int agno, bool dir, struct inode *ip) in diAllocAG()
1629 int rc, addext, numfree, numinos; in diAllocAG()
1634 numfree = imap->im_agctl[agno].numfree; in diAllocAG()
1635 numinos = imap->im_agctl[agno].numinos; in diAllocAG()
1638 jfs_error(ip->i_sb, "numfree > numinos\n"); in diAllocAG()
1639 return -EIO; in diAllocAG()
1662 if ((rc = diAllocExt(imap, agno, ip)) != -ENOSPC) in diAllocAG()
1684 * imap - pointer to inode map control structure.
1685 * agno - primary allocation group (to avoid).
1686 * dir - 'true' if the new disk inode is for a directory.
1687 * ip - pointer to a new inode to be filled in on successful return
1692 * 0 - success.
1693 * -ENOSPC - insufficient disk resources.
1694 * -EIO - i/o error.
1696 static int
1697 diAllocAny(struct inomap * imap, int agno, bool dir, struct inode *ip) in diAllocAny()
1699 int ag, rc; in diAllocAny()
1700 int maxag = JFS_SBI(imap->im_ipimap->i_sb)->bmap->db_maxag; in diAllocAny()
1713 if (rc != -ENOSPC) in diAllocAny()
1726 if (rc != -ENOSPC) in diAllocAny()
1732 return -ENOSPC; in diAllocAny()
1750 * imap - pointer to inode map control structure.
1751 * agno - allocation group.
1752 * ip - pointer to new inode to be filled in on successful return
1757 * 0 - success.
1758 * -ENOSPC - insufficient disk resources.
1759 * -EIO - i/o error.
1761 static int diAllocIno(struct inomap * imap, int agno, struct inode *ip) in diAllocIno()
1763 int iagno, ino, rc, rem, extno, sword; in diAllocIno()
1769 if ((iagno = imap->im_agctl[agno].inofree) < 0) in diAllocIno()
1770 return -ENOSPC; in diAllocIno()
1773 IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP); in diAllocIno()
1778 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1781 iagp = (struct iag *) mp->data; in diAllocIno()
1786 if (!iagp->nfreeinos) { in diAllocIno()
1787 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1789 jfs_error(ip->i_sb, "nfreeinos = 0, but iag on freelist\n"); in diAllocIno()
1790 return -EIO; in diAllocIno()
1798 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1800 jfs_error(ip->i_sb, in diAllocIno()
1802 return -EIO; in diAllocIno()
1805 if (~iagp->inosmap[sword]) in diAllocIno()
1812 rem = diFindFree(le32_to_cpu(iagp->inosmap[sword]), 0); in diAllocIno()
1814 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1816 jfs_error(ip->i_sb, "no free extent found\n"); in diAllocIno()
1817 return -EIO; in diAllocIno()
1823 rem = diFindFree(le32_to_cpu(iagp->wmap[extno]), 0); in diAllocIno()
1825 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1827 jfs_error(ip->i_sb, "free inode not found\n"); in diAllocIno()
1828 return -EIO; in diAllocIno()
1838 IREAD_UNLOCK(imap->im_ipimap); in diAllocIno()
1874 * imap - pointer to inode map control structure.
1875 * agno - allocation group number.
1876 * ip - pointer to new inode to be filled in on successful return
1881 * 0 - success.
1882 * -ENOSPC - insufficient disk resources.
1883 * -EIO - i/o error.
1885 static int diAllocExt(struct inomap * imap, int agno, struct inode *ip) in diAllocExt()
1887 int rem, iagno, sword, extno, rc; in diAllocExt()
1894 if ((iagno = imap->im_agctl[agno].extfree) < 0) { in diAllocExt()
1901 iagp = (struct iag *) mp->data; in diAllocExt()
1905 iagp->agstart = in diAllocExt()
1906 cpu_to_le64(AGTOBLK(agno, imap->im_ipimap)); in diAllocExt()
1910 IREAD_LOCK(imap->im_ipimap, RDWRLOCK_IMAP); in diAllocExt()
1912 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1913 jfs_error(ip->i_sb, "error reading iag\n"); in diAllocExt()
1916 iagp = (struct iag *) mp->data; in diAllocExt()
1924 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1925 jfs_error(ip->i_sb, "free ext summary map not found\n"); in diAllocExt()
1926 return -EIO; in diAllocExt()
1928 if (~iagp->extsmap[sword]) in diAllocExt()
1934 rem = diFindFree(le32_to_cpu(iagp->extsmap[sword]), 0); in diAllocExt()
1937 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1938 jfs_error(ip->i_sb, "free extent not found\n"); in diAllocExt()
1939 return -EIO; in diAllocExt()
1946 IREAD_UNLOCK(imap->im_ipimap); in diAllocExt()
1952 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diAllocExt()
1954 iagp->iagfree = cpu_to_le32(imap->im_freeiag); in diAllocExt()
1955 imap->im_freeiag = iagno; in diAllocExt()
1993 * imap - pointer to inode map control structure.
1994 * iagp - pointer to iag.
1995 * ino - inode number to be allocated within the iag.
1998 * 0 - success.
1999 * -ENOSPC - insufficient disk resources.
2000 * -EIO - i/o error.
2002 static int diAllocBit(struct inomap * imap, struct iag * iagp, int ino) in diAllocBit()
2004 int extno, bitno, agno, sword, rc; in diAllocBit()
2007 u32 mask; in diAllocBit() local
2014 if (iagp->nfreeinos == cpu_to_le32(1)) { in diAllocBit()
2015 if ((int) le32_to_cpu(iagp->inofreefwd) >= 0) { in diAllocBit()
2017 diIAGRead(imap, le32_to_cpu(iagp->inofreefwd), in diAllocBit()
2020 aiagp = (struct iag *) amp->data; in diAllocBit()
2023 if ((int) le32_to_cpu(iagp->inofreeback) >= 0) { in diAllocBit()
2026 le32_to_cpu(iagp->inofreeback), in diAllocBit()
2032 biagp = (struct iag *) bmp->data; in diAllocBit()
2039 agno = BLKTOAG(le64_to_cpu(iagp->agstart), JFS_SBI(imap->im_ipimap->i_sb)); in diAllocBit()
2041 bitno = ino & (INOSPEREXT - 1); in diAllocBit()
2043 /* compute the mask for setting the map. in diAllocBit()
2045 mask = HIGHORDER >> bitno; in diAllocBit()
2049 if (((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) || in diAllocBit()
2050 ((le32_to_cpu(iagp->wmap[extno]) & mask) != 0) || in diAllocBit()
2051 (addressPXD(&iagp->inoext[extno]) == 0)) { in diAllocBit()
2057 jfs_error(imap->im_ipimap->i_sb, "iag inconsistent\n"); in diAllocBit()
2058 return -EIO; in diAllocBit()
2063 iagp->wmap[extno] |= cpu_to_le32(mask); in diAllocBit()
2069 if (iagp->wmap[extno] == cpu_to_le32(ONES)) { in diAllocBit()
2071 bitno = extno & (EXTSPERSUM - 1); in diAllocBit()
2072 iagp->inosmap[sword] |= cpu_to_le32(HIGHORDER >> bitno); in diAllocBit()
2078 if (iagp->nfreeinos == cpu_to_le32(1)) { in diAllocBit()
2080 aiagp->inofreeback = iagp->inofreeback; in diAllocBit()
2085 biagp->inofreefwd = iagp->inofreefwd; in diAllocBit()
2088 imap->im_agctl[agno].inofree = in diAllocBit()
2089 le32_to_cpu(iagp->inofreefwd); in diAllocBit()
2091 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diAllocBit()
2097 le32_add_cpu(&iagp->nfreeinos, -1); in diAllocBit()
2098 imap->im_agctl[agno].numfree -= 1; in diAllocBit()
2099 atomic_dec(&imap->im_numfree); in diAllocBit()
2139 * imap - pointer to inode map control structure.
2140 * iagp - pointer to iag.
2141 * extno - extent number.
2144 * 0 - success.
2145 * -ENOSPC - insufficient disk resources.
2146 * -EIO - i/o error.
2148 static int diNewExt(struct inomap * imap, struct iag * iagp, int extno) in diNewExt()
2150 int agno, iagno, fwd, back, freei = 0, sword, rc; in diNewExt() local
2155 int i, j; in diNewExt()
2156 u32 mask; in diNewExt() local
2163 if (!iagp->nfreeexts) { in diNewExt()
2164 jfs_error(imap->im_ipimap->i_sb, "no free extents\n"); in diNewExt()
2165 return -EIO; in diNewExt()
2170 ipimap = imap->im_ipimap; in diNewExt()
2171 sbi = JFS_SBI(ipimap->i_sb); in diNewExt()
2177 agno = BLKTOAG(le64_to_cpu(iagp->agstart), sbi); in diNewExt()
2178 iagno = le32_to_cpu(iagp->iagnum); in diNewExt()
2185 if (iagp->nfreeexts == cpu_to_le32(1)) { in diNewExt()
2186 if ((fwd = le32_to_cpu(iagp->extfreefwd)) >= 0) { in diNewExt()
2187 if ((rc = diIAGRead(imap, fwd, &))) in diNewExt()
2189 aiagp = (struct iag *) amp->data; in diNewExt()
2192 if ((back = le32_to_cpu(iagp->extfreeback)) >= 0) { in diNewExt()
2195 biagp = (struct iag *) bmp->data; in diNewExt()
2204 fwd = back = -1; in diNewExt()
2205 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diNewExt()
2206 if ((fwd = imap->im_agctl[agno].extfree) >= 0) { in diNewExt()
2207 if ((rc = diIAGRead(imap, fwd, &))) in diNewExt()
2209 aiagp = (struct iag *) amp->data; in diNewExt()
2221 if (iagp->nfreeinos == 0) { in diNewExt()
2222 freei = imap->im_agctl[agno].inofree; in diNewExt()
2225 if (freei == fwd) { in diNewExt()
2232 ciagp = (struct iag *) cmp->data; in diNewExt()
2235 jfs_error(imap->im_ipimap->i_sb, in diNewExt()
2237 rc = -EIO; in diNewExt()
2245 if ((extno == 0) || (addressPXD(&iagp->inoext[extno - 1]) == 0)) in diNewExt()
2246 hint = ((s64) agno << sbi->bmap->db_agl2size) - 1; in diNewExt()
2248 hint = addressPXD(&iagp->inoext[extno - 1]) + in diNewExt()
2249 lengthPXD(&iagp->inoext[extno - 1]) - 1; in diNewExt()
2251 if ((rc = dbAlloc(ipimap, hint, (s64) imap->im_nbperiext, &blkno))) in diNewExt()
2262 for (i = 0; i < imap->im_nbperiext; i += sbi->nbperpage) { in diNewExt()
2267 rc = -EIO; in diNewExt()
2270 dp = (struct dinode *) dmp->data; in diNewExt()
2276 dp->di_inostamp = cpu_to_le32(sbi->inostamp); in diNewExt()
2277 dp->di_number = cpu_to_le32(ino); in diNewExt()
2278 dp->di_fileset = cpu_to_le32(FILESYSTEM_I); in diNewExt()
2279 dp->di_mode = 0; in diNewExt()
2280 dp->di_nlink = 0; in diNewExt()
2281 PXDaddress(&(dp->di_ixpxd), blkno); in diNewExt()
2282 PXDlength(&(dp->di_ixpxd), imap->im_nbperiext); in diNewExt()
2290 if (iagp->nfreeexts == cpu_to_le32(1)) { in diNewExt()
2291 if (fwd >= 0) in diNewExt()
2292 aiagp->extfreeback = iagp->extfreeback; in diNewExt()
2295 biagp->extfreefwd = iagp->extfreefwd; in diNewExt()
2297 imap->im_agctl[agno].extfree = in diNewExt()
2298 le32_to_cpu(iagp->extfreefwd); in diNewExt()
2300 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diNewExt()
2305 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diNewExt()
2306 if (fwd >= 0) in diNewExt()
2307 aiagp->extfreeback = cpu_to_le32(iagno); in diNewExt()
2309 iagp->extfreefwd = cpu_to_le32(fwd); in diNewExt()
2310 iagp->extfreeback = cpu_to_le32(-1); in diNewExt()
2311 imap->im_agctl[agno].extfree = iagno; in diNewExt()
2318 if (iagp->nfreeinos == 0) { in diNewExt()
2320 ciagp->inofreeback = cpu_to_le32(iagno); in diNewExt()
2322 iagp->inofreefwd = in diNewExt()
2323 cpu_to_le32(imap->im_agctl[agno].inofree); in diNewExt()
2324 iagp->inofreeback = cpu_to_le32(-1); in diNewExt()
2325 imap->im_agctl[agno].inofree = iagno; in diNewExt()
2329 PXDlength(&iagp->inoext[extno], imap->im_nbperiext); in diNewExt()
2330 PXDaddress(&iagp->inoext[extno], blkno); in diNewExt()
2336 iagp->wmap[extno] = cpu_to_le32(HIGHORDER); in diNewExt()
2337 iagp->pmap[extno] = 0; in diNewExt()
2344 mask = HIGHORDER >> (extno & (EXTSPERSUM - 1)); in diNewExt()
2345 iagp->extsmap[sword] |= cpu_to_le32(mask); in diNewExt()
2346 iagp->inosmap[sword] &= cpu_to_le32(~mask); in diNewExt()
2351 le32_add_cpu(&iagp->nfreeinos, (INOSPEREXT - 1)); in diNewExt()
2352 le32_add_cpu(&iagp->nfreeexts, -1); in diNewExt()
2356 imap->im_agctl[agno].numfree += (INOSPEREXT - 1); in diNewExt()
2357 imap->im_agctl[agno].numinos += INOSPEREXT; in diNewExt()
2361 atomic_add(INOSPEREXT - 1, &imap->im_numfree); in diNewExt()
2362 atomic_add(INOSPEREXT, &imap->im_numinos); in diNewExt()
2404 * imap - pointer to inode map control structure.
2405 * iagnop - pointer to an iag number set with the number of the
2407 * agno - allocation group number.
2408 * bpp - Buffer pointer to be filled in with new IAG's buffer
2411 * 0 - success.
2412 * -ENOSPC - insufficient disk resources.
2413 * -EIO - i/o error.
2425 * . at start of logredo(): init in-memory imap with one additional iag page;
2426 * . at end of logredo(): re-read imap inode to determine
2429 static int
2430 diNewIAG(struct inomap * imap, int *iagnop, int agno, struct metapage ** mpp) in diNewIAG()
2432 int rc; in diNewIAG()
2433 int iagno, i, xlen; in diNewIAG()
2445 ipimap = imap->im_ipimap; in diNewIAG()
2446 sb = ipimap->i_sb; in diNewIAG()
2455 if (imap->im_freeiag >= 0) { in diNewIAG()
2457 iagno = imap->im_freeiag; in diNewIAG()
2460 blkno = IAGTOLBLK(iagno, sbi->l2nbperpage); in diNewIAG()
2469 if (ipimap->i_size >> L2PSIZE != imap->im_nextiag + 1) { in diNewIAG()
2472 jfs_error(imap->im_ipimap->i_sb, in diNewIAG()
2473 "ipimap->i_size is wrong\n"); in diNewIAG()
2474 return -EIO; in diNewIAG()
2479 iagno = imap->im_nextiag; in diNewIAG()
2484 if (iagno > (MAXIAGS - 1)) { in diNewIAG()
2488 rc = -ENOSPC; in diNewIAG()
2496 blkno = IAGTOLBLK(iagno, sbi->l2nbperpage); in diNewIAG()
2499 xlen = sbi->nbperpage; in diNewIAG()
2512 mutex_lock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2518 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2531 ipimap->i_size += PSIZE; in diNewIAG()
2541 xtTruncate(tid, ipimap, ipimap->i_size - PSIZE, in diNewIAG()
2546 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2551 rc = -EIO; in diNewIAG()
2554 iagp = (struct iag *) mp->data; in diNewIAG()
2558 iagp->iagnum = cpu_to_le32(iagno); in diNewIAG()
2559 iagp->inofreefwd = iagp->inofreeback = cpu_to_le32(-1); in diNewIAG()
2560 iagp->extfreefwd = iagp->extfreeback = cpu_to_le32(-1); in diNewIAG()
2561 iagp->iagfree = cpu_to_le32(-1); in diNewIAG()
2562 iagp->nfreeinos = 0; in diNewIAG()
2563 iagp->nfreeexts = cpu_to_le32(EXTSPERIAG); in diNewIAG()
2569 iagp->inosmap[i] = cpu_to_le32(ONES); in diNewIAG()
2585 mutex_unlock(&JFS_IP(ipimap)->commit_mutex); in diNewIAG()
2590 imap->im_nextiag += 1; in diNewIAG()
2595 imap->im_freeiag = iagno; in diNewIAG()
2612 rc = -EIO; in diNewIAG()
2615 iagp = (struct iag *) mp->data; in diNewIAG()
2618 imap->im_freeiag = le32_to_cpu(iagp->iagfree); in diNewIAG()
2619 iagp->iagfree = cpu_to_le32(-1); in diNewIAG()
2639 * imap - pointer to inode map control structure.
2640 * iagno - iag number.
2641 * bpp - point to buffer pointer to be filled in on successful
2650 * 0 - success.
2651 * -EIO - i/o error.
2653 static int diIAGRead(struct inomap * imap, int iagno, struct metapage ** mpp) in diIAGRead()
2655 struct inode *ipimap = imap->im_ipimap; in diIAGRead()
2659 blkno = IAGTOLBLK(iagno, JFS_SBI(ipimap->i_sb)->l2nbperpage); in diIAGRead()
2664 return -EIO; in diIAGRead()
2677 * word - word to be examined.
2678 * start - starting bit position.
2684 static int diFindFree(u32 word, int start) in diFindFree()
2686 int bitno; in diFindFree()
2706 * ipimap - Incore inode map inode
2707 * inum - Number of inode to mark in permanent map
2708 * is_free - If 'true' indicates inode should be marked freed, otherwise
2714 int
2718 int rc; in diUpdatePMap()
2721 int iagno, ino, extno, bitno; in diUpdatePMap()
2723 u32 mask; in diUpdatePMap() local
2725 int lsn, difft, diffp; in diUpdatePMap()
2728 imap = JFS_IP(ipimap)->i_imap; in diUpdatePMap()
2732 if (iagno >= imap->im_nextiag) { in diUpdatePMap()
2733 jfs_error(ipimap->i_sb, "the iag is outside the map\n"); in diUpdatePMap()
2734 return -EIO; in diUpdatePMap()
2743 iagp = (struct iag *) mp->data; in diUpdatePMap()
2747 ino = inum & (INOSPERIAG - 1); in diUpdatePMap()
2749 bitno = ino & (INOSPEREXT - 1); in diUpdatePMap()
2750 mask = HIGHORDER >> bitno; in diUpdatePMap()
2760 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diUpdatePMap()
2761 jfs_error(ipimap->i_sb, in diUpdatePMap()
2765 if (!(le32_to_cpu(iagp->pmap[extno]) & mask)) { in diUpdatePMap()
2766 jfs_error(ipimap->i_sb, in diUpdatePMap()
2771 iagp->pmap[extno] &= cpu_to_le32(~mask); in diUpdatePMap()
2780 if (!(le32_to_cpu(iagp->wmap[extno]) & mask)) { in diUpdatePMap()
2782 jfs_error(ipimap->i_sb, in diUpdatePMap()
2784 return -EIO; in diUpdatePMap()
2786 if ((le32_to_cpu(iagp->pmap[extno]) & mask) != 0) { in diUpdatePMap()
2788 jfs_error(ipimap->i_sb, in diUpdatePMap()
2790 return -EIO; in diUpdatePMap()
2793 iagp->pmap[extno] |= cpu_to_le32(mask); in diUpdatePMap()
2798 lsn = tblk->lsn; in diUpdatePMap()
2799 log = JFS_SBI(tblk->sb)->log; in diUpdatePMap()
2801 if (mp->lsn != 0) { in diUpdatePMap()
2804 logdiff(diffp, mp->lsn, log); in diUpdatePMap()
2806 mp->lsn = lsn; in diUpdatePMap()
2808 list_move(&mp->synclist, &tblk->synclist); in diUpdatePMap()
2811 assert(mp->clsn); in diUpdatePMap()
2812 logdiff(difft, tblk->clsn, log); in diUpdatePMap()
2813 logdiff(diffp, mp->clsn, log); in diUpdatePMap()
2815 mp->clsn = tblk->clsn; in diUpdatePMap()
2817 mp->log = log; in diUpdatePMap()
2818 mp->lsn = lsn; in diUpdatePMap()
2820 log->count++; in diUpdatePMap()
2821 list_add(&mp->synclist, &tblk->synclist); in diUpdatePMap()
2822 mp->clsn = tblk->clsn; in diUpdatePMap()
2837 int diExtendFS(struct inode *ipimap, struct inode *ipbmap) in diExtendFS()
2839 int rc, rcx = 0; in diExtendFS()
2840 struct inomap *imap = JFS_IP(ipimap)->i_imap; in diExtendFS()
2842 struct bmap *mp = JFS_SBI(ipbmap->i_sb)->bmap; in diExtendFS()
2844 int i, n, head; in diExtendFS()
2845 int numinos, xnuminos = 0, xnumfree = 0; in diExtendFS()
2849 imap->im_nextiag, atomic_read(&imap->im_numinos), in diExtendFS()
2850 atomic_read(&imap->im_numfree)); in diExtendFS()
2856 * i.e., (AGi, ..., AGj) where i = k*n and j = k*(n+1) - 1 to AGn; in diExtendFS()
2862 imap->im_agctl[i].inofree = -1; in diExtendFS()
2863 imap->im_agctl[i].extfree = -1; in diExtendFS()
2864 imap->im_agctl[i].numinos = 0; /* number of backed inodes */ in diExtendFS()
2865 imap->im_agctl[i].numfree = 0; /* number of free backed inodes */ in diExtendFS()
2873 for (i = 0; i < imap->im_nextiag; i++) { in diExtendFS()
2878 iagp = (struct iag *) bp->data; in diExtendFS()
2879 if (le32_to_cpu(iagp->iagnum) != i) { in diExtendFS()
2881 jfs_error(ipimap->i_sb, "unexpected value of iagnum\n"); in diExtendFS()
2882 return -EIO; in diExtendFS()
2886 if (iagp->nfreeexts == cpu_to_le32(EXTSPERIAG)) { in diExtendFS()
2891 agstart = le64_to_cpu(iagp->agstart); in diExtendFS()
2892 n = agstart >> mp->db_agl2size; in diExtendFS()
2893 iagp->agstart = cpu_to_le64((s64)n << mp->db_agl2size); in diExtendFS()
2896 numinos = (EXTSPERIAG - le32_to_cpu(iagp->nfreeexts)) in diExtendFS()
2900 imap->im_agctl[n].numinos += numinos; in diExtendFS()
2905 if ((int) le32_to_cpu(iagp->nfreeinos) > 0) { in diExtendFS()
2906 if ((head = imap->im_agctl[n].inofree) == -1) { in diExtendFS()
2907 iagp->inofreefwd = cpu_to_le32(-1); in diExtendFS()
2908 iagp->inofreeback = cpu_to_le32(-1); in diExtendFS()
2914 hiagp = (struct iag *) hbp->data; in diExtendFS()
2915 hiagp->inofreeback = iagp->iagnum; in diExtendFS()
2916 iagp->inofreefwd = cpu_to_le32(head); in diExtendFS()
2917 iagp->inofreeback = cpu_to_le32(-1); in diExtendFS()
2921 imap->im_agctl[n].inofree = in diExtendFS()
2922 le32_to_cpu(iagp->iagnum); in diExtendFS()
2925 imap->im_agctl[n].numfree += in diExtendFS()
2926 le32_to_cpu(iagp->nfreeinos); in diExtendFS()
2927 xnumfree += le32_to_cpu(iagp->nfreeinos); in diExtendFS()
2931 if (le32_to_cpu(iagp->nfreeexts) > 0) { in diExtendFS()
2932 if ((head = imap->im_agctl[n].extfree) == -1) { in diExtendFS()
2933 iagp->extfreefwd = cpu_to_le32(-1); in diExtendFS()
2934 iagp->extfreeback = cpu_to_le32(-1); in diExtendFS()
2940 hiagp = (struct iag *) hbp->data; in diExtendFS()
2941 hiagp->extfreeback = iagp->iagnum; in diExtendFS()
2942 iagp->extfreefwd = cpu_to_le32(head); in diExtendFS()
2943 iagp->extfreeback = cpu_to_le32(-1); in diExtendFS()
2947 imap->im_agctl[n].extfree = in diExtendFS()
2948 le32_to_cpu(iagp->iagnum); in diExtendFS()
2955 if (xnuminos != atomic_read(&imap->im_numinos) || in diExtendFS()
2956 xnumfree != atomic_read(&imap->im_numfree)) { in diExtendFS()
2957 jfs_error(ipimap->i_sb, "numinos or numfree incorrect\n"); in diExtendFS()
2958 return -EIO; in diExtendFS()
2973 int xlen, s64 *xaddr) in duplicateIXtree()
2981 if (JFS_SBI(sb)->mntflag & JFS_BAD_SAIT) /* s_flag */ in duplicateIXtree()
2985 JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT; in duplicateIXtree()
2988 j_sb = (struct jfs_superblock *)bh->b_data; in duplicateIXtree()
2989 j_sb->s_flag |= cpu_to_le32(JFS_BAD_SAIT); in duplicateIXtree()
3001 JFS_SBI(sb)->mntflag |= JFS_BAD_SAIT; in duplicateIXtree()
3007 ip->i_size += PSIZE; in duplicateIXtree()
3018 * FUNCTION: Copies inode info from disk inode to in-memory inode
3021 * 0 - success
3022 * -ENOMEM - insufficient memory
3024 static int copy_from_dinode(struct dinode * dip, struct inode *ip) in copy_from_dinode()
3027 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in copy_from_dinode()
3029 jfs_ip->fileset = le32_to_cpu(dip->di_fileset); in copy_from_dinode()
3030 jfs_ip->mode2 = le32_to_cpu(dip->di_mode); in copy_from_dinode()
3033 ip->i_mode = le32_to_cpu(dip->di_mode) & 0xffff; in copy_from_dinode()
3034 if (sbi->umask != -1) { in copy_from_dinode()
3035 ip->i_mode = (ip->i_mode & ~0777) | (0777 & ~sbi->umask); in copy_from_dinode()
3037 if (S_ISDIR(ip->i_mode)) { in copy_from_dinode()
3038 if (ip->i_mode & 0400) in copy_from_dinode()
3039 ip->i_mode |= 0100; in copy_from_dinode()
3040 if (ip->i_mode & 0040) in copy_from_dinode()
3041 ip->i_mode |= 0010; in copy_from_dinode()
3042 if (ip->i_mode & 0004) in copy_from_dinode()
3043 ip->i_mode |= 0001; in copy_from_dinode()
3046 set_nlink(ip, le32_to_cpu(dip->di_nlink)); in copy_from_dinode()
3048 jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid)); in copy_from_dinode()
3049 if (!uid_valid(sbi->uid)) in copy_from_dinode()
3050 ip->i_uid = jfs_ip->saved_uid; in copy_from_dinode()
3052 ip->i_uid = sbi->uid; in copy_from_dinode()
3055 jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid)); in copy_from_dinode()
3056 if (!gid_valid(sbi->gid)) in copy_from_dinode()
3057 ip->i_gid = jfs_ip->saved_gid; in copy_from_dinode()
3059 ip->i_gid = sbi->gid; in copy_from_dinode()
3062 ip->i_size = le64_to_cpu(dip->di_size); in copy_from_dinode()
3063 ip->i_atime.tv_sec = le32_to_cpu(dip->di_atime.tv_sec); in copy_from_dinode()
3064 ip->i_atime.tv_nsec = le32_to_cpu(dip->di_atime.tv_nsec); in copy_from_dinode()
3065 ip->i_mtime.tv_sec = le32_to_cpu(dip->di_mtime.tv_sec); in copy_from_dinode()
3066 ip->i_mtime.tv_nsec = le32_to_cpu(dip->di_mtime.tv_nsec); in copy_from_dinode()
3067 ip->i_ctime.tv_sec = le32_to_cpu(dip->di_ctime.tv_sec); in copy_from_dinode()
3068 ip->i_ctime.tv_nsec = le32_to_cpu(dip->di_ctime.tv_nsec); in copy_from_dinode()
3069 ip->i_blocks = LBLK2PBLK(ip->i_sb, le64_to_cpu(dip->di_nblocks)); in copy_from_dinode()
3070 ip->i_generation = le32_to_cpu(dip->di_gen); in copy_from_dinode()
3072 jfs_ip->ixpxd = dip->di_ixpxd; /* in-memory pxd's are little-endian */ in copy_from_dinode()
3073 jfs_ip->acl = dip->di_acl; /* as are dxd's */ in copy_from_dinode()
3074 jfs_ip->ea = dip->di_ea; in copy_from_dinode()
3075 jfs_ip->next_index = le32_to_cpu(dip->di_next_index); in copy_from_dinode()
3076 jfs_ip->otime = le32_to_cpu(dip->di_otime.tv_sec); in copy_from_dinode()
3077 jfs_ip->acltype = le32_to_cpu(dip->di_acltype); in copy_from_dinode()
3079 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) { in copy_from_dinode()
3080 jfs_ip->dev = le32_to_cpu(dip->di_rdev); in copy_from_dinode()
3081 ip->i_rdev = new_decode_dev(jfs_ip->dev); in copy_from_dinode()
3084 if (S_ISDIR(ip->i_mode)) { in copy_from_dinode()
3085 memcpy(&jfs_ip->u.dir, &dip->u._dir, 384); in copy_from_dinode()
3086 } else if (S_ISREG(ip->i_mode) || S_ISLNK(ip->i_mode)) { in copy_from_dinode()
3087 memcpy(&jfs_ip->i_xtroot, &dip->di_xtroot, 288); in copy_from_dinode()
3089 memcpy(&jfs_ip->i_inline_ea, &dip->di_inlineea, 128); in copy_from_dinode()
3091 /* Zero the in-memory-only stuff */ in copy_from_dinode()
3092 jfs_ip->cflag = 0; in copy_from_dinode()
3093 jfs_ip->btindex = 0; in copy_from_dinode()
3094 jfs_ip->btorder = 0; in copy_from_dinode()
3095 jfs_ip->bxflag = 0; in copy_from_dinode()
3096 jfs_ip->blid = 0; in copy_from_dinode()
3097 jfs_ip->atlhead = 0; in copy_from_dinode()
3098 jfs_ip->atltail = 0; in copy_from_dinode()
3099 jfs_ip->xtlid = 0; in copy_from_dinode()
3106 * FUNCTION: Copies inode info from in-memory inode to disk inode
3111 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb); in copy_to_dinode()
3113 dip->di_fileset = cpu_to_le32(jfs_ip->fileset); in copy_to_dinode()
3114 dip->di_inostamp = cpu_to_le32(sbi->inostamp); in copy_to_dinode()
3115 dip->di_number = cpu_to_le32(ip->i_ino); in copy_to_dinode()
3116 dip->di_gen = cpu_to_le32(ip->i_generation); in copy_to_dinode()
3117 dip->di_size = cpu_to_le64(ip->i_size); in copy_to_dinode()
3118 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks)); in copy_to_dinode()
3119 dip->di_nlink = cpu_to_le32(ip->i_nlink); in copy_to_dinode()
3120 if (!uid_valid(sbi->uid)) in copy_to_dinode()
3121 dip->di_uid = cpu_to_le32(i_uid_read(ip)); in copy_to_dinode()
3123 dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns, in copy_to_dinode()
3124 jfs_ip->saved_uid)); in copy_to_dinode()
3125 if (!gid_valid(sbi->gid)) in copy_to_dinode()
3126 dip->di_gid = cpu_to_le32(i_gid_read(ip)); in copy_to_dinode()
3128 dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns, in copy_to_dinode()
3129 jfs_ip->saved_gid)); in copy_to_dinode()
3134 if (sbi->umask == -1) in copy_to_dinode()
3135 dip->di_mode = cpu_to_le32((jfs_ip->mode2 & 0xffff0000) | in copy_to_dinode()
3136 ip->i_mode); in copy_to_dinode()
3138 dip->di_mode = cpu_to_le32(jfs_ip->mode2); in copy_to_dinode()
3140 dip->di_atime.tv_sec = cpu_to_le32(ip->i_atime.tv_sec); in copy_to_dinode()
3141 dip->di_atime.tv_nsec = cpu_to_le32(ip->i_atime.tv_nsec); in copy_to_dinode()
3142 dip->di_ctime.tv_sec = cpu_to_le32(ip->i_ctime.tv_sec); in copy_to_dinode()
3143 dip->di_ctime.tv_nsec = cpu_to_le32(ip->i_ctime.tv_nsec); in copy_to_dinode()
3144 dip->di_mtime.tv_sec = cpu_to_le32(ip->i_mtime.tv_sec); in copy_to_dinode()
3145 dip->di_mtime.tv_nsec = cpu_to_le32(ip->i_mtime.tv_nsec); in copy_to_dinode()
3146 dip->di_ixpxd = jfs_ip->ixpxd; /* in-memory pxd's are little-endian */ in copy_to_dinode()
3147 dip->di_acl = jfs_ip->acl; /* as are dxd's */ in copy_to_dinode()
3148 dip->di_ea = jfs_ip->ea; in copy_to_dinode()
3149 dip->di_next_index = cpu_to_le32(jfs_ip->next_index); in copy_to_dinode()
3150 dip->di_otime.tv_sec = cpu_to_le32(jfs_ip->otime); in copy_to_dinode()
3151 dip->di_otime.tv_nsec = 0; in copy_to_dinode()
3152 dip->di_acltype = cpu_to_le32(jfs_ip->acltype); in copy_to_dinode()
3153 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) in copy_to_dinode()
3154 dip->di_rdev = cpu_to_le32(jfs_ip->dev); in copy_to_dinode()