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

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Copyright (C) Andrew Tridgell 2004
       5             :    
       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 3 of the License, or
       9             :    (at your option) any later version.
      10             :    
      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.
      15             :    
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : 
      20             : /*
      21             :   this is the open files database. It implements shared storage of
      22             :   what files are open between server instances, and implements the rules
      23             :   of shared access to files.
      24             : 
      25             :   The caller needs to provide a file_key, which specifies what file
      26             :   they are talking about. This needs to be a unique key across all
      27             :   filesystems, and is usually implemented in terms of a device/inode
      28             :   pair.
      29             : 
      30             :   Before any operations can be performed the caller needs to establish
      31             :   a lock on the record associated with file_key. That is done by
      32             :   calling odb_lock(). The caller releases this lock by calling
      33             :   talloc_free() on the returned handle.
      34             : 
      35             :   All other operations on a record are done by passing the odb_lock()
      36             :   handle back to this module. The handle contains internal
      37             :   information about what file_key is being operated on.
      38             : */
      39             : 
      40             : #include "includes.h"
      41             : #include "ntvfs/ntvfs.h"
      42             : #include "ntvfs/common/ntvfs_common.h"
      43             : #include "cluster/cluster.h"
      44             : #include "param/param.h"
      45             : 
      46             : static const struct opendb_ops *ops;
      47             : 
      48             : /*
      49             :   set the odb backend ops
      50             : */
      51           4 : void odb_set_ops(const struct opendb_ops *new_ops)
      52             : {
      53           4 :         ops = new_ops;
      54           4 : }
      55             : 
      56             : /*
      57             :   Open up the openfiles.tdb database. Close it down using
      58             :   talloc_free(). We need the imessaging_ctx to allow for pending open
      59             :   notifications.
      60             : */
      61        1328 : struct odb_context *odb_init(TALLOC_CTX *mem_ctx, 
      62             :                                       struct ntvfs_context *ntvfs_ctx)
      63             : {
      64        1328 :         if (ops == NULL) {
      65           4 :                 odb_tdb_init_ops();
      66             :         }
      67        1328 :         return ops->odb_init(mem_ctx, ntvfs_ctx);
      68             : }
      69             : 
      70             : /*
      71             :   get a lock on a entry in the odb. This call returns a lock handle,
      72             :   which the caller should unlock using talloc_free().
      73             : */
      74      949443 : struct odb_lock *odb_lock(TALLOC_CTX *mem_ctx,
      75             :                                    struct odb_context *odb, DATA_BLOB *file_key)
      76             : {
      77      949443 :         return ops->odb_lock(mem_ctx, odb, file_key);
      78             : }
      79             : 
      80        2915 : DATA_BLOB odb_get_key(TALLOC_CTX *mem_ctx, struct odb_lock *lck)
      81             : {
      82        2915 :         return ops->odb_get_key(mem_ctx, lck);
      83             : }
      84             : 
      85             : /*
      86             :   register an open file in the open files database.
      87             :   The share_access rules are implemented by odb_can_open()
      88             :   and it's needed to call odb_can_open() before
      89             :   odb_open_file() otherwise NT_STATUS_INTERNAL_ERROR is returned
      90             : 
      91             :   Note that the path is only used by the delete on close logic, not
      92             :   for comparing with other filenames
      93             : */
      94      203228 : NTSTATUS odb_open_file(struct odb_lock *lck,
      95             :                                 void *file_handle, const char *path,
      96             :                                 int *fd, NTTIME open_write_time,
      97             :                                 bool allow_level_II_oplock,
      98             :                                 uint32_t oplock_level, uint32_t *oplock_granted)
      99             : {
     100      203228 :         return ops->odb_open_file(lck, file_handle, path,
     101             :                                   fd, open_write_time,
     102             :                                   allow_level_II_oplock,
     103             :                                   oplock_level, oplock_granted);
     104             : }
     105             : 
     106             : 
     107             : /*
     108             :   register a pending open file in the open files database
     109             : */
     110        2915 : NTSTATUS odb_open_file_pending(struct odb_lock *lck, void *private_data)
     111             : {
     112        2915 :         return ops->odb_open_file_pending(lck, private_data);
     113             : }
     114             : 
     115             : 
     116             : /*
     117             :   remove a opendb entry
     118             : */
     119      203228 : NTSTATUS odb_close_file(struct odb_lock *lck, void *file_handle,
     120             :                                  const char **delete_path)
     121             : {
     122      203228 :         return ops->odb_close_file(lck, file_handle, delete_path);
     123             : }
     124             : 
     125             : 
     126             : /*
     127             :   remove a pending opendb entry
     128             : */
     129        2831 : NTSTATUS odb_remove_pending(struct odb_lock *lck, void *private_data)
     130             : {
     131        2831 :         return ops->odb_remove_pending(lck, private_data);
     132             : }
     133             : 
     134             : 
     135             : /*
     136             :   rename the path in a open file
     137             : */
     138         112 : NTSTATUS odb_rename(struct odb_lock *lck, const char *path)
     139             : {
     140         112 :         return ops->odb_rename(lck, path);
     141             : }
     142             : 
     143             : /*
     144             :   get back the path of an open file
     145             : */
     146        8392 : NTSTATUS odb_get_path(struct odb_lock *lck, const char **path)
     147             : {
     148        8392 :         return ops->odb_get_path(lck, path);
     149             : }
     150             : 
     151             : /*
     152             :   update delete on close flag on an open file
     153             : */
     154         317 : NTSTATUS odb_set_delete_on_close(struct odb_lock *lck, bool del_on_close)
     155             : {
     156         317 :         return ops->odb_set_delete_on_close(lck, del_on_close);
     157             : }
     158             : 
     159             : /*
     160             :   update the write time on an open file
     161             : */
     162        9634 : NTSTATUS odb_set_write_time(struct odb_lock *lck,
     163             :                             NTTIME write_time, bool force)
     164             : {
     165        9634 :         return ops->odb_set_write_time(lck, write_time, force);
     166             : }
     167             : 
     168             : /*
     169             :   return the current value of the delete_on_close bit,
     170             :   and the current write time.
     171             : */
     172      460156 : NTSTATUS odb_get_file_infos(struct odb_context *odb, DATA_BLOB *key,
     173             :                             bool *del_on_close, NTTIME *write_time)
     174             : {
     175      460156 :         return ops->odb_get_file_infos(odb, key, del_on_close, write_time);
     176             : }
     177             : 
     178             : /*
     179             :   determine if a file can be opened with the given share_access,
     180             :   create_options and access_mask
     181             : */
     182      242479 : NTSTATUS odb_can_open(struct odb_lock *lck,
     183             :                                uint32_t stream_id, uint32_t share_access,
     184             :                                uint32_t access_mask, bool delete_on_close,
     185             :                                uint32_t open_disposition, bool break_to_none)
     186             : {
     187      242479 :         return ops->odb_can_open(lck, stream_id, share_access, access_mask,
     188             :                                  delete_on_close, open_disposition, break_to_none);
     189             : }
     190             : 
     191          86 : NTSTATUS odb_update_oplock(struct odb_lock *lck, void *file_handle,
     192             :                                     uint32_t oplock_level)
     193             : {
     194          86 :         return ops->odb_update_oplock(lck, file_handle, oplock_level);
     195             : }
     196             : 
     197       31538 : NTSTATUS odb_break_oplocks(struct odb_lock *lck)
     198             : {
     199       31538 :         return ops->odb_break_oplocks(lck);
     200             : }

Generated by: LCOV version 1.14