From patchwork Tue Aug 18 18:07:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 31583 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.samba.org (fn.samba.org [216.83.154.106]) by bilbo.ozlabs.org (Postfix) with ESMTP id 04B5BB7067 for ; Wed, 19 Aug 2009 04:08:35 +1000 (EST) Received: from fn.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 54C89ACFA5; Tue, 18 Aug 2009 12:02:00 -0600 (MDT) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on fn.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=3.8 tests=AWL, BAYES_00, NO_MORE_FUNN, SPF_PASS autolearn=no version=3.2.5 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from cdptpa-omtalb.mail.rr.com (cdptpa-omtalb.mail.rr.com [75.180.132.121]) by lists.samba.org (Postfix) with ESMTP id 3DA8BACF9E for ; Tue, 18 Aug 2009 12:01:54 -0600 (MDT) Received: from mail.poochiereds.net ([71.70.153.3]) by cdptpa-omta04.mail.rr.com with ESMTP id <20090818180827570.FWNB6077@cdptpa-omta04.mail.rr.com>; Tue, 18 Aug 2009 18:08:27 +0000 Received: by mail.poochiereds.net (Postfix, from userid 4447) id 0C0AD5814D; Tue, 18 Aug 2009 14:07:03 -0400 (EDT) From: Jeff Layton To: smfrench@gmail.com Date: Tue, 18 Aug 2009 14:07:00 -0400 Message-Id: <1250618822-6131-4-git-send-email-jlayton@redhat.com> X-Mailer: git-send-email 1.6.0.6 In-Reply-To: <1250618822-6131-1-git-send-email-jlayton@redhat.com> References: <1250618822-6131-1-git-send-email-jlayton@redhat.com> Cc: linux-cifs-client@lists.samba.org Subject: [linux-cifs-client] [PATCH 3/5] cifs: clean up cifs_oplock_thread loop X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-cifs-client-bounces@lists.samba.org Errors-To: linux-cifs-client-bounces@lists.samba.org Minor cleanups and optimizations mostly. Also fix it so that if a kthread_stop races in at the right time, it won't make the thread sleep unnecessarily for 39s. Signed-off-by: Jeff Layton Acked-by: Shirish Pargaonkar --- fs/cifs/cifsfs.c | 66 +++++++++++++++++++++++++++++------------------------ 1 files changed, 36 insertions(+), 30 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 7ce8dcd..2fcc722 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -972,10 +972,10 @@ cifs_destroy_mids(void) static int cifs_oplock_thread(void *dummyarg) { - struct oplock_q_entry *oplock_item; - struct cifsTconInfo *pTcon; + struct oplock_q_entry *oplock; + struct cifsTconInfo *tcon; struct inode *inode; - __u16 netfid; + struct cifsInodeInfo *cifsi; int rc, waitrc = 0; set_freezable(); @@ -984,34 +984,30 @@ static int cifs_oplock_thread(void *dummyarg) continue; spin_lock(&cifs_oplock_lock); - if (list_empty(&cifs_oplock_list)) { + while(!list_empty(&cifs_oplock_list)) { + oplock = list_entry(cifs_oplock_list.next, + struct oplock_q_entry, qhead); + list_del(&oplock->qhead); spin_unlock(&cifs_oplock_lock); - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(39*HZ); - } else { - oplock_item = list_entry(cifs_oplock_list.next, - struct oplock_q_entry, qhead); + cFYI(1, ("found oplock item to write out")); - pTcon = oplock_item->tcon; - inode = oplock_item->pinode; - netfid = oplock_item->netfid; - list_del(&oplock_item->qhead); - spin_unlock(&cifs_oplock_lock); - kmem_cache_free(cifs_oplock_cachep, oplock_item); + tcon = oplock->tcon; + inode = oplock->pinode; /* can not grab inode sem here since it would deadlock when oplock received on delete since vfs_unlink holds the i_mutex across the call */ /* mutex_lock(&inode->i_mutex);*/ + cifsi = CIFS_I(inode); if (S_ISREG(inode->i_mode)) { #ifdef CONFIG_CIFS_EXPERIMENTAL - if (CIFS_I(inode)->clientCanCacheAll == 0) + if (cifsi->clientCanCacheAll == 0) break_lease(inode, FMODE_READ); - else if (CIFS_I(inode)->clientCanCacheRead == 0) + else if (cifsi->clientCanCacheRead == 0) break_lease(inode, FMODE_WRITE); #endif rc = filemap_fdatawrite(inode->i_mapping); - if (CIFS_I(inode)->clientCanCacheRead == 0) { + if (cifsi->clientCanCacheRead == 0) { waitrc = filemap_fdatawait( inode->i_mapping); invalidate_remote_inode(inode); @@ -1022,27 +1018,37 @@ static int cifs_oplock_thread(void *dummyarg) rc = 0; /* mutex_unlock(&inode->i_mutex);*/ if (rc) - CIFS_I(inode)->write_behind_rc = rc; + cifsi->write_behind_rc = rc; cFYI(1, ("Oplock flush inode %p rc %d", inode, rc)); - /* releasing stale oplock after recent reconnect - of smb session using a now incorrect file - handle is not a data integrity issue but do - not bother sending an oplock release if session - to server still is disconnected since oplock - already released by the server in that case */ - if (!pTcon->need_reconnect) { - rc = CIFSSMBLock(0, pTcon, netfid, + /* + * releasing stale oplock after recent reconnect + * of smb session using a now incorrect file + * handle is not a data integrity issue but do + * not bother sending an oplock release if session + * to server still is disconnected since oplock + * already released by the server in that case + */ + if (!tcon->need_reconnect) { + rc = CIFSSMBLock(0, tcon, oplock->netfid, 0 /* len */ , 0 /* offset */, 0, 0, LOCKING_ANDX_OPLOCK_RELEASE, false /* wait flag */); cFYI(1, ("Oplock release rc = %d", rc)); } - cifs_put_tcon(pTcon); - set_current_state(TASK_INTERRUPTIBLE); - schedule_timeout(1); /* yield in case q were corrupt */ + cifs_put_tcon(tcon); + kmem_cache_free(cifs_oplock_cachep, oplock); + spin_lock(&cifs_oplock_lock); + } + spin_unlock(&cifs_oplock_lock); + set_current_state(TASK_INTERRUPTIBLE); + if (kthread_should_stop()) { + set_current_state(TASK_RUNNING); + break; } + /* FIXME: Why 39s here? This should be a named constant. */ + schedule_timeout(39*HZ); } while (!kthread_should_stop()); return 0;