Re: [PATCH v4 2/3] initramfs: read metadata from special file METADATA!!!

From: Mimi Zohar
Date: Mon Jul 01 2019 - 08:54:46 EST


Hi Roberto,

> diff --git a/init/initramfs.c b/init/initramfs.c
> index 5de396a6aac0..862c03123de8 100644
> --- a/init/initramfs.c
> +++ b/init/initramfs.c

> +static int __init do_process_metadata(char *buf, int len, bool last)
> +{

Part of the problem in upstreaming CPIO xattr support has been the
difficulty in reading and understanding the initramfs code due to a
lack of comments. ÂAt least for any new code, let's add some comments
to simplify the review. ÂIn this case, understanding "last", before
reading the code, would help.

Mimi

> + int ret = 0;
> +
> + if (!metadata_buf) {
> + metadata_buf_ptr = metadata_buf = kmalloc(body_len, GFP_KERNEL);
> + if (!metadata_buf_ptr) {
> + ret = -ENOMEM;
> + goto out;
> + }
> +
> + metadata_len = body_len;
> + }
> +
> + if (metadata_buf_ptr + len > metadata_buf + metadata_len) {
> + ret = -EINVAL;
> + goto out;
> + }
> +
> + memcpy(metadata_buf_ptr, buf, len);
> + metadata_buf_ptr += len;
> +
> + if (last)
> + do_parse_metadata(previous_name_buf);
> +out:
> + if (ret < 0 || last) {
> + kfree(metadata_buf);
> + metadata_buf = NULL;
> + metadata = 0;
> + }
> +
> + return ret;
> +}
> +
> static int __init do_copy(void)
> {
> if (byte_count >= body_len) {
> if (xwrite(wfd, victim, body_len) != body_len)
> error("write error");
> + if (metadata)
> + do_process_metadata(victim, body_len, true);
> ksys_close(wfd);
> do_utime(vcollected, mtime);
> kfree(vcollected);
> @@ -458,6 +500,8 @@ static int __init do_copy(void)
> } else {
> if (xwrite(wfd, victim, byte_count) != byte_count)
> error("write error");
> + if (metadata)
> + do_process_metadata(victim, byte_count, false);
> body_len -= byte_count;
> eat(byte_count);
> return 1;
>