Home | History | Annotate | Download | only in resize_ffs

Lines Matching defs:cg

77 /* size of a cg, in bytes, rounded up to a frag boundary */
108 /* a cg's worth of brand new squeaky-clean inodes */
113 static struct cg **cgs;
118 /* per-cg flags, indexed by cg number */
325 * them into and initializes the per-cg flags.
330 uint32_t cg;
334 cgs = nfmalloc(oldsb->fs_ncg * sizeof(*cgs), "cg pointers");
336 cgflags = nfmalloc(oldsb->fs_ncg, "cg flags");
337 csums = nfmalloc(oldsb->fs_cssize, "cg summary");
338 for (cg = 0; cg < oldsb->fs_ncg; cg++) {
339 cgs[cg] = (struct cg *) cgp;
340 readat(FFS_FSBTODB(oldsb, cgtod(oldsb, cg)), cgp, cgblksz);
342 ffs_cg_swap(cgs[cg],cgs[cg],oldsb);
343 cgflags[cg] = 0;
453 * Initialize a new cg. Called when growing. Assumes memory has been
455 * the cg, initializes the bitmaps (and cluster summaries, if
457 * summary info in newsb; it also writes out new inodes for the cg.
459 * This code knows it can never be called for cg 0, which makes it a
465 struct cg *cg; /* The in-core cg, of course */
466 int64_t base; /* Disk address of cg base */
467 int64_t dlow; /* Size of pre-cg data area */
472 int start; /* start of cg maps */
474 cg = cgs[cgn];
482 start = (unsigned char *)&cg->cg_space[0] - (unsigned char *) cg;
484 * Clear out the cg - assumes all-0-bytes is the correct way
489 memset(cg, 0, newsb->fs_cgsize);
491 cg->cg_time = newsb->fs_time;
492 cg->cg_magic = CG_MAGIC;
493 cg->cg_cgx = cgn;
494 cg->cg_niblk = newsb->fs_ipg;
495 cg->cg_ndblk = dmax;
498 cg->cg_time = newsb->fs_time;
499 cg->cg_initediblk = newsb->fs_ipg < 2 * FFS_INOPB(newsb) ?
501 cg->cg_iusedoff = start;
503 cg->cg_old_time = newsb->fs_time;
504 cg->cg_old_niblk = cg->cg_niblk;
505 cg->cg_niblk = 0;
506 cg->cg_initediblk = 0;
509 cg->cg_old_ncyl = newsb->fs_old_cpg;
513 cg->cg_old_ncyl = newsb->fs_old_ncyl %
518 * to lay out the cg _exactly_ the way mkfs and fsck
519 * do it, since fsck compares the _entire_ cg against
520 * a recomputed cg, and whines if there is any
523 cg->cg_old_btotoff = start;
524 cg->cg_old_boff = cg->cg_old_btotoff
526 cg->cg_iusedoff = cg->cg_old_boff +
529 cg->cg_freeoff = cg->cg_iusedoff + howmany(newsb->fs_ipg, NBBY);
531 cg->cg_nclusterblks = cg->cg_ndblk / newsb->fs_frag;
532 cg->cg_clustersumoff = cg->cg_freeoff +
534 cg->cg_clustersumoff =
535 roundup(cg->cg_clustersumoff, sizeof(int32_t));
536 cg->cg_clusteroff = cg->cg_clustersumoff +
538 cg->cg_nextfreeoff = cg->cg_clusteroff +
542 set_bits(cg_clustersfree(cg, 0), 0, n);
543 cg_clustersum(cg, 0)[(n > newsb->fs_contigsumsize) ?
547 cg->cg_nextfreeoff = cg->cg_freeoff +
552 set_bits(cg_blksfree(cg, 0), 0, dlow);
553 set_bits(cg_blksfree(cg, 0), dhigh, dmax - dhigh);
555 cg->cg_cs.cs_ndir = 0;
556 cg->cg_cs.cs_nifree = newsb->fs_ipg;
557 cg->cg_cs.cs_nbfree = dlow / newsb->fs_frag;
558 cg->cg_cs.cs_nffree = 0;
572 old_cg_blktot(cg, 0)[old_cbtocylno(newsb, di)]++;
573 old_cg_blks(newsb, cg,
585 cg->cg_frsum[n]++;
586 cg->cg_cs.cs_nffree += n;
592 cg->cg_cs.cs_nbfree += n;
595 set_bits(cg_clustersfree(cg, 0), i, n);
596 cg_clustersum(cg, 0)[(n > newsb->fs_contigsumsize) ?
601 old_cg_blktot(cg, 0)[old_cbtocylno(newsb,
603 old_cg_blks(newsb, cg,
611 /* Deal with any leftover frag at the end of the cg. */
614 cg->cg_frsum[i]++;
615 cg->cg_cs.cs_nffree += i;
618 csums[cgn] = cg->cg_cs;
619 newsb->fs_cstotal.cs_nffree += cg->cg_cs.cs_nffree;
620 newsb->fs_cstotal.cs_nbfree += cg->cg_cs.cs_nbfree;
621 newsb->fs_cstotal.cs_nifree += cg->cg_cs.cs_nifree;
625 cg->cg_initediblk * sizeof(*zinodes2));
631 /* Dirty the cg. */
636 * attention to block boundaries, but refuses to straddle cg
660 int cgsize; /* size of the cg hand currently points into */
661 uint32_t cgn; /* number of cg hand currently points into */
662 int fwc; /* frag-within-cg number of frag hand points
667 unsigned char *bits; /* cg_blksfree()[] for cg hand points into */
714 uint32_t cgn; /* cg number of cg hand points into */
715 int fwc; /* frag-within-cg number of frag hand points
717 int cgsize; /* size of cg hand points into */
719 unsigned char *bits; /* cg_blksfree()[] for cg hand points into */
757 uint32_t cgn; /* cg number of cg hand points into */
758 uint32_t iwc; /* inode-within-cg number of inode hand points
761 unsigned char *bits; /* cg_inosused()[] for cg hand points into */
788 * for the appropriate cg, and marks the cg as dirty.
801 * for the appropriate cg, and marks the cg as dirty.
830 int cgn; /* cg number, used when shrinking */
850 * the csum area to grow, we must be adding at least one cg, so the
853 /* XXX what if csum info is at end of cg and grows into next cg, what
854 * if it spills over onto the next cg's backup superblock? Can this
893 * data blocks in that cg to the total.
904 int64_t dmax; /* total size of cg */
905 int64_t base; /* base of cg, since cgsblock() etc add it in */
914 /* Space in cg 0 before cgsblock is boot area, not free space! */
952 /* Does the last cg end before the end of its inode area? There is no
1026 csums = nfrealloc(csums, newsb->fs_cssize, "new cg summary");
1032 "cg pointers");
1033 cgflags = nfrealloc(cgflags, newsb->fs_ncg, "cg flags");
1039 cgs[i] = (struct cg *) cgp;
1040 progress_bar(special, "grow cg",
1048 /* If the old fs ended partway through a cg, we have to update the old
1049 * last cg (though possibly not to a full cg!). */
1051 struct cg *cg;
1055 cg = cgs[oldsb->fs_ncg - 1];
1062 set_bits(cg_blksfree(cg, 0), oldcgsize, newcgsize - oldcgsize);
1063 cg->cg_old_ncyl = oldsb->fs_old_cpg;
1064 cg->cg_ndblk = newcgsize;
1327 /* Helper function - evict n frags, starting with start (cg-relative).
1332 fragmove(struct cg * cg, int64_t base, unsigned int start, unsigned int n)
1339 if ((i < n) && bit_is_clr(cg_blksfree(cg, 0), start + i)) {
1348 set_bits(cg_blksfree(cg, 0), start + i - run,
1358 * Evict all data blocks from the given cg, starting at minfrag (based
1359 * at the beginning of the cg), for length nfrag. The eviction is
1361 * range overlapping the metadata structures in the cg. It also
1362 * assumes minfrag points into the given cg; it will misbehave if this
1369 evict_data(struct cg * cg, unsigned int minfrag, int nfrag)
1371 int64_t base; /* base of cg (in frags from beginning of fs) */
1373 base = cgbase(oldsb, cg->cg_cgx);
1389 if (!blk_is_set(cg_blksfree(cg, 0), minfrag, oldsb->fs_frag)) {
1390 if (blk_is_clr(cg_blksfree(cg, 0), minfrag,
1397 set_bits(cg_blksfree(cg, 0), minfrag,
1402 fragmove(cg, base, minfrag, oldsb->fs_frag);
1410 fragmove(cg, base, minfrag, nfrag);
1635 * Evict all inodes from the specified cg. shrink() already checked
1642 evict_inodes(struct cg * cg)
1648 inum = newsb->fs_ipg * cg->cg_cgx;
1656 clr_bits(cg_inosused(cg, 0), i, 1);
1804 /* Update the new last cg. */
1807 /* Is the new last cg partial? If so, evict any data from the part
1810 struct cg *cg;
1813 cg = cgs[newsb->fs_ncg - 1];
1819 evict_data(cg, newcgsize, oldcgsize - newcgsize);
1820 clr_bits(cg_blksfree(cg, 0), newcgsize, oldcgsize - newcgsize);
1861 * position summaries, for a given cg (specified by number), based on
1867 struct cg *cg;
1875 cg = cgs[cgn];
1877 newsb->fs_cstotal.cs_nffree -= cg->cg_cs.cs_nffree;
1878 newsb->fs_cstotal.cs_nbfree -= cg->cg_cs.cs_nbfree;
1880 cg->cg_cs.cs_nffree = 0;
1881 cg->cg_cs.cs_nbfree = 0;
1882 memset(&cg->cg_frsum[0], 0, MAXFRAG * sizeof(cg->cg_frsum[0]));
1883 memset(&old_cg_blktot(cg, 0)[0], 0,
1884 newsb->fs_old_cpg * sizeof(old_cg_blktot(cg, 0)[0]));
1885 memset(&old_cg_blks(newsb, cg, 0, 0)[0], 0,
1887 sizeof(old_cg_blks(newsb, cg, 0, 0)[0]));
1889 cg->cg_nclusterblks = cg->cg_ndblk / newsb->fs_frag;
1890 memset(&cg_clustersum(cg, 0)[1], 0,
1892 sizeof(cg_clustersum(cg, 0)[1]));
1894 memset(&cg_clustersfree(cg, 0)[0], 0,
1897 memset(&cg_clustersfree(cg, 0)[0], 0,
1911 while (f < cg->cg_ndblk) {
1912 if (bit_is_set(cg_blksfree(cg, 0), f)) {
1917 cg->cg_frsum[fragrun]++;
1918 cg->cg_cs.cs_nffree += fragrun;
1926 cg->cg_cs.cs_nbfree++;
1928 set_bits(cg_clustersfree(cg, 0), b, 1);
1930 old_cg_blktot(cg, 0)[
1933 old_cg_blks(newsb, cg,
1942 cg->cg_frsum[fragrun]++;
1943 cg->cg_cs.cs_nffree += fragrun;
1947 cg_clustersum(cg, 0)[(blkrun
1962 cg->cg_frsum[fragrun]++;
1963 cg->cg_cs.cs_nffree += fragrun;
1966 cg_clustersum(cg, 0)[(blkrun > newsb->fs_contigsumsize) ?
1971 * back into the sb's summary info. Then mark the cg dirty.
1973 csums[cgn] = cg->cg_cs;
1974 newsb->fs_cstotal.cs_nffree += cg->cg_cs.cs_nffree;
1975 newsb->fs_cstotal.cs_nbfree += cg->cg_cs.cs_nbfree;
1980 * values, for a cg, based on the in-core inodes for that cg.
1985 struct cg *cg;
1989 cg = cgs[cgn];
1990 newsb->fs_cstotal.cs_ndir -= cg->cg_cs.cs_ndir;
1991 newsb->fs_cstotal.cs_nifree -= cg->cg_cs.cs_nifree;
1992 cg->cg_cs.cs_ndir = 0;
1993 cg->cg_cs.cs_nifree = 0;
1994 memset(&cg_inosused(cg, 0)[0], 0, howmany(newsb->fs_ipg, NBBY));
1997 set_bits(cg_inosused(cg, 0), 0, 2);
2006 cg->cg_cs.cs_nifree++;
2009 cg->cg_cs.cs_ndir++;
2012 set_bits(cg_inosused(cg, 0), iwc, 1);
2016 csums[cgn] = cg->cg_cs;
2017 newsb->fs_cstotal.cs_ndir += cg->cg_cs.cs_ndir;
2018 newsb->fs_cstotal.cs_nifree += cg->cg_cs.cs_nifree;
2030 progress_bar(special, "flush cg",
2055 * Write the superblock, both to the main superblock and to each cg's