From: Eric Sandeen <sandeen@sandeen.net>
To: "Darrick J. Wong" <darrick.wong@oracle.com>,
Jens Axboe <axboe@kernel.dk>,
Christoph Hellwig <hch@infradead.org>
Cc: linux-block@vger.kernel.org,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH v3] loop: fix no-unmap write-zeroes request behavior
Date: Mon, 14 Oct 2019 11:39:43 -0500 [thread overview]
Message-ID: <9605de8e-ecd7-9e30-ab48-943211d8f931@sandeen.net> (raw)
In-Reply-To: <20191014155030.GS13108@magnolia>
On 10/14/19 10:50 AM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Currently, if the loop device receives a WRITE_ZEROES request, it asks
> the underlying filesystem to punch out the range. This behavior is
> correct if unmapping is allowed. However, a NOUNMAP request means that
> the caller doesn't want us to free the storage backing the range, so
> punching out the range is incorrect behavior.
>
> To satisfy a NOUNMAP | WRITE_ZEROES request, loop should ask the
> underlying filesystem to FALLOC_FL_ZERO_RANGE, which is (according to
> the fallocate documentation) required to ensure that the entire range is
> backed by real storage, which suffices for our purposes.
>
> Fixes: 19372e2769179dd ("loop: implement REQ_OP_WRITE_ZEROES")
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> v3: refactor into a single fallocate function
> v2: reorganize a little according to hch feedback
> ---
> drivers/block/loop.c | 26 ++++++++++++++++++--------
> 1 file changed, 18 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/block/loop.c b/drivers/block/loop.c
> index f6f77eaa7217..ef6e251857c8 100644
> --- a/drivers/block/loop.c
> +++ b/drivers/block/loop.c
> @@ -417,18 +417,20 @@ static int lo_read_transfer(struct loop_device *lo, struct request *rq,
> return ret;
> }
>
> -static int lo_discard(struct loop_device *lo, struct request *rq, loff_t pos)
> +static int lo_fallocate(struct loop_device *lo, struct request *rq, loff_t pos,
> + int mode)
> {
> /*
> - * We use punch hole to reclaim the free space used by the
> - * image a.k.a. discard. However we do not support discard if
> - * encryption is enabled, because it may give an attacker
> - * useful information.
> + * We use fallocate to manipulate the space mappings used by the image
> + * a.k.a. discard/zerorange. However we do not support this if
> + * encryption is enabled, because it may give an attacker useful
> + * information.
> */
> struct file *file = lo->lo_backing_file;
> - int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
> int ret;
>
> + mode |= FALLOC_FL_KEEP_SIZE;
> +
> if ((!file->f_op->fallocate) || lo->lo_encrypt_key_size) {
> ret = -EOPNOTSUPP;
> goto out;
> @@ -596,9 +598,17 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
> switch (req_op(rq)) {
> case REQ_OP_FLUSH:
> return lo_req_flush(lo, rq);
> - case REQ_OP_DISCARD:
> case REQ_OP_WRITE_ZEROES:
> - return lo_discard(lo, rq, pos);
cxz ÿbvVBV
> + case REQ_OP_DISCARD:
> + return lo_fallocate(lo, rq, pos, FALLOC_FL_PUNCH_HOLE);
I get lost in the twisty passages. What happens if the filesystem hosting the
backing file doesn't support fallocate, and REQ_OP_DISCARD / REQ_OP_WRITE_ZEROES
returns EOPNOTSUPP - discard is advisory, is it ok to fail REQ_OP_WRITE_ZEROES?
Does something at another layer fall back to writing zeros?
-Eric
> case REQ_OP_WRITE:
> if (lo->transfer)
> return lo_write_transfer(lo, rq, pos);
>
next prev parent reply other threads:[~2019-10-14 16:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-10 17:02 [PATCH] loop: fix no-unmap write-zeroes request behavior Darrick J. Wong
2019-10-11 7:51 ` Christoph Hellwig
2019-10-11 16:05 ` [PATCH v2] " Darrick J. Wong
2019-10-14 7:28 ` Christoph Hellwig
2019-10-14 15:50 ` [PATCH v3] " Darrick J. Wong
2019-10-14 16:39 ` Eric Sandeen [this message]
2019-10-14 17:00 ` Darrick J. Wong
2019-10-15 7:58 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9605de8e-ecd7-9e30-ab48-943211d8f931@sandeen.net \
--to=sandeen@sandeen.net \
--cc=axboe@kernel.dk \
--cc=darrick.wong@oracle.com \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).