<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">2023年3月2日 15:17,Jia Zhu <<a href="mailto:zhujia.zj@bytedance.com" class="">zhujia.zj@bytedance.com</a>> 写道:</div><br class="Apple-interchange-newline"><div class=""><div class="">In order to support mounting multi-blobs container image as a single<br class="">block device, add flattened block device feature for EROFS.<br class=""><br class="">In this mode, all meta/data contents will be mapped into one block<br class="">address. User could compose a block device(by nbd/ublk/virtio-blk/<br class="">vhost-user-blk) from multiple sources and mount the block device by<br class="">EROFS directly. It can reduce the number of block devices used, and<br class="">it's also benefits in both VM file passthrough and distributed storage<br class="">scenarios.<br class=""><br class="">You can test this using the method mentioned by:<br class=""><a href="https://github.com/dragonflyoss/image-service/pull/1111" class="">https://github.com/dragonflyoss/image-service/pull/1111</a><br class="">1. Compose a (nbd)block device from multi-blobs.<br class="">2. Mount EROFS on mntdir/.<br class="">3. Compare the md5sum between source dir and mntdir/.<br class=""><br class="">Later, we could also use it to refer original tar blobs.<br class=""><br class="">Signed-off-by: Jia Zhu <zhujia.zj@bytedance.com><br class="">Signed-off-by: Xin Yin <yinxin.x@bytedance.com><br class="">Reviewed-by: Jingbo Xu <jefflexu@linux.alibaba.com><br class=""></div></div></blockquote><div>Tested-by: Jiang Liu <<a href="mailto:gerry@alibaba.linux.com" class="">gerry@linux.alibaba.com</a>></div><br class=""><blockquote type="cite" class=""><div class=""><div class="">---<br class="">v3:<br class="">1. Move the flatdev check down after all sanity checks.(Jingbo Xu)<br class="">2. Add Reviewed-by tag.<br class="">---<br class=""> fs/erofs/data.c | 8 ++++++--<br class=""> fs/erofs/internal.h | 1 +<br class=""> fs/erofs/super.c | 5 ++++-<br class=""> 3 files changed, 11 insertions(+), 3 deletions(-)<br class=""><br class="">diff --git a/fs/erofs/data.c b/fs/erofs/data.c<br class="">index e16545849ea7..818f78ce648c 100644<br class="">--- a/fs/erofs/data.c<br class="">+++ b/fs/erofs/data.c<br class="">@@ -197,7 +197,6 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>struct erofs_device_info *dif;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>int id;<br class=""><br class="">-<span class="Apple-tab-span" style="white-space:pre"> </span>/* primary device by default */<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>map->m_bdev = sb->s_bdev;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>map->m_daxdev = EROFS_SB(sb)->dax_dev;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>map->m_dax_part_off = EROFS_SB(sb)->dax_part_off;<br class="">@@ -210,12 +209,17 @@ int erofs_map_dev(struct super_block *sb, struct erofs_map_dev *map)<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>up_read(&devs->rwsem);<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>return -ENODEV;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>}<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>if (devs->flatdev) {<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>map->m_pa += blknr_to_addr(dif->mapped_blkaddr);<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>up_read(&devs->rwsem);<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>return 0;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>}<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>map->m_bdev = dif->bdev;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>map->m_daxdev = dif->dax_dev;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>map->m_dax_part_off = dif->dax_part_off;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>map->m_fscache = dif->fscache;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>up_read(&devs->rwsem);<br class="">-<span class="Apple-tab-span" style="white-space:pre"> </span>} else if (devs->extra_devices) {<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>} else if (devs->extra_devices && !devs->flatdev) {<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>down_read(&devs->rwsem);<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>idr_for_each_entry(&devs->tree, dif, id) {<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>erofs_off_t startoff, length;<br class="">diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h<br class="">index 3f3561d37d1b..4fee380a98d9 100644<br class="">--- a/fs/erofs/internal.h<br class="">+++ b/fs/erofs/internal.h<br class="">@@ -81,6 +81,7 @@ struct erofs_dev_context {<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>struct rw_semaphore rwsem;<br class=""><br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>unsigned int extra_devices;<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>bool flatdev;<br class=""> };<br class=""><br class=""> struct erofs_fs_context {<br class="">diff --git a/fs/erofs/super.c b/fs/erofs/super.c<br class="">index 19b1ae79cec4..0afdfce372b3 100644<br class="">--- a/fs/erofs/super.c<br class="">+++ b/fs/erofs/super.c<br class="">@@ -248,7 +248,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>if (IS_ERR(fscache))<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>return PTR_ERR(fscache);<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>dif->fscache = fscache;<br class="">-<span class="Apple-tab-span" style="white-space:pre"> </span>} else {<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>} else if (!sbi->devs->flatdev) {<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>bdev = blkdev_get_by_path(dif->path, FMODE_READ | FMODE_EXCL,<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span> sb->s_type);<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>if (IS_ERR(bdev))<br class="">@@ -290,6 +290,9 @@ static int erofs_scan_devices(struct super_block *sb,<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>if (!ondisk_extradevs)<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>return 0;<br class=""><br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span>if (!sbi->devs->extra_devices && !erofs_is_fscache_mode(sb))<br class="">+<span class="Apple-tab-span" style="white-space:pre"> </span><span class="Apple-tab-span" style="white-space:pre"> </span>sbi->devs->flatdev = true;<br class="">+<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>sbi->device_id_mask = roundup_pow_of_two(ondisk_extradevs + 1) - 1;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>pos = le16_to_cpu(dsb->devt_slotoff) * EROFS_DEVT_SLOT_SIZE;<br class=""> <span class="Apple-tab-span" style="white-space:pre"> </span>down_read(&sbi->devs->rwsem);<br class="">-- <br class="">2.20.1<br class=""></div></div></blockquote></div><br class=""></body></html>