diff options
author | Manuel Bentele | 2021-03-15 12:18:10 +0100 |
---|---|---|
committer | Manuel Bentele | 2021-03-15 12:18:10 +0100 |
commit | 3bc3b89d5a85b9642e96688e6c9c2862a95e7b45 (patch) | |
tree | 7f4e067962ced878427d128410671e6d1c1d4154 /src/kernel/xloop_file_fmt_raw.c | |
parent | Add support in CMake to validate (lint) the source code (diff) | |
download | xloop-3bc3b89d5a85b9642e96688e6c9c2862a95e7b45.tar.gz xloop-3bc3b89d5a85b9642e96688e6c9c2862a95e7b45.tar.xz xloop-3bc3b89d5a85b9642e96688e6c9c2862a95e7b45.zip |
Refactor kernel code to satisfy Linux kernel code style
Diffstat (limited to 'src/kernel/xloop_file_fmt_raw.c')
-rw-r--r-- | src/kernel/xloop_file_fmt_raw.c | 99 |
1 files changed, 40 insertions, 59 deletions
diff --git a/src/kernel/xloop_file_fmt_raw.c b/src/kernel/xloop_file_fmt_raw.c index 12914e8..1c2c42b 100644 --- a/src/kernel/xloop_file_fmt_raw.c +++ b/src/kernel/xloop_file_fmt_raw.c @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +// SPDX-License-Identifier: GPL-2.0 /* * xloop_file_fmt_raw.c * @@ -27,18 +27,16 @@ #include "xloop_file_fmt.h" -static inline loff_t __raw_file_fmt_rq_get_pos(struct xloop_file_fmt *xlo_fmt, - struct request *rq) +static inline loff_t __raw_file_fmt_rq_get_pos(struct xloop_file_fmt *xlo_fmt, struct request *rq) { struct xloop_device *xlo = xloop_file_fmt_get_xlo(xlo_fmt); - return ((loff_t) blk_rq_pos(rq) << 9) + xlo->xlo_offset; + + return ((loff_t)blk_rq_pos(rq) << 9) + xlo->xlo_offset; } /* transfer function for DEPRECATED cryptoxloop support */ -static inline int __raw_file_fmt_do_transfer(struct xloop_device *xlo, int cmd, - struct page *rpage, unsigned roffs, - struct page *lpage, unsigned loffs, - int size, sector_t rblock) +static inline int __raw_file_fmt_do_transfer(struct xloop_device *xlo, int cmd, struct page *rpage, unsigned int roffs, + struct page *lpage, unsigned int loffs, int size, sector_t rblock) { int ret; @@ -46,13 +44,11 @@ static inline int __raw_file_fmt_do_transfer(struct xloop_device *xlo, int cmd, if (likely(!ret)) return 0; - pr_err_ratelimited("transfer error at byte offset %llu, length %i.\n", - (unsigned long long)rblock << 9, size); + pr_err_ratelimited("transfer error at byte offset %llu, length %i.\n", (unsigned long long)rblock << 9, size); return ret; } -static int __raw_file_fmt_read_transfer(struct xloop_device *xlo, - struct request *rq, loff_t pos) +static int __raw_file_fmt_read_transfer(struct xloop_device *xlo, struct request *rq, loff_t pos) { struct bio_vec bvec, b; struct req_iterator iter; @@ -79,8 +75,7 @@ static int __raw_file_fmt_read_transfer(struct xloop_device *xlo, goto out_free_page; } - ret = __raw_file_fmt_do_transfer(xlo, READ, page, 0, bvec.bv_page, - bvec.bv_offset, len, offset >> 9); + ret = __raw_file_fmt_do_transfer(xlo, READ, page, 0, bvec.bv_page, bvec.bv_offset, len, offset >> 9); if (ret) goto out_free_page; @@ -101,8 +96,7 @@ out_free_page: return ret; } -static int raw_file_fmt_read(struct xloop_file_fmt *xlo_fmt, - struct request *rq) +static int raw_file_fmt_read(struct xloop_file_fmt *xlo_fmt, struct request *rq) { struct bio_vec bvec; struct req_iterator iter; @@ -164,8 +158,7 @@ static void __raw_file_fmt_rw_aio_complete(struct kiocb *iocb, long ret, long re __raw_file_fmt_rw_aio_do_completion(cmd); } -static int __raw_file_fmt_rw_aio(struct xloop_device *xlo, - struct xloop_cmd *cmd, loff_t pos, bool rw) +static int __raw_file_fmt_rw_aio(struct xloop_device *xlo, struct xloop_cmd *cmd, loff_t pos, bool rw) { struct iov_iter iter; struct req_iterator rq_iter; @@ -188,8 +181,7 @@ static int __raw_file_fmt_rw_aio(struct xloop_device *xlo, __rq_for_each_bio(bio, rq) nr_bvec += bio_segments(bio); #endif - bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), - GFP_NOIO); + bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), GFP_NOIO); if (!bvec) return -EIO; cmd->bvec = bvec; @@ -248,8 +240,7 @@ static int __raw_file_fmt_rw_aio(struct xloop_device *xlo, return 0; } -static int raw_file_fmt_read_aio(struct xloop_file_fmt *xlo_fmt, - struct request *rq) +static int raw_file_fmt_read_aio(struct xloop_file_fmt *xlo_fmt, struct request *rq) { struct xloop_device *xlo = xloop_file_fmt_get_xlo(xlo_fmt); struct xloop_cmd *cmd = blk_mq_rq_to_pdu(rq); @@ -258,9 +249,7 @@ static int raw_file_fmt_read_aio(struct xloop_file_fmt *xlo_fmt, return __raw_file_fmt_rw_aio(xlo, cmd, pos, READ); } -static int __raw_file_fmt_write_bvec(struct file *file, - struct bio_vec *bvec, - loff_t *ppos) +static int __raw_file_fmt_write_bvec(struct file *file, struct bio_vec *bvec, loff_t *ppos) { struct iov_iter i; ssize_t bw; @@ -271,11 +260,10 @@ static int __raw_file_fmt_write_bvec(struct file *file, bw = vfs_iter_write(file, &i, ppos, 0); file_end_write(file); - if (likely(bw == bvec->bv_len)) + if (likely(bw == bvec->bv_len)) return 0; - pr_err_ratelimited("write error at byte offset %llu, length %i.\n", - (unsigned long long)*ppos, bvec->bv_len); + pr_err_ratelimited("write error at byte offset %llu, length %i.\n", (unsigned long long)*ppos, bvec->bv_len); if (bw >= 0) bw = -EIO; return bw; @@ -286,10 +274,9 @@ static int __raw_file_fmt_write_bvec(struct file *file, * data as it cannot do the transformations in place without having direct * access to the destination pages of the backing file. */ -static int __raw_file_fmt_write_transfer(struct xloop_device *xlo, - struct request *rq, loff_t pos) +static int __raw_file_fmt_write_transfer(struct xloop_device *xlo, struct request *rq, loff_t pos) { -struct bio_vec bvec, b; + struct bio_vec bvec, b; struct req_iterator iter; struct page *page; int ret = 0; @@ -299,8 +286,8 @@ struct bio_vec bvec, b; return -ENOMEM; rq_for_each_segment(bvec, rq, iter) { - ret = __raw_file_fmt_do_transfer(xlo, WRITE, page, 0, bvec.bv_page, - bvec.bv_offset, bvec.bv_len, pos >> 9); + ret = __raw_file_fmt_do_transfer(xlo, WRITE, page, 0, bvec.bv_page, bvec.bv_offset, bvec.bv_len, + pos >> 9); if (unlikely(ret)) break; @@ -316,8 +303,7 @@ struct bio_vec bvec, b; return ret; } -static int raw_file_fmt_write(struct xloop_file_fmt *xlo_fmt, - struct request *rq) +static int raw_file_fmt_write(struct xloop_file_fmt *xlo_fmt, struct request *rq) { struct bio_vec bvec; struct req_iterator iter; @@ -341,8 +327,7 @@ static int raw_file_fmt_write(struct xloop_file_fmt *xlo_fmt, return ret; } -static int raw_file_fmt_write_aio(struct xloop_file_fmt *xlo_fmt, - struct request *rq) +static int raw_file_fmt_write_aio(struct xloop_file_fmt *xlo_fmt, struct request *rq) { struct xloop_device *xlo = xloop_file_fmt_get_xlo(xlo_fmt); struct xloop_cmd *cmd = blk_mq_rq_to_pdu(rq); @@ -351,8 +336,7 @@ static int raw_file_fmt_write_aio(struct xloop_file_fmt *xlo_fmt, return __raw_file_fmt_rw_aio(xlo, cmd, pos, WRITE); } -static int __raw_file_fmt_fallocate(struct xloop_device *xlo, - struct request *rq, loff_t pos, int mode) +static int __raw_file_fmt_fallocate(struct xloop_device *xlo, struct request *rq, loff_t pos, int mode) { /* * We use fallocate to manipulate the space mappings used by the image @@ -378,8 +362,7 @@ out: return ret; } -static int raw_file_fmt_write_zeros(struct xloop_file_fmt *xlo_fmt, - struct request *rq) +static int raw_file_fmt_write_zeros(struct xloop_file_fmt *xlo_fmt, struct request *rq) { loff_t pos = __raw_file_fmt_rq_get_pos(xlo_fmt, rq); struct xloop_device *xlo = xloop_file_fmt_get_xlo(xlo_fmt); @@ -389,13 +372,10 @@ static int raw_file_fmt_write_zeros(struct xloop_file_fmt *xlo_fmt, * write zeroes the range. Otherwise, punch them out. */ return __raw_file_fmt_fallocate(xlo, rq, pos, - (rq->cmd_flags & REQ_NOUNMAP) ? - FALLOC_FL_ZERO_RANGE : - FALLOC_FL_PUNCH_HOLE); + (rq->cmd_flags & REQ_NOUNMAP) ? FALLOC_FL_ZERO_RANGE : FALLOC_FL_PUNCH_HOLE); } -static int raw_file_fmt_discard(struct xloop_file_fmt *xlo_fmt, - struct request *rq) +static int raw_file_fmt_discard(struct xloop_file_fmt *xlo_fmt, struct request *rq) { loff_t pos = __raw_file_fmt_rq_get_pos(xlo_fmt, rq); struct xloop_device *xlo = xloop_file_fmt_get_xlo(xlo_fmt); @@ -408,14 +388,15 @@ static int raw_file_fmt_flush(struct xloop_file_fmt *xlo_fmt) struct xloop_device *xlo = xloop_file_fmt_get_xlo(xlo_fmt); struct file *file = xlo->xlo_backing_file; int ret = vfs_fsync(file, 0); + if (unlikely(ret && ret != -EINVAL)) ret = -EIO; return ret; } -static loff_t raw_file_fmt_sector_size(struct xloop_file_fmt *xlo_fmt, - struct file *file, loff_t offset, loff_t sizelimit) +static loff_t raw_file_fmt_sector_size(struct xloop_file_fmt *xlo_fmt, struct file *file, loff_t offset, + loff_t sizelimit) { loff_t xloopsize; @@ -437,23 +418,23 @@ static loff_t raw_file_fmt_sector_size(struct xloop_file_fmt *xlo_fmt, } static struct xloop_file_fmt_ops raw_file_fmt_ops = { - .init = NULL, - .exit = NULL, - .read = raw_file_fmt_read, - .write = raw_file_fmt_write, - .read_aio = raw_file_fmt_read_aio, - .write_aio = raw_file_fmt_write_aio, + .init = NULL, + .exit = NULL, + .read = raw_file_fmt_read, + .write = raw_file_fmt_write, + .read_aio = raw_file_fmt_read_aio, + .write_aio = raw_file_fmt_write_aio, .write_zeros = raw_file_fmt_write_zeros, - .discard = raw_file_fmt_discard, - .flush = raw_file_fmt_flush, + .discard = raw_file_fmt_discard, + .flush = raw_file_fmt_flush, .sector_size = raw_file_fmt_sector_size, }; static struct xloop_file_fmt_driver raw_file_fmt_driver = { - .name = "RAW", + .name = "RAW", .file_fmt_type = XLO_FILE_FMT_RAW, - .ops = &raw_file_fmt_ops, - .owner = THIS_MODULE, + .ops = &raw_file_fmt_ops, + .owner = THIS_MODULE, }; static int __init xloop_file_fmt_raw_init(void) |