r23779: Change from v2 or later to v3 or later.
[samba.git] / source3 / smbd / oplock_linux.c
index 9a5eb52e6125ee1d184e1ca27e1e7233512daeec..5fe3668aec9d0106c74e68de624dad4992420275 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -89,7 +89,8 @@ static void set_capability(unsigned capability)
        header.pid = 0;
 
        if (capget(&header, &data) == -1) {
-               DEBUG(3,("Unable to get kernel capabilities (%s)\n", strerror(errno)));
+               DEBUG(3,("Unable to get kernel capabilities (%s)\n",
+                        strerror(errno)));
                return;
        }
 
@@ -101,20 +102,29 @@ static void set_capability(unsigned capability)
        }
 }
 
+/*
+ Call to set the kernel lease signal handler
+*/
+int linux_set_lease_sighandler(int fd)
+{
+        if (fcntl(fd, F_SETSIG, RT_SIGNAL_LEASE) == -1) {
+                DEBUG(3,("Failed to set signal handler for kernel lease\n"));
+                return -1;
+        }
+
+       return 0;
+}
+
 /****************************************************************************
  Call SETLEASE. If we get EACCES then we try setting up the right capability and
- try again
+ try again.
+ Use the SMB_VFS_LINUX_SETLEASE instead of this call directly.
 ****************************************************************************/
 
-static int linux_setlease(int fd, int leasetype)
+int linux_setlease(int fd, int leasetype)
 {
        int ret;
 
-       if (fcntl(fd, F_SETSIG, RT_SIGNAL_LEASE) == -1) {
-               DEBUG(3,("Failed to set signal handler for kernel lease\n"));
-               return -1;
-       }
-
        ret = fcntl(fd, F_SETLEASE, leasetype);
        if (ret == -1 && errno == EACCES) {
                set_capability(CAP_LEASE);
@@ -155,16 +165,19 @@ static files_struct *linux_oplock_receive_message(fd_set *fds)
 
 static BOOL linux_set_kernel_oplock(files_struct *fsp, int oplock_type)
 {
-       if (linux_setlease(fsp->fh->fd, F_WRLCK) == -1) {
-               DEBUG(3,("linux_set_kernel_oplock: Refused oplock on file %s, fd = %d, dev = %x, \
-inode = %.0f. (%s)\n",
+       if ( SMB_VFS_LINUX_SETLEASE(fsp,fsp->fh->fd, F_WRLCK) == -1) {
+               DEBUG(3,("linux_set_kernel_oplock: Refused oplock on file %s, "
+                        "fd = %d, file_id = %s. (%s)\n",
                         fsp->fsp_name, fsp->fh->fd, 
-                        (unsigned int)fsp->dev, (double)fsp->inode, strerror(errno)));
+                        file_id_static_string(&fsp->file_id),
+                        strerror(errno)));
                return False;
        }
        
-       DEBUG(3,("linux_set_kernel_oplock: got kernel oplock on file %s, dev = %x, inode = %.0f, file_id = %lu\n",
-                 fsp->fsp_name, (unsigned int)fsp->dev, (double)fsp->inode, fsp->file_id));
+       DEBUG(3,("linux_set_kernel_oplock: got kernel oplock on file %s, "
+                "file_id = %s gen_id = %lu\n",
+                fsp->fsp_name, file_id_static_string(&fsp->file_id),
+                fsp->fh->gen_id));
 
        return True;
 }
@@ -181,20 +194,23 @@ static void linux_release_kernel_oplock(files_struct *fsp)
                 * oplock state of this file.
                 */
                int state = fcntl(fsp->fh->fd, F_GETLEASE, 0);
-               dbgtext("linux_release_kernel_oplock: file %s, dev = %x, inode = %.0f file_id = %lu has kernel \
-oplock state of %x.\n", fsp->fsp_name, (unsigned int)fsp->dev,
-                        (double)fsp->inode, fsp->file_id, state );
+               dbgtext("linux_release_kernel_oplock: file %s, file_id = %s "
+                       "gen_id = %lu has kernel oplock state "
+                       "of %x.\n", fsp->fsp_name, file_id_static_string(&fsp->file_id),
+                       fsp->fh->gen_id, state );
        }
 
        /*
         * Remove the kernel oplock on this file.
         */
-       if (linux_setlease(fsp->fh->fd, F_UNLCK) == -1) {
+       if ( SMB_VFS_LINUX_SETLEASE(fsp,fsp->fh->fd, F_UNLCK) == -1) {
                if (DEBUGLVL(0)) {
-                       dbgtext("linux_release_kernel_oplock: Error when removing kernel oplock on file " );
-                       dbgtext("%s, dev = %x, inode = %.0f, file_id = %lu. Error was %s\n",
-                               fsp->fsp_name, (unsigned int)fsp->dev, 
-                               (double)fsp->inode, fsp->file_id, strerror(errno) );
+                       dbgtext("linux_release_kernel_oplock: Error when "
+                               "removing kernel oplock on file " );
+                       dbgtext("%s, file_id = %s, gen_id = %lu. "
+                               "Error was %s\n", fsp->fsp_name,
+                               file_id_static_string(&fsp->file_id),
+                               fsp->fh->gen_id, strerror(errno) );
                }
        }
 }