VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / fs / cifs / connect.c
index befbff5..bb6b0f3 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/pagemap.h>
 #include <linux/ctype.h>
 #include <linux/utsname.h>
+#include <linux/mempool.h>
 #include <asm/uaccess.h>
 #include <asm/processor.h>
 #include "cifspdu.h"
@@ -49,6 +50,8 @@ extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8,
                         unsigned char *p24);
 extern int cifs_inet_pton(int, const char *, void *dst);
 
+extern mempool_t *cifs_req_poolp;
+
 struct smb_vol {
        char *username;
        char *password;
@@ -64,6 +67,8 @@ struct smb_vol {
        int rw:1;
        int retry:1;
        int intr:1;
+       int setuids:1;
+       int noperm:1;
        unsigned int rsize;
        unsigned int wsize;
        unsigned int sockopt;
@@ -175,7 +180,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
                        if(server->tcpStatus != CifsExiting)
                                server->tcpStatus = CifsGood;
                        spin_unlock(&GlobalMid_Lock);
-                       atomic_set(&server->inFlight,0);
+       /*              atomic_set(&server->inFlight,0);*/
                        wake_up(&server->response_q);
                }
        }
@@ -189,8 +194,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
        unsigned int pdu_length, total_read;
        struct smb_hdr *smb_buffer = NULL;
        struct msghdr smb_msg;
-       mm_segment_t temp_fs;
-       struct iovec iov;
+       struct kvec iov;
        struct socket *csocket = server->ssocket;
        struct list_head *tmp;
        struct cifsSesInfo *ses;
@@ -203,9 +207,15 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
        current->flags |= PF_MEMALLOC;
        server->tsk = current;  /* save process info to wake at shutdown */
        cFYI(1, ("Demultiplex PID: %d", current->pid));
-
-       temp_fs = get_fs();     /* we must turn off socket api parm checking */
-       set_fs(get_ds());
+       write_lock(&GlobalSMBSeslock);
+       atomic_inc(&tcpSesAllocCount);
+       length = tcpSesAllocCount.counter;
+       write_unlock(&GlobalSMBSeslock);
+       if(length  > 1) {
+               mempool_resize(cifs_req_poolp,
+                       length + CIFS_MIN_RCV_POOL,
+                       GFP_KERNEL);
+       }
 
        while (server->tcpStatus != CifsExiting) {
                if (smb_buffer == NULL)
@@ -222,16 +232,15 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                iov.iov_base = smb_buffer;
                iov.iov_len = sizeof (struct smb_hdr) - 1;      
         /* 1 byte less above since wct is not always returned in error cases */
-               smb_msg.msg_iov = &iov;
-               smb_msg.msg_iovlen = 1;
                smb_msg.msg_control = NULL;
                smb_msg.msg_controllen = 0;
 
                length =
-                   sock_recvmsg(csocket, &smb_msg,
-                                sizeof (struct smb_hdr) -
-                                1 /* RFC1001 header and SMB header */ ,
-                                MSG_PEEK /* flags see socket.h */ );
+                   kernel_recvmsg(csocket, &smb_msg,
+                                  &iov, 1,
+                                  sizeof (struct smb_hdr) -
+                                  1 /* RFC1001 header and SMB header */ ,
+                                  MSG_PEEK /* flags see socket.h */ );
 
                if(server->tcpStatus == CifsExiting) {
                        break;
@@ -253,13 +262,12 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                                /* some servers kill tcp session rather than returning
                                        smb negprot error in which case reconnecting here is
                                        not going to help - return error to mount */
-                               spin_lock(&GlobalMid_Lock);
-                               server->tcpStatus = CifsExiting;
-                               spin_unlock(&GlobalMid_Lock);
-                               wake_up(&server->response_q);
                                break;
                        }
-
+                       if(length == -EINTR) { 
+                               cFYI(1,("cifsd thread killed"));
+                               break;
+                       }
                        cFYI(1,("Reconnecting after unexpected peek error %d",length));
                        cifs_reconnect(server);
                        csocket = server->ssocket;
@@ -277,12 +285,14 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                        if (temp[0] == (char) RFC1002_SESSION_KEEP_ALIVE) {
                                iov.iov_base = smb_buffer;
                                iov.iov_len = 4;
-                               length = sock_recvmsg(csocket, &smb_msg, 4, 0);
+                               length = kernel_recvmsg(csocket, &smb_msg,
+                                                       &iov, 1, 4, 0);
                                cFYI(0,("Received 4 byte keep alive packet"));
                        } else if (temp[0] == (char) RFC1002_POSITIVE_SESSION_RESPONSE) {
-                                       iov.iov_base = smb_buffer;
-                                       iov.iov_len = 4;
-                                       length = sock_recvmsg(csocket, &smb_msg, 4, 0);
+                               iov.iov_base = smb_buffer;
+                               iov.iov_len = 4;
+                               length = kernel_recvmsg(csocket, &smb_msg,
+                                                       &iov, 1, 4, 0);
                                        cFYI(1,("Good RFC 1002 session rsp"));
                        } else if ((temp[0] == (char)RFC1002_NEGATIVE_SESSION_RESPONSE)
                                   && (length == 5)) {
@@ -292,11 +302,6 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                                        /* if nack on negprot (rather than 
                                        ret of smb negprot error) reconnecting
                                        not going to help, ret error to mount */
-                                       spin_lock(&GlobalMid_Lock);
-                                       server->tcpStatus = CifsExiting;
-                                       spin_unlock(&GlobalMid_Lock);
-                                       /* wake up thread doing negprot */
-                                       wake_up(&server->response_q);
                                        break;
                                } else {
                                        /* give server a second to
@@ -347,7 +352,8 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                                        for (total_read = 0; 
                                             total_read < pdu_length;
                                             total_read += length) {    
-                                               length = sock_recvmsg(csocket, &smb_msg, 
+                                               length = kernel_recvmsg(csocket, &smb_msg, 
+                                                       &iov, 1,
                                                        pdu_length - total_read, 0);
                                                if (length == 0) {
                                                        cERROR(1,
@@ -398,7 +404,9 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                             ("Frame less than four bytes received  %d bytes long.",
                              length));
                        if (length > 0) {
-                               length = sock_recvmsg(csocket, &smb_msg, length, 0);    /* throw away junk frame */
+                               length = kernel_recvmsg(csocket, &smb_msg,
+                                       &iov, 1,
+                                       length, 0);     /* throw away junk frame */
                                cFYI(1,
                                     (" with junk  0x%x in it ",
                                      *(__u32 *) smb_buffer));
@@ -407,20 +415,23 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
        }
        spin_lock(&GlobalMid_Lock);
        server->tcpStatus = CifsExiting;
-       spin_unlock(&GlobalMid_Lock);
+       server->tsk = NULL;
        atomic_set(&server->inFlight, 0);
+       spin_unlock(&GlobalMid_Lock);
        /* Although there should not be any requests blocked on 
        this queue it can not hurt to be paranoid and try to wake up requests
        that may haven been blocked when more than 50 at time were on the wire 
        to the same server - they now will see the session is in exit state
        and get out of SendReceive.  */
-       wake_up_all(&server->request_q);   
-       server->tsk = NULL;
+       wake_up_all(&server->request_q);
+       /* give those requests time to exit */
+       set_current_state(TASK_INTERRUPTIBLE);
+       schedule_timeout(HZ/8);
+
        if(server->ssocket) {
                sock_release(csocket);
                server->ssocket = NULL;
        }
-       set_fs(temp_fs);
        if (smb_buffer) /* buffer usually freed in free_mid - need to free it on error or exit */
                cifs_buf_release(smb_buffer);
 
@@ -453,7 +464,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                spin_unlock(&GlobalMid_Lock);
                read_unlock(&GlobalSMBSeslock);
                set_current_state(TASK_INTERRUPTIBLE);
-               /* 1/8th of sec should be more than enough time for them to exit */
+               /* 1/8th of sec is more than enough time for them to exit */
                schedule_timeout(HZ/8); 
        }
 
@@ -468,7 +479,18 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
        }
        kfree(server);
 
-       cFYI(1, ("About to exit from demultiplex thread"));
+       write_lock(&GlobalSMBSeslock);
+       atomic_dec(&tcpSesAllocCount);
+       length = tcpSesAllocCount.counter;
+       write_unlock(&GlobalSMBSeslock);
+       if(length  > 0) {
+               mempool_resize(cifs_req_poolp,
+                       length + CIFS_MIN_RCV_POOL,
+                       GFP_KERNEL);
+       }
+
+       set_current_state(TASK_INTERRUPTIBLE);
+       schedule_timeout(HZ/4);
        return 0;
 }
 
@@ -716,6 +738,8 @@ cifs_parse_mount_options(char *options, const char *devname, struct smb_vol *vol
                                if((i==15) && (value[i] != 0))
                                        printk(KERN_WARNING "CIFS: netbiosname longer than 15 and was truncated.\n");
                        }
+               } else if (strnicmp(data, "credentials", 4) == 0) {
+                       /* ignore */
                } else if (strnicmp(data, "version", 3) == 0) {
                        /* ignore */
                } else if (strnicmp(data, "rw", 2) == 0) {
@@ -740,6 +764,14 @@ cifs_parse_mount_options(char *options, const char *devname, struct smb_vol *vol
                        vol->retry = 1;
                } else if (strnicmp(data, "soft", 4) == 0) {
                        vol->retry = 0;
+               } else if (strnicmp(data, "perm", 4) == 0) {
+                       vol->noperm = 0;
+               } else if (strnicmp(data, "noperm", 6) == 0) {
+                       vol->noperm = 1;
+               } else if (strnicmp(data, "setuids", 7) == 0) {
+                       vol->setuids = 1;
+               } else if (strnicmp(data, "nosetuids", 9) == 0) {
+                       vol->setuids = 0;
                } else if (strnicmp(data, "nohard", 6) == 0) {
                        vol->retry = 0;
                } else if (strnicmp(data, "nosoft", 6) == 0) {
@@ -1314,6 +1346,12 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
                cifs_sb->mnt_file_mode = volume_info.file_mode;
                cifs_sb->mnt_dir_mode = volume_info.dir_mode;
                cFYI(1,("file mode: 0x%x  dir mode: 0x%x",cifs_sb->mnt_file_mode,cifs_sb->mnt_dir_mode));
+
+               if(volume_info.noperm)
+                       cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
+               if(volume_info.setuids)
+                       cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_SET_UID;
+
                tcon =
                    find_unc(sin_server.sin_addr.s_addr, volume_info.UNC,
                             volume_info.username);
@@ -1357,31 +1395,37 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb,
                        }
                }
        }
-       if (pSesInfo->capabilities & CAP_LARGE_FILES) {
-               cFYI(0, ("Large files supported "));
-               sb->s_maxbytes = (u64) 1 << 63;
-       } else
-               sb->s_maxbytes = (u64) 1 << 31; /* 2 GB */
+       if(pSesInfo) {
+               if (pSesInfo->capabilities & CAP_LARGE_FILES) {
+                       sb->s_maxbytes = (u64) 1 << 63;
+               } else
+                       sb->s_maxbytes = (u64) 1 << 31; /* 2 GB */
+       }
 
 /* on error free sesinfo and tcon struct if needed */
        if (rc) {
+               /* if session setup failed, use count is zero but
+               we still need to free cifsd thread */
                if(atomic_read(&srvTcp->socketUseCount) == 0) {
                        spin_lock(&GlobalMid_Lock);
                        srvTcp->tcpStatus = CifsExiting;
                        spin_unlock(&GlobalMid_Lock);
+                       if(srvTcp->tsk)
+                               send_sig(SIGKILL,srvTcp->tsk,1);
                }
                 /* If find_unc succeeded then rc == 0 so we can not end */
-               if (tcon)  /* up here accidently freeing someone elses tcon struct */
+               if (tcon)  /* up accidently freeing someone elses tcon struct */
                        tconInfoFree(tcon);
                if (existingCifsSes == 0) {
                        if (pSesInfo) {
-                               if (pSesInfo->server) {
-                                       if (pSesInfo->Suid)
-                                               CIFSSMBLogoff(xid, pSesInfo);
-                                       if(pSesInfo->server->tsk)
+                               if ((pSesInfo->server) && 
+                                   (pSesInfo->status == CifsGood)) {
+                                       int temp_rc;
+                                       temp_rc = CIFSSMBLogoff(xid, pSesInfo);
+                                       /* if the socketUseCount is now zero */
+                                       if((temp_rc == -ESHUTDOWN) &&
+                                          (pSesInfo->server->tsk))
                                                send_sig(SIGKILL,pSesInfo->server->tsk,1);
-                                       set_current_state(TASK_INTERRUPTIBLE);
-                                       schedule_timeout(HZ / 4);       /* give captive thread time to exit */
                                } else
                                        cFYI(1, ("No session or bad tcon"));
                                sesInfoFree(pSesInfo);
@@ -1438,7 +1482,7 @@ CIFSSessSetup(unsigned int xid, struct cifsSesInfo *ses,
 
        /* send SMBsessionSetup here */
        header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
-                       0 /* no tCon exists yet */ , 13 /* wct */ );
+                       NULL /* no tCon exists yet */ , 13 /* wct */ );
 
        pSMB->req_no_secext.AndXCommand = 0xFF;
        pSMB->req_no_secext.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
@@ -1694,7 +1738,7 @@ CIFSSpnegoSessSetup(unsigned int xid, struct cifsSesInfo *ses,
 
        /* send SMBsessionSetup here */
        header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
-                       0 /* no tCon exists yet */ , 12 /* wct */ );
+                       NULL /* no tCon exists yet */ , 12 /* wct */ );
        pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
        pSMB->req.AndXCommand = 0xFF;
        pSMB->req.MaxBufferSize = cpu_to_le16(ses->server->maxBuf);
@@ -1956,7 +2000,7 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned int xid,
 
        /* send SMBsessionSetup here */
        header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
-                       0 /* no tCon exists yet */ , 12 /* wct */ );
+                       NULL /* no tCon exists yet */ , 12 /* wct */ );
        pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
        pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT);
 
@@ -2296,7 +2340,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xid, struct cifsSesInfo *ses,
 
        /* send SMBsessionSetup here */
        header_assemble(smb_buffer, SMB_COM_SESSION_SETUP_ANDX,
-                       0 /* no tCon exists yet */ , 12 /* wct */ );
+                       NULL /* no tCon exists yet */ , 12 /* wct */ );
        pSMB->req.hdr.Flags |= (SMBFLG_CASELESS | SMBFLG_CANONICAL_PATH_FORMAT);
        pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
        pSMB->req.AndXCommand = 0xFF;
@@ -2669,7 +2713,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
        smb_buffer_response = smb_buffer;
 
        header_assemble(smb_buffer, SMB_COM_TREE_CONNECT_ANDX,
-                       0 /*no tid */ , 4 /*wct */ );
+                       NULL /*no tid */ , 4 /*wct */ );
        smb_buffer->Uid = ses->Suid;
        pSMB = (TCONX_REQ *) smb_buffer;
        pSMBr = (TCONX_RSP *) smb_buffer_response;
@@ -2769,6 +2813,7 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
        int rc = 0;
        int xid;
        struct cifsSesInfo *ses = NULL;
+       struct task_struct *cifsd_task;
 
        xid = GetXid();
 
@@ -2781,19 +2826,19 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
                }
                tconInfoFree(cifs_sb->tcon);
                if ((ses) && (ses->server)) {
+                       /* save off task so we do not refer to ses later */
+                       cifsd_task = ses->server->tsk;
                        cFYI(1, ("About to do SMBLogoff "));
                        rc = CIFSSMBLogoff(xid, ses);
                        if (rc == -EBUSY) {
                                FreeXid(xid);
                                return 0;
-                       }
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       schedule_timeout(HZ / 4);       /* give captive thread time to exit */
-                       if((ses->server) && (ses->server->ssocket)) {            
-                               cFYI(1,("Waking up socket by sending it signal "));
-                               send_sig(SIGKILL,ses->server->tsk,1);
-                       }
+                       } else if (rc == -ESHUTDOWN) {
+                               cFYI(1,("Waking up socket by sending it signal"));
+                               send_sig(SIGKILL,cifsd_task,1);
+                               rc = 0;
+                       } /* else - we have an smb session
+                               left on this socket do not kill cifsd */
                } else
                        cFYI(1, ("No session or bad tcon"));
        }