Subject: kern/30303: Unlocking already-unlocked file on smbfs returns EBUSY
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <khym@azeotrope.org>
List: netbsd-bugs
Date: 05/22/2005 07:40:00
>Number:         30303
>Category:       kern
>Synopsis:       Unlocking already-unlocked file on smbfs returns EBUSY
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 22 07:40:00 +0000 2005
>Originator:     Dave Huang
>Release:        NetBSD 2.0
>Organization:
Name: Dave Huang         |  Mammal, mammal / their names are called /
INet: khym@azeotrope.org |  they raise a paw / the bat, the cat /
FurryMUCK: Dahan         |  dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 29 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Environment:
	
	
System: NetBSD yerfable.azeotrope.org 2.0 NetBSD 2.0 (YERFABLE) #214: Sun Dec 12 07:15:04 CST 2004 khym@yerfable.azeotrope.org:/usr2/obj.alpha/sys/arch/alpha/compile/YERFABLE alpha
Architecture: alpha
Machine: alpha
>Description:
	Calling flock(2) to unlock a file that's not locked succeeds
the file is on a FFS filesystem. However, if the file is on SMBFS, the
flock() call returns an error and sets errno to EBUSY. According to
the manpage, EBUSY is not an error flock() should return, and it seems
to me that it shouldn't return any error in this case.

	This is apparently due to smb_maperror() in
sys/netsmb/smb_subr.c mapping the ERRnotlocked returned by the SMB
server to EBUSY, then that getting passed back up to flock()'s caller.

>How-To-Repeat:
#include <fcntl.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
	int f;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s filename\n", argv[0]);
		return 1;
	}

	if ((f = open(argv[1], O_RDWR | O_CREAT, 0666)) == -1) {
		perror("open");
		return 1;
	}

	if (flock(f, LOCK_UN) == -1) {
		perror("flock");
		return -1;
	}

	printf("No error\n");

	return 0;
}

% ./locktest /usr/tmp/abc
No error
% ./locktest /c/abc
flock: Device busy

(Where /usr/tmp is ffs, and /c is smbfs)

>Fix:
	I don't know... perhaps smb_advlock() should see if it gets
EBUSY when unlocking, and return success in that case?

>Unformatted: