diff options
author | Amir Goldstein <amir73il@gmail.com> | 2018-01-17 07:40:27 -0500 |
---|---|---|
committer | Miklos Szeredi <mszeredi@redhat.com> | 2018-01-24 05:26:05 -0500 |
commit | 061701540349c30d72e48a201449a840c77ad509 (patch) | |
tree | 46d3e9191ba287cd420af0a41bd5aba86bb50a89 | |
parent | 4b91c30a5a19332e8dd10b601d05b72caf657730 (diff) |
ovl: lookup indexed ancestor of lower dir
ovl_lookup_real() in lower layer walks back lower parents to find the
topmost indexed parent. If an indexed ancestor is found before reaching
lower layer root, ovl_lookup_real() is called recursively with upper
layer to walk back from indexed upper to the topmost connected/hashed
upper parent (or up to root).
ovl_lookup_real() in upper layer then walks forward to connect the topmost
upper overlay dir dentry and ovl_lookup_real() in lower layer continues to
walk forward to connect the decoded lower overlay dir dentry.
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
-rw-r--r-- | fs/overlayfs/export.c | 41 | ||||
-rw-r--r-- | fs/overlayfs/namei.c | 20 | ||||
-rw-r--r-- | fs/overlayfs/overlayfs.h | 2 |
3 files changed, 56 insertions, 7 deletions
diff --git a/fs/overlayfs/export.c b/fs/overlayfs/export.c index 092e6e8c9258..b65ea49de457 100644 --- a/fs/overlayfs/export.c +++ b/fs/overlayfs/export.c | |||
@@ -294,6 +294,10 @@ fail: | |||
294 | goto out; | 294 | goto out; |
295 | } | 295 | } |
296 | 296 | ||
297 | static struct dentry *ovl_lookup_real(struct super_block *sb, | ||
298 | struct dentry *real, | ||
299 | struct ovl_layer *layer); | ||
300 | |||
297 | /* | 301 | /* |
298 | * Lookup an indexed or hashed overlay dentry by real inode. | 302 | * Lookup an indexed or hashed overlay dentry by real inode. |
299 | */ | 303 | */ |
@@ -301,9 +305,16 @@ static struct dentry *ovl_lookup_real_inode(struct super_block *sb, | |||
301 | struct dentry *real, | 305 | struct dentry *real, |
302 | struct ovl_layer *layer) | 306 | struct ovl_layer *layer) |
303 | { | 307 | { |
308 | struct ovl_fs *ofs = sb->s_fs_info; | ||
309 | struct ovl_layer upper_layer = { .mnt = ofs->upper_mnt }; | ||
310 | struct dentry *index = NULL; | ||
304 | struct dentry *this = NULL; | 311 | struct dentry *this = NULL; |
305 | struct inode *inode; | 312 | struct inode *inode; |
306 | 313 | ||
314 | /* | ||
315 | * Decoding upper dir from index is expensive, so first try to lookup | ||
316 | * overlay dentry in inode/dcache. | ||
317 | */ | ||
307 | inode = ovl_lookup_inode(sb, real, !layer->idx); | 318 | inode = ovl_lookup_inode(sb, real, !layer->idx); |
308 | if (IS_ERR(inode)) | 319 | if (IS_ERR(inode)) |
309 | return ERR_CAST(inode); | 320 | return ERR_CAST(inode); |
@@ -312,7 +323,35 @@ static struct dentry *ovl_lookup_real_inode(struct super_block *sb, | |||
312 | iput(inode); | 323 | iput(inode); |
313 | } | 324 | } |
314 | 325 | ||
315 | /* TODO: use index when looking up by origin inode */ | 326 | /* |
327 | * For decoded lower dir file handle, lookup index by origin to check | ||
328 | * if lower dir was copied up and and/or removed. | ||
329 | */ | ||
330 | if (!this && layer->idx && ofs->indexdir && !WARN_ON(!d_is_dir(real))) { | ||
331 | index = ovl_lookup_index(ofs, NULL, real, false); | ||
332 | if (IS_ERR(index)) | ||
333 | return index; | ||
334 | } | ||
335 | |||
336 | /* Get connected upper overlay dir from index */ | ||
337 | if (index) { | ||
338 | struct dentry *upper = ovl_index_upper(ofs, index); | ||
339 | |||
340 | dput(index); | ||
341 | if (IS_ERR_OR_NULL(upper)) | ||
342 | return upper; | ||
343 | |||
344 | /* | ||
345 | * ovl_lookup_real() in lower layer may call recursively once to | ||
346 | * ovl_lookup_real() in upper layer. The first level call walks | ||
347 | * back lower parents to the topmost indexed parent. The second | ||
348 | * recursive call walks back from indexed upper to the topmost | ||
349 | * connected/hashed upper parent (or up to root). | ||
350 | */ | ||
351 | this = ovl_lookup_real(sb, upper, &upper_layer); | ||
352 | dput(upper); | ||
353 | } | ||
354 | |||
316 | if (!this) | 355 | if (!this) |
317 | return NULL; | 356 | return NULL; |
318 | 357 | ||
diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c index 6199bf7a77c7..c5449efd96d5 100644 --- a/fs/overlayfs/namei.c +++ b/fs/overlayfs/namei.c | |||
@@ -661,11 +661,9 @@ struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh) | |||
661 | return ERR_PTR(err); | 661 | return ERR_PTR(err); |
662 | } | 662 | } |
663 | 663 | ||
664 | static struct dentry *ovl_lookup_index(struct dentry *dentry, | 664 | struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, |
665 | struct dentry *upper, | 665 | struct dentry *origin, bool verify) |
666 | struct dentry *origin) | ||
667 | { | 666 | { |
668 | struct ovl_fs *ofs = dentry->d_sb->s_fs_info; | ||
669 | struct dentry *index; | 667 | struct dentry *index; |
670 | struct inode *inode; | 668 | struct inode *inode; |
671 | struct qstr name; | 669 | struct qstr name; |
@@ -693,6 +691,16 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, | |||
693 | inode = d_inode(index); | 691 | inode = d_inode(index); |
694 | if (d_is_negative(index)) { | 692 | if (d_is_negative(index)) { |
695 | goto out_dput; | 693 | goto out_dput; |
694 | } else if (ovl_is_whiteout(index) && !verify) { | ||
695 | /* | ||
696 | * When index lookup is called with !verify for decoding an | ||
697 | * overlay file handle, a whiteout index implies that decode | ||
698 | * should treat file handle as stale and no need to print a | ||
699 | * warning about it. | ||
700 | */ | ||
701 | dput(index); | ||
702 | index = ERR_PTR(-ESTALE); | ||
703 | goto out; | ||
696 | } else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) || | 704 | } else if (ovl_dentry_weird(index) || ovl_is_whiteout(index) || |
697 | ((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) { | 705 | ((inode->i_mode ^ d_inode(origin)->i_mode) & S_IFMT)) { |
698 | /* | 706 | /* |
@@ -706,7 +714,7 @@ static struct dentry *ovl_lookup_index(struct dentry *dentry, | |||
706 | index, d_inode(index)->i_mode & S_IFMT, | 714 | index, d_inode(index)->i_mode & S_IFMT, |
707 | d_inode(origin)->i_mode & S_IFMT); | 715 | d_inode(origin)->i_mode & S_IFMT); |
708 | goto fail; | 716 | goto fail; |
709 | } else if (is_dir) { | 717 | } else if (is_dir && verify) { |
710 | if (!upper) { | 718 | if (!upper) { |
711 | pr_warn_ratelimited("overlayfs: suspected uncovered redirected dir found (origin=%pd2, index=%pd2).\n", | 719 | pr_warn_ratelimited("overlayfs: suspected uncovered redirected dir found (origin=%pd2, index=%pd2).\n", |
712 | origin, index); | 720 | origin, index); |
@@ -943,7 +951,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, | |||
943 | 951 | ||
944 | if (origin && ovl_indexdir(dentry->d_sb) && | 952 | if (origin && ovl_indexdir(dentry->d_sb) && |
945 | (!d.is_dir || ovl_index_all(dentry->d_sb))) { | 953 | (!d.is_dir || ovl_index_all(dentry->d_sb))) { |
946 | index = ovl_lookup_index(dentry, upperdentry, origin); | 954 | index = ovl_lookup_index(ofs, upperdentry, origin, true); |
947 | if (IS_ERR(index)) { | 955 | if (IS_ERR(index)) { |
948 | err = PTR_ERR(index); | 956 | err = PTR_ERR(index); |
949 | index = NULL; | 957 | index = NULL; |
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h index bf17bf97c50f..0df25a9c94bd 100644 --- a/fs/overlayfs/overlayfs.h +++ b/fs/overlayfs/overlayfs.h | |||
@@ -274,6 +274,8 @@ struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index); | |||
274 | int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); | 274 | int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index); |
275 | int ovl_get_index_name(struct dentry *origin, struct qstr *name); | 275 | int ovl_get_index_name(struct dentry *origin, struct qstr *name); |
276 | struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); | 276 | struct dentry *ovl_get_index_fh(struct ovl_fs *ofs, struct ovl_fh *fh); |
277 | struct dentry *ovl_lookup_index(struct ovl_fs *ofs, struct dentry *upper, | ||
278 | struct dentry *origin, bool verify); | ||
277 | int ovl_path_next(int idx, struct dentry *dentry, struct path *path); | 279 | int ovl_path_next(int idx, struct dentry *dentry, struct path *path); |
278 | struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, | 280 | struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry, |
279 | unsigned int flags); | 281 | unsigned int flags); |