From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff Moyer Subject: Re: [PATCH] loop: add discard support for loop devices Date: Thu, 18 Aug 2011 11:33:22 -0400 Message-ID: References: <1313063143-14473-1-git-send-email-lczerner@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-kernel@vger.kernel.org, achender@linux.vnet.ibm.com, Jens Axboe , linux-fsdevel@vger.kernel.org To: Lukas Czerner Return-path: Received: from mx1.redhat.com ([209.132.183.28]:32083 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755475Ab1HRPdj (ORCPT ); Thu, 18 Aug 2011 11:33:39 -0400 In-Reply-To: (Lukas Czerner's message of "Wed, 17 Aug 2011 15:13:31 +0200 (CEST)") Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Lukas Czerner writes: >> @@ -484,6 +485,29 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio) >> } >> } >> >> + /* >> + * We use punch hole to reclaim the free space used by the >> + * image a.k.a. discard. However we do support discard if >> + * encryption is enabled, because it may give an attacker >> + * useful information. >> + */ >> + if (bio->bi_rw & REQ_DISCARD) { >> + struct file *file = lo->lo_backing_file; >> + int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE; >> + >> + if ((!file->f_op->fallocate) || >> + lo->lo_encrypt_key_size) { >> + ret = -EOPNOTSUPP; >> + goto out; >> + } >> + ret = file->f_op->fallocate(file, mode, pos, >> + bio->bi_size); >> + if (unlikely(ret && ret != -EINVAL && >> + ret != -EOPNOTSUPP)) >> + ret = -EIO; >> + goto out; >> + } >> + Seems you missed the bizarre case of configuring a loop device over top of a block device. Cheers, Jeff