cifs: fix charset issue in reconnection
Subsystems (3)
cover cifs: fix charset issue in reconnection
The patch 1 make load_nls() take a const char * as parameter so we can reuse a nls's name without cast:
ses->local_nls = load_nls(ctx->local_nls->charset);
The patch 2 do the charset fix in cifs.
--
Winston Wen (2):
fs/nls: make load_nls() take a const parameter
cifs: fix charset issue in reconnection
fs/nls/nls_base.c | 4 ++-- fs/smb/client/cifsglob.h | 1 + fs/smb/client/cifssmb.c | 3 +-- fs/smb/client/connect.c | 5 +++++ fs/smb/client/misc.c | 1 + fs/smb/client/smb2pdu.c | 3 +-- include/linux/nls.h | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-)
PATCH 1/2 fs/nls: make load_nls() take a const parameter
load_nls() take a char * parameter, use it to find nls module in list or construct the module name to load it.
This change make load_nls() take a const parameter, so we don't need do some cast like this:
ses->local_nls = load_nls((char *)ctx->local_nls->charset);
--- fs/nls/nls_base.c | 4 ++-- include/linux/nls.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/nls/nls_base.c +2 -2
@@ -272,7 +272,7 @@ int unregister_nls(struct nls_table * nls)return -EINVAL ; } -static struct nls_table *find_nls (char *charset) +static struct nls_table *find_nls (const char *charset) {struct nls_table *nls;spin_lock (&nls_lock);
@@ -288,7 +288,7 @@ static struct nls_table *find_nls(char *charset)return nls; } -struct nls_table *load_nls (char *charset) +struct nls_table *load_nls (const char *charset) {return try_then_request_module (find_nls (charset),"nls_%s" , charset); }
include/linux/nls.h +1 -1
@@ -47,7 +47,7 @@ enum utf16_endian {/* nls_base.c */ extern int __register_nls (struct nls_table *,struct module *);extern int unregister_nls (struct nls_table *); -extern struct nls_table *load_nls (char *); +extern struct nls_table *load_nls (const char *charset);extern void unload_nls (struct nls_table *);extern struct nls_table *load_nls_default (void );#define register_nls (nls) __register_nls((nls), THIS_MODULE)
Signature · 1 line
2.40.1
Re: [PATCH 1/2] fs/nls: make load_nls() take a const parameter
Quoted 6 lines · Winston Wen
load_nls()take a char * parameter, use it to find nls module in list or construct the module name to load it.This change make
load_nls()take a const parameter, so we don't need do some cast like this:
Quoted 6 lines
ses->local_nls = load_nls((char *)ctx->local_nls->charset);Suggested-by Stephen Rothwell <[email protected]>Signed-off-by Winston Wen <[email protected]>Reviewed-by Paulo Alcantara <[email protected]>---
Looks good to me,
PATCH 2/2 cifs: fix charset issue in reconnection
In reply to Winston WenWe need to specify charset, like "iocharset=utf-8", in mount options for Chinese path if the nls_default don't support it, such as iso8859-1, the default value for CONFIG_NLS_DEFAULT.
But now in reconnection the nls_default is used, instead of the one we specified and used in mount, and this can lead to mount failure.
--- fs/smb/client/cifsglob.h | 1 + fs/smb/client/cifssmb.c | 3 +-- fs/smb/client/connect.c | 5 +++++ fs/smb/client/misc.c | 1 + fs/smb/client/smb2pdu.c | 3 +-- 5 files changed, 9 insertions(+), 4 deletions(-)
fs/smb/client/cifsglob.h +1 -0
@@ -1062,6 +1062,7 @@ struct cifs_ses {unsigned long chans_need_reconnect;/* ========= end: protected by chan_lock ======== */ struct cifs_ses *dfs_root_ses; +struct nls_table *local_nls; }; static inline bool
fs/smb/client/cifssmb.c +1 -2
@@ -129,7 +129,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) }spin_unlock (&server->srv_lock); - nls_codepage =load_nls_default (); + nls_codepage = ses->local_nls;/* * need to prevent multiple threads trying to simultaneously
@@ -200,7 +200,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) rc = -EAGAIN ; } -unload_nls (nls_codepage);return rc; }
fs/smb/client/connect.c +5 -0
@@ -1842,6 +1842,10 @@ static int match_session(struct cifs_ses *ses, struct smb3_fs_context *ctx) CIFS_MAX_PASSWORD_LEN))return 0 ; } + +if (strcmp (ctx->local_nls->charset, ses->local_nls->charset)) +return 0 ; +return 1 ; }
@@ -2286,6 +2290,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb3_fs_context *ctx) ses->sectype = ctx->sectype; ses->sign = ctx->sign; + ses->local_nls =load_nls (ctx->local_nls->charset);/* add server as first channel */ spin_lock (&ses->chan_lock);
fs/smb/client/misc.c +1 -0
@@ -95,6 +95,7 @@ sesInfoFree(struct cifs_ses *buf_to_free)return ; } +unload_nls (buf_to_free->local_nls);atomic_dec (&sesInfoAllocCount);kfree (buf_to_free->serverOS);kfree (buf_to_free->serverDomain);
fs/smb/client/smb2pdu.c +1 -2
@@ -242,7 +242,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, }spin_unlock (&server->srv_lock); - nls_codepage =load_nls_default (); + nls_codepage = ses->local_nls;/* * need to prevent multiple threads trying to simultaneously
@@ -324,7 +324,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, rc = -EAGAIN ; } failed: -unload_nls (nls_codepage);return rc; }
Signature · 1 line
2.40.1