Overlay文件系统是覆盖在基础文件系统上的一种堆栈式文件系统,所以也是一种wrapfs,Documentation有下面的介绍。
An overlay-filesystem tries to present a
filesystem which is the result over overlaying one filesystem on top
of the other.
堆栈式文件系统由于内存问题不能一直堆叠,本篇主要来介绍下Overlay的mount流程,旨在梳理如何限制堆栈式文件系统堆叠层数。下面的代码基于Kernel 5.10源码。直接从mount_nodev中注册的回调函数看起,前面的部分是常规的初始化流程。
static int ovl_fill_super(struct super_block *sb, void *data, int silent)
{
struct path upperpath = {
};
struct dentry *root_dentry;
struct ovl_entry *oe;
struct ovl_fs *ofs;
struct ovl_layer *layers;
struct cred *cred;
char *splitlower = NULL;
unsigned int numlower;
int err;
err = -EIO;
if (WARN_ON(sb->s_user_ns != current_user_ns()))
goto out;
sb->s_d_op = &ovl_dentry_operations; //注册dentry操作函数
err = -ENOMEM;
ofs = kzalloc(sizeof(struct ovl_fs), GFP_KERNEL);
if (!ofs)
goto out;
err = -ENOMEM;
ofs->creator_cred = cred = prepare_creds();
if (!cred)
goto out_err;
/* Is there a reason anyone would want not to share whiteouts? */
ofs->share_whiteout = true;
ofs->config.index = ovl_index_def;
ofs->config.uuid = true;
ofs->config.nfs_export = ovl_nfs_export_def;
ofs->config.xino = ovl_xino_def();
ofs->config.metacopy = ovl_metacopy_def;
err =