Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/holtmann/bluet...
[linux-block.git] / fs / cifs / cifs_dfs_ref.c
index f53f41ff16653622755973ebf1b7880bf8a0ca09..d82374c9e3296d737a0aba07ea2c08d1acd0ee20 100644 (file)
 
 static LIST_HEAD(cifs_dfs_automount_list);
 
-/*
- * DFS functions
-*/
+static void cifs_dfs_expire_automounts(struct work_struct *work);
+static DECLARE_DELAYED_WORK(cifs_dfs_automount_task,
+                           cifs_dfs_expire_automounts);
+static int cifs_dfs_mountpoint_expiry_timeout = 500 * HZ;
 
-void dfs_shrink_umount_helper(struct vfsmount *vfsmnt)
+static void cifs_dfs_expire_automounts(struct work_struct *work)
 {
-       mark_mounts_for_expiry(&cifs_dfs_automount_list);
-       mark_mounts_for_expiry(&cifs_dfs_automount_list);
+       struct list_head *list = &cifs_dfs_automount_list;
+
+       mark_mounts_for_expiry(list);
+       if (!list_empty(list))
+               schedule_delayed_work(&cifs_dfs_automount_task,
+                                     cifs_dfs_mountpoint_expiry_timeout);
+}
+
+void cifs_dfs_release_automount_timer(void)
+{
+       BUG_ON(!list_empty(&cifs_dfs_automount_list));
+       cancel_delayed_work(&cifs_dfs_automount_task);
+       flush_scheduled_work();
 }
 
 /**
@@ -81,15 +93,11 @@ static char *cifs_get_share_name(const char *node_name)
        /* find sharename end */
        pSep++;
        pSep = memchr(UNC+(pSep-UNC), '\\', len-(pSep-UNC));
-       if (!pSep) {
-               cERROR(1, ("%s:2 cant find share name in node name: %s",
-                       __func__, node_name));
-               kfree(UNC);
-               return NULL;
+       if (pSep) {
+               /* trim path up to sharename end
+                * now we have share name in UNC */
+               *pSep = 0;
        }
-       /* trim path up to sharename end
-        *          * now we have share name in UNC */
-       *pSep = 0;
 
        return UNC;
 }
@@ -176,7 +184,7 @@ static char *compose_mount_options(const char *sb_mountdata,
                tkn_e = strchr(tkn_e+1, '\\');
                if (tkn_e) {
                        strcat(mountdata, ",prefixpath=");
-                       strcat(mountdata, tkn_e);
+                       strcat(mountdata, tkn_e+1);
                }
        }
 
@@ -211,46 +219,6 @@ static struct vfsmount *cifs_dfs_do_refmount(const struct vfsmount *mnt_parent,
 
 }
 
-static char *build_full_dfs_path_from_dentry(struct dentry *dentry)
-{
-       char *full_path = NULL;
-       char *search_path;
-       char *tmp_path;
-       size_t l_max_len;
-       struct cifs_sb_info *cifs_sb;
-
-       if (dentry->d_inode == NULL)
-               return NULL;
-
-       cifs_sb = CIFS_SB(dentry->d_inode->i_sb);
-
-       if (cifs_sb->tcon == NULL)
-               return NULL;
-
-       search_path = build_path_from_dentry(dentry);
-       if (search_path == NULL)
-               return NULL;
-
-       if (cifs_sb->tcon->Flags & SMB_SHARE_IS_IN_DFS) {
-               /* we should use full path name to correct working with DFS */
-               l_max_len = strnlen(cifs_sb->tcon->treeName, MAX_TREE_SIZE+1) +
-                                       strnlen(search_path, MAX_PATHCONF) + 1;
-               tmp_path = kmalloc(l_max_len, GFP_KERNEL);
-               if (tmp_path == NULL) {
-                       kfree(search_path);
-                       return NULL;
-               }
-               strncpy(tmp_path, cifs_sb->tcon->treeName, l_max_len);
-               strcat(tmp_path, search_path);
-               tmp_path[l_max_len-1] = 0;
-               full_path = tmp_path;
-               kfree(search_path);
-       } else {
-               full_path = search_path;
-       }
-       return full_path;
-}
-
 static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd,
                                struct list_head *mntlist)
 {
@@ -261,10 +229,11 @@ static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd,
        err = do_add_mount(newmnt, nd, nd->path.mnt->mnt_flags, mntlist);
        switch (err) {
        case 0:
-               dput(nd->path.dentry);
-               mntput(nd->path.mnt);
+               path_put(&nd->path);
                nd->path.mnt = newmnt;
                nd->path.dentry = dget(newmnt->mnt_root);
+               schedule_delayed_work(&cifs_dfs_automount_task,
+                                     cifs_dfs_mountpoint_expiry_timeout);
                break;
        case -EBUSY:
                /* someone else made a mount here whilst we were busy */
@@ -317,7 +286,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
                goto out_err;
        }
 
-       full_path = build_full_dfs_path_from_dentry(dentry);
+       full_path = build_path_from_dentry(dentry);
        if (full_path == NULL) {
                rc = -ENOMEM;
                goto out_err;