master - bcache-utils: bcache_set_bytes()
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=1c5c99afceb28f6ee464a705f1337866d29a9819 Commit: 1c5c99afceb28f6ee464a705f1337866d29a9819 Parent: 2e1869b9231181cbd5c3cfa7dbbb3ef237ffa4a9 Author: Joe Thornber <[email protected]> AuthorDate: Wed May 9 11:05:29 2018 +0100 Committer: Joe Thornber <[email protected]> CommitterDate: Wed May 9 11:05:29 2018 +0100
bcache-utils: bcache_set_bytes()
--- lib/device/bcache-utils.c | 43 ++++++++++++++++++++++++++++ lib/device/bcache.h | 1 + test/unit/bcache_utils_t.c | 66 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 108 insertions(+), 2 deletions(-)
lib/device/bcache-utils.c +43 -0
@@ -227,3 +227,46 @@ bool bcache_zero_bytes(struct bcache *cache, int fd, uint64_t start, size_t len) }//---------------------------------------------------------------- + +static bool _set_partial (struct updater *u,int fd,block_address bb,uint64_t offset,size_t len) +{ +struct block *b; +uint8_t val = *((uint8_t *) u->data); + +if (!bcache_get (u->cache, fd, bb,GF_DIRTY , &b,NULL )) +return false; + +memset (((unsigned char *) b->data) + offset, val, len); +bcache_put (b); + +return true; +} + +static bool _set_whole (struct updater *u,int fd,block_address bb,block_address be) +{ +struct block *b; +uint8_t val = *((uint8_t *) u->data); +uint64_t len =bcache_block_sectors (u->cache) *512 ; + +for (; bb != be; bb++) { +if (!bcache_get (u->cache, fd, bb,GF_ZERO , &b,NULL )) +return false; +memset ((unsigned char *) b->data, val, len); +bcache_put (b); + } + +return true; +} + +bool bcache_set_bytes (struct bcache *cache,int fd,uint64_t start,size_t len,uint8_t val) +{ +struct updater u; + + u.cache = cache; + u.partial_fn = _set_partial; + u.whole_fn = _set_whole; + u.data = &val; + +return _update_bytes (&u, fd, start, len); +} +
lib/device/bcache.h +1 -0
@@ -162,6 +162,7 @@ void bcache_prefetch_bytes(struct bcache *cache, int fd, uint64_t start, size_tbool bcache_read_bytes (struct bcache *cache,int fd,uint64_t start,size_t len,void *data);bool bcache_write_bytes (struct bcache *cache,int fd,uint64_t start,size_t len,void *data);bool bcache_zero_bytes (struct bcache *cache,int fd,uint64_t start,size_t len); +bool bcache_set_bytes (struct bcache *cache,int fd,uint64_t start,size_t len,uint8_t val);//----------------------------------------------------------------
test/unit/bcache_utils_t.c +64 -2
102 lines not on this page · raw message