Skip to content

Commit 1fa9c5c

Browse files
author
Miklos Szeredi
committed
ovl: use inode instead of dentry where possible
Passing dentry to some helpers is unnecessary. Simplify these cases. Signed-off-by: Miklos Szeredi <[email protected]>
1 parent cf4ef78 commit 1fa9c5c

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

fs/overlayfs/overlayfs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ const char *ovl_dentry_get_redirect(struct dentry *dentry);
401401
void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
402402
void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
403403
void ovl_dir_modified(struct dentry *dentry, bool impurity);
404-
u64 ovl_dentry_version_get(struct dentry *dentry);
404+
u64 ovl_inode_version_get(struct inode *inode);
405405
bool ovl_is_whiteout(struct dentry *dentry);
406406
struct file *ovl_path_open(const struct path *path, int flags);
407407
int ovl_copy_up_start(struct dentry *dentry, int flags);
@@ -571,9 +571,9 @@ int ovl_indexdir_cleanup(struct ovl_fs *ofs);
571571
* lower dir was removed under it and possibly before it was rotated from upper
572572
* to lower layer.
573573
*/
574-
static inline bool ovl_dir_is_real(struct dentry *dir)
574+
static inline bool ovl_dir_is_real(struct inode *dir)
575575
{
576-
return !ovl_test_flag(OVL_WHITEOUTS, d_inode(dir));
576+
return !ovl_test_flag(OVL_WHITEOUTS, dir);
577577
}
578578

579579
/* inode.c */

fs/overlayfs/readdir.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ void ovl_dir_cache_free(struct inode *inode)
235235
}
236236
}
237237

238-
static void ovl_cache_put(struct ovl_dir_file *od, struct dentry *dentry)
238+
static void ovl_cache_put(struct ovl_dir_file *od, struct inode *inode)
239239
{
240240
struct ovl_dir_cache *cache = od->cache;
241241

242242
WARN_ON(cache->refcount <= 0);
243243
cache->refcount--;
244244
if (!cache->refcount) {
245-
if (ovl_dir_cache(d_inode(dentry)) == cache)
246-
ovl_set_dir_cache(d_inode(dentry), NULL);
245+
if (ovl_dir_cache(inode) == cache)
246+
ovl_set_dir_cache(inode, NULL);
247247

248248
ovl_cache_free(&cache->entries);
249249
kfree(cache);
@@ -323,15 +323,15 @@ static void ovl_dir_reset(struct file *file)
323323
{
324324
struct ovl_dir_file *od = file->private_data;
325325
struct ovl_dir_cache *cache = od->cache;
326-
struct dentry *dentry = file->f_path.dentry;
326+
struct inode *inode = file_inode(file);
327327
bool is_real;
328328

329-
if (cache && ovl_dentry_version_get(dentry) != cache->version) {
330-
ovl_cache_put(od, dentry);
329+
if (cache && ovl_inode_version_get(inode) != cache->version) {
330+
ovl_cache_put(od, inode);
331331
od->cache = NULL;
332332
od->cursor = NULL;
333333
}
334-
is_real = ovl_dir_is_real(dentry);
334+
is_real = ovl_dir_is_real(inode);
335335
if (od->is_real != is_real) {
336336
/* is_real can only become false when dir is copied up */
337337
if (WARN_ON(is_real))
@@ -394,9 +394,10 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
394394
{
395395
int res;
396396
struct ovl_dir_cache *cache;
397+
struct inode *inode = d_inode(dentry);
397398

398-
cache = ovl_dir_cache(d_inode(dentry));
399-
if (cache && ovl_dentry_version_get(dentry) == cache->version) {
399+
cache = ovl_dir_cache(inode);
400+
if (cache && ovl_inode_version_get(inode) == cache->version) {
400401
WARN_ON(!cache->refcount);
401402
cache->refcount++;
402403
return cache;
@@ -418,8 +419,8 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
418419
return ERR_PTR(res);
419420
}
420421

421-
cache->version = ovl_dentry_version_get(dentry);
422-
ovl_set_dir_cache(d_inode(dentry), cache);
422+
cache->version = ovl_inode_version_get(inode);
423+
ovl_set_dir_cache(inode, cache);
423424

424425
return cache;
425426
}
@@ -596,16 +597,17 @@ static struct ovl_dir_cache *ovl_cache_get_impure(const struct path *path)
596597
{
597598
int res;
598599
struct dentry *dentry = path->dentry;
600+
struct inode *inode = d_inode(dentry);
599601
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
600602
struct ovl_dir_cache *cache;
601603

602-
cache = ovl_dir_cache(d_inode(dentry));
603-
if (cache && ovl_dentry_version_get(dentry) == cache->version)
604+
cache = ovl_dir_cache(inode);
605+
if (cache && ovl_inode_version_get(inode) == cache->version)
604606
return cache;
605607

606608
/* Impure cache is not refcounted, free it here */
607-
ovl_dir_cache_free(d_inode(dentry));
608-
ovl_set_dir_cache(d_inode(dentry), NULL);
609+
ovl_dir_cache_free(inode);
610+
ovl_set_dir_cache(inode, NULL);
609611

610612
cache = kzalloc(sizeof(struct ovl_dir_cache), GFP_KERNEL);
611613
if (!cache)
@@ -627,13 +629,13 @@ static struct ovl_dir_cache *ovl_cache_get_impure(const struct path *path)
627629
OVL_XATTR_IMPURE);
628630
ovl_drop_write(dentry);
629631
}
630-
ovl_clear_flag(OVL_IMPURE, d_inode(dentry));
632+
ovl_clear_flag(OVL_IMPURE, inode);
631633
kfree(cache);
632634
return NULL;
633635
}
634636

635-
cache->version = ovl_dentry_version_get(dentry);
636-
ovl_set_dir_cache(d_inode(dentry), cache);
637+
cache->version = ovl_inode_version_get(inode);
638+
ovl_set_dir_cache(inode, cache);
637639

638640
return cache;
639641
}
@@ -675,7 +677,7 @@ static bool ovl_fill_real(struct dir_context *ctx, const char *name,
675677
static bool ovl_is_impure_dir(struct file *file)
676678
{
677679
struct ovl_dir_file *od = file->private_data;
678-
struct inode *dir = d_inode(file->f_path.dentry);
680+
struct inode *dir = file_inode(file);
679681

680682
/*
681683
* Only upper dir can be impure, but if we are in the middle of
@@ -893,7 +895,7 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
893895
struct file *realfile;
894896
int err;
895897

896-
err = ovl_sync_status(OVL_FS(file->f_path.dentry->d_sb));
898+
err = ovl_sync_status(OVL_FS(file_inode(file)->i_sb));
897899
if (err <= 0)
898900
return err;
899901

@@ -913,7 +915,7 @@ static int ovl_dir_release(struct inode *inode, struct file *file)
913915

914916
if (od->cache) {
915917
inode_lock(inode);
916-
ovl_cache_put(od, file->f_path.dentry);
918+
ovl_cache_put(od, inode);
917919
inode_unlock(inode);
918920
}
919921
fput(od->realfile);
@@ -942,7 +944,7 @@ static int ovl_dir_open(struct inode *inode, struct file *file)
942944
return PTR_ERR(realfile);
943945
}
944946
od->realfile = realfile;
945-
od->is_real = ovl_dir_is_real(file->f_path.dentry);
947+
od->is_real = ovl_dir_is_real(inode);
946948
od->is_upper = OVL_TYPE_UPPER(type);
947949
file->private_data = od;
948950

fs/overlayfs/util.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static void ovl_dir_version_inc(struct dentry *dentry, bool impurity)
463463
* which have been copied up and have origins), so only need to note
464464
* changes to impure entries.
465465
*/
466-
if (!ovl_dir_is_real(dentry) || impurity)
466+
if (!ovl_dir_is_real(inode) || impurity)
467467
OVL_I(inode)->version++;
468468
}
469469

@@ -475,10 +475,8 @@ void ovl_dir_modified(struct dentry *dentry, bool impurity)
475475
ovl_dir_version_inc(dentry, impurity);
476476
}
477477

478-
u64 ovl_dentry_version_get(struct dentry *dentry)
478+
u64 ovl_inode_version_get(struct inode *inode)
479479
{
480-
struct inode *inode = d_inode(dentry);
481-
482480
WARN_ON(!inode_is_locked(inode));
483481
return OVL_I(inode)->version;
484482
}

0 commit comments

Comments
 (0)