On Tue, 12/30 12:20, Denis V. Lunev wrote: > actually the code > if (ret == -ENODEV || ret == -ENOSYS || ret == -EOPNOTSUPP || > ret == -ENOTTY) { > ret = -ENOTSUP; > } > is present twice and will be added a couple more times. Create helper > for this. Place it into do_fallocate() for further convinience.
s/convinience/convenience/ > > Signed-off-by: Denis V. Lunev <d...@openvz.org> > CC: Kevin Wolf <kw...@redhat.com> > CC: Stefan Hajnoczi <stefa...@redhat.com> > CC: Peter Lieven <p...@kamp.de> > --- > block/raw-posix.c | 21 ++++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/block/raw-posix.c b/block/raw-posix.c > index a7c8816..25a6947 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -894,6 +894,15 @@ static int xfs_discard(BDRVRawState *s, int64_t offset, > uint64_t bytes) > #endif > > > +static int translate_err(int err) > +{ > + if (err == -ENODEV || err == -ENOSYS || err == -EOPNOTSUPP || > + err == -ENOTTY) { > + err = -ENOTSUP; > + } > + return err; > +} > + > #if defined(CONFIG_FALLOCATE_PUNCH_HOLE) || > defined(CONFIG_FALLOCATE_ZERO_RANGE) > static int do_fallocate(int fd, int mode, off_t offset, off_t len) > { > @@ -902,7 +911,7 @@ static int do_fallocate(int fd, int mode, off_t offset, > off_t len) > return 0; > } > } while (errno == EINTR); > - return -errno; > + return translate_err(-errno); This could be a separate patch. Maybe reorder the previous patches as: 1) Introduce translate_err. 2) Refactor out do_fallocate. 3) Introduce FALLOC_FL_ZERO_RANGE calling code. Fam > } > #endif > > @@ -939,10 +948,9 @@ static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData > *aiocb) > #endif > } > > - if (ret == -ENODEV || ret == -ENOSYS || ret == -EOPNOTSUPP || > - ret == -ENOTTY) { > + ret = translate_err(ret); > + if (ret == -ENOTSUP) { > s->has_write_zeroes = false; > - ret = -ENOTSUP; > } > return ret; > } > @@ -980,10 +988,9 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData > *aiocb) > #endif > } > > - if (ret == -ENODEV || ret == -ENOSYS || ret == -EOPNOTSUPP || > - ret == -ENOTTY) { > + ret = translate_err(ret); > + if (ret == -ENOTSUP) { > s->has_discard = false; > - ret = -ENOTSUP; > } > return ret; > } > -- > 1.9.1 > >