mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Sheng Yong <shengyong2021@gmail.com>
Cc: linux-kernel@vger.kernel.org, Sheng Yong <shengyong1@xiaomi.com>,
	Wang Shuai <wangshuai12@xiaomi.com>, Gao Xiang <xiang@kernel.org>,
	Chao Yu <chao@kernel.org>, Yue Hu <zbestahu@gmail.com>,
	Jeffle Xu <jefflexu@linux.alibaba.com>,
	Sandeep Dhavale <dhavale@google.com>,
	linux-erofs mailing list <linux-erofs@lists.ozlabs.org>
Subject: Re: [RFC PATCH] erofs: add start offset for file-backed mount
Date: Tue, 25 Mar 2025 09:37:39 +0800	[thread overview]
Message-ID: <1b0ce59a-30a7-46e3-9c63-72c3f8d44b77@linux.alibaba.com> (raw)
In-Reply-To: <20250324022849.2715578-1-shengyong1@xiaomi.com>

Hi Yong!

On 2025/3/24 10:28, Sheng Yong wrote:
> From: Sheng Yong <shengyong1@xiaomi.com>
> 
> When attempting to use an archive file, such as APEX on android,
> as a file-backed mount source, it fails because EROFS image within
> the archive file does not start at offset 0. As a result, a loop
> device is still needed to attach the image file at an appropriate
> offset first.
> 
> To address this issue, this patch parses the `source' parameter in
> EROFS to accept a start offset for the file-backed mount. The format
> is `/path/to/archive_file:offs', where `offs' represents the start
> offset. EROFS will add this offset before performing read requests.
> 
> Signed-off-by: Sheng Yong <shengyong1@xiaomi.com>
> Signed-off-by: Wang Shuai <wangshuai12@xiaomi.com>

Sorry for late reply. Yeah, that is a great feature.

> ---

...

> @@ -411,6 +412,31 @@ static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
>   #endif
>   }
>   
> +static loff_t erofs_fc_parse_source(struct fs_context *fc,
> +				    struct fs_parameter *param)
> +{
> +	const char *devname = param->string;
> +	const char *fofs_start __maybe_unused;
> +	loff_t fofs = 0;
> +
> +	if (!devname || !*devname)
> +		return invalfc(fc, "Empty source");
> +
> +#ifdef CONFIG_EROFS_FS_BACKED_BY_FILE
> +	fofs_start = strchr(devname, ':');
> +	if (!fofs_start)
> +		goto out;
> +	if (kstrtoll(fofs_start + 1, 0, &fofs) < 0)
> +		return invalfc(fc, "Invalid filebacked offset %s", fofs_start);
> +	fc->source = kstrndup(devname, fofs_start - devname, GFP_KERNEL);
> +	return fofs;
> +out:
> +#endif
> +	fc->source = devname;
> +	param->string = NULL;
> +	return fofs;
> +}

Could we just add a new mount option for this, and apply this feature
for both file-backed mounts and bdev-based mounts?

Twist source option is not quite clean on my side.



> +
>   static int erofs_fc_parse_param(struct fs_context *fc,
>   				struct fs_parameter *param)
>   {
> @@ -507,6 +533,11 @@ static int erofs_fc_parse_param(struct fs_context *fc,
>   		errorfc(fc, "%s option not supported", erofs_fs_parameters[opt].name);
>   #endif
>   		break;
> +	case Opt_source:
> +		sbi->dif0.fofs = erofs_fc_parse_source(fc, param);
> +		if (sbi->dif0.fofs < 0)
> +			return -EINVAL;
> +		break;
>   	}
>   	return 0;
>   }
> @@ -697,6 +728,10 @@ static int erofs_fc_get_tree(struct fs_context *fc)
>   		file = filp_open(fc->source, O_RDONLY | O_LARGEFILE, 0);
>   		if (IS_ERR(file))
>   			return PTR_ERR(file);
> +		if (sbi->dif0.fofs + PAGE_SIZE >= i_size_read(file_inode(file))) {
> +			fput(file);
> +			return invalf(fc, "Start offset too large");
> +		}

I guess we need to verify the offset is block-aligned too.

Thanks,
Gao Xiang

      reply	other threads:[~2025-03-25  1:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24  2:28 Sheng Yong
2025-03-25  1:37 ` Gao Xiang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b0ce59a-30a7-46e3-9c63-72c3f8d44b77@linux.alibaba.com \
    --to=hsiangkao@linux.alibaba.com \
    --cc=chao@kernel.org \
    --cc=dhavale@google.com \
    --cc=jefflexu@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shengyong1@xiaomi.com \
    --cc=shengyong2021@gmail.com \
    --cc=wangshuai12@xiaomi.com \
    --cc=xiang@kernel.org \
    --cc=zbestahu@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®