Technical article 100022

What file locking is available in SCO AFPS?

OpenServer 5.0.0OpenServer 5.0.2

Written · Last revised

Problem

What file locking is available in SCO Advanced File and Print Server Release 3.5.1f (AFPS) and how is it implemented?

Solution

The SCO Advanced File and Print Server (AFPS) product is based on Microsoft Networking technology running on top of the SCO UNIX System V/386 Operating System. Clients of this product are also based on this technology. Locking is implemented in different ways in the UNIX operating system, the AFPS server, the PC client operating system networking redirector component, and the application programs. In this mixed environment, you will encounter locking as you attempt to open and work on a file resident on the AFPS server using a PC client-based application program. However, you may also require access to the same file using a server-based UNIX application. A PC client application will request a lock on a file using a specific network SMB (Server Message Block) request. A UNIX application will request a lock using an operating system system call. When a PC client opens a dialogue with the AFPS server, both parties negotiate what "dialect" of SMB protocol they will "speak". Examples of these "dialects" include:

MSNET/PCNET/OpenNET/Microsoft Networks File sharing or "Core" protocol, LAN Manager 1.0 (or SMB 2.0 extensions), LAN Manager 2.0 (or SMB 3.0 extensions), Windows 3.11, Windows 95 and NT extensions (NT LM 0.12).

The subsequent agreed dialect will decide, among other things, what locking functionality will be used. The SMB dialects have evolved since 1986 with various releases of Microsoft networking products. Unfortunately, references to "dialects" can be confusing as the dialect itself may be identified or referenced in different ways. Examples of this may be found in network specification documentation, product code, or as reported by server or client utility programs such as "net session".

An example of lock functionality within SMB "core" dialect is in the SMB "open" message. MS-DOS can open a file in read/write and share mode. The share mode itself has options for allowing an exclusive lock to be placed on the file or a "deny write" (read only) or "deny read" (write only) option. If opened with "deny none" mode, then a record-locking SMB can be sent incorporating the open file SMB file handler requesting several non-overlapping byte ranges to be locked in the file.

On the server, a lock may be placed on a file by the UNIX operating system or by the AFPS server. The UNIX operating system will place a lock using its own primitives (see lockf(S), fcntl(S), fcntl(M)), whereas AFPS will place its own type of lock (or a UNIX lock depending on the setting of the "unixlocks" parameter) in the [ lmxserver ] section of the AFPS control file, "/usr/net/servers/lanman/lanman .ini". By default, unixlocks is set to "no", and the AFPS server does not reflect its own lock on a particular file in the UNIX operating system. The lock information is held internally within AFPS. If "unixlocks" is set to "yes", the AFPS server will try to apply all locks in the UNIX operating system as they have been applied by the client.

An AFPS data file will be resident on an AFPS share on the server. This share may, in some cases, actually be an NFS mounted remote filesystem rather than a local UNIX filesystem. In this case, locking will be undertaken by the NFS daemons component of the operating system. (SCO OpenServer uses the Network Lock Manager, "NLM".) This separate NFS locking mechanism may be implemented in slightly different fashions by different vendors on their UNIX operating systems. Because of this, a PC client request for a lock via an SMB request may not be reflected in the remote NFS filesystem, as the NFS component will not support the operation. AFPS uses the "nfslocks" parameter in the [ lmxserver ] section of "/usr/net/servers/lanman/ lanman.ini" to take account of this situation. By default, nfslocks is set to "no" so that AFPS locks are not reflected in NFS. If "unixlocks" is set to "no", "nfslocks" will have no effect on the server. If "unixlocks" has been set to "yes" and "nfslocks" is set to "yes", locks will attempt to be set and any errors reported back to the client. If "unixlocks" has been set to "yes" and "nfslocks" to "no", the locks will attempt to be mirrored in the UNIX operating system whether NFS-mounted or not, but the result is redundant. Setting "nfslocks=no" will not reduce any NLM file locking traffic generated by AFPS.

Another locking mechanism the AFPS Server can use is "opportunistic locking". This is the ability of the server to grant a preemptive lock on a particular file in response to an open or lock request from a client. The server does not actually proceed with the overhead of applying the lock. The client believes it has the file locked, whereas, in fact, the server simply recognizes that it is the only client session accessing that file. When the program running on the client calls any filelocking operating system calls, the client operating system knows that the file is already locked. Thus, there is no need for these calls to be made over the network to the server, and no wait for any network acknowledgements from the server to any such lock calls. This results in overall network traffic being reduced and performance increased. Should another client program request access to the same file, the AFPS server "breaks" the preemptive lock of the original client and informs the client with an unsolicited SMB message that its opportunistic lock has been broken. From that point, all the client operating systems have to resort to their usual protocol to apply for and release locks on the file.

Opportunistic locking is governed by the "useoplock" parameter in the [ lmxserver ] section of the "/usr/net/servers/lanman/lanman.ini" control file. By default, an AFPS server will grant an opportunistic lock on a file if requested to do so by a client. It is an optimization on network traffic to take advantage of a common situation. Setting "useoplock=no" will turn off this facility.

One point to note about the use of opportunistic locking ("oplocks")
is that this mechanism only applies to networked AFPS clients. The
AFPS server has to be aware of another client's access request for
the oplock to be broken. If, in fact, the file is accessed by a
UNIX-based application, the AFPS server will be unaware of that
fact.  For this reason, on server systems where it is expected
that there will coexist UNIX-based applications accessing the same
files as the AFPS users, opportunistic locking should be disabled.
See IT afps/9, "UNIX file on SCO AFPS share fails to save correctly
on PC hard disk" for an example of this situation. The fact that a
UNIX based application will be accessing an AFPS shared file will
require that any lock placed by a PC client application is reflected
in the operating system, so "unixlocks" should be set to "yes"
(default=no) with "useoplock=no".

As mentioned previously, a client will request to place a lock on a particular file using an application program. This lock will be applied transparently to the user/application, in that it is not aware of the location of the file in real terms; whether it is local, and hence under the control of the local PC client's own operating system locking mechanisms, or remote, under the control of a server's locking mechanism. The client application lock request is either serviced locally by the operating system (for example, by a Win32 API under Windows NT), or passed by it to a redirector component which then prepares an SMB request for the remote server. The lock may or may not succeed dependent on whether the server understands the SMB dialect and currently implements the type of requested lock.

See also

SCO Advanced File and Print Server System Guide, Appendix B: Server Configuration.

IT afps/9, "UNIX file on SCO AFPS share fails to save correctly on client PC hard disk."

IT lmu/91, "What are opportunistic locks and how are they related to performance?"

From the Xinuos technical article database, record 100022. Reproduced with permission. The original is at www.sco.com/ta/100022, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.