From e9f4fc2f658958a37f859a37084560c592c162ec Mon Sep 17 00:00:00 2001 From: YangXin <245051644@qq.com> Date: Fri, 10 Feb 2023 13:55:57 +0000 Subject: [PATCH] Adapt to kernel 6.1 file system interface changes. Signed-off-by: YangXin <245051644@qq.com> --- qtfs/qtfs/ops.h | 2 +- qtfs/qtfs/proc.c | 6 +++--- qtfs/qtfs/qtfs-mod.c | 5 +++-- qtfs/qtfs/sb.c | 43 ++++++++++++++++++++++------------------ qtfs/qtfs/xattr.c | 4 ++++ qtfs/qtfs_server/fsops.c | 16 +++++++-------- 6 files changed, 43 insertions(+), 33 deletions(-) diff --git a/qtfs/qtfs/ops.h b/qtfs/qtfs/ops.h index 5cab367..a18f4da 100644 --- a/qtfs/qtfs/ops.h +++ b/qtfs/qtfs/ops.h @@ -15,7 +15,7 @@ bool is_sb_proc(struct super_block *sb); struct inode *qtfs_iget(struct super_block *sb, struct inode_info *ii); const char *qtfs_getlink(struct dentry *dentry, struct inode *inode, struct delayed_call *done); -int qtfs_getattr(const struct path *, struct kstat *, u32, unsigned int); +int qtfs_getattr(struct user_namespace *mnt_userns, const struct path *, struct kstat *, u32, unsigned int); struct dentry * qtfs_lookup(struct inode *, struct dentry *, unsigned int); #endif diff --git a/qtfs/qtfs/proc.c b/qtfs/qtfs/proc.c index 60401d9..e37303e 100644 --- a/qtfs/qtfs/proc.c +++ b/qtfs/qtfs/proc.c @@ -9,7 +9,7 @@ struct dentry *qtfs_proc_lookup(struct inode *parent_inode, struct dentry *child_dentry, unsigned int flags); const char *qtfs_proc_getlink(struct dentry *dentry, struct inode *inode, struct delayed_call *done); -int qtfs_proc_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags); +int qtfs_proc_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags); enum qtfs_type qtfs_get_type(char *str) { @@ -187,7 +187,7 @@ remote: return qtfs_getlink(dentry, inode, done); } -int qtfs_proc_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags) +int qtfs_proc_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags) { char cpath[NAME_MAX] = {0}; char tmp[NAME_MAX] = {0}; @@ -223,5 +223,5 @@ int qtfs_proc_getattr(const struct path *path, struct kstat *stat, u32 req_mask, } remote: - return qtfs_getattr(path, stat, req_mask, flags); + return qtfs_getattr(NULL, path, stat, req_mask, flags); } diff --git a/qtfs/qtfs/qtfs-mod.c b/qtfs/qtfs/qtfs-mod.c index abd9443..eb8d21a 100644 --- a/qtfs/qtfs/qtfs-mod.c +++ b/qtfs/qtfs/qtfs-mod.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include "conn.h" #include "qtfs-mod.h" @@ -114,7 +115,7 @@ connecting: msleep(500); } if (pvar == NULL) { - do_exit(0); + return 0; } qtfs_info("qtfs epoll thread establish a new connection."); req = qtfs_sock_msg_buf(pvar, QTFS_RECV); @@ -170,7 +171,7 @@ connecting: qtfs_err("conn send failed, ret:%d\n", ret); } qtfs_epoll_cut_conn(pvar); - do_exit(0); + return 0; } struct file_operations qtfs_misc_fops = { diff --git a/qtfs/qtfs/sb.c b/qtfs/qtfs/sb.c index 104d137..38cac43 100644 --- a/qtfs/qtfs/sb.c +++ b/qtfs/qtfs/sb.c @@ -461,13 +461,12 @@ static vm_fault_t qtfs_vm_fault(struct vm_fault *vmf) return ret; } -static void qtfs_map_pages(struct vm_fault *vmf, +static vm_fault_t qtfs_map_pages(struct vm_fault *vmf, pgoff_t start_pgoff, pgoff_t end_pgoff) { qtfs_info("qtfs map pages enter, pgoff:%lu start:%lu end:%lu.", vmf->pgoff, start_pgoff, end_pgoff); - filemap_map_pages(vmf, start_pgoff, end_pgoff); - return; + return filemap_map_pages(vmf, start_pgoff, end_pgoff); } static vm_fault_t qtfs_page_mkwrite(struct vm_fault *vmf) @@ -665,7 +664,6 @@ static struct file_operations qtfs_file_ops = { .poll = qtfsfifo_poll, }; - static int qtfs_readpage(struct file *file, struct page *page) { void *kaddr = NULL; @@ -682,6 +680,14 @@ static int qtfs_readpage(struct file *file, struct page *page) return 0; } +static int qtfs_read_folio(struct file *file, struct folio *folio) +{ + struct page *page = &folio->page; + qtfs_readpage(file, page); + + return 0; +} + static struct page **qtfs_alloc_pages(unsigned int nr) { struct page **pages = kzalloc(nr * (sizeof(struct page *)), GFP_KERNEL); @@ -726,19 +732,18 @@ static int qtfs_writepages(struct address_space *mapping, return 0; } -static int qtfs_setpagedirty(struct page *page) +static bool qtfs_dirty_folio(struct address_space *mapping, struct folio *folio) { qtfs_info("qtfs set page dirty."); - __set_page_dirty_nobuffers(page); - return 0; + return filemap_dirty_folio(mapping, folio); } static const struct address_space_operations qtfs_aops = { - .readpage = qtfs_readpage, + .read_folio = qtfs_read_folio, .readahead = qtfs_readahead, .writepage = qtfs_writepage, .writepages = qtfs_writepages, - .set_page_dirty = qtfs_setpagedirty, + .dirty_folio = qtfs_dirty_folio, }; int qtfs_new_entry(struct inode *inode, struct dentry *dentry) @@ -758,7 +763,7 @@ int qtfs_new_entry(struct inode *inode, struct dentry *dentry) return 0; } -int qtfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) +int qtfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode) { struct qtfs_sock_var_s *pvar = qtfs_conn_get_param(); struct qtreq_mkdir *req = NULL; @@ -793,7 +798,7 @@ int qtfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) return ret; } -int qtfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) +int qtfs_create(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl) { struct qtfs_sock_var_s *pvar = qtfs_conn_get_param(); struct qtreq_icreate *req; @@ -833,7 +838,7 @@ int qtfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool exc return ret ? ret : ret2; } -int qtfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) +int qtfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) { struct qtfs_sock_var_s *pvar = qtfs_conn_get_param(); struct qtreq_mknod *req; @@ -1093,7 +1098,7 @@ err_end: return error; } -int qtfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) +int qtfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, const char *symname) { struct qtfs_sock_var_s *pvar = qtfs_conn_get_param(); struct qtreq_symlink *req; @@ -1138,7 +1143,7 @@ err_end: return error; } -int qtfs_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags) +int qtfs_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags) { struct qtfs_sock_var_s *pvar = qtfs_conn_get_param(); struct qtreq_getattr *req; @@ -1182,7 +1187,7 @@ int qtfs_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsi return 0; } -int qtfs_setattr(struct dentry *dentry, struct iattr *attr) +int qtfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, struct iattr *attr) { struct qtfs_sock_var_s *pvar = qtfs_conn_get_param(); struct qtreq_setattr *req; @@ -1277,9 +1282,9 @@ const char *qtfs_getlink(struct dentry *dentry, return link; } -int qtfs_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry, - unsigned int flags) +int qtfs_rename(struct user_namespace *mnt_userns, struct inode *old_dir, + struct dentry *old_dentry, struct inode *new_dir, + struct dentry *new_dentry, unsigned int flags) { struct qtreq_rename *req; struct qtrsp_rename *rsp; @@ -1364,7 +1369,7 @@ static int qtfs_fill_super(struct super_block *sb, void *priv_data, int silent) root_inode = new_inode(sb); root_inode->i_ino = 1; - inode_init_owner(root_inode, NULL, mode); + inode_init_owner(&init_user_ns, root_inode, NULL, mode); root_inode->i_sb = sb; if (priv->type == QTFS_PROC) { qtfs_info("qtfs type: proc\n"); diff --git a/qtfs/qtfs/xattr.c b/qtfs/qtfs/xattr.c index a2a605d..61153c0 100644 --- a/qtfs/qtfs/xattr.c +++ b/qtfs/qtfs/xattr.c @@ -59,6 +59,7 @@ static int qtfs_xattr_set(const struct xattr_handler *handler, static int qtfs_xattr_user_set(const struct xattr_handler *handler, + struct user_namespace *mnt_userns, struct dentry *unused, struct inode *inode, const char *name, const void *value, size_t size, int flags) @@ -69,6 +70,7 @@ qtfs_xattr_user_set(const struct xattr_handler *handler, static int qtfs_xattr_trusted_set(const struct xattr_handler *handler, + struct user_namespace *mnt_userns, struct dentry *unused, struct inode *inode, const char *name, const void *value, size_t size, int flags) @@ -78,6 +80,7 @@ qtfs_xattr_trusted_set(const struct xattr_handler *handler, static int qtfs_xattr_security_set(const struct xattr_handler *handler, + struct user_namespace *mnt_userns, struct dentry *unused, struct inode *inode, const char *name, const void *value, size_t size, int flags) @@ -87,6 +90,7 @@ qtfs_xattr_security_set(const struct xattr_handler *handler, static int qtfs_xattr_hurd_set(const struct xattr_handler *handler, + struct user_namespace *mnt_userns, struct dentry *unused, struct inode *inode, const char *name, const void *value, size_t size, int flags) diff --git a/qtfs/qtfs_server/fsops.c b/qtfs/qtfs_server/fsops.c index 6c3e201..87caf90 100644 --- a/qtfs/qtfs_server/fsops.c +++ b/qtfs/qtfs_server/fsops.c @@ -431,7 +431,7 @@ static int handle_lookup(struct qtserver_arg *arg) return sizeof(struct qtrsp_lookup); } -static int qtfs_filldir(struct dir_context *ctx, const char *name, int namelen, +static bool qtfs_filldir(struct dir_context *ctx, const char *name, int namelen, loff_t offset, u64 ino, unsigned int d_type) { struct qtfs_dirent64 *dirent, *prev; @@ -440,7 +440,7 @@ static int qtfs_filldir(struct dir_context *ctx, const char *name, int namelen, int prev_reclen; if (reclen > buf->count) - return -EINVAL; + return false; prev_reclen = buf->prev_reclen; dirent = buf->dir; @@ -455,7 +455,7 @@ static int qtfs_filldir(struct dir_context *ctx, const char *name, int namelen, buf->dir = (void *)dirent + reclen; buf->count -= reclen; buf->vldcnt++; - return 0; + return true; } static int handle_readdir(struct qtserver_arg *arg) @@ -642,7 +642,7 @@ static int handle_setattr(struct qtserver_arg *arg) } inode_lock(inode); - rsp->errno = notify_change(path.dentry, &req->attr, NULL); + rsp->errno = notify_change(&init_user_ns, path.dentry, &req->attr, NULL); if (rsp->errno < 0) { rsp->ret = QTFS_ERR; qtfs_err("handle setattr, path:<%s> failed with %d.\n", req->path, ret); @@ -716,7 +716,7 @@ retry: req->mode &= ~current_umask(); error = security_path_mknod(&path, dent, req->mode, req->dev); if (!error) - error = vfs_mknod(path.dentry->d_inode, dent, req->mode, req->dev); + error = vfs_mknod(&init_user_ns, path.dentry->d_inode, dent, req->mode, req->dev); done_path_create(&path, dent); if (error == -ESTALE && !(flags & LOOKUP_REVAL)) { flags |= LOOKUP_REVAL; @@ -794,7 +794,7 @@ retry: return sizeof(struct qtrsp_symlink); } - rsp->errno = vfs_symlink(path.dentry->d_inode, dentry, oldname); + rsp->errno = vfs_symlink(&init_user_ns, path.dentry->d_inode, dentry, oldname); done_path_create(&path, dentry); if (rsp->errno == -ESTALE && !(lookup_flags & LOOKUP_REVAL)) { lookup_flags |= LOOKUP_REVAL; @@ -922,7 +922,7 @@ int handle_xattrset(struct qtserver_arg *arg) goto err_handle; } - rsp->errno = vfs_setxattr(path.dentry, &req->buf[req->d.pathlen], &req->buf[req->d.pathlen + req->d.namelen], req->d.size, req->d.flags); + rsp->errno = vfs_setxattr(&init_user_ns, path.dentry, &req->buf[req->d.pathlen], &req->buf[req->d.pathlen + req->d.namelen], req->d.size, req->d.flags); qtfs_info("handle xattrset path:%s name:%s value:%s ret:%d size:%lu flags:%d", req->buf, &req->buf[req->d.pathlen], &req->buf[req->d.pathlen + req->d.namelen], rsp->errno, req->d.size, req->d.flags); @@ -963,7 +963,7 @@ int handle_xattrget(struct qtserver_arg *arg) } } - error = vfs_getxattr(path.dentry, req->d.prefix_name, kvalue, req->d.size); + error = vfs_getxattr(&init_user_ns, path.dentry, req->d.prefix_name, kvalue, req->d.size); path_put(&path); if (error > 0) { if (req->d.pos >= error) { -- 2.33.0