Skip to contentSkip to conversation

cifs and kthread_run / kernel_thread

DISCUSSION Steve French (smfltc) 3 participants 6 messages Apr 1, 2007 – Apr 2, 2007 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 11 lines

Hi all,

I would like to use cifs inside linux-vserver guests. Discussion this with the vserver people, we found that cifs is using the new kthread_run and the old kernel_thread interface for starting kernel-threads. The old-style interface renders cifs unusable inside a vserver-guest :-(

My questions:

i) Are there newer versions of cifs, where only kthread_run is used in all places?

No - IIRC the original patch (for the switch of cifs from kernel_thread to kthread) had a minor implementation problem in handling the cifs_demultiplex thread, so this one small area was left with the old style.

Quoted 3 lines

iii) Is it difficult to switch to the new interface?

No, I don't think so, but I have not investigated it. We would be happy to review and test a patch for this though.

Quoted 16 lines

gs cifs # grep kthread_run *.[ch]

cifsfs.c:       oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
cifsfs.c:       dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd");

gs cifs # grep kernel_thread *.[ch]

cifs.mod.c:     { 0x7e9ebb05, "kernel_thread" },
connect.c:                      rc = (int)kernel_thread((void *)(void *)cifs_demultiplex_thread, srvTcp,

Thx,

Wilhelm

*********************************************

#2 lore raw
Quoted 15 lines · Steve French (smfltc)
Quoted 11 lines

Hi all,

I would like to use cifs inside linux-vserver guests. Discussion this with the vserver people, we found that cifs is using the new kthread_run and the old kernel_thread interface for starting kernel-threads. The old-style interface renders cifs unusable inside a vserver-guest :-(

My questions:

i) Are there newer versions of cifs, where only kthread_run is used in all places?

No - IIRC the original patch (for the switch of cifs from kernel_thread to kthread) had a minor implementation problem in handling the cifs_demultiplex thread, so this one small area was left with the old style.

Quoted 20 lines
Quoted 3 lines

iii) Is it difficult to switch to the new interface?

No, I don't think so, but I have not investigated it. We would be happy to review and test a patch for this though.

Quoted 14 lines

gs cifs # grep kthread_run *.[ch]

cifsfs.c:       oplockThread = kthread_run(cifs_oplock_thread, NULL, "cifsoplockd");
cifsfs.c:       dnotifyThread = kthread_run(cifs_dnotify_thread, NULL, "cifsdnotifyd");

gs cifs # grep kernel_thread *.[ch]

cifs.mod.c:     { 0x7e9ebb05, "kernel_thread" },
connect.c:                      rc = (int)kernel_thread((void *)(void *)cifs_demultiplex_thread, srvTcp,

Thx,

Wilhelm

*****************************************

It seems to me that I rewrote cifs_demultiplex_thread to use kthread_run in DFS patch.

Signature · 5 lines
Best regards,

-------------------------
Igor Mammedov,
niallain "at" gmail.com
#3 lore raw

Hi Steve, hi Igor,

Am Montag, 2. April 2007 schrieb Q (Igor Mammedov):

Quoted 6 lines
Quoted 6 lines

No - IIRC the original patch (for the switch of cifs from kernel_thread to kthread) had a
minor implementation problem in handling the cifs_demultiplex thread, so this one small
area was left with the old style.

can you remember what the problems (if any) were with this patch from Igor?

Quoted 3 lines

It seems to me that I rewrote cifs_demultiplex_thread to use kthread_run in DFS patch.

o.k., I found the patch on the list. Will do some testing with it.

-
Wilhelm

#4 lore raw

Am Montag, 2. April 2007 schrieb Wilhelm Meier:

Quoted 5 lines
Quoted 3 lines

It seems to me that I rewrote cifs_demultiplex_thread to use kthread_run in DFS patch.

o.k., I found the patch on the list. Will do some testing with it.

o.k., the patch seems to be fine for linux-vserver. cifs-mounting inside the guest is now possible.

Do you see any possiblility to include this part of Igors work (not the whole DFS thing) to the mainline? It fixes the use of the deprecated api.

-
Wilhelm

connect.c +16 -16
Index: connect.c
===================================================================
@@ -30,6 +30,7 @@
 #include <linux/mempool.h>
 #include <linux/delay.h>
 #include <linux/completion.h>
+#include <linux/kthread.h>
 #include <linux/pagevec.h>
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -119,7 +120,7 @@
 	struct mid_q_entry * mid_entry;
 	
 	spin_lock(&GlobalMid_Lock);
-	if(server->tcpStatus == CifsExiting) {
+	if( kthread_should_stop() ) {
 		/* the demux thread will exit normally 
 		next time through the loop */
 		spin_unlock(&GlobalMid_Lock);
@@ -181,7 +182,7 @@
 	spin_unlock(&GlobalMid_Lock);
 	up(&server->tcpSem); 
 
-	while ((server->tcpStatus != CifsExiting) && (server->tcpStatus != CifsGood))
+	while ( (!kthread_should_stop()) && (server->tcpStatus != CifsGood))
 	{
 		try_to_freeze();
 		if(server->protocolType == IPV6) {
@@ -198,7 +199,7 @@
 		} else {
 			atomic_inc(&tcpSesReconnectCount);
 			spin_lock(&GlobalMid_Lock);
-			if(server->tcpStatus != CifsExiting)
+			if( !kthread_should_stop() )
 				server->tcpStatus = CifsGood;
 			server->sequence_number = 0;
 			spin_unlock(&GlobalMid_Lock);			
@@ -344,7 +345,6 @@
 	int isMultiRsp;
 	int reconnect;
 
-	daemonize("cifsd");
 	allow_signal(SIGKILL);
 	current->flags |= PF_MEMALLOC;
 	server->tsk = current;	/* save process info to wake at shutdown */
@@ -360,7 +360,7 @@
 			GFP_KERNEL);
 	}
 
-	while (server->tcpStatus != CifsExiting) {
+	while (!kthread_should_stop()) {
 		if (try_to_freeze())
 			continue;
 		if (bigbuf == NULL) {
@@ -399,7 +399,7 @@
 		    kernel_recvmsg(csocket, &smb_msg,
 				 &iov, 1, 4, 0 /* BB see socket.h flags */);
 
-		if (server->tcpStatus == CifsExiting) {
+		if ( kthread_should_stop() ) {
 			break;
 		} else if (server->tcpStatus == CifsNeedReconnect) {
 			cFYI(1, ("Reconnect after server stopped responding"));
@@ -523,7 +523,7 @@
 		     total_read += length) {
 			length = kernel_recvmsg(csocket, &smb_msg, &iov, 1,
 						pdu_length - total_read, 0);
-			if((server->tcpStatus == CifsExiting) ||
+			if( kthread_should_stop() ||
 			    (length == -EINTR)) {
 				/* then will exit */
 				reconnect = 2;
@@ -756,7 +756,6 @@
 			GFP_KERNEL);
 	}
 	
-	complete_and_exit(&cifsd_complete, 0);
 	return 0;
 }
 
@@ -1779,10 +1778,11 @@
 			so no need to spinlock this init of tcpStatus */
 			srvTcp->tcpStatus = CifsNew;
 			init_MUTEX(&srvTcp->tcpSem);
-			rc = (int)kernel_thread((void *)(void *)cifs_demultiplex_thread, srvTcp,
-				      CLONE_FS | CLONE_FILES | CLONE_VM);
-			if(rc < 0) {
-				rc = -ENOMEM;
+			srvTcp->tsk = kthread_run((void *)(void *)cifs_demultiplex_thread, srvTcp, "cifsd");
+			if( IS_ERR(srvTcp->tsk) ) {
+				rc = PTR_ERR(srvTcp->tsk);
+				cERROR(1,("error %d create cifsd thread", rc));
+				srvTcp->tsk = NULL;
 				sock_release(csocket);
 				kfree(volume_info.UNC);
 				kfree(volume_info.password);
@@ -1973,7 +1973,7 @@
 			spin_unlock(&GlobalMid_Lock);
 			if(srvTcp->tsk) {
 				send_sig(SIGKILL,srvTcp->tsk,1);
-				wait_for_completion(&cifsd_complete);
+				kthread_stop(srvTcp->tsk);
 			}
 		}
 		 /* If find_unc succeeded then rc == 0 so we can not end */
@@ -1987,9 +1987,9 @@
 					temp_rc = CIFSSMBLogoff(xid, pSesInfo);
 					/* if the socketUseCount is now zero */
 					if((temp_rc == -ESHUTDOWN) &&
-					   (pSesInfo->server->tsk)) {
+					   (pSesInfo->server) && (pSesInfo->server->tsk)) {
 						send_sig(SIGKILL,pSesInfo->server->tsk,1);
-						wait_for_completion(&cifsd_complete);
+						kthread_stop(pSesInfo->server->tsk);
 					}
 				} else
 					cFYI(1, ("No session or bad tcon"));
@@ -3273,7 +3273,7 @@
 				cFYI(1,("Waking up socket by sending it signal"));
 				if(cifsd_task) {
 					send_sig(SIGKILL,cifsd_task,1);
-					wait_for_completion(&cifsd_complete);
+					kthread_stop(cifsd_task);
 				}
 				rc = 0;
 			} /* else - we have an smb session
#5 lore raw
Quoted 143 lines · Wilhelm Meier

m Montag, 2. April 2007 schrieb Wilhelm Meier:

Quoted 7 lines
Quoted 4 lines

It seems to me that I rewrote cifs_demultiplex_thread to use kthread_run in DFS patch.

o.k., I found the patch on the list. Will do some testing with it.

o.k., the patch seems to be fine for linux-vserver. cifs-mounting inside the guest is now possible.

Do you see any possiblility to include this part of Igors work (not the whole DFS thing) to the mainline? It fixes the use of the deprecated api.

-
Wilhelm

------------------------------------------------------------------------

Index: connect.c
===================================================================

connect.c +15 -15
@@ -30,6 +30,7 @@
 #include <linux/mempool.h>
 #include <linux/delay.h>
 #include <linux/completion.h>
+#include <linux/kthread.h>
 #include <linux/pagevec.h>
 #include <asm/uaccess.h>
 #include <asm/processor.h>
@@ -119,7 +120,7 @@
 	struct mid_q_entry * mid_entry;
 
 	spin_lock(&GlobalMid_Lock);
-	if(server->tcpStatus == CifsExiting) {
+	if( kthread_should_stop() ) {
 		/* the demux thread will exit normally 
 		next time through the loop */
 		spin_unlock(&GlobalMid_Lock);
@@ -181,7 +182,7 @@
 	spin_unlock(&GlobalMid_Lock);
 	up(&server->tcpSem); 
 
-	while ((server->tcpStatus != CifsExiting) && (server->tcpStatus != CifsGood))
+	while ( (!kthread_should_stop()) && (server->tcpStatus != CifsGood))
 	{
 		try_to_freeze();
 		if(server->protocolType == IPV6) {
@@ -198,7 +199,7 @@
 		} else {
 			atomic_inc(&tcpSesReconnectCount);
 			spin_lock(&GlobalMid_Lock);
-			if(server->tcpStatus != CifsExiting)
+			if( !kthread_should_stop() )
 				server->tcpStatus = CifsGood;
 			server->sequence_number = 0;
 			spin_unlock(&GlobalMid_Lock);			
@@ -344,7 +345,6 @@
 	int isMultiRsp;
 	int reconnect;
 
-	daemonize("cifsd");
 	allow_signal(SIGKILL);
 	current->flags |= PF_MEMALLOC;
 	server->tsk = current;	/* save process info to wake at shutdown */
@@ -360,7 +360,7 @@
 			GFP_KERNEL);
 	}
 
-	while (server->tcpStatus != CifsExiting) {
+	while (!kthread_should_stop()) {
 		if (try_to_freeze())
 			continue;
 		if (bigbuf == NULL) {
@@ -399,7 +399,7 @@
 		    kernel_recvmsg(csocket, &smb_msg,
 				 &iov, 1, 4, 0 /* BB see socket.h flags */);
 
-		if (server->tcpStatus == CifsExiting) {
+		if ( kthread_should_stop() ) {
 			break;
 		} else if (server->tcpStatus == CifsNeedReconnect) {
 			cFYI(1, ("Reconnect after server stopped responding"));
@@ -523,7 +523,7 @@
 		     total_read += length) {
 			length = kernel_recvmsg(csocket, &smb_msg, &iov, 1,
 						pdu_length - total_read, 0);
-			if((server->tcpStatus == CifsExiting) ||
+			if( kthread_should_stop() ||
 			    (length == -EINTR)) {
 				/* then will exit */
 				reconnect = 2;
@@ -756,7 +756,6 @@
 			GFP_KERNEL);
 	}
 
-	complete_and_exit(&cifsd_complete, 0);
 	return 0;
 }
 
@@ -1779,10 +1778,11 @@
 			so no need to spinlock this init of tcpStatus */
 			srvTcp->tcpStatus = CifsNew;
 			init_MUTEX(&srvTcp->tcpSem);
-			rc = (int)kernel_thread((void *)(void *)cifs_demultiplex_thread, srvTcp,
-				      CLONE_FS | CLONE_FILES | CLONE_VM);
-			if(rc < 0) {
-				rc = -ENOMEM;
+			srvTcp->tsk = kthread_run((void *)(void *)cifs_demultiplex_thread, srvTcp, "cifsd");
+			if( IS_ERR(srvTcp->tsk) ) {
+				rc = PTR_ERR(srvTcp->tsk);
+				cERROR(1,("error %d create cifsd thread", rc));
+				srvTcp->tsk = NULL;
 				sock_release(csocket);
 				kfree(volume_info.UNC);
 				kfree(volume_info.password);
@@ -1973,7 +1973,7 @@
 			spin_unlock(&GlobalMid_Lock);
 			if(srvTcp->tsk) {
 				send_sig(SIGKILL,srvTcp->tsk,1);
-				wait_for_completion(&cifsd_complete);
+				kthread_stop(srvTcp->tsk);
 			}
 		}
 		 /* If find_unc succeeded then rc == 0 so we can not end */
@@ -1987,9 +1987,9 @@
 					temp_rc = CIFSSMBLogoff(xid, pSesInfo);
 					/* if the socketUseCount is now zero */
 					if((temp_rc == -ESHUTDOWN) &&
-					   (pSesInfo->server->tsk)) {
+					   (pSesInfo->server) && (pSesInfo->server->tsk)) {
 						send_sig(SIGKILL,pSesInfo->server->tsk,1);
-						wait_for_completion(&cifsd_complete);
+						kthread_stop(pSesInfo->server->tsk);
 					}
 				} else
 					cFYI(1, ("No session or bad tcon"));

connect.c line 3279

Quoted 8 lines
connect.c +1 -1
@@ -3273,7 +3273,7 @@
 				cFYI(1,("Waking up socket by sending it signal"));
 				if(cifsd_task) {
 					send_sig(SIGKILL,cifsd_task,1);
-					wait_for_completion(&cifsd_complete);
+					kthread_stop(cifsd_task);
 				}
 				rc = 0;
 			} /* else - we have an smb session

Yes. I can merge this today in cifs-2.6 development tree after I try it out (and to 2.6.22 when it opens up
soon).

I also plan to merge a somewhat simpler change tothe inet_pton related change that Q made, since that can be pulled out to make the final dfs change smaller to finish review (but it requires an additional change to fs/cifs/connect.c to recognize ipv6 connections)..

#6 lore raw
In reply to Q (Igor Mammedov)
Quoted 9 lines · Q (Igor Mammedov)
Quoted 7 lines · Steve French (smfltc)

No - IIRC the original patch (for the switch of cifs from kernel_thread to kthread) had a minor implementation problem in handling the cifs_demultiplex thread, so this one small area was left with the old style.

Quoted 3 lines

iii) Is it difficult to switch to the new interface?

Quoted 8 lines
Quoted 5 lines

No, I don't think so, but I have not investigated it. We would be happy to review and test a patch for this though.

Quoted 1 line

***************************

It seems to me that I rewrote cifs_demultiplex_thread to use kthread_run in DFS patch.

Yes - Q's patch has the final change to kthread (as part of a larger DFS change). The original patch which switched to kthread was done long before this.

I have not broken all the large dfs patch into small pieces but will look to see if just this part can be done easily