2 Unix SMB/CIFS implementation.
3 IRIX kernel oplock processing
4 Copyright (C) Andrew Tridgell 1992-1998
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #define DBGC_CLASS DBGC_LOCKING
24 #if HAVE_KERNEL_OPLOCKS_IRIX
26 static int oplock_pipe_write
= -1;
27 static int oplock_pipe_read
= -1;
29 /****************************************************************************
30 Test to see if IRIX kernel oplocks work.
31 ****************************************************************************/
33 static BOOL
irix_oplocks_available(void)
39 set_effective_capability(KERNEL_OPLOCK_CAPABILITY
);
41 slprintf(tmpname
,sizeof(tmpname
)-1, "%s/koplock.%d", lp_lockdir(),
45 DEBUG(0,("check_kernel_oplocks: Unable to create pipe. Error "
51 if((fd
= sys_open(tmpname
, O_RDWR
|O_CREAT
|O_EXCL
|O_TRUNC
, 0600)) < 0) {
52 DEBUG(0,("check_kernel_oplocks: Unable to open temp test file "
54 tmpname
, strerror(errno
) ));
63 if(sys_fcntl_long(fd
, F_OPLKREG
, pfd
[1]) == -1) {
64 DEBUG(0,("check_kernel_oplocks: Kernel oplocks are not "
65 "available on this machine. Disabling kernel oplock "
73 if(sys_fcntl_long(fd
, F_OPLKACK
, OP_REVOKE
) < 0 ) {
74 DEBUG(0,("check_kernel_oplocks: Error when removing kernel "
75 "oplock. Error was %s. Disabling kernel oplock "
76 "support.\n", strerror(errno
) ));
90 /****************************************************************************
91 * Deal with the IRIX kernel <--> smbd
92 * oplock break protocol.
93 ****************************************************************************/
95 static files_struct
*irix_oplock_receive_message(fd_set
*fds
)
97 extern int smb_read_error
;
102 /* Ensure we only get one call per select fd set. */
103 FD_CLR(oplock_pipe_read
, fds
);
106 * Read one byte of zero to clear the
107 * kernel break notify message.
110 if(read(oplock_pipe_read
, &dummy
, 1) != 1) {
111 DEBUG(0,("irix_oplock_receive_message: read of kernel "
112 "notification failed. Error was %s.\n",
114 smb_read_error
= READ_ERROR
;
119 * Do a query to get the
120 * device and inode of the file that has the break
121 * request outstanding.
124 if(sys_fcntl_ptr(oplock_pipe_read
, F_OPLKSTAT
, &os
) < 0) {
125 DEBUG(0,("irix_oplock_receive_message: fcntl of kernel "
126 "notification failed. Error was %s.\n",
128 if(errno
== EAGAIN
) {
130 * Duplicate kernel break message - ignore.
134 smb_read_error
= READ_ERROR
;
139 * We only have device and inode info here - we have to guess that this
140 * is the first fsp open with this dev,ino pair.
143 if ((fsp
= file_find_di_first((SMB_DEV_T
)os
.os_dev
,
144 (SMB_INO_T
)os
.os_ino
)) == NULL
) {
145 DEBUG(0,("irix_oplock_receive_message: unable to find open "
146 "file with dev = %x, inode = %.0f\n",
147 (unsigned int)os
.os_dev
, (double)os
.os_ino
));
151 DEBUG(5,("irix_oplock_receive_message: kernel oplock break request "
152 "received for dev = %x, inode = %.0f\n, file_id = %ul",
153 (unsigned int)fsp
->dev
, (double)fsp
->inode
,
159 /****************************************************************************
160 Attempt to set an kernel oplock on a file.
161 ****************************************************************************/
163 static BOOL
irix_set_kernel_oplock(files_struct
*fsp
, int oplock_type
)
165 if (sys_fcntl_long(fsp
->fh
->fd
, F_OPLKREG
, oplock_pipe_write
) == -1) {
166 if(errno
!= EAGAIN
) {
167 DEBUG(0,("irix_set_kernel_oplock: Unable to get "
168 "kernel oplock on file %s, dev = %x, inode "
169 "= %.0f, file_id = %ul. Error was %s\n",
170 fsp
->fsp_name
, (unsigned int)fsp
->dev
,
171 (double)fsp
->inode
, fsp
->fh
->file_id
,
174 DEBUG(5,("irix_set_kernel_oplock: Refused oplock on "
175 "file %s, fd = %d, dev = %x, inode = %.0f, "
176 "file_id = %ul. Another process had the file "
178 fsp
->fsp_name
, fsp
->fh
->fd
,
179 (unsigned int)fsp
->dev
, (double)fsp
->inode
,
185 DEBUG(10,("irix_set_kernel_oplock: got kernel oplock on file %s, dev "
186 "= %x, inode = %.0f, file_id = %ul\n",
187 fsp
->fsp_name
, (unsigned int)fsp
->dev
, (double)fsp
->inode
,
193 /****************************************************************************
194 Release a kernel oplock on a file.
195 ****************************************************************************/
197 static void irix_release_kernel_oplock(files_struct
*fsp
)
201 * Check and print out the current kernel
202 * oplock state of this file.
204 int state
= sys_fcntl_long(fsp
->fh
->fd
, F_OPLKACK
, -1);
205 dbgtext("irix_release_kernel_oplock: file %s, dev = %x, "
206 "inode = %.0f file_id = %ul, has kernel oplock state "
207 "of %x.\n", fsp
->fsp_name
, (unsigned int)fsp
->dev
,
208 (double)fsp
->inode
, fsp
->fh
->file_id
, state
);
212 * Remove the kernel oplock on this file.
214 if(sys_fcntl_long(fsp
->fh
->fd
, F_OPLKACK
, OP_REVOKE
) < 0) {
216 dbgtext("irix_release_kernel_oplock: Error when "
217 "removing kernel oplock on file " );
218 dbgtext("%s, dev = %x, inode = %.0f, file_id = %ul. "
220 fsp
->fsp_name
, (unsigned int)fsp
->dev
,
221 (double)fsp
->inode
, fsp
->fh
->file_id
,
227 /****************************************************************************
228 See if there is a message waiting in this fd set.
229 Note that fds MAY BE NULL ! If so we must do our own select.
230 ****************************************************************************/
232 static BOOL
irix_oplock_msg_waiting(fd_set
*fds
)
238 if (oplock_pipe_read
== -1)
242 return FD_ISSET(oplock_pipe_read
, fds
);
245 /* Do a zero-time select. We just need to find out if there
246 * are any outstanding messages. We use sys_select_intr as
247 * we need to ignore any signals. */
250 FD_SET(oplock_pipe_read
, &myfds
);
252 to
= timeval_set(0, 0);
253 selrtn
= sys_select_intr(oplock_pipe_read
+1,&myfds
,NULL
,NULL
,&to
);
254 return (selrtn
== 1) ? True
: False
;
257 /****************************************************************************
258 Setup kernel oplocks.
259 ****************************************************************************/
261 struct kernel_oplocks
*irix_init_kernel_oplocks(void)
264 static struct kernel_oplocks koplocks
;
266 if (!irix_oplocks_available())
270 DEBUG(0,("setup_kernel_oplock_pipe: Unable to create pipe. "
271 "Error was %s\n", strerror(errno
) ));
275 oplock_pipe_read
= pfd
[0];
276 oplock_pipe_write
= pfd
[1];
278 koplocks
.receive_message
= irix_oplock_receive_message
;
279 koplocks
.set_oplock
= irix_set_kernel_oplock
;
280 koplocks
.release_oplock
= irix_release_kernel_oplock
;
281 koplocks
.msg_waiting
= irix_oplock_msg_waiting
;
282 koplocks
.notification_fd
= oplock_pipe_read
;
287 void oplock_irix_dummy(void);
288 void oplock_irix_dummy(void) {}
289 #endif /* HAVE_KERNEL_OPLOCKS_IRIX */