All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Suresh Jayaraman <sjayaraman-l3A5Bk7waGM@public.gmane.org>
Cc: smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH 02/18] cifs: no need to mark smb_ses_list as cifs_demultiplex_thread is exiting
Date: Mon, 20 Dec 2010 20:38:40 -0500	[thread overview]
Message-ID: <20101220203840.26adf77f@corrin.poochiereds.net> (raw)
In-Reply-To: <4D0F868E.8020407-l3A5Bk7waGM@public.gmane.org>

On Mon, 20 Dec 2010 22:08:38 +0530
Suresh Jayaraman <sjayaraman-l3A5Bk7waGM@public.gmane.org> wrote:

> On 12/17/2010 08:38 PM, Jeff Layton wrote:
> > The TCP_Server_Info is refcounted and every SMB session holds a
> > reference to it. Thus, smb_ses_list is always going to be empty when
> > cifsd is coming down. This is dead code.
> > 
> > Signed-off-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
> > ---
> >  fs/cifs/connect.c |   44 +++-----------------------------------------
> >  1 files changed, 3 insertions(+), 41 deletions(-)
> > 
> > diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
> > index 9fe620e2..67d3d0d 100644
> > --- a/fs/cifs/connect.c
> > +++ b/fs/cifs/connect.c
> > @@ -346,7 +346,6 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
> >  	struct kvec iov;
> >  	struct socket *csocket = server->ssocket;
> >  	struct list_head *tmp;
> > -	struct cifsSesInfo *ses;
> >  	struct task_struct *task_to_wake = NULL;
> >  	struct mid_q_entry *mid_entry;
> >  	char temp;
> > @@ -677,44 +676,19 @@ multi_t2_fnd:
> >  	if (smallbuf) /* no sense logging a debug message if NULL */
> >  		cifs_small_buf_release(smallbuf);
> >  
> > -	/*
> > -	 * BB: we shouldn't have to do any of this. It shouldn't be
> > -	 * possible to exit from the thread with active SMB sessions
> > -	 */
> > -	spin_lock(&cifs_tcp_ses_lock);
> > -	if (list_empty(&server->pending_mid_q)) {
> > -		/* loop through server session structures attached to this and
> > -		    mark them dead */
> > -		list_for_each(tmp, &server->smb_ses_list) {
> > -			ses = list_entry(tmp, struct cifsSesInfo,
> > -					 smb_ses_list);
> > -			ses->status = CifsExiting;
> > -			ses->server = NULL;
> > -		}
> > -		spin_unlock(&cifs_tcp_ses_lock);
> > -	} else {
> > -		/* although we can not zero the server struct pointer yet,
> > -		since there are active requests which may depnd on them,
> > -		mark the corresponding SMB sessions as exiting too */
> > -		list_for_each(tmp, &server->smb_ses_list) {
> > -			ses = list_entry(tmp, struct cifsSesInfo,
> > -					 smb_ses_list);
> > -			ses->status = CifsExiting;
> > -		}
> > -
> > +	if (!list_empty(&server->pending_mid_q)) {
> >  		spin_lock(&GlobalMid_Lock);
> >  		list_for_each(tmp, &server->pending_mid_q) {
> > -		mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
> > +			mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
> >  			if (mid_entry->midState == MID_REQUEST_SUBMITTED) {
> >  				cFYI(1, "Clearing Mid 0x%x - waking up ",
> > -					 mid_entry->mid);
> > +					mid_entry->mid);
> >  				task_to_wake = mid_entry->tsk;
> >  				if (task_to_wake)
> >  					wake_up_process(task_to_wake);
> >  			}
> >  		}
> >  		spin_unlock(&GlobalMid_Lock);
> > -		spin_unlock(&cifs_tcp_ses_lock);
> >  		/* 1/8th of sec is more than enough time for them to exit */
> >  		msleep(125);
> >  	}
> > @@ -732,18 +706,6 @@ multi_t2_fnd:
> >  		coming home not much else we can do but free the memory */
> >  	}
> >  
> > -	/* last chance to mark ses pointers invalid
> > -	if there are any pointing to this (e.g
> > -	if a crazy root user tried to kill cifsd
> > -	kernel thread explicitly this might happen) */
> 
> The above comment sounds little scary. Though, I don't see how this
> could happen, I think it's better to test the above scenario to be sure
> (I guess you would have already taken care?)
> 
> > -	/* BB: This shouldn't be necessary, see above */
> > -	spin_lock(&cifs_tcp_ses_lock);
> > -	list_for_each(tmp, &server->smb_ses_list) {
> > -		ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
> > -		ses->server = NULL;
> > -	}
> > -	spin_unlock(&cifs_tcp_ses_lock);
> > -
> >  	kfree(server->hostname);
> >  	task_to_wake = xchg(&server->tsk, NULL);
> >  	kfree(server);
> 
> 

That comment is a holdover from earlier, broken code that did not do
proper refcounting (see the changes in 2008 near commit e7ddee90 that
fixed this). You'll note that I added this comment around the same
time:

-       /*
-        * BB: we shouldn't have to do any of this. It shouldn't be
-        * possible to exit from the thread with active SMB sessions
-        */

...but I never got around to actually ripping out that bogus code.

Today, the only way to take down cifs_demultiplex_thread is for the
refcount (server->srv_count) to go to zero. The model is for each
cifsSesInfo struct to hold a single reference to a TCP_Server_Info. So,
if there are still entries on the server->smb_ses_list while the thread
is coming down, then there is something very, very wrong.

-- 
Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>

  parent reply	other threads:[~2010-12-21  1:38 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-17 15:07 [PATCH 00/18] cifs: overhaul request timeout behavior in CIFS (try #3) Jeff Layton
     [not found] ` <1292598497-29796-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-17 15:08   ` [PATCH 01/18] cifs: don't fail writepages on -EAGAIN errors Jeff Layton
     [not found]     ` <1292598497-29796-2-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 10:53       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 02/18] cifs: no need to mark smb_ses_list as cifs_demultiplex_thread is exiting Jeff Layton
     [not found]     ` <1292598497-29796-3-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 10:52       ` Suresh Jayaraman
2010-12-20 16:38       ` Suresh Jayaraman
     [not found]         ` <4D0F868E.8020407-l3A5Bk7waGM@public.gmane.org>
2010-12-21  1:38           ` Jeff Layton [this message]
2010-12-17 15:08   ` [PATCH 03/18] cifs: make wait_for_free_request take a TCP_Server_Info pointer Jeff Layton
     [not found]     ` <1292598497-29796-4-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 10:52       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 04/18] cifs: clean up accesses to midCount Jeff Layton
     [not found]     ` <1292598497-29796-5-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 10:52       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 05/18] cifs: move locked sections out of DeleteMidQEntry and AllocMidQEntry Jeff Layton
     [not found]     ` <1292598497-29796-6-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 11:00       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 06/18] cifs: move mid result processing into common function Jeff Layton
     [not found]     ` <1292598497-29796-7-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 11:06       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 07/18] cifs: wait indefinitely for responses Jeff Layton
     [not found]     ` <1292598497-29796-8-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-21 15:50       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 08/18] cifs: don't reconnect server when we don't get a response Jeff Layton
     [not found]     ` <1292598497-29796-9-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 11:27       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 09/18] cifs: clean up sync_mid_result Jeff Layton
     [not found]     ` <1292598497-29796-10-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-20 11:27       ` Suresh Jayaraman
     [not found]         ` <4D0F3DAD.7080801-l3A5Bk7waGM@public.gmane.org>
2010-12-20 13:04           ` Jeff Layton
     [not found]             ` <20101220080409.35112ed8-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org>
2010-12-20 16:35               ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 10/18] cifs: allow for different handling of received response Jeff Layton
     [not found]     ` <1292598497-29796-11-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-21 15:50       ` Suresh Jayaraman
     [not found]         ` <4D10CCD3.1040502-l3A5Bk7waGM@public.gmane.org>
2010-12-21 16:48           ` Jeff Layton
2010-12-21 15:51       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 11/18] cifs: handle cancelled requests better Jeff Layton
2010-12-17 15:08   ` [PATCH 12/18] cifs: add cifs_call_async Jeff Layton
     [not found]     ` <1292598497-29796-13-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-21 16:05       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 13/18] cifs: add ability to send an echo request Jeff Layton
     [not found]     ` <1292598497-29796-14-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-21 16:05       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 14/18] cifs: set up recurring workqueue job to do SMB echo requests Jeff Layton
     [not found]     ` <1292598497-29796-15-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-21 16:06       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 15/18] cifs: reconnect unresponsive servers Jeff Layton
     [not found]     ` <1292598497-29796-16-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-23 10:31       ` Suresh Jayaraman
     [not found]         ` <4D1324EC.8010305-l3A5Bk7waGM@public.gmane.org>
2010-12-23 13:20           ` Jeff Layton
     [not found]             ` <20101223082005.347b8ca8-xSBYVWDuneFaJnirhKH9O4GKTjYczspe@public.gmane.org>
2010-12-23 15:36               ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 16/18] cifs: remove code for setting timeouts on requests Jeff Layton
     [not found]     ` <1292598497-29796-17-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-23 10:32       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 17/18] cifs: mangle existing header for SMB_COM_NT_CANCEL Jeff Layton
     [not found]     ` <1292598497-29796-18-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-23 11:05       ` Suresh Jayaraman
2010-12-17 15:08   ` [PATCH 18/18] cifs: send an NT_CANCEL request when a process is signalled Jeff Layton
     [not found]     ` <1292598497-29796-19-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-23 11:06       ` Suresh Jayaraman
  -- strict thread matches above, loose matches on Subject: below --
2010-12-27  2:29 [PATCH 00/18] cifs: overhaul request timeout behavior in CIFS (try #4) Jeff Layton
     [not found] ` <1293417006-6417-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-12-27  2:29   ` [PATCH 02/18] cifs: no need to mark smb_ses_list as cifs_demultiplex_thread is exiting Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101220203840.26adf77f@corrin.poochiereds.net \
    --to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sjayaraman-l3A5Bk7waGM@public.gmane.org \
    --cc=smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.