Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4664817pxu; Tue, 13 Oct 2020 04:20:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSo6lIoa6XW73h55FWJLherTdO0czwRa5Uhmr+LvHTVwzQrgsTTUXJ+a68IbOsLH0+XXk+ X-Received: by 2002:a05:6402:6d0:: with SMTP id n16mr19647418edy.133.1602588009332; Tue, 13 Oct 2020 04:20:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602588009; cv=none; d=google.com; s=arc-20160816; b=eYauznIzYjrOTdo1WnvCAWZbDh4Oca4o+zfzFJ3Zo8gu0Hxf+K+z1TfllYM/aoiw9g CCNoTihmyyO4j1K6MU5wpBRRYbA8cJnMW4Uf1FcINEF7dH8sxGlhRv++jqQGmLCzKWB8 wth3dQxhrjZYp6oAvGlt18oMX3YFiRXuJdZ5u57mvmk5nXff+483/Z1VKu7PY6t6GDca WC7Jwgr+l8tsIenjITvbHJGoPGF5q2bwPWECUITJoj3pAH2v6uTIxEZL8Fu4hNMLWlS5 9plip0CLQocZIh1Oevz1/Yi8AhyAm6cFxSmUBfMOVvD4ZKrMJQfQ5x0rrnNyFhArt1EX cqKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eEV/cWEF/JYPft5qQa3SDqcnDv+itkYtghzo7XBgFNs=; b=mUGChqHbUYH47Z1ikjMAI1VCjbnmi9Sx/348lpZnD3zBFl8JJtiB5MARDr5dqH8SwB PTncnyNu8dEy8ZrcRYxtbaZVZDLfwG0rKy7eMZ21VrSG6ljaKgEvYzFyOyOgd4VOu97S 8kzyR5F+fnyvvpVk4rClfUPAeU3hE5C9mn3bVruhmO8FJJtqbdI45qtcovk/CnDtFn3s gZ+5RHAJD3D4n8TSvS/g1G1FgREfzEWAhCtROJYCqv/05tnrs8DIMq4eRheBRnYVEHah Q3o0MlQTSMdFA0sQQxw08OGLzm1ECra4vNAQp+BEMgXq0ZexjycEx5ajpHjsp4R4mxv6 hX5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GWOTVtAd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd24si12809222ejb.523.2020.10.13.04.19.46; Tue, 13 Oct 2020 04:20:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=GWOTVtAd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728718AbgJMCYs (ORCPT + 99 others); Mon, 12 Oct 2020 22:24:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728695AbgJMCYr (ORCPT ); Mon, 12 Oct 2020 22:24:47 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3171CC0613D0 for ; Mon, 12 Oct 2020 19:24:46 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id n9so2952162pgt.8 for ; Mon, 12 Oct 2020 19:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eEV/cWEF/JYPft5qQa3SDqcnDv+itkYtghzo7XBgFNs=; b=GWOTVtAdo8DKLCg2sfVY/T+Lny64tP5ZynNSLR/cL67sSFaJyP6GD/dKjlhcsAyceo d3hNAVF5U5SwXvV5b4XPZG4+8CZRqeP4RUjKqRW1Y7Dk+Mq3BgVTfRi/FrP7w/A+pAHV 0oW60V5PPlUMK8I6VxYREn5YzJHO9LTug1tiwOfNO6/YiNTFJAe8QbrGbUF1VhXLBA1v LTd56ImOOqEBn+OdQsG9FVG93lh9DJPSeReGva2hrAPQlqnq9dFKqcnKHe3DzCCb0Urw VmV/MnJM9QgEgrqjJ0ZhNGeNaHQcTQWrIxgUBfbEaq9iPp7K7a+YW455cueLbEaxufv6 fF2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eEV/cWEF/JYPft5qQa3SDqcnDv+itkYtghzo7XBgFNs=; b=nwGA/F/n/vBu2QJ65+oOH0tZMU1pI74CfwQj73k/prAS3fNM6NV80QqO9y9dAyXg+v MhfnROnGOu+DeIW1KKZ5Uk0u6r0oLp9DhS0DLgFq5oql2DdzsOcgehFRpAOE9d9cNKA3 QRPEBFhCqXYH+mghODBLKk3WzEJUOV6OBwGy/K266UI/bdVXTO53uNgcCUrbTnWx/nZl gQbMeK0h3g0uWMEiDtWjRt88Ov5l2X3GDTMyMv8NghvEyy1F2v4/pvMfoGTpV86IO20T tSi7hzSaHjLN7ZNDej/5HY3J7ZNHxdwR0ALnFiUdj31og1yiMaLHSQTLIUgkMzkHEohB mxQA== X-Gm-Message-State: AOAM531IZesFH9QvyztFsvp7MTywu6kiGpvd+HUFD54f7gVFrlB+H4zY GoUF1ZicK4Kio+Z6PEkILgceOrXJGMU= X-Received: by 2002:a05:6a00:8c5:b029:142:2501:39e6 with SMTP id s5-20020a056a0008c5b0290142250139e6mr26902826pfu.53.1602555885313; Mon, 12 Oct 2020 19:24:45 -0700 (PDT) Received: from daehojeong1.seo.corp.google.com ([2401:fa00:d:1:a6ae:11ff:fe18:6ce2]) by smtp.gmail.com with ESMTPSA id d194sm10581110pfd.172.2020.10.12.19.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Oct 2020 19:24:44 -0700 (PDT) From: Daeho Jeong To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com Cc: Daeho Jeong Subject: [PATCH 2/2] f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl Date: Tue, 13 Oct 2020 11:24:29 +0900 Message-Id: <20201013022429.454161-2-daeho43@gmail.com> X-Mailer: git-send-email 2.28.0.1011.ga647a8990f-goog In-Reply-To: <20201013022429.454161-1-daeho43@gmail.com> References: <20201013022429.454161-1-daeho43@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daeho Jeong Added a new F2FS_IOC_SET_COMPRESS_OPTION ioctl to change file compression option of a file. Signed-off-by: Daeho Jeong --- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/file.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index a33c90cf979b..5ee8a4859b62 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -435,6 +435,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, struct f2fs_sectrim_range) #define F2FS_IOC_GET_COMPRESS_OPTION _IOR(F2FS_IOCTL_MAGIC, 21, \ struct f2fs_comp_option) +#define F2FS_IOC_SET_COMPRESS_OPTION _IOW(F2FS_IOCTL_MAGIC, 22, \ + struct f2fs_comp_option) /* * should be same as XFS_IOC_GOINGDOWN. diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 7e64259f6f5e..6c265c66ddd4 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3963,6 +3963,59 @@ static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg) return 0; } +static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) +{ + struct inode *inode = file_inode(filp); + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); + struct f2fs_comp_option option; + int ret; + int writecount; + + if (!f2fs_sb_has_compression(sbi)) + return -EOPNOTSUPP; + + if (!f2fs_compressed_file(inode) || IS_IMMUTABLE(inode)) + return -EINVAL; + + if (f2fs_readonly(sbi->sb)) + return -EROFS; + + if (copy_from_user(&option, (struct f2fs_comp_option __user *)arg, + sizeof(option))) + return -EFAULT; + + if (option.log_cluster_size < MIN_COMPRESS_LOG_SIZE || + option.log_cluster_size > MAX_COMPRESS_LOG_SIZE || + option.algorithm >= COMPRESS_MAX) + return -EINVAL; + + ret = mnt_want_write_file(filp); + if (ret) + return ret; + + inode_lock(inode); + + writecount = atomic_read(&inode->i_writecount); + if ((filp->f_mode & FMODE_WRITE && writecount != 1) || + (!(filp->f_mode & FMODE_WRITE) && writecount)) { + ret = -EBUSY; + goto out; + } + + if (get_dirty_pages(inode) || inode->i_size) { + ret = -EINVAL; + goto out; + } + + F2FS_I(inode)->i_compress_algorithm = option.algorithm; + F2FS_I(inode)->i_log_cluster_size = option.log_cluster_size; + F2FS_I(inode)->i_cluster_size = 1 << option.log_cluster_size; + f2fs_mark_inode_dirty_sync(inode, true); +out: + inode_unlock(inode); + return ret; +} + long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) @@ -4053,6 +4106,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return f2fs_sec_trim_file(filp, arg); case F2FS_IOC_GET_COMPRESS_OPTION: return f2fs_ioc_get_compress_option(filp, arg); + case F2FS_IOC_SET_COMPRESS_OPTION: + return f2fs_ioc_set_compress_option(filp, arg); default: return -ENOTTY; } @@ -4224,6 +4279,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case F2FS_IOC_RESERVE_COMPRESS_BLOCKS: case F2FS_IOC_SEC_TRIM_FILE: case F2FS_IOC_GET_COMPRESS_OPTION: + case F2FS_IOC_SET_COMPRESS_OPTION: break; default: return -ENOIOCTLCMD; -- 2.28.0.1011.ga647a8990f-goog