From patchwork Tue Oct 26 17:54:17 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Czerner X-Patchwork-Id: 69277 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C39EBB70D1 for ; Wed, 27 Oct 2010 04:54:41 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760210Ab0JZRyk (ORCPT ); Tue, 26 Oct 2010 13:54:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35391 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752045Ab0JZRyk (ORCPT ); Tue, 26 Oct 2010 13:54:40 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9QHscci003911 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Oct 2010 13:54:38 -0400 Received: from dhcp-lab-213.englab.brq.redhat.com (dhcp-27-236.brq.redhat.com [10.34.27.236]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9QHsQCE016508; Tue, 26 Oct 2010 13:54:37 -0400 From: Lukas Czerner To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, sandeen@redhat.com, adilger@dilger.ca, lczerner@redhat.com Subject: [PATCH 6/7] mke2fs: Use unix_discard() for discards Date: Tue, 26 Oct 2010 19:54:17 +0200 Message-Id: <1288115658-7004-7-git-send-email-lczerner@redhat.com> In-Reply-To: <1288115658-7004-1-git-send-email-lczerner@redhat.com> References: <1288115658-7004-1-git-send-email-lczerner@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org There is generic discard function in struct_io_manager, or in unix_io_manager to be specific. So use this instead of mke2fs_discard_blocks(). Since mke2fs_discard_blocks() is not used anymore (and should not be) remove it. Signed-off-by: Lukas Czerner --- misc/mke2fs.c | 50 +++++++++++--------------------------------------- 1 files changed, 11 insertions(+), 39 deletions(-) diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 32e3a2b..09ce711 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1902,48 +1902,10 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr) #ifdef __linux__ -#ifndef BLKDISCARD -#define BLKDISCARD _IO(0x12,119) -#endif - #ifndef BLKDISCARDZEROES #define BLKDISCARDZEROES _IO(0x12,124) #endif -/* - * Return zero if the discard succeeds, and -1 if the discard fails. - */ -static int mke2fs_discard_blocks(ext2_filsys fs) -{ - int fd; - int ret; - int blocksize; - __u64 blocks; - __uint64_t range[2]; - - blocks = ext2fs_blocks_count(fs->super); - blocksize = EXT2_BLOCK_SIZE(fs->super); - range[0] = 0; - range[1] = blocks * blocksize; - - fd = open64(fs->device_name, O_RDWR); - - if (fd > 0) { - ret = ioctl(fd, BLKDISCARD, &range); - if (verbose) { - printf(_("Calling BLKDISCARD from %llu to %llu "), - (unsigned long long) range[0], - (unsigned long long) range[1]); - if (ret) - printf(_("failed.\n")); - else - printf(_("succeeded.\n")); - } - close(fd); - } - return ret; -} - static int mke2fs_discard_zeroes_data(ext2_filsys fs) { int fd; @@ -2023,7 +1985,17 @@ int main (int argc, char *argv[]) /* Can't undo discard ... */ if (discard && (io_ptr != undo_io_manager)) { - retval = mke2fs_discard_blocks(fs); + blk64_t blocks = ext2fs_blocks_count(fs->super); + retval = io_ptr->discard(fs->io, 0, blocks, fs); + + if (verbose) { + printf(_("Calling BLKDISCARD from 0 to %llu "), + (unsigned long long) blocks); + if (retval) + printf(_("failed.\n")); + else + printf(_("succeeded.\n")); + } if (!retval && mke2fs_discard_zeroes_data(fs)) { if (verbose)