[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-kernel
Subject:    Ftape spinlock patch for 2.1.84
From:       Shaw Carruthers <shaw () shawc ! demon ! co ! uk>
Date:       1998-01-31 20:55:53
[Download RAW message or body]


I guess while the fiddling with sigmasks in ftape is there it should be
protected by spinlocks. Here is a patch against 2.1.84

--- linux.dist/drivers/char/ftape/zftape/zftape-init.c	Tue Jan 27 01:27:34 1998
+++ linux/drivers/char/ftape/zftape/zftape-init.c	Sat Jan 31 12:27:59 1998
@@ -138,6 +138,26 @@
 	NULL,			/* fsync */
 };
 
+/* fix signal handling */
+
+void sigblockall( sigset_t * oldmask )
+{
+	spin_lock_irq(&current->sigmask_lock);
+	*oldmask = current->blocked;
+	sigfillset(&current->blocked);
+	recalc_sigpending(current);
+	spin_unlock_irq(&current->sigmask_lock);
+}
+
+void sigrestoreold ( sigset_t * oldmask)
+{
+	spin_lock_irq(&current->sigmask_lock);
+	current->blocked = *oldmask;
+	recalc_sigpending(current);
+	spin_unlock_irq(&current->sigmask_lock);
+}
+				
+
 /*      Open floppy tape device
  */
 static int zft_open(struct inode *ino, struct file *filep)
@@ -170,11 +190,10 @@
 #endif
 		TRACE_ABORT(-ENXIO, ft_t_err, "failed: illegal unit nr");
 	}
-	orig_sigmask = current->blocked;
-	sigfillset(&current->blocked);
+	sigblockall(&orig_sigmask);
 	result = _zft_open(MINOR(ino->i_rdev), filep->f_flags & O_ACCMODE);
 	if (result < 0) {
-		current->blocked = orig_sigmask; /* restore mask */
+		sigrestoreold( &orig_sigmask); /* restore mask */
 		busy_flag = 0;
 #if defined(MODULE) && LINUX_VERSION_CODE < KERNEL_VER(2,1,18)
 		if (!zft_dirty()) {
@@ -186,8 +205,8 @@
 		/* Mask signals that will disturb proper operation of the
 		 * program that is calling.
 		 */
-		current->blocked = orig_sigmask;
-		sigaddsetmask (&current->blocked, _DO_BLOCK);
+		sigaddsetmask (&orig_sigmask, _DO_BLOCK);
+		sigrestoreold (&orig_sigmask);
 		TRACE_EXIT 0;
 	}
 }
@@ -207,12 +226,12 @@
 		TRACE_EXIT; /* keep busy_flag !(?) */
 #endif
 	}
-	sigfillset(&current->blocked);
+	sigblockall(&orig_sigmask);
 	result = _zft_close();
 	if (result < 0) {
 		TRACE(ft_t_err, "_zft_close failed");
 	}
-	current->blocked = orig_sigmask; /* restore before open state */
+	sigrestoreold( &orig_sigmask); /* restore before open state */
 	busy_flag = 0;
 #if defined(MODULE) && LINUX_VERSION_CODE < KERNEL_VER(2,1,18)
 	if (!zft_dirty()) {
@@ -239,11 +258,10 @@
 		TRACE_ABORT(-EIO, ft_t_err,
 			    "failed: not busy, failure or wrong unit");
 	}
-	old_sigmask = current->blocked; /* save mask */
-	sigfillset(&current->blocked);
+	sigblockall(&old_sigmask); /* save mask */
 	/* This will work as long as sizeof(void *) == sizeof(long) */
 	result = _zft_ioctl(command, (void *) arg);
-	current->blocked = old_sigmask; /* restore mask */
+	sigrestoreold(&old_sigmask); /* restore mask */
 	TRACE_EXIT result;
 }
 
@@ -272,8 +290,7 @@
 		TRACE_ABORT(-EIO, ft_t_err,
 			    "failed: not busy, failure or wrong unit");
 	}
-	old_sigmask = current->blocked; /* save mask */
-	sigfillset(&current->blocked);
+	sigblockall(&old_sigmask); /* save mask */
 	if ((result = ftape_mmap(vma)) >= 0) {
 #ifndef MSYNC_BUG_WAS_FIXED
 		static struct vm_operations_struct dummy = { NULL, };
@@ -286,7 +303,7 @@
 		inode_inc_count (ino);
 #endif
 	}
-	current->blocked = old_sigmask; /* restore mask */
+	sigrestoreold(&old_sigmask); /* restore mask */
 	TRACE_EXIT result;
 }
 
@@ -315,10 +332,9 @@
 		TRACE_ABORT(-EIO, ft_t_err,
 			    "failed: not busy, failure or wrong unit");
 	}
-	old_sigmask = current->blocked; /* save mask */
-	sigfillset(&current->blocked);
+	sigblockall(&old_sigmask); /* save mask */
 	result = _zft_read(buff, req_len);
-	current->blocked = old_sigmask; /* restore mask */
+	sigrestoreold(&old_sigmask); /* restore mask */
 	TRACE(ft_t_data_flow, "return with count: %d", result);
 	TRACE_EXIT result;
 }
@@ -351,10 +367,9 @@
 		TRACE_ABORT(-EIO, ft_t_err,
 			    "failed: not busy, failure or wrong unit");
 	}
-	old_sigmask = current->blocked; /* save mask */
-	sigfillset(&current->blocked);
+	sigblockall(&old_sigmask); /* save mask */
 	result = _zft_write(buff, req_len);
-	current->blocked = old_sigmask; /* restore mask */
+	sigrestoreold(&old_sigmask); /* restore mask */
 	TRACE(ft_t_data_flow, "return with count: %d", result);
 	TRACE_EXIT result;
 }

--
Shaw Carruthers - shaw@shawc.demon.co.uk
London SW14 7JW UK
This is not a sig( with homage to Magritte).
  

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic