dpu-utilities/0015-Adapt-for-kernel-6.4.patch
Weifeng Su 9cafb1714f Adapt for kernel 6.4
Signed-off-by: Weifeng Su <suweifeng1@huawei.com>
2023-08-21 12:03:09 +00:00

309 lines
14 KiB
Diff

From 8e66cbde95f58c3a2a18351b81cae29bc69f760d Mon Sep 17 00:00:00 2001
From: Weifeng Su <suweifeng1@huawei.com>
Date: Tue, 15 Aug 2023 07:06:03 +0000
Subject: [PATCH] Adapt for kernel 6.4
The file system inode ops need struct mnt_idmap parameter in kernel 6.4
Signed-off-by: Weifeng Su <suweifeng1@huawei.com>
---
qtfs/qtfs/ops.h | 4 +++-
qtfs/qtfs/proc.c | 8 ++++++--
qtfs/qtfs/sb.c | 35 +++++++++++++++++++++++++++--------
qtfs/qtfs/xattr.c | 32 ++++++++++++++++++++++++++++----
qtfs/qtfs_common/conn.c | 5 ++++-
qtfs/qtfs_server/fsops.c | 25 +++++++++++++++++++------
6 files changed, 87 insertions(+), 22 deletions(-)
diff --git a/qtfs/qtfs/ops.h b/qtfs/qtfs/ops.h
index 560be74..bdb2628 100644
--- a/qtfs/qtfs/ops.h
+++ b/qtfs/qtfs/ops.h
@@ -29,7 +29,9 @@ 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);
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_getattr(struct mnt_idmap *idmap, const struct path *, struct kstat *, u32, unsigned int);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_getattr(struct user_namespace *mnt_userns, const struct path *, struct kstat *, u32, unsigned int);
#else
int qtfs_getattr(const struct path *, struct kstat *, u32, unsigned int);
diff --git a/qtfs/qtfs/proc.c b/qtfs/qtfs/proc.c
index e56bd8c..70238ea 100644
--- a/qtfs/qtfs/proc.c
+++ b/qtfs/qtfs/proc.c
@@ -26,7 +26,9 @@
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);
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_proc_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_proc_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags);
#else
int qtfs_proc_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags);
@@ -240,7 +242,9 @@ link_local:
return link;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_proc_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_proc_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags)
#else
int qtfs_proc_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags)
diff --git a/qtfs/qtfs/sb.c b/qtfs/qtfs/sb.c
index fa3b5ac..faafa76 100644
--- a/qtfs/qtfs/sb.c
+++ b/qtfs/qtfs/sb.c
@@ -907,7 +907,9 @@ int qtfs_new_entry(struct inode *inode, struct dentry *dentry)
return 0;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_mkdir(struct mnt_idmap *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode)
#else
int qtfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
@@ -946,7 +948,9 @@ int qtfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
return ret;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_create(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_create(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, bool excl)
#else
int qtfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool excl)
@@ -990,7 +994,9 @@ int qtfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool exc
return ret ? ret : ret2;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_mknod(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
#else
int qtfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
@@ -1258,7 +1264,9 @@ err_end:
return error;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_symlink(struct mnt_idmap *idmap, struct inode *dir, struct dentry *dentry, const char *symname)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_symlink(struct user_namespace *mnt_userns, struct inode *dir, struct dentry *dentry, const char *symname)
#else
int qtfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
@@ -1307,7 +1315,9 @@ err_end:
return error;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_getattr(struct mnt_idmap *idmap, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_getattr(struct user_namespace *mnt_userns, const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags)
#else
int qtfs_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsigned int flags)
@@ -1360,7 +1370,9 @@ int qtfs_getattr(const struct path *path, struct kstat *stat, u32 req_mask, unsi
return 0;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, struct iattr *attr)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
int qtfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, struct iattr *attr)
#else
int qtfs_setattr(struct dentry *dentry, struct iattr *attr)
@@ -1463,7 +1475,12 @@ const char *qtfs_getlink(struct dentry *dentry,
qtfs_conn_put_param(pvar);
return link;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+int qtfs_rename(struct mnt_idmap *idmap, struct inode *old_dir,
+ struct dentry *old_dentry, struct inode *new_dir,
+ struct dentry *new_dentry, unsigned int flags)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
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)
@@ -1604,7 +1621,9 @@ static int qtfs_fill_super(struct super_block *sb, void *priv_data, int silent)
root_inode = new_inode(sb);
root_inode->i_ino = 1;
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+ inode_init_owner(&nop_mnt_idmap, root_inode, NULL, mode);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
inode_init_owner(&init_user_ns, root_inode, NULL, mode);
#else
inode_init_owner(root_inode, NULL, mode);
diff --git a/qtfs/qtfs/xattr.c b/qtfs/qtfs/xattr.c
index 3ba7704..4d15daf 100644
--- a/qtfs/qtfs/xattr.c
+++ b/qtfs/qtfs/xattr.c
@@ -73,7 +73,13 @@ static int qtfs_xattr_set(const struct xattr_handler *handler,
size_t size, int flags);
static int
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+qtfs_xattr_user_set(const struct xattr_handler *handler,
+ struct mnt_idmap *idmap,
+ struct dentry *unused, struct inode *inode,
+ const char *name, const void *value,
+ size_t size, int flags)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
qtfs_xattr_user_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct dentry *unused, struct inode *inode,
@@ -91,7 +97,13 @@ qtfs_xattr_user_set(const struct xattr_handler *handler,
}
static int
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+qtfs_xattr_trusted_set(const struct xattr_handler *handler,
+ struct mnt_idmap *idmap,
+ struct dentry *unused, struct inode *inode,
+ const char *name, const void *value,
+ size_t size, int flags)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
qtfs_xattr_trusted_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct dentry *unused, struct inode *inode,
@@ -108,7 +120,13 @@ qtfs_xattr_trusted_set(const struct xattr_handler *handler,
}
static int
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+qtfs_xattr_security_set(const struct xattr_handler *handler,
+ struct mnt_idmap *idmap,
+ struct dentry *unused, struct inode *inode,
+ const char *name, const void *value,
+ size_t size, int flags)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
qtfs_xattr_security_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct dentry *unused, struct inode *inode,
@@ -270,7 +288,13 @@ const struct xattr_handler qtfs_xattr_security_handler = {
#ifndef KVER_4_19
static int
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+qtfs_xattr_hurd_set(const struct xattr_handler *handler,
+ struct mnt_idmap *idmap,
+ struct dentry *unused, struct inode *inode,
+ const char *name, const void *value,
+ size_t size, int flags)
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
qtfs_xattr_hurd_set(const struct xattr_handler *handler,
struct user_namespace *mnt_userns,
struct dentry *unused, struct inode *inode,
diff --git a/qtfs/qtfs_common/conn.c b/qtfs/qtfs_common/conn.c
index 10b4cbe..cc59d52 100644
--- a/qtfs/qtfs_common/conn.c
+++ b/qtfs/qtfs_common/conn.c
@@ -167,8 +167,11 @@ int qtfs_uds_remote_connect_user(int fd, struct sockaddr __user *addr, int len)
if (f.file == NULL) {
return -EBADF;
}
-
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+ sock =sock_from_file(f.file);
+#else
sock = sock_from_file(f.file, &err);
+#endif
if (!sock) {
goto end;
}
diff --git a/qtfs/qtfs_server/fsops.c b/qtfs/qtfs_server/fsops.c
index 5485d04..5f3f779 100644
--- a/qtfs/qtfs_server/fsops.c
+++ b/qtfs/qtfs_server/fsops.c
@@ -30,7 +30,10 @@
#include <linux/blkdev.h>
#include <linux/version.h>
#include <linux/if_tun.h>
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+#include <linux/pipe_fs_i.h>
+#include <linux/fdtable.h>
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0))
#include <linux/fdtable.h>
#endif
@@ -860,7 +863,9 @@ static int handle_setattr(struct qtserver_arg *arg)
}
inode_lock(inode);
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+ rsp->errno = notify_change(&nop_mnt_idmap, path.dentry, &req->attr, NULL);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
rsp->errno = notify_change(&init_user_ns, path.dentry, &req->attr, NULL);
#else
rsp->errno = notify_change(path.dentry, &req->attr, NULL);
@@ -938,7 +943,9 @@ retry:
req->mode &= ~current_umask();
error = security_path_mknod(&path, dent, req->mode, req->dev);
if (!error)
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+ error = vfs_mknod(&nop_mnt_idmap, path.dentry->d_inode, dent, req->mode, req->dev);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
error = vfs_mknod(&init_user_ns, path.dentry->d_inode, dent, req->mode, req->dev);
#else
error = vfs_mknod(path.dentry->d_inode, dent, req->mode, req->dev);
@@ -1046,7 +1053,9 @@ retry:
qtfs_err("handle_symlink: newname(%s), oldname(%s) in kern_path_create %d\n", newname, oldname, error);
return sizeof(struct qtrsp_symlink);
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+ rsp->errno = vfs_symlink(&nop_mnt_idmap, path.dentry->d_inode, dentry, oldname);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
rsp->errno = vfs_symlink(&init_user_ns, path.dentry->d_inode, dentry, oldname);
#else
rsp->errno = vfs_symlink(path.dentry->d_inode, dentry, oldname);
@@ -1188,7 +1197,9 @@ int handle_xattrset(struct qtserver_arg *arg)
path_put(&path);
goto err_handle;
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+ rsp->errno = vfs_setxattr(&nop_mnt_idmap, path.dentry, &req->buf[req->d.pathlen], &req->buf[req->d.pathlen + req->d.namelen], req->d.size, req->d.flags);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
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);
#else
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);
@@ -1238,7 +1249,9 @@ int handle_xattrget(struct qtserver_arg *arg)
goto err_handle;
}
}
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
+ error = vfs_getxattr(&nop_mnt_idmap, path.dentry, req->d.prefix_name, kvalue, req->d.size);
+#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0))
error = vfs_getxattr(&init_user_ns, path.dentry, req->d.prefix_name, kvalue, req->d.size);
#else
error = vfs_getxattr(path.dentry, req->d.prefix_name, kvalue, req->d.size);
--
2.33.0