mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] Make {posix,flock}_lock_file interface simpler
@ 2002-11-20 19:35 Petr Vandrovec
  0 siblings, 0 replies; only message in thread
From: Petr Vandrovec @ 2002-11-20 19:35 UTC (permalink / raw)
  To: willy; +Cc: linux-kernel

Hi Willy,
  some months ago, after your fs/locks.c cleanup, and after 
troubles we had with getting tests for non-blocking vs. blocking
calls correct, I wrote following patch. If you are still 
interested in cleaning up fs/locks.c, can you review it, and 
either dump to the floor, or send to Linus?

  With old version, we do wait_event_interruptible()
when lock function returned -EAGAIN and we did blocking call.

  Patch below changes locking code to return -EAGAIN if
wait_event_interruptible() should not called, and -ERESTARTSYS
if wait_event_interruptible() should be called (that is,
locking code called locks_insert_block()). So now calling
rule is simple: if you got -ERESTARTSYS, you must do
wait_event_interruptible, otherwise you have error code to
return to userspace.

  I choosed ERESTARTSYS just arbitrary: it was not used by
currentl locking code, it must not be returned to userspace,
and it already exists.
				Thanks,
					Petr Vandrovec
					vandrove@vc.cvut.cz

diff -urdN linux/fs/locks.c linux/fs/locks.c
--- linux/fs/locks.c	2002-11-20 18:33:14.000000000 +0000
+++ linux/fs/locks.c	2002-11-20 18:42:01.000000000 +0000
@@ -678,7 +678,7 @@
 
 	for (;;) {
 		error = posix_lock_file(filp, &fl);
-		if (error != -EAGAIN)
+		if (error != -ERESTARTSYS)
 			break;
 		error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
 		if (!error) {
@@ -749,6 +749,7 @@
 		error = -EAGAIN;
 		if (new_fl->fl_flags & FL_SLEEP) {
 			locks_insert_block(fl, new_fl);
+			error = -ERESTARTSYS;
 		}
 		goto out;
 	}
@@ -812,7 +813,7 @@
 			error = -EDEADLK;
 			if (posix_locks_deadlock(request, fl))
 				goto out;
-			error = -EAGAIN;
+			error = -ERESTARTSYS;
 			locks_insert_block(fl, request);
 			goto out;
   		}
@@ -1295,7 +1296,7 @@
 
 	for (;;) {
 		error = flock_lock_file(filp, lock);
-		if ((error != -EAGAIN) || (cmd & LOCK_NB))
+		if (error != -ERESTARTSYS)
 			break;
 		error = wait_event_interruptible(lock->fl_wait, !lock->fl_next);
 		if (!error)
@@ -1453,7 +1454,7 @@
 
 	for (;;) {
 		error = posix_lock_file(filp, file_lock);
-		if ((error != -EAGAIN) || (cmd == F_SETLK))
+		if (error != -ERESTARTSYS)
 			break;
 		error = wait_event_interruptible(file_lock->fl_wait,
 				!file_lock->fl_next);
@@ -1593,7 +1594,7 @@
 
 	for (;;) {
 		error = posix_lock_file(filp, file_lock);
-		if ((error != -EAGAIN) || (cmd == F_SETLK64))
+		if (error != -ERESTARTSYS)
 			break;
 		error = wait_event_interruptible(file_lock->fl_wait,
 				!file_lock->fl_next);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-11-20 19:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-20 19:35 [PATCH] Make {posix,flock}_lock_file interface simpler Petr Vandrovec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®