Message ID | 20220124220357.74017-3-f4bug@amsat.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | block/export/fuse: Fix build failure on FreeBSD | expand |
On 24/01/2022 23.03, Philippe Mathieu-Daudé via wrote: > Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> > --- > block/export/fuse.c | 48 +++++++++++++++++++++++++++++---------------- > 1 file changed, 31 insertions(+), 17 deletions(-) > > diff --git a/block/export/fuse.c b/block/export/fuse.c > index 31cb0503adc..3a158342c75 100644 > --- a/block/export/fuse.c > +++ b/block/export/fuse.c > @@ -603,6 +603,35 @@ static void fuse_write(fuse_req_t req, fuse_ino_t inode, const char *buf, > } > } > > +static bool fuse_fallocate_punch_hole(fuse_req_t req, fuse_ino_t inode, > + int mode, int64_t blk_len, > + off_t offset, off_t *length) > +{ > + FuseExport *exp = fuse_req_userdata(req); > + > + if (mode & FALLOC_FL_KEEP_SIZE) { > + *length = MIN(*length, blk_len - offset); > + } > + > + if (mode & FALLOC_FL_PUNCH_HOLE) { > + int ret; > + > + if (!(mode & FALLOC_FL_KEEP_SIZE)) { > + fuse_reply_err(req, EINVAL); > + return false; > + } > + > + do { > + int size = MIN(*length, BDRV_REQUEST_MAX_BYTES); > + > + ret = blk_pdiscard(exp->common.blk, offset, size); > + offset += size; > + *length -= size; > + } while (ret == 0 && *length > 0); > + } > + return true; > +} > + > static bool fuse_fallocate_zero_range(fuse_req_t req, fuse_ino_t inode, > int mode, int64_t blk_len, > off_t offset, off_t *length) > @@ -657,23 +686,8 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, > return; > } > > - if (mode & FALLOC_FL_KEEP_SIZE) { > - length = MIN(length, blk_len - offset); > - } > - > - if (mode & FALLOC_FL_PUNCH_HOLE) { > - if (!(mode & FALLOC_FL_KEEP_SIZE)) { > - fuse_reply_err(req, EINVAL); > - return; > - } > - > - do { > - int size = MIN(length, BDRV_REQUEST_MAX_BYTES); > - > - ret = blk_pdiscard(exp->common.blk, offset, size); > - offset += size; > - length -= size; > - } while (ret == 0 && length > 0); > + if (!fuse_fallocate_punch_hole(req, inode, mode, blk_len, offset, &length)) { > + return; Same issue as with the previous patch? If the do-while loop has been executed, the else branches below should not be called... Thomas > } else if (!fuse_fallocate_zero_range(req, inode, blk_len, mode, offset, &length)) { > return; > } else if (!mode) {
diff --git a/block/export/fuse.c b/block/export/fuse.c index 31cb0503adc..3a158342c75 100644 --- a/block/export/fuse.c +++ b/block/export/fuse.c @@ -603,6 +603,35 @@ static void fuse_write(fuse_req_t req, fuse_ino_t inode, const char *buf, } } +static bool fuse_fallocate_punch_hole(fuse_req_t req, fuse_ino_t inode, + int mode, int64_t blk_len, + off_t offset, off_t *length) +{ + FuseExport *exp = fuse_req_userdata(req); + + if (mode & FALLOC_FL_KEEP_SIZE) { + *length = MIN(*length, blk_len - offset); + } + + if (mode & FALLOC_FL_PUNCH_HOLE) { + int ret; + + if (!(mode & FALLOC_FL_KEEP_SIZE)) { + fuse_reply_err(req, EINVAL); + return false; + } + + do { + int size = MIN(*length, BDRV_REQUEST_MAX_BYTES); + + ret = blk_pdiscard(exp->common.blk, offset, size); + offset += size; + *length -= size; + } while (ret == 0 && *length > 0); + } + return true; +} + static bool fuse_fallocate_zero_range(fuse_req_t req, fuse_ino_t inode, int mode, int64_t blk_len, off_t offset, off_t *length) @@ -657,23 +686,8 @@ static void fuse_fallocate(fuse_req_t req, fuse_ino_t inode, int mode, return; } - if (mode & FALLOC_FL_KEEP_SIZE) { - length = MIN(length, blk_len - offset); - } - - if (mode & FALLOC_FL_PUNCH_HOLE) { - if (!(mode & FALLOC_FL_KEEP_SIZE)) { - fuse_reply_err(req, EINVAL); - return; - } - - do { - int size = MIN(length, BDRV_REQUEST_MAX_BYTES); - - ret = blk_pdiscard(exp->common.blk, offset, size); - offset += size; - length -= size; - } while (ret == 0 && length > 0); + if (!fuse_fallocate_punch_hole(req, inode, mode, blk_len, offset, &length)) { + return; } else if (!fuse_fallocate_zero_range(req, inode, blk_len, mode, offset, &length)) { return; } else if (!mode) {
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> --- block/export/fuse.c | 48 +++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-)