diff options
author | pfg <pfg@FreeBSD.org> | 2016-04-26 15:38:17 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2016-04-26 15:38:17 +0000 |
commit | fc01419148d065603607b1008d536431465f3bc3 (patch) | |
tree | 1bff72784c0591a61e4e16e97fae48d0614891dc /sys/geom | |
parent | 3a3f015eb3ae533a46cf30b5262d15cb4b5db097 (diff) | |
download | FreeBSD-src-fc01419148d065603607b1008d536431465f3bc3.zip FreeBSD-src-fc01419148d065603607b1008d536431465f3bc3.tar.gz |
sys: extend use of the howmany() macro when available.
We have a howmany() macro in the <sys/param.h> header that is
convenient to re-use as it makes things easier to read.
Diffstat (limited to 'sys/geom')
-rw-r--r-- | sys/geom/part/g_part_gpt.c | 17 | ||||
-rw-r--r-- | sys/geom/part/g_part_ldm.c | 3 | ||||
-rw-r--r-- | sys/geom/raid/md_ddf.c | 62 | ||||
-rw-r--r-- | sys/geom/raid/md_intel.c | 2 | ||||
-rw-r--r-- | sys/geom/uzip/g_uzip.c | 7 |
5 files changed, 44 insertions, 47 deletions
diff --git a/sys/geom/part/g_part_gpt.c b/sys/geom/part/g_part_gpt.c index 465bb5e..f9017ab 100644 --- a/sys/geom/part/g_part_gpt.c +++ b/sys/geom/part/g_part_gpt.c @@ -472,8 +472,7 @@ gpt_read_hdr(struct g_part_gpt_table *table, struct g_consumer *cp, hdr->hdr_lba_table <= hdr->hdr_lba_end) goto fail; lba = hdr->hdr_lba_table + - (hdr->hdr_entries * hdr->hdr_entsz + pp->sectorsize - 1) / - pp->sectorsize - 1; + howmany(hdr->hdr_entries * hdr->hdr_entsz, pp->sectorsize) - 1; if (lba >= last) goto fail; if (lba >= hdr->hdr_lba_start && lba <= hdr->hdr_lba_end) @@ -515,7 +514,7 @@ gpt_read_tbl(struct g_part_gpt_table *table, struct g_consumer *cp, table->state[elt] = GPT_STATE_MISSING; tblsz = hdr->hdr_entries * hdr->hdr_entsz; - sectors = (tblsz + pp->sectorsize - 1) / pp->sectorsize; + sectors = howmany(tblsz, pp->sectorsize); buf = g_malloc(sectors * pp->sectorsize, M_WAITOK | M_ZERO); for (idx = 0; idx < sectors; idx += MAXPHYS / pp->sectorsize) { size = (sectors - idx > MAXPHYS / pp->sectorsize) ? MAXPHYS: @@ -653,8 +652,8 @@ g_part_gpt_create(struct g_part_table *basetable, struct g_part_parms *gpp) table = (struct g_part_gpt_table *)basetable; pp = gpp->gpp_provider; - tblsz = (basetable->gpt_entries * sizeof(struct gpt_ent) + - pp->sectorsize - 1) / pp->sectorsize; + tblsz = howmany(basetable->gpt_entries * sizeof(struct gpt_ent), + pp->sectorsize); if (pp->sectorsize < MBRSIZE || pp->mediasize < (3 + 2 * tblsz + basetable->gpt_entries) * pp->sectorsize) @@ -1134,8 +1133,8 @@ g_part_gpt_write(struct g_part_table *basetable, struct g_consumer *cp) pp = cp->provider; table = (struct g_part_gpt_table *)basetable; - tblsz = (table->hdr->hdr_entries * table->hdr->hdr_entsz + - pp->sectorsize - 1) / pp->sectorsize; + tblsz = howmany(table->hdr->hdr_entries * table->hdr->hdr_entsz, + pp->sectorsize); /* Reconstruct the MBR from the GPT if under Boot Camp. */ if (table->bootcamp) @@ -1239,8 +1238,8 @@ g_gpt_set_defaults(struct g_part_table *basetable, struct g_provider *pp) table = (struct g_part_gpt_table *)basetable; last = pp->mediasize / pp->sectorsize - 1; - tblsz = (basetable->gpt_entries * sizeof(struct gpt_ent) + - pp->sectorsize - 1) / pp->sectorsize; + tblsz = howmany(basetable->gpt_entries * sizeof(struct gpt_ent), + pp->sectorsize); table->lba[GPT_ELT_PRIHDR] = 1; table->lba[GPT_ELT_PRITBL] = 2; diff --git a/sys/geom/part/g_part_ldm.c b/sys/geom/part/g_part_ldm.c index 374a77a..33555ce 100644 --- a/sys/geom/part/g_part_ldm.c +++ b/sys/geom/part/g_part_ldm.c @@ -1013,8 +1013,7 @@ ldm_vmdb_parse(struct ldm_db *db, struct g_consumer *cp) int error; pp = cp->provider; - size = (db->dh.last_seq * db->dh.size + - pp->sectorsize - 1) / pp->sectorsize; + size = howmany(db->dh.last_seq * db->dh.size, pp->sectorsize); size -= 1; /* one sector takes vmdb header */ for (n = 0; n < size; n += MAXPHYS / pp->sectorsize) { offset = db->ph.db_offset + db->th.conf_offset + n + 1; diff --git a/sys/geom/raid/md_ddf.c b/sys/geom/raid/md_ddf.c index eed048d..686bd4d 100644 --- a/sys/geom/raid/md_ddf.c +++ b/sys/geom/raid/md_ddf.c @@ -593,35 +593,36 @@ ddf_meta_create(struct g_raid_disk *disk, struct ddf_meta *sample) memcpy(meta->hdr, sample->hdr, sizeof(struct ddf_header)); if (ss != sample->sectorsize) { SET32(meta, hdr->WorkSpace_Length, - (GET32(sample, hdr->WorkSpace_Length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->WorkSpace_Length) * + sample->sectorsize, ss)); SET16(meta, hdr->Configuration_Record_Length, - (GET16(sample, hdr->Configuration_Record_Length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET16(sample, + hdr->Configuration_Record_Length) * + sample->sectorsize, ss)); SET32(meta, hdr->cd_length, - (GET32(sample, hdr->cd_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->cd_length) * + sample->sectorsize, ss)); SET32(meta, hdr->pdr_length, - (GET32(sample, hdr->pdr_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->pdr_length) * + sample->sectorsize, ss)); SET32(meta, hdr->vdr_length, - (GET32(sample, hdr->vdr_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->vdr_length) * + sample->sectorsize, ss)); SET32(meta, hdr->cr_length, - (GET32(sample, hdr->cr_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->cr_length) * + sample->sectorsize, ss)); SET32(meta, hdr->pdd_length, - (GET32(sample, hdr->pdd_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->pdd_length) * + sample->sectorsize, ss)); SET32(meta, hdr->bbmlog_length, - (GET32(sample, hdr->bbmlog_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->bbmlog_length) * + sample->sectorsize, ss)); SET32(meta, hdr->Diagnostic_Space, - (GET32(sample, hdr->bbmlog_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->bbmlog_length) * + sample->sectorsize, ss)); SET32(meta, hdr->Vendor_Specific_Logs, - (GET32(sample, hdr->bbmlog_length) * - sample->sectorsize + ss - 1) / ss); + howmany(GET32(sample, hdr->bbmlog_length) * + sample->sectorsize, ss)); } } else { SET32(meta, hdr->Signature, DDF_HEADER_SIGNATURE); @@ -635,24 +636,23 @@ ddf_meta_create(struct g_raid_disk *disk, struct ddf_meta *sample) SET16(meta, hdr->Max_Partitions, DDF_MAX_PARTITIONS); SET16(meta, hdr->Max_Primary_Element_Entries, DDF_MAX_DISKS); SET16(meta, hdr->Configuration_Record_Length, - (sizeof(struct ddf_vdc_record) + - (4 + 8) * GET16(meta, hdr->Max_Primary_Element_Entries) + - ss - 1) / ss); + howmany(sizeof(struct ddf_vdc_record) + (4 + 8) * + GET16(meta, hdr->Max_Primary_Element_Entries), ss)); SET32(meta, hdr->cd_length, - (sizeof(struct ddf_cd_record) + ss - 1) / ss); + howmany(sizeof(struct ddf_cd_record), ss)); SET32(meta, hdr->pdr_length, - (sizeof(struct ddf_pd_record) + - sizeof(struct ddf_pd_entry) * - GET16(meta, hdr->Max_PD_Entries) + ss - 1) / ss); + howmany(sizeof(struct ddf_pd_record) + + sizeof(struct ddf_pd_entry) * GET16(meta, + hdr->Max_PD_Entries), ss)); SET32(meta, hdr->vdr_length, - (sizeof(struct ddf_vd_record) + - sizeof(struct ddf_vd_entry) * - GET16(meta, hdr->Max_VD_Entries) + ss - 1) / ss); + howmany(sizeof(struct ddf_vd_record) + + sizeof(struct ddf_vd_entry) * + GET16(meta, hdr->Max_VD_Entries), ss)); SET32(meta, hdr->cr_length, GET16(meta, hdr->Configuration_Record_Length) * (GET16(meta, hdr->Max_Partitions) + 1)); SET32(meta, hdr->pdd_length, - (sizeof(struct ddf_pdd_record) + ss - 1) / ss); + howmany(sizeof(struct ddf_pdd_record), ss)); SET32(meta, hdr->bbmlog_length, 0); SET32(meta, hdr->Diagnostic_Space_Length, 0); SET32(meta, hdr->Vendor_Specific_Logs_Length, 0); diff --git a/sys/geom/raid/md_intel.c b/sys/geom/raid/md_intel.c index 6d12602..11c561c 100644 --- a/sys/geom/raid/md_intel.c +++ b/sys/geom/raid/md_intel.c @@ -773,7 +773,7 @@ intel_meta_write(struct g_consumer *cp, struct intel_raid_conf *meta) meta->checksum = checksum; /* Create and fill buffer. */ - sectors = (meta->config_size + pp->sectorsize - 1) / pp->sectorsize; + sectors = howmany(meta->config_size, pp->sectorsize); buf = malloc(sectors * pp->sectorsize, M_MD_INTEL, M_WAITOK | M_ZERO); if (sectors > 1) { memcpy(buf, ((char *)meta) + pp->sectorsize, diff --git a/sys/geom/uzip/g_uzip.c b/sys/geom/uzip/g_uzip.c index 768a454..bbb31e4 100644 --- a/sys/geom/uzip/g_uzip.c +++ b/sys/geom/uzip/g_uzip.c @@ -195,9 +195,8 @@ g_uzip_cached(struct g_geom *gp, struct bio *bp) #define TOFF_2_BOFF(sc, pp, bi) ((sc)->toc[(bi)].offset - \ (sc)->toc[(bi)].offset % (pp)->sectorsize) -#define TLEN_2_BLEN(sc, pp, bp, ei) ((BLK_ENDS((sc), (ei)) - \ - (bp)->bio_offset + (pp)->sectorsize - 1) / \ - (pp)->sectorsize * (pp)->sectorsize) +#define TLEN_2_BLEN(sc, pp, bp, ei) roundup(BLK_ENDS((sc), (ei)) - \ + (bp)->bio_offset, (pp)->sectorsize) static int g_uzip_request(struct g_geom *gp, struct bio *bp) @@ -220,7 +219,7 @@ g_uzip_request(struct g_geom *gp, struct bio *bp) ofs = bp->bio_offset + bp->bio_completed; start_blk = ofs / sc->blksz; KASSERT(start_blk < sc->nblocks, ("start_blk out of range")); - end_blk = (ofs + bp->bio_resid + sc->blksz - 1) / sc->blksz; + end_blk = howmany(ofs + bp->bio_resid, sc->blksz); KASSERT(end_blk <= sc->nblocks, ("end_blk out of range")); for (; BLK_IS_NIL(sc, start_blk) && start_blk < end_blk; start_blk++) { |