From nobody Wed Nov 27 10:40:59 2024 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5C51635 for ; Fri, 11 Oct 2024 06:51:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728629508; cv=none; b=DjeJQT2TsKpZBn0YWmaIQ501YSuMzMOi2zpxFLixxOh1YU9t4ixlQZq79gGKddE9duORmNxcMo9Py/fHIlHG04OSx/K4FalYKshDeIkUSD5YB6ZPVb/r6MWJ4ZyBOvN1luTsL+P9gf8VQtEg9U2DdATJwxiOaHQ9rgjQ1g6NVBs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728629508; c=relaxed/simple; bh=z84KbUksL+ig752MN4+yXHP/+ziUJayhbQclHqpv+lQ=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=XMZ0N0/O/JyH6k2JBIvMkd7dckE7pU5uMy+Lu+QbvVxZ+Yg2PL/0rV9bMgOM6jzfjJTB/2BkkHYIWNZLspNPsr22IcRhxFDWVz8YUWX/FlLvl8SUBb4gbtajXkUcBlVCO+Z3cwBpu8GsiXcEEG/eGhlTlOGctRpsR4YOYwR/7HI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=RYlKzdRc; arc=none smtp.client-ip=115.124.30.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="RYlKzdRc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1728629503; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=9Jq7WlCziE6Y2VeyCMIXiyZ4N1+DiD4cKivRAbahRII=; b=RYlKzdRczAWMo+DBV6GQwNI2WOnx3PcthvX41hac4boGvXq/5TXAA2KxqQK2O9ysAQ4sI7Gc51aAlTrlHeaFAgsUtsMgzeVCrSZaV1BRLSQfyqOxuWAPsk/6eG6Tq7zZ+Qro7g+18QXTpnUShDM1ROiJMM6+6Og3XXFPh15j8II= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WGp69Ai_1728629490 cluster:ay36) by smtp.aliyun-inc.com; Fri, 11 Oct 2024 14:51:43 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang Subject: [PATCH] erofs: add SEEK_{DATA,HOLE} support Date: Fri, 11 Oct 2024 14:51:28 +0800 Message-ID: <20241011065128.2097377-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Many userspace programs (including erofs-utils itself) uses SEEK_DATA / SEEK_HOLE to parse hole extents in addition to FIEMAP. Signed-off-by: Gao Xiang Reviewed-by: Chao Yu --- fs/erofs/data.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fs/erofs/data.c b/fs/erofs/data.c index 61debd799cf9..6355866220ff 100644 --- a/fs/erofs/data.c +++ b/fs/erofs/data.c @@ -473,8 +473,32 @@ static int erofs_file_mmap(struct file *file, struct v= m_area_struct *vma) #define erofs_file_mmap generic_file_readonly_mmap #endif =20 +static loff_t erofs_file_llseek(struct file *file, loff_t offset, int when= ce) +{ + struct inode *inode =3D file->f_mapping->host; + const struct iomap_ops *ops =3D &erofs_iomap_ops; + + if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) +#ifdef CONFIG_EROFS_FS_ZIP + ops =3D &z_erofs_iomap_report_ops; +#else + return generic_file_llseek(file, offset, whence); +#endif + + if (whence =3D=3D SEEK_HOLE) + offset =3D iomap_seek_hole(inode, offset, ops); + else if (whence =3D=3D SEEK_DATA) + offset =3D iomap_seek_data(inode, offset, ops); + else + return generic_file_llseek(file, offset, whence); + + if (offset < 0) + return offset; + return vfs_setpos(file, offset, inode->i_sb->s_maxbytes); +} + const struct file_operations erofs_file_fops =3D { - .llseek =3D generic_file_llseek, + .llseek =3D erofs_file_llseek, .read_iter =3D erofs_file_read_iter, .mmap =3D erofs_file_mmap, .get_unmapped_area =3D thp_get_unmapped_area, --=20 2.43.5