Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1345704pxx; Tue, 27 Oct 2020 14:36:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrXXDUVyg2xpNKShG6yIQ9wWlgjWh8mE98Fv1WUM3I+mQ1P4221poDV47JcaEomSaAju8J X-Received: by 2002:a17:90a:4083:: with SMTP id l3mr3687048pjg.111.1603834576927; Tue, 27 Oct 2020 14:36:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603834576; cv=none; d=google.com; s=arc-20160816; b=0bhED3t/lzIkuS5MeCeU27ZilA9eVFx5YdYHvCnbslhOZUxMslMLaUwGmg1+7KkiJX O670cfDODokFepHsG0bjIHisUvvhGMp4cOXzNyf7MVMGLew3bErb65qulkq1VMcEcQj6 0w0eLWoF3pBJ3WbKb4BI9C4XV13Q6jxXd1f527bHucPNDEKVl0s+sIso2ythP8gJ9/9c QZmp5LvgmhGoAL/mSsPQZb18nbEYsR1/0EwIhb5JKDhfalArWEdj96GIaJB3j4khBHQL PooxLx2lRm1LayYYDSpU7BxNLpzsrQVUy4INRGw6gZK6p1ccPbPkFxLCbXZjKsD86Nra qBcQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Y88FdVXAgfg5w8PyflknRqNxB6/N6fKsnjWxZd+03NM=; b=v4PQzhXbRmKxe08pfef7dw5VRI9B729Hiam6q3MMievXidA5kYIDxlxGkN7pyHl2u2 21+8RKM6+Nh4DXAG1wOPixzcd4glilJCfIOIr/+GZ090OSfyhZPkhGNNCO2hv9EORkth kJlZiGlddZgCtMoukrCghzyktbcBvMfB4PTaWYfWLXIn8FWXuQXxhGp/+vQ5FgfkWnFO grDefqKge/yJL7yEXp4i1C6GJIdav9Gc6dyLiMif2JmJwzSRg+XHaB/3+qa3K52LxGJP j3PLruM6crEEUzf2sGwT8Teo6TwLBhzBnfAGjAJia08pvKwycIaC0/NMkrzuTLVF4eCC tV0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ueh7Hse2; 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 s10si2745518plr.423.2020.10.27.14.35.12; Tue, 27 Oct 2020 14:36:16 -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=Ueh7Hse2; 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 S2505923AbgJ0Fi0 (ORCPT + 99 others); Tue, 27 Oct 2020 01:38:26 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:34114 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2441525AbgJ0FiZ (ORCPT ); Tue, 27 Oct 2020 01:38:25 -0400 Received: by mail-pj1-f65.google.com with SMTP id b6so250296pju.1 for ; Mon, 26 Oct 2020 22:38:25 -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:mime-version :content-transfer-encoding; bh=Y88FdVXAgfg5w8PyflknRqNxB6/N6fKsnjWxZd+03NM=; b=Ueh7Hse2bmKx46Y6BDGHFuX3F9o4sLgKwhpQ+5wTCBm7sBnNy0MBuNHCo7tIAjrwmC f3zFPYMUohNPlD71bm8dQ8sKaSIFHZrXyU6CyyktrId62npDXV/8a9igN+R1sOcinvIS F5Y3i2psZFaVJiMbtpCJlPCRkroZdRBjYIo0YTLB5v3qq/8wOncpfd9U2JF5jorYYlMb X2zWp2jFTdAzYyuKi5DlSKYUfjm9+S//e1rsrBtFjcAeFgrKQOv6zHgvUTSYk2lRHzRD h/ybJKwmLyjws40OiVuk0iVmrLCz004erYmuZV8etUwghc/vJpHsNLPp/oQRsfa+vKSn 9dmg== 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:mime-version :content-transfer-encoding; bh=Y88FdVXAgfg5w8PyflknRqNxB6/N6fKsnjWxZd+03NM=; b=WBUb8MyPQKtDTV16WbsV/mE7Qw8SYEsHpdfrIZ0RS5l9RC8DPdU08B2ocWOzBVjQGp syU+ifKmHp4yj0t8JZi/jGLr/advkP2CzeY5nQX9f5FQq2f/IlVzjeqCPHmhs+IN6ZPA LseazhKPq6W+B4bGs7RdEcGvc/sg/Q/3pepYvhI2bpaWPxxSh1xD2p9KYg0TBd0Ri3Vg edengSD7Zpbrqh61NGvYbTCmaMB4THZfTLPGVF8/WN6feqxFZauHhWnrMekXjzOfAWsO nfGu1eow6wt7IW1vNIdam1WSCO4qSHNDe3uUfoDfDb3X9UhSikVaevekAZbeBR8/108i 5BZQ== X-Gm-Message-State: AOAM5323JIdtcACNECArpZ9tgwk+n0uYYGvJOSzvkXyEpHBfnQ9dLAPf SfQUVuZaJ3JkUlEa6ur/b6rNEDnldwc= X-Received: by 2002:a17:90a:f206:: with SMTP id bs6mr484281pjb.214.1603777104571; Mon, 26 Oct 2020 22:38:24 -0700 (PDT) Received: from daehojeong1.seo.corp.google.com ([2401:fa00:d:11:a6ae:11ff:fe18:6ce2]) by smtp.gmail.com with ESMTPSA id z10sm573029pff.218.2020.10.26.22.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Oct 2020 22:38:23 -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 v4 1/2] f2fs: add F2FS_IOC_GET_COMPRESS_OPTION ioctl Date: Tue, 27 Oct 2020 14:38:17 +0900 Message-Id: <20201027053818.3291747-1-daeho43@gmail.com> X-Mailer: git-send-email 2.29.0.rc2.309.g374f81d7ae-goog 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_GET_COMPRESS_OPTION ioctl to get file compression option of a file. struct f2fs_comp_option { u8 algorithm; => compression algorithm => 0:lzo, 1:lz4, 2:zstd, 3:lzorle u8 log_cluster_size; => log scale cluster size => 2 ~ 8 }; struct f2fs_comp_option option; ioctl(fd, F2FS_IOC_GET_COMPRESS_OPTION, &option); Signed-off-by: Daeho Jeong --- v4: changed commit message. v3: changed the error number more specific. v2: added ioctl description. --- fs/f2fs/f2fs.h | 7 +++++++ fs/f2fs/file.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 53fe2853579c..a33c90cf979b 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -433,6 +433,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal, _IOR(F2FS_IOCTL_MAGIC, 19, __u64) #define F2FS_IOC_SEC_TRIM_FILE _IOW(F2FS_IOCTL_MAGIC, 20, \ struct f2fs_sectrim_range) +#define F2FS_IOC_GET_COMPRESS_OPTION _IOR(F2FS_IOCTL_MAGIC, 21, \ + struct f2fs_comp_option) /* * should be same as XFS_IOC_GOINGDOWN. @@ -481,6 +483,11 @@ struct f2fs_sectrim_range { u64 flags; }; +struct f2fs_comp_option { + u8 algorithm; + u8 log_cluster_size; +}; + /* for inline stuff */ #define DEF_INLINE_RESERVED_SIZE 1 static inline int get_extra_isize(struct inode *inode); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index ef5a844de53f..8922ab191a9d 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3936,6 +3936,33 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) return ret; } +static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg) +{ + struct inode *inode = file_inode(filp); + struct f2fs_comp_option option; + + if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) + return -EOPNOTSUPP; + + inode_lock(inode); + + if (!f2fs_compressed_file(inode)) { + inode_unlock(inode); + return -ENODATA; + } + + option.algorithm = F2FS_I(inode)->i_compress_algorithm; + option.log_cluster_size = F2FS_I(inode)->i_log_cluster_size; + + inode_unlock(inode); + + if (copy_to_user((struct f2fs_comp_option __user *)arg, &option, + sizeof(option))) + return -EFAULT; + + return 0; +} + long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) @@ -4024,6 +4051,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return f2fs_reserve_compress_blocks(filp, arg); case F2FS_IOC_SEC_TRIM_FILE: return f2fs_sec_trim_file(filp, arg); + case F2FS_IOC_GET_COMPRESS_OPTION: + return f2fs_ioc_get_compress_option(filp, arg); default: return -ENOTTY; } @@ -4194,6 +4223,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: case F2FS_IOC_RESERVE_COMPRESS_BLOCKS: case F2FS_IOC_SEC_TRIM_FILE: + case F2FS_IOC_GET_COMPRESS_OPTION: break; default: return -ENOIOCTLCMD; -- 2.29.0.rc2.309.g374f81d7ae-goog