Skip to content

Commit 37ebf05

Browse files
committed
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 <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 9e88f90 commit 37ebf05

4 files changed

Lines changed: 107 additions & 8 deletions

File tree

‎Documentation/filesystems/overlayfs.rst‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,41 @@ conflict with metacopy=on, and will result in an error.
371371
[*] redirect_dir=follow only conflicts with metacopy=on if upperdir=... is
372372
given.
373373

374+
375+
Data-only lower layers
376+
----------------------
377+
378+
With "metacopy" feature enabled, an overlayfs regular file may be a composition
379+
of information from up to three different layers:
380+
381+
1) metadata from a file in the upper layer
382+
383+
2) st_ino and st_dev object identifier from a file in a lower layer
384+
385+
3) data from a file in another lower layer (further below)
386+
387+
The "lower data" file can be on any lower layer, except from the top most
388+
lower layer.
389+
390+
Below the top most lower layer, any number of lower most layers may be defined
391+
as "data-only" lower layers, using double colon ("::") separators.
392+
A normal lower layer is not allowed to be below a data-only layer, so single
393+
colon separators are not allowed to the right of double colon ("::") separators.
394+
395+
396+
For example:
397+
398+
mount -t overlay overlay -olowerdir=/l1:/l2:/l3::/do1::/do2 /merged
399+
400+
The paths of files in the "data-only" lower layers are not visible in the
401+
merged overlayfs directories and the metadata and st_ino/st_dev of files
402+
in the "data-only" lower layers are not visible in overlayfs inodes.
403+
404+
Only the data of the files in the "data-only" lower layers may be visible
405+
when a "metacopy" file in one of the lower layers above it, has a "redirect"
406+
to the absolute path of the "lower data" file in the "data-only" lower layer.
407+
408+
374409
Sharing and copying layers
375410
--------------------------
376411

‎fs/overlayfs/namei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
356356
struct dentry *origin = NULL;
357357
int i;
358358

359-
for (i = 1; i < ofs->numlayer; i++) {
359+
for (i = 1; i <= ovl_numlowerlayer(ofs); i++) {
360360
/*
361361
* If lower fs uuid is not unique among lower fs we cannot match
362362
* fh->uuid to layer.

‎fs/overlayfs/ovl_entry.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ struct ovl_fs {
5757
unsigned int numlayer;
5858
/* Number of unique fs among layers including upper fs */
5959
unsigned int numfs;
60+
/* Number of data-only lower layers */
61+
unsigned int numdatalayer;
6062
const struct ovl_layer *layers;
6163
struct ovl_sb *fs;
6264
/* workbasedir is the path at workdir= mount option */
@@ -90,6 +92,13 @@ struct ovl_fs {
9092
errseq_t errseq;
9193
};
9294

95+
96+
/* Number of lower layers, not including data-only layers */
97+
static inline unsigned int ovl_numlowerlayer(struct ovl_fs *ofs)
98+
{
99+
return ofs->numlayer - ofs->numdatalayer - 1;
100+
}
101+
93102
static inline struct vfsmount *ovl_upper_mnt(struct ovl_fs *ofs)
94103
{
95104
return ofs->layers[0].mnt;

‎fs/overlayfs/super.c‎

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,18 +1568,31 @@ static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
15681568
return ofs->numfs++;
15691569
}
15701570

1571+
/*
1572+
* The fsid after the last lower fsid is used for the data layers.
1573+
* It is a "null fs" with a null sb, null uuid, and no pseudo dev.
1574+
*/
1575+
static int ovl_get_data_fsid(struct ovl_fs *ofs)
1576+
{
1577+
return ofs->numfs;
1578+
}
1579+
1580+
15711581
static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
15721582
struct path *stack, unsigned int numlower,
15731583
struct ovl_layer *layers)
15741584
{
15751585
int err;
15761586
unsigned int i;
15771587

1578-
ofs->fs = kcalloc(numlower + 1, sizeof(struct ovl_sb), GFP_KERNEL);
1588+
ofs->fs = kcalloc(numlower + 2, sizeof(struct ovl_sb), GFP_KERNEL);
15791589
if (ofs->fs == NULL)
15801590
return -ENOMEM;
15811591

1582-
/* idx/fsid 0 are reserved for upper fs even with lower only overlay */
1592+
/*
1593+
* idx/fsid 0 are reserved for upper fs even with lower only overlay
1594+
* and the last fsid is reserved for "null fs" of the data layers.
1595+
*/
15831596
ofs->numfs++;
15841597

15851598
/*
@@ -1604,7 +1617,10 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
16041617
struct inode *trap;
16051618
int fsid;
16061619

1607-
fsid = ovl_get_fsid(ofs, &stack[i]);
1620+
if (i < numlower - ofs->numdatalayer)
1621+
fsid = ovl_get_fsid(ofs, &stack[i]);
1622+
else
1623+
fsid = ovl_get_data_fsid(ofs);
16081624
if (fsid < 0)
16091625
return fsid;
16101626

@@ -1692,6 +1708,7 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
16921708
int err;
16931709
struct path *stack = NULL;
16941710
struct ovl_path *lowerstack;
1711+
unsigned int numlowerdata = 0;
16951712
unsigned int i;
16961713
struct ovl_entry *oe;
16971714

@@ -1704,13 +1721,50 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
17041721
if (!stack)
17051722
return ERR_PTR(-ENOMEM);
17061723

1707-
err = -EINVAL;
1708-
for (i = 0; i < numlower; i++) {
1724+
for (i = 0; i < numlower;) {
17091725
err = ovl_lower_dir(lower, &stack[i], ofs, &sb->s_stack_depth);
17101726
if (err)
17111727
goto out_err;
17121728

17131729
lower = strchr(lower, '\0') + 1;
1730+
1731+
i++;
1732+
if (i == numlower)
1733+
break;
1734+
1735+
err = -EINVAL;
1736+
/*
1737+
* Empty lower layer path could mean :: separator that indicates
1738+
* a data-only lower data.
1739+
* Several data-only layers are allowed, but they all need to be
1740+
* at the bottom of the stack.
1741+
*/
1742+
if (*lower) {
1743+
/* normal lower dir */
1744+
if (numlowerdata) {
1745+
pr_err("lower data-only dirs must be at the bottom of the stack.\n");
1746+
goto out_err;
1747+
}
1748+
} else {
1749+
/* data-only lower dir */
1750+
if (!ofs->config.metacopy) {
1751+
pr_err("lower data-only dirs require metacopy support.\n");
1752+
goto out_err;
1753+
}
1754+
if (i == numlower - 1) {
1755+
pr_err("lowerdir argument must not end with double colon.\n");
1756+
goto out_err;
1757+
}
1758+
lower++;
1759+
numlower--;
1760+
numlowerdata++;
1761+
}
1762+
}
1763+
1764+
if (numlowerdata) {
1765+
ofs->numdatalayer = numlowerdata;
1766+
pr_info("using the lowest %d of %d lowerdirs as data layers\n",
1767+
numlowerdata, numlower);
17141768
}
17151769

17161770
err = -EINVAL;
@@ -1725,12 +1779,13 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
17251779
goto out_err;
17261780

17271781
err = -ENOMEM;
1728-
oe = ovl_alloc_entry(numlower);
1782+
/* Data-only layers are not merged in root directory */
1783+
oe = ovl_alloc_entry(numlower - numlowerdata);
17291784
if (!oe)
17301785
goto out_err;
17311786

17321787
lowerstack = ovl_lowerstack(oe);
1733-
for (i = 0; i < numlower; i++) {
1788+
for (i = 0; i < numlower - numlowerdata; i++) {
17341789
lowerstack[i].dentry = dget(stack[i].dentry);
17351790
lowerstack[i].layer = &ofs->layers[i+1];
17361791
}

0 commit comments

Comments
 (0)