s3: Fix max indentation and max column
[samba.git] / source3 / smbd / oplock_irix.c
index 23b2fa908133e59bb5d55b58d678c9467545efd5..75f34df1c2059a0d53b0e509254d744b6a1fe391 100644 (file)
 
 #define DBGC_CLASS DBGC_LOCKING
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
 #include "smbd/globals.h"
 
 #if HAVE_KERNEL_OPLOCKS_IRIX
 
 struct irix_oplocks_context {
        struct kernel_oplocks *ctx;
+       struct smbd_server_connection *sconn;
        int write_fd;
        int read_fd;
-       struct fd_event *read_fde;
+       struct tevent_fd *read_fde;
        bool pending;
 };
 
@@ -46,8 +49,8 @@ static bool irix_oplocks_available(void)
 
        tmpname = talloc_asprintf(ctx,
                                "%s/koplock.%d",
-                               lp_lockdir(),
-                               (int)sys_getpid());
+                               lp_lock_directory(),
+                               (int)getpid());
        if (!tmpname) {
                TALLOC_FREE(ctx);
                return False;
@@ -61,7 +64,7 @@ static bool irix_oplocks_available(void)
                return False;
        }
 
-       if((fd = sys_open(tmpname, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, 0600)) < 0) {
+       if((fd = open(tmpname, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, 0600)) < 0) {
                DEBUG(0,("check_kernel_oplocks: Unable to open temp test file "
                         "%s. Error was %s\n",
                         tmpname, strerror(errno) ));
@@ -103,6 +106,24 @@ static bool irix_oplocks_available(void)
        return True;
 }
 
+/*
+ * This is bad because the file_id should always be created through the vfs
+ * layer!  Unfortunately, a conn struct isn't available here.
+ */
+static struct file_id file_id_create_dev(SMB_DEV_T dev, SMB_INO_T inode)
+{
+       struct file_id key;
+
+       /* the ZERO_STRUCT ensures padding doesn't break using the key as a
+        * blob */
+       ZERO_STRUCT(key);
+
+       key.devid = dev;
+       key.inode = inode;
+
+       return key;
+}
+
 /****************************************************************************
  * Deal with the IRIX kernel <--> smbd
  * oplock break protocol.
@@ -164,7 +185,7 @@ static files_struct *irix_oplock_receive_message(struct kernel_oplocks *_ctx)
 
        fileid = file_id_create_dev((SMB_DEV_T)os.os_dev,
                                    (SMB_INO_T)os.os_ino);
-       if ((fsp = file_find_di_first(fileid)) == NULL) {
+       if ((fsp = file_find_di_first(ctx->sconn, fileid)) == NULL) {
                DEBUG(0,("irix_oplock_receive_message: unable to find open "
                         "file with dev = %x, inode = %.0f\n",
                         (unsigned int)os.os_dev, (double)os.os_ino ));
@@ -194,7 +215,8 @@ static bool irix_set_kernel_oplock(struct kernel_oplocks *_ctx,
                        DEBUG(0,("irix_set_kernel_oplock: Unable to get "
                                 "kernel oplock on file %s, file_id %s "
                                 "gen_id = %ul. Error was %s\n", 
-                                fsp->fsp_name, file_id_string_tos(&fsp->file_id), 
+                                fsp_str_dbg(fsp),
+                                file_id_string_tos(&fsp->file_id),
                                 fsp->fh->gen_id,
                                 strerror(errno) ));
                } else {
@@ -202,7 +224,7 @@ static bool irix_set_kernel_oplock(struct kernel_oplocks *_ctx,
                                 "file %s, fd = %d, file_id = %s, "
                                 "gen_id = %ul. Another process had the file "
                                 "open.\n",
-                                fsp->fsp_name, fsp->fh->fd,
+                                fsp_str_dbg(fsp), fsp->fh->fd,
                                 file_id_string_tos(&fsp->file_id),
                                 fsp->fh->gen_id ));
                }
@@ -211,7 +233,7 @@ static bool irix_set_kernel_oplock(struct kernel_oplocks *_ctx,
        
        DEBUG(10,("irix_set_kernel_oplock: got kernel oplock on file %s, file_id = %s "
                  "gen_id = %ul\n",
-                 fsp->fsp_name, file_id_string_tos(&fsp->file_id),
+                 fsp_str_dbg(fsp), file_id_string_tos(&fsp->file_id),
                  fsp->fh->gen_id));
 
        return True;
@@ -232,7 +254,8 @@ static void irix_release_kernel_oplock(struct kernel_oplocks *_ctx,
                int state = sys_fcntl_long(fsp->fh->fd, F_OPLKACK, -1);
                dbgtext("irix_release_kernel_oplock: file %s, file_id = %s"
                        "gen_id = %ul, has kernel oplock state "
-                       "of %x.\n", fsp->fsp_name, file_id_string_tos(&fsp->file_id),
+                       "of %x.\n", fsp_str_dbg(fsp),
+                       file_id_string_tos(&fsp->file_id),
                         fsp->fh->gen_id, state );
        }
 
@@ -245,15 +268,16 @@ static void irix_release_kernel_oplock(struct kernel_oplocks *_ctx,
                                "removing kernel oplock on file " );
                        dbgtext("%s, file_id = %s gen_id = %ul. "
                                "Error was %s\n",
-                               fsp->fsp_name, file_id_string_tos(&fsp->file_id),
+                               fsp_str_dbg(fsp),
+                               file_id_string_tos(&fsp->file_id),
                                fsp->fh->gen_id,
                                strerror(errno) );
                }
        }
 }
 
-static void irix_oplocks_read_fde_handler(struct event_context *ev,
-                                         struct fd_event *fde,
+static void irix_oplocks_read_fde_handler(struct tevent_context *ev,
+                                         struct tevent_fd *fde,
                                          uint16_t flags,
                                          void *private_data)
 {
@@ -262,7 +286,7 @@ static void irix_oplocks_read_fde_handler(struct event_context *ev,
        files_struct *fsp;
 
        fsp = irix_oplock_receive_message(ctx->ctx);
-       break_kernel_oplock(smbd_messaging_context(), fsp);
+       break_kernel_oplock(ctx->sconn->msg_ctx, fsp);
 }
 
 /****************************************************************************
@@ -270,11 +294,13 @@ static void irix_oplocks_read_fde_handler(struct event_context *ev,
 ****************************************************************************/
 
 static const struct kernel_oplocks_ops irix_koplocks = {
-       .set_oplock             = irix_set_kernel_oplock,
-       .release_oplock         = irix_release_kernel_oplock,
+       .set_oplock                     = irix_set_kernel_oplock,
+       .release_oplock                 = irix_release_kernel_oplock,
+       .contend_level2_oplocks_begin   = NULL,
+       .contend_level2_oplocks_end     = NULL,
 };
 
-struct kernel_oplocks *irix_init_kernel_oplocks(TALLOC_CTX *mem_ctx)
+struct kernel_oplocks *irix_init_kernel_oplocks(struct smbd_server_connection *sconn)
 {
        struct kernel_oplocks *_ctx;
        struct irix_oplocks_context *ctx;
@@ -283,7 +309,7 @@ struct kernel_oplocks *irix_init_kernel_oplocks(TALLOC_CTX *mem_ctx)
        if (!irix_oplocks_available())
                return NULL;
 
-       _ctx = talloc_zero(mem_ctx, struct kernel_oplocks);
+       _ctx = talloc_zero(sconn, struct kernel_oplocks);
        if (!_ctx) {
                return NULL;
        }
@@ -296,6 +322,7 @@ struct kernel_oplocks *irix_init_kernel_oplocks(TALLOC_CTX *mem_ctx)
        _ctx->ops = &irix_koplocks;
        _ctx->private_data = ctx;
        ctx->ctx = _ctx;
+       ctx->sconn = sconn;
 
        if(pipe(pfd) != 0) {
                talloc_free(_ctx);
@@ -307,10 +334,10 @@ struct kernel_oplocks *irix_init_kernel_oplocks(TALLOC_CTX *mem_ctx)
        ctx->read_fd = pfd[0];
        ctx->write_fd = pfd[1];
 
-       ctx->read_fde = event_add_fd(smbd_event_context(),
+       ctx->read_fde = tevent_add_fd(sconn->ev_ctx,
                                     ctx,
                                     ctx->read_fd,
-                                    EVENT_FD_READ,
+                                    TEVENT_FD_READ,
                                     irix_oplocks_read_fde_handler,
                                     ctx);
        return _ctx;