ovl: introduce data-only lower layers
Introduce the format lowerdir=lower1:lower2::lowerdata1::lowerdata2 where the lower layers on the right of the :: separators are not merged into the overlayfs merge dirs. Data-only lower layers are only allowed at the bottom of the stack. The files in those layers are only meant to be accessible via absolute redirect from metacopy files in lower layers. Following changes will implement lookup in the data layers. This feature was requested for composefs ostree use case, where the lower data layer should only be accessiable via absolute redirects from metacopy inodes. The lower data layers are not required to a have a unique uuid or any uuid at all, because they are never used to compose the overlayfs inode st_ino/st_dev. Reviewed-by: Alexander Larsson <alexl@redhat.com> Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
parent
9e88f90524
commit
37ebf056d6
|
@ -371,6 +371,41 @@ conflict with metacopy=on, and will result in an error.
|
||||||
[*] redirect_dir=follow only conflicts with metacopy=on if upperdir=... is
|
[*] redirect_dir=follow only conflicts with metacopy=on if upperdir=... is
|
||||||
given.
|
given.
|
||||||
|
|
||||||
|
|
||||||
|
Data-only lower layers
|
||||||
|
----------------------
|
||||||
|
|
||||||
|
With "metacopy" feature enabled, an overlayfs regular file may be a composition
|
||||||
|
of information from up to three different layers:
|
||||||
|
|
||||||
|
1) metadata from a file in the upper layer
|
||||||
|
|
||||||
|
2) st_ino and st_dev object identifier from a file in a lower layer
|
||||||
|
|
||||||
|
3) data from a file in another lower layer (further below)
|
||||||
|
|
||||||
|
The "lower data" file can be on any lower layer, except from the top most
|
||||||
|
lower layer.
|
||||||
|
|
||||||
|
Below the top most lower layer, any number of lower most layers may be defined
|
||||||
|
as "data-only" lower layers, using double colon ("::") separators.
|
||||||
|
A normal lower layer is not allowed to be below a data-only layer, so single
|
||||||
|
colon separators are not allowed to the right of double colon ("::") separators.
|
||||||
|
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
mount -t overlay overlay -olowerdir=/l1:/l2:/l3::/do1::/do2 /merged
|
||||||
|
|
||||||
|
The paths of files in the "data-only" lower layers are not visible in the
|
||||||
|
merged overlayfs directories and the metadata and st_ino/st_dev of files
|
||||||
|
in the "data-only" lower layers are not visible in overlayfs inodes.
|
||||||
|
|
||||||
|
Only the data of the files in the "data-only" lower layers may be visible
|
||||||
|
when a "metacopy" file in one of the lower layers above it, has a "redirect"
|
||||||
|
to the absolute path of the "lower data" file in the "data-only" lower layer.
|
||||||
|
|
||||||
|
|
||||||
Sharing and copying layers
|
Sharing and copying layers
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
|
|
|
@ -356,7 +356,7 @@ int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
|
||||||
struct dentry *origin = NULL;
|
struct dentry *origin = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 1; i < ofs->numlayer; i++) {
|
for (i = 1; i <= ovl_numlowerlayer(ofs); i++) {
|
||||||
/*
|
/*
|
||||||
* If lower fs uuid is not unique among lower fs we cannot match
|
* If lower fs uuid is not unique among lower fs we cannot match
|
||||||
* fh->uuid to layer.
|
* fh->uuid to layer.
|
||||||
|
|
|
@ -57,6 +57,8 @@ struct ovl_fs {
|
||||||
unsigned int numlayer;
|
unsigned int numlayer;
|
||||||
/* Number of unique fs among layers including upper fs */
|
/* Number of unique fs among layers including upper fs */
|
||||||
unsigned int numfs;
|
unsigned int numfs;
|
||||||
|
/* Number of data-only lower layers */
|
||||||
|
unsigned int numdatalayer;
|
||||||
const struct ovl_layer *layers;
|
const struct ovl_layer *layers;
|
||||||
struct ovl_sb *fs;
|
struct ovl_sb *fs;
|
||||||
/* workbasedir is the path at workdir= mount option */
|
/* workbasedir is the path at workdir= mount option */
|
||||||
|
@ -90,6 +92,13 @@ struct ovl_fs {
|
||||||
errseq_t errseq;
|
errseq_t errseq;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Number of lower layers, not including data-only layers */
|
||||||
|
static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
|
||||||
|
{
|
||||||
|
return ofs->numlayer - ofs->numdatalayer - 1;
|
||||||
|
}
|
||||||
|
|
||||||
static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
|
static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
|
||||||
{
|
{
|
||||||
return ofs->layers[0].mnt;
|
return ofs->layers[0].mnt;
|
||||||
|
|
|
@ -1568,6 +1568,16 @@ static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
|
||||||
return ofs->numfs++;
|
return ofs->numfs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The fsid after the last lower fsid is used for the data layers.
|
||||||
|
* It is a "null fs" with a null sb, null uuid, and no pseudo dev.
|
||||||
|
*/
|
||||||
|
static int ovl_get_data_fsid(struct ovl_fs *ofs)
|
||||||
|
{
|
||||||
|
return ofs->numfs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
|
static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
|
||||||
struct path *stack, unsigned int numlower,
|
struct path *stack, unsigned int numlower,
|
||||||
struct ovl_layer *layers)
|
struct ovl_layer *layers)
|
||||||
|
@ -1575,11 +1585,14 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
|
||||||
int err;
|
int err;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
ofs->fs = kcalloc(numlower + 1, sizeof(struct ovl_sb), GFP_KERNEL);
|
ofs->fs = kcalloc(numlower + 2, sizeof(struct ovl_sb), GFP_KERNEL);
|
||||||
if (ofs->fs == NULL)
|
if (ofs->fs == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
/* idx/fsid 0 are reserved for upper fs even with lower only overlay */
|
/*
|
||||||
|
* idx/fsid 0 are reserved for upper fs even with lower only overlay
|
||||||
|
* and the last fsid is reserved for "null fs" of the data layers.
|
||||||
|
*/
|
||||||
ofs->numfs++;
|
ofs->numfs++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1604,7 +1617,10 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
|
||||||
struct inode *trap;
|
struct inode *trap;
|
||||||
int fsid;
|
int fsid;
|
||||||
|
|
||||||
fsid = ovl_get_fsid(ofs, &stack[i]);
|
if (i < numlower - ofs->numdatalayer)
|
||||||
|
fsid = ovl_get_fsid(ofs, &stack[i]);
|
||||||
|
else
|
||||||
|
fsid = ovl_get_data_fsid(ofs);
|
||||||
if (fsid < 0)
|
if (fsid < 0)
|
||||||
return fsid;
|
return fsid;
|
||||||
|
|
||||||
|
@ -1692,6 +1708,7 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
|
||||||
int err;
|
int err;
|
||||||
struct path *stack = NULL;
|
struct path *stack = NULL;
|
||||||
struct ovl_path *lowerstack;
|
struct ovl_path *lowerstack;
|
||||||
|
unsigned int numlowerdata = 0;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct ovl_entry *oe;
|
struct ovl_entry *oe;
|
||||||
|
|
||||||
|
@ -1704,13 +1721,50 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
|
||||||
if (!stack)
|
if (!stack)
|
||||||
return ERR_PTR(-ENOMEM);
|
return ERR_PTR(-ENOMEM);
|
||||||
|
|
||||||
err = -EINVAL;
|
for (i = 0; i < numlower;) {
|
||||||
for (i = 0; i < numlower; i++) {
|
|
||||||
err = ovl_lower_dir(lower, &stack[i], ofs, &sb->s_stack_depth);
|
err = ovl_lower_dir(lower, &stack[i], ofs, &sb->s_stack_depth);
|
||||||
if (err)
|
if (err)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
lower = strchr(lower, '\0') + 1;
|
lower = strchr(lower, '\0') + 1;
|
||||||
|
|
||||||
|
i++;
|
||||||
|
if (i == numlower)
|
||||||
|
break;
|
||||||
|
|
||||||
|
err = -EINVAL;
|
||||||
|
/*
|
||||||
|
* Empty lower layer path could mean :: separator that indicates
|
||||||
|
* a data-only lower data.
|
||||||
|
* Several data-only layers are allowed, but they all need to be
|
||||||
|
* at the bottom of the stack.
|
||||||
|
*/
|
||||||
|
if (*lower) {
|
||||||
|
/* normal lower dir */
|
||||||
|
if (numlowerdata) {
|
||||||
|
pr_err("lower data-only dirs must be at the bottom of the stack.\n");
|
||||||
|
goto out_err;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* data-only lower dir */
|
||||||
|
if (!ofs->config.metacopy) {
|
||||||
|
pr_err("lower data-only dirs require metacopy support.\n");
|
||||||
|
goto out_err;
|
||||||
|
}
|
||||||
|
if (i == numlower - 1) {
|
||||||
|
pr_err("lowerdir argument must not end with double colon.\n");
|
||||||
|
goto out_err;
|
||||||
|
}
|
||||||
|
lower++;
|
||||||
|
numlower--;
|
||||||
|
numlowerdata++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numlowerdata) {
|
||||||
|
ofs->numdatalayer = numlowerdata;
|
||||||
|
pr_info("using the lowest %d of %d lowerdirs as data layers\n",
|
||||||
|
numlowerdata, numlower);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
|
@ -1725,12 +1779,13 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
oe = ovl_alloc_entry(numlower);
|
/* Data-only layers are not merged in root directory */
|
||||||
|
oe = ovl_alloc_entry(numlower - numlowerdata);
|
||||||
if (!oe)
|
if (!oe)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
lowerstack = ovl_lowerstack(oe);
|
lowerstack = ovl_lowerstack(oe);
|
||||||
for (i = 0; i < numlower; i++) {
|
for (i = 0; i < numlower - numlowerdata; i++) {
|
||||||
lowerstack[i].dentry = dget(stack[i].dentry);
|
lowerstack[i].dentry = dget(stack[i].dentry);
|
||||||
lowerstack[i].layer = &ofs->layers[i+1];
|
lowerstack[i].layer = &ofs->layers[i+1];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue