// SPDX-License-Identifier: GPL-2.0 /* * random utility code, for bcache but in theory not specific to bcache * * Copyright 2010, 2011 Kent Overstreet <[email protected]> * Copyright 2012 Google, Inc. */ #include <linux/bio.h> #include <linux/blkdev.h> #include <linux/ctype.h> #include <linux/debugfs.h> #include <linux/module.h> #include <linux/seq_file.h> #include <linux/types.h> #include <linux/sched/clock.h> #include "util.h" #define simple_strtoint(c, end, base) … #define simple_strtouint(c, end, base) … #define STRTO_H(name, type) … \ STRTO_H(…) STRTO_H(…) STRTO_H(…) STRTO_H(…) /** * bch_hprint - formats @v to human readable string for sysfs. * @buf: the (at least 8 byte) buffer to format the result into. * @v: signed 64 bit integer * * Returns the number of bytes used by format. */ ssize_t bch_hprint(char *buf, int64_t v) { … } bool bch_is_zero(const char *p, size_t n) { … } int bch_parse_uuid(const char *s, char *uuid) { … } void bch_time_stats_update(struct time_stats *stats, uint64_t start_time) { … } /** * bch_next_delay() - update ratelimiting statistics and calculate next delay * @d: the struct bch_ratelimit to update * @done: the amount of work done, in arbitrary units * * Increment @d by the amount of work done, and return how long to delay in * jiffies until the next time to do some work. */ uint64_t bch_next_delay(struct bch_ratelimit *d, uint64_t done) { … } /* * Generally it isn't good to access .bi_io_vec and .bi_vcnt directly, * the preferred way is bio_add_page, but in this case, bch_bio_map() * supposes that the bvec table is empty, so it is safe to access * .bi_vcnt & .bi_io_vec in this way even after multipage bvec is * supported. */ void bch_bio_map(struct bio *bio, void *base) { … } /** * bch_bio_alloc_pages - allocates a single page for each bvec in a bio * @bio: bio to allocate pages for * @gfp_mask: flags for allocation * * Allocates pages up to @bio->bi_vcnt. * * Returns 0 on success, -ENOMEM on failure. On failure, any allocated pages are * freed. */ int bch_bio_alloc_pages(struct bio *bio, gfp_t gfp_mask) { … }