Skip to contentSkip to conversation

Make {posix,flock}_lock_file interface simpler

PATCH New Petr Vandrovec 1 participant 1 message Nov 20, 2002

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Make {posix,flock}_lock_file interface simpler

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 [email protected]

fs/locks.c +6 -5
diff -urdN linux/fs/locks.c linux/fs/locks.c
@@ -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);