[CIFS] fixed compatibility issue with samba refferal request
[safe/jmp/linux-2.6] / fs / cifs / cifs_dfs_ref.c
index 6ad4475..f6fdecf 100644 (file)
 #include "dns_resolve.h"
 #include "cifs_debug.h"
 
-LIST_HEAD(cifs_dfs_automount_list);
+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;
+
+static void cifs_dfs_expire_automounts(struct work_struct *work)
+{
+       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 dfs_shrink_umount_helper(struct vfsmount *vfsmnt)
+void cifs_dfs_release_automount_timer(void)
 {
-       mark_mounts_for_expiry(&cifs_dfs_automount_list);
-       mark_mounts_for_expiry(&cifs_dfs_automount_list);
-       shrink_submounts(vfsmnt, &cifs_dfs_automount_list);
+       BUG_ON(!list_empty(&cifs_dfs_automount_list));
+       cancel_delayed_work(&cifs_dfs_automount_task);
+       flush_scheduled_work();
 }
 
 /**
@@ -74,7 +85,7 @@ static char *cifs_get_share_name(const char *node_name)
        pSep = memchr(UNC+2, '\\', len-2);
        if (!pSep) {
                cERROR(1, ("%s: no server name end in node name: %s",
-                       __FUNCTION__, node_name));
+                       __func__, node_name));
                kfree(UNC);
                return NULL;
        }
@@ -82,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",
-                       __FUNCTION__, 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;
 }
@@ -127,7 +134,7 @@ static char *compose_mount_options(const char *sb_mountdata,
        rc = dns_resolve_server_name_to_ip(*devname, &srvIP);
        if (rc != 0) {
                cERROR(1, ("%s: Failed to resolve server part of %s to IP",
-                         __FUNCTION__, *devname));
+                         __func__, *devname));
                mountdata = ERR_PTR(rc);
                goto compose_mount_options_out;
        }
@@ -177,12 +184,12 @@ 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);
                }
        }
 
-       /*cFYI(1,("%s: parent mountdata: %s", __FUNCTION__,sb_mountdata));*/
-       /*cFYI(1, ("%s: submount mountdata: %s", __FUNCTION__, mountdata ));*/
+       /*cFYI(1,("%s: parent mountdata: %s", __func__,sb_mountdata));*/
+       /*cFYI(1, ("%s: submount mountdata: %s", __func__, mountdata ));*/
 
 compose_mount_options_out:
        kfree(srvIP);
@@ -233,7 +240,8 @@ static char *build_full_dfs_path_from_dentry(struct dentry *dentry)
                return NULL;
 
        if (cifs_sb->tcon->Flags & SMB_SHARE_IS_IN_DFS) {
-               /* we should use full path name to correct working with DFS */
+               int i;
+               /* we should use full path name for 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);
@@ -242,8 +250,14 @@ static char *build_full_dfs_path_from_dentry(struct dentry *dentry)
                        return NULL;
                }
                strncpy(tmp_path, cifs_sb->tcon->treeName, l_max_len);
-               strcat(tmp_path, search_path);
                tmp_path[l_max_len-1] = 0;
+               if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_POSIX_PATHS)
+                       for (i = 0; i < l_max_len; i++) {
+                               if (tmp_path[i] == '\\')
+                                       tmp_path[i] = '/';
+                       }
+               strncat(tmp_path, search_path, l_max_len - strlen(tmp_path));
+
                full_path = tmp_path;
                kfree(search_path);
        } else {
@@ -262,10 +276,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 */
@@ -286,7 +301,7 @@ static void dump_referral(const struct dfs_info3_param *ref)
        cFYI(1, ("DFS: node path: %s", ref->node_name));
        cFYI(1, ("DFS: fl: %hd, srv_type: %hd", ref->flags, ref->server_type));
        cFYI(1, ("DFS: ref_flags: %hd, path_consumed: %hd", ref->ref_flag,
-                               ref->PathConsumed));
+                               ref->path_consumed));
 }
 
 
@@ -302,7 +317,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
        int rc = 0;
        struct vfsmount *mnt = ERR_PTR(-ENOENT);
 
-       cFYI(1, ("in %s", __FUNCTION__));
+       cFYI(1, ("in %s", __func__));
        BUG_ON(IS_ROOT(dentry));
 
        xid = GetXid();
@@ -336,7 +351,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
                        len = strlen(referrals[i].node_name);
                        if (len < 2) {
                                cERROR(1, ("%s: Net Address path too short: %s",
-                                       __FUNCTION__, referrals[i].node_name));
+                                       __func__, referrals[i].node_name));
                                rc = -EINVAL;
                                goto out_err;
                        }
@@ -344,7 +359,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
                                                nd->path.dentry,
                                                referrals[i].node_name);
                        cFYI(1, ("%s: cifs_dfs_do_refmount:%s , mnt:%p",
-                                        __FUNCTION__,
+                                        __func__,
                                        referrals[i].node_name, mnt));
 
                        /* complete mount procedure if we accured submount */
@@ -365,7 +380,7 @@ out:
        FreeXid(xid);
        free_dfs_info_array(referrals, num_referrals);
        kfree(full_path);
-       cFYI(1, ("leaving %s" , __FUNCTION__));
+       cFYI(1, ("leaving %s" , __func__));
        return ERR_PTR(rc);
 out_err:
        path_put(&nd->path);