Skip to content

Commit e64d471

Browse files
robntonyhutter
authored andcommitted
Linux 6.15: mkdir now returns struct dentry *
The intent is that the filesystem may have a reference to an "old" version of the new directory, eg if it was keeping it alive because a remote NFS client still had it open. We don't need anything like that, so this really just changes things so we return error codes encoded in pointers. Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Pavel Snajdr <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #17229 (cherry picked from commit bb740d6)
1 parent a4de1d3 commit e64d471

File tree

3 files changed

+70
-20
lines changed

3 files changed

+70
-20
lines changed

config/kernel-mkdir.m4

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ dnl #
22
dnl # Supported mkdir() interfaces checked newest to oldest.
33
dnl #
44
AC_DEFUN([ZFS_AC_KERNEL_SRC_MKDIR], [
5+
dnl #
6+
dnl # 6.15 API change
7+
dnl # mkdir() returns struct dentry *
8+
dnl #
9+
ZFS_LINUX_TEST_SRC([mkdir_return_dentry], [
10+
#include <linux/fs.h>
11+
12+
static struct dentry *mkdir(struct mnt_idmap *idmap,
13+
struct inode *inode, struct dentry *dentry,
14+
umode_t umode) { return dentry; }
15+
static const struct inode_operations
16+
iops __attribute__ ((unused)) = {
17+
.mkdir = mkdir,
18+
};
19+
],[])
20+
521
dnl #
622
dnl # 6.3 API change
723
dnl # mkdir() takes struct mnt_idmap * as the first arg
@@ -59,29 +75,40 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_MKDIR], [
5975

6076
AC_DEFUN([ZFS_AC_KERNEL_MKDIR], [
6177
dnl #
62-
dnl # 6.3 API change
63-
dnl # mkdir() takes struct mnt_idmap * as the first arg
78+
dnl # 6.15 API change
79+
dnl # mkdir() returns struct dentry *
6480
dnl #
65-
AC_MSG_CHECKING([whether iops->mkdir() takes struct mnt_idmap*])
66-
ZFS_LINUX_TEST_RESULT([mkdir_mnt_idmap], [
81+
AC_MSG_CHECKING([whether iops->mkdir() returns struct dentry*])
82+
ZFS_LINUX_TEST_RESULT([mkdir_return_dentry], [
6783
AC_MSG_RESULT(yes)
68-
AC_DEFINE(HAVE_IOPS_MKDIR_IDMAP, 1,
69-
[iops->mkdir() takes struct mnt_idmap*])
84+
AC_DEFINE(HAVE_IOPS_MKDIR_DENTRY, 1,
85+
[iops->mkdir() returns struct dentry*])
7086
],[
71-
AC_MSG_RESULT(no)
72-
7387
dnl #
74-
dnl # 5.12 API change
75-
dnl # The struct user_namespace arg was added as the first argument to
76-
dnl # mkdir() of the iops structure.
88+
dnl # 6.3 API change
89+
dnl # mkdir() takes struct mnt_idmap * as the first arg
7790
dnl #
78-
AC_MSG_CHECKING([whether iops->mkdir() takes struct user_namespace*])
79-
ZFS_LINUX_TEST_RESULT([mkdir_user_namespace], [
91+
AC_MSG_CHECKING([whether iops->mkdir() takes struct mnt_idmap*])
92+
ZFS_LINUX_TEST_RESULT([mkdir_mnt_idmap], [
8093
AC_MSG_RESULT(yes)
81-
AC_DEFINE(HAVE_IOPS_MKDIR_USERNS, 1,
82-
[iops->mkdir() takes struct user_namespace*])
94+
AC_DEFINE(HAVE_IOPS_MKDIR_IDMAP, 1,
95+
[iops->mkdir() takes struct mnt_idmap*])
8396
],[
8497
AC_MSG_RESULT(no)
98+
99+
dnl #
100+
dnl # 5.12 API change
101+
dnl # The struct user_namespace arg was added as the first argument to
102+
dnl # mkdir() of the iops structure.
103+
dnl #
104+
AC_MSG_CHECKING([whether iops->mkdir() takes struct user_namespace*])
105+
ZFS_LINUX_TEST_RESULT([mkdir_user_namespace], [
106+
AC_MSG_RESULT(yes)
107+
AC_DEFINE(HAVE_IOPS_MKDIR_USERNS, 1,
108+
[iops->mkdir() takes struct user_namespace*])
109+
],[
110+
AC_MSG_RESULT(no)
111+
])
85112
])
86113
])
87114
])

module/os/linux/zfs/zpl_ctldir.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,20 @@ zpl_snapdir_rmdir(struct inode *dip, struct dentry *dentry)
341341
return (error);
342342
}
343343

344+
#if defined(HAVE_IOPS_MKDIR_USERNS)
344345
static int
345-
#ifdef HAVE_IOPS_MKDIR_USERNS
346346
zpl_snapdir_mkdir(struct user_namespace *user_ns, struct inode *dip,
347347
struct dentry *dentry, umode_t mode)
348348
#elif defined(HAVE_IOPS_MKDIR_IDMAP)
349+
static int
350+
zpl_snapdir_mkdir(struct mnt_idmap *user_ns, struct inode *dip,
351+
struct dentry *dentry, umode_t mode)
352+
#elif defined(HAVE_IOPS_MKDIR_DENTRY)
353+
static struct dentry *
349354
zpl_snapdir_mkdir(struct mnt_idmap *user_ns, struct inode *dip,
350355
struct dentry *dentry, umode_t mode)
351356
#else
357+
static int
352358
zpl_snapdir_mkdir(struct inode *dip, struct dentry *dentry, umode_t mode)
353359
#endif
354360
{
@@ -376,7 +382,11 @@ zpl_snapdir_mkdir(struct inode *dip, struct dentry *dentry, umode_t mode)
376382
ASSERT3S(error, <=, 0);
377383
crfree(cr);
378384

385+
#if defined(HAVE_IOPS_MKDIR_DENTRY)
386+
return (ERR_PTR(error));
387+
#else
379388
return (error);
389+
#endif
380390
}
381391

382392
/*

module/os/linux/zfs/zpl_inode.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,20 @@ zpl_unlink(struct inode *dir, struct dentry *dentry)
374374
return (error);
375375
}
376376

377+
#if defined(HAVE_IOPS_MKDIR_USERNS)
377378
static int
378-
#ifdef HAVE_IOPS_MKDIR_USERNS
379379
zpl_mkdir(struct user_namespace *user_ns, struct inode *dir,
380380
struct dentry *dentry, umode_t mode)
381381
#elif defined(HAVE_IOPS_MKDIR_IDMAP)
382+
static int
383+
zpl_mkdir(struct mnt_idmap *user_ns, struct inode *dir,
384+
struct dentry *dentry, umode_t mode)
385+
#elif defined(HAVE_IOPS_MKDIR_DENTRY)
386+
static struct dentry *
382387
zpl_mkdir(struct mnt_idmap *user_ns, struct inode *dir,
383388
struct dentry *dentry, umode_t mode)
384389
#else
390+
static int
385391
zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
386392
#endif
387393
{
@@ -390,12 +396,14 @@ zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
390396
znode_t *zp;
391397
int error;
392398
fstrans_cookie_t cookie;
393-
#if !(defined(HAVE_IOPS_MKDIR_USERNS) || defined(HAVE_IOPS_MKDIR_IDMAP))
399+
#if !(defined(HAVE_IOPS_MKDIR_USERNS) || \
400+
defined(HAVE_IOPS_MKDIR_IDMAP) || defined(HAVE_IOPS_MKDIR_DENTRY))
394401
zidmap_t *user_ns = kcred->user_ns;
395402
#endif
396403

397404
if (is_nametoolong(dentry)) {
398-
return (-ENAMETOOLONG);
405+
error = -ENAMETOOLONG;
406+
goto err;
399407
}
400408

401409
crhold(cr);
@@ -422,9 +430,14 @@ zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
422430
spl_fstrans_unmark(cookie);
423431
kmem_free(vap, sizeof (vattr_t));
424432
crfree(cr);
425-
ASSERT3S(error, <=, 0);
426433

434+
err:
435+
ASSERT3S(error, <=, 0);
436+
#if defined(HAVE_IOPS_MKDIR_DENTRY)
437+
return (error != 0 ? ERR_PTR(error) : NULL);
438+
#else
427439
return (error);
440+
#endif
428441
}
429442

430443
static int

0 commit comments

Comments
 (0)