root/source4/ntvfs/common/brlock.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. brl_set_ops
  2. brl_init
  3. brl_create_handle
  4. brl_lock
  5. brl_unlock
  6. brl_remove_pending
  7. brl_locktest
  8. brl_close

   1 /* 
   2    Unix SMB/CIFS implementation.
   3 
   4    generic byte range locking code
   5 
   6    Copyright (C) Andrew Tridgell 1992-2004
   7    Copyright (C) Jeremy Allison 1992-2000
   8    
   9    This program is free software; you can redistribute it and/or modify
  10    it under the terms of the GNU General Public License as published by
  11    the Free Software Foundation; either version 3 of the License, or
  12    (at your option) any later version.
  13    
  14    This program is distributed in the hope that it will be useful,
  15    but WITHOUT ANY WARRANTY; without even the implied warranty of
  16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17    GNU General Public License for more details.
  18    
  19    You should have received a copy of the GNU General Public License
  20    along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21 */
  22 
  23 /* This module implements a tdb based byte range locking service,
  24    replacing the fcntl() based byte range locking previously
  25    used. This allows us to provide the same semantics as NT */
  26 
  27 #include "includes.h"
  28 #include "system/filesys.h"
  29 #include "../tdb/include/tdb.h"
  30 #include "messaging/messaging.h"
  31 #include "lib/messaging/irpc.h"
  32 #include "libcli/libcli.h"
  33 #include "cluster/cluster.h"
  34 #include "ntvfs/common/ntvfs_common.h"
  35 
  36 static const struct brlock_ops *ops;
  37 
  38 /*
  39   set the brl backend ops
  40 */
  41 void brl_set_ops(const struct brlock_ops *new_ops)
     /* [<][>][^][v][top][bottom][index][help] */
  42 {
  43         ops = new_ops;
  44 }
  45 
  46 /*
  47   Open up the brlock database. Close it down using talloc_free(). We
  48   need the messaging_ctx to allow for pending lock notifications.
  49 */
  50 struct brl_context *brl_init(TALLOC_CTX *mem_ctx, struct server_id server, 
     /* [<][>][^][v][top][bottom][index][help] */
  51                              struct loadparm_context *lp_ctx,
  52                              struct messaging_context *messaging_ctx)
  53 {
  54         if (ops == NULL) {
  55                 brl_tdb_init_ops();
  56         }
  57         return ops->brl_init(mem_ctx, server, lp_ctx, messaging_ctx);
  58 }
  59 
  60 struct brl_handle *brl_create_handle(TALLOC_CTX *mem_ctx, struct ntvfs_handle *ntvfs, DATA_BLOB *file_key)
     /* [<][>][^][v][top][bottom][index][help] */
  61 {
  62         return ops->brl_create_handle(mem_ctx, ntvfs, file_key);
  63 }
  64 
  65 /*
  66   Lock a range of bytes.  The lock_type can be a PENDING_*_LOCK, in
  67   which case a real lock is first tried, and if that fails then a
  68   pending lock is created. When the pending lock is triggered (by
  69   someone else closing an overlapping lock range) a messaging
  70   notification is sent, identified by the notify_ptr
  71 */
  72 NTSTATUS brl_lock(struct brl_context *brl,
     /* [<][>][^][v][top][bottom][index][help] */
  73                   struct brl_handle *brlh,
  74                   uint32_t smbpid,
  75                   uint64_t start, uint64_t size, 
  76                   enum brl_type lock_type,
  77                   void *notify_ptr)
  78 {
  79         return ops->brl_lock(brl, brlh, smbpid, start, size, lock_type, notify_ptr);
  80 }
  81 
  82 
  83 /*
  84  Unlock a range of bytes.
  85 */
  86 NTSTATUS brl_unlock(struct brl_context *brl,
     /* [<][>][^][v][top][bottom][index][help] */
  87                     struct brl_handle *brlh, 
  88                     uint32_t smbpid,
  89                     uint64_t start, uint64_t size)
  90 {
  91         return ops->brl_unlock(brl, brlh, smbpid, start, size);
  92 }
  93 
  94 /*
  95   remove a pending lock. This is called when the caller has either
  96   given up trying to establish a lock or when they have succeeded in
  97   getting it. In either case they no longer need to be notified.
  98 */
  99 NTSTATUS brl_remove_pending(struct brl_context *brl,
     /* [<][>][^][v][top][bottom][index][help] */
 100                             struct brl_handle *brlh, 
 101                             void *notify_ptr)
 102 {
 103         return ops->brl_remove_pending(brl, brlh, notify_ptr);
 104 }
 105 
 106 
 107 /*
 108   Test if we are allowed to perform IO on a region of an open file
 109 */
 110 NTSTATUS brl_locktest(struct brl_context *brl,
     /* [<][>][^][v][top][bottom][index][help] */
 111                       struct brl_handle *brlh,
 112                       uint32_t smbpid, 
 113                       uint64_t start, uint64_t size, 
 114                       enum brl_type lock_type)
 115 {
 116         return ops->brl_locktest(brl, brlh, smbpid, start, size, lock_type);
 117 }
 118 
 119 
 120 /*
 121  Remove any locks associated with a open file.
 122 */
 123 NTSTATUS brl_close(struct brl_context *brl,
     /* [<][>][^][v][top][bottom][index][help] */
 124                    struct brl_handle *brlh)
 125 {
 126         return ops->brl_close(brl, brlh);
 127 }

/* [<][>][^][v][top][bottom][index][help] */