2004-10-22 01:19:07 +00:00
/*
Unix SMB / CIFS implementation .
Copyright ( C ) Andrew Tridgell 2004
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
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2004-10-22 01:19:07 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2004-10-22 01:19:07 +00:00
*/
/*
this is the open files database . It implements shared storage of
what files are open between server instances , and implements the rules
of shared access to files .
The caller needs to provide a file_key , which specifies what file
they are talking about . This needs to be a unique key across all
filesystems , and is usually implemented in terms of a device / inode
pair .
Before any operations can be performed the caller needs to establish
a lock on the record associated with file_key . That is done by
calling odb_lock ( ) . The caller releases this lock by calling
talloc_free ( ) on the returned handle .
All other operations on a record are done by passing the odb_lock ( )
handle back to this module . The handle contains internal
2004-10-22 04:48:24 +00:00
information about what file_key is being operated on .
2004-10-22 01:19:07 +00:00
*/
# include "includes.h"
2006-04-12 04:42:40 +00:00
# include "ntvfs/ntvfs.h"
2007-01-19 11:58:03 +00:00
# include "ntvfs/common/ntvfs_common.h"
2007-01-10 13:25:39 +00:00
# include "cluster/cluster.h"
2007-09-08 12:42:09 +00:00
# include "param/param.h"
2004-10-22 01:19:07 +00:00
2007-03-13 01:47:04 +00:00
static const struct opendb_ops * ops ;
2004-10-22 01:19:07 +00:00
/*
2007-03-13 01:47:04 +00:00
set the odb backend ops
2004-10-22 01:19:07 +00:00
*/
2007-03-13 01:47:04 +00:00
void odb_set_ops ( const struct opendb_ops * new_ops )
{
ops = new_ops ;
}
2004-10-22 01:19:07 +00:00
/*
Open up the openfiles . tdb database . Close it down using
talloc_free ( ) . We need the messaging_ctx to allow for pending open
notifications .
*/
2008-04-02 04:53:27 +02:00
struct odb_context * odb_init ( TALLOC_CTX * mem_ctx ,
2006-04-12 04:42:40 +00:00
struct ntvfs_context * ntvfs_ctx )
2004-10-22 01:19:07 +00:00
{
2007-03-13 01:47:04 +00:00
if ( ops = = NULL ) {
2007-12-10 04:33:16 +01:00
if ( lp_parm_bool ( ntvfs_ctx - > lp_ctx , NULL , " ctdb " , " opendb " , false ) ) {
2007-04-05 03:51:49 +00:00
odb_ctdb_init_ops ( ) ;
} else {
odb_tdb_init_ops ( ) ;
}
2004-10-22 01:19:07 +00:00
}
2007-03-13 01:47:04 +00:00
return ops - > odb_init ( mem_ctx , ntvfs_ctx ) ;
2004-10-22 01:19:07 +00:00
}
/*
get a lock on a entry in the odb . This call returns a lock handle ,
which the caller should unlock using talloc_free ( ) .
*/
2008-04-02 04:53:27 +02:00
struct odb_lock * odb_lock ( TALLOC_CTX * mem_ctx ,
2006-04-07 14:14:27 +00:00
struct odb_context * odb , DATA_BLOB * file_key )
2004-10-22 01:19:07 +00:00
{
2007-03-13 01:47:04 +00:00
return ops - > odb_lock ( mem_ctx , odb , file_key ) ;
2004-10-22 01:19:07 +00:00
}
2004-10-24 08:31:41 +00:00
2008-04-02 04:53:27 +02:00
DATA_BLOB odb_get_key ( TALLOC_CTX * mem_ctx , struct odb_lock * lck )
2008-02-22 10:18:13 +01:00
{
return ops - > odb_get_key ( mem_ctx , lck ) ;
}
2004-10-24 08:31:41 +00:00
2004-11-03 10:09:48 +00:00
/*
2008-03-07 18:23:34 +01:00
register an open file in the open files database .
The share_access rules are implemented by odb_can_open ( )
and it ' s needed to call odb_can_open ( ) before
odb_open_file ( ) otherwise NT_STATUS_INTERNAL_ERROR is returned
2006-02-28 03:47:02 +00:00
Note that the path is only used by the delete on close logic , not
for comparing with other filenames
2004-11-03 10:09:48 +00:00
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_open_file ( struct odb_lock * lck ,
2008-02-25 16:47:48 +01:00
void * file_handle , const char * path ,
2008-04-15 16:00:42 +02:00
int * fd , NTTIME open_write_time ,
bool allow_level_II_oplock ,
2006-04-12 04:42:40 +00:00
uint32_t oplock_level , uint32_t * oplock_granted )
2004-11-03 10:09:48 +00:00
{
2008-03-07 18:23:34 +01:00
return ops - > odb_open_file ( lck , file_handle , path ,
2008-04-15 16:00:42 +02:00
fd , open_write_time ,
allow_level_II_oplock ,
2008-03-06 15:47:27 +01:00
oplock_level , oplock_granted ) ;
2004-11-03 10:09:48 +00:00
}
2004-10-24 08:31:41 +00:00
/*
2006-02-28 03:47:02 +00:00
register a pending open file in the open files database
2004-10-24 08:31:41 +00:00
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_open_file_pending ( struct odb_lock * lck , void * private )
2004-10-24 08:31:41 +00:00
{
2007-03-13 01:47:04 +00:00
return ops - > odb_open_file_pending ( lck , private ) ;
2006-02-28 03:47:02 +00:00
}
/*
remove a opendb entry
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_close_file ( struct odb_lock * lck , void * file_handle ,
2008-02-27 21:50:51 +01:00
const char * * delete_path )
2006-02-28 03:47:02 +00:00
{
2008-02-27 21:50:51 +01:00
return ops - > odb_close_file ( lck , file_handle , delete_path ) ;
2004-10-24 08:31:41 +00:00
}
2004-10-24 12:39:15 +00:00
2004-11-03 10:09:48 +00:00
/*
remove a pending opendb entry
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_remove_pending ( struct odb_lock * lck , void * private )
2004-11-03 10:09:48 +00:00
{
2007-03-13 01:47:04 +00:00
return ops - > odb_remove_pending ( lck , private ) ;
2004-11-03 10:09:48 +00:00
}
2004-10-24 12:39:15 +00:00
/*
2006-02-28 03:47:02 +00:00
rename the path in a open file
2004-10-24 12:39:15 +00:00
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_rename ( struct odb_lock * lck , const char * path )
2004-10-24 12:39:15 +00:00
{
2007-03-13 01:47:04 +00:00
return ops - > odb_rename ( lck , path ) ;
2006-02-28 03:47:02 +00:00
}
2008-02-28 09:06:49 +01:00
/*
get back the path of an open file
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_get_path ( struct odb_lock * lck , const char * * path )
2008-02-28 09:06:49 +01:00
{
return ops - > odb_get_path ( lck , path ) ;
}
2006-02-28 03:47:02 +00:00
/*
update delete on close flag on an open file
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_set_delete_on_close ( struct odb_lock * lck , bool del_on_close )
2006-02-28 03:47:02 +00:00
{
2007-03-13 01:47:04 +00:00
return ops - > odb_set_delete_on_close ( lck , del_on_close ) ;
2006-02-28 03:47:02 +00:00
}
/*
2008-04-15 16:00:42 +02:00
update the write time on an open file
2006-02-28 03:47:02 +00:00
*/
2008-04-15 16:00:42 +02:00
NTSTATUS odb_set_write_time ( struct odb_lock * lck ,
NTTIME write_time , bool force )
2006-02-28 03:47:02 +00:00
{
2008-04-15 16:00:42 +02:00
return ops - > odb_set_write_time ( lck , write_time , force ) ;
2004-10-24 12:39:15 +00:00
}
2004-10-25 01:29:31 +00:00
2008-04-15 16:00:42 +02:00
/*
return the current value of the delete_on_close bit ,
and the current write time .
*/
NTSTATUS odb_get_file_infos ( struct odb_context * odb , DATA_BLOB * key ,
bool * del_on_close , NTTIME * write_time )
{
return ops - > odb_get_file_infos ( odb , key , del_on_close , write_time ) ;
}
2004-10-25 01:29:31 +00:00
/*
2004-10-25 04:24:58 +00:00
determine if a file can be opened with the given share_access ,
create_options and access_mask
2004-10-25 01:29:31 +00:00
*/
2008-04-02 04:53:27 +02:00
NTSTATUS odb_can_open ( struct odb_lock * lck ,
2008-02-25 17:48:13 +01:00
uint32_t stream_id , uint32_t share_access ,
uint32_t access_mask , bool delete_on_close ,
uint32_t open_disposition , bool break_to_none )
2004-10-25 01:29:31 +00:00
{
2008-02-25 17:48:13 +01:00
return ops - > odb_can_open ( lck , stream_id , share_access , access_mask ,
delete_on_close , open_disposition , break_to_none ) ;
2004-10-25 01:29:31 +00:00
}
2008-02-21 16:12:27 +01:00
2008-04-02 04:53:27 +02:00
NTSTATUS odb_update_oplock ( struct odb_lock * lck , void * file_handle ,
2008-02-21 16:12:27 +01:00
uint32_t oplock_level )
{
return ops - > odb_update_oplock ( lck , file_handle , oplock_level ) ;
}
2008-02-22 16:30:13 +01:00
2008-04-02 04:53:27 +02:00
NTSTATUS odb_break_oplocks ( struct odb_lock * lck )
2008-02-22 16:30:13 +01:00
{
return ops - > odb_break_oplocks ( lck ) ;
}