Skip to content

Commit 837e3a1

Browse files
Ronnie SahlbergSteve French
authored andcommitted
cifs: rename dup_vol to smb3_fs_context_dup and move it into fs_context.c
Continue restructuring needed for support of new mount API Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 3fa1c6d commit 837e3a1

File tree

3 files changed

+44
-60
lines changed

3 files changed

+44
-60
lines changed

fs/cifs/dfs_cache.c

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,64 +1141,6 @@ int dfs_cache_get_tgt_referral(const char *path,
11411141
return rc;
11421142
}
11431143

1144-
static int dup_vol(struct smb3_fs_context *ctx, struct smb3_fs_context *new)
1145-
{
1146-
memcpy(new, ctx, sizeof(*new));
1147-
1148-
if (ctx->username) {
1149-
new->username = kstrndup(ctx->username, strlen(ctx->username),
1150-
GFP_KERNEL);
1151-
if (!new->username)
1152-
return -ENOMEM;
1153-
}
1154-
if (ctx->password) {
1155-
new->password = kstrndup(ctx->password, strlen(ctx->password),
1156-
GFP_KERNEL);
1157-
if (!new->password)
1158-
goto err_free_username;
1159-
}
1160-
if (ctx->UNC) {
1161-
cifs_dbg(FYI, "%s: ctx->UNC: %s\n", __func__, ctx->UNC);
1162-
new->UNC = kstrndup(ctx->UNC, strlen(ctx->UNC), GFP_KERNEL);
1163-
if (!new->UNC)
1164-
goto err_free_password;
1165-
}
1166-
if (ctx->domainname) {
1167-
new->domainname = kstrndup(ctx->domainname,
1168-
strlen(ctx->domainname), GFP_KERNEL);
1169-
if (!new->domainname)
1170-
goto err_free_unc;
1171-
}
1172-
if (ctx->iocharset) {
1173-
new->iocharset = kstrndup(ctx->iocharset,
1174-
strlen(ctx->iocharset), GFP_KERNEL);
1175-
if (!new->iocharset)
1176-
goto err_free_domainname;
1177-
}
1178-
if (ctx->prepath) {
1179-
cifs_dbg(FYI, "%s: ctx->prepath: %s\n", __func__, ctx->prepath);
1180-
new->prepath = kstrndup(ctx->prepath, strlen(ctx->prepath),
1181-
GFP_KERNEL);
1182-
if (!new->prepath)
1183-
goto err_free_iocharset;
1184-
}
1185-
1186-
return 0;
1187-
1188-
err_free_iocharset:
1189-
kfree(new->iocharset);
1190-
err_free_domainname:
1191-
kfree(new->domainname);
1192-
err_free_unc:
1193-
kfree(new->UNC);
1194-
err_free_password:
1195-
kfree_sensitive(new->password);
1196-
err_free_username:
1197-
kfree(new->username);
1198-
kfree(new);
1199-
return -ENOMEM;
1200-
}
1201-
12021144
/**
12031145
* dfs_cache_add_vol - add a cifs volume during mount() that will be handled by
12041146
* DFS cache refresh worker.
@@ -1229,7 +1171,7 @@ int dfs_cache_add_vol(char *mntdata, struct smb3_fs_context *ctx, const char *fu
12291171
goto err_free_vi;
12301172
}
12311173

1232-
rc = dup_vol(ctx, &vi->ctx);
1174+
rc = smb3_fs_context_dup(&vi->ctx, ctx);
12331175
if (rc)
12341176
goto err_free_fullpath;
12351177

fs/cifs/fs_context.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include "cifsglob.h"
10+
#include "cifsproto.h"
1011
#include "cifs_debug.h"
1112
#include "fs_context.h"
1213

@@ -219,3 +220,43 @@ cifs_parse_cache_flavor(char *value, struct smb3_fs_context *ctx)
219220
}
220221
return 0;
221222
}
223+
224+
#define DUP_CTX_STR(field) \
225+
do { \
226+
if (ctx->field) { \
227+
new_ctx->field = kstrdup(ctx->field, GFP_ATOMIC); \
228+
if (new_ctx->field == NULL) { \
229+
cifs_cleanup_volume_info_contents(new_ctx); \
230+
return -ENOMEM; \
231+
} \
232+
} \
233+
} while (0)
234+
235+
int
236+
smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx)
237+
{
238+
int rc = 0;
239+
240+
memcpy(new_ctx, ctx, sizeof(*ctx));
241+
new_ctx->prepath = NULL;
242+
new_ctx->local_nls = NULL;
243+
new_ctx->nodename = NULL;
244+
new_ctx->username = NULL;
245+
new_ctx->password = NULL;
246+
new_ctx->domainname = NULL;
247+
new_ctx->UNC = NULL;
248+
new_ctx->iocharset = NULL;
249+
250+
/*
251+
* Make sure to stay in sync with cifs_cleanup_volume_info_contents()
252+
*/
253+
DUP_CTX_STR(prepath);
254+
DUP_CTX_STR(username);
255+
DUP_CTX_STR(password);
256+
DUP_CTX_STR(UNC);
257+
DUP_CTX_STR(domainname);
258+
DUP_CTX_STR(nodename);
259+
DUP_CTX_STR(iocharset);
260+
261+
return rc;
262+
}

fs/cifs/fs_context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ struct smb3_fs_context {
152152
bool rootfs:1; /* if it's a SMB root file system */
153153
};
154154

155-
int cifs_parse_security_flavors(char *value, struct smb3_fs_context *ctx);
155+
extern int cifs_parse_security_flavors(char *value, struct smb3_fs_context *ctx);
156+
extern int smb3_fs_context_dup(struct smb3_fs_context *new_ctx, struct smb3_fs_context *ctx);
156157

157158
#endif

0 commit comments

Comments
 (0)