LCOV - code coverage report
Current view: top level - source4/ntvfs/common - brlock.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 21 21 100.0 %
Date: 2024-04-21 15:09:00 Functions: 9 9 100.0 %

          Line data    Source code
       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 "messaging/messaging.h"
      30             : #include "lib/messaging/irpc.h"
      31             : #include "libcli/libcli.h"
      32             : #include "cluster/cluster.h"
      33             : #include "ntvfs/common/ntvfs_common.h"
      34             : 
      35             : static const struct brlock_ops *ops;
      36             : 
      37             : /*
      38             :   set the brl backend ops
      39             : */
      40           4 : void brlock_set_ops(const struct brlock_ops *new_ops)
      41             : {
      42           4 :         ops = new_ops;
      43           4 : }
      44             : 
      45             : /*
      46             :   Open up the brlock database. Close it down using talloc_free(). We
      47             :   need the imessaging_ctx to allow for pending lock notifications.
      48             : */
      49        1328 : struct brl_context *brlock_init(TALLOC_CTX *mem_ctx, struct server_id server, 
      50             :                              struct loadparm_context *lp_ctx,
      51             :                              struct imessaging_context *imessaging_ctx)
      52             : {
      53        1328 :         if (ops == NULL) {
      54           4 :                 brl_tdb_init_ops();
      55             :         }
      56        1328 :         return ops->brl_init(mem_ctx, server, lp_ctx, imessaging_ctx);
      57             : }
      58             : 
      59      189155 : struct brl_handle *brlock_create_handle(TALLOC_CTX *mem_ctx, struct ntvfs_handle *ntvfs, DATA_BLOB *file_key)
      60             : {
      61      189155 :         return ops->brl_create_handle(mem_ctx, ntvfs, file_key);
      62             : }
      63             : 
      64             : /*
      65             :   Lock a range of bytes.  The lock_type can be a PENDING_*_LOCK, in
      66             :   which case a real lock is first tried, and if that fails then a
      67             :   pending lock is created. When the pending lock is triggered (by
      68             :   someone else closing an overlapping lock range) a messaging
      69             :   notification is sent, identified by the notify_ptr
      70             : */
      71        1766 : NTSTATUS brlock_lock(struct brl_context *brl,
      72             :                   struct brl_handle *brlh,
      73             :                   uint32_t smbpid,
      74             :                   uint64_t start, uint64_t size, 
      75             :                   enum brl_type lock_type,
      76             :                   void *notify_ptr)
      77             : {
      78        1766 :         return ops->brl_lock(brl, brlh, smbpid, start, size, lock_type, notify_ptr);
      79             : }
      80             : 
      81             : 
      82             : /*
      83             :  Unlock a range of bytes.
      84             : */
      85         684 : NTSTATUS brlock_unlock(struct brl_context *brl,
      86             :                     struct brl_handle *brlh, 
      87             :                     uint32_t smbpid,
      88             :                     uint64_t start, uint64_t size)
      89             : {
      90         684 :         return ops->brl_unlock(brl, brlh, smbpid, start, size);
      91             : }
      92             : 
      93             : /*
      94             :   remove a pending lock. This is called when the caller has either
      95             :   given up trying to establish a lock or when they have succeeded in
      96             :   getting it. In either case they no longer need to be notified.
      97             : */
      98          82 : NTSTATUS brlock_remove_pending(struct brl_context *brl,
      99             :                             struct brl_handle *brlh, 
     100             :                             void *notify_ptr)
     101             : {
     102          82 :         return ops->brl_remove_pending(brl, brlh, notify_ptr);
     103             : }
     104             : 
     105             : 
     106             : /*
     107             :   Test if we are allowed to perform IO on a region of an open file
     108             : */
     109       51616 : NTSTATUS brlock_locktest(struct brl_context *brl,
     110             :                       struct brl_handle *brlh,
     111             :                       uint32_t smbpid, 
     112             :                       uint64_t start, uint64_t size, 
     113             :                       enum brl_type lock_type)
     114             : {
     115       51616 :         return ops->brl_locktest(brl, brlh, smbpid, start, size, lock_type);
     116             : }
     117             : 
     118             : 
     119             : /*
     120             :  Remove any locks associated with a open file.
     121             : */
     122         155 : NTSTATUS brlock_close(struct brl_context *brl,
     123             :                    struct brl_handle *brlh)
     124             : {
     125         155 :         return ops->brl_close(brl, brlh);
     126             : }
     127             : 
     128             : /*
     129             :  Get a number of locks associated with a open file.
     130             : */
     131       89170 : NTSTATUS brlock_count(struct brl_context *brl,
     132             :                    struct brl_handle *brlh,
     133             :                    int *count)
     134             : {
     135       89170 :         return ops->brl_count(brl, brlh, count);
     136             : }

Generated by: LCOV version 1.14