From f54c4657bd29cd0347490d355c9993fe7d3956d7 Mon Sep 17 00:00:00 2001 From: Luyao Wang Date: Fri, 2 Feb 2024 20:57:40 +0800 Subject: [PATCH] cloud dentry cred Signed-off-by: Luyao Wang Change-Id: I4ed83a6201b605b84da044b75d4011a71e0c8d7c --- fs/hmdfs/file_cloud.c | 11 +++++++++-- fs/hmdfs/hmdfs_dentryfile.c | 14 ++++---------- fs/hmdfs/hmdfs_dentryfile.h | 4 ++-- fs/hmdfs/hmdfs_dentryfile_cloud.c | 16 ++++++++++++++-- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/fs/hmdfs/file_cloud.c b/fs/hmdfs/file_cloud.c index b939b109913c..f94c5e6c92e4 100644 --- a/fs/hmdfs/file_cloud.c +++ b/fs/hmdfs/file_cloud.c @@ -273,7 +273,7 @@ static int hmdfs_readpage(struct file *file, struct page *page) lower_file = gfi->lower_file; else goto out; - + page_buf = kmap(page); if (!page_buf) goto out; @@ -321,6 +321,13 @@ const struct address_space_operations hmdfs_aops_cloud = { .readpages = hmdfs_readpages_cloud, }; +static int hmdfs_metainfo_read_cloud(struct hmdfs_sb_info * sbi, struct file *filp, void *buffer, int size, int bidx) +{ + loff_t pos = get_dentry_group_pos(bidx); + + return cache_file_read_cloud(sbi, filp, buffer, (size_t)size, &pos); +} + int analysis_dentry_file_from_cloud(struct hmdfs_sb_info *sbi, struct file *file, struct file *handler, struct dir_context *ctx) @@ -354,7 +361,7 @@ int analysis_dentry_file_from_cloud(struct hmdfs_sb_info *sbi, } for (i = group_id; i < group_num; i++) { - int ret = hmdfs_metainfo_read_nocred(handler, dentry_group, + int ret = hmdfs_metainfo_read_cloud(sbi,handler, dentry_group, sizeof(struct hmdfs_dentry_group_cloud), i); if (ret != sizeof(struct hmdfs_dentry_group_cloud)) { diff --git a/fs/hmdfs/hmdfs_dentryfile.c b/fs/hmdfs/hmdfs_dentryfile.c index 5ec0980b7bf3..a6d409f55678 100644 --- a/fs/hmdfs/hmdfs_dentryfile.c +++ b/fs/hmdfs/hmdfs_dentryfile.c @@ -402,14 +402,6 @@ char *hmdfs_connect_path(const char *path, const char *name) return buf; } -int hmdfs_metainfo_read_nocred(struct file *filp, - void *buffer, int size, int bidx) -{ - loff_t pos = get_dentry_group_pos(bidx); - - return kernel_read(filp, buffer, (size_t)size, &pos); -} - int hmdfs_metainfo_read(struct hmdfs_sb_info *sbi, struct file *filp, void *buffer, int size, int bidx) { @@ -931,7 +923,7 @@ int create_dentry(struct dentry *child_dentry, struct inode *inode, goto find; add: pos = get_dentry_group_pos(bidx); - update_dentry(dentry_blk, child_dentry, inode, sbi->sb, namehash, + update_dentry(dentry_blk, child_dentry, inode, sbi->sb, namehash, bit_pos); size = cache_file_write(sbi, file, dentry_blk, sizeof(struct hmdfs_dentry_group), &pos); @@ -1416,6 +1408,7 @@ int get_cloud_cache_file(struct dentry *dentry, struct hmdfs_sb_info *sbi) char *fullname = NULL; char *cache_file_name = NULL; char *kvalue = NULL; + const struct cred *old_cred; item = hmdfs_find_cache_item(CLOUD_DEVICE, dentry); if (item) { @@ -1460,7 +1453,7 @@ int get_cloud_cache_file(struct dentry *dentry, struct hmdfs_sb_info *sbi) snprintf(dirname, PATH_MAX, "%s/dentry_cache/cloud/", sbi->cache_dir); snprintf(fullname, PATH_MAX, "%s%s", dirname, cache_file_name); - + old_cred = hmdfs_override_creds(sbi->cred); filp = filp_open(fullname, O_RDWR | O_LARGEFILE, 0); if (IS_ERR(filp)) { hmdfs_debug("open fail %ld", PTR_ERR(filp)); @@ -1491,6 +1484,7 @@ int get_cloud_cache_file(struct dentry *dentry, struct hmdfs_sb_info *sbi) ret = 0; out: + hmdfs_revert_creds(old_cred); kfree(relative_path); kfree(dirname); kfree(fullname); diff --git a/fs/hmdfs/hmdfs_dentryfile.h b/fs/hmdfs/hmdfs_dentryfile.h index b3907ce1b86e..a55ebe5b7035 100644 --- a/fs/hmdfs/hmdfs_dentryfile.h +++ b/fs/hmdfs/hmdfs_dentryfile.h @@ -285,10 +285,10 @@ long cache_file_truncate(struct hmdfs_sb_info *sbi, const struct path *path, loff_t length); ssize_t cache_file_read(struct hmdfs_sb_info *sbi, struct file *filp, void *buf, size_t count, loff_t *pos); +ssize_t cache_file_read_cloud(struct hmdfs_sb_info *sbi, struct file *filp, void *buf, + size_t count, loff_t *pos); ssize_t cache_file_write(struct hmdfs_sb_info *sbi, struct file *filp, const void *buf, size_t count, loff_t *pos); -int hmdfs_metainfo_read_nocred(struct file *filp, - void *buffer, int size, int bidx); int hmdfs_metainfo_read(struct hmdfs_sb_info *sbi, struct file *filp, void *buffer, int buffersize, int bidx); diff --git a/fs/hmdfs/hmdfs_dentryfile_cloud.c b/fs/hmdfs/hmdfs_dentryfile_cloud.c index 4e7dd009913d..bf79edcbd208 100644 --- a/fs/hmdfs/hmdfs_dentryfile_cloud.c +++ b/fs/hmdfs/hmdfs_dentryfile_cloud.c @@ -8,6 +8,7 @@ #include "hmdfs_dentryfile_cloud.h" #include +#include "authority/authenrication.h" void hmdfs_init_dcache_lookup_ctx_cloud( struct hmdfs_dcache_lookup_ctx_cloud *ctx, struct hmdfs_sb_info *sbi, @@ -23,6 +24,17 @@ void hmdfs_init_dcache_lookup_ctx_cloud( ctx->insense_page = NULL; } +ssize_t cache_file_read_cloud(struct hmdfs_sb_info *sbi, struct file *filp, void *buf, + size_t count, loff_t *pos) +{ + const struct cred *old_cred = hmdfs_override_creds(sbi->cred); + ssize_t ret = kernel_read(filp, buf, count, pos); + + hmdfs_revert_creds(old_cred); + + return ret; +} + static struct hmdfs_dentry_group_cloud *find_dentry_page(struct hmdfs_sb_info *sbi, pgoff_t index, struct file *filp) { @@ -37,12 +49,12 @@ static struct hmdfs_dentry_group_cloud *find_dentry_page(struct hmdfs_sb_info *s err = hmdfs_wlock_file(filp, pos, DENTRYGROUP_SIZE); if (err) { - hmdfs_err("lock file pos %lld failed %d", pos, err); + hmdfs_err("lock file pos %lld failed", pos); kfree(dentry_blk); return NULL; } - size = kernel_read(filp, dentry_blk, (size_t)DENTRYGROUP_SIZE, + size = cache_file_read_cloud(filp, dentry_blk, (size_t)DENTRYGROUP_SIZE, &pos); if (size != DENTRYGROUP_SIZE) { hmdfs_err("read pos %lld failed %d", pos, size); -- Gitee