Print this page
5133 Upstream SMB client fixes: Nexenta SUP-538 and SUP-548


  15  *    This product includes software developed by Boris Popov.
  16  * 4. Neither the name of the author nor the names of any co-contributors
  17  *    may be used to endorse or promote products derived from this software
  18  *    without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30  * SUCH DAMAGE.
  31  *
  32  * $Id: smb_trantcp.c,v 1.39 2005/03/02 01:27:44 lindak Exp $
  33  */
  34 /*
  35  * Copyright 2012 Nexenta Systems, Inc.  All rights reserved.
  36  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  37  * Use is subject to license terms.

  38  */
  39 
  40 #include <sys/param.h>
  41 #include <sys/systm.h>
  42 #include <sys/autoconf.h>
  43 #include <sys/sysmacros.h>
  44 #include <sys/sunddi.h>
  45 #include <sys/kmem.h>
  46 #include <sys/proc.h>
  47 #include <sys/protosw.h>
  48 #include <sys/socket.h>
  49 #include <sys/poll.h>
  50 #include <sys/stream.h>
  51 #include <sys/strsubr.h>
  52 #include <sys/strsun.h>
  53 #include <sys/stropts.h>
  54 #include <sys/cmn_err.h>
  55 #include <sys/tihdr.h>
  56 #include <sys/tiuser.h>
  57 #include <sys/t_kuser.h>


 579  * Keeping nbp_lock held during the activities of these two
 580  * threads would lead to the possibility of nbp_lock being
 581  * held by a blocked thread, so this instead sets one of the
 582  * flags (NBF_SENDLOCK | NBF_RECVLOCK) when a sender or a
 583  * receiver is active (respectively).  Lastly, tear-down is
 584  * the only tricky bit (here) where we must wait for any of
 585  * these activities to get out of current calls so they will
 586  * notice that we've turned off the NBF_CONNECTED flag.
 587  */
 588 static void
 589 nb_unloan_fp(struct nbpcb *nbp)
 590 {
 591 
 592         mutex_enter(&nbp->nbp_lock);
 593 
 594         nbp->nbp_flags &= ~NBF_CONNECTED;
 595         while (nbp->nbp_flags & (NBF_SENDLOCK | NBF_RECVLOCK)) {
 596                 nbp->nbp_flags |= NBF_LOCKWAIT;
 597                 cv_wait(&nbp->nbp_cv, &nbp->nbp_lock);
 598         }
 599 



 600         if (nbp->nbp_tiptr != NULL) {
 601                 (void) t_kclose(nbp->nbp_tiptr, 0);
 602                 nbp->nbp_tiptr = NULL;
 603         }
 604         nbp->nbp_state = NBST_CLOSED;
 605 
 606         mutex_exit(&nbp->nbp_lock);
 607 }
 608 
 609 static int
 610 smb_nbst_loan_fp(struct smb_vc *vcp, struct file *fp, cred_t *cr)
 611 {
 612         struct nbpcb *nbp = vcp->vc_tdata;
 613         int error = 0;
 614 
 615         /*
 616          * Un-loan the existing one, if any.
 617          */
 618         (void) nb_disconnect(nbp);
 619         nb_unloan_fp(nbp);


 646 static int
 647 smb_nbst_disconnect(struct smb_vc *vcp)
 648 {
 649         struct nbpcb *nbp = vcp->vc_tdata;
 650 
 651         if (nbp == NULL)
 652                 return (ENOTCONN);
 653 
 654         return (nb_disconnect(nbp));
 655 }
 656 
 657 static int
 658 nb_disconnect(struct nbpcb *nbp)
 659 {
 660         int err = 0;
 661 
 662         mutex_enter(&nbp->nbp_lock);
 663 
 664         if ((nbp->nbp_flags & NBF_CONNECTED) != 0) {
 665                 nbp->nbp_flags &= ~NBF_CONNECTED;
 666 
 667                 if (nbp->nbp_frag != NULL) {
 668                         freemsg(nbp->nbp_frag);
 669                         nbp->nbp_frag = NULL;
 670                 }
 671 
 672                 err = nb_snddis(nbp);
 673         }
 674 
 675         mutex_exit(&nbp->nbp_lock);
 676         return (err);
 677 }
 678 
 679 /*
 680  * Add the NetBIOS session header and send.
 681  *
 682  * Calls to this are serialized at a higher level.
 683  */
 684 static int
 685 nbssn_send(struct nbpcb *nbp, mblk_t *m)
 686 {
 687         ptrdiff_t diff;
 688         uint32_t mlen;
 689         int error;
 690 
 691         /* We should be the only sender. */




  15  *    This product includes software developed by Boris Popov.
  16  * 4. Neither the name of the author nor the names of any co-contributors
  17  *    may be used to endorse or promote products derived from this software
  18  *    without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30  * SUCH DAMAGE.
  31  *
  32  * $Id: smb_trantcp.c,v 1.39 2005/03/02 01:27:44 lindak Exp $
  33  */
  34 /*

  35  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  36  * Use is subject to license terms.
  37  * Copyright 2013 Nexenta Systems, Inc.  All rights reserved.
  38  */
  39 
  40 #include <sys/param.h>
  41 #include <sys/systm.h>
  42 #include <sys/autoconf.h>
  43 #include <sys/sysmacros.h>
  44 #include <sys/sunddi.h>
  45 #include <sys/kmem.h>
  46 #include <sys/proc.h>
  47 #include <sys/protosw.h>
  48 #include <sys/socket.h>
  49 #include <sys/poll.h>
  50 #include <sys/stream.h>
  51 #include <sys/strsubr.h>
  52 #include <sys/strsun.h>
  53 #include <sys/stropts.h>
  54 #include <sys/cmn_err.h>
  55 #include <sys/tihdr.h>
  56 #include <sys/tiuser.h>
  57 #include <sys/t_kuser.h>


 579  * Keeping nbp_lock held during the activities of these two
 580  * threads would lead to the possibility of nbp_lock being
 581  * held by a blocked thread, so this instead sets one of the
 582  * flags (NBF_SENDLOCK | NBF_RECVLOCK) when a sender or a
 583  * receiver is active (respectively).  Lastly, tear-down is
 584  * the only tricky bit (here) where we must wait for any of
 585  * these activities to get out of current calls so they will
 586  * notice that we've turned off the NBF_CONNECTED flag.
 587  */
 588 static void
 589 nb_unloan_fp(struct nbpcb *nbp)
 590 {
 591 
 592         mutex_enter(&nbp->nbp_lock);
 593 
 594         nbp->nbp_flags &= ~NBF_CONNECTED;
 595         while (nbp->nbp_flags & (NBF_SENDLOCK | NBF_RECVLOCK)) {
 596                 nbp->nbp_flags |= NBF_LOCKWAIT;
 597                 cv_wait(&nbp->nbp_cv, &nbp->nbp_lock);
 598         }
 599         if (nbp->nbp_frag != NULL) {
 600                 freemsg(nbp->nbp_frag);
 601                 nbp->nbp_frag = NULL;
 602         }
 603         if (nbp->nbp_tiptr != NULL) {
 604                 (void) t_kclose(nbp->nbp_tiptr, 0);
 605                 nbp->nbp_tiptr = NULL;
 606         }
 607         nbp->nbp_state = NBST_CLOSED;
 608 
 609         mutex_exit(&nbp->nbp_lock);
 610 }
 611 
 612 static int
 613 smb_nbst_loan_fp(struct smb_vc *vcp, struct file *fp, cred_t *cr)
 614 {
 615         struct nbpcb *nbp = vcp->vc_tdata;
 616         int error = 0;
 617 
 618         /*
 619          * Un-loan the existing one, if any.
 620          */
 621         (void) nb_disconnect(nbp);
 622         nb_unloan_fp(nbp);


 649 static int
 650 smb_nbst_disconnect(struct smb_vc *vcp)
 651 {
 652         struct nbpcb *nbp = vcp->vc_tdata;
 653 
 654         if (nbp == NULL)
 655                 return (ENOTCONN);
 656 
 657         return (nb_disconnect(nbp));
 658 }
 659 
 660 static int
 661 nb_disconnect(struct nbpcb *nbp)
 662 {
 663         int err = 0;
 664 
 665         mutex_enter(&nbp->nbp_lock);
 666 
 667         if ((nbp->nbp_flags & NBF_CONNECTED) != 0) {
 668                 nbp->nbp_flags &= ~NBF_CONNECTED;






 669                 err = nb_snddis(nbp);
 670         }
 671 
 672         mutex_exit(&nbp->nbp_lock);
 673         return (err);
 674 }
 675 
 676 /*
 677  * Add the NetBIOS session header and send.
 678  *
 679  * Calls to this are serialized at a higher level.
 680  */
 681 static int
 682 nbssn_send(struct nbpcb *nbp, mblk_t *m)
 683 {
 684         ptrdiff_t diff;
 685         uint32_t mlen;
 686         int error;
 687 
 688         /* We should be the only sender. */