Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3FFCC0650F for ; Tue, 6 Aug 2019 02:50:58 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 832652075B for ; Tue, 6 Aug 2019 02:50:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="Og9jJlGk"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="OYTSASNU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 832652075B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1hupYw-0000uQ-3U; Tue, 06 Aug 2019 02:50:58 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hupYt-0000u0-3z for linux-f2fs-devel@lists.sourceforge.net; Tue, 06 Aug 2019 02:50:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Type:MIME-Version:Message-ID:Date:Subject: CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=EzIlRTAxMorLM+vWVUqqaacvvr4xv/Y3VPgwueiRnCU=; b=Og9jJlGklJQEuHODgQpFLOdfrM Uoqkan7EJ1+XK/DDpx/TVaJ5QUsNOVMm/Sd6WDQPw77FWq1uJTT3QmVoutDlPCyaZj7ZY2rIMyjjD tpbKEo01eVaGUdLkDieQH5GgI5URCUDUlh10u3wgeFE/KyAw0zaALPXcAs5pwMlUmEeY=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From:Sender: Reply-To:Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date :Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=EzIlRTAxMorLM+vWVUqqaacvvr4xv/Y3VPgwueiRnCU=; b=O YTSASNUXr3UHG7H19I5C+ERULAXCBeCGNHdsZgkVqnFkRmrXD35E1Ie8FBq2Agk9Dr1Ntpfk6wW6q h4S+6wDyZb4qFm0dwBA/KJYuunXqVxXz2ENcOwM5H1gJJPz+uq0m7LfG3IxaYnSYmkMvTkDTIb5Qb BVuZTZax0C/vwAkc=; Received: from szxga07-in.huawei.com ([45.249.212.35] helo=huawei.com) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1hupYq-00Bp7i-LM for linux-f2fs-devel@lists.sourceforge.net; Tue, 06 Aug 2019 02:50:55 +0000 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 8D8FEE25B2CE76F08387; Tue, 6 Aug 2019 10:50:44 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Tue, 6 Aug 2019 10:50:38 +0800 From: Chao Yu To: Date: Tue, 6 Aug 2019 10:50:31 +0800 Message-ID: <20190806025031.4444-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected X-Headers-End: 1hupYq-00Bp7i-LM Subject: [f2fs-dev] [PATCH v3] f2fs_io: support defrag_file X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Support 'defrag_file' sub command to trigger file based defragment via ioctl in f2fs. Signed-off-by: Chao Yu --- v3: - remove -v option. tools/f2fs_io/f2fs_io.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c index f087da4..6b43778 100644 --- a/tools/f2fs_io/f2fs_io.c +++ b/tools/f2fs_io/f2fs_io.c @@ -442,6 +442,45 @@ static void do_gc_urgent(int argc, char **argv, const struct cmd_desc *cmd) } } +#define defrag_file_desc "do defragment on file" +#define defrag_file_help \ +"f2fs_io defrag_file [start] [length] [file_path]\n\n" \ +" start : start offset of defragment region, unit: bytes\n" \ +" length : bytes number of defragment region\n" \ + +static void do_defrag_file(int argc, char **argv, const struct cmd_desc *cmd) +{ + struct f2fs_defragment df; + u64 len; + int ret, fd; + + if (argc != 4) { + fputs("Excess arguments\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + df.start = atoll(argv[1]); + df.len = len = atoll(argv[2]); + + fd = open(argv[3], O_RDWR); + if (fd == -1) { + fputs("Open failed\n\n", stderr); + fputs(cmd->cmd_help, stderr); + exit(1); + } + + ret = ioctl(fd, F2FS_IOC_DEFRAGMENT, &df); + if (ret < 0) { + perror("F2FS_IOC_DEFRAGMENT"); + exit(1); + } + printf("defrag %s in region[%llu, %llu]\n", argv[3], + df.start, df.start + len); + exit(0); +} + + #define CMD_HIDDEN 0x0001 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 } #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN } @@ -456,6 +495,7 @@ const struct cmd_desc cmd_list[] = { CMD(read), CMD(fiemap), CMD(gc_urgent), + CMD(defrag_file), { NULL, NULL, NULL, NULL, 0 } }; -- 2.18.0.rc1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel