Skip to contentSkip to conversation

smb: client: set symlink type as native for POSIX mounts

PATCH In review Paulo Alcantara 2 participants 4 messages Jul 31, 2025 – Aug 1, 2025

Subsystems (2)
lore
Share & tools
lore

Paulo Alcantara

author maintainer
#0 lore raw

PATCH 1/3 smb: client: set symlink type as native for POSIX mounts

SMB3.1.1 POSIX mounts require symlinks to be created natively with IO_REPARSE_TAG_SYMLINK reparse point.

---
 fs/smb/client/cifsfs.c     |  2 +-
 fs/smb/client/fs_context.c | 18 ------------------
 fs/smb/client/fs_context.h | 18 +++++++++++++++++-
 fs/smb/client/link.c       | 11 +++--------
 fs/smb/client/reparse.c    |  2 +-
 5 files changed, 22 insertions(+), 29 deletions(-)
fs/smb/client/cifsfs.c +1 -1
index 0a5266ecfd15..697badd0445a 100644
@@ -723,7 +723,7 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
 	else
 		seq_puts(s, ",nativesocket");
 	seq_show_option(s, "symlink",
-			cifs_symlink_type_str(get_cifs_symlink_type(cifs_sb)));
+			cifs_symlink_type_str(cifs_symlink_type(cifs_sb)));
 
 	seq_printf(s, ",rsize=%u", cifs_sb->ctx->rsize);
 	seq_printf(s, ",wsize=%u", cifs_sb->ctx->wsize);
fs/smb/client/fs_context.c +0 -18
index 3f34bb07997b..cc8bd79ebca9 100644
@@ -1829,24 +1829,6 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
 	return -EINVAL;
 }
 
-enum cifs_symlink_type get_cifs_symlink_type(struct cifs_sb_info *cifs_sb)
-{
-	if (cifs_sb->ctx->symlink_type == CIFS_SYMLINK_TYPE_DEFAULT) {
-		if (cifs_sb->ctx->mfsymlinks)
-			return CIFS_SYMLINK_TYPE_MFSYMLINKS;
-		else if (cifs_sb->ctx->sfu_emul)
-			return CIFS_SYMLINK_TYPE_SFU;
-		else if (cifs_sb->ctx->linux_ext && !cifs_sb->ctx->no_linux_ext)
-			return CIFS_SYMLINK_TYPE_UNIX;
-		else if (cifs_sb->ctx->reparse_type != CIFS_REPARSE_TYPE_NONE)
-			return CIFS_SYMLINK_TYPE_NATIVE;
-		else
-			return CIFS_SYMLINK_TYPE_NONE;
-	} else {
-		return cifs_sb->ctx->symlink_type;
-	}
-}
-
 int smb3_init_fs_context(struct fs_context *fc)
 {
 	struct smb3_fs_context *ctx;
fs/smb/client/fs_context.h +17 -1
index 9e83302ce4b8..b0fec6b9a23b 100644
@@ -341,7 +341,23 @@ struct smb3_fs_context {
 
 extern const struct fs_parameter_spec smb3_fs_parameters[];
 
-extern enum cifs_symlink_type get_cifs_symlink_type(struct cifs_sb_info *cifs_sb);
+static inline enum cifs_symlink_type cifs_symlink_type(struct cifs_sb_info *cifs_sb)
+{
+	bool posix = cifs_sb_master_tcon(cifs_sb)->posix_extensions;
+
+	if (cifs_sb->ctx->symlink_type != CIFS_SYMLINK_TYPE_DEFAULT)
+		return cifs_sb->ctx->symlink_type;
+
+	if (cifs_sb->ctx->mfsymlinks)
+		return CIFS_SYMLINK_TYPE_MFSYMLINKS;
+	else if (cifs_sb->ctx->sfu_emul)
+		return CIFS_SYMLINK_TYPE_SFU;
+	else if (cifs_sb->ctx->linux_ext && !cifs_sb->ctx->no_linux_ext)
+		return posix ? CIFS_SYMLINK_TYPE_NATIVE : CIFS_SYMLINK_TYPE_UNIX;
+	else if (cifs_sb->ctx->reparse_type != CIFS_REPARSE_TYPE_NONE)
+		return CIFS_SYMLINK_TYPE_NATIVE;
+	return CIFS_SYMLINK_TYPE_NONE;
+}
 
 extern int smb3_init_fs_context(struct fs_context *fc);
 extern void smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx);
fs/smb/client/link.c +3 -8
index 2ecd705e9e8c..afe76367d2c8 100644
@@ -605,14 +605,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,
 
 	/* BB what if DFS and this volume is on different share? BB */
 	rc = -EOPNOTSUPP;
-	switch (get_cifs_symlink_type(cifs_sb)) {
-	case CIFS_SYMLINK_TYPE_DEFAULT:
-		/* should not happen, get_cifs_symlink_type() resolves the default */
-		break;
-
-	case CIFS_SYMLINK_TYPE_NONE:
-		break;
-
+	switch (cifs_symlink_type(cifs_sb)) {
 	case CIFS_SYMLINK_TYPE_UNIX:
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
 		if (pTcon->unix_ext) {
@@ -648,6 +641,8 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,
 			goto symlink_exit;
 		}
 		break;
+	default:
+		break;
 	}
 
 	if (rc == 0) {
fs/smb/client/reparse.c +1 -1
index 33c1d970747c..7869cec58f52 100644
@@ -38,7 +38,7 @@ int create_reparse_symlink(const unsigned int xid, struct inode *inode,
 				struct dentry *dentry, struct cifs_tcon *tcon,
 				const char *full_path, const char *symname)
 {
-	switch (get_cifs_symlink_type(CIFS_SB(inode->i_sb))) {
+	switch (cifs_symlink_type(CIFS_SB(inode->i_sb))) {
 	case CIFS_SYMLINK_TYPE_NATIVE:
 		return create_native_symlink(xid, inode, dentry, tcon, full_path, symname);
 	case CIFS_SYMLINK_TYPE_NFS:
Signature · 1 line
2.50.1
author maintainer
#1 lore raw

PATCH 2/3 smb: client: default to nonativesocket under POSIX mounts

SMB3.1.1 POSIX mounts require sockets to be created with NFS reparse points.

---
 fs/smb/client/fs_context.c | 1 +
 1 file changed, 1 insertion(+)
fs/smb/client/fs_context.c +1 -0
index cc8bd79ebca9..312f5a0592ae 100644
@@ -1652,6 +1652,7 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
 				pr_warn_once("conflicting posix mount options specified\n");
 			ctx->linux_ext = 1;
 			ctx->no_linux_ext = 0;
+			ctx->nonativesocket = 1;
 		}
 		break;
 	case Opt_nocase:
Signature · 1 line
2.50.1
author maintainer
#2 lore raw

PATCH 3/3 smb: client: fix creating symlinks under POSIX mounts

In reply to Paulo Alcantara

SMB3.1.1 POSIX mounts support native symlinks that are created with IO_REPARSE_TAG_SYMLINK reparse points, so skip the checking of FILE_SUPPORTS_REPARSE_POINTS as some servers might not have it set.

---
 fs/smb/client/cifsglob.h  | 5 +++++
 fs/smb/client/cifssmb.c   | 4 ++--
 fs/smb/client/link.c      | 2 +-
 fs/smb/client/smb1ops.c   | 2 +-
 fs/smb/client/smb2inode.c | 5 ++---
 fs/smb/client/smb2ops.c   | 5 ++---
 6 files changed, 13 insertions(+), 10 deletions(-)
fs/smb/client/cifsglob.h +5 -0
index 19dd901fe8ab..a97e2cca2f53 100644
@@ -2377,4 +2377,9 @@ static inline bool cifs_netbios_name(const char *name, size_t namelen)
 	return ret;
 }
 
+#define CIFS_REPARSE_SUPPORT(tcon) \
+	((tcon)->posix_extensions || \
+	 (le32_to_cpu((tcon)->fsAttrInfo.Attributes) & \
+	  FILE_SUPPORTS_REPARSE_POINTS))
+
 #endif	/* _CIFS_GLOB_H */
fs/smb/client/cifssmb.c +2 -2
index 6c890db06593..d20766f664c4 100644
@@ -2751,7 +2751,7 @@ int cifs_query_reparse_point(const unsigned int xid,
 	if (cap_unix(tcon->ses))
 		return -EOPNOTSUPP;
 
-	if (!(le32_to_cpu(tcon->fsAttrInfo.Attributes) & FILE_SUPPORTS_REPARSE_POINTS))
+	if (!CIFS_REPARSE_SUPPORT(tcon))
 		return -EOPNOTSUPP;
 
 	oparms = (struct cifs_open_parms) {
@@ -2879,7 +2879,7 @@ struct inode *cifs_create_reparse_inode(struct cifs_open_info_data *data,
 	 * attempt to create reparse point. This will prevent creating unusable
 	 * empty object on the server.
 	 */
-	if (!(le32_to_cpu(tcon->fsAttrInfo.Attributes) & FILE_SUPPORTS_REPARSE_POINTS))
+	if (!CIFS_REPARSE_SUPPORT(tcon))
 		return ERR_PTR(-EOPNOTSUPP);
 
 #ifndef CONFIG_CIFS_XATTR
fs/smb/client/link.c +1 -1
index afe76367d2c8..fe80e711cd75 100644
@@ -635,7 +635,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,
 	case CIFS_SYMLINK_TYPE_NATIVE:
 	case CIFS_SYMLINK_TYPE_NFS:
 	case CIFS_SYMLINK_TYPE_WSL:
-		if (le32_to_cpu(pTcon->fsAttrInfo.Attributes) & FILE_SUPPORTS_REPARSE_POINTS) {
+		if (CIFS_REPARSE_SUPPORT(pTcon)) {
 			rc = create_reparse_symlink(xid, inode, direntry, pTcon,
 						    full_path, symname);
 			goto symlink_exit;
fs/smb/client/smb1ops.c +1 -1
index e364b6515af3..f722c7f47b07 100644
@@ -1272,7 +1272,7 @@ cifs_make_node(unsigned int xid, struct inode *inode,
 		 */
 		return cifs_sfu_make_node(xid, inode, dentry, tcon,
 					  full_path, mode, dev);
-	} else if (le32_to_cpu(tcon->fsAttrInfo.Attributes) & FILE_SUPPORTS_REPARSE_POINTS) {
+	} else if (CIFS_REPARSE_SUPPORT(tcon)) {
 		/*
 		 * mknod via reparse points requires server support for
 		 * storing reparse points, which is available since
fs/smb/client/smb2inode.c +2 -3
index 69d251726c02..2a0316c514e4 100644
@@ -1346,9 +1346,8 @@ struct inode *smb2_create_reparse_inode(struct cifs_open_info_data *data,
 	 * attempt to create reparse point. This will prevent creating unusable
 	 * empty object on the server.
 	 */
-	if (!(le32_to_cpu(tcon->fsAttrInfo.Attributes) & FILE_SUPPORTS_REPARSE_POINTS))
-		if (!tcon->posix_extensions)
-			return ERR_PTR(-EOPNOTSUPP);
+	if (!CIFS_REPARSE_SUPPORT(tcon))
+		return ERR_PTR(-EOPNOTSUPP);
 
 	oparms = CIFS_OPARMS(cifs_sb, tcon, full_path,
 			     SYNCHRONIZE | DELETE |
fs/smb/client/smb2ops.c +2 -3
index 1b4a31894f43..bd6c1fb2a992 100644
@@ -5260,10 +5260,9 @@ static int smb2_make_node(unsigned int xid, struct inode *inode,
 	if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
 		rc = cifs_sfu_make_node(xid, inode, dentry, tcon,
 					full_path, mode, dev);
-	} else if ((le32_to_cpu(tcon->fsAttrInfo.Attributes) & FILE_SUPPORTS_REPARSE_POINTS)
-		|| (tcon->posix_extensions)) {
+	} else if (CIFS_REPARSE_SUPPORT(tcon)) {
 		rc = mknod_reparse(xid, inode, dentry, tcon,
-					full_path, mode, dev);
+				   full_path, mode, dev);
 	}
 	return rc;
 }
Signature · 1 line
2.50.1
#3 lore raw
In reply to Paulo Alcantara

These three look promising, will run some tests on these now. Any
objections to adding cc:stable for these three?

Quoted 134 lines · Paulo Alcantara

SMB3.1.1 POSIX mounts require symlinks to be created natively with IO_REPARSE_TAG_SYMLINK reparse point.

---
 fs/smb/client/cifsfs.c     |  2 +-
 fs/smb/client/fs_context.c | 18 ------------------
 fs/smb/client/fs_context.h | 18 +++++++++++++++++-
 fs/smb/client/link.c       | 11 +++--------
 fs/smb/client/reparse.c    |  2 +-
 5 files changed, 22 insertions(+), 29 deletions(-)
fs/smb/client/cifsfs.c +1 -1
index 0a5266ecfd15..697badd0445a 100644
@@ -723,7 +723,7 @@ cifs_show_options(struct seq_file *s, struct dentry *root)
        else
                seq_puts(s, ",nativesocket");
        seq_show_option(s, "symlink",
-                       cifs_symlink_type_str(get_cifs_symlink_type(cifs_sb)));
+                       cifs_symlink_type_str(cifs_symlink_type(cifs_sb)));
 
        seq_printf(s, ",rsize=%u", cifs_sb->ctx->rsize);
        seq_printf(s, ",wsize=%u", cifs_sb->ctx->wsize);
fs/smb/client/fs_context.c +0 -18
index 3f34bb07997b..cc8bd79ebca9 100644
@@ -1829,24 +1829,6 @@ static int smb3_fs_context_parse_param(struct fs_context *fc,
        return -EINVAL;
 }
 
-enum cifs_symlink_type get_cifs_symlink_type(struct cifs_sb_info *cifs_sb)
-{
-       if (cifs_sb->ctx->symlink_type == CIFS_SYMLINK_TYPE_DEFAULT) {
-               if (cifs_sb->ctx->mfsymlinks)
-                       return CIFS_SYMLINK_TYPE_MFSYMLINKS;
-               else if (cifs_sb->ctx->sfu_emul)
-                       return CIFS_SYMLINK_TYPE_SFU;
-               else if (cifs_sb->ctx->linux_ext && !cifs_sb->ctx->no_linux_ext)
-                       return CIFS_SYMLINK_TYPE_UNIX;
-               else if (cifs_sb->ctx->reparse_type != CIFS_REPARSE_TYPE_NONE)
-                       return CIFS_SYMLINK_TYPE_NATIVE;
-               else
-                       return CIFS_SYMLINK_TYPE_NONE;
-       } else {
-               return cifs_sb->ctx->symlink_type;
-       }
-}
-
 int smb3_init_fs_context(struct fs_context *fc)
 {
        struct smb3_fs_context *ctx;
fs/smb/client/fs_context.h +17 -1
index 9e83302ce4b8..b0fec6b9a23b 100644
@@ -341,7 +341,23 @@ struct smb3_fs_context {
 
 extern const struct fs_parameter_spec smb3_fs_parameters[];
 
-extern enum cifs_symlink_type get_cifs_symlink_type(struct cifs_sb_info *cifs_sb);
+static inline enum cifs_symlink_type cifs_symlink_type(struct cifs_sb_info *cifs_sb)
+{
+       bool posix = cifs_sb_master_tcon(cifs_sb)->posix_extensions;
+
+       if (cifs_sb->ctx->symlink_type != CIFS_SYMLINK_TYPE_DEFAULT)
+               return cifs_sb->ctx->symlink_type;
+
+       if (cifs_sb->ctx->mfsymlinks)
+               return CIFS_SYMLINK_TYPE_MFSYMLINKS;
+       else if (cifs_sb->ctx->sfu_emul)
+               return CIFS_SYMLINK_TYPE_SFU;
+       else if (cifs_sb->ctx->linux_ext && !cifs_sb->ctx->no_linux_ext)
+               return posix ? CIFS_SYMLINK_TYPE_NATIVE : CIFS_SYMLINK_TYPE_UNIX;
+       else if (cifs_sb->ctx->reparse_type != CIFS_REPARSE_TYPE_NONE)
+               return CIFS_SYMLINK_TYPE_NATIVE;
+       return CIFS_SYMLINK_TYPE_NONE;
+}
 
 extern int smb3_init_fs_context(struct fs_context *fc);
 extern void smb3_cleanup_fs_context_contents(struct smb3_fs_context *ctx);
fs/smb/client/link.c +3 -8
index 2ecd705e9e8c..afe76367d2c8 100644
@@ -605,14 +605,7 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,
 
        /* BB what if DFS and this volume is on different share? BB */
        rc = -EOPNOTSUPP;
-       switch (get_cifs_symlink_type(cifs_sb)) {
-       case CIFS_SYMLINK_TYPE_DEFAULT:
-               /* should not happen, get_cifs_symlink_type() resolves the default */
-               break;
-
-       case CIFS_SYMLINK_TYPE_NONE:
-               break;
-
+       switch (cifs_symlink_type(cifs_sb)) {
        case CIFS_SYMLINK_TYPE_UNIX:
 #ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY
                if (pTcon->unix_ext) {
@@ -648,6 +641,8 @@ cifs_symlink(struct mnt_idmap *idmap, struct inode *inode,
                        goto symlink_exit;
                }
                break;
+       default:
+               break;
        }
 
        if (rc == 0) {
fs/smb/client/reparse.c +1 -2
index 33c1d970747c..7869cec58f52 100644
@@ -38,7 +38,7 @@ int create_reparse_symlink(const unsigned int xid, struct inode *inode,
                                struct dentry *dentry, struct cifs_tcon *tcon,
                                const char *full_path, const char *symname)
 {
-       switch (get_cifs_symlink_type(CIFS_SB(inode->i_sb))) {
+       switch (cifs_symlink_type(CIFS_SB(inode->i_sb))) {
        case CIFS_SYMLINK_TYPE_NATIVE:
                return create_native_symlink(xid, inode, dentry, tcon, full_path, symname);
        case CIFS_SYMLINK_TYPE_NFS:
--

2.50.1

Signature · 3 lines
Thanks,

Steve