@@ -216,7 +216,6 @@ static void ovl_free_fs(struct ovl_fs *ofs)
216
216
iput (ofs -> workbasedir_trap );
217
217
iput (ofs -> indexdir_trap );
218
218
iput (ofs -> workdir_trap );
219
- iput (ofs -> upperdir_trap );
220
219
dput (ofs -> whiteout );
221
220
dput (ofs -> indexdir );
222
221
dput (ofs -> workdir );
@@ -225,8 +224,7 @@ static void ovl_free_fs(struct ovl_fs *ofs)
225
224
dput (ofs -> workbasedir );
226
225
if (ofs -> upperdir_locked )
227
226
ovl_inuse_unlock (ovl_upper_mnt (ofs )-> mnt_root );
228
- mntput (ofs -> upper_mnt );
229
- for (i = 1 ; i < ofs -> numlayer ; i ++ ) {
227
+ for (i = 0 ; i < ofs -> numlayer ; i ++ ) {
230
228
iput (ofs -> layers [i ].trap );
231
229
mntput (ofs -> layers [i ].mnt );
232
230
}
@@ -837,11 +835,11 @@ static int ovl_lower_dir(const char *name, struct path *path,
837
835
838
836
err = ovl_mount_dir_noesc (name , path );
839
837
if (err )
840
- goto out ;
838
+ return err ;
841
839
842
840
err = ovl_check_namelen (path , ofs , name );
843
841
if (err )
844
- goto out_put ;
842
+ return err ;
845
843
846
844
* stack_depth = max (* stack_depth , path -> mnt -> mnt_sb -> s_stack_depth );
847
845
@@ -863,11 +861,6 @@ static int ovl_lower_dir(const char *name, struct path *path,
863
861
ofs -> xino_mode = -1 ;
864
862
865
863
return 0 ;
866
-
867
- out_put :
868
- path_put_init (path );
869
- out :
870
- return err ;
871
864
}
872
865
873
866
/* Workdir should not be subdir of upperdir and vice versa */
@@ -1074,7 +1067,7 @@ static int ovl_report_in_use(struct ovl_fs *ofs, const char *name)
1074
1067
}
1075
1068
1076
1069
static int ovl_get_upper (struct super_block * sb , struct ovl_fs * ofs ,
1077
- struct path * upperpath )
1070
+ struct ovl_layer * upper_layer , struct path * upperpath )
1078
1071
{
1079
1072
struct vfsmount * upper_mnt ;
1080
1073
int err ;
@@ -1094,7 +1087,7 @@ static int ovl_get_upper(struct super_block *sb, struct ovl_fs *ofs,
1094
1087
if (err )
1095
1088
goto out ;
1096
1089
1097
- err = ovl_setup_trap (sb , upperpath -> dentry , & ofs -> upperdir_trap ,
1090
+ err = ovl_setup_trap (sb , upperpath -> dentry , & upper_layer -> trap ,
1098
1091
"upperdir" );
1099
1092
if (err )
1100
1093
goto out ;
@@ -1108,7 +1101,9 @@ static int ovl_get_upper(struct super_block *sb, struct ovl_fs *ofs,
1108
1101
1109
1102
/* Don't inherit atime flags */
1110
1103
upper_mnt -> mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME );
1111
- ofs -> upper_mnt = upper_mnt ;
1104
+ upper_layer -> mnt = upper_mnt ;
1105
+ upper_layer -> idx = 0 ;
1106
+ upper_layer -> fsid = 0 ;
1112
1107
1113
1108
/*
1114
1109
* Inherit SB_NOSEC flag from upperdir.
@@ -1458,30 +1453,20 @@ static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
1458
1453
}
1459
1454
1460
1455
static int ovl_get_layers (struct super_block * sb , struct ovl_fs * ofs ,
1461
- struct path * stack , unsigned int numlower )
1456
+ struct path * stack , unsigned int numlower ,
1457
+ struct ovl_layer * layers )
1462
1458
{
1463
1459
int err ;
1464
1460
unsigned int i ;
1465
- struct ovl_layer * layers ;
1466
1461
1467
1462
err = - ENOMEM ;
1468
- layers = kcalloc (numlower + 1 , sizeof (struct ovl_layer ), GFP_KERNEL );
1469
- if (!layers )
1470
- goto out ;
1471
- ofs -> layers = layers ;
1472
-
1473
1463
ofs -> fs = kcalloc (numlower + 1 , sizeof (struct ovl_sb ), GFP_KERNEL );
1474
1464
if (ofs -> fs == NULL )
1475
1465
goto out ;
1476
1466
1477
1467
/* idx/fsid 0 are reserved for upper fs even with lower only overlay */
1478
1468
ofs -> numfs ++ ;
1479
1469
1480
- layers [0 ].mnt = ovl_upper_mnt (ofs );
1481
- layers [0 ].idx = 0 ;
1482
- layers [0 ].fsid = 0 ;
1483
- ofs -> numlayer = 1 ;
1484
-
1485
1470
/*
1486
1471
* All lower layers that share the same fs as upper layer, use the same
1487
1472
* pseudo_dev as upper layer. Allocate fs[0].pseudo_dev even for lower
@@ -1579,44 +1564,30 @@ static int ovl_get_layers(struct super_block *sb, struct ovl_fs *ofs,
1579
1564
}
1580
1565
1581
1566
static struct ovl_entry * ovl_get_lowerstack (struct super_block * sb ,
1582
- struct ovl_fs * ofs )
1567
+ const char * lower , unsigned int numlower ,
1568
+ struct ovl_fs * ofs , struct ovl_layer * layers )
1583
1569
{
1584
1570
int err ;
1585
- char * lowertmp , * lower ;
1586
1571
struct path * stack = NULL ;
1587
- unsigned int stacklen , numlower = 0 , i ;
1572
+ unsigned int i ;
1588
1573
struct ovl_entry * oe ;
1589
1574
1590
- err = - ENOMEM ;
1591
- lowertmp = kstrdup (ofs -> config .lowerdir , GFP_KERNEL );
1592
- if (!lowertmp )
1593
- goto out_err ;
1594
-
1595
- err = - EINVAL ;
1596
- stacklen = ovl_split_lowerdirs (lowertmp );
1597
- if (stacklen > OVL_MAX_STACK ) {
1598
- pr_err ("too many lower directories, limit is %d\n" ,
1599
- OVL_MAX_STACK );
1600
- goto out_err ;
1601
- } else if (!ofs -> config .upperdir && stacklen == 1 ) {
1575
+ if (!ofs -> config .upperdir && numlower == 1 ) {
1602
1576
pr_err ("at least 2 lowerdir are needed while upperdir nonexistent\n" );
1603
- goto out_err ;
1577
+ return ERR_PTR ( - EINVAL ) ;
1604
1578
} else if (!ofs -> config .upperdir && ofs -> config .nfs_export &&
1605
1579
ofs -> config .redirect_follow ) {
1606
1580
pr_warn ("NFS export requires \"redirect_dir=nofollow\" on non-upper mount, falling back to nfs_export=off.\n" );
1607
1581
ofs -> config .nfs_export = false;
1608
1582
}
1609
1583
1610
- err = - ENOMEM ;
1611
- stack = kcalloc (stacklen , sizeof (struct path ), GFP_KERNEL );
1584
+ stack = kcalloc (numlower , sizeof (struct path ), GFP_KERNEL );
1612
1585
if (!stack )
1613
- goto out_err ;
1586
+ return ERR_PTR ( - ENOMEM ) ;
1614
1587
1615
1588
err = - EINVAL ;
1616
- lower = lowertmp ;
1617
- for (numlower = 0 ; numlower < stacklen ; numlower ++ ) {
1618
- err = ovl_lower_dir (lower , & stack [numlower ], ofs ,
1619
- & sb -> s_stack_depth );
1589
+ for (i = 0 ; i < numlower ; i ++ ) {
1590
+ err = ovl_lower_dir (lower , & stack [i ], ofs , & sb -> s_stack_depth );
1620
1591
if (err )
1621
1592
goto out_err ;
1622
1593
@@ -1630,7 +1601,7 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
1630
1601
goto out_err ;
1631
1602
}
1632
1603
1633
- err = ovl_get_layers (sb , ofs , stack , numlower );
1604
+ err = ovl_get_layers (sb , ofs , stack , numlower , layers );
1634
1605
if (err )
1635
1606
goto out_err ;
1636
1607
@@ -1648,7 +1619,6 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
1648
1619
for (i = 0 ; i < numlower ; i ++ )
1649
1620
path_put (& stack [i ]);
1650
1621
kfree (stack );
1651
- kfree (lowertmp );
1652
1622
1653
1623
return oe ;
1654
1624
@@ -1772,7 +1742,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1772
1742
struct dentry * root_dentry ;
1773
1743
struct ovl_entry * oe ;
1774
1744
struct ovl_fs * ofs ;
1745
+ struct ovl_layer * layers ;
1775
1746
struct cred * cred ;
1747
+ char * splitlower = NULL ;
1748
+ unsigned int numlower ;
1776
1749
int err ;
1777
1750
1778
1751
sb -> s_d_op = & ovl_dentry_operations ;
@@ -1804,6 +1777,26 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1804
1777
goto out_err ;
1805
1778
}
1806
1779
1780
+ err = - ENOMEM ;
1781
+ splitlower = kstrdup (ofs -> config .lowerdir , GFP_KERNEL );
1782
+ if (!splitlower )
1783
+ goto out_err ;
1784
+
1785
+ numlower = ovl_split_lowerdirs (splitlower );
1786
+ if (numlower > OVL_MAX_STACK ) {
1787
+ pr_err ("too many lower directories, limit is %d\n" ,
1788
+ OVL_MAX_STACK );
1789
+ goto out_err ;
1790
+ }
1791
+
1792
+ layers = kcalloc (numlower + 1 , sizeof (struct ovl_layer ), GFP_KERNEL );
1793
+ if (!layers )
1794
+ goto out_err ;
1795
+
1796
+ ofs -> layers = layers ;
1797
+ /* Layer 0 is reserved for upper even if there's no upper */
1798
+ ofs -> numlayer = 1 ;
1799
+
1807
1800
sb -> s_stack_depth = 0 ;
1808
1801
sb -> s_maxbytes = MAX_LFS_FILESIZE ;
1809
1802
atomic_long_set (& ofs -> last_ino , 1 );
@@ -1825,7 +1818,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1825
1818
goto out_err ;
1826
1819
}
1827
1820
1828
- err = ovl_get_upper (sb , ofs , & upperpath );
1821
+ err = ovl_get_upper (sb , ofs , & layers [ 0 ], & upperpath );
1829
1822
if (err )
1830
1823
goto out_err ;
1831
1824
@@ -1840,7 +1833,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1840
1833
sb -> s_time_gran = ovl_upper_mnt (ofs )-> mnt_sb -> s_time_gran ;
1841
1834
1842
1835
}
1843
- oe = ovl_get_lowerstack (sb , ofs );
1836
+ oe = ovl_get_lowerstack (sb , splitlower , numlower , ofs , layers );
1844
1837
err = PTR_ERR (oe );
1845
1838
if (IS_ERR (oe ))
1846
1839
goto out_err ;
@@ -1903,6 +1896,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1903
1896
goto out_free_oe ;
1904
1897
1905
1898
mntput (upperpath .mnt );
1899
+ kfree (splitlower );
1906
1900
1907
1901
sb -> s_root = root_dentry ;
1908
1902
@@ -1912,6 +1906,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
1912
1906
ovl_entry_stack_free (oe );
1913
1907
kfree (oe );
1914
1908
out_err :
1909
+ kfree (splitlower );
1915
1910
path_put (& upperpath );
1916
1911
ovl_free_fs (ofs );
1917
1912
out :
0 commit comments