Merge tag 'ktest-v5.11' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux-2.6-microblaze.git] / fs / cifs / dfs_cache.c
index 6ee8496..6ad6ba5 100644 (file)
@@ -18,6 +18,7 @@
 #include "cifs_debug.h"
 #include "cifs_unicode.h"
 #include "smb2glob.h"
+#include "fs_context.h"
 
 #include "dfs_cache.h"
 
@@ -48,8 +49,8 @@ struct cache_entry {
 
 struct vol_info {
        char *fullpath;
-       spinlock_t smb_vol_lock;
-       struct smb_vol smb_vol;
+       spinlock_t ctx_lock;
+       struct smb3_fs_context ctx;
        char *mntdata;
        struct list_head list;
        struct list_head rlist;
@@ -586,7 +587,7 @@ static void __vol_release(struct vol_info *vi)
 {
        kfree(vi->fullpath);
        kfree(vi->mntdata);
-       cifs_cleanup_volume_info_contents(&vi->smb_vol);
+       smb3_cleanup_fs_context_contents(&vi->ctx);
        kfree(vi);
 }
 
@@ -1140,80 +1141,22 @@ out_unlock:
        return rc;
 }
 
-static int dup_vol(struct smb_vol *vol, struct smb_vol *new)
-{
-       memcpy(new, vol, sizeof(*new));
-
-       if (vol->username) {
-               new->username = kstrndup(vol->username, strlen(vol->username),
-                                        GFP_KERNEL);
-               if (!new->username)
-                       return -ENOMEM;
-       }
-       if (vol->password) {
-               new->password = kstrndup(vol->password, strlen(vol->password),
-                                        GFP_KERNEL);
-               if (!new->password)
-                       goto err_free_username;
-       }
-       if (vol->UNC) {
-               cifs_dbg(FYI, "%s: vol->UNC: %s\n", __func__, vol->UNC);
-               new->UNC = kstrndup(vol->UNC, strlen(vol->UNC), GFP_KERNEL);
-               if (!new->UNC)
-                       goto err_free_password;
-       }
-       if (vol->domainname) {
-               new->domainname = kstrndup(vol->domainname,
-                                          strlen(vol->domainname), GFP_KERNEL);
-               if (!new->domainname)
-                       goto err_free_unc;
-       }
-       if (vol->iocharset) {
-               new->iocharset = kstrndup(vol->iocharset,
-                                         strlen(vol->iocharset), GFP_KERNEL);
-               if (!new->iocharset)
-                       goto err_free_domainname;
-       }
-       if (vol->prepath) {
-               cifs_dbg(FYI, "%s: vol->prepath: %s\n", __func__, vol->prepath);
-               new->prepath = kstrndup(vol->prepath, strlen(vol->prepath),
-                                       GFP_KERNEL);
-               if (!new->prepath)
-                       goto err_free_iocharset;
-       }
-
-       return 0;
-
-err_free_iocharset:
-       kfree(new->iocharset);
-err_free_domainname:
-       kfree(new->domainname);
-err_free_unc:
-       kfree(new->UNC);
-err_free_password:
-       kfree_sensitive(new->password);
-err_free_username:
-       kfree(new->username);
-       kfree(new);
-       return -ENOMEM;
-}
-
 /**
- * dfs_cache_add_vol - add a cifs volume during mount() that will be handled by
+ * dfs_cache_add_vol - add a cifs context during mount() that will be handled by
  * DFS cache refresh worker.
  *
  * @mntdata: mount data.
- * @vol: cifs volume.
+ * @ctx: cifs context.
  * @fullpath: origin full path.
  *
- * Return zero if volume was set up correctly, otherwise non-zero.
+ * Return zero if context was set up correctly, otherwise non-zero.
  */
-int dfs_cache_add_vol(char *mntdata, struct smb_vol *vol, const char *fullpath)
+int dfs_cache_add_vol(char *mntdata, struct smb3_fs_context *ctx, const char *fullpath)
 {
        int rc;
        struct vol_info *vi;
 
-       if (!vol || !fullpath || !mntdata)
+       if (!ctx || !fullpath || !mntdata)
                return -EINVAL;
 
        cifs_dbg(FYI, "%s: fullpath: %s\n", __func__, fullpath);
@@ -1228,12 +1171,12 @@ int dfs_cache_add_vol(char *mntdata, struct smb_vol *vol, const char *fullpath)
                goto err_free_vi;
        }
 
-       rc = dup_vol(vol, &vi->smb_vol);
+       rc = smb3_fs_context_dup(&vi->ctx, ctx);
        if (rc)
                goto err_free_fullpath;
 
        vi->mntdata = mntdata;
-       spin_lock_init(&vi->smb_vol_lock);
+       spin_lock_init(&vi->ctx_lock);
        kref_init(&vi->refcnt);
 
        spin_lock(&vol_list_lock);
@@ -1289,10 +1232,10 @@ int dfs_cache_update_vol(const char *fullpath, struct TCP_Server_Info *server)
        spin_unlock(&vol_list_lock);
 
        cifs_dbg(FYI, "%s: updating volume info\n", __func__);
-       spin_lock(&vi->smb_vol_lock);
-       memcpy(&vi->smb_vol.dstaddr, &server->dstaddr,
-              sizeof(vi->smb_vol.dstaddr));
-       spin_unlock(&vi->smb_vol_lock);
+       spin_lock(&vi->ctx_lock);
+       memcpy(&vi->ctx.dstaddr, &server->dstaddr,
+              sizeof(vi->ctx.dstaddr));
+       spin_unlock(&vi->ctx_lock);
 
        kref_put(&vi->refcnt, vol_release);
 
@@ -1445,11 +1388,11 @@ static inline void put_tcp_server(struct TCP_Server_Info *server)
        cifs_put_tcp_session(server, 0);
 }
 
-static struct TCP_Server_Info *get_tcp_server(struct smb_vol *vol)
+static struct TCP_Server_Info *get_tcp_server(struct smb3_fs_context *ctx)
 {
        struct TCP_Server_Info *server;
 
-       server = cifs_find_tcp_session(vol);
+       server = cifs_find_tcp_session(ctx);
        if (IS_ERR_OR_NULL(server))
                return NULL;
 
@@ -1473,10 +1416,10 @@ static struct cifs_ses *find_root_ses(struct vol_info *vi,
        int rc;
        struct cache_entry *ce;
        struct dfs_info3_param ref = {0};
-       char *mdata = NULL, *devname = NULL;
+       char *mdata = NULL;
        struct TCP_Server_Info *server;
        struct cifs_ses *ses;
-       struct smb_vol vol = {NULL};
+       struct smb3_fs_context ctx = {NULL};
 
        rpath = get_dfs_root(path);
        if (IS_ERR(rpath))
@@ -1500,8 +1443,7 @@ static struct cifs_ses *find_root_ses(struct vol_info *vi,
 
        up_read(&htable_rw_lock);
 
-       mdata = cifs_compose_mount_options(vi->mntdata, rpath, &ref,
-                                          &devname);
+       mdata = cifs_compose_mount_options(vi->mntdata, rpath, &ref);
        free_dfs_info_param(&ref);
 
        if (IS_ERR(mdata)) {
@@ -1510,24 +1452,23 @@ static struct cifs_ses *find_root_ses(struct vol_info *vi,
                goto out;
        }
 
-       rc = cifs_setup_volume_info(&vol, mdata, devname, false);
-       kfree(devname);
+       rc = cifs_setup_volume_info(&ctx);
 
        if (rc) {
                ses = ERR_PTR(rc);
                goto out;
        }
 
-       server = get_tcp_server(&vol);
+       server = get_tcp_server(&ctx);
        if (!server) {
                ses = ERR_PTR(-EHOSTDOWN);
                goto out;
        }
 
-       ses = cifs_get_smb_ses(server, &vol);
+       ses = cifs_get_smb_ses(server, &ctx);
 
 out:
-       cifs_cleanup_volume_info_contents(&vol);
+       smb3_cleanup_fs_context_contents(&ctx);
        kfree(mdata);
        kfree(rpath);
 
@@ -1619,7 +1560,7 @@ static void refresh_cache_worker(struct work_struct *work)
         */
        spin_lock(&vol_list_lock);
        list_for_each_entry(vi, &vol_list, list) {
-               server = get_tcp_server(&vi->smb_vol);
+               server = get_tcp_server(&vi->ctx);
                if (!server)
                        continue;
 
@@ -1631,9 +1572,9 @@ static void refresh_cache_worker(struct work_struct *work)
 
        /* Walk through all TCONs and refresh any expired cache entry */
        list_for_each_entry_safe(vi, nvi, &vols, rlist) {
-               spin_lock(&vi->smb_vol_lock);
-               server = get_tcp_server(&vi->smb_vol);
-               spin_unlock(&vi->smb_vol_lock);
+               spin_lock(&vi->ctx_lock);
+               server = get_tcp_server(&vi->ctx);
+               spin_unlock(&vi->ctx_lock);
 
                if (!server)
                        goto next_vol;